import{a as e}from"./chunk-BNv3lrIs.js";import{n as t,t as n}from"./jsx-runtime-pmtNMKr4.js";import{n as r}from"./toast-hrvP3G3Q.js";import{t as i}from"./Button-_yTP2B6J.js";import{t as a}from"./Modal-Bcsx2gm1.js";import{t as o}from"./useMediaQuery-C_7KdS3g.js";import{t as s}from"./load-HIf6x4Qy.js";import{A as c,An as l,Rn as u,Un as d,Vi as f,li as p,ln as m,ui as h,yr as g}from"./index-CBXvBSuP.js";import{t as _}from"./PageHeader-C3X_ZaAc.js";import{t as v}from"./DataTable-BuE1Zp8A.js";import{t as y}from"./useTheme-D5mB3Mad.js";import{i as b,t as x}from"./ordenCompra-FFNcqTVX.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),[o,s]=(0,S.useState)([]),[c,u]=(0,S.useState)(!1),d=()=>u(!1),_=e=>{console.log(`order`,e),u(!0),s(e)};return(0,C.jsxs)(`div`,{children:[(0,C.jsxs)(h,{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)(f,{bg:e.estadoPago==`0`?`warning`:`success`,children:e.estadoPago==`0`?`Por Pagar`:`Pagado`})}),(0,C.jsx)(`td`,{children:e.estadoPago==`0`?(0,C.jsx)(i,{variant:`success`,title:`Cambiar a pagada`,onClick:()=>_(e),children:(0,C.jsx)(p,{icon:l})}):`No disponibles`})]},e._id))})]}),(0,C.jsxs)(a,{show:c,onHide:d,children:[(0,C.jsx)(a.Header,{closeButton:!0,children:(0,C.jsx)(a.Title,{children:`Estado del pago de orden de compra`})}),(0,C.jsx)(a.Body,{children:(0,C.jsxs)(`h3`,{style:{textAlign:`center`,fontStyle:`italic`},children:[`¿La orden `,o.folio,` fué pagada?`]})}),(0,C.jsxs)(a.Footer,{children:[(0,C.jsxs)(i,{variant:`danger`,onClick:d,children:[(0,C.jsx)(p,{icon:m}),` Cancelar`]}),(0,C.jsxs)(i,{variant:`success`,onClick:()=>{try{x(o._id,{estadoPago:`1`}).then(e=>{let{data:n}=e;r.success(`Se ha marcado como pagada la orden`),d(),t(!1)})}catch(e){console.log(e)}},children:[(0,C.jsx)(p,{icon:g}),` Pagada`]})]})]})]})},T=()=>{o(y().breakpoints.down(`sm`));let[e,t]=(0,S.useState)(!0);(0,S.useEffect)(()=>{setTimeout(()=>{t(!1)},500)},[]);let[n,r]=(0,S.useState)(!1),[a,l]=(0,S.useState)(null),[f,m]=(0,S.useState)(null),h=e=>{m(`Lista de ordenes de cliente`),l(e),r(!0)},g=[{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)(i,{variant:`link`,title:`Ver ordenes`,style:{textDecoration:`none`},onClick:()=>h((0,C.jsx)(w,{setShowModal:r,data:t})),children:(0,C.jsx)(p,{icon:u,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)(s,{}),(0,C.jsx)(_,{title:`Cuentas por pagar`,icon:d}),(0,C.jsxs)(`div`,{className:`divTabla`,children:[(0,C.jsx)(v,{title:`Lista de saldos de clientes registrados`,datos:T,columnas:g}),(0,C.jsxs)(c,{show:n,onClose:()=>r(!1),maxWidth:`xl`,children:[(0,C.jsx)(c.Header,{closeButton:!0,onClose:()=>r(!1),children:f}),(0,C.jsx)(c.Body,{children:a})]})]})]})};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};