Skip to content

Commit

Permalink
Merge pull request #53304 from Expensify/lucien/fix-search-bulkAction…
Browse files Browse the repository at this point in the history
…-pay

(cherry picked from commit 0a51ff8)

(CP triggered by mountiny)
  • Loading branch information
mountiny authored and OSBotify committed Nov 29, 2024
1 parent 62f3f46 commit 8d3f3fb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
22 changes: 22 additions & 0 deletions src/components/Search/SearchPageHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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]}))
Expand Down
2 changes: 1 addition & 1 deletion src/components/Search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
};
}
Expand Down
6 changes: 6 additions & 0 deletions src/libs/PolicyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -1186,6 +1191,7 @@ export {
canSendInvoice,
hasWorkspaceWithInvoices,
hasDependentTags,
hasVBBA,
getXeroTenants,
findCurrentXeroOrganization,
getCurrentXeroOrganizationName,
Expand Down

0 comments on commit 8d3f3fb

Please sign in to comment.