2
0
mirror of https://github.com/frappe/books.git synced 2024-11-10 15:50:56 +00:00
books/reports/TrialBalance/TrialBalance.js

26 lines
670 B
JavaScript
Raw Normal View History

2018-04-27 11:33:36 +00:00
const frappe = require('frappejs');
const {
getTrialBalance
} = require('../FinancialStatements/FinancialStatements');
2018-04-27 11:33:36 +00:00
module.exports = class TrialBalance {
async run({ fromDate, toDate }) {
2019-08-14 07:43:49 +00:00
if (!fromDate && !toDate) {
return { rows: [] };
}
const promises = ['Asset', 'Expense', 'Income', 'Liability', 'Equity'].map(
rootType => {
return getTrialBalance({ rootType, fromDate, toDate });
}
);
2018-04-27 11:33:36 +00:00
const values = await Promise.all(promises);
let rows = values.reduce((acc, curr) => {
return [...acc, ...curr];
}, []);
2018-04-27 11:33:36 +00:00
rows = rows.filter(r => r.debit !== 0 || r.credit !== 0);
return { rows };
}
};