From 8479c5030427781f55a74861841209779c598008 Mon Sep 17 00:00:00 2001 From: kubabutkiewicz Date: Mon, 20 Oct 2025 16:35:01 +0200 Subject: [PATCH 1/8] Enhance transaction report calculations to correctly adjust totals based on transaction amounts. --- src/libs/actions/Transaction.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/libs/actions/Transaction.ts b/src/libs/actions/Transaction.ts index 5af340eddf02..2405127c36ef 100644 --- a/src/libs/actions/Transaction.ts +++ b/src/libs/actions/Transaction.ts @@ -891,7 +891,11 @@ function changeTransactionsReport( const transactionAmount = getAmount(transaction, undefined, undefined, allowNegative); if (oldReport) { - updatedReportTotals[oldReportID] = (updatedReportTotals[oldReportID] ? updatedReportTotals[oldReportID] : (oldReport?.total ?? 0)) + transactionAmount; + updatedReportTotals[oldReportID] = updatedReportTotals[oldReportID] + ? updatedReportTotals[oldReportID] + : transactionAmount < 0 + ? (oldReport?.total ?? 0) - transactionAmount + : (oldReport?.total ?? 0) + transactionAmount; updatedReportNonReimbursableTotals[oldReportID] = (updatedReportNonReimbursableTotals[oldReportID] ? updatedReportNonReimbursableTotals[oldReportID] : (oldReport?.nonReimbursableTotal ?? 0)) + (transaction?.reimbursable ? 0 : transactionAmount); From 42d9d3bd744c382023af4f290d3d002f5980fb2c Mon Sep 17 00:00:00 2001 From: kubabutkiewicz Date: Thu, 23 Oct 2025 09:23:50 +0200 Subject: [PATCH 2/8] testing --- src/libs/actions/Transaction.ts | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/libs/actions/Transaction.ts b/src/libs/actions/Transaction.ts index 2405127c36ef..06b66f47ccff 100644 --- a/src/libs/actions/Transaction.ts +++ b/src/libs/actions/Transaction.ts @@ -24,6 +24,7 @@ import { buildTransactionThread, findSelfDMReportID, getReportTransactions, + getTransactionDetails, hasViolations as hasViolationsReportUtils, shouldEnableNegative, } from '@libs/ReportUtils'; @@ -889,28 +890,37 @@ function changeTransactionsReport( const isUnreported = reportID === CONST.REPORT.UNREPORTED_REPORT_ID; const targetReportID = isUnreported ? selfDMReportID : reportID; const transactionAmount = getAmount(transaction, undefined, undefined, allowNegative); + const isTransactionNegative = (getTransactionDetails(transaction, undefined, undefined, allowNegative)?.amount ?? 0) < 0; + console.log('isTransactionNegative', isTransactionNegative); + console.log('getTransactionDetails(transaction, undefined, undefined, allowNegative)', getTransactionDetails(transaction, undefined, undefined, allowNegative)); if (oldReport) { - updatedReportTotals[oldReportID] = updatedReportTotals[oldReportID] - ? updatedReportTotals[oldReportID] - : transactionAmount < 0 - ? (oldReport?.total ?? 0) - transactionAmount - : (oldReport?.total ?? 0) + transactionAmount; + console.log('oldReport', oldReport); + console.log('updatedReportTotals[oldReportID]', updatedReportTotals[oldReportID]); + updatedReportTotals[oldReportID] = updatedReportTotals[oldReportID] ? updatedReportTotals[oldReportID] : transactionAmount; + console.log('updatedReportTotals[oldReportID]', updatedReportTotals[oldReportID]); updatedReportNonReimbursableTotals[oldReportID] = (updatedReportNonReimbursableTotals[oldReportID] ? updatedReportNonReimbursableTotals[oldReportID] : (oldReport?.nonReimbursableTotal ?? 0)) + (transaction?.reimbursable ? 0 : transactionAmount); + console.log('updatedReportNonReimbursableTotals[oldReportID]', updatedReportNonReimbursableTotals[oldReportID]); updatedReportUnheldNonReimbursableTotals[oldReportID] = (updatedReportUnheldNonReimbursableTotals[oldReportID] ? updatedReportUnheldNonReimbursableTotals[oldReportID] : (oldReport?.unheldNonReimbursableTotal ?? 0)) + (transaction?.reimbursable && !isOnHold(transaction) ? 0 : transactionAmount); + console.log('updatedReportUnheldNonReimbursableTotals[oldReportID]', updatedReportUnheldNonReimbursableTotals[oldReportID]); } if (reportID && newReport) { + console.log('targetReportID', targetReportID); + console.log('updatedReportTotals[targetReportID]', updatedReportTotals[targetReportID]); updatedReportTotals[targetReportID] = (updatedReportTotals[targetReportID] ? updatedReportTotals[targetReportID] : (newReport.total ?? 0)) - transactionAmount; + console.log('updatedReportTotals[targetReportID]', updatedReportTotals[targetReportID]); updatedReportNonReimbursableTotals[targetReportID] = (updatedReportNonReimbursableTotals[targetReportID] ? updatedReportNonReimbursableTotals[targetReportID] : (newReport.nonReimbursableTotal ?? 0)) - (transactionReimbursable ? 0 : transactionAmount); + console.log('updatedReportNonReimbursableTotals[targetReportID]', updatedReportNonReimbursableTotals[targetReportID]); updatedReportUnheldNonReimbursableTotals[targetReportID] = (updatedReportUnheldNonReimbursableTotals[targetReportID] ? updatedReportUnheldNonReimbursableTotals[targetReportID] : (newReport.unheldNonReimbursableTotal ?? 0)) - (transactionReimbursable && !isOnHold(transaction) ? 0 : transactionAmount); + console.log('updatedReportUnheldNonReimbursableTotals[targetReportID]', updatedReportUnheldNonReimbursableTotals[targetReportID]); } // 4. Optimistically update the IOU action reportID From cdafd756937ef4c74b997429b50af9577ac3f570 Mon Sep 17 00:00:00 2001 From: kubabutkiewicz Date: Thu, 23 Oct 2025 12:16:05 +0200 Subject: [PATCH 3/8] fixed wrong transaction amount --- src/libs/actions/Transaction.ts | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/src/libs/actions/Transaction.ts b/src/libs/actions/Transaction.ts index 06b66f47ccff..c1c4d8820c99 100644 --- a/src/libs/actions/Transaction.ts +++ b/src/libs/actions/Transaction.ts @@ -889,38 +889,27 @@ function changeTransactionsReport( // 3. Keep track of the new report totals const isUnreported = reportID === CONST.REPORT.UNREPORTED_REPORT_ID; const targetReportID = isUnreported ? selfDMReportID : reportID; - const transactionAmount = getAmount(transaction, undefined, undefined, allowNegative); - const isTransactionNegative = (getTransactionDetails(transaction, undefined, undefined, allowNegative)?.amount ?? 0) < 0; - console.log('isTransactionNegative', isTransactionNegative); - console.log('getTransactionDetails(transaction, undefined, undefined, allowNegative)', getTransactionDetails(transaction, undefined, undefined, allowNegative)); + const transactionAmount = getTransactionDetails(transaction, undefined, undefined, allowNegative)?.amount ?? 0; if (oldReport) { - console.log('oldReport', oldReport); - console.log('updatedReportTotals[oldReportID]', updatedReportTotals[oldReportID]); updatedReportTotals[oldReportID] = updatedReportTotals[oldReportID] ? updatedReportTotals[oldReportID] : transactionAmount; - console.log('updatedReportTotals[oldReportID]', updatedReportTotals[oldReportID]); updatedReportNonReimbursableTotals[oldReportID] = (updatedReportNonReimbursableTotals[oldReportID] ? updatedReportNonReimbursableTotals[oldReportID] : (oldReport?.nonReimbursableTotal ?? 0)) + (transaction?.reimbursable ? 0 : transactionAmount); - console.log('updatedReportNonReimbursableTotals[oldReportID]', updatedReportNonReimbursableTotals[oldReportID]); updatedReportUnheldNonReimbursableTotals[oldReportID] = (updatedReportUnheldNonReimbursableTotals[oldReportID] ? updatedReportUnheldNonReimbursableTotals[oldReportID] : (oldReport?.unheldNonReimbursableTotal ?? 0)) + (transaction?.reimbursable && !isOnHold(transaction) ? 0 : transactionAmount); - console.log('updatedReportUnheldNonReimbursableTotals[oldReportID]', updatedReportUnheldNonReimbursableTotals[oldReportID]); } if (reportID && newReport) { - console.log('targetReportID', targetReportID); - console.log('updatedReportTotals[targetReportID]', updatedReportTotals[targetReportID]); updatedReportTotals[targetReportID] = (updatedReportTotals[targetReportID] ? updatedReportTotals[targetReportID] : (newReport.total ?? 0)) - transactionAmount; - console.log('updatedReportTotals[targetReportID]', updatedReportTotals[targetReportID]); + updatedReportNonReimbursableTotals[targetReportID] = (updatedReportNonReimbursableTotals[targetReportID] ? updatedReportNonReimbursableTotals[targetReportID] : (newReport.nonReimbursableTotal ?? 0)) - (transactionReimbursable ? 0 : transactionAmount); - console.log('updatedReportNonReimbursableTotals[targetReportID]', updatedReportNonReimbursableTotals[targetReportID]); + updatedReportUnheldNonReimbursableTotals[targetReportID] = (updatedReportUnheldNonReimbursableTotals[targetReportID] ? updatedReportUnheldNonReimbursableTotals[targetReportID] : (newReport.unheldNonReimbursableTotal ?? 0)) - (transactionReimbursable && !isOnHold(transaction) ? 0 : transactionAmount); - console.log('updatedReportUnheldNonReimbursableTotals[targetReportID]', updatedReportUnheldNonReimbursableTotals[targetReportID]); } // 4. Optimistically update the IOU action reportID From 4b81683910e438bd646fbabb30cf59d8c03002f8 Mon Sep 17 00:00:00 2001 From: kubabutkiewicz Date: Tue, 28 Oct 2025 15:31:11 +0100 Subject: [PATCH 4/8] lint issue --- src/pages/TeachersUnite/KnowATeacherPage.tsx | 2 +- src/pages/iou/SplitExpensePage.tsx | 14 +++++++++----- .../request/step/IOURequestEditReportCommon.tsx | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/pages/TeachersUnite/KnowATeacherPage.tsx b/src/pages/TeachersUnite/KnowATeacherPage.tsx index 349cf6f038f1..0865929d13a8 100644 --- a/src/pages/TeachersUnite/KnowATeacherPage.tsx +++ b/src/pages/TeachersUnite/KnowATeacherPage.tsx @@ -87,7 +87,7 @@ function KnowATeacherPage() { return errors; }, - [loginList, translate], + [countryCode, loginList, translate], ); return ( diff --git a/src/pages/iou/SplitExpensePage.tsx b/src/pages/iou/SplitExpensePage.tsx index a83b0214d10c..39cf0dfae872 100644 --- a/src/pages/iou/SplitExpensePage.tsx +++ b/src/pages/iou/SplitExpensePage.tsx @@ -185,7 +185,10 @@ function SplitExpensePage({route}: SplitExpensePageProps) { splitExpenses, childTransactions.length, isBetaEnabled, - draftTransaction, + draftTransaction?.errors, + draftTransaction?.reportID, + draftTransaction?.comment?.originalTransactionID, + draftTransaction?.comment?.splitExpensesTotal, sumOfSplitExpenses, transactionDetailsAmount, isPerDiem, @@ -193,18 +196,19 @@ function SplitExpensePage({route}: SplitExpensePageProps) { splitFieldDataFromChildTransactions, allTransactions, allReports, + allReportNameValuePairs, currentSearchHash, policyCategories, expenseReportPolicy, policyRecentlyUsedCategories, + iouReport, + chatReport, + iouActions, + isChatIOUReportArchived, splitFieldDataFromOriginalTransaction, translate, transactionID, transactionDetails?.currency, - isChatIOUReportArchived, - iouReport, - iouActions, - chatReport, ]); const onSplitExpenseAmountChange = useCallback( diff --git a/src/pages/iou/request/step/IOURequestEditReportCommon.tsx b/src/pages/iou/request/step/IOURequestEditReportCommon.tsx index 427d0659aeff..28fc6ea39784 100644 --- a/src/pages/iou/request/step/IOURequestEditReportCommon.tsx +++ b/src/pages/iou/request/step/IOURequestEditReportCommon.tsx @@ -207,7 +207,7 @@ function IOURequestEditReportCommon({ icon={Expensicons.Document} /> ); - }, [createReport, isEditing, isOwner, translate, policyForMovingExpenses?.name, isSelectedReportUnreported]); + }, [createReport, isEditing, isOwner, translate, policyForMovingExpenses?.name]); // eslint-disable-next-line rulesdir/no-negated-variables const shouldShowNotFoundPage = useMemo(() => { From f0bb146271c6d31690bf23c1ecfaf013ea830da4 Mon Sep 17 00:00:00 2001 From: kubabutkiewicz Date: Tue, 28 Oct 2025 15:36:46 +0100 Subject: [PATCH 5/8] lint issue --- src/libs/actions/Transaction.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/Transaction.ts b/src/libs/actions/Transaction.ts index d941d098c2d7..868328d6c04e 100644 --- a/src/libs/actions/Transaction.ts +++ b/src/libs/actions/Transaction.ts @@ -28,7 +28,7 @@ import { hasViolations as hasViolationsReportUtils, shouldEnableNegative, } from '@libs/ReportUtils'; -import {getAmount, isOnHold, waypointHasValidAddress} from '@libs/TransactionUtils'; +import {isOnHold, waypointHasValidAddress} from '@libs/TransactionUtils'; import ViolationsUtils from '@libs/Violations/ViolationsUtils'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; From 76028318555b1a472adfa8c92daf4a569d1ebd3a Mon Sep 17 00:00:00 2001 From: kubabutkiewicz Date: Fri, 31 Oct 2025 12:46:29 +0100 Subject: [PATCH 6/8] fix --- src/libs/actions/Transaction.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libs/actions/Transaction.ts b/src/libs/actions/Transaction.ts index 868328d6c04e..77cbe9bdb35e 100644 --- a/src/libs/actions/Transaction.ts +++ b/src/libs/actions/Transaction.ts @@ -890,9 +890,10 @@ function changeTransactionsReport( const isUnreported = reportID === CONST.REPORT.UNREPORTED_REPORT_ID; const targetReportID = isUnreported ? selfDMReportID : reportID; const transactionAmount = getTransactionDetails(transaction, undefined, undefined, allowNegative)?.amount ?? 0; + const isTransactionAmountNegative = transactionAmount < 0 ? (oldReport?.total ?? 0 - transactionAmount) : (oldReport?.total ?? 0 + transactionAmount); if (oldReport) { - updatedReportTotals[oldReportID] = updatedReportTotals[oldReportID] ? updatedReportTotals[oldReportID] : transactionAmount; + updatedReportTotals[oldReportID] = updatedReportTotals[oldReportID] ? updatedReportTotals[oldReportID] : isTransactionAmountNegative; updatedReportNonReimbursableTotals[oldReportID] = (updatedReportNonReimbursableTotals[oldReportID] ? updatedReportNonReimbursableTotals[oldReportID] : (oldReport?.nonReimbursableTotal ?? 0)) + (transaction?.reimbursable ? 0 : transactionAmount); From 1d4c5930aa10d31f97d60fa7105afca699bc6965 Mon Sep 17 00:00:00 2001 From: kubabutkiewicz Date: Mon, 3 Nov 2025 09:05:02 +0100 Subject: [PATCH 7/8] changed variable name --- src/libs/actions/Transaction.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/Transaction.ts b/src/libs/actions/Transaction.ts index 77cbe9bdb35e..9edf5a7e1249 100644 --- a/src/libs/actions/Transaction.ts +++ b/src/libs/actions/Transaction.ts @@ -890,10 +890,10 @@ function changeTransactionsReport( const isUnreported = reportID === CONST.REPORT.UNREPORTED_REPORT_ID; const targetReportID = isUnreported ? selfDMReportID : reportID; const transactionAmount = getTransactionDetails(transaction, undefined, undefined, allowNegative)?.amount ?? 0; - const isTransactionAmountNegative = transactionAmount < 0 ? (oldReport?.total ?? 0 - transactionAmount) : (oldReport?.total ?? 0 + transactionAmount); + const updatedReportTotal = transactionAmount < 0 ? (oldReport?.total ?? 0 - transactionAmount) : (oldReport?.total ?? 0 + transactionAmount); if (oldReport) { - updatedReportTotals[oldReportID] = updatedReportTotals[oldReportID] ? updatedReportTotals[oldReportID] : isTransactionAmountNegative; + updatedReportTotals[oldReportID] = updatedReportTotals[oldReportID] ? updatedReportTotals[oldReportID] : updatedReportTotal; updatedReportNonReimbursableTotals[oldReportID] = (updatedReportNonReimbursableTotals[oldReportID] ? updatedReportNonReimbursableTotals[oldReportID] : (oldReport?.nonReimbursableTotal ?? 0)) + (transaction?.reimbursable ? 0 : transactionAmount); From c00d25febe04c595a690447ccde039a44bb881db Mon Sep 17 00:00:00 2001 From: kubabutkiewicz Date: Tue, 4 Nov 2025 10:58:40 +0100 Subject: [PATCH 8/8] lint --- src/pages/iou/SplitExpensePage.tsx | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/pages/iou/SplitExpensePage.tsx b/src/pages/iou/SplitExpensePage.tsx index 8b9651b9f016..932418b17df9 100644 --- a/src/pages/iou/SplitExpensePage.tsx +++ b/src/pages/iou/SplitExpensePage.tsx @@ -209,11 +209,6 @@ function SplitExpensePage({route}: SplitExpensePageProps) { translate, transactionID, transactionDetails?.currency, - isChatIOUReportArchived, - iouReport, - iouActions, - chatReport, - allReportNameValuePairs, ]); const onSplitExpenseAmountChange = useCallback( @@ -363,6 +358,7 @@ function SplitExpensePage({route}: SplitExpensePageProps) { })} onBackButtonPress={() => Navigation.goBack(backTo)} /> + (