Skip to content

Commit

Permalink
Merge #3825
Browse files Browse the repository at this point in the history
3825: fix (Invoicing Bug) r=jniles a=lomamech

- 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

Co-authored-by: Chris Lomame <lomamech@gmail.com>
  • Loading branch information
bors[bot] and lomamech committed Aug 5, 2019
2 parents 7ae875f + b289a4e commit 1326302
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions server/controllers/finance/debtors/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,16 @@ 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,
MAX(trans_date) AS until
IFNULL(SUM(ledger.debit_equiv - ledger.credit_equiv), 0) 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
WHERE entity_uuid = ? ${excludeCautionLinks ? excludeCautionLinkStatement : ''}
Expand Down
2 changes: 1 addition & 1 deletion server/controllers/finance/patientInvoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ function create(req, res, next) {
// so, we will use their caution balance to link to the invoice for payment.
Debtors.balance(invoice.debtor_uuid)
.then(([pBalance]) => {
const hasCreditorBalance = hasPrepaymentSupport && pBalance && (pBalance.credit > pBalance.debit);
const hasCreditorBalance = hasPrepaymentSupport && pBalance && ((pBalance.credit - pBalance.debit) > 0.01);
const preparedTransaction = createInvoice(invoice, hasCreditorBalance, prepaymentDescription);
return preparedTransaction.execute();
})
Expand Down

0 comments on commit 1326302

Please sign in to comment.