refactoring: APAing summary.

This commit is contained in:
elforjani3
2021-02-22 12:18:07 +02:00
parent 1e3b8df702
commit a752af47d6
16 changed files with 343 additions and 217 deletions

View File

@@ -137,6 +137,41 @@ export const ARAgingSummaryTableRowsMapper = (sheet, total) => {
];
};
export const APAgingSummaryTableRowsMapper = (sheet, total) => {
const rows = [];
const mapAging = (agingPeriods) => {
return agingPeriods.reduce((acc, aging, index) => {
acc[`aging-${index}`] = aging.total.formatted_amount;
return acc;
}, {});
};
sheet.vendors.forEach((vendor) => {
const agingRow = mapAging(vendor.aging);
rows.push({
rowType: 'vendor',
name: vendor.vendor_name,
...agingRow,
current: vendor.current.formatted_amount,
total: vendor.total.formatted_amount,
});
});
if (rows.length <= 0) {
return [];
}
return [
...rows,
{
name: '',
rowType: 'total',
current: sheet.total.current.formatted_amount,
...mapAging(sheet.total.aging),
total: sheet.total.total.formatted_amount,
},
];
};
export const mapTrialBalanceSheetToRows = (sheet) => {
const results = [];

View File

@@ -197,7 +197,7 @@ export default createReducer(initialState, {
columns,
vendors,
total,
// tableRows: APAgingSummaryTableRowsMapper({ vendors, columns, total }),
tableRows: APAgingSummaryTableRowsMapper({ vendors, columns, total }),
};
state.payableAgingSummary.sheet = receivableSheet;
},