2
0
mirror of https://github.com/frappe/books.git synced 2025-01-25 16:18:33 +00:00
books/reports/GeneralLedger/GeneralLedger.js

97 lines
2.3 KiB
JavaScript
Raw Normal View History

import frappe from 'frappe';
2018-03-26 17:44:27 +05:30
2018-03-27 19:22:59 +05:30
class GeneralLedger {
2018-07-14 19:58:41 +05:30
async run(params) {
const filters = {};
if (params.account) filters.account = params.account;
if (params.party) filters.party = params.party;
if (params.referenceType !== 'All')
filters.referenceType = params.referenceType;
2018-07-14 19:58:41 +05:30
if (params.referenceName) filters.referenceName = params.referenceName;
if (params.toDate || params.fromDate) {
filters.date = [];
if (params.toDate) filters.date.push('<=', params.toDate);
if (params.fromDate) filters.date.push('>=', params.fromDate);
}
let data = (
await frappe.db.getAll({
doctype: 'AccountingLedgerEntry',
fields: [
'date',
'account',
'party',
'referenceType',
'referenceName',
'debit',
'credit',
'reverted',
],
filters: filters,
})
)
.filter((d) => !d.reverted || (d.reverted && params.reverted))
.map((row) => {
row.debit = row.debit.float;
row.credit = row.credit.float;
return row;
});
2018-03-26 17:44:27 +05:30
2019-07-18 12:19:12 +05:30
return this.appendOpeningEntry(data);
}
appendOpeningEntry(data) {
let glEntries = [];
let balance = 0,
debitTotal = 0,
creditTotal = 0;
glEntries.push({
date: '',
account: { template: '<b>Opening</b>' },
2019-07-18 12:19:12 +05:30
party: '',
debit: 0,
credit: 0,
balance: 0,
referenceType: '',
referenceName: '',
2019-07-18 12:19:12 +05:30
});
for (let entry of data) {
balance += entry.debit > 0 ? entry.debit : -entry.credit;
debitTotal += entry.debit;
creditTotal += entry.credit;
entry.balance = balance;
if (entry.debit === 0) {
entry.debit = '';
}
if (entry.credit === 0) {
entry.credit = '';
}
2019-07-18 12:19:12 +05:30
glEntries.push(entry);
}
glEntries.push({
date: '',
account: { template: '<b>Total</b>' },
2019-07-18 12:19:12 +05:30
party: '',
debit: debitTotal,
credit: creditTotal,
balance: balance,
referenceType: '',
referenceName: '',
2019-07-18 12:19:12 +05:30
});
glEntries.push({
date: '',
account: { template: '<b>Closing</b>' },
2019-07-18 12:19:12 +05:30
party: '',
debit: debitTotal,
credit: creditTotal,
balance: balance,
referenceType: '',
referenceName: '',
2019-07-18 12:19:12 +05:30
});
return glEntries;
2018-07-14 19:58:41 +05:30
}
2018-04-18 14:32:05 +05:30
}
export default GeneralLedger;