@accounter/client 0.0.9-alpha-20251210021331-63c0e030ef47ee78435447a41a8ce6fd9f0fe241 → 0.0.9-alpha-20251210055345-8f85061e52de38780029792fc3a45da0360197df
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/dist/assets/{Checkbox-BHVKlxRj.js → Checkbox-DUyxts6I.js} +1 -1
- package/dist/assets/{MultiSelect-DY08OexD.js → MultiSelect-mJTNaBvj.js} +1 -1
- package/dist/assets/{Progress-CkBW27DM.js → Progress-CbEkKbvT.js} +1 -1
- package/dist/assets/{Table-bhKB4PFK.js → Table-BD-Y5pOR.js} +1 -1
- package/dist/assets/{Typography-DclIL89E.js → Typography-CdxJ9FGD.js} +1 -1
- package/dist/assets/{YearPickerInput-DgK0Ih6X.js → YearPickerInput-Bka3kNAU.js} +1 -1
- package/dist/assets/{accordion-CAxRDsFz.js → accordion-DQeKF8al.js} +1 -1
- package/dist/assets/{accountant-approvals-Dgsw0WDb.js → accountant-approvals-BxwZf4R5.js} +1 -1
- package/dist/assets/{accounter-table-DIm6Wedu.js → accounter-table-Brq5y129.js} +1 -1
- package/dist/assets/{addDays-CpwSVE6j.js → addDays-BKzA2JVL.js} +1 -1
- package/dist/assets/{all-charges-CS_0zCEZ.js → all-charges-zbnc8c0w.js} +1 -1
- package/dist/assets/{arrow-up-down-BCKzoFzo.js → arrow-up-down-BL4JClUu.js} +1 -1
- package/dist/assets/{building-2-Cp2Es1mt.js → building-2-Bg-rF-On.js} +1 -1
- package/dist/assets/{business-B1WVYc0i.js → business-DeIv5a1x.js} +2 -2
- package/dist/assets/{business-extended-info-NwMS1Rj6.js → business-extended-info-BzvYZDrX.js} +1 -1
- package/dist/assets/{business-header-D7w2Xzis.js → business-header-D4uSFuTz.js} +1 -1
- package/dist/assets/{business-ledger-filters-BBCKjVgu.js → business-ledger-filters-B_KOoEZi.js} +1 -1
- package/dist/assets/{business-ledger-single-CjmguyFq.js → business-ledger-single-BNRwnlGk.js} +1 -1
- package/dist/assets/{business-trip-BljjobKa.js → business-trip-Cmeyg86P.js} +1 -1
- package/dist/assets/charge-gtojshxD.js +1 -0
- package/dist/assets/{charges-filters-D_ruML4x.js → charges-filters-BTiGpLnh.js} +1 -1
- package/dist/assets/{charges-ledger-validation-RNuvPfFo.js → charges-ledger-validation-DPXMr9tU.js} +1 -1
- package/dist/assets/{charges-table-Dmz1Fxim.js → charges-table-DAgbJYqd.js} +1 -1
- package/dist/assets/{chart-MqLuc9m0.js → chart-BwU_CSjE.js} +1 -1
- package/dist/assets/{contracts-DCmvv-5I.js → contracts-uxjAMebQ.js} +1 -1
- package/dist/assets/{data-table-column-header-CT7O7uRT.js → data-table-column-header-C23SEs2k.js} +1 -1
- package/dist/assets/{data-table-pagination-Bn6-S7wX.js → data-table-pagination-BQNSZ2L6.js} +1 -1
- package/dist/assets/{deposits-transactions-table-BAObjoYX.js → deposits-transactions-table-DkCO1YMQ.js} +1 -1
- package/dist/assets/{download-csv-button-BsXK9P76.js → download-csv-button-DDfbg2Ju.js} +1 -1
- package/dist/assets/{edit-issue-document-modal-CG9FH4t_.js → edit-issue-document-modal-CoDIF8wL.js} +1 -1
- package/dist/assets/{editable-business-trip-CH61WHL7.js → editable-business-trip-DlCsUKF5.js} +1 -1
- package/dist/assets/{eye-off-Cc-ssiRk.js → eye-off-B09TfzwY.js} +1 -1
- package/dist/assets/{funnel-4UXATjU3.js → funnel-DyklXeNl.js} +1 -1
- package/dist/assets/{index-D8HuUMKu.js → index--iJB0sxH.js} +1 -1
- package/dist/assets/{index-YQXRLoVL.js → index-3QXfdVxu.js} +1 -1
- package/dist/assets/{index-CHtpNrAW.js → index-3R_zL83W.js} +4 -4
- package/dist/assets/{index-C9bDcLJk.js → index-8pKwHvS9.js} +1 -1
- package/dist/assets/{index-DYUcGCvp.js → index-B0G1u66z.js} +1 -1
- package/dist/assets/{index-BWtniMl1.js → index-BKPGYmU-.js} +1 -1
- package/dist/assets/{index-JJZ0k_k8.js → index-BSKBXgwE.js} +1 -1
- package/dist/assets/{index-SV9JUpu6.js → index-Bd97U3hC.js} +1 -1
- package/dist/assets/{index-CPuaqVQw.js → index-BfcmcL6K.js} +1 -1
- package/dist/assets/{index-xOkwbA9z.js → index-BjuUvxKm.js} +1 -1
- package/dist/assets/{index-CjcufnQY.js → index-C6Zrze8T.js} +1 -1
- package/dist/assets/{index-lpyXbMDd.js → index-CG9Rvi6d.js} +1 -1
- package/dist/assets/{index-qyF0HH0t.js → index-Cx6vlnNj.js} +1 -1
- package/dist/assets/{index-BNGi9a78.js → index-D0hgb0zb.js} +1 -1
- package/dist/assets/{index-BNMU0DUr.js → index-D9NtAUH-.js} +1 -1
- package/dist/assets/{index-BHTel4x6.js → index-D9hW-VSC.js} +1 -1
- package/dist/assets/{index-Cz49agDK.js → index-DccvyKKG.js} +1 -1
- package/dist/assets/{index-D42PKeAo.js → index-DdmQcg10.js} +1 -1
- package/dist/assets/{index-De4VpPkV.js → index-DgdaooUO.js} +1 -1
- package/dist/assets/{index-DPzHTlTo.js → index-DjVyUwTs.js} +1 -1
- package/dist/assets/{index-CFOw7tWS.js → index-GPz1OvDX.js} +1 -1
- package/dist/assets/{index-DVU7w2C4.js → index-NqZEUKdc.js} +1 -1
- package/dist/assets/{index-Cw81Wg3b.js → index-QibxRyXY.js} +1 -1
- package/dist/assets/{index-CFrclniY.js → index-Tfghmwvz.js} +1 -1
- package/dist/assets/{index-C3pJ0CeY.js → index-acshDJGW.js} +1 -1
- package/dist/assets/{index-DQsGXPYg.js → index-r6BRIiv_.js} +1 -1
- package/dist/assets/{index.es-DnF4r6Dk.js → index.es-DO643o1z.js} +1 -1
- package/dist/assets/{insert-business-trip-modal-CQv_ZpxL.js → insert-business-trip-modal-CQ2SX9SN.js} +1 -1
- package/dist/assets/issue-document-BQ0ogJOO.js +1 -0
- package/dist/assets/{list-plus-DsfXaxO5.js → list-plus-BYDB6Bug.js} +1 -1
- package/dist/assets/{login-page-DKeixPVN.js → login-page-CSAu4EPx.js} +1 -1
- package/dist/assets/{match-document-modal-LhAEyv1y.js → match-document-modal-CcYNlqoN.js} +1 -1
- package/dist/assets/{missing-info-charges-DCVKrfEr.js → missing-info-charges-BMG4Sqri.js} +1 -1
- package/dist/assets/{modal-YTgF-R03.js → modal-ZC7sNmLW.js} +1 -1
- package/dist/assets/{modify-contract-dialog-D7Z8bOws.js → modify-contract-dialog-Cx5gt7hE.js} +1 -1
- package/dist/assets/{page-layout-Cs7LzhPs.js → page-layout-CowMhn5y.js} +1 -1
- package/dist/assets/{page-not-found-Cs086tZP.js → page-not-found-DUGJ7yMm.js} +1 -1
- package/dist/assets/{panel-top-open-DfXV4xoB.js → panel-top-open-DNq_YeJ3.js} +1 -1
- package/dist/assets/{pencil-3H1z0dQ2.js → pencil-Bl19crq5.js} +1 -1
- package/dist/assets/{report-commentary-row-DNTsFgf_.js → report-commentary-row-DQCpV1AP.js} +1 -1
- package/dist/assets/{save-D2KnX2aJ.js → save-BKXGqFkY.js} +1 -1
- package/dist/assets/{similar-transactions-modal-DN6pAqBR.js → similar-transactions-modal-DTnZQkpm.js} +1 -1
- package/dist/assets/{sub-UiWBdxTZ.js → sub-BqAPBfvE.js} +1 -1
- package/dist/assets/subMonths-Cpq9u0d9.js +1 -0
- package/dist/assets/{summary-DLRjO19t.js → summary-dKO6hc4g.js} +1 -1
- package/dist/assets/{toggle-expansion-button-ByfnT_sn.js → toggle-expansion-button-C91T0tTd.js} +1 -1
- package/dist/assets/tooltip-h3zSyeCb.js +1 -0
- package/dist/assets/{use-url-query-DMunwqS4.js → use-url-query-Bdqm6AUY.js} +1 -1
- package/dist/index.html +1 -1
- package/package.json +1 -1
- package/src/components/business/admin/financial-account-section.tsx +2 -0
- package/src/components/financial-accounts/financial-account-card.tsx +4 -0
- package/src/components/financial-accounts/modify-financial-account-dialog.tsx +19 -0
- package/src/components/financial-accounts/types.ts +1 -0
- package/src/gql/gql.ts +3 -3
- package/src/gql/graphql.ts +5 -2
- package/dist/assets/charge-ChPubJah.js +0 -1
- package/dist/assets/issue-document-DJMGPj2s.js +0 -1
- package/dist/assets/subMonths-DZvdAXT7.js +0 -1
- package/dist/assets/tooltip-0-bix6mQ.js +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{v as ie,w as js,u as le,S as Hs,r as b,j as e,D as Ke,x as Ye,E as qs,c as gs,g as Be,t as K,i as Ee,U as Gs,y as Pe,z as Xe,G as we,H as be,J as Y,K as X,N as vs,O as Q,Q as J,V as Oe,W as Z,X as ce,Y as g,Z as v,_ as f,$ as y,I as A,a0 as T,a1 as C,a2 as Ce,B as S,a3 as ae,a4 as ne,a5 as Qe,a6 as Ws,a7 as ue,a8 as Je,a9 as Ze,aa as me,ab as V,ac as es,ad as Ks,ae as $,af as Ys,ag as te,ah as Xs,ai as pe,R as fs,aj as Qs,ak as Js,al as ys,am as Ns,an as bs,ao as Cs,ap as As,aq as ws,ar as Is,as as ks,at as re,au as Ds,av as Zs,aw as Ss,ax as ea,ay as Ts,az as $e,aA as sa,aB as aa,aC as ss,aD as na,P as ta,aE as ia,aF as U,aG as ns,aH as Le,aI as ra,aJ as ca,aK as la,aL as oa,aM as Bs,aN as da,aO as D,aP as ze,aQ as Es,aR as Ue,aS as ts,aT as ma,aU as ua,aV as Ps,aW as xa,aX as ha,aY as pa,aZ as de,a_ as ja,a$ as ga,b0 as va,b1 as He,b2 as fa,b3 as ya,b4 as Na,b5 as ba,b6 as Ca,b7 as is,b8 as Aa,b9 as wa,ba as Ia,bb as rs,bc as ka,bd as Da,be as Sa,bf as Ta,bg as Ba,F as Ea,bh as Pa,bi as Oa,bj as ee,bk as La,bl as Fa,bm as W,bn as _a,a as Ma,b as Ra,bo as Va}from"./index-CHtpNrAW.js";import{S as as}from"./save-D2KnX2aJ.js";import{B as De}from"./building-2-Cp2Es1mt.js";import{B as $a}from"./business-extended-info-NwMS1Rj6.js";import{B as za}from"./business-header-D7w2Xzis.js";import{S as Ua,C as Ha,L as qa,W as Ga}from"./charges-table-Dmz1Fxim.js";import{i as Wa,D as Ka,f as Ya,E as Xa,L as Fe,a as Ie,C as Qa,A as Ja,b as ve,c as Za,d as qe,h as en,e as sn,g as Os,u as an,G as nn,j as cs,k as tn,X as Ls,Y as Fs,l as rn,m as cn,R as ln,n as on,o as dn,p as mn}from"./chart-MqLuc9m0.js";import{M as un,s as xn,a as hn}from"./modify-contract-dialog-D7Z8bOws.js";import{P as pn}from"./pencil-3H1z0dQ2.js";import{E as jn,T as gn}from"./index-YQXRLoVL.js";import{A as vn,a as ke,b as _e,c as ls}from"./accordion-CAxRDsFz.js";import"./data-table-column-header-CT7O7uRT.js";import"./eye-off-Cc-ssiRk.js";import"./download-csv-button-BsXK9P76.js";import"./toggle-expansion-button-ByfnT_sn.js";import"./panel-top-open-DfXV4xoB.js";import"./Table-bhKB4PFK.js";import"./summary-DLRjO19t.js";import"./list-plus-DsfXaxO5.js";import"./deposits-transactions-table-BAObjoYX.js";import"./Checkbox-BHVKlxRj.js";import"./sequential-CAnleQny.js";import"./similar-transactions-modal-DN6pAqBR.js";import"./addDays-CpwSVE6j.js";import"./tooltip-0-bix6mQ.js";const fn=[["path",{d:"M3.85 8.62a4 4 0 0 1 4.78-4.77 4 4 0 0 1 6.74 0 4 4 0 0 1 4.78 4.78 4 4 0 0 1 0 6.74 4 4 0 0 1-4.77 4.78 4 4 0 0 1-6.75 0 4 4 0 0 1-4.78-4.77 4 4 0 0 1 0-6.76Z",key:"3c2336"}],["path",{d:"M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3",key:"1u773s"}],["line",{x1:"12",x2:"12.01",y1:"17",y2:"17",key:"io3f8k"}]],yn=ie("badge-question-mark",fn);const Nn=[["path",{d:"M11.767 19.089c4.924.868 6.14-6.025 1.216-6.894m-1.216 6.894L5.86 18.047m5.908 1.042-.347 1.97m1.563-8.864c4.924.869 6.14-6.025 1.215-6.893m-1.215 6.893-3.94-.694m5.155-6.2L8.29 4.26m5.908 1.042.348-1.97M7.48 20.364l3.126-17.727",key:"yr8idg"}]],bn=ie("bitcoin",Nn);const Cn=[["path",{d:"M3 3v16a2 2 0 0 0 2 2h16",key:"c24i48"}],["path",{d:"m19 9-5 5-4-4-3 3",key:"2osh9i"}]],An=ie("chart-line",Cn);const wn=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]],Me=ie("circle-check",wn);const In=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"9",x2:"15",y1:"15",y2:"9",key:"1dfufj"}]],os=ie("circle-slash",In);const kn=[["line",{x1:"12",x2:"12",y1:"2",y2:"22",key:"7eqyqh"}],["path",{d:"M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6",key:"1b0p4s"}]],Se=ie("dollar-sign",kn);const Dn=[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"m9 15 2 2 4-4",key:"1grp1n"}]],Sn=ie("file-check",Dn);const Tn=[["path",{d:"M3 7V5a2 2 0 0 1 2-2h2",key:"aa7l1z"}],["path",{d:"M17 3h2a2 2 0 0 1 2 2v2",key:"4qcy5o"}],["path",{d:"M21 17v2a2 2 0 0 1-2 2h-2",key:"6vwrx8"}],["path",{d:"M7 21H5a2 2 0 0 1-2-2v-2",key:"ioqczr"}],["rect",{width:"10",height:"8",x:"7",y:"8",rx:"1",key:"vys8me"}]],Bn=ie("fullscreen",Tn);const En=[["path",{d:"M2 6h4",key:"aawbzj"}],["path",{d:"M2 10h4",key:"l0bgd4"}],["path",{d:"M2 14h4",key:"1gsvsf"}],["path",{d:"M2 18h4",key:"1bu2t1"}],["rect",{width:"16",height:"20",x:"4",y:"2",rx:"2",key:"1nb95v"}],["path",{d:"M16 2v20",key:"rotuqe"}]],Pn=ie("notebook",En);const On=[["path",{d:"M12 22v-5",key:"1ega77"}],["path",{d:"M15 8V2",key:"18g5xt"}],["path",{d:"M17 8a1 1 0 0 1 1 1v4a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V9a1 1 0 0 1 1-1z",key:"1xoxul"}],["path",{d:"M9 8V2",key:"14iosj"}]],Ln=ie("plug",On);function Fn(s){return js(s,"yyyy-MM-dd")}function _n({businessId:s,tagIds:a,description:n,open:t,onOpenChange:l,onClose:o}){const[{data:r,fetching:i},h]=le({pause:!0,query:Hs,variables:{businessId:s,tagsDifferentThan:a?a.map(p=>p.id):void 0,descriptionDifferentThan:n}});b.useEffect(()=>{t&&(a||n)&&!r&&h()},[t,a,n,h,r]);const d=b.useCallback(p=>{l(p),t&&!p&&o?.()},[l,o,t]),m=b.useMemo(()=>t&&(!!a||!!n)&&r&&r?.similarChargesByBusiness.length>0,[t,a,n,r]);return e.jsx(Ke,{open:m,onOpenChange:d,children:e.jsx(Ye,{className:"overflow-scroll max-h-screen w-full sm:max-w-[640px] md:max-w-[768px] lg:max-w-[900px]",onClick:p=>p.stopPropagation(),children:e.jsx(qs,{fallback:e.jsx("div",{children:"Error fetching similar charges"}),children:i?e.jsx(gs,{}):a||n?e.jsx(Ua,{data:r?.similarChargesByBusiness??[],tagIds:a,description:n,onOpenChange:d,title:"Similar Charges by Business"}):null})})})}const Mn="updateAdminBusiness",Rn=()=>{const[{fetching:s},a]=Be(Gs),n=b.useCallback(async t=>{const l=`Error updating admin business ID [${t.adminBusinessId}]`,o=`${Mn}-${t.adminBusinessId}`;K.loading("Updating admin business",{id:o});try{const r=await a(t),i=Ee(r,l,o,"updateAdminBusiness");if(i)return K.success("Success",{id:o,description:"Admin Business Updated"}),i.updateAdminBusiness}catch(r){console.error(`${l}: ${r}`),K.error("Error",{id:o,description:l,duration:1e5,closeButton:!0})}},[a]);return{fetching:s,updateAdminBusiness:n}},Re=ue({year:es().min(2e3).max(2100),id:V().min(1,{message:"ID is required"})}),Vn=ue({registrationDate:V().min(1,{message:"Business Registration Start Date is required"}),withholdingTaxAnnualIds:me(Re),withholdingTaxCompanyId:V().min(1,{message:"Withholding Tax Company ID is required"}),socialSecurityEmployerIds:me(Re),socialSecurityDeductionsId:V().min(1,{message:"Social Security Deductions ID is required"}),taxAdvancesAnnualIds:me(Re),taxAdvancesRates:me(ue({date:Ks(),rate:es().min(0,{message:"Rate must be at least 0"}).max(100,{message:"Rate must be at most 100"})}))}),fe={WITHHOLDING_TAX:"https://secapp.taxes.gov.il/NikPay/StartPage.aspx#/Home",TAX_ADVANCES:"https://secapp.taxes.gov.il/gmftashmh/main/entrance",SOCIAL_SECURITY:"https://b2b.btl.gov.il/BTL.ILG.Payments/ChovDochMaasikInfo.aspx",VAT:"https://secapp.taxes.gov.il/emdvhmfrt/wLogOnMenu.aspx"},ye=({href:s,children:a})=>e.jsxs("h3",{className:"flex flex-row gap-2 text-sm font-semibold text-foreground md:col-span-2",children:[e.jsx("a",{href:s,target:"_blank",rel:"noreferrer",onClick:n=>n.stopPropagation(),className:"inline-flex items-center font-semibold",children:e.jsx(Je,{size:12})}),e.jsx("span",{children:a})]});function ds(s){return!s||s.__typename!=="LtdFinancialEntity"||!s.adminInfo?{}:{registrationDate:s.adminInfo.registrationDate,withholdingTaxAnnualIds:s.adminInfo.withholdingTaxAnnualIds.sort((a,n)=>n.year-a.year),withholdingTaxCompanyId:s.adminInfo.withholdingTaxCompanyId??void 0,socialSecurityEmployerIds:s.adminInfo.socialSecurityEmployerIds.sort((a,n)=>n.year-a.year),socialSecurityDeductionsId:s.adminInfo.socialSecurityDeductionsId??void 0,taxAdvancesAnnualIds:s.adminInfo.taxAdvancesAnnualIds.sort((a,n)=>n.year-a.year),taxAdvancesRates:s.adminInfo.taxAdvancesRates?.map(a=>({date:a.date,rate:a.rate*100}))}}function $n(s){return{registrationDate:s.registrationDate?Fn(new Date(s.registrationDate)):void 0,withholdingTaxAnnualIds:s.withholdingTaxAnnualIds,withholdingTaxCompanyId:s.withholdingTaxCompanyId,socialSecurityEmployerIds:s.socialSecurityEmployerIds,taxAdvancesRates:s.taxAdvancesRates?.map(a=>({date:a.date,rate:a.rate/100})),taxAdvancesAnnualIds:s.taxAdvancesAnnualIds}}function zn({data:s,refetchBusiness:a}){const n=we(Ws,s),[t,l]=b.useState(ds(n)),{updateAdminBusiness:o,fetching:r}=Rn(),i=Pe({resolver:Xe(Vn),defaultValues:t}),h=async k=>{if(!n)return;const x=Ze(k,i.formState.dirtyFields);if(!x)return;const N=$n(x);await o({adminBusinessId:n.id,fields:N}),a?.()};b.useEffect(()=>{if(n){const k=ds(n);l(k),i.reset(k)}},[n,i]);const{fields:d,append:m,remove:p}=be({control:i.control,name:"taxAdvancesAnnualIds"}),{fields:u,append:j,remove:w}=be({control:i.control,name:"withholdingTaxAnnualIds"}),{fields:I,append:B,remove:F}=be({control:i.control,name:"socialSecurityEmployerIds"}),P={withholdingTaxAnnualIds:{append:j,remove:w},taxAdvancesAnnualIds:{append:m,remove:p},socialSecurityEmployerIds:{append:B,remove:F}},M=k=>{P[k].append({year:new Date().getFullYear(),id:""})},z=(k,x)=>{P[k].remove(x)},{fields:_,append:G,remove:c}=be({control:i.control,name:"taxAdvancesRates"}),O=()=>{G({date:js(new Date,"yyyy-MM-dd"),rate:0})},R=k=>{c(k)};return e.jsxs(Y,{children:[e.jsxs(X,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(vs,{className:"h-5 w-5 text-primary"}),e.jsx(Q,{children:"Admin Business Configuration"})]}),e.jsx(J,{children:"Tax and registration information for the business operating this application"})]}),e.jsx(Oe,{...i,children:e.jsxs("form",{onSubmit:i.handleSubmit(h),className:"space-y-6",children:[e.jsx(Z,{children:e.jsxs("div",{className:"grid gap-6 md:grid-cols-2",children:[e.jsx(ye,{href:fe.VAT,children:"VAT"}),e.jsx(ce,{className:"md:col-span-2"}),e.jsx(ye,{href:fe.TAX_ADVANCES,children:"Tax Advances"}),e.jsx(ce,{className:"md:col-span-2"}),e.jsx(ye,{href:fe.WITHHOLDING_TAX,children:"Withholding Tax"}),e.jsx(g,{control:i.control,name:"withholdingTaxCompanyId",render:({field:k,fieldState:x})=>e.jsxs(v,{children:[e.jsx(f,{children:"Company Tax ID"}),e.jsx(y,{children:e.jsx(A,{placeholder:"Enter company ID",...k,className:T(x)})}),e.jsx(C,{})]})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(Ce,{children:"Annual IDs"}),e.jsx(S,{type:"button",variant:"outline",size:"sm",onClick:()=>M("withholdingTaxAnnualIds"),children:e.jsx(ae,{className:"size-4"})})]}),e.jsx("div",{className:"space-y-3",children:u.map((k,x)=>e.jsxs("div",{className:"flex gap-2 items-start",children:[e.jsxs("div",{className:"flex-1 grid grid-cols-2 gap-2",children:[e.jsx(A,{placeholder:"Year",type:"number",...i.register(`withholdingTaxAnnualIds.${x}.year`,{valueAsNumber:!0})}),e.jsx(A,{placeholder:"ID",...i.register(`withholdingTaxAnnualIds.${x}.id`)})]}),e.jsx(S,{type:"button",variant:"ghost",size:"icon",onClick:()=>z("withholdingTaxAnnualIds",x),children:e.jsx(ne,{className:"size-4"})})]},k.id))})]}),e.jsx(ce,{className:"md:col-span-2"}),e.jsx(ye,{href:fe.TAX_ADVANCES,children:"Tax Advances"}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(Ce,{children:"Annual IDs"}),e.jsx(S,{type:"button",variant:"outline",size:"sm",onClick:()=>M("taxAdvancesAnnualIds"),children:e.jsx(ae,{className:"size-4"})})]}),e.jsx("div",{className:"space-y-3",children:d.map((k,x)=>e.jsxs("div",{className:"flex gap-2 items-start",children:[e.jsxs("div",{className:"flex-1 grid grid-cols-2 gap-2",children:[e.jsx(A,{placeholder:"Year",type:"number",...i.register(`taxAdvancesAnnualIds.${x}.year`,{valueAsNumber:!0})}),e.jsx(A,{placeholder:"ID",...i.register(`taxAdvancesAnnualIds.${x}.id`)})]}),e.jsx(S,{type:"button",variant:"ghost",size:"icon",onClick:()=>z("taxAdvancesAnnualIds",x),children:e.jsx(ne,{className:"size-4"})})]},k.id))})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(Ce,{children:"Rates (%)"}),e.jsx(S,{type:"button",variant:"outline",size:"sm",onClick:O,children:e.jsx(ae,{className:"size-4"})})]}),e.jsx("div",{className:"space-y-3",children:_.map((k,x)=>e.jsxs("div",{className:"flex gap-2 items-start",children:[e.jsxs("div",{className:"flex-1 grid grid-cols-2 gap-2",children:[e.jsx(A,{placeholder:"Date",type:"date",...i.register(`taxAdvancesRates.${x}.date`)}),e.jsx(A,{placeholder:"Rate",...i.register(`taxAdvancesRates.${x}.rate`,{valueAsNumber:!0})})]}),e.jsx(S,{type:"button",variant:"ghost",size:"icon",onClick:()=>R(x),children:e.jsx(ne,{className:"size-4"})})]},k.id))})]}),e.jsx(ce,{className:"md:col-span-2"}),e.jsx(ye,{href:fe.SOCIAL_SECURITY,children:"Social Security"}),e.jsx(g,{control:i.control,name:"socialSecurityDeductionsId",render:({field:k,fieldState:x})=>e.jsxs(v,{children:[e.jsx(f,{children:"Deductions ID"}),e.jsx(y,{children:e.jsx(A,{placeholder:"Enter deductions ID",...k,className:T(x)})}),e.jsx(C,{})]})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(Ce,{children:"Annual Employer IDs"}),e.jsx(S,{type:"button",variant:"outline",size:"sm",onClick:()=>M("socialSecurityEmployerIds"),children:e.jsx(ae,{className:"size-4"})})]}),e.jsx("div",{className:"space-y-3",children:I.map((k,x)=>e.jsxs("div",{className:"flex gap-2 items-start",children:[e.jsxs("div",{className:"flex-1 grid grid-cols-2 gap-2",children:[e.jsx(A,{placeholder:"Year",type:"number",...i.register(`socialSecurityEmployerIds.${x}.year`,{valueAsNumber:!0})}),e.jsx(A,{placeholder:"ID",...i.register(`socialSecurityEmployerIds.${x}.id`)})]}),e.jsx(S,{type:"button",variant:"ghost",size:"icon",onClick:()=>z("socialSecurityEmployerIds",x),children:e.jsx(ne,{className:"size-4"})})]},k.id))})]}),e.jsx(ce,{className:"md:col-span-2"}),e.jsx(g,{control:i.control,name:"registrationDate",render:({field:k,fieldState:x})=>e.jsxs(v,{children:[e.jsx(f,{children:"Business Registration Start Date"}),e.jsx(y,{children:e.jsx(A,{type:"date",...k,className:T(x)})}),e.jsx(C,{})]})})]})}),e.jsx(Qe,{className:"flex justify-end border-t mt-4 pt-6",children:e.jsxs(S,{type:"submit",disabled:r||Object.keys(i.formState.dirtyFields).length===0||!i.formState.isValid,children:[e.jsx(as,{className:"h-4 w-4"}),"Save Changes"]})})]})})]})}const Un=s=>{switch(s){case $.BankAccount:return e.jsx(De,{className:"h-5 w-5"});case $.CreditCard:return e.jsx(Ys,{className:"h-5 w-5"});case $.CryptoWallet:return e.jsx(bn,{className:"h-5 w-5"});case $.BankDepositAccount:return e.jsx(De,{className:"h-5 w-5"});case $.ForeignSecurities:return e.jsx(De,{className:"h-5 w-5"});default:return e.jsx(yn,{className:"h-5 w-5"})}},_s=s=>{switch(s){case $.BankAccount:return"Bank Account";case $.CreditCard:return"Credit Card";case $.CryptoWallet:return"Crypto Wallet";case $.BankDepositAccount:return"Bank Deposit Account";case $.ForeignSecurities:return"Foreign Securities";default:return"Unknown Account Type"}};function Hn({account:s,handleOpenModal:a}){return e.jsxs(Y,{children:[e.jsx(X,{children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10 text-primary",children:Un(s.type)}),e.jsxs("div",{children:[e.jsxs(Q,{className:"text-lg",children:[s.name,s.name===s.number?"":` (${s.number})`]}),e.jsxs(J,{className:"flex items-center gap-2 mt-1",children:[e.jsx(te,{variant:"outline",children:_s(s.type)}),!s.isBusiness&&e.jsx(te,{variant:"secondary",children:"Private"})]})]})]}),e.jsx("div",{className:"flex gap-1",children:e.jsx(S,{variant:"ghost",size:"sm",onClick:()=>a(s),"aria-label":`Edit account ${s.name}`,children:e.jsx(Xs,{className:"h-4 w-4","aria-hidden":"true"})})})]})}),e.jsxs(Z,{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium mb-2",children:"Currencies & Tax Categories"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:s.currencies?.map(n=>e.jsx(pe,{to:fs.TAX_CATEGORIES,target:"_blank",rel:"noreferrer",onClick:t=>t.stopPropagation(),children:e.jsxs(te,{variant:"secondary",className:"text-xs",children:[n.currency," → ",n.taxCategory.name]})},n.currency))})]}),s.type===$.BankAccount&&e.jsxs("div",{className:"border-t pt-4",children:[e.jsx("h4",{className:"text-sm font-medium mb-3",children:"Bank Details"}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-3 text-sm",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"Bank Number:"}),e.jsx("p",{className:"font-medium",children:s.bankNumber})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"Branch Number:"}),e.jsx("p",{className:"font-medium",children:s.branchNumber})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"Extended Bank Number:"}),e.jsx("p",{className:"font-medium",children:s.extendedBankNumber})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"Party Preferred Indication:"}),e.jsx("p",{className:"font-medium",children:s.partyPreferredIndication})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"Party Account Involvement:"}),e.jsx("p",{className:"font-medium",children:s.partyAccountInvolvementCode})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"Account Deal Date:"}),e.jsx("p",{className:"font-medium",children:s.accountDealDate})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"Account Update Date:"}),e.jsx("p",{className:"font-medium",children:s.accountUpdateDate})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"Meteg Dora Net:"}),e.jsx("p",{className:"font-medium",children:s.metegDoarNet})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"Kod Harshaot Peilut:"}),e.jsx("p",{className:"font-medium",children:s.kodHarshaatPeilut})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"Closing Reason Code:"}),e.jsx("p",{className:"font-medium",children:s.accountClosingReasonCode})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"Agreement Opening Date:"}),e.jsx("p",{className:"font-medium",children:s.accountAgreementOpeningDate})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"Branch Type Code:"}),e.jsx("p",{className:"font-medium",children:s.branchTypeCode})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"Mymail Entitlement:"}),e.jsx("p",{className:"font-medium",children:s.mymailEntitlementSwitch})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"Service Authorization:"}),e.jsx("p",{className:"font-medium",children:s.serviceAuthorizationDesc})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"Product Label:"}),e.jsx("p",{className:"font-medium",children:s.productLabel})]})]})]})]})]})}const qn="createFinancialAccount",Gn=()=>{const[{fetching:s},a]=Be(Qs),n=b.useCallback(async t=>{const l=`Error creating new account "${t.input.name}"`,o=`${qn}-${t.input.name}`;K.loading("Creating account",{id:o});try{const r=await a(t);Ee(r,l,o)&&K.success("Success",{id:o,description:`Financial Account ${t.input.name} was successfully created`})}catch(r){console.error(`${l}: ${r}`),K.error("Error",{id:o,description:l,duration:1e5,closeButton:!0})}},[a]);return{creating:s,createFinancialAccount:n}},Wn="updateFinancialAccount",Kn=()=>{const[{fetching:s},a]=Be(Js),n=b.useCallback(async t=>{const l=`Error updating financial account ID [${t.financialAccountId}]`,o=`${Wn}-${t.financialAccountId}`;K.loading("Updating financial account",{id:o});try{const r=await a(t),i=Ee(r,l,o,"updateFinancialAccount");if(i)return K.success("Success",{id:o,description:"Financial account updated"}),i.updateFinancialAccount}catch(r){console.error(`${l}: ${r}`),K.error("Error",{id:o,description:l,duration:1e5,closeButton:!0})}},[a]);return{updating:s,updateFinancialAccount:n}},Yn=ue({currency:Ss(Object.values(Ts),"Currency is required"),taxCategory:ue({id:sa("Tax category ID is required"),name:V().min(1,"Tax category name is required")})}),H=Zs(s=>{if(s===""||s===void 0||s===null)return;const a=typeof s=="string"?parseInt(s,10):s;return Number.isNaN(a)?void 0:a},es().int().optional()),Xn=ue({name:V().min(1,"Name is required"),number:V().min(1,"Account number is required"),isBusiness:ea().default(!1).optional(),type:Ss(Object.values($),"Account type is required"),currencies:me(Yn),bankNumber:H,branchNumber:H,extendedBankNumber:H,partyPreferredIndication:H,partyAccountInvolvementCode:H,accountDealDate:H,accountUpdateDate:H,metegDoarNet:H,kodHarshaatPeilut:H,accountClosingReasonCode:H,accountAgreementOpeningDate:H,serviceAuthorizationDesc:V().optional(),branchTypeCode:H,mymailEntitlementSwitch:H,productLabel:V().optional()}),Qn=b.forwardRef(function({ownerId:a,onDone:n},t){const[l,o]=b.useState(!1),[r,i]=b.useState(null),{createFinancialAccount:h,creating:d}=Gn(),{updateFinancialAccount:m,updating:p}=Kn(),u=Pe({resolver:Xe(Xn),defaultValues:{name:"",number:"",isBusiness:!1,type:$.BankAccount,currencies:[],bankNumber:void 0,branchNumber:void 0,extendedBankNumber:void 0,partyPreferredIndication:void 0,partyAccountInvolvementCode:void 0,accountDealDate:void 0,accountUpdateDate:void 0,metegDoarNet:void 0,kodHarshaatPeilut:void 0,accountClosingReasonCode:void 0,accountAgreementOpeningDate:void 0,serviceAuthorizationDesc:void 0,branchTypeCode:void 0,mymailEntitlementSwitch:void 0,productLabel:void 0},mode:"onBlur"}),{control:j,handleSubmit:w,watch:I,reset:B}=u,F=c=>{c?(i(c),B(c)):(i(null),B()),o(!0)};b.useImperativeHandle(t,()=>({open:F}));const P=be({control:j,name:"currencies"}),M=()=>{o(!1),i(null),B()},z=async c=>{try{const O=c.isBusiness?$e.Business:$e.Private,R=c.type===$.BankAccount&&c.bankNumber!==void 0&&c.branchNumber!==void 0?{bankNumber:c.bankNumber,branchNumber:c.branchNumber,...c.extendedBankNumber!==void 0&&{extendedBankNumber:c.extendedBankNumber},...c.partyPreferredIndication!==void 0&&{partyPreferredIndication:c.partyPreferredIndication},...c.partyAccountInvolvementCode!==void 0&&{partyAccountInvolvementCode:c.partyAccountInvolvementCode},...c.accountDealDate!==void 0&&{accountDealDate:c.accountDealDate},...c.accountUpdateDate!==void 0&&{accountUpdateDate:c.accountUpdateDate},...c.metegDoarNet!==void 0&&{metegDoarNet:c.metegDoarNet},...c.kodHarshaatPeilut!==void 0&&{kodHarshaatPeilut:c.kodHarshaatPeilut},...c.accountClosingReasonCode!==void 0&&{accountClosingReasonCode:c.accountClosingReasonCode},...c.accountAgreementOpeningDate!==void 0&&{accountAgreementOpeningDate:c.accountAgreementOpeningDate},...c.serviceAuthorizationDesc!==void 0&&{serviceAuthorizationDesc:c.serviceAuthorizationDesc},...c.branchTypeCode!==void 0&&{branchTypeCode:c.branchTypeCode},...c.mymailEntitlementSwitch!==void 0&&{mymailEntitlementSwitch:c.mymailEntitlementSwitch},...c.productLabel!==void 0&&{productLabel:c.productLabel}}:void 0;r?await m({financialAccountId:r.id,fields:{name:c.name,number:c.number,type:c.type,privateOrBusiness:O,bankAccountDetails:R}}):await h({input:{name:c.name,number:c.number,ownerId:a,type:c.type,privateOrBusiness:O,bankAccountDetails:R}}),M(),n?.()}catch{}},_=()=>{P.append({currency:Ts.Usd,taxCategory:{id:"",name:""}})},G=c=>{P.remove(c)};return e.jsx(Ke,{open:l,onOpenChange:o,children:e.jsxs(Ye,{className:"max-w-4xl max-h-[90vh] overflow-y-auto",children:[e.jsxs(ys,{children:[e.jsx(Ns,{children:r?"Edit Account":"New Account"}),e.jsx(bs,{children:r?"Update account details and settings":"Add a new financial account"})]}),e.jsx(Oe,{...u,children:e.jsxs("form",{onSubmit:w(z),className:"space-y-6",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-sm font-semibold",children:"Basic Information"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx(g,{control:j,name:"name",render:({field:c})=>e.jsxs(v,{className:"space-y-2",children:[e.jsx(f,{children:"Name *"}),e.jsx(y,{children:e.jsx(A,{...c})}),e.jsx(C,{})]})}),e.jsx(g,{control:j,name:"number",render:({field:c})=>e.jsxs(v,{className:"space-y-2",children:[e.jsx(f,{children:"Account Number *"}),e.jsx(y,{children:e.jsx(A,{...c})}),e.jsx(C,{})]})}),e.jsx(g,{control:j,name:"type",render:({field:c})=>e.jsxs(v,{className:"space-y-2",children:[e.jsx(f,{children:"Account Type *"}),e.jsxs(Cs,{value:c.value,onValueChange:c.onChange,children:[e.jsx(As,{id:"type",children:e.jsx(ws,{})}),e.jsx(Is,{children:Object.values($).map(O=>e.jsx(ks,{value:O,children:_s(O)},O))})]}),e.jsx(C,{})]})}),e.jsx(g,{control:j,name:"isBusiness",render:({field:c})=>e.jsxs(v,{className:"flex items-center space-x-2",children:[e.jsx(y,{children:e.jsx(re,{id:"isBusiness",checked:c.value,onCheckedChange:c.onChange})}),e.jsx(f,{children:"Business Account"})]})})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-sm font-semibold",children:"Currencies & Tax Categories"}),e.jsxs(S,{type:"button",variant:"outline",size:"sm",onClick:_,"aria-label":"Add currency row",children:[e.jsx(ae,{className:"h-4 w-4 mr-2","aria-hidden":"true"}),"Add Currency"]})]}),e.jsx("div",{className:"space-y-3",children:P.fields.map((c,O)=>e.jsxs("div",{className:"flex gap-2 items-start",children:[e.jsxs("div",{className:"flex-1 grid grid-cols-2 gap-2",children:[e.jsx(g,{control:j,name:`currencies.${O}.currency`,render:({field:R})=>e.jsxs(v,{children:[e.jsx(y,{children:e.jsx(A,{placeholder:"Currency (e.g., ILS, USD)",...R})}),e.jsx(C,{})]})}),e.jsx(g,{control:j,name:`currencies.${O}.taxCategory.id`,render:({field:R})=>e.jsxs(v,{children:[e.jsx(y,{children:e.jsx(A,{placeholder:"Tax Category ID",...R})}),e.jsx(C,{})]})})]}),e.jsx(S,{type:"button",variant:"ghost",size:"icon",onClick:()=>G(O),"aria-label":`Remove currency ${I(`currencies.${O}.currency`)||""}`,children:e.jsx(ne,{className:"h-4 w-4","aria-hidden":"true"})})]},c.id))})]}),I("type")===$.BankAccount&&e.jsxs("div",{className:"space-y-4 border-t pt-4",children:[e.jsx("h3",{className:"text-sm font-semibold",children:"Bank-Specific Details"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:[e.jsx(g,{control:j,name:"bankNumber",render:({field:c})=>e.jsxs(v,{className:"space-y-2",children:[e.jsx(f,{children:"Bank Number"}),e.jsx(y,{children:e.jsx(A,{inputMode:"numeric",value:c.value??"",onChange:c.onChange})}),e.jsx(C,{})]})}),e.jsx(g,{control:j,name:"branchNumber",render:({field:c})=>e.jsxs(v,{className:"space-y-2",children:[e.jsx(f,{children:"Branch Number"}),e.jsx(y,{children:e.jsx(A,{inputMode:"numeric",value:c.value??"",onChange:c.onChange})}),e.jsx(C,{})]})}),e.jsx(g,{control:j,name:"extendedBankNumber",render:({field:c})=>e.jsxs(v,{className:"space-y-2",children:[e.jsx(f,{children:"Extended Bank Number"}),e.jsx(y,{children:e.jsx(A,{inputMode:"numeric",value:c.value??"",onChange:c.onChange})}),e.jsx(C,{})]})}),e.jsx(g,{control:j,name:"partyPreferredIndication",render:({field:c})=>e.jsxs(v,{className:"space-y-2",children:[e.jsx(f,{children:"Party Preferred Indication"}),e.jsx(y,{children:e.jsx(A,{inputMode:"numeric",value:c.value??"",onChange:c.onChange})}),e.jsx(C,{})]})}),e.jsx(g,{control:j,name:"partyAccountInvolvementCode",render:({field:c})=>e.jsxs(v,{className:"space-y-2",children:[e.jsx(f,{children:"Party Account Involvement Code"}),e.jsx(y,{children:e.jsx(A,{inputMode:"numeric",value:c.value??"",onChange:c.onChange})}),e.jsx(C,{})]})}),e.jsx(g,{control:j,name:"accountDealDate",render:({field:c})=>e.jsxs(v,{className:"space-y-2",children:[e.jsx(f,{children:"Account Deal Date"}),e.jsx(y,{children:e.jsx(A,{inputMode:"numeric",placeholder:"YYYYMMDD",value:c.value??"",onChange:c.onChange})}),e.jsx(C,{})]})}),e.jsx(g,{control:j,name:"accountUpdateDate",render:({field:c})=>e.jsxs(v,{className:"space-y-2",children:[e.jsx(f,{children:"Account Update Date"}),e.jsx(y,{children:e.jsx(A,{inputMode:"numeric",placeholder:"YYYYMMDD",value:c.value??"",onChange:c.onChange})}),e.jsx(C,{})]})}),e.jsx(g,{control:j,name:"metegDoarNet",render:({field:c})=>e.jsxs(v,{className:"space-y-2",children:[e.jsx(f,{children:"Meteg Dora Net"}),e.jsx(y,{children:e.jsx(A,{inputMode:"numeric",value:c.value??"",onChange:c.onChange})}),e.jsx(C,{})]})}),e.jsx(g,{control:j,name:"kodHarshaatPeilut",render:({field:c})=>e.jsxs(v,{className:"space-y-2",children:[e.jsx(f,{children:"Kod Harshaot Peilut"}),e.jsx(y,{children:e.jsx(A,{inputMode:"numeric",value:c.value??"",onChange:c.onChange})}),e.jsx(C,{})]})}),e.jsx(g,{control:j,name:"accountClosingReasonCode",render:({field:c})=>e.jsxs(v,{className:"space-y-2",children:[e.jsx(f,{children:"Account Closing Reason Code"}),e.jsx(y,{children:e.jsx(A,{inputMode:"numeric",value:c.value??"",onChange:c.onChange})}),e.jsx(C,{})]})}),e.jsx(g,{control:j,name:"accountAgreementOpeningDate",render:({field:c})=>e.jsxs(v,{className:"space-y-2",children:[e.jsx(f,{children:"Account Agreement Opening Date"}),e.jsx(y,{children:e.jsx(A,{inputMode:"numeric",placeholder:"YYYYMMDD",value:c.value??"",onChange:c.onChange})}),e.jsx(C,{})]})}),e.jsx(g,{control:j,name:"branchTypeCode",render:({field:c})=>e.jsxs(v,{className:"space-y-2",children:[e.jsx(f,{children:"Branch Type Code"}),e.jsx(y,{children:e.jsx(A,{inputMode:"numeric",value:c.value??"",onChange:c.onChange})}),e.jsx(C,{})]})}),e.jsx(g,{control:j,name:"mymailEntitlementSwitch",render:({field:c})=>e.jsxs(v,{className:"space-y-2",children:[e.jsx(f,{children:"Mymail Entitlement Switch"}),e.jsx(y,{children:e.jsx(A,{inputMode:"numeric",value:c.value??"",onChange:c.onChange})}),e.jsx(C,{})]})}),e.jsx(g,{control:j,name:"serviceAuthorizationDesc",render:({field:c})=>e.jsxs(v,{className:"space-y-2 md:col-span-2",children:[e.jsx(f,{children:"Service Authorization Description"}),e.jsx(y,{children:e.jsx(A,{...c})}),e.jsx(C,{})]})}),e.jsx(g,{control:j,name:"productLabel",render:({field:c})=>e.jsxs(v,{className:"space-y-2 md:col-span-2 lg:col-span-3",children:[e.jsx(f,{children:"Product Label"}),e.jsx(y,{children:e.jsx(A,{...c})}),e.jsx(C,{})]})})]})]}),e.jsxs(Ds,{children:[e.jsx(S,{type:"button",variant:"outline",onClick:M,children:"Cancel"}),e.jsx(S,{type:"submit",disabled:d||p,children:r?p?"Updating…":"Update Account":d?"Creating…":"Create Account"})]})]})})]})})});function Jn(s){return{id:s.id,name:s.name,number:s.number,isBusiness:s.privateOrBusiness===$e.Business,type:s.type,currencies:s.accountTaxCategories.map(a=>({currency:a.currency,taxCategory:{id:a.taxCategory.id,name:a.taxCategory.name}})),...s.__typename==="BankFinancialAccount"?{bankNumber:s.bankNumber,branchNumber:s.branchNumber,extendedBankNumber:s.extendedBankNumber??void 0,partyPreferredIndication:s.partyPreferredIndication??void 0,partyAccountInvolvementCode:s.partyAccountInvolvementCode??void 0,accountDealDate:s.accountDealDate??void 0,accountUpdateDate:s.accountUpdateDate??void 0,metegDoarNet:s.metegDoarNet??void 0,kodHarshaatPeilut:s.kodHarshaatPeilut??void 0,accountClosingReasonCode:s.accountClosingReasonCode??void 0,accountAgreementOpeningDate:s.accountAgreementOpeningDate??void 0,serviceAuthorizationDesc:s.serviceAuthorizationDesc??void 0,branchTypeCode:s.branchTypeCode??void 0,mymailEntitlementSwitch:s.mymailEntitlementSwitch??void 0,productLabel:s.productLabel??void 0}:{}}}function Zn({adminId:s}){const[a,n]=b.useState([]),[{data:t,fetching:l},o]=le({query:aa,variables:{adminId:s}});b.useEffect(()=>{t?.financialAccountsByOwner&&n(t.financialAccountsByOwner?.map(Jn)??[])},[t]);const r=b.useRef(null),i=h=>{r.current?.open(h)};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-semibold tracking-tight",children:"Financial Accounts"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Manage bank accounts, credit cards, and crypto wallets"})]}),e.jsxs(S,{onClick:()=>i(),"aria-label":"Create new financial account",children:[e.jsx(ae,{className:"h-4 w-4 mr-2","aria-hidden":"true"}),"New Account"]})]}),l?e.jsx("p",{children:"Loading..."}):e.jsxs("div",{className:"grid gap-4",children:[a.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"No financial accounts added yet."}),a.map(h=>e.jsx(Hn,{account:h,handleOpenModal:i},h.id))]}),e.jsx(Qn,{ownerId:s,ref:r,onDone:()=>o()})]})}function et({businessId:s}){return e.jsxs(Y,{children:[e.jsxs(X,{className:"flex w-full justify-between items-center",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{children:[e.jsx(Q,{children:"Balance"}),e.jsx(J,{children:"Business balance overview"})]})}),e.jsx(pe,{to:fs.BUSINESSES.DETAIL_LEDGER(s),children:e.jsx(S,{variant:"outline",size:"icon",children:e.jsx(Bn,{})})})]}),e.jsx(Z,{children:e.jsx("div",{className:"rounded-md border",children:e.jsx($a,{businessID:s,filter:{}})})})]})}function st({businessId:s}){const{userContext:a}=b.useContext(ss),[n,t]=b.useState(0),[{data:l,fetching:o}]=le({query:na,variables:{filters:{byOwners:a?.context.adminBusinessId?[a.context.adminBusinessId]:void 0,sortBy:{field:ia.Date,asc:!1},byBusinesses:[s]},page:n,limit:10}}),r=l?.allCharges?.pageInfo.totalPages??1,i=l?.allCharges?.nodes??[];return o?e.jsx("div",{children:"Loading charges..."}):e.jsxs(Y,{children:[e.jsxs(X,{className:"flex w-full justify-between items-center",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{children:[e.jsx(Q,{children:"Charges"}),e.jsx(J,{children:"Recurring and one-time charges for this business"})]})}),r>1&&e.jsx(ta,{className:"flex-fit w-fit mx-0",currentPageIndex:n,onChange:t,totalPages:r})]}),e.jsx(Z,{children:e.jsx("div",{className:"rounded-md border",children:e.jsx(Ha,{data:i,isAllOpened:!1})})})]})}var at=["type","layout","connectNulls","ref"],nt=["key"];function je(s){"@babel/helpers - typeof";return je=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(a){return typeof a}:function(a){return a&&typeof Symbol=="function"&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},je(s)}function ms(s,a){if(s==null)return{};var n=tt(s,a),t,l;if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(s);for(l=0;l<o.length;l++)t=o[l],!(a.indexOf(t)>=0)&&Object.prototype.propertyIsEnumerable.call(s,t)&&(n[t]=s[t])}return n}function tt(s,a){if(s==null)return{};var n={};for(var t in s)if(Object.prototype.hasOwnProperty.call(s,t)){if(a.indexOf(t)>=0)continue;n[t]=s[t]}return n}function Ae(){return Ae=Object.assign?Object.assign.bind():function(s){for(var a=1;a<arguments.length;a++){var n=arguments[a];for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(s[t]=n[t])}return s},Ae.apply(this,arguments)}function us(s,a){var n=Object.keys(s);if(Object.getOwnPropertySymbols){var t=Object.getOwnPropertySymbols(s);a&&(t=t.filter(function(l){return Object.getOwnPropertyDescriptor(s,l).enumerable})),n.push.apply(n,t)}return n}function q(s){for(var a=1;a<arguments.length;a++){var n=arguments[a]!=null?arguments[a]:{};a%2?us(Object(n),!0).forEach(function(t){se(s,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(s,Object.getOwnPropertyDescriptors(n)):us(Object(n)).forEach(function(t){Object.defineProperty(s,t,Object.getOwnPropertyDescriptor(n,t))})}return s}function he(s){return lt(s)||ct(s)||rt(s)||it()}function it(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
|
|
2
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function rt(s,a){if(s){if(typeof s=="string")return Ge(s,a);var n=Object.prototype.toString.call(s).slice(8,-1);if(n==="Object"&&s.constructor&&(n=s.constructor.name),n==="Map"||n==="Set")return Array.from(s);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return Ge(s,a)}}function ct(s){if(typeof Symbol<"u"&&s[Symbol.iterator]!=null||s["@@iterator"]!=null)return Array.from(s)}function lt(s){if(Array.isArray(s))return Ge(s)}function Ge(s,a){(a==null||a>s.length)&&(a=s.length);for(var n=0,t=new Array(a);n<a;n++)t[n]=s[n];return t}function ot(s,a){if(!(s instanceof a))throw new TypeError("Cannot call a class as a function")}function xs(s,a){for(var n=0;n<a.length;n++){var t=a[n];t.enumerable=t.enumerable||!1,t.configurable=!0,"value"in t&&(t.writable=!0),Object.defineProperty(s,Rs(t.key),t)}}function dt(s,a,n){return a&&xs(s.prototype,a),n&&xs(s,n),Object.defineProperty(s,"prototype",{writable:!1}),s}function mt(s,a,n){return a=Te(a),ut(s,Ms()?Reflect.construct(a,n||[],Te(s).constructor):a.apply(s,n))}function ut(s,a){if(a&&(je(a)==="object"||typeof a=="function"))return a;if(a!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return xt(s)}function xt(s){if(s===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return s}function Ms(){try{var s=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch{}return(Ms=function(){return!!s})()}function Te(s){return Te=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(n){return n.__proto__||Object.getPrototypeOf(n)},Te(s)}function ht(s,a){if(typeof a!="function"&&a!==null)throw new TypeError("Super expression must either be null or a function");s.prototype=Object.create(a&&a.prototype,{constructor:{value:s,writable:!0,configurable:!0}}),Object.defineProperty(s,"prototype",{writable:!1}),a&&We(s,a)}function We(s,a){return We=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,l){return t.__proto__=l,t},We(s,a)}function se(s,a,n){return a=Rs(a),a in s?Object.defineProperty(s,a,{value:n,enumerable:!0,configurable:!0,writable:!0}):s[a]=n,s}function Rs(s){var a=pt(s,"string");return je(a)=="symbol"?a:a+""}function pt(s,a){if(je(s)!="object"||!s)return s;var n=s[Symbol.toPrimitive];if(n!==void 0){var t=n.call(s,a);if(je(t)!="object")return t;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(s)}var ge=(function(s){function a(){var n;ot(this,a);for(var t=arguments.length,l=new Array(t),o=0;o<t;o++)l[o]=arguments[o];return n=mt(this,a,[].concat(l)),se(n,"state",{isAnimationFinished:!0,totalLength:0}),se(n,"generateSimpleStrokeDasharray",function(r,i){return"".concat(i,"px ").concat(r-i,"px")}),se(n,"getStrokeDasharray",function(r,i,h){var d=h.reduce(function(F,P){return F+P});if(!d)return n.generateSimpleStrokeDasharray(i,r);for(var m=Math.floor(r/d),p=r%d,u=i-r,j=[],w=0,I=0;w<h.length;I+=h[w],++w)if(I+h[w]>p){j=[].concat(he(h.slice(0,w)),[p-I]);break}var B=j.length%2===0?[0,u]:[u];return[].concat(he(a.repeat(h,m)),he(j),B).map(function(F){return"".concat(F,"px")}).join(", ")}),se(n,"id",an("recharts-line-")),se(n,"pathRef",function(r){n.mainCurve=r}),se(n,"handleAnimationEnd",function(){n.setState({isAnimationFinished:!0}),n.props.onAnimationEnd&&n.props.onAnimationEnd()}),se(n,"handleAnimationStart",function(){n.setState({isAnimationFinished:!1}),n.props.onAnimationStart&&n.props.onAnimationStart()}),n}return ht(a,s),dt(a,[{key:"componentDidMount",value:function(){if(this.props.isAnimationActive){var t=this.getTotalLength();this.setState({totalLength:t})}}},{key:"componentDidUpdate",value:function(){if(this.props.isAnimationActive){var t=this.getTotalLength();t!==this.state.totalLength&&this.setState({totalLength:t})}}},{key:"getTotalLength",value:function(){var t=this.mainCurve;try{return t&&t.getTotalLength&&t.getTotalLength()||0}catch{return 0}}},{key:"renderErrorBar",value:function(t,l){if(this.props.isAnimationActive&&!this.state.isAnimationFinished)return null;var o=this.props,r=o.points,i=o.xAxis,h=o.yAxis,d=o.layout,m=o.children,p=Ya(m,Xa);if(!p)return null;var u=function(I,B){return{x:I.x,y:I.y,value:I.value,errorVal:Os(I.payload,B)}},j={clipPath:t?"url(#clipPath-".concat(l,")"):null};return U.createElement(Fe,j,p.map(function(w){return U.cloneElement(w,{key:"bar-".concat(w.props.dataKey),data:r,xAxis:i,yAxis:h,layout:d,dataPointFormatter:u})}))}},{key:"renderDots",value:function(t,l,o){var r=this.props.isAnimationActive;if(r&&!this.state.isAnimationFinished)return null;var i=this.props,h=i.dot,d=i.points,m=i.dataKey,p=Ie(this.props,!1),u=Ie(h,!0),j=d.map(function(I,B){var F=q(q(q({key:"dot-".concat(B),r:3},p),u),{},{index:B,cx:I.x,cy:I.y,value:I.value,dataKey:m,payload:I.payload,points:d});return a.renderDotItem(h,F)}),w={clipPath:t?"url(#clipPath-".concat(l?"":"dots-").concat(o,")"):null};return U.createElement(Fe,Ae({className:"recharts-line-dots",key:"dots"},w),j)}},{key:"renderCurveStatically",value:function(t,l,o,r){var i=this.props,h=i.type,d=i.layout,m=i.connectNulls;i.ref;var p=ms(i,at),u=q(q(q({},Ie(p,!0)),{},{fill:"none",className:"recharts-line-curve",clipPath:l?"url(#clipPath-".concat(o,")"):null,points:t},r),{},{type:h,layout:d,connectNulls:m});return U.createElement(Qa,Ae({},u,{pathRef:this.pathRef}))}},{key:"renderCurveWithAnimation",value:function(t,l){var o=this,r=this.props,i=r.points,h=r.strokeDasharray,d=r.isAnimationActive,m=r.animationBegin,p=r.animationDuration,u=r.animationEasing,j=r.animationId,w=r.animateNewValues,I=r.width,B=r.height,F=this.state,P=F.prevPoints,M=F.totalLength;return U.createElement(Ja,{begin:m,duration:p,isActive:d,easing:u,from:{t:0},to:{t:1},key:"line-".concat(j),onAnimationEnd:this.handleAnimationEnd,onAnimationStart:this.handleAnimationStart},function(z){var _=z.t;if(P){var G=P.length/i.length,c=i.map(function(N,E){var L=Math.floor(E*G);if(P[L]){var oe=P[L],xe=ve(oe.x,N.x),$s=ve(oe.y,N.y);return q(q({},N),{},{x:xe(_),y:$s(_)})}if(w){var zs=ve(I*2,N.x),Us=ve(B/2,N.y);return q(q({},N),{},{x:zs(_),y:Us(_)})}return q(q({},N),{},{x:N.x,y:N.y})});return o.renderCurveStatically(c,t,l)}var O=ve(0,M),R=O(_),k;if(h){var x="".concat(h).split(/[,\s]+/gim).map(function(N){return parseFloat(N)});k=o.getStrokeDasharray(R,M,x)}else k=o.generateSimpleStrokeDasharray(M,R);return o.renderCurveStatically(i,t,l,{strokeDasharray:k})})}},{key:"renderCurve",value:function(t,l){var o=this.props,r=o.points,i=o.isAnimationActive,h=this.state,d=h.prevPoints,m=h.totalLength;return i&&r&&r.length&&(!d&&m>0||!Za(d,r))?this.renderCurveWithAnimation(t,l):this.renderCurveStatically(r,t,l)}},{key:"render",value:function(){var t,l=this.props,o=l.hide,r=l.dot,i=l.points,h=l.className,d=l.xAxis,m=l.yAxis,p=l.top,u=l.left,j=l.width,w=l.height,I=l.isAnimationActive,B=l.id;if(o||!i||!i.length)return null;var F=this.state.isAnimationFinished,P=i.length===1,M=ns("recharts-line",h),z=d&&d.allowDataOverflow,_=m&&m.allowDataOverflow,G=z||_,c=qe(B)?this.id:B,O=(t=Ie(r,!1))!==null&&t!==void 0?t:{r:3,strokeWidth:2},R=O.r,k=R===void 0?3:R,x=O.strokeWidth,N=x===void 0?2:x,E=en(r)?r:{},L=E.clipDot,oe=L===void 0?!0:L,xe=k*2+N;return U.createElement(Fe,{className:M},z||_?U.createElement("defs",null,U.createElement("clipPath",{id:"clipPath-".concat(c)},U.createElement("rect",{x:z?u:u-j/2,y:_?p:p-w/2,width:z?j:j*2,height:_?w:w*2})),!oe&&U.createElement("clipPath",{id:"clipPath-dots-".concat(c)},U.createElement("rect",{x:u-xe/2,y:p-xe/2,width:j+xe,height:w+xe}))):null,!P&&this.renderCurve(G,c),this.renderErrorBar(G,c),(P||r)&&this.renderDots(G,oe,c),(!I||F)&&sn.renderCallByParent(this.props,i))}}],[{key:"getDerivedStateFromProps",value:function(t,l){return t.animationId!==l.prevAnimationId?{prevAnimationId:t.animationId,curPoints:t.points,prevPoints:l.curPoints}:t.points!==l.curPoints?{curPoints:t.points}:null}},{key:"repeat",value:function(t,l){for(var o=t.length%2!==0?[].concat(he(t),[0]):t,r=[],i=0;i<l;++i)r=[].concat(he(r),he(o));return r}},{key:"renderDotItem",value:function(t,l){var o;if(U.isValidElement(t))o=U.cloneElement(t,l);else if(Wa(t))o=t(l);else{var r=l.key,i=ms(l,nt),h=ns("recharts-line-dot",typeof t!="boolean"?t.className:"");o=U.createElement(Ka,Ae({key:r},i,{className:h}))}return o}}])})(b.PureComponent);se(ge,"displayName","Line");se(ge,"defaultProps",{xAxisId:0,yAxisId:0,connectNulls:!1,activeDot:!0,dot:!0,legendType:"line",stroke:"#3182bd",strokeWidth:1,fill:"#fff",points:[],isAnimationActive:!nn.isSsr,animateNewValues:!0,animationBegin:0,animationDuration:1500,animationEasing:"ease",hide:!1,label:!1});se(ge,"getComposedData",function(s){var a=s.props,n=s.xAxis,t=s.yAxis,l=s.xAxisTicks,o=s.yAxisTicks,r=s.dataKey,i=s.bandSize,h=s.displayedData,d=s.offset,m=a.layout,p=h.map(function(u,j){var w=Os(u,r);return m==="horizontal"?{x:cs({axis:n,ticks:l,bandSize:i,entry:u,index:j}),y:qe(w)?null:t.scale(w),value:w,payload:u}:{x:qe(w)?null:n.scale(w),y:cs({axis:t,ticks:o,bandSize:i,entry:u,index:j}),value:w,payload:u}});return q({points:p,layout:m},d)});var jt=tn({chartName:"LineChart",GraphicalChild:ge,axisComponents:[{axisType:"xAxis",AxisComp:Ls},{axisType:"yAxis",AxisComp:Fs}],formatAxisMap:rn});const Ne=[{month:"Jan",revenue:12500,expenses:8200},{month:"Feb",revenue:15800,expenses:9100},{month:"Mar",revenue:18200,expenses:10500},{month:"Apr",revenue:16900,expenses:9800},{month:"May",revenue:21300,expenses:11200},{month:"Jun",revenue:24500,expenses:12800},{month:"Jul",revenue:22800,expenses:11900},{month:"Aug",revenue:26100,expenses:13500},{month:"Sep",revenue:28900,expenses:14200},{month:"Oct",revenue:31200,expenses:15100}];function gt(){const s=Ne.reduce((n,t)=>n+t.revenue,0),a=s/Ne.length;return e.jsxs(Y,{children:[e.jsxs(X,{children:[e.jsx(Q,{children:"Revenue Analytics"}),e.jsx(J,{children:"Revenue and expenses over time"})]}),e.jsxs(Z,{children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-3 mb-6",children:[e.jsxs("div",{className:"rounded-lg border p-4 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(Se,{className:"h-4 w-4"}),"Total Revenue"]}),e.jsxs("p",{className:"text-2xl font-bold",children:["$",s.toLocaleString()]}),e.jsxs("div",{className:"flex items-center gap-1 text-sm text-green-600",children:[e.jsx(Le,{className:"h-3 w-3"}),e.jsx("span",{children:"+24.5% from last period"})]})]}),e.jsxs("div",{className:"rounded-lg border p-4 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(Se,{className:"h-4 w-4"}),"Average Monthly"]}),e.jsxs("p",{className:"text-2xl font-bold",children:["$",a.toLocaleString(void 0,{maximumFractionDigits:0})]}),e.jsxs("div",{className:"flex items-center gap-1 text-sm text-green-600",children:[e.jsx(Le,{className:"h-3 w-3"}),e.jsx("span",{children:"+18.2% growth rate"})]})]}),e.jsxs("div",{className:"rounded-lg border p-4 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(Se,{className:"h-4 w-4"}),"Current Month"]}),e.jsxs("p",{className:"text-2xl font-bold",children:["$",Ne[Ne.length-1].revenue.toLocaleString()]}),e.jsxs("div",{className:"flex items-center gap-1 text-sm text-green-600",children:[e.jsx(Le,{className:"h-3 w-3"}),e.jsx("span",{children:"+8.0% from last month"})]})]})]}),e.jsx(cn,{config:{revenue:{label:"Revenue",color:"hsl(var(--chart-1))"},expenses:{label:"Expenses",color:"hsl(var(--chart-2))"}},className:"h-[400px]",children:e.jsx(ln,{width:"100%",height:"100%",children:e.jsxs(jt,{data:Ne,margin:{top:5,right:10,left:10,bottom:5},children:[e.jsx(on,{strokeDasharray:"3 3",className:"stroke-muted"}),e.jsx(Ls,{dataKey:"month",className:"text-xs",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(Fs,{className:"text-xs",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(dn,{content:e.jsx(mn,{})}),e.jsx(ge,{type:"monotone",dataKey:"revenue",stroke:"var(--color-revenue)",strokeWidth:2,dot:{fill:"var(--color-revenue)",r:4}}),e.jsx(ge,{type:"monotone",dataKey:"expenses",stroke:"var(--color-expenses)",strokeWidth:2,dot:{fill:"var(--color-expenses)",r:4}})]})})})]})]})}function vt(s){return{id:s.id,pos:s.purchaseOrders??void 0,startDate:s.startDate,endDate:s.endDate,paymentAmount:s.amount.raw,paymentCurrency:s.amount.currency,productType:s.product??void 0,billingCycle:s.billingCycle,msCloudLink:s.msCloud?.toString(),isActive:s.isActive,subscriptionPlan:s.plan??void 0,defaultRemark:s.remarks??void 0,defaultDocumentType:s.documentType??void 0,operationsLimit:s.operationsLimit}}function ft({clientId:s}){const[a,n]=b.useState(null),[{data:t,fetching:l},o]=le({query:ra,variables:{clientId:s}}),r=t?.contractsByClient??[];return l?e.jsx("div",{children:"Loading contracts..."}):e.jsxs(Y,{children:[e.jsx(X,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(Q,{children:"Contracts"}),e.jsx(J,{children:"Current and past contracts sorted by start date"})]}),e.jsx(un,{clientId:s,contract:a,onDone:o})]})}),e.jsx(Z,{className:"space-y-4",children:r.map(i=>{const h=!!i.isActive;return e.jsxs("div",{className:"rounded-lg border p-4 space-y-4",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h4",{className:"font-semibold",children:i.product}),e.jsx(te,{variant:h?"default":"secondary",children:i.isActive?"Active":"Inactive"})]}),e.jsx("p",{className:"text-sm text-muted-foreground font-mono",children:i.id})]}),e.jsx(S,{variant:"ghost",size:"sm",onClick:()=>n(vt(i)),children:e.jsx(pn,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2 lg:grid-cols-3",children:[e.jsxs("div",{className:"space-y-0",children:[e.jsxs("p",{className:"text-sm text-muted-foreground flex items-center gap-1",children:[e.jsx(ca,{className:"h-3 w-3"}),"Contract Period"]}),e.jsxs("p",{className:"text-sm font-medium",children:[new Date(i.startDate).toLocaleDateString()," →"," ",new Date(i.endDate).toLocaleDateString()]})]}),e.jsxs("div",{className:"space-y-0",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"PO Numbers"}),e.jsx("p",{className:"text-sm font-medium font-mono",children:i.purchaseOrders.toReversed()[0]??""}),i.purchaseOrders.length>1&&e.jsx("div",{className:"space-x-1",children:i.purchaseOrders.toReversed().slice(1).map(d=>e.jsx("span",{className:"text-xs font-thin font-mono",children:d},d))})]}),e.jsxs("div",{className:"space-y-0",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Payment"}),e.jsx("p",{className:"text-sm font-medium",children:la(i.amount.raw,i.amount.currency)})]}),e.jsxs("div",{className:"space-y-0",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Billing Cycle"}),e.jsx("p",{className:"text-sm font-medium",children:xn(i.billingCycle)})]}),e.jsxs("div",{className:"space-y-0",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Subscription Plan"}),e.jsx("p",{className:"text-sm font-medium",children:i.plan?hn(i.plan):"N/A"})]}),e.jsxs("div",{className:"space-y-0",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Operations Limit"}),e.jsx("p",{className:"text-sm font-medium",children:i.operationsLimit.toLocaleString()})]}),e.jsxs("div",{className:"space-y-0",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Document Type"}),e.jsx("p",{className:"text-sm font-medium",children:oa(i.documentType)})]})]}),i.remarks&&e.jsxs("div",{className:"space-y-0",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Remark"}),e.jsx("p",{className:"text-sm",children:i.remarks})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:i.msCloud&&e.jsx(S,{variant:"outline",size:"sm",asChild:!0,children:e.jsxs("a",{href:i.msCloud.toString(),target:"_blank",rel:"noopener noreferrer",children:[e.jsx(Je,{className:"h-4 w-4 mr-2"}),"MS Cloud",e.jsx(jn,{className:"h-3 w-3 ml-1"})]})})})]},i.id)})})]})}const yt=[{id:"linearId",name:"Linear",description:"Issue tracking and project management",url:"https://linear.app/the-guild/customer/[ID]",color:"indigo-500"},{id:"slackChannelKey",name:"Slack",description:"Team communication and notifications",keyType:"Channel Key",url:"https://guild-oss.slack.com/archives/[ID]"},{id:"notionId",name:"Notion",description:"Documentation and knowledge management",url:"https://www.notion.so/theguildoss/[ID]"},{id:"workflowyUrl",name:"Workflowy",keyType:"URL",description:"Task management and note taking",url:"[ID]"}];function Nt({data:s}){const[a,n]=b.useState([]),t=we(ma,s),l=t?.clientInfo?.integrations,{updateClient:o}=Bs(),[{data:r,fetching:i},h]=le({query:da,variables:{clientId:t?.id??""},pause:!l?.greenInvoiceInfo||!t?.id||!a.includes("green-invoice")}),d=r?.greenInvoiceClient,m=l?.hiveId,p=b.useCallback((u,j)=>{if(!t?.id)return;const w={};w[j]=u,o({businessId:t?.id,fields:{integrations:w}})},[t?.id,o]);return b.useEffect(()=>{l?.greenInvoiceInfo?.greenInvoiceId&&t?.id&&a.includes("green-invoice")&&h()},[l?.greenInvoiceInfo?.greenInvoiceId,t?.id,h,a]),e.jsxs(Y,{children:[e.jsx(X,{children:e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{children:[e.jsx(Q,{children:"Integrations"}),e.jsx(J,{children:"Connected external services and providers"})]})})}),e.jsx(Z,{className:"space-y-6",children:e.jsxs(vn,{type:"multiple",value:a,onValueChange:n,className:"space-y-4",children:[i?e.jsxs(ke,{value:"green-invoice",className:"rounded-lg border-2 border-green-600/20 bg-green-600/5",children:[e.jsx("div",{className:"px-4 py-3 bg-green-600/10 rounded-t-lg",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-1",children:[e.jsx(D,{className:"h-10 w-10 rounded-lg"}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(D,{className:"h-6 w-32"}),e.jsx(D,{className:"h-5 w-5 rounded-full"})]}),e.jsx(D,{className:"h-4 w-64"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(D,{className:"h-8 w-24"}),e.jsx(D,{className:"h-8 w-8"})]})]})}),e.jsx(_e,{children:e.jsxs("div",{className:"p-6 space-y-6",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx(D,{className:"h-4 w-40"}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(D,{className:"h-3 w-24"}),e.jsx(D,{className:"h-4 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(D,{className:"h-3 w-24"}),e.jsx(D,{className:"h-4 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(D,{className:"h-3 w-24"}),e.jsx(D,{className:"h-4 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(D,{className:"h-3 w-24"}),e.jsx(D,{className:"h-4 w-full"})]})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(D,{className:"h-4 w-40"}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(D,{className:"h-3 w-32"}),e.jsx(D,{className:"h-6 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(D,{className:"h-3 w-24"}),e.jsx(D,{className:"h-4 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(D,{className:"h-3 w-24"}),e.jsx(D,{className:"h-4 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(D,{className:"h-3 w-24"}),e.jsx(D,{className:"h-4 w-full"})]})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(D,{className:"h-4 w-40"}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-3",children:[e.jsxs("div",{className:"space-y-2 md:col-span-2",children:[e.jsx(D,{className:"h-3 w-24"}),e.jsx(D,{className:"h-4 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(D,{className:"h-3 w-24"}),e.jsx(D,{className:"h-4 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(D,{className:"h-3 w-24"}),e.jsx(D,{className:"h-4 w-full"})]})]})]})]})})]}):e.jsxs(ke,{value:"green-invoice",className:"rounded-lg border-2 border-green-600/20 bg-green-600/5",children:[e.jsx("div",{className:"px-4 py-3 bg-green-600/10 rounded-t-lg",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-1",children:[e.jsx("div",{className:"h-10 w-10 rounded-lg bg-green-600 flex items-center justify-center text-white font-bold",children:"GI"}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"font-semibold text-lg",children:"Green Invoice"}),e.jsx(Me,{className:"h-5 w-5 text-green-600"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Israeli invoicing system integration"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ve,{id:t?.clientInfo?.integrations.greenInvoiceInfo?.greenInvoiceId??void 0,provider:"Green Invoice",updateClient:async u=>p(u,"greenInvoiceId")}),d&&e.jsx(ls,{className:"hover:no-underline p-2"})]})]})}),e.jsx(_e,{children:d&&e.jsxs("div",{className:"p-6 space-y-6",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx("h4",{className:"font-semibold text-sm text-muted-foreground uppercase tracking-wide",children:"Business Information"}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:"Integration ID"}),e.jsx("p",{className:"text-sm font-mono",children:t?.clientInfo?.integrations.greenInvoiceInfo?.greenInvoiceId})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:"Business Name"}),e.jsx("p",{className:"text-sm",children:d.name})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:"Country"}),e.jsx("p",{className:"text-sm",children:d.country})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:"Tax ID"}),e.jsx("p",{className:"text-sm font-mono",children:d.taxId})]})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h4",{className:"font-semibold text-sm text-muted-foreground uppercase tracking-wide",children:"Contact Information"}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("span",{className:"text-sm font-medium text-muted-foreground flex items-center gap-2",children:[e.jsx(ze,{className:"h-3.5 w-3.5"}),"Email Addresses"]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:d.emails?.map((u,j)=>e.jsx("span",{className:"text-sm px-2 py-1 bg-muted rounded",children:u},j))})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("span",{className:"text-sm font-medium text-muted-foreground flex items-center gap-2",children:[e.jsx(Es,{className:"h-3.5 w-3.5"}),"Phone"]}),e.jsx("p",{className:"text-sm font-mono",children:d.phone})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:"Mobile"}),e.jsx("p",{className:"text-sm font-mono",children:d.mobile})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:"Fax"}),e.jsx("p",{className:"text-sm font-mono",children:d.fax})]})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("h4",{className:"font-semibold text-sm text-muted-foreground uppercase tracking-wide flex items-center gap-2",children:[e.jsx(Ue,{className:"h-3.5 w-3.5"}),"Address"]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-3",children:[e.jsxs("div",{className:"space-y-1 md:col-span-2",children:[e.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:"Street Address"}),e.jsx("p",{className:"text-sm",children:d.address})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:"City"}),e.jsx("p",{className:"text-sm",children:d.city})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:"Zip Code"}),e.jsx("p",{className:"text-sm font-mono",children:d.zip})]})]})]})]})})]}),e.jsxs(ke,{value:"hiveId",className:"rounded-lg border-2 border-green-900/20 bg-green-900/5",children:[e.jsx("div",{className:"px-4 py-3 bg-green-900/10 rounded-t-lg",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-1",children:[m?e.jsx(pe,{to:"https://the-guild.dev/graphql/hive",target:"_blank",rel:"noreferrer",onClick:u=>u.stopPropagation(),className:"inline-flex items-center font-semibold",children:e.jsx("div",{className:"h-10 w-10 rounded-lg bg-green-900 flex items-center justify-center text-white font-bold",children:e.jsx("img",{src:"/icons/logos/hive.svg",alt:"Hive logo",className:"size-8 object-cover"})})}):e.jsx("div",{className:"h-10 w-10 rounded-lg bg-green-900 flex items-center justify-center text-white font-bold",children:e.jsx(ts,{})}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"font-semibold text-lg",children:"Hive"}),m?e.jsx(Me,{className:"h-5 w-5 text-green-600"}):e.jsx(os,{className:"h-5 w-5 text-red-600"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Schema registry, analytics, metrics and gateway for GraphQL federation and other GraphQL APIs"})]})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(Ve,{id:l?.hiveId??void 0,provider:"Hive",updateClient:async u=>p(u,"hiveId")})}),m&&e.jsx(ls,{className:"hover:no-underline p-2"})]})}),e.jsx(_e,{children:m&&e.jsxs("div",{className:"flex flex-col gap-4 px-4 pb-4 pt-2 border-t",children:[e.jsx("div",{className:"text-sm",children:e.jsxs(pe,{to:"https://the-guild.dev/graphql/hive",target:"_blank",rel:"noreferrer",onClick:u=>u.stopPropagation(),className:"inline-flex items-center font-semibold gap-2",children:[e.jsx("img",{src:"/icons/logos/hive.svg",alt:"Hive logo",className:"size-8 object-cover"}),"Hive"]})}),e.jsx("div",{className:"text-sm",children:e.jsxs(pe,{to:`https://graphcdn.retool.com/apps/f6c244bc-b7ce-11ef-a86c-0b05f221c5b4/Hive/Hive%20Admin/explore_organization?id=${l.hiveId}`,target:"_blank",rel:"noreferrer",onClick:u=>u.stopPropagation(),className:"inline-flex items-center font-semibold gap-2",children:[e.jsx("img",{src:"/icons/logos/retool.svg",alt:"Retool logo",className:"size-8 object-cover"}),"Retool"]})})]})})]},"hiveId"),yt.map(u=>e.jsx(ke,{value:u.id,className:"rounded-lg border-2 border-gray-500/20 bg-gray-500/5",children:e.jsx("div",{className:"px-4 py-3 bg-gray-500/10 rounded-t-lg",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-1",children:[l?.[u.id]?e.jsx(pe,{to:u.url.replace("[ID]",l?.[u.id]??""),target:"_blank",rel:"noreferrer",onClick:j=>j.stopPropagation(),className:"inline-flex items-center font-semibold",children:e.jsx("div",{className:"h-10 w-10 rounded-lg bg-gray-500 flex items-center justify-center text-white font-bold",children:e.jsx(Je,{})})}):e.jsx("div",{className:"h-10 w-10 rounded-lg bg-gray-500 flex items-center justify-center text-white font-bold",children:e.jsx(ts,{})}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"font-semibold text-lg",children:u.name}),l?.[u.id]==null?e.jsx(os,{className:"h-5 w-5 text-red-600"}):e.jsx(Me,{className:"h-5 w-5 text-green-600"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:u.description})]})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(Ve,{id:t?.clientInfo?.integrations[u.id]??void 0,provider:u.name,keyType:u.keyType,updateClient:async j=>p(j,u.id)})})]})})},u.id))]})})]})}function Ve({id:s,provider:a,keyType:n,updateClient:t}){const[l,o]=b.useState(!1),[r,i]=b.useState(s),h=b.useCallback(async()=>{await t(r),o(!1)},[r,t]);return e.jsxs(Ke,{open:l,onOpenChange:o,children:[e.jsx(ua,{asChild:!0,children:e.jsx(S,{variant:"outline",size:"sm",onClick:d=>d.stopPropagation(),children:e.jsx(Ps,{className:"h-4 w-4"})})}),e.jsxs(Ye,{onClick:d=>d.stopPropagation(),children:[e.jsxs(ys,{children:[e.jsxs(Ns,{children:["Configure ",a]}),e.jsxs(bs,{children:["Update your ",a," integration settings"]})]}),e.jsx("div",{className:"space-y-4 py-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsxs(Ce,{htmlFor:"id",children:[a," ",n??"ID"]}),e.jsx(A,{id:"id",value:r,onChange:d=>i(d.target.value),placeholder:`Enter ${a} ${n??"ID"}`})]})}),e.jsxs(Ds,{children:[e.jsx(S,{variant:"outline",onClick:()=>o(!1),children:"Cancel"}),e.jsx(S,{onClick:h,disabled:!r,children:"Save Changes"})]})]})]})}const bt="updateBusiness",Vs=()=>{const[{fetching:s},a]=Be(xa),n=b.useCallback(async t=>{const l=`Error updating business ID [${t.businessId}]`,o=`${bt}-${t.businessId}`;K.loading("Updating business",{id:o});try{const r=await a(t),i=Ee(r,l,o,"updateBusiness");if(i)return K.success("Success",{id:o,description:"Business updated"}),i.updateBusiness}catch(r){console.error(`${l}: ${r}`),K.error("Error",{id:o,description:l,duration:1e5,closeButton:!0})}},[a]);return{fetching:s,updateBusiness:n}},Ct=Object.values(ba);function hs(s){return!s||s.__typename!=="LtdFinancialEntity"?{}:{isClient:!!s.clientInfo?.id,isActive:s.isActive,isReceiptEnough:s.isReceiptEnough??void 0,isDocumentsOptional:s.isDocumentsOptional??void 0,isVatOptional:s.optionalVAT??void 0,isExemptDealer:s.exemptDealer??void 0,sortCode:s.sortCode?.key?.toString()??void 0,taxCategory:s.taxCategory?.id??void 0,pcn874RecordType:s?.pcn874RecordType??void 0,irsCode:s?.irsCode??void 0,description:s.suggestions?.description??void 0,tags:s.suggestions?.tags?.map(a=>a.id)??[],phrases:s.suggestions?.phrases??[],emails:s.suggestions?.emails??[],internalLinks:s.suggestions?.emailListener?.internalEmailLinks??[],attachmentTypes:s.suggestions?.emailListener?.attachments??[],useMessageBody:s.suggestions?.emailListener?.emailBody??void 0}}function At(s){const n=s.internalLinks||s.useMessageBody||s.attachmentTypes?{internalEmailLinks:s.internalLinks,emailBody:s.useMessageBody,attachments:s.attachmentTypes}:void 0,l=s.description||s.tags||s.phrases||s.emails||n?{description:s.description,tags:s.tags?.map(o=>({id:o})),phrases:s.phrases,emails:s.emails,emailListener:n}:void 0;return{optionalVAT:s.isVatOptional,exemptDealer:s.isExemptDealer,sortCode:s.sortCode?parseInt(s.sortCode):void 0,taxCategory:s.taxCategory,pcn874RecordType:s.pcn874RecordType,irsCode:s.irsCode,isActive:s.isActive,isReceiptEnough:s.isReceiptEnough,isDocumentsOptional:s.isDocumentsOptional,suggestions:l}}function wt({data:s,refetchBusiness:a}){const n=we(pa,s),[t,l]=b.useState(hs(n)),{userContext:o}=b.useContext(ss),{updateBusiness:r,fetching:i}=Vs(),[h,d]=b.useState(!1),[m,p]=b.useState(void 0),u=Pe({defaultValues:t}),j=async I=>{if(!n||!o?.context.adminBusinessId)return;const B=Ze(I,u.formState.dirtyFields);if(!B)return;const F=At(B);await r({businessId:n.id,ownerId:o.context.adminBusinessId,fields:F}),B.tags?.length||B.description?(p({tagIds:B.tags?.map(P=>({id:P})),description:B.description}),d(!0)):a?.()};if(b.useEffect(()=>{if(n){const I=hs(n);l(I),u.reset(I)}},[n,u]),!n)return e.jsx("div",{});const w=u.watch("isClient");return e.jsxs(Y,{children:[e.jsx(X,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(Q,{children:"Configurations"}),e.jsx(J,{children:"Business status, tax settings, automation rules, and integration preferences"})]}),!w&&e.jsx(ha,{businessId:n.id,onDone:a})]})}),e.jsx(Oe,{...u,children:e.jsxs("form",{onSubmit:u.handleSubmit(j),children:[e.jsxs(Z,{className:"space-y-6",children:[e.jsx(It,{form:u}),e.jsx(ce,{}),e.jsx(kt,{form:u}),e.jsx(ce,{}),e.jsx(Dt,{form:u}),e.jsx(ce,{}),e.jsx(St,{form:u})]}),e.jsx(Qe,{className:"flex justify-end border-t pt-6",children:e.jsxs(S,{type:"submit",disabled:i||Object.keys(u.formState.dirtyFields).length===0,children:[e.jsx(as,{className:"h-4 w-4 mr-2"}),"Save Changes"]})})]})}),e.jsx(_n,{businessId:n.id,tagIds:m?.tagIds,description:m?.description,open:h,onOpenChange:d,onClose:a})]})}function It({form:s}){return e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-sm font-semibold text-foreground",children:"Business Status & Behavior"}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(g,{control:s.control,name:"isClient",render:({field:a,fieldState:n})=>e.jsxs(v,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(f,{children:"Is Client"}),e.jsx(de,{children:"Mark this business as a client"})]}),e.jsx(y,{children:e.jsx(re,{disabled:!0,checked:a.value,onCheckedChange:a.onChange,className:T(n)})})]})}),e.jsx(g,{control:s.control,name:"isActive",render:({field:a,fieldState:n})=>e.jsxs(v,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(f,{children:"Is Active"}),e.jsx(de,{children:"Business is currently active"})]}),e.jsx(y,{children:e.jsx(re,{checked:a.value,onCheckedChange:a.onChange,className:T(n)})})]})}),e.jsx(g,{control:s.control,name:"isReceiptEnough",render:({field:a,fieldState:n})=>e.jsxs(v,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(f,{children:"Is Receipt Enough"}),e.jsx(de,{children:"Generate ledger for receipt documents if no invoice available"})]}),e.jsx(y,{children:e.jsx(re,{checked:a.value,onCheckedChange:a.onChange,className:T(n)})})]})}),e.jsx(g,{control:s.control,name:"isDocumentsOptional",render:({field:a,fieldState:n})=>e.jsxs(v,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(f,{children:"No Docs Required"}),e.jsx(de,{children:"Skip document validation for common charges"})]}),e.jsx(y,{children:e.jsx(re,{checked:a.value,onCheckedChange:a.onChange,className:T(n)})})]})}),e.jsx(g,{control:s.control,name:"isVatOptional",render:({field:a,fieldState:n})=>e.jsxs(v,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(f,{children:"Is VAT Optional"}),e.jsx(de,{children:"Mute missing VAT indicator"})]}),e.jsx(y,{children:e.jsx(re,{checked:a.value,onCheckedChange:a.onChange,className:T(n)})})]})}),e.jsx(g,{control:s.control,name:"isExemptDealer",render:({field:a,fieldState:n})=>e.jsxs(v,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(f,{children:"Is Exempt Dealer"}),e.jsx(de,{children:"Business is exempt from VAT requirements"})]}),e.jsx(y,{children:e.jsx(re,{checked:a.value,onCheckedChange:a.onChange,className:T(n)})})]})})]})]})}function kt({form:s}){const{selectableTaxCategories:a,fetching:n}=ja(),{selectableSortCodes:t,fetching:l,sortCodes:o}=ga(),{selectableTags:r,fetching:i}=va(),h=b.useCallback(d=>{if(d){const m=o.find(p=>Number(p.key)===Number(d));m&&(m.defaultIrsCode?s.setValue("irsCode",m.defaultIrsCode,{shouldDirty:!0}):s.setValue("irsCode",null,{shouldDirty:!0}))}},[s,o]);return e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-sm font-semibold text-foreground",children:"Default Settings"}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsx(g,{control:s.control,name:"sortCode",render:({field:d,fieldState:m})=>e.jsxs(v,{children:[e.jsx(f,{children:"Sort Code"}),e.jsx(y,{children:e.jsx(He,{onChange:p=>{h(p),d.onChange(p)},data:t,value:d.value,disabled:l,placeholder:"Scroll to see all options",formPart:!0,triggerProps:{className:T(m)}})}),e.jsx(C,{})]})}),e.jsx(g,{control:s.control,name:"taxCategory",render:({field:d,fieldState:m})=>e.jsxs(v,{children:[e.jsx(f,{children:"Tax Category"}),e.jsx(y,{children:e.jsx(He,{data:a,disabled:n,value:d.value,onChange:d.onChange,placeholder:"Scroll to see all options",formPart:!0,triggerProps:{className:T(m)}})}),e.jsx(C,{})]})}),e.jsx(g,{control:s.control,name:"pcn874RecordType",render:({field:d,fieldState:m})=>e.jsxs(v,{children:[e.jsx(f,{children:"PCN874 Record Type"}),e.jsxs(Cs,{onValueChange:d.onChange,value:d.value,children:[e.jsx(y,{children:e.jsx(As,{className:T(m),children:e.jsx(ws,{})})}),e.jsx(Is,{children:Object.entries(fa).map(([p,u])=>e.jsx(ks,{value:p,children:`${u} (${p})`},p))})]}),e.jsx(C,{})]})}),e.jsx(g,{control:s.control,name:"irsCode",render:({field:d,fieldState:m})=>e.jsxs(v,{children:[e.jsx(f,{children:"IRS Code"}),e.jsx(y,{children:e.jsx(ya,{value:d.value??void 0,onValueChange:p=>d.onChange(p??null),hideControls:!0,decimalScale:0,className:T(m)})}),e.jsx(C,{})]})}),e.jsx(g,{control:s.control,name:"description",render:({field:d,fieldState:m})=>e.jsxs(v,{children:[e.jsx(f,{children:"Charge Description"}),e.jsx(y,{children:e.jsx(A,{placeholder:"Enter default charge description",...d,className:T(m)})}),e.jsx(C,{})]})}),e.jsx(g,{control:s.control,name:"tags",render:({field:d,fieldState:m})=>e.jsxs(v,{children:[e.jsx(f,{children:"Tags"}),e.jsx(y,{children:e.jsx(Na,{options:Object.values(r).map(({value:p,label:u})=>({label:u,value:p})),onValueChange:d.onChange,defaultValue:d.value,value:d.value,placeholder:"Select Default Tags",variant:"default",disabled:i,className:T(m)})}),e.jsx(C,{})]})})]})]})}function Dt({form:s}){const[a,n]=b.useState(""),[t,l]=b.useState(""),o=()=>{if(a.trim()){const d=s.getValues("phrases");s.setValue("phrases",[...d,a.trim()],{shouldDirty:!0}),n("")}},r=()=>{if(t.trim()){const d=s.getValues("emails");s.setValue("emails",[...d,t.trim()],{shouldDirty:!0}),l("")}},i=d=>{const m=s.getValues("phrases");s.setValue("phrases",m.filter((p,u)=>u!==d),{shouldDirty:!0})},h=d=>{const m=s.getValues("emails");s.setValue("emails",m.filter((p,u)=>u!==d),{shouldDirty:!0})};return e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-sm font-semibold text-foreground",children:"Auto-matching Configuration"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Configure patterns for automatic matching of bank transactions and documents"}),e.jsx(g,{control:s.control,name:"phrases",render:({field:d,fieldState:m})=>e.jsxs(v,{children:[e.jsx(f,{children:"Phrases"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(A,{placeholder:"Add phrase...",value:a,onChange:p=>n(p.target.value),onKeyDown:p=>{p.key==="Enter"&&(p.preventDefault(),o())},className:T(m)}),e.jsx(S,{type:"button",size:"sm",onClick:o,children:e.jsx(ae,{className:"h-4 w-4"})})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:d.value?.map((p,u)=>e.jsxs(te,{variant:"secondary",className:"gap-1",children:[p,e.jsx(S,{variant:"ghost",size:"icon",className:"p-0 size-3",onClick:()=>i(u),children:e.jsx(ne,{className:"size-3 cursor-pointer",onClick:()=>i(u)})})]},u))}),e.jsx(C,{})]})}),e.jsx(g,{control:s.control,name:"emails",render:({field:d,fieldState:m})=>e.jsxs(v,{children:[e.jsx(f,{children:"Email Addresses"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(A,{type:"email",placeholder:"Add email...",value:t,onChange:p=>l(p.target.value),onKeyDown:p=>{p.key==="Enter"&&(p.preventDefault(),r())},className:T(m)}),e.jsx(S,{type:"button",size:"sm",onClick:r,children:e.jsx(ae,{className:"h-4 w-4"})})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:d.value?.map((p,u)=>e.jsxs(te,{variant:"secondary",className:"gap-1",children:[p,e.jsx(S,{variant:"ghost",size:"icon",className:"p-0 size-3",onClick:()=>h(u),children:e.jsx(ne,{className:"size-3 cursor-pointer"})})]},u))}),e.jsx(C,{})]})})]})}function St({form:s}){const[a,n]=b.useState(""),t=()=>{if(a.trim()){const r=s.getValues("internalLinks");s.setValue("internalLinks",[...r,a.trim()],{shouldDirty:!0}),n("")}},l=r=>{const i=s.getValues("attachmentTypes");s.setValue("attachmentTypes",i?.includes(r)?i.filter(h=>h!==r):[...i,r],{shouldDirty:!0})},o=r=>{const i=s.getValues("internalLinks");s.setValue("internalLinks",i.filter((h,d)=>d!==r),{shouldDirty:!0})};return e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-sm font-semibold text-foreground",children:"Gmail Feature Configuration"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Configure Gmail integration settings for document processing"}),e.jsx(g,{control:s.control,name:"attachmentTypes",render:({field:r,fieldState:i})=>e.jsxs(v,{children:[e.jsx(f,{children:"Attachment Types"}),e.jsx("div",{className:T(i)+" rounded-md flex flex-wrap gap-2",children:Ct.map(h=>e.jsx(te,{variant:r.value?.includes(h)?"default":"outline",className:"cursor-pointer",onClick:()=>l(h),children:h},h))}),e.jsx(C,{})]})}),e.jsx(g,{control:s.control,name:"internalLinks",render:({field:r,fieldState:i})=>e.jsxs(v,{children:[e.jsx(f,{children:"Internal Links"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(A,{type:"url",placeholder:"Add internal link...",value:a,onChange:h=>n(h.target.value),onKeyDown:h=>{h.key==="Enter"&&(h.preventDefault(),t())}}),e.jsx(S,{type:"button",size:"sm",onClick:t,children:e.jsx(ae,{className:"h-4 w-4"})})]}),e.jsx("div",{className:T(i)+" flex flex-wrap gap-2 rounded-md",children:r.value?.map((h,d)=>e.jsxs(te,{variant:"secondary",className:"gap-1 max-w-xs truncate",children:[h,e.jsx(S,{variant:"ghost",size:"icon",className:"p-0 size-3",onClick:()=>o(d),children:e.jsx(ne,{className:"size-3 cursor-pointer flex-shrink-0"})})]},d))}),e.jsx(C,{})]})}),e.jsx(g,{control:s.control,name:"useMessageBody",render:({field:r,fieldState:i})=>e.jsxs(v,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(f,{children:"Should Use Message Body"}),e.jsx(de,{children:"Extract information from email message body"})]}),e.jsx(y,{children:e.jsx(re,{checked:r.value,onCheckedChange:r.onChange,className:T(i)})})]})})]})}const Tt=ue({businessName:V().min(1,"Business name is required"),locality:V().min(1,"Locality is required"),localName:V().optional(),govId:V().optional(),address:V().optional(),localAddress:V().optional(),phone:V().optional(),website:Ia("Invalid URL").optional().or(ka("")),generalContacts:me(rs()).optional(),billingEmails:me(rs()).optional()});function ps(s){return!s||s.__typename!=="LtdFinancialEntity"?{}:{businessName:s.name,locality:s.country,localName:s.hebrewName??void 0,govId:s.governmentId??void 0,address:s.address??void 0,phone:s.phoneNumber??void 0,website:s.website??void 0,generalContacts:s.email?.split(",").map(a=>a.trim()),billingEmails:s.clientInfo?.emails}}function Bt(s){return{name:s.businessName,country:s.locality,hebrewName:s.localName,governmentId:s.govId,address:s.address,phoneNumber:s.phone,website:s.website,email:s.generalContacts?.join(", ")}}function Et({data:s,refetchBusiness:a}){const n=we(wa,s),[t,l]=b.useState(ps(n)),{userContext:o}=b.useContext(ss),{updateBusiness:r,fetching:i}=Vs(),{updateClient:h,fetching:d}=Bs(),m=Pe({resolver:Xe(Tt),defaultValues:t}),{countries:p,fetching:u}=Ca(),[j,w]=b.useState(""),[I,B]=b.useState(""),F=m.watch("locality"),P=m.watch("address"),M=m.watch("localAddress");b.useEffect(()=>{P!==t.address&&m.setValue("address",P,{shouldDirty:!0})},[P,t.address,m]),b.useEffect(()=>{M!==t.localAddress&&m.setValue("localAddress",M,{shouldDirty:!0})},[M,t.localAddress,m]);const z=n&&"clientInfo"in n&&!!n.clientInfo,_=F===o?.context.locality,G=x=>{j.trim()&&(m.setValue("generalContacts",[...x,j.trim()],{shouldDirty:!0}),w(""))},c=(x,N)=>{m.setValue("generalContacts",x.filter((E,L)=>L!==N),{shouldDirty:!0})},O=x=>{I.trim()&&(m.setValue("billingEmails",[...x,I.trim()],{shouldDirty:!0}),B(""))},R=(x,N)=>{m.setValue("billingEmails",x.filter((E,L)=>L!==N),{shouldDirty:!0})},k=async x=>{if(!n||!o?.context.adminBusinessId)return;const N=Ze(x,m.formState.dirtyFields);if(!N)return;const E=Bt(N),L=[];Object.values(E).some(oe=>oe!=null)&&L.push(r({businessId:n.id,ownerId:o.context.adminBusinessId,fields:E})),z&&N.billingEmails&&L.push(h({businessId:n.id,fields:{emails:N.billingEmails}})),await Promise.all(L),a?.()};return b.useEffect(()=>{if(n){const x=ps(n);l(x),m.reset(x)}},[n,m]),e.jsxs(Y,{children:[e.jsxs(X,{children:[e.jsx(Q,{children:"Contact Information"}),e.jsx(J,{children:"Business contact details and address information"})]}),e.jsx(Oe,{...m,children:e.jsxs("form",{onSubmit:m.handleSubmit(k),children:[e.jsx(Z,{children:e.jsxs("div",{className:"grid gap-6 md:grid-cols-2",children:[e.jsx(g,{control:m.control,name:"businessName",render:({field:x,fieldState:N})=>e.jsxs(v,{children:[e.jsx(f,{children:"Business Name"}),e.jsx(y,{children:e.jsx(A,{...x,className:T(N)})}),e.jsx(C,{})]})}),e.jsx(g,{control:m.control,name:"locality",render:({field:x,fieldState:N})=>e.jsxs(v,{children:[e.jsx(f,{children:"Locality / Country"}),e.jsx(He,{onChange:x.onChange,data:p.map(E=>({value:E.code,label:E.name})),value:x.value,disabled:u,placeholder:"Scroll to see all options",formPart:!0,triggerProps:{className:T(N)}}),e.jsx(C,{})]})}),_&&e.jsx(g,{control:m.control,name:"localName",render:({field:x,fieldState:N})=>e.jsxs(v,{children:[e.jsx(f,{children:"Local Name"}),e.jsx(y,{children:e.jsx(A,{...x,placeholder:"Business name in local language",className:T(N)})}),e.jsx(C,{})]})}),e.jsx(g,{control:m.control,name:"govId",render:({field:x,fieldState:N})=>e.jsxs(v,{children:[e.jsx(f,{children:"Government ID"}),e.jsx(y,{children:e.jsx(A,{...x,placeholder:"Enter Government ID",className:T(N)})}),e.jsx(C,{})]})}),e.jsx(g,{control:m.control,name:"address",render:({field:x,fieldState:N})=>e.jsxs(v,{className:"md:col-span-2",children:[e.jsxs(f,{className:"flex items-center gap-2",children:[e.jsx(Ue,{className:"h-4 w-4"}),"Address"]}),e.jsx(y,{children:e.jsx(is,{...x,rows:3,placeholder:"Enter business address",className:T(N)})}),e.jsx(C,{})]})}),_&&e.jsx(g,{control:m.control,name:"localAddress",render:({field:x,fieldState:N})=>e.jsxs(v,{className:"md:col-span-2",children:[e.jsxs(f,{className:"flex items-center gap-2",children:[e.jsx(Ue,{className:"h-4 w-4"}),"Local Address"]}),e.jsx(y,{children:e.jsx(is,{...x,rows:3,placeholder:"Enter address in local language",className:T(N)})}),e.jsx(C,{})]})}),e.jsx(g,{control:m.control,name:"phone",render:({field:x,fieldState:N})=>e.jsxs(v,{children:[e.jsxs(f,{className:"flex items-center gap-2",children:[e.jsx(Es,{className:"h-4 w-4"}),"Phone"]}),e.jsx(y,{children:e.jsx(A,{...x,type:"tel",placeholder:"+1 (555) 123-4567",className:T(N)})}),e.jsx(C,{})]})}),e.jsx(g,{control:m.control,name:"website",render:({field:x,fieldState:N})=>e.jsxs(v,{children:[e.jsxs(f,{className:"flex items-center gap-2",children:[e.jsx(Aa,{className:"h-4 w-4"}),"Website"]}),e.jsx(y,{children:e.jsx(A,{...x,type:"url",placeholder:"https://example.com",className:T(N)})}),e.jsx(C,{})]})}),e.jsx(g,{control:m.control,name:"generalContacts",render:({field:x,fieldState:N})=>e.jsxs(v,{className:"md:col-span-2",children:[e.jsxs(f,{className:"flex items-center gap-2",children:[e.jsx(ze,{className:"h-4 w-4"}),"General Contacts"]}),e.jsx(y,{children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:T(N)+" flex flex-wrap gap-2 mb-2 rounded-md",children:x.value?.map((E,L)=>e.jsxs(te,{variant:"secondary",className:"gap-1 pr-1",children:[E,e.jsx("button",{type:"button",onClick:()=>c(x.value??[],L),className:"ml-1 hover:bg-muted rounded-sm p-0.5",children:e.jsx(ne,{className:"h-3 w-3"})})]},L))}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(A,{value:j,onChange:E=>w(E.target.value),onKeyDown:E=>{E.key==="Enter"&&(E.preventDefault(),G(x.value??[]))},placeholder:"Add contact email",type:"email"}),e.jsx(S,{type:"button",variant:"outline",size:"icon",disabled:!j.trim(),onClick:()=>G(x.value??[]),children:e.jsx(ae,{className:"h-4 w-4"})})]})]})}),e.jsx(C,{})]})}),z&&e.jsx(g,{control:m.control,name:"billingEmails",render:({field:x,fieldState:N})=>e.jsxs(v,{className:"md:col-span-2",children:[e.jsxs(f,{className:"flex items-center gap-2",children:[e.jsx(ze,{className:"h-4 w-4"}),"Billing Emails"]}),e.jsx(y,{children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:T(N)+" flex flex-wrap gap-2 mb-2 rounded-md",children:x.value?.map((E,L)=>e.jsxs(te,{variant:"secondary",className:"gap-1 pr-1",children:[E,e.jsx("button",{type:"button",onClick:()=>R(x.value??[],L),className:"ml-1 hover:bg-muted rounded-sm p-0.5",children:e.jsx(ne,{className:"h-3 w-3"})})]},L))}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(A,{value:I,onChange:E=>B(E.target.value),onKeyDown:E=>{E.key==="Enter"&&(E.preventDefault(),O(x.value??[]))},placeholder:"Add billing email",type:"email"}),e.jsx(S,{type:"button",variant:"outline",size:"icon",disabled:!I.trim(),onClick:()=>O(x.value??[]),children:e.jsx(ae,{className:"h-4 w-4"})})]})]})}),e.jsx(C,{})]})})]})}),e.jsx(Qe,{className:"flex justify-end border-t mt-4 pt-6",children:e.jsxs(S,{type:"submit",disabled:i||d||Object.keys(m.formState.dirtyFields).length===0,children:[e.jsx(as,{className:"h-4 w-4 mr-2"}),"Save Changes"]})})]})})]})}function Pt({businessId:s}){return e.jsxs(Y,{children:[e.jsx(X,{children:e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{children:[e.jsx(Q,{children:"Documents"}),e.jsx(J,{children:"Invoices, proformas, receipts, and other accounting documents"})]})})}),e.jsx(Z,{children:e.jsx(Da,{businessId:s,linkedDocumentIds:[],limit:1e3})})]})}function Ot({businessId:s}){const[{data:a,fetching:n}]=le({query:Sa,variables:{businessId:s}});return n?e.jsx("div",{children:"Loading ledger records..."}):e.jsxs(Y,{children:[e.jsx(X,{className:"flex w-full justify-between items-center",children:e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{children:[e.jsx(Q,{children:"Ledger Records"}),e.jsx(J,{children:"Complete ledger history for this business"})]})})}),e.jsx(Z,{children:e.jsx("div",{className:"rounded-md border",children:e.jsx(qa,{ledgerRecordsData:a?.ledgerRecordsByFinancialEntity??[]})})})]})}function Lt({businessId:s}){const[{data:a,fetching:n}]=le({query:Ta,variables:{businessId:s}});return n?e.jsx("div",{children:"Loading transactions..."}):e.jsxs(Y,{children:[e.jsx(X,{className:"flex w-full justify-between items-center",children:e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{children:[e.jsx(Q,{children:"Transactions"}),e.jsx(J,{children:"Complete transaction history for this business"})]})})}),e.jsx(Z,{children:e.jsx("div",{className:"rounded-md border",children:e.jsx(gn,{transactionsProps:a?.transactionsByFinancialEntity??[]})})})]})}function Ft({data:s,refetchBusiness:a}){const n=we(_a,s),[t,l]=Ba(),{setFiltersContext:o}=b.useContext(Ea);b.useEffect(()=>{o(null)},[o]);const r=t.get("tab")||"contact",i=m=>{l({tab:m})};if(!n)return e.jsx("div",{children:"Business not found"});const h="clientInfo"in n&&!!n.clientInfo,d="adminInfo"in n&&!!n.adminInfo;return e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx(za,{data:n}),e.jsx("main",{className:"container mx-auto px-4 py-6 md:px-6 lg:px-8 max-w-7xl",children:e.jsxs(Pa,{value:r,onValueChange:i,className:"w-full",children:[e.jsxs(Oa,{className:"grid w-full lg:grid-cols-8 sm:grid-cols-4 grid-cols-8 mb-6 h-auto gap-1 bg-muted/50 p-1",children:[e.jsxs(ee,{value:"contact",className:"flex items-center gap-2 data-[state=active]:bg-background",children:[e.jsx(De,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Contact"})]}),e.jsxs(ee,{value:"config",className:"flex items-center gap-2 data-[state=active]:bg-background",children:[e.jsx(Ps,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Config"})]}),e.jsxs(ee,{value:"charges",className:"flex items-center gap-2 data-[state=active]:bg-background",children:[e.jsx(Se,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Charges"})]}),e.jsxs(ee,{value:"transactions",className:"flex items-center gap-2 data-[state=active]:bg-background",children:[e.jsx(La,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Transactions"})]}),e.jsxs(ee,{value:"documents",className:"flex items-center gap-2 data-[state=active]:bg-background",children:[e.jsx(Fa,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Documents"})]}),e.jsxs(ee,{value:"ledger",className:"flex items-center gap-2 data-[state=active]:bg-background",children:[e.jsx(Pn,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Ledger"})]}),e.jsxs(ee,{value:"balance",className:"flex items-center gap-2 data-[state=active]:bg-background",children:[e.jsx(An,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Balance"})]}),h&&e.jsxs(e.Fragment,{children:[e.jsxs(ee,{value:"contracts",className:"flex items-center gap-2 data-[state=active]:bg-background",children:[e.jsx(Sn,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Contracts"})]}),e.jsxs(ee,{value:"integrations",className:"flex items-center gap-2 data-[state=active]:bg-background",children:[e.jsx(Ln,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Integrations"})]})]}),d&&e.jsxs(e.Fragment,{children:[e.jsxs(ee,{value:"accounts",className:"flex items-center gap-2 data-[state=active]:bg-background",children:[e.jsx(Ga,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Accounts"})]}),e.jsxs(ee,{value:"admin",className:"flex items-center gap-2 data-[state=active]:bg-background",children:[e.jsx(vs,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Admin"})]})]})]}),e.jsx(W,{value:"contact",className:"mt-0",children:e.jsx(Et,{data:n,refetchBusiness:a})}),e.jsx(W,{value:"config",className:"mt-0",children:e.jsx(wt,{data:n,refetchBusiness:a})}),e.jsx(W,{value:"charges",className:"mt-0",children:e.jsx(st,{businessId:n.id})}),e.jsx(W,{value:"transactions",className:"mt-0",children:e.jsx(Lt,{businessId:n.id})}),e.jsx(W,{value:"documents",className:"mt-0",children:e.jsx(Pt,{businessId:n.id})}),e.jsx(W,{value:"ledger",className:"mt-0",children:e.jsx(Ot,{businessId:n.id})}),e.jsx(W,{value:"balance",className:"mt-0",children:e.jsx(et,{businessId:n.id})}),h&&e.jsxs(e.Fragment,{children:[e.jsx(W,{value:"contracts",className:"mt-0",children:e.jsx(ft,{clientId:n.id})}),e.jsx(W,{value:"integrations",className:"mt-0",children:e.jsx(Nt,{data:n})}),e.jsx(W,{value:"charts",className:"mt-0",children:e.jsx(gt,{})})]}),d&&e.jsxs(e.Fragment,{children:[e.jsx(W,{value:"accounts",className:"mt-0",children:e.jsx(Zn,{adminId:n.id})}),e.jsx(W,{value:"admin",className:"mt-0",children:e.jsx(zn,{data:n})})]})]})})]})}const li=()=>{const{businessId:s}=Ma();let a;try{a=Ra()}catch{}const[{data:n,fetching:t},l]=le({query:Va,pause:!s||!!a,variables:{businessId:s??""}}),o=a||n;return!a&&t&&!o?.business?e.jsx(gs,{}):!s||!o?.business?e.jsx("div",{children:"Business not found"}):e.jsx(Ft,{data:o.business,refetchBusiness:async()=>l()})};export{li as BusinessScreen};
|
|
1
|
+
import{v as ie,w as js,u as le,S as qs,r as C,j as e,D as Ke,x as Ye,E as Gs,c as gs,g as Be,t as K,i as Ee,U as Ws,y as Pe,z as Xe,G as we,H as be,J as Y,K as X,N as vs,O as Q,Q as J,V as Oe,W as Z,X as ce,Y as g,Z as v,_ as f,$ as y,I as A,a0 as T,a1 as b,a2 as Ce,B as S,a3 as ae,a4 as ne,a5 as Qe,a6 as Ks,a7 as ue,a8 as Je,a9 as Ze,aa as me,ab as M,ac as es,ad as Ys,ae as $,af as Xs,ag as te,ah as Qs,ai as pe,R as fs,aj as Js,ak as Zs,al as ys,am as Ns,an as bs,ao as Cs,ap as As,aq as ws,ar as Is,as as ks,at as re,au as Ds,av as Ss,aw as Ts,ax as ea,ay as Bs,az as $e,aA as sa,aB as aa,aC as ss,aD as na,P as ta,aE as ia,aF as U,aG as ns,aH as Le,aI as ra,aJ as ca,aK as la,aL as oa,aM as Es,aN as da,aO as D,aP as ze,aQ as Ps,aR as Ue,aS as ts,aT as ma,aU as ua,aV as Os,aW as xa,aX as ha,aY as pa,aZ as de,a_ as ja,a$ as ga,b0 as va,b1 as He,b2 as fa,b3 as ya,b4 as Na,b5 as ba,b6 as Ca,b7 as is,b8 as Aa,b9 as wa,ba as Ia,bb as rs,bc as ka,bd as Da,be as Sa,bf as Ta,bg as Ba,F as Ea,bh as Pa,bi as Oa,bj as ee,bk as La,bl as Fa,bm as W,bn as _a,a as Ma,b as Ra,bo as Va}from"./index-3R_zL83W.js";import{S as as}from"./save-BKXGqFkY.js";import{B as De}from"./building-2-Bg-rF-On.js";import{B as $a}from"./business-extended-info-BzvYZDrX.js";import{B as za}from"./business-header-D4uSFuTz.js";import{S as Ua,C as Ha,L as qa,W as Ga}from"./charges-table-DAgbJYqd.js";import{i as Wa,D as Ka,f as Ya,E as Xa,L as Fe,a as Ie,C as Qa,A as Ja,b as ve,c as Za,d as qe,h as en,e as sn,g as Ls,u as an,G as nn,j as cs,k as tn,X as Fs,Y as _s,l as rn,m as cn,R as ln,n as on,o as dn,p as mn}from"./chart-BwU_CSjE.js";import{M as un,s as xn,a as hn}from"./modify-contract-dialog-Cx5gt7hE.js";import{P as pn}from"./pencil-Bl19crq5.js";import{E as jn,T as gn}from"./index-3QXfdVxu.js";import{A as vn,a as ke,b as _e,c as ls}from"./accordion-DQeKF8al.js";import"./data-table-column-header-C23SEs2k.js";import"./eye-off-B09TfzwY.js";import"./download-csv-button-DDfbg2Ju.js";import"./toggle-expansion-button-C91T0tTd.js";import"./panel-top-open-DNq_YeJ3.js";import"./Table-BD-Y5pOR.js";import"./summary-dKO6hc4g.js";import"./list-plus-BYDB6Bug.js";import"./deposits-transactions-table-DkCO1YMQ.js";import"./Checkbox-DUyxts6I.js";import"./sequential-CAnleQny.js";import"./similar-transactions-modal-DTnZQkpm.js";import"./addDays-BKzA2JVL.js";import"./tooltip-h3zSyeCb.js";const fn=[["path",{d:"M3.85 8.62a4 4 0 0 1 4.78-4.77 4 4 0 0 1 6.74 0 4 4 0 0 1 4.78 4.78 4 4 0 0 1 0 6.74 4 4 0 0 1-4.77 4.78 4 4 0 0 1-6.75 0 4 4 0 0 1-4.78-4.77 4 4 0 0 1 0-6.76Z",key:"3c2336"}],["path",{d:"M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3",key:"1u773s"}],["line",{x1:"12",x2:"12.01",y1:"17",y2:"17",key:"io3f8k"}]],yn=ie("badge-question-mark",fn);const Nn=[["path",{d:"M11.767 19.089c4.924.868 6.14-6.025 1.216-6.894m-1.216 6.894L5.86 18.047m5.908 1.042-.347 1.97m1.563-8.864c4.924.869 6.14-6.025 1.215-6.893m-1.215 6.893-3.94-.694m5.155-6.2L8.29 4.26m5.908 1.042.348-1.97M7.48 20.364l3.126-17.727",key:"yr8idg"}]],bn=ie("bitcoin",Nn);const Cn=[["path",{d:"M3 3v16a2 2 0 0 0 2 2h16",key:"c24i48"}],["path",{d:"m19 9-5 5-4-4-3 3",key:"2osh9i"}]],An=ie("chart-line",Cn);const wn=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]],Me=ie("circle-check",wn);const In=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"9",x2:"15",y1:"15",y2:"9",key:"1dfufj"}]],os=ie("circle-slash",In);const kn=[["line",{x1:"12",x2:"12",y1:"2",y2:"22",key:"7eqyqh"}],["path",{d:"M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6",key:"1b0p4s"}]],Se=ie("dollar-sign",kn);const Dn=[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"m9 15 2 2 4-4",key:"1grp1n"}]],Sn=ie("file-check",Dn);const Tn=[["path",{d:"M3 7V5a2 2 0 0 1 2-2h2",key:"aa7l1z"}],["path",{d:"M17 3h2a2 2 0 0 1 2 2v2",key:"4qcy5o"}],["path",{d:"M21 17v2a2 2 0 0 1-2 2h-2",key:"6vwrx8"}],["path",{d:"M7 21H5a2 2 0 0 1-2-2v-2",key:"ioqczr"}],["rect",{width:"10",height:"8",x:"7",y:"8",rx:"1",key:"vys8me"}]],Bn=ie("fullscreen",Tn);const En=[["path",{d:"M2 6h4",key:"aawbzj"}],["path",{d:"M2 10h4",key:"l0bgd4"}],["path",{d:"M2 14h4",key:"1gsvsf"}],["path",{d:"M2 18h4",key:"1bu2t1"}],["rect",{width:"16",height:"20",x:"4",y:"2",rx:"2",key:"1nb95v"}],["path",{d:"M16 2v20",key:"rotuqe"}]],Pn=ie("notebook",En);const On=[["path",{d:"M12 22v-5",key:"1ega77"}],["path",{d:"M15 8V2",key:"18g5xt"}],["path",{d:"M17 8a1 1 0 0 1 1 1v4a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V9a1 1 0 0 1 1-1z",key:"1xoxul"}],["path",{d:"M9 8V2",key:"14iosj"}]],Ln=ie("plug",On);function Fn(s){return js(s,"yyyy-MM-dd")}function _n({businessId:s,tagIds:a,description:n,open:t,onOpenChange:l,onClose:o}){const[{data:r,fetching:i},h]=le({pause:!0,query:qs,variables:{businessId:s,tagsDifferentThan:a?a.map(p=>p.id):void 0,descriptionDifferentThan:n}});C.useEffect(()=>{t&&(a||n)&&!r&&h()},[t,a,n,h,r]);const d=C.useCallback(p=>{l(p),t&&!p&&o?.()},[l,o,t]),m=C.useMemo(()=>t&&(!!a||!!n)&&r&&r?.similarChargesByBusiness.length>0,[t,a,n,r]);return e.jsx(Ke,{open:m,onOpenChange:d,children:e.jsx(Ye,{className:"overflow-scroll max-h-screen w-full sm:max-w-[640px] md:max-w-[768px] lg:max-w-[900px]",onClick:p=>p.stopPropagation(),children:e.jsx(Gs,{fallback:e.jsx("div",{children:"Error fetching similar charges"}),children:i?e.jsx(gs,{}):a||n?e.jsx(Ua,{data:r?.similarChargesByBusiness??[],tagIds:a,description:n,onOpenChange:d,title:"Similar Charges by Business"}):null})})})}const Mn="updateAdminBusiness",Rn=()=>{const[{fetching:s},a]=Be(Ws),n=C.useCallback(async t=>{const l=`Error updating admin business ID [${t.adminBusinessId}]`,o=`${Mn}-${t.adminBusinessId}`;K.loading("Updating admin business",{id:o});try{const r=await a(t),i=Ee(r,l,o,"updateAdminBusiness");if(i)return K.success("Success",{id:o,description:"Admin Business Updated"}),i.updateAdminBusiness}catch(r){console.error(`${l}: ${r}`),K.error("Error",{id:o,description:l,duration:1e5,closeButton:!0})}},[a]);return{fetching:s,updateAdminBusiness:n}},Re=ue({year:es().min(2e3).max(2100),id:M().min(1,{message:"ID is required"})}),Vn=ue({registrationDate:M().min(1,{message:"Business Registration Start Date is required"}),withholdingTaxAnnualIds:me(Re),withholdingTaxCompanyId:M().min(1,{message:"Withholding Tax Company ID is required"}),socialSecurityEmployerIds:me(Re),socialSecurityDeductionsId:M().min(1,{message:"Social Security Deductions ID is required"}),taxAdvancesAnnualIds:me(Re),taxAdvancesRates:me(ue({date:Ys(),rate:es().min(0,{message:"Rate must be at least 0"}).max(100,{message:"Rate must be at most 100"})}))}),fe={WITHHOLDING_TAX:"https://secapp.taxes.gov.il/NikPay/StartPage.aspx#/Home",TAX_ADVANCES:"https://secapp.taxes.gov.il/gmftashmh/main/entrance",SOCIAL_SECURITY:"https://b2b.btl.gov.il/BTL.ILG.Payments/ChovDochMaasikInfo.aspx",VAT:"https://secapp.taxes.gov.il/emdvhmfrt/wLogOnMenu.aspx"},ye=({href:s,children:a})=>e.jsxs("h3",{className:"flex flex-row gap-2 text-sm font-semibold text-foreground md:col-span-2",children:[e.jsx("a",{href:s,target:"_blank",rel:"noreferrer",onClick:n=>n.stopPropagation(),className:"inline-flex items-center font-semibold",children:e.jsx(Je,{size:12})}),e.jsx("span",{children:a})]});function ds(s){return!s||s.__typename!=="LtdFinancialEntity"||!s.adminInfo?{}:{registrationDate:s.adminInfo.registrationDate,withholdingTaxAnnualIds:s.adminInfo.withholdingTaxAnnualIds.sort((a,n)=>n.year-a.year),withholdingTaxCompanyId:s.adminInfo.withholdingTaxCompanyId??void 0,socialSecurityEmployerIds:s.adminInfo.socialSecurityEmployerIds.sort((a,n)=>n.year-a.year),socialSecurityDeductionsId:s.adminInfo.socialSecurityDeductionsId??void 0,taxAdvancesAnnualIds:s.adminInfo.taxAdvancesAnnualIds.sort((a,n)=>n.year-a.year),taxAdvancesRates:s.adminInfo.taxAdvancesRates?.map(a=>({date:a.date,rate:a.rate*100}))}}function $n(s){return{registrationDate:s.registrationDate?Fn(new Date(s.registrationDate)):void 0,withholdingTaxAnnualIds:s.withholdingTaxAnnualIds,withholdingTaxCompanyId:s.withholdingTaxCompanyId,socialSecurityEmployerIds:s.socialSecurityEmployerIds,taxAdvancesRates:s.taxAdvancesRates?.map(a=>({date:a.date,rate:a.rate/100})),taxAdvancesAnnualIds:s.taxAdvancesAnnualIds}}function zn({data:s,refetchBusiness:a}){const n=we(Ks,s),[t,l]=C.useState(ds(n)),{updateAdminBusiness:o,fetching:r}=Rn(),i=Pe({resolver:Xe(Vn),defaultValues:t}),h=async k=>{if(!n)return;const x=Ze(k,i.formState.dirtyFields);if(!x)return;const N=$n(x);await o({adminBusinessId:n.id,fields:N}),a?.()};C.useEffect(()=>{if(n){const k=ds(n);l(k),i.reset(k)}},[n,i]);const{fields:d,append:m,remove:p}=be({control:i.control,name:"taxAdvancesAnnualIds"}),{fields:u,append:j,remove:w}=be({control:i.control,name:"withholdingTaxAnnualIds"}),{fields:I,append:B,remove:F}=be({control:i.control,name:"socialSecurityEmployerIds"}),P={withholdingTaxAnnualIds:{append:j,remove:w},taxAdvancesAnnualIds:{append:m,remove:p},socialSecurityEmployerIds:{append:B,remove:F}},R=k=>{P[k].append({year:new Date().getFullYear(),id:""})},z=(k,x)=>{P[k].remove(x)},{fields:_,append:G,remove:c}=be({control:i.control,name:"taxAdvancesRates"}),O=()=>{G({date:js(new Date,"yyyy-MM-dd"),rate:0})},V=k=>{c(k)};return e.jsxs(Y,{children:[e.jsxs(X,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(vs,{className:"h-5 w-5 text-primary"}),e.jsx(Q,{children:"Admin Business Configuration"})]}),e.jsx(J,{children:"Tax and registration information for the business operating this application"})]}),e.jsx(Oe,{...i,children:e.jsxs("form",{onSubmit:i.handleSubmit(h),className:"space-y-6",children:[e.jsx(Z,{children:e.jsxs("div",{className:"grid gap-6 md:grid-cols-2",children:[e.jsx(ye,{href:fe.VAT,children:"VAT"}),e.jsx(ce,{className:"md:col-span-2"}),e.jsx(ye,{href:fe.TAX_ADVANCES,children:"Tax Advances"}),e.jsx(ce,{className:"md:col-span-2"}),e.jsx(ye,{href:fe.WITHHOLDING_TAX,children:"Withholding Tax"}),e.jsx(g,{control:i.control,name:"withholdingTaxCompanyId",render:({field:k,fieldState:x})=>e.jsxs(v,{children:[e.jsx(f,{children:"Company Tax ID"}),e.jsx(y,{children:e.jsx(A,{placeholder:"Enter company ID",...k,className:T(x)})}),e.jsx(b,{})]})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(Ce,{children:"Annual IDs"}),e.jsx(S,{type:"button",variant:"outline",size:"sm",onClick:()=>R("withholdingTaxAnnualIds"),children:e.jsx(ae,{className:"size-4"})})]}),e.jsx("div",{className:"space-y-3",children:u.map((k,x)=>e.jsxs("div",{className:"flex gap-2 items-start",children:[e.jsxs("div",{className:"flex-1 grid grid-cols-2 gap-2",children:[e.jsx(A,{placeholder:"Year",type:"number",...i.register(`withholdingTaxAnnualIds.${x}.year`,{valueAsNumber:!0})}),e.jsx(A,{placeholder:"ID",...i.register(`withholdingTaxAnnualIds.${x}.id`)})]}),e.jsx(S,{type:"button",variant:"ghost",size:"icon",onClick:()=>z("withholdingTaxAnnualIds",x),children:e.jsx(ne,{className:"size-4"})})]},k.id))})]}),e.jsx(ce,{className:"md:col-span-2"}),e.jsx(ye,{href:fe.TAX_ADVANCES,children:"Tax Advances"}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(Ce,{children:"Annual IDs"}),e.jsx(S,{type:"button",variant:"outline",size:"sm",onClick:()=>R("taxAdvancesAnnualIds"),children:e.jsx(ae,{className:"size-4"})})]}),e.jsx("div",{className:"space-y-3",children:d.map((k,x)=>e.jsxs("div",{className:"flex gap-2 items-start",children:[e.jsxs("div",{className:"flex-1 grid grid-cols-2 gap-2",children:[e.jsx(A,{placeholder:"Year",type:"number",...i.register(`taxAdvancesAnnualIds.${x}.year`,{valueAsNumber:!0})}),e.jsx(A,{placeholder:"ID",...i.register(`taxAdvancesAnnualIds.${x}.id`)})]}),e.jsx(S,{type:"button",variant:"ghost",size:"icon",onClick:()=>z("taxAdvancesAnnualIds",x),children:e.jsx(ne,{className:"size-4"})})]},k.id))})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(Ce,{children:"Rates (%)"}),e.jsx(S,{type:"button",variant:"outline",size:"sm",onClick:O,children:e.jsx(ae,{className:"size-4"})})]}),e.jsx("div",{className:"space-y-3",children:_.map((k,x)=>e.jsxs("div",{className:"flex gap-2 items-start",children:[e.jsxs("div",{className:"flex-1 grid grid-cols-2 gap-2",children:[e.jsx(A,{placeholder:"Date",type:"date",...i.register(`taxAdvancesRates.${x}.date`)}),e.jsx(A,{placeholder:"Rate",...i.register(`taxAdvancesRates.${x}.rate`,{valueAsNumber:!0})})]}),e.jsx(S,{type:"button",variant:"ghost",size:"icon",onClick:()=>V(x),children:e.jsx(ne,{className:"size-4"})})]},k.id))})]}),e.jsx(ce,{className:"md:col-span-2"}),e.jsx(ye,{href:fe.SOCIAL_SECURITY,children:"Social Security"}),e.jsx(g,{control:i.control,name:"socialSecurityDeductionsId",render:({field:k,fieldState:x})=>e.jsxs(v,{children:[e.jsx(f,{children:"Deductions ID"}),e.jsx(y,{children:e.jsx(A,{placeholder:"Enter deductions ID",...k,className:T(x)})}),e.jsx(b,{})]})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(Ce,{children:"Annual Employer IDs"}),e.jsx(S,{type:"button",variant:"outline",size:"sm",onClick:()=>R("socialSecurityEmployerIds"),children:e.jsx(ae,{className:"size-4"})})]}),e.jsx("div",{className:"space-y-3",children:I.map((k,x)=>e.jsxs("div",{className:"flex gap-2 items-start",children:[e.jsxs("div",{className:"flex-1 grid grid-cols-2 gap-2",children:[e.jsx(A,{placeholder:"Year",type:"number",...i.register(`socialSecurityEmployerIds.${x}.year`,{valueAsNumber:!0})}),e.jsx(A,{placeholder:"ID",...i.register(`socialSecurityEmployerIds.${x}.id`)})]}),e.jsx(S,{type:"button",variant:"ghost",size:"icon",onClick:()=>z("socialSecurityEmployerIds",x),children:e.jsx(ne,{className:"size-4"})})]},k.id))})]}),e.jsx(ce,{className:"md:col-span-2"}),e.jsx(g,{control:i.control,name:"registrationDate",render:({field:k,fieldState:x})=>e.jsxs(v,{children:[e.jsx(f,{children:"Business Registration Start Date"}),e.jsx(y,{children:e.jsx(A,{type:"date",...k,className:T(x)})}),e.jsx(b,{})]})})]})}),e.jsx(Qe,{className:"flex justify-end border-t mt-4 pt-6",children:e.jsxs(S,{type:"submit",disabled:r||Object.keys(i.formState.dirtyFields).length===0||!i.formState.isValid,children:[e.jsx(as,{className:"h-4 w-4"}),"Save Changes"]})})]})})]})}const Un=s=>{switch(s){case $.BankAccount:return e.jsx(De,{className:"h-5 w-5"});case $.CreditCard:return e.jsx(Xs,{className:"h-5 w-5"});case $.CryptoWallet:return e.jsx(bn,{className:"h-5 w-5"});case $.BankDepositAccount:return e.jsx(De,{className:"h-5 w-5"});case $.ForeignSecurities:return e.jsx(De,{className:"h-5 w-5"});default:return e.jsx(yn,{className:"h-5 w-5"})}},Ms=s=>{switch(s){case $.BankAccount:return"Bank Account";case $.CreditCard:return"Credit Card";case $.CryptoWallet:return"Crypto Wallet";case $.BankDepositAccount:return"Bank Deposit Account";case $.ForeignSecurities:return"Foreign Securities";default:return"Unknown Account Type"}};function Hn({account:s,handleOpenModal:a}){return e.jsxs(Y,{children:[e.jsx(X,{children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10 text-primary",children:Un(s.type)}),e.jsxs("div",{children:[e.jsxs(Q,{className:"text-lg",children:[s.name,s.name===s.number?"":` (${s.number})`]}),e.jsxs(J,{className:"flex items-center gap-2 mt-1",children:[e.jsx(te,{variant:"outline",children:Ms(s.type)}),!s.isBusiness&&e.jsx(te,{variant:"secondary",children:"Private"})]})]})]}),e.jsx("div",{className:"flex gap-1",children:e.jsx(S,{variant:"ghost",size:"sm",onClick:()=>a(s),"aria-label":`Edit account ${s.name}`,children:e.jsx(Qs,{className:"h-4 w-4","aria-hidden":"true"})})})]})}),e.jsxs(Z,{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium mb-2",children:"Currencies & Tax Categories"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:s.currencies?.map(n=>e.jsx(pe,{to:fs.TAX_CATEGORIES,target:"_blank",rel:"noreferrer",onClick:t=>t.stopPropagation(),children:e.jsxs(te,{variant:"secondary",className:"text-xs",children:[n.currency," → ",n.taxCategory.name]})},n.currency))})]}),s.type===$.BankAccount&&e.jsxs("div",{className:"border-t pt-4",children:[e.jsx("h4",{className:"text-sm font-medium mb-3",children:"Bank Details"}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-3 text-sm",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"Bank Number:"}),e.jsx("p",{className:"font-medium",children:s.bankNumber})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"Branch Number:"}),e.jsx("p",{className:"font-medium",children:s.branchNumber})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"Extended Bank Number:"}),e.jsx("p",{className:"font-medium",children:s.extendedBankNumber})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"IBAN:"}),e.jsx("p",{className:"font-medium",children:s.iban})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"Party Preferred Indication:"}),e.jsx("p",{className:"font-medium",children:s.partyPreferredIndication})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"Party Account Involvement:"}),e.jsx("p",{className:"font-medium",children:s.partyAccountInvolvementCode})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"Account Deal Date:"}),e.jsx("p",{className:"font-medium",children:s.accountDealDate})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"Account Update Date:"}),e.jsx("p",{className:"font-medium",children:s.accountUpdateDate})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"Meteg Dora Net:"}),e.jsx("p",{className:"font-medium",children:s.metegDoarNet})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"Kod Harshaot Peilut:"}),e.jsx("p",{className:"font-medium",children:s.kodHarshaatPeilut})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"Closing Reason Code:"}),e.jsx("p",{className:"font-medium",children:s.accountClosingReasonCode})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"Agreement Opening Date:"}),e.jsx("p",{className:"font-medium",children:s.accountAgreementOpeningDate})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"Branch Type Code:"}),e.jsx("p",{className:"font-medium",children:s.branchTypeCode})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"Mymail Entitlement:"}),e.jsx("p",{className:"font-medium",children:s.mymailEntitlementSwitch})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"Service Authorization:"}),e.jsx("p",{className:"font-medium",children:s.serviceAuthorizationDesc})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"Product Label:"}),e.jsx("p",{className:"font-medium",children:s.productLabel})]})]})]})]})]})}const qn="createFinancialAccount",Gn=()=>{const[{fetching:s},a]=Be(Js),n=C.useCallback(async t=>{const l=`Error creating new account "${t.input.name}"`,o=`${qn}-${t.input.name}`;K.loading("Creating account",{id:o});try{const r=await a(t);Ee(r,l,o)&&K.success("Success",{id:o,description:`Financial Account ${t.input.name} was successfully created`})}catch(r){console.error(`${l}: ${r}`),K.error("Error",{id:o,description:l,duration:1e5,closeButton:!0})}},[a]);return{creating:s,createFinancialAccount:n}},Wn="updateFinancialAccount",Kn=()=>{const[{fetching:s},a]=Be(Zs),n=C.useCallback(async t=>{const l=`Error updating financial account ID [${t.financialAccountId}]`,o=`${Wn}-${t.financialAccountId}`;K.loading("Updating financial account",{id:o});try{const r=await a(t),i=Ee(r,l,o,"updateFinancialAccount");if(i)return K.success("Success",{id:o,description:"Financial account updated"}),i.updateFinancialAccount}catch(r){console.error(`${l}: ${r}`),K.error("Error",{id:o,description:l,duration:1e5,closeButton:!0})}},[a]);return{updating:s,updateFinancialAccount:n}},Yn=ue({currency:Ts(Object.values(Bs),"Currency is required"),taxCategory:ue({id:sa("Tax category ID is required"),name:M().min(1,"Tax category name is required")})}),H=Ss(s=>{if(s===""||s===void 0||s===null)return;const a=typeof s=="string"?parseInt(s,10):s;return Number.isNaN(a)?void 0:a},es().int().optional()),Xn=ue({name:M().min(1,"Name is required"),number:M().min(1,"Account number is required"),isBusiness:ea().default(!1).optional(),type:Ts(Object.values($),"Account type is required"),currencies:me(Yn),bankNumber:H,branchNumber:H,iban:Ss(s=>s===""?void 0:s,M().optional()),extendedBankNumber:H,partyPreferredIndication:H,partyAccountInvolvementCode:H,accountDealDate:H,accountUpdateDate:H,metegDoarNet:H,kodHarshaatPeilut:H,accountClosingReasonCode:H,accountAgreementOpeningDate:H,serviceAuthorizationDesc:M().optional(),branchTypeCode:H,mymailEntitlementSwitch:H,productLabel:M().optional()}),Qn=C.forwardRef(function({ownerId:a,onDone:n},t){const[l,o]=C.useState(!1),[r,i]=C.useState(null),{createFinancialAccount:h,creating:d}=Gn(),{updateFinancialAccount:m,updating:p}=Kn(),u=Pe({resolver:Xe(Xn),defaultValues:{name:"",number:"",isBusiness:!1,type:$.BankAccount,currencies:[],bankNumber:void 0,branchNumber:void 0,iban:void 0,extendedBankNumber:void 0,partyPreferredIndication:void 0,partyAccountInvolvementCode:void 0,accountDealDate:void 0,accountUpdateDate:void 0,metegDoarNet:void 0,kodHarshaatPeilut:void 0,accountClosingReasonCode:void 0,accountAgreementOpeningDate:void 0,serviceAuthorizationDesc:void 0,branchTypeCode:void 0,mymailEntitlementSwitch:void 0,productLabel:void 0},mode:"onBlur"}),{control:j,handleSubmit:w,watch:I,reset:B}=u,F=c=>{c?(i(c),B(c)):(i(null),B()),o(!0)};C.useImperativeHandle(t,()=>({open:F}));const P=be({control:j,name:"currencies"}),R=()=>{o(!1),i(null),B()},z=async c=>{try{const O=c.isBusiness?$e.Business:$e.Private,V=c.type===$.BankAccount&&c.bankNumber!==void 0&&c.branchNumber!==void 0?{bankNumber:c.bankNumber,branchNumber:c.branchNumber,...c.iban!==void 0&&{iban:c.iban},...c.extendedBankNumber!==void 0&&{extendedBankNumber:c.extendedBankNumber},...c.partyPreferredIndication!==void 0&&{partyPreferredIndication:c.partyPreferredIndication},...c.partyAccountInvolvementCode!==void 0&&{partyAccountInvolvementCode:c.partyAccountInvolvementCode},...c.accountDealDate!==void 0&&{accountDealDate:c.accountDealDate},...c.accountUpdateDate!==void 0&&{accountUpdateDate:c.accountUpdateDate},...c.metegDoarNet!==void 0&&{metegDoarNet:c.metegDoarNet},...c.kodHarshaatPeilut!==void 0&&{kodHarshaatPeilut:c.kodHarshaatPeilut},...c.accountClosingReasonCode!==void 0&&{accountClosingReasonCode:c.accountClosingReasonCode},...c.accountAgreementOpeningDate!==void 0&&{accountAgreementOpeningDate:c.accountAgreementOpeningDate},...c.serviceAuthorizationDesc!==void 0&&{serviceAuthorizationDesc:c.serviceAuthorizationDesc},...c.branchTypeCode!==void 0&&{branchTypeCode:c.branchTypeCode},...c.mymailEntitlementSwitch!==void 0&&{mymailEntitlementSwitch:c.mymailEntitlementSwitch},...c.productLabel!==void 0&&{productLabel:c.productLabel}}:void 0;r?await m({financialAccountId:r.id,fields:{name:c.name,number:c.number,type:c.type,privateOrBusiness:O,bankAccountDetails:V}}):await h({input:{name:c.name,number:c.number,ownerId:a,type:c.type,privateOrBusiness:O,bankAccountDetails:V}}),R(),n?.()}catch{}},_=()=>{P.append({currency:Bs.Usd,taxCategory:{id:"",name:""}})},G=c=>{P.remove(c)};return e.jsx(Ke,{open:l,onOpenChange:o,children:e.jsxs(Ye,{className:"max-w-4xl max-h-[90vh] overflow-y-auto",children:[e.jsxs(ys,{children:[e.jsx(Ns,{children:r?"Edit Account":"New Account"}),e.jsx(bs,{children:r?"Update account details and settings":"Add a new financial account"})]}),e.jsx(Oe,{...u,children:e.jsxs("form",{onSubmit:w(z),className:"space-y-6",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-sm font-semibold",children:"Basic Information"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx(g,{control:j,name:"name",render:({field:c})=>e.jsxs(v,{className:"space-y-2",children:[e.jsx(f,{children:"Name *"}),e.jsx(y,{children:e.jsx(A,{...c})}),e.jsx(b,{})]})}),e.jsx(g,{control:j,name:"number",render:({field:c})=>e.jsxs(v,{className:"space-y-2",children:[e.jsx(f,{children:"Account Number *"}),e.jsx(y,{children:e.jsx(A,{...c})}),e.jsx(b,{})]})}),e.jsx(g,{control:j,name:"type",render:({field:c})=>e.jsxs(v,{className:"space-y-2",children:[e.jsx(f,{children:"Account Type *"}),e.jsxs(Cs,{value:c.value,onValueChange:c.onChange,children:[e.jsx(As,{id:"type",children:e.jsx(ws,{})}),e.jsx(Is,{children:Object.values($).map(O=>e.jsx(ks,{value:O,children:Ms(O)},O))})]}),e.jsx(b,{})]})}),e.jsx(g,{control:j,name:"isBusiness",render:({field:c})=>e.jsxs(v,{className:"flex items-center space-x-2",children:[e.jsx(y,{children:e.jsx(re,{id:"isBusiness",checked:c.value,onCheckedChange:c.onChange})}),e.jsx(f,{children:"Business Account"})]})})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-sm font-semibold",children:"Currencies & Tax Categories"}),e.jsxs(S,{type:"button",variant:"outline",size:"sm",onClick:_,"aria-label":"Add currency row",children:[e.jsx(ae,{className:"h-4 w-4 mr-2","aria-hidden":"true"}),"Add Currency"]})]}),e.jsx("div",{className:"space-y-3",children:P.fields.map((c,O)=>e.jsxs("div",{className:"flex gap-2 items-start",children:[e.jsxs("div",{className:"flex-1 grid grid-cols-2 gap-2",children:[e.jsx(g,{control:j,name:`currencies.${O}.currency`,render:({field:V})=>e.jsxs(v,{children:[e.jsx(y,{children:e.jsx(A,{placeholder:"Currency (e.g., ILS, USD)",...V})}),e.jsx(b,{})]})}),e.jsx(g,{control:j,name:`currencies.${O}.taxCategory.id`,render:({field:V})=>e.jsxs(v,{children:[e.jsx(y,{children:e.jsx(A,{placeholder:"Tax Category ID",...V})}),e.jsx(b,{})]})})]}),e.jsx(S,{type:"button",variant:"ghost",size:"icon",onClick:()=>G(O),"aria-label":`Remove currency ${I(`currencies.${O}.currency`)||""}`,children:e.jsx(ne,{className:"h-4 w-4","aria-hidden":"true"})})]},c.id))})]}),I("type")===$.BankAccount&&e.jsxs("div",{className:"space-y-4 border-t pt-4",children:[e.jsx("h3",{className:"text-sm font-semibold",children:"Bank-Specific Details"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:[e.jsx(g,{control:j,name:"bankNumber",render:({field:c})=>e.jsxs(v,{className:"space-y-2",children:[e.jsx(f,{children:"Bank Number"}),e.jsx(y,{children:e.jsx(A,{inputMode:"numeric",value:c.value??"",onChange:c.onChange})}),e.jsx(b,{})]})}),e.jsx(g,{control:j,name:"branchNumber",render:({field:c})=>e.jsxs(v,{className:"space-y-2",children:[e.jsx(f,{children:"Branch Number"}),e.jsx(y,{children:e.jsx(A,{inputMode:"numeric",value:c.value??"",onChange:c.onChange})}),e.jsx(b,{})]})}),e.jsx(g,{control:j,name:"iban",render:({field:c})=>e.jsxs(v,{className:"space-y-2",children:[e.jsx(f,{children:"IBAN"}),e.jsx(y,{children:e.jsx(A,{value:c.value??"",onChange:c.onChange})}),e.jsx(b,{})]})}),e.jsx(g,{control:j,name:"extendedBankNumber",render:({field:c})=>e.jsxs(v,{className:"space-y-2",children:[e.jsx(f,{children:"Extended Bank Number"}),e.jsx(y,{children:e.jsx(A,{inputMode:"numeric",value:c.value??"",onChange:c.onChange})}),e.jsx(b,{})]})}),e.jsx(g,{control:j,name:"partyPreferredIndication",render:({field:c})=>e.jsxs(v,{className:"space-y-2",children:[e.jsx(f,{children:"Party Preferred Indication"}),e.jsx(y,{children:e.jsx(A,{inputMode:"numeric",value:c.value??"",onChange:c.onChange})}),e.jsx(b,{})]})}),e.jsx(g,{control:j,name:"partyAccountInvolvementCode",render:({field:c})=>e.jsxs(v,{className:"space-y-2",children:[e.jsx(f,{children:"Party Account Involvement Code"}),e.jsx(y,{children:e.jsx(A,{inputMode:"numeric",value:c.value??"",onChange:c.onChange})}),e.jsx(b,{})]})}),e.jsx(g,{control:j,name:"accountDealDate",render:({field:c})=>e.jsxs(v,{className:"space-y-2",children:[e.jsx(f,{children:"Account Deal Date"}),e.jsx(y,{children:e.jsx(A,{inputMode:"numeric",placeholder:"YYYYMMDD",value:c.value??"",onChange:c.onChange})}),e.jsx(b,{})]})}),e.jsx(g,{control:j,name:"accountUpdateDate",render:({field:c})=>e.jsxs(v,{className:"space-y-2",children:[e.jsx(f,{children:"Account Update Date"}),e.jsx(y,{children:e.jsx(A,{inputMode:"numeric",placeholder:"YYYYMMDD",value:c.value??"",onChange:c.onChange})}),e.jsx(b,{})]})}),e.jsx(g,{control:j,name:"metegDoarNet",render:({field:c})=>e.jsxs(v,{className:"space-y-2",children:[e.jsx(f,{children:"Meteg Dora Net"}),e.jsx(y,{children:e.jsx(A,{inputMode:"numeric",value:c.value??"",onChange:c.onChange})}),e.jsx(b,{})]})}),e.jsx(g,{control:j,name:"kodHarshaatPeilut",render:({field:c})=>e.jsxs(v,{className:"space-y-2",children:[e.jsx(f,{children:"Kod Harshaot Peilut"}),e.jsx(y,{children:e.jsx(A,{inputMode:"numeric",value:c.value??"",onChange:c.onChange})}),e.jsx(b,{})]})}),e.jsx(g,{control:j,name:"accountClosingReasonCode",render:({field:c})=>e.jsxs(v,{className:"space-y-2",children:[e.jsx(f,{children:"Account Closing Reason Code"}),e.jsx(y,{children:e.jsx(A,{inputMode:"numeric",value:c.value??"",onChange:c.onChange})}),e.jsx(b,{})]})}),e.jsx(g,{control:j,name:"accountAgreementOpeningDate",render:({field:c})=>e.jsxs(v,{className:"space-y-2",children:[e.jsx(f,{children:"Account Agreement Opening Date"}),e.jsx(y,{children:e.jsx(A,{inputMode:"numeric",placeholder:"YYYYMMDD",value:c.value??"",onChange:c.onChange})}),e.jsx(b,{})]})}),e.jsx(g,{control:j,name:"branchTypeCode",render:({field:c})=>e.jsxs(v,{className:"space-y-2",children:[e.jsx(f,{children:"Branch Type Code"}),e.jsx(y,{children:e.jsx(A,{inputMode:"numeric",value:c.value??"",onChange:c.onChange})}),e.jsx(b,{})]})}),e.jsx(g,{control:j,name:"mymailEntitlementSwitch",render:({field:c})=>e.jsxs(v,{className:"space-y-2",children:[e.jsx(f,{children:"Mymail Entitlement Switch"}),e.jsx(y,{children:e.jsx(A,{inputMode:"numeric",value:c.value??"",onChange:c.onChange})}),e.jsx(b,{})]})}),e.jsx(g,{control:j,name:"serviceAuthorizationDesc",render:({field:c})=>e.jsxs(v,{className:"space-y-2 md:col-span-2",children:[e.jsx(f,{children:"Service Authorization Description"}),e.jsx(y,{children:e.jsx(A,{...c})}),e.jsx(b,{})]})}),e.jsx(g,{control:j,name:"productLabel",render:({field:c})=>e.jsxs(v,{className:"space-y-2 md:col-span-2 lg:col-span-3",children:[e.jsx(f,{children:"Product Label"}),e.jsx(y,{children:e.jsx(A,{...c})}),e.jsx(b,{})]})})]})]}),e.jsxs(Ds,{children:[e.jsx(S,{type:"button",variant:"outline",onClick:R,children:"Cancel"}),e.jsx(S,{type:"submit",disabled:d||p,children:r?p?"Updating…":"Update Account":d?"Creating…":"Create Account"})]})]})})]})})});function Jn(s){return{id:s.id,name:s.name,number:s.number,isBusiness:s.privateOrBusiness===$e.Business,type:s.type,currencies:s.accountTaxCategories.map(a=>({currency:a.currency,taxCategory:{id:a.taxCategory.id,name:a.taxCategory.name}})),...s.__typename==="BankFinancialAccount"?{bankNumber:s.bankNumber,branchNumber:s.branchNumber,iban:s.iban??void 0,extendedBankNumber:s.extendedBankNumber??void 0,partyPreferredIndication:s.partyPreferredIndication??void 0,partyAccountInvolvementCode:s.partyAccountInvolvementCode??void 0,accountDealDate:s.accountDealDate??void 0,accountUpdateDate:s.accountUpdateDate??void 0,metegDoarNet:s.metegDoarNet??void 0,kodHarshaatPeilut:s.kodHarshaatPeilut??void 0,accountClosingReasonCode:s.accountClosingReasonCode??void 0,accountAgreementOpeningDate:s.accountAgreementOpeningDate??void 0,serviceAuthorizationDesc:s.serviceAuthorizationDesc??void 0,branchTypeCode:s.branchTypeCode??void 0,mymailEntitlementSwitch:s.mymailEntitlementSwitch??void 0,productLabel:s.productLabel??void 0}:{}}}function Zn({adminId:s}){const[a,n]=C.useState([]),[{data:t,fetching:l},o]=le({query:aa,variables:{adminId:s}});C.useEffect(()=>{t?.financialAccountsByOwner&&n(t.financialAccountsByOwner?.map(Jn)??[])},[t]);const r=C.useRef(null),i=h=>{r.current?.open(h)};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-semibold tracking-tight",children:"Financial Accounts"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Manage bank accounts, credit cards, and crypto wallets"})]}),e.jsxs(S,{onClick:()=>i(),"aria-label":"Create new financial account",children:[e.jsx(ae,{className:"h-4 w-4 mr-2","aria-hidden":"true"}),"New Account"]})]}),l?e.jsx("p",{children:"Loading..."}):e.jsxs("div",{className:"grid gap-4",children:[a.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"No financial accounts added yet."}),a.map(h=>e.jsx(Hn,{account:h,handleOpenModal:i},h.id))]}),e.jsx(Qn,{ownerId:s,ref:r,onDone:()=>o()})]})}function et({businessId:s}){return e.jsxs(Y,{children:[e.jsxs(X,{className:"flex w-full justify-between items-center",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{children:[e.jsx(Q,{children:"Balance"}),e.jsx(J,{children:"Business balance overview"})]})}),e.jsx(pe,{to:fs.BUSINESSES.DETAIL_LEDGER(s),children:e.jsx(S,{variant:"outline",size:"icon",children:e.jsx(Bn,{})})})]}),e.jsx(Z,{children:e.jsx("div",{className:"rounded-md border",children:e.jsx($a,{businessID:s,filter:{}})})})]})}function st({businessId:s}){const{userContext:a}=C.useContext(ss),[n,t]=C.useState(0),[{data:l,fetching:o}]=le({query:na,variables:{filters:{byOwners:a?.context.adminBusinessId?[a.context.adminBusinessId]:void 0,sortBy:{field:ia.Date,asc:!1},byBusinesses:[s]},page:n,limit:10}}),r=l?.allCharges?.pageInfo.totalPages??1,i=l?.allCharges?.nodes??[];return o?e.jsx("div",{children:"Loading charges..."}):e.jsxs(Y,{children:[e.jsxs(X,{className:"flex w-full justify-between items-center",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{children:[e.jsx(Q,{children:"Charges"}),e.jsx(J,{children:"Recurring and one-time charges for this business"})]})}),r>1&&e.jsx(ta,{className:"flex-fit w-fit mx-0",currentPageIndex:n,onChange:t,totalPages:r})]}),e.jsx(Z,{children:e.jsx("div",{className:"rounded-md border",children:e.jsx(Ha,{data:i,isAllOpened:!1})})})]})}var at=["type","layout","connectNulls","ref"],nt=["key"];function je(s){"@babel/helpers - typeof";return je=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(a){return typeof a}:function(a){return a&&typeof Symbol=="function"&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},je(s)}function ms(s,a){if(s==null)return{};var n=tt(s,a),t,l;if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(s);for(l=0;l<o.length;l++)t=o[l],!(a.indexOf(t)>=0)&&Object.prototype.propertyIsEnumerable.call(s,t)&&(n[t]=s[t])}return n}function tt(s,a){if(s==null)return{};var n={};for(var t in s)if(Object.prototype.hasOwnProperty.call(s,t)){if(a.indexOf(t)>=0)continue;n[t]=s[t]}return n}function Ae(){return Ae=Object.assign?Object.assign.bind():function(s){for(var a=1;a<arguments.length;a++){var n=arguments[a];for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(s[t]=n[t])}return s},Ae.apply(this,arguments)}function us(s,a){var n=Object.keys(s);if(Object.getOwnPropertySymbols){var t=Object.getOwnPropertySymbols(s);a&&(t=t.filter(function(l){return Object.getOwnPropertyDescriptor(s,l).enumerable})),n.push.apply(n,t)}return n}function q(s){for(var a=1;a<arguments.length;a++){var n=arguments[a]!=null?arguments[a]:{};a%2?us(Object(n),!0).forEach(function(t){se(s,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(s,Object.getOwnPropertyDescriptors(n)):us(Object(n)).forEach(function(t){Object.defineProperty(s,t,Object.getOwnPropertyDescriptor(n,t))})}return s}function he(s){return lt(s)||ct(s)||rt(s)||it()}function it(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
|
|
2
|
+
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function rt(s,a){if(s){if(typeof s=="string")return Ge(s,a);var n=Object.prototype.toString.call(s).slice(8,-1);if(n==="Object"&&s.constructor&&(n=s.constructor.name),n==="Map"||n==="Set")return Array.from(s);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return Ge(s,a)}}function ct(s){if(typeof Symbol<"u"&&s[Symbol.iterator]!=null||s["@@iterator"]!=null)return Array.from(s)}function lt(s){if(Array.isArray(s))return Ge(s)}function Ge(s,a){(a==null||a>s.length)&&(a=s.length);for(var n=0,t=new Array(a);n<a;n++)t[n]=s[n];return t}function ot(s,a){if(!(s instanceof a))throw new TypeError("Cannot call a class as a function")}function xs(s,a){for(var n=0;n<a.length;n++){var t=a[n];t.enumerable=t.enumerable||!1,t.configurable=!0,"value"in t&&(t.writable=!0),Object.defineProperty(s,Vs(t.key),t)}}function dt(s,a,n){return a&&xs(s.prototype,a),n&&xs(s,n),Object.defineProperty(s,"prototype",{writable:!1}),s}function mt(s,a,n){return a=Te(a),ut(s,Rs()?Reflect.construct(a,n||[],Te(s).constructor):a.apply(s,n))}function ut(s,a){if(a&&(je(a)==="object"||typeof a=="function"))return a;if(a!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return xt(s)}function xt(s){if(s===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return s}function Rs(){try{var s=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch{}return(Rs=function(){return!!s})()}function Te(s){return Te=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(n){return n.__proto__||Object.getPrototypeOf(n)},Te(s)}function ht(s,a){if(typeof a!="function"&&a!==null)throw new TypeError("Super expression must either be null or a function");s.prototype=Object.create(a&&a.prototype,{constructor:{value:s,writable:!0,configurable:!0}}),Object.defineProperty(s,"prototype",{writable:!1}),a&&We(s,a)}function We(s,a){return We=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,l){return t.__proto__=l,t},We(s,a)}function se(s,a,n){return a=Vs(a),a in s?Object.defineProperty(s,a,{value:n,enumerable:!0,configurable:!0,writable:!0}):s[a]=n,s}function Vs(s){var a=pt(s,"string");return je(a)=="symbol"?a:a+""}function pt(s,a){if(je(s)!="object"||!s)return s;var n=s[Symbol.toPrimitive];if(n!==void 0){var t=n.call(s,a);if(je(t)!="object")return t;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(s)}var ge=(function(s){function a(){var n;ot(this,a);for(var t=arguments.length,l=new Array(t),o=0;o<t;o++)l[o]=arguments[o];return n=mt(this,a,[].concat(l)),se(n,"state",{isAnimationFinished:!0,totalLength:0}),se(n,"generateSimpleStrokeDasharray",function(r,i){return"".concat(i,"px ").concat(r-i,"px")}),se(n,"getStrokeDasharray",function(r,i,h){var d=h.reduce(function(F,P){return F+P});if(!d)return n.generateSimpleStrokeDasharray(i,r);for(var m=Math.floor(r/d),p=r%d,u=i-r,j=[],w=0,I=0;w<h.length;I+=h[w],++w)if(I+h[w]>p){j=[].concat(he(h.slice(0,w)),[p-I]);break}var B=j.length%2===0?[0,u]:[u];return[].concat(he(a.repeat(h,m)),he(j),B).map(function(F){return"".concat(F,"px")}).join(", ")}),se(n,"id",an("recharts-line-")),se(n,"pathRef",function(r){n.mainCurve=r}),se(n,"handleAnimationEnd",function(){n.setState({isAnimationFinished:!0}),n.props.onAnimationEnd&&n.props.onAnimationEnd()}),se(n,"handleAnimationStart",function(){n.setState({isAnimationFinished:!1}),n.props.onAnimationStart&&n.props.onAnimationStart()}),n}return ht(a,s),dt(a,[{key:"componentDidMount",value:function(){if(this.props.isAnimationActive){var t=this.getTotalLength();this.setState({totalLength:t})}}},{key:"componentDidUpdate",value:function(){if(this.props.isAnimationActive){var t=this.getTotalLength();t!==this.state.totalLength&&this.setState({totalLength:t})}}},{key:"getTotalLength",value:function(){var t=this.mainCurve;try{return t&&t.getTotalLength&&t.getTotalLength()||0}catch{return 0}}},{key:"renderErrorBar",value:function(t,l){if(this.props.isAnimationActive&&!this.state.isAnimationFinished)return null;var o=this.props,r=o.points,i=o.xAxis,h=o.yAxis,d=o.layout,m=o.children,p=Ya(m,Xa);if(!p)return null;var u=function(I,B){return{x:I.x,y:I.y,value:I.value,errorVal:Ls(I.payload,B)}},j={clipPath:t?"url(#clipPath-".concat(l,")"):null};return U.createElement(Fe,j,p.map(function(w){return U.cloneElement(w,{key:"bar-".concat(w.props.dataKey),data:r,xAxis:i,yAxis:h,layout:d,dataPointFormatter:u})}))}},{key:"renderDots",value:function(t,l,o){var r=this.props.isAnimationActive;if(r&&!this.state.isAnimationFinished)return null;var i=this.props,h=i.dot,d=i.points,m=i.dataKey,p=Ie(this.props,!1),u=Ie(h,!0),j=d.map(function(I,B){var F=q(q(q({key:"dot-".concat(B),r:3},p),u),{},{index:B,cx:I.x,cy:I.y,value:I.value,dataKey:m,payload:I.payload,points:d});return a.renderDotItem(h,F)}),w={clipPath:t?"url(#clipPath-".concat(l?"":"dots-").concat(o,")"):null};return U.createElement(Fe,Ae({className:"recharts-line-dots",key:"dots"},w),j)}},{key:"renderCurveStatically",value:function(t,l,o,r){var i=this.props,h=i.type,d=i.layout,m=i.connectNulls;i.ref;var p=ms(i,at),u=q(q(q({},Ie(p,!0)),{},{fill:"none",className:"recharts-line-curve",clipPath:l?"url(#clipPath-".concat(o,")"):null,points:t},r),{},{type:h,layout:d,connectNulls:m});return U.createElement(Qa,Ae({},u,{pathRef:this.pathRef}))}},{key:"renderCurveWithAnimation",value:function(t,l){var o=this,r=this.props,i=r.points,h=r.strokeDasharray,d=r.isAnimationActive,m=r.animationBegin,p=r.animationDuration,u=r.animationEasing,j=r.animationId,w=r.animateNewValues,I=r.width,B=r.height,F=this.state,P=F.prevPoints,R=F.totalLength;return U.createElement(Ja,{begin:m,duration:p,isActive:d,easing:u,from:{t:0},to:{t:1},key:"line-".concat(j),onAnimationEnd:this.handleAnimationEnd,onAnimationStart:this.handleAnimationStart},function(z){var _=z.t;if(P){var G=P.length/i.length,c=i.map(function(N,E){var L=Math.floor(E*G);if(P[L]){var oe=P[L],xe=ve(oe.x,N.x),zs=ve(oe.y,N.y);return q(q({},N),{},{x:xe(_),y:zs(_)})}if(w){var Us=ve(I*2,N.x),Hs=ve(B/2,N.y);return q(q({},N),{},{x:Us(_),y:Hs(_)})}return q(q({},N),{},{x:N.x,y:N.y})});return o.renderCurveStatically(c,t,l)}var O=ve(0,R),V=O(_),k;if(h){var x="".concat(h).split(/[,\s]+/gim).map(function(N){return parseFloat(N)});k=o.getStrokeDasharray(V,R,x)}else k=o.generateSimpleStrokeDasharray(R,V);return o.renderCurveStatically(i,t,l,{strokeDasharray:k})})}},{key:"renderCurve",value:function(t,l){var o=this.props,r=o.points,i=o.isAnimationActive,h=this.state,d=h.prevPoints,m=h.totalLength;return i&&r&&r.length&&(!d&&m>0||!Za(d,r))?this.renderCurveWithAnimation(t,l):this.renderCurveStatically(r,t,l)}},{key:"render",value:function(){var t,l=this.props,o=l.hide,r=l.dot,i=l.points,h=l.className,d=l.xAxis,m=l.yAxis,p=l.top,u=l.left,j=l.width,w=l.height,I=l.isAnimationActive,B=l.id;if(o||!i||!i.length)return null;var F=this.state.isAnimationFinished,P=i.length===1,R=ns("recharts-line",h),z=d&&d.allowDataOverflow,_=m&&m.allowDataOverflow,G=z||_,c=qe(B)?this.id:B,O=(t=Ie(r,!1))!==null&&t!==void 0?t:{r:3,strokeWidth:2},V=O.r,k=V===void 0?3:V,x=O.strokeWidth,N=x===void 0?2:x,E=en(r)?r:{},L=E.clipDot,oe=L===void 0?!0:L,xe=k*2+N;return U.createElement(Fe,{className:R},z||_?U.createElement("defs",null,U.createElement("clipPath",{id:"clipPath-".concat(c)},U.createElement("rect",{x:z?u:u-j/2,y:_?p:p-w/2,width:z?j:j*2,height:_?w:w*2})),!oe&&U.createElement("clipPath",{id:"clipPath-dots-".concat(c)},U.createElement("rect",{x:u-xe/2,y:p-xe/2,width:j+xe,height:w+xe}))):null,!P&&this.renderCurve(G,c),this.renderErrorBar(G,c),(P||r)&&this.renderDots(G,oe,c),(!I||F)&&sn.renderCallByParent(this.props,i))}}],[{key:"getDerivedStateFromProps",value:function(t,l){return t.animationId!==l.prevAnimationId?{prevAnimationId:t.animationId,curPoints:t.points,prevPoints:l.curPoints}:t.points!==l.curPoints?{curPoints:t.points}:null}},{key:"repeat",value:function(t,l){for(var o=t.length%2!==0?[].concat(he(t),[0]):t,r=[],i=0;i<l;++i)r=[].concat(he(r),he(o));return r}},{key:"renderDotItem",value:function(t,l){var o;if(U.isValidElement(t))o=U.cloneElement(t,l);else if(Wa(t))o=t(l);else{var r=l.key,i=ms(l,nt),h=ns("recharts-line-dot",typeof t!="boolean"?t.className:"");o=U.createElement(Ka,Ae({key:r},i,{className:h}))}return o}}])})(C.PureComponent);se(ge,"displayName","Line");se(ge,"defaultProps",{xAxisId:0,yAxisId:0,connectNulls:!1,activeDot:!0,dot:!0,legendType:"line",stroke:"#3182bd",strokeWidth:1,fill:"#fff",points:[],isAnimationActive:!nn.isSsr,animateNewValues:!0,animationBegin:0,animationDuration:1500,animationEasing:"ease",hide:!1,label:!1});se(ge,"getComposedData",function(s){var a=s.props,n=s.xAxis,t=s.yAxis,l=s.xAxisTicks,o=s.yAxisTicks,r=s.dataKey,i=s.bandSize,h=s.displayedData,d=s.offset,m=a.layout,p=h.map(function(u,j){var w=Ls(u,r);return m==="horizontal"?{x:cs({axis:n,ticks:l,bandSize:i,entry:u,index:j}),y:qe(w)?null:t.scale(w),value:w,payload:u}:{x:qe(w)?null:n.scale(w),y:cs({axis:t,ticks:o,bandSize:i,entry:u,index:j}),value:w,payload:u}});return q({points:p,layout:m},d)});var jt=tn({chartName:"LineChart",GraphicalChild:ge,axisComponents:[{axisType:"xAxis",AxisComp:Fs},{axisType:"yAxis",AxisComp:_s}],formatAxisMap:rn});const Ne=[{month:"Jan",revenue:12500,expenses:8200},{month:"Feb",revenue:15800,expenses:9100},{month:"Mar",revenue:18200,expenses:10500},{month:"Apr",revenue:16900,expenses:9800},{month:"May",revenue:21300,expenses:11200},{month:"Jun",revenue:24500,expenses:12800},{month:"Jul",revenue:22800,expenses:11900},{month:"Aug",revenue:26100,expenses:13500},{month:"Sep",revenue:28900,expenses:14200},{month:"Oct",revenue:31200,expenses:15100}];function gt(){const s=Ne.reduce((n,t)=>n+t.revenue,0),a=s/Ne.length;return e.jsxs(Y,{children:[e.jsxs(X,{children:[e.jsx(Q,{children:"Revenue Analytics"}),e.jsx(J,{children:"Revenue and expenses over time"})]}),e.jsxs(Z,{children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-3 mb-6",children:[e.jsxs("div",{className:"rounded-lg border p-4 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(Se,{className:"h-4 w-4"}),"Total Revenue"]}),e.jsxs("p",{className:"text-2xl font-bold",children:["$",s.toLocaleString()]}),e.jsxs("div",{className:"flex items-center gap-1 text-sm text-green-600",children:[e.jsx(Le,{className:"h-3 w-3"}),e.jsx("span",{children:"+24.5% from last period"})]})]}),e.jsxs("div",{className:"rounded-lg border p-4 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(Se,{className:"h-4 w-4"}),"Average Monthly"]}),e.jsxs("p",{className:"text-2xl font-bold",children:["$",a.toLocaleString(void 0,{maximumFractionDigits:0})]}),e.jsxs("div",{className:"flex items-center gap-1 text-sm text-green-600",children:[e.jsx(Le,{className:"h-3 w-3"}),e.jsx("span",{children:"+18.2% growth rate"})]})]}),e.jsxs("div",{className:"rounded-lg border p-4 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(Se,{className:"h-4 w-4"}),"Current Month"]}),e.jsxs("p",{className:"text-2xl font-bold",children:["$",Ne[Ne.length-1].revenue.toLocaleString()]}),e.jsxs("div",{className:"flex items-center gap-1 text-sm text-green-600",children:[e.jsx(Le,{className:"h-3 w-3"}),e.jsx("span",{children:"+8.0% from last month"})]})]})]}),e.jsx(cn,{config:{revenue:{label:"Revenue",color:"hsl(var(--chart-1))"},expenses:{label:"Expenses",color:"hsl(var(--chart-2))"}},className:"h-[400px]",children:e.jsx(ln,{width:"100%",height:"100%",children:e.jsxs(jt,{data:Ne,margin:{top:5,right:10,left:10,bottom:5},children:[e.jsx(on,{strokeDasharray:"3 3",className:"stroke-muted"}),e.jsx(Fs,{dataKey:"month",className:"text-xs",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(_s,{className:"text-xs",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(dn,{content:e.jsx(mn,{})}),e.jsx(ge,{type:"monotone",dataKey:"revenue",stroke:"var(--color-revenue)",strokeWidth:2,dot:{fill:"var(--color-revenue)",r:4}}),e.jsx(ge,{type:"monotone",dataKey:"expenses",stroke:"var(--color-expenses)",strokeWidth:2,dot:{fill:"var(--color-expenses)",r:4}})]})})})]})]})}function vt(s){return{id:s.id,pos:s.purchaseOrders??void 0,startDate:s.startDate,endDate:s.endDate,paymentAmount:s.amount.raw,paymentCurrency:s.amount.currency,productType:s.product??void 0,billingCycle:s.billingCycle,msCloudLink:s.msCloud?.toString(),isActive:s.isActive,subscriptionPlan:s.plan??void 0,defaultRemark:s.remarks??void 0,defaultDocumentType:s.documentType??void 0,operationsLimit:s.operationsLimit}}function ft({clientId:s}){const[a,n]=C.useState(null),[{data:t,fetching:l},o]=le({query:ra,variables:{clientId:s}}),r=t?.contractsByClient??[];return l?e.jsx("div",{children:"Loading contracts..."}):e.jsxs(Y,{children:[e.jsx(X,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(Q,{children:"Contracts"}),e.jsx(J,{children:"Current and past contracts sorted by start date"})]}),e.jsx(un,{clientId:s,contract:a,onDone:o})]})}),e.jsx(Z,{className:"space-y-4",children:r.map(i=>{const h=!!i.isActive;return e.jsxs("div",{className:"rounded-lg border p-4 space-y-4",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h4",{className:"font-semibold",children:i.product}),e.jsx(te,{variant:h?"default":"secondary",children:i.isActive?"Active":"Inactive"})]}),e.jsx("p",{className:"text-sm text-muted-foreground font-mono",children:i.id})]}),e.jsx(S,{variant:"ghost",size:"sm",onClick:()=>n(vt(i)),children:e.jsx(pn,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2 lg:grid-cols-3",children:[e.jsxs("div",{className:"space-y-0",children:[e.jsxs("p",{className:"text-sm text-muted-foreground flex items-center gap-1",children:[e.jsx(ca,{className:"h-3 w-3"}),"Contract Period"]}),e.jsxs("p",{className:"text-sm font-medium",children:[new Date(i.startDate).toLocaleDateString()," →"," ",new Date(i.endDate).toLocaleDateString()]})]}),e.jsxs("div",{className:"space-y-0",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"PO Numbers"}),e.jsx("p",{className:"text-sm font-medium font-mono",children:i.purchaseOrders.toReversed()[0]??""}),i.purchaseOrders.length>1&&e.jsx("div",{className:"space-x-1",children:i.purchaseOrders.toReversed().slice(1).map(d=>e.jsx("span",{className:"text-xs font-thin font-mono",children:d},d))})]}),e.jsxs("div",{className:"space-y-0",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Payment"}),e.jsx("p",{className:"text-sm font-medium",children:la(i.amount.raw,i.amount.currency)})]}),e.jsxs("div",{className:"space-y-0",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Billing Cycle"}),e.jsx("p",{className:"text-sm font-medium",children:xn(i.billingCycle)})]}),e.jsxs("div",{className:"space-y-0",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Subscription Plan"}),e.jsx("p",{className:"text-sm font-medium",children:i.plan?hn(i.plan):"N/A"})]}),e.jsxs("div",{className:"space-y-0",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Operations Limit"}),e.jsx("p",{className:"text-sm font-medium",children:i.operationsLimit.toLocaleString()})]}),e.jsxs("div",{className:"space-y-0",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Document Type"}),e.jsx("p",{className:"text-sm font-medium",children:oa(i.documentType)})]})]}),i.remarks&&e.jsxs("div",{className:"space-y-0",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Remark"}),e.jsx("p",{className:"text-sm",children:i.remarks})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:i.msCloud&&e.jsx(S,{variant:"outline",size:"sm",asChild:!0,children:e.jsxs("a",{href:i.msCloud.toString(),target:"_blank",rel:"noopener noreferrer",children:[e.jsx(Je,{className:"h-4 w-4 mr-2"}),"MS Cloud",e.jsx(jn,{className:"h-3 w-3 ml-1"})]})})})]},i.id)})})]})}const yt=[{id:"linearId",name:"Linear",description:"Issue tracking and project management",url:"https://linear.app/the-guild/customer/[ID]",color:"indigo-500"},{id:"slackChannelKey",name:"Slack",description:"Team communication and notifications",keyType:"Channel Key",url:"https://guild-oss.slack.com/archives/[ID]"},{id:"notionId",name:"Notion",description:"Documentation and knowledge management",url:"https://www.notion.so/theguildoss/[ID]"},{id:"workflowyUrl",name:"Workflowy",keyType:"URL",description:"Task management and note taking",url:"[ID]"}];function Nt({data:s}){const[a,n]=C.useState([]),t=we(ma,s),l=t?.clientInfo?.integrations,{updateClient:o}=Es(),[{data:r,fetching:i},h]=le({query:da,variables:{clientId:t?.id??""},pause:!l?.greenInvoiceInfo||!t?.id||!a.includes("green-invoice")}),d=r?.greenInvoiceClient,m=l?.hiveId,p=C.useCallback((u,j)=>{if(!t?.id)return;const w={};w[j]=u,o({businessId:t?.id,fields:{integrations:w}})},[t?.id,o]);return C.useEffect(()=>{l?.greenInvoiceInfo?.greenInvoiceId&&t?.id&&a.includes("green-invoice")&&h()},[l?.greenInvoiceInfo?.greenInvoiceId,t?.id,h,a]),e.jsxs(Y,{children:[e.jsx(X,{children:e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{children:[e.jsx(Q,{children:"Integrations"}),e.jsx(J,{children:"Connected external services and providers"})]})})}),e.jsx(Z,{className:"space-y-6",children:e.jsxs(vn,{type:"multiple",value:a,onValueChange:n,className:"space-y-4",children:[i?e.jsxs(ke,{value:"green-invoice",className:"rounded-lg border-2 border-green-600/20 bg-green-600/5",children:[e.jsx("div",{className:"px-4 py-3 bg-green-600/10 rounded-t-lg",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-1",children:[e.jsx(D,{className:"h-10 w-10 rounded-lg"}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(D,{className:"h-6 w-32"}),e.jsx(D,{className:"h-5 w-5 rounded-full"})]}),e.jsx(D,{className:"h-4 w-64"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(D,{className:"h-8 w-24"}),e.jsx(D,{className:"h-8 w-8"})]})]})}),e.jsx(_e,{children:e.jsxs("div",{className:"p-6 space-y-6",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx(D,{className:"h-4 w-40"}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(D,{className:"h-3 w-24"}),e.jsx(D,{className:"h-4 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(D,{className:"h-3 w-24"}),e.jsx(D,{className:"h-4 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(D,{className:"h-3 w-24"}),e.jsx(D,{className:"h-4 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(D,{className:"h-3 w-24"}),e.jsx(D,{className:"h-4 w-full"})]})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(D,{className:"h-4 w-40"}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(D,{className:"h-3 w-32"}),e.jsx(D,{className:"h-6 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(D,{className:"h-3 w-24"}),e.jsx(D,{className:"h-4 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(D,{className:"h-3 w-24"}),e.jsx(D,{className:"h-4 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(D,{className:"h-3 w-24"}),e.jsx(D,{className:"h-4 w-full"})]})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(D,{className:"h-4 w-40"}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-3",children:[e.jsxs("div",{className:"space-y-2 md:col-span-2",children:[e.jsx(D,{className:"h-3 w-24"}),e.jsx(D,{className:"h-4 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(D,{className:"h-3 w-24"}),e.jsx(D,{className:"h-4 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(D,{className:"h-3 w-24"}),e.jsx(D,{className:"h-4 w-full"})]})]})]})]})})]}):e.jsxs(ke,{value:"green-invoice",className:"rounded-lg border-2 border-green-600/20 bg-green-600/5",children:[e.jsx("div",{className:"px-4 py-3 bg-green-600/10 rounded-t-lg",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-1",children:[e.jsx("div",{className:"h-10 w-10 rounded-lg bg-green-600 flex items-center justify-center text-white font-bold",children:"GI"}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"font-semibold text-lg",children:"Green Invoice"}),e.jsx(Me,{className:"h-5 w-5 text-green-600"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Israeli invoicing system integration"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ve,{id:t?.clientInfo?.integrations.greenInvoiceInfo?.greenInvoiceId??void 0,provider:"Green Invoice",updateClient:async u=>p(u,"greenInvoiceId")}),d&&e.jsx(ls,{className:"hover:no-underline p-2"})]})]})}),e.jsx(_e,{children:d&&e.jsxs("div",{className:"p-6 space-y-6",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx("h4",{className:"font-semibold text-sm text-muted-foreground uppercase tracking-wide",children:"Business Information"}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:"Integration ID"}),e.jsx("p",{className:"text-sm font-mono",children:t?.clientInfo?.integrations.greenInvoiceInfo?.greenInvoiceId})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:"Business Name"}),e.jsx("p",{className:"text-sm",children:d.name})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:"Country"}),e.jsx("p",{className:"text-sm",children:d.country})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:"Tax ID"}),e.jsx("p",{className:"text-sm font-mono",children:d.taxId})]})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h4",{className:"font-semibold text-sm text-muted-foreground uppercase tracking-wide",children:"Contact Information"}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("span",{className:"text-sm font-medium text-muted-foreground flex items-center gap-2",children:[e.jsx(ze,{className:"h-3.5 w-3.5"}),"Email Addresses"]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:d.emails?.map((u,j)=>e.jsx("span",{className:"text-sm px-2 py-1 bg-muted rounded",children:u},j))})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("span",{className:"text-sm font-medium text-muted-foreground flex items-center gap-2",children:[e.jsx(Ps,{className:"h-3.5 w-3.5"}),"Phone"]}),e.jsx("p",{className:"text-sm font-mono",children:d.phone})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:"Mobile"}),e.jsx("p",{className:"text-sm font-mono",children:d.mobile})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:"Fax"}),e.jsx("p",{className:"text-sm font-mono",children:d.fax})]})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("h4",{className:"font-semibold text-sm text-muted-foreground uppercase tracking-wide flex items-center gap-2",children:[e.jsx(Ue,{className:"h-3.5 w-3.5"}),"Address"]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-3",children:[e.jsxs("div",{className:"space-y-1 md:col-span-2",children:[e.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:"Street Address"}),e.jsx("p",{className:"text-sm",children:d.address})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:"City"}),e.jsx("p",{className:"text-sm",children:d.city})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:"Zip Code"}),e.jsx("p",{className:"text-sm font-mono",children:d.zip})]})]})]})]})})]}),e.jsxs(ke,{value:"hiveId",className:"rounded-lg border-2 border-green-900/20 bg-green-900/5",children:[e.jsx("div",{className:"px-4 py-3 bg-green-900/10 rounded-t-lg",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-1",children:[m?e.jsx(pe,{to:"https://the-guild.dev/graphql/hive",target:"_blank",rel:"noreferrer",onClick:u=>u.stopPropagation(),className:"inline-flex items-center font-semibold",children:e.jsx("div",{className:"h-10 w-10 rounded-lg bg-green-900 flex items-center justify-center text-white font-bold",children:e.jsx("img",{src:"/icons/logos/hive.svg",alt:"Hive logo",className:"size-8 object-cover"})})}):e.jsx("div",{className:"h-10 w-10 rounded-lg bg-green-900 flex items-center justify-center text-white font-bold",children:e.jsx(ts,{})}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"font-semibold text-lg",children:"Hive"}),m?e.jsx(Me,{className:"h-5 w-5 text-green-600"}):e.jsx(os,{className:"h-5 w-5 text-red-600"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Schema registry, analytics, metrics and gateway for GraphQL federation and other GraphQL APIs"})]})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(Ve,{id:l?.hiveId??void 0,provider:"Hive",updateClient:async u=>p(u,"hiveId")})}),m&&e.jsx(ls,{className:"hover:no-underline p-2"})]})}),e.jsx(_e,{children:m&&e.jsxs("div",{className:"flex flex-col gap-4 px-4 pb-4 pt-2 border-t",children:[e.jsx("div",{className:"text-sm",children:e.jsxs(pe,{to:"https://the-guild.dev/graphql/hive",target:"_blank",rel:"noreferrer",onClick:u=>u.stopPropagation(),className:"inline-flex items-center font-semibold gap-2",children:[e.jsx("img",{src:"/icons/logos/hive.svg",alt:"Hive logo",className:"size-8 object-cover"}),"Hive"]})}),e.jsx("div",{className:"text-sm",children:e.jsxs(pe,{to:`https://graphcdn.retool.com/apps/f6c244bc-b7ce-11ef-a86c-0b05f221c5b4/Hive/Hive%20Admin/explore_organization?id=${l.hiveId}`,target:"_blank",rel:"noreferrer",onClick:u=>u.stopPropagation(),className:"inline-flex items-center font-semibold gap-2",children:[e.jsx("img",{src:"/icons/logos/retool.svg",alt:"Retool logo",className:"size-8 object-cover"}),"Retool"]})})]})})]},"hiveId"),yt.map(u=>e.jsx(ke,{value:u.id,className:"rounded-lg border-2 border-gray-500/20 bg-gray-500/5",children:e.jsx("div",{className:"px-4 py-3 bg-gray-500/10 rounded-t-lg",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-1",children:[l?.[u.id]?e.jsx(pe,{to:u.url.replace("[ID]",l?.[u.id]??""),target:"_blank",rel:"noreferrer",onClick:j=>j.stopPropagation(),className:"inline-flex items-center font-semibold",children:e.jsx("div",{className:"h-10 w-10 rounded-lg bg-gray-500 flex items-center justify-center text-white font-bold",children:e.jsx(Je,{})})}):e.jsx("div",{className:"h-10 w-10 rounded-lg bg-gray-500 flex items-center justify-center text-white font-bold",children:e.jsx(ts,{})}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"font-semibold text-lg",children:u.name}),l?.[u.id]==null?e.jsx(os,{className:"h-5 w-5 text-red-600"}):e.jsx(Me,{className:"h-5 w-5 text-green-600"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:u.description})]})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(Ve,{id:t?.clientInfo?.integrations[u.id]??void 0,provider:u.name,keyType:u.keyType,updateClient:async j=>p(j,u.id)})})]})})},u.id))]})})]})}function Ve({id:s,provider:a,keyType:n,updateClient:t}){const[l,o]=C.useState(!1),[r,i]=C.useState(s),h=C.useCallback(async()=>{await t(r),o(!1)},[r,t]);return e.jsxs(Ke,{open:l,onOpenChange:o,children:[e.jsx(ua,{asChild:!0,children:e.jsx(S,{variant:"outline",size:"sm",onClick:d=>d.stopPropagation(),children:e.jsx(Os,{className:"h-4 w-4"})})}),e.jsxs(Ye,{onClick:d=>d.stopPropagation(),children:[e.jsxs(ys,{children:[e.jsxs(Ns,{children:["Configure ",a]}),e.jsxs(bs,{children:["Update your ",a," integration settings"]})]}),e.jsx("div",{className:"space-y-4 py-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsxs(Ce,{htmlFor:"id",children:[a," ",n??"ID"]}),e.jsx(A,{id:"id",value:r,onChange:d=>i(d.target.value),placeholder:`Enter ${a} ${n??"ID"}`})]})}),e.jsxs(Ds,{children:[e.jsx(S,{variant:"outline",onClick:()=>o(!1),children:"Cancel"}),e.jsx(S,{onClick:h,disabled:!r,children:"Save Changes"})]})]})]})}const bt="updateBusiness",$s=()=>{const[{fetching:s},a]=Be(xa),n=C.useCallback(async t=>{const l=`Error updating business ID [${t.businessId}]`,o=`${bt}-${t.businessId}`;K.loading("Updating business",{id:o});try{const r=await a(t),i=Ee(r,l,o,"updateBusiness");if(i)return K.success("Success",{id:o,description:"Business updated"}),i.updateBusiness}catch(r){console.error(`${l}: ${r}`),K.error("Error",{id:o,description:l,duration:1e5,closeButton:!0})}},[a]);return{fetching:s,updateBusiness:n}},Ct=Object.values(ba);function hs(s){return!s||s.__typename!=="LtdFinancialEntity"?{}:{isClient:!!s.clientInfo?.id,isActive:s.isActive,isReceiptEnough:s.isReceiptEnough??void 0,isDocumentsOptional:s.isDocumentsOptional??void 0,isVatOptional:s.optionalVAT??void 0,isExemptDealer:s.exemptDealer??void 0,sortCode:s.sortCode?.key?.toString()??void 0,taxCategory:s.taxCategory?.id??void 0,pcn874RecordType:s?.pcn874RecordType??void 0,irsCode:s?.irsCode??void 0,description:s.suggestions?.description??void 0,tags:s.suggestions?.tags?.map(a=>a.id)??[],phrases:s.suggestions?.phrases??[],emails:s.suggestions?.emails??[],internalLinks:s.suggestions?.emailListener?.internalEmailLinks??[],attachmentTypes:s.suggestions?.emailListener?.attachments??[],useMessageBody:s.suggestions?.emailListener?.emailBody??void 0}}function At(s){const n=s.internalLinks||s.useMessageBody||s.attachmentTypes?{internalEmailLinks:s.internalLinks,emailBody:s.useMessageBody,attachments:s.attachmentTypes}:void 0,l=s.description||s.tags||s.phrases||s.emails||n?{description:s.description,tags:s.tags?.map(o=>({id:o})),phrases:s.phrases,emails:s.emails,emailListener:n}:void 0;return{optionalVAT:s.isVatOptional,exemptDealer:s.isExemptDealer,sortCode:s.sortCode?parseInt(s.sortCode):void 0,taxCategory:s.taxCategory,pcn874RecordType:s.pcn874RecordType,irsCode:s.irsCode,isActive:s.isActive,isReceiptEnough:s.isReceiptEnough,isDocumentsOptional:s.isDocumentsOptional,suggestions:l}}function wt({data:s,refetchBusiness:a}){const n=we(pa,s),[t,l]=C.useState(hs(n)),{userContext:o}=C.useContext(ss),{updateBusiness:r,fetching:i}=$s(),[h,d]=C.useState(!1),[m,p]=C.useState(void 0),u=Pe({defaultValues:t}),j=async I=>{if(!n||!o?.context.adminBusinessId)return;const B=Ze(I,u.formState.dirtyFields);if(!B)return;const F=At(B);await r({businessId:n.id,ownerId:o.context.adminBusinessId,fields:F}),B.tags?.length||B.description?(p({tagIds:B.tags?.map(P=>({id:P})),description:B.description}),d(!0)):a?.()};if(C.useEffect(()=>{if(n){const I=hs(n);l(I),u.reset(I)}},[n,u]),!n)return e.jsx("div",{});const w=u.watch("isClient");return e.jsxs(Y,{children:[e.jsx(X,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(Q,{children:"Configurations"}),e.jsx(J,{children:"Business status, tax settings, automation rules, and integration preferences"})]}),!w&&e.jsx(ha,{businessId:n.id,onDone:a})]})}),e.jsx(Oe,{...u,children:e.jsxs("form",{onSubmit:u.handleSubmit(j),children:[e.jsxs(Z,{className:"space-y-6",children:[e.jsx(It,{form:u}),e.jsx(ce,{}),e.jsx(kt,{form:u}),e.jsx(ce,{}),e.jsx(Dt,{form:u}),e.jsx(ce,{}),e.jsx(St,{form:u})]}),e.jsx(Qe,{className:"flex justify-end border-t pt-6",children:e.jsxs(S,{type:"submit",disabled:i||Object.keys(u.formState.dirtyFields).length===0,children:[e.jsx(as,{className:"h-4 w-4 mr-2"}),"Save Changes"]})})]})}),e.jsx(_n,{businessId:n.id,tagIds:m?.tagIds,description:m?.description,open:h,onOpenChange:d,onClose:a})]})}function It({form:s}){return e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-sm font-semibold text-foreground",children:"Business Status & Behavior"}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(g,{control:s.control,name:"isClient",render:({field:a,fieldState:n})=>e.jsxs(v,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(f,{children:"Is Client"}),e.jsx(de,{children:"Mark this business as a client"})]}),e.jsx(y,{children:e.jsx(re,{disabled:!0,checked:a.value,onCheckedChange:a.onChange,className:T(n)})})]})}),e.jsx(g,{control:s.control,name:"isActive",render:({field:a,fieldState:n})=>e.jsxs(v,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(f,{children:"Is Active"}),e.jsx(de,{children:"Business is currently active"})]}),e.jsx(y,{children:e.jsx(re,{checked:a.value,onCheckedChange:a.onChange,className:T(n)})})]})}),e.jsx(g,{control:s.control,name:"isReceiptEnough",render:({field:a,fieldState:n})=>e.jsxs(v,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(f,{children:"Is Receipt Enough"}),e.jsx(de,{children:"Generate ledger for receipt documents if no invoice available"})]}),e.jsx(y,{children:e.jsx(re,{checked:a.value,onCheckedChange:a.onChange,className:T(n)})})]})}),e.jsx(g,{control:s.control,name:"isDocumentsOptional",render:({field:a,fieldState:n})=>e.jsxs(v,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(f,{children:"No Docs Required"}),e.jsx(de,{children:"Skip document validation for common charges"})]}),e.jsx(y,{children:e.jsx(re,{checked:a.value,onCheckedChange:a.onChange,className:T(n)})})]})}),e.jsx(g,{control:s.control,name:"isVatOptional",render:({field:a,fieldState:n})=>e.jsxs(v,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(f,{children:"Is VAT Optional"}),e.jsx(de,{children:"Mute missing VAT indicator"})]}),e.jsx(y,{children:e.jsx(re,{checked:a.value,onCheckedChange:a.onChange,className:T(n)})})]})}),e.jsx(g,{control:s.control,name:"isExemptDealer",render:({field:a,fieldState:n})=>e.jsxs(v,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(f,{children:"Is Exempt Dealer"}),e.jsx(de,{children:"Business is exempt from VAT requirements"})]}),e.jsx(y,{children:e.jsx(re,{checked:a.value,onCheckedChange:a.onChange,className:T(n)})})]})})]})]})}function kt({form:s}){const{selectableTaxCategories:a,fetching:n}=ja(),{selectableSortCodes:t,fetching:l,sortCodes:o}=ga(),{selectableTags:r,fetching:i}=va(),h=C.useCallback(d=>{if(d){const m=o.find(p=>Number(p.key)===Number(d));m&&(m.defaultIrsCode?s.setValue("irsCode",m.defaultIrsCode,{shouldDirty:!0}):s.setValue("irsCode",null,{shouldDirty:!0}))}},[s,o]);return e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-sm font-semibold text-foreground",children:"Default Settings"}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsx(g,{control:s.control,name:"sortCode",render:({field:d,fieldState:m})=>e.jsxs(v,{children:[e.jsx(f,{children:"Sort Code"}),e.jsx(y,{children:e.jsx(He,{onChange:p=>{h(p),d.onChange(p)},data:t,value:d.value,disabled:l,placeholder:"Scroll to see all options",formPart:!0,triggerProps:{className:T(m)}})}),e.jsx(b,{})]})}),e.jsx(g,{control:s.control,name:"taxCategory",render:({field:d,fieldState:m})=>e.jsxs(v,{children:[e.jsx(f,{children:"Tax Category"}),e.jsx(y,{children:e.jsx(He,{data:a,disabled:n,value:d.value,onChange:d.onChange,placeholder:"Scroll to see all options",formPart:!0,triggerProps:{className:T(m)}})}),e.jsx(b,{})]})}),e.jsx(g,{control:s.control,name:"pcn874RecordType",render:({field:d,fieldState:m})=>e.jsxs(v,{children:[e.jsx(f,{children:"PCN874 Record Type"}),e.jsxs(Cs,{onValueChange:d.onChange,value:d.value,children:[e.jsx(y,{children:e.jsx(As,{className:T(m),children:e.jsx(ws,{})})}),e.jsx(Is,{children:Object.entries(fa).map(([p,u])=>e.jsx(ks,{value:p,children:`${u} (${p})`},p))})]}),e.jsx(b,{})]})}),e.jsx(g,{control:s.control,name:"irsCode",render:({field:d,fieldState:m})=>e.jsxs(v,{children:[e.jsx(f,{children:"IRS Code"}),e.jsx(y,{children:e.jsx(ya,{value:d.value??void 0,onValueChange:p=>d.onChange(p??null),hideControls:!0,decimalScale:0,className:T(m)})}),e.jsx(b,{})]})}),e.jsx(g,{control:s.control,name:"description",render:({field:d,fieldState:m})=>e.jsxs(v,{children:[e.jsx(f,{children:"Charge Description"}),e.jsx(y,{children:e.jsx(A,{placeholder:"Enter default charge description",...d,className:T(m)})}),e.jsx(b,{})]})}),e.jsx(g,{control:s.control,name:"tags",render:({field:d,fieldState:m})=>e.jsxs(v,{children:[e.jsx(f,{children:"Tags"}),e.jsx(y,{children:e.jsx(Na,{options:Object.values(r).map(({value:p,label:u})=>({label:u,value:p})),onValueChange:d.onChange,defaultValue:d.value,value:d.value,placeholder:"Select Default Tags",variant:"default",disabled:i,className:T(m)})}),e.jsx(b,{})]})})]})]})}function Dt({form:s}){const[a,n]=C.useState(""),[t,l]=C.useState(""),o=()=>{if(a.trim()){const d=s.getValues("phrases");s.setValue("phrases",[...d,a.trim()],{shouldDirty:!0}),n("")}},r=()=>{if(t.trim()){const d=s.getValues("emails");s.setValue("emails",[...d,t.trim()],{shouldDirty:!0}),l("")}},i=d=>{const m=s.getValues("phrases");s.setValue("phrases",m.filter((p,u)=>u!==d),{shouldDirty:!0})},h=d=>{const m=s.getValues("emails");s.setValue("emails",m.filter((p,u)=>u!==d),{shouldDirty:!0})};return e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-sm font-semibold text-foreground",children:"Auto-matching Configuration"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Configure patterns for automatic matching of bank transactions and documents"}),e.jsx(g,{control:s.control,name:"phrases",render:({field:d,fieldState:m})=>e.jsxs(v,{children:[e.jsx(f,{children:"Phrases"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(A,{placeholder:"Add phrase...",value:a,onChange:p=>n(p.target.value),onKeyDown:p=>{p.key==="Enter"&&(p.preventDefault(),o())},className:T(m)}),e.jsx(S,{type:"button",size:"sm",onClick:o,children:e.jsx(ae,{className:"h-4 w-4"})})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:d.value?.map((p,u)=>e.jsxs(te,{variant:"secondary",className:"gap-1",children:[p,e.jsx(S,{variant:"ghost",size:"icon",className:"p-0 size-3",onClick:()=>i(u),children:e.jsx(ne,{className:"size-3 cursor-pointer",onClick:()=>i(u)})})]},u))}),e.jsx(b,{})]})}),e.jsx(g,{control:s.control,name:"emails",render:({field:d,fieldState:m})=>e.jsxs(v,{children:[e.jsx(f,{children:"Email Addresses"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(A,{type:"email",placeholder:"Add email...",value:t,onChange:p=>l(p.target.value),onKeyDown:p=>{p.key==="Enter"&&(p.preventDefault(),r())},className:T(m)}),e.jsx(S,{type:"button",size:"sm",onClick:r,children:e.jsx(ae,{className:"h-4 w-4"})})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:d.value?.map((p,u)=>e.jsxs(te,{variant:"secondary",className:"gap-1",children:[p,e.jsx(S,{variant:"ghost",size:"icon",className:"p-0 size-3",onClick:()=>h(u),children:e.jsx(ne,{className:"size-3 cursor-pointer"})})]},u))}),e.jsx(b,{})]})})]})}function St({form:s}){const[a,n]=C.useState(""),t=()=>{if(a.trim()){const r=s.getValues("internalLinks");s.setValue("internalLinks",[...r,a.trim()],{shouldDirty:!0}),n("")}},l=r=>{const i=s.getValues("attachmentTypes");s.setValue("attachmentTypes",i?.includes(r)?i.filter(h=>h!==r):[...i,r],{shouldDirty:!0})},o=r=>{const i=s.getValues("internalLinks");s.setValue("internalLinks",i.filter((h,d)=>d!==r),{shouldDirty:!0})};return e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-sm font-semibold text-foreground",children:"Gmail Feature Configuration"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Configure Gmail integration settings for document processing"}),e.jsx(g,{control:s.control,name:"attachmentTypes",render:({field:r,fieldState:i})=>e.jsxs(v,{children:[e.jsx(f,{children:"Attachment Types"}),e.jsx("div",{className:T(i)+" rounded-md flex flex-wrap gap-2",children:Ct.map(h=>e.jsx(te,{variant:r.value?.includes(h)?"default":"outline",className:"cursor-pointer",onClick:()=>l(h),children:h},h))}),e.jsx(b,{})]})}),e.jsx(g,{control:s.control,name:"internalLinks",render:({field:r,fieldState:i})=>e.jsxs(v,{children:[e.jsx(f,{children:"Internal Links"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(A,{type:"url",placeholder:"Add internal link...",value:a,onChange:h=>n(h.target.value),onKeyDown:h=>{h.key==="Enter"&&(h.preventDefault(),t())}}),e.jsx(S,{type:"button",size:"sm",onClick:t,children:e.jsx(ae,{className:"h-4 w-4"})})]}),e.jsx("div",{className:T(i)+" flex flex-wrap gap-2 rounded-md",children:r.value?.map((h,d)=>e.jsxs(te,{variant:"secondary",className:"gap-1 max-w-xs truncate",children:[h,e.jsx(S,{variant:"ghost",size:"icon",className:"p-0 size-3",onClick:()=>o(d),children:e.jsx(ne,{className:"size-3 cursor-pointer flex-shrink-0"})})]},d))}),e.jsx(b,{})]})}),e.jsx(g,{control:s.control,name:"useMessageBody",render:({field:r,fieldState:i})=>e.jsxs(v,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(f,{children:"Should Use Message Body"}),e.jsx(de,{children:"Extract information from email message body"})]}),e.jsx(y,{children:e.jsx(re,{checked:r.value,onCheckedChange:r.onChange,className:T(i)})})]})})]})}const Tt=ue({businessName:M().min(1,"Business name is required"),locality:M().min(1,"Locality is required"),localName:M().optional(),govId:M().optional(),address:M().optional(),localAddress:M().optional(),phone:M().optional(),website:Ia("Invalid URL").optional().or(ka("")),generalContacts:me(rs()).optional(),billingEmails:me(rs()).optional()});function ps(s){return!s||s.__typename!=="LtdFinancialEntity"?{}:{businessName:s.name,locality:s.country,localName:s.hebrewName??void 0,govId:s.governmentId??void 0,address:s.address??void 0,phone:s.phoneNumber??void 0,website:s.website??void 0,generalContacts:s.email?.split(",").map(a=>a.trim()),billingEmails:s.clientInfo?.emails}}function Bt(s){return{name:s.businessName,country:s.locality,hebrewName:s.localName,governmentId:s.govId,address:s.address,phoneNumber:s.phone,website:s.website,email:s.generalContacts?.join(", ")}}function Et({data:s,refetchBusiness:a}){const n=we(wa,s),[t,l]=C.useState(ps(n)),{userContext:o}=C.useContext(ss),{updateBusiness:r,fetching:i}=$s(),{updateClient:h,fetching:d}=Es(),m=Pe({resolver:Xe(Tt),defaultValues:t}),{countries:p,fetching:u}=Ca(),[j,w]=C.useState(""),[I,B]=C.useState(""),F=m.watch("locality"),P=m.watch("address"),R=m.watch("localAddress");C.useEffect(()=>{P!==t.address&&m.setValue("address",P,{shouldDirty:!0})},[P,t.address,m]),C.useEffect(()=>{R!==t.localAddress&&m.setValue("localAddress",R,{shouldDirty:!0})},[R,t.localAddress,m]);const z=n&&"clientInfo"in n&&!!n.clientInfo,_=F===o?.context.locality,G=x=>{j.trim()&&(m.setValue("generalContacts",[...x,j.trim()],{shouldDirty:!0}),w(""))},c=(x,N)=>{m.setValue("generalContacts",x.filter((E,L)=>L!==N),{shouldDirty:!0})},O=x=>{I.trim()&&(m.setValue("billingEmails",[...x,I.trim()],{shouldDirty:!0}),B(""))},V=(x,N)=>{m.setValue("billingEmails",x.filter((E,L)=>L!==N),{shouldDirty:!0})},k=async x=>{if(!n||!o?.context.adminBusinessId)return;const N=Ze(x,m.formState.dirtyFields);if(!N)return;const E=Bt(N),L=[];Object.values(E).some(oe=>oe!=null)&&L.push(r({businessId:n.id,ownerId:o.context.adminBusinessId,fields:E})),z&&N.billingEmails&&L.push(h({businessId:n.id,fields:{emails:N.billingEmails}})),await Promise.all(L),a?.()};return C.useEffect(()=>{if(n){const x=ps(n);l(x),m.reset(x)}},[n,m]),e.jsxs(Y,{children:[e.jsxs(X,{children:[e.jsx(Q,{children:"Contact Information"}),e.jsx(J,{children:"Business contact details and address information"})]}),e.jsx(Oe,{...m,children:e.jsxs("form",{onSubmit:m.handleSubmit(k),children:[e.jsx(Z,{children:e.jsxs("div",{className:"grid gap-6 md:grid-cols-2",children:[e.jsx(g,{control:m.control,name:"businessName",render:({field:x,fieldState:N})=>e.jsxs(v,{children:[e.jsx(f,{children:"Business Name"}),e.jsx(y,{children:e.jsx(A,{...x,className:T(N)})}),e.jsx(b,{})]})}),e.jsx(g,{control:m.control,name:"locality",render:({field:x,fieldState:N})=>e.jsxs(v,{children:[e.jsx(f,{children:"Locality / Country"}),e.jsx(He,{onChange:x.onChange,data:p.map(E=>({value:E.code,label:E.name})),value:x.value,disabled:u,placeholder:"Scroll to see all options",formPart:!0,triggerProps:{className:T(N)}}),e.jsx(b,{})]})}),_&&e.jsx(g,{control:m.control,name:"localName",render:({field:x,fieldState:N})=>e.jsxs(v,{children:[e.jsx(f,{children:"Local Name"}),e.jsx(y,{children:e.jsx(A,{...x,placeholder:"Business name in local language",className:T(N)})}),e.jsx(b,{})]})}),e.jsx(g,{control:m.control,name:"govId",render:({field:x,fieldState:N})=>e.jsxs(v,{children:[e.jsx(f,{children:"Government ID"}),e.jsx(y,{children:e.jsx(A,{...x,placeholder:"Enter Government ID",className:T(N)})}),e.jsx(b,{})]})}),e.jsx(g,{control:m.control,name:"address",render:({field:x,fieldState:N})=>e.jsxs(v,{className:"md:col-span-2",children:[e.jsxs(f,{className:"flex items-center gap-2",children:[e.jsx(Ue,{className:"h-4 w-4"}),"Address"]}),e.jsx(y,{children:e.jsx(is,{...x,rows:3,placeholder:"Enter business address",className:T(N)})}),e.jsx(b,{})]})}),_&&e.jsx(g,{control:m.control,name:"localAddress",render:({field:x,fieldState:N})=>e.jsxs(v,{className:"md:col-span-2",children:[e.jsxs(f,{className:"flex items-center gap-2",children:[e.jsx(Ue,{className:"h-4 w-4"}),"Local Address"]}),e.jsx(y,{children:e.jsx(is,{...x,rows:3,placeholder:"Enter address in local language",className:T(N)})}),e.jsx(b,{})]})}),e.jsx(g,{control:m.control,name:"phone",render:({field:x,fieldState:N})=>e.jsxs(v,{children:[e.jsxs(f,{className:"flex items-center gap-2",children:[e.jsx(Ps,{className:"h-4 w-4"}),"Phone"]}),e.jsx(y,{children:e.jsx(A,{...x,type:"tel",placeholder:"+1 (555) 123-4567",className:T(N)})}),e.jsx(b,{})]})}),e.jsx(g,{control:m.control,name:"website",render:({field:x,fieldState:N})=>e.jsxs(v,{children:[e.jsxs(f,{className:"flex items-center gap-2",children:[e.jsx(Aa,{className:"h-4 w-4"}),"Website"]}),e.jsx(y,{children:e.jsx(A,{...x,type:"url",placeholder:"https://example.com",className:T(N)})}),e.jsx(b,{})]})}),e.jsx(g,{control:m.control,name:"generalContacts",render:({field:x,fieldState:N})=>e.jsxs(v,{className:"md:col-span-2",children:[e.jsxs(f,{className:"flex items-center gap-2",children:[e.jsx(ze,{className:"h-4 w-4"}),"General Contacts"]}),e.jsx(y,{children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:T(N)+" flex flex-wrap gap-2 mb-2 rounded-md",children:x.value?.map((E,L)=>e.jsxs(te,{variant:"secondary",className:"gap-1 pr-1",children:[E,e.jsx("button",{type:"button",onClick:()=>c(x.value??[],L),className:"ml-1 hover:bg-muted rounded-sm p-0.5",children:e.jsx(ne,{className:"h-3 w-3"})})]},L))}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(A,{value:j,onChange:E=>w(E.target.value),onKeyDown:E=>{E.key==="Enter"&&(E.preventDefault(),G(x.value??[]))},placeholder:"Add contact email",type:"email"}),e.jsx(S,{type:"button",variant:"outline",size:"icon",disabled:!j.trim(),onClick:()=>G(x.value??[]),children:e.jsx(ae,{className:"h-4 w-4"})})]})]})}),e.jsx(b,{})]})}),z&&e.jsx(g,{control:m.control,name:"billingEmails",render:({field:x,fieldState:N})=>e.jsxs(v,{className:"md:col-span-2",children:[e.jsxs(f,{className:"flex items-center gap-2",children:[e.jsx(ze,{className:"h-4 w-4"}),"Billing Emails"]}),e.jsx(y,{children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:T(N)+" flex flex-wrap gap-2 mb-2 rounded-md",children:x.value?.map((E,L)=>e.jsxs(te,{variant:"secondary",className:"gap-1 pr-1",children:[E,e.jsx("button",{type:"button",onClick:()=>V(x.value??[],L),className:"ml-1 hover:bg-muted rounded-sm p-0.5",children:e.jsx(ne,{className:"h-3 w-3"})})]},L))}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(A,{value:I,onChange:E=>B(E.target.value),onKeyDown:E=>{E.key==="Enter"&&(E.preventDefault(),O(x.value??[]))},placeholder:"Add billing email",type:"email"}),e.jsx(S,{type:"button",variant:"outline",size:"icon",disabled:!I.trim(),onClick:()=>O(x.value??[]),children:e.jsx(ae,{className:"h-4 w-4"})})]})]})}),e.jsx(b,{})]})})]})}),e.jsx(Qe,{className:"flex justify-end border-t mt-4 pt-6",children:e.jsxs(S,{type:"submit",disabled:i||d||Object.keys(m.formState.dirtyFields).length===0,children:[e.jsx(as,{className:"h-4 w-4 mr-2"}),"Save Changes"]})})]})})]})}function Pt({businessId:s}){return e.jsxs(Y,{children:[e.jsx(X,{children:e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{children:[e.jsx(Q,{children:"Documents"}),e.jsx(J,{children:"Invoices, proformas, receipts, and other accounting documents"})]})})}),e.jsx(Z,{children:e.jsx(Da,{businessId:s,linkedDocumentIds:[],limit:1e3})})]})}function Ot({businessId:s}){const[{data:a,fetching:n}]=le({query:Sa,variables:{businessId:s}});return n?e.jsx("div",{children:"Loading ledger records..."}):e.jsxs(Y,{children:[e.jsx(X,{className:"flex w-full justify-between items-center",children:e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{children:[e.jsx(Q,{children:"Ledger Records"}),e.jsx(J,{children:"Complete ledger history for this business"})]})})}),e.jsx(Z,{children:e.jsx("div",{className:"rounded-md border",children:e.jsx(qa,{ledgerRecordsData:a?.ledgerRecordsByFinancialEntity??[]})})})]})}function Lt({businessId:s}){const[{data:a,fetching:n}]=le({query:Ta,variables:{businessId:s}});return n?e.jsx("div",{children:"Loading transactions..."}):e.jsxs(Y,{children:[e.jsx(X,{className:"flex w-full justify-between items-center",children:e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{children:[e.jsx(Q,{children:"Transactions"}),e.jsx(J,{children:"Complete transaction history for this business"})]})})}),e.jsx(Z,{children:e.jsx("div",{className:"rounded-md border",children:e.jsx(gn,{transactionsProps:a?.transactionsByFinancialEntity??[]})})})]})}function Ft({data:s,refetchBusiness:a}){const n=we(_a,s),[t,l]=Ba(),{setFiltersContext:o}=C.useContext(Ea);C.useEffect(()=>{o(null)},[o]);const r=t.get("tab")||"contact",i=m=>{l({tab:m})};if(!n)return e.jsx("div",{children:"Business not found"});const h="clientInfo"in n&&!!n.clientInfo,d="adminInfo"in n&&!!n.adminInfo;return e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx(za,{data:n}),e.jsx("main",{className:"container mx-auto px-4 py-6 md:px-6 lg:px-8 max-w-7xl",children:e.jsxs(Pa,{value:r,onValueChange:i,className:"w-full",children:[e.jsxs(Oa,{className:"grid w-full lg:grid-cols-8 sm:grid-cols-4 grid-cols-8 mb-6 h-auto gap-1 bg-muted/50 p-1",children:[e.jsxs(ee,{value:"contact",className:"flex items-center gap-2 data-[state=active]:bg-background",children:[e.jsx(De,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Contact"})]}),e.jsxs(ee,{value:"config",className:"flex items-center gap-2 data-[state=active]:bg-background",children:[e.jsx(Os,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Config"})]}),e.jsxs(ee,{value:"charges",className:"flex items-center gap-2 data-[state=active]:bg-background",children:[e.jsx(Se,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Charges"})]}),e.jsxs(ee,{value:"transactions",className:"flex items-center gap-2 data-[state=active]:bg-background",children:[e.jsx(La,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Transactions"})]}),e.jsxs(ee,{value:"documents",className:"flex items-center gap-2 data-[state=active]:bg-background",children:[e.jsx(Fa,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Documents"})]}),e.jsxs(ee,{value:"ledger",className:"flex items-center gap-2 data-[state=active]:bg-background",children:[e.jsx(Pn,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Ledger"})]}),e.jsxs(ee,{value:"balance",className:"flex items-center gap-2 data-[state=active]:bg-background",children:[e.jsx(An,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Balance"})]}),h&&e.jsxs(e.Fragment,{children:[e.jsxs(ee,{value:"contracts",className:"flex items-center gap-2 data-[state=active]:bg-background",children:[e.jsx(Sn,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Contracts"})]}),e.jsxs(ee,{value:"integrations",className:"flex items-center gap-2 data-[state=active]:bg-background",children:[e.jsx(Ln,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Integrations"})]})]}),d&&e.jsxs(e.Fragment,{children:[e.jsxs(ee,{value:"accounts",className:"flex items-center gap-2 data-[state=active]:bg-background",children:[e.jsx(Ga,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Accounts"})]}),e.jsxs(ee,{value:"admin",className:"flex items-center gap-2 data-[state=active]:bg-background",children:[e.jsx(vs,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Admin"})]})]})]}),e.jsx(W,{value:"contact",className:"mt-0",children:e.jsx(Et,{data:n,refetchBusiness:a})}),e.jsx(W,{value:"config",className:"mt-0",children:e.jsx(wt,{data:n,refetchBusiness:a})}),e.jsx(W,{value:"charges",className:"mt-0",children:e.jsx(st,{businessId:n.id})}),e.jsx(W,{value:"transactions",className:"mt-0",children:e.jsx(Lt,{businessId:n.id})}),e.jsx(W,{value:"documents",className:"mt-0",children:e.jsx(Pt,{businessId:n.id})}),e.jsx(W,{value:"ledger",className:"mt-0",children:e.jsx(Ot,{businessId:n.id})}),e.jsx(W,{value:"balance",className:"mt-0",children:e.jsx(et,{businessId:n.id})}),h&&e.jsxs(e.Fragment,{children:[e.jsx(W,{value:"contracts",className:"mt-0",children:e.jsx(ft,{clientId:n.id})}),e.jsx(W,{value:"integrations",className:"mt-0",children:e.jsx(Nt,{data:n})}),e.jsx(W,{value:"charts",className:"mt-0",children:e.jsx(gt,{})})]}),d&&e.jsxs(e.Fragment,{children:[e.jsx(W,{value:"accounts",className:"mt-0",children:e.jsx(Zn,{adminId:n.id})}),e.jsx(W,{value:"admin",className:"mt-0",children:e.jsx(zn,{data:n})})]})]})})]})}const li=()=>{const{businessId:s}=Ma();let a;try{a=Ra()}catch{}const[{data:n,fetching:t},l]=le({query:Va,pause:!s||!!a,variables:{businessId:s??""}}),o=a||n;return!a&&t&&!o?.business?e.jsx(gs,{}):!s||!o?.business?e.jsx("div",{children:"Business not found"}):e.jsx(Ft,{data:o.business,refetchBusiness:async()=>l()})};export{li as BusinessScreen};
|
package/dist/assets/{business-extended-info-NwMS1Rj6.js → business-extended-info-BzvYZDrX.js}
RENAMED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{j as e,m as S,aK as H,ai as z,R as F,w as D,ay as d,bs as _,bM as h,bP as B,b_ as G,r as c,dk as Z,u as ee,e3 as te,bU as ne,aO as f,bK as V,bL as k,bN as O,bO as P,e4 as se,I as ae,bV as re,bW as oe,B as ie,bX as le,bY as ce,bZ as me,ao as ue,ap as de,aq as ge,ar as xe,as as fe,P as he,c0 as pe,b$ as we,c1 as be,c2 as je}from"./index-
|
|
1
|
+
import{j as e,m as S,aK as H,ai as z,R as F,w as D,ay as d,bs as _,bM as h,bP as B,b_ as G,r as c,dk as Z,u as ee,e3 as te,bU as ne,aO as f,bK as V,bL as k,bN as O,bO as P,e4 as se,I as ae,bV as re,bW as oe,B as ie,bX as le,bY as ce,bZ as me,ao as ue,ap as de,aq as ge,ar as xe,as as fe,P as he,c0 as pe,b$ as we,c1 as be,c2 as je}from"./index-3R_zL83W.js";import{D as p}from"./data-table-column-header-C23SEs2k.js";import{D as Ce}from"./download-csv-button-DDfbg2Ju.js";const Se=({amount:t})=>!t||t.raw===0?e.jsx("span",{className:"text-sm text-gray-400",children:"—"}):e.jsx("span",{className:S("text-sm font-medium whitespace-nowrap",t.raw>0?"text-green-700":"text-red-600"),children:t.formatted}),Ne=({balance:t,currency:r})=>{if(t===0)return e.jsx("span",{className:"text-sm text-gray-400",children:"—"});const n=H(t,r);return e.jsx("span",{className:S("text-sm font-medium whitespace-nowrap",t>0?"text-green-700":"text-red-600"),children:n})},ye=({business:t})=>e.jsx(z,{to:F.BUSINESSES.DETAIL(t.id),target:"_blank",rel:"noopener noreferrer",onClick:r=>r.stopPropagation(),className:"inline-flex items-center font-semibold whitespace-nowrap",children:t.name}),Ae=({counterAccount:t})=>t?e.jsx(z,{to:F.BUSINESSES.DETAIL(t.id),target:"_blank",rel:"noopener noreferrer",onClick:r=>r.stopPropagation(),className:"inline-flex items-center font-semibold whitespace-nowrap text-sm",children:t.name}):e.jsx("span",{className:"text-sm text-gray-400",children:"—"}),Ie=({row:t,currency:r})=>{const n=t.foreignAmount&&t.foreignAmount.currency===r?t.foreignAmount:null;return!n||n.raw===0?e.jsx("span",{className:"text-sm text-gray-400",children:"—"}):e.jsx("span",{className:S("text-sm font-medium whitespace-nowrap",n.raw>0?"text-green-700":"text-red-600"),children:n.formatted})},ve=({row:t,currency:r})=>{const n=`${r.toLowerCase()}Balance`,a=t[n]??0;if(a===0)return e.jsx("span",{className:"text-sm text-gray-400",children:"—"});const l=H(a,r);return e.jsx("span",{className:S("text-sm font-medium whitespace-nowrap",a>0?"text-green-700":"text-red-600"),children:l})},De=({date:t})=>t?e.jsx("span",{className:"text-sm font-medium whitespace-nowrap",children:D(new Date(t),"dd/MM/yy")}):e.jsx("span",{className:"text-sm text-gray-400",children:"—"}),Be=()=>[{accessorKey:"business.name",id:"businessName",header:"Business Name",cell:({row:t})=>e.jsx(ye,{business:t.original.business}),enableSorting:!1,enableHiding:!1},{accessorKey:"invoiceDate",id:"date",header:({column:t})=>e.jsx(p,{column:t,title:"Date"}),cell:({row:t})=>e.jsx(De,{date:t.original.invoiceDate}),sortingFn:"datetime"},{accessorKey:"amount.raw",id:"amount",header:({column:t})=>e.jsx(p,{column:t,title:"Amount"}),cell:({row:t})=>e.jsx(Se,{amount:t.original.amount}),sortingFn:"basic"},{accessorKey:"ilsBalance",id:"ilsBalance",header:({column:t})=>e.jsx(p,{column:t,title:"Amount Balance"}),cell:({row:t})=>e.jsx(Ne,{balance:t.original.ilsBalance,currency:d.Ils}),sortingFn:"basic"}],Fe=()=>Object.values(d).filter(n=>n!==d.Ils).sort((n,a)=>{const l=_.includes(n),m=_.includes(a);return l&&!m?-1:!l&&m?1:n.localeCompare(a)}).flatMap(n=>[{id:`${n.toLowerCase()}Amount`,accessorFn:a=>a.foreignAmount?.currency===n?a.foreignAmount.raw:null,header:({column:a})=>e.jsx(p,{column:a,title:`${n} Amount`}),cell:({row:a})=>e.jsx(Ie,{row:a.original,currency:n}),sortingFn:"basic",enableHiding:!0},{id:`${n.toLowerCase()}Balance`,accessorFn:a=>a[`${n.toLowerCase()}Balance`]??null,header:({column:a})=>e.jsx(p,{column:a,title:`${n} Balance`}),cell:({row:a})=>e.jsx(ve,{row:a.original,currency:n}),sortingFn:"basic",enableHiding:!0}]),$e=()=>[{accessorKey:"reference",id:"reference",header:"Reference",cell:({row:t})=>e.jsx("p",{className:"text-sm whitespace-nowrap",children:t.original.reference??""}),enableSorting:!1},{accessorKey:"details",id:"details",header:"Details",cell:({row:t})=>e.jsx("p",{className:"text-sm whitespace-nowrap",children:t.original.details??""}),enableSorting:!1},{accessorKey:"counterAccount.name",id:"counterAccount",header:"Counter Account",cell:({row:t})=>e.jsx(Ae,{counterAccount:t.original.counterAccount}),enableSorting:!1}],Me=()=>[...Be(),...Fe(),...$e()],Re=t=>{const r={};for(const n of Object.values(d).filter(a=>a!==d.Ils)){const a=t.has(n),l=`${n.toLowerCase()}Amount`,m=`${n.toLowerCase()}Balance`;a||(r[l]=!1,r[m]=!1)}return r},Te=({row:t})=>{const r=n=>{n.stopPropagation(),window.open(F.CHARGES.DETAIL(t.original.chargeId),"_blank","noopener noreferrer")};return e.jsx(h,{onClick:r,className:"cursor-pointer hover:bg-gray-50 transition-colors",children:t.getVisibleCells().map(n=>e.jsx(B,{children:G(n.column.columnDef.cell,n.getContext())},n.id))})},Ee=({ledgerRecords:t,businessName:r,fromDate:n,toDate:a})=>{const l=c.useCallback(async()=>{const m=Le(t);return{fileName:`business_${r}_ledger_records${n?`_${n}`:""}${a?`_${a}`:""}`,fileContent:m}},[t,r,n,a]);return e.jsx(Ce,{createFileVariables:l})},Le=t=>{let r="";const n=Array.from(new Set(t.filter(a=>a.foreignAmount?.currency).map(a=>a.foreignAmount.currency)));r+=`Sorting Date,Date,Amount,Amount Balance,${_e(n)}Reference,Details,Counter Account\r
|
|
2
2
|
`;for(const a of t){const l=ke(a,n);r+=l}return r};function _e(t){let r="";return t.map(n=>{const a=Z(n);r+=`${n}(${a}) Amount,${n}(${a}) Balance,`}),r}function Ve(t,r){let n="";return r.map(a=>{t.foreignAmount&&t.foreignAmount.currency===a?n+=`${t.foreignAmount.raw},${t[`${a.toLowerCase()}Balance`]??0},`:n+=",,"}),n}function ke(t,r){let n="";const a=t.invoiceDate?D(new Date(t.invoiceDate),"yyy-MM-dd"):null,l=t.invoiceDate?D(new Date(t.invoiceDate),"dd/MM/yy"):null,m=t.amount.raw,{ilsBalance:x,reference:w,details:N}=t,y=t.counterAccount?.name??"";return n+=`${a},${l},${m},${x},${Ve(t,r)}${v(w??"")},${v(N??"")},${v(y)},\r
|
|
3
3
|
`,n}function v(t){return t===""?"":Number.isNaN(Number(t))?String(t).replace(/"/g,'""').replace(/,/g,"."):Number(t).toFixed(2).toString()}const K="businessLedger",C={SORTING:`${K}_sorting`,COLUMN_VISIBILITY:`${K}_columnVisibility`};function He({businessID:t,filter:r}){const[n,a]=c.useState(()=>{try{const s=localStorage.getItem(C.SORTING);return s?JSON.parse(s):[]}catch{return[]}}),[l,m]=c.useState([]),[x,w]=c.useState(""),[N,y]=c.useState({pageIndex:0,pageSize:50});c.useEffect(()=>{try{localStorage.setItem(C.SORTING,JSON.stringify(n))}catch(s){console.warn("Failed to save sorting to localStorage:",s)}},[n]);const{fromDate:U,ownerIds:Y,toDate:J}=r??{},[{data:A,fetching:q}]=ee({query:te,variables:{filters:{fromDate:U,ownerIds:Y,toDate:J,businessIDs:[t]}}}),g=c.useMemo(()=>A?.businessTransactionsFromLedgerRecords.__typename==="CommonError"?[]:A?.businessTransactionsFromLedgerRecords.businessTransactions.sort((s,o)=>s.invoiceDate>o.invoiceDate?1:-1)??[],[A]),$=c.useMemo(()=>{const s=[];for(let o=0;o<g.length;o++){const{__typename:X,...u}=g[o],Q=o===0?u.amount.raw:(s[o-1].ilsBalance??0)+u.amount.raw,E={};Object.values(d).map(j=>{if(j!==d.Ils){const L=`${j.toLowerCase()}Balance`;E[L]=o===0?(u.foreignAmount?.currency===j?u.foreignAmount?.raw:0)??0:(s[o-1]?.[L]??0)+(u.foreignAmount?.currency===j?u.foreignAmount?.raw:0)}}),s.push({...u,ilsBalance:Q,...E})}return s},[g]),M=c.useMemo(()=>new Set(g.filter(s=>s.foreignAmount?.currency).map(s=>s.foreignAmount.currency)),[g]),R=Me(),b=c.useMemo(()=>Re(M),[M]),[I,T]=c.useState(()=>{try{const s=localStorage.getItem(C.COLUMN_VISIBILITY);if(s){const o=JSON.parse(s);return{...b,...o}}}catch{}return b});c.useEffect(()=>{try{localStorage.setItem(C.COLUMN_VISIBILITY,JSON.stringify(I))}catch(s){console.warn("Failed to save column visibility to localStorage:",s)}},[I]),c.useEffect(()=>{T(s=>({...b,...s}))},[b]);const i=ne({data:$,columns:R,getCoreRowModel:je(),getSortedRowModel:be(),getFilteredRowModel:we(),getPaginationRowModel:pe(),onSortingChange:a,onColumnFiltersChange:m,onColumnVisibilityChange:T,onGlobalFilterChange:w,onPaginationChange:y,globalFilterFn:"includesString",state:{sorting:n,columnFilters:l,columnVisibility:I,globalFilter:x,pagination:N}}),W=g[0]?.business.name??"unknown";return q?e.jsxs("div",{className:"flex flex-col gap-4 max-w-[90vw] m-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(f,{className:"h-10 w-64"}),e.jsx(f,{className:"h-10 w-32"})]}),e.jsx(f,{className:"size-10"})]}),e.jsx("div",{className:"rounded-md border overflow-x-auto",children:e.jsxs(V,{children:[e.jsx(k,{children:e.jsx(h,{children:Array.from({length:8}).map((s,o)=>e.jsx(O,{children:e.jsx(f,{className:"h-4 w-24"})},o))})}),e.jsx(P,{children:Array.from({length:5}).map((s,o)=>e.jsx(h,{children:Array.from({length:8}).map((X,u)=>e.jsx(B,{children:e.jsx(f,{className:"h-4 w-full"})},u))},o))})]})})]}):e.jsxs("div",{className:"flex flex-col gap-4 max-w-[90vw] m-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4 flex-wrap",children:[e.jsxs("div",{className:"flex items-center gap-4 flex-wrap",children:[e.jsxs("div",{className:"relative flex-1 min-w-[200px] max-w-sm",children:[e.jsx(se,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-gray-500"}),e.jsx(ae,{placeholder:"Search reference, details, business...",value:x??"",onChange:s=>w(s.target.value),className:"pl-8"})]}),e.jsxs(re,{children:[e.jsx(oe,{asChild:!0,children:e.jsxs(ie,{variant:"outline",size:"sm",children:[e.jsx(le,{className:"mr-2 h-4 w-4"}),"Columns"]})}),e.jsx(ce,{align:"end",className:"max-h-96 overflow-y-auto",children:i.getAllColumns().filter(s=>s.getCanHide()).map(s=>e.jsx(me,{className:"capitalize",checked:s.getIsVisible(),onCheckedChange:o=>s.toggleVisibility(!!o),children:s.id},s.id))})]})]}),e.jsx(Ee,{ledgerRecords:$,businessName:W,fromDate:r?.fromDate??void 0,toDate:r?.toDate??void 0})]}),e.jsx("div",{className:"rounded-md border overflow-x-auto",children:e.jsxs(V,{children:[e.jsx(k,{className:"sticky top-0 z-20 bg-white border-b",children:i.getHeaderGroups().map(s=>e.jsx(h,{children:s.headers.map(o=>e.jsx(O,{colSpan:o.colSpan,children:o.isPlaceholder?null:G(o.column.columnDef.header,o.getContext())},o.id))},s.id))}),e.jsx(P,{children:i.getRowModel().rows?.length?i.getRowModel().rows.map(s=>e.jsx(Te,{row:s},s.id)):e.jsx(h,{children:e.jsx(B,{colSpan:R.length,className:"h-24 text-center",children:"No transactions found."})})})]})}),e.jsxs("div",{className:"flex items-center justify-between gap-4 flex-wrap",children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs("p",{className:"text-sm text-gray-700",children:["Showing"," ",i.getState().pagination.pageIndex*i.getState().pagination.pageSize+1," to"," ",Math.min((i.getState().pagination.pageIndex+1)*i.getState().pagination.pageSize,i.getFilteredRowModel().rows.length)," ","of ",i.getFilteredRowModel().rows.length," transactions"]})}),e.jsxs("div",{className:"flex items-center gap-6",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"text-sm font-medium",children:"Rows per page:"}),e.jsxs(ue,{value:String(i.getState().pagination.pageSize),onValueChange:s=>{i.setPageSize(Number(s))},children:[e.jsx(de,{className:"h-8 w-[70px]",children:e.jsx(ge,{placeholder:i.getState().pagination.pageSize})}),e.jsx(xe,{side:"top",children:[25,50,100,200,500].map(s=>e.jsx(fe,{value:String(s),children:s},s))})]})]}),e.jsx(he,{className:"w-fit mx-0",currentPageIndex:i.getState().pagination.pageIndex,totalPages:i.getPageCount(),onChange:s=>i.setPageIndex(s)})]})]})]})}export{He as B};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{G as l,j as e,ag as t,w as m,bp as x}from"./index-
|
|
1
|
+
import{G as l,j as e,ag as t,w as m,bp as x}from"./index-3R_zL83W.js";import{B as o}from"./building-2-Bg-rF-On.js";function h({data:n}){const s=l(x,n);if(!s||s.__typename!=="LtdFinancialEntity")return e.jsx("div",{});const{isActive:i,adminInfo:r,clientInfo:a}=s,d=!!r?.id,c=!!a?.id;return e.jsx("header",{className:"sticky top-0 z-50 w-full border-b border-border bg-card/95 backdrop-blur supports-[backdrop-filter]:bg-card/60",children:e.jsx("div",{className:"container mx-auto px-4 md:px-6 lg:px-8 max-w-7xl",children:e.jsxs("div",{className:"flex h-16 items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0 flex-1",children:[e.jsx("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-lg bg-accent",children:e.jsx(o,{className:"h-5 w-5 text-accent-foreground"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("h1",{className:"text-lg font-semibold text-foreground",children:s.name}),i?e.jsx(t,{variant:"secondary",children:"Active"}):e.jsx(t,{variant:"destructive",children:"Inactive"}),d&&e.jsx(t,{variant:"outline",children:"Admin"}),c&&e.jsx(t,{variant:"outline",children:"Client"})]}),e.jsxs("p",{className:"text-sm text-muted-foreground truncate",children:["Business ID: ",s.id]})]})]}),e.jsxs("div",{className:"hidden md:flex items-center gap-6 text-sm",children:[s.governmentId&&e.jsxs("div",{className:"text-right",children:[e.jsx("p",{className:"text-muted-foreground",children:"Tax ID"}),e.jsx("p",{className:"font-medium text-foreground",children:s.governmentId})]}),e.jsxs("div",{className:"text-right",children:[e.jsx("p",{className:"text-muted-foreground",children:"Since"}),e.jsx("p",{className:"font-medium text-foreground",children:m(s.createdAt,"MMM yyyy")})]})]})]})})})}export{h as B};
|