@accounter/client 0.0.8-alpha-20251023122652-765c7f951395441461726b3b4345eebd020632d7 → 0.0.8-alpha-20251023123704-5af903a2732fbfc73740e2810002ee0b9683cef2

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.
Files changed (92) hide show
  1. package/CHANGELOG.md +19 -16
  2. package/dist/assets/{Checkbox-CpANMiXr.js → Checkbox-H3Qd4S1t.js} +2 -2
  3. package/dist/assets/{Progress-BEKiyNRK.js → Progress-_1EGB-Ud.js} +1 -1
  4. package/dist/assets/{Typography-C0c5augK.js → Typography-CuVqczIo.js} +1 -1
  5. package/dist/assets/{accordion-ZFVTCyDy.js → accordion-DUFvx4CN.js} +1 -1
  6. package/dist/assets/accountant-approvals-C7301eJO.js +1 -0
  7. package/dist/assets/{all-charges-BTyaAlp7.js → all-charges-Dx0Q4kZB.js} +1 -1
  8. package/dist/assets/{arrow-up-down-PQdrJdei.js → arrow-up-down-CehT3kEY.js} +1 -1
  9. package/dist/assets/building-2-CuwOX2TZ.js +6 -0
  10. package/dist/assets/business-CCi3RVvR.js +32 -0
  11. package/dist/assets/business-header-7F1UaeQp.js +1 -0
  12. package/dist/assets/{business-transactions-single-DJqvqlMO.js → business-transactions-single-94CVQ7c0.js} +1 -1
  13. package/dist/assets/{business-trip-BXAjI1mO.js → business-trip-cR3VWzx8.js} +1 -1
  14. package/dist/assets/charges-filters-DfoaNqnd.js +1 -0
  15. package/dist/assets/{charges-ledger-validation-CFc_zJFO.js → charges-ledger-validation-2A3wPF8j.js} +1 -1
  16. package/dist/assets/{chart-C5LuxRSv.js → chart-n1Grhp6o.js} +1 -1
  17. package/dist/assets/{data-table-pagination-g2cF8_uB.js → data-table-pagination-vl-bvd92.js} +1 -1
  18. package/dist/assets/{editable-business-trip-DyQsUJjl.js → editable-business-trip-B3CI9JMc.js} +2 -2
  19. package/dist/assets/index-8z9vrO7T.js +1 -0
  20. package/dist/assets/index-B0RQaZA4.js +1 -0
  21. package/dist/assets/{index-gBZ-7Z07.js → index-BAIrtSSd.js} +1 -1
  22. package/dist/assets/index-BBrtRPns.js +1 -0
  23. package/dist/assets/index-BU7S_VxQ.css +1 -0
  24. package/dist/assets/{index-C99l-a0m.js → index-BhJUmbsL.js} +1 -1
  25. package/dist/assets/{index-6-J73JPC.js → index-BuVXS77A.js} +1 -1
  26. package/dist/assets/index-C1x_UnLe.js +9 -0
  27. package/dist/assets/index-C9f-XFQb.js +1 -0
  28. package/dist/assets/{index-Is4LJW4y.js → index-CEXuDudr.js} +2 -2
  29. package/dist/assets/{index-C0OGGVXE.js → index-CPkFsfdv.js} +2 -2
  30. package/dist/assets/{index-Bpef3vuz.js → index-CaRLwZiB.js} +2 -2
  31. package/dist/assets/index-Cf3-ZPQo.js +1 -0
  32. package/dist/assets/{index-o_W5PWRq.js → index-Cm8oS2Wv.js} +6 -6
  33. package/dist/assets/{index-BSg8ocop.js → index-Cq6OcLVo.js} +2 -2
  34. package/dist/assets/{index-S6eSocQH.js → index-Csw94_Rv.js} +7 -7
  35. package/dist/assets/{index-CJdrnxxy.js → index-D7mzFB80.js} +2 -2
  36. package/dist/assets/{index-CN2818Wt.js → index-DGu24d2w.js} +233 -223
  37. package/dist/assets/index-DqCKwgnm.js +1 -0
  38. package/dist/assets/index-F3Rioz-t.js +1 -0
  39. package/dist/assets/index-PtT3cBhJ.js +1 -0
  40. package/dist/assets/index-YubUek6Y.js +1 -0
  41. package/dist/assets/index-fV50iczO.js +1 -0
  42. package/dist/assets/index-v0pHA7vt.js +1 -0
  43. package/dist/assets/{index.es-DZgQ4YcV.js → index.es-DdWlmUts.js} +1 -1
  44. package/dist/assets/{issue-document-D-JoFiMZ.js → issue-document-Dzhl0JwR.js} +1 -1
  45. package/dist/assets/login-page-D3LEhB5B.js +1 -0
  46. package/dist/assets/{missing-info-charges-CPnjfjfW.js → missing-info-charges-B4HgfJ2l.js} +1 -1
  47. package/dist/assets/page-not-found-CPpHfwNp.js +1 -0
  48. package/dist/assets/{pencil-BUwX_eHK.js → pencil-Ua-VQaqF.js} +1 -1
  49. package/dist/assets/report-commentary-row-BXqG5TF-.js +1 -0
  50. package/dist/assets/save-DxeJtmwS.js +6 -0
  51. package/dist/assets/{sub-C2zifPY5.js → sub-CvDx5dr5.js} +1 -1
  52. package/dist/assets/subMonths-DgP1GRUy.js +1 -0
  53. package/dist/index.html +2 -2
  54. package/package.json +4 -4
  55. package/src/components/business/business-header.tsx +21 -2
  56. package/src/components/businesses/index.tsx +56 -39
  57. package/src/components/common/forms/index.ts +0 -1
  58. package/src/components/common/modals/insert-business.tsx +659 -51
  59. package/src/gql/gql.ts +6 -30
  60. package/src/gql/graphql.ts +7 -30
  61. package/src/providers/urql-client.ts +3 -2
  62. package/src/providers/urql.tsx +0 -5
  63. package/src/router/loaders/business-loader.ts +4 -2
  64. package/src/router/loaders/charge-loader.ts +4 -2
  65. package/dist/assets/accountant-approvals-CpzuSBgK.js +0 -1
  66. package/dist/assets/business-DiQFqEHI.js +0 -42
  67. package/dist/assets/charges-filters-r7FjeZLc.js +0 -1
  68. package/dist/assets/index-2g0J28D2.js +0 -1
  69. package/dist/assets/index-B5j8Fmt8.js +0 -1
  70. package/dist/assets/index-BSBV6pv2.js +0 -9
  71. package/dist/assets/index-BziuNiXZ.js +0 -1
  72. package/dist/assets/index-C7KKktQ5.js +0 -1
  73. package/dist/assets/index-CE3kLG2a.js +0 -1
  74. package/dist/assets/index-CjDRKTTf.js +0 -1
  75. package/dist/assets/index-CzzfC-dD.css +0 -1
  76. package/dist/assets/index-D2xdQJAx.js +0 -1
  77. package/dist/assets/index-DGvh10a7.js +0 -1
  78. package/dist/assets/index-DLI6Z9VU.js +0 -1
  79. package/dist/assets/index-DXL1qPt9.js +0 -1
  80. package/dist/assets/index-T-JiUNDA.js +0 -1
  81. package/dist/assets/login-page-DsHy5amR.js +0 -1
  82. package/dist/assets/page-not-found-CYmXF0n2.js +0 -1
  83. package/dist/assets/report-commentary-row-Bpvvtwpd.js +0 -1
  84. package/dist/assets/save-Ck68rh6u.js +0 -11
  85. package/dist/assets/similar-charges-by-business-modal-bUtiFfAw.js +0 -1
  86. package/dist/assets/subMonths-uUfFviD2.js +0 -1
  87. package/src/components/businesses/all-businesses-row.tsx +0 -87
  88. package/src/components/businesses/cells/hebrew-name.tsx +0 -31
  89. package/src/components/businesses/cells/index.ts +0 -2
  90. package/src/components/businesses/cells/name.tsx +0 -31
  91. package/src/components/common/forms/business-card.tsx +0 -234
  92. package/src/providers/urql-error-handler.ts +0 -27
@@ -8,7 +8,6 @@ import {
8
8
  } from 'urql';
9
9
  import { authExchange } from '@urql/exchange-auth';
10
10
  import { UserService } from '../services/user-service.js';
11
- import { handleUrqlError } from './urql-error-handler.js';
12
11
 
13
12
  /**
14
13
  * Singleton URQL client for use in loaders and server-side operations
@@ -44,7 +43,9 @@ export function getUrqlClient(): Client {
44
43
  exchanges: [
45
44
  mapExchange({
46
45
  onResult(result) {
47
- handleUrqlError(result);
46
+ if (result.error?.networkError) {
47
+ console.error('Network Error:', result.error.networkError);
48
+ }
48
49
  },
49
50
  }),
50
51
  authExchange(async utils => {
@@ -11,7 +11,6 @@ import {
11
11
  import { authExchange } from '@urql/exchange-auth';
12
12
  import { ROUTES } from '../router/routes.js';
13
13
  import { AuthContext } from './auth-guard.js';
14
- import { handleUrqlError } from './urql-error-handler.js';
15
14
 
16
15
  export function UrqlProvider({ children }: { children?: ReactNode }): ReactNode {
17
16
  const { authService } = useContext(AuthContext);
@@ -48,7 +47,6 @@ export function UrqlProvider({ children }: { children?: ReactNode }): ReactNode
48
47
  exchanges: [
49
48
  mapExchange({
50
49
  onResult(result) {
51
- // Handle authentication errors
52
50
  const isAuthError =
53
51
  result?.error?.graphQLErrors.some(e => e.extensions?.code === 'FORBIDDEN') ||
54
52
  result?.error?.response?.status === 401;
@@ -56,10 +54,7 @@ export function UrqlProvider({ children }: { children?: ReactNode }): ReactNode
56
54
  navigate(ROUTES.LOGIN, {
57
55
  state: { message: 'You are not authorized to access this page' },
58
56
  });
59
- return;
60
57
  }
61
-
62
- handleUrqlError(result);
63
58
  },
64
59
  }),
65
60
  authExchange(async utils => {
@@ -13,8 +13,10 @@ export async function businessLoader({ params }: LoaderFunctionArgs) {
13
13
  const client = getUrqlClient();
14
14
  const result = await client.query(BusinessScreenDocument, { businessId }).toPromise();
15
15
 
16
- // GraphQL errors are now handled by toast notifications in urql-client
17
- // Only throw for 404 to show the error boundary
16
+ if (result.error) {
17
+ throw new Response('Failed to load business', { status: 500 });
18
+ }
19
+
18
20
  if (!result.data?.business) {
19
21
  throw new Response('Business not found', { status: 404 });
20
22
  }
@@ -13,8 +13,10 @@ export async function chargeLoader({ params }: LoaderFunctionArgs) {
13
13
  const client = getUrqlClient();
14
14
  const result = await client.query(ChargeScreenDocument, { chargeId }).toPromise();
15
15
 
16
- // GraphQL errors are now handled by toast notifications in urql-client
17
- // Only throw for 404 to show the error boundary
16
+ if (result.error) {
17
+ throw new Response('Failed to load charge', { status: 500 });
18
+ }
19
+
18
20
  if (!result.data?.charge) {
19
21
  throw new Response('Charge not found', { status: 404 });
20
22
  }
@@ -1 +0,0 @@
1
- import{r as s,F as h,u as v,U as C,ai as A,a as F,j as e,c as P,L as b,fr as y}from"./index-CN2818Wt.js";import{C as j}from"./charges-filters-r7FjeZLc.js";import{P as D}from"./Progress-BEKiyNRK.js";import"./sub-C2zifPY5.js";import"./subMonths-uUfFviD2.js";const w=()=>{const{setFiltersContext:c}=s.useContext(h),{get:i}=v(),{userContext:p}=s.useContext(C),[a,x]=s.useState(i("chargesFilters")?JSON.parse(decodeURIComponent(i("chargesFilters"))):{byOwners:p?.context.adminBusinessId?[p?.context.adminBusinessId]:[],sortBy:{field:A.Date,asc:!1},toAnyDate:null,fromAnyDate:null}),[{data:r,fetching:u}]=F({query:y,variables:{filters:a,page:1,limit:999999}}),t=r?.allCharges?.nodes.length??0;let o=0,l=0,n=0;r?.allCharges?.nodes.map(f=>{switch(f.accountantApproval){case"APPROVED":o+=1;break;case"PENDING":l+=1;break;case"UNAPPROVED":n+=1;break}});const d=100*o/t,g=100*l/t,m=100*n/t;return s.useEffect(()=>{c(e.jsx("div",{className:"flex flex-row gap-x-5",children:e.jsx(j,{filter:a,setFilter:x,activePage:1,setPage:()=>{},totalPages:1})}))},[r,u,a,c,x]),e.jsx(P,{title:"Accountant Approvals Status",children:u?e.jsx(b,{className:"h-10 w-10 animate-spin mr-2 self-center"}):e.jsxs("div",{className:"mx-10 mt-5 flex flex-col gap-5",children:[`Total charges: ${t}`,e.jsx(D,{color:"green",radius:"xl",size:"xl",sections:[{value:d,color:"green",label:`${d.toFixed(1)}% (${o})`},{value:g,color:"orange",label:`${g.toFixed(1)}% (${l})`},{value:m,color:"red",label:`${m.toFixed(1)}% (${n})`}]})]})})};export{w as AccountantApprovals};
@@ -1,42 +0,0 @@
1
- import{V as ee,W as Ce,X as Se,Y as ie,p as be,r as N,t as B,s as we,Z as Ms,k as Ie,_ as Ee,D as je,j as e,$ as W,a0 as K,a1 as H,a2 as X,l as De,a3 as Q,a4 as j,a5 as g,a6 as f,a7 as y,Q as T,a8 as I,a9 as C,aa as Qe,B as E,ab as Us,ac as Pe,o as Ye,ad as V,ae as Cs,af as q,ag as zs,U as Ze,a as Oe,ah as qs,O as Gs,C as Ws,ai as Ks,aj as L,ak as ds,al as Hs,am as Xs,an as ue,ao as Je,ap as es,aq as G,ar as ss,as as ns,at as ts,au as as,av as he,aw as le,ax as ce,ay as oe,az as de,aA as me,aB as rs,aC as is,aD as Re,aE as re,aF as Me,aG as Ue,aH as Le,aI as Qs,aJ as se,aK as J,aL as Ys,aM as Zs,aN as Js,aO as ze,aP as en,aQ as sn,aR as nn,aS as tn,aT as an,aU as qe,aV as rn,aW as Ge,aX as ln,aY as bs,aZ as ws,a_ as cn,a$ as on,b0 as Is,b1 as ls,b2 as dn,b3 as ms,b4 as mn,b5 as un,b6 as hn,b7 as xn,b8 as pn,b9 as jn,ba as gn,bb as D,bc as fn,bd as cs,be as vn,bf as yn,bg as Nn,bh as Cn,bi as bn,bj as wn,bk as Z,bl as In,bm as Dn,bn as z,bo as An,bp as kn,bq as Sn,w as Tn,br as En}from"./index-CN2818Wt.js";import{S as os,B as Ds}from"./save-Ck68rh6u.js";import{i as Pn,D as On,f as Bn,E as Ln,L as Ve,a as Ae,C as Vn,A as _n,b as ve,c as Fn,d as We,h as $n,e as Rn,g as As,u as Mn,G as Un,j as us,k as zn,X as ks,Y as Ss,l as qn,m as Gn,R as Wn,n as Kn,o as Hn,p as Xn}from"./chart-C5LuxRSv.js";import{u as Ts,S as Qn}from"./similar-charges-by-business-modal-bUtiFfAw.js";import{P as Yn}from"./pencil-BUwX_eHK.js";import{A as Zn,a as _e,b as Fe,c as hs}from"./accordion-ZFVTCyDy.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 Jn=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]],xs=ee("circle-check",Jn);/**
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 et=[["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=ee("dollar-sign",et);/**
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 st=[["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"}]],nt=ee("file-check",st);/**
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 tt=[["path",{d:"M20 10c0 4.993-5.539 10.193-7.399 11.799a1 1 0 0 1-1.202 0C9.539 20.193 4 14.993 4 10a8 8 0 0 1 16 0",key:"1r0f0z"}],["circle",{cx:"12",cy:"10",r:"3",key:"ilqhr7"}]],Ke=ee("map-pin",tt);/**
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 at=[["path",{d:"M13.832 16.568a1 1 0 0 0 1.213-.303l.355-.465A2 2 0 0 1 17 15h3a2 2 0 0 1 2 2v3a2 2 0 0 1-2 2A18 18 0 0 1 2 4a2 2 0 0 1 2-2h3a2 2 0 0 1 2 2v3a2 2 0 0 1-.8 1.6l-.468.351a1 1 0 0 0-.292 1.233 14 14 0 0 0 6.392 6.384",key:"9njp5v"}]],Es=ee("phone",at);/**
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 rt=[["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"}]],it=ee("plug",rt);/**
32
- * @license lucide-react v0.546.0 - ISC
33
- *
34
- * This source code is licensed under the ISC license.
35
- * See the LICENSE file in the root directory of this source tree.
36
- */const lt=[["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"}]],Ps=ee("shield",lt);/**
37
- * @license lucide-react v0.546.0 - ISC
38
- *
39
- * This source code is licensed under the ISC license.
40
- * See the LICENSE file in the root directory of this source tree.
41
- */const ct=[["path",{d:"M16 7h6v6",key:"box55l"}],["path",{d:"m22 7-8.5 8.5-5-5L2 17",key:"1t1m79"}]],$e=ee("trending-up",ct);function Os(s){switch(s){case Ce.Annual:return"Annual";case Ce.Monthly:return"Monthly";default:throw new Error(`Unsupported Billing Cycle: ${s}`)}}function Bs(s){switch(s){case Se.Enterprise:return"Enterprise";case Se.Pro:return"Pro";default:throw new Error(`Unsupported Subscription plan: ${s}`)}}function ot(s){return ie(s,"yyyy-MM-dd")}const dt="updateAdminBusiness",mt=()=>{const[{fetching:s},n]=be(Ms),t=N.useCallback(async a=>{const i=`Error updating admin business ID [${a.adminBusinessId}]`,l=`${dt}-${a.adminBusinessId}`;B.loading("Updating admin business",{id:l});try{const c=await n(a),r=we(c,i,l,"updateAdminBusiness");if(r)return B.success("Success",{id:l,description:"Admin Business Updated"}),r.updateAdminBusiness}catch(c){console.error(`${i}: ${c}`),B.error("Error",{id:l,description:i,duration:1e5,closeButton:!0})}},[n]);return{fetching:s,updateAdminBusiness:t}},ut=Pe({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:Cs().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 ht(s){return{employerWithholdingTaxAccountNumber:s.employerWithholdingTaxAccountNumber,taxPrepaymentId:s.taxPrepaymentId,nationalInsuranceEmployerId:s.nationalInsuranceEmployerId,advanceTaxRate:s.advanceTaxRate,registrationDate:s.registrationDate?ot(new Date(s.registrationDate)):void 0}}function xt({data:s,refetchBusiness:n}){const t=je(Us,s),[a,i]=N.useState(ps(t)),{updateAdminBusiness:l,fetching:c}=mt(),r=Ie({resolver:Ee(ut),defaultValues:a}),o=async d=>{if(!t)return;const x=Ye(d,r.formState.dirtyFields);if(!x)return;const u=ht(x);await l({adminBusinessId:t.id,fields:u}),n?.()};return N.useEffect(()=>{if(t){const d=ps(t);i(d),r.reset(d)}},[t,r]),e.jsxs(W,{children:[e.jsxs(K,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ps,{className:"h-5 w-5 text-primary"}),e.jsx(H,{children:"Admin Business Configuration"})]}),e.jsx(X,{children:"Tax and registration information for the business operating this application"})]}),e.jsx(De,{...r,children:e.jsxs("form",{onSubmit:r.handleSubmit(o),className:"space-y-6",children:[e.jsx(Q,{children:e.jsxs("div",{className:"grid gap-6 md:grid-cols-2",children:[e.jsx(j,{control:r.control,name:"employerWithholdingTaxAccountNumber",render:({field:d,fieldState:x})=>e.jsxs(g,{children:[e.jsx(f,{children:"Employer Withholding Tax Account Number"}),e.jsx(y,{children:e.jsx(T,{placeholder:"Enter account number",...d,className:I(x)})}),e.jsx(C,{})]})}),e.jsx(j,{control:r.control,name:"taxPrepaymentId",render:({field:d,fieldState:x})=>e.jsxs(g,{children:[e.jsx(f,{children:"Tax Prepayment ID"}),e.jsx(y,{children:e.jsx(T,{placeholder:"Enter prepayment ID",...d,className:I(x)})}),e.jsx(C,{})]})}),e.jsx(j,{control:r.control,name:"nationalInsuranceEmployerId",render:({field:d,fieldState:x})=>e.jsxs(g,{children:[e.jsx(f,{children:"National Insurance Employer ID"}),e.jsx(y,{children:e.jsx(T,{placeholder:"Enter employer ID",...d,className:I(x)})}),e.jsx(C,{})]})}),e.jsx(j,{control:r.control,name:"advanceTaxRate",render:({field:d,fieldState:x})=>e.jsxs(g,{children:[e.jsx(f,{children:"Advance Tax Rate (%)"}),e.jsx(y,{children:e.jsx(T,{type:"number",step:"0.01",min:"0",max:"100",placeholder:"Enter tax rate",...d,className:I(x)})}),e.jsx(C,{})]})}),e.jsx(j,{control:r.control,name:"registrationDate",render:({field:d,fieldState:x})=>e.jsxs(g,{children:[e.jsx(f,{children:"Registration Date"}),e.jsx(y,{children:e.jsx(T,{type:"date",...d,className:I(x)})}),e.jsx(C,{})]})})]})}),e.jsx(Qe,{className:"flex justify-end border-t mt-4 pt-6",children:e.jsxs(E,{type:"submit",disabled:c||Object.keys(r.formState.dirtyFields).length===0||!r.formState.isValid,children:[e.jsx(os,{className:"h-4 w-4"}),"Save Changes"]})})]})})]})}function pt({data:s}){const n=je(zs,s);return!n||n.__typename!=="LtdFinancialEntity"?e.jsx("div",{}):e.jsx("header",{className:"sticky top-0 z-50 w-full border-b border-border bg-card/95 backdrop-blur supports-[backdrop-filter]:bg-card/60",children:e.jsx("div",{className:"container mx-auto px-4 md:px-6 lg:px-8 max-w-7xl",children:e.jsxs("div",{className:"flex h-16 items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0 flex-1",children:[e.jsx("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-lg bg-accent",children:e.jsx(Ds,{className:"h-5 w-5 text-accent-foreground"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("h1",{className:"text-lg font-semibold text-foreground",children:n.name}),e.jsx(q,{variant:"secondary",children:"Active"})]}),e.jsxs("p",{className:"text-sm text-muted-foreground truncate",children:["Business ID: ",n.id]})]})]}),e.jsxs("div",{className:"hidden md:flex items-center gap-6 text-sm",children:[n.governmentId&&e.jsxs("div",{className:"text-right",children:[e.jsx("p",{className:"text-muted-foreground",children:"Tax ID"}),e.jsx("p",{className:"font-medium text-foreground",children:n.governmentId})]}),e.jsxs("div",{className:"text-right",children:[e.jsx("p",{className:"text-muted-foreground",children:"Since"}),e.jsx("p",{className:"font-medium text-foreground",children:ie(n.createdAt,"MMM yyyy")})]})]})]})})})}function jt({businessId:s}){const{userContext:n}=N.useContext(Ze),[t,a]=N.useState(1),[{data:i,fetching:l}]=Oe({query:qs,variables:{filters:{byOwners:n?.context.adminBusinessId?[n.context.adminBusinessId]:void 0,sortBy:{field:Ks.Date,asc:!1},byBusinesses:[s]},page:t,limit:100}}),c=i?.allCharges?.pageInfo.totalPages??1,r=i?.allCharges?.nodes??[];return l?e.jsx("div",{children:"Loading charges..."}):e.jsxs(W,{children:[e.jsxs(K,{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(H,{children:"Charges"}),e.jsx(X,{children:"Recurring and one-time charges for this business"})]})}),c>1&&e.jsx(Gs,{className:"flex-fit",value:t,onChange:a,total:c})]}),e.jsx(Q,{children:e.jsx("div",{className:"rounded-md border",children:e.jsx(Ws,{data:r,isAllOpened:!1})})})]})}var gt=["type","layout","connectNulls","ref"],ft=["key"];function xe(s){"@babel/helpers - typeof";return xe=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},xe(s)}function js(s,n){if(s==null)return{};var t=vt(s,n),a,i;if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(s);for(i=0;i<l.length;i++)a=l[i],!(n.indexOf(a)>=0)&&Object.prototype.propertyIsEnumerable.call(s,a)&&(t[a]=s[a])}return t}function vt(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 Ne(){return Ne=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},Ne.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(i){return Object.getOwnPropertyDescriptor(s,i).enumerable})),t.push.apply(t,a)}return t}function F(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 ae(s){return bt(s)||Ct(s)||Nt(s)||yt()}function yt(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
42
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function Nt(s,n){if(s){if(typeof s=="string")return He(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 He(s,n)}}function Ct(s){if(typeof Symbol<"u"&&s[Symbol.iterator]!=null||s["@@iterator"]!=null)return Array.from(s)}function bt(s){if(Array.isArray(s))return He(s)}function He(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 wt(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,Vs(a.key),a)}}function It(s,n,t){return n&&fs(s.prototype,n),t&&fs(s,t),Object.defineProperty(s,"prototype",{writable:!1}),s}function Dt(s,n,t){return n=Te(n),At(s,Ls()?Reflect.construct(n,t||[],Te(s).constructor):n.apply(s,t))}function At(s,n){if(n&&(xe(n)==="object"||typeof n=="function"))return n;if(n!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return kt(s)}function kt(s){if(s===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return s}function Ls(){try{var s=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch{}return(Ls=function(){return!!s})()}function Te(s){return Te=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},Te(s)}function St(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&&Xe(s,n)}function Xe(s,n){return Xe=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(a,i){return a.__proto__=i,a},Xe(s,n)}function M(s,n,t){return n=Vs(n),n in s?Object.defineProperty(s,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):s[n]=t,s}function Vs(s){var n=Tt(s,"string");return xe(n)=="symbol"?n:n+""}function Tt(s,n){if(xe(s)!="object"||!s)return s;var t=s[Symbol.toPrimitive];if(t!==void 0){var a=t.call(s,n);if(xe(a)!="object")return a;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(s)}var pe=(function(s){function n(){var t;wt(this,n);for(var a=arguments.length,i=new Array(a),l=0;l<a;l++)i[l]=arguments[l];return t=Dt(this,n,[].concat(i)),M(t,"state",{isAnimationFinished:!0,totalLength:0}),M(t,"generateSimpleStrokeDasharray",function(c,r){return"".concat(r,"px ").concat(c-r,"px")}),M(t,"getStrokeDasharray",function(c,r,o){var d=o.reduce(function(b,S){return b+S});if(!d)return t.generateSimpleStrokeDasharray(r,c);for(var x=Math.floor(c/d),u=c%d,h=r-c,A=[],m=0,p=0;m<o.length;p+=o[m],++m)if(p+o[m]>u){A=[].concat(ae(o.slice(0,m)),[u-p]);break}var k=A.length%2===0?[0,h]:[h];return[].concat(ae(n.repeat(o,x)),ae(A),k).map(function(b){return"".concat(b,"px")}).join(", ")}),M(t,"id",Mn("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 St(n,s),It(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,i){if(this.props.isAnimationActive&&!this.state.isAnimationFinished)return null;var l=this.props,c=l.points,r=l.xAxis,o=l.yAxis,d=l.layout,x=l.children,u=Bn(x,Ln);if(!u)return null;var h=function(p,k){return{x:p.x,y:p.y,value:p.value,errorVal:As(p.payload,k)}},A={clipPath:a?"url(#clipPath-".concat(i,")"):null};return L.createElement(Ve,A,u.map(function(m){return L.cloneElement(m,{key:"bar-".concat(m.props.dataKey),data:c,xAxis:r,yAxis:o,layout:d,dataPointFormatter:h})}))}},{key:"renderDots",value:function(a,i,l){var c=this.props.isAnimationActive;if(c&&!this.state.isAnimationFinished)return null;var r=this.props,o=r.dot,d=r.points,x=r.dataKey,u=Ae(this.props,!1),h=Ae(o,!0),A=d.map(function(p,k){var b=F(F(F({key:"dot-".concat(k),r:3},u),h),{},{index:k,cx:p.x,cy:p.y,value:p.value,dataKey:x,payload:p.payload,points:d});return n.renderDotItem(o,b)}),m={clipPath:a?"url(#clipPath-".concat(i?"":"dots-").concat(l,")"):null};return L.createElement(Ve,Ne({className:"recharts-line-dots",key:"dots"},m),A)}},{key:"renderCurveStatically",value:function(a,i,l,c){var r=this.props,o=r.type,d=r.layout,x=r.connectNulls;r.ref;var u=js(r,gt),h=F(F(F({},Ae(u,!0)),{},{fill:"none",className:"recharts-line-curve",clipPath:i?"url(#clipPath-".concat(l,")"):null,points:a},c),{},{type:o,layout:d,connectNulls:x});return L.createElement(Vn,Ne({},h,{pathRef:this.pathRef}))}},{key:"renderCurveWithAnimation",value:function(a,i){var l=this,c=this.props,r=c.points,o=c.strokeDasharray,d=c.isAnimationActive,x=c.animationBegin,u=c.animationDuration,h=c.animationEasing,A=c.animationId,m=c.animateNewValues,p=c.width,k=c.height,b=this.state,S=b.prevPoints,_=b.totalLength;return L.createElement(_n,{begin:x,duration:u,isActive:d,easing:h,from:{t:0},to:{t:1},key:"line-".concat(A),onAnimationEnd:this.handleAnimationEnd,onAnimationStart:this.handleAnimationStart},function(R){var $=R.t;if(S){var Y=S.length/r.length,U=r.map(function(O,Be){var ge=Math.floor(Be*Y);if(S[ge]){var fe=S[ge],te=ve(fe.x,O.x),Fs=ve(fe.y,O.y);return F(F({},O),{},{x:te($),y:Fs($)})}if(m){var $s=ve(p*2,O.x),Rs=ve(k/2,O.y);return F(F({},O),{},{x:$s($),y:Rs($)})}return F(F({},O),{},{x:O.x,y:O.y})});return l.renderCurveStatically(U,a,i)}var ne=ve(0,_),v=ne($),w;if(o){var P="".concat(o).split(/[,\s]+/gim).map(function(O){return parseFloat(O)});w=l.getStrokeDasharray(v,_,P)}else w=l.generateSimpleStrokeDasharray(_,v);return l.renderCurveStatically(r,a,i,{strokeDasharray:w})})}},{key:"renderCurve",value:function(a,i){var l=this.props,c=l.points,r=l.isAnimationActive,o=this.state,d=o.prevPoints,x=o.totalLength;return r&&c&&c.length&&(!d&&x>0||!Fn(d,c))?this.renderCurveWithAnimation(a,i):this.renderCurveStatically(c,a,i)}},{key:"render",value:function(){var a,i=this.props,l=i.hide,c=i.dot,r=i.points,o=i.className,d=i.xAxis,x=i.yAxis,u=i.top,h=i.left,A=i.width,m=i.height,p=i.isAnimationActive,k=i.id;if(l||!r||!r.length)return null;var b=this.state.isAnimationFinished,S=r.length===1,_=ds("recharts-line",o),R=d&&d.allowDataOverflow,$=x&&x.allowDataOverflow,Y=R||$,U=We(k)?this.id:k,ne=(a=Ae(c,!1))!==null&&a!==void 0?a:{r:3,strokeWidth:2},v=ne.r,w=v===void 0?3:v,P=ne.strokeWidth,O=P===void 0?2:P,Be=$n(c)?c:{},ge=Be.clipDot,fe=ge===void 0?!0:ge,te=w*2+O;return L.createElement(Ve,{className:_},R||$?L.createElement("defs",null,L.createElement("clipPath",{id:"clipPath-".concat(U)},L.createElement("rect",{x:R?h:h-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:h-te/2,y:u-te/2,width:A+te,height:m+te}))):null,!S&&this.renderCurve(Y,U),this.renderErrorBar(Y,U),(S||c)&&this.renderDots(Y,fe,U),(!p||b)&&Rn.renderCallByParent(this.props,r))}}],[{key:"getDerivedStateFromProps",value:function(a,i){return a.animationId!==i.prevAnimationId?{prevAnimationId:a.animationId,curPoints:a.points,prevPoints:i.curPoints}:a.points!==i.curPoints?{curPoints:a.points}:null}},{key:"repeat",value:function(a,i){for(var l=a.length%2!==0?[].concat(ae(a),[0]):a,c=[],r=0;r<i;++r)c=[].concat(ae(c),ae(l));return c}},{key:"renderDotItem",value:function(a,i){var l;if(L.isValidElement(a))l=L.cloneElement(a,i);else if(Pn(a))l=a(i);else{var c=i.key,r=js(i,ft),o=ds("recharts-line-dot",typeof a!="boolean"?a.className:"");l=L.createElement(On,Ne({key:c},r,{className:o}))}return l}}])})(N.PureComponent);M(pe,"displayName","Line");M(pe,"defaultProps",{xAxisId:0,yAxisId:0,connectNulls:!1,activeDot:!0,dot:!0,legendType:"line",stroke:"#3182bd",strokeWidth:1,fill:"#fff",points:[],isAnimationActive:!Un.isSsr,animateNewValues:!0,animationBegin:0,animationDuration:1500,animationEasing:"ease",hide:!1,label:!1});M(pe,"getComposedData",function(s){var n=s.props,t=s.xAxis,a=s.yAxis,i=s.xAxisTicks,l=s.yAxisTicks,c=s.dataKey,r=s.bandSize,o=s.displayedData,d=s.offset,x=n.layout,u=o.map(function(h,A){var m=As(h,c);return x==="horizontal"?{x:us({axis:t,ticks:i,bandSize:r,entry:h,index:A}),y:We(m)?null:a.scale(m),value:m,payload:h}:{x:We(m)?null:t.scale(m),y:us({axis:a,ticks:l,bandSize:r,entry:h,index:A}),value:m,payload:h}});return F({points:u,layout:x},d)});var Et=zn({chartName:"LineChart",GraphicalChild:pe,axisComponents:[{axisType:"xAxis",AxisComp:ks},{axisType:"yAxis",AxisComp:Ss}],formatAxisMap:qn});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 Pt(){const s=ye.reduce((t,a)=>t+a.revenue,0),n=s/ye.length;return e.jsxs(W,{children:[e.jsxs(K,{children:[e.jsx(H,{children:"Revenue Analytics"}),e.jsx(X,{children:"Revenue and expenses over time"})]}),e.jsxs(Q,{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($e,{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($e,{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($e,{className:"h-3 w-3"}),e.jsx("span",{children:"+8.0% from last month"})]})]})]}),e.jsx(Gn,{config:{revenue:{label:"Revenue",color:"hsl(var(--chart-1))"},expenses:{label:"Expenses",color:"hsl(var(--chart-2))"}},className:"h-[400px]",children:e.jsx(Wn,{width:"100%",height:"100%",children:e.jsxs(Et,{data:ye,margin:{top:5,right:10,left:10,bottom:5},children:[e.jsx(Kn,{strokeDasharray:"3 3",className:"stroke-muted"}),e.jsx(ks,{dataKey:"month",className:"text-xs",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(Ss,{className:"text-xs",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(Hn,{content:e.jsx(Xn,{})}),e.jsx(pe,{type:"monotone",dataKey:"revenue",stroke:"var(--color-revenue)",strokeWidth:2,dot:{fill:"var(--color-revenue)",r:4}}),e.jsx(pe,{type:"monotone",dataKey:"expenses",stroke:"var(--color-expenses)",strokeWidth:2,dot:{fill:"var(--color-expenses)",r:4}})]})})})]})]})}const Ot="insertClient",Bt=()=>{const[{fetching:s},n]=be(Hs),t=N.useCallback(async a=>{const i=`Error creating client [${a.fields.businessId}]`,l=`${Ot}-${a.fields.businessId}`;B.loading("Creating Client...",{id:l});try{const c=await n(a),r=we(c,i,l,"insertClient");if(r)return B.success("Success",{id:l,description:`Client [${a.fields.businessId}] was created`}),r.insertClient}catch(c){console.error(`${i}: ${c}`),B.error("Error",{id:l,description:i,duration:1e5,closeButton:!0})}},[n]);return{fetching:s,insertClient:t}},Lt="updateClient",_s=()=>{const[{fetching:s},n]=be(Xs),t=N.useCallback(async a=>{const i=`Error updating client ID [${a.businessId}]`,l=`${Lt}-${a.businessId}`;B.loading("Updating client",{id:l});try{const c=await n(a),r=we(c,i,l,"updateClient");if(r)return B.success("Success",{id:l,description:"Client updated"}),r.updateClient}catch(c){console.error(`${i}: ${c}`),B.error("Error",{id:l,description:i,duration:1e5,closeButton:!0})}},[n]);return{fetching:s,updateClient:t}},Vt=Pe({id:Re().optional(),emails:Me(Ue()).optional(),generatedDocumentType:re(Object.values(ue)),greenInvoiceId:Re().optional(),hiveId:V().optional()});function _t({client:s,businessId:n,onDone:t}){const[a,i]=N.useState(!1),[l,c]=N.useState(null),{updateClient:r}=_s(),{insertClient:o}=Bt(),[d,x]=N.useState(""),u={id:n,generatedDocumentType:ue.Proforma,emails:[]},h=Ie({resolver:Ee(Vt),defaultValues:s||u});N.useEffect(()=>{s&&(c(s),h.reset({emails:s.emails,greenInvoiceId:s.greenInvoiceId,hiveId:s.hiveId,generatedDocumentType:s.generatedDocumentType,id:s.id}),i(!0))},[s,h]);const A=()=>{c(null),h.reset(u),i(!0)},m=()=>{if(d.trim()){const b=h.getValues("emails");h.setValue("emails",[...b??[],d.trim()],{shouldDirty:!0}),x("")}},p=b=>{const S=h.getValues("emails");h.setValue("emails",(S??[]).filter((_,R)=>R!==b),{shouldDirty:!0})},k=N.useCallback(async b=>{if(l)r({businessId:n,fields:b});else{if(!b.greenInvoiceId){h.setError("greenInvoiceId",{message:"Green Invoice ID is required"});return}o({fields:{...b,greenInvoiceId:b.greenInvoiceId,businessId:n}})}i(!1),c(null),t?.()},[l,t,r,n,o,h]);return e.jsxs(Je,{open:a,onOpenChange:i,children:[e.jsx(es,{asChild:!0,children:e.jsxs(E,{size:"sm",onClick:A,children:[e.jsx(G,{className:"h-4 w-4 mr-2"}),"New Client"]})}),e.jsxs(ss,{className:"max-w-2xl max-h-[90vh] overflow-y-auto",children:[e.jsxs(ns,{children:[e.jsx(ts,{children:l?"Edit Client":"Create New Client"}),e.jsx(as,{children:l?"Update client details":"Add a new client with all required details"})]}),e.jsx(De,{...h,children:e.jsxs("form",{onSubmit:h.handleSubmit(k),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:h.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(T,{placeholder:"Add email...",value:d,onChange:S=>x(S.target.value),onKeyDown:S=>{S.key==="Enter"&&(S.preventDefault(),m())}}),e.jsx(E,{type:"button",size:"sm",onClick:m,children:e.jsx(G,{className:"h-4 w-4"})})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:b.value?.map((S,_)=>e.jsxs(q,{variant:"secondary",className:"gap-1",children:[S,e.jsx(E,{variant:"ghost",size:"icon",className:"p-0 size-3",onClick:()=>p(_),children:e.jsx(he,{className:"size-3 cursor-pointer"})})]},_))}),e.jsx(C,{})]})}),e.jsx(j,{control:h.control,name:"generatedDocumentType",render:({field:b})=>e.jsxs(g,{children:[e.jsx(f,{children:"Default Document Type"}),e.jsxs(le,{onValueChange:b.onChange,defaultValue:b.value,children:[e.jsx(y,{children:e.jsx(ce,{children:e.jsx(oe,{})})}),e.jsx(de,{children:Object.values(ue).map(S=>e.jsx(me,{value:S,children:rs(S)},S))})]}),e.jsx(C,{})]})}),e.jsx(j,{control:h.control,name:"greenInvoiceId",render:({field:b})=>e.jsxs(g,{children:[e.jsx(f,{children:"Green Invoice ID"}),e.jsx(y,{children:e.jsx(T,{type:"text",placeholder:"Enter Green Invoice ID",...b,required:!l})}),e.jsx(C,{})]})}),e.jsx(j,{control:h.control,name:"hiveId",render:({field:b})=>e.jsxs(g,{children:[e.jsx(f,{children:"Hive ID"}),e.jsx(y,{children:e.jsx(T,{type:"text",placeholder:"Enter Hive ID",...b,required:!l})}),e.jsx(C,{})]})})]})}),e.jsxs(is,{children:[e.jsx(E,{type:"button",variant:"outline",onClick:()=>i(!1),children:"Cancel"}),e.jsx(E,{type:"submit",children:l?"Update Client":"Create Client"})]})]})})]})]})}const Ft=Object.values(tn);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 $t(s){const t=s.internalLinks||s.useMessageBody||s.attachmentTypes?{internalEmailLinks:s.internalLinks,emailBody:s.useMessageBody,attachments:s.attachmentTypes}:void 0,i=s.description||s.tags||s.phrases||s.emails||t?{description:s.description,tags:s.tags?.map(l=>({id:l})),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:i}}function Rt({data:s,refetchBusiness:n}){const t=je(Qs,s),[a,i]=N.useState(vs(t)),{userContext:l}=N.useContext(Ze),{updateBusiness:c,fetching:r}=Ts(),[o,d]=N.useState(!1),[x,u]=N.useState(void 0),h=Ie({defaultValues:a}),A=async p=>{if(!t||!l?.context.adminBusinessId)return;const k=Ye(p,h.formState.dirtyFields);if(!k)return;const b=$t(k);await c({businessId:t.id,ownerId:l.context.adminBusinessId,fields:b}),k.tags?.length||k.description?(u({tagIds:k.tags?.map(S=>({id:S})),description:k.description}),d(!0)):n?.()};if(N.useEffect(()=>{if(t){const p=vs(t);i(p),h.reset(p)}},[t,h]),!t)return e.jsx("div",{});const m=h.watch("isClient");return e.jsxs(W,{children:[e.jsx(K,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(H,{children:"Configurations"}),e.jsx(X,{children:"Business status, tax settings, automation rules, and integration preferences"})]}),!m&&e.jsx(_t,{businessId:t.id,onDone:n})]})}),e.jsx(De,{...h,children:e.jsxs("form",{onSubmit:h.handleSubmit(A),children:[e.jsxs(Q,{className:"space-y-6",children:[e.jsx(Mt,{form:h}),e.jsx(Le,{}),e.jsx(Ut,{form:h}),e.jsx(Le,{}),e.jsx(zt,{form:h}),e.jsx(Le,{}),e.jsx(qt,{form:h})]}),e.jsx(Qe,{className:"flex justify-end border-t pt-6",children:e.jsxs(E,{type:"submit",disabled:r||Object.keys(h.formState.dirtyFields).length===0,children:[e.jsx(os,{className:"h-4 w-4 mr-2"}),"Save Changes"]})})]})}),e.jsx(Qn,{businessId:t.id,tagIds:x?.tagIds,description:x?.description,open:o,onOpenChange:d,onClose:n})]})}function Mt({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(se,{children:"Mark this business as a client"})]}),e.jsx(y,{children:e.jsx(J,{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(se,{children:"Business is currently active"})]}),e.jsx(y,{children:e.jsx(J,{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(se,{children:"Generate ledger for receipt documents if no invoice available"})]}),e.jsx(y,{children:e.jsx(J,{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(se,{children:"Skip document validation for common charges"})]}),e.jsx(y,{children:e.jsx(J,{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(se,{children:"Mute missing VAT indicator"})]}),e.jsx(y,{children:e.jsx(J,{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(se,{children:"Business is exempt from VAT requirements"})]}),e.jsx(y,{children:e.jsx(J,{checked:n.value,onCheckedChange:n.onChange,className:I(t)})})]})})]})]})}function Ut({form:s}){const{selectableTaxCategories:n,fetching:t}=Ys(),{selectableSortCodes:a,fetching:i,sortCodes:l}=Zs(),{selectableTags:c,fetching:r}=Js(),o=N.useCallback(d=>{if(d){const x=l.find(u=>Number(u.key)===Number(d));x&&(x.defaultIrsCode?s.setValue("irsCode",x.defaultIrsCode,{shouldDirty:!0}):s.setValue("irsCode",null,{shouldDirty:!0}))}},[s,l]);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:x})=>e.jsxs(g,{children:[e.jsx(f,{children:"Sort Code"}),e.jsx(y,{children:e.jsx(ze,{onChange:u=>{o(u),d.onChange(u)},data:a,value:d.value,disabled:i,placeholder:"Scroll to see all options",formPart:!0,triggerProps:{className:I(x)}})}),e.jsx(C,{})]})}),e.jsx(j,{control:s.control,name:"taxCategory",render:({field:d,fieldState:x})=>e.jsxs(g,{children:[e.jsx(f,{children:"Tax Category"}),e.jsx(y,{children:e.jsx(ze,{data:n,disabled:t,value:d.value,onChange:d.onChange,placeholder:"Scroll to see all options",formPart:!0,triggerProps:{className:I(x)}})}),e.jsx(C,{})]})}),e.jsx(j,{control:s.control,name:"pcn874RecordType",render:({field:d,fieldState:x})=>e.jsxs(g,{children:[e.jsx(f,{children:"PCN874 Record Type"}),e.jsxs(le,{onValueChange:d.onChange,value:d.value,children:[e.jsx(y,{children:e.jsx(ce,{className:I(x),children:e.jsx(oe,{})})}),e.jsx(de,{children:Object.entries(en).map(([u,h])=>e.jsx(me,{value:u,children:`${h} (${u})`},u))})]}),e.jsx(C,{})]})}),e.jsx(j,{control:s.control,name:"irsCode",render:({field:d,fieldState:x})=>e.jsxs(g,{children:[e.jsx(f,{children:"IRS Code"}),e.jsx(y,{children:e.jsx(sn,{value:d.value??void 0,onValueChange:u=>d.onChange(u??null),hideControls:!0,decimalScale:0,className:I(x)})}),e.jsx(C,{})]})}),e.jsx(j,{control:s.control,name:"description",render:({field:d,fieldState:x})=>e.jsxs(g,{children:[e.jsx(f,{children:"Charge Description"}),e.jsx(y,{children:e.jsx(T,{placeholder:"Enter default charge description",...d,className:I(x)})}),e.jsx(C,{})]})}),e.jsx(j,{control:s.control,name:"tags",render:({field:d,fieldState:x})=>e.jsxs(g,{children:[e.jsx(f,{children:"Tags"}),e.jsx(y,{children:e.jsx(nn,{options:Object.values(c).map(({value:u,label:h})=>({label:h,value:u})),onValueChange:d.onChange,defaultValue:d.value,value:d.value,placeholder:"Select Default Tags",variant:"default",disabled:r,className:I(x)})}),e.jsx(C,{})]})})]})]})}function zt({form:s}){const[n,t]=N.useState(""),[a,i]=N.useState(""),l=()=>{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}),i("")}},r=d=>{const x=s.getValues("phrases");s.setValue("phrases",x.filter((u,h)=>h!==d),{shouldDirty:!0})},o=d=>{const x=s.getValues("emails");s.setValue("emails",x.filter((u,h)=>h!==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:x})=>e.jsxs(g,{children:[e.jsx(f,{children:"Phrases"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(T,{placeholder:"Add phrase...",value:n,onChange:u=>t(u.target.value),onKeyDown:u=>{u.key==="Enter"&&(u.preventDefault(),l())},className:I(x)}),e.jsx(E,{type:"button",size:"sm",onClick:l,children:e.jsx(G,{className:"h-4 w-4"})})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:d.value?.map((u,h)=>e.jsxs(q,{variant:"secondary",className:"gap-1",children:[u,e.jsx(E,{variant:"ghost",size:"icon",className:"p-0 size-3",onClick:()=>r(h),children:e.jsx(he,{className:"size-3 cursor-pointer",onClick:()=>r(h)})})]},h))}),e.jsx(C,{})]})}),e.jsx(j,{control:s.control,name:"emails",render:({field:d,fieldState:x})=>e.jsxs(g,{children:[e.jsx(f,{children:"Email Addresses"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(T,{type:"email",placeholder:"Add email...",value:a,onChange:u=>i(u.target.value),onKeyDown:u=>{u.key==="Enter"&&(u.preventDefault(),c())},className:I(x)}),e.jsx(E,{type:"button",size:"sm",onClick:c,children:e.jsx(G,{className:"h-4 w-4"})})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:d.value?.map((u,h)=>e.jsxs(q,{variant:"secondary",className:"gap-1",children:[u,e.jsx(E,{variant:"ghost",size:"icon",className:"p-0 size-3",onClick:()=>o(h),children:e.jsx(he,{className:"size-3 cursor-pointer"})})]},h))}),e.jsx(C,{})]})})]})}function qt({form:s}){const[n,t]=N.useState(""),a=()=>{if(n.trim()){const c=s.getValues("internalLinks");s.setValue("internalLinks",[...c,n.trim()],{shouldDirty:!0}),t("")}},i=c=>{const r=s.getValues("attachmentTypes");s.setValue("attachmentTypes",r?.includes(c)?r.filter(o=>o!==c):[...r,c],{shouldDirty:!0})},l=c=>{const r=s.getValues("internalLinks");s.setValue("internalLinks",r.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:r})=>e.jsxs(g,{children:[e.jsx(f,{children:"Attachment Types"}),e.jsx("div",{className:I(r)+" rounded-md flex flex-wrap gap-2",children:Ft.map(o=>e.jsx(q,{variant:c.value?.includes(o)?"default":"outline",className:"cursor-pointer",onClick:()=>i(o),children:o},o))}),e.jsx(C,{})]})}),e.jsx(j,{control:s.control,name:"internalLinks",render:({field:c,fieldState:r})=>e.jsxs(g,{children:[e.jsx(f,{children:"Internal Links"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(T,{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(G,{className:"h-4 w-4"})})]}),e.jsx("div",{className:I(r)+" flex flex-wrap gap-2 rounded-md",children:c.value?.map((o,d)=>e.jsxs(q,{variant:"secondary",className:"gap-1 max-w-xs truncate",children:[o,e.jsx(E,{variant:"ghost",size:"icon",className:"p-0 size-3",onClick:()=>l(d),children:e.jsx(he,{className:"size-3 cursor-pointer flex-shrink-0"})})]},d))}),e.jsx(C,{})]})}),e.jsx(j,{control:s.control,name:"useMessageBody",render:({field:c,fieldState:r})=>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(se,{children:"Extract information from email message body"})]}),e.jsx(y,{children:e.jsx(J,{checked:c.value,onCheckedChange:c.onChange,className:I(r)})})]})})]})}const Gt=Pe({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:bs("Invalid URL").optional().or(ws("")),generalContacts:Me(Ue()).optional(),billingEmails:Me(Ue()).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 Wt(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 Kt({data:s,refetchBusiness:n}){const t=je(ln,s),[a,i]=N.useState(ys(t)),{userContext:l}=N.useContext(Ze),{updateBusiness:c,fetching:r}=Ts(),o=Ie({resolver:Ee(Gt),defaultValues:a}),{countries:d,fetching:x}=an(),[u,h]=N.useState(""),[A,m]=N.useState(""),p=o.watch("locality"),k=o.watch("address"),b=o.watch("localAddress");N.useEffect(()=>{k!==a.address&&o.setValue("address",k,{shouldDirty:!0})},[k,a.address,o]),N.useEffect(()=>{b!==a.localAddress&&o.setValue("localAddress",b,{shouldDirty:!0})},[b,a.localAddress,o]);const S=t&&"clientInfo"in t&&!!t.clientInfo,_=p===l?.context.locality,R=v=>{u.trim()&&(o.setValue("generalContacts",[...v,u.trim()],{shouldDirty:!0}),h(""))},$=(v,w)=>{o.setValue("generalContacts",v.filter((P,O)=>O!==w),{shouldDirty:!0})},Y=v=>{A.trim()&&(o.setValue("billingEmails",[...v,A.trim()],{shouldDirty:!0}),m(""))},U=(v,w)=>{o.setValue("billingEmails",v.filter((P,O)=>O!==w),{shouldDirty:!0})},ne=async v=>{if(!t||!l?.context.adminBusinessId)return;const w=Ye(v,o.formState.dirtyFields);if(!w)return;const P=Wt(w);await c({businessId:t.id,ownerId:l.context.adminBusinessId,fields:P}),n?.()};return N.useEffect(()=>{if(t){const v=ys(t);i(v),o.reset(v)}},[t,o]),e.jsxs(W,{children:[e.jsxs(K,{children:[e.jsx(H,{children:"Contact Information"}),e.jsx(X,{children:"Business contact details and address information"})]}),e.jsx(De,{...o,children:e.jsxs("form",{onSubmit:o.handleSubmit(ne),children:[e.jsx(Q,{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(y,{children:e.jsx(T,{...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(ze,{onChange:v.onChange,data:d.map(P=>({value:P.code,label:P.name})),value:v.value,disabled:x,placeholder:"Scroll to see all options",formPart:!0,triggerProps:{className:I(w)}}),e.jsx(C,{})]})}),_&&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(y,{children:e.jsx(T,{...v,placeholder:"Business name in local language",className:I(w)})}),e.jsx(C,{})]})}),_&&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(y,{children:e.jsx(T,{...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(Ke,{className:"h-4 w-4"}),"Address"]}),e.jsx(y,{children:e.jsx(qe,{...v,rows:3,placeholder:"Enter business address",className:I(w)})}),e.jsx(C,{})]})}),_&&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(Ke,{className:"h-4 w-4"}),"Local Address"]}),e.jsx(y,{children:e.jsx(qe,{...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(Es,{className:"h-4 w-4"}),"Phone"]}),e.jsx(y,{children:e.jsx(T,{...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(rn,{className:"h-4 w-4"}),"Website"]}),e.jsx(y,{children:e.jsx(T,{...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(Ge,{className:"h-4 w-4"}),"General Contacts"]}),e.jsx(y,{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,O)=>e.jsxs(q,{variant:"secondary",className:"gap-1 pr-1",children:[P,e.jsx("button",{type:"button",onClick:()=>$(v.value??[],O),className:"ml-1 hover:bg-muted rounded-sm p-0.5",children:e.jsx(he,{className:"h-3 w-3"})})]},O))}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(T,{value:u,onChange:P=>h(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(G,{className:"h-4 w-4"})})]})]})}),e.jsx(C,{})]})}),S&&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(Ge,{className:"h-4 w-4"}),"Billing Emails"]}),e.jsx(y,{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,O)=>e.jsxs(q,{variant:"secondary",className:"gap-1 pr-1",children:[P,e.jsx("button",{type:"button",onClick:()=>U(v.value??[],O),className:"ml-1 hover:bg-muted rounded-sm p-0.5",children:e.jsx(he,{className:"h-3 w-3"})})]},O))}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(T,{value:A,onChange:P=>m(P.target.value),onKeyDown:P=>{P.key==="Enter"&&(P.preventDefault(),Y(v.value??[]))},placeholder:"Add billing email",type:"email"}),e.jsx(E,{type:"button",variant:"outline",size:"icon",disabled:!A.trim(),onClick:()=>Y(v.value??[]),children:e.jsx(G,{className:"h-4 w-4"})})]})]})}),e.jsx(C,{})]})})]})}),e.jsx(Qe,{className:"flex justify-end border-t mt-4 pt-6",children:e.jsxs(E,{type:"submit",disabled:r||Object.keys(o.formState.dirtyFields).length===0,children:[e.jsx(os,{className:"h-4 w-4 mr-2"}),"Save Changes"]})})]})})]})}const Ht="createContract",Xt=()=>{const[{fetching:s},n]=be(cn),t=N.useCallback(async a=>{const i=`Error creating new contract for client[${a.input.clientId}]`,l=`${Ht}-${a.input.clientId}`;B.loading("Creating contract",{id:l});try{const c=await n(a);we(c,i,l)&&B.success("Success",{id:l,description:`Contract for client ${a.input.clientId} was successfully created`})}catch(c){console.error(`${i}: ${c}`),B.error("Error",{id:l,description:i,duration:1e5,closeButton:!0})}},[n]);return{creating:s,createContract:t}},Qt="updateContract",Yt=()=>{const[{fetching:s},n]=be(on),t=N.useCallback(async a=>{const i=`Error updating contract ID [${a.contractId}]`,l=`${Qt}-${a.contractId}`;B.loading("Updating contract",{id:l});try{const c=await n(a),r=we(c,i,l,"updateContract");if(r)return B.success("Success",{id:l,description:"Contract updated"}),r.updateContract}catch(c){console.error(`${i}: ${c}`),B.error("Error",{id:l,description:i,duration:1e5,closeButton:!0})}},[n]);return{updating:s,updateContract:t}},Zt=Pe({id:Re().optional(),startDate:ms("Start date is required"),endDate:ms("End date is required"),po:V().optional(),paymentAmount:Cs().min(0,"Payment amount must be non-negative"),paymentCurrency:re(Object.values(ls),"Currency is required"),productType:re(Object.values(Is)).optional(),msCloudLink:bs().optional().or(ws("")),billingCycle:re(Object.values(Ce)).optional(),subscriptionPlan:re(Object.values(Se)).optional(),isActive:dn(),defaultRemark:V().optional(),defaultDocumentType:re(Object.values(ue))}),Ns={startDate:"",endDate:"",po:void 0,paymentAmount:0,paymentCurrency:ls.Usd,productType:Is.Hive,msCloudLink:void 0,billingCycle:Ce.Monthly,subscriptionPlan:void 0,isActive:!0,defaultRemark:void 0,defaultDocumentType:ue.Proforma};function Jt({clientId:s,contract:n,onDone:t}){const[a,i]=N.useState(!1),[l,c]=N.useState(null),{updateContract:r,updating:o}=Yt(),{createContract:d,creating:x}=Xt(),u=Ie({resolver:Ee(Zt),defaultValues:n||Ns});N.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}),i(!0))},[n,u]);const h=()=>{c(null),u.reset(Ns),i(!0)},A=N.useCallback(async m=>{if(l)await r({contractId:l.id,input:{amount:{raw:m.paymentAmount,currency:m.paymentCurrency},billingCycle:m.billingCycle,documentType:m.defaultDocumentType,endDate:ie(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:ie(new Date(m.startDate),"yyyy-MM-dd")}});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:ie(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:ie(new Date(m.startDate),"yyyy-MM-dd")}})}i(!1),c(null),t?.()},[l,t,d,r,s,u]);return e.jsxs(Je,{open:a,onOpenChange:i,children:[e.jsx(es,{asChild:!0,children:e.jsxs(E,{size:"sm",onClick:h,children:[e.jsx(G,{className:"h-4 w-4 mr-2"}),"New Contract"]})}),e.jsxs(ss,{className:"max-w-2xl max-h-[90vh] overflow-y-auto",children:[e.jsxs(ns,{children:[e.jsx(ts,{children:l?"Edit Contract":"Create New Contract"}),e.jsx(as,{children:l?"Update contract details":"Add a new contract with all required details"})]}),e.jsx(De,{...u,children:e.jsxs("form",{onSubmit:u.handleSubmit(A),children:[e.jsxs("div",{className:"grid gap-4 py-4",children:[e.jsx("div",{className:"grid gap-4 md:grid-cols-2",children:e.jsx(j,{control:u.control,name:"po",render:({field:m})=>e.jsxs(g,{children:[e.jsx(f,{children:"PO Number"}),e.jsx(y,{children:e.jsx(T,{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(y,{children:e.jsx(T,{type:"date",...p,onInput:k=>m(k)})}),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(y,{children:e.jsx(T,{type:"date",...p,onInput:k=>m(k)})}),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(y,{children:e.jsx(T,{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(le,{onValueChange:m.onChange,defaultValue:m.value,children:[e.jsx(y,{children:e.jsx(ce,{children:e.jsx(oe,{})})}),e.jsx(de,{children:Object.values(ls).map(p=>e.jsx(me,{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(y,{children:e.jsx(T,{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(le,{onValueChange:m.onChange,defaultValue:m.value,children:[e.jsx(y,{children:e.jsx(ce,{children:e.jsx(oe,{})})}),e.jsx(de,{children:Object.values(Ce).map(p=>e.jsx(me,{value:p,children:Os(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(y,{children:e.jsxs(le,{onValueChange:m.onChange,defaultValue:m.value,children:[e.jsx(y,{children:e.jsx(ce,{children:e.jsx(oe,{})})}),e.jsx(de,{children:Object.values(Se).map(p=>e.jsx(me,{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(y,{children:e.jsx(J,{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(y,{children:e.jsx(T,{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(le,{onValueChange:m.onChange,defaultValue:m.value,children:[e.jsx(y,{children:e.jsx(ce,{children:e.jsx(oe,{})})}),e.jsx(de,{children:Object.values(ue).map(p=>e.jsx(me,{value:p,children:rs(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(y,{children:e.jsx(qe,{placeholder:"Enter default remark for this contract...",rows:3,...m})}),e.jsx(C,{})]})})]}),e.jsxs(is,{children:[e.jsx(E,{type:"button",variant:"outline",onClick:()=>i(!1),children:"Cancel"}),e.jsx(E,{type:"submit",disabled:x||o,children:l?"Update Contract":"Create Contract"})]})]})})]})]})}function ea(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}}function sa({clientId:s}){const[n,t]=N.useState(null),[{data:a,fetching:i},l]=Oe({query:mn,variables:{clientId:s}}),c=a?.contractsByClient??[];return i?e.jsx("div",{children:"Loading contracts..."}):e.jsxs(W,{children:[e.jsx(K,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(H,{children:"Contracts"}),e.jsx(X,{children:"Current and past contracts sorted by start date"})]}),e.jsx(Jt,{clientId:s,contract:n,onDone:l})]})}),e.jsx(Q,{className:"space-y-4",children:c.map(r=>{const o=!!r.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:r.product}),e.jsx(q,{variant:o?"default":"secondary",children:r.isActive?"Active":"Inactive"})]}),e.jsx("p",{className:"text-sm text-muted-foreground font-mono",children:r.id})]}),e.jsx(E,{variant:"ghost",size:"sm",onClick:()=>t(ea(r)),children:e.jsx(Yn,{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(un,{className:"h-3 w-3"}),"Contract Period"]}),e.jsxs("p",{className:"text-sm font-medium",children:[new Date(r.startDate).toLocaleDateString()," →"," ",new Date(r.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:r.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:hn(r.amount.raw,r.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:Os(r.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:r.plan?Bs(r.plan):"N/A"})]}),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:rs(r.documentType)})]})]}),r.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:r.remarks})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:r.msCloud&&e.jsx(E,{variant:"outline",size:"sm",asChild:!0,children:e.jsxs("a",{href:r.msCloud.toString(),target:"_blank",rel:"noopener noreferrer",children:[e.jsx(xn,{className:"h-4 w-4 mr-2"}),"MS Cloud",e.jsx(pn,{className:"h-3 w-3 ml-1"})]})})})]},r.id)})})]})}function na({businessId:s}){return e.jsxs(W,{children:[e.jsx(K,{children:e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{children:[e.jsx(H,{children:"Documents"}),e.jsx(X,{children:"Invoices, proformas, receipts, and other accounting documents"})]})})}),e.jsx(Q,{children:e.jsx(jn,{businessId:s,linkedDocumentIds:[],limit:1e3})})]})}const ta=[{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 aa({data:s}){const n=je(vn,s),[{data:t,fetching:a},i]=Oe({query:gn,variables:{clientId:n?.id??""},pause:!n?.clientInfo?.greenInvoiceId||!n?.id}),{updateClient:l}=_s(),c=N.useCallback((o,d)=>{if(!n?.id)return;const x={};x[d]=o,l({businessId:n?.id,fields:x})},[n?.id,l]);N.useEffect(()=>{n?.clientInfo?.greenInvoiceId&&n?.id&&i()},[n?.clientInfo?.greenInvoiceId,n?.id,i]);const r=t?.greenInvoiceClient;return e.jsxs(W,{children:[e.jsx(K,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(H,{children:"Integrations"}),e.jsx(X,{children:"Connected external services and providers"})]}),e.jsxs(E,{size:"sm",children:[e.jsx(G,{className:"h-4 w-4 mr-2"}),"Add Integration"]})]})}),e.jsx(Q,{className:"space-y-6",children:e.jsxs(Zn,{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(Fe,{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(ra,{id:n?.clientInfo?.greenInvoiceId,provider:"Green Invoice",updateClient:async o=>c(o,"greenInvoiceId")}),e.jsx(hs,{className:"hover:no-underline p-2"})]})]})}),e.jsx(Fe,{children:r&&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:r.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:r.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:r.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(Ge,{className:"h-3.5 w-3.5"}),"Email Addresses"]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:r.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(Es,{className:"h-3.5 w-3.5"}),"Phone"]}),e.jsx("p",{className:"text-sm font-mono",children:r.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:r.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:r.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(Ke,{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:r.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:r.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:r.zip})]})]})]})]})})]}),ta.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(fn,{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(Fe,{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 ra({id:s,provider:n,updateClient:t}){const[a,i]=N.useState(!1),[l,c]=N.useState(s),r=N.useCallback(async()=>{await t(l),i(!1)},[l,t]);return e.jsxs(Je,{open:a,onOpenChange:i,children:[e.jsx(es,{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(ss,{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(yn,{htmlFor:"id",children:[n," ID"]}),e.jsx(T,{id:"id",value:l,onChange:o=>c(o.target.value),placeholder:`Enter ${n} ID`})]})}),e.jsxs(is,{children:[e.jsx(E,{variant:"outline",onClick:()=>i(!1),children:"Cancel"}),e.jsx(E,{onClick:r,disabled:!l,children:"Save Changes"})]})]})]})}function ia({businessId:s}){return e.jsxs(W,{children:[e.jsx(K,{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(H,{children:"Transactions"}),e.jsx(X,{children:"Complete transaction history for this business"})]})})}),e.jsx(Q,{children:e.jsx("div",{className:"rounded-md border",children:e.jsx(Nn,{businessID:s,filter:{}})})})]})}function la({data:s,refetchBusiness:n}){const t=je(An,s),[a,i]=Cn(),l=a.get("tab")||"contact",c=d=>{i({tab:d})};if(!t)return e.jsx("div",{children:"Business not found"});const r="clientInfo"in t&&!!t.clientInfo,o="adminInfo"in t&&!!t.adminInfo;return e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx(pt,{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(bn,{value:l,onValueChange:c,className:"w-full",children:[e.jsxs(wn,{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(Z,{value:"contact",className:"flex items-center gap-2 data-[state=active]:bg-background",children:[e.jsx(Ds,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Contact"})]}),e.jsxs(Z,{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(Z,{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(Z,{value:"transactions",className:"flex items-center gap-2 data-[state=active]:bg-background",children:[e.jsx(In,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Transactions"})]}),e.jsxs(Z,{value:"documents",className:"flex items-center gap-2 data-[state=active]:bg-background",children:[e.jsx(Dn,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Documents"})]}),r&&e.jsxs(e.Fragment,{children:[e.jsxs(Z,{value:"contracts",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:"Contracts"})]}),e.jsxs(Z,{value:"integrations",className:"flex items-center gap-2 data-[state=active]:bg-background",children:[e.jsx(it,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Integrations"})]})]}),o&&e.jsxs(Z,{value:"admin",className:"flex items-center gap-2 data-[state=active]:bg-background",children:[e.jsx(Ps,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Admin"})]})]}),e.jsx(z,{value:"contact",className:"mt-0",children:e.jsx(Kt,{data:t,refetchBusiness:n})}),e.jsx(z,{value:"config",className:"mt-0",children:e.jsx(Rt,{data:t,refetchBusiness:n})}),e.jsx(z,{value:"charges",className:"mt-0",children:e.jsx(jt,{businessId:t.id})}),e.jsx(z,{value:"transactions",className:"mt-0",children:e.jsx(ia,{businessId:t.id})}),e.jsx(z,{value:"documents",className:"mt-0",children:e.jsx(na,{businessId:t.id})}),r&&e.jsxs(e.Fragment,{children:[e.jsx(z,{value:"contracts",className:"mt-0",children:e.jsx(sa,{clientId:t.id})}),e.jsx(z,{value:"integrations",className:"mt-0",children:e.jsx(aa,{data:t})}),e.jsx(z,{value:"charts",className:"mt-0",children:e.jsx(Pt,{})})]}),o&&e.jsx(z,{value:"admin",className:"mt-0",children:e.jsx(xt,{data:t})})]})})]})}function pa(s){return`/businesses/${s}`}const ja=()=>{const{businessId:s}=kn();let n;try{n=Sn()}catch{}const[{data:t,fetching:a},i]=Oe({query:En,pause:!s||!!n,variables:{businessId:s??""}}),l=n||t;return!n&&a&&!l?.business?e.jsx(Tn,{}):!s||!l?.business?e.jsx("div",{children:"Business not found"}):e.jsx(la,{data:l.business,refetchBusiness:async()=>i()})};export{ja as BusinessScreen,pa as getBusinessHref};
@@ -1 +0,0 @@
1
- import{d0 as B,r as i,u as W,d3 as H,j as e,d1 as U,O as z,bC as G,B as _,d2 as X,U as q,k as J,Y as N,ai as D,dk as K,aN as Q,l as Y,dl as Z,bR as h,cj as k,fs as $,bW as M,bX as L,bS as P,eA as A,aK as x,ft as ee,bf as se,a4 as m,a5 as j,a6 as g,a7 as p,dM as ae,dN as te,dO as ne}from"./index-CN2818Wt.js";import{s as oe}from"./sub-C2zifPY5.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:A.All},{label:"Income",value:A.Income},{label:"Expense",value:A.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}=Q(),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 R(){w({}),F(!1),d()}return e.jsxs(e.Fragment,{children:[t?e.jsx("div",{children:"Loading..."}):e.jsx("div",{}),e.jsx(Y,{...o,children:e.jsxs("form",{onSubmit:T(V),children:[e.jsxs(Z,{cols:2,children:[e.jsx(h,{name:"byOwners",control:r,defaultValue:a.byOwners,render:({field:s,fieldState:n})=>e.jsx(k,{...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(k,{...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(k,{...s,data:v,itemComponent:$,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,O)=>O.label?.toLowerCase().includes(l.toLowerCase().trim())||O.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(L,{...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(L,{...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??A.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(k,{...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:R,children:"Clear"}),e.jsx("button",{type:"button",className:"text-white bg-rose-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-rose-600 rounded-sm text-lg",onClick:d,children:"Cancel"})]})]})})]})}function 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}=W();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=>{H(t,a)||(w(t),F(!B(t)))},[a,w]);return e.jsxs("div",{className:"flex flex-row gap-5 items-center",children:[e.jsx(U,{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(X,{className:"size-5"})})})]})}export{he as C,ce as c,le as e};
@@ -1 +0,0 @@
1
- import{p as f,fR as I,r as u,t as l,s as p,k as b,D as y,j as e,l as C,fA as D,a4 as $,a5 as F,a6 as w,a7 as k,Q as j,a9 as v,fS as E,fT as A,o as S,x as z,T as M,B as T,ca as O,z as L,fU as P,fV as B,F as U,a as q,fW as V,c as _,L as R,bU as Q,bV as G,fX as W}from"./index-CN2818Wt.js";const X="updateTag",H=()=>{const[{fetching:d},r]=f(I),c=u.useCallback(async a=>{const t=`Error updating tag ID [${a.tagId}]`,s=`${X}-${a.tagId}`;l.loading("Updating Tag...",{id:s});try{const n=await r(a),i=p(n,t,s,"updateTag");if(i)return l.success("Success",{id:s,description:"Tag updated"}),i.updateTag}catch(n){console.error(`${t}: ${n}`),l.error("Error",{id:s,description:t,duration:1e5,closeButton:!0})}return!1},[r]);return{fetching:d,updateTag:c}},J=({onDone:d,data:r,close:c})=>{const{updateTag:a,fetching:t}=H(),s=y(A,r),n=b({defaultValues:{name:s.name,parentId:s.parent?.id}}),{control:i,handleSubmit:m,formState:{dirtyFields:h}}=n,x=o=>{const g=S(o,h);c(),g&&Object.keys(g).length>0&&a({tagId:s.id,fields:g}).then(()=>d?.())};return e.jsx(C,{...n,children:e.jsxs("form",{onSubmit:m(x),children:[e.jsx("div",{className:"flex-row px-10 h-max justify-start block",children:e.jsxs(D,{cols:3,children:[e.jsx($,{name:"name",control:i,defaultValue:s.name,rules:{required:"Required",minLength:{value:2,message:"Must be at least 2 characters"}},render:({field:o})=>e.jsxs(F,{children:[e.jsx(w,{children:"Name"}),e.jsx(k,{children:e.jsx(j,{...o,value:o.value??void 0})}),e.jsx(v,{})]})}),e.jsx(E,{formManager:n,tagsPath:"parentId",label:"Parent Tag"})]})}),e.jsxs("div",{className:"mt-10 mb-5 flex justify-center gap-5",children:[e.jsx("button",{type:"submit",onClick:()=>m(x),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:t||Object.keys(h).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:c,children:"Cancel"})]})]})})},K=({onDone:d,data:r})=>{const[c,{open:a,close:t}]=z(!1);function s(){t(),d?.()}return e.jsxs(e.Fragment,{children:[e.jsx(M,{label:"Edit Tag",children:e.jsx(T,{variant:"ghost",size:"icon",className:"size-7.5",onClick:a,children:e.jsx(O,{className:"size-5"})})}),e.jsx(L,{centered:!0,opened:c,onClose:t,title:"Insert Business Trip",children:e.jsx(J,{close:t,onDone:s,data:r})})]})},Y="addTag",Z=()=>{const[{fetching:d},r]=f(P),c=u.useCallback(async a=>{const t=`Error adding new tag [${a.tagName}]`,s=`${Y}-${a.tagName}`;l.loading("Adding tag",{id:s});try{const n=await r(a);p(n,t,s)&&l.success("Success",{id:s,description:`"${a.tagName}" tag was successfully added`})}catch(n){console.error(`${t}: ${n}`),l.error("Error",{id:s,description:t,duration:1e5,closeButton:!0})}},[r]);return{fetching:d,addTag:c}},ee="deleteTag",se=()=>{const[{fetching:d},r]=f(B),c=u.useCallback(async a=>{const t=`Error deleting new tag [${a.name}]`,s=`${ee}-${a.tagId}`;l.loading(`Deleting tag [${a.name}]`,{id:s});try{const n=await r(a);p(n,t,s)&&l.success("Tag Deleted",{id:s,description:`[${a.name}] tag was successfully removed`})}catch(n){console.error(`${t}: ${n}`),l.error("Error",{id:s,description:t,duration:1e5,closeButton:!0})}},[r]);return{fetching:d,deleteTag:c}},te=()=>{const{setFiltersContext:d}=u.useContext(U),[r,c]=u.useState(""),[{data:a,fetching:t},s]=q({query:W}),{addTag:n}=Z(),{deleteTag:i}=se();d(null);const m=V(a?.allTags??[]),h=u.useCallback(o=>{o.length>2&&n({tagName:o}).then(()=>{s()})},[n,s]),x=u.useCallback((o,g)=>{i({tagId:o,name:g}).then(()=>{s()})},[i,s]);return e.jsx(_,{title:"Tags",description:"Manage tags for your bookmarks.",children:t?e.jsx(R,{className:"h-10 w-10 animate-spin mr-2 self-center"}):e.jsxs("div",{className:"h-full flex flex-col overflow-hidden",children:[m?.map(o=>e.jsxs("div",{className:"flex items-center gap-2 text-gray-600 mb-2",children:[e.jsxs("div",{className:"w-full mt-1 relative rounded-md shadow-xs",children:[o.namePath?.map((g,N)=>e.jsx("span",{className:"ms-2"},N)),o.name]}),e.jsx(K,{data:o}),e.jsx(T,{variant:"ghost",size:"icon",className:"size-7.5",onClick:()=>x(o.id,o.name),children:e.jsx(Q,{className:"size-5"})})]},o.id)),e.jsxs("div",{className:"flex justify-start items-center gap-2 text-gray-600 mb-2",children:[e.jsx(j,{className:"w-80",value:r,onChange:o=>c(o.currentTarget.value),placeholder:"Add new tag",required:!0}),e.jsx(T,{variant:"ghost",size:"icon",className:"size-7.5",disabled:r.length<2,onClick:()=>h(r),children:e.jsx(G,{className:"size-5"})})]})]})})};export{te as TagsManager};
@@ -1 +0,0 @@
1
- import{r as h,j as e,d1 as u,eL as f,B as y,d2 as R,bp as D,F as T,a as E,c as b,L as w,R as F,eN as g}from"./index-CN2818Wt.js";import{d as v}from"./graphql-document-dedupe-fragments-ByT8-wlV.js";import{R as d}from"./report-commentary-row-Bpvvtwpd.js";function B({year:i,setYear:m,referenceYears:x,setReferenceYears:j}){const[c,o]=h.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsx(u,{opened:c,onClose:()=>o(!1),withCloseButton:!0,content:e.jsxs(e.Fragment,{children:[e.jsx(f,{label:"Change report year",value:new Date(i,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=>i!==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:i}=D(),{setFiltersContext:m}=h.useContext(T),[x,j]=h.useState(i?Number(i):new Date().getFullYear()),[c,o]=h.useState([]),[{data:n,fetching:l}]=E({query:v(g),variables:{reportYear:x,referenceYears:c}});h.useEffect(()=>{m(e.jsx("div",{className:"flex flex-row gap-2",children:e.jsx(B,{year:x,setYear:j,referenceYears:c,setReferenceYears:o})}))},[x,l,m,c,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,9 +0,0 @@
1
- import{d0 as f,r as h,u as B,j as e,d1 as R,bC as N,B as w,d2 as $,k,cf as O,U as A,l as E,bR as v,cj as D,bW as C,bX as F,Y as T,a4 as z,a5 as P,a6 as L,a7 as V,aK as M,d3 as U,dU as _,c2 as S,T as I,P as q,b as G,bg as Z,b6 as j,b1 as p,D as H,dV as J,R as W,cV as y,F as X,a as K,dW as Q,dX as Y,c as ee,L as te,dY as se}from"./index-CN2818Wt.js";function re(t){return!t||f(t)?null:encodeURIComponent(JSON.stringify(t))}function ae({filter:t,setFilter:s,closeModal:o}){const n=k({defaultValues:{...t}}),{control:a,handleSubmit:l}=n,{selectableBusinesses:r,fetching:u}=O(),{userContext:m}=h.useContext(A),c=i=>{i.fromDate?.trim()===""&&(i.fromDate=void 0),i.toDate?.trim()===""&&(i.toDate=void 0),s(i),o()};function d(){s({}),o()}return e.jsxs(e.Fragment,{children:[u?e.jsx("div",{children:"Loading..."}):e.jsx("div",{}),e.jsx(E,{...n,children:e.jsxs("form",{onSubmit:l(c),className:"space-y-2",children:[e.jsx(v,{name:"ownerIds",control:a,defaultValue:void 0,render:({field:i,fieldState:b})=>e.jsx(D,{...i,data:r,value:i.value??(m?.context.adminBusinessId?[m?.context.adminBusinessId]:void 0),disabled:u,label:"Owners",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:b.error?.message})}),e.jsx(v,{name:"businessIDs",control:a,defaultValue:void 0,render:({field:i,fieldState:b})=>e.jsx(D,{...i,data:r,value:i.value??void 0,disabled:u,label:"Businesses",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:b.error?.message})}),e.jsx(v,{name:"fromDate",control:a,defaultValue:t.fromDate,rules:{required:"Required",pattern:{value:C,message:"Date must be im format yyyy-mm-dd"}},render:({field:i,fieldState:b})=>e.jsx(F,{...i,onChange:x=>{const g=x?typeof x=="string"?x:T(x,"yyyy-MM-dd"):void 0;g!==i.value&&i.onChange(g)},value:i.value?new Date(i.value):void 0,label:"From Date",error:b.error?.message,required:!0,popoverProps:{withinPortal:!0}})}),e.jsx(v,{name:"toDate",control:a,defaultValue:t.toDate,rules:{pattern:{value:C,message:"Date must be im format yyyy-mm-dd"}},render:({field:i,fieldState:b})=>e.jsx(F,{...i,onChange:x=>{const g=x?typeof x=="string"?x:T(x,"yyyy-MM-dd"):void 0;g!==i.value&&i.onChange(g)},value:i.value?new Date(i.value):void 0,label:"To Date",error:b.error?.message,required:!0,popoverProps:{withinPortal:!0}})}),e.jsx(z,{name:"isShowZeroedAccounts",control:a,render:({field:i})=>e.jsxs(P,{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(L,{children:"Show zeroed accounts"})}),e.jsxs("div",{className:"flex flex-row items-center gap-1",children:[e.jsx(V,{children:e.jsx(M,{defaultChecked:t.isShowZeroedAccounts??!1,onCheckedChange:i.onChange,checked:i.value===!0})}),e.jsx("span",{children:i.value?"show":"remove"})]})]})}),e.jsxs("div",{className:"flex justify-center mt-5 gap-3",children:[e.jsx("button",{type:"submit",className:"text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg",children:"Filter"}),e.jsx("button",{type:"button",className:"text-white bg-orange-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-orange-600 rounded-sm text-lg",onClick:d,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 ne({filter:t,setFilter:s}){const[o,n]=h.useState(!1),[a,l]=h.useState(!f(t)),{get:r,set:u}=B();function m(d){return Object.entries(d??{}).filter(([b,x])=>x!==void 0&&Array.isArray(x)&&x.length>0).length>0}function c(d){U(d,t)||(s(d),l(m(d)))}return h.useEffect(()=>{const d=f(t)?null:encodeURIComponent(JSON.stringify(t)),i=r("trialBalanceReportFilters");d!==i&&u("trialBalanceReportFilters",d)},[t,r,u]),e.jsxs(e.Fragment,{children:[e.jsx(R,{opened:o,onClose:()=>n(!1),content:e.jsx(ae,{filter:t,setFilter:c,closeModal:()=>n(!1)})}),e.jsx(N,{inline:!0,size:16,disabled:!a,children:e.jsx(w,{variant:"outline",onClick:()=>n(!0),className:"p-2",children:e.jsx($,{size:20})})})]})}const oe=({data:t,fromDate:s,toDate:o})=>{const n=h.useCallback(async()=>{const a=le(t),l=`trial_balance_report${s?`_${s}`:""}${o?`_${o}`:""}`;return{fileContent:a,fileName:l}},[t,s,o]);return e.jsx(_,{createFileVariables:n})},le=t=>{let s="";s+=`Sort Code,Account Name,Debit,Credit,Balance\r
2
- `;for(const[o,n]of Object.entries(t)){const a=ie(o,n);s+=a}return s+=`Report total:,,${Object.values(t).reduce((o,n)=>o+n.totalDebit,0)},${Object.values(t).reduce((o,n)=>o+n.totalCredit,0)},${Object.values(t).reduce((o,n)=>o+n.sum,0)}\r
3
- `,s};function ie(t,s){let o="";return Object.values(s.sortCodes).sort((n,a)=>n.key-a.key).map(n=>{const a=ce(n);o+=a}),o+=`${t.replaceAll("0","*")},Group Total:,${s.totalDebit??""},${s.totalCredit??""},${s.sum}\r
4
- `,o}function ce(t){let s="";s+=`${t.name}\r
5
- `,t.records.sort((l,r)=>l.business.name.localeCompare(r.business.name)).map(l=>{const r=l?.total?.raw??0,u=l?.debit?.raw??0,m=l?.credit?.raw??0,c=`${t.key},${l.business.name?`"${de(l.business.name)}"`:""},${u?l?.debit?.raw:void 0},${m?l?.credit?.raw:void 0},${r>.001||r<-.001?l?.total?.raw??"":""}\r
6
- `;s+=c});const o=`${t.key},Group total:,${t.totalDebit??""},${t.totalCredit??""},${t.sum}\r
7
- `;s+=o;const n=t.debit?`,,,Total Debit Balances:,${t.debit}\r
8
- `:"";s+=n;const a=t.credit?`,,,Total Credit Balances:,${t.credit}\r
9
- `:"";return s+=a,s}function de(t){let s="";return s=t.replace(/"/g,'""'),s}const ue=({record:t,sortCodeKey:s,filter:o,isAllOpened:n})=>{const[a,l]=h.useState(n),r=t?.total?.raw??0,u=t?.debit?.raw??0,m=t?.credit?.raw??0;return e.jsxs(e.Fragment,{children:[e.jsxs("tr",{children:[e.jsx("td",{children:s}),e.jsx("td",{children:t.business.id}),e.jsx("td",{children:t.business.name??void 0}),e.jsx("td",{children:u?t?.debit?.formatted:void 0}),e.jsx("td",{children:m?t?.credit?.formatted:void 0}),e.jsx("td",{children:(r>.001||r<-.001)&&e.jsx(S,{color:r>0?"green":"red",children:t?.total?.formatted})}),e.jsx("td",{children:e.jsx(I,{label:"Detailed records",children:e.jsx(w,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>l(c=>!c),children:a||n?e.jsx(q,{className:"size-5"}):e.jsx(G,{className:"size-5"})})})})]},t.business.id),(a||n)&&e.jsx("tr",{children:e.jsx("td",{colSpan:7,children:e.jsx(Z,{businessID:t.business?.id,filter:o})})})]})},me=({sortCode:t,filter:s,isAllOpened:o})=>t.records.length>0?e.jsxs(e.Fragment,{children:[e.jsx("tr",{children:e.jsx("td",{colSpan:7,children:e.jsx("span",{className:"font-bold",children:t.name})})}),t.records.sort((n,a)=>n.business.name.localeCompare(a.business.name)).map(n=>e.jsx(ue,{record:n,sortCodeKey:t.key,filter:s,isAllOpened:o},n.business.id)),e.jsx("tr",{className:"bg-gray-100",children:t.records.length>1?e.jsxs(e.Fragment,{children:[e.jsx("td",{colSpan:2,children:"Group total:"}),e.jsx("td",{colSpan:1,children:t.key}),e.jsx("td",{colSpan:1,children:!!t.totalDebit&&j(t.totalDebit,p.Ils)}),e.jsx("td",{colSpan:1,children:!!t.totalCredit&&j(t.totalCredit,p.Ils)}),e.jsxs("td",{colSpan:1,children:[e.jsx(S,{c:t.sum>0?"green":t.sum<0?"red":void 0,children:j(t.sum,p.Ils)}),!!t.debit&&e.jsxs(e.Fragment,{children:[e.jsx("br",{}),"Total Debit Balances: ",j(t.debit,p.Ils)]}),!!t.credit&&e.jsxs(e.Fragment,{children:[e.jsx("br",{}),"Total Credit Balances: ",j(t.credit,p.Ils)]})]})]}):void 0})]}):null,xe=({group:t,data:s,filter:o,isAllOpened:n})=>e.jsxs(e.Fragment,{children:[Object.values(s.sortCodes).sort((a,l)=>a.key-l.key).map((a,l)=>e.jsx(me,{sortCode:a,filter:o,isAllOpened:n},`${a.key} ${l}`)),e.jsxs("tr",{className:"bg-gray-100",children:[e.jsx("td",{colSpan:2,children:"Group total:"}),e.jsx("td",{colSpan:1,children:t.replaceAll("0","*")}),e.jsx("td",{colSpan:1,children:!!s.totalDebit&&j(s.totalDebit,p.Ils)}),e.jsx("td",{colSpan:1,children:!!s.totalCredit&&j(s.totalCredit,p.Ils)}),e.jsx("td",{colSpan:1,children:e.jsx(S,{fw:700,c:s.sum>0?"green":s.sum<0?"red":void 0,children:j(s.sum,p.Ils)})})]},"group"+t)]});function he(t){return Math.floor(t/100)*100}const be=({data:t,filter:s,isAllOpened:o})=>{const{businessTransactionsSum:n}=H(J,t),a=h.useMemo(()=>{const l={};for(const r of n){r.business.sortCode??={id:"-999",key:-999,name:"Misc"};const u=!r.total.raw||r.total.raw<.001&&r.total.raw>-.001;if(!s.isShowZeroedAccounts&&u)continue;const m=he(r.business.sortCode.key);l[m]??={sortCodes:{},totalCredit:0,totalDebit:0,credit:0,debit:0,sum:0};const c=l[m];c.sortCodes[r.business.sortCode.key]??={...r.business.sortCode,totalCredit:0,totalDebit:0,records:[],credit:0,debit:0,sum:0};const d=c.sortCodes[r.business.sortCode.key];d.totalCredit+=r.credit.raw,d.totalDebit+=r.debit.raw,d.sum+=r.total.raw,c.totalCredit+=r.credit.raw,c.totalDebit+=r.debit.raw,c.sum+=r.total.raw,r.total.raw>0?(d.credit+=r.total.raw,c.credit+=r.total.raw):(d.debit+=r.total.raw,c.debit+=r.total.raw),d.records.push(r)}return l},[n,s.isShowZeroedAccounts]);return e.jsxs(W,{highlightOnHover:!0,children:[e.jsx("thead",{style:{position:"sticky",top:0,zIndex:20},children:e.jsxs("tr",{className:"bg-gray-300",children:[e.jsx("th",{children:"Sort Code"}),e.jsx("th",{children:"Account"}),e.jsx("th",{children:"Account Name"}),e.jsx("th",{children:"Total Debit"}),e.jsx("th",{children:"Total Credit"}),e.jsx("th",{children:"Balance"}),e.jsx("th",{children:e.jsx(oe,{data:a,fromDate:s.fromDate??void 0,toDate:s.toDate??void 0})})]})}),e.jsxs("tbody",{children:[Object.entries(a).map(([l,r])=>e.jsx(xe,{data:r,group:l,filter:s,isAllOpened:o},l)),e.jsxs("tr",{className:"bg-gray-100",children:[e.jsx("td",{colSpan:2,children:"Report total:"}),e.jsx("td",{}),e.jsxs("td",{children:["(",y(Object.values(a).reduce((l,r)=>l+r.totalDebit,0)),")"]}),e.jsxs("td",{children:["(",y(Object.values(a).reduce((l,r)=>l+r.totalCredit,0)),")"]}),e.jsx("td",{colSpan:1,children:y(Object.values(a).reduce((l,r)=>l+r.sum,0))})]})]})]})};function pe(t){const s=new URLSearchParams,o=re(t);return o&&s.append("trialBalanceReportFilters",o),`/reports/trial-balance${s.size>0?`?${s}`:""}`}const ge=()=>{const[t,s]=h.useState(!1),{get:o}=B(),{setFiltersContext:n}=h.useContext(X),[a,l]=h.useState(o("trialBalanceReportFilters")?JSON.parse(decodeURIComponent(o("trialBalanceReportFilters"))):{}),[{data:r,fetching:u}]=K({query:se,variables:{filters:{fromDate:a?.fromDate,toDate:a?.toDate,ownerIds:a?.ownerIds,businessIDs:a?.businessIDs}}});h.useEffect(()=>{n(e.jsxs("div",{className:"flex flex-row gap-2",children:[e.jsx(I,{label:"Expand all accounts",children:e.jsx(w,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>s(c=>!c),children:t?e.jsx(Q,{className:"size-5"}):e.jsx(Y,{className:"size-5"})})}),e.jsx(ne,{filter:a,setFilter:l})]}))},[a,t,n]);const m=h.useMemo(()=>r?.businessTransactionsSumFromLedgerRecords.__typename==="CommonError"?void 0:r?.businessTransactionsSumFromLedgerRecords,[r?.businessTransactionsSumFromLedgerRecords]);return e.jsx(ee,{title:"Trial Balance Report",description:"Trial balance report for all businesses",children:u||!m?e.jsx(te,{className:"h-10 w-10 animate-spin mr-2 self-center"}):e.jsx(be,{data:m,filter:a,isAllOpened:t})})};export{ge as TrialBalanceReport,pe as getTrialBalanceReportHref};
@@ -1 +0,0 @@
1
- import{j as n,r as x,d1 as v,eL as g,B as D,d2 as R,D as h,f6 as j,bp as E,F as y,a as C,c as w,L as T,R as b,bC as A,eb as F,T as u,f7 as I}from"./index-CN2818Wt.js";import{d as N}from"./graphql-document-dedupe-fragments-ByT8-wlV.js";const o=({originalAmount:a,diffAmount:t})=>!t||a===t?n.jsx("td",{children:a}):n.jsx("td",{children:n.jsxs("div",{className:"flex flex-col",children:[n.jsx("p",{className:t?"line-through":"",children:a}),t&&n.jsx("div",{className:"border-2 border-yellow-500 rounded-md",children:t})]})});function P({years:a,setYears:t}){const[r,l]=x.useState(!1);return n.jsxs(n.Fragment,{children:[n.jsx(v,{opened:r,onClose:()=>l(!1),withCloseButton:!0,content:n.jsx(g,{type:"multiple",label:"Pick years",value:a?.map(d=>new Date(d,0,1)),onChange:d=>t(d.map(p=>p.getFullYear())),popoverProps:{withinPortal:!0},minDate:new Date(2010,0,1),maxDate:new Date})}),n.jsx(D,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>l(!0),children:n.jsx(R,{className:"size-5"})})]})}const f=({originalRuleData:a,diffRuleData:t})=>{const r=h(j,a),l=h(j,t),d=l?.isCompliant!==r.isCompliant||l?.percentage.formatted!==r.percentage.formatted;return!l||!d?n.jsx("td",{className:r.isCompliant?"text-green-500":"text-red-500",children:r.percentage.formatted}):n.jsx("td",{className:r.isCompliant?"text-green-500":"text-red-500",children:n.jsxs("div",{className:"flex flex-col",children:[n.jsx("p",{className:"line-through ".concat(r.isCompliant?"text-green-500":"text-red-500"),children:r.percentage.formatted}),l&&n.jsx("div",{className:"border-2 border-yellow-500 rounded-md ".concat(l.isCompliant?"text-green-500":"text-red-500"),children:l.percentage.formatted})]})})},c=(a,t)=>F(t).format(a);function m(a,t){if(a.length!==0)return c(a.reduce((r,l)=>r+l,0),t)}const B=()=>{const{year:a}=E(),{setFiltersContext:t}=x.useContext(y),[r,l]=x.useState(a?[Number(a)]:[new Date().getFullYear()]),[{data:d,fetching:p}]=C({query:N(I),variables:{years:r}});x.useEffect(()=>{t(n.jsx("div",{className:"flex flex-row gap-2",children:n.jsx(P,{years:r,setYears:l})}))},[r,p,t]);const s=d?.corporateTaxRulingComplianceReport??[];return n.jsx(w,{title:"Corporate Tax Ruling Compliance Report",children:p?n.jsx(T,{className:"h-10 w-10 animate-spin mr-2 self-center"}):n.jsx("div",{className:"flex flex-col gap-4",children:s&&n.jsxs(b,{highlightOnHover:!0,fontSize:"md",children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{}),r.map(e=>n.jsx("th",{children:n.jsx(A,{inline:!0,size:12,processing:!s.find(i=>i.year===e)?.differences,disabled:!!s.find(i=>i.year===e)?.differences,color:"orange",zIndex:"auto",children:e})},e)),n.jsx("th",{children:"Summary"},"sum")]})}),n.jsxs("tbody",{children:[n.jsxs("tr",{children:[n.jsx("td",{children:"Total Income"}),s.map(e=>n.jsx(o,{originalAmount:e.totalIncome.formatted,diffAmount:e.differences?.totalIncome?.formatted??void 0},e.year)),n.jsx(o,{originalAmount:c(s.map(e=>e.totalIncome.raw).reduce((e,i)=>e+i,0),s[0].totalIncome.currency),diffAmount:m(s.map(e=>e.differences?.totalIncome?.raw??e.totalIncome.raw).filter(e=>!!e),s[0].totalIncome.currency)},"sum")]}),n.jsxs("tr",{children:[n.jsx("td",{children:"Total R&D Expensess"}),s.map(e=>n.jsx(o,{originalAmount:e.researchAndDevelopmentExpenses.formatted,diffAmount:e.differences?.researchAndDevelopmentExpenses?.formatted??void 0},e.year)),n.jsx(o,{originalAmount:c(s.map(e=>e.researchAndDevelopmentExpenses.raw).reduce((e,i)=>e+i,0),s[0].researchAndDevelopmentExpenses.currency),diffAmount:m(s.map(e=>e.differences?.researchAndDevelopmentExpenses?.raw??e.researchAndDevelopmentExpenses.raw).filter(e=>!!e),s[0].researchAndDevelopmentExpenses.currency)},"sum")]}),n.jsxs("tr",{children:[n.jsx("th",{children:n.jsx(u,{multiline:!0,width:220,transitionProps:{duration:200},label:s[0]?.rndRelativeToIncome.rule,children:n.jsx("p",{children:"R&D Expenses out of Income"})})}),s.map(e=>n.jsx(f,{originalRuleData:e.rndRelativeToIncome,diffRuleData:e.differences?.rndRelativeToIncome??void 0},e.year)),n.jsx("td",{})]}),n.jsxs("tr",{children:[n.jsx("td",{children:"Local Development Expenses"}),s.map(e=>n.jsx(o,{originalAmount:e.localDevelopmentExpenses.formatted,diffAmount:e.differences?.localDevelopmentExpenses?.formatted??void 0},e.year)),n.jsx(o,{originalAmount:c(s.map(e=>e.localDevelopmentExpenses.raw).reduce((e,i)=>e+i,0),s[0].localDevelopmentExpenses.currency),diffAmount:m(s.map(e=>e.differences?.localDevelopmentExpenses?.raw??e.localDevelopmentExpenses.raw).filter(e=>!!e),s[0].localDevelopmentExpenses.currency)},"sum")]}),n.jsxs("tr",{children:[n.jsx("th",{children:n.jsx(u,{multiline:!0,width:220,transitionProps:{duration:200},label:s[0]?.localDevelopmentRelativeToRnd.rule,children:n.jsx("p",{children:"Local Development out of R&D"})})}),s.map(e=>n.jsx(f,{originalRuleData:e.localDevelopmentRelativeToRnd,diffRuleData:e.differences?.localDevelopmentRelativeToRnd??void 0},e.year)),n.jsx("td",{})]}),n.jsxs("tr",{children:[n.jsx("td",{children:"Foreign Development Expenses"}),s.map(e=>n.jsx(o,{originalAmount:e.foreignDevelopmentExpenses.formatted,diffAmount:e.differences?.foreignDevelopmentExpenses?.formatted??void 0},e.year)),n.jsx(o,{originalAmount:c(s.map(e=>e.foreignDevelopmentExpenses.raw).reduce((e,i)=>e+i,0),s[0].foreignDevelopmentExpenses.currency),diffAmount:m(s.map(e=>e.differences?.foreignDevelopmentExpenses?.raw??e.foreignDevelopmentExpenses.raw).filter(e=>!!e),s[0].foreignDevelopmentExpenses.currency)},"sum")]}),n.jsxs("tr",{children:[n.jsx("th",{children:n.jsx(u,{multiline:!0,width:220,transitionProps:{duration:200},label:s[0]?.foreignDevelopmentRelativeToRnd.rule,children:n.jsx("p",{children:"Foreign Development out of R&D"})})}),s.map(e=>n.jsx(f,{originalRuleData:e.foreignDevelopmentRelativeToRnd,diffRuleData:e.differences?.foreignDevelopmentRelativeToRnd??void 0},e.year)),n.jsx("td",{})]}),n.jsxs("tr",{children:[n.jsx("td",{children:"R&D Business Trips Expenses"}),s.map(e=>n.jsx(o,{originalAmount:e.businessTripRndExpenses.formatted,diffAmount:e.differences?.businessTripRndExpenses?.formatted??void 0},e.year)),n.jsx(o,{originalAmount:c(s.map(e=>e.businessTripRndExpenses.raw).reduce((e,i)=>e+i,0),s[0].businessTripRndExpenses.currency),diffAmount:m(s.map(e=>e.differences?.businessTripRndExpenses?.raw??e.businessTripRndExpenses.raw).filter(e=>!!e),s[0].businessTripRndExpenses.currency)},"sum")]})]})]})})})};export{B as CorporateTaxRulingComplianceReport};
@@ -1 +0,0 @@
1
- import{r as c,a as N,i as k,j as e,e as w,U as E,k as z,l as D,m as L,n as A,o as T,p as O,q as P,t as B,s as R,v as U,w as $,x as q,B as C,y as S,z as H,D as v,G as _,H as Q,P as F,b as I,J as V,K as G,N as J,u as M,O as K,Q as W,F as X,T as Y,c as Z,L as ee,R as se,S as te}from"./index-CN2818Wt.js";import{C as ne,M as ie}from"./Checkbox-CpANMiXr.js";import{u as ae,S as re}from"./similar-charges-by-business-modal-bUtiFfAw.js";function oe({businessID:t,updateBusiness:n}){const[r,u]=c.useState(void 0),[{data:o,fetching:i},l]=N({query:k,variables:{id:t}});return c.useEffect(()=>{i?u(void 0):o&&o.business.__typename==="LtdFinancialEntity"&&u(o.business)},[o,i]),c.useEffect(()=>{r&&n(r)},[r,n]),e.jsx("div",{className:"flex flex-col gap-5",children:r?e.jsx(le,{business:r,refetchBusiness:l}):i?e.jsx(w,{className:"flex self-center my-5",color:"dark",size:"xl",variant:"dots"}):e.jsx("p",{children:"Error fetching extended information for this business"})})}function le({business:t,refetchBusiness:n}){const[r,u]=c.useState(!1),[o,i]=c.useState(!1),[l,d]=c.useState(void 0),{userContext:g}=c.useContext(E),{updateBusiness:f,fetching:a}=ae(),x=z({defaultValues:{...t,taxCategory:t.taxCategory?.id,sortCode:t?.sortCode?.key,irsCode:t?.irsCode}}),{handleSubmit:p,formState:{dirtyFields:h}}=x,b=async j=>{if(!t||!g?.context.adminBusinessId)return;const s=T(j,h);s&&Object.keys(s).length>0&&(s.sortCode&&=parseInt(s.sortCode.toString()),s.suggestions?.tags&&(s.suggestions.tags=s.suggestions.tags.map(m=>({id:m.id}))),s.suggestions?.phrases&&(s.suggestions.phrases=j.suggestions.phrases.map(m=>m)),s.suggestions?.emails&&(s.suggestions.emails=j.suggestions.emails.map(m=>m)),s.suggestions?.emailListener&&(s.suggestions.emailListener.attachments&&=j.suggestions.emailListener.attachments.map(m=>m),s.suggestions.emailListener.internalEmailLinks&&=j.suggestions.emailListener.internalEmailLinks.map(m=>m)),await f({businessId:t.id,ownerId:g.context.adminBusinessId,fields:s}),s.suggestions?.tags?.length||s.suggestions?.description?(d({tagIds:s.suggestions?.tags?.map(m=>({id:m.id})),description:s.suggestions?.description??void 0}),i(!0)):n())};return e.jsxs(e.Fragment,{children:[r&&e.jsx(w,{className:"flex self-center my-5",color:"dark",size:"xl",variant:"dots"}),e.jsx("div",{className:"flex flex-row gap-5",children:e.jsx(D,{...x,children:e.jsxs("form",{onSubmit:p(b),children:[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 Business:"}),e.jsxs("div",{className:"flex flex-row gap-2",children:["ID: ",t.id,e.jsx(L,{content:t.id})]})]}),e.jsx("div",{className:"flex-row px-10 h-max justify-start block",children:e.jsx(A,{isInsert:!1,formManager:x,setFetching:u})}),e.jsx("div",{className:"mt-10 mb-5 flex justify-center gap-5",children:e.jsx("button",{type:"submit",onClick:()=>p(b),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:a||Object.keys(h).length===0,children:"Update"})})]})})}),e.jsx(re,{businessId:t.id,tagIds:l?.tagIds,description:l?.description,open:o,onOpenChange:i,onClose:n})]})}const ce="mergeBusinesses",de=()=>{const[{fetching:t},n]=O(P),r=c.useCallback(async u=>{const o=`Error merging into business ID [${u.targetBusinessId}]`,i=`${ce}-${u.targetBusinessId}`;B.loading("Merging Businesses",{id:i});try{const l=await n(u),d=R(l,o,i);if(d)return B.success("Success",{id:i,description:"Businesses merged"}),d.mergeBusinesses.id}catch(l){console.error(`${o}: ${l}`),B.error("Error",{id:i,description:o,duration:1e5,closeButton:!0})}},[n]);return{fetching:t,mergeBusinesses:r}};function ue({businessIds:t,onDone:n,resetMerge:r}){const{mergeBusinesses:u,fetching:o}=de(),i=Array.from(new Set(t)),[{data:l,fetching:d}]=N({query:U,variables:{businessIds:i}}),[g,f]=c.useState(l?.businesses[0]),a=l?.businesses.length!==i.length&&"Some businesses were not Found"||void 0,x=l?.businesses||[],p=c.useCallback(async()=>{if(!g){B.error("Error",{description:"No main business selected"});return}if(i.length<2){B.error("Error",{description:"At least 2 businesses are required to execute a merge"});return}return await u({targetBusinessId:g.id,businessIdsToMerge:i.filter(h=>h!==g.id)}),r(),n()},[g,i,u,n,r]);return e.jsxs(e.Fragment,{children:[d&&e.jsx("div",{className:"flex flex-col text-center w-full mb-1",children:e.jsx($,{})}),!d&&a&&e.jsx("div",{className:"flex flex-col text-center w-full mb-1",children:e.jsx("h3",{className:"sm:text-2xl text-xl font-medium title-font mb-6 text-gray-900",children:a})}),!d&&!a&&e.jsxs(e.Fragment,{children:[e.jsxs("table",{children:[e.jsxs("tr",{children:[e.jsx("th",{children:"Main"}),x.map(h=>e.jsx("td",{children:e.jsx("div",{className:"flex items-center justify-center mx-2 px-2 py-2 border-2 border-b-0 rounded-t-xl",children:e.jsx(ne,{checked:h.id===g?.id,size:"xl",onClick:()=>{f(h)}})})},h.id))]}),e.jsxs("tr",{children:[e.jsx("th",{children:"Name"}),x.map(h=>e.jsx("td",{children:h.name},h.id))]})]}),e.jsxs("div",{className:"flex justify-center gap-5 mt-5",children:[e.jsx("button",{type:"button",className:" text-white bg-blue-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-blue-600 rounded-sm text-lg",disabled:d||o,onClick:p,children:"Accept"}),e.jsx("button",{type:"button",className:" text-white bg-red-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-red-600 rounded-sm text-lg",onClick:n,children:"Cancel"}),e.jsx("button",{type:"button",className:" text-white bg-red-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-red-600 rounded-sm text-lg",onClick:()=>{r(),n()},children:"Reset Merge"})]})]})]})}function ge(t){const[n,{close:r,open:u}]=q(!1),{selected:o,resetMerge:i}=t,l=new Set(o.map(({id:x})=>x)),d=l.size>=1,[g,f]=c.useState(d?"default":"outline");c.useEffect(()=>{f(d?"default":"outline")},[d]);const a=c.useCallback(()=>{r(),o.map(({onChange:x})=>x())},[o,r]);return e.jsxs(e.Fragment,{children:[e.jsx(C,{onClick:()=>{d&&u()},disabled:!d,variant:g,className:S("size-7.5",d?" bg-blue-500 hover:bg-blue-500/90":""),size:"icon",children:e.jsx(ie,{className:"size-5"})}),e.jsx(H,{opened:n,onClose:r,size:"auto",centered:!0,children:e.jsx(ue,{businessIds:Array.from(l),onDone:a,resetMerge:i})})]})}const me=({data:t})=>{const n=v(_,t);return e.jsx("td",{children:e.jsx("div",{style:{whiteSpace:"nowrap"},children:n.hebrewName})})},xe=({data:t})=>{const n=v(Q,t);return e.jsx("td",{children:e.jsx("div",{style:{whiteSpace:"nowrap"},children:n.name})})},he=({data:t,isAllOpened:n,toggleMergeBusiness:r,isSelectedForMerge:u})=>{const[o,i]=c.useState(!1),[l,d]=c.useState(v(J,t));return e.jsxs(e.Fragment,{children:[e.jsxs("tr",{children:[e.jsx(xe,{data:l}),e.jsx(me,{data:l}),e.jsx("td",{children:e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(C,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>{i(g=>!g)},children:n||o?e.jsx(F,{className:"size-5"}):e.jsx(I,{className:"size-5"})}),r&&e.jsx(V,{toggleMergeSelected:()=>r(()=>{}),mergeSelected:u})]})})]}),(n||o)&&e.jsx("tr",{children:e.jsx("td",{colSpan:12,children:e.jsx(G,{style:{width:"100%"},withBorder:!0,shadow:"lg",children:e.jsx(oe,{businessID:l.id,updateBusiness:d})})})})]})};function fe({activePage:t,setPage:n,totalPages:r=1,businessName:u,setBusinessName:o}){const{get:i,set:l}=M(),[d,g]=c.useState(u);c.useEffect(()=>{const a=t>1?t.toFixed(0):void 0,x=i("page");a!==x&&a!=="1"&&l("page",a)},[t,i,l]),c.useEffect(()=>{const a=setTimeout(()=>{o(d)},600);return()=>{clearTimeout(a)}},[d,o]);const f=a=>{g(a)};return e.jsxs("div",{className:"flex flex-row gap-5 items-center",children:[e.jsx(K,{className:"flex-auto",value:t,onChange:n,total:r}),e.jsx(W,{className:"w-72",placeholder:"Business Name",defaultValue:u??void 0,onChange:a=>f(a.target.value===""?void 0:a.target.value)})]})}const Be=()=>{const{get:t}=M(),[n,r]=c.useState(!1),[u,o]=c.useState(t("page")?Number(t("page")):1),[i,l]=c.useState(t("name")?t("page"):void 0),{setFiltersContext:d}=c.useContext(X),[{data:g,fetching:f}]=N({query:te,variables:{page:u,limit:100,name:i}}),[a,x]=c.useState([]),p=c.useCallback((s,m)=>{a.map(y=>y.id).includes(s)?x(a.filter(y=>y.id!==s)):x([...a,{id:s,onChange:m}])},[a]);function h(){x([])}c.useEffect(()=>{d(e.jsxs("div",{className:"flex flex-row gap-x-5",children:[e.jsx(fe,{activePage:u,setPage:o,businessName:i,setBusinessName:l,totalPages:g?.allBusinesses?.pageInfo.totalPages}),e.jsx(Y,{label:"Expand all businesses",children:e.jsx(C,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>r(s=>!s),children:n?e.jsx(F,{className:"size-5"}):e.jsx(I,{className:"size-5"})})}),e.jsx(ge,{selected:a,resetMerge:h})]}))},[g,u,i,n,d,o,l,r,a]);const b=g?.allBusinesses?.nodes.filter(s=>s.__typename==="LtdFinancialEntity").sort((s,m)=>s.name.toLowerCase()>m.name.toLowerCase()?1:-1)??[],j=new Set(a.map(s=>s.id));return e.jsx(Z,{title:`Businesses (${b.length})`,description:"All businesses",children:f?e.jsx("div",{className:"flex flex-row justify-center",children:e.jsx(ee,{className:S("h-10 w-10 animate-spin mr-2")})}):e.jsxs(se,{striped:!0,highlightOnHover:!0,children:[e.jsx("thead",{className:"sticky top-0 z-20",children:e.jsxs("tr",{className:"px-10 py-10 title-font tracking-wider font-medium text-gray-900 text-sm bg-gray-100 rounded-tl rounded-bl",children:[e.jsx("th",{children:"Name"}),e.jsx("th",{children:"Hebrew Name"}),e.jsx("th",{children:"More Info"})]})}),e.jsx("tbody",{children:b.map(s=>e.jsx(he,{data:s,isAllOpened:n,toggleMergeBusiness:p?m=>p(s.id,m):void 0,isSelectedForMerge:j.has(s.id)??!1},s.id))})]})})};export{Be as Businesses};
@@ -1 +0,0 @@
1
- import{r as h,j as e,d1 as u,eL as p,B as y,d2 as g,bp as D,F as P,a as R,c as w,L as E,R as v,eM as F}from"./index-CN2818Wt.js";import{d as C}from"./graphql-document-dedupe-fragments-ByT8-wlV.js";import{R as d}from"./report-commentary-row-Bpvvtwpd.js";function A({year:l,setYear:m,referenceYears:o,setReferenceYears:j}){const[c,x]=h.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsx(u,{opened:c,onClose:()=>x(!1),withCloseButton:!0,content:e.jsxs(e.Fragment,{children:[e.jsx(p,{label:"Change report year",value:new Date(l,0,1),onChange:n=>n&&m(n?.getFullYear()),popoverProps:{withinPortal:!0},minDate:new Date(2010,0,1),maxDate:new Date}),e.jsx(p,{type:"multiple",label:"Pick reference years",value:o?.map(n=>new Date(n,0,1)),onChange:n=>j(n.map(i=>i.getFullYear()).filter(i=>l!==i)),popoverProps:{withinPortal:!0},minDate:new Date(2010,0,1),maxDate:new Date})]})}),e.jsx(y,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>x(!0),children:e.jsx(g,{className:"size-5"})})]})}const b=()=>{const{year:l}=D(),{setFiltersContext:m}=h.useContext(P),[o,j]=h.useState(l?Number(l):new Date().getFullYear()),[c,x]=h.useState([]),[{data:n,fetching:i}]=R({query:C(F),variables:{reportYear:o,referenceYears:c}});h.useEffect(()=>{m(e.jsx("div",{className:"flex flex-row gap-2",children:e.jsx(A,{year:o,setYear:j,referenceYears:c,setReferenceYears:x})}))},[o,i,m,c,x]);const f=n?.profitAndLossReport,a=f?.report,s=f?.reference??[];return e.jsx(w,{title:"Profit and Loss Report",children:i?e.jsx(E,{className:"h-10 w-10 animate-spin mr-2 self-center"}):e.jsx("div",{className:"flex flex-col gap-4",children:a&&e.jsxs(v,{highlightOnHover:!0,fontSize:"md",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{}),e.jsx("th",{children:o},o),e.jsx("th",{}),s.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:"Revenue"}),e.jsx("th",{children:a.revenue.amount.formatted}),e.jsx("th",{children:t}),s.map(r=>e.jsx("th",{children:r.revenue.amount.formatted},r.year))]}),commentaryData:a.revenue}),e.jsx(d,{dataRow:t=>e.jsxs("tr",{children:[e.jsx("td",{children:"Cost of Sales"}),e.jsx("td",{children:a.costOfSales.amount.formatted}),e.jsx("th",{children:t}),s.map(r=>e.jsx("td",{children:r.costOfSales.amount.formatted},r.year))]}),commentaryData:a.costOfSales}),e.jsxs("tr",{children:[e.jsx("th",{children:"Gross Profit"}),e.jsx("th",{children:a.grossProfit.formatted}),e.jsx("th",{}),s.map(t=>e.jsx("th",{children:t.grossProfit.formatted},t.year))]}),e.jsx(d,{dataRow:t=>e.jsxs("tr",{children:[e.jsx("td",{children:"R&D Expenses"}),e.jsx("td",{children:a.researchAndDevelopmentExpenses.amount.formatted}),e.jsx("th",{children:t}),s.map(r=>e.jsx("td",{children:r.researchAndDevelopmentExpenses.amount.formatted},r.year))]}),commentaryData:a.researchAndDevelopmentExpenses}),e.jsx(d,{dataRow:t=>e.jsxs("tr",{children:[e.jsx("td",{children:"Marketing Expenses"}),e.jsx("td",{children:a.marketingExpenses.amount.formatted}),e.jsx("th",{children:t}),s.map(r=>e.jsx("td",{children:r.marketingExpenses.amount.formatted},r.year))]}),commentaryData:a.marketingExpenses}),e.jsx(d,{dataRow:t=>e.jsxs("tr",{children:[e.jsx("td",{children:"Management and General Expenses"}),e.jsx("td",{children:a.managementAndGeneralExpenses.amount.formatted}),e.jsx("th",{children:t}),s.map(r=>e.jsx("td",{children:r.managementAndGeneralExpenses.amount.formatted},r.year))]}),commentaryData:a.managementAndGeneralExpenses}),e.jsxs("tr",{children:[e.jsx("th",{children:"Operating Profit"}),e.jsx("th",{children:a.operatingProfit.formatted}),e.jsx("th",{}),s.map(t=>e.jsx("th",{children:t.operatingProfit.formatted},t.year))]}),e.jsx(d,{dataRow:t=>e.jsxs("tr",{children:[e.jsx("td",{children:"Financial Expenses"}),e.jsx("td",{children:a.financialExpenses.amount.formatted}),e.jsx("th",{children:t}),s.map(r=>e.jsx("td",{children:r.financialExpenses.amount.formatted},r.year))]}),commentaryData:a.financialExpenses}),e.jsx(d,{dataRow:t=>e.jsxs("tr",{children:[e.jsx("td",{children:"Other Income"}),e.jsx("td",{children:a.otherIncome.amount.formatted}),e.jsx("th",{children:t}),s.map(r=>e.jsx("td",{children:r.otherIncome.amount.formatted},r.year))]}),commentaryData:a.otherIncome}),e.jsxs("tr",{children:[e.jsx("th",{children:"Profit Before Tax"}),e.jsx("th",{children:a.profitBeforeTax.formatted}),e.jsx("th",{}),s.map(t=>e.jsx("th",{children:t.profitBeforeTax.formatted},t.year))]}),e.jsxs("tr",{children:[e.jsx("td",{children:"Tax"}),e.jsx("td",{children:a.tax.formatted}),e.jsx("td",{}),s.map(t=>e.jsx("td",{children:t.tax.formatted},t.year))]})]}),e.jsx("tfoot",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Net Profit"}),e.jsx("th",{children:a.netProfit.formatted}),e.jsx("th",{}),s.map(t=>e.jsx("th",{children:t.netProfit.formatted},t.year))]})})]})})})};export{b as ProfitAndLossReport};
@@ -1 +0,0 @@
1
- import{d0 as _,r as m,u as R,d3 as V,j as e,d1 as q,bC as Q,B as I,d2 as G,k as z,cf as K,dk as X,aN as J,dl as W,bR as y,bS as A,bW as F,bX as B,Y as M,cj as E,a as U,f8 as Z,$ as P,w as $,a0 as Y,a1 as ee,av as ae,a3 as O,f9 as se,F as te,U as re,aR as ne,c as oe,a2 as le,eb as ie,fa as ce,b1 as de}from"./index-CN2818Wt.js";import{k as ue,B as N,X as H,Y as me,l as pe,m as xe,n as ge,o as he,p as fe,q as be,r as je}from"./chart-C5LuxRSv.js";import{s as ye}from"./sub-C2zifPY5.js";import"./sequential-CAnleQny.js";import"./subMonths-uUfFviD2.js";var ve=ue({chartName:"BarChart",GraphicalChild:N,defaultTooltipEventType:"axis",validateTooltipEventTypes:["axis","item"],axisComponents:[{axisType:"xAxis",AxisComp:H},{axisType:"yAxis",AxisComp:me}],formatAxisMap:pe});function k(s){return!s||_(s)?null:encodeURIComponent(JSON.stringify(s))}const L="balanceReportFilters",x={MONTHLY:"Monthly",BI_MONTHLY:"Bi-monthly",QUARTERLY:"Quarterly",SEMI_ANNUALLY:"Semi-Annually",ANNUALLY:"Annually"};function Ce({filter:s,setFilter:n,closeModal:c}){const{control:t,handleSubmit:r,watch:g}=z({defaultValues:{...s}}),{selectableBusinesses:b,fetching:h}=K(),{selectableFinancialEntities:f,fetching:v}=X(),{selectableTags:p,fetching:j}=J(),S=a=>{n(a),c()},C=g("excludedTags"),l=m.useMemo(()=>p.filter(a=>!C.includes(a.value)),[C,p]),d=g("includedTags"),o=m.useMemo(()=>p.filter(a=>!d.includes(a.value)),[d,p]);return e.jsxs("form",{onSubmit:r(S),children:[e.jsxs(W,{cols:2,children:[e.jsx(y,{name:"ownerId",control:t,defaultValue:s?.ownerId,render:({field:a,fieldState:i})=>e.jsx(A,{...a,data:b,value:a.value,disabled:h,label:"Owners",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:i.error?.message,withinPortal:!0})}),e.jsx(y,{name:"fromDate",control:t,defaultValue:s?.fromDate,rules:{pattern:{value:F,message:"Date must be im format yyyy-mm-dd"}},render:({field:a,fieldState:i})=>e.jsx(B,{...a,onChange:u=>{const T=u?typeof u=="string"?u:M(u,"yyyy-MM-dd"):void 0;T!==a.value&&a.onChange(T)},value:a.value?new Date(a.value):void 0,error:i.error?.message,label:"From Date",popoverProps:{withinPortal:!0}})}),e.jsx(y,{name:"toDate",control:t,defaultValue:s?.toDate,rules:{pattern:{value:F,message:"Date must be im format yyyy-mm-dd"}},render:({field:a,fieldState:i})=>e.jsx(B,{...a,onChange:u=>{const T=u?typeof u=="string"?u:M(u,"yyyy-MM-dd"):void 0;T!==a.value&&a.onChange(T)},value:a.value?new Date(a.value):void 0,error:i.error?.message,label:"To Date",popoverProps:{withinPortal:!0}})}),e.jsx(y,{name:"period",control:t,defaultValue:x.MONTHLY,render:({field:a,fieldState:i})=>e.jsx(A,{...a,data:Object.values(x).map(u=>({value:u,label:u})),value:a.value,label:"Period",maxDropdownHeight:160,error:i.error?.message,withinPortal:!0})}),e.jsx(y,{name:"excludedCounterparties",control:t,defaultValue:s.excludedCounterparties,render:({field:a,fieldState:i})=>e.jsx(E,{...a,data:f,value:a.value??[],disabled:v,label:"Excluded Counterparties",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:i.error?.message,withinPortal:!0})}),e.jsx(y,{name:"includedTags",control:t,defaultValue:s.includedTags,render:({field:a,fieldState:i})=>e.jsx(E,{...a,data:l,value:a.value??[],disabled:j,label:"Included Tags",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:i.error?.message,withinPortal:!0})}),e.jsx(y,{name:"excludedTags",control:t,defaultValue:s.excludedTags,render:({field:a,fieldState:i})=>e.jsx(E,{...a,data:o,value:a.value??[],disabled:j,label:"Excluded Tags",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:i.error?.message,withinPortal:!0})})]}),e.jsxs("div",{className:"flex justify-center mt-5 gap-3",children:[e.jsx("button",{type:"submit",disabled:h,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-rose-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-rose-600 rounded-sm text-lg",onClick:c,children:"Cancel"})]})]})}function Te({filter:s,setFilter:n,initiallyOpened:c=!1}){const[t,r]=m.useState(c),[g,b]=m.useState(!!s),{get:h,set:f}=R();m.useEffect(()=>{const p=k(s),j=h(L);p!==j&&f(L,p)},[s,h,f]);const v=m.useCallback(p=>{V(p,s)||(n(p),b(!!p))},[s,n]);return e.jsxs("div",{className:"flex flex-row gap-5 items-center",children:[e.jsx(q,{opened:t,onClose:()=>r(!1),content:e.jsx(Ce,{filter:s,setFilter:v,closeModal:()=>r(!1)}),modalSize:"xl"}),e.jsx(Q,{inline:!0,size:16,disabled:!g,children:e.jsx(I,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>r(!0),children:e.jsx(G,{className:"size-5"})})})]})}const we=({period:s,transactionIDs:n,onCloseExtendedTransactions:c})=>{const[{data:t,fetching:r}]=U({query:Z,variables:{transactionIDs:n}}),g=m.useMemo(()=>t?.transactionsByIDs?n.map(b=>t?.transactionsByIDs.find(h=>h.id===b)).filter(Boolean):[],[t,n]);return e.jsx(P,{className:"mt-5 w-full",children:r?e.jsx($,{}):e.jsxs(e.Fragment,{children:[e.jsx(Y,{children:e.jsxs(ee,{className:"flex justify-between",children:[e.jsxs("span",{children:[s," Transactions"]}),e.jsx(I,{variant:"link",onClick:c,children:e.jsx(ae,{className:"h-4 w-4"})})]})}),e.jsx(O,{children:e.jsx(se,{transactionsProps:g})})]})})};function Be(s){const n=new URLSearchParams,c=k(s);return c&&n.append(L,c),`/reports/balance${n.size>0?`?${n}`:""}`}const w={income:{label:"Income",color:"rgba(0, 255, 50, 0.5)"},expense:{label:"Expense",color:"rgba(255, 0, 0, 0.5)"},delta:{label:"Delta",color:"rgba(0, 30, 255, 0.5)"},cumulative:{label:"Cumulative Balance",color:"rgba(100, 0, 255, 0.5)"}};function Ne(s,n,c){switch(c){case x.MONTHLY:{const t=String(n).padStart(2,"0");return`${s}-${t}`}case x.BI_MONTHLY:{const t=n%2===0?n-1:n,r=String(t).padStart(2,"0");return`${s}-${r}`}case x.QUARTERLY:{const t=Math.ceil(n/3);return`${s}-Q${t}`}case x.SEMI_ANNUALLY:{const t=n>6?2:1;return`${s}-H${t}`}case x.ANNUALLY:return String(s)}}function Se(s,n){switch(n){case x.MONTHLY:{const[c,t]=s.split("-");return`${t}/${c}`}case x.BI_MONTHLY:{const[c,t]=s.split("-"),r=Number(t)+1,g=String(r).padStart(2,"0");return`${t}-${g}/${c}`}case x.QUARTERLY:{const[c,t]=s.split("-");return`${t}, ${c}`}case x.SEMI_ANNUALLY:{const[c,t]=s.split("-");return`${t}, ${c}`}case x.ANNUALLY:return s}}const D=ie(de.Usd),De=()=>{const{setFiltersContext:s}=m.useContext(te),{userContext:n}=m.useContext(re),{get:c}=R(),t=m.useMemo(()=>{const l={ownerId:n?.context.adminBusinessId,toDate:M(new Date,"yyyy-MM-dd"),period:x.MONTHLY,fromDate:M(ye(new Date,{years:1}),"yyyy-MM-dd"),excludedCounterparties:[],includedTags:[],excludedTags:[]},d=c(L);if(d)try{return JSON.parse(decodeURIComponent(d))}catch(o){console.log("Error parsing balance report filters from URL:",o)}return l},[n?.context.adminBusinessId,c]),[r,g]=m.useState(t),[b,h]=m.useState(void 0),[f,v]=m.useState(Object.keys(w)),p=m.useMemo(()=>{const{ownerId:l,fromDate:d,toDate:o}=r;return{ownerId:l,fromDate:d,toDate:o}},[r]),[{data:j,fetching:S}]=U({query:ce,variables:p,pause:!r});m.useEffect(()=>{s(e.jsxs("div",{className:"flex flex-row gap-x-5",children:[e.jsx(Te,{filter:r,setFilter:g,initiallyOpened:!r}),e.jsx(ne,{options:Object.entries(w).map(([l,d])=>({label:d.label,value:l})),onValueChange:v,defaultValue:f,placeholder:"Select Data Sets",variant:"default",maxCount:1})]})),h(void 0)},[j,S,r,s,g,f]),m.useEffect(()=>{g(l=>({...l,ownerId:n?.context.adminBusinessId}))},[n]);const C=m.useMemo(()=>{if(!j?.transactionsForBalanceReport)return[];const l=new Map;j.transactionsForBalanceReport.map(o=>{if(o.counterparty?.id&&(!o.isFee&&n?.context.financialAccountsBusinessesIds?.includes(o.counterparty.id)||r.excludedCounterparties?.includes(o.counterparty.id))||r.includedTags.length>0&&(!o.charge?.tags||o.charge.tags.length===0||!o.charge.tags.some(u=>r.includedTags.includes(u.id)))||r.excludedTags.length>0&&o.charge?.tags.length&&o.charge.tags.some(u=>r.excludedTags.includes(u.id)))return;const a=Ne(o.year,o.month,r.period);l.has(a)||l.set(a,{income:0,expense:0,delta:0,transactions:[]});const i=l.get(a);o.amountUsd.raw>0?i.income+=o.amountUsd.raw:i.expense+=o.amountUsd.raw,i.delta+=o.amountUsd.raw,i.transactions.push(o)});let d=0;return Array.from(l.entries()).sort((o,a)=>o[0].localeCompare(a[0])).map(([o,a])=>(d+=a.delta,{period:o,income:a.income,expense:a.expense,delta:a.delta,cumulative:d,transactions:a.transactions.sort((i,u)=>Math.abs(u.amountUsd.raw)-Math.abs(i.amountUsd.raw))}))},[j,r.period,r.excludedCounterparties,n?.context.financialAccountsBusinessesIds,r.includedTags,r.excludedTags]);return e.jsx(oe,{title:"Balance Report",description:"Accounts periodical balance",children:S?e.jsx($,{}):e.jsxs(e.Fragment,{children:[e.jsxs(P,{className:"w-full",children:[e.jsx(Y,{children:e.jsx(le,{children:"Click specific period to expand it's transactions data"})}),e.jsx(O,{children:e.jsx(xe,{config:w,className:"h-150 w-full",children:e.jsxs(ve,{accessibilityLayer:!0,data:C,onClick:l=>h(l.activeLabel),children:[e.jsx(ge,{vertical:!1}),e.jsx(H,{dataKey:"period",tickLine:!1,tickMargin:10,axisLine:!1,tickFormatter:l=>Se(l,r.period)}),e.jsx(he,{content:e.jsx(fe,{formatter:(l,d,o,a)=>{const i=`bg-[var(--color-${d})]`;return a<2?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:`${i} h-2.5 w-2.5 shrink-0 rounded-[2px]`}),w[d]?.label||d,e.jsx("div",{className:"ml-auto flex items-baseline gap-0.5 font-mono font-medium tabular-nums text-foreground",children:D.format(Number(l))})]}):e.jsxs("div",{className:"mt-1.5 flex basis-full items-center border-t pt-1.5 text-xs font-medium text-foreground",children:[e.jsx("div",{className:`h-2.5 w-2.5 shrink-0 rounded-[2px] mr-2 ${i}`}),w[d]?.label||d,e.jsx("div",{className:"ml-auto flex items-baseline gap-0.5 font-mono font-medium tabular-nums text-foreground",children:D.format(Number(l))})]})}})}),e.jsx(be,{content:e.jsx(je,{})}),f.includes("income")&&e.jsx(N,{dataKey:"income",fill:"var(--color-income)",radius:4}),f.includes("expense")&&e.jsx(N,{dataKey:"expense",fill:"var(--color-expense)",radius:4}),f.includes("delta")&&e.jsx(N,{dataKey:"delta",fill:"var(--color-delta)",radius:4}),f.includes("cumulative")&&e.jsx(N,{dataKey:"cumulative",fill:"var(--color-cumulative)",radius:4})]})})})]}),b&&e.jsx(we,{period:b,onCloseExtendedTransactions:()=>h(void 0),transactionIDs:C.find(l=>l.period===b)?.transactions.map(l=>l.id)??[]})]})})};export{De as BalanceReport,Be as getBalanceReportHref};