UNPKG

@accounter/client

Version:
2 lines • 7.42 kB
import{s as e}from"./dist-ypP48_Ax.js";import{i as t,o as n}from"./utils-CbS-oR5I.js";import{t as r}from"./loader-circle-CfW9jOIr.js";import{It as i,St as a,er as o,gt as s}from"./common-D-vYt_Yl.js";import{c}from"./separator-BvKylNhK.js";import{Ul as l,Zc as u,a as d,c as f,d as p,i as m,n as h,o as g,r as _,s as v,t as y}from"./table-AJA7Uyxy.js";import{Jo as b,Pn as x,Qo as S,Yr as C}from"./graphql-DC5GYCFE.js";import{t as w}from"./page-layout-DfY10rJx.js";var T=e(n(),1),E=t(),D=({data:e,year:t})=>{let n=(0,T.useCallback)(async()=>e?{fileContent:k(u(C,e)),fileName:`${t}_ledger`}:{fileContent:``,fileName:``},[e,t]);return e?(0,E.jsx)(i,{createFileVariables:n}):(0,E.jsx)(`div`,{})},O=[{key:``,valueFn:()=>``},{key:``,valueFn:()=>``},{key:`Counterparty`,valueFn:e=>A(e.counterParty?.name??``)},{key:`Invoice Date`,valueFn:e=>l(e.invoiceDate,`yyyy-MM-dd`)},{key:`Value Date`,valueFn:e=>l(e.valueDate,`yyyy-MM-dd`)},{key:`Reference`,valueFn:e=>e.reference?`"${A(e.reference)}"`:``},{key:`Description`,valueFn:e=>e.description?`"${A(e.description)}"`:``},{key:`Debit Amount`,valueFn:e=>e.amount.raw<0?Math.abs(e.amount.raw).toFixed(2):``},{key:`Credit Amount`,valueFn:e=>e.amount.raw>=0?e.amount.raw.toFixed(2):``},{key:`Balance`,valueFn:e=>e.balance.toFixed(2)}],k=e=>{let t=[O.map(({key:e})=>e).join(`,`)];return e.financialEntitiesInfo.map(e=>{let n=`${A(e.entity.name)},${e.entity.sortCode?.key}`,r=`,Opening Balance,,,,,,,,${e.openingBalance.raw.toFixed(2)}`,i=`Total,${A(e.entity.name)},,,,,,,${Math.abs(e.totalDebit.raw).toFixed(2)} Debit,`,a=`,,,,,,,,${e.totalCredit.raw.toFixed(2)} Credit,${e.closingBalance.raw.toFixed(2)}`,o=`,,,,,,,,${(e.totalCredit.raw-e.totalDebit.raw).toFixed(2)} Diff,`;t.push(n,r,...e.records.map(e=>O.map(({valueFn:t})=>t(e)).join(`,`)),i,a,o)}),t.join(`\r `)};function A(e){return e.replace(/"/g,`""`).replace(/,/g,`.`)}var j=o(x.Ils),M=[{id:`placeholder`,header:``,cell:()=>null},{id:`counterparty`,accessorKey:`counterparty`,header:`Counterparty`,cell:({row:e})=>(0,E.jsx)(`div`,{className:`font-medium`,children:e.original.counterParty?.name})},{id:`invoiceDate`,accessorKey:`invoiceDate`,header:`Invoice Date`,cell:({row:e})=>{let t=new Date(e.getValue(`invoiceDate`)),n=l(t,`yyyy-MM-dd`);return(0,E.jsx)(`div`,{className:`font-medium`,children:n})}},{id:`valueDate`,accessorKey:`valueDate`,header:`Value Date`,cell:({row:e})=>{let t=new Date(e.getValue(`valueDate`)),n=l(t,`yyyy-MM-dd`);return(0,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:e})=>{let t=e.original.amount.raw;return t<0?(0,E.jsx)(`div`,{className:`font-medium`,children:j.format(t*-1)}):null}},{id:`credit`,header:`Credit`,cell:({row:e})=>{let t=e.original.amount.raw;return t>=0?(0,E.jsx)(`div`,{className:`font-medium`,children:j.format(t)}):null}},{id:`balance`,accessorKey:`balance`,header:`Balance`,cell:({row:e})=>(0,E.jsx)(`div`,{className:`font-medium`,children:j.format(e.getValue(`balance`))})}],N=()=>{let{setFiltersContext:e}=(0,T.useContext)(c),[t,n]=(0,T.useState)(new Date().getFullYear()-1),[{data:i,fetching:o}]=S({query:b,variables:{year:t}}),l=i?.yearlyLedgerReport,{financialEntitiesInfo:u}=l??{},x=(0,T.useMemo)(()=>u?.flatMap(e=>{let{entity:t,openingBalance:n,closingBalance:r,totalCredit:i,totalDebit:a}=e;return e.records.map(e=>({entity:t,openingBalance:n,closingBalance:r,totalCredit:i,totalDebit:a,...e}))})??[],[u]),C=f({features:v,data:x,columns:M,initialState:{pagination:{pageIndex:0,pageSize:100}}}),{pageIndex:O,pageSize:k}=C.state.pagination,A=C.getPageCount();return(0,T.useEffect)(()=>{e((0,E.jsxs)(`div`,{className:`flex items-center justify-end gap-10 space-x-2 py-4`,children:[(0,E.jsx)(`div`,{className:`flex items-center justify-between px-2`,children:(0,E.jsx)(a,{table:C})}),(0,E.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[(0,E.jsx)(s,{value:new Date(t,0,1),onChange:e=>e&&n(e?.getFullYear()),popoverProps:{withinPortal:!0},minDate:new Date(2010,0,1),maxDate:new Date}),(0,E.jsx)(D,{data:l,year:t})]})]}))},[t,o,e,l,O,k,A]),(0,E.jsx)(w,{title:`Yearly Ledger Report`,children:o?(0,E.jsx)(r,{className:`h-10 w-10 animate-spin mr-2 self-center`}):l?(0,E.jsx)(`div`,{className:`flex flex-col gap-4 rounded-md border`,children:(0,E.jsxs)(y,{children:[(0,E.jsx)(d,{children:C.getHeaderGroups().map(e=>(0,E.jsx)(g,{children:e.headers.map(e=>(0,E.jsx)(m,{children:e.isPlaceholder?null:p(e.column.columnDef.header,e.getContext())},e.id))},e.id))}),(0,E.jsx)(h,{children:C.getRowModel().rows.map((e,t)=>{let n=C.getRowModel().rows[t-1],r=C.getRowModel().rows[t+1],i=!n||n.original.entity.id!==e.original.entity.id,a=!r||r.original.entity.id!==e.original.entity.id;return(0,E.jsxs)(E.Fragment,{children:[i&&t!==0&&(0,E.jsx)(g,{className:`border-y-2 border-t-gray-300 border-b-gray-500`,children:(0,E.jsx)(_,{})}),i&&(0,E.jsx)(P,{row:e}),(0,E.jsx)(g,{children:e.getVisibleCells().map(e=>(0,E.jsx)(_,{children:p(e.column.columnDef.cell,e.getContext())},e.id))},e.id),a&&(0,E.jsx)(F,{row:e})]})})})]})}):(0,E.jsx)(`div`,{className:`rounded-md border h-24 text-center`,children:`No results.`})})};function P({row:e}){return(0,E.jsxs)(E.Fragment,{children:[(0,E.jsxs)(g,{className:`bg-gray-300`,children:[(0,E.jsx)(_,{children:(0,E.jsx)(`div`,{className:`font-medium`,children:e.original.entity.name})}),(0,E.jsx)(_,{children:(0,E.jsx)(`div`,{className:`font-medium`,children:e.original.entity.sortCode?.key})}),(0,E.jsx)(_,{}),(0,E.jsx)(_,{}),(0,E.jsx)(_,{}),(0,E.jsx)(_,{}),(0,E.jsx)(_,{}),(0,E.jsx)(_,{}),(0,E.jsx)(_,{})]},`${e.id}-opening1`),(0,E.jsxs)(g,{className:`bg-gray-200`,children:[(0,E.jsx)(_,{}),(0,E.jsx)(_,{children:(0,E.jsx)(`div`,{className:`font-medium`,children:`Opening Balance`})}),(0,E.jsx)(_,{}),(0,E.jsx)(_,{}),(0,E.jsx)(_,{}),(0,E.jsx)(_,{}),(0,E.jsx)(_,{}),(0,E.jsx)(_,{}),(0,E.jsx)(_,{children:(0,E.jsx)(`div`,{className:`font-medium`,children:j.format(e.original.openingBalance.raw)})})]},`${e.id}-opening2`)]})}function F({row:e}){return(0,E.jsxs)(E.Fragment,{children:[(0,E.jsxs)(g,{className:`bg-gray-200`,children:[(0,E.jsx)(_,{children:(0,E.jsx)(`div`,{className:`font-medium`,children:`Total`})}),(0,E.jsx)(_,{children:(0,E.jsx)(`div`,{className:`font-medium`,children:e.original.entity.name})}),(0,E.jsx)(_,{}),(0,E.jsx)(_,{}),(0,E.jsx)(_,{}),(0,E.jsx)(_,{}),(0,E.jsx)(_,{}),(0,E.jsx)(_,{children:(0,E.jsxs)(`div`,{className:`font-medium`,children:[j.format(e.original.totalDebit.raw),` Debit`]})}),(0,E.jsx)(_,{})]},`${e.id}-totals1`),(0,E.jsxs)(g,{className:`bg-gray-200`,children:[(0,E.jsx)(_,{}),(0,E.jsx)(_,{}),(0,E.jsx)(_,{}),(0,E.jsx)(_,{}),(0,E.jsx)(_,{}),(0,E.jsx)(_,{}),(0,E.jsx)(_,{}),(0,E.jsx)(_,{children:(0,E.jsxs)(`div`,{className:`font-medium`,children:[j.format(e.original.totalCredit.raw),` Credit`]})}),(0,E.jsx)(_,{children:(0,E.jsx)(`div`,{className:`font-medium`,children:j.format(e.original.closingBalance.raw)})})]},`${e.id}-totals2`),(0,E.jsxs)(g,{className:`bg-gray-200`,children:[(0,E.jsx)(_,{}),(0,E.jsx)(_,{}),(0,E.jsx)(_,{}),(0,E.jsx)(_,{}),(0,E.jsx)(_,{}),(0,E.jsx)(_,{}),(0,E.jsx)(_,{}),(0,E.jsx)(_,{children:(0,E.jsxs)(`div`,{className:`font-medium`,children:[j.format(e.original.totalCredit.raw-e.original.totalDebit.raw),` Diff`]})}),(0,E.jsx)(_,{})]},`${e.id}-totals3`)]})}export{N as YearlyLedgerReport};