From 3dda25f9cff031c4db6102a62a986842c990f778 Mon Sep 17 00:00:00 2001 From: Jonathan Niles Date: Wed, 21 Mar 2018 12:53:31 +0100 Subject: [PATCH] fix(reports): incorrect footer account statement This commit fixes a bug in the summing of debits/credits on the Account Statement report. Closes #2609. --- .../finance/reports/account_statement/index.js | 10 +++++----- .../finance/reports/reportAccounts/index.js | 5 ++--- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/server/controllers/finance/reports/account_statement/index.js b/server/controllers/finance/reports/account_statement/index.js index 476e78622f..9625643bf3 100644 --- a/server/controllers/finance/reports/account_statement/index.js +++ b/server/controllers/finance/reports/account_statement/index.js @@ -39,7 +39,7 @@ function report(req, res, next) { } catch (e) { return next(e); } - // converting uuids in binary + // converting uuids in binary db.convert(options, ['uuids']); return generalLedger.find(options) @@ -48,9 +48,9 @@ function report(req, res, next) { glb.rows = rows; const aggregateSql = ` - SELECT SUM(debit_equiv) AS debit_equiv, SUM(credit_equiv) AS credit_equiv, - SUM(debit_equiv - credit_equiv) AS balance - FROM general_ledger + SELECT SUM(debit_equiv) AS debit_equiv, SUM(credit_equiv) AS credit_equiv, + SUM(debit_equiv - credit_equiv) AS balance + FROM general_ledger WHERE uuid IN (?); `; const transactionIds = rows.map(row => { @@ -71,4 +71,4 @@ function report(req, res, next) { }) .catch(next) .done(); -} \ No newline at end of file +} diff --git a/server/controllers/finance/reports/reportAccounts/index.js b/server/controllers/finance/reports/reportAccounts/index.js index 4ea56b37a3..3b4d612454 100644 --- a/server/controllers/finance/reports/reportAccounts/index.js +++ b/server/controllers/finance/reports/reportAccounts/index.js @@ -176,7 +176,8 @@ function getTotalsSQL(options) { SELECT IFNULL(GetExchangeRate(${options.enterprise_id}, ${currencyId}, NOW()), 1) AS rate, ${currencyId} AS currency_id, - SUM(ROUND(debit_equiv, 2)) AS debit, SUM(ROUND(credit_equiv, 2)) AS credit, + SUM(ROUND(debit, 2)) AS debit, SUM(ROUND(credit, 2)) AS credit, + SUM(ROUND(debit_equiv, 2)) AS debit_equiv, SUM(ROUND(credit_equiv, 2)) AS credit_equiv, (SUM(ROUND(debit_equiv, 2)) - SUM(ROUND(credit_equiv, 2))) AS balance FROM general_ledger `; @@ -242,8 +243,6 @@ function getAccountTransactions(options, openingBalance = 0) { // contains the grid totals for the footer const footer = { date : lastDate, - exchangedDebit : totals.debit * totals.rate, - exchangedCredit : totals.credit * totals.rate, exchangedBalance : totals.balance * totals.rate, exchangedCumSum : lastCumSum, exchangedDate : new Date(),