fix: AR/AP aging summary report.

This commit is contained in:
a.bouhuolia
2021-01-14 13:16:32 +02:00
parent 343185b8bd
commit a747750d88
13 changed files with 287 additions and 154 deletions

View File

@@ -7,6 +7,7 @@ import {
ISaleInvoice,
IARAgingSummaryData,
IARAgingSummaryColumns,
IARAgingSummaryTotal,
} from 'interfaces';
import AgingSummaryReport from './AgingSummary';
import { Dictionary } from 'tsyringe/dist/typings/types';
@@ -44,8 +45,14 @@ export default class ARAgingSummarySheet extends AgingSummaryReport {
this.baseCurrency = baseCurrency;
this.numberFormat = this.query.numberFormat;
this.overdueInvoicesByContactId = groupBy(overdueSaleInvoices, 'customerId');
this.currentInvoicesByContactId = groupBy(currentSaleInvoices, 'customerId');
this.overdueInvoicesByContactId = groupBy(
overdueSaleInvoices,
'customerId'
);
this.currentInvoicesByContactId = groupBy(
currentSaleInvoices,
'customerId'
);
// Initializes the aging periods.
this.agingPeriods = this.agingRangePeriods(
@@ -84,27 +91,41 @@ export default class ARAgingSummarySheet extends AgingSummaryReport {
.map((customer) => this.customerData(customer))
.filter(
(customer: IARAgingSummaryCustomer) =>
!(customer.total.total === 0 && this.query.noneZero)
!(customer.total.amount === 0 && this.query.noneZero)
);
}
/**
* Retrieve the customers aging and current total.
* @param {IARAgingSummaryCustomer} customersAgingPeriods
*/
private getCustomersTotal(
customersAgingPeriods: IARAgingSummaryCustomer[]
): IARAgingSummaryTotal {
const totalAgingPeriods = this.getTotalAgingPeriods(customersAgingPeriods);
const totalCurrent = this.getTotalCurrent(customersAgingPeriods);
const totalCustomersTotal = this.getTotalContactsTotals(
customersAgingPeriods
);
return {
current: this.formatTotalAmount(totalCurrent),
aging: totalAgingPeriods,
total: this.formatTotalAmount(totalCustomersTotal),
};
}
/**
* Retrieve A/R aging summary report data.
* @return {IARAgingSummaryData}
*/
public reportData(): IARAgingSummaryData {
const customersAgingPeriods = this.customersWalker(this.contacts);
const totalAgingPeriods = this.getTotalAgingPeriods(customersAgingPeriods);
const totalCurrent = this.getTotalCurrent(customersAgingPeriods);
const totalCustomersTotal = this.getTotalContactsTotals(customersAgingPeriods);
const customersTotal = this.getCustomersTotal(customersAgingPeriods);
return {
customers: customersAgingPeriods,
total: {
current: this.formatTotalAmount(totalCurrent),
aging: totalAgingPeriods,
total: this.formatTotalAmount(totalCustomersTotal),
}
total: customersTotal,
};
}