import{r as g,u as b,j as e,H as v}from"./app-BQEFzdw6.js";import{A as N}from"./AppLayout-kozc03ce.js";import{P as _}from"./PageHeader-Bj1OQnqr.js";import{F as l}from"./FormField-HY4WrCzQ.js";import{f as u,a as P}from"./formatters-ClI693-F.js";import{F as C}from"./PlusIcon-ElxOOThC.js";import"./useThemeColor-qPCpc713.js";import"./dayjs.min-BDUBcDj6.js";function V({payments:a,purchaseOrders:h}){const[m,o]=g.useState(!1),{data:r,setData:s,post:f,processing:c,errors:n,reset:j}=b({purchase_order_id:"",amount:"",payment_date:new Date().toISOString().substring(0,10),payment_method:"bank_transfer",reference:"",notes:""});function y(t){t.preventDefault(),f(route("accounts.vendor-payments.store"),{onSuccess:()=>{j(),o(!1)}})}return e.jsxs(N,{children:[e.jsx(v,{title:"Vendor Payments"}),e.jsx(_,{title:"Vendor Payments",subtitle:`${(a.data??a).length} payments`,children:e.jsxs("button",{onClick:()=>o(!m),className:"btn btn-primary flex items-center gap-2",children:[e.jsx(C,{className:"w-4 h-4"})," Record Payment"]})}),e.jsxs("div",{className:"p-4 sm:p-6",children:[m&&e.jsxs("form",{onSubmit:y,className:"card p-4 mb-4 space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3",children:[e.jsx(l,{label:"Purchase Order",error:n.purchase_order_id,required:!0,children:e.jsxs("select",{className:"form-input text-sm",value:r.purchase_order_id,onChange:t=>s("purchase_order_id",t.target.value),children:[e.jsx("option",{value:"",children:"Select PO…"}),(h??[]).map(t=>{var d;return e.jsxs("option",{value:t.id,children:[t.code," — ",(d=t.vendor)==null?void 0:d.name," (",u(t.grand_total),")"]},t.id)})]})}),e.jsx(l,{label:"Amount (৳)",error:n.amount,required:!0,children:e.jsx("input",{type:"number",className:"form-input text-sm",value:r.amount,onChange:t=>s("amount",t.target.value)})}),e.jsx(l,{label:"Date",error:n.payment_date,children:e.jsx("input",{type:"date",className:"form-input text-sm",value:r.payment_date,onChange:t=>s("payment_date",t.target.value)})}),e.jsx(l,{label:"Method",error:n.payment_method,children:e.jsx("select",{className:"form-input text-sm",value:r.payment_method,onChange:t=>s("payment_method",t.target.value),children:["cash","bank_transfer","cheque","mobile_banking"].map(t=>e.jsx("option",{value:t,children:t.replace("_"," ")},t))})}),e.jsx(l,{label:"Reference",error:n.reference,children:e.jsx("input",{className:"form-input text-sm",value:r.reference,onChange:t=>s("reference",t.target.value)})})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"submit",disabled:c,className:"btn btn-primary text-sm",children:c?"…":"Record Payment"}),e.jsx("button",{type:"button",onClick:()=>o(!1),className:"btn text-sm",children:"Cancel"})]})]}),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","PO Code","Vendor","Amount","Method","Reference"].map(t=>e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase",children:t},t))})}),e.jsxs("tbody",{className:"divide-y divide-gray-100",children:[(a.data??a).map(t=>{var d,i,x,p;return e.jsxs("tr",{children:[e.jsx("td",{className:"px-4 py-3 text-sm",children:P(t.payment_date)}),e.jsx("td",{className:"px-4 py-3 text-sm font-mono text-primary-600",children:(d=t.purchaseOrder)==null?void 0:d.code}),e.jsx("td",{className:"px-4 py-3 text-sm",children:(x=(i=t.purchaseOrder)==null?void 0:i.vendor)==null?void 0:x.name}),e.jsx("td",{className:"px-4 py-3 text-sm font-semibold text-red-600",children:u(t.amount)}),e.jsx("td",{className:"px-4 py-3 text-sm capitalize",children:(p=t.payment_method)==null?void 0:p.replace("_"," ")}),e.jsx("td",{className:"px-4 py-3 text-sm text-gray-500",children:t.reference??"—"})]},t.id)}),(a.data??a).length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:6,className:"px-4 py-8 text-center text-gray-400",children:"No vendor payments found."})})]})]})})]})]})}export{V as default};
