@accounter/client 0.0.8-alpha-20251029124558-c1dac18cef0a90c88021bcb6e06319cc55ec33d9 → 0.0.8-alpha-20251029125027-49c1a0d649d4e1877f5b88b36105b6108a393666

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 (85) hide show
  1. package/CHANGELOG.md +15 -1
  2. package/dist/assets/{Checkbox-w99PhJ6L.js → Checkbox-qIwbw1Vm.js} +1 -1
  3. package/dist/assets/{MultiSelect-9BbcXHjB.js → MultiSelect-Uj0K1auE.js} +1 -1
  4. package/dist/assets/{Pagination-BVQu3Yj6.js → Pagination-D9TkQfLt.js} +1 -1
  5. package/dist/assets/{Progress-BKRQuJXK.js → Progress-lLgzD5SX.js} +1 -1
  6. package/dist/assets/{Table-CR8S5Pp5.js → Table-Cr3nIx5M.js} +1 -1
  7. package/dist/assets/{Typography-D1_XzAPj.js → Typography-D8eUZCfX.js} +1 -1
  8. package/dist/assets/{YearPickerInput-dCiPlZqk.js → YearPickerInput-BdNLRDw_.js} +1 -1
  9. package/dist/assets/{accordion-QkFWsf0a.js → accordion-DwkOqBRF.js} +1 -1
  10. package/dist/assets/{accountant-approvals-AD_TNBTH.js → accountant-approvals-DX9vcA7l.js} +1 -1
  11. package/dist/assets/{accounter-table-CBigzB_s.js → accounter-table-R92v4QWf.js} +1 -1
  12. package/dist/assets/{addDays-CjlJbHpj.js → addDays-CHr5nY3e.js} +1 -1
  13. package/dist/assets/{all-charges-BdHR-QjC.js → all-charges-DVKRQLII.js} +1 -1
  14. package/dist/assets/{arrow-up-down-Cq3mRkaO.js → arrow-up-down-CTxePA5K.js} +1 -1
  15. package/dist/assets/{building-2-BE02hpsM.js → building-2-B6TvGHom.js} +1 -1
  16. package/dist/assets/{business-CX0D-23F.js → business-CCLPxEIP.js} +2 -2
  17. package/dist/assets/{business-extended-info-BRde-LSv.js → business-extended-info-tkrkodR7.js} +1 -1
  18. package/dist/assets/{business-header-CMH3yBZc.js → business-header-Dx4N1uVn.js} +1 -1
  19. package/dist/assets/{business-ledger-filters-DQ4D4mv8.js → business-ledger-filters-GmMxns0y.js} +1 -1
  20. package/dist/assets/{business-ledger-single-BSeNj9f2.js → business-ledger-single-BeO0VVgy.js} +1 -1
  21. package/dist/assets/{business-trip-CX-3yJmB.js → business-trip-D3REiwV6.js} +1 -1
  22. package/dist/assets/{charge-BzCN_Szu.js → charge-DPnVzmY7.js} +1 -1
  23. package/dist/assets/{charges-filters-C7YlWAFn.js → charges-filters-BSbPgdun.js} +1 -1
  24. package/dist/assets/{charges-ledger-validation-DqM92cc-.js → charges-ledger-validation-zkS0soMY.js} +1 -1
  25. package/dist/assets/{charges-table-BOnvwci9.js → charges-table-BIpECr1x.js} +1 -1
  26. package/dist/assets/{chart-OVHXA3Uy.js → chart-Caa1VlDy.js} +1 -1
  27. package/dist/assets/{data-table-pagination-BLbPHs4o.js → data-table-pagination-psKhAMGL.js} +1 -1
  28. package/dist/assets/{download-csv-button-C5J9ow3I.js → download-csv-button-B1TMXv92.js} +1 -1
  29. package/dist/assets/{editable-business-trip-Ito1rWaY.js → editable-business-trip-CCy91YvH.js} +1 -1
  30. package/dist/assets/{funnel-IYKnhWOy.js → funnel-DP2XBopJ.js} +1 -1
  31. package/dist/assets/{index-B3W0RNqC.js → index-4ge3Am6D.js} +1 -1
  32. package/dist/assets/{index-ofME77ND.js → index-8gQaTQhF.js} +2 -2
  33. package/dist/assets/{index-BOmTn4-L.js → index-BfV_NJXM.js} +1 -1
  34. package/dist/assets/{index-D68aCDMG.js → index-BiaDwWnW.js} +1 -1
  35. package/dist/assets/{index-Dvp0RPEc.js → index-BsxEk8Re.js} +1 -1
  36. package/dist/assets/{index-CP5LZIWs.js → index-CDhroLKu.js} +1 -1
  37. package/dist/assets/{index-CY5Ok8zP.js → index-CFIvwwkB.js} +1 -1
  38. package/dist/assets/{index-qLJISPWb.js → index-CLvGPwjT.js} +1 -1
  39. package/dist/assets/{index-smNUtwvf.js → index-CRuhKIVD.js} +1 -1
  40. package/dist/assets/{index-C8HkbFzQ.js → index-CV2QxRmK.js} +1 -1
  41. package/dist/assets/{index-DE0nwhFR.js → index-CY-XVbUJ.js} +1 -1
  42. package/dist/assets/{index-DjPei962.js → index-CdGH-wdf.js} +1 -1
  43. package/dist/assets/{index-kSig9eXf.js → index-CeSVmmFv.js} +1 -1
  44. package/dist/assets/{index-D31j2-8X.js → index-CmRnzPuP.js} +1 -1
  45. package/dist/assets/{index-D1Hpe746.js → index-CvxMeW9Y.js} +1 -1
  46. package/dist/assets/{index-ofu4jqHf.js → index-D9OJexEV.js} +1 -1
  47. package/dist/assets/{index-a32atud-.js → index-DjTdlXK_.js} +1 -1
  48. package/dist/assets/{index-Cn-lknzD.js → index-DkgLEg6I.js} +1 -1
  49. package/dist/assets/{index-2j4tFkfX.js → index-DtwTITCT.js} +1 -1
  50. package/dist/assets/{index-DeFWFAwx.js → index-PaMjwOfa.js} +1 -1
  51. package/dist/assets/{index-DGxxgGxy.js → index-PfXGaCrc.js} +1 -1
  52. package/dist/assets/{index-4YPOH-A_.js → index-dsDfIa4Y.js} +1 -1
  53. package/dist/assets/{index-CcJvt1sI.js → index-fZcP3X7C.js} +3 -3
  54. package/dist/assets/{index-CnlrBGcj.js → index-lk_kdDxO.js} +1 -1
  55. package/dist/assets/{index-DKVhuSlP.js → index-xJNjwngg.js} +1 -1
  56. package/dist/assets/{index.es-D7_nzQqR.js → index.es-tIpBPUgx.js} +1 -1
  57. package/dist/assets/{insert-business-trip-modal-D08ePEzY.js → insert-business-trip-modal-qIM7A1Dw.js} +1 -1
  58. package/dist/assets/issue-document-CAewRj6P.js +1 -0
  59. package/dist/assets/{list-plus-Cv8qnwZd.js → list-plus-ZIHrrCaO.js} +1 -1
  60. package/dist/assets/{login-page-sUXp3XoV.js → login-page-z7UM7kNz.js} +1 -1
  61. package/dist/assets/{match-document-modal-D2TgC0aR.js → match-document-modal-CpUhpMJc.js} +1 -1
  62. package/dist/assets/{missing-info-charges-BJnQHRZs.js → missing-info-charges-C1tPzMqU.js} +1 -1
  63. package/dist/assets/{modal-DOtlViK5.js → modal-B_jJz-4Z.js} +1 -1
  64. package/dist/assets/{page-layout-BNHKLJFL.js → page-layout-DUgx8eXl.js} +1 -1
  65. package/dist/assets/{page-not-found-j9vQhz-c.js → page-not-found-D8UJ6_C9.js} +1 -1
  66. package/dist/assets/{panel-top-open-DQ1wo5PZ.js → panel-top-open-CcWXXds7.js} +1 -1
  67. package/dist/assets/{pencil-BWTnh6hj.js → pencil-zApPUfTb.js} +1 -1
  68. package/dist/assets/{report-commentary-row-DBOCwi7X.js → report-commentary-row-BonuPEAK.js} +1 -1
  69. package/dist/assets/{save-DuIXDTLc.js → save-tZoVFUtG.js} +1 -1
  70. package/dist/assets/{similar-transactions-modal-DDVojjq0.js → similar-transactions-modal-Cdv2FmQ8.js} +1 -1
  71. package/dist/assets/{sub-CIKovQuv.js → sub-zRppNrG0.js} +1 -1
  72. package/dist/assets/subMonths-CLe-U48r.js +1 -0
  73. package/dist/assets/{summary-BV3HUEgI.js → summary-yiqSbK4V.js} +1 -1
  74. package/dist/assets/{toggle-expansion-button-Bdpb_YfG.js → toggle-expansion-button-pWLCCDmM.js} +1 -1
  75. package/dist/assets/tooltip-r34BEIrK.js +1 -0
  76. package/dist/assets/{use-url-query-D-GsTMWL.js → use-url-query-DyJg_rMw.js} +1 -1
  77. package/dist/index.html +1 -1
  78. package/package.json +1 -1
  79. package/src/components/business/index.tsx +4 -2
  80. package/src/components/tags/index.tsx +4 -2
  81. package/src/components/transactions-table/index.tsx +0 -2
  82. package/src/router/config.tsx +1 -1
  83. package/dist/assets/issue-document-D2L9kG1u.js +0 -1
  84. package/dist/assets/subMonths-GbNm9rnx.js +0 -1
  85. package/dist/assets/tooltip-Cy3vJ3fy.js +0 -1
@@ -1 +1 @@
1
- import{j as e,T as se,B as $,au as ae,bq as ne,u as I,hb as te,r as x,a8 as H,hc as oe,hd as z,G as V,t as f,V as le,e9 as ie,cK as G,br as u,bu as k,X as de,he as ce,Y as me,Z as ue,_ as xe,I as ye,a0 as pe,bM as g,bK as S,x as E,a5 as ge,g as W,hf as he,i as Y,hg as je,ee as _,d as fe,hh as ve,gH as be,bo as Ne,bv as Se,J as w,hi as Ee,hj as we,hk as Fe,hl as Ce,hm as Ie,fE as De,hn as Ae,ho as Pe,hp as Re,F as Te,L as ke,hq as Me}from"./index-CcJvt1sI.js";import{u as J}from"./use-url-query-D-GsTMWL.js";import{P as Be}from"./page-layout-BNHKLJFL.js";import{P as Le}from"./modal-DOtlViK5.js";import{F as Ze}from"./funnel-IYKnhWOy.js";import{M as qe}from"./MultiSelect-9BbcXHjB.js";function K(t){return e.jsx(se,{disabled:!t.tooltip,label:t.tooltip,children:e.jsx($,{variant:"ghost",size:"icon",className:"size-7.5",...t,children:e.jsx(ae,{className:"size-5"})})})}const Q=({isNewInsert:t=!0,defaultValues:s,month:l,onDone:d,isModifying:o})=>{const{selectableBusinesses:i,fetching:n}=ne(),[{data:c,fetching:y,error:j}]=I({query:te}),{userContext:v}=x.useContext(H),[{data:b,fetching:F,error:R}]=I({query:oe}),[{data:D,fetching:M,error:C}]=I({query:z,variables:{employerId:v?.context.adminBusinessId??""}}),[p,N]=x.useState([]),[A,T]=x.useState([]),[X,ee]=x.useState([]),P=s?.month??l,Z=V({defaultValues:{...s,month:P}}),{control:m,handleSubmit:q,formState:{dirtyFields:O},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(()=>{D?.employeesByEmployerId.length&&ee(D.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))},[D,T]),x.useEffect(()=>{!s?.employer&&v?.context.adminBusinessId&&B("employer",v.context.adminBusinessId,{shouldDirty:!0,shouldTouch:!0})},[B,s?.employer,v?.context.adminBusinessId]);const U=r=>{const a=ge(r,O);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(le,{...Z,children:e.jsxs("form",{onSubmit:q(U),children:[e.jsx("div",{className:"flex-row px-10 h-max justify-start block",children:e.jsxs(ie,{cols:4,children:[e.jsxs("div",{className:"flex-column h-max justify-start block",children:[e.jsx(G,{defaultDate:P?new Date(P):void 0,defaultValue:P?new Date(P):void 0,onChange:re,popoverProps:{withinPortal:!0}}),e.jsx(u,{name:"employer",control:m,defaultValue: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:()=>q(U),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:o||Object.keys(O).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"})]})]})})},Oe="updateSalaryRecord",Ue=()=>{const[{fetching:t},s]=W(he),l=x.useCallback(async d=>{const o=`Error updating salary record [${d.salaryRecord.month}] employee [${d.salaryRecord.employeeId}]`,i=Oe;f.loading("Updating Salary Record",{id:i});try{const n=await s(d),c=Y(n,o,i,"updateSalaryRecord");if(c)return f.success("Success",{id:i,description:"Salary record was updated"}),c.updateSalaryRecord.salaryRecord}catch(n){console.error(`${o}: ${n}`),f.error("Error",{id:i,description:o,duration:1e5,closeButton:!0})}},[s]);return{fetching:t,updateSalaryRecord:l}},$e=({recordVariables:t,onDone:s})=>t?e.jsx(He,{recordVariables:t,onDone:s}):null,He=({recordVariables:t,onDone:s})=>{const{updateSalaryRecord:l,fetching:d}=Ue(),[{data:o,fetching:i}]=I({query:je,variables:{employeeIDs:[t.employeeId],month:E(new Date(t.month),"yyyy-MM-dd")}}),n=o?.salaryRecordsByDates?.[0],c=x.useCallback(j=>{s(),j&&l({salaryRecord:j})},[s,l]);if(!n?.employer?.id||!n?.employee?.id)return e.jsx(e.Fragment,{});const y={addedVacationDays:n?.vacationDays?.added,baseSalary:n?.baseAmount?.raw,bonus:n?.bonus?.raw,chargeId:n?.charge?.id,compensationsEmployerAmount:n?.compensationsAmount?.raw,compensationsEmployerPercentage:n?.compensationsPercentage,directPaymentAmount:n?.directAmount?.raw,employer:n.employer.id,employeeId:n.employee.id,gift:n?.gift?.raw,globalAdditionalHours:n?.globalAdditionalHoursAmount?.raw,healthPaymentAmount:n?.healthInsuranceAmount?.raw,month:n?.month,pensionEmployeeAmount:n?.pensionEmployeeAmount?.raw,pensionEmployeePercentage:n?.pensionEmployeePercentage,pensionEmployerAmount:n?.pensionEmployerAmount?.raw,pensionEmployerPercentage:n?.pensionEmployerPercentage,pensionFundId:n?.pensionFund?.id,recovery:n?.recovery?.raw,sicknessDaysBalance:n?.sicknessDays?.balance,socialSecurityAmountEmployee:n?.socialSecurityEmployeeAmount?.raw,socialSecurityAmountEmployer:n?.socialSecurityEmployerAmount?.raw,taxAmount:n?.incomeTaxAmount?.raw,trainingFundEmployeeAmount:n?.trainingFundEmployeeAmount?.raw,trainingFundEmployeePercentage:n?.trainingFundEmployeePercentage,trainingFundEmployerAmount:n?.trainingFundEmployerAmount?.raw,trainingFundEmployerPercentage:n?.trainingFundEmployerPercentage,trainingFundId:n?.trainingFund?.id,travelAndSubsistence:n?.travelAndSubsistence?.raw,vacationDaysBalance:n?.vacationDays?.balance,vacationTakeout:n?.vacationTakeout?.raw,workDays:n?.workDays,zkufot:n?.notionalExpense?.raw};return e.jsx(_,{modalSize:"fit-content",position:"bottom",title:e.jsxs("div",{className:"flex flex-row mx-3 pt-3 sm:text-1xl gap-10",children:[e.jsx("h1",{className:"sm:text-2xl font-small text-gray-900",children:"Edit Salary Record:"}),e.jsxs("div",{className:"flex flex-row gap-2",children:["month: ",t.month," employeeId: ",t.employeeId]})]}),opened:!!t,onClose:s,children:i||!n?e.jsx(fe,{className:"flex self-center my-5",color:"dark",size:"xl",variant:"dots"}):e.jsx(Q,{isNewInsert:!1,defaultValues:y,onDone:c,isModifying:d})})},ze="insertSalaryRecords",Ve=()=>{const[{fetching:t},s]=W(ve),l=x.useCallback(async d=>{const o=ze;if(f.loading("Adding salary record",{id:o}),!d.salaryRecords||Array.isArray(d.salaryRecords)&&d.salaryRecords.length===0){f.error("Error",{id:o,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:o,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=Y(c,n,o,"insertSalaryRecords");if(y)return f.success("Success",{id:o,description:"Salary record was added"}),y.insertSalaryRecords.salaryRecords[0]}catch(c){console.error(`${n}: ${c}`),f.error("Error",{id:o,description:n,duration:1e5,closeButton:!0})}},[s]);return{fetching:t,insertSalaryRecord:l}},Ge=({insertSalaryRecordParams:t,setInsertSalaryRecord:s})=>{const{insertSalaryRecord:l,fetching:d}=Ve(),o=x.useCallback(i=>{i&&l({salaryRecords:[i]}),s(void 0)},[s,l]);return e.jsx(_,{modalSize:"40%",position:"bottom",title:e.jsx("div",{className:"flex flex-row mx-3 pt-3 sm:text-1xl gap-10",children:e.jsx("h1",{className:"sm:text-2xl font-small text-gray-900",children:"Insert Salary Record:"})}),opened:!!t,onClose:()=>s(void 0),children:e.jsx(Q,{isNewInsert:!0,onDone:o,isModifying:d,month:t.month})})};function L(){const t=new Date,s=E(t,"yyyy-MM-dd"),l=E(be(t),"yyyy-MM-dd");return{fromDate:s,toDate:l}}function We({filter:t,setFilter:s,closeModal:l}){const{control:d,handleSubmit:o,setValue:i}=V({defaultValues:{...t}}),[n,c]=x.useState([]),{userContext:y}=x.useContext(H),[{data:j,fetching:v,error:b},F]=I({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),l()};function D(){s({...L()}),l()}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:o(R),children:[e.jsx(G,{type:"range",numberOfColumns:2,defaultValue:[new Date(t?.fromDate??C.fromDate),new Date(t?.toDate??C.toDate)],defaultDate:new Date(t?.fromDate??C.fromDate),onChange:M,popoverProps:{withinPortal:!0}}),e.jsx(u,{name:"employeeIDs",control:d,defaultValue:t.employeeIDs,render:({field:p,fieldState:N})=>e.jsx(qe,{...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: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:l,children:"Cancel"})]})]})]})}function Ye({filter:t,setFilter:s}){const[l,d]=x.useState(!1),{get:o,set:i}=J();x.useEffect(()=>{const c=Ne(t)?null:encodeURIComponent(JSON.stringify(t)),y=o("salariesFilters");c!==y&&i("salariesFilters",c)},[t,o,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(Le,{opened:l,onClose:()=>d(!1),content:e.jsx(We,{filter:t,setFilter:n,closeModal:()=>d(!1)}),modalSize:"xl"}),e.jsx($,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>d(!0),children:e.jsx(Ze,{className:"size-5"})})]})}const _e=({month:t,setInsertSalaryRecord:s})=>{const l=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:l}),e.jsx("div",{className:"flex items-center",children:e.jsx("div",{className:"flex flex-col",children:e.jsx(K,{onClick:s})})})]})})})},Je=({data:t})=>{const{employee:s,month:l}=w(Ee,t),d=E(new Date(l),"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})]})})})},Ke=({data:t})=>{const{pensionEmployeeAmount:s,pensionEmployeePercentage:l,pensionEmployerAmount:d,pensionEmployerPercentage:o,compensationsAmount:i,compensationsPercentage:n,pensionFund:c,trainingFund:y,trainingFundEmployeeAmount:j,trainingFundEmployeePercentage:v,trainingFundEmployerAmount:b,trainingFundEmployerPercentage:F}=w(we,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,l&&` (${l}%)`]})]}),!!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,o&&` (${o}%)`]})]}),!!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}%)`]})]})]})})})},Qe=({data:t})=>{const{healthInsuranceAmount:s,socialSecurityEmployeeAmount:l,socialSecurityEmployerAmount:d,incomeTaxAmount:o,notionalExpense:i}=w(Fe,t),n=!!l||!!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:l?.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})]})]}),(!!o?.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:o?.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:l,globalAdditionalHoursAmount:d,bonus:o,gift:i,recovery:n,vacationTakeout:c}=w(Ce,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})]}),!!o?.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:o?.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:l?.formatted})]})]})})})},er=({data:t})=>{const{vacationDays:s,workDays:l,sicknessDays:d}=w(Ie,t),{added:o,taken:i,balance:n}=s??{},{balance:c}=d??{},y=!!o||!!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:[!!l&&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:l})})]}),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:"}),!!o&&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:o})]}),!!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 l=w(Ae,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:l}),e.jsx(Xe,{data:l}),e.jsx(Ke,{data:l}),e.jsx(Qe,{data:l}),e.jsx(er,{data:l}),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(De,{onClick:t})})})})]}),e.jsx("tr",{className:"h-3"})]})},sr=({setEditSalaryRecord:t,setInsertSalaryRecord:s,data:l})=>{const d=l?.map(o=>w(Pe,o))??[];return e.jsxs(e.Fragment,{children:[e.jsx("tr",{className:"h-3"}),e.jsx(_e,{month:d[0].month,setInsertSalaryRecord:s}),e.jsx("tr",{className:"h-3"}),d.map(o=>e.jsx(rr,{data:o,setEditSalaryRecord:()=>t(o.employee?.id)},`${o.month} ${o.employee?.id}`))]})},ar=({setEditSalaryRecord:t,setInsertSalaryRecord:s,data:l})=>{const d=x.useMemo(()=>{const o=l?.map(n=>w(Re,n))??[],i=new Map;return o.map(n=>{const{month:c}=n,y=i.get(c)??[];i.set(c,[...y,n])}),i},[l]);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(([o,i])=>e.jsx(sr,{data:i,setEditSalaryRecord:n=>t(n?{month:o,employeeId:n}:void 0),setInsertSalaryRecord:()=>s({month:o})},o))})})})]})})},cr=()=>{const{setFiltersContext:t}=x.useContext(Te),[s,l]=x.useState(void 0),[d,o]=x.useState(void 0),{get:i}=J(),[n,c]=x.useState(i("salariesFilters")?JSON.parse(decodeURIComponent(i("salariesFilters"))):{...L()}),[{data:y,fetching:j}]=I({query:Me,variables:{...n}});return x.useEffect(()=>{t(e.jsxs("div",{className:"flex flex-row gap-x-5",children:[e.jsx(Ye,{filter:n,setFilter:c}),e.jsx(K,{variant:"default",onClick:()=>o({})})]}))},[y,j,n,t,c]),e.jsxs(Be,{title:"Salaries",description:"View and manage salaries of employees.",children:[j?e.jsx(ke,{className:"h-10 w-10 animate-spin mr-2 self-center"}):e.jsx(ar,{setEditSalaryRecord:l,setInsertSalaryRecord:o,data:y?.salaryRecordsByDates}),e.jsx($e,{recordVariables:s,onDone:()=>l(void 0)}),d&&e.jsx(Ge,{insertSalaryRecordParams:d,setInsertSalaryRecord:o})]})};export{cr as Salaries};
1
+ import{j as e,T as se,B as $,au as ae,bq as ne,u as I,hb as te,r as x,a8 as H,hc as oe,hd as z,G as V,t as f,V as le,e9 as ie,cK as G,br as u,bu as k,X as de,he as ce,Y as me,Z as ue,_ as xe,I as ye,a0 as pe,bM as g,bK as S,x as E,a5 as ge,g as W,hf as he,i as Y,hg as je,ee as _,d as fe,hh as ve,gH as be,bo as Ne,bv as Se,J as w,hi as Ee,hj as we,hk as Fe,hl as Ce,hm as Ie,fE as De,hn as Ae,ho as Pe,hp as Re,F as Te,L as ke,hq as Me}from"./index-fZcP3X7C.js";import{u as J}from"./use-url-query-DyJg_rMw.js";import{P as Be}from"./page-layout-DUgx8eXl.js";import{P as Le}from"./modal-B_jJz-4Z.js";import{F as Ze}from"./funnel-DP2XBopJ.js";import{M as qe}from"./MultiSelect-Uj0K1auE.js";function K(t){return e.jsx(se,{disabled:!t.tooltip,label:t.tooltip,children:e.jsx($,{variant:"ghost",size:"icon",className:"size-7.5",...t,children:e.jsx(ae,{className:"size-5"})})})}const Q=({isNewInsert:t=!0,defaultValues:s,month:l,onDone:d,isModifying:o})=>{const{selectableBusinesses:i,fetching:n}=ne(),[{data:c,fetching:y,error:j}]=I({query:te}),{userContext:v}=x.useContext(H),[{data:b,fetching:F,error:R}]=I({query:oe}),[{data:D,fetching:M,error:C}]=I({query:z,variables:{employerId:v?.context.adminBusinessId??""}}),[p,N]=x.useState([]),[A,T]=x.useState([]),[X,ee]=x.useState([]),P=s?.month??l,Z=V({defaultValues:{...s,month:P}}),{control:m,handleSubmit:q,formState:{dirtyFields:O},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(()=>{D?.employeesByEmployerId.length&&ee(D.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))},[D,T]),x.useEffect(()=>{!s?.employer&&v?.context.adminBusinessId&&B("employer",v.context.adminBusinessId,{shouldDirty:!0,shouldTouch:!0})},[B,s?.employer,v?.context.adminBusinessId]);const U=r=>{const a=ge(r,O);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(le,{...Z,children:e.jsxs("form",{onSubmit:q(U),children:[e.jsx("div",{className:"flex-row px-10 h-max justify-start block",children:e.jsxs(ie,{cols:4,children:[e.jsxs("div",{className:"flex-column h-max justify-start block",children:[e.jsx(G,{defaultDate:P?new Date(P):void 0,defaultValue:P?new Date(P):void 0,onChange:re,popoverProps:{withinPortal:!0}}),e.jsx(u,{name:"employer",control:m,defaultValue: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:()=>q(U),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:o||Object.keys(O).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"})]})]})})},Oe="updateSalaryRecord",Ue=()=>{const[{fetching:t},s]=W(he),l=x.useCallback(async d=>{const o=`Error updating salary record [${d.salaryRecord.month}] employee [${d.salaryRecord.employeeId}]`,i=Oe;f.loading("Updating Salary Record",{id:i});try{const n=await s(d),c=Y(n,o,i,"updateSalaryRecord");if(c)return f.success("Success",{id:i,description:"Salary record was updated"}),c.updateSalaryRecord.salaryRecord}catch(n){console.error(`${o}: ${n}`),f.error("Error",{id:i,description:o,duration:1e5,closeButton:!0})}},[s]);return{fetching:t,updateSalaryRecord:l}},$e=({recordVariables:t,onDone:s})=>t?e.jsx(He,{recordVariables:t,onDone:s}):null,He=({recordVariables:t,onDone:s})=>{const{updateSalaryRecord:l,fetching:d}=Ue(),[{data:o,fetching:i}]=I({query:je,variables:{employeeIDs:[t.employeeId],month:E(new Date(t.month),"yyyy-MM-dd")}}),n=o?.salaryRecordsByDates?.[0],c=x.useCallback(j=>{s(),j&&l({salaryRecord:j})},[s,l]);if(!n?.employer?.id||!n?.employee?.id)return e.jsx(e.Fragment,{});const y={addedVacationDays:n?.vacationDays?.added,baseSalary:n?.baseAmount?.raw,bonus:n?.bonus?.raw,chargeId:n?.charge?.id,compensationsEmployerAmount:n?.compensationsAmount?.raw,compensationsEmployerPercentage:n?.compensationsPercentage,directPaymentAmount:n?.directAmount?.raw,employer:n.employer.id,employeeId:n.employee.id,gift:n?.gift?.raw,globalAdditionalHours:n?.globalAdditionalHoursAmount?.raw,healthPaymentAmount:n?.healthInsuranceAmount?.raw,month:n?.month,pensionEmployeeAmount:n?.pensionEmployeeAmount?.raw,pensionEmployeePercentage:n?.pensionEmployeePercentage,pensionEmployerAmount:n?.pensionEmployerAmount?.raw,pensionEmployerPercentage:n?.pensionEmployerPercentage,pensionFundId:n?.pensionFund?.id,recovery:n?.recovery?.raw,sicknessDaysBalance:n?.sicknessDays?.balance,socialSecurityAmountEmployee:n?.socialSecurityEmployeeAmount?.raw,socialSecurityAmountEmployer:n?.socialSecurityEmployerAmount?.raw,taxAmount:n?.incomeTaxAmount?.raw,trainingFundEmployeeAmount:n?.trainingFundEmployeeAmount?.raw,trainingFundEmployeePercentage:n?.trainingFundEmployeePercentage,trainingFundEmployerAmount:n?.trainingFundEmployerAmount?.raw,trainingFundEmployerPercentage:n?.trainingFundEmployerPercentage,trainingFundId:n?.trainingFund?.id,travelAndSubsistence:n?.travelAndSubsistence?.raw,vacationDaysBalance:n?.vacationDays?.balance,vacationTakeout:n?.vacationTakeout?.raw,workDays:n?.workDays,zkufot:n?.notionalExpense?.raw};return e.jsx(_,{modalSize:"fit-content",position:"bottom",title:e.jsxs("div",{className:"flex flex-row mx-3 pt-3 sm:text-1xl gap-10",children:[e.jsx("h1",{className:"sm:text-2xl font-small text-gray-900",children:"Edit Salary Record:"}),e.jsxs("div",{className:"flex flex-row gap-2",children:["month: ",t.month," employeeId: ",t.employeeId]})]}),opened:!!t,onClose:s,children:i||!n?e.jsx(fe,{className:"flex self-center my-5",color:"dark",size:"xl",variant:"dots"}):e.jsx(Q,{isNewInsert:!1,defaultValues:y,onDone:c,isModifying:d})})},ze="insertSalaryRecords",Ve=()=>{const[{fetching:t},s]=W(ve),l=x.useCallback(async d=>{const o=ze;if(f.loading("Adding salary record",{id:o}),!d.salaryRecords||Array.isArray(d.salaryRecords)&&d.salaryRecords.length===0){f.error("Error",{id:o,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:o,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=Y(c,n,o,"insertSalaryRecords");if(y)return f.success("Success",{id:o,description:"Salary record was added"}),y.insertSalaryRecords.salaryRecords[0]}catch(c){console.error(`${n}: ${c}`),f.error("Error",{id:o,description:n,duration:1e5,closeButton:!0})}},[s]);return{fetching:t,insertSalaryRecord:l}},Ge=({insertSalaryRecordParams:t,setInsertSalaryRecord:s})=>{const{insertSalaryRecord:l,fetching:d}=Ve(),o=x.useCallback(i=>{i&&l({salaryRecords:[i]}),s(void 0)},[s,l]);return e.jsx(_,{modalSize:"40%",position:"bottom",title:e.jsx("div",{className:"flex flex-row mx-3 pt-3 sm:text-1xl gap-10",children:e.jsx("h1",{className:"sm:text-2xl font-small text-gray-900",children:"Insert Salary Record:"})}),opened:!!t,onClose:()=>s(void 0),children:e.jsx(Q,{isNewInsert:!0,onDone:o,isModifying:d,month:t.month})})};function L(){const t=new Date,s=E(t,"yyyy-MM-dd"),l=E(be(t),"yyyy-MM-dd");return{fromDate:s,toDate:l}}function We({filter:t,setFilter:s,closeModal:l}){const{control:d,handleSubmit:o,setValue:i}=V({defaultValues:{...t}}),[n,c]=x.useState([]),{userContext:y}=x.useContext(H),[{data:j,fetching:v,error:b},F]=I({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),l()};function D(){s({...L()}),l()}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:o(R),children:[e.jsx(G,{type:"range",numberOfColumns:2,defaultValue:[new Date(t?.fromDate??C.fromDate),new Date(t?.toDate??C.toDate)],defaultDate:new Date(t?.fromDate??C.fromDate),onChange:M,popoverProps:{withinPortal:!0}}),e.jsx(u,{name:"employeeIDs",control:d,defaultValue:t.employeeIDs,render:({field:p,fieldState:N})=>e.jsx(qe,{...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: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:l,children:"Cancel"})]})]})]})}function Ye({filter:t,setFilter:s}){const[l,d]=x.useState(!1),{get:o,set:i}=J();x.useEffect(()=>{const c=Ne(t)?null:encodeURIComponent(JSON.stringify(t)),y=o("salariesFilters");c!==y&&i("salariesFilters",c)},[t,o,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(Le,{opened:l,onClose:()=>d(!1),content:e.jsx(We,{filter:t,setFilter:n,closeModal:()=>d(!1)}),modalSize:"xl"}),e.jsx($,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>d(!0),children:e.jsx(Ze,{className:"size-5"})})]})}const _e=({month:t,setInsertSalaryRecord:s})=>{const l=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:l}),e.jsx("div",{className:"flex items-center",children:e.jsx("div",{className:"flex flex-col",children:e.jsx(K,{onClick:s})})})]})})})},Je=({data:t})=>{const{employee:s,month:l}=w(Ee,t),d=E(new Date(l),"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})]})})})},Ke=({data:t})=>{const{pensionEmployeeAmount:s,pensionEmployeePercentage:l,pensionEmployerAmount:d,pensionEmployerPercentage:o,compensationsAmount:i,compensationsPercentage:n,pensionFund:c,trainingFund:y,trainingFundEmployeeAmount:j,trainingFundEmployeePercentage:v,trainingFundEmployerAmount:b,trainingFundEmployerPercentage:F}=w(we,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,l&&` (${l}%)`]})]}),!!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,o&&` (${o}%)`]})]}),!!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}%)`]})]})]})})})},Qe=({data:t})=>{const{healthInsuranceAmount:s,socialSecurityEmployeeAmount:l,socialSecurityEmployerAmount:d,incomeTaxAmount:o,notionalExpense:i}=w(Fe,t),n=!!l||!!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:l?.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})]})]}),(!!o?.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:o?.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:l,globalAdditionalHoursAmount:d,bonus:o,gift:i,recovery:n,vacationTakeout:c}=w(Ce,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})]}),!!o?.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:o?.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:l?.formatted})]})]})})})},er=({data:t})=>{const{vacationDays:s,workDays:l,sicknessDays:d}=w(Ie,t),{added:o,taken:i,balance:n}=s??{},{balance:c}=d??{},y=!!o||!!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:[!!l&&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:l})})]}),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:"}),!!o&&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:o})]}),!!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 l=w(Ae,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:l}),e.jsx(Xe,{data:l}),e.jsx(Ke,{data:l}),e.jsx(Qe,{data:l}),e.jsx(er,{data:l}),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(De,{onClick:t})})})})]}),e.jsx("tr",{className:"h-3"})]})},sr=({setEditSalaryRecord:t,setInsertSalaryRecord:s,data:l})=>{const d=l?.map(o=>w(Pe,o))??[];return e.jsxs(e.Fragment,{children:[e.jsx("tr",{className:"h-3"}),e.jsx(_e,{month:d[0].month,setInsertSalaryRecord:s}),e.jsx("tr",{className:"h-3"}),d.map(o=>e.jsx(rr,{data:o,setEditSalaryRecord:()=>t(o.employee?.id)},`${o.month} ${o.employee?.id}`))]})},ar=({setEditSalaryRecord:t,setInsertSalaryRecord:s,data:l})=>{const d=x.useMemo(()=>{const o=l?.map(n=>w(Re,n))??[],i=new Map;return o.map(n=>{const{month:c}=n,y=i.get(c)??[];i.set(c,[...y,n])}),i},[l]);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(([o,i])=>e.jsx(sr,{data:i,setEditSalaryRecord:n=>t(n?{month:o,employeeId:n}:void 0),setInsertSalaryRecord:()=>s({month:o})},o))})})})]})})},cr=()=>{const{setFiltersContext:t}=x.useContext(Te),[s,l]=x.useState(void 0),[d,o]=x.useState(void 0),{get:i}=J(),[n,c]=x.useState(i("salariesFilters")?JSON.parse(decodeURIComponent(i("salariesFilters"))):{...L()}),[{data:y,fetching:j}]=I({query:Me,variables:{...n}});return x.useEffect(()=>{t(e.jsxs("div",{className:"flex flex-row gap-x-5",children:[e.jsx(Ye,{filter:n,setFilter:c}),e.jsx(K,{variant:"default",onClick:()=>o({})})]}))},[y,j,n,t,c]),e.jsxs(Be,{title:"Salaries",description:"View and manage salaries of employees.",children:[j?e.jsx(ke,{className:"h-10 w-10 animate-spin mr-2 self-center"}):e.jsx(ar,{setEditSalaryRecord:l,setInsertSalaryRecord:o,data:y?.salaryRecordsByDates}),e.jsx($e,{recordVariables:s,onDone:()=>l(void 0)}),d&&e.jsx(Ge,{insertSalaryRecordParams:d,setInsertSalaryRecord:o})]})};export{cr as Salaries};
@@ -1 +1 @@
1
- import{r as m,j as e,B as u,a as y,F as R,u as T,L as D,fX as E}from"./index-CcJvt1sI.js";import{d as b}from"./graphql-document-dedupe-fragments-ByT8-wlV.js";import{P as w}from"./page-layout-BNHKLJFL.js";import{R as d}from"./report-commentary-row-DBOCwi7X.js";import{P as F}from"./modal-DOtlViK5.js";import{Y as f}from"./YearPickerInput-dCiPlZqk.js";import{F as g}from"./funnel-IYKnhWOy.js";import{T as v}from"./Table-CR8S5Pp5.js";import"./toggle-expansion-button-Bdpb_YfG.js";import"./panel-top-open-DQ1wo5PZ.js";function B({year:i,setYear:h,referenceYears:x,setReferenceYears:j}){const[l,c]=m.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsx(F,{opened:l,onClose:()=>c(!1),withCloseButton:!0,content:e.jsxs(e.Fragment,{children:[e.jsx(f,{label:"Change report year",value:new Date(i,0,1),onChange:n=>n&&h(n?.getFullYear()),popoverProps:{withinPortal:!0},minDate:new Date(2010,0,1),maxDate:new Date}),e.jsx(f,{type:"multiple",label:"Pick reference years",value:x?.map(n=>new Date(n,0,1)),onChange:n=>j(n.map(o=>o.getFullYear()).filter(o=>i!==o)),popoverProps:{withinPortal:!0},minDate:new Date(2010,0,1),maxDate:new Date})]})}),e.jsx(u,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>c(!0),children:e.jsx(g,{className:"size-5"})})]})}const G=()=>{const{year:i}=y(),{setFiltersContext:h}=m.useContext(R),[x,j]=m.useState(i?Number(i):new Date().getFullYear()),[l,c]=m.useState([]),[{data:n,fetching:o}]=T({query:b(E),variables:{reportYear:x,referenceYears:l}});m.useEffect(()=>{h(e.jsx("div",{className:"flex flex-row gap-2",children:e.jsx(B,{year:x,setYear:j,referenceYears:l,setReferenceYears:c})}))},[x,o,h,l,c]);const p=n?.taxReport,s=p?.report,r=p?.reference??[];return e.jsx(w,{title:"Tax Report",children:o?e.jsx(D,{className:"h-10 w-10 animate-spin mr-2 self-center"}):e.jsx("div",{className:"flex flex-col gap-4",children:s&&e.jsxs(v,{highlightOnHover:!0,fontSize:"md",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{}),e.jsx("th",{children:x},x),e.jsx("th",{}),r.map(t=>e.jsx("th",{children:t.year},t.year))]})}),e.jsxs("tbody",{children:[e.jsx(d,{dataRow:t=>e.jsxs("tr",{children:[e.jsx("th",{children:"Profit Before Tax"}),e.jsx("th",{children:s.profitBeforeTax.amount.formatted}),e.jsx("th",{children:t}),r.map(a=>e.jsx("th",{children:a.profitBeforeTax.amount.formatted},a.year))]}),commentaryData:s.profitBeforeTax}),e.jsx(d,{dataRow:t=>e.jsxs("tr",{children:[e.jsx("td",{children:"R&D Expenses By Records"}),e.jsx("td",{children:s.researchAndDevelopmentExpensesByRecords.amount.formatted}),e.jsx("th",{children:t}),r.map(a=>e.jsx("td",{children:a.researchAndDevelopmentExpensesByRecords.amount.formatted},a.year))]}),commentaryData:s.researchAndDevelopmentExpensesByRecords}),e.jsxs("tr",{children:[e.jsx("td",{children:"R&D Expenses For Tax"}),e.jsx("td",{children:s.researchAndDevelopmentExpensesForTax.formatted}),e.jsx("td",{}),r.map(t=>e.jsx("td",{children:t.researchAndDevelopmentExpensesForTax.formatted},t.year)),e.jsx("td",{})]}),e.jsx(d,{dataRow:t=>e.jsxs("tr",{children:[e.jsx("td",{children:"Fines"}),e.jsx("td",{children:s.fines.amount.formatted}),e.jsx("th",{children:t}),r.map(a=>e.jsx("td",{children:a.fines.amount.formatted},a.year))]}),commentaryData:s.fines}),e.jsx(d,{dataRow:t=>e.jsxs("tr",{children:[e.jsx("td",{children:"Untaxable Gifts"}),e.jsx("td",{children:s.untaxableGifts.amount.formatted}),e.jsx("th",{children:t}),r.map(a=>e.jsx("td",{children:a.untaxableGifts.amount.formatted},a.year))]}),commentaryData:s.untaxableGifts}),e.jsxs("tr",{children:[e.jsx("td",{children:"Business Trips Excess Expenses"}),e.jsx("td",{children:s.businessTripsExcessExpensesAmount.formatted}),e.jsx("td",{}),r.map(t=>e.jsx("td",{children:t.businessTripsExcessExpensesAmount.formatted},t.year)),e.jsx("td",{})]}),e.jsxs("tr",{children:[e.jsx("td",{children:"Salary Excess Expenses"}),e.jsx("td",{children:s.salaryExcessExpensesAmount.formatted}),e.jsx("td",{}),r.map(t=>e.jsx("td",{children:t.salaryExcessExpensesAmount.formatted},t.year)),e.jsx("td",{})]}),e.jsx(d,{dataRow:t=>e.jsxs("tr",{children:[e.jsx("td",{children:"Reserves"}),e.jsx("td",{children:s.reserves.amount.formatted}),e.jsx("th",{children:t}),r.map(a=>e.jsx("td",{children:a.reserves.amount.formatted},a.year))]}),commentaryData:s.reserves}),e.jsx(d,{dataRow:t=>e.jsxs("tr",{children:[e.jsx("td",{children:"Nontaxable Linkage"}),e.jsx("td",{children:s.nontaxableLinkage.amount.formatted}),e.jsx("th",{children:t}),r.map(a=>e.jsx("td",{children:a.nontaxableLinkage.amount.formatted},a.year))]}),commentaryData:s.nontaxableLinkage}),e.jsxs("tr",{children:[e.jsx("th",{children:"Taxable Income"}),e.jsx("th",{children:s.taxableIncome.formatted}),e.jsx("th",{}),r.map(t=>e.jsx("th",{children:t.taxableIncome.formatted},t.year)),e.jsx("td",{})]}),e.jsxs("tr",{children:[e.jsx("td",{children:"Tax Rate"}),e.jsxs("td",{children:[(s.taxRate*100).toFixed(1),"%"]}),e.jsx("td",{}),r.map(t=>e.jsxs("td",{children:[(t.taxRate*100).toFixed(1),"%"]},t.year)),e.jsx("td",{})]}),e.jsx(d,{dataRow:t=>e.jsxs("tr",{children:[e.jsx("td",{children:"Income with Special Tax Rate"}),e.jsx("td",{children:s.specialTaxableIncome.amount.formatted}),e.jsx("th",{children:t}),r.map(a=>e.jsx("td",{children:a.specialTaxableIncome.amount.formatted},a.year))]}),commentaryData:s.specialTaxableIncome}),e.jsxs("tr",{children:[e.jsx("td",{children:"Special Tax Rate"}),e.jsxs("td",{children:[(s.specialTaxRate*100).toFixed(1),"%"]}),e.jsx("td",{}),r.map(t=>e.jsxs("td",{children:[(t.specialTaxRate*100).toFixed(1),"%"]},t.year)),e.jsx("td",{})]})]}),e.jsx("tfoot",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Annual Tax Expense"}),e.jsx("th",{children:s.annualTaxExpense.formatted}),e.jsx("th",{}),r.map(t=>e.jsx("th",{children:t.annualTaxExpense.formatted},t.year)),e.jsx("td",{})]})})]})})})};export{G as TaxReport};
1
+ import{r as m,j as e,B as u,a as y,F as R,u as T,L as D,fX as E}from"./index-fZcP3X7C.js";import{d as b}from"./graphql-document-dedupe-fragments-ByT8-wlV.js";import{P as w}from"./page-layout-DUgx8eXl.js";import{R as d}from"./report-commentary-row-BonuPEAK.js";import{P as F}from"./modal-B_jJz-4Z.js";import{Y as f}from"./YearPickerInput-BdNLRDw_.js";import{F as g}from"./funnel-DP2XBopJ.js";import{T as v}from"./Table-Cr3nIx5M.js";import"./toggle-expansion-button-pWLCCDmM.js";import"./panel-top-open-CcWXXds7.js";function B({year:i,setYear:h,referenceYears:x,setReferenceYears:j}){const[l,c]=m.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsx(F,{opened:l,onClose:()=>c(!1),withCloseButton:!0,content:e.jsxs(e.Fragment,{children:[e.jsx(f,{label:"Change report year",value:new Date(i,0,1),onChange:n=>n&&h(n?.getFullYear()),popoverProps:{withinPortal:!0},minDate:new Date(2010,0,1),maxDate:new Date}),e.jsx(f,{type:"multiple",label:"Pick reference years",value:x?.map(n=>new Date(n,0,1)),onChange:n=>j(n.map(o=>o.getFullYear()).filter(o=>i!==o)),popoverProps:{withinPortal:!0},minDate:new Date(2010,0,1),maxDate:new Date})]})}),e.jsx(u,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>c(!0),children:e.jsx(g,{className:"size-5"})})]})}const G=()=>{const{year:i}=y(),{setFiltersContext:h}=m.useContext(R),[x,j]=m.useState(i?Number(i):new Date().getFullYear()),[l,c]=m.useState([]),[{data:n,fetching:o}]=T({query:b(E),variables:{reportYear:x,referenceYears:l}});m.useEffect(()=>{h(e.jsx("div",{className:"flex flex-row gap-2",children:e.jsx(B,{year:x,setYear:j,referenceYears:l,setReferenceYears:c})}))},[x,o,h,l,c]);const p=n?.taxReport,s=p?.report,r=p?.reference??[];return e.jsx(w,{title:"Tax Report",children:o?e.jsx(D,{className:"h-10 w-10 animate-spin mr-2 self-center"}):e.jsx("div",{className:"flex flex-col gap-4",children:s&&e.jsxs(v,{highlightOnHover:!0,fontSize:"md",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{}),e.jsx("th",{children:x},x),e.jsx("th",{}),r.map(t=>e.jsx("th",{children:t.year},t.year))]})}),e.jsxs("tbody",{children:[e.jsx(d,{dataRow:t=>e.jsxs("tr",{children:[e.jsx("th",{children:"Profit Before Tax"}),e.jsx("th",{children:s.profitBeforeTax.amount.formatted}),e.jsx("th",{children:t}),r.map(a=>e.jsx("th",{children:a.profitBeforeTax.amount.formatted},a.year))]}),commentaryData:s.profitBeforeTax}),e.jsx(d,{dataRow:t=>e.jsxs("tr",{children:[e.jsx("td",{children:"R&D Expenses By Records"}),e.jsx("td",{children:s.researchAndDevelopmentExpensesByRecords.amount.formatted}),e.jsx("th",{children:t}),r.map(a=>e.jsx("td",{children:a.researchAndDevelopmentExpensesByRecords.amount.formatted},a.year))]}),commentaryData:s.researchAndDevelopmentExpensesByRecords}),e.jsxs("tr",{children:[e.jsx("td",{children:"R&D Expenses For Tax"}),e.jsx("td",{children:s.researchAndDevelopmentExpensesForTax.formatted}),e.jsx("td",{}),r.map(t=>e.jsx("td",{children:t.researchAndDevelopmentExpensesForTax.formatted},t.year)),e.jsx("td",{})]}),e.jsx(d,{dataRow:t=>e.jsxs("tr",{children:[e.jsx("td",{children:"Fines"}),e.jsx("td",{children:s.fines.amount.formatted}),e.jsx("th",{children:t}),r.map(a=>e.jsx("td",{children:a.fines.amount.formatted},a.year))]}),commentaryData:s.fines}),e.jsx(d,{dataRow:t=>e.jsxs("tr",{children:[e.jsx("td",{children:"Untaxable Gifts"}),e.jsx("td",{children:s.untaxableGifts.amount.formatted}),e.jsx("th",{children:t}),r.map(a=>e.jsx("td",{children:a.untaxableGifts.amount.formatted},a.year))]}),commentaryData:s.untaxableGifts}),e.jsxs("tr",{children:[e.jsx("td",{children:"Business Trips Excess Expenses"}),e.jsx("td",{children:s.businessTripsExcessExpensesAmount.formatted}),e.jsx("td",{}),r.map(t=>e.jsx("td",{children:t.businessTripsExcessExpensesAmount.formatted},t.year)),e.jsx("td",{})]}),e.jsxs("tr",{children:[e.jsx("td",{children:"Salary Excess Expenses"}),e.jsx("td",{children:s.salaryExcessExpensesAmount.formatted}),e.jsx("td",{}),r.map(t=>e.jsx("td",{children:t.salaryExcessExpensesAmount.formatted},t.year)),e.jsx("td",{})]}),e.jsx(d,{dataRow:t=>e.jsxs("tr",{children:[e.jsx("td",{children:"Reserves"}),e.jsx("td",{children:s.reserves.amount.formatted}),e.jsx("th",{children:t}),r.map(a=>e.jsx("td",{children:a.reserves.amount.formatted},a.year))]}),commentaryData:s.reserves}),e.jsx(d,{dataRow:t=>e.jsxs("tr",{children:[e.jsx("td",{children:"Nontaxable Linkage"}),e.jsx("td",{children:s.nontaxableLinkage.amount.formatted}),e.jsx("th",{children:t}),r.map(a=>e.jsx("td",{children:a.nontaxableLinkage.amount.formatted},a.year))]}),commentaryData:s.nontaxableLinkage}),e.jsxs("tr",{children:[e.jsx("th",{children:"Taxable Income"}),e.jsx("th",{children:s.taxableIncome.formatted}),e.jsx("th",{}),r.map(t=>e.jsx("th",{children:t.taxableIncome.formatted},t.year)),e.jsx("td",{})]}),e.jsxs("tr",{children:[e.jsx("td",{children:"Tax Rate"}),e.jsxs("td",{children:[(s.taxRate*100).toFixed(1),"%"]}),e.jsx("td",{}),r.map(t=>e.jsxs("td",{children:[(t.taxRate*100).toFixed(1),"%"]},t.year)),e.jsx("td",{})]}),e.jsx(d,{dataRow:t=>e.jsxs("tr",{children:[e.jsx("td",{children:"Income with Special Tax Rate"}),e.jsx("td",{children:s.specialTaxableIncome.amount.formatted}),e.jsx("th",{children:t}),r.map(a=>e.jsx("td",{children:a.specialTaxableIncome.amount.formatted},a.year))]}),commentaryData:s.specialTaxableIncome}),e.jsxs("tr",{children:[e.jsx("td",{children:"Special Tax Rate"}),e.jsxs("td",{children:[(s.specialTaxRate*100).toFixed(1),"%"]}),e.jsx("td",{}),r.map(t=>e.jsxs("td",{children:[(t.specialTaxRate*100).toFixed(1),"%"]},t.year)),e.jsx("td",{})]})]}),e.jsx("tfoot",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Annual Tax Expense"}),e.jsx("th",{children:s.annualTaxExpense.formatted}),e.jsx("th",{}),r.map(t=>e.jsx("th",{children:t.annualTaxExpense.formatted},t.year)),e.jsx("td",{})]})})]})})})};export{G as TaxReport};
@@ -1,4 +1,4 @@
1
- import{cA as fr,ac as gr,ab as ge,j as F,r as kt,bo as pr,B as mr,G as br,x as le,br as Pn,bs as Dn,bt as An,bv as xr,F as _r,u as yr,bn as wr,aN as it,L as vr,cB as Mr}from"./index-CcJvt1sI.js";import{u as io}from"./use-url-query-D-GsTMWL.js";import{P as Sr}from"./page-layout-BNHKLJFL.js";import{P as kr}from"./modal-DOtlViK5.js";import{F as Cr}from"./funnel-IYKnhWOy.js";/*!
1
+ import{cA as fr,ac as gr,ab as ge,j as F,r as kt,bo as pr,B as mr,G as br,x as le,br as Pn,bs as Dn,bt as An,bv as xr,F as _r,u as yr,bn as wr,aN as it,L as vr,cB as Mr}from"./index-fZcP3X7C.js";import{u as io}from"./use-url-query-DyJg_rMw.js";import{P as Sr}from"./page-layout-DUgx8eXl.js";import{P as kr}from"./modal-B_jJz-4Z.js";import{F as Cr}from"./funnel-DP2XBopJ.js";/*!
2
2
  * decimal.js v10.6.0
3
3
  * An arbitrary-precision Decimal type for JavaScript.
4
4
  * https://github.com/MikeMcl/decimal.js
@@ -1 +1 @@
1
- import{g as k,h as M,r as a,t as j,i as A,u as N,k as F,j as e,c as L,l as P,B as S,m as v,n as T,I as z,F as D,o as $,T as O,L as R,p as U,R as b,q,s as _}from"./index-CcJvt1sI.js";import{u as C}from"./use-url-query-D-GsTMWL.js";import{B as Q}from"./business-header-CMH3yBZc.js";import{C as V,M as H}from"./Checkbox-w99PhJ6L.js";import{P as K}from"./page-layout-BNHKLJFL.js";import{P as G}from"./Pagination-BVQu3Yj6.js";import{P as J,a as W}from"./panel-top-open-DQ1wo5PZ.js";import"./building-2-BE02hpsM.js";import"./create-event-handler-BiA-1lGu.js";const X="mergeBusinesses",Y=()=>{const[{fetching:o},d]=k(M),u=a.useCallback(async l=>{const c=`Error merging into business ID [${l.targetBusinessId}]`,t=`${X}-${l.targetBusinessId}`;j.loading("Merging Businesses",{id:t});try{const i=await d(l),s=A(i,c,t);if(s)return j.success("Success",{id:t,description:"Businesses merged"}),s.mergeBusinesses.id}catch(i){console.error(`${c}: ${i}`),j.error("Error",{id:t,description:c,duration:1e5,closeButton:!0})}},[d]);return{fetching:o,mergeBusinesses:u}};function Z({businessIds:o,onDone:d,resetMerge:u}){const{mergeBusinesses:l,fetching:c}=Y(),t=Array.from(new Set(o)),[{data:i,fetching:s}]=N({query:F,variables:{businessIds:t}}),[m,h]=a.useState(i?.businesses[0]),n=i?.businesses.length!==t.length&&"Some businesses were not Found"||void 0,g=i?.businesses||[],p=a.useCallback(async()=>{if(!m){j.error("Error",{description:"No main business selected"});return}if(t.length<2){j.error("Error",{description:"At least 2 businesses are required to execute a merge"});return}return await l({targetBusinessId:m.id,businessIdsToMerge:t.filter(x=>x!==m.id)}),u(),d()},[m,t,l,d,u]);return e.jsxs(e.Fragment,{children:[s&&e.jsx("div",{className:"flex flex-col text-center w-full mb-1",children:e.jsx(L,{})}),!s&&n&&e.jsx("div",{className:"flex flex-col text-center w-full mb-1",children:e.jsx("h3",{className:"sm:text-2xl text-xl font-medium title-font mb-6 text-gray-900",children:n})}),!s&&!n&&e.jsxs(e.Fragment,{children:[e.jsxs("table",{children:[e.jsxs("tr",{children:[e.jsx("th",{children:"Main"}),g.map(x=>e.jsx("td",{children:e.jsx("div",{className:"flex items-center justify-center mx-2 px-2 py-2 border-2 border-b-0 rounded-t-xl",children:e.jsx(V,{checked:x.id===m?.id,size:"xl",onClick:()=>{h(x)}})})},x.id))]}),e.jsxs("tr",{children:[e.jsx("th",{children:"Name"}),g.map(x=>e.jsx("td",{children:x.name},x.id))]})]}),e.jsxs("div",{className:"flex justify-center gap-5 mt-5",children:[e.jsx("button",{type:"button",className:" text-white bg-blue-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-blue-600 rounded-sm text-lg",disabled:s||c,onClick:p,children:"Accept"}),e.jsx("button",{type:"button",className:" text-white bg-red-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-red-600 rounded-sm text-lg",onClick:d,children:"Cancel"}),e.jsx("button",{type:"button",className:" text-white bg-red-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-red-600 rounded-sm text-lg",onClick:()=>{u(),d()},children:"Reset Merge"})]})]})]})}function ee(o){const[d,{close:u,open:l}]=P(!1),{selected:c,resetMerge:t}=o,i=new Set(c.map(({id:g})=>g)),s=i.size>=1,[m,h]=a.useState(s?"default":"outline");a.useEffect(()=>{h(s?"default":"outline")},[s]);const n=a.useCallback(()=>{u(),c.map(({onChange:g})=>g())},[c,u]);return e.jsxs(e.Fragment,{children:[e.jsx(S,{onClick:()=>{s&&l()},disabled:!s,variant:m,className:v("size-7.5",s?" bg-blue-500 hover:bg-blue-500/90":""),size:"icon",children:e.jsx(H,{className:"size-5"})}),e.jsx(T,{opened:d,onClose:u,size:"auto",centered:!0,children:e.jsx(Z,{businessIds:Array.from(i),onDone:n,resetMerge:t})})]})}function se({activePage:o,setPage:d,totalPages:u=1,businessName:l,setBusinessName:c}){const{get:t,set:i}=C(),[s,m]=a.useState(l);a.useEffect(()=>{const n=o>1?o.toFixed(0):void 0,g=t("page");n!==g&&n!=="1"&&i("page",n)},[o,t,i]),a.useEffect(()=>{const n=setTimeout(()=>{c(s)},600);return()=>{clearTimeout(n)}},[s,c]);const h=n=>{m(n)};return e.jsxs("div",{className:"flex flex-row gap-5 items-center",children:[e.jsx(G,{className:"flex-auto",value:o,onChange:d,total:u}),e.jsx(z,{className:"w-72",placeholder:"Business Name",defaultValue:l??void 0,onChange:n=>h(n.target.value===""?void 0:n.target.value)})]})}const ue=()=>{const{get:o}=C(),[d,u]=a.useState(!1),[l,c]=a.useState(o("page")?Number(o("page")):1),[t,i]=a.useState(o("name")?o("page"):void 0),{setFiltersContext:s}=a.useContext(D),[{data:m,fetching:h},n]=N({query:_,variables:{page:l,limit:100,name:t}}),g=$(),[p,x]=a.useState([]),y=a.useCallback((r,f)=>{p.map(B=>B.id).includes(r)?x(p.filter(B=>B.id!==r)):x([...p,{id:r,onChange:f}])},[p]);function I(){x([])}a.useEffect(()=>{s(e.jsxs("div",{className:"flex flex-row gap-x-5",children:[e.jsx(se,{activePage:l,setPage:c,businessName:t,setBusinessName:i,totalPages:m?.allBusinesses?.pageInfo.totalPages}),e.jsx(O,{label:"Expand all businesses",children:e.jsx(S,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>u(r=>!r),children:d?e.jsx(J,{className:"size-5"}):e.jsx(W,{className:"size-5"})})}),e.jsx(ee,{selected:p,resetMerge:I})]}))},[m,l,t,d,s,c,i,u,p]);const E=m?.allBusinesses?.nodes.filter(r=>r.__typename==="LtdFinancialEntity").sort((r,f)=>r.name.toLowerCase()>f.name.toLowerCase()?1:-1)??[],w=new Set(p.map(r=>r.id));return e.jsx(K,{title:`Businesses (${m?.allBusinesses?.pageInfo.totalRecords??""})`,description:"All businesses",headerActions:e.jsx("div",{className:"flex items-center py-4 gap-4",children:e.jsx(q,{description:"",onAdd:()=>n()})}),children:h?e.jsx("div",{className:"flex flex-row justify-center",children:e.jsx(R,{className:v("h-10 w-10 animate-spin mr-2")})}):e.jsx("div",{className:"space-y-2",children:E.map(r=>e.jsx("div",{className:"group relative border rounded-lg hover:shadow-md transition-shadow",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"pl-4 flex items-center",children:e.jsx(U,{checked:w.has(r.id),onCheckedChange:()=>{y(r.id,()=>{})},className:"h-4 w-4 rounded border-gray-300 cursor-pointer",onClick:f=>f.stopPropagation()})}),e.jsx("div",{role:"button",tabIndex:0,className:"flex-1 cursor-pointer",onClick:()=>{g(b.BUSINESSES.DETAIL(r.id),{state:{from:b.BUSINESSES.ALL}})},onKeyDown:f=>{(f.key==="Enter"||f.key===" ")&&(f.preventDefault(),g(b.BUSINESSES.DETAIL(r.id),{state:{from:b.BUSINESSES.ALL}}))},children:e.jsx(Q,{data:r})})]})},r.id))})})};export{ue as Businesses};
1
+ import{g as k,h as M,r as a,t as j,i as A,u as N,k as F,j as e,c as L,l as P,B as S,m as v,n as T,I as z,F as D,o as $,T as O,L as R,p as U,R as b,q,s as _}from"./index-fZcP3X7C.js";import{u as C}from"./use-url-query-DyJg_rMw.js";import{B as Q}from"./business-header-Dx4N1uVn.js";import{C as V,M as H}from"./Checkbox-qIwbw1Vm.js";import{P as K}from"./page-layout-DUgx8eXl.js";import{P as G}from"./Pagination-D9TkQfLt.js";import{P as J,a as W}from"./panel-top-open-CcWXXds7.js";import"./building-2-B6TvGHom.js";import"./create-event-handler-BiA-1lGu.js";const X="mergeBusinesses",Y=()=>{const[{fetching:o},d]=k(M),u=a.useCallback(async l=>{const c=`Error merging into business ID [${l.targetBusinessId}]`,t=`${X}-${l.targetBusinessId}`;j.loading("Merging Businesses",{id:t});try{const i=await d(l),s=A(i,c,t);if(s)return j.success("Success",{id:t,description:"Businesses merged"}),s.mergeBusinesses.id}catch(i){console.error(`${c}: ${i}`),j.error("Error",{id:t,description:c,duration:1e5,closeButton:!0})}},[d]);return{fetching:o,mergeBusinesses:u}};function Z({businessIds:o,onDone:d,resetMerge:u}){const{mergeBusinesses:l,fetching:c}=Y(),t=Array.from(new Set(o)),[{data:i,fetching:s}]=N({query:F,variables:{businessIds:t}}),[m,h]=a.useState(i?.businesses[0]),n=i?.businesses.length!==t.length&&"Some businesses were not Found"||void 0,g=i?.businesses||[],p=a.useCallback(async()=>{if(!m){j.error("Error",{description:"No main business selected"});return}if(t.length<2){j.error("Error",{description:"At least 2 businesses are required to execute a merge"});return}return await l({targetBusinessId:m.id,businessIdsToMerge:t.filter(x=>x!==m.id)}),u(),d()},[m,t,l,d,u]);return e.jsxs(e.Fragment,{children:[s&&e.jsx("div",{className:"flex flex-col text-center w-full mb-1",children:e.jsx(L,{})}),!s&&n&&e.jsx("div",{className:"flex flex-col text-center w-full mb-1",children:e.jsx("h3",{className:"sm:text-2xl text-xl font-medium title-font mb-6 text-gray-900",children:n})}),!s&&!n&&e.jsxs(e.Fragment,{children:[e.jsxs("table",{children:[e.jsxs("tr",{children:[e.jsx("th",{children:"Main"}),g.map(x=>e.jsx("td",{children:e.jsx("div",{className:"flex items-center justify-center mx-2 px-2 py-2 border-2 border-b-0 rounded-t-xl",children:e.jsx(V,{checked:x.id===m?.id,size:"xl",onClick:()=>{h(x)}})})},x.id))]}),e.jsxs("tr",{children:[e.jsx("th",{children:"Name"}),g.map(x=>e.jsx("td",{children:x.name},x.id))]})]}),e.jsxs("div",{className:"flex justify-center gap-5 mt-5",children:[e.jsx("button",{type:"button",className:" text-white bg-blue-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-blue-600 rounded-sm text-lg",disabled:s||c,onClick:p,children:"Accept"}),e.jsx("button",{type:"button",className:" text-white bg-red-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-red-600 rounded-sm text-lg",onClick:d,children:"Cancel"}),e.jsx("button",{type:"button",className:" text-white bg-red-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-red-600 rounded-sm text-lg",onClick:()=>{u(),d()},children:"Reset Merge"})]})]})]})}function ee(o){const[d,{close:u,open:l}]=P(!1),{selected:c,resetMerge:t}=o,i=new Set(c.map(({id:g})=>g)),s=i.size>=1,[m,h]=a.useState(s?"default":"outline");a.useEffect(()=>{h(s?"default":"outline")},[s]);const n=a.useCallback(()=>{u(),c.map(({onChange:g})=>g())},[c,u]);return e.jsxs(e.Fragment,{children:[e.jsx(S,{onClick:()=>{s&&l()},disabled:!s,variant:m,className:v("size-7.5",s?" bg-blue-500 hover:bg-blue-500/90":""),size:"icon",children:e.jsx(H,{className:"size-5"})}),e.jsx(T,{opened:d,onClose:u,size:"auto",centered:!0,children:e.jsx(Z,{businessIds:Array.from(i),onDone:n,resetMerge:t})})]})}function se({activePage:o,setPage:d,totalPages:u=1,businessName:l,setBusinessName:c}){const{get:t,set:i}=C(),[s,m]=a.useState(l);a.useEffect(()=>{const n=o>1?o.toFixed(0):void 0,g=t("page");n!==g&&n!=="1"&&i("page",n)},[o,t,i]),a.useEffect(()=>{const n=setTimeout(()=>{c(s)},600);return()=>{clearTimeout(n)}},[s,c]);const h=n=>{m(n)};return e.jsxs("div",{className:"flex flex-row gap-5 items-center",children:[e.jsx(G,{className:"flex-auto",value:o,onChange:d,total:u}),e.jsx(z,{className:"w-72",placeholder:"Business Name",defaultValue:l??void 0,onChange:n=>h(n.target.value===""?void 0:n.target.value)})]})}const ue=()=>{const{get:o}=C(),[d,u]=a.useState(!1),[l,c]=a.useState(o("page")?Number(o("page")):1),[t,i]=a.useState(o("name")?o("page"):void 0),{setFiltersContext:s}=a.useContext(D),[{data:m,fetching:h},n]=N({query:_,variables:{page:l,limit:100,name:t}}),g=$(),[p,x]=a.useState([]),y=a.useCallback((r,f)=>{p.map(B=>B.id).includes(r)?x(p.filter(B=>B.id!==r)):x([...p,{id:r,onChange:f}])},[p]);function I(){x([])}a.useEffect(()=>{s(e.jsxs("div",{className:"flex flex-row gap-x-5",children:[e.jsx(se,{activePage:l,setPage:c,businessName:t,setBusinessName:i,totalPages:m?.allBusinesses?.pageInfo.totalPages}),e.jsx(O,{label:"Expand all businesses",children:e.jsx(S,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>u(r=>!r),children:d?e.jsx(J,{className:"size-5"}):e.jsx(W,{className:"size-5"})})}),e.jsx(ee,{selected:p,resetMerge:I})]}))},[m,l,t,d,s,c,i,u,p]);const E=m?.allBusinesses?.nodes.filter(r=>r.__typename==="LtdFinancialEntity").sort((r,f)=>r.name.toLowerCase()>f.name.toLowerCase()?1:-1)??[],w=new Set(p.map(r=>r.id));return e.jsx(K,{title:`Businesses (${m?.allBusinesses?.pageInfo.totalRecords??""})`,description:"All businesses",headerActions:e.jsx("div",{className:"flex items-center py-4 gap-4",children:e.jsx(q,{description:"",onAdd:()=>n()})}),children:h?e.jsx("div",{className:"flex flex-row justify-center",children:e.jsx(R,{className:v("h-10 w-10 animate-spin mr-2")})}):e.jsx("div",{className:"space-y-2",children:E.map(r=>e.jsx("div",{className:"group relative border rounded-lg hover:shadow-md transition-shadow",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"pl-4 flex items-center",children:e.jsx(U,{checked:w.has(r.id),onCheckedChange:()=>{y(r.id,()=>{})},className:"h-4 w-4 rounded border-gray-300 cursor-pointer",onClick:f=>f.stopPropagation()})}),e.jsx("div",{role:"button",tabIndex:0,className:"flex-1 cursor-pointer",onClick:()=>{g(b.BUSINESSES.DETAIL(r.id),{state:{from:b.BUSINESSES.ALL}})},onKeyDown:f=>{(f.key==="Enter"||f.key===" ")&&(f.preventDefault(),g(b.BUSINESSES.DETAIL(r.id),{state:{from:b.BUSINESSES.ALL}}))},children:e.jsx(Q,{data:r})})]})},r.id))})})};export{ue as Businesses};
@@ -1 +1 @@
1
- import{u as M,d9 as W,t as C,r as s,g as K,i as Q,da as X,db as Y,J as F,dc as E,j as e,D as R,aO as G,B as v,au as _,z as V,aP as J,aQ as U,am as Z,an as ee,ao as se,ap as te,ar as ne,dd as ae,de as re,df as q,dg as z,bW as ce,dh as $,di as ie,K as k,W as B,L as A,dj as le,e as oe,N as de,P as ue,dk as me,bg as he,b1 as xe,dl as je,x as P,dm as H,G as pe,bI as fe,w as ge,V as ye,b8 as ve,cK as De,cV as be,cW as Ce,cX as O,cY as g,c_ as Ne,c$ as y,aw as we,bS as Ie,F as Me,c as Te}from"./index-CcJvt1sI.js";import{s as L}from"./subMonths-GbNm9rnx.js";const Se=()=>{const[{data:u,fetching:o,error:c},x]=M({query:W});c&&(console.error(`Error fetching contracts: ${c}`),C.error("Error",{description:"Unable to fetch contracts"}));const a=s.useMemo(()=>u?.allOpenContracts?.slice().sort((t,d)=>t.client.originalBusiness.name>d.client.originalBusiness.name?1:-1)??[],[u]),i=s.useMemo(()=>a.map(t=>({value:t.id,label:t.client.originalBusiness.name})),[a]);return{fetching:o,refresh:()=>x(),openContracts:a,selectableOpenContracts:i}},Fe="IssueMonthlyDocuments",Ee=()=>{const[{fetching:u},o]=K(X),c=s.useCallback(async x=>{const a="Error issuing monthly documents",i=Fe;C.loading("Issuing documents",{id:i});try{const t=await o(x),d=Q(t,a,i);if(d?.issueGreenInvoiceDocuments?.success){C.success("Success",{id:i,description:"Documents issued successfully"});return}d?.issueGreenInvoiceDocuments?.errors&&console.error(d.issueGreenInvoiceDocuments.errors),C.error("Error",{id:i,description:a,duration:1e5,closeButton:!0})}catch(t){console.error(`${a}: ${t}`),C.error("Error",{id:i,description:a,duration:1e5,closeButton:!0})}},[o]);return{fetching:u,issueDocuments:c}};function Pe({issueMonth:u,contracts:o,onAdd:c}){const[x,a]=s.useState(!1),[i,t]=s.useState(""),[{data:d},h]=M({query:Y,variables:{issueMonth:u,clientId:i}}),j=s.useCallback(n=>{t(n),h()},[h,t]);return s.useEffect(()=>{i!==""&&d&&(c(F(E,d.clientMonthlyChargeDraft)),a(!1))},[i,d,c]),e.jsxs(R,{open:x,onOpenChange:a,children:[e.jsx(G,{asChild:!0,children:e.jsx(v,{variant:"outline",size:"icon",children:e.jsx(_,{})})}),e.jsxs(V,{className:"w-[400px] max-w-screen-md",children:[e.jsx(J,{children:e.jsx(U,{children:"Select document recipient"})}),e.jsxs(Z,{onValueChange:j,children:[e.jsx(ee,{children:e.jsx(se,{placeholder:"Recipient"})}),e.jsx(te,{children:o.map(n=>e.jsx(ne,{value:n.client.originalBusiness.id,children:n.client.originalBusiness.name},n.client.originalBusiness.id))})]})]})]})}function ke({onApprove:u,draft:o}){const[c,x]=s.useState(!1),[a,i]=s.useState(!1),[t,d]=s.useState(null),{previewDocument:h,fetching:j}=ae(),[n,N]=s.useState(re(o)),T=s.useCallback((l,p)=>{N(f=>({...f,[l]:p}))},[]);s.useEffect(()=>{i(!1)},[n]);const D=s.useCallback(async()=>{try{const l=await h({input:n});if(!l)throw new Error("No preview data returned");d(l),i(!0)}catch(l){console.error("Failed to generate preview:",l)}},[n,h]);s.useEffect(()=>{c&&!t&&D()},[c,t,D]);const w=n.income?.reduce((l,p)=>{const f=p.price*p.quantity,r=f*((p.vatRate||0)/100);return l+f+r},0)||0,I=()=>{u(n),x(!1)};return e.jsxs(R,{open:c,onOpenChange:x,children:[e.jsx(G,{asChild:!0,type:"button",children:e.jsxs(q,{children:[e.jsx(z,{asChild:!0,type:"button",children:e.jsx(v,{className:"size-7.5",variant:"secondary",onClick:()=>x(l=>!l),type:"button",children:e.jsx(ce,{className:"size-5"})})}),e.jsx($,{children:e.jsx("p",{children:"Edit document"})})]})}),e.jsx(V,{className:"w-7xl sm:max-w-[95%] max-h-[90vh] overflow-y-auto",children:e.jsx("div",{className:"min-h-screen bg-gray-50 p-4",children:e.jsxs("div",{className:"max-w-7xl mx-auto",children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("h1",{className:"text-3xl font-bold text-gray-900",children:"Edit Document"}),e.jsx("p",{className:"text-gray-600 mt-2",children:"Modify and preview your accounting document before issuing"})]}),e.jsxs("div",{className:"grid lg:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"space-y-6",children:[e.jsx(ie,{formData:n,updateFormData:T}),e.jsx(k,{children:e.jsxs(B,{className:"pt-6",children:[e.jsxs("div",{className:"flex gap-3",children:[e.jsx(v,{onClick:D,disabled:j||a,variant:"outline",className:"flex-1 bg-transparent",children:j?e.jsxs(e.Fragment,{children:[e.jsx(A,{className:"w-4 h-4 mr-2 animate-spin"}),"Generating..."]}):e.jsxs(e.Fragment,{children:[e.jsx(le,{className:"w-4 h-4 mr-2"}),"Preview"]})}),e.jsxs(v,{onClick:I,className:"flex-1",children:[e.jsx(oe,{className:"w-4 h-4 mr-2"}),"Accept Changes"]})]}),w>0&&e.jsx("div",{className:"mt-4 p-3 bg-blue-50 rounded-lg",children:e.jsxs("div",{className:"flex justify-between items-center font-medium text-blue-900",children:[e.jsx("span",{children:"Total Document Amount:"}),e.jsxs("span",{children:[w.toFixed(2)," ",n.currency]})]})})]})})]}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs(k,{className:"h-fit",children:[e.jsx(de,{children:e.jsx(ue,{children:"Document Preview"})}),e.jsx(B,{children:e.jsx("div",{className:"border-2 border-dashed border-gray-200 rounded-lg min-h-[600px] flex items-center justify-center bg-gray-50",children:j?e.jsxs("div",{className:"text-center",children:[e.jsx(A,{className:"w-8 h-8 animate-spin mx-auto mb-4 text-gray-400"}),e.jsx("p",{className:"text-gray-500",children:"Generating document preview..."})]}):t?e.jsx("div",{className:"w-full",children:e.jsx("div",{className:"bg-white shadow-lg rounded-lg overflow-hidden",children:e.jsx("div",{className:"aspect-[8.5/11] bg-white border",children:e.jsx("div",{className:"h-full flex items-center justify-center",children:e.jsxs("div",{className:"text-center p-6",children:[e.jsx(me,{src:t}),!a&&e.jsx("p",{className:"text-xs text-amber-600 mt-3 bg-amber-50 px-2 py-1 rounded",children:"Preview may be outdated"})]})})})})}):e.jsxs("div",{className:"text-center",children:[e.jsx(he,{className:"w-16 h-16 mx-auto mb-4 text-gray-300"}),e.jsx("p",{className:"text-gray-500 mb-2",children:"No preview available"}),e.jsx("p",{className:"text-sm text-gray-400",children:"Click Preview to generate document"})]})})})]}),n.client?.id&&e.jsx(xe,{businessId:n.client?.id,linkedDocumentIds:n.linkedDocumentIds??[]}),e.jsx(je,{documentType:n.type})]})]})]})})})]})}const Be=({drafts:u})=>{const[o,c]=s.useState(u.map(r=>F(E,r))),x=P(L(new Date,1),"yyyy-MM-dd"),[a,i]=s.useState(x),[{data:t},d]=M({query:H,variables:{issueMonth:a},pause:!0});s.useEffect(()=>{t?.clientMonthlyChargesDrafts&&c(t.clientMonthlyChargesDrafts.map(r=>F(E,r)))},[t,c]),s.useEffect(()=>{d()},[a,d]);const h=pe({values:{generateDocumentsInfo:o}}),{issueDocuments:j}=Ee(),{openContracts:n}=Se(),{fields:N,append:T,remove:D,update:w}=fe({control:h.control,name:"generateDocumentsInfo"}),I=h.watch("generateDocumentsInfo"),l=s.useMemo(()=>N.map((r,m)=>({...r,...I[m],id:r.client?.id})),[N,I]),p=s.useCallback(r=>{j(r)},[j]),f=s.useMemo(()=>n.filter(r=>r.billingCycle===ge.Monthly&&!l.some(m=>m.client?.id===r.client.originalBusiness.id)),[l,n]);return e.jsx("div",{className:"p-2",children:e.jsx(ye,{...h,children:e.jsxs("form",{onSubmit:h.handleSubmit(p),children:[e.jsxs("div",{className:"flex gap-2 items-center mb-4",children:[e.jsx(ve,{children:"Issue Month:"}),e.jsx(De,{value:new Date(a),onChange:r=>{const m=new Date(r.getFullYear(),r.getMonth(),15);i(P(m,"yyyy-MM-dd"))},popoverProps:{withinPortal:!0}})]}),e.jsxs(be,{children:[e.jsx(Ce,{children:e.jsxs(O,{children:[e.jsx(g,{children:"Name"}),e.jsx(g,{children:"Document"}),e.jsx(g,{children:"Amount"}),e.jsx(g,{children:"Remark"}),e.jsx(g,{children:"Recipients"}),e.jsx(g,{})]})}),e.jsx(Ne,{children:l.map(({id:r,...m},S)=>e.jsxs(O,{children:[e.jsx(y,{children:m.client?.name}),e.jsx(y,{children:m.type}),e.jsxs(y,{children:[m.income?.[0]?.price," ",m.income?.[0]?.currency]}),e.jsx(y,{children:e.jsx("span",{className:"text-sm text-gray-500 whitespace-normal max-w-50",children:m.remarks})}),e.jsx(y,{children:e.jsx("div",{className:"flex flex-col",children:m.client?.emails?.map(b=>e.jsx("span",{className:"text-sm text-gray-500",children:b},b))})}),e.jsx(y,{children:e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs(q,{children:[e.jsx(z,{asChild:!0,type:"button",children:e.jsx(v,{className:"size-7.5",variant:"secondary",onClick:()=>D(S),children:e.jsx(we,{size:16})})}),e.jsx($,{children:e.jsx("p",{children:"Remove document"})})]}),e.jsx(ke,{draft:m,onApprove:b=>{h.setValue(`generateDocumentsInfo.${S}`,b,{shouldDirty:!0,shouldTouch:!0,shouldValidate:!0}),w(S,{...b})}})]})})]},r))})]}),e.jsxs("div",{className:"flex justify-between items-center mt-4",children:[e.jsx(Pe,{contracts:f,onAdd:T,issueMonth:a}),e.jsx(Ie,{onConfirm:h.handleSubmit(p),title:`Are you sure you want to issue ${l.length} documents?`,children:e.jsx(v,{children:"Issue"})})]})]})})})},Re=()=>{const{setFiltersContext:u}=s.useContext(Me),[{data:o,fetching:c}]=M({query:H,variables:{issueMonth:P(L(new Date,1),"yyyy-MM-dd")}});return s.useEffect(()=>{o?.clientMonthlyChargesDrafts||u(null)},[o,u]),c?e.jsx(Te,{}):e.jsx(Be,{drafts:o?.clientMonthlyChargesDrafts??[]})};export{Re as IssueDocuments};
1
+ import{u as M,d9 as W,t as C,r as s,g as K,i as Q,da as X,db as Y,J as F,dc as E,j as e,D as R,aO as G,B as v,au as _,z as V,aP as J,aQ as U,am as Z,an as ee,ao as se,ap as te,ar as ne,dd as ae,de as re,df as q,dg as z,bW as ce,dh as $,di as ie,K as k,W as B,L as A,dj as le,e as oe,N as de,P as ue,dk as me,bg as he,b1 as xe,dl as je,x as P,dm as H,G as pe,bI as fe,w as ge,V as ye,b8 as ve,cK as De,cV as be,cW as Ce,cX as O,cY as g,c_ as Ne,c$ as y,aw as we,bS as Ie,F as Me,c as Te}from"./index-fZcP3X7C.js";import{s as L}from"./subMonths-CLe-U48r.js";const Se=()=>{const[{data:u,fetching:o,error:c},x]=M({query:W});c&&(console.error(`Error fetching contracts: ${c}`),C.error("Error",{description:"Unable to fetch contracts"}));const a=s.useMemo(()=>u?.allOpenContracts?.slice().sort((t,d)=>t.client.originalBusiness.name>d.client.originalBusiness.name?1:-1)??[],[u]),i=s.useMemo(()=>a.map(t=>({value:t.id,label:t.client.originalBusiness.name})),[a]);return{fetching:o,refresh:()=>x(),openContracts:a,selectableOpenContracts:i}},Fe="IssueMonthlyDocuments",Ee=()=>{const[{fetching:u},o]=K(X),c=s.useCallback(async x=>{const a="Error issuing monthly documents",i=Fe;C.loading("Issuing documents",{id:i});try{const t=await o(x),d=Q(t,a,i);if(d?.issueGreenInvoiceDocuments?.success){C.success("Success",{id:i,description:"Documents issued successfully"});return}d?.issueGreenInvoiceDocuments?.errors&&console.error(d.issueGreenInvoiceDocuments.errors),C.error("Error",{id:i,description:a,duration:1e5,closeButton:!0})}catch(t){console.error(`${a}: ${t}`),C.error("Error",{id:i,description:a,duration:1e5,closeButton:!0})}},[o]);return{fetching:u,issueDocuments:c}};function Pe({issueMonth:u,contracts:o,onAdd:c}){const[x,a]=s.useState(!1),[i,t]=s.useState(""),[{data:d},h]=M({query:Y,variables:{issueMonth:u,clientId:i}}),j=s.useCallback(n=>{t(n),h()},[h,t]);return s.useEffect(()=>{i!==""&&d&&(c(F(E,d.clientMonthlyChargeDraft)),a(!1))},[i,d,c]),e.jsxs(R,{open:x,onOpenChange:a,children:[e.jsx(G,{asChild:!0,children:e.jsx(v,{variant:"outline",size:"icon",children:e.jsx(_,{})})}),e.jsxs(V,{className:"w-[400px] max-w-screen-md",children:[e.jsx(J,{children:e.jsx(U,{children:"Select document recipient"})}),e.jsxs(Z,{onValueChange:j,children:[e.jsx(ee,{children:e.jsx(se,{placeholder:"Recipient"})}),e.jsx(te,{children:o.map(n=>e.jsx(ne,{value:n.client.originalBusiness.id,children:n.client.originalBusiness.name},n.client.originalBusiness.id))})]})]})]})}function ke({onApprove:u,draft:o}){const[c,x]=s.useState(!1),[a,i]=s.useState(!1),[t,d]=s.useState(null),{previewDocument:h,fetching:j}=ae(),[n,N]=s.useState(re(o)),T=s.useCallback((l,p)=>{N(f=>({...f,[l]:p}))},[]);s.useEffect(()=>{i(!1)},[n]);const D=s.useCallback(async()=>{try{const l=await h({input:n});if(!l)throw new Error("No preview data returned");d(l),i(!0)}catch(l){console.error("Failed to generate preview:",l)}},[n,h]);s.useEffect(()=>{c&&!t&&D()},[c,t,D]);const w=n.income?.reduce((l,p)=>{const f=p.price*p.quantity,r=f*((p.vatRate||0)/100);return l+f+r},0)||0,I=()=>{u(n),x(!1)};return e.jsxs(R,{open:c,onOpenChange:x,children:[e.jsx(G,{asChild:!0,type:"button",children:e.jsxs(q,{children:[e.jsx(z,{asChild:!0,type:"button",children:e.jsx(v,{className:"size-7.5",variant:"secondary",onClick:()=>x(l=>!l),type:"button",children:e.jsx(ce,{className:"size-5"})})}),e.jsx($,{children:e.jsx("p",{children:"Edit document"})})]})}),e.jsx(V,{className:"w-7xl sm:max-w-[95%] max-h-[90vh] overflow-y-auto",children:e.jsx("div",{className:"min-h-screen bg-gray-50 p-4",children:e.jsxs("div",{className:"max-w-7xl mx-auto",children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("h1",{className:"text-3xl font-bold text-gray-900",children:"Edit Document"}),e.jsx("p",{className:"text-gray-600 mt-2",children:"Modify and preview your accounting document before issuing"})]}),e.jsxs("div",{className:"grid lg:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"space-y-6",children:[e.jsx(ie,{formData:n,updateFormData:T}),e.jsx(k,{children:e.jsxs(B,{className:"pt-6",children:[e.jsxs("div",{className:"flex gap-3",children:[e.jsx(v,{onClick:D,disabled:j||a,variant:"outline",className:"flex-1 bg-transparent",children:j?e.jsxs(e.Fragment,{children:[e.jsx(A,{className:"w-4 h-4 mr-2 animate-spin"}),"Generating..."]}):e.jsxs(e.Fragment,{children:[e.jsx(le,{className:"w-4 h-4 mr-2"}),"Preview"]})}),e.jsxs(v,{onClick:I,className:"flex-1",children:[e.jsx(oe,{className:"w-4 h-4 mr-2"}),"Accept Changes"]})]}),w>0&&e.jsx("div",{className:"mt-4 p-3 bg-blue-50 rounded-lg",children:e.jsxs("div",{className:"flex justify-between items-center font-medium text-blue-900",children:[e.jsx("span",{children:"Total Document Amount:"}),e.jsxs("span",{children:[w.toFixed(2)," ",n.currency]})]})})]})})]}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs(k,{className:"h-fit",children:[e.jsx(de,{children:e.jsx(ue,{children:"Document Preview"})}),e.jsx(B,{children:e.jsx("div",{className:"border-2 border-dashed border-gray-200 rounded-lg min-h-[600px] flex items-center justify-center bg-gray-50",children:j?e.jsxs("div",{className:"text-center",children:[e.jsx(A,{className:"w-8 h-8 animate-spin mx-auto mb-4 text-gray-400"}),e.jsx("p",{className:"text-gray-500",children:"Generating document preview..."})]}):t?e.jsx("div",{className:"w-full",children:e.jsx("div",{className:"bg-white shadow-lg rounded-lg overflow-hidden",children:e.jsx("div",{className:"aspect-[8.5/11] bg-white border",children:e.jsx("div",{className:"h-full flex items-center justify-center",children:e.jsxs("div",{className:"text-center p-6",children:[e.jsx(me,{src:t}),!a&&e.jsx("p",{className:"text-xs text-amber-600 mt-3 bg-amber-50 px-2 py-1 rounded",children:"Preview may be outdated"})]})})})})}):e.jsxs("div",{className:"text-center",children:[e.jsx(he,{className:"w-16 h-16 mx-auto mb-4 text-gray-300"}),e.jsx("p",{className:"text-gray-500 mb-2",children:"No preview available"}),e.jsx("p",{className:"text-sm text-gray-400",children:"Click Preview to generate document"})]})})})]}),n.client?.id&&e.jsx(xe,{businessId:n.client?.id,linkedDocumentIds:n.linkedDocumentIds??[]}),e.jsx(je,{documentType:n.type})]})]})]})})})]})}const Be=({drafts:u})=>{const[o,c]=s.useState(u.map(r=>F(E,r))),x=P(L(new Date,1),"yyyy-MM-dd"),[a,i]=s.useState(x),[{data:t},d]=M({query:H,variables:{issueMonth:a},pause:!0});s.useEffect(()=>{t?.clientMonthlyChargesDrafts&&c(t.clientMonthlyChargesDrafts.map(r=>F(E,r)))},[t,c]),s.useEffect(()=>{d()},[a,d]);const h=pe({values:{generateDocumentsInfo:o}}),{issueDocuments:j}=Ee(),{openContracts:n}=Se(),{fields:N,append:T,remove:D,update:w}=fe({control:h.control,name:"generateDocumentsInfo"}),I=h.watch("generateDocumentsInfo"),l=s.useMemo(()=>N.map((r,m)=>({...r,...I[m],id:r.client?.id})),[N,I]),p=s.useCallback(r=>{j(r)},[j]),f=s.useMemo(()=>n.filter(r=>r.billingCycle===ge.Monthly&&!l.some(m=>m.client?.id===r.client.originalBusiness.id)),[l,n]);return e.jsx("div",{className:"p-2",children:e.jsx(ye,{...h,children:e.jsxs("form",{onSubmit:h.handleSubmit(p),children:[e.jsxs("div",{className:"flex gap-2 items-center mb-4",children:[e.jsx(ve,{children:"Issue Month:"}),e.jsx(De,{value:new Date(a),onChange:r=>{const m=new Date(r.getFullYear(),r.getMonth(),15);i(P(m,"yyyy-MM-dd"))},popoverProps:{withinPortal:!0}})]}),e.jsxs(be,{children:[e.jsx(Ce,{children:e.jsxs(O,{children:[e.jsx(g,{children:"Name"}),e.jsx(g,{children:"Document"}),e.jsx(g,{children:"Amount"}),e.jsx(g,{children:"Remark"}),e.jsx(g,{children:"Recipients"}),e.jsx(g,{})]})}),e.jsx(Ne,{children:l.map(({id:r,...m},S)=>e.jsxs(O,{children:[e.jsx(y,{children:m.client?.name}),e.jsx(y,{children:m.type}),e.jsxs(y,{children:[m.income?.[0]?.price," ",m.income?.[0]?.currency]}),e.jsx(y,{children:e.jsx("span",{className:"text-sm text-gray-500 whitespace-normal max-w-50",children:m.remarks})}),e.jsx(y,{children:e.jsx("div",{className:"flex flex-col",children:m.client?.emails?.map(b=>e.jsx("span",{className:"text-sm text-gray-500",children:b},b))})}),e.jsx(y,{children:e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs(q,{children:[e.jsx(z,{asChild:!0,type:"button",children:e.jsx(v,{className:"size-7.5",variant:"secondary",onClick:()=>D(S),children:e.jsx(we,{size:16})})}),e.jsx($,{children:e.jsx("p",{children:"Remove document"})})]}),e.jsx(ke,{draft:m,onApprove:b=>{h.setValue(`generateDocumentsInfo.${S}`,b,{shouldDirty:!0,shouldTouch:!0,shouldValidate:!0}),w(S,{...b})}})]})})]},r))})]}),e.jsxs("div",{className:"flex justify-between items-center mt-4",children:[e.jsx(Pe,{contracts:f,onAdd:T,issueMonth:a}),e.jsx(Ie,{onConfirm:h.handleSubmit(p),title:`Are you sure you want to issue ${l.length} documents?`,children:e.jsx(v,{children:"Issue"})})]})]})})})},Re=()=>{const{setFiltersContext:u}=s.useContext(Me),[{data:o,fetching:c}]=M({query:H,variables:{issueMonth:P(L(new Date,1),"yyyy-MM-dd")}});return s.useEffect(()=>{o?.clientMonthlyChargesDrafts||u(null)},[o,u]),c?e.jsx(Te,{}):e.jsx(Be,{drafts:o?.clientMonthlyChargesDrafts??[]})};export{Re as IssueDocuments};
@@ -1 +1 @@
1
- import{r as m,bv as k,j as e,bp as _,B as I,bo as V,G as Q,bq as G,cQ as q,ak as K,cR as z,br as y,bu as A,bs as F,bt as B,x as S,u as R,gp as X,K as P,c as U,N as $,P as J,aw as W,W as Y,F as Z,a8 as ee,at as ae,Q as se,dG as te,gq as re,aN as ne}from"./index-CcJvt1sI.js";import{u as O}from"./use-url-query-D-GsTMWL.js";import{P as oe}from"./page-layout-BNHKLJFL.js";import{k as ie,B as w,X as H,Y as le,l as ce,m as de,n as ue,o as me,p as pe,q as xe,r as ge}from"./chart-OVHXA3Uy.js";import{P as he}from"./modal-DOtlViK5.js";import{F as fe}from"./funnel-IYKnhWOy.js";import{M as E}from"./MultiSelect-9BbcXHjB.js";import{T as be}from"./index-ofME77ND.js";import{s as je}from"./sub-CIKovQuv.js";import"./sequential-CAnleQny.js";import"./similar-transactions-modal-DDVojjq0.js";import"./addDays-CjlJbHpj.js";import"./list-plus-Cv8qnwZd.js";import"./tooltip-Cy3vJ3fy.js";import"./subMonths-GbNm9rnx.js";var ye=ie({chartName:"BarChart",GraphicalChild:w,defaultTooltipEventType:"axis",validateTooltipEventTypes:["axis","item"],axisComponents:[{axisType:"xAxis",AxisComp:H},{axisType:"yAxis",AxisComp:le}],formatAxisMap:ce});function ve(s){return!s||V(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:i,closeModal:c}){const{control:t,handleSubmit:r,watch:g}=Q({defaultValues:{...s}}),{selectableBusinesses:b,fetching:h}=G(),{selectableFinancialEntities:f,fetching:v}=q(),{selectableTags:p,fetching:j}=K(),M=a=>{i(a),c()},C=g("excludedTags"),o=m.useMemo(()=>p.filter(a=>!C.includes(a.value)),[C,p]),d=g("includedTags"),n=m.useMemo(()=>p.filter(a=>!d.includes(a.value)),[d,p]);return e.jsxs("form",{onSubmit:r(M),children:[e.jsxs(z,{cols:2,children:[e.jsx(y,{name:"ownerId",control:t,defaultValue:s?.ownerId,render:({field:a,fieldState:l})=>e.jsx(A,{...a,data:b,value:a.value,disabled:h,label:"Owners",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:l.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:l})=>e.jsx(B,{...a,onChange:u=>{const T=u?typeof u=="string"?u:S(u,"yyyy-MM-dd"):void 0;T!==a.value&&a.onChange(T)},value:a.value?new Date(a.value):void 0,error:l.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:l})=>e.jsx(B,{...a,onChange:u=>{const T=u?typeof u=="string"?u:S(u,"yyyy-MM-dd"):void 0;T!==a.value&&a.onChange(T)},value:a.value?new Date(a.value):void 0,error:l.error?.message,label:"To Date",popoverProps:{withinPortal:!0}})}),e.jsx(y,{name:"period",control:t,defaultValue:x.MONTHLY,render:({field:a,fieldState:l})=>e.jsx(A,{...a,data:Object.values(x).map(u=>({value:u,label:u})),value:a.value,label:"Period",maxDropdownHeight:160,error:l.error?.message,withinPortal:!0})}),e.jsx(y,{name:"excludedCounterparties",control:t,defaultValue:s.excludedCounterparties,render:({field:a,fieldState:l})=>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:l.error?.message,withinPortal:!0})}),e.jsx(y,{name:"includedTags",control:t,defaultValue:s.includedTags,render:({field:a,fieldState:l})=>e.jsx(E,{...a,data:o,value:a.value??[],disabled:j,label:"Included Tags",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:l.error?.message,withinPortal:!0})}),e.jsx(y,{name:"excludedTags",control:t,defaultValue:s.excludedTags,render:({field:a,fieldState:l})=>e.jsx(E,{...a,data:n,value:a.value??[],disabled:j,label:"Excluded Tags",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:l.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:i,initiallyOpened:c=!1}){const[t,r]=m.useState(c),[g,b]=m.useState(!!s),{get:h,set:f}=O();m.useEffect(()=>{const p=ve(s),j=h(L);p!==j&&f(L,p)},[s,h,f]);const v=m.useCallback(p=>{k(p,s)||(i(p),b(!!p))},[s,i]);return e.jsxs("div",{className:"flex flex-row gap-5 items-center",children:[e.jsx(he,{opened:t,onClose:()=>r(!1),content:e.jsx(Ce,{filter:s,setFilter:v,closeModal:()=>r(!1)}),modalSize:"xl"}),e.jsx(_,{inline:!0,size:16,disabled:!g,children:e.jsx(I,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>r(!0),children:e.jsx(fe,{className:"size-5"})})})]})}const Ne=({period:s,transactionIDs:i,onCloseExtendedTransactions:c})=>{const[{data:t,fetching:r}]=R({query:X,variables:{transactionIDs:i}}),g=m.useMemo(()=>t?.transactionsByIDs?i.map(b=>t?.transactionsByIDs.find(h=>h.id===b)).filter(Boolean):[],[t,i]);return e.jsx(P,{className:"mt-5 w-full",children:r?e.jsx(U,{}):e.jsxs(e.Fragment,{children:[e.jsx($,{children:e.jsxs(J,{className:"flex justify-between",children:[e.jsxs("span",{children:[s," Transactions"]}),e.jsx(I,{variant:"link",onClick:c,children:e.jsx(W,{className:"h-4 w-4"})})]})}),e.jsx(Y,{children:e.jsx(be,{transactionsProps:g})})]})})},N={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 we(s,i,c){switch(c){case x.MONTHLY:{const t=String(i).padStart(2,"0");return`${s}-${t}`}case x.BI_MONTHLY:{const t=i%2===0?i-1:i,r=String(t).padStart(2,"0");return`${s}-${r}`}case x.QUARTERLY:{const t=Math.ceil(i/3);return`${s}-Q${t}`}case x.SEMI_ANNUALLY:{const t=i>6?2:1;return`${s}-H${t}`}case x.ANNUALLY:return String(s)}}function Me(s,i){switch(i){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=te(ne.Usd),ke=()=>{const{setFiltersContext:s}=m.useContext(Z),{userContext:i}=m.useContext(ee),{get:c}=O(),t=m.useMemo(()=>{const o={ownerId:i?.context.adminBusinessId,toDate:S(new Date,"yyyy-MM-dd"),period:x.MONTHLY,fromDate:S(je(new Date,{years:1}),"yyyy-MM-dd"),excludedCounterparties:[],includedTags:[],excludedTags:[]},d=c(L);if(d)try{return JSON.parse(decodeURIComponent(d))}catch(n){console.log("Error parsing balance report filters from URL:",n)}return o},[i?.context.adminBusinessId,c]),[r,g]=m.useState(t),[b,h]=m.useState(void 0),[f,v]=m.useState(Object.keys(N)),p=m.useMemo(()=>{const{ownerId:o,fromDate:d,toDate:n}=r;return{ownerId:o,fromDate:d,toDate:n}},[r]),[{data:j,fetching:M}]=R({query:re,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(ae,{options:Object.entries(N).map(([o,d])=>({label:d.label,value:o})),onValueChange:v,defaultValue:f,placeholder:"Select Data Sets",variant:"default",maxCount:1})]})),h(void 0)},[j,M,r,s,g,f]),m.useEffect(()=>{g(o=>({...o,ownerId:i?.context.adminBusinessId}))},[i]);const C=m.useMemo(()=>{if(!j?.transactionsForBalanceReport)return[];const o=new Map;j.transactionsForBalanceReport.map(n=>{if(n.counterparty?.id&&(!n.isFee&&i?.context.financialAccountsBusinessesIds?.includes(n.counterparty.id)||r.excludedCounterparties?.includes(n.counterparty.id))||r.includedTags.length>0&&(!n.charge?.tags||n.charge.tags.length===0||!n.charge.tags.some(u=>r.includedTags.includes(u.id)))||r.excludedTags.length>0&&n.charge?.tags.length&&n.charge.tags.some(u=>r.excludedTags.includes(u.id)))return;const a=we(n.year,n.month,r.period);o.has(a)||o.set(a,{income:0,expense:0,delta:0,transactions:[]});const l=o.get(a);n.amountUsd.raw>0?l.income+=n.amountUsd.raw:l.expense+=n.amountUsd.raw,l.delta+=n.amountUsd.raw,l.transactions.push(n)});let d=0;return Array.from(o.entries()).sort((n,a)=>n[0].localeCompare(a[0])).map(([n,a])=>(d+=a.delta,{period:n,income:a.income,expense:a.expense,delta:a.delta,cumulative:d,transactions:a.transactions.sort((l,u)=>Math.abs(u.amountUsd.raw)-Math.abs(l.amountUsd.raw))}))},[j,r.period,r.excludedCounterparties,i?.context.financialAccountsBusinessesIds,r.includedTags,r.excludedTags]);return e.jsx(oe,{title:"Balance Report",description:"Accounts periodical balance",children:M?e.jsx(U,{}):e.jsxs(e.Fragment,{children:[e.jsxs(P,{className:"w-full",children:[e.jsx($,{children:e.jsx(se,{children:"Click specific period to expand it's transactions data"})}),e.jsx(Y,{children:e.jsx(de,{config:N,className:"h-150 w-full",children:e.jsxs(ye,{accessibilityLayer:!0,data:C,onClick:o=>h(o.activeLabel),children:[e.jsx(ue,{vertical:!1}),e.jsx(H,{dataKey:"period",tickLine:!1,tickMargin:10,axisLine:!1,tickFormatter:o=>Me(o,r.period)}),e.jsx(me,{content:e.jsx(pe,{formatter:(o,d,n,a)=>{const l=`bg-[var(--color-${d})]`;return a<2?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:`${l} h-2.5 w-2.5 shrink-0 rounded-[2px]`}),N[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(o))})]}):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 ${l}`}),N[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(o))})]})}})}),e.jsx(xe,{content:e.jsx(ge,{})}),f.includes("income")&&e.jsx(w,{dataKey:"income",fill:"var(--color-income)",radius:4}),f.includes("expense")&&e.jsx(w,{dataKey:"expense",fill:"var(--color-expense)",radius:4}),f.includes("delta")&&e.jsx(w,{dataKey:"delta",fill:"var(--color-delta)",radius:4}),f.includes("cumulative")&&e.jsx(w,{dataKey:"cumulative",fill:"var(--color-cumulative)",radius:4})]})})})]}),b&&e.jsx(Ne,{period:b,onCloseExtendedTransactions:()=>h(void 0),transactionIDs:C.find(o=>o.period===b)?.transactions.map(o=>o.id)??[]})]})})};export{ke as BalanceReport};
1
+ import{r as m,bv as k,j as e,bp as _,B as I,bo as V,G as Q,bq as G,cQ as q,ak as K,cR as z,br as y,bu as A,bs as F,bt as B,x as S,u as R,gp as X,K as P,c as U,N as $,P as J,aw as W,W as Y,F as Z,a8 as ee,at as ae,Q as se,dG as te,gq as re,aN as ne}from"./index-fZcP3X7C.js";import{u as O}from"./use-url-query-DyJg_rMw.js";import{P as oe}from"./page-layout-DUgx8eXl.js";import{k as ie,B as w,X as H,Y as le,l as ce,m as de,n as ue,o as me,p as pe,q as xe,r as ge}from"./chart-Caa1VlDy.js";import{P as he}from"./modal-B_jJz-4Z.js";import{F as fe}from"./funnel-DP2XBopJ.js";import{M as E}from"./MultiSelect-Uj0K1auE.js";import{T as be}from"./index-8gQaTQhF.js";import{s as je}from"./sub-zRppNrG0.js";import"./sequential-CAnleQny.js";import"./similar-transactions-modal-Cdv2FmQ8.js";import"./addDays-CHr5nY3e.js";import"./list-plus-ZIHrrCaO.js";import"./tooltip-r34BEIrK.js";import"./subMonths-CLe-U48r.js";var ye=ie({chartName:"BarChart",GraphicalChild:w,defaultTooltipEventType:"axis",validateTooltipEventTypes:["axis","item"],axisComponents:[{axisType:"xAxis",AxisComp:H},{axisType:"yAxis",AxisComp:le}],formatAxisMap:ce});function ve(s){return!s||V(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:i,closeModal:c}){const{control:t,handleSubmit:r,watch:g}=Q({defaultValues:{...s}}),{selectableBusinesses:b,fetching:h}=G(),{selectableFinancialEntities:f,fetching:v}=q(),{selectableTags:p,fetching:j}=K(),M=a=>{i(a),c()},C=g("excludedTags"),o=m.useMemo(()=>p.filter(a=>!C.includes(a.value)),[C,p]),d=g("includedTags"),n=m.useMemo(()=>p.filter(a=>!d.includes(a.value)),[d,p]);return e.jsxs("form",{onSubmit:r(M),children:[e.jsxs(z,{cols:2,children:[e.jsx(y,{name:"ownerId",control:t,defaultValue:s?.ownerId,render:({field:a,fieldState:l})=>e.jsx(A,{...a,data:b,value:a.value,disabled:h,label:"Owners",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:l.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:l})=>e.jsx(B,{...a,onChange:u=>{const T=u?typeof u=="string"?u:S(u,"yyyy-MM-dd"):void 0;T!==a.value&&a.onChange(T)},value:a.value?new Date(a.value):void 0,error:l.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:l})=>e.jsx(B,{...a,onChange:u=>{const T=u?typeof u=="string"?u:S(u,"yyyy-MM-dd"):void 0;T!==a.value&&a.onChange(T)},value:a.value?new Date(a.value):void 0,error:l.error?.message,label:"To Date",popoverProps:{withinPortal:!0}})}),e.jsx(y,{name:"period",control:t,defaultValue:x.MONTHLY,render:({field:a,fieldState:l})=>e.jsx(A,{...a,data:Object.values(x).map(u=>({value:u,label:u})),value:a.value,label:"Period",maxDropdownHeight:160,error:l.error?.message,withinPortal:!0})}),e.jsx(y,{name:"excludedCounterparties",control:t,defaultValue:s.excludedCounterparties,render:({field:a,fieldState:l})=>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:l.error?.message,withinPortal:!0})}),e.jsx(y,{name:"includedTags",control:t,defaultValue:s.includedTags,render:({field:a,fieldState:l})=>e.jsx(E,{...a,data:o,value:a.value??[],disabled:j,label:"Included Tags",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:l.error?.message,withinPortal:!0})}),e.jsx(y,{name:"excludedTags",control:t,defaultValue:s.excludedTags,render:({field:a,fieldState:l})=>e.jsx(E,{...a,data:n,value:a.value??[],disabled:j,label:"Excluded Tags",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:l.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:i,initiallyOpened:c=!1}){const[t,r]=m.useState(c),[g,b]=m.useState(!!s),{get:h,set:f}=O();m.useEffect(()=>{const p=ve(s),j=h(L);p!==j&&f(L,p)},[s,h,f]);const v=m.useCallback(p=>{k(p,s)||(i(p),b(!!p))},[s,i]);return e.jsxs("div",{className:"flex flex-row gap-5 items-center",children:[e.jsx(he,{opened:t,onClose:()=>r(!1),content:e.jsx(Ce,{filter:s,setFilter:v,closeModal:()=>r(!1)}),modalSize:"xl"}),e.jsx(_,{inline:!0,size:16,disabled:!g,children:e.jsx(I,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>r(!0),children:e.jsx(fe,{className:"size-5"})})})]})}const Ne=({period:s,transactionIDs:i,onCloseExtendedTransactions:c})=>{const[{data:t,fetching:r}]=R({query:X,variables:{transactionIDs:i}}),g=m.useMemo(()=>t?.transactionsByIDs?i.map(b=>t?.transactionsByIDs.find(h=>h.id===b)).filter(Boolean):[],[t,i]);return e.jsx(P,{className:"mt-5 w-full",children:r?e.jsx(U,{}):e.jsxs(e.Fragment,{children:[e.jsx($,{children:e.jsxs(J,{className:"flex justify-between",children:[e.jsxs("span",{children:[s," Transactions"]}),e.jsx(I,{variant:"link",onClick:c,children:e.jsx(W,{className:"h-4 w-4"})})]})}),e.jsx(Y,{children:e.jsx(be,{transactionsProps:g})})]})})},N={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 we(s,i,c){switch(c){case x.MONTHLY:{const t=String(i).padStart(2,"0");return`${s}-${t}`}case x.BI_MONTHLY:{const t=i%2===0?i-1:i,r=String(t).padStart(2,"0");return`${s}-${r}`}case x.QUARTERLY:{const t=Math.ceil(i/3);return`${s}-Q${t}`}case x.SEMI_ANNUALLY:{const t=i>6?2:1;return`${s}-H${t}`}case x.ANNUALLY:return String(s)}}function Me(s,i){switch(i){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=te(ne.Usd),ke=()=>{const{setFiltersContext:s}=m.useContext(Z),{userContext:i}=m.useContext(ee),{get:c}=O(),t=m.useMemo(()=>{const o={ownerId:i?.context.adminBusinessId,toDate:S(new Date,"yyyy-MM-dd"),period:x.MONTHLY,fromDate:S(je(new Date,{years:1}),"yyyy-MM-dd"),excludedCounterparties:[],includedTags:[],excludedTags:[]},d=c(L);if(d)try{return JSON.parse(decodeURIComponent(d))}catch(n){console.log("Error parsing balance report filters from URL:",n)}return o},[i?.context.adminBusinessId,c]),[r,g]=m.useState(t),[b,h]=m.useState(void 0),[f,v]=m.useState(Object.keys(N)),p=m.useMemo(()=>{const{ownerId:o,fromDate:d,toDate:n}=r;return{ownerId:o,fromDate:d,toDate:n}},[r]),[{data:j,fetching:M}]=R({query:re,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(ae,{options:Object.entries(N).map(([o,d])=>({label:d.label,value:o})),onValueChange:v,defaultValue:f,placeholder:"Select Data Sets",variant:"default",maxCount:1})]})),h(void 0)},[j,M,r,s,g,f]),m.useEffect(()=>{g(o=>({...o,ownerId:i?.context.adminBusinessId}))},[i]);const C=m.useMemo(()=>{if(!j?.transactionsForBalanceReport)return[];const o=new Map;j.transactionsForBalanceReport.map(n=>{if(n.counterparty?.id&&(!n.isFee&&i?.context.financialAccountsBusinessesIds?.includes(n.counterparty.id)||r.excludedCounterparties?.includes(n.counterparty.id))||r.includedTags.length>0&&(!n.charge?.tags||n.charge.tags.length===0||!n.charge.tags.some(u=>r.includedTags.includes(u.id)))||r.excludedTags.length>0&&n.charge?.tags.length&&n.charge.tags.some(u=>r.excludedTags.includes(u.id)))return;const a=we(n.year,n.month,r.period);o.has(a)||o.set(a,{income:0,expense:0,delta:0,transactions:[]});const l=o.get(a);n.amountUsd.raw>0?l.income+=n.amountUsd.raw:l.expense+=n.amountUsd.raw,l.delta+=n.amountUsd.raw,l.transactions.push(n)});let d=0;return Array.from(o.entries()).sort((n,a)=>n[0].localeCompare(a[0])).map(([n,a])=>(d+=a.delta,{period:n,income:a.income,expense:a.expense,delta:a.delta,cumulative:d,transactions:a.transactions.sort((l,u)=>Math.abs(u.amountUsd.raw)-Math.abs(l.amountUsd.raw))}))},[j,r.period,r.excludedCounterparties,i?.context.financialAccountsBusinessesIds,r.includedTags,r.excludedTags]);return e.jsx(oe,{title:"Balance Report",description:"Accounts periodical balance",children:M?e.jsx(U,{}):e.jsxs(e.Fragment,{children:[e.jsxs(P,{className:"w-full",children:[e.jsx($,{children:e.jsx(se,{children:"Click specific period to expand it's transactions data"})}),e.jsx(Y,{children:e.jsx(de,{config:N,className:"h-150 w-full",children:e.jsxs(ye,{accessibilityLayer:!0,data:C,onClick:o=>h(o.activeLabel),children:[e.jsx(ue,{vertical:!1}),e.jsx(H,{dataKey:"period",tickLine:!1,tickMargin:10,axisLine:!1,tickFormatter:o=>Me(o,r.period)}),e.jsx(me,{content:e.jsx(pe,{formatter:(o,d,n,a)=>{const l=`bg-[var(--color-${d})]`;return a<2?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:`${l} h-2.5 w-2.5 shrink-0 rounded-[2px]`}),N[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(o))})]}):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 ${l}`}),N[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(o))})]})}})}),e.jsx(xe,{content:e.jsx(ge,{})}),f.includes("income")&&e.jsx(w,{dataKey:"income",fill:"var(--color-income)",radius:4}),f.includes("expense")&&e.jsx(w,{dataKey:"expense",fill:"var(--color-expense)",radius:4}),f.includes("delta")&&e.jsx(w,{dataKey:"delta",fill:"var(--color-delta)",radius:4}),f.includes("cumulative")&&e.jsx(w,{dataKey:"cumulative",fill:"var(--color-cumulative)",radius:4})]})})})]}),b&&e.jsx(Ne,{period:b,onCloseExtendedTransactions:()=>h(void 0),transactionIDs:C.find(o=>o.period===b)?.transactions.map(o=>o.id)??[]})]})})};export{ke as BalanceReport};
@@ -1 +1 @@
1
- import{r as c,j as e,B as u,a as y,F as g,u as P,L as D,fW as w}from"./index-CcJvt1sI.js";import{d as R}from"./graphql-document-dedupe-fragments-ByT8-wlV.js";import{P as E}from"./page-layout-BNHKLJFL.js";import{R as d}from"./report-commentary-row-DBOCwi7X.js";import{P as v}from"./modal-DOtlViK5.js";import{Y as p}from"./YearPickerInput-dCiPlZqk.js";import{F}from"./funnel-IYKnhWOy.js";import{T as C}from"./Table-CR8S5Pp5.js";import"./toggle-expansion-button-Bdpb_YfG.js";import"./panel-top-open-DQ1wo5PZ.js";function A({year:l,setYear:h,referenceYears:o,setReferenceYears:j}){const[m,x]=c.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsx(v,{opened:m,onClose:()=>x(!1),withCloseButton:!0,content:e.jsxs(e.Fragment,{children:[e.jsx(p,{label:"Change report year",value:new Date(l,0,1),onChange:n=>n&&h(n?.getFullYear()),popoverProps:{withinPortal:!0},minDate:new Date(2010,0,1),maxDate:new Date}),e.jsx(p,{type:"multiple",label:"Pick reference years",value:o?.map(n=>new Date(n,0,1)),onChange:n=>j(n.map(i=>i.getFullYear()).filter(i=>l!==i)),popoverProps:{withinPortal:!0},minDate:new Date(2010,0,1),maxDate:new Date})]})}),e.jsx(u,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>x(!0),children:e.jsx(F,{className:"size-5"})})]})}const I=()=>{const{year:l}=y(),{setFiltersContext:h}=c.useContext(g),[o,j]=c.useState(l?Number(l):new Date().getFullYear()),[m,x]=c.useState([]),[{data:n,fetching:i}]=P({query:R(w),variables:{reportYear:o,referenceYears:m}});c.useEffect(()=>{h(e.jsx("div",{className:"flex flex-row gap-2",children:e.jsx(A,{year:o,setYear:j,referenceYears:m,setReferenceYears:x})}))},[o,i,h,m,x]);const f=n?.profitAndLossReport,r=f?.report,s=f?.reference??[];return e.jsx(E,{title:"Profit and Loss Report",children:i?e.jsx(D,{className:"h-10 w-10 animate-spin mr-2 self-center"}):e.jsx("div",{className:"flex flex-col gap-4",children:r&&e.jsxs(C,{highlightOnHover:!0,fontSize:"md",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{}),e.jsx("th",{children:o},o),e.jsx("th",{}),s.map(t=>e.jsx("th",{children:t.year},t.year))]})}),e.jsxs("tbody",{children:[e.jsx(d,{dataRow:t=>e.jsxs("tr",{children:[e.jsx("th",{children:"Revenue"}),e.jsx("th",{children:r.revenue.amount.formatted}),e.jsx("th",{children:t}),s.map(a=>e.jsx("th",{children:a.revenue.amount.formatted},a.year))]}),commentaryData:r.revenue}),e.jsx(d,{dataRow:t=>e.jsxs("tr",{children:[e.jsx("td",{children:"Cost of Sales"}),e.jsx("td",{children:r.costOfSales.amount.formatted}),e.jsx("th",{children:t}),s.map(a=>e.jsx("td",{children:a.costOfSales.amount.formatted},a.year))]}),commentaryData:r.costOfSales}),e.jsxs("tr",{children:[e.jsx("th",{children:"Gross Profit"}),e.jsx("th",{children:r.grossProfit.formatted}),e.jsx("th",{}),s.map(t=>e.jsx("th",{children:t.grossProfit.formatted},t.year))]}),e.jsx(d,{dataRow:t=>e.jsxs("tr",{children:[e.jsx("td",{children:"R&D Expenses"}),e.jsx("td",{children:r.researchAndDevelopmentExpenses.amount.formatted}),e.jsx("th",{children:t}),s.map(a=>e.jsx("td",{children:a.researchAndDevelopmentExpenses.amount.formatted},a.year))]}),commentaryData:r.researchAndDevelopmentExpenses}),e.jsx(d,{dataRow:t=>e.jsxs("tr",{children:[e.jsx("td",{children:"Marketing Expenses"}),e.jsx("td",{children:r.marketingExpenses.amount.formatted}),e.jsx("th",{children:t}),s.map(a=>e.jsx("td",{children:a.marketingExpenses.amount.formatted},a.year))]}),commentaryData:r.marketingExpenses}),e.jsx(d,{dataRow:t=>e.jsxs("tr",{children:[e.jsx("td",{children:"Management and General Expenses"}),e.jsx("td",{children:r.managementAndGeneralExpenses.amount.formatted}),e.jsx("th",{children:t}),s.map(a=>e.jsx("td",{children:a.managementAndGeneralExpenses.amount.formatted},a.year))]}),commentaryData:r.managementAndGeneralExpenses}),e.jsxs("tr",{children:[e.jsx("th",{children:"Operating Profit"}),e.jsx("th",{children:r.operatingProfit.formatted}),e.jsx("th",{}),s.map(t=>e.jsx("th",{children:t.operatingProfit.formatted},t.year))]}),e.jsx(d,{dataRow:t=>e.jsxs("tr",{children:[e.jsx("td",{children:"Financial Expenses"}),e.jsx("td",{children:r.financialExpenses.amount.formatted}),e.jsx("th",{children:t}),s.map(a=>e.jsx("td",{children:a.financialExpenses.amount.formatted},a.year))]}),commentaryData:r.financialExpenses}),e.jsx(d,{dataRow:t=>e.jsxs("tr",{children:[e.jsx("td",{children:"Other Income"}),e.jsx("td",{children:r.otherIncome.amount.formatted}),e.jsx("th",{children:t}),s.map(a=>e.jsx("td",{children:a.otherIncome.amount.formatted},a.year))]}),commentaryData:r.otherIncome}),e.jsxs("tr",{children:[e.jsx("th",{children:"Profit Before Tax"}),e.jsx("th",{children:r.profitBeforeTax.formatted}),e.jsx("th",{}),s.map(t=>e.jsx("th",{children:t.profitBeforeTax.formatted},t.year))]}),e.jsxs("tr",{children:[e.jsx("td",{children:"Tax"}),e.jsx("td",{children:r.tax.formatted}),e.jsx("td",{}),s.map(t=>e.jsx("td",{children:t.tax.formatted},t.year))]})]}),e.jsx("tfoot",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Net Profit"}),e.jsx("th",{children:r.netProfit.formatted}),e.jsx("th",{}),s.map(t=>e.jsx("th",{children:t.netProfit.formatted},t.year))]})})]})})})};export{I as ProfitAndLossReport};
1
+ import{r as c,j as e,B as u,a as y,F as g,u as P,L as D,fW as w}from"./index-fZcP3X7C.js";import{d as R}from"./graphql-document-dedupe-fragments-ByT8-wlV.js";import{P as E}from"./page-layout-DUgx8eXl.js";import{R as d}from"./report-commentary-row-BonuPEAK.js";import{P as v}from"./modal-B_jJz-4Z.js";import{Y as p}from"./YearPickerInput-BdNLRDw_.js";import{F}from"./funnel-DP2XBopJ.js";import{T as C}from"./Table-Cr3nIx5M.js";import"./toggle-expansion-button-pWLCCDmM.js";import"./panel-top-open-CcWXXds7.js";function A({year:l,setYear:h,referenceYears:o,setReferenceYears:j}){const[m,x]=c.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsx(v,{opened:m,onClose:()=>x(!1),withCloseButton:!0,content:e.jsxs(e.Fragment,{children:[e.jsx(p,{label:"Change report year",value:new Date(l,0,1),onChange:n=>n&&h(n?.getFullYear()),popoverProps:{withinPortal:!0},minDate:new Date(2010,0,1),maxDate:new Date}),e.jsx(p,{type:"multiple",label:"Pick reference years",value:o?.map(n=>new Date(n,0,1)),onChange:n=>j(n.map(i=>i.getFullYear()).filter(i=>l!==i)),popoverProps:{withinPortal:!0},minDate:new Date(2010,0,1),maxDate:new Date})]})}),e.jsx(u,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>x(!0),children:e.jsx(F,{className:"size-5"})})]})}const I=()=>{const{year:l}=y(),{setFiltersContext:h}=c.useContext(g),[o,j]=c.useState(l?Number(l):new Date().getFullYear()),[m,x]=c.useState([]),[{data:n,fetching:i}]=P({query:R(w),variables:{reportYear:o,referenceYears:m}});c.useEffect(()=>{h(e.jsx("div",{className:"flex flex-row gap-2",children:e.jsx(A,{year:o,setYear:j,referenceYears:m,setReferenceYears:x})}))},[o,i,h,m,x]);const f=n?.profitAndLossReport,r=f?.report,s=f?.reference??[];return e.jsx(E,{title:"Profit and Loss Report",children:i?e.jsx(D,{className:"h-10 w-10 animate-spin mr-2 self-center"}):e.jsx("div",{className:"flex flex-col gap-4",children:r&&e.jsxs(C,{highlightOnHover:!0,fontSize:"md",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{}),e.jsx("th",{children:o},o),e.jsx("th",{}),s.map(t=>e.jsx("th",{children:t.year},t.year))]})}),e.jsxs("tbody",{children:[e.jsx(d,{dataRow:t=>e.jsxs("tr",{children:[e.jsx("th",{children:"Revenue"}),e.jsx("th",{children:r.revenue.amount.formatted}),e.jsx("th",{children:t}),s.map(a=>e.jsx("th",{children:a.revenue.amount.formatted},a.year))]}),commentaryData:r.revenue}),e.jsx(d,{dataRow:t=>e.jsxs("tr",{children:[e.jsx("td",{children:"Cost of Sales"}),e.jsx("td",{children:r.costOfSales.amount.formatted}),e.jsx("th",{children:t}),s.map(a=>e.jsx("td",{children:a.costOfSales.amount.formatted},a.year))]}),commentaryData:r.costOfSales}),e.jsxs("tr",{children:[e.jsx("th",{children:"Gross Profit"}),e.jsx("th",{children:r.grossProfit.formatted}),e.jsx("th",{}),s.map(t=>e.jsx("th",{children:t.grossProfit.formatted},t.year))]}),e.jsx(d,{dataRow:t=>e.jsxs("tr",{children:[e.jsx("td",{children:"R&D Expenses"}),e.jsx("td",{children:r.researchAndDevelopmentExpenses.amount.formatted}),e.jsx("th",{children:t}),s.map(a=>e.jsx("td",{children:a.researchAndDevelopmentExpenses.amount.formatted},a.year))]}),commentaryData:r.researchAndDevelopmentExpenses}),e.jsx(d,{dataRow:t=>e.jsxs("tr",{children:[e.jsx("td",{children:"Marketing Expenses"}),e.jsx("td",{children:r.marketingExpenses.amount.formatted}),e.jsx("th",{children:t}),s.map(a=>e.jsx("td",{children:a.marketingExpenses.amount.formatted},a.year))]}),commentaryData:r.marketingExpenses}),e.jsx(d,{dataRow:t=>e.jsxs("tr",{children:[e.jsx("td",{children:"Management and General Expenses"}),e.jsx("td",{children:r.managementAndGeneralExpenses.amount.formatted}),e.jsx("th",{children:t}),s.map(a=>e.jsx("td",{children:a.managementAndGeneralExpenses.amount.formatted},a.year))]}),commentaryData:r.managementAndGeneralExpenses}),e.jsxs("tr",{children:[e.jsx("th",{children:"Operating Profit"}),e.jsx("th",{children:r.operatingProfit.formatted}),e.jsx("th",{}),s.map(t=>e.jsx("th",{children:t.operatingProfit.formatted},t.year))]}),e.jsx(d,{dataRow:t=>e.jsxs("tr",{children:[e.jsx("td",{children:"Financial Expenses"}),e.jsx("td",{children:r.financialExpenses.amount.formatted}),e.jsx("th",{children:t}),s.map(a=>e.jsx("td",{children:a.financialExpenses.amount.formatted},a.year))]}),commentaryData:r.financialExpenses}),e.jsx(d,{dataRow:t=>e.jsxs("tr",{children:[e.jsx("td",{children:"Other Income"}),e.jsx("td",{children:r.otherIncome.amount.formatted}),e.jsx("th",{children:t}),s.map(a=>e.jsx("td",{children:a.otherIncome.amount.formatted},a.year))]}),commentaryData:r.otherIncome}),e.jsxs("tr",{children:[e.jsx("th",{children:"Profit Before Tax"}),e.jsx("th",{children:r.profitBeforeTax.formatted}),e.jsx("th",{}),s.map(t=>e.jsx("th",{children:t.profitBeforeTax.formatted},t.year))]}),e.jsxs("tr",{children:[e.jsx("td",{children:"Tax"}),e.jsx("td",{children:r.tax.formatted}),e.jsx("td",{}),s.map(t=>e.jsx("td",{children:t.tax.formatted},t.year))]})]}),e.jsx("tfoot",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Net Profit"}),e.jsx("th",{children:r.netProfit.formatted}),e.jsx("th",{}),s.map(t=>e.jsx("th",{children:t.netProfit.formatted},t.year))]})})]})})})};export{I as ProfitAndLossReport};
@@ -1,4 +1,4 @@
1
- import{v as G,r as d,j as e,J as p,B as g,dT as q,dU as H,dV as _,cw as F,dW as M,dX as Q,dY as J,dZ as $,d_ as Y,d$ as K,e0 as W,u as T,t as X,e1 as Z,T as ee,e2 as te,a8 as E,bo as se,G as ae,cQ as ne,br as A,bu as S,e3 as N,cK as re,x as D,bv as oe,F as ie,L as ce,e4 as le}from"./index-CcJvt1sI.js";import{d as R}from"./graphql-document-dedupe-fragments-ByT8-wlV.js";import{u as V}from"./use-url-query-D-GsTMWL.js";import{M as de}from"./index-kSig9eXf.js";import{E as he,I as me,M as xe}from"./match-document-modal-D2TgC0aR.js";import{P as ue}from"./page-layout-BNHKLJFL.js";import{C as I,u as pe,a as z,b as O}from"./charges-table-BOnvwci9.js";import{P as w,a as y}from"./panel-top-open-DQ1wo5PZ.js";import{T as k}from"./toggle-expansion-button-Bdpb_YfG.js";import{T as P}from"./Table-CR8S5Pp5.js";import{c as ge}from"./charges-filters-C7YlWAFn.js";import{P as je}from"./modal-DOtlViK5.js";import{F as fe}from"./funnel-IYKnhWOy.js";import"./Checkbox-w99PhJ6L.js";import"./YearPickerInput-dCiPlZqk.js";import"./list-plus-Cv8qnwZd.js";import"./insert-business-trip-modal-D08ePEzY.js";import"./accounter-table-CBigzB_s.js";import"./Pagination-BVQu3Yj6.js";import"./create-event-handler-BiA-1lGu.js";import"./index-ofME77ND.js";import"./similar-transactions-modal-DDVojjq0.js";import"./addDays-CjlJbHpj.js";import"./tooltip-Cy3vJ3fy.js";import"./summary-BV3HUEgI.js";import"./sub-CIKovQuv.js";import"./subMonths-GbNm9rnx.js";import"./MultiSelect-9BbcXHjB.js";/**
1
+ import{v as G,r as d,j as e,J as p,B as g,dT as q,dU as H,dV as _,cw as F,dW as M,dX as Q,dY as J,dZ as $,d_ as Y,d$ as K,e0 as W,u as T,t as X,e1 as Z,T as ee,e2 as te,a8 as E,bo as se,G as ae,cQ as ne,br as A,bu as S,e3 as N,cK as re,x as D,bv as oe,F as ie,L as ce,e4 as le}from"./index-fZcP3X7C.js";import{d as R}from"./graphql-document-dedupe-fragments-ByT8-wlV.js";import{u as V}from"./use-url-query-DyJg_rMw.js";import{M as de}from"./index-CeSVmmFv.js";import{E as he,I as me,M as xe}from"./match-document-modal-CpUhpMJc.js";import{P as ue}from"./page-layout-DUgx8eXl.js";import{C as I,u as pe,a as z,b as O}from"./charges-table-BIpECr1x.js";import{P as w,a as y}from"./panel-top-open-CcWXXds7.js";import{T as k}from"./toggle-expansion-button-pWLCCDmM.js";import{T as P}from"./Table-Cr3nIx5M.js";import{c as ge}from"./charges-filters-BSbPgdun.js";import{P as je}from"./modal-B_jJz-4Z.js";import{F as fe}from"./funnel-DP2XBopJ.js";import"./Checkbox-qIwbw1Vm.js";import"./YearPickerInput-BdNLRDw_.js";import"./list-plus-ZIHrrCaO.js";import"./insert-business-trip-modal-qIM7A1Dw.js";import"./accounter-table-R92v4QWf.js";import"./Pagination-D9TkQfLt.js";import"./create-event-handler-BiA-1lGu.js";import"./index-8gQaTQhF.js";import"./similar-transactions-modal-Cdv2FmQ8.js";import"./addDays-CHr5nY3e.js";import"./tooltip-r34BEIrK.js";import"./summary-yiqSbK4V.js";import"./sub-zRppNrG0.js";import"./subMonths-CLe-U48r.js";import"./MultiSelect-Uj0K1auE.js";/**
2
2
  * @license lucide-react v0.548.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1,2 +1,2 @@
1
- import{r as F,j as r,e as J,u as K,gX as Q,L as E,a8 as H,bo as X,B as U,G as $,bq as ee,br as te,bu as ne,cK as O,x as S,gY as T,bv as se,F as oe,K as re,P as ie,W as le}from"./index-CcJvt1sI.js";import{u as Y}from"./use-url-query-D-GsTMWL.js";import{P as ae}from"./page-layout-BNHKLJFL.js";import{A as ce,a as ue,c as fe,b as he}from"./accordion-QkFWsf0a.js";import{P as de}from"./modal-DOtlViK5.js";import{F as pe}from"./funnel-IYKnhWOy.js";var v={},z;function ye(){if(z)return v;z=1,Object.defineProperty(v,"__esModule",{value:!0}),v.calcSlices=v.applyPatch=v.calcPatch=v.lcs=v.diff=v.diff_core=void 0;function c(e,n){const{b:t,eq:s,stack_base:i}=e;let{i:l,N:o,j:h,M:a,Z:u,stack_top:x}=e;for(;;)switch(n){case 0:{e:for(;o>0&&a>0;){t.fill(0,0,2*u);const V=o-a,_=o+a,B=_&1,W=l+o-1,Z=h+a-1,q=(_+B)/2;let N;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 f=I;f<=L;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<a&&s(l+b,h+C);)b++,C++;if(t[f-u*Math.floor(f/u)]=b,B===1&&(N=V-f)>=1-M&&N<M&&b+t[u+N-u*Math.floor(N/u)]>=o)if(M>1||b!==w){i[x++]=l+b,i[x++]=o-b,i[x++]=h+C,i[x++]=a-C,o=w,a=k,u=2*(Math.min(o,a)+1);continue e}else break t}for(let f=I;f<=L;f+=2){const A=t[u+f-1-u*Math.floor((f-1)/u)],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<a&&s(W-b,Z-C);)b++,C++;if(t[u+f-u*Math.floor(f/u)]=b,B===0&&(N=V-f)>=-M&&N<=M&&b+t[N-u*Math.floor(N/u)]>=o)if(M>0||b!==w){i[x++]=l+o-w,i[x++]=w,i[x++]=h+a-k,i[x++]=k,o=o-b,a=a-C,u=2*(Math.min(o,a)+1);continue e}else break t}}if(o!==a){a>o?(l+=o,h+=o,a-=o,o=0):(l+=a,h+=a,o-=a,a=0);break}}if(o+a!==0)if(e.pxe===l||e.pye===h)e.pxe=l+o,e.pye=h+a;else{const 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=u,e.stack_top=x,1}}case 1:{if(x===0)return 2;a=i[--x],h=i[--x],o=i[--x],l=i[--x],u=2*(Math.min(o,a)+1),n=0}}}class m{constructor(n){this.state=n,this.c=0,this.result={value:null,done:!1}}[Symbol.iterator](){return this}next(){const{state:n,result:t}=this;if(this.c>1)return t.done=!0,t.value=void 0,t;const s=c(n,this.c);return this.c=s,s===1?(t.value=[n.oxs,n.oxe,n.oys,n.oye],t):n.pxs>=0?(t.value=[n.pxs,n.pxe,n.pys,n.pye],t):(t.done=!0,t.value=void 0,t)}}function D(e,n,t,s,i){const l=(Math.min(n,s)+1)*2,o=n+s,h=new(o<256?Uint8Array:o<65536?Uint16Array:Uint32Array)(2*l);return new m({i:e,N:n,j:t,M:s,Z:l,b:h,eq:i,pxs:-1,pxe:-1,pys:-1,pye:-1,oxs:-1,oxe:-1,oys:-1,oye:-1,stack_top:0,stack_base:[]})}v.diff_core=D;function d(e,n,t){let[s,i,l]=[0,e.length,n.length];if(typeof t=="function"){for(;s<i&&s<l&&t(s,s);)s++;if(s===i&&s===l)return[][Symbol.iterator]();for(;t(--i,--l)&&i>s&&l>s;);}else{for(;s<i&&s<l&&e[s]===n[s];)s++;if(s===i&&s===l)return[][Symbol.iterator]();for(;e[--i]===n[--l]&&i>s&&l>s;);t=(o,h)=>e[o]===n[h]}return D(s,i+1-s,s,l+1-s,t)}v.diff=d;class p{constructor(n,t){this.diff=n,this.N=t,this.i=0,this.j=0}[Symbol.iterator](){return this}next(){const n=this.diff.next();if(n.done){const{i:a,j:u,N:x}=this;return a<x&&(n.done=!1,n.value=[a,u,x-a],this.i=x),n}const t=n.value,s=t[0],i=t[1],l=t[3],{i:o,j:h}=this;return o!==s&&(t.length--,t[0]=o,t[1]=h,t[2]=s-o),this.i=i,this.j=l,n}}function y(e,n,t){return new p(d(e,n,t),e.length)}v.lcs=y;function*g(e,n,t){const s=ArrayBuffer.isView(e)?Uint8Array.prototype.subarray:e.slice;for(const i of d(e,n,t))i[2]=s.call(n,i[2],i[3]),yield i}v.calcPatch=g;function*P(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=P;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}),G=({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(""),P=Array.from(xe.calcPatch(g,y)),j=[];let e=0;for(const[t,s,i]of P)if(j.length===0&&t>=17&&s<=25&&i.length===s-t){if(P.length===1)return p;continue}else e<t&&j.push([g.slice(e,t).join(""),G]),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(""),G]);let n=[];for(const[t,s]of j){const i=t.split(`
1
+ import{r as F,j as r,e as J,u as K,gX as Q,L as E,a8 as H,bo as X,B as U,G as $,bq as ee,br as te,bu as ne,cK as O,x as S,gY as T,bv as se,F as oe,K as re,P as ie,W as le}from"./index-fZcP3X7C.js";import{u as Y}from"./use-url-query-DyJg_rMw.js";import{P as ae}from"./page-layout-DUgx8eXl.js";import{A as ce,a as ue,c as fe,b as he}from"./accordion-DwkOqBRF.js";import{P as de}from"./modal-B_jJz-4Z.js";import{F as pe}from"./funnel-DP2XBopJ.js";var v={},z;function ye(){if(z)return v;z=1,Object.defineProperty(v,"__esModule",{value:!0}),v.calcSlices=v.applyPatch=v.calcPatch=v.lcs=v.diff=v.diff_core=void 0;function c(e,n){const{b:t,eq:s,stack_base:i}=e;let{i:l,N:o,j:h,M:a,Z:u,stack_top:x}=e;for(;;)switch(n){case 0:{e:for(;o>0&&a>0;){t.fill(0,0,2*u);const V=o-a,_=o+a,B=_&1,W=l+o-1,Z=h+a-1,q=(_+B)/2;let N;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 f=I;f<=L;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<a&&s(l+b,h+C);)b++,C++;if(t[f-u*Math.floor(f/u)]=b,B===1&&(N=V-f)>=1-M&&N<M&&b+t[u+N-u*Math.floor(N/u)]>=o)if(M>1||b!==w){i[x++]=l+b,i[x++]=o-b,i[x++]=h+C,i[x++]=a-C,o=w,a=k,u=2*(Math.min(o,a)+1);continue e}else break t}for(let f=I;f<=L;f+=2){const A=t[u+f-1-u*Math.floor((f-1)/u)],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<a&&s(W-b,Z-C);)b++,C++;if(t[u+f-u*Math.floor(f/u)]=b,B===0&&(N=V-f)>=-M&&N<=M&&b+t[N-u*Math.floor(N/u)]>=o)if(M>0||b!==w){i[x++]=l+o-w,i[x++]=w,i[x++]=h+a-k,i[x++]=k,o=o-b,a=a-C,u=2*(Math.min(o,a)+1);continue e}else break t}}if(o!==a){a>o?(l+=o,h+=o,a-=o,o=0):(l+=a,h+=a,o-=a,a=0);break}}if(o+a!==0)if(e.pxe===l||e.pye===h)e.pxe=l+o,e.pye=h+a;else{const 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=u,e.stack_top=x,1}}case 1:{if(x===0)return 2;a=i[--x],h=i[--x],o=i[--x],l=i[--x],u=2*(Math.min(o,a)+1),n=0}}}class m{constructor(n){this.state=n,this.c=0,this.result={value:null,done:!1}}[Symbol.iterator](){return this}next(){const{state:n,result:t}=this;if(this.c>1)return t.done=!0,t.value=void 0,t;const s=c(n,this.c);return this.c=s,s===1?(t.value=[n.oxs,n.oxe,n.oys,n.oye],t):n.pxs>=0?(t.value=[n.pxs,n.pxe,n.pys,n.pye],t):(t.done=!0,t.value=void 0,t)}}function D(e,n,t,s,i){const l=(Math.min(n,s)+1)*2,o=n+s,h=new(o<256?Uint8Array:o<65536?Uint16Array:Uint32Array)(2*l);return new m({i:e,N:n,j:t,M:s,Z:l,b:h,eq:i,pxs:-1,pxe:-1,pys:-1,pye:-1,oxs:-1,oxe:-1,oys:-1,oye:-1,stack_top:0,stack_base:[]})}v.diff_core=D;function d(e,n,t){let[s,i,l]=[0,e.length,n.length];if(typeof t=="function"){for(;s<i&&s<l&&t(s,s);)s++;if(s===i&&s===l)return[][Symbol.iterator]();for(;t(--i,--l)&&i>s&&l>s;);}else{for(;s<i&&s<l&&e[s]===n[s];)s++;if(s===i&&s===l)return[][Symbol.iterator]();for(;e[--i]===n[--l]&&i>s&&l>s;);t=(o,h)=>e[o]===n[h]}return D(s,i+1-s,s,l+1-s,t)}v.diff=d;class p{constructor(n,t){this.diff=n,this.N=t,this.i=0,this.j=0}[Symbol.iterator](){return this}next(){const n=this.diff.next();if(n.done){const{i:a,j:u,N:x}=this;return a<x&&(n.done=!1,n.value=[a,u,x-a],this.i=x),n}const t=n.value,s=t[0],i=t[1],l=t[3],{i:o,j:h}=this;return o!==s&&(t.length--,t[0]=o,t[1]=h,t[2]=s-o),this.i=i,this.j=l,n}}function y(e,n,t){return new p(d(e,n,t),e.length)}v.lcs=y;function*g(e,n,t){const s=ArrayBuffer.isView(e)?Uint8Array.prototype.subarray:e.slice;for(const i of d(e,n,t))i[2]=s.call(n,i[2],i[3]),yield i}v.calcPatch=g;function*P(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=P;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}),G=({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(""),P=Array.from(xe.calcPatch(g,y)),j=[];let e=0;for(const[t,s,i]of P)if(j.length===0&&t>=17&&s<=25&&i.length===s-t){if(P.length===1)return p;continue}else e<t&&j.push([g.slice(e,t).join(""),G]),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(""),G]);let n=[];for(const[t,s]of j){const i=t.split(`
2
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(J,{className:"text-green-500"})]}),!!d.length&&d]})},Me=({filter:c})=>{const[{data:m,fetching:D,hasNext:d}]=K({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}=$({defaultValues:{...c}}),{selectableBusinesses:g,fetching:P}=ee(),j=e=>{m(e),D()};return r.jsxs(r.Fragment,{children:[P?r.jsx("div",{children:"Loading..."}):r.jsx("div",{}),r.jsxs("form",{onSubmit:p(j),children:[r.jsx(te,{name:"businessId",control:d,defaultValue:void 0,render:({field:e,fieldState:n})=>r.jsx(ne,{...e,data:g,value:e.value,disabled:P,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 P(j){j||={businessId:g?.context.adminBusinessId??c.businessId,fromMonthDate:S(T(new Date),"yyyy-MM-15"),toMonthDate:S(new Date,"yyyy-MM-15")},se(j,c)||m(j)}return F.useEffect(()=>{const j=X(c??{})?null:encodeURIComponent(JSON.stringify(c)),e=p("validateReportsFilters");j!==e&&y("validateReportsFilters",j)},[c,p,y]),r.jsxs(r.Fragment,{children:[r.jsx(de,{opened:D,onClose:()=>d(!1),content:r.jsx(be,{filter:c,setFilter:P,closeModal:()=>d(!1)})}),r.jsx(U,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>d(!0),children:r.jsx(pe,{className:"size-5"})})]})}const ke=()=>{const{get:c}=Y(),{setFiltersContext:m}=F.useContext(oe),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(ce,{type:"single",collapsible:!0,children:r.jsx(ue,{value:"pcn874",children:r.jsxs(re,{className:"p-4",children:[r.jsx(fe,{children:r.jsx(ie,{children:"Monthly VAT (PCN874)"})}),r.jsx(he,{children:r.jsx(le,{children:r.jsx(Me,{filter:d})})})]})})})})};export{ke as ValidateReportsScreen};