@accounter/client 0.0.8-alpha-20251029233737-ec3a7806df63c8556b232ea893d0d3855d2c402a → 0.0.8-alpha-20251029235231-f14290dbb5dedec255de3cef292d3b4c5c71298e
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.
- package/CHANGELOG.md +1 -1
- package/dist/assets/{Checkbox-Dkdl2KPL.js → Checkbox-m4EJFPdR.js} +1 -1
- package/dist/assets/{MultiSelect-Cyxk2rHZ.js → MultiSelect-9iwOrNey.js} +1 -1
- package/dist/assets/{Progress-Dz3kmpOR.js → Progress-jpjCOY1T.js} +1 -1
- package/dist/assets/{Table-D9Xe8npl.js → Table-KlqUi970.js} +1 -1
- package/dist/assets/{Typography-B6OkseM2.js → Typography-DcCXHm8f.js} +1 -1
- package/dist/assets/{YearPickerInput-BucWT0nK.js → YearPickerInput-CWNdAJVU.js} +1 -1
- package/dist/assets/{accordion-C9ERQxxl.js → accordion-DyS7JLRn.js} +1 -1
- package/dist/assets/{accountant-approvals-DqA6PQCp.js → accountant-approvals-BPCEe5wp.js} +1 -1
- package/dist/assets/{accounter-table-Bx5lKrE8.js → accounter-table-CdLG0nPv.js} +1 -1
- package/dist/assets/{addDays-CALX0aWH.js → addDays-C65N2SCe.js} +1 -1
- package/dist/assets/{all-charges-B4gOWEXY.js → all-charges-CrhqMOdj.js} +1 -1
- package/dist/assets/{arrow-up-down-DsNx-cif.js → arrow-up-down-B8i8ydxe.js} +1 -1
- package/dist/assets/{building-2-x1AfgsH8.js → building-2-cN3QI06F.js} +1 -1
- package/dist/assets/{business-extended-info-D1TnFaiA.js → business-extended-info-DCsSJJtc.js} +1 -1
- package/dist/assets/{business-header-BUTofpzW.js → business-header-HggV7QvE.js} +1 -1
- package/dist/assets/{business-ledger-filters-D1HRrkmz.js → business-ledger-filters-B9SOs3sR.js} +1 -1
- package/dist/assets/{business-ledger-single-BtjWZG51.js → business-ledger-single-BYrOpHks.js} +1 -1
- package/dist/assets/{business-DNbsyDDm.js → business-nIHEv4T5.js} +1 -1
- package/dist/assets/{business-trip-Ge-CfFL0.js → business-trip-CaVFJEg1.js} +1 -1
- package/dist/assets/{charge-DDcUoeIv.js → charge-XVI9hWTT.js} +1 -1
- package/dist/assets/{charges-filters-_yO8uyNv.js → charges-filters-D2_BKbWX.js} +1 -1
- package/dist/assets/{charges-ledger-validation-DxgBywa5.js → charges-ledger-validation-FYtG72Q6.js} +1 -1
- package/dist/assets/{charges-table-jw3hYGav.js → charges-table-BEP9lXbG.js} +1 -1
- package/dist/assets/{chart-C5brdPZL.js → chart-DrNm6pqY.js} +1 -1
- package/dist/assets/{data-table-pagination-B0x5jC5y.js → data-table-pagination-azA1p3g-.js} +1 -1
- package/dist/assets/{download-csv-button-DpX8ARIH.js → download-csv-button-DsnbHQxU.js} +1 -1
- package/dist/assets/{editable-business-trip-sqyvdP8s.js → editable-business-trip-DuwclYZj.js} +1 -1
- package/dist/assets/{funnel-6jLbjYGX.js → funnel-DT4mmN3u.js} +1 -1
- package/dist/assets/{index-CP96tj1j.js → index-4EzhixKH.js} +1 -1
- package/dist/assets/{index-CVs7a0UT.js → index-B7Rl68zJ.js} +1 -1
- package/dist/assets/{index-B5LyBBYZ.js → index-BMBj2AP4.js} +1 -1
- package/dist/assets/{index-DoLygAFd.js → index-BPrO70_k.js} +1 -1
- package/dist/assets/{index-DOzakCg2.js → index-BTtuW68l.js} +1 -1
- package/dist/assets/{index-CHa6Oypu.js → index-BlKLmORp.js} +1 -1
- package/dist/assets/{index-BKpUH4la.js → index-Bt8Ea12_.js} +1 -1
- package/dist/assets/{index-Cveg7OhP.js → index-BzVbeSlP.js} +1 -1
- package/dist/assets/{index-C4stmrJs.js → index-C1gcTg-z.js} +1 -1
- package/dist/assets/{index-C9fHUfnt.js → index-C3k8jflc.js} +195 -195
- package/dist/assets/{index-BZmRoc6Y.js → index-CXHGrcA4.js} +1 -1
- package/dist/assets/{index-sOFgAguM.js → index-CjH08FXI.js} +1 -1
- package/dist/assets/{index-BnhVZdLt.js → index-CsarR72G.js} +1 -1
- package/dist/assets/{index-CvAQBU8L.js → index-Cy1QJKqT.js} +1 -1
- package/dist/assets/{index-Ba0CN-4T.js → index-DGb4vHzt.js} +1 -1
- package/dist/assets/{index-BsyvCrXc.js → index-DKIBrU0J.js} +1 -1
- package/dist/assets/{index-GGTa2We-.js → index-DTXvsvms.js} +1 -1
- package/dist/assets/{index-Ckws0Mij.js → index-DY9WOuok.js} +1 -1
- package/dist/assets/{index-CGkDGuVg.js → index-KrbE7--b.js} +1 -1
- package/dist/assets/{index-ioC7EoSD.js → index-SMnzi7Aw.js} +1 -1
- package/dist/assets/{index-CTbf4Zzl.js → index-SWslvlxa.js} +1 -1
- package/dist/assets/{index-Bk5Ep2sg.js → index-faGFVNCX.js} +1 -1
- package/dist/assets/{index-DqHa4Uaj.js → index-hM1FptsM.js} +1 -1
- package/dist/assets/{index-kxJit6Qg.js → index-mUNwzNlf.js} +1 -1
- package/dist/assets/{index-BJ6-VFcr.js → index-s6ijvE1i.js} +1 -1
- package/dist/assets/{index.es-CZzNbEFb.js → index.es-BBqsLcyU.js} +1 -1
- package/dist/assets/{insert-business-trip-modal-C3QHG-Hj.js → insert-business-trip-modal-DN3T9OON.js} +1 -1
- package/dist/assets/issue-document-lGktP9-p.js +1 -0
- package/dist/assets/{list-plus-Bopa-Y0W.js → list-plus-2cRRgK1O.js} +1 -1
- package/dist/assets/{login-page-DGx3Nqaj.js → login-page-DSTZWEBe.js} +1 -1
- package/dist/assets/{match-document-modal-D3yH_ZI7.js → match-document-modal-DKRuRsKN.js} +1 -1
- package/dist/assets/{missing-info-charges-DCnTH3uo.js → missing-info-charges-CJZN7U_u.js} +1 -1
- package/dist/assets/{modal-weFgvkj_.js → modal-DNhi-EIe.js} +1 -1
- package/dist/assets/{page-layout-DZOekob-.js → page-layout-x3aFVsg9.js} +1 -1
- package/dist/assets/{page-not-found-C0w0y25P.js → page-not-found-KmbtQYNL.js} +1 -1
- package/dist/assets/{panel-top-open-imelKSS6.js → panel-top-open-B-b6XxK7.js} +1 -1
- package/dist/assets/{pencil-SvSI226Y.js → pencil-6cV3Nfmi.js} +1 -1
- package/dist/assets/{report-commentary-row-ukhFSoXq.js → report-commentary-row-PIhBXrbg.js} +1 -1
- package/dist/assets/{save-9rdeUT73.js → save-CjO_Dmsz.js} +1 -1
- package/dist/assets/{similar-transactions-modal-CNAIbrow.js → similar-transactions-modal-C7aYlzhE.js} +1 -1
- package/dist/assets/{sub-ImDFXoGZ.js → sub-CMuEnyTg.js} +1 -1
- package/dist/assets/subMonths-Cs2weYkL.js +1 -0
- package/dist/assets/{summary-lammmyU_.js → summary-BWbSzpOQ.js} +1 -1
- package/dist/assets/{toggle-expansion-button-COvBOxVQ.js → toggle-expansion-button-B-4w-oFe.js} +1 -1
- package/dist/assets/tooltip-DG_b_ZsV.js +1 -0
- package/dist/assets/{use-url-query-BS26aRC-.js → use-url-query-BOxCMiZm.js} +1 -1
- package/dist/index.html +1 -1
- package/package.json +2 -2
- package/dist/assets/issue-document-DT8nhIz7.js +0 -1
- package/dist/assets/subMonths-CuWsjtWU.js +0 -1
- package/dist/assets/tooltip-D2vdZwho.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{u as x,bx as h,J as T,r,j as s,bq as g,by as j,F as B,T as w,ai as C,L as b,av as v,bz as y}from"./index-
|
|
1
|
+
import{u as x,bx as h,J as T,r,j as s,bq as g,by as j,F as B,T as w,ai as C,L as b,av as v,bz as y}from"./index-C3k8jflc.js";import{E,P,C as L}from"./editable-business-trip-DuwclYZj.js";import{I as F}from"./insert-business-trip-modal-DN3T9OON.js";import{P as I}from"./page-layout-x3aFVsg9.js";import{A as m}from"./summary-BWbSzpOQ.js";import"./list-plus-2cRRgK1O.js";import"./Table-KlqUi970.js";import"./toggle-expansion-button-B-4w-oFe.js";import"./panel-top-open-B-b6XxK7.js";import"./MultiSelect-9iwOrNey.js";import"./similar-transactions-modal-C7aYlzhE.js";import"./tooltip-DG_b_ZsV.js";const S=({data:c,isOpened:o,shouldValidate:l})=>{const e=T(j,c),[{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]),u=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:!u,color:d?"red":"yellow",zIndex:"auto",children:e.name})}),s.jsx(m.Panel,{children:o&&s.jsx(E,{tripId:e.id,isExtended:!0},e.id)})]})},U=()=>{const{setFiltersContext:c}=r.useContext(B),[o,l]=r.useState([]),[e,i]=r.useState(!1),[{data:a,fetching:d}]=x({query:y});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[u,f]=r.useState([]);return r.useEffect(()=>{c(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(P,{filename:"business_trips"})]}))},[a,d,c,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:u,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:u.includes(t.id)},t.id))})})})};export{U as BusinessTrips};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{v as V,g as E,e6 as q,r,t as k,i as F,u as $,e7 as _,j as s,c as L,l as R,B as H,m as Q,n as X}from"./index-
|
|
1
|
+
import{v as V,g as E,e6 as q,r,t as k,i as F,u as $,e7 as _,j as s,c as L,l as R,B as H,m as Q,n as X}from"./index-C3k8jflc.js";import{c as G}from"./charges-table-BEP9lXbG.js";import{C as J,M as K}from"./Checkbox-m4EJFPdR.js";/**
|
|
2
2
|
* @license lucide-react v0.548.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{r as u,j as e,x as v,J as R,gf as M,F as $,u as k,cT as B,L as P,cW as T,cX as V,cY as d,cZ as L,c_ as C,c$ as Y,d0 as t,gg as S,d7 as K,d8 as O,dH as H,aO as z}from"./index-
|
|
1
|
+
import{r as u,j as e,x as v,J as R,gf as M,F as $,u as k,cT as B,L as P,cW as T,cX as V,cY as d,cZ as L,c_ as C,c$ as Y,d0 as t,gg as S,d7 as K,d8 as O,dH as H,aO as z}from"./index-C3k8jflc.js";import{D as A}from"./data-table-pagination-azA1p3g-.js";import{P as _}from"./page-layout-x3aFVsg9.js";import{D as q}from"./download-csv-button-DsnbHQxU.js";import{Y as J}from"./YearPickerInput-CWNdAJVU.js";const Q=({data:a,year:s})=>{const n=u.useCallback(async()=>{if(!a)return{fileContent:"",fileName:""};const x=R(M,a),m=W(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)}],W=a=>{const s=[F.map(({key:n})=>n).join(",")];return a.financialEntitiesInfo.map(n=>{const x=`${j(n.entity.name)},${n.entity.sortCode?.key}`,m=`,Opening Balance,,,,,,,,${n.openingBalance.raw.toFixed(2)}`,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),X=[{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:X,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(J,{value:new Date(s,0,1),onChange:r=>r&&n(r?.getFullYear()),popoverProps:{withinPortal:!0},minDate:new Date(2010,0,1),maxDate:new Date}),e.jsx(Q,{data:l,year:s})]})]}))},[s,m,a,l,o,b]),e.jsx(_,{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(Z,{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(E,{row:r})]})})})]})}):e.jsx("div",{className:"rounded-md border h-24 text-center",children:"No results."})})};function Z({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 E({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 +1 @@
|
|
|
1
|
-
import{g as T,hy as N,r as u,t as l,i as f,G as y,J as b,j as e,W as C,ea as $,Y as D,Z as F,_ as w,$ as k,I as j,a1 as E,hz as v,hA as A,a6 as z,l as S,T as M,B as p,bX as L,n as O,hB as P,hC as B,F as q,u as _,hD as U,L as G,bM as R,hE as V}from"./index-
|
|
1
|
+
import{g as T,hy as N,r as u,t as l,i as f,G as y,J as b,j as e,W as C,ea as $,Y as D,Z as F,_ as w,$ as k,I as j,a1 as E,hz as v,hA as A,a6 as z,l as S,T as M,B as p,bX as L,n as O,hB as P,hC as B,F as q,u as _,hD as U,L as G,bM as R,hE as V}from"./index-C3k8jflc.js";import{P as J}from"./page-layout-x3aFVsg9.js";import{L as Q}from"./list-plus-2cRRgK1O.js";const W="updateTag",X=()=>{const[{fetching:c},r]=T(N),i=u.useCallback(async t=>{const a=`Error updating tag ID [${t.tagId}]`,s=`${W}-${t.tagId}`;l.loading("Updating Tag...",{id:s});try{const n=await r(t),d=f(n,a,s,"updateTag");if(d)return l.success("Success",{id:s,description:"Tag updated"}),d.updateTag}catch(n){console.error(`${a}: ${n}`),l.error("Error",{id:s,description:a,duration:1e5,closeButton:!0})}return!1},[r]);return{fetching:c,updateTag:i}},Y=({onDone:c,data:r,close:i})=>{const{updateTag:t,fetching:a}=X(),s=b(A,r),n=y({defaultValues:{name:s.name,parentId:s.parent?.id}}),{control:d,handleSubmit:m,formState:{dirtyFields:h}}=n,x=o=>{const g=z(o,h);i(),g&&Object.keys(g).length>0&&t({tagId:s.id,fields:g}).then(()=>c?.())};return e.jsx(C,{...n,children:e.jsxs("form",{onSubmit:m(x),children:[e.jsx("div",{className:"flex-row px-10 h-max justify-start block",children:e.jsxs($,{cols:3,children:[e.jsx(D,{name:"name",control:d,defaultValue:s.name,rules:{required:"Required",minLength:{value:2,message:"Must be at least 2 characters"}},render:({field:o})=>e.jsxs(F,{children:[e.jsx(w,{children:"Name"}),e.jsx(k,{children:e.jsx(j,{...o,value:o.value??void 0})}),e.jsx(E,{})]})}),e.jsx(v,{formManager:n,tagsPath:"parentId",label:"Parent Tag"})]})}),e.jsxs("div",{className:"mt-10 mb-5 flex justify-center gap-5",children:[e.jsx("button",{type:"submit",onClick:()=>m(x),className:"mt-8 text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg",disabled:a||Object.keys(h).length===0,children:"Accept"}),e.jsx("button",{type:"button",className:"mt-8 text-white bg-rose-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-rose-600 rounded-sm text-lg",onClick:i,children:"Cancel"})]})]})})},Z=({onDone:c,data:r})=>{const[i,{open:t,close:a}]=S(!1);function s(){a(),c?.()}return e.jsxs(e.Fragment,{children:[e.jsx(M,{label:"Edit Tag",children:e.jsx(p,{variant:"ghost",size:"icon",className:"size-7.5",onClick:t,children:e.jsx(L,{className:"size-5"})})}),e.jsx(O,{centered:!0,opened:i,onClose:a,title:"Insert Business Trip",children:e.jsx(Y,{close:a,onDone:s,data:r})})]})},H="addTag",K=()=>{const[{fetching:c},r]=T(P),i=u.useCallback(async t=>{const a=`Error adding new tag [${t.tagName}]`,s=`${H}-${t.tagName}`;l.loading("Adding tag",{id:s});try{const n=await r(t);f(n,a,s)&&l.success("Success",{id:s,description:`"${t.tagName}" tag was successfully added`})}catch(n){console.error(`${a}: ${n}`),l.error("Error",{id:s,description:a,duration:1e5,closeButton:!0})}},[r]);return{fetching:c,addTag:i}},ee="deleteTag",se=()=>{const[{fetching:c},r]=T(B),i=u.useCallback(async t=>{const a=`Error deleting new tag [${t.name}]`,s=`${ee}-${t.tagId}`;l.loading(`Deleting tag [${t.name}]`,{id:s});try{const n=await r(t);f(n,a,s)&&l.success("Tag Deleted",{id:s,description:`[${t.name}] tag was successfully removed`})}catch(n){console.error(`${a}: ${n}`),l.error("Error",{id:s,description:a,duration:1e5,closeButton:!0})}},[r]);return{fetching:c,deleteTag:i}},oe=()=>{const{setFiltersContext:c}=u.useContext(q),[r,i]=u.useState(""),[{data:t,fetching:a},s]=_({query:V}),{addTag:n}=K(),{deleteTag:d}=se();u.useEffect(()=>{c(null)},[c]);const m=U(t?.allTags??[]),h=u.useCallback(o=>{o.length>2&&n({tagName:o}).then(()=>{s()})},[n,s]),x=u.useCallback((o,g)=>{d({tagId:o,name:g}).then(()=>{s()})},[d,s]);return e.jsx(J,{title:"Tags",description:"Manage tags for your bookmarks.",children:a?e.jsx(G,{className:"h-10 w-10 animate-spin mr-2 self-center"}):e.jsxs("div",{className:"h-full flex flex-col overflow-hidden",children:[m?.map(o=>e.jsxs("div",{className:"flex items-center gap-2 text-gray-600 mb-2",children:[e.jsxs("div",{className:"w-full mt-1 relative rounded-md shadow-xs",children:[o.namePath?.map((g,I)=>e.jsx("span",{className:"ms-2"},I)),o.name]}),e.jsx(Z,{data:o}),e.jsx(p,{variant:"ghost",size:"icon",className:"size-7.5",onClick:()=>x(o.id,o.name),children:e.jsx(R,{className:"size-5"})})]},o.id)),e.jsxs("div",{className:"flex justify-start items-center gap-2 text-gray-600 mb-2",children:[e.jsx(j,{className:"w-80",value:r,onChange:o=>i(o.currentTarget.value),placeholder:"Add new tag",required:!0}),e.jsx(p,{variant:"ghost",size:"icon",className:"size-7.5",disabled:r.length<2,onClick:()=>h(r),children:e.jsx(Q,{className:"size-5"})})]})]})})};export{oe as TagsManager};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{g as v,hF as U,r as u,t as m,i as F,ak as B,j as e,Y as C,Z as j,_ as f,$ as p,I as L,a0 as y,a1 as S,bs as _,bv as z,at as G,ai as V,D,aP as E,B as h,z as M,aQ as R,aR as A,G as $,W as k,hG as K,bX as Q,u as P,hH as W,L as O,F as X,cT as Y,cW as Z,cX as J,cY as T,cZ as ee,c_ as b,c$ as se,d0 as w,hI as te,d6 as ae,d7 as re,d8 as oe}from"./index-
|
|
1
|
+
import{g as v,hF as U,r as u,t as m,i as F,ak as B,j as e,Y as C,Z as j,_ as f,$ as p,I as L,a0 as y,a1 as S,bs as _,bv as z,at as G,ai as V,D,aP as E,B as h,z as M,aQ as R,aR as A,G as $,W as k,hG as K,bX as Q,u as P,hH as W,L as O,F as X,cT as Y,cW as Z,cX as J,cY as T,cZ as ee,c_ as b,c$ as se,d0 as w,hI as te,d6 as ae,d7 as re,d8 as oe}from"./index-C3k8jflc.js";import{D as ne}from"./data-table-pagination-azA1p3g-.js";import{P as ie}from"./page-layout-x3aFVsg9.js";import{A as I}from"./arrow-up-down-B8i8ydxe.js";const de="insertTaxCategory",ce=()=>{const[{fetching:s},n]=v(U),t=u.useCallback(async a=>{const d="Error creating tax category",r=de;m.loading("Adding Tax Category",{id:r});try{const i=await n(a),l=F(i,d,r);if(l)return m.success("Success",{id:r,description:`${l.insertTaxCategory.name} was created`}),l.insertTaxCategory}catch(i){console.error(`${d}: ${i}`),m.error("Error",{id:r,description:d,duration:1e5,closeButton:!0})}},[n]);return{fetching:s,insertTaxCategory:t}};function q({formManager:s,setFetching:n,isInsert:t}){const{control:a,watch:d,setValue:r}=s,{selectableSortCodes:i,fetching:l,sortCodes:x}=B();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(_,{name:"sortCode",control:a,render:({field:o,fieldState:g})=>e.jsx(z,{...o,onChange:H=>{o.onChange(Number(H))},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(G,{...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(V,{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(h,{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=$({}),{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(k,{...t,children:e.jsxs("form",{onSubmit:a(x),children:[e.jsx("div",{className:"flex flex-col gap-4 my-4",children:e.jsx(q,{isInsert:!0,formManager:t,setFetching:r})}),e.jsx("div",{className:"flex justify-end mt-4",children:e.jsx(h,{type:"submit",disabled:l||d,children:"Add Tax Category"})})]})})}const ue="updateTaxCategory",ge=()=>{const[{fetching:s},n]=v(K),t=u.useCallback(async a=>{const d="Error updating tax category",r=`${ue}-${a.taxCategoryId}`;m.loading("Uploading Tax Category",{id:r});try{const i=await n(a),l=F(i,d,r,"updateTaxCategory");if(l)return m.success("Success",{id:r,description:`${l.updateTaxCategory.name} was updated`}),l.updateTaxCategory}catch(i){console.error(`${d}: ${i}`),m.error("Error",{id:r,description:d,duration:1e5,closeButton:!0})}},[n]);return{fetching:s,updateTaxCategory:t}};function me({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(h,{variant:"outline",size:"icon",children:e.jsx(Q,{})})}),e.jsxs(M,{className:"w-[400px] max-w-screen-md",children:[e.jsx(R,{children:e.jsx(A,{children:"Edit Tax Category"})}),e.jsx(he,{taxCategoryId:s,close:()=>a(!1),onAdd:n})]})]})}function he({taxCategoryId:s,close:n,onAdd:t}){const[{data:a,fetching:d}]=P({query:W,variables:{id:s}}),r=a?.taxCategory;return!r&&!d&&m.error("Error",{description:"Couldn'nt find tax category"}),d?e.jsx(O,{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=$({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(k,{...a,children:e.jsxs("form",{onSubmit:d(c),children:[e.jsx("div",{className:"flex flex-col gap-4 my-4",children:e.jsx(q,{isInsert:!1,formManager:a,setFetching:i})}),e.jsx("div",{className:"flex justify-end mt-4",children:e.jsx(h,{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"}),N=[{id:"name",accessorKey:"name",cell:({row:s})=>e.jsx(je,{data:s.original}),header:({column:s})=>e.jsxs(h,{variant:"ghost",onClick:()=>s.toggleSorting(s.getIsSorted()==="asc"),children:["Name",e.jsx(I,{})]})},{id:"sortCode",accessorKey:"sortCode.key",cell:({row:s})=>e.jsx(fe,{data:s.original}),header:({column:s})=>e.jsxs(h,{variant:"ghost",onClick:()=>s.toggleSorting(s.getIsSorted()==="asc"),children:["Sort Code",e.jsx(I,{})]})},{id:"edit",cell:({row:s})=>e.jsx(me,{taxCategoryId:s.original.id})}],be=()=>{const[{data:s,fetching:n,error:t},a]=P({query:te}),{setFiltersContext:d}=u.useContext(X),r=s?.taxCategories??[],i=Y({data:r,columns:N,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&&m.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(O,{className:"h-10 w-10 animate-spin mr-2"})}):e.jsx("div",{className:"flex flex-col gap-4 rounded-md border",children:e.jsxs(Z,{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:N.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 +1 @@
|
|
|
1
|
-
import{j as e,T as se,B as q,av as ae,br as ne,u as I,h9 as te,r as x,a9 as H,ha as oe,hb as z,G,t as f,W as le,ea as ie,cL as V,bs as u,bv as k,Y as de,hc as ce,Z as me,_ as ue,$ as xe,I as ye,a1 as pe,bN as g,bL as S,x as E,a6 as ge,g as W,hd as he,i as Y,he as je,ef as _,d as fe,hf as ve,gI as be,bp as Ne,bw as Se,J as w,hg as Ee,hh as we,hi as Fe,hj as Ce,hk as Ie,fF as De,hl as Ae,hm as Pe,hn as Re,F as Te,L as ke,ho as Me}from"./index-C9fHUfnt.js";import{u as J}from"./use-url-query-BS26aRC-.js";import{P as Be}from"./page-layout-DZOekob-.js";import{P as Le}from"./modal-weFgvkj_.js";import{F as Ze}from"./funnel-6jLbjYGX.js";import{M as $e}from"./MultiSelect-Cyxk2rHZ.js";function Q(t){return e.jsx(se,{disabled:!t.tooltip,label:t.tooltip,children:e.jsx(q,{variant:"ghost",size:"icon",className:"size-7.5",...t,children:e.jsx(ae,{className:"size-5"})})})}const X=({isNewInsert:t=!0,defaultValues:s,month:l,onDone:d,isModifying:o})=>{const{selectableBusinesses:i,fetching:n}=ne(),[{data:c,fetching:y,error:j}]=I({query:te}),{userContext:v}=x.useContext(H),[{data:b,fetching:F,error:R}]=I({query:oe}),[{data:D,fetching:M,error:C}]=I({query:z,variables:{employerId:v?.context.adminBusinessId??""}}),[p,N]=x.useState([]),[A,T]=x.useState([]),[K,ee]=x.useState([]),P=s?.month??l,Z=G({defaultValues:{...s,month:P}}),{control:m,handleSubmit:$,formState:{dirtyFields:O},setValue:B}=Z;x.useEffect(()=>{j&&f.error("Error",{description:"Oh no!, we have an error fetching pension funds! 🤥"})},[j]),x.useEffect(()=>{R&&f.error("Error",{description:"Oh no!, we have an error fetching training funds! 🤥"})},[R]),x.useEffect(()=>{C&&f.error("Error",{description:"Oh no!, we have an error employees! 🤥"})},[C]),x.useEffect(()=>{c?.allPensionFunds?.length&&N(c.allPensionFunds.map(r=>({value:r.id,label:r.name})).sort((r,a)=>r.label>a.label?1:-1))},[c,T]),x.useEffect(()=>{b?.allTrainingFunds?.length&&T(b.allTrainingFunds.map(r=>({value:r.id,label:r.name})).sort((r,a)=>r.label>a.label?1:-1))},[b,T]),x.useEffect(()=>{D?.employeesByEmployerId.length&&ee(D.employeesByEmployerId.filter(r=>!r.name.toLocaleLowerCase().includes("batched")).map(r=>({value:r.id,label:r.name})).sort((r,a)=>r.label>a.label?1:-1))},[D,T]),x.useEffect(()=>{!s?.employer&&v?.context.adminBusinessId&&B("employer",v.context.adminBusinessId,{shouldDirty:!0,shouldTouch:!0})},[B,s?.employer,v?.context.adminBusinessId]);const U=r=>{const a=ge(r,O);if(!(t&&(!a?.directPaymentAmount||!a?.employeeId||!a?.employer||!a?.month)))if(a&&Object.keys(a).length>0){if(!t){if(!s)return;a.employeeId??=s.employeeId,a.month??=s.month}d(a)}else d()};function re(r){B("month",E(r,"yyyy-MM-dd"),{shouldDirty:!0,shouldTouch:!0})}return e.jsx(le,{...Z,children:e.jsxs("form",{onSubmit:$(U),children:[e.jsx("div",{className:"flex-row px-10 h-max justify-start block",children:e.jsxs(ie,{cols:4,children:[e.jsxs("div",{className:"flex-column h-max justify-start block",children:[e.jsx(V,{defaultDate:P?new Date(P):void 0,defaultValue:P?new Date(P):void 0,onChange:re,popoverProps:{withinPortal:!0}}),e.jsx(u,{name:"employer",control:m,defaultValue:s?.employer,rules:{required:"Required"},render:({field:r,fieldState:a})=>e.jsx(k,{...r,data:i,value:r.value,disabled:n,label:"Employer",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:a.error?.message})}),e.jsx(de,{name:"chargeId",control:m,defaultValue:s?.chargeId,rules:{pattern:{value:ce,message:"Invalid UUID"}},render:({field:r})=>e.jsxs(me,{children:[e.jsx(ue,{children:"Charge ID"}),e.jsx(xe,{children:e.jsx(ye,{...r,value:r.value??void 0})}),e.jsx(pe,{})]})}),e.jsx(u,{name:"employeeId",control:m,defaultValue:s?.employeeId,rules:{required:"Required"},render:({field:r,fieldState:a})=>e.jsx(k,{...r,data:K,value:r.value,disabled:M,label:"Employee",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:a.error?.message})})]}),e.jsxs("div",{className:"flex-row px-10 h-max justify-start block",children:[e.jsx(u,{name:"baseSalary",control:m,defaultValue:s?.baseSalary,render:({field:r,fieldState:a})=>e.jsx(g,{...r,value:r.value??void 0,error:a.error?.message,label:"Base Salary",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"globalAdditionalHours",control:m,defaultValue:s?.globalAdditionalHours,render:({field:r,fieldState:a})=>e.jsx(g,{...r,value:r.value??void 0,error:a.error?.message,label:"Global Additional Hours",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"bonus",control:m,defaultValue:s?.bonus,render:({field:r,fieldState:a})=>e.jsx(g,{...r,value:r.value??void 0,error:a.error?.message,label:"Bonus",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"gift",control:m,defaultValue:s?.gift,render:({field:r,fieldState:a})=>e.jsx(g,{...r,value:r.value??void 0,error:a.error?.message,label:"Gift",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"travelAndSubsistence",control:m,defaultValue:s?.travelAndSubsistence,render:({field:r,fieldState:a})=>e.jsx(g,{...r,value:r.value??void 0,error:a.error?.message,label:"Travel and Subsistence",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"recovery",control:m,defaultValue:s?.recovery,render:({field:r,fieldState:a})=>e.jsx(g,{...r,value:r.value??void 0,error:a.error?.message,label:"Recovery",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency"}})}),e.jsx(u,{name:"vacationTakeout",control:m,defaultValue:s?.vacationTakeout,render:({field:r,fieldState:a})=>e.jsx(g,{...r,value:r.value??void 0,error:a.error?.message,label:"Vacation Takeout",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"directPaymentAmount",control:m,defaultValue:s?.directPaymentAmount,rules:{required:"Required"},render:({field:r,fieldState:a})=>e.jsx(g,{...r,value:r.value??void 0,error:a.error?.message,label:"Direct Payment",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})})]}),e.jsxs("div",{className:"flex-row px-10 h-max justify-start block",children:[e.jsx(u,{name:"pensionFundId",control:m,defaultValue:s?.pensionFundId,render:({field:r,fieldState:a})=>e.jsx(k,{...r,data:p,value:r.value,disabled:y,label:"Pension Fund",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:a.error?.message})}),e.jsx(u,{name:"pensionEmployeeAmount",control:m,defaultValue:s?.pensionEmployeeAmount,render:({field:r,fieldState:a})=>e.jsx(g,{...r,value:r.value??void 0,error:a.error?.message,label:"Pension Employee Amount",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"pensionEmployeePercentage",control:m,defaultValue:s?.pensionEmployeePercentage,render:({field:{value:r,...a},fieldState:h})=>e.jsx(S,{...a,hideControls:!0,precision:2,removeTrailingZeros:!0,rightSection:"%",value:r??void 0,error:h.error?.message,label:"Pension Employee Percentage"})}),e.jsx(u,{name:"pensionEmployerAmount",control:m,defaultValue:s?.pensionEmployerAmount,render:({field:r,fieldState:a})=>e.jsx(g,{...r,value:r.value??void 0,error:a.error?.message,label:"Pension Employer Amount",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"pensionEmployerPercentage",control:m,defaultValue:s?.pensionEmployerPercentage,render:({field:{value:r,...a},fieldState:h})=>e.jsx(S,{...a,hideControls:!0,precision:2,removeTrailingZeros:!0,rightSection:"%",value:r??void 0,error:h.error?.message,label:"Pension Employer Percentage"})})]}),e.jsxs("div",{className:"flex-row px-10 h-max justify-start block",children:[e.jsx(u,{name:"compensationsEmployerAmount",control:m,defaultValue:s?.compensationsEmployerAmount,render:({field:r,fieldState:a})=>e.jsx(g,{...r,value:r.value??void 0,error:a.error?.message,label:"Compensations Amount",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"compensationsEmployerPercentage",control:m,defaultValue:s?.compensationsEmployerPercentage,render:({field:{value:r,...a},fieldState:h})=>e.jsx(S,{...a,hideControls:!0,precision:2,removeTrailingZeros:!0,rightSection:"%",value:r??void 0,error:h.error?.message,label:"Compensations Percentage"})})]}),e.jsxs("div",{className:"flex-row px-10 h-max justify-start block",children:[e.jsx(u,{name:"trainingFundId",control:m,defaultValue:s?.trainingFundId,render:({field:r,fieldState:a})=>e.jsx(k,{...r,data:A,value:r.value,disabled:F,label:"Training Fund",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:a.error?.message})}),e.jsx(u,{name:"trainingFundEmployeeAmount",control:m,defaultValue:s?.trainingFundEmployeeAmount,render:({field:r,fieldState:a})=>e.jsx(g,{...r,value:r.value??void 0,error:a.error?.message,label:"Training Employee Amount",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"trainingFundEmployeePercentage",control:m,defaultValue:s?.trainingFundEmployeePercentage,render:({field:{value:r,...a},fieldState:h})=>e.jsx(S,{...a,hideControls:!0,precision:2,removeTrailingZeros:!0,rightSection:"%",value:r??void 0,error:h.error?.message,label:"Training Employee Percentage"})}),e.jsx(u,{name:"trainingFundEmployerAmount",control:m,defaultValue:s?.trainingFundEmployerAmount,render:({field:r,fieldState:a})=>e.jsx(g,{...r,value:r.value??void 0,error:a.error?.message,label:"Training Employer Amount",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"trainingFundEmployerPercentage",control:m,defaultValue:s?.trainingFundEmployerPercentage,render:({field:{value:r,...a},fieldState:h})=>e.jsx(S,{...a,hideControls:!0,precision:2,removeTrailingZeros:!0,rightSection:"%",value:r??void 0,error:h.error?.message,label:"Training Employer Percentage"})})]}),e.jsxs("div",{className:"flex-row px-10 h-max justify-start block",children:[e.jsx(u,{name:"socialSecurityAmountEmployee",control:m,defaultValue:s?.socialSecurityAmountEmployee,render:({field:r,fieldState:a})=>e.jsx(g,{...r,value:r.value??void 0,error:a.error?.message,label:"Social Security - Employee",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"socialSecurityAmountEmployer",control:m,defaultValue:s?.socialSecurityAmountEmployer,render:({field:r,fieldState:a})=>e.jsx(g,{...r,value:r.value??void 0,error:a.error?.message,label:"Social Security - Employer",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"healthPaymentAmount",control:m,defaultValue:s?.healthPaymentAmount,render:({field:r,fieldState:a})=>e.jsx(g,{...r,value:r.value??void 0,error:a.error?.message,label:"Health Insurance",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})})]}),e.jsxs("div",{className:"flex-row px-10 h-max justify-start block",children:[e.jsx(u,{name:"taxAmount",control:m,defaultValue:s?.taxAmount,render:({field:r,fieldState:a})=>e.jsx(g,{...r,value:r.value??void 0,error:a.error?.message,label:"Income Tax",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"zkufot",control:m,defaultValue:s?.zkufot,render:({field:r,fieldState:a})=>e.jsx(g,{...r,value:r.value??void 0,error:a.error?.message,precision:0,label:"Notional Expense",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})})]}),e.jsxs("div",{className:"flex-row px-10 h-max justify-start block",children:[e.jsx(u,{name:"workDays",control:m,defaultValue:s?.workDays,render:({field:{value:r,...a},fieldState:h})=>e.jsx(S,{...a,hideControls:!0,precision:2,removeTrailingZeros:!0,value:r??void 0,error:h.error?.message,label:"Work Days"})}),e.jsx(u,{name:"addedVacationDays",control:m,defaultValue:s?.addedVacationDays,render:({field:{value:r,...a},fieldState:h})=>e.jsx(S,{...a,hideControls:!0,precision:2,removeTrailingZeros:!0,value:r??void 0,error:h.error?.message,label:"Added Vacation Days"})}),e.jsx(u,{name:"vacationDaysBalance",control:m,defaultValue:s?.vacationDaysBalance,render:({field:{value:r,...a},fieldState:h})=>e.jsx(S,{...a,hideControls:!0,precision:2,removeTrailingZeros:!0,value:r??void 0,error:h.error?.message,label:"Vacation Days Balance"})}),e.jsx(u,{name:"sicknessDaysBalance",control:m,defaultValue:s?.sicknessDaysBalance,render:({field:{value:r,...a},fieldState:h})=>e.jsx(S,{...a,hideControls:!0,precision:2,removeTrailingZeros:!0,value:r??void 0,error:h.error?.message,label:"Sickness Days Balance"})})]})]})}),e.jsxs("div",{className:"mt-10 mb-5 flex justify-center gap-5",children:[e.jsx("button",{type:"submit",onClick:()=>$(U),className:"mt-8 text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg",disabled:o||Object.keys(O).length===0,children:"Accept"}),e.jsx("button",{type:"button",className:"mt-8 text-white bg-rose-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-rose-600 rounded-sm text-lg",onClick:()=>d(),children:"Cancel"})]})]})})},Oe="updateSalaryRecord",Ue=()=>{const[{fetching:t},s]=W(he),l=x.useCallback(async d=>{const o=`Error updating salary record [${d.salaryRecord.month}] employee [${d.salaryRecord.employeeId}]`,i=Oe;f.loading("Updating Salary Record",{id:i});try{const n=await s(d),c=Y(n,o,i,"updateSalaryRecord");if(c)return f.success("Success",{id:i,description:"Salary record was updated"}),c.updateSalaryRecord.salaryRecord}catch(n){console.error(`${o}: ${n}`),f.error("Error",{id:i,description:o,duration:1e5,closeButton:!0})}},[s]);return{fetching:t,updateSalaryRecord:l}},qe=({recordVariables:t,onDone:s})=>t?e.jsx(He,{recordVariables:t,onDone:s}):null,He=({recordVariables:t,onDone:s})=>{const{updateSalaryRecord:l,fetching:d}=Ue(),[{data:o,fetching:i}]=I({query:je,variables:{employeeIDs:[t.employeeId],month:E(new Date(t.month),"yyyy-MM-dd")}}),n=o?.salaryRecordsByDates?.[0],c=x.useCallback(j=>{s(),j&&l({salaryRecord:j})},[s,l]);if(!n?.employer?.id||!n?.employee?.id)return e.jsx(e.Fragment,{});const y={addedVacationDays:n?.vacationDays?.added,baseSalary:n?.baseAmount?.raw,bonus:n?.bonus?.raw,chargeId:n?.charge?.id,compensationsEmployerAmount:n?.compensationsAmount?.raw,compensationsEmployerPercentage:n?.compensationsPercentage,directPaymentAmount:n?.directAmount?.raw,employer:n.employer.id,employeeId:n.employee.id,gift:n?.gift?.raw,globalAdditionalHours:n?.globalAdditionalHoursAmount?.raw,healthPaymentAmount:n?.healthInsuranceAmount?.raw,month:n?.month,pensionEmployeeAmount:n?.pensionEmployeeAmount?.raw,pensionEmployeePercentage:n?.pensionEmployeePercentage,pensionEmployerAmount:n?.pensionEmployerAmount?.raw,pensionEmployerPercentage:n?.pensionEmployerPercentage,pensionFundId:n?.pensionFund?.id,recovery:n?.recovery?.raw,sicknessDaysBalance:n?.sicknessDays?.balance,socialSecurityAmountEmployee:n?.socialSecurityEmployeeAmount?.raw,socialSecurityAmountEmployer:n?.socialSecurityEmployerAmount?.raw,taxAmount:n?.incomeTaxAmount?.raw,trainingFundEmployeeAmount:n?.trainingFundEmployeeAmount?.raw,trainingFundEmployeePercentage:n?.trainingFundEmployeePercentage,trainingFundEmployerAmount:n?.trainingFundEmployerAmount?.raw,trainingFundEmployerPercentage:n?.trainingFundEmployerPercentage,trainingFundId:n?.trainingFund?.id,travelAndSubsistence:n?.travelAndSubsistence?.raw,vacationDaysBalance:n?.vacationDays?.balance,vacationTakeout:n?.vacationTakeout?.raw,workDays:n?.workDays,zkufot:n?.notionalExpense?.raw};return e.jsx(_,{modalSize:"fit-content",position:"bottom",title:e.jsxs("div",{className:"flex flex-row mx-3 pt-3 sm:text-1xl gap-10",children:[e.jsx("h1",{className:"sm:text-2xl font-small text-gray-900",children:"Edit Salary Record:"}),e.jsxs("div",{className:"flex flex-row gap-2",children:["month: ",t.month," employeeId: ",t.employeeId]})]}),opened:!!t,onClose:s,children:i||!n?e.jsx(fe,{className:"flex self-center my-5",color:"dark",size:"xl",variant:"dots"}):e.jsx(X,{isNewInsert:!1,defaultValues:y,onDone:c,isModifying:d})})},ze="insertSalaryRecords",Ge=()=>{const[{fetching:t},s]=W(ve),l=x.useCallback(async d=>{const o=ze;if(f.loading("Adding salary record",{id:o}),!d.salaryRecords||Array.isArray(d.salaryRecords)&&d.salaryRecords.length===0){f.error("Error",{id:o,description:"No salary records to insert",duration:1e5,closeButton:!0});return}const i=Array.isArray(d.salaryRecords)?d.salaryRecords[0]:d.salaryRecords;if(!i?.directPaymentAmount||!i?.employeeId||!i?.employer||!i?.month){f.error("Error",{id:o,description:"Missing required salary record fields",duration:1e5,closeButton:!0});return}const n=`Error adding salary record [${i.month}] employee [${i.employeeId}]`;try{const c=await s(d),y=Y(c,n,o,"insertSalaryRecords");if(y)return f.success("Success",{id:o,description:"Salary record was added"}),y.insertSalaryRecords.salaryRecords[0]}catch(c){console.error(`${n}: ${c}`),f.error("Error",{id:o,description:n,duration:1e5,closeButton:!0})}},[s]);return{fetching:t,insertSalaryRecord:l}},Ve=({insertSalaryRecordParams:t,setInsertSalaryRecord:s})=>{const{insertSalaryRecord:l,fetching:d}=Ge(),o=x.useCallback(i=>{i&&l({salaryRecords:[i]}),s(void 0)},[s,l]);return e.jsx(_,{modalSize:"40%",position:"bottom",title:e.jsx("div",{className:"flex flex-row mx-3 pt-3 sm:text-1xl gap-10",children:e.jsx("h1",{className:"sm:text-2xl font-small text-gray-900",children:"Insert Salary Record:"})}),opened:!!t,onClose:()=>s(void 0),children:e.jsx(X,{isNewInsert:!0,onDone:o,isModifying:d,month:t.month})})};function L(){const t=new Date,s=E(t,"yyyy-MM-dd"),l=E(be(t),"yyyy-MM-dd");return{fromDate:s,toDate:l}}function We({filter:t,setFilter:s,closeModal:l}){const{control:d,handleSubmit:o,setValue:i}=G({defaultValues:{...t}}),[n,c]=x.useState([]),{userContext:y}=x.useContext(H),[{data:j,fetching:v,error:b},F]=I({query:z,variables:{employerId:y?.context.adminBusinessId??""},pause:!0});x.useEffect(()=>{F()},[y?.context.adminBusinessId,F]),x.useEffect(()=>{b&&f.error("Error",{description:"Oh no!, we have an error fetching employees! 🤥"})},[b]);const R=p=>{p.employeeIDs?.length===0&&delete p.employeeIDs,s(p),l()};function D(){s({...L()}),l()}x.useEffect(()=>{j?.employeesByEmployerId.length&&c(j.employeesByEmployerId.filter(p=>!p.name.toLocaleLowerCase().includes("batched")).map(p=>({value:p.id,label:p.name})).sort((p,N)=>p.label>N.label?1:-1))},[j,c]);function M([p,N]){if(N){const A=new Date(N.getFullYear(),N.getMonth()+1,0);i("toDate",E(A,"yyyy-MM-dd"))}if(p){const A=new Date(p.getFullYear(),p.getMonth(),1);i("fromDate",E(A,"yyyy-MM-dd"))}}const C=L();return e.jsxs(e.Fragment,{children:[v?e.jsx("div",{children:"Loading..."}):e.jsx("div",{}),e.jsxs("form",{onSubmit:o(R),children:[e.jsx(V,{type:"range",numberOfColumns:2,defaultValue:[new Date(t?.fromDate??C.fromDate),new Date(t?.toDate??C.toDate)],defaultDate:new Date(t?.fromDate??C.fromDate),onChange:M,popoverProps:{withinPortal:!0}}),e.jsx(u,{name:"employeeIDs",control:d,defaultValue:t.employeeIDs,render:({field:p,fieldState:N})=>e.jsx($e,{...p,data:n,value:p.value??[],disabled:v,label:"Employees",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:N.error?.message})}),e.jsxs("div",{className:"flex justify-center mt-5 gap-3",children:[e.jsx("button",{type:"submit",disabled:v,className:"text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg",children:"Filter"}),e.jsx("button",{type:"button",className:"text-white bg-orange-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-orange-600 rounded-sm text-lg",onClick:D,children:"Clear"}),e.jsx("button",{type:"button",className:"text-white bg-rose-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-rose-600 rounded-sm text-lg",onClick:l,children:"Cancel"})]})]})]})}function Ye({filter:t,setFilter:s}){const[l,d]=x.useState(!1),{get:o,set:i}=J();x.useEffect(()=>{const c=Ne(t)?null:encodeURIComponent(JSON.stringify(t)),y=o("salariesFilters");c!==y&&i("salariesFilters",c)},[t,o,i]);const n=x.useCallback(c=>{Se(c,t)||s(c)},[t,s]);return e.jsxs("div",{className:"flex flex-row gap-5 items-center",children:[e.jsx(Le,{opened:l,onClose:()=>d(!1),content:e.jsx(We,{filter:t,setFilter:n,closeModal:()=>d(!1)}),modalSize:"xl"}),e.jsx(q,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>d(!0),children:e.jsx(Ze,{className:"size-5"})})]})}const _e=({month:t,setInsertSalaryRecord:s})=>{const l=E(new Date(t),"MMMM yyyy");return e.jsx("tr",{tabIndex:0,className:"h-16 rounded-sm",children:e.jsx("td",{colSpan:100,children:e.jsxs("div",{className:"flex justify-between pl-5",children:[e.jsx("p",{className:"text-lg font-bold text-gray-800",children:l}),e.jsx("div",{className:"flex items-center",children:e.jsx("div",{className:"flex flex-col",children:e.jsx(Q,{onClick:s})})})]})})})},Je=({data:t})=>{const{employee:s,month:l}=w(Ee,t),d=E(new Date(l),"MMMM yyyy");return e.jsx("td",{className:"",children:e.jsx("div",{className:"flex items-center pl-5",children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("p",{className:"text-base font-bold text-gray-800",children:s?.name}),e.jsx("p",{className:"text-base font-medium text-gray-800",children:d})]})})})},Qe=({data:t})=>{const{pensionEmployeeAmount:s,pensionEmployeePercentage:l,pensionEmployerAmount:d,pensionEmployerPercentage:o,compensationsAmount:i,compensationsPercentage:n,pensionFund:c,trainingFund:y,trainingFundEmployeeAmount:j,trainingFundEmployeePercentage:v,trainingFundEmployerAmount:b,trainingFundEmployerPercentage:F}=w(we,t);return e.jsx("td",{className:"pl-5",children:e.jsx("div",{className:"flex items-center",children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("p",{className:"text-md font-bold text-gray-800",children:"Pension Fund"}),e.jsx("p",{className:"text-md font-medium text-gray-800",children:c?.name}),!!s?.raw&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Employee Part:"}),e.jsxs("p",{className:"text-sm leading-none text-gray-600 ml-2",children:[s?.formatted,l&&` (${l}%)`]})]}),!!d?.raw&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Employer Part:"}),e.jsxs("p",{className:"text-sm leading-none text-gray-600 ml-2",children:[d?.formatted,o&&` (${o}%)`]})]}),!!i?.raw&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Compensations Amount:"}),e.jsxs("p",{className:"text-sm leading-none text-gray-600 ml-2",children:[i?.formatted,n&&` (${n}%)`]})]}),e.jsx("p",{className:"text-md font-bold text-gray-800 mt-2",children:"Training Fund"}),e.jsx("p",{className:"text-md font-medium text-gray-800",children:y?.name}),!!j?.raw&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Employee Part:"}),e.jsxs("p",{className:"text-sm leading-none text-gray-600 ml-2",children:[j?.formatted,v&&` (${v}%)`]})]}),!!b?.raw&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Employer Part:"}),e.jsxs("p",{className:"text-sm leading-none text-gray-600 ml-2",children:[b?.formatted,F&&` (${F}%)`]})]})]})})})},Xe=({data:t})=>{const{healthInsuranceAmount:s,socialSecurityEmployeeAmount:l,socialSecurityEmployerAmount:d,incomeTaxAmount:o,notionalExpense:i}=w(Fe,t),n=!!l||!!d;return e.jsx("td",{className:"pl-5",children:e.jsx("div",{className:"flex items-center pl-5",children:e.jsxs("div",{className:"flex flex-col",children:[n&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-md font-bold text-gray-800",children:"Social Security"}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Employee Part:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:l?.formatted})]}),e.jsx("p",{className:"text-md font-bold text-gray-800 mt-2",children:"Pension Fund"}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Employer Part:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:d?.formatted})]})]}),!!s?.raw&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-md font-bold text-gray-800 mt-2",children:"Health Insurance"}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Amount:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:s?.formatted})]})]}),(!!o?.raw||!!i?.raw)&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-md font-bold text-gray-800 mt-2",children:"Taxes"}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Income Tax:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:o?.formatted})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Notional Expense:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:i?.formatted})]})]})]})})})},Ke=({data:t})=>{const{baseAmount:s,directAmount:l,globalAdditionalHoursAmount:d,bonus:o,gift:i,recovery:n,vacationTakeout:c}=w(Ce,t);return e.jsx("td",{className:"pl-24",children:e.jsx("div",{className:"flex items-center",children:e.jsxs("div",{className:"flex flex-col",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Base Amount:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:s?.formatted})]}),e.jsxs("div",{className:"flex justify-between mb-2",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Global Extra Hours:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:d?.formatted})]}),!!o?.raw&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Bonus:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:o?.formatted})]}),!!i?.raw&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Gift:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:i?.formatted})]}),!!n?.raw&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Recovery:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:n?.formatted})]}),!!c?.raw&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Vacation Takeout:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:c?.formatted})]}),e.jsxs("div",{className:"flex justify-between mt-2",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Direct Amount:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:l?.formatted})]})]})})})},er=({data:t})=>{const{vacationDays:s,workDays:l,sicknessDays:d}=w(Ie,t),{added:o,taken:i,balance:n}=s??{},{balance:c}=d??{},y=!!o||!!i||!!n;return e.jsx("td",{className:"pl-5",children:e.jsx("div",{className:"flex items-center",children:e.jsxs("div",{className:"flex flex-col",children:[!!l&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-md leading-none text-gray-800",children:"Work Days:"}),e.jsx("div",{className:"flex justify-between",children:e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:l})})]}),y&&e.jsxs("div",{className:"flex flex-col",children:[e.jsx("p",{className:"text-md leading-none text-gray-800 mt-2",children:"Vacation Days:"}),!!o&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Added:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:o})]}),!!i&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Taken:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:i})]}),!!n&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Balance:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:n})]})]}),!!c&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-md leading-none text-gray-800 mt-2",children:"Sickness Days:"}),e.jsx("div",{className:"flex justify-between",children:e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:c})})]})]})})})},rr=({setEditSalaryRecord:t,data:s})=>{const l=w(Ae,s);return e.jsxs(e.Fragment,{children:[e.jsxs("tr",{tabIndex:0,className:"h-16 border border-gray-100 hover:bg-gray-100 rounded-sm",children:[e.jsx(Je,{data:l}),e.jsx(Ke,{data:l}),e.jsx(Qe,{data:l}),e.jsx(Xe,{data:l}),e.jsx(er,{data:l}),e.jsx("td",{className:"pl-2",children:e.jsx("div",{className:"flex items-center",children:e.jsx("div",{className:"flex flex-col",children:e.jsx(De,{onClick:t})})})})]}),e.jsx("tr",{className:"h-3"})]})},sr=({setEditSalaryRecord:t,setInsertSalaryRecord:s,data:l})=>{const d=l?.map(o=>w(Pe,o))??[];return e.jsxs(e.Fragment,{children:[e.jsx("tr",{className:"h-3"}),e.jsx(_e,{month:d[0].month,setInsertSalaryRecord:s}),e.jsx("tr",{className:"h-3"}),d.map(o=>e.jsx(rr,{data:o,setEditSalaryRecord:()=>t(o.employee?.id)},`${o.month} ${o.employee?.id}`))]})},ar=({setEditSalaryRecord:t,setInsertSalaryRecord:s,data:l})=>{const d=x.useMemo(()=>{const o=l?.map(n=>w(Re,n))??[],i=new Map;return o.map(n=>{const{month:c}=n,y=i.get(c)??[];i.set(c,[...y,n])}),i},[l]);return e.jsx("div",{className:"sm:px-6 w-full",children:e.jsxs("div",{className:"bg-white py-4 md:py-7 px-4 md:px-8 xl:px-10",children:[e.jsxs("div",{className:"sm:flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center",children:[e.jsx("div",{className:"rounded-full focus:outline-hidden focus:ring-2 focus:bg-indigo-50 focus:ring-indigo-800",children:e.jsx("div",{className:"py-2 px-8 bg-indigo-100 text-indigo-700 rounded-full",children:e.jsx("p",{children:"All"})})}),e.jsx("div",{className:"rounded-full focus:outline-hidden focus:ring-2 focus:bg-indigo-50 focus:ring-indigo-800 ml-4 sm:ml-8",children:e.jsx("div",{className:"py-2 px-8 text-gray-600 hover:text-indigo-700 hover:bg-indigo-100 rounded-full ",children:e.jsx("p",{children:"Done"})})}),e.jsx("div",{className:"rounded-full focus:outline-hidden focus:ring-2 focus:bg-indigo-50 focus:ring-indigo-800 ml-4 sm:ml-8",children:e.jsx("div",{className:"py-2 px-8 text-gray-600 hover:text-indigo-700 hover:bg-indigo-100 rounded-full ",children:e.jsx("p",{children:"Pending"})})})]}),e.jsx("button",{className:"focus:ring-2 focus:ring-offset-2 focus:ring-indigo-600 mt-4 sm:mt-0 inline-flex items-start justify-start px-6 py-3 bg-indigo-700 hover:bg-indigo-600 focus:outline-hidden rounded-sm",children:e.jsx("p",{className:"text-sm font-medium leading-none text-white",children:"Add Task"})})]}),e.jsx("div",{className:"mt-7 overflow-x-auto",children:e.jsx("table",{className:"w-full whitespace-nowrap",children:e.jsx("tbody",{children:Array.from(d).map(([o,i])=>e.jsx(sr,{data:i,setEditSalaryRecord:n=>t(n?{month:o,employeeId:n}:void 0),setInsertSalaryRecord:()=>s({month:o})},o))})})})]})})},cr=()=>{const{setFiltersContext:t}=x.useContext(Te),[s,l]=x.useState(void 0),[d,o]=x.useState(void 0),{get:i}=J(),[n,c]=x.useState(i("salariesFilters")?JSON.parse(decodeURIComponent(i("salariesFilters"))):{...L()}),[{data:y,fetching:j}]=I({query:Me,variables:{...n}});return x.useEffect(()=>{t(e.jsxs("div",{className:"flex flex-row gap-x-5",children:[e.jsx(Ye,{filter:n,setFilter:c}),e.jsx(Q,{variant:"default",onClick:()=>o({})})]}))},[y,j,n,t,c]),e.jsxs(Be,{title:"Salaries",description:"View and manage salaries of employees.",children:[j?e.jsx(ke,{className:"h-10 w-10 animate-spin mr-2 self-center"}):e.jsx(ar,{setEditSalaryRecord:l,setInsertSalaryRecord:o,data:y?.salaryRecordsByDates}),e.jsx(qe,{recordVariables:s,onDone:()=>l(void 0)}),d&&e.jsx(Ve,{insertSalaryRecordParams:d,setInsertSalaryRecord:o})]})};export{cr as Salaries};
|
|
1
|
+
import{j as e,T as se,B as q,av as ae,br as ne,u as I,h9 as te,r as x,a9 as H,ha as oe,hb as z,G,t as f,W as le,ea as ie,cL as V,bs as u,bv as k,Y as de,hc as ce,Z as me,_ as ue,$ as xe,I as ye,a1 as pe,bN as g,bL as S,x as E,a6 as ge,g as W,hd as he,i as Y,he as je,ef as _,d as fe,hf as ve,gI as be,bp as Ne,bw as Se,J as w,hg as Ee,hh as we,hi as Fe,hj as Ce,hk as Ie,fF as De,hl as Ae,hm as Pe,hn as Re,F as Te,L as ke,ho as Me}from"./index-C3k8jflc.js";import{u as J}from"./use-url-query-BOxCMiZm.js";import{P as Be}from"./page-layout-x3aFVsg9.js";import{P as Le}from"./modal-DNhi-EIe.js";import{F as Ze}from"./funnel-DT4mmN3u.js";import{M as $e}from"./MultiSelect-9iwOrNey.js";function Q(t){return e.jsx(se,{disabled:!t.tooltip,label:t.tooltip,children:e.jsx(q,{variant:"ghost",size:"icon",className:"size-7.5",...t,children:e.jsx(ae,{className:"size-5"})})})}const X=({isNewInsert:t=!0,defaultValues:s,month:l,onDone:d,isModifying:o})=>{const{selectableBusinesses:i,fetching:n}=ne(),[{data:c,fetching:y,error:j}]=I({query:te}),{userContext:v}=x.useContext(H),[{data:b,fetching:F,error:R}]=I({query:oe}),[{data:D,fetching:M,error:C}]=I({query:z,variables:{employerId:v?.context.adminBusinessId??""}}),[p,N]=x.useState([]),[A,T]=x.useState([]),[K,ee]=x.useState([]),P=s?.month??l,Z=G({defaultValues:{...s,month:P}}),{control:m,handleSubmit:$,formState:{dirtyFields:O},setValue:B}=Z;x.useEffect(()=>{j&&f.error("Error",{description:"Oh no!, we have an error fetching pension funds! 🤥"})},[j]),x.useEffect(()=>{R&&f.error("Error",{description:"Oh no!, we have an error fetching training funds! 🤥"})},[R]),x.useEffect(()=>{C&&f.error("Error",{description:"Oh no!, we have an error employees! 🤥"})},[C]),x.useEffect(()=>{c?.allPensionFunds?.length&&N(c.allPensionFunds.map(r=>({value:r.id,label:r.name})).sort((r,a)=>r.label>a.label?1:-1))},[c,T]),x.useEffect(()=>{b?.allTrainingFunds?.length&&T(b.allTrainingFunds.map(r=>({value:r.id,label:r.name})).sort((r,a)=>r.label>a.label?1:-1))},[b,T]),x.useEffect(()=>{D?.employeesByEmployerId.length&&ee(D.employeesByEmployerId.filter(r=>!r.name.toLocaleLowerCase().includes("batched")).map(r=>({value:r.id,label:r.name})).sort((r,a)=>r.label>a.label?1:-1))},[D,T]),x.useEffect(()=>{!s?.employer&&v?.context.adminBusinessId&&B("employer",v.context.adminBusinessId,{shouldDirty:!0,shouldTouch:!0})},[B,s?.employer,v?.context.adminBusinessId]);const U=r=>{const a=ge(r,O);if(!(t&&(!a?.directPaymentAmount||!a?.employeeId||!a?.employer||!a?.month)))if(a&&Object.keys(a).length>0){if(!t){if(!s)return;a.employeeId??=s.employeeId,a.month??=s.month}d(a)}else d()};function re(r){B("month",E(r,"yyyy-MM-dd"),{shouldDirty:!0,shouldTouch:!0})}return e.jsx(le,{...Z,children:e.jsxs("form",{onSubmit:$(U),children:[e.jsx("div",{className:"flex-row px-10 h-max justify-start block",children:e.jsxs(ie,{cols:4,children:[e.jsxs("div",{className:"flex-column h-max justify-start block",children:[e.jsx(V,{defaultDate:P?new Date(P):void 0,defaultValue:P?new Date(P):void 0,onChange:re,popoverProps:{withinPortal:!0}}),e.jsx(u,{name:"employer",control:m,defaultValue:s?.employer,rules:{required:"Required"},render:({field:r,fieldState:a})=>e.jsx(k,{...r,data:i,value:r.value,disabled:n,label:"Employer",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:a.error?.message})}),e.jsx(de,{name:"chargeId",control:m,defaultValue:s?.chargeId,rules:{pattern:{value:ce,message:"Invalid UUID"}},render:({field:r})=>e.jsxs(me,{children:[e.jsx(ue,{children:"Charge ID"}),e.jsx(xe,{children:e.jsx(ye,{...r,value:r.value??void 0})}),e.jsx(pe,{})]})}),e.jsx(u,{name:"employeeId",control:m,defaultValue:s?.employeeId,rules:{required:"Required"},render:({field:r,fieldState:a})=>e.jsx(k,{...r,data:K,value:r.value,disabled:M,label:"Employee",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:a.error?.message})})]}),e.jsxs("div",{className:"flex-row px-10 h-max justify-start block",children:[e.jsx(u,{name:"baseSalary",control:m,defaultValue:s?.baseSalary,render:({field:r,fieldState:a})=>e.jsx(g,{...r,value:r.value??void 0,error:a.error?.message,label:"Base Salary",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"globalAdditionalHours",control:m,defaultValue:s?.globalAdditionalHours,render:({field:r,fieldState:a})=>e.jsx(g,{...r,value:r.value??void 0,error:a.error?.message,label:"Global Additional Hours",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"bonus",control:m,defaultValue:s?.bonus,render:({field:r,fieldState:a})=>e.jsx(g,{...r,value:r.value??void 0,error:a.error?.message,label:"Bonus",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"gift",control:m,defaultValue:s?.gift,render:({field:r,fieldState:a})=>e.jsx(g,{...r,value:r.value??void 0,error:a.error?.message,label:"Gift",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"travelAndSubsistence",control:m,defaultValue:s?.travelAndSubsistence,render:({field:r,fieldState:a})=>e.jsx(g,{...r,value:r.value??void 0,error:a.error?.message,label:"Travel and Subsistence",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"recovery",control:m,defaultValue:s?.recovery,render:({field:r,fieldState:a})=>e.jsx(g,{...r,value:r.value??void 0,error:a.error?.message,label:"Recovery",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency"}})}),e.jsx(u,{name:"vacationTakeout",control:m,defaultValue:s?.vacationTakeout,render:({field:r,fieldState:a})=>e.jsx(g,{...r,value:r.value??void 0,error:a.error?.message,label:"Vacation Takeout",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"directPaymentAmount",control:m,defaultValue:s?.directPaymentAmount,rules:{required:"Required"},render:({field:r,fieldState:a})=>e.jsx(g,{...r,value:r.value??void 0,error:a.error?.message,label:"Direct Payment",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})})]}),e.jsxs("div",{className:"flex-row px-10 h-max justify-start block",children:[e.jsx(u,{name:"pensionFundId",control:m,defaultValue:s?.pensionFundId,render:({field:r,fieldState:a})=>e.jsx(k,{...r,data:p,value:r.value,disabled:y,label:"Pension Fund",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:a.error?.message})}),e.jsx(u,{name:"pensionEmployeeAmount",control:m,defaultValue:s?.pensionEmployeeAmount,render:({field:r,fieldState:a})=>e.jsx(g,{...r,value:r.value??void 0,error:a.error?.message,label:"Pension Employee Amount",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"pensionEmployeePercentage",control:m,defaultValue:s?.pensionEmployeePercentage,render:({field:{value:r,...a},fieldState:h})=>e.jsx(S,{...a,hideControls:!0,precision:2,removeTrailingZeros:!0,rightSection:"%",value:r??void 0,error:h.error?.message,label:"Pension Employee Percentage"})}),e.jsx(u,{name:"pensionEmployerAmount",control:m,defaultValue:s?.pensionEmployerAmount,render:({field:r,fieldState:a})=>e.jsx(g,{...r,value:r.value??void 0,error:a.error?.message,label:"Pension Employer Amount",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"pensionEmployerPercentage",control:m,defaultValue:s?.pensionEmployerPercentage,render:({field:{value:r,...a},fieldState:h})=>e.jsx(S,{...a,hideControls:!0,precision:2,removeTrailingZeros:!0,rightSection:"%",value:r??void 0,error:h.error?.message,label:"Pension Employer Percentage"})})]}),e.jsxs("div",{className:"flex-row px-10 h-max justify-start block",children:[e.jsx(u,{name:"compensationsEmployerAmount",control:m,defaultValue:s?.compensationsEmployerAmount,render:({field:r,fieldState:a})=>e.jsx(g,{...r,value:r.value??void 0,error:a.error?.message,label:"Compensations Amount",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"compensationsEmployerPercentage",control:m,defaultValue:s?.compensationsEmployerPercentage,render:({field:{value:r,...a},fieldState:h})=>e.jsx(S,{...a,hideControls:!0,precision:2,removeTrailingZeros:!0,rightSection:"%",value:r??void 0,error:h.error?.message,label:"Compensations Percentage"})})]}),e.jsxs("div",{className:"flex-row px-10 h-max justify-start block",children:[e.jsx(u,{name:"trainingFundId",control:m,defaultValue:s?.trainingFundId,render:({field:r,fieldState:a})=>e.jsx(k,{...r,data:A,value:r.value,disabled:F,label:"Training Fund",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:a.error?.message})}),e.jsx(u,{name:"trainingFundEmployeeAmount",control:m,defaultValue:s?.trainingFundEmployeeAmount,render:({field:r,fieldState:a})=>e.jsx(g,{...r,value:r.value??void 0,error:a.error?.message,label:"Training Employee Amount",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"trainingFundEmployeePercentage",control:m,defaultValue:s?.trainingFundEmployeePercentage,render:({field:{value:r,...a},fieldState:h})=>e.jsx(S,{...a,hideControls:!0,precision:2,removeTrailingZeros:!0,rightSection:"%",value:r??void 0,error:h.error?.message,label:"Training Employee Percentage"})}),e.jsx(u,{name:"trainingFundEmployerAmount",control:m,defaultValue:s?.trainingFundEmployerAmount,render:({field:r,fieldState:a})=>e.jsx(g,{...r,value:r.value??void 0,error:a.error?.message,label:"Training Employer Amount",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"trainingFundEmployerPercentage",control:m,defaultValue:s?.trainingFundEmployerPercentage,render:({field:{value:r,...a},fieldState:h})=>e.jsx(S,{...a,hideControls:!0,precision:2,removeTrailingZeros:!0,rightSection:"%",value:r??void 0,error:h.error?.message,label:"Training Employer Percentage"})})]}),e.jsxs("div",{className:"flex-row px-10 h-max justify-start block",children:[e.jsx(u,{name:"socialSecurityAmountEmployee",control:m,defaultValue:s?.socialSecurityAmountEmployee,render:({field:r,fieldState:a})=>e.jsx(g,{...r,value:r.value??void 0,error:a.error?.message,label:"Social Security - Employee",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"socialSecurityAmountEmployer",control:m,defaultValue:s?.socialSecurityAmountEmployer,render:({field:r,fieldState:a})=>e.jsx(g,{...r,value:r.value??void 0,error:a.error?.message,label:"Social Security - Employer",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"healthPaymentAmount",control:m,defaultValue:s?.healthPaymentAmount,render:({field:r,fieldState:a})=>e.jsx(g,{...r,value:r.value??void 0,error:a.error?.message,label:"Health Insurance",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})})]}),e.jsxs("div",{className:"flex-row px-10 h-max justify-start block",children:[e.jsx(u,{name:"taxAmount",control:m,defaultValue:s?.taxAmount,render:({field:r,fieldState:a})=>e.jsx(g,{...r,value:r.value??void 0,error:a.error?.message,label:"Income Tax",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})}),e.jsx(u,{name:"zkufot",control:m,defaultValue:s?.zkufot,render:({field:r,fieldState:a})=>e.jsx(g,{...r,value:r.value??void 0,error:a.error?.message,precision:0,label:"Notional Expense",removeTrailingZeros:!0,currencyCodeProps:{value:"ILS",label:"Currency",disabled:!0}})})]}),e.jsxs("div",{className:"flex-row px-10 h-max justify-start block",children:[e.jsx(u,{name:"workDays",control:m,defaultValue:s?.workDays,render:({field:{value:r,...a},fieldState:h})=>e.jsx(S,{...a,hideControls:!0,precision:2,removeTrailingZeros:!0,value:r??void 0,error:h.error?.message,label:"Work Days"})}),e.jsx(u,{name:"addedVacationDays",control:m,defaultValue:s?.addedVacationDays,render:({field:{value:r,...a},fieldState:h})=>e.jsx(S,{...a,hideControls:!0,precision:2,removeTrailingZeros:!0,value:r??void 0,error:h.error?.message,label:"Added Vacation Days"})}),e.jsx(u,{name:"vacationDaysBalance",control:m,defaultValue:s?.vacationDaysBalance,render:({field:{value:r,...a},fieldState:h})=>e.jsx(S,{...a,hideControls:!0,precision:2,removeTrailingZeros:!0,value:r??void 0,error:h.error?.message,label:"Vacation Days Balance"})}),e.jsx(u,{name:"sicknessDaysBalance",control:m,defaultValue:s?.sicknessDaysBalance,render:({field:{value:r,...a},fieldState:h})=>e.jsx(S,{...a,hideControls:!0,precision:2,removeTrailingZeros:!0,value:r??void 0,error:h.error?.message,label:"Sickness Days Balance"})})]})]})}),e.jsxs("div",{className:"mt-10 mb-5 flex justify-center gap-5",children:[e.jsx("button",{type:"submit",onClick:()=>$(U),className:"mt-8 text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg",disabled:o||Object.keys(O).length===0,children:"Accept"}),e.jsx("button",{type:"button",className:"mt-8 text-white bg-rose-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-rose-600 rounded-sm text-lg",onClick:()=>d(),children:"Cancel"})]})]})})},Oe="updateSalaryRecord",Ue=()=>{const[{fetching:t},s]=W(he),l=x.useCallback(async d=>{const o=`Error updating salary record [${d.salaryRecord.month}] employee [${d.salaryRecord.employeeId}]`,i=Oe;f.loading("Updating Salary Record",{id:i});try{const n=await s(d),c=Y(n,o,i,"updateSalaryRecord");if(c)return f.success("Success",{id:i,description:"Salary record was updated"}),c.updateSalaryRecord.salaryRecord}catch(n){console.error(`${o}: ${n}`),f.error("Error",{id:i,description:o,duration:1e5,closeButton:!0})}},[s]);return{fetching:t,updateSalaryRecord:l}},qe=({recordVariables:t,onDone:s})=>t?e.jsx(He,{recordVariables:t,onDone:s}):null,He=({recordVariables:t,onDone:s})=>{const{updateSalaryRecord:l,fetching:d}=Ue(),[{data:o,fetching:i}]=I({query:je,variables:{employeeIDs:[t.employeeId],month:E(new Date(t.month),"yyyy-MM-dd")}}),n=o?.salaryRecordsByDates?.[0],c=x.useCallback(j=>{s(),j&&l({salaryRecord:j})},[s,l]);if(!n?.employer?.id||!n?.employee?.id)return e.jsx(e.Fragment,{});const y={addedVacationDays:n?.vacationDays?.added,baseSalary:n?.baseAmount?.raw,bonus:n?.bonus?.raw,chargeId:n?.charge?.id,compensationsEmployerAmount:n?.compensationsAmount?.raw,compensationsEmployerPercentage:n?.compensationsPercentage,directPaymentAmount:n?.directAmount?.raw,employer:n.employer.id,employeeId:n.employee.id,gift:n?.gift?.raw,globalAdditionalHours:n?.globalAdditionalHoursAmount?.raw,healthPaymentAmount:n?.healthInsuranceAmount?.raw,month:n?.month,pensionEmployeeAmount:n?.pensionEmployeeAmount?.raw,pensionEmployeePercentage:n?.pensionEmployeePercentage,pensionEmployerAmount:n?.pensionEmployerAmount?.raw,pensionEmployerPercentage:n?.pensionEmployerPercentage,pensionFundId:n?.pensionFund?.id,recovery:n?.recovery?.raw,sicknessDaysBalance:n?.sicknessDays?.balance,socialSecurityAmountEmployee:n?.socialSecurityEmployeeAmount?.raw,socialSecurityAmountEmployer:n?.socialSecurityEmployerAmount?.raw,taxAmount:n?.incomeTaxAmount?.raw,trainingFundEmployeeAmount:n?.trainingFundEmployeeAmount?.raw,trainingFundEmployeePercentage:n?.trainingFundEmployeePercentage,trainingFundEmployerAmount:n?.trainingFundEmployerAmount?.raw,trainingFundEmployerPercentage:n?.trainingFundEmployerPercentage,trainingFundId:n?.trainingFund?.id,travelAndSubsistence:n?.travelAndSubsistence?.raw,vacationDaysBalance:n?.vacationDays?.balance,vacationTakeout:n?.vacationTakeout?.raw,workDays:n?.workDays,zkufot:n?.notionalExpense?.raw};return e.jsx(_,{modalSize:"fit-content",position:"bottom",title:e.jsxs("div",{className:"flex flex-row mx-3 pt-3 sm:text-1xl gap-10",children:[e.jsx("h1",{className:"sm:text-2xl font-small text-gray-900",children:"Edit Salary Record:"}),e.jsxs("div",{className:"flex flex-row gap-2",children:["month: ",t.month," employeeId: ",t.employeeId]})]}),opened:!!t,onClose:s,children:i||!n?e.jsx(fe,{className:"flex self-center my-5",color:"dark",size:"xl",variant:"dots"}):e.jsx(X,{isNewInsert:!1,defaultValues:y,onDone:c,isModifying:d})})},ze="insertSalaryRecords",Ge=()=>{const[{fetching:t},s]=W(ve),l=x.useCallback(async d=>{const o=ze;if(f.loading("Adding salary record",{id:o}),!d.salaryRecords||Array.isArray(d.salaryRecords)&&d.salaryRecords.length===0){f.error("Error",{id:o,description:"No salary records to insert",duration:1e5,closeButton:!0});return}const i=Array.isArray(d.salaryRecords)?d.salaryRecords[0]:d.salaryRecords;if(!i?.directPaymentAmount||!i?.employeeId||!i?.employer||!i?.month){f.error("Error",{id:o,description:"Missing required salary record fields",duration:1e5,closeButton:!0});return}const n=`Error adding salary record [${i.month}] employee [${i.employeeId}]`;try{const c=await s(d),y=Y(c,n,o,"insertSalaryRecords");if(y)return f.success("Success",{id:o,description:"Salary record was added"}),y.insertSalaryRecords.salaryRecords[0]}catch(c){console.error(`${n}: ${c}`),f.error("Error",{id:o,description:n,duration:1e5,closeButton:!0})}},[s]);return{fetching:t,insertSalaryRecord:l}},Ve=({insertSalaryRecordParams:t,setInsertSalaryRecord:s})=>{const{insertSalaryRecord:l,fetching:d}=Ge(),o=x.useCallback(i=>{i&&l({salaryRecords:[i]}),s(void 0)},[s,l]);return e.jsx(_,{modalSize:"40%",position:"bottom",title:e.jsx("div",{className:"flex flex-row mx-3 pt-3 sm:text-1xl gap-10",children:e.jsx("h1",{className:"sm:text-2xl font-small text-gray-900",children:"Insert Salary Record:"})}),opened:!!t,onClose:()=>s(void 0),children:e.jsx(X,{isNewInsert:!0,onDone:o,isModifying:d,month:t.month})})};function L(){const t=new Date,s=E(t,"yyyy-MM-dd"),l=E(be(t),"yyyy-MM-dd");return{fromDate:s,toDate:l}}function We({filter:t,setFilter:s,closeModal:l}){const{control:d,handleSubmit:o,setValue:i}=G({defaultValues:{...t}}),[n,c]=x.useState([]),{userContext:y}=x.useContext(H),[{data:j,fetching:v,error:b},F]=I({query:z,variables:{employerId:y?.context.adminBusinessId??""},pause:!0});x.useEffect(()=>{F()},[y?.context.adminBusinessId,F]),x.useEffect(()=>{b&&f.error("Error",{description:"Oh no!, we have an error fetching employees! 🤥"})},[b]);const R=p=>{p.employeeIDs?.length===0&&delete p.employeeIDs,s(p),l()};function D(){s({...L()}),l()}x.useEffect(()=>{j?.employeesByEmployerId.length&&c(j.employeesByEmployerId.filter(p=>!p.name.toLocaleLowerCase().includes("batched")).map(p=>({value:p.id,label:p.name})).sort((p,N)=>p.label>N.label?1:-1))},[j,c]);function M([p,N]){if(N){const A=new Date(N.getFullYear(),N.getMonth()+1,0);i("toDate",E(A,"yyyy-MM-dd"))}if(p){const A=new Date(p.getFullYear(),p.getMonth(),1);i("fromDate",E(A,"yyyy-MM-dd"))}}const C=L();return e.jsxs(e.Fragment,{children:[v?e.jsx("div",{children:"Loading..."}):e.jsx("div",{}),e.jsxs("form",{onSubmit:o(R),children:[e.jsx(V,{type:"range",numberOfColumns:2,defaultValue:[new Date(t?.fromDate??C.fromDate),new Date(t?.toDate??C.toDate)],defaultDate:new Date(t?.fromDate??C.fromDate),onChange:M,popoverProps:{withinPortal:!0}}),e.jsx(u,{name:"employeeIDs",control:d,defaultValue:t.employeeIDs,render:({field:p,fieldState:N})=>e.jsx($e,{...p,data:n,value:p.value??[],disabled:v,label:"Employees",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:N.error?.message})}),e.jsxs("div",{className:"flex justify-center mt-5 gap-3",children:[e.jsx("button",{type:"submit",disabled:v,className:"text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg",children:"Filter"}),e.jsx("button",{type:"button",className:"text-white bg-orange-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-orange-600 rounded-sm text-lg",onClick:D,children:"Clear"}),e.jsx("button",{type:"button",className:"text-white bg-rose-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-rose-600 rounded-sm text-lg",onClick:l,children:"Cancel"})]})]})]})}function Ye({filter:t,setFilter:s}){const[l,d]=x.useState(!1),{get:o,set:i}=J();x.useEffect(()=>{const c=Ne(t)?null:encodeURIComponent(JSON.stringify(t)),y=o("salariesFilters");c!==y&&i("salariesFilters",c)},[t,o,i]);const n=x.useCallback(c=>{Se(c,t)||s(c)},[t,s]);return e.jsxs("div",{className:"flex flex-row gap-5 items-center",children:[e.jsx(Le,{opened:l,onClose:()=>d(!1),content:e.jsx(We,{filter:t,setFilter:n,closeModal:()=>d(!1)}),modalSize:"xl"}),e.jsx(q,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>d(!0),children:e.jsx(Ze,{className:"size-5"})})]})}const _e=({month:t,setInsertSalaryRecord:s})=>{const l=E(new Date(t),"MMMM yyyy");return e.jsx("tr",{tabIndex:0,className:"h-16 rounded-sm",children:e.jsx("td",{colSpan:100,children:e.jsxs("div",{className:"flex justify-between pl-5",children:[e.jsx("p",{className:"text-lg font-bold text-gray-800",children:l}),e.jsx("div",{className:"flex items-center",children:e.jsx("div",{className:"flex flex-col",children:e.jsx(Q,{onClick:s})})})]})})})},Je=({data:t})=>{const{employee:s,month:l}=w(Ee,t),d=E(new Date(l),"MMMM yyyy");return e.jsx("td",{className:"",children:e.jsx("div",{className:"flex items-center pl-5",children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("p",{className:"text-base font-bold text-gray-800",children:s?.name}),e.jsx("p",{className:"text-base font-medium text-gray-800",children:d})]})})})},Qe=({data:t})=>{const{pensionEmployeeAmount:s,pensionEmployeePercentage:l,pensionEmployerAmount:d,pensionEmployerPercentage:o,compensationsAmount:i,compensationsPercentage:n,pensionFund:c,trainingFund:y,trainingFundEmployeeAmount:j,trainingFundEmployeePercentage:v,trainingFundEmployerAmount:b,trainingFundEmployerPercentage:F}=w(we,t);return e.jsx("td",{className:"pl-5",children:e.jsx("div",{className:"flex items-center",children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("p",{className:"text-md font-bold text-gray-800",children:"Pension Fund"}),e.jsx("p",{className:"text-md font-medium text-gray-800",children:c?.name}),!!s?.raw&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Employee Part:"}),e.jsxs("p",{className:"text-sm leading-none text-gray-600 ml-2",children:[s?.formatted,l&&` (${l}%)`]})]}),!!d?.raw&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Employer Part:"}),e.jsxs("p",{className:"text-sm leading-none text-gray-600 ml-2",children:[d?.formatted,o&&` (${o}%)`]})]}),!!i?.raw&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Compensations Amount:"}),e.jsxs("p",{className:"text-sm leading-none text-gray-600 ml-2",children:[i?.formatted,n&&` (${n}%)`]})]}),e.jsx("p",{className:"text-md font-bold text-gray-800 mt-2",children:"Training Fund"}),e.jsx("p",{className:"text-md font-medium text-gray-800",children:y?.name}),!!j?.raw&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Employee Part:"}),e.jsxs("p",{className:"text-sm leading-none text-gray-600 ml-2",children:[j?.formatted,v&&` (${v}%)`]})]}),!!b?.raw&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Employer Part:"}),e.jsxs("p",{className:"text-sm leading-none text-gray-600 ml-2",children:[b?.formatted,F&&` (${F}%)`]})]})]})})})},Xe=({data:t})=>{const{healthInsuranceAmount:s,socialSecurityEmployeeAmount:l,socialSecurityEmployerAmount:d,incomeTaxAmount:o,notionalExpense:i}=w(Fe,t),n=!!l||!!d;return e.jsx("td",{className:"pl-5",children:e.jsx("div",{className:"flex items-center pl-5",children:e.jsxs("div",{className:"flex flex-col",children:[n&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-md font-bold text-gray-800",children:"Social Security"}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Employee Part:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:l?.formatted})]}),e.jsx("p",{className:"text-md font-bold text-gray-800 mt-2",children:"Pension Fund"}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Employer Part:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:d?.formatted})]})]}),!!s?.raw&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-md font-bold text-gray-800 mt-2",children:"Health Insurance"}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Amount:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:s?.formatted})]})]}),(!!o?.raw||!!i?.raw)&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-md font-bold text-gray-800 mt-2",children:"Taxes"}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Income Tax:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:o?.formatted})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Notional Expense:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:i?.formatted})]})]})]})})})},Ke=({data:t})=>{const{baseAmount:s,directAmount:l,globalAdditionalHoursAmount:d,bonus:o,gift:i,recovery:n,vacationTakeout:c}=w(Ce,t);return e.jsx("td",{className:"pl-24",children:e.jsx("div",{className:"flex items-center",children:e.jsxs("div",{className:"flex flex-col",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Base Amount:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:s?.formatted})]}),e.jsxs("div",{className:"flex justify-between mb-2",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Global Extra Hours:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:d?.formatted})]}),!!o?.raw&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Bonus:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:o?.formatted})]}),!!i?.raw&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Gift:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:i?.formatted})]}),!!n?.raw&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Recovery:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:n?.formatted})]}),!!c?.raw&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Vacation Takeout:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:c?.formatted})]}),e.jsxs("div",{className:"flex justify-between mt-2",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Direct Amount:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:l?.formatted})]})]})})})},er=({data:t})=>{const{vacationDays:s,workDays:l,sicknessDays:d}=w(Ie,t),{added:o,taken:i,balance:n}=s??{},{balance:c}=d??{},y=!!o||!!i||!!n;return e.jsx("td",{className:"pl-5",children:e.jsx("div",{className:"flex items-center",children:e.jsxs("div",{className:"flex flex-col",children:[!!l&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-md leading-none text-gray-800",children:"Work Days:"}),e.jsx("div",{className:"flex justify-between",children:e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:l})})]}),y&&e.jsxs("div",{className:"flex flex-col",children:[e.jsx("p",{className:"text-md leading-none text-gray-800 mt-2",children:"Vacation Days:"}),!!o&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Added:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:o})]}),!!i&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Taken:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:i})]}),!!n&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:"Balance:"}),e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:n})]})]}),!!c&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-md leading-none text-gray-800 mt-2",children:"Sickness Days:"}),e.jsx("div",{className:"flex justify-between",children:e.jsx("p",{className:"text-sm leading-none text-gray-600 ml-2",children:c})})]})]})})})},rr=({setEditSalaryRecord:t,data:s})=>{const l=w(Ae,s);return e.jsxs(e.Fragment,{children:[e.jsxs("tr",{tabIndex:0,className:"h-16 border border-gray-100 hover:bg-gray-100 rounded-sm",children:[e.jsx(Je,{data:l}),e.jsx(Ke,{data:l}),e.jsx(Qe,{data:l}),e.jsx(Xe,{data:l}),e.jsx(er,{data:l}),e.jsx("td",{className:"pl-2",children:e.jsx("div",{className:"flex items-center",children:e.jsx("div",{className:"flex flex-col",children:e.jsx(De,{onClick:t})})})})]}),e.jsx("tr",{className:"h-3"})]})},sr=({setEditSalaryRecord:t,setInsertSalaryRecord:s,data:l})=>{const d=l?.map(o=>w(Pe,o))??[];return e.jsxs(e.Fragment,{children:[e.jsx("tr",{className:"h-3"}),e.jsx(_e,{month:d[0].month,setInsertSalaryRecord:s}),e.jsx("tr",{className:"h-3"}),d.map(o=>e.jsx(rr,{data:o,setEditSalaryRecord:()=>t(o.employee?.id)},`${o.month} ${o.employee?.id}`))]})},ar=({setEditSalaryRecord:t,setInsertSalaryRecord:s,data:l})=>{const d=x.useMemo(()=>{const o=l?.map(n=>w(Re,n))??[],i=new Map;return o.map(n=>{const{month:c}=n,y=i.get(c)??[];i.set(c,[...y,n])}),i},[l]);return e.jsx("div",{className:"sm:px-6 w-full",children:e.jsxs("div",{className:"bg-white py-4 md:py-7 px-4 md:px-8 xl:px-10",children:[e.jsxs("div",{className:"sm:flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center",children:[e.jsx("div",{className:"rounded-full focus:outline-hidden focus:ring-2 focus:bg-indigo-50 focus:ring-indigo-800",children:e.jsx("div",{className:"py-2 px-8 bg-indigo-100 text-indigo-700 rounded-full",children:e.jsx("p",{children:"All"})})}),e.jsx("div",{className:"rounded-full focus:outline-hidden focus:ring-2 focus:bg-indigo-50 focus:ring-indigo-800 ml-4 sm:ml-8",children:e.jsx("div",{className:"py-2 px-8 text-gray-600 hover:text-indigo-700 hover:bg-indigo-100 rounded-full ",children:e.jsx("p",{children:"Done"})})}),e.jsx("div",{className:"rounded-full focus:outline-hidden focus:ring-2 focus:bg-indigo-50 focus:ring-indigo-800 ml-4 sm:ml-8",children:e.jsx("div",{className:"py-2 px-8 text-gray-600 hover:text-indigo-700 hover:bg-indigo-100 rounded-full ",children:e.jsx("p",{children:"Pending"})})})]}),e.jsx("button",{className:"focus:ring-2 focus:ring-offset-2 focus:ring-indigo-600 mt-4 sm:mt-0 inline-flex items-start justify-start px-6 py-3 bg-indigo-700 hover:bg-indigo-600 focus:outline-hidden rounded-sm",children:e.jsx("p",{className:"text-sm font-medium leading-none text-white",children:"Add Task"})})]}),e.jsx("div",{className:"mt-7 overflow-x-auto",children:e.jsx("table",{className:"w-full whitespace-nowrap",children:e.jsx("tbody",{children:Array.from(d).map(([o,i])=>e.jsx(sr,{data:i,setEditSalaryRecord:n=>t(n?{month:o,employeeId:n}:void 0),setInsertSalaryRecord:()=>s({month:o})},o))})})})]})})},cr=()=>{const{setFiltersContext:t}=x.useContext(Te),[s,l]=x.useState(void 0),[d,o]=x.useState(void 0),{get:i}=J(),[n,c]=x.useState(i("salariesFilters")?JSON.parse(decodeURIComponent(i("salariesFilters"))):{...L()}),[{data:y,fetching:j}]=I({query:Me,variables:{...n}});return x.useEffect(()=>{t(e.jsxs("div",{className:"flex flex-row gap-x-5",children:[e.jsx(Ye,{filter:n,setFilter:c}),e.jsx(Q,{variant:"default",onClick:()=>o({})})]}))},[y,j,n,t,c]),e.jsxs(Be,{title:"Salaries",description:"View and manage salaries of employees.",children:[j?e.jsx(ke,{className:"h-10 w-10 animate-spin mr-2 self-center"}):e.jsx(ar,{setEditSalaryRecord:l,setInsertSalaryRecord:o,data:y?.salaryRecordsByDates}),e.jsx(qe,{recordVariables:s,onDone:()=>l(void 0)}),d&&e.jsx(Ve,{insertSalaryRecordParams:d,setInsertSalaryRecord:o})]})};export{cr as Salaries};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{r as h,bp as S,j as e,bq as N,B as y,G as $,br as k,a9 as R,W as O,bs as f,bt as D,bu as C,x as F,Y as A,Z as E,_ as z,$ as P,ai as M,bw as L,bm as w,T as B,b0 as j,aO as p,J as _,dp as V,cx as v,F as q,u as G,dq as U,dr as Z,L as H,ds as J}from"./index-
|
|
1
|
+
import{r as h,bp as S,j as e,bq as N,B as y,G as $,br as k,a9 as R,W as O,bs as f,bt as D,bu as C,x as F,Y as A,Z as E,_ as z,$ as P,ai as M,bw as L,bm as w,T as B,b0 as j,aO as p,J as _,dp as V,cx as v,F as q,u as G,dq as U,dr as Z,L as H,ds as J}from"./index-C3k8jflc.js";import{u as I}from"./use-url-query-BOxCMiZm.js";import{P as Q}from"./page-layout-x3aFVsg9.js";import{P as W}from"./modal-DNhi-EIe.js";import{F as K}from"./funnel-DT4mmN3u.js";import{M as T}from"./MultiSelect-9iwOrNey.js";import{D as X}from"./download-csv-button-DsnbHQxU.js";import{B as Y}from"./business-extended-info-DCsSJJtc.js";import{P as ee,a as te}from"./panel-top-open-B-b6XxK7.js";import{T as se}from"./Table-KlqUi970.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(W,{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(X,{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 +1 @@
|
|
|
1
|
-
import{r as m,bw as _,j as e,bq as k,B as I,bp as V,G as Q,br as q,cR as G,al as K,cS as z,bs as y,bv as A,bt as F,bu as B,x as S,u as R,gq as X,K as P,c as U,N as $,Q as J,ax as W,X as Y,F as Z,a9 as ee,au as ae,V as se,dH as te,gr as re,aO as ne}from"./index-C9fHUfnt.js";import{u as O}from"./use-url-query-BS26aRC-.js";import{P as oe}from"./page-layout-DZOekob-.js";import{k as ie,B as w,X as H,Y as le,l as ce,m as de,n as ue,o as me,p as pe,q as xe,r as ge}from"./chart-C5brdPZL.js";import{P as he}from"./modal-weFgvkj_.js";import{F as fe}from"./funnel-6jLbjYGX.js";import{M as E}from"./MultiSelect-Cyxk2rHZ.js";import{T as be}from"./index-CVs7a0UT.js";import{s as je}from"./sub-ImDFXoGZ.js";import"./sequential-CAnleQny.js";import"./similar-transactions-modal-CNAIbrow.js";import"./addDays-CALX0aWH.js";import"./list-plus-Bopa-Y0W.js";import"./tooltip-D2vdZwho.js";import"./subMonths-CuWsjtWU.js";var ye=ie({chartName:"BarChart",GraphicalChild:w,defaultTooltipEventType:"axis",validateTooltipEventTypes:["axis","item"],axisComponents:[{axisType:"xAxis",AxisComp:H},{axisType:"yAxis",AxisComp:le}],formatAxisMap:ce});function ve(s){return!s||V(s)?null:encodeURIComponent(JSON.stringify(s))}const L="balanceReportFilters",x={MONTHLY:"Monthly",BI_MONTHLY:"Bi-monthly",QUARTERLY:"Quarterly",SEMI_ANNUALLY:"Semi-Annually",ANNUALLY:"Annually"};function Ce({filter:s,setFilter:i,closeModal:c}){const{control:t,handleSubmit:r,watch:g}=Q({defaultValues:{...s}}),{selectableBusinesses:b,fetching:h}=q(),{selectableFinancialEntities:f,fetching:v}=G(),{selectableTags:p,fetching:j}=K(),M=a=>{i(a),c()},C=g("excludedTags"),o=m.useMemo(()=>p.filter(a=>!C.includes(a.value)),[C,p]),d=g("includedTags"),n=m.useMemo(()=>p.filter(a=>!d.includes(a.value)),[d,p]);return e.jsxs("form",{onSubmit:r(M),children:[e.jsxs(z,{cols:2,children:[e.jsx(y,{name:"ownerId",control:t,defaultValue:s?.ownerId,render:({field:a,fieldState:l})=>e.jsx(A,{...a,data:b,value:a.value,disabled:h,label:"Owners",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:l.error?.message,withinPortal:!0})}),e.jsx(y,{name:"fromDate",control:t,defaultValue:s?.fromDate,rules:{pattern:{value:F,message:"Date must be im format yyyy-mm-dd"}},render:({field:a,fieldState:l})=>e.jsx(B,{...a,onChange:u=>{const T=u?typeof u=="string"?u:S(u,"yyyy-MM-dd"):void 0;T!==a.value&&a.onChange(T)},value:a.value?new Date(a.value):void 0,error:l.error?.message,label:"From Date",popoverProps:{withinPortal:!0}})}),e.jsx(y,{name:"toDate",control:t,defaultValue:s?.toDate,rules:{pattern:{value:F,message:"Date must be im format yyyy-mm-dd"}},render:({field:a,fieldState:l})=>e.jsx(B,{...a,onChange:u=>{const T=u?typeof u=="string"?u:S(u,"yyyy-MM-dd"):void 0;T!==a.value&&a.onChange(T)},value:a.value?new Date(a.value):void 0,error:l.error?.message,label:"To Date",popoverProps:{withinPortal:!0}})}),e.jsx(y,{name:"period",control:t,defaultValue:x.MONTHLY,render:({field:a,fieldState:l})=>e.jsx(A,{...a,data:Object.values(x).map(u=>({value:u,label:u})),value:a.value,label:"Period",maxDropdownHeight:160,error:l.error?.message,withinPortal:!0})}),e.jsx(y,{name:"excludedCounterparties",control:t,defaultValue:s.excludedCounterparties,render:({field:a,fieldState:l})=>e.jsx(E,{...a,data:f,value:a.value??[],disabled:v,label:"Excluded Counterparties",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:l.error?.message,withinPortal:!0})}),e.jsx(y,{name:"includedTags",control:t,defaultValue:s.includedTags,render:({field:a,fieldState:l})=>e.jsx(E,{...a,data:o,value:a.value??[],disabled:j,label:"Included Tags",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:l.error?.message,withinPortal:!0})}),e.jsx(y,{name:"excludedTags",control:t,defaultValue:s.excludedTags,render:({field:a,fieldState:l})=>e.jsx(E,{...a,data:n,value:a.value??[],disabled:j,label:"Excluded Tags",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:l.error?.message,withinPortal:!0})})]}),e.jsxs("div",{className:"flex justify-center mt-5 gap-3",children:[e.jsx("button",{type:"submit",disabled:h,className:"text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg",children:"Filter"}),e.jsx("button",{type:"button",className:"text-white bg-rose-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-rose-600 rounded-sm text-lg",onClick:c,children:"Cancel"})]})]})}function Te({filter:s,setFilter:i,initiallyOpened:c=!1}){const[t,r]=m.useState(c),[g,b]=m.useState(!!s),{get:h,set:f}=O();m.useEffect(()=>{const p=ve(s),j=h(L);p!==j&&f(L,p)},[s,h,f]);const v=m.useCallback(p=>{_(p,s)||(i(p),b(!!p))},[s,i]);return e.jsxs("div",{className:"flex flex-row gap-5 items-center",children:[e.jsx(he,{opened:t,onClose:()=>r(!1),content:e.jsx(Ce,{filter:s,setFilter:v,closeModal:()=>r(!1)}),modalSize:"xl"}),e.jsx(k,{inline:!0,size:16,disabled:!g,children:e.jsx(I,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>r(!0),children:e.jsx(fe,{className:"size-5"})})})]})}const Ne=({period:s,transactionIDs:i,onCloseExtendedTransactions:c})=>{const[{data:t,fetching:r}]=R({query:X,variables:{transactionIDs:i}}),g=m.useMemo(()=>t?.transactionsByIDs?i.map(b=>t?.transactionsByIDs.find(h=>h.id===b)).filter(Boolean):[],[t,i]);return e.jsx(P,{className:"mt-5 w-full",children:r?e.jsx(U,{}):e.jsxs(e.Fragment,{children:[e.jsx($,{children:e.jsxs(J,{className:"flex justify-between",children:[e.jsxs("span",{children:[s," Transactions"]}),e.jsx(I,{variant:"link",onClick:c,children:e.jsx(W,{className:"h-4 w-4"})})]})}),e.jsx(Y,{children:e.jsx(be,{transactionsProps:g})})]})})},N={income:{label:"Income",color:"rgba(0, 255, 50, 0.5)"},expense:{label:"Expense",color:"rgba(255, 0, 0, 0.5)"},delta:{label:"Delta",color:"rgba(0, 30, 255, 0.5)"},cumulative:{label:"Cumulative Balance",color:"rgba(100, 0, 255, 0.5)"}};function we(s,i,c){switch(c){case x.MONTHLY:{const t=String(i).padStart(2,"0");return`${s}-${t}`}case x.BI_MONTHLY:{const t=i%2===0?i-1:i,r=String(t).padStart(2,"0");return`${s}-${r}`}case x.QUARTERLY:{const t=Math.ceil(i/3);return`${s}-Q${t}`}case x.SEMI_ANNUALLY:{const t=i>6?2:1;return`${s}-H${t}`}case x.ANNUALLY:return String(s)}}function Me(s,i){switch(i){case x.MONTHLY:{const[c,t]=s.split("-");return`${t}/${c}`}case x.BI_MONTHLY:{const[c,t]=s.split("-"),r=Number(t)+1,g=String(r).padStart(2,"0");return`${t}-${g}/${c}`}case x.QUARTERLY:{const[c,t]=s.split("-");return`${t}, ${c}`}case x.SEMI_ANNUALLY:{const[c,t]=s.split("-");return`${t}, ${c}`}case x.ANNUALLY:return s}}const D=te(ne.Usd),_e=()=>{const{setFiltersContext:s}=m.useContext(Z),{userContext:i}=m.useContext(ee),{get:c}=O(),t=m.useMemo(()=>{const o={ownerId:i?.context.adminBusinessId,toDate:S(new Date,"yyyy-MM-dd"),period:x.MONTHLY,fromDate:S(je(new Date,{years:1}),"yyyy-MM-dd"),excludedCounterparties:[],includedTags:[],excludedTags:[]},d=c(L);if(d)try{return JSON.parse(decodeURIComponent(d))}catch(n){console.log("Error parsing balance report filters from URL:",n)}return o},[i?.context.adminBusinessId,c]),[r,g]=m.useState(t),[b,h]=m.useState(void 0),[f,v]=m.useState(Object.keys(N)),p=m.useMemo(()=>{const{ownerId:o,fromDate:d,toDate:n}=r;return{ownerId:o,fromDate:d,toDate:n}},[r]),[{data:j,fetching:M}]=R({query:re,variables:p,pause:!r});m.useEffect(()=>{s(e.jsxs("div",{className:"flex flex-row gap-x-5",children:[e.jsx(Te,{filter:r,setFilter:g,initiallyOpened:!r}),e.jsx(ae,{options:Object.entries(N).map(([o,d])=>({label:d.label,value:o})),onValueChange:v,defaultValue:f,placeholder:"Select Data Sets",variant:"default",maxCount:1})]})),h(void 0)},[j,M,r,s,g,f]),m.useEffect(()=>{g(o=>({...o,ownerId:i?.context.adminBusinessId}))},[i]);const C=m.useMemo(()=>{if(!j?.transactionsForBalanceReport)return[];const o=new Map;j.transactionsForBalanceReport.map(n=>{if(n.counterparty?.id&&(!n.isFee&&i?.context.financialAccountsBusinessesIds?.includes(n.counterparty.id)||r.excludedCounterparties?.includes(n.counterparty.id))||r.includedTags.length>0&&(!n.charge?.tags||n.charge.tags.length===0||!n.charge.tags.some(u=>r.includedTags.includes(u.id)))||r.excludedTags.length>0&&n.charge?.tags.length&&n.charge.tags.some(u=>r.excludedTags.includes(u.id)))return;const a=we(n.year,n.month,r.period);o.has(a)||o.set(a,{income:0,expense:0,delta:0,transactions:[]});const l=o.get(a);n.amountUsd.raw>0?l.income+=n.amountUsd.raw:l.expense+=n.amountUsd.raw,l.delta+=n.amountUsd.raw,l.transactions.push(n)});let d=0;return Array.from(o.entries()).sort((n,a)=>n[0].localeCompare(a[0])).map(([n,a])=>(d+=a.delta,{period:n,income:a.income,expense:a.expense,delta:a.delta,cumulative:d,transactions:a.transactions.sort((l,u)=>Math.abs(u.amountUsd.raw)-Math.abs(l.amountUsd.raw))}))},[j,r.period,r.excludedCounterparties,i?.context.financialAccountsBusinessesIds,r.includedTags,r.excludedTags]);return e.jsx(oe,{title:"Balance Report",description:"Accounts periodical balance",children:M?e.jsx(U,{}):e.jsxs(e.Fragment,{children:[e.jsxs(P,{className:"w-full",children:[e.jsx($,{children:e.jsx(se,{children:"Click specific period to expand it's transactions data"})}),e.jsx(Y,{children:e.jsx(de,{config:N,className:"h-150 w-full",children:e.jsxs(ye,{accessibilityLayer:!0,data:C,onClick:o=>h(o.activeLabel),children:[e.jsx(ue,{vertical:!1}),e.jsx(H,{dataKey:"period",tickLine:!1,tickMargin:10,axisLine:!1,tickFormatter:o=>Me(o,r.period)}),e.jsx(me,{content:e.jsx(pe,{formatter:(o,d,n,a)=>{const l=`bg-[var(--color-${d})]`;return a<2?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:`${l} h-2.5 w-2.5 shrink-0 rounded-[2px]`}),N[d]?.label||d,e.jsx("div",{className:"ml-auto flex items-baseline gap-0.5 font-mono font-medium tabular-nums text-foreground",children:D.format(Number(o))})]}):e.jsxs("div",{className:"mt-1.5 flex basis-full items-center border-t pt-1.5 text-xs font-medium text-foreground",children:[e.jsx("div",{className:`h-2.5 w-2.5 shrink-0 rounded-[2px] mr-2 ${l}`}),N[d]?.label||d,e.jsx("div",{className:"ml-auto flex items-baseline gap-0.5 font-mono font-medium tabular-nums text-foreground",children:D.format(Number(o))})]})}})}),e.jsx(xe,{content:e.jsx(ge,{})}),f.includes("income")&&e.jsx(w,{dataKey:"income",fill:"var(--color-income)",radius:4}),f.includes("expense")&&e.jsx(w,{dataKey:"expense",fill:"var(--color-expense)",radius:4}),f.includes("delta")&&e.jsx(w,{dataKey:"delta",fill:"var(--color-delta)",radius:4}),f.includes("cumulative")&&e.jsx(w,{dataKey:"cumulative",fill:"var(--color-cumulative)",radius:4})]})})})]}),b&&e.jsx(Ne,{period:b,onCloseExtendedTransactions:()=>h(void 0),transactionIDs:C.find(o=>o.period===b)?.transactions.map(o=>o.id)??[]})]})})};export{_e as BalanceReport};
|
|
1
|
+
import{r as m,bw as _,j as e,bq as k,B as I,bp as V,G as Q,br as q,cR as G,al as K,cS as z,bs as y,bv as A,bt as F,bu as B,x as S,u as R,gq as X,K as P,c as U,N as $,Q as J,ax as W,X as Y,F as Z,a9 as ee,au as ae,V as se,dH as te,gr as re,aO as ne}from"./index-C3k8jflc.js";import{u as O}from"./use-url-query-BOxCMiZm.js";import{P as oe}from"./page-layout-x3aFVsg9.js";import{k as ie,B as w,X as H,Y as le,l as ce,m as de,n as ue,o as me,p as pe,q as xe,r as ge}from"./chart-DrNm6pqY.js";import{P as he}from"./modal-DNhi-EIe.js";import{F as fe}from"./funnel-DT4mmN3u.js";import{M as E}from"./MultiSelect-9iwOrNey.js";import{T as be}from"./index-B7Rl68zJ.js";import{s as je}from"./sub-CMuEnyTg.js";import"./sequential-CAnleQny.js";import"./similar-transactions-modal-C7aYlzhE.js";import"./addDays-C65N2SCe.js";import"./list-plus-2cRRgK1O.js";import"./tooltip-DG_b_ZsV.js";import"./subMonths-Cs2weYkL.js";var ye=ie({chartName:"BarChart",GraphicalChild:w,defaultTooltipEventType:"axis",validateTooltipEventTypes:["axis","item"],axisComponents:[{axisType:"xAxis",AxisComp:H},{axisType:"yAxis",AxisComp:le}],formatAxisMap:ce});function ve(s){return!s||V(s)?null:encodeURIComponent(JSON.stringify(s))}const L="balanceReportFilters",x={MONTHLY:"Monthly",BI_MONTHLY:"Bi-monthly",QUARTERLY:"Quarterly",SEMI_ANNUALLY:"Semi-Annually",ANNUALLY:"Annually"};function Ce({filter:s,setFilter:i,closeModal:c}){const{control:t,handleSubmit:r,watch:g}=Q({defaultValues:{...s}}),{selectableBusinesses:b,fetching:h}=q(),{selectableFinancialEntities:f,fetching:v}=G(),{selectableTags:p,fetching:j}=K(),M=a=>{i(a),c()},C=g("excludedTags"),o=m.useMemo(()=>p.filter(a=>!C.includes(a.value)),[C,p]),d=g("includedTags"),n=m.useMemo(()=>p.filter(a=>!d.includes(a.value)),[d,p]);return e.jsxs("form",{onSubmit:r(M),children:[e.jsxs(z,{cols:2,children:[e.jsx(y,{name:"ownerId",control:t,defaultValue:s?.ownerId,render:({field:a,fieldState:l})=>e.jsx(A,{...a,data:b,value:a.value,disabled:h,label:"Owners",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:l.error?.message,withinPortal:!0})}),e.jsx(y,{name:"fromDate",control:t,defaultValue:s?.fromDate,rules:{pattern:{value:F,message:"Date must be im format yyyy-mm-dd"}},render:({field:a,fieldState:l})=>e.jsx(B,{...a,onChange:u=>{const T=u?typeof u=="string"?u:S(u,"yyyy-MM-dd"):void 0;T!==a.value&&a.onChange(T)},value:a.value?new Date(a.value):void 0,error:l.error?.message,label:"From Date",popoverProps:{withinPortal:!0}})}),e.jsx(y,{name:"toDate",control:t,defaultValue:s?.toDate,rules:{pattern:{value:F,message:"Date must be im format yyyy-mm-dd"}},render:({field:a,fieldState:l})=>e.jsx(B,{...a,onChange:u=>{const T=u?typeof u=="string"?u:S(u,"yyyy-MM-dd"):void 0;T!==a.value&&a.onChange(T)},value:a.value?new Date(a.value):void 0,error:l.error?.message,label:"To Date",popoverProps:{withinPortal:!0}})}),e.jsx(y,{name:"period",control:t,defaultValue:x.MONTHLY,render:({field:a,fieldState:l})=>e.jsx(A,{...a,data:Object.values(x).map(u=>({value:u,label:u})),value:a.value,label:"Period",maxDropdownHeight:160,error:l.error?.message,withinPortal:!0})}),e.jsx(y,{name:"excludedCounterparties",control:t,defaultValue:s.excludedCounterparties,render:({field:a,fieldState:l})=>e.jsx(E,{...a,data:f,value:a.value??[],disabled:v,label:"Excluded Counterparties",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:l.error?.message,withinPortal:!0})}),e.jsx(y,{name:"includedTags",control:t,defaultValue:s.includedTags,render:({field:a,fieldState:l})=>e.jsx(E,{...a,data:o,value:a.value??[],disabled:j,label:"Included Tags",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:l.error?.message,withinPortal:!0})}),e.jsx(y,{name:"excludedTags",control:t,defaultValue:s.excludedTags,render:({field:a,fieldState:l})=>e.jsx(E,{...a,data:n,value:a.value??[],disabled:j,label:"Excluded Tags",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:l.error?.message,withinPortal:!0})})]}),e.jsxs("div",{className:"flex justify-center mt-5 gap-3",children:[e.jsx("button",{type:"submit",disabled:h,className:"text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg",children:"Filter"}),e.jsx("button",{type:"button",className:"text-white bg-rose-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-rose-600 rounded-sm text-lg",onClick:c,children:"Cancel"})]})]})}function Te({filter:s,setFilter:i,initiallyOpened:c=!1}){const[t,r]=m.useState(c),[g,b]=m.useState(!!s),{get:h,set:f}=O();m.useEffect(()=>{const p=ve(s),j=h(L);p!==j&&f(L,p)},[s,h,f]);const v=m.useCallback(p=>{_(p,s)||(i(p),b(!!p))},[s,i]);return e.jsxs("div",{className:"flex flex-row gap-5 items-center",children:[e.jsx(he,{opened:t,onClose:()=>r(!1),content:e.jsx(Ce,{filter:s,setFilter:v,closeModal:()=>r(!1)}),modalSize:"xl"}),e.jsx(k,{inline:!0,size:16,disabled:!g,children:e.jsx(I,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>r(!0),children:e.jsx(fe,{className:"size-5"})})})]})}const Ne=({period:s,transactionIDs:i,onCloseExtendedTransactions:c})=>{const[{data:t,fetching:r}]=R({query:X,variables:{transactionIDs:i}}),g=m.useMemo(()=>t?.transactionsByIDs?i.map(b=>t?.transactionsByIDs.find(h=>h.id===b)).filter(Boolean):[],[t,i]);return e.jsx(P,{className:"mt-5 w-full",children:r?e.jsx(U,{}):e.jsxs(e.Fragment,{children:[e.jsx($,{children:e.jsxs(J,{className:"flex justify-between",children:[e.jsxs("span",{children:[s," Transactions"]}),e.jsx(I,{variant:"link",onClick:c,children:e.jsx(W,{className:"h-4 w-4"})})]})}),e.jsx(Y,{children:e.jsx(be,{transactionsProps:g})})]})})},N={income:{label:"Income",color:"rgba(0, 255, 50, 0.5)"},expense:{label:"Expense",color:"rgba(255, 0, 0, 0.5)"},delta:{label:"Delta",color:"rgba(0, 30, 255, 0.5)"},cumulative:{label:"Cumulative Balance",color:"rgba(100, 0, 255, 0.5)"}};function we(s,i,c){switch(c){case x.MONTHLY:{const t=String(i).padStart(2,"0");return`${s}-${t}`}case x.BI_MONTHLY:{const t=i%2===0?i-1:i,r=String(t).padStart(2,"0");return`${s}-${r}`}case x.QUARTERLY:{const t=Math.ceil(i/3);return`${s}-Q${t}`}case x.SEMI_ANNUALLY:{const t=i>6?2:1;return`${s}-H${t}`}case x.ANNUALLY:return String(s)}}function Me(s,i){switch(i){case x.MONTHLY:{const[c,t]=s.split("-");return`${t}/${c}`}case x.BI_MONTHLY:{const[c,t]=s.split("-"),r=Number(t)+1,g=String(r).padStart(2,"0");return`${t}-${g}/${c}`}case x.QUARTERLY:{const[c,t]=s.split("-");return`${t}, ${c}`}case x.SEMI_ANNUALLY:{const[c,t]=s.split("-");return`${t}, ${c}`}case x.ANNUALLY:return s}}const D=te(ne.Usd),_e=()=>{const{setFiltersContext:s}=m.useContext(Z),{userContext:i}=m.useContext(ee),{get:c}=O(),t=m.useMemo(()=>{const o={ownerId:i?.context.adminBusinessId,toDate:S(new Date,"yyyy-MM-dd"),period:x.MONTHLY,fromDate:S(je(new Date,{years:1}),"yyyy-MM-dd"),excludedCounterparties:[],includedTags:[],excludedTags:[]},d=c(L);if(d)try{return JSON.parse(decodeURIComponent(d))}catch(n){console.log("Error parsing balance report filters from URL:",n)}return o},[i?.context.adminBusinessId,c]),[r,g]=m.useState(t),[b,h]=m.useState(void 0),[f,v]=m.useState(Object.keys(N)),p=m.useMemo(()=>{const{ownerId:o,fromDate:d,toDate:n}=r;return{ownerId:o,fromDate:d,toDate:n}},[r]),[{data:j,fetching:M}]=R({query:re,variables:p,pause:!r});m.useEffect(()=>{s(e.jsxs("div",{className:"flex flex-row gap-x-5",children:[e.jsx(Te,{filter:r,setFilter:g,initiallyOpened:!r}),e.jsx(ae,{options:Object.entries(N).map(([o,d])=>({label:d.label,value:o})),onValueChange:v,defaultValue:f,placeholder:"Select Data Sets",variant:"default",maxCount:1})]})),h(void 0)},[j,M,r,s,g,f]),m.useEffect(()=>{g(o=>({...o,ownerId:i?.context.adminBusinessId}))},[i]);const C=m.useMemo(()=>{if(!j?.transactionsForBalanceReport)return[];const o=new Map;j.transactionsForBalanceReport.map(n=>{if(n.counterparty?.id&&(!n.isFee&&i?.context.financialAccountsBusinessesIds?.includes(n.counterparty.id)||r.excludedCounterparties?.includes(n.counterparty.id))||r.includedTags.length>0&&(!n.charge?.tags||n.charge.tags.length===0||!n.charge.tags.some(u=>r.includedTags.includes(u.id)))||r.excludedTags.length>0&&n.charge?.tags.length&&n.charge.tags.some(u=>r.excludedTags.includes(u.id)))return;const a=we(n.year,n.month,r.period);o.has(a)||o.set(a,{income:0,expense:0,delta:0,transactions:[]});const l=o.get(a);n.amountUsd.raw>0?l.income+=n.amountUsd.raw:l.expense+=n.amountUsd.raw,l.delta+=n.amountUsd.raw,l.transactions.push(n)});let d=0;return Array.from(o.entries()).sort((n,a)=>n[0].localeCompare(a[0])).map(([n,a])=>(d+=a.delta,{period:n,income:a.income,expense:a.expense,delta:a.delta,cumulative:d,transactions:a.transactions.sort((l,u)=>Math.abs(u.amountUsd.raw)-Math.abs(l.amountUsd.raw))}))},[j,r.period,r.excludedCounterparties,i?.context.financialAccountsBusinessesIds,r.includedTags,r.excludedTags]);return e.jsx(oe,{title:"Balance Report",description:"Accounts periodical balance",children:M?e.jsx(U,{}):e.jsxs(e.Fragment,{children:[e.jsxs(P,{className:"w-full",children:[e.jsx($,{children:e.jsx(se,{children:"Click specific period to expand it's transactions data"})}),e.jsx(Y,{children:e.jsx(de,{config:N,className:"h-150 w-full",children:e.jsxs(ye,{accessibilityLayer:!0,data:C,onClick:o=>h(o.activeLabel),children:[e.jsx(ue,{vertical:!1}),e.jsx(H,{dataKey:"period",tickLine:!1,tickMargin:10,axisLine:!1,tickFormatter:o=>Me(o,r.period)}),e.jsx(me,{content:e.jsx(pe,{formatter:(o,d,n,a)=>{const l=`bg-[var(--color-${d})]`;return a<2?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:`${l} h-2.5 w-2.5 shrink-0 rounded-[2px]`}),N[d]?.label||d,e.jsx("div",{className:"ml-auto flex items-baseline gap-0.5 font-mono font-medium tabular-nums text-foreground",children:D.format(Number(o))})]}):e.jsxs("div",{className:"mt-1.5 flex basis-full items-center border-t pt-1.5 text-xs font-medium text-foreground",children:[e.jsx("div",{className:`h-2.5 w-2.5 shrink-0 rounded-[2px] mr-2 ${l}`}),N[d]?.label||d,e.jsx("div",{className:"ml-auto flex items-baseline gap-0.5 font-mono font-medium tabular-nums text-foreground",children:D.format(Number(o))})]})}})}),e.jsx(xe,{content:e.jsx(ge,{})}),f.includes("income")&&e.jsx(w,{dataKey:"income",fill:"var(--color-income)",radius:4}),f.includes("expense")&&e.jsx(w,{dataKey:"expense",fill:"var(--color-expense)",radius:4}),f.includes("delta")&&e.jsx(w,{dataKey:"delta",fill:"var(--color-delta)",radius:4}),f.includes("cumulative")&&e.jsx(w,{dataKey:"cumulative",fill:"var(--color-cumulative)",radius:4})]})})})]}),b&&e.jsx(Ne,{period:b,onCloseExtendedTransactions:()=>h(void 0),transactionIDs:C.find(o=>o.period===b)?.transactions.map(o=>o.id)??[]})]})})};export{_e as BalanceReport};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as c,j as e,B as u,a as y,F as g,u as P,L as D,fX as w}from"./index-
|
|
1
|
+
import{r as c,j as e,B as u,a as y,F as g,u as P,L as D,fX as w}from"./index-C3k8jflc.js";import{d as R}from"./graphql-document-dedupe-fragments-ByT8-wlV.js";import{P as E}from"./page-layout-x3aFVsg9.js";import{R as d}from"./report-commentary-row-PIhBXrbg.js";import{P as v}from"./modal-DNhi-EIe.js";import{Y as p}from"./YearPickerInput-CWNdAJVU.js";import{F}from"./funnel-DT4mmN3u.js";import{T as C}from"./Table-KlqUi970.js";import"./toggle-expansion-button-B-4w-oFe.js";import"./panel-top-open-B-b6XxK7.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 +1 @@
|
|
|
1
|
-
import{u as M,da as X,t as C,r as s,g as Q,i as J,db as W,dc as Y,J as F,dd as E,j as e,D as R,aP as q,B as v,av as K,z as G,aQ as U,aR as Z,an as _,ao as ee,ap as se,aq as te,as as ne,de as ae,df as re,dg as z,dh as $,bX as ce,di as H,dj as ie,K as P,X as B,L as A,dk as le,e as oe,N as de,Q as ue,dl as me,bh as he,b2 as xe,dm as je,x as k,dn as L,G as pe,bJ as fe,w as ge,W as ye,b9 as ve,cL as De,cW as be,cX as Ce,cY as O,cZ as g,c$ as Ne,d0 as y,ax as we,bT as Ie,F as Me,c as Te}from"./index-
|
|
1
|
+
import{u as M,da as X,t as C,r as s,g as Q,i as J,db as W,dc as Y,J as F,dd as E,j as e,D as R,aP as q,B as v,av as K,z as G,aQ as U,aR as Z,an as _,ao as ee,ap as se,aq as te,as as ne,de as ae,df as re,dg as z,dh as $,bX as ce,di as H,dj as ie,K as P,X as B,L as A,dk as le,e as oe,N as de,Q as ue,dl as me,bh as he,b2 as xe,dm as je,x as k,dn as L,G as pe,bJ as fe,w as ge,W as ye,b9 as ve,cL as De,cW as be,cX as Ce,cY as O,cZ as g,c$ as Ne,d0 as y,ax as we,bT as Ie,F as Me,c as Te}from"./index-C3k8jflc.js";import{s as V}from"./subMonths-Cs2weYkL.js";const Se=()=>{const[{data:u,fetching:o,error:c},x]=M({query:X});c&&(console.error(`Error fetching contracts: ${c}`),C.error("Error",{description:"Unable to fetch contracts"}));const a=s.useMemo(()=>u?.allOpenContracts?.slice().sort((t,d)=>t.client.originalBusiness.name>d.client.originalBusiness.name?1:-1)??[],[u]),i=s.useMemo(()=>a.map(t=>({value:t.id,label:t.client.originalBusiness.name})),[a]);return{fetching:o,refresh:()=>x(),openContracts:a,selectableOpenContracts:i}},Fe="IssueMonthlyDocuments",Ee=()=>{const[{fetching:u},o]=Q(W),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=J(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 ke({issueMonth:u,contracts:o,onAdd:c}){const[x,a]=s.useState(!1),[i,t]=s.useState(""),[{data:d},h]=M({query:Y,variables:{issueMonth:u,clientId:i}}),j=s.useCallback(n=>{t(n),h()},[h,t]);return s.useEffect(()=>{i!==""&&d&&(c(F(E,d.clientMonthlyChargeDraft)),a(!1))},[i,d,c]),e.jsxs(R,{open:x,onOpenChange:a,children:[e.jsx(q,{asChild:!0,children:e.jsx(v,{variant:"outline",size:"icon",children:e.jsx(K,{})})}),e.jsxs(G,{className:"w-[400px] max-w-screen-md",children:[e.jsx(U,{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 Pe({onApprove:u,draft:o}){const[c,x]=s.useState(!1),[a,i]=s.useState(!1),[t,d]=s.useState(null),{previewDocument:h,fetching:j}=ae(),[n,N]=s.useState(re(o)),T=s.useCallback((l,p)=>{N(f=>({...f,[l]:p}))},[]);s.useEffect(()=>{i(!1)},[n]);const D=s.useCallback(async()=>{try{const l=await h({input:n});if(!l)throw new Error("No preview data returned");d(l),i(!0)}catch(l){console.error("Failed to generate preview:",l)}},[n,h]);s.useEffect(()=>{c&&!t&&D()},[c,t,D]);const w=n.income?.reduce((l,p)=>{const f=p.price*p.quantity,r=f*((p.vatRate||0)/100);return l+f+r},0)||0,I=()=>{u(n),x(!1)};return e.jsxs(R,{open:c,onOpenChange:x,children:[e.jsx(q,{asChild:!0,type:"button",children:e.jsxs(z,{children:[e.jsx($,{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(G,{className:"w-7xl sm:max-w-[95%] max-h-[90vh] overflow-y-auto",children:e.jsx("div",{className:"min-h-screen bg-gray-50 p-4",children:e.jsxs("div",{className:"max-w-7xl mx-auto",children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("h1",{className:"text-3xl font-bold text-gray-900",children:"Edit Document"}),e.jsx("p",{className:"text-gray-600 mt-2",children:"Modify and preview your accounting document before issuing"})]}),e.jsxs("div",{className:"grid lg:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"space-y-6",children:[e.jsx(ie,{formData:n,updateFormData:T}),e.jsx(P,{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(P,{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=k(V(new Date,1),"yyyy-MM-dd"),[a,i]=s.useState(x),[{data:t},d]=M({query:L,variables:{issueMonth:a},pause:!0});s.useEffect(()=>{t?.clientMonthlyChargesDrafts&&c(t.clientMonthlyChargesDrafts.map(r=>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(k(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(z,{children:[e.jsx($,{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(Pe,{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(ke,{contracts:f,onAdd:T,issueMonth:a}),e.jsx(Ie,{onConfirm:h.handleSubmit(p),title:`Are you sure you want to issue ${l.length} documents?`,children:e.jsx(v,{children:"Issue"})})]})]})})})},Re=()=>{const{setFiltersContext:u}=s.useContext(Me),[{data:o,fetching:c}]=M({query:L,variables:{issueMonth:k(V(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,cY as D,d0 as a,x as f,cx as n,J as N,f$ as v,r as d,bw as E,D as T,aP as A,B as w,z as I,bp as O,G as P,cR as M,W as B,Y as y,Z as C,_ as F,$ as L,at as U,a1 as R,am as V,aU as $,F as _,a9 as k,u as q,c as z,cW as G,cX as J,cZ as o,c$ as Q,g0 as H}from"./index-
|
|
1
|
+
import{j as e,cY as D,d0 as a,x as f,cx as n,J as N,f$ as v,r as d,bw as E,D as T,aP as A,B as w,z as I,bp as O,G as P,cR as M,W as B,Y as y,Z as C,_ as F,$ as L,at as U,a1 as R,am as V,aU as $,F as _,a9 as k,u as q,c as z,cW as G,cX as J,cZ as o,c$ as Q,g0 as H}from"./index-C3k8jflc.js";import{u as S}from"./use-url-query-BOxCMiZm.js";import{P as W}from"./page-layout-x3aFVsg9.js";import{F as Z}from"./funnel-DT4mmN3u.js";const X=({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=P({defaultValues:{...s}}),{control:c,handleSubmit:x}=m,{selectableFinancialEntities:u,fetching:l}=M(),j=i=>{t({...i,year:Number(i.year)}),r()};return e.jsx(B,{...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(L,{children:e.jsx(U,{...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(V,{...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(w,{type:"submit",disabled:l,children:"Filter"})})]})})}function ae({filter:s,setFilter:t}){const[r,m]=d.useState(!1),{get:c,set:x}=S();d.useEffect(()=>{const l=K(s),j=c(b);l!==j&&x(b,l)},[s,c,x]);const u=d.useCallback(l=>{E(l,s)||t(l)},[s,t]);return e.jsxs(T,{open:r,onOpenChange:m,children:[e.jsx(A,{asChild:!0,children:e.jsx(w,{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(_),{userContext:t}=d.useContext(k),{get:r}=S(),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}]=q({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(W,{title:"Depreciation Report",description:j,children:l?e.jsx(z,{}):e.jsxs(G,{children:[e.jsxs(J,{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(Q,{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,Y)=>h.purchaseDate.localeCompare(Y.purchaseDate)).map(h=>e.jsx(X,{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{cB as fr,ad as gr,ac as ge,j as F,r as kt,bp as pr,B as mr,G as br,x as le,bs as Pn,bt as Dn,bu as An,bw as xr,F as _r,u as yr,bo as wr,aO as it,L as vr,cC as Mr}from"./index-
|
|
1
|
+
import{cB as fr,ad as gr,ac as ge,j as F,r as kt,bp as pr,B as mr,G as br,x as le,bs as Pn,bt as Dn,bu as An,bw as xr,F as _r,u as yr,bo as wr,aO as it,L as vr,cC as Mr}from"./index-C3k8jflc.js";import{u as io}from"./use-url-query-BOxCMiZm.js";import{P as Sr}from"./page-layout-x3aFVsg9.js";import{P as kr}from"./modal-DNhi-EIe.js";import{F as Cr}from"./funnel-DT4mmN3u.js";/*!
|
|
2
2
|
* decimal.js v10.6.0
|
|
3
3
|
* An arbitrary-precision Decimal type for JavaScript.
|
|
4
4
|
* https://github.com/MikeMcl/decimal.js
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r,bp as w,bw as O,j as e,bq as U,B as c,a9 as K,G as _,x as b,cR as z,W as B,cS as H,bs as D,bt as M,bu as I,Y as L,Z as G,_ as q,$ as J,ai as Q,F as W,u as X,cT as Y,L as Z,cU as $,cV as ee,cW as te,cX as se,cY as S,cZ as ae,c_ as T,c$ as ne,d0 as k,d1 as re,d2 as ie,d3 as le,d4 as oe,d5 as ce,d6 as de,d7 as me,d8 as ue}from"./index-C9fHUfnt.js";import{u as P}from"./use-url-query-BS26aRC-.js";import{a as ge}from"./accounter-table-Bx5lKrE8.js";import{D as xe}from"./data-table-pagination-B0x5jC5y.js";import{P as V}from"./modal-weFgvkj_.js";import{P as he}from"./page-layout-DZOekob-.js";import{F as pe}from"./funnel-6jLbjYGX.js";import{M as R}from"./MultiSelect-Cyxk2rHZ.js";import{s as je}from"./sub-ImDFXoGZ.js";import{A as v}from"./arrow-up-down-DsNx-cif.js";import"./Table-D9Xe8npl.js";import"./addDays-CALX0aWH.js";import"./subMonths-CuWsjtWU.js";function fe({filter:t,setFilter:s,closeModal:h}){const{userContext:p}=r.useContext(K),x=_({defaultValues:{ownerIDs:p?.context.adminBusinessId?[p.context.adminBusinessId]:void 0,toDate:b(new Date,"yyyy-MM-dd"),fromDate:b(je(new Date,{years:1}),"yyyy-MM-dd"),...t}}),{control:o,handleSubmit:y}=x,{selectableFinancialEntities:i,fetching:d}=z(),C=a=>{s(a),h()};function m(){s({}),h()}return e.jsxs(e.Fragment,{children:[d?e.jsx("div",{children:"Loading..."}):e.jsx("div",{}),e.jsx(B,{...x,children:e.jsxs("form",{onSubmit:y(C),children:[e.jsxs(H,{cols:2,children:[e.jsx(D,{name:"ownerIDs",control:o,defaultValue:t.ownerIDs,render:({field:a,fieldState:g})=>e.jsx(R,{...a,data:i,value:a.value??[],disabled:d,label:"Owners",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:g.error?.message,withinPortal:!0})}),e.jsx(D,{name:"businessIDs",control:o,defaultValue:t.businessIDs,render:({field:a,fieldState:g})=>e.jsx(R,{...a,data:i,value:a.value??[],disabled:d,label:"Financial Entities",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:g.error?.message,withinPortal:!0})}),e.jsx(D,{name:"fromDate",control:o,defaultValue:t.fromDate,rules:{pattern:{value:M,message:"Date must be im format yyyy-mm-dd"}},render:({field:a,fieldState:g})=>e.jsx(I,{...a,onChange:l=>{const j=l?typeof l=="string"?l:b(l,"yyyy-MM-dd"):void 0;j!==a.value&&a.onChange(j)},value:a.value?new Date(a.value):void 0,error:g.error?.message,label:"From Date",popoverProps:{withinPortal:!0}})}),e.jsx(D,{name:"toDate",control:o,defaultValue:t.toDate,rules:{pattern:{value:M,message:"Date must be im format yyyy-mm-dd"}},render:({field:a,fieldState:g})=>e.jsx(I,{...a,onChange:l=>{const j=l?typeof l=="string"?l:b(l,"yyyy-MM-dd"):void 0;j!==a.value&&a.onChange(j)},value:a.value?new Date(a.value):void 0,error:g.error?.message,label:"To Date",popoverProps:{withinPortal:!0}})}),e.jsx(L,{name:"unmatched",control:o,render:({field:a})=>e.jsxs(G,{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(q,{children:"Unmatched only"})}),e.jsx(J,{children:e.jsx(Q,{defaultChecked:t.unmatched??!1,onCheckedChange:a.onChange})})]})})]}),e.jsxs("div",{className:"flex justify-center mt-5 gap-3",children:[e.jsx("button",{type:"submit",disabled:d,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:m,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:h,children:"Cancel"})]})]})})]})}function ve({filter:t={},setFilter:s,initiallyOpened:h=!1}){const[p,x]=r.useState(h),[o,y]=r.useState(!w(t)),{get:i,set:d}=P();r.useEffect(()=>{const m=w(t)?null:encodeURIComponent(JSON.stringify(t)),a=i("documentsFilters");m!==a&&d("documentsFilters",m)},[t,i,d]);const C=r.useCallback(m=>{O(m,t)||(s(m),y(!w(m)))},[t,s]);return e.jsxs("div",{className:"flex flex-row gap-5 items-center",children:[e.jsx(V,{opened:p,onClose:()=>x(!1),content:e.jsx(fe,{filter:t,setFilter:C,closeModal:()=>x(!1)}),modalSize:"xl"}),e.jsx(U,{inline:!0,size:16,disabled:!o,children:e.jsx(c,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>x(!0),children:e.jsx(pe,{className:"size-5"})})})]})}const E=[{accessorKey:"__typename",header:({column:t})=>e.jsxs(c,{variant:"ghost",onClick:()=>t.toggleSorting(t.getIsSorted()==="asc"),children:[e.jsx("div",{className:"text-left",children:"Type"}),e.jsx(v,{className:"ml-2 h-4 w-4"})]}),cell:({row:t})=>{const{__typename:s}=t.original;return e.jsx("div",{className:"text-left font-medium",children:s})}},{accessorKey:"image",header:()=>e.jsx("div",{className:"text-left",children:"Image"}),cell:({row:t})=>{const{image:s}=t.original;return e.jsx("div",{className:"text-left font-medium",children:s?e.jsx("img",{alt:"missing img",src:s?.toString(),height:80,width:80}):"No image"})}},{accessorKey:"file",header:()=>e.jsx("div",{className:"text-left",children:"File"}),cell:({row:t})=>{const{file:s}=t.original;return e.jsx("div",{className:"text-left font-medium",children:s&&e.jsx(c,{variant:"outline",size:"sm",asChild:!0,children:e.jsx("a",{target:"_blank",rel:"noreferrer",href:s?.toString(),children:"Open"})})})}},{accessorKey:"date",header:({column:t})=>e.jsxs(c,{variant:"ghost",onClick:()=>t.toggleSorting(t.getIsSorted()==="asc"),children:[e.jsx("div",{className:"text-left",children:"Date"}),e.jsx(v,{className:"ml-2 h-4 w-4"})]}),cell:({row:t})=>"date"in t.original&&t.original.date?e.jsx("div",{className:"text-left font-medium",children:b(new Date(t.original.date),"dd/MM/yy")}):null},{accessorKey:"serialNumber",header:({column:t})=>e.jsxs(c,{variant:"ghost",onClick:()=>t.toggleSorting(t.getIsSorted()==="asc"),children:[e.jsx("div",{className:"text-left",children:"Serial Number"}),e.jsx(v,{className:"ml-2 h-4 w-4"})]}),cell:({row:t})=>"serialNumber"in t.original&&t.original.serialNumber?e.jsx("div",{className:"text-left font-medium",children:t.original.serialNumber}):null},{accessorKey:"vat.raw",header:({column:t})=>e.jsxs(c,{variant:"ghost",onClick:()=>t.toggleSorting(t.getIsSorted()==="asc"),children:[e.jsx("div",{className:"text-left",children:"VAT"}),e.jsx(v,{className:"ml-2 h-4 w-4"})]}),cell:({row:t})=>"vat"in t.original&&t.original.vat?.formatted?e.jsx("div",{className:"text-left font-medium whitespace-nowrap",children:t.original.vat.formatted}):null},{accessorKey:"amount.raw",header:({column:t})=>e.jsxs(c,{variant:"ghost",onClick:()=>t.toggleSorting(t.getIsSorted()==="asc"),children:[e.jsx("div",{className:"text-left",children:"Amount"}),e.jsx(v,{className:"ml-2 h-4 w-4"})]}),cell:({row:t})=>"amount"in t.original&&t.original.amount?.formatted?e.jsx("div",{className:"text-left font-medium whitespace-nowrap",children:t.original.amount.formatted}):null},{accessorKey:"creditor.name",header:({column:t})=>e.jsxs(c,{variant:"ghost",onClick:()=>t.toggleSorting(t.getIsSorted()==="asc"),children:[e.jsx("div",{className:"text-left",children:"Creditor"}),e.jsx(v,{className:"ml-2 h-4 w-4"})]}),cell:({row:t})=>"creditor"in t.original&&t.original.creditor?.name?e.jsx("div",{className:"text-left font-medium whitespace-nowrap",children:t.original.creditor.name}):null},{accessorKey:"debtor.name",header:({column:t})=>e.jsxs(c,{variant:"ghost",onClick:()=>t.toggleSorting(t.getIsSorted()==="asc"),children:[e.jsx("div",{className:"text-left",children:"Debtor"}),e.jsx(v,{className:"ml-2 h-4 w-4"})]}),cell:({row:t})=>"debtor"in t.original&&t.original.debtor?.name?e.jsx("div",{className:"text-left font-medium whitespace-nowrap",children:t.original.debtor.name}):null},{accessorKey:"charge.transactions[0].id",header:()=>e.jsx("div",{className:"text-left",children:"Related Transaction"}),cell:({row:t})=>t.original.charge?.transactions?.[0]?.id?e.jsx(ge,{items:t.original.charge?.transactions??[],columns:[{title:"Transaction Amount",value:s=>s?.amount.formatted},{title:"Transaction Created At",value:s=>s?.eventDate?b(new Date(s.eventDate),"dd/MM/yy"):null},{title:"Transaction Effective Date",value:s=>s?.effectiveDate?b(new Date(s.effectiveDate),"dd/MM/yy"):null},{title:"Transaction Description",value:s=>s?.sourceDescription}]}):"No Related Transaction"}],Ee=()=>{const[t,s]=r.useState(null),[h,p]=r.useState(!1),{get:x}=P(),o=x("documentsFilters"),y=r.useMemo(()=>{if(o)try{return JSON.parse(decodeURIComponent(o))}catch{return}},[o]),[i,d]=r.useState(y),[C,m]=r.useState([]),[a,g]=r.useState({}),{setFiltersContext:l}=r.useContext(W),[{data:j,fetching:F},N]=X({query:ce,variables:{filters:i??{}},pause:!0});r.useEffect(()=>{i&&N()},[i,N]);const f=Y({data:j?.documentsByFilters??[],columns:E,getCoreRowModel:ue(),getPaginationRowModel:me(),onSortingChange:m,getSortedRowModel:de(),onColumnVisibilityChange:g,state:{sorting:C,columnVisibility:a}}),A=f.getState().pagination.pageIndex;return r.useEffect(()=>{l(e.jsxs("div",{className:"flex flex-row gap-x-5",children:[e.jsx(xe,{table:f}),e.jsx(ve,{filter:i,setFilter:d,initiallyOpened:!i})]}))},[f,F,i,l,d,y,A]),e.jsx(he,{title:"Documents",description:"All documents",headerActions:e.jsxs("div",{className:"flex items-center py-4 gap-4",children:[e.jsxs(re,{children:[e.jsx(ie,{asChild:!0,children:e.jsx(c,{className:"ml-auto",children:"Columns"})}),e.jsx(le,{align:"end",children:f.getAllColumns().filter(n=>n.getCanHide()).map(n=>e.jsx(oe,{className:"capitalize",checked:n.getIsVisible(),onCheckedChange:u=>n.toggleVisibility(!!u),children:n.id},n.id))})]}),e.jsx(c,{onClick:()=>p(!0),children:"Upload Documents"})]}),children:F?e.jsx(Z,{className:"h-10 w-10 animate-spin mr-2 self-center"}):e.jsxs(e.Fragment,{children:[e.jsx($,{open:h,onOpenChange:p,onChange:N}),t&&e.jsx(V,{modalSize:"45%",content:e.jsx(ee,{src:t}),opened:!!t,onClose:()=>s(null)}),e.jsxs(te,{children:[e.jsx(se,{children:f.getHeaderGroups().map(n=>e.jsx(S,{children:n.headers.map(u=>e.jsx(ae,{children:u.isPlaceholder?null:T(u.column.columnDef.header,u.getContext())},u.id))},n.id))}),e.jsx(ne,{children:f.getRowModel().rows?.length?f.getRowModel().rows.map(n=>e.jsx(S,{"data-state":n.getIsSelected()&&"selected",children:n.getVisibleCells().map(u=>e.jsx(k,{children:T(u.column.columnDef.cell,u.getContext())},u.id))},n.id)):e.jsx(S,{children:e.jsx(k,{colSpan:E.length,className:"h-24 text-center",children:"No results."})})})]})]})})};export{Ee as DocumentsReport,E as columns};
|
|
1
|
+
import{r,bp as w,bw as O,j as e,bq as U,B as c,a9 as K,G as _,x as b,cR as z,W as B,cS as H,bs as D,bt as M,bu as I,Y as L,Z as G,_ as q,$ as J,ai as Q,F as W,u as X,cT as Y,L as Z,cU as $,cV as ee,cW as te,cX as se,cY as S,cZ as ae,c_ as T,c$ as ne,d0 as k,d1 as re,d2 as ie,d3 as le,d4 as oe,d5 as ce,d6 as de,d7 as me,d8 as ue}from"./index-C3k8jflc.js";import{u as P}from"./use-url-query-BOxCMiZm.js";import{a as ge}from"./accounter-table-CdLG0nPv.js";import{D as xe}from"./data-table-pagination-azA1p3g-.js";import{P as V}from"./modal-DNhi-EIe.js";import{P as he}from"./page-layout-x3aFVsg9.js";import{F as pe}from"./funnel-DT4mmN3u.js";import{M as R}from"./MultiSelect-9iwOrNey.js";import{s as je}from"./sub-CMuEnyTg.js";import{A as v}from"./arrow-up-down-B8i8ydxe.js";import"./Table-KlqUi970.js";import"./addDays-C65N2SCe.js";import"./subMonths-Cs2weYkL.js";function fe({filter:t,setFilter:s,closeModal:h}){const{userContext:p}=r.useContext(K),x=_({defaultValues:{ownerIDs:p?.context.adminBusinessId?[p.context.adminBusinessId]:void 0,toDate:b(new Date,"yyyy-MM-dd"),fromDate:b(je(new Date,{years:1}),"yyyy-MM-dd"),...t}}),{control:o,handleSubmit:y}=x,{selectableFinancialEntities:i,fetching:d}=z(),C=a=>{s(a),h()};function m(){s({}),h()}return e.jsxs(e.Fragment,{children:[d?e.jsx("div",{children:"Loading..."}):e.jsx("div",{}),e.jsx(B,{...x,children:e.jsxs("form",{onSubmit:y(C),children:[e.jsxs(H,{cols:2,children:[e.jsx(D,{name:"ownerIDs",control:o,defaultValue:t.ownerIDs,render:({field:a,fieldState:g})=>e.jsx(R,{...a,data:i,value:a.value??[],disabled:d,label:"Owners",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:g.error?.message,withinPortal:!0})}),e.jsx(D,{name:"businessIDs",control:o,defaultValue:t.businessIDs,render:({field:a,fieldState:g})=>e.jsx(R,{...a,data:i,value:a.value??[],disabled:d,label:"Financial Entities",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:g.error?.message,withinPortal:!0})}),e.jsx(D,{name:"fromDate",control:o,defaultValue:t.fromDate,rules:{pattern:{value:M,message:"Date must be im format yyyy-mm-dd"}},render:({field:a,fieldState:g})=>e.jsx(I,{...a,onChange:l=>{const j=l?typeof l=="string"?l:b(l,"yyyy-MM-dd"):void 0;j!==a.value&&a.onChange(j)},value:a.value?new Date(a.value):void 0,error:g.error?.message,label:"From Date",popoverProps:{withinPortal:!0}})}),e.jsx(D,{name:"toDate",control:o,defaultValue:t.toDate,rules:{pattern:{value:M,message:"Date must be im format yyyy-mm-dd"}},render:({field:a,fieldState:g})=>e.jsx(I,{...a,onChange:l=>{const j=l?typeof l=="string"?l:b(l,"yyyy-MM-dd"):void 0;j!==a.value&&a.onChange(j)},value:a.value?new Date(a.value):void 0,error:g.error?.message,label:"To Date",popoverProps:{withinPortal:!0}})}),e.jsx(L,{name:"unmatched",control:o,render:({field:a})=>e.jsxs(G,{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(q,{children:"Unmatched only"})}),e.jsx(J,{children:e.jsx(Q,{defaultChecked:t.unmatched??!1,onCheckedChange:a.onChange})})]})})]}),e.jsxs("div",{className:"flex justify-center mt-5 gap-3",children:[e.jsx("button",{type:"submit",disabled:d,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:m,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:h,children:"Cancel"})]})]})})]})}function ve({filter:t={},setFilter:s,initiallyOpened:h=!1}){const[p,x]=r.useState(h),[o,y]=r.useState(!w(t)),{get:i,set:d}=P();r.useEffect(()=>{const m=w(t)?null:encodeURIComponent(JSON.stringify(t)),a=i("documentsFilters");m!==a&&d("documentsFilters",m)},[t,i,d]);const C=r.useCallback(m=>{O(m,t)||(s(m),y(!w(m)))},[t,s]);return e.jsxs("div",{className:"flex flex-row gap-5 items-center",children:[e.jsx(V,{opened:p,onClose:()=>x(!1),content:e.jsx(fe,{filter:t,setFilter:C,closeModal:()=>x(!1)}),modalSize:"xl"}),e.jsx(U,{inline:!0,size:16,disabled:!o,children:e.jsx(c,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>x(!0),children:e.jsx(pe,{className:"size-5"})})})]})}const E=[{accessorKey:"__typename",header:({column:t})=>e.jsxs(c,{variant:"ghost",onClick:()=>t.toggleSorting(t.getIsSorted()==="asc"),children:[e.jsx("div",{className:"text-left",children:"Type"}),e.jsx(v,{className:"ml-2 h-4 w-4"})]}),cell:({row:t})=>{const{__typename:s}=t.original;return e.jsx("div",{className:"text-left font-medium",children:s})}},{accessorKey:"image",header:()=>e.jsx("div",{className:"text-left",children:"Image"}),cell:({row:t})=>{const{image:s}=t.original;return e.jsx("div",{className:"text-left font-medium",children:s?e.jsx("img",{alt:"missing img",src:s?.toString(),height:80,width:80}):"No image"})}},{accessorKey:"file",header:()=>e.jsx("div",{className:"text-left",children:"File"}),cell:({row:t})=>{const{file:s}=t.original;return e.jsx("div",{className:"text-left font-medium",children:s&&e.jsx(c,{variant:"outline",size:"sm",asChild:!0,children:e.jsx("a",{target:"_blank",rel:"noreferrer",href:s?.toString(),children:"Open"})})})}},{accessorKey:"date",header:({column:t})=>e.jsxs(c,{variant:"ghost",onClick:()=>t.toggleSorting(t.getIsSorted()==="asc"),children:[e.jsx("div",{className:"text-left",children:"Date"}),e.jsx(v,{className:"ml-2 h-4 w-4"})]}),cell:({row:t})=>"date"in t.original&&t.original.date?e.jsx("div",{className:"text-left font-medium",children:b(new Date(t.original.date),"dd/MM/yy")}):null},{accessorKey:"serialNumber",header:({column:t})=>e.jsxs(c,{variant:"ghost",onClick:()=>t.toggleSorting(t.getIsSorted()==="asc"),children:[e.jsx("div",{className:"text-left",children:"Serial Number"}),e.jsx(v,{className:"ml-2 h-4 w-4"})]}),cell:({row:t})=>"serialNumber"in t.original&&t.original.serialNumber?e.jsx("div",{className:"text-left font-medium",children:t.original.serialNumber}):null},{accessorKey:"vat.raw",header:({column:t})=>e.jsxs(c,{variant:"ghost",onClick:()=>t.toggleSorting(t.getIsSorted()==="asc"),children:[e.jsx("div",{className:"text-left",children:"VAT"}),e.jsx(v,{className:"ml-2 h-4 w-4"})]}),cell:({row:t})=>"vat"in t.original&&t.original.vat?.formatted?e.jsx("div",{className:"text-left font-medium whitespace-nowrap",children:t.original.vat.formatted}):null},{accessorKey:"amount.raw",header:({column:t})=>e.jsxs(c,{variant:"ghost",onClick:()=>t.toggleSorting(t.getIsSorted()==="asc"),children:[e.jsx("div",{className:"text-left",children:"Amount"}),e.jsx(v,{className:"ml-2 h-4 w-4"})]}),cell:({row:t})=>"amount"in t.original&&t.original.amount?.formatted?e.jsx("div",{className:"text-left font-medium whitespace-nowrap",children:t.original.amount.formatted}):null},{accessorKey:"creditor.name",header:({column:t})=>e.jsxs(c,{variant:"ghost",onClick:()=>t.toggleSorting(t.getIsSorted()==="asc"),children:[e.jsx("div",{className:"text-left",children:"Creditor"}),e.jsx(v,{className:"ml-2 h-4 w-4"})]}),cell:({row:t})=>"creditor"in t.original&&t.original.creditor?.name?e.jsx("div",{className:"text-left font-medium whitespace-nowrap",children:t.original.creditor.name}):null},{accessorKey:"debtor.name",header:({column:t})=>e.jsxs(c,{variant:"ghost",onClick:()=>t.toggleSorting(t.getIsSorted()==="asc"),children:[e.jsx("div",{className:"text-left",children:"Debtor"}),e.jsx(v,{className:"ml-2 h-4 w-4"})]}),cell:({row:t})=>"debtor"in t.original&&t.original.debtor?.name?e.jsx("div",{className:"text-left font-medium whitespace-nowrap",children:t.original.debtor.name}):null},{accessorKey:"charge.transactions[0].id",header:()=>e.jsx("div",{className:"text-left",children:"Related Transaction"}),cell:({row:t})=>t.original.charge?.transactions?.[0]?.id?e.jsx(ge,{items:t.original.charge?.transactions??[],columns:[{title:"Transaction Amount",value:s=>s?.amount.formatted},{title:"Transaction Created At",value:s=>s?.eventDate?b(new Date(s.eventDate),"dd/MM/yy"):null},{title:"Transaction Effective Date",value:s=>s?.effectiveDate?b(new Date(s.effectiveDate),"dd/MM/yy"):null},{title:"Transaction Description",value:s=>s?.sourceDescription}]}):"No Related Transaction"}],Ee=()=>{const[t,s]=r.useState(null),[h,p]=r.useState(!1),{get:x}=P(),o=x("documentsFilters"),y=r.useMemo(()=>{if(o)try{return JSON.parse(decodeURIComponent(o))}catch{return}},[o]),[i,d]=r.useState(y),[C,m]=r.useState([]),[a,g]=r.useState({}),{setFiltersContext:l}=r.useContext(W),[{data:j,fetching:F},N]=X({query:ce,variables:{filters:i??{}},pause:!0});r.useEffect(()=>{i&&N()},[i,N]);const f=Y({data:j?.documentsByFilters??[],columns:E,getCoreRowModel:ue(),getPaginationRowModel:me(),onSortingChange:m,getSortedRowModel:de(),onColumnVisibilityChange:g,state:{sorting:C,columnVisibility:a}}),A=f.getState().pagination.pageIndex;return r.useEffect(()=>{l(e.jsxs("div",{className:"flex flex-row gap-x-5",children:[e.jsx(xe,{table:f}),e.jsx(ve,{filter:i,setFilter:d,initiallyOpened:!i})]}))},[f,F,i,l,d,y,A]),e.jsx(he,{title:"Documents",description:"All documents",headerActions:e.jsxs("div",{className:"flex items-center py-4 gap-4",children:[e.jsxs(re,{children:[e.jsx(ie,{asChild:!0,children:e.jsx(c,{className:"ml-auto",children:"Columns"})}),e.jsx(le,{align:"end",children:f.getAllColumns().filter(n=>n.getCanHide()).map(n=>e.jsx(oe,{className:"capitalize",checked:n.getIsVisible(),onCheckedChange:u=>n.toggleVisibility(!!u),children:n.id},n.id))})]}),e.jsx(c,{onClick:()=>p(!0),children:"Upload Documents"})]}),children:F?e.jsx(Z,{className:"h-10 w-10 animate-spin mr-2 self-center"}):e.jsxs(e.Fragment,{children:[e.jsx($,{open:h,onOpenChange:p,onChange:N}),t&&e.jsx(V,{modalSize:"45%",content:e.jsx(ee,{src:t}),opened:!!t,onClose:()=>s(null)}),e.jsxs(te,{children:[e.jsx(se,{children:f.getHeaderGroups().map(n=>e.jsx(S,{children:n.headers.map(u=>e.jsx(ae,{children:u.isPlaceholder?null:T(u.column.columnDef.header,u.getContext())},u.id))},n.id))}),e.jsx(ne,{children:f.getRowModel().rows?.length?f.getRowModel().rows.map(n=>e.jsx(S,{"data-state":n.getIsSelected()&&"selected",children:n.getVisibleCells().map(u=>e.jsx(k,{children:T(u.column.columnDef.cell,u.getContext())},u.id))},n.id)):e.jsx(S,{children:e.jsx(k,{colSpan:E.length,className:"h-24 text-center",children:"No results."})})})]})]})})};export{Ee as DocumentsReport,E as columns};
|