@accounter/client 0.0.8-alpha-20251029234818-bb69914cb7aaa4859296baa4a256c251158fd15b → 0.0.8-alpha-20251030162201-d2f279aafe537912ec3546af855cbd3a38ac0f5c
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 +2 -2
- package/dist/assets/{Checkbox-ChZFYaBU.js → Checkbox-qEdmT4HE.js} +2 -2
- package/dist/assets/{MultiSelect-h-orVW8D.js → MultiSelect-Dm9mO7pJ.js} +1 -1
- package/dist/assets/{Progress-DVn-HXq3.js → Progress-kr0gnfBa.js} +1 -1
- package/dist/assets/{Table-B88LD0fO.js → Table-DnHfGe-y.js} +1 -1
- package/dist/assets/{Typography-DSr2wXoh.js → Typography-Cu3puAUK.js} +1 -1
- package/dist/assets/{YearPickerInput-DQjO6Nmm.js → YearPickerInput-oa86GF4P.js} +1 -1
- package/dist/assets/{accordion-vlJV5349.js → accordion-DLtMSqIv.js} +1 -1
- package/dist/assets/accountant-approvals-DsL0uiBa.js +1 -0
- package/dist/assets/accounter-table-BL_yrGIl.js +1 -0
- package/dist/assets/{addDays-CiW9nfcU.js → addDays-DqZEDZy3.js} +1 -1
- package/dist/assets/all-charges-D3Xf-pEY.js +1 -0
- package/dist/assets/{arrow-up-down-DCZ98zEE.js → arrow-up-down-DchtBEG4.js} +1 -1
- package/dist/assets/{building-2-MkMlc3HY.js → building-2-ZTKteVvf.js} +1 -1
- package/dist/assets/{business-BIPODXgU.js → business-CAcKSrnu.js} +3 -3
- package/dist/assets/{business-extended-info-CFdeLUKP.js → business-extended-info-1mzdXJbs.js} +4 -4
- package/dist/assets/{business-header-pPq6w0Xw.js → business-header-CJqfKV4d.js} +1 -1
- package/dist/assets/{business-ledger-filters-ClJxXoLC.js → business-ledger-filters-BRB1r_DP.js} +1 -1
- package/dist/assets/business-ledger-single-C8FIQJ8V.js +1 -0
- package/dist/assets/business-trip-DkTEY8b1.js +1 -0
- package/dist/assets/charge-Df3lWZH-.js +1 -0
- package/dist/assets/charges-filters-DUuY-N0H.js +1 -0
- package/dist/assets/charges-ledger-validation-CtCBR3C-.js +1 -0
- package/dist/assets/{charges-table-eZes2r5b.js → charges-table-CWbe3t13.js} +7 -7
- package/dist/assets/{chart-BiPB-6_s.js → chart-Cmm-jp0c.js} +1 -1
- package/dist/assets/{data-table-pagination-D9orF6C5.js → data-table-pagination-fdOZTf64.js} +1 -1
- package/dist/assets/{download-csv-button-DUWRJL2T.js → download-csv-button-CwK31swX.js} +1 -1
- package/dist/assets/{editable-business-trip-BhXW_0XH.js → editable-business-trip-Bjxkm9xV.js} +2 -2
- package/dist/assets/{funnel-DrJtNpvJ.js → funnel-CMG4QvaK.js} +1 -1
- package/dist/assets/index-6G62OvEh.js +1 -0
- package/dist/assets/{index-CsYsahJ3.js → index-B9CbQIGq.js} +1 -1
- package/dist/assets/index-BD4s2ucv.css +1 -0
- package/dist/assets/{index-BG_PTq9Q.js → index-BEahR51x.js} +2 -2
- package/dist/assets/index-BFwWHKS1.js +1 -0
- package/dist/assets/index-BI0XToIk.js +1 -0
- package/dist/assets/index-BQb_C-JL.js +1 -0
- package/dist/assets/{index-BsEpUd8e.js → index-BZVrGMgV.js} +2 -2
- package/dist/assets/{index-CQwkSv45.js → index-C7oYbGGm.js} +1 -1
- package/dist/assets/index-CJQlHnFs.js +1 -0
- package/dist/assets/{index-DCJnXE5L.js → index-CTatkdRy.js} +1 -1
- package/dist/assets/{index-ZqxiihxR.js → index-C_ZNQ0Zr.js} +1 -1
- package/dist/assets/{index-Dl0o8K5Z.js → index-CgokSIpu.js} +7 -7
- package/dist/assets/{index-B0hUbUBg.js → index-CjC_SXIA.js} +1 -1
- package/dist/assets/index-Cm6Blkgf.js +1 -0
- package/dist/assets/{index-CKSGCsKO.js → index-CriBDqbK.js} +1 -1
- package/dist/assets/{index-CuoWV8xf.js → index-Cw_aKL-8.js} +173 -173
- package/dist/assets/{index-BNmy1oek.js → index-DFW4nqx8.js} +7 -7
- package/dist/assets/{index-HAjwT8i6.js → index-DInU4RP4.js} +2 -2
- package/dist/assets/{index-BidQYESH.js → index-DJLQkpmI.js} +2 -2
- package/dist/assets/index-DLwMwjDQ.js +1 -0
- package/dist/assets/{index-1EyW0AOu.js → index-DcwGbXWr.js} +1 -1
- package/dist/assets/index-Dlj3jpuW.js +1 -0
- package/dist/assets/index-iya2tfvn.js +1 -0
- package/dist/assets/{index-BHVgafF5.js → index-jCPWIpdP.js} +1 -1
- package/dist/assets/index-xxe8M91O.js +6 -0
- package/dist/assets/{index.es-BiiexU-G.js → index.es-B_Bf6nNm.js} +1 -1
- package/dist/assets/{insert-business-trip-modal-CkXaCqH7.js → insert-business-trip-modal-Ds3RIlmF.js} +2 -2
- package/dist/assets/issue-document-_iHCFO9h.js +1 -0
- package/dist/assets/{list-plus-BPyHtPSB.js → list-plus-B3EB-dKe.js} +1 -1
- package/dist/assets/login-page-BtT_TCEJ.js +1 -0
- package/dist/assets/{match-document-modal-BZOEBBCt.js → match-document-modal-Bo9pBr8W.js} +4 -4
- package/dist/assets/missing-info-charges-BQYXI7bj.js +1 -0
- package/dist/assets/{modal-CguzFJgR.js → modal-Pj_6bAFk.js} +1 -1
- package/dist/assets/{page-layout-jOFfeRt_.js → page-layout-CVTeUSZp.js} +1 -1
- package/dist/assets/{page-not-found-ghVdWRX4.js → page-not-found-TvTAiAs4.js} +1 -1
- package/dist/assets/{panel-top-open-BLNJL6FI.js → panel-top-open-DzBY_TuM.js} +1 -1
- package/dist/assets/{pencil-DePZCoA1.js → pencil-BBmFhuZN.js} +1 -1
- package/dist/assets/{report-commentary-row-bJgTfAoe.js → report-commentary-row-Dqw62LLo.js} +1 -1
- package/dist/assets/{save-DDATKcb8.js → save-BW18gNVs.js} +1 -1
- package/dist/assets/similar-transactions-modal-B39q1NLa.js +1 -0
- package/dist/assets/{sub-CUQX8erq.js → sub-DOjETdwl.js} +1 -1
- package/dist/assets/subMonths-DqeFZ4O6.js +1 -0
- package/dist/assets/summary-Bbsq64IN.js +1 -0
- package/dist/assets/{toggle-expansion-button-BarJY9rA.js → toggle-expansion-button-BrKkZtGj.js} +1 -1
- package/dist/assets/tooltip-CbnJYNc4.js +1 -0
- package/dist/assets/{use-url-query-CMqziw3P.js → use-url-query-C0mVgO2i.js} +1 -1
- package/dist/index.html +2 -2
- package/package.json +1 -1
- package/src/components/business/charges-section.tsx +5 -5
- package/src/components/businesses/businesses-filters.tsx +7 -2
- package/src/components/charges/charges-filters.tsx +8 -3
- package/src/components/common/accounter-table.tsx +1 -3
- package/src/components/common/index.ts +1 -0
- package/src/components/common/pagination.tsx +84 -0
- package/src/components/ledger-table/index.tsx +15 -8
- package/src/components/transactions-table/index.tsx +11 -5
- package/src/components/ui/pagination.tsx +3 -99
- package/dist/assets/Pagination-CraTfR0n.js +0 -1
- package/dist/assets/accountant-approvals-DOxFOZAO.js +0 -1
- package/dist/assets/accounter-table-D9Vunjfy.js +0 -1
- package/dist/assets/all-charges-bPDT5kwM.js +0 -1
- package/dist/assets/business-ledger-single-BOtdOkme.js +0 -1
- package/dist/assets/business-trip-6WyqArkv.js +0 -1
- package/dist/assets/charge-BbtacTJ9.js +0 -1
- package/dist/assets/charges-filters-Ir-7TzSP.js +0 -1
- package/dist/assets/charges-ledger-validation-6prUhTM_.js +0 -1
- package/dist/assets/create-event-handler-BiA-1lGu.js +0 -1
- package/dist/assets/index--ZcPa6E_.js +0 -1
- package/dist/assets/index-2OCszu-l.js +0 -1
- package/dist/assets/index-BKcxKTE4.js +0 -1
- package/dist/assets/index-BUJm5I0K.css +0 -1
- package/dist/assets/index-Crk-yNk8.js +0 -1
- package/dist/assets/index-DVm5mt8x.js +0 -6
- package/dist/assets/index-DmOniXdt.js +0 -1
- package/dist/assets/index-SAaZFNWd.js +0 -1
- package/dist/assets/index-XNTNgbUr.js +0 -1
- package/dist/assets/index-jf6jgMhL.js +0 -1
- package/dist/assets/index-z10NcX_S.js +0 -1
- package/dist/assets/issue-document-IUlUh6n7.js +0 -1
- package/dist/assets/login-page-CGLD1xCA.js +0 -1
- package/dist/assets/missing-info-charges-C1QWCAWR.js +0 -1
- package/dist/assets/similar-transactions-modal-BxhD4UyN.js +0 -1
- package/dist/assets/subMonths-QOcbO9QP.js +0 -1
- package/dist/assets/summary-CBR-TMN0.js +0 -1
- package/dist/assets/tooltip-BFYX9MeB.js +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{v as ne,w as we,S as Te,x as ce,u as ie,y as zs,r as C,j as e,D as Xe,z as Je,E as Us,c as vs,g as Be,t as $,i as Pe,U as qs,G as Le,H as Qe,J as Ie,K as Se,N as G,O as W,
|
|
1
|
+
import{v as ne,w as we,S as Te,x as ce,u as ie,y as zs,r as C,j as e,D as Xe,z as Je,E as Us,c as vs,g as Be,t as $,i as Pe,U as qs,G as Le,H as Qe,J as Ie,K as Se,N as G,O as W,Q as ys,V as K,W as H,X as Oe,Y,Z as y,_ as N,$ as b,a0 as w,I as k,a1 as T,a2 as I,a3 as ge,B as D,a4 as M,a5 as Q,a6 as oe,a7 as Ze,a8 as Gs,a9 as Ae,aa as es,ab as te,ac as R,ad as ss,ae as ze,af as as,ag as Ws,P as Ks,ah as Hs,ai as V,aj as ls,ak as Ys,al as Xs,am as Js,an as ae,ao as ee,ap as Qs,aq as Zs,ar as ea,as as Ue,at as fe,au as ve,av as ye,aw as Ne,ax as sa,ay as be,az as aa,aA as ta,aB as se,aC as na,aD as ia,aE as qe,aF as Ge,aG as Ns,aH as ra,aI as We,aJ as la,aK as bs,aL as cs,aM as Cs,aN as ca,aO as oa,aP as ts,aQ as ws,aR as ns,aS as As,aT as Is,aU as Ss,aV as Ds,aW as ks,aX as Ts,aY as da,aZ as xe,a_ as ma,a$ as ua,b0 as ha,b1 as xa,b2 as pa,b3 as ja,b4 as ga,b5 as fa,b6 as va,b7 as S,b8 as ya,b9 as is,ba as Na,bb as ba,bc as Ca,bd as wa,F as Aa,be as Ia,bf as Sa,bg as J,bh as Da,bi as ka,bj as U,bk as Ta,a as Ea,b as Ba,bl as Pa}from"./index-Cw_aKL-8.js";import{S as rs}from"./save-BW18gNVs.js";import{B as La}from"./business-extended-info-1mzdXJbs.js";import{B as Oa}from"./business-header-CJqfKV4d.js";import{S as Fa,C as Va,L as _a}from"./charges-table-CWbe3t13.js";import{i as Ra,D as Ma,f as $a,E as za,L as Ve,a as De,C as Ua,A as qa,b as pe,c as Ga,d as Ke,h as Wa,e as Ka,g as Es,u as Ha,G as Ya,j as os,k as Xa,X as Bs,Y as Ps,l as Ja,m as Qa,R as Za,n as et,o as st,p as at}from"./chart-Cmm-jp0c.js";import{P as tt}from"./pencil-BBmFhuZN.js";import{E as nt,T as it}from"./index-xxe8M91O.js";import{A as rt,a as _e,b as Re,c as ds}from"./accordion-DLtMSqIv.js";import{B as lt}from"./building-2-ZTKteVvf.js";import"./download-csv-button-CwK31swX.js";import"./Table-DnHfGe-y.js";import"./toggle-expansion-button-BrKkZtGj.js";import"./panel-top-open-DzBY_TuM.js";import"./summary-Bbsq64IN.js";import"./list-plus-B3EB-dKe.js";import"./sequential-CAnleQny.js";import"./similar-transactions-modal-B39q1NLa.js";import"./addDays-DqZEDZy3.js";import"./tooltip-CbnJYNc4.js";/**
|
|
2
2
|
* @license lucide-react v0.548.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -33,5 +33,5 @@ import{v as ne,w as we,S as Te,x as ce,u as ie,y as zs,r as C,j as e,D as Xe,z a
|
|
|
33
33
|
*
|
|
34
34
|
* This source code is licensed under the ISC license.
|
|
35
35
|
* See the LICENSE file in the root directory of this source tree.
|
|
36
|
-
*/const ft=[["path",{d:"M16 7h6v6",key:"box55l"}],["path",{d:"m22 7-8.5 8.5-5-5L2 17",key:"1t1m79"}]],Me=ne("trending-up",ft);function Ls(s){switch(s){case we.Annual:return"Annual";case we.Monthly:return"Monthly";default:throw new Error(`Unsupported Billing Cycle: ${s}`)}}function Os(s){switch(s){case Te.Enterprise:return"Enterprise";case Te.Pro:return"Pro";default:throw new Error(`Unsupported Subscription plan: ${s}`)}}function vt(s){return ce(s,"yyyy-MM-dd")}function yt({businessId:s,tagIds:a,description:t,open:n,onOpenChange:l,onClose:o}){const[{data:r,fetching:i},c]=ie({pause:!0,query:zs,variables:{businessId:s,tagsDifferentThan:a?a.map(u=>u.id):void 0,descriptionDifferentThan:t}});C.useEffect(()=>{n&&(a||t)&&!r&&c()},[n,a,t,c,r]);const d=C.useCallback(u=>{l(u),n&&!u&&o?.()},[l,o,n]),h=C.useMemo(()=>n&&(!!a||!!t)&&r&&r?.similarChargesByBusiness.length>0,[n,a,t,r]);return e.jsx(Xe,{open:h,onOpenChange:d,children:e.jsx(Je,{className:"overflow-scroll max-h-screen w-full sm:max-w-[640px] md:max-w-[768px] lg:max-w-[900px]",onClick:u=>u.stopPropagation(),children:e.jsx(Us,{fallback:e.jsx("div",{children:"Error fetching similar charges"}),children:i?e.jsx(vs,{}):a||t?e.jsx(Oa,{data:r?.similarChargesByBusiness??[],tagIds:a,description:t,onOpenChange:d,title:"Similar Charges by Business"}):null})})})}const Nt="updateAdminBusiness",bt=()=>{const[{fetching:s},a]=Be(qs),t=C.useCallback(async n=>{const l=`Error updating admin business ID [${n.adminBusinessId}]`,o=`${Nt}-${n.adminBusinessId}`;$.loading("Updating admin business",{id:o});try{const r=await a(n),i=Pe(r,l,o,"updateAdminBusiness");if(i)return $.success("Success",{id:o,description:"Admin Business Updated"}),i.updateAdminBusiness}catch(r){console.error(`${l}: ${r}`),$.error("Error",{id:o,description:l,duration:1e5,closeButton:!0})}},[a]);return{fetching:s,updateAdminBusiness:t}},$e=Ae({year:ss().min(2e3).max(2100),id:R().min(1,{message:"ID is required"})}),Ct=Ae({registrationDate:R().min(1,{message:"Business Registration Start Date is required"}),withholdingTaxAnnualIds:te($e),withholdingTaxCompanyId:R().min(1,{message:"Withholding Tax Company ID is required"}),socialSecurityEmployerIds:te($e),socialSecurityDeductionsId:R().min(1,{message:"Social Security Deductions ID is required"}),taxAdvancesAnnualIds:te($e),taxAdvancesRates:te(Ae({date:ze(),rate:ss().min(0,{message:"Rate must be at least 0"}).max(100,{message:"Rate must be at most 100"})}))});function us(s){return!s||s.__typename!=="LtdFinancialEntity"||!s.adminInfo?{}:{registrationDate:s.adminInfo.registrationDate,withholdingTaxAnnualIds:s.adminInfo.withholdingTaxAnnualIds.sort((a,t)=>t.year-a.year),withholdingTaxCompanyId:s.adminInfo.withholdingTaxCompanyId??void 0,socialSecurityEmployerIds:s.adminInfo.socialSecurityEmployerIds.sort((a,t)=>t.year-a.year),socialSecurityDeductionsId:s.adminInfo.socialSecurityDeductionsId??void 0,taxAdvancesAnnualIds:s.adminInfo.taxAdvancesAnnualIds.sort((a,t)=>t.year-a.year),taxAdvancesRates:s.adminInfo.taxAdvancesRates?.map(a=>({date:a.date,rate:a.rate*100}))}}function wt(s){return{registrationDate:s.registrationDate?vt(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 At({data:s,refetchBusiness:a}){const t=Ie(Gs,s),[n,l]=C.useState(us(t)),{updateAdminBusiness:o,fetching:r}=bt(),i=Le({resolver:Qe(Ct),defaultValues:n}),c=async x=>{if(!t)return;const j=es(x,i.formState.dirtyFields);if(!j)return;const P=wt(j);await o({adminBusinessId:t.id,fields:P}),a?.()};C.useEffect(()=>{if(t){const x=us(t);l(x),i.reset(x)}},[t,i]);const{fields:d,append:h,remove:u}=Se({control:i.control,name:"taxAdvancesAnnualIds"}),{fields:p,append:g,remove:A}=Se({control:i.control,name:"withholdingTaxAnnualIds"}),{fields:E,append:B,remove:O}=Se({control:i.control,name:"socialSecurityEmployerIds"}),m={withholdingTaxAnnualIds:{append:g,remove:A},taxAdvancesAnnualIds:{append:h,remove:u},socialSecurityEmployerIds:{append:B,remove:O}},f=x=>{m[x].append({year:new Date().getFullYear(),id:""})},L=(x,j)=>{m[x].remove(j)},{fields:F,append:X,remove:z}=Se({control:i.control,name:"taxAdvancesRates"}),Z=()=>{X({date:ce(new Date,"yyyy-MM-dd"),rate:0})},v=x=>{z(x)};return e.jsxs(G,{children:[e.jsxs(W,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ys,{className:"h-5 w-5 text-primary"}),e.jsx(K,{children:"Admin Business Configuration"})]}),e.jsx(H,{children:"Tax and registration information for the business operating this application"})]}),e.jsx(Oe,{...i,children:e.jsxs("form",{onSubmit:i.handleSubmit(c),className:"space-y-6",children:[e.jsx(Y,{children:e.jsxs("div",{className:"grid gap-6 md:grid-cols-2",children:[e.jsx("h3",{className:"text-sm font-semibold text-foreground md:col-span-2",children:"Withholding Tax"}),e.jsx(y,{control:i.control,name:"withholdingTaxCompanyId",render:({field:x,fieldState:j})=>e.jsxs(N,{children:[e.jsx(b,{children:"Company Tax ID"}),e.jsx(w,{children:e.jsx(k,{placeholder:"Enter company ID",...x,className:T(j)})}),e.jsx(I,{})]})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(ge,{children:"Annual IDs"}),e.jsx(D,{type:"button",variant:"outline",size:"sm",onClick:()=>f("withholdingTaxAnnualIds"),children:e.jsx(M,{className:"size-4"})})]}),e.jsx("div",{className:"space-y-3",children:p.map((x,j)=>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(k,{placeholder:"Year",type:"number",...i.register(`withholdingTaxAnnualIds.${j}.year`,{valueAsNumber:!0})}),e.jsx(k,{placeholder:"ID",...i.register(`withholdingTaxAnnualIds.${j}.id`)})]}),e.jsx(D,{type:"button",variant:"ghost",size:"icon",onClick:()=>L("withholdingTaxAnnualIds",j),children:e.jsx(Q,{className:"size-4"})})]},x.id))})]}),e.jsx(oe,{className:"md:col-span-2"}),e.jsx("h3",{className:"text-sm font-semibold text-foreground md:col-span-2",children:"Tax Advances"}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(ge,{children:"Annual IDs"}),e.jsx(D,{type:"button",variant:"outline",size:"sm",onClick:()=>f("taxAdvancesAnnualIds"),children:e.jsx(M,{className:"size-4"})})]}),e.jsx("div",{className:"space-y-3",children:d.map((x,j)=>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(k,{placeholder:"Year",type:"number",...i.register(`taxAdvancesAnnualIds.${j}.year`,{valueAsNumber:!0})}),e.jsx(k,{placeholder:"ID",...i.register(`taxAdvancesAnnualIds.${j}.id`)})]}),e.jsx(D,{type:"button",variant:"ghost",size:"icon",onClick:()=>L("taxAdvancesAnnualIds",j),children:e.jsx(Q,{className:"size-4"})})]},x.id))})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(ge,{children:"Rates (%)"}),e.jsx(D,{type:"button",variant:"outline",size:"sm",onClick:Z,children:e.jsx(M,{className:"size-4"})})]}),e.jsx("div",{className:"space-y-3",children:F.map((x,j)=>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(k,{placeholder:"Date",type:"date",...i.register(`taxAdvancesRates.${j}.date`)}),e.jsx(k,{placeholder:"Rate",...i.register(`taxAdvancesRates.${j}.rate`,{valueAsNumber:!0})})]}),e.jsx(D,{type:"button",variant:"ghost",size:"icon",onClick:()=>v(j),children:e.jsx(Q,{className:"size-4"})})]},x.id))})]}),e.jsx(oe,{className:"md:col-span-2"}),e.jsx("h3",{className:"text-sm font-semibold text-foreground md:col-span-2",children:"Social Security"}),e.jsx(y,{control:i.control,name:"socialSecurityDeductionsId",render:({field:x,fieldState:j})=>e.jsxs(N,{children:[e.jsx(b,{children:"Deductions ID"}),e.jsx(w,{children:e.jsx(k,{placeholder:"Enter deductions ID",...x,className:T(j)})}),e.jsx(I,{})]})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(ge,{children:"Annual Employer IDs"}),e.jsx(D,{type:"button",variant:"outline",size:"sm",onClick:()=>f("socialSecurityEmployerIds"),children:e.jsx(M,{className:"size-4"})})]}),e.jsx("div",{className:"space-y-3",children:E.map((x,j)=>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(k,{placeholder:"Year",type:"number",...i.register(`socialSecurityEmployerIds.${j}.year`,{valueAsNumber:!0})}),e.jsx(k,{placeholder:"ID",...i.register(`socialSecurityEmployerIds.${j}.id`)})]}),e.jsx(D,{type:"button",variant:"ghost",size:"icon",onClick:()=>L("socialSecurityEmployerIds",j),children:e.jsx(Q,{className:"size-4"})})]},x.id))})]}),e.jsx(oe,{className:"md:col-span-2"}),e.jsx(y,{control:i.control,name:"registrationDate",render:({field:x,fieldState:j})=>e.jsxs(N,{children:[e.jsx(b,{children:"Business Registration Start Date"}),e.jsx(w,{children:e.jsx(k,{type:"date",...x,className:T(j)})}),e.jsx(I,{})]})})]})}),e.jsx(Ze,{className:"flex justify-end border-t mt-4 pt-6",children:e.jsxs(D,{type:"submit",disabled:r||Object.keys(i.formState.dirtyFields).length===0||!i.formState.isValid,children:[e.jsx(rs,{className:"h-4 w-4"}),"Save Changes"]})})]})})]})}function It({businessId:s}){return e.jsxs(G,{children:[e.jsx(W,{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(K,{children:"Balance"}),e.jsx(H,{children:"Business balance overview"})]})})}),e.jsx(Y,{children:e.jsx("div",{className:"rounded-md border",children:e.jsx(Pa,{businessID:s,filter:{}})})})]})}function St({businessId:s}){const{userContext:a}=C.useContext(as),[t,n]=C.useState(1),[{data:l,fetching:o}]=ie({query:Ws,variables:{filters:{byOwners:a?.context.adminBusinessId?[a.context.adminBusinessId]:void 0,sortBy:{field:Ks.Date,asc:!1},byBusinesses:[s]},page:t,limit:100}}),r=l?.allCharges?.pageInfo.totalPages??1,i=l?.allCharges?.nodes??[];return o?e.jsx("div",{children:"Loading charges..."}):e.jsxs(G,{children:[e.jsxs(W,{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(K,{children:"Charges"}),e.jsx(H,{children:"Recurring and one-time charges for this business"})]})}),r>1&&e.jsx(_a,{className:"flex-fit",value:t,onChange:n,total:r})]}),e.jsx(Y,{children:e.jsx("div",{className:"rounded-md border",children:e.jsx(Fa,{data:i,isAllOpened:!1})})})]})}var Dt=["type","layout","connectNulls","ref"],kt=["key"];function de(s){"@babel/helpers - typeof";return de=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},de(s)}function hs(s,a){if(s==null)return{};var t=Tt(s,a),n,l;if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(s);for(l=0;l<o.length;l++)n=o[l],!(a.indexOf(n)>=0)&&Object.prototype.propertyIsEnumerable.call(s,n)&&(t[n]=s[n])}return t}function Tt(s,a){if(s==null)return{};var t={};for(var n in s)if(Object.prototype.hasOwnProperty.call(s,n)){if(a.indexOf(n)>=0)continue;t[n]=s[n]}return t}function Ce(){return Ce=Object.assign?Object.assign.bind():function(s){for(var a=1;a<arguments.length;a++){var t=arguments[a];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(s[n]=t[n])}return s},Ce.apply(this,arguments)}function xs(s,a){var t=Object.keys(s);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(s);a&&(n=n.filter(function(l){return Object.getOwnPropertyDescriptor(s,l).enumerable})),t.push.apply(t,n)}return t}function _(s){for(var a=1;a<arguments.length;a++){var t=arguments[a]!=null?arguments[a]:{};a%2?xs(Object(t),!0).forEach(function(n){q(s,n,t[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(s,Object.getOwnPropertyDescriptors(t)):xs(Object(t)).forEach(function(n){Object.defineProperty(s,n,Object.getOwnPropertyDescriptor(t,n))})}return s}function le(s){return Lt(s)||Pt(s)||Bt(s)||Et()}function Et(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
|
|
37
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function Bt(s,a){if(s){if(typeof s=="string")return He(s,a);var t=Object.prototype.toString.call(s).slice(8,-1);if(t==="Object"&&s.constructor&&(t=s.constructor.name),t==="Map"||t==="Set")return Array.from(s);if(t==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return He(s,a)}}function Pt(s){if(typeof Symbol<"u"&&s[Symbol.iterator]!=null||s["@@iterator"]!=null)return Array.from(s)}function Lt(s){if(Array.isArray(s))return He(s)}function He(s,a){(a==null||a>s.length)&&(a=s.length);for(var t=0,n=new Array(a);t<a;t++)n[t]=s[t];return n}function Ot(s,a){if(!(s instanceof a))throw new TypeError("Cannot call a class as a function")}function ps(s,a){for(var t=0;t<a.length;t++){var n=a[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(s,Vs(n.key),n)}}function Ft(s,a,t){return a&&ps(s.prototype,a),t&&ps(s,t),Object.defineProperty(s,"prototype",{writable:!1}),s}function Vt(s,a,t){return a=Ee(a),_t(s,Fs()?Reflect.construct(a,t||[],Ee(s).constructor):a.apply(s,t))}function _t(s,a){if(a&&(de(a)==="object"||typeof a=="function"))return a;if(a!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return Rt(s)}function Rt(s){if(s===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return s}function Fs(){try{var s=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch{}return(Fs=function(){return!!s})()}function Ee(s){return Ee=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},Ee(s)}function Mt(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&&Ye(s,a)}function Ye(s,a){return Ye=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(n,l){return n.__proto__=l,n},Ye(s,a)}function q(s,a,t){return a=Vs(a),a in s?Object.defineProperty(s,a,{value:t,enumerable:!0,configurable:!0,writable:!0}):s[a]=t,s}function Vs(s){var a=$t(s,"string");return de(a)=="symbol"?a:a+""}function $t(s,a){if(de(s)!="object"||!s)return s;var t=s[Symbol.toPrimitive];if(t!==void 0){var n=t.call(s,a);if(de(n)!="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(s)}var me=(function(s){function a(){var t;Ot(this,a);for(var n=arguments.length,l=new Array(n),o=0;o<n;o++)l[o]=arguments[o];return t=Vt(this,a,[].concat(l)),q(t,"state",{isAnimationFinished:!0,totalLength:0}),q(t,"generateSimpleStrokeDasharray",function(r,i){return"".concat(i,"px ").concat(r-i,"px")}),q(t,"getStrokeDasharray",function(r,i,c){var d=c.reduce(function(O,m){return O+m});if(!d)return t.generateSimpleStrokeDasharray(i,r);for(var h=Math.floor(r/d),u=r%d,p=i-r,g=[],A=0,E=0;A<c.length;E+=c[A],++A)if(E+c[A]>u){g=[].concat(le(c.slice(0,A)),[u-E]);break}var B=g.length%2===0?[0,p]:[p];return[].concat(le(a.repeat(c,h)),le(g),B).map(function(O){return"".concat(O,"px")}).join(", ")}),q(t,"id",Ha("recharts-line-")),q(t,"pathRef",function(r){t.mainCurve=r}),q(t,"handleAnimationEnd",function(){t.setState({isAnimationFinished:!0}),t.props.onAnimationEnd&&t.props.onAnimationEnd()}),q(t,"handleAnimationStart",function(){t.setState({isAnimationFinished:!1}),t.props.onAnimationStart&&t.props.onAnimationStart()}),t}return Mt(a,s),Ft(a,[{key:"componentDidMount",value:function(){if(this.props.isAnimationActive){var n=this.getTotalLength();this.setState({totalLength:n})}}},{key:"componentDidUpdate",value:function(){if(this.props.isAnimationActive){var n=this.getTotalLength();n!==this.state.totalLength&&this.setState({totalLength:n})}}},{key:"getTotalLength",value:function(){var n=this.mainCurve;try{return n&&n.getTotalLength&&n.getTotalLength()||0}catch{return 0}}},{key:"renderErrorBar",value:function(n,l){if(this.props.isAnimationActive&&!this.state.isAnimationFinished)return null;var o=this.props,r=o.points,i=o.xAxis,c=o.yAxis,d=o.layout,h=o.children,u=$a(h,za);if(!u)return null;var p=function(E,B){return{x:E.x,y:E.y,value:E.value,errorVal:Es(E.payload,B)}},g={clipPath:n?"url(#clipPath-".concat(l,")"):null};return V.createElement(Ve,g,u.map(function(A){return V.cloneElement(A,{key:"bar-".concat(A.props.dataKey),data:r,xAxis:i,yAxis:c,layout:d,dataPointFormatter:p})}))}},{key:"renderDots",value:function(n,l,o){var r=this.props.isAnimationActive;if(r&&!this.state.isAnimationFinished)return null;var i=this.props,c=i.dot,d=i.points,h=i.dataKey,u=De(this.props,!1),p=De(c,!0),g=d.map(function(E,B){var O=_(_(_({key:"dot-".concat(B),r:3},u),p),{},{index:B,cx:E.x,cy:E.y,value:E.value,dataKey:h,payload:E.payload,points:d});return a.renderDotItem(c,O)}),A={clipPath:n?"url(#clipPath-".concat(l?"":"dots-").concat(o,")"):null};return V.createElement(Ve,Ce({className:"recharts-line-dots",key:"dots"},A),g)}},{key:"renderCurveStatically",value:function(n,l,o,r){var i=this.props,c=i.type,d=i.layout,h=i.connectNulls;i.ref;var u=hs(i,Dt),p=_(_(_({},De(u,!0)),{},{fill:"none",className:"recharts-line-curve",clipPath:l?"url(#clipPath-".concat(o,")"):null,points:n},r),{},{type:c,layout:d,connectNulls:h});return V.createElement(Ua,Ce({},p,{pathRef:this.pathRef}))}},{key:"renderCurveWithAnimation",value:function(n,l){var o=this,r=this.props,i=r.points,c=r.strokeDasharray,d=r.isAnimationActive,h=r.animationBegin,u=r.animationDuration,p=r.animationEasing,g=r.animationId,A=r.animateNewValues,E=r.width,B=r.height,O=this.state,m=O.prevPoints,f=O.totalLength;return V.createElement(qa,{begin:h,duration:u,isActive:d,easing:p,from:{t:0},to:{t:1},key:"line-".concat(g),onAnimationEnd:this.handleAnimationEnd,onAnimationStart:this.handleAnimationStart},function(L){var F=L.t;if(m){var X=m.length/i.length,z=i.map(function(P,Fe){var ue=Math.floor(Fe*X);if(m[ue]){var he=m[ue],re=pe(he.x,P.x),Rs=pe(he.y,P.y);return _(_({},P),{},{x:re(F),y:Rs(F)})}if(A){var Ms=pe(E*2,P.x),$s=pe(B/2,P.y);return _(_({},P),{},{x:Ms(F),y:$s(F)})}return _(_({},P),{},{x:P.x,y:P.y})});return o.renderCurveStatically(z,n,l)}var Z=pe(0,f),v=Z(F),x;if(c){var j="".concat(c).split(/[,\s]+/gim).map(function(P){return parseFloat(P)});x=o.getStrokeDasharray(v,f,j)}else x=o.generateSimpleStrokeDasharray(f,v);return o.renderCurveStatically(i,n,l,{strokeDasharray:x})})}},{key:"renderCurve",value:function(n,l){var o=this.props,r=o.points,i=o.isAnimationActive,c=this.state,d=c.prevPoints,h=c.totalLength;return i&&r&&r.length&&(!d&&h>0||!Ga(d,r))?this.renderCurveWithAnimation(n,l):this.renderCurveStatically(r,n,l)}},{key:"render",value:function(){var n,l=this.props,o=l.hide,r=l.dot,i=l.points,c=l.className,d=l.xAxis,h=l.yAxis,u=l.top,p=l.left,g=l.width,A=l.height,E=l.isAnimationActive,B=l.id;if(o||!i||!i.length)return null;var O=this.state.isAnimationFinished,m=i.length===1,f=ls("recharts-line",c),L=d&&d.allowDataOverflow,F=h&&h.allowDataOverflow,X=L||F,z=Ke(B)?this.id:B,Z=(n=De(r,!1))!==null&&n!==void 0?n:{r:3,strokeWidth:2},v=Z.r,x=v===void 0?3:v,j=Z.strokeWidth,P=j===void 0?2:j,Fe=Wa(r)?r:{},ue=Fe.clipDot,he=ue===void 0?!0:ue,re=x*2+P;return V.createElement(Ve,{className:f},L||F?V.createElement("defs",null,V.createElement("clipPath",{id:"clipPath-".concat(z)},V.createElement("rect",{x:L?p:p-g/2,y:F?u:u-A/2,width:L?g:g*2,height:F?A:A*2})),!he&&V.createElement("clipPath",{id:"clipPath-dots-".concat(z)},V.createElement("rect",{x:p-re/2,y:u-re/2,width:g+re,height:A+re}))):null,!m&&this.renderCurve(X,z),this.renderErrorBar(X,z),(m||r)&&this.renderDots(X,he,z),(!E||O)&&Ka.renderCallByParent(this.props,i))}}],[{key:"getDerivedStateFromProps",value:function(n,l){return n.animationId!==l.prevAnimationId?{prevAnimationId:n.animationId,curPoints:n.points,prevPoints:l.curPoints}:n.points!==l.curPoints?{curPoints:n.points}:null}},{key:"repeat",value:function(n,l){for(var o=n.length%2!==0?[].concat(le(n),[0]):n,r=[],i=0;i<l;++i)r=[].concat(le(r),le(o));return r}},{key:"renderDotItem",value:function(n,l){var o;if(V.isValidElement(n))o=V.cloneElement(n,l);else if(Ra(n))o=n(l);else{var r=l.key,i=hs(l,kt),c=ls("recharts-line-dot",typeof n!="boolean"?n.className:"");o=V.createElement(Ma,Ce({key:r},i,{className:c}))}return o}}])})(C.PureComponent);q(me,"displayName","Line");q(me,"defaultProps",{xAxisId:0,yAxisId:0,connectNulls:!1,activeDot:!0,dot:!0,legendType:"line",stroke:"#3182bd",strokeWidth:1,fill:"#fff",points:[],isAnimationActive:!Ya.isSsr,animateNewValues:!0,animationBegin:0,animationDuration:1500,animationEasing:"ease",hide:!1,label:!1});q(me,"getComposedData",function(s){var a=s.props,t=s.xAxis,n=s.yAxis,l=s.xAxisTicks,o=s.yAxisTicks,r=s.dataKey,i=s.bandSize,c=s.displayedData,d=s.offset,h=a.layout,u=c.map(function(p,g){var A=Es(p,r);return h==="horizontal"?{x:os({axis:t,ticks:l,bandSize:i,entry:p,index:g}),y:Ke(A)?null:n.scale(A),value:A,payload:p}:{x:Ke(A)?null:t.scale(A),y:os({axis:n,ticks:o,bandSize:i,entry:p,index:g}),value:A,payload:p}});return _({points:u,layout:h},d)});var zt=Xa({chartName:"LineChart",GraphicalChild:me,axisComponents:[{axisType:"xAxis",AxisComp:Bs},{axisType:"yAxis",AxisComp:Ps}],formatAxisMap:Ja});const je=[{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 Ut(){const s=je.reduce((t,n)=>t+n.revenue,0),a=s/je.length;return e.jsxs(G,{children:[e.jsxs(W,{children:[e.jsx(K,{children:"Revenue Analytics"}),e.jsx(H,{children:"Revenue and expenses over time"})]}),e.jsxs(Y,{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(ke,{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(Me,{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(ke,{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(Me,{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(ke,{className:"h-4 w-4"}),"Current Month"]}),e.jsxs("p",{className:"text-2xl font-bold",children:["$",je[je.length-1].revenue.toLocaleString()]}),e.jsxs("div",{className:"flex items-center gap-1 text-sm text-green-600",children:[e.jsx(Me,{className:"h-3 w-3"}),e.jsx("span",{children:"+8.0% from last month"})]})]})]}),e.jsx(Qa,{config:{revenue:{label:"Revenue",color:"hsl(var(--chart-1))"},expenses:{label:"Expenses",color:"hsl(var(--chart-2))"}},className:"h-[400px]",children:e.jsx(Za,{width:"100%",height:"100%",children:e.jsxs(zt,{data:je,margin:{top:5,right:10,left:10,bottom:5},children:[e.jsx(et,{strokeDasharray:"3 3",className:"stroke-muted"}),e.jsx(Bs,{dataKey:"month",className:"text-xs",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(Ps,{className:"text-xs",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(st,{content:e.jsx(at,{})}),e.jsx(me,{type:"monotone",dataKey:"revenue",stroke:"var(--color-revenue)",strokeWidth:2,dot:{fill:"var(--color-revenue)",r:4}}),e.jsx(me,{type:"monotone",dataKey:"expenses",stroke:"var(--color-expenses)",strokeWidth:2,dot:{fill:"var(--color-expenses)",r:4}})]})})})]})]})}const qt="updateBusiness",_s=()=>{const[{fetching:s},a]=Be(Hs),t=C.useCallback(async n=>{const l=`Error updating business ID [${n.businessId}]`,o=`${qt}-${n.businessId}`;$.loading("Updating business",{id:o});try{const r=await a(n),i=Pe(r,l,o,"updateBusiness");if(i)return $.success("Success",{id:o,description:"Business updated"}),i.updateBusiness}catch(r){console.error(`${l}: ${r}`),$.error("Error",{id:o,description:l,duration:1e5,closeButton:!0})}},[a]);return{fetching:s,updateBusiness:t}},Gt=Object.values(ta);function js(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 Wt(s){const t=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||t?{description:s.description,tags:s.tags?.map(o=>({id:o})),phrases:s.phrases,emails:s.emails,emailListener:t}: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 Kt({data:s,refetchBusiness:a}){const t=Ie(Xs,s),[n,l]=C.useState(js(t)),{userContext:o}=C.useContext(as),{updateBusiness:r,fetching:i}=_s(),[c,d]=C.useState(!1),[h,u]=C.useState(void 0),p=Le({defaultValues:n}),g=async E=>{if(!t||!o?.context.adminBusinessId)return;const B=es(E,p.formState.dirtyFields);if(!B)return;const O=Wt(B);await r({businessId:t.id,ownerId:o.context.adminBusinessId,fields:O}),B.tags?.length||B.description?(u({tagIds:B.tags?.map(m=>({id:m})),description:B.description}),d(!0)):a?.()};if(C.useEffect(()=>{if(t){const E=js(t);l(E),p.reset(E)}},[t,p]),!t)return e.jsx("div",{});const A=p.watch("isClient");return e.jsxs(G,{children:[e.jsx(W,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(K,{children:"Configurations"}),e.jsx(H,{children:"Business status, tax settings, automation rules, and integration preferences"})]}),!A&&e.jsx(Ys,{businessId:t.id,onDone:a})]})}),e.jsx(Oe,{...p,children:e.jsxs("form",{onSubmit:p.handleSubmit(g),children:[e.jsxs(Y,{className:"space-y-6",children:[e.jsx(Ht,{form:p}),e.jsx(oe,{}),e.jsx(Yt,{form:p}),e.jsx(oe,{}),e.jsx(Xt,{form:p}),e.jsx(oe,{}),e.jsx(Jt,{form:p})]}),e.jsx(Ze,{className:"flex justify-end border-t pt-6",children:e.jsxs(D,{type:"submit",disabled:i||Object.keys(p.formState.dirtyFields).length===0,children:[e.jsx(rs,{className:"h-4 w-4 mr-2"}),"Save Changes"]})})]})}),e.jsx(yt,{businessId:t.id,tagIds:h?.tagIds,description:h?.description,open:c,onOpenChange:d,onClose:a})]})}function Ht({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(y,{control:s.control,name:"isClient",render:({field:a,fieldState:t})=>e.jsxs(N,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(b,{children:"Is Client"}),e.jsx(ae,{children:"Mark this business as a client"})]}),e.jsx(w,{children:e.jsx(ee,{disabled:!0,checked:a.value,onCheckedChange:a.onChange,className:T(t)})})]})}),e.jsx(y,{control:s.control,name:"isActive",render:({field:a,fieldState:t})=>e.jsxs(N,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(b,{children:"Is Active"}),e.jsx(ae,{children:"Business is currently active"})]}),e.jsx(w,{children:e.jsx(ee,{checked:a.value,onCheckedChange:a.onChange,className:T(t)})})]})}),e.jsx(y,{control:s.control,name:"isReceiptEnough",render:({field:a,fieldState:t})=>e.jsxs(N,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(b,{children:"Is Receipt Enough"}),e.jsx(ae,{children:"Generate ledger for receipt documents if no invoice available"})]}),e.jsx(w,{children:e.jsx(ee,{checked:a.value,onCheckedChange:a.onChange,className:T(t)})})]})}),e.jsx(y,{control:s.control,name:"isDocumentsOptional",render:({field:a,fieldState:t})=>e.jsxs(N,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(b,{children:"No Docs Required"}),e.jsx(ae,{children:"Skip document validation for common charges"})]}),e.jsx(w,{children:e.jsx(ee,{checked:a.value,onCheckedChange:a.onChange,className:T(t)})})]})}),e.jsx(y,{control:s.control,name:"isVatOptional",render:({field:a,fieldState:t})=>e.jsxs(N,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(b,{children:"Is VAT Optional"}),e.jsx(ae,{children:"Mute missing VAT indicator"})]}),e.jsx(w,{children:e.jsx(ee,{checked:a.value,onCheckedChange:a.onChange,className:T(t)})})]})}),e.jsx(y,{control:s.control,name:"isExemptDealer",render:({field:a,fieldState:t})=>e.jsxs(N,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(b,{children:"Is Exempt Dealer"}),e.jsx(ae,{children:"Business is exempt from VAT requirements"})]}),e.jsx(w,{children:e.jsx(ee,{checked:a.value,onCheckedChange:a.onChange,className:T(t)})})]})})]})]})}function Yt({form:s}){const{selectableTaxCategories:a,fetching:t}=Js(),{selectableSortCodes:n,fetching:l,sortCodes:o}=Qs(),{selectableTags:r,fetching:i}=Zs(),c=C.useCallback(d=>{if(d){const h=o.find(u=>Number(u.key)===Number(d));h&&(h.defaultIrsCode?s.setValue("irsCode",h.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(y,{control:s.control,name:"sortCode",render:({field:d,fieldState:h})=>e.jsxs(N,{children:[e.jsx(b,{children:"Sort Code"}),e.jsx(w,{children:e.jsx(Ue,{onChange:u=>{c(u),d.onChange(u)},data:n,value:d.value,disabled:l,placeholder:"Scroll to see all options",formPart:!0,triggerProps:{className:T(h)}})}),e.jsx(I,{})]})}),e.jsx(y,{control:s.control,name:"taxCategory",render:({field:d,fieldState:h})=>e.jsxs(N,{children:[e.jsx(b,{children:"Tax Category"}),e.jsx(w,{children:e.jsx(Ue,{data:a,disabled:t,value:d.value,onChange:d.onChange,placeholder:"Scroll to see all options",formPart:!0,triggerProps:{className:T(h)}})}),e.jsx(I,{})]})}),e.jsx(y,{control:s.control,name:"pcn874RecordType",render:({field:d,fieldState:h})=>e.jsxs(N,{children:[e.jsx(b,{children:"PCN874 Record Type"}),e.jsxs(fe,{onValueChange:d.onChange,value:d.value,children:[e.jsx(w,{children:e.jsx(ve,{className:T(h),children:e.jsx(ye,{})})}),e.jsx(Ne,{children:Object.entries(ea).map(([u,p])=>e.jsx(be,{value:u,children:`${p} (${u})`},u))})]}),e.jsx(I,{})]})}),e.jsx(y,{control:s.control,name:"irsCode",render:({field:d,fieldState:h})=>e.jsxs(N,{children:[e.jsx(b,{children:"IRS Code"}),e.jsx(w,{children:e.jsx(sa,{value:d.value??void 0,onValueChange:u=>d.onChange(u??null),hideControls:!0,decimalScale:0,className:T(h)})}),e.jsx(I,{})]})}),e.jsx(y,{control:s.control,name:"description",render:({field:d,fieldState:h})=>e.jsxs(N,{children:[e.jsx(b,{children:"Charge Description"}),e.jsx(w,{children:e.jsx(k,{placeholder:"Enter default charge description",...d,className:T(h)})}),e.jsx(I,{})]})}),e.jsx(y,{control:s.control,name:"tags",render:({field:d,fieldState:h})=>e.jsxs(N,{children:[e.jsx(b,{children:"Tags"}),e.jsx(w,{children:e.jsx(aa,{options:Object.values(r).map(({value:u,label:p})=>({label:p,value:u})),onValueChange:d.onChange,defaultValue:d.value,value:d.value,placeholder:"Select Default Tags",variant:"default",disabled:i,className:T(h)})}),e.jsx(I,{})]})})]})]})}function Xt({form:s}){const[a,t]=C.useState(""),[n,l]=C.useState(""),o=()=>{if(a.trim()){const d=s.getValues("phrases");s.setValue("phrases",[...d,a.trim()],{shouldDirty:!0}),t("")}},r=()=>{if(n.trim()){const d=s.getValues("emails");s.setValue("emails",[...d,n.trim()],{shouldDirty:!0}),l("")}},i=d=>{const h=s.getValues("phrases");s.setValue("phrases",h.filter((u,p)=>p!==d),{shouldDirty:!0})},c=d=>{const h=s.getValues("emails");s.setValue("emails",h.filter((u,p)=>p!==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(y,{control:s.control,name:"phrases",render:({field:d,fieldState:h})=>e.jsxs(N,{children:[e.jsx(b,{children:"Phrases"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(k,{placeholder:"Add phrase...",value:a,onChange:u=>t(u.target.value),onKeyDown:u=>{u.key==="Enter"&&(u.preventDefault(),o())},className:T(h)}),e.jsx(D,{type:"button",size:"sm",onClick:o,children:e.jsx(M,{className:"h-4 w-4"})})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:d.value?.map((u,p)=>e.jsxs(se,{variant:"secondary",className:"gap-1",children:[u,e.jsx(D,{variant:"ghost",size:"icon",className:"p-0 size-3",onClick:()=>i(p),children:e.jsx(Q,{className:"size-3 cursor-pointer",onClick:()=>i(p)})})]},p))}),e.jsx(I,{})]})}),e.jsx(y,{control:s.control,name:"emails",render:({field:d,fieldState:h})=>e.jsxs(N,{children:[e.jsx(b,{children:"Email Addresses"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(k,{type:"email",placeholder:"Add email...",value:n,onChange:u=>l(u.target.value),onKeyDown:u=>{u.key==="Enter"&&(u.preventDefault(),r())},className:T(h)}),e.jsx(D,{type:"button",size:"sm",onClick:r,children:e.jsx(M,{className:"h-4 w-4"})})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:d.value?.map((u,p)=>e.jsxs(se,{variant:"secondary",className:"gap-1",children:[u,e.jsx(D,{variant:"ghost",size:"icon",className:"p-0 size-3",onClick:()=>c(p),children:e.jsx(Q,{className:"size-3 cursor-pointer"})})]},p))}),e.jsx(I,{})]})})]})}function Jt({form:s}){const[a,t]=C.useState(""),n=()=>{if(a.trim()){const r=s.getValues("internalLinks");s.setValue("internalLinks",[...r,a.trim()],{shouldDirty:!0}),t("")}},l=r=>{const i=s.getValues("attachmentTypes");s.setValue("attachmentTypes",i?.includes(r)?i.filter(c=>c!==r):[...i,r],{shouldDirty:!0})},o=r=>{const i=s.getValues("internalLinks");s.setValue("internalLinks",i.filter((c,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(y,{control:s.control,name:"attachmentTypes",render:({field:r,fieldState:i})=>e.jsxs(N,{children:[e.jsx(b,{children:"Attachment Types"}),e.jsx("div",{className:T(i)+" rounded-md flex flex-wrap gap-2",children:Gt.map(c=>e.jsx(se,{variant:r.value?.includes(c)?"default":"outline",className:"cursor-pointer",onClick:()=>l(c),children:c},c))}),e.jsx(I,{})]})}),e.jsx(y,{control:s.control,name:"internalLinks",render:({field:r,fieldState:i})=>e.jsxs(N,{children:[e.jsx(b,{children:"Internal Links"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(k,{type:"url",placeholder:"Add internal link...",value:a,onChange:c=>t(c.target.value),onKeyDown:c=>{c.key==="Enter"&&(c.preventDefault(),n())}}),e.jsx(D,{type:"button",size:"sm",onClick:n,children:e.jsx(M,{className:"h-4 w-4"})})]}),e.jsx("div",{className:T(i)+" flex flex-wrap gap-2 rounded-md",children:r.value?.map((c,d)=>e.jsxs(se,{variant:"secondary",className:"gap-1 max-w-xs truncate",children:[c,e.jsx(D,{variant:"ghost",size:"icon",className:"p-0 size-3",onClick:()=>o(d),children:e.jsx(Q,{className:"size-3 cursor-pointer flex-shrink-0"})})]},d))}),e.jsx(I,{})]})}),e.jsx(y,{control:s.control,name:"useMessageBody",render:({field:r,fieldState:i})=>e.jsxs(N,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(b,{children:"Should Use Message Body"}),e.jsx(ae,{children:"Extract information from email message body"})]}),e.jsx(w,{children:e.jsx(ee,{checked:r.value,onCheckedChange:r.onChange,className:T(i)})})]})})]})}const Qt=Ae({businessName:R().min(1,"Business name is required"),locality:R().min(1,"Locality is required"),localName:R().optional(),govId:R().optional(),address:R().optional(),localAddress:R().optional(),phone:R().optional(),website:bs("Invalid URL").optional().or(Cs("")),generalContacts:te(cs()).optional(),billingEmails:te(cs()).optional()});function gs(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 Zt(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 en({data:s,refetchBusiness:a}){const t=Ie(ra,s),[n,l]=C.useState(gs(t)),{userContext:o}=C.useContext(as),{updateBusiness:r,fetching:i}=_s(),c=Le({resolver:Qe(Qt),defaultValues:n}),{countries:d,fetching:h}=na(),[u,p]=C.useState(""),[g,A]=C.useState(""),E=c.watch("locality"),B=c.watch("address"),O=c.watch("localAddress");C.useEffect(()=>{B!==n.address&&c.setValue("address",B,{shouldDirty:!0})},[B,n.address,c]),C.useEffect(()=>{O!==n.localAddress&&c.setValue("localAddress",O,{shouldDirty:!0})},[O,n.localAddress,c]);const m=t&&"clientInfo"in t&&!!t.clientInfo,f=E===o?.context.locality,L=v=>{u.trim()&&(c.setValue("generalContacts",[...v,u.trim()],{shouldDirty:!0}),p(""))},F=(v,x)=>{c.setValue("generalContacts",v.filter((j,P)=>P!==x),{shouldDirty:!0})},X=v=>{g.trim()&&(c.setValue("billingEmails",[...v,g.trim()],{shouldDirty:!0}),A(""))},z=(v,x)=>{c.setValue("billingEmails",v.filter((j,P)=>P!==x),{shouldDirty:!0})},Z=async v=>{if(!t||!o?.context.adminBusinessId)return;const x=es(v,c.formState.dirtyFields);if(!x)return;const j=Zt(x);await r({businessId:t.id,ownerId:o.context.adminBusinessId,fields:j}),a?.()};return C.useEffect(()=>{if(t){const v=gs(t);l(v),c.reset(v)}},[t,c]),e.jsxs(G,{children:[e.jsxs(W,{children:[e.jsx(K,{children:"Contact Information"}),e.jsx(H,{children:"Business contact details and address information"})]}),e.jsx(Oe,{...c,children:e.jsxs("form",{onSubmit:c.handleSubmit(Z),children:[e.jsx(Y,{children:e.jsxs("div",{className:"grid gap-6 md:grid-cols-2",children:[e.jsx(y,{control:c.control,name:"businessName",render:({field:v,fieldState:x})=>e.jsxs(N,{children:[e.jsx(b,{children:"Business Name"}),e.jsx(w,{children:e.jsx(k,{...v,className:T(x)})}),e.jsx(I,{})]})}),e.jsx(y,{control:c.control,name:"locality",render:({field:v,fieldState:x})=>e.jsxs(N,{children:[e.jsx(b,{children:"Locality / Country"}),e.jsx(Ue,{onChange:v.onChange,data:d.map(j=>({value:j.code,label:j.name})),value:v.value,disabled:h,placeholder:"Scroll to see all options",formPart:!0,triggerProps:{className:T(x)}}),e.jsx(I,{})]})}),f&&e.jsx(y,{control:c.control,name:"localName",render:({field:v,fieldState:x})=>e.jsxs(N,{children:[e.jsx(b,{children:"Local Name"}),e.jsx(w,{children:e.jsx(k,{...v,placeholder:"Business name in local language",className:T(x)})}),e.jsx(I,{})]})}),f&&e.jsx(y,{control:c.control,name:"govId",render:({field:v,fieldState:x})=>e.jsxs(N,{children:[e.jsx(b,{children:"Government ID"}),e.jsx(w,{children:e.jsx(k,{...v,placeholder:"Enter Government ID",className:T(x)})}),e.jsx(I,{})]})}),e.jsx(y,{control:c.control,name:"address",render:({field:v,fieldState:x})=>e.jsxs(N,{className:"md:col-span-2",children:[e.jsxs(b,{className:"flex items-center gap-2",children:[e.jsx(qe,{className:"h-4 w-4"}),"Address"]}),e.jsx(w,{children:e.jsx(Ge,{...v,rows:3,placeholder:"Enter business address",className:T(x)})}),e.jsx(I,{})]})}),f&&e.jsx(y,{control:c.control,name:"localAddress",render:({field:v,fieldState:x})=>e.jsxs(N,{className:"md:col-span-2",children:[e.jsxs(b,{className:"flex items-center gap-2",children:[e.jsx(qe,{className:"h-4 w-4"}),"Local Address"]}),e.jsx(w,{children:e.jsx(Ge,{...v,rows:3,placeholder:"Enter address in local language",className:T(x)})}),e.jsx(I,{})]})}),e.jsx(y,{control:c.control,name:"phone",render:({field:v,fieldState:x})=>e.jsxs(N,{children:[e.jsxs(b,{className:"flex items-center gap-2",children:[e.jsx(Ns,{className:"h-4 w-4"}),"Phone"]}),e.jsx(w,{children:e.jsx(k,{...v,type:"tel",placeholder:"+1 (555) 123-4567",className:T(x)})}),e.jsx(I,{})]})}),e.jsx(y,{control:c.control,name:"website",render:({field:v,fieldState:x})=>e.jsxs(N,{children:[e.jsxs(b,{className:"flex items-center gap-2",children:[e.jsx(ia,{className:"h-4 w-4"}),"Website"]}),e.jsx(w,{children:e.jsx(k,{...v,type:"url",placeholder:"https://example.com",className:T(x)})}),e.jsx(I,{})]})}),e.jsx(y,{control:c.control,name:"generalContacts",render:({field:v,fieldState:x})=>e.jsxs(N,{className:"md:col-span-2",children:[e.jsxs(b,{className:"flex items-center gap-2",children:[e.jsx(We,{className:"h-4 w-4"}),"General Contacts"]}),e.jsx(w,{children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:T(x)+" flex flex-wrap gap-2 mb-2 rounded-md",children:v.value?.map((j,P)=>e.jsxs(se,{variant:"secondary",className:"gap-1 pr-1",children:[j,e.jsx("button",{type:"button",onClick:()=>F(v.value??[],P),className:"ml-1 hover:bg-muted rounded-sm p-0.5",children:e.jsx(Q,{className:"h-3 w-3"})})]},P))}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(k,{value:u,onChange:j=>p(j.target.value),onKeyDown:j=>{j.key==="Enter"&&(j.preventDefault(),L(v.value??[]))},placeholder:"Add contact email",type:"email"}),e.jsx(D,{type:"button",variant:"outline",size:"icon",disabled:!u.trim(),onClick:()=>L(v.value??[]),children:e.jsx(M,{className:"h-4 w-4"})})]})]})}),e.jsx(I,{})]})}),m&&e.jsx(y,{control:c.control,name:"billingEmails",render:({field:v,fieldState:x})=>e.jsxs(N,{className:"md:col-span-2",children:[e.jsxs(b,{className:"flex items-center gap-2",children:[e.jsx(We,{className:"h-4 w-4"}),"Billing Emails"]}),e.jsx(w,{children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:T(x)+" flex flex-wrap gap-2 mb-2 rounded-md",children:v.value?.map((j,P)=>e.jsxs(se,{variant:"secondary",className:"gap-1 pr-1",children:[j,e.jsx("button",{type:"button",onClick:()=>z(v.value??[],P),className:"ml-1 hover:bg-muted rounded-sm p-0.5",children:e.jsx(Q,{className:"h-3 w-3"})})]},P))}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(k,{value:g,onChange:j=>A(j.target.value),onKeyDown:j=>{j.key==="Enter"&&(j.preventDefault(),X(v.value??[]))},placeholder:"Add billing email",type:"email"}),e.jsx(D,{type:"button",variant:"outline",size:"icon",disabled:!g.trim(),onClick:()=>X(v.value??[]),children:e.jsx(M,{className:"h-4 w-4"})})]})]})}),e.jsx(I,{})]})})]})}),e.jsx(Ze,{className:"flex justify-end border-t mt-4 pt-6",children:e.jsxs(D,{type:"submit",disabled:i||Object.keys(c.formState.dirtyFields).length===0,children:[e.jsx(rs,{className:"h-4 w-4 mr-2"}),"Save Changes"]})})]})})]})}const sn="createContract",an=()=>{const[{fetching:s},a]=Be(la),t=C.useCallback(async n=>{const l=`Error creating new contract for client[${n.input.clientId}]`,o=`${sn}-${n.input.clientId}`;$.loading("Creating contract",{id:o});try{const r=await a(n);Pe(r,l,o)&&$.success("Success",{id:o,description:`Contract for client ${n.input.clientId} was successfully created`})}catch(r){console.error(`${l}: ${r}`),$.error("Error",{id:o,description:l,duration:1e5,closeButton:!0})}},[a]);return{creating:s,createContract:t}},tn="updateContract",nn=()=>{const[{fetching:s},a]=Be(ca),t=C.useCallback(async n=>{const l=`Error updating contract ID [${n.contractId}]`,o=`${tn}-${n.contractId}`;$.loading("Updating contract",{id:o});try{const r=await a(n),i=Pe(r,l,o,"updateContract");if(i)return $.success("Success",{id:o,description:"Contract updated"}),i.updateContract}catch(r){console.error(`${l}: ${r}`),$.error("Error",{id:o,description:l,duration:1e5,closeButton:!0})}},[a]);return{updating:s,updateContract:t}},rn=Ae({id:ma().optional(),startDate:ze("Start date is required"),endDate:ze("End date is required"),pos:te(R()),paymentAmount:ss().min(0,"Payment amount must be non-negative"),paymentCurrency:xe(Object.values(ns),"Currency is required"),productType:xe(Object.values(ws)).optional(),msCloudLink:bs().optional().or(Cs("")),billingCycle:xe(Object.values(we)).optional(),subscriptionPlan:xe(Object.values(Te)).optional(),isActive:da(),defaultRemark:R().optional(),defaultDocumentType:xe(Object.values(ts)),operationsLimit:oa().min(0,"Operations limit must be non-negative")}),fs={startDate:"",endDate:"",pos:[],paymentAmount:0,paymentCurrency:ns.Usd,productType:ws.Hive,msCloudLink:void 0,billingCycle:we.Monthly,subscriptionPlan:void 0,isActive:!0,defaultRemark:void 0,defaultDocumentType:ts.Proforma,operationsLimit:0};function ln({clientId:s,contract:a,onDone:t}){const[n,l]=C.useState(!1),[o,r]=C.useState(null),[i,c]=C.useState(""),{updateContract:d,updating:h}=nn(),{createContract:u,creating:p}=an(),g=Le({resolver:Qe(rn),defaultValues:a||fs}),A=()=>{const m=i.trim();if(m){const f=g.getValues("pos");f.includes(m)||g.setValue("pos",[...f,m],{shouldDirty:!0}),c("")}},E=m=>{const f=g.getValues("pos");g.setValue("pos",f.filter((L,F)=>F!==m),{shouldDirty:!0})};C.useEffect(()=>{a&&(r(a),g.reset({startDate:a.startDate,endDate:a.endDate,pos:a.pos,paymentAmount:a.paymentAmount,paymentCurrency:a.paymentCurrency,productType:a.productType,msCloudLink:a.msCloudLink,billingCycle:a.billingCycle,subscriptionPlan:a.subscriptionPlan,isActive:a.isActive,defaultRemark:a.defaultRemark,defaultDocumentType:a.defaultDocumentType,operationsLimit:a.operationsLimit}),l(!0))},[a,g]);const B=()=>{r(null),g.reset(fs),l(!0)},O=C.useCallback(async m=>{if(o)await d({contractId:o.id,input:{amount:{raw:m.paymentAmount,currency:m.paymentCurrency},billingCycle:m.billingCycle,documentType:m.defaultDocumentType,endDate:ce(new Date(m.endDate),"yyyy-MM-dd"),isActive:m.isActive,msCloud:m.msCloudLink,plan:m.subscriptionPlan,product:m.productType,purchaseOrders:m.pos,remarks:m.defaultRemark,startDate:ce(new Date(m.startDate),"yyyy-MM-dd"),operationsLimit:m.operationsLimit}});else{if(!m.billingCycle){g.setError("billingCycle",{message:"Billing cycle is required"});return}await u({input:{clientId:s,amount:{raw:m.paymentAmount,currency:m.paymentCurrency},billingCycle:m.billingCycle,documentType:m.defaultDocumentType,endDate:ce(new Date(m.endDate),"yyyy-MM-dd"),isActive:m.isActive,msCloud:m.msCloudLink,plan:m.subscriptionPlan,product:m.productType,purchaseOrders:m.pos,remarks:m.defaultRemark,startDate:ce(new Date(m.startDate),"yyyy-MM-dd"),operationsLimit:m.operationsLimit}})}l(!1),r(null),t?.()},[o,t,u,d,s,g]);return e.jsxs(Xe,{open:n,onOpenChange:l,children:[e.jsx(As,{asChild:!0,children:e.jsxs(D,{size:"sm",onClick:B,children:[e.jsx(M,{className:"h-4 w-4 mr-2"}),"New Contract"]})}),e.jsxs(Je,{className:"max-w-2xl max-h-[90vh] overflow-y-auto",children:[e.jsxs(Is,{children:[e.jsx(Ss,{children:o?"Edit Contract":"Create New Contract"}),e.jsx(Ds,{children:o?"Update contract details":"Add a new contract with all required details"})]}),e.jsx(Oe,{...g,children:e.jsxs("form",{onSubmit:g.handleSubmit(O),children:[e.jsxs("div",{className:"grid gap-4 py-4",children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsx(y,{control:g.control,name:"operationsLimit",render:({field:m})=>e.jsxs(N,{children:[e.jsx(b,{children:"Operations Limit"}),e.jsx(w,{children:e.jsx(k,{type:"number",placeholder:"500",...m})}),e.jsx(I,{})]})}),e.jsx(y,{control:g.control,name:"pos",render:({field:m})=>e.jsxs(N,{children:[e.jsx(b,{children:"Purchase Orders"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(k,{placeholder:"Add PO...",value:i,onChange:f=>c(f.target.value),onKeyDown:f=>{f.key==="Enter"&&(f.preventDefault(),A())}}),e.jsx(D,{type:"button",size:"sm",onClick:A,children:e.jsx(M,{className:"h-4 w-4"})})]}),e.jsx("div",{className:"flex flex-wrap gap-2 mt-2",children:m.value?.map((f,L)=>e.jsxs(se,{variant:"secondary",className:"gap-1 max-w-xs truncate",children:[f,L===m.value.length-1&&e.jsx(D,{variant:"ghost",size:"icon",className:"p-0 size-3",onClick:()=>E(L),children:e.jsx(Q,{className:"size-3 cursor-pointer flex-shrink-0"})})]},f))}),e.jsx(I,{})]})})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsx(y,{control:g.control,name:"startDate",render:({field:{onChange:m,...f}})=>e.jsxs(N,{children:[e.jsx(b,{children:"Start Date"}),e.jsx(w,{children:e.jsx(k,{type:"date",...f,onInput:L=>m(L)})}),e.jsx(I,{})]})}),e.jsx(y,{control:g.control,name:"endDate",render:({field:{onChange:m,...f}})=>e.jsxs(N,{children:[e.jsx(b,{children:"End Date"}),e.jsx(w,{children:e.jsx(k,{type:"date",...f,onInput:L=>m(L)})}),e.jsx(I,{})]})})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-3",children:[e.jsx(y,{control:g.control,name:"paymentAmount",render:({field:m})=>e.jsxs(N,{className:"md:col-span-2",children:[e.jsx(b,{children:"Payment Amount"}),e.jsx(w,{children:e.jsx(k,{type:"number",placeholder:"24000",...m,onChange:f=>{m.onChange(f?.target.value?Number(f?.target.value):void 0)}})}),e.jsx(I,{})]})}),e.jsx(y,{control:g.control,name:"paymentCurrency",render:({field:m})=>e.jsxs(N,{children:[e.jsx(b,{children:"Currency"}),e.jsxs(fe,{onValueChange:m.onChange,defaultValue:m.value,children:[e.jsx(w,{children:e.jsx(ve,{children:e.jsx(ye,{})})}),e.jsx(Ne,{children:Object.values(ns).map(f=>e.jsx(be,{value:f,children:f},f))})]}),e.jsx(I,{})]})})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsx(y,{control:g.control,name:"productType",render:({field:m})=>e.jsxs(N,{children:[e.jsx(b,{children:"Product Type"}),e.jsx(w,{children:e.jsx(k,{placeholder:"Cloud Services",...m})}),e.jsx(I,{})]})}),e.jsx(y,{control:g.control,name:"billingCycle",render:({field:m})=>e.jsxs(N,{children:[e.jsx(b,{children:"Billing Cycle"}),e.jsxs(fe,{onValueChange:m.onChange,defaultValue:m.value,children:[e.jsx(w,{children:e.jsx(ve,{children:e.jsx(ye,{})})}),e.jsx(Ne,{children:Object.values(we).map(f=>e.jsx(be,{value:f,children:Ls(f)},f))})]}),e.jsx(I,{})]})})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsx(y,{control:g.control,name:"subscriptionPlan",render:({field:m})=>e.jsxs(N,{children:[e.jsx(b,{children:"Subscription Plan"}),e.jsx(w,{children:e.jsxs(fe,{onValueChange:m.onChange,defaultValue:m.value,children:[e.jsx(w,{children:e.jsx(ve,{children:e.jsx(ye,{})})}),e.jsx(Ne,{children:Object.values(Te).map(f=>e.jsx(be,{value:f,children:Os(f)},f))})]})}),e.jsx(I,{})]})}),e.jsx(y,{control:g.control,name:"isActive",render:({field:m})=>e.jsxs(N,{className:"flex flex-row items-center justify-between rounded-lg border p-4",children:[e.jsx("div",{className:"space-y-0.5",children:e.jsx(b,{className:"text-base",children:"Active Status"})}),e.jsx(w,{children:e.jsx(ee,{checked:m.value,onCheckedChange:m.onChange})})]})})]}),e.jsx(y,{control:g.control,name:"msCloudLink",render:({field:m})=>e.jsxs(N,{children:[e.jsx(b,{children:"MS Cloud Link"}),e.jsx(w,{children:e.jsx(k,{type:"url",placeholder:"https://portal.azure.com/contract-id",...m})}),e.jsx(I,{})]})}),e.jsx(y,{control:g.control,name:"defaultDocumentType",render:({field:m})=>e.jsxs(N,{children:[e.jsx(b,{children:"Default Document Type"}),e.jsxs(fe,{onValueChange:m.onChange,defaultValue:m.value,children:[e.jsx(w,{children:e.jsx(ve,{children:e.jsx(ye,{})})}),e.jsx(Ne,{children:Object.values(ts).map(f=>e.jsx(be,{value:f,children:ks(f)},f))})]}),e.jsx(I,{})]})}),e.jsx(y,{control:g.control,name:"defaultRemark",render:({field:m})=>e.jsxs(N,{children:[e.jsx(b,{children:"Default Remark"}),e.jsx(w,{children:e.jsx(Ge,{placeholder:"Enter default remark for this contract...",rows:3,...m})}),e.jsx(I,{})]})})]}),e.jsxs(Ts,{children:[e.jsx(D,{type:"button",variant:"outline",onClick:()=>l(!1),children:"Cancel"}),e.jsx(D,{type:"submit",disabled:p||h,children:o?"Update Contract":"Create Contract"})]})]})})]})]})}function cn(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 on({clientId:s}){const[a,t]=C.useState(null),[{data:n,fetching:l},o]=ie({query:ua,variables:{clientId:s}}),r=n?.contractsByClient??[];return l?e.jsx("div",{children:"Loading contracts..."}):e.jsxs(G,{children:[e.jsx(W,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(K,{children:"Contracts"}),e.jsx(H,{children:"Current and past contracts sorted by start date"})]}),e.jsx(ln,{clientId:s,contract:a,onDone:o})]})}),e.jsx(Y,{className:"space-y-4",children:r.map(i=>{const c=!!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(se,{variant:c?"default":"secondary",children:i.isActive?"Active":"Inactive"})]}),e.jsx("p",{className:"text-sm text-muted-foreground font-mono",children:i.id})]}),e.jsx(D,{variant:"ghost",size:"sm",onClick:()=>t(cn(i)),children:e.jsx(tt,{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(ha,{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:xa(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:Ls(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?Os(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:ks(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(D,{variant:"outline",size:"sm",asChild:!0,children:e.jsxs("a",{href:i.msCloud.toString(),target:"_blank",rel:"noopener noreferrer",children:[e.jsx(pa,{className:"h-4 w-4 mr-2"}),"MS Cloud",e.jsx(nt,{className:"h-3 w-3 ml-1"})]})})})]},i.id)})})]})}function dn({businessId:s}){return e.jsxs(G,{children:[e.jsx(W,{children:e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{children:[e.jsx(K,{children:"Documents"}),e.jsx(H,{children:"Invoices, proformas, receipts, and other accounting documents"})]})})}),e.jsx(Y,{children:e.jsx(ja,{businessId:s,linkedDocumentIds:[],limit:1e3})})]})}const mn=[{id:"hive",name:"Hive",description:"Schema registry, analytics, metrics and gateway for GraphQL federation and other GraphQL APIs",status:"disconnected",lastSync:"Never"},{id:"slack",name:"Slack",description:"Team communication and notifications",status:"disconnected",lastSync:"Never"},{id:"retool",name:"Retool",description:"Internal tools and dashboards",status:"disconnected",lastSync:"Never"},{id:"linear",name:"Linear",description:"Issue tracking and project management",status:"disconnected",lastSync:"Never"},{id:"workflowy",name:"Workflowy",description:"Task management and note taking",status:"disconnected",lastSync:"Never"}];function un({data:s}){const a=Ie(ya,s),[{data:t,fetching:n},l]=ie({query:ga,variables:{clientId:a?.id??""},pause:!a?.clientInfo?.greenInvoiceId||!a?.id}),{updateClient:o}=fa(),r=C.useCallback((c,d)=>{if(!a?.id)return;const h={};h[d]=c,o({businessId:a?.id,fields:h})},[a?.id,o]);C.useEffect(()=>{a?.clientInfo?.greenInvoiceId&&a?.id&&l()},[a?.clientInfo?.greenInvoiceId,a?.id,l]);const i=t?.greenInvoiceClient;return e.jsxs(G,{children:[e.jsx(W,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(K,{children:"Integrations"}),e.jsx(H,{children:"Connected external services and providers"})]}),e.jsxs(D,{size:"sm",children:[e.jsx(M,{className:"h-4 w-4 mr-2"}),"Add Integration"]})]})}),e.jsx(Y,{className:"space-y-6",children:e.jsxs(rt,{type:"multiple",defaultValue:["green-invoice"],className:"space-y-4",children:[n?e.jsxs(_e,{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(S,{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(S,{className:"h-6 w-32"}),e.jsx(S,{className:"h-5 w-5 rounded-full"})]}),e.jsx(S,{className:"h-4 w-64"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(S,{className:"h-8 w-24"}),e.jsx(S,{className:"h-8 w-8"})]})]})}),e.jsx(Re,{children:e.jsxs("div",{className:"p-6 space-y-6",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx(S,{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(S,{className:"h-3 w-24"}),e.jsx(S,{className:"h-4 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(S,{className:"h-3 w-24"}),e.jsx(S,{className:"h-4 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(S,{className:"h-3 w-24"}),e.jsx(S,{className:"h-4 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(S,{className:"h-3 w-24"}),e.jsx(S,{className:"h-4 w-full"})]})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(S,{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(S,{className:"h-3 w-32"}),e.jsx(S,{className:"h-6 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(S,{className:"h-3 w-24"}),e.jsx(S,{className:"h-4 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(S,{className:"h-3 w-24"}),e.jsx(S,{className:"h-4 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(S,{className:"h-3 w-24"}),e.jsx(S,{className:"h-4 w-full"})]})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(S,{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(S,{className:"h-3 w-24"}),e.jsx(S,{className:"h-4 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(S,{className:"h-3 w-24"}),e.jsx(S,{className:"h-4 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(S,{className:"h-3 w-24"}),e.jsx(S,{className:"h-4 w-full"})]})]})]})]})})]}):e.jsxs(_e,{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(ms,{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(hn,{id:a?.clientInfo?.greenInvoiceId,provider:"Green Invoice",updateClient:async c=>r(c,"greenInvoiceId")}),e.jsx(ds,{className:"hover:no-underline p-2"})]})]})}),e.jsx(Re,{children:i&&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:a?.clientInfo?.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:i.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:i.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:i.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(We,{className:"h-3.5 w-3.5"}),"Email Addresses"]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:i.emails?.map((c,d)=>e.jsx("span",{className:"text-sm px-2 py-1 bg-muted rounded",children:c},d))})]}),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(Ns,{className:"h-3.5 w-3.5"}),"Phone"]}),e.jsx("p",{className:"text-sm font-mono",children:i.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:i.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:i.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(qe,{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:i.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:i.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:i.zip})]})]})]})]})})]}),mn.map(c=>e.jsxs(_e,{value:c.id,className:"rounded-lg border",children:[e.jsx("div",{className:"px-4 py-3",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{className:"flex items-center gap-3 flex-1",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:c.name}),c.status==="connected"?e.jsx(ms,{className:"h-4 w-4 text-green-600"}):e.jsx(va,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:c.description})]})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(D,{variant:"ghost",size:"sm",onClick:d=>d.stopPropagation(),children:e.jsx(is,{className:"h-4 w-4"})}),e.jsx(ds,{className:"hover:no-underline p-2"})]})]})}),e.jsx(Re,{children:e.jsx("div",{className:"px-4 pb-4 pt-2 border-t",children:e.jsxs("div",{className:"text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:"Last sync: "}),e.jsx("span",{className:"font-medium",children:c.lastSync})]})})})]},c.id))]})})]})}function hn({id:s,provider:a,updateClient:t}){const[n,l]=C.useState(!1),[o,r]=C.useState(s),i=C.useCallback(async()=>{await t(o),l(!1)},[o,t]);return e.jsxs(Xe,{open:n,onOpenChange:l,children:[e.jsx(As,{asChild:!0,children:e.jsxs(D,{variant:"outline",size:"sm",onClick:c=>c.stopPropagation(),children:[e.jsx(is,{className:"h-4 w-4 mr-2"}),"Configure"]})}),e.jsxs(Je,{onClick:c=>c.stopPropagation(),children:[e.jsxs(Is,{children:[e.jsxs(Ss,{children:["Configure ",a]}),e.jsxs(Ds,{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(ge,{htmlFor:"id",children:[a," ID"]}),e.jsx(k,{id:"id",value:o,onChange:c=>r(c.target.value),placeholder:`Enter ${a} ID`})]})}),e.jsxs(Ts,{children:[e.jsx(D,{variant:"outline",onClick:()=>l(!1),children:"Cancel"}),e.jsx(D,{onClick:i,disabled:!o,children:"Save Changes"})]})]})]})}function xn({businessId:s}){const[{data:a,fetching:t}]=ie({query:Na,variables:{businessId:s}});return t?e.jsx("div",{children:"Loading ledger records..."}):e.jsxs(G,{children:[e.jsx(W,{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(K,{children:"Ledger Records"}),e.jsx(H,{children:"Complete ledger history for this business"})]})})}),e.jsx(Y,{children:e.jsx("div",{className:"rounded-md border",children:e.jsx(Va,{ledgerRecordsData:a?.ledgerRecordsByFinancialEntity??[]})})})]})}function pn({businessId:s}){const[{data:a,fetching:t}]=ie({query:ba,variables:{businessId:s}});return t?e.jsx("div",{children:"Loading transactions..."}):e.jsxs(G,{children:[e.jsx(W,{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(K,{children:"Transactions"}),e.jsx(H,{children:"Complete transaction history for this business"})]})})}),e.jsx(Y,{children:e.jsx("div",{className:"rounded-md border",children:e.jsx(it,{transactionsProps:a?.transactionsByFinancialEntity??[]})})})]})}function jn({data:s,refetchBusiness:a}){const t=Ie(ka,s),[n,l]=Ca(),{setFiltersContext:o}=C.useContext(wa);C.useEffect(()=>{o(null)},[o]);const r=n.get("tab")||"contact",i=h=>{l({tab:h})};if(!t)return e.jsx("div",{children:"Business not found"});const c="clientInfo"in t&&!!t.clientInfo,d="adminInfo"in t&&!!t.adminInfo;return e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx(La,{data:t}),e.jsx("main",{className:"container mx-auto px-4 py-6 md:px-6 lg:px-8 max-w-7xl",children:e.jsxs(Aa,{value:r,onValueChange:i,className:"w-full",children:[e.jsxs(Ia,{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(J,{value:"contact",className:"flex items-center gap-2 data-[state=active]:bg-background",children:[e.jsx(lt,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Contact"})]}),e.jsxs(J,{value:"config",className:"flex items-center gap-2 data-[state=active]:bg-background",children:[e.jsx(is,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Config"})]}),e.jsxs(J,{value:"charges",className:"flex items-center gap-2 data-[state=active]:bg-background",children:[e.jsx(ke,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Charges"})]}),e.jsxs(J,{value:"transactions",className:"flex items-center gap-2 data-[state=active]:bg-background",children:[e.jsx(Sa,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Transactions"})]}),e.jsxs(J,{value:"documents",className:"flex items-center gap-2 data-[state=active]:bg-background",children:[e.jsx(Da,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Documents"})]}),e.jsxs(J,{value:"ledger",className:"flex items-center gap-2 data-[state=active]:bg-background",children:[e.jsx(pt,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Ledger"})]}),e.jsxs(J,{value:"balance",className:"flex items-center gap-2 data-[state=active]:bg-background",children:[e.jsx(ot,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Balance"})]}),c&&e.jsxs(e.Fragment,{children:[e.jsxs(J,{value:"contracts",className:"flex items-center gap-2 data-[state=active]:bg-background",children:[e.jsx(ht,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Contracts"})]}),e.jsxs(J,{value:"integrations",className:"flex items-center gap-2 data-[state=active]:bg-background",children:[e.jsx(gt,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Integrations"})]})]}),d&&e.jsxs(J,{value:"admin",className:"flex items-center gap-2 data-[state=active]:bg-background",children:[e.jsx(ys,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Admin"})]})]}),e.jsx(U,{value:"contact",className:"mt-0",children:e.jsx(en,{data:t,refetchBusiness:a})}),e.jsx(U,{value:"config",className:"mt-0",children:e.jsx(Kt,{data:t,refetchBusiness:a})}),e.jsx(U,{value:"charges",className:"mt-0",children:e.jsx(St,{businessId:t.id})}),e.jsx(U,{value:"transactions",className:"mt-0",children:e.jsx(pn,{businessId:t.id})}),e.jsx(U,{value:"documents",className:"mt-0",children:e.jsx(dn,{businessId:t.id})}),e.jsx(U,{value:"ledger",className:"mt-0",children:e.jsx(xn,{businessId:t.id})}),e.jsx(U,{value:"balance",className:"mt-0",children:e.jsx(It,{businessId:t.id})}),c&&e.jsxs(e.Fragment,{children:[e.jsx(U,{value:"contracts",className:"mt-0",children:e.jsx(on,{clientId:t.id})}),e.jsx(U,{value:"integrations",className:"mt-0",children:e.jsx(un,{data:t})}),e.jsx(U,{value:"charts",className:"mt-0",children:e.jsx(Ut,{})})]}),d&&e.jsx(U,{value:"admin",className:"mt-0",children:e.jsx(At,{data:t})})]})})]})}const Rn=()=>{const{businessId:s}=Ta();let a;try{a=Ea()}catch{}const[{data:t,fetching:n},l]=ie({query:Ba,pause:!s||!!a,variables:{businessId:s??""}}),o=a||t;return!a&&n&&!o?.business?e.jsx(vs,{}):!s||!o?.business?e.jsx("div",{children:"Business not found"}):e.jsx(jn,{data:o.business,refetchBusiness:async()=>l()})};export{Rn as BusinessScreen};
|
|
36
|
+
*/const ft=[["path",{d:"M16 7h6v6",key:"box55l"}],["path",{d:"m22 7-8.5 8.5-5-5L2 17",key:"1t1m79"}]],Me=ne("trending-up",ft);function Ls(s){switch(s){case we.Annual:return"Annual";case we.Monthly:return"Monthly";default:throw new Error(`Unsupported Billing Cycle: ${s}`)}}function Os(s){switch(s){case Te.Enterprise:return"Enterprise";case Te.Pro:return"Pro";default:throw new Error(`Unsupported Subscription plan: ${s}`)}}function vt(s){return ce(s,"yyyy-MM-dd")}function yt({businessId:s,tagIds:a,description:t,open:n,onOpenChange:l,onClose:o}){const[{data:r,fetching:i},c]=ie({pause:!0,query:zs,variables:{businessId:s,tagsDifferentThan:a?a.map(u=>u.id):void 0,descriptionDifferentThan:t}});C.useEffect(()=>{n&&(a||t)&&!r&&c()},[n,a,t,c,r]);const d=C.useCallback(u=>{l(u),n&&!u&&o?.()},[l,o,n]),h=C.useMemo(()=>n&&(!!a||!!t)&&r&&r?.similarChargesByBusiness.length>0,[n,a,t,r]);return e.jsx(Xe,{open:h,onOpenChange:d,children:e.jsx(Je,{className:"overflow-scroll max-h-screen w-full sm:max-w-[640px] md:max-w-[768px] lg:max-w-[900px]",onClick:u=>u.stopPropagation(),children:e.jsx(Us,{fallback:e.jsx("div",{children:"Error fetching similar charges"}),children:i?e.jsx(vs,{}):a||t?e.jsx(Fa,{data:r?.similarChargesByBusiness??[],tagIds:a,description:t,onOpenChange:d,title:"Similar Charges by Business"}):null})})})}const Nt="updateAdminBusiness",bt=()=>{const[{fetching:s},a]=Be(qs),t=C.useCallback(async n=>{const l=`Error updating admin business ID [${n.adminBusinessId}]`,o=`${Nt}-${n.adminBusinessId}`;$.loading("Updating admin business",{id:o});try{const r=await a(n),i=Pe(r,l,o,"updateAdminBusiness");if(i)return $.success("Success",{id:o,description:"Admin Business Updated"}),i.updateAdminBusiness}catch(r){console.error(`${l}: ${r}`),$.error("Error",{id:o,description:l,duration:1e5,closeButton:!0})}},[a]);return{fetching:s,updateAdminBusiness:t}},$e=Ae({year:ss().min(2e3).max(2100),id:R().min(1,{message:"ID is required"})}),Ct=Ae({registrationDate:R().min(1,{message:"Business Registration Start Date is required"}),withholdingTaxAnnualIds:te($e),withholdingTaxCompanyId:R().min(1,{message:"Withholding Tax Company ID is required"}),socialSecurityEmployerIds:te($e),socialSecurityDeductionsId:R().min(1,{message:"Social Security Deductions ID is required"}),taxAdvancesAnnualIds:te($e),taxAdvancesRates:te(Ae({date:ze(),rate:ss().min(0,{message:"Rate must be at least 0"}).max(100,{message:"Rate must be at most 100"})}))});function us(s){return!s||s.__typename!=="LtdFinancialEntity"||!s.adminInfo?{}:{registrationDate:s.adminInfo.registrationDate,withholdingTaxAnnualIds:s.adminInfo.withholdingTaxAnnualIds.sort((a,t)=>t.year-a.year),withholdingTaxCompanyId:s.adminInfo.withholdingTaxCompanyId??void 0,socialSecurityEmployerIds:s.adminInfo.socialSecurityEmployerIds.sort((a,t)=>t.year-a.year),socialSecurityDeductionsId:s.adminInfo.socialSecurityDeductionsId??void 0,taxAdvancesAnnualIds:s.adminInfo.taxAdvancesAnnualIds.sort((a,t)=>t.year-a.year),taxAdvancesRates:s.adminInfo.taxAdvancesRates?.map(a=>({date:a.date,rate:a.rate*100}))}}function wt(s){return{registrationDate:s.registrationDate?vt(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 At({data:s,refetchBusiness:a}){const t=Ie(Gs,s),[n,l]=C.useState(us(t)),{updateAdminBusiness:o,fetching:r}=bt(),i=Le({resolver:Qe(Ct),defaultValues:n}),c=async x=>{if(!t)return;const j=es(x,i.formState.dirtyFields);if(!j)return;const P=wt(j);await o({adminBusinessId:t.id,fields:P}),a?.()};C.useEffect(()=>{if(t){const x=us(t);l(x),i.reset(x)}},[t,i]);const{fields:d,append:h,remove:u}=Se({control:i.control,name:"taxAdvancesAnnualIds"}),{fields:p,append:g,remove:A}=Se({control:i.control,name:"withholdingTaxAnnualIds"}),{fields:E,append:B,remove:O}=Se({control:i.control,name:"socialSecurityEmployerIds"}),m={withholdingTaxAnnualIds:{append:g,remove:A},taxAdvancesAnnualIds:{append:h,remove:u},socialSecurityEmployerIds:{append:B,remove:O}},f=x=>{m[x].append({year:new Date().getFullYear(),id:""})},L=(x,j)=>{m[x].remove(j)},{fields:F,append:X,remove:z}=Se({control:i.control,name:"taxAdvancesRates"}),Z=()=>{X({date:ce(new Date,"yyyy-MM-dd"),rate:0})},v=x=>{z(x)};return e.jsxs(G,{children:[e.jsxs(W,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ys,{className:"h-5 w-5 text-primary"}),e.jsx(K,{children:"Admin Business Configuration"})]}),e.jsx(H,{children:"Tax and registration information for the business operating this application"})]}),e.jsx(Oe,{...i,children:e.jsxs("form",{onSubmit:i.handleSubmit(c),className:"space-y-6",children:[e.jsx(Y,{children:e.jsxs("div",{className:"grid gap-6 md:grid-cols-2",children:[e.jsx("h3",{className:"text-sm font-semibold text-foreground md:col-span-2",children:"Withholding Tax"}),e.jsx(y,{control:i.control,name:"withholdingTaxCompanyId",render:({field:x,fieldState:j})=>e.jsxs(N,{children:[e.jsx(b,{children:"Company Tax ID"}),e.jsx(w,{children:e.jsx(k,{placeholder:"Enter company ID",...x,className:T(j)})}),e.jsx(I,{})]})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(ge,{children:"Annual IDs"}),e.jsx(D,{type:"button",variant:"outline",size:"sm",onClick:()=>f("withholdingTaxAnnualIds"),children:e.jsx(M,{className:"size-4"})})]}),e.jsx("div",{className:"space-y-3",children:p.map((x,j)=>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(k,{placeholder:"Year",type:"number",...i.register(`withholdingTaxAnnualIds.${j}.year`,{valueAsNumber:!0})}),e.jsx(k,{placeholder:"ID",...i.register(`withholdingTaxAnnualIds.${j}.id`)})]}),e.jsx(D,{type:"button",variant:"ghost",size:"icon",onClick:()=>L("withholdingTaxAnnualIds",j),children:e.jsx(Q,{className:"size-4"})})]},x.id))})]}),e.jsx(oe,{className:"md:col-span-2"}),e.jsx("h3",{className:"text-sm font-semibold text-foreground md:col-span-2",children:"Tax Advances"}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(ge,{children:"Annual IDs"}),e.jsx(D,{type:"button",variant:"outline",size:"sm",onClick:()=>f("taxAdvancesAnnualIds"),children:e.jsx(M,{className:"size-4"})})]}),e.jsx("div",{className:"space-y-3",children:d.map((x,j)=>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(k,{placeholder:"Year",type:"number",...i.register(`taxAdvancesAnnualIds.${j}.year`,{valueAsNumber:!0})}),e.jsx(k,{placeholder:"ID",...i.register(`taxAdvancesAnnualIds.${j}.id`)})]}),e.jsx(D,{type:"button",variant:"ghost",size:"icon",onClick:()=>L("taxAdvancesAnnualIds",j),children:e.jsx(Q,{className:"size-4"})})]},x.id))})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(ge,{children:"Rates (%)"}),e.jsx(D,{type:"button",variant:"outline",size:"sm",onClick:Z,children:e.jsx(M,{className:"size-4"})})]}),e.jsx("div",{className:"space-y-3",children:F.map((x,j)=>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(k,{placeholder:"Date",type:"date",...i.register(`taxAdvancesRates.${j}.date`)}),e.jsx(k,{placeholder:"Rate",...i.register(`taxAdvancesRates.${j}.rate`,{valueAsNumber:!0})})]}),e.jsx(D,{type:"button",variant:"ghost",size:"icon",onClick:()=>v(j),children:e.jsx(Q,{className:"size-4"})})]},x.id))})]}),e.jsx(oe,{className:"md:col-span-2"}),e.jsx("h3",{className:"text-sm font-semibold text-foreground md:col-span-2",children:"Social Security"}),e.jsx(y,{control:i.control,name:"socialSecurityDeductionsId",render:({field:x,fieldState:j})=>e.jsxs(N,{children:[e.jsx(b,{children:"Deductions ID"}),e.jsx(w,{children:e.jsx(k,{placeholder:"Enter deductions ID",...x,className:T(j)})}),e.jsx(I,{})]})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(ge,{children:"Annual Employer IDs"}),e.jsx(D,{type:"button",variant:"outline",size:"sm",onClick:()=>f("socialSecurityEmployerIds"),children:e.jsx(M,{className:"size-4"})})]}),e.jsx("div",{className:"space-y-3",children:E.map((x,j)=>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(k,{placeholder:"Year",type:"number",...i.register(`socialSecurityEmployerIds.${j}.year`,{valueAsNumber:!0})}),e.jsx(k,{placeholder:"ID",...i.register(`socialSecurityEmployerIds.${j}.id`)})]}),e.jsx(D,{type:"button",variant:"ghost",size:"icon",onClick:()=>L("socialSecurityEmployerIds",j),children:e.jsx(Q,{className:"size-4"})})]},x.id))})]}),e.jsx(oe,{className:"md:col-span-2"}),e.jsx(y,{control:i.control,name:"registrationDate",render:({field:x,fieldState:j})=>e.jsxs(N,{children:[e.jsx(b,{children:"Business Registration Start Date"}),e.jsx(w,{children:e.jsx(k,{type:"date",...x,className:T(j)})}),e.jsx(I,{})]})})]})}),e.jsx(Ze,{className:"flex justify-end border-t mt-4 pt-6",children:e.jsxs(D,{type:"submit",disabled:r||Object.keys(i.formState.dirtyFields).length===0||!i.formState.isValid,children:[e.jsx(rs,{className:"h-4 w-4"}),"Save Changes"]})})]})})]})}function It({businessId:s}){return e.jsxs(G,{children:[e.jsx(W,{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(K,{children:"Balance"}),e.jsx(H,{children:"Business balance overview"})]})})}),e.jsx(Y,{children:e.jsx("div",{className:"rounded-md border",children:e.jsx(La,{businessID:s,filter:{}})})})]})}function St({businessId:s}){const{userContext:a}=C.useContext(as),[t,n]=C.useState(0),[{data:l,fetching:o}]=ie({query:Ws,variables:{filters:{byOwners:a?.context.adminBusinessId?[a.context.adminBusinessId]:void 0,sortBy:{field:Hs.Date,asc:!1},byBusinesses:[s]},page:t-1,limit:10}}),r=l?.allCharges?.pageInfo.totalPages??1,i=l?.allCharges?.nodes??[];return o?e.jsx("div",{children:"Loading charges..."}):e.jsxs(G,{children:[e.jsxs(W,{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(K,{children:"Charges"}),e.jsx(H,{children:"Recurring and one-time charges for this business"})]})}),r>1&&e.jsx(Ks,{className:"flex-fit w-fit mx-0",value:t,onChange:n,total:r})]}),e.jsx(Y,{children:e.jsx("div",{className:"rounded-md border",children:e.jsx(Va,{data:i,isAllOpened:!1})})})]})}var Dt=["type","layout","connectNulls","ref"],kt=["key"];function de(s){"@babel/helpers - typeof";return de=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},de(s)}function hs(s,a){if(s==null)return{};var t=Tt(s,a),n,l;if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(s);for(l=0;l<o.length;l++)n=o[l],!(a.indexOf(n)>=0)&&Object.prototype.propertyIsEnumerable.call(s,n)&&(t[n]=s[n])}return t}function Tt(s,a){if(s==null)return{};var t={};for(var n in s)if(Object.prototype.hasOwnProperty.call(s,n)){if(a.indexOf(n)>=0)continue;t[n]=s[n]}return t}function Ce(){return Ce=Object.assign?Object.assign.bind():function(s){for(var a=1;a<arguments.length;a++){var t=arguments[a];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(s[n]=t[n])}return s},Ce.apply(this,arguments)}function xs(s,a){var t=Object.keys(s);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(s);a&&(n=n.filter(function(l){return Object.getOwnPropertyDescriptor(s,l).enumerable})),t.push.apply(t,n)}return t}function _(s){for(var a=1;a<arguments.length;a++){var t=arguments[a]!=null?arguments[a]:{};a%2?xs(Object(t),!0).forEach(function(n){q(s,n,t[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(s,Object.getOwnPropertyDescriptors(t)):xs(Object(t)).forEach(function(n){Object.defineProperty(s,n,Object.getOwnPropertyDescriptor(t,n))})}return s}function le(s){return Lt(s)||Pt(s)||Bt(s)||Et()}function Et(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
|
|
37
|
+
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function Bt(s,a){if(s){if(typeof s=="string")return He(s,a);var t=Object.prototype.toString.call(s).slice(8,-1);if(t==="Object"&&s.constructor&&(t=s.constructor.name),t==="Map"||t==="Set")return Array.from(s);if(t==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return He(s,a)}}function Pt(s){if(typeof Symbol<"u"&&s[Symbol.iterator]!=null||s["@@iterator"]!=null)return Array.from(s)}function Lt(s){if(Array.isArray(s))return He(s)}function He(s,a){(a==null||a>s.length)&&(a=s.length);for(var t=0,n=new Array(a);t<a;t++)n[t]=s[t];return n}function Ot(s,a){if(!(s instanceof a))throw new TypeError("Cannot call a class as a function")}function ps(s,a){for(var t=0;t<a.length;t++){var n=a[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(s,Vs(n.key),n)}}function Ft(s,a,t){return a&&ps(s.prototype,a),t&&ps(s,t),Object.defineProperty(s,"prototype",{writable:!1}),s}function Vt(s,a,t){return a=Ee(a),_t(s,Fs()?Reflect.construct(a,t||[],Ee(s).constructor):a.apply(s,t))}function _t(s,a){if(a&&(de(a)==="object"||typeof a=="function"))return a;if(a!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return Rt(s)}function Rt(s){if(s===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return s}function Fs(){try{var s=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch{}return(Fs=function(){return!!s})()}function Ee(s){return Ee=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},Ee(s)}function Mt(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&&Ye(s,a)}function Ye(s,a){return Ye=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(n,l){return n.__proto__=l,n},Ye(s,a)}function q(s,a,t){return a=Vs(a),a in s?Object.defineProperty(s,a,{value:t,enumerable:!0,configurable:!0,writable:!0}):s[a]=t,s}function Vs(s){var a=$t(s,"string");return de(a)=="symbol"?a:a+""}function $t(s,a){if(de(s)!="object"||!s)return s;var t=s[Symbol.toPrimitive];if(t!==void 0){var n=t.call(s,a);if(de(n)!="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(s)}var me=(function(s){function a(){var t;Ot(this,a);for(var n=arguments.length,l=new Array(n),o=0;o<n;o++)l[o]=arguments[o];return t=Vt(this,a,[].concat(l)),q(t,"state",{isAnimationFinished:!0,totalLength:0}),q(t,"generateSimpleStrokeDasharray",function(r,i){return"".concat(i,"px ").concat(r-i,"px")}),q(t,"getStrokeDasharray",function(r,i,c){var d=c.reduce(function(O,m){return O+m});if(!d)return t.generateSimpleStrokeDasharray(i,r);for(var h=Math.floor(r/d),u=r%d,p=i-r,g=[],A=0,E=0;A<c.length;E+=c[A],++A)if(E+c[A]>u){g=[].concat(le(c.slice(0,A)),[u-E]);break}var B=g.length%2===0?[0,p]:[p];return[].concat(le(a.repeat(c,h)),le(g),B).map(function(O){return"".concat(O,"px")}).join(", ")}),q(t,"id",Ha("recharts-line-")),q(t,"pathRef",function(r){t.mainCurve=r}),q(t,"handleAnimationEnd",function(){t.setState({isAnimationFinished:!0}),t.props.onAnimationEnd&&t.props.onAnimationEnd()}),q(t,"handleAnimationStart",function(){t.setState({isAnimationFinished:!1}),t.props.onAnimationStart&&t.props.onAnimationStart()}),t}return Mt(a,s),Ft(a,[{key:"componentDidMount",value:function(){if(this.props.isAnimationActive){var n=this.getTotalLength();this.setState({totalLength:n})}}},{key:"componentDidUpdate",value:function(){if(this.props.isAnimationActive){var n=this.getTotalLength();n!==this.state.totalLength&&this.setState({totalLength:n})}}},{key:"getTotalLength",value:function(){var n=this.mainCurve;try{return n&&n.getTotalLength&&n.getTotalLength()||0}catch{return 0}}},{key:"renderErrorBar",value:function(n,l){if(this.props.isAnimationActive&&!this.state.isAnimationFinished)return null;var o=this.props,r=o.points,i=o.xAxis,c=o.yAxis,d=o.layout,h=o.children,u=$a(h,za);if(!u)return null;var p=function(E,B){return{x:E.x,y:E.y,value:E.value,errorVal:Es(E.payload,B)}},g={clipPath:n?"url(#clipPath-".concat(l,")"):null};return V.createElement(Ve,g,u.map(function(A){return V.cloneElement(A,{key:"bar-".concat(A.props.dataKey),data:r,xAxis:i,yAxis:c,layout:d,dataPointFormatter:p})}))}},{key:"renderDots",value:function(n,l,o){var r=this.props.isAnimationActive;if(r&&!this.state.isAnimationFinished)return null;var i=this.props,c=i.dot,d=i.points,h=i.dataKey,u=De(this.props,!1),p=De(c,!0),g=d.map(function(E,B){var O=_(_(_({key:"dot-".concat(B),r:3},u),p),{},{index:B,cx:E.x,cy:E.y,value:E.value,dataKey:h,payload:E.payload,points:d});return a.renderDotItem(c,O)}),A={clipPath:n?"url(#clipPath-".concat(l?"":"dots-").concat(o,")"):null};return V.createElement(Ve,Ce({className:"recharts-line-dots",key:"dots"},A),g)}},{key:"renderCurveStatically",value:function(n,l,o,r){var i=this.props,c=i.type,d=i.layout,h=i.connectNulls;i.ref;var u=hs(i,Dt),p=_(_(_({},De(u,!0)),{},{fill:"none",className:"recharts-line-curve",clipPath:l?"url(#clipPath-".concat(o,")"):null,points:n},r),{},{type:c,layout:d,connectNulls:h});return V.createElement(Ua,Ce({},p,{pathRef:this.pathRef}))}},{key:"renderCurveWithAnimation",value:function(n,l){var o=this,r=this.props,i=r.points,c=r.strokeDasharray,d=r.isAnimationActive,h=r.animationBegin,u=r.animationDuration,p=r.animationEasing,g=r.animationId,A=r.animateNewValues,E=r.width,B=r.height,O=this.state,m=O.prevPoints,f=O.totalLength;return V.createElement(qa,{begin:h,duration:u,isActive:d,easing:p,from:{t:0},to:{t:1},key:"line-".concat(g),onAnimationEnd:this.handleAnimationEnd,onAnimationStart:this.handleAnimationStart},function(L){var F=L.t;if(m){var X=m.length/i.length,z=i.map(function(P,Fe){var ue=Math.floor(Fe*X);if(m[ue]){var he=m[ue],re=pe(he.x,P.x),Rs=pe(he.y,P.y);return _(_({},P),{},{x:re(F),y:Rs(F)})}if(A){var Ms=pe(E*2,P.x),$s=pe(B/2,P.y);return _(_({},P),{},{x:Ms(F),y:$s(F)})}return _(_({},P),{},{x:P.x,y:P.y})});return o.renderCurveStatically(z,n,l)}var Z=pe(0,f),v=Z(F),x;if(c){var j="".concat(c).split(/[,\s]+/gim).map(function(P){return parseFloat(P)});x=o.getStrokeDasharray(v,f,j)}else x=o.generateSimpleStrokeDasharray(f,v);return o.renderCurveStatically(i,n,l,{strokeDasharray:x})})}},{key:"renderCurve",value:function(n,l){var o=this.props,r=o.points,i=o.isAnimationActive,c=this.state,d=c.prevPoints,h=c.totalLength;return i&&r&&r.length&&(!d&&h>0||!Ga(d,r))?this.renderCurveWithAnimation(n,l):this.renderCurveStatically(r,n,l)}},{key:"render",value:function(){var n,l=this.props,o=l.hide,r=l.dot,i=l.points,c=l.className,d=l.xAxis,h=l.yAxis,u=l.top,p=l.left,g=l.width,A=l.height,E=l.isAnimationActive,B=l.id;if(o||!i||!i.length)return null;var O=this.state.isAnimationFinished,m=i.length===1,f=ls("recharts-line",c),L=d&&d.allowDataOverflow,F=h&&h.allowDataOverflow,X=L||F,z=Ke(B)?this.id:B,Z=(n=De(r,!1))!==null&&n!==void 0?n:{r:3,strokeWidth:2},v=Z.r,x=v===void 0?3:v,j=Z.strokeWidth,P=j===void 0?2:j,Fe=Wa(r)?r:{},ue=Fe.clipDot,he=ue===void 0?!0:ue,re=x*2+P;return V.createElement(Ve,{className:f},L||F?V.createElement("defs",null,V.createElement("clipPath",{id:"clipPath-".concat(z)},V.createElement("rect",{x:L?p:p-g/2,y:F?u:u-A/2,width:L?g:g*2,height:F?A:A*2})),!he&&V.createElement("clipPath",{id:"clipPath-dots-".concat(z)},V.createElement("rect",{x:p-re/2,y:u-re/2,width:g+re,height:A+re}))):null,!m&&this.renderCurve(X,z),this.renderErrorBar(X,z),(m||r)&&this.renderDots(X,he,z),(!E||O)&&Ka.renderCallByParent(this.props,i))}}],[{key:"getDerivedStateFromProps",value:function(n,l){return n.animationId!==l.prevAnimationId?{prevAnimationId:n.animationId,curPoints:n.points,prevPoints:l.curPoints}:n.points!==l.curPoints?{curPoints:n.points}:null}},{key:"repeat",value:function(n,l){for(var o=n.length%2!==0?[].concat(le(n),[0]):n,r=[],i=0;i<l;++i)r=[].concat(le(r),le(o));return r}},{key:"renderDotItem",value:function(n,l){var o;if(V.isValidElement(n))o=V.cloneElement(n,l);else if(Ra(n))o=n(l);else{var r=l.key,i=hs(l,kt),c=ls("recharts-line-dot",typeof n!="boolean"?n.className:"");o=V.createElement(Ma,Ce({key:r},i,{className:c}))}return o}}])})(C.PureComponent);q(me,"displayName","Line");q(me,"defaultProps",{xAxisId:0,yAxisId:0,connectNulls:!1,activeDot:!0,dot:!0,legendType:"line",stroke:"#3182bd",strokeWidth:1,fill:"#fff",points:[],isAnimationActive:!Ya.isSsr,animateNewValues:!0,animationBegin:0,animationDuration:1500,animationEasing:"ease",hide:!1,label:!1});q(me,"getComposedData",function(s){var a=s.props,t=s.xAxis,n=s.yAxis,l=s.xAxisTicks,o=s.yAxisTicks,r=s.dataKey,i=s.bandSize,c=s.displayedData,d=s.offset,h=a.layout,u=c.map(function(p,g){var A=Es(p,r);return h==="horizontal"?{x:os({axis:t,ticks:l,bandSize:i,entry:p,index:g}),y:Ke(A)?null:n.scale(A),value:A,payload:p}:{x:Ke(A)?null:t.scale(A),y:os({axis:n,ticks:o,bandSize:i,entry:p,index:g}),value:A,payload:p}});return _({points:u,layout:h},d)});var zt=Xa({chartName:"LineChart",GraphicalChild:me,axisComponents:[{axisType:"xAxis",AxisComp:Bs},{axisType:"yAxis",AxisComp:Ps}],formatAxisMap:Ja});const je=[{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 Ut(){const s=je.reduce((t,n)=>t+n.revenue,0),a=s/je.length;return e.jsxs(G,{children:[e.jsxs(W,{children:[e.jsx(K,{children:"Revenue Analytics"}),e.jsx(H,{children:"Revenue and expenses over time"})]}),e.jsxs(Y,{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(ke,{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(Me,{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(ke,{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(Me,{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(ke,{className:"h-4 w-4"}),"Current Month"]}),e.jsxs("p",{className:"text-2xl font-bold",children:["$",je[je.length-1].revenue.toLocaleString()]}),e.jsxs("div",{className:"flex items-center gap-1 text-sm text-green-600",children:[e.jsx(Me,{className:"h-3 w-3"}),e.jsx("span",{children:"+8.0% from last month"})]})]})]}),e.jsx(Qa,{config:{revenue:{label:"Revenue",color:"hsl(var(--chart-1))"},expenses:{label:"Expenses",color:"hsl(var(--chart-2))"}},className:"h-[400px]",children:e.jsx(Za,{width:"100%",height:"100%",children:e.jsxs(zt,{data:je,margin:{top:5,right:10,left:10,bottom:5},children:[e.jsx(et,{strokeDasharray:"3 3",className:"stroke-muted"}),e.jsx(Bs,{dataKey:"month",className:"text-xs",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(Ps,{className:"text-xs",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(st,{content:e.jsx(at,{})}),e.jsx(me,{type:"monotone",dataKey:"revenue",stroke:"var(--color-revenue)",strokeWidth:2,dot:{fill:"var(--color-revenue)",r:4}}),e.jsx(me,{type:"monotone",dataKey:"expenses",stroke:"var(--color-expenses)",strokeWidth:2,dot:{fill:"var(--color-expenses)",r:4}})]})})})]})]})}const qt="updateBusiness",_s=()=>{const[{fetching:s},a]=Be(Ys),t=C.useCallback(async n=>{const l=`Error updating business ID [${n.businessId}]`,o=`${qt}-${n.businessId}`;$.loading("Updating business",{id:o});try{const r=await a(n),i=Pe(r,l,o,"updateBusiness");if(i)return $.success("Success",{id:o,description:"Business updated"}),i.updateBusiness}catch(r){console.error(`${l}: ${r}`),$.error("Error",{id:o,description:l,duration:1e5,closeButton:!0})}},[a]);return{fetching:s,updateBusiness:t}},Gt=Object.values(na);function js(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 Wt(s){const t=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||t?{description:s.description,tags:s.tags?.map(o=>({id:o})),phrases:s.phrases,emails:s.emails,emailListener:t}: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 Kt({data:s,refetchBusiness:a}){const t=Ie(Js,s),[n,l]=C.useState(js(t)),{userContext:o}=C.useContext(as),{updateBusiness:r,fetching:i}=_s(),[c,d]=C.useState(!1),[h,u]=C.useState(void 0),p=Le({defaultValues:n}),g=async E=>{if(!t||!o?.context.adminBusinessId)return;const B=es(E,p.formState.dirtyFields);if(!B)return;const O=Wt(B);await r({businessId:t.id,ownerId:o.context.adminBusinessId,fields:O}),B.tags?.length||B.description?(u({tagIds:B.tags?.map(m=>({id:m})),description:B.description}),d(!0)):a?.()};if(C.useEffect(()=>{if(t){const E=js(t);l(E),p.reset(E)}},[t,p]),!t)return e.jsx("div",{});const A=p.watch("isClient");return e.jsxs(G,{children:[e.jsx(W,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(K,{children:"Configurations"}),e.jsx(H,{children:"Business status, tax settings, automation rules, and integration preferences"})]}),!A&&e.jsx(Xs,{businessId:t.id,onDone:a})]})}),e.jsx(Oe,{...p,children:e.jsxs("form",{onSubmit:p.handleSubmit(g),children:[e.jsxs(Y,{className:"space-y-6",children:[e.jsx(Ht,{form:p}),e.jsx(oe,{}),e.jsx(Yt,{form:p}),e.jsx(oe,{}),e.jsx(Xt,{form:p}),e.jsx(oe,{}),e.jsx(Jt,{form:p})]}),e.jsx(Ze,{className:"flex justify-end border-t pt-6",children:e.jsxs(D,{type:"submit",disabled:i||Object.keys(p.formState.dirtyFields).length===0,children:[e.jsx(rs,{className:"h-4 w-4 mr-2"}),"Save Changes"]})})]})}),e.jsx(yt,{businessId:t.id,tagIds:h?.tagIds,description:h?.description,open:c,onOpenChange:d,onClose:a})]})}function Ht({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(y,{control:s.control,name:"isClient",render:({field:a,fieldState:t})=>e.jsxs(N,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(b,{children:"Is Client"}),e.jsx(ae,{children:"Mark this business as a client"})]}),e.jsx(w,{children:e.jsx(ee,{disabled:!0,checked:a.value,onCheckedChange:a.onChange,className:T(t)})})]})}),e.jsx(y,{control:s.control,name:"isActive",render:({field:a,fieldState:t})=>e.jsxs(N,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(b,{children:"Is Active"}),e.jsx(ae,{children:"Business is currently active"})]}),e.jsx(w,{children:e.jsx(ee,{checked:a.value,onCheckedChange:a.onChange,className:T(t)})})]})}),e.jsx(y,{control:s.control,name:"isReceiptEnough",render:({field:a,fieldState:t})=>e.jsxs(N,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(b,{children:"Is Receipt Enough"}),e.jsx(ae,{children:"Generate ledger for receipt documents if no invoice available"})]}),e.jsx(w,{children:e.jsx(ee,{checked:a.value,onCheckedChange:a.onChange,className:T(t)})})]})}),e.jsx(y,{control:s.control,name:"isDocumentsOptional",render:({field:a,fieldState:t})=>e.jsxs(N,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(b,{children:"No Docs Required"}),e.jsx(ae,{children:"Skip document validation for common charges"})]}),e.jsx(w,{children:e.jsx(ee,{checked:a.value,onCheckedChange:a.onChange,className:T(t)})})]})}),e.jsx(y,{control:s.control,name:"isVatOptional",render:({field:a,fieldState:t})=>e.jsxs(N,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(b,{children:"Is VAT Optional"}),e.jsx(ae,{children:"Mute missing VAT indicator"})]}),e.jsx(w,{children:e.jsx(ee,{checked:a.value,onCheckedChange:a.onChange,className:T(t)})})]})}),e.jsx(y,{control:s.control,name:"isExemptDealer",render:({field:a,fieldState:t})=>e.jsxs(N,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(b,{children:"Is Exempt Dealer"}),e.jsx(ae,{children:"Business is exempt from VAT requirements"})]}),e.jsx(w,{children:e.jsx(ee,{checked:a.value,onCheckedChange:a.onChange,className:T(t)})})]})})]})]})}function Yt({form:s}){const{selectableTaxCategories:a,fetching:t}=Qs(),{selectableSortCodes:n,fetching:l,sortCodes:o}=Zs(),{selectableTags:r,fetching:i}=ea(),c=C.useCallback(d=>{if(d){const h=o.find(u=>Number(u.key)===Number(d));h&&(h.defaultIrsCode?s.setValue("irsCode",h.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(y,{control:s.control,name:"sortCode",render:({field:d,fieldState:h})=>e.jsxs(N,{children:[e.jsx(b,{children:"Sort Code"}),e.jsx(w,{children:e.jsx(Ue,{onChange:u=>{c(u),d.onChange(u)},data:n,value:d.value,disabled:l,placeholder:"Scroll to see all options",formPart:!0,triggerProps:{className:T(h)}})}),e.jsx(I,{})]})}),e.jsx(y,{control:s.control,name:"taxCategory",render:({field:d,fieldState:h})=>e.jsxs(N,{children:[e.jsx(b,{children:"Tax Category"}),e.jsx(w,{children:e.jsx(Ue,{data:a,disabled:t,value:d.value,onChange:d.onChange,placeholder:"Scroll to see all options",formPart:!0,triggerProps:{className:T(h)}})}),e.jsx(I,{})]})}),e.jsx(y,{control:s.control,name:"pcn874RecordType",render:({field:d,fieldState:h})=>e.jsxs(N,{children:[e.jsx(b,{children:"PCN874 Record Type"}),e.jsxs(fe,{onValueChange:d.onChange,value:d.value,children:[e.jsx(w,{children:e.jsx(ve,{className:T(h),children:e.jsx(ye,{})})}),e.jsx(Ne,{children:Object.entries(sa).map(([u,p])=>e.jsx(be,{value:u,children:`${p} (${u})`},u))})]}),e.jsx(I,{})]})}),e.jsx(y,{control:s.control,name:"irsCode",render:({field:d,fieldState:h})=>e.jsxs(N,{children:[e.jsx(b,{children:"IRS Code"}),e.jsx(w,{children:e.jsx(aa,{value:d.value??void 0,onValueChange:u=>d.onChange(u??null),hideControls:!0,decimalScale:0,className:T(h)})}),e.jsx(I,{})]})}),e.jsx(y,{control:s.control,name:"description",render:({field:d,fieldState:h})=>e.jsxs(N,{children:[e.jsx(b,{children:"Charge Description"}),e.jsx(w,{children:e.jsx(k,{placeholder:"Enter default charge description",...d,className:T(h)})}),e.jsx(I,{})]})}),e.jsx(y,{control:s.control,name:"tags",render:({field:d,fieldState:h})=>e.jsxs(N,{children:[e.jsx(b,{children:"Tags"}),e.jsx(w,{children:e.jsx(ta,{options:Object.values(r).map(({value:u,label:p})=>({label:p,value:u})),onValueChange:d.onChange,defaultValue:d.value,value:d.value,placeholder:"Select Default Tags",variant:"default",disabled:i,className:T(h)})}),e.jsx(I,{})]})})]})]})}function Xt({form:s}){const[a,t]=C.useState(""),[n,l]=C.useState(""),o=()=>{if(a.trim()){const d=s.getValues("phrases");s.setValue("phrases",[...d,a.trim()],{shouldDirty:!0}),t("")}},r=()=>{if(n.trim()){const d=s.getValues("emails");s.setValue("emails",[...d,n.trim()],{shouldDirty:!0}),l("")}},i=d=>{const h=s.getValues("phrases");s.setValue("phrases",h.filter((u,p)=>p!==d),{shouldDirty:!0})},c=d=>{const h=s.getValues("emails");s.setValue("emails",h.filter((u,p)=>p!==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(y,{control:s.control,name:"phrases",render:({field:d,fieldState:h})=>e.jsxs(N,{children:[e.jsx(b,{children:"Phrases"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(k,{placeholder:"Add phrase...",value:a,onChange:u=>t(u.target.value),onKeyDown:u=>{u.key==="Enter"&&(u.preventDefault(),o())},className:T(h)}),e.jsx(D,{type:"button",size:"sm",onClick:o,children:e.jsx(M,{className:"h-4 w-4"})})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:d.value?.map((u,p)=>e.jsxs(se,{variant:"secondary",className:"gap-1",children:[u,e.jsx(D,{variant:"ghost",size:"icon",className:"p-0 size-3",onClick:()=>i(p),children:e.jsx(Q,{className:"size-3 cursor-pointer",onClick:()=>i(p)})})]},p))}),e.jsx(I,{})]})}),e.jsx(y,{control:s.control,name:"emails",render:({field:d,fieldState:h})=>e.jsxs(N,{children:[e.jsx(b,{children:"Email Addresses"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(k,{type:"email",placeholder:"Add email...",value:n,onChange:u=>l(u.target.value),onKeyDown:u=>{u.key==="Enter"&&(u.preventDefault(),r())},className:T(h)}),e.jsx(D,{type:"button",size:"sm",onClick:r,children:e.jsx(M,{className:"h-4 w-4"})})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:d.value?.map((u,p)=>e.jsxs(se,{variant:"secondary",className:"gap-1",children:[u,e.jsx(D,{variant:"ghost",size:"icon",className:"p-0 size-3",onClick:()=>c(p),children:e.jsx(Q,{className:"size-3 cursor-pointer"})})]},p))}),e.jsx(I,{})]})})]})}function Jt({form:s}){const[a,t]=C.useState(""),n=()=>{if(a.trim()){const r=s.getValues("internalLinks");s.setValue("internalLinks",[...r,a.trim()],{shouldDirty:!0}),t("")}},l=r=>{const i=s.getValues("attachmentTypes");s.setValue("attachmentTypes",i?.includes(r)?i.filter(c=>c!==r):[...i,r],{shouldDirty:!0})},o=r=>{const i=s.getValues("internalLinks");s.setValue("internalLinks",i.filter((c,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(y,{control:s.control,name:"attachmentTypes",render:({field:r,fieldState:i})=>e.jsxs(N,{children:[e.jsx(b,{children:"Attachment Types"}),e.jsx("div",{className:T(i)+" rounded-md flex flex-wrap gap-2",children:Gt.map(c=>e.jsx(se,{variant:r.value?.includes(c)?"default":"outline",className:"cursor-pointer",onClick:()=>l(c),children:c},c))}),e.jsx(I,{})]})}),e.jsx(y,{control:s.control,name:"internalLinks",render:({field:r,fieldState:i})=>e.jsxs(N,{children:[e.jsx(b,{children:"Internal Links"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(k,{type:"url",placeholder:"Add internal link...",value:a,onChange:c=>t(c.target.value),onKeyDown:c=>{c.key==="Enter"&&(c.preventDefault(),n())}}),e.jsx(D,{type:"button",size:"sm",onClick:n,children:e.jsx(M,{className:"h-4 w-4"})})]}),e.jsx("div",{className:T(i)+" flex flex-wrap gap-2 rounded-md",children:r.value?.map((c,d)=>e.jsxs(se,{variant:"secondary",className:"gap-1 max-w-xs truncate",children:[c,e.jsx(D,{variant:"ghost",size:"icon",className:"p-0 size-3",onClick:()=>o(d),children:e.jsx(Q,{className:"size-3 cursor-pointer flex-shrink-0"})})]},d))}),e.jsx(I,{})]})}),e.jsx(y,{control:s.control,name:"useMessageBody",render:({field:r,fieldState:i})=>e.jsxs(N,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(b,{children:"Should Use Message Body"}),e.jsx(ae,{children:"Extract information from email message body"})]}),e.jsx(w,{children:e.jsx(ee,{checked:r.value,onCheckedChange:r.onChange,className:T(i)})})]})})]})}const Qt=Ae({businessName:R().min(1,"Business name is required"),locality:R().min(1,"Locality is required"),localName:R().optional(),govId:R().optional(),address:R().optional(),localAddress:R().optional(),phone:R().optional(),website:bs("Invalid URL").optional().or(Cs("")),generalContacts:te(cs()).optional(),billingEmails:te(cs()).optional()});function gs(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 Zt(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 en({data:s,refetchBusiness:a}){const t=Ie(la,s),[n,l]=C.useState(gs(t)),{userContext:o}=C.useContext(as),{updateBusiness:r,fetching:i}=_s(),c=Le({resolver:Qe(Qt),defaultValues:n}),{countries:d,fetching:h}=ia(),[u,p]=C.useState(""),[g,A]=C.useState(""),E=c.watch("locality"),B=c.watch("address"),O=c.watch("localAddress");C.useEffect(()=>{B!==n.address&&c.setValue("address",B,{shouldDirty:!0})},[B,n.address,c]),C.useEffect(()=>{O!==n.localAddress&&c.setValue("localAddress",O,{shouldDirty:!0})},[O,n.localAddress,c]);const m=t&&"clientInfo"in t&&!!t.clientInfo,f=E===o?.context.locality,L=v=>{u.trim()&&(c.setValue("generalContacts",[...v,u.trim()],{shouldDirty:!0}),p(""))},F=(v,x)=>{c.setValue("generalContacts",v.filter((j,P)=>P!==x),{shouldDirty:!0})},X=v=>{g.trim()&&(c.setValue("billingEmails",[...v,g.trim()],{shouldDirty:!0}),A(""))},z=(v,x)=>{c.setValue("billingEmails",v.filter((j,P)=>P!==x),{shouldDirty:!0})},Z=async v=>{if(!t||!o?.context.adminBusinessId)return;const x=es(v,c.formState.dirtyFields);if(!x)return;const j=Zt(x);await r({businessId:t.id,ownerId:o.context.adminBusinessId,fields:j}),a?.()};return C.useEffect(()=>{if(t){const v=gs(t);l(v),c.reset(v)}},[t,c]),e.jsxs(G,{children:[e.jsxs(W,{children:[e.jsx(K,{children:"Contact Information"}),e.jsx(H,{children:"Business contact details and address information"})]}),e.jsx(Oe,{...c,children:e.jsxs("form",{onSubmit:c.handleSubmit(Z),children:[e.jsx(Y,{children:e.jsxs("div",{className:"grid gap-6 md:grid-cols-2",children:[e.jsx(y,{control:c.control,name:"businessName",render:({field:v,fieldState:x})=>e.jsxs(N,{children:[e.jsx(b,{children:"Business Name"}),e.jsx(w,{children:e.jsx(k,{...v,className:T(x)})}),e.jsx(I,{})]})}),e.jsx(y,{control:c.control,name:"locality",render:({field:v,fieldState:x})=>e.jsxs(N,{children:[e.jsx(b,{children:"Locality / Country"}),e.jsx(Ue,{onChange:v.onChange,data:d.map(j=>({value:j.code,label:j.name})),value:v.value,disabled:h,placeholder:"Scroll to see all options",formPart:!0,triggerProps:{className:T(x)}}),e.jsx(I,{})]})}),f&&e.jsx(y,{control:c.control,name:"localName",render:({field:v,fieldState:x})=>e.jsxs(N,{children:[e.jsx(b,{children:"Local Name"}),e.jsx(w,{children:e.jsx(k,{...v,placeholder:"Business name in local language",className:T(x)})}),e.jsx(I,{})]})}),f&&e.jsx(y,{control:c.control,name:"govId",render:({field:v,fieldState:x})=>e.jsxs(N,{children:[e.jsx(b,{children:"Government ID"}),e.jsx(w,{children:e.jsx(k,{...v,placeholder:"Enter Government ID",className:T(x)})}),e.jsx(I,{})]})}),e.jsx(y,{control:c.control,name:"address",render:({field:v,fieldState:x})=>e.jsxs(N,{className:"md:col-span-2",children:[e.jsxs(b,{className:"flex items-center gap-2",children:[e.jsx(qe,{className:"h-4 w-4"}),"Address"]}),e.jsx(w,{children:e.jsx(Ge,{...v,rows:3,placeholder:"Enter business address",className:T(x)})}),e.jsx(I,{})]})}),f&&e.jsx(y,{control:c.control,name:"localAddress",render:({field:v,fieldState:x})=>e.jsxs(N,{className:"md:col-span-2",children:[e.jsxs(b,{className:"flex items-center gap-2",children:[e.jsx(qe,{className:"h-4 w-4"}),"Local Address"]}),e.jsx(w,{children:e.jsx(Ge,{...v,rows:3,placeholder:"Enter address in local language",className:T(x)})}),e.jsx(I,{})]})}),e.jsx(y,{control:c.control,name:"phone",render:({field:v,fieldState:x})=>e.jsxs(N,{children:[e.jsxs(b,{className:"flex items-center gap-2",children:[e.jsx(Ns,{className:"h-4 w-4"}),"Phone"]}),e.jsx(w,{children:e.jsx(k,{...v,type:"tel",placeholder:"+1 (555) 123-4567",className:T(x)})}),e.jsx(I,{})]})}),e.jsx(y,{control:c.control,name:"website",render:({field:v,fieldState:x})=>e.jsxs(N,{children:[e.jsxs(b,{className:"flex items-center gap-2",children:[e.jsx(ra,{className:"h-4 w-4"}),"Website"]}),e.jsx(w,{children:e.jsx(k,{...v,type:"url",placeholder:"https://example.com",className:T(x)})}),e.jsx(I,{})]})}),e.jsx(y,{control:c.control,name:"generalContacts",render:({field:v,fieldState:x})=>e.jsxs(N,{className:"md:col-span-2",children:[e.jsxs(b,{className:"flex items-center gap-2",children:[e.jsx(We,{className:"h-4 w-4"}),"General Contacts"]}),e.jsx(w,{children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:T(x)+" flex flex-wrap gap-2 mb-2 rounded-md",children:v.value?.map((j,P)=>e.jsxs(se,{variant:"secondary",className:"gap-1 pr-1",children:[j,e.jsx("button",{type:"button",onClick:()=>F(v.value??[],P),className:"ml-1 hover:bg-muted rounded-sm p-0.5",children:e.jsx(Q,{className:"h-3 w-3"})})]},P))}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(k,{value:u,onChange:j=>p(j.target.value),onKeyDown:j=>{j.key==="Enter"&&(j.preventDefault(),L(v.value??[]))},placeholder:"Add contact email",type:"email"}),e.jsx(D,{type:"button",variant:"outline",size:"icon",disabled:!u.trim(),onClick:()=>L(v.value??[]),children:e.jsx(M,{className:"h-4 w-4"})})]})]})}),e.jsx(I,{})]})}),m&&e.jsx(y,{control:c.control,name:"billingEmails",render:({field:v,fieldState:x})=>e.jsxs(N,{className:"md:col-span-2",children:[e.jsxs(b,{className:"flex items-center gap-2",children:[e.jsx(We,{className:"h-4 w-4"}),"Billing Emails"]}),e.jsx(w,{children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:T(x)+" flex flex-wrap gap-2 mb-2 rounded-md",children:v.value?.map((j,P)=>e.jsxs(se,{variant:"secondary",className:"gap-1 pr-1",children:[j,e.jsx("button",{type:"button",onClick:()=>z(v.value??[],P),className:"ml-1 hover:bg-muted rounded-sm p-0.5",children:e.jsx(Q,{className:"h-3 w-3"})})]},P))}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(k,{value:g,onChange:j=>A(j.target.value),onKeyDown:j=>{j.key==="Enter"&&(j.preventDefault(),X(v.value??[]))},placeholder:"Add billing email",type:"email"}),e.jsx(D,{type:"button",variant:"outline",size:"icon",disabled:!g.trim(),onClick:()=>X(v.value??[]),children:e.jsx(M,{className:"h-4 w-4"})})]})]})}),e.jsx(I,{})]})})]})}),e.jsx(Ze,{className:"flex justify-end border-t mt-4 pt-6",children:e.jsxs(D,{type:"submit",disabled:i||Object.keys(c.formState.dirtyFields).length===0,children:[e.jsx(rs,{className:"h-4 w-4 mr-2"}),"Save Changes"]})})]})})]})}const sn="createContract",an=()=>{const[{fetching:s},a]=Be(ca),t=C.useCallback(async n=>{const l=`Error creating new contract for client[${n.input.clientId}]`,o=`${sn}-${n.input.clientId}`;$.loading("Creating contract",{id:o});try{const r=await a(n);Pe(r,l,o)&&$.success("Success",{id:o,description:`Contract for client ${n.input.clientId} was successfully created`})}catch(r){console.error(`${l}: ${r}`),$.error("Error",{id:o,description:l,duration:1e5,closeButton:!0})}},[a]);return{creating:s,createContract:t}},tn="updateContract",nn=()=>{const[{fetching:s},a]=Be(oa),t=C.useCallback(async n=>{const l=`Error updating contract ID [${n.contractId}]`,o=`${tn}-${n.contractId}`;$.loading("Updating contract",{id:o});try{const r=await a(n),i=Pe(r,l,o,"updateContract");if(i)return $.success("Success",{id:o,description:"Contract updated"}),i.updateContract}catch(r){console.error(`${l}: ${r}`),$.error("Error",{id:o,description:l,duration:1e5,closeButton:!0})}},[a]);return{updating:s,updateContract:t}},rn=Ae({id:ua().optional(),startDate:ze("Start date is required"),endDate:ze("End date is required"),pos:te(R()),paymentAmount:ss().min(0,"Payment amount must be non-negative"),paymentCurrency:xe(Object.values(ns),"Currency is required"),productType:xe(Object.values(ws)).optional(),msCloudLink:bs().optional().or(Cs("")),billingCycle:xe(Object.values(we)).optional(),subscriptionPlan:xe(Object.values(Te)).optional(),isActive:ma(),defaultRemark:R().optional(),defaultDocumentType:xe(Object.values(ts)),operationsLimit:da().min(0,"Operations limit must be non-negative")}),fs={startDate:"",endDate:"",pos:[],paymentAmount:0,paymentCurrency:ns.Usd,productType:ws.Hive,msCloudLink:void 0,billingCycle:we.Monthly,subscriptionPlan:void 0,isActive:!0,defaultRemark:void 0,defaultDocumentType:ts.Proforma,operationsLimit:0};function ln({clientId:s,contract:a,onDone:t}){const[n,l]=C.useState(!1),[o,r]=C.useState(null),[i,c]=C.useState(""),{updateContract:d,updating:h}=nn(),{createContract:u,creating:p}=an(),g=Le({resolver:Qe(rn),defaultValues:a||fs}),A=()=>{const m=i.trim();if(m){const f=g.getValues("pos");f.includes(m)||g.setValue("pos",[...f,m],{shouldDirty:!0}),c("")}},E=m=>{const f=g.getValues("pos");g.setValue("pos",f.filter((L,F)=>F!==m),{shouldDirty:!0})};C.useEffect(()=>{a&&(r(a),g.reset({startDate:a.startDate,endDate:a.endDate,pos:a.pos,paymentAmount:a.paymentAmount,paymentCurrency:a.paymentCurrency,productType:a.productType,msCloudLink:a.msCloudLink,billingCycle:a.billingCycle,subscriptionPlan:a.subscriptionPlan,isActive:a.isActive,defaultRemark:a.defaultRemark,defaultDocumentType:a.defaultDocumentType,operationsLimit:a.operationsLimit}),l(!0))},[a,g]);const B=()=>{r(null),g.reset(fs),l(!0)},O=C.useCallback(async m=>{if(o)await d({contractId:o.id,input:{amount:{raw:m.paymentAmount,currency:m.paymentCurrency},billingCycle:m.billingCycle,documentType:m.defaultDocumentType,endDate:ce(new Date(m.endDate),"yyyy-MM-dd"),isActive:m.isActive,msCloud:m.msCloudLink,plan:m.subscriptionPlan,product:m.productType,purchaseOrders:m.pos,remarks:m.defaultRemark,startDate:ce(new Date(m.startDate),"yyyy-MM-dd"),operationsLimit:m.operationsLimit}});else{if(!m.billingCycle){g.setError("billingCycle",{message:"Billing cycle is required"});return}await u({input:{clientId:s,amount:{raw:m.paymentAmount,currency:m.paymentCurrency},billingCycle:m.billingCycle,documentType:m.defaultDocumentType,endDate:ce(new Date(m.endDate),"yyyy-MM-dd"),isActive:m.isActive,msCloud:m.msCloudLink,plan:m.subscriptionPlan,product:m.productType,purchaseOrders:m.pos,remarks:m.defaultRemark,startDate:ce(new Date(m.startDate),"yyyy-MM-dd"),operationsLimit:m.operationsLimit}})}l(!1),r(null),t?.()},[o,t,u,d,s,g]);return e.jsxs(Xe,{open:n,onOpenChange:l,children:[e.jsx(As,{asChild:!0,children:e.jsxs(D,{size:"sm",onClick:B,children:[e.jsx(M,{className:"h-4 w-4 mr-2"}),"New Contract"]})}),e.jsxs(Je,{className:"max-w-2xl max-h-[90vh] overflow-y-auto",children:[e.jsxs(Is,{children:[e.jsx(Ss,{children:o?"Edit Contract":"Create New Contract"}),e.jsx(Ds,{children:o?"Update contract details":"Add a new contract with all required details"})]}),e.jsx(Oe,{...g,children:e.jsxs("form",{onSubmit:g.handleSubmit(O),children:[e.jsxs("div",{className:"grid gap-4 py-4",children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsx(y,{control:g.control,name:"operationsLimit",render:({field:m})=>e.jsxs(N,{children:[e.jsx(b,{children:"Operations Limit"}),e.jsx(w,{children:e.jsx(k,{type:"number",placeholder:"500",...m})}),e.jsx(I,{})]})}),e.jsx(y,{control:g.control,name:"pos",render:({field:m})=>e.jsxs(N,{children:[e.jsx(b,{children:"Purchase Orders"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(k,{placeholder:"Add PO...",value:i,onChange:f=>c(f.target.value),onKeyDown:f=>{f.key==="Enter"&&(f.preventDefault(),A())}}),e.jsx(D,{type:"button",size:"sm",onClick:A,children:e.jsx(M,{className:"h-4 w-4"})})]}),e.jsx("div",{className:"flex flex-wrap gap-2 mt-2",children:m.value?.map((f,L)=>e.jsxs(se,{variant:"secondary",className:"gap-1 max-w-xs truncate",children:[f,L===m.value.length-1&&e.jsx(D,{variant:"ghost",size:"icon",className:"p-0 size-3",onClick:()=>E(L),children:e.jsx(Q,{className:"size-3 cursor-pointer flex-shrink-0"})})]},f))}),e.jsx(I,{})]})})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsx(y,{control:g.control,name:"startDate",render:({field:{onChange:m,...f}})=>e.jsxs(N,{children:[e.jsx(b,{children:"Start Date"}),e.jsx(w,{children:e.jsx(k,{type:"date",...f,onInput:L=>m(L)})}),e.jsx(I,{})]})}),e.jsx(y,{control:g.control,name:"endDate",render:({field:{onChange:m,...f}})=>e.jsxs(N,{children:[e.jsx(b,{children:"End Date"}),e.jsx(w,{children:e.jsx(k,{type:"date",...f,onInput:L=>m(L)})}),e.jsx(I,{})]})})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-3",children:[e.jsx(y,{control:g.control,name:"paymentAmount",render:({field:m})=>e.jsxs(N,{className:"md:col-span-2",children:[e.jsx(b,{children:"Payment Amount"}),e.jsx(w,{children:e.jsx(k,{type:"number",placeholder:"24000",...m,onChange:f=>{m.onChange(f?.target.value?Number(f?.target.value):void 0)}})}),e.jsx(I,{})]})}),e.jsx(y,{control:g.control,name:"paymentCurrency",render:({field:m})=>e.jsxs(N,{children:[e.jsx(b,{children:"Currency"}),e.jsxs(fe,{onValueChange:m.onChange,defaultValue:m.value,children:[e.jsx(w,{children:e.jsx(ve,{children:e.jsx(ye,{})})}),e.jsx(Ne,{children:Object.values(ns).map(f=>e.jsx(be,{value:f,children:f},f))})]}),e.jsx(I,{})]})})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsx(y,{control:g.control,name:"productType",render:({field:m})=>e.jsxs(N,{children:[e.jsx(b,{children:"Product Type"}),e.jsx(w,{children:e.jsx(k,{placeholder:"Cloud Services",...m})}),e.jsx(I,{})]})}),e.jsx(y,{control:g.control,name:"billingCycle",render:({field:m})=>e.jsxs(N,{children:[e.jsx(b,{children:"Billing Cycle"}),e.jsxs(fe,{onValueChange:m.onChange,defaultValue:m.value,children:[e.jsx(w,{children:e.jsx(ve,{children:e.jsx(ye,{})})}),e.jsx(Ne,{children:Object.values(we).map(f=>e.jsx(be,{value:f,children:Ls(f)},f))})]}),e.jsx(I,{})]})})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsx(y,{control:g.control,name:"subscriptionPlan",render:({field:m})=>e.jsxs(N,{children:[e.jsx(b,{children:"Subscription Plan"}),e.jsx(w,{children:e.jsxs(fe,{onValueChange:m.onChange,defaultValue:m.value,children:[e.jsx(w,{children:e.jsx(ve,{children:e.jsx(ye,{})})}),e.jsx(Ne,{children:Object.values(Te).map(f=>e.jsx(be,{value:f,children:Os(f)},f))})]})}),e.jsx(I,{})]})}),e.jsx(y,{control:g.control,name:"isActive",render:({field:m})=>e.jsxs(N,{className:"flex flex-row items-center justify-between rounded-lg border p-4",children:[e.jsx("div",{className:"space-y-0.5",children:e.jsx(b,{className:"text-base",children:"Active Status"})}),e.jsx(w,{children:e.jsx(ee,{checked:m.value,onCheckedChange:m.onChange})})]})})]}),e.jsx(y,{control:g.control,name:"msCloudLink",render:({field:m})=>e.jsxs(N,{children:[e.jsx(b,{children:"MS Cloud Link"}),e.jsx(w,{children:e.jsx(k,{type:"url",placeholder:"https://portal.azure.com/contract-id",...m})}),e.jsx(I,{})]})}),e.jsx(y,{control:g.control,name:"defaultDocumentType",render:({field:m})=>e.jsxs(N,{children:[e.jsx(b,{children:"Default Document Type"}),e.jsxs(fe,{onValueChange:m.onChange,defaultValue:m.value,children:[e.jsx(w,{children:e.jsx(ve,{children:e.jsx(ye,{})})}),e.jsx(Ne,{children:Object.values(ts).map(f=>e.jsx(be,{value:f,children:ks(f)},f))})]}),e.jsx(I,{})]})}),e.jsx(y,{control:g.control,name:"defaultRemark",render:({field:m})=>e.jsxs(N,{children:[e.jsx(b,{children:"Default Remark"}),e.jsx(w,{children:e.jsx(Ge,{placeholder:"Enter default remark for this contract...",rows:3,...m})}),e.jsx(I,{})]})})]}),e.jsxs(Ts,{children:[e.jsx(D,{type:"button",variant:"outline",onClick:()=>l(!1),children:"Cancel"}),e.jsx(D,{type:"submit",disabled:p||h,children:o?"Update Contract":"Create Contract"})]})]})})]})]})}function cn(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 on({clientId:s}){const[a,t]=C.useState(null),[{data:n,fetching:l},o]=ie({query:ha,variables:{clientId:s}}),r=n?.contractsByClient??[];return l?e.jsx("div",{children:"Loading contracts..."}):e.jsxs(G,{children:[e.jsx(W,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(K,{children:"Contracts"}),e.jsx(H,{children:"Current and past contracts sorted by start date"})]}),e.jsx(ln,{clientId:s,contract:a,onDone:o})]})}),e.jsx(Y,{className:"space-y-4",children:r.map(i=>{const c=!!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(se,{variant:c?"default":"secondary",children:i.isActive?"Active":"Inactive"})]}),e.jsx("p",{className:"text-sm text-muted-foreground font-mono",children:i.id})]}),e.jsx(D,{variant:"ghost",size:"sm",onClick:()=>t(cn(i)),children:e.jsx(tt,{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(xa,{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:pa(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:Ls(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?Os(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:ks(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(D,{variant:"outline",size:"sm",asChild:!0,children:e.jsxs("a",{href:i.msCloud.toString(),target:"_blank",rel:"noopener noreferrer",children:[e.jsx(ja,{className:"h-4 w-4 mr-2"}),"MS Cloud",e.jsx(nt,{className:"h-3 w-3 ml-1"})]})})})]},i.id)})})]})}function dn({businessId:s}){return e.jsxs(G,{children:[e.jsx(W,{children:e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{children:[e.jsx(K,{children:"Documents"}),e.jsx(H,{children:"Invoices, proformas, receipts, and other accounting documents"})]})})}),e.jsx(Y,{children:e.jsx(ga,{businessId:s,linkedDocumentIds:[],limit:1e3})})]})}const mn=[{id:"hive",name:"Hive",description:"Schema registry, analytics, metrics and gateway for GraphQL federation and other GraphQL APIs",status:"disconnected",lastSync:"Never"},{id:"slack",name:"Slack",description:"Team communication and notifications",status:"disconnected",lastSync:"Never"},{id:"retool",name:"Retool",description:"Internal tools and dashboards",status:"disconnected",lastSync:"Never"},{id:"linear",name:"Linear",description:"Issue tracking and project management",status:"disconnected",lastSync:"Never"},{id:"workflowy",name:"Workflowy",description:"Task management and note taking",status:"disconnected",lastSync:"Never"}];function un({data:s}){const a=Ie(Na,s),[{data:t,fetching:n},l]=ie({query:fa,variables:{clientId:a?.id??""},pause:!a?.clientInfo?.greenInvoiceId||!a?.id}),{updateClient:o}=va(),r=C.useCallback((c,d)=>{if(!a?.id)return;const h={};h[d]=c,o({businessId:a?.id,fields:h})},[a?.id,o]);C.useEffect(()=>{a?.clientInfo?.greenInvoiceId&&a?.id&&l()},[a?.clientInfo?.greenInvoiceId,a?.id,l]);const i=t?.greenInvoiceClient;return e.jsxs(G,{children:[e.jsx(W,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(K,{children:"Integrations"}),e.jsx(H,{children:"Connected external services and providers"})]}),e.jsxs(D,{size:"sm",children:[e.jsx(M,{className:"h-4 w-4 mr-2"}),"Add Integration"]})]})}),e.jsx(Y,{className:"space-y-6",children:e.jsxs(rt,{type:"multiple",defaultValue:["green-invoice"],className:"space-y-4",children:[n?e.jsxs(_e,{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(S,{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(S,{className:"h-6 w-32"}),e.jsx(S,{className:"h-5 w-5 rounded-full"})]}),e.jsx(S,{className:"h-4 w-64"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(S,{className:"h-8 w-24"}),e.jsx(S,{className:"h-8 w-8"})]})]})}),e.jsx(Re,{children:e.jsxs("div",{className:"p-6 space-y-6",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx(S,{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(S,{className:"h-3 w-24"}),e.jsx(S,{className:"h-4 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(S,{className:"h-3 w-24"}),e.jsx(S,{className:"h-4 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(S,{className:"h-3 w-24"}),e.jsx(S,{className:"h-4 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(S,{className:"h-3 w-24"}),e.jsx(S,{className:"h-4 w-full"})]})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(S,{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(S,{className:"h-3 w-32"}),e.jsx(S,{className:"h-6 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(S,{className:"h-3 w-24"}),e.jsx(S,{className:"h-4 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(S,{className:"h-3 w-24"}),e.jsx(S,{className:"h-4 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(S,{className:"h-3 w-24"}),e.jsx(S,{className:"h-4 w-full"})]})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(S,{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(S,{className:"h-3 w-24"}),e.jsx(S,{className:"h-4 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(S,{className:"h-3 w-24"}),e.jsx(S,{className:"h-4 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(S,{className:"h-3 w-24"}),e.jsx(S,{className:"h-4 w-full"})]})]})]})]})})]}):e.jsxs(_e,{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(ms,{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(hn,{id:a?.clientInfo?.greenInvoiceId,provider:"Green Invoice",updateClient:async c=>r(c,"greenInvoiceId")}),e.jsx(ds,{className:"hover:no-underline p-2"})]})]})}),e.jsx(Re,{children:i&&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:a?.clientInfo?.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:i.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:i.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:i.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(We,{className:"h-3.5 w-3.5"}),"Email Addresses"]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:i.emails?.map((c,d)=>e.jsx("span",{className:"text-sm px-2 py-1 bg-muted rounded",children:c},d))})]}),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(Ns,{className:"h-3.5 w-3.5"}),"Phone"]}),e.jsx("p",{className:"text-sm font-mono",children:i.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:i.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:i.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(qe,{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:i.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:i.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:i.zip})]})]})]})]})})]}),mn.map(c=>e.jsxs(_e,{value:c.id,className:"rounded-lg border",children:[e.jsx("div",{className:"px-4 py-3",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{className:"flex items-center gap-3 flex-1",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:c.name}),c.status==="connected"?e.jsx(ms,{className:"h-4 w-4 text-green-600"}):e.jsx(ya,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:c.description})]})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(D,{variant:"ghost",size:"sm",onClick:d=>d.stopPropagation(),children:e.jsx(is,{className:"h-4 w-4"})}),e.jsx(ds,{className:"hover:no-underline p-2"})]})]})}),e.jsx(Re,{children:e.jsx("div",{className:"px-4 pb-4 pt-2 border-t",children:e.jsxs("div",{className:"text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:"Last sync: "}),e.jsx("span",{className:"font-medium",children:c.lastSync})]})})})]},c.id))]})})]})}function hn({id:s,provider:a,updateClient:t}){const[n,l]=C.useState(!1),[o,r]=C.useState(s),i=C.useCallback(async()=>{await t(o),l(!1)},[o,t]);return e.jsxs(Xe,{open:n,onOpenChange:l,children:[e.jsx(As,{asChild:!0,children:e.jsxs(D,{variant:"outline",size:"sm",onClick:c=>c.stopPropagation(),children:[e.jsx(is,{className:"h-4 w-4 mr-2"}),"Configure"]})}),e.jsxs(Je,{onClick:c=>c.stopPropagation(),children:[e.jsxs(Is,{children:[e.jsxs(Ss,{children:["Configure ",a]}),e.jsxs(Ds,{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(ge,{htmlFor:"id",children:[a," ID"]}),e.jsx(k,{id:"id",value:o,onChange:c=>r(c.target.value),placeholder:`Enter ${a} ID`})]})}),e.jsxs(Ts,{children:[e.jsx(D,{variant:"outline",onClick:()=>l(!1),children:"Cancel"}),e.jsx(D,{onClick:i,disabled:!o,children:"Save Changes"})]})]})]})}function xn({businessId:s}){const[{data:a,fetching:t}]=ie({query:ba,variables:{businessId:s}});return t?e.jsx("div",{children:"Loading ledger records..."}):e.jsxs(G,{children:[e.jsx(W,{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(K,{children:"Ledger Records"}),e.jsx(H,{children:"Complete ledger history for this business"})]})})}),e.jsx(Y,{children:e.jsx("div",{className:"rounded-md border",children:e.jsx(_a,{ledgerRecordsData:a?.ledgerRecordsByFinancialEntity??[]})})})]})}function pn({businessId:s}){const[{data:a,fetching:t}]=ie({query:Ca,variables:{businessId:s}});return t?e.jsx("div",{children:"Loading transactions..."}):e.jsxs(G,{children:[e.jsx(W,{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(K,{children:"Transactions"}),e.jsx(H,{children:"Complete transaction history for this business"})]})})}),e.jsx(Y,{children:e.jsx("div",{className:"rounded-md border",children:e.jsx(it,{transactionsProps:a?.transactionsByFinancialEntity??[]})})})]})}function jn({data:s,refetchBusiness:a}){const t=Ie(Ta,s),[n,l]=wa(),{setFiltersContext:o}=C.useContext(Aa);C.useEffect(()=>{o(null)},[o]);const r=n.get("tab")||"contact",i=h=>{l({tab:h})};if(!t)return e.jsx("div",{children:"Business not found"});const c="clientInfo"in t&&!!t.clientInfo,d="adminInfo"in t&&!!t.adminInfo;return e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx(Oa,{data:t}),e.jsx("main",{className:"container mx-auto px-4 py-6 md:px-6 lg:px-8 max-w-7xl",children:e.jsxs(Ia,{value:r,onValueChange:i,className:"w-full",children:[e.jsxs(Sa,{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(J,{value:"contact",className:"flex items-center gap-2 data-[state=active]:bg-background",children:[e.jsx(lt,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Contact"})]}),e.jsxs(J,{value:"config",className:"flex items-center gap-2 data-[state=active]:bg-background",children:[e.jsx(is,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Config"})]}),e.jsxs(J,{value:"charges",className:"flex items-center gap-2 data-[state=active]:bg-background",children:[e.jsx(ke,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Charges"})]}),e.jsxs(J,{value:"transactions",className:"flex items-center gap-2 data-[state=active]:bg-background",children:[e.jsx(Da,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Transactions"})]}),e.jsxs(J,{value:"documents",className:"flex items-center gap-2 data-[state=active]:bg-background",children:[e.jsx(ka,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Documents"})]}),e.jsxs(J,{value:"ledger",className:"flex items-center gap-2 data-[state=active]:bg-background",children:[e.jsx(pt,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Ledger"})]}),e.jsxs(J,{value:"balance",className:"flex items-center gap-2 data-[state=active]:bg-background",children:[e.jsx(ot,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Balance"})]}),c&&e.jsxs(e.Fragment,{children:[e.jsxs(J,{value:"contracts",className:"flex items-center gap-2 data-[state=active]:bg-background",children:[e.jsx(ht,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Contracts"})]}),e.jsxs(J,{value:"integrations",className:"flex items-center gap-2 data-[state=active]:bg-background",children:[e.jsx(gt,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Integrations"})]})]}),d&&e.jsxs(J,{value:"admin",className:"flex items-center gap-2 data-[state=active]:bg-background",children:[e.jsx(ys,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Admin"})]})]}),e.jsx(U,{value:"contact",className:"mt-0",children:e.jsx(en,{data:t,refetchBusiness:a})}),e.jsx(U,{value:"config",className:"mt-0",children:e.jsx(Kt,{data:t,refetchBusiness:a})}),e.jsx(U,{value:"charges",className:"mt-0",children:e.jsx(St,{businessId:t.id})}),e.jsx(U,{value:"transactions",className:"mt-0",children:e.jsx(pn,{businessId:t.id})}),e.jsx(U,{value:"documents",className:"mt-0",children:e.jsx(dn,{businessId:t.id})}),e.jsx(U,{value:"ledger",className:"mt-0",children:e.jsx(xn,{businessId:t.id})}),e.jsx(U,{value:"balance",className:"mt-0",children:e.jsx(It,{businessId:t.id})}),c&&e.jsxs(e.Fragment,{children:[e.jsx(U,{value:"contracts",className:"mt-0",children:e.jsx(on,{clientId:t.id})}),e.jsx(U,{value:"integrations",className:"mt-0",children:e.jsx(un,{data:t})}),e.jsx(U,{value:"charts",className:"mt-0",children:e.jsx(Ut,{})})]}),d&&e.jsx(U,{value:"admin",className:"mt-0",children:e.jsx(At,{data:t})})]})})]})}const Vn=()=>{const{businessId:s}=Ea();let a;try{a=Ba()}catch{}const[{data:t,fetching:n},l]=ie({query:Pa,pause:!s||!!a,variables:{businessId:s??""}}),o=a||t;return!a&&n&&!o?.business?e.jsx(vs,{}):!s||!o?.business?e.jsx("div",{children:"Business not found"}):e.jsx(jn,{data:o.business,refetchBusiness:async()=>l()})};export{Vn as BusinessScreen};
|
package/dist/assets/{business-extended-info-CFdeLUKP.js → business-extended-info-1mzdXJbs.js}
RENAMED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import{v as
|
|
1
|
+
import{v as M,bC as G,r as D,bE as V,ai as J,bG as H,j as e,cP as K,x as v,u as Y,dT as q,aR as o,c as Q,T as W,B as X,bV as L,R as b,b2 as A,bp as Z}from"./index-Cw_aKL-8.js";import{D as ee}from"./download-csv-button-CwK31swX.js";import{T as ne}from"./Table-DnHfGe-y.js";/**
|
|
2
2
|
* @license lucide-react v0.548.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
5
5
|
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/const te=[["path",{d:"M12 12h.01",key:"1mp3jc"}],["path",{d:"M16 12h.01",key:"1l6xoz"}],["path",{d:"m17 7 5 5-5 5",key:"1xlxn0"}],["path",{d:"m7 7-5 5 5 5",key:"19njba"}],["path",{d:"M8 12h.01",key:"czm47f"}]],se=
|
|
6
|
+
*/const te=[["path",{d:"M12 12h.01",key:"1mp3jc"}],["path",{d:"M16 12h.01",key:"1l6xoz"}],["path",{d:"m17 7 5 5-5 5",key:"1xlxn0"}],["path",{d:"m7 7-5 5 5 5",key:"19njba"}],["path",{d:"M8 12h.01",key:"czm47f"}]],se=M("chevrons-left-right-ellipsis",te);/**
|
|
7
7
|
* @license lucide-react v0.548.0 - ISC
|
|
8
8
|
*
|
|
9
9
|
* This source code is licensed under the ISC license.
|
|
10
10
|
* See the LICENSE file in the root directory of this source tree.
|
|
11
|
-
*/const re=[["path",{d:"m20 17-5-5 5-5",key:"30x0n2"}],["path",{d:"m4 17 5-5-5-5",key:"16spf4"}]],ae=
|
|
11
|
+
*/const re=[["path",{d:"m20 17-5-5 5-5",key:"30x0n2"}],["path",{d:"m4 17 5-5-5-5",key:"16spf4"}]],ae=M("chevrons-right-left",re);var oe=G((n,{color:s})=>({root:{backgroundColor:n.fn.themeColor(s,n.colorScheme==="dark"?5:2),color:n.colorScheme==="dark"?n.colors.dark[9]:"inherit"}})),ce=Object.defineProperty,C=Object.getOwnPropertySymbols,O=Object.prototype.hasOwnProperty,R=Object.prototype.propertyIsEnumerable,T=(n,s,t)=>s in n?ce(n,s,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[s]=t,ie=(n,s)=>{for(var t in s||(s={}))O.call(s,t)&&T(n,t,s[t]);if(C)for(var t of C(s))R.call(s,t)&&T(n,t,s[t]);return n},le=(n,s)=>{var t={};for(var a in n)O.call(n,a)&&s.indexOf(a)<0&&(t[a]=n[a]);if(n!=null&&C)for(var a of C(n))s.indexOf(a)<0&&R.call(n,a)&&(t[a]=n[a]);return t};const de={color:"yellow"},p=D.forwardRef((n,s)=>{const t=V("Mark",de,n),{color:a,className:i,unstyled:u,variant:h}=t,x=le(t,["color","className","unstyled","variant"]),{classes:f,cx:l}=oe({color:a},{unstyled:u,name:"Mark",variant:h});return J.createElement(H,ie({component:"mark",ref:s,className:l(f.root,i)},x))});p.displayName="@mantine/core/Mark";const ue=({ledgerRecords:n,businessName:s,fromDate:t,toDate:a})=>{const i=D.useCallback(async()=>{const u=me(n);return{fileName:`business_${s}_ledger_records${t?`_${t}`:""}${a?`_${a}`:""}`,fileContent:u}},[n,s,t,a]);return e.jsx(ee,{createFileVariables:i})},me=n=>{let s="";const t=Array.from(new Set(n.filter(a=>a.foreignAmount?.currency).map(a=>a.foreignAmount.currency)));s+=`Sorting Date,Date,Amount,Amount Balance,${he(t)}Reference,Details,Counter Account\r
|
|
12
12
|
`;for(const a of n){const i=fe(a,t);s+=i}return s};function he(n){let s="";return n.map(t=>{const a=K(t);s+=`${t}(${a}) Amount,${t}(${a}) Balance,`}),s}function xe(n,s){let t="";return s.map(a=>{n.foreignAmount&&n.foreignAmount.currency===a?t+=`${n.foreignAmount.raw},${n[`${a.toLowerCase()}Balance`]??0},`:t+=",,"}),t}function fe(n,s){let t="";const a=n.invoiceDate?v(new Date(n.invoiceDate),"yyy-MM-dd"):null,i=n.invoiceDate?v(new Date(n.invoiceDate),"dd/MM/yy"):null,u=n.amount.raw,{ilsBalance:h,reference:x,details:f}=n,l=n.counterAccount?.name??"";return t+=`${a},${i},${u},${h},${xe(n,s)}${S(x??"")},${S(f??"")},${S(l)},\r
|
|
13
|
-
`,t}function S(n){return n===""?"":Number.isNaN(Number(n))?String(n).replace(/"/g,'""').replace(/,/g,"."):Number(n).toFixed(2).toString()}function Ae({businessID:n,filter:s}){const[t,a]=D.useState(!1),{fromDate:i,ownerIds:u,toDate:h}=s??{},[{data:x,fetching:f}]=
|
|
13
|
+
`,t}function S(n){return n===""?"":Number.isNaN(Number(n))?String(n).replace(/"/g,'""').replace(/,/g,"."):Number(n).toFixed(2).toString()}function Ae({businessID:n,filter:s}){const[t,a]=D.useState(!1),{fromDate:i,ownerIds:u,toDate:h}=s??{},[{data:x,fetching:f}]=Y({query:q,variables:{filters:{fromDate:i,ownerIds:u,toDate:h,businessIDs:[n]}}}),l=x?.businessTransactionsFromLedgerRecords.__typename==="CommonError"?[]:x?.businessTransactionsFromLedgerRecords.businessTransactions.sort((r,g)=>r.invoiceDate>g.invoiceDate?1:-1)??[],j=[];for(let r=0;r<l.length;r++){const{__typename:g,...c}=l[r],z=r===0?c.amount.raw:(j[r-1].ilsBalance??0)+c.amount.raw,I={};Object.values(o).map(y=>{if(y!==o.Ils){const P=`${y.toLowerCase()}Balance`;I[P]=r===0?(c.foreignAmount?.currency===y?c.foreignAmount?.raw:0)??0:(j[r-1]?.[P]??0)+(c.foreignAmount?.currency===y?c.foreignAmount?.raw:0)}}),j.push({...c,ilsBalance:z,...I})}const m=new Set(l.filter(r=>r.foreignAmount?.currency).map(r=>r.foreignAmount.currency)),B=t||m.has(o.Eur),E=t||m.has(o.Usd),_=t||m.has(o.Gbp),k=t||m.has(o.Cad),N=t||m.has(o.Jpy),$=t||m.has(o.Aud),F=t||m.has(o.Sek),w=l[0]?.business.name??"unknown";return e.jsx("div",{className:"flex flex-row gap-5",children:f?e.jsx(Q,{}):e.jsxs(ne,{striped:!0,highlightOnHover:!0,children:[e.jsx("thead",{style:{position:"sticky",top:0,zIndex:20},children:e.jsxs("tr",{className:"px-10 py-10 title-font tracking-wider font-medium text-gray-900 text-sm bg-gray-100 rounded-tl rounded-bl",children:[e.jsx("th",{children:"Business Name"}),e.jsx("th",{children:"Date"}),e.jsx("th",{children:"Amount"}),e.jsx("th",{children:"Amount Balance"}),B&&e.jsxs(e.Fragment,{children:[e.jsx("th",{children:"EUR Amount"}),e.jsx("th",{children:"EUR Balance"})]}),E&&e.jsxs(e.Fragment,{children:[e.jsx("th",{children:"USD Amount"}),e.jsx("th",{children:"USD Balance"})]}),_&&e.jsxs(e.Fragment,{children:[e.jsx("th",{children:"GBP Amount"}),e.jsx("th",{children:"GBP Balance"})]}),k&&e.jsxs(e.Fragment,{children:[e.jsx("th",{children:"CAD Amount"}),e.jsx("th",{children:"CAD Balance"})]}),N&&e.jsxs(e.Fragment,{children:[e.jsx("th",{children:"JPY Amount"}),e.jsx("th",{children:"JPY Balance"})]}),$&&e.jsxs(e.Fragment,{children:[e.jsx("th",{children:"AUD Amount"}),e.jsx("th",{children:"AUD Balance"})]}),F&&e.jsxs(e.Fragment,{children:[e.jsx("th",{children:"SEK Amount"}),e.jsx("th",{children:"SEK Balance"})]}),e.jsx("th",{children:e.jsx(W,{label:"Expand all currencies",children:e.jsx(X,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>a(r=>!r),children:t?e.jsx(ae,{className:"size-5"}):e.jsx(se,{className:"size-5"})})})}),t&&e.jsx(e.Fragment,{children:U.map(r=>e.jsxs(e.Fragment,{children:[e.jsxs("th",{children:[r," Amount"]}),e.jsxs("th",{children:[r," Balance"]})]}))}),e.jsx("th",{children:"Reference"}),e.jsx("th",{children:"Details"}),e.jsx("th",{children:"Counter Account"}),e.jsx("th",{children:e.jsx(ue,{ledgerRecords:j,businessName:w,fromDate:s?.fromDate??void 0,toDate:s?.toDate??void 0})})]})}),e.jsx("tbody",{children:j.map((r,g)=>e.jsxs("tr",{className:"cursor-pointer",onClick:c=>{c.stopPropagation(),window.open(b.CHARGES.DETAIL(r.chargeId),"_blank","noreferrer")},children:[e.jsx("td",{children:e.jsx(L,{to:b.BUSINESSES.DETAIL(r.business.id),target:"_blank",rel:"noreferrer",onClick:c=>c.stopPropagation(),className:"inline-flex items-center font-semibold",children:r.business.name})}),e.jsx("td",{children:r.invoiceDate?v(new Date(r.invoiceDate),"dd/MM/yy"):null}),e.jsx("td",{style:{whiteSpace:"nowrap"},children:r.amount&&r.amount.raw!==0&&e.jsx(p,{color:r.amount.raw>0?"green":"red",children:r.amount.formatted})}),e.jsx("td",{children:r.ilsBalance===0?A(r.ilsBalance,o.Ils):e.jsx(p,{color:r.ilsBalance>0?"green":"red",children:A(r.ilsBalance,o.Ils)})}),B&&e.jsx(d,{data:r,currency:o.Eur}),E&&e.jsx(d,{data:r,currency:o.Usd}),_&&e.jsx(d,{data:r,currency:o.Gbp}),k&&e.jsx(d,{data:r,currency:o.Cad}),N&&e.jsx(d,{data:r,currency:o.Jpy}),$&&e.jsx(d,{data:r,currency:o.Aud}),F&&e.jsx(d,{data:r,currency:o.Sek}),e.jsx("td",{}),t&&e.jsx(je,{data:r}),e.jsx("td",{children:r.reference}),e.jsx("td",{children:r.details}),e.jsx("td",{children:r.counterAccount&&e.jsx(L,{to:b.BUSINESSES.DETAIL(r.counterAccount.id),target:"_blank",rel:"noreferrer",onClick:c=>c.stopPropagation(),className:"inline-flex items-center font-semibold",children:r.counterAccount.name})}),e.jsx("td",{})]},g))})]})})}function d({currency:n,data:s}){const t=s.foreignAmount&&s.foreignAmount.currency===n?s.foreignAmount:null,a=`${n.toLowerCase()}Balance`;return e.jsxs(e.Fragment,{children:[e.jsx("td",{style:{whiteSpace:"nowrap"},children:!!t&&t.raw!==0&&e.jsx(p,{color:t.raw>0?"green":"red",children:t.formatted})}),e.jsx("td",{children:(s[a]??0)!==0&&(s[a]===0?A(s[a],n):e.jsx(p,{color:s[a]>0?"green":"red",children:A(s[a],n)}))})]})}const U=Object.values(o).filter(n=>!Z.includes(n));function je({data:n}){return e.jsx(e.Fragment,{children:U.map(s=>e.jsx(d,{currency:s,data:n},s))})}export{Ae as B,ae as C,p as M,se as a};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{J as l,j as e,
|
|
1
|
+
import{J as l,j as e,aB as t,x as m,bm as x}from"./index-Cw_aKL-8.js";import{B as o}from"./building-2-ZTKteVvf.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};
|
package/dist/assets/{business-ledger-filters-ClJxXoLC.js → business-ledger-filters-BRB1r_DP.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as
|
|
1
|
+
import{r as g,bq as v,j as e,br as C,B as S,G as I,bs as F,af as B,bt as m,bu as y,bv as j,x as f,bw as E,bx as w}from"./index-Cw_aKL-8.js";import{u as N}from"./use-url-query-C0mVgO2i.js";import{P as L}from"./modal-Pj_6bAFk.js";import{F as R}from"./funnel-CMG4QvaK.js";import{M as D}from"./MultiSelect-Dm9mO7pJ.js";function A({filter:r,setFilter:b,closeModal:u,single:l=!1}){const{control:n,handleSubmit:p}=I({defaultValues:{...r}}),{selectableBusinesses:d,fetching:i}=F(),{userContext:x}=g.useContext(B),h=s=>{b(s),u()};function o(){b({businessIDs:l?r.businessIDs:void 0}),u()}return e.jsxs(e.Fragment,{children:[i?e.jsx("div",{children:"Loading..."}):e.jsx("div",{}),e.jsxs("form",{onSubmit:p(h),children:[e.jsx(m,{name:"ownerIds",control:n,defaultValue:r.ownerIds,render:({field:s,fieldState:a})=>e.jsx(D,{...s,data:d,value:s.value??(x?.context.adminBusinessId?[x.context.adminBusinessId]:void 0),disabled:i,label:"Owners",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:a.error?.message})}),!l&&e.jsx(m,{name:"businessIDs",control:n,defaultValue:r.businessIDs,render:({field:s,fieldState:a})=>e.jsx(D,{...s,data:d,value:s.value??void 0,disabled:i,label:"Businesses",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:a.error?.message})}),e.jsx(m,{name:"fromDate",control:n,defaultValue:r.fromDate,rules:{pattern:{value:y,message:"Date must be im format yyyy-mm-dd"}},render:({field:s,fieldState:a})=>e.jsx(j,{...s,onChange:t=>{const c=t?typeof t=="string"?t:f(t,"yyyy-MM-dd"):void 0;c!==s.value&&s.onChange(c)},value:s.value?new Date(s.value):void 0,error:a.error?.message,label:"From Date",popoverProps:{withinPortal:!0}})}),e.jsx(m,{name:"toDate",control:n,defaultValue:r.toDate,rules:{pattern:{value:y,message:"Date must be im format yyyy-mm-dd"}},render:({field:s,fieldState:a})=>e.jsx(j,{...s,onChange:t=>{const c=t?typeof t=="string"?t:f(t,"yyyy-MM-dd"):void 0;c!==s.value&&s.onChange(c)},value:s.value?new Date(s.value):void 0,error:a.error?.message,label:"To Date",popoverProps:{withinPortal:!0}})}),e.jsx(m,{name:"type",control:n,defaultValue:null,render:({field:s,fieldState:a})=>e.jsx(E,{...s,onChange:t=>s.onChange(t==="NULL"?null:t),data:[{value:"NULL",label:"All"},{value:"BUSINESS",label:"Business"},{value:"TAX_CATEGORY",label:"Tax Category"}],error:a.error?.message,label:"Type"})}),e.jsxs("div",{className:"flex justify-center mt-5 gap-3",children:[e.jsx("button",{type:"submit",className:"text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg",children:"Filter"}),e.jsx("button",{type:"button",className:"text-white bg-orange-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-orange-600 rounded-sm text-lg",onClick:o,children:"Clear"}),e.jsx("button",{type:"button",className:"text-white bg-rose-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-rose-600 rounded-sm text-lg",onClick:u,children:"Cancel"})]})]})]})}function V({filter:r,setFilter:b}){const[u,l]=g.useState(!1),[n,p]=g.useState(!v(r)),{get:d,set:i}=N();function x(o){return Object.entries(o??{}).filter(([a,t])=>t!==void 0&&Array.isArray(t)&&t.length>0).length>0}function h(o){o.fromDate?.trim()===""&&(o.fromDate=void 0),o.toDate?.trim()===""&&(o.toDate=void 0),w(o,r)||(b(o),p(x(o)))}return g.useEffect(()=>{const o=v(r)?null:encodeURIComponent(JSON.stringify(r)),s=d("ledgerRecordsFilters");o!==s&&i("ledgerRecordsFilters",o)},[r,d,i]),e.jsxs(e.Fragment,{children:[e.jsx(L,{opened:u,onClose:()=>l(!1),content:e.jsx(A,{single:!0,filter:r,setFilter:h,closeModal:()=>l(!1)})}),e.jsx(C,{inline:!0,size:16,disabled:!n,children:e.jsx(S,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>l(!0),children:e.jsx(R,{className:"size-5"})})})]})}export{V as B};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as S,r as c,F as w,u as C,j as n,c as x,aR as o,bo as y}from"./index-Cw_aKL-8.js";import{u as R}from"./use-url-query-C0mVgO2i.js";import{a as h}from"./accounter-table-BL_yrGIl.js";import{M as p,B as F}from"./business-extended-info-1mzdXJbs.js";import{B as v}from"./business-ledger-filters-BRB1r_DP.js";import"./Table-DnHfGe-y.js";import"./download-csv-button-CwK31swX.js";import"./modal-Pj_6bAFk.js";import"./funnel-CMG4QvaK.js";import"./MultiSelect-Dm9mO7pJ.js";const M=({businessId:t})=>{const{businessId:r}=S(),{get:s}=R(),{setFiltersContext:u}=c.useContext(w),l=t||r,[m,d]=c.useState(s("ledgerRecordsFilters")?{...JSON.parse(decodeURIComponent(s("ledgerRecordsFilters"))),businessIDs:l?[l]:[]}:{businessIDs:l?[l]:[]}),[{data:a,fetching:f}]=C({query:y,variables:{filters:m}});c.useEffect(()=>{u(n.jsx(v,{filter:m,setFilter:d}))},[a,m,u,d]);const b=c.useMemo(()=>a?.businessTransactionsSumFromLedgerRecords.__typename==="CommonError"?[]:a?.businessTransactionsSumFromLedgerRecords.businessTransactionsSum?a.businessTransactionsSumFromLedgerRecords.businessTransactionsSum.sort((e,g)=>e.business.name.localeCompare(g.business.name)):[],[a?.businessTransactionsSumFromLedgerRecords]);return f?n.jsx(x,{}):n.jsx(h,{moreInfo:e=>n.jsx(F,{businessID:e.business.id,filter:m}),striped:!0,highlightOnHover:!0,stickyHeader:!0,items:b,columns:[{title:"Business Name",value:e=>e.business.name},{title:"Debit",value:e=>e.debit.formatted,style:{whiteSpace:"nowrap"}},{title:"Credit",value:e=>e.credit.formatted,style:{whiteSpace:"nowrap"}},{title:"Total",value:e=>e.total.raw&&(e.total.raw<-1e-4||e.total.raw>1e-4)?n.jsx(p,{color:e.total.raw>0?"green":"red",children:e.total.formatted}):e.total.formatted,style:{whiteSpace:"nowrap"}},...i(o.Eur),...i(o.Usd),...i(o.Gbp),...i(o.Cad),...i(o.Jpy),...i(o.Aud),...i(o.Sek)]})};function i(t){return[{title:`${t} Debit`,value:r=>r.foreignCurrenciesSum.find(s=>s.currency===t)?.debit?.formatted,style:{whiteSpace:"nowrap"}},{title:`${t} Credit`,value:r=>r.foreignCurrenciesSum.find(s=>s.currency===t)?.credit?.formatted,style:{whiteSpace:"nowrap"}},{title:`${t} Total`,value:r=>{const s=r.foreignCurrenciesSum.find(u=>u.currency===t);return s?.total?.raw&&(s.total.raw<-1e-4||s.total.raw>1e-4)?n.jsx(p,{color:s.total.raw>0?"green":"red",children:s.total.formatted}):s?.total?.formatted},style:{whiteSpace:"nowrap"}}]}export{M as BusinessLedgerRecordsSingle};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as p,r as n,F as u,u as m,j as s,c,bB as x}from"./index-Cw_aKL-8.js";import{P as d,C as l,E as b}from"./editable-business-trip-Bjxkm9xV.js";import{P as f}from"./page-layout-CVTeUSZp.js";import"./list-plus-B3EB-dKe.js";import"./summary-Bbsq64IN.js";import"./Table-DnHfGe-y.js";import"./toggle-expansion-button-BrKkZtGj.js";import"./panel-top-open-DzBY_TuM.js";import"./MultiSelect-Dm9mO7pJ.js";import"./similar-transactions-modal-B39q1NLa.js";import"./tooltip-CbnJYNc4.js";const v=({businessTripId:o})=>{const{businessTripId:a}=p(),{setFiltersContext:i}=n.useContext(u),e=o??a??"",[{data:r,fetching:t}]=m({query:x,variables:{businessTripId:e}});return n.useEffect(()=>{i(s.jsx("div",{className:"flex flex-row gap-x-5",children:s.jsx(d,{filename:"business_trip_report"})}))},[r,t,i]),t||!r?.businessTrip?s.jsx(c,{}):s.jsx(f,{title:`Business Trip: ${r.businessTrip.name}`,description:"Manage business trip",children:s.jsx(l,{className:"mt-5",children:e&&s.jsx(b,{tripId:e,isExtended:!0})})})};export{v as BusinessTrip};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as I,b as x,r,u as D,j as e,c as f,C as j}from"./index-Cw_aKL-8.js";import{C as v}from"./charges-table-CWbe3t13.js";import{E as M,I as E,M as S}from"./match-document-modal-Bo9pBr8W.js";import"./toggle-expansion-button-BrKkZtGj.js";import"./panel-top-open-DzBY_TuM.js";import"./index-xxe8M91O.js";import"./similar-transactions-modal-B39q1NLa.js";import"./addDays-DqZEDZy3.js";import"./list-plus-B3EB-dKe.js";import"./tooltip-CbnJYNc4.js";import"./Table-DnHfGe-y.js";import"./summary-Bbsq64IN.js";import"./YearPickerInput-oa86GF4P.js";import"./insert-business-trip-modal-Ds3RIlmF.js";import"./accounter-table-BL_yrGIl.js";import"./modal-Pj_6bAFk.js";const G=({chargeId:u})=>{const{chargeId:g}=I(),a=u||g;let t;try{t=x()}catch{}const[o,n]=r.useState(void 0),[s,i]=r.useState(void 0),[c,d]=r.useState(void 0),[{data:p,fetching:l},m]=D({query:j,pause:!a||!!t,variables:{chargeId:a??""}});r.useEffect(()=>{a&&!t&&m()},[a,t,m]);const h=t||p,C=!t&&l;return a?e.jsxs(e.Fragment,{children:[C?e.jsx(f,{}):e.jsx(v,{setEditChargeId:n,setInsertDocument:i,setMatchDocuments:d,data:h?.charge?[h.charge]:[],isAllOpened:!0}),o&&e.jsx(M,{chargeId:o?.id,close:()=>n(void 0),onChange:o.onChange}),s&&e.jsx(E,{chargeId:s.id,onChange:s.onChange,close:()=>i(void 0)}),c&&e.jsx(S,{chargeId:c.id,ownerId:c.ownerId,setMatchDocuments:()=>d(void 0)})]}):e.jsx("div",{children:"Charge not found"})};export{G as Charge};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as i,bq as B,bx as H,j as e,P as W,br as z,B as G,af as U,G as _,x as N,ah as D,cR as q,ar as X,X as J,cS as Q,bt as h,ed as Z,bu as P,bv as O,bw as L,e4 as k,ao as m,h8 as $,a3 as K,Z as x,_ as j,$ as p,a0 as g,dg as Y,dh as ee,di as se}from"./index-Cw_aKL-8.js";import{u as ae}from"./use-url-query-C0mVgO2i.js";import{P as te}from"./modal-Pj_6bAFk.js";import{F as ne}from"./funnel-CMG4QvaK.js";import{s as oe}from"./sub-DOjETdwl.js";import{M as A}from"./MultiSelect-Dm9mO7pJ.js";function re(a){return!a||B(a)?null:encodeURIComponent(JSON.stringify(a))}const le=[{value:D.AbsAmount,label:"Abs Amount"},{value:D.Amount,label:"Amount"},{value:D.Date,label:"Date"}],ce=[{label:"All",value:k.All},{label:"Income",value:k.Income},{label:"Expense",value:k.Expense}];function ie({filter:a,setFilter:w,closeModal:d}){const{userContext:b}=i.useContext(U),o=_({defaultValues:{byOwners:b?.context.adminBusinessId?[b.context.adminBusinessId]:void 0,sortBy:{field:D.Date,asc:!1},toAnyDate:N(new Date,"yyyy-MM-dd"),fromAnyDate:N(oe(new Date,{years:1}),"yyyy-MM-dd"),...a}}),{control:l,handleSubmit:T,watch:C}=o,[y,F]=i.useState(a.sortBy?.asc??!1),[c,u]=i.useState(!!a.sortBy?.field),{selectableFinancialEntities:S,fetching:t}=q(),{selectableTags:v,fetching:I}=X(),E=C("sortBy.field");i.useEffect(()=>{E&&!c?u(!0):!E&&c&&u(!1)},[E,c]);const V=s=>{y!=null&&s.sortBy?.field&&(s.sortBy.asc=y),w(s),d()};function R(){w({}),F(!1),d()}return e.jsxs(e.Fragment,{children:[t?e.jsx("div",{children:"Loading..."}):e.jsx("div",{}),e.jsx(J,{...o,children:e.jsxs("form",{onSubmit:T(V),children:[e.jsxs(Q,{cols:2,children:[e.jsx(h,{name:"byOwners",control:l,defaultValue:a.byOwners,render:({field:s,fieldState:n})=>e.jsx(A,{...s,data:S,value:s.value??[],disabled:t,label:"Owners",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:n.error?.message,withinPortal:!0})}),e.jsx(h,{name:"byBusinesses",control:l,defaultValue:a.byBusinesses,render:({field:s,fieldState:n})=>e.jsx(A,{...s,data:S,value:s.value??[],disabled:t,label:"Financial Entities",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:n.error?.message,withinPortal:!0})}),e.jsx(h,{name:"byTags",control:l,defaultValue:a.byTags,render:({field:s,fieldState:n})=>e.jsx(A,{...s,data:v,itemComponent:Z,value:s.value??[],disabled:I,label:"Tags",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:n.error?.message,withinPortal:!0,filter:(r,f,M)=>M.label?.toLowerCase().includes(r.toLowerCase().trim())||M.description?.toLowerCase().includes(r.toLowerCase().trim())})}),e.jsx(h,{name:"fromAnyDate",control:l,defaultValue:a.fromAnyDate,rules:{pattern:{value:P,message:"Date must be im format yyyy-mm-dd"}},render:({field:s,fieldState:n})=>e.jsx(O,{...s,onChange:r=>{const f=r?typeof r=="string"?r:N(r,"yyyy-MM-dd"):void 0;f!==s.value&&s.onChange(f)},value:s.value?new Date(s.value):void 0,error:n.error?.message,label:"From Date",popoverProps:{withinPortal:!0}})}),e.jsx(h,{name:"toAnyDate",control:l,defaultValue:a.toAnyDate,rules:{pattern:{value:P,message:"Date must be im format yyyy-mm-dd"}},render:({field:s,fieldState:n})=>e.jsx(O,{...s,onChange:r=>{const f=r?typeof r=="string"?r:N(r,"yyyy-MM-dd"):void 0;f!==s.value&&s.onChange(f)},value:s.value?new Date(s.value):void 0,error:n.error?.message,label:"To Date",popoverProps:{withinPortal:!0}})}),e.jsx(h,{name:"chargesType",control:l,defaultValue:a.chargesType,render:({field:s,fieldState:n})=>e.jsx(L,{...s,data:ce,value:s.value??k.All,disabled:t,label:"Charge Type",placeholder:"Filter income/expense",maxDropdownHeight:160,error:n.error?.message,withinPortal:!0})}),e.jsx(h,{name:"sortBy.field",control:l,defaultValue:a.sortBy?.field??D.Date,render:({field:s,fieldState:n})=>e.jsx(L,{...s,data:le,label:"Field to sort by",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:n.error?.message,rightSectionProps:{style:{width:"5rem"}},withinPortal:!0,rightSection:e.jsxs("div",{className:"flex flex-row items-center gap-1",children:[e.jsx(m,{defaultChecked:a.sortBy?.asc??!1,checked:y??!1,disabled:!c,onCheckedChange:F}),e.jsx("span",{className:"text-xs",children:y?"ASC":"DESC"})]})})}),e.jsx(h,{name:"accountantStatus",control:l,defaultValue:a.accountantStatus,render:({field:s,fieldState:n})=>e.jsx(A,{...s,value:s.value??[],data:$,disabled:t,label:"Accountant Status",placeholder:"All",maxDropdownHeight:160,error:n.error?.message,withinPortal:!0})}),e.jsxs("div",{className:"flex flex-col gap-2 mt-4 rounded-lg border p-3 shadow-sm space-y-2",children:[e.jsx(K,{children:"Missing Information:"}),e.jsx(x,{control:o.control,name:"withoutInvoice",render:({field:s})=>e.jsxs(j,{className:"flex flex-row items-center justify-between",children:[e.jsx("div",{className:"space-y-0.5",children:e.jsx(p,{children:"Without Invoice"})}),e.jsx(g,{children:e.jsx(m,{defaultChecked:a.withoutInvoice??!1,onCheckedChange:s.onChange})})]})}),e.jsx(x,{control:o.control,name:"withoutReceipt",render:({field:s})=>e.jsxs(j,{className:"flex flex-row items-center justify-between",children:[e.jsx("div",{className:"space-y-0.5",children:e.jsx(p,{children:"Without Receipts"})}),e.jsx(g,{children:e.jsx(m,{defaultChecked:a.withoutReceipt??!1,onCheckedChange:s.onChange})})]})}),e.jsx(x,{control:o.control,name:"withoutDocuments",render:({field:s})=>e.jsxs(j,{className:"flex flex-row items-center justify-between",children:[e.jsx("div",{className:"space-y-0.5",children:e.jsx(p,{children:"Without Documents"})}),e.jsx(g,{children:e.jsx(m,{defaultChecked:a.withoutDocuments??!1,onCheckedChange:s.onChange})})]})}),e.jsx(x,{control:o.control,name:"withOpenDocuments",render:({field:s})=>e.jsxs(j,{className:"flex flex-row items-center justify-between",children:[e.jsx("div",{className:"space-y-0.5",children:e.jsx(p,{children:"With Open Documents"})}),e.jsx(g,{children:e.jsxs(Y,{children:[e.jsx(ee,{children:e.jsx(m,{defaultChecked:a.withOpenDocuments??!1,onCheckedChange:s.onChange})}),e.jsx(se,{children:e.jsx("p",{children:"Show only charges with documents that are currently open"})})]})})]})}),e.jsx(x,{control:o.control,name:"withoutTransactions",render:({field:s})=>e.jsxs(j,{className:"flex flex-row items-center justify-between",children:[e.jsx("div",{className:"space-y-0.5",children:e.jsx(p,{children:"Without Transactions"})}),e.jsx(g,{children:e.jsx(m,{defaultChecked:a.withoutTransactions??!1,onCheckedChange:s.onChange})})]})}),e.jsx(x,{control:o.control,name:"unbalanced",render:({field:s})=>e.jsxs(j,{className:"flex flex-row items-center justify-between",children:[e.jsx("div",{className:"space-y-0.5",children:e.jsx(p,{children:"Unbalanced businesses"})}),e.jsx(g,{children:e.jsx(m,{defaultChecked:a.unbalanced??!1,onCheckedChange:s.onChange})})]})}),e.jsx(x,{control:o.control,name:"withoutLedger",render:({field:s})=>e.jsxs(j,{className:"flex flex-row items-center justify-between",children:[e.jsx("div",{className:"space-y-0.5",children:e.jsx(p,{children:"Without ledger"})}),e.jsx(g,{children:e.jsx(m,{defaultChecked:a.withoutLedger??!1,onCheckedChange:s.onChange})})]})})]})]}),e.jsxs("div",{className:"flex justify-center mt-5 gap-3",children:[e.jsx("button",{type:"submit",disabled:t||I,className:"text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg",children:"Filter"}),e.jsx("button",{type:"button",className:"text-white bg-orange-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-orange-600 rounded-sm text-lg",onClick:R,children:"Clear"}),e.jsx("button",{type:"button",className:"text-white bg-rose-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-rose-600 rounded-sm text-lg",onClick:d,children:"Cancel"})]})]})})]})}function pe({filter:a={},setFilter:w,activePage:d,setPage:b,totalPages:o=1,initiallyOpened:l=!1}){const[T,C]=i.useState(l),[y,F]=i.useState(!B(a)),{get:c,set:u}=ae();i.useEffect(()=>{const t=d>1?d.toFixed(0):null,v=c("page");t!==v&&u("page",t)},[d,c,u]),i.useEffect(()=>{const t=re(a),v=c("chargesFilters");t!==v&&(u("chargesFilters",t),u("page"),b(1))},[a,c,u,b]);const S=i.useCallback(t=>{H(t,a)||(w(t),F(!B(t)))},[a,w]);return e.jsxs("div",{className:"flex flex-row gap-5 items-center",children:[e.jsx(te,{opened:T,onClose:()=>C(!1),content:e.jsx(ie,{filter:a,setFilter:S,closeModal:()=>C(!1)}),modalSize:"xl"}),o>1&&e.jsx(W,{className:"flex-fit w-fit mx-0",value:d,onChange:b,total:o}),e.jsx(z,{inline:!0,size:16,disabled:!y,children:e.jsx(G,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>C(!0),children:e.jsx(ne,{className:"size-5"})})})]})}export{pe as C,ce as c};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as t,F as D,u as E,j as e,T as N,B as w,L as T,d as b,e as z,f as W}from"./index-Cw_aKL-8.js";import{u as O}from"./use-url-query-C0mVgO2i.js";import{C as k}from"./charges-filters-DUuY-N0H.js";import{C as B,T as R}from"./charges-table-CWbe3t13.js";import{M as V}from"./index-CTatkdRy.js";import{E as A,I as Q,M as U}from"./match-document-modal-Bo9pBr8W.js";import{P as q}from"./page-layout-CVTeUSZp.js";import{P as J}from"./Progress-kr0gnfBa.js";import{P as $,a as G}from"./panel-top-open-DzBY_TuM.js";import"./modal-Pj_6bAFk.js";import"./funnel-CMG4QvaK.js";import"./sub-DOjETdwl.js";import"./addDays-DqZEDZy3.js";import"./subMonths-DqeFZ4O6.js";import"./MultiSelect-Dm9mO7pJ.js";import"./toggle-expansion-button-BrKkZtGj.js";import"./index-xxe8M91O.js";import"./similar-transactions-modal-B39q1NLa.js";import"./list-plus-B3EB-dKe.js";import"./tooltip-CbnJYNc4.js";import"./Table-DnHfGe-y.js";import"./summary-Bbsq64IN.js";import"./Checkbox-qEdmT4HE.js";import"./YearPickerInput-oa86GF4P.js";import"./insert-business-trip-modal-Ds3RIlmF.js";import"./accounter-table-BL_yrGIl.js";const Me=()=>{const{setFiltersContext:p}=t.useContext(D),[n,u]=t.useState(void 0),[l,x]=t.useState(void 0),[c,C]=t.useState(void 0),[g,f]=t.useState(!1),[r,d]=t.useState([]),{get:F}=O(),m=F("chargesFilters"),I=t.useMemo(()=>{if(m)try{return JSON.parse(decodeURIComponent(m))}catch{return}},[m]),[o,j]=t.useState(I),S=t.useCallback((s,y)=>{r.map(h=>h.id).includes(s)?d(r.filter(h=>h.id!==s)):d([...r,{id:s,onChange:y}])},[r]),[{data:a,fetching:M},v]=E({query:W,variables:{filters:o},pause:!0});function P(){d([])}const i=t.useMemo(()=>a?.chargesWithLedgerChanges?.length?a.chargesWithLedgerChanges[a.chargesWithLedgerChanges.length-1].progress:0,[a?.chargesWithLedgerChanges]),L=t.useCallback(s=>{j(s)},[j]);return t.useEffect(()=>{o&&v()},[o,v]),t.useEffect(()=>{p(e.jsxs("div",{className:"flex flex-row gap-x-5 items-center",children:[e.jsx(J,{value:i,label:`${i?.toFixed(2)}%`,size:"xl",animate:i<100,className:"min-w-52"}),e.jsx(k,{filter:o,setFilter:L,activePage:1,setPage:()=>{},initiallyOpened:!0}),e.jsx(N,{label:"Expand all accounts",children:e.jsx(w,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>f(s=>!s),children:g?e.jsx($,{className:"size-5"}):e.jsx(G,{className:"size-5"})})}),e.jsx(V,{selected:r,resetMerge:P})]}))},[a,M,o,g,p,f,r,i,L]),e.jsxs(q,{title:"Charges Ledger Validation",description:"Manage charges",children:[M?e.jsx(T,{className:"h-10 w-10 animate-spin mr-2 self-center"}):e.jsxs(e.Fragment,{children:[e.jsx(B,{setEditChargeId:u,setInsertDocument:x,setMatchDocuments:C,toggleMergeCharge:S,mergeSelectedCharges:new Set(r.map(s=>s.id)),data:a?.chargesWithLedgerChanges.filter(s=>!!s.charge).map(s=>s.charge)??[],isAllOpened:g}),e.jsxs("div",{className:"flex flex-row justify-center my-2",children:[i>0&&i<100&&e.jsx(b,{}),i===100&&!a?.chargesWithLedgerChanges.filter(s=>!!s.charge).length&&e.jsx(R,{radius:"xl",size:"xl",color:"green",children:e.jsx(z,{})})]})]}),n&&e.jsx(A,{chargeId:n?.id,close:()=>u(void 0),onChange:n.onChange}),l&&e.jsx(Q,{chargeId:l.id,onChange:l.onChange,close:()=>x(void 0)}),c&&e.jsx(U,{chargeId:c.id,ownerId:c.ownerId,setMatchDocuments:()=>C(void 0)})]})};export{Me as ChargesLedgerValidation};
|