From 81670fd017f021cdbbecb19f0fd8497f3db8aace Mon Sep 17 00:00:00 2001 From: Vit Horacek Date: Thu, 17 Aug 2023 15:24:59 +0100 Subject: [PATCH 1/2] Fix the negative amounts showing --- src/libs/TransactionUtils.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/libs/TransactionUtils.js b/src/libs/TransactionUtils.js index a8fd828d07d4..6e0932c5ec28 100644 --- a/src/libs/TransactionUtils.js +++ b/src/libs/TransactionUtils.js @@ -120,13 +120,23 @@ function getDescription(transaction) { * @returns {Number} */ function getAmount(transaction, isFromExpenseReport) { - // In case of expense reports, the amounts are stored using an opposite sign - const multiplier = isFromExpenseReport ? -1 : 1; + // IOU requests cannot have negative values but they can be stored as negative values, let's return absolute value + if (!isFromExpenseReport) { + const amount = lodashGet(transaction, 'modifiedAmount', 0); + if (amount) { + return Math.abs(amount); + } + return Math.abs(lodashGet(transaction, 'amount', 0)); + } + + // Expense report case: + // The amounts are stored using an opposite sign and negative values can be set, + // we need to return an opposite sign than is saved in the transaction object const amount = lodashGet(transaction, 'modifiedAmount', 0); if (amount) { - return multiplier * amount; + return -amount; } - return multiplier * lodashGet(transaction, 'amount', 0); + return -lodashGet(transaction, 'amount', 0); } /** From 0acfcb72b5805c8ae4bf3596e58b6dbbafcd7a6e Mon Sep 17 00:00:00 2001 From: Vit Horacek Date: Thu, 17 Aug 2023 15:58:46 +0100 Subject: [PATCH 2/2] Avoid -0 notation --- src/libs/TransactionUtils.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/libs/TransactionUtils.js b/src/libs/TransactionUtils.js index 6e0932c5ec28..06ad190048c3 100644 --- a/src/libs/TransactionUtils.js +++ b/src/libs/TransactionUtils.js @@ -132,11 +132,14 @@ function getAmount(transaction, isFromExpenseReport) { // Expense report case: // The amounts are stored using an opposite sign and negative values can be set, // we need to return an opposite sign than is saved in the transaction object - const amount = lodashGet(transaction, 'modifiedAmount', 0); + let amount = lodashGet(transaction, 'modifiedAmount', 0); if (amount) { return -amount; } - return -lodashGet(transaction, 'amount', 0); + + // To avoid -0 being shown, lets only change the sign if the value is other than 0. + amount = lodashGet(transaction, 'amount', 0); + return amount ? -amount : 0; } /**