PageSourceSearch

https://slive.ai/_next/static/chunks/80052-0bbc09df3483e958.js

js slive.ai collected 2026-10-05 12:40:16 UTC 69,217 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[80052],{14981:(e,s,t)=>{t.d(s,{Ay:()=>L});var a=t(95155),l=t(34623),r=t(68189),n=t(2943),i=t(49387),c=t(68459),o=t(51914),d=t(33210),u=t(50910),m=t(12115),x=t(60848),p=t(57657),f=t(55638),h=t(9339);let b=(0,h.createServerReference)("4013b53f67b54f469b4ba9e2067b0feb65e5dc0ab3",h.callServer,void 0,h.findSourceMapURL,"createProductLabel"),g=(0,h.createServerReference)("60bf5bd79b21d30f06cbb734e4d59ff53ff9ed569b",h.callServer,void 0,h.findSourceMapURL,"updateProductLabel"),j=(0,h.createServerReference)("40c41415c055f686c7822b58306a4bc52d07225469",h.callServer,void 0,h.findSourceMapURL,"deleteProductLabel");var y=t(45706),N=t(95106),v=t(85218),C=t(72740),A=t(42399),w=t(21819),D=t(99003),E=t(42067),S=t(2614),_=t(11697);let P=({label:e,setShowLabelDialogForm:s,labelFunctions:t,handleAddLabel:l,handleReplaceLabel:n,placeholder:i="catalogue"})=>{let[c,o]=(0,m.useState)(!1),{control:d,formState:u,handleSubmit:x,setValue:f,getFieldState:h,watch:b,reset:g}=(0,D.mN)({mode:"onChange",defaultValues:{label:e?.label||""},resolver:(0,C.t)(A.Ik({label:A.Yj().required()}))}),{createLabelFunction:j,updateLabelFunction:N,deleteLabelFunction:v}=t,P=(0,_.Ym)();(0,m.useEffect)(()=>{e?f("label",e.label):f("label","")},[e,f]);let R=async t=>{try{o(!0);let a=e?.customerLabelCode||e?.supplierLabelCode||e?.value,r=e?await N(a,t.label):await j(t);r.Error?S.toast.error(`Failed to ${e?"update":"create"} ${i} ${r.Message[P]}`):(e?(S.toast.success(`${i} updated successfully`),n({label:r.Data.label,value:r.Data.value})):S.toast.success(`${i} created successfully`),l({label:r.Data.label,value:r.Data.value}),s(!1))}catch(e){console.error(e),S.toast.error("An error occurred")}finally{o(!1)}};return(0,a.jsx)(w.lV,{getFieldState:h,children:(0,a.jsxs)(p.DialogContent,{children:[(0,a.jsxs)(p.DialogHeader,{children:[(0,a.jsxs)(p.DialogTitle,{children:[e?"Edit":"Create"," ",i]}),(0,a.jsx)(p.DialogDescription,{children:e?`Change the name of the ${i}.`:`Create a new ${i}`})]}),(0,a.jsx)("div",{children:(0,a.jsx)("div",{className:"space-y-4 py-2 pb-4",children:(0,a.jsx)(w.zB,{control:d,name:"label",render:({field:e})=>(0,a.jsxs)(w.eI,{children:[(0,a.jsxs)(w.lR,{children:[i," name"]}),(0,a.jsx)(w.MJ,{children:(0,a.jsx)(E.Input,{placeholder:i,...e})}),(0,a.jsx)(w.C5,{})]})})})}),(0,a.jsxs)(p.DialogFooter,{children:[(0,a.jsx)(r.Button,{variant:"outline",onClick:()=>{s(!1),g()},children:"Cancel"}),c?(0,a.jsx)(r.Button,{variant:"ghost",disabled:!0,children:(0,a.jsx)(y.A,{size:24})}):(0,a.jsx)(r.Button,{variant:"default",onClick:x(R),children:"Continue"})]})]})})};var R=t(86190);function I({item:e,handleAddLabel:s,setOpen:t,setSelectedLabel:l,setShowLabelDialogForm:r,labelFunctions:o,availableLabels:d,title:u}){let m=async e=>{try{let{deleteLabelFunction:s}=o,t=e.customerLabelCode||e.supplierLabelCode||e.value;(await s(t)).Error?S.toast.error("Error deleting label"):S.toast.success("Label deleted successfully")}catch(e){console.error({error:e}),S.toast.error("Error deleting label")}},p=d.some(s=>s.value===e.value);return(0,a.jsx)(x.h_,{className:"flex justify-between",children:(0,a.jsxs)(N.lv,{children:[(0,a.jsx)(N.nV,{className:"w-full",children:e.label||e}),(0,a.jsxs)(N.M5,{className:"p-0",children:[(0,a.jsx)(N.DropdownMenuLabel,{children:"Actions"}),(0,a.jsxs)(N.DropdownMenuGroup,{children:[p&&(0,a.jsxs)(N.DropdownMenuItem,{onSelect:()=>{s(e),t(!1)},children:[(0,a.jsx)(n.A,{className:"mr-2 h-4 w-4"}),(0,a.jsx)("span",{children:u||"Assign to catalogue"})]}),(0,a.jsxs)(N.DropdownMenuItem,{onSelect:()=>{t(!1),l(e),r(!0)},children:[(0,a.jsx)(i.A,{className:"mr-2 h-4 w-4"}),(0,a.jsx)("span",{children:"Edit"})]}),(0,a.jsxs)(N.DropdownMenuItem,{onSelect:()=>{m(e),t(!1)},children:[(0,a.jsx)(c.A,{className:"mr-2 h-4 w-4 text-primary hover:text-primary-500"}),(0,a.jsx)("span",{children:"Delete"})]})]})]})]})},e.value)}let O=({availableLabels:e,labels:s,hasAtLeastOneLabel:t,handleAddLabel:l,handleReplaceLabel:n,labelFunctions:i,title:c,placeholder:d})=>{let[u,h]=(0,m.useState)(!1),[b,g]=(0,m.useState)(!1),[j,y]=(0,m.useState)(null);return(0,a.jsxs)(p.Dialog,{open:b,onOpenChange:g,children:[(0,a.jsxs)(N.DropdownMenu,{open:u,onOpenChange:h,children:[(0,a.jsx)(N.DropdownMenuTrigger,{asChild:!0,className:"w-fit",children:t?(0,a.jsx)(r.Button,{variant:"outline",className:"text-primary rounded-full py-2.5 px-1",size:"iconSm",onClick:()=>{},children:(0,a.jsx)(o.A,{size:16})}):(0,a.jsxs)(r.Button,{variant:"outline",className:"text-primary gap-1 text-base",size:"sm",onClick:()=>{},children:[(0,a.jsx)(o.A,{size:16})," ",c||"Add Label"]})}),(0,a.jsx)(N.DropdownMenuContent,{className:"w-[300px] p-0",align:"start",children:(0,a.jsxs)(x.uB,{children:[(0,a.jsxs)(x.oI,{className:"custom-scrollbar",children:[(0,a.jsx)(x.G7,{placeholder:"Search..."}),(0,a.jsx)(x.xL,{children:"No label found."}),e.map((s,t)=>(0,a.jsx)(I,{item:s,handleAddLabel:l,setOpen:h,setSelectedLabel:y,setShowLabelDialogForm:g,labelFunctions:i,availableLabels:e,title:c},s.value||t))]}),(0,a.jsx)(x.fx,{}),(0,a.jsx)(x.oI,{children:(0,a.jsx)(x.L$,{children:(0,a.jsx)(p.DialogTrigger,{asChild:!0,children:(0,a.jsxs)(x.h_,{onSelect:()=>{h(!1),g(!0),y(null)},children:[(0,a.jsx)(f.WBl,{className:"mr-2 h-5 w-5"}),"Create new"]})})})})]})})]}),(0,a.jsx)(P,{setShowLabelDialogForm:g,labelFunctions:i,label:j,handleAddLabel:l,handleReplaceLabel:n,placeholder:d})]})},k=({labels:e,labelsList:s,availableLabels:t,setValue:l,name:n="general.labels",labelFunctions:i,labelSelectorTitle:c="Add Label",placeholder:o=""})=>{let u=e.length>0;return(0,a.jsxs)("div",{className:"flex flex-row gap-2 mt-2 max-w-xl items-center",children:[u&&(0,a.jsx)("div",{className:"flex overflow-x-auto w-36 md:w-fit gap-2 custom-scrollbar",children:e.map((s,t)=>(0,a.jsxs)(v.E,{variant:"outline",className:"flex text-primary  text-base h-8 w-fit truncate text-ellipsis whitespace-nowrap gap-1 items-center",type:"button",children:[(0,a.jsx)("p",{children:s.label}),(0,a.jsx)(r.Button,{variant:"outline",size:"ghost",className:"rounded-full border-0 h-full",onClick:()=>{let t;return t=s.id||s.value,void l(n,e.filter(e=>e.id?e.id!==t:e.value!==t))},children:(0,a.jsx)(d.A,{size:14})})]},s.value||t))}),(0,a.jsx)(O,{labels:s,availableLabels:t,hasAtLeastOneLabel:u,handleAddLabel:s=>{l(n,[...e,s])},labelFunctions:i,handleReplaceLabel:s=>{l(n,e.filter(e=>e.value!==s.value)),l(n,[...e,s])},title:c,placeholder:o})]})},L=({header:e,buttonLabel:s,className:t,subHeader:n,labelSelectorTitle:i,allowsCatalogue:c=!1,isFormValid:o=!0,handleSubmit:d,labels:m=null,availableLabels:x=[],labelsList:p=[],setValue:f=()=>{},isLoading:h=!1,createLabelPlaceholder:N="label",labelFormValueName:v="general.labels",labelFunctions:C={createLabelFunction:b,updateLabelFunction:g,deleteLabelFunction:j},customSaveButton:A=null,backURL:w=null,hideButton:D=!1})=>{let E=(0,u.c)("APPS.PRODUCTS.PRODUCT_FORM");return(0,a.jsxs)("div",{className:(0,R.cn)("bg-card flex justify-between gap-2 sticky z-20 md:z-30 top-[4rem] md:top-[4.5rem] pt-1 pb-6 rounded-lg items-center",t),children:[(0,a.jsxs)("div",{className:"flex flex-col flex-1",children:[(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:n}),m&&c&&(0,a.jsx)(k,{labels:m,labelsList:p,availableLabels:x,setValue:f,name:v,labelFunctions:C,labelSelectorTitle:i,placeholder:N})]}),(0,a.jsxs)("div",{className:"flex gap-4 items-end w-fit md:pe-3",children:[(0,a.jsx)(l.A,{side:"bottom",backUrl:w}),!D&&(h?(0,a.jsx)(r.Button,{variant:"ghost",size:"lgApp",disabled:!0,children:(0,a.jsx)(y.A,{size:24})}):A||(0,a.jsx)(r.Button,{variant:"default",size:"lgApp",disabled:!o,onClick:d,children:s??E("SAVE")}))]})]})}},40037:(e,s,t)=>{t.d(s,{Cb:()=>r,J_:()=>
1o,VC:()=>l,YC:()=>n,cy:()=>c,fW:()=>a}),t(86190);let a=Object.freeze({NONE:0,VOID:1,PENDING:2,COMPLETED:3,APPROVED:4,PENDING_PREPARATION:5,IN_PREPARATION:6,CANCELLED:7,ORDER_PACKED:8,PAYMENT_FAILED:9,IN_TRANSIT:10,READY_FOR_PICKUP:11,PAYMENT_PENDING:12}),l=Object.freeze({NONE:0,QUOTATION:1,DELIVERYNOTE:2,ORDER:3,INVOICE:4,RETURN:5});l.QUOTATION,l.DELIVERYNOTE,l.ORDER,l.INVOICE,l.RETURN;let r={[a.PENDING]:"equalStatistic",[a.PENDING_PREPARATION]:"equalStatistic",[a.IN_PREPARATION]:"equalStatistic",[a.CANCELLED]:"destructiveStatistic",[a.PAYMENT_PENDING]:"equalStatistic",[a.COMPLETED]:"successStatistic",[a.APPROVED]:"successStatistic",[a.ORDER_PACKED]:"successStatistic",[a.IN_TRANSIT]:"successStatistic",[a.READY_FOR_PICKUP]:"successStatistic"},n={[a.NONE]:"none",[a.VOID]:"void",[a.PENDING]:"pending",[a.COMPLETED]:"completed",[a.APPROVED]:"approved",[a.PENDING_PREPARATION]:"pending_preparation",[a.IN_PREPARATION]:"in_preparation",[a.CANCELLED]:"cancelled",[a.ORDER_PACKED]:"order_packed",[a.PAYMENT_FAILED]:"payment_failed",[a.IN_TRANSIT]:"in_transit",[a.READY_FOR_PICKUP]:"ready_for_pickup",[a.PAYMENT_PENDING]:"payment_pending"},i={[a.NONE]:[a.PENDING],[a.PENDING]:[a.CANCELLED,a.PAYMENT_FAILED,a.PAYMENT_PENDING],[a.COMPLETED]:[],[a.APPROVED]:[a.ORDER_PACKED,a.IN_TRANSIT,a.READY_FOR_PICKUP,a.COMPLETED,a.CANCELLED,a.VOID,a.PENDING_PREPARATION],[a.PENDING_PREPARATION]:[a.IN_PREPARATION,a.CANCELLED,a.VOID],[a.IN_PREPARATION]:[a.READY_FOR_PICKUP,a.ORDER_PACKED,a.VOID,a.CANCELLED],[a.CANCELLED]:[a.VOID],[a.ORDER_PACKED]:[a.READY_FOR_PICKUP],[a.PAYMENT_FAILED]:[a.APPROVED,a.CANCELLED,a.VOID],[a.IN_TRANSIT]:[a.COMPLETED,a.READY_FOR_PICKUP,a.CANCELLED],[a.READY_FOR_PICKUP]:[a.IN_TRANSIT,a.COMPLETED,a.CANCELLED],[a.PAYMENT_PENDING]:[a.APPROVED,a.PAYMENT_FAILED,a.CANCELLED,a.VOID],[a.VOID]:[]},c=(e,s)=>(i[e]||[]).includes(s);Object.freeze({PERCENTAGE:"percentage",FEE:"fee"});let o=e=>e&&Array.isArray(e)?e.map(e=>{let s=Array.isArray(e.prices)?e.prices:[],t=Number(e.price??0),a=e=>Number(e.price??e.Price??0),l=s.find(e=>a(e)===t),r=s.reduce((e,s)=>null==e||Math.abs(a(s)-t)<Math.abs(a(e)-t)?s:e,null),n=l??r;return{...e,discount:e.discount??0,id:e.itemID??"",name:e.historicName??"",price:n?n.id??n.ID??"":"",prices:s,priceValue:e.price??0,allowedReturnQuantity:e.quantity??0,quantity:e.quantity??0,subTotal:e.subtotal??0,taxData:e.tax??{},totalAmount:e.total??0,totalTax:(e.totalFeeCalculated??0)+(e.totalTaxCalculated??0)}}):[];Object.freeze({1:"Jan",2:"Feb",3:"Mar",4:"Apr",5:"May",6:"Jun",7:"Jul",8:"Aug",9:"Sep",10:"Oct",11:"Nov",12:"Dec"})},42176:(e,s,t)=>{t.d(s,{r:()=>l});var a=t(9339);let l=(0,a.createServerReference)("4035101d625f05be1399df2c70611fcdf67fd75599",a.callServer,void 0,a.findSourceMapURL,"getCustomerById")},54366:(e,s,t)=>{t.d(s,{A:()=>p});var a=t(95155),l=t(72971),r=t(12115),n=t(67192),i=t(66088),c=t(50910),o=t(68189),d=t(49494),u=t(99027),m=t(86190);let x=({data:e,header:s,media:t,children:l,forceExpanded:x=!1,className:p=""})=>{let[f,h]=(0,r.useState)(!1),[b,g]=(0,r.useState)(0),j=(0,r.useRef)(null),y=(0,c.c)("components.summary-panel");(0,r.useLayoutEffect)(()=>{if(!j.current)return;let e=j.current,s=()=>g(e.scrollHeight);s();let t=new ResizeObserver(s);return t.observe(e),()=>t.disconnect()},[e,s,t]);let N=!x&&b>330,v=N?f?b:330:b,C=Array.isArray(e)?e.length>0:!!e&&Object.keys(e).length>0;return(0,a.jsxs)("div",{className:(0,m.cn)("pb-4",p),children:[(0,a.jsx)(n.P.div,{className:(0,m.cn)("overflow-hidden border-b-0 rounded-t-2xl",!N&&"rounded-b-2xl"),animate:{height:v},initial:!1,transition:{duration:.28,ease:"easeInOut"},children:(0,a.jsx)("div",{ref:j,children:l||(0,a.jsxs)(d.A,{header:s,className:(0,m.cn)("rounded-t-2xl",N?"rounded-b-none border-b-0":"rounded-b-2xl"),children:[t,C?(0,a.jsx)(u.A,{data:e}):!t&&(0,a.jsx)("p",{className:"pt-4 text-sm text-muted-foreground",children:y("summary_no_data")})]})})}),N&&(0,a.jsx)(o.Button,{type:"button",variant:"ghost",onClick:()=>h(e=>!e),"aria-expanded":f,"aria-label":y(f?"aria_collapse_summary":"aria_expand_summary"),className:"hidden h-auto w-full items-center justify-center rounded-b-2xl rounded-t-none border border-t-0 border-border/60 bg-white-base py-1.5 text-muted-foreground transition-colors hover:bg-muted/60 hover:text-foreground md:flex",children:(0,a.jsx)(i.A,{className:(0,m.cn)("h-5 w-5 transition-transform duration-200",f&&"rotate-180")}
1)})]})},p=({isEditing:e=!1,summary:s={},entity:t,changelog:r=[],children:n,className:i="",showSummary:c=!0})=>{let{data:o,header:d,media:u,forceExpanded:p}=s;return(0,a.jsxs)("div",{className:(0,m.cn)("flex flex-col gap-4",i),children:[e&&(0,a.jsx)(l.default,{entity:t,changelog:r}),c&&(0,a.jsx)(x,{data:o,header:d,media:u,forceExpanded:p,children:n})]})}},80052:(e,s,t)=>{t.r(s),t.d(s,{SECTION_ACCORDION_ITEM_CLASSNAME:()=>eY,SECTION_ACCORDION_TRIGGER_CLASSNAME:()=>eG,default:()=>eW});var a=t(95155),l=t(12115),r=t(99003),n=t(72740),i=t(2614),c=t(11697),o=t(14981),d=t(405),u=t(83475),m=t(22368),x=t(92289),p=t(79372),f=t(48368),h=t(52484),b=t(37231),g=t(90258),j=t(51726);let y=({formConfig:e})=>{let{control:s,setValue:t,watch:n}=(0,r.xW)(),i=e.resume.itemsField||"Details",c=(0,r.FH)({name:i,control:s}),o=(0,l.useCallback)(()=>{if(!c||!Array.isArray(c))return void console.error("Details data is invalid or not an array");let s=e=>c.reduce((s,t)=>s+(parseFloat(t?.[e])||0),0),a=s("subTotal"),l=s("totalTax"),r=s("discountAmount"),n=s("promotionAmount"),i=e=>Number(((e,s=2)=>{let t=parseFloat(e)||0,a=Math.pow(10,s);return Math.ceil(t*a)/a})(e,2).toFixed(2)),o={total:i(a+l),subTotal:i(a),totalTax:i(l),totalDiscount:i(r),totalPromotion:i(n)};e.resume.appendValues&&e.resume.fields.forEach(e=>{void 0!==o[e.field]&&t(e?.formValue||e?.field,o[e.field])})},[c,e.totalCalculation.fields,t,e.resume.appendValues]);if((0,l.useEffect)(()=>{o()},[c,o]),!e.calculateTotal)return null;let d=e=>parseFloat(n(e?.formValue?e.formValue:e.field)),u=e=>{let s=d(e);return Number.isFinite(s)?s.toFixed(2):"N/A"},m=e?.resume?.fields||[],x=e=>"total"===e.field,p=new Set(["totalDiscount","totalPromotion","discount"]),f=m.filter(e=>!x(e)).filter(e=>!p.has(e.field)||0!==(d(e)||0)),h=e?.currency?.symbol??"";return(0,a.jsxs)("div",{className:"flex flex-col gap-2",children:[f.map(e=>(0,a.jsxs)("div",{className:"flex items-center justify-between text-sm text-muted-foreground",children:[(0,a.jsx)("span",{className:"capitalize",children:e?.label}),(0,a.jsxs)("span",{children:[p.has(e.field)?"-":"",h," ",u(e)]})]},e.field)),m.filter(x).map(e=>(0,a.jsxs)("div",{className:"mt-1 flex items-center justify-between border-t pt-2",children:[(0,a.jsx)("span",{className:"text-sm font-medium capitalize text-foreground",children:e?.label}),(0,a.jsxs)("span",{className:"text-xl font-bold text-primary",children:[h," ",u(e)]})]},e.field))]})};var N=t(57657),v=t(68189),C=t(42067),A=t(70733),w=t(77104),D=t(68822),E=t(6296),S=t(98981),_=t(5872),P=t(80723),R=t(51914),I=t(71275),O=t(68459),k=t(40037),L=t(86190),T=t(50910),z=t(9339);let F=(0,z.createServerReference)("407021047a6a23ea2c30a3fb2e62a109397ae08886",z.callServer,void 0,z.findSourceMapURL,"getInvoiceTotals");var M=t(35077),V=t(68034);function $({config:e={}}){let s,t={open:!1,setOpen:()=>{},total:0,currency:{},currencies:[],paymentMethods:[],submit:()=>{},askCondition:!1,availableCredit:null,...e},n=(0,T.c)("components.transaction-form"),i=(0,c.Ym)(),{setValue:o,watch:d}=(0,r.xW)(),u=t.availableCredit,m=null!==u&&0>=Number(u),x=t.askCondition&&!m,[f,h]=(0,l.useState)(x?"condition":"cash"),[b,g]=(0,l.useState)("currency"),[j,y]=(0,l.useState)(!1),[z,M]=(0,l.useState)(!1),[K,U]=(0,l.useState)([]),[Y,G]=(0,l.useState)(""),[q,W]=(0,l.useState)(!1),[H,J]=(0,l.useState)(null),[Q,X]=(0,l.useState)(""),Z=(0,l.useRef)(null),ee=(0,l.useRef)(null),es=(0,l.useRef)(null),et=(0,l.useRef)(null),ea=(t.currencies||[]).filter(e=>e?.status!==!1&&e?.Status!==!1),el=ea.find(e=>String(e.currencyCode)===String(t.currency?.currencyCode))||ea.find(e=>String(e.currencyCode)===String(t.currency?.isoCode))||t.currency||ea[0]||null,[er,en]=(0,l.useState)(el),ei=e=>{if(null==e)return"";let s=Number(e);if(Number.isNaN(s))return"";try{return new Intl.NumberFormat(V.l0,{minimumFractionDigits:2,maximumFractionDigits:2}).format(s)}catch(e){return s.toFixed(2)}},ec=K.reduce((e,s)=>e+(s.convertedAmount||0),0),eo=ec-(t.total||0),ed=(t.total||0)-ec,eu=async()=>{if(eo>=0){M(!0);try{o("isCreditSale",!1),o("status",k.fW.APPROVED),o("paymentMethodsDetails",K),await Promise.resolve(t.submit()),M(!1),t.setOpen(!1)}catch(e){console.error(e),W(!1),M(!1)}}},em=async()=>{M(!0);
1try{o("isCreditSale",!0),o("paymentMethodsDetails",[]),await Promise.resolve(t.submit()),M(!1),t.setOpen(!1)}catch(e){console.error(e),M(!1)}},ex=e=>e?(t.paymentMethods||[]).filter(s=>{let t=s?.CurrencyCode,a=e?.currencyCode;return String(t)===String(a)&&s?.Status!==!1}):[],ep=d(),ef={...ep,details:(ep.details||[]).map(e=>({...e,id:e.id,name:e.name,quantity:e.quantity,price:e.price,subtotal:e.subTotal,tax:e.taxData,discount:e.discount,total:e.totalAmount,QuantityReturned:0}))},eh=async()=>{try{y(!0);let e=await F(ef);if(e.Error)throw Error(e.Error.Message[i]||e.Error.Message.en||"Error");o("subTotal",e.Data.subtotalCount||0),o("totalTax",e.Data.tax||0),o("total",e.Data.totalRounded||0)}catch(e){console.error("Error fetching invoice totals:",e)}finally{y(!1)}};(0,l.useEffect)(()=>{t.open&&(h(x?"condition":"cash"),g(K.length>0?"list":"currency"),J(null),eh())},[t.open]);let eb=Number(d("total"))||t.total||0,eg=Number(d("subTotal"))||0,ej=Number(d("totalTax"))||0,ey=(d("details")||[]).reduce((e,s)=>e+(Number(s?.discount)||0),0),eN=null!==u&&Number(u)>0&&eb>Number(u),ev=Number(t.currency?.exchangeRate)||1,eC=(t.currencies||[]).find(e=>String(e?.currencyCode)!==String(t.currency?.currencyCode)&&(e?.baseCurrency===!0||e?.BaseCurrency===!0)),eA=eC&&Number(eC.exchangeRate)?(0,L.Yq)(ev,Number(eC.exchangeRate),eb):null,ew=()=>{o("isCreditSale",!1),J(null),g(K.length>0?"list":"currency"),h("cash")},eD=e=>{let s=e?.Currency?.exchangeRate??e?.exchangeRate??er?.exchangeRate??1,t=(0,L.Yq)(ev,Number(s)||1,Math.max(ed,0));J(e),X(t>0?t.toFixed(2):"")},eE=()=>{((e,s)=>{if(!e)return;let a=parseFloat(s);if(!(a>0))return;let l=e?.Currency?.exchangeRate??e?.exchangeRate??er?.exchangeRate??1,r=t?.currency?.exchangeRate??1,n=(0,L.Yq)(l,r,a),i={id:K.length+1,code:e?.Code||null,description:e?.Description||e?.MethodName||"",name:e?.MethodName||e?.Description||"",convertedAmount:n,amount:+a.toFixed(2),currencySymbol:er?.symbol||"",currencyCode:er?.currencyCode,currency:er?.isoCode,bankCode:null,bankName:null,bankReference:null,allowsChange:e?.AllowsChange??!1},c=[...K,i];U(c);try{o("paymentMethodsDetails",c)}catch(e){}})(H,Q),J(null),X(""),g("list")},eS=d("customerName")||d("customerFullName"),e_=d("customerCode"),eP=d("documentCode")||d("correlative")||d("documentNumber"),eR={condition:n("payment"),cash:n("payment"),credit:n("credit_summary_title")};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(N.Dialog,{open:t.open,onOpenChange:t.setOpen,children:(0,a.jsxs)(N.DialogContent,{className:`max-w-[95vw] w-full max-h-[90vh] overflow-y-auto ${"cash"===f?"sm:max-w-[900px]":"sm:max-w-[520px]"}`,children:[(0,a.jsx)(N.DialogHeader,{children:(0,a.jsxs)(N.DialogTitle,{className:"flex items-center gap-2",children:[(x&&"condition"!==f||"cash"===f&&"methods"===b)&&(0,a.jsx)("button",{type:"button",onClick:()=>{"credit"===f?h("condition"):"cash"===f&&("methods"===b?g("currency"):x&&h("condition"))},className:"rounded-md p-1 hover:bg-muted","aria-label":n("back"),children:(0,a.jsx)(P.A,{className:"size-4"})}),eR[f]||n("payment")]})}),j?(0,a.jsx)(B,{t:n}):"condition"===f?(0,a.jsxs)("div",{className:"space-y-4 py-2",onKeyDown:e=>{"1"===e.key?(e.preventDefault(),ew()):"2"===e.key?(e.preventDefault(),m||h("credit")):["ArrowRight","ArrowDown"].includes(e.key)?(e.preventDefault(),es.current?.focus()):["ArrowLeft","ArrowUp"].includes(e.key)&&(e.preventDefault(),ee.current?.focus())},children:[(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:n("payment_condition_title")}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[(0,a.jsxs)("button",{ref:ee,type:"button",autoFocus:!0,onClick:ew,className:"relative flex flex-col items-center gap-2 rounded-xl border-2 border-transparent bg-muted/40 p-5 text-center transition hover:border-primary hover:bg-primary/5 focus-visible:border-primary focus-visible:outline-none",children:[(0,a.jsx)("span",{className:"absolute left-2 top-2 text-xs font-semibold text-muted-foreground",children:"1"}),(0,a.jsx)("span",{className:"flex size-11 items-center justify-center rounded-full bg-success-tint text-success",children:(0,a.jsx)(w.A,{className:"size-6"})}),(0,a.jsx)("span",{className:"text-base font-semibold",children:n("pay_cash")})]}),(0,a.jsxs)("button",{ref:es,type:"button",disabled:m,onClick:()=>h("credit"),className:`relative flex flex-col items-center gap-2 rounded-xl border-2 border-transparent p-5 text-center transition focus-visible:border-primary focus-visible:outline-none ${m?"curs
1or-not-allowed bg-muted/40 opacity-60":"bg-muted/40 hover:border-primary hover:bg-primary/5"}`,children:[(0,a.jsx)("span",{className:"absolute left-2 top-2 text-xs font-semibold text-muted-foreground",children:"2"}),(0,a.jsx)("span",{className:"flex size-11 items-center justify-center rounded-full bg-primary-100 text-violet-600",children:(0,a.jsx)(p.A,{className:"size-6"})}),(0,a.jsx)("span",{className:"text-base font-semibold",children:n("pay_credit")}),m&&(0,a.jsx)("span",{className:"text-xs text-destructive",children:n("no_credit_available")})]})]}),(0,a.jsx)("div",{className:"border-t pt-3",children:(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[(0,a.jsx)("span",{className:"text-base font-semibold text-primary",children:n("total")}),(0,a.jsxs)("span",{className:"text-base font-semibold text-primary",children:[t.currency?.symbol,ei(eb)]})]})}),(0,a.jsx)("p",{className:"text-center text-[11px] text-muted-foreground",children:n("keyboard_hint_condition")})]}):"credit"===f?(0,a.jsxs)("div",{className:"space-y-4 py-2",children:[(0,a.jsxs)("div",{className:"rounded-xl border bg-muted/30 p-4 space-y-2 text-sm",children:[(0,a.jsxs)("div",{className:"flex justify-between",children:[(0,a.jsx)("span",{className:"text-muted-foreground",children:n("subtotal")}),(0,a.jsxs)("span",{children:[t.currency?.symbol,ei(d("subTotal")||0)]})]}),(0,a.jsxs)("div",{className:"flex justify-between",children:[(0,a.jsx)("span",{className:"text-muted-foreground",children:n("tax")}),(0,a.jsxs)("span",{children:[t.currency?.symbol,ei(d("totalTax")||0)]})]}),(0,a.jsxs)("div",{className:"flex justify-between border-t pt-2 text-primary",children:[(0,a.jsx)("span",{className:"text-base font-semibold",children:n("total")}),(0,a.jsxs)("span",{className:"text-base font-semibold",children:[t.currency?.symbol,ei(eb)]})]}),null!==u&&(0,a.jsxs)("div",{className:"flex justify-between",children:[(0,a.jsx)("span",{className:"text-muted-foreground",children:n("available_credit")}),(0,a.jsxs)("span",{className:eN?"text-warning":"text-success",children:[t.currency?.symbol,ei(u)]})]})]}),eN&&(0,a.jsxs)("p",{className:"flex items-start gap-2 rounded-lg border border-warning/30 bg-warning-tint px-3 py-2 text-xs text-warning",children:[(0,a.jsx)(D.A,{className:"mt-0.5 size-4 shrink-0"}),n("credit_exceeded",{amount:ei(u)})]}),(0,a.jsx)(v.Button,{variant:"default",className:"w-full",autoFocus:!0,onClick:em,disabled:z||eb<=0||eN,children:z?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(E.A,{className:"mr-2 h-4 w-4 animate-spin"}),n("emitting")]}):n("emit_credit")})]}):(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-6 py-2 md:grid-cols-2",children:[(0,a.jsx)("div",{className:"md:border-r md:pr-6",children:(0,a.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,a.jsxs)("div",{className:"rounded-xl bg-muted/40 p-4",children:[eS&&(0,a.jsx)("p",{className:"text-lg font-semibold",children:eS}),(0,a.jsxs)("div",{className:"flex flex-wrap items-center gap-x-4 gap-y-0.5 text-xs text-muted-foreground",children:[e_&&(0,a.jsxs)("span",{children:[n("customer_code"),": ",e_]}),eP&&(0,a.jsxs)("span",{children:[n("invoice_number"),":"," ",(0,a.jsx)("span",{className:"font-semibold text-foreground",children:eP})]})]})]}),(0,a.jsxs)("div",{children:[(0,a.jsxs)("div",{className:"flex items-baseline gap-2",children:[(0,a.jsxs)("span",{className:"text-2xl font-bold",children:[n("total"),":"]}),(0,a.jsxs)("span",{className:"text-2xl font-bold",children:[t.currency?.symbol," ",ei(eb)]})]}),null!=eA&&(0,a.jsxs)("p",{className:"text-sm text-muted-foreground",children:[eC?.symbol," ",ei(eA)]})]}),(0,a.jsxs)("div",{className:"space-y-1",children:[(0,a.jsxs)("div",{className:"flex justify-between",children:[(0,a.jsxs)("span",{className:"text-base font-semibold text-info",children:[n("cancelled"),":"]}),(0,a.jsxs)("span",{className:"text-base font-semibold text-info",children:[t.currency?.symbol," ",ei(ec)]})]}),(0,a.jsxs)("div",{className:"flex justify-between",children:[(0,a.jsxs)("span",{className:"text-base font-semibold text-destructive",children:[n("change"),":"]}),(0,a.jsxs)("span",{className:`text-base font-semibold ${eo>=0?"text-success":"text-destructive"}`,children:[t.currency?.symbol," ",ei(eo)]})]})]}),(0,a.jsxs)("div",{className:"space-y-1 border-t pt-3 text-sm",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[(0,a.jsxs)("span",{className:"text-muted-foreground",children:[n("subtotal"),":"]}),(0,a.jsxs)("span",{children:[t.currency?.symbol," ",ei(eg)]})]}),ey>0&&(0,a.jsxs)("details",{className:"group w-full [&_summary::-webkit-details-marker]:hidden",children:[(0,a.jsxs)("summary",{className:"flex cursor-pointer list-none items-center justify-between gap-2",children:[(0,a.jsxs)("span",{className:"flex items-center gap-1 text-success",children:[(0,a.jsx)(S.A,{className:"h-4 w-4 transition-transform group-open:rotate-90"}),n("discount"),":"]}),(0,a.jsxs)("span",{className:"font-semibold text-success",children:["- ",t.currency?.symbol," ",ei(ey)]})]}),(0,a.jsx)("div",{className:"mt-1 flex flex-col gap-0.5 pl-5",children:(0,a.jsxs)("div",{className:"flex items-center justify-between text-success",children:[(0,a.jsxs)("span",{children:[n("product_discount"),":"]}),(0,a.jsxs)("span",{children:["- ",t.currency?.symbol," ",ei(ey)]})]})})]}),ej>0&&(0,a.jsxs)("details",{className:"group w-full [&_summary::-webkit-details-marker]:hidden",children:[(0,a.jsxs)("summary",{className:"flex cursor-pointer list-none items-center justify-between gap-2",children:[(0,a.jsxs)("span",{className:"flex items-center gap-1 text-muted-foreground",children:[(0,a.jsx)(S.A,{className:"h-4 w-4 transition-transform group-open:rotate-90"}),n("tax"),":"]}),(0,a.jsxs)("span",{children:[t.currency?.symbol," ",ei(ej)]})]}),(0,a.jsx)("div",{className:"mt-1 flex flex-col gap-0.5 pl-5 text-muted-foreground",children:(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[(0,a.jsxs)("span",{children:[n("product_tax"),":"]}),(0,a.jsxs)("span",{children:[t.currency?.symbol," ",ei(ej)]})]})})]})]})]})}),(0,a.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,a.jsxs)("div",{className:"flex min-h-[360px] flex-1 flex-col rounded-xl bg-muted/50 p-4",children:["currency"===b&&(0,a.jsxs)("div",{className:"flex flex-col gap-3",onKeyDown:e=>
1{if(/^[1-9]$/.test(e.key)){let s=ea[parseInt(e.key,10)-1];s&&(e.preventDefault(),en(s),g("methods"))}},children:[(0,a.jsx)("h3",{className:"text-center text-lg font-semibold",children:n("select_currency")}),0===ea.length?(0,a.jsx)("p",{className:"py-6 text-center text-sm text-muted-foreground",children:n("no_currencies")}):ea.map((e,s)=>(0,a.jsxs)("button",{type:"button",autoFocus:0===s,onClick:()=>{en(e),g("methods")},className:"flex w-full items-center gap-3 rounded-xl border bg-card px-5 py-5 text-left transition hover:border-primary hover:bg-primary/5 focus-visible:border-primary focus-visible:outline-none",children:[(0,a.jsx)("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-full bg-muted text-muted-foreground",children:(0,a.jsx)(_.A,{className:"size-5"})}),(0,a.jsxs)("span",{className:"text-base font-medium",children:[e.symbol," - ",e?.currencyName||e?.name||e?.isoCode||e?.symbol||""]})]},e.currencyCode??s))]}),"methods"===b&&(s=ex(er),(0,a.jsxs)("div",{className:"flex flex-col gap-3",onKeyDown:e=>{if(/^[1-9]$/.test(e.key)){let t=s[parseInt(e.key,10)-1];t&&(e.preventDefault(),eD(t))}},children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("button",{type:"button",onClick:()=>g("currency"),className:"rounded-md p-1 hover:bg-muted","aria-label":n("back"),children:(0,a.jsx)(P.A,{className:"size-4"})}),(0,a.jsx)("h3",{className:"flex-1 text-center text-lg font-semibold",children:n("select_payment_method")}),(0,a.jsx)("span",{className:"w-6"})]}),0===s.length?(0,a.jsxs)("div",{className:"flex flex-col items-center gap-3 py-6 text-center",children:[(0,a.jsx)("p",{className:"text-sm font-medium text-muted-foreground",children:n("no_payment_methods_available")}),(0,a.jsxs)("a",{href:`/${i}/apps/treasury/payment_methods/new`,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-2 rounded-lg border border-primary px-4 py-2 text-sm font-semibold text-primary transition hover:bg-primary/5",children:[(0,a.jsx)(R.A,{className:"size-4"}),n("create_payment_methods_to_continue")]})]}):s.map((e,s)=>(0,a.jsxs)("button",{type:"button",autoFocus:0===s,onClick:()=>eD(e),className:"flex w-full items-center gap-3 rounded-xl border bg-card px-5 py-5 text-left transition hover:border-primary hover:bg-primary/5 focus-visible:border-primary focus-visible:outline-none",children:[(0,a.jsx)("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-full bg-muted text-muted-foreground",children:(0,a.jsx)(I.A,{className:"size-5"})}),(0,a.jsx)("span",{className:"text-base font-medium",children:e.Description||e.MethodName})]},e.Code||e.ConfigurationCode||e.MethodName||s))]})),"list"===b&&(0,a.jsxs)("div",{className:"flex flex-col gap-3",children:[0===K.length?(0,a.jsx)("p",{className:"py-6 text-center text-sm text-muted-foreground",children:n("enter_amount")}):K.map((e,s)=>(0,a.jsxs)("div",{className:"flex items-center justify-between gap-3 rounded-xl border bg-card px-4 py-3",children:[(0,a.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,a.jsx)("p",{className:"truncate font-semibold",children:e.description||e.name}),(0,a.jsxs)("p",{className:"text-xs text-muted-foreground",children:[n("amount"),": ",e.currencySymbol,ei(e.amount)," (",e.currency,")"]})]}),(0,a.jsxs)("span",{className:"whitespace-nowrap font-semibold",children:[t.currency?.symbol," ",ei(e.convertedAmount)]}),(0,a.jsx)(v.Button,{variant:"ghost",size:"sm",className:"h-8 w-8 shrink-0 p-0",onClick:()=>(e=>{let s=K.filter((s,t)=>t!==e);U(s);try{o("paymentMethodsDetails",s)}catch(e){}W(!1)})(s),disabled:q,children:(0,a.jsx)(O.A,{className:"h-4 w-4 text-destructive"})})]},s)),(0,a.jsxs)(v.Button,{type:"button",variant:"default",className:"w-full",onClick:()=>g("currency"),disabled:q||ed<=0,children:[(0,a.jsx)(R.A,{className:"mr-1 size-4"}),n("add_payment_method")]}),eo>0&&(0,a.jsxs)(A.l6,{onValueChange:G,disabled:q,children:[(0,a.jsx)(A.bq,{children:(0,a.jsx)(A.yv,{placeholder:n("select_change_method")})}),(0,a.jsx)(A.gC,{children:ex(er).filter(e=>e?.AllowsChange).map(e=>(0,a.jsx)(A.eb,{value:e.Code,children:e.Description||e.MethodName},e.Code||e.ConfigurationCode))})]})]})]}),"list"===b&&K.length>0&&(0,a.jsx)(v.Button,{ref:Z,onClick:eu,disabled:ed>0||eo>0&&!Y||z,className:"h-14 w-full rounded-xl bg-success text-lg font-bold uppercase tracking-wide text-success hover:bg-success disabled:opacity-60",children:z?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(E.A,{className:"mr-2 h-5 w-5 animate-spin"})," ",n("processing")]}):n("pay")})]})]})]})}),(0,a.jsx)(N.Dialog,{open:!!H,onOpenChange:e=>{e||(J(null),X(""))},children:(0,a.jsxs)(N.DialogContent,{className:"max-w-[95vw] w-full sm:max-w-[440px]",children:[(0,a.jsx)(N.DialogHeader,{children:(0,a.jsx)(N.DialogTitle,{children:n("payment_details")})}),(0,a.jsx)("p",{className:"-mt-2 text-sm text-muted-foreground",children:n("payment_details_subtitle")}),(0,a.jsxs)("div",{className:"space-y-4 py-2",children:[(0,a.jsxs)("div",{className:"space-y-1",children:[(0,a.jsxs)("span",{className:"text-sm font-semibold",children:[n("enter_amount"),":"]}
1),(0,a.jsx)(C.Input,{ref:et,autoFocus:!0,type:"number",value:Q,onChange:e=>X(e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),parseFloat(Q)>0&&eE())},placeholder:n("enter_amount_placeholder"),className:"text-right",prefix:er?.symbol})]}),(0,a.jsxs)("div",{className:"space-y-1 border-t pt-3 text-sm",children:[(0,a.jsxs)("div",{className:"flex justify-between text-muted-foreground",children:[(0,a.jsx)("span",{children:n("subtotal")}),(0,a.jsxs)("span",{children:[t.currency?.symbol," ",ei(eb)]})]}),(0,a.jsxs)("div",{className:"flex justify-between text-muted-foreground",children:[(0,a.jsx)("span",{children:n("remaining")}),(0,a.jsxs)("span",{children:[t.currency?.symbol," ",ei(Math.max(ed,0))]})]})]}),(0,a.jsx)("div",{className:"flex justify-end",children:(0,a.jsx)(v.Button,{type:"button",onClick:eE,disabled:!(parseFloat(Q)>0),children:n("add_payment")})})]})]})})]})}let B=({t:e=()=>{}})=>(0,a.jsxs)("div",{className:"flex flex-col items-center justify-center p-10",children:[(0,a.jsx)(M.A,{className:"min-h-[200px] w-full"}),(0,a.jsx)("p",{className:"text-xl font-semibold text-primary",children:e("loading_invoice_totals")})]});t(5772);var K=t(80642),U=t(67192),Y=t(72055);let G=({config:e})=>{let s=(0,T.c)("components.dynamic-sticky-header"),[t,r]=(0,l.useState)(!1);return(0,l.useEffect)(()=>{let e=()=>{r(window.scrollY>100)};return window.addEventListener("scroll",e),()=>window.removeEventListener("scroll",e)},[]),(0,a.jsx)(K.N,{children:(0,a.jsx)(U.P.header,{className:"w-full sticky z-30 top-[8rem] md:top-[8.7rem] bg-card border-b border-border shadow-sm",initial:{opacity:+!!t,y:t?0:-20},animate:{opacity:+!!t,y:t?0:-20},exit:{opacity:0,y:-20},transition:{duration:.3,ease:"easeInOut"},children:(0,a.jsx)("div",{className:"w-full px-4 py-3",children:(0,a.jsxs)("div",{className:"flex flex-row items-center justify-between flex-wrap",children:[e.fields.map((e,s)=>((e,s)=>{if("static"===e.type)return(0,a.jsxs)("div",{className:"flex flex-col items-start",children:[(0,a.jsx)("p",{className:"text-xs text-muted-foreground uppercase tracking-wide",children:e.title}),(0,a.jsx)("p",{className:"text-sm font-semibold",children:e.content})]},`header-static-${s}`)})(e,s)),(0,a.jsxs)(U.P.button,{onClick:()=>{window.scrollTo({top:0,behavior:"smooth"})},className:"text-primary p-1.5 hover:text-primary-500 transition-colors flex items-center gap-2","aria-label":"Back to top",initial:{opacity:0,scale:.8},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.8},transition:{duration:.2},children:[s("BackToTop")," ",(0,a.jsx)(Y.A,{size:16})]})]})})})})};var q=t(73331),W=t.n(q);let H=({onSubmit:e=()=>{},formConfig:s})=>{let{control:t,handleSubmit:n,watch:i}=(0,r.xW)(),[c,o]=(0,l.useState)(!1),d=(0,T.c)("components.transaction-form");return(0,a.jsxs)(a.Fragment,{children:[s?.usesPayment&&c&&(0,a.jsx)($,{config:{open:c,setOpen:o,currency:s?.currency,currencies:s?.currencies,paymentMethods:s?.paymentMethods||[],total:+i(s?.usesPayment?.totalField),callbackUrl:s.successURL,submit:n(e)}}),(0,a.jsx)(G,{config:s.header}),(0,a.jsx)("div",{className:"w-full mx-auto bg-card p-2 md:p-10 rounded-lg shadow-sm -mt-14",children:(0,a.jsxs)("form",{onSubmit:n(e),children:[(0,a.jsx)("div",{className:"mb-6",children:(0,a.jsxs)("div",{className:"flex flex-col md:flex-row md:justify-between",children:[(0,a.jsxs)("div",{className:"text-left flex flex-col md:flex-row md:space-x-3 md:items-center",children:[s?.header?.image&&(0,a.jsx)("img",{src:W()(s?.header?.image)?s?.header?.image:"/Images/placeholder.svg",alt:s?.header?.title||"Form Image",width:140,height:140,className:"object-cover border border-border rounded-md p-1"}),(0,a.jsxs)("div",{children:[(0,a.jsx)("h1",{className:"text-xl md:text-3xl font-bold",children:s?.header?.title}),(0,a.jsx)("p",{className:"text-lg md:text-2xl",children:s?.header?.subtitle}),(0,a.jsx)("p",{className:"text-md md:text-xl",children:s?.header?.text}),(0,a.jsx)("p",{className:"text-md md:text-lg",children:s?.header?.subText})]})]}),(0,a.jsx)("div",{children:s?.header?.fields?.map((e,s)=>"static"===e.type?(0,a.jsxs)("div",{className:"flex flex-col items-start",children:[(0,a.jsx)("p",{className:"text-sm text-muted-foreground uppercase tracking-wide",children:e.title}),(0,a.jsx)("p",{className:"text-lg font-semibold",children:e.content})]},`header-static-${s}`):(0,a.jsxs)("div",{className:"flex flex-col items-start",children:[e.additionalProps?.label&&(0,a.jsxs)("p",{className:"text-sm text-muted-foreground uppercase tracking-wide",children:[e.additionalProps.label,":"]}
1),(0,a.jsx)(g.A,{control:t,name:e.name,type:e.type,label:e.label,options:e.options,additionalProps:e.additionalProps,additionalFields:e.additionalFields},`header-formfield-${e.name}-${s}`)]},`header-field-${s}`))})]})}),(0,a.jsx)(j.Separator,{className:"mt-5 mb-5"}),s?.body?.sections?.map((e,s)=>(0,a.jsxs)("div",{className:"mb-6",children:[e.title&&(0,a.jsx)("h3",{className:"text-xl font-semibold",children:e.title}),(0,a.jsx)("p",{className:"text-sm",children:e?.helperText}),(0,a.jsx)("div",{className:(0,L.cn)("w-full",e?.className),children:e.fields.map((e,s)=>"static"===e.type?(0,a.jsxs)("div",{className:"flex flex-col items-start py-2",children:[e.title&&(0,a.jsx)("p",{className:"text-sm text-muted-foreground uppercase tracking-wide",children:e.title}),(0,a.jsx)("p",{className:"text-lg font-semibold",children:e.content})]},`body-static-${s}`):(0,a.jsx)(g.A,{control:t,name:e.name,type:e.type,label:e.label,options:e.options,additionalProps:e.additionalProps,additionalFields:e.additionalFields},`body-field-${e.name}-${s}`))})]},`body-section-${s}`)),s?.observations!==!1&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(j.Separator,{className:"mt-5 mb-5"}),(0,a.jsxs)("div",{className:"flex flex-col md:flex-row space-x-5",children:[(0,a.jsx)("div",{className:"flex-1",children:(0,a.jsx)(g.A,{control:t,name:s?.body?.observationKey||"observation",type:"textarea",className:"w-full",options:{placeholder:d("observation")}})}),s?.resume&&s.calculateTotal&&(0,a.jsx)("div",{className:"w-full md:w-72",children:(0,a.jsx)("div",{className:"rounded-xl border bg-primary-100/40 p-4",children:(0,a.jsx)(y,{formConfig:s})})})]})," "]}),s?.usesPayment&&!i("isCreditSale")&&(0,a.jsx)("div",{className:"flex justify-end",children:(0,a.jsxs)(v.Button,{type:"button",variant:"default",size:"lg",onClick:()=>o(!0),disabled:0>=i(s?.usesPayment?.totalField)||!i("customerCode"),children:[d("proceed-to-payment"),(0,a.jsx)(_.A,{className:"ml-2",size:24})]})})]})})]})};var J=t(72140),Q=t(42869),X=t(50049),Z=t(2943),ee=t(24538),es=t(84980),et=t(85877),ea=t(21053),el=t(93219),er=t(48106),en=t(53961),ei=t(56204),ec=t(35799),eo=t.n(ec),ed=t(49387),eu=t(1732);function em({field:e,accent:s=null,readOnly:t=!1,i18nScope:n=null}){let{icon:i=null,iconClass:c="text-muted-foreground",bgClass:o="bg-muted"}=s||{},{control:d,watch:u,register:m}=(0,r.xW)(),x=(0,T.c)(n||"applications.sales.invoicing"),[p,f]=l.useState(!1),h=u(e.name),b="static"===e.type,j=t||b,y=l.useMemo(()=>{if(b)return e.content??null;if(null==h||""===h||Array.isArray(h)&&0===h.length)return null;switch(e.type){case"select":{let s=(e.options?.choices||[]).find(e=>String(e.value)===String(h));return s?s.label:String(h)}case"multiple-selector":{let s=e.options?.options||[],t=e.options?.labelAccesorKey||"name",a=e.options?.idAccesorKey||"id";return(Array.isArray(h)?h:[h]).map(e=>{let l=e&&"object"==typeof e?e[a]:e,r=s.find(e=>eo()(e,a)===l);return r?eo()(r,t):String(l)}).join(", ")}case"select-popover":{let s=e.additionalProps?.items||[],t=e.additionalProps?.valueProp||"id",a=e.additionalProps?.valueLabel||"name",l=s.find(e=>String(eo()(e,t))===String(h));return l?eo()(l,a):String(h)}case"account-popover-selector":{let s=e.options?.accounts||[],t=e.options?.accountConfig||{},a=s.find(e=>String(eo()(e,t.key))===String(h));return a?eo()(a,t.nameKey):String(h)}case"datepicker":case"datetimepicker":{let e=h instanceof Date?h:new Date(h);return isNaN(e.getTime())?String(h):e.toLocaleDateString()}default:return String(h)}},[h,e,b]);return(0,a.jsxs)("div",{className:"flex items-start gap-2.5 rounded-xl border bg-card p-3",children:[(0,a.jsx)("span",{className:`mt-0.5 flex size-7 shrink-0 items-center justify-center rounded-lg ${o} ${c}`,children:i}),(0,a.jsxs)("div",{className:"flex min-w-0 flex-1 flex-col gap-0.5",children:[(0,a.jsx)("span",{className:"text-[11px] uppercase tracking-wide text-muted-foreground",children:e.label||e.title}),(0,a.jsxs)("div",{className:"flex items-start gap-2",children:[(0,a.jsx)("span",{className:"line-clamp-2 break-words text-sm font-medium leading-snug text-foreground",title:"string"==typeof y?y:void 0,children:y??(0,a.jsx)("span",{className:"font-normal italic text-muted-foreground",children:x("compact.not_set")})}),!j&&(0,a.jsxs)(eu.AM,{open:p,onOpenChange:f,children:[(0,a.jsx)(eu.Wv,{asChild:!0,children:(0,a.jsxs)("button",{type:"button",className:"inline-flex shrink-0 items-center gap-0.5 text-[11px] text-primary hover:underline","aria-label":x("compact.edit"),children:[(0,a.jsx)(ed.A,{className:"size-3"}),x("compact.edit")]})}),(0,a.jsxs)(eu.hl,{align:"start",className:"w-80",children:[(0,a.jsx)("p",{className:"mb-2 text-sm font-medium",children:e.label||e.title}),(0,a.jsx)(g.A,{control:d,name:e.name,type:e.type,label:null,options:e.options,additionalProps:e.additionalProps,additionalFields:e.additionalFields})]})]})]})]}),j&&!b&&(0,a.jsx)("input",{type:"hidden",...m(e.name)}
1)]})}var ex=t(33210),ep=t(66890),ef=t(60848);function eh({accounts:e=[],accountConfig:s={},value:t=null,onChange:r=()=>{},placeholder:n="Search...",emptyMessage:i="No results found.",detailSlot:c=null,autoFocus:o=!1}){let[d,u]=l.useState(!1),[m,x]=l.useState(""),p=l.useRef(null),f=l.useMemo(()=>e.find(e=>eo()(e,s.key)===t)||null,[e,s.key,t]);return f?(0,a.jsxs)("div",{className:"flex items-center justify-between gap-3 rounded-md border bg-white-base px-3 py-2",children:[(0,a.jsxs)("div",{className:"flex items-center gap-3 min-w-0",children:[(0,a.jsxs)(ep.Avatar,{className:"size-9",children:[(0,a.jsx)(ep.AvatarImage,{src:eo()(f,s.imageKey),alt:eo()(f,s.nameKey)}),(0,a.jsx)(ep.AvatarFallback,{children:eo()(f,s.nameKey)?.charAt(0)||"?"})]}),(0,a.jsxs)("div",{className:"min-w-0",children:[(0,a.jsx)("p",{className:"truncate text-sm font-medium text-foreground",children:eo()(f,s.nameKey)||"N/A"}),(0,a.jsx)("p",{className:"truncate text-xs text-muted-foreground",children:eo()(f,s.contactKey)}),c]})]}),(0,a.jsx)("button",{type:"button",onClick:()=>{r(""),x("")},className:"shrink-0 rounded-md p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Clear",children:(0,a.jsx)(ex.A,{className:"size-4"})})]}):(0,a.jsx)("div",{className:"relative",children:(0,a.jsxs)(ef.uB,{className:"overflow-visible rounded-md border bg-white-base",children:[(0,a.jsx)(ef.G7,{autoFocus:o,placeholder:n,value:m,onValueChange:e=>{x(e),u(!0)},onFocus:()=>u(!0),onBlur:()=>{p.current=setTimeout(()=>u(!1),150)},className:"border-0"}),d&&(0,a.jsxs)(ef.oI,{className:"absolute left-0 right-0 top-[calc(100%+4px)] z-50 max-h-64 rounded-md border bg-popover shadow-md",onMouseDown:()=>{p.current&&clearTimeout(p.current)},children:[(0,a.jsx)(ef.xL,{children:i}),(0,a.jsx)(ef.L$,{children:e.map(e=>{let t=eo()(e,s.key),l=eo()(e,s.nameKey)||"",n=eo()(e,s.contactKey)||"";return(0,a.jsxs)(ef.h_,{value:`${l} ${n} ${t}`,onSelect:()=>{r(eo()(e,s.key)),u(!1),x("")},className:"gap-3",children:[(0,a.jsxs)(ep.Avatar,{className:"size-8",children:[(0,a.jsx)(ep.AvatarImage,{src:eo()(e,s.imageKey),alt:l}),(0,a.jsx)(ep.AvatarFallback,{children:l.charAt(0)||"?"})]}),(0,a.jsxs)("div",{className:"min-w-0",children:[(0,a.jsx)("p",{className:"truncate text-sm font-medium",children:l||"N/A"}),(0,a.jsx)("p",{className:"truncate text-xs text-muted-foreground",children:n})]})]},t)})})]})]})})}var eb=t(33851),eg=t(6962),ej=t(61878),ey=t(16950),eN=t(13545),ev=t(45706),eC=t(58276);let eA=(0,z.createServerReference)("705174978d9a45f4606fb43605b6a09c4f728837d6",z.callServer,void 0,z.findSourceMapURL,"getAllSalesDocumentsByFilter"),ew=(0,z.createServerReference)("4024407ee855dfcbb798e14b173fa0be6a9c765b99",z.callServer,void 0,z.findSourceMapURL,"getSalesDocumentById");var eD=t(62155),eE=t(46465);let eS=({i18nScope:e}={})=>{let s=(0,T.c)(e||"applications.sales.invoicing"),{setValue:t,getValues:n}=(0,r.xW)(),c=(0,l.useContext)(eE.A),[o,d]=(0,l.useState)(!1),[u,m]=(0,l.useState)(k.VC.QUOTATION),[x,p]=(0,l.useState)(""),[f,b]=(0,l.useState)(""),[g,j]=(0,l.useState)([]),[y,A]=(0,l.useState)(1),[w,D]=(0,l.useState)(1),[E,S]=(0,l.useState)(!1),[_,P]=(0,l.useState)(!1),[R,I]=(0,l.useState)(null),[O,z]=(0,l.useState)(null),F=[{type:k.VC.QUOTATION,label:s("import.type_quotation")},{type:k.VC.INVOICE,label:s("import.type_invoice")},{type:k.VC.ORDER,label:s("import.type_order")}];(0,l.useEffect)(()=>{let e=setTimeout(()=>b(x.trim()),400);return()=>clearTimeout(e)},[x]);let M=(0,l.useCallback)(async(e,{append:t=!1}={})=>{t?P(!0):S(!0),I(null);try{let a=await eA(u,{page:e,rows:20,documentCode:f||void 0,status:u===k.VC.QUOTATION?k.fW.APPROVED:void 0});if(a?.Error||a?.error){I(s("import.error")),t||j([]);return}let l=a?.Data||{},r=l.list||[],n=l.totalPages||(l.total?Math.ceil(l.total/20):e);j(e=>t?[...e,...r]:r),A(e),D(n||1)}catch{I(s("import.error")),t||j([])}finally{S(!1),P(!1)}},[u,f,s]);(0,l.useEffect)(()=>{o&&M(1)},[o,u,f]);let V=e=>{if(e.unitId&&Array.isArray(e.units)&&e.units.length>0)return e;let s=Array.isArray(e.units)&&e.units[0]||null;return s?{...e,unitId:e.unitId||s.unitID||"",unitName:e.unitName||s.name||"",unitMultiplier:e.unitMultiplier||s.value||1}:e},$=async e=>{let a=e?.documentCode;if(a){z(a),I(null);try{let{Error:e,Data:l}=await ew(a);if(e||!l)return void I(s("import.error"));let r=n("currencyCode"),o=n("warehouseCode"),u=await Promise.all((0,k.J_)(l?.salesData?.details).map(async e=>{let s=e.sku??e.correlativeItem;if(!s)return V(e);try{let t=await (0,eD.p)({Code:s,Currency:r,Warehouse:o}),a=(t?.Data||[]).find(t=>String(t.itemID)===String(e.id)||t.sku===s);return V(((e,s)=>{if(!s)return e;let t=Array.isArray(s.itemCostList)?s.itemCostList:Array.isArray(e.prices)?e.prices:[],a=Number(e.priceValue??0),l=e=>Number(e.price??e.Price??0),r=t.find(e=>l(e)===a),n=t.reduce((e,s)=>null==e||Math.abs(l(s)-a)<Math.abs(l(e)-a)?s:e,null),i=r??n,c=Array.isArray(s.units)?s.units:Array.isArray(e.units)?e.units:[],o=e.unitId&&c.some(s=>s.unitID===e.unitId),d=c[0]||{};return{...e,taxData:s.taxData??e.taxData,prices:t,units:c,price:i?i.id??i.ID??"":e.price,unitId:o?e.unitId:d.unitID??e.unitId??"",unitName:o?e.unitName:d.name??e.unitName??"",unitMultiplier:o?e.unitMultiplier:d.value??e.unitMultiplier??1}})(e,a))}catch{return V(e)}}));if(0===u.length)return void I(s("import.empty_document"));c?.current&&c.current(u),t("documentCodeReferenceForReturn",a),i.toast.success(s("import.items_added",{count:u.length})),d(!1)}catch{I(s("import.error"))}finally{z(null)}}};return(0,a.jsxs)(N.Dialog,{open:o,onOpenChange:d,children:[(0,a.jsx)(N.DialogTrigger,{asChild:!0,children:(0,a.jsxs)(v.Button,{type:"button",variant:"outline",size:"sm",children:[(0,a.jsx)(eg.A,{className:"mr-1.5 size-4"}
1),s("import_document")]})}),(0,a.jsxs)(N.DialogContent,{className:"sm:max-w-2xl",children:[(0,a.jsxs)(N.DialogHeader,{children:[(0,a.jsx)(N.DialogTitle,{children:(0,a.jsx)("h2",{className:"text-lg font-semibold",children:s("import.title")})}),(0,a.jsx)(N.DialogDescription,{children:(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:s("import.description")})})]}),(0,a.jsx)("div",{className:"grid grid-cols-3 gap-2 rounded-lg bg-muted p-1",children:F.map(e=>(0,a.jsx)(v.Button,{type:"button",variant:u===e.type?"default":"ghost",size:"sm",className:"w-full",onClick:()=>{var s;(s=e.type)!==u&&(m(s),p(""),b(""))},children:e.label},e.type))}),(0,a.jsxs)("div",{className:"relative",children:[(0,a.jsx)(ej.A,{className:"absolute left-3 top-1/2 z-20 -translate-y-1/2 text-muted-foreground"}),(0,a.jsx)(C.Input,{type:"text",placeholder:s("import.search_placeholder"),className:"w-full pl-10",value:x,onChange:e=>p(e.target.value)})]}),E?(0,a.jsxs)("div",{className:"flex h-80 flex-col items-center justify-center gap-4 text-muted-foreground",children:[(0,a.jsx)(ev.A,{}),(0,a.jsx)("p",{children:s("import.loading")})]}):(0,a.jsx)(eC.ScrollArea,{className:"h-80 rounded border p-4",children:g.length>0?(0,a.jsxs)(a.Fragment,{children:[g.map(e=>{let s=O===e.documentCode;return(0,a.jsxs)("div",{className:(0,L.cn)("flex cursor-pointer items-center space-x-4 rounded px-2 py-2 hover:bg-muted",s&&"pointer-events-none opacity-60"),onClick:()=>$(e),children:[s?(0,a.jsx)(h.A,{className:"text-primary"}):(0,a.jsx)(ey.A,{className:"text-muted-foreground"}),(0,a.jsxs)("div",{children:[(0,a.jsx)("p",{className:"font-medium",children:e.documentCode}),e.creationDate&&(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:(0,eb.GP)(new Date(e.creationDate),"dd/MM/yyyy HH:mm")})]})]},e.id||e.documentCode)}),y<w&&(0,a.jsx)("div",{className:"mt-2 flex justify-center",children:(0,a.jsx)(v.Button,{type:"button",variant:"ghost",size:"sm",disabled:_,onClick:()=>M(y+1,{append:!0}),children:_?(0,a.jsx)(ev.A,{size:16}):s("import.load_more")})})]}):(0,a.jsxs)("div",{className:"flex h-72 flex-col items-center justify-center text-muted-foreground",children:[(0,a.jsx)(eN.A,{className:"mb-2 h-12 w-12"}),(0,a.jsx)("p",{children:s("import.empty")})]})}),R&&(0,a.jsxs)("div",{className:"flex items-center gap-2 rounded-md bg-destructive/10 p-3 text-sm text-destructive",children:[(0,a.jsx)(eN.A,{className:"h-4 w-4 shrink-0"}),(0,a.jsx)("span",{children:R})]})]})]})};var e_=t(3770),eP=t(2467);function eR({rows:e,className:s}){let t=(0,T.c)("components.keyboard-legend"),l=[{combo:["Ctrl / ⌘","Enter"],label:t("totalize")},{combo:["↑","↓"],label:t("navigate")},{combo:["Enter"],label:t("select")},{combo:["Esc"],label:t("close")}];return(0,a.jsxs)(eu.AM,{children:[(0,a.jsx)(eu.Wv,{asChild:!0,children:(0,a.jsx)("button",{type:"button","aria-label":t("aria_label"),className:(0,L.cn)("flex size-9 items-center justify-center rounded-lg border text-muted-foreground transition hover:bg-muted hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",s),children:(0,a.jsx)(eP.A,{className:"size-4"})})}),(0,a.jsxs)(eu.hl,{align:"end",className:"w-64",children:[(0,a.jsxs)("p",{className:"mb-3 flex items-center gap-2 text-sm font-semibold",children:[(0,a.jsx)(eP.A,{className:"size-4 text-primary"}),t("title")]}),(0,a.jsx)("ul",{className:"space-y-2",children:(e||l).map((e,s)=>(0,a.jsxs)("li",{className:"flex items-center justify-between gap-3 text-sm",children:[(0,a.jsx)("span",{className:"text-muted-foreground",children:e.label}),(0,a.jsx)("span",{className:"flex shrink-0 items-center gap-1",children:e.combo.map((e,s)=>(0,a.jsx)("kbd",{className:"rounded border bg-muted px-1.5 py-0.5 text-[11px] font-medium text-foreground",children:e},s))})]},s))})]})]})}var eI=t(42176);let eO=(0,z.createServerReference)("40aec6d29ecea94447dcc021d3caa630e3d92967ba",z.callServer,void 0,z.findSourceMapURL,"getCustomerFinancialSummary");var ek=t(72925);let eL=({onSubmit:e=()=>{},formConfig:s})=>{let{control:t,handleSubmit:n,watch:i,register:c,formState:{isSubmitting:o}}=(0,r.xW)(),d=(0,T.c)(s?.i18nScope||"applications.sales.invoicing"),[u,x]=(0,l.useState)(!1),p=(0,l.useRef)(null),h=s?.compactOptions||{},b=[...(s?.body?.sections||[]).flatMap(e=>e.fields||[]),...(s?.sideSections||[]).flatMap(e=>
1e.fields||[]),...s?.header?.fields||[]].filter(Boolean),N=e=>b.find(s=>s.name===e),C=h.accountFieldName||"customerCode",A=N(C),w=N(h.detailsFieldName||"details"),D=N("isCreditSale"),S=h.leadField?N(h.leadField):null,P=!!D||!!h.showCredit,R=i(C),[O,k]=(0,l.useState)({addressText:"",availableCredit:null}),L=!1!==h.fetchAccountDetail;(0,l.useEffect)(()=>{let e=!0;return R&&L?((async()=>{try{let[t,a]=await Promise.all([(0,eI.r)(R),P?eO(R):Promise.resolve(null)]);if(!e)return;let l=t?.Data??null,r=l?.currencyCodeAllowedList??l?.CurrencyCodeAllowedList??[],n=(r?.[0]?.currencyCode??r?.[0]?.CurrencyCode)||s?.currency?.currencyCode,c=i("currencyCode");if(n&&n!==c&&"function"==typeof h?.onCustomerCurrency)return void h.onCustomerCurrency(R,n);let o=e=>{if(!e)return"";let s=e;if("string"==typeof e)try{s=JSON.parse(e)}catch{return""}if(Array.isArray(s)&&(s=s[0]),s&&"object"==typeof s&&s.value&&(s=s.value),!s||"object"!=typeof s)return"";let t=(e,t)=>s[e]??s[t];return[t("street","Street"),t("city","City"),t("state","State"),t("country","Country"),t("postalCode","PostalCode")].filter(e=>e&&String(e).trim()).join(", ")},d=o(l?.mainAddress??l?.MainAddress);if(!d)for(let e of l?.contactList??l?.ContactList??[]){for(let s of e?.addresses??e?.Addresses??[]){let e=o(s);if(e){d=e;break}}if(d)break}let u=a?.data??null,m=u?Number(u.AvailableCredit??u.availableCredit??0):null;k({addressText:d,availableCredit:m})}catch{e&&k({addressText:"",availableCredit:null})}})(),()=>{e=!1}):void k({addressText:"",availableCredit:null})},[R,P,L]);let z=h.readOnlyFields||["sellerID","expirationDate"],F={creation_date:{icon:(0,a.jsx)(J.A,{className:"size-4"}),iconClass:"text-info",bgClass:"bg-info-tint"},customerCode:{icon:(0,a.jsx)(Q.A,{className:"size-4"}),iconClass:"text-violet-500",bgClass:"bg-primary-100"},supplierCode:{icon:(0,a.jsx)(X.A,{className:"size-4"}),iconClass:"text-violet-500",bgClass:"bg-primary-100"},buyerCode:{icon:(0,a.jsx)(m.A,{className:"size-4"}),iconClass:"text-indigo-500",bgClass:"bg-primary-100"},detailsType:{icon:(0,a.jsx)(Z.A,{className:"size-4"}),iconClass:"text-info",bgClass:"bg-info-tint"},requester:{icon:(0,a.jsx)(m.A,{className:"size-4"}),iconClass:"text-teal-500",bgClass:"bg-success-tint"},locationCodeList:{icon:(0,a.jsx)(ee.A,{className:"size-4"}),iconClass:"text-destructive",bgClass:"bg-destructive-tint"},sellerID:{icon:(0,a.jsx)(Q.A,{className:"size-4"}),iconClass:"text-indigo-500",bgClass:"bg-primary-100"},locationCode:{icon:(0,a.jsx)(ee.A,{className:"size-4"}),iconClass:"text-destructive",bgClass:"bg-destructive-tint"},warehouseCode:{icon:(0,a.jsx)(I.A,{className:"size-4"}),iconClass:"text-warning",bgClass:"bg-warning-tint"},currencyCode:{icon:(0,a.jsx)(_.A,{className:"size-4"}),iconClass:"text-success",bgClass:"bg-success-tint"},expirationDate:{icon:(0,a.jsx)(es.A,{className:"size-4"}),iconClass:"text-warning",bgClass:"bg-warning-tint"},dueDate:{icon:(0,a.jsx)(es.A,{className:"size-4"}),iconClass:"text-warning",bgClass:"bg-warning-tint"},originWarehouseCode:{icon:(0,a.jsx)(et.A,{className:"size-4"}),iconClass:"text-warning",bgClass:"bg-warning-tint"},destinationWarehouseCode:{icon:(0,a.jsx)(et.A,{className:"size-4"}),iconClass:"text-info",bgClass:"bg-info-tint"},transportCode:{icon:(0,a.jsx)(ea.A,{className:"size-4"}),iconClass:"text-muted-foreground",bgClass:"bg-muted"},Location:{icon:(0,a.jsx)(ee.A,{className:"size-4"}),iconClass:"text-destructive",bgClass:"bg-destructive-tint"},LocationCode:{icon:(0,a.jsx)(ee.A,{className:"size-4"}),iconClass:"text-destructive",bgClass:"bg-destructive-tint"},OriginWarehouseCode:{icon:(0,a.jsx)(et.A,{className:"size-4"}),iconClass:"text-warning",bgClass:"bg-warning-tint"},DestinationWarehouseCode:{icon:(0,a.jsx)(et.A,{className:"size-4"}),iconClass:"text-info",bgClass:"bg-info-tint"},packerID:{icon:(0,a.jsx)(m.A,{className:"size-4"}),iconClass:"text-indigo-500",bgClass:"bg-primary-100"},pickerID:{icon:(0,a.jsx)(m.A,{className:"size-4"}),iconClass:"text-indigo-500",bgClass:"bg-primary-100"},carrier:{icon:(0,a.jsx)(ea.A,{className:"size-4"}),iconClass:"text-muted-foreground",bgClass:"bg-muted"},Status:{icon:(0,a.jsx)(el.A,{className:"size-4"}),iconClass:"text-violet-500",bgClass:"bg-primary-100"},Date:{icon:(0,a.jsx)(J.A,{className:"size-4"}),iconClass:"text-info",bgClass:"bg-info-tint"},scheduledDate:{icon:(0,a.jsx)(J.A,{className:"size-4"}),iconClass:"text-info",bgClass:"bg-info-tint"},shippingDate:{icon:(0,a.jsx)(J.A,{className:"size-4"}),iconClass:"text-info",bgClass:"bg-info-tint"},deliveryDate:{icon:(0,a.jsx)(es.A,{className:"size-4"}),iconClass:"text-warning",bgClass:"bg-warning-tint"},...Object.fromEntries(["code","Code","DocumentCode","packingCode","pickingCode","shippingOrderCode"].map(e=>[e,{icon:(0,a.jsx)(er.A,{className:"size-4"}),iconClass:"text-teal-500",bgClass:"bg-success-tint"}]))},M=h.chipOrder||["sellerID","locationCode","warehouseCode","currencyCode","expirationDate"],V=!!h.customerReadOnly,B=M.map(e=>
1N(e)).filter(Boolean).map(e=>({field:e,readOnly:V||z.includes(e.name)})),K=[].map(N).filter(Boolean),U=s?.usesPayment?.totalField||h.totalField||"total",Y=!1!==h.requiresAccount,G=!1!==h.requiresTotal,q=!!h.requiresDetails,W=q?i(w?.name):null,H=Array.isArray(W)&&W.some(e=>Array.isArray(e?.items)?e.items.length>0:Object.entries(e||{}).some(([e,s])=>"Code"!==e&&""!==s&&0!==s&&null!=s)),ec=o||G&&0>=i(U)||Y&&!R||q&&!H;(0,ek.A)("Enter",()=>{ec||(s?.usesPayment?x(!0):n(e)())});let{addressText:eo,availableCredit:ed}=O,eu="number"==typeof ed&&ed>0,ex=eo||null!==ed?(0,a.jsxs)("div",{className:"mt-1 flex flex-col gap-1",children:[eo&&(0,a.jsx)("p",{className:"truncate text-xs text-muted-foreground",children:eo}),null!==ed&&(0,a.jsx)("span",{className:`inline-flex w-fit items-center rounded-full px-2 py-0.5 text-[11px] font-medium ${eu?"bg-success-tint text-success":"bg-muted text-muted-foreground"}`,children:eu?d("compact.available_credit",{amount:`${s?.currency?.symbol||""} ${Number(ed??0).toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2})}`}):d("compact.no_credit_available")})]}):null;return(0,a.jsxs)(eE.A.Provider,{value:p,children:[s?.usesPayment&&u&&(0,a.jsx)($,{config:{open:u,setOpen:x,currency:s?.currency,currencies:s?.currencies,paymentMethods:s?.paymentMethods||[],total:+i(U),callbackUrl:s.successURL,submit:n(e),askCondition:P,availableCredit:O.availableCredit}}),(0,a.jsxs)("form",{onSubmit:n(e),className:"space-y-5",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between gap-3",children:[(0,a.jsxs)("div",{className:"flex items-center gap-3",children:[(0,a.jsx)("span",{className:"flex size-10 items-center justify-center rounded-xl bg-primary-100",children:(0,a.jsx)(f.A,{className:"size-5 text-primary"})}),(0,a.jsxs)("div",{className:"flex flex-col",children:[(0,a.jsx)("span",{className:"text-lg font-semibold leading-tight",children:s?.title||d("new_invoice")}),(0,a.jsx)("span",{className:"text-sm text-muted-foreground",children:d("compact.subtitle")})]})]}),(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[h.showImport&&(0,a.jsx)(eS,{i18nScope:s?.i18nScope}),(0,a.jsx)(eR,{})]})]}),S&&(0,a.jsx)("div",{className:"rounded-xl border bg-card p-4",children:(0,a.jsx)(g.A,{control:t,name:S.name,type:S.type,label:S.label,options:S.options,additionalProps:{...S.additionalProps,autoFocus:!0},additionalFields:S.additionalFields})}),(A||B.length>0)&&(0,a.jsxs)("div",{className:"rounded-xl border bg-card p-4",children:[A&&(0,a.jsxs)("div",{className:"mb-2 flex items-center justify-between gap-3",children:[(0,a.jsxs)("span",{className:"flex items-center gap-2 text-sm font-medium text-foreground",children:[(0,a.jsx)("span",{className:"size-2 rounded-full bg-primary"}),A.label||d("customer")]}),(0,a.jsxs)("span",{className:"inline-flex items-center gap-1.5 rounded-full bg-primary-100 px-3 py-1 text-xs font-medium text-primary",children:[(0,a.jsx)(en.A,{className:"size-3.5"}),d("compact.autoloaded_fiscal_data")]})]}),A&&!V&&(0,a.jsx)(r.xI,{control:t,name:A.name,render:({field:e})=>(0,a.jsx)(eh,{accounts:A.options?.accounts||[],accountConfig:A.options?.accountConfig||{},value:e.value,onChange:e.onChange,placeholder:A.options?.placeholder||d("select_customer"),emptyMessage:d("compact.not_set"),detailSlot:ex,autoFocus:!S})}),K.map(e=>(0,a.jsx)("input",{type:"hidden",...c(e.name)},e.name)),P&&(0,a.jsx)("input",{type:"hidden",...c("isCreditSale")}),(0,a.jsxs)("div",{className:`grid grid-cols-1 gap-3 sm:grid-cols-[repeat(auto-fit,minmax(190px,1fr))] ${A?"mt-4 border-t pt-4":""}`,children:[(0,a.jsxs)("div",{className:"flex items-start gap-2.5 rounded-xl border bg-card p-3",children:[(0,a.jsx)("span",{className:`mt-0.5 flex size-7 shrink-0 items-center justify-center rounded-lg ${F.creation_date.bgClass} ${F.creation_date.iconClass}`,children:F.creation_date.icon}),(0,a.jsxs)("div",{className:"flex min-w-0 flex-1 flex-col gap-0.5",children:[(0,a.jsx)("span",{className:"text-[11px] uppercase tracking-wide text-muted-foreground",children:d("creation_date")}),(0,a.jsx)("span",{className:"text-sm font-medium leading-snug text-foreground",children:new Date().toLocaleDateString()})]})]}),B.map(({field:e,readOnly:t})=>(0,a.jsx)(em,{field:e,accent:F[e.name],readOnly:t,i18nScope:s?.i18nScope},e.name))]})]}),D&&R&&(0,a.jsx)(e_.A,{options:{...D.options,showToggle:!1,availableCredit:O.availableCredit,invoiceTotal:Number(i(U))||0}}),w&&(0,a.jsx)("div",{children:(0,a.jsx)(g.A,{control:t,name:w.name,type:w.type,label:w.label,options:w.options,additionalProps:w.additionalProps,additionalFields:w.additionalFields})}),(0,a.jsx)(j.Separator,{className:"my-4"}),(0,a.jsxs)("div",{className:"flex flex-col gap-4 md:flex-row md:items-stretch",children:[(0,a.jsx)("div",{className:"flex-1 space-y-4",children:(0,a.jsx)(g.A,{control:t,name:s?.body?.observationKey||"observation",type:"textarea",options:{placeholder:d("observation")},additionalProps:{className:"min-h-[90px]"}})}),(0,a.jsxs)("div",{className:"flex w-full flex-col gap-3 md:w-72",children:[s?.resume&&s.calculateTotal&&(0,a.jsx)("div",{className:"rounded-xl border bg-primary-100/40 p-4",children:(0,a.jsx)(y,{formConfig:s})}),s?.usesPayment?(0,a.jsxs)(v.Button,{type:"button",size:"lg",className:"mt-auto w-full",onClick:()=>x(!0),disabled:ec,children:[o?(0,a.jsx)(E.A,{className:"mr-1.5 size-4 animate-spin"}):(0,a.jsx)(ei.A,{className:"mr-1.5 size-4"}),d("compact.issue_invoice")]}):(0,a.jsxs)(v.Button,{type:"button",size:"lg",className:"mt-auto w-full",onClick:()=>n(e)(),disabled:ec,children:[o?(0,a.jsx)(E.A,{className:"mr-1.5 size-4 animate-spin"}):(0,a.jsx)(ei.A,{className:"mr-1.5 size-4"}),h.actionLabelKey?d(h.actionLabelKey):s?.title||d("save")]})]})]})]})]})};var eT=t(65082),ez=t(89754),eF=t(54366),eM=t(29050);let eV=({formConfig:e,values:s,header:t})=>{let l=(0,c.Ym)(),r=(0,T.c)("components.summary-panel"),n=(0,eT.dv)(),i=(0,eM.f)(e,s,{t:r,locale:l,publishedLabels:n});return(0,a.jsx)(eF.A,{isEditing:e?.isEditing??!1,entity:e?.entity,changelog:e?.changelog??[],summary:{data:i,header:t}})};var e$=t(73321),eB=t(85218),eK=t(60841);let eU={identity:m.A,contact:x.A,financial:p.A,advanced:f.A},eY="border-b-0 rounded-2xl px-3 md:px-6",eG="w-full font-semibold justify-between flex -mx-3 px-3 md:-mx-6 md:px-6",eq=(e,s,t=!1,a=null,l=null)=>{if(l&&a?.has?.(String(l)))return a(String(l));let r=t?"An error occurred. Please try again later.":"Submitted successfully";return"object"==typeof e&&null!==e?e[s]||e.en||r:"string"==typeof e?e:r},eW=({formConfig:e,additionalData:s={},onFormReady:t})=>{let{title:m,type:x,onSubmit:p,successURL:f,defaultValues:j,validationSchemaName:y,validationContext:N,sections:v,customSaveButton:C,buttonLabel:A,hideButton:w,backURL:D,labelFunctions:E=null,availableLabels:S=null,labelKey:_=null,validationMessagesNamespace:P=null}=e,R=(0,T.c)("components.dynamic-form"),I=(0,T.c)(P||void 0),O=(0,l.useRef)(null),k=(0,e$.useRouter)(),z=(0,c.Ym)(),F=(0,T.c)("responses.codes"),[M,V]=(0,l.useState)(!1),$=void 0===e.defaultAccordionValue?[]:Array.isArray(e.defaultAccordionValue)?e.defaultAccordionValue[0]:e.defaultAccordionValue?[e.defaultAccordionValue]:[],[B,K]=(0,l.useState)($),U="document"===x,Y=((e,s)=>
1{let[t,a]=(0,l.useState)(null);return(0,l.useEffect)(()=>{let t=e&&b.Ay[e];t?a("function"==typeof t?t(s):t):a(null)},[e,s]),t})(y,I),G=(0,r.mN)({mode:"onChange",defaultValues:j||{},context:N,resolver:Y?(0,n.t)(Y):void 0});(0,eK.i)(G,e);let q=(0,l.useRef)(t);q.current=t,(0,l.useEffect)(()=>{q.current?.(G)},[G]);let W=(0,l.useRef)(void 0===j?"undefined":JSON.stringify(j)),{handleSubmit:J,control:Q,watch:X,formState:{errors:Z},reset:ee,getValues:es}=G;(0,l.useEffect)(()=>{let e=void 0===j?"undefined":JSON.stringify(j);if(e!==W.current){W.current=e;let s=es();ee({...j,posFinalName:s.posFinalName??j?.posFinalName??""},{keepDirty:!0,keepDirtyValues:!0,keepTouched:!0})}},[j]);let et=async s=>{let t=(0,L.Qe)(s);V(!0);try{let s=await p(t),a=s.response??s,l=a.error??a.Error,r=a.message??a.Message,n=a.code??a.Code;if(l)return void i.toast.error(eq(r,z,!0,F,n));if(i.toast.success(eq(r,z,!1,F,n)),"function"==typeof e?.onSuccess)try{let s=await e.onSuccess(a,t);if(!1===s)return}catch(e){console.error("onSuccess hook error",e)}e?.preventAutoRedirect||k.push(f??"/apps")}catch(e){console.error(e),i.toast.error("An error occurred. Please try again later.")}finally{V(!1)}},ea=e=>{let s=0;return Array.isArray(e)?e.forEach(e=>{s+=ea(e)}):"object"==typeof e&&null!==e&&!Array.isArray(e)&&Object.keys(e).length>0&&(s=e.message?1:Object.keys(e).length),s},el=e=>[...new Set(e?.fields?.map(e=>e?.name))].reduce((e,s)=>{let t;return e+ea((t=s?.replace(/\[(\d+)\]/g,".$1").split("."),t?.reduce((e,s)=>{if(null!==e&&"object"==typeof e)return e[s]},Z)))},0),er=()=>{let e=v?.find(e=>el(e)>0);e&&K(e.value)},en=e=>{if(!e.showIf)return!0;let{field:s,value:t,operator:a}=e.showIf;if(Array.isArray(s)){let e=s.map(e=>X(e));return"oneOfComposite"===a&&Array.isArray(t)&&t.some(s=>Array.isArray(s)&&s.length===e.length&&s.every((s,t)=>s===e[t]))}let l=X(s);return"notEmpty"===a?!!l&&""!==l:"oneOf"===a?Array.isArray(t)&&t.includes(l):l===t},ei=(v||[]).filter(e=>e.openOnShow&&en(e)).map(e=>
1e.value),ec=ei.join("|"),eo=(0,l.useRef)(ei);return(0,l.useEffect)(()=>{let e=ei.find(e=>!eo.current.includes(e));eo.current=ei,e&&K(e)},[ec]),(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(o.Ay,{subHeader:e?.layout==="compact"?null:m,className:(0,L.cn)({"w-full md:w-full":U&&!e?.renderResume}),backURL:D||null,isLoading:M,handleSubmit:J(et,er),buttonLabel:A||null,customSaveButton:C?(0,a.jsx)(u.A,{items:[[{icon:(0,a.jsx)(h.A,{className:"mr-2 h-4 w-4"}),label:"Save as pending",onClick:J(et,er)}]],buttonLabel:"Options",mainButton:{label:"Save",onClick:J(et,er)}}):null,hideButton:w||!1,labelFunctions:E,availableLabels:S,labels:X(_)??[],allowsCatalogue:!!E,labelFormValueName:_,setValue:G.setValue}),(0,a.jsxs)("div",{className:(0,L.cn)({[ez.X$]:!U,"w-full flex justify-center":U&&!e?.renderResume,"grid grid-cols-1 md:grid-cols-12 gap-4":U&&e?.renderResume}),children:[(0,a.jsx)(r.Op,{...G,children:(0,a.jsxs)(eT.zL,{children:[U&&e?.layout==="compact"?(0,a.jsx)("div",{className:"w-full md:col-span-10 lg:col-span-9 xl:col-span-8",children:(0,a.jsx)(eL,{formConfig:e,onSubmit:et})}):U?(0,a.jsx)("div",{className:"p-2 md:p-5 bg-white-base rounded-md w-full md:col-span-10 lg:col-span-9 xl:col-span-8 ",children:(0,a.jsx)(H,{formConfig:e,onSubmit:et})}):(0,a.jsx)("div",{className:(0,L.cn)("col-span-1",ez.G6),children:(0,a.jsx)(d.Accordion,{type:"single",collapsible:!0,value:B,onValueChange:K,children:(0,a.jsx)("form",{className:"space-y-2",onSubmit:J(et,er),children:v?.map(e=>{let t,l;if(!en(e))return null;let r=el(e);return(0,a.jsxs)(d.AccordionItem,{value:e.value,className:eY,children:[(0,a.jsxs)(d.AccordionTrigger,{className:eG,children:[(0,a.jsxs)("div",{className:"flex items-center gap-3 text-left",children:[(t=e.icon?eU[e.icon]:null)?(0,a.jsx)("span",{className:"flex size-10 shrink-0 items-center justify-center rounded-xl bg-primary-100 text-primary",children:(0,a.jsx)(t,{className:"size-5"})}):null,(0,a.jsxs)("div",{className:"flex flex-col",children:[e.title&&(0,a.jsx)("span",{className:"capitalize",children:e.title}),(l=e.counters?.length?e.counters.map(e=>{let s=X(e.path),t=Array.isArray(s)?s.length:+!!s;return`${t} ${e.unit}`}).join(" \xb7 "):e.subtitle)?(0,a.jsx)("span",{className:"text-xs font-normal text-muted-foreground",children:l}):null]})]}),r>0&&(0,a.jsx)(eB.E,{variant:"destructive",className:"ml-4 py-1 px-2 rounded-full text-xs",children:r})]}),(0,a.jsx)(d.AccordionContent,{className:(0,L.cn)("grid"===e.layout?"grid grid-cols-1 md:grid-cols-2 gap-x-4 gap-y-3":"space-y-2"),children:e.fields.map(t=>{if(t.showIf){let{field:e,value:s,operator:a,emptyValue:l}=t.showIf,r=!1;if(Array.isArray(e))"anyEquals"===a&&(r=e.some((e,t)=>X(e)===s[t]));else{let t=X(e);r="notEmpty"===a?t&&""!==t&&t!==l:t===s}if(!r)return null}let l=(0,a.jsx)(g.A,{control:Q,name:t.name,type:t.type,label:t.label,options:t.options,additionalProps:t.additionalProps,additionalFields:t.additionalFields,data:s,portalContainerRef:O},t.key??t.name);return"grid"===e.layout?(0,a.jsx)("div",{className:(0,L.cn)("full"===t.colSpan?"md:col-span-2":"md:col-span-1","file-input"===t.type&&"flex flex-col"),children:l},t.key??t.name):l})})]},e.value)})})})}),!U&&!0===e.renderResume&&(0,a.jsx)("div",{className:"col-span-1 space-y-4",children:(0,a.jsx)(eV,{formConfig:e,values:X(),header:R("summary")})})]})}),(0,a.jsx)("div",{ref:O})]})]})}}}]);

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.