From 5df04af570e72b23dd930f1b1270b5111069b7dd Mon Sep 17 00:00:00 2001 From: Suraj Shetty Date: Sat, 14 Jul 2018 19:58:41 +0530 Subject: [PATCH] Fix date filter in general ledger --- reports/GeneralLedger/GeneralLedger.js | 35 ++++++++++++++------------ 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/reports/GeneralLedger/GeneralLedger.js b/reports/GeneralLedger/GeneralLedger.js index f433615e..722d7045 100644 --- a/reports/GeneralLedger/GeneralLedger.js +++ b/reports/GeneralLedger/GeneralLedger.js @@ -1,23 +1,26 @@ const frappe = require('frappejs'); class GeneralLedger { - async run(params) { - const filters = {}; - if (params.account) filters.account = params.account; - if (params.party) filters.party = params.party; - if (params.referenceType) filters.referenceType = params.referenceType; - if (params.referenceName) filters.referenceName = params.referenceName; - if (params.fromDate) filters.date = ['>=', params.fromDate]; - if (params.toDate) filters.date = ['<=', params.toDate]; - - let data = await frappe.db.getAll({ - doctype: 'AccountingLedgerEntry', - fields: ['date', 'account', 'party', 'referenceType', 'referenceName', 'debit', 'credit'], - filters: filters - }); - - return data; + async run(params) { + const filters = {}; + if (params.account) filters.account = params.account; + if (params.party) filters.party = params.party; + if (params.referenceType) filters.referenceType = params.referenceType; + 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'], + filters: filters + }); + + return data; + } } module.exports = GeneralLedger;