import{r as b,u as g,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{a as C,f as R}from"./formatters-ClI693-F.js";import{F as S}from"./PlusIcon-ElxOOThC.js";import"./useThemeColor-qPCpc713.js";import"./dayjs.min-BDUBcDj6.js";function E({receipts:a,invoices:m}){const[d,c]=b.useState(!1),{data:s,setData:n,post:f,processing:p,errors:r,reset:j}=g({invoice_id:"",amount:"",payment_date:new Date().toISOString().substring(0,10),payment_method:"bank_transfer",reference:"",notes:""});function y(t){t.preventDefault(),f(route("accounts.receipts.store"),{onSuccess:()=>{j(),c(!1)}})}const o=(m??[]).find(t=>t.id===s.invoice_id);return e.jsxs(N,{children:[e.jsx(v,{title:"Client Receipts"}),e.jsx(_,{title:"Client Receipts",subtitle:`${(a.data??a).length} receipts`,children:e.jsxs("button",{onClick:()=>c(!d),className:"btn btn-primary flex items-center gap-2",children:[e.jsx(S,{className:"w-4 h-4"})," Record Receipt"]})}),e.jsxs("div",{className:"p-4 sm:p-6",children:[d&&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:"Invoice",error:r.invoice_id,required:!0,children:e.jsxs("select",{className:"form-input text-sm",value:s.invoice_id,onChange:t=>n("invoice_id",t.target.value),children:[e.jsx("option",{value:"",children:"Select Invoice…"}),(m??[]).filter(t=>t.balance_due>0).map(t=>{var i;return e.jsxs("option",{value:t.id,children:[t.code," — ",(i=t.client)==null?void 0:i.name," (Due: ",Number(t.balance_due).toLocaleString("en-IN"),"৳"]},t.id)})]})}),e.jsx(l,{label:"Amount (৳)",error:r.amount,required:!0,children:e.jsx("input",{type:"number",className:"form-input text-sm",value:s.amount,max:o==null?void 0:o.balance_due,onChange:t=>n("amount",t.target.value)})}),e.jsx(l,{label:"Date",error:r.payment_date,children:e.jsx("input",{type:"date",className:"form-input text-sm",value:s.payment_date,onChange:t=>n("payment_date",t.target.value)})}),e.jsx(l,{label:"Method",error:r.payment_method,children:e.jsx("select",{className:"form-input text-sm",value:s.payment_method,onChange:t=>n("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:r.reference,children:e.jsx("input",{className:"form-input text-sm",value:s.reference,onChange:t=>n("reference",t.target.value)})})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"submit",disabled:p,className:"btn btn-primary text-sm",children:p?"…":"Record Receipt"}),e.jsx("button",{type:"button",onClick:()=>c(!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","Invoice","Client","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 i,x,u,h;return e.jsxs("tr",{children:[e.jsx("td",{className:"px-4 py-3 text-sm",children:C(t.payment_date)}),e.jsx("td",{className:"px-4 py-3 text-sm font-mono text-primary-600",children:(i=t.invoice)==null?void 0:i.code}),e.jsx("td",{className:"px-4 py-3 text-sm",children:(u=(x=t.invoice)==null?void 0:x.client)==null?void 0:u.name}),e.jsx("td",{className:"px-4 py-3 text-sm font-semibold text-green-700",children:R(t.amount)}),e.jsx("td",{className:"px-4 py-3 text-sm capitalize",children:(h=t.payment_method)==null?void 0:h.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 receipts found."})})]})]})})]})]})}export{E as default};
