From 158e5e66f3af413a53a405f18c009b28b508dab1 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Mon, 22 Jan 2024 12:06:43 -0700 Subject: [PATCH 1/6] calculate reimbursable total based on total and nonReimbursableTotal --- src/libs/ReportUtils.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 78086c354de0..982ff286932b 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1811,13 +1811,13 @@ function getMoneyRequestReimbursableTotal(report: OnyxEntry, allReportsD moneyRequestReport = allAvailableReports[`${ONYXKEYS.COLLECTION.REPORT}${report.iouReportID}`]; } if (moneyRequestReport) { - const total = moneyRequestReport?.total ?? 0; + const reimbursableTotal = (moneyRequestReport?.total ?? 0) - (moneyRequestReport?.nonReimbursableTotal ?? 0); - if (total !== 0) { + if (reimbursableTotal !== 0) { // There is a possibility that if the Expense report has a negative total. // This is because there are instances where you can get a credit back on your card, // or you enter a negative expense to “offset” future expenses - return isExpenseReport(moneyRequestReport) ? total * -1 : Math.abs(total); + return isExpenseReport(moneyRequestReport) ? reimbursableTotal * -1 : Math.abs(reimbursableTotal); } } return 0; From 09e90dd42268f798b7e581e2022ea36841a3901f Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Mon, 22 Jan 2024 12:12:59 -0700 Subject: [PATCH 2/6] revert changes --- src/libs/ReportUtils.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 982ff286932b..78086c354de0 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1811,13 +1811,13 @@ function getMoneyRequestReimbursableTotal(report: OnyxEntry, allReportsD moneyRequestReport = allAvailableReports[`${ONYXKEYS.COLLECTION.REPORT}${report.iouReportID}`]; } if (moneyRequestReport) { - const reimbursableTotal = (moneyRequestReport?.total ?? 0) - (moneyRequestReport?.nonReimbursableTotal ?? 0); + const total = moneyRequestReport?.total ?? 0; - if (reimbursableTotal !== 0) { + if (total !== 0) { // There is a possibility that if the Expense report has a negative total. // This is because there are instances where you can get a credit back on your card, // or you enter a negative expense to “offset” future expenses - return isExpenseReport(moneyRequestReport) ? reimbursableTotal * -1 : Math.abs(reimbursableTotal); + return isExpenseReport(moneyRequestReport) ? total * -1 : Math.abs(total); } } return 0; From 0ddc19813ee488fbb7f54797f462da9beb007d83 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Mon, 22 Jan 2024 12:13:49 -0700 Subject: [PATCH 3/6] use getMoneyRequestSpendBreakdown --- src/components/MoneyReportHeader.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/components/MoneyReportHeader.tsx b/src/components/MoneyReportHeader.tsx index afdc62218f95..b69fe63bb638 100644 --- a/src/components/MoneyReportHeader.tsx +++ b/src/components/MoneyReportHeader.tsx @@ -52,7 +52,7 @@ function MoneyReportHeader({session, personalDetails, policy, chatReport, nextSt const styles = useThemeStyles(); const {translate} = useLocalize(); const {windowWidth, isSmallScreenWidth} = useWindowDimensions(); - const reimbursableTotal = ReportUtils.getMoneyRequestReimbursableTotal(moneyRequestReport); + const {reimbursableSpend} = ReportUtils.getMoneyRequestSpendBreakdown(moneyRequestReport); const isApproved = ReportUtils.isReportApproved(moneyRequestReport); const isSettled = ReportUtils.isSettled(moneyRequestReport.reportID); const policyType = policy?.type; @@ -65,8 +65,8 @@ function MoneyReportHeader({session, personalDetails, policy, chatReport, nextSt : isPolicyAdmin || (ReportUtils.isMoneyRequestReport(moneyRequestReport) && isManager); const isDraft = ReportUtils.isDraftExpenseReport(moneyRequestReport); const shouldShowPayButton = useMemo( - () => isPayer && !isDraft && !isSettled && !moneyRequestReport.isWaitingOnBankAccount && reimbursableTotal !== 0 && !ReportUtils.isArchivedRoom(chatReport), - [isPayer, isDraft, isSettled, moneyRequestReport, reimbursableTotal, chatReport], + () => isPayer && !isDraft && !isSettled && !moneyRequestReport.isWaitingOnBankAccount && reimbursableSpend !== 0 && !ReportUtils.isArchivedRoom(chatReport), + [isPayer, isDraft, isSettled, moneyRequestReport, reimbursableSpend, chatReport], ); const shouldShowApproveButton = useMemo(() => { if (!isPaidGroupPolicy) { @@ -75,12 +75,12 @@ function MoneyReportHeader({session, personalDetails, policy, chatReport, nextSt return isManager && !isDraft && !isApproved && !isSettled; }, [isPaidGroupPolicy, isManager, isDraft, isApproved, isSettled]); const shouldShowSettlementButton = shouldShowPayButton || shouldShowApproveButton; - const shouldShowSubmitButton = isDraft && reimbursableTotal !== 0; + const shouldShowSubmitButton = isDraft && reimbursableSpend !== 0; const isFromPaidPolicy = policyType === CONST.POLICY.TYPE.TEAM || policyType === CONST.POLICY.TYPE.CORPORATE; const shouldShowNextStep = isFromPaidPolicy && !!nextStep?.message?.length; const shouldShowAnyButton = shouldShowSettlementButton || shouldShowApproveButton || shouldShowSubmitButton || shouldShowNextStep; const bankAccountRoute = ReportUtils.getBankAccountRoute(chatReport); - const formattedAmount = CurrencyUtils.convertToDisplayString(reimbursableTotal, moneyRequestReport.currency); + const formattedAmount = CurrencyUtils.convertToDisplayString(reimbursableSpend, moneyRequestReport.currency); const isMoreContentShown = shouldShowNextStep || (shouldShowAnyButton && isSmallScreenWidth); // The submit button should be success green colour only if the user is submitter and the policy does not have Scheduled Submit turned on From 25595f98f3a5cda690d7fc6d01a77e7117fa2a24 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Mon, 22 Jan 2024 12:15:19 -0700 Subject: [PATCH 4/6] rename getMoneyRequestReimbursableTotal to getMoneyRequestTotal --- src/libs/OptionsListUtils.js | 2 +- src/libs/ReportUtils.ts | 10 +++++----- src/libs/SidebarUtils.ts | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index e86c9daacb42..724c6465bdce 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -568,7 +568,7 @@ function createOption(accountIDs, personalDetails, report, reportActions = {}, { } result.isIOUReportOwner = ReportUtils.isIOUOwnedByCurrentUser(result); - result.iouReportAmount = ReportUtils.getMoneyRequestReimbursableTotal(result); + result.iouReportAmount = ReportUtils.getMoneyRequestTotal(result); if (!hasMultipleParticipants) { result.login = personalDetail.login; diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 78086c354de0..49e310bcadc8 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1801,7 +1801,7 @@ function hasNonReimbursableTransactions(iouReportID: string | undefined): boolea return transactions.filter((transaction) => transaction.reimbursable === false).length > 0; } -function getMoneyRequestReimbursableTotal(report: OnyxEntry, allReportsDict: OnyxCollection = null): number { +function getMoneyRequestTotal(report: OnyxEntry, allReportsDict: OnyxCollection = null): number { const allAvailableReports = allReportsDict ?? allReports; let moneyRequestReport: OnyxEntry | undefined; if (isMoneyRequestReport(report)) { @@ -1903,7 +1903,7 @@ function getPolicyExpenseChatName(report: OnyxEntry, policy: OnyxEntry

, policy: OnyxEntry | undefined = undefined): string { - const moneyRequestTotal = getMoneyRequestReimbursableTotal(report); + const moneyRequestTotal = getMoneyRequestTotal(report); const formattedAmount = CurrencyUtils.convertToDisplayString(moneyRequestTotal, report?.currency, hasOnlyDistanceRequestTransactions(report?.reportID)); const payerOrApproverName = isExpenseReport(report) ? getPolicyName(report, false, policy) : getDisplayNameForParticipant(report?.managerID) ?? ''; const payerPaidAmountMessage = Localize.translateLocal('iou.payerPaidAmount', { @@ -2203,7 +2203,7 @@ function getReportPreviewMessage( } } - const totalAmount = getMoneyRequestReimbursableTotal(report); + const totalAmount = getMoneyRequestTotal(report); const policyName = getPolicyName(report, false, policy); const payerName = isExpenseReport(report) ? policyName : getDisplayNameForParticipant(report.managerID, !isPreviewMessageForParentChatReport); @@ -2746,7 +2746,7 @@ function getIOUReportActionMessage(iouReportID: string, type: string, total: num const report = getReport(iouReportID); const amount = type === CONST.IOU.REPORT_ACTION_TYPE.PAY - ? CurrencyUtils.convertToDisplayString(getMoneyRequestReimbursableTotal(!isEmptyObject(report) ? report : null), currency) + ? CurrencyUtils.convertToDisplayString(getMoneyRequestTotal(!isEmptyObject(report) ? report : null), currency) : CurrencyUtils.convertToDisplayString(total, currency); let paymentMethodMessage; @@ -4593,7 +4593,7 @@ export { hasExpensifyGuidesEmails, requiresAttentionFromCurrentUser, isIOUOwnedByCurrentUser, - getMoneyRequestReimbursableTotal, + getMoneyRequestTotal, getMoneyRequestSpendBreakdown, canShowReportRecipientLocalTime, formatReportLastMessageText, diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index 445d9dc30dd8..0548c4071330 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -199,7 +199,7 @@ function getOrderedReportIDs( report.displayName = ReportUtils.getReportName(report); // eslint-disable-next-line no-param-reassign - report.iouReportAmount = ReportUtils.getMoneyRequestReimbursableTotal(report, allReports); + report.iouReportAmount = ReportUtils.getMoneyRequestTotal(report, allReports); const isPinned = report.isPinned ?? false; const reportAction = ReportActionsUtils.getReportAction(report.parentReportID ?? '', report.parentReportActionID ?? ''); @@ -458,7 +458,7 @@ function getOptionData({ } result.isIOUReportOwner = ReportUtils.isIOUOwnedByCurrentUser(result as Report); - result.iouReportAmount = ReportUtils.getMoneyRequestReimbursableTotal(result as Report); + result.iouReportAmount = ReportUtils.getMoneyRequestTotal(result as Report); if (!hasMultipleParticipants) { result.accountID = personalDetail.accountID; From 1be02bcbdb657af69134eaac589d5b80b3f96ac7 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Mon, 22 Jan 2024 12:27:38 -0700 Subject: [PATCH 5/6] delete getMoneyRequestReimbursableTotal --- src/libs/OptionsListUtils.js | 2 +- src/libs/ReportUtils.ts | 29 +++-------------------------- src/libs/SidebarUtils.ts | 4 ++-- 3 files changed, 6 insertions(+), 29 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 724c6465bdce..beab49818fa0 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -568,7 +568,7 @@ function createOption(accountIDs, personalDetails, report, reportActions = {}, { } result.isIOUReportOwner = ReportUtils.isIOUOwnedByCurrentUser(result); - result.iouReportAmount = ReportUtils.getMoneyRequestTotal(result); + result.iouReportAmount = ReportUtils.getMoneyRequestSpendBreakdown(result).totalDisplaySpend; if (!hasMultipleParticipants) { result.login = personalDetail.login; diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 49e310bcadc8..ab06125a828c 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1801,28 +1801,6 @@ function hasNonReimbursableTransactions(iouReportID: string | undefined): boolea return transactions.filter((transaction) => transaction.reimbursable === false).length > 0; } -function getMoneyRequestTotal(report: OnyxEntry, allReportsDict: OnyxCollection = null): number { - const allAvailableReports = allReportsDict ?? allReports; - let moneyRequestReport: OnyxEntry | undefined; - if (isMoneyRequestReport(report)) { - moneyRequestReport = report; - } - if (allAvailableReports && report?.iouReportID) { - moneyRequestReport = allAvailableReports[`${ONYXKEYS.COLLECTION.REPORT}${report.iouReportID}`]; - } - if (moneyRequestReport) { - const total = moneyRequestReport?.total ?? 0; - - if (total !== 0) { - // There is a possibility that if the Expense report has a negative total. - // This is because there are instances where you can get a credit back on your card, - // or you enter a negative expense to “offset” future expenses - return isExpenseReport(moneyRequestReport) ? total * -1 : Math.abs(total); - } - } - return 0; -} - function getMoneyRequestSpendBreakdown(report: OnyxEntry, allReportsDict: OnyxCollection = null): SpendBreakdown { const allAvailableReports = allReportsDict ?? allReports; let moneyRequestReport; @@ -1903,7 +1881,7 @@ function getPolicyExpenseChatName(report: OnyxEntry, policy: OnyxEntry

, policy: OnyxEntry | undefined = undefined): string { - const moneyRequestTotal = getMoneyRequestTotal(report); + const moneyRequestTotal = getMoneyRequestSpendBreakdown(report).totalDisplaySpend; const formattedAmount = CurrencyUtils.convertToDisplayString(moneyRequestTotal, report?.currency, hasOnlyDistanceRequestTransactions(report?.reportID)); const payerOrApproverName = isExpenseReport(report) ? getPolicyName(report, false, policy) : getDisplayNameForParticipant(report?.managerID) ?? ''; const payerPaidAmountMessage = Localize.translateLocal('iou.payerPaidAmount', { @@ -2203,7 +2181,7 @@ function getReportPreviewMessage( } } - const totalAmount = getMoneyRequestTotal(report); + const totalAmount = getMoneyRequestSpendBreakdown(report).totalDisplaySpend; const policyName = getPolicyName(report, false, policy); const payerName = isExpenseReport(report) ? policyName : getDisplayNameForParticipant(report.managerID, !isPreviewMessageForParentChatReport); @@ -2746,7 +2724,7 @@ function getIOUReportActionMessage(iouReportID: string, type: string, total: num const report = getReport(iouReportID); const amount = type === CONST.IOU.REPORT_ACTION_TYPE.PAY - ? CurrencyUtils.convertToDisplayString(getMoneyRequestTotal(!isEmptyObject(report) ? report : null), currency) + ? CurrencyUtils.convertToDisplayString(getMoneyRequestSpendBreakdown(!isEmptyObject(report) ? report : null).totalDisplaySpend, currency) : CurrencyUtils.convertToDisplayString(total, currency); let paymentMethodMessage; @@ -4593,7 +4571,6 @@ export { hasExpensifyGuidesEmails, requiresAttentionFromCurrentUser, isIOUOwnedByCurrentUser, - getMoneyRequestTotal, getMoneyRequestSpendBreakdown, canShowReportRecipientLocalTime, formatReportLastMessageText, diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index 0548c4071330..a3208208dbc2 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -199,7 +199,7 @@ function getOrderedReportIDs( report.displayName = ReportUtils.getReportName(report); // eslint-disable-next-line no-param-reassign - report.iouReportAmount = ReportUtils.getMoneyRequestTotal(report, allReports); + report.iouReportAmount = ReportUtils.getMoneyRequestSpendBreakdown(report, allReports).totalDisplaySpend; const isPinned = report.isPinned ?? false; const reportAction = ReportActionsUtils.getReportAction(report.parentReportID ?? '', report.parentReportActionID ?? ''); @@ -458,7 +458,7 @@ function getOptionData({ } result.isIOUReportOwner = ReportUtils.isIOUOwnedByCurrentUser(result as Report); - result.iouReportAmount = ReportUtils.getMoneyRequestTotal(result as Report); + result.iouReportAmount = ReportUtils.getMoneyRequestSpendBreakdown(result as Report).totalDisplaySpend; if (!hasMultipleParticipants) { result.accountID = personalDetail.accountID; From fbda64af9d2a0711853e73fa7aa6835915a6bcbd Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Fri, 26 Jan 2024 09:51:28 -0700 Subject: [PATCH 6/6] fix conflict --- 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 de465b02ca95..e570fdbd34a4 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -4593,7 +4593,7 @@ function canBeAutoReimbursed(report: OnyxEntry, policy: OnyxEntry