From 69ac6d276c2ffca9ad28f82bb188873f69f1fcbc Mon Sep 17 00:00:00 2001 From: dominictb Date: Wed, 26 Jun 2024 17:03:32 +0700 Subject: [PATCH] fix: negate amount for expense report in ReportUtils.getNonHeldAndFullAmount Signed-off-by: dominictb --- src/libs/ReportUtils.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 7a3b2d1d0869..71ed75a6457d 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -6592,15 +6592,18 @@ function getNonHeldAndFullAmount(iouReport: OnyxEntry, policy: OnyxEntry const transactions = TransactionUtils.getAllReportTransactions(iouReport?.reportID ?? '-1'); const hasPendingTransaction = transactions.some((transaction) => !!transaction.pendingAction); + // if the report is an expense report, the total amount should be negated + const coefficient = isExpenseReport(iouReport) ? -1 : 1; + if (hasUpdatedTotal(iouReport, policy) && hasPendingTransaction) { const unheldTotal = transactions.reduce((currentVal, transaction) => currentVal - (!TransactionUtils.isOnHold(transaction) ? transaction.amount : 0), 0); - return [CurrencyUtils.convertToDisplayString(unheldTotal, iouReport?.currency), CurrencyUtils.convertToDisplayString((iouReport?.total ?? 0) * -1, iouReport?.currency)]; + return [CurrencyUtils.convertToDisplayString(unheldTotal, iouReport?.currency), CurrencyUtils.convertToDisplayString((iouReport?.total ?? 0) * coefficient, iouReport?.currency)]; } return [ - CurrencyUtils.convertToDisplayString((iouReport?.unheldTotal ?? 0) * -1, iouReport?.currency), - CurrencyUtils.convertToDisplayString((iouReport?.total ?? 0) * -1, iouReport?.currency), + CurrencyUtils.convertToDisplayString((iouReport?.unheldTotal ?? 0) * coefficient, iouReport?.currency), + CurrencyUtils.convertToDisplayString((iouReport?.total ?? 0) * coefficient, iouReport?.currency), ]; }