From 1edfd7be0d4435ade6dff559ec4cb300262de583 Mon Sep 17 00:00:00 2001 From: Chris Lomame Date: Tue, 30 Jul 2019 15:38:10 +0100 Subject: [PATCH] fix (Invoicing Bug) - resolution of the problem when calling the Debtors.balance function with rounding to two ranks after the decimal point of the total credit and debit values closes #3822 --- server/controllers/finance/debtors/index.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/server/controllers/finance/debtors/index.js b/server/controllers/finance/debtors/index.js index f83acdb2ee..2df550322e 100644 --- a/server/controllers/finance/debtors/index.js +++ b/server/controllers/finance/debtors/index.js @@ -261,9 +261,15 @@ function balance(debtorUuid, excludeCautionLinks = false) { const excludeCautionLinkStatement = `AND transaction_type_id <> ${CAUTION_LINK_TYPE_ID}`; + /** + * resolution of the problem when calling the Debtors.balance function with + * rounding to two ranks after the decimal point of the total credit and + * debit values + * + */ const sql = ` - SELECT IFNULL(SUM(ledger.debit_equiv), 0) AS debit, IFNULL(SUM(ledger.credit_equiv), 0) AS credit, - IFNULL(SUM(ledger.debit_equiv - ledger.credit_equiv), 0) AS balance, MIN(trans_date) AS since, + SELECT ROUND(IFNULL(SUM(ledger.debit_equiv), 0), 2) AS debit, ROUND(IFNULL(SUM(ledger.credit_equiv), 0),2) AS credit, + ROUND(IFNULL(SUM(ledger.debit_equiv - ledger.credit_equiv), 0),2) AS balance, MIN(trans_date) AS since, MAX(trans_date) AS until FROM ( SELECT debit_equiv, credit_equiv, entity_uuid, trans_date FROM posting_journal