2
0
mirror of https://github.com/frappe/books.git synced 2024-11-13 00:46:28 +00:00
books/reports/financialStatements.js
Faris Ansari 1c1f72281e wip
2018-04-18 14:32:05 +05:30

42 lines
892 B
JavaScript

const frappe = require('frappejs');
async function getData({ rootType, balanceMustBe }) {
const accounts = await getAccounts(rootType);
if (!accounts || accounts.length === 0) return [];
const ledgerEntries = await frappe.db.getAll({
doctype: 'AccountingLedgerEntry',
fields: ['account', 'debit', 'credit'],
filters: {
account: ['in', accounts]
}
});
let data = {};
for (let entry of ledgerEntries) {
if (!data[entry.account]) {
data[entry.account] = 0.0;
}
data[entry.account] += entry.debit - entry.credit;
}
return data;
}
async function getAccounts(rootType) {
return (await frappe.db.getAll({
doctype: 'Account',
fields: ['name'],
filters: {
rootType
}
}))
.map(d => d.name);
}
module.exports = {
getData
}