@accounter/client
Version:
Accounter client application
1 lines • 4.1 kB
JavaScript
import{n as e,t}from"./business-ledger-filters-YtcEd0tA.js";import{$n as n,$u as r,Br as i,Ki as a,Kl as o,Ml as s,Nd as c,Rd as l,Tu as u,Xu as d,Yu as f,Za as p,en as m,er as h,fs as g,rr as _,xd as v}from"./index-BdWApCqi.js";import{t as y}from"./use-url-query-8I97z9a3.js";import{t as b}from"./business-extended-info-DmsDeYCa.js";import{t as x}from"./page-layout-9Fp4HhGU.js";var S=v(`chevrons-left-right-ellipsis`,[[`path`,{d:`M12 12h.01`,key:`1mp3jc`}],[`path`,{d:`M16 12h.01`,key:`1l6xoz`}],[`path`,{d:`m17 7 5 5-5 5`,key:`1xlxn0`}],[`path`,{d:`m7 7-5 5 5 5`,key:`19njba`}],[`path`,{d:`M8 12h.01`,key:`czm47f`}]]),C=v(`chevrons-right-left`,[[`path`,{d:`m20 17-5-5 5-5`,key:`30x0n2`}],[`path`,{d:`m4 17 5-5-5-5`,key:`16spf4`}]]),w=l(c(),1),T=u(),E=()=>{let{get:e}=y(),{setFiltersContext:a}=(0,w.useContext)(h),[c,l]=(0,w.useState)(!1),[u,v]=(0,w.useState)(!1),[E,k]=(0,w.useState)(e(`ledgerRecordsFilters`)?JSON.parse(decodeURIComponent(e(`ledgerRecordsFilters`))):{}),[{data:A,fetching:j}]=s({query:p,variables:{filters:E}});(0,w.useEffect)(()=>{a((0,T.jsxs)(`div`,{className:`flex flex-row gap-x-5`,children:[(0,T.jsx)(t,{filter:E,setFilter:k}),(0,T.jsx)(m,{content:`Expand all accounts`,asChild:!0,children:(0,T.jsx)(o,{variant:`outline`,size:`icon`,className:`size-7.5`,onClick:()=>l(e=>!e),children:c?(0,T.jsx)(d,{className:`size-5`}):(0,T.jsx)(f,{className:`size-5`})})}),(0,T.jsx)(m,{content:`Expand all currencies`,asChild:!0,children:(0,T.jsx)(o,{variant:`outline`,size:`icon`,className:`size-7.5`,onClick:()=>v(e=>!e),children:u?(0,T.jsx)(C,{className:`size-5`}):(0,T.jsx)(S,{className:`size-5`})})})]}))},[A,E,a,k,c,l,u]);let M=A?.businessTransactionsSumFromLedgerRecords.__typename===`CommonError`?void 0:A?.businessTransactionsSumFromLedgerRecords.businessTransactionsSum,N=M?[...M].sort((e,t)=>e.business.name.localeCompare(t.business.name)):[],P=[{title:`Business Name`,value:e=>e.business.name},{title:`Debit / Credit`,value:e=>(0,T.jsxs)(`div`,{className:`flex flex-col items-center`,children:[(0,T.jsx)(`p`,{className:`flex flex-row gap-2 whitespace-nowrap`,children:(0,T.jsx)(i,{c:`red`,children:e.debit.formatted})}),(0,T.jsx)(`p`,{className:`flex flex-row gap-2 whitespace-nowrap`,children:(0,T.jsx)(i,{c:`green`,children:e.credit.formatted})})]}),style:{whiteSpace:`nowrap`}},{title:`Total`,value:e=>(0,T.jsx)(i,{c:e.total.raw<-1e-4?`red`:e.total.raw>1e-4?`green`:void 0,fw:700,children:e.total.formatted}),style:{whiteSpace:`nowrap`}},...D(g.Eur),...D(g.Usd),...D(g.Gbp),...D(g.Cad),...D(g.Jpy),...D(g.Aud),...D(g.Sek),...O(u)];return(0,T.jsx)(x,{title:`Business Ledger Records`,description:`Business Ledger Records Summary`,children:j?(0,T.jsx)(r,{className:`h-10 w-10 animate-spin mr-2 self-center`}):(0,T.jsxs)(_,{striped:!0,highlightOnHover:!0,children:[(0,T.jsx)(`thead`,{className:`sticky top-0 z-20`,children:(0,T.jsxs)(`tr`,{className:`tracking-wider font-medium text-gray-900 text-sm bg-gray-100`,children:[P.map((e,t)=>e.disabled?null:(0,T.jsx)(`th`,{children:e.title},String(t))),(0,T.jsx)(`th`,{children:`More Info`})]})}),(0,T.jsx)(`tbody`,{children:N.map((e,t)=>(0,T.jsx)(n,{columns:P,item:e,moreInfo:()=>(0,T.jsx)(b,{businessID:e.business.id,filter:E}),isShowAll:c},t))})]})})};function D(t){return[{title:`${t} Debit / Credit`,value:e=>{let n=e.foreignCurrenciesSum.find(e=>e.currency===t);return n?(0,T.jsxs)(`div`,{className:`flex flex-col items-center`,children:[(0,T.jsx)(`p`,{className:`flex flex-row gap-2 whitespace-nowrap`,children:(0,T.jsx)(i,{c:`red`,children:n.debit.formatted})}),(0,T.jsx)(`p`,{className:`flex flex-row gap-2 whitespace-nowrap`,children:(0,T.jsx)(i,{c:`green`,children:n.credit.formatted})})]}):null},style:{whiteSpace:`nowrap`}},{title:`${t} Total`,value:n=>{let r=n.foreignCurrenciesSum.find(e=>e.currency===t);return r?.total?.raw&&(r.total.raw<-1e-4||r.total.raw>1e-4)?(0,T.jsx)(e,{color:r.total.raw>0?`green`:`red`,children:r.total.formatted}):r?.total?.formatted},style:{whiteSpace:`nowrap`}}]}function O(e){return e?Object.values(g).filter(e=>!a.includes(e)).map(D).flat():[]}export{E as BusinessLedgerRecordsSummery};