@accounter/client
Version:
Accounter client application
1 lines • 4.39 kB
JavaScript
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"./createLucideIcon-BK8Z-P8J.js";import{Cr as i,Ct as a,Jt as o,Kt as s,tr as c,wr as l}from"./common-CXB0UgWw.js";import{c as u}from"./separator-CQBUMn7G.js";import{t as d}from"./loader-circle-CZACSY-b.js";import{t as f}from"./button-DUNsVBiu.js";import{ol as p}from"./table-Dje35oxp.js";import{In as m,pt as h,us as g}from"./graphql-BIob9ctl.js";import{n as _,t as v}from"./business-ledger-filters-aASREZnD.js";import{t as y}from"./use-url-query-C3m3Z87n.js";import{t as b}from"./business-extended-info-B_hJ4-O-.js";import{t as x}from"./page-layout-YKSXEkhJ.js";var S=r(`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=r(`chevrons-right-left`,[[`path`,{d:`m20 17-5-5 5-5`,key:`30x0n2`}],[`path`,{d:`m4 17 5-5-5-5`,key:`16spf4`}]]),w=e(n(),1),T=t(),E=()=>{let{get:e}=y(),{setFiltersContext:t}=(0,w.useContext)(u),[n,r]=(0,w.useState)(!1),[c,_]=(0,w.useState)(!1),[E,k]=(0,w.useState)(e(`ledgerRecordsFilters`)?JSON.parse(decodeURIComponent(e(`ledgerRecordsFilters`))):{}),[{data:A,fetching:j}]=g({query:h,variables:{filters:E}});(0,w.useEffect)(()=>{t((0,T.jsxs)(`div`,{className:`flex flex-row gap-x-5`,children:[(0,T.jsx)(v,{filter:E,setFilter:k}),(0,T.jsx)(a,{content:`Expand all accounts`,asChild:!0,children:(0,T.jsx)(f,{variant:`outline`,size:`icon`,className:`size-7.5`,onClick:()=>r(e=>!e),children:n?(0,T.jsx)(l,{className:`size-5`}):(0,T.jsx)(i,{className:`size-5`})})}),(0,T.jsx)(a,{content:`Expand all currencies`,asChild:!0,children:(0,T.jsx)(f,{variant:`outline`,size:`icon`,className:`size-7.5`,onClick:()=>_(e=>!e),children:c?(0,T.jsx)(C,{className:`size-5`}):(0,T.jsx)(S,{className:`size-5`})})})]}))},[A,E,t,k,n,r,c]);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)(p,{c:`red`,children:e.debit.formatted})}),(0,T.jsx)(`p`,{className:`flex flex-row gap-2 whitespace-nowrap`,children:(0,T.jsx)(p,{c:`green`,children:e.credit.formatted})})]}),style:{whiteSpace:`nowrap`}},{title:`Total`,value:e=>(0,T.jsx)(p,{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(m.Eur),...D(m.Usd),...D(m.Gbp),...D(m.Cad),...D(m.Jpy),...D(m.Aud),...D(m.Sek),...O(c)];return(0,T.jsx)(x,{title:`Business Ledger Records`,description:`Business Ledger Records Summary`,children:j?(0,T.jsx)(d,{className:`h-10 w-10 animate-spin mr-2 self-center`}):(0,T.jsxs)(o,{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)(s,{columns:P,item:e,moreInfo:()=>(0,T.jsx)(b,{businessID:e.business.id,filter:E}),isShowAll:n},t))})]})})};function D(e){return[{title:`${e} Debit / Credit`,value:t=>{let n=t.foreignCurrenciesSum.find(t=>t.currency===e);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)(p,{c:`red`,children:n.debit.formatted})}),(0,T.jsx)(`p`,{className:`flex flex-row gap-2 whitespace-nowrap`,children:(0,T.jsx)(p,{c:`green`,children:n.credit.formatted})})]}):null},style:{whiteSpace:`nowrap`}},{title:`${e} Total`,value:t=>{let n=t.foreignCurrenciesSum.find(t=>t.currency===e);return n?.total?.raw&&(n.total.raw<-1e-4||n.total.raw>1e-4)?(0,T.jsx)(_,{color:n.total.raw>0?`green`:`red`,children:n.total.formatted}):n?.total?.formatted},style:{whiteSpace:`nowrap`}}]}function O(e){return e?Object.values(m).filter(e=>!c.includes(e)).map(D).flat():[]}export{E as BusinessLedgerRecordsSummery};