1import{a as te,r as a,j as e,bl as O,bm as se,bn as ae,a8 as re,aB as le,av as q,L as ne,w as oe}from"./index-DelWp-6b.js";import{P as ie}from"./StandardMasterSelects-pQNg0ucS.js";import{u as ce}from"./usePurchaseOrders-CuilBAdv.js";import{D as de}from"./DataTable-BnD-eYaR.js";import{Q as me}from"./QueryErrorState-BF64fE-V.js";import{V as xe}from"./ViewPaymentModal-bsZGRwIo.js";import{u as ue}from"./usePagination-Cphy509k.js";import{T as pe}from"./TablePagination-Dis1c7z7.js";import{P as he}from"./plus-BjX2r5pd.js";import{C as be}from"./chevron-down-B145rEUg.js";import{F as E}from"./filter-Bi-RNbDd.js";import{C as ge}from"./chevron-right-B4DUFimd.js";import"./standard-masters.service-5cGfGpYm.js";import"./crud.service-B2C_PX1U.js";import"./useQuery-B9eAwr7I.js";import"./useMutation-CwYdRQCa.js";import"./purchase.service-B2GUOycb.js";import"./axios-B9iLQH_W.js";import"./Modal-DNpkLqIa.js";import"./exportUtils-Cucw6H5V.js";import"./download-B0-Qxbs8.js";import"./chevrons-right-Cgl0PtMR.js";import"./chevron-left-BM0LmnuU.js";function Ee(){const P=te(),{data:r,isLoading:K,isError:U,refetch:Q}=ce(),[T,N]=a.useState(null),[d,z]=a.useState(""),[l,G]=a.useState(!1),[Z,H]=a.use
1State(!1),[o,A]=a.useState(""),[m,L]=a.useState(""),[i,M]=a.useState(""),[x,B]=a.useState(""),[f,J]=a.useState(""),[W,X]=a.useState(!1),[u,I]=a.useState(""),[p,$]=a.useState(""),[h,V]=a.useState(""),v=Array.isArray(r)?r:(r==null?void 0:r.data)??(r==null?void 0:r.items)??[],C=a.useMemo(()=>v.flatMap(t=>(t.invoices??[]).map(s=>({...s,poNumber:t.poNumber,vendorName:t.vendorName}))).sort((t,s)=>new Date(s.invoiceDate).getTime()-new Date(t.invoiceDate).getTime()),[v]),D=a.useMemo(()=>C.filter(t=>{var s,b,g;if(f){const c=f.toLowerCase();if(!((s=t.invoiceNumber)!=null&&s.toLowerCase().includes(c))&&!((b=t.poNumber)!=null&&b.toLowerCase().includes(c))&&!((g=t.vendorName)!=null&&g.toLowerCase().includes(c)))return!1}return!(u&&t.statusDisplay!==u||p&&t.invoiceDate<p||h&&t.invoiceDate>h)}),[C,f,u,p,h]),k=ue(D,{initialPageSize:25});a.useEffect(()=>{k.setPage(1)},[d,i]);const y=[u,p,h].filter(Boolean).length,Y=()=>{I(""),$(""),V("")},n=a.useMemo(()=>v.flatMap(t=>(t.payments??[]).map(s=>({...s,poNumber:t.poNumber,vendorName:t.vendorName}))).sort((t,s)=>new Date(s.paymentDate).getTime()-new Date(t.paymentDate).getTime()),[v]),j=a.useMemo(()=>({total:n.length,totalAmount:n.reduce((t,s)=>t+(s.amount||0),0),bankTransfer:n.filter(t=>{var s;return(s=t.paymentMethodDisplay)==null?void 0:s.toLowerCase().includes("bank")}).length,cheque:n.filter(t=>{var s;return(s=t.paymentMethodDisplay)==null?void 0:s.toLowerCase().includes("cheque")}).length}),[n]),w=[o,m,i,x].filter(Boolean).length,_=()=>{A(""),L(""),M(""),B("")},S=a.useMemo(()=>n.filter(t=>{var s,b,g,c,R;if(d){const F=d.toLowerCase();if(!((s=t.paymentReference)!=null&&s.toLowerCase().includes(F))&&!((b=t.poNumber)!=null&&b.toLowerCase().includes(F))&&!((g=t.vendorName)!=null&&g.toLowerCase().includes(F)))return!1}return!(o&&!((c=t.paymentMethodDisplay)!=null&&c.toLowerCase().includes(o.toLowerCase()))||m&&!((R=t.vendorName)!=null&&R.toLowerCase().includes(m.toLowerCase()))||i&&t.paymentDate<i||x&&t.paymentDate>x)}),[n,d,o,m,i,x]),ee=[{header:"Reference",cell:t=>e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold text-slate-800 block",children:t.paymentReference||"â"}),e.jsx("span",{className:"text-xs text-slate-500",children:t.paymentTypeDisplay})]})},{header:"PO Number",accessorKey:"poNumber"},{header:"Vendor",accessorKey:"vendorName"},{header:"Method",accessorKey:"paymentMethodDisplay"},{header:"Date",cell:t=>new Date(t.paymentDate).toLocaleDateString()},{header:"Amount",cell:t=>e.jsxs("span",{className:"font-bold text-slate-800",children:[t.amount.toLocaleString("en-US",{minimumFractionDigits:2})," ",t.currency]})},{header:"Actions",cell:t=>e.jsx("button",{onClick:s=>{s.stopPropagation(),N(t)},className:"p-1.5 rounded-lg text-slate-400 hover:text-[var(--primary-500)] hover:bg-[var(--primary-50)] transition-colors",title:"View Details",children:e.jsx(oe,{className:"w-4 h-4"})})}];return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4 flex-wrap",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-slate-900",children:"Payments"}),e.jsx("p",{className:"text-sm text-slate-500 mt-1",children:"Global view of all outgoing payments across purchase orders."})]}),e.jsxs("button",{onClick:()=>P("/purchasing/payments/new"),className:"flex items-center gap-2 px-4 py-2.5 bg-[var(--primary-500)] hover:bg-[var(--primary-600)] text-white rounded-xl text-sm font-semibold shadow-sm transition-colors shrink-0",children:[e.jsx(he,{className:"w-4 h-4"}),"Create Payment"]})]}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-4",children:[{label:"Total Payments",value:j.total,icon:O,iconBg:"bg-slate-100",iconColor:"text-slate-600",isAmount:!1},{label:"Total Paid",value:j.totalAmount.toLocaleString("en-US",{minimumFractionDigits:0}),icon:O,iconBg:"bg-green-100",iconColor:"text-green-600",isAmount:!0},{label:"Bank Transfer",value:j.bankTransfer,icon:se,iconBg:"bg-blue-100",iconColor:"text-blue-600",isAmount:!1},{label:"Cheque",value:j.cheque,icon:ae,iconBg:"bg-purple-100",iconColor:"text-purple-600",isAmount:!1}].map(t=>e.jsxs("div",{className:"bg-white rounded-xl shadow-card p-4 flex items-center gap-3",children:[e.jsx("div",{className:`w-10 h-10 rounded-lg ${t.iconBg} flex items-center justify-center shrink-0`,children:e.jsx(t.icon,{className:`w-5 h-5 ${t.iconColor}`})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-xs text-slate-500 font-medium",children:t.label}),e.jsx("p",{className:`font-bold text-slate-900 leading-none mt-0.5 truncate ${t.isAmount?"text-lg":"text-2xl"}`,children:t.value})]})]},t.label))}),e.jsxs("button",{onClick:()=>G(t=>!t),className:`w-full flex items-center gap-3 px-4 py-3.5 rounded-xl border shadow-sm transition-all text-left ${l?"bg-gradient-to-r from-[#1B2559] to-[#2d3a7c] border-[#1B2559]":"bg-white border-slate-200 hover:border-indigo-300"}`,children:[e.jsx("div",{className:`w-10 h-10 rounded-lg flex items-center justify-center shrink-0 ${l?"bg-white/20":"bg-
1amber-100"}`,children:e.jsx(re,{className:`w-5 h-5 ${l?"text-white":"text-amber-600"}`})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:`text-xs font-medium ${l?"text-white/70":"text-slate-500"}`,children:"Invoices"}),e.jsx("p",{className:`text-2xl font-bold leading-none mt-0.5 ${l?"text-white":"text-slate-900"}`,children:C.length})]}),l?e.jsx(le,{className:"w-5 h-5 text-white/60 shrink-0"}):e.jsx(be,{className:"w-5 h-5 text-slate-400 shrink-0"})]}),l&&e.jsxs("div",{className:"bg-white rounded-xl shadow-card overflow-hidden border border-slate-100",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3",style:{background:"linear-gradient(90deg,#1B2559,#2d3a7c)"},children:[e.jsx("span",{className:"text-sm font-semibold text-white",children:"Invoices"}),e.jsxs("span",{className:"text-xs text-white/50",children:[D.length," records"]})]}),e.jsxs("div",{className:"px-4 py-3 border-b border-slate-100 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"relative flex-1 max-w-sm",children:[e.jsx(q,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-slate-400 pointer-events-none"}),e.jsx("input",{value:f,onChange:t=>J(t.target.value),placeholder:"Search invoice number, PO, or vendor...",className:"w-full pl-9 pr-4 py-2 border border-slate-200 rounded-lg text-sm bg-white focus:outline-none focus:ring-2 focus:ring-[var(--primary-500)]"})]}),e.jsxs("button",{onClick:()=>X(t=>!t),className:`flex items-center gap-2 px-3 py-2 rounded-lg border text-sm font-medium transition-colors ${y>0?"bg-[var(--primary-50)] border-[var(--primary-200)] text-[var(--primary-700)]":"border-slate-200 text-slate-600 hover:bg-[rgba(var(--primary-rgb),0.07)]"}`,children:[e.jsx(E,{className:"w-4 h-4"}),"Filters",y>0&&e.jsx("span",{className:"w-5 h-5 rounded-full bg-[var(--primary-500)] text-white text-[10px] font-bold flex items-center justify-center",children:y})]}),y>0&&e.jsx("button",{onClick:Y,className:"text-xs text-slate-400 hover:text-red-500 transition-colors",children:"Clear all"})]}),W&&e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-3 pt-2 border-t border-slate-50",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-[10px] font-semibold text-slate-500 uppercase tracking-wide mb-1",children:"Status"}),e.jsxs("select",{value:u,onChange:t=>I(t.target.value),className:"w-full px-2.5 py-1.5 border border-slate-200 rounded-lg text-sm bg-white focus:outline-none focus:ring-2 focus:ring-[var(--primary-500)]",children:[e.jsx("option",{value:"",children:"All Statuses"}),["Pending","PendingVerification","Verified","Approved","Rejected","Paid","Cancelled"].map(t=>e.jsx("option",{value:t,children:t.replace(/([A-Z])/g," $1").trim()},t))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[10px] font-semibold text-slate-500 uppercase tracking-wide mb-1",children:"Date From"}),e.jsx("input",{type:"date",value:p,onChange:t=>$(t.target.value),className:"w-full px-2.5 py-1.5 border border-slate-200 rounded-lg text-sm bg-white focus:outline-none focus:ring-2 focus:ring-[var(--primary-500)]"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[10px] font-semibold text-slate-500 uppercase tracking-wide mb-1",children:"Date To"}),e.jsx("input",{type:"date",value:h,onChange:t=>V(t.target.value),className:"w-full px-2.5 py-1.5 border border-slate-200 rounded-lg text-sm bg-white focus:outline-none focus:ring-2 focus:ring-[var(--primary-500)]"})]})]})]}),D.length===0?e.jsx("div",{className:"py-10 text-center text-slate-400 text-sm",children:"No invoices found."}):e.jsxs(e.Fragment,{children:[e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-slate-100 bg-slate-50",children:[["Invoice #","PO Number","Vendor","Date","Amount","Status"].map(t=>e.jsx("th",{className:"text-left px-4 py-2.5 text-[11px] font-semibold text-slate-500 uppercase tracking-wide",children:t},t)),e.jsx("th",{})]})}),e.jsx("tbody",{children:k.paginatedData.map((t,s)=>e.jsxs("tr",{onClick:()=>
1P("/purchasing/invoices"),className:`cursor-pointer border-b border-slate-50 hover:bg-[var(--primary-50)] transition-colors ${s%2===1?"bg-slate-50/40":""}`,children:[e.jsx("td",{className:"px-4 py-3 font-mono font-semibold text-[#1B2559] text-xs",children:t.invoiceNumber??"â"}),e.jsx("td",{className:"px-4 py-3 text-slate-600 text-xs",children:t.poNumber??"â"}),e.jsx("td",{className:"px-4 py-3 text-slate-600 text-xs",children:t.vendorName??"â"}),e.jsx("td",{className:"px-4 py-3 text-slate-400 text-xs",children:t.invoiceDate?new Date(t.invoiceDate).toLocaleDateString():"â"}),e.jsx("td",{className:"px-4 py-3 font-semibold text-slate-700 text-xs",children:t.grandTotal!=null?`${Number(t.grandTotal).toLocaleString()} ${t.currency??"SAR"}`:"â"}),e.jsx("td",{className:"px-4 py-3",children:e.jsx("span",{className:"text-[11px] px-2 py-0.5 rounded-full font-semibold bg-amber-50 text-amber-700 border border-amber-100",children:t.statusDisplay??"â"})}),e.jsx("td",{className:"px-4 py-3 text-right",children:e.jsx(ge,{className:"w-4 h-4 text-slate-300 inline-block"})})]},t.id??s))})]}),e.jsx(pe,{...k,noun:"invoices"})]})]}),e.jsxs("div",{className:"bg-white rounded-xl border border-slate-100 shadow-sm px-4 py-3 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"relative flex-1 max-w-sm",children:[e.jsx(q,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-slate-400 pointer-events-none"}),e.jsx("input",{value:d,onChange:t=>z(t.target.value),placeholder:"Search reference, PO, or vendor...",className:"w-full pl-9 pr-4 py-2 border border-slate-200 rounded-lg text-sm bg-white focus:outline-none focus:ring-2 focus:ring-[var(--primary-500)]"})]}),e.jsxs("button",{onClick:()=>H(t=>!t),className:`flex items-center gap-2 px-3 py-2 rounded-lg border text-sm font-medium transition-colors ${w>0?"bg-[var(--primary-50)] border-[var(--primary-200)] text-[var(--primary-700)]":"border-slate-200 text-slate-600 hover:bg-[rgba(var(--primary-rgb),0.07)]"}`,children:[e.jsx(E,{className:"w-4 h-4"}),"Filters",w>0&&e.jsx("span",{className:"w-5 h-5 rounded-full bg-[var(--primary-500)] text-white text-[10px] font-bold flex items-center justify-center",children:w})]}),w>0&&e.jsx("button",{onClick:_,className:"text-xs text-slate-400 hover:text-red-500 transition-colors",children:"Clear all"}),e.jsxs("span",{className:"text-xs text-slate-400 ml-auto",children:[S.length," record",S.length!==1?"s":""]})]}),Z&&e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3 pt-2 border-t border-slate-50",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-[10px] font-semibold text-slate-500 uppercase tracking-wide mb-1",children:"Method"}),e.jsxs("select",{value:o,onChange:t=>A(t.target.value),className:"w-full px-2.5 py-1.5 border border-slate-200 rounded-lg text-sm bg-white focus:outline-none focus:ring-2 focus:ring-[var(--primary-500)]",children:[e.jsx("option",{value:"",children:"All Methods"}),e.jsx(ie,{current:o})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[10px] font-semibold text-slate-500 uppercase tracking-wide mb-1",children:"Vendor"}),e.jsx("input",{value:m,onChange:t=>L(t.target.value),placeholder:"Filter by vendorâ¦",className:"w-full px-2.5 py-1.5 border border-slate-200 rounded-lg text-sm bg-white focus:outline-none focus:ring-2 focus:ring-[var(--primary-500)]"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[10px] font-semibold text-slate-500 uppercase tracking-wide mb-1",children:"Date From"}),e.jsx("input",{type:"date",value:i,onChange:t=>M(t.target.value),className:"w-full px-2.5 py-1.5 border border-slate-200 rounded-lg text-sm bg-white focus:outline-none focus:ring-2 focus:ring-[var(--primary-500)]"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[10px] font-semibold text-slate-500 uppercase tracking-wide mb-1",children:"Date To"}),e.jsx("input",{type:"date",value:x,onChange:t=>B(t.target.value),className:"w-full px-2.5 py-1.5 border border-slate-200 rounded-lg text-sm bg-white focus:outline-none focus:ring-2 focus:ring-[var(--primary-500)]"})]})]})]}),e.jsx("div",{className:"bg-white rounded-xl shadow-card overflow-hidden",children:K?e.jsx("div",{className:"p-10 flex justify-center",children:e.jsx(ne,{className:"w-8 h-8 animate-spin text-[var(--primary-500)]"})}):U?e.jsx(me,{entity:"payments",onRetry:()=>Q()}):e.jsx(de,{columns:ee,data:S,emptyMessage:"No payments recorded yet.",onRowClick:t=>N(t)})}),e.jsx(xe,{isOpen:!!T,onClose:()=>N(null),payment:T})]})}
1export{Ee as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.