From 8d3f3fb5b86f1373fb721f0581a19a63f7efb952 Mon Sep 17 00:00:00 2001 From: Vit Horacek <36083550+mountiny@users.noreply.github.com> Date: Fri, 29 Nov 2024 17:46:54 +0100 Subject: [PATCH] Merge pull request #53304 from Expensify/lucien/fix-search-bulkAction-pay (cherry picked from commit 0a51ff8bef467e6d85ae0167e583998a588aad0f) (CP triggered by mountiny) --- src/components/Search/SearchPageHeader.tsx | 22 ++++++++++++++++++++++ src/components/Search/index.tsx | 2 +- src/libs/PolicyUtils.ts | 6 ++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/components/Search/SearchPageHeader.tsx b/src/components/Search/SearchPageHeader.tsx index f4feaef632b7..a78845f126d2 100644 --- a/src/components/Search/SearchPageHeader.tsx +++ b/src/components/Search/SearchPageHeader.tsx @@ -17,6 +17,7 @@ import useThemeStyles from '@hooks/useThemeStyles'; import * as SearchActions from '@libs/actions/Search'; import Navigation from '@libs/Navigation/Navigation'; import {getAllTaxRates} from '@libs/PolicyUtils'; +import * as PolicyUtils from '@libs/PolicyUtils'; import * as SearchQueryUtils from '@libs/SearchQueryUtils'; import SearchSelectedNarrow from '@pages/Search/SearchSelectedNarrow'; import variables from '@styles/variables'; @@ -130,7 +131,28 @@ function SearchPageHeader({queryJSON}: SearchPageHeaderProps) { setIsOfflineModalVisible(true); return; } + + const activeRoute = Navigation.getActiveRoute(); const transactionIDList = selectedReports.length ? undefined : Object.keys(selectedTransactions); + const items = selectedReports.length ? selectedReports : Object.values(selectedTransactions); + + for (const item of items) { + const policyID = item.policyID; + const lastPolicyPaymentMethod = policyID ? lastPaymentMethods?.[policyID] : null; + + if (!lastPolicyPaymentMethod) { + Navigation.navigate(ROUTES.SEARCH_REPORT.getRoute({reportID: item.reportID, backTo: activeRoute})); + return; + } + + const hasVBBA = PolicyUtils.hasVBBA(policyID); + + if (lastPolicyPaymentMethod !== CONST.IOU.PAYMENT_TYPE.ELSEWHERE && !hasVBBA) { + Navigation.navigate(ROUTES.SEARCH_REPORT.getRoute({reportID: item.reportID, backTo: activeRoute})); + return; + } + } + const paymentData = ( selectedReports.length ? selectedReports.map((report) => ({reportID: report.reportID, amount: report.total, paymentType: lastPaymentMethods[report.policyID]})) diff --git a/src/components/Search/index.tsx b/src/components/Search/index.tsx index ea712ddaafd6..0f4b5f8608c0 100644 --- a/src/components/Search/index.tsx +++ b/src/components/Search/index.tsx @@ -108,7 +108,7 @@ function prepareTransactionsList(item: TransactionListItemType, selectedTransact action: item.action, reportID: item.reportID, policyID: item.policyID, - amount: item.modifiedAmount ?? item.amount, + amount: Math.abs(item.modifiedAmount || item.amount), }, }; } diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index ab24f472cdf4..f6b277d69d6b 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -1079,6 +1079,11 @@ function getWorkspaceAccountID(policyID: string) { return policy.workspaceAccountID ?? 0; } +function hasVBBA(policyID: string) { + const policy = getPolicy(policyID); + return !!policy?.achAccount?.bankAccountID; +} + function getTagApproverRule(policyID: string, tagName: string) { const policy = getPolicy(policyID); @@ -1186,6 +1191,7 @@ export { canSendInvoice, hasWorkspaceWithInvoices, hasDependentTags, + hasVBBA, getXeroTenants, findCurrentXeroOrganization, getCurrentXeroOrganizationName,