@accounter/client
Version:
Accounter client application
1 lines • 24.2 kB
JavaScript
import{s as e}from"./dist-BmACi7k_.js";import{i as t,o as n}from"./utils-BxkqV8PM.js";import{Ao as r,Do as i,Dr as a,Eo as o,Fn as s,Mo as c,No as l,Oo as u,Ro as d,To as f,Zt as p,jo as m,ko as h,r as g,wo as ee}from"./error-handling-wXZrXhQp.js";import{n as te,s as _,t as v}from"./routes-C4NpBRv7.js";import{dt as ne,ft as y,gt as b,mt as re}from"./select-C2i-wLGF.js";import{n as ie,t as x}from"./charges-table-B5AOJMeH.js";import{Ar as ae,Et as oe,J as se,Rt as S,Sr as C,Tt as w,W as ce,Xn as T,_t as le,ct as ue,er as E,f as de,in as fe,p as pe,qt as me,xr as D}from"./common-BcRe1iBH.js";import{c as he}from"./separator-D3vGB2Vv.js";import{t as ge}from"./funnel-BUKxmzao.js";import{t as O}from"./button-BZ6z_NAl.js";import{$c as _e,Kl as k,Pl as ve,Zc as ye,a as be,c as A,d as j,el as M,i as N,l as P,m as F,n as I,nl as L,o as R,r as z,s as B,t as V,u as H}from"./table-wRyN67dl.js";import{t as U}from"./card-BRoEyy6u.js";import{t as xe}from"./files-D4cmudBT.js";import{t as W}from"./graphql-document-dedupe-fragments-C4jAugiJ.js";import{t as G}from"./use-url-query-DXFemxIX.js";import{t as Se}from"./page-layout-BcxA2__m.js";import{n as Ce}from"./charges-filters-Baf1Vq_M.js";var K=b(`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=b(`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`}]]),q=e(n(),1),J=t(),Te=({data:e,rowSelection:t,onRowSelectionChange:n})=>{let r=M(o,e),[i,a]=(0,q.useState)(!0);return(0,J.jsxs)(U,{className:`p-6`,children:[(0,J.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,J.jsxs)(`h2`,{className:`text-lg font-semibold flex items-center gap-2`,children:[(0,J.jsx)(O,{variant:`outline`,size:`icon`,className:`size-7.5`,onClick:()=>a(e=>!e),disabled:!r||r.businessTrips.length===0,children:i?(0,J.jsx)(C,{className:`size-5`}):(0,J.jsx)(D,{className:`size-5`})}),`Business Trips`]})}),i&&r&&(0,J.jsx)(x,{data:r.businessTrips,rowSelection:t,onRowSelectionChange:n})]})};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,q.useMemo)(()=>Ee(e??[]),[e]);return(0,J.jsx)(`div`,{className:`overflow-x-auto`,children:(0,J.jsxs)(`table`,{className:`w-full`,children:[(0,J.jsx)(`thead`,{children:(0,J.jsxs)(`tr`,{className:`border-b border-border text-left`,children:[(0,J.jsx)(`th`,{className:`pb-3 text-sm font-medium text-muted-foreground`,children:`Record Type`}),(0,J.jsx)(`th`,{className:`pb-3 text-sm font-medium text-muted-foreground text-right`,children:`Count`}),(0,J.jsx)(`th`,{className:`pb-3 text-sm font-medium text-muted-foreground text-right`,children:`Total Before VAT`}),(0,J.jsx)(`th`,{className:`pb-3 text-sm font-medium text-muted-foreground text-right`,children:`VAT Total`})]})}),(0,J.jsx)(`tbody`,{children:t.map(e=>(0,J.jsxs)(`tr`,{className:`border-b border-border/50`,children:[(0,J.jsxs)(`td`,{className:`py-3 text-sm font-medium`,children:[Y(e.recordType),` (`,e.recordType,`)`]}),(0,J.jsx)(`td`,{className:`py-3 text-sm text-right`,children:e.count}),(0,J.jsx)(`td`,{className:`py-3 text-sm text-right`,children:E(e.totalBeforeVat,s.Ils)}),(0,J.jsx)(`td`,{className:`py-3 text-sm text-right`,children:E(e.vatTotal,s.Ils)})]},e.recordType))})]})})};function Oe({data:e}){let{chargeId:t,chargeAccountantStatus:n}=M(f,e);return(0,J.jsx)(`td`,{children:(0,J.jsx)(se,{value:n??void 0,chargeId:t})})}var X=P(),Z=[X.accessor(e=>M(u,e.data).recordType,{id:`recordType`,header:`Record Type`,cell:e=>{let t=e.getValue();return(0,J.jsx)(`p`,{className:`whitespace-wrap`,children:`${Y(t)} (${t})`})}}),X.accessor(e=>M(u,e.data).business?.name??``,{id:`business`,header:`Business`,cell:e=>{let t=M(u,e.row.original.data);return(0,J.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[t.business?.id?(0,J.jsx)(_,{to:v.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,J.jsx)(`span`,{children:t.business?.name}),t.vatNumber&&(0,J.jsx)(`span`,{className:`text-[10px] text-gray-500`,children:t.vatNumber})]})}}),X.display({id:`invoice`,header:`Invoice`,cell:e=>{let t=M(u,e.row.original.data);return t.image?(0,J.jsx)(`a`,{href:t.image,target:`_blank`,rel:`noreferrer`,children:(0,J.jsx)(`img`,{alt:`missing img`,src:t.image,height:80,width:80})}):null}}),X.accessor(e=>M(u,e.data).documentSerial??``,{id:`documentSerial`,header:`Invoice Serial#`,cell:e=>{let t=M(u,e.row.original.data);return(0,J.jsxs)(`div`,{className:`flex flex-col`,children:[(0,J.jsx)(`span`,{children:e.getValue()}),t.allocationNumber&&(0,J.jsxs)(`span`,{className:`text-xs`,children:[`(`,t.allocationNumber,`)`]})]})}}),X.accessor(e=>M(u,e.data).documentDate??``,{id:`documentDate`,header:`Invoice Date`,cell:e=>e.getValue()}),X.accessor(e=>M(u,e.data).chargeDate??``,{id:`chargeDate`,header:`Transaction Date`,cell:e=>e.getValue()}),X.accessor(e=>M(u,e.data).amount.raw??0,{id:`amount`,header:`Amount`,cell:e=>(0,J.jsx)(`span`,{className:`whitespace-nowrap`,children:M(u,e.row.original.data).amount.formatted})}),X.accessor(e=>M(u,e.data).localAmount?.raw??0,{id:`localAmount`,header:`Amount ₪`,cell:e=>(0,J.jsx)(`span`,{className:`whitespace-nowrap`,children:M(u,e.row.original.data).localAmount?.formatted})}),X.accessor(e=>M(u,e.data).localVat?.raw??0,{id:`localVat`,header:`VAT`,cell:e=>(0,J.jsx)(`span`,{className:`whitespace-nowrap`,children:M(u,e.row.original.data).localVat?.formatted})}),X.accessor(e=>M(u,e.data).localVatAfterDeduction?.raw??0,{id:`localVatAfterDeduction`,header:`VAT ₪`,cell:e=>(0,J.jsx)(`span`,{className:`whitespace-nowrap`,children:M(u,e.row.original.data).localVatAfterDeduction?.formatted})}),X.accessor(e=>M(u,e.data).foreignVatAfterDeduction?.raw??0,{id:`foreignVatAfterDeduction`,header:`Actual VAT`,cell:e=>(0,J.jsx)(`span`,{className:`whitespace-nowrap`,children:M(u,e.row.original.data).foreignVatAfterDeduction?.formatted})}),X.accessor(e=>M(u,e.data).roundedLocalVatAfterDeduction?.raw??0,{id:`roundedLocalVatAfterDeduction`,header:`Rounded VAT`,cell:e=>(0,J.jsx)(`span`,{className:`whitespace-nowrap`,children:M(u,e.row.original.data).roundedLocalVatAfterDeduction?.formatted})}),X.accessor(e=>e.cumulativeVat,{id:`cumulativeVat`,header:`Cumulative VAT`,cell:e=>(0,J.jsxs)(`span`,{className:`whitespace-nowrap`,children:[`₪ `,T(e.getValue(),0)]})}),X.accessor(e=>M(u,e.data).taxReducedLocalAmount?.raw??0,{id:`taxReducedLocalAmount`,header:`Amount without VAT ₪`,cell:e=>(0,J.jsx)(`span`,{className:`whitespace-nowrap`,children:M(u,e.row.original.data).taxReducedLocalAmount?.formatted})}),X.accessor(e=>e.cumulativeAmount,{id:`cumulativeAmount`,header:`Cumulative Amount without VAT ₪`,cell:e=>(0,J.jsxs)(`span`,{className:`whitespace-nowrap`,children:[`₪ `,T(e.getValue(),0)]})}),X.display({id:`accountantApproval`,header:`Accountant Approval`,cell:e=>(0,J.jsx)(Oe,{data:M(u,e.row.original.data)})}),X.display({id:`actions`,header:`Edit`,cell:e=>{let t=M(u,e.row.original.data);return(0,J.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,J.jsx)(oe,{toggleExpansion:()=>e.row.toggleExpanded(),isExpanded:e.row.getIsExpanded()}),(0,J.jsx)(w,{toggleMergeSelected:()=>e.row.original.toggleMergeCharge(t.chargeId),mergeSelected:e.row.original.mergeSelectedCharges.has(t.chargeId)}),(0,J.jsx)(S,{chargeId:t.chargeId})]})}})],ke=({data:e,toggleMergeCharge:t,mergeSelectedCharges:n})=>{let{expenses:r}=M(i,e)??{expenses:[]},[a,o]=(0,q.useState)(!0),[s,c]=(0,q.useState)([]),[l,d]=(0,q.useState)({}),[f,p]=(0,q.useState)({}),[m,h]=(0,q.useState)(`detailed`),g=A({data:(0,q.useMemo)(()=>{let e=0,i=0;return r.map(r=>(e+=r.taxReducedLocalAmount?.raw??0,i+=r.roundedLocalVatAfterDeduction?.raw??0,{data:r,toggleMergeCharge:t,mergeSelectedCharges:n,cumulativeVat:i,cumulativeAmount:e}))},[r,t,n]),columns:Z,getCoreRowModel:H(),onSortingChange:c,getSortedRowModel:F(),onColumnVisibilityChange:d,onExpandedChange:p,getExpandedRowModel:j(),state:{sorting:s,columnVisibility:l,expanded:f}});return(0,J.jsxs)(U,{className:`p-6`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,J.jsxs)(`h2`,{className:`text-lg font-semibold flex items-center gap-2`,children:[(0,J.jsx)(O,{variant:`outline`,size:`icon`,className:`size-7.5`,onClick:()=>o(e=>!e),children:a?(0,J.jsx)(C,{className:`size-5`}):(0,J.jsx)(D,{className:`size-5`})}),`Expenses`]}),a&&(0,J.jsxs)(`div`,{className:`flex gap-2`,children:[(0,J.jsxs)(O,{variant:m===`detailed`?`default`:`outline`,size:`sm`,onClick:()=>h(`detailed`),children:[(0,J.jsx)(ae,{className:`h-4 w-4 mr-2`}),`Detailed`]}),(0,J.jsxs)(O,{variant:m===`summarized`?`default`:`outline`,size:`sm`,onClick:()=>h(`summarized`),children:[(0,J.jsx)(K,{className:`h-4 w-4 mr-2`}),`Summarized`]})]})]}),a&&(m===`detailed`?(0,J.jsxs)(V,{children:[(0,J.jsx)(be,{children:g.getHeaderGroups().map(e=>(0,J.jsx)(R,{children:e.headers.map(e=>(0,J.jsx)(N,{colSpan:e.colSpan,children:e.isPlaceholder?null:(0,J.jsxs)(O,{variant:`ghost`,onClick:e.column.getToggleSortingHandler(),className:`h-auto p-0 hover:bg-transparent`,children:[B(e.column.columnDef.header,e.getContext()),{asc:(0,J.jsx)(y,{className:`size-5`}),desc:(0,J.jsx)(re,{className:`size-5`})}[e.column.getIsSorted()]??null]})},e.id))},e.id))}),(0,J.jsx)(I,{children:g.getRowModel().rows?.length?g.getRowModel().rows.map(e=>{let t=M(u,e.original.data);return(0,J.jsxs)(q.Fragment,{children:[(0,J.jsx)(R,{"data-state":e.getIsSelected()&&`selected`,children:e.getVisibleCells().map(e=>(0,J.jsx)(z,{children:B(e.column.columnDef.cell,e.getContext())},e.id))}),e.getIsExpanded()&&(0,J.jsx)(R,{children:(0,J.jsx)(z,{colSpan:Z.length,children:(0,J.jsx)(fe,{style:{width:`100%`},withBorder:!0,shadow:`lg`,children:(0,J.jsx)(ie,{chargeID:t.chargeId,fetching:!!t})})})})]},e.id)}):(0,J.jsx)(R,{children:(0,J.jsx)(z,{colSpan:Z.length,className:`h-24 text-center`,children:`No results.`})})})]}):(0,J.jsx)(De,{records:r}))]})},Q=P(),$=[Q.accessor(e=>M(r,e.data).recordType,{id:`recordType`,header:`Record Type`,cell:e=>{let t=e.getValue();return(0,J.jsx)(`p`,{className:`whitespace-wrap`,children:`${Y(t)} (${t})`})}}),Q.accessor(e=>M(r,e.data).business?.name??``,{id:`business`,header:`Business`,cell:e=>{let t=M(r,e.row.original.data);return(0,J.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[t.business?.id?(0,J.jsx)(_,{to:v.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,J.jsx)(`span`,{children:t.business?.name}),t.vatNumber&&(0,J.jsx)(`span`,{className:`text-[10px] text-gray-500`,children:t.vatNumber})]})}}),Q.display({id:`invoice`,header:`Invoice`,cell:e=>{let t=M(r,e.row.original.data);return t.image?(0,J.jsx)(`a`,{href:t.image,target:`_blank`,rel:`noreferrer`,children:(0,J.jsx)(`img`,{alt:`missing img`,src:t.image,height:80,width:80})}):null}}),Q.accessor(e=>M(r,e.data).documentSerial??``,{id:`documentSerial`,header:`Invoice Serial#`,cell:e=>{let t=M(r,e.row.original.data);return(0,J.jsxs)(`div`,{className:`flex flex-col`,children:[(0,J.jsx)(`span`,{children:e.getValue()}),t.allocationNumber&&(0,J.jsxs)(`span`,{className:`text-xs`,children:[`(`,t.allocationNumber,`)`]})]})}}),Q.accessor(e=>M(r,e.data).documentDate??``,{id:`documentDate`,header:`Invoice Date`,cell:e=>e.getValue()}),Q.accessor(e=>M(r,e.data).chargeDate??``,{id:`chargeDate`,header:`Transaction Date`,cell:e=>e.getValue()}),Q.accessor(e=>M(r,e.data).taxReducedForeignAmount?.raw??0,{id:`amount`,header:`Amount`,cell:e=>M(r,e.row.original.data).taxReducedForeignAmount?.formatted??``}),Q.accessor(e=>M(r,e.data).taxReducedLocalAmount?.raw??0,{id:`localAmount`,header:`Amount ₪`,cell:e=>M(r,e.row.original.data).taxReducedLocalAmount?.formatted??``}),Q.accessor(e=>e.cumulativeAmount,{id:`cumulativeAmount`,header:`Cumulative Amount ₪`,cell:e=>(0,J.jsxs)(`span`,{className:`whitespace-nowrap`,children:[`₪ `,T(e.getValue(),0)]})}),Q.display({id:`accountantApproval`,header:`Accountant Approval`,cell:e=>(0,J.jsx)(Oe,{data:M(r,e.row.original.data)})}),Q.display({id:`actions`,header:`Edit`,cell:e=>{let t=M(r,e.row.original.data);return(0,J.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,J.jsx)(oe,{toggleExpansion:()=>e.row.toggleExpanded(),isExpanded:e.row.getIsExpanded()}),(0,J.jsx)(w,{toggleMergeSelected:()=>e.row.original.toggleMergeCharge(t.chargeId),mergeSelected:e.row.original.mergeSelectedCharges.has(t.chargeId)}),(0,J.jsx)(S,{chargeId:t.chargeId})]})}})],Ae=({data:e,toggleMergeCharge:t,mergeSelectedCharges:n})=>{let{income:i}=M(h,e)??{income:[]},[a,o]=(0,q.useState)(!0),[s,c]=(0,q.useState)([]),[l,u]=(0,q.useState)({}),[d,f]=(0,q.useState)({}),[p,m]=(0,q.useState)(`detailed`),g=A({data:(0,q.useMemo)(()=>{let e=0;return i.map(r=>(e+=r.taxReducedLocalAmount?.raw??0,{data:r,toggleMergeCharge:t,mergeSelectedCharges:n,cumulativeAmount:e}))},[i,t,n]),columns:$,getCoreRowModel:H(),onSortingChange:c,getSortedRowModel:F(),onColumnVisibilityChange:u,onExpandedChange:f,getExpandedRowModel:j(),state:{sorting:s,columnVisibility:l,expanded:d}});return(0,J.jsxs)(U,{className:`p-6`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,J.jsxs)(`h2`,{className:`text-lg font-semibold flex items-center gap-2`,children:[(0,J.jsx)(O,{variant:`outline`,size:`icon`,className:`size-7.5`,onClick:()=>o(e=>!e),children:a?(0,J.jsx)(C,{className:`size-5`}):(0,J.jsx)(D,{className:`size-5`})}),`Income`]}),a&&(0,J.jsxs)(`div`,{className:`flex gap-2`,children:[(0,J.jsxs)(O,{variant:p===`detailed`?`default`:`outline`,size:`sm`,onClick:()=>m(`detailed`),children:[(0,J.jsx)(ae,{className:`h-4 w-4 mr-2`}),`Detailed`]}),(0,J.jsxs)(O,{variant:p===`summarized`?`default`:`outline`,size:`sm`,onClick:()=>m(`summarized`),children:[(0,J.jsx)(K,{className:`h-4 w-4 mr-2`}),`Summarized`]})]})]}),a&&(p===`detailed`?(0,J.jsxs)(V,{children:[(0,J.jsx)(be,{children:g.getHeaderGroups().map(e=>(0,J.jsx)(R,{children:e.headers.map(e=>(0,J.jsx)(N,{colSpan:e.colSpan,children:e.isPlaceholder?null:(0,J.jsxs)(O,{variant:`ghost`,onClick:e.column.getToggleSortingHandler(),className:`h-auto p-0 hover:bg-transparent`,children:[B(e.column.columnDef.header,e.getContext()),{asc:(0,J.jsx)(y,{className:`size-5`}),desc:(0,J.jsx)(re,{className:`size-5`})}[e.column.getIsSorted()]??null]})},e.id))},e.id))}),(0,J.jsx)(I,{children:g.getRowModel().rows?.length?g.getRowModel().rows.map(e=>{let t=M(r,e.original.data);return(0,J.jsxs)(q.Fragment,{children:[(0,J.jsx)(R,{"data-state":e.getIsSelected()&&`selected`,children:e.getVisibleCells().map(e=>(0,J.jsx)(z,{children:B(e.column.columnDef.cell,e.getContext())},e.id))}),e.getIsExpanded()&&(0,J.jsx)(R,{children:(0,J.jsx)(z,{colSpan:$.length,children:(0,J.jsx)(fe,{style:{width:`100%`},withBorder:!0,shadow:`lg`,children:(0,J.jsx)(ie,{chargeID:t.chargeId,fetching:!!t})})})})]},e.id)}):(0,J.jsx)(R,{children:(0,J.jsx)(z,{colSpan:$.length,className:`h-24 text-center`,children:`No results.`})})})]}):(0,J.jsx)(De,{records:i}))]})},je=({data:e,rowSelection:t,onRowSelectionChange:n})=>{let r=M(m,e),[i,a]=(0,q.useState)(!0);return(0,J.jsxs)(U,{className:`p-6`,children:[(0,J.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,J.jsxs)(`h2`,{className:`text-lg font-semibold flex items-center gap-2`,children:[(0,J.jsx)(O,{variant:`outline`,size:`icon`,className:`size-7.5`,onClick:()=>a(e=>!e),disabled:!r||r.differentMonthDoc.length===0,children:i?(0,J.jsx)(C,{className:`size-5`}):(0,J.jsx)(D,{className:`size-5`})}),`Misc Charges (which are not on the above tables)`]})}),i&&r&&(0,J.jsx)(x,{data:r.differentMonthDoc,rowSelection:t,onRowSelectionChange:n})]})},Me=({data:e,rowSelection:t,onRowSelectionChange:n})=>{let r=M(c,e),[i,a]=(0,q.useState)(!0);return(0,J.jsxs)(U,{className:`p-6`,children:[(0,J.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,J.jsxs)(`h2`,{className:`text-lg font-semibold flex items-center gap-2`,children:[(0,J.jsx)(O,{variant:`outline`,size:`icon`,className:`size-7.5`,onClick:()=>a(e=>!e),disabled:!r||r.missingInfo.length===0,children:i?(0,J.jsx)(C,{className:`size-5`}):(0,J.jsx)(D,{className:`size-5`})}),`Missing Info`]})}),i&&r&&(0,J.jsx)(x,{data:r.missingInfo,rowSelection:t,onRowSelectionChange:n,showExport:!0})]})},Ne=({filter:{monthDate:e,financialEntityId:t},isLoading:n})=>{let[{data:r,fetching:i,error:o},s]=d({query:W(a),pause:!0,variables:{monthDate:e,financialEntityId:t}});return(0,q.useEffect)(()=>{if(o){let e=`Error generating PCN874 file`;console.error(`${e}: ${o}`),g.error(`Error`,{description:e,duration:5e3,closeButton:!0})}},[o]),(0,q.useEffect)(()=>{r&&xe(new File([r.pcnFile.reportContent],`pcn874.txt`,{type:`text/plain`}))},[r]),(0,J.jsx)(ue,{content:`Generate and Download PCN874 File`,children:(0,J.jsx)(O,{disabled:i||n,variant:`outline`,size:`icon`,className:`size-7.5`,onClick:s,children:(0,J.jsx)(we,{className:`size-5`})})})},Pe=({data:e})=>{let t=M(l,e),n=(0,q.useMemo)(()=>t?.expenses??[],[t?.expenses]),r=(0,q.useMemo)(()=>t?.income??[],[t?.income]),i=(0,q.useMemo)(()=>r.reduce((e,t)=>e+(t.taxReducedLocalAmount?.raw??0),0),[r]),a=(0,q.useMemo)(()=>r.reduce((e,t)=>e+(t.roundedLocalVatAfterDeduction?.raw??0),0),[r]),o=(0,q.useMemo)(()=>r.filter(e=>(e.roundedLocalVatAfterDeduction?.raw??0)===0).reduce((e,t)=>e+(t.taxReducedLocalAmount?.raw??0),0),[r]),c=(0,q.useMemo)(()=>n.filter(e=>e.isProperty).reduce((e,t)=>e+(t.taxReducedLocalAmount?.raw??0),0),[n]),u=(0,q.useMemo)(()=>a-n.reduce((e,t)=>e+(t.roundedLocalVatAfterDeduction?.raw??0),0),[a,n]);return(0,J.jsxs)(U,{className:`p-6`,children:[(0,J.jsx)(`h2`,{className:`text-lg font-semibold mb-4`,children:`Report Summary`}),(0,J.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2 lg:grid-cols-3`,children:[(0,J.jsxs)(`div`,{className:`space-y-1`,children:[(0,J.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Taxable Sales Total`}),(0,J.jsx)(`p`,{className:`text-2xl font-bold`,children:E(i,s.Ils)})]}),(0,J.jsxs)(`div`,{className:`space-y-1`,children:[(0,J.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Taxable Sales VAT`}),(0,J.jsx)(`p`,{className:`text-2xl font-bold`,children:E(a,s.Ils)})]}),(0,J.jsxs)(`div`,{className:`space-y-1`,children:[(0,J.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Zero / Exempt Sales`}),(0,J.jsx)(`p`,{className:`text-2xl font-bold`,children:E(o,s.Ils)})]}),(0,J.jsxs)(`div`,{className:`space-y-1`,children:[(0,J.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Equipment Inputs`}),(0,J.jsx)(`p`,{className:`text-2xl font-bold`,children:E(c,s.Ils)})]}),(0,J.jsxs)(`div`,{className:`space-y-1`,children:[(0,J.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Total VAT Amount`}),(0,J.jsx)(`p`,{className:`text-2xl font-bold`,children:E(u,s.Ils)})]})]})]})},Fe=e(ve(),1);function Ie({filter:e,setFilter:t,closeModal:n}){let{control:r,handleSubmit:i,setValue:a}=_e({defaultValues:{...e}}),{selectableAdminBusinesses:o,fetching:s}=de(),c=e=>{t(e),n()};function l(){t(),n()}function u(e){let t=new Date(e.getFullYear(),e.getMonth(),15);a(`monthDate`,k(t,`yyyy-MM-dd`))}return(0,J.jsxs)(J.Fragment,{children:[s?(0,J.jsx)(`div`,{children:`Loading...`}):(0,J.jsx)(`div`,{}),(0,J.jsxs)(`form`,{onSubmit:i(c),children:[(0,J.jsx)(ye,{name:`financialEntityId`,control:r,defaultValue:void 0,render:({field:e,fieldState:t})=>(0,J.jsx)(me,{...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,J.jsx)(ye,{name:`chargesType`,control:r,defaultValue:e.chargesType,render:({field:e,fieldState:t})=>(0,J.jsx)(me,{...e,data:Ce,value:e.value??p.All,label:`Charge Type`,placeholder:`Filter income/expense`,maxDropdownHeight:160,error:t.error?.message})}),(0,J.jsx)(le,{defaultValue:e?.monthDate?new Date(e.monthDate):new Date,defaultDate:e?.monthDate?new Date(e.monthDate):new Date,onChange:u,popoverProps:{withinPortal:!0}}),(0,J.jsxs)(`div`,{className:`flex justify-center mt-5 gap-3`,children:[(0,J.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,J.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:l,children:`Clear`}),(0,J.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,q.useState)(!1),{get:i,set:a}=G(),{userContext:o}=(0,q.useContext)(L);function s(n){n||={financialEntityId:o?.context.adminBusinessId??e.financialEntityId,monthDate:k(new Date,`yyyy-MM-15`)},(0,Fe.default)(n,e)||t(n)}return(0,q.useEffect)(()=>{let t=te(e??{});t!==i(`vatMonthlyReportFilters`)&&a(`vatMonthlyReportFilters`,t)},[e,i,a]),(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(pe,{opened:n,onClose:()=>r(!1),content:(0,J.jsx)(Ie,{filter:e,setFilter:s,closeModal:()=>r(!1)})}),(0,J.jsx)(O,{variant:`outline`,size:`icon`,className:`size-7.5`,onClick:()=>r(!0),children:(0,J.jsx)(ge,{className:`size-5`})})]})}var Re=()=>{let{get:e}=G(),{setFiltersContext:t}=(0,q.useContext)(he),{userContext:n}=(0,q.useContext)(L),[r,i]=(0,q.useState)(e(`vatMonthlyReportFilters`)?JSON.parse(decodeURIComponent(e(`vatMonthlyReportFilters`))):{financialEntityId:n?.context.adminBusinessId??``,monthDate:k(new Date,`yyyy-MM-15`)}),[a,o]=(0,q.useState)({});(0,q.useEffect)(()=>{(!r.financialEntityId||r.financialEntityId===``)&&n?.context.adminBusinessId&&i({...r,financialEntityId:n.context.adminBusinessId})},[r,n?.context.adminBusinessId]);let[{data:s,fetching:c}]=d({query:W(ee),variables:{filters:r},pause:r.financialEntityId===``}),l=(0,q.useMemo)(()=>Object.entries(a).flatMap(([e,t])=>t?[e]:[]),[a]),u=(0,q.useMemo)(()=>new Set(l),[l]),f=(0,q.useCallback)(e=>{o(t=>{let n={...t};return n[e]?delete n[e]:n[e]=!0,n})},[]),m=(0,q.useCallback)(()=>{o({})},[]);return(0,q.useEffect)(()=>{t((0,J.jsxs)(`div`,{className:`flex flex-row gap-2`,children:[(0,J.jsx)(Ne,{filter:r,isLoading:c}),(0,J.jsx)(Le,{filter:{...r},setFilter:i}),(0,J.jsx)(ce,{selected:l.map(e=>({id:e,onChange:()=>{}})),resetMergeList:m})]}))},[r,c,t,i,l,m]),(0,J.jsx)(Se,{title:`VAT Monthly Report${r.monthDate?`, ${k(new Date(r.monthDate),`MMMM yyyy`)}`:``}`,children:c?(0,J.jsx)(ne,{className:`h-10 w-10 animate-spin mr-2 self-center`}):(0,J.jsx)(`div`,{className:`min-h-screen`,children:(0,J.jsxs)(`div`,{className:`space-y-4`,children:[r.financialEntityId&&r.monthDate&&(0,J.jsx)(Pe,{data:s?.vatReport}),r.chargesType!==p.Expense&&(0,J.jsx)(Ae,{data:s?.vatReport,toggleMergeCharge:f,mergeSelectedCharges:u}),r.chargesType!==p.Income&&(0,J.jsx)(ke,{data:s?.vatReport,toggleMergeCharge:f,mergeSelectedCharges:u}),(0,J.jsx)(Me,{data:s?.vatReport,rowSelection:a,onRowSelectionChange:o}),(0,J.jsx)(Te,{data:s?.vatReport,rowSelection:a,onRowSelectionChange:o}),(0,J.jsx)(je,{data:s?.vatReport,rowSelection:a,onRowSelectionChange:o})]})})})};export{Re as VatMonthlyReport};