@accounter/client
Version:
Accounter client application
1 lines • 2.13 kB
JavaScript
import{n as e,t}from"./business-ledger-filters-CSni7JNu.js";import{Dd as n,Ml as r,Nd as i,Qn as a,Rd as o,Tu as s,Za as c,er as l,fs as u,nr as d}from"./index-DJOqGznr.js";import{t as f}from"./use-url-query-DGlulgYn.js";import{t as p}from"./business-extended-info-BEE_HHR4.js";var m=o(i(),1),h=s(),g=({businessId:i})=>{let{businessId:o}=n(),{get:s}=f(),{setFiltersContext:g}=(0,m.useContext)(l),v=i||o,[y,b]=(0,m.useState)(s(`ledgerRecordsFilters`)?{...JSON.parse(decodeURIComponent(s(`ledgerRecordsFilters`))),businessIDs:v?[v]:[]}:{businessIDs:v?[v]:[]}),[{data:x,fetching:S}]=r({query:c,variables:{filters:y}});(0,m.useEffect)(()=>{g((0,h.jsx)(t,{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)(d,{}):(0,h.jsx)(a,{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:t=>t.total.raw&&(t.total.raw<-1e-4||t.total.raw>1e-4)?(0,h.jsx)(e,{color:t.total.raw>0?`green`:`red`,children:t.total.formatted}):t.total.formatted,style:{whiteSpace:`nowrap`}},..._(u.Eur),..._(u.Usd),..._(u.Gbp),..._(u.Cad),..._(u.Jpy),..._(u.Aud),..._(u.Sek)]})};function _(t){return[{title:`${t} Debit`,value:e=>e.foreignCurrenciesSum.find(e=>e.currency===t)?.debit?.formatted,style:{whiteSpace:`nowrap`}},{title:`${t} Credit`,value:e=>e.foreignCurrenciesSum.find(e=>e.currency===t)?.credit?.formatted,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,h.jsx)(e,{color:r.total.raw>0?`green`:`red`,children:r.total.formatted}):r?.total?.formatted},style:{whiteSpace:`nowrap`}}]}export{g as BusinessLedgerRecordsSingle};