@accounter/client
Version:
Accounter client application
1 lines • 2.34 kB
JavaScript
import{s as e}from"./dist-ypP48_Ax.js";import{i as t,o as n}from"./utils-CbS-oR5I.js";import{y as r}from"./routes-Cawu7UJi.js";import{Ut as i}from"./common-D-vYt_Yl.js";import{c as a}from"./separator-BvKylNhK.js";import{tl as o}from"./table-AJA7Uyxy.js";import{Pn as s,Qo as c,ft as l}from"./graphql-DC5GYCFE.js";import{n as u,t as d}from"./business-ledger-filters-IiPVQ-FB.js";import{t as f}from"./use-url-query-Bb8ddrDs.js";import{t as p}from"./business-extended-info-Du_cp_Fm.js";var m=e(n(),1),h=t(),g=({businessId:e})=>{let{businessId:t}=r(),{get:n}=f(),{setFiltersContext:g}=(0,m.useContext)(a),v=e||t,[y,b]=(0,m.useState)(n(`ledgerRecordsFilters`)?{...JSON.parse(decodeURIComponent(n(`ledgerRecordsFilters`))),businessIDs:v?[v]:[]}:{businessIDs:v?[v]:[]}),[{data:x,fetching:S}]=c({query:l,variables:{filters:y}});(0,m.useEffect)(()=>{g((0,h.jsx)(d,{filter:y,setFilter:b}))},[x,y,g,b]);let C=x?.businessTransactionsSumFromLedgerRecords.__typename===`CommonError`?void 0:x?.businessTransactionsSumFromLedgerRecords.businessTransactionsSum,w=C?[...C].sort((e,t)=>e.business.name.localeCompare(t.business.name)):[];return S?(0,h.jsx)(o,{}):(0,h.jsx)(i,{moreInfo:e=>(0,h.jsx)(p,{businessID:e.business.id,filter:y}),striped:!0,highlightOnHover:!0,stickyHeader:!0,items:w,columns:[{title:`Business Name`,value:e=>e.business.name},{title:`Debit`,value:e=>e.debit.formatted,style:{whiteSpace:`nowrap`}},{title:`Credit`,value:e=>e.credit.formatted,style:{whiteSpace:`nowrap`}},{title:`Total`,value:e=>e.total.raw&&(e.total.raw<-1e-4||e.total.raw>1e-4)?(0,h.jsx)(u,{color:e.total.raw>0?`green`:`red`,children:e.total.formatted}):e.total.formatted,style:{whiteSpace:`nowrap`}},..._(s.Eur),..._(s.Usd),..._(s.Gbp),..._(s.Cad),..._(s.Jpy),..._(s.Aud),..._(s.Sek)]})};function _(e){return[{title:`${e} Debit`,value:t=>t.foreignCurrenciesSum.find(t=>t.currency===e)?.debit?.formatted,style:{whiteSpace:`nowrap`}},{title:`${e} Credit`,value:t=>t.foreignCurrenciesSum.find(t=>t.currency===e)?.credit?.formatted,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,h.jsx)(u,{color:n.total.raw>0?`green`:`red`,children:n.total.formatted}):n?.total?.formatted},style:{whiteSpace:`nowrap`}}]}export{g as BusinessLedgerRecordsSingle};