UNPKG

@accounter/client

Version:
1 lines 2.34 kB
import{s as e}from"./dist-BBBZL-zT.js";import{i as t,o as n}from"./utils-C9b7NsUD.js";import{In as r,_o as i,pt as a}from"./error-handling-DBz7h-2r.js";import{y as o}from"./routes-g2AjKuLo.js";import{dn as s}from"./common-3l1_jDFS.js";import{b as c}from"./table-CZ9XLwX9.js";import{n as l,t as u}from"./business-ledger-filters-Divdb2ym.js";import{x as d}from"./index-C5FJSqDD.js";import{t as f}from"./use-url-query-BAiQvBd8.js";import{t as p}from"./business-extended-info-DLZ5p-7w.js";var m=e(n(),1),h=t(),g=({businessId:e})=>{let{businessId:t}=o(),{get:n}=f(),{setFiltersContext:g}=(0,m.useContext)(d),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}]=i({query:a,variables:{filters:y}});(0,m.useEffect)(()=>{g((0,h.jsx)(u,{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)(c,{}):(0,h.jsx)(s,{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)(l,{color:e.total.raw>0?`green`:`red`,children:e.total.formatted}):e.total.formatted,style:{whiteSpace:`nowrap`}},..._(r.Eur),..._(r.Usd),..._(r.Gbp),..._(r.Cad),..._(r.Jpy),..._(r.Aud),..._(r.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)(l,{color:n.total.raw>0?`green`:`red`,children:n.total.formatted}):n?.total?.formatted},style:{whiteSpace:`nowrap`}}]}export{g as BusinessLedgerRecordsSingle};