@accounter/client
Version:
Accounter client application
1 lines • 6.86 kB
JavaScript
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,Qn as i,Yo as a}from"./error-handling-C2WP9OW-.js";import{n as o,o as s}from"./routes-BB3QY9SQ.js";import{c,d as l,l as u,m as d}from"./select--D-3UcF0.js";import{Zn as f,et as p,ht as m,kt as h,ot as g}from"./common-Ba8DOj18.js";import{c as _}from"./separator-YxKc_C_z.js";import{t as v}from"./funnel-CpkhRhGY.js";import{t as y}from"./button-DUNsVBiu.js";import{$c as b,Gc as x,Hc as S,Kc as C,Ul as w,Vc as T,Wc as E,Xc as D,Zc as O,a as k,i as A,jl as j,n as M,o as N,qc as P,r as F,t as I,tl as L}from"./table-M99ToVB3.js";import{t as R}from"./use-url-query-BH1w9BvL.js";import{t as z}from"./page-layout-CbMLHRAP.js";var B=e(n(),1),V=t(),H=({record:e})=>{let t=O(i,e);return(0,V.jsxs)(N,{children:[(0,V.jsx)(F,{children:e.description}),(0,V.jsx)(F,{children:w(new Date(e.purchaseDate),`dd/MM/yyyy`)}),(0,V.jsx)(F,{children:e.activationDate?w(new Date(e.activationDate),`dd/MM/yyyy`):void 0}),(0,V.jsx)(F,{children:t.originalCost?f(t.originalCost,0):void 0}),(0,V.jsx)(F,{children:t.reportYearDelta?f(t.reportYearDelta,0):void 0}),(0,V.jsx)(F,{children:f(t.totalDepreciableCosts,0)}),(0,V.jsxs)(F,{children:[f(e.statutoryDepreciationRate,0),`%`]}),(0,V.jsx)(F,{children:e.claimedDepreciationRate?`${f(e.claimedDepreciationRate,1)}%`:`-`}),(0,V.jsx)(F,{children:t.reportYearClaimedDepreciation?f(t.reportYearClaimedDepreciation,0):`-`}),(0,V.jsx)(F,{children:t.pastYearsAccumulatedDepreciation?f(t.pastYearsAccumulatedDepreciation,0):`-`}),(0,V.jsx)(F,{children:t.totalDepreciation?f(t.totalDepreciation,0):`-`}),(0,V.jsx)(F,{children:t.netValue?f(t.netValue,0):`-`})]})},U=e(j(),1);function W({filter:e,setFilter:t,close:n}){let r=D({defaultValues:{...e}}),{control:i,handleSubmit:a}=r,{selectableFinancialEntities:o,fetching:s}=m(),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)(E,{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)(C,{children:`Year`}),(0,V.jsx)(S,{children:(0,V.jsx)(p,{...e,hideControls:!0,decimalScale:0})}),(0,V.jsx)(P,{})]})}),(0,V.jsx)(E,{name:`financialEntityId`,defaultValue:e?.financialEntityId,control:i,render:({field:e})=>(0,V.jsxs)(x,{children:[(0,V.jsx)(C,{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)(P,{})]})}),(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=O(i,e);return(0,V.jsxs)(N,{className:`font-bold border-b border-black`,children:[(0,V.jsx)(F,{children:t?`Group Total`:`Overall Total`}),(0,V.jsx)(F,{colSpan:2,children:t}),(0,V.jsx)(F,{children:n.originalCost?f(n.originalCost,0):void 0}),(0,V.jsx)(F,{children:n.reportYearDelta?f(n.reportYearDelta,0):void 0}),(0,V.jsx)(F,{children:n.totalDepreciableCosts?f(n.totalDepreciableCosts,0):void 0}),(0,V.jsx)(F,{}),(0,V.jsx)(F,{}),(0,V.jsx)(F,{children:n.reportYearClaimedDepreciation?f(n.reportYearClaimedDepreciation,0):void 0}),(0,V.jsx)(F,{children:n.pastYearsAccumulatedDepreciation?f(n.pastYearsAccumulatedDepreciation,0):void 0}),(0,V.jsx)(F,{children:n.totalDepreciation?f(n.totalDepreciation,0):void 0}),(0,V.jsx)(F,{children:n.netValue?f(n.netValue,0):void 0})]})},q=()=>{let{setFiltersContext:e}=(0,B.useContext)(_),{userContext:t}=(0,B.useContext)(b),{get:n}=R(),i=(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]),[o,c]=(0,B.useState)(i),[{data:l,fetching:u}]=a({query:r,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:c})}))},[o,e,c]);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)(h,{filename:`depreciation_report_${o.year??``}`}),children:u?(0,V.jsx)(L,{}):(0,V.jsxs)(I,{children:[(0,V.jsxs)(k,{children:[(0,V.jsxs)(N,{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)(N,{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:l?.depreciationReport&&(0,V.jsxs)(V.Fragment,{children:[l.depreciationReport.categories.map((e,t)=>(0,V.jsxs)(B.Fragment,{children:[(0,V.jsxs)(N,{className:`font-bold`,children:[(0,V.jsx)(F,{children:`Category ${t+1}`}),(0,V.jsx)(F,{colSpan:2,children:e.category.name}),(0,V.jsx)(F,{colSpan:3}),(0,V.jsxs)(F,{children:[f(e.category.percentage,0),`%`]}),(0,V.jsx)(F,{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};