@accounter/client
Version:
Accounter client application
1 lines • 6.85 kB
JavaScript
import{s as e}from"./dist-ypP48_Ax.js";import{i as t,o as n}from"./utils-CbS-oR5I.js";import{Qn as r,ct as i,et as a,gt as o,jt as s}from"./common-DtCH-1rN.js";import{c,d as l,l as u,m as d}from"./select-DrAHsHyM.js";import{c as f}from"./separator-C_NTzotM.js";import{t as p}from"./funnel-CtGZVesZ.js";import{n as m,o as h}from"./routes-4W-duEv9.js";import{t as g}from"./button-DUNsVBiu.js";import{Gc as _,Hc as v,Kc as y,Kl as b,Pl as x,Vc as S,Wc as C,Zc as w,a as T,el as E,i as D,il as O,n as k,nl as A,o as j,qc as M,r as N,t as P}from"./table-BXolY871.js";import{Qn as F,Zn as I,ls as L}from"./graphql-HKLcNTdf.js";import{t as R}from"./use-url-query-C3m3Z87n.js";import{t as z}from"./page-layout-DtkTEMd2.js";var B=e(n(),1),V=t(),H=({record:e})=>{let t=E(I,e);return(0,V.jsxs)(j,{children:[(0,V.jsx)(N,{children:e.description}),(0,V.jsx)(N,{children:b(new Date(e.purchaseDate),`dd/MM/yyyy`)}),(0,V.jsx)(N,{children:e.activationDate?b(new Date(e.activationDate),`dd/MM/yyyy`):void 0}),(0,V.jsx)(N,{children:t.originalCost?r(t.originalCost,0):void 0}),(0,V.jsx)(N,{children:t.reportYearDelta?r(t.reportYearDelta,0):void 0}),(0,V.jsx)(N,{children:r(t.totalDepreciableCosts,0)}),(0,V.jsxs)(N,{children:[r(e.statutoryDepreciationRate,0),`%`]}),(0,V.jsx)(N,{children:e.claimedDepreciationRate?`${r(e.claimedDepreciationRate,1)}%`:`-`}),(0,V.jsx)(N,{children:t.reportYearClaimedDepreciation?r(t.reportYearClaimedDepreciation,0):`-`}),(0,V.jsx)(N,{children:t.pastYearsAccumulatedDepreciation?r(t.pastYearsAccumulatedDepreciation,0):`-`}),(0,V.jsx)(N,{children:t.totalDepreciation?r(t.totalDepreciation,0):`-`}),(0,V.jsx)(N,{children:t.netValue?r(t.netValue,0):`-`})]})},U=e(x(),1);function W({filter:e,setFilter:t,close:n}){let r=w({defaultValues:{...e}}),{control:s,handleSubmit:c}=r,{selectableFinancialEntities:u,fetching:d}=o(),f=e=>{t({...e,year:Number(e.year)}),n()};return(0,V.jsx)(S,{...r,children:(0,V.jsxs)(`form`,{onSubmit:c(f),className:`space-y-4`,children:[(0,V.jsx)(C,{name:`year`,control:s,rules:{required:`Year is required`,validate:e=>{let t=Number(e);return Number.isNaN(t)||t<2e3||t>2100?`Invalid year`:!0}},render:({field:e})=>(0,V.jsxs)(_,{children:[(0,V.jsx)(y,{children:`Year`}),(0,V.jsx)(v,{children:(0,V.jsx)(a,{...e,hideControls:!0,decimalScale:0})}),(0,V.jsx)(M,{})]})}),(0,V.jsx)(C,{name:`financialEntityId`,defaultValue:e?.financialEntityId,control:s,render:({field:e})=>(0,V.jsxs)(_,{children:[(0,V.jsx)(y,{children:`Owner`}),(0,V.jsx)(i,{...e,data:u,value:e.value??void 0,disabled:d,placeholder:`Select a financial entity`,formPart:!0}),(0,V.jsx)(M,{})]})}),(0,V.jsx)(l,{children:(0,V.jsx)(g,{type:`submit`,disabled:d,children:`Filter`})})]})})}function G({filter:e,setFilter:t}){let[n,r]=(0,B.useState)(!1),{get:i,set:a}=R();(0,B.useEffect)(()=>{let t=m(e);t!==i(`depreciationReportFilters`)&&a(h,t)},[e,i,a]);let o=(0,B.useCallback)(n=>{(0,U.default)(n,e)||t(n)},[e,t]);return(0,V.jsxs)(c,{open:n,onOpenChange:r,children:[(0,V.jsx)(d,{asChild:!0,children:(0,V.jsx)(g,{variant:`outline`,size:`icon`,children:(0,V.jsx)(p,{size:20})})}),(0,V.jsx)(u,{className:`sm:max-w-[425px]`,children:(0,V.jsx)(W,{filter:e,setFilter:o,close:()=>r(!1)})})]})}var K=({data:e,groupName:t})=>{let n=E(I,e);return(0,V.jsxs)(j,{className:`font-bold border-b border-black`,children:[(0,V.jsx)(N,{children:t?`Group Total`:`Overall Total`}),(0,V.jsx)(N,{colSpan:2,children:t}),(0,V.jsx)(N,{children:n.originalCost?r(n.originalCost,0):void 0}),(0,V.jsx)(N,{children:n.reportYearDelta?r(n.reportYearDelta,0):void 0}),(0,V.jsx)(N,{children:n.totalDepreciableCosts?r(n.totalDepreciableCosts,0):void 0}),(0,V.jsx)(N,{}),(0,V.jsx)(N,{}),(0,V.jsx)(N,{children:n.reportYearClaimedDepreciation?r(n.reportYearClaimedDepreciation,0):void 0}),(0,V.jsx)(N,{children:n.pastYearsAccumulatedDepreciation?r(n.pastYearsAccumulatedDepreciation,0):void 0}),(0,V.jsx)(N,{children:n.totalDepreciation?r(n.totalDepreciation,0):void 0}),(0,V.jsx)(N,{children:n.netValue?r(n.netValue,0):void 0})]})},q=()=>{let{setFiltersContext:e}=(0,B.useContext)(f),{userContext:t}=(0,B.useContext)(A),{get:n}=R(),i=(0,B.useMemo)(()=>{let e={financialEntityId:t?.context.adminBusinessId,year:new Date().getFullYear()},r=n(h);if(r)try{return JSON.parse(decodeURIComponent(r))}catch(e){console.error(`Failed to parse depreciation report filters from URL`,e)}return e},[t?.context.adminBusinessId,n]),[a,o]=(0,B.useState)(i),[{data:c,fetching:l}]=L({query:F,variables:{filters:a}});(0,B.useEffect)(()=>{e((0,V.jsx)(`div`,{className:`flex flex-row gap-x-5`,children:(0,V.jsx)(G,{filter:a,setFilter:o})}))},[a,e,o]);let u=(0,B.useMemo)(()=>`Depreciation Report for ${a.year}`,[a.year]);return(0,V.jsx)(z,{title:`Depreciation Report`,description:u,headerActions:(0,V.jsx)(s,{filename:`depreciation_report_${a.year??``}`}),children:l?(0,V.jsx)(O,{}):(0,V.jsxs)(P,{children:[(0,V.jsxs)(T,{children:[(0,V.jsxs)(j,{className:`font-bold text-xl`,children:[(0,V.jsx)(D,{colSpan:6,className:`text-center border-x`,children:`List of Assets and Costs`}),(0,V.jsx)(D,{colSpan:5,className:`text-center border-x`,children:`Depreciation`}),(0,V.jsx)(D,{className:`text-center border-x`,children:`Remaining`})]}),(0,V.jsxs)(j,{className:`border-b border-black`,children:[(0,V.jsx)(D,{className:`whitespace-normal`,children:`Assets List and Descriptions`}),(0,V.jsx)(D,{className:`whitespace-normal`,children:`Date of Purchase`}),(0,V.jsx)(D,{className:`whitespace-normal`,children:`Activation Date`}),(0,V.jsx)(D,{className:`whitespace-normal`,children:`Original Cost`}),(0,V.jsx)(D,{className:`whitespace-normal`,children:`Changes During the Year`}),(0,V.jsx)(D,{className:`whitespace-normal`,children:`Total Depreciable Assets`}),(0,V.jsx)(D,{className:`whitespace-normal`,children:`Statutory Depreciation Rate`}),(0,V.jsx)(D,{className:`whitespace-normal`,children:`Claimed Depreciation Rate`}),(0,V.jsx)(D,{className:`whitespace-normal`,children:`Depreciation Claimed This Year`}),(0,V.jsx)(D,{className:`whitespace-normal`,children:`Previous Tax Years Accumulated Depreciation`}),(0,V.jsx)(D,{className:`whitespace-normal`,children:`Total Depreciation`}),(0,V.jsx)(D,{className:`whitespace-normal`,children:`Net Book Value`})]})]}),(0,V.jsx)(k,{children:c?.depreciationReport&&(0,V.jsxs)(V.Fragment,{children:[c.depreciationReport.categories.map((e,t)=>(0,V.jsxs)(B.Fragment,{children:[(0,V.jsxs)(j,{className:`font-bold`,children:[(0,V.jsx)(N,{children:`Category ${t+1}`}),(0,V.jsx)(N,{colSpan:2,children:e.category.name}),(0,V.jsx)(N,{colSpan:3}),(0,V.jsxs)(N,{children:[r(e.category.percentage,0),`%`]}),(0,V.jsx)(N,{colSpan:5})]}),e.records.sort((e,t)=>e.purchaseDate.localeCompare(t.purchaseDate)).map(e=>(0,V.jsx)(H,{record:e},e.id)),(0,V.jsx)(K,{data:e.summary,groupName:e.category.name})]},e.id)),(0,V.jsx)(K,{data:c.depreciationReport.summary})]})})]})})};export{q as DepreciationReport};