1import{r as N,j as e}from"./vendor-react-0b52e17d.js";import{u as f,bv as Y,aN as y,H as Z}from"./vendor-misc-60f9a457.js";import{V as J}from"./VyPageLayout-15c807fc.js";import{bg as D,a9 as K,S as Q,aL as I,u as X,aj as ee}from"./app-core-d11f9ebf.js";import{cH as te,aS as W,g as b,dZ as S,d as v,q as se,ae as F,bs as re,s as w,$ as ie,p as ne}from"./vendor-vy-3b44047f.js";import{u as ae,e as oe,E as ce,a as le,C as de}from"./use-preview-currency-4052b1ee.js";import{a as P,C as xe,w as me}from"./CreateInvoiceForm-7289591b.js";import{u as G}from"./use-contracts-by-customer-id-f149ab4f.js";import{D as pe}from"./is-add-product-d5de001a.js";import{u as ue,f as he,E as ge,A as V,a as fe,b as L,F as je,C as Ce,c as ve}from"./AddIcon-b108927a.js";import{p as O,T as x,B as M,S as E,b0 as c,o as be,g as Se,i as Ie,b1 as ye,b2 as R,b3 as z,az as Ne,e as B,b4 as Ee,b5 as we,av as Pe}from"./vendor-mui-238acd1e.js";import{V as Oe,a6 as T,e as Ae}from"./vendor-vy-ds-885d80cb.js";import{u as Te}from"./use-customers-names-10c2875a.js";import{I as H}from"./invoice-due-date-consts-400d4187.js";import{V as A}from"./VyDatePicker-ffe76d24.js";import"./page-frame-cbbf18ba.js";import"./VyPageLayoutTabs-1805ce94.js";import"./VyTooltip-6bcb524b.js";import"./Price-1f7c2338.js";import"./VyTextareaField-fc08cf8e.js";import"./use-country-options-b4d34c7b.js";import"./VySwitchField-fe849c62.js";import"./VyBooleanCheckboxField-5aa5d605.js";import"./use-catalog-products-list-5f86cccb.js";import"./use-anrok-enabled-1433a0ef.js";import"./use-debounce-c674a381.js";import"./use-net-suite-products-b58d8bcf.js";import"./use-net-suite-classes-76255a9e.js";import"./use-integration-entities-d3c1a2c2.js";import"./UpsertCatalogProductsDialog-1690daaa.js";import"./NetSuiteProductsDropdown-ce46a9d2.js";import"./build-erp-entity-from-external-integration-03c34b8c.js";import"./use-subsidiary-name-map-b6683d64.js";import"./use-subsidiaries-9438a3e5.js";import"./reference-data-query-options-consts-5095626a.js";import"./use-formatted-xero-products-b9819930.js";import"./use-paddle-products-c939e580.js";import"./use-stripe-tax-enabled-ae951464.js";import"./use-integration-settings-1461d694.js";import"./use-account-7dbbc7a8.js";import"./VyNumberFieldField-8608cbd2.js";import"./VySelectField-5d1c450d.js";import"./use-meters-44d1580c.js";import"./ArrowIcon-0a7a632e.js";import"./use-toggle-b8bd28b6.js";import"./use-billing-engine-estimation-4177f73c.js";import"./ContractPhasesTimelineContainer-e72323f9.js";import"./VyTextFieldField-b4524273.js";import"./sizes-b8509740.js";import"./add-item-button-consts-47e5b6b0.js";import"./VyPaper-00f3d28d.js";import"./UpsertCreditTypeDialog-fd2bfe78.js";import"./VyDateField-e8ded6f2.js";import"./withPrefetch-fe90ea99.js";import"./use-menu-b2c157ac.js";import"./picker-value-utils-370a432f.js";(function(){try{var t=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{};t.SENTRY_RELEASE={id:"2cd2d3d210c4"};var s=new t.Error().stack;s&&(t._sentryDebugIds=t._sentryDebugIds||{},t._sentryDebugIds[s]="d8825a39-2936-4131-91a1-26cb06db01d5",t._sentryDebugIdIdentifier="sentry-dbid-d8825a39-2936-4131-91a1-26cb06db01d5")}catch{}})();const De=()=>{const{errorsFields:t,registerErrorCustomField:s,showErrorNotification:n,setShowErrorNotification:o}=D(),{formState:{errors:r}}=f(),i=ae(te(t,"fieldPath"),r),a=W(i)?i:oe(r);return N.useEffect(()=>{s("productsValidation")},[s]),e.jsx(ce,{open:n&&a.length>0,errors:a,description:"Find and fix the errors before saving the invoice",onClose:()=>o(!1)})},U=({onAddCreditClick:t})=>{const{setValue:s,getValues:n}=f(),{getFixedOneTimeProductConfiguration:o,getCommercialTermsProductConfiguration:r}=ue(),i=a=>()=>{const p=n("fixedProducts")??[],m=a(),u=[...p,m];s("fixedProducts",u)};return e.jsxs(e.Fragment,{children:[e.jsxs(O,{className:"flex flex-col items-start",onClick:i(o),...b(S.fixedChargesTab.oneTimeFeeOption),children:[e.jsx(x,{className:"text-sm font-normal text-black",children:"One-time fee"}),e.jsx(x,{className:"text-xs font-normal text-[#94A0A4]",children:"Single one time charge"})]}),e.jsxs(O,{className:"flex flex-col items-start",onClick:i(r),...b(S.fixedChargesTab.contractTermsOption),children:[e.jsx(x,{className:"text-sm font-normal text-black",children:"Contract terms"}),e.jsx(x,{className:"text-xs font-normal text-[#94A0A4]",children:"Contract commitment"})]}),v(t)&&e.jsxs(O,{className:"flex flex-col items-start",onClick:t,...b(S.fixedChargesTab.creditOption),children:[e.jsxs(M,{className:"flex items-center gap-x-1",children:[e.jsx(x,{className:"text-sm font-normal text-black",children:"Credit"}),e.jsx(M,{sx:{borderRadius:"4px",bgcolor:"#E7F2FF",color:"#0521FF",fontSize:"10px",fontWeight:600,lineHeight:1,padding:"2px 4px"},children:"New"})]}),e.jsx(x,{className:"text-xs font-normal text-[#94A0A4]",children:"Prepaid balance for future charges"})]})]})},Fe=({fixedProducts:t})=>{const{control:s,getValues:n,setValue:o}=f(),{isDialogOpen:r,handleOpen:i,handleClose:a}=K(),m=(Y({control:s,name:"credits"})??[]).map((C,h)=>he(C,h)),u=m.length>0,j=C=>{const h=F(n("credits"),[]);o("credits",[...h,ve(C)],{shouldDirty:!0})};return se(t)&&!u?e.jsxs("div",{className:"flex w-full flex-col gap-y-4",children:[e.jsx(ge,{title:"Create and add fixed fees",description:"Set up one-time fees, subscription charges or price per unit to tailor your pricing model.",children:e.jsx(V,{cta:e.jsxs("span",{className:"flex items-center gap-x-2",children:[e.jsx(fe,{}),e.jsx("span",{children:"Add fees"})]}),...b(S.fixedChargesTab.addFeesButton),children:e.jsx(U,{onAddCreditClick:i})})}),r&&e.jsx(L,{open:r,onClose:a,onAddCredit:j})]}):e.jsxs("div",{className:"flex w-full flex-col gap-y-4",children:[e.jsx("div",{className:"flex items-center justify-end",children:e.jsx(V,{color:"primary",...b(S.fixedChargesTab.addFeesButton),cta:e.jsxs("span",{className:"flex items-center gap-x-2",children:[e.jsx(Oe,{icon:"PlusMedium",style:{transform:"scale(0.8)"}}),e.jsx("span",{children:"Add item"})]}),anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},children:e.jsx(U,{onAddCreditClick:i})})}),W(t)&&e.jsxs(e.Fragment,{children:[e.jsx(x,{className:"text-base font-medium",children:"Service fees"}),e.jsx(N.Suspense,{fallback:e.jsx(Q,{size:75}),children:e.jsx(je,{fixedProducts:t,isInvoice:!0})})]}),u&&e.jsx(Ce,{rows:m}),r&&e.jsx(L,{open:r,onClose:a,onAddCredit:j})]})},_e=()=>{const{watch:t}=f();return e.jsx(E,{sx:{padding:2},children:e.jsx(Fe,{fixedProducts:[...F(t("fixedProducts"),[])]})})},ke=()=>{const{control:t}=f(),{data:s,isLoading:n}=Te(),o=F(s==null?void 0:s.customers,[]);return e.jsx(c,{children:e.jsx(y,{control:t,name:"settings.customerId",render:({field:r})=>e.jsx(T,{autoHighlight:!0,disableClearable:!0,inputSlotProps:{htmlInput:{autoComplete:"new-password"}},options:o,loading:n,getOptionLabel:i=>i.name,onChange:(i,a)=>
1{a&&r.onChange(a.id)},value:o.find(i=>i.id===r.value),...b(S.settings.customerSelect)})})})},Ve=()=>{const{control:t,register:s,setValue:n,watch:o}=f(),{registerErrorField:r}=D(),i=o("settings.customerId"),{data:a,isLoading:p}=G(i??"",void 0,{enabled:v(i),suspense:!1}),m=s("settings.startDate"),u=s("settings.endDate"),j=s("settings.issueDate"),C=s("settings.purchaseOrder"),h=s("settings.customerId");N.useEffect(()=>{r(h.name)},[r,h.name]);const $=l=>`Net ${l.toString()===H.EOM.toString()?"EoM":l}`,_=((a==null?void 0:a.contracts.filter(({status:l})=>l===re.Active))??[]).map(({id:l,plan:d})=>({label:d.name,value:l}));return e.jsxs("section",{className:"flex h-full flex-col p-6 gap-y-6 overflow-auto",children:[e.jsx(x,{variant:"h6",children:"Settings"}),e.jsx(E,{direction:"column",sx:{mb:"40px"},children:e.jsxs(E,{component:be,elevation:1,divider:e.jsx(Se,{}),sx:{rowGap:3,padding:3},children:[e.jsxs(c,{container:!0,sx:{alignItems:"center"},children:[e.jsx(c,{sx:{flex:1},children:e.jsx(x,{children:"Customer"})}),e.jsx(c,{size:3,children:e.jsx(N.Suspense,{fallback:e.jsx(Ie,{variant:"rectangular",height:40,sx:{borderRadius:"12px"}}),children:e.jsx(ke,{})})})]}),e.jsxs(c,{container:!0,sx:{alignItems:"center"},children:[e.jsx(c,{sx:{flex:1},children:e.jsx(x,{children:"Period"})}),e.jsxs(c,{container:!0,wrap:"nowrap",size:6,sx:{gap:1},children:[e.jsx(y,{name:m.name,render:({field:l})=>e.jsx(A,{label:"Start date",value:l.value,onChange:d=>{if(v(d)){const g=w(d).startOf("day").toDate();n(m.name,g.toISOString())}}})}),e.jsx(y,{name:u.name,render:({field:l})=>{const d=o(m.name),g=d?w(d):void 0;return e.jsx(A,{label:"End date",value:l.value,minDate:g,onChange:k=>{if(v(k)){const q=w(k).endOf("day").toDate();n(u.name,q.toISOString())}}})}})]})]}),e.jsxs(c,{container:!0,sx:{alignItems:"center"},children:[e.jsx(c,{sx:{flex:1},children:e.jsx(x,{children:"Issue date"})}),e.jsx(c,{size:3,children:e.jsx(y,{name:j.name,render:({field:l})=>e.jsx(A,{label:"Issue date",value:l.value,onChange:d=>{if(v(d)){const g=w(d).startOf("day").toDate();n(j.name,g.toISOString())}}})})})]}),e.jsxs(c,{container:!0,sx:{alignItems:"center"},children:[e.jsx(c,{sx:{flex:1},children:e.jsx(x,{children:"Due date"})}),e.jsx(c,{size:3,children:e.jsx(y,{control:t,name:"settings.paymentDueDays",render:({field:l})=>e.jsx(T,{autoHighlight:!0,disableClearable:!0,placeholder:"Select due date",inputSlotProps:{htmlInput:{autoComplete:"new-password"}},options:ie(H),getOptionLabel:$,onChange:(d,g)=>{l.onChange(g)}})})})]}),e.jsxs(c,{container:!0,sx:{alignItems:"center"},children:[e.jsx(c,{sx:{flex:1},children:e.jsx(x,{variant:"subtitle1",children:"PO. Number"})}),e.jsx(c,{size:3,children:e.jsx(Ae,{placeholder:"input text",...C})})]}),e.jsxs(c,{container:!0,sx:{alignItems:"center"},children:[e.jsx(c,{sx:{flex:1},children:e.jsx(x,{children:"Contract"})}),e.jsx(c,{size:3,children:e.jsx(y,{control:t,name:"settings.contractId",render:({field:l})=>e.jsx(T,{autoHighlight:!0,disableClearable:!0,placeholder:"Select contract",inputSlotProps:{htmlInput:{autoComplete:"new-password"}},options:_,loading:p,getOptionLabel:d=>d.label,onChange:(d,g)=>{v(g)&&l.onChange(g.value)},value:_.find(d=>d.value===l.value)})})})]})]})})]})},Le=()=>{const{invoiceCreationStepper:{currentStep:t,goToStep:s}}=P();return e.jsx(E,{sx:n=>({backgroundColor:n.palette.common.white,display:"flex",padding:"24px 0px 16px 0px",margin:"auto",maxWidth:"340px"}),children:e.jsxs(ye,{activeStep:t,children:[e.jsx(R,{className:"hover:cursor-pointer",onClick:()=>s(I.settings),sx:{"& .MuiStepIcon-root.Mui-active, & .MuiStepIcon-root.Mui-completed":{color:"primary.main"},"& .MuiStepLabel-label.Mui-active, & .MuiStepLabel-label.Mui-completed":{color:"text.primary",fontWeight:600}},children:e.jsx(z,{children:"Invoice details"})}),e.jsx(R,{children:e.jsx(z,{children:"Pricing options"})})]})})},Me={[I.settings]:e.jsx(Ve,{}),[I.content]:e.jsx(_e,{})},Re=()=>{const{invoiceCreationStepper:{currentStep:t},planPreview:{open:s,hide:n}}=P(),{watch:o}=f(),r=o("settings.customerId"),i=o("settings.contractId"),{data:a}=G(r??"",void 0,{enabled:v(r),suspense:!1}),p=a==null?void 0:a.contracts.find(u=>u.id===i),m=le(r,p==null?void 0:p.currencyOverride);return e.jsx(pe,{currency:m,children:e.jsxs("div",{className:"flex h-full w-full overflow-y-hidden",children:[e.jsxs(E,{sx:{height:"100%",flex:1},children:[e.jsx("div",{className:"w-full",children:e.jsx(Le,{})}),Me[t]]}),e.jsx(Ne,{in:s,orientation:"horizontal",sx:{height:"100%"},children:e.jsx(de,{title:"Preview",onHide:n})})]})})},ze={[I.settings]:"Save settings & continue",[I.content]:"Confirm & create invoice"},Be=()=>{const{invoiceCreationStepper:{currentStep:t,nextStep:s,onFinalStep:n,isFinalStep:o,goToStep:r}}=P(),{setShowErrorNotification:i}=D(),{trigger:a,reset:p}=f(),m=X();ne(n);const u=N.useCallback(async C=>{let h=!1;
1if(t===I.content?h=await a(["fixedProducts","usageProducts","productsValidation"]):t===I.settings&&(h=await a(["settings"])),!h){i(!0);return}return o?n():(C.preventDefault(),s())},[t,o,s,n,i,a]),j=N.useCallback(()=>{p(xe,{keepDefaultValues:!0}),r(0),m("/invoices/create")},[r,m,p]);return e.jsxs("div",{className:"flex justify-end gap-x-2 border-t border-t-[#DFEBF1] bg-white p-4",children:[e.jsx(B,{variant:"text",color:"primary",size:"large",disableElevation:!0,onClick:j,children:"Clear form"}),e.jsx(B,{variant:"contained",color:"primary",size:"medium",disableElevation:!0,onClick:u,type:"button",...b(S.continueButton),children:ze[t]})]})},He=()=>{const{planPreview:{open:t,hide:s,show:n}}=P(),o=(r,i)=>{i?n():s()};return e.jsxs(J,{showBackButton:!0,title:"Create invoice",sx:{padding:"0"},action:e.jsxs(Ee,{className:"flex flex-row items-center gap-x-2",children:[e.jsx(we,{htmlFor:"plan-preview-switch",children:e.jsx(x,{variant:"body1",sx:{color:"text.primary"},children:"See preview"})}),e.jsx(Pe,{id:"plan-preview-switch",checked:t,onChange:o})]}),children:[e.jsx(Z,{children:e.jsx("title",{children:"Create invoice"})}),e.jsx(ee,{children:e.jsxs("div",{className:"flex h-full flex-col",children:[e.jsx(Re,{}),e.jsx(Be,{}),e.jsx(De,{})]})})]})},$t=me(He);export{$t as CreateInvoicePage};
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.