PageSourceSearch

https://arrow-education.vercel.app/_next/static/chunks/81325-38576d3e6cc91f41.js

js arrow-education.vercel.app collected 2026-10-03 06:08:26 UTC 58,897 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[81325],{1556:(e,n,s)=>{s.d(n,{i:()=>l});var t=s(12115),a=s(18720),i=s(99776),r=s(95155),c=s(80991);function o(e){let{message:n}=e,[s,a]=(0,t.useState)(5);return(0,t.useEffect)(()=>{let e=setInterval(()=>{a(n=>n>=90?(clearInterval(e),90):n<60?n+8:n+2)},150);return()=>clearInterval(e)},[]),(0,r.jsxs)(r.Fragment,{children:[n,(0,r.jsx)(c.k,{value:s,className:"absolute inset-x-0 bottom-0 h-1 rounded-none bg-current/25 [&_[data-slot=progress-indicator]]:bg-current"})]})}function l(){let e=(0,i.jE)();return{save:(0,t.useCallback)(n=>{let{promise:s,entityName:i,action:r="create",invalidateKeys:c,onServerSuccess:l}=n,d="update"===r?"updated":"created";a.oR.promise(s(),{className:"overflow-hidden",loading:(0,t.createElement)(o,{message:"".concat("update"===r?"Updating":"Creating"," ").concat(i,"...")}),success:n=>{if(c)for(let n of c)e.invalidateQueries({queryKey:n});if(l)try{Promise.resolve(l(n)).catch(e=>{console.error("[useOptimisticSave] onServerSuccess error:",e)})}catch(e){console.error("[useOptimisticSave] onServerSuccess error:",e)}return(null==n?void 0:n.pendingApproval)?"".concat(i.charAt(0).toUpperCase()+i.slice(1)," sent for approval. It takes effect once approved."):"".concat(i.charAt(0).toUpperCase()+i.slice(1)," ").concat(d," successfully.")},error:e=>{let n=e instanceof Error?e.message:"Failed to ".concat(r," ").concat(i);return{message:"Failed to ".concat(r," ").concat(i),description:n!=="Failed to ".concat(r," ").concat(i)?n:void 0,duration:5e3}}})},[e])}}},5301:(e,n,s)=>{s.d(n,{e:()=>D});var t=s(95155),a=s(12115),i=s(17742),r=s(22544),c=s(66942),o=s(50370),l=s(58775),d=s(41068),u=s(28215),m=s(3998),x=s(65142),f=s(31120),h=s(11186),v=s(64269),j=s(51834),p=s(41052),N=s(86948),y=s(86259),g=s(18332),b=s(18720),w=s(97858),C=s(1556),A=s(87321),E=s(67611),P=s(68939),S=s(82827),R=s(17670);function D(e){var n,s,D;let{open:k,onOpenChange:I,invoice:T,onPaymentSuccess:F}=e,{t:M}=(0,E.B)("finance"),[L,O]=(0,a.useState)([]),[B,K]=(0,a.useState)(!1),{save:q}=(0,C.i)(),Q=null!=(s=T.balanceDue)?s:T.totalAmount-T.paidAmount,J=(0,r.mN)({resolver:(0,c.u)(w.ueD),defaultValues:{invoiceId:T.id,customerId:T.customerId,amount:Q,paymentDate:(0,i.s)(new Date),paymentMethod:"BANK_TRANSFER",reference:"",notes:"",bankAccountId:""}});J.watch("paymentMethod");let z=J.watch("amount"),H=Math.max(0,z-Q),W=H>0;(0,a.useEffect)(()=>{k&&(V(),J.reset({invoiceId:T.id,customerId:T.customerId,amount:Q,paymentDate:(0,i.s)(new Date),paymentMethod:"BANK_TRANSFER",reference:"",notes:"",bankAccountId:""}))},[k,T,Q,J]);let V=async()=>{try{K(!0);let e=await fetch("/api/finance/bank-accounts?isActive=true");if(e.ok){let n=(await e.json()).bankAccounts||[];O(n)}else console.error("Failed to fetch bank accounts:",e.status)}catch(e){console.error("Error fetching bank accounts:",e)}finally{K(!1)}},{formatBase:$}=(0,P.H)(),{settings:_}=(0,S.Nn)(),U=null!=(D=null==_?void 0:_.allowOverpaymentCredit)&&D,Z=e=>new Date(e).toLocaleDateString("en-US",{year:"numeric",month:"long",day:"numeric"}),G=async e=>{let n={...e},s=T.id;I(!1),q({promise:async()=>{let e=await fetch("/api/finance/invoices/".concat(s,"/payments"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});if(!e.ok)throw Error((await e.json()).error||"Failed to record payment");return e.json()},entityName:"invoice payment",action:"create",onServerSuccess:e=>{var n;(null==(n=e.overpayment)?void 0:n.amount)>0&&e.overpayment.appliedToBalance&&b.oR.info(M("finance.invoices.payment.overpaymentCredited",{amount:$(e.overpayment.amount)})),F()}})};return(0,t.jsx)(j.lG,{open:k,onOpenChange:I,children:(0,t.jsxs)(j.Cf,{className:"sm:max-w-[600px] max-h-[90vh] overflow-y-auto",children:[(0,t.jsxs)(j.c7,{children:[(0,t.jsxs)(j.L3,{className:"flex items-center gap-2",children:[(0,t.jsx)(o.A,{className:"h-5 w-5"}),M("finance.invoices.payment.title",{number:T.invoiceNumber})]}),(0,t.jsx)(j.rr,{children:M("finance.invoices.payment.description")})]}),(0,t.jsxs)("div",{className:"space-y-6",children:[(0,t.jsxs)(N.Zp,{children:[(0,t.jsx)(N.aR,{className:"pb-3",children:(0,t.jsxs)(N.ZB,{className:"flex items-center gap-2 text-base",children:[(0,t.jsx)(l.A,{className:"h-4 w-4"}),M("finance.invoices.payment.invoiceSummaryTitle")]})}),(0,t.jsxs)(N.Wu,{className:"space-y-3",children:[(0,t.jsxs)("div",{className:"flex justify-between",children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:M("finance.invoices.payment.customer")}),(0,t.jsx)("span",{className:"font-medium",children:(null==(n=T.customer)?void 0:n.name)||M("finance.invoices.payment.unknownCustomer")})]}),(0,t.jsxs)("div",{className:"flex justify-between",children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:M("finance.invoices.payment.invoiceDate")}),(0,t.jsx)("span",{children:Z(T.invoiceDate)})]}),(0,t.jsxs)("div",{className:"flex justify-between",children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:M("finance.invoices.payment.dueDate")}),(0,t.jsx)("span",{children:Z(T.dueDate)})]}),(0,t.jsxs)("div",{className:"flex justify-between",children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:M("finance.invoices.payment.status")}),(0,t.jsx)("span",{className:(0,v.cn)("px-2 py-0.5 rounded text-xs font-medium","PAID"===T.status&&"bg-status-success-fill text-status-success-text","PARTIALLY_PAID"===T.status&&"bg-status-warning-fill text-status-warning-text","OVERDUE"===T.status&&"bg-status-danger-fill text-status-danger-text","SENT"===T.status&&"bg-status-info-fill text-status-info-text"),children:T.status})]}),(0,t.jsx)(y.w,{}),(0,t.jsxs)("div",{className:"flex justify-between",children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:M("finance.invoices.payment.totalAmount")}),(0,t.jsx)("span",{children:$(T.totalAmount)})]}),(0,t.jsxs)("div",{className:"flex justify-between",children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:M("finance.invoices.payment.alreadyPaid")}),(0,t.jsx)("span",{className:"text-status-success-text",children:$(T.paidAmount)})]}),(0,t.jsxs)("div",{className:"flex justify-between text-lg font-semibold",children:[(0,t.jsx)("span",{children:M("finance.invoices.payment.balanceDue")}),(0,t.jsx)("span",{className:(0,v.cn)(Q>0?"text-status-danger-text":"text-status-success-text"),children:$(Q)})]})]})]}),(0,t.jsx)(p.lV,{...J,children:(0,t.jsxs)("form",{onSubmit:J.handleSubmit(G),className:"space-y-4",children:[(0,t.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[(0,t.jsx)(p.zB,{control:J.control,name:"amount",render:e=>{let{field:n}=e;return(0,t.jsxs)(p.eI,{children:[(0,t.jsx)(p.lR,{children:M("finance.invoices.payment.amountLabel")}),(0,t.jsx)(p.MJ,{children:(0,t.jsxs)("div",{className:"relative",children:[(0,t.jsx)(d.A,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),(0,t.jsx)(x.p,{type:"number",step:"0.01",min:"0.01",placeholder:"0.00",className:"pl-9",...n,onChange:e=>{let s=parseFloat(e.target.value)||0;n.onChange(s)}})]})}),(0,t.jsx)(p.C5,{}),z>0&&(0,t.jsxs)("div",{className:"text-sm text-muted-foreground",children:[z===Q?M("finance.invoices.payment.typeFullPayment"):z<Q?M("finance.invoices.payment.typePartialPayment"):M("finance.invoices.payment.typeOverpayment"),z<Q&&(0,t.jsx)("span",{className:"block",children:M("finance.invoices.payment.remaining",{amount:$(Math.max(0,Q-z))})})]})]})}}),(0,t.jsx)(p.zB,{control:J.control,name:"paymentDate",render:e=>{let{field:n}=e;return(0,t.jsxs)(p.eI,{className:"space-y-2",children:[(0,t.jsx)(p.lR,{children:M("finance.invoices.payment.dateLabel")}),(0,t.jsx)(p.MJ,{children:(0,t.jsx)(A.t,{value:(0,i.c)(n.value),onChange:e=>{e&&n.onChange((0,i.s)(e))}})}),(0,t.jsx)(p.C5,{})]})}}),(0,t.jsx)(p.zB,{control:J.control,name:"paymentMethod",render:e=>{let{field:n}=e;return(0,t.jsxs)(p.eI,{children:[(0,t.jsx)(p.lR,{children:M("finance.invoices.payment.methodLabel")}),(0,t.jsxs)(h.l6,{onValueChange:n.onChange,value:n.value,children:[(0,t.jsx)(p.MJ,{children:(0,t.jsx)(h.bq,{children:(0,t.jsx)(h.yv,{placeholder:M("finance.invoices.payment.methodPlaceholder")})})}),(0,t.jsxs)(h.gC,{children:[(0,t.jsx)(h.eb,{value:"CASH",children:M("finance.invoices.payment.methodCash")}),(0,t.jsx)(h.eb,{value:"CHECK",children:M("finance.invoices.payment.methodCheck")}),(0,t.jsx)(h.eb,{value:"CREDIT_CARD",children:M("finance.invoices.payment.methodCreditCard")}),(0,t.jsx)(h.eb,{value:"BANK_TRANSFER",children:M("finance.invoices.payment.methodBankTransfer")}),(0,t.jsx)(h.eb,{value:"OTHER",children:M("finance.invoices.payment.methodOther")})]})]}),(0,t.jsx)(p.C5,{})]})}}),(0,t.jsx)(p.zB,{control:J.control,name:"bankAccountId",render:e=>{var n;let{field:s}=e;return(0,t.jsxs)(p.eI,{children:[(0,t.jsx)(p.lR,{children:M("finance.invoices.payment.depositAccountLabel")}),(0,t.jsxs)(h.l6,{onValueChange:s.onChange,value:s.value||"",children:[(0,t.jsx)(p.MJ,{children:(0,t.jsx)(h.bq,{className:"w-full",children:(0,t.jsx)(h.yv,{placeholder:M("finance.invoices.payment.depositAccountPlaceholder"),children:null==(n=L.find(e=>e.id===s.value))?void 0:n.accountName})})}),(0,t.jsx)(h.gC,{children:L.map(e=>(0,t.jsx)(h.eb,{value:e.id,children:(0,t.jsxs)("div",{className:"flex flex-col",children:[(0,t.jsx)("span",{className:"font-medium",children:e.accountName}),(0,t.jsx)("span",{className:"text-xs text-muted-foreground",children:(0,R.e)(e)})]})},e.id))})]}),(0,t.jsx)(p.C5,{})]})}})]}),(0,t.jsx)(p.zB,{control:J.control,name:"reference",render:e=>{let{field:n}=e;return(0,t.jsxs)(p.eI,{children:[(0,t.jsx)(p.lR,{children:M("finance.invoices.payment.referenceLabel")}),(0,t.jsx)(p.MJ,{children:(0,t.jsx)(x.p,{placeholder:M("finance.invoices.payment.referencePlaceholder"),...n})}),(0,t.jsx)(p.C5,{})]})}}),(0,t.jsx)(p.zB,{control:J.control,name:"notes",render:e=>{let{field:n}=e;return(0,t.jsxs)(p.eI,{children:[(0,t.jsx)(p.lR,{children:M("finance.invoices.payment.notesLabel")}),(0,t.jsx)(p.MJ,{children:(0,t.jsx)(f.T,{placeholder:M("finance.invoices.payment.notesPlaceholder"),...n})}),(0,t.jsx)(p.C5,{})]})}}),W&&(0,t.jsxs)(g.Fc,{variant:U?"default":"destructive",children:[(0,t.jsx)(u.A,{className:"h-4 w-4"}),(0,t.jsx)(g.TN,{children:U?M("finance.invoices.payment.overpaymentWillBeCredited",{amount:$(H)}):M("finance.invoices.payment.overpaymentRefused",{amount:$(H),balance:$(Q)})})]})]})})]}),(0,t.jsxs)(j.Es,{children:[(0,t.jsx)(m.$,{variant:"outline",onClick:()=>I(!1),children:M("finance.invoices.payment.btnCancel")}),(0,t.jsx)(m.$,{onClick:J.handleSubmit(G),disabled:W&&!U,children:M("finance.invoices.payment.btnRecord")})]})]})})}},11647:(e,n,s)=>{s.d(n,{E:()=>l});var t=s(95155);s(12115);var a=s(32467),i=s(83101),r=s(64269),c=s(54354);let o=(0,i.F)("inline-flex items-center justify-center rounded-md border px-2 py-0.5 text-xs font-medium w-fit whitespace-nowrap shrink-0 [&>svg]:size-3 gap-1 [&>svg]:pointer-events-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive transition-[color,box-shadow] overflow-hidden",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground [a&]:hover:bg-primary/90",secondary:"border-transparent bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90",destructive:"border-transparent bg-destructive text-white [a&]:hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",outline:"text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground"}},defaultVariants:{variant:"default"}});function l(e){let{className:n,variant:s,kind:i,appearance:l="soft",asChild:d=!1,style:u,...m}=e,x=d?a.DX:"span",f=i?"outline"===l?{borderColor:(0,c.qi)(i).borderColor,...(0,c.H5)(i)}:{...(0,c.qi)(i),...(0,c.H5)(i)}:void 0;return(0,t.jsx)(x,{"data-slot":"badge","data-kind":i,"data-appearance":i?l:void 0,className:(0,r.cn)(i?o({variant:null}):o({variant:s}),n),style:f?{...f,...u}:u,...m})}},17670:(e,n,s)=>{s.d(n,{e:()=>t});function t(e){let n=e.accountNumber?"****".concat(e.accountNumber.slice(-4)):"";
1return[e.bankName,n].filter(Boolean).join(" - ")}},22955:(e,n,s)=>{s.d(n,{G:()=>t,s:()=>a});let t=["BANK_TRANSFER","CHECK","CASH","CREDIT_CARD_REVERSAL","OTHER"];function a(e,n,s){var t;return n.errorKey?String(e(n.errorKey,null!=(t=n.details)?t:{})):e(s)}},31409:(e,n,s)=>{s.d(n,{O:()=>h});var t=s(95155),a=s(12115),i=s(18720),r=s(83437),c=s(3998),o=s(65142),l=s(76444),d=s(51834),u=s(67611),m=s(68939),x=s(86540),f=s(22955);function h(e){let{open:n,onOpenChange:s,customer:h,onRequested:v}=e,{t:j}=(0,u.B)("finance"),{formatBase:p}=(0,m.H)(),[N,y]=(0,a.useState)(null),[g,b]=(0,a.useState)(0),[w,C]=(0,a.useState)(x.KW),[A,E]=(0,a.useState)(!1);(0,a.useEffect)(()=>{n&&(C(x.KW),y(null),(async()=>{try{let e=await fetch("/api/finance/customers/".concat(h.id,"/refunds"));if(!e.ok)throw Error();let n=await e.json();y(n.refundable),b(n.refundable)}catch(e){i.oR.error(j("finance.refunds.credit.loadFailed"))}})())},[n,h.id,j]);let P=null!==N&&g>N,S=async()=>{E(!0);try{let e=await fetch("/api/finance/customers/".concat(h.id,"/refunds"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...(0,x.IO)(w),amount:g})}),n=await e.json().catch(()=>({}));if(!e.ok)return void i.oR.error((0,f.s)(j,n,"finance.refunds.create.errorFailed"));i.oR.success(j("finance.refunds.create.successTitle"),{description:j("finance.refunds.create.successDescription",{amount:p(n.refund.amount)})}),s(!1),v()}catch(e){i.oR.error(j("finance.refunds.create.errorFailed"))}finally{E(!1)}};return(0,t.jsx)(d.lG,{open:n,onOpenChange:s,children:(0,t.jsxs)(d.Cf,{className:"sm:max-w-[560px] max-h-[90vh] overflow-y-auto",children:[(0,t.jsxs)(d.c7,{children:[(0,t.jsxs)(d.L3,{className:"flex items-center gap-2",children:[(0,t.jsx)(r.A,{className:"h-5 w-5"}),j("finance.refunds.credit.title")]}),(0,t.jsx)(d.rr,{children:j("finance.refunds.credit.description",{name:h.name})})]}),(0,t.jsxs)("div",{className:"flex items-baseline justify-between rounded-md border px-4 py-3",children:[(0,t.jsx)("span",{className:"text-sm text-muted-foreground",children:j("finance.refunds.credit.available")}),(0,t.jsx)("span",{className:"font-mono font-semibold",children:null===N?"":p(N)})]}),(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(l.J,{htmlFor:"refund-credit-amount",children:j("finance.refunds.credit.amountLabel")}),(0,t.jsx)(o.p,{id:"refund-credit-amount",type:"number",step:"any",min:"0",max:null!=N?N:void 0,value:g,onChange:e=>b(parseFloat(e.target.value)||0)}),P&&null!==N&&(0,t.jsx)("p",{className:"text-sm text-destructive",children:j("finance.refunds.credit.exceeds",{amount:p(N)})})]}),(0,t.jsx)(x.H6,{value:w,onChange:C}),(0,t.jsxs)(d.Es,{children:[(0,t.jsx)(c.$,{variant:"outline",onClick:()=>s(!1),disabled:A,children:j("common.actions.cancel",{ns:"common"})}),(0,t.jsx)(c.$,{onClick:S,disabled:A||P||g<=0||!(0,x.J8)(w),children:A?j("finance.refunds.create.submitting"):j("finance.refunds.create.submit")})]})]})})}},40113:(e,n,s)=>{s.d(n,{K:()=>i,i:()=>a});var t=s(17742);function a(e){var n,s;return e?null!=(s=null==(n=(0,t.c)(e))?void 0:n.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"}))?s:e:""}function i(e){return e?new Date(e).toLocaleString(void 0,{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}):""}},41052:(e,n,s)=>{s.d(n,{C5:()=>p,MJ:()=>v,Rr:()=>j,eI:()=>f,lR:()=>h,lV:()=>l,zB:()=>u});var t=s(95155),a=s(12115),i=s(32467),r=s(22544),c=s(64269),o=s(76444);let l=r.Op,d=a.createContext({}),u=e=>{let{...n}=e;return(0,t.jsx)(d.Provider,{value:{name:n.name},children:(0,t.jsx)(r.xI,{...n})})},m=()=>{let e=a.useContext(d),n=a.useContext(x),{getFieldState:s}=(0,r.xW)(),t=(0,r.lN)({name:e.name}),i=s(e.name,t);if(!e)throw Error("useFormField should be used within <FormField>");let{id:c}=n;return{id:c,name:e.name,formItemId:"".concat(c,"-form-item"),formDescriptionId:"".concat(c,"-form-item-description"),formMessageId:"".concat(c,"-form-item-message"),...i}},x=a.createContext({});function f(e){let{className:n,...s}=e,i=a.useId();return(0,t.jsx)(x.Provider,{value:{id:i},children:(0,t.jsx)("div",{"data-slot":"form-item",className:(0,
1c.cn)("grid gap-2",n),...s})})}function h(e){let{className:n,...s}=e,{error:a,formItemId:i}=m();return(0,t.jsx)(o.J,{"data-slot":"form-label","data-error":!!a,className:(0,c.cn)("data-[error=true]:text-destructive",n),htmlFor:i,...s})}function v(e){let{...n}=e,{error:s,formItemId:a,formDescriptionId:r,formMessageId:c}=m();return(0,t.jsx)(i.DX,{"data-slot":"form-control",id:a,"aria-describedby":s?"".concat(r," ").concat(c):"".concat(r),"aria-invalid":!!s,...n})}function j(e){let{className:n,...s}=e,{formDescriptionId:a}=m();return(0,t.jsx)("p",{"data-slot":"form-description",id:a,className:(0,c.cn)("text-muted-foreground text-sm",n),...s})}function p(e){var n;let{className:s,...a}=e,{error:i,formMessageId:r}=m(),o=i?String(null!=(n=null==i?void 0:i.message)?n:""):a.children;return o?(0,t.jsx)("p",{"data-slot":"form-message",id:r,className:(0,c.cn)("text-destructive text-sm",s),...a,children:o}):null}},51834:(e,n,s)=>{s.d(n,{Cf:()=>m,Es:()=>f,HM:()=>d,L3:()=>h,c7:()=>x,lG:()=>c,rr:()=>v,zM:()=>o});var t=s(95155);s(12115);var a=s(89511),i=s(34788),r=s(64269);function c(e){let{...n}=e;return(0,t.jsx)(a.bL,{"data-slot":"dialog",...n})}function o(e){let{...n}=e;return(0,t.jsx)(a.l9,{"data-slot":"dialog-trigger",...n})}function l(e){let{...n}=e;return(0,t.jsx)(a.ZL,{"data-slot":"dialog-portal",...n})}function d(e){let{...n}=e;return(0,t.jsx)(a.bm,{"data-slot":"dialog-close",...n})}function u(e){let{className:n,...s}=e;return(0,t.jsx)(a.hJ,{"data-slot":"dialog-overlay",className:(0,r.cn)("data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",n),...s})}function m(e){let{className:n,children:s,...c}=e,o=/(?:^|\s)\S*max-w-/.test(null!=n?n:"");return(0,t.jsxs)(l,{"data-slot":"dialog-portal",children:[(0,t.jsx)(u,{}),(0,t.jsxs)(a.UC,{"data-slot":"dialog-content",className:(0,r.cn)("bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border p-6 shadow-lg duration-200",!o&&"sm:max-w-lg",n),...c,children:[s,(0,t.jsxs)(a.bm,{className:"focus-visible:ring-ring/50 data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus-visible:ring-[3px] outline-none disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",children:[(0,t.jsx)(i.A,{}),(0,t.jsx)("span",{className:"sr-only",children:"Close"})]})]})]})}function x(e){let{className:n,...s}=e;return(0,t.jsx)("div",{"data-slot":"dialog-header",className:(0,r.cn)("flex flex-col gap-2 text-center sm:text-left",n),...s})}function f(e){let{className:n,...s}=e;return(0,t.jsx)("div",{"data-slot":"dialog-footer",className:(0,r.cn)("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",n),...s})}function h(e){let{className:n,...s}=e;return(0,t.jsx)(a.hE,{"data-slot":"dialog-title",className:(0,r.cn)("text-lg leading-none font-semibold",n),...s})}function v(e){let{className:n,...s}=e;return(0,t.jsx)(a.VY,{"data-slot":"dialog-description",className:(0,r.cn)("text-muted-foreground text-sm",n),...s})}},54354:(e,n,s)=>{s.d(n,{H5:()=>d,qe:()=>
1o,qi:()=>c,wP:()=>l});let t={success:"var(--status-success)",warning:"var(--status-warning)",danger:"var(--status-danger)",info:"var(--status-info)",neutral:"var(--status-neutral)"},a={success:"var(--status-success-fill)",warning:"var(--status-warning-fill)",danger:"var(--status-danger-fill)",info:"var(--status-info-fill)",neutral:"var(--status-neutral-fill)"},i={success:"var(--status-success-border)",warning:"var(--status-warning-border)",danger:"var(--status-danger-border)",info:"var(--status-info-border)",neutral:"var(--status-neutral-border)"},r={success:"var(--status-success-text)",warning:"var(--status-warning-text)",danger:"var(--status-danger-text)",info:"var(--status-info-text)",neutral:"var(--status-neutral-text)"};function c(e){return{backgroundColor:a[e],borderColor:i[e]}}function o(e){return c(e)}function l(e){return t[e]}function d(e){return{color:r[e]}}},81325:(e,n,s)=>{s.d(n,{q:()=>G});var t=s(95155),a=s(12115),i=s(35354),r=s(58775),c=s(79564),o=s(41068),l=s(58164),d=s(50370),u=s(96205),m=s(57419),x=s(23916),f=s(39013),h=s(89840),v=s(27906),j=s(38629),p=s(83437),N=s(27667),y=s(3998),g=s(11647),b=s(51834),w=s(87270),C=s(86948),A=s(86259),E=s(18720),P=s(68939),S=s(5301),R=s(67611),D=s(22544),k=s(66942),I=s(84107),T=s(31120),F=s(73457),M=s(41052),L=s(18332),O=s(97858);function B(e){var n,s,i,r;let{open:c,onOpenChange:o,payment:l,onVoidSuccess:d}=e,[u,m]=(0,a.useState)(!1),{t:x}=(0,R.B)("finance"),h=(0,D.mN)({resolver:(0,k.u)(O.wTR),defaultValues:{paymentId:l.id,reason:"",confirmVoid:!1}}),v=h.watch("confirmVoid"),j=e=>new Intl.NumberFormat("en-US",{style:"currency",currency:"USD"}).format(e),p=async e=>{try{var n;m(!0);let s=await fetch("/api/finance/payments/".concat(l.id,"/void"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!s.ok){let e=await s.json();throw Error(e.error||"Failed to void payment")}let t=await s.json();E.oR.success(x("finance.invoices.voidPaymentModal.toast.success")),(null==(n=t.invoiceUpdated)?void 0:n.statusChanged)&&E.oR.info(x("finance.invoices.voidPaymentModal.toast.statusChanged",{previousStatus:t.invoiceUpdated.previousStatus,newStatus:t.invoiceUpdated.newStatus})),d(),o(!1)}catch(e){console.error("Error voiding payment:",e),E.oR.error(e instanceof Error?e.message:x("finance.invoices.voidPaymentModal.toast.error"))}finally{m(!1)}},N=(null==(n=l.invoice)?void 0:n.paidAmount)||0,g=Math.max(0,N-l.amount),w=((null==(s=l.invoice)?void 0:s.totalAmount)||0)-g;return(0,t.jsx)(b.lG,{open:c,onOpenChange:o,children:(0,t.jsxs)(b.Cf,{className:"sm:max-w-[550px]",children:[(0,t.jsxs)(b.c7,{children:[(0,t.jsxs)(b.L3,{className:"flex items-center gap-2 text-destructive",children:[(0,t.jsx)(f.A,{className:"h-5 w-5"}),x("finance.invoices.voidPaymentModal.title")]}),(0,t.jsx)(b.rr,{children:x("finance.invoices.voidPaymentModal.description")})]}),(0,t.jsxs)("div",{className:"space-y-6",children:[(0,t.jsxs)(L.Fc,{variant:"destructive",children:[(0,t.jsx)(I.A,{className:"h-4 w-4"}),(0,t.jsx)(L.XL,{children:x("finance.invoices.voidPaymentModal.warningTitle")}),(0,t.jsxs)(L.TN,{children:[x("finance.invoices.voidPaymentModal.warningDescription"),(0,t.jsxs)("ul",{className:"list-disc list-inside mt-2 space-y-1",children:[(0,t.jsx)("li",{children:x("finance.invoices.voidPaymentModal.warningItem1")}),(0,t.jsx)("li",{children:x("finance.invoices.voidPaymentModal.warningItem2",{amount:j(l.amount)})}),(0,t.jsx)("li",{children:x("finance.invoices.voidPaymentModal.warningItem3")})]})]})]}),(0,t.jsxs)(C.Zp,{children:[(0,t.jsx)(C.aR,{className:"pb-3",children:(0,t.jsx)(C.ZB,{className:"text-base",children:x("finance.invoices.voidPaymentModal.paymentDetailsTitle")})}),(0,t.jsxs)(C.Wu,{className:"space-y-3",children:[(0,t.jsxs)("div",{className:"flex justify-between",children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:x("finance.invoices.voidPaymentModal.invoice")}),(0,t.jsxs)("span",{className:"font-medium",children:["#",null==(i=l.invoice)?void 0:i.invoiceNumber]})]}),(0,t.jsxs)("div",{className:"flex justify-between",children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:x("finance.invoices.voidPaymentModal.customer")}),(0,t.jsx)("span",{children:(null==(r=l.customer)?void 0:r.name)||x("finance.invoices.voidPaymentModal.unknownCustomer")})]}),(0,t.jsxs)("div",{className:"flex justify-between",children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:x("finance.invoices.voidPaymentModal.paymentDate")}),(0,t.jsx)("span",{children:new Date(l.paymentDate).toLocaleDateString("en-US",{year:"numeric",month:"long",day:"numeric"})})]}),(0,t.jsxs)("div",{className:"flex justify-between",children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:x("finance.invoices.voidPaymentModal.paymentMethod")}),(0,t.jsx)("span",{children:l.paymentMethod})]}),l.reference&&(0,t.jsxs)("div",{className:"flex justify-between",children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:x("finance.invoices.voidPaymentModal.reference")}),(0,t.jsx)("span",{children:l.reference})]}),(0,t.jsx)(A.w,{}),(0,t.jsxs)("div",{className:"flex justify-between text-lg font-semibold",children:[(0,t.jsx)("span",{children:x("finance.invoices.voidPaymentModal.amountToVoid")}),(0,t.jsx)("span",{className:"text-destructive",children:j(l.amount)})]})]})]}),(0,t.jsxs)(C.Zp,{children:[(0,t.jsx)(C.aR,{className:"pb-3",children:(0,t.jsx)(C.ZB,{className:"text-base",children:x("finance.invoices.voidPaymentModal.invoiceImpactTitle")})}),(0,t.jsxs)(C.Wu,{className:"space-y-2",children:[(0,t.jsxs)("div",{className:"flex justify-between text-sm",children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:x("finance.invoices.voidPaymentModal.currentPaidAmount")}),(0,t.jsx)("span",{children:j(N)})]}),(0,t.jsxs)("div",{className:"flex justify-between text-sm",children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:x("finance.invoices.voidPaymentModal.afterVoid")}),(0,t.jsx)("span",{children:j(g)})]}),(0,t.jsx)(A.w,{}),(0,t.jsxs)("div",{className:"flex justify-between font-medium",children:[(0,t.jsx)("span",{children:x("finance.invoices.voidPaymentModal.newBalanceDue")}),(0,t.jsx)("span",{className:"text-status-danger-text",children:j(w)})]})]})]}),(0,t.jsx)(M.lV,{...h,children:(0,t.jsxs)("form",{onSubmit:h.handleSubmit(p),className:"space-y-4",children:[(0,t.jsx)(M.zB,{control:h.control,name:"reason",render:e=>{let{field:n}=e;return(0,t.jsxs)(M.eI,{children:[(0,t.jsx)(M.lR,{children:x("finance.invoices.voidPaymentModal.reasonLabel")}),(0,t.jsx)(M.MJ,{children:(0,t.jsx)(T.T,{placeholder:x("finance.invoices.voidPaymentModal.reasonPlaceholder"),className:"min-h-[100px]",...n})}),(0,t.jsx)(M.Rr,{children:x("finance.invoices.voidPaymentModal.reasonDescription")}),(0,t.jsx)(M.C5,{})]})}}),(0,t.jsx)(M.zB,{control:h.control,name:"confirmVoid",render:e=>{let{field:n}=e;return(0,t.jsxs)(M.eI,{className:"flex flex-row items-start space-x-3 space-y-0 rounded-md border p-4 bg-destructive/5",children:[(0,t.jsx)(M.MJ,{children:(0,t.jsx)(F.S,{checked:n.value,onCheckedChange:n.onChange})}),(0,t.jsxs)("div",{className:"space-y-1 leading-none",children:[(0,t.jsx)(M.lR,{className:"font-medium",children:x("finance.invoices.voidPaymentModal.confirmLabel")}),(0,t.jsx)(M.Rr,{children:x("finance.invoices.voidPaymentModal.confirmDescription")})]})]})}})]})})]}),(0,t.jsxs)(b.Es,{children:[(0,t.jsx)(y.$,{variant:"outline",onClick:()=>o(!1),disabled:u,children:x("common.actions.cancel",{ns:"common"})}),(0,t.jsx)(y.$,{variant:"destructive",onClick:h.handleSubmit(p),disabled:u||!v,children:u?x("finance.invoices.voidPaymentModal.voidingPayment"):x("finance.invoices.voidPaymentModal.voidPayment")})]})]})})}var K=s(65142),q=s(86540),Q=s(22955);function J(e){var n;let{open:s,onOpenChange:i,invoice:r,paymentId:c,onRequested:o}=e,{t:l}=(0,R.B)("finance"),{formatBase:d}=(0,P.H)(),[u,m]=(0,a.useState)([]),[x,f]=(0,a.useState)(q.KW),[h,v]=(0,a.useState)(null),[j,N]=(0,a.useState)(null),[g,C]=(0,a.useState)(!1);(0,a.useEffect)(()=>{var e;s&&(f(q.KW),v(null),N(null),m((null!=(e=r.items)?e:[]).map(e=>({...e,included:!0,creditQuantity:Number(e.quantity)}))))},[s,r.items]);let S=(0,a.useMemo)(()=>u.filter(e=>e.included&&e.creditQuantity>0).map(e=>{var n;return{description:e.description,quantity:e.creditQuantity,unitPrice:Number(e.unitPrice),taxRate:void 0===e.taxRate||null===e.taxRate?void 0:Number(e.taxR
1ate),accountId:e.accountId,departmentId:null!=(n=e.departmentId)?n:null}}),[u]);(0,a.useEffect)(()=>{if(!s)return;if(0===S.length){v(null),N(null);return}let e=new AbortController,n=setTimeout(async()=>{try{let n=await fetch("/api/finance/invoices/".concat(r.id,"/refunds?preview=true"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({items:S}),signal:e.signal}),s=await n.json().catch(()=>({}));if(!n.ok){v(null),N((0,Q.s)(l,s,"finance.refunds.create.previewFailed"));return}v(s),N(null)}catch(e){"AbortError"!==e.name&&N(l("finance.refunds.create.previewFailed"))}},300);return()=>{clearTimeout(n),e.abort()}},[s,r.id,S]);let D=async()=>{C(!0);try{let e=await fetch("/api/finance/invoices/".concat(r.id,"/refunds"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...(0,q.IO)(x),items:S,...c?{paymentId:c}:{}})}),n=await e.json().catch(()=>({}));if(!e.ok)return void E.oR.error((0,Q.s)(l,n,"finance.refunds.create.errorFailed"));E.oR.success(l("finance.refunds.create.successTitle"),{description:l("finance.refunds.create.successDescription",{amount:d(n.refund.amount)})}),i(!1),o()}catch(e){E.oR.error(l("finance.refunds.create.errorFailed"))}finally{C(!1)}},k=null!=(n=null==h?void 0:h.moneyBack)?n:0;return(0,t.jsx)(b.lG,{open:s,onOpenChange:i,children:(0,t.jsxs)(b.Cf,{className:"sm:max-w-3xl max-h-[90vh] overflow-y-auto",children:[(0,t.jsxs)(b.c7,{children:[(0,t.jsxs)(b.L3,{className:"flex items-center gap-2",children:[(0,t.jsx)(p.A,{className:"h-5 w-5"}),l("finance.refunds.create.title",{number:r.invoiceNumber})]}),(0,t.jsx)(b.rr,{children:l("finance.refunds.create.description")})]}),(0,t.jsxs)(w.XI,{children:[(0,t.jsx)(w.A0,{children:(0,t.jsxs)(w.Hj,{children:[(0,t.jsx)(w.nd,{className:"w-8"}),(0,t.jsx)(w.nd,{children:l("finance.invoices.create.colDescription")}),(0,t.jsx)(w.nd,{className:"text-right",children:l("finance.invoices.creditNote.colInvoiced")}),(0,t.jsx)(w.nd,{className:"text-right",children:l("finance.refunds.create.colTakeBack")}),(0,t.jsx)(w.nd,{className:"text-right",children:l("finance.invoices.create.colUnitPrice")})]})}),(0,t.jsx)(w.BF,{children:u.map((e,n)=>(0,t.jsxs)(w.Hj,{children:[(0,t.jsx)(w.nA,{children:(0,t.jsx)(F.S,{checked:e.included,onCheckedChange:e=>m(s=>s.map((s,t)=>t===n?{...s,included:!0===e}:s))})}),(0,t.jsx)(w.nA,{children:e.description}),(0,t.jsx)(w.nA,{className:"text-right font-mono",children:Number(e.quantity)}),(0,t.jsx)(w.nA,{className:"text-right",children:(0,t.jsx)(K.p,{type:"number",min:0,max:Number(e.quantity),step:"0.01",disabled:!e.included,value:e.creditQuantity,onChange:e=>m(s=>s.map((s,t)=>t===n?{...s,creditQuantity:Math.min(Number(s.quantity),Math.max(0,parseFloat(e.target.value)||0))}:s)),className:"w-24 text-right ml-auto"})}),(0,t.jsx)(w.nA,{className:"text-right font-mono",children:d(Number(e.unitPrice))})]},e.id))})]}),(0,t.jsxs)("div",{className:"rounded-md border px-4 py-3 space-y-1 text-sm",children:[h&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"flex justify-between",children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:l("finance.refunds.create.takenBack")}),(0,t.jsx)("span",{className:"font-mono",children:d(h.creditTotal)})]}),(0,t.jsxs)("div",{className:"flex justify-between",children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:l("finance.refunds.create.stillOwed")}),(0,t.jsx)("span",{className:"font-mono",children:d(h.owed)})]})]}),(0,t.jsxs)("div",{className:"flex justify-between font-medium pt-1",children:[(0,t.jsx)("span",{children:l("finance.refunds.create.moneyBack")}),(0,t.jsx)("span",{className:"font-mono text-base",children:d(k)})]}),j&&(0,t.jsx)("p",{className:"text-destructive pt-1",children:j}),h&&k<=0&&!j&&(0,t.jsx)("p",{className:"text-muted-foreground pt-1",children:l("finance.refunds.create.nothingBack")})]}),(0,t.jsx)(A.w,{}),(0,t.jsx)(q.H6,{value:x,onChange:f}),(0,t.jsxs)(b.Es,{children:[(0,t.jsx)(y.$,{variant:"outline",onClick:()=>i(!1),disabled:g,children:l("common.actions.cancel",{ns:"common"})}),(0,t.jsx)(y.$,{onClick:D,disabled:g||!(0,q.J8)(x)||k<=0||!!j,children:g?l("finance.refunds.create.submitting"):l("finance.refunds.create.submit")})]})]})})}var z=s(31409),H=s(40113),W=s(10223),V=s(99776),$=s(76444),_=s(62108);function U(e){let{isOpen:n,onClose:s,invoice:i,onRaised:r}=e,{t:c}=(0,R.B)("finance"),{formatBase:o}=(0,P.H)(),l=(0,V.jE)(),[d,u]=(0,a.useState)(""),[m,x]=(0,a.useState)(!1),[f,h]=(0,a.useState)([]);(0,a.useEffect)(()=>{var e;n&&(u(""),h((null!=(e=i.items)?e:[]).map(e=>({...e,included:!0,creditQuantity:Number(e.quantity)}))))},[n,i.items]);let v=f.filter(e=>e.included&&e.creditQuantity>0).reduce((e,n)=>e+n.creditQuantity*Number(n.unitPrice),0),j=Number(i.totalAmount)-Number(i.paidAmount),p=async()=>{let e=f.filter(e=>e.included&&e.creditQuantity>0).map(e=>{var n;return{description:e.description,quantity:e.creditQuantity,unitPrice:Number(e.unitPrice),taxRate:void 0===e.taxRate||null===e.taxRate?void 0:Number(e.taxR
1ate),accountId:e.accountId,departmentId:null!=(n=e.departmentId)?n:null}});if(0===e.length)return void E.oR.error(c("finance.invoices.creditNote.noLines"));try{x(!0);let n=await fetch("/api/finance/invoices/".concat(i.id,"/credit-note"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({reason:d,items:e})}),t=await n.json();if(!n.ok)throw Error(t.errorKey?c(t.errorKey,t.details):t.error||c("finance.invoices.creditNote.failed"));E.oR.success(c("finance.invoices.creditNote.raised",{number:t.data.invoiceNumber,entry:t.data.entryNumber})),l.invalidateQueries({queryKey:_.WQ.all}),null==r||r(t.data.invoiceNumber),s()}catch(e){E.oR.error(e instanceof Error?e.message:c("finance.invoices.creditNote.failed"))}finally{x(!1)}};return(0,t.jsx)(b.lG,{open:n,onOpenChange:e=>{e||s()},children:(0,t.jsxs)(b.Cf,{className:"sm:max-w-2xl",children:[(0,t.jsxs)(b.c7,{children:[(0,t.jsx)(b.L3,{children:c("finance.invoices.creditNote.title",{number:i.invoiceNumber})}),(0,t.jsx)(b.rr,{children:c("finance.invoices.creditNote.description")})]}),(0,t.jsxs)(w.XI,{children:[(0,t.jsx)(w.A0,{children:(0,t.jsxs)(w.Hj,{children:[(0,t.jsx)(w.nd,{className:"w-8"}),(0,t.jsx)(w.nd,{children:c("finance.invoices.create.colDescription")}),(0,t.jsx)(w.nd,{className:"text-right",children:c("finance.invoices.creditNote.colInvoiced")}),(0,t.jsx)(w.nd,{className:"text-right",children:c("finance.invoices.creditNote.colCredit")}),(0,t.jsx)(w.nd,{className:"text-right",children:c("finance.invoices.create.colUnitPrice")})]})}),(0,t.jsx)(w.BF,{children:f.map((e,n)=>(0,t.jsxs)(w.Hj,{children:[(0,t.jsx)(w.nA,{children:(0,t.jsx)(F.S,{checked:e.included,onCheckedChange:e=>h(s=>s.map((s,t)=>t===n?{...s,included:!0===e}:s))})}),(0,t.jsx)(w.nA,{children:e.description}),(0,t.jsx)(w.nA,{className:"text-right font-mono",children:Number(e.quantity)}),(0,t.jsx)(w.nA,{className:"text-right",children:(0,t.jsx)(K.p,{type:"number",min:0,max:Number(e.quantity),step:"0.01",disabled:!e.included,value:e.creditQuantity,onChange:e=>h(s=>s.map((s,t)=>t===n?{...s,creditQuantity:Math.min(Number(s.quantity),Math.max(0,parseFloat(e.target.value)||0))}:s)),className:"w-24 text-right ml-auto"})}),(0,t.jsx)(w.nA,{className:"text-right font-mono",children:o(Number(e.unitPrice))})]},e.id))})]}),(0,t.jsxs)("div",{className:"flex justify-between text-sm",children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:c("finance.invoices.creditNote.balanceNote",{balance:o(j)})}),(0,t.jsx)("span",{className:"font-mono font-medium",children:c("finance.invoices.creditNote.total",{amount:o(v)})})]}),(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)($.J,{htmlFor:"credit-note-reason",children:c("finance.invoices.creditNote.reasonLabel")}),(0,t.jsx)(T.T,{id:"credit-note-reason",value:d,onChange:e=>u(e.target.value),placeholder:c("finance.invoices.creditNote.reasonPlaceholder"),rows:2,maxLength:500})]}),(0,t.jsxs)(b.Es,{children:[(0,t.jsx)(y.$,{variant:"outline",onClick:s,disabled:m,children:c("common.actions.cancel",{ns:"common"})}),(0,t.jsx)(y.$,{onClick:p,disabled:m||d.trim().length<5,children:m?c("finance.invoices.creditNote.raising"):c("finance.invoices.creditNote.raise")})]})]})})}var Z=s(80208);function G(e){var n,s,D,k,I,F,M,L,O,K,q,Q,$,G,X,Y,ee;let{isOpen:en,onClose:es,invoice:et,onEdit:ea,can:ei={update:!0,create:!0,recordPayment:!0}}=e,{t:er}=(0,R.B)("finance"),[ec,eo]=(0,a.useState)(!1),{formatCurrency:el}=(0,P.H)(),ed=(0,V.jE)(),[eu,em]=(0,a.useState)(!1),[ex,ef]=(0,a.useState)(!1),[eh,ev]=(0,a.useState)(!1),[ej,ep]=(0,a.useState)(!1),eN=(0,W.J)("create","finance_refund"),[ey,eg]=(0,a.useState)(null),[eb,ew]=(0,a.useState)(null),eC=()=>(Number(et.totalAmount)||0)-(Number(et.paidAmount)||0),eA=async()=>{try{eo(!0);let e=await fetch("/api/finance/invoices/".concat(et.id,"/apply-credit"),{method:"POST"}),n=await e.json();if(!e.ok)throw Error(n.errorKey?er(n.errorKey):n.error||er("finance.invoices.payment.creditApplyFailed"));E.oR.success(er("finance.invoices.payment.creditApplied",{amount:el(n.applied)})),ed.invalidateQueries({queryKey:_.WQ.all}),es()}catch(e){console.error("Error applying credit:",e),E.oR.error(e instanceof Error?e.message:er("finance.invoices.payment.creditApplyFailed"))}finally{eo(!1)}},eE=async()=>{try{var e;eo(!0);let n=await fetch("/api/finance/invoices/".concat(et.id,"/send"),{method:"POST"}),s=await n.json();if(!n.ok)throw Error(s.errorKey?er(s.errorKey):s.error||er("finance.invoices.view.sendFailed"));
1(null==(e=s.data)?void 0:e.emailSent)?E.oR.success(er("finance.invoices.view.sendSuccessEmailed",{number:et.invoiceNumber})):E.oR.success(er("finance.invoices.view.sendSuccessNoEmail",{number:et.invoiceNumber})),ed.invalidateQueries({queryKey:_.WQ.all}),es()}catch(e){console.error("Error sending invoice:",e),E.oR.error(e instanceof Error?e.message:er("finance.invoices.view.sendFailed"))}finally{eo(!1)}},eP=async()=>{try{eo(!0);let e=await fetch("/api/finance/invoices/".concat(et.id,"/pdf"),{method:"GET"});if(!e.ok){let n=await e.json();throw Error(n.error||"Failed to generate PDF")}let n=await e.blob(),s=window.URL.createObjectURL(n),t=document.createElement("a");t.href=s,t.download="Invoice-".concat(et.invoiceNumber,".pdf"),document.body.appendChild(t),t.click(),document.body.removeChild(t),window.URL.revokeObjectURL(s),E.oR.success("Invoice PDF downloaded successfully")}catch(e){console.error("Error downloading PDF:",e),E.oR.error(e instanceof Error?e.message:"Failed to download PDF")}finally{eo(!1)}},[eS,eR]=(0,a.useState)(!1),eD=async()=>{try{eo(!0);let e=await fetch("/api/finance/invoices/".concat(et.id),{method:"DELETE"});if(!e.ok){let n=await e.json();throw Error(n.errorKey?er(n.errorKey):n.error||er("finance.invoices.view.deleteFailed"))}E.oR.success(er("finance.invoices.view.deleted",{number:et.invoiceNumber})),ed.invalidateQueries({queryKey:_.WQ.all}),eR(!1),es()}catch(e){console.error("Error deleting invoice:",e),E.oR.error(e instanceof Error?e.message:er("finance.invoices.view.deleteFailed"))}finally{eo(!1)}},[ek,eI]=(0,a.useState)(!1),[eT,eF]=(0,a.useState)(""),eM=async()=>{try{eo(!0);let e=await fetch("/api/finance/invoices/".concat(et.id,"/cancel"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({reason:eT})}),n=await e.json();if(!e.ok)throw Error(n.errorKey?er(n.errorKey,n.details):n.error||er("finance.invoices.view.cancelFailed"));E.oR.success(n.data.orderCancelled?er("finance.invoices.view.cancelledWithOrder",{number:et.invoiceNumber}):er("finance.invoices.view.cancelled",{number:et.invoiceNumber})),ed.invalidateQueries({queryKey:_.WQ.all}),eI(!1),es()}catch(e){console.error("Error cancelling invoice:",e),E.oR.error(e instanceof Error?e.message:er("finance.invoices.view.cancelFailed"))}finally{eo(!1)}},[eL,eO]=(0,a.useState)(!1),eB="CREDIT_NOTE"===et.kind,eK="DRAFT"===et.status,eq=Number(et.paidAmount)>0||null!=(q=null==(n=et.payments)?void 0:n.some(e=>"VOIDED"!==e.status))&&q,eQ=()=>!eB&&("SENT"===et.status||"PARTIALLY_PAID"===et.status||"PAID"===et.status)&&!!ei.create,eJ=null!=(Q=null==(s=et.refunds)?void 0:s.some(e=>"PENDING"===e.status||"APPROVED"===e.status))&&Q,ez=null!=($=null==(D=et.customer)?void 0:D.creditBalance)?$:0;return(0,t.jsx)(b.lG,{open:en,onOpenChange:es,children:(0,t.jsxs)(b.Cf,{className:"sm:max-w-[85%] md:max-w-[80%] lg:max-w-[75%] xl:max-w-[1200px] max-h-[90vh] overflow-y-auto",children:[(0,t.jsxs)(b.c7,{children:[(0,t.jsxs)(b.L3,{className:"flex items-center gap-2",children:[(0,t.jsx)(i.A,{className:"h-5 w-5"}),er("finance.invoices.view.title",{number:et.invoiceNumber})]}),(0,t.jsx)(b.rr,{children:er("finance.invoices.view.description")}),"CREDIT_NOTE"===et.kind&&et.creditsInvoice&&(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:er("finance.invoices.view.creditsInvoice",{number:et.creditsInvoice.invoiceNumber})}),!!(null==(k=et.creditNotes)?void 0:k.length)&&(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:er("finance.invoices.view.creditedBy",{notes:et.creditNotes.map(e=>"".concat(e.invoiceNumber," (").concat(el(Number(e.totalAmount)),")")).join(", ")})}),"CANCELLED"===et.status&&et.cancelReason&&(0,t.jsx)("p",{className:"text-sm text-status-danger-text",children:er("finance.invoices.view.cancelledReason",{reason:et.cancelReason})})]}),(0,t.jsxs)("div",{className:"space-y-6",children:[(0,t.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[(0,t.jsxs)(C.Zp,{children:[(0,t.jsx)(C.aR,{children:(0,t.jsxs)(C.ZB,{className:"flex items-center gap-2",children:[(0,t.jsx)(r.A,{className:"h-5 w-5"}),er("finance.invoices.view.customerInfo")]})}),(0,t.jsx)(C.Wu,{className:"space-y-2",children:(0,t.jsxs)("div",{children:[(0,t.jsx)("div",{className:"font-medium",children:(null==(I=et.customer)?void 0:I.name)||er("finance.invoices.view.unknownCustomer")}),(null==(F=et.customer)?void 0:F.email)&&(0,t.jsx)("div",{className:"text-sm text-muted-foreground",children:et.customer.email})]})})]}),(0,t.jsxs)(C.Zp,{children:[(0,t.jsx)(C.aR,{children:(0,t.jsxs)(C.ZB,{className:"flex items-center gap-2",children:[(0,t.jsx)(c.A,{className:"h-5 w-5"}),er("finance.invoices.view.invoiceDetails")]})}),(0,t.jsxs)(C.Wu,{className:"space-y-2",children:[(0,t.jsxs)("div",{className:"flex justify-between",children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:er("finance.invoices.view.detailStatus")}),(0,t.jsxs)("span",{className:"flex items-center gap-2",children:[(e=>{switch(e){case"DRAFT":return(0,t.jsx)(g.E,{kind:"neutral",appearance:"outline",children:er("finance.invoices.status.draft")});case"SENT":return(0,t.jsx)(g.E,{kind:"info",appearance:"outline",children:er("finance.invoices.status.sent")});case"PARTIALLY_PAID":return(0,t.jsx)(g.E,{kind:"info",appearance:"outline",children:er("finance.invoices.status.partiallyPaid")});case"PAID":return(0,t.jsx)(g.E,{kind:"success",appearance:"outline",children:er("finance.invoices.status.paid")});case"CANCELLED":return(0,t.jsx)(g.E,{kind:"neutral",appearance:"outline",children:er("finance.invoices.status.cancelled")});default:return(0,t.jsx)(g.E,{variant:"outline",children:e})}})(et.status),!0===et.overdue&&(0,t.jsx)("span",{className:"text-status-danger-text",children:er("finance.invoices.view.overdueLabel")})]})]}),(0,t.jsxs)("div",{className:"flex justify-between",children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:er("finance.invoices.view.detailInvoiceDate")}),(0,t.jsx)("span",{children:new Date(et.invoiceDate).toLocaleDateString()})]}),(0,t.jsxs)("div",{className:"flex justify-between",children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:er("finance.invoices.view.detailDueDate")}),(0,t.jsx)("span",{className:!0===et.overdue?"text-status-danger-text font-medium":"",children:new Date(et.dueDate).toLocaleDateString()})]}),et.sentAt&&(0,t.jsxs)("div",{className:"flex justify-between",children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:er("finance.invoices.view.detailSentDate")}),(0,t.jsx)("span",{children:new Date(et.sentAt).toLocaleDateString()})]}),et.terms&&(0,t.jsxs)("div",{className:"flex justify-between",children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:er("finance.invoices.view.detailTerms")}),(0,t.jsx)("span",{children:et.terms})]})]})]})]}),(0,t.jsxs)(C.Zp,{children:[(0,t.jsx)(C.aR,{children:(0,t.jsx)(C.ZB,{children:er("finance.invoices.view.itemsTitle")})}),(0,t.jsx)(C.Wu,{children:(0,t.jsxs)(w.XI,{children:[(0,t.jsx)(w.A0,{children:(0,t.jsxs)(w.Hj,{children:[(0,t.jsx)(w.nd,{children:er("finance.invoices.view.colDescription")}),(0,t.jsx)(w.nd,{children:er("finance.invoices.view.colAccount")}
1),(0,t.jsx)(w.nd,{className:"text-right",children:er("finance.invoices.view.colQty")}),(0,t.jsx)(w.nd,{className:"text-right",children:er("finance.invoices.view.colUnitPrice")}),(0,t.jsx)(w.nd,{className:"text-right",children:er("finance.invoices.view.colTotal")})]})}),(0,t.jsx)(w.BF,{children:(null==(M=et.items)?void 0:M.map(e=>(0,t.jsxs)(w.Hj,{children:[(0,t.jsx)(w.nA,{children:e.description}),(0,t.jsx)(w.nA,{children:(0,t.jsxs)("div",{children:[(0,t.jsx)("div",{className:"font-medium",children:e.account.accountCode}),(0,t.jsx)("div",{className:"text-sm text-muted-foreground",children:e.account.accountName})]})}),(0,t.jsx)(w.nA,{className:"text-right",children:e.quantity||0}),(0,t.jsx)(w.nA,{className:"text-right font-mono",children:e.unitPriceFormatted||el(Number(e.unitPrice)||0)}),(0,t.jsx)(w.nA,{className:"text-right font-mono",children:e.totalPriceFormatted||el(Number(e.totalPrice)||0)})]},e.id)))||(0,t.jsx)(w.Hj,{children:(0,t.jsx)(w.nA,{colSpan:5,className:"text-center text-muted-foreground",children:er("finance.invoices.view.noItems")})})})]})})]}),(0,t.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[(0,t.jsxs)(C.Zp,{children:[(0,t.jsx)(C.aR,{children:(0,t.jsxs)(C.ZB,{className:"flex items-center gap-2",children:[(0,t.jsx)(o.A,{className:"h-5 w-5"}),er("finance.invoices.view.financialSummaryTitle")]})}),(0,t.jsxs)(C.Wu,{className:"space-y-3",children:[(0,t.jsxs)("div",{className:"flex justify-between",children:[(0,t.jsx)("span",{children:er("finance.invoices.view.subtotal")}),(0,t.jsx)("span",{className:"font-mono",children:et.subtotalFormatted||el(Number(et.subtotal)||0)})]}),Number(et.discountAmount)>0&&(0,t.jsxs)("div",{className:"flex justify-between text-status-success-text",children:[(0,t.jsxs)("span",{className:"flex items-center gap-1",children:[(0,t.jsx)(l.A,{className:"h-3 w-3"}),er("finance.invoices.view.discount"),et.discountDescription&&(0,t.jsxs)("span",{className:"text-muted-foreground",children:["(",et.discountDescription,")"]})]}),(0,t.jsxs)("span",{className:"font-mono",children:["-",et.discountAmountFormatted||el(Number(et.discountAmount)||0)]})]}),(0,t.jsxs)("div",{className:"flex justify-between",children:[(0,t.jsx)("span",{children:er("finance.invoices.view.tax")}),(0,t.jsx)("span",{className:"font-mono",children:et.taxAmountFormatted||el(Number(et.taxAmount)||0)})]}),(0,t.jsx)(A.w,{}),(0,t.jsxs)("div",{className:"flex justify-between text-lg font-bold",children:[(0,t.jsx)("span",{children:er("finance.invoices.view.totalAmount")}),(0,t.jsx)("span",{className:"font-mono",children:et.totalAmountFormatted||el(Number(et.totalAmount)||0)})]}),(0,t.jsxs)("div",{className:"flex justify-between text-status-success-text",children:[(0,t.jsx)("span",{children:er("finance.invoices.view.amountPaid")}
1),(0,t.jsx)("span",{className:"font-mono",children:et.paidAmountFormatted||el(Number(et.paidAmount)||0)})]}),(0,t.jsxs)("div",{className:"flex justify-between text-status-info-text font-medium",children:[(0,t.jsx)("span",{children:er("finance.invoices.view.balanceDue")}),(0,t.jsx)("span",{className:"font-mono",children:el(eC())})]})]})]}),(0,t.jsxs)(C.Zp,{children:[(0,t.jsxs)(C.aR,{className:"flex flex-row items-center justify-between",children:[(0,t.jsxs)(C.ZB,{className:"flex items-center gap-2",children:[(0,t.jsx)(d.A,{className:"h-5 w-5"}),er("finance.invoices.view.paymentHistoryTitle")]}),(0,t.jsxs)("div",{className:"flex gap-2",children:[ez>0&&eN&&et.customer&&(0,t.jsxs)(y.$,{size:"sm",variant:"outline",onClick:()=>ep(!0),children:[(0,t.jsx)(u.A,{className:"h-4 w-4 mr-2"}),er("finance.refunds.credit.button",{amount:el(ez)})]}),ei.recordPayment&&("SENT"===et.status||"PARTIALLY_PAID"===et.status)&&eC()>0&&(0,t.jsxs)(t.Fragment,{children:[(null!=(G=null==(L=et.customer)?void 0:L.creditBalance)?G:0)>0&&(0,t.jsx)(y.$,{size:"sm",variant:"outline",onClick:eA,disabled:ec,children:er("finance.invoices.actions.applyCredit",{amount:el(null!=(X=null==(O=et.customer)?void 0:O.creditBalance)?X:0)})}),(0,t.jsxs)(y.$,{size:"sm",onClick:()=>em(!0),children:[(0,t.jsx)(d.A,{className:"h-4 w-4 mr-2"}),er("finance.invoices.actions.recordPayment")]})]})]})]}),(0,t.jsxs)(C.Wu,{children:[et.payments&&0!==et.payments.length?(0,t.jsx)("div",{className:"space-y-3",children:et.payments.map(e=>{let n=eb===e.id;return(0,t.jsxs)("div",{className:"border rounded-lg overflow-hidden",children:[(0,t.jsxs)("div",{className:"flex justify-between items-center p-3 cursor-pointer hover:bg-muted/50 transition-colors ".concat("VOIDED"===e.status?"bg-status-danger-fill":""),onClick:()=>ew(n?null:e.id),children:[(0,t.jsxs)("div",{className:"flex items-center gap-3",children:[(0,t.jsx)("div",{children:n?(0,t.jsx)(m.A,{className:"h-4 w-4 text-muted-foreground"}):(0,t.jsx)(x.A,{className:"h-4 w-4 text-muted-foreground"})}),(0,t.jsxs)("div",{children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("span",{className:"font-medium",children:e.amountFormatted||el(Number(e.amount)||0)}),(0,t.jsx)(g.E,{variant:"outline",className:"ACTIVE"===e.status?"border-status-success-border text-status-success-text":"VOIDED"===e.status?"border-status-danger-border text-status-danger-text":"border-status-warning-border text-status-warning-text",children:e.status})]}),(0,t.jsxs)("div",{className:"text-sm text-muted-foreground flex items-center gap-2",children:[(0,t.jsx)("span",{children:e.paymentMethod}),e.reference&&(0,t.jsxs)("span",{children:["- Ref: ",e.reference]})]})]})]}),(0,t.jsx)("div",{className:"text-right",children:(0,t.jsx)("div",{className:"text-sm",children:new Date(e.paymentDate).toLocaleDateString()})})]}),n&&(0,t.jsxs)("div",{className:"border-t p-3 bg-muted/30 space-y-3",children:[e.notes&&(0,t.jsxs)("div",{className:"text-sm",children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:er("finance.invoices.view.paymentNotes")})," ",e.notes]}),"ACTIVE"===e.status&&(0,t.jsx)("div",{className:"flex gap-2 pt-2",children:(0,t.jsxs)(y.$,{variant:"outline",size:"sm",className:"text-status-danger-text",onClick:n=>{n.stopPropagation(),eg(e),ef(!0)},children:[(0,t.jsx)(f.A,{className:"h-4 w-4 mr-1"}),er("finance.invoices.view.voidPayment")]})})]})]},e.id)})}):(0,t.jsx)("div",{className:"text-center py-4 text-muted-foreground",children:er("finance.invoices.view.noPayments")}),!!(null==(K=et.refunds)?void 0:K.length)&&(0,t.jsxs)("div",{className:"mt-4 space-y-2",children:[(0,t.jsx)("div",{className:"text-sm font-medium",children:er("finance.invoices.view.refundsTitle")}),et.refunds.map(e=>(0,t.jsxs)("div",{className:"flex justify-between items-center p-2 rounded border",children:[(0,t.jsxs)("div",{children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsxs)("span",{className:"font-mono font-medium",children:["-",el(e.amount)]}),(0,t.jsx)(g.E,{variant:"outline",className:"PENDING"===e.status?"border-status-warning-border text-status-warning-text":"APPROVED"===e.status?"border-status-info-border text-status-info-text":"ISSUED"===e.status?"border-status-success-border text-status-success-text":"REJECTED"===e.status?"border-status-danger-border text-status-danger-text":"border-status-neutral-border text-status-neutral-text",children:er("finance.refunds.status.".concat(e.status))})]}),(0,t.jsxs)("div",{className:"text-xs text-muted-foreground",children:[er("finance.refunds.method.".concat(e.refundMethod))," - ",e.reason]})]}),(0,t.jsx)("div",{className:"text-xs text-muted-foreground",children:(0,H.i)(e.refundDate)})]},e.id))]})]})]})]}),et.notes&&(0,t.jsxs)(C.Zp,{children:[(0,t.jsx)(C.aR,{children:(0,t.jsx)(C.ZB,{children:er("finance.invoices.view.notesTitle")})}),(0,t.jsx)(C.Wu,{children:(0,t.jsx)("p",{className:"text-sm text-muted-foreground whitespace-pre-wrap",children:et.notes})})]})]}),(0,t.jsxs)(b.Es,{className:"flex flex-col sm:flex-row gap-2",children:[(0,t.jsxs)("div",{className:"flex gap-2",children:[eK&&!!ei.update&&(0,t.jsxs)(y.$,{variant:"outline",size:"sm",onClick:eE,children:[(0,t.jsx)(h.A,{className:"h-4 w-4 mr-2"}),er("finance.invoices.view.btnSend")]}),(0,t.jsxs)(y.$,{variant:"outline",size:"sm",onClick:eP,disabled:ec,children:[(0,t.jsx)(v.A,{className:"h-4 w-4 mr-2"}),ec?er("finance.invoices.view.btnGeneratingPdf"):er("finance.invoices.view.btnDownloadPdf")]}),eK&&!!ea&&!!ei.update&&(0,t.jsxs)(y.$,{variant:"outline",size:"sm",onClick:()=>{null==ea||ea(et)},children:[(0,t.jsx)(j.A,{className:"h-4 w-4 mr-2"}),er("finance.invoices.view.btnEdit")]}),eQ()&&(0,t.jsxs)(y.$,{variant:"outline",size:"sm",onClick:()=>eO(!0),children:[(0,t.jsx)(p.A,{className:"h-4 w-4 mr-2"}),er("finance.invoices.view.btnCreditNote")]}),eQ()&&Number(et.paidAmount)>0&&!eJ&&eN&&(0,t.jsxs)(y.$,{variant:"outline",size:"sm",onClick:()=>ev(!0),children:[(0,t.jsx)(u.A,{className:"h-4 w-4 mr-2"}),er("finance.invoices.view.refundPayment")]}),!eK&&"CANCELLED"!==et.status&&!eq&&!(null==(ee=et.creditNotes)?void 0:ee.length)&&!!ei.update&&(0,t.jsxs)(y.$,{variant:"outline",size:"sm",onClick:()=>{eF(""),eI(!0)},className:"text-status-danger-text",children:[(0,t.jsx)(f.A,{className:"h-4 w-4 mr-2"}),er("finance.invoices.view.btnCancel")]}),eK&&!!ei.update&&(0,t.jsxs)(y.$,{variant:"outline",size:"sm",onClick:()=>eR(!0),disabled:ec,className:"text-status-danger-text",children:[(0,t.jsx)(N.A,{className:"h-4 w-4 mr-2"}),er("finance.invoices.view.btnDelete")]})]}),(0,t.jsx)(y.$,{variant:"outline",onClick:es,children:er("finance.invoices.view.btnClose")})]}),(0,t.jsx)(Z.C,{isOpen:eS,permanent:!0,onClose:()=>eR(!1),onConfirm:eD,itemName:et.invoiceNumber}),(0,t.jsx)(b.lG,{open:ek,onOpenChange:e=>{e||eI(!1)},children:(0,t.jsxs)(b.Cf,{className:"sm:max-w-md",children:[(0,t.jsxs)(b.c7,{children:[(0,t.jsx)(b.L3,{children:er("finance.invoices.view.cancelTitle",{number:et.invoiceNumber})}),(0,t.jsx)(b.rr,{children:et.orderId?er("finance.invoices.view.cancelDescriptionWithOrder"):er("finance.invoices.view.cancelDescription")})]}),(0,t.jsx)(T.T,{value:eT,onChange:e=>eF(e.target.value),placeholder:er("finance.invoices.view.cancelReasonPlaceholder"),rows:3,maxLength:500}),(0,t.jsxs)(b.Es,{children:[(0,t.jsx)(y.$,{variant:"outline",onClick:()=>eI(!1),disabled:ec,children:er("finance.invoices.view.btnKeep")}),(0,t.jsx)(y.$,{variant:"destructive",onClick:eM,disabled:ec||eT.trim().length<5,children:er("finance.invoices.view.btnCancelConfirm")})]})]})}),(0,t.jsx)(U,{isOpen:eL,onClose:()=>eO(!1),invoice:{id:et.id,invoiceNumber:et.invoiceNumber,totalAmount:et.totalAmount,paidAmount:et.paidAmount,items:et.items},onRaised:()=>es()}),(0,t.jsx)(S.e,{open:eu,onOpenChange:e=>{em(e)},invoice:{id:et.id,invoiceNumber:et.invoiceNumber,customerId:et.customerId,invoiceDate:et.invoiceDate,dueDate:et.dueDate,status:et.status,subtotal:et.subtotal,taxAmount:et.taxAmount,totalAmount:et.totalAmount,paidAmount:et.paidAmount,customer:et.customer?{id:et.customer.id,name:et.customer.name||null,email:et.customer.email||null}:void 0},onPaymentSuccess:()=>{em(!1),E.oR.success(er("finance.invoices.view.paymentRecorded")),ed.invalidateQueries({queryKey:_.WQ.all})}}),ey&&(0,t.jsx)(B,{open:ex,onOpenChange:e=>{ef(e),e||eg(null)},payment:{id:ey.id,invoiceId:et.id,amount:ey.amount,paymentDate:ey.paymentDate,paymentMethod:ey.paymentMethod,reference:ey.reference||null,status:ey.status,invoice:{id:et.id,invoiceNumber:et.invoiceNumber,totalAmount:et.totalAmount,paidAmount:et.paidAmount},customer:et.customer?{id:et.customer.id,name:et.customer.name||null,email:et.customer.email||null}:void 0},onVoidSuccess:()=>{ef(!1),eg(null),E.oR.success("Payment voided successfully")}}),(0,t.jsx)(J,{open:eh,onOpenChange:ev,invoice:{id:et.id,invoiceNumber:et.invoiceNumber,items:et.items},onRequested:()=>ed.invalidateQueries({queryKey:_.WQ.all})}),et.customer&&(0,t.jsx)(z.O,{open:ej,onOpenChange:ep,customer:{id:et.customer.id,name:null!=(Y=et.customer.name)?Y:""},onRequested:()=>ed.invalidateQueries({queryKey:_.WQ.all})})]})})}},86540:(e,n,s)=>{s.d(n,{H6:()=>f,Hh:()=>u,IO:()=>x,J8:()=>m,KW:()=>d});var t=s(95155),a=s(65142),i=s(76444),r=s(31120),c=s(11186),o=s(67611),l=s(22955);let d={reason:"",refundMethod:"BANK_TRANSFER",notes:"",reference:""},u=10;function m(e){return e.reason.trim().length>=u}function x(e){return{reason:e.reason.trim(),refundMethod:e.refundMethod,...e.notes.trim()?{notes:e.notes.trim()}:{},...e.reference.trim()?{reference:e.reference.trim()}:{}}}function f(e){let{value:n,onChange:s}=e,{t:d}=(0,o.B)("finance");return(0,t.jsxs)("div",{className:"space-y-4",children:[(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(i.J,{htmlFor:"refund-reason",children:d("finance.refunds.create.reasonLabel")}),(0,t.jsx)(r.T,{id:"refund-reason",value:n.reason,onChange:e=>s({...n,reason:e.target.value}),placeholder:d("finance.refunds.create.reasonPlaceholder"),maxLength:500,rows:2}),n.reason.trim().length>0&&n.reason.trim().length<u?(0,t.jsx)("p",{className:"text-xs text-destructive",children:d("finance.refunds.create.reasonTooShort",{count:u
1-n.reason.trim().length})}):(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:d("finance.refunds.create.reasonDescription",{min:u})})]}),(0,t.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(i.J,{children:d("finance.refunds.create.methodLabel")}),(0,t.jsxs)(c.l6,{value:n.refundMethod,onValueChange:e=>s({...n,refundMethod:e}),children:[(0,t.jsx)(c.bq,{children:(0,t.jsx)(c.yv,{})}),(0,t.jsx)(c.gC,{children:l.G.map(e=>(0,t.jsx)(c.eb,{value:e,children:d("finance.refunds.method.".concat(e))},e))})]})]}),(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(i.J,{htmlFor:"refund-request-reference",children:d("finance.refunds.create.referenceLabel")}),(0,t.jsx)(a.p,{id:"refund-request-reference",value:n.reference,maxLength:100,placeholder:d("finance.refunds.create.referencePlaceholder"),onChange:e=>s({...n,reference:e.target.value})})]})]}),(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(i.J,{htmlFor:"refund-notes",children:d("finance.refunds.create.notesLabel")}),(0,t.jsx)(r.T,{id:"refund-notes",value:n.notes,onChange:e=>s({...n,notes:e.target.value}),maxLength:500,rows:2})]})]})}}}]);

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.