UNPKG

@accounter/client

Version:
1 lines • 6.85 kB
import{s as e}from"./dist-ypP48_Ax.js";import{i as t,o as n}from"./utils-CbS-oR5I.js";import{n as r,o as i}from"./routes-Cawu7UJi.js";import{Yn as a,et as o,ht as s,kt as c,ot as l}from"./common-D-vYt_Yl.js";import{c as u,d,l as f,m as p}from"./select-Zdatwv1b.js";import{c as m}from"./separator-BvKylNhK.js";import{t as h}from"./funnel-BrJTCiKR.js";import{t as g}from"./button-DUNsVBiu.js";import{$c as _,Gc as v,Hc as y,Kc as b,Ul as x,Vc as S,Wc as C,Xc as w,Zc as T,a as E,i as D,jl as O,n as k,o as A,qc as j,r as M,t as N,tl as P}from"./table-AJA7Uyxy.js";import{Qo as F,Xn as I,Yn as L}from"./graphql-DC5GYCFE.js";import{t as R}from"./use-url-query-Bb8ddrDs.js";import{t as z}from"./page-layout-DfY10rJx.js";var B=e(n(),1),V=t(),H=({record:e})=>{let t=T(L,e);return(0,V.jsxs)(A,{children:[(0,V.jsx)(M,{children:e.description}),(0,V.jsx)(M,{children:x(new Date(e.purchaseDate),`dd/MM/yyyy`)}),(0,V.jsx)(M,{children:e.activationDate?x(new Date(e.activationDate),`dd/MM/yyyy`):void 0}),(0,V.jsx)(M,{children:t.originalCost?a(t.originalCost,0):void 0}),(0,V.jsx)(M,{children:t.reportYearDelta?a(t.reportYearDelta,0):void 0}),(0,V.jsx)(M,{children:a(t.totalDepreciableCosts,0)}),(0,V.jsxs)(M,{children:[a(e.statutoryDepreciationRate,0),`%`]}),(0,V.jsx)(M,{children:e.claimedDepreciationRate?`${a(e.claimedDepreciationRate,1)}%`:`-`}),(0,V.jsx)(M,{children:t.reportYearClaimedDepreciation?a(t.reportYearClaimedDepreciation,0):`-`}),(0,V.jsx)(M,{children:t.pastYearsAccumulatedDepreciation?a(t.pastYearsAccumulatedDepreciation,0):`-`}),(0,V.jsx)(M,{children:t.totalDepreciation?a(t.totalDepreciation,0):`-`}),(0,V.jsx)(M,{children:t.netValue?a(t.netValue,0):`-`})]})},U=e(O(),1);function W({filter:e,setFilter:t,close:n}){let r=w({defaultValues:{...e}}),{control:i,handleSubmit:a}=r,{selectableFinancialEntities:c,fetching:u}=s(),f=e=>{t({...e,year:Number(e.year)}),n()};return(0,V.jsx)(S,{...r,children:(0,V.jsxs)(`form`,{onSubmit:a(f),className:`space-y-4`,children:[(0,V.jsx)(C,{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)(v,{children:[(0,V.jsx)(b,{children:`Year`}),(0,V.jsx)(y,{children:(0,V.jsx)(o,{...e,hideControls:!0,decimalScale:0})}),(0,V.jsx)(j,{})]})}),(0,V.jsx)(C,{name:`financialEntityId`,defaultValue:e?.financialEntityId,control:i,render:({field:e})=>(0,V.jsxs)(v,{children:[(0,V.jsx)(b,{children:`Owner`}),(0,V.jsx)(l,{...e,data:c,value:e.value??void 0,disabled:u,placeholder:`Select a financial entity`,formPart:!0}),(0,V.jsx)(j,{})]})}),(0,V.jsx)(d,{children:(0,V.jsx)(g,{type:`submit`,disabled:u,children:`Filter`})})]})})}function G({filter:e,setFilter:t}){let[n,a]=(0,B.useState)(!1),{get:o,set:s}=R();(0,B.useEffect)(()=>{let t=r(e);t!==o(`depreciationReportFilters`)&&s(i,t)},[e,o,s]);let c=(0,B.useCallback)(n=>{(0,U.default)(n,e)||t(n)},[e,t]);return(0,V.jsxs)(u,{open:n,onOpenChange:a,children:[(0,V.jsx)(p,{asChild:!0,children:(0,V.jsx)(g,{variant:`outline`,size:`icon`,children:(0,V.jsx)(h,{size:20})})}),(0,V.jsx)(f,{className:`sm:max-w-[425px]`,children:(0,V.jsx)(W,{filter:e,setFilter:c,close:()=>a(!1)})})]})}var K=({data:e,groupName:t})=>{let n=T(L,e);return(0,V.jsxs)(A,{className:`font-bold border-b border-black`,children:[(0,V.jsx)(M,{children:t?`Group Total`:`Overall Total`}),(0,V.jsx)(M,{colSpan:2,children:t}),(0,V.jsx)(M,{children:n.originalCost?a(n.originalCost,0):void 0}),(0,V.jsx)(M,{children:n.reportYearDelta?a(n.reportYearDelta,0):void 0}),(0,V.jsx)(M,{children:n.totalDepreciableCosts?a(n.totalDepreciableCosts,0):void 0}),(0,V.jsx)(M,{}),(0,V.jsx)(M,{}),(0,V.jsx)(M,{children:n.reportYearClaimedDepreciation?a(n.reportYearClaimedDepreciation,0):void 0}),(0,V.jsx)(M,{children:n.pastYearsAccumulatedDepreciation?a(n.pastYearsAccumulatedDepreciation,0):void 0}),(0,V.jsx)(M,{children:n.totalDepreciation?a(n.totalDepreciation,0):void 0}),(0,V.jsx)(M,{children:n.netValue?a(n.netValue,0):void 0})]})},q=()=>{let{setFiltersContext:e}=(0,B.useContext)(m),{userContext:t}=(0,B.useContext)(_),{get:n}=R(),r=(0,B.useMemo)(()=>{let e={financialEntityId:t?.context.adminBusinessId,year:new Date().getFullYear()},r=n(i);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]),[o,s]=(0,B.useState)(r),[{data:l,fetching:u}]=F({query:I,variables:{filters:o}});(0,B.useEffect)(()=>{e((0,V.jsx)(`div`,{className:`flex flex-row gap-x-5`,children:(0,V.jsx)(G,{filter:o,setFilter:s})}))},[o,e,s]);let d=(0,B.useMemo)(()=>`Depreciation Report for ${o.year}`,[o.year]);return(0,V.jsx)(z,{title:`Depreciation Report`,description:d,headerActions:(0,V.jsx)(c,{filename:`depreciation_report_${o.year??``}`}),children:u?(0,V.jsx)(P,{}):(0,V.jsxs)(N,{children:[(0,V.jsxs)(E,{children:[(0,V.jsxs)(A,{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)(A,{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:l?.depreciationReport&&(0,V.jsxs)(V.Fragment,{children:[l.depreciationReport.categories.map((e,t)=>(0,V.jsxs)(B.Fragment,{children:[(0,V.jsxs)(A,{className:`font-bold`,children:[(0,V.jsx)(M,{children:`Category ${t+1}`}),(0,V.jsx)(M,{colSpan:2,children:e.category.name}),(0,V.jsx)(M,{colSpan:3}),(0,V.jsxs)(M,{children:[a(e.category.percentage,0),`%`]}),(0,V.jsx)(M,{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:l.depreciationReport.summary})]})})]})})};export{q as DepreciationReport};