UNPKG

@accounter/client

Version:
1 lines • 6.58 kB
import{t as e}from"./funnel-CDY9d08i.js";import{$t as t,Al as n,B as r,Cs as i,Cu as a,G as o,H as s,Id as c,Ii as l,In as u,Ml as d,Mu as f,Ni as p,Ou as m,Pi as h,Ss as g,U as _,Ut as v,V as y,Vi as b,W as x,Wl 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,jd as j,nr as M,pn as N,tr as P,vn as F,wn as I,zi as L}from"./index-CSYTUOOk.js";import{t as R}from"./use-url-query-CA_xnIYM.js";import{t as z}from"./page-layout-DE94O32j.js";var B=c(j(),1),V=a(),H=({record:e})=>{let t=C(g,e);return(0,V.jsxs)(o,{children:[(0,V.jsx)(s,{children:e.description}),(0,V.jsx)(s,{children:d(new Date(e.purchaseDate),`dd/MM/yyyy`)}),(0,V.jsx)(s,{children:e.activationDate?d(new Date(e.activationDate),`dd/MM/yyyy`):void 0}),(0,V.jsx)(s,{children:t.originalCost?b(t.originalCost,0):void 0}),(0,V.jsx)(s,{children:t.reportYearDelta?b(t.reportYearDelta,0):void 0}),(0,V.jsx)(s,{children:b(t.totalDepreciableCosts,0)}),(0,V.jsxs)(s,{children:[b(e.statutoryDepreciationRate,0),`%`]}),(0,V.jsx)(s,{children:e.claimedDepreciationRate?`${b(e.claimedDepreciationRate,1)}%`:`-`}),(0,V.jsx)(s,{children:t.reportYearClaimedDepreciation?b(t.reportYearClaimedDepreciation,0):`-`}),(0,V.jsx)(s,{children:t.pastYearsAccumulatedDepreciation?b(t.pastYearsAccumulatedDepreciation,0):`-`}),(0,V.jsx)(s,{children:t.totalDepreciation?b(t.totalDepreciation,0):`-`}),(0,V.jsx)(s,{children:t.netValue?b(t.netValue,0):`-`})]})},U=c(O(),1);function W({filter:e,setFilter:n,close:r}){let i=I({defaultValues:{...e}}),{control:a,handleSubmit:o}=i,{selectableFinancialEntities:s,fetching:c}=T(),u=e=>{n({...e,year:Number(e.year)}),r()};return(0,V.jsx)(D,{...i,children:(0,V.jsxs)(`form`,{onSubmit:o(u),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)(N,{children:(0,V.jsx)(v,{...e,hideControls:!0,decimalScale:0})}),(0,V.jsx)(F,{})]})}),(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:s,value:e.value??void 0,disabled:c,placeholder:`Select a financial entity`,formPart:!0}),(0,V.jsx)(F,{})]})}),(0,V.jsx)(l,{children:(0,V.jsx)(S,{type:`submit`,disabled:c,children:`Filter`})})]})})}function G({filter:t,setFilter:n}){let[r,i]=(0,B.useState)(!1),{get:a,set:o}=R();(0,B.useEffect)(()=>{let e=m(t);e!==a(`depreciationReportFilters`)&&o(f,e)},[t,a,o]);let s=(0,B.useCallback)(e=>{(0,U.default)(e,t)||n(e)},[t,n]);return(0,V.jsxs)(p,{open:r,onOpenChange:i,children:[(0,V.jsx)(L,{asChild:!0,children:(0,V.jsx)(S,{variant:`outline`,size:`icon`,children:(0,V.jsx)(e,{size:20})})}),(0,V.jsx)(h,{className:`sm:max-w-[425px]`,children:(0,V.jsx)(W,{filter:t,setFilter:s,close:()=>i(!1)})})]})}var K=({data:e,groupName:t})=>{let n=C(g,e);return(0,V.jsxs)(o,{className:`font-bold border-b border-black`,children:[(0,V.jsx)(s,{children:t?`Group Total`:`Overall Total`}),(0,V.jsx)(s,{colSpan:2,children:t}),(0,V.jsx)(s,{children:n.originalCost?b(n.originalCost,0):void 0}),(0,V.jsx)(s,{children:n.reportYearDelta?b(n.reportYearDelta,0):void 0}),(0,V.jsx)(s,{children:n.totalDepreciableCosts?b(n.totalDepreciableCosts,0):void 0}),(0,V.jsx)(s,{}),(0,V.jsx)(s,{}),(0,V.jsx)(s,{children:n.reportYearClaimedDepreciation?b(n.reportYearClaimedDepreciation,0):void 0}),(0,V.jsx)(s,{children:n.pastYearsAccumulatedDepreciation?b(n.pastYearsAccumulatedDepreciation,0):void 0}),(0,V.jsx)(s,{children:n.totalDepreciation?b(n.totalDepreciation,0):void 0}),(0,V.jsx)(s,{children:n.netValue?b(n.netValue,0):void 0})]})},q=()=>{let{setFiltersContext:e}=(0,B.useContext)(E),{userContext:t}=(0,B.useContext)(P),{get:a}=R(),[c,l]=(0,B.useState)((0,B.useMemo)(()=>{let e={financialEntityId:t?.context.adminBusinessId,year:new Date().getFullYear()},n=a(f);if(n)try{return JSON.parse(decodeURIComponent(n))}catch(e){console.error(`Failed to parse depreciation report filters from URL`,e)}return e},[t?.context.adminBusinessId,a])),[{data:d,fetching:p}]=n({query:i,variables:{filters:c}});return(0,B.useEffect)(()=>{e((0,V.jsx)(`div`,{className:`flex flex-row gap-x-5`,children:(0,V.jsx)(G,{filter:c,setFilter:l})}))},[c,e,l]),(0,V.jsx)(z,{title:`Depreciation Report`,description:(0,B.useMemo)(()=>`Depreciation Report for ${c.year}`,[c.year]),headerActions:(0,V.jsx)(u,{filename:`depreciation_report_${c.year??``}`}),children:p?(0,V.jsx)(M,{}):(0,V.jsxs)(r,{children:[(0,V.jsxs)(x,{children:[(0,V.jsxs)(o,{className:`font-bold text-xl`,children:[(0,V.jsx)(_,{colSpan:6,className:`text-center border-x`,children:`List of Assets and Costs`}),(0,V.jsx)(_,{colSpan:5,className:`text-center border-x`,children:`Depreciation`}),(0,V.jsx)(_,{className:`text-center border-x`,children:`Remaining`})]}),(0,V.jsxs)(o,{className:`border-b border-black`,children:[(0,V.jsx)(_,{className:`whitespace-normal`,children:`Assets List and Descriptions`}),(0,V.jsx)(_,{className:`whitespace-normal`,children:`Date of Purchase`}),(0,V.jsx)(_,{className:`whitespace-normal`,children:`Activation Date`}),(0,V.jsx)(_,{className:`whitespace-normal`,children:`Original Cost`}),(0,V.jsx)(_,{className:`whitespace-normal`,children:`Changes During the Year`}),(0,V.jsx)(_,{className:`whitespace-normal`,children:`Total Depreciable Assets`}),(0,V.jsx)(_,{className:`whitespace-normal`,children:`Statutory Depreciation Rate`}),(0,V.jsx)(_,{className:`whitespace-normal`,children:`Claimed Depreciation Rate`}),(0,V.jsx)(_,{className:`whitespace-normal`,children:`Depreciation Claimed This Year`}),(0,V.jsx)(_,{className:`whitespace-normal`,children:`Previous Tax Years Accumulated Depreciation`}),(0,V.jsx)(_,{className:`whitespace-normal`,children:`Total Depreciation`}),(0,V.jsx)(_,{className:`whitespace-normal`,children:`Net Book Value`})]})]}),(0,V.jsx)(y,{children:d?.depreciationReport&&(0,V.jsxs)(V.Fragment,{children:[d.depreciationReport.categories.map((e,t)=>(0,V.jsxs)(B.Fragment,{children:[(0,V.jsxs)(o,{className:`font-bold`,children:[(0,V.jsx)(s,{children:`Category ${t+1}`}),(0,V.jsx)(s,{colSpan:2,children:e.category.name}),(0,V.jsx)(s,{colSpan:3}),(0,V.jsxs)(s,{children:[b(e.category.percentage,0),`%`]}),(0,V.jsx)(s,{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:d.depreciationReport.summary})]})})]})})};export{q as DepreciationReport};