import{r as e}from"./chunk-QTnfLwEv.js";import{n as t,t as n}from"./jsx-runtime-BWRPWl8p.js";import{t as r}from"./Modal-CUfJmnkI.js";import{Da as i,Di as a,Ei as o,En as s,G as c,Ir as l,W as u,ha as d,ma as f,or as p,qn as m,tr as h}from"./index-DccLTdzK.js";import{t as g}from"./PageHeader-DNnlanBD.js";import{t as _}from"./DataTable-KLBE0uXO.js";import{t as v}from"./useTheme-ClV7RdEj.js";import{t as y}from"./useMediaQuery-Diq4jKog.js";import{i as b,t as x}from"./ordenCompra-PdChTz8F.js";var S=e(t(),1),C=n(),w=({data:e,setShowModal:t})=>{let n=e=>new Intl.NumberFormat(`es-MX`,{style:`currency`,currency:`MXN`,minimumFractionDigits:2}).format(e),[c,u]=(0,S.useState)([]),[p,h]=(0,S.useState)(!1),g=()=>h(!1),_=e=>{console.log(`order`,e),h(!0),u(e)};return(0,C.jsxs)(`div`,{children:[(0,C.jsxs)(a,{striped:!0,bordered:!0,hover:!0,style:{textAlign:`center`},children:[(0,C.jsx)(`thead`,{children:(0,C.jsxs)(`tr`,{children:[(0,C.jsx)(`th`,{children:`Folio`}),(0,C.jsx)(`th`,{children:`Fecha`}),(0,C.jsx)(`th`,{children:`Total`}),(0,C.jsx)(`th`,{children:`Estado`}),(0,C.jsx)(`th`,{children:`Estado Pago`}),(0,C.jsx)(`th`,{children:`Pagar`})]})}),(0,C.jsx)(`tbody`,{children:e.map(e=>(0,C.jsxs)(`tr`,{children:[(0,C.jsx)(`td`,{children:e.folio}),(0,C.jsx)(`td`,{children:new Date(e.fecha).toLocaleDateString()}),(0,C.jsx)(`td`,{children:n(e.total)}),(0,C.jsx)(`td`,{children:e.estado==`1`?`Recibida`:null}),(0,C.jsx)(`td`,{children:(0,C.jsx)(d,{bg:e.estadoPago==`0`?`warning`:`success`,children:e.estadoPago==`0`?`Por Pagar`:`Pagado`})}),(0,C.jsx)(`td`,{children:e.estadoPago==`0`?(0,C.jsx)(f,{variant:`success`,title:`Cambiar a pagada`,onClick:()=>_(e),children:(0,C.jsx)(o,{icon:m})}):`No disponibles`})]},e._id))})]}),(0,C.jsxs)(r,{show:p,onHide:g,children:[(0,C.jsx)(r.Header,{closeButton:!0,children:(0,C.jsx)(r.Title,{children:`Estado del pago de orden de compra`})}),(0,C.jsx)(r.Body,{children:(0,C.jsxs)(`h3`,{style:{textAlign:`center`,fontStyle:`italic`},children:[`¿La orden `,c.folio,` fué pagada?`]})}),(0,C.jsxs)(r.Footer,{children:[(0,C.jsxs)(f,{variant:`danger`,onClick:g,children:[(0,C.jsx)(o,{icon:s}),` Cancelar`]}),(0,C.jsxs)(f,{variant:`success`,onClick:()=>{try{x(c._id,{estadoPago:`1`}).then(e=>{let{data:n}=e;i.success(`Se ha marcado como pagada la orden`),g(),t(!1)})}catch(e){console.log(e)}},children:[(0,C.jsx)(o,{icon:l}),` Pagada`]})]})]})]})},T=()=>{y(v().breakpoints.down(`sm`));let[e,t]=(0,S.useState)(!0);(0,S.useEffect)(()=>{setTimeout(()=>{t(!1)},500)},[]);let[n,r]=(0,S.useState)(!1),[i,a]=(0,S.useState)(null),[s,l]=(0,S.useState)(null),d=e=>{l(`Lista de ordenes de cliente`),a(e),r(!0)},m=[{name:`RAZÓN SOCIAL`,selector:e=>e.id,sortable:!0},{name:`TOTAL DE COMPRAS`,selector:e=>e.totalOrdenes,sortable:!0},{name:`LISTA`,selector:e=>e.ordenesCompra,cell:e=>{let t=e.ordenesCompra;return Array.isArray(t)?(0,C.jsx)(f,{variant:`link`,title:`Ver ordenes`,style:{textDecoration:`none`},onClick:()=>d((0,C.jsx)(w,{setShowModal:r,data:t})),children:(0,C.jsx)(o,{icon:h,style:{color:`#000080`}})}):(console.error(`ordenesCompra no es un array:`,t),null)}},{name:`TOTAL PAGADO`,selector:e=>e.totalMontoEstado1,sortable:!0,cell:e=>x(e.totalMontoEstado1==null?0:e.totalMontoEstado1)},{name:`POR PAGAR`,selector:e=>e.totalMontoEstado0,sortable:!0,cell:e=>x(e.totalMontoEstado0==null?0:e.totalMontoEstado0)}],x=e=>new Intl.NumberFormat(`es-MX`,{style:`currency`,currency:`MXN`,minimumFractionDigits:2}).format(e),[T,D]=(0,S.useState)([]),O=()=>{try{b().then(e=>{let{data:t}=e;D(E(t))}).catch(e=>{})}catch{}};return(0,S.useEffect)(()=>{n||O()},[n]),(0,C.jsxs)(C.Fragment,{children:[e&&(0,C.jsx)(u,{}),(0,C.jsx)(g,{title:`Cuentas por pagar`,icon:p}),(0,C.jsxs)(`div`,{className:`divTabla`,children:[(0,C.jsx)(_,{title:`Lista de saldos de clientes registrados`,datos:T,columnas:m}),(0,C.jsxs)(c,{show:n,onClose:()=>r(!1),maxWidth:`xl`,children:[(0,C.jsx)(c.Header,{closeButton:!0,onClose:()=>r(!1),children:s}),(0,C.jsx)(c.Body,{children:i})]})]})]})};function E(e){let t=[];return e.forEach(e=>{t.push({id:e.razonSocial,totalOrdenes:e.totalOrdenes,totalMontoEstado0:e.totalMontoEstado0,totalMontoEstado1:e.totalMontoEstado1,ordenesCompra:e.ordenesCompra})}),console.log(`🚀 ~ formatModelOCR ~ dataTemp:`,t),t}export{T as default};