@accounter/client 0.0.8-alpha-20251029124401-d15137847e8450b1ecf3e3cfa6b68dda7239ca45 → 0.0.8-alpha-20251029124448-6b4f8bc975a23de63429b68d0806022dbfc5b226

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 (87) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/dist/assets/{Checkbox-Cxbop3qM.js → Checkbox-Ddw01d64.js} +1 -1
  3. package/dist/assets/{MultiSelect-D1XVjXLN.js → MultiSelect-CBtq6WUv.js} +1 -1
  4. package/dist/assets/{Pagination-DMimIHM4.js → Pagination-BM-86UO5.js} +1 -1
  5. package/dist/assets/{Progress-CP4jnh2x.js → Progress-Bda-J3ZH.js} +1 -1
  6. package/dist/assets/{Table-DTU12O53.js → Table-CYqAEQfS.js} +1 -1
  7. package/dist/assets/{Typography-IL0wuZeq.js → Typography--U0GsZ21.js} +1 -1
  8. package/dist/assets/{YearPickerInput-CPL_XozD.js → YearPickerInput-CgU-feeq.js} +1 -1
  9. package/dist/assets/{accordion-DKLV9b0H.js → accordion-B8kebokE.js} +1 -1
  10. package/dist/assets/{accountant-approvals-CdX2nUgB.js → accountant-approvals-CUluc3sH.js} +1 -1
  11. package/dist/assets/{accounter-table-CeZ4q0re.js → accounter-table-CM6PQ9Aw.js} +1 -1
  12. package/dist/assets/{addDays-sGeEkIxC.js → addDays-DGlDD_vj.js} +1 -1
  13. package/dist/assets/{all-charges-BJvp1ecZ.js → all-charges-DpQS6Xp3.js} +1 -1
  14. package/dist/assets/{arrow-up-down-DkEXGAin.js → arrow-up-down-C61ge4J5.js} +1 -1
  15. package/dist/assets/{building-2-BcYhLAVP.js → building-2-3KauBrnS.js} +1 -1
  16. package/dist/assets/{business-CO7M6XNI.js → business-RCuQN-RO.js} +1 -1
  17. package/dist/assets/{business-extended-info-MUfOmQ_B.js → business-extended-info-DmQ7B7-Z.js} +1 -1
  18. package/dist/assets/{business-header-BG2B-PcM.js → business-header-B-uHcc1D.js} +1 -1
  19. package/dist/assets/{business-transactions-filters-Cijy7ryl.js → business-transactions-filters-D-Y8vZwZ.js} +1 -1
  20. package/dist/assets/{business-transactions-single-DZqMwNkv.js → business-transactions-single-CEE249QN.js} +1 -1
  21. package/dist/assets/{business-trip-C7G814AY.js → business-trip-3kCBQ5MD.js} +1 -1
  22. package/dist/assets/{charge-Bm0hPNT7.js → charge-D19rkm2C.js} +1 -1
  23. package/dist/assets/{charges-filters-DjnsiGzC.js → charges-filters-BUFmsiTq.js} +1 -1
  24. package/dist/assets/{charges-ledger-validation-CoHDjCf2.js → charges-ledger-validation-OPtbHzXu.js} +1 -1
  25. package/dist/assets/{charges-table-C_4dY1Ic.js → charges-table-D_GDHvFS.js} +1 -1
  26. package/dist/assets/{chart-SbwWAyei.js → chart-iyOBgiH0.js} +1 -1
  27. package/dist/assets/{data-table-pagination-DtnUvTOC.js → data-table-pagination-CKN0E29f.js} +1 -1
  28. package/dist/assets/{download-csv-button-D9_6J2pA.js → download-csv-button-DZ5cKqkV.js} +1 -1
  29. package/dist/assets/{editable-business-trip-xFRu5fSA.js → editable-business-trip-CRiuNdbP.js} +1 -1
  30. package/dist/assets/{funnel-WdA7f2As.js → funnel-BlaCusqP.js} +1 -1
  31. package/dist/assets/{index-DPvrbbz9.js → index-B2_EbsaK.js} +191 -191
  32. package/dist/assets/{index-D3-tv-Kb.js → index-B8pzYiEH.js} +1 -1
  33. package/dist/assets/{index-9JObwNSb.js → index-BAGVbiiM.js} +1 -1
  34. package/dist/assets/{index-VzPCd0L-.js → index-BD86tRnn.js} +1 -1
  35. package/dist/assets/{index-BIdEjDD3.js → index-BGh0NOfw.js} +1 -1
  36. package/dist/assets/{index-BaEmw40f.js → index-BKiLhEyi.js} +1 -1
  37. package/dist/assets/{index-Ct0AJEN9.js → index-BNAjS3Tn.js} +1 -1
  38. package/dist/assets/{index-CwbqTlM4.js → index-BRSlJnxd.js} +1 -1
  39. package/dist/assets/{index-DjQIiDMo.js → index-BoL57v1D.js} +1 -1
  40. package/dist/assets/{index-Ey6XKYuP.js → index-C2GP2DWO.js} +1 -1
  41. package/dist/assets/{index-Vq1FAgYe.js → index-CM60VmgR.js} +1 -1
  42. package/dist/assets/index-CRLPoT61.js +6 -0
  43. package/dist/assets/{index-Bx-qi8fd.js → index-CRooGu6R.js} +1 -1
  44. package/dist/assets/{index--LMZMPY_.js → index-C_OSDuUb.js} +1 -1
  45. package/dist/assets/{index-Bm3ZL2dx.js → index-Cc7exUI5.js} +1 -1
  46. package/dist/assets/{index-Bw5hpWBz.js → index-Co66MgF6.js} +1 -1
  47. package/dist/assets/{index-1loWF1jV.js → index-CyBAoT0l.js} +1 -1
  48. package/dist/assets/{index-mN2sZqiu.js → index-D5tmtR-a.js} +1 -1
  49. package/dist/assets/{index-CfsTscFv.js → index-DINxWoMX.js} +1 -1
  50. package/dist/assets/{index-W6Xv87pg.js → index-DIiuo0-v.js} +1 -1
  51. package/dist/assets/index-DWXHJxFq.css +1 -0
  52. package/dist/assets/{index-BOhdfO95.js → index-DtrRL2jA.js} +1 -1
  53. package/dist/assets/{index-CXH_lcpK.js → index-EaY6ZYvr.js} +1 -1
  54. package/dist/assets/{index-p1BcqxXQ.js → index-mMqWkzUL.js} +1 -1
  55. package/dist/assets/{index-CdAUtS2Q.js → index-xLWv_qf6.js} +1 -1
  56. package/dist/assets/{index-BxnmQCT9.js → index-yOhbO3fy.js} +1 -1
  57. package/dist/assets/{index.es-C3XngPKv.js → index.es-CaOIcY7v.js} +1 -1
  58. package/dist/assets/{insert-business-trip-modal-BHY3QQup.js → insert-business-trip-modal-BwOnvw7X.js} +1 -1
  59. package/dist/assets/issue-document-CzBtBCCO.js +1 -0
  60. package/dist/assets/{list-plus-ZvPwjqZn.js → list-plus-CGvSlslE.js} +1 -1
  61. package/dist/assets/{login-page-CsXdm3AZ.js → login-page-BTcklqv4.js} +1 -1
  62. package/dist/assets/{match-document-modal-Cqimg0VE.js → match-document-modal-DcL0siQq.js} +1 -1
  63. package/dist/assets/{missing-info-charges-DxLGt6Xs.js → missing-info-charges-DfwRkzNe.js} +1 -1
  64. package/dist/assets/{modal-Nvfe-DMu.js → modal-B0uNLang.js} +1 -1
  65. package/dist/assets/{page-layout-SHFb6rY4.js → page-layout-C0GJoVTR.js} +1 -1
  66. package/dist/assets/{page-not-found-BZ6s-Q5n.js → page-not-found-9UX5vsGE.js} +1 -1
  67. package/dist/assets/{panel-top-open-C3Q9X7Tg.js → panel-top-open-BFNhAe3f.js} +1 -1
  68. package/dist/assets/{pencil-CPPx1BhC.js → pencil-9Th5X-OY.js} +1 -1
  69. package/dist/assets/{report-commentary-row-DpYgprQr.js → report-commentary-row-CNIlhboC.js} +1 -1
  70. package/dist/assets/{save-D-W46u2J.js → save-qtyyZLc5.js} +1 -1
  71. package/dist/assets/{similar-transactions-modal-zQY2R-sr.js → similar-transactions-modal-nk8VHEtX.js} +1 -1
  72. package/dist/assets/{sub-7frHBT3Y.js → sub-fkVv9ghZ.js} +1 -1
  73. package/dist/assets/subMonths-5wFmciT1.js +1 -0
  74. package/dist/assets/{summary-DwX_dmjr.js → summary-DuWhfNdL.js} +1 -1
  75. package/dist/assets/{toggle-expansion-button-Bh24n-cz.js → toggle-expansion-button-41Ejffq3.js} +1 -1
  76. package/dist/assets/tooltip-lhMCop8U.js +1 -0
  77. package/dist/assets/{use-url-query-COmN7DHP.js → use-url-query-BPzyQB93.js} +1 -1
  78. package/dist/index.html +2 -2
  79. package/package.json +1 -1
  80. package/src/providers/index.ts +4 -0
  81. package/dist/assets/index-BUJm5I0K.css +0 -1
  82. package/dist/assets/index-DFgRsYAU.js +0 -6
  83. package/dist/assets/issue-document-BpzcqnRu.js +0 -1
  84. package/dist/assets/subMonths-CY79vHaS.js +0 -1
  85. package/dist/assets/tooltip-BaULIFLC.js +0 -1
  86. package/src/components/ui/pagination.tsx +0 -194
  87. package/src/providers/index.tsx +0 -56
@@ -1 +1 @@
1
- import{r as l,F as C,u as S,j as e,T as h,B as j,bj as m,aN as a,L as T,bk as y,bl as N}from"./index-DPvrbbz9.js";import{u as v}from"./use-url-query-COmN7DHP.js";import{A as E}from"./accounter-table-CeZ4q0re.js";import{P as F}from"./page-layout-SHFb6rY4.js";import{C as B,a as R,B as z,M as I}from"./business-extended-info-MUfOmQ_B.js";import{B as L}from"./business-transactions-filters-Cijy7ryl.js";import{P as k,a as A}from"./panel-top-open-C3Q9X7Tg.js";import{T as O}from"./Table-DTU12O53.js";import"./Pagination-DMimIHM4.js";import"./create-event-handler-BiA-1lGu.js";import"./download-csv-button-D9_6J2pA.js";import"./modal-Nvfe-DMu.js";import"./funnel-WdA7f2As.js";import"./MultiSelect-D1XVjXLN.js";const Y=()=>{const{get:t}=v(),{setFiltersContext:i}=l.useContext(C),[r,o]=l.useState(!1),[p,w]=l.useState(!1),[d,x]=l.useState(t("transactionsFilters")?JSON.parse(decodeURIComponent(t("transactionsFilters"))):{}),[{data:c,fetching:b}]=S({query:y,variables:{filters:d}});l.useEffect(()=>{i(e.jsxs("div",{className:"flex flex-row gap-x-5",children:[e.jsx(L,{filter:d,setFilter:x}),e.jsx(h,{label:"Expand all accounts",children:e.jsx(j,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>o(s=>!s),children:r?e.jsx(k,{className:"size-5"}):e.jsx(A,{className:"size-5"})})}),e.jsx(h,{label:"Expand all currencies",children:e.jsx(j,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>w(s=>!s),children:p?e.jsx(B,{className:"size-5"}):e.jsx(R,{className:"size-5"})})})]}))},[c,d,i,x,r,o,p]);const g=l.useMemo(()=>c?.businessTransactionsSumFromLedgerRecords.__typename==="CommonError"?[]:c?.businessTransactionsSumFromLedgerRecords.businessTransactionsSum?c.businessTransactionsSumFromLedgerRecords.businessTransactionsSum.sort((s,u)=>s.business.name.localeCompare(u.business.name)):[],[c?.businessTransactionsSumFromLedgerRecords]),f=[{title:"Business Name",value:s=>s.business.name},{title:"Debit / Credit",value:s=>e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("p",{className:"flex flex-row gap-2 whitespace-nowrap",children:e.jsx(m,{c:"red",children:s.debit.formatted})}),e.jsx("p",{className:"flex flex-row gap-2 whitespace-nowrap",children:e.jsx(m,{c:"green",children:s.credit.formatted})})]}),style:{whiteSpace:"nowrap"}},{title:"Total",value:s=>e.jsx(m,{c:s.total.raw<-1e-4?"red":s.total.raw>1e-4?"green":void 0,fw:700,children:s.total.formatted}),style:{whiteSpace:"nowrap"}},...n(a.Eur),...n(a.Usd),...n(a.Gbp),...n(a.Cad),...n(a.Jpy),...n(a.Aud),...n(a.Sek),...P(p)];return e.jsx(F,{title:"Business Transactions",description:"Business Transactions Summery",children:b?e.jsx(T,{className:"h-10 w-10 animate-spin mr-2 self-center"}):e.jsxs(O,{striped:!0,highlightOnHover:!0,children:[e.jsx("thead",{className:"sticky top-0 z-20",children:e.jsxs("tr",{className:"tracking-wider font-medium text-gray-900 text-sm bg-gray-100",children:[f.map((s,u)=>s.disabled?null:e.jsx("th",{children:s.title},String(u))),e.jsx("th",{children:"More Info"})]})}),e.jsx("tbody",{children:g.map((s,u)=>e.jsx(E,{columns:f,item:s,moreInfo:()=>e.jsx(z,{businessID:s.business.id,filter:d}),isShowAll:r},u))})]})})};function n(t){return[{title:`${t} Debit / Credit`,value:i=>{const r=i.foreignCurrenciesSum.find(o=>o.currency===t);return r?e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("p",{className:"flex flex-row gap-2 whitespace-nowrap",children:e.jsx(m,{c:"red",children:r.debit.formatted})}),e.jsx("p",{className:"flex flex-row gap-2 whitespace-nowrap",children:e.jsx(m,{c:"green",children:r.credit.formatted})})]}):null},style:{whiteSpace:"nowrap"}},{title:`${t} Total`,value:i=>{const r=i.foreignCurrenciesSum.find(o=>o.currency===t);return r?.total?.raw&&(r.total.raw<-1e-4||r.total.raw>1e-4)?e.jsx(I,{color:r.total.raw>0?"green":"red",children:r.total.formatted}):r?.total?.formatted},style:{whiteSpace:"nowrap"}}]}function P(t){return t?Object.values(a).filter(r=>!N.includes(r)).map(n).flat():[]}export{Y as BusinessTransactionsSummery};
1
+ import{r as l,F as C,u as S,j as e,T as h,B as j,bj as m,aN as a,L as T,bk as y,bl as N}from"./index-B2_EbsaK.js";import{u as v}from"./use-url-query-BPzyQB93.js";import{A as E}from"./accounter-table-CM6PQ9Aw.js";import{P as F}from"./page-layout-C0GJoVTR.js";import{C as B,a as R,B as z,M as I}from"./business-extended-info-DmQ7B7-Z.js";import{B as L}from"./business-transactions-filters-D-Y8vZwZ.js";import{P as k,a as A}from"./panel-top-open-BFNhAe3f.js";import{T as O}from"./Table-CYqAEQfS.js";import"./Pagination-BM-86UO5.js";import"./create-event-handler-BiA-1lGu.js";import"./download-csv-button-DZ5cKqkV.js";import"./modal-B0uNLang.js";import"./funnel-BlaCusqP.js";import"./MultiSelect-CBtq6WUv.js";const Y=()=>{const{get:t}=v(),{setFiltersContext:i}=l.useContext(C),[r,o]=l.useState(!1),[p,w]=l.useState(!1),[d,x]=l.useState(t("transactionsFilters")?JSON.parse(decodeURIComponent(t("transactionsFilters"))):{}),[{data:c,fetching:b}]=S({query:y,variables:{filters:d}});l.useEffect(()=>{i(e.jsxs("div",{className:"flex flex-row gap-x-5",children:[e.jsx(L,{filter:d,setFilter:x}),e.jsx(h,{label:"Expand all accounts",children:e.jsx(j,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>o(s=>!s),children:r?e.jsx(k,{className:"size-5"}):e.jsx(A,{className:"size-5"})})}),e.jsx(h,{label:"Expand all currencies",children:e.jsx(j,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>w(s=>!s),children:p?e.jsx(B,{className:"size-5"}):e.jsx(R,{className:"size-5"})})})]}))},[c,d,i,x,r,o,p]);const g=l.useMemo(()=>c?.businessTransactionsSumFromLedgerRecords.__typename==="CommonError"?[]:c?.businessTransactionsSumFromLedgerRecords.businessTransactionsSum?c.businessTransactionsSumFromLedgerRecords.businessTransactionsSum.sort((s,u)=>s.business.name.localeCompare(u.business.name)):[],[c?.businessTransactionsSumFromLedgerRecords]),f=[{title:"Business Name",value:s=>s.business.name},{title:"Debit / Credit",value:s=>e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("p",{className:"flex flex-row gap-2 whitespace-nowrap",children:e.jsx(m,{c:"red",children:s.debit.formatted})}),e.jsx("p",{className:"flex flex-row gap-2 whitespace-nowrap",children:e.jsx(m,{c:"green",children:s.credit.formatted})})]}),style:{whiteSpace:"nowrap"}},{title:"Total",value:s=>e.jsx(m,{c:s.total.raw<-1e-4?"red":s.total.raw>1e-4?"green":void 0,fw:700,children:s.total.formatted}),style:{whiteSpace:"nowrap"}},...n(a.Eur),...n(a.Usd),...n(a.Gbp),...n(a.Cad),...n(a.Jpy),...n(a.Aud),...n(a.Sek),...P(p)];return e.jsx(F,{title:"Business Transactions",description:"Business Transactions Summery",children:b?e.jsx(T,{className:"h-10 w-10 animate-spin mr-2 self-center"}):e.jsxs(O,{striped:!0,highlightOnHover:!0,children:[e.jsx("thead",{className:"sticky top-0 z-20",children:e.jsxs("tr",{className:"tracking-wider font-medium text-gray-900 text-sm bg-gray-100",children:[f.map((s,u)=>s.disabled?null:e.jsx("th",{children:s.title},String(u))),e.jsx("th",{children:"More Info"})]})}),e.jsx("tbody",{children:g.map((s,u)=>e.jsx(E,{columns:f,item:s,moreInfo:()=>e.jsx(z,{businessID:s.business.id,filter:d}),isShowAll:r},u))})]})})};function n(t){return[{title:`${t} Debit / Credit`,value:i=>{const r=i.foreignCurrenciesSum.find(o=>o.currency===t);return r?e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("p",{className:"flex flex-row gap-2 whitespace-nowrap",children:e.jsx(m,{c:"red",children:r.debit.formatted})}),e.jsx("p",{className:"flex flex-row gap-2 whitespace-nowrap",children:e.jsx(m,{c:"green",children:r.credit.formatted})})]}):null},style:{whiteSpace:"nowrap"}},{title:`${t} Total`,value:i=>{const r=i.foreignCurrenciesSum.find(o=>o.currency===t);return r?.total?.raw&&(r.total.raw<-1e-4||r.total.raw>1e-4)?e.jsx(I,{color:r.total.raw>0?"green":"red",children:r.total.formatted}):r?.total?.formatted},style:{whiteSpace:"nowrap"}}]}function P(t){return t?Object.values(a).filter(r=>!N.includes(r)).map(n).flat():[]}export{Y as BusinessTransactionsSummery};
@@ -1 +1 @@
1
- import{j as n,r as x,B as g,J as h,ge as j,a as v,F as D,u as R,L as E,bn as y,dE as T,T as u,gf as w}from"./index-DPvrbbz9.js";import{d as C}from"./graphql-document-dedupe-fragments-ByT8-wlV.js";import{P as A}from"./page-layout-SHFb6rY4.js";import{P as b}from"./modal-Nvfe-DMu.js";import{Y as F}from"./YearPickerInput-CPL_XozD.js";import{F as I}from"./funnel-WdA7f2As.js";import{T as N}from"./Table-DTU12O53.js";const i=({originalAmount:a,diffAmount:t})=>!t||a===t?n.jsx("td",{children:a}):n.jsx("td",{children:n.jsxs("div",{className:"flex flex-col",children:[n.jsx("p",{className:t?"line-through":"",children:a}),t&&n.jsx("div",{className:"border-2 border-yellow-500 rounded-md",children:t})]})});function P({years:a,setYears:t}){const[r,l]=x.useState(!1);return n.jsxs(n.Fragment,{children:[n.jsx(b,{opened:r,onClose:()=>l(!1),withCloseButton:!0,content:n.jsx(F,{type:"multiple",label:"Pick years",value:a?.map(d=>new Date(d,0,1)),onChange:d=>t(d.map(p=>p.getFullYear())),popoverProps:{withinPortal:!0},minDate:new Date(2010,0,1),maxDate:new Date})}),n.jsx(g,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>l(!0),children:n.jsx(I,{className:"size-5"})})]})}const f=({originalRuleData:a,diffRuleData:t})=>{const r=h(j,a),l=h(j,t),d=l?.isCompliant!==r.isCompliant||l?.percentage.formatted!==r.percentage.formatted;return!l||!d?n.jsx("td",{className:r.isCompliant?"text-green-500":"text-red-500",children:r.percentage.formatted}):n.jsx("td",{className:r.isCompliant?"text-green-500":"text-red-500",children:n.jsxs("div",{className:"flex flex-col",children:[n.jsx("p",{className:"line-through ".concat(r.isCompliant?"text-green-500":"text-red-500"),children:r.percentage.formatted}),l&&n.jsx("div",{className:"border-2 border-yellow-500 rounded-md ".concat(l.isCompliant?"text-green-500":"text-red-500"),children:l.percentage.formatted})]})})},c=(a,t)=>T(t).format(a);function m(a,t){if(a.length!==0)return c(a.reduce((r,l)=>r+l,0),t)}const U=()=>{const{year:a}=v(),{setFiltersContext:t}=x.useContext(D),[r,l]=x.useState(a?[Number(a)]:[new Date().getFullYear()]),[{data:d,fetching:p}]=R({query:C(w),variables:{years:r}});x.useEffect(()=>{t(n.jsx("div",{className:"flex flex-row gap-2",children:n.jsx(P,{years:r,setYears:l})}))},[r,p,t]);const s=d?.corporateTaxRulingComplianceReport??[];return n.jsx(A,{title:"Corporate Tax Ruling Compliance Report",children:p?n.jsx(E,{className:"h-10 w-10 animate-spin mr-2 self-center"}):n.jsx("div",{className:"flex flex-col gap-4",children:s&&n.jsxs(N,{highlightOnHover:!0,fontSize:"md",children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{}),r.map(e=>n.jsx("th",{children:n.jsx(y,{inline:!0,size:12,processing:!s.find(o=>o.year===e)?.differences,disabled:!!s.find(o=>o.year===e)?.differences,color:"orange",zIndex:"auto",children:e})},e)),n.jsx("th",{children:"Summary"},"sum")]})}),n.jsxs("tbody",{children:[n.jsxs("tr",{children:[n.jsx("td",{children:"Total Income"}),s.map(e=>n.jsx(i,{originalAmount:e.totalIncome.formatted,diffAmount:e.differences?.totalIncome?.formatted??void 0},e.year)),n.jsx(i,{originalAmount:c(s.map(e=>e.totalIncome.raw).reduce((e,o)=>e+o,0),s[0].totalIncome.currency),diffAmount:m(s.map(e=>e.differences?.totalIncome?.raw??e.totalIncome.raw).filter(e=>!!e),s[0].totalIncome.currency)},"sum")]}),n.jsxs("tr",{children:[n.jsx("td",{children:"Total R&D Expensess"}),s.map(e=>n.jsx(i,{originalAmount:e.researchAndDevelopmentExpenses.formatted,diffAmount:e.differences?.researchAndDevelopmentExpenses?.formatted??void 0},e.year)),n.jsx(i,{originalAmount:c(s.map(e=>e.researchAndDevelopmentExpenses.raw).reduce((e,o)=>e+o,0),s[0].researchAndDevelopmentExpenses.currency),diffAmount:m(s.map(e=>e.differences?.researchAndDevelopmentExpenses?.raw??e.researchAndDevelopmentExpenses.raw).filter(e=>!!e),s[0].researchAndDevelopmentExpenses.currency)},"sum")]}),n.jsxs("tr",{children:[n.jsx("th",{children:n.jsx(u,{multiline:!0,width:220,transitionProps:{duration:200},label:s[0]?.rndRelativeToIncome.rule,children:n.jsx("p",{children:"R&D Expenses out of Income"})})}),s.map(e=>n.jsx(f,{originalRuleData:e.rndRelativeToIncome,diffRuleData:e.differences?.rndRelativeToIncome??void 0},e.year)),n.jsx("td",{})]}),n.jsxs("tr",{children:[n.jsx("td",{children:"Local Development Expenses"}),s.map(e=>n.jsx(i,{originalAmount:e.localDevelopmentExpenses.formatted,diffAmount:e.differences?.localDevelopmentExpenses?.formatted??void 0},e.year)),n.jsx(i,{originalAmount:c(s.map(e=>e.localDevelopmentExpenses.raw).reduce((e,o)=>e+o,0),s[0].localDevelopmentExpenses.currency),diffAmount:m(s.map(e=>e.differences?.localDevelopmentExpenses?.raw??e.localDevelopmentExpenses.raw).filter(e=>!!e),s[0].localDevelopmentExpenses.currency)},"sum")]}),n.jsxs("tr",{children:[n.jsx("th",{children:n.jsx(u,{multiline:!0,width:220,transitionProps:{duration:200},label:s[0]?.localDevelopmentRelativeToRnd.rule,children:n.jsx("p",{children:"Local Development out of R&D"})})}),s.map(e=>n.jsx(f,{originalRuleData:e.localDevelopmentRelativeToRnd,diffRuleData:e.differences?.localDevelopmentRelativeToRnd??void 0},e.year)),n.jsx("td",{})]}),n.jsxs("tr",{children:[n.jsx("td",{children:"Foreign Development Expenses"}),s.map(e=>n.jsx(i,{originalAmount:e.foreignDevelopmentExpenses.formatted,diffAmount:e.differences?.foreignDevelopmentExpenses?.formatted??void 0},e.year)),n.jsx(i,{originalAmount:c(s.map(e=>e.foreignDevelopmentExpenses.raw).reduce((e,o)=>e+o,0),s[0].foreignDevelopmentExpenses.currency),diffAmount:m(s.map(e=>e.differences?.foreignDevelopmentExpenses?.raw??e.foreignDevelopmentExpenses.raw).filter(e=>!!e),s[0].foreignDevelopmentExpenses.currency)},"sum")]}),n.jsxs("tr",{children:[n.jsx("th",{children:n.jsx(u,{multiline:!0,width:220,transitionProps:{duration:200},label:s[0]?.foreignDevelopmentRelativeToRnd.rule,children:n.jsx("p",{children:"Foreign Development out of R&D"})})}),s.map(e=>n.jsx(f,{originalRuleData:e.foreignDevelopmentRelativeToRnd,diffRuleData:e.differences?.foreignDevelopmentRelativeToRnd??void 0},e.year)),n.jsx("td",{})]}),n.jsxs("tr",{children:[n.jsx("td",{children:"R&D Business Trips Expenses"}),s.map(e=>n.jsx(i,{originalAmount:e.businessTripRndExpenses.formatted,diffAmount:e.differences?.businessTripRndExpenses?.formatted??void 0},e.year)),n.jsx(i,{originalAmount:c(s.map(e=>e.businessTripRndExpenses.raw).reduce((e,o)=>e+o,0),s[0].businessTripRndExpenses.currency),diffAmount:m(s.map(e=>e.differences?.businessTripRndExpenses?.raw??e.businessTripRndExpenses.raw).filter(e=>!!e),s[0].businessTripRndExpenses.currency)},"sum")]})]})]})})})};export{U as CorporateTaxRulingComplianceReport};
1
+ import{j as n,r as x,B as g,J as h,ge as j,a as v,F as D,u as R,L as E,bn as y,dE as T,T as u,gf as w}from"./index-B2_EbsaK.js";import{d as C}from"./graphql-document-dedupe-fragments-ByT8-wlV.js";import{P as A}from"./page-layout-C0GJoVTR.js";import{P as b}from"./modal-B0uNLang.js";import{Y as F}from"./YearPickerInput-CgU-feeq.js";import{F as I}from"./funnel-BlaCusqP.js";import{T as N}from"./Table-CYqAEQfS.js";const i=({originalAmount:a,diffAmount:t})=>!t||a===t?n.jsx("td",{children:a}):n.jsx("td",{children:n.jsxs("div",{className:"flex flex-col",children:[n.jsx("p",{className:t?"line-through":"",children:a}),t&&n.jsx("div",{className:"border-2 border-yellow-500 rounded-md",children:t})]})});function P({years:a,setYears:t}){const[r,l]=x.useState(!1);return n.jsxs(n.Fragment,{children:[n.jsx(b,{opened:r,onClose:()=>l(!1),withCloseButton:!0,content:n.jsx(F,{type:"multiple",label:"Pick years",value:a?.map(d=>new Date(d,0,1)),onChange:d=>t(d.map(p=>p.getFullYear())),popoverProps:{withinPortal:!0},minDate:new Date(2010,0,1),maxDate:new Date})}),n.jsx(g,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>l(!0),children:n.jsx(I,{className:"size-5"})})]})}const f=({originalRuleData:a,diffRuleData:t})=>{const r=h(j,a),l=h(j,t),d=l?.isCompliant!==r.isCompliant||l?.percentage.formatted!==r.percentage.formatted;return!l||!d?n.jsx("td",{className:r.isCompliant?"text-green-500":"text-red-500",children:r.percentage.formatted}):n.jsx("td",{className:r.isCompliant?"text-green-500":"text-red-500",children:n.jsxs("div",{className:"flex flex-col",children:[n.jsx("p",{className:"line-through ".concat(r.isCompliant?"text-green-500":"text-red-500"),children:r.percentage.formatted}),l&&n.jsx("div",{className:"border-2 border-yellow-500 rounded-md ".concat(l.isCompliant?"text-green-500":"text-red-500"),children:l.percentage.formatted})]})})},c=(a,t)=>T(t).format(a);function m(a,t){if(a.length!==0)return c(a.reduce((r,l)=>r+l,0),t)}const U=()=>{const{year:a}=v(),{setFiltersContext:t}=x.useContext(D),[r,l]=x.useState(a?[Number(a)]:[new Date().getFullYear()]),[{data:d,fetching:p}]=R({query:C(w),variables:{years:r}});x.useEffect(()=>{t(n.jsx("div",{className:"flex flex-row gap-2",children:n.jsx(P,{years:r,setYears:l})}))},[r,p,t]);const s=d?.corporateTaxRulingComplianceReport??[];return n.jsx(A,{title:"Corporate Tax Ruling Compliance Report",children:p?n.jsx(E,{className:"h-10 w-10 animate-spin mr-2 self-center"}):n.jsx("div",{className:"flex flex-col gap-4",children:s&&n.jsxs(N,{highlightOnHover:!0,fontSize:"md",children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{}),r.map(e=>n.jsx("th",{children:n.jsx(y,{inline:!0,size:12,processing:!s.find(o=>o.year===e)?.differences,disabled:!!s.find(o=>o.year===e)?.differences,color:"orange",zIndex:"auto",children:e})},e)),n.jsx("th",{children:"Summary"},"sum")]})}),n.jsxs("tbody",{children:[n.jsxs("tr",{children:[n.jsx("td",{children:"Total Income"}),s.map(e=>n.jsx(i,{originalAmount:e.totalIncome.formatted,diffAmount:e.differences?.totalIncome?.formatted??void 0},e.year)),n.jsx(i,{originalAmount:c(s.map(e=>e.totalIncome.raw).reduce((e,o)=>e+o,0),s[0].totalIncome.currency),diffAmount:m(s.map(e=>e.differences?.totalIncome?.raw??e.totalIncome.raw).filter(e=>!!e),s[0].totalIncome.currency)},"sum")]}),n.jsxs("tr",{children:[n.jsx("td",{children:"Total R&D Expensess"}),s.map(e=>n.jsx(i,{originalAmount:e.researchAndDevelopmentExpenses.formatted,diffAmount:e.differences?.researchAndDevelopmentExpenses?.formatted??void 0},e.year)),n.jsx(i,{originalAmount:c(s.map(e=>e.researchAndDevelopmentExpenses.raw).reduce((e,o)=>e+o,0),s[0].researchAndDevelopmentExpenses.currency),diffAmount:m(s.map(e=>e.differences?.researchAndDevelopmentExpenses?.raw??e.researchAndDevelopmentExpenses.raw).filter(e=>!!e),s[0].researchAndDevelopmentExpenses.currency)},"sum")]}),n.jsxs("tr",{children:[n.jsx("th",{children:n.jsx(u,{multiline:!0,width:220,transitionProps:{duration:200},label:s[0]?.rndRelativeToIncome.rule,children:n.jsx("p",{children:"R&D Expenses out of Income"})})}),s.map(e=>n.jsx(f,{originalRuleData:e.rndRelativeToIncome,diffRuleData:e.differences?.rndRelativeToIncome??void 0},e.year)),n.jsx("td",{})]}),n.jsxs("tr",{children:[n.jsx("td",{children:"Local Development Expenses"}),s.map(e=>n.jsx(i,{originalAmount:e.localDevelopmentExpenses.formatted,diffAmount:e.differences?.localDevelopmentExpenses?.formatted??void 0},e.year)),n.jsx(i,{originalAmount:c(s.map(e=>e.localDevelopmentExpenses.raw).reduce((e,o)=>e+o,0),s[0].localDevelopmentExpenses.currency),diffAmount:m(s.map(e=>e.differences?.localDevelopmentExpenses?.raw??e.localDevelopmentExpenses.raw).filter(e=>!!e),s[0].localDevelopmentExpenses.currency)},"sum")]}),n.jsxs("tr",{children:[n.jsx("th",{children:n.jsx(u,{multiline:!0,width:220,transitionProps:{duration:200},label:s[0]?.localDevelopmentRelativeToRnd.rule,children:n.jsx("p",{children:"Local Development out of R&D"})})}),s.map(e=>n.jsx(f,{originalRuleData:e.localDevelopmentRelativeToRnd,diffRuleData:e.differences?.localDevelopmentRelativeToRnd??void 0},e.year)),n.jsx("td",{})]}),n.jsxs("tr",{children:[n.jsx("td",{children:"Foreign Development Expenses"}),s.map(e=>n.jsx(i,{originalAmount:e.foreignDevelopmentExpenses.formatted,diffAmount:e.differences?.foreignDevelopmentExpenses?.formatted??void 0},e.year)),n.jsx(i,{originalAmount:c(s.map(e=>e.foreignDevelopmentExpenses.raw).reduce((e,o)=>e+o,0),s[0].foreignDevelopmentExpenses.currency),diffAmount:m(s.map(e=>e.differences?.foreignDevelopmentExpenses?.raw??e.foreignDevelopmentExpenses.raw).filter(e=>!!e),s[0].foreignDevelopmentExpenses.currency)},"sum")]}),n.jsxs("tr",{children:[n.jsx("th",{children:n.jsx(u,{multiline:!0,width:220,transitionProps:{duration:200},label:s[0]?.foreignDevelopmentRelativeToRnd.rule,children:n.jsx("p",{children:"Foreign Development out of R&D"})})}),s.map(e=>n.jsx(f,{originalRuleData:e.foreignDevelopmentRelativeToRnd,diffRuleData:e.differences?.foreignDevelopmentRelativeToRnd??void 0},e.year)),n.jsx("td",{})]}),n.jsxs("tr",{children:[n.jsx("td",{children:"R&D Business Trips Expenses"}),s.map(e=>n.jsx(i,{originalAmount:e.businessTripRndExpenses.formatted,diffAmount:e.differences?.businessTripRndExpenses?.formatted??void 0},e.year)),n.jsx(i,{originalAmount:c(s.map(e=>e.businessTripRndExpenses.raw).reduce((e,o)=>e+o,0),s[0].businessTripRndExpenses.currency),diffAmount:m(s.map(e=>e.differences?.businessTripRndExpenses?.raw??e.businessTripRndExpenses.raw).filter(e=>!!e),s[0].businessTripRndExpenses.currency)},"sum")]})]})]})})})};export{U as CorporateTaxRulingComplianceReport};
@@ -1,2 +1,2 @@
1
- import{r as F,j as r,e as Q,u as q,gR as H,L as E,a8 as K,bm as $,B as U,G as X,bo as ee,bp as te,bs as ne,cI as O,x as k,gS as T,bt as se,F as oe,K as re,P as ie,W as le}from"./index-DPvrbbz9.js";import{u as W}from"./use-url-query-COmN7DHP.js";import{P as ae}from"./page-layout-SHFb6rY4.js";import{A as ce,a as fe,c as ue,b as he}from"./accordion-DKLV9b0H.js";import{P as de}from"./modal-Nvfe-DMu.js";import{F as pe}from"./funnel-WdA7f2As.js";var v={},z;function ye(){if(z)return v;z=1,Object.defineProperty(v,"__esModule",{value:!0}),v.calcSlices=v.applyPatch=v.calcPatch=v.lcs=v.diff=v.diff_core=void 0;function c(e,n){const{b:t,eq:s,stack_base:i}=e;let{i:l,N:o,j:h,M:a,Z:f,stack_top:x}=e;for(;;)switch(n){case 0:{e:for(;o>0&&a>0;){t.fill(0,0,2*f);const V=o-a,_=o+a,B=_&1,Y=l+o-1,Z=h+a-1,J=(_+B)/2;let N;t:for(let M=0;M<=J;M++){const I=2*Math.max(0,M-a)-M,L=M-2*Math.max(0,M-o);for(let u=I;u<=L;u+=2){const A=t[u-1-f*Math.floor((u-1)/f)],R=t[u+1-f*Math.floor((u+1)/f)],w=u===-M||u!==M&&A<R?R:A+1,S=w-u;let b=w,C=S;for(;b<o&&C<a&&s(l+b,h+C);)b++,C++;if(t[u-f*Math.floor(u/f)]=b,B===1&&(N=V-u)>=1-M&&N<M&&b+t[f+N-f*Math.floor(N/f)]>=o)if(M>1||b!==w){i[x++]=l+b,i[x++]=o-b,i[x++]=h+C,i[x++]=a-C,o=w,a=S,f=2*(Math.min(o,a)+1);continue e}else break t}for(let u=I;u<=L;u+=2){const A=t[f+u-1-f*Math.floor((u-1)/f)],R=t[f+u+1-f*Math.floor((u+1)/f)],w=u===-M||u!==M&&A<R?R:A+1,S=w-u;let b=w,C=S;for(;b<o&&C<a&&s(Y-b,Z-C);)b++,C++;if(t[f+u-f*Math.floor(u/f)]=b,B===0&&(N=V-u)>=-M&&N<=M&&b+t[N-f*Math.floor(N/f)]>=o)if(M>0||b!==w){i[x++]=l+o-w,i[x++]=w,i[x++]=h+a-S,i[x++]=S,o=o-b,a=a-C,f=2*(Math.min(o,a)+1);continue e}else break t}}if(o!==a){a>o?(l+=o,h+=o,a-=o,o=0):(l+=a,h+=a,o-=a,a=0);break}}if(o+a!==0)if(e.pxe===l||e.pye===h)e.pxe=l+o,e.pye=h+a;else{const V=e.pxs;if(e.oxs=e.pxs,e.oxe=e.pxe,e.oys=e.pys,e.oye=e.pye,e.pxs=l,e.pxe=l+o,e.pys=h,e.pye=h+a,V>=0)return e.i=l,e.N=o,e.j=h,e.M=a,e.Z=f,e.stack_top=x,1}}case 1:{if(x===0)return 2;a=i[--x],h=i[--x],o=i[--x],l=i[--x],f=2*(Math.min(o,a)+1),n=0}}}class m{constructor(n){this.state=n,this.c=0,this.result={value:null,done:!1}}[Symbol.iterator](){return this}next(){const{state:n,result:t}=this;if(this.c>1)return t.done=!0,t.value=void 0,t;const s=c(n,this.c);return this.c=s,s===1?(t.value=[n.oxs,n.oxe,n.oys,n.oye],t):n.pxs>=0?(t.value=[n.pxs,n.pxe,n.pys,n.pye],t):(t.done=!0,t.value=void 0,t)}}function D(e,n,t,s,i){const l=(Math.min(n,s)+1)*2,o=n+s,h=new(o<256?Uint8Array:o<65536?Uint16Array:Uint32Array)(2*l);return new m({i:e,N:n,j:t,M:s,Z:l,b:h,eq:i,pxs:-1,pxe:-1,pys:-1,pye:-1,oxs:-1,oxe:-1,oys:-1,oye:-1,stack_top:0,stack_base:[]})}v.diff_core=D;function d(e,n,t){let[s,i,l]=[0,e.length,n.length];if(typeof t=="function"){for(;s<i&&s<l&&t(s,s);)s++;if(s===i&&s===l)return[][Symbol.iterator]();for(;t(--i,--l)&&i>s&&l>s;);}else{for(;s<i&&s<l&&e[s]===n[s];)s++;if(s===i&&s===l)return[][Symbol.iterator]();for(;e[--i]===n[--l]&&i>s&&l>s;);t=(o,h)=>e[o]===n[h]}return D(s,i+1-s,s,l+1-s,t)}v.diff=d;class p{constructor(n,t){this.diff=n,this.N=t,this.i=0,this.j=0}[Symbol.iterator](){return this}next(){const n=this.diff.next();if(n.done){const{i:a,j:f,N:x}=this;return a<x&&(n.done=!1,n.value=[a,f,x-a],this.i=x),n}const t=n.value,s=t[0],i=t[1],l=t[3],{i:o,j:h}=this;return o!==s&&(t.length--,t[0]=o,t[1]=h,t[2]=s-o),this.i=i,this.j=l,n}}function y(e,n,t){return new p(d(e,n,t),e.length)}v.lcs=y;function*g(e,n,t){const s=ArrayBuffer.isView(e)?Uint8Array.prototype.subarray:e.slice;for(const i of d(e,n,t))i[2]=s.call(n,i[2],i[3]),yield i}v.calcPatch=g;function*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 Q,u as q,gR as H,L as E,a8 as K,bm as $,B as U,G as X,bo as ee,bp as te,bs as ne,cI as O,x as k,gS as T,bt as se,F as oe,K as re,P as ie,W as le}from"./index-B2_EbsaK.js";import{u as W}from"./use-url-query-BPzyQB93.js";import{P as ae}from"./page-layout-C0GJoVTR.js";import{A as ce,a as fe,c as ue,b as he}from"./accordion-B8kebokE.js";import{P as de}from"./modal-B0uNLang.js";import{F as pe}from"./funnel-BlaCusqP.js";var v={},z;function ye(){if(z)return v;z=1,Object.defineProperty(v,"__esModule",{value:!0}),v.calcSlices=v.applyPatch=v.calcPatch=v.lcs=v.diff=v.diff_core=void 0;function c(e,n){const{b:t,eq:s,stack_base:i}=e;let{i:l,N:o,j:h,M:a,Z:f,stack_top:x}=e;for(;;)switch(n){case 0:{e:for(;o>0&&a>0;){t.fill(0,0,2*f);const V=o-a,_=o+a,B=_&1,Y=l+o-1,Z=h+a-1,J=(_+B)/2;let N;t:for(let M=0;M<=J;M++){const I=2*Math.max(0,M-a)-M,L=M-2*Math.max(0,M-o);for(let u=I;u<=L;u+=2){const A=t[u-1-f*Math.floor((u-1)/f)],R=t[u+1-f*Math.floor((u+1)/f)],w=u===-M||u!==M&&A<R?R:A+1,S=w-u;let b=w,C=S;for(;b<o&&C<a&&s(l+b,h+C);)b++,C++;if(t[u-f*Math.floor(u/f)]=b,B===1&&(N=V-u)>=1-M&&N<M&&b+t[f+N-f*Math.floor(N/f)]>=o)if(M>1||b!==w){i[x++]=l+b,i[x++]=o-b,i[x++]=h+C,i[x++]=a-C,o=w,a=S,f=2*(Math.min(o,a)+1);continue e}else break t}for(let u=I;u<=L;u+=2){const A=t[f+u-1-f*Math.floor((u-1)/f)],R=t[f+u+1-f*Math.floor((u+1)/f)],w=u===-M||u!==M&&A<R?R:A+1,S=w-u;let b=w,C=S;for(;b<o&&C<a&&s(Y-b,Z-C);)b++,C++;if(t[f+u-f*Math.floor(u/f)]=b,B===0&&(N=V-u)>=-M&&N<=M&&b+t[N-f*Math.floor(N/f)]>=o)if(M>0||b!==w){i[x++]=l+o-w,i[x++]=w,i[x++]=h+a-S,i[x++]=S,o=o-b,a=a-C,f=2*(Math.min(o,a)+1);continue e}else break t}}if(o!==a){a>o?(l+=o,h+=o,a-=o,o=0):(l+=a,h+=a,o-=a,a=0);break}}if(o+a!==0)if(e.pxe===l||e.pye===h)e.pxe=l+o,e.pye=h+a;else{const V=e.pxs;if(e.oxs=e.pxs,e.oxe=e.pxe,e.oys=e.pys,e.oye=e.pye,e.pxs=l,e.pxe=l+o,e.pys=h,e.pye=h+a,V>=0)return e.i=l,e.N=o,e.j=h,e.M=a,e.Z=f,e.stack_top=x,1}}case 1:{if(x===0)return 2;a=i[--x],h=i[--x],o=i[--x],l=i[--x],f=2*(Math.min(o,a)+1),n=0}}}class m{constructor(n){this.state=n,this.c=0,this.result={value:null,done:!1}}[Symbol.iterator](){return this}next(){const{state:n,result:t}=this;if(this.c>1)return t.done=!0,t.value=void 0,t;const s=c(n,this.c);return this.c=s,s===1?(t.value=[n.oxs,n.oxe,n.oys,n.oye],t):n.pxs>=0?(t.value=[n.pxs,n.pxe,n.pys,n.pye],t):(t.done=!0,t.value=void 0,t)}}function D(e,n,t,s,i){const l=(Math.min(n,s)+1)*2,o=n+s,h=new(o<256?Uint8Array:o<65536?Uint16Array:Uint32Array)(2*l);return new m({i:e,N:n,j:t,M:s,Z:l,b:h,eq:i,pxs:-1,pxe:-1,pys:-1,pye:-1,oxs:-1,oxe:-1,oys:-1,oye:-1,stack_top:0,stack_base:[]})}v.diff_core=D;function d(e,n,t){let[s,i,l]=[0,e.length,n.length];if(typeof t=="function"){for(;s<i&&s<l&&t(s,s);)s++;if(s===i&&s===l)return[][Symbol.iterator]();for(;t(--i,--l)&&i>s&&l>s;);}else{for(;s<i&&s<l&&e[s]===n[s];)s++;if(s===i&&s===l)return[][Symbol.iterator]();for(;e[--i]===n[--l]&&i>s&&l>s;);t=(o,h)=>e[o]===n[h]}return D(s,i+1-s,s,l+1-s,t)}v.diff=d;class p{constructor(n,t){this.diff=n,this.N=t,this.i=0,this.j=0}[Symbol.iterator](){return this}next(){const n=this.diff.next();if(n.done){const{i:a,j:f,N:x}=this;return a<x&&(n.done=!1,n.value=[a,f,x-a],this.i=x),n}const t=n.value,s=t[0],i=t[1],l=t[3],{i:o,j:h}=this;return o!==s&&(t.length--,t[0]=o,t[1]=h,t[2]=s-o),this.i=i,this.j=l,n}}function y(e,n,t){return new p(d(e,n,t),e.length)}v.lcs=y;function*g(e,n,t){const s=ArrayBuffer.isView(e)?Uint8Array.prototype.subarray:e.slice;for(const i of d(e,n,t))i[2]=s.call(n,i[2],i[3]),yield i}v.calcPatch=g;function*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(Q,{className:"text-green-500"})]}),!!d.length&&d]})},Me=({filter:c})=>{const[{data:m,fetching:D,hasNext:d}]=q({query:H,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}=X({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",k(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",k(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}=W(),{userContext:g}=F.useContext(K);function P(j){j||={businessId:g?.context.adminBusinessId??c.businessId,fromMonthDate:k(T(new Date),"yyyy-MM-15"),toMonthDate:k(new Date,"yyyy-MM-15")},se(j,c)||m(j)}return F.useEffect(()=>{const j=$(c??{})?null:encodeURIComponent(JSON.stringify(c)),e=p("validateReportsFilters");j!==e&&y("validateReportsFilters",j)},[c,p,y]),r.jsxs(r.Fragment,{children:[r.jsx(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 Se=()=>{const{get:c}=W(),{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:k(T(new Date),"yyyy-MM-15"),toMonthDate:k(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(fe,{value:"pcn874",children:r.jsxs(re,{className:"p-4",children:[r.jsx(ue,{children:r.jsx(ie,{children:"Monthly VAT (PCN874)"})}),r.jsx(he,{children:r.jsx(le,{children:r.jsx(Me,{filter:d})})})]})})})})};export{Se as ValidateReportsScreen};
@@ -1 +1 @@
1
- import{u as M,d7 as Q,t as C,r as s,g as U,i as W,d8 as Y,d9 as J,J as F,da as E,j as e,D as R,aO as G,B as v,au as K,z as V,aP as X,aQ as Z,am as _,an as ee,ao as se,ap as te,ar as ne,db as ae,dc as re,dd as q,de as z,bU as ce,df as H,dg as ie,K as k,W as B,L as A,dh as le,e as oe,N as de,P as ue,di as me,be as he,b1 as xe,dj as je,x as P,dk as $,G as pe,bG as fe,w as ge,V as ye,b8 as ve,cI as De,cT as be,cU as Ce,cV as O,cW as g,cY as Ne,cZ as y,aw as we,bQ as Ie,F as Me,c as Te}from"./index-DPvrbbz9.js";import{s as L}from"./subMonths-CY79vHaS.js";const Se=()=>{const[{data:u,fetching:o,error:c},x]=M({query:Q});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]=U(Y),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=W(t,a,i);if(d?.issueGreenInvoiceDocuments?.success){C.success("Success",{id:i,description:"Documents issued successfully"});return}d?.issueGreenInvoiceDocuments?.errors&&console.error(d.issueGreenInvoiceDocuments.errors),C.error("Error",{id:i,description:a,duration:1e5,closeButton:!0})}catch(t){console.error(`${a}: ${t}`),C.error("Error",{id:i,description:a,duration:1e5,closeButton:!0})}},[o]);return{fetching:u,issueDocuments:c}};function Pe({issueMonth:u,contracts:o,onAdd:c}){const[x,a]=s.useState(!1),[i,t]=s.useState(""),[{data:d},h]=M({query:J,variables:{issueMonth:u,clientId:i}}),j=s.useCallback(n=>{t(n),h()},[h,t]);return s.useEffect(()=>{i!==""&&d&&(c(F(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(K,{})})}),e.jsxs(V,{className:"w-[400px] max-w-screen-md",children:[e.jsx(X,{children:e.jsx(Z,{children:"Select document recipient"})}),e.jsxs(_,{onValueChange:j,children:[e.jsx(ee,{children:e.jsx(se,{placeholder:"Recipient"})}),e.jsx(te,{children:o.map(n=>e.jsx(ne,{value:n.client.originalBusiness.id,children:n.client.originalBusiness.name},n.client.originalBusiness.id))})]})]})]})}function ke({onApprove:u,draft:o}){const[c,x]=s.useState(!1),[a,i]=s.useState(!1),[t,d]=s.useState(null),{previewDocument:h,fetching:j}=ae(),[n,N]=s.useState(re(o)),T=s.useCallback((l,p)=>{N(f=>({...f,[l]:p}))},[]);s.useEffect(()=>{i(!1)},[n]);const D=s.useCallback(async()=>{try{const l=await h({input:n});if(!l)throw new Error("No preview data returned");d(l),i(!0)}catch(l){console.error("Failed to generate preview:",l)}},[n,h]);s.useEffect(()=>{c&&!t&&D()},[c,t,D]);const w=n.income?.reduce((l,p)=>{const f=p.price*p.quantity,r=f*((p.vatRate||0)/100);return l+f+r},0)||0,I=()=>{u(n),x(!1)};return e.jsxs(R,{open:c,onOpenChange:x,children:[e.jsx(G,{asChild:!0,type:"button",children:e.jsxs(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(H,{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:$,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(H,{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:$,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,d7 as Q,t as C,r as s,g as U,i as W,d8 as Y,d9 as J,J as F,da as E,j as e,D as R,aO as G,B as v,au as K,z as V,aP as X,aQ as Z,am as _,an as ee,ao as se,ap as te,ar as ne,db as ae,dc as re,dd as q,de as z,bU as ce,df as H,dg as ie,K as k,W as B,L as A,dh as le,e as oe,N as de,P as ue,di as me,be as he,b1 as xe,dj as je,x as P,dk as $,G as pe,bG as fe,w as ge,V as ye,b8 as ve,cI as De,cT as be,cU as Ce,cV as O,cW as g,cY as Ne,cZ as y,aw as we,bQ as Ie,F as Me,c as Te}from"./index-B2_EbsaK.js";import{s as L}from"./subMonths-5wFmciT1.js";const Se=()=>{const[{data:u,fetching:o,error:c},x]=M({query:Q});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]=U(Y),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=W(t,a,i);if(d?.issueGreenInvoiceDocuments?.success){C.success("Success",{id:i,description:"Documents issued successfully"});return}d?.issueGreenInvoiceDocuments?.errors&&console.error(d.issueGreenInvoiceDocuments.errors),C.error("Error",{id:i,description:a,duration:1e5,closeButton:!0})}catch(t){console.error(`${a}: ${t}`),C.error("Error",{id:i,description:a,duration:1e5,closeButton:!0})}},[o]);return{fetching:u,issueDocuments:c}};function Pe({issueMonth:u,contracts:o,onAdd:c}){const[x,a]=s.useState(!1),[i,t]=s.useState(""),[{data:d},h]=M({query:J,variables:{issueMonth:u,clientId:i}}),j=s.useCallback(n=>{t(n),h()},[h,t]);return s.useEffect(()=>{i!==""&&d&&(c(F(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(K,{})})}),e.jsxs(V,{className:"w-[400px] max-w-screen-md",children:[e.jsx(X,{children:e.jsx(Z,{children:"Select document recipient"})}),e.jsxs(_,{onValueChange:j,children:[e.jsx(ee,{children:e.jsx(se,{placeholder:"Recipient"})}),e.jsx(te,{children:o.map(n=>e.jsx(ne,{value:n.client.originalBusiness.id,children:n.client.originalBusiness.name},n.client.originalBusiness.id))})]})]})]})}function ke({onApprove:u,draft:o}){const[c,x]=s.useState(!1),[a,i]=s.useState(!1),[t,d]=s.useState(null),{previewDocument:h,fetching:j}=ae(),[n,N]=s.useState(re(o)),T=s.useCallback((l,p)=>{N(f=>({...f,[l]:p}))},[]);s.useEffect(()=>{i(!1)},[n]);const D=s.useCallback(async()=>{try{const l=await h({input:n});if(!l)throw new Error("No preview data returned");d(l),i(!0)}catch(l){console.error("Failed to generate preview:",l)}},[n,h]);s.useEffect(()=>{c&&!t&&D()},[c,t,D]);const w=n.income?.reduce((l,p)=>{const f=p.price*p.quantity,r=f*((p.vatRate||0)/100);return l+f+r},0)||0,I=()=>{u(n),x(!1)};return e.jsxs(R,{open:c,onOpenChange:x,children:[e.jsx(G,{asChild:!0,type:"button",children:e.jsxs(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(H,{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:$,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(H,{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:$,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{j as e,cV as D,cZ as a,x as f,cu as n,J as N,fX as v,r as d,bt as T,D as E,aO as A,B as Y,z as I,bm as O,G as V,cO as M,V as P,X as y,Y as C,Z as F,_ as B,as as L,a0 as R,al as U,aT as _,F as k,a8 as q,u as z,c as G,cT as J,cU as Q,cW as o,cY as $,fY as H}from"./index-DPvrbbz9.js";import{u as w}from"./use-url-query-COmN7DHP.js";import{P as X}from"./page-layout-SHFb6rY4.js";import{F as Z}from"./funnel-WdA7f2As.js";const W=({record:s})=>{const t=N(v,s);return e.jsxs(D,{children:[e.jsx(a,{children:s.description}),e.jsx(a,{children:f(new Date(s.purchaseDate),"dd/MM/yyyy")}),e.jsx(a,{children:s.activationDate?f(new Date(s.activationDate),"dd/MM/yyyy"):void 0}),e.jsx(a,{children:t.originalCost?n(t.originalCost,0):void 0}),e.jsx(a,{children:t.reportYearDelta?n(t.reportYearDelta,0):void 0}),e.jsx(a,{children:n(t.totalDepreciableCosts,0)}),e.jsxs(a,{children:[n(s.statutoryDepreciationRate,0),"%"]}),e.jsx(a,{children:s.claimedDepreciationRate?`${n(s.claimedDepreciationRate,1)}%`:"-"}),e.jsx(a,{children:t.reportYearClaimedDepreciation?n(t.reportYearClaimedDepreciation,0):"-"}),e.jsx(a,{children:t.pastYearsAccumulatedDepreciation?n(t.pastYearsAccumulatedDepreciation,0):"-"}),e.jsx(a,{children:t.totalDepreciation?n(t.totalDepreciation,0):"-"}),e.jsx(a,{children:t.netValue?n(t.netValue,0):"-"})]})};function K(s){return!s||O(s)?null:encodeURIComponent(JSON.stringify(s))}const b="depreciationReportFilters";function ee({filter:s,setFilter:t,close:r}){const m=V({defaultValues:{...s}}),{control:c,handleSubmit:x}=m,{selectableFinancialEntities:u,fetching:l}=M(),j=i=>{t({...i,year:Number(i.year)}),r()};return e.jsx(P,{...m,children:e.jsxs("form",{onSubmit:x(j),className:"space-y-4",children:[e.jsx(y,{name:"year",control:c,rules:{required:"Year is required",validate:i=>{const p=Number(i);return Number.isNaN(p)||p<2e3||p>2100?"Invalid year":!0}},render:({field:i})=>e.jsxs(C,{children:[e.jsx(F,{children:"Year"}),e.jsx(B,{children:e.jsx(L,{...i,hideControls:!0,decimalScale:0})}),e.jsx(R,{})]})}),e.jsx(y,{name:"financialEntityId",defaultValue:s?.financialEntityId,control:c,render:({field:i})=>e.jsxs(C,{children:[e.jsx(F,{children:"Owner"}),e.jsx(U,{...i,data:u,value:i.value??void 0,disabled:l,placeholder:"Select a financial entity",formPart:!0}),e.jsx(R,{})]})}),e.jsx(_,{children:e.jsx(Y,{type:"submit",disabled:l,children:"Filter"})})]})})}function ae({filter:s,setFilter:t}){const[r,m]=d.useState(!1),{get:c,set:x}=w();d.useEffect(()=>{const l=K(s),j=c(b);l!==j&&x(b,l)},[s,c,x]);const u=d.useCallback(l=>{T(l,s)||t(l)},[s,t]);return e.jsxs(E,{open:r,onOpenChange:m,children:[e.jsx(A,{asChild:!0,children:e.jsx(Y,{variant:"outline",size:"icon",children:e.jsx(Z,{size:20})})}),e.jsx(I,{className:"sm:max-w-[425px]",children:e.jsx(ee,{filter:s,setFilter:u,close:()=>m(!1)})})]})}const g=({data:s,groupName:t})=>{const r=N(v,s);return e.jsxs(D,{className:"font-bold border-b border-black",children:[e.jsx(a,{children:t?"Group Total":"Overall Total"}),e.jsx(a,{colSpan:2,children:t}),e.jsx(a,{children:r.originalCost?n(r.originalCost,0):void 0}),e.jsx(a,{children:r.reportYearDelta?n(r.reportYearDelta,0):void 0}),e.jsx(a,{children:r.totalDepreciableCosts?n(r.totalDepreciableCosts,0):void 0}),e.jsx(a,{}),e.jsx(a,{}),e.jsx(a,{children:r.reportYearClaimedDepreciation?n(r.reportYearClaimedDepreciation,0):void 0}),e.jsx(a,{children:r.pastYearsAccumulatedDepreciation?n(r.pastYearsAccumulatedDepreciation,0):void 0}),e.jsx(a,{children:r.totalDepreciation?n(r.totalDepreciation,0):void 0}),e.jsx(a,{children:r.netValue?n(r.netValue,0):void 0})]})},ne=()=>{const{setFiltersContext:s}=d.useContext(k),{userContext:t}=d.useContext(q),{get:r}=w(),m=d.useMemo(()=>{const i={financialEntityId:t?.context.adminBusinessId,year:new Date().getFullYear()},p=r(b);if(p)try{return JSON.parse(decodeURIComponent(p))}catch(h){console.error("Failed to parse depreciation report filters from URL",h)}return i},[t?.context.adminBusinessId]),[c,x]=d.useState(m),[{data:u,fetching:l}]=z({query:H,variables:{filters:c}});d.useEffect(()=>{s(e.jsx("div",{className:"flex flex-row gap-x-5",children:e.jsx(ae,{filter:c,setFilter:x})}))},[c,s,x]);const j=d.useMemo(()=>`Depreciation Report for ${c.year}`,[c.year]);return e.jsx(X,{title:"Depreciation Report",description:j,children:l?e.jsx(G,{}):e.jsxs(J,{children:[e.jsxs(Q,{children:[e.jsxs(D,{className:"font-bold text-xl",children:[e.jsx(o,{colSpan:6,className:"text-center border-x",children:"List of Assets and Costs"}),e.jsx(o,{colSpan:5,className:"text-center border-x",children:"Depreciation"}),e.jsx(o,{className:"text-center border-x",children:"Remaining"})]}),e.jsxs(D,{className:"border-b border-black",children:[e.jsx(o,{className:"whitespace-normal",children:"Assets List and Descriptions"}),e.jsx(o,{className:"whitespace-normal",children:"Date of Purchase"}),e.jsx(o,{className:"whitespace-normal",children:"Activation Date"}),e.jsx(o,{className:"whitespace-normal",children:"Original Cost"}),e.jsx(o,{className:"whitespace-normal",children:"Changes During the Year"}),e.jsx(o,{className:"whitespace-normal",children:"Total Depreciable Assets"}),e.jsx(o,{className:"whitespace-normal",children:"Statutory Depreciation Rate"}),e.jsx(o,{className:"whitespace-normal",children:"Claimed Depreciation Rate"}),e.jsx(o,{className:"whitespace-normal",children:"Depreciation Claimed This Year"}),e.jsx(o,{className:"whitespace-normal",children:"Previous Tax Years Accumulated Depreciation"}),e.jsx(o,{className:"whitespace-normal",children:"Total Depreciation"}),e.jsx(o,{className:"whitespace-normal",children:"Net Book Value"})]})]}),e.jsx($,{children:u?.depreciationReport&&e.jsxs(e.Fragment,{children:[u.depreciationReport.categories.map((i,p)=>e.jsxs(d.Fragment,{children:[e.jsxs(D,{className:"font-bold",children:[e.jsx(a,{children:`Category ${p+1}`}),e.jsx(a,{colSpan:2,children:i.category.name}),e.jsx(a,{colSpan:3}),e.jsxs(a,{children:[n(i.category.percentage,0),"%"]}),e.jsx(a,{colSpan:5})]}),i.records.sort((h,S)=>h.purchaseDate.localeCompare(S.purchaseDate)).map(h=>e.jsx(W,{record:h},h.id)),e.jsx(g,{data:i.summary,groupName:i.category.name})]},i.id)),e.jsx(g,{data:u.depreciationReport.summary})]})})]})})};export{ne as DepreciationReport};
1
+ import{j as e,cV as D,cZ as a,x as f,cu as n,J as N,fX as v,r as d,bt as T,D as E,aO as A,B as Y,z as I,bm as O,G as V,cO as M,V as P,X as y,Y as C,Z as F,_ as B,as as L,a0 as R,al as U,aT as _,F as k,a8 as q,u as z,c as G,cT as J,cU as Q,cW as o,cY as $,fY as H}from"./index-B2_EbsaK.js";import{u as w}from"./use-url-query-BPzyQB93.js";import{P as X}from"./page-layout-C0GJoVTR.js";import{F as Z}from"./funnel-BlaCusqP.js";const W=({record:s})=>{const t=N(v,s);return e.jsxs(D,{children:[e.jsx(a,{children:s.description}),e.jsx(a,{children:f(new Date(s.purchaseDate),"dd/MM/yyyy")}),e.jsx(a,{children:s.activationDate?f(new Date(s.activationDate),"dd/MM/yyyy"):void 0}),e.jsx(a,{children:t.originalCost?n(t.originalCost,0):void 0}),e.jsx(a,{children:t.reportYearDelta?n(t.reportYearDelta,0):void 0}),e.jsx(a,{children:n(t.totalDepreciableCosts,0)}),e.jsxs(a,{children:[n(s.statutoryDepreciationRate,0),"%"]}),e.jsx(a,{children:s.claimedDepreciationRate?`${n(s.claimedDepreciationRate,1)}%`:"-"}),e.jsx(a,{children:t.reportYearClaimedDepreciation?n(t.reportYearClaimedDepreciation,0):"-"}),e.jsx(a,{children:t.pastYearsAccumulatedDepreciation?n(t.pastYearsAccumulatedDepreciation,0):"-"}),e.jsx(a,{children:t.totalDepreciation?n(t.totalDepreciation,0):"-"}),e.jsx(a,{children:t.netValue?n(t.netValue,0):"-"})]})};function K(s){return!s||O(s)?null:encodeURIComponent(JSON.stringify(s))}const b="depreciationReportFilters";function ee({filter:s,setFilter:t,close:r}){const m=V({defaultValues:{...s}}),{control:c,handleSubmit:x}=m,{selectableFinancialEntities:u,fetching:l}=M(),j=i=>{t({...i,year:Number(i.year)}),r()};return e.jsx(P,{...m,children:e.jsxs("form",{onSubmit:x(j),className:"space-y-4",children:[e.jsx(y,{name:"year",control:c,rules:{required:"Year is required",validate:i=>{const p=Number(i);return Number.isNaN(p)||p<2e3||p>2100?"Invalid year":!0}},render:({field:i})=>e.jsxs(C,{children:[e.jsx(F,{children:"Year"}),e.jsx(B,{children:e.jsx(L,{...i,hideControls:!0,decimalScale:0})}),e.jsx(R,{})]})}),e.jsx(y,{name:"financialEntityId",defaultValue:s?.financialEntityId,control:c,render:({field:i})=>e.jsxs(C,{children:[e.jsx(F,{children:"Owner"}),e.jsx(U,{...i,data:u,value:i.value??void 0,disabled:l,placeholder:"Select a financial entity",formPart:!0}),e.jsx(R,{})]})}),e.jsx(_,{children:e.jsx(Y,{type:"submit",disabled:l,children:"Filter"})})]})})}function ae({filter:s,setFilter:t}){const[r,m]=d.useState(!1),{get:c,set:x}=w();d.useEffect(()=>{const l=K(s),j=c(b);l!==j&&x(b,l)},[s,c,x]);const u=d.useCallback(l=>{T(l,s)||t(l)},[s,t]);return e.jsxs(E,{open:r,onOpenChange:m,children:[e.jsx(A,{asChild:!0,children:e.jsx(Y,{variant:"outline",size:"icon",children:e.jsx(Z,{size:20})})}),e.jsx(I,{className:"sm:max-w-[425px]",children:e.jsx(ee,{filter:s,setFilter:u,close:()=>m(!1)})})]})}const g=({data:s,groupName:t})=>{const r=N(v,s);return e.jsxs(D,{className:"font-bold border-b border-black",children:[e.jsx(a,{children:t?"Group Total":"Overall Total"}),e.jsx(a,{colSpan:2,children:t}),e.jsx(a,{children:r.originalCost?n(r.originalCost,0):void 0}),e.jsx(a,{children:r.reportYearDelta?n(r.reportYearDelta,0):void 0}),e.jsx(a,{children:r.totalDepreciableCosts?n(r.totalDepreciableCosts,0):void 0}),e.jsx(a,{}),e.jsx(a,{}),e.jsx(a,{children:r.reportYearClaimedDepreciation?n(r.reportYearClaimedDepreciation,0):void 0}),e.jsx(a,{children:r.pastYearsAccumulatedDepreciation?n(r.pastYearsAccumulatedDepreciation,0):void 0}),e.jsx(a,{children:r.totalDepreciation?n(r.totalDepreciation,0):void 0}),e.jsx(a,{children:r.netValue?n(r.netValue,0):void 0})]})},ne=()=>{const{setFiltersContext:s}=d.useContext(k),{userContext:t}=d.useContext(q),{get:r}=w(),m=d.useMemo(()=>{const i={financialEntityId:t?.context.adminBusinessId,year:new Date().getFullYear()},p=r(b);if(p)try{return JSON.parse(decodeURIComponent(p))}catch(h){console.error("Failed to parse depreciation report filters from URL",h)}return i},[t?.context.adminBusinessId]),[c,x]=d.useState(m),[{data:u,fetching:l}]=z({query:H,variables:{filters:c}});d.useEffect(()=>{s(e.jsx("div",{className:"flex flex-row gap-x-5",children:e.jsx(ae,{filter:c,setFilter:x})}))},[c,s,x]);const j=d.useMemo(()=>`Depreciation Report for ${c.year}`,[c.year]);return e.jsx(X,{title:"Depreciation Report",description:j,children:l?e.jsx(G,{}):e.jsxs(J,{children:[e.jsxs(Q,{children:[e.jsxs(D,{className:"font-bold text-xl",children:[e.jsx(o,{colSpan:6,className:"text-center border-x",children:"List of Assets and Costs"}),e.jsx(o,{colSpan:5,className:"text-center border-x",children:"Depreciation"}),e.jsx(o,{className:"text-center border-x",children:"Remaining"})]}),e.jsxs(D,{className:"border-b border-black",children:[e.jsx(o,{className:"whitespace-normal",children:"Assets List and Descriptions"}),e.jsx(o,{className:"whitespace-normal",children:"Date of Purchase"}),e.jsx(o,{className:"whitespace-normal",children:"Activation Date"}),e.jsx(o,{className:"whitespace-normal",children:"Original Cost"}),e.jsx(o,{className:"whitespace-normal",children:"Changes During the Year"}),e.jsx(o,{className:"whitespace-normal",children:"Total Depreciable Assets"}),e.jsx(o,{className:"whitespace-normal",children:"Statutory Depreciation Rate"}),e.jsx(o,{className:"whitespace-normal",children:"Claimed Depreciation Rate"}),e.jsx(o,{className:"whitespace-normal",children:"Depreciation Claimed This Year"}),e.jsx(o,{className:"whitespace-normal",children:"Previous Tax Years Accumulated Depreciation"}),e.jsx(o,{className:"whitespace-normal",children:"Total Depreciation"}),e.jsx(o,{className:"whitespace-normal",children:"Net Book Value"})]})]}),e.jsx($,{children:u?.depreciationReport&&e.jsxs(e.Fragment,{children:[u.depreciationReport.categories.map((i,p)=>e.jsxs(d.Fragment,{children:[e.jsxs(D,{className:"font-bold",children:[e.jsx(a,{children:`Category ${p+1}`}),e.jsx(a,{colSpan:2,children:i.category.name}),e.jsx(a,{colSpan:3}),e.jsxs(a,{children:[n(i.category.percentage,0),"%"]}),e.jsx(a,{colSpan:5})]}),i.records.sort((h,S)=>h.purchaseDate.localeCompare(S.purchaseDate)).map(h=>e.jsx(W,{record:h},h.id)),e.jsx(g,{data:i.summary,groupName:i.category.name})]},i.id)),e.jsx(g,{data:u.depreciationReport.summary})]})})]})})};export{ne as DepreciationReport};
@@ -1,4 +1,4 @@
1
- import{r as h,bm as S,j as e,bn as N,B as y,G as $,bo as k,a8 as R,V as O,bp as f,bq as D,br as C,x as F,X as A,Y as E,Z as z,_ as P,ah as M,bt as L,bj as w,T as B,a$ as j,aN as p,J as V,dl as _,cu as v,F as G,u as q,dm as U,dn as Z,L as H,dp as J}from"./index-DPvrbbz9.js";import{u as I}from"./use-url-query-COmN7DHP.js";import{P as Q}from"./page-layout-SHFb6rY4.js";import{P as X}from"./modal-Nvfe-DMu.js";import{F as K}from"./funnel-WdA7f2As.js";import{M as T}from"./MultiSelect-D1XVjXLN.js";import{D as W}from"./download-csv-button-D9_6J2pA.js";import{B as Y}from"./business-extended-info-MUfOmQ_B.js";import{P as ee,a as te}from"./panel-top-open-C3Q9X7Tg.js";import{T as se}from"./Table-DTU12O53.js";function re({filter:t,setFilter:s,closeModal:i}){const n=$({defaultValues:{...t}}),{control:a,handleSubmit:o}=n,{selectableBusinesses:r,fetching:u}=k(),{userContext:m}=h.useContext(R),c=l=>{l.fromDate?.trim()===""&&(l.fromDate=void 0),l.toDate?.trim()===""&&(l.toDate=void 0),s(l),i()};function d(){s({}),i()}return e.jsxs(e.Fragment,{children:[u?e.jsx("div",{children:"Loading..."}):e.jsx("div",{}),e.jsx(O,{...n,children:e.jsxs("form",{onSubmit:o(c),className:"space-y-2",children:[e.jsx(f,{name:"ownerIds",control:a,defaultValue:void 0,render:({field:l,fieldState:b})=>e.jsx(T,{...l,data:r,value:l.value??(m?.context.adminBusinessId?[m?.context.adminBusinessId]:void 0),disabled:u,label:"Owners",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:b.error?.message})}),e.jsx(f,{name:"businessIDs",control:a,defaultValue:void 0,render:({field:l,fieldState:b})=>e.jsx(T,{...l,data:r,value:l.value??void 0,disabled:u,label:"Businesses",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:b.error?.message})}),e.jsx(f,{name:"fromDate",control:a,defaultValue:t.fromDate,rules:{required:"Required",pattern:{value:D,message:"Date must be im format yyyy-mm-dd"}},render:({field:l,fieldState:b})=>e.jsx(C,{...l,onChange:x=>{const g=x?typeof x=="string"?x:F(x,"yyyy-MM-dd"):void 0;g!==l.value&&l.onChange(g)},value:l.value?new Date(l.value):void 0,label:"From Date",error:b.error?.message,required:!0,popoverProps:{withinPortal:!0}})}),e.jsx(f,{name:"toDate",control:a,defaultValue:t.toDate,rules:{pattern:{value:D,message:"Date must be im format yyyy-mm-dd"}},render:({field:l,fieldState:b})=>e.jsx(C,{...l,onChange:x=>{const g=x?typeof x=="string"?x:F(x,"yyyy-MM-dd"):void 0;g!==l.value&&l.onChange(g)},value:l.value?new Date(l.value):void 0,label:"To Date",error:b.error?.message,required:!0,popoverProps:{withinPortal:!0}})}),e.jsx(A,{name:"isShowZeroedAccounts",control:a,render:({field:l})=>e.jsxs(E,{className:"flex flex-row items-center justify-between rounded-lg border p-3 shadow-sm",children:[e.jsx("div",{className:"space-y-0.5",children:e.jsx(z,{children:"Show zeroed accounts"})}),e.jsxs("div",{className:"flex flex-row items-center gap-1",children:[e.jsx(P,{children:e.jsx(M,{defaultChecked:t.isShowZeroedAccounts??!1,onCheckedChange:l.onChange,checked:l.value===!0})}),e.jsx("span",{children:l.value?"show":"remove"})]})]})}),e.jsxs("div",{className:"flex justify-center mt-5 gap-3",children:[e.jsx("button",{type:"submit",className:"text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg",children:"Filter"}),e.jsx("button",{type:"button",className:"text-white bg-orange-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-orange-600 rounded-sm text-lg",onClick:d,children:"Clear"}),e.jsx("button",{type:"button",className:"text-white bg-rose-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-rose-600 rounded-sm text-lg",onClick:i,children:"Cancel"})]})]})})]})}function ae({filter:t,setFilter:s}){const[i,n]=h.useState(!1),[a,o]=h.useState(!S(t)),{get:r,set:u}=I();function m(d){return Object.entries(d??{}).filter(([b,x])=>x!==void 0&&Array.isArray(x)&&x.length>0).length>0}function c(d){L(d,t)||(s(d),o(m(d)))}return h.useEffect(()=>{const d=S(t)?null:encodeURIComponent(JSON.stringify(t)),l=r("trialBalanceReportFilters");d!==l&&u("trialBalanceReportFilters",d)},[t,r,u]),e.jsxs(e.Fragment,{children:[e.jsx(X,{opened:i,onClose:()=>n(!1),content:e.jsx(re,{filter:t,setFilter:c,closeModal:()=>n(!1)})}),e.jsx(N,{inline:!0,size:16,disabled:!a,children:e.jsx(y,{variant:"outline",onClick:()=>n(!0),className:"p-2",children:e.jsx(K,{size:20})})})]})}const ne=({data:t,fromDate:s,toDate:i})=>{const n=h.useCallback(async()=>{const a=oe(t),o=`trial_balance_report${s?`_${s}`:""}${i?`_${i}`:""}`;return{fileContent:a,fileName:o}},[t,s,i]);return e.jsx(W,{createFileVariables:n})},oe=t=>{let s="";s+=`Sort Code,Account Name,Debit,Credit,Balance\r
1
+ import{r as h,bm as S,j as e,bn as N,B as y,G as $,bo as k,a8 as R,V as O,bp as f,bq as D,br as C,x as F,X as A,Y as E,Z as z,_ as P,ah as M,bt as L,bj as w,T as B,a$ as j,aN as p,J as V,dl as _,cu as v,F as G,u as q,dm as U,dn as Z,L as H,dp as J}from"./index-B2_EbsaK.js";import{u as I}from"./use-url-query-BPzyQB93.js";import{P as Q}from"./page-layout-C0GJoVTR.js";import{P as X}from"./modal-B0uNLang.js";import{F as K}from"./funnel-BlaCusqP.js";import{M as T}from"./MultiSelect-CBtq6WUv.js";import{D as W}from"./download-csv-button-DZ5cKqkV.js";import{B as Y}from"./business-extended-info-DmQ7B7-Z.js";import{P as ee,a as te}from"./panel-top-open-BFNhAe3f.js";import{T as se}from"./Table-CYqAEQfS.js";function re({filter:t,setFilter:s,closeModal:i}){const n=$({defaultValues:{...t}}),{control:a,handleSubmit:o}=n,{selectableBusinesses:r,fetching:u}=k(),{userContext:m}=h.useContext(R),c=l=>{l.fromDate?.trim()===""&&(l.fromDate=void 0),l.toDate?.trim()===""&&(l.toDate=void 0),s(l),i()};function d(){s({}),i()}return e.jsxs(e.Fragment,{children:[u?e.jsx("div",{children:"Loading..."}):e.jsx("div",{}),e.jsx(O,{...n,children:e.jsxs("form",{onSubmit:o(c),className:"space-y-2",children:[e.jsx(f,{name:"ownerIds",control:a,defaultValue:void 0,render:({field:l,fieldState:b})=>e.jsx(T,{...l,data:r,value:l.value??(m?.context.adminBusinessId?[m?.context.adminBusinessId]:void 0),disabled:u,label:"Owners",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:b.error?.message})}),e.jsx(f,{name:"businessIDs",control:a,defaultValue:void 0,render:({field:l,fieldState:b})=>e.jsx(T,{...l,data:r,value:l.value??void 0,disabled:u,label:"Businesses",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:b.error?.message})}),e.jsx(f,{name:"fromDate",control:a,defaultValue:t.fromDate,rules:{required:"Required",pattern:{value:D,message:"Date must be im format yyyy-mm-dd"}},render:({field:l,fieldState:b})=>e.jsx(C,{...l,onChange:x=>{const g=x?typeof x=="string"?x:F(x,"yyyy-MM-dd"):void 0;g!==l.value&&l.onChange(g)},value:l.value?new Date(l.value):void 0,label:"From Date",error:b.error?.message,required:!0,popoverProps:{withinPortal:!0}})}),e.jsx(f,{name:"toDate",control:a,defaultValue:t.toDate,rules:{pattern:{value:D,message:"Date must be im format yyyy-mm-dd"}},render:({field:l,fieldState:b})=>e.jsx(C,{...l,onChange:x=>{const g=x?typeof x=="string"?x:F(x,"yyyy-MM-dd"):void 0;g!==l.value&&l.onChange(g)},value:l.value?new Date(l.value):void 0,label:"To Date",error:b.error?.message,required:!0,popoverProps:{withinPortal:!0}})}),e.jsx(A,{name:"isShowZeroedAccounts",control:a,render:({field:l})=>e.jsxs(E,{className:"flex flex-row items-center justify-between rounded-lg border p-3 shadow-sm",children:[e.jsx("div",{className:"space-y-0.5",children:e.jsx(z,{children:"Show zeroed accounts"})}),e.jsxs("div",{className:"flex flex-row items-center gap-1",children:[e.jsx(P,{children:e.jsx(M,{defaultChecked:t.isShowZeroedAccounts??!1,onCheckedChange:l.onChange,checked:l.value===!0})}),e.jsx("span",{children:l.value?"show":"remove"})]})]})}),e.jsxs("div",{className:"flex justify-center mt-5 gap-3",children:[e.jsx("button",{type:"submit",className:"text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg",children:"Filter"}),e.jsx("button",{type:"button",className:"text-white bg-orange-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-orange-600 rounded-sm text-lg",onClick:d,children:"Clear"}),e.jsx("button",{type:"button",className:"text-white bg-rose-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-rose-600 rounded-sm text-lg",onClick:i,children:"Cancel"})]})]})})]})}function ae({filter:t,setFilter:s}){const[i,n]=h.useState(!1),[a,o]=h.useState(!S(t)),{get:r,set:u}=I();function m(d){return Object.entries(d??{}).filter(([b,x])=>x!==void 0&&Array.isArray(x)&&x.length>0).length>0}function c(d){L(d,t)||(s(d),o(m(d)))}return h.useEffect(()=>{const d=S(t)?null:encodeURIComponent(JSON.stringify(t)),l=r("trialBalanceReportFilters");d!==l&&u("trialBalanceReportFilters",d)},[t,r,u]),e.jsxs(e.Fragment,{children:[e.jsx(X,{opened:i,onClose:()=>n(!1),content:e.jsx(re,{filter:t,setFilter:c,closeModal:()=>n(!1)})}),e.jsx(N,{inline:!0,size:16,disabled:!a,children:e.jsx(y,{variant:"outline",onClick:()=>n(!0),className:"p-2",children:e.jsx(K,{size:20})})})]})}const ne=({data:t,fromDate:s,toDate:i})=>{const n=h.useCallback(async()=>{const a=oe(t),o=`trial_balance_report${s?`_${s}`:""}${i?`_${i}`:""}`;return{fileContent:a,fileName:o}},[t,s,i]);return e.jsx(W,{createFileVariables:n})},oe=t=>{let s="";s+=`Sort Code,Account Name,Debit,Credit,Balance\r
2
2
  `;for(const[i,n]of Object.entries(t)){const a=ie(i,n);s+=a}return s+=`Report total:,,${Object.values(t).reduce((i,n)=>i+n.totalDebit,0)},${Object.values(t).reduce((i,n)=>i+n.totalCredit,0)},${Object.values(t).reduce((i,n)=>i+n.sum,0)}\r
3
3
  `,s};function ie(t,s){let i="";return Object.values(s.sortCodes).sort((n,a)=>n.key-a.key).map(n=>{const a=le(n);i+=a}),i+=`${t.replaceAll("0","*")},Group Total:,${s.totalDebit??""},${s.totalCredit??""},${s.sum}\r
4
4
  `,i}function le(t){let s="";s+=`${t.name}\r
@@ -1,4 +1,4 @@
1
- import{v as G,r as d,j as e,J as p,B as g,dR as q,dS as H,dT as _,cu as F,dU as M,dV as J,dW as Q,dX as $,dY as Y,dZ as W,d_ as X,u as T,t as Z,d$ as K,T as ee,e0 as te,a8 as E,bm as se,G as ae,cO as ne,bp as S,bs as A,e1 as N,cI as re,x as D,bt as oe,F as ie,L as ce,e2 as le}from"./index-DPvrbbz9.js";import{d as R}from"./graphql-document-dedupe-fragments-ByT8-wlV.js";import{u as V}from"./use-url-query-COmN7DHP.js";import{M as de}from"./index-CXH_lcpK.js";import{E as he,I as me,M as xe}from"./match-document-modal-Cqimg0VE.js";import{P as ue}from"./page-layout-SHFb6rY4.js";import{C as I,u as pe,a as z,b as O}from"./charges-table-C_4dY1Ic.js";import{P as w,a as y}from"./panel-top-open-C3Q9X7Tg.js";import{T as k}from"./toggle-expansion-button-Bh24n-cz.js";import{T as P}from"./Table-DTU12O53.js";import{c as ge}from"./charges-filters-DjnsiGzC.js";import{P as je}from"./modal-Nvfe-DMu.js";import{F as fe}from"./funnel-WdA7f2As.js";import"./Checkbox-Cxbop3qM.js";import"./YearPickerInput-CPL_XozD.js";import"./list-plus-ZvPwjqZn.js";import"./insert-business-trip-modal-BHY3QQup.js";import"./accounter-table-CeZ4q0re.js";import"./Pagination-DMimIHM4.js";import"./create-event-handler-BiA-1lGu.js";import"./index-DFgRsYAU.js";import"./similar-transactions-modal-zQY2R-sr.js";import"./addDays-sGeEkIxC.js";import"./tooltip-BaULIFLC.js";import"./summary-DwX_dmjr.js";import"./sub-7frHBT3Y.js";import"./subMonths-CY79vHaS.js";import"./MultiSelect-D1XVjXLN.js";/**
1
+ import{v as G,r as d,j as e,J as p,B as g,dR as q,dS as H,dT as _,cu as F,dU as M,dV as J,dW as Q,dX as $,dY as Y,dZ as W,d_ as X,u as T,t as Z,d$ as K,T as ee,e0 as te,a8 as E,bm as se,G as ae,cO as ne,bp as S,bs as A,e1 as N,cI as re,x as D,bt as oe,F as ie,L as ce,e2 as le}from"./index-B2_EbsaK.js";import{d as R}from"./graphql-document-dedupe-fragments-ByT8-wlV.js";import{u as V}from"./use-url-query-BPzyQB93.js";import{M as de}from"./index-EaY6ZYvr.js";import{E as he,I as me,M as xe}from"./match-document-modal-DcL0siQq.js";import{P as ue}from"./page-layout-C0GJoVTR.js";import{C as I,u as pe,a as z,b as O}from"./charges-table-D_GDHvFS.js";import{P as w,a as y}from"./panel-top-open-BFNhAe3f.js";import{T as k}from"./toggle-expansion-button-41Ejffq3.js";import{T as P}from"./Table-CYqAEQfS.js";import{c as ge}from"./charges-filters-BUFmsiTq.js";import{P as je}from"./modal-B0uNLang.js";import{F as fe}from"./funnel-BlaCusqP.js";import"./Checkbox-Ddw01d64.js";import"./YearPickerInput-CgU-feeq.js";import"./list-plus-CGvSlslE.js";import"./insert-business-trip-modal-BwOnvw7X.js";import"./accounter-table-CM6PQ9Aw.js";import"./Pagination-BM-86UO5.js";import"./create-event-handler-BiA-1lGu.js";import"./index-CRLPoT61.js";import"./similar-transactions-modal-nk8VHEtX.js";import"./addDays-DGlDD_vj.js";import"./tooltip-lhMCop8U.js";import"./summary-DuWhfNdL.js";import"./sub-fkVv9ghZ.js";import"./subMonths-5wFmciT1.js";import"./MultiSelect-CBtq6WUv.js";/**
2
2
  * @license lucide-react v0.548.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -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,fT as w}from"./index-DPvrbbz9.js";import{d as R}from"./graphql-document-dedupe-fragments-ByT8-wlV.js";import{P as E}from"./page-layout-SHFb6rY4.js";import{R as d}from"./report-commentary-row-DpYgprQr.js";import{P as v}from"./modal-Nvfe-DMu.js";import{Y as p}from"./YearPickerInput-CPL_XozD.js";import{F}from"./funnel-WdA7f2As.js";import{T as C}from"./Table-DTU12O53.js";import"./toggle-expansion-button-Bh24n-cz.js";import"./panel-top-open-C3Q9X7Tg.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,fT as w}from"./index-B2_EbsaK.js";import{d as R}from"./graphql-document-dedupe-fragments-ByT8-wlV.js";import{P as E}from"./page-layout-C0GJoVTR.js";import{R as d}from"./report-commentary-row-CNIlhboC.js";import{P as v}from"./modal-B0uNLang.js";import{Y as p}from"./YearPickerInput-CgU-feeq.js";import{F}from"./funnel-BlaCusqP.js";import{T as C}from"./Table-CYqAEQfS.js";import"./toggle-expansion-button-41Ejffq3.js";import"./panel-top-open-BFNhAe3f.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,2 +1,2 @@
1
- import{r as u,j as e,x as v,J as R,gb as M,F as $,u as k,cQ as B,L as P,cT as T,cU as V,cV as d,cW as L,cX as C,cY as Y,cZ as t,gc as S,d4 as K,d5 as O,dE as H,aN as z}from"./index-DPvrbbz9.js";import{D as A}from"./data-table-pagination-DtnUvTOC.js";import{P as Q}from"./page-layout-SHFb6rY4.js";import{D as q}from"./download-csv-button-D9_6J2pA.js";import{Y as E}from"./YearPickerInput-CPL_XozD.js";const J=({data:a,year:s})=>{const n=u.useCallback(async()=>{if(!a)return{fileContent:"",fileName:""};const x=R(M,a),m=U(x),l=`${s}_ledger`;return{fileContent:m,fileName:l}},[a,s]);return a?e.jsx(q,{createFileVariables:n}):e.jsx("div",{})},F=[{key:"",valueFn:()=>""},{key:"",valueFn:()=>""},{key:"Counterparty",valueFn:a=>j(a.counterParty?.name??"")},{key:"Invoice Date",valueFn:a=>v(a.invoiceDate,"yyyy-MM-dd")},{key:"Value Date",valueFn:a=>v(a.valueDate,"yyyy-MM-dd")},{key:"Reference",valueFn:a=>a.reference?`"${j(a.reference)}"`:""},{key:"Description",valueFn:a=>a.description?`"${j(a.description)}"`:""},{key:"Debit Amount",valueFn:a=>a.amount.raw<0?Math.abs(a.amount.raw).toFixed(2):""},{key:"Credit Amount",valueFn:a=>a.amount.raw>=0?a.amount.raw.toFixed(2):""},{key:"Balance",valueFn:a=>a.balance.toFixed(2)}],U=a=>{const s=[F.map(({key:n})=>n).join(",")];return a.financialEntitiesInfo.map(n=>{const x=`${j(n.entity.name)},${n.entity.sortCode?.key}`,m=`,Opening Balance,,,,,,,,${n.openingBalance.raw.toFixed(2)}`,l=`Total,${j(n.entity.name)},,,,,,,${Math.abs(n.totalDebit.raw).toFixed(2)} Debit,`,g=`,,,,,,,,${n.totalCredit.raw.toFixed(2)} Credit,${n.closingBalance.raw.toFixed(2)}`,D=`,,,,,,,,${(n.totalCredit.raw-n.totalDebit.raw).toFixed(2)} Diff,`;s.push(x,m,...n.records.map(o=>F.map(({valueFn:b})=>b(o)).join(",")),l,g,D)}),s.join(`\r
1
+ import{r as u,j as e,x as v,J as R,gb as M,F as $,u as k,cQ as B,L as P,cT as T,cU as V,cV as d,cW as L,cX as C,cY as Y,cZ as t,gc as S,d4 as K,d5 as O,dE as H,aN as z}from"./index-B2_EbsaK.js";import{D as A}from"./data-table-pagination-CKN0E29f.js";import{P as Q}from"./page-layout-C0GJoVTR.js";import{D as q}from"./download-csv-button-DZ5cKqkV.js";import{Y as E}from"./YearPickerInput-CgU-feeq.js";const J=({data:a,year:s})=>{const n=u.useCallback(async()=>{if(!a)return{fileContent:"",fileName:""};const x=R(M,a),m=U(x),l=`${s}_ledger`;return{fileContent:m,fileName:l}},[a,s]);return a?e.jsx(q,{createFileVariables:n}):e.jsx("div",{})},F=[{key:"",valueFn:()=>""},{key:"",valueFn:()=>""},{key:"Counterparty",valueFn:a=>j(a.counterParty?.name??"")},{key:"Invoice Date",valueFn:a=>v(a.invoiceDate,"yyyy-MM-dd")},{key:"Value Date",valueFn:a=>v(a.valueDate,"yyyy-MM-dd")},{key:"Reference",valueFn:a=>a.reference?`"${j(a.reference)}"`:""},{key:"Description",valueFn:a=>a.description?`"${j(a.description)}"`:""},{key:"Debit Amount",valueFn:a=>a.amount.raw<0?Math.abs(a.amount.raw).toFixed(2):""},{key:"Credit Amount",valueFn:a=>a.amount.raw>=0?a.amount.raw.toFixed(2):""},{key:"Balance",valueFn:a=>a.balance.toFixed(2)}],U=a=>{const s=[F.map(({key:n})=>n).join(",")];return a.financialEntitiesInfo.map(n=>{const x=`${j(n.entity.name)},${n.entity.sortCode?.key}`,m=`,Opening Balance,,,,,,,,${n.openingBalance.raw.toFixed(2)}`,l=`Total,${j(n.entity.name)},,,,,,,${Math.abs(n.totalDebit.raw).toFixed(2)} Debit,`,g=`,,,,,,,,${n.totalCredit.raw.toFixed(2)} Credit,${n.closingBalance.raw.toFixed(2)}`,D=`,,,,,,,,${(n.totalCredit.raw-n.totalDebit.raw).toFixed(2)} Diff,`;s.push(x,m,...n.records.map(o=>F.map(({valueFn:b})=>b(o)).join(",")),l,g,D)}),s.join(`\r
2
2
  `)};function j(a){return a.replace(/"/g,'""').replace(/,/g,".")}const c=H(z.Ils),W=[{id:"placeholder",header:"",cell:()=>null},{id:"counterparty",accessorKey:"counterparty",header:"Counterparty",cell:({row:a})=>e.jsx("div",{className:"font-medium",children:a.original.counterParty?.name})},{id:"invoiceDate",accessorKey:"invoiceDate",header:"Invoice Date",cell:({row:a})=>{const s=new Date(a.getValue("invoiceDate")),n=v(s,"yyyy-MM-dd");return e.jsx("div",{className:"font-medium",children:n})}},{id:"valueDate",accessorKey:"valueDate",header:"Value Date",cell:({row:a})=>{const s=new Date(a.getValue("valueDate")),n=v(s,"yyyy-MM-dd");return e.jsx("div",{className:"font-medium",children:n})}},{id:"reference",accessorKey:"reference",header:"Reference"},{id:"description",accessorKey:"description",header:"Description"},{id:"debit",header:"Debit",cell:({row:a})=>{const s=a.original.amount.raw;return s<0?e.jsx("div",{className:"font-medium",children:c.format(s*-1)}):null}},{id:"credit",header:"Credit",cell:({row:a})=>{const s=a.original.amount.raw;return s>=0?e.jsx("div",{className:"font-medium",children:c.format(s)}):null}},{id:"balance",accessorKey:"balance",header:"Balance",cell:({row:a})=>e.jsx("div",{className:"font-medium",children:c.format(a.getValue("balance"))})}],te=()=>{const{setFiltersContext:a}=u.useContext($),[s,n]=u.useState(new Date().getFullYear()-1),[{data:x,fetching:m}]=k({query:S,variables:{year:s}}),l=x?.yearlyLedgerReport,{financialEntitiesInfo:g}=l??{},D=u.useMemo(()=>g?.flatMap(r=>{const{entity:i,openingBalance:y,closingBalance:h,totalCredit:p,totalDebit:w}=r;return r.records.map(N=>({entity:i,openingBalance:y,closingBalance:h,totalCredit:p,totalDebit:w,...N}))})??[],[g]),o=B({data:D,columns:W,getCoreRowModel:O(),getPaginationRowModel:K(),initialState:{pagination:{pageSize:100}}}),b=o.getState().pagination.pageIndex;return u.useEffect(()=>{a(e.jsxs("div",{className:"flex items-center justify-end gap-10 space-x-2 py-4",children:[e.jsx("div",{className:"flex items-center justify-between px-2",children:e.jsx(A,{table:o})}),e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(E,{value:new Date(s,0,1),onChange:r=>r&&n(r?.getFullYear()),popoverProps:{withinPortal:!0},minDate:new Date(2010,0,1),maxDate:new Date}),e.jsx(J,{data:l,year:s})]})]}))},[s,m,a,l,o,b]),e.jsx(Q,{title:"Yearly Ledger Report",children:m?e.jsx(P,{className:"h-10 w-10 animate-spin mr-2 self-center"}):l?e.jsx("div",{className:"flex flex-col gap-4 rounded-md border",children:e.jsxs(T,{children:[e.jsx(V,{children:o.getHeaderGroups().map(r=>e.jsx(d,{children:r.headers.map(i=>e.jsx(L,{children:i.isPlaceholder?null:C(i.column.columnDef.header,i.getContext())},i.id))},r.id))}),e.jsx(Y,{children:o.getRowModel().rows.map((r,i)=>{const y=o.getRowModel().rows[i-1],h=o.getRowModel().rows[i+1],p=!y||y.original.entity.id!==r.original.entity.id,w=!h||h.original.entity.id!==r.original.entity.id;return e.jsxs(e.Fragment,{children:[p&&i!==0&&e.jsx(d,{className:"border-y-2 border-t-gray-300 border-b-gray-500",children:e.jsx(t,{})}),p&&e.jsx(X,{row:r}),e.jsx(d,{children:r.getVisibleCells().map(f=>e.jsx(t,{children:C(f.column.columnDef.cell,f.getContext())},f.id))},r.id),w&&e.jsx(Z,{row:r})]})})})]})}):e.jsx("div",{className:"rounded-md border h-24 text-center",children:"No results."})})};function X({row:a}){return e.jsxs(e.Fragment,{children:[e.jsxs(d,{className:"bg-gray-300",children:[e.jsx(t,{children:e.jsx("div",{className:"font-medium",children:a.original.entity.name})}),e.jsx(t,{children:e.jsx("div",{className:"font-medium",children:a.original.entity.sortCode?.key})}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{})]},`${a.id}-opening1`),e.jsxs(d,{className:"bg-gray-200",children:[e.jsx(t,{}),e.jsx(t,{children:e.jsx("div",{className:"font-medium",children:"Opening Balance"})}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{children:e.jsx("div",{className:"font-medium",children:c.format(a.original.openingBalance.raw)})})]},`${a.id}-opening2`)]})}function Z({row:a}){return e.jsxs(e.Fragment,{children:[e.jsxs(d,{className:"bg-gray-200",children:[e.jsx(t,{children:e.jsx("div",{className:"font-medium",children:"Total"})}),e.jsx(t,{children:e.jsx("div",{className:"font-medium",children:a.original.entity.name})}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{children:e.jsxs("div",{className:"font-medium",children:[c.format(a.original.totalDebit.raw)," Debit"]})}),e.jsx(t,{})]},`${a.id}-totals1`),e.jsxs(d,{className:"bg-gray-200",children:[e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{children:e.jsxs("div",{className:"font-medium",children:[c.format(a.original.totalCredit.raw)," Credit"]})}),e.jsx(t,{children:e.jsx("div",{className:"font-medium",children:c.format(a.original.closingBalance.raw)})})]},`${a.id}-totals2`),e.jsxs(d,{className:"bg-gray-200",children:[e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{}),e.jsx(t,{children:e.jsxs("div",{className:"font-medium",children:[c.format(a.original.totalCredit.raw-a.original.totalDebit.raw)," Diff"]})}),e.jsx(t,{})]},`${a.id}-totals3`)]})}export{te as YearlyLedgerReport};
@@ -1,4 +1,4 @@
1
- import{v as it,r as m,cE as Nc,ab as V,cJ as kc,ac as ae,j as v,cH as vn,dq as It,dr as ge,ds as Ho,cK as Lc,dt as Vc,du as nn,dv as jc,bm as Fi,D as _r,aO as zr,bn as Fc,B as ee,z as $r,aP as Ur,aQ as Hr,G as Wo,bo as Bc,a8 as _c,bp as An,bq as Bi,br as _i,x as rn,ah as Go,b8 as Ko,bt as zc,g as qo,dw as $c,t as Pe,i as Xo,u as rr,dx as Uc,cQ as Hc,dy as Wc,d3 as Gc,d4 as Kc,d5 as qc,L as Yo,I as Wr,cT as Xc,cU as Yc,cV as Nn,cW as Zc,cX as zi,cY as Jc,cZ as $i,c_ as Zo,c$ as Jo,d0 as Qo,dz as Qc,dA as eu,dB as sn,dC as tu,H as nu,a4 as ru,V as iu,X as su,Y as ou,Z as au,_ as lu,a0 as cu,aT as uu,a6 as Ui,dD as du,e as hu,aw as fu,av as Hi,dE as pu,dF as gu,dG as Wi,bR as mu,aN as vu,F as yu,aj as bu,dH as Tu,dI as xu}from"./index-DPvrbbz9.js";import{u as ea}from"./use-url-query-COmN7DHP.js";import{T as yn}from"./tooltip-BaULIFLC.js";import{A as Gi}from"./arrow-up-down-DkEXGAin.js";import{D as Su}from"./download-csv-button-D9_6J2pA.js";import{B as wu}from"./business-extended-info-MUfOmQ_B.js";import{_ as Du,a as bn,s as we,g as Gr,u as Ki,c as Kr,m as wt,d as ir,T as sr}from"./Typography-IL0wuZeq.js";import{P as Cu}from"./pencil-CPPx1BhC.js";import{P as Eu,a as Ou}from"./panel-top-open-C3Q9X7Tg.js";import{F as Pu}from"./funnel-WdA7f2As.js";import{M as Mu}from"./MultiSelect-D1XVjXLN.js";import"./Table-DTU12O53.js";/**
1
+ import{v as it,r as m,cE as Nc,ab as V,cJ as kc,ac as ae,j as v,cH as vn,dq as It,dr as ge,ds as Ho,cK as Lc,dt as Vc,du as nn,dv as jc,bm as Fi,D as _r,aO as zr,bn as Fc,B as ee,z as $r,aP as Ur,aQ as Hr,G as Wo,bo as Bc,a8 as _c,bp as An,bq as Bi,br as _i,x as rn,ah as Go,b8 as Ko,bt as zc,g as qo,dw as $c,t as Pe,i as Xo,u as rr,dx as Uc,cQ as Hc,dy as Wc,d3 as Gc,d4 as Kc,d5 as qc,L as Yo,I as Wr,cT as Xc,cU as Yc,cV as Nn,cW as Zc,cX as zi,cY as Jc,cZ as $i,c_ as Zo,c$ as Jo,d0 as Qo,dz as Qc,dA as eu,dB as sn,dC as tu,H as nu,a4 as ru,V as iu,X as su,Y as ou,Z as au,_ as lu,a0 as cu,aT as uu,a6 as Ui,dD as du,e as hu,aw as fu,av as Hi,dE as pu,dF as gu,dG as Wi,bR as mu,aN as vu,F as yu,aj as bu,dH as Tu,dI as xu}from"./index-B2_EbsaK.js";import{u as ea}from"./use-url-query-BPzyQB93.js";import{T as yn}from"./tooltip-lhMCop8U.js";import{A as Gi}from"./arrow-up-down-C61ge4J5.js";import{D as Su}from"./download-csv-button-DZ5cKqkV.js";import{B as wu}from"./business-extended-info-DmQ7B7-Z.js";import{_ as Du,a as bn,s as we,g as Gr,u as Ki,c as Kr,m as wt,d as ir,T as sr}from"./Typography--U0GsZ21.js";import{P as Cu}from"./pencil-9Th5X-OY.js";import{P as Eu,a as Ou}from"./panel-top-open-BFNhAe3f.js";import{F as Pu}from"./funnel-BlaCusqP.js";import{M as Mu}from"./MultiSelect-CBtq6WUv.js";import"./Table-CYqAEQfS.js";/**
2
2
  * @license lucide-react v0.548.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -0,0 +1,6 @@
1
+ import{v as fn,gp as te,fG as R,fE as ye,gq as Re,gr as hn,j as i,T as ut,bS as ft,R as ht,B as H,m as E,bQ as mn,gs as yn,e6 as gn,u as mt,gt as pn,G as yt,r as S,cO as gt,d as vn,V as pt,e7 as xn,X as se,Y as re,Z as oe,am as bn,_ as he,an as Dn,ao as kn,ap as Mn,ar as wn,a0 as ie,bq as vt,x as le,ah as Cn,a5 as Sn,g as On,gu as Nn,t as Te,i as jn,L as Tn,al as Qe,bp as Je,bK as Wn,br as En,gv as _n,I as xt,gw as In,gx as Fn,fF as Yn,gy as Bn,gz as Pn,gA as An,gB as Rn,gC as zn,gD as qn,gE as Hn,gF as bt,ab as m,gG as $n,gH as Zn,dn as ne,gI as Xe,gJ as Un,gK as Kn,a_ as Ln,gL as Gn,dv as Vn,ec as Qn,ed as Jn,gM as Xn,D as es,aO as ts,z as ns,aP as ss,aQ as rs,cu as os,bo as as,cp as is,q as cs,e as ls,dm as ae,fB as ds,J as us,fo as fs,cQ as hs,d3 as ms,d5 as ys,cT as gs,cU as ps,cV as We,cW as vs,cX as et,cY as xs,cZ as tt}from"./index-B2_EbsaK.js";import{u as qe,S as bs}from"./similar-transactions-modal-nk8VHEtX.js";import{a as Dt}from"./addDays-DGlDD_vj.js";import{L as Ds}from"./list-plus-CGvSlslE.js";import{T as ks}from"./tooltip-lhMCop8U.js";/**
2
+ * @license lucide-react v0.548.0 - ISC
3
+ *
4
+ * This source code is licensed under the ISC license.
5
+ * See the LICENSE file in the root directory of this source tree.
6
+ */const Ms=[["path",{d:"M15 3h6v6",key:"1q9fwt"}],["path",{d:"M10 14 21 3",key:"gplh6r"}],["path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6",key:"a6xqqp"}]],ws=fn("external-link",Ms);function Cs(e,t,s){return Dt(e,t*7,s)}function Ss(e,t){let s,n=t?.in;return e.forEach(r=>{!n&&typeof r=="object"&&(n=te.bind(null,r));const a=R(r,n);(!s||s<a||isNaN(+a))&&(s=a)}),te(n,s||NaN)}function Os(e,t){let s,n=t?.in;return e.forEach(r=>{!n&&typeof r=="object"&&(n=te.bind(null,r));const a=R(r,n);(!s||s>a||isNaN(+a))&&(s=a)}),te(n,s||NaN)}function Ns(e,t,s){const[n,r]=ye(s?.in,e,t);return+Re(n)==+Re(r)}function js(e,t,s){const[n,r]=ye(s?.in,e,t),a=n.getFullYear()-r.getFullYear(),c=n.getMonth()-r.getMonth();return a*12+c}function Ts(e,t){const s=R(e,t?.in),n=s.getMonth();return s.setFullYear(s.getFullYear(),n+1,0),s.setHours(23,59,59,999),s}function kt(e,t){const[s,n]=ye(e,t.start,t.end);return{start:s,end:n}}function Ws(e,t){const{start:s,end:n}=kt(t?.in,e);let r=+s>+n;const a=r?+s:+n,c=r?n:s;c.setHours(0,0,0,0),c.setDate(1);let o=1;const l=[];for(;+c<=a;)l.push(te(s,c)),c.setMonth(c.getMonth()+o);return r?l.reverse():l}function Es(e,t){const s=R(e,t?.in);return s.setDate(1),s.setHours(0,0,0,0),s}function _s(e,t){const{start:s,end:n}=kt(t?.in,e);let r=+s>+n;const a=r?+s:+n,c=r?n:s;c.setHours(0,0,0,0),c.setMonth(0,1);let o=1;const l=[];for(;+c<=a;)l.push(te(s,c)),c.setFullYear(c.getFullYear()+o);return r?l.reverse():l}function Mt(e,t){const s=hn(),n=t?.weekStartsOn??t?.locale?.options?.weekStartsOn??s.weekStartsOn??s.locale?.options?.weekStartsOn??0,r=R(e,t?.in),a=r.getDay(),c=(a<n?-7:0)+6-(a-n);return r.setDate(r.getDate()+c),r.setHours(23,59,59,999),r}function Is(e,t){return Mt(e,{...t,weekStartsOn:1})}function Fs(e,t){const s=R(e,t?.in),n=s.getFullYear(),r=s.getMonth(),a=te(s,0);return a.setFullYear(n,r+1,0),a.setHours(0,0,0,0),a.getDate()}function Ys(e,t){return R(e,t?.in).getMonth()}function Bs(e,t){return R(e,t?.in).getFullYear()}function Ps(e,t){return+R(e)>+R(t)}function As(e,t){return+R(e)<+R(t)}function Rs(e,t,s){const[n,r]=ye(s?.in,e,t);return n.getFullYear()===r.getFullYear()&&n.getMonth()===r.getMonth()}function zs(e,t,s){const[n,r]=ye(s?.in,e,t);return n.getFullYear()===r.getFullYear()}function qs(e,t,s){const n=R(e,s?.in),r=n.getFullYear(),a=n.getDate(),c=te(e,0);c.setFullYear(r,t,15),c.setHours(0,0,0,0);const o=Fs(c);return n.setMonth(t,Math.min(a,o)),n}function Hs(e,t,s){const n=R(e,s?.in);return isNaN(+n)?te(e,NaN):(n.setFullYear(t),n)}function $s(e){return i.jsx(ut,{label:"To Charge",children:i.jsx(ft,{to:ht.CHARGES.DETAIL(e.chargeId),target:"_blank",rel:"noreferrer",onClick:t=>t.stopPropagation(),className:"inline-block",children:i.jsx(H,{...e,className:E("size-7.5",e.className),variant:"ghost",children:i.jsx(ws,{className:"size-5"})})})})}function Zs({transactionId:e}){const{updateTransaction:t}=qe();function s(){t({transactionId:e,fields:{chargeId:gn}})}return i.jsx(mn,{onConfirm:s,title:"Are you sure you want to unlink this transaction from the charge?",children:i.jsx(H,{variant:"ghost",size:"icon",className:"size-7.5",children:i.jsx(yn,{className:"size-5"})})})}const Us=({transactionID:e,onDone:t,onChange:s})=>{const[{data:n,fetching:r}]=mt({query:pn,variables:{transactionIDs:[e]}}),a=n?.transactionsByIDs?.[0],c=yt({defaultValues:a??{}});S.useEffect(()=>{a&&c.reset(a)},[a,c]);const{control:o,handleSubmit:l,formState:{dirtyFields:d}}=c,{updateTransaction:f,fetching:u}=qe(),h=x=>{if(!a)return;const g=Sn(x,d);t?.(),g&&Object.keys(g).length>0&&f({transactionId:a.id,fields:g}).then(s)},{selectableFinancialEntities:y,fetching:C}=gt();return i.jsxs(i.Fragment,{children:[r&&i.jsx(vn,{className:"flex self-center my-5",color:"dark",size:"xl",variant:"dots"}),!r&&a&&i.jsx(pt,{...c,children:i.jsxs("form",{onSubmit:l(h),children:[i.jsx("div",{className:"flex-row px-10 h-max justify-start block",children:i.jsxs(xn,{cols:3,children:[i.jsx(se,{name:"counterpartyId",control:o,defaultValue:a.counterparty?.id,rules:{minLength:{value:2,message:"Minimum 2 characters"}},render:({field:x})=>i.jsxs(re,{children:[i.jsx(oe,{children:"Counterparty"}),i.jsxs(bn,{onValueChange:x.onChange,value:x.value??void 0,disabled:C,children:[i.jsx(he,{children:i.jsx(Dn,{className:"w-full truncate",children:i.jsx(kn,{placeholder:"Scroll to see all options"})})}),i.jsx(Mn,{onClick:g=>g.stopPropagation(),children:y.map(({value:g,label:k})=>i.jsx(wn,{value:g,children:k},g))})]}),i.jsx(ie,{})]})}),a?.account.__typename==="CardFinancialAccount"?i.jsx(se,{name:"effectiveDate",control:o,rules:{pattern:{value:vt,message:"Date must be im format yyyy-mm-dd"}},render:({field:x})=>i.jsxs(re,{children:[i.jsx(oe,{children:"Effective Date"}),i.jsx(he,{children:i.jsx(Bo,{...x,onChange:g=>{const k=g?le(g,"yyyy-MM-dd"):void 0;k!==x.value&&x.onChange(k)},value:x.value?new Date(x.value):void 0})}),i.jsx(ie,{})]})}):i.jsx(i.Fragment,{}),i.jsx(se,{name:"isFee",control:o,defaultValue:a.isFee,render:({field:x})=>i.jsxs(re,{className:"flex flex-row items-center justify-between rounded-lg border p-3 shadow-sm",children:[i.jsx("div",{className:"space-y-0.5",children:i.jsx(oe,{children:"Fee Transaction"})}),i.jsx(he,{children:i.jsx(Cn,{checked:x.value===!0,onCheckedChange:x.onChange})})]})})]})}),i.jsxs("div",{className:"mt-10 mb-5 flex justify-center gap-5",children:[i.jsx("button",{type:"submit",onClick:()=>l(h),className:"mt-8 text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg",disabled:u||Object.keys(d).length===0,children:"Accept"}),i.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:t,children:"Cancel"})]})]})})]})},Ks="insertMiscExpense",Ls=()=>{const[{fetching:e},t]=On(Nn),s=S.useCallback(async n=>{const r="Error creating misc expense",a=`${Ks}-${n.chargeId}`;Te.loading("Creating misc expense",{id:a});try{const c=await t(n),o=jn(c,r,a);if(o)return Te.success("Success",{id:a,description:"Misc expense was created"}),o.insertMiscExpense}catch(c){console.error(`${r}: ${c}`),Te.error("Error",{id:a,description:r,duration:1e5,closeButton:!0})}},[t]);return{fetching:e,insertMiscExpense:s}},Gs=({onDone:e,defaultValues:t={},chargeId:s})=>{const{insertMiscExpense:n,fetching:r}=Ls(),a=S.useCallback(async c=>{await n({chargeId:s,fields:c}),e()},[n,s,e]);return i.jsx(Vs,{defaultValues:t,onInsertDone:a,fetching:r})},Vs=({onInsertDone:e,defaultValues:t,fetching:s})=>{const n=o=>{o&&Object.keys(o).length>0&&e(o)},r=yt({defaultValues:{...t}}),{handleSubmit:a,formState:{dirtyFields:c}}=r;return i.jsx(pt,{...r,children:i.jsx("form",{onSubmit:a(n),noValidate:!0,children:i.jsxs("div",{className:"px-5 flex flex-col gap-5 relative",children:[s&&i.jsx("div",{className:"absolute bg-white/60 z-10 h-full w-full flex items-center justify-center",children:i.jsx("div",{className:"flex items-center",children:i.jsx("span",{className:"text-3xl mr-4",children:i.jsx(Tn,{className:"h-10 w-10 animate-spin mr-2 self-center"})})})}),i.jsx(Qs,{formManager:r,isInsert:!0}),i.jsx("div",{className:"flex justify-right gap-5 mt-5",children:i.jsx("button",{type:"submit",className:"text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg",disabled:s||Object.keys(c).length===0,children:"Accept"})})]})})})},Qs=({formManager:e,isInsert:t})=>{const{control:s,setValue:n}=e,{selectableFinancialEntities:r,fetching:a}=gt();return i.jsxs(i.Fragment,{children:[i.jsx(se,{name:"creditorId",control:s,rules:{required:t?"Required":void 0},render:({field:c})=>i.jsxs(re,{children:[i.jsx(oe,{children:"Creditor"}),i.jsx(Qe,{...c,data:r,value:c.value??void 0,disabled:a,placeholder:"Select creditor",formPart:!0}),i.jsx(ie,{})]})}),i.jsx(se,{name:"debtorId",control:s,rules:{required:t?"Required":void 0},render:({field:c})=>i.jsxs(re,{children:[i.jsx(oe,{children:"Debtor"}),i.jsx(Qe,{...c,data:r,value:c.value??void 0,disabled:a,placeholder:"Select debtor",formPart:!0}),i.jsx(ie,{})]})}),i.jsx(Je,{name:"amount",control:s,rules:{required:t?"Required":void 0},render:({field:c,fieldState:o})=>i.jsx(Je,{name:"currency",control:s,rules:{required:t?"Required":void 0},render:({field:l,fieldState:d})=>i.jsx(Wn,{...c,required:t,value:c.value??void 0,error:o.error?.message||d.error?.message,label:"Amount",currencyCodeProps:{...l,required:t,label:"Currency"}})})}),i.jsx(se,{name:"invoiceDate",control:s,rules:{...t?{required:"Required"}:{},pattern:{value:vt,message:"Date must be im format yyyy-mm-dd"}},render:({field:c})=>{const o=c.value?new Date(c.value):void 0;return i.jsxs(re,{children:[i.jsx(oe,{children:"Invoice Date"}),i.jsx(he,{children:i.jsx(En,{...c,required:t,onChange:l=>{const d=l?typeof l=="string"?l:le(l,"yyyy-MM-dd"):void 0;d!==c.value&&(n("invoiceDate",d),c.onChange(d))},value:o,valueFormat:"DD/MM/YYYY"})}),i.jsx(ie,{})]})}}),i.jsx(se,{name:"valueDate",control:s,rules:{...t?{required:"Required"}:{},validate:c=>c?!Number.isNaN(c.getTime())||"Invalid date and time format":!0},render:({field:c})=>i.jsxs(re,{children:[i.jsx(oe,{children:"Value Date"}),i.jsx(he,{children:i.jsx(_n,{...c,onChange:o=>{n("valueDate",o),c.onChange(o)},onPointerEnterCapture:()=>{},onPointerLeaveCapture:()=>{},required:t,placeholder:"Pick date and time",valueFormat:"DD/MM/YYYY HH:mm:ss",withSeconds:!0})}),i.jsx(ie,{})]})}),i.jsx(se,{name:"description",control:s,rules:{required:t?"Required":void 0},render:({field:c})=>i.jsxs(re,{children:[i.jsx(oe,{children:"Description"}),i.jsx(he,{children:i.jsx(xt,{...c,required:t,value:c.value??void 0})}),i.jsx(ie,{})]})})]})};function Js(e,t,s="long"){return new Intl.DateTimeFormat("en-US",{hour:"numeric",timeZone:e,timeZoneName:s}).format(t).split(/\s/g).slice(2).join(" ")}const Xs={},me={};function ce(e,t){try{const n=(Xs[e]||=new Intl.DateTimeFormat("en-US",{timeZone:e,timeZoneName:"longOffset"}).format)(t).split("GMT")[1];return n in me?me[n]:nt(n,n.split(":"))}catch{if(e in me)return me[e];const s=e?.match(er);return s?nt(e,s.slice(1)):NaN}}const er=/([+-]\d\d):?(\d\d)?/;function nt(e,t){const s=+(t[0]||0),n=+(t[1]||0),r=+(t[2]||0)/60;return me[e]=s*60+n>0?s*60+n+r:s*60-n-r}class V extends Date{constructor(...t){super(),t.length>1&&typeof t[t.length-1]=="string"&&(this.timeZone=t.pop()),this.internal=new Date,isNaN(ce(this.timeZone,this))?this.setTime(NaN):t.length?typeof t[0]=="number"&&(t.length===1||t.length===2&&typeof t[1]!="number")?this.setTime(t[0]):typeof t[0]=="string"?this.setTime(+new Date(t[0])):t[0]instanceof Date?this.setTime(+t[0]):(this.setTime(+new Date(...t)),wt(this),ze(this)):this.setTime(Date.now())}static tz(t,...s){return s.length?new V(...s,t):new V(Date.now(),t)}withTimeZone(t){return new V(+this,t)}getTimezoneOffset(){const t=-ce(this.timeZone,this);return t>0?Math.floor(t):Math.ceil(t)}setTime(t){return Date.prototype.setTime.apply(this,arguments),ze(this),+this}[Symbol.for("constructDateFrom")](t){return new V(+new Date(t),this.timeZone)}}const st=/^(get|set)(?!UTC)/;Object.getOwnPropertyNames(Date.prototype).forEach(e=>{if(!st.test(e))return;const t=e.replace(st,"$1UTC");V.prototype[t]&&(e.startsWith("get")?V.prototype[e]=function(){return this.internal[t]()}:(V.prototype[e]=function(){return Date.prototype[t].apply(this.internal,arguments),tr(this),+this},V.prototype[t]=function(){return Date.prototype[t].apply(this,arguments),ze(this),+this}))});function ze(e){e.internal.setTime(+e),e.internal.setUTCSeconds(e.internal.getUTCSeconds()-Math.round(-ce(e.timeZone,e)*60))}function tr(e){Date.prototype.setFullYear.call(e,e.internal.getUTCFullYear(),e.internal.getUTCMonth(),e.internal.getUTCDate()),Date.prototype.setHours.call(e,e.internal.getUTCHours(),e.internal.getUTCMinutes(),e.internal.getUTCSeconds(),e.internal.getUTCMilliseconds()),wt(e)}function wt(e){const t=ce(e.timeZone,e),s=t>0?Math.floor(t):Math.ceil(t),n=new Date(+e);n.setUTCHours(n.getUTCHours()-1);const r=-new Date(+e).getTimezoneOffset(),a=-new Date(+n).getTimezoneOffset(),c=r-a,o=Date.prototype.getHours.apply(e)!==e.internal.getUTCHours();c&&o&&e.internal.setUTCMinutes(e.internal.getUTCMinutes()+c);const l=r-s;l&&Date.prototype.setUTCMinutes.call(e,Date.prototype.getUTCMinutes.call(e)+l);const d=new Date(+e);d.setUTCSeconds(0);const f=r>0?d.getSeconds():(d.getSeconds()-60)%60,u=Math.round(-(ce(e.timeZone,e)*60))%60;(u||f)&&(e.internal.setUTCSeconds(e.internal.getUTCSeconds()+u),Date.prototype.setUTCSeconds.call(e,Date.prototype.getUTCSeconds.call(e)+u+f));const h=ce(e.timeZone,e),y=h>0?Math.floor(h):Math.ceil(h),x=-new Date(+e).getTimezoneOffset()-y,g=y!==s,k=x-l;if(g&&k){Date.prototype.setUTCMinutes.call(e,Date.prototype.getUTCMinutes.call(e)+k);const T=ce(e.timeZone,e),b=T>0?Math.floor(T):Math.ceil(T),j=y-b;j&&(e.internal.setUTCMinutes(e.internal.getUTCMinutes()+j),Date.prototype.setUTCMinutes.call(e,Date.prototype.getUTCMinutes.call(e)+j))}}class B extends V{static tz(t,...s){return s.length?new B(...s,t):new B(Date.now(),t)}toISOString(){const[t,s,n]=this.tzComponents(),r=`${t}${s}:${n}`;return this.internal.toISOString().slice(0,-1)+r}toString(){return`${this.toDateString()} ${this.toTimeString()}`}toDateString(){const[t,s,n,r]=this.internal.toUTCString().split(" ");return`${t?.slice(0,-1)} ${n} ${s} ${r}`}toTimeString(){const t=this.internal.toUTCString().split(" ")[4],[s,n,r]=this.tzComponents();return`${t} GMT${s}${n}${r} (${Js(this.timeZone,this)})`}toLocaleString(t,s){return Date.prototype.toLocaleString.call(this,t,{...s,timeZone:s?.timeZone||this.timeZone})}toLocaleDateString(t,s){return Date.prototype.toLocaleDateString.call(this,t,{...s,timeZone:s?.timeZone||this.timeZone})}toLocaleTimeString(t,s){return Date.prototype.toLocaleTimeString.call(this,t,{...s,timeZone:s?.timeZone||this.timeZone})}tzComponents(){const t=this.getTimezoneOffset(),s=t>0?"-":"+",n=String(Math.floor(Math.abs(t)/60)).padStart(2,"0"),r=String(Math.abs(t)%60).padStart(2,"0");return[s,n,r]}withTimeZone(t){return new B(+this,t)}[Symbol.for("constructDateFrom")](t){return new B(+new Date(t),this.timeZone)}}const rt=5,nr=4;function sr(e,t){const s=t.startOfMonth(e),n=s.getDay()>0?s.getDay():7,r=t.addDays(e,-n+1),a=t.addDays(r,rt*7-1);return t.getMonth(e)===t.getMonth(a)?rt:nr}function Ct(e,t){const s=t.startOfMonth(e),n=s.getDay();return n===1?s:n===0?t.addDays(s,-6):t.addDays(s,-1*(n-1))}function rr(e,t){const s=Ct(e,t),n=sr(e,t);return t.addDays(s,n*7-1)}class ${constructor(t,s){this.Date=Date,this.today=()=>this.overrides?.today?this.overrides.today():this.options.timeZone?B.tz(this.options.timeZone):new this.Date,this.newDate=(n,r,a)=>this.overrides?.newDate?this.overrides.newDate(n,r,a):this.options.timeZone?new B(n,r,a,this.options.timeZone):new Date(n,r,a),this.addDays=(n,r)=>this.overrides?.addDays?this.overrides.addDays(n,r):Dt(n,r),this.addMonths=(n,r)=>this.overrides?.addMonths?this.overrides.addMonths(n,r):In(n,r),this.addWeeks=(n,r)=>this.overrides?.addWeeks?this.overrides.addWeeks(n,r):Cs(n,r),this.addYears=(n,r)=>this.overrides?.addYears?this.overrides.addYears(n,r):Fn(n,r),this.differenceInCalendarDays=(n,r)=>this.overrides?.differenceInCalendarDays?this.overrides.differenceInCalendarDays(n,r):Yn(n,r),this.differenceInCalendarMonths=(n,r)=>this.overrides?.differenceInCalendarMonths?this.overrides.differenceInCalendarMonths(n,r):js(n,r),this.eachMonthOfInterval=n=>this.overrides?.eachMonthOfInterval?this.overrides.eachMonthOfInterval(n):Ws(n),this.eachYearOfInterval=n=>{const r=this.overrides?.eachYearOfInterval?this.overrides.eachYearOfInterval(n):_s(n),a=new Set(r.map(o=>this.getYear(o)));if(a.size===r.length)return r;const c=[];return a.forEach(o=>{c.push(new Date(o,0,1))}),c},this.endOfBroadcastWeek=n=>this.overrides?.endOfBroadcastWeek?this.overrides.endOfBroadcastWeek(n):rr(n,this),this.endOfISOWeek=n=>this.overrides?.endOfISOWeek?this.overrides.endOfISOWeek(n):Is(n),this.endOfMonth=n=>this.overrides?.endOfMonth?this.overrides.endOfMonth(n):Ts(n),this.endOfWeek=(n,r)=>this.overrides?.endOfWeek?this.overrides.endOfWeek(n,r):Mt(n,this.options),this.endOfYear=n=>this.overrides?.endOfYear?this.overrides.endOfYear(n):Bn(n),this.format=(n,r,a)=>{const c=this.overrides?.format?this.overrides.format(n,r,this.options):le(n,r,this.options);return this.options.numerals&&this.options.numerals!=="latn"?this.replaceDigits(c):c},this.getISOWeek=n=>this.overrides?.getISOWeek?this.overrides.getISOWeek(n):Pn(n),this.getMonth=(n,r)=>this.overrides?.getMonth?this.overrides.getMonth(n,this.options):Ys(n,this.options),this.getYear=(n,r)=>this.overrides?.getYear?this.overrides.getYear(n,this.options):Bs(n,this.options),this.getWeek=(n,r)=>this.overrides?.getWeek?this.overrides.getWeek(n,this.options):An(n,this.options),this.isAfter=(n,r)=>this.overrides?.isAfter?this.overrides.isAfter(n,r):Ps(n,r),this.isBefore=(n,r)=>this.overrides?.isBefore?this.overrides.isBefore(n,r):As(n,r),this.isDate=n=>this.overrides?.isDate?this.overrides.isDate(n):Rn(n),this.isSameDay=(n,r)=>this.overrides?.isSameDay?this.overrides.isSameDay(n,r):Ns(n,r),this.isSameMonth=(n,r)=>this.overrides?.isSameMonth?this.overrides.isSameMonth(n,r):Rs(n,r),this.isSameYear=(n,r)=>this.overrides?.isSameYear?this.overrides.isSameYear(n,r):zs(n,r),this.max=n=>this.overrides?.max?this.overrides.max(n):Ss(n),this.min=n=>this.overrides?.min?this.overrides.min(n):Os(n),this.setMonth=(n,r)=>this.overrides?.setMonth?this.overrides.setMonth(n,r):qs(n,r),this.setYear=(n,r)=>this.overrides?.setYear?this.overrides.setYear(n,r):Hs(n,r),this.startOfBroadcastWeek=(n,r)=>this.overrides?.startOfBroadcastWeek?this.overrides.startOfBroadcastWeek(n,this):Ct(n,this),this.startOfDay=n=>this.overrides?.startOfDay?this.overrides.startOfDay(n):Re(n),this.startOfISOWeek=n=>this.overrides?.startOfISOWeek?this.overrides.startOfISOWeek(n):zn(n),this.startOfMonth=n=>this.overrides?.startOfMonth?this.overrides.startOfMonth(n):Es(n),this.startOfWeek=(n,r)=>this.overrides?.startOfWeek?this.overrides.startOfWeek(n,this.options):qn(n,this.options),this.startOfYear=n=>this.overrides?.startOfYear?this.overrides.startOfYear(n):Hn(n),this.options={locale:bt,...t},this.overrides=s}getDigitMap(){const{numerals:t="latn"}=this.options,s=new Intl.NumberFormat("en-US",{numberingSystem:t}),n={};for(let r=0;r<10;r++)n[r.toString()]=s.format(r);return n}replaceDigits(t){const s=this.getDigitMap();return t.replace(/\d/g,n=>s[n]||n)}formatNumber(t){return this.replaceDigits(t.toString())}getMonthYearOrder(){const t=this.options.locale?.code;return t&&$.yearFirstLocales.has(t)?"year-first":"month-first"}formatMonthYear(t){const{locale:s,timeZone:n,numerals:r}=this.options,a=s?.code;if(a&&$.yearFirstLocales.has(a))try{return new Intl.DateTimeFormat(a,{month:"long",year:"numeric",timeZone:n,numberingSystem:r}).format(t)}catch{}const c=this.getMonthYearOrder()==="year-first"?"y LLLL":"LLLL y";return this.format(t,c)}}$.yearFirstLocales=new Set(["eu","hu","ja","ja-Hira","ja-JP","ko","ko-KR","lt","lt-LT","lv","lv-LV","mn","mn-MN","zh","zh-CN","zh-HK","zh-TW"]);const Q=new $;class St{constructor(t,s,n=Q){this.date=t,this.displayMonth=s,this.outside=!!(s&&!n.isSameMonth(t,s)),this.dateLib=n}isEqualTo(t){return this.dateLib.isSameDay(t.date,this.date)&&this.dateLib.isSameMonth(t.displayMonth,this.displayMonth)}}class or{constructor(t,s){this.date=t,this.weeks=s}}class ar{constructor(t,s){this.days=s,this.weekNumber=t}}function ir(e){return m.createElement("button",{...e})}function cr(e){return m.createElement("span",{...e})}function lr(e){const{size:t=24,orientation:s="left",className:n}=e;return m.createElement("svg",{className:n,width:t,height:t,viewBox:"0 0 24 24"},s==="up"&&m.createElement("polygon",{points:"6.77 17 12.5 11.43 18.24 17 20 15.28 12.5 8 5 15.28"}),s==="down"&&m.createElement("polygon",{points:"6.77 8 12.5 13.57 18.24 8 20 9.72 12.5 17 5 9.72"}),s==="left"&&m.createElement("polygon",{points:"16 18.112 9.81111111 12 16 5.87733333 14.0888889 4 6 12 14.0888889 20"}),s==="right"&&m.createElement("polygon",{points:"8 18.112 14.18888889 12 8 5.87733333 9.91111111 4 18 12 9.91111111 20"}))}function dr(e){const{day:t,modifiers:s,...n}=e;return m.createElement("td",{...n})}function ur(e){const{day:t,modifiers:s,...n}=e,r=m.useRef(null);return m.useEffect(()=>{s.focused&&r.current?.focus()},[s.focused]),m.createElement("button",{ref:r,...n})}var p;(function(e){e.Root="root",e.Chevron="chevron",e.Day="day",e.DayButton="day_button",e.CaptionLabel="caption_label",e.Dropdowns="dropdowns",e.Dropdown="dropdown",e.DropdownRoot="dropdown_root",e.Footer="footer",e.MonthGrid="month_grid",e.MonthCaption="month_caption",e.MonthsDropdown="months_dropdown",e.Month="month",e.Months="months",e.Nav="nav",e.NextMonthButton="button_next",e.PreviousMonthButton="button_previous",e.Week="week",e.Weeks="weeks",e.Weekday="weekday",e.Weekdays="weekdays",e.WeekNumber="week_number",e.WeekNumberHeader="week_number_header",e.YearsDropdown="years_dropdown"})(p||(p={}));var F;(function(e){e.disabled="disabled",e.hidden="hidden",e.outside="outside",e.focused="focused",e.today="today"})(F||(F={}));var L;(function(e){e.range_end="range_end",e.range_middle="range_middle",e.range_start="range_start",e.selected="selected"})(L||(L={}));var q;(function(e){e.weeks_before_enter="weeks_before_enter",e.weeks_before_exit="weeks_before_exit",e.weeks_after_enter="weeks_after_enter",e.weeks_after_exit="weeks_after_exit",e.caption_after_enter="caption_after_enter",e.caption_after_exit="caption_after_exit",e.caption_before_enter="caption_before_enter",e.caption_before_exit="caption_before_exit"})(q||(q={}));function fr(e){const{options:t,className:s,components:n,classNames:r,...a}=e,c=[r[p.Dropdown],s].join(" "),o=t?.find(({value:l})=>l===a.value);return m.createElement("span",{"data-disabled":a.disabled,className:r[p.DropdownRoot]},m.createElement(n.Select,{className:c,...a},t?.map(({value:l,label:d,disabled:f})=>m.createElement(n.Option,{key:l,value:l,disabled:f},d))),m.createElement("span",{className:r[p.CaptionLabel],"aria-hidden":!0},o?.label,m.createElement(n.Chevron,{orientation:"down",size:18,className:r[p.Chevron]})))}function hr(e){return m.createElement("div",{...e})}function mr(e){return m.createElement("div",{...e})}function yr(e){const{calendarMonth:t,displayIndex:s,...n}=e;return m.createElement("div",{...n},e.children)}function gr(e){const{calendarMonth:t,displayIndex:s,...n}=e;return m.createElement("div",{...n})}function pr(e){return m.createElement("table",{...e})}function vr(e){return m.createElement("div",{...e})}const Ot=S.createContext(void 0);function ge(){const e=S.useContext(Ot);if(e===void 0)throw new Error("useDayPicker() must be used within a custom component.");return e}function xr(e){const{components:t}=ge();return m.createElement(t.Dropdown,{...e})}function br(e){const{onPreviousClick:t,onNextClick:s,previousMonth:n,nextMonth:r,...a}=e,{components:c,classNames:o,labels:{labelPrevious:l,labelNext:d}}=ge(),f=S.useCallback(h=>{r&&s?.(h)},[r,s]),u=S.useCallback(h=>{n&&t?.(h)},[n,t]);return m.createElement("nav",{...a},m.createElement(c.PreviousMonthButton,{type:"button",className:o[p.PreviousMonthButton],tabIndex:n?void 0:-1,"aria-disabled":n?void 0:!0,"aria-label":l(n),onClick:u},m.createElement(c.Chevron,{disabled:n?void 0:!0,className:o[p.Chevron],orientation:"left"})),m.createElement(c.NextMonthButton,{type:"button",className:o[p.NextMonthButton],tabIndex:r?void 0:-1,"aria-disabled":r?void 0:!0,"aria-label":d(r),onClick:f},m.createElement(c.Chevron,{disabled:r?void 0:!0,orientation:"right",className:o[p.Chevron]})))}function Dr(e){const{components:t}=ge();return m.createElement(t.Button,{...e})}function kr(e){return m.createElement("option",{...e})}function Mr(e){const{components:t}=ge();return m.createElement(t.Button,{...e})}function wr(e){const{rootRef:t,...s}=e;return m.createElement("div",{...s,ref:t})}function Cr(e){return m.createElement("select",{...e})}function Sr(e){const{week:t,...s}=e;return m.createElement("tr",{...s})}function Or(e){return m.createElement("th",{...e})}function Nr(e){return m.createElement("thead",{"aria-hidden":!0},m.createElement("tr",{...e}))}function jr(e){const{week:t,...s}=e;return m.createElement("th",{...s})}function Tr(e){return m.createElement("th",{...e})}function Wr(e){return m.createElement("tbody",{...e})}function Er(e){const{components:t}=ge();return m.createElement(t.Dropdown,{...e})}const _r=Object.freeze(Object.defineProperty({__proto__:null,Button:ir,CaptionLabel:cr,Chevron:lr,Day:dr,DayButton:ur,Dropdown:fr,DropdownNav:hr,Footer:mr,Month:yr,MonthCaption:gr,MonthGrid:pr,Months:vr,MonthsDropdown:xr,Nav:br,NextMonthButton:Dr,Option:kr,PreviousMonthButton:Mr,Root:wr,Select:Cr,Week:Sr,WeekNumber:jr,WeekNumberHeader:Tr,Weekday:Or,Weekdays:Nr,Weeks:Wr,YearsDropdown:Er},Symbol.toStringTag,{value:"Module"}));function X(e,t,s=!1,n=Q){let{from:r,to:a}=e;const{differenceInCalendarDays:c,isSameDay:o}=n;return r&&a?(c(a,r)<0&&([r,a]=[a,r]),c(t,r)>=(s?1:0)&&c(a,t)>=(s?1:0)):!s&&a?o(a,t):!s&&r?o(r,t):!1}function Nt(e){return!!(e&&typeof e=="object"&&"before"in e&&"after"in e)}function He(e){return!!(e&&typeof e=="object"&&"from"in e)}function jt(e){return!!(e&&typeof e=="object"&&"after"in e)}function Tt(e){return!!(e&&typeof e=="object"&&"before"in e)}function Wt(e){return!!(e&&typeof e=="object"&&"dayOfWeek"in e)}function Et(e,t){return Array.isArray(e)&&e.every(t.isDate)}function ee(e,t,s=Q){const n=Array.isArray(t)?t:[t],{isSameDay:r,differenceInCalendarDays:a,isAfter:c}=s;return n.some(o=>{if(typeof o=="boolean")return o;if(s.isDate(o))return r(e,o);if(Et(o,s))return o.includes(e);if(He(o))return X(o,e,!1,s);if(Wt(o))return Array.isArray(o.dayOfWeek)?o.dayOfWeek.includes(e.getDay()):o.dayOfWeek===e.getDay();if(Nt(o)){const l=a(o.before,e),d=a(o.after,e),f=l>0,u=d<0;return c(o.before,o.after)?u&&f:f||u}return jt(o)?a(e,o.after)>0:Tt(o)?a(o.before,e)>0:typeof o=="function"?o(e):!1})}function Ir(e,t,s,n,r){const{disabled:a,hidden:c,modifiers:o,showOutsideDays:l,broadcastCalendar:d,today:f}=t,{isSameDay:u,isSameMonth:h,startOfMonth:y,isBefore:C,endOfMonth:x,isAfter:g}=r,k=s&&y(s),T=n&&x(n),b={[F.focused]:[],[F.outside]:[],[F.disabled]:[],[F.hidden]:[],[F.today]:[]},j={};for(const v of e){const{date:D,displayMonth:M}=v,N=!!(M&&!h(D,M)),Y=!!(k&&C(D,k)),P=!!(T&&g(D,T)),A=!!(a&&ee(D,a,r)),Z=!!(c&&ee(D,c,r))||Y||P||!d&&!l&&N||d&&l===!1&&N,de=u(D,f??r.today());N&&b.outside.push(v),A&&b.disabled.push(v),Z&&b.hidden.push(v),de&&b.today.push(v),o&&Object.keys(o).forEach(ue=>{const fe=o?.[ue];fe&&ee(D,fe,r)&&(j[ue]?j[ue].push(v):j[ue]=[v])})}return v=>{const D={[F.focused]:!1,[F.disabled]:!1,[F.hidden]:!1,[F.outside]:!1,[F.today]:!1},M={};for(const N in b){const Y=b[N];D[N]=Y.some(P=>P===v)}for(const N in j)M[N]=j[N].some(Y=>Y===v);return{...D,...M}}}function Fr(e,t,s={}){return Object.entries(e).filter(([,r])=>r===!0).reduce((r,[a])=>(s[a]?r.push(s[a]):t[F[a]]?r.push(t[F[a]]):t[L[a]]&&r.push(t[L[a]]),r),[t[p.Day]])}function Yr(e){return{..._r,...e}}function Br(e){const t={"data-mode":e.mode??void 0,"data-required":"required"in e?e.required:void 0,"data-multiple-months":e.numberOfMonths&&e.numberOfMonths>1||void 0,"data-week-numbers":e.showWeekNumber||void 0,"data-broadcast-calendar":e.broadcastCalendar||void 0,"data-nav-layout":e.navLayout||void 0};return Object.entries(e).forEach(([s,n])=>{s.startsWith("data-")&&(t[s]=n)}),t}function $e(){const e={};for(const t in p)e[p[t]]=`rdp-${p[t]}`;for(const t in F)e[F[t]]=`rdp-${F[t]}`;for(const t in L)e[L[t]]=`rdp-${L[t]}`;for(const t in q)e[q[t]]=`rdp-${q[t]}`;return e}function _t(e,t,s){return(s??new $(t)).formatMonthYear(e)}const Pr=_t;function Ar(e,t,s){return(s??new $(t)).format(e,"d")}function Rr(e,t=Q){return t.format(e,"LLLL")}function zr(e,t,s){return(s??new $(t)).format(e,"cccccc")}function qr(e,t=Q){return e<10?t.formatNumber(`0${e.toLocaleString()}`):t.formatNumber(`${e.toLocaleString()}`)}function Hr(){return""}function It(e,t=Q){return t.format(e,"yyyy")}const $r=It,Zr=Object.freeze(Object.defineProperty({__proto__:null,formatCaption:_t,formatDay:Ar,formatMonthCaption:Pr,formatMonthDropdown:Rr,formatWeekNumber:qr,formatWeekNumberHeader:Hr,formatWeekdayName:zr,formatYearCaption:$r,formatYearDropdown:It},Symbol.toStringTag,{value:"Module"}));function Ur(e){return e?.formatMonthCaption&&!e.formatCaption&&(e.formatCaption=e.formatMonthCaption),e?.formatYearCaption&&!e.formatYearDropdown&&(e.formatYearDropdown=e.formatYearCaption),{...Zr,...e}}function Kr(e,t,s,n,r){const{startOfMonth:a,startOfYear:c,endOfYear:o,eachMonthOfInterval:l,getMonth:d}=r;return l({start:c(e),end:o(e)}).map(h=>{const y=n.formatMonthDropdown(h,r),C=d(h),x=t&&h<a(t)||s&&h>a(s)||!1;return{value:C,label:y,disabled:x}})}function Lr(e,t={},s={}){let n={...t?.[p.Day]};return Object.entries(e).filter(([,r])=>r===!0).forEach(([r])=>{n={...n,...s?.[r]}}),n}function Gr(e,t,s){const n=e.today(),r=t?e.startOfISOWeek(n):e.startOfWeek(n),a=[];for(let c=0;c<7;c++){const o=e.addDays(r,c);a.push(o)}return a}function Vr(e,t,s,n,r=!1){if(!e||!t)return;const{startOfYear:a,endOfYear:c,eachYearOfInterval:o,getYear:l}=n,d=a(e),f=c(t),u=o({start:d,end:f});return r&&u.reverse(),u.map(h=>{const y=s.formatYearDropdown(h,n);return{value:l(h),label:y,disabled:!1}})}function Ft(e,t,s,n){let r=(n??new $(s)).format(e,"PPPP");return t.today&&(r=`Today, ${r}`),t.selected&&(r=`${r}, selected`),r}const Qr=Ft;function Yt(e,t,s){return(s??new $(t)).formatMonthYear(e)}const Jr=Yt;function Xr(e,t,s,n){let r=(n??new $(s)).format(e,"PPPP");return t?.today&&(r=`Today, ${r}`),r}function eo(e){return"Choose the Month"}function to(){return""}function no(e){return"Go to the Next Month"}function so(e){return"Go to the Previous Month"}function ro(e,t,s){return(s??new $(t)).format(e,"cccc")}function oo(e,t){return`Week ${e}`}function ao(e){return"Week Number"}function io(e){return"Choose the Year"}const co=Object.freeze(Object.defineProperty({__proto__:null,labelCaption:Jr,labelDay:Qr,labelDayButton:Ft,labelGrid:Yt,labelGridcell:Xr,labelMonthDropdown:eo,labelNav:to,labelNext:no,labelPrevious:so,labelWeekNumber:oo,labelWeekNumberHeader:ao,labelWeekday:ro,labelYearDropdown:io},Symbol.toStringTag,{value:"Module"})),pe=e=>e instanceof HTMLElement?e:null,Ee=e=>[...e.querySelectorAll("[data-animated-month]")??[]],lo=e=>pe(e.querySelector("[data-animated-month]")),_e=e=>pe(e.querySelector("[data-animated-caption]")),Ie=e=>pe(e.querySelector("[data-animated-weeks]")),uo=e=>pe(e.querySelector("[data-animated-nav]")),fo=e=>pe(e.querySelector("[data-animated-weekdays]"));function ho(e,t,{classNames:s,months:n,focused:r,dateLib:a}){const c=S.useRef(null),o=S.useRef(n),l=S.useRef(!1);S.useLayoutEffect(()=>{const d=o.current;if(o.current=n,!t||!e.current||!(e.current instanceof HTMLElement)||n.length===0||d.length===0||n.length!==d.length)return;const f=a.isSameMonth(n[0].date,d[0].date),u=a.isAfter(n[0].date,d[0].date),h=u?s[q.caption_after_enter]:s[q.caption_before_enter],y=u?s[q.weeks_after_enter]:s[q.weeks_before_enter],C=c.current,x=e.current.cloneNode(!0);if(x instanceof HTMLElement?(Ee(x).forEach(b=>{if(!(b instanceof HTMLElement))return;const j=lo(b);j&&b.contains(j)&&b.removeChild(j);const v=_e(b);v&&v.classList.remove(h);const D=Ie(b);D&&D.classList.remove(y)}),c.current=x):c.current=null,l.current||f||r)return;const g=C instanceof HTMLElement?Ee(C):[],k=Ee(e.current);if(k?.every(T=>T instanceof HTMLElement)&&g&&g.every(T=>T instanceof HTMLElement)){l.current=!0,e.current.style.isolation="isolate";const T=uo(e.current);T&&(T.style.zIndex="1"),k.forEach((b,j)=>{const v=g[j];if(!v)return;b.style.position="relative",b.style.overflow="hidden";const D=_e(b);D&&D.classList.add(h);const M=Ie(b);M&&M.classList.add(y);const N=()=>{l.current=!1,e.current&&(e.current.style.isolation=""),T&&(T.style.zIndex=""),D&&D.classList.remove(h),M&&M.classList.remove(y),b.style.position="",b.style.overflow="",b.contains(v)&&b.removeChild(v)};v.style.pointerEvents="none",v.style.position="absolute",v.style.overflow="hidden",v.setAttribute("aria-hidden","true");const Y=fo(v);Y&&(Y.style.opacity="0");const P=_e(v);P&&(P.classList.add(u?s[q.caption_before_exit]:s[q.caption_after_exit]),P.addEventListener("animationend",N));const A=Ie(v);A&&A.classList.add(u?s[q.weeks_before_exit]:s[q.weeks_after_exit]),b.insertBefore(v,b.firstChild)})}})}function mo(e,t,s,n){const r=e[0],a=e[e.length-1],{ISOWeek:c,fixedWeeks:o,broadcastCalendar:l}=s??{},{addDays:d,differenceInCalendarDays:f,differenceInCalendarMonths:u,endOfBroadcastWeek:h,endOfISOWeek:y,endOfMonth:C,endOfWeek:x,isAfter:g,startOfBroadcastWeek:k,startOfISOWeek:T,startOfWeek:b}=n,j=l?k(r,n):c?T(r):b(r),v=l?h(a):c?y(C(a)):x(C(a)),D=f(v,j),M=u(a,r)+1,N=[];for(let A=0;A<=D;A++){const Z=d(j,A);if(t&&g(Z,t))break;N.push(Z)}const P=(l?35:42)*M;if(o&&N.length<P){const A=P-N.length;for(let Z=0;Z<A;Z++){const de=d(N[N.length-1],1);N.push(de)}}return N}function yo(e){const t=[];return e.reduce((s,n)=>{const r=n.weeks.reduce((a,c)=>a.concat(c.days.slice()),t.slice());return s.concat(r.slice())},t.slice())}function go(e,t,s,n){const{numberOfMonths:r=1}=s,a=[];for(let c=0;c<r;c++){const o=n.addMonths(e,c);if(t&&o>t)break;a.push(o)}return a}function ot(e,t,s,n){const{month:r,defaultMonth:a,today:c=n.today(),numberOfMonths:o=1}=e;let l=r||a||c;const{differenceInCalendarMonths:d,addMonths:f,startOfMonth:u}=n;if(s&&d(s,l)<o-1){const h=-1*(o-1);l=f(s,h)}return t&&d(l,t)<0&&(l=t),u(l)}function po(e,t,s,n){const{addDays:r,endOfBroadcastWeek:a,endOfISOWeek:c,endOfMonth:o,endOfWeek:l,getISOWeek:d,getWeek:f,startOfBroadcastWeek:u,startOfISOWeek:h,startOfWeek:y}=n,C=e.reduce((x,g)=>{const k=s.broadcastCalendar?u(g,n):s.ISOWeek?h(g):y(g),T=s.broadcastCalendar?a(g):s.ISOWeek?c(o(g)):l(o(g)),b=t.filter(M=>M>=k&&M<=T),j=s.broadcastCalendar?35:42;if(s.fixedWeeks&&b.length<j){const M=t.filter(N=>{const Y=j-b.length;return N>T&&N<=r(T,Y)});b.push(...M)}const v=b.reduce((M,N)=>{const Y=s.ISOWeek?d(N):f(N),P=M.find(Z=>Z.weekNumber===Y),A=new St(N,g,n);return P?P.days.push(A):M.push(new ar(Y,[A])),M},[]),D=new or(g,v);return x.push(D),x},[]);return s.reverseMonths?C.reverse():C}function vo(e,t){let{startMonth:s,endMonth:n}=e;const{startOfYear:r,startOfDay:a,startOfMonth:c,endOfMonth:o,addYears:l,endOfYear:d,newDate:f,today:u}=t,{fromYear:h,toYear:y,fromMonth:C,toMonth:x}=e;!s&&C&&(s=C),!s&&h&&(s=t.newDate(h,0,1)),!n&&x&&(n=x),!n&&y&&(n=f(y,11,31));const g=e.captionLayout==="dropdown"||e.captionLayout==="dropdown-years";return s?s=c(s):h?s=f(h,0,1):!s&&g&&(s=r(l(e.today??u(),-100))),n?n=o(n):y?n=f(y,11,31):!n&&g&&(n=d(e.today??u())),[s&&a(s),n&&a(n)]}function xo(e,t,s,n){if(s.disableNavigation)return;const{pagedNavigation:r,numberOfMonths:a=1}=s,{startOfMonth:c,addMonths:o,differenceInCalendarMonths:l}=n,d=r?a:1,f=c(e);if(!t)return o(f,d);if(!(l(t,e)<a))return o(f,d)}function bo(e,t,s,n){if(s.disableNavigation)return;const{pagedNavigation:r,numberOfMonths:a}=s,{startOfMonth:c,addMonths:o,differenceInCalendarMonths:l}=n,d=r?a??1:1,f=c(e);if(!t)return o(f,-d);if(!(l(f,t)<=0))return o(f,-d)}function Do(e){const t=[];return e.reduce((s,n)=>s.concat(n.weeks.slice()),t.slice())}function De(e,t){const[s,n]=S.useState(e);return[t===void 0?s:t,n]}function ko(e,t){const[s,n]=vo(e,t),{startOfMonth:r,endOfMonth:a}=t,c=ot(e,s,n,t),[o,l]=De(c,e.month?c:void 0);S.useEffect(()=>{const D=ot(e,s,n,t);l(D)},[e.timeZone]);const d=go(o,n,e,t),f=mo(d,e.endMonth?a(e.endMonth):void 0,e,t),u=po(d,f,e,t),h=Do(u),y=yo(u),C=bo(o,s,e,t),x=xo(o,n,e,t),{disableNavigation:g,onMonthChange:k}=e,T=D=>h.some(M=>M.days.some(N=>N.isEqualTo(D))),b=D=>{if(g)return;let M=r(D);s&&M<r(s)&&(M=r(s)),n&&M>r(n)&&(M=r(n)),l(M),k?.(M)};return{months:u,weeks:h,days:y,navStart:s,navEnd:n,previousMonth:C,nextMonth:x,goToMonth:b,goToDay:D=>{T(D)||b(D.date)}}}var G;(function(e){e[e.Today=0]="Today",e[e.Selected=1]="Selected",e[e.LastFocused=2]="LastFocused",e[e.FocusedModifier=3]="FocusedModifier"})(G||(G={}));function at(e){return!e[F.disabled]&&!e[F.hidden]&&!e[F.outside]}function Mo(e,t,s,n){let r,a=-1;for(const c of e){const o=t(c);at(o)&&(o[F.focused]&&a<G.FocusedModifier?(r=c,a=G.FocusedModifier):n?.isEqualTo(c)&&a<G.LastFocused?(r=c,a=G.LastFocused):s(c.date)&&a<G.Selected?(r=c,a=G.Selected):o[F.today]&&a<G.Today&&(r=c,a=G.Today))}return r||(r=e.find(c=>at(t(c)))),r}function wo(e,t,s,n,r,a,c){const{ISOWeek:o,broadcastCalendar:l}=a,{addDays:d,addMonths:f,addWeeks:u,addYears:h,endOfBroadcastWeek:y,endOfISOWeek:C,endOfWeek:x,max:g,min:k,startOfBroadcastWeek:T,startOfISOWeek:b,startOfWeek:j}=c;let D={day:d,week:u,month:f,year:h,startOfWeek:M=>l?T(M,c):o?b(M):j(M),endOfWeek:M=>l?y(M):o?C(M):x(M)}[e](s,t==="after"?1:-1);return t==="before"&&n?D=g([n,D]):t==="after"&&r&&(D=k([r,D])),D}function Bt(e,t,s,n,r,a,c,o=0){if(o>365)return;const l=wo(e,t,s.date,n,r,a,c),d=!!(a.disabled&&ee(l,a.disabled,c)),f=!!(a.hidden&&ee(l,a.hidden,c)),u=l,h=new St(l,u,c);return!d&&!f?h:Bt(e,t,h,n,r,a,c,o+1)}function Co(e,t,s,n,r){const{autoFocus:a}=e,[c,o]=S.useState(),l=Mo(t.days,s,n||(()=>!1),c),[d,f]=S.useState(a?l:void 0);return{isFocusTarget:x=>!!l?.isEqualTo(x),setFocused:f,focused:d,blur:()=>{o(d),f(void 0)},moveFocus:(x,g)=>{if(!d)return;const k=Bt(x,g,d,t.navStart,t.navEnd,e,r);k&&(e.disableNavigation&&!t.days.some(b=>b.isEqualTo(k))||(t.goToDay(k),f(k)))}}}function So(e,t){const{selected:s,required:n,onSelect:r}=e,[a,c]=De(s,r?s:void 0),o=r?s:a,{isSameDay:l}=t,d=y=>o?.some(C=>l(C,y))??!1,{min:f,max:u}=e;return{selected:o,select:(y,C,x)=>{let g=[...o??[]];if(d(y)){if(o?.length===f||n&&o?.length===1)return;g=o?.filter(k=>!l(k,y))}else o?.length===u?g=[y]:g=[...g,y];return r||c(g),r?.(g,y,C,x),g},isSelected:d}}function Oo(e,t,s=0,n=0,r=!1,a=Q){const{from:c,to:o}=t||{},{isSameDay:l,isAfter:d,isBefore:f}=a;let u;if(!c&&!o)u={from:e,to:s>0?void 0:e};else if(c&&!o)l(c,e)?s===0?u={from:c,to:e}:r?u={from:c,to:void 0}:u=void 0:f(e,c)?u={from:e,to:c}:u={from:c,to:e};else if(c&&o)if(l(c,e)&&l(o,e))r?u={from:c,to:o}:u=void 0;else if(l(c,e))u={from:c,to:s>0?void 0:e};else if(l(o,e))u={from:e,to:s>0?void 0:e};else if(f(e,c))u={from:e,to:o};else if(d(e,c))u={from:c,to:e};else if(d(e,o))u={from:c,to:e};else throw new Error("Invalid range");if(u?.from&&u?.to){const h=a.differenceInCalendarDays(u.to,u.from);n>0&&h>n?u={from:e,to:void 0}:s>1&&h<s&&(u={from:e,to:void 0})}return u}function No(e,t,s=Q){const n=Array.isArray(t)?t:[t];let r=e.from;const a=s.differenceInCalendarDays(e.to,e.from),c=Math.min(a,6);for(let o=0;o<=c;o++){if(n.includes(r.getDay()))return!0;r=s.addDays(r,1)}return!1}function it(e,t,s=Q){return X(e,t.from,!1,s)||X(e,t.to,!1,s)||X(t,e.from,!1,s)||X(t,e.to,!1,s)}function jo(e,t,s=Q){const n=Array.isArray(t)?t:[t];if(n.filter(o=>typeof o!="function").some(o=>typeof o=="boolean"?o:s.isDate(o)?X(e,o,!1,s):Et(o,s)?o.some(l=>X(e,l,!1,s)):He(o)?o.from&&o.to?it(e,{from:o.from,to:o.to},s):!1:Wt(o)?No(e,o.dayOfWeek,s):Nt(o)?s.isAfter(o.before,o.after)?it(e,{from:s.addDays(o.after,1),to:s.addDays(o.before,-1)},s):ee(e.from,o,s)||ee(e.to,o,s):jt(o)||Tt(o)?ee(e.from,o,s)||ee(e.to,o,s):!1))return!0;const c=n.filter(o=>typeof o=="function");if(c.length){let o=e.from;const l=s.differenceInCalendarDays(e.to,e.from);for(let d=0;d<=l;d++){if(c.some(f=>f(o)))return!0;o=s.addDays(o,1)}}return!1}function To(e,t){const{disabled:s,excludeDisabled:n,selected:r,required:a,onSelect:c}=e,[o,l]=De(r,c?r:void 0),d=c?r:o;return{selected:d,select:(h,y,C)=>{const{min:x,max:g}=e,k=h?Oo(h,d,x,g,a,t):void 0;return n&&s&&k?.from&&k.to&&jo({from:k.from,to:k.to},s,t)&&(k.from=h,k.to=void 0),c||l(k),c?.(k,h,y,C),k},isSelected:h=>d&&X(d,h,!1,t)}}function Wo(e,t){const{selected:s,required:n,onSelect:r}=e,[a,c]=De(s,r?s:void 0),o=r?s:a,{isSameDay:l}=t;return{selected:o,select:(u,h,y)=>{let C=u;return!n&&o&&o&&l(u,o)&&(C=void 0),r||c(C),r?.(C,u,h,y),C},isSelected:u=>o?l(o,u):!1}}function Eo(e,t){const s=Wo(e,t),n=So(e,t),r=To(e,t);switch(e.mode){case"single":return s;case"multiple":return n;case"range":return r;default:return}}function _o(e){let t=e;t.timeZone&&(t={...e},t.today&&(t.today=new B(t.today,t.timeZone)),t.month&&(t.month=new B(t.month,t.timeZone)),t.defaultMonth&&(t.defaultMonth=new B(t.defaultMonth,t.timeZone)),t.startMonth&&(t.startMonth=new B(t.startMonth,t.timeZone)),t.endMonth&&(t.endMonth=new B(t.endMonth,t.timeZone)),t.mode==="single"&&t.selected?t.selected=new B(t.selected,t.timeZone):t.mode==="multiple"&&t.selected?t.selected=t.selected?.map(O=>new B(O,t.timeZone)):t.mode==="range"&&t.selected&&(t.selected={from:t.selected.from?new B(t.selected.from,t.timeZone):void 0,to:t.selected.to?new B(t.selected.to,t.timeZone):void 0}));const{components:s,formatters:n,labels:r,dateLib:a,locale:c,classNames:o}=S.useMemo(()=>{const O={...bt,...t.locale};return{dateLib:new $({locale:O,weekStartsOn:t.broadcastCalendar?1:t.weekStartsOn,firstWeekContainsDate:t.firstWeekContainsDate,useAdditionalWeekYearTokens:t.useAdditionalWeekYearTokens,useAdditionalDayOfYearTokens:t.useAdditionalDayOfYearTokens,timeZone:t.timeZone,numerals:t.numerals},t.dateLib),components:Yr(t.components),formatters:Ur(t.formatters),labels:{...co,...t.labels},locale:O,classNames:{...$e(),...t.classNames}}},[t.locale,t.broadcastCalendar,t.weekStartsOn,t.firstWeekContainsDate,t.useAdditionalWeekYearTokens,t.useAdditionalDayOfYearTokens,t.timeZone,t.numerals,t.dateLib,t.components,t.formatters,t.labels,t.classNames]),{captionLayout:l,mode:d,navLayout:f,numberOfMonths:u=1,onDayBlur:h,onDayClick:y,onDayFocus:C,onDayKeyDown:x,onDayMouseEnter:g,onDayMouseLeave:k,onNextClick:T,onPrevClick:b,showWeekNumber:j,styles:v}=t,{formatCaption:D,formatDay:M,formatMonthDropdown:N,formatWeekNumber:Y,formatWeekNumberHeader:P,formatWeekdayName:A,formatYearDropdown:Z}=n,de=ko(t,a),{days:ue,months:fe,navStart:ve,navEnd:ke,previousMonth:U,nextMonth:K,goToMonth:J}=de,Me=Ir(ue,t,ve,ke,a),{isSelected:we,select:Ce,selected:xe}=Eo(t,a)??{},{blur:Ze,focused:Ue,isFocusTarget:Pt,moveFocus:Ke,setFocused:be}=Co(t,de,Me,we??(()=>!1),a),{labelDayButton:At,labelGridcell:Rt,labelGrid:zt,labelMonthDropdown:qt,labelNav:Le,labelPrevious:Ht,labelNext:$t,labelWeekday:Zt,labelWeekNumber:Ut,labelWeekNumberHeader:Kt,labelYearDropdown:Lt}=r,Gt=S.useMemo(()=>Gr(a,t.ISOWeek),[a,t.ISOWeek]),Ge=d!==void 0||y!==void 0,Se=S.useCallback(()=>{U&&(J(U),b?.(U))},[U,J,b]),Oe=S.useCallback(()=>{K&&(J(K),T?.(K))},[J,K,T]),Vt=S.useCallback((O,I)=>w=>{w.preventDefault(),w.stopPropagation(),be(O),Ce?.(O.date,I,w),y?.(O.date,I,w)},[Ce,y,be]),Qt=S.useCallback((O,I)=>w=>{be(O),C?.(O.date,I,w)},[C,be]),Jt=S.useCallback((O,I)=>w=>{Ze(),h?.(O.date,I,w)},[Ze,h]),Xt=S.useCallback((O,I)=>w=>{const _={ArrowLeft:[w.shiftKey?"month":"day",t.dir==="rtl"?"after":"before"],ArrowRight:[w.shiftKey?"month":"day",t.dir==="rtl"?"before":"after"],ArrowDown:[w.shiftKey?"year":"week","after"],ArrowUp:[w.shiftKey?"year":"week","before"],PageUp:[w.shiftKey?"year":"month","before"],PageDown:[w.shiftKey?"year":"month","after"],Home:["startOfWeek","before"],End:["endOfWeek","after"]};if(_[w.key]){w.preventDefault(),w.stopPropagation();const[z,W]=_[w.key];Ke(z,W)}x?.(O.date,I,w)},[Ke,x,t.dir]),en=S.useCallback((O,I)=>w=>{g?.(O.date,I,w)},[g]),tn=S.useCallback((O,I)=>w=>{k?.(O.date,I,w)},[k]),nn=S.useCallback(O=>I=>{const w=Number(I.target.value),_=a.setMonth(a.startOfMonth(O),w);J(_)},[a,J]),sn=S.useCallback(O=>I=>{const w=Number(I.target.value),_=a.setYear(a.startOfMonth(O),w);J(_)},[a,J]),{className:rn,style:on}=S.useMemo(()=>({className:[o[p.Root],t.className].filter(Boolean).join(" "),style:{...v?.[p.Root],...t.style}}),[o,t.className,t.style,v]),an=Br(t),Ve=S.useRef(null);ho(Ve,!!t.animate,{classNames:o,months:fe,focused:Ue,dateLib:a});const cn={dayPickerProps:t,selected:xe,select:Ce,isSelected:we,months:fe,nextMonth:K,previousMonth:U,goToMonth:J,getModifiers:Me,components:s,classNames:o,styles:v,labels:r,formatters:n};return m.createElement(Ot.Provider,{value:cn},m.createElement(s.Root,{rootRef:t.animate?Ve:void 0,className:rn,style:on,dir:t.dir,id:t.id,lang:t.lang,nonce:t.nonce,title:t.title,role:t.role,"aria-label":t["aria-label"],"aria-labelledby":t["aria-labelledby"],...an},m.createElement(s.Months,{className:o[p.Months],style:v?.[p.Months]},!t.hideNavigation&&!f&&m.createElement(s.Nav,{"data-animated-nav":t.animate?"true":void 0,className:o[p.Nav],style:v?.[p.Nav],"aria-label":Le(),onPreviousClick:Se,onNextClick:Oe,previousMonth:U,nextMonth:K}),fe.map((O,I)=>m.createElement(s.Month,{"data-animated-month":t.animate?"true":void 0,className:o[p.Month],style:v?.[p.Month],key:I,displayIndex:I,calendarMonth:O},f==="around"&&!t.hideNavigation&&I===0&&m.createElement(s.PreviousMonthButton,{type:"button",className:o[p.PreviousMonthButton],tabIndex:U?void 0:-1,"aria-disabled":U?void 0:!0,"aria-label":Ht(U),onClick:Se,"data-animated-button":t.animate?"true":void 0},m.createElement(s.Chevron,{disabled:U?void 0:!0,className:o[p.Chevron],orientation:t.dir==="rtl"?"right":"left"})),m.createElement(s.MonthCaption,{"data-animated-caption":t.animate?"true":void 0,className:o[p.MonthCaption],style:v?.[p.MonthCaption],calendarMonth:O,displayIndex:I},l?.startsWith("dropdown")?m.createElement(s.DropdownNav,{className:o[p.Dropdowns],style:v?.[p.Dropdowns]},(()=>{const w=l==="dropdown"||l==="dropdown-months"?m.createElement(s.MonthsDropdown,{key:"month",className:o[p.MonthsDropdown],"aria-label":qt(),classNames:o,components:s,disabled:!!t.disableNavigation,onChange:nn(O.date),options:Kr(O.date,ve,ke,n,a),style:v?.[p.Dropdown],value:a.getMonth(O.date)}):m.createElement("span",{key:"month"},N(O.date,a)),_=l==="dropdown"||l==="dropdown-years"?m.createElement(s.YearsDropdown,{key:"year",className:o[p.YearsDropdown],"aria-label":Lt(a.options),classNames:o,components:s,disabled:!!t.disableNavigation,onChange:sn(O.date),options:Vr(ve,ke,n,a,!!t.reverseYears),style:v?.[p.Dropdown],value:a.getYear(O.date)}):m.createElement("span",{key:"year"},Z(O.date,a));return a.getMonthYearOrder()==="year-first"?[_,w]:[w,_]})(),m.createElement("span",{role:"status","aria-live":"polite",style:{border:0,clip:"rect(0 0 0 0)",height:"1px",margin:"-1px",overflow:"hidden",padding:0,position:"absolute",width:"1px",whiteSpace:"nowrap",wordWrap:"normal"}},D(O.date,a.options,a))):m.createElement(s.CaptionLabel,{className:o[p.CaptionLabel],role:"status","aria-live":"polite"},D(O.date,a.options,a))),f==="around"&&!t.hideNavigation&&I===u-1&&m.createElement(s.NextMonthButton,{type:"button",className:o[p.NextMonthButton],tabIndex:K?void 0:-1,"aria-disabled":K?void 0:!0,"aria-label":$t(K),onClick:Oe,"data-animated-button":t.animate?"true":void 0},m.createElement(s.Chevron,{disabled:K?void 0:!0,className:o[p.Chevron],orientation:t.dir==="rtl"?"left":"right"})),I===u-1&&f==="after"&&!t.hideNavigation&&m.createElement(s.Nav,{"data-animated-nav":t.animate?"true":void 0,className:o[p.Nav],style:v?.[p.Nav],"aria-label":Le(),onPreviousClick:Se,onNextClick:Oe,previousMonth:U,nextMonth:K}),m.createElement(s.MonthGrid,{role:"grid","aria-multiselectable":d==="multiple"||d==="range","aria-label":zt(O.date,a.options,a)||void 0,className:o[p.MonthGrid],style:v?.[p.MonthGrid]},!t.hideWeekdays&&m.createElement(s.Weekdays,{"data-animated-weekdays":t.animate?"true":void 0,className:o[p.Weekdays],style:v?.[p.Weekdays]},j&&m.createElement(s.WeekNumberHeader,{"aria-label":Kt(a.options),className:o[p.WeekNumberHeader],style:v?.[p.WeekNumberHeader],scope:"col"},P()),Gt.map(w=>m.createElement(s.Weekday,{"aria-label":Zt(w,a.options,a),className:o[p.Weekday],key:String(w),style:v?.[p.Weekday],scope:"col"},A(w,a.options,a)))),m.createElement(s.Weeks,{"data-animated-weeks":t.animate?"true":void 0,className:o[p.Weeks],style:v?.[p.Weeks]},O.weeks.map(w=>m.createElement(s.Week,{className:o[p.Week],key:w.weekNumber,style:v?.[p.Week],week:w},j&&m.createElement(s.WeekNumber,{week:w,style:v?.[p.WeekNumber],"aria-label":Ut(w.weekNumber,{locale:c}),className:o[p.WeekNumber],scope:"row",role:"rowheader"},Y(w.weekNumber,a)),w.days.map(_=>{const{date:z}=_,W=Me(_);if(W[F.focused]=!W.hidden&&!!Ue?.isEqualTo(_),W[L.selected]=we?.(z)||W.selected,He(xe)){const{from:Ne,to:je}=xe;W[L.range_start]=!!(Ne&&je&&a.isSameDay(z,Ne)),W[L.range_end]=!!(Ne&&je&&a.isSameDay(z,je)),W[L.range_middle]=X(xe,z,!0,a)}const ln=Lr(W,v,t.modifiersStyles),dn=Fr(W,o,t.modifiersClassNames),un=!Ge&&!W.hidden?Rt(z,W,a.options,a):void 0;return m.createElement(s.Day,{key:`${a.format(z,"yyyy-MM-dd")}_${a.format(_.displayMonth,"yyyy-MM")}`,day:_,modifiers:W,className:dn.join(" "),style:ln,role:"gridcell","aria-selected":W.selected||void 0,"aria-label":un,"data-day":a.format(z,"yyyy-MM-dd"),"data-month":_.outside?a.format(z,"yyyy-MM"):void 0,"data-selected":W.selected||void 0,"data-disabled":W.disabled||void 0,"data-hidden":W.hidden||void 0,"data-outside":_.outside||void 0,"data-focused":W.focused||void 0,"data-today":W.today||void 0},!W.hidden&&Ge?m.createElement(s.DayButton,{className:o[p.DayButton],style:v?.[p.DayButton],type:"button",day:_,modifiers:W,disabled:W.disabled||void 0,tabIndex:Pt(_)?0:-1,"aria-label":At(z,W,a.options,a),onClick:Vt(_,W),onBlur:Jt(_,W),onFocus:Qt(_,W),onKeyDown:Xt(_,W),onMouseEnter:en(_,W),onMouseLeave:tn(_,W)},M(z,a.options,a)):!W.hidden&&M(_.date,a.options,a))})))))))),t.footer&&m.createElement(s.Footer,{className:o[p.Footer],style:v?.[p.Footer],role:"status","aria-live":"polite"},t.footer)))}function Io({className:e,classNames:t,showOutsideDays:s=!0,captionLayout:n="label",buttonVariant:r="ghost",formatters:a,components:c,...o}){const l=$e();return i.jsx(_o,{showOutsideDays:s,className:E("bg-white group/calendar p-3 [--cell-size:--spacing(8)] [[data-slot=card-content]_&]:bg-transparent [[data-slot=popover-content]_&]:bg-transparent dark:bg-gray-950",String.raw`rtl:**:[.rdp-button\_next>svg]:rotate-180`,String.raw`rtl:**:[.rdp-button\_previous>svg]:rotate-180`,e),captionLayout:n,formatters:{formatMonthDropdown:d=>d.toLocaleString("default",{month:"short"}),...a},classNames:{root:E("w-fit",l.root),months:E("flex gap-4 flex-col md:flex-row relative",l.months),month:E("flex flex-col w-full gap-4",l.month),nav:E("flex items-center gap-1 w-full absolute top-0 inset-x-0 justify-between",l.nav),button_previous:E(Xe({variant:r}),"size-(--cell-size) aria-disabled:opacity-50 p-0 select-none",l.button_previous),button_next:E(Xe({variant:r}),"size-(--cell-size) aria-disabled:opacity-50 p-0 select-none",l.button_next),month_caption:E("flex items-center justify-center h-(--cell-size) w-full px-(--cell-size)",l.month_caption),dropdowns:E("w-full flex items-center text-sm font-medium justify-center h-(--cell-size) gap-1.5",l.dropdowns),dropdown_root:E("relative has-focus:border-gray-950 border border-gray-200 shadow-xs has-focus:ring-gray-950/50 has-focus:ring-[3px] rounded-md dark:has-focus:border-gray-300 dark:border-gray-800 dark:has-focus:ring-gray-300/50",l.dropdown_root),dropdown:E("absolute bg-white inset-0 opacity-0 dark:bg-gray-950",l.dropdown),caption_label:E("select-none font-medium",n==="label"?"text-sm":"rounded-md pl-2 pr-1 flex items-center gap-1 text-sm h-8 [&>svg]:text-gray-500 [&>svg]:size-3.5 dark:[&>svg]:text-gray-400",l.caption_label),table:"w-full border-collapse",weekdays:E("flex",l.weekdays),weekday:E("text-gray-500 rounded-md flex-1 font-normal text-[0.8rem] select-none dark:text-gray-400",l.weekday),week:E("flex w-full mt-2",l.week),week_number_header:E("select-none w-(--cell-size)",l.week_number_header),week_number:E("text-[0.8rem] select-none text-gray-500 dark:text-gray-400",l.week_number),day:E("relative w-full h-full p-0 text-center [&:first-child[data-selected=true]_button]:rounded-l-md [&:last-child[data-selected=true]_button]:rounded-r-md group/day aspect-square select-none",l.day),range_start:E("rounded-l-md bg-gray-100 dark:bg-gray-800",l.range_start),range_middle:E("rounded-none",l.range_middle),range_end:E("rounded-r-md bg-gray-100 dark:bg-gray-800",l.range_end),today:E("bg-gray-100 text-gray-900 rounded-md data-[selected=true]:rounded-none dark:bg-gray-800 dark:text-gray-50",l.today),outside:E("text-gray-500 aria-selected:text-gray-500 dark:text-gray-400 dark:aria-selected:text-gray-400",l.outside),disabled:E("text-gray-500 opacity-50 dark:text-gray-400",l.disabled),hidden:E("invisible",l.hidden),...t},components:{Root:({className:d,rootRef:f,...u})=>i.jsx("div",{"data-slot":"calendar",ref:f,className:E(d),...u}),Chevron:({className:d,orientation:f,...u})=>f==="left"?i.jsx($n,{className:E("size-4",d),...u}):f==="right"?i.jsx(Zn,{className:E("size-4",d),...u}):i.jsx(ne,{className:E("size-4",d),...u}),DayButton:Fo,WeekNumber:({children:d,...f})=>i.jsx("td",{...f,children:i.jsx("div",{className:"flex size-(--cell-size) items-center justify-center text-center",children:d})}),...c},...o})}function Fo({className:e,day:t,modifiers:s,...n}){const r=$e(),a=m.useRef(null);return m.useEffect(()=>{s.focused&&a.current?.focus()},[s.focused]),i.jsx(H,{ref:a,variant:"ghost",size:"icon","data-day":t.date.toLocaleDateString(),"data-selected-single":s.selected&&!s.range_start&&!s.range_end&&!s.range_middle,"data-range-start":s.range_start,"data-range-end":s.range_end,"data-range-middle":s.range_middle,className:E("data-[selected-single=true]:bg-gray-900 data-[selected-single=true]:text-gray-50 data-[range-middle=true]:bg-gray-100 data-[range-middle=true]:text-gray-900 data-[range-start=true]:bg-gray-900 data-[range-start=true]:text-gray-50 data-[range-end=true]:bg-gray-900 data-[range-end=true]:text-gray-50 group-data-[focused=true]/day:border-ring group-data-[focused=true]/day:ring-ring/50 dark:hover:text-gray-900 flex aspect-square size-auto w-full min-w-(--cell-size) flex-col gap-1 leading-none font-normal group-data-[focused=true]/day:relative group-data-[focused=true]/day:z-10 group-data-[focused=true]/day:ring-[3px] data-[range-end=true]:rounded-md data-[range-end=true]:rounded-r-md data-[range-middle=true]:rounded-none data-[range-start=true]:rounded-md data-[range-start=true]:rounded-l-md [&>span]:text-xs [&>span]:opacity-70 dark:data-[selected-single=true]:bg-gray-50 dark:data-[selected-single=true]:text-gray-900 dark:data-[range-middle=true]:bg-gray-800 dark:data-[range-middle=true]:text-gray-50 dark:data-[range-start=true]:bg-gray-50 dark:data-[range-start=true]:text-gray-900 dark:data-[range-end=true]:bg-gray-50 dark:data-[range-end=true]:text-gray-900 dark:dark:hover:text-gray-50",r.day,e),...n})}function Fe(e){return e?le(e,"yyyy-MM-dd"):""}function Yo(e){return e?!Number.isNaN(e.getTime()):!1}function Bo({value:e,onChange:t,disabled:s,...n}){const[r,a]=m.useState(!1),[c,o]=m.useState(e),[l,d]=m.useState(Fe(e));return S.useEffect(()=>{e&&d(Fe(e))},[e]),i.jsxs("div",{className:"relative flex gap-2",children:[i.jsx(xt,{...n,disabled:s,value:l,onChange:f=>{d(f.target.value);const u=f.target.value?new Date(f.target.value):void 0;Yo(u)&&(t?.(u),o(u))},onKeyDown:f=>{f.key==="ArrowDown"&&(f.preventDefault(),a(!0))}}),i.jsxs(Un,{open:r,onOpenChange:a,children:[i.jsx(Kn,{asChild:!0,children:i.jsxs(H,{id:"date-picker",variant:"ghost",className:"absolute top-1/2 right-2 size-6 -translate-y-1/2",disabled:s,children:[i.jsx(Ln,{className:"size-3.5"}),i.jsx("span",{className:"sr-only",children:"Select date"})]})}),i.jsx(Gn,{className:"w-auto overflow-hidden p-0",align:"end",alignOffset:-8,sideOffset:10,children:i.jsx(Io,{mode:"single",selected:e,captionLayout:"dropdown",month:c,onMonthChange:o,onSelect:f=>{t?.(f),d(Fe(f??void 0)),a(!1)}})})]})]})}var Ye={exports:{}},Be,ct;function Po(){if(ct)return Be;ct=1;var e="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED";return Be=e,Be}var Pe,lt;function Ao(){if(lt)return Pe;lt=1;var e=Po();function t(){}function s(){}return s.resetWarningCache=t,Pe=function(){function n(c,o,l,d,f,u){if(u!==e){var h=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw h.name="Invariant Violation",h}}n.isRequired=n;function r(){return n}var a={array:n,bigint:n,bool:n,func:n,number:n,object:n,string:n,symbol:n,any:n,arrayOf:r,element:n,elementType:n,instanceOf:r,node:n,objectOf:r,oneOf:r,oneOfType:r,shape:r,exact:r,checkPropTypes:s,resetWarningCache:t};return a.PropTypes=a,a},Pe}var dt;function Ro(){return dt||(dt=1,Ye.exports=Ao()()),Ye.exports}var zo=Ro();const sa=Vn(zo),qo=({close:e,transactionID:t,onChange:s})=>t?i.jsx(Qn,{modalSize:"fit-content",position:"bottom",title:i.jsxs("div",{className:"flex flex-row mx-3 pt-3 sm:text-1xl gap-10",children:[i.jsx("h1",{className:"sm:text-2xl font-small text-gray-900",children:"Edit Transaction:"}),i.jsxs("div",{className:"flex flex-row gap-2",children:["ID: ",t,i.jsx(Jn,{content:t}),i.jsx(Zs,{transactionId:t})]})]}),opened:!!t,onClose:e,children:i.jsx(Us,{transactionID:t,onDone:e,onChange:s})}):null,Ho=({onDone:e,transactionId:t,chargeId:s})=>{const[n,r]=S.useState(!1),[{data:a,fetching:c}]=mt({query:Xn,pause:!t,variables:{transactionId:t}}),o=a?.transactionsByIDs[0];function l(){r(!1),e?.()}return i.jsxs(es,{open:n,onOpenChange:r,children:[i.jsx(ts,{asChild:!0,children:i.jsx(ut,{label:"Insert Related Misc Expense",children:i.jsx(H,{variant:"ghost",size:"icon",className:"size-7.5",disabled:c,children:i.jsx(Ds,{className:"size-5"})})})}),i.jsxs(ns,{className:"sm:max-w-[425px]",children:[i.jsx(ss,{children:i.jsx(rs,{children:"Insert Misc Expense"})}),o&&i.jsx(Gs,{onDone:l,chargeId:s,defaultValues:{amount:o?.amount.raw?Math.abs(o?.amount.raw):void 0,currency:o?.amount.currency,invoiceDate:o?.eventDate,valueDate:o?.exactEffectiveDate||o?.effectiveDate?new Date(o.exactEffectiveDate??o.effectiveDate):void 0,creditorId:(o?.amount.raw??0)>0?o?.counterparty?.id:void 0,debtorId:(o?.amount.raw??0)<0?o?.counterparty?.id:void 0}})]})]})},$o=({transaction:e})=>{const t="effectiveDate"in e?e.effectiveDate:void 0;return i.jsxs("div",{className:"flex flex-col justify-center",children:[i.jsx("div",{children:t&&le(new Date(t),"dd/MM/yy")}),e.sourceEffectiveDate&&i.jsxs("div",{className:"text-xs text-gray-500",children:["(Originally ",le(new Date(e.sourceEffectiveDate),"dd/MM/yy"),")"]})]})},Zo=({transaction:e})=>{const t="eventDate"in e?e.eventDate:void 0;return i.jsx("div",{className:"flex flex-col justify-center",children:t&&le(new Date(t),"dd/MM/yy")})},Uo=({transaction:e})=>{const t="amount"in e?e.amount:void 0;return i.jsxs("div",{style:{color:Number(t?.raw)>0?"green":"red",whiteSpace:"nowrap"},children:[t?.formatted,i.jsx("br",{}),e.cryptoExchangeRate&&i.jsxs("span",{style:{color:"gray",marginLeft:"0.5rem"},children:[`(Rate: ${e.cryptoExchangeRate.rate})`,i.jsx("br",{}),t?.raw?`${os(t.raw*e.cryptoExchangeRate.rate)}$`:null]})]})},Ko=({transaction:e})=>{const{account:t}=e,s=t.type,n=t.name;return i.jsxs("div",{className:"flex flex-col justify-center",children:[i.jsx("p",{children:s}),i.jsx("p",{children:n})]})},Lo=({transaction:e})=>{const t="sourceDescription"in e?e.sourceDescription:"Missing";return i.jsx("div",{className:"flex flex-wrap",children:i.jsx("div",{className:"flex flex-col justify-center",children:t})})},Go=({transaction:e})=>i.jsx("div",{className:"flex flex-wrap",children:i.jsx("div",{className:"flex flex-col justify-center",children:e.referenceKey})});function Vo({transaction:e,onChange:t}){const{id:s,counterparty:n,missingInfoSuggestions:r,id:a,sourceDescription:c,enableEdit:o}=e,l=!!r?.business&&o,d=l?r?.business?.name:"Missing",f=l?r?.business?.id:null,u=n?.name??d,[h,y]=S.useState(!1),{updateTransaction:C,fetching:x}=qe(),g=S.useCallback(async N=>{await C({transactionId:a,fields:{counterpartyId:N}}),y(!0)},[a,C]),k=S.useCallback(async N=>{await g(N),t?.()},[g,t]),{selectableBusinesses:T,fetching:b}=as(),[j,v]=S.useState(f??null),[D,M]=S.useState(c);return i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"flex flex-wrap flex-col justify-center",children:n?.id?i.jsx(ft,{to:ht.BUSINESSES.DETAIL(n.id),target:"_blank",rel:"noreferrer",onClick:N=>N.stopPropagation(),className:"inline-flex items-center font-semibold",children:u}):i.jsxs(i.Fragment,{children:[i.jsx(is,{options:T,value:j,onChange:v,search:D,onSearchChange:M,placeholder:"Choose or create a business",empty:D?i.jsx(cs,{description:D,onAdd:k}):null}),i.jsx(ks,{content:"Approve",children:i.jsx(H,{variant:"outline",size:"icon",onClick:()=>j&&g(j),disabled:x||b||!j,children:i.jsx(ls,{className:"size-4"})})})]})}),i.jsx(bs,{transactionId:s,counterpartyId:n?.id??j,open:h,onOpenChange:y,onClose:t})]})}const Ae=[{accessorKey:"counterparty.name",header:({column:e})=>i.jsxs(H,{variant:"ghost",children:["Counterparty",e.getIsSorted()&&(e.getIsSorted()==="asc"?i.jsx(ae,{className:"ml-2 h-4 w-4"}):i.jsx(ne,{className:"ml-2 h-4 w-4"}))]}),cell:({row:e})=>i.jsx(Vo,{transaction:e.original})},{accessorKey:"eventDate",sortingFn:e=>"eventDate"in e.original&&e.original.eventDate?new Date(e.original.eventDate).getTime():0,header:({column:e})=>i.jsxs(H,{variant:"ghost",children:["Event Date",e.getIsSorted()&&(e.getIsSorted()==="asc"?i.jsx(ae,{className:"ml-2 h-4 w-4"}):i.jsx(ne,{className:"ml-2 h-4 w-4"}))]}),cell:({row:e})=>i.jsx(Zo,{transaction:e.original})},{accessorKey:"effectiveDate",sortingFn:e=>"effectiveDate"in e.original&&e.original.effectiveDate?new Date(e.original.effectiveDate).getTime():0,header:({column:e})=>i.jsxs(H,{variant:"ghost",children:["Debit Date",e.getIsSorted()&&(e.getIsSorted()==="asc"?i.jsx(ae,{className:"ml-2 h-4 w-4"}):i.jsx(ne,{className:"ml-2 h-4 w-4"}))]}),cell:({row:e})=>i.jsx($o,{transaction:e.original})},{accessorKey:"amount.raw",header:({column:e})=>i.jsxs(H,{variant:"ghost",children:["Amount",e.getIsSorted()&&(e.getIsSorted()==="asc"?i.jsx(ae,{className:"ml-2 h-4 w-4"}):i.jsx(ne,{className:"ml-2 h-4 w-4"}))]}),cell:({row:e})=>i.jsx(Uo,{transaction:e.original})},{accessorKey:"account.name",header:({column:e})=>i.jsxs(H,{variant:"ghost",children:["Account",e.getIsSorted()&&(e.getIsSorted()==="asc"?i.jsx(ae,{className:"ml-2 h-4 w-4"}):i.jsx(ne,{className:"ml-2 h-4 w-4"}))]}),cell:({row:e})=>i.jsx(Ko,{transaction:e.original})},{accessorKey:"sourceDescription",header:({column:e})=>i.jsxs(H,{variant:"ghost",children:["Description",e.getIsSorted()&&(e.getIsSorted()==="asc"?i.jsx(ae,{className:"ml-2 h-4 w-4"}):i.jsx(ne,{className:"ml-2 h-4 w-4"}))]}),cell:({row:e})=>i.jsx(Lo,{transaction:e.original})},{accessorKey:"referenceKey",header:({column:e})=>i.jsxs(H,{variant:"ghost",children:["Reference#",e.getIsSorted()&&(e.getIsSorted()==="asc"?i.jsx(ae,{className:"ml-2 h-4 w-4"}):i.jsx(ne,{className:"ml-2 h-4 w-4"}))]}),cell:({row:e})=>i.jsx(Go,{transaction:e.original})}],Qo={accessorKey:"id",header:"Actions",cell:({row:e})=>e.original.enableEdit?i.jsxs(i.Fragment,{children:[i.jsx(ds,{onClick:e.original.editTransaction}),i.jsx(Ho,{chargeId:e.original.chargeId,transactionId:e.original.id,onDone:e.original.onUpdate})]}):e.original.enableChargeLink?i.jsx($s,{chargeId:e.original.chargeId}):null},ra=({transactionsProps:e,onChange:t=()=>{},enableEdit:s,enableChargeLink:n})=>{const[r,a]=S.useState(void 0),[c,o]=S.useState([]),l=S.useMemo(()=>e.map(h=>us(fs,h)),[e]),d=S.useMemo(()=>l?.map(h=>({...h,editTransaction:()=>a(h.id),onUpdate:t,enableEdit:s,enableChargeLink:n})),[l,t,s,n]),f=S.useMemo(()=>s||n?[...Ae,Qo]:Ae,[s,n]),u=hs({data:d,columns:f,getCoreRowModel:ys(),onSortingChange:o,getSortedRowModel:ms(),state:{sorting:c}});return i.jsxs(i.Fragment,{children:[i.jsxs(gs,{children:[i.jsx(ps,{children:u.getHeaderGroups().map(h=>i.jsx(We,{children:h.headers.map(y=>i.jsx(vs,{colSpan:y.colSpan,children:y.isPlaceholder?null:et(y.column.columnDef.header,y.getContext())},y.id))},h.id))}),i.jsx(xs,{children:u.getRowModel().rows?.length?u.getRowModel().rows.map(h=>i.jsx(We,{children:h.getVisibleCells().map(y=>i.jsx(tt,{children:et(y.column.columnDef.cell,y.getContext())},y.id))},h.id)):i.jsx(We,{children:i.jsx(tt,{colSpan:Ae.length,className:"h-24 text-center",children:"No results."})})})]}),i.jsx(qo,{transactionID:r,close:()=>a(void 0),onChange:t})]})};export{Uo as A,Vo as C,$o as D,ws as E,Gs as I,Qs as M,sa as P,Go as S,ra as T,Zo as a,Ko as b,Lo as c,$s as d};
@@ -1 +1 @@
1
- import{u as x,bu as h,J as T,r,j as s,bn as g,bv as j,F as B,T as w,ah as C,L as b,au as v,bw as E}from"./index-DPvrbbz9.js";import{E as P,P as y,C as L}from"./editable-business-trip-xFRu5fSA.js";import{I as F}from"./insert-business-trip-modal-BHY3QQup.js";import{P as I}from"./page-layout-SHFb6rY4.js";import{A as m}from"./summary-DwX_dmjr.js";import"./list-plus-ZvPwjqZn.js";import"./Table-DTU12O53.js";import"./toggle-expansion-button-Bh24n-cz.js";import"./panel-top-open-C3Q9X7Tg.js";import"./MultiSelect-D1XVjXLN.js";import"./similar-transactions-modal-zQY2R-sr.js";import"./tooltip-BaULIFLC.js";import"./create-event-handler-BiA-1lGu.js";const S=({data:u,isOpened:o,shouldValidate:l})=>{const e=T(j,u),[{data:i,fetching:a}]=x({pause:!l,query:h,variables:{id:e.id}}),d=r.useMemo(()=>l?i?.businessTrip&&(i.businessTrip.uncategorizedTransactions?.length||i?.businessTrip.summary?.errors?.length):!1,[i]),c=d||e?.accountantApproval!=="APPROVED";return s.jsxs(m.Item,{value:e.id,children:[s.jsx(m.Control,{children:s.jsx(g,{inline:!0,size:12,processing:a,disabled:!c,color:d?"red":"yellow",zIndex:"auto",children:e.name})}),s.jsx(m.Panel,{children:o&&s.jsx(P,{tripId:e.id,isExtended:!0},e.id)})]})},_=()=>{const{setFiltersContext:u}=r.useContext(B),[o,l]=r.useState([]),[e,i]=r.useState(!1),[{data:a,fetching:d}]=x({query:E});r.useEffect(()=>{if(!a?.allBusinessTrips?.length){l([]);return}const t=a.allBusinessTrips.sort((n,p)=>n.dates?.start&&p.dates?.start?n.dates.start<p.dates.start?1:-1:n.dates?.start?-1:p.dates?.start?1:n.name.toLocaleLowerCase()<p.name.toLocaleLowerCase()?-1:1);l(t)},[a?.allBusinessTrips]);const[c,f]=r.useState([]);return r.useEffect(()=>{u(s.jsxs("div",{className:"flex flex-row gap-x-5",children:[s.jsx(F,{}),s.jsx(w,{label:"Toggle business trips validation",children:s.jsxs("div",{className:"flex flex-row items-center gap-x-2",children:[s.jsx(C,{checked:e??!1,onCheckedChange:t=>i(t)}),s.jsx("span",{className:"text-sm text-gray-500",children:"Validate"})]})}),s.jsx(y,{filename:"business_trips"})]}))},[a,d,u,e]),s.jsx(I,{title:"Business Trips",description:"Manage business trips",children:o.length===0&&d?s.jsx(b,{className:"h-10 w-10 animate-spin mr-2 self-center"}):s.jsx(L,{children:s.jsx(m,{className:"w-full",multiple:!0,value:c,onChange:f,chevron:s.jsx(v,{size:"1rem"}),styles:{chevron:{"&[data-rotate]":{transform:"rotate(45deg)"}}},children:o?.map(t=>s.jsx(S,{data:o.find(n=>n.id===t.id),shouldValidate:e,isOpened:c.includes(t.id)},t.id))})})})};export{_ as BusinessTrips};
1
+ import{u as x,bu as h,J as T,r,j as s,bn as g,bv as j,F as B,T as w,ah as C,L as b,au as v,bw as E}from"./index-B2_EbsaK.js";import{E as P,P as y,C as L}from"./editable-business-trip-CRiuNdbP.js";import{I as F}from"./insert-business-trip-modal-BwOnvw7X.js";import{P as I}from"./page-layout-C0GJoVTR.js";import{A as m}from"./summary-DuWhfNdL.js";import"./list-plus-CGvSlslE.js";import"./Table-CYqAEQfS.js";import"./toggle-expansion-button-41Ejffq3.js";import"./panel-top-open-BFNhAe3f.js";import"./MultiSelect-CBtq6WUv.js";import"./similar-transactions-modal-nk8VHEtX.js";import"./tooltip-lhMCop8U.js";import"./create-event-handler-BiA-1lGu.js";const S=({data:u,isOpened:o,shouldValidate:l})=>{const e=T(j,u),[{data:i,fetching:a}]=x({pause:!l,query:h,variables:{id:e.id}}),d=r.useMemo(()=>l?i?.businessTrip&&(i.businessTrip.uncategorizedTransactions?.length||i?.businessTrip.summary?.errors?.length):!1,[i]),c=d||e?.accountantApproval!=="APPROVED";return s.jsxs(m.Item,{value:e.id,children:[s.jsx(m.Control,{children:s.jsx(g,{inline:!0,size:12,processing:a,disabled:!c,color:d?"red":"yellow",zIndex:"auto",children:e.name})}),s.jsx(m.Panel,{children:o&&s.jsx(P,{tripId:e.id,isExtended:!0},e.id)})]})},_=()=>{const{setFiltersContext:u}=r.useContext(B),[o,l]=r.useState([]),[e,i]=r.useState(!1),[{data:a,fetching:d}]=x({query:E});r.useEffect(()=>{if(!a?.allBusinessTrips?.length){l([]);return}const t=a.allBusinessTrips.sort((n,p)=>n.dates?.start&&p.dates?.start?n.dates.start<p.dates.start?1:-1:n.dates?.start?-1:p.dates?.start?1:n.name.toLocaleLowerCase()<p.name.toLocaleLowerCase()?-1:1);l(t)},[a?.allBusinessTrips]);const[c,f]=r.useState([]);return r.useEffect(()=>{u(s.jsxs("div",{className:"flex flex-row gap-x-5",children:[s.jsx(F,{}),s.jsx(w,{label:"Toggle business trips validation",children:s.jsxs("div",{className:"flex flex-row items-center gap-x-2",children:[s.jsx(C,{checked:e??!1,onCheckedChange:t=>i(t)}),s.jsx("span",{className:"text-sm text-gray-500",children:"Validate"})]})}),s.jsx(y,{filename:"business_trips"})]}))},[a,d,u,e]),s.jsx(I,{title:"Business Trips",description:"Manage business trips",children:o.length===0&&d?s.jsx(b,{className:"h-10 w-10 animate-spin mr-2 self-center"}):s.jsx(L,{children:s.jsx(m,{className:"w-full",multiple:!0,value:c,onChange:f,chevron:s.jsx(v,{size:"1rem"}),styles:{chevron:{"&[data-rotate]":{transform:"rotate(45deg)"}}},children:o?.map(t=>s.jsx(S,{data:o.find(n=>n.id===t.id),shouldValidate:e,isOpened:c.includes(t.id)},t.id))})})})};export{_ as BusinessTrips};
@@ -1 +1 @@
1
- import{g as v,hB as B,r as u,t as h,i as F,aj as H,j as e,X as C,Y as j,Z as f,_ as p,I as L,$ as y,a0 as S,bp as V,bs as z,as as Q,ah as _,D,aO as E,B as m,z as M,aP as R,aQ as A,G as O,V as P,hC as G,bU as K,u as $,hD as X,L as k,F as Y,cQ as Z,cT as W,cU as J,cV as T,cW as ee,cX as b,cY as se,cZ as w,hE as te,d3 as ae,d4 as re,d5 as oe}from"./index-DPvrbbz9.js";import{D as ne}from"./data-table-pagination-DtnUvTOC.js";import{P as ie}from"./page-layout-SHFb6rY4.js";import{A as N}from"./arrow-up-down-DkEXGAin.js";const de="insertTaxCategory",ce=()=>{const[{fetching:s},n]=v(B),t=u.useCallback(async a=>{const d="Error creating tax category",r=de;h.loading("Adding Tax Category",{id:r});try{const i=await n(a),l=F(i,d,r);if(l)return h.success("Success",{id:r,description:`${l.insertTaxCategory.name} was created`}),l.insertTaxCategory}catch(i){console.error(`${d}: ${i}`),h.error("Error",{id:r,description:d,duration:1e5,closeButton:!0})}},[n]);return{fetching:s,insertTaxCategory:t}};function U({formManager:s,setFetching:n,isInsert:t}){const{control:a,watch:d,setValue:r}=s,{selectableSortCodes:i,fetching:l,sortCodes:x}=H();u.useEffect(()=>{n(l)},[n,l]);const c=d("sortCode");return u.useEffect(()=>{if(c){const o=x.find(g=>g.key===c);o?.defaultIrsCode&&r("irsCode",o.defaultIrsCode,{shouldDirty:!0})}},[c,x,r]),e.jsxs(e.Fragment,{children:[e.jsx(C,{name:"name",control:a,rules:{required:"Required",minLength:{value:2,message:"Must be at least 2 characters"}},render:({field:o,fieldState:g})=>e.jsxs(j,{children:[e.jsx(f,{children:"Name"}),e.jsx(p,{children:e.jsx(L,{...o,value:o.value??void 0,required:!0,className:t?"":y(g)})}),e.jsx(S,{})]})}),e.jsx(V,{name:"sortCode",control:a,render:({field:o,fieldState:g})=>e.jsx(z,{...o,onChange:q=>{o.onChange(Number(q))},data:i,value:o.value?.toString(),disabled:l,label:"Sort Code",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,className:t?"":y(g)})}),e.jsx(C,{name:"irsCode",control:a,render:({field:o,fieldState:g})=>e.jsxs(j,{children:[e.jsx(f,{children:"IRS Code"}),e.jsx(p,{children:e.jsx(Q,{...o,className:t?"":y(g),value:o.value??void 0,hideControls:!0,decimalScale:0})}),e.jsx(S,{})]})}),e.jsx(C,{control:a,name:"taxExcluded",render:({field:o})=>e.jsxs(j,{className:"flex flex-row items-center justify-between",children:[e.jsx("div",{className:"space-y-0.5",children:e.jsx(f,{children:"Tax excluded category"})}),e.jsx(p,{children:e.jsx(_,{onCheckedChange:o.onChange,checked:o.value??void 0})})]})})]})}function le({onAdd:s}){const[n,t]=u.useState(!1);return e.jsxs(D,{open:n,onOpenChange:t,children:[e.jsx(E,{asChild:!0,children:e.jsx(m,{children:"Add Tax Category"})}),e.jsxs(M,{className:"w-[90vw] max-w-screen-md",children:[e.jsx(R,{children:e.jsx(A,{children:"Add New Tax Category"})}),e.jsx(xe,{close:()=>t(!1),onAdd:s})]})]})}function xe({close:s,onAdd:n}){const t=O({}),{handleSubmit:a}=t,[d,r]=u.useState(!1),{insertTaxCategory:i,fetching:l}=ce(),x=c=>{c.sortCode&&=parseInt(c.sortCode.toString()),i({fields:c}).then(o=>{o?.id&&(n?.(o.id),s())})};return e.jsx(P,{...t,children:e.jsxs("form",{onSubmit:a(x),children:[e.jsx("div",{className:"flex flex-col gap-4 my-4",children:e.jsx(U,{isInsert:!0,formManager:t,setFetching:r})}),e.jsx("div",{className:"flex justify-end mt-4",children:e.jsx(m,{type:"submit",disabled:l||d,children:"Add Tax Category"})})]})})}const ue="updateTaxCategory",ge=()=>{const[{fetching:s},n]=v(G),t=u.useCallback(async a=>{const d="Error updating tax category",r=`${ue}-${a.taxCategoryId}`;h.loading("Uploading Tax Category",{id:r});try{const i=await n(a),l=F(i,d,r,"updateTaxCategory");if(l)return h.success("Success",{id:r,description:`${l.updateTaxCategory.name} was updated`}),l.updateTaxCategory}catch(i){console.error(`${d}: ${i}`),h.error("Error",{id:r,description:d,duration:1e5,closeButton:!0})}},[n]);return{fetching:s,updateTaxCategory:t}};function he({taxCategoryId:s,onAdd:n}){const[t,a]=u.useState(!1);return e.jsxs(D,{open:t,onOpenChange:a,children:[e.jsx(E,{asChild:!0,children:e.jsx(m,{variant:"outline",size:"icon",children:e.jsx(K,{})})}),e.jsxs(M,{className:"w-[400px] max-w-screen-md",children:[e.jsx(R,{children:e.jsx(A,{children:"Edit Tax Category"})}),e.jsx(me,{taxCategoryId:s,close:()=>a(!1),onAdd:n})]})]})}function me({taxCategoryId:s,close:n,onAdd:t}){const[{data:a,fetching:d}]=$({query:X,variables:{id:s}}),r=a?.taxCategory;return!r&&!d&&h.error("Error",{description:"Couldn'nt find tax category"}),d?e.jsx(k,{className:"h-10 w-10 animate-spin"}):e.jsx(Ce,{taxCategory:r,close:n,onAdd:t})}function Ce({taxCategory:s,close:n,onAdd:t}){const a=O({defaultValues:{sortCode:s.sortCode?.key,name:s.name,irsCode:s.irsCode}}),{handleSubmit:d}=a,[r,i]=u.useState(!1),{updateTaxCategory:l,fetching:x}=ge(),c=o=>{o.sortCode&&=parseInt(o.sortCode.toString()),l({fields:o,taxCategoryId:s.id}).then(g=>{g?.id&&(t?.(g.id),n())})};return e.jsx(P,{...a,children:e.jsxs("form",{onSubmit:d(c),children:[e.jsx("div",{className:"flex flex-col gap-4 my-4",children:e.jsx(U,{isInsert:!1,formManager:a,setFetching:i})}),e.jsx("div",{className:"flex justify-end mt-4",children:e.jsx(m,{type:"submit",disabled:x||r,children:"Update"})})]})})}const je=({data:s})=>e.jsx("td",{children:s.name}),fe=({data:s})=>e.jsx("td",{children:s.sortCode?e.jsxs("span",{children:[s.sortCode?.name," (",s.sortCode?.id,")"]}):"N/A"}),I=[{id:"name",accessorKey:"name",cell:({row:s})=>e.jsx(je,{data:s.original}),header:({column:s})=>e.jsxs(m,{variant:"ghost",onClick:()=>s.toggleSorting(s.getIsSorted()==="asc"),children:["Name",e.jsx(N,{})]})},{id:"sortCode",accessorKey:"sortCode.key",cell:({row:s})=>e.jsx(fe,{data:s.original}),header:({column:s})=>e.jsxs(m,{variant:"ghost",onClick:()=>s.toggleSorting(s.getIsSorted()==="asc"),children:["Sort Code",e.jsx(N,{})]})},{id:"edit",cell:({row:s})=>e.jsx(he,{taxCategoryId:s.original.id})}],be=()=>{const[{data:s,fetching:n,error:t},a]=$({query:te}),{setFiltersContext:d}=u.useContext(Y),r=s?.taxCategories??[],i=Z({data:r,columns:I,getCoreRowModel:oe(),getPaginationRowModel:re(),getSortedRowModel:ae(),initialState:{pagination:{pageSize:30}}}),l=i.getPageOptions();return u.useEffect(()=>{d(e.jsx("div",{className:"flex items-center justify-end gap-10 space-x-2 py-4",children:e.jsx("div",{className:"flex items-center justify-between px-2",children:e.jsx(ne,{table:i})})}))},[d,i,l]),u.useEffect(()=>{t&&h.error("Error",{description:"Error fetching tax categories"})},[t]),e.jsx(ie,{title:`Tax Categories (${r.length})`,description:"All tax categories",headerActions:e.jsx(le,{onAdd:()=>a()}),children:n?e.jsx("div",{className:"flex flex-row justify-center",children:e.jsx(k,{className:"h-10 w-10 animate-spin mr-2"})}):e.jsx("div",{className:"flex flex-col gap-4 rounded-md border",children:e.jsxs(W,{children:[e.jsx(J,{children:i.getHeaderGroups().map(x=>e.jsx(T,{children:x.headers.map(c=>e.jsx(ee,{children:c.isPlaceholder?null:b(c.column.columnDef.header,c.getContext())},c.id))},x.id))}),e.jsx(se,{children:i.getRowModel().rows.length===0?e.jsx(T,{children:e.jsx(w,{colSpan:I.length,className:"text-center py-8",children:"No tax categories found"})}):i.getRowModel().rows.map(x=>e.jsx(T,{children:x.getVisibleCells().map(c=>e.jsx(w,{children:b(c.column.columnDef.cell,c.getContext())},c.id))},x.id))})]})})})};export{be as TaxCategories};
1
+ import{g as v,hB as B,r as u,t as h,i as F,aj as H,j as e,X as C,Y as j,Z as f,_ as p,I as L,$ as y,a0 as S,bp as V,bs as z,as as Q,ah as _,D,aO as E,B as m,z as M,aP as R,aQ as A,G as O,V as P,hC as G,bU as K,u as $,hD as X,L as k,F as Y,cQ as Z,cT as W,cU as J,cV as T,cW as ee,cX as b,cY as se,cZ as w,hE as te,d3 as ae,d4 as re,d5 as oe}from"./index-B2_EbsaK.js";import{D as ne}from"./data-table-pagination-CKN0E29f.js";import{P as ie}from"./page-layout-C0GJoVTR.js";import{A as N}from"./arrow-up-down-C61ge4J5.js";const de="insertTaxCategory",ce=()=>{const[{fetching:s},n]=v(B),t=u.useCallback(async a=>{const d="Error creating tax category",r=de;h.loading("Adding Tax Category",{id:r});try{const i=await n(a),l=F(i,d,r);if(l)return h.success("Success",{id:r,description:`${l.insertTaxCategory.name} was created`}),l.insertTaxCategory}catch(i){console.error(`${d}: ${i}`),h.error("Error",{id:r,description:d,duration:1e5,closeButton:!0})}},[n]);return{fetching:s,insertTaxCategory:t}};function U({formManager:s,setFetching:n,isInsert:t}){const{control:a,watch:d,setValue:r}=s,{selectableSortCodes:i,fetching:l,sortCodes:x}=H();u.useEffect(()=>{n(l)},[n,l]);const c=d("sortCode");return u.useEffect(()=>{if(c){const o=x.find(g=>g.key===c);o?.defaultIrsCode&&r("irsCode",o.defaultIrsCode,{shouldDirty:!0})}},[c,x,r]),e.jsxs(e.Fragment,{children:[e.jsx(C,{name:"name",control:a,rules:{required:"Required",minLength:{value:2,message:"Must be at least 2 characters"}},render:({field:o,fieldState:g})=>e.jsxs(j,{children:[e.jsx(f,{children:"Name"}),e.jsx(p,{children:e.jsx(L,{...o,value:o.value??void 0,required:!0,className:t?"":y(g)})}),e.jsx(S,{})]})}),e.jsx(V,{name:"sortCode",control:a,render:({field:o,fieldState:g})=>e.jsx(z,{...o,onChange:q=>{o.onChange(Number(q))},data:i,value:o.value?.toString(),disabled:l,label:"Sort Code",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,className:t?"":y(g)})}),e.jsx(C,{name:"irsCode",control:a,render:({field:o,fieldState:g})=>e.jsxs(j,{children:[e.jsx(f,{children:"IRS Code"}),e.jsx(p,{children:e.jsx(Q,{...o,className:t?"":y(g),value:o.value??void 0,hideControls:!0,decimalScale:0})}),e.jsx(S,{})]})}),e.jsx(C,{control:a,name:"taxExcluded",render:({field:o})=>e.jsxs(j,{className:"flex flex-row items-center justify-between",children:[e.jsx("div",{className:"space-y-0.5",children:e.jsx(f,{children:"Tax excluded category"})}),e.jsx(p,{children:e.jsx(_,{onCheckedChange:o.onChange,checked:o.value??void 0})})]})})]})}function le({onAdd:s}){const[n,t]=u.useState(!1);return e.jsxs(D,{open:n,onOpenChange:t,children:[e.jsx(E,{asChild:!0,children:e.jsx(m,{children:"Add Tax Category"})}),e.jsxs(M,{className:"w-[90vw] max-w-screen-md",children:[e.jsx(R,{children:e.jsx(A,{children:"Add New Tax Category"})}),e.jsx(xe,{close:()=>t(!1),onAdd:s})]})]})}function xe({close:s,onAdd:n}){const t=O({}),{handleSubmit:a}=t,[d,r]=u.useState(!1),{insertTaxCategory:i,fetching:l}=ce(),x=c=>{c.sortCode&&=parseInt(c.sortCode.toString()),i({fields:c}).then(o=>{o?.id&&(n?.(o.id),s())})};return e.jsx(P,{...t,children:e.jsxs("form",{onSubmit:a(x),children:[e.jsx("div",{className:"flex flex-col gap-4 my-4",children:e.jsx(U,{isInsert:!0,formManager:t,setFetching:r})}),e.jsx("div",{className:"flex justify-end mt-4",children:e.jsx(m,{type:"submit",disabled:l||d,children:"Add Tax Category"})})]})})}const ue="updateTaxCategory",ge=()=>{const[{fetching:s},n]=v(G),t=u.useCallback(async a=>{const d="Error updating tax category",r=`${ue}-${a.taxCategoryId}`;h.loading("Uploading Tax Category",{id:r});try{const i=await n(a),l=F(i,d,r,"updateTaxCategory");if(l)return h.success("Success",{id:r,description:`${l.updateTaxCategory.name} was updated`}),l.updateTaxCategory}catch(i){console.error(`${d}: ${i}`),h.error("Error",{id:r,description:d,duration:1e5,closeButton:!0})}},[n]);return{fetching:s,updateTaxCategory:t}};function he({taxCategoryId:s,onAdd:n}){const[t,a]=u.useState(!1);return e.jsxs(D,{open:t,onOpenChange:a,children:[e.jsx(E,{asChild:!0,children:e.jsx(m,{variant:"outline",size:"icon",children:e.jsx(K,{})})}),e.jsxs(M,{className:"w-[400px] max-w-screen-md",children:[e.jsx(R,{children:e.jsx(A,{children:"Edit Tax Category"})}),e.jsx(me,{taxCategoryId:s,close:()=>a(!1),onAdd:n})]})]})}function me({taxCategoryId:s,close:n,onAdd:t}){const[{data:a,fetching:d}]=$({query:X,variables:{id:s}}),r=a?.taxCategory;return!r&&!d&&h.error("Error",{description:"Couldn'nt find tax category"}),d?e.jsx(k,{className:"h-10 w-10 animate-spin"}):e.jsx(Ce,{taxCategory:r,close:n,onAdd:t})}function Ce({taxCategory:s,close:n,onAdd:t}){const a=O({defaultValues:{sortCode:s.sortCode?.key,name:s.name,irsCode:s.irsCode}}),{handleSubmit:d}=a,[r,i]=u.useState(!1),{updateTaxCategory:l,fetching:x}=ge(),c=o=>{o.sortCode&&=parseInt(o.sortCode.toString()),l({fields:o,taxCategoryId:s.id}).then(g=>{g?.id&&(t?.(g.id),n())})};return e.jsx(P,{...a,children:e.jsxs("form",{onSubmit:d(c),children:[e.jsx("div",{className:"flex flex-col gap-4 my-4",children:e.jsx(U,{isInsert:!1,formManager:a,setFetching:i})}),e.jsx("div",{className:"flex justify-end mt-4",children:e.jsx(m,{type:"submit",disabled:x||r,children:"Update"})})]})})}const je=({data:s})=>e.jsx("td",{children:s.name}),fe=({data:s})=>e.jsx("td",{children:s.sortCode?e.jsxs("span",{children:[s.sortCode?.name," (",s.sortCode?.id,")"]}):"N/A"}),I=[{id:"name",accessorKey:"name",cell:({row:s})=>e.jsx(je,{data:s.original}),header:({column:s})=>e.jsxs(m,{variant:"ghost",onClick:()=>s.toggleSorting(s.getIsSorted()==="asc"),children:["Name",e.jsx(N,{})]})},{id:"sortCode",accessorKey:"sortCode.key",cell:({row:s})=>e.jsx(fe,{data:s.original}),header:({column:s})=>e.jsxs(m,{variant:"ghost",onClick:()=>s.toggleSorting(s.getIsSorted()==="asc"),children:["Sort Code",e.jsx(N,{})]})},{id:"edit",cell:({row:s})=>e.jsx(he,{taxCategoryId:s.original.id})}],be=()=>{const[{data:s,fetching:n,error:t},a]=$({query:te}),{setFiltersContext:d}=u.useContext(Y),r=s?.taxCategories??[],i=Z({data:r,columns:I,getCoreRowModel:oe(),getPaginationRowModel:re(),getSortedRowModel:ae(),initialState:{pagination:{pageSize:30}}}),l=i.getPageOptions();return u.useEffect(()=>{d(e.jsx("div",{className:"flex items-center justify-end gap-10 space-x-2 py-4",children:e.jsx("div",{className:"flex items-center justify-between px-2",children:e.jsx(ne,{table:i})})}))},[d,i,l]),u.useEffect(()=>{t&&h.error("Error",{description:"Error fetching tax categories"})},[t]),e.jsx(ie,{title:`Tax Categories (${r.length})`,description:"All tax categories",headerActions:e.jsx(le,{onAdd:()=>a()}),children:n?e.jsx("div",{className:"flex flex-row justify-center",children:e.jsx(k,{className:"h-10 w-10 animate-spin mr-2"})}):e.jsx("div",{className:"flex flex-col gap-4 rounded-md border",children:e.jsxs(W,{children:[e.jsx(J,{children:i.getHeaderGroups().map(x=>e.jsx(T,{children:x.headers.map(c=>e.jsx(ee,{children:c.isPlaceholder?null:b(c.column.columnDef.header,c.getContext())},c.id))},x.id))}),e.jsx(se,{children:i.getRowModel().rows.length===0?e.jsx(T,{children:e.jsx(w,{colSpan:I.length,className:"text-center py-8",children:"No tax categories found"})}):i.getRowModel().rows.map(x=>e.jsx(T,{children:x.getVisibleCells().map(c=>e.jsx(w,{children:b(c.column.columnDef.cell,c.getContext())},c.id))},x.id))})]})})})};export{be as TaxCategories};
@@ -1,4 +1,4 @@
1
- import{cy as fr,ac as gr,ab as ge,j as F,r as kt,bm as pr,B as mr,G as br,x as le,bp as Pn,bq as Dn,br as An,bt as xr,F as _r,u as yr,bl as wr,aN as it,L as vr,cz as Mr}from"./index-DPvrbbz9.js";import{u as io}from"./use-url-query-COmN7DHP.js";import{P as Sr}from"./page-layout-SHFb6rY4.js";import{P as kr}from"./modal-Nvfe-DMu.js";import{F as Cr}from"./funnel-WdA7f2As.js";/*!
1
+ import{cy as fr,ac as gr,ab as ge,j as F,r as kt,bm as pr,B as mr,G as br,x as le,bp as Pn,bq as Dn,br as An,bt as xr,F as _r,u as yr,bl as wr,aN as it,L as vr,cz as Mr}from"./index-B2_EbsaK.js";import{u as io}from"./use-url-query-BPzyQB93.js";import{P as Sr}from"./page-layout-C0GJoVTR.js";import{P as kr}from"./modal-B0uNLang.js";import{F as Cr}from"./funnel-BlaCusqP.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,4 +1,4 @@
1
- import{v as z,r as b,bo as Q,j as e,D as U,aO as W,B as g,z as G,aP as J,aQ as K,b8 as T,al as Z,a_ as R,am as A,an as O,ao as k,ap as E,ar as D,cu as X,J as j,bf as w,fZ as M,f_ as ee,f$ as S,g0 as se,g1 as I,g2 as L,g3 as P,g4 as N,g5 as p,g6 as B,g7 as _,dh as re,g8 as te,ba as ae,bb as le,bc as v,g9 as $,F as de,u as ne,K as oe,N as ce,W as ie,ga as me}from"./index-DPvrbbz9.js";import{F as V}from"./funnel-WdA7f2As.js";import{B as ue}from"./building-2-BcYhLAVP.js";import{S as xe}from"./save-D-W46u2J.js";/**
1
+ import{v as z,r as b,bo as Q,j as e,D as U,aO as W,B as g,z as G,aP as J,aQ as K,b8 as T,al as Z,a_ as R,am as A,an as O,ao as k,ap as E,ar as D,cu as X,J as j,bf as w,fZ as M,f_ as ee,f$ as S,g0 as se,g1 as I,g2 as L,g3 as P,g4 as N,g5 as p,g6 as B,g7 as _,dh as re,g8 as te,ba as ae,bb as le,bc as v,g9 as $,F as de,u as ne,K as oe,N as ce,W as ie,ga as me}from"./index-B2_EbsaK.js";import{F as V}from"./funnel-BlaCusqP.js";import{B as ue}from"./building-2-3KauBrnS.js";import{S as xe}from"./save-qtyyZLc5.js";/**
2
2
  * @license lucide-react v0.548.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.