mirror of
https://github.com/frappe/books.git
synced 2024-11-13 00:46:28 +00:00
42 lines
892 B
JavaScript
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
|
|
}
|