import{r as d,j as e,H as N,a as v}from"./app-BQEFzdw6.js";import{A as f}from"./AppLayout-kozc03ce.js";import{P as b}from"./PageHeader-Bj1OQnqr.js";import{f as t,a as S}from"./formatters-ClI693-F.js";import{B as _}from"./Badge-CiLdjUlo.js";import"./useThemeColor-qPCpc713.js";import"./dayjs.min-BDUBcDj6.js";function L({vendor:l,transactions:n,vendors:u,filters:s}){const[c,h]=d.useState((s==null?void 0:s.vendor_id)??""),[o,j]=d.useState((s==null?void 0:s.from)??""),[x,g]=d.useState((s==null?void 0:s.to)??"");function y(a){a.preventDefault(),v.get(route("accounts.reports.vendor-ledger"),{vendor_id:c,from:o,to:x},{preserveState:!0,replace:!0})}const m=(n??[]).filter(a=>a.type==="purchase_order").reduce((a,r)=>a+parseFloat(r.amount),0),p=(n??[]).filter(a=>a.type==="payment").reduce((a,r)=>a+parseFloat(r.amount),0);return e.jsxs(f,{children:[e.jsx(N,{title:"Vendor Ledger"}),e.jsx(b,{title:"Vendor Ledger",back:route("accounts.reports.index")}),e.jsxs("div",{className:"p-4 sm:p-6",children:[e.jsxs("form",{onSubmit:y,className:"flex gap-3 mb-4 items-end flex-wrap",children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("label",{className:"text-xs text-gray-500",children:"Vendor"}),e.jsxs("select",{className:"form-input text-sm",value:c,onChange:a=>h(a.target.value),children:[e.jsx("option",{value:"",children:"Select Vendor…"}),(u??[]).map(a=>e.jsx("option",{value:a.id,children:a.name},a.id))]})]}),e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("label",{className:"text-xs text-gray-500",children:"From"}),e.jsx("input",{type:"date",className:"form-input text-sm",value:o,onChange:a=>j(a.target.value)})]}),e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("label",{className:"text-xs text-gray-500",children:"To"}),e.jsx("input",{type:"date",className:"form-input text-sm",value:x,onChange:a=>g(a.target.value)})]}),e.jsx("button",{type:"submit",className:"btn btn-primary text-sm",children:"Generate"})]}),l&&e.jsxs("div",{className:"mb-4 p-3 bg-orange-50 rounded-lg text-sm",children:[e.jsx("strong",{children:l.name})," · ",l.phone,e.jsxs("span",{className:"ml-4",children:["Total POs: ",e.jsx("strong",{children:t(m)})]}),e.jsxs("span",{className:"ml-4",children:["Total Paid: ",e.jsx("strong",{className:"text-green-700",children:t(p)})]}),e.jsxs("span",{className:"ml-4",children:["Outstanding: ",e.jsx("strong",{className:"text-red-600",children:t(m-p)})]})]}),e.jsx("div",{className:"card overflow-hidden",children:e.jsxs("table",{className:"min-w-full divide-y divide-gray-200",children:[e.jsx("thead",{className:"bg-gray-50",children:e.jsx("tr",{children:["Date","Type","Reference","Description","Amount","Paid","Balance"].map(a=>e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase",children:a},a))})}),e.jsxs("tbody",{className:"divide-y divide-gray-100",children:[(n??[]).map((a,r)=>{var i;return e.jsxs("tr",{children:[e.jsx("td",{className:"px-4 py-3 text-sm",children:S(a.date)}),e.jsx("td",{className:"px-4 py-3",children:e.jsx(_,{variant:a.type==="purchase_order"?"warning":"success",children:(i=a.type)==null?void 0:i.replace("_"," ")})}),e.jsx("td",{className:"px-4 py-3 text-sm font-mono text-primary-600",children:a.reference}),e.jsx("td",{className:"px-4 py-3 text-sm text-gray-600",children:a.description}),e.jsx("td",{className:"px-4 py-3 text-sm",children:a.type==="purchase_order"?t(a.amount):"—"}),e.jsx("td",{className:"px-4 py-3 text-sm text-green-700",children:a.type==="payment"?t(a.amount):"—"}),e.jsx("td",{className:"px-4 py-3 text-sm font-semibold",children:t(a.running_balance)})]},r)}),(n??[]).length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:7,className:"px-4 py-8 text-center text-gray-400",children:"Select a vendor to view ledger."})})]})]})})]})]})}export{L as default};
