From f227a8436f3d8fa0051a50bb4f1129ffaabca495 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Wed, 13 Mar 2024 12:43:29 -0600 Subject: [PATCH 01/13] fix pay button show conditions --- src/libs/ReportUtils.ts | 2 +- src/libs/actions/IOU.ts | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 8dc1c9967f13..30ae15610744 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1271,7 +1271,7 @@ function isPayer(session: OnyxEntry, iouReport: OnyxEntry) { if (isPaidGroupPolicy(iouReport)) { if (policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_YES) { const isReimburser = session?.email === policy?.reimburserEmail; - return isReimburser && (isApproved || isManager); + return (!policy?.reimburserEmail || isReimburser) && (isApproved || isManager); } if (policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_MANUAL) { return isAdmin && (isApproved || isManager); diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index af5c40836c74..450d6a38eed4 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -3666,6 +3666,10 @@ function canIOUBePaid(iouReport: OnyxEntry | EmptyObject, chat return false; } + if (policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_NO) { + return false; + } + const isPayer = ReportUtils.isPayer( { email: currentUserEmail, From 44c4842f5e50e71c261333ecc2890a08344e8460 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Wed, 13 Mar 2024 13:21:08 -0600 Subject: [PATCH 02/13] fix more conditionals --- src/components/SettlementButton.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/components/SettlementButton.tsx b/src/components/SettlementButton.tsx index 6b6ad3af737a..6f5b507eda9e 100644 --- a/src/components/SettlementButton.tsx +++ b/src/components/SettlementButton.tsx @@ -135,13 +135,12 @@ function SettlementButton({ PaymentMethods.openWalletPage(); }, []); - const policy = ReportUtils.getPolicy(policyID); const session = useSession(); const chatReport = ReportUtils.getReport(chatReportID); const isPaidGroupPolicy = ReportUtils.isPaidGroupPolicyExpenseChat(chatReport as OnyxEntry); const shouldShowPaywithExpensifyOption = !isPaidGroupPolicy || - (!shouldHidePaymentOptions && policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_YES && policy?.reimburserEmail === session?.email); + (!shouldHidePaymentOptions && ReportUtils.isPayer(session, iouReport as OnyxEntry)); const paymentButtonOptions = useMemo(() => { const buttonOptions = []; const isExpenseReport = ReportUtils.isExpenseReport(iouReport); From facdc0ad01f293deca2825bcc2c06b78820ef6db Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Wed, 13 Mar 2024 13:25:37 -0600 Subject: [PATCH 03/13] add manul reimburse case --- src/components/SettlementButton.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/components/SettlementButton.tsx b/src/components/SettlementButton.tsx index 6f5b507eda9e..5a9cd637dcab 100644 --- a/src/components/SettlementButton.tsx +++ b/src/components/SettlementButton.tsx @@ -135,6 +135,7 @@ function SettlementButton({ PaymentMethods.openWalletPage(); }, []); + const policy = ReportUtils.getPolicy(policyID); const session = useSession(); const chatReport = ReportUtils.getReport(chatReportID); const isPaidGroupPolicy = ReportUtils.isPaidGroupPolicyExpenseChat(chatReport as OnyxEntry); @@ -183,7 +184,9 @@ function SettlementButton({ if (isExpenseReport && shouldShowPaywithExpensifyOption) { buttonOptions.push(paymentMethods[CONST.IOU.PAYMENT_TYPE.VBBA]); } - buttonOptions.push(paymentMethods[CONST.IOU.PAYMENT_TYPE.ELSEWHERE]); + if (isExpenseReport && policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_MANUAL) { + buttonOptions.push(paymentMethods[CONST.IOU.PAYMENT_TYPE.ELSEWHERE]); + } if (shouldShowApproveButton) { buttonOptions.push(approveButtonOption); From 8dc39a9d9d7e0b330b872dbd86fb1b69561fba43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucien=20Akchot=C3=A9?= Date: Thu, 21 Mar 2024 10:39:55 +0100 Subject: [PATCH 04/13] do not show approve button if approvals disabled --- src/components/ReportActionItem/ReportPreview.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/components/ReportActionItem/ReportPreview.tsx b/src/components/ReportActionItem/ReportPreview.tsx index d183d27fefb8..ebc4e0b31486 100644 --- a/src/components/ReportActionItem/ReportPreview.tsx +++ b/src/components/ReportActionItem/ReportPreview.tsx @@ -207,8 +207,7 @@ function ReportPreview({ const shouldShowPayButton = useMemo(() => IOU.canIOUBePaid(iouReport, chatReport, policy), [iouReport, chatReport, policy]); - const shouldShowApproveButton = useMemo(() => IOU.canApproveIOU(iouReport, chatReport, policy), [iouReport, chatReport, policy]); - + const shouldShowApproveButton = useMemo(() => IOU.canApproveIOU(iouReport, chatReport, policy) && policy?.approvalMode !== CONST.POLICY.APPROVAL_MODE.OPTIONAL, [iouReport, chatReport, policy]); const shouldShowSettlementButton = shouldShowPayButton || shouldShowApproveButton; const shouldPromptUserToAddBankAccount = ReportUtils.hasMissingPaymentMethod(userWallet, iouReportID); From 71c5bdb3babe341eb0114d6ff570e49360840da5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucien=20Akchot=C3=A9?= Date: Thu, 21 Mar 2024 11:07:16 +0100 Subject: [PATCH 05/13] modify isAutoReimbursable to show pay button to be congruent with nextStepUtils step waiting for pay --- 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 b65d81a228ef..f5944d3407f8 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -4510,7 +4510,7 @@ function canIOUBePaid(iouReport: OnyxEntry | EmptyObject, chat const iouSettled = ReportUtils.isSettled(iouReport?.reportID); const {reimbursableSpend} = ReportUtils.getMoneyRequestSpendBreakdown(iouReport); - const isAutoReimbursable = ReportUtils.canBeAutoReimbursed(iouReport, policy); + const isAutoReimbursable = policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_YES ? false : ReportUtils.canBeAutoReimbursed(iouReport, policy); return isPayer && !isOpenExpenseReport && !iouSettled && !iouReport?.isWaitingOnBankAccount && reimbursableSpend !== 0 && !iouCanceled && !isAutoReimbursable; } From 9a1a1605560425ea720ad994e1c4e1a49fb6e437 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucien=20Akchot=C3=A9?= Date: Thu, 21 Mar 2024 11:07:32 +0100 Subject: [PATCH 06/13] do not show approve button if approvals disabled --- src/components/MoneyReportHeader.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/MoneyReportHeader.tsx b/src/components/MoneyReportHeader.tsx index 2bf346ec8de4..55f40bc2bfa8 100644 --- a/src/components/MoneyReportHeader.tsx +++ b/src/components/MoneyReportHeader.tsx @@ -65,7 +65,7 @@ function MoneyReportHeader({session, policy, chatReport, nextStep, report: money const shouldShowPayButton = useMemo(() => IOU.canIOUBePaid(moneyRequestReport, chatReport, policy), [moneyRequestReport, chatReport, policy]); - const shouldShowApproveButton = useMemo(() => IOU.canApproveIOU(moneyRequestReport, chatReport, policy), [moneyRequestReport, chatReport, policy]); + const shouldShowApproveButton = useMemo(() => IOU.canApproveIOU(moneyRequestReport, chatReport, policy) && policy?.approvalMode !== CONST.POLICY.APPROVAL_MODE.OPTIONAL, [moneyRequestReport, chatReport, policy]); const shouldShowSettlementButton = shouldShowPayButton || shouldShowApproveButton; From d9fa855480b5985134a3e2520bd41a3f6fd84ab3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucien=20Akchot=C3=A9?= Date: Thu, 21 Mar 2024 12:13:50 +0100 Subject: [PATCH 07/13] handle delay submissions and approvals enabled scenario --- src/libs/actions/IOU.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index f5944d3407f8..2af9a63c89e5 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -4511,7 +4511,12 @@ function canIOUBePaid(iouReport: OnyxEntry | EmptyObject, chat const {reimbursableSpend} = ReportUtils.getMoneyRequestSpendBreakdown(iouReport); const isAutoReimbursable = policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_YES ? false : ReportUtils.canBeAutoReimbursed(iouReport, policy); - return isPayer && !isOpenExpenseReport && !iouSettled && !iouReport?.isWaitingOnBankAccount && reimbursableSpend !== 0 && !iouCanceled && !isAutoReimbursable; + let shouldBeApproved = false; + if (policy?.approvalMode !== CONST.POLICY.APPROVAL_MODE.OPTIONAL && iouReport.statusNum === CONST.REPORT.STATUS_NUM.SUBMITTED) { + shouldBeApproved = true; + } + + return isPayer && !isOpenExpenseReport && !iouSettled && !iouReport?.isWaitingOnBankAccount && reimbursableSpend !== 0 && !iouCanceled && !isAutoReimbursable && !shouldBeApproved; } function canApproveIOU(iouReport: OnyxEntry | EmptyObject, chatReport: OnyxEntry | EmptyObject, policy: OnyxEntry | EmptyObject) { From 3f3d761cb7b15e7876430302ef01dbf03df3d68c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucien=20Akchot=C3=A9?= Date: Thu, 21 Mar 2024 14:08:55 +0100 Subject: [PATCH 08/13] fix style --- src/components/MoneyReportHeader.tsx | 5 ++++- src/components/ReportActionItem/ReportPreview.tsx | 5 ++++- src/components/SettlementButton.tsx | 4 +--- src/libs/actions/IOU.ts | 2 +- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/components/MoneyReportHeader.tsx b/src/components/MoneyReportHeader.tsx index 55f40bc2bfa8..31182cd5ec5e 100644 --- a/src/components/MoneyReportHeader.tsx +++ b/src/components/MoneyReportHeader.tsx @@ -65,7 +65,10 @@ function MoneyReportHeader({session, policy, chatReport, nextStep, report: money const shouldShowPayButton = useMemo(() => IOU.canIOUBePaid(moneyRequestReport, chatReport, policy), [moneyRequestReport, chatReport, policy]); - const shouldShowApproveButton = useMemo(() => IOU.canApproveIOU(moneyRequestReport, chatReport, policy) && policy?.approvalMode !== CONST.POLICY.APPROVAL_MODE.OPTIONAL, [moneyRequestReport, chatReport, policy]); + const shouldShowApproveButton = useMemo( + () => IOU.canApproveIOU(moneyRequestReport, chatReport, policy) && policy?.approvalMode !== CONST.POLICY.APPROVAL_MODE.OPTIONAL, + [moneyRequestReport, chatReport, policy], + ); const shouldShowSettlementButton = shouldShowPayButton || shouldShowApproveButton; diff --git a/src/components/ReportActionItem/ReportPreview.tsx b/src/components/ReportActionItem/ReportPreview.tsx index ebc4e0b31486..036c7466dde0 100644 --- a/src/components/ReportActionItem/ReportPreview.tsx +++ b/src/components/ReportActionItem/ReportPreview.tsx @@ -207,7 +207,10 @@ function ReportPreview({ const shouldShowPayButton = useMemo(() => IOU.canIOUBePaid(iouReport, chatReport, policy), [iouReport, chatReport, policy]); - const shouldShowApproveButton = useMemo(() => IOU.canApproveIOU(iouReport, chatReport, policy) && policy?.approvalMode !== CONST.POLICY.APPROVAL_MODE.OPTIONAL, [iouReport, chatReport, policy]); + const shouldShowApproveButton = useMemo( + () => IOU.canApproveIOU(iouReport, chatReport, policy) && policy?.approvalMode !== CONST.POLICY.APPROVAL_MODE.OPTIONAL, + [iouReport, chatReport, policy], + ); const shouldShowSettlementButton = shouldShowPayButton || shouldShowApproveButton; const shouldPromptUserToAddBankAccount = ReportUtils.hasMissingPaymentMethod(userWallet, iouReportID); diff --git a/src/components/SettlementButton.tsx b/src/components/SettlementButton.tsx index 5a9cd637dcab..c6c3125aa02b 100644 --- a/src/components/SettlementButton.tsx +++ b/src/components/SettlementButton.tsx @@ -139,9 +139,7 @@ function SettlementButton({ const session = useSession(); const chatReport = ReportUtils.getReport(chatReportID); const isPaidGroupPolicy = ReportUtils.isPaidGroupPolicyExpenseChat(chatReport as OnyxEntry); - const shouldShowPaywithExpensifyOption = - !isPaidGroupPolicy || - (!shouldHidePaymentOptions && ReportUtils.isPayer(session, iouReport as OnyxEntry)); + const shouldShowPaywithExpensifyOption = !isPaidGroupPolicy || (!shouldHidePaymentOptions && ReportUtils.isPayer(session, iouReport as OnyxEntry)); const paymentButtonOptions = useMemo(() => { const buttonOptions = []; const isExpenseReport = ReportUtils.isExpenseReport(iouReport); diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 2af9a63c89e5..114ed1ba70b6 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -4515,7 +4515,7 @@ function canIOUBePaid(iouReport: OnyxEntry | EmptyObject, chat if (policy?.approvalMode !== CONST.POLICY.APPROVAL_MODE.OPTIONAL && iouReport.statusNum === CONST.REPORT.STATUS_NUM.SUBMITTED) { shouldBeApproved = true; } - + return isPayer && !isOpenExpenseReport && !iouSettled && !iouReport?.isWaitingOnBankAccount && reimbursableSpend !== 0 && !iouCanceled && !isAutoReimbursable && !shouldBeApproved; } From 2319ff58fddc3e6fa98db4e7f16623413b334bfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucien=20Akchot=C3=A9?= Date: Thu, 21 Mar 2024 15:26:20 +0100 Subject: [PATCH 09/13] improve code --- src/components/MoneyReportHeader.tsx | 2 +- src/components/ReportActionItem/ReportPreview.tsx | 2 +- src/libs/actions/IOU.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/MoneyReportHeader.tsx b/src/components/MoneyReportHeader.tsx index 31182cd5ec5e..0dfd48ffc660 100644 --- a/src/components/MoneyReportHeader.tsx +++ b/src/components/MoneyReportHeader.tsx @@ -66,7 +66,7 @@ function MoneyReportHeader({session, policy, chatReport, nextStep, report: money const shouldShowPayButton = useMemo(() => IOU.canIOUBePaid(moneyRequestReport, chatReport, policy), [moneyRequestReport, chatReport, policy]); const shouldShowApproveButton = useMemo( - () => IOU.canApproveIOU(moneyRequestReport, chatReport, policy) && policy?.approvalMode !== CONST.POLICY.APPROVAL_MODE.OPTIONAL, + () => IOU.canApproveIOU(moneyRequestReport, chatReport, policy), [moneyRequestReport, chatReport, policy], ); diff --git a/src/components/ReportActionItem/ReportPreview.tsx b/src/components/ReportActionItem/ReportPreview.tsx index 036c7466dde0..8af227d28725 100644 --- a/src/components/ReportActionItem/ReportPreview.tsx +++ b/src/components/ReportActionItem/ReportPreview.tsx @@ -208,7 +208,7 @@ function ReportPreview({ const shouldShowPayButton = useMemo(() => IOU.canIOUBePaid(iouReport, chatReport, policy), [iouReport, chatReport, policy]); const shouldShowApproveButton = useMemo( - () => IOU.canApproveIOU(iouReport, chatReport, policy) && policy?.approvalMode !== CONST.POLICY.APPROVAL_MODE.OPTIONAL, + () => IOU.canApproveIOU(iouReport, chatReport, policy), [iouReport, chatReport, policy], ); const shouldShowSettlementButton = shouldShowPayButton || shouldShowApproveButton; diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 114ed1ba70b6..976a3c293c27 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -4512,7 +4512,7 @@ function canIOUBePaid(iouReport: OnyxEntry | EmptyObject, chat const {reimbursableSpend} = ReportUtils.getMoneyRequestSpendBreakdown(iouReport); const isAutoReimbursable = policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_YES ? false : ReportUtils.canBeAutoReimbursed(iouReport, policy); let shouldBeApproved = false; - if (policy?.approvalMode !== CONST.POLICY.APPROVAL_MODE.OPTIONAL && iouReport.statusNum === CONST.REPORT.STATUS_NUM.SUBMITTED) { + if (iouReport.statusNum === CONST.REPORT.STATUS_NUM.SUBMITTED || iouReport.stateNum === CONST.REPORT.STATE_NUM.SUBMITTED) { shouldBeApproved = true; } From 55c3fb26be0d18a26b5e8bd457ec3cc0b41d6a1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucien=20Akchot=C3=A9?= Date: Thu, 21 Mar 2024 15:27:20 +0100 Subject: [PATCH 10/13] fix style --- src/components/MoneyReportHeader.tsx | 5 +---- src/components/ReportActionItem/ReportPreview.tsx | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/components/MoneyReportHeader.tsx b/src/components/MoneyReportHeader.tsx index 0dfd48ffc660..2bf346ec8de4 100644 --- a/src/components/MoneyReportHeader.tsx +++ b/src/components/MoneyReportHeader.tsx @@ -65,10 +65,7 @@ function MoneyReportHeader({session, policy, chatReport, nextStep, report: money const shouldShowPayButton = useMemo(() => IOU.canIOUBePaid(moneyRequestReport, chatReport, policy), [moneyRequestReport, chatReport, policy]); - const shouldShowApproveButton = useMemo( - () => IOU.canApproveIOU(moneyRequestReport, chatReport, policy), - [moneyRequestReport, chatReport, policy], - ); + const shouldShowApproveButton = useMemo(() => IOU.canApproveIOU(moneyRequestReport, chatReport, policy), [moneyRequestReport, chatReport, policy]); const shouldShowSettlementButton = shouldShowPayButton || shouldShowApproveButton; diff --git a/src/components/ReportActionItem/ReportPreview.tsx b/src/components/ReportActionItem/ReportPreview.tsx index 8af227d28725..216eb84016ab 100644 --- a/src/components/ReportActionItem/ReportPreview.tsx +++ b/src/components/ReportActionItem/ReportPreview.tsx @@ -207,10 +207,7 @@ function ReportPreview({ const shouldShowPayButton = useMemo(() => IOU.canIOUBePaid(iouReport, chatReport, policy), [iouReport, chatReport, policy]); - const shouldShowApproveButton = useMemo( - () => IOU.canApproveIOU(iouReport, chatReport, policy), - [iouReport, chatReport, policy], - ); + const shouldShowApproveButton = useMemo(() => IOU.canApproveIOU(iouReport, chatReport, policy), [iouReport, chatReport, policy]); const shouldShowSettlementButton = shouldShowPayButton || shouldShowApproveButton; const shouldPromptUserToAddBankAccount = ReportUtils.hasMissingPaymentMethod(userWallet, iouReportID); From ebce13b4df9dea9715c6e44d31d87c1814c383cd Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Thu, 21 Mar 2024 18:02:26 -0600 Subject: [PATCH 11/13] rm unnecessary change --- src/components/ReportActionItem/ReportPreview.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/ReportActionItem/ReportPreview.tsx b/src/components/ReportActionItem/ReportPreview.tsx index 216eb84016ab..d183d27fefb8 100644 --- a/src/components/ReportActionItem/ReportPreview.tsx +++ b/src/components/ReportActionItem/ReportPreview.tsx @@ -208,6 +208,7 @@ function ReportPreview({ const shouldShowPayButton = useMemo(() => IOU.canIOUBePaid(iouReport, chatReport, policy), [iouReport, chatReport, policy]); const shouldShowApproveButton = useMemo(() => IOU.canApproveIOU(iouReport, chatReport, policy), [iouReport, chatReport, policy]); + const shouldShowSettlementButton = shouldShowPayButton || shouldShowApproveButton; const shouldPromptUserToAddBankAccount = ReportUtils.hasMissingPaymentMethod(userWallet, iouReportID); From 432195f992ce4353f621f53d8ee6c73ab50ddbf1 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Fri, 22 Mar 2024 15:22:00 -0600 Subject: [PATCH 12/13] fix iou, free policy pay --- src/libs/actions/IOU.ts | 57 +++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 30 deletions(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 93f5407f3566..5632268ef6ca 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -4484,6 +4484,32 @@ function sendMoneyWithWallet(report: OnyxTypes.Report, amount: number, currency: Report.notifyNewAction(params.chatReportID, managerID); } +function canApproveIOU(iouReport: OnyxEntry | EmptyObject, chatReport: OnyxEntry | EmptyObject, policy: OnyxEntry | EmptyObject) { + if (isEmptyObject(chatReport)) { + return false; + } + const isPaidGroupPolicy = ReportUtils.isPaidGroupPolicyExpenseChat(chatReport); + if (!isPaidGroupPolicy) { + return false; + } + + const isOnInstantSubmitPolicy = PolicyUtils.isInstantSubmitEnabled(policy); + const isOnSubmitAndClosePolicy = PolicyUtils.isSubmitAndClose(policy); + if (isOnInstantSubmitPolicy && isOnSubmitAndClosePolicy) { + return false; + } + + const managerID = iouReport?.managerID ?? 0; + const isCurrentUserManager = managerID === userAccountID; + const isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(chatReport); + + const isOpenExpenseReport = isPolicyExpenseChat && ReportUtils.isOpenExpenseReport(iouReport); + const isApproved = ReportUtils.isReportApproved(iouReport); + const iouSettled = ReportUtils.isSettled(iouReport?.reportID); + + return isCurrentUserManager && !isOpenExpenseReport && !isApproved && !iouSettled; +} + function canIOUBePaid(iouReport: OnyxEntry | EmptyObject, chatReport: OnyxEntry | EmptyObject, policy: OnyxEntry | EmptyObject) { const isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(chatReport); const iouCanceled = ReportUtils.isArchivedRoom(chatReport); @@ -4509,40 +4535,11 @@ function canIOUBePaid(iouReport: OnyxEntry | EmptyObject, chat const {reimbursableSpend} = ReportUtils.getMoneyRequestSpendBreakdown(iouReport); const isAutoReimbursable = policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_YES ? false : ReportUtils.canBeAutoReimbursed(iouReport, policy); - let shouldBeApproved = false; - if (iouReport.statusNum === CONST.REPORT.STATUS_NUM.SUBMITTED || iouReport.stateNum === CONST.REPORT.STATE_NUM.SUBMITTED) { - shouldBeApproved = true; - } + const shouldBeApproved = canApproveIOU(iouReport, chatReport, policy); return isPayer && !isOpenExpenseReport && !iouSettled && !iouReport?.isWaitingOnBankAccount && reimbursableSpend !== 0 && !iouCanceled && !isAutoReimbursable && !shouldBeApproved; } -function canApproveIOU(iouReport: OnyxEntry | EmptyObject, chatReport: OnyxEntry | EmptyObject, policy: OnyxEntry | EmptyObject) { - if (isEmptyObject(chatReport)) { - return false; - } - const isPaidGroupPolicy = ReportUtils.isPaidGroupPolicyExpenseChat(chatReport); - if (!isPaidGroupPolicy) { - return false; - } - - const isOnInstantSubmitPolicy = PolicyUtils.isInstantSubmitEnabled(policy); - const isOnSubmitAndClosePolicy = PolicyUtils.isSubmitAndClose(policy); - if (isOnInstantSubmitPolicy && isOnSubmitAndClosePolicy) { - return false; - } - - const managerID = iouReport?.managerID ?? 0; - const isCurrentUserManager = managerID === userAccountID; - const isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(chatReport); - - const isOpenExpenseReport = isPolicyExpenseChat && ReportUtils.isOpenExpenseReport(iouReport); - const isApproved = ReportUtils.isReportApproved(iouReport); - const iouSettled = ReportUtils.isSettled(iouReport?.reportID); - - return isCurrentUserManager && !isOpenExpenseReport && !isApproved && !iouSettled; -} - function hasIOUToApproveOrPay(chatReport: OnyxEntry | EmptyObject, excludedIOUReportID: string): boolean { const chatReportActions = ReportActionsUtils.getAllReportActions(chatReport?.reportID ?? ''); From 0047ad2cc9005042b064bfd2fb5b8c6d21055d66 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Fri, 22 Mar 2024 16:38:34 -0600 Subject: [PATCH 13/13] fix conditional --- src/components/SettlementButton.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/SettlementButton.tsx b/src/components/SettlementButton.tsx index 16c0b2ecaea5..690a9485f099 100644 --- a/src/components/SettlementButton.tsx +++ b/src/components/SettlementButton.tsx @@ -144,6 +144,7 @@ function SettlementButton({ const chatReport = ReportUtils.getReport(chatReportID); const isPaidGroupPolicy = ReportUtils.isPaidGroupPolicyExpenseChat(chatReport as OnyxEntry); const shouldShowPaywithExpensifyOption = !isPaidGroupPolicy || (!shouldHidePaymentOptions && ReportUtils.isPayer(session, iouReport as OnyxEntry)); + const shouldShowPayElsewhereOption = !isPaidGroupPolicy || policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_MANUAL; const paymentButtonOptions = useMemo(() => { const buttonOptions = []; const isExpenseReport = ReportUtils.isExpenseReport(iouReport); @@ -187,7 +188,7 @@ function SettlementButton({ if (isExpenseReport && shouldShowPaywithExpensifyOption) { buttonOptions.push(paymentMethods[CONST.IOU.PAYMENT_TYPE.VBBA]); } - if (isExpenseReport && policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_MANUAL) { + if (shouldShowPayElsewhereOption) { buttonOptions.push(paymentMethods[CONST.IOU.PAYMENT_TYPE.ELSEWHERE]); }