@accounter/client
Version:
Accounter client application
1 lines • 24.4 kB
JavaScript
import{s as e}from"./dist-ypP48_Ax.js";import{i as t,o as n}from"./utils-CbS-oR5I.js";import{r}from"./error-handling-CKe_iwSC.js";import{n as i,s as a,t as o}from"./routes-D0AKaVmS.js";import{n as s,t as c}from"./loader-circle-CfW9jOIr.js";import{n as l,t as u}from"./charges-table-Dhb5QetT.js";import{Cr as d,Ct as f,Dt as p,K as m,Mr as h,Ot as g,Vt as _,X as v,Xt as y,Zn as b,f as ee,on as te,p as ne,tr as x,vt as re,wr as S}from"./common-3blB_OGJ.js";import{dt as C,pt as w}from"./select-Bp1lD5cE.js";import{c as ie}from"./separator-5ROkkkxt.js";import{t as ae}from"./funnel-BrJTCiKR.js";import{t as T}from"./button-DUNsVBiu.js";import{$c as E,Jc as D,Ul as O,Xc as oe,Zc as k,a as se,c as ce,d as A,i as j,jl as le,n as M,o as N,r as P,s as F,t as I}from"./table-B6QCIQQv.js";import{t as L}from"./card-DR4aRSHr.js";import{$o as ue,In as R,Jo as de,Qo as z,Xo as fe,Yo as pe,Zo as me,Zt as B,es as V,kr as he,ls as H,ns as ge,rs as _e,ts as ve}from"./graphql-lcoKwSC9.js";import{t as ye}from"./subMonths-Bev5ALJU.js";import{t as U}from"./graphql-document-dedupe-fragments-C4jAugiJ.js";import{t as W}from"./columnHelper-BPS5AuUP.js";import{D as be}from"./index-DMUEhX8V.js";import{t as G}from"./use-url-query-v8OHvuc2.js";import{t as xe}from"./page-layout-Dg61gTWe.js";import{n as Se}from"./charges-filters-BTXPpV2h.js";var Ce=s(`chart-column`,[[`path`,{d:`M3 3v16a2 2 0 0 0 2 2h16`,key:`c24i48`}],[`path`,{d:`M18 17V9`,key:`2bz60n`}],[`path`,{d:`M13 17V5`,key:`1frdt8`}],[`path`,{d:`M8 17v-3`,key:`17ska0`}]]),we=s(`file-digit`,[[`path`,{d:`M4 12V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.706.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2`,key:`jrl274`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M10 16h2v6`,key:`1bxocy`}],[`path`,{d:`M10 22h4`,key:`ceow96`}],[`rect`,{x:`2`,y:`16`,width:`4`,height:`6`,rx:`2`,key:`r45zd0`}]]),K=e(n(),1),q=t(),Te=({data:e,rowSelection:t,onRowSelectionChange:n})=>{let r=k(fe,e),[i,a]=(0,K.useState)(!0);return(0,q.jsxs)(L,{className:`p-6`,children:[(0,q.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,q.jsxs)(`h2`,{className:`text-lg font-semibold flex items-center gap-2`,children:[(0,q.jsx)(T,{variant:`outline`,size:`icon`,className:`size-7.5`,onClick:()=>a(e=>!e),disabled:!r||r.businessTrips.length===0,children:i?(0,q.jsx)(S,{className:`size-5`}):(0,q.jsx)(d,{className:`size-5`})}),`Business Trips`]})}),i&&r&&(0,q.jsx)(u,{data:r.businessTrips,rowSelection:t,onRowSelectionChange:n})]})};function J(){return O(ye(new Date,1),`yyyy-MM-15`)}function Y(e){switch(e){case`C`:case`M`:return`Self Invoice`;case`H`:return`Single Doc By Law`;case`I`:return`Palestinian Customer`;case`K`:return`Petty Cash`;case`L1`:return`Unidentified Customer`;case`L2`:return`Unidentified Zero or Exempt`;case`P`:return`Palestinian Supplier`;case`R`:return`Import`;case`S1`:case`T`:return`Regular`;case`S2`:return`Zero or Exempt`;case`Y`:return`Export`;default:return`Unknown`}}var Ee=e=>{let t=e.reduce((e,t)=>(e[t.recordType]||={recordType:t.recordType,count:0,vatTotal:0,totalBeforeVat:0},e[t.recordType].count++,e[t.recordType].vatTotal+=t.roundedLocalVatAfterDeduction?.raw??0,e[t.recordType].totalBeforeVat+=t.taxReducedLocalAmount?.raw??0,e),{});return Object.values(t)},De=({records:e})=>{let t=(0,K.useMemo)(()=>Ee(e??[]),[e]);return(0,q.jsx)(`div`,{className:`overflow-x-auto`,children:(0,q.jsxs)(`table`,{className:`w-full`,children:[(0,q.jsx)(`thead`,{children:(0,q.jsxs)(`tr`,{className:`border-b border-border text-left`,children:[(0,q.jsx)(`th`,{className:`pb-3 text-sm font-medium text-muted-foreground`,children:`Record Type`}),(0,q.jsx)(`th`,{className:`pb-3 text-sm font-medium text-muted-foreground text-right`,children:`Count`}),(0,q.jsx)(`th`,{className:`pb-3 text-sm font-medium text-muted-foreground text-right`,children:`Total Before VAT`}),(0,q.jsx)(`th`,{className:`pb-3 text-sm font-medium text-muted-foreground text-right`,children:`VAT Total`})]})}),(0,q.jsx)(`tbody`,{children:t.map(e=>(0,q.jsxs)(`tr`,{className:`border-b border-border/50`,children:[(0,q.jsxs)(`td`,{className:`py-3 text-sm font-medium`,children:[Y(e.recordType),` (`,e.recordType,`)`]}),(0,q.jsx)(`td`,{className:`py-3 text-sm text-right`,children:e.count}),(0,q.jsx)(`td`,{className:`py-3 text-sm text-right`,children:x(e.totalBeforeVat,R.Ils)}),(0,q.jsx)(`td`,{className:`py-3 text-sm text-right`,children:x(e.vatTotal,R.Ils)})]},e.recordType))})]})})};function Oe({data:e}){let{chargeId:t,chargeAccountantStatus:n}=k(pe,e);return(0,q.jsx)(`td`,{children:(0,q.jsx)(v,{value:n??void 0,chargeId:t})})}var X=W(),Z=X.columns([X.accessor(e=>k(z,e.data).recordType,{id:`recordType`,header:`Record Type`,cell:e=>{let t=e.getValue();return(0,q.jsx)(`p`,{className:`whitespace-wrap`,children:`${Y(t)} (${t})`})}}),X.accessor(e=>k(z,e.data).business?.name??``,{id:`business`,header:`Business`,cell:e=>{let t=k(z,e.row.original.data);return(0,q.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[t.business?.id?(0,q.jsx)(a,{to:o.BUSINESSES.DETAIL(t.business.id),target:`_blank`,rel:`noreferrer`,onClick:e=>e.stopPropagation(),className:`inline-flex items-center font-semibold`,children:t.business.name}):(0,q.jsx)(`span`,{children:t.business?.name}),t.vatNumber&&(0,q.jsx)(`span`,{className:`text-[10px] text-gray-500`,children:t.vatNumber})]})}}),X.display({id:`invoice`,header:`Invoice`,cell:e=>{let t=k(z,e.row.original.data);return t.image?(0,q.jsx)(`a`,{href:t.image,target:`_blank`,rel:`noreferrer`,children:(0,q.jsx)(`img`,{alt:`missing img`,src:t.image,height:80,width:80})}):null}}),X.accessor(e=>k(z,e.data).documentSerial??``,{id:`documentSerial`,header:`Invoice Serial#`,cell:e=>{let t=k(z,e.row.original.data);return(0,q.jsxs)(`div`,{className:`flex flex-col`,children:[(0,q.jsx)(`span`,{children:e.getValue()}),t.allocationNumber&&(0,q.jsxs)(`span`,{className:`text-xs`,children:[`(`,t.allocationNumber,`)`]})]})}}),X.accessor(e=>k(z,e.data).documentDate??``,{id:`documentDate`,header:`Invoice Date`,cell:e=>e.getValue()}),X.accessor(e=>k(z,e.data).chargeDate??``,{id:`chargeDate`,header:`Transaction Date`,cell:e=>e.getValue()}),X.accessor(e=>k(z,e.data).amount.raw??0,{id:`amount`,header:`Amount`,cell:e=>{let t=k(z,e.row.original.data);return(0,q.jsx)(`span`,{className:`whitespace-nowrap`,children:t.amount.formatted})}}),X.accessor(e=>k(z,e.data).localAmount?.raw??0,{id:`localAmount`,header:`Amount ₪`,cell:e=>{let t=k(z,e.row.original.data);return(0,q.jsx)(`span`,{className:`whitespace-nowrap`,children:t.localAmount?.formatted})}}),X.accessor(e=>k(z,e.data).localVat?.raw??0,{id:`localVat`,header:`VAT`,cell:e=>{let t=k(z,e.row.original.data);return(0,q.jsx)(`span`,{className:`whitespace-nowrap`,children:t.localVat?.formatted})}}),X.accessor(e=>k(z,e.data).localVatAfterDeduction?.raw??0,{id:`localVatAfterDeduction`,header:`VAT ₪`,cell:e=>{let t=k(z,e.row.original.data);return(0,q.jsx)(`span`,{className:`whitespace-nowrap`,children:t.localVatAfterDeduction?.formatted})}}),X.accessor(e=>k(z,e.data).foreignVatAfterDeduction?.raw??0,{id:`foreignVatAfterDeduction`,header:`Actual VAT`,cell:e=>{let t=k(z,e.row.original.data);return(0,q.jsx)(`span`,{className:`whitespace-nowrap`,children:t.foreignVatAfterDeduction?.formatted})}}),X.accessor(e=>k(z,e.data).roundedLocalVatAfterDeduction?.raw??0,{id:`roundedLocalVatAfterDeduction`,header:`Rounded VAT`,cell:e=>{let t=k(z,e.row.original.data);return(0,q.jsx)(`span`,{className:`whitespace-nowrap`,children:t.roundedLocalVatAfterDeduction?.formatted})}}),X.accessor(e=>e.cumulativeVat,{id:`cumulativeVat`,header:`Cumulative VAT`,cell:e=>(0,q.jsxs)(`span`,{className:`whitespace-nowrap`,children:[`₪ `,b(e.getValue(),0)]})}),X.accessor(e=>k(z,e.data).taxReducedLocalAmount?.raw??0,{id:`taxReducedLocalAmount`,header:`Amount without VAT ₪`,cell:e=>{let t=k(z,e.row.original.data);return(0,q.jsx)(`span`,{className:`whitespace-nowrap`,children:t.taxReducedLocalAmount?.formatted})}}),X.accessor(e=>e.cumulativeAmount,{id:`cumulativeAmount`,header:`Cumulative Amount without VAT ₪`,cell:e=>(0,q.jsxs)(`span`,{className:`whitespace-nowrap`,children:[`₪ `,b(e.getValue(),0)]})}),X.display({id:`accountantApproval`,header:`Accountant Approval`,cell:e=>{let t=k(z,e.row.original.data);return(0,q.jsx)(Oe,{data:t})}}),X.display({id:`actions`,header:`Edit`,cell:e=>{let t=k(z,e.row.original.data);return(0,q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,q.jsx)(g,{toggleExpansion:()=>e.row.toggleExpanded(),isExpanded:e.row.getIsExpanded()}),(0,q.jsx)(p,{toggleMergeSelected:()=>e.row.original.toggleMergeCharge(t.chargeId),mergeSelected:e.row.original.mergeSelectedCharges.has(t.chargeId)}),(0,q.jsx)(_,{chargeId:t.chargeId})]})}})]),ke=({data:e,toggleMergeCharge:t,mergeSelectedCharges:n})=>{let{expenses:r}=k(me,e)??{expenses:[]},[i,a]=(0,K.useState)(!0),[o,s]=(0,K.useState)([]),[c,u]=(0,K.useState)({}),[f,p]=(0,K.useState)({}),[m,g]=(0,K.useState)(`detailed`),_=(0,K.useMemo)(()=>{let e=0,i=0,a=[];for(let o of r)e+=o.taxReducedLocalAmount?.raw??0,i+=o.roundedLocalVatAfterDeduction?.raw??0,a.push({data:o,toggleMergeCharge:t,mergeSelectedCharges:n,cumulativeVat:i,cumulativeAmount:e});return a},[r,t,n]),v=ce({features:F,data:_,columns:Z,onSortingChange:s,onColumnVisibilityChange:u,onExpandedChange:p,getRowCanExpand:()=>!0,state:{sorting:o,columnVisibility:c,expanded:f}});return(0,q.jsxs)(L,{className:`p-6`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,q.jsxs)(`h2`,{className:`text-lg font-semibold flex items-center gap-2`,children:[(0,q.jsx)(T,{variant:`outline`,size:`icon`,className:`size-7.5`,onClick:()=>a(e=>!e),children:i?(0,q.jsx)(S,{className:`size-5`}):(0,q.jsx)(d,{className:`size-5`})}),`Expenses`]}),i&&(0,q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,q.jsxs)(T,{variant:m===`detailed`?`default`:`outline`,size:`sm`,onClick:()=>g(`detailed`),children:[(0,q.jsx)(h,{className:`h-4 w-4 mr-2`}),`Detailed`]}),(0,q.jsxs)(T,{variant:m===`summarized`?`default`:`outline`,size:`sm`,onClick:()=>g(`summarized`),children:[(0,q.jsx)(Ce,{className:`h-4 w-4 mr-2`}),`Summarized`]})]})]}),i&&(m===`detailed`?(0,q.jsxs)(I,{children:[(0,q.jsx)(se,{children:v.getHeaderGroups().map(e=>(0,q.jsx)(N,{children:e.headers.map(e=>(0,q.jsx)(j,{colSpan:e.colSpan,children:e.isPlaceholder?null:(0,q.jsxs)(T,{variant:`ghost`,onClick:e.column.getToggleSortingHandler(),className:`h-auto p-0 hover:bg-transparent`,children:[A(e.column.columnDef.header,e.getContext()),{asc:(0,q.jsx)(C,{className:`size-5`}),desc:(0,q.jsx)(w,{className:`size-5`})}[e.column.getIsSorted()]??null]})},e.id))},e.id))}),(0,q.jsx)(M,{children:v.getRowModel().rows?.length?v.getRowModel().rows.map(e=>{let t=k(z,e.original.data);return(0,q.jsxs)(K.Fragment,{children:[(0,q.jsx)(N,{"data-state":e.getIsSelected()&&`selected`,children:e.getVisibleCells().map(e=>(0,q.jsx)(P,{children:A(e.column.columnDef.cell,e.getContext())},e.id))}),e.getIsExpanded()&&(0,q.jsx)(N,{children:(0,q.jsx)(P,{colSpan:Z.length,children:(0,q.jsx)(te,{style:{width:`100%`},withBorder:!0,shadow:`lg`,children:(0,q.jsx)(l,{chargeID:t.chargeId,fetching:!!t})})})})]},e.id)}):(0,q.jsx)(N,{children:(0,q.jsx)(P,{colSpan:Z.length,className:`h-24 text-center`,children:`No results.`})})})]}):(0,q.jsx)(De,{records:r}))]})},Q=W(),$=Q.columns([Q.accessor(e=>k(V,e.data).recordType,{id:`recordType`,header:`Record Type`,cell:e=>{let t=e.getValue();return(0,q.jsx)(`p`,{className:`whitespace-wrap`,children:`${Y(t)} (${t})`})}}),Q.accessor(e=>k(V,e.data).business?.name??``,{id:`business`,header:`Business`,cell:e=>{let t=k(V,e.row.original.data);return(0,q.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[t.business?.id?(0,q.jsx)(a,{to:o.BUSINESSES.DETAIL(t.business.id),target:`_blank`,rel:`noreferrer`,onClick:e=>e.stopPropagation(),className:`inline-flex items-center font-semibold`,children:t.business.name}):(0,q.jsx)(`span`,{children:t.business?.name}),t.vatNumber&&(0,q.jsx)(`span`,{className:`text-[10px] text-gray-500`,children:t.vatNumber})]})}}),Q.display({id:`invoice`,header:`Invoice`,cell:e=>{let t=k(V,e.row.original.data);return t.image?(0,q.jsx)(`a`,{href:t.image,target:`_blank`,rel:`noreferrer`,children:(0,q.jsx)(`img`,{alt:`missing img`,src:t.image,height:80,width:80})}):null}}),Q.accessor(e=>k(V,e.data).documentSerial??``,{id:`documentSerial`,header:`Invoice Serial#`,cell:e=>{let t=k(V,e.row.original.data);return(0,q.jsxs)(`div`,{className:`flex flex-col`,children:[(0,q.jsx)(`span`,{children:e.getValue()}),t.allocationNumber&&(0,q.jsxs)(`span`,{className:`text-xs`,children:[`(`,t.allocationNumber,`)`]})]})}}),Q.accessor(e=>k(V,e.data).documentDate??``,{id:`documentDate`,header:`Invoice Date`,cell:e=>e.getValue()}),Q.accessor(e=>k(V,e.data).chargeDate??``,{id:`chargeDate`,header:`Transaction Date`,cell:e=>e.getValue()}),Q.accessor(e=>k(V,e.data).taxReducedForeignAmount?.raw??0,{id:`amount`,header:`Amount`,cell:e=>k(V,e.row.original.data).taxReducedForeignAmount?.formatted??``}),Q.accessor(e=>k(V,e.data).taxReducedLocalAmount?.raw??0,{id:`localAmount`,header:`Amount ₪`,cell:e=>k(V,e.row.original.data).taxReducedLocalAmount?.formatted??``}),Q.accessor(e=>e.cumulativeAmount,{id:`cumulativeAmount`,header:`Cumulative Amount ₪`,cell:e=>(0,q.jsxs)(`span`,{className:`whitespace-nowrap`,children:[`₪ `,b(e.getValue(),0)]})}),Q.display({id:`accountantApproval`,header:`Accountant Approval`,cell:e=>{let t=k(V,e.row.original.data);return(0,q.jsx)(Oe,{data:t})}}),Q.display({id:`actions`,header:`Edit`,cell:e=>{let t=k(V,e.row.original.data);return(0,q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,q.jsx)(g,{toggleExpansion:()=>e.row.toggleExpanded(),isExpanded:e.row.getIsExpanded()}),(0,q.jsx)(p,{toggleMergeSelected:()=>e.row.original.toggleMergeCharge(t.chargeId),mergeSelected:e.row.original.mergeSelectedCharges.has(t.chargeId)}),(0,q.jsx)(_,{chargeId:t.chargeId})]})}})]),Ae=({data:e,toggleMergeCharge:t,mergeSelectedCharges:n})=>{let{income:r}=k(ue,e)??{income:[]},[i,a]=(0,K.useState)(!0),[o,s]=(0,K.useState)([]),[c,u]=(0,K.useState)({}),[f,p]=(0,K.useState)({}),[m,g]=(0,K.useState)(`detailed`),_=(0,K.useMemo)(()=>{let e=0,i=[];for(let a of r)e+=a.taxReducedLocalAmount?.raw??0,i.push({data:a,toggleMergeCharge:t,mergeSelectedCharges:n,cumulativeAmount:e});return i},[r,t,n]),v=ce({features:F,data:_,columns:$,onSortingChange:s,onColumnVisibilityChange:u,onExpandedChange:p,getRowCanExpand:()=>!0,state:{sorting:o,columnVisibility:c,expanded:f}});return(0,q.jsxs)(L,{className:`p-6`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,q.jsxs)(`h2`,{className:`text-lg font-semibold flex items-center gap-2`,children:[(0,q.jsx)(T,{variant:`outline`,size:`icon`,className:`size-7.5`,onClick:()=>a(e=>!e),children:i?(0,q.jsx)(S,{className:`size-5`}):(0,q.jsx)(d,{className:`size-5`})}),`Income`]}),i&&(0,q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,q.jsxs)(T,{variant:m===`detailed`?`default`:`outline`,size:`sm`,onClick:()=>g(`detailed`),children:[(0,q.jsx)(h,{className:`h-4 w-4 mr-2`}),`Detailed`]}),(0,q.jsxs)(T,{variant:m===`summarized`?`default`:`outline`,size:`sm`,onClick:()=>g(`summarized`),children:[(0,q.jsx)(Ce,{className:`h-4 w-4 mr-2`}),`Summarized`]})]})]}),i&&(m===`detailed`?(0,q.jsxs)(I,{children:[(0,q.jsx)(se,{children:v.getHeaderGroups().map(e=>(0,q.jsx)(N,{children:e.headers.map(e=>(0,q.jsx)(j,{colSpan:e.colSpan,children:e.isPlaceholder?null:(0,q.jsxs)(T,{variant:`ghost`,onClick:e.column.getToggleSortingHandler(),className:`h-auto p-0 hover:bg-transparent`,children:[A(e.column.columnDef.header,e.getContext()),{asc:(0,q.jsx)(C,{className:`size-5`}),desc:(0,q.jsx)(w,{className:`size-5`})}[e.column.getIsSorted()]??null]})},e.id))},e.id))}),(0,q.jsx)(M,{children:v.getRowModel().rows?.length?v.getRowModel().rows.map(e=>{let t=k(V,e.original.data);return(0,q.jsxs)(K.Fragment,{children:[(0,q.jsx)(N,{"data-state":e.getIsSelected()&&`selected`,children:e.getVisibleCells().map(e=>(0,q.jsx)(P,{children:A(e.column.columnDef.cell,e.getContext())},e.id))}),e.getIsExpanded()&&(0,q.jsx)(N,{children:(0,q.jsx)(P,{colSpan:$.length,children:(0,q.jsx)(te,{style:{width:`100%`},withBorder:!0,shadow:`lg`,children:(0,q.jsx)(l,{chargeID:t.chargeId,fetching:!!t})})})})]},e.id)}):(0,q.jsx)(N,{children:(0,q.jsx)(P,{colSpan:$.length,className:`h-24 text-center`,children:`No results.`})})})]}):(0,q.jsx)(De,{records:r}))]})},je=({data:e,rowSelection:t,onRowSelectionChange:n})=>{let r=k(ve,e),[i,a]=(0,K.useState)(!0);return(0,q.jsxs)(L,{className:`p-6`,children:[(0,q.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,q.jsxs)(`h2`,{className:`text-lg font-semibold flex items-center gap-2`,children:[(0,q.jsx)(T,{variant:`outline`,size:`icon`,className:`size-7.5`,onClick:()=>a(e=>!e),disabled:!r||r.differentMonthDoc.length===0,children:i?(0,q.jsx)(S,{className:`size-5`}):(0,q.jsx)(d,{className:`size-5`})}),`Misc Charges (which are not on the above tables)`]})}),i&&r&&(0,q.jsx)(u,{data:r.differentMonthDoc,rowSelection:t,onRowSelectionChange:n})]})},Me=({data:e,rowSelection:t,onRowSelectionChange:n})=>{let r=k(ge,e),[i,a]=(0,K.useState)(!0);return(0,q.jsxs)(L,{className:`p-6`,children:[(0,q.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,q.jsxs)(`h2`,{className:`text-lg font-semibold flex items-center gap-2`,children:[(0,q.jsx)(T,{variant:`outline`,size:`icon`,className:`size-7.5`,onClick:()=>a(e=>!e),disabled:!r||r.missingInfo.length===0,children:i?(0,q.jsx)(S,{className:`size-5`}):(0,q.jsx)(d,{className:`size-5`})}),`Missing Info`]})}),i&&r&&(0,q.jsx)(u,{data:r.missingInfo,rowSelection:t,onRowSelectionChange:n,showExport:!0})]})},Ne=({filter:{monthDate:e,financialEntityId:t},isLoading:n})=>{let[{data:i,fetching:a,error:o},s]=H({query:U(he),pause:!0,variables:{monthDate:e,financialEntityId:t}});return(0,K.useEffect)(()=>{if(o){let e=`Error generating PCN874 file`;console.error(`${e}: ${o}`),r.error(`Error`,{description:e,duration:5e3,closeButton:!0})}},[o]),(0,K.useEffect)(()=>{if(i){let e=new File([i.pcnFile.reportContent],`pcn874.txt`,{type:`text/plain`});be(e)}},[i]),(0,q.jsx)(f,{content:`Generate and Download PCN874 File`,children:(0,q.jsx)(T,{disabled:a||n,variant:`outline`,size:`icon`,className:`size-7.5`,onClick:s,children:(0,q.jsx)(we,{className:`size-5`})})})},Pe=({data:e})=>{let t=k(_e,e),n=(0,K.useMemo)(()=>t?.expenses??[],[t?.expenses]),r=(0,K.useMemo)(()=>t?.income??[],[t?.income]),i=(0,K.useMemo)(()=>r.reduce((e,t)=>e+(t.taxReducedLocalAmount?.raw??0),0),[r]),a=(0,K.useMemo)(()=>r.reduce((e,t)=>e+(t.roundedLocalVatAfterDeduction?.raw??0),0),[r]),o=(0,K.useMemo)(()=>r.filter(e=>(e.roundedLocalVatAfterDeduction?.raw??0)===0).reduce((e,t)=>e+(t.taxReducedLocalAmount?.raw??0),0),[r]),s=(0,K.useMemo)(()=>n.filter(e=>e.isProperty).reduce((e,t)=>e+(t.taxReducedLocalAmount?.raw??0),0),[n]),c=(0,K.useMemo)(()=>a-n.reduce((e,t)=>e+(t.roundedLocalVatAfterDeduction?.raw??0),0),[a,n]);return(0,q.jsxs)(L,{className:`p-6`,children:[(0,q.jsx)(`h2`,{className:`text-lg font-semibold mb-4`,children:`Report Summary`}),(0,q.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2 lg:grid-cols-3`,children:[(0,q.jsxs)(`div`,{className:`space-y-1`,children:[(0,q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Taxable Sales Total`}),(0,q.jsx)(`p`,{className:`text-2xl font-bold`,children:x(i,R.Ils)})]}),(0,q.jsxs)(`div`,{className:`space-y-1`,children:[(0,q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Taxable Sales VAT`}),(0,q.jsx)(`p`,{className:`text-2xl font-bold`,children:x(a,R.Ils)})]}),(0,q.jsxs)(`div`,{className:`space-y-1`,children:[(0,q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Zero / Exempt Sales`}),(0,q.jsx)(`p`,{className:`text-2xl font-bold`,children:x(o,R.Ils)})]}),(0,q.jsxs)(`div`,{className:`space-y-1`,children:[(0,q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Equipment Inputs`}),(0,q.jsx)(`p`,{className:`text-2xl font-bold`,children:x(s,R.Ils)})]}),(0,q.jsxs)(`div`,{className:`space-y-1`,children:[(0,q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Total VAT Amount`}),(0,q.jsx)(`p`,{className:`text-2xl font-bold`,children:x(c,R.Ils)})]})]})]})},Fe=e(le(),1);function Ie({filter:e,setFilter:t,closeModal:n}){let{control:r,handleSubmit:i,setValue:a}=oe({defaultValues:{...e}}),{selectableAdminBusinesses:o,fetching:s}=ee(),c=new Date(e?.monthDate??J()),l=e=>{t(e),n()};function u(){t(),n()}function d(e){let t=new Date(e.getFullYear(),e.getMonth(),15);a(`monthDate`,O(t,`yyyy-MM-dd`))}return(0,q.jsxs)(q.Fragment,{children:[s?(0,q.jsx)(`div`,{children:`Loading...`}):(0,q.jsx)(`div`,{}),(0,q.jsxs)(`form`,{onSubmit:i(l),children:[(0,q.jsx)(D,{name:`financialEntityId`,control:r,defaultValue:void 0,render:({field:e,fieldState:t})=>(0,q.jsx)(y,{...e,data:o,value:e.value,disabled:s,label:`Report Issuer (Admin Business)`,placeholder:`Scroll to see all options`,maxDropdownHeight:160,searchable:!0,error:t.error?.message})}),(0,q.jsx)(D,{name:`chargesType`,control:r,defaultValue:e.chargesType,render:({field:e,fieldState:t})=>(0,q.jsx)(y,{...e,data:Se,value:e.value??B.All,label:`Charge Type`,placeholder:`Filter income/expense`,maxDropdownHeight:160,error:t.error?.message})}),(0,q.jsx)(re,{defaultValue:c,defaultDate:c,onChange:d,popoverProps:{withinPortal:!0}}),(0,q.jsxs)(`div`,{className:`flex justify-center mt-5 gap-3`,children:[(0,q.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`}),(0,q.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:u,children:`Clear`}),(0,q.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:n,children:`Cancel`})]})]})]})}function Le({filter:e,setFilter:t}){let[n,r]=(0,K.useState)(!1),{get:a,set:o}=G(),{userContext:s}=(0,K.useContext)(E);function c(n){n||={financialEntityId:s?.context.adminBusinessId??e.financialEntityId,monthDate:J()},(0,Fe.default)(n,e)||t(n)}return(0,K.useEffect)(()=>{let t=i(e??{});t!==a(`vatMonthlyReportFilters`)&&o(`vatMonthlyReportFilters`,t)},[e,a,o]),(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(ne,{opened:n,onClose:()=>r(!1),content:(0,q.jsx)(Ie,{filter:e,setFilter:c,closeModal:()=>r(!1)})}),(0,q.jsx)(T,{variant:`outline`,size:`icon`,className:`size-7.5`,onClick:()=>r(!0),children:(0,q.jsx)(ae,{className:`size-5`})})]})}var Re=U(de),ze=()=>{let{get:e}=G(),{setFiltersContext:t}=(0,K.useContext)(ie),{userContext:n}=(0,K.useContext)(E),[r,i]=(0,K.useState)(e(`vatMonthlyReportFilters`)?JSON.parse(decodeURIComponent(e(`vatMonthlyReportFilters`))):{financialEntityId:n?.context.adminBusinessId??``,monthDate:J()}),[a,o]=(0,K.useState)({});(0,K.useEffect)(()=>{(!r.financialEntityId||r.financialEntityId===``)&&n?.context.adminBusinessId&&i({...r,financialEntityId:n.context.adminBusinessId})},[r,n?.context.adminBusinessId]);let[{data:s,fetching:l}]=H({query:Re,variables:{filters:r},pause:r.financialEntityId===``}),u=(0,K.useMemo)(()=>Object.entries(a).flatMap(([e,t])=>t?[e]:[]),[a]),d=(0,K.useMemo)(()=>new Set(u),[u]),f=(0,K.useCallback)(e=>{o(t=>{let n={...t};return n[e]?delete n[e]:n[e]=!0,n})},[]),p=(0,K.useCallback)(()=>{o({})},[]);return(0,K.useEffect)(()=>{t((0,q.jsxs)(`div`,{className:`flex flex-row gap-2`,children:[(0,q.jsx)(Ne,{filter:r,isLoading:l}),(0,q.jsx)(Le,{filter:{...r},setFilter:i}),(0,q.jsx)(m,{selected:u.map(e=>({id:e,onChange:()=>{}})),resetMergeList:p})]}))},[r,l,t,i,u,p]),(0,q.jsx)(xe,{title:`VAT Monthly Report${r.monthDate?`, ${O(new Date(r.monthDate),`MMMM yyyy`)}`:``}`,children:l?(0,q.jsx)(c,{className:`h-10 w-10 animate-spin mr-2 self-center`}):(0,q.jsx)(`div`,{className:`min-h-screen`,children:(0,q.jsxs)(`div`,{className:`space-y-4`,children:[r.financialEntityId&&r.monthDate&&(0,q.jsx)(Pe,{data:s?.vatReport}),r.chargesType!==B.Expense&&(0,q.jsx)(Ae,{data:s?.vatReport,toggleMergeCharge:f,mergeSelectedCharges:d}),r.chargesType!==B.Income&&(0,q.jsx)(ke,{data:s?.vatReport,toggleMergeCharge:f,mergeSelectedCharges:d}),(0,q.jsx)(Me,{data:s?.vatReport,rowSelection:a,onRowSelectionChange:o}),(0,q.jsx)(Te,{data:s?.vatReport,rowSelection:a,onRowSelectionChange:o}),(0,q.jsx)(je,{data:s?.vatReport,rowSelection:a,onRowSelectionChange:o})]})})})};export{ze as VatMonthlyReport};