From 801ea5dfdbc580317f7e002d942c93db13f72cb4 Mon Sep 17 00:00:00 2001 From: Ahmed Bouhuolia Date: Sat, 2 Sep 2023 01:50:24 +0200 Subject: [PATCH] feat: wip sales tax summary report --- .../SalesTaxLiabilitySummary/index.ts | 4 ---- .../interfaces/SalesTaxLiabilitySummary.ts | 4 +++- .../SalesTaxLiabilitySummary.ts | 14 ++++++++++-- .../SalesTaxLiabilitySummaryTable.ts | 22 ++++++++++++------- 4 files changed, 29 insertions(+), 15 deletions(-) diff --git a/packages/server/src/api/controllers/FinancialStatements/SalesTaxLiabilitySummary/index.ts b/packages/server/src/api/controllers/FinancialStatements/SalesTaxLiabilitySummary/index.ts index a9399c1dd..42e2c5ecc 100644 --- a/packages/server/src/api/controllers/FinancialStatements/SalesTaxLiabilitySummary/index.ts +++ b/packages/server/src/api/controllers/FinancialStatements/SalesTaxLiabilitySummary/index.ts @@ -5,13 +5,9 @@ import asyncMiddleware from '@/api/middleware/asyncMiddleware'; import BaseFinancialReportController from '../BaseFinancialReportController'; import { AbilitySubject, ReportsAction } from '@/interfaces'; import CheckPolicies from '@/api/middleware/CheckPolicies'; -import HasTenancyService from '@/services/Tenancy/TenancyService'; import { SalesTaxLiabilitySummaryService } from '@/services/FinancialStatements/SalesTaxLiabilitySummary/SalesTaxLiabilitySummaryService'; export default class SalesTaxLiabilitySummary extends BaseFinancialReportController { - @Inject() - private tenancy: HasTenancyService; - @Inject() private salesTaxLiabilitySummaryService: SalesTaxLiabilitySummaryService; diff --git a/packages/server/src/interfaces/SalesTaxLiabilitySummary.ts b/packages/server/src/interfaces/SalesTaxLiabilitySummary.ts index 301cdd76c..1a036ce1c 100644 --- a/packages/server/src/interfaces/SalesTaxLiabilitySummary.ts +++ b/packages/server/src/interfaces/SalesTaxLiabilitySummary.ts @@ -13,13 +13,15 @@ export interface SalesTaxLiabilitySummaryAmount { export interface SalesTaxLiabilitySummaryTotal { taxableAmount: SalesTaxLiabilitySummaryAmount; taxAmount: SalesTaxLiabilitySummaryAmount; + collectedTaxAmount: SalesTaxLiabilitySummaryAmount; } export interface SalesTaxLiabilitySummaryRate { taxName: string; - taxCode: string; taxableAmount: SalesTaxLiabilitySummaryAmount; taxAmount: SalesTaxLiabilitySummaryAmount; + taxPercentage: any; + collectedTaxAmount: SalesTaxLiabilitySummaryAmount; } export enum SalesTaxLiabilitySummaryTableRowType { diff --git a/packages/server/src/services/FinancialStatements/SalesTaxLiabilitySummary/SalesTaxLiabilitySummary.ts b/packages/server/src/services/FinancialStatements/SalesTaxLiabilitySummary/SalesTaxLiabilitySummary.ts index 3c658dd8a..9a84849a2 100644 --- a/packages/server/src/services/FinancialStatements/SalesTaxLiabilitySummary/SalesTaxLiabilitySummary.ts +++ b/packages/server/src/services/FinancialStatements/SalesTaxLiabilitySummary/SalesTaxLiabilitySummary.ts @@ -53,11 +53,19 @@ export class SalesTaxLiabilitySummary extends FinancialSheet { : 0; const salesTaxAmount = salesTax ? salesTax.credit - salesTax.debit : 0; + // Calculates the tax percentage. + const taxPercentage = salesTaxAmount / payableTaxAmount; + const taxPercentageRate = taxPercentage / 100; + + // Calculates the payable tax amount. + const collectedTaxAmount = payableTax ? payableTax.debit : 0; + return { - taxName: taxRate.name, - taxCode: taxRate.code, + taxName: `${taxRate.name} (${taxRate.rate}%)`, taxableAmount: this.getAmountMeta(salesTaxAmount), taxAmount: this.getAmountMeta(payableTaxAmount), + taxPercentage: this.getPercentageAmountMeta(taxPercentageRate), + collectedTaxAmount: this.getAmountMeta(collectedTaxAmount), }; }; @@ -79,10 +87,12 @@ export class SalesTaxLiabilitySummary extends FinancialSheet { ): SalesTaxLiabilitySummaryTotal => { const taxableAmount = sumBy(nodes, 'taxableAmount.amount'); const taxAmount = sumBy(nodes, 'taxAmount.amount'); + const collectedTaxAmount = sumBy(nodes, 'collectedTaxAmount.amount'); return { taxableAmount: this.getTotalAmountMeta(taxableAmount), taxAmount: this.getTotalAmountMeta(taxAmount), + collectedTaxAmount: this.getTotalAmountMeta(collectedTaxAmount), }; }; diff --git a/packages/server/src/services/FinancialStatements/SalesTaxLiabilitySummary/SalesTaxLiabilitySummaryTable.ts b/packages/server/src/services/FinancialStatements/SalesTaxLiabilitySummary/SalesTaxLiabilitySummaryTable.ts index 204675ce3..7da959a9a 100644 --- a/packages/server/src/services/FinancialStatements/SalesTaxLiabilitySummary/SalesTaxLiabilitySummaryTable.ts +++ b/packages/server/src/services/FinancialStatements/SalesTaxLiabilitySummary/SalesTaxLiabilitySummaryTable.ts @@ -44,9 +44,10 @@ export class SalesTaxLiabilitySummaryTable extends R.compose( */ private get taxRateRowAccessor() { return [ - { key: 'taxName', value: 'taxName' }, - { key: 'taxCode', accessor: 'taxCode' }, + { key: 'taxName', accessor: 'taxName' }, + { key: 'taxPercentage', accessor: 'taxPercentage.formattedAmount' }, { key: 'taxableAmount', accessor: 'taxableAmount.formattedAmount' }, + { key: 'collectedTax', accessor: 'collectedTaxAmount.formattedAmount' }, { key: 'taxAmount', accessor: 'taxAmount.formattedAmount' }, ]; } @@ -57,9 +58,10 @@ export class SalesTaxLiabilitySummaryTable extends R.compose( */ private get taxRateTotalRowAccessors() { return [ - { key: 'taxName', value: '' }, - { key: 'taxCode', accessor: 'taxCode' }, + { key: 'taxName', value: 'Total' }, + { key: 'taxPercentage', value: '' }, { key: 'taxableAmount', accessor: 'taxableAmount.formattedAmount' }, + { key: 'collectedTax', accessor: 'collectedTaxAmount.formattedAmount' }, { key: 'taxAmount', accessor: 'taxAmount.formattedAmount' }, ]; } @@ -122,7 +124,7 @@ export class SalesTaxLiabilitySummaryTable extends R.compose( } /** - * Retrieve the table rows. + * Retrieves the table rows. * @returns {ITableRow[]} */ public tableRows(): ITableRow[] { @@ -133,7 +135,7 @@ export class SalesTaxLiabilitySummaryTable extends R.compose( } /** - * Retrieve the table columns. + * Retrieves the table columns. * @returns {ITableColumn[]} */ public tableColumns(): ITableColumn[] { @@ -143,13 +145,17 @@ export class SalesTaxLiabilitySummaryTable extends R.compose( key: 'taxName', }, { - label: 'Tax Code', - key: 'taxCode', + label: 'Tax Percentage', + key: 'taxPercentage', }, { label: 'Taxable Amount', key: 'taxableAmount', }, + { + label: 'Collected Tax', + key: 'collectedTax', + }, { label: 'Tax Rate', key: 'taxRate',