UNPKG

@accounter/client

Version:
1 lines • 6.8 kB
import{s as e}from"./dist-C51EwTaa.js";import{i as t,o as n}from"./utils-DdVdMk8X.js";import{$n as r,Lo as i,Qn as a}from"./error-handling-Dpfd9svJ.js";import{n as o,o as s}from"./routes-DUvpW9-n.js";import{c,d as l,l as u,m as d}from"./select-CrsvQyhZ.js";import{t as f}from"./funnel-BFbxpUGW.js";import{t as p}from"./button-Dzp2INW0.js";import{B as m,F as h,J as g,K as _,L as v,Lt as y,P as b,R as x,U as S,W as C,a as w,i as T,n as E,o as D,r as O,t as k,wt as A,z as j}from"./table--bF0wbxq.js";import{Kt as M,Nt as N,cn as P,hr as F,ht as I,wt as L}from"./index-CL8-JoMZ.js";import{t as R}from"./use-url-query-BCNbSvLg.js";import{t as z}from"./page-layout-DoLDsSrs.js";var B=e(n(),1),V=t(),H=({record:e})=>{let t=C(a,e);return(0,V.jsxs)(D,{children:[(0,V.jsx)(O,{children:e.description}),(0,V.jsx)(O,{children:y(new Date(e.purchaseDate),`dd/MM/yyyy`)}),(0,V.jsx)(O,{children:e.activationDate?y(new Date(e.activationDate),`dd/MM/yyyy`):void 0}),(0,V.jsx)(O,{children:t.originalCost?F(t.originalCost,0):void 0}),(0,V.jsx)(O,{children:t.reportYearDelta?F(t.reportYearDelta,0):void 0}),(0,V.jsx)(O,{children:F(t.totalDepreciableCosts,0)}),(0,V.jsxs)(O,{children:[F(e.statutoryDepreciationRate,0),`%`]}),(0,V.jsx)(O,{children:e.claimedDepreciationRate?`${F(e.claimedDepreciationRate,1)}%`:`-`}),(0,V.jsx)(O,{children:t.reportYearClaimedDepreciation?F(t.reportYearClaimedDepreciation,0):`-`}),(0,V.jsx)(O,{children:t.pastYearsAccumulatedDepreciation?F(t.pastYearsAccumulatedDepreciation,0):`-`}),(0,V.jsx)(O,{children:t.totalDepreciation?F(t.totalDepreciation,0):`-`}),(0,V.jsx)(O,{children:t.netValue?F(t.netValue,0):`-`})]})},U=e(A(),1);function W({filter:e,setFilter:t,close:n}){let r=S({defaultValues:{...e}}),{control:i,handleSubmit:a}=r,{selectableFinancialEntities:o,fetching:s}=N(),c=e=>{t({...e,year:Number(e.year)}),n()};return(0,V.jsx)(b,{...r,children:(0,V.jsxs)(`form`,{onSubmit:a(c),className:`space-y-4`,children:[(0,V.jsx)(v,{name:`year`,control:i,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)(x,{children:[(0,V.jsx)(j,{children:`Year`}),(0,V.jsx)(h,{children:(0,V.jsx)(I,{...e,hideControls:!0,decimalScale:0})}),(0,V.jsx)(m,{})]})}),(0,V.jsx)(v,{name:`financialEntityId`,defaultValue:e?.financialEntityId,control:i,render:({field:e})=>(0,V.jsxs)(x,{children:[(0,V.jsx)(j,{children:`Owner`}),(0,V.jsx)(L,{...e,data:o,value:e.value??void 0,disabled:s,placeholder:`Select a financial entity`,formPart:!0}),(0,V.jsx)(m,{})]})}),(0,V.jsx)(l,{children:(0,V.jsx)(p,{type:`submit`,disabled:s,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=o(e);t!==i(`depreciationReportFilters`)&&a(s,t)},[e,i,a]);let l=(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)(p,{variant:`outline`,size:`icon`,children:(0,V.jsx)(f,{size:20})})}),(0,V.jsx)(u,{className:`sm:max-w-[425px]`,children:(0,V.jsx)(W,{filter:e,setFilter:l,close:()=>r(!1)})})]})}var K=({data:e,groupName:t})=>{let n=C(a,e);return(0,V.jsxs)(D,{className:`font-bold border-b border-black`,children:[(0,V.jsx)(O,{children:t?`Group Total`:`Overall Total`}),(0,V.jsx)(O,{colSpan:2,children:t}),(0,V.jsx)(O,{children:n.originalCost?F(n.originalCost,0):void 0}),(0,V.jsx)(O,{children:n.reportYearDelta?F(n.reportYearDelta,0):void 0}),(0,V.jsx)(O,{children:n.totalDepreciableCosts?F(n.totalDepreciableCosts,0):void 0}),(0,V.jsx)(O,{}),(0,V.jsx)(O,{}),(0,V.jsx)(O,{children:n.reportYearClaimedDepreciation?F(n.reportYearClaimedDepreciation,0):void 0}),(0,V.jsx)(O,{children:n.pastYearsAccumulatedDepreciation?F(n.pastYearsAccumulatedDepreciation,0):void 0}),(0,V.jsx)(O,{children:n.totalDepreciation?F(n.totalDepreciation,0):void 0}),(0,V.jsx)(O,{children:n.netValue?F(n.netValue,0):void 0})]})},q=()=>{let{setFiltersContext:e}=(0,B.useContext)(P),{userContext:t}=(0,B.useContext)(_),{get:n}=R(),[a,o]=(0,B.useState)((0,B.useMemo)(()=>{let e={financialEntityId:t?.context.adminBusinessId,year:new Date().getFullYear()},r=n(s);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])),[{data:c,fetching:l}]=i({query:r,variables:{filters:a}});return(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]),(0,V.jsx)(z,{title:`Depreciation Report`,description:(0,B.useMemo)(()=>`Depreciation Report for ${a.year}`,[a.year]),headerActions:(0,V.jsx)(M,{filename:`depreciation_report_${a.year??``}`}),children:l?(0,V.jsx)(g,{}):(0,V.jsxs)(k,{children:[(0,V.jsxs)(w,{children:[(0,V.jsxs)(D,{className:`font-bold text-xl`,children:[(0,V.jsx)(T,{colSpan:6,className:`text-center border-x`,children:`List of Assets and Costs`}),(0,V.jsx)(T,{colSpan:5,className:`text-center border-x`,children:`Depreciation`}),(0,V.jsx)(T,{className:`text-center border-x`,children:`Remaining`})]}),(0,V.jsxs)(D,{className:`border-b border-black`,children:[(0,V.jsx)(T,{className:`whitespace-normal`,children:`Assets List and Descriptions`}),(0,V.jsx)(T,{className:`whitespace-normal`,children:`Date of Purchase`}),(0,V.jsx)(T,{className:`whitespace-normal`,children:`Activation Date`}),(0,V.jsx)(T,{className:`whitespace-normal`,children:`Original Cost`}),(0,V.jsx)(T,{className:`whitespace-normal`,children:`Changes During the Year`}),(0,V.jsx)(T,{className:`whitespace-normal`,children:`Total Depreciable Assets`}),(0,V.jsx)(T,{className:`whitespace-normal`,children:`Statutory Depreciation Rate`}),(0,V.jsx)(T,{className:`whitespace-normal`,children:`Claimed Depreciation Rate`}),(0,V.jsx)(T,{className:`whitespace-normal`,children:`Depreciation Claimed This Year`}),(0,V.jsx)(T,{className:`whitespace-normal`,children:`Previous Tax Years Accumulated Depreciation`}),(0,V.jsx)(T,{className:`whitespace-normal`,children:`Total Depreciation`}),(0,V.jsx)(T,{className:`whitespace-normal`,children:`Net Book Value`})]})]}),(0,V.jsx)(E,{children:c?.depreciationReport&&(0,V.jsxs)(V.Fragment,{children:[c.depreciationReport.categories.map((e,t)=>(0,V.jsxs)(B.Fragment,{children:[(0,V.jsxs)(D,{className:`font-bold`,children:[(0,V.jsx)(O,{children:`Category ${t+1}`}),(0,V.jsx)(O,{colSpan:2,children:e.category.name}),(0,V.jsx)(O,{colSpan:3}),(0,V.jsxs)(O,{children:[F(e.category.percentage,0),`%`]}),(0,V.jsx)(O,{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};