diff --git a/src/components/MoneyReportHeader.tsx b/src/components/MoneyReportHeader.tsx index 5209ab894828..0c478e125def 100644 --- a/src/components/MoneyReportHeader.tsx +++ b/src/components/MoneyReportHeader.tsx @@ -54,6 +54,7 @@ function MoneyReportHeader({session, policy, chatReport, nextStep, report: money const {reimbursableSpend} = ReportUtils.getMoneyRequestSpendBreakdown(moneyRequestReport); const isApproved = ReportUtils.isReportApproved(moneyRequestReport); const isSettled = ReportUtils.isSettled(moneyRequestReport.reportID); + const canAllowSettlement = ReportUtils.hasUpdatedTotal(moneyRequestReport); const policyType = policy?.type; const isPolicyAdmin = policyType !== CONST.POLICY.TYPE.PERSONAL && policy?.role === CONST.POLICY.ROLE.ADMIN; const isAutoReimbursable = ReportUtils.canBeAutoReimbursed(moneyRequestReport, policy); @@ -140,6 +141,7 @@ function MoneyReportHeader({session, policy, chatReport, nextStep, report: money shouldShowApproveButton={shouldShowApproveButton} style={[styles.pv2]} formattedAmount={formattedAmount} + isDisabled={!canAllowSettlement} /> )} @@ -171,6 +173,7 @@ function MoneyReportHeader({session, policy, chatReport, nextStep, report: money shouldHidePaymentOptions={!shouldShowPayButton} shouldShowApproveButton={shouldShowApproveButton} formattedAmount={formattedAmount} + isDisabled={!canAllowSettlement} /> )} diff --git a/src/components/ReportActionItem/MoneyReportView.tsx b/src/components/ReportActionItem/MoneyReportView.tsx index 3c0e50b2c940..e2021360c11a 100644 --- a/src/components/ReportActionItem/MoneyReportView.tsx +++ b/src/components/ReportActionItem/MoneyReportView.tsx @@ -44,6 +44,7 @@ function MoneyReportView({report, policy, policyReportFields, shouldShowHorizont const {isSmallScreenWidth} = useWindowDimensions(); const {canUseReportFields} = usePermissions(); const isSettled = ReportUtils.isSettled(report.reportID); + const isTotalUpdated = ReportUtils.hasUpdatedTotal(report); const {totalDisplaySpend, nonReimbursableSpend, reimbursableSpend} = ReportUtils.getMoneyRequestSpendBreakdown(report); @@ -119,7 +120,7 @@ function MoneyReportView({report, policy, policyReportFields, shouldShowHorizont )} {formattedTotalAmount} diff --git a/src/components/ReportActionItem/ReportPreview.tsx b/src/components/ReportActionItem/ReportPreview.tsx index bdb3bbd2bb33..13c9d547ea57 100644 --- a/src/components/ReportActionItem/ReportPreview.tsx +++ b/src/components/ReportActionItem/ReportPreview.tsx @@ -130,9 +130,11 @@ function ReportPreview({ const isDraftExpenseReport = isPolicyExpenseChat && ReportUtils.isDraftExpenseReport(iouReport); const isApproved = ReportUtils.isReportApproved(iouReport); + const canAllowSettlement = ReportUtils.hasUpdatedTotal(iouReport); const isMoneyRequestReport = ReportUtils.isMoneyRequestReport(iouReport); const transactionsWithReceipts = ReportUtils.getTransactionsWithReceipts(iouReportID); const numberOfScanningReceipts = transactionsWithReceipts.filter((transaction) => TransactionUtils.isReceiptBeingScanned(transaction)).length; + const hasReceipts = transactionsWithReceipts.length > 0; const isScanning = hasReceipts && areAllRequestsBeingSmartScanned; const hasErrors = (hasReceipts && hasMissingSmartscanFields) || (canUseViolations && ReportUtils.hasViolations(iouReportID, transactionViolations)); @@ -307,6 +309,7 @@ function ReportPreview({ horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.RIGHT, vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.BOTTOM, }} + isDisabled={!canAllowSettlement} /> )} {shouldShowSubmitButton && ( diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 568ce49ff961..c3de0f9f749f 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -4648,6 +4648,21 @@ function shouldDisplayThreadReplies(reportAction: OnyxEntry, repor return hasReplies && !!reportAction?.childCommenterCount && !isThreadFirstChat(reportAction, reportID); } +/** + * Check if money report has any transactions updated optimistically + */ +function hasUpdatedTotal(report: OnyxEntry): boolean { + if (!report) { + return true; + } + + const transactions = TransactionUtils.getAllReportTransactions(report.reportID); + const hasPendingTransaction = transactions.some((transaction) => !!transaction.pendingAction); + const hasTransactionWithDifferentCurrency = transactions.some((transaction) => transaction.currency !== report.currency); + + return !(hasPendingTransaction && hasTransactionWithDifferentCurrency); +} + /** * Disable reply in thread action if: * @@ -4946,6 +4961,7 @@ export { isReportParticipant, isValidReport, isReportFieldOfTypeTitle, + hasUpdatedTotal, isReportFieldDisabled, getAvailableReportFields, getAllAncestorReportActionIDs,