@accounter/client 0.0.8-alpha-20251027170934-006cd73f08bdddc55a4caff263dcfa5e2b8b63ec → 0.0.8-alpha-20251028103841-7bfcc6a48108b285963cd18e3cc0548f0dd19dd8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/dist/assets/{Checkbox-BZ680-Kk.js → Checkbox-D8vMngET.js} +2 -2
- package/dist/assets/MultiSelect-DyHLxout.js +1 -0
- package/dist/assets/Pagination-J219P8nB.js +1 -0
- package/dist/assets/{Progress-DembKoIO.js → Progress-CtbG-tgE.js} +1 -1
- package/dist/assets/Table-DiM_oZiR.js +1 -0
- package/dist/assets/Typography-Cci39G2t.js +1 -0
- package/dist/assets/YearPickerInput-fBHzo-9n.js +1 -0
- package/dist/assets/accordion-CIgxze9K.js +1 -0
- package/dist/assets/accountant-approvals-Da-Rhpn-.js +1 -0
- package/dist/assets/accounter-table-CVAmEnx0.js +1 -0
- package/dist/assets/addDays-CkP1VB0c.js +1 -0
- package/dist/assets/all-charges-DBThy56x.js +1 -0
- package/dist/assets/{arrow-up-down-J9wnXx-h.js → arrow-up-down-DuRFov-X.js} +1 -1
- package/dist/assets/{building-2-1saARtmG.js → building-2-CSNfw8ff.js} +1 -1
- package/dist/assets/business-BwlprQsj.js +32 -0
- package/dist/assets/business-extended-info-CaNS8hMv.js +13 -0
- package/dist/assets/{business-header-SAnNK6FP.js → business-header-BwPwvICE.js} +1 -1
- package/dist/assets/business-transactions-filters-Dc2oWHEf.js +1 -0
- package/dist/assets/business-transactions-single-CPfIuNhV.js +1 -0
- package/dist/assets/business-trip-ChARfpOB.js +1 -0
- package/dist/assets/charge-DVi7MgMm.js +1 -0
- package/dist/assets/charges-filters-qR84DcIb.js +1 -0
- package/dist/assets/charges-ledger-validation-DtbFDZzl.js +1 -0
- package/dist/assets/charges-table-acSB8S00.js +62 -0
- package/dist/assets/{chart-Dq5fMHeT.js → chart-DtI3g0Q5.js} +6 -6
- package/dist/assets/create-event-handler-BiA-1lGu.js +1 -0
- package/dist/assets/{data-table-pagination-4YqSgXqX.js → data-table-pagination-Cv19AH6N.js} +1 -1
- package/dist/assets/download-csv-button-CBfb0Niq.js +1 -0
- package/dist/assets/editable-business-trip-BSVnyXpu.js +16 -0
- package/dist/assets/funnel-BjNIVF6D.js +6 -0
- package/dist/assets/{index-CBQNwu37.js → index-BBP2jL6K.js} +2 -2
- package/dist/assets/index-BcYldCey.js +1 -0
- package/dist/assets/index-C0gmUFjA.css +1 -0
- package/dist/assets/{index-AxUq37Ea.js → index-C1syq_qI.js} +2 -2
- package/dist/assets/index-C4ONlwvw.js +6 -0
- package/dist/assets/index-C5CNHfZr.js +1 -0
- package/dist/assets/index-CB2VcZw_.js +768 -0
- package/dist/assets/index-CHBmUMgX.js +1 -0
- package/dist/assets/index-CJmuVRwK.js +1 -0
- package/dist/assets/{index-sA_45leD.js → index-CRPI_Ng7.js} +3 -3
- package/dist/assets/index-CXbdg8VR.js +1 -0
- package/dist/assets/index-CaGyGe4W.js +9 -0
- package/dist/assets/index-CeKRCUfE.js +1 -0
- package/dist/assets/{index-BYoh_mMo.js → index-Cm34goSF.js} +3 -3
- package/dist/assets/index-CrszoO0T.js +1 -0
- package/dist/assets/index-Cwocz_5B.js +1 -0
- package/dist/assets/index-DFacP-84.js +1 -0
- package/dist/assets/index-DGwGMNjJ.js +2 -0
- package/dist/assets/index-DHPND3oV.js +1 -0
- package/dist/assets/index-DUpo5A07.js +1 -0
- package/dist/assets/index-DoiB6EIi.js +1 -0
- package/dist/assets/index-DrYwq6CI.js +1 -0
- package/dist/assets/index-QZZ5Nw4M.js +1 -0
- package/dist/assets/{index-B4-_AJ5N.js → index-bdZbvws5.js} +16 -16
- package/dist/assets/index-dYyPNFFk.js +2 -0
- package/dist/assets/index-zeuBKIVA.js +6 -0
- package/dist/assets/{index.es-Dwfw0glc.js → index.es-Ddqnt5kx.js} +1 -1
- package/dist/assets/insert-business-trip-modal-5QaUlEPB.js +6 -0
- package/dist/assets/issue-document-n_B8vFIC.js +1 -0
- package/dist/assets/list-plus-CdX74KkH.js +6 -0
- package/dist/assets/login-page-C7kjnYWZ.js +1 -0
- package/dist/assets/match-document-modal-BhJxxCwh.js +16 -0
- package/dist/assets/missing-info-charges-CogpD4pD.js +1 -0
- package/dist/assets/modal-CWL2uL48.js +1 -0
- package/dist/assets/page-layout-Di4aGcKz.js +1 -0
- package/dist/assets/page-not-found-BzIsL96K.js +1 -0
- package/dist/assets/panel-top-open-QFGcJlh7.js +11 -0
- package/dist/assets/{pencil-CYypGy_s.js → pencil-MpkgghkS.js} +1 -1
- package/dist/assets/report-commentary-row-DVBtcPLr.js +1 -0
- package/dist/assets/{save-BE7zhMeq.js → save-C550A2xp.js} +1 -1
- package/dist/assets/similar-transactions-modal-CuhHSiYp.js +1 -0
- package/dist/assets/sub-BJ17PU-y.js +1 -0
- package/dist/assets/subMonths-ClZ3ESsy.js +1 -0
- package/dist/assets/summary-Boa5uC3b.js +1 -0
- package/dist/assets/switch-DXxPikE7.js +1 -0
- package/dist/assets/toggle-expansion-button-DmgIHP4k.js +1 -0
- package/dist/assets/tooltip-B387WRNk.js +1 -0
- package/dist/assets/use-url-query-BPBYbbPQ.js +1 -0
- package/dist/index.html +2 -2
- package/package.json +1 -1
- package/src/components/business/contracts-section.tsx +0 -7
- package/src/components/business-transactions/business-extended-info.tsx +56 -53
- package/src/components/business-transactions/index.tsx +1 -28
- package/src/components/businesses/index.tsx +6 -2
- package/src/components/charges/cells/business-trip.tsx +6 -1
- package/src/components/charges/cells/counterparty.tsx +4 -28
- package/src/components/clients/contracts/modify-contract-dialog.tsx +3 -7
- package/src/components/common/business-trip-report/parts/core-expense-row.tsx +2 -2
- package/src/components/common/business-trip-report/parts/report-header.tsx +2 -1
- package/src/components/common/business-trip-report/parts/uncategorized-transactions.tsx +2 -2
- package/src/components/common/buttons/charge-navigate-button.tsx +12 -11
- package/src/components/common/modals/edit-charge-modal.tsx +2 -2
- package/src/components/common/modals/insert-document-modal.tsx +2 -2
- package/src/components/common/modals/match-document-modal.tsx +2 -2
- package/src/components/common/new-documents-list.tsx +2 -2
- package/src/components/documents-table/cells/creditor.tsx +2 -11
- package/src/components/documents-table/cells/debtor.tsx +2 -11
- package/src/components/ledger-table/counterparty-cell.tsx +4 -33
- package/src/components/reports/conto/index.tsx +1 -18
- package/src/components/reports/trial-balance-report/index.tsx +1 -17
- package/src/components/screens/businesses/business.tsx +0 -4
- package/src/components/screens/charges/all-charges.tsx +1 -17
- package/src/components/screens/charges/charge.tsx +0 -4
- package/src/components/screens/reports/balance-report/index.tsx +0 -14
- package/src/components/screens/reports/depreciation-report/index.tsx +0 -14
- package/src/components/transactions-table/cells/counterparty.tsx +2 -23
- package/src/components/transactions-table/cells-legacy/counterparty.tsx +3 -26
- package/src/gql/gql.ts +3 -3
- package/src/gql/graphql.ts +2 -5
- package/src/providers/urql.tsx +2 -2
- package/dist/assets/Typography-DPXB3hIS.js +0 -1
- package/dist/assets/accordion-UZwiz3fM.js +0 -1
- package/dist/assets/accountant-approvals-DDxSuMql.js +0 -1
- package/dist/assets/all-charges-BCP7OG1d.js +0 -1
- package/dist/assets/business-CBRlGy9p.js +0 -32
- package/dist/assets/business-transactions-single-DvPZFvmH.js +0 -1
- package/dist/assets/business-trip-g2hB76cn.js +0 -1
- package/dist/assets/charges-filters-T9c4RGLH.js +0 -1
- package/dist/assets/charges-ledger-validation-DaD8DCN4.js +0 -1
- package/dist/assets/editable-business-trip-B95j7iAh.js +0 -16
- package/dist/assets/index-5Fl36gjg.js +0 -1
- package/dist/assets/index-BDKAR_k1.js +0 -1
- package/dist/assets/index-BKXeyD9a.js +0 -1
- package/dist/assets/index-BPSZWRv9.js +0 -9
- package/dist/assets/index-BVetJA6_.js +0 -6
- package/dist/assets/index-BXp9NrWt.js +0 -1
- package/dist/assets/index-Br0-IMSG.js +0 -1
- package/dist/assets/index-Bw6OrQ7c.js +0 -1
- package/dist/assets/index-C3bFFbEz.js +0 -1
- package/dist/assets/index-CDIzaROV.js +0 -2
- package/dist/assets/index-CgQ4Qjvh.js +0 -886
- package/dist/assets/index-D4O5HA1y.js +0 -1
- package/dist/assets/index-DAbvR7_s.js +0 -1
- package/dist/assets/index-DkwmPZgt.js +0 -1
- package/dist/assets/index-DpsNoHLd.js +0 -2
- package/dist/assets/index-DtE5Y1ZB.css +0 -1
- package/dist/assets/index-k-cHMsFi.js +0 -1
- package/dist/assets/index-vkYxo-Uq.js +0 -1
- package/dist/assets/index-vstSRm8a.js +0 -1
- package/dist/assets/issue-document-umUFIxCu.js +0 -1
- package/dist/assets/login-page-Ck61EC35.js +0 -1
- package/dist/assets/missing-info-charges-aak-KkPt.js +0 -1
- package/dist/assets/page-not-found-Dzg-czJK.js +0 -1
- package/dist/assets/report-commentary-row-B479zk-x.js +0 -1
- package/dist/assets/sub-BxFupCKS.js +0 -1
- package/dist/assets/subMonths-DskeQPiN.js +0 -1
- package/src/components/charges/helpers.ts +0 -15
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import{D as xe,G as be,S as Te,H as Ne,a as we,J as Ms,r as y,j as e,K as Pe,N as Be,O as Us,n as Cs,Q as zs,i as pe,t as O,l as je,U as qs,V as Ie,W as Oe,X as De,Y as G,Z as W,_ as K,$ as H,a0 as Ae,a1 as X,a2 as j,a3 as g,a4 as f,a5 as N,v as k,a6 as I,a7 as C,a8 as Ye,B as E,a9 as Gs,aa as Le,ab as Ze,ac as V,ad as bs,ae as es,af as Ws,s as Ks,C as Hs,ag as Xs,ah as L,ai as ds,aj as Js,ak as Qs,al as Ys,am as de,an as ss,ao as q,ap as ns,aq as ts,ar as as,as as Z,at as me,au as ie,av as re,aw as le,ax as ce,ay as oe,az as is,aA as rs,aB as Ue,aC as ae,aD as ze,aE as qe,aF as Fe,aG as Zs,aH as ee,aI as Y,aJ as en,aK as sn,aL as nn,aM as Ge,aN as tn,aO as an,aP as rn,aQ as ln,aR as cn,aS as We,aT as Ke,aU as ws,aV as on,aW as He,aX as dn,aY as Is,aZ as Ds,a_ as mn,a$ as un,b0 as As,b1 as ls,b2 as hn,b3 as xn,b4 as ms,b5 as pn,b6 as jn,b7 as gn,b8 as fn,b9 as vn,ba as yn,bb as Nn,bc as D,bd as Cn,be as cs,bf as bn,bg as wn,bh as In,bi as Dn,bj as An,bk as Sn,bl as Q,bm as kn,bn as Tn,bo as z,bp as En,bq as Pn,br as Bn,bs as On}from"./index-CgQ4Qjvh.js";import{S as os}from"./save-BE7zhMeq.js";import{B as Ln}from"./business-header-SAnNK6FP.js";import{i as Vn,D as Fn,f as _n,E as $n,L as _e,a as Se,C as Rn,A as Mn,b as ve,c as Un,d as Xe,h as zn,e as qn,g as Ss,u as Gn,G as Wn,j as us,k as Kn,X as ks,Y as Ts,l as Hn,m as Xn,R as Jn,n as Qn,o as Yn,p as Zn}from"./chart-Dq5fMHeT.js";import{P as et}from"./pencil-CYypGy_s.js";import{A as st,a as $e,b as Re,c as hs}from"./accordion-UZwiz3fM.js";import{B as nt}from"./building-2-1saARtmG.js";import"./sequential-CAnleQny.js";/**
|
|
2
|
-
* @license lucide-react v0.546.0 - ISC
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the ISC license.
|
|
5
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/const tt=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]],xs=xe("circle-check",tt);/**
|
|
7
|
-
* @license lucide-react v0.546.0 - ISC
|
|
8
|
-
*
|
|
9
|
-
* This source code is licensed under the ISC license.
|
|
10
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
11
|
-
*/const at=[["line",{x1:"12",x2:"12",y1:"2",y2:"22",key:"7eqyqh"}],["path",{d:"M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6",key:"1b0p4s"}]],ke=xe("dollar-sign",at);/**
|
|
12
|
-
* @license lucide-react v0.546.0 - ISC
|
|
13
|
-
*
|
|
14
|
-
* This source code is licensed under the ISC license.
|
|
15
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
16
|
-
*/const it=[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"m9 15 2 2 4-4",key:"1grp1n"}]],rt=xe("file-check",it);/**
|
|
17
|
-
* @license lucide-react v0.546.0 - ISC
|
|
18
|
-
*
|
|
19
|
-
* This source code is licensed under the ISC license.
|
|
20
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
21
|
-
*/const lt=[["path",{d:"M12 22v-5",key:"1ega77"}],["path",{d:"M9 8V2",key:"14iosj"}],["path",{d:"M15 8V2",key:"18g5xt"}],["path",{d:"M18 8v5a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V8Z",key:"osxo6l"}]],ct=xe("plug",lt);/**
|
|
22
|
-
* @license lucide-react v0.546.0 - ISC
|
|
23
|
-
*
|
|
24
|
-
* This source code is licensed under the ISC license.
|
|
25
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
26
|
-
*/const ot=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}]],Es=xe("shield",ot);/**
|
|
27
|
-
* @license lucide-react v0.546.0 - ISC
|
|
28
|
-
*
|
|
29
|
-
* This source code is licensed under the ISC license.
|
|
30
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
31
|
-
*/const dt=[["path",{d:"M16 7h6v6",key:"box55l"}],["path",{d:"m22 7-8.5 8.5-5-5L2 17",key:"1t1m79"}]],Me=xe("trending-up",dt);function Ps(s){switch(s){case be.Annual:return"Annual";case be.Monthly:return"Monthly";default:throw new Error(`Unsupported Billing Cycle: ${s}`)}}function Bs(s){switch(s){case Te.Enterprise:return"Enterprise";case Te.Pro:return"Pro";default:throw new Error(`Unsupported Subscription plan: ${s}`)}}function mt(s){return Ne(s,"yyyy-MM-dd")}function ut({businessId:s,tagIds:n,description:t,open:a,onOpenChange:l,onClose:r}){const[{data:c,fetching:i},o]=we({pause:!0,query:Ms,variables:{businessId:s,tagsDifferentThan:n?n.map(u=>u.id):void 0,descriptionDifferentThan:t}});y.useEffect(()=>{a&&(n||t)&&!c&&o()},[a,n,t,o,c]);const d=y.useCallback(u=>{l(u),a&&!u&&r?.()},[l,r,a]),h=y.useMemo(()=>a&&(!!n||!!t)&&c&&c?.similarChargesByBusiness.length>0,[a,n,t,c]);return e.jsx(Pe,{open:h,onOpenChange:d,children:e.jsx(Be,{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(Cs,{}):n||t?e.jsx(zs,{data:c?.similarChargesByBusiness??[],tagIds:n,description:t,onOpenChange:d,title:"Similar Charges by Business"}):null})})})}const ht="updateAdminBusiness",xt=()=>{const[{fetching:s},n]=pe(qs),t=y.useCallback(async a=>{const l=`Error updating admin business ID [${a.adminBusinessId}]`,r=`${ht}-${a.adminBusinessId}`;O.loading("Updating admin business",{id:r});try{const c=await n(a),i=je(c,l,r,"updateAdminBusiness");if(i)return O.success("Success",{id:r,description:"Admin Business Updated"}),i.updateAdminBusiness}catch(c){console.error(`${l}: ${c}`),O.error("Error",{id:r,description:l,duration:1e5,closeButton:!0})}},[n]);return{fetching:s,updateAdminBusiness:t}},pt=Le({employerWithholdingTaxAccountNumber:V().min(1,{message:"Employer Withholding Tax Account Number is required"}),taxPrepaymentId:V().min(1,{message:"Tax Prepayment ID is required"}),nationalInsuranceEmployerId:V().min(1,{message:"National Insurance Employer ID is required"}),advanceTaxRate:bs().min(0,{message:"Advance Tax Rate must be at least 0"}).max(100,{message:"Advance Tax Rate must be at most 100"}),registrationDate:V().min(1,{message:"Registration Date is required"})});function ps(s){return!s||s.__typename!=="LtdFinancialEntity"||!s.adminInfo?{}:{employerWithholdingTaxAccountNumber:s.adminInfo.employerWithholdingTaxAccountNumber??"",taxPrepaymentId:s.adminInfo.taxPrepaymentId??"",nationalInsuranceEmployerId:s.adminInfo.nationalInsuranceEmployerId??"",advanceTaxRate:s.adminInfo.advanceTaxRate??0,registrationDate:s.adminInfo.registrationDate??""}}function jt(s){return{employerWithholdingTaxAccountNumber:s.employerWithholdingTaxAccountNumber,taxPrepaymentId:s.taxPrepaymentId,nationalInsuranceEmployerId:s.nationalInsuranceEmployerId,advanceTaxRate:s.advanceTaxRate,registrationDate:s.registrationDate?mt(new Date(s.registrationDate)):void 0}}function gt({data:s,refetchBusiness:n}){const t=De(Gs,s),[a,l]=y.useState(ps(t)),{updateAdminBusiness:r,fetching:c}=xt(),i=Ie({resolver:Oe(pt),defaultValues:a}),o=async d=>{if(!t)return;const h=Ze(d,i.formState.dirtyFields);if(!h)return;const u=jt(h);await r({adminBusinessId:t.id,fields:u}),n?.()};return y.useEffect(()=>{if(t){const d=ps(t);l(d),i.reset(d)}},[t,i]),e.jsxs(G,{children:[e.jsxs(W,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Es,{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(Ae,{...i,children:e.jsxs("form",{onSubmit:i.handleSubmit(o),className:"space-y-6",children:[e.jsx(X,{children:e.jsxs("div",{className:"grid gap-6 md:grid-cols-2",children:[e.jsx(j,{control:i.control,name:"employerWithholdingTaxAccountNumber",render:({field:d,fieldState:h})=>e.jsxs(g,{children:[e.jsx(f,{children:"Employer Withholding Tax Account Number"}),e.jsx(N,{children:e.jsx(k,{placeholder:"Enter account number",...d,className:I(h)})}),e.jsx(C,{})]})}),e.jsx(j,{control:i.control,name:"taxPrepaymentId",render:({field:d,fieldState:h})=>e.jsxs(g,{children:[e.jsx(f,{children:"Tax Prepayment ID"}),e.jsx(N,{children:e.jsx(k,{placeholder:"Enter prepayment ID",...d,className:I(h)})}),e.jsx(C,{})]})}),e.jsx(j,{control:i.control,name:"nationalInsuranceEmployerId",render:({field:d,fieldState:h})=>e.jsxs(g,{children:[e.jsx(f,{children:"National Insurance Employer ID"}),e.jsx(N,{children:e.jsx(k,{placeholder:"Enter employer ID",...d,className:I(h)})}),e.jsx(C,{})]})}),e.jsx(j,{control:i.control,name:"advanceTaxRate",render:({field:d,fieldState:h})=>e.jsxs(g,{children:[e.jsx(f,{children:"Advance Tax Rate (%)"}),e.jsx(N,{children:e.jsx(k,{type:"number",step:"0.01",min:"0",max:"100",placeholder:"Enter tax rate",...d,className:I(h)})}),e.jsx(C,{})]})}),e.jsx(j,{control:i.control,name:"registrationDate",render:({field:d,fieldState:h})=>e.jsxs(g,{children:[e.jsx(f,{children:"Registration Date"}),e.jsx(N,{children:e.jsx(k,{type:"date",...d,className:I(h)})}),e.jsx(C,{})]})})]})}),e.jsx(Ye,{className:"flex justify-end border-t mt-4 pt-6",children:e.jsxs(E,{type:"submit",disabled:c||Object.keys(i.formState.dirtyFields).length===0||!i.formState.isValid,children:[e.jsx(os,{className:"h-4 w-4"}),"Save Changes"]})})]})})]})}function ft({businessId:s}){const{userContext:n}=y.useContext(es),[t,a]=y.useState(1),[{data:l,fetching:r}]=we({query:Ws,variables:{filters:{byOwners:n?.context.adminBusinessId?[n.context.adminBusinessId]:void 0,sortBy:{field:Xs.Date,asc:!1},byBusinesses:[s]},page:t,limit:100}}),c=l?.allCharges?.pageInfo.totalPages??1,i=l?.allCharges?.nodes??[];return r?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"})]})}),c>1&&e.jsx(Ks,{className:"flex-fit",value:t,onChange:a,total:c})]}),e.jsx(X,{children:e.jsx("div",{className:"rounded-md border",children:e.jsx(Hs,{data:i,isAllOpened:!1})})})]})}var vt=["type","layout","connectNulls","ref"],yt=["key"];function ue(s){"@babel/helpers - typeof";return ue=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(n){return typeof n}:function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},ue(s)}function js(s,n){if(s==null)return{};var t=Nt(s,n),a,l;if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(s);for(l=0;l<r.length;l++)a=r[l],!(n.indexOf(a)>=0)&&Object.prototype.propertyIsEnumerable.call(s,a)&&(t[a]=s[a])}return t}function Nt(s,n){if(s==null)return{};var t={};for(var a in s)if(Object.prototype.hasOwnProperty.call(s,a)){if(n.indexOf(a)>=0)continue;t[a]=s[a]}return t}function Ce(){return Ce=Object.assign?Object.assign.bind():function(s){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var a in t)Object.prototype.hasOwnProperty.call(t,a)&&(s[a]=t[a])}return s},Ce.apply(this,arguments)}function gs(s,n){var t=Object.keys(s);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(s);n&&(a=a.filter(function(l){return Object.getOwnPropertyDescriptor(s,l).enumerable})),t.push.apply(t,a)}return t}function _(s){for(var n=1;n<arguments.length;n++){var t=arguments[n]!=null?arguments[n]:{};n%2?gs(Object(t),!0).forEach(function(a){M(s,a,t[a])}):Object.getOwnPropertyDescriptors?Object.defineProperties(s,Object.getOwnPropertyDescriptors(t)):gs(Object(t)).forEach(function(a){Object.defineProperty(s,a,Object.getOwnPropertyDescriptor(t,a))})}return s}function te(s){return It(s)||wt(s)||bt(s)||Ct()}function Ct(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
|
|
32
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function bt(s,n){if(s){if(typeof s=="string")return Je(s,n);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 Je(s,n)}}function wt(s){if(typeof Symbol<"u"&&s[Symbol.iterator]!=null||s["@@iterator"]!=null)return Array.from(s)}function It(s){if(Array.isArray(s))return Je(s)}function Je(s,n){(n==null||n>s.length)&&(n=s.length);for(var t=0,a=new Array(n);t<n;t++)a[t]=s[t];return a}function Dt(s,n){if(!(s instanceof n))throw new TypeError("Cannot call a class as a function")}function fs(s,n){for(var t=0;t<n.length;t++){var a=n[t];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(s,Ls(a.key),a)}}function At(s,n,t){return n&&fs(s.prototype,n),t&&fs(s,t),Object.defineProperty(s,"prototype",{writable:!1}),s}function St(s,n,t){return n=Ee(n),kt(s,Os()?Reflect.construct(n,t||[],Ee(s).constructor):n.apply(s,t))}function kt(s,n){if(n&&(ue(n)==="object"||typeof n=="function"))return n;if(n!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return Tt(s)}function Tt(s){if(s===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return s}function Os(){try{var s=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch{}return(Os=function(){return!!s})()}function Ee(s){return Ee=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},Ee(s)}function Et(s,n){if(typeof n!="function"&&n!==null)throw new TypeError("Super expression must either be null or a function");s.prototype=Object.create(n&&n.prototype,{constructor:{value:s,writable:!0,configurable:!0}}),Object.defineProperty(s,"prototype",{writable:!1}),n&&Qe(s,n)}function Qe(s,n){return Qe=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(a,l){return a.__proto__=l,a},Qe(s,n)}function M(s,n,t){return n=Ls(n),n in s?Object.defineProperty(s,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):s[n]=t,s}function Ls(s){var n=Pt(s,"string");return ue(n)=="symbol"?n:n+""}function Pt(s,n){if(ue(s)!="object"||!s)return s;var t=s[Symbol.toPrimitive];if(t!==void 0){var a=t.call(s,n);if(ue(a)!="object")return a;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(s)}var he=(function(s){function n(){var t;Dt(this,n);for(var a=arguments.length,l=new Array(a),r=0;r<a;r++)l[r]=arguments[r];return t=St(this,n,[].concat(l)),M(t,"state",{isAnimationFinished:!0,totalLength:0}),M(t,"generateSimpleStrokeDasharray",function(c,i){return"".concat(i,"px ").concat(c-i,"px")}),M(t,"getStrokeDasharray",function(c,i,o){var d=o.reduce(function(b,T){return b+T});if(!d)return t.generateSimpleStrokeDasharray(i,c);for(var h=Math.floor(c/d),u=c%d,x=i-c,A=[],m=0,p=0;m<o.length;p+=o[m],++m)if(p+o[m]>u){A=[].concat(te(o.slice(0,m)),[u-p]);break}var S=A.length%2===0?[0,x]:[x];return[].concat(te(n.repeat(o,h)),te(A),S).map(function(b){return"".concat(b,"px")}).join(", ")}),M(t,"id",Gn("recharts-line-")),M(t,"pathRef",function(c){t.mainCurve=c}),M(t,"handleAnimationEnd",function(){t.setState({isAnimationFinished:!0}),t.props.onAnimationEnd&&t.props.onAnimationEnd()}),M(t,"handleAnimationStart",function(){t.setState({isAnimationFinished:!1}),t.props.onAnimationStart&&t.props.onAnimationStart()}),t}return Et(n,s),At(n,[{key:"componentDidMount",value:function(){if(this.props.isAnimationActive){var a=this.getTotalLength();this.setState({totalLength:a})}}},{key:"componentDidUpdate",value:function(){if(this.props.isAnimationActive){var a=this.getTotalLength();a!==this.state.totalLength&&this.setState({totalLength:a})}}},{key:"getTotalLength",value:function(){var a=this.mainCurve;try{return a&&a.getTotalLength&&a.getTotalLength()||0}catch{return 0}}},{key:"renderErrorBar",value:function(a,l){if(this.props.isAnimationActive&&!this.state.isAnimationFinished)return null;var r=this.props,c=r.points,i=r.xAxis,o=r.yAxis,d=r.layout,h=r.children,u=_n(h,$n);if(!u)return null;var x=function(p,S){return{x:p.x,y:p.y,value:p.value,errorVal:Ss(p.payload,S)}},A={clipPath:a?"url(#clipPath-".concat(l,")"):null};return L.createElement(_e,A,u.map(function(m){return L.cloneElement(m,{key:"bar-".concat(m.props.dataKey),data:c,xAxis:i,yAxis:o,layout:d,dataPointFormatter:x})}))}},{key:"renderDots",value:function(a,l,r){var c=this.props.isAnimationActive;if(c&&!this.state.isAnimationFinished)return null;var i=this.props,o=i.dot,d=i.points,h=i.dataKey,u=Se(this.props,!1),x=Se(o,!0),A=d.map(function(p,S){var b=_(_(_({key:"dot-".concat(S),r:3},u),x),{},{index:S,cx:p.x,cy:p.y,value:p.value,dataKey:h,payload:p.payload,points:d});return n.renderDotItem(o,b)}),m={clipPath:a?"url(#clipPath-".concat(l?"":"dots-").concat(r,")"):null};return L.createElement(_e,Ce({className:"recharts-line-dots",key:"dots"},m),A)}},{key:"renderCurveStatically",value:function(a,l,r,c){var i=this.props,o=i.type,d=i.layout,h=i.connectNulls;i.ref;var u=js(i,vt),x=_(_(_({},Se(u,!0)),{},{fill:"none",className:"recharts-line-curve",clipPath:l?"url(#clipPath-".concat(r,")"):null,points:a},c),{},{type:o,layout:d,connectNulls:h});return L.createElement(Rn,Ce({},x,{pathRef:this.pathRef}))}},{key:"renderCurveWithAnimation",value:function(a,l){var r=this,c=this.props,i=c.points,o=c.strokeDasharray,d=c.isAnimationActive,h=c.animationBegin,u=c.animationDuration,x=c.animationEasing,A=c.animationId,m=c.animateNewValues,p=c.width,S=c.height,b=this.state,T=b.prevPoints,F=b.totalLength;return L.createElement(Mn,{begin:h,duration:u,isActive:d,easing:x,from:{t:0},to:{t:1},key:"line-".concat(A),onAnimationEnd:this.handleAnimationEnd,onAnimationStart:this.handleAnimationStart},function(R){var $=R.t;if(T){var J=T.length/i.length,U=i.map(function(B,Ve){var ge=Math.floor(Ve*J);if(T[ge]){var fe=T[ge],ne=ve(fe.x,B.x),_s=ve(fe.y,B.y);return _(_({},B),{},{x:ne($),y:_s($)})}if(m){var $s=ve(p*2,B.x),Rs=ve(S/2,B.y);return _(_({},B),{},{x:$s($),y:Rs($)})}return _(_({},B),{},{x:B.x,y:B.y})});return r.renderCurveStatically(U,a,l)}var se=ve(0,F),v=se($),w;if(o){var P="".concat(o).split(/[,\s]+/gim).map(function(B){return parseFloat(B)});w=r.getStrokeDasharray(v,F,P)}else w=r.generateSimpleStrokeDasharray(F,v);return r.renderCurveStatically(i,a,l,{strokeDasharray:w})})}},{key:"renderCurve",value:function(a,l){var r=this.props,c=r.points,i=r.isAnimationActive,o=this.state,d=o.prevPoints,h=o.totalLength;return i&&c&&c.length&&(!d&&h>0||!Un(d,c))?this.renderCurveWithAnimation(a,l):this.renderCurveStatically(c,a,l)}},{key:"render",value:function(){var a,l=this.props,r=l.hide,c=l.dot,i=l.points,o=l.className,d=l.xAxis,h=l.yAxis,u=l.top,x=l.left,A=l.width,m=l.height,p=l.isAnimationActive,S=l.id;if(r||!i||!i.length)return null;var b=this.state.isAnimationFinished,T=i.length===1,F=ds("recharts-line",o),R=d&&d.allowDataOverflow,$=h&&h.allowDataOverflow,J=R||$,U=Xe(S)?this.id:S,se=(a=Se(c,!1))!==null&&a!==void 0?a:{r:3,strokeWidth:2},v=se.r,w=v===void 0?3:v,P=se.strokeWidth,B=P===void 0?2:P,Ve=zn(c)?c:{},ge=Ve.clipDot,fe=ge===void 0?!0:ge,ne=w*2+B;return L.createElement(_e,{className:F},R||$?L.createElement("defs",null,L.createElement("clipPath",{id:"clipPath-".concat(U)},L.createElement("rect",{x:R?x:x-A/2,y:$?u:u-m/2,width:R?A:A*2,height:$?m:m*2})),!fe&&L.createElement("clipPath",{id:"clipPath-dots-".concat(U)},L.createElement("rect",{x:x-ne/2,y:u-ne/2,width:A+ne,height:m+ne}))):null,!T&&this.renderCurve(J,U),this.renderErrorBar(J,U),(T||c)&&this.renderDots(J,fe,U),(!p||b)&&qn.renderCallByParent(this.props,i))}}],[{key:"getDerivedStateFromProps",value:function(a,l){return a.animationId!==l.prevAnimationId?{prevAnimationId:a.animationId,curPoints:a.points,prevPoints:l.curPoints}:a.points!==l.curPoints?{curPoints:a.points}:null}},{key:"repeat",value:function(a,l){for(var r=a.length%2!==0?[].concat(te(a),[0]):a,c=[],i=0;i<l;++i)c=[].concat(te(c),te(r));return c}},{key:"renderDotItem",value:function(a,l){var r;if(L.isValidElement(a))r=L.cloneElement(a,l);else if(Vn(a))r=a(l);else{var c=l.key,i=js(l,yt),o=ds("recharts-line-dot",typeof a!="boolean"?a.className:"");r=L.createElement(Fn,Ce({key:c},i,{className:o}))}return r}}])})(y.PureComponent);M(he,"displayName","Line");M(he,"defaultProps",{xAxisId:0,yAxisId:0,connectNulls:!1,activeDot:!0,dot:!0,legendType:"line",stroke:"#3182bd",strokeWidth:1,fill:"#fff",points:[],isAnimationActive:!Wn.isSsr,animateNewValues:!0,animationBegin:0,animationDuration:1500,animationEasing:"ease",hide:!1,label:!1});M(he,"getComposedData",function(s){var n=s.props,t=s.xAxis,a=s.yAxis,l=s.xAxisTicks,r=s.yAxisTicks,c=s.dataKey,i=s.bandSize,o=s.displayedData,d=s.offset,h=n.layout,u=o.map(function(x,A){var m=Ss(x,c);return h==="horizontal"?{x:us({axis:t,ticks:l,bandSize:i,entry:x,index:A}),y:Xe(m)?null:a.scale(m),value:m,payload:x}:{x:Xe(m)?null:t.scale(m),y:us({axis:a,ticks:r,bandSize:i,entry:x,index:A}),value:m,payload:x}});return _({points:u,layout:h},d)});var Bt=Kn({chartName:"LineChart",GraphicalChild:he,axisComponents:[{axisType:"xAxis",AxisComp:ks},{axisType:"yAxis",AxisComp:Ts}],formatAxisMap:Hn});const ye=[{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 Ot(){const s=ye.reduce((t,a)=>t+a.revenue,0),n=s/ye.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(X,{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:["$",n.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:["$",ye[ye.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(Xn,{config:{revenue:{label:"Revenue",color:"hsl(var(--chart-1))"},expenses:{label:"Expenses",color:"hsl(var(--chart-2))"}},className:"h-[400px]",children:e.jsx(Jn,{width:"100%",height:"100%",children:e.jsxs(Bt,{data:ye,margin:{top:5,right:10,left:10,bottom:5},children:[e.jsx(Qn,{strokeDasharray:"3 3",className:"stroke-muted"}),e.jsx(ks,{dataKey:"month",className:"text-xs",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(Ts,{className:"text-xs",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(Yn,{content:e.jsx(Zn,{})}),e.jsx(he,{type:"monotone",dataKey:"revenue",stroke:"var(--color-revenue)",strokeWidth:2,dot:{fill:"var(--color-revenue)",r:4}}),e.jsx(he,{type:"monotone",dataKey:"expenses",stroke:"var(--color-expenses)",strokeWidth:2,dot:{fill:"var(--color-expenses)",r:4}})]})})})]})]})}const Lt="updateBusiness",Vs=()=>{const[{fetching:s},n]=pe(Js),t=y.useCallback(async a=>{const l=`Error updating business ID [${a.businessId}]`,r=`${Lt}-${a.businessId}`;O.loading("Updating business",{id:r});try{const c=await n(a),i=je(c,l,r,"updateBusiness");if(i)return O.success("Success",{id:r,description:"Business updated"}),i.updateBusiness}catch(c){console.error(`${l}: ${c}`),O.error("Error",{id:r,description:l,duration:1e5,closeButton:!0})}},[n]);return{fetching:s,updateBusiness:t}},Vt="insertClient",Ft=()=>{const[{fetching:s},n]=pe(Qs),t=y.useCallback(async a=>{const l=`Error creating client [${a.fields.businessId}]`,r=`${Vt}-${a.fields.businessId}`;O.loading("Creating Client...",{id:r});try{const c=await n(a),i=je(c,l,r,"insertClient");if(i)return O.success("Success",{id:r,description:`Client [${a.fields.businessId}] was created`}),i.insertClient}catch(c){console.error(`${l}: ${c}`),O.error("Error",{id:r,description:l,duration:1e5,closeButton:!0})}},[n]);return{fetching:s,insertClient:t}},_t="updateClient",Fs=()=>{const[{fetching:s},n]=pe(Ys),t=y.useCallback(async a=>{const l=`Error updating client ID [${a.businessId}]`,r=`${_t}-${a.businessId}`;O.loading("Updating client",{id:r});try{const c=await n(a),i=je(c,l,r,"updateClient");if(i)return O.success("Success",{id:r,description:"Client updated"}),i.updateClient}catch(c){console.error(`${l}: ${c}`),O.error("Error",{id:r,description:l,duration:1e5,closeButton:!0})}},[n]);return{fetching:s,updateClient:t}},$t=Le({businessId:Ue().optional(),emails:ze(qe()).optional(),generatedDocumentType:ae(Object.values(de)),greenInvoiceId:Ue().optional(),hiveId:V().optional()});function Rt({client:s,businessId:n,onDone:t}){const[a,l]=y.useState(!1),[r,c]=y.useState(null),{updateClient:i}=Fs(),{insertClient:o}=Ft(),[d,h]=y.useState(""),u={businessId:n,generatedDocumentType:de.Proforma,emails:[]},x=Ie({resolver:Oe($t),defaultValues:s||u});y.useEffect(()=>{s&&(c(s),x.reset({emails:s.emails,greenInvoiceId:s.greenInvoiceId,hiveId:s.hiveId,generatedDocumentType:s.generatedDocumentType,businessId:s.businessId}),l(!0))},[s,x]);const A=()=>{c(null),x.reset(u),l(!0)},m=()=>{if(d.trim()){const b=x.getValues("emails");x.setValue("emails",[...b??[],d.trim()],{shouldDirty:!0}),h("")}},p=b=>{const T=x.getValues("emails");x.setValue("emails",(T??[]).filter((F,R)=>R!==b),{shouldDirty:!0})},S=y.useCallback(async b=>{if(r)i({businessId:n,fields:b});else{if(!b.greenInvoiceId){x.setError("greenInvoiceId",{message:"Green Invoice ID is required"});return}o({fields:{...b,greenInvoiceId:b.greenInvoiceId,businessId:n}})}l(!1),c(null),t?.()},[r,t,i,n,o,x]);return e.jsxs(Pe,{open:a,onOpenChange:l,children:[e.jsx(ss,{asChild:!0,children:e.jsxs(E,{size:"sm",onClick:A,children:[e.jsx(q,{className:"h-4 w-4 mr-2"}),"New Client"]})}),e.jsxs(Be,{className:"max-w-2xl max-h-[90vh] overflow-y-auto",children:[e.jsxs(ns,{children:[e.jsx(ts,{children:r?"Edit Client":"Create New Client"}),e.jsx(as,{children:r?"Update client details":"Add a new client with all required details"})]}),e.jsx(Ae,{...x,children:e.jsxs("form",{onSubmit:x.handleSubmit(S),children:[e.jsx("div",{className:"grid gap-4 py-4",children:e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsx(j,{control:x.control,name:"emails",render:({field:b})=>e.jsxs(g,{children:[e.jsx(f,{children:"Emails"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(k,{placeholder:"Add email...",value:d,onChange:T=>h(T.target.value),onKeyDown:T=>{T.key==="Enter"&&(T.preventDefault(),m())}}),e.jsx(E,{type:"button",size:"sm",onClick:m,children:e.jsx(q,{className:"h-4 w-4"})})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:b.value?.map((T,F)=>e.jsxs(Z,{variant:"secondary",className:"gap-1",children:[T,e.jsx(E,{variant:"ghost",size:"icon",className:"p-0 size-3",onClick:()=>p(F),children:e.jsx(me,{className:"size-3 cursor-pointer"})})]},F))}),e.jsx(C,{})]})}),e.jsx(j,{control:x.control,name:"generatedDocumentType",render:({field:b})=>e.jsxs(g,{children:[e.jsx(f,{children:"Default Document Type"}),e.jsxs(ie,{onValueChange:b.onChange,defaultValue:b.value,children:[e.jsx(N,{children:e.jsx(re,{children:e.jsx(le,{})})}),e.jsx(ce,{children:Object.values(de).map(T=>e.jsx(oe,{value:T,children:is(T)},T))})]}),e.jsx(C,{})]})}),e.jsx(j,{control:x.control,name:"greenInvoiceId",render:({field:b})=>e.jsxs(g,{children:[e.jsx(f,{children:"Green Invoice ID"}),e.jsx(N,{children:e.jsx(k,{type:"text",placeholder:"Enter Green Invoice ID",...b,required:!r})}),e.jsx(C,{})]})}),e.jsx(j,{control:x.control,name:"hiveId",render:({field:b})=>e.jsxs(g,{children:[e.jsx(f,{children:"Hive ID"}),e.jsx(N,{children:e.jsx(k,{type:"text",placeholder:"Enter Hive ID",...b,required:!r})}),e.jsx(C,{})]})})]})}),e.jsxs(rs,{children:[e.jsx(E,{type:"button",variant:"outline",onClick:()=>l(!1),children:"Cancel"}),e.jsx(E,{type:"submit",children:r?"Update Client":"Create Client"})]})]})})]})]})}const Mt=Object.values(ln);function vs(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(n=>n.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 Ut(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(r=>({id:r})),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 zt({data:s,refetchBusiness:n}){const t=De(Zs,s),[a,l]=y.useState(vs(t)),{userContext:r}=y.useContext(es),{updateBusiness:c,fetching:i}=Vs(),[o,d]=y.useState(!1),[h,u]=y.useState(void 0),x=Ie({defaultValues:a}),A=async p=>{if(!t||!r?.context.adminBusinessId)return;const S=Ze(p,x.formState.dirtyFields);if(!S)return;const b=Ut(S);await c({businessId:t.id,ownerId:r.context.adminBusinessId,fields:b}),S.tags?.length||S.description?(u({tagIds:S.tags?.map(T=>({id:T})),description:S.description}),d(!0)):n?.()};if(y.useEffect(()=>{if(t){const p=vs(t);l(p),x.reset(p)}},[t,x]),!t)return e.jsx("div",{});const m=x.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"})]}),!m&&e.jsx(Rt,{businessId:t.id,onDone:n})]})}),e.jsx(Ae,{...x,children:e.jsxs("form",{onSubmit:x.handleSubmit(A),children:[e.jsxs(X,{className:"space-y-6",children:[e.jsx(qt,{form:x}),e.jsx(Fe,{}),e.jsx(Gt,{form:x}),e.jsx(Fe,{}),e.jsx(Wt,{form:x}),e.jsx(Fe,{}),e.jsx(Kt,{form:x})]}),e.jsx(Ye,{className:"flex justify-end border-t pt-6",children:e.jsxs(E,{type:"submit",disabled:i||Object.keys(x.formState.dirtyFields).length===0,children:[e.jsx(os,{className:"h-4 w-4 mr-2"}),"Save Changes"]})})]})}),e.jsx(ut,{businessId:t.id,tagIds:h?.tagIds,description:h?.description,open:o,onOpenChange:d,onClose:n})]})}function qt({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(j,{control:s.control,name:"isClient",render:({field:n,fieldState:t})=>e.jsxs(g,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(f,{children:"Is Client"}),e.jsx(ee,{children:"Mark this business as a client"})]}),e.jsx(N,{children:e.jsx(Y,{disabled:!0,checked:n.value,onCheckedChange:n.onChange,className:I(t)})})]})}),e.jsx(j,{control:s.control,name:"isActive",render:({field:n,fieldState:t})=>e.jsxs(g,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(f,{children:"Is Active"}),e.jsx(ee,{children:"Business is currently active"})]}),e.jsx(N,{children:e.jsx(Y,{checked:n.value,onCheckedChange:n.onChange,className:I(t)})})]})}),e.jsx(j,{control:s.control,name:"isReceiptEnough",render:({field:n,fieldState:t})=>e.jsxs(g,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(f,{children:"Is Receipt Enough"}),e.jsx(ee,{children:"Generate ledger for receipt documents if no invoice available"})]}),e.jsx(N,{children:e.jsx(Y,{checked:n.value,onCheckedChange:n.onChange,className:I(t)})})]})}),e.jsx(j,{control:s.control,name:"isDocumentsOptional",render:({field:n,fieldState:t})=>e.jsxs(g,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(f,{children:"No Docs Required"}),e.jsx(ee,{children:"Skip document validation for common charges"})]}),e.jsx(N,{children:e.jsx(Y,{checked:n.value,onCheckedChange:n.onChange,className:I(t)})})]})}),e.jsx(j,{control:s.control,name:"isVatOptional",render:({field:n,fieldState:t})=>e.jsxs(g,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(f,{children:"Is VAT Optional"}),e.jsx(ee,{children:"Mute missing VAT indicator"})]}),e.jsx(N,{children:e.jsx(Y,{checked:n.value,onCheckedChange:n.onChange,className:I(t)})})]})}),e.jsx(j,{control:s.control,name:"isExemptDealer",render:({field:n,fieldState:t})=>e.jsxs(g,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(f,{children:"Is Exempt Dealer"}),e.jsx(ee,{children:"Business is exempt from VAT requirements"})]}),e.jsx(N,{children:e.jsx(Y,{checked:n.value,onCheckedChange:n.onChange,className:I(t)})})]})})]})]})}function Gt({form:s}){const{selectableTaxCategories:n,fetching:t}=en(),{selectableSortCodes:a,fetching:l,sortCodes:r}=sn(),{selectableTags:c,fetching:i}=nn(),o=y.useCallback(d=>{if(d){const h=r.find(u=>Number(u.key)===Number(d));h&&(h.defaultIrsCode?s.setValue("irsCode",h.defaultIrsCode,{shouldDirty:!0}):s.setValue("irsCode",null,{shouldDirty:!0}))}},[s,r]);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(j,{control:s.control,name:"sortCode",render:({field:d,fieldState:h})=>e.jsxs(g,{children:[e.jsx(f,{children:"Sort Code"}),e.jsx(N,{children:e.jsx(Ge,{onChange:u=>{o(u),d.onChange(u)},data:a,value:d.value,disabled:l,placeholder:"Scroll to see all options",formPart:!0,triggerProps:{className:I(h)}})}),e.jsx(C,{})]})}),e.jsx(j,{control:s.control,name:"taxCategory",render:({field:d,fieldState:h})=>e.jsxs(g,{children:[e.jsx(f,{children:"Tax Category"}),e.jsx(N,{children:e.jsx(Ge,{data:n,disabled:t,value:d.value,onChange:d.onChange,placeholder:"Scroll to see all options",formPart:!0,triggerProps:{className:I(h)}})}),e.jsx(C,{})]})}),e.jsx(j,{control:s.control,name:"pcn874RecordType",render:({field:d,fieldState:h})=>e.jsxs(g,{children:[e.jsx(f,{children:"PCN874 Record Type"}),e.jsxs(ie,{onValueChange:d.onChange,value:d.value,children:[e.jsx(N,{children:e.jsx(re,{className:I(h),children:e.jsx(le,{})})}),e.jsx(ce,{children:Object.entries(tn).map(([u,x])=>e.jsx(oe,{value:u,children:`${x} (${u})`},u))})]}),e.jsx(C,{})]})}),e.jsx(j,{control:s.control,name:"irsCode",render:({field:d,fieldState:h})=>e.jsxs(g,{children:[e.jsx(f,{children:"IRS Code"}),e.jsx(N,{children:e.jsx(an,{value:d.value??void 0,onValueChange:u=>d.onChange(u??null),hideControls:!0,decimalScale:0,className:I(h)})}),e.jsx(C,{})]})}),e.jsx(j,{control:s.control,name:"description",render:({field:d,fieldState:h})=>e.jsxs(g,{children:[e.jsx(f,{children:"Charge Description"}),e.jsx(N,{children:e.jsx(k,{placeholder:"Enter default charge description",...d,className:I(h)})}),e.jsx(C,{})]})}),e.jsx(j,{control:s.control,name:"tags",render:({field:d,fieldState:h})=>e.jsxs(g,{children:[e.jsx(f,{children:"Tags"}),e.jsx(N,{children:e.jsx(rn,{options:Object.values(c).map(({value:u,label:x})=>({label:x,value:u})),onValueChange:d.onChange,defaultValue:d.value,value:d.value,placeholder:"Select Default Tags",variant:"default",disabled:i,className:I(h)})}),e.jsx(C,{})]})})]})]})}function Wt({form:s}){const[n,t]=y.useState(""),[a,l]=y.useState(""),r=()=>{if(n.trim()){const d=s.getValues("phrases");s.setValue("phrases",[...d,n.trim()],{shouldDirty:!0}),t("")}},c=()=>{if(a.trim()){const d=s.getValues("emails");s.setValue("emails",[...d,a.trim()],{shouldDirty:!0}),l("")}},i=d=>{const h=s.getValues("phrases");s.setValue("phrases",h.filter((u,x)=>x!==d),{shouldDirty:!0})},o=d=>{const h=s.getValues("emails");s.setValue("emails",h.filter((u,x)=>x!==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(j,{control:s.control,name:"phrases",render:({field:d,fieldState:h})=>e.jsxs(g,{children:[e.jsx(f,{children:"Phrases"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(k,{placeholder:"Add phrase...",value:n,onChange:u=>t(u.target.value),onKeyDown:u=>{u.key==="Enter"&&(u.preventDefault(),r())},className:I(h)}),e.jsx(E,{type:"button",size:"sm",onClick:r,children:e.jsx(q,{className:"h-4 w-4"})})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:d.value?.map((u,x)=>e.jsxs(Z,{variant:"secondary",className:"gap-1",children:[u,e.jsx(E,{variant:"ghost",size:"icon",className:"p-0 size-3",onClick:()=>i(x),children:e.jsx(me,{className:"size-3 cursor-pointer",onClick:()=>i(x)})})]},x))}),e.jsx(C,{})]})}),e.jsx(j,{control:s.control,name:"emails",render:({field:d,fieldState:h})=>e.jsxs(g,{children:[e.jsx(f,{children:"Email Addresses"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(k,{type:"email",placeholder:"Add email...",value:a,onChange:u=>l(u.target.value),onKeyDown:u=>{u.key==="Enter"&&(u.preventDefault(),c())},className:I(h)}),e.jsx(E,{type:"button",size:"sm",onClick:c,children:e.jsx(q,{className:"h-4 w-4"})})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:d.value?.map((u,x)=>e.jsxs(Z,{variant:"secondary",className:"gap-1",children:[u,e.jsx(E,{variant:"ghost",size:"icon",className:"p-0 size-3",onClick:()=>o(x),children:e.jsx(me,{className:"size-3 cursor-pointer"})})]},x))}),e.jsx(C,{})]})})]})}function Kt({form:s}){const[n,t]=y.useState(""),a=()=>{if(n.trim()){const c=s.getValues("internalLinks");s.setValue("internalLinks",[...c,n.trim()],{shouldDirty:!0}),t("")}},l=c=>{const i=s.getValues("attachmentTypes");s.setValue("attachmentTypes",i?.includes(c)?i.filter(o=>o!==c):[...i,c],{shouldDirty:!0})},r=c=>{const i=s.getValues("internalLinks");s.setValue("internalLinks",i.filter((o,d)=>d!==c),{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(j,{control:s.control,name:"attachmentTypes",render:({field:c,fieldState:i})=>e.jsxs(g,{children:[e.jsx(f,{children:"Attachment Types"}),e.jsx("div",{className:I(i)+" rounded-md flex flex-wrap gap-2",children:Mt.map(o=>e.jsx(Z,{variant:c.value?.includes(o)?"default":"outline",className:"cursor-pointer",onClick:()=>l(o),children:o},o))}),e.jsx(C,{})]})}),e.jsx(j,{control:s.control,name:"internalLinks",render:({field:c,fieldState:i})=>e.jsxs(g,{children:[e.jsx(f,{children:"Internal Links"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(k,{type:"url",placeholder:"Add internal link...",value:n,onChange:o=>t(o.target.value),onKeyDown:o=>{o.key==="Enter"&&(o.preventDefault(),a())}}),e.jsx(E,{type:"button",size:"sm",onClick:a,children:e.jsx(q,{className:"h-4 w-4"})})]}),e.jsx("div",{className:I(i)+" flex flex-wrap gap-2 rounded-md",children:c.value?.map((o,d)=>e.jsxs(Z,{variant:"secondary",className:"gap-1 max-w-xs truncate",children:[o,e.jsx(E,{variant:"ghost",size:"icon",className:"p-0 size-3",onClick:()=>r(d),children:e.jsx(me,{className:"size-3 cursor-pointer flex-shrink-0"})})]},d))}),e.jsx(C,{})]})}),e.jsx(j,{control:s.control,name:"useMessageBody",render:({field:c,fieldState:i})=>e.jsxs(g,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(f,{children:"Should Use Message Body"}),e.jsx(ee,{children:"Extract information from email message body"})]}),e.jsx(N,{children:e.jsx(Y,{checked:c.value,onCheckedChange:c.onChange,className:I(i)})})]})})]})}const Ht=Le({businessName:V().min(1,"Business name is required"),locality:V().min(1,"Locality is required"),localName:V().optional(),govId:V().optional(),address:V().optional(),localAddress:V().optional(),phone:V().optional(),website:Is("Invalid URL").optional().or(Ds("")),generalContacts:ze(qe()).optional(),billingEmails:ze(qe()).optional()});function ys(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(n=>n.trim()),billingEmails:s.clientInfo?.emails}}function Xt(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 Jt({data:s,refetchBusiness:n}){const t=De(dn,s),[a,l]=y.useState(ys(t)),{userContext:r}=y.useContext(es),{updateBusiness:c,fetching:i}=Vs(),o=Ie({resolver:Oe(Ht),defaultValues:a}),{countries:d,fetching:h}=cn(),[u,x]=y.useState(""),[A,m]=y.useState(""),p=o.watch("locality"),S=o.watch("address"),b=o.watch("localAddress");y.useEffect(()=>{S!==a.address&&o.setValue("address",S,{shouldDirty:!0})},[S,a.address,o]),y.useEffect(()=>{b!==a.localAddress&&o.setValue("localAddress",b,{shouldDirty:!0})},[b,a.localAddress,o]);const T=t&&"clientInfo"in t&&!!t.clientInfo,F=p===r?.context.locality,R=v=>{u.trim()&&(o.setValue("generalContacts",[...v,u.trim()],{shouldDirty:!0}),x(""))},$=(v,w)=>{o.setValue("generalContacts",v.filter((P,B)=>B!==w),{shouldDirty:!0})},J=v=>{A.trim()&&(o.setValue("billingEmails",[...v,A.trim()],{shouldDirty:!0}),m(""))},U=(v,w)=>{o.setValue("billingEmails",v.filter((P,B)=>B!==w),{shouldDirty:!0})},se=async v=>{if(!t||!r?.context.adminBusinessId)return;const w=Ze(v,o.formState.dirtyFields);if(!w)return;const P=Xt(w);await c({businessId:t.id,ownerId:r.context.adminBusinessId,fields:P}),n?.()};return y.useEffect(()=>{if(t){const v=ys(t);l(v),o.reset(v)}},[t,o]),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(Ae,{...o,children:e.jsxs("form",{onSubmit:o.handleSubmit(se),children:[e.jsx(X,{children:e.jsxs("div",{className:"grid gap-6 md:grid-cols-2",children:[e.jsx(j,{control:o.control,name:"businessName",render:({field:v,fieldState:w})=>e.jsxs(g,{children:[e.jsx(f,{children:"Business Name"}),e.jsx(N,{children:e.jsx(k,{...v,className:I(w)})}),e.jsx(C,{})]})}),e.jsx(j,{control:o.control,name:"locality",render:({field:v,fieldState:w})=>e.jsxs(g,{children:[e.jsx(f,{children:"Locality / Country"}),e.jsx(Ge,{onChange:v.onChange,data:d.map(P=>({value:P.code,label:P.name})),value:v.value,disabled:h,placeholder:"Scroll to see all options",formPart:!0,triggerProps:{className:I(w)}}),e.jsx(C,{})]})}),F&&e.jsx(j,{control:o.control,name:"localName",render:({field:v,fieldState:w})=>e.jsxs(g,{children:[e.jsx(f,{children:"Local Name"}),e.jsx(N,{children:e.jsx(k,{...v,placeholder:"Business name in local language",className:I(w)})}),e.jsx(C,{})]})}),F&&e.jsx(j,{control:o.control,name:"govId",render:({field:v,fieldState:w})=>e.jsxs(g,{children:[e.jsx(f,{children:"Government ID"}),e.jsx(N,{children:e.jsx(k,{...v,placeholder:"Enter Government ID",className:I(w)})}),e.jsx(C,{})]})}),e.jsx(j,{control:o.control,name:"address",render:({field:v,fieldState:w})=>e.jsxs(g,{className:"md:col-span-2",children:[e.jsxs(f,{className:"flex items-center gap-2",children:[e.jsx(We,{className:"h-4 w-4"}),"Address"]}),e.jsx(N,{children:e.jsx(Ke,{...v,rows:3,placeholder:"Enter business address",className:I(w)})}),e.jsx(C,{})]})}),F&&e.jsx(j,{control:o.control,name:"localAddress",render:({field:v,fieldState:w})=>e.jsxs(g,{className:"md:col-span-2",children:[e.jsxs(f,{className:"flex items-center gap-2",children:[e.jsx(We,{className:"h-4 w-4"}),"Local Address"]}),e.jsx(N,{children:e.jsx(Ke,{...v,rows:3,placeholder:"Enter address in local language",className:I(w)})}),e.jsx(C,{})]})}),e.jsx(j,{control:o.control,name:"phone",render:({field:v,fieldState:w})=>e.jsxs(g,{children:[e.jsxs(f,{className:"flex items-center gap-2",children:[e.jsx(ws,{className:"h-4 w-4"}),"Phone"]}),e.jsx(N,{children:e.jsx(k,{...v,type:"tel",placeholder:"+1 (555) 123-4567",className:I(w)})}),e.jsx(C,{})]})}),e.jsx(j,{control:o.control,name:"website",render:({field:v,fieldState:w})=>e.jsxs(g,{children:[e.jsxs(f,{className:"flex items-center gap-2",children:[e.jsx(on,{className:"h-4 w-4"}),"Website"]}),e.jsx(N,{children:e.jsx(k,{...v,type:"url",placeholder:"https://example.com",className:I(w)})}),e.jsx(C,{})]})}),e.jsx(j,{control:o.control,name:"generalContacts",render:({field:v,fieldState:w})=>e.jsxs(g,{className:"md:col-span-2",children:[e.jsxs(f,{className:"flex items-center gap-2",children:[e.jsx(He,{className:"h-4 w-4"}),"General Contacts"]}),e.jsx(N,{children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:I(w)+" flex flex-wrap gap-2 mb-2 rounded-md",children:v.value?.map((P,B)=>e.jsxs(Z,{variant:"secondary",className:"gap-1 pr-1",children:[P,e.jsx("button",{type:"button",onClick:()=>$(v.value??[],B),className:"ml-1 hover:bg-muted rounded-sm p-0.5",children:e.jsx(me,{className:"h-3 w-3"})})]},B))}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(k,{value:u,onChange:P=>x(P.target.value),onKeyDown:P=>{P.key==="Enter"&&(P.preventDefault(),R(v.value??[]))},placeholder:"Add contact email",type:"email"}),e.jsx(E,{type:"button",variant:"outline",size:"icon",disabled:!u.trim(),onClick:()=>R(v.value??[]),children:e.jsx(q,{className:"h-4 w-4"})})]})]})}),e.jsx(C,{})]})}),T&&e.jsx(j,{control:o.control,name:"billingEmails",render:({field:v,fieldState:w})=>e.jsxs(g,{className:"md:col-span-2",children:[e.jsxs(f,{className:"flex items-center gap-2",children:[e.jsx(He,{className:"h-4 w-4"}),"Billing Emails"]}),e.jsx(N,{children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:I(w)+" flex flex-wrap gap-2 mb-2 rounded-md",children:v.value?.map((P,B)=>e.jsxs(Z,{variant:"secondary",className:"gap-1 pr-1",children:[P,e.jsx("button",{type:"button",onClick:()=>U(v.value??[],B),className:"ml-1 hover:bg-muted rounded-sm p-0.5",children:e.jsx(me,{className:"h-3 w-3"})})]},B))}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(k,{value:A,onChange:P=>m(P.target.value),onKeyDown:P=>{P.key==="Enter"&&(P.preventDefault(),J(v.value??[]))},placeholder:"Add billing email",type:"email"}),e.jsx(E,{type:"button",variant:"outline",size:"icon",disabled:!A.trim(),onClick:()=>J(v.value??[]),children:e.jsx(q,{className:"h-4 w-4"})})]})]})}),e.jsx(C,{})]})})]})}),e.jsx(Ye,{className:"flex justify-end border-t mt-4 pt-6",children:e.jsxs(E,{type:"submit",disabled:i||Object.keys(o.formState.dirtyFields).length===0,children:[e.jsx(os,{className:"h-4 w-4 mr-2"}),"Save Changes"]})})]})})]})}const Qt="createContract",Yt=()=>{const[{fetching:s},n]=pe(mn),t=y.useCallback(async a=>{const l=`Error creating new contract for client[${a.input.clientId}]`,r=`${Qt}-${a.input.clientId}`;O.loading("Creating contract",{id:r});try{const c=await n(a);je(c,l,r)&&O.success("Success",{id:r,description:`Contract for client ${a.input.clientId} was successfully created`})}catch(c){console.error(`${l}: ${c}`),O.error("Error",{id:r,description:l,duration:1e5,closeButton:!0})}},[n]);return{creating:s,createContract:t}},Zt="updateContract",ea=()=>{const[{fetching:s},n]=pe(un),t=y.useCallback(async a=>{const l=`Error updating contract ID [${a.contractId}]`,r=`${Zt}-${a.contractId}`;O.loading("Updating contract",{id:r});try{const c=await n(a),i=je(c,l,r,"updateContract");if(i)return O.success("Success",{id:r,description:"Contract updated"}),i.updateContract}catch(c){console.error(`${l}: ${c}`),O.error("Error",{id:r,description:l,duration:1e5,closeButton:!0})}},[n]);return{updating:s,updateContract:t}},sa=Le({id:Ue().optional(),startDate:ms("Start date is required"),endDate:ms("End date is required"),po:V().optional(),paymentAmount:bs().min(0,"Payment amount must be non-negative"),paymentCurrency:ae(Object.values(ls),"Currency is required"),productType:ae(Object.values(As)).optional(),msCloudLink:Is().optional().or(Ds("")),billingCycle:ae(Object.values(be)).optional(),subscriptionPlan:ae(Object.values(Te)).optional(),isActive:xn(),defaultRemark:V().optional(),defaultDocumentType:ae(Object.values(de)),operationsLimit:hn().min(0,"Operations limit must be non-negative")}),Ns={startDate:"",endDate:"",po:void 0,paymentAmount:0,paymentCurrency:ls.Usd,productType:As.Hive,msCloudLink:void 0,billingCycle:be.Monthly,subscriptionPlan:void 0,isActive:!0,defaultRemark:void 0,defaultDocumentType:de.Proforma,operationsLimit:0};function na({clientId:s,contract:n,onDone:t}){const[a,l]=y.useState(!1),[r,c]=y.useState(null),{updateContract:i,updating:o}=ea(),{createContract:d,creating:h}=Yt(),u=Ie({resolver:Oe(sa),defaultValues:n||Ns});y.useEffect(()=>{n&&(c(n),u.reset({startDate:n.startDate,endDate:n.endDate,po:n.po,paymentAmount:n.paymentAmount,paymentCurrency:n.paymentCurrency,productType:n.productType,msCloudLink:n.msCloudLink,billingCycle:n.billingCycle,subscriptionPlan:n.subscriptionPlan,isActive:n.isActive,defaultRemark:n.defaultRemark,defaultDocumentType:n.defaultDocumentType,operationsLimit:n.operationsLimit}),l(!0))},[n,u]);const x=()=>{c(null),u.reset(Ns),l(!0)},A=y.useCallback(async m=>{if(r)await i({contractId:r.id,input:{amount:{raw:m.paymentAmount,currency:m.paymentCurrency},billingCycle:m.billingCycle,documentType:m.defaultDocumentType,endDate:Ne(new Date(m.endDate),"yyyy-MM-dd"),isActive:m.isActive,msCloud:m.msCloudLink,plan:m.subscriptionPlan,product:m.productType,purchaseOrder:m.po,remarks:m.defaultRemark,startDate:Ne(new Date(m.startDate),"yyyy-MM-dd"),operationsLimit:m.operationsLimit}});else{if(!m.billingCycle){u.setError("billingCycle",{message:"Billing cycle is required"});return}await d({input:{clientId:s,amount:{raw:m.paymentAmount,currency:m.paymentCurrency},billingCycle:m.billingCycle,documentType:m.defaultDocumentType,endDate:Ne(new Date(m.endDate),"yyyy-MM-dd"),isActive:m.isActive,msCloud:m.msCloudLink,plan:m.subscriptionPlan,product:m.productType,purchaseOrder:m.po,remarks:m.defaultRemark,startDate:Ne(new Date(m.startDate),"yyyy-MM-dd"),operationsLimit:m.operationsLimit}})}l(!1),c(null),t?.()},[r,t,d,i,s,u]);return e.jsxs(Pe,{open:a,onOpenChange:l,children:[e.jsx(ss,{asChild:!0,children:e.jsxs(E,{size:"sm",onClick:x,children:[e.jsx(q,{className:"h-4 w-4 mr-2"}),"New Contract"]})}),e.jsxs(Be,{className:"max-w-2xl max-h-[90vh] overflow-y-auto",children:[e.jsxs(ns,{children:[e.jsx(ts,{children:r?"Edit Contract":"Create New Contract"}),e.jsx(as,{children:r?"Update contract details":"Add a new contract with all required details"})]}),e.jsx(Ae,{...u,children:e.jsxs("form",{onSubmit:u.handleSubmit(A),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(j,{control:u.control,name:"operationsLimit",render:({field:m})=>e.jsxs(g,{children:[e.jsx(f,{children:"Operations Limit"}),e.jsx(N,{children:e.jsx(k,{type:"number",placeholder:"500",...m})}),e.jsx(C,{})]})}),e.jsx(j,{control:u.control,name:"po",render:({field:m})=>e.jsxs(g,{children:[e.jsx(f,{children:"PO Number"}),e.jsx(N,{children:e.jsx(k,{placeholder:"PO-2024-001",...m})}),e.jsx(C,{})]})})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsx(j,{control:u.control,name:"startDate",render:({field:{onChange:m,...p}})=>e.jsxs(g,{children:[e.jsx(f,{children:"Start Date"}),e.jsx(N,{children:e.jsx(k,{type:"date",...p,onInput:S=>m(S)})}),e.jsx(C,{})]})}),e.jsx(j,{control:u.control,name:"endDate",render:({field:{onChange:m,...p}})=>e.jsxs(g,{children:[e.jsx(f,{children:"End Date"}),e.jsx(N,{children:e.jsx(k,{type:"date",...p,onInput:S=>m(S)})}),e.jsx(C,{})]})})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-3",children:[e.jsx(j,{control:u.control,name:"paymentAmount",render:({field:m})=>e.jsxs(g,{className:"md:col-span-2",children:[e.jsx(f,{children:"Payment Amount"}),e.jsx(N,{children:e.jsx(k,{type:"number",placeholder:"24000",...m,onChange:p=>{m.onChange(p?.target.value?Number(p?.target.value):void 0)}})}),e.jsx(C,{})]})}),e.jsx(j,{control:u.control,name:"paymentCurrency",render:({field:m})=>e.jsxs(g,{children:[e.jsx(f,{children:"Currency"}),e.jsxs(ie,{onValueChange:m.onChange,defaultValue:m.value,children:[e.jsx(N,{children:e.jsx(re,{children:e.jsx(le,{})})}),e.jsx(ce,{children:Object.values(ls).map(p=>e.jsx(oe,{value:p,children:p},p))})]}),e.jsx(C,{})]})})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsx(j,{control:u.control,name:"productType",render:({field:m})=>e.jsxs(g,{children:[e.jsx(f,{children:"Product Type"}),e.jsx(N,{children:e.jsx(k,{placeholder:"Cloud Services",...m})}),e.jsx(C,{})]})}),e.jsx(j,{control:u.control,name:"billingCycle",render:({field:m})=>e.jsxs(g,{children:[e.jsx(f,{children:"Billing Cycle"}),e.jsxs(ie,{onValueChange:m.onChange,defaultValue:m.value,children:[e.jsx(N,{children:e.jsx(re,{children:e.jsx(le,{})})}),e.jsx(ce,{children:Object.values(be).map(p=>e.jsx(oe,{value:p,children:Ps(p)},p))})]}),e.jsx(C,{})]})})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsx(j,{control:u.control,name:"subscriptionPlan",render:({field:m})=>e.jsxs(g,{children:[e.jsx(f,{children:"Subscription Plan"}),e.jsx(N,{children:e.jsxs(ie,{onValueChange:m.onChange,defaultValue:m.value,children:[e.jsx(N,{children:e.jsx(re,{children:e.jsx(le,{})})}),e.jsx(ce,{children:Object.values(Te).map(p=>e.jsx(oe,{value:p,children:Bs(p)},p))})]})}),e.jsx(C,{})]})}),e.jsx(j,{control:u.control,name:"isActive",render:({field:m})=>e.jsxs(g,{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(f,{className:"text-base",children:"Active Status"})}),e.jsx(N,{children:e.jsx(Y,{checked:m.value,onCheckedChange:m.onChange})})]})})]}),e.jsx(j,{control:u.control,name:"msCloudLink",render:({field:m})=>e.jsxs(g,{children:[e.jsx(f,{children:"MS Cloud Link"}),e.jsx(N,{children:e.jsx(k,{type:"url",placeholder:"https://portal.azure.com/contract-id",...m})}),e.jsx(C,{})]})}),e.jsx(j,{control:u.control,name:"defaultDocumentType",render:({field:m})=>e.jsxs(g,{children:[e.jsx(f,{children:"Default Document Type"}),e.jsxs(ie,{onValueChange:m.onChange,defaultValue:m.value,children:[e.jsx(N,{children:e.jsx(re,{children:e.jsx(le,{})})}),e.jsx(ce,{children:Object.values(de).map(p=>e.jsx(oe,{value:p,children:is(p)},p))})]}),e.jsx(C,{})]})}),e.jsx(j,{control:u.control,name:"defaultRemark",render:({field:m})=>e.jsxs(g,{children:[e.jsx(f,{children:"Default Remark"}),e.jsx(N,{children:e.jsx(Ke,{placeholder:"Enter default remark for this contract...",rows:3,...m})}),e.jsx(C,{})]})})]}),e.jsxs(rs,{children:[e.jsx(E,{type:"button",variant:"outline",onClick:()=>l(!1),children:"Cancel"}),e.jsx(E,{type:"submit",disabled:h||o,children:r?"Update Contract":"Create Contract"})]})]})})]})]})}function ta(s){return{id:s.id,po:s.purchaseOrder??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 aa({clientId:s}){const[n,t]=y.useState(null),[{data:a,fetching:l},r]=we({query:pn,variables:{clientId:s}}),c=a?.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(na,{clientId:s,contract:n,onDone:r})]})}),e.jsx(X,{className:"space-y-4",children:c.map(i=>{const o=!!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(Z,{variant:o?"default":"secondary",children:i.isActive?"Active":"Inactive"})]}),e.jsx("p",{className:"text-sm text-muted-foreground font-mono",children:i.id})]}),e.jsx(E,{variant:"ghost",size:"sm",onClick:()=>t(ta(i)),children:e.jsx(et,{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(jn,{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 Number"}),e.jsx("p",{className:"text-sm font-medium font-mono",children:i.purchaseOrder})]}),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:gn(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:Ps(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?Bs(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:is(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(E,{variant:"outline",size:"sm",asChild:!0,children:e.jsxs("a",{href:i.msCloud.toString(),target:"_blank",rel:"noopener noreferrer",children:[e.jsx(fn,{className:"h-4 w-4 mr-2"}),"MS Cloud",e.jsx(vn,{className:"h-3 w-3 ml-1"})]})})})]},i.id)})})]})}function ia({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(X,{children:e.jsx(yn,{businessId:s,linkedDocumentIds:[],limit:1e3})})]})}const ra=[{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 la({data:s}){const n=De(bn,s),[{data:t,fetching:a},l]=we({query:Nn,variables:{clientId:n?.id??""},pause:!n?.clientInfo?.greenInvoiceId||!n?.id}),{updateClient:r}=Fs(),c=y.useCallback((o,d)=>{if(!n?.id)return;const h={};h[d]=o,r({businessId:n?.id,fields:h})},[n?.id,r]);y.useEffect(()=>{n?.clientInfo?.greenInvoiceId&&n?.id&&l()},[n?.clientInfo?.greenInvoiceId,n?.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(E,{size:"sm",children:[e.jsx(q,{className:"h-4 w-4 mr-2"}),"Add Integration"]})]})}),e.jsx(X,{className:"space-y-6",children:e.jsxs(st,{type:"multiple",defaultValue:["green-invoice"],className:"space-y-4",children:[a?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(D,{className:"h-10 w-10 rounded-lg"}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(D,{className:"h-6 w-32"}),e.jsx(D,{className:"h-5 w-5 rounded-full"})]}),e.jsx(D,{className:"h-4 w-64"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(D,{className:"h-8 w-24"}),e.jsx(D,{className:"h-8 w-8"})]})]})}),e.jsx(Re,{children:e.jsxs("div",{className:"p-6 space-y-6",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx(D,{className:"h-4 w-40"}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(D,{className:"h-3 w-24"}),e.jsx(D,{className:"h-4 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(D,{className:"h-3 w-24"}),e.jsx(D,{className:"h-4 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(D,{className:"h-3 w-24"}),e.jsx(D,{className:"h-4 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(D,{className:"h-3 w-24"}),e.jsx(D,{className:"h-4 w-full"})]})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(D,{className:"h-4 w-40"}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(D,{className:"h-3 w-32"}),e.jsx(D,{className:"h-6 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(D,{className:"h-3 w-24"}),e.jsx(D,{className:"h-4 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(D,{className:"h-3 w-24"}),e.jsx(D,{className:"h-4 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(D,{className:"h-3 w-24"}),e.jsx(D,{className:"h-4 w-full"})]})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(D,{className:"h-4 w-40"}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-3",children:[e.jsxs("div",{className:"space-y-2 md:col-span-2",children:[e.jsx(D,{className:"h-3 w-24"}),e.jsx(D,{className:"h-4 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(D,{className:"h-3 w-24"}),e.jsx(D,{className:"h-4 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(D,{className:"h-3 w-24"}),e.jsx(D,{className:"h-4 w-full"})]})]})]})]})})]}):e.jsxs($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(xs,{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(ca,{id:n?.clientInfo?.greenInvoiceId,provider:"Green Invoice",updateClient:async o=>c(o,"greenInvoiceId")}),e.jsx(hs,{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:n?.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(He,{className:"h-3.5 w-3.5"}),"Email Addresses"]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:i.emails?.map((o,d)=>e.jsx("span",{className:"text-sm px-2 py-1 bg-muted rounded",children:o},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(ws,{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(We,{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})]})]})]})]})})]}),ra.map(o=>e.jsxs($e,{value:o.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:o.name}),o.status==="connected"?e.jsx(xs,{className:"h-4 w-4 text-green-600"}):e.jsx(Cn,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:o.description})]})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(E,{variant:"ghost",size:"sm",onClick:d=>d.stopPropagation(),children:e.jsx(cs,{className:"h-4 w-4"})}),e.jsx(hs,{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:o.lastSync})]})})})]},o.id))]})})]})}function ca({id:s,provider:n,updateClient:t}){const[a,l]=y.useState(!1),[r,c]=y.useState(s),i=y.useCallback(async()=>{await t(r),l(!1)},[r,t]);return e.jsxs(Pe,{open:a,onOpenChange:l,children:[e.jsx(ss,{asChild:!0,children:e.jsxs(E,{variant:"outline",size:"sm",onClick:o=>o.stopPropagation(),children:[e.jsx(cs,{className:"h-4 w-4 mr-2"}),"Configure"]})}),e.jsxs(Be,{onClick:o=>o.stopPropagation(),children:[e.jsxs(ns,{children:[e.jsxs(ts,{children:["Configure ",n]}),e.jsxs(as,{children:["Update your ",n," integration settings"]})]}),e.jsx("div",{className:"space-y-4 py-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsxs(wn,{htmlFor:"id",children:[n," ID"]}),e.jsx(k,{id:"id",value:r,onChange:o=>c(o.target.value),placeholder:`Enter ${n} ID`})]})}),e.jsxs(rs,{children:[e.jsx(E,{variant:"outline",onClick:()=>l(!1),children:"Cancel"}),e.jsx(E,{onClick:i,disabled:!r,children:"Save Changes"})]})]})]})}function oa({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:"Transactions"}),e.jsx(H,{children:"Complete transaction history for this business"})]})})}),e.jsx(X,{children:e.jsx("div",{className:"rounded-md border",children:e.jsx(In,{businessID:s,filter:{}})})})]})}function da({data:s,refetchBusiness:n}){const t=De(En,s),[a,l]=Dn(),r=a.get("tab")||"contact",c=d=>{l({tab:d})};if(!t)return e.jsx("div",{children:"Business not found"});const i="clientInfo"in t&&!!t.clientInfo,o="adminInfo"in t&&!!t.adminInfo;return e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx(Ln,{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(An,{value:r,onValueChange:c,className:"w-full",children:[e.jsxs(Sn,{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(Q,{value:"contact",className:"flex items-center gap-2 data-[state=active]:bg-background",children:[e.jsx(nt,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Contact"})]}),e.jsxs(Q,{value:"config",className:"flex items-center gap-2 data-[state=active]:bg-background",children:[e.jsx(cs,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Config"})]}),e.jsxs(Q,{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(Q,{value:"transactions",className:"flex items-center gap-2 data-[state=active]:bg-background",children:[e.jsx(kn,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Transactions"})]}),e.jsxs(Q,{value:"documents",className:"flex items-center gap-2 data-[state=active]:bg-background",children:[e.jsx(Tn,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Documents"})]}),i&&e.jsxs(e.Fragment,{children:[e.jsxs(Q,{value:"contracts",className:"flex items-center gap-2 data-[state=active]:bg-background",children:[e.jsx(rt,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Contracts"})]}),e.jsxs(Q,{value:"integrations",className:"flex items-center gap-2 data-[state=active]:bg-background",children:[e.jsx(ct,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Integrations"})]})]}),o&&e.jsxs(Q,{value:"admin",className:"flex items-center gap-2 data-[state=active]:bg-background",children:[e.jsx(Es,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Admin"})]})]}),e.jsx(z,{value:"contact",className:"mt-0",children:e.jsx(Jt,{data:t,refetchBusiness:n})}),e.jsx(z,{value:"config",className:"mt-0",children:e.jsx(zt,{data:t,refetchBusiness:n})}),e.jsx(z,{value:"charges",className:"mt-0",children:e.jsx(ft,{businessId:t.id})}),e.jsx(z,{value:"transactions",className:"mt-0",children:e.jsx(oa,{businessId:t.id})}),e.jsx(z,{value:"documents",className:"mt-0",children:e.jsx(ia,{businessId:t.id})}),i&&e.jsxs(e.Fragment,{children:[e.jsx(z,{value:"contracts",className:"mt-0",children:e.jsx(aa,{clientId:t.id})}),e.jsx(z,{value:"integrations",className:"mt-0",children:e.jsx(la,{data:t})}),e.jsx(z,{value:"charts",className:"mt-0",children:e.jsx(Ot,{})})]}),o&&e.jsx(z,{value:"admin",className:"mt-0",children:e.jsx(gt,{data:t})})]})})]})}function va(s){return`/businesses/${s}`}const ya=()=>{const{businessId:s}=Pn();let n;try{n=Bn()}catch{}const[{data:t,fetching:a},l]=we({query:On,pause:!s||!!n,variables:{businessId:s??""}}),r=n||t;return!n&&a&&!r?.business?e.jsx(Cs,{}):!s||!r?.business?e.jsx("div",{children:"Business not found"}):e.jsx(da,{data:r.business,refetchBusiness:async()=>l()})};export{ya as BusinessScreen,va as getBusinessHref};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{bq as S,u as g,r as m,F as x,a as C,j as o,bu as y,n as h,bv as T,bw as b,b1 as n,bh as F,bx as v}from"./index-CgQ4Qjvh.js";const I=({businessId:t})=>{const{businessId:r}=S(),{get:s}=g(),{setFiltersContext:u}=m.useContext(x),l=t||r,[c,d]=m.useState(s("transactionsFilters")?{...JSON.parse(decodeURIComponent(s("transactionsFilters"))),businessIDs:l?[l]:[]}:{businessIDs:l?[l]:[]}),[{data:i,fetching:f}]=C({query:v,variables:{filters:c}});m.useEffect(()=>{u(o.jsx(y,{filter:c,setFilter:d}))},[i,c,u,d]);const p=m.useMemo(()=>i?.businessTransactionsSumFromLedgerRecords.__typename==="CommonError"?[]:i?.businessTransactionsSumFromLedgerRecords.businessTransactionsSum?i.businessTransactionsSumFromLedgerRecords.businessTransactionsSum.sort((e,w)=>e.business.name.localeCompare(w.business.name)):[],[i?.businessTransactionsSumFromLedgerRecords]);return f?o.jsx(h,{}):o.jsx(T,{moreInfo:e=>o.jsx(F,{businessID:e.business.id,filter:c}),striped:!0,highlightOnHover:!0,stickyHeader:!0,items:p,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)?o.jsx(b,{color:e.total.raw>0?"green":"red",children:e.total.formatted}):e.total.formatted,style:{whiteSpace:"nowrap"}},...a(n.Eur),...a(n.Usd),...a(n.Gbp),...a(n.Cad),...a(n.Jpy),...a(n.Aud),...a(n.Sek)]})};function a(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)?o.jsx(b,{color:s.total.raw>0?"green":"red",children:s.total.formatted}):s?.total?.formatted},style:{whiteSpace:"nowrap"}}]}export{I as BusinessTransactionsSingle};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{bq as u,r as n,F as p,a as c,j as s,n as x,c as d,bE as l}from"./index-CgQ4Qjvh.js";import{P as m,C as b,E as T}from"./editable-business-trip-B95j7iAh.js";const E=({businessTripId:a})=>{const{businessTripId:o}=u(),{setFiltersContext:i}=n.useContext(p),e=a??o??"",[{data:r,fetching:t}]=c({query:l,variables:{businessTripId:e}});return n.useEffect(()=>{i(s.jsx("div",{className:"flex flex-row gap-x-5",children:s.jsx(m,{filename:"business_trip_report"})}))},[r,t,i]),t||!r?.businessTrip?s.jsx(x,{}):s.jsx(d,{title:`Business Trip: ${r.businessTrip.name}`,description:"Manage business trip",children:s.jsx(b,{className:"mt-5",children:e&&s.jsx(T,{tripId:e,isExtended:!0})})})};export{E as BusinessTrip};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{c_ as B,r as i,u as R,d1 as U,j as e,c$ as W,s as z,bA as G,B as _,d0 as Q,ae as q,V as J,H as N,ag as D,di as K,aL as X,a0 as $,dj as Y,bP as h,ci as A,fs as Z,bU as M,bV as O,bQ as P,eA as k,aI as x,ft as ee,bg as se,a2 as m,a3 as j,a4 as g,a5 as p,dK as ae,dL as te,dM as ne}from"./index-CgQ4Qjvh.js";import{s as oe}from"./sub-BxFupCKS.js";function le(a){return!a||B(a)?null:encodeURIComponent(JSON.stringify(a))}const re=[{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:y}=i.useContext(q),o=J({defaultValues:{byOwners:y?.context.adminBusinessId?[y.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:r,handleSubmit:T,watch:C}=o,[b,F]=i.useState(a.sortBy?.asc??!1),[c,u]=i.useState(!!a.sortBy?.field),{selectableFinancialEntities:S,fetching:t}=K(),{selectableTags:v,fetching:I}=X(),E=C("sortBy.field");i.useEffect(()=>{E&&!c?u(!0):!E&&c&&u(!1)},[E,c]);const V=s=>{b!=null&&s.sortBy?.field&&(s.sortBy.asc=b),w(s),d()};function H(){w({}),F(!1),d()}return e.jsxs(e.Fragment,{children:[t?e.jsx("div",{children:"Loading..."}):e.jsx("div",{}),e.jsx($,{...o,children:e.jsxs("form",{onSubmit:T(V),children:[e.jsxs(Y,{cols:2,children:[e.jsx(h,{name:"byOwners",control:r,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:r,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:r,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:(l,f,L)=>L.label?.toLowerCase().includes(l.toLowerCase().trim())||L.description?.toLowerCase().includes(l.toLowerCase().trim())})}),e.jsx(h,{name:"fromAnyDate",control:r,defaultValue:a.fromAnyDate,rules:{pattern:{value:M,message:"Date must be im format yyyy-mm-dd"}},render:({field:s,fieldState:n})=>e.jsx(O,{...s,onChange:l=>{const f=l?typeof l=="string"?l:N(l,"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:r,defaultValue:a.toAnyDate,rules:{pattern:{value:M,message:"Date must be im format yyyy-mm-dd"}},render:({field:s,fieldState:n})=>e.jsx(O,{...s,onChange:l=>{const f=l?typeof l=="string"?l:N(l,"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:r,defaultValue:a.chargesType,render:({field:s,fieldState:n})=>e.jsx(P,{...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:r,defaultValue:a.sortBy?.field??D.Date,render:({field:s,fieldState:n})=>e.jsx(P,{...s,data:re,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(x,{defaultChecked:a.sortBy?.asc??!1,checked:b??!1,disabled:!c,onCheckedChange:F}),e.jsx("span",{className:"text-xs",children:b?"ASC":"DESC"})]})})}),e.jsx(h,{name:"accountantStatus",control:r,defaultValue:a.accountantStatus,render:({field:s,fieldState:n})=>e.jsx(A,{...s,value:s.value??[],data:ee,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(se,{children:"Missing Information:"}),e.jsx(m,{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(g,{children:"Without Invoice"})}),e.jsx(p,{children:e.jsx(x,{defaultChecked:a.withoutInvoice??!1,onCheckedChange:s.onChange})})]})}),e.jsx(m,{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(g,{children:"Without Receipts"})}),e.jsx(p,{children:e.jsx(x,{defaultChecked:a.withoutReceipt??!1,onCheckedChange:s.onChange})})]})}),e.jsx(m,{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(g,{children:"Without Documents"})}),e.jsx(p,{children:e.jsx(x,{defaultChecked:a.withoutDocuments??!1,onCheckedChange:s.onChange})})]})}),e.jsx(m,{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(g,{children:"With Open Documents"})}),e.jsx(p,{children:e.jsxs(ae,{children:[e.jsx(te,{children:e.jsx(x,{defaultChecked:a.withOpenDocuments??!1,onCheckedChange:s.onChange})}),e.jsx(ne,{children:e.jsx("p",{children:"Show only charges with documents that are currently open"})})]})})]})}),e.jsx(m,{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(g,{children:"Without Transactions"})}),e.jsx(p,{children:e.jsx(x,{defaultChecked:a.withoutTransactions??!1,onCheckedChange:s.onChange})})]})}),e.jsx(m,{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(g,{children:"Unbalanced businesses"})}),e.jsx(p,{children:e.jsx(x,{defaultChecked:a.unbalanced??!1,onCheckedChange:s.onChange})})]})}),e.jsx(m,{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(g,{children:"Without ledger"})}),e.jsx(p,{children:e.jsx(x,{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:H,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 he({filter:a={},setFilter:w,activePage:d,setPage:y,totalPages:o=1,initiallyOpened:r=!1}){const[T,C]=i.useState(r),[b,F]=i.useState(!B(a)),{get:c,set:u}=R();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=le(a),v=c("chargesFilters");t!==v&&(u("chargesFilters",t),u("page"),y(1))},[a,c,u,y]);const S=i.useCallback(t=>{U(t,a)||(w(t),F(!B(t)))},[a,w]);return e.jsxs("div",{className:"flex flex-row gap-5 items-center",children:[e.jsx(W,{opened:T,onClose:()=>C(!1),content:e.jsx(ie,{filter:a,setFilter:S,closeModal:()=>C(!1)}),modalSize:"xl"}),o>1&&e.jsx(z,{className:"flex-auto",value:d,onChange:y,total:o}),e.jsx(G,{inline:!0,size:16,disabled:!b,children:e.jsx(_,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>C(!0),children:e.jsx(Q,{className:"size-5"})})})]})}export{he as C,ce as c,le as e};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as t,F as E,u as N,a as P,j as e,T as b,B as w,P as z,b as T,c as W,L as O,C as k,e as B,f as R,g as V,E as A,I as Q,M as U,h as q}from"./index-CgQ4Qjvh.js";import{C as J}from"./charges-filters-T9c4RGLH.js";import{M as $}from"./index-AxUq37Ea.js";import{P as G}from"./Progress-DembKoIO.js";import"./sub-BxFupCKS.js";import"./subMonths-DskeQPiN.js";import"./Checkbox-BZ680-Kk.js";const se=()=>{const{setFiltersContext:m}=t.useContext(E),[o,x]=t.useState(void 0),[l,C]=t.useState(void 0),[c,p]=t.useState(void 0),[g,f]=t.useState(!1),[a,d]=t.useState([]),{get:F}=N(),h=F("chargesFilters"),I=t.useMemo(()=>{if(h)try{return JSON.parse(decodeURIComponent(h))}catch{return}},[h]),[n,j]=t.useState(I),S=t.useCallback((s,D)=>{a.map(u=>u.id).includes(s)?d(a.filter(u=>u.id!==s)):d([...a,{id:s,onChange:D}])},[a]),[{data:r,fetching:M},v]=P({query:q,variables:{filters:n},pause:!0});function y(){d([])}const i=t.useMemo(()=>r?.chargesWithLedgerChanges?.length?r.chargesWithLedgerChanges[r.chargesWithLedgerChanges.length-1].progress:0,[r?.chargesWithLedgerChanges]),L=t.useCallback(s=>{j(s)},[j]);return t.useEffect(()=>{n&&v()},[n,v]),t.useEffect(()=>{m(e.jsxs("div",{className:"flex flex-row gap-x-5 items-center",children:[e.jsx(G,{value:i,label:`${i?.toFixed(2)}%`,size:"xl",animate:i<100,className:"min-w-52"}),e.jsx(J,{filter:n,setFilter:L,activePage:1,setPage:()=>{},initiallyOpened:!0}),e.jsx(b,{label:"Expand all accounts",children:e.jsx(w,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>f(s=>!s),children:g?e.jsx(z,{className:"size-5"}):e.jsx(T,{className:"size-5"})})}),e.jsx($,{selected:a,resetMerge:y})]}))},[r,M,n,g,m,f,a,i,L]),e.jsxs(W,{title:"Charges Ledger Validation",description:"Manage charges",children:[M?e.jsx(O,{className:"h-10 w-10 animate-spin mr-2 self-center"}):e.jsxs(e.Fragment,{children:[e.jsx(k,{setEditChargeId:x,setInsertDocument:C,setMatchDocuments:p,toggleMergeCharge:S,mergeSelectedCharges:new Set(a.map(s=>s.id)),data:r?.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&&!r?.chargesWithLedgerChanges.filter(s=>!!s.charge).length&&e.jsx(R,{radius:"xl",size:"xl",color:"green",children:e.jsx(V,{})})]})]}),o&&e.jsx(A,{chargeId:o?.id,close:()=>x(void 0),onChange:o.onChange}),l&&e.jsx(Q,{chargeId:l.id,onChange:l.onChange,close:()=>C(void 0)}),c&&e.jsx(U,{chargeId:c.id,ownerId:c.ownerId,setMatchDocuments:()=>p(void 0)})]})};export{se as ChargesLedgerValidation};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import{D as Te,bF as Qe,bG as Je,r as x,bH as es,bI as ae,ah as ss,bJ as ts,bK as ns,bL as rs,j as e,B as b,L as Se,i as B,bM as is,t as j,l as I,bN as Fe,a as re,bO as je,bP as y,bQ as G,bR as oe,bS as Me,bT as ze,ae as as,bU as W,bV as q,H as F,b1 as Pe,bW as $e,o as U,T as w,ao as Y,V as S,q as C,a0 as N,a2 as M,a3 as z,a4 as Q,a5 as P,v as J,a7 as R,aO as Oe,bX as K,e as X,bY as os,bZ as cs,b_ as ds,b$ as ne,c0 as D,c1 as ls,c2 as ke,c3 as Re,X as A,c4 as Ce,c5 as He,c6 as us,c7 as me,c8 as ee,g as se,c9 as hs,ca as xs,cb as te,cc as ps,cd as ms,ce as _e,cf as gs,cg as js,ch as fs,ci as Ve,cj as Ue,ck as vs,cl as bs,cm as ys,cn as Ts,co as Le,cp as Cs,cq as Es,cr as As,aI as fe,cs as ws,ct as Ds,cu as Bs,cv as Is,cw as Ns,cx as Ss,cy as Fs,cz as Ms,cA as zs,cB as Ps,cC as $s,cD as Os,cE as ks,cF as Rs,cG as Hs,cH as _s,cI as Vs,u as Us,cJ as Ls,cK as Ws,cL as qs,cM as Gs,y as Ys,cN as Ks,cO as Xs,cP as Zs,cQ as Qs,cR as Js,cS as et,cT as st,cU as ye,cV as tt,cW as nt,cX as rt,bz as T,cY as it}from"./index-CgQ4Qjvh.js";/**
|
|
2
|
-
* @license lucide-react v0.546.0 - ISC
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the ISC license.
|
|
5
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/const at=[["path",{d:"M19 17h2c.6 0 1-.4 1-1v-3c0-.9-.7-1.7-1.5-1.9C18.7 10.6 16 10 16 10s-1.3-1.4-2.2-2.3c-.5-.4-1.1-.7-1.8-.7H5c-.6 0-1.1.4-1.4.9l-1.4 2.9A3.7 3.7 0 0 0 2 12v4c0 .6.4 1 1 1h2",key:"5owen"}],["circle",{cx:"7",cy:"17",r:"2",key:"u2ysq9"}],["path",{d:"M9 17h6",key:"r8uit2"}],["circle",{cx:"17",cy:"17",r:"2",key:"axvx0g"}]],ot=Te("car",at);/**
|
|
7
|
-
* @license lucide-react v0.546.0 - ISC
|
|
8
|
-
*
|
|
9
|
-
* This source code is licensed under the ISC license.
|
|
10
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
11
|
-
*/const ct=[["path",{d:"M14 13h2a2 2 0 0 1 2 2v2a2 2 0 0 0 4 0v-6.998a2 2 0 0 0-.59-1.42L18 5",key:"1wtuz0"}],["path",{d:"M14 21V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v16",key:"e09ifn"}],["path",{d:"M2 21h13",key:"1x0fut"}],["path",{d:"M3 9h11",key:"1p7c0w"}]],dt=Te("fuel",ct);/**
|
|
12
|
-
* @license lucide-react v0.546.0 - ISC
|
|
13
|
-
*
|
|
14
|
-
* This source code is licensed under the ISC license.
|
|
15
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
16
|
-
*/const lt=[["path",{d:"M6 18H4a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2",key:"143wyd"}],["path",{d:"M6 9V3a1 1 0 0 1 1-1h10a1 1 0 0 1 1 1v6",key:"1itne7"}],["rect",{x:"6",y:"14",width:"12",height:"8",rx:"1",key:"1ue0tg"}]],ut=Te("printer",lt);var ht=Qe((i,{fluid:n,sizes:r},{size:t})=>({root:{paddingLeft:i.spacing.md,paddingRight:i.spacing.md,maxWidth:n?"100%":Je({size:t,sizes:r}),marginLeft:"auto",marginRight:"auto"}})),xt=Object.defineProperty,ge=Object.getOwnPropertySymbols,We=Object.prototype.hasOwnProperty,qe=Object.prototype.propertyIsEnumerable,Ee=(i,n,r)=>n in i?xt(i,n,{enumerable:!0,configurable:!0,writable:!0,value:r}):i[n]=r,pt=(i,n)=>{for(var r in n||(n={}))We.call(n,r)&&Ee(i,r,n[r]);if(ge)for(var r of ge(n))qe.call(n,r)&&Ee(i,r,n[r]);return i},mt=(i,n)=>{var r={};for(var t in i)We.call(i,t)&&n.indexOf(t)<0&&(r[t]=i[t]);if(i!=null&&ge)for(var t of ge(i))n.indexOf(t)<0&&qe.call(i,t)&&(r[t]=i[t]);return r};const gt={sizes:{xs:ae(540),sm:ae(720),md:ae(960),lg:ae(1140),xl:ae(1320)}},jt=x.forwardRef((i,n)=>{const r=es("Container",gt,i),{className:t,fluid:s,size:a,unstyled:o,sizes:d,variant:m}=r,p=mt(r,["className","fluid","size","unstyled","sizes","variant"]),{classes:h,cx:l}=ht({fluid:s,sizes:d},{unstyled:o,name:"Container",variant:m,size:a});return ss.createElement(ts,pt({className:l(h.root,t),ref:n},p))});jt.displayName="@mantine/core/Container";var k=3.77952755906,xe={method:"save",resolution:3,page:{margin:0,format:"A4",orientation:"portrait"},canvas:{mimeType:"image/jpeg",qualityRatio:1,useCORS:!0,logging:!1},overrides:{}},ft=class{pdf;canvas;options;constructor(i,n){this.canvas=i,this.options=n,this.pdf=new rs({format:this.options.page.format,orientation:this.options.page.orientation,...this.options.overrides?.pdf,unit:"mm"})}getMarginTopMM(){const i=typeof this.options.page.margin=="object"?this.options.page.margin.top:this.options.page.margin;return Number(i)}getMarginLeftMM(){const i=typeof this.options.page.margin=="object"?this.options.page.margin.left:this.options.page.margin;return Number(i)}getMarginRightMM(){const i=typeof this.options.page.margin=="object"?this.options.page.margin.right:this.options.page.margin;return Number(i)}getMarginBottomMM(){const i=typeof this.options.page.margin=="object"?this.options.page.margin.bottom:this.options.page.margin;return Number(i)}getMarginTop(){return this.getMarginTopMM()*k}getMarginBottom(){return this.getMarginBottomMM()*k}getMarginLeft(){return this.getMarginLeftMM()*k}getMarginRight(){return this.getMarginRightMM()*k}getScale(){return this.options.resolution}getPageHeight(){return this.getPageHeightMM()*k}getPageHeightMM(){return this.pdf.internal.pageSize.height}getPageWidthMM(){return this.pdf.internal.pageSize.width}getPageWidth(){return this.getPageWidthMM()*k}getOriginalCanvasWidth(){return this.canvas.width/this.getScale()}getOriginalCanvasHeight(){return this.canvas.height/this.getScale()}getCanvasPageAvailableHeight(){return this.getPageAvailableHeight()*this.getScale()*this.getHorizontalFitFactor()}getPageAvailableWidth(){return this.getPageWidth()-(this.getMarginLeft()+this.getMarginRight())}getPageAvailableHeight(){return this.getPageHeight()-(this.getMarginTop()+this.getMarginBottom())}getPageAvailableWidthMM(){return this.getPageAvailableWidth()/k}getPageAvailableHeightMM(){return this.getPageAvailableHeight()/k}getNumberPages(){return Math.ceil(this.canvas.height/this.getCanvasPageAvailableHeight())}getHorizontalFitFactor(){return this.getPageAvailableWidth()<this.getOriginalCanvasWidth()?this.getOriginalCanvasWidth()/this.getPageAvailableWidth():1}getCanvasOffsetY(i){return this.getCanvasPageAvailableHeight()*(i-1)}getCanvasHeightLeft(i){return this.canvas.height-this.getCanvasOffsetY(i)}getCanvasPageHeight(i){if(this.canvas.height<this.getCanvasPageAvailableHeight())return this.canvas.height;const n=this.getCanvasHeightLeft(i);return n<this.getCanvasPageAvailableHeight()?n:this.getCanvasPageAvailableHeight()}getCanvasPageWidth(){return this.canvas.width}createCanvasPage(i){const n=this.getCanvasPageWidth(),r=this.getCanvasPageHeight(i),t=document.createElement("canvas");return t.setAttribute("width",String(n)),t.setAttribute("height",String(r)),t.getContext("2d").drawImage(this.canvas,0,this.getCanvasOffsetY(i),this.canvas.width,r,0,0,this.canvas.width,r),t}convert(){let i=1;const n=this.getNumberPages();for(;i<=n;){i>1&&this.pdf.addPage(this.options.page.format,this.options.page.orientation);const r=this.createCanvasPage(i),t=r.toDataURL(this.options.canvas.mimeType,this.options.canvas.qualityRatio);this.pdf.setPage(i),this.pdf.addImage({imageData:t,width:r.width/(this.getScale()*k*this.getHorizontalFitFactor()),height:r.height/(this.getScale()*k*this.getHorizontalFitFactor()),x:this.getMarginLeftMM(),y:this.getMarginTopMM()}),i+=1}return this.pdf}},vt=i=>i?{...xe,...i,canvas:{...xe.canvas,...i.canvas},page:{...xe.page,...i.page}}:xe,bt=i=>typeof i=="function"?i():i?.current,yt=async(i,n)=>{const r=vt(n),t=bt(i);if(!t){console.error("Unable to get the target element.");return}const s=await ns(t,{useCORS:r.canvas.useCORS,logging:r.canvas.logging,scale:r.resolution,...r.overrides?.canvas}),o=new ft(s,r).convert();switch(r.method){case"build":return o;case"open":return window.open(o.output("bloburl"),"_blank"),o;case"save":default:{const d=r.filename??`${new Date().getTime()}.pdf`;return await o.save(d,{returnPromise:!0}),o}}},Tt=yt;const Ct={method:"open",overrides:{pdf:{compress:!0}}},Et=()=>document.getElementById("main-page"),Rn=({filename:i})=>{const[n,r]=x.useState(!1),t=async()=>{r(!0),await Tt(Et,{...Ct,filename:i}),r(!1)};return e.jsx(b,{variant:"outline",size:"icon",className:"size-7.5",onClick:t,disabled:n,children:n?e.jsx(Se,{className:"h-10 w-10 animate-spin mr-2 self-center"}):e.jsx(ut,{className:"size-5"})})},At="addBusinessTripAccommodationsExpense",wt=()=>{const[{fetching:i},n]=B(is),r=x.useCallback(async t=>{const s="Error adding business trip accommodations expense",a=At;j.loading("Adding Business Trip Accommodations Expense",{id:a});try{const o=await n(t),d=I(o,s,a);if(d)return j.success("Success",{id:a,description:"Business trip accommodations expense added"}),d.addBusinessTripAccommodationsExpense}catch(o){console.error(`${s}: ${o}`),j.error("Error",{id:a,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:i,addBusinessTripAccommodationsExpense:r}};function Ge({formManager:i,attendeesStayPath:n,attendeesData:r,fetchingAttendees:t=!1,businessTripId:s}){const{control:a,watch:o,trigger:d}=i,{fields:m,append:p,remove:h}=Fe({control:a,name:n}),[l,c]=x.useState(t),[u,g]=x.useState(r??[]),f=o(n),E=m.map((_,O)=>({..._,...f[O]}));x.useEffect(()=>{r&&g(r)},[r]),x.useEffect(()=>{c(t)},[t]);const[{data:v,fetching:$},H]=re({query:je,pause:!0,variables:{businessTripId:s??""}});return x.useEffect(()=>{if(v?.businessTrip?.attendees.length){const _=v.businessTrip.attendees.map(O=>({value:O.id,label:O.name}))??[];g(_)}},[v?.businessTrip?.attendees]),x.useEffect(()=>{c($)},[$]),x.useEffect(()=>{!r&&!v&&!t&&!$&&H({businessTripId:s})},[r,t,$,H,s,v]),!s&&!r?e.jsx("div",{children:"Cannot edit attendees stay, lacking some mandatory information!"}):e.jsxs("div",{children:[e.jsx("span",{className:"mantine-InputWrapper-label mantine-Select-label",children:"Employees Stay"}),e.jsxs("div",{className:"h-full flex flex-col overflow-hidden",children:[E?.map((_,O)=>e.jsxs("div",{className:"flex items-end gap-2 text-gray-600 mb-2",children:[e.jsx("div",{className:"w-full mt-1 relative rounded-md shadow-xs",children:e.jsx(y,{name:`${n}.${O}.attendeeId`,control:a,rules:{required:"Required"},render:({field:L,fieldState:V})=>e.jsx(G,{...L,disabled:l,data:u,value:L.value??void 0,label:"Attendee",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:V.error?.message,withinPortal:!0,required:!0})})}),e.jsx("div",{className:"w-full mt-1 relative rounded-md shadow-xs",children:e.jsx(y,{control:a,name:`${n}.${O}.nightsCount`,render:({field:L,fieldState:V})=>e.jsx(oe,{className:"w-full",...L,min:0,label:"Nights Count",value:L.value??void 0,hideControls:!0,precision:0,error:V.error?.message,required:!0,onChange:ie=>L.onChange(ie&&typeof ie=="number"?ie:void 0)})})}),e.jsx(b,{variant:"ghost",size:"icon",className:"mb-2 size-7.5",onClick:()=>{h(O),d(n)},children:e.jsx(Me,{className:"size-5"})})]},_.id)),e.jsx(b,{variant:"ghost",size:"icon",className:"size-7.5",onClick:()=>{p({}),d(n)},children:e.jsx(ze,{className:"size-5"})})]})]})}function ce({businessTripId:i,control:n,setFetching:r}){const[t,s]=x.useState([]),[{data:a,fetching:o,error:d}]=re({query:je,variables:{businessTripId:i}}),{userContext:m}=x.useContext(as);x.useEffect(()=>{a?.businessTrip?.attendees.length&&s(a.businessTrip.attendees.map(h=>({value:h.id,label:h.name})).sort((h,l)=>h.label>l.label?1:-1))},[a,s]),x.useEffect(()=>{r(o)},[r,o]),x.useEffect(()=>{d&&j.error("Error",{description:"Oops, we have an error fetching attendees"})},[d]);const p=x.useMemo(()=>m?.context.ledgerLock,[m]);return e.jsxs(e.Fragment,{children:[e.jsx(y,{name:"date",control:n,rules:{min:p?{value:p,message:`Date must be after ${p}`}:void 0,pattern:{value:W,message:"Date must be im format yyyy-mm-dd"}},render:({field:h,fieldState:l})=>e.jsx(q,{"data-autofocus":!0,...h,onChange:c=>{const u=c?typeof c=="string"?c:F(c,"yyyy-MM-dd"):void 0;u!==h.value&&h.onChange(u)},value:h.value?new Date(h.value):void 0,error:l.error?.message,label:"Date",popoverProps:{withinPortal:!0}})}),e.jsx(y,{name:"valueDate",control:n,rules:{pattern:{value:W,message:"Date must be im format yyyy-mm-dd"},min:p?{value:p,message:`Date must be after ${p}`}:void 0},render:({field:h,fieldState:l})=>e.jsx(q,{...h,onChange:c=>{const u=c?typeof c=="string"?c:F(c,"yyyy-MM-dd"):void 0;u!==h.value&&h.onChange(u)},value:h.value?new Date(h.value):void 0,error:l.error?.message,label:"Value Date",popoverProps:{withinPortal:!0}})}),e.jsx(y,{name:"amount",control:n,render:({field:h,fieldState:l})=>e.jsx(y,{name:"currency",control:n,defaultValue:Pe.Ils,render:({field:c,fieldState:u})=>e.jsx($e,{...h,value:h.value??void 0,error:l.error?.message||u.error?.message,label:"Amount",currencyCodeProps:{...c,label:"Currency"}})})}),e.jsx(y,{name:"employeeBusinessId",control:n,render:({field:h,fieldState:l})=>e.jsx(G,{...h,data:t,value:h.value,disabled:o,label:"Attendee",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:l.error?.message,withinPortal:!0})})]})}function Ae(i){const{businessTripId:n,onAdd:r}=i,[t,{close:s,open:a}]=U(!1);return e.jsxs(e.Fragment,{children:[e.jsx(w,{label:"Add Accommodations Expense",children:e.jsx(b,{variant:"outline",size:"icon",className:"size-7.5",onClick:o=>{o.stopPropagation(),a()},children:e.jsx(Y,{className:"size-5"})})}),t&&e.jsx(Dt,{businessTripId:n,opened:t,close:s,onAdd:r})]})}function Dt({businessTripId:i,opened:n,close:r,onAdd:t}){const s=S({defaultValues:{businessTripId:i}}),{control:a,handleSubmit:o}=s,[d,m]=x.useState(!1),{addBusinessTripAccommodationsExpense:p,fetching:h}=wt(),l=c=>{p({fields:c}).then(()=>{t?.(),r()})};return e.jsxs(C,{opened:n,onClose:r,centered:!0,lockScroll:!0,children:[e.jsx(C.Title,{children:"Add Accommodation Expense"}),e.jsx(C.Body,{children:e.jsx(N,{...s,children:e.jsxs("form",{onSubmit:o(l),className:"space-y-3",children:[e.jsx(ce,{businessTripId:i,control:a,setFetching:m}),e.jsx(M,{control:a,name:"country",render:({field:c})=>e.jsxs(z,{children:[e.jsx(Q,{children:"Country"}),e.jsx(P,{children:e.jsx(J,{...c,value:c.value??void 0})}),e.jsx(R,{})]})}),e.jsx(M,{name:"nightsCount",control:a,render:({field:c})=>e.jsxs(z,{children:[e.jsx(Q,{children:"Nights Count"}),e.jsx(P,{children:e.jsx(Oe,{...c,value:c.value??void 0,hideControls:!0,decimalScale:0,thousandSeparator:","})}),e.jsx(R,{})]})}),e.jsx(Ge,{formManager:s,attendeesStayPath:"attendeesStay",businessTripId:i}),e.jsx("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:"Add"})})]})})}),(h||d)&&e.jsx(K,{blur:1,center:!0,children:e.jsx(X,{})})]})}const Bt="updateBusinessTripAccommodationsExpense",It=()=>{const[{fetching:i},n]=B(os),r=x.useCallback(async t=>{const s="Error updating business trip accommodations expense",a=Bt;j.loading("Updating trip accommodations expense",{id:a});try{const o=await n(t),d=I(o,s,a);if(d)return j.success("Success",{id:a,description:"Business trip accommodations expense was updated"}),d.updateBusinessTripAccommodationsExpense}catch(o){console.error(`${s}: ${o}`),j.error("Error",{id:a,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:i,updateBusinessTripAccommodationsExpense:r}},Nt="categorizeIntoExistingBusinessTripExpense",St=()=>{const[{fetching:i},n]=B(cs),r=x.useCallback(async t=>{const s="Error updating business trip expense category",a=Nt;j.loading("Updating business trip expense category",{id:a});try{const o=await n(t),d=I(o,s,a);if(d)return j.success("Success",{id:a,description:"Business trip expense category was updated"}),d.categorizeIntoExistingBusinessTripExpense}catch(o){console.error(`${s}: ${o}`),j.error("Error",{id:a,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:i,categorizeIntoExistingBusinessTripExpense:r}};function de(i){const{businessTripExpenseId:n,businessTripId:r,onChange:t}=i,[s,{close:a,open:o}]=U(!1);return e.jsxs(e.Fragment,{children:[e.jsx(w,{label:"Attach Uncategorized Transaction",children:e.jsx(b,{variant:"outline",size:"icon",className:"size-7.5",onClick:d=>{d.stopPropagation(),o()},children:e.jsx(Y,{className:"size-5"})})}),s&&e.jsx(Ft,{businessTripExpenseId:n,businessTripId:r,opened:s,close:a,onChange:t})]})}function Ft({businessTripExpenseId:i,businessTripId:n,opened:r,close:t,onChange:s}){const{control:a,handleSubmit:o,setValue:d}=S({defaultValues:{businessTripExpenseId:i}}),[m,p]=x.useState([]),[{data:h,fetching:l,error:c}]=re({query:ds,variables:{businessTripId:n}}),{categorizeIntoExistingBusinessTripExpense:u,fetching:g}=St(),f=E=>{u({fields:E}).then(()=>{s?.(),t()})};return x.useEffect(()=>{if(h?.businessTrip?.uncategorizedTransactions.length){const E=h.businessTrip.uncategorizedTransactions.filter(v=>v?.transaction);p(E.map(({transaction:v})=>({eventDate:v.eventDate,sourceDescription:v.sourceDescription,referenceKey:v.referenceKey,counterparty:v.counterparty?.name,amount:v.amount.formatted,rawAmount:v.amount.raw,value:v.id,label:`${v.eventDate} | ${v.counterparty?.name} | ${v.amount.formatted}`})).sort((v,$)=>v.eventDate.localeCompare($.eventDate)))}},[h,p]),x.useEffect(()=>{c&&j.error("Error",{description:"Oops, we have an error fetching transactions to categorize"})},[c]),e.jsxs(C,{opened:r,onClose:t,centered:!0,children:[e.jsx(C.Title,{children:"Set Transaction Category"}),e.jsx(C.Body,{children:e.jsxs("form",{onSubmit:o(f),className:"flex flex-col gap-3 mt-3",children:[e.jsx(y,{name:"transactionId",control:a,render:({field:E,fieldState:v})=>e.jsx(G,{...E,itemComponent:Mt,data:m??[],disabled:l,label:"Transactions",placeholder:"Scroll to see all options",maxDropdownHeight:160,error:v.error?.message,withAsterisk:!0,withinPortal:!0,onChange:$=>{const H=m.find(_=>_.value===$);H?.rawAmount&&d("amount",H.rawAmount),E.onChange($)}})}),e.jsx(y,{name:"amount",control:a,render:({field:E,fieldState:v})=>e.jsx(oe,{...E,value:E.value??void 0,hideControls:!0,precision:2,removeTrailingZeros:!0,error:v.error?.message,label:"Amount"})}),e.jsx("div",{className:"flex justify-center 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:"Confirm"})})]})}),g&&e.jsx(K,{blur:1,center:!0,children:e.jsx(X,{})})]})}const Mt=x.forwardRef(({eventDate:i,sourceDescription:n,referenceKey:r,counterparty:t,amount:s,...a},o)=>e.jsx("div",{ref:o,...a,children:e.jsxs(ne,{children:[e.jsx(ne.Col,{span:4,children:i}),e.jsx(ne.Col,{span:4,children:e.jsx(D,{size:"sm",children:t})}),e.jsx(ne.Col,{span:4,children:e.jsx(D,{size:"sm",children:s})}),e.jsx(ne.Col,{span:8,children:e.jsx(D,{size:"xs",opacity:.65,children:n})}),e.jsxs(ne.Col,{span:4,children:["Reference: ",r]})]})})),zt="deleteBusinessTripExpense",Pt=()=>{const[{fetching:i},n]=B(ls),r=x.useCallback(async t=>{const s="Error deleting business trip expense",a=`${zt}-${t.businessTripExpenseId}`;j.loading("Deleting trip expense",{id:a});try{const o=await n(t),d=I(o,s,a);if(d)return j.success("Success",{id:a,description:"Business trip expense was deleted"}),d.deleteBusinessTripExpense}catch(o){console.error(`${s}: ${o}`),j.error("Error",{id:a,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:i,deleteBusinessTripExpense:r}};function le(i){const{fetching:n,deleteBusinessTripExpense:r}=Pt(),t=x.useCallback(()=>{r({businessTripExpenseId:i.businessTripExpenseId}).then(()=>{i.onDelete?.()})},[i,r]);return e.jsx(ke,{onConfirm:t,title:"Are you sure you want to remove expense?",children:e.jsx(w,{label:"Remove Expense",children:e.jsx(b,{variant:"outline",size:"icon",className:"size-7.5 text-red-500",disabled:n,children:e.jsx(Re,{className:"size-5"})})})})}const ue=({data:i,isEditMode:n=!1,control:r,businessTripId:t})=>{const s=A(us,i),[a,o]=x.useState([]),[{data:d,fetching:m,error:p}]=re({query:je,variables:{businessTripId:t}});x.useEffect(()=>{d?.businessTrip?.attendees.length&&o(d.businessTrip.attendees.map(l=>({value:l.id,label:l.name})).sort((l,c)=>l.label>c.label?1:-1))},[d,o]),x.useEffect(()=>{p&&j.error("Error",{description:"Oops, we have an error fetching attendees"})},[p]);const h=Array.from(new Set(s.charges?.map(l=>l.id)));return e.jsxs(e.Fragment,{children:[e.jsx("td",{children:e.jsx("div",{className:"flex flex-col gap-2 justify-center",children:n&&s.payedByEmployee?e.jsxs(e.Fragment,{children:[e.jsx(y,{name:"date",control:r,defaultValue:s.date,rules:{pattern:{value:W,message:"Date must be im format yyyy-mm-dd"}},render:({field:l,fieldState:c})=>e.jsx(q,{...l,form:`form ${s.id}`,"data-autofocus":!0,onChange:u=>{const g=u?typeof u=="string"?u:F(u,"yyyy-MM-dd"):void 0;g!==l.value&&l.onChange(g)},value:l.value?new Date(l.value):void 0,label:"Date",error:c.error?.message,popoverProps:{withinPortal:!0}})}),e.jsx(y,{name:"valueDate",control:r,defaultValue:s.valueDate,rules:{pattern:{value:W,message:"Date must be im format yyyy-mm-dd"}},render:({field:l,fieldState:c})=>e.jsx(q,{...l,form:`form ${s.id}`,onChange:u=>{const g=u?typeof u=="string"?u:F(u,"yyyy-MM-dd"):void 0;g!==l.value&&l.onChange(g)},value:l.value?new Date(l.value):void 0,label:"Value Date",error:c.error?.message,popoverProps:{withinPortal:!0}})})]}):e.jsxs(e.Fragment,{children:[s.date&&F(new Date(s.date),"dd/MM/yy"),e.jsx(D,{fz:"sm",c:"dimmed",children:s.valueDate&&F(new Date(s.valueDate),"dd/MM/yy")})]})})}),e.jsx("td",{children:n&&s.payedByEmployee?e.jsx(y,{name:"amount",control:r,defaultValue:s.amount?.raw??void 0,render:({field:l,fieldState:c})=>e.jsx(y,{name:"currency",control:r,defaultValue:s.amount?.currency??Pe.Ils,render:({field:u,fieldState:g})=>e.jsx($e,{form:`form ${s.id}`,...l,value:l.value??void 0,error:c.error?.message||g.error?.message,label:"Amount",currencyCodeProps:{...u,label:"Currency",form:`form ${s.id}`}})})}):e.jsx("div",{children:s.amount?.formatted})}),e.jsx("td",{children:e.jsx("div",{className:"flex flex-col gap-2 justify-center",children:n&&s.payedByEmployee?e.jsx(y,{name:"employeeBusinessId",control:r,defaultValue:s.employee?.id,render:({field:l,fieldState:c})=>e.jsx(G,{form:`form ${s.id}`,...l,data:a,value:l.value,disabled:m,label:"Attendee",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:c.error?.message,withinPortal:!0})}):e.jsx("div",{className:"flex flex-row gap-2 items-center",children:s.payedByEmployee&&e.jsx(D,{c:s.employee?.name?void 0:"red",children:s.employee?.name??"Missing"})})})}),e.jsx("td",{children:e.jsx("div",{className:"flex flex-col gap-2",children:h.map(l=>e.jsx(Ce,{to:He(l),target:"_blank",rel:"noreferrer",onClick:c=>c.stopPropagation(),className:"inline-flex items-center font-semibold",children:"To Charge"},l))})})]})},he=()=>e.jsxs(e.Fragment,{children:[e.jsx("th",{children:"Date"}),e.jsx("th",{children:"Amount"}),e.jsx("th",{children:"Payed By Attendee"}),e.jsx("th",{children:"Charges"})]}),$t=({data:i,businessTripId:n,onChange:r})=>{const t=A(hs,i),[s,a]=x.useState(!1),o=S({defaultValues:{id:t.id,businessTripId:n,attendeesStay:t.attendeesStay.map(c=>({attendeeId:c.id,nightsCount:c.nightsCount}))}}),{control:d,handleSubmit:m}=o,{updateBusinessTripAccommodationsExpense:p,fetching:h}=It(),l=c=>{p({fields:c}).then(()=>{r?.(),a(!1)})};return e.jsxs("tr",{children:[e.jsx(ue,{data:t,isEditMode:s,control:d,businessTripId:n}),e.jsx("td",{children:e.jsx(N,{...o,children:e.jsx("form",{id:`form ${t.id}`,onSubmit:m(l),children:s?e.jsx(M,{name:"country",control:d,defaultValue:t.country,render:({field:c})=>e.jsxs(z,{children:[e.jsx(P,{children:e.jsx(J,{form:`form ${t.id}`,...c,value:c.value??void 0})}),e.jsx(R,{})]})}):e.jsx(D,{c:t.country?void 0:"red",children:t.country??"Missing"})})})}),e.jsx("td",{children:e.jsx("div",{className:"flex flex-col gap-2 justify-center",children:s?e.jsx(N,{...o,children:e.jsx(M,{name:"nightsCount",control:d,defaultValue:t.nightsCount,render:({field:c})=>e.jsxs(z,{children:[e.jsx(P,{children:e.jsx(Oe,{...c,value:c.value??void 0,form:`form ${t.id}`,hideControls:!0,decimalScale:0,thousandSeparator:","})}),e.jsx(R,{})]})})}):e.jsx(D,{c:t.nightsCount?void 0:"red",children:t.nightsCount??"Missing"})})}),e.jsx("td",{children:s?e.jsx(N,{...o,children:e.jsx(Ge,{formManager:o,attendeesStayPath:"attendeesStay",businessTripId:n})}):e.jsx(me,{listStyleType:"disc",children:t.attendeesStay?.length?t.attendeesStay.map(c=>e.jsxs(me.Item,{children:[c.attendee.name," (",c.nightsCount,")"]},c.id)):e.jsx(D,{c:"red",fz:"sm",children:"Missing"})})}),e.jsx("td",{children:r&&e.jsxs(e.Fragment,{children:[e.jsx(w,{label:"Edit",children:e.jsx(b,{disabled:h,variant:s?"default":"outline",size:"icon",className:"size-7.5",onClick:c=>{c.stopPropagation(),a(u=>!u)},children:e.jsx(ee,{className:"size-5"})})}),s&&e.jsx(w,{label:"Confirm Changes",children:e.jsx(b,{type:"submit",form:`form ${t.id}`,variant:"outline",size:"icon",className:"size-7.5 text-green-500",children:e.jsx(se,{className:"size-5"})})}),e.jsx(de,{businessTripExpenseId:t.id,businessTripId:n,onChange:r}),e.jsx(le,{businessTripExpenseId:t.id,onDelete:r})]})})]},t.id)},Ye=({businessTripId:i,expenses:n,onChange:r})=>{if(!n?.length)return r?e.jsx(Ae,{businessTripId:i,onAdd:r}):e.jsx(e.Fragment,{});const t=n.map(s=>A(xs,s));return e.jsx("div",{className:"flex flex-col gap-2 mt-5",children:e.jsxs(te,{highlightOnHover:!0,withBorder:!0,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx(he,{}),e.jsx("th",{children:"Location"}),e.jsx("th",{children:"Nights"}),e.jsx("th",{children:"Attendees Stay"}),e.jsx("th",{})]})}),e.jsxs("tbody",{children:[t.sort((s,a)=>s.date&&a.date?s.date<a.date?1:-1:s.date?-1:a.date?1:0).map(s=>e.jsx($t,{data:s,businessTripId:i,onChange:r},s.id)),r&&e.jsx("tr",{children:e.jsx("td",{colSpan:6,children:e.jsx(Ae,{businessTripId:i,onAdd:r})})})]})]})})},Ot=({data:i,onChange:n})=>{const{accommodationExpenses:r,id:t}=A(ps,i);return e.jsx(Ye,{businessTripId:t,expenses:r,onChange:n})},kt="insertBusinessTripAttendee",Rt=()=>{const[{fetching:i},n]=B(ms),r=x.useCallback(async t=>{const s="Error adding attendee to business trip",a=kt;j.loading("Adding attendee",{id:a});try{const o=await n(t),d=I(o,s,a);if(d)return j.success("Success",{id:a,description:"Attendee was added to the business trip"}),d.insertBusinessTripAttendee}catch(o){console.error(`${s}: ${o}`),j.error("Error",{id:a,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:i,insertBusinessTripAttendee:r}};function we(i){const{businessTripId:n,onAdd:r}=i,[t,{close:s,open:a}]=U(!1);return e.jsxs(e.Fragment,{children:[e.jsx(w,{label:"Add Attendee",children:e.jsx(b,{variant:"outline",size:"icon",onClick:o=>{o.stopPropagation(),a()},className:"size-7.5",children:e.jsx(Y,{className:"size-5"})})}),t&&e.jsx(Ht,{businessTripId:n,opened:t,close:s,onAdd:r})]})}function Ht({businessTripId:i,opened:n,close:r,onAdd:t}){const{selectableBusinesses:s,fetching:a}=_e(),{control:o,handleSubmit:d}=S({defaultValues:{businessTripId:i}}),{insertBusinessTripAttendee:m,fetching:p}=Rt(),h=l=>{m({fields:l}).then(()=>{t?.(),r()})};return e.jsxs(C,{opened:n,onClose:r,centered:!0,children:[e.jsx(C.Title,{children:"Add Attendee"}),e.jsx(C.Body,{children:e.jsxs("form",{onSubmit:d(h),children:[e.jsx(y,{name:"attendeeId",control:o,render:({field:l,fieldState:c})=>e.jsx(G,{"data-autofocus":!0,...l,data:s,value:l.value,disabled:a,label:"Attendee",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:c.error?.message,withAsterisk:!0,withinPortal:!0})}),e.jsx(y,{name:"arrivalDate",control:o,rules:{pattern:{value:W,message:"Date must be im format yyyy-mm-dd"}},render:({field:l,fieldState:c})=>e.jsx(q,{...l,onChange:u=>{const g=u?typeof u=="string"?u:F(u,"yyyy-MM-dd"):void 0;g!==l.value&&l.onChange(g)},value:l.value?new Date(l.value):void 0,error:c.error?.message,label:"Arrival",popoverProps:{withinPortal:!0}})}),e.jsx(y,{name:"departureDate",control:o,rules:{pattern:{value:W,message:"Date must be im format yyyy-mm-dd"}},render:({field:l,fieldState:c})=>e.jsx(q,{...l,onChange:u=>{const g=u?typeof u=="string"?u:F(u,"yyyy-MM-dd"):void 0;g!==l.value&&l.onChange(g)},value:l.value?new Date(l.value):void 0,error:c.error?.message,label:"Departure",popoverProps:{withinPortal:!0}})}),e.jsx("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:"Add"})})]})}),(p||a)&&e.jsx(K,{blur:1,center:!0,children:e.jsx(X,{})})]})}const _t="updateBusinessTripAttendee",Vt=()=>{const[{fetching:i},n]=B(gs),r=x.useCallback(async t=>{const s="Error updating business trip attendee",a=_t;j.loading("Updating trip attendee",{id:a});try{const o=await n(t),d=I(o,s,a);if(d)return j.success("Success",{id:a,description:"Business trip attendee was updated"}),d.updateBusinessTripAttendee}catch(o){console.error(`${s}: ${o}`),j.error("Error",{id:a,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:i,updateBusinessTripAttendee:r}},Ut="deleteBusinessTripAttendee",Lt=()=>{const[{fetching:i},n]=B(js),r=x.useCallback(async t=>{const s="Error removing business trip attendee",a=Ut;j.loading("Removing business trip attendee",{id:a});try{const o=await n(t),d=I(o,s,a);if(d)return j.success("Success",{id:a,description:"Business trip attendee was removed"}),d.deleteBusinessTripAttendee}catch(o){console.error(`${s}: ${o}`),j.error("Error",{id:a,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:i,deleteBusinessTripAttendee:r}};function Wt(i){const{fetching:n,deleteBusinessTripAttendee:r}=Lt(),t=x.useCallback(()=>{r({fields:{businessTripId:i.businessTripId,attendeeId:i.attendeeId}}).then(()=>{i.onDelete?.()})},[i,r]);return e.jsx(ke,{onConfirm:t,title:"Are you sure you want to remove attendee?",children:e.jsx(w,{label:"Remove Attendee",children:e.jsx(b,{variant:"outline",size:"icon",className:"size-7.5 text-red-500",disabled:n,children:e.jsx(Re,{className:"size-5"})})})})}const qt="addBusinessTripFlightsExpense",Gt=()=>{const[{fetching:i},n]=B(fs),r=x.useCallback(async t=>{const s="Error adding business trip flight expense",a=qt;j.loading("Adding business trip flight expense",{id:a});try{const o=await n(t),d=I(o,s,a);if(d)return j.success("Success",{id:a,description:"Business trip flight expense added"}),d.addBusinessTripFlightsExpense}catch(o){console.error(`${s}: ${o}`),j.error("Error",{id:a,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:i,addBusinessTripFlightsExpense:r}};function Ke({formManager:i,flightPathPath:n,flightPathData:r}){const{control:t,watch:s,trigger:a}=i,{fields:o,append:d,remove:m}=Fe({control:t,name:n}),p=s(n),h=o.map((l,c)=>({...l,...p[c]}));return r?e.jsxs("div",{children:[e.jsx("span",{className:"mantine-InputWrapper-label mantine-Select-label",children:"Flight Path"}),e.jsxs("div",{className:"h-full flex flex-col overflow-hidden",children:[h?.map((l,c)=>e.jsxs("div",{className:"flex items-end gap-2 text-gray-600 mb-2",children:[e.jsx("div",{className:"w-full mt-1 relative rounded-md shadow-xs",children:e.jsx(M,{name:`${n}.${c}`,control:t,rules:{required:"Required"},render:({field:u})=>e.jsxs(z,{children:[e.jsx(P,{children:e.jsx(J,{...u,value:u.value??void 0,placeholder:"Destination"})}),e.jsx(R,{})]})})}),e.jsx(b,{variant:"ghost",size:"icon",className:"mb-2 size-7.5",onClick:()=>{m(c),a(n)},children:e.jsx(Me,{className:"size-5"})})]},l.id)),e.jsx(b,{variant:"ghost",size:"icon",className:"size-7.5",onClick:()=>{d(""),a(n)},children:e.jsx(ze,{className:"size-5"})})]})]}):e.jsx("div",{children:"Cannot edit flight path stay, lacking some mandatory information!"})}function De(i){const{businessTripId:n,onAdd:r}=i,[t,{close:s,open:a}]=U(!1);return e.jsxs(e.Fragment,{children:[e.jsx(w,{label:"Add Flight Expense",children:e.jsx(b,{variant:"outline",size:"icon",className:"size-7.5",onClick:o=>{o.stopPropagation(),a()},children:e.jsx(Y,{className:"size-5"})})}),t&&e.jsx(Kt,{businessTripId:n,opened:t,close:s,onAdd:r})]})}const Yt=Object.entries(Ue).map(([i,n])=>({value:n,label:i}));function Kt({businessTripId:i,opened:n,close:r,onAdd:t}){const s=S({defaultValues:{businessTripId:i}}),{control:a,handleSubmit:o}=s,[d,m]=x.useState(!1),[{data:p,fetching:h}]=re({query:je,variables:{businessTripId:i}}),{addBusinessTripFlightsExpense:l,fetching:c}=Gt(),u=f=>{l({fields:f}).then(()=>{t?.(),r()})},g=p?.businessTrip?.attendees.map(f=>({value:f.id,label:f.name}))??[];return e.jsxs(C,{opened:n,onClose:r,centered:!0,lockScroll:!0,children:[e.jsx(C.Title,{children:"Add Flight Expense"}),e.jsx(C.Body,{children:e.jsx(N,{...s,children:e.jsxs("form",{onSubmit:o(u),children:[e.jsx(ce,{businessTripId:i,control:a,setFetching:m}),e.jsx(Ke,{formManager:s,flightPathPath:"path"}),e.jsx(y,{name:"flightClass",control:a,render:({field:f,fieldState:E})=>e.jsx(G,{...f,data:Yt,value:f.value,label:"Flight Class",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:E.error?.message,withinPortal:!0})}),e.jsx(y,{name:"attendeeIds",control:a,render:({field:f,fieldState:E})=>e.jsx(Ve,{...f,disabled:h,data:g,value:f.value??[],label:"Attendees",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:E.error?.message,withinPortal:!0})}),e.jsx("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:"Add"})})]})})}),(c||d)&&e.jsx(K,{blur:1,center:!0,children:e.jsx(X,{})})]})}const Xt="updateBusinessTripFlightsExpense",Zt=()=>{const[{fetching:i},n]=B(vs),r=x.useCallback(async t=>{const s="Error updating business trip flights expense",a=Xt;j.loading("Updating trip flights expense",{id:a});try{const o=await n(t),d=I(o,s,a);if(d)return j.success("Success",{id:a,description:"Business trip flights expense was updated"}),d.updateBusinessTripFlightsExpense}catch(o){console.error(`${s}: ${o}`),j.error("Error",{id:a,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:i,updateBusinessTripFlightsExpense:r}},Qt=Object.entries(Ue).map(([i,n])=>({value:n,label:i})),Jt=({data:i,businessTripId:n,onChange:r,attendees:t})=>{const s=A(bs,i),[a,o]=x.useState(!1),d=S({defaultValues:{id:s.id,businessTripId:n,attendeeIds:s.attendees?.map(g=>g.id)??[],path:s.path??[]}}),{control:m,handleSubmit:p}=d,{updateBusinessTripFlightsExpense:h,fetching:l}=Zt(),c=g=>{h({fields:g}).then(()=>{r?.(),o(!1)})},u=t.map(g=>({value:g.id,label:g.name}));return e.jsxs("tr",{children:[e.jsx(ue,{data:s,isEditMode:a,control:m,businessTripId:n}),e.jsx("td",{children:e.jsx(N,{...d,children:e.jsx("form",{id:`form ${s.id}`,onSubmit:p(c),children:e.jsxs("div",{className:"flex flex-col gap-2 justify-center",children:[a?e.jsx(Ke,{formManager:d,flightPathPath:"path",flightPathData:s.path??void 0}):e.jsx("div",{className:"flex gap-2 items-center",children:s.path?.length?s.path.map((g,f)=>e.jsxs(e.Fragment,{children:[e.jsx(D,{fw:700,children:g},f),f<s.path.length-1&&(g===s.path[f+1]?" | ":" → ")]})):e.jsx(D,{fw:700,className:"flex gap-2 items-center",c:"red",children:"Missing"})}),a?e.jsx(y,{name:"flightClass",control:m,defaultValue:s.class??void 0,render:({field:g,fieldState:f})=>e.jsx(G,{form:`form ${s.id}`,"data-autofocus":!0,...g,data:Qt,value:g.value,label:"Flight Class",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:f.error?.message,withinPortal:!0})}):e.jsx(D,{c:s.class?void 0:"red",fz:"sm",children:`Class: ${s.class??"Missing"}`})]})})})}),e.jsx("td",{children:a?e.jsx(y,{name:"attendeeIds",control:m,defaultValue:s.attendees?.map(g=>g.id)??void 0,render:({field:g,fieldState:f})=>e.jsx(Ve,{...g,form:`form ${s.id}`,data:u,value:g.value??[],label:"Attendees",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:f.error?.message,withinPortal:!0})}):e.jsx(me,{listStyleType:"disc",children:s.attendees?.length?s.attendees.map(g=>e.jsx(me.Item,{children:g.name},g.id)):e.jsx(D,{c:"red",fz:"sm",children:"Missing"})})}),e.jsx("td",{children:r&&e.jsxs(e.Fragment,{children:[e.jsx(w,{label:"Edit",children:e.jsx(b,{disabled:l,variant:a?"default":"outline",size:"icon",className:"size-7.5",onClick:g=>{g.stopPropagation(),o(f=>!f)},children:e.jsx(ee,{className:"size-5"})})}),a&&e.jsx(w,{label:"Confirm Changes",children:e.jsx(b,{type:"submit",form:`form ${s.id}`,variant:"outline",size:"icon",className:"size-7.5 text-green-500",children:e.jsx(se,{className:"size-5"})})}),e.jsx(de,{businessTripExpenseId:s.id,businessTripId:n,onChange:r}),e.jsx(le,{businessTripExpenseId:s.id,onDelete:r})]})})]},s.id)},Xe=({businessTripId:i,expenses:n,attendees:r,onChange:t})=>{if(!n?.length)return t?e.jsx(De,{businessTripId:i,onAdd:t}):e.jsx(e.Fragment,{});const s=n.map(a=>A(ys,a));return e.jsx("div",{className:"flex flex-col gap-2 mt-5",children:e.jsxs(te,{highlightOnHover:!0,withBorder:!0,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx(he,{}),e.jsx("th",{children:"Flight"}),e.jsx("th",{children:"Attendees"}),e.jsx("th",{})]})}),e.jsxs("tbody",{children:[s.sort((a,o)=>a.date&&o.date?a.date<o.date?1:-1:a.date?-1:o.date?1:0).map(a=>e.jsx(Jt,{data:a,businessTripId:i,onChange:t,attendees:r},a.id)),t&&e.jsx("tr",{children:e.jsx("td",{colSpan:5,children:e.jsx(De,{businessTripId:i,onAdd:t})})})]})]})})},en=({data:i,businessTripId:n,onChange:r})=>{const t=A(Cs,i),[s,a]=x.useState(!1),[o,d]=x.useState(!1),{control:m,handleSubmit:p}=S({defaultValues:{businessTripId:n,attendeeId:t.id,arrivalDate:t.arrivalDate,departureDate:t.departureDate}}),{updateBusinessTripAttendee:h,fetching:l}=Vt(),c=u=>{h({fields:u}).then(()=>{r?.(),a(!1)})};return e.jsxs(e.Fragment,{children:[e.jsxs("tr",{children:[e.jsx("td",{children:t.name}),e.jsx("td",{children:s?e.jsx("form",{id:`form ${t.id}`,onSubmit:p(c),children:e.jsx(y,{name:"arrivalDate",control:m,defaultValue:t.arrivalDate,rules:{pattern:{value:W,message:"Date must be im format yyyy-mm-dd"}},render:({field:u,fieldState:g})=>e.jsx(q,{...u,onChange:f=>{const E=f?typeof f=="string"?f:F(f,"yyyy-MM-dd"):void 0;E!==u.value&&u.onChange(E)},"data-autofocus":!0,value:u.value?new Date(u.value):void 0,error:g.error?.message,label:"Arrival",popoverProps:{withinPortal:!0}})})}):t.arrivalDate}),e.jsx("td",{children:s?e.jsx(y,{name:"departureDate",control:m,defaultValue:t.departureDate,rules:{pattern:{value:W,message:"Date must be im format yyyy-mm-dd"}},render:({field:u,fieldState:g})=>e.jsx(q,{...u,onChange:f=>{const E=f?typeof f=="string"?f:F(f,"yyyy-MM-dd"):void 0;E!==u.value&&u.onChange(E)},value:u.value?new Date(u.value):void 0,error:g.error?.message,label:"Departure",popoverProps:{withinPortal:!0}})}):t.departureDate}),e.jsxs("td",{className:"flex items-center gap-2",children:[e.jsx(w,{label:"Edit",children:e.jsx(b,{disabled:l,variant:s?"default":"outline",size:"icon",className:"size-7.5",onClick:u=>{u.stopPropagation(),a(g=>!g)},children:e.jsx(ee,{className:"size-5"})})}),s&&e.jsx(w,{label:"Confirm Changes",children:e.jsx(b,{type:"submit",form:`form ${t.id}`,variant:"outline",size:"icon",className:"size-7.5 text-green-500",children:e.jsx(se,{className:"size-5"})})}),e.jsx(Wt,{businessTripId:n,attendeeId:t.id,onDelete:r}),e.jsx(Ts,{toggleExpansion:d,isExpanded:o})]})]},t.id),o&&e.jsx("tr",{children:e.jsx("td",{colSpan:4,children:e.jsx(Le,{shadow:"sm",withBorder:!0,children:e.jsxs("div",{className:"flex flex-col gap-2",children:[t.flights&&e.jsxs(e.Fragment,{children:[e.jsx("div",{children:"Flights:"}),e.jsx(Xe,{businessTripId:n,attendees:[],expenses:t.flights})]}),t.accommodations&&e.jsxs(e.Fragment,{children:[e.jsx("div",{children:"Accommodations:"}),e.jsx(Ye,{businessTripId:n,expenses:t.accommodations})]})]})})})},`${t.id}-expension`)]})},sn=({data:i,onChange:n})=>{const{attendees:r,id:t}=A(Es,i);return r?.length?e.jsx("div",{className:"flex flex-col gap-2 mt-5",children:e.jsxs(te,{highlightOnHover:!0,withBorder:!0,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Name"}),e.jsx("th",{children:"Arrival Date"}),e.jsx("th",{children:"Departure Date"}),e.jsx("th",{})]})}),e.jsxs("tbody",{children:[r.sort((s,a)=>s.name.toLocaleLowerCase()>a.name.toLocaleLowerCase()?1:-1).map(s=>e.jsx(en,{data:s,businessTripId:t,onChange:n},s.id)),e.jsx("tr",{children:e.jsx("td",{colSpan:4,children:e.jsx(we,{businessTripId:t,onAdd:n})})})]})]})}):e.jsx(we,{businessTripId:t,onAdd:n})},pe="addBusinessTripCarRentalExpense",tn=()=>{const[{fetching:i},n]=B(As),r=x.useCallback(async t=>{const s="Error adding business trip car rental expense";j.loading("Adding car rental expense...",{id:pe});try{const a=await n(t),o=I(a,s,pe);if(o)return j.success("Success",{id:pe,description:"Car rental expense added"}),o.addBusinessTripCarRentalExpense}catch(a){console.error(`${s}: ${a}`),j.error("Error",{id:pe,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:i,addBusinessTripCarRentalExpense:r}};function Be(i){const{businessTripId:n,onAdd:r}=i,[t,{close:s,open:a}]=U(!1);return e.jsxs(e.Fragment,{children:[e.jsx(w,{label:"Add Car Rental Expense",children:e.jsx(b,{variant:"outline",size:"icon",onClick:o=>{o.stopPropagation(),a()},className:"size-7.5",children:e.jsx(Y,{className:"size-5"})})}),t&&e.jsx(nn,{businessTripId:n,opened:t,close:s,onAdd:r})]})}function nn({businessTripId:i,opened:n,close:r,onAdd:t}){const s=S({defaultValues:{businessTripId:i}}),{control:a,handleSubmit:o}=s,[d,m]=x.useState(!1),{addBusinessTripCarRentalExpense:p,fetching:h}=tn(),l=c=>{p({fields:c}).then(()=>{t?.(),r()})};return e.jsxs(C,{opened:n,onClose:r,centered:!0,lockScroll:!0,children:[e.jsx(C.Title,{children:"Add Car Rental Expense"}),e.jsx(C.Body,{children:e.jsx(N,{...s,children:e.jsxs("form",{onSubmit:o(l),children:[e.jsx(ce,{businessTripId:i,control:a,setFetching:m}),e.jsx(y,{name:"days",control:a,render:({field:c,fieldState:u})=>e.jsx(oe,{...c,value:c.value??void 0,hideControls:!0,precision:2,removeTrailingZeros:!0,error:u.error?.message,label:"Rent Days"})}),e.jsx(M,{name:"isFuelExpense",control:a,render:({field:{value:c,...u}})=>e.jsxs(z,{className:"flex flex-row items-center justify-between rounded-lg border p-3 shadow-sm",children:[e.jsx("div",{className:"space-y-0.5",children:e.jsx(Q,{children:"Is Fuel Expense"})}),e.jsx(P,{children:e.jsx(fe,{...u,checked:c===!0,onCheckedChange:u.onChange})}),e.jsx(R,{})]})}),e.jsx("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:"Add"})})]})})}),(h||d)&&e.jsx(K,{blur:1,center:!0,children:e.jsx(X,{})})]})}const rn="updateBusinessTripCarRentalExpense",an=()=>{const[{fetching:i},n]=B(ws),r=x.useCallback(async t=>{const s="Error updating business trip car rental expense",a=rn;j.loading("Updating trip car rental expense",{id:a});try{const o=await n(t),d=I(o,s,a);if(d)return j.success("Success",{id:a,description:"Business trip car rental expense was updated"}),d.updateBusinessTripCarRentalExpense}catch(o){console.error(`${s}: ${o}`),j.error("Error",{id:a,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:i,updateBusinessTripCarRentalExpense:r}},on=({data:i,businessTripId:n,onChange:r})=>{const t=A(Ds,i),[s,a]=x.useState(!1),o=S({defaultValues:{id:t.id,businessTripId:n}}),{control:d,handleSubmit:m}=o,{updateBusinessTripCarRentalExpense:p,fetching:h}=an(),l=c=>{p({fields:c}).then(()=>{r?.(),a(!1)})};return e.jsxs("tr",{children:[e.jsx(ue,{data:t,isEditMode:s,control:d,businessTripId:n}),e.jsx("td",{children:e.jsx(N,{...o,children:e.jsx("form",{id:`form ${t.id}`,onSubmit:m(l),children:e.jsx("div",{className:"flex flex-col gap-2 justify-center",children:t.isFuelExpense!==!0&&(s?e.jsx(y,{name:"days",control:d,defaultValue:t.days,render:({field:c,fieldState:u})=>e.jsx(oe,{...c,value:c.value??void 0,form:`form ${t.id}`,hideControls:!0,precision:2,removeTrailingZeros:!0,error:u.error?.message,placeholder:"Rent Days"})}):e.jsx(D,{c:t.days?void 0:"red",children:t.days??"Missing"}))})})})}),e.jsx("td",{children:s?e.jsx(N,{...o,children:e.jsx(M,{name:"isFuelExpense",control:d,defaultValue:t.isFuelExpense,render:({field:c})=>e.jsxs(z,{className:"flex flex-row items-center justify-between rounded-lg border p-3 shadow-sm",children:[e.jsx("div",{className:"space-y-0.5",children:e.jsx(Q,{children:"Is Fuel Expense"})}),e.jsx(P,{children:e.jsx(fe,{form:`form ${t.id}`,checked:c.value===!0,onCheckedChange:c.onChange})})]})})}):t.isFuelExpense===!0?e.jsx(dt,{}):e.jsx(ot,{})}),e.jsxs("td",{children:[e.jsx(w,{label:"Edit",children:e.jsx(b,{disabled:h,variant:s?"default":"outline",size:"icon",className:"size-7.5",onClick:c=>{c.stopPropagation(),a(u=>!u)},children:e.jsx(ee,{className:"size-5"})})}),s&&e.jsx(w,{label:"Confirm Changes",children:e.jsx(b,{type:"submit",form:`form ${t.id}`,variant:"outline",size:"icon",className:"size-7.5 text-green-500",children:e.jsx(se,{className:"size-5"})})}),e.jsx(de,{businessTripExpenseId:t.id,businessTripId:n,onChange:r}),e.jsx(le,{businessTripExpenseId:t.id,onDelete:r})]})]},t.id)},cn=({data:i,onChange:n})=>{const{carRentalExpenses:r,id:t}=A(Bs,i);return r?.length?e.jsx("div",{className:"flex flex-col gap-2 mt-5",children:e.jsxs(te,{highlightOnHover:!0,withBorder:!0,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx(he,{}),e.jsx("th",{children:"Days"}),e.jsx("th",{children:"Type"}),e.jsx("th",{})]})}),e.jsxs("tbody",{children:[r.sort((s,a)=>s.date&&a.date?s.date<a.date?1:-1:s.date?-1:a.date?1:0).map(s=>e.jsx(on,{data:s,businessTripId:t,onChange:n},s.id)),e.jsx("tr",{children:e.jsx("td",{colSpan:6,children:e.jsx(Be,{businessTripId:t,onAdd:n})})})]})]})}):e.jsx(Be,{businessTripId:t,onAdd:n})},dn=({data:i,onChange:n})=>{const{flightExpenses:r,id:t,attendees:s}=A(Is,i);return e.jsx(Xe,{businessTripId:t,attendees:s,expenses:r,onChange:n})},ln="addBusinessTripOtherExpense",un=()=>{const[{fetching:i},n]=B(Ns),r=x.useCallback(async t=>{const s='Error adding business trip "other" expense',a=ln;j.loading('Adding trip "other" expense',{id:a});try{const o=await n(t),d=I(o,s,a);if(d)return j.success("Success",{id:a,description:'Business trip "other" expense was added'}),d.addBusinessTripOtherExpense}catch(o){console.error(`${s}: ${o}`),j.error("Error",{id:a,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:i,addBusinessTripOtherExpense:r}};function Ie(i){const{businessTripId:n,onAdd:r}=i,[t,{close:s,open:a}]=U(!1);return e.jsxs(e.Fragment,{children:[e.jsx(w,{label:"Add Other Expense",children:e.jsx(b,{variant:"outline",size:"icon",className:"size-7.5",onClick:o=>{o.stopPropagation(),a()},children:e.jsx(Y,{className:"size-5"})})}),t&&e.jsx(hn,{businessTripId:n,opened:t,close:s,onAdd:r})]})}function hn({businessTripId:i,opened:n,close:r,onAdd:t}){const s=S({defaultValues:{businessTripId:i}}),{control:a,handleSubmit:o}=s,[d,m]=x.useState(!1),{addBusinessTripOtherExpense:p,fetching:h}=un(),l=c=>{p({fields:c}).then(()=>{t?.(),r()})};return e.jsxs(C,{opened:n,onClose:r,centered:!0,lockScroll:!0,children:[e.jsx(C.Title,{children:"Add Other Expense"}),e.jsx(C.Body,{children:e.jsx(N,{...s,children:e.jsxs("form",{onSubmit:o(l),className:"space-y-3",children:[e.jsx(ce,{businessTripId:i,control:a,setFetching:m}),e.jsx(M,{name:"description",control:a,render:({field:c})=>e.jsxs(z,{children:[e.jsx(Q,{children:"Description"}),e.jsx(P,{children:e.jsx(J,{...c,value:c.value??void 0})}),e.jsx(R,{})]})}),e.jsx(M,{control:s.control,name:"deductibleExpense",render:({field:c})=>e.jsxs(z,{className:"flex flex-row items-center justify-between rounded-lg border p-3 shadow-sm",children:[e.jsx("div",{className:"space-y-0.5",children:e.jsx(Q,{children:"Deductible Expense"})}),e.jsx(P,{children:e.jsx(fe,{checked:c.value===!0,onCheckedChange:c.onChange})})]})}),e.jsx("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:"Add"})})]})})}),(h||d)&&e.jsx(K,{blur:1,center:!0,children:e.jsx(X,{})})]})}const xn="updateBusinessTripOtherExpense",pn=()=>{const[{fetching:i},n]=B(Ss),r=x.useCallback(async t=>{const s='Error updating business trip "other" expense',a=xn;j.loading('Updating business trip "other" expense',{id:a});try{const o=await n(t),d=I(o,s,a);if(d)return j.success("Success",{id:a,description:'Business trip "other" expense was updated'}),d.updateBusinessTripOtherExpense}catch(o){console.error(`${s}: ${o}`),j.error("Error",{id:a,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:i,updateBusinessTripOtherExpense:r}},mn=({data:i,businessTripId:n,onChange:r})=>{const t=A(Fs,i),[s,a]=x.useState(!1),o=S({defaultValues:{id:t.id,businessTripId:n}}),{control:d,handleSubmit:m}=o,{updateBusinessTripOtherExpense:p,fetching:h}=pn(),l=c=>{p({fields:c}).then(()=>{r?.(),a(!1)})};return e.jsxs("tr",{children:[e.jsx(ue,{data:t,isEditMode:s,control:d,businessTripId:n}),e.jsx("td",{children:e.jsx(N,{...o,children:e.jsx("form",{id:`form ${t.id}`,onSubmit:m(l),children:s?e.jsx(M,{name:"description",control:d,defaultValue:t.description,render:({field:c})=>e.jsxs(z,{children:[e.jsx(P,{children:e.jsx(J,{form:`form ${t.id}`,...c,value:c.value??void 0})}),e.jsx(R,{})]})}):e.jsx(D,{c:t.description?void 0:"red",children:t.description??"Missing"})})})}),e.jsx("td",{children:e.jsx("div",{className:"flex flex-col gap-2 justify-center",children:s?e.jsx(N,{...o,children:e.jsx(M,{name:"deductibleExpense",control:o.control,defaultValue:t.deductibleExpense,render:({field:c})=>e.jsx(z,{children:e.jsx(P,{children:e.jsx(fe,{form:`form ${t.id}`,checked:c.value===!0,onCheckedChange:c.onChange})})})})}):e.jsx(D,{c:t.deductibleExpense?void 0:"red",children:t.deductibleExpense===!0?"Yes":t.deductibleExpense===!1?"No":"Missing"})})}),e.jsxs("td",{children:[e.jsx(w,{label:"Edit",children:e.jsx(b,{disabled:h,variant:s?"default":"outline",size:"icon",className:"size-7.5",onClick:c=>{c.stopPropagation(),a(u=>!u)},children:e.jsx(ee,{className:"size-5"})})}),s&&e.jsx(w,{label:"Confirm Changes",children:e.jsx(b,{type:"submit",form:`form ${t.id}`,variant:"outline",size:"icon",className:"size-7.5 text-green-500",children:e.jsx(se,{className:"size-5"})})}),e.jsx(de,{businessTripExpenseId:t.id,businessTripId:n,onChange:r}),e.jsx(le,{businessTripExpenseId:t.id,onDelete:r})]})]},t.id)},gn=({data:i,onChange:n})=>{const{otherExpenses:r,id:t}=A(Ms,i);return r?.length?e.jsx("div",{className:"flex flex-col gap-2 mt-5",children:e.jsxs(te,{highlightOnHover:!0,withBorder:!0,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx(he,{}),e.jsx("th",{children:"Description"}),e.jsx("th",{children:"Deductible Expense"}),e.jsx("th",{})]})}),e.jsxs("tbody",{children:[r.sort((s,a)=>s.date&&a.date?s.date<a.date?1:-1:s.date?-1:a.date?1:0).map(s=>e.jsx(mn,{data:s,businessTripId:t,onChange:n},s.id)),e.jsx("tr",{children:e.jsx("td",{colSpan:6,children:e.jsx(Ie,{businessTripId:t,onAdd:n})})})]})]})}):e.jsx(Ie,{businessTripId:t,onAdd:n})},jn="addBusinessTripTravelAndSubsistenceExpense",fn=()=>{const[{fetching:i},n]=B(zs),r=x.useCallback(async t=>{const s="Error adding business trip travel&subsistence expense",a=jn;j.loading("Adding trip travel&subsistence expense",{id:a});try{const o=await n(t),d=I(o,s,a);if(d)return j.success("Success",{id:a,description:"Business trip travel&subsistence expense was added"}),d.addBusinessTripTravelAndSubsistenceExpense}catch(o){console.error(`${s}: ${o}`),j.error("Error",{id:a,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:i,addBusinessTripTravelAndSubsistenceExpense:r}};function Ne(i){const{businessTripId:n,onAdd:r}=i,[t,{close:s,open:a}]=U(!1);return e.jsxs(e.Fragment,{children:[e.jsx(w,{label:"Add T&S Expense",children:e.jsx(b,{variant:"outline",size:"icon",className:"size-7.5",onClick:o=>{o.stopPropagation(),a()},children:e.jsx(Y,{className:"size-5"})})}),t&&e.jsx(vn,{businessTripId:n,opened:t,close:s,onAdd:r})]})}function vn({businessTripId:i,opened:n,close:r,onAdd:t}){const s=S({defaultValues:{businessTripId:i}}),{control:a,handleSubmit:o}=s,[d,m]=x.useState(!1),{addBusinessTripTravelAndSubsistenceExpense:p,fetching:h}=fn(),l=c=>{p({fields:c}).then(()=>{t?.(),r()})};return e.jsxs(C,{opened:n,onClose:r,centered:!0,lockScroll:!0,children:[e.jsx(C.Title,{children:"Add Travel & Subsistence Expense"}),e.jsx(C.Body,{children:e.jsx(N,{...s,children:e.jsxs("form",{onSubmit:o(l),className:"space-y-3",children:[e.jsx(ce,{businessTripId:i,control:a,setFetching:m}),e.jsx(M,{name:"expenseType",control:a,render:({field:c})=>e.jsxs(z,{children:[e.jsx(Q,{children:"Expense Type"}),e.jsx(P,{children:e.jsx(J,{...c,value:c.value??void 0})}),e.jsx(R,{})]})}),e.jsx("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:"Add"})})]})})}),(h||d)&&e.jsx(K,{blur:1,center:!0,children:e.jsx(X,{})})]})}const bn="updateBusinessTripTravelAndSubsistenceExpense",yn=()=>{const[{fetching:i},n]=B(Ps),r=x.useCallback(async t=>{const s="Error updating business trip travel&subsistence expense",a=bn;j.loading("Updating trip travel&subsistence expense",{id:a});try{const o=await n(t),d=I(o,s,a);if(d)return j.success("Success",{id:a,description:"Business trip travel&subsistence expense was updated"}),d.updateBusinessTripTravelAndSubsistenceExpense}catch(o){console.error(`${s}: ${o}`),j.error("Error",{id:a,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:i,updateBusinessTripTravelAndSubsistenceExpense:r}},Tn=({data:i,businessTripId:n,onChange:r})=>{const t=A($s,i),[s,a]=x.useState(!1),o=S({defaultValues:{id:t.id,businessTripId:n}}),{control:d,handleSubmit:m}=o,{updateBusinessTripTravelAndSubsistenceExpense:p,fetching:h}=yn(),l=c=>{p({fields:c}).then(()=>{r?.(),a(!1)})};return e.jsxs("tr",{children:[e.jsx(ue,{data:t,isEditMode:s,control:d,businessTripId:n}),e.jsx("td",{children:e.jsx(N,{...o,children:e.jsx("form",{id:`form ${t.id}`,onSubmit:m(l),children:s?e.jsx(M,{name:"expenseType",control:d,defaultValue:t.expenseType,render:({field:c})=>e.jsxs(z,{children:[e.jsx(P,{children:e.jsx(J,{form:`form ${t.id}`,...c,value:c.value??void 0})}),e.jsx(R,{})]})}):e.jsx(D,{c:t.expenseType?void 0:"red",children:t.expenseType??"Missing"})})})}),e.jsxs("td",{children:[e.jsx(w,{label:"Edit",children:e.jsx(b,{disabled:h,variant:s?"default":"outline",size:"icon",className:"size-7.5",onClick:c=>{c.stopPropagation(),a(u=>!u)},children:e.jsx(ee,{className:"size-5"})})}),s&&e.jsx(w,{label:"Confirm Changes",children:e.jsx(b,{type:"submit",form:`form ${t.id}`,variant:"outline",size:"icon",className:"size-7.5 text-green-500",children:e.jsx(se,{className:"size-5"})})}),e.jsx(de,{businessTripExpenseId:t.id,businessTripId:n,onChange:r}),e.jsx(le,{businessTripExpenseId:t.id,onDelete:r})]})]},t.id)},Cn=({data:i,onChange:n})=>{const{travelAndSubsistenceExpenses:r,id:t}=A(Os,i);return r?.length?e.jsx("div",{className:"flex flex-col gap-2 mt-5",children:e.jsxs(te,{highlightOnHover:!0,withBorder:!0,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx(he,{}),e.jsx("th",{children:"Expense Type"}),e.jsx("th",{})]})}),e.jsxs("tbody",{children:[r.sort((s,a)=>s.date&&a.date?s.date<a.date?1:-1:s.date?-1:a.date?1:0).map(s=>e.jsx(Tn,{data:s,businessTripId:t,onChange:n},s.id)),e.jsx("tr",{children:e.jsx("td",{colSpan:6,children:e.jsx(Ne,{businessTripId:t,onAdd:n})})})]})]})}):e.jsx(Ne,{businessTripId:t,onAdd:n})},En=({data:i})=>{const n=A(ks,i),r="effectiveDate"in n?n.effectiveDate:void 0;return e.jsx("td",{children:e.jsxs("div",{className:"flex flex-col justify-center",children:[e.jsx("div",{children:r&&F(new Date(r),"dd/MM/yy")}),n.sourceEffectiveDate&&e.jsxs("div",{className:"text-xs text-gray-500",children:["(Originally ",F(new Date(n.sourceEffectiveDate),"dd/MM/yy"),")"]})]})})},An=({data:i})=>{const n=A(Rs,i),r="eventDate"in n?n.eventDate:void 0;return e.jsx("td",{children:e.jsx("div",{className:"flex flex-col justify-center",children:r&&F(new Date(r),"dd/MM/yy")})})},wn=({data:i})=>{const n=A(Hs,i),{account:r}=n,t=r.type,s=r.name;return e.jsx("td",{children:e.jsxs("div",{className:"flex flex-col gap-2 items-center",children:[e.jsx("p",{children:t}),e.jsx("p",{children:s})]})})},Dn=({data:i})=>{const n=A(_s,i),r="sourceDescription"in n?n.sourceDescription:"Missing";return e.jsx("td",{children:e.jsx("div",{className:"flex flex-wrap",children:e.jsx("div",{className:"flex flex-col justify-center",children:r})})})},Bn=({data:i})=>{const n=A(Vs,i);return e.jsx("td",{children:e.jsx("div",{className:"flex flex-wrap",children:e.jsx("div",{className:"flex flex-col justify-center",children:n.referenceKey})})})};function In({data:i,onChange:n,enableEdit:r}){const{get:t}=Us(),{id:s,counterparty:a,missingInfoSuggestions:o,id:d,sourceDescription:m}=A(Ls,i),p=!!o?.business&&r,h=p?o?.business?.name:"Missing",l=p?o?.business?.id:null,c=a?.name??h,[u,g]=x.useState(!1),{updateTransaction:f,fetching:E}=Ws(),v=x.useCallback(async Z=>{await f({transactionId:d,fields:{counterpartyId:Z}}),g(!0)},[d,f]),$=x.useCallback(async Z=>{await v(Z),n?.()},[v,n]),H=t("chargesFilters"),_=x.useCallback(Z=>{const be=H?JSON.parse(decodeURIComponent(H)):{};return qs({fromDate:be.fromDate,toDate:be.toDate,ownerIds:be.byOwners,businessIDs:[Z]})},[H]),{selectableBusinesses:O,fetching:L}=_e(),[V,ie]=x.useState(l??null),[ve,Ze]=x.useState(m);return e.jsxs("td",{children:[e.jsx("div",{className:"flex flex-wrap gap-1 items-center justify-center",children:a?.id?e.jsx(Ce,{to:_(a.id),target:"_blank",rel:"noreferrer",onClick:Z=>Z.stopPropagation(),className:"inline-flex items-center font-semibold",children:c}):e.jsxs(e.Fragment,{children:[e.jsx(Gs,{options:O,value:V,onChange:ie,search:ve,onSearchChange:Ze,placeholder:"Choose or create a business",empty:ve?e.jsx(Ys,{description:ve,onAdd:$}):null}),e.jsx(Ks,{content:"Approve",children:e.jsx(b,{variant:"outline",size:"icon",onClick:()=>V&&v(V),disabled:E||L||!V,children:e.jsx(se,{className:"size-4"})})})]})}),e.jsx(Xs,{transactionId:s,counterpartyId:a?.id??V,open:u,onOpenChange:g,onClose:n})]})}const Nn="categorizeBusinessTripExpense",Sn=()=>{const[{fetching:i},n]=B(Zs),r=x.useCallback(async t=>{const s="Error updating business trip expense category",a=Nn;j.loading("Updating trip expense category",{id:a});try{const o=await n(t),d=I(o,s,a);if(d)return j.success("Success",{id:a,description:"Business trip expense category was updated"}),d.categorizeBusinessTripExpense}catch(o){console.error(`${s}: ${o}`),j.error("Error",{id:a,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:i,categorizeBusinessTripExpense:r}};function Fn(i){const{businessTripId:n,transactionId:r,onChange:t,defaultAmount:s}=i,[a,{close:o,open:d}]=U(!1);return e.jsxs(e.Fragment,{children:[e.jsx(w,{label:"Categorize",children:e.jsx(b,{variant:"outline",size:"icon",className:"size-7.5",onClick:m=>{m.stopPropagation(),d()},children:e.jsx(ee,{className:"size-5"})})}),a&&e.jsx(zn,{businessTripId:n,transactionId:r,opened:a,close:o,onChange:t,defaultAmount:s})]})}const Mn=Object.entries(Qs).map(([i,n])=>({value:n,label:i}));function zn({businessTripId:i,transactionId:n,defaultAmount:r,opened:t,close:s,onChange:a}){const{control:o,handleSubmit:d}=S({defaultValues:{businessTripId:i,transactionId:n}}),{categorizeBusinessTripExpense:m,fetching:p}=Sn(),h=l=>{m({fields:l}).then(()=>{a?.(),s()})};return e.jsxs(C,{opened:t,onClose:s,centered:!0,children:[e.jsx(C.Title,{children:"Set Expense Category"}),e.jsx(C.Body,{children:e.jsxs("form",{onSubmit:d(h),className:"flex flex-col gap-3 mt-3",children:[e.jsx(y,{name:"category",control:o,render:({field:l,fieldState:c})=>e.jsx(G,{"data-autofocus":!0,...l,data:Mn,value:l.value,label:"Category",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:c.error?.message,withinPortal:!0})}),e.jsx(y,{name:"amount",control:o,defaultValue:r,render:({field:l,fieldState:c})=>e.jsx(oe,{...l,value:l.value??void 0,hideControls:!0,precision:2,removeTrailingZeros:!0,error:c.error?.message,label:"Amount"})}),e.jsx("div",{className:"flex justify-center 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:"Confirm"})})]})}),p&&e.jsx(K,{blur:1,center:!0,children:e.jsx(X,{})})]})}const Pn=({data:i,onChange:n})=>{const{uncategorizedTransactions:r,id:t}=A(Js,i);return r?.length?e.jsx("div",{className:"flex flex-col gap-2 mt-5",children:e.jsxs(te,{highlightOnHover:!0,withBorder:!0,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Event Date"}),e.jsx("th",{children:"Debit Date"}),e.jsx("th",{children:"Amount"}),e.jsx("th",{}),e.jsx("th",{children:"Account"}),e.jsx("th",{children:"Description"}),e.jsx("th",{children:"Reference#"}),e.jsx("th",{children:"Counterparty"}),e.jsx("th",{})]})}),e.jsx("tbody",{children:r.sort((s,a)=>s.transaction.eventDate.localeCompare(a.transaction.eventDate)).map(s=>e.jsxs("tr",{children:[e.jsx(An,{data:s.transaction}),e.jsx(En,{data:s.transaction}),e.jsx($n,{data:s}),e.jsx("td",{children:e.jsx(Ce,{to:He(s.transaction.chargeId),target:"_blank",rel:"noreferrer",onClick:a=>a.stopPropagation(),className:"inline-flex items-center font-semibold",children:"To Charge"})}),e.jsx(wn,{data:s.transaction}),e.jsx(Dn,{data:s.transaction}),e.jsx(Bn,{data:s.transaction}),e.jsx(In,{data:s.transaction}),e.jsx("td",{children:e.jsx(Fn,{businessTripId:t,transactionId:s.transaction.id,onChange:n,defaultAmount:s.transaction.amount.raw})})]},s.transaction.id))})]})}):e.jsx(e.Fragment,{})},$n=({data:i})=>{const{transaction:n,categorizedAmount:r,errors:t}=A(et,i),s="amount"in n?n.amount:void 0,a=s?.raw!==r.raw&&r.raw!==0;return e.jsx("td",{children:e.jsxs("div",{className:"flex flex-col whitespace-nowrap",style:{color:Number(s?.raw)>0?"green":"red"},children:[e.jsxs("div",{className:"flex gap-1",children:[s?.formatted,t.length>0&&e.jsx(On,{errors:t})]}),a&&e.jsxs("div",{className:"text-gray-500 ml-2",children:[r.formatted," categorized "]}),n.cryptoExchangeRate&&e.jsxs("div",{className:"text-gray-500 ml-2",children:[`(Rate: ${n.cryptoExchangeRate.rate})`,e.jsx("br",{}),s?.raw?`${st(s.raw*n.cryptoExchangeRate.rate)}$`:null]})]})})},On=({errors:i})=>{const[n,{close:r,open:t}]=U(!1);return e.jsxs(ye,{width:200,position:"bottom",shadow:"md",opened:n,children:[e.jsx(ye.Target,{children:e.jsx(tt,{onMouseEnter:t,onMouseLeave:r})}),e.jsx(ye.Dropdown,{sx:{pointerEvents:"none"},className:"whitespace-normal text-red-500",children:i.map((s,a)=>e.jsx(D,{size:"sm",children:s},a))})]})};function Hn({tripId:i,isExtended:n=!1}){const[r,t]=x.useState(),[s,a]=x.useState([]),[{data:o},d]=re({query:nt,variables:{businessTripId:i}});function m(h){s.includes(h)?a(l=>l.filter(c=>c!==h)):a(l=>[...l,h])}const p=d;return x.useEffect(()=>{o?.businessTrip&&t(o.businessTrip)},[o?.businessTrip]),e.jsx(Le,{shadow:"sm",radius:"md",withBorder:!0,children:r?e.jsxs(e.Fragment,{children:[e.jsx(rt,{data:r,onChange:p}),e.jsxs(T,{className:"w-full",multiple:!0,value:s,chevron:e.jsx(Y,{size:"1rem"}),styles:{chevron:{"&[data-rotate]":{transform:"rotate(45deg)"}}},children:[e.jsxs(T.Item,{value:"attendees",children:[e.jsx(T.Control,{onClick:()=>m("attendees"),children:"Attendees"}),e.jsx(T.Panel,{children:e.jsx(sn,{data:r,onChange:p})})]}),n&&e.jsxs(T.Item,{value:"uncategorized-transactions",children:[e.jsx(T.Control,{onClick:()=>m("uncategorized-transactions"),disabled:!r.uncategorizedTransactions?.length,children:"Uncategorized Transactions"}),e.jsx(T.Panel,{children:e.jsx(Pn,{data:r,onChange:p})})]}),e.jsxs(T.Item,{value:"flights",children:[e.jsx(T.Control,{onClick:()=>m("flights"),children:"Flights"}),e.jsx(T.Panel,{children:e.jsx(dn,{data:r,onChange:p})})]}),e.jsxs(T.Item,{value:"accommodations",children:[e.jsx(T.Control,{onClick:()=>m("accommodations"),children:"Accommodations"}),e.jsx(T.Panel,{children:e.jsx(Ot,{data:r,onChange:p})})]}),e.jsxs(T.Item,{value:"travelAndSubsistence",children:[e.jsx(T.Control,{onClick:()=>m("travelAndSubsistence"),children:"Travel & Subsistence"}),e.jsx(T.Panel,{children:e.jsx(Cn,{data:r,onChange:p})})]}),e.jsxs(T.Item,{value:"other",children:[e.jsx(T.Control,{onClick:()=>m("other"),children:"Other"}),e.jsx(T.Panel,{children:e.jsx(gn,{data:r,onChange:p})})]}),e.jsxs(T.Item,{value:"carRental",children:[e.jsx(T.Control,{onClick:()=>m("carRental"),children:"Car Rental"}),e.jsx(T.Panel,{children:e.jsx(cn,{data:r,onChange:p})})]}),e.jsxs(T.Item,{value:"summary",children:[e.jsx(T.Control,{onClick:()=>m("summary"),children:"Summary"}),e.jsx(T.Panel,{children:e.jsx(it,{data:r})})]})]})]}):e.jsx(Se,{className:"h-10 w-10 animate-spin mr-2 self-center"})})}export{jt as C,Hn as E,Rn as P};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{j as e,T as ae,B as U,ao as se,ce as ne,a as D,fx as te,r as x,ae as q,fy as le,fz as z,V,t as f,a0 as oe,fA as ie,dc as G,bP as u,bQ as k,a2 as de,fB as ce,a3 as me,a4 as ue,a5 as xe,v as ye,a7 as pe,bW as g,bR as S,H as E,ab as ge,i as W,fC as he,l as Q,fD as je,fE as _,e as fe,fF as ve,fG as be,u as J,c_ as Ne,d1 as Se,c$ as Ee,d0 as we,ci as Fe,X as w,fH as Ce,fI as De,fJ as Ie,fK as Ae,fL as Pe,fM as Re,fN as Te,fO as ke,fP as Me,F as Be,c as Le,L as Ze,fQ as Oe}from"./index-CgQ4Qjvh.js";function Y(t){return e.jsx(ae,{disabled:!t.tooltip,label:t.tooltip,children:e.jsx(U,{variant:"ghost",size:"icon",className:"size-7.5",...t,children:e.jsx(se,{className:"size-5"})})})}const X=({isNewInsert:t=!0,defaultValues:a,month:o,onDone:d,isModifying:l})=>{const{selectableBusinesses:i,fetching:n}=ne(),[{data:c,fetching:y,error:j}]=D({query:te}),{userContext:v}=x.useContext(q),[{data:b,fetching:F,error:R}]=D({query:le}),[{data:I,fetching:M,error:C}]=D({query:z,variables:{employerId:v?.context.adminBusinessId??""}}),[p,N]=x.useState([]),[A,T]=x.useState([]),[K,ee]=x.useState([]),P=a?.month??o,Z=V({defaultValues:{...a,month:P}}),{control:m,handleSubmit:O,formState:{dirtyFields:$},setValue:B}=Z;x.useEffect(()=>{j&&f.error("Error",{description:"Oh no!, we have an error fetching pension funds! 🤥"})},[j]),x.useEffect(()=>{R&&f.error("Error",{description:"Oh no!, we have an error fetching training funds! 🤥"})},[R]),x.useEffect(()=>{C&&f.error("Error",{description:"Oh no!, we have an error employees! 🤥"})},[C]),x.useEffect(()=>{c?.allPensionFunds?.length&&N(c.allPensionFunds.map(r=>({value:r.id,label:r.name})).sort((r,s)=>r.label>s.label?1:-1))},[c,T]),x.useEffect(()=>{b?.allTrainingFunds?.length&&T(b.allTrainingFunds.map(r=>({value:r.id,label:r.name})).sort((r,s)=>r.label>s.label?1:-1))},[b,T]),x.useEffect(()=>{I?.employeesByEmployerId.length&&ee(I.employeesByEmployerId.filter(r=>!r.name.toLocaleLowerCase().includes("batched")).map(r=>({value:r.id,label:r.name})).sort((r,s)=>r.label>s.label?1:-1))},[I,T]),x.useEffect(()=>{!a?.employer&&v?.context.adminBusinessId&&B("employer",v.context.adminBusinessId,{shouldDirty:!0,shouldTouch:!0})},[B,a?.employer,v?.context.adminBusinessId]);const H=r=>{const s=ge(r,$);if(!(t&&(!s?.directPaymentAmount||!s?.employeeId||!s?.employer||!s?.month)))if(s&&Object.keys(s).length>0){if(!t){if(!a)return;s.employeeId??=a.employeeId,s.month??=a.month}d(s)}else d()};function re(r){B("month",E(r,"yyyy-MM-dd"),{shouldDirty:!0,shouldTouch:!0})}return e.jsx(oe,{...Z,children:e.jsxs("form",{onSubmit:O(H),children:[e.jsx("div",{className:"flex-row px-10 h-max justify-start block",children:e.jsxs(ie,{cols:4,children:[e.jsxs("div",{className:"flex-column h-max justify-start block",children:[e.jsx(G,{defaultDate:P?new Date(P):void 0,defaultValue:P?new Date(P):void 0,onChange:re,popoverProps:{withinPortal:!0}}),e.jsx(u,{name:"employer",control:m,defaultValue:a?.employer,rules:{required:"Required"},render:({field:r,fieldState:s})=>e.jsx(k,{...r,data:i,value:r.value,disabled:n,label:"Employer",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:s.error?.message})}),e.jsx(de,{name:"chargeId",control:m,defaultValue:a?.chargeId,rules:{pattern:{value:ce,message:"Invalid UUID"}},render:({field:r})=>e.jsxs(me,{children:[e.jsx(ue,{children:"Charge ID"}),e.jsx(xe,{children:e.jsx(ye,{...r,value:r.value??void 0})}),e.jsx(pe,{})]})}),e.jsx(u,{name:"employeeId",control:m,defaultValue:a?.employeeId,rules:{required:"Required"},render:({field:r,fieldState:s})=>e.jsx(k,{...r,data:K,value:r.value,disabled:M,label:"Employee",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:s.error?.message})})]}),e.jsxs("div",{className:"flex-row px-10 h-max justify-start block",children:[e.jsx(u,{name:"baseSalary",control:m,defaultValue:a?.baseSalary,render:({field:r,fieldState:s})=>e.jsx(g,{...r,value:r.value??void 0,error:s.error?.message,label:"Base Salary",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"globalAdditionalHours",control:m,defaultValue:a?.globalAdditionalHours,render:({field:r,fieldState:s})=>e.jsx(g,{...r,value:r.value??void 0,error:s.error?.message,label:"Global Additional Hours",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"bonus",control:m,defaultValue:a?.bonus,render:({field:r,fieldState:s})=>e.jsx(g,{...r,value:r.value??void 0,error:s.error?.message,label:"Bonus",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"gift",control:m,defaultValue:a?.gift,render:({field:r,fieldState:s})=>e.jsx(g,{...r,value:r.value??void 0,error:s.error?.message,label:"Gift",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"travelAndSubsistence",control:m,defaultValue:a?.travelAndSubsistence,render:({field:r,fieldState:s})=>e.jsx(g,{...r,value:r.value??void 0,error:s.error?.message,label:"Travel and Subsistence",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"recovery",control:m,defaultValue:a?.recovery,render:({field:r,fieldState:s})=>e.jsx(g,{...r,value:r.value??void 0,error:s.error?.message,label:"Recovery",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency"}})}),e.jsx(u,{name:"vacationTakeout",control:m,defaultValue:a?.vacationTakeout,render:({field:r,fieldState:s})=>e.jsx(g,{...r,value:r.value??void 0,error:s.error?.message,label:"Vacation Takeout",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"directPaymentAmount",control:m,defaultValue:a?.directPaymentAmount,rules:{required:"Required"},render:({field:r,fieldState:s})=>e.jsx(g,{...r,value:r.value??void 0,error:s.error?.message,label:"Direct Payment",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})})]}),e.jsxs("div",{className:"flex-row px-10 h-max justify-start block",children:[e.jsx(u,{name:"pensionFundId",control:m,defaultValue:a?.pensionFundId,render:({field:r,fieldState:s})=>e.jsx(k,{...r,data:p,value:r.value,disabled:y,label:"Pension Fund",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:s.error?.message})}),e.jsx(u,{name:"pensionEmployeeAmount",control:m,defaultValue:a?.pensionEmployeeAmount,render:({field:r,fieldState:s})=>e.jsx(g,{...r,value:r.value??void 0,error:s.error?.message,label:"Pension Employee Amount",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"pensionEmployeePercentage",control:m,defaultValue:a?.pensionEmployeePercentage,render:({field:{value:r,...s},fieldState:h})=>e.jsx(S,{...s,hideControls:!0,precision:2,removeTrailingZeros:!0,rightSection:"%",value:r??void 0,error:h.error?.message,label:"Pension Employee Percentage"})}),e.jsx(u,{name:"pensionEmployerAmount",control:m,defaultValue:a?.pensionEmployerAmount,render:({field:r,fieldState:s})=>e.jsx(g,{...r,value:r.value??void 0,error:s.error?.message,label:"Pension Employer Amount",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"pensionEmployerPercentage",control:m,defaultValue:a?.pensionEmployerPercentage,render:({field:{value:r,...s},fieldState:h})=>e.jsx(S,{...s,hideControls:!0,precision:2,removeTrailingZeros:!0,rightSection:"%",value:r??void 0,error:h.error?.message,label:"Pension Employer Percentage"})})]}),e.jsxs("div",{className:"flex-row px-10 h-max justify-start block",children:[e.jsx(u,{name:"compensationsEmployerAmount",control:m,defaultValue:a?.compensationsEmployerAmount,render:({field:r,fieldState:s})=>e.jsx(g,{...r,value:r.value??void 0,error:s.error?.message,label:"Compensations Amount",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"compensationsEmployerPercentage",control:m,defaultValue:a?.compensationsEmployerPercentage,render:({field:{value:r,...s},fieldState:h})=>e.jsx(S,{...s,hideControls:!0,precision:2,removeTrailingZeros:!0,rightSection:"%",value:r??void 0,error:h.error?.message,label:"Compensations Percentage"})})]}),e.jsxs("div",{className:"flex-row px-10 h-max justify-start block",children:[e.jsx(u,{name:"trainingFundId",control:m,defaultValue:a?.trainingFundId,render:({field:r,fieldState:s})=>e.jsx(k,{...r,data:A,value:r.value,disabled:F,label:"Training Fund",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:s.error?.message})}),e.jsx(u,{name:"trainingFundEmployeeAmount",control:m,defaultValue:a?.trainingFundEmployeeAmount,render:({field:r,fieldState:s})=>e.jsx(g,{...r,value:r.value??void 0,error:s.error?.message,label:"Training Employee Amount",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"trainingFundEmployeePercentage",control:m,defaultValue:a?.trainingFundEmployeePercentage,render:({field:{value:r,...s},fieldState:h})=>e.jsx(S,{...s,hideControls:!0,precision:2,removeTrailingZeros:!0,rightSection:"%",value:r??void 0,error:h.error?.message,label:"Training Employee Percentage"})}),e.jsx(u,{name:"trainingFundEmployerAmount",control:m,defaultValue:a?.trainingFundEmployerAmount,render:({field:r,fieldState:s})=>e.jsx(g,{...r,value:r.value??void 0,error:s.error?.message,label:"Training Employer Amount",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"trainingFundEmployerPercentage",control:m,defaultValue:a?.trainingFundEmployerPercentage,render:({field:{value:r,...s},fieldState:h})=>e.jsx(S,{...s,hideControls:!0,precision:2,removeTrailingZeros:!0,rightSection:"%",value:r??void 0,error:h.error?.message,label:"Training Employer Percentage"})})]}),e.jsxs("div",{className:"flex-row px-10 h-max justify-start block",children:[e.jsx(u,{name:"socialSecurityAmountEmployee",control:m,defaultValue:a?.socialSecurityAmountEmployee,render:({field:r,fieldState:s})=>e.jsx(g,{...r,value:r.value??void 0,error:s.error?.message,label:"Social Security - Employee",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"socialSecurityAmountEmployer",control:m,defaultValue:a?.socialSecurityAmountEmployer,render:({field:r,fieldState:s})=>e.jsx(g,{...r,value:r.value??void 0,error:s.error?.message,label:"Social Security - Employer",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"healthPaymentAmount",control:m,defaultValue:a?.healthPaymentAmount,render:({field:r,fieldState:s})=>e.jsx(g,{...r,value:r.value??void 0,error:s.error?.message,label:"Health Insurance",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})})]}),e.jsxs("div",{className:"flex-row px-10 h-max justify-start block",children:[e.jsx(u,{name:"taxAmount",control:m,defaultValue:a?.taxAmount,render:({field:r,fieldState:s})=>e.jsx(g,{...r,value:r.value??void 0,error:s.error?.message,label:"Income Tax",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"zkufot",control:m,defaultValue:a?.zkufot,render:({field:r,fieldState:s})=>e.jsx(g,{...r,value:r.value??void 0,error:s.error?.message,precision:0,label:"Notional Expense",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})})]}),e.jsxs("div",{className:"flex-row px-10 h-max justify-start block",children:[e.jsx(u,{name:"workDays",control:m,defaultValue:a?.workDays,render:({field:{value:r,...s},fieldState:h})=>e.jsx(S,{...s,hideControls:!0,precision:2,removeTrailingZeros:!0,value:r??void 0,error:h.error?.message,label:"Work Days"})}),e.jsx(u,{name:"addedVacationDays",control:m,defaultValue:a?.addedVacationDays,render:({field:{value:r,...s},fieldState:h})=>e.jsx(S,{...s,hideControls:!0,precision:2,removeTrailingZeros:!0,value:r??void 0,error:h.error?.message,label:"Added Vacation Days"})}),e.jsx(u,{name:"vacationDaysBalance",control:m,defaultValue:a?.vacationDaysBalance,render:({field:{value:r,...s},fieldState:h})=>e.jsx(S,{...s,hideControls:!0,precision:2,removeTrailingZeros:!0,value:r??void 0,error:h.error?.message,label:"Vacation Days Balance"})}),e.jsx(u,{name:"sicknessDaysBalance",control:m,defaultValue:a?.sicknessDaysBalance,render:({field:{value:r,...s},fieldState:h})=>e.jsx(S,{...s,hideControls:!0,precision:2,removeTrailingZeros:!0,value:r??void 0,error:h.error?.message,label:"Sickness Days Balance"})})]})]})}),e.jsxs("div",{className:"mt-10 mb-5 flex justify-center gap-5",children:[e.jsx("button",{type:"submit",onClick:()=>O(H),className:"mt-8 text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg",disabled:l||Object.keys($).length===0,children:"Accept"}),e.jsx("button",{type:"button",className:"mt-8 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"})]})]})})},$e="updateSalaryRecord",He=()=>{const[{fetching:t},a]=W(he),o=x.useCallback(async d=>{const l=`Error updating salary record [${d.salaryRecord.month}] employee [${d.salaryRecord.employeeId}]`,i=$e;f.loading("Updating Salary Record",{id:i});try{const n=await a(d),c=Q(n,l,i,"updateSalaryRecord");if(c)return f.success("Success",{id:i,description:"Salary record was updated"}),c.updateSalaryRecord.salaryRecord}catch(n){console.error(`${l}: ${n}`),f.error("Error",{id:i,description:l,duration:1e5,closeButton:!0})}},[a]);return{fetching:t,updateSalaryRecord:o}},Ue=({recordVariables:t,onDone:a})=>t?e.jsx(qe,{recordVariables:t,onDone:a}):null,qe=({recordVariables:t,onDone:a})=>{const{updateSalaryRecord:o,fetching:d}=He(),[{data:l,fetching:i}]=D({query:je,variables:{employeeIDs:[t.employeeId],month:E(new Date(t.month),"yyyy-MM-dd")}}),n=l?.salaryRecordsByDates?.[0],c=x.useCallback(j=>{a(),j&&o({salaryRecord:j})},[a,o]);if(!n?.employer?.id||!n?.employee?.id)return e.jsx(e.Fragment,{});const y={addedVacationDays:n?.vacationDays?.added,baseSalary:n?.baseAmount?.raw,bonus:n?.bonus?.raw,chargeId:n?.charge?.id,compensationsEmployerAmount:n?.compensationsAmount?.raw,compensationsEmployerPercentage:n?.compensationsPercentage,directPaymentAmount:n?.directAmount?.raw,employer:n.employer.id,employeeId:n.employee.id,gift:n?.gift?.raw,globalAdditionalHours:n?.globalAdditionalHoursAmount?.raw,healthPaymentAmount:n?.healthInsuranceAmount?.raw,month:n?.month,pensionEmployeeAmount:n?.pensionEmployeeAmount?.raw,pensionEmployeePercentage:n?.pensionEmployeePercentage,pensionEmployerAmount:n?.pensionEmployerAmount?.raw,pensionEmployerPercentage:n?.pensionEmployerPercentage,pensionFundId:n?.pensionFund?.id,recovery:n?.recovery?.raw,sicknessDaysBalance:n?.sicknessDays?.balance,socialSecurityAmountEmployee:n?.socialSecurityEmployeeAmount?.raw,socialSecurityAmountEmployer:n?.socialSecurityEmployerAmount?.raw,taxAmount:n?.incomeTaxAmount?.raw,trainingFundEmployeeAmount:n?.trainingFundEmployeeAmount?.raw,trainingFundEmployeePercentage:n?.trainingFundEmployeePercentage,trainingFundEmployerAmount:n?.trainingFundEmployerAmount?.raw,trainingFundEmployerPercentage:n?.trainingFundEmployerPercentage,trainingFundId:n?.trainingFund?.id,travelAndSubsistence:n?.travelAndSubsistence?.raw,vacationDaysBalance:n?.vacationDays?.balance,vacationTakeout:n?.vacationTakeout?.raw,workDays:n?.workDays,zkufot:n?.notionalExpense?.raw};return e.jsx(_,{modalSize:"fit-content",position:"bottom",title:e.jsxs("div",{className:"flex flex-row mx-3 pt-3 sm:text-1xl gap-10",children:[e.jsx("h1",{className:"sm:text-2xl font-small text-gray-900",children:"Edit Salary Record:"}),e.jsxs("div",{className:"flex flex-row gap-2",children:["month: ",t.month," employeeId: ",t.employeeId]})]}),opened:!!t,onClose:a,children:i||!n?e.jsx(fe,{className:"flex self-center my-5",color:"dark",size:"xl",variant:"dots"}):e.jsx(X,{isNewInsert:!1,defaultValues:y,onDone:c,isModifying:d})})},ze="insertSalaryRecords",Ve=()=>{const[{fetching:t},a]=W(ve),o=x.useCallback(async d=>{const l=ze;if(f.loading("Adding salary record",{id:l}),!d.salaryRecords||Array.isArray(d.salaryRecords)&&d.salaryRecords.length===0){f.error("Error",{id:l,description:"No salary records to insert",duration:1e5,closeButton:!0});return}const i=Array.isArray(d.salaryRecords)?d.salaryRecords[0]:d.salaryRecords;if(!i?.directPaymentAmount||!i?.employeeId||!i?.employer||!i?.month){f.error("Error",{id:l,description:"Missing required salary record fields",duration:1e5,closeButton:!0});return}const n=`Error adding salary record [${i.month}] employee [${i.employeeId}]`;try{const c=await a(d),y=Q(c,n,l,"insertSalaryRecords");if(y)return f.success("Success",{id:l,description:"Salary record was added"}),y.insertSalaryRecords.salaryRecords[0]}catch(c){console.error(`${n}: ${c}`),f.error("Error",{id:l,description:n,duration:1e5,closeButton:!0})}},[a]);return{fetching:t,insertSalaryRecord:o}},Ge=({insertSalaryRecordParams:t,setInsertSalaryRecord:a})=>{const{insertSalaryRecord:o,fetching:d}=Ve(),l=x.useCallback(i=>{i&&o({salaryRecords:[i]}),a(void 0)},[a,o]);return e.jsx(_,{modalSize:"40%",position:"bottom",title:e.jsx("div",{className:"flex flex-row mx-3 pt-3 sm:text-1xl gap-10",children:e.jsx("h1",{className:"sm:text-2xl font-small text-gray-900",children:"Insert Salary Record:"})}),opened:!!t,onClose:()=>a(void 0),children:e.jsx(X,{isNewInsert:!0,onDone:l,isModifying:d,month:t.month})})};function L(){const t=new Date,a=E(t,"yyyy-MM-dd"),o=E(be(t),"yyyy-MM-dd");return{fromDate:a,toDate:o}}function We({filter:t,setFilter:a,closeModal:o}){const{control:d,handleSubmit:l,setValue:i}=V({defaultValues:{...t}}),[n,c]=x.useState([]),{userContext:y}=x.useContext(q),[{data:j,fetching:v,error:b},F]=D({query:z,variables:{employerId:y?.context.adminBusinessId??""},pause:!0});x.useEffect(()=>{F()},[y?.context.adminBusinessId,F]),x.useEffect(()=>{b&&f.error("Error",{description:"Oh no!, we have an error fetching employees! 🤥"})},[b]);const R=p=>{p.employeeIDs?.length===0&&delete p.employeeIDs,a(p),o()};function I(){a({...L()}),o()}x.useEffect(()=>{j?.employeesByEmployerId.length&&c(j.employeesByEmployerId.filter(p=>!p.name.toLocaleLowerCase().includes("batched")).map(p=>({value:p.id,label:p.name})).sort((p,N)=>p.label>N.label?1:-1))},[j,c]);function M([p,N]){if(N){const A=new Date(N.getFullYear(),N.getMonth()+1,0);i("toDate",E(A,"yyyy-MM-dd"))}if(p){const A=new Date(p.getFullYear(),p.getMonth(),1);i("fromDate",E(A,"yyyy-MM-dd"))}}const C=L();return e.jsxs(e.Fragment,{children:[v?e.jsx("div",{children:"Loading..."}):e.jsx("div",{}),e.jsxs("form",{onSubmit:l(R),children:[e.jsx(G,{type:"range",numberOfColumns:2,defaultValue:[new Date(t?.fromDate??C.fromDate),new Date(t?.toDate??C.toDate)],defaultDate:new Date(t?.fromDate??C.fromDate),onChange:M,popoverProps:{withinPortal:!0}}),e.jsx(u,{name:"employeeIDs",control:d,defaultValue:t.employeeIDs,render:({field:p,fieldState:N})=>e.jsx(Fe,{...p,data:n,value:p.value??[],disabled:v,label:"Employees",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:N.error?.message})}),e.jsxs("div",{className:"flex justify-center mt-5 gap-3",children:[e.jsx("button",{type:"submit",disabled:v,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:I,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:o,children:"Cancel"})]})]})]})}function Qe({filter:t,setFilter:a}){const[o,d]=x.useState(!1),{get:l,set:i}=J();x.useEffect(()=>{const c=Ne(t)?null:encodeURIComponent(JSON.stringify(t)),y=l("salariesFilters");c!==y&&i("salariesFilters",c)},[t,l,i]);const n=x.useCallback(c=>{Se(c,t)||a(c)},[t,a]);return e.jsxs("div",{className:"flex flex-row gap-5 items-center",children:[e.jsx(Ee,{opened:o,onClose:()=>d(!1),content:e.jsx(We,{filter:t,setFilter:n,closeModal:()=>d(!1)}),modalSize:"xl"}),e.jsx(U,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>d(!0),children:e.jsx(we,{className:"size-5"})})]})}const _e=({month:t,setInsertSalaryRecord:a})=>{const o=E(new Date(t),"MMMM yyyy");return e.jsx("tr",{tabIndex:0,className:"h-16 rounded-sm",children:e.jsx("td",{colSpan:100,children:e.jsxs("div",{className:"flex justify-between pl-5",children:[e.jsx("p",{className:"text-lg font-bold text-gray-800",children:o}),e.jsx("div",{className:"flex items-center",children:e.jsx("div",{className:"flex flex-col",children:e.jsx(Y,{onClick:a})})})]})})})},Je=({data:t})=>{const{employee:a,month:o}=w(Ce,t),d=E(new Date(o),"MMMM yyyy");return e.jsx("td",{className:"",children:e.jsx("div",{className:"flex items-center pl-5",children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("p",{className:"text-base font-bold text-gray-800",children:a?.name}),e.jsx("p",{className:"text-base font-medium text-gray-800",children:d})]})})})},Ye=({data:t})=>{const{pensionEmployeeAmount:a,pensionEmployeePercentage:o,pensionEmployerAmount:d,pensionEmployerPercentage:l,compensationsAmount:i,compensationsPercentage:n,pensionFund:c,trainingFund:y,trainingFundEmployeeAmount:j,trainingFundEmployeePercentage:v,trainingFundEmployerAmount:b,trainingFundEmployerPercentage:F}=w(De,t);return e.jsx("td",{className:"pl-5",children:e.jsx("div",{className:"flex items-center",children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("p",{className:"text-md font-bold text-gray-800",children:"Pension Fund"}),e.jsx("p",{className:"text-md font-medium text-gray-800",children:c?.name}),!!a?.raw&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Employee Part:"}),e.jsxs("p",{className:"text-sm leading-none text-gray-600 ml-2",children:[a?.formatted,o&&` (${o}%)`]})]}),!!d?.raw&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Employer Part:"}),e.jsxs("p",{className:"text-sm leading-none text-gray-600 ml-2",children:[d?.formatted,l&&` (${l}%)`]})]}),!!i?.raw&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Compensations Amount:"}),e.jsxs("p",{className:"text-sm leading-none text-gray-600 ml-2",children:[i?.formatted,n&&` (${n}%)`]})]}),e.jsx("p",{className:"text-md font-bold text-gray-800 mt-2",children:"Training Fund"}),e.jsx("p",{className:"text-md font-medium text-gray-800",children:y?.name}),!!j?.raw&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Employee Part:"}),e.jsxs("p",{className:"text-sm leading-none text-gray-600 ml-2",children:[j?.formatted,v&&` (${v}%)`]})]}),!!b?.raw&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Employer Part:"}),e.jsxs("p",{className:"text-sm leading-none text-gray-600 ml-2",children:[b?.formatted,F&&` (${F}%)`]})]})]})})})},Xe=({data:t})=>{const{healthInsuranceAmount:a,socialSecurityEmployeeAmount:o,socialSecurityEmployerAmount:d,incomeTaxAmount:l,notionalExpense:i}=w(Ie,t),n=!!o||!!d;return e.jsx("td",{className:"pl-5",children:e.jsx("div",{className:"flex items-center pl-5",children:e.jsxs("div",{className:"flex flex-col",children:[n&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-md font-bold text-gray-800",children:"Social Security"}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Employee Part:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:o?.formatted})]}),e.jsx("p",{className:"text-md font-bold text-gray-800 mt-2",children:"Pension Fund"}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Employer Part:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:d?.formatted})]})]}),!!a?.raw&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-md font-bold text-gray-800 mt-2",children:"Health Insurance"}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Amount:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:a?.formatted})]})]}),(!!l?.raw||!!i?.raw)&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-md font-bold text-gray-800 mt-2",children:"Taxes"}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Income Tax:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:l?.formatted})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Notional Expense:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:i?.formatted})]})]})]})})})},Ke=({data:t})=>{const{baseAmount:a,directAmount:o,globalAdditionalHoursAmount:d,bonus:l,gift:i,recovery:n,vacationTakeout:c}=w(Ae,t);return e.jsx("td",{className:"pl-24",children:e.jsx("div",{className:"flex items-center",children:e.jsxs("div",{className:"flex flex-col",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Base Amount:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:a?.formatted})]}),e.jsxs("div",{className:"flex justify-between mb-2",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Global Extra Hours:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:d?.formatted})]}),!!l?.raw&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Bonus:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:l?.formatted})]}),!!i?.raw&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Gift:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:i?.formatted})]}),!!n?.raw&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Recovery:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:n?.formatted})]}),!!c?.raw&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Vacation Takeout:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:c?.formatted})]}),e.jsxs("div",{className:"flex justify-between mt-2",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Direct Amount:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:o?.formatted})]})]})})})},er=({data:t})=>{const{vacationDays:a,workDays:o,sicknessDays:d}=w(Pe,t),{added:l,taken:i,balance:n}=a??{},{balance:c}=d??{},y=!!l||!!i||!!n;return e.jsx("td",{className:"pl-5",children:e.jsx("div",{className:"flex items-center",children:e.jsxs("div",{className:"flex flex-col",children:[!!o&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-md leading-none text-gray-800",children:"Work Days:"}),e.jsx("div",{className:"flex justify-between",children:e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:o})})]}),y&&e.jsxs("div",{className:"flex flex-col",children:[e.jsx("p",{className:"text-md leading-none text-gray-800 mt-2",children:"Vacation Days:"}),!!l&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Added:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:l})]}),!!i&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Taken:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:i})]}),!!n&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Balance:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:n})]})]}),!!c&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-md leading-none text-gray-800 mt-2",children:"Sickness Days:"}),e.jsx("div",{className:"flex justify-between",children:e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:c})})]})]})})})},rr=({setEditSalaryRecord:t,data:a})=>{const o=w(Te,a);return e.jsxs(e.Fragment,{children:[e.jsxs("tr",{tabIndex:0,className:"h-16 border border-gray-100 hover:bg-gray-100 rounded-sm",children:[e.jsx(Je,{data:o}),e.jsx(Ke,{data:o}),e.jsx(Ye,{data:o}),e.jsx(Xe,{data:o}),e.jsx(er,{data:o}),e.jsx("td",{className:"pl-2",children:e.jsx("div",{className:"flex items-center",children:e.jsx("div",{className:"flex flex-col",children:e.jsx(Re,{onClick:t})})})})]}),e.jsx("tr",{className:"h-3"})]})},ar=({setEditSalaryRecord:t,setInsertSalaryRecord:a,data:o})=>{const d=o?.map(l=>w(ke,l))??[];return e.jsxs(e.Fragment,{children:[e.jsx("tr",{className:"h-3"}),e.jsx(_e,{month:d[0].month,setInsertSalaryRecord:a}),e.jsx("tr",{className:"h-3"}),d.map(l=>e.jsx(rr,{data:l,setEditSalaryRecord:()=>t(l.employee?.id)},`${l.month} ${l.employee?.id}`))]})},sr=({setEditSalaryRecord:t,setInsertSalaryRecord:a,data:o})=>{const d=x.useMemo(()=>{const l=o?.map(n=>w(Me,n))??[],i=new Map;return l.map(n=>{const{month:c}=n,y=i.get(c)??[];i.set(c,[...y,n])}),i},[o]);return e.jsx("div",{className:"sm:px-6 w-full",children:e.jsxs("div",{className:"bg-white py-4 md:py-7 px-4 md:px-8 xl:px-10",children:[e.jsxs("div",{className:"sm:flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center",children:[e.jsx("div",{className:"rounded-full focus:outline-hidden focus:ring-2 focus:bg-indigo-50 focus:ring-indigo-800",children:e.jsx("div",{className:"py-2 px-8 bg-indigo-100 text-indigo-700 rounded-full",children:e.jsx("p",{children:"All"})})}),e.jsx("div",{className:"rounded-full focus:outline-hidden focus:ring-2 focus:bg-indigo-50 focus:ring-indigo-800 ml-4 sm:ml-8",children:e.jsx("div",{className:"py-2 px-8 text-gray-600 hover:text-indigo-700 hover:bg-indigo-100 rounded-full ",children:e.jsx("p",{children:"Done"})})}),e.jsx("div",{className:"rounded-full focus:outline-hidden focus:ring-2 focus:bg-indigo-50 focus:ring-indigo-800 ml-4 sm:ml-8",children:e.jsx("div",{className:"py-2 px-8 text-gray-600 hover:text-indigo-700 hover:bg-indigo-100 rounded-full ",children:e.jsx("p",{children:"Pending"})})})]}),e.jsx("button",{className:"focus:ring-2 focus:ring-offset-2 focus:ring-indigo-600 mt-4 sm:mt-0 inline-flex items-start justify-start px-6 py-3 bg-indigo-700 hover:bg-indigo-600 focus:outline-hidden rounded-sm",children:e.jsx("p",{className:"text-sm font-medium leading-none text-white",children:"Add Task"})})]}),e.jsx("div",{className:"mt-7 overflow-x-auto",children:e.jsx("table",{className:"w-full whitespace-nowrap",children:e.jsx("tbody",{children:Array.from(d).map(([l,i])=>e.jsx(ar,{data:i,setEditSalaryRecord:n=>t(n?{month:l,employeeId:n}:void 0),setInsertSalaryRecord:()=>a({month:l})},l))})})})]})})},tr=()=>{const{setFiltersContext:t}=x.useContext(Be),[a,o]=x.useState(void 0),[d,l]=x.useState(void 0),{get:i}=J(),[n,c]=x.useState(i("salariesFilters")?JSON.parse(decodeURIComponent(i("salariesFilters"))):{...L()}),[{data:y,fetching:j}]=D({query:Oe,variables:{...n}});return x.useEffect(()=>{t(e.jsxs("div",{className:"flex flex-row gap-x-5",children:[e.jsx(Qe,{filter:n,setFilter:c}),e.jsx(Y,{variant:"default",onClick:()=>l({})})]}))},[y,j,n,t,c]),e.jsxs(Le,{title:"Salaries",description:"View and manage salaries of employees.",children:[j?e.jsx(Ze,{className:"h-10 w-10 animate-spin mr-2 self-center"}):e.jsx(sr,{setEditSalaryRecord:o,setInsertSalaryRecord:l,data:y?.salaryRecordsByDates}),e.jsx(Ue,{recordVariables:a,onDone:()=>o(void 0)}),d&&e.jsx(Ge,{insertSalaryRecordParams:d,setInsertSalaryRecord:l})]})};export{tr as Salaries};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as h,j as e,c$ as u,eL as f,B as y,d0 as R,bq as D,F as T,a as E,c as b,L as w,cb as F,eN as g}from"./index-CgQ4Qjvh.js";import{d as v}from"./graphql-document-dedupe-fragments-ByT8-wlV.js";import{R as d}from"./report-commentary-row-B479zk-x.js";function B({year:c,setYear:m,referenceYears:x,setReferenceYears:j}){const[i,o]=h.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsx(u,{opened:i,onClose:()=>o(!1),withCloseButton:!0,content:e.jsxs(e.Fragment,{children:[e.jsx(f,{label:"Change report year",value:new Date(c,0,1),onChange:n=>n&&m(n?.getFullYear()),popoverProps:{withinPortal:!0},minDate:new Date(2010,0,1),maxDate:new Date}),e.jsx(f,{type:"multiple",label:"Pick reference years",value:x?.map(n=>new Date(n,0,1)),onChange:n=>j(n.map(l=>l.getFullYear()).filter(l=>c!==l)),popoverProps:{withinPortal:!0},minDate:new Date(2010,0,1),maxDate:new Date})]})}),e.jsx(y,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>o(!0),children:e.jsx(R,{className:"size-5"})})]})}const Y=()=>{const{year:c}=D(),{setFiltersContext:m}=h.useContext(T),[x,j]=h.useState(c?Number(c):new Date().getFullYear()),[i,o]=h.useState([]),[{data:n,fetching:l}]=E({query:v(g),variables:{reportYear:x,referenceYears:i}});h.useEffect(()=>{m(e.jsx("div",{className:"flex flex-row gap-2",children:e.jsx(B,{year:x,setYear:j,referenceYears:i,setReferenceYears:o})}))},[x,l,m,i,o]);const p=n?.taxReport,s=p?.report,r=p?.reference??[];return e.jsx(b,{title:"Tax Report",children:l?e.jsx(w,{className:"h-10 w-10 animate-spin mr-2 self-center"}):e.jsx("div",{className:"flex flex-col gap-4",children:s&&e.jsxs(F,{highlightOnHover:!0,fontSize:"md",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{}),e.jsx("th",{children:x},x),e.jsx("th",{}),r.map(t=>e.jsx("th",{children:t.year},t.year))]})}),e.jsxs("tbody",{children:[e.jsx(d,{dataRow:t=>e.jsxs("tr",{children:[e.jsx("th",{children:"Profit Before Tax"}),e.jsx("th",{children:s.profitBeforeTax.amount.formatted}),e.jsx("th",{children:t}),r.map(a=>e.jsx("th",{children:a.profitBeforeTax.amount.formatted},a.year))]}),commentaryData:s.profitBeforeTax}),e.jsx(d,{dataRow:t=>e.jsxs("tr",{children:[e.jsx("td",{children:"R&D Expenses By Records"}),e.jsx("td",{children:s.researchAndDevelopmentExpensesByRecords.amount.formatted}),e.jsx("th",{children:t}),r.map(a=>e.jsx("td",{children:a.researchAndDevelopmentExpensesByRecords.amount.formatted},a.year))]}),commentaryData:s.researchAndDevelopmentExpensesByRecords}),e.jsxs("tr",{children:[e.jsx("td",{children:"R&D Expenses For Tax"}),e.jsx("td",{children:s.researchAndDevelopmentExpensesForTax.formatted}),e.jsx("td",{}),r.map(t=>e.jsx("td",{children:t.researchAndDevelopmentExpensesForTax.formatted},t.year)),e.jsx("td",{})]}),e.jsx(d,{dataRow:t=>e.jsxs("tr",{children:[e.jsx("td",{children:"Fines"}),e.jsx("td",{children:s.fines.amount.formatted}),e.jsx("th",{children:t}),r.map(a=>e.jsx("td",{children:a.fines.amount.formatted},a.year))]}),commentaryData:s.fines}),e.jsx(d,{dataRow:t=>e.jsxs("tr",{children:[e.jsx("td",{children:"Untaxable Gifts"}),e.jsx("td",{children:s.untaxableGifts.amount.formatted}),e.jsx("th",{children:t}),r.map(a=>e.jsx("td",{children:a.untaxableGifts.amount.formatted},a.year))]}),commentaryData:s.untaxableGifts}),e.jsxs("tr",{children:[e.jsx("td",{children:"Business Trips Excess Expenses"}),e.jsx("td",{children:s.businessTripsExcessExpensesAmount.formatted}),e.jsx("td",{}),r.map(t=>e.jsx("td",{children:t.businessTripsExcessExpensesAmount.formatted},t.year)),e.jsx("td",{})]}),e.jsxs("tr",{children:[e.jsx("td",{children:"Salary Excess Expenses"}),e.jsx("td",{children:s.salaryExcessExpensesAmount.formatted}),e.jsx("td",{}),r.map(t=>e.jsx("td",{children:t.salaryExcessExpensesAmount.formatted},t.year)),e.jsx("td",{})]}),e.jsx(d,{dataRow:t=>e.jsxs("tr",{children:[e.jsx("td",{children:"Reserves"}),e.jsx("td",{children:s.reserves.amount.formatted}),e.jsx("th",{children:t}),r.map(a=>e.jsx("td",{children:a.reserves.amount.formatted},a.year))]}),commentaryData:s.reserves}),e.jsx(d,{dataRow:t=>e.jsxs("tr",{children:[e.jsx("td",{children:"Nontaxable Linkage"}),e.jsx("td",{children:s.nontaxableLinkage.amount.formatted}),e.jsx("th",{children:t}),r.map(a=>e.jsx("td",{children:a.nontaxableLinkage.amount.formatted},a.year))]}),commentaryData:s.nontaxableLinkage}),e.jsxs("tr",{children:[e.jsx("th",{children:"Taxable Income"}),e.jsx("th",{children:s.taxableIncome.formatted}),e.jsx("th",{}),r.map(t=>e.jsx("th",{children:t.taxableIncome.formatted},t.year)),e.jsx("td",{})]}),e.jsxs("tr",{children:[e.jsx("td",{children:"Tax Rate"}),e.jsxs("td",{children:[(s.taxRate*100).toFixed(1),"%"]}),e.jsx("td",{}),r.map(t=>e.jsxs("td",{children:[(t.taxRate*100).toFixed(1),"%"]},t.year)),e.jsx("td",{})]}),e.jsx(d,{dataRow:t=>e.jsxs("tr",{children:[e.jsx("td",{children:"Income with Special Tax Rate"}),e.jsx("td",{children:s.specialTaxableIncome.amount.formatted}),e.jsx("th",{children:t}),r.map(a=>e.jsx("td",{children:a.specialTaxableIncome.amount.formatted},a.year))]}),commentaryData:s.specialTaxableIncome}),e.jsxs("tr",{children:[e.jsx("td",{children:"Special Tax Rate"}),e.jsxs("td",{children:[(s.specialTaxRate*100).toFixed(1),"%"]}),e.jsx("td",{}),r.map(t=>e.jsxs("td",{children:[(t.specialTaxRate*100).toFixed(1),"%"]},t.year)),e.jsx("td",{})]})]}),e.jsx("tfoot",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Annual Tax Expense"}),e.jsx("th",{children:s.annualTaxExpense.formatted}),e.jsx("th",{}),r.map(t=>e.jsx("th",{children:t.annualTaxExpense.formatted},t.year)),e.jsx("td",{})]})})]})})})};export{Y as TaxReport};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{j as e,dq as D,du as t,H as y,cT as n,X as N,eQ as v,c_ as T,r as d,u as w,d1 as A,K as I,an as O,B as S,d0 as P,N as M,V as L,di as V,a0 as q,a2 as f,a3 as R,a4 as C,a5 as B,aO as U,a7 as F,aM as _,aA as $,F as k,ae as H,a as Q,c as z,n as G,dn as J,dp as K,dr as o,dt as X,eR as W}from"./index-CgQ4Qjvh.js";const Z=({record:a})=>{const s=N(v,a);return e.jsxs(D,{children:[e.jsx(t,{children:a.description}),e.jsx(t,{children:y(new Date(a.purchaseDate),"dd/MM/yyyy")}),e.jsx(t,{children:a.activationDate?y(new Date(a.activationDate),"dd/MM/yyyy"):void 0}),e.jsx(t,{children:s.originalCost?n(s.originalCost,0):void 0}),e.jsx(t,{children:s.reportYearDelta?n(s.reportYearDelta,0):void 0}),e.jsx(t,{children:n(s.totalDepreciableCosts,0)}),e.jsxs(t,{children:[n(a.statutoryDepreciationRate,0),"%"]}),e.jsx(t,{children:a.claimedDepreciationRate?`${n(a.claimedDepreciationRate,1)}%`:"-"}),e.jsx(t,{children:s.reportYearClaimedDepreciation?n(s.reportYearClaimedDepreciation,0):"-"}),e.jsx(t,{children:s.pastYearsAccumulatedDepreciation?n(s.pastYearsAccumulatedDepreciation,0):"-"}),e.jsx(t,{children:s.totalDepreciation?n(s.totalDepreciation,0):"-"}),e.jsx(t,{children:s.netValue?n(s.netValue,0):"-"})]})};function Y(a){return!a||T(a)?null:encodeURIComponent(JSON.stringify(a))}const b="depreciationReportFilters";function ee({filter:a,setFilter:s,close:r}){const p=L({defaultValues:{...a}}),{control:c,handleSubmit:x}=p,{selectableFinancialEntities:u,fetching:l}=V(),j=i=>{s({...i,year:Number(i.year)}),r()};return e.jsx(q,{...p,children:e.jsxs("form",{onSubmit:x(j),className:"space-y-4",children:[e.jsx(f,{name:"year",control:c,rules:{required:"Year is required",validate:i=>{const m=Number(i);return Number.isNaN(m)||m<2e3||m>2100?"Invalid year":!0}},render:({field:i})=>e.jsxs(R,{children:[e.jsx(C,{children:"Year"}),e.jsx(B,{children:e.jsx(U,{...i,hideControls:!0,decimalScale:0})}),e.jsx(F,{})]})}),e.jsx(f,{name:"financialEntityId",defaultValue:a?.financialEntityId,control:c,render:({field:i})=>e.jsxs(R,{children:[e.jsx(C,{children:"Owner"}),e.jsx(_,{...i,data:u,value:i.value??void 0,disabled:l,placeholder:"Select a financial entity",formPart:!0}),e.jsx(F,{})]})}),e.jsx($,{children:e.jsx(S,{type:"submit",disabled:l,children:"Filter"})})]})})}function ae({filter:a,setFilter:s}){const[r,p]=d.useState(!1),{get:c,set:x}=w();d.useEffect(()=>{const l=Y(a),j=c(b);l!==j&&x(b,l)},[a,c,x]);const u=d.useCallback(l=>{A(l,a)||s(l)},[a,s]);return e.jsxs(I,{open:r,onOpenChange:p,children:[e.jsx(O,{asChild:!0,children:e.jsx(S,{variant:"outline",size:"icon",children:e.jsx(P,{size:20})})}),e.jsx(M,{className:"sm:max-w-[425px]",children:e.jsx(ee,{filter:a,setFilter:u,close:()=>p(!1)})})]})}const g=({data:a,groupName:s})=>{const r=N(v,a);return e.jsxs(D,{className:"font-bold border-b border-black",children:[e.jsx(t,{children:s?"Group Total":"Overall Total"}),e.jsx(t,{colSpan:2,children:s}),e.jsx(t,{children:r.originalCost?n(r.originalCost,0):void 0}),e.jsx(t,{children:r.reportYearDelta?n(r.reportYearDelta,0):void 0}),e.jsx(t,{children:r.totalDepreciableCosts?n(r.totalDepreciableCosts,0):void 0}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{children:r.reportYearClaimedDepreciation?n(r.reportYearClaimedDepreciation,0):void 0}),e.jsx(t,{children:r.pastYearsAccumulatedDepreciation?n(r.pastYearsAccumulatedDepreciation,0):void 0}),e.jsx(t,{children:r.totalDepreciation?n(r.totalDepreciation,0):void 0}),e.jsx(t,{children:r.netValue?n(r.netValue,0):void 0})]})};function te(a){const s=new URLSearchParams,r=Y(a);return r&&s.append(b,r),`/reports/depreciation${s.size>0?`?${s}`:""}`}const re=()=>{const{setFiltersContext:a}=d.useContext(k),{userContext:s}=d.useContext(H),{get:r}=w(),p=d.useMemo(()=>{const i={financialEntityId:s?.context.adminBusinessId,year:new Date().getFullYear()},m=r(b);if(m)try{return JSON.parse(decodeURIComponent(m))}catch(h){console.error("Failed to parse depreciation report filters from URL",h)}return i},[s?.context.adminBusinessId]),[c,x]=d.useState(p),[{data:u,fetching:l}]=Q({query:W,variables:{filters:c}});d.useEffect(()=>{a(e.jsx("div",{className:"flex flex-row gap-x-5",children:e.jsx(ae,{filter:c,setFilter:x})}))},[c,a,x]);const j=d.useMemo(()=>`Depreciation Report for ${c.year}`,[c.year]);return e.jsx(z,{title:"Depreciation Report",description:j,children:l?e.jsx(G,{}):e.jsxs(J,{children:[e.jsxs(K,{children:[e.jsxs(D,{className:"font-bold text-xl",children:[e.jsx(o,{colSpan:6,className:"text-center border-x",children:"List of Assets and Costs"}),e.jsx(o,{colSpan:5,className:"text-center border-x",children:"Depreciation"}),e.jsx(o,{className:"text-center border-x",children:"Remaining"})]}),e.jsxs(D,{className:"border-b border-black",children:[e.jsx(o,{className:"whitespace-normal",children:"Assets List and Descriptions"}),e.jsx(o,{className:"whitespace-normal",children:"Date of Purchase"}),e.jsx(o,{className:"whitespace-normal",children:"Activation Date"}),e.jsx(o,{className:"whitespace-normal",children:"Original Cost"}),e.jsx(o,{className:"whitespace-normal",children:"Changes During the Year"}),e.jsx(o,{className:"whitespace-normal",children:"Total Depreciable Assets"}),e.jsx(o,{className:"whitespace-normal",children:"Statutory Depreciation Rate"}),e.jsx(o,{className:"whitespace-normal",children:"Claimed Depreciation Rate"}),e.jsx(o,{className:"whitespace-normal",children:"Depreciation Claimed This Year"}),e.jsx(o,{className:"whitespace-normal",children:"Previous Tax Years Accumulated Depreciation"}),e.jsx(o,{className:"whitespace-normal",children:"Total Depreciation"}),e.jsx(o,{className:"whitespace-normal",children:"Net Book Value"})]})]}),e.jsx(X,{children:u?.depreciationReport&&e.jsxs(e.Fragment,{children:[u.depreciationReport.categories.map((i,m)=>e.jsxs(d.Fragment,{children:[e.jsxs(D,{className:"font-bold",children:[e.jsx(t,{children:`Category ${m+1}`}),e.jsx(t,{colSpan:2,children:i.category.name}),e.jsx(t,{colSpan:3}),e.jsxs(t,{children:[n(i.category.percentage,0),"%"]}),e.jsx(t,{colSpan:5})]}),i.records.sort((h,E)=>h.purchaseDate.localeCompare(E.purchaseDate)).map(h=>e.jsx(Z,{record:h},h.id)),e.jsx(g,{data:i.summary,groupName:i.category.name})]},i.id)),e.jsx(g,{data:u.depreciationReport.summary})]})})]})})};export{re as DepreciationReport,te as getDepreciationReportHref};
|