@accounter/client 0.0.8-alpha-20251023065832-9a9f37786b0e29dc8e6ea58ec9856bc043cc0e8a → 0.0.8-alpha-20251023070808-bdd9d09db3d693f2c0061a2bbd66a4bfe5224012

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 (88) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/dist/assets/{Checkbox-lfqFDKZM.js → Checkbox-Bm30-WRa.js} +2 -2
  3. package/dist/assets/{Progress-DvGsu87E.js → Progress-DxcT-wYo.js} +1 -1
  4. package/dist/assets/{Typography-BX4mj53o.js → Typography-CZLHs9y2.js} +1 -1
  5. package/dist/assets/{accordion-lOk81yKP.js → accordion-_VaDHoQb.js} +1 -1
  6. package/dist/assets/accountant-approvals-C7GnMLyl.js +1 -0
  7. package/dist/assets/{all-charges-DhPxcK73.js → all-charges-DS-mdep6.js} +1 -1
  8. package/dist/assets/{arrow-up-down-CFrneqND.js → arrow-up-down-Bt3_puEZ.js} +1 -1
  9. package/dist/assets/business-Db4PzgLz.js +42 -0
  10. package/dist/assets/{business-transactions-single-CJ5pLN-D.js → business-transactions-single-Canul8rR.js} +1 -1
  11. package/dist/assets/{business-trip-Jlc0bfXC.js → business-trip-x8lljSMP.js} +1 -1
  12. package/dist/assets/charges-filters-DkO9FBdC.js +1 -0
  13. package/dist/assets/{charges-ledger-validation-Bln73m_U.js → charges-ledger-validation-wla_aWIc.js} +1 -1
  14. package/dist/assets/{chart-Wut6cPCx.js → chart-2uS7cQLX.js} +1 -1
  15. package/dist/assets/{data-table-pagination-BnQGVnmE.js → data-table-pagination-CQQBbtVE.js} +1 -1
  16. package/dist/assets/{editable-business-trip-CjJg13b0.js → editable-business-trip-D50scoPo.js} +2 -2
  17. package/dist/assets/{index-y8Z-aJKc.js → index-B20Tn_iF.js} +2 -2
  18. package/dist/assets/{index-BoSqeUi7.js → index-BJ63UrPP.js} +6 -6
  19. package/dist/assets/{index-C2INIVq3.js → index-BNPAKzBY.js} +1 -1
  20. package/dist/assets/index-BP2Hv2J-.js +1 -0
  21. package/dist/assets/{index-Csqyxwgx.js → index-BTiGhl3N.js} +2 -2
  22. package/dist/assets/index-BaDl3RPI.js +1 -0
  23. package/dist/assets/index-BmSAw35b.js +1 -0
  24. package/dist/assets/{index-CN7VPpiB.js → index-BsGG-RLV.js} +13 -13
  25. package/dist/assets/index-Bskia9ol.js +1 -0
  26. package/dist/assets/index-C4JVZBO-.js +1 -0
  27. package/dist/assets/{index-BX3VSsge.js → index-CDHKPA0l.js} +1 -1
  28. package/dist/assets/{index-DquDHLbE.js → index-CqZy7PVr.js} +1 -1
  29. package/dist/assets/index-CzzfC-dD.css +1 -0
  30. package/dist/assets/index-D2w9iaKk.js +1 -0
  31. package/dist/assets/index-D5CFY1GF.js +1 -0
  32. package/dist/assets/index-DBjj2AmF.js +1 -0
  33. package/dist/assets/index-DJ33tRZ1.js +1 -0
  34. package/dist/assets/index-DKS2QKOQ.js +1 -0
  35. package/dist/assets/index-DOKYSdGb.js +1 -0
  36. package/dist/assets/{index-BagyRbeI.js → index-D_PykgGt.js} +2 -2
  37. package/dist/assets/index-Dk4NeG4m.js +1 -0
  38. package/dist/assets/{index-DjSJrgv5.js → index-Dkqd5T8J.js} +2 -2
  39. package/dist/assets/{index-CVz9TqoS.js → index-IN8Kpfsx.js} +2 -2
  40. package/dist/assets/index-OqG78rNq.js +9 -0
  41. package/dist/assets/{index.es-D8leRAY2.js → index.es-DKjfxgqg.js} +1 -1
  42. package/dist/assets/{issue-document-DKE0dzdE.js → issue-document-BFOjGS-U.js} +1 -1
  43. package/dist/assets/login-page-CpRailN7.js +1 -0
  44. package/dist/assets/{missing-info-charges-CgMJ4Bu3.js → missing-info-charges-BnYMeatL.js} +1 -1
  45. package/dist/assets/page-not-found-BLrYvmf4.js +1 -0
  46. package/dist/assets/{pencil-CUSCcyVn.js → pencil-DC6M9VTY.js} +1 -1
  47. package/dist/assets/report-commentary-row-DJPRyQur.js +1 -0
  48. package/dist/assets/save-Dr3CNkcl.js +11 -0
  49. package/dist/assets/similar-charges-by-business-modal-CCw5opHn.js +1 -0
  50. package/dist/assets/sub-DKnwnbwx.js +1 -0
  51. package/dist/assets/subMonths-B44KizJf.js +1 -0
  52. package/dist/index.html +2 -2
  53. package/package.json +2 -2
  54. package/src/components/business/business-header.tsx +2 -21
  55. package/src/components/businesses/all-businesses-row.tsx +87 -0
  56. package/src/components/businesses/cells/hebrew-name.tsx +31 -0
  57. package/src/components/businesses/cells/index.ts +2 -0
  58. package/src/components/businesses/cells/name.tsx +31 -0
  59. package/src/components/businesses/index.tsx +36 -45
  60. package/src/components/common/forms/business-card.tsx +234 -0
  61. package/src/components/common/forms/index.ts +1 -0
  62. package/src/gql/gql.ts +30 -6
  63. package/src/gql/graphql.ts +30 -7
  64. package/dist/assets/accountant-approvals-DWLEu1Um.js +0 -1
  65. package/dist/assets/building-2-Bqvbwz7Q.js +0 -6
  66. package/dist/assets/business--eNnF4xF.js +0 -42
  67. package/dist/assets/business-header-DjutqTRC.js +0 -1
  68. package/dist/assets/charges-filters-C-H07qp1.js +0 -1
  69. package/dist/assets/index-BE5nnZYY.js +0 -9
  70. package/dist/assets/index-BQrSA2Kk.js +0 -1
  71. package/dist/assets/index-BkeJsHyM.js +0 -1
  72. package/dist/assets/index-BtAgm6J8.js +0 -1
  73. package/dist/assets/index-BwIQ8ifH.js +0 -1
  74. package/dist/assets/index-Bxlzprxi.js +0 -1
  75. package/dist/assets/index-C--YkrHw.js +0 -1
  76. package/dist/assets/index-CQXFj3Uj.css +0 -1
  77. package/dist/assets/index-CalcGztb.js +0 -1
  78. package/dist/assets/index-Dr2UkUOm.js +0 -1
  79. package/dist/assets/index-E2rO9Bsf.js +0 -1
  80. package/dist/assets/index-Ggixi4PP.js +0 -1
  81. package/dist/assets/index-WCosiqtQ.js +0 -1
  82. package/dist/assets/index-vsZbkVMv.js +0 -1
  83. package/dist/assets/login-page-BYwtRBMd.js +0 -1
  84. package/dist/assets/page-not-found-Cfte6bjZ.js +0 -1
  85. package/dist/assets/report-commentary-row-B-uxVnyO.js +0 -1
  86. package/dist/assets/save-qyt28nOG.js +0 -6
  87. package/dist/assets/sub-LLu8afpC.js +0 -1
  88. package/dist/assets/subMonths-C1UIPrOU.js +0 -1
@@ -0,0 +1 @@
1
+ import{j as e,T as se,B as q,aq as ae,cf as ne,a as D,fx as te,r as x,U as H,fy as le,fz as z,k as G,t as f,l as oe,fA as ie,de as V,bR as u,bS as k,a4 as de,fB as ce,a5 as me,a6 as ue,a7 as xe,Q as ye,a9 as pe,bY as g,bT as S,Y as E,o as ge,p as Y,fC as he,s as Q,fD as je,fE as W,e as fe,fF as ve,fG as be,u as J,d0 as Ne,d3 as Se,d1 as Ee,d2 as we,cj as Fe,D 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-BsGG-RLV.js";function _(t){return e.jsx(se,{disabled:!t.tooltip,label:t.tooltip,children:e.jsx(q,{variant:"ghost",size:"icon",className:"size-7.5",...t,children:e.jsx(ae,{className:"size-5"})})})}const K=({isNewInsert:t=!0,defaultValues:s,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(H),[{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([]),[X,ee]=x.useState([]),P=s?.month??o,Z=G({defaultValues:{...s,month:P}}),{control:m,handleSubmit:O,formState:{dirtyFields:U},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,a)=>r.label>a.label?1:-1))},[c,T]),x.useEffect(()=>{b?.allTrainingFunds?.length&&T(b.allTrainingFunds.map(r=>({value:r.id,label:r.name})).sort((r,a)=>r.label>a.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,a)=>r.label>a.label?1:-1))},[I,T]),x.useEffect(()=>{!s?.employer&&v?.context.adminBusinessId&&B("employer",v.context.adminBusinessId,{shouldDirty:!0,shouldTouch:!0})},[B,s?.employer,v?.context.adminBusinessId]);const $=r=>{const a=ge(r,U);if(!(t&&(!a?.directPaymentAmount||!a?.employeeId||!a?.employer||!a?.month)))if(a&&Object.keys(a).length>0){if(!t){if(!s)return;a.employeeId??=s.employeeId,a.month??=s.month}d(a)}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($),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(V,{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:s?.employer,rules:{required:"Required"},render:({field:r,fieldState:a})=>e.jsx(k,{...r,data:i,value:r.value,disabled:n,label:"Employer",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:a.error?.message})}),e.jsx(de,{name:"chargeId",control:m,defaultValue:s?.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:s?.employeeId,rules:{required:"Required"},render:({field:r,fieldState:a})=>e.jsx(k,{...r,data:X,value:r.value,disabled:M,label:"Employee",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:a.error?.message})})]}),e.jsxs("div",{className:"flex-row px-10 h-max justify-start block",children:[e.jsx(u,{name:"baseSalary",control:m,defaultValue:s?.baseSalary,render:({field:r,fieldState:a})=>e.jsx(g,{...r,value:r.value??void 0,error:a.error?.message,label:"Base Salary",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"globalAdditionalHours",control:m,defaultValue:s?.globalAdditionalHours,render:({field:r,fieldState:a})=>e.jsx(g,{...r,value:r.value??void 0,error:a.error?.message,label:"Global Additional Hours",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"bonus",control:m,defaultValue:s?.bonus,render:({field:r,fieldState:a})=>e.jsx(g,{...r,value:r.value??void 0,error:a.error?.message,label:"Bonus",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"gift",control:m,defaultValue:s?.gift,render:({field:r,fieldState:a})=>e.jsx(g,{...r,value:r.value??void 0,error:a.error?.message,label:"Gift",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"travelAndSubsistence",control:m,defaultValue:s?.travelAndSubsistence,render:({field:r,fieldState:a})=>e.jsx(g,{...r,value:r.value??void 0,error:a.error?.message,label:"Travel and Subsistence",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"recovery",control:m,defaultValue:s?.recovery,render:({field:r,fieldState:a})=>e.jsx(g,{...r,value:r.value??void 0,error:a.error?.message,label:"Recovery",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency"}})}),e.jsx(u,{name:"vacationTakeout",control:m,defaultValue:s?.vacationTakeout,render:({field:r,fieldState:a})=>e.jsx(g,{...r,value:r.value??void 0,error:a.error?.message,label:"Vacation Takeout",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"directPaymentAmount",control:m,defaultValue:s?.directPaymentAmount,rules:{required:"Required"},render:({field:r,fieldState:a})=>e.jsx(g,{...r,value:r.value??void 0,error:a.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:s?.pensionFundId,render:({field:r,fieldState:a})=>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:a.error?.message})}),e.jsx(u,{name:"pensionEmployeeAmount",control:m,defaultValue:s?.pensionEmployeeAmount,render:({field:r,fieldState:a})=>e.jsx(g,{...r,value:r.value??void 0,error:a.error?.message,label:"Pension Employee Amount",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"pensionEmployeePercentage",control:m,defaultValue:s?.pensionEmployeePercentage,render:({field:{value:r,...a},fieldState:h})=>e.jsx(S,{...a,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:s?.pensionEmployerAmount,render:({field:r,fieldState:a})=>e.jsx(g,{...r,value:r.value??void 0,error:a.error?.message,label:"Pension Employer Amount",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"pensionEmployerPercentage",control:m,defaultValue:s?.pensionEmployerPercentage,render:({field:{value:r,...a},fieldState:h})=>e.jsx(S,{...a,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:s?.compensationsEmployerAmount,render:({field:r,fieldState:a})=>e.jsx(g,{...r,value:r.value??void 0,error:a.error?.message,label:"Compensations Amount",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"compensationsEmployerPercentage",control:m,defaultValue:s?.compensationsEmployerPercentage,render:({field:{value:r,...a},fieldState:h})=>e.jsx(S,{...a,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:s?.trainingFundId,render:({field:r,fieldState:a})=>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:a.error?.message})}),e.jsx(u,{name:"trainingFundEmployeeAmount",control:m,defaultValue:s?.trainingFundEmployeeAmount,render:({field:r,fieldState:a})=>e.jsx(g,{...r,value:r.value??void 0,error:a.error?.message,label:"Training Employee Amount",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"trainingFundEmployeePercentage",control:m,defaultValue:s?.trainingFundEmployeePercentage,render:({field:{value:r,...a},fieldState:h})=>e.jsx(S,{...a,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:s?.trainingFundEmployerAmount,render:({field:r,fieldState:a})=>e.jsx(g,{...r,value:r.value??void 0,error:a.error?.message,label:"Training Employer Amount",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"trainingFundEmployerPercentage",control:m,defaultValue:s?.trainingFundEmployerPercentage,render:({field:{value:r,...a},fieldState:h})=>e.jsx(S,{...a,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:s?.socialSecurityAmountEmployee,render:({field:r,fieldState:a})=>e.jsx(g,{...r,value:r.value??void 0,error:a.error?.message,label:"Social Security - Employee",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"socialSecurityAmountEmployer",control:m,defaultValue:s?.socialSecurityAmountEmployer,render:({field:r,fieldState:a})=>e.jsx(g,{...r,value:r.value??void 0,error:a.error?.message,label:"Social Security - Employer",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"healthPaymentAmount",control:m,defaultValue:s?.healthPaymentAmount,render:({field:r,fieldState:a})=>e.jsx(g,{...r,value:r.value??void 0,error:a.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:s?.taxAmount,render:({field:r,fieldState:a})=>e.jsx(g,{...r,value:r.value??void 0,error:a.error?.message,label:"Income Tax",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"zkufot",control:m,defaultValue:s?.zkufot,render:({field:r,fieldState:a})=>e.jsx(g,{...r,value:r.value??void 0,error:a.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:s?.workDays,render:({field:{value:r,...a},fieldState:h})=>e.jsx(S,{...a,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:s?.addedVacationDays,render:({field:{value:r,...a},fieldState:h})=>e.jsx(S,{...a,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:s?.vacationDaysBalance,render:({field:{value:r,...a},fieldState:h})=>e.jsx(S,{...a,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:s?.sicknessDaysBalance,render:({field:{value:r,...a},fieldState:h})=>e.jsx(S,{...a,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($),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(U).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"})]})]})})},Ue="updateSalaryRecord",$e=()=>{const[{fetching:t},s]=Y(he),o=x.useCallback(async d=>{const l=`Error updating salary record [${d.salaryRecord.month}] employee [${d.salaryRecord.employeeId}]`,i=Ue;f.loading("Updating Salary Record",{id:i});try{const n=await s(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})}},[s]);return{fetching:t,updateSalaryRecord:o}},qe=({recordVariables:t,onDone:s})=>t?e.jsx(He,{recordVariables:t,onDone:s}):null,He=({recordVariables:t,onDone:s})=>{const{updateSalaryRecord:o,fetching:d}=$e(),[{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=>{s(),j&&o({salaryRecord:j})},[s,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(W,{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:s,children:i||!n?e.jsx(fe,{className:"flex self-center my-5",color:"dark",size:"xl",variant:"dots"}):e.jsx(K,{isNewInsert:!1,defaultValues:y,onDone:c,isModifying:d})})},ze="insertSalaryRecords",Ge=()=>{const[{fetching:t},s]=Y(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 s(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})}},[s]);return{fetching:t,insertSalaryRecord:o}},Ve=({insertSalaryRecordParams:t,setInsertSalaryRecord:s})=>{const{insertSalaryRecord:o,fetching:d}=Ge(),l=x.useCallback(i=>{i&&o({salaryRecords:[i]}),s(void 0)},[s,o]);return e.jsx(W,{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:()=>s(void 0),children:e.jsx(K,{isNewInsert:!0,onDone:l,isModifying:d,month:t.month})})};function L(){const t=new Date,s=E(t,"yyyy-MM-dd"),o=E(be(t),"yyyy-MM-dd");return{fromDate:s,toDate:o}}function Ye({filter:t,setFilter:s,closeModal:o}){const{control:d,handleSubmit:l,setValue:i}=G({defaultValues:{...t}}),[n,c]=x.useState([]),{userContext:y}=x.useContext(H),[{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,s(p),o()};function I(){s({...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(V,{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:s}){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)||s(c)},[t,s]);return e.jsxs("div",{className:"flex flex-row gap-5 items-center",children:[e.jsx(Ee,{opened:o,onClose:()=>d(!1),content:e.jsx(Ye,{filter:t,setFilter:n,closeModal:()=>d(!1)}),modalSize:"xl"}),e.jsx(q,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>d(!0),children:e.jsx(we,{className:"size-5"})})]})}const We=({month:t,setInsertSalaryRecord:s})=>{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(_,{onClick:s})})})]})})})},Je=({data:t})=>{const{employee:s,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:s?.name}),e.jsx("p",{className:"text-base font-medium text-gray-800",children:d})]})})})},_e=({data:t})=>{const{pensionEmployeeAmount:s,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}),!!s?.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:[s?.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}%)`]})]})]})})})},Ke=({data:t})=>{const{healthInsuranceAmount:s,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})]})]}),!!s?.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:s?.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})]})]})]})})})},Xe=({data:t})=>{const{baseAmount:s,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:s?.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:s,workDays:o,sicknessDays:d}=w(Pe,t),{added:l,taken:i,balance:n}=s??{},{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:s})=>{const o=w(Te,s);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(Xe,{data:o}),e.jsx(_e,{data:o}),e.jsx(Ke,{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"})]})},sr=({setEditSalaryRecord:t,setInsertSalaryRecord:s,data:o})=>{const d=o?.map(l=>w(ke,l))??[];return e.jsxs(e.Fragment,{children:[e.jsx("tr",{className:"h-3"}),e.jsx(We,{month:d[0].month,setInsertSalaryRecord:s}),e.jsx("tr",{className:"h-3"}),d.map(l=>e.jsx(rr,{data:l,setEditSalaryRecord:()=>t(l.employee?.id)},`${l.month} ${l.employee?.id}`))]})},ar=({setEditSalaryRecord:t,setInsertSalaryRecord:s,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(sr,{data:i,setEditSalaryRecord:n=>t(n?{month:l,employeeId:n}:void 0),setInsertSalaryRecord:()=>s({month:l})},l))})})})]})})},tr=()=>{const{setFiltersContext:t}=x.useContext(Be),[s,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(_,{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(ar,{setEditSalaryRecord:o,setInsertSalaryRecord:l,data:y?.salaryRecordsByDates}),e.jsx(qe,{recordVariables:s,onDone:()=>o(void 0)}),d&&e.jsx(Ve,{insertSalaryRecordParams:d,setInsertSalaryRecord:l})]})};export{tr as Salaries};
@@ -0,0 +1 @@
1
+ import{j as e,ds as D,dw as t,Y as y,cV as n,D as N,eQ as v,d0 as T,r as d,u as w,d3 as A,ao as I,ap as O,B as S,d2 as P,ar as L,k as M,dk as U,l as V,a4 as f,a5 as C,a6 as R,a7 as q,aQ as B,a9 as F,aO as k,aC as Q,F as $,U as _,a as z,c as H,w as G,dq as J,dr as K,dt as o,dv as W,eR as X}from"./index-BsGG-RLV.js";const Z=({record:a})=>{const s=N(v,a);return e.jsxs(D,{children:[e.jsx(t,{children:a.description}),e.jsx(t,{children:y(new Date(a.purchaseDate),"dd/MM/yyyy")}),e.jsx(t,{children:a.activationDate?y(new Date(a.activationDate),"dd/MM/yyyy"):void 0}),e.jsx(t,{children:s.originalCost?n(s.originalCost,0):void 0}),e.jsx(t,{children:s.reportYearDelta?n(s.reportYearDelta,0):void 0}),e.jsx(t,{children:n(s.totalDepreciableCosts,0)}),e.jsxs(t,{children:[n(a.statutoryDepreciationRate,0),"%"]}),e.jsx(t,{children:a.claimedDepreciationRate?`${n(a.claimedDepreciationRate,1)}%`:"-"}),e.jsx(t,{children:s.reportYearClaimedDepreciation?n(s.reportYearClaimedDepreciation,0):"-"}),e.jsx(t,{children:s.pastYearsAccumulatedDepreciation?n(s.pastYearsAccumulatedDepreciation,0):"-"}),e.jsx(t,{children:s.totalDepreciation?n(s.totalDepreciation,0):"-"}),e.jsx(t,{children:s.netValue?n(s.netValue,0):"-"})]})};function Y(a){return!a||T(a)?null:encodeURIComponent(JSON.stringify(a))}const b="depreciationReportFilters";function ee({filter:a,setFilter:s,close:r}){const p=M({defaultValues:{...a}}),{control:c,handleSubmit:x}=p,{selectableFinancialEntities:u,fetching:l}=U(),j=i=>{s({...i,year:Number(i.year)}),r()};return e.jsx(V,{...p,children:e.jsxs("form",{onSubmit:x(j),className:"space-y-4",children:[e.jsx(f,{name:"year",control:c,rules:{required:"Year is required",validate:i=>{const m=Number(i);return Number.isNaN(m)||m<2e3||m>2100?"Invalid year":!0}},render:({field:i})=>e.jsxs(C,{children:[e.jsx(R,{children:"Year"}),e.jsx(q,{children:e.jsx(B,{...i,hideControls:!0,decimalScale:0})}),e.jsx(F,{})]})}),e.jsx(f,{name:"financialEntityId",defaultValue:a?.financialEntityId,control:c,render:({field:i})=>e.jsxs(C,{children:[e.jsx(R,{children:"Owner"}),e.jsx(k,{...i,data:u,value:i.value??void 0,disabled:l,placeholder:"Select a financial entity",formPart:!0}),e.jsx(F,{})]})}),e.jsx(Q,{children:e.jsx(S,{type:"submit",disabled:l,children:"Filter"})})]})})}function ae({filter:a,setFilter:s}){const[r,p]=d.useState(!1),{get:c,set:x}=w();d.useEffect(()=>{const l=Y(a),j=c(b);l!==j&&x(b,l)},[a,c,x]);const u=d.useCallback(l=>{A(l,a)||s(l)},[a,s]);return e.jsxs(I,{open:r,onOpenChange:p,children:[e.jsx(O,{asChild:!0,children:e.jsx(S,{variant:"outline",size:"icon",children:e.jsx(P,{size:20})})}),e.jsx(L,{className:"sm:max-w-[425px]",children:e.jsx(ee,{filter:a,setFilter:u,close:()=>p(!1)})})]})}const g=({data:a,groupName:s})=>{const r=N(v,a);return e.jsxs(D,{className:"font-bold border-b border-black",children:[e.jsx(t,{children:s?"Group Total":"Overall Total"}),e.jsx(t,{colSpan:2,children:s}),e.jsx(t,{children:r.originalCost?n(r.originalCost,0):void 0}),e.jsx(t,{children:r.reportYearDelta?n(r.reportYearDelta,0):void 0}),e.jsx(t,{children:r.totalDepreciableCosts?n(r.totalDepreciableCosts,0):void 0}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{children:r.reportYearClaimedDepreciation?n(r.reportYearClaimedDepreciation,0):void 0}),e.jsx(t,{children:r.pastYearsAccumulatedDepreciation?n(r.pastYearsAccumulatedDepreciation,0):void 0}),e.jsx(t,{children:r.totalDepreciation?n(r.totalDepreciation,0):void 0}),e.jsx(t,{children:r.netValue?n(r.netValue,0):void 0})]})};function te(a){const s=new URLSearchParams,r=Y(a);return r&&s.append(b,r),`/reports/depreciation${s.size>0?`?${s}`:""}`}const re=()=>{const{setFiltersContext:a}=d.useContext($),{userContext:s}=d.useContext(_),{get:r}=w(),p=d.useMemo(()=>{const i={financialEntityId:s?.context.adminBusinessId,year:new Date().getFullYear()},m=r(b);if(m)try{return JSON.parse(decodeURIComponent(m))}catch(h){console.error("Failed to parse depreciation report filters from URL",h)}return i},[s?.context.adminBusinessId]),[c,x]=d.useState(p),[{data:u,fetching:l}]=z({query:X,variables:{filters:c}});d.useEffect(()=>{a(e.jsx("div",{className:"flex flex-row gap-x-5",children:e.jsx(ae,{filter:c,setFilter:x})}))},[c,a,x]);const j=d.useMemo(()=>`Depreciation Report for ${c.year}`,[c.year]);return e.jsx(H,{title:"Depreciation Report",description:j,children:l?e.jsx(G,{}):e.jsxs(J,{children:[e.jsxs(K,{children:[e.jsxs(D,{className:"font-bold text-xl",children:[e.jsx(o,{colSpan:6,className:"text-center border-x",children:"List of Assets and Costs"}),e.jsx(o,{colSpan:5,className:"text-center border-x",children:"Depreciation"}),e.jsx(o,{className:"text-center border-x",children:"Remaining"})]}),e.jsxs(D,{className:"border-b border-black",children:[e.jsx(o,{className:"whitespace-normal",children:"Assets List and Descriptions"}),e.jsx(o,{className:"whitespace-normal",children:"Date of Purchase"}),e.jsx(o,{className:"whitespace-normal",children:"Activation Date"}),e.jsx(o,{className:"whitespace-normal",children:"Original Cost"}),e.jsx(o,{className:"whitespace-normal",children:"Changes During the Year"}),e.jsx(o,{className:"whitespace-normal",children:"Total Depreciable Assets"}),e.jsx(o,{className:"whitespace-normal",children:"Statutory Depreciation Rate"}),e.jsx(o,{className:"whitespace-normal",children:"Claimed Depreciation Rate"}),e.jsx(o,{className:"whitespace-normal",children:"Depreciation Claimed This Year"}),e.jsx(o,{className:"whitespace-normal",children:"Previous Tax Years Accumulated Depreciation"}),e.jsx(o,{className:"whitespace-normal",children:"Total Depreciation"}),e.jsx(o,{className:"whitespace-normal",children:"Net Book Value"})]})]}),e.jsx(W,{children:u?.depreciationReport&&e.jsxs(e.Fragment,{children:[u.depreciationReport.categories.map((i,m)=>e.jsxs(d.Fragment,{children:[e.jsxs(D,{className:"font-bold",children:[e.jsx(t,{children:`Category ${m+1}`}),e.jsx(t,{colSpan:2,children:i.category.name}),e.jsx(t,{colSpan:3}),e.jsxs(t,{children:[n(i.category.percentage,0),"%"]}),e.jsx(t,{colSpan:5})]}),i.records.sort((h,E)=>h.purchaseDate.localeCompare(E.purchaseDate)).map(h=>e.jsx(Z,{record:h},h.id)),e.jsx(g,{data:i.summary,groupName:i.category.name})]},i.id)),e.jsx(g,{data:u.depreciationReport.summary})]})})]})})};export{re as DepreciationReport,te as getDepreciationReportHref};
@@ -0,0 +1 @@
1
+ import{j as e,a4 as C,a5 as p,a6 as S,a7 as y,aQ as N,a9 as I,Q as L,p as F,g0 as H,r as u,t as m,s as E,ao as M,ap as R,B as x,ca as Q,ar as T,as as A,at as $,a as q,g1 as _,L as O,k as P,l as K,o as z,g2 as V,F as G,dm as J,c as W,dq as X,dr as Y,ds as b,dt as Z,du as v,dv as ee,dw as h,g3 as se,dC as te,dD as oe,dE as re}from"./index-BsGG-RLV.js";import{D as ne}from"./data-table-pagination-CQQBbtVE.js";import{A as k}from"./arrow-up-down-Bt3_puEZ.js";function U({isInsert:s,formManager:n}){const{control:o}=n;return e.jsxs(e.Fragment,{children:[e.jsx(C,{name:"key",control:o,disabled:!s,rules:{required:"Required",validate:{positive:t=>Number(t)>0||"Key must be a positive number",integer:t=>Number.isInteger(Number(t))||"Key must be an integer"}},render:({field:t})=>e.jsxs(p,{children:[e.jsx(S,{children:"Key"}),e.jsx(y,{children:e.jsx(N,{...t,value:t.value??void 0,hideControls:!0,decimalScale:0,thousandSeparator:"",required:!0})}),e.jsx(I,{})]})}),e.jsx(C,{name:"name",control:o,rules:{required:"Required",minLength:{value:2,message:"Must be at least 2 characters"}},render:({field:t})=>e.jsxs(p,{children:[e.jsx(S,{children:"Name"}),e.jsx(y,{children:e.jsx(L,{...t,value:t.value??void 0,required:!0})}),e.jsx(I,{})]})}),e.jsx(C,{name:"defaultIrsCode",control:o,render:({field:t})=>e.jsxs(p,{children:[e.jsx(S,{children:"Default IRS Code"}),e.jsx(y,{children:e.jsx(N,{...t,value:t.value??void 0,hideControls:!0,decimalScale:0})}),e.jsx(I,{})]})})]})}const ae="updateSortCode",de=()=>{const[{fetching:s},n]=F(H),o=u.useCallback(async t=>{const d=`Error updating sort code ID [${t.key}]`,r=`${ae}-${t.key}`;m.loading("Updating Sort Code...",{id:r});try{const a=await n(t),i=E(a,d,r,"updateSortCode");if(i)return m.success("Success",{id:r,description:"SortCode updated"}),i.updateSortCode}catch(a){console.error(`${d}: ${a}`),m.error("Error",{id:r,description:d,duration:1e5,closeButton:!0})}return!1},[n]);return{fetching:s,updateSortCode:o}};function ie({sortCodeKey:s,onAdd:n}){const[o,t]=u.useState(!1);return e.jsxs(M,{open:o,onOpenChange:t,children:[e.jsx(R,{asChild:!0,children:e.jsx(x,{variant:"outline",size:"icon",children:e.jsx(Q,{})})}),e.jsxs(T,{className:"w-[400px] max-w-screen-md",children:[e.jsx(A,{children:e.jsx($,{children:"Edit Sort Code"})}),e.jsx(le,{sortCodeKey:s,close:()=>t(!1),onAdd:n})]})]})}function le({sortCodeKey:s,close:n,onAdd:o}){const[{data:t,fetching:d}]=q({query:_,variables:{key:s}}),r=t?.sortCode;return!r&&!d&&m.error("Error",{description:"Couldn't find sort code"}),d?e.jsx(O,{className:"h-10 w-10 animate-spin"}):r?e.jsx(ce,{sortCode:r,close:n,onAdd:o}):e.jsx("div",{children:"Sort code not found"})}function ce({sortCode:s,close:n,onAdd:o}){const t=P({defaultValues:s}),{handleSubmit:d,formState:{dirtyFields:r}}=t,{updateSortCode:a,fetching:i}=de(),l=({key:c,...B})=>{const g=z(B,r);if(g&&Object.keys(g).length>0){let w;if(g.defaultIrsCode){const j=g.defaultIrsCode,f=Number(j);if(!Number.isInteger(f)||f<2||f>9999)throw new Error(`Invalid IRS code: ${j}`);w=f}a({fields:{...g,defaultIrsCode:w},key:s.key}).then(j=>{j&&(o?.(s.key),n())})}};return e.jsx(K,{...t,children:e.jsxs("form",{onSubmit:d(l),children:[e.jsx("div",{className:"flex flex-col gap-4 my-4",children:e.jsx(U,{isInsert:!1,formManager:t})}),e.jsx("div",{className:"flex justify-end mt-4",children:e.jsx(x,{type:"submit",disabled:i,children:"Update"})})]})})}const ue="addSortCode",me=()=>{const[{fetching:s},n]=F(V),o=u.useCallback(async t=>{const d=`Error adding new sort code [${t.name}]`,r=`${ue}-${t.name}`;m.loading("Adding sort code",{id:r});try{const a=await n(t);E(a,d,r)&&m.success("Success",{id:r,description:`"${t.name}" sort code was successfully added`})}catch(a){console.error(`${d}: ${a}`),m.error("Error",{id:r,description:d,duration:1e5,closeButton:!0})}},[n]);return{fetching:s,addSortCode:o}};function xe({onAdd:s}){const[n,o]=u.useState(!1);return e.jsxs(M,{open:n,onOpenChange:o,children:[e.jsx(R,{asChild:!0,children:e.jsx(x,{children:"Add Sort Code"})}),e.jsxs(T,{className:"w-[90vw] max-w-screen-md",children:[e.jsx(A,{children:e.jsx($,{children:"Add New Sort Code"})}),e.jsx(ge,{close:()=>o(!1),onAdd:s})]})]})}function ge({close:s,onAdd:n}){const o=P({}),{handleSubmit:t}=o,{addSortCode:d,fetching:r}=me(),a=i=>{i.key&&=parseInt(i.key.toString()),i.defaultIrsCode&&=parseInt(i.defaultIrsCode.toString()),d(i).then(()=>{s(),n?.()})};return e.jsx(K,{...o,children:e.jsxs("form",{onSubmit:t(a),children:[e.jsx("div",{className:"flex flex-col gap-4 my-4",children:e.jsx(U,{isInsert:!0,formManager:o})}),e.jsx("div",{className:"flex justify-end mt-4",children:e.jsx(x,{type:"submit",disabled:r,children:"Add Sort Code"})})]})})}const D=[{id:"key",accessorKey:"key",cell:({row:s})=>e.jsx(h,{children:s.original.key}),header:({column:s})=>e.jsxs(x,{variant:"ghost",onClick:()=>s.toggleSorting(s.getIsSorted()==="asc"),children:["Key",e.jsx(k,{})]})},{id:"name",accessorKey:"name",cell:({row:s})=>e.jsx(h,{children:s.original.name}),header:({column:s})=>e.jsxs(x,{variant:"ghost",onClick:()=>s.toggleSorting(s.getIsSorted()==="asc"),children:["Name",e.jsx(k,{})]})},{id:"defaultIrsCode",accessorKey:"defaultIrsCode",cell:({row:s})=>e.jsx(h,{className:"flex flex-wrap gap-1 p-1",children:s.original.defaultIrsCode&&e.jsx(x,{variant:"outline",disabled:!0,className:"p-1 w-15",children:s.original.defaultIrsCode})}),header:"Default IRS Code"},{id:"edit",cell:({row:s})=>e.jsx(ie,{sortCodeKey:s.original.key,onAdd:s.original.refetchSortCodes})}],Ce=()=>{const[{data:s,fetching:n,error:o},t]=q({query:se}),{setFiltersContext:d}=u.useContext(G),r=u.useMemo(()=>s?.allSortCodes?.map(l=>({...l,refetchSortCodes:t}))??[],[s?.allSortCodes,t]),a=J({data:r,columns:D,getCoreRowModel:re(),getPaginationRowModel:oe(),getSortedRowModel:te(),initialState:{pagination:{pageSize:100}}}),i=a.getPageOptions();return u.useEffect(()=>{d(e.jsx("div",{className:"flex items-center justify-end gap-10 space-x-2 py-4",children:e.jsx(ne,{table:a})}))},[d,a,i]),u.useEffect(()=>{o&&(console.error("Error fetching sort codes",o),m.error("Error",{description:"Error fetching sort codes"}))},[o]),e.jsx(W,{title:`Sort Codes (${r.length})`,description:"All sort codes",headerActions:e.jsx(xe,{onAdd:()=>t()}),children:n?e.jsx("div",{className:"flex flex-row justify-center",children:e.jsx(O,{className:"h-10 w-10 animate-spin mr-2"})}):e.jsx("div",{className:"flex flex-col gap-4 rounded-md border",children:e.jsxs(X,{children:[e.jsx(Y,{children:a.getHeaderGroups().map(l=>e.jsx(b,{children:l.headers.map(c=>e.jsx(Z,{children:c.isPlaceholder?null:v(c.column.columnDef.header,c.getContext())},c.id))},l.id))}),e.jsx(ee,{children:a.getRowModel().rows.length===0?e.jsx(b,{children:e.jsx(h,{colSpan:D.length,className:"text-center py-8",children:"No sort codes found"})}):a.getRowModel().rows.map(l=>e.jsx(b,{children:l.getVisibleCells().map(c=>e.jsx(h,{children:v(c.column.columnDef.cell,c.getContext())},c.id))},l.id))})]})})})};export{Ce as SortCodes};
@@ -1,2 +1,2 @@
1
- import{r as F,j as r,g as W,a as X,fa as q,L as E,u as G,ad as H,cX as $,cY as K,B as U,cZ as ee,Q as te,ca as ne,bL as se,bM as oe,d9 as O,G as S,fb as T,c_ as re,F as ie,c as ae,X as le,Z as ce,a0 as ue}from"./index-CN7VPpiB.js";import{A as fe,a as he,c as de,b as pe}from"./accordion-lOk81yKP.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:a,N:o,j:h,M:l,Z:u,stack_top:x}=e;for(;;)switch(n){case 0:{e:for(;o>0&&l>0;){t.fill(0,0,2*u);const V=o-l,_=o+l,B=_&1,Y=a+o-1,Q=h+l-1,J=(_+B)/2;let P;t:for(let M=0;M<=J;M++){const L=2*Math.max(0,M-l)-M,I=M-2*Math.max(0,M-o);for(let f=L;f<=I;f+=2){const A=t[f-1-u*Math.floor((f-1)/u)],R=t[f+1-u*Math.floor((f+1)/u)],w=f===-M||f!==M&&A<R?R:A+1,k=w-f;let b=w,C=k;for(;b<o&&C<l&&s(a+b,h+C);)b++,C++;if(t[f-u*Math.floor(f/u)]=b,B===1&&(P=V-f)>=1-M&&P<M&&b+t[u+P-u*Math.floor(P/u)]>=o)if(M>1||b!==w){i[x++]=a+b,i[x++]=o-b,i[x++]=h+C,i[x++]=l-C,o=w,l=k,u=2*(Math.min(o,l)+1);continue e}else break t}for(let f=L;f<=I;f+=2){const A=t[u+f-1-u*Math.floor((f-1)/u)],R=t[u+f+1-u*Math.floor((f+1)/u)],w=f===-M||f!==M&&A<R?R:A+1,k=w-f;let b=w,C=k;for(;b<o&&C<l&&s(Y-b,Q-C);)b++,C++;if(t[u+f-u*Math.floor(f/u)]=b,B===0&&(P=V-f)>=-M&&P<=M&&b+t[P-u*Math.floor(P/u)]>=o)if(M>0||b!==w){i[x++]=a+o-w,i[x++]=w,i[x++]=h+l-k,i[x++]=k,o=o-b,l=l-C,u=2*(Math.min(o,l)+1);continue e}else break t}}if(o!==l){l>o?(a+=o,h+=o,l-=o,o=0):(a+=l,h+=l,o-=l,l=0);break}}if(o+l!==0)if(e.pxe===a||e.pye===h)e.pxe=a+o,e.pye=h+l;else{const V=e.pxs;if(e.oxs=e.pxs,e.oxe=e.pxe,e.oys=e.pys,e.oye=e.pye,e.pxs=a,e.pxe=a+o,e.pys=h,e.pye=h+l,V>=0)return e.i=a,e.N=o,e.j=h,e.M=l,e.Z=u,e.stack_top=x,1}}case 1:{if(x===0)return 2;l=i[--x],h=i[--x],o=i[--x],a=i[--x],u=2*(Math.min(o,l)+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 a=(Math.min(n,s)+1)*2,o=n+s,h=new(o<256?Uint8Array:o<65536?Uint16Array:Uint32Array)(2*a);return new m({i:e,N:n,j:t,M:s,Z:a,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,a]=[0,e.length,n.length];if(typeof t=="function"){for(;s<i&&s<a&&t(s,s);)s++;if(s===i&&s===a)return[][Symbol.iterator]();for(;t(--i,--a)&&i>s&&a>s;);}else{for(;s<i&&s<a&&e[s]===n[s];)s++;if(s===i&&s===a)return[][Symbol.iterator]();for(;e[--i]===n[--a]&&i>s&&a>s;);t=(o,h)=>e[o]===n[h]}return D(s,i+1-s,s,a+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:l,j:u,N:x}=this;return l<x&&(n.done=!1,n.value=[l,u,x-l],this.i=x),n}const t=n.value,s=t[0],i=t[1],a=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=a,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,a,o]of n)t<i&&(yield s.call(e,t,i)),o.length>0&&(yield o),t=a;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[a,o,h,l]of d(e,n,t))s<a&&(yield[0,i.call(e,s,a)]),a<o&&(yield[-1,i.call(e,a,o)]),h<l&&(yield[1,i.call(n,h,l)]),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}),z=({children:c})=>r.jsx("span",{children:c}),ge=({content:c,contentOrigin:m,monthDate:D})=>{const d=F.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(""),z]),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(""),z]);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((a,o)=>{n.push(r.jsx(s,{children:a},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(W,{className:"text-green-500"})]}),!!d.length&&d]})},Me=({filter:c})=>{const[{data:m,fetching:D,hasNext:d}]=X({query:q,variables:c}),p=F.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]=F.useState(!1),{get:p,set:y}=G(),{userContext:g}=F.useContext(H);function N(j){j||={businessId:g?.context.adminBusinessId??c.businessId,fromMonthDate:S(T(new Date),"yyyy-MM-15"),toMonthDate:S(new Date,"yyyy-MM-15")},re(j,c)||m(j)}return F.useEffect(()=>{const j=$(c??{})?null:encodeURIComponent(JSON.stringify(c)),e=p("validateReportsFilters");j!==e&&y("validateReportsFilters",j)},[c,p,y]),r.jsxs(r.Fragment,{children:[r.jsx(K,{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}=G(),{setFiltersContext:m}=F.useContext(ie),D=F.useMemo(()=>{try{if(c("validateReportsFilters"))return JSON.parse(decodeURIComponent(c("validateReportsFilters")))}catch(y){console.error("Error parsing filter from URL",y)}return{fromMonthDate:S(T(new Date),"yyyy-MM-15"),toMonthDate:S(new Date,"yyyy-MM-15")}},[c]),[d,p]=F.useState(D);return F.useEffect(()=>{m(r.jsx("div",{className:"flex flex-row gap-2",children:r.jsx(ve,{filter:{...d},setFilter:p})}))},[d,m]),r.jsx(ae,{title:"Report Validations",children:r.jsx(fe,{type:"single",collapsible:!0,children:r.jsx(he,{value:"pcn874",children:r.jsxs(le,{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 F,j as r,g as W,a as $,fd as q,L as E,u as Y,U as H,d0 as K,d1 as X,B as U,d2 as ee,k as te,cf as ne,bR as se,bS as oe,de as O,Y as S,fe as G,d3 as re,F as ie,c as le,$ as ae,a1 as ce,a3 as fe}from"./index-BsGG-RLV.js";import{A as ue,a as he,c as de,b as pe}from"./accordion-_VaDHoQb.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:f,stack_top:x}=e;for(;;)switch(n){case 0:{e:for(;o>0&&a>0;){t.fill(0,0,2*f);const V=o-a,_=o+a,B=_&1,Z=l+o-1,J=h+a-1,Q=(_+B)/2;let P;t:for(let M=0;M<=Q;M++){const I=2*Math.max(0,M-a)-M,L=M-2*Math.max(0,M-o);for(let u=I;u<=L;u+=2){const A=t[u-1-f*Math.floor((u-1)/f)],R=t[u+1-f*Math.floor((u+1)/f)],w=u===-M||u!==M&&A<R?R:A+1,k=w-u;let b=w,C=k;for(;b<o&&C<a&&s(l+b,h+C);)b++,C++;if(t[u-f*Math.floor(u/f)]=b,B===1&&(P=V-u)>=1-M&&P<M&&b+t[f+P-f*Math.floor(P/f)]>=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,f=2*(Math.min(o,a)+1);continue e}else break t}for(let u=I;u<=L;u+=2){const A=t[f+u-1-f*Math.floor((u-1)/f)],R=t[f+u+1-f*Math.floor((u+1)/f)],w=u===-M||u!==M&&A<R?R:A+1,k=w-u;let b=w,C=k;for(;b<o&&C<a&&s(Z-b,J-C);)b++,C++;if(t[f+u-f*Math.floor(u/f)]=b,B===0&&(P=V-u)>=-M&&P<=M&&b+t[P-f*Math.floor(P/f)]>=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,f=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 V=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,V>=0)return e.i=l,e.N=o,e.j=h,e.M=a,e.Z=f,e.stack_top=x,1}}case 1:{if(x===0)return 2;a=i[--x],h=i[--x],o=i[--x],l=i[--x],f=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:f,N:x}=this;return a<x&&(n.done=!1,n.value=[a,f,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=F.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(W,{className:"text-green-500"})]}),!!d.length&&d]})},Me=({filter:c})=>{const[{data:m,fetching:D,hasNext:d}]=$({query:q,variables:c}),p=F.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]=F.useState(!1),{get:p,set:y}=Y(),{userContext:g}=F.useContext(H);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 F.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}=F.useContext(ie),D=F.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]=F.useState(D);return F.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(ue,{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(fe,{children:r.jsx(Me,{filter:d})})})]})})})})};export{Ce as ValidateReportsScreen};
@@ -0,0 +1 @@
1
+ import{d0 as _,r as m,u as R,d3 as V,j as e,d1 as q,bC as Q,B as I,d2 as G,k as z,cf as K,dk as X,aN as J,dl as W,bR as y,bS as A,bW as F,bX as B,Y as M,cj as E,a as U,f8 as Z,$ as P,w as $,a0 as Y,a1 as ee,av as ae,a3 as O,f9 as se,F as te,U as re,aR as ne,c as oe,a2 as le,eb as ie,fa as ce,b1 as de}from"./index-BsGG-RLV.js";import{k as ue,B as N,X as H,Y as me,l as pe,m as xe,n as ge,o as he,p as fe,q as be,r as je}from"./chart-2uS7cQLX.js";import{s as ye}from"./sub-DKnwnbwx.js";import"./sequential-CAnleQny.js";import"./subMonths-B44KizJf.js";var ve=ue({chartName:"BarChart",GraphicalChild:N,defaultTooltipEventType:"axis",validateTooltipEventTypes:["axis","item"],axisComponents:[{axisType:"xAxis",AxisComp:H},{axisType:"yAxis",AxisComp:me}],formatAxisMap:pe});function k(s){return!s||_(s)?null:encodeURIComponent(JSON.stringify(s))}const L="balanceReportFilters",x={MONTHLY:"Monthly",BI_MONTHLY:"Bi-monthly",QUARTERLY:"Quarterly",SEMI_ANNUALLY:"Semi-Annually",ANNUALLY:"Annually"};function Ce({filter:s,setFilter:n,closeModal:c}){const{control:t,handleSubmit:r,watch:g}=z({defaultValues:{...s}}),{selectableBusinesses:b,fetching:h}=K(),{selectableFinancialEntities:f,fetching:v}=X(),{selectableTags:p,fetching:j}=J(),S=a=>{n(a),c()},C=g("excludedTags"),l=m.useMemo(()=>p.filter(a=>!C.includes(a.value)),[C,p]),d=g("includedTags"),o=m.useMemo(()=>p.filter(a=>!d.includes(a.value)),[d,p]);return e.jsxs("form",{onSubmit:r(S),children:[e.jsxs(W,{cols:2,children:[e.jsx(y,{name:"ownerId",control:t,defaultValue:s?.ownerId,render:({field:a,fieldState:i})=>e.jsx(A,{...a,data:b,value:a.value,disabled:h,label:"Owners",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:i.error?.message,withinPortal:!0})}),e.jsx(y,{name:"fromDate",control:t,defaultValue:s?.fromDate,rules:{pattern:{value:F,message:"Date must be im format yyyy-mm-dd"}},render:({field:a,fieldState:i})=>e.jsx(B,{...a,onChange:u=>{const T=u?typeof u=="string"?u:M(u,"yyyy-MM-dd"):void 0;T!==a.value&&a.onChange(T)},value:a.value?new Date(a.value):void 0,error:i.error?.message,label:"From Date",popoverProps:{withinPortal:!0}})}),e.jsx(y,{name:"toDate",control:t,defaultValue:s?.toDate,rules:{pattern:{value:F,message:"Date must be im format yyyy-mm-dd"}},render:({field:a,fieldState:i})=>e.jsx(B,{...a,onChange:u=>{const T=u?typeof u=="string"?u:M(u,"yyyy-MM-dd"):void 0;T!==a.value&&a.onChange(T)},value:a.value?new Date(a.value):void 0,error:i.error?.message,label:"To Date",popoverProps:{withinPortal:!0}})}),e.jsx(y,{name:"period",control:t,defaultValue:x.MONTHLY,render:({field:a,fieldState:i})=>e.jsx(A,{...a,data:Object.values(x).map(u=>({value:u,label:u})),value:a.value,label:"Period",maxDropdownHeight:160,error:i.error?.message,withinPortal:!0})}),e.jsx(y,{name:"excludedCounterparties",control:t,defaultValue:s.excludedCounterparties,render:({field:a,fieldState:i})=>e.jsx(E,{...a,data:f,value:a.value??[],disabled:v,label:"Excluded Counterparties",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:i.error?.message,withinPortal:!0})}),e.jsx(y,{name:"includedTags",control:t,defaultValue:s.includedTags,render:({field:a,fieldState:i})=>e.jsx(E,{...a,data:l,value:a.value??[],disabled:j,label:"Included Tags",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:i.error?.message,withinPortal:!0})}),e.jsx(y,{name:"excludedTags",control:t,defaultValue:s.excludedTags,render:({field:a,fieldState:i})=>e.jsx(E,{...a,data:o,value:a.value??[],disabled:j,label:"Excluded Tags",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:i.error?.message,withinPortal:!0})})]}),e.jsxs("div",{className:"flex justify-center mt-5 gap-3",children:[e.jsx("button",{type:"submit",disabled:h,className:"text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg",children:"Filter"}),e.jsx("button",{type:"button",className:"text-white bg-rose-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-rose-600 rounded-sm text-lg",onClick:c,children:"Cancel"})]})]})}function Te({filter:s,setFilter:n,initiallyOpened:c=!1}){const[t,r]=m.useState(c),[g,b]=m.useState(!!s),{get:h,set:f}=R();m.useEffect(()=>{const p=k(s),j=h(L);p!==j&&f(L,p)},[s,h,f]);const v=m.useCallback(p=>{V(p,s)||(n(p),b(!!p))},[s,n]);return e.jsxs("div",{className:"flex flex-row gap-5 items-center",children:[e.jsx(q,{opened:t,onClose:()=>r(!1),content:e.jsx(Ce,{filter:s,setFilter:v,closeModal:()=>r(!1)}),modalSize:"xl"}),e.jsx(Q,{inline:!0,size:16,disabled:!g,children:e.jsx(I,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>r(!0),children:e.jsx(G,{className:"size-5"})})})]})}const we=({period:s,transactionIDs:n,onCloseExtendedTransactions:c})=>{const[{data:t,fetching:r}]=U({query:Z,variables:{transactionIDs:n}}),g=m.useMemo(()=>t?.transactionsByIDs?n.map(b=>t?.transactionsByIDs.find(h=>h.id===b)).filter(Boolean):[],[t,n]);return e.jsx(P,{className:"mt-5 w-full",children:r?e.jsx($,{}):e.jsxs(e.Fragment,{children:[e.jsx(Y,{children:e.jsxs(ee,{className:"flex justify-between",children:[e.jsxs("span",{children:[s," Transactions"]}),e.jsx(I,{variant:"link",onClick:c,children:e.jsx(ae,{className:"h-4 w-4"})})]})}),e.jsx(O,{children:e.jsx(se,{transactionsProps:g})})]})})};function Be(s){const n=new URLSearchParams,c=k(s);return c&&n.append(L,c),`/reports/balance${n.size>0?`?${n}`:""}`}const w={income:{label:"Income",color:"rgba(0, 255, 50, 0.5)"},expense:{label:"Expense",color:"rgba(255, 0, 0, 0.5)"},delta:{label:"Delta",color:"rgba(0, 30, 255, 0.5)"},cumulative:{label:"Cumulative Balance",color:"rgba(100, 0, 255, 0.5)"}};function Ne(s,n,c){switch(c){case x.MONTHLY:{const t=String(n).padStart(2,"0");return`${s}-${t}`}case x.BI_MONTHLY:{const t=n%2===0?n-1:n,r=String(t).padStart(2,"0");return`${s}-${r}`}case x.QUARTERLY:{const t=Math.ceil(n/3);return`${s}-Q${t}`}case x.SEMI_ANNUALLY:{const t=n>6?2:1;return`${s}-H${t}`}case x.ANNUALLY:return String(s)}}function Se(s,n){switch(n){case x.MONTHLY:{const[c,t]=s.split("-");return`${t}/${c}`}case x.BI_MONTHLY:{const[c,t]=s.split("-"),r=Number(t)+1,g=String(r).padStart(2,"0");return`${t}-${g}/${c}`}case x.QUARTERLY:{const[c,t]=s.split("-");return`${t}, ${c}`}case x.SEMI_ANNUALLY:{const[c,t]=s.split("-");return`${t}, ${c}`}case x.ANNUALLY:return s}}const D=ie(de.Usd),De=()=>{const{setFiltersContext:s}=m.useContext(te),{userContext:n}=m.useContext(re),{get:c}=R(),t=m.useMemo(()=>{const l={ownerId:n?.context.adminBusinessId,toDate:M(new Date,"yyyy-MM-dd"),period:x.MONTHLY,fromDate:M(ye(new Date,{years:1}),"yyyy-MM-dd"),excludedCounterparties:[],includedTags:[],excludedTags:[]},d=c(L);if(d)try{return JSON.parse(decodeURIComponent(d))}catch(o){console.log("Error parsing balance report filters from URL:",o)}return l},[n?.context.adminBusinessId,c]),[r,g]=m.useState(t),[b,h]=m.useState(void 0),[f,v]=m.useState(Object.keys(w)),p=m.useMemo(()=>{const{ownerId:l,fromDate:d,toDate:o}=r;return{ownerId:l,fromDate:d,toDate:o}},[r]),[{data:j,fetching:S}]=U({query:ce,variables:p,pause:!r});m.useEffect(()=>{s(e.jsxs("div",{className:"flex flex-row gap-x-5",children:[e.jsx(Te,{filter:r,setFilter:g,initiallyOpened:!r}),e.jsx(ne,{options:Object.entries(w).map(([l,d])=>({label:d.label,value:l})),onValueChange:v,defaultValue:f,placeholder:"Select Data Sets",variant:"default",maxCount:1})]})),h(void 0)},[j,S,r,s,g,f]),m.useEffect(()=>{g(l=>({...l,ownerId:n?.context.adminBusinessId}))},[n]);const C=m.useMemo(()=>{if(!j?.transactionsForBalanceReport)return[];const l=new Map;j.transactionsForBalanceReport.map(o=>{if(o.counterparty?.id&&(!o.isFee&&n?.context.financialAccountsBusinessesIds?.includes(o.counterparty.id)||r.excludedCounterparties?.includes(o.counterparty.id))||r.includedTags.length>0&&(!o.charge?.tags||o.charge.tags.length===0||!o.charge.tags.some(u=>r.includedTags.includes(u.id)))||r.excludedTags.length>0&&o.charge?.tags.length&&o.charge.tags.some(u=>r.excludedTags.includes(u.id)))return;const a=Ne(o.year,o.month,r.period);l.has(a)||l.set(a,{income:0,expense:0,delta:0,transactions:[]});const i=l.get(a);o.amountUsd.raw>0?i.income+=o.amountUsd.raw:i.expense+=o.amountUsd.raw,i.delta+=o.amountUsd.raw,i.transactions.push(o)});let d=0;return Array.from(l.entries()).sort((o,a)=>o[0].localeCompare(a[0])).map(([o,a])=>(d+=a.delta,{period:o,income:a.income,expense:a.expense,delta:a.delta,cumulative:d,transactions:a.transactions.sort((i,u)=>Math.abs(u.amountUsd.raw)-Math.abs(i.amountUsd.raw))}))},[j,r.period,r.excludedCounterparties,n?.context.financialAccountsBusinessesIds,r.includedTags,r.excludedTags]);return e.jsx(oe,{title:"Balance Report",description:"Accounts periodical balance",children:S?e.jsx($,{}):e.jsxs(e.Fragment,{children:[e.jsxs(P,{className:"w-full",children:[e.jsx(Y,{children:e.jsx(le,{children:"Click specific period to expand it's transactions data"})}),e.jsx(O,{children:e.jsx(xe,{config:w,className:"h-150 w-full",children:e.jsxs(ve,{accessibilityLayer:!0,data:C,onClick:l=>h(l.activeLabel),children:[e.jsx(ge,{vertical:!1}),e.jsx(H,{dataKey:"period",tickLine:!1,tickMargin:10,axisLine:!1,tickFormatter:l=>Se(l,r.period)}),e.jsx(he,{content:e.jsx(fe,{formatter:(l,d,o,a)=>{const i=`bg-[var(--color-${d})]`;return a<2?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:`${i} h-2.5 w-2.5 shrink-0 rounded-[2px]`}),w[d]?.label||d,e.jsx("div",{className:"ml-auto flex items-baseline gap-0.5 font-mono font-medium tabular-nums text-foreground",children:D.format(Number(l))})]}):e.jsxs("div",{className:"mt-1.5 flex basis-full items-center border-t pt-1.5 text-xs font-medium text-foreground",children:[e.jsx("div",{className:`h-2.5 w-2.5 shrink-0 rounded-[2px] mr-2 ${i}`}),w[d]?.label||d,e.jsx("div",{className:"ml-auto flex items-baseline gap-0.5 font-mono font-medium tabular-nums text-foreground",children:D.format(Number(l))})]})}})}),e.jsx(be,{content:e.jsx(je,{})}),f.includes("income")&&e.jsx(N,{dataKey:"income",fill:"var(--color-income)",radius:4}),f.includes("expense")&&e.jsx(N,{dataKey:"expense",fill:"var(--color-expense)",radius:4}),f.includes("delta")&&e.jsx(N,{dataKey:"delta",fill:"var(--color-delta)",radius:4}),f.includes("cumulative")&&e.jsx(N,{dataKey:"cumulative",fill:"var(--color-cumulative)",radius:4})]})})})]}),b&&e.jsx(we,{period:b,onCloseExtendedTransactions:()=>h(void 0),transactionIDs:C.find(l=>l.period===b)?.transactions.map(l=>l.id)??[]})]})})};export{De as BalanceReport,Be as getBalanceReportHref};
@@ -1,2 +1,2 @@
1
- import{r as u,j as e,dP as R,G as v,W as M,f1 as $,F as k,a as B,dh as P,eI as T,c as V,L,dk as S,dl as Y,dm as d,dn as K,dp as C,dq as O,dr as t,f2 as z,dy as H,dz as q,e6 as A,a_ as _}from"./index-CN7VPpiB.js";import{D as G}from"./data-table-pagination-BnQGVnmE.js";const Q=({data:a,year:s})=>{const n=u.useCallback(async()=>{if(!a)return{fileContent:"",fileName:""};const x=M($,a),m=W(x),o=`${s}_ledger`;return{fileContent:m,fileName:o}},[a,s]);return a?e.jsx(R,{createFileVariables:n}):e.jsx("div",{})},F=[{key:"",valueFn:()=>""},{key:"",valueFn:()=>""},{key:"Counterparty",valueFn:a=>j(a.counterParty?.name??"")},{key:"Invoice Date",valueFn:a=>v(a.invoiceDate,"yyyy-MM-dd")},{key:"Value Date",valueFn:a=>v(a.valueDate,"yyyy-MM-dd")},{key:"Reference",valueFn:a=>a.reference?`"${j(a.reference)}"`:""},{key:"Description",valueFn:a=>a.description?`"${j(a.description)}"`:""},{key:"Debit Amount",valueFn:a=>a.amount.raw<0?Math.abs(a.amount.raw).toFixed(2):""},{key:"Credit Amount",valueFn:a=>a.amount.raw>=0?a.amount.raw.toFixed(2):""},{key:"Balance",valueFn:a=>a.balance.toFixed(2)}],W=a=>{const s=[F.map(({key:n})=>n).join(",")];return a.financialEntitiesInfo.map(n=>{const x=`${j(n.entity.name)},${n.entity.sortCode?.key}`,m=`,Opening Balance,,,,,,,,${n.openingBalance.raw.toFixed(2)}`,o=`Total,${j(n.entity.name)},,,,,,,${Math.abs(n.totalDebit.raw).toFixed(2)} Debit,`,g=`,,,,,,,,${n.totalCredit.raw.toFixed(2)} Credit,${n.closingBalance.raw.toFixed(2)}`,D=`,,,,,,,,${(n.totalCredit.raw-n.totalDebit.raw).toFixed(2)} Diff,`;s.push(x,m,...n.records.map(l=>F.map(({valueFn:b})=>b(l)).join(",")),o,g,D)}),s.join(`\r
2
- `)};function j(a){return a.replace(/"/g,'""').replace(/,/g,".")}const c=A(_.Ils),E=[{id:"placeholder",header:"",cell:()=>null},{id:"counterparty",accessorKey:"counterparty",header:"Counterparty",cell:({row:a})=>e.jsx("div",{className:"font-medium",children:a.original.counterParty?.name})},{id:"invoiceDate",accessorKey:"invoiceDate",header:"Invoice Date",cell:({row:a})=>{const s=new Date(a.getValue("invoiceDate")),n=v(s,"yyyy-MM-dd");return e.jsx("div",{className:"font-medium",children:n})}},{id:"valueDate",accessorKey:"valueDate",header:"Value Date",cell:({row:a})=>{const s=new Date(a.getValue("valueDate")),n=v(s,"yyyy-MM-dd");return e.jsx("div",{className:"font-medium",children:n})}},{id:"reference",accessorKey:"reference",header:"Reference"},{id:"description",accessorKey:"description",header:"Description"},{id:"debit",header:"Debit",cell:({row:a})=>{const s=a.original.amount.raw;return s<0?e.jsx("div",{className:"font-medium",children:c.format(s*-1)}):null}},{id:"credit",header:"Credit",cell:({row:a})=>{const s=a.original.amount.raw;return s>=0?e.jsx("div",{className:"font-medium",children:c.format(s)}):null}},{id:"balance",accessorKey:"balance",header:"Balance",cell:({row:a})=>e.jsx("div",{className:"font-medium",children:c.format(a.getValue("balance"))})}],I=()=>{const{setFiltersContext:a}=u.useContext(k),[s,n]=u.useState(new Date().getFullYear()-1),[{data:x,fetching:m}]=B({query:z,variables:{year:s}}),o=x?.yearlyLedgerReport,{financialEntitiesInfo:g}=o??{},D=u.useMemo(()=>g?.flatMap(r=>{const{entity:i,openingBalance:y,closingBalance:h,totalCredit:p,totalDebit:w}=r;return r.records.map(N=>({entity:i,openingBalance:y,closingBalance:h,totalCredit:p,totalDebit:w,...N}))})??[],[g]),l=P({data:D,columns:E,getCoreRowModel:q(),getPaginationRowModel:H(),initialState:{pagination:{pageSize:100}}}),b=l.getState().pagination.pageIndex;return u.useEffect(()=>{a(e.jsxs("div",{className:"flex items-center justify-end gap-10 space-x-2 py-4",children:[e.jsx("div",{className:"flex items-center justify-between px-2",children:e.jsx(G,{table:l})}),e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(T,{value:new Date(s,0,1),onChange:r=>r&&n(r?.getFullYear()),popoverProps:{withinPortal:!0},minDate:new Date(2010,0,1),maxDate:new Date}),e.jsx(Q,{data:o,year:s})]})]}))},[s,m,a,o,l,b]),e.jsx(V,{title:"Yearly Ledger Report",children:m?e.jsx(L,{className:"h-10 w-10 animate-spin mr-2 self-center"}):o?e.jsx("div",{className:"flex flex-col gap-4 rounded-md border",children:e.jsxs(S,{children:[e.jsx(Y,{children:l.getHeaderGroups().map(r=>e.jsx(d,{children:r.headers.map(i=>e.jsx(K,{children:i.isPlaceholder?null:C(i.column.columnDef.header,i.getContext())},i.id))},r.id))}),e.jsx(O,{children:l.getRowModel().rows.map((r,i)=>{const y=l.getRowModel().rows[i-1],h=l.getRowModel().rows[i+1],p=!y||y.original.entity.id!==r.original.entity.id,w=!h||h.original.entity.id!==r.original.entity.id;return e.jsxs(e.Fragment,{children:[p&&i!==0&&e.jsx(d,{className:"border-y-2 border-t-gray-300 border-b-gray-500",children:e.jsx(t,{})}),p&&e.jsx(J,{row:r}),e.jsx(d,{children:r.getVisibleCells().map(f=>e.jsx(t,{children:C(f.column.columnDef.cell,f.getContext())},f.id))},r.id),w&&e.jsx(U,{row:r})]})})})]})}):e.jsx("div",{className:"rounded-md border h-24 text-center",children:"No results."})})};function J({row:a}){return e.jsxs(e.Fragment,{children:[e.jsxs(d,{className:"bg-gray-300",children:[e.jsx(t,{children:e.jsx("div",{className:"font-medium",children:a.original.entity.name})}),e.jsx(t,{children:e.jsx("div",{className:"font-medium",children:a.original.entity.sortCode?.key})}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{})]},`${a.id}-opening1`),e.jsxs(d,{className:"bg-gray-200",children:[e.jsx(t,{}),e.jsx(t,{children:e.jsx("div",{className:"font-medium",children:"Opening Balance"})}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{children:e.jsx("div",{className:"font-medium",children:c.format(a.original.openingBalance.raw)})})]},`${a.id}-opening2`)]})}function U({row:a}){return e.jsxs(e.Fragment,{children:[e.jsxs(d,{className:"bg-gray-200",children:[e.jsx(t,{children:e.jsx("div",{className:"font-medium",children:"Total"})}),e.jsx(t,{children:e.jsx("div",{className:"font-medium",children:a.original.entity.name})}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{children:e.jsxs("div",{className:"font-medium",children:[c.format(a.original.totalDebit.raw)," Debit"]})}),e.jsx(t,{})]},`${a.id}-totals1`),e.jsxs(d,{className:"bg-gray-200",children:[e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{children:e.jsxs("div",{className:"font-medium",children:[c.format(a.original.totalCredit.raw)," Credit"]})}),e.jsx(t,{children:e.jsx("div",{className:"font-medium",children:c.format(a.original.closingBalance.raw)})})]},`${a.id}-totals2`),e.jsxs(d,{className:"bg-gray-200",children:[e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{children:e.jsxs("div",{className:"font-medium",children:[c.format(a.original.totalCredit.raw-a.original.totalDebit.raw)," Diff"]})}),e.jsx(t,{})]},`${a.id}-totals3`)]})}export{I as YearlyLedgerReport};
1
+ import{r as u,j as e,dU as R,Y as v,D as M,f4 as $,F as k,a as B,dm as P,eL as T,c as L,L as V,dq as S,dr as Y,ds as d,dt as K,du as C,dv as O,dw as t,f5 as H,dD as q,dE as z,eb as A,b1 as E}from"./index-BsGG-RLV.js";import{D as Q}from"./data-table-pagination-CQQBbtVE.js";const U=({data:a,year:s})=>{const n=u.useCallback(async()=>{if(!a)return{fileContent:"",fileName:""};const x=M($,a),m=_(x),o=`${s}_ledger`;return{fileContent:m,fileName:o}},[a,s]);return a?e.jsx(R,{createFileVariables:n}):e.jsx("div",{})},F=[{key:"",valueFn:()=>""},{key:"",valueFn:()=>""},{key:"Counterparty",valueFn:a=>j(a.counterParty?.name??"")},{key:"Invoice Date",valueFn:a=>v(a.invoiceDate,"yyyy-MM-dd")},{key:"Value Date",valueFn:a=>v(a.valueDate,"yyyy-MM-dd")},{key:"Reference",valueFn:a=>a.reference?`"${j(a.reference)}"`:""},{key:"Description",valueFn:a=>a.description?`"${j(a.description)}"`:""},{key:"Debit Amount",valueFn:a=>a.amount.raw<0?Math.abs(a.amount.raw).toFixed(2):""},{key:"Credit Amount",valueFn:a=>a.amount.raw>=0?a.amount.raw.toFixed(2):""},{key:"Balance",valueFn:a=>a.balance.toFixed(2)}],_=a=>{const s=[F.map(({key:n})=>n).join(",")];return a.financialEntitiesInfo.map(n=>{const x=`${j(n.entity.name)},${n.entity.sortCode?.key}`,m=`,Opening Balance,,,,,,,,${n.openingBalance.raw.toFixed(2)}`,o=`Total,${j(n.entity.name)},,,,,,,${Math.abs(n.totalDebit.raw).toFixed(2)} Debit,`,g=`,,,,,,,,${n.totalCredit.raw.toFixed(2)} Credit,${n.closingBalance.raw.toFixed(2)}`,D=`,,,,,,,,${(n.totalCredit.raw-n.totalDebit.raw).toFixed(2)} Diff,`;s.push(x,m,...n.records.map(l=>F.map(({valueFn:b})=>b(l)).join(",")),o,g,D)}),s.join(`\r
2
+ `)};function j(a){return a.replace(/"/g,'""').replace(/,/g,".")}const c=A(E.Ils),G=[{id:"placeholder",header:"",cell:()=>null},{id:"counterparty",accessorKey:"counterparty",header:"Counterparty",cell:({row:a})=>e.jsx("div",{className:"font-medium",children:a.original.counterParty?.name})},{id:"invoiceDate",accessorKey:"invoiceDate",header:"Invoice Date",cell:({row:a})=>{const s=new Date(a.getValue("invoiceDate")),n=v(s,"yyyy-MM-dd");return e.jsx("div",{className:"font-medium",children:n})}},{id:"valueDate",accessorKey:"valueDate",header:"Value Date",cell:({row:a})=>{const s=new Date(a.getValue("valueDate")),n=v(s,"yyyy-MM-dd");return e.jsx("div",{className:"font-medium",children:n})}},{id:"reference",accessorKey:"reference",header:"Reference"},{id:"description",accessorKey:"description",header:"Description"},{id:"debit",header:"Debit",cell:({row:a})=>{const s=a.original.amount.raw;return s<0?e.jsx("div",{className:"font-medium",children:c.format(s*-1)}):null}},{id:"credit",header:"Credit",cell:({row:a})=>{const s=a.original.amount.raw;return s>=0?e.jsx("div",{className:"font-medium",children:c.format(s)}):null}},{id:"balance",accessorKey:"balance",header:"Balance",cell:({row:a})=>e.jsx("div",{className:"font-medium",children:c.format(a.getValue("balance"))})}],I=()=>{const{setFiltersContext:a}=u.useContext(k),[s,n]=u.useState(new Date().getFullYear()-1),[{data:x,fetching:m}]=B({query:H,variables:{year:s}}),o=x?.yearlyLedgerReport,{financialEntitiesInfo:g}=o??{},D=u.useMemo(()=>g?.flatMap(r=>{const{entity:i,openingBalance:y,closingBalance:h,totalCredit:p,totalDebit:w}=r;return r.records.map(N=>({entity:i,openingBalance:y,closingBalance:h,totalCredit:p,totalDebit:w,...N}))})??[],[g]),l=P({data:D,columns:G,getCoreRowModel:z(),getPaginationRowModel:q(),initialState:{pagination:{pageSize:100}}}),b=l.getState().pagination.pageIndex;return u.useEffect(()=>{a(e.jsxs("div",{className:"flex items-center justify-end gap-10 space-x-2 py-4",children:[e.jsx("div",{className:"flex items-center justify-between px-2",children:e.jsx(Q,{table:l})}),e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(T,{value:new Date(s,0,1),onChange:r=>r&&n(r?.getFullYear()),popoverProps:{withinPortal:!0},minDate:new Date(2010,0,1),maxDate:new Date}),e.jsx(U,{data:o,year:s})]})]}))},[s,m,a,o,l,b]),e.jsx(L,{title:"Yearly Ledger Report",children:m?e.jsx(V,{className:"h-10 w-10 animate-spin mr-2 self-center"}):o?e.jsx("div",{className:"flex flex-col gap-4 rounded-md border",children:e.jsxs(S,{children:[e.jsx(Y,{children:l.getHeaderGroups().map(r=>e.jsx(d,{children:r.headers.map(i=>e.jsx(K,{children:i.isPlaceholder?null:C(i.column.columnDef.header,i.getContext())},i.id))},r.id))}),e.jsx(O,{children:l.getRowModel().rows.map((r,i)=>{const y=l.getRowModel().rows[i-1],h=l.getRowModel().rows[i+1],p=!y||y.original.entity.id!==r.original.entity.id,w=!h||h.original.entity.id!==r.original.entity.id;return e.jsxs(e.Fragment,{children:[p&&i!==0&&e.jsx(d,{className:"border-y-2 border-t-gray-300 border-b-gray-500",children:e.jsx(t,{})}),p&&e.jsx(J,{row:r}),e.jsx(d,{children:r.getVisibleCells().map(f=>e.jsx(t,{children:C(f.column.columnDef.cell,f.getContext())},f.id))},r.id),w&&e.jsx(W,{row:r})]})})})]})}):e.jsx("div",{className:"rounded-md border h-24 text-center",children:"No results."})})};function J({row:a}){return e.jsxs(e.Fragment,{children:[e.jsxs(d,{className:"bg-gray-300",children:[e.jsx(t,{children:e.jsx("div",{className:"font-medium",children:a.original.entity.name})}),e.jsx(t,{children:e.jsx("div",{className:"font-medium",children:a.original.entity.sortCode?.key})}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{})]},`${a.id}-opening1`),e.jsxs(d,{className:"bg-gray-200",children:[e.jsx(t,{}),e.jsx(t,{children:e.jsx("div",{className:"font-medium",children:"Opening Balance"})}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{children:e.jsx("div",{className:"font-medium",children:c.format(a.original.openingBalance.raw)})})]},`${a.id}-opening2`)]})}function W({row:a}){return e.jsxs(e.Fragment,{children:[e.jsxs(d,{className:"bg-gray-200",children:[e.jsx(t,{children:e.jsx("div",{className:"font-medium",children:"Total"})}),e.jsx(t,{children:e.jsx("div",{className:"font-medium",children:a.original.entity.name})}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{children:e.jsxs("div",{className:"font-medium",children:[c.format(a.original.totalDebit.raw)," Debit"]})}),e.jsx(t,{})]},`${a.id}-totals1`),e.jsxs(d,{className:"bg-gray-200",children:[e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{children:e.jsxs("div",{className:"font-medium",children:[c.format(a.original.totalCredit.raw)," Credit"]})}),e.jsx(t,{children:e.jsx("div",{className:"font-medium",children:c.format(a.original.closingBalance.raw)})})]},`${a.id}-totals2`),e.jsxs(d,{className:"bg-gray-200",children:[e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{children:e.jsxs("div",{className:"font-medium",children:[c.format(a.original.totalCredit.raw-a.original.totalDebit.raw)," Diff"]})}),e.jsx(t,{})]},`${a.id}-totals3`)]})}export{I as YearlyLedgerReport};
@@ -1,6 +1,6 @@
1
- import{z as U,r as d,j as e,W as p,B as g,P as w,b as y,C as F,ei as q,ej as H,ek as Q,el as _,cQ as N,cj as M,em as E,en as R,eo as T,ep as J,eq as Y,c7 as V,er as $,es as W,et as X,eu as Z,a as z,t as K,ev as ee,T as te,ew as se,u as k,ad as O,cX as ae,cY as ne,cZ as re,Q as oe,df as ie,bL as A,bM as S,ex as D,d9 as ce,G as I,c_ as le,F as de,c as he,L as xe,E as ue,I as me,M as pe,ey as ge}from"./index-CN7VPpiB.js";import{d as B}from"./graphql-document-dedupe-fragments-ByT8-wlV.js";import{M as je}from"./index-Csqyxwgx.js";import{c as fe}from"./charges-filters-C-H07qp1.js";import"./Checkbox-lfqFDKZM.js";import"./sub-LLu8afpC.js";import"./subMonths-C1UIPrOU.js";/**
1
+ import{V as q,r as d,j as e,D as p,B as g,P as w,b as y,C as F,en as G,eo as H,ep as _,eq as J,cV as D,co as M,J as E,K as R,er as T,es as Q,et as Y,R as V,eu as $,ev as K,ew as W,ex as X,a as z,t as Z,ey as ee,T as te,ez as se,u as k,U as O,d0 as ae,d1 as ne,d2 as re,k as oe,dk as ie,bR as A,bS as S,eA as N,de as ce,Y as I,d3 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-BsGG-RLV.js";import{d as B}from"./graphql-document-dedupe-fragments-ByT8-wlV.js";import{M as je}from"./index-BTiGhl3N.js";import{c as fe}from"./charges-filters-DkO9FBdC.js";import"./Checkbox-Bm30-WRa.js";import"./sub-DKnwnbwx.js";import"./subMonths-B44KizJf.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=U("file-digit",ve),ye=({data:a,setEditCharge:c,setInsertDocument:l,setMatchDocuments:r,toggleMergeCharge:o,mergeSelectedCharges:n})=>{const s=p(q,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 L({data:a}){const{chargeId:c,chargeAccountantStatus:l}=p(H,a),{updateChargeAccountantApproval:r}=Q();return e.jsx("td",{children:e.jsx(_,{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(J,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:["₪ ",N(r,0)]}),e.jsxs("td",{className:"whitespace-nowrap",children:["₪ ",N(o,0)]}),e.jsx(L,{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(Y,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)})})]})]})},Ne=({data:a,toggleMergeCharge:c,mergeSelectedCharges:l,cumulativeAmount:r})=>{const[o,n]=d.useState(!1),s=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:[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:"₪ "+N(r,0)}),e.jsx(L,{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})})})})]})},De=({data:a,toggleMergeCharge:c,mergeSelectedCharges:l})=>{const{income:r}=p(W,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(Ne,{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(X,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(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"})}),"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}`),K.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??D.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}=k(),{userContext:s}=d.useContext(O);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}=k(),{setFiltersContext:c}=d.useContext(de),{userContext:l}=d.useContext(O),[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(G=>G!==v)):s([...n,v])},[n]);function P(){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:P})]}))},[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!==D.Expense&&e.jsx(De,{data:j?.vatReport,toggleMergeCharge:f,mergeSelectedCharges:n}),r.chargesType!==D.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(J,{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(Q,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(Y,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($,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(K,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(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"})}),"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(X,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}=k(),{userContext:s}=d.useContext(O);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}=k(),{setFiltersContext:c}=d.useContext(de),{userContext:l}=d.useContext(O),[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};
@@ -0,0 +1,9 @@
1
+ import{d0 as f,r as h,u as B,j as e,d1 as R,bC as N,B as w,d2 as $,k,cf as O,U as A,l as E,bR as v,cj as D,bW as C,bX as F,Y as T,a4 as z,a5 as P,a6 as L,a7 as V,aK as M,d3 as U,dU as _,c2 as S,T as I,P as q,b as G,bg as Z,b6 as j,b1 as p,D as H,dV as J,R as W,cV as y,F as X,a as K,dW as Q,dX as Y,c as ee,L as te,dY as se}from"./index-BsGG-RLV.js";function re(t){return!t||f(t)?null:encodeURIComponent(JSON.stringify(t))}function ae({filter:t,setFilter:s,closeModal:o}){const n=k({defaultValues:{...t}}),{control:a,handleSubmit:l}=n,{selectableBusinesses:r,fetching:u}=O(),{userContext:m}=h.useContext(A),c=i=>{i.fromDate?.trim()===""&&(i.fromDate=void 0),i.toDate?.trim()===""&&(i.toDate=void 0),s(i),o()};function d(){s({}),o()}return e.jsxs(e.Fragment,{children:[u?e.jsx("div",{children:"Loading..."}):e.jsx("div",{}),e.jsx(E,{...n,children:e.jsxs("form",{onSubmit:l(c),className:"space-y-2",children:[e.jsx(v,{name:"ownerIds",control:a,defaultValue:void 0,render:({field:i,fieldState:b})=>e.jsx(D,{...i,data:r,value:i.value??(m?.context.adminBusinessId?[m?.context.adminBusinessId]:void 0),disabled:u,label:"Owners",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:b.error?.message})}),e.jsx(v,{name:"businessIDs",control:a,defaultValue:void 0,render:({field:i,fieldState:b})=>e.jsx(D,{...i,data:r,value:i.value??void 0,disabled:u,label:"Businesses",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:b.error?.message})}),e.jsx(v,{name:"fromDate",control:a,defaultValue:t.fromDate,rules:{required:"Required",pattern:{value:C,message:"Date must be im format yyyy-mm-dd"}},render:({field:i,fieldState:b})=>e.jsx(F,{...i,onChange:x=>{const g=x?typeof x=="string"?x:T(x,"yyyy-MM-dd"):void 0;g!==i.value&&i.onChange(g)},value:i.value?new Date(i.value):void 0,label:"From Date",error:b.error?.message,required:!0,popoverProps:{withinPortal:!0}})}),e.jsx(v,{name:"toDate",control:a,defaultValue:t.toDate,rules:{pattern:{value:C,message:"Date must be im format yyyy-mm-dd"}},render:({field:i,fieldState:b})=>e.jsx(F,{...i,onChange:x=>{const g=x?typeof x=="string"?x:T(x,"yyyy-MM-dd"):void 0;g!==i.value&&i.onChange(g)},value:i.value?new Date(i.value):void 0,label:"To Date",error:b.error?.message,required:!0,popoverProps:{withinPortal:!0}})}),e.jsx(z,{name:"isShowZeroedAccounts",control:a,render:({field:i})=>e.jsxs(P,{className:"flex flex-row items-center justify-between rounded-lg border p-3 shadow-sm",children:[e.jsx("div",{className:"space-y-0.5",children:e.jsx(L,{children:"Show zeroed accounts"})}),e.jsxs("div",{className:"flex flex-row items-center gap-1",children:[e.jsx(V,{children:e.jsx(M,{defaultChecked:t.isShowZeroedAccounts??!1,onCheckedChange:i.onChange,checked:i.value===!0})}),e.jsx("span",{children:i.value?"show":"remove"})]})]})}),e.jsxs("div",{className:"flex justify-center mt-5 gap-3",children:[e.jsx("button",{type:"submit",className:"text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg",children:"Filter"}),e.jsx("button",{type:"button",className:"text-white bg-orange-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-orange-600 rounded-sm text-lg",onClick:d,children:"Clear"}),e.jsx("button",{type:"button",className:"text-white bg-rose-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-rose-600 rounded-sm text-lg",onClick:o,children:"Cancel"})]})]})})]})}function ne({filter:t,setFilter:s}){const[o,n]=h.useState(!1),[a,l]=h.useState(!f(t)),{get:r,set:u}=B();function m(d){return Object.entries(d??{}).filter(([b,x])=>x!==void 0&&Array.isArray(x)&&x.length>0).length>0}function c(d){U(d,t)||(s(d),l(m(d)))}return h.useEffect(()=>{const d=f(t)?null:encodeURIComponent(JSON.stringify(t)),i=r("trialBalanceReportFilters");d!==i&&u("trialBalanceReportFilters",d)},[t,r,u]),e.jsxs(e.Fragment,{children:[e.jsx(R,{opened:o,onClose:()=>n(!1),content:e.jsx(ae,{filter:t,setFilter:c,closeModal:()=>n(!1)})}),e.jsx(N,{inline:!0,size:16,disabled:!a,children:e.jsx(w,{variant:"outline",onClick:()=>n(!0),className:"p-2",children:e.jsx($,{size:20})})})]})}const oe=({data:t,fromDate:s,toDate:o})=>{const n=h.useCallback(async()=>{const a=le(t),l=`trial_balance_report${s?`_${s}`:""}${o?`_${o}`:""}`;return{fileContent:a,fileName:l}},[t,s,o]);return e.jsx(_,{createFileVariables:n})},le=t=>{let s="";s+=`Sort Code,Account Name,Debit,Credit,Balance\r
2
+ `;for(const[o,n]of Object.entries(t)){const a=ie(o,n);s+=a}return s+=`Report total:,,${Object.values(t).reduce((o,n)=>o+n.totalDebit,0)},${Object.values(t).reduce((o,n)=>o+n.totalCredit,0)},${Object.values(t).reduce((o,n)=>o+n.sum,0)}\r
3
+ `,s};function ie(t,s){let o="";return Object.values(s.sortCodes).sort((n,a)=>n.key-a.key).map(n=>{const a=ce(n);o+=a}),o+=`${t.replaceAll("0","*")},Group Total:,${s.totalDebit??""},${s.totalCredit??""},${s.sum}\r
4
+ `,o}function ce(t){let s="";s+=`${t.name}\r
5
+ `,t.records.sort((l,r)=>l.business.name.localeCompare(r.business.name)).map(l=>{const r=l?.total?.raw??0,u=l?.debit?.raw??0,m=l?.credit?.raw??0,c=`${t.key},${l.business.name?`"${de(l.business.name)}"`:""},${u?l?.debit?.raw:void 0},${m?l?.credit?.raw:void 0},${r>.001||r<-.001?l?.total?.raw??"":""}\r
6
+ `;s+=c});const o=`${t.key},Group total:,${t.totalDebit??""},${t.totalCredit??""},${t.sum}\r
7
+ `;s+=o;const n=t.debit?`,,,Total Debit Balances:,${t.debit}\r
8
+ `:"";s+=n;const a=t.credit?`,,,Total Credit Balances:,${t.credit}\r
9
+ `:"";return s+=a,s}function de(t){let s="";return s=t.replace(/"/g,'""'),s}const ue=({record:t,sortCodeKey:s,filter:o,isAllOpened:n})=>{const[a,l]=h.useState(n),r=t?.total?.raw??0,u=t?.debit?.raw??0,m=t?.credit?.raw??0;return e.jsxs(e.Fragment,{children:[e.jsxs("tr",{children:[e.jsx("td",{children:s}),e.jsx("td",{children:t.business.id}),e.jsx("td",{children:t.business.name??void 0}),e.jsx("td",{children:u?t?.debit?.formatted:void 0}),e.jsx("td",{children:m?t?.credit?.formatted:void 0}),e.jsx("td",{children:(r>.001||r<-.001)&&e.jsx(S,{color:r>0?"green":"red",children:t?.total?.formatted})}),e.jsx("td",{children:e.jsx(I,{label:"Detailed records",children:e.jsx(w,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>l(c=>!c),children:a||n?e.jsx(q,{className:"size-5"}):e.jsx(G,{className:"size-5"})})})})]},t.business.id),(a||n)&&e.jsx("tr",{children:e.jsx("td",{colSpan:7,children:e.jsx(Z,{businessID:t.business?.id,filter:o})})})]})},me=({sortCode:t,filter:s,isAllOpened:o})=>t.records.length>0?e.jsxs(e.Fragment,{children:[e.jsx("tr",{children:e.jsx("td",{colSpan:7,children:e.jsx("span",{className:"font-bold",children:t.name})})}),t.records.sort((n,a)=>n.business.name.localeCompare(a.business.name)).map(n=>e.jsx(ue,{record:n,sortCodeKey:t.key,filter:s,isAllOpened:o},n.business.id)),e.jsx("tr",{className:"bg-gray-100",children:t.records.length>1?e.jsxs(e.Fragment,{children:[e.jsx("td",{colSpan:2,children:"Group total:"}),e.jsx("td",{colSpan:1,children:t.key}),e.jsx("td",{colSpan:1,children:!!t.totalDebit&&j(t.totalDebit,p.Ils)}),e.jsx("td",{colSpan:1,children:!!t.totalCredit&&j(t.totalCredit,p.Ils)}),e.jsxs("td",{colSpan:1,children:[e.jsx(S,{c:t.sum>0?"green":t.sum<0?"red":void 0,children:j(t.sum,p.Ils)}),!!t.debit&&e.jsxs(e.Fragment,{children:[e.jsx("br",{}),"Total Debit Balances: ",j(t.debit,p.Ils)]}),!!t.credit&&e.jsxs(e.Fragment,{children:[e.jsx("br",{}),"Total Credit Balances: ",j(t.credit,p.Ils)]})]})]}):void 0})]}):null,xe=({group:t,data:s,filter:o,isAllOpened:n})=>e.jsxs(e.Fragment,{children:[Object.values(s.sortCodes).sort((a,l)=>a.key-l.key).map((a,l)=>e.jsx(me,{sortCode:a,filter:o,isAllOpened:n},`${a.key} ${l}`)),e.jsxs("tr",{className:"bg-gray-100",children:[e.jsx("td",{colSpan:2,children:"Group total:"}),e.jsx("td",{colSpan:1,children:t.replaceAll("0","*")}),e.jsx("td",{colSpan:1,children:!!s.totalDebit&&j(s.totalDebit,p.Ils)}),e.jsx("td",{colSpan:1,children:!!s.totalCredit&&j(s.totalCredit,p.Ils)}),e.jsx("td",{colSpan:1,children:e.jsx(S,{fw:700,c:s.sum>0?"green":s.sum<0?"red":void 0,children:j(s.sum,p.Ils)})})]},"group"+t)]});function he(t){return Math.floor(t/100)*100}const be=({data:t,filter:s,isAllOpened:o})=>{const{businessTransactionsSum:n}=H(J,t),a=h.useMemo(()=>{const l={};for(const r of n){r.business.sortCode??={id:"-999",key:-999,name:"Misc"};const u=!r.total.raw||r.total.raw<.001&&r.total.raw>-.001;if(!s.isShowZeroedAccounts&&u)continue;const m=he(r.business.sortCode.key);l[m]??={sortCodes:{},totalCredit:0,totalDebit:0,credit:0,debit:0,sum:0};const c=l[m];c.sortCodes[r.business.sortCode.key]??={...r.business.sortCode,totalCredit:0,totalDebit:0,records:[],credit:0,debit:0,sum:0};const d=c.sortCodes[r.business.sortCode.key];d.totalCredit+=r.credit.raw,d.totalDebit+=r.debit.raw,d.sum+=r.total.raw,c.totalCredit+=r.credit.raw,c.totalDebit+=r.debit.raw,c.sum+=r.total.raw,r.total.raw>0?(d.credit+=r.total.raw,c.credit+=r.total.raw):(d.debit+=r.total.raw,c.debit+=r.total.raw),d.records.push(r)}return l},[n,s.isShowZeroedAccounts]);return e.jsxs(W,{highlightOnHover:!0,children:[e.jsx("thead",{style:{position:"sticky",top:0,zIndex:20},children:e.jsxs("tr",{className:"bg-gray-300",children:[e.jsx("th",{children:"Sort Code"}),e.jsx("th",{children:"Account"}),e.jsx("th",{children:"Account Name"}),e.jsx("th",{children:"Total Debit"}),e.jsx("th",{children:"Total Credit"}),e.jsx("th",{children:"Balance"}),e.jsx("th",{children:e.jsx(oe,{data:a,fromDate:s.fromDate??void 0,toDate:s.toDate??void 0})})]})}),e.jsxs("tbody",{children:[Object.entries(a).map(([l,r])=>e.jsx(xe,{data:r,group:l,filter:s,isAllOpened:o},l)),e.jsxs("tr",{className:"bg-gray-100",children:[e.jsx("td",{colSpan:2,children:"Report total:"}),e.jsx("td",{}),e.jsxs("td",{children:["(",y(Object.values(a).reduce((l,r)=>l+r.totalDebit,0)),")"]}),e.jsxs("td",{children:["(",y(Object.values(a).reduce((l,r)=>l+r.totalCredit,0)),")"]}),e.jsx("td",{colSpan:1,children:y(Object.values(a).reduce((l,r)=>l+r.sum,0))})]})]})]})};function pe(t){const s=new URLSearchParams,o=re(t);return o&&s.append("trialBalanceReportFilters",o),`/reports/trial-balance${s.size>0?`?${s}`:""}`}const ge=()=>{const[t,s]=h.useState(!1),{get:o}=B(),{setFiltersContext:n}=h.useContext(X),[a,l]=h.useState(o("trialBalanceReportFilters")?JSON.parse(decodeURIComponent(o("trialBalanceReportFilters"))):{}),[{data:r,fetching:u}]=K({query:se,variables:{filters:{fromDate:a?.fromDate,toDate:a?.toDate,ownerIds:a?.ownerIds,businessIDs:a?.businessIDs}}});h.useEffect(()=>{n(e.jsxs("div",{className:"flex flex-row gap-2",children:[e.jsx(I,{label:"Expand all accounts",children:e.jsx(w,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>s(c=>!c),children:t?e.jsx(Q,{className:"size-5"}):e.jsx(Y,{className:"size-5"})})}),e.jsx(ne,{filter:a,setFilter:l})]}))},[a,t,n]);const m=h.useMemo(()=>r?.businessTransactionsSumFromLedgerRecords.__typename==="CommonError"?void 0:r?.businessTransactionsSumFromLedgerRecords,[r?.businessTransactionsSumFromLedgerRecords]);return e.jsx(ee,{title:"Trial Balance Report",description:"Trial balance report for all businesses",children:u||!m?e.jsx(te,{className:"h-10 w-10 animate-spin mr-2 self-center"}):e.jsx(be,{data:m,filter:a,isAllOpened:t})})};export{ge as TrialBalanceReport,pe as getTrialBalanceReportHref};