From 09a1942fd86e4ec470873c41413b098afa1168df Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Tue, 1 Oct 2024 16:24:51 +0800 Subject: [PATCH 01/17] fix the wrong calculation --- src/libs/actions/IOU.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 874056cac4a0..05e85701abbb 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -6448,7 +6448,7 @@ function getReportFromHoldRequestsOnyxData( chatReport.reportID, chatReport.policyID ?? iouReport?.policyID ?? '', recipient.accountID ?? 1, - holdTransactions.reduce((acc, transaction) => acc + transaction.amount, 0) * (ReportUtils.isIOUReport(iouReport) ? 1 : -1), + ((iouReport?.total ?? 0) - ((iouReport?.unheldTotal ?? 0) + (iouReport?.nonReimbursableTotal ?? 0))) * (ReportUtils.isIOUReport(iouReport) ? 1 : -1), getCurrency(firstHoldTransaction), false, newParentReportActionID, From 2b5a1525508c12e7c195c90c42ea9c8675a89642 Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Tue, 1 Oct 2024 21:44:49 +0800 Subject: [PATCH 02/17] use the current iou when creating the new report --- src/libs/actions/IOU.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 05e85701abbb..4ec22844af2d 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -6449,7 +6449,7 @@ function getReportFromHoldRequestsOnyxData( chatReport.policyID ?? iouReport?.policyID ?? '', recipient.accountID ?? 1, ((iouReport?.total ?? 0) - ((iouReport?.unheldTotal ?? 0) + (iouReport?.nonReimbursableTotal ?? 0))) * (ReportUtils.isIOUReport(iouReport) ? 1 : -1), - getCurrency(firstHoldTransaction), + iouReport?.currency ?? '', false, newParentReportActionID, ); From 6196f9c0a253417c7f626f6ec8bbd7e8af1b8b85 Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Tue, 1 Oct 2024 21:51:03 +0800 Subject: [PATCH 03/17] remove unused import --- src/libs/actions/IOU.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 4ec22844af2d..95a4683fcc90 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -52,7 +52,7 @@ import * as ReportUtils from '@libs/ReportUtils'; import * as SessionUtils from '@libs/SessionUtils'; import * as SubscriptionUtils from '@libs/SubscriptionUtils'; import * as TransactionUtils from '@libs/TransactionUtils'; -import {getCurrency, getTransaction} from '@libs/TransactionUtils'; +import {getTransaction} from '@libs/TransactionUtils'; import ViolationsUtils from '@libs/Violations/ViolationsUtils'; import type {IOUAction, IOUType} from '@src/CONST'; import CONST from '@src/CONST'; From b831dd146c8bbe86ed416f1e47e31322d8da544f Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Wed, 16 Oct 2024 19:25:02 +0800 Subject: [PATCH 04/17] fix total calculation --- src/libs/actions/IOU.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 82847d121fd7..47f56790b46a 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -6496,7 +6496,7 @@ function getReportFromHoldRequestsOnyxData( chatReport.reportID, chatReport.policyID ?? iouReport?.policyID ?? '', recipient.accountID ?? 1, - ((iouReport?.total ?? 0) - ((iouReport?.unheldTotal ?? 0) + (iouReport?.nonReimbursableTotal ?? 0))) * (ReportUtils.isIOUReport(iouReport) ? 1 : -1), + ((iouReport?.total ?? 0) - (iouReport?.unheldTotal ?? 0)) * (ReportUtils.isIOUReport(iouReport) ? 1 : -1), iouReport?.currency ?? '', false, newParentReportActionID, From 7c223b95f3744d9531e11f8ae3d30d24cbb8209b Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Fri, 18 Oct 2024 18:24:56 +0800 Subject: [PATCH 05/17] get the reimbursable amount when the type is pay --- src/components/MoneyReportHeader.tsx | 2 +- .../ReportActionItem/ReportPreview.tsx | 24 +++++++------- src/libs/ReportUtils.ts | 31 +++++++++++++------ src/pages/home/ReportScreen.tsx | 1 + src/types/onyx/Report.ts | 3 ++ 5 files changed, 39 insertions(+), 22 deletions(-) diff --git a/src/components/MoneyReportHeader.tsx b/src/components/MoneyReportHeader.tsx index caa50abfca46..b88658a32c1c 100644 --- a/src/components/MoneyReportHeader.tsx +++ b/src/components/MoneyReportHeader.tsx @@ -158,7 +158,7 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea shouldShowExportIntegrationButton; const bankAccountRoute = ReportUtils.getBankAccountRoute(chatReport); const formattedAmount = CurrencyUtils.convertToDisplayString(reimbursableSpend, moneyRequestReport?.currency); - const [nonHeldAmount, fullAmount] = ReportUtils.getNonHeldAndFullAmount(moneyRequestReport, policy); + const [nonHeldAmount, fullAmount] = ReportUtils.getNonHeldAndFullAmount(moneyRequestReport, policy, shouldShowPayButton); const isAnyTransactionOnHold = ReportUtils.hasHeldExpenses(moneyRequestReport?.reportID); const displayedAmount = isAnyTransactionOnHold && canAllowSettlement ? nonHeldAmount : formattedAmount; const isMoreContentShown = shouldShowNextStep || shouldShowStatusBar || (shouldShowAnyButton && shouldUseNarrowLayout); diff --git a/src/components/ReportActionItem/ReportPreview.tsx b/src/components/ReportActionItem/ReportPreview.tsx index 411f6be7252c..91c27467d73e 100644 --- a/src/components/ReportActionItem/ReportPreview.tsx +++ b/src/components/ReportActionItem/ReportPreview.tsx @@ -100,6 +100,9 @@ function ReportPreview({ const [transactions] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION); const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS); const [userWallet] = useOnyx(ONYXKEYS.USER_WALLET); + const [invoiceReceiverPolicy] = useOnyx( + `${ONYXKEYS.COLLECTION.POLICY}${chatReport?.invoiceReceiver && 'policyID' in chatReport.invoiceReceiver ? chatReport.invoiceReceiver.policyID : -1}`, + ); const theme = useTheme(); const styles = useThemeStyles(); const {translate} = useLocalize(); @@ -121,13 +124,19 @@ function ReportPreview({ const [isPaidAnimationRunning, setIsPaidAnimationRunning] = useState(false); const [isHoldMenuVisible, setIsHoldMenuVisible] = useState(false); const [requestType, setRequestType] = useState(); - const [nonHeldAmount, fullAmount] = ReportUtils.getNonHeldAndFullAmount(iouReport, policy); - const hasOnlyHeldExpenses = ReportUtils.hasOnlyHeldExpenses(iouReport?.reportID ?? ''); const [paymentType, setPaymentType] = useState(); - const [invoiceReceiverPolicy] = useOnyx( - `${ONYXKEYS.COLLECTION.POLICY}${chatReport?.invoiceReceiver && 'policyID' in chatReport.invoiceReceiver ? chatReport.invoiceReceiver.policyID : -1}`, + + const getCanIOUBePaid = useCallback( + (onlyShowPayElsewhere = false) => IOU.canIOUBePaid(iouReport, chatReport, policy, allTransactions, onlyShowPayElsewhere), + [iouReport, chatReport, policy, allTransactions], ); + const canIOUBePaid = useMemo(() => getCanIOUBePaid(), [getCanIOUBePaid]); + const onlyShowPayElsewhere = useMemo(() => !canIOUBePaid && getCanIOUBePaid(true), [canIOUBePaid, getCanIOUBePaid]); + const shouldShowPayButton = isPaidAnimationRunning || canIOUBePaid || onlyShowPayElsewhere; + const [nonHeldAmount, fullAmount] = ReportUtils.getNonHeldAndFullAmount(iouReport, policy, shouldShowPayButton); + const hasOnlyHeldExpenses = ReportUtils.hasOnlyHeldExpenses(iouReport?.reportID ?? ''); + const managerID = iouReport?.managerID ?? action.childManagerAccountID ?? 0; const {totalDisplaySpend, reimbursableSpend} = ReportUtils.getMoneyRequestSpendBreakdown(iouReport); @@ -317,14 +326,7 @@ function ReportPreview({ ]); const bankAccountRoute = ReportUtils.getBankAccountRoute(chatReport); - const getCanIOUBePaid = useCallback( - (onlyShowPayElsewhere = false) => IOU.canIOUBePaid(iouReport, chatReport, policy, allTransactions, onlyShowPayElsewhere), - [iouReport, chatReport, policy, allTransactions], - ); - const canIOUBePaid = useMemo(() => getCanIOUBePaid(), [getCanIOUBePaid]); - const onlyShowPayElsewhere = useMemo(() => !canIOUBePaid && getCanIOUBePaid(true), [canIOUBePaid, getCanIOUBePaid]); - const shouldShowPayButton = isPaidAnimationRunning || canIOUBePaid || onlyShowPayElsewhere; const shouldShowApproveButton = useMemo(() => IOU.canApproveIOU(iouReport, policy), [iouReport, policy]); const shouldDisableApproveButton = shouldShowApproveButton && !ReportUtils.isAllowedToApproveExpenseReport(iouReport); diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 4bae619d928e..126612b34901 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -7677,26 +7677,37 @@ function hasUpdatedTotal(report: OnyxInputOrEntry, policy: OnyxInputOrEn /** * Return held and full amount formatted with used currency */ -function getNonHeldAndFullAmount(iouReport: OnyxEntry, policy: OnyxEntry): string[] { +function getNonHeldAndFullAmount(iouReport: OnyxEntry, policy: OnyxEntry, isReimbursableOnly: boolean): string[] { const reportTransactions = reportsTransactions[iouReport?.reportID ?? ''] ?? []; const hasPendingTransaction = reportTransactions.some((transaction) => !!transaction.pendingAction); // if the report is an expense report, the total amount should be negated const coefficient = isExpenseReport(iouReport) ? -1 : 1; + let total = iouReport?.total ?? 0; + if (isReimbursableOnly) { + total -= iouReport?.nonReimbursableTotal ?? 0; + } + if (hasUpdatedTotal(iouReport, policy) && hasPendingTransaction) { - const unheldTotal = reportTransactions.reduce((currentVal, transaction) => currentVal + (!TransactionUtils.isOnHold(transaction) ? transaction.amount : 0), 0); + const unheldNonReimbursableTotal = reportTransactions.reduce( + (currentVal, transaction) => currentVal + (!TransactionUtils.isOnHold(transaction) && !transaction.reimbursable ? transaction.amount : 0), + 0, + ); + let unheldTotal = reportTransactions.reduce((currentVal, transaction) => currentVal + (!TransactionUtils.isOnHold(transaction) ? transaction.amount : 0), 0); + + if (isReimbursableOnly) { + unheldTotal -= unheldNonReimbursableTotal; + } - return [ - CurrencyUtils.convertToDisplayString(unheldTotal * coefficient, iouReport?.currency), - CurrencyUtils.convertToDisplayString((iouReport?.total ?? 0) * coefficient, iouReport?.currency), - ]; + return [CurrencyUtils.convertToDisplayString(unheldTotal * coefficient, iouReport?.currency), CurrencyUtils.convertToDisplayString(total * coefficient, iouReport?.currency)]; } - return [ - CurrencyUtils.convertToDisplayString((iouReport?.unheldTotal ?? 0) * coefficient, iouReport?.currency), - CurrencyUtils.convertToDisplayString((iouReport?.total ?? 0) * coefficient, iouReport?.currency), - ]; + let unheldTotal = iouReport?.unheldTotal ?? 0; + if (isReimbursableOnly) { + unheldTotal -= iouReport?.unheldNonReimbursableTotal ?? 0; + } + return [CurrencyUtils.convertToDisplayString(unheldTotal * coefficient, iouReport?.currency), CurrencyUtils.convertToDisplayString(total * coefficient, iouReport?.currency)]; } /** diff --git a/src/pages/home/ReportScreen.tsx b/src/pages/home/ReportScreen.tsx index 4a87d51e3c82..2cc229c4fda5 100644 --- a/src/pages/home/ReportScreen.tsx +++ b/src/pages/home/ReportScreen.tsx @@ -193,6 +193,7 @@ function ReportScreen({route, currentReportID = '', navigation}: ReportScreenPro ownerAccountID: reportOnyx.ownerAccountID, currency: reportOnyx.currency, unheldTotal: reportOnyx.unheldTotal, + unheldNonReimbursableTotal: reportOnyx.unheldNonReimbursableTotal, participants: reportOnyx.participants, isWaitingOnBankAccount: reportOnyx.isWaitingOnBankAccount, iouReportID: reportOnyx.iouReportID, diff --git a/src/types/onyx/Report.ts b/src/types/onyx/Report.ts index 43c82cfdc227..2eedb57f4f13 100644 --- a/src/types/onyx/Report.ts +++ b/src/types/onyx/Report.ts @@ -218,6 +218,9 @@ type Report = OnyxCommon.OnyxValueWithOfflineFeedback< /** For expense reports, this is the total amount requested */ unheldTotal?: number; + /** Total amount of unheld and non-reimbursable transactions in an expense report */ + unheldNonReimbursableTotal?: number; + /** For expense reports, this is the currency of the expense */ currency?: string; From 903d17d0a942dc4eed3d32fd1dde0c1183a9414d Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Tue, 22 Oct 2024 11:33:56 +0800 Subject: [PATCH 06/17] rename --- src/libs/ReportUtils.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index f90fd469c617..9c766a972a65 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -7679,7 +7679,7 @@ function hasUpdatedTotal(report: OnyxInputOrEntry, policy: OnyxInputOrEn /** * Return held and full amount formatted with used currency */ -function getNonHeldAndFullAmount(iouReport: OnyxEntry, policy: OnyxEntry, isReimbursableOnly: boolean): string[] { +function getNonHeldAndFullAmount(iouReport: OnyxEntry, policy: OnyxEntry, shouldExcludeNonReimbursables: boolean): string[] { const reportTransactions = reportsTransactions[iouReport?.reportID ?? ''] ?? []; const hasPendingTransaction = reportTransactions.some((transaction) => !!transaction.pendingAction); @@ -7687,7 +7687,7 @@ function getNonHeldAndFullAmount(iouReport: OnyxEntry, policy: OnyxEntry const coefficient = isExpenseReport(iouReport) ? -1 : 1; let total = iouReport?.total ?? 0; - if (isReimbursableOnly) { + if (shouldExcludeNonReimbursables) { total -= iouReport?.nonReimbursableTotal ?? 0; } @@ -7698,7 +7698,7 @@ function getNonHeldAndFullAmount(iouReport: OnyxEntry, policy: OnyxEntry ); let unheldTotal = reportTransactions.reduce((currentVal, transaction) => currentVal + (!TransactionUtils.isOnHold(transaction) ? transaction.amount : 0), 0); - if (isReimbursableOnly) { + if (shouldExcludeNonReimbursables) { unheldTotal -= unheldNonReimbursableTotal; } @@ -7706,7 +7706,7 @@ function getNonHeldAndFullAmount(iouReport: OnyxEntry, policy: OnyxEntry } let unheldTotal = iouReport?.unheldTotal ?? 0; - if (isReimbursableOnly) { + if (shouldExcludeNonReimbursables) { unheldTotal -= iouReport?.unheldNonReimbursableTotal ?? 0; } return [CurrencyUtils.convertToDisplayString(unheldTotal * coefficient, iouReport?.currency), CurrencyUtils.convertToDisplayString(total * coefficient, iouReport?.currency)]; From 997de55caf5614183ec9d93691017aa5bac02698 Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Tue, 22 Oct 2024 15:50:39 +0800 Subject: [PATCH 07/17] update unheldTotal and unheldReimburableTotal optimistically --- src/components/MoneyReportHeader.tsx | 2 +- .../ReportActionItem/ReportPreview.tsx | 2 +- src/libs/ReportUtils.ts | 29 ++---- src/libs/actions/IOU.ts | 93 +++++++++++++++++-- 4 files changed, 92 insertions(+), 34 deletions(-) diff --git a/src/components/MoneyReportHeader.tsx b/src/components/MoneyReportHeader.tsx index 6bf2e0843922..ee74ac1ed58a 100644 --- a/src/components/MoneyReportHeader.tsx +++ b/src/components/MoneyReportHeader.tsx @@ -167,7 +167,7 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea shouldShowExportIntegrationButton; const bankAccountRoute = ReportUtils.getBankAccountRoute(chatReport); const formattedAmount = CurrencyUtils.convertToDisplayString(reimbursableSpend, moneyRequestReport?.currency); - const [nonHeldAmount, fullAmount] = ReportUtils.getNonHeldAndFullAmount(moneyRequestReport, policy, shouldShowPayButton); + const [nonHeldAmount, fullAmount] = ReportUtils.getNonHeldAndFullAmount(moneyRequestReport, shouldShowPayButton); const isAnyTransactionOnHold = ReportUtils.hasHeldExpenses(moneyRequestReport?.reportID); const displayedAmount = isAnyTransactionOnHold && canAllowSettlement ? nonHeldAmount : formattedAmount; const isMoreContentShown = shouldShowNextStep || shouldShowStatusBar || (shouldShowAnyButton && shouldUseNarrowLayout); diff --git a/src/components/ReportActionItem/ReportPreview.tsx b/src/components/ReportActionItem/ReportPreview.tsx index 9452f19cd45b..b54507c4869d 100644 --- a/src/components/ReportActionItem/ReportPreview.tsx +++ b/src/components/ReportActionItem/ReportPreview.tsx @@ -135,7 +135,7 @@ function ReportPreview({ const canIOUBePaid = useMemo(() => getCanIOUBePaid(), [getCanIOUBePaid]); const onlyShowPayElsewhere = useMemo(() => !canIOUBePaid && getCanIOUBePaid(true), [canIOUBePaid, getCanIOUBePaid]); const shouldShowPayButton = isPaidAnimationRunning || canIOUBePaid || onlyShowPayElsewhere; - const [nonHeldAmount, fullAmount] = ReportUtils.getNonHeldAndFullAmount(iouReport, policy, shouldShowPayButton); + const [nonHeldAmount, fullAmount] = ReportUtils.getNonHeldAndFullAmount(iouReport, shouldShowPayButton); const hasOnlyHeldExpenses = ReportUtils.hasOnlyHeldExpenses(iouReport?.reportID ?? ''); const managerID = iouReport?.managerID ?? action.childManagerAccountID ?? 0; diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 9c766a972a65..d835c05e0c7d 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -155,7 +155,9 @@ type OptimisticExpenseReport = Pick< | 'stateNum' | 'statusNum' | 'total' + | 'unheldTotal' | 'nonReimbursableTotal' + | 'unheldNonReimbursableTotal' | 'parentReportID' | 'lastVisibleActionCreated' | 'parentReportActionID' @@ -4579,7 +4581,9 @@ function buildOptimisticExpenseReport( stateNum, statusNum, total: storedTotal, + unheldTotal: storedTotal, nonReimbursableTotal: reimbursable ? 0 : storedTotal, + unheldNonReimbursableTotal: reimbursable ? 0 : storedTotal, participants: { [payeeAccountID]: { notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN, @@ -7679,36 +7683,17 @@ function hasUpdatedTotal(report: OnyxInputOrEntry, policy: OnyxInputOrEn /** * Return held and full amount formatted with used currency */ -function getNonHeldAndFullAmount(iouReport: OnyxEntry, policy: OnyxEntry, shouldExcludeNonReimbursables: boolean): string[] { - const reportTransactions = reportsTransactions[iouReport?.reportID ?? ''] ?? []; - const hasPendingTransaction = reportTransactions.some((transaction) => !!transaction.pendingAction); - +function getNonHeldAndFullAmount(iouReport: OnyxEntry, shouldExcludeNonReimbursables: boolean): string[] { // if the report is an expense report, the total amount should be negated const coefficient = isExpenseReport(iouReport) ? -1 : 1; let total = iouReport?.total ?? 0; - if (shouldExcludeNonReimbursables) { - total -= iouReport?.nonReimbursableTotal ?? 0; - } - - if (hasUpdatedTotal(iouReport, policy) && hasPendingTransaction) { - const unheldNonReimbursableTotal = reportTransactions.reduce( - (currentVal, transaction) => currentVal + (!TransactionUtils.isOnHold(transaction) && !transaction.reimbursable ? transaction.amount : 0), - 0, - ); - let unheldTotal = reportTransactions.reduce((currentVal, transaction) => currentVal + (!TransactionUtils.isOnHold(transaction) ? transaction.amount : 0), 0); - - if (shouldExcludeNonReimbursables) { - unheldTotal -= unheldNonReimbursableTotal; - } - - return [CurrencyUtils.convertToDisplayString(unheldTotal * coefficient, iouReport?.currency), CurrencyUtils.convertToDisplayString(total * coefficient, iouReport?.currency)]; - } - let unheldTotal = iouReport?.unheldTotal ?? 0; if (shouldExcludeNonReimbursables) { + total -= iouReport?.nonReimbursableTotal ?? 0; unheldTotal -= iouReport?.unheldNonReimbursableTotal ?? 0; } + return [CurrencyUtils.convertToDisplayString(unheldTotal * coefficient, iouReport?.currency), CurrencyUtils.convertToDisplayString(total * coefficient, iouReport?.currency)]; } diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index ae527da83e07..b4263ce0f620 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -2075,9 +2075,15 @@ function getMoneyRequestInformation( : ReportUtils.buildOptimisticIOUReport(payeeAccountID, payerAccountID, amount, chatReport.reportID, currency); } else if (isPolicyExpenseChat) { iouReport = {...iouReport}; - if (iouReport?.currency === currency && typeof iouReport.total === 'number') { - // Because of the Expense reports are stored as negative values, we subtract the total from the amount - iouReport.total -= amount; + // Because of the Expense reports are stored as negative values, we subtract the total from the amount + if (iouReport?.currency === currency) { + if (typeof iouReport.total === 'number') { + iouReport.total -= amount; + } + + if (typeof iouReport.unheldTotal === 'number') { + iouReport.unheldTotal -= amount; + } } } else { iouReport = IOUUtils.updateIOUOwnerAndTotal(iouReport, payeeAccountID, amount, currency); @@ -2301,10 +2307,17 @@ function getTrackExpenseInformation( iouReport = ReportUtils.buildOptimisticExpenseReport(chatReport.reportID, chatReport.policyID ?? '-1', payeeAccountID, amount, currency, false); } else { iouReport = {...iouReport}; - if (iouReport?.currency === currency && typeof iouReport.total === 'number' && typeof iouReport.nonReimbursableTotal === 'number') { - // Because of the Expense reports are stored as negative values, we subtract the total from the amount - iouReport.total -= amount; - iouReport.nonReimbursableTotal -= amount; + // Because of the Expense reports are stored as negative values, we subtract the total from the amount + if (iouReport?.currency === currency) { + if (typeof iouReport.total === 'number' && typeof iouReport.nonReimbursableTotal === 'number') { + iouReport.total -= amount; + iouReport.nonReimbursableTotal -= amount; + } + + if (typeof iouReport.unheldTotal === 'number' && typeof iouReport.unheldNonReimbursableTotal === 'number') { + iouReport.unheldTotal -= amount; + iouReport.unheldNonReimbursableTotal -= amount; + } } } } @@ -2505,6 +2518,7 @@ function getUpdateMoneyRequestParams( // Step 2: Get all the collections being updated const transactionThread = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`] ?? null; const transaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`]; + const isTransactionOnHold = TransactionUtils.isOnHold(transaction); const iouReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThread?.parentReportID}`] ?? null; const isFromExpenseReport = ReportUtils.isExpenseReport(iouReport); const isScanning = TransactionUtils.hasReceipt(transaction) && TransactionUtils.isReceiptBeingScanned(transaction); @@ -2624,6 +2638,14 @@ function getUpdateMoneyRequestParams( if (!transaction?.reimbursable && typeof updatedMoneyRequestReport.nonReimbursableTotal === 'number') { updatedMoneyRequestReport.nonReimbursableTotal -= diff; } + if (!isTransactionOnHold) { + if (typeof updatedMoneyRequestReport.unheldTotal === 'number') { + updatedMoneyRequestReport.unheldTotal -= diff; + } + if (!transaction?.reimbursable && typeof updatedMoneyRequestReport.unheldNonReimbursableTotal === 'number') { + updatedMoneyRequestReport.unheldNonReimbursableTotal -= diff; + } + } } else { updatedMoneyRequestReport = IOUUtils.updateIOUOwnerAndTotal(iouReport, updatedReportAction.actorAccountID ?? -1, diff, TransactionUtils.getCurrency(transaction), false, true); } @@ -4224,9 +4246,15 @@ function createSplitsAndOnyxData( ? ReportUtils.buildOptimisticExpenseReport(oneOnOneChatReport.reportID, oneOnOneChatReport.policyID ?? '-1', currentUserAccountID, splitAmount, currency) : ReportUtils.buildOptimisticIOUReport(currentUserAccountID, accountID, splitAmount, oneOnOneChatReport.reportID, currency); } else if (isOwnPolicyExpenseChat) { - if (typeof oneOnOneIOUReport?.total === 'number') { - // Because of the Expense reports are stored as negative values, we subtract the total from the amount - oneOnOneIOUReport.total -= splitAmount; + // Because of the Expense reports are stored as negative values, we subtract the total from the amount + if (oneOnOneIOUReport?.currency === currency) { + if (typeof oneOnOneIOUReport.total === 'number') { + oneOnOneIOUReport.total -= splitAmount; + } + + if (typeof oneOnOneIOUReport.unheldTotal === 'number') { + oneOnOneIOUReport.unheldTotal -= splitAmount; + } } } else { oneOnOneIOUReport = IOUUtils.updateIOUOwnerAndTotal(oneOnOneIOUReport, currentUserAccountID, splitAmount, currency); @@ -5624,6 +5652,7 @@ function prepareToCleanUpMoneyRequest(transactionID: string, reportAction: OnyxT // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const reportPreviewAction = getReportPreviewAction(iouReport?.chatReportID ?? '-1', iouReport?.reportID ?? '-1')!; const transaction = allTransactions[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`]; + const isTransactionOnHold = TransactionUtils.isOnHold(transaction); const transactionViolations = allTransactionViolations[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`]; const transactionThreadID = reportAction.childReportID; let transactionThread = null; @@ -5679,6 +5708,16 @@ function prepareToCleanUpMoneyRequest(transactionID: string, reportAction: OnyxT if (!transaction?.reimbursable && typeof updatedIOUReport.nonReimbursableTotal === 'number') { updatedIOUReport.nonReimbursableTotal += amountDiff; } + + if (!isTransactionOnHold) { + if (typeof updatedIOUReport.unheldTotal === 'number') { + updatedIOUReport.unheldTotal += amountDiff; + } + + if (!transaction?.reimbursable && typeof updatedIOUReport.unheldNonReimbursableTotal === 'number') { + updatedIOUReport.unheldNonReimbursableTotal += amountDiff; + } + } } } else { updatedIOUReport = IOUUtils.updateIOUOwnerAndTotal(iouReport, reportAction.actorAccountID ?? -1, TransactionUtils.getAmount(transaction, false), currency, true); @@ -7954,6 +7993,8 @@ function putOnHold(transactionID: string, comment: string, reportID: string, sea const transactionViolations = allTransactionViolations[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`] ?? []; const updatedViolations = [...transactionViolations, newViolation]; const parentReportActionOptimistic = ReportUtils.getOptimisticDataForParentReportAction(reportID, createdReportActionComment.created, CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD); + const transaction = allTransactions[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`]; + const iouReport = ReportConnection.getAllReports()?.[`${ONYXKEYS.COLLECTION.REPORT}${transaction?.reportID}`]; const optimisticData: OnyxUpdate[] = [ { @@ -7981,6 +8022,21 @@ function putOnHold(transactionID: string, comment: string, reportID: string, sea }, ]; + if (iouReport && iouReport.currency === transaction?.currency) { + const isExpenseReport = ReportUtils.isExpenseReport(iouReport); + const coefficient = isExpenseReport ? -1 : 1; + optimisticData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport.reportID}`, + value: { + unheldTotal: (iouReport.unheldTotal ?? 0) - TransactionUtils.getAmount(transaction, isExpenseReport) * coefficient, + unheldNonReimbursableTotal: !transaction?.reimbursable + ? (iouReport.unheldNonReimbursableTotal ?? 0) - TransactionUtils.getAmount(transaction, isExpenseReport) * coefficient + : iouReport.unheldNonReimbursableTotal, + }, + }); + } + parentReportActionOptimistic.forEach((parentActionData) => { if (!parentActionData) { return; @@ -8058,6 +8114,8 @@ function putOnHold(transactionID: string, comment: string, reportID: string, sea function unholdRequest(transactionID: string, reportID: string, searchHash?: number) { const createdReportAction = ReportUtils.buildOptimisticUnHoldReportAction(); const transactionViolations = allTransactionViolations[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`]; + const transaction = allTransactions[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`]; + const iouReport = ReportConnection.getAllReports()?.[`${ONYXKEYS.COLLECTION.REPORT}${transaction?.reportID}`]; const optimisticData: OnyxUpdate[] = [ { @@ -8084,6 +8142,21 @@ function unholdRequest(transactionID: string, reportID: string, searchHash?: num }, ]; + if (iouReport && iouReport.currency === transaction?.currency) { + const isExpenseReport = ReportUtils.isExpenseReport(iouReport); + const coefficient = isExpenseReport ? -1 : 1; + optimisticData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport.reportID}`, + value: { + unheldTotal: (iouReport.unheldTotal ?? 0) + TransactionUtils.getAmount(transaction, isExpenseReport) * coefficient, + unheldNonReimbursableTotal: !transaction?.reimbursable + ? (iouReport.unheldNonReimbursableTotal ?? 0) + TransactionUtils.getAmount(transaction, isExpenseReport) * coefficient + : iouReport.unheldNonReimbursableTotal, + }, + }); + } + const successData: OnyxUpdate[] = [ { onyxMethod: Onyx.METHOD.MERGE, From 6e1f6e41d154ef365ab0fca7e9d9b0710dbdf8e5 Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Wed, 23 Oct 2024 11:15:11 +0800 Subject: [PATCH 08/17] update comment --- src/types/onyx/Report.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types/onyx/Report.ts b/src/types/onyx/Report.ts index 2eedb57f4f13..1e937e8c9093 100644 --- a/src/types/onyx/Report.ts +++ b/src/types/onyx/Report.ts @@ -218,7 +218,7 @@ type Report = OnyxCommon.OnyxValueWithOfflineFeedback< /** For expense reports, this is the total amount requested */ unheldTotal?: number; - /** Total amount of unheld and non-reimbursable transactions in an expense report */ + /** Total amount of unheld non-reimbursable transactions in an expense report */ unheldNonReimbursableTotal?: number; /** For expense reports, this is the currency of the expense */ From 077a7d5f61d578f00318b5e963935936c97e7373 Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Wed, 23 Oct 2024 11:16:11 +0800 Subject: [PATCH 09/17] calc the amount once --- src/libs/actions/IOU.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index edd31a9ac8aa..49496b3087bd 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -8024,14 +8024,13 @@ function putOnHold(transactionID: string, comment: string, reportID: string, sea if (iouReport && iouReport.currency === transaction?.currency) { const isExpenseReport = ReportUtils.isExpenseReport(iouReport); const coefficient = isExpenseReport ? -1 : 1; + const transactionAmount = TransactionUtils.getAmount(transaction, isExpenseReport) * coefficient; optimisticData.push({ onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport.reportID}`, value: { - unheldTotal: (iouReport.unheldTotal ?? 0) - TransactionUtils.getAmount(transaction, isExpenseReport) * coefficient, - unheldNonReimbursableTotal: !transaction?.reimbursable - ? (iouReport.unheldNonReimbursableTotal ?? 0) - TransactionUtils.getAmount(transaction, isExpenseReport) * coefficient - : iouReport.unheldNonReimbursableTotal, + unheldTotal: (iouReport.unheldTotal ?? 0) - transactionAmount, + unheldNonReimbursableTotal: !transaction?.reimbursable ? (iouReport.unheldNonReimbursableTotal ?? 0) - transactionAmount : iouReport.unheldNonReimbursableTotal, }, }); } @@ -8144,14 +8143,13 @@ function unholdRequest(transactionID: string, reportID: string, searchHash?: num if (iouReport && iouReport.currency === transaction?.currency) { const isExpenseReport = ReportUtils.isExpenseReport(iouReport); const coefficient = isExpenseReport ? -1 : 1; + const transactionAmount = TransactionUtils.getAmount(transaction, isExpenseReport) * coefficient; optimisticData.push({ onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport.reportID}`, value: { - unheldTotal: (iouReport.unheldTotal ?? 0) + TransactionUtils.getAmount(transaction, isExpenseReport) * coefficient, - unheldNonReimbursableTotal: !transaction?.reimbursable - ? (iouReport.unheldNonReimbursableTotal ?? 0) + TransactionUtils.getAmount(transaction, isExpenseReport) * coefficient - : iouReport.unheldNonReimbursableTotal, + unheldTotal: (iouReport.unheldTotal ?? 0) + transactionAmount, + unheldNonReimbursableTotal: !transaction?.reimbursable ? (iouReport.unheldNonReimbursableTotal ?? 0) + transactionAmount : iouReport.unheldNonReimbursableTotal, }, }); } From d7fddd16e266a0f2e6d8f4376a2abf62b2db6ef8 Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Wed, 23 Oct 2024 15:27:37 +0800 Subject: [PATCH 10/17] store the correct non reimbursable amount --- src/libs/ReportUtils.ts | 7 ++++--- src/libs/actions/IOU.ts | 8 +++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index dcb2a45bfb97..5b529f662b35 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -4557,11 +4557,12 @@ function buildOptimisticExpenseReport( payeeAccountID: number, total: number, currency: string, - reimbursable = true, + nonReimbursableTotal: number = 0, parentReportActionID?: string, ): OptimisticExpenseReport { // The amount for Expense reports are stored as negative value in the database const storedTotal = total * -1; + const storedNonReimbursableTotal = nonReimbursableTotal * -1; const policyName = getPolicyName(ReportConnection.getAllReports()?.[`${ONYXKEYS.COLLECTION.REPORT}${chatReportID}`]); const formattedTotal = CurrencyUtils.convertToDisplayString(storedTotal, currency); const policy = getPolicy(policyID); @@ -4581,8 +4582,8 @@ function buildOptimisticExpenseReport( statusNum, total: storedTotal, unheldTotal: storedTotal, - nonReimbursableTotal: reimbursable ? 0 : storedTotal, - unheldNonReimbursableTotal: reimbursable ? 0 : storedTotal, + nonReimbursableTotal: storedNonReimbursableTotal, + unheldNonReimbursableTotal: storedNonReimbursableTotal, participants: { [payeeAccountID]: { notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN, diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 49496b3087bd..5a8fbc8c7976 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -2304,7 +2304,7 @@ function getTrackExpenseInformation( shouldCreateNewMoneyRequestReport = ReportUtils.shouldCreateNewMoneyRequestReport(iouReport, chatReport); if (!iouReport || shouldCreateNewMoneyRequestReport) { - iouReport = ReportUtils.buildOptimisticExpenseReport(chatReport.reportID, chatReport.policyID ?? '-1', payeeAccountID, amount, currency, false); + iouReport = ReportUtils.buildOptimisticExpenseReport(chatReport.reportID, chatReport.policyID ?? '-1', payeeAccountID, amount, currency, 0); } else { iouReport = {...iouReport}; // Because of the Expense reports are stored as negative values, we subtract the total from the amount @@ -6549,13 +6549,14 @@ function getReportFromHoldRequestsOnyxData( const firstHoldTransaction = holdTransactions.at(0); const newParentReportActionID = rand64(); + const coefficient = ReportUtils.isExpenseReport(iouReport) ? -1 : 1; const optimisticExpenseReport = ReportUtils.buildOptimisticExpenseReport( chatReport.reportID, chatReport.policyID ?? iouReport?.policyID ?? '', recipient.accountID ?? 1, - ((iouReport?.total ?? 0) - (iouReport?.unheldTotal ?? 0)) * (ReportUtils.isIOUReport(iouReport) ? 1 : -1), + ((iouReport?.total ?? 0) - (iouReport?.unheldTotal ?? 0)) * coefficient, iouReport?.currency ?? '', - false, + ((iouReport?.nonReimbursableTotal ?? 0) - (iouReport?.unheldNonReimbursableTotal ?? 0)) * coefficient, newParentReportActionID, ); const optimisticExpenseReportPreview = ReportUtils.buildOptimisticReportPreview( @@ -6630,6 +6631,7 @@ function getReportFromHoldRequestsOnyxData( value: { ...optimisticExpenseReport, unheldTotal: 0, + unheldNonReimbursableTotal: 0, }, }, // add preview report action to main chat From 6932d6052c6ce827272dcbfca1c1cb977566c43f Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Wed, 23 Oct 2024 15:35:02 +0800 Subject: [PATCH 11/17] fix lint --- src/libs/ReportUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 5b529f662b35..b288441cd79d 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -4557,7 +4557,7 @@ function buildOptimisticExpenseReport( payeeAccountID: number, total: number, currency: string, - nonReimbursableTotal: number = 0, + nonReimbursableTotal = 0, parentReportActionID?: string, ): OptimisticExpenseReport { // The amount for Expense reports are stored as negative value in the database From 8ce39ae2c6913a33fbc996d1456e0b791edb3d9b Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Thu, 24 Oct 2024 10:40:30 +0800 Subject: [PATCH 12/17] fix wrong non reimbursable amount --- src/libs/actions/IOU.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 1064a23d818c..9ac974b47ed8 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -2304,7 +2304,7 @@ function getTrackExpenseInformation( shouldCreateNewMoneyRequestReport = ReportUtils.shouldCreateNewMoneyRequestReport(iouReport, chatReport); if (!iouReport || shouldCreateNewMoneyRequestReport) { - iouReport = ReportUtils.buildOptimisticExpenseReport(chatReport.reportID, chatReport.policyID ?? '-1', payeeAccountID, amount, currency, 0); + iouReport = ReportUtils.buildOptimisticExpenseReport(chatReport.reportID, chatReport.policyID ?? '-1', payeeAccountID, amount, currency, amount); } else { iouReport = {...iouReport}; // Because of the Expense reports are stored as negative values, we subtract the total from the amount From c278a1a6091c19ad549ac5e06b2b8cfeb756fd45 Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Thu, 24 Oct 2024 11:28:07 +0800 Subject: [PATCH 13/17] optimistically update unheld total for IOU --- src/libs/IOUUtils.ts | 9 +++++++++ src/libs/ReportUtils.ts | 6 ++++++ src/libs/actions/IOU.ts | 20 ++++++++++++++++++-- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/libs/IOUUtils.ts b/src/libs/IOUUtils.ts index dcfdd4bbc73a..3ef36460c405 100644 --- a/src/libs/IOUUtils.ts +++ b/src/libs/IOUUtils.ts @@ -75,6 +75,7 @@ function updateIOUOwnerAndTotal>( currency: string, isDeleting = false, isUpdating = false, + isOnhold = false, ): TReport { // For the update case, we have calculated the diff amount in the calculateDiffAmount function so there is no need to compare currencies here if ((currency !== iouReport?.currency && !isUpdating) || !iouReport) { @@ -86,11 +87,18 @@ function updateIOUOwnerAndTotal>( // Let us ensure a valid value before updating the total amount. iouReportUpdate.total = iouReportUpdate.total ?? 0; + iouReportUpdate.unheldTotal = iouReportUpdate.unheldTotal ?? 0; if (actorAccountID === iouReport.ownerAccountID) { iouReportUpdate.total += isDeleting ? -amount : amount; + if (!isOnhold) { + iouReportUpdate.unheldTotal += isDeleting ? -amount : amount; + } } else { iouReportUpdate.total += isDeleting ? amount : -amount; + if (!isOnhold) { + iouReportUpdate.unheldTotal += isDeleting ? amount : -amount; + } } if (iouReportUpdate.total < 0) { @@ -98,6 +106,7 @@ function updateIOUOwnerAndTotal>( iouReportUpdate.ownerAccountID = iouReport.managerID; iouReportUpdate.managerID = iouReport.ownerAccountID; iouReportUpdate.total = -iouReportUpdate.total; + iouReportUpdate.unheldTotal = -iouReportUpdate.unheldTotal; } return iouReportUpdate; diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 39a2043db339..e3c689af2247 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -449,6 +449,9 @@ type OptimisticIOUReport = Pick< | 'stateNum' | 'statusNum' | 'total' + | 'unheldTotal' + | 'nonReimbursableTotal' + | 'unheldNonReimbursableTotal' | 'reportName' | 'parentReportID' | 'lastVisibleActionCreated' @@ -4458,6 +4461,9 @@ function buildOptimisticIOUReport(payeeAccountID: number, payerAccountID: number stateNum: isSendingMoney ? CONST.REPORT.STATE_NUM.APPROVED : CONST.REPORT.STATE_NUM.SUBMITTED, statusNum: isSendingMoney ? CONST.REPORT.STATUS_NUM.REIMBURSED : CONST.REPORT.STATE_NUM.SUBMITTED, total, + unheldTotal: total, + nonReimbursableTotal: 0, + unheldNonReimbursableTotal: 0, // We don't translate reportName because the server response is always in English reportName: `${payerEmail} owes ${formattedTotal}`, diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 9ac974b47ed8..88482c195ca5 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -2644,7 +2644,15 @@ function getUpdateMoneyRequestParams( } } } else { - updatedMoneyRequestReport = IOUUtils.updateIOUOwnerAndTotal(iouReport, updatedReportAction.actorAccountID ?? -1, diff, TransactionUtils.getCurrency(transaction), false, true); + updatedMoneyRequestReport = IOUUtils.updateIOUOwnerAndTotal( + iouReport, + updatedReportAction.actorAccountID ?? -1, + diff, + TransactionUtils.getCurrency(transaction), + false, + true, + isTransactionOnHold, + ); } if (updatedMoneyRequestReport) { @@ -5716,7 +5724,15 @@ function prepareToCleanUpMoneyRequest(transactionID: string, reportAction: OnyxT } } } else { - updatedIOUReport = IOUUtils.updateIOUOwnerAndTotal(iouReport, reportAction.actorAccountID ?? -1, TransactionUtils.getAmount(transaction, false), currency, true); + updatedIOUReport = IOUUtils.updateIOUOwnerAndTotal( + iouReport, + reportAction.actorAccountID ?? -1, + TransactionUtils.getAmount(transaction, false), + currency, + true, + false, + isTransactionOnHold, + ); } if (updatedIOUReport) { From 164a73a73e8f49abebb17a5490740640dcc35092 Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Thu, 14 Nov 2024 19:31:22 +0800 Subject: [PATCH 14/17] fix syntax error --- src/libs/actions/IOU.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 812b1b137884..df10224925f3 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -6324,7 +6324,7 @@ function getReportFromHoldRequestsOnyxData( const coefficient = ReportUtils.isExpenseReport(iouReport) ? -1 : 1; const isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(chatReport); const holdAmount = ((iouReport?.total ?? 0) - (iouReport?.unheldTotal ?? 0)) * coefficient; - const holdNonReimbursableAmount = ((iouReport?.nonReimbursableTotal ?? 0) - (iouReport?.unheldNonReimbursableTotal ?? 0)) * coefficient,; + const holdNonReimbursableAmount = ((iouReport?.nonReimbursableTotal ?? 0) - (iouReport?.unheldNonReimbursableTotal ?? 0)) * coefficient; const optimisticExpenseReport = isPolicyExpenseChat ? ReportUtils.buildOptimisticExpenseReport( chatReport.reportID, From 2c4480d2998fadd4cdb6cb5955b82545e478cddd Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Sat, 23 Nov 2024 14:33:57 +0800 Subject: [PATCH 15/17] fix lint --- src/libs/DebugUtils.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/DebugUtils.ts b/src/libs/DebugUtils.ts index 671fb03f268b..f881d703d269 100644 --- a/src/libs/DebugUtils.ts +++ b/src/libs/DebugUtils.ts @@ -616,6 +616,7 @@ function validateReportDraftProperty(key: keyof Report, value: string) { participants: CONST.RED_BRICK_ROAD_PENDING_ACTION, total: CONST.RED_BRICK_ROAD_PENDING_ACTION, unheldTotal: CONST.RED_BRICK_ROAD_PENDING_ACTION, + unheldNonReimbursableTotal: CONST.RED_BRICK_ROAD_PENDING_ACTION, isWaitingOnBankAccount: CONST.RED_BRICK_ROAD_PENDING_ACTION, isCancelledIOU: CONST.RED_BRICK_ROAD_PENDING_ACTION, iouReportID: CONST.RED_BRICK_ROAD_PENDING_ACTION, From 9ade52c0d5a6abcde9a8468fe4380cb07ce6c6dd Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Sat, 23 Nov 2024 14:37:21 +0800 Subject: [PATCH 16/17] fix another lint --- src/libs/DebugUtils.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/DebugUtils.ts b/src/libs/DebugUtils.ts index f881d703d269..061931aa0bd4 100644 --- a/src/libs/DebugUtils.ts +++ b/src/libs/DebugUtils.ts @@ -489,6 +489,7 @@ function validateReportDraftProperty(key: keyof Report, value: string) { case 'total': case 'unheldTotal': case 'nonReimbursableTotal': + case 'unheldNonReimbursableTotal': return validateNumber(value); case 'chatType': return validateConstantEnum(value, CONST.REPORT.CHAT_TYPE); From fa58c4f5c1ba9470e159862e316b5e7388fe794d Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Sat, 23 Nov 2024 14:44:02 +0800 Subject: [PATCH 17/17] fix type error --- src/types/utils/whitelistedReportKeys.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/types/utils/whitelistedReportKeys.ts b/src/types/utils/whitelistedReportKeys.ts index 32aa0797d0f8..db03d887038c 100644 --- a/src/types/utils/whitelistedReportKeys.ts +++ b/src/types/utils/whitelistedReportKeys.ts @@ -47,6 +47,7 @@ type WhitelistedReport = OnyxCommon.OnyxValueWithOfflineFeedback< participants: unknown; total: unknown; unheldTotal: unknown; + unheldNonReimbursableTotal: unknown; currency: unknown; errorFields: unknown; isWaitingOnBankAccount: unknown;