UNPKG

@accounter/client

Version:
1 lines • 5.66 kB
import{s as e}from"./dist-BmACi7k_.js";import{i as t,o as n}from"./utils-BxkqV8PM.js";import{Si as r,zo as i}from"./error-handling-sQ-z99nE.js";import{y as a}from"./routes-C4NpBRv7.js";import{dt as o}from"./select-KYQbDWZT.js";import{Ot as s,Wt as c,gt as l,p as u}from"./common-DtK-TFhT.js";import{c as d}from"./separator-CNv9f_S5.js";import{t as f}from"./funnel-Djj7k08w.js";import{t as p}from"./button-BZ6z_NAl.js";import{t as m}from"./graphql-document-dedupe-fragments-C4jAugiJ.js";import{t as h}from"./page-layout-jrXvjrbd.js";import{t as g}from"./report-commentary-row-BCHxOY3g.js";var _=e(n(),1),v=t();function y({year:e,setYear:t,referenceYears:n,setReferenceYears:r}){let[i,a]=(0,_.useState)(!1);return(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)(u,{opened:i,onClose:()=>a(!1),withCloseButton:!0,content:(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)(l,{label:`Change report year`,value:new Date(e,0,1),onChange:e=>e&&t(e?.getFullYear()),popoverProps:{withinPortal:!0},minDate:new Date(2010,0,1),maxDate:new Date}),(0,v.jsx)(l,{type:`multiple`,label:`Pick reference years`,value:n?.map(e=>new Date(e,0,1)),onChange:t=>r(t.map(e=>e.getFullYear()).filter(t=>e!==t)),popoverProps:{withinPortal:!0},minDate:new Date(2010,0,1),maxDate:new Date})]})}),(0,v.jsx)(p,{variant:`outline`,size:`icon`,className:`size-7.5`,onClick:()=>a(!0),children:(0,v.jsx)(f,{className:`size-5`})})]})}var b=()=>{let{year:e}=a(),{setFiltersContext:t}=(0,_.useContext)(d),[n,l]=(0,_.useState)(e?Number(e):new Date().getFullYear()),[u,f]=(0,_.useState)([]),[{data:p,fetching:b}]=i({query:m(r),variables:{reportYear:n,referenceYears:u}});(0,_.useEffect)(()=>{t((0,v.jsx)(`div`,{className:`flex flex-row gap-2`,children:(0,v.jsx)(y,{year:n,setYear:l,referenceYears:u,setReferenceYears:f})}))},[n,b,t,u,f]);let x=p?.profitAndLossReport,S=x?.report,C=x?.reference??[];return(0,v.jsx)(h,{title:`Profit and Loss Report`,headerActions:(0,v.jsx)(s,{filename:`profit_and_loss_${n}`}),children:b?(0,v.jsx)(o,{className:`h-10 w-10 animate-spin mr-2 self-center`}):(0,v.jsx)(`div`,{className:`flex flex-col gap-4`,children:S&&(0,v.jsxs)(c,{highlightOnHover:!0,fontSize:`md`,children:[(0,v.jsx)(`thead`,{children:(0,v.jsxs)(`tr`,{children:[(0,v.jsx)(`th`,{}),(0,v.jsx)(`th`,{children:n},n),(0,v.jsx)(`th`,{}),C.map(e=>(0,v.jsx)(`th`,{children:e.year},e.year))]})}),(0,v.jsxs)(`tbody`,{children:[(0,v.jsx)(g,{dataRow:e=>(0,v.jsxs)(`tr`,{children:[(0,v.jsx)(`th`,{children:`Revenue`}),(0,v.jsx)(`th`,{children:S.revenue.amount.formatted}),(0,v.jsx)(`th`,{children:e}),C.map(e=>(0,v.jsx)(`th`,{children:e.revenue.amount.formatted},e.year))]}),commentaryData:S.revenue}),(0,v.jsx)(g,{dataRow:e=>(0,v.jsxs)(`tr`,{children:[(0,v.jsx)(`td`,{children:`Cost of Sales`}),(0,v.jsx)(`td`,{children:S.costOfSales.amount.formatted}),(0,v.jsx)(`th`,{children:e}),C.map(e=>(0,v.jsx)(`td`,{children:e.costOfSales.amount.formatted},e.year))]}),commentaryData:S.costOfSales}),(0,v.jsxs)(`tr`,{children:[(0,v.jsx)(`th`,{children:`Gross Profit`}),(0,v.jsx)(`th`,{children:S.grossProfit.formatted}),(0,v.jsx)(`th`,{}),C.map(e=>(0,v.jsx)(`th`,{children:e.grossProfit.formatted},e.year))]}),(0,v.jsx)(g,{dataRow:e=>(0,v.jsxs)(`tr`,{children:[(0,v.jsx)(`td`,{children:`R&D Expenses`}),(0,v.jsx)(`td`,{children:S.researchAndDevelopmentExpenses.amount.formatted}),(0,v.jsx)(`th`,{children:e}),C.map(e=>(0,v.jsx)(`td`,{children:e.researchAndDevelopmentExpenses.amount.formatted},e.year))]}),commentaryData:S.researchAndDevelopmentExpenses}),(0,v.jsx)(g,{dataRow:e=>(0,v.jsxs)(`tr`,{children:[(0,v.jsx)(`td`,{children:`Marketing Expenses`}),(0,v.jsx)(`td`,{children:S.marketingExpenses.amount.formatted}),(0,v.jsx)(`th`,{children:e}),C.map(e=>(0,v.jsx)(`td`,{children:e.marketingExpenses.amount.formatted},e.year))]}),commentaryData:S.marketingExpenses}),(0,v.jsx)(g,{dataRow:e=>(0,v.jsxs)(`tr`,{children:[(0,v.jsx)(`td`,{children:`Management and General Expenses`}),(0,v.jsx)(`td`,{children:S.managementAndGeneralExpenses.amount.formatted}),(0,v.jsx)(`th`,{children:e}),C.map(e=>(0,v.jsx)(`td`,{children:e.managementAndGeneralExpenses.amount.formatted},e.year))]}),commentaryData:S.managementAndGeneralExpenses}),(0,v.jsxs)(`tr`,{children:[(0,v.jsx)(`th`,{children:`Operating Profit`}),(0,v.jsx)(`th`,{children:S.operatingProfit.formatted}),(0,v.jsx)(`th`,{}),C.map(e=>(0,v.jsx)(`th`,{children:e.operatingProfit.formatted},e.year))]}),(0,v.jsx)(g,{dataRow:e=>(0,v.jsxs)(`tr`,{children:[(0,v.jsx)(`td`,{children:`Financial Expenses`}),(0,v.jsx)(`td`,{children:S.financialExpenses.amount.formatted}),(0,v.jsx)(`th`,{children:e}),C.map(e=>(0,v.jsx)(`td`,{children:e.financialExpenses.amount.formatted},e.year))]}),commentaryData:S.financialExpenses}),(0,v.jsx)(g,{dataRow:e=>(0,v.jsxs)(`tr`,{children:[(0,v.jsx)(`td`,{children:`Other Income`}),(0,v.jsx)(`td`,{children:S.otherIncome.amount.formatted}),(0,v.jsx)(`th`,{children:e}),C.map(e=>(0,v.jsx)(`td`,{children:e.otherIncome.amount.formatted},e.year))]}),commentaryData:S.otherIncome}),(0,v.jsxs)(`tr`,{children:[(0,v.jsx)(`th`,{children:`Profit Before Tax`}),(0,v.jsx)(`th`,{children:S.profitBeforeTax.formatted}),(0,v.jsx)(`th`,{}),C.map(e=>(0,v.jsx)(`th`,{children:e.profitBeforeTax.formatted},e.year))]}),(0,v.jsxs)(`tr`,{children:[(0,v.jsx)(`td`,{children:`Tax`}),(0,v.jsx)(`td`,{children:S.tax.formatted}),(0,v.jsx)(`td`,{}),C.map(e=>(0,v.jsx)(`td`,{children:e.tax.formatted},e.year))]})]}),(0,v.jsx)(`tfoot`,{children:(0,v.jsxs)(`tr`,{children:[(0,v.jsx)(`th`,{children:`Net Profit`}),(0,v.jsx)(`th`,{children:S.netProfit.formatted}),(0,v.jsx)(`th`,{}),C.map(e=>(0,v.jsx)(`th`,{children:e.netProfit.formatted},e.year))]})})]})})})};export{b as ProfitAndLossReport};