@accounter/client 0.0.8-alpha-20251027152122-3a28383f5256a0af85ebc9a1667c671cd03d1217 → 0.0.8-alpha-20251027160338-ca62e8e69bd7874decbfbb4576775bd3aeaf8d17

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 (67) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/dist/assets/{Checkbox-BO9Xpz8t.js → Checkbox-BPO8_jMH.js} +2 -2
  3. package/dist/assets/{Progress-D2_rEDMg.js → Progress-NZzZXmow.js} +1 -1
  4. package/dist/assets/{Typography-D5R2ABRc.js → Typography-IaNz_UpB.js} +1 -1
  5. package/dist/assets/{accordion-BdInypOR.js → accordion-DLhPc0rw.js} +1 -1
  6. package/dist/assets/{accountant-approvals-Dxukyb2L.js → accountant-approvals--bHmgziw.js} +1 -1
  7. package/dist/assets/{all-charges-CKoiOatE.js → all-charges-n5LCQpkn.js} +1 -1
  8. package/dist/assets/{arrow-up-down-CkKoHOZz.js → arrow-up-down-CM9bwo8G.js} +1 -1
  9. package/dist/assets/{building-2-DqnthsV_.js → building-2-HRA8xsoA.js} +1 -1
  10. package/dist/assets/business-Cc9BXzpb.js +32 -0
  11. package/dist/assets/{business-header-BoDcKSl2.js → business-header-D0Pi0ox5.js} +1 -1
  12. package/dist/assets/{business-transactions-single-sJPwKffn.js → business-transactions-single-CEYMQLQD.js} +1 -1
  13. package/dist/assets/{business-trip-ak7ozCMK.js → business-trip-CJO6fi9D.js} +1 -1
  14. package/dist/assets/{charges-filters-BZS9K5l_.js → charges-filters-hjHQC8jb.js} +1 -1
  15. package/dist/assets/{charges-ledger-validation-Dn1tKuHo.js → charges-ledger-validation-B-CsyNZK.js} +1 -1
  16. package/dist/assets/{chart-D5qMOolQ.js → chart-Dt1GKbU0.js} +1 -1
  17. package/dist/assets/{data-table-pagination-DNmtrpVu.js → data-table-pagination-YsvftRMU.js} +1 -1
  18. package/dist/assets/{editable-business-trip-tuSBklIH.js → editable-business-trip-DVC29gsX.js} +2 -2
  19. package/dist/assets/{index-cI8Jsxnd.js → index-9gE-VJnf.js} +1 -1
  20. package/dist/assets/{index-B8uhIk_K.js → index-B6wS4Wxh.js} +1 -1
  21. package/dist/assets/{index-1y5LxkZU.js → index-BC8lCcej.js} +1 -1
  22. package/dist/assets/{index-BUrkGANf.js → index-BEDk77TL.js} +1 -1
  23. package/dist/assets/{index-BEycb-eF.js → index-BgzvCxY1.js} +1 -1
  24. package/dist/assets/{index-mPs7_Pzt.js → index-BmHIdR_i.js} +1 -1
  25. package/dist/assets/{index-Dbs_Faiq.js → index-BoRdLlCV.js} +1 -1
  26. package/dist/assets/index-BowN47so.js +1 -0
  27. package/dist/assets/{index-zNOIAEsv.js → index-ByZ_pm4F.js} +1 -1
  28. package/dist/assets/{index-BUOmPZZE.js → index-BykvJIPg.js} +1 -1
  29. package/dist/assets/{index-rzb-Wfyn.js → index-C1QP_1hi.js} +2 -2
  30. package/dist/assets/{index-DO9LsGUk.js → index-C5THrBcZ.js} +2 -2
  31. package/dist/assets/{index-Cq_8eDaQ.js → index-CAz755Vg.js} +1 -1
  32. package/dist/assets/index-CBPTpZHL.css +1 -0
  33. package/dist/assets/{index-Bm0ybubD.js → index-CRMsr3ea.js} +1 -1
  34. package/dist/assets/{index-CoP8rTKg.js → index-CRpqdixQ.js} +1 -1
  35. package/dist/assets/{index-8n4-QaWx.js → index-CebS9Rr6.js} +2 -2
  36. package/dist/assets/{index-CPDxJ2sU.js → index-CpAsLkZ-.js} +2 -2
  37. package/dist/assets/{index-B-M613Ei.js → index-D4QXCBac.js} +2 -2
  38. package/dist/assets/{index-DUfo3Krp.js → index-DFDi4HIa.js} +1 -1
  39. package/dist/assets/{index-Bv4hj0Jy.js → index-DYbojoX7.js} +2 -2
  40. package/dist/assets/{index-CwWYxYTu.js → index-O4Zp6w2B.js} +1 -1
  41. package/dist/assets/{index-CQrnA6kA.js → index-nOsVSS34.js} +7 -7
  42. package/dist/assets/{index-C1vFqfE7.js → index-xIO0bA36.js} +258 -263
  43. package/dist/assets/{index.es-CaCwgSGE.js → index.es-B9NUKbEG.js} +1 -1
  44. package/dist/assets/{issue-document-CiJeX3C9.js → issue-document-CUSNTaeZ.js} +1 -1
  45. package/dist/assets/{login-page-YiLbVzv0.js → login-page-DmLdOH1y.js} +1 -1
  46. package/dist/assets/{missing-info-charges-Dz2clKfl.js → missing-info-charges-DsgMcotI.js} +1 -1
  47. package/dist/assets/{page-not-found-4Tf0NkPJ.js → page-not-found-B8fy5aDg.js} +1 -1
  48. package/dist/assets/{pencil-DgX1JiCS.js → pencil-Dmfzg-6O.js} +1 -1
  49. package/dist/assets/{report-commentary-row-CiD9pNPE.js → report-commentary-row-BPh5_3g6.js} +1 -1
  50. package/dist/assets/{save-DQHS5I6h.js → save-BPUtJeTy.js} +1 -1
  51. package/dist/assets/{sub-DVpRQI4L.js → sub-CqZ9jxmt.js} +1 -1
  52. package/dist/assets/subMonths-CwZPyK0k.js +1 -0
  53. package/dist/index.html +2 -2
  54. package/package.json +1 -1
  55. package/src/components/business/admin-business-section.tsx +36 -74
  56. package/src/components/business/contracts-section.tsx +18 -4
  57. package/src/components/clients/contracts/modify-contract-dialog.tsx +65 -11
  58. package/src/components/clients/modify-client-dialog.tsx +9 -27
  59. package/src/components/common/modals/insert-business.tsx +36 -87
  60. package/src/components/layout/user-nav.tsx +3 -25
  61. package/src/gql/gql.ts +9 -9
  62. package/src/gql/graphql.ts +23 -26
  63. package/src/hooks/use-get-all-contracts.ts +1 -1
  64. package/dist/assets/business-BtfvlRp_.js +0 -27
  65. package/dist/assets/index-B5E9Adf1.js +0 -1
  66. package/dist/assets/index-DtE5Y1ZB.css +0 -1
  67. package/dist/assets/subMonths-CFZKY9ia.js +0 -1
@@ -1 +1 @@
1
- import{a as M,dE as X,t as C,r as s,i as Y,l as K,dF as Q,dG as J,X as F,dH as S,j as e,K as R,aW as G,B as v,aC as U,N as q,aX as W,aY as Z,au as _,av as ee,aw as se,ax as te,az as ne,dI as ae,dJ as re,dK as H,dL as z,c8 as ce,dM as V,dN as ie,Y as k,a2 as B,L as A,dO as le,g as oe,Z as de,$ as ue,dP as me,bn as he,b9 as xe,dQ as je,H as P,dR as $,V as pe,bN as fe,G as ge,a1 as ye,bg as ve,dc as De,dn as be,dp as Ce,dq as O,dr as g,dt as Ne,du as y,aE as we,c2 as Ie,F as Me,n as Te}from"./index-C1vFqfE7.js";import{s as L}from"./subMonths-CFZKY9ia.js";const Ee=()=>{const[{data:u,fetching:o,error:c},x]=M({query:X});c&&(console.error(`Error fetching contracts: ${c}`),C.error("Error",{description:"Unable to fetch contracts"}));const a=s.useMemo(()=>u?.allOpenContracts?.slice().sort((t,d)=>t.client.originalBusiness.name>d.client.originalBusiness.name?1:-1)??[],[u]),i=s.useMemo(()=>a.map(t=>({value:t.id,label:t.client.originalBusiness.name})),[a]);return{fetching:o,refresh:()=>x(),openContracts:a,selectableOpenContracts:i}},Fe="IssueMonthlyDocuments",Se=()=>{const[{fetching:u},o]=Y(Q),c=s.useCallback(async x=>{const a="Error issuing monthly documents",i=Fe;C.loading("Issuing documents",{id:i});try{const t=await o(x),d=K(t,a,i);if(d?.issueGreenInvoiceDocuments?.success){C.success("Success",{id:i,description:"Documents issued successfully"});return}d?.issueGreenInvoiceDocuments?.errors&&console.error(d.issueGreenInvoiceDocuments.errors),C.error("Error",{id:i,description:a,duration:1e5,closeButton:!0})}catch(t){console.error(`${a}: ${t}`),C.error("Error",{id:i,description:a,duration:1e5,closeButton:!0})}},[o]);return{fetching:u,issueDocuments:c}};function Pe({issueMonth:u,contracts:o,onAdd:c}){const[x,a]=s.useState(!1),[i,t]=s.useState(""),[{data:d},h]=M({query:J,variables:{issueMonth:u,clientId:i}}),j=s.useCallback(n=>{t(n),h()},[h,t]);return s.useEffect(()=>{i!==""&&d&&(c(F(S,d.clientMonthlyChargeDraft)),a(!1))},[i,d,c]),e.jsxs(R,{open:x,onOpenChange:a,children:[e.jsx(G,{asChild:!0,children:e.jsx(v,{variant:"outline",size:"icon",children:e.jsx(U,{})})}),e.jsxs(q,{className:"w-[400px] max-w-screen-md",children:[e.jsx(W,{children:e.jsx(Z,{children:"Select document recipient"})}),e.jsxs(_,{onValueChange:j,children:[e.jsx(ee,{children:e.jsx(se,{placeholder:"Recipient"})}),e.jsx(te,{children:o.map(n=>e.jsx(ne,{value:n.client.originalBusiness.id,children:n.client.originalBusiness.name},n.client.originalBusiness.id))})]})]})]})}function ke({onApprove:u,draft:o}){const[c,x]=s.useState(!1),[a,i]=s.useState(!1),[t,d]=s.useState(null),{previewDocument:h,fetching:j}=ae(),[n,N]=s.useState(re(o)),T=s.useCallback((l,p)=>{N(f=>({...f,[l]:p}))},[]);s.useEffect(()=>{i(!1)},[n]);const D=s.useCallback(async()=>{try{const l=await h({input:n});if(!l)throw new Error("No preview data returned");d(l),i(!0)}catch(l){console.error("Failed to generate preview:",l)}},[n,h]);s.useEffect(()=>{c&&!t&&D()},[c,t,D]);const w=n.income?.reduce((l,p)=>{const f=p.price*p.quantity,r=f*((p.vatRate||0)/100);return l+f+r},0)||0,I=()=>{u(n),x(!1)};return e.jsxs(R,{open:c,onOpenChange:x,children:[e.jsx(G,{asChild:!0,type:"button",children:e.jsxs(H,{children:[e.jsx(z,{asChild:!0,type:"button",children:e.jsx(v,{className:"size-7.5",variant:"secondary",onClick:()=>x(l=>!l),type:"button",children:e.jsx(ce,{className:"size-5"})})}),e.jsx(V,{children:e.jsx("p",{children:"Edit document"})})]})}),e.jsx(q,{className:"w-7xl sm:max-w-[95%] max-h-[90vh] overflow-y-auto",children:e.jsx("div",{className:"min-h-screen bg-gray-50 p-4",children:e.jsxs("div",{className:"max-w-7xl mx-auto",children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("h1",{className:"text-3xl font-bold text-gray-900",children:"Edit Document"}),e.jsx("p",{className:"text-gray-600 mt-2",children:"Modify and preview your accounting document before issuing"})]}),e.jsxs("div",{className:"grid lg:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"space-y-6",children:[e.jsx(ie,{formData:n,updateFormData:T}),e.jsx(k,{children:e.jsxs(B,{className:"pt-6",children:[e.jsxs("div",{className:"flex gap-3",children:[e.jsx(v,{onClick:D,disabled:j||a,variant:"outline",className:"flex-1 bg-transparent",children:j?e.jsxs(e.Fragment,{children:[e.jsx(A,{className:"w-4 h-4 mr-2 animate-spin"}),"Generating..."]}):e.jsxs(e.Fragment,{children:[e.jsx(le,{className:"w-4 h-4 mr-2"}),"Preview"]})}),e.jsxs(v,{onClick:I,className:"flex-1",children:[e.jsx(oe,{className:"w-4 h-4 mr-2"}),"Accept Changes"]})]}),w>0&&e.jsx("div",{className:"mt-4 p-3 bg-blue-50 rounded-lg",children:e.jsxs("div",{className:"flex justify-between items-center font-medium text-blue-900",children:[e.jsx("span",{children:"Total Document Amount:"}),e.jsxs("span",{children:[w.toFixed(2)," ",n.currency]})]})})]})})]}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs(k,{className:"h-fit",children:[e.jsx(de,{children:e.jsx(ue,{children:"Document Preview"})}),e.jsx(B,{children:e.jsx("div",{className:"border-2 border-dashed border-gray-200 rounded-lg min-h-[600px] flex items-center justify-center bg-gray-50",children:j?e.jsxs("div",{className:"text-center",children:[e.jsx(A,{className:"w-8 h-8 animate-spin mx-auto mb-4 text-gray-400"}),e.jsx("p",{className:"text-gray-500",children:"Generating document preview..."})]}):t?e.jsx("div",{className:"w-full",children:e.jsx("div",{className:"bg-white shadow-lg rounded-lg overflow-hidden",children:e.jsx("div",{className:"aspect-[8.5/11] bg-white border",children:e.jsx("div",{className:"h-full flex items-center justify-center",children:e.jsxs("div",{className:"text-center p-6",children:[e.jsx(me,{src:t}),!a&&e.jsx("p",{className:"text-xs text-amber-600 mt-3 bg-amber-50 px-2 py-1 rounded",children:"Preview may be outdated"})]})})})})}):e.jsxs("div",{className:"text-center",children:[e.jsx(he,{className:"w-16 h-16 mx-auto mb-4 text-gray-300"}),e.jsx("p",{className:"text-gray-500 mb-2",children:"No preview available"}),e.jsx("p",{className:"text-sm text-gray-400",children:"Click Preview to generate document"})]})})})]}),n.client?.id&&e.jsx(xe,{businessId:n.client?.id,linkedDocumentIds:n.linkedDocumentIds??[]}),e.jsx(je,{documentType:n.type})]})]})]})})})]})}const Be=({drafts:u})=>{const[o,c]=s.useState(u.map(r=>F(S,r))),x=P(L(new Date,1),"yyyy-MM-dd"),[a,i]=s.useState(x),[{data:t},d]=M({query:$,variables:{issueMonth:a},pause:!0});s.useEffect(()=>{t?.clientMonthlyChargesDrafts&&c(t.clientMonthlyChargesDrafts.map(r=>F(S,r)))},[t,c]),s.useEffect(()=>{d()},[a,d]);const h=pe({values:{generateDocumentsInfo:o}}),{issueDocuments:j}=Se(),{openContracts:n}=Ee(),{fields:N,append:T,remove:D,update:w}=fe({control:h.control,name:"generateDocumentsInfo"}),I=h.watch("generateDocumentsInfo"),l=s.useMemo(()=>N.map((r,m)=>({...r,...I[m],id:r.client?.id})),[N,I]),p=s.useCallback(r=>{j(r)},[j]),f=s.useMemo(()=>n.filter(r=>r.billingCycle===ge.Monthly&&!l.some(m=>m.client?.id===r.client.originalBusiness.id)),[l,n]);return e.jsx("div",{className:"p-2",children:e.jsx(ye,{...h,children:e.jsxs("form",{onSubmit:h.handleSubmit(p),children:[e.jsxs("div",{className:"flex gap-2 items-center mb-4",children:[e.jsx(ve,{children:"Issue Month:"}),e.jsx(De,{value:new Date(a),onChange:r=>{const m=new Date(r.getFullYear(),r.getMonth(),15);i(P(m,"yyyy-MM-dd"))},popoverProps:{withinPortal:!0}})]}),e.jsxs(be,{children:[e.jsx(Ce,{children:e.jsxs(O,{children:[e.jsx(g,{children:"Name"}),e.jsx(g,{children:"Document"}),e.jsx(g,{children:"Amount"}),e.jsx(g,{children:"Remark"}),e.jsx(g,{children:"Recipients"}),e.jsx(g,{})]})}),e.jsx(Ne,{children:l.map(({id:r,...m},E)=>e.jsxs(O,{children:[e.jsx(y,{children:m.client?.name}),e.jsx(y,{children:m.type}),e.jsxs(y,{children:[m.income?.[0]?.price," ",m.income?.[0]?.currency]}),e.jsx(y,{children:e.jsx("span",{className:"text-sm text-gray-500 whitespace-normal max-w-50",children:m.remarks})}),e.jsx(y,{children:e.jsx("div",{className:"flex flex-col",children:m.client?.emails?.map(b=>e.jsx("span",{className:"text-sm text-gray-500",children:b},b))})}),e.jsx(y,{children:e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs(H,{children:[e.jsx(z,{asChild:!0,type:"button",children:e.jsx(v,{className:"size-7.5",variant:"secondary",onClick:()=>D(E),children:e.jsx(we,{size:16})})}),e.jsx(V,{children:e.jsx("p",{children:"Remove document"})})]}),e.jsx(ke,{draft:m,onApprove:b=>{h.setValue(`generateDocumentsInfo.${E}`,b,{shouldDirty:!0,shouldTouch:!0,shouldValidate:!0}),w(E,{...b})}})]})})]},r))})]}),e.jsxs("div",{className:"flex justify-between items-center mt-4",children:[e.jsx(Pe,{contracts:f,onAdd:T,issueMonth:a}),e.jsx(Ie,{onConfirm:h.handleSubmit(p),title:`Are you sure you want to issue ${l.length} documents?`,children:e.jsx(v,{children:"Issue"})})]})]})})})},Re=()=>{const{setFiltersContext:u}=s.useContext(Me),[{data:o,fetching:c}]=M({query:$,variables:{issueMonth:P(L(new Date,1),"yyyy-MM-dd")}});return s.useEffect(()=>{o?.clientMonthlyChargesDrafts||u(null)},[o,u]),c?e.jsx(Te,{}):e.jsx(Be,{drafts:o?.clientMonthlyChargesDrafts??[]})};export{Re as IssueDocuments};
1
+ import{a as M,dD as K,t as C,r as s,i as Q,l as X,dE as Y,dF as _,X as S,dG as E,j as e,K as R,an as q,B as v,ao as J,N as G,ap as U,aq as Z,au as W,av as ee,aw as se,ax as te,ay as ne,dH as ae,dI as re,dJ as H,dK as V,c7 as ce,dL as z,dM as ie,Y as k,a1 as B,L as A,dN as le,g as oe,Z as de,_ as ue,dO as me,bm as he,b9 as xe,dP as je,H as P,dQ as L,V as pe,bM as fe,G as ge,a0 as ye,bf as ve,db as De,dm as be,dn as Ce,dp as O,dq as g,ds as Ne,dt as y,at as we,c1 as Ie,F as Me,n as Te}from"./index-xIO0bA36.js";import{s as $}from"./subMonths-CwZPyK0k.js";const Fe=()=>{const[{data:u,fetching:o,error:c},x]=M({query:K});c&&(console.error(`Error fetching contracts: ${c}`),C.error("Error",{description:"Unable to fetch contracts"}));const a=s.useMemo(()=>u?.allOpenContracts?.slice().sort((t,d)=>t.client.originalBusiness.name>d.client.originalBusiness.name?1:-1)??[],[u]),i=s.useMemo(()=>a.map(t=>({value:t.id,label:t.client.originalBusiness.name})),[a]);return{fetching:o,refresh:()=>x(),openContracts:a,selectableOpenContracts:i}},Se="IssueMonthlyDocuments",Ee=()=>{const[{fetching:u},o]=Q(Y),c=s.useCallback(async x=>{const a="Error issuing monthly documents",i=Se;C.loading("Issuing documents",{id:i});try{const t=await o(x),d=X(t,a,i);if(d?.issueGreenInvoiceDocuments?.success){C.success("Success",{id:i,description:"Documents issued successfully"});return}d?.issueGreenInvoiceDocuments?.errors&&console.error(d.issueGreenInvoiceDocuments.errors),C.error("Error",{id:i,description:a,duration:1e5,closeButton:!0})}catch(t){console.error(`${a}: ${t}`),C.error("Error",{id:i,description:a,duration:1e5,closeButton:!0})}},[o]);return{fetching:u,issueDocuments:c}};function Pe({issueMonth:u,contracts:o,onAdd:c}){const[x,a]=s.useState(!1),[i,t]=s.useState(""),[{data:d},h]=M({query:_,variables:{issueMonth:u,clientId:i}}),j=s.useCallback(n=>{t(n),h()},[h,t]);return s.useEffect(()=>{i!==""&&d&&(c(S(E,d.clientMonthlyChargeDraft)),a(!1))},[i,d,c]),e.jsxs(R,{open:x,onOpenChange:a,children:[e.jsx(q,{asChild:!0,children:e.jsx(v,{variant:"outline",size:"icon",children:e.jsx(J,{})})}),e.jsxs(G,{className:"w-[400px] max-w-screen-md",children:[e.jsx(U,{children:e.jsx(Z,{children:"Select document recipient"})}),e.jsxs(W,{onValueChange:j,children:[e.jsx(ee,{children:e.jsx(se,{placeholder:"Recipient"})}),e.jsx(te,{children:o.map(n=>e.jsx(ne,{value:n.client.originalBusiness.id,children:n.client.originalBusiness.name},n.client.originalBusiness.id))})]})]})]})}function ke({onApprove:u,draft:o}){const[c,x]=s.useState(!1),[a,i]=s.useState(!1),[t,d]=s.useState(null),{previewDocument:h,fetching:j}=ae(),[n,N]=s.useState(re(o)),T=s.useCallback((l,p)=>{N(f=>({...f,[l]:p}))},[]);s.useEffect(()=>{i(!1)},[n]);const D=s.useCallback(async()=>{try{const l=await h({input:n});if(!l)throw new Error("No preview data returned");d(l),i(!0)}catch(l){console.error("Failed to generate preview:",l)}},[n,h]);s.useEffect(()=>{c&&!t&&D()},[c,t,D]);const w=n.income?.reduce((l,p)=>{const f=p.price*p.quantity,r=f*((p.vatRate||0)/100);return l+f+r},0)||0,I=()=>{u(n),x(!1)};return e.jsxs(R,{open:c,onOpenChange:x,children:[e.jsx(q,{asChild:!0,type:"button",children:e.jsxs(H,{children:[e.jsx(V,{asChild:!0,type:"button",children:e.jsx(v,{className:"size-7.5",variant:"secondary",onClick:()=>x(l=>!l),type:"button",children:e.jsx(ce,{className:"size-5"})})}),e.jsx(z,{children:e.jsx("p",{children:"Edit document"})})]})}),e.jsx(G,{className:"w-7xl sm:max-w-[95%] max-h-[90vh] overflow-y-auto",children:e.jsx("div",{className:"min-h-screen bg-gray-50 p-4",children:e.jsxs("div",{className:"max-w-7xl mx-auto",children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("h1",{className:"text-3xl font-bold text-gray-900",children:"Edit Document"}),e.jsx("p",{className:"text-gray-600 mt-2",children:"Modify and preview your accounting document before issuing"})]}),e.jsxs("div",{className:"grid lg:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"space-y-6",children:[e.jsx(ie,{formData:n,updateFormData:T}),e.jsx(k,{children:e.jsxs(B,{className:"pt-6",children:[e.jsxs("div",{className:"flex gap-3",children:[e.jsx(v,{onClick:D,disabled:j||a,variant:"outline",className:"flex-1 bg-transparent",children:j?e.jsxs(e.Fragment,{children:[e.jsx(A,{className:"w-4 h-4 mr-2 animate-spin"}),"Generating..."]}):e.jsxs(e.Fragment,{children:[e.jsx(le,{className:"w-4 h-4 mr-2"}),"Preview"]})}),e.jsxs(v,{onClick:I,className:"flex-1",children:[e.jsx(oe,{className:"w-4 h-4 mr-2"}),"Accept Changes"]})]}),w>0&&e.jsx("div",{className:"mt-4 p-3 bg-blue-50 rounded-lg",children:e.jsxs("div",{className:"flex justify-between items-center font-medium text-blue-900",children:[e.jsx("span",{children:"Total Document Amount:"}),e.jsxs("span",{children:[w.toFixed(2)," ",n.currency]})]})})]})})]}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs(k,{className:"h-fit",children:[e.jsx(de,{children:e.jsx(ue,{children:"Document Preview"})}),e.jsx(B,{children:e.jsx("div",{className:"border-2 border-dashed border-gray-200 rounded-lg min-h-[600px] flex items-center justify-center bg-gray-50",children:j?e.jsxs("div",{className:"text-center",children:[e.jsx(A,{className:"w-8 h-8 animate-spin mx-auto mb-4 text-gray-400"}),e.jsx("p",{className:"text-gray-500",children:"Generating document preview..."})]}):t?e.jsx("div",{className:"w-full",children:e.jsx("div",{className:"bg-white shadow-lg rounded-lg overflow-hidden",children:e.jsx("div",{className:"aspect-[8.5/11] bg-white border",children:e.jsx("div",{className:"h-full flex items-center justify-center",children:e.jsxs("div",{className:"text-center p-6",children:[e.jsx(me,{src:t}),!a&&e.jsx("p",{className:"text-xs text-amber-600 mt-3 bg-amber-50 px-2 py-1 rounded",children:"Preview may be outdated"})]})})})})}):e.jsxs("div",{className:"text-center",children:[e.jsx(he,{className:"w-16 h-16 mx-auto mb-4 text-gray-300"}),e.jsx("p",{className:"text-gray-500 mb-2",children:"No preview available"}),e.jsx("p",{className:"text-sm text-gray-400",children:"Click Preview to generate document"})]})})})]}),n.client?.id&&e.jsx(xe,{businessId:n.client?.id,linkedDocumentIds:n.linkedDocumentIds??[]}),e.jsx(je,{documentType:n.type})]})]})]})})})]})}const Be=({drafts:u})=>{const[o,c]=s.useState(u.map(r=>S(E,r))),x=P($(new Date,1),"yyyy-MM-dd"),[a,i]=s.useState(x),[{data:t},d]=M({query:L,variables:{issueMonth:a},pause:!0});s.useEffect(()=>{t?.clientMonthlyChargesDrafts&&c(t.clientMonthlyChargesDrafts.map(r=>S(E,r)))},[t,c]),s.useEffect(()=>{d()},[a,d]);const h=pe({values:{generateDocumentsInfo:o}}),{issueDocuments:j}=Ee(),{openContracts:n}=Fe(),{fields:N,append:T,remove:D,update:w}=fe({control:h.control,name:"generateDocumentsInfo"}),I=h.watch("generateDocumentsInfo"),l=s.useMemo(()=>N.map((r,m)=>({...r,...I[m],id:r.client?.id})),[N,I]),p=s.useCallback(r=>{j(r)},[j]),f=s.useMemo(()=>n.filter(r=>r.billingCycle===ge.Monthly&&!l.some(m=>m.client?.id===r.client.originalBusiness.id)),[l,n]);return e.jsx("div",{className:"p-2",children:e.jsx(ye,{...h,children:e.jsxs("form",{onSubmit:h.handleSubmit(p),children:[e.jsxs("div",{className:"flex gap-2 items-center mb-4",children:[e.jsx(ve,{children:"Issue Month:"}),e.jsx(De,{value:new Date(a),onChange:r=>{const m=new Date(r.getFullYear(),r.getMonth(),15);i(P(m,"yyyy-MM-dd"))},popoverProps:{withinPortal:!0}})]}),e.jsxs(be,{children:[e.jsx(Ce,{children:e.jsxs(O,{children:[e.jsx(g,{children:"Name"}),e.jsx(g,{children:"Document"}),e.jsx(g,{children:"Amount"}),e.jsx(g,{children:"Remark"}),e.jsx(g,{children:"Recipients"}),e.jsx(g,{})]})}),e.jsx(Ne,{children:l.map(({id:r,...m},F)=>e.jsxs(O,{children:[e.jsx(y,{children:m.client?.name}),e.jsx(y,{children:m.type}),e.jsxs(y,{children:[m.income?.[0]?.price," ",m.income?.[0]?.currency]}),e.jsx(y,{children:e.jsx("span",{className:"text-sm text-gray-500 whitespace-normal max-w-50",children:m.remarks})}),e.jsx(y,{children:e.jsx("div",{className:"flex flex-col",children:m.client?.emails?.map(b=>e.jsx("span",{className:"text-sm text-gray-500",children:b},b))})}),e.jsx(y,{children:e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs(H,{children:[e.jsx(V,{asChild:!0,type:"button",children:e.jsx(v,{className:"size-7.5",variant:"secondary",onClick:()=>D(F),children:e.jsx(we,{size:16})})}),e.jsx(z,{children:e.jsx("p",{children:"Remove document"})})]}),e.jsx(ke,{draft:m,onApprove:b=>{h.setValue(`generateDocumentsInfo.${F}`,b,{shouldDirty:!0,shouldTouch:!0,shouldValidate:!0}),w(F,{...b})}})]})})]},r))})]}),e.jsxs("div",{className:"flex justify-between items-center mt-4",children:[e.jsx(Pe,{contracts:f,onAdd:T,issueMonth:a}),e.jsx(Ie,{onConfirm:h.handleSubmit(p),title:`Are you sure you want to issue ${l.length} documents?`,children:e.jsx(v,{children:"Issue"})})]})]})})})},Re=()=>{const{setFiltersContext:u}=s.useContext(Me),[{data:o,fetching:c}]=M({query:L,variables:{issueMonth:P($(new Date,1),"yyyy-MM-dd")}});return s.useEffect(()=>{o?.clientMonthlyChargesDrafts||u(null)},[o,u]),c?e.jsx(Te,{}):e.jsx(Be,{drafts:o?.clientMonthlyChargesDrafts??[]})};export{Re as IssueDocuments};
@@ -1,2 +1,2 @@
1
- import{r as P,j as r,g as H,a as J,fd as W,L as E,u as Y,ag as q,c_ as K,c$ as X,B as U,d0 as ee,V as te,ce as ne,bP as se,bQ as oe,dc as O,H as S,fe as G,d1 as re,F as ie,c as le,Y as ae,$ as ce,a2 as ue}from"./index-C1vFqfE7.js";import{A as fe,a as he,c as de,b as pe}from"./accordion-BdInypOR.js";var v={},z;function ye(){if(z)return v;z=1,Object.defineProperty(v,"__esModule",{value:!0}),v.calcSlices=v.applyPatch=v.calcPatch=v.lcs=v.diff=v.diff_core=void 0;function c(e,n){const{b:t,eq:s,stack_base:i}=e;let{i:l,N:o,j:h,M:a,Z:u,stack_top:x}=e;for(;;)switch(n){case 0:{e:for(;o>0&&a>0;){t.fill(0,0,2*u);const R=o-a,_=o+a,B=_&1,Q=l+o-1,Z=h+a-1,$=(_+B)/2;let F;t:for(let M=0;M<=$;M++){const I=2*Math.max(0,M-a)-M,L=M-2*Math.max(0,M-o);for(let f=I;f<=L;f+=2){const A=t[f-1-u*Math.floor((f-1)/u)],V=t[f+1-u*Math.floor((f+1)/u)],w=f===-M||f!==M&&A<V?V:A+1,k=w-f;let b=w,C=k;for(;b<o&&C<a&&s(l+b,h+C);)b++,C++;if(t[f-u*Math.floor(f/u)]=b,B===1&&(F=R-f)>=1-M&&F<M&&b+t[u+F-u*Math.floor(F/u)]>=o)if(M>1||b!==w){i[x++]=l+b,i[x++]=o-b,i[x++]=h+C,i[x++]=a-C,o=w,a=k,u=2*(Math.min(o,a)+1);continue e}else break t}for(let f=I;f<=L;f+=2){const A=t[u+f-1-u*Math.floor((f-1)/u)],V=t[u+f+1-u*Math.floor((f+1)/u)],w=f===-M||f!==M&&A<V?V:A+1,k=w-f;let b=w,C=k;for(;b<o&&C<a&&s(Q-b,Z-C);)b++,C++;if(t[u+f-u*Math.floor(f/u)]=b,B===0&&(F=R-f)>=-M&&F<=M&&b+t[F-u*Math.floor(F/u)]>=o)if(M>0||b!==w){i[x++]=l+o-w,i[x++]=w,i[x++]=h+a-k,i[x++]=k,o=o-b,a=a-C,u=2*(Math.min(o,a)+1);continue e}else break t}}if(o!==a){a>o?(l+=o,h+=o,a-=o,o=0):(l+=a,h+=a,o-=a,a=0);break}}if(o+a!==0)if(e.pxe===l||e.pye===h)e.pxe=l+o,e.pye=h+a;else{const R=e.pxs;if(e.oxs=e.pxs,e.oxe=e.pxe,e.oys=e.pys,e.oye=e.pye,e.pxs=l,e.pxe=l+o,e.pys=h,e.pye=h+a,R>=0)return e.i=l,e.N=o,e.j=h,e.M=a,e.Z=u,e.stack_top=x,1}}case 1:{if(x===0)return 2;a=i[--x],h=i[--x],o=i[--x],l=i[--x],u=2*(Math.min(o,a)+1),n=0}}}class m{constructor(n){this.state=n,this.c=0,this.result={value:null,done:!1}}[Symbol.iterator](){return this}next(){const{state:n,result:t}=this;if(this.c>1)return t.done=!0,t.value=void 0,t;const s=c(n,this.c);return this.c=s,s===1?(t.value=[n.oxs,n.oxe,n.oys,n.oye],t):n.pxs>=0?(t.value=[n.pxs,n.pxe,n.pys,n.pye],t):(t.done=!0,t.value=void 0,t)}}function D(e,n,t,s,i){const l=(Math.min(n,s)+1)*2,o=n+s,h=new(o<256?Uint8Array:o<65536?Uint16Array:Uint32Array)(2*l);return new m({i:e,N:n,j:t,M:s,Z:l,b:h,eq:i,pxs:-1,pxe:-1,pys:-1,pye:-1,oxs:-1,oxe:-1,oys:-1,oye:-1,stack_top:0,stack_base:[]})}v.diff_core=D;function d(e,n,t){let[s,i,l]=[0,e.length,n.length];if(typeof t=="function"){for(;s<i&&s<l&&t(s,s);)s++;if(s===i&&s===l)return[][Symbol.iterator]();for(;t(--i,--l)&&i>s&&l>s;);}else{for(;s<i&&s<l&&e[s]===n[s];)s++;if(s===i&&s===l)return[][Symbol.iterator]();for(;e[--i]===n[--l]&&i>s&&l>s;);t=(o,h)=>e[o]===n[h]}return D(s,i+1-s,s,l+1-s,t)}v.diff=d;class p{constructor(n,t){this.diff=n,this.N=t,this.i=0,this.j=0}[Symbol.iterator](){return this}next(){const n=this.diff.next();if(n.done){const{i:a,j:u,N:x}=this;return a<x&&(n.done=!1,n.value=[a,u,x-a],this.i=x),n}const t=n.value,s=t[0],i=t[1],l=t[3],{i:o,j:h}=this;return o!==s&&(t.length--,t[0]=o,t[1]=h,t[2]=s-o),this.i=i,this.j=l,n}}function y(e,n,t){return new p(d(e,n,t),e.length)}v.lcs=y;function*g(e,n,t){const s=ArrayBuffer.isView(e)?Uint8Array.prototype.subarray:e.slice;for(const i of d(e,n,t))i[2]=s.call(n,i[2],i[3]),yield i}v.calcPatch=g;function*N(e,n){let t=0;const s=ArrayBuffer.isView(e)?Uint8Array.prototype.subarray:e.slice;for(const[i,l,o]of n)t<i&&(yield s.call(e,t,i)),o.length>0&&(yield o),t=l;t<e.length&&(yield s.call(e,t))}v.applyPatch=N;function*j(e,n,t){let s=0;const i=ArrayBuffer.isView(e)?Uint8Array.prototype.subarray:e.slice;for(const[l,o,h,a]of d(e,n,t))s<l&&(yield[0,i.call(e,s,l)]),l<o&&(yield[-1,i.call(e,l,o)]),h<a&&(yield[1,i.call(n,h,a)]),s=o;s<e.length&&(yield[0,e.slice(s)])}return v.calcSlices=j,v}var xe=ye();const me=({children:c})=>r.jsx("span",{className:"bg-green-100",children:c}),je=({children:c})=>r.jsx("span",{className:"bg-red-100 line-through",children:c}),T=({children:c})=>r.jsx("span",{children:c}),ge=({content:c,contentOrigin:m,monthDate:D})=>{const d=P.useMemo(()=>{const p=[];if(!m)return p;const y=c.split(""),g=m.split(""),N=Array.from(xe.calcPatch(g,y)),j=[];let e=0;for(const[t,s,i]of N)if(j.length===0&&t>=17&&s<=25&&i.length===s-t){if(N.length===1)return p;continue}else e<t&&j.push([g.slice(e,t).join(""),T]),s>t&&j.push([g.slice(t,s).join(""),je]),i.length>0&&j.push([i.join(""),me]),e=s;e<g.length&&j.push([g.slice(e).join(""),T]);let n=[];for(const[t,s]of j){const i=t.split(`
2
- `);i.length===1?n.push(r.jsx(s,{children:t},`unchanged-${n.length}`)):i.map((l,o)=>{n.push(r.jsx(s,{children:l},o)),p.push(r.jsx("div",{children:n},p.length-1)),n=[]})}return n.length>0&&p.push(r.jsx("div",{children:n},p.length-1)),p},[c,m]);return r.jsxs("div",{className:"flex flex-col",children:[r.jsxs("div",{className:"text-sm text-gray-500 flex flex-row gap-2",children:[r.jsx("span",{className:"font-bold",children:"Month:"}),r.jsx("span",{children:D.slice(0,7)}),!d.length&&r.jsx(H,{className:"text-green-500"})]}),!!d.length&&d]})},Me=({filter:c})=>{const[{data:m,fetching:D,hasNext:d}]=J({query:W,variables:c}),p=P.useMemo(()=>m?.pcnByDate?m.pcnByDate.sort((y,g)=>g.date>y.date?1:g.date<y.date?-1:0):[],[m?.pcnByDate]);return D?r.jsx("div",{className:"w-full h-full flex justify-center",children:r.jsx(E,{className:"h-10 w-10 animate-spin mr-2 self-center"})}):r.jsxs("div",{className:"flex flex-col gap-4",children:[!!m&&d&&r.jsx("div",{className:"w-full h-full flex justify-center",children:r.jsx(E,{className:"h-10 w-10 animate-spin mr-2 self-center"})}),p.map((y,g)=>r.jsx(ge,{content:y.content,contentOrigin:y.diffContent,monthDate:y.date},g))]})};function be({filter:c,setFilter:m,closeModal:D}){const{control:d,handleSubmit:p,setValue:y}=te({defaultValues:{...c}}),{selectableBusinesses:g,fetching:N}=ne(),j=e=>{m(e),D()};return r.jsxs(r.Fragment,{children:[N?r.jsx("div",{children:"Loading..."}):r.jsx("div",{}),r.jsxs("form",{onSubmit:p(j),children:[r.jsx(se,{name:"businessId",control:d,defaultValue:void 0,render:({field:e,fieldState:n})=>r.jsx(oe,{...e,data:g,value:e.value,disabled:N,label:"Businesses",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:n.error?.message})}),r.jsx(O,{label:"From date",defaultValue:c?.fromMonthDate?new Date(c.fromMonthDate):new Date,defaultDate:c?.fromMonthDate?new Date(c.fromMonthDate):new Date,onChange:e=>{const n=new Date(e.getFullYear(),e.getMonth(),15);y("fromMonthDate",S(n,"yyyy-MM-dd"))},popoverProps:{withinPortal:!0}}),r.jsx(O,{label:"To date",defaultValue:c?.toMonthDate?new Date(c.toMonthDate):new Date,defaultDate:c?.toMonthDate?new Date(c.toMonthDate):new Date,onChange:e=>{const n=new Date(e.getFullYear(),e.getMonth(),15);y("toMonthDate",S(n,"yyyy-MM-dd"))},popoverProps:{withinPortal:!0}}),r.jsxs("div",{className:"flex justify-center mt-5 gap-3",children:[r.jsx(U,{type:"submit",children:"Filter"}),r.jsx(U,{type:"button",onClick:D,children:"Cancel"})]})]})]})}function ve({filter:c,setFilter:m}){const[D,d]=P.useState(!1),{get:p,set:y}=Y(),{userContext:g}=P.useContext(q);function N(j){j||={businessId:g?.context.adminBusinessId??c.businessId,fromMonthDate:S(G(new Date),"yyyy-MM-15"),toMonthDate:S(new Date,"yyyy-MM-15")},re(j,c)||m(j)}return P.useEffect(()=>{const j=K(c??{})?null:encodeURIComponent(JSON.stringify(c)),e=p("validateReportsFilters");j!==e&&y("validateReportsFilters",j)},[c,p,y]),r.jsxs(r.Fragment,{children:[r.jsx(X,{opened:D,onClose:()=>d(!1),content:r.jsx(be,{filter:c,setFilter:N,closeModal:()=>d(!1)})}),r.jsx(U,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>d(!0),children:r.jsx(ee,{className:"size-5"})})]})}const Ce=()=>{const{get:c}=Y(),{setFiltersContext:m}=P.useContext(ie),D=P.useMemo(()=>{try{if(c("validateReportsFilters"))return JSON.parse(decodeURIComponent(c("validateReportsFilters")))}catch(y){console.error("Error parsing filter from URL",y)}return{fromMonthDate:S(G(new Date),"yyyy-MM-15"),toMonthDate:S(new Date,"yyyy-MM-15")}},[c]),[d,p]=P.useState(D);return P.useEffect(()=>{m(r.jsx("div",{className:"flex flex-row gap-2",children:r.jsx(ve,{filter:{...d},setFilter:p})}))},[d,m]),r.jsx(le,{title:"Report Validations",children:r.jsx(fe,{type:"single",collapsible:!0,children:r.jsx(he,{value:"pcn874",children:r.jsxs(ae,{className:"p-4",children:[r.jsx(de,{children:r.jsx(ce,{children:"Monthly VAT (PCN874)"})}),r.jsx(pe,{children:r.jsx(ue,{children:r.jsx(Me,{filter:d})})})]})})})})};export{Ce as ValidateReportsScreen};
1
+ import{r as P,j as r,g as Q,a as W,fc as $,L as E,u as Y,ae as q,cZ as K,c_ as X,B as U,c$ as ee,V as te,cd as ne,bO as se,bP as oe,db as O,H as S,fd as Z,d0 as re,F as ie,c as le,Y as ae,_ as ce,a1 as ue}from"./index-xIO0bA36.js";import{A as fe,a as he,c as de,b as pe}from"./accordion-DLhPc0rw.js";var v={},z;function ye(){if(z)return v;z=1,Object.defineProperty(v,"__esModule",{value:!0}),v.calcSlices=v.applyPatch=v.calcPatch=v.lcs=v.diff=v.diff_core=void 0;function c(e,n){const{b:t,eq:s,stack_base:i}=e;let{i:l,N:o,j:h,M:a,Z:u,stack_top:x}=e;for(;;)switch(n){case 0:{e:for(;o>0&&a>0;){t.fill(0,0,2*u);const R=o-a,_=o+a,B=_&1,G=l+o-1,H=h+a-1,J=(_+B)/2;let F;t:for(let M=0;M<=J;M++){const I=2*Math.max(0,M-a)-M,L=M-2*Math.max(0,M-o);for(let f=I;f<=L;f+=2){const A=t[f-1-u*Math.floor((f-1)/u)],V=t[f+1-u*Math.floor((f+1)/u)],w=f===-M||f!==M&&A<V?V:A+1,k=w-f;let b=w,C=k;for(;b<o&&C<a&&s(l+b,h+C);)b++,C++;if(t[f-u*Math.floor(f/u)]=b,B===1&&(F=R-f)>=1-M&&F<M&&b+t[u+F-u*Math.floor(F/u)]>=o)if(M>1||b!==w){i[x++]=l+b,i[x++]=o-b,i[x++]=h+C,i[x++]=a-C,o=w,a=k,u=2*(Math.min(o,a)+1);continue e}else break t}for(let f=I;f<=L;f+=2){const A=t[u+f-1-u*Math.floor((f-1)/u)],V=t[u+f+1-u*Math.floor((f+1)/u)],w=f===-M||f!==M&&A<V?V:A+1,k=w-f;let b=w,C=k;for(;b<o&&C<a&&s(G-b,H-C);)b++,C++;if(t[u+f-u*Math.floor(f/u)]=b,B===0&&(F=R-f)>=-M&&F<=M&&b+t[F-u*Math.floor(F/u)]>=o)if(M>0||b!==w){i[x++]=l+o-w,i[x++]=w,i[x++]=h+a-k,i[x++]=k,o=o-b,a=a-C,u=2*(Math.min(o,a)+1);continue e}else break t}}if(o!==a){a>o?(l+=o,h+=o,a-=o,o=0):(l+=a,h+=a,o-=a,a=0);break}}if(o+a!==0)if(e.pxe===l||e.pye===h)e.pxe=l+o,e.pye=h+a;else{const R=e.pxs;if(e.oxs=e.pxs,e.oxe=e.pxe,e.oys=e.pys,e.oye=e.pye,e.pxs=l,e.pxe=l+o,e.pys=h,e.pye=h+a,R>=0)return e.i=l,e.N=o,e.j=h,e.M=a,e.Z=u,e.stack_top=x,1}}case 1:{if(x===0)return 2;a=i[--x],h=i[--x],o=i[--x],l=i[--x],u=2*(Math.min(o,a)+1),n=0}}}class m{constructor(n){this.state=n,this.c=0,this.result={value:null,done:!1}}[Symbol.iterator](){return this}next(){const{state:n,result:t}=this;if(this.c>1)return t.done=!0,t.value=void 0,t;const s=c(n,this.c);return this.c=s,s===1?(t.value=[n.oxs,n.oxe,n.oys,n.oye],t):n.pxs>=0?(t.value=[n.pxs,n.pxe,n.pys,n.pye],t):(t.done=!0,t.value=void 0,t)}}function D(e,n,t,s,i){const l=(Math.min(n,s)+1)*2,o=n+s,h=new(o<256?Uint8Array:o<65536?Uint16Array:Uint32Array)(2*l);return new m({i:e,N:n,j:t,M:s,Z:l,b:h,eq:i,pxs:-1,pxe:-1,pys:-1,pye:-1,oxs:-1,oxe:-1,oys:-1,oye:-1,stack_top:0,stack_base:[]})}v.diff_core=D;function d(e,n,t){let[s,i,l]=[0,e.length,n.length];if(typeof t=="function"){for(;s<i&&s<l&&t(s,s);)s++;if(s===i&&s===l)return[][Symbol.iterator]();for(;t(--i,--l)&&i>s&&l>s;);}else{for(;s<i&&s<l&&e[s]===n[s];)s++;if(s===i&&s===l)return[][Symbol.iterator]();for(;e[--i]===n[--l]&&i>s&&l>s;);t=(o,h)=>e[o]===n[h]}return D(s,i+1-s,s,l+1-s,t)}v.diff=d;class p{constructor(n,t){this.diff=n,this.N=t,this.i=0,this.j=0}[Symbol.iterator](){return this}next(){const n=this.diff.next();if(n.done){const{i:a,j:u,N:x}=this;return a<x&&(n.done=!1,n.value=[a,u,x-a],this.i=x),n}const t=n.value,s=t[0],i=t[1],l=t[3],{i:o,j:h}=this;return o!==s&&(t.length--,t[0]=o,t[1]=h,t[2]=s-o),this.i=i,this.j=l,n}}function y(e,n,t){return new p(d(e,n,t),e.length)}v.lcs=y;function*g(e,n,t){const s=ArrayBuffer.isView(e)?Uint8Array.prototype.subarray:e.slice;for(const i of d(e,n,t))i[2]=s.call(n,i[2],i[3]),yield i}v.calcPatch=g;function*N(e,n){let t=0;const s=ArrayBuffer.isView(e)?Uint8Array.prototype.subarray:e.slice;for(const[i,l,o]of n)t<i&&(yield s.call(e,t,i)),o.length>0&&(yield o),t=l;t<e.length&&(yield s.call(e,t))}v.applyPatch=N;function*j(e,n,t){let s=0;const i=ArrayBuffer.isView(e)?Uint8Array.prototype.subarray:e.slice;for(const[l,o,h,a]of d(e,n,t))s<l&&(yield[0,i.call(e,s,l)]),l<o&&(yield[-1,i.call(e,l,o)]),h<a&&(yield[1,i.call(n,h,a)]),s=o;s<e.length&&(yield[0,e.slice(s)])}return v.calcSlices=j,v}var xe=ye();const me=({children:c})=>r.jsx("span",{className:"bg-green-100",children:c}),je=({children:c})=>r.jsx("span",{className:"bg-red-100 line-through",children:c}),T=({children:c})=>r.jsx("span",{children:c}),ge=({content:c,contentOrigin:m,monthDate:D})=>{const d=P.useMemo(()=>{const p=[];if(!m)return p;const y=c.split(""),g=m.split(""),N=Array.from(xe.calcPatch(g,y)),j=[];let e=0;for(const[t,s,i]of N)if(j.length===0&&t>=17&&s<=25&&i.length===s-t){if(N.length===1)return p;continue}else e<t&&j.push([g.slice(e,t).join(""),T]),s>t&&j.push([g.slice(t,s).join(""),je]),i.length>0&&j.push([i.join(""),me]),e=s;e<g.length&&j.push([g.slice(e).join(""),T]);let n=[];for(const[t,s]of j){const i=t.split(`
2
+ `);i.length===1?n.push(r.jsx(s,{children:t},`unchanged-${n.length}`)):i.map((l,o)=>{n.push(r.jsx(s,{children:l},o)),p.push(r.jsx("div",{children:n},p.length-1)),n=[]})}return n.length>0&&p.push(r.jsx("div",{children:n},p.length-1)),p},[c,m]);return r.jsxs("div",{className:"flex flex-col",children:[r.jsxs("div",{className:"text-sm text-gray-500 flex flex-row gap-2",children:[r.jsx("span",{className:"font-bold",children:"Month:"}),r.jsx("span",{children:D.slice(0,7)}),!d.length&&r.jsx(Q,{className:"text-green-500"})]}),!!d.length&&d]})},Me=({filter:c})=>{const[{data:m,fetching:D,hasNext:d}]=W({query:$,variables:c}),p=P.useMemo(()=>m?.pcnByDate?m.pcnByDate.sort((y,g)=>g.date>y.date?1:g.date<y.date?-1:0):[],[m?.pcnByDate]);return D?r.jsx("div",{className:"w-full h-full flex justify-center",children:r.jsx(E,{className:"h-10 w-10 animate-spin mr-2 self-center"})}):r.jsxs("div",{className:"flex flex-col gap-4",children:[!!m&&d&&r.jsx("div",{className:"w-full h-full flex justify-center",children:r.jsx(E,{className:"h-10 w-10 animate-spin mr-2 self-center"})}),p.map((y,g)=>r.jsx(ge,{content:y.content,contentOrigin:y.diffContent,monthDate:y.date},g))]})};function be({filter:c,setFilter:m,closeModal:D}){const{control:d,handleSubmit:p,setValue:y}=te({defaultValues:{...c}}),{selectableBusinesses:g,fetching:N}=ne(),j=e=>{m(e),D()};return r.jsxs(r.Fragment,{children:[N?r.jsx("div",{children:"Loading..."}):r.jsx("div",{}),r.jsxs("form",{onSubmit:p(j),children:[r.jsx(se,{name:"businessId",control:d,defaultValue:void 0,render:({field:e,fieldState:n})=>r.jsx(oe,{...e,data:g,value:e.value,disabled:N,label:"Businesses",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:n.error?.message})}),r.jsx(O,{label:"From date",defaultValue:c?.fromMonthDate?new Date(c.fromMonthDate):new Date,defaultDate:c?.fromMonthDate?new Date(c.fromMonthDate):new Date,onChange:e=>{const n=new Date(e.getFullYear(),e.getMonth(),15);y("fromMonthDate",S(n,"yyyy-MM-dd"))},popoverProps:{withinPortal:!0}}),r.jsx(O,{label:"To date",defaultValue:c?.toMonthDate?new Date(c.toMonthDate):new Date,defaultDate:c?.toMonthDate?new Date(c.toMonthDate):new Date,onChange:e=>{const n=new Date(e.getFullYear(),e.getMonth(),15);y("toMonthDate",S(n,"yyyy-MM-dd"))},popoverProps:{withinPortal:!0}}),r.jsxs("div",{className:"flex justify-center mt-5 gap-3",children:[r.jsx(U,{type:"submit",children:"Filter"}),r.jsx(U,{type:"button",onClick:D,children:"Cancel"})]})]})]})}function ve({filter:c,setFilter:m}){const[D,d]=P.useState(!1),{get:p,set:y}=Y(),{userContext:g}=P.useContext(q);function N(j){j||={businessId:g?.context.adminBusinessId??c.businessId,fromMonthDate:S(Z(new Date),"yyyy-MM-15"),toMonthDate:S(new Date,"yyyy-MM-15")},re(j,c)||m(j)}return P.useEffect(()=>{const j=K(c??{})?null:encodeURIComponent(JSON.stringify(c)),e=p("validateReportsFilters");j!==e&&y("validateReportsFilters",j)},[c,p,y]),r.jsxs(r.Fragment,{children:[r.jsx(X,{opened:D,onClose:()=>d(!1),content:r.jsx(be,{filter:c,setFilter:N,closeModal:()=>d(!1)})}),r.jsx(U,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>d(!0),children:r.jsx(ee,{className:"size-5"})})]})}const Ce=()=>{const{get:c}=Y(),{setFiltersContext:m}=P.useContext(ie),D=P.useMemo(()=>{try{if(c("validateReportsFilters"))return JSON.parse(decodeURIComponent(c("validateReportsFilters")))}catch(y){console.error("Error parsing filter from URL",y)}return{fromMonthDate:S(Z(new Date),"yyyy-MM-15"),toMonthDate:S(new Date,"yyyy-MM-15")}},[c]),[d,p]=P.useState(D);return P.useEffect(()=>{m(r.jsx("div",{className:"flex flex-row gap-2",children:r.jsx(ve,{filter:{...d},setFilter:p})}))},[d,m]),r.jsx(le,{title:"Report Validations",children:r.jsx(fe,{type:"single",collapsible:!0,children:r.jsx(he,{value:"pcn874",children:r.jsxs(ae,{className:"p-4",children:[r.jsx(de,{children:r.jsx(ce,{children:"Monthly VAT (PCN874)"})}),r.jsx(pe,{children:r.jsx(ue,{children:r.jsx(Me,{filter:d})})})]})})})})};export{Ce as ValidateReportsScreen};
@@ -1,4 +1,4 @@
1
- import{c_ as f,r as h,u as B,j as e,c$ as N,bA as $,B as w,d0 as R,V as k,ce as O,ag as A,a1 as E,bP as v,ci as D,bU as C,bV as F,H as T,a3 as z,a4 as P,a5 as V,a6 as L,ap as M,d1 as U,dS as _,c0 as S,T as I,P as q,b as G,bh as H,b6 as j,aV as p,X as Z,dT as J,cb as Q,cT as y,F as W,a as X,dU as K,dV as Y,c as ee,L as te,dW as se}from"./index-C1vFqfE7.js";function ae(t){return!t||f(t)?null:encodeURIComponent(JSON.stringify(t))}function re({filter:t,setFilter:s,closeModal:o}){const n=k({defaultValues:{...t}}),{control:r,handleSubmit:l}=n,{selectableBusinesses:a,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:r,defaultValue:void 0,render:({field:i,fieldState:b})=>e.jsx(D,{...i,data:a,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:r,defaultValue:void 0,render:({field:i,fieldState:b})=>e.jsx(D,{...i,data:a,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:r,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:r,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:r,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(V,{children:"Show zeroed accounts"})}),e.jsxs("div",{className:"flex flex-row items-center gap-1",children:[e.jsx(L,{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),[r,l]=h.useState(!f(t)),{get:a,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=a("trialBalanceReportFilters");d!==i&&u("trialBalanceReportFilters",d)},[t,a,u]),e.jsxs(e.Fragment,{children:[e.jsx(N,{opened:o,onClose:()=>n(!1),content:e.jsx(re,{filter:t,setFilter:c,closeModal:()=>n(!1)})}),e.jsx($,{inline:!0,size:16,disabled:!r,children:e.jsx(w,{variant:"outline",onClick:()=>n(!0),className:"p-2",children:e.jsx(R,{size:20})})})]})}const oe=({data:t,fromDate:s,toDate:o})=>{const n=h.useCallback(async()=>{const r=le(t),l=`trial_balance_report${s?`_${s}`:""}${o?`_${o}`:""}`;return{fileContent:r,fileName:l}},[t,s,o]);return e.jsx(_,{createFileVariables:n})},le=t=>{let s="";s+=`Sort Code,Account Name,Debit,Credit,Balance\r
1
+ import{cZ as f,r as h,u as B,j as e,c_ as $,bz as N,B as S,c$ as R,V as k,cd as O,ae as z,a0 as A,bO as v,ch as D,bT as C,bU as F,H as T,a2 as E,a3 as P,a4 as L,a5 as V,aI as M,d0 as U,dR as _,b$ as w,T as I,P as q,b as G,bg as Z,b6 as j,b1 as p,X as H,dS as J,ca as Q,cS as y,F as X,a as K,dT as W,dU as Y,c as ee,L as te,dV as se}from"./index-xIO0bA36.js";function ae(t){return!t||f(t)?null:encodeURIComponent(JSON.stringify(t))}function re({filter:t,setFilter:s,closeModal:o}){const n=k({defaultValues:{...t}}),{control:r,handleSubmit:l}=n,{selectableBusinesses:a,fetching:u}=O(),{userContext:m}=h.useContext(z),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(A,{...n,children:e.jsxs("form",{onSubmit:l(c),className:"space-y-2",children:[e.jsx(v,{name:"ownerIds",control:r,defaultValue:void 0,render:({field:i,fieldState:b})=>e.jsx(D,{...i,data:a,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:r,defaultValue:void 0,render:({field:i,fieldState:b})=>e.jsx(D,{...i,data:a,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:r,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:r,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(E,{name:"isShowZeroedAccounts",control:r,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),[r,l]=h.useState(!f(t)),{get:a,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=a("trialBalanceReportFilters");d!==i&&u("trialBalanceReportFilters",d)},[t,a,u]),e.jsxs(e.Fragment,{children:[e.jsx($,{opened:o,onClose:()=>n(!1),content:e.jsx(re,{filter:t,setFilter:c,closeModal:()=>n(!1)})}),e.jsx(N,{inline:!0,size:16,disabled:!r,children:e.jsx(S,{variant:"outline",onClick:()=>n(!0),className:"p-2",children:e.jsx(R,{size:20})})})]})}const oe=({data:t,fromDate:s,toDate:o})=>{const n=h.useCallback(async()=>{const r=le(t),l=`trial_balance_report${s?`_${s}`:""}${o?`_${o}`:""}`;return{fileContent:r,fileName:l}},[t,s,o]);return e.jsx(_,{createFileVariables:n})},le=t=>{let s="";s+=`Sort Code,Account Name,Debit,Credit,Balance\r
2
2
  `;for(const[o,n]of Object.entries(t)){const r=ie(o,n);s+=r}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
3
  `,s};function ie(t,s){let o="";return Object.values(s.sortCodes).sort((n,r)=>n.key-r.key).map(n=>{const r=ce(n);o+=r}),o+=`${t.replaceAll("0","*")},Group Total:,${s.totalDebit??""},${s.totalCredit??""},${s.sum}\r
4
4
  `,o}function ce(t){let s="";s+=`${t.name}\r
@@ -6,4 +6,4 @@ import{c_ as f,r as h,u as B,j as e,c$ as N,bA as $,B as w,d0 as R,V as k,ce as
6
6
  `;s+=c});const o=`${t.key},Group total:,${t.totalDebit??""},${t.totalCredit??""},${t.sum}\r
7
7
  `;s+=o;const n=t.debit?`,,,Total Debit Balances:,${t.debit}\r
8
8
  `:"";s+=n;const r=t.credit?`,,,Total Credit Balances:,${t.credit}\r
9
- `:"";return s+=r,s}function de(t){let s="";return s=t.replace(/"/g,'""'),s}const ue=({record:t,sortCodeKey:s,filter:o,isAllOpened:n})=>{const[r,l]=h.useState(n),a=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:(a>.001||a<-.001)&&e.jsx(S,{color:a>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:r||n?e.jsx(q,{className:"size-5"}):e.jsx(G,{className:"size-5"})})})})]},t.business.id),(r||n)&&e.jsx("tr",{children:e.jsx("td",{colSpan:7,children:e.jsx(H,{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,r)=>n.business.name.localeCompare(r.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((r,l)=>r.key-l.key).map((r,l)=>e.jsx(me,{sortCode:r,filter:o,isAllOpened:n},`${r.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}=Z(J,t),r=h.useMemo(()=>{const l={};for(const a of n){a.business.sortCode??={id:"-999",key:-999,name:"Misc"};const u=!a.total.raw||a.total.raw<.001&&a.total.raw>-.001;if(!s.isShowZeroedAccounts&&u)continue;const m=he(a.business.sortCode.key);l[m]??={sortCodes:{},totalCredit:0,totalDebit:0,credit:0,debit:0,sum:0};const c=l[m];c.sortCodes[a.business.sortCode.key]??={...a.business.sortCode,totalCredit:0,totalDebit:0,records:[],credit:0,debit:0,sum:0};const d=c.sortCodes[a.business.sortCode.key];d.totalCredit+=a.credit.raw,d.totalDebit+=a.debit.raw,d.sum+=a.total.raw,c.totalCredit+=a.credit.raw,c.totalDebit+=a.debit.raw,c.sum+=a.total.raw,a.total.raw>0?(d.credit+=a.total.raw,c.credit+=a.total.raw):(d.debit+=a.total.raw,c.debit+=a.total.raw),d.records.push(a)}return l},[n,s.isShowZeroedAccounts]);return e.jsxs(Q,{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:r,fromDate:s.fromDate??void 0,toDate:s.toDate??void 0})})]})}),e.jsxs("tbody",{children:[Object.entries(r).map(([l,a])=>e.jsx(xe,{data:a,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(r).reduce((l,a)=>l+a.totalDebit,0)),")"]}),e.jsxs("td",{children:["(",y(Object.values(r).reduce((l,a)=>l+a.totalCredit,0)),")"]}),e.jsx("td",{colSpan:1,children:y(Object.values(r).reduce((l,a)=>l+a.sum,0))})]})]})]})};function pe(t){const s=new URLSearchParams,o=ae(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(W),[r,l]=h.useState(o("trialBalanceReportFilters")?JSON.parse(decodeURIComponent(o("trialBalanceReportFilters"))):{}),[{data:a,fetching:u}]=X({query:se,variables:{filters:{fromDate:r?.fromDate,toDate:r?.toDate,ownerIds:r?.ownerIds,businessIDs:r?.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(K,{className:"size-5"}):e.jsx(Y,{className:"size-5"})})}),e.jsx(ne,{filter:r,setFilter:l})]}))},[r,t,n]);const m=h.useMemo(()=>a?.businessTransactionsSumFromLedgerRecords.__typename==="CommonError"?void 0:a?.businessTransactionsSumFromLedgerRecords,[a?.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:r,isAllOpened:t})})};export{ge as TrialBalanceReport,pe as getTrialBalanceReportHref};
9
+ `:"";return s+=r,s}function de(t){let s="";return s=t.replace(/"/g,'""'),s}const ue=({record:t,sortCodeKey:s,filter:o,isAllOpened:n})=>{const[r,l]=h.useState(n),a=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:(a>.001||a<-.001)&&e.jsx(w,{color:a>0?"green":"red",children:t?.total?.formatted})}),e.jsx("td",{children:e.jsx(I,{label:"Detailed records",children:e.jsx(S,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>l(c=>!c),children:r||n?e.jsx(q,{className:"size-5"}):e.jsx(G,{className:"size-5"})})})})]},t.business.id),(r||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,r)=>n.business.name.localeCompare(r.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(w,{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((r,l)=>r.key-l.key).map((r,l)=>e.jsx(me,{sortCode:r,filter:o,isAllOpened:n},`${r.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(w,{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),r=h.useMemo(()=>{const l={};for(const a of n){a.business.sortCode??={id:"-999",key:-999,name:"Misc"};const u=!a.total.raw||a.total.raw<.001&&a.total.raw>-.001;if(!s.isShowZeroedAccounts&&u)continue;const m=he(a.business.sortCode.key);l[m]??={sortCodes:{},totalCredit:0,totalDebit:0,credit:0,debit:0,sum:0};const c=l[m];c.sortCodes[a.business.sortCode.key]??={...a.business.sortCode,totalCredit:0,totalDebit:0,records:[],credit:0,debit:0,sum:0};const d=c.sortCodes[a.business.sortCode.key];d.totalCredit+=a.credit.raw,d.totalDebit+=a.debit.raw,d.sum+=a.total.raw,c.totalCredit+=a.credit.raw,c.totalDebit+=a.debit.raw,c.sum+=a.total.raw,a.total.raw>0?(d.credit+=a.total.raw,c.credit+=a.total.raw):(d.debit+=a.total.raw,c.debit+=a.total.raw),d.records.push(a)}return l},[n,s.isShowZeroedAccounts]);return e.jsxs(Q,{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:r,fromDate:s.fromDate??void 0,toDate:s.toDate??void 0})})]})}),e.jsxs("tbody",{children:[Object.entries(r).map(([l,a])=>e.jsx(xe,{data:a,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(r).reduce((l,a)=>l+a.totalDebit,0)),")"]}),e.jsxs("td",{children:["(",y(Object.values(r).reduce((l,a)=>l+a.totalCredit,0)),")"]}),e.jsx("td",{colSpan:1,children:y(Object.values(r).reduce((l,a)=>l+a.sum,0))})]})]})]})};function pe(t){const s=new URLSearchParams,o=ae(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),[r,l]=h.useState(o("trialBalanceReportFilters")?JSON.parse(decodeURIComponent(o("trialBalanceReportFilters"))):{}),[{data:a,fetching:u}]=K({query:se,variables:{filters:{fromDate:r?.fromDate,toDate:r?.toDate,ownerIds:r?.ownerIds,businessIDs:r?.businessIDs}}});h.useEffect(()=>{n(e.jsxs("div",{className:"flex flex-row gap-2",children:[e.jsx(I,{label:"Expand all accounts",children:e.jsx(S,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>s(c=>!c),children:t?e.jsx(W,{className:"size-5"}):e.jsx(Y,{className:"size-5"})})}),e.jsx(ne,{filter:r,setFilter:l})]}))},[r,t,n]);const m=h.useMemo(()=>a?.businessTransactionsSumFromLedgerRecords.__typename==="CommonError"?void 0:a?.businessTransactionsSumFromLedgerRecords,[a?.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:r,isAllOpened:t})})};export{ge as TrialBalanceReport,pe as getTrialBalanceReportHref};
@@ -1,6 +1,6 @@
1
- import{D as q,r as d,j as e,X as p,B as g,P as w,b as y,C as F,el as G,em as H,en as _,eo as Q,cT as D,cn as M,ep as E,eq as T,er as R,es as $,et as J,cb as V,eu as X,ev as Y,ew as K,ex as W,a as z,t as Z,ey as ee,T as te,ez as se,u as O,ag as k,c_ as ae,c$ as ne,d0 as re,V as oe,di as ie,bP as A,bQ as S,eA as N,dc as ce,H as I,d1 as le,F as de,c as he,L as xe,E as ue,I as me,M as pe,eB as ge}from"./index-C1vFqfE7.js";import{d as B}from"./graphql-document-dedupe-fragments-ByT8-wlV.js";import{M as je}from"./index-rzb-Wfyn.js";import{c as fe}from"./charges-filters-BZS9K5l_.js";import"./Checkbox-BO9Xpz8t.js";import"./sub-DVpRQI4L.js";import"./subMonths-CFZKY9ia.js";/**
1
+ import{D as q,r as d,j as e,X as p,B as g,P as w,b as y,C as F,ek as G,el as H,em as _,en as Q,cS as D,cm as M,eo as E,ep as R,eq as T,er as $,es as J,ca as V,et as X,eu as Y,ev as Z,ew as K,a as z,t as W,ex as ee,T as te,ey as se,u as O,ae as k,cZ as ae,c_ as ne,c$ as re,V as oe,dh as ie,bO as A,bP as S,ez as N,db as ce,H as I,d0 as le,F as de,c as he,L as xe,E as ue,I as me,M as pe,eA as ge}from"./index-xIO0bA36.js";import{d as B}from"./graphql-document-dedupe-fragments-ByT8-wlV.js";import{M as je}from"./index-C1QP_1hi.js";import{c as fe}from"./charges-filters-hjHQC8jb.js";import"./Checkbox-BPO8_jMH.js";import"./sub-CqZ9jxmt.js";import"./subMonths-CwZPyK0k.js";/**
2
2
  * @license lucide-react v0.546.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
5
5
  * See the LICENSE file in the root directory of this source tree.
6
- */const ve=[["path",{d:"M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v4",key:"1pf5j1"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["rect",{width:"4",height:"6",x:"2",y:"12",rx:"2",key:"jm304g"}],["path",{d:"M10 12h2v6",key:"12zw74"}],["path",{d:"M10 18h4",key:"1ulq68"}]],we=q("file-digit",ve),ye=({data:a,setEditCharge:c,setInsertDocument:l,setMatchDocuments:r,toggleMergeCharge:o,mergeSelectedCharges:n})=>{const s=p(G,a),[t,i]=d.useState(!0);return e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"text-lg font-semibold whitespace-nowrap flex flex-row gap-4",children:[e.jsx(g,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>i(h=>!h),children:t?e.jsx(w,{className:"size-5"}):e.jsx(y,{className:"size-5"})}),"Business Trips"]}),t&&s&&e.jsx(F,{setEditChargeId:c,setInsertDocument:l,setMatchDocuments:r,data:s.businessTrips,isAllOpened:!1,toggleMergeCharge:o,mergeSelectedCharges:n})]})};function P({data:a}){const{chargeId:c,chargeAccountantStatus:l}=p(H,a),{updateChargeAccountantApproval:r}=_();return e.jsx("td",{children:e.jsx(Q,{value:l??void 0,onChange:o=>r({chargeId:c,status:o})})})}const be=({data:a,toggleMergeCharge:c,mergeSelectedCharges:l,cumulativeVat:r,cumulativeAmount:o})=>{const[n,s]=d.useState(!1),t=p($,a);return e.jsxs(e.Fragment,{children:[e.jsxs("tr",{className:"bg-gray-100",children:[e.jsxs("td",{className:"flex flex-col gap-1",children:[t.business?.name,t.vatNumber&&e.jsx("span",{style:{fontSize:"10px",color:"darkGray"},children:t.vatNumber})]}),e.jsx("td",{children:t.image&&e.jsx("a",{href:t.image,target:"_blank",rel:"noreferrer",children:e.jsx("img",{alt:"missing img",src:t.image,height:80,width:80})})}),e.jsx("td",{children:t.documentSerial}),e.jsx("td",{children:t.documentDate}),e.jsx("td",{children:t.chargeDate}),e.jsx("td",{className:"whitespace-nowrap",children:t.amount.formatted}),e.jsx("td",{className:"whitespace-nowrap",children:t.localAmount?.formatted}),e.jsx("td",{className:"whitespace-nowrap",children:t.localVat?.formatted}),e.jsx("td",{className:"whitespace-nowrap",children:t.localVatAfterDeduction?.formatted}),e.jsx("td",{className:"whitespace-nowrap",children:t.foreignVatAfterDeduction?.formatted}),e.jsx("td",{className:"whitespace-nowrap",children:t.roundedLocalVatAfterDeduction?.formatted}),e.jsxs("td",{className:"whitespace-nowrap",children:["₪ ",D(r,0)]}),e.jsxs("td",{className:"whitespace-nowrap",children:["₪ ",D(o,0)]}),e.jsx(P,{data:t}),e.jsx("td",{children:e.jsx("div",{className:"flex flex-col gap-2",children:e.jsx(M,{toggleExpansion:s,isExpanded:n})})}),e.jsx("td",{children:e.jsx(E,{toggleMergeSelected:()=>c(t.chargeId),mergeSelected:l.includes(t.chargeId)})})]}),n&&e.jsx("tr",{children:e.jsx("td",{colSpan:17,children:e.jsx(T,{style:{width:"100%"},withBorder:!0,shadow:"lg",children:e.jsx(R,{chargeID:t.chargeId,fetching:!!t})})})})]})},Ce=({data:a,toggleMergeCharge:c,mergeSelectedCharges:l})=>{const{expenses:r}=p(J,a)??{expenses:[]},[o,n]=d.useState(!0);let s=0,t=0;return e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"text-lg font-semibold whitespace-nowrap flex flex-row gap-4",children:[e.jsx(g,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>n(i=>!i),children:o?e.jsx(w,{className:"size-5"}):e.jsx(y,{className:"size-5"})}),"Expenses"]}),o&&e.jsxs(V,{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:"Business"}),e.jsx("th",{children:"Invoice"}),e.jsx("th",{children:"Invoice Serial#"}),e.jsx("th",{children:"Invoice Date"}),e.jsx("th",{children:"Transaction Date"}),e.jsx("th",{children:"Amount"}),e.jsx("th",{children:"Amount ₪"}),e.jsx("th",{children:"VAT"}),e.jsx("th",{children:"VAT ₪"}),e.jsx("th",{children:"Actual VAT"}),e.jsx("th",{children:"Rounded VAT"}),e.jsx("th",{children:"Cumulative VAT"}),e.jsx("th",{children:"Amount without VAT ₪"}),e.jsx("th",{children:"Cumulative Amount without VAT ₪"}),e.jsx("th",{children:"Accountant Approval"}),e.jsx("th",{colSpan:2,children:"Edit"})]})}),e.jsx("tbody",{children:r.map((i,h)=>{s+=i.taxReducedLocalAmount?.raw??0;const m=s;t+=i.roundedLocalVatAfterDeduction?.raw??0;const x=t;return e.jsx(be,{data:i,toggleMergeCharge:c,mergeSelectedCharges:l,cumulativeVat:x,cumulativeAmount:m},h)})})]})]})},De=({data:a,toggleMergeCharge:c,mergeSelectedCharges:l,cumulativeAmount:r})=>{const[o,n]=d.useState(!1),s=p(X,a);return e.jsxs(e.Fragment,{children:[e.jsxs("tr",{className:"bg-gray-100",children:[e.jsxs("td",{className:"flex flex-col gap-1",children:[s.business?.name,s.vatNumber&&e.jsx("span",{style:{fontSize:"10px",color:"darkGray"},children:s.vatNumber})]}),e.jsx("td",{children:s.image&&e.jsx("a",{href:s.image,target:"_blank",rel:"noreferrer",children:e.jsx("img",{alt:"missing img",src:s.image,height:80,width:80})})}),e.jsx("td",{children:s.documentSerial}),e.jsx("td",{children:s.documentDate}),e.jsx("td",{children:s.chargeDate}),e.jsx("td",{children:s.taxReducedForeignAmount?.formatted}),e.jsx("td",{children:s.taxReducedLocalAmount?.formatted}),e.jsx("td",{children:"₪ "+D(r,0)}),e.jsx(P,{data:s}),e.jsx("td",{children:e.jsx("div",{className:"flex flex-col gap-2",children:e.jsx(M,{toggleExpansion:n,isExpanded:o})})}),e.jsx("td",{children:e.jsx(E,{toggleMergeSelected:()=>c(s.chargeId),mergeSelected:l.includes(s.chargeId)})})]}),o&&e.jsx("tr",{children:e.jsx("td",{colSpan:11,children:e.jsx(T,{style:{width:"100%"},withBorder:!0,shadow:"lg",children:e.jsx(R,{chargeID:s.chargeId,fetching:!!s})})})})]})},Ne=({data:a,toggleMergeCharge:c,mergeSelectedCharges:l})=>{const{income:r}=p(Y,a)??{income:[]},[o,n]=d.useState(!0);let s=0;return e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"text-lg font-semibold whitespace-nowrap flex flex-row gap-4",children:[e.jsx(g,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>n(t=>!t),children:o?e.jsx(w,{className:"size-5"}):e.jsx(y,{className:"size-5"})}),"Income"]}),o&&e.jsxs(V,{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:"Business"}),e.jsx("th",{children:"Invoice"}),e.jsx("th",{children:"Invoice Serial#"}),e.jsx("th",{children:"Invoice Date"}),e.jsx("th",{children:"Transaction Date"}),e.jsx("th",{children:"Amount"}),e.jsx("th",{children:"Amount ₪"}),e.jsx("th",{children:"Cumulative Amount ₪"}),e.jsx("th",{children:"Accountant Approval"}),e.jsx("th",{colSpan:2,children:"Edit"})]})}),e.jsx("tbody",{children:r.map((t,i)=>{s+=t.taxReducedLocalAmount?.raw??0;const h=s;return e.jsx(De,{data:t,toggleMergeCharge:c,mergeSelectedCharges:l,cumulativeAmount:h},i)})})]})]})},Fe=({data:a,setEditCharge:c,setInsertDocument:l,setMatchDocuments:r,toggleMergeCharge:o,mergeSelectedCharges:n})=>{const s=p(K,a),[t,i]=d.useState(!0);return e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"text-lg font-semibold whitespace-nowrap flex flex-row gap-4",children:[e.jsx(g,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>i(h=>!h),children:t?e.jsx(w,{className:"size-5"}):e.jsx(y,{className:"size-5"})}),"Misc Charges (which are not on the above tables)"]}),t&&s&&e.jsx(F,{setEditChargeId:c,setInsertDocument:l,setMatchDocuments:r,data:s.differentMonthDoc,isAllOpened:!1,toggleMergeCharge:o,mergeSelectedCharges:n})]})},Ie=({data:a,setEditCharge:c,setInsertDocument:l,setMatchDocuments:r,toggleMergeCharge:o,mergeSelectedCharges:n})=>{const s=p(W,a),[t,i]=d.useState(!0);return e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"text-lg font-semibold whitespace-nowrap flex flex-row gap-4",children:[e.jsx(g,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>i(h=>!h),children:t?e.jsx(w,{className:"size-5"}):e.jsx(y,{className:"size-5"})}),"Missing Info"]}),t&&s&&e.jsx(F,{setEditChargeId:c,setInsertDocument:l,setMatchDocuments:r,data:s.missingInfo,isAllOpened:!1,toggleMergeCharge:o,mergeSelectedCharges:n})]})},Ae=({filter:{monthDate:a,financialEntityId:c},isLoading:l})=>{const[{data:r,fetching:o,error:n},s]=z({query:B(se),pause:!0,variables:{monthDate:a,financialEntityId:c}});return d.useEffect(()=>{if(n){const t="Error generating PCN874 file";console.error(`${t}: ${n}`),Z.error("Error",{description:t,duration:5e3,closeButton:!0})}},[n]),d.useEffect(()=>{if(r){const t=new File([r.pcnFile.reportContent],"pcn874.txt",{type:"text/plain"});ee(t)}},[r]),e.jsx(te,{label:"Generate and Download PCN874 File",children:e.jsx(g,{disabled:o||l,variant:"outline",size:"icon",className:"size-7.5",onClick:s,children:e.jsx(we,{className:"size-5"})})})};function Se({filter:a,setFilter:c,closeModal:l}){const{control:r,handleSubmit:o,setValue:n}=oe({defaultValues:{...a}}),{selectableFinancialEntities:s,fetching:t}=ie(),i=x=>{c(x),l()};function h(){c(),l()}function m(x){const u=new Date(x.getFullYear(),x.getMonth(),15);n("monthDate",I(u,"yyyy-MM-dd"))}return e.jsxs(e.Fragment,{children:[t?e.jsx("div",{children:"Loading..."}):e.jsx("div",{}),e.jsxs("form",{onSubmit:o(i),children:[e.jsx(A,{name:"financialEntityId",control:r,defaultValue:void 0,render:({field:x,fieldState:u})=>e.jsx(S,{...x,data:s,value:x.value,disabled:t,label:"Financial Entities",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:u.error?.message})}),e.jsx(A,{name:"chargesType",control:r,defaultValue:a.chargesType,render:({field:x,fieldState:u})=>e.jsx(S,{...x,data:fe,value:x.value??N.All,label:"Charge Type",placeholder:"Filter income/expense",maxDropdownHeight:160,error:u.error?.message})}),e.jsx(ce,{defaultValue:a?.monthDate?new Date(a.monthDate):new Date,defaultDate:a?.monthDate?new Date(a.monthDate):new Date,onChange:m,popoverProps:{withinPortal:!0}}),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:h,children:"Clear"}),e.jsx("button",{type:"button",className:"text-white bg-rose-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-rose-600 rounded-sm text-lg",onClick:l,children:"Cancel"})]})]})]})}function Me({filter:a,setFilter:c}){const[l,r]=d.useState(!1),{get:o,set:n}=O(),{userContext:s}=d.useContext(k);function t(i){i||={financialEntityId:s?.context.adminBusinessId??a.financialEntityId,monthDate:I(new Date,"yyyy-MM-15")},le(i,a)||c(i)}return d.useEffect(()=>{const i=ae(a??{})?null:encodeURIComponent(JSON.stringify(a)),h=o("vatMonthlyReportFilters");i!==h&&n("vatMonthlyReportFilters",i)},[a,o,n]),e.jsxs(e.Fragment,{children:[e.jsx(ne,{opened:l,onClose:()=>r(!1),content:e.jsx(Se,{filter:a,setFilter:t,closeModal:()=>r(!1)})}),e.jsx(g,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>r(!0),children:e.jsx(re,{className:"size-5"})})]})}const Be=()=>{const{get:a}=O(),{setFiltersContext:c}=d.useContext(de),{userContext:l}=d.useContext(k),[r,o]=d.useState(a("vatMonthlyReportFilters")?JSON.parse(decodeURIComponent(a("vatMonthlyReportFilters"))):{financialEntityId:l?.context.adminBusinessId??"",monthDate:I(new Date,"yyyy-MM-15")}),[n,s]=d.useState([]),[t,i]=d.useState(void 0),[h,m]=d.useState(void 0),[x,u]=d.useState(void 0),[{data:j,fetching:b}]=z({query:B(ge),variables:{filters:r}}),f=d.useCallback(v=>{n.includes(v)?s(n.filter(U=>U!==v)):s([...n,v])},[n]);function L(){s([])}d.useEffect(()=>{c(e.jsxs("div",{className:"flex flex-row gap-2",children:[e.jsx(Ae,{filter:r,isLoading:b}),e.jsx(Me,{filter:{...r},setFilter:o}),e.jsx(je,{selected:n.map(v=>({id:v,onChange:()=>{}})),resetMerge:L})]}))},[j,r,b,c,n]);const C=d.useMemo(()=>new Set(n),[n]);return e.jsx(he,{title:"VAT Monthly Report",children:b?e.jsx(xe,{className:"h-10 w-10 animate-spin mr-2 self-center"}):e.jsxs("div",{className:"flex flex-col gap-4",children:[r.chargesType!==N.Expense&&e.jsx(Ne,{data:j?.vatReport,toggleMergeCharge:f,mergeSelectedCharges:n}),r.chargesType!==N.Income&&e.jsx(Ce,{data:j?.vatReport,toggleMergeCharge:f,mergeSelectedCharges:n}),e.jsx(Ie,{data:j?.vatReport,setEditCharge:u,setInsertDocument:i,setMatchDocuments:m,toggleMergeCharge:f,mergeSelectedCharges:C}),e.jsx(ye,{data:j?.vatReport,setEditCharge:u,setInsertDocument:i,setMatchDocuments:m,toggleMergeCharge:f,mergeSelectedCharges:C}),e.jsx(Fe,{data:j?.vatReport,setEditCharge:u,setInsertDocument:i,setMatchDocuments:m,toggleMergeCharge:f,mergeSelectedCharges:C}),x&&e.jsx(ue,{chargeId:x.id,close:()=>u(void 0)}),t&&e.jsx(me,{chargeId:t.id,close:()=>i(void 0)}),h&&e.jsx(pe,{chargeId:h.id,ownerId:h.ownerId,setMatchDocuments:()=>m(void 0)})]})})};export{Be as VatMonthlyReport};
6
+ */const ve=[["path",{d:"M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v4",key:"1pf5j1"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["rect",{width:"4",height:"6",x:"2",y:"12",rx:"2",key:"jm304g"}],["path",{d:"M10 12h2v6",key:"12zw74"}],["path",{d:"M10 18h4",key:"1ulq68"}]],we=q("file-digit",ve),ye=({data:a,setEditCharge:c,setInsertDocument:l,setMatchDocuments:r,toggleMergeCharge:o,mergeSelectedCharges:n})=>{const s=p(G,a),[t,i]=d.useState(!0);return e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"text-lg font-semibold whitespace-nowrap flex flex-row gap-4",children:[e.jsx(g,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>i(h=>!h),children:t?e.jsx(w,{className:"size-5"}):e.jsx(y,{className:"size-5"})}),"Business Trips"]}),t&&s&&e.jsx(F,{setEditChargeId:c,setInsertDocument:l,setMatchDocuments:r,data:s.businessTrips,isAllOpened:!1,toggleMergeCharge:o,mergeSelectedCharges:n})]})};function P({data:a}){const{chargeId:c,chargeAccountantStatus:l}=p(H,a),{updateChargeAccountantApproval:r}=_();return e.jsx("td",{children:e.jsx(Q,{value:l??void 0,onChange:o=>r({chargeId:c,status:o})})})}const be=({data:a,toggleMergeCharge:c,mergeSelectedCharges:l,cumulativeVat:r,cumulativeAmount:o})=>{const[n,s]=d.useState(!1),t=p($,a);return e.jsxs(e.Fragment,{children:[e.jsxs("tr",{className:"bg-gray-100",children:[e.jsxs("td",{className:"flex flex-col gap-1",children:[t.business?.name,t.vatNumber&&e.jsx("span",{style:{fontSize:"10px",color:"darkGray"},children:t.vatNumber})]}),e.jsx("td",{children:t.image&&e.jsx("a",{href:t.image,target:"_blank",rel:"noreferrer",children:e.jsx("img",{alt:"missing img",src:t.image,height:80,width:80})})}),e.jsx("td",{children:t.documentSerial}),e.jsx("td",{children:t.documentDate}),e.jsx("td",{children:t.chargeDate}),e.jsx("td",{className:"whitespace-nowrap",children:t.amount.formatted}),e.jsx("td",{className:"whitespace-nowrap",children:t.localAmount?.formatted}),e.jsx("td",{className:"whitespace-nowrap",children:t.localVat?.formatted}),e.jsx("td",{className:"whitespace-nowrap",children:t.localVatAfterDeduction?.formatted}),e.jsx("td",{className:"whitespace-nowrap",children:t.foreignVatAfterDeduction?.formatted}),e.jsx("td",{className:"whitespace-nowrap",children:t.roundedLocalVatAfterDeduction?.formatted}),e.jsxs("td",{className:"whitespace-nowrap",children:["₪ ",D(r,0)]}),e.jsxs("td",{className:"whitespace-nowrap",children:["₪ ",D(o,0)]}),e.jsx(P,{data:t}),e.jsx("td",{children:e.jsx("div",{className:"flex flex-col gap-2",children:e.jsx(M,{toggleExpansion:s,isExpanded:n})})}),e.jsx("td",{children:e.jsx(E,{toggleMergeSelected:()=>c(t.chargeId),mergeSelected:l.includes(t.chargeId)})})]}),n&&e.jsx("tr",{children:e.jsx("td",{colSpan:17,children:e.jsx(R,{style:{width:"100%"},withBorder:!0,shadow:"lg",children:e.jsx(T,{chargeID:t.chargeId,fetching:!!t})})})})]})},Ce=({data:a,toggleMergeCharge:c,mergeSelectedCharges:l})=>{const{expenses:r}=p(J,a)??{expenses:[]},[o,n]=d.useState(!0);let s=0,t=0;return e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"text-lg font-semibold whitespace-nowrap flex flex-row gap-4",children:[e.jsx(g,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>n(i=>!i),children:o?e.jsx(w,{className:"size-5"}):e.jsx(y,{className:"size-5"})}),"Expenses"]}),o&&e.jsxs(V,{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:"Business"}),e.jsx("th",{children:"Invoice"}),e.jsx("th",{children:"Invoice Serial#"}),e.jsx("th",{children:"Invoice Date"}),e.jsx("th",{children:"Transaction Date"}),e.jsx("th",{children:"Amount"}),e.jsx("th",{children:"Amount ₪"}),e.jsx("th",{children:"VAT"}),e.jsx("th",{children:"VAT ₪"}),e.jsx("th",{children:"Actual VAT"}),e.jsx("th",{children:"Rounded VAT"}),e.jsx("th",{children:"Cumulative VAT"}),e.jsx("th",{children:"Amount without VAT ₪"}),e.jsx("th",{children:"Cumulative Amount without VAT ₪"}),e.jsx("th",{children:"Accountant Approval"}),e.jsx("th",{colSpan:2,children:"Edit"})]})}),e.jsx("tbody",{children:r.map((i,h)=>{s+=i.taxReducedLocalAmount?.raw??0;const m=s;t+=i.roundedLocalVatAfterDeduction?.raw??0;const x=t;return e.jsx(be,{data:i,toggleMergeCharge:c,mergeSelectedCharges:l,cumulativeVat:x,cumulativeAmount:m},h)})})]})]})},De=({data:a,toggleMergeCharge:c,mergeSelectedCharges:l,cumulativeAmount:r})=>{const[o,n]=d.useState(!1),s=p(X,a);return e.jsxs(e.Fragment,{children:[e.jsxs("tr",{className:"bg-gray-100",children:[e.jsxs("td",{className:"flex flex-col gap-1",children:[s.business?.name,s.vatNumber&&e.jsx("span",{style:{fontSize:"10px",color:"darkGray"},children:s.vatNumber})]}),e.jsx("td",{children:s.image&&e.jsx("a",{href:s.image,target:"_blank",rel:"noreferrer",children:e.jsx("img",{alt:"missing img",src:s.image,height:80,width:80})})}),e.jsx("td",{children:s.documentSerial}),e.jsx("td",{children:s.documentDate}),e.jsx("td",{children:s.chargeDate}),e.jsx("td",{children:s.taxReducedForeignAmount?.formatted}),e.jsx("td",{children:s.taxReducedLocalAmount?.formatted}),e.jsx("td",{children:"₪ "+D(r,0)}),e.jsx(P,{data:s}),e.jsx("td",{children:e.jsx("div",{className:"flex flex-col gap-2",children:e.jsx(M,{toggleExpansion:n,isExpanded:o})})}),e.jsx("td",{children:e.jsx(E,{toggleMergeSelected:()=>c(s.chargeId),mergeSelected:l.includes(s.chargeId)})})]}),o&&e.jsx("tr",{children:e.jsx("td",{colSpan:11,children:e.jsx(R,{style:{width:"100%"},withBorder:!0,shadow:"lg",children:e.jsx(T,{chargeID:s.chargeId,fetching:!!s})})})})]})},Ne=({data:a,toggleMergeCharge:c,mergeSelectedCharges:l})=>{const{income:r}=p(Y,a)??{income:[]},[o,n]=d.useState(!0);let s=0;return e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"text-lg font-semibold whitespace-nowrap flex flex-row gap-4",children:[e.jsx(g,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>n(t=>!t),children:o?e.jsx(w,{className:"size-5"}):e.jsx(y,{className:"size-5"})}),"Income"]}),o&&e.jsxs(V,{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:"Business"}),e.jsx("th",{children:"Invoice"}),e.jsx("th",{children:"Invoice Serial#"}),e.jsx("th",{children:"Invoice Date"}),e.jsx("th",{children:"Transaction Date"}),e.jsx("th",{children:"Amount"}),e.jsx("th",{children:"Amount ₪"}),e.jsx("th",{children:"Cumulative Amount ₪"}),e.jsx("th",{children:"Accountant Approval"}),e.jsx("th",{colSpan:2,children:"Edit"})]})}),e.jsx("tbody",{children:r.map((t,i)=>{s+=t.taxReducedLocalAmount?.raw??0;const h=s;return e.jsx(De,{data:t,toggleMergeCharge:c,mergeSelectedCharges:l,cumulativeAmount:h},i)})})]})]})},Fe=({data:a,setEditCharge:c,setInsertDocument:l,setMatchDocuments:r,toggleMergeCharge:o,mergeSelectedCharges:n})=>{const s=p(Z,a),[t,i]=d.useState(!0);return e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"text-lg font-semibold whitespace-nowrap flex flex-row gap-4",children:[e.jsx(g,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>i(h=>!h),children:t?e.jsx(w,{className:"size-5"}):e.jsx(y,{className:"size-5"})}),"Misc Charges (which are not on the above tables)"]}),t&&s&&e.jsx(F,{setEditChargeId:c,setInsertDocument:l,setMatchDocuments:r,data:s.differentMonthDoc,isAllOpened:!1,toggleMergeCharge:o,mergeSelectedCharges:n})]})},Ie=({data:a,setEditCharge:c,setInsertDocument:l,setMatchDocuments:r,toggleMergeCharge:o,mergeSelectedCharges:n})=>{const s=p(K,a),[t,i]=d.useState(!0);return e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"text-lg font-semibold whitespace-nowrap flex flex-row gap-4",children:[e.jsx(g,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>i(h=>!h),children:t?e.jsx(w,{className:"size-5"}):e.jsx(y,{className:"size-5"})}),"Missing Info"]}),t&&s&&e.jsx(F,{setEditChargeId:c,setInsertDocument:l,setMatchDocuments:r,data:s.missingInfo,isAllOpened:!1,toggleMergeCharge:o,mergeSelectedCharges:n})]})},Ae=({filter:{monthDate:a,financialEntityId:c},isLoading:l})=>{const[{data:r,fetching:o,error:n},s]=z({query:B(se),pause:!0,variables:{monthDate:a,financialEntityId:c}});return d.useEffect(()=>{if(n){const t="Error generating PCN874 file";console.error(`${t}: ${n}`),W.error("Error",{description:t,duration:5e3,closeButton:!0})}},[n]),d.useEffect(()=>{if(r){const t=new File([r.pcnFile.reportContent],"pcn874.txt",{type:"text/plain"});ee(t)}},[r]),e.jsx(te,{label:"Generate and Download PCN874 File",children:e.jsx(g,{disabled:o||l,variant:"outline",size:"icon",className:"size-7.5",onClick:s,children:e.jsx(we,{className:"size-5"})})})};function Se({filter:a,setFilter:c,closeModal:l}){const{control:r,handleSubmit:o,setValue:n}=oe({defaultValues:{...a}}),{selectableFinancialEntities:s,fetching:t}=ie(),i=x=>{c(x),l()};function h(){c(),l()}function m(x){const u=new Date(x.getFullYear(),x.getMonth(),15);n("monthDate",I(u,"yyyy-MM-dd"))}return e.jsxs(e.Fragment,{children:[t?e.jsx("div",{children:"Loading..."}):e.jsx("div",{}),e.jsxs("form",{onSubmit:o(i),children:[e.jsx(A,{name:"financialEntityId",control:r,defaultValue:void 0,render:({field:x,fieldState:u})=>e.jsx(S,{...x,data:s,value:x.value,disabled:t,label:"Financial Entities",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:u.error?.message})}),e.jsx(A,{name:"chargesType",control:r,defaultValue:a.chargesType,render:({field:x,fieldState:u})=>e.jsx(S,{...x,data:fe,value:x.value??N.All,label:"Charge Type",placeholder:"Filter income/expense",maxDropdownHeight:160,error:u.error?.message})}),e.jsx(ce,{defaultValue:a?.monthDate?new Date(a.monthDate):new Date,defaultDate:a?.monthDate?new Date(a.monthDate):new Date,onChange:m,popoverProps:{withinPortal:!0}}),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:h,children:"Clear"}),e.jsx("button",{type:"button",className:"text-white bg-rose-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-rose-600 rounded-sm text-lg",onClick:l,children:"Cancel"})]})]})]})}function Me({filter:a,setFilter:c}){const[l,r]=d.useState(!1),{get:o,set:n}=O(),{userContext:s}=d.useContext(k);function t(i){i||={financialEntityId:s?.context.adminBusinessId??a.financialEntityId,monthDate:I(new Date,"yyyy-MM-15")},le(i,a)||c(i)}return d.useEffect(()=>{const i=ae(a??{})?null:encodeURIComponent(JSON.stringify(a)),h=o("vatMonthlyReportFilters");i!==h&&n("vatMonthlyReportFilters",i)},[a,o,n]),e.jsxs(e.Fragment,{children:[e.jsx(ne,{opened:l,onClose:()=>r(!1),content:e.jsx(Se,{filter:a,setFilter:t,closeModal:()=>r(!1)})}),e.jsx(g,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>r(!0),children:e.jsx(re,{className:"size-5"})})]})}const Be=()=>{const{get:a}=O(),{setFiltersContext:c}=d.useContext(de),{userContext:l}=d.useContext(k),[r,o]=d.useState(a("vatMonthlyReportFilters")?JSON.parse(decodeURIComponent(a("vatMonthlyReportFilters"))):{financialEntityId:l?.context.adminBusinessId??"",monthDate:I(new Date,"yyyy-MM-15")}),[n,s]=d.useState([]),[t,i]=d.useState(void 0),[h,m]=d.useState(void 0),[x,u]=d.useState(void 0),[{data:j,fetching:b}]=z({query:B(ge),variables:{filters:r}}),f=d.useCallback(v=>{n.includes(v)?s(n.filter(U=>U!==v)):s([...n,v])},[n]);function L(){s([])}d.useEffect(()=>{c(e.jsxs("div",{className:"flex flex-row gap-2",children:[e.jsx(Ae,{filter:r,isLoading:b}),e.jsx(Me,{filter:{...r},setFilter:o}),e.jsx(je,{selected:n.map(v=>({id:v,onChange:()=>{}})),resetMerge:L})]}))},[j,r,b,c,n]);const C=d.useMemo(()=>new Set(n),[n]);return e.jsx(he,{title:"VAT Monthly Report",children:b?e.jsx(xe,{className:"h-10 w-10 animate-spin mr-2 self-center"}):e.jsxs("div",{className:"flex flex-col gap-4",children:[r.chargesType!==N.Expense&&e.jsx(Ne,{data:j?.vatReport,toggleMergeCharge:f,mergeSelectedCharges:n}),r.chargesType!==N.Income&&e.jsx(Ce,{data:j?.vatReport,toggleMergeCharge:f,mergeSelectedCharges:n}),e.jsx(Ie,{data:j?.vatReport,setEditCharge:u,setInsertDocument:i,setMatchDocuments:m,toggleMergeCharge:f,mergeSelectedCharges:C}),e.jsx(ye,{data:j?.vatReport,setEditCharge:u,setInsertDocument:i,setMatchDocuments:m,toggleMergeCharge:f,mergeSelectedCharges:C}),e.jsx(Fe,{data:j?.vatReport,setEditCharge:u,setInsertDocument:i,setMatchDocuments:m,toggleMergeCharge:f,mergeSelectedCharges:C}),x&&e.jsx(ue,{chargeId:x.id,close:()=>u(void 0)}),t&&e.jsx(me,{chargeId:t.id,close:()=>i(void 0)}),h&&e.jsx(pe,{chargeId:h.id,ownerId:h.ownerId,setMatchDocuments:()=>m(void 0)})]})})};export{Be as VatMonthlyReport};
@@ -1 +1 @@
1
- import{j as e,T as ae,B as U,aC as se,ce as ne,a as D,fx as te,r as x,ag as q,fy as le,fz as z,V,t as f,a1 as oe,fA as ie,dc as G,bP as u,bQ as k,a3 as de,fB as ce,a4 as me,a5 as ue,a6 as xe,v as ye,a8 as pe,bW as g,bR as S,H as E,ad as ge,i as W,fC as he,l as Q,fD as je,fE as _,e as fe,fF as ve,fG as be,u as J,c_ as Ne,d1 as Se,c$ as Ee,d0 as we,ci as Fe,X as w,fH as Ce,fI as De,fJ as Ie,fK as Ae,fL as Pe,fM as Re,fN as Te,fO as ke,fP as Me,F as Be,c as Le,L as Ze,fQ as Oe}from"./index-C1vFqfE7.js";function Y(t){return e.jsx(ae,{disabled:!t.tooltip,label:t.tooltip,children:e.jsx(U,{variant:"ghost",size:"icon",className:"size-7.5",...t,children:e.jsx(se,{className:"size-5"})})})}const X=({isNewInsert:t=!0,defaultValues:a,month:o,onDone:d,isModifying:l})=>{const{selectableBusinesses:i,fetching:n}=ne(),[{data:c,fetching:y,error:j}]=D({query:te}),{userContext:v}=x.useContext(q),[{data:b,fetching:F,error:R}]=D({query:le}),[{data:I,fetching:M,error:C}]=D({query:z,variables:{employerId:v?.context.adminBusinessId??""}}),[p,N]=x.useState([]),[A,T]=x.useState([]),[K,ee]=x.useState([]),P=a?.month??o,Z=V({defaultValues:{...a,month:P}}),{control:m,handleSubmit:O,formState:{dirtyFields:$},setValue:B}=Z;x.useEffect(()=>{j&&f.error("Error",{description:"Oh no!, we have an error fetching pension funds! 🤥"})},[j]),x.useEffect(()=>{R&&f.error("Error",{description:"Oh no!, we have an error fetching training funds! 🤥"})},[R]),x.useEffect(()=>{C&&f.error("Error",{description:"Oh no!, we have an error employees! 🤥"})},[C]),x.useEffect(()=>{c?.allPensionFunds?.length&&N(c.allPensionFunds.map(r=>({value:r.id,label:r.name})).sort((r,s)=>r.label>s.label?1:-1))},[c,T]),x.useEffect(()=>{b?.allTrainingFunds?.length&&T(b.allTrainingFunds.map(r=>({value:r.id,label:r.name})).sort((r,s)=>r.label>s.label?1:-1))},[b,T]),x.useEffect(()=>{I?.employeesByEmployerId.length&&ee(I.employeesByEmployerId.filter(r=>!r.name.toLocaleLowerCase().includes("batched")).map(r=>({value:r.id,label:r.name})).sort((r,s)=>r.label>s.label?1:-1))},[I,T]),x.useEffect(()=>{!a?.employer&&v?.context.adminBusinessId&&B("employer",v.context.adminBusinessId,{shouldDirty:!0,shouldTouch:!0})},[B,a?.employer,v?.context.adminBusinessId]);const H=r=>{const s=ge(r,$);if(!(t&&(!s?.directPaymentAmount||!s?.employeeId||!s?.employer||!s?.month)))if(s&&Object.keys(s).length>0){if(!t){if(!a)return;s.employeeId??=a.employeeId,s.month??=a.month}d(s)}else d()};function re(r){B("month",E(r,"yyyy-MM-dd"),{shouldDirty:!0,shouldTouch:!0})}return e.jsx(oe,{...Z,children:e.jsxs("form",{onSubmit:O(H),children:[e.jsx("div",{className:"flex-row px-10 h-max justify-start block",children:e.jsxs(ie,{cols:4,children:[e.jsxs("div",{className:"flex-column h-max justify-start block",children:[e.jsx(G,{defaultDate:P?new Date(P):void 0,defaultValue:P?new Date(P):void 0,onChange:re,popoverProps:{withinPortal:!0}}),e.jsx(u,{name:"employer",control:m,defaultValue:a?.employer,rules:{required:"Required"},render:({field:r,fieldState:s})=>e.jsx(k,{...r,data:i,value:r.value,disabled:n,label:"Employer",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:s.error?.message})}),e.jsx(de,{name:"chargeId",control:m,defaultValue:a?.chargeId,rules:{pattern:{value:ce,message:"Invalid UUID"}},render:({field:r})=>e.jsxs(me,{children:[e.jsx(ue,{children:"Charge ID"}),e.jsx(xe,{children:e.jsx(ye,{...r,value:r.value??void 0})}),e.jsx(pe,{})]})}),e.jsx(u,{name:"employeeId",control:m,defaultValue:a?.employeeId,rules:{required:"Required"},render:({field:r,fieldState:s})=>e.jsx(k,{...r,data:K,value:r.value,disabled:M,label:"Employee",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:s.error?.message})})]}),e.jsxs("div",{className:"flex-row px-10 h-max justify-start block",children:[e.jsx(u,{name:"baseSalary",control:m,defaultValue:a?.baseSalary,render:({field:r,fieldState:s})=>e.jsx(g,{...r,value:r.value??void 0,error:s.error?.message,label:"Base Salary",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"globalAdditionalHours",control:m,defaultValue:a?.globalAdditionalHours,render:({field:r,fieldState:s})=>e.jsx(g,{...r,value:r.value??void 0,error:s.error?.message,label:"Global Additional Hours",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"bonus",control:m,defaultValue:a?.bonus,render:({field:r,fieldState:s})=>e.jsx(g,{...r,value:r.value??void 0,error:s.error?.message,label:"Bonus",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"gift",control:m,defaultValue:a?.gift,render:({field:r,fieldState:s})=>e.jsx(g,{...r,value:r.value??void 0,error:s.error?.message,label:"Gift",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"travelAndSubsistence",control:m,defaultValue:a?.travelAndSubsistence,render:({field:r,fieldState:s})=>e.jsx(g,{...r,value:r.value??void 0,error:s.error?.message,label:"Travel and Subsistence",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"recovery",control:m,defaultValue:a?.recovery,render:({field:r,fieldState:s})=>e.jsx(g,{...r,value:r.value??void 0,error:s.error?.message,label:"Recovery",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency"}})}),e.jsx(u,{name:"vacationTakeout",control:m,defaultValue:a?.vacationTakeout,render:({field:r,fieldState:s})=>e.jsx(g,{...r,value:r.value??void 0,error:s.error?.message,label:"Vacation Takeout",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"directPaymentAmount",control:m,defaultValue:a?.directPaymentAmount,rules:{required:"Required"},render:({field:r,fieldState:s})=>e.jsx(g,{...r,value:r.value??void 0,error:s.error?.message,label:"Direct Payment",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})})]}),e.jsxs("div",{className:"flex-row px-10 h-max justify-start block",children:[e.jsx(u,{name:"pensionFundId",control:m,defaultValue:a?.pensionFundId,render:({field:r,fieldState:s})=>e.jsx(k,{...r,data:p,value:r.value,disabled:y,label:"Pension Fund",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:s.error?.message})}),e.jsx(u,{name:"pensionEmployeeAmount",control:m,defaultValue:a?.pensionEmployeeAmount,render:({field:r,fieldState:s})=>e.jsx(g,{...r,value:r.value??void 0,error:s.error?.message,label:"Pension Employee Amount",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"pensionEmployeePercentage",control:m,defaultValue:a?.pensionEmployeePercentage,render:({field:{value:r,...s},fieldState:h})=>e.jsx(S,{...s,hideControls:!0,precision:2,removeTrailingZeros:!0,rightSection:"%",value:r??void 0,error:h.error?.message,label:"Pension Employee Percentage"})}),e.jsx(u,{name:"pensionEmployerAmount",control:m,defaultValue:a?.pensionEmployerAmount,render:({field:r,fieldState:s})=>e.jsx(g,{...r,value:r.value??void 0,error:s.error?.message,label:"Pension Employer Amount",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"pensionEmployerPercentage",control:m,defaultValue:a?.pensionEmployerPercentage,render:({field:{value:r,...s},fieldState:h})=>e.jsx(S,{...s,hideControls:!0,precision:2,removeTrailingZeros:!0,rightSection:"%",value:r??void 0,error:h.error?.message,label:"Pension Employer Percentage"})})]}),e.jsxs("div",{className:"flex-row px-10 h-max justify-start block",children:[e.jsx(u,{name:"compensationsEmployerAmount",control:m,defaultValue:a?.compensationsEmployerAmount,render:({field:r,fieldState:s})=>e.jsx(g,{...r,value:r.value??void 0,error:s.error?.message,label:"Compensations Amount",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"compensationsEmployerPercentage",control:m,defaultValue:a?.compensationsEmployerPercentage,render:({field:{value:r,...s},fieldState:h})=>e.jsx(S,{...s,hideControls:!0,precision:2,removeTrailingZeros:!0,rightSection:"%",value:r??void 0,error:h.error?.message,label:"Compensations Percentage"})})]}),e.jsxs("div",{className:"flex-row px-10 h-max justify-start block",children:[e.jsx(u,{name:"trainingFundId",control:m,defaultValue:a?.trainingFundId,render:({field:r,fieldState:s})=>e.jsx(k,{...r,data:A,value:r.value,disabled:F,label:"Training Fund",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:s.error?.message})}),e.jsx(u,{name:"trainingFundEmployeeAmount",control:m,defaultValue:a?.trainingFundEmployeeAmount,render:({field:r,fieldState:s})=>e.jsx(g,{...r,value:r.value??void 0,error:s.error?.message,label:"Training Employee Amount",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"trainingFundEmployeePercentage",control:m,defaultValue:a?.trainingFundEmployeePercentage,render:({field:{value:r,...s},fieldState:h})=>e.jsx(S,{...s,hideControls:!0,precision:2,removeTrailingZeros:!0,rightSection:"%",value:r??void 0,error:h.error?.message,label:"Training Employee Percentage"})}),e.jsx(u,{name:"trainingFundEmployerAmount",control:m,defaultValue:a?.trainingFundEmployerAmount,render:({field:r,fieldState:s})=>e.jsx(g,{...r,value:r.value??void 0,error:s.error?.message,label:"Training Employer Amount",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"trainingFundEmployerPercentage",control:m,defaultValue:a?.trainingFundEmployerPercentage,render:({field:{value:r,...s},fieldState:h})=>e.jsx(S,{...s,hideControls:!0,precision:2,removeTrailingZeros:!0,rightSection:"%",value:r??void 0,error:h.error?.message,label:"Training Employer Percentage"})})]}),e.jsxs("div",{className:"flex-row px-10 h-max justify-start block",children:[e.jsx(u,{name:"socialSecurityAmountEmployee",control:m,defaultValue:a?.socialSecurityAmountEmployee,render:({field:r,fieldState:s})=>e.jsx(g,{...r,value:r.value??void 0,error:s.error?.message,label:"Social Security - Employee",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"socialSecurityAmountEmployer",control:m,defaultValue:a?.socialSecurityAmountEmployer,render:({field:r,fieldState:s})=>e.jsx(g,{...r,value:r.value??void 0,error:s.error?.message,label:"Social Security - Employer",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"healthPaymentAmount",control:m,defaultValue:a?.healthPaymentAmount,render:({field:r,fieldState:s})=>e.jsx(g,{...r,value:r.value??void 0,error:s.error?.message,label:"Health Insurance",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})})]}),e.jsxs("div",{className:"flex-row px-10 h-max justify-start block",children:[e.jsx(u,{name:"taxAmount",control:m,defaultValue:a?.taxAmount,render:({field:r,fieldState:s})=>e.jsx(g,{...r,value:r.value??void 0,error:s.error?.message,label:"Income Tax",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"zkufot",control:m,defaultValue:a?.zkufot,render:({field:r,fieldState:s})=>e.jsx(g,{...r,value:r.value??void 0,error:s.error?.message,precision:0,label:"Notional Expense",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})})]}),e.jsxs("div",{className:"flex-row px-10 h-max justify-start block",children:[e.jsx(u,{name:"workDays",control:m,defaultValue:a?.workDays,render:({field:{value:r,...s},fieldState:h})=>e.jsx(S,{...s,hideControls:!0,precision:2,removeTrailingZeros:!0,value:r??void 0,error:h.error?.message,label:"Work Days"})}),e.jsx(u,{name:"addedVacationDays",control:m,defaultValue:a?.addedVacationDays,render:({field:{value:r,...s},fieldState:h})=>e.jsx(S,{...s,hideControls:!0,precision:2,removeTrailingZeros:!0,value:r??void 0,error:h.error?.message,label:"Added Vacation Days"})}),e.jsx(u,{name:"vacationDaysBalance",control:m,defaultValue:a?.vacationDaysBalance,render:({field:{value:r,...s},fieldState:h})=>e.jsx(S,{...s,hideControls:!0,precision:2,removeTrailingZeros:!0,value:r??void 0,error:h.error?.message,label:"Vacation Days Balance"})}),e.jsx(u,{name:"sicknessDaysBalance",control:m,defaultValue:a?.sicknessDaysBalance,render:({field:{value:r,...s},fieldState:h})=>e.jsx(S,{...s,hideControls:!0,precision:2,removeTrailingZeros:!0,value:r??void 0,error:h.error?.message,label:"Sickness Days Balance"})})]})]})}),e.jsxs("div",{className:"mt-10 mb-5 flex justify-center gap-5",children:[e.jsx("button",{type:"submit",onClick:()=>O(H),className:"mt-8 text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg",disabled:l||Object.keys($).length===0,children:"Accept"}),e.jsx("button",{type:"button",className:"mt-8 text-white bg-rose-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-rose-600 rounded-sm text-lg",onClick:()=>d(),children:"Cancel"})]})]})})},$e="updateSalaryRecord",He=()=>{const[{fetching:t},a]=W(he),o=x.useCallback(async d=>{const l=`Error updating salary record [${d.salaryRecord.month}] employee [${d.salaryRecord.employeeId}]`,i=$e;f.loading("Updating Salary Record",{id:i});try{const n=await a(d),c=Q(n,l,i,"updateSalaryRecord");if(c)return f.success("Success",{id:i,description:"Salary record was updated"}),c.updateSalaryRecord.salaryRecord}catch(n){console.error(`${l}: ${n}`),f.error("Error",{id:i,description:l,duration:1e5,closeButton:!0})}},[a]);return{fetching:t,updateSalaryRecord:o}},Ue=({recordVariables:t,onDone:a})=>t?e.jsx(qe,{recordVariables:t,onDone:a}):null,qe=({recordVariables:t,onDone:a})=>{const{updateSalaryRecord:o,fetching:d}=He(),[{data:l,fetching:i}]=D({query:je,variables:{employeeIDs:[t.employeeId],month:E(new Date(t.month),"yyyy-MM-dd")}}),n=l?.salaryRecordsByDates?.[0],c=x.useCallback(j=>{a(),j&&o({salaryRecord:j})},[a,o]);if(!n?.employer?.id||!n?.employee?.id)return e.jsx(e.Fragment,{});const y={addedVacationDays:n?.vacationDays?.added,baseSalary:n?.baseAmount?.raw,bonus:n?.bonus?.raw,chargeId:n?.charge?.id,compensationsEmployerAmount:n?.compensationsAmount?.raw,compensationsEmployerPercentage:n?.compensationsPercentage,directPaymentAmount:n?.directAmount?.raw,employer:n.employer.id,employeeId:n.employee.id,gift:n?.gift?.raw,globalAdditionalHours:n?.globalAdditionalHoursAmount?.raw,healthPaymentAmount:n?.healthInsuranceAmount?.raw,month:n?.month,pensionEmployeeAmount:n?.pensionEmployeeAmount?.raw,pensionEmployeePercentage:n?.pensionEmployeePercentage,pensionEmployerAmount:n?.pensionEmployerAmount?.raw,pensionEmployerPercentage:n?.pensionEmployerPercentage,pensionFundId:n?.pensionFund?.id,recovery:n?.recovery?.raw,sicknessDaysBalance:n?.sicknessDays?.balance,socialSecurityAmountEmployee:n?.socialSecurityEmployeeAmount?.raw,socialSecurityAmountEmployer:n?.socialSecurityEmployerAmount?.raw,taxAmount:n?.incomeTaxAmount?.raw,trainingFundEmployeeAmount:n?.trainingFundEmployeeAmount?.raw,trainingFundEmployeePercentage:n?.trainingFundEmployeePercentage,trainingFundEmployerAmount:n?.trainingFundEmployerAmount?.raw,trainingFundEmployerPercentage:n?.trainingFundEmployerPercentage,trainingFundId:n?.trainingFund?.id,travelAndSubsistence:n?.travelAndSubsistence?.raw,vacationDaysBalance:n?.vacationDays?.balance,vacationTakeout:n?.vacationTakeout?.raw,workDays:n?.workDays,zkufot:n?.notionalExpense?.raw};return e.jsx(_,{modalSize:"fit-content",position:"bottom",title:e.jsxs("div",{className:"flex flex-row mx-3 pt-3 sm:text-1xl gap-10",children:[e.jsx("h1",{className:"sm:text-2xl font-small text-gray-900",children:"Edit Salary Record:"}),e.jsxs("div",{className:"flex flex-row gap-2",children:["month: ",t.month," employeeId: ",t.employeeId]})]}),opened:!!t,onClose:a,children:i||!n?e.jsx(fe,{className:"flex self-center my-5",color:"dark",size:"xl",variant:"dots"}):e.jsx(X,{isNewInsert:!1,defaultValues:y,onDone:c,isModifying:d})})},ze="insertSalaryRecords",Ve=()=>{const[{fetching:t},a]=W(ve),o=x.useCallback(async d=>{const l=ze;if(f.loading("Adding salary record",{id:l}),!d.salaryRecords||Array.isArray(d.salaryRecords)&&d.salaryRecords.length===0){f.error("Error",{id:l,description:"No salary records to insert",duration:1e5,closeButton:!0});return}const i=Array.isArray(d.salaryRecords)?d.salaryRecords[0]:d.salaryRecords;if(!i?.directPaymentAmount||!i?.employeeId||!i?.employer||!i?.month){f.error("Error",{id:l,description:"Missing required salary record fields",duration:1e5,closeButton:!0});return}const n=`Error adding salary record [${i.month}] employee [${i.employeeId}]`;try{const c=await a(d),y=Q(c,n,l,"insertSalaryRecords");if(y)return f.success("Success",{id:l,description:"Salary record was added"}),y.insertSalaryRecords.salaryRecords[0]}catch(c){console.error(`${n}: ${c}`),f.error("Error",{id:l,description:n,duration:1e5,closeButton:!0})}},[a]);return{fetching:t,insertSalaryRecord:o}},Ge=({insertSalaryRecordParams:t,setInsertSalaryRecord:a})=>{const{insertSalaryRecord:o,fetching:d}=Ve(),l=x.useCallback(i=>{i&&o({salaryRecords:[i]}),a(void 0)},[a,o]);return e.jsx(_,{modalSize:"40%",position:"bottom",title:e.jsx("div",{className:"flex flex-row mx-3 pt-3 sm:text-1xl gap-10",children:e.jsx("h1",{className:"sm:text-2xl font-small text-gray-900",children:"Insert Salary Record:"})}),opened:!!t,onClose:()=>a(void 0),children:e.jsx(X,{isNewInsert:!0,onDone:l,isModifying:d,month:t.month})})};function L(){const t=new Date,a=E(t,"yyyy-MM-dd"),o=E(be(t),"yyyy-MM-dd");return{fromDate:a,toDate:o}}function We({filter:t,setFilter:a,closeModal:o}){const{control:d,handleSubmit:l,setValue:i}=V({defaultValues:{...t}}),[n,c]=x.useState([]),{userContext:y}=x.useContext(q),[{data:j,fetching:v,error:b},F]=D({query:z,variables:{employerId:y?.context.adminBusinessId??""},pause:!0});x.useEffect(()=>{F()},[y?.context.adminBusinessId,F]),x.useEffect(()=>{b&&f.error("Error",{description:"Oh no!, we have an error fetching employees! 🤥"})},[b]);const R=p=>{p.employeeIDs?.length===0&&delete p.employeeIDs,a(p),o()};function I(){a({...L()}),o()}x.useEffect(()=>{j?.employeesByEmployerId.length&&c(j.employeesByEmployerId.filter(p=>!p.name.toLocaleLowerCase().includes("batched")).map(p=>({value:p.id,label:p.name})).sort((p,N)=>p.label>N.label?1:-1))},[j,c]);function M([p,N]){if(N){const A=new Date(N.getFullYear(),N.getMonth()+1,0);i("toDate",E(A,"yyyy-MM-dd"))}if(p){const A=new Date(p.getFullYear(),p.getMonth(),1);i("fromDate",E(A,"yyyy-MM-dd"))}}const C=L();return e.jsxs(e.Fragment,{children:[v?e.jsx("div",{children:"Loading..."}):e.jsx("div",{}),e.jsxs("form",{onSubmit:l(R),children:[e.jsx(G,{type:"range",numberOfColumns:2,defaultValue:[new Date(t?.fromDate??C.fromDate),new Date(t?.toDate??C.toDate)],defaultDate:new Date(t?.fromDate??C.fromDate),onChange:M,popoverProps:{withinPortal:!0}}),e.jsx(u,{name:"employeeIDs",control:d,defaultValue:t.employeeIDs,render:({field:p,fieldState:N})=>e.jsx(Fe,{...p,data:n,value:p.value??[],disabled:v,label:"Employees",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:N.error?.message})}),e.jsxs("div",{className:"flex justify-center mt-5 gap-3",children:[e.jsx("button",{type:"submit",disabled:v,className:"text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg",children:"Filter"}),e.jsx("button",{type:"button",className:"text-white bg-orange-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-orange-600 rounded-sm text-lg",onClick:I,children:"Clear"}),e.jsx("button",{type:"button",className:"text-white bg-rose-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-rose-600 rounded-sm text-lg",onClick:o,children:"Cancel"})]})]})]})}function Qe({filter:t,setFilter:a}){const[o,d]=x.useState(!1),{get:l,set:i}=J();x.useEffect(()=>{const c=Ne(t)?null:encodeURIComponent(JSON.stringify(t)),y=l("salariesFilters");c!==y&&i("salariesFilters",c)},[t,l,i]);const n=x.useCallback(c=>{Se(c,t)||a(c)},[t,a]);return e.jsxs("div",{className:"flex flex-row gap-5 items-center",children:[e.jsx(Ee,{opened:o,onClose:()=>d(!1),content:e.jsx(We,{filter:t,setFilter:n,closeModal:()=>d(!1)}),modalSize:"xl"}),e.jsx(U,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>d(!0),children:e.jsx(we,{className:"size-5"})})]})}const _e=({month:t,setInsertSalaryRecord:a})=>{const o=E(new Date(t),"MMMM yyyy");return e.jsx("tr",{tabIndex:0,className:"h-16 rounded-sm",children:e.jsx("td",{colSpan:100,children:e.jsxs("div",{className:"flex justify-between pl-5",children:[e.jsx("p",{className:"text-lg font-bold text-gray-800",children:o}),e.jsx("div",{className:"flex items-center",children:e.jsx("div",{className:"flex flex-col",children:e.jsx(Y,{onClick:a})})})]})})})},Je=({data:t})=>{const{employee:a,month:o}=w(Ce,t),d=E(new Date(o),"MMMM yyyy");return e.jsx("td",{className:"",children:e.jsx("div",{className:"flex items-center pl-5",children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("p",{className:"text-base font-bold text-gray-800",children:a?.name}),e.jsx("p",{className:"text-base font-medium text-gray-800",children:d})]})})})},Ye=({data:t})=>{const{pensionEmployeeAmount:a,pensionEmployeePercentage:o,pensionEmployerAmount:d,pensionEmployerPercentage:l,compensationsAmount:i,compensationsPercentage:n,pensionFund:c,trainingFund:y,trainingFundEmployeeAmount:j,trainingFundEmployeePercentage:v,trainingFundEmployerAmount:b,trainingFundEmployerPercentage:F}=w(De,t);return e.jsx("td",{className:"pl-5",children:e.jsx("div",{className:"flex items-center",children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("p",{className:"text-md font-bold text-gray-800",children:"Pension Fund"}),e.jsx("p",{className:"text-md font-medium text-gray-800",children:c?.name}),!!a?.raw&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Employee Part:"}),e.jsxs("p",{className:"text-sm leading-none text-gray-600 ml-2",children:[a?.formatted,o&&` (${o}%)`]})]}),!!d?.raw&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Employer Part:"}),e.jsxs("p",{className:"text-sm leading-none text-gray-600 ml-2",children:[d?.formatted,l&&` (${l}%)`]})]}),!!i?.raw&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Compensations Amount:"}),e.jsxs("p",{className:"text-sm leading-none text-gray-600 ml-2",children:[i?.formatted,n&&` (${n}%)`]})]}),e.jsx("p",{className:"text-md font-bold text-gray-800 mt-2",children:"Training Fund"}),e.jsx("p",{className:"text-md font-medium text-gray-800",children:y?.name}),!!j?.raw&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Employee Part:"}),e.jsxs("p",{className:"text-sm leading-none text-gray-600 ml-2",children:[j?.formatted,v&&` (${v}%)`]})]}),!!b?.raw&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Employer Part:"}),e.jsxs("p",{className:"text-sm leading-none text-gray-600 ml-2",children:[b?.formatted,F&&` (${F}%)`]})]})]})})})},Xe=({data:t})=>{const{healthInsuranceAmount:a,socialSecurityEmployeeAmount:o,socialSecurityEmployerAmount:d,incomeTaxAmount:l,notionalExpense:i}=w(Ie,t),n=!!o||!!d;return e.jsx("td",{className:"pl-5",children:e.jsx("div",{className:"flex items-center pl-5",children:e.jsxs("div",{className:"flex flex-col",children:[n&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-md font-bold text-gray-800",children:"Social Security"}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Employee Part:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:o?.formatted})]}),e.jsx("p",{className:"text-md font-bold text-gray-800 mt-2",children:"Pension Fund"}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Employer Part:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:d?.formatted})]})]}),!!a?.raw&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-md font-bold text-gray-800 mt-2",children:"Health Insurance"}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Amount:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:a?.formatted})]})]}),(!!l?.raw||!!i?.raw)&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-md font-bold text-gray-800 mt-2",children:"Taxes"}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Income Tax:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:l?.formatted})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Notional Expense:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:i?.formatted})]})]})]})})})},Ke=({data:t})=>{const{baseAmount:a,directAmount:o,globalAdditionalHoursAmount:d,bonus:l,gift:i,recovery:n,vacationTakeout:c}=w(Ae,t);return e.jsx("td",{className:"pl-24",children:e.jsx("div",{className:"flex items-center",children:e.jsxs("div",{className:"flex flex-col",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Base Amount:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:a?.formatted})]}),e.jsxs("div",{className:"flex justify-between mb-2",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Global Extra Hours:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:d?.formatted})]}),!!l?.raw&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Bonus:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:l?.formatted})]}),!!i?.raw&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Gift:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:i?.formatted})]}),!!n?.raw&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Recovery:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:n?.formatted})]}),!!c?.raw&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Vacation Takeout:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:c?.formatted})]}),e.jsxs("div",{className:"flex justify-between mt-2",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Direct Amount:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:o?.formatted})]})]})})})},er=({data:t})=>{const{vacationDays:a,workDays:o,sicknessDays:d}=w(Pe,t),{added:l,taken:i,balance:n}=a??{},{balance:c}=d??{},y=!!l||!!i||!!n;return e.jsx("td",{className:"pl-5",children:e.jsx("div",{className:"flex items-center",children:e.jsxs("div",{className:"flex flex-col",children:[!!o&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-md leading-none text-gray-800",children:"Work Days:"}),e.jsx("div",{className:"flex justify-between",children:e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:o})})]}),y&&e.jsxs("div",{className:"flex flex-col",children:[e.jsx("p",{className:"text-md leading-none text-gray-800 mt-2",children:"Vacation Days:"}),!!l&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Added:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:l})]}),!!i&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Taken:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:i})]}),!!n&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Balance:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:n})]})]}),!!c&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-md leading-none text-gray-800 mt-2",children:"Sickness Days:"}),e.jsx("div",{className:"flex justify-between",children:e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:c})})]})]})})})},rr=({setEditSalaryRecord:t,data:a})=>{const o=w(Te,a);return e.jsxs(e.Fragment,{children:[e.jsxs("tr",{tabIndex:0,className:"h-16 border border-gray-100 hover:bg-gray-100 rounded-sm",children:[e.jsx(Je,{data:o}),e.jsx(Ke,{data:o}),e.jsx(Ye,{data:o}),e.jsx(Xe,{data:o}),e.jsx(er,{data:o}),e.jsx("td",{className:"pl-2",children:e.jsx("div",{className:"flex items-center",children:e.jsx("div",{className:"flex flex-col",children:e.jsx(Re,{onClick:t})})})})]}),e.jsx("tr",{className:"h-3"})]})},ar=({setEditSalaryRecord:t,setInsertSalaryRecord:a,data:o})=>{const d=o?.map(l=>w(ke,l))??[];return e.jsxs(e.Fragment,{children:[e.jsx("tr",{className:"h-3"}),e.jsx(_e,{month:d[0].month,setInsertSalaryRecord:a}),e.jsx("tr",{className:"h-3"}),d.map(l=>e.jsx(rr,{data:l,setEditSalaryRecord:()=>t(l.employee?.id)},`${l.month} ${l.employee?.id}`))]})},sr=({setEditSalaryRecord:t,setInsertSalaryRecord:a,data:o})=>{const d=x.useMemo(()=>{const l=o?.map(n=>w(Me,n))??[],i=new Map;return l.map(n=>{const{month:c}=n,y=i.get(c)??[];i.set(c,[...y,n])}),i},[o]);return e.jsx("div",{className:"sm:px-6 w-full",children:e.jsxs("div",{className:"bg-white py-4 md:py-7 px-4 md:px-8 xl:px-10",children:[e.jsxs("div",{className:"sm:flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center",children:[e.jsx("div",{className:"rounded-full focus:outline-hidden focus:ring-2 focus:bg-indigo-50 focus:ring-indigo-800",children:e.jsx("div",{className:"py-2 px-8 bg-indigo-100 text-indigo-700 rounded-full",children:e.jsx("p",{children:"All"})})}),e.jsx("div",{className:"rounded-full focus:outline-hidden focus:ring-2 focus:bg-indigo-50 focus:ring-indigo-800 ml-4 sm:ml-8",children:e.jsx("div",{className:"py-2 px-8 text-gray-600 hover:text-indigo-700 hover:bg-indigo-100 rounded-full ",children:e.jsx("p",{children:"Done"})})}),e.jsx("div",{className:"rounded-full focus:outline-hidden focus:ring-2 focus:bg-indigo-50 focus:ring-indigo-800 ml-4 sm:ml-8",children:e.jsx("div",{className:"py-2 px-8 text-gray-600 hover:text-indigo-700 hover:bg-indigo-100 rounded-full ",children:e.jsx("p",{children:"Pending"})})})]}),e.jsx("button",{className:"focus:ring-2 focus:ring-offset-2 focus:ring-indigo-600 mt-4 sm:mt-0 inline-flex items-start justify-start px-6 py-3 bg-indigo-700 hover:bg-indigo-600 focus:outline-hidden rounded-sm",children:e.jsx("p",{className:"text-sm font-medium leading-none text-white",children:"Add Task"})})]}),e.jsx("div",{className:"mt-7 overflow-x-auto",children:e.jsx("table",{className:"w-full whitespace-nowrap",children:e.jsx("tbody",{children:Array.from(d).map(([l,i])=>e.jsx(ar,{data:i,setEditSalaryRecord:n=>t(n?{month:l,employeeId:n}:void 0),setInsertSalaryRecord:()=>a({month:l})},l))})})})]})})},tr=()=>{const{setFiltersContext:t}=x.useContext(Be),[a,o]=x.useState(void 0),[d,l]=x.useState(void 0),{get:i}=J(),[n,c]=x.useState(i("salariesFilters")?JSON.parse(decodeURIComponent(i("salariesFilters"))):{...L()}),[{data:y,fetching:j}]=D({query:Oe,variables:{...n}});return x.useEffect(()=>{t(e.jsxs("div",{className:"flex flex-row gap-x-5",children:[e.jsx(Qe,{filter:n,setFilter:c}),e.jsx(Y,{variant:"default",onClick:()=>l({})})]}))},[y,j,n,t,c]),e.jsxs(Le,{title:"Salaries",description:"View and manage salaries of employees.",children:[j?e.jsx(Ze,{className:"h-10 w-10 animate-spin mr-2 self-center"}):e.jsx(sr,{setEditSalaryRecord:o,setInsertSalaryRecord:l,data:y?.salaryRecordsByDates}),e.jsx(Ue,{recordVariables:a,onDone:()=>o(void 0)}),d&&e.jsx(Ge,{insertSalaryRecordParams:d,setInsertSalaryRecord:l})]})};export{tr as Salaries};
1
+ import{j as e,T as ae,B as U,ao as se,cd as ne,a as D,fw as te,r as x,ae as q,fx as le,fy as z,V,t as f,a0 as oe,fz as ie,db as G,bO as u,bP as k,a2 as de,fA as ce,a3 as me,a4 as ue,a5 as xe,v as ye,a7 as pe,bV as g,bQ as S,H as E,ab as ge,i as W,fB as he,l as _,fC as je,fD as J,e as fe,fE as ve,fF as be,u as Q,cZ as Ne,d0 as Se,c_ as Ee,c$ as we,ch as Fe,X as w,fG as Ce,fH as De,fI as Ie,fJ as Ae,fK as Pe,fL as Re,fM as Te,fN as ke,fO as Me,F as Be,c as Le,L as Ze,fP as Oe}from"./index-xIO0bA36.js";function Y(t){return e.jsx(ae,{disabled:!t.tooltip,label:t.tooltip,children:e.jsx(U,{variant:"ghost",size:"icon",className:"size-7.5",...t,children:e.jsx(se,{className:"size-5"})})})}const X=({isNewInsert:t=!0,defaultValues:a,month:o,onDone:d,isModifying:l})=>{const{selectableBusinesses:i,fetching:n}=ne(),[{data:c,fetching:y,error:j}]=D({query:te}),{userContext:v}=x.useContext(q),[{data:b,fetching:F,error:R}]=D({query:le}),[{data:I,fetching:M,error:C}]=D({query:z,variables:{employerId:v?.context.adminBusinessId??""}}),[p,N]=x.useState([]),[A,T]=x.useState([]),[K,ee]=x.useState([]),P=a?.month??o,Z=V({defaultValues:{...a,month:P}}),{control:m,handleSubmit:O,formState:{dirtyFields:$},setValue:B}=Z;x.useEffect(()=>{j&&f.error("Error",{description:"Oh no!, we have an error fetching pension funds! 🤥"})},[j]),x.useEffect(()=>{R&&f.error("Error",{description:"Oh no!, we have an error fetching training funds! 🤥"})},[R]),x.useEffect(()=>{C&&f.error("Error",{description:"Oh no!, we have an error employees! 🤥"})},[C]),x.useEffect(()=>{c?.allPensionFunds?.length&&N(c.allPensionFunds.map(r=>({value:r.id,label:r.name})).sort((r,s)=>r.label>s.label?1:-1))},[c,T]),x.useEffect(()=>{b?.allTrainingFunds?.length&&T(b.allTrainingFunds.map(r=>({value:r.id,label:r.name})).sort((r,s)=>r.label>s.label?1:-1))},[b,T]),x.useEffect(()=>{I?.employeesByEmployerId.length&&ee(I.employeesByEmployerId.filter(r=>!r.name.toLocaleLowerCase().includes("batched")).map(r=>({value:r.id,label:r.name})).sort((r,s)=>r.label>s.label?1:-1))},[I,T]),x.useEffect(()=>{!a?.employer&&v?.context.adminBusinessId&&B("employer",v.context.adminBusinessId,{shouldDirty:!0,shouldTouch:!0})},[B,a?.employer,v?.context.adminBusinessId]);const H=r=>{const s=ge(r,$);if(!(t&&(!s?.directPaymentAmount||!s?.employeeId||!s?.employer||!s?.month)))if(s&&Object.keys(s).length>0){if(!t){if(!a)return;s.employeeId??=a.employeeId,s.month??=a.month}d(s)}else d()};function re(r){B("month",E(r,"yyyy-MM-dd"),{shouldDirty:!0,shouldTouch:!0})}return e.jsx(oe,{...Z,children:e.jsxs("form",{onSubmit:O(H),children:[e.jsx("div",{className:"flex-row px-10 h-max justify-start block",children:e.jsxs(ie,{cols:4,children:[e.jsxs("div",{className:"flex-column h-max justify-start block",children:[e.jsx(G,{defaultDate:P?new Date(P):void 0,defaultValue:P?new Date(P):void 0,onChange:re,popoverProps:{withinPortal:!0}}),e.jsx(u,{name:"employer",control:m,defaultValue:a?.employer,rules:{required:"Required"},render:({field:r,fieldState:s})=>e.jsx(k,{...r,data:i,value:r.value,disabled:n,label:"Employer",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:s.error?.message})}),e.jsx(de,{name:"chargeId",control:m,defaultValue:a?.chargeId,rules:{pattern:{value:ce,message:"Invalid UUID"}},render:({field:r})=>e.jsxs(me,{children:[e.jsx(ue,{children:"Charge ID"}),e.jsx(xe,{children:e.jsx(ye,{...r,value:r.value??void 0})}),e.jsx(pe,{})]})}),e.jsx(u,{name:"employeeId",control:m,defaultValue:a?.employeeId,rules:{required:"Required"},render:({field:r,fieldState:s})=>e.jsx(k,{...r,data:K,value:r.value,disabled:M,label:"Employee",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:s.error?.message})})]}),e.jsxs("div",{className:"flex-row px-10 h-max justify-start block",children:[e.jsx(u,{name:"baseSalary",control:m,defaultValue:a?.baseSalary,render:({field:r,fieldState:s})=>e.jsx(g,{...r,value:r.value??void 0,error:s.error?.message,label:"Base Salary",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"globalAdditionalHours",control:m,defaultValue:a?.globalAdditionalHours,render:({field:r,fieldState:s})=>e.jsx(g,{...r,value:r.value??void 0,error:s.error?.message,label:"Global Additional Hours",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"bonus",control:m,defaultValue:a?.bonus,render:({field:r,fieldState:s})=>e.jsx(g,{...r,value:r.value??void 0,error:s.error?.message,label:"Bonus",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"gift",control:m,defaultValue:a?.gift,render:({field:r,fieldState:s})=>e.jsx(g,{...r,value:r.value??void 0,error:s.error?.message,label:"Gift",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"travelAndSubsistence",control:m,defaultValue:a?.travelAndSubsistence,render:({field:r,fieldState:s})=>e.jsx(g,{...r,value:r.value??void 0,error:s.error?.message,label:"Travel and Subsistence",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"recovery",control:m,defaultValue:a?.recovery,render:({field:r,fieldState:s})=>e.jsx(g,{...r,value:r.value??void 0,error:s.error?.message,label:"Recovery",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency"}})}),e.jsx(u,{name:"vacationTakeout",control:m,defaultValue:a?.vacationTakeout,render:({field:r,fieldState:s})=>e.jsx(g,{...r,value:r.value??void 0,error:s.error?.message,label:"Vacation Takeout",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"directPaymentAmount",control:m,defaultValue:a?.directPaymentAmount,rules:{required:"Required"},render:({field:r,fieldState:s})=>e.jsx(g,{...r,value:r.value??void 0,error:s.error?.message,label:"Direct Payment",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})})]}),e.jsxs("div",{className:"flex-row px-10 h-max justify-start block",children:[e.jsx(u,{name:"pensionFundId",control:m,defaultValue:a?.pensionFundId,render:({field:r,fieldState:s})=>e.jsx(k,{...r,data:p,value:r.value,disabled:y,label:"Pension Fund",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:s.error?.message})}),e.jsx(u,{name:"pensionEmployeeAmount",control:m,defaultValue:a?.pensionEmployeeAmount,render:({field:r,fieldState:s})=>e.jsx(g,{...r,value:r.value??void 0,error:s.error?.message,label:"Pension Employee Amount",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"pensionEmployeePercentage",control:m,defaultValue:a?.pensionEmployeePercentage,render:({field:{value:r,...s},fieldState:h})=>e.jsx(S,{...s,hideControls:!0,precision:2,removeTrailingZeros:!0,rightSection:"%",value:r??void 0,error:h.error?.message,label:"Pension Employee Percentage"})}),e.jsx(u,{name:"pensionEmployerAmount",control:m,defaultValue:a?.pensionEmployerAmount,render:({field:r,fieldState:s})=>e.jsx(g,{...r,value:r.value??void 0,error:s.error?.message,label:"Pension Employer Amount",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"pensionEmployerPercentage",control:m,defaultValue:a?.pensionEmployerPercentage,render:({field:{value:r,...s},fieldState:h})=>e.jsx(S,{...s,hideControls:!0,precision:2,removeTrailingZeros:!0,rightSection:"%",value:r??void 0,error:h.error?.message,label:"Pension Employer Percentage"})})]}),e.jsxs("div",{className:"flex-row px-10 h-max justify-start block",children:[e.jsx(u,{name:"compensationsEmployerAmount",control:m,defaultValue:a?.compensationsEmployerAmount,render:({field:r,fieldState:s})=>e.jsx(g,{...r,value:r.value??void 0,error:s.error?.message,label:"Compensations Amount",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"compensationsEmployerPercentage",control:m,defaultValue:a?.compensationsEmployerPercentage,render:({field:{value:r,...s},fieldState:h})=>e.jsx(S,{...s,hideControls:!0,precision:2,removeTrailingZeros:!0,rightSection:"%",value:r??void 0,error:h.error?.message,label:"Compensations Percentage"})})]}),e.jsxs("div",{className:"flex-row px-10 h-max justify-start block",children:[e.jsx(u,{name:"trainingFundId",control:m,defaultValue:a?.trainingFundId,render:({field:r,fieldState:s})=>e.jsx(k,{...r,data:A,value:r.value,disabled:F,label:"Training Fund",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:s.error?.message})}),e.jsx(u,{name:"trainingFundEmployeeAmount",control:m,defaultValue:a?.trainingFundEmployeeAmount,render:({field:r,fieldState:s})=>e.jsx(g,{...r,value:r.value??void 0,error:s.error?.message,label:"Training Employee Amount",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"trainingFundEmployeePercentage",control:m,defaultValue:a?.trainingFundEmployeePercentage,render:({field:{value:r,...s},fieldState:h})=>e.jsx(S,{...s,hideControls:!0,precision:2,removeTrailingZeros:!0,rightSection:"%",value:r??void 0,error:h.error?.message,label:"Training Employee Percentage"})}),e.jsx(u,{name:"trainingFundEmployerAmount",control:m,defaultValue:a?.trainingFundEmployerAmount,render:({field:r,fieldState:s})=>e.jsx(g,{...r,value:r.value??void 0,error:s.error?.message,label:"Training Employer Amount",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"trainingFundEmployerPercentage",control:m,defaultValue:a?.trainingFundEmployerPercentage,render:({field:{value:r,...s},fieldState:h})=>e.jsx(S,{...s,hideControls:!0,precision:2,removeTrailingZeros:!0,rightSection:"%",value:r??void 0,error:h.error?.message,label:"Training Employer Percentage"})})]}),e.jsxs("div",{className:"flex-row px-10 h-max justify-start block",children:[e.jsx(u,{name:"socialSecurityAmountEmployee",control:m,defaultValue:a?.socialSecurityAmountEmployee,render:({field:r,fieldState:s})=>e.jsx(g,{...r,value:r.value??void 0,error:s.error?.message,label:"Social Security - Employee",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"socialSecurityAmountEmployer",control:m,defaultValue:a?.socialSecurityAmountEmployer,render:({field:r,fieldState:s})=>e.jsx(g,{...r,value:r.value??void 0,error:s.error?.message,label:"Social Security - Employer",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"healthPaymentAmount",control:m,defaultValue:a?.healthPaymentAmount,render:({field:r,fieldState:s})=>e.jsx(g,{...r,value:r.value??void 0,error:s.error?.message,label:"Health Insurance",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})})]}),e.jsxs("div",{className:"flex-row px-10 h-max justify-start block",children:[e.jsx(u,{name:"taxAmount",control:m,defaultValue:a?.taxAmount,render:({field:r,fieldState:s})=>e.jsx(g,{...r,value:r.value??void 0,error:s.error?.message,label:"Income Tax",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"zkufot",control:m,defaultValue:a?.zkufot,render:({field:r,fieldState:s})=>e.jsx(g,{...r,value:r.value??void 0,error:s.error?.message,precision:0,label:"Notional Expense",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})})]}),e.jsxs("div",{className:"flex-row px-10 h-max justify-start block",children:[e.jsx(u,{name:"workDays",control:m,defaultValue:a?.workDays,render:({field:{value:r,...s},fieldState:h})=>e.jsx(S,{...s,hideControls:!0,precision:2,removeTrailingZeros:!0,value:r??void 0,error:h.error?.message,label:"Work Days"})}),e.jsx(u,{name:"addedVacationDays",control:m,defaultValue:a?.addedVacationDays,render:({field:{value:r,...s},fieldState:h})=>e.jsx(S,{...s,hideControls:!0,precision:2,removeTrailingZeros:!0,value:r??void 0,error:h.error?.message,label:"Added Vacation Days"})}),e.jsx(u,{name:"vacationDaysBalance",control:m,defaultValue:a?.vacationDaysBalance,render:({field:{value:r,...s},fieldState:h})=>e.jsx(S,{...s,hideControls:!0,precision:2,removeTrailingZeros:!0,value:r??void 0,error:h.error?.message,label:"Vacation Days Balance"})}),e.jsx(u,{name:"sicknessDaysBalance",control:m,defaultValue:a?.sicknessDaysBalance,render:({field:{value:r,...s},fieldState:h})=>e.jsx(S,{...s,hideControls:!0,precision:2,removeTrailingZeros:!0,value:r??void 0,error:h.error?.message,label:"Sickness Days Balance"})})]})]})}),e.jsxs("div",{className:"mt-10 mb-5 flex justify-center gap-5",children:[e.jsx("button",{type:"submit",onClick:()=>O(H),className:"mt-8 text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg",disabled:l||Object.keys($).length===0,children:"Accept"}),e.jsx("button",{type:"button",className:"mt-8 text-white bg-rose-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-rose-600 rounded-sm text-lg",onClick:()=>d(),children:"Cancel"})]})]})})},$e="updateSalaryRecord",He=()=>{const[{fetching:t},a]=W(he),o=x.useCallback(async d=>{const l=`Error updating salary record [${d.salaryRecord.month}] employee [${d.salaryRecord.employeeId}]`,i=$e;f.loading("Updating Salary Record",{id:i});try{const n=await a(d),c=_(n,l,i,"updateSalaryRecord");if(c)return f.success("Success",{id:i,description:"Salary record was updated"}),c.updateSalaryRecord.salaryRecord}catch(n){console.error(`${l}: ${n}`),f.error("Error",{id:i,description:l,duration:1e5,closeButton:!0})}},[a]);return{fetching:t,updateSalaryRecord:o}},Ue=({recordVariables:t,onDone:a})=>t?e.jsx(qe,{recordVariables:t,onDone:a}):null,qe=({recordVariables:t,onDone:a})=>{const{updateSalaryRecord:o,fetching:d}=He(),[{data:l,fetching:i}]=D({query:je,variables:{employeeIDs:[t.employeeId],month:E(new Date(t.month),"yyyy-MM-dd")}}),n=l?.salaryRecordsByDates?.[0],c=x.useCallback(j=>{a(),j&&o({salaryRecord:j})},[a,o]);if(!n?.employer?.id||!n?.employee?.id)return e.jsx(e.Fragment,{});const y={addedVacationDays:n?.vacationDays?.added,baseSalary:n?.baseAmount?.raw,bonus:n?.bonus?.raw,chargeId:n?.charge?.id,compensationsEmployerAmount:n?.compensationsAmount?.raw,compensationsEmployerPercentage:n?.compensationsPercentage,directPaymentAmount:n?.directAmount?.raw,employer:n.employer.id,employeeId:n.employee.id,gift:n?.gift?.raw,globalAdditionalHours:n?.globalAdditionalHoursAmount?.raw,healthPaymentAmount:n?.healthInsuranceAmount?.raw,month:n?.month,pensionEmployeeAmount:n?.pensionEmployeeAmount?.raw,pensionEmployeePercentage:n?.pensionEmployeePercentage,pensionEmployerAmount:n?.pensionEmployerAmount?.raw,pensionEmployerPercentage:n?.pensionEmployerPercentage,pensionFundId:n?.pensionFund?.id,recovery:n?.recovery?.raw,sicknessDaysBalance:n?.sicknessDays?.balance,socialSecurityAmountEmployee:n?.socialSecurityEmployeeAmount?.raw,socialSecurityAmountEmployer:n?.socialSecurityEmployerAmount?.raw,taxAmount:n?.incomeTaxAmount?.raw,trainingFundEmployeeAmount:n?.trainingFundEmployeeAmount?.raw,trainingFundEmployeePercentage:n?.trainingFundEmployeePercentage,trainingFundEmployerAmount:n?.trainingFundEmployerAmount?.raw,trainingFundEmployerPercentage:n?.trainingFundEmployerPercentage,trainingFundId:n?.trainingFund?.id,travelAndSubsistence:n?.travelAndSubsistence?.raw,vacationDaysBalance:n?.vacationDays?.balance,vacationTakeout:n?.vacationTakeout?.raw,workDays:n?.workDays,zkufot:n?.notionalExpense?.raw};return e.jsx(J,{modalSize:"fit-content",position:"bottom",title:e.jsxs("div",{className:"flex flex-row mx-3 pt-3 sm:text-1xl gap-10",children:[e.jsx("h1",{className:"sm:text-2xl font-small text-gray-900",children:"Edit Salary Record:"}),e.jsxs("div",{className:"flex flex-row gap-2",children:["month: ",t.month," employeeId: ",t.employeeId]})]}),opened:!!t,onClose:a,children:i||!n?e.jsx(fe,{className:"flex self-center my-5",color:"dark",size:"xl",variant:"dots"}):e.jsx(X,{isNewInsert:!1,defaultValues:y,onDone:c,isModifying:d})})},ze="insertSalaryRecords",Ve=()=>{const[{fetching:t},a]=W(ve),o=x.useCallback(async d=>{const l=ze;if(f.loading("Adding salary record",{id:l}),!d.salaryRecords||Array.isArray(d.salaryRecords)&&d.salaryRecords.length===0){f.error("Error",{id:l,description:"No salary records to insert",duration:1e5,closeButton:!0});return}const i=Array.isArray(d.salaryRecords)?d.salaryRecords[0]:d.salaryRecords;if(!i?.directPaymentAmount||!i?.employeeId||!i?.employer||!i?.month){f.error("Error",{id:l,description:"Missing required salary record fields",duration:1e5,closeButton:!0});return}const n=`Error adding salary record [${i.month}] employee [${i.employeeId}]`;try{const c=await a(d),y=_(c,n,l,"insertSalaryRecords");if(y)return f.success("Success",{id:l,description:"Salary record was added"}),y.insertSalaryRecords.salaryRecords[0]}catch(c){console.error(`${n}: ${c}`),f.error("Error",{id:l,description:n,duration:1e5,closeButton:!0})}},[a]);return{fetching:t,insertSalaryRecord:o}},Ge=({insertSalaryRecordParams:t,setInsertSalaryRecord:a})=>{const{insertSalaryRecord:o,fetching:d}=Ve(),l=x.useCallback(i=>{i&&o({salaryRecords:[i]}),a(void 0)},[a,o]);return e.jsx(J,{modalSize:"40%",position:"bottom",title:e.jsx("div",{className:"flex flex-row mx-3 pt-3 sm:text-1xl gap-10",children:e.jsx("h1",{className:"sm:text-2xl font-small text-gray-900",children:"Insert Salary Record:"})}),opened:!!t,onClose:()=>a(void 0),children:e.jsx(X,{isNewInsert:!0,onDone:l,isModifying:d,month:t.month})})};function L(){const t=new Date,a=E(t,"yyyy-MM-dd"),o=E(be(t),"yyyy-MM-dd");return{fromDate:a,toDate:o}}function We({filter:t,setFilter:a,closeModal:o}){const{control:d,handleSubmit:l,setValue:i}=V({defaultValues:{...t}}),[n,c]=x.useState([]),{userContext:y}=x.useContext(q),[{data:j,fetching:v,error:b},F]=D({query:z,variables:{employerId:y?.context.adminBusinessId??""},pause:!0});x.useEffect(()=>{F()},[y?.context.adminBusinessId,F]),x.useEffect(()=>{b&&f.error("Error",{description:"Oh no!, we have an error fetching employees! 🤥"})},[b]);const R=p=>{p.employeeIDs?.length===0&&delete p.employeeIDs,a(p),o()};function I(){a({...L()}),o()}x.useEffect(()=>{j?.employeesByEmployerId.length&&c(j.employeesByEmployerId.filter(p=>!p.name.toLocaleLowerCase().includes("batched")).map(p=>({value:p.id,label:p.name})).sort((p,N)=>p.label>N.label?1:-1))},[j,c]);function M([p,N]){if(N){const A=new Date(N.getFullYear(),N.getMonth()+1,0);i("toDate",E(A,"yyyy-MM-dd"))}if(p){const A=new Date(p.getFullYear(),p.getMonth(),1);i("fromDate",E(A,"yyyy-MM-dd"))}}const C=L();return e.jsxs(e.Fragment,{children:[v?e.jsx("div",{children:"Loading..."}):e.jsx("div",{}),e.jsxs("form",{onSubmit:l(R),children:[e.jsx(G,{type:"range",numberOfColumns:2,defaultValue:[new Date(t?.fromDate??C.fromDate),new Date(t?.toDate??C.toDate)],defaultDate:new Date(t?.fromDate??C.fromDate),onChange:M,popoverProps:{withinPortal:!0}}),e.jsx(u,{name:"employeeIDs",control:d,defaultValue:t.employeeIDs,render:({field:p,fieldState:N})=>e.jsx(Fe,{...p,data:n,value:p.value??[],disabled:v,label:"Employees",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:N.error?.message})}),e.jsxs("div",{className:"flex justify-center mt-5 gap-3",children:[e.jsx("button",{type:"submit",disabled:v,className:"text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg",children:"Filter"}),e.jsx("button",{type:"button",className:"text-white bg-orange-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-orange-600 rounded-sm text-lg",onClick:I,children:"Clear"}),e.jsx("button",{type:"button",className:"text-white bg-rose-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-rose-600 rounded-sm text-lg",onClick:o,children:"Cancel"})]})]})]})}function _e({filter:t,setFilter:a}){const[o,d]=x.useState(!1),{get:l,set:i}=Q();x.useEffect(()=>{const c=Ne(t)?null:encodeURIComponent(JSON.stringify(t)),y=l("salariesFilters");c!==y&&i("salariesFilters",c)},[t,l,i]);const n=x.useCallback(c=>{Se(c,t)||a(c)},[t,a]);return e.jsxs("div",{className:"flex flex-row gap-5 items-center",children:[e.jsx(Ee,{opened:o,onClose:()=>d(!1),content:e.jsx(We,{filter:t,setFilter:n,closeModal:()=>d(!1)}),modalSize:"xl"}),e.jsx(U,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>d(!0),children:e.jsx(we,{className:"size-5"})})]})}const Je=({month:t,setInsertSalaryRecord:a})=>{const o=E(new Date(t),"MMMM yyyy");return e.jsx("tr",{tabIndex:0,className:"h-16 rounded-sm",children:e.jsx("td",{colSpan:100,children:e.jsxs("div",{className:"flex justify-between pl-5",children:[e.jsx("p",{className:"text-lg font-bold text-gray-800",children:o}),e.jsx("div",{className:"flex items-center",children:e.jsx("div",{className:"flex flex-col",children:e.jsx(Y,{onClick:a})})})]})})})},Qe=({data:t})=>{const{employee:a,month:o}=w(Ce,t),d=E(new Date(o),"MMMM yyyy");return e.jsx("td",{className:"",children:e.jsx("div",{className:"flex items-center pl-5",children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("p",{className:"text-base font-bold text-gray-800",children:a?.name}),e.jsx("p",{className:"text-base font-medium text-gray-800",children:d})]})})})},Ye=({data:t})=>{const{pensionEmployeeAmount:a,pensionEmployeePercentage:o,pensionEmployerAmount:d,pensionEmployerPercentage:l,compensationsAmount:i,compensationsPercentage:n,pensionFund:c,trainingFund:y,trainingFundEmployeeAmount:j,trainingFundEmployeePercentage:v,trainingFundEmployerAmount:b,trainingFundEmployerPercentage:F}=w(De,t);return e.jsx("td",{className:"pl-5",children:e.jsx("div",{className:"flex items-center",children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("p",{className:"text-md font-bold text-gray-800",children:"Pension Fund"}),e.jsx("p",{className:"text-md font-medium text-gray-800",children:c?.name}),!!a?.raw&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Employee Part:"}),e.jsxs("p",{className:"text-sm leading-none text-gray-600 ml-2",children:[a?.formatted,o&&` (${o}%)`]})]}),!!d?.raw&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Employer Part:"}),e.jsxs("p",{className:"text-sm leading-none text-gray-600 ml-2",children:[d?.formatted,l&&` (${l}%)`]})]}),!!i?.raw&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Compensations Amount:"}),e.jsxs("p",{className:"text-sm leading-none text-gray-600 ml-2",children:[i?.formatted,n&&` (${n}%)`]})]}),e.jsx("p",{className:"text-md font-bold text-gray-800 mt-2",children:"Training Fund"}),e.jsx("p",{className:"text-md font-medium text-gray-800",children:y?.name}),!!j?.raw&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Employee Part:"}),e.jsxs("p",{className:"text-sm leading-none text-gray-600 ml-2",children:[j?.formatted,v&&` (${v}%)`]})]}),!!b?.raw&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Employer Part:"}),e.jsxs("p",{className:"text-sm leading-none text-gray-600 ml-2",children:[b?.formatted,F&&` (${F}%)`]})]})]})})})},Xe=({data:t})=>{const{healthInsuranceAmount:a,socialSecurityEmployeeAmount:o,socialSecurityEmployerAmount:d,incomeTaxAmount:l,notionalExpense:i}=w(Ie,t),n=!!o||!!d;return e.jsx("td",{className:"pl-5",children:e.jsx("div",{className:"flex items-center pl-5",children:e.jsxs("div",{className:"flex flex-col",children:[n&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-md font-bold text-gray-800",children:"Social Security"}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Employee Part:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:o?.formatted})]}),e.jsx("p",{className:"text-md font-bold text-gray-800 mt-2",children:"Pension Fund"}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Employer Part:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:d?.formatted})]})]}),!!a?.raw&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-md font-bold text-gray-800 mt-2",children:"Health Insurance"}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Amount:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:a?.formatted})]})]}),(!!l?.raw||!!i?.raw)&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-md font-bold text-gray-800 mt-2",children:"Taxes"}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Income Tax:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:l?.formatted})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Notional Expense:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:i?.formatted})]})]})]})})})},Ke=({data:t})=>{const{baseAmount:a,directAmount:o,globalAdditionalHoursAmount:d,bonus:l,gift:i,recovery:n,vacationTakeout:c}=w(Ae,t);return e.jsx("td",{className:"pl-24",children:e.jsx("div",{className:"flex items-center",children:e.jsxs("div",{className:"flex flex-col",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Base Amount:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:a?.formatted})]}),e.jsxs("div",{className:"flex justify-between mb-2",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Global Extra Hours:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:d?.formatted})]}),!!l?.raw&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Bonus:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:l?.formatted})]}),!!i?.raw&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Gift:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:i?.formatted})]}),!!n?.raw&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Recovery:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:n?.formatted})]}),!!c?.raw&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Vacation Takeout:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:c?.formatted})]}),e.jsxs("div",{className:"flex justify-between mt-2",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Direct Amount:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:o?.formatted})]})]})})})},er=({data:t})=>{const{vacationDays:a,workDays:o,sicknessDays:d}=w(Pe,t),{added:l,taken:i,balance:n}=a??{},{balance:c}=d??{},y=!!l||!!i||!!n;return e.jsx("td",{className:"pl-5",children:e.jsx("div",{className:"flex items-center",children:e.jsxs("div",{className:"flex flex-col",children:[!!o&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-md leading-none text-gray-800",children:"Work Days:"}),e.jsx("div",{className:"flex justify-between",children:e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:o})})]}),y&&e.jsxs("div",{className:"flex flex-col",children:[e.jsx("p",{className:"text-md leading-none text-gray-800 mt-2",children:"Vacation Days:"}),!!l&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Added:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:l})]}),!!i&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Taken:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:i})]}),!!n&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Balance:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:n})]})]}),!!c&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-md leading-none text-gray-800 mt-2",children:"Sickness Days:"}),e.jsx("div",{className:"flex justify-between",children:e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:c})})]})]})})})},rr=({setEditSalaryRecord:t,data:a})=>{const o=w(Te,a);return e.jsxs(e.Fragment,{children:[e.jsxs("tr",{tabIndex:0,className:"h-16 border border-gray-100 hover:bg-gray-100 rounded-sm",children:[e.jsx(Qe,{data:o}),e.jsx(Ke,{data:o}),e.jsx(Ye,{data:o}),e.jsx(Xe,{data:o}),e.jsx(er,{data:o}),e.jsx("td",{className:"pl-2",children:e.jsx("div",{className:"flex items-center",children:e.jsx("div",{className:"flex flex-col",children:e.jsx(Re,{onClick:t})})})})]}),e.jsx("tr",{className:"h-3"})]})},ar=({setEditSalaryRecord:t,setInsertSalaryRecord:a,data:o})=>{const d=o?.map(l=>w(ke,l))??[];return e.jsxs(e.Fragment,{children:[e.jsx("tr",{className:"h-3"}),e.jsx(Je,{month:d[0].month,setInsertSalaryRecord:a}),e.jsx("tr",{className:"h-3"}),d.map(l=>e.jsx(rr,{data:l,setEditSalaryRecord:()=>t(l.employee?.id)},`${l.month} ${l.employee?.id}`))]})},sr=({setEditSalaryRecord:t,setInsertSalaryRecord:a,data:o})=>{const d=x.useMemo(()=>{const l=o?.map(n=>w(Me,n))??[],i=new Map;return l.map(n=>{const{month:c}=n,y=i.get(c)??[];i.set(c,[...y,n])}),i},[o]);return e.jsx("div",{className:"sm:px-6 w-full",children:e.jsxs("div",{className:"bg-white py-4 md:py-7 px-4 md:px-8 xl:px-10",children:[e.jsxs("div",{className:"sm:flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center",children:[e.jsx("div",{className:"rounded-full focus:outline-hidden focus:ring-2 focus:bg-indigo-50 focus:ring-indigo-800",children:e.jsx("div",{className:"py-2 px-8 bg-indigo-100 text-indigo-700 rounded-full",children:e.jsx("p",{children:"All"})})}),e.jsx("div",{className:"rounded-full focus:outline-hidden focus:ring-2 focus:bg-indigo-50 focus:ring-indigo-800 ml-4 sm:ml-8",children:e.jsx("div",{className:"py-2 px-8 text-gray-600 hover:text-indigo-700 hover:bg-indigo-100 rounded-full ",children:e.jsx("p",{children:"Done"})})}),e.jsx("div",{className:"rounded-full focus:outline-hidden focus:ring-2 focus:bg-indigo-50 focus:ring-indigo-800 ml-4 sm:ml-8",children:e.jsx("div",{className:"py-2 px-8 text-gray-600 hover:text-indigo-700 hover:bg-indigo-100 rounded-full ",children:e.jsx("p",{children:"Pending"})})})]}),e.jsx("button",{className:"focus:ring-2 focus:ring-offset-2 focus:ring-indigo-600 mt-4 sm:mt-0 inline-flex items-start justify-start px-6 py-3 bg-indigo-700 hover:bg-indigo-600 focus:outline-hidden rounded-sm",children:e.jsx("p",{className:"text-sm font-medium leading-none text-white",children:"Add Task"})})]}),e.jsx("div",{className:"mt-7 overflow-x-auto",children:e.jsx("table",{className:"w-full whitespace-nowrap",children:e.jsx("tbody",{children:Array.from(d).map(([l,i])=>e.jsx(ar,{data:i,setEditSalaryRecord:n=>t(n?{month:l,employeeId:n}:void 0),setInsertSalaryRecord:()=>a({month:l})},l))})})})]})})},tr=()=>{const{setFiltersContext:t}=x.useContext(Be),[a,o]=x.useState(void 0),[d,l]=x.useState(void 0),{get:i}=Q(),[n,c]=x.useState(i("salariesFilters")?JSON.parse(decodeURIComponent(i("salariesFilters"))):{...L()}),[{data:y,fetching:j}]=D({query:Oe,variables:{...n}});return x.useEffect(()=>{t(e.jsxs("div",{className:"flex flex-row gap-x-5",children:[e.jsx(_e,{filter:n,setFilter:c}),e.jsx(Y,{variant:"default",onClick:()=>l({})})]}))},[y,j,n,t,c]),e.jsxs(Le,{title:"Salaries",description:"View and manage salaries of employees.",children:[j?e.jsx(Ze,{className:"h-10 w-10 animate-spin mr-2 self-center"}):e.jsx(sr,{setEditSalaryRecord:o,setInsertSalaryRecord:l,data:y?.salaryRecordsByDates}),e.jsx(Ue,{recordVariables:a,onDone:()=>o(void 0)}),d&&e.jsx(Ge,{insertSalaryRecordParams:d,setInsertSalaryRecord:l})]})};export{tr as Salaries};
@@ -1,6 +1,6 @@
1
- import{D as U,r as b,ce as W,j as e,K as z,aW as X,B as g,d0 as R,N as G,aX as Q,aY as Z,bg as T,at as K,b5 as A,au as O,av as k,aw as E,ax as M,az as D,cT as J,X as j,bo as w,eS as I,eT as ee,eU as S,eV as se,eW as L,eX as B,eY as P,eZ as N,e_ as p,e$ as Y,f0 as V,dO as re,f1 as te,bj as ae,bk as le,bl as v,f2 as $,F as de,a as ne,Y as oe,Z as ce,a2 as ie,f3 as ue}from"./index-C1vFqfE7.js";import{B as me}from"./building-2-DqnthsV_.js";import{S as xe}from"./save-DQHS5I6h.js";/**
1
+ import{D as U,r as b,cd as W,j as e,K as z,an as G,B as g,c$ as R,N as Q,ap as X,aq as Z,bf as T,aM as K,b5 as A,au as k,av as O,aw as M,ax as E,ay as D,cS as J,X as j,bn as w,eR as I,eS as ee,eT as S,eU as se,eV as L,eW as B,eX as P,eY as N,eZ as p,e_ as Y,e$ as $,dN as re,f0 as te,bi as ae,bj as le,bk as v,f1 as V,F as de,a as ne,Y as oe,Z as ce,a1 as ie,f2 as ue}from"./index-xIO0bA36.js";import{B as me}from"./building-2-HRA8xsoA.js";import{S as xe}from"./save-BPUtJeTy.js";/**
2
2
  * @license lucide-react v0.546.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
5
5
  * See the LICENSE file in the root directory of this source tree.
6
- */const he=[["path",{d:"M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49",key:"ct8e1f"}],["path",{d:"M14.084 14.158a3 3 0 0 1-4.242-4.242",key:"151rxh"}],["path",{d:"M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143",key:"13bj9a"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]],be=U("eye-off",he),C=["2020","2021","2022","2023"];function je({selectedBusiness:t,setSelectedBusiness:d,selectedYear:s,setSelectedYear:c,referenceYear:l,setReferenceYear:o}){const[n,r]=b.useState(!s||!t),{selectableBusinesses:a,fetching:i}=W(),h=b.useMemo(()=>t?a.find(f=>f.value===t)?.label??"":"",[a,t]);return e.jsxs(z,{open:n,onOpenChange:r,children:[e.jsx(X,{asChild:!0,children:e.jsxs(g,{variant:"outline",className:"flex items-center gap-2",children:[e.jsx(R,{className:"h-4 w-4"}),"מסננים",e.jsxs("span",{className:"text-xs bg-blue-100 text-blue-800 px-2 py-0.5 rounded-full",children:[h," • ",s]})]})}),e.jsxs(G,{className:"sm:max-w-md",dir:"rtl",children:[e.jsx(Q,{children:e.jsxs(Z,{className:"flex items-center gap-2",children:[e.jsx(R,{className:"h-5 w-5"}),"מסנני דוח"]})}),e.jsxs("div",{className:"space-y-6 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(T,{htmlFor:"business-select",className:"flex items-center gap-2",children:[e.jsx(me,{className:"h-4 w-4"}),"בחירת עסק"]}),e.jsx(K,{onChange:x=>d(x??void 0),data:a,value:t,disabled:i,placeholder:"Scroll to see all options",triggerProps:{className:"w-full"}})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(T,{htmlFor:"year-select",className:"flex items-center gap-2",children:[e.jsx(A,{className:"h-4 w-4"}),"שנת דיווח"]}),e.jsxs(O,{value:s,onValueChange:c,children:[e.jsx(k,{id:"year-select",children:e.jsx(E,{})}),e.jsx(M,{children:C.map(x=>e.jsx(D,{value:x,children:x},x))})]}),e.jsxs("p",{className:"text-xs text-gray-500",children:["זמינות נתונים: ",C.join(", ")]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(T,{htmlFor:"reference-year-select",className:"flex items-center gap-2",children:[e.jsx(A,{className:"h-4 w-4"}),"שנת השוואה"]}),e.jsxs(O,{value:l,onValueChange:x=>o(x==="none"?void 0:x),children:[e.jsx(k,{id:"reference-year-select",children:e.jsx(E,{})}),e.jsxs(M,{children:[e.jsx(D,{value:"none",children:"ללא"},"none"),C.map(x=>e.jsx(D,{value:x,children:x},x))]})]}),e.jsxs("p",{className:"text-xs text-gray-500",children:["זמינות נתונים: ",C.join(", ")]})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[e.jsx(g,{variant:"outline",onClick:()=>r(!1),children:"ביטול"}),e.jsx(g,{onClick:()=>r(!1),children:"אישור"})]})]})]})]})}const u=({label:t,value:d,code:s,referenceValue:c,showEmptyFields:l,showChange:o=!1})=>{const n=h=>l?!0:!r(h),r=h=>!h||h.trim()===""||h==="0"||h==="0.00",a=(h,x)=>{if(!x)return null;const f=q=>Number.parseFloat(q.replace(/[,\s₪]/g,""))||0,H=f(h),F=f(x);return F===0?null:(H-F)/F*100};if(!n(d))return null;const i=o?a(d,c):null;return e.jsxs("div",{className:"flex justify-between items-center py-2 border-b border-gray-200",dir:"rtl",children:[e.jsxs("span",{className:"text-sm text-gray-600",children:[t," ",s&&`(${s})`]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`font-medium ${r(d)?"text-gray-400":""}`,children:r(d)?"0":d}),i!==null&&e.jsxs("span",{className:`text-xs px-1 py-0.5 rounded ${i>0?"text-green-700 bg-green-100":i<0?"text-red-700 bg-red-100":"text-gray-700 bg-gray-100"}`,children:[i>0?"+":"",i.toFixed(1),"%"]})]})]})},m=({codes:t,referenceCodes:d,code:s,showEmptyFields:c})=>{const{value:l,label:o}=b.useMemo(()=>{const r=t.find(a=>a.code===s);return{value:r?.amount||0,label:r?.label||"לא זוהה קוד"}},[t,s]),n=b.useMemo(()=>d?.find(r=>r.code===s)?.amount.toString()||"",[d,s]);return e.jsx(u,{label:o,value:J(l,0),code:String(s),showChange:!0,showEmptyFields:c,referenceValue:n})},pe=[{title:"מזומנים ושווי מזומנים",codes:[7110,7120,7150],sumCode:7100},{title:"ניירות ערך",codes:[7215,7225,7230,7290,7295],sumCode:7200},{title:"לקוחות",codes:[7310,7320,7330,7350,7360,7380,7390],sumCode:7300},{title:"חייבים ויתרות חובה",codes:[7410,7420,7430,7440,7450,7461,7462,7470,7490],sumCode:7400},{title:"מסים נדחים לזמן קצר",codes:[7610,7620,7690],sumCode:7600},{title:"הלוואות לזמן קצר",codes:[7711,7712,7720],sumCode:7700},{title:"מלאי",codes:[7805,7810,7815,7820,7825,7830,7840,7850,7860,7870,7890],sumCode:7800}],ge=[{title:"רכוש קבוע",codes:[8010,8020,8025,8030,8040,8050,8060,8080,8090,8095,8100,8105,8110,8120,8130,8140,8150,8160,8170,8180,8190],sumCode:8e3},{title:"נכסים לא שוטפים מוחזקים למכירה",codes:[8710],sumCode:8700},{title:"הוצאות מראש לזמן ארוך",codes:[8210,8220,8290],sumCode:8200},{title:"השקעות בחברות מוחזקות כלולות ומאוחדות",codes:[8315,8325,8335,8340,8350],sumCode:8300},{title:'השקעות בחברות אחרות כולל ני"ע סחירים מוחזקים לזמן ארוך',codes:[8410,8420,8440,8450,8460,8490],sumCode:8400},{title:"מסים נדחים לזמן ארוך",codes:[8510,8520,8590],sumCode:8500},{title:"הוצאות נדחות ורכוש אחר",codes:[8610,8620,8630,8640,8690],sumCode:8600}],fe=[{title:"בנקים והלואות לזמן קצר",codes:[9110,9120,9130,9140,9151,9152,9190],sumCode:9100},{title:"ספקים ונותני שירותים",codes:[9210,9220,9230,9290],sumCode:9200},{title:"זכאים ויתרות זכות",codes:[9310,9320,9330,9340,9350,9360,9370,9410,9420,9431,9432,9435,9440,9450,9460,9470,9480,9490],sumCode:9400},{title:"עתודה למסים נדחים לזמן קצר",codes:[9510,9520,9530],sumCode:9500}],Ne=[{title:"התחייבויות לזמן ארוך",codes:[9605,9610,9620,9631,9632,9640,9650,9660,9670,9690],sumCode:9600},{title:"התחייבויות בשל סיום יחסי עובד-מעביד",codes:[9710,9720,9790],sumCode:9700},{title:"עתודה למסים נדחים לזמן ארוך",codes:[9810,9820,9890],sumCode:9800}],ve=[{title:"הון עצמי",codes:[9910,9920,9930,9940,9950,9960,9980],sumCode:9900}];function Ce({data:t,referenceData:d,showEmptyFields:s=!1}){const l=j(I,t).balanceSheet||[],n=j(I,d)?.balanceSheet||[];return e.jsx(w,{value:"balanceSheet",className:"border rounded-md p-4",children:e.jsxs("div",{className:"space-y-6",dir:"rtl",children:[e.jsx("h3",{className:"text-lg font-bold border-b pb-2",children:"נתוני המאזן"}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx("h4",{className:"text-lg font-bold text-blue-800 border-b pb-2",children:"נכסים"}),e.jsx("div",{className:"bg-blue-100 p-4 rounded-md border-2 border-blue-300",children:e.jsx("h5",{className:"font-bold",children:"רכוש שוטף"})}),pe.map(r=>e.jsxs("div",{className:"bg-blue-50 p-4 rounded-md",children:[e.jsx("h6",{className:"font-bold mb-3",children:r.title}),e.jsxs("div",{className:"space-y-2",children:[r.codes.map(a=>e.jsx(m,{codes:l,referenceCodes:n,code:a,showEmptyFields:s},a)),e.jsx("div",{className:"border-2 rounded-md border-gray-300",children:e.jsx(m,{codes:l,referenceCodes:n,code:r.sumCode,showEmptyFields:s})})]})]},r.title)),e.jsx("div",{className:"bg-blue-100 p-4 rounded-md border-2 border-blue-300",children:e.jsx(m,{codes:l,code:7e3,showEmptyFields:s})}),ge.map(r=>e.jsxs("div",{className:"bg-blue-50 p-4 rounded-md",children:[e.jsx("h6",{className:"font-bold mb-3",children:r.title}),e.jsxs("div",{className:"space-y-2",children:[r.codes.map(a=>e.jsx(m,{codes:l,referenceCodes:n,code:a,showEmptyFields:s},a)),e.jsx("div",{className:"border-2 rounded-md border-gray-300",children:e.jsx(m,{codes:l,referenceCodes:n,code:r.sumCode,showEmptyFields:s})})]})]},r.title)),e.jsx("div",{className:"bg-blue-100 p-4 rounded-md border-2 border-blue-300",children:e.jsx(m,{codes:l,code:8888,showEmptyFields:s})})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h4",{className:"text-lg font-bold text-red-800 border-b pb-2",children:"התחייבויות והון"}),e.jsx("div",{className:"bg-red-100 p-4 rounded-md border-2 border-red-300",children:e.jsx("h5",{className:"font-bold",children:"התחייבויות שוטפות"})}),fe.map(r=>e.jsxs("div",{className:"bg-red-50 p-4 rounded-md",children:[e.jsx("h6",{className:"font-bold mb-3",children:r.title}),e.jsxs("div",{className:"space-y-2",children:[r.codes.map(a=>e.jsx(m,{codes:l,referenceCodes:n,code:a,showEmptyFields:s},a)),e.jsx("div",{className:"border-2 rounded-md border-gray-300",children:e.jsx(m,{codes:l,referenceCodes:n,code:r.sumCode,showEmptyFields:s})})]})]},r.title)),e.jsx("div",{className:"bg-red-100 p-4 rounded-md border-2 border-red-300",children:e.jsx(m,{codes:l,code:9e3,showEmptyFields:s})}),Ne.map(r=>e.jsxs("div",{className:"bg-red-50 p-4 rounded-md",children:[e.jsx("h6",{className:"font-bold mb-3",children:r.title}),e.jsxs("div",{className:"space-y-2",children:[r.codes.map(a=>e.jsx(m,{codes:l,referenceCodes:n,code:a,showEmptyFields:s},a)),e.jsx("div",{className:"border-2 rounded-md border-gray-300",children:e.jsx(m,{codes:l,referenceCodes:n,code:r.sumCode,showEmptyFields:s})})]})]},r.title)),ve.map(r=>e.jsxs("div",{className:"bg-green-50 p-4 rounded-md",children:[e.jsx("h5",{className:"font-bold mb-3",children:r.title}),e.jsx("div",{className:"space-y-2",children:r.codes.map(a=>e.jsx(m,{codes:l,referenceCodes:n,code:a,showEmptyFields:s},a))})]},r.title)),e.jsx("div",{className:"bg-red-100 p-4 rounded-md border-2 border-red-300",children:e.jsx(m,{codes:l,code:9999,showEmptyFields:s})})]})]})]})})}const ye=t=>{switch(t){case"1":return"תעשייתי";case"2":return"מסחרי";case"3":return"נותני שירותים";case"99":return"הדיווח כולל יותר מעסק אחד";default:return""}},Se=t=>{switch(t){case S.Cash:return"מזומן";case S.Accrual:return"מצטבר";case S.DollarRegulations:return"לפי תקנות דולריות";default:return""}},we=t=>{switch(t){case L.Shekels:return"שקלים";case L.Dollars:return"דולרים";default:return""}},Fe=t=>{switch(t){case B.DoubleEntry:return"כפולה";case B.SingleEntry:return"חד-צידית";default:return""}},Te=t=>{switch(t){case P.Computerized:return"ממוחשב";case P.Manual:return"ידני";default:return""}},De=t=>{switch(t){case N.Option_1:return"חלופה 1";case N.Option_2Adjustments:return"התאמות חשבונאיות למי שיישם את חלופה 2 בהוראת ביצוע 7/2010";case N.Option_3Adjustments:return"התאמות חשבונאיות למי שיישם את חלופה 3 בהוראת ביצוע 7/2010";case N.None:return"ללא חלופה";default:return""}},Re=t=>{switch(t){case p.Unqualified:return"נוסח אחיד (בלתי מסוייג)";case p.UnqualifiedWithGoingConcern:return"בנוסח אחיד עם הפניית תשומת לב להערת עסק חי";case p.UnqualifiedWithOtherEmphases:return"בנוסח אחיד עם הפניות תשומת לב אחרת";case p.Qualified:return"הסתייגות";case p.Adverse:return"שלילית";case p.Disclaimer:return"המנעות";case p.None:return"אין חוות דעת";default:return""}},y=t=>t==null?"":t?"כן":"לא";function Ae({data:t,businessInfo:d}){const{header:s}=j(ee,t),c=j(se,d);return e.jsx(w,{value:"header",className:"border rounded-md p-4",children:e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",dir:"rtl",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-lg font-bold border-b pb-2",children:"פרטים מזהים"}),e.jsx(u,{label:"השם הרשום",value:c.name,showEmptyFields:!0}),e.jsx(u,{label:"תיאור העיסוק המדווח",value:s.businessDescription??"",showEmptyFields:!0}),e.jsx(u,{label:"מספר זהות",value:s.idNumber,showEmptyFields:!0}),e.jsx(u,{label:"מספר תיק",value:s.taxFileNumber,showEmptyFields:!0}),e.jsx(u,{label:'תיק מדווח למע"מ',value:s.vatFileNumber??"",showEmptyFields:!0}),e.jsx(u,{label:"מספר תיק ניכויים",value:s.withholdingTaxFileNumber??"",showEmptyFields:!0})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-lg font-bold border-b pb-2",children:"פרטי העסק"}),e.jsx(u,{value:ye(s.businessType),label:"סוג העסק המדווח",showEmptyFields:!0}),e.jsx(u,{label:"שיטת דיווח",value:Se(s.reportingMethod),showEmptyFields:!0}),s.reportingMethod===S.DollarRegulations&&e.jsx(u,{label:"מטבע הסכומים",value:we(s.currencyType),showEmptyFields:!0}),e.jsx(u,{label:"הסכום באלפים",value:y(s.amountsInThousands),showEmptyFields:!0}),e.jsx(u,{label:"שיטת חשבונאות",value:Fe(s.accountingMethod),showEmptyFields:!0}),e.jsx(u,{label:"הנהלת חשבונות",value:Te(s.accountingSystem),showEmptyFields:!0}),e.jsx(u,{label:"חייב ברישום תוכנה",value:y(!!s.softwareRegistrationNumber),showEmptyFields:!0}),s.softwareRegistrationNumber&&e.jsx(u,{label:"מספר תעודת רישום",value:s.softwareRegistrationNumber,showEmptyFields:!0}),e.jsx(u,{label:"דוח בגין שותפות",value:y(!!s.isPartnership),showEmptyFields:!0}),s.isPartnership&&e.jsxs(e.Fragment,{children:[e.jsx(u,{label:"מספר שותפים",value:s.partnershipCount?.toString()??"",showEmptyFields:!0}),e.jsx(u,{label:"חלקי ברווחי השותפות",value:`${s.partnershipProfitShare}%`,showEmptyFields:!0})]}),e.jsx(u,{label:"יישום תקני חשבונאות (IFRS)",value:y(!!s.ifrsImplementationYear||!!s.ifrsReportingOption),showEmptyFields:!0}),(!!s.ifrsImplementationYear||!!s.ifrsReportingOption)&&e.jsxs(e.Fragment,{children:[e.jsx(u,{label:"החל משנת המס",value:s.ifrsImplementationYear??"",showEmptyFields:!0}),e.jsx(u,{label:"דווח בחלופה",value:De(s.ifrsReportingOption),showEmptyFields:!0})]}),e.jsx(u,{label:"מספר ענף כלכלי של המדווח",value:s.industryCode,showEmptyFields:!0}),e.jsx(u,{label:"חוות דעת המבקר",value:Re(s.auditOpinionType),showEmptyFields:!0})]})]})})}const Oe=[{title:"הכנסות ממכירות ומתן שירותים",color:"text-blue-700",codes:[1010,1015,1020,1025,1030,1040,1051,1052,1090],sumCode:1e3},{title:"עלות המכירות ומתן השירותים וביצוע עבודות",color:"text-purple-700",codes:[1306,1308,1307,1310,1320,1330,1340,1350,1360,1371,1372,1390,1400,1450],sumCode:1300},{title:"עלויות ייצור ועלויות אצל קבלן בונה",color:"text-rose-700",codes:[2005,2006,2011,2012,2015,2020,2025,2030,2035,2040,2045,2050,2060,2066,2067,2068,2070,2075,2080,2085,2090,2095],sumCode:2e3},{title:"הוצאות מחקר ופיתוח",color:"text-amber-700",codes:[2510,2520,2530,2540,2550,2560,2570,2590],sumCode:2500},{title:"הוצאות מכירה",color:"text-green-700",codes:[3011,3013,3012,3015,3020,3025,3030,3040,3045,3050,3060,3066,3067,3068,3070,3075,3080,3085,3090,3100,3120,3190],sumCode:3e3},{title:"הוצאות הנהלה וכלליות",color:"text-cyan-700",codes:[3511,3513,3512,3515,3520,3530,3535,3540,3545,3550,3560,3566,3567,3568,3570,3575,3580,3590,3595,3600,3610,3620,3625,3631,3632,3640,3650,3660,3665,3680,3685,3690],sumCode:3500},{title:"הוצאות מימון",color:"text-indigo-700",codes:[5010,5020,5025,5030,5040,5050,5051,5090],sumCode:5e3},{title:"הכנסות מימון",color:"text-fuchsia-700",codes:[5110,5121,5122,5130,5150,5160,5190],sumCode:5100},{title:"הכנסות אחרות",color:"text-red-700",codes:[5210,5220,5230,5236,5237,5240,5250,5260,5270,5290],sumCode:5200},{title:"הוצאות אחרות",color:"text-yellow-700",codes:[5310,5320,5330,5390],sumCode:5300}],ke=[{title:"מסים על הכנסה",color:"text-sky-700",codes:[5610,5620,5630],sumCode:5600},{title:"ייעוד הרווחים",color:"text-violet-700",codes:[5710],sumCode:5700},{title:"רווח/הפסד אקויטי",color:"text-pink-700",codes:[5810],sumCode:5800}];function Ee({selectedYear:t,referenceYear:d,data:s,referenceData:c,showEmptyFields:l=!1}){const{profitAndLoss:o}=j(Y,s),r=j(Y,c)?.profitAndLoss||[];return e.jsx(w,{value:"profitLoss",className:"border rounded-md p-4",children:e.jsxs("div",{className:"space-y-6",dir:"rtl",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("h3",{className:"text-lg font-bold border-b pb-2",children:"נתוני רווח והפסד"}),d&&t!==d&&e.jsxs("span",{className:"text-sm text-blue-600 bg-blue-50 px-2 py-1 rounded",children:["מציג שינויים לעומת ",d]})]}),Oe.map(a=>e.jsxs("div",{className:"bg-gray-50 p-4 rounded-md",children:[e.jsx("h4",{className:`font-bold mb-4 ${a.color}`,children:a.title}),e.jsxs("div",{className:"space-y-2",children:[a.codes.map(i=>e.jsx(m,{codes:o,referenceCodes:r,code:i,showEmptyFields:l},i)),e.jsx("div",{className:"border-2 rounded-md border-gray-300",children:e.jsx(m,{codes:o,referenceCodes:r,code:a.sumCode,showEmptyFields:l})})]})]},a.title)),e.jsx("div",{className:"bg-emerald-50 p-4 rounded-md border-2 border-emerald-200",children:e.jsx(m,{codes:o,referenceCodes:r,code:6666,showEmptyFields:l})}),ke.map(a=>e.jsxs("div",{className:"bg-gray-50 p-4 rounded-md",children:[e.jsx("h4",{className:`font-bold mb-4 ${a.color}`,children:a.title}),e.jsxs("div",{className:"space-y-2",children:[a.codes.map(i=>e.jsx(m,{codes:o,referenceCodes:r,code:i,showEmptyFields:l},i)),e.jsx("div",{className:"border-2 rounded-md border-gray-300",children:e.jsx(m,{codes:o,referenceCodes:r,code:a.sumCode,showEmptyFields:l})})]})]},a.title))]})})}const Me=[{title:"התאמות חשבונאיות למי שיישם את חלופה 2 בהוראת ביצוע 7/2010 בנושא IFRS",color:"red",codes:[103,104]},{title:"התאמות נדרשות לצרכי מס (הוסף/הפחת)",color:"yellow",codes:[110,120,130,135,140,150,160,170,180,181,182,183,184,190,200,300,310,320,330,350,360],sumCode:370},{title:"התאמות חשבונאיות למי שיישם את חלופה 3 בהוראת ביצוע 7/2010 בנושא IFRS שלא מצאו את ביטויין בהתאמות הנדרשות לצרכי מס",color:"emerald",codes:[383],sumCode:400},{title:"יישום הוראות חוקי מס נוספים",color:"sky",codes:[430,480,490],sumCode:500},{title:"נתונים נוספים",color:"violet",codes:[510,520,530,540,550,570,575,580,585,590]},{title:"בשותפות",color:"pink",codes:[600]}],_={red:{header:"text-red-700",sum:"bg-red-50 border-red-200"},yellow:{header:"text-yellow-700",sum:"bg-yellow-50 border-yellow-200"},emerald:{header:"text-emerald-700",sum:"bg-emerald-50 border-emerald-200"},sky:{header:"text-sky-700",sum:"bg-sky-50 border-sky-200"},violet:{header:"text-violet-700",sum:"bg-violet-50 border-violet-200"},pink:{header:"text-pink-700",sum:"bg-pink-50 border-pink-200"}};function Ie({data:t,referenceData:d,showEmptyFields:s=!1}){const{taxAdjustment:c}=j(V,t),o=j(V,d)?.taxAdjustment||[];return e.jsx(w,{value:"taxAdjustment",className:"border rounded-md p-4",children:e.jsxs("div",{className:"space-y-6",dir:"rtl",children:[e.jsx("h3",{className:"text-lg font-bold border-b pb-2",children:'נתוני דו"ח התאמה למס'}),e.jsx("div",{className:"bg-emerald-50 p-4 rounded-md border-2 border-emerald-200",children:e.jsx(m,{codes:c,referenceCodes:o,code:100,showEmptyFields:s})}),Me.map(n=>{const{header:r,sum:a}=_[n.color]||_.red;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"bg-gray-50 p-4 rounded-md",children:[e.jsx("h4",{className:"font-bold mb-4 "+r,children:n.title}),e.jsx("div",{className:"space-y-2",children:n.codes.map(i=>e.jsx(m,{codes:c,referenceCodes:o,code:i,showEmptyFields:s},i))})]}),n.sumCode&&e.jsx("div",{className:"p-4 rounded-md border-2 "+a,children:e.jsx(m,{codes:c,referenceCodes:o,code:n.sumCode,showEmptyFields:s})})]},n.title)})]})})}function Le({data:t,referenceData:d,businessInfo:s,selectedYear:c,referenceYear:l}){const o=j($,t),n=j($,d),[r,a]=b.useState("header"),[i,h]=b.useState(!0);return e.jsxs("div",{className:"p-4 border-gray-300",dir:"rtl",children:[e.jsxs("div",{className:"flex justify-between items-center mb-4",children:[e.jsx("div",{className:"flex items-center gap-4",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(g,{variant:i?"outline":"default",size:"sm",onClick:()=>h(!i),className:"flex items-center gap-2",children:[i?e.jsx(be,{className:"h-4 w-4"}):e.jsx(re,{className:"h-4 w-4"}),i?"הסתר שדות ריקים":"הצג שדות ריקים"]}),e.jsx("span",{className:"text-sm text-gray-500",children:i?"מציג את כל השדות":"מציג רק שדות עם נתונים"})]})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(g,{variant:"outline",className:"flex items-center gap-2",children:[e.jsx(te,{className:"h-4 w-4"}),"הורד"]}),e.jsxs(g,{variant:"outline",className:"flex items-center gap-2",children:[e.jsx(xe,{className:"h-4 w-4"}),"שמור"]})]})]}),e.jsxs(ae,{value:r,onValueChange:a,className:"w-full",children:[e.jsxs(le,{className:"grid grid-cols-4 w-full",dir:"rtl",children:[e.jsx(v,{value:"header",children:"פרטים מזהים"}),e.jsx(v,{value:"profitLoss",children:"רווח והפסד"}),e.jsx(v,{value:"taxAdjustment",children:"התאמה למס"}),e.jsx(v,{value:"balanceSheet",children:"מאזן"})]}),e.jsx(Ae,{data:o,businessInfo:s}),e.jsx(Ee,{selectedYear:c,referenceYear:l,data:o,referenceData:n,showEmptyFields:i}),e.jsx(Ie,{data:o,referenceData:n,showEmptyFields:i}),e.jsx(Ce,{data:o,referenceData:n,showEmptyFields:i})]})]})}function _e(){const{setFiltersContext:t}=b.useContext(de),[d,s]=b.useState(void 0),[c,l]=b.useState(void 0),[o,n]=b.useState(void 0),[{data:r,fetching:a}]=ne({query:ue,variables:{year:c?Number.parseInt(c,10):0,businessId:d},pause:!c||!d});return b.useEffect(()=>{t(e.jsx("div",{className:"flex flex-row gap-x-5",dir:"rtl",children:e.jsx(je,{selectedBusiness:d,setSelectedBusiness:s,selectedYear:c,setSelectedYear:l,referenceYear:o,setReferenceYear:n})}))},[t,d,c,o]),e.jsx("div",{className:"container mx-auto",dir:"rtl",children:e.jsxs(oe,{className:"border-2 border-gray-300",children:[e.jsx(ce,{className:"bg-gray-100 border-b-2 border-gray-300 flex flex-row justify-between items-center",children:e.jsxs("div",{className:"text-center w-full",children:[e.jsx("h1",{className:"text-2xl font-bold",children:'נספח לטופס הדו"ח השנתי ליחיד ולחבר בני אדם'}),e.jsxs("h2",{className:"text-xl",children:["לשנת המס ",c]}),e.jsx("p",{className:"text-sm",children:'נתוני הדוחות הכספיים, מאזן, רווח והפסד ודו"ח ההתאמה למס'})]})}),e.jsx(ie,{className:"p-0",children:e.jsx(Be,{fetching:a,data:r,selectedBusiness:d,selectedYear:c,referenceYear:o})})]})})}function Be({fetching:t,data:d,selectedBusiness:s,selectedYear:c,referenceYear:l}){if(t)return e.jsx("div",{className:"container mx-auto p-8 text-center",dir:"rtl",children:e.jsx("p",{className:"text-lg text-gray-600",children:"טוען נתונים..."})});if(!c||!s)return e.jsx("div",{className:"container mx-auto p-8 text-center",dir:"rtl",children:e.jsx("p",{className:"text-lg text-gray-600",children:"יש לבחור עסק ושנת דיווח"})});const o=d?.shaam6111.data;return o?e.jsx(Le,{data:o,businessInfo:d.shaam6111.business,selectedBusiness:s,selectedYear:c,referenceYear:l}):e.jsx("div",{className:"container mx-auto p-8 text-center",dir:"rtl",children:e.jsx("p",{className:"text-lg text-gray-600",children:"אין נתונים זמינים עבור העסק והשנה שנבחרו"})})}export{_e as Shaam6111Report};
6
+ */const he=[["path",{d:"M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49",key:"ct8e1f"}],["path",{d:"M14.084 14.158a3 3 0 0 1-4.242-4.242",key:"151rxh"}],["path",{d:"M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143",key:"13bj9a"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]],be=U("eye-off",he),y=["2020","2021","2022","2023"];function je({selectedBusiness:t,setSelectedBusiness:d,selectedYear:s,setSelectedYear:c,referenceYear:l,setReferenceYear:o}){const[n,r]=b.useState(!s||!t),{selectableBusinesses:a,fetching:i}=W(),h=b.useMemo(()=>t?a.find(f=>f.value===t)?.label??"":"",[a,t]);return e.jsxs(z,{open:n,onOpenChange:r,children:[e.jsx(G,{asChild:!0,children:e.jsxs(g,{variant:"outline",className:"flex items-center gap-2",children:[e.jsx(R,{className:"h-4 w-4"}),"מסננים",e.jsxs("span",{className:"text-xs bg-blue-100 text-blue-800 px-2 py-0.5 rounded-full",children:[h," • ",s]})]})}),e.jsxs(Q,{className:"sm:max-w-md",dir:"rtl",children:[e.jsx(X,{children:e.jsxs(Z,{className:"flex items-center gap-2",children:[e.jsx(R,{className:"h-5 w-5"}),"מסנני דוח"]})}),e.jsxs("div",{className:"space-y-6 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(T,{htmlFor:"business-select",className:"flex items-center gap-2",children:[e.jsx(me,{className:"h-4 w-4"}),"בחירת עסק"]}),e.jsx(K,{onChange:x=>d(x??void 0),data:a,value:t,disabled:i,placeholder:"Scroll to see all options",triggerProps:{className:"w-full"}})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(T,{htmlFor:"year-select",className:"flex items-center gap-2",children:[e.jsx(A,{className:"h-4 w-4"}),"שנת דיווח"]}),e.jsxs(k,{value:s,onValueChange:c,children:[e.jsx(O,{id:"year-select",children:e.jsx(M,{})}),e.jsx(E,{children:y.map(x=>e.jsx(D,{value:x,children:x},x))})]}),e.jsxs("p",{className:"text-xs text-gray-500",children:["זמינות נתונים: ",y.join(", ")]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(T,{htmlFor:"reference-year-select",className:"flex items-center gap-2",children:[e.jsx(A,{className:"h-4 w-4"}),"שנת השוואה"]}),e.jsxs(k,{value:l,onValueChange:x=>o(x==="none"?void 0:x),children:[e.jsx(O,{id:"reference-year-select",children:e.jsx(M,{})}),e.jsxs(E,{children:[e.jsx(D,{value:"none",children:"ללא"},"none"),y.map(x=>e.jsx(D,{value:x,children:x},x))]})]}),e.jsxs("p",{className:"text-xs text-gray-500",children:["זמינות נתונים: ",y.join(", ")]})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[e.jsx(g,{variant:"outline",onClick:()=>r(!1),children:"ביטול"}),e.jsx(g,{onClick:()=>r(!1),children:"אישור"})]})]})]})]})}const u=({label:t,value:d,code:s,referenceValue:c,showEmptyFields:l,showChange:o=!1})=>{const n=h=>l?!0:!r(h),r=h=>!h||h.trim()===""||h==="0"||h==="0.00",a=(h,x)=>{if(!x)return null;const f=H=>Number.parseFloat(H.replace(/[,\s₪]/g,""))||0,q=f(h),F=f(x);return F===0?null:(q-F)/F*100};if(!n(d))return null;const i=o?a(d,c):null;return e.jsxs("div",{className:"flex justify-between items-center py-2 border-b border-gray-200",dir:"rtl",children:[e.jsxs("span",{className:"text-sm text-gray-600",children:[t," ",s&&`(${s})`]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`font-medium ${r(d)?"text-gray-400":""}`,children:r(d)?"0":d}),i!==null&&e.jsxs("span",{className:`text-xs px-1 py-0.5 rounded ${i>0?"text-green-700 bg-green-100":i<0?"text-red-700 bg-red-100":"text-gray-700 bg-gray-100"}`,children:[i>0?"+":"",i.toFixed(1),"%"]})]})]})},m=({codes:t,referenceCodes:d,code:s,showEmptyFields:c})=>{const{value:l,label:o}=b.useMemo(()=>{const r=t.find(a=>a.code===s);return{value:r?.amount||0,label:r?.label||"לא זוהה קוד"}},[t,s]),n=b.useMemo(()=>d?.find(r=>r.code===s)?.amount.toString()||"",[d,s]);return e.jsx(u,{label:o,value:J(l,0),code:String(s),showChange:!0,showEmptyFields:c,referenceValue:n})},pe=[{title:"מזומנים ושווי מזומנים",codes:[7110,7120,7150],sumCode:7100},{title:"ניירות ערך",codes:[7215,7225,7230,7290,7295],sumCode:7200},{title:"לקוחות",codes:[7310,7320,7330,7350,7360,7380,7390],sumCode:7300},{title:"חייבים ויתרות חובה",codes:[7410,7420,7430,7440,7450,7461,7462,7470,7490],sumCode:7400},{title:"מסים נדחים לזמן קצר",codes:[7610,7620,7690],sumCode:7600},{title:"הלוואות לזמן קצר",codes:[7711,7712,7720],sumCode:7700},{title:"מלאי",codes:[7805,7810,7815,7820,7825,7830,7840,7850,7860,7870,7890],sumCode:7800}],ge=[{title:"רכוש קבוע",codes:[8010,8020,8025,8030,8040,8050,8060,8080,8090,8095,8100,8105,8110,8120,8130,8140,8150,8160,8170,8180,8190],sumCode:8e3},{title:"נכסים לא שוטפים מוחזקים למכירה",codes:[8710],sumCode:8700},{title:"הוצאות מראש לזמן ארוך",codes:[8210,8220,8290],sumCode:8200},{title:"השקעות בחברות מוחזקות כלולות ומאוחדות",codes:[8315,8325,8335,8340,8350],sumCode:8300},{title:'השקעות בחברות אחרות כולל ני"ע סחירים מוחזקים לזמן ארוך',codes:[8410,8420,8440,8450,8460,8490],sumCode:8400},{title:"מסים נדחים לזמן ארוך",codes:[8510,8520,8590],sumCode:8500},{title:"הוצאות נדחות ורכוש אחר",codes:[8610,8620,8630,8640,8690],sumCode:8600}],fe=[{title:"בנקים והלואות לזמן קצר",codes:[9110,9120,9130,9140,9151,9152,9190],sumCode:9100},{title:"ספקים ונותני שירותים",codes:[9210,9220,9230,9290],sumCode:9200},{title:"זכאים ויתרות זכות",codes:[9310,9320,9330,9340,9350,9360,9370,9410,9420,9431,9432,9435,9440,9450,9460,9470,9480,9490],sumCode:9400},{title:"עתודה למסים נדחים לזמן קצר",codes:[9510,9520,9530],sumCode:9500}],Ne=[{title:"התחייבויות לזמן ארוך",codes:[9605,9610,9620,9631,9632,9640,9650,9660,9670,9690],sumCode:9600},{title:"התחייבויות בשל סיום יחסי עובד-מעביד",codes:[9710,9720,9790],sumCode:9700},{title:"עתודה למסים נדחים לזמן ארוך",codes:[9810,9820,9890],sumCode:9800}],ve=[{title:"הון עצמי",codes:[9910,9920,9930,9940,9950,9960,9980],sumCode:9900}];function ye({data:t,referenceData:d,showEmptyFields:s=!1}){const l=j(I,t).balanceSheet||[],n=j(I,d)?.balanceSheet||[];return e.jsx(w,{value:"balanceSheet",className:"border rounded-md p-4",children:e.jsxs("div",{className:"space-y-6",dir:"rtl",children:[e.jsx("h3",{className:"text-lg font-bold border-b pb-2",children:"נתוני המאזן"}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx("h4",{className:"text-lg font-bold text-blue-800 border-b pb-2",children:"נכסים"}),e.jsx("div",{className:"bg-blue-100 p-4 rounded-md border-2 border-blue-300",children:e.jsx("h5",{className:"font-bold",children:"רכוש שוטף"})}),pe.map(r=>e.jsxs("div",{className:"bg-blue-50 p-4 rounded-md",children:[e.jsx("h6",{className:"font-bold mb-3",children:r.title}),e.jsxs("div",{className:"space-y-2",children:[r.codes.map(a=>e.jsx(m,{codes:l,referenceCodes:n,code:a,showEmptyFields:s},a)),e.jsx("div",{className:"border-2 rounded-md border-gray-300",children:e.jsx(m,{codes:l,referenceCodes:n,code:r.sumCode,showEmptyFields:s})})]})]},r.title)),e.jsx("div",{className:"bg-blue-100 p-4 rounded-md border-2 border-blue-300",children:e.jsx(m,{codes:l,code:7e3,showEmptyFields:s})}),ge.map(r=>e.jsxs("div",{className:"bg-blue-50 p-4 rounded-md",children:[e.jsx("h6",{className:"font-bold mb-3",children:r.title}),e.jsxs("div",{className:"space-y-2",children:[r.codes.map(a=>e.jsx(m,{codes:l,referenceCodes:n,code:a,showEmptyFields:s},a)),e.jsx("div",{className:"border-2 rounded-md border-gray-300",children:e.jsx(m,{codes:l,referenceCodes:n,code:r.sumCode,showEmptyFields:s})})]})]},r.title)),e.jsx("div",{className:"bg-blue-100 p-4 rounded-md border-2 border-blue-300",children:e.jsx(m,{codes:l,code:8888,showEmptyFields:s})})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h4",{className:"text-lg font-bold text-red-800 border-b pb-2",children:"התחייבויות והון"}),e.jsx("div",{className:"bg-red-100 p-4 rounded-md border-2 border-red-300",children:e.jsx("h5",{className:"font-bold",children:"התחייבויות שוטפות"})}),fe.map(r=>e.jsxs("div",{className:"bg-red-50 p-4 rounded-md",children:[e.jsx("h6",{className:"font-bold mb-3",children:r.title}),e.jsxs("div",{className:"space-y-2",children:[r.codes.map(a=>e.jsx(m,{codes:l,referenceCodes:n,code:a,showEmptyFields:s},a)),e.jsx("div",{className:"border-2 rounded-md border-gray-300",children:e.jsx(m,{codes:l,referenceCodes:n,code:r.sumCode,showEmptyFields:s})})]})]},r.title)),e.jsx("div",{className:"bg-red-100 p-4 rounded-md border-2 border-red-300",children:e.jsx(m,{codes:l,code:9e3,showEmptyFields:s})}),Ne.map(r=>e.jsxs("div",{className:"bg-red-50 p-4 rounded-md",children:[e.jsx("h6",{className:"font-bold mb-3",children:r.title}),e.jsxs("div",{className:"space-y-2",children:[r.codes.map(a=>e.jsx(m,{codes:l,referenceCodes:n,code:a,showEmptyFields:s},a)),e.jsx("div",{className:"border-2 rounded-md border-gray-300",children:e.jsx(m,{codes:l,referenceCodes:n,code:r.sumCode,showEmptyFields:s})})]})]},r.title)),ve.map(r=>e.jsxs("div",{className:"bg-green-50 p-4 rounded-md",children:[e.jsx("h5",{className:"font-bold mb-3",children:r.title}),e.jsx("div",{className:"space-y-2",children:r.codes.map(a=>e.jsx(m,{codes:l,referenceCodes:n,code:a,showEmptyFields:s},a))})]},r.title)),e.jsx("div",{className:"bg-red-100 p-4 rounded-md border-2 border-red-300",children:e.jsx(m,{codes:l,code:9999,showEmptyFields:s})})]})]})]})})}const Ce=t=>{switch(t){case"1":return"תעשייתי";case"2":return"מסחרי";case"3":return"נותני שירותים";case"99":return"הדיווח כולל יותר מעסק אחד";default:return""}},Se=t=>{switch(t){case S.Cash:return"מזומן";case S.Accrual:return"מצטבר";case S.DollarRegulations:return"לפי תקנות דולריות";default:return""}},we=t=>{switch(t){case L.Shekels:return"שקלים";case L.Dollars:return"דולרים";default:return""}},Fe=t=>{switch(t){case B.DoubleEntry:return"כפולה";case B.SingleEntry:return"חד-צידית";default:return""}},Te=t=>{switch(t){case P.Computerized:return"ממוחשב";case P.Manual:return"ידני";default:return""}},De=t=>{switch(t){case N.Option_1:return"חלופה 1";case N.Option_2Adjustments:return"התאמות חשבונאיות למי שיישם את חלופה 2 בהוראת ביצוע 7/2010";case N.Option_3Adjustments:return"התאמות חשבונאיות למי שיישם את חלופה 3 בהוראת ביצוע 7/2010";case N.None:return"ללא חלופה";default:return""}},Re=t=>{switch(t){case p.Unqualified:return"נוסח אחיד (בלתי מסוייג)";case p.UnqualifiedWithGoingConcern:return"בנוסח אחיד עם הפניית תשומת לב להערת עסק חי";case p.UnqualifiedWithOtherEmphases:return"בנוסח אחיד עם הפניות תשומת לב אחרת";case p.Qualified:return"הסתייגות";case p.Adverse:return"שלילית";case p.Disclaimer:return"המנעות";case p.None:return"אין חוות דעת";default:return""}},C=t=>t==null?"":t?"כן":"לא";function Ae({data:t,businessInfo:d}){const{header:s}=j(ee,t),c=j(se,d);return e.jsx(w,{value:"header",className:"border rounded-md p-4",children:e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",dir:"rtl",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-lg font-bold border-b pb-2",children:"פרטים מזהים"}),e.jsx(u,{label:"השם הרשום",value:c.name,showEmptyFields:!0}),e.jsx(u,{label:"תיאור העיסוק המדווח",value:s.businessDescription??"",showEmptyFields:!0}),e.jsx(u,{label:"מספר זהות",value:s.idNumber,showEmptyFields:!0}),e.jsx(u,{label:"מספר תיק",value:s.taxFileNumber,showEmptyFields:!0}),e.jsx(u,{label:'תיק מדווח למע"מ',value:s.vatFileNumber??"",showEmptyFields:!0}),e.jsx(u,{label:"מספר תיק ניכויים",value:s.withholdingTaxFileNumber??"",showEmptyFields:!0})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-lg font-bold border-b pb-2",children:"פרטי העסק"}),e.jsx(u,{value:Ce(s.businessType),label:"סוג העסק המדווח",showEmptyFields:!0}),e.jsx(u,{label:"שיטת דיווח",value:Se(s.reportingMethod),showEmptyFields:!0}),s.reportingMethod===S.DollarRegulations&&e.jsx(u,{label:"מטבע הסכומים",value:we(s.currencyType),showEmptyFields:!0}),e.jsx(u,{label:"הסכום באלפים",value:C(s.amountsInThousands),showEmptyFields:!0}),e.jsx(u,{label:"שיטת חשבונאות",value:Fe(s.accountingMethod),showEmptyFields:!0}),e.jsx(u,{label:"הנהלת חשבונות",value:Te(s.accountingSystem),showEmptyFields:!0}),e.jsx(u,{label:"חייב ברישום תוכנה",value:C(!!s.softwareRegistrationNumber),showEmptyFields:!0}),s.softwareRegistrationNumber&&e.jsx(u,{label:"מספר תעודת רישום",value:s.softwareRegistrationNumber,showEmptyFields:!0}),e.jsx(u,{label:"דוח בגין שותפות",value:C(!!s.isPartnership),showEmptyFields:!0}),s.isPartnership&&e.jsxs(e.Fragment,{children:[e.jsx(u,{label:"מספר שותפים",value:s.partnershipCount?.toString()??"",showEmptyFields:!0}),e.jsx(u,{label:"חלקי ברווחי השותפות",value:`${s.partnershipProfitShare}%`,showEmptyFields:!0})]}),e.jsx(u,{label:"יישום תקני חשבונאות (IFRS)",value:C(!!s.ifrsImplementationYear||!!s.ifrsReportingOption),showEmptyFields:!0}),(!!s.ifrsImplementationYear||!!s.ifrsReportingOption)&&e.jsxs(e.Fragment,{children:[e.jsx(u,{label:"החל משנת המס",value:s.ifrsImplementationYear??"",showEmptyFields:!0}),e.jsx(u,{label:"דווח בחלופה",value:De(s.ifrsReportingOption),showEmptyFields:!0})]}),e.jsx(u,{label:"מספר ענף כלכלי של המדווח",value:s.industryCode,showEmptyFields:!0}),e.jsx(u,{label:"חוות דעת המבקר",value:Re(s.auditOpinionType),showEmptyFields:!0})]})]})})}const ke=[{title:"הכנסות ממכירות ומתן שירותים",color:"text-blue-700",codes:[1010,1015,1020,1025,1030,1040,1051,1052,1090],sumCode:1e3},{title:"עלות המכירות ומתן השירותים וביצוע עבודות",color:"text-purple-700",codes:[1306,1308,1307,1310,1320,1330,1340,1350,1360,1371,1372,1390,1400,1450],sumCode:1300},{title:"עלויות ייצור ועלויות אצל קבלן בונה",color:"text-rose-700",codes:[2005,2006,2011,2012,2015,2020,2025,2030,2035,2040,2045,2050,2060,2066,2067,2068,2070,2075,2080,2085,2090,2095],sumCode:2e3},{title:"הוצאות מחקר ופיתוח",color:"text-amber-700",codes:[2510,2520,2530,2540,2550,2560,2570,2590],sumCode:2500},{title:"הוצאות מכירה",color:"text-green-700",codes:[3011,3013,3012,3015,3020,3025,3030,3040,3045,3050,3060,3066,3067,3068,3070,3075,3080,3085,3090,3100,3120,3190],sumCode:3e3},{title:"הוצאות הנהלה וכלליות",color:"text-cyan-700",codes:[3511,3513,3512,3515,3520,3530,3535,3540,3545,3550,3560,3566,3567,3568,3570,3575,3580,3590,3595,3600,3610,3620,3625,3631,3632,3640,3650,3660,3665,3680,3685,3690],sumCode:3500},{title:"הוצאות מימון",color:"text-indigo-700",codes:[5010,5020,5025,5030,5040,5050,5051,5090],sumCode:5e3},{title:"הכנסות מימון",color:"text-fuchsia-700",codes:[5110,5121,5122,5130,5150,5160,5190],sumCode:5100},{title:"הכנסות אחרות",color:"text-red-700",codes:[5210,5220,5230,5236,5237,5240,5250,5260,5270,5290],sumCode:5200},{title:"הוצאות אחרות",color:"text-yellow-700",codes:[5310,5320,5330,5390],sumCode:5300}],Oe=[{title:"מסים על הכנסה",color:"text-sky-700",codes:[5610,5620,5630],sumCode:5600},{title:"ייעוד הרווחים",color:"text-violet-700",codes:[5710],sumCode:5700},{title:"רווח/הפסד אקויטי",color:"text-pink-700",codes:[5810],sumCode:5800}];function Me({selectedYear:t,referenceYear:d,data:s,referenceData:c,showEmptyFields:l=!1}){const{profitAndLoss:o}=j(Y,s),r=j(Y,c)?.profitAndLoss||[];return e.jsx(w,{value:"profitLoss",className:"border rounded-md p-4",children:e.jsxs("div",{className:"space-y-6",dir:"rtl",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("h3",{className:"text-lg font-bold border-b pb-2",children:"נתוני רווח והפסד"}),d&&t!==d&&e.jsxs("span",{className:"text-sm text-blue-600 bg-blue-50 px-2 py-1 rounded",children:["מציג שינויים לעומת ",d]})]}),ke.map(a=>e.jsxs("div",{className:"bg-gray-50 p-4 rounded-md",children:[e.jsx("h4",{className:`font-bold mb-4 ${a.color}`,children:a.title}),e.jsxs("div",{className:"space-y-2",children:[a.codes.map(i=>e.jsx(m,{codes:o,referenceCodes:r,code:i,showEmptyFields:l},i)),e.jsx("div",{className:"border-2 rounded-md border-gray-300",children:e.jsx(m,{codes:o,referenceCodes:r,code:a.sumCode,showEmptyFields:l})})]})]},a.title)),e.jsx("div",{className:"bg-emerald-50 p-4 rounded-md border-2 border-emerald-200",children:e.jsx(m,{codes:o,referenceCodes:r,code:6666,showEmptyFields:l})}),Oe.map(a=>e.jsxs("div",{className:"bg-gray-50 p-4 rounded-md",children:[e.jsx("h4",{className:`font-bold mb-4 ${a.color}`,children:a.title}),e.jsxs("div",{className:"space-y-2",children:[a.codes.map(i=>e.jsx(m,{codes:o,referenceCodes:r,code:i,showEmptyFields:l},i)),e.jsx("div",{className:"border-2 rounded-md border-gray-300",children:e.jsx(m,{codes:o,referenceCodes:r,code:a.sumCode,showEmptyFields:l})})]})]},a.title))]})})}const Ee=[{title:"התאמות חשבונאיות למי שיישם את חלופה 2 בהוראת ביצוע 7/2010 בנושא IFRS",color:"red",codes:[103,104]},{title:"התאמות נדרשות לצרכי מס (הוסף/הפחת)",color:"yellow",codes:[110,120,130,135,140,150,160,170,180,181,182,183,184,190,200,300,310,320,330,350,360],sumCode:370},{title:"התאמות חשבונאיות למי שיישם את חלופה 3 בהוראת ביצוע 7/2010 בנושא IFRS שלא מצאו את ביטויין בהתאמות הנדרשות לצרכי מס",color:"emerald",codes:[383],sumCode:400},{title:"יישום הוראות חוקי מס נוספים",color:"sky",codes:[430,480,490],sumCode:500},{title:"נתונים נוספים",color:"violet",codes:[510,520,530,540,550,570,575,580,585,590]},{title:"בשותפות",color:"pink",codes:[600]}],_={red:{header:"text-red-700",sum:"bg-red-50 border-red-200"},yellow:{header:"text-yellow-700",sum:"bg-yellow-50 border-yellow-200"},emerald:{header:"text-emerald-700",sum:"bg-emerald-50 border-emerald-200"},sky:{header:"text-sky-700",sum:"bg-sky-50 border-sky-200"},violet:{header:"text-violet-700",sum:"bg-violet-50 border-violet-200"},pink:{header:"text-pink-700",sum:"bg-pink-50 border-pink-200"}};function Ie({data:t,referenceData:d,showEmptyFields:s=!1}){const{taxAdjustment:c}=j($,t),o=j($,d)?.taxAdjustment||[];return e.jsx(w,{value:"taxAdjustment",className:"border rounded-md p-4",children:e.jsxs("div",{className:"space-y-6",dir:"rtl",children:[e.jsx("h3",{className:"text-lg font-bold border-b pb-2",children:'נתוני דו"ח התאמה למס'}),e.jsx("div",{className:"bg-emerald-50 p-4 rounded-md border-2 border-emerald-200",children:e.jsx(m,{codes:c,referenceCodes:o,code:100,showEmptyFields:s})}),Ee.map(n=>{const{header:r,sum:a}=_[n.color]||_.red;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"bg-gray-50 p-4 rounded-md",children:[e.jsx("h4",{className:"font-bold mb-4 "+r,children:n.title}),e.jsx("div",{className:"space-y-2",children:n.codes.map(i=>e.jsx(m,{codes:c,referenceCodes:o,code:i,showEmptyFields:s},i))})]}),n.sumCode&&e.jsx("div",{className:"p-4 rounded-md border-2 "+a,children:e.jsx(m,{codes:c,referenceCodes:o,code:n.sumCode,showEmptyFields:s})})]},n.title)})]})})}function Le({data:t,referenceData:d,businessInfo:s,selectedYear:c,referenceYear:l}){const o=j(V,t),n=j(V,d),[r,a]=b.useState("header"),[i,h]=b.useState(!0);return e.jsxs("div",{className:"p-4 border-gray-300",dir:"rtl",children:[e.jsxs("div",{className:"flex justify-between items-center mb-4",children:[e.jsx("div",{className:"flex items-center gap-4",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(g,{variant:i?"outline":"default",size:"sm",onClick:()=>h(!i),className:"flex items-center gap-2",children:[i?e.jsx(be,{className:"h-4 w-4"}):e.jsx(re,{className:"h-4 w-4"}),i?"הסתר שדות ריקים":"הצג שדות ריקים"]}),e.jsx("span",{className:"text-sm text-gray-500",children:i?"מציג את כל השדות":"מציג רק שדות עם נתונים"})]})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(g,{variant:"outline",className:"flex items-center gap-2",children:[e.jsx(te,{className:"h-4 w-4"}),"הורד"]}),e.jsxs(g,{variant:"outline",className:"flex items-center gap-2",children:[e.jsx(xe,{className:"h-4 w-4"}),"שמור"]})]})]}),e.jsxs(ae,{value:r,onValueChange:a,className:"w-full",children:[e.jsxs(le,{className:"grid grid-cols-4 w-full",dir:"rtl",children:[e.jsx(v,{value:"header",children:"פרטים מזהים"}),e.jsx(v,{value:"profitLoss",children:"רווח והפסד"}),e.jsx(v,{value:"taxAdjustment",children:"התאמה למס"}),e.jsx(v,{value:"balanceSheet",children:"מאזן"})]}),e.jsx(Ae,{data:o,businessInfo:s}),e.jsx(Me,{selectedYear:c,referenceYear:l,data:o,referenceData:n,showEmptyFields:i}),e.jsx(Ie,{data:o,referenceData:n,showEmptyFields:i}),e.jsx(ye,{data:o,referenceData:n,showEmptyFields:i})]})]})}function _e(){const{setFiltersContext:t}=b.useContext(de),[d,s]=b.useState(void 0),[c,l]=b.useState(void 0),[o,n]=b.useState(void 0),[{data:r,fetching:a}]=ne({query:ue,variables:{year:c?Number.parseInt(c,10):0,businessId:d},pause:!c||!d});return b.useEffect(()=>{t(e.jsx("div",{className:"flex flex-row gap-x-5",dir:"rtl",children:e.jsx(je,{selectedBusiness:d,setSelectedBusiness:s,selectedYear:c,setSelectedYear:l,referenceYear:o,setReferenceYear:n})}))},[t,d,c,o]),e.jsx("div",{className:"container mx-auto",dir:"rtl",children:e.jsxs(oe,{className:"border-2 border-gray-300",children:[e.jsx(ce,{className:"bg-gray-100 border-b-2 border-gray-300 flex flex-row justify-between items-center",children:e.jsxs("div",{className:"text-center w-full",children:[e.jsx("h1",{className:"text-2xl font-bold",children:'נספח לטופס הדו"ח השנתי ליחיד ולחבר בני אדם'}),e.jsxs("h2",{className:"text-xl",children:["לשנת המס ",c]}),e.jsx("p",{className:"text-sm",children:'נתוני הדוחות הכספיים, מאזן, רווח והפסד ודו"ח ההתאמה למס'})]})}),e.jsx(ie,{className:"p-0",children:e.jsx(Be,{fetching:a,data:r,selectedBusiness:d,selectedYear:c,referenceYear:o})})]})})}function Be({fetching:t,data:d,selectedBusiness:s,selectedYear:c,referenceYear:l}){if(t)return e.jsx("div",{className:"container mx-auto p-8 text-center",dir:"rtl",children:e.jsx("p",{className:"text-lg text-gray-600",children:"טוען נתונים..."})});if(!c||!s)return e.jsx("div",{className:"container mx-auto p-8 text-center",dir:"rtl",children:e.jsx("p",{className:"text-lg text-gray-600",children:"יש לבחור עסק ושנת דיווח"})});const o=d?.shaam6111.data;return o?e.jsx(Le,{data:o,businessInfo:d.shaam6111.business,selectedBusiness:s,selectedYear:c,referenceYear:l}):e.jsx("div",{className:"container mx-auto p-8 text-center",dir:"rtl",children:e.jsx("p",{className:"text-lg text-gray-600",children:"אין נתונים זמינים עבור העסק והשנה שנבחרו"})})}export{_e as Shaam6111Report};