mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 21:30:31 +00:00
draft: AR and AP aging summary report.
This commit is contained in:
@@ -1,12 +1,97 @@
|
||||
import FinancialSheet from "../FinancialSheet";
|
||||
import { groupBy, sumBy } from 'lodash';
|
||||
import AgingSummaryReport from './AgingSummary';
|
||||
import {
|
||||
IAPAgingSummaryQuery,
|
||||
IAgingPeriod,
|
||||
IBill,
|
||||
IVendor,
|
||||
IAPAgingSummaryData,
|
||||
IAPAgingSummaryVendor,
|
||||
IAPAgingSummaryColumns
|
||||
} from 'interfaces';
|
||||
import { Dictionary } from 'tsyringe/dist/typings/types';
|
||||
export default class APAgingSummarySheet extends AgingSummaryReport {
|
||||
readonly tenantId: number;
|
||||
readonly query: IAPAgingSummaryQuery;
|
||||
readonly contacts: IVendor[];
|
||||
readonly unpaidBills: IBill[];
|
||||
readonly baseCurrency: string;
|
||||
|
||||
readonly unpaidInvoicesByContactId: Dictionary<IBill[]>;
|
||||
readonly agingPeriods: IAgingPeriod[];
|
||||
|
||||
constructor(
|
||||
tenantId: number,
|
||||
query: IAPAgingSummaryQuery,
|
||||
vendors: IVendor[],
|
||||
unpaidBills: IBill[],
|
||||
baseCurrency: string
|
||||
) {
|
||||
super();
|
||||
|
||||
export default class APAgingSummarySheet extends FinancialSheet {
|
||||
this.tenantId = tenantId;
|
||||
this.query = query;
|
||||
this.numberFormat = this.query.numberFormat;
|
||||
this.contacts = vendors;
|
||||
this.unpaidBills = unpaidBills;
|
||||
this.baseCurrency = baseCurrency;
|
||||
|
||||
|
||||
this.unpaidInvoicesByContactId = groupBy(unpaidBills, 'vendorId');
|
||||
|
||||
reportData() {
|
||||
// Initializes the aging periods.
|
||||
this.agingPeriods = this.agingRangePeriods(
|
||||
this.query.asDate,
|
||||
this.query.agingDaysBefore,
|
||||
this.query.agingPeriods
|
||||
);
|
||||
this.initContactsAgingPeriods();
|
||||
this.calcUnpaidInvoicesAgingPeriods();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the vendor section data.
|
||||
* @param {IVendor} vendor
|
||||
* @return {IAPAgingSummaryData}
|
||||
*/
|
||||
protected vendorData(vendor: IVendor): IAPAgingSummaryVendor {
|
||||
const agingPeriods = this.getContactAgingPeriods(vendor.id);
|
||||
const amount = sumBy(agingPeriods, 'total');
|
||||
|
||||
return {
|
||||
vendorName: vendor.displayName,
|
||||
aging: agingPeriods,
|
||||
total: this.formatTotalAmount(amount),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve vendors aging periods.
|
||||
* @return {IAPAgingSummaryVendor[]}
|
||||
*/
|
||||
private vendorsWalker(): IAPAgingSummaryVendor[] {
|
||||
return this.contacts
|
||||
.map((vendor) => this.vendorData(vendor))
|
||||
.filter(
|
||||
(vendor: IAPAgingSummaryVendor) =>
|
||||
!(vendor.total.total === 0 && this.query.noneZero)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the A/P aging summary report data.
|
||||
* @return {IAPAgingSummaryData}
|
||||
*/
|
||||
public reportData(): IAPAgingSummaryData {
|
||||
return {
|
||||
vendors: this.vendorsWalker(),
|
||||
total: this.getTotalAgingPeriods(),
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the A/P aging summary report columns.
|
||||
*/
|
||||
reportColumns(): IAPAgingSummaryColumns {
|
||||
return this.agingPeriods;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user