UNPKG

@accounter/client

Version:
1 lines • 6.58 kB
import{t as e}from"./funnel-DYKZrHgK.js";import{$t as t,Au as n,B as r,Cs as i,G as a,H as o,Ii as s,In as c,Kl as l,Ml as u,Nd as d,Ni as f,Pi as p,Pl as m,Pu as h,Rd as g,Tu as _,U as v,Ut as y,V as b,Vi as x,W as S,Xn as C,_n as w,cn as T,er as E,fn as D,gi as O,gn as k,hn as A,nr as j,pn as M,tr as N,vn as P,wn as F,ws as I,zi as L}from"./index-BdWApCqi.js";import{t as R}from"./use-url-query-8I97z9a3.js";import{t as z}from"./page-layout-9Fp4HhGU.js";var B=g(d(),1),V=_(),H=({record:e})=>{let t=C(i,e);return(0,V.jsxs)(a,{children:[(0,V.jsx)(o,{children:e.description}),(0,V.jsx)(o,{children:m(new Date(e.purchaseDate),`dd/MM/yyyy`)}),(0,V.jsx)(o,{children:e.activationDate?m(new Date(e.activationDate),`dd/MM/yyyy`):void 0}),(0,V.jsx)(o,{children:t.originalCost?x(t.originalCost,0):void 0}),(0,V.jsx)(o,{children:t.reportYearDelta?x(t.reportYearDelta,0):void 0}),(0,V.jsx)(o,{children:x(t.totalDepreciableCosts,0)}),(0,V.jsxs)(o,{children:[x(e.statutoryDepreciationRate,0),`%`]}),(0,V.jsx)(o,{children:e.claimedDepreciationRate?`${x(e.claimedDepreciationRate,1)}%`:`-`}),(0,V.jsx)(o,{children:t.reportYearClaimedDepreciation?x(t.reportYearClaimedDepreciation,0):`-`}),(0,V.jsx)(o,{children:t.pastYearsAccumulatedDepreciation?x(t.pastYearsAccumulatedDepreciation,0):`-`}),(0,V.jsx)(o,{children:t.totalDepreciation?x(t.totalDepreciation,0):`-`}),(0,V.jsx)(o,{children:t.netValue?x(t.netValue,0):`-`})]})},U=g(O(),1);function W({filter:e,setFilter:n,close:r}){let i=F({defaultValues:{...e}}),{control:a,handleSubmit:o}=i,{selectableFinancialEntities:c,fetching:u}=T(),d=e=>{n({...e,year:Number(e.year)}),r()};return(0,V.jsx)(D,{...i,children:(0,V.jsxs)(`form`,{onSubmit:o(d),className:`space-y-4`,children:[(0,V.jsx)(A,{name:`year`,control:a,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)(k,{children:[(0,V.jsx)(w,{children:`Year`}),(0,V.jsx)(M,{children:(0,V.jsx)(y,{...e,hideControls:!0,decimalScale:0})}),(0,V.jsx)(P,{})]})}),(0,V.jsx)(A,{name:`financialEntityId`,defaultValue:e?.financialEntityId,control:a,render:({field:e})=>(0,V.jsxs)(k,{children:[(0,V.jsx)(w,{children:`Owner`}),(0,V.jsx)(t,{...e,data:c,value:e.value??void 0,disabled:u,placeholder:`Select a financial entity`,formPart:!0}),(0,V.jsx)(P,{})]})}),(0,V.jsx)(s,{children:(0,V.jsx)(l,{type:`submit`,disabled:u,children:`Filter`})})]})})}function G({filter:t,setFilter:r}){let[i,a]=(0,B.useState)(!1),{get:o,set:s}=R();(0,B.useEffect)(()=>{let e=n(t);e!==o(`depreciationReportFilters`)&&s(h,e)},[t,o,s]);let c=(0,B.useCallback)(e=>{(0,U.default)(e,t)||r(e)},[t,r]);return(0,V.jsxs)(f,{open:i,onOpenChange:a,children:[(0,V.jsx)(L,{asChild:!0,children:(0,V.jsx)(l,{variant:`outline`,size:`icon`,children:(0,V.jsx)(e,{size:20})})}),(0,V.jsx)(p,{className:`sm:max-w-[425px]`,children:(0,V.jsx)(W,{filter:t,setFilter:c,close:()=>a(!1)})})]})}var K=({data:e,groupName:t})=>{let n=C(i,e);return(0,V.jsxs)(a,{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?x(n.originalCost,0):void 0}),(0,V.jsx)(o,{children:n.reportYearDelta?x(n.reportYearDelta,0):void 0}),(0,V.jsx)(o,{children:n.totalDepreciableCosts?x(n.totalDepreciableCosts,0):void 0}),(0,V.jsx)(o,{}),(0,V.jsx)(o,{}),(0,V.jsx)(o,{children:n.reportYearClaimedDepreciation?x(n.reportYearClaimedDepreciation,0):void 0}),(0,V.jsx)(o,{children:n.pastYearsAccumulatedDepreciation?x(n.pastYearsAccumulatedDepreciation,0):void 0}),(0,V.jsx)(o,{children:n.totalDepreciation?x(n.totalDepreciation,0):void 0}),(0,V.jsx)(o,{children:n.netValue?x(n.netValue,0):void 0})]})},q=()=>{let{setFiltersContext:e}=(0,B.useContext)(E),{userContext:t}=(0,B.useContext)(N),{get:n}=R(),[i,s]=(0,B.useState)((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])),[{data:l,fetching:d}]=u({query:I,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:s})}))},[i,e,s]),(0,V.jsx)(z,{title:`Depreciation Report`,description:(0,B.useMemo)(()=>`Depreciation Report for ${i.year}`,[i.year]),headerActions:(0,V.jsx)(c,{filename:`depreciation_report_${i.year??``}`}),children:d?(0,V.jsx)(j,{}):(0,V.jsxs)(r,{children:[(0,V.jsxs)(S,{children:[(0,V.jsxs)(a,{className:`font-bold text-xl`,children:[(0,V.jsx)(v,{colSpan:6,className:`text-center border-x`,children:`List of Assets and Costs`}),(0,V.jsx)(v,{colSpan:5,className:`text-center border-x`,children:`Depreciation`}),(0,V.jsx)(v,{className:`text-center border-x`,children:`Remaining`})]}),(0,V.jsxs)(a,{className:`border-b border-black`,children:[(0,V.jsx)(v,{className:`whitespace-normal`,children:`Assets List and Descriptions`}),(0,V.jsx)(v,{className:`whitespace-normal`,children:`Date of Purchase`}),(0,V.jsx)(v,{className:`whitespace-normal`,children:`Activation Date`}),(0,V.jsx)(v,{className:`whitespace-normal`,children:`Original Cost`}),(0,V.jsx)(v,{className:`whitespace-normal`,children:`Changes During the Year`}),(0,V.jsx)(v,{className:`whitespace-normal`,children:`Total Depreciable Assets`}),(0,V.jsx)(v,{className:`whitespace-normal`,children:`Statutory Depreciation Rate`}),(0,V.jsx)(v,{className:`whitespace-normal`,children:`Claimed Depreciation Rate`}),(0,V.jsx)(v,{className:`whitespace-normal`,children:`Depreciation Claimed This Year`}),(0,V.jsx)(v,{className:`whitespace-normal`,children:`Previous Tax Years Accumulated Depreciation`}),(0,V.jsx)(v,{className:`whitespace-normal`,children:`Total Depreciation`}),(0,V.jsx)(v,{className:`whitespace-normal`,children:`Net Book Value`})]})]}),(0,V.jsx)(b,{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)(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:[x(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:l.depreciationReport.summary})]})})]})})};export{q as DepreciationReport};