From 2ff840c510301816b86597bd3f32623df3bc1af4 Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Fri, 5 Apr 2024 15:40:09 +0800 Subject: [PATCH 1/3] disable pay button when the iou report currency is different than poliyc currency --- src/components/MoneyReportHeader.tsx | 4 ++-- src/components/ReportActionItem/MoneyReportView.tsx | 2 +- src/components/ReportActionItem/ReportPreview.tsx | 2 +- src/libs/ReportUtils.ts | 9 +++++---- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/components/MoneyReportHeader.tsx b/src/components/MoneyReportHeader.tsx index d36c8c43d322..d70d8a16cb60 100644 --- a/src/components/MoneyReportHeader.tsx +++ b/src/components/MoneyReportHeader.tsx @@ -77,7 +77,7 @@ function MoneyReportHeader({session, policy, chatReport, nextStep, report: money const [isHoldMenuVisible, setIsHoldMenuVisible] = useState(false); const [paymentType, setPaymentType] = useState(); const [requestType, setRequestType] = useState<'pay' | 'approve'>(); - const canAllowSettlement = ReportUtils.hasUpdatedTotal(moneyRequestReport); + const canAllowSettlement = ReportUtils.hasUpdatedTotal(moneyRequestReport, policy); const policyType = policy?.type; const isPayer = ReportUtils.isPayer(session, moneyRequestReport); const isDraft = ReportUtils.isOpenExpenseReport(moneyRequestReport); @@ -106,7 +106,7 @@ function MoneyReportHeader({session, policy, chatReport, nextStep, report: money const shouldShowAnyButton = shouldShowSettlementButton || shouldShowApproveButton || shouldShowSubmitButton || shouldShowNextStep; const bankAccountRoute = ReportUtils.getBankAccountRoute(chatReport); const formattedAmount = CurrencyUtils.convertToDisplayString(reimbursableSpend, moneyRequestReport.currency); - const [nonHeldAmount, fullAmount] = ReportUtils.getNonHeldAndFullAmount(moneyRequestReport); + const [nonHeldAmount, fullAmount] = ReportUtils.getNonHeldAndFullAmount(moneyRequestReport, policy); const displayedAmount = ReportUtils.hasHeldExpenses(moneyRequestReport.reportID) && canAllowSettlement ? nonHeldAmount : formattedAmount; const isMoreContentShown = shouldShowNextStep || (shouldShowAnyButton && isSmallScreenWidth); diff --git a/src/components/ReportActionItem/MoneyReportView.tsx b/src/components/ReportActionItem/MoneyReportView.tsx index a1a9c6c747a1..6083370f7c11 100644 --- a/src/components/ReportActionItem/MoneyReportView.tsx +++ b/src/components/ReportActionItem/MoneyReportView.tsx @@ -40,7 +40,7 @@ function MoneyReportView({report, policy, shouldShowHorizontalRule}: MoneyReport const {translate} = useLocalize(); const {isSmallScreenWidth} = useWindowDimensions(); const isSettled = ReportUtils.isSettled(report.reportID); - const isTotalUpdated = ReportUtils.hasUpdatedTotal(report); + const isTotalUpdated = ReportUtils.hasUpdatedTotal(report, policy); const {totalDisplaySpend, nonReimbursableSpend, reimbursableSpend} = ReportUtils.getMoneyRequestSpendBreakdown(report); diff --git a/src/components/ReportActionItem/ReportPreview.tsx b/src/components/ReportActionItem/ReportPreview.tsx index efe0b71b1012..190343e48abd 100644 --- a/src/components/ReportActionItem/ReportPreview.tsx +++ b/src/components/ReportActionItem/ReportPreview.tsx @@ -128,7 +128,7 @@ function ReportPreview({ const isOpenExpenseReport = isPolicyExpenseChat && ReportUtils.isOpenExpenseReport(iouReport); const isApproved = ReportUtils.isReportApproved(iouReport); - const canAllowSettlement = ReportUtils.hasUpdatedTotal(iouReport); + const canAllowSettlement = ReportUtils.hasUpdatedTotal(iouReport, policy); const allTransactions = TransactionUtils.getAllReportTransactions(iouReportID); const transactionsWithReceipts = ReportUtils.getTransactionsWithReceipts(iouReportID); const numberOfScanningReceipts = transactionsWithReceipts.filter((transaction) => TransactionUtils.isReceiptBeingScanned(transaction)).length; diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index fec64efaac7f..a93e85c15ce2 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -5473,7 +5473,7 @@ function shouldDisplayThreadReplies(reportAction: OnyxEntry, repor /** * Check if money report has any transactions updated optimistically */ -function hasUpdatedTotal(report: OnyxEntry): boolean { +function hasUpdatedTotal(report: OnyxEntry, policy: OnyxEntry): boolean { if (!report) { return true; } @@ -5481,18 +5481,19 @@ function hasUpdatedTotal(report: OnyxEntry): boolean { const transactions = TransactionUtils.getAllReportTransactions(report.reportID); const hasPendingTransaction = transactions.some((transaction) => !!transaction.pendingAction); const hasTransactionWithDifferentCurrency = transactions.some((transaction) => transaction.currency !== report.currency); + const hasDifferentCurrencyWithWorkspace = report.pendingFields?.createChat && isExpenseReport(report) && report.currency !== policy?.outputCurrency - return !(hasPendingTransaction && hasTransactionWithDifferentCurrency) && !(hasHeldExpenses(report.reportID) && report?.unheldTotal === undefined); + return !(hasPendingTransaction && (hasTransactionWithDifferentCurrency || hasDifferentCurrencyWithWorkspace)) && !(hasHeldExpenses(report.reportID) && report?.unheldTotal === undefined); } /** * Return held and full amount formatted with used currency */ -function getNonHeldAndFullAmount(iouReport: OnyxEntry): string[] { +function getNonHeldAndFullAmount(iouReport: OnyxEntry, policy: OnyxEntry): string[] { const transactions = TransactionUtils.getAllReportTransactions(iouReport?.reportID ?? ''); const hasPendingTransaction = transactions.some((transaction) => !!transaction.pendingAction); - if (hasUpdatedTotal(iouReport) && hasPendingTransaction) { + 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 ?? '')]; From 096ce744103f691f516b055e70d0da4b8b623359 Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Fri, 5 Apr 2024 16:10:53 +0800 Subject: [PATCH 2/3] prettier --- 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 a93e85c15ce2..b4b00390a0f2 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -5481,7 +5481,7 @@ function hasUpdatedTotal(report: OnyxEntry, policy: OnyxEntry): const transactions = TransactionUtils.getAllReportTransactions(report.reportID); const hasPendingTransaction = transactions.some((transaction) => !!transaction.pendingAction); const hasTransactionWithDifferentCurrency = transactions.some((transaction) => transaction.currency !== report.currency); - const hasDifferentCurrencyWithWorkspace = report.pendingFields?.createChat && isExpenseReport(report) && report.currency !== policy?.outputCurrency + const hasDifferentCurrencyWithWorkspace = report.pendingFields?.createChat && isExpenseReport(report) && report.currency !== policy?.outputCurrency; return !(hasPendingTransaction && (hasTransactionWithDifferentCurrency || hasDifferentCurrencyWithWorkspace)) && !(hasHeldExpenses(report.reportID) && report?.unheldTotal === undefined); } From a1e134eb1c589d4c3c292c9e760c3535bf977eab Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Mon, 8 Apr 2024 23:37:50 +0800 Subject: [PATCH 3/3] update variable name --- src/libs/ReportUtils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index b4b00390a0f2..3404c64120cd 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -5481,9 +5481,9 @@ function hasUpdatedTotal(report: OnyxEntry, policy: OnyxEntry): const transactions = TransactionUtils.getAllReportTransactions(report.reportID); const hasPendingTransaction = transactions.some((transaction) => !!transaction.pendingAction); const hasTransactionWithDifferentCurrency = transactions.some((transaction) => transaction.currency !== report.currency); - const hasDifferentCurrencyWithWorkspace = report.pendingFields?.createChat && isExpenseReport(report) && report.currency !== policy?.outputCurrency; + const hasDifferentWorkspaceCurrency = report.pendingFields?.createChat && isExpenseReport(report) && report.currency !== policy?.outputCurrency; - return !(hasPendingTransaction && (hasTransactionWithDifferentCurrency || hasDifferentCurrencyWithWorkspace)) && !(hasHeldExpenses(report.reportID) && report?.unheldTotal === undefined); + return !(hasPendingTransaction && (hasTransactionWithDifferentCurrency || hasDifferentWorkspaceCurrency)) && !(hasHeldExpenses(report.reportID) && report?.unheldTotal === undefined); } /**