UNPKG

@accounter/client

Version:
1 lines • 6.84 kB
import{s as e}from"./dist-BmACi7k_.js";import{i as t,o as n}from"./utils-BxkqV8PM.js";import{Qn as r,Zn as i,zo as a}from"./error-handling-sQ-z99nE.js";import{n as o,o as s}from"./routes-C4NpBRv7.js";import{c,d as l,l as u,m as d}from"./select-KYQbDWZT.js";import{Ot as f,Xn as p,et as m,ht as h,ot as g}from"./common-DtK-TFhT.js";import{c as _}from"./separator-CNv9f_S5.js";import{t as v}from"./funnel-Djj7k08w.js";import{t as y}from"./button-BZ6z_NAl.js";import{$c as b,Gc as x,Jc as S,Kl as C,Pl as w,Wc as T,Xc as E,Yc as D,a as O,el as k,i as A,il as j,n as M,nl as N,o as P,qc as F,r as I,t as L}from"./table-D4eAFW7G.js";import{t as R}from"./use-url-query-DXFemxIX.js";import{t as z}from"./page-layout-jrXvjrbd.js";var B=e(n(),1),V=t(),H=({record:e})=>{let t=k(i,e);return(0,V.jsxs)(P,{children:[(0,V.jsx)(I,{children:e.description}),(0,V.jsx)(I,{children:C(new Date(e.purchaseDate),`dd/MM/yyyy`)}),(0,V.jsx)(I,{children:e.activationDate?C(new Date(e.activationDate),`dd/MM/yyyy`):void 0}),(0,V.jsx)(I,{children:t.originalCost?p(t.originalCost,0):void 0}),(0,V.jsx)(I,{children:t.reportYearDelta?p(t.reportYearDelta,0):void 0}),(0,V.jsx)(I,{children:p(t.totalDepreciableCosts,0)}),(0,V.jsxs)(I,{children:[p(e.statutoryDepreciationRate,0),`%`]}),(0,V.jsx)(I,{children:e.claimedDepreciationRate?`${p(e.claimedDepreciationRate,1)}%`:`-`}),(0,V.jsx)(I,{children:t.reportYearClaimedDepreciation?p(t.reportYearClaimedDepreciation,0):`-`}),(0,V.jsx)(I,{children:t.pastYearsAccumulatedDepreciation?p(t.pastYearsAccumulatedDepreciation,0):`-`}),(0,V.jsx)(I,{children:t.totalDepreciation?p(t.totalDepreciation,0):`-`}),(0,V.jsx)(I,{children:t.netValue?p(t.netValue,0):`-`})]})},U=e(w(),1);function W({filter:e,setFilter:t,close:n}){let r=b({defaultValues:{...e}}),{control:i,handleSubmit:a}=r,{selectableFinancialEntities:o,fetching:s}=h(),c=e=>{t({...e,year:Number(e.year)}),n()};return(0,V.jsx)(T,{...r,children:(0,V.jsxs)(`form`,{onSubmit:a(c),className:`space-y-4`,children:[(0,V.jsx)(F,{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)(S,{children:[(0,V.jsx)(D,{children:`Year`}),(0,V.jsx)(x,{children:(0,V.jsx)(m,{...e,hideControls:!0,decimalScale:0})}),(0,V.jsx)(E,{})]})}),(0,V.jsx)(F,{name:`financialEntityId`,defaultValue:e?.financialEntityId,control:i,render:({field:e})=>(0,V.jsxs)(S,{children:[(0,V.jsx)(D,{children:`Owner`}),(0,V.jsx)(g,{...e,data:o,value:e.value??void 0,disabled:s,placeholder:`Select a financial entity`,formPart:!0}),(0,V.jsx)(E,{})]})}),(0,V.jsx)(l,{children:(0,V.jsx)(y,{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)(y,{variant:`outline`,size:`icon`,children:(0,V.jsx)(v,{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=k(i,e);return(0,V.jsxs)(P,{className:`font-bold border-b border-black`,children:[(0,V.jsx)(I,{children:t?`Group Total`:`Overall Total`}),(0,V.jsx)(I,{colSpan:2,children:t}),(0,V.jsx)(I,{children:n.originalCost?p(n.originalCost,0):void 0}),(0,V.jsx)(I,{children:n.reportYearDelta?p(n.reportYearDelta,0):void 0}),(0,V.jsx)(I,{children:n.totalDepreciableCosts?p(n.totalDepreciableCosts,0):void 0}),(0,V.jsx)(I,{}),(0,V.jsx)(I,{}),(0,V.jsx)(I,{children:n.reportYearClaimedDepreciation?p(n.reportYearClaimedDepreciation,0):void 0}),(0,V.jsx)(I,{children:n.pastYearsAccumulatedDepreciation?p(n.pastYearsAccumulatedDepreciation,0):void 0}),(0,V.jsx)(I,{children:n.totalDepreciation?p(n.totalDepreciation,0):void 0}),(0,V.jsx)(I,{children:n.netValue?p(n.netValue,0):void 0})]})},q=()=>{let{setFiltersContext:e}=(0,B.useContext)(_),{userContext:t}=(0,B.useContext)(N),{get:n}=R(),[i,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}]=a({query:r,variables:{filters:i}});return(0,B.useEffect)(()=>{e((0,V.jsx)(`div`,{className:`flex flex-row gap-x-5`,children:(0,V.jsx)(G,{filter:i,setFilter:o})}))},[i,e,o]),(0,V.jsx)(z,{title:`Depreciation Report`,description:(0,B.useMemo)(()=>`Depreciation Report for ${i.year}`,[i.year]),headerActions:(0,V.jsx)(f,{filename:`depreciation_report_${i.year??``}`}),children:l?(0,V.jsx)(j,{}):(0,V.jsxs)(L,{children:[(0,V.jsxs)(O,{children:[(0,V.jsxs)(P,{className:`font-bold text-xl`,children:[(0,V.jsx)(A,{colSpan:6,className:`text-center border-x`,children:`List of Assets and Costs`}),(0,V.jsx)(A,{colSpan:5,className:`text-center border-x`,children:`Depreciation`}),(0,V.jsx)(A,{className:`text-center border-x`,children:`Remaining`})]}),(0,V.jsxs)(P,{className:`border-b border-black`,children:[(0,V.jsx)(A,{className:`whitespace-normal`,children:`Assets List and Descriptions`}),(0,V.jsx)(A,{className:`whitespace-normal`,children:`Date of Purchase`}),(0,V.jsx)(A,{className:`whitespace-normal`,children:`Activation Date`}),(0,V.jsx)(A,{className:`whitespace-normal`,children:`Original Cost`}),(0,V.jsx)(A,{className:`whitespace-normal`,children:`Changes During the Year`}),(0,V.jsx)(A,{className:`whitespace-normal`,children:`Total Depreciable Assets`}),(0,V.jsx)(A,{className:`whitespace-normal`,children:`Statutory Depreciation Rate`}),(0,V.jsx)(A,{className:`whitespace-normal`,children:`Claimed Depreciation Rate`}),(0,V.jsx)(A,{className:`whitespace-normal`,children:`Depreciation Claimed This Year`}),(0,V.jsx)(A,{className:`whitespace-normal`,children:`Previous Tax Years Accumulated Depreciation`}),(0,V.jsx)(A,{className:`whitespace-normal`,children:`Total Depreciation`}),(0,V.jsx)(A,{className:`whitespace-normal`,children:`Net Book Value`})]})]}),(0,V.jsx)(M,{children:c?.depreciationReport&&(0,V.jsxs)(V.Fragment,{children:[c.depreciationReport.categories.map((e,t)=>(0,V.jsxs)(B.Fragment,{children:[(0,V.jsxs)(P,{className:`font-bold`,children:[(0,V.jsx)(I,{children:`Category ${t+1}`}),(0,V.jsx)(I,{colSpan:2,children:e.category.name}),(0,V.jsx)(I,{colSpan:3}),(0,V.jsxs)(I,{children:[p(e.category.percentage,0),`%`]}),(0,V.jsx)(I,{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};