Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ function OptionRowLHNData({
const [policyTags] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${fullReport?.policyID}`);
const [isTrackIntentUser] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED, {selector: isTrackIntentUserSelector});
const [rules] = useOnyx(ONYXKEYS.COLLECTION.RULE);
const [bankAccountList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST);

const card = useGetExpensifyCardFromReportAction({reportAction: lastAction, policyID: fullReport?.policyID});

Expand Down Expand Up @@ -178,7 +177,6 @@ function OptionRowLHNData({
isTrackIntentUser,
formatPhoneNumber,
rules,
bankAccountList,
});

// For single-sender IOUs, trim to the sender's avatar to match the header.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ function ExpenseReportListItemInner<TItem extends ListItem>({
delegateEmail,
delegateAccountID,
conciergeChat,
bankAccountList,
} = useReportPaymentContext({
chatReportPolicyID: chatReport?.policyID,
});
Expand Down Expand Up @@ -323,7 +322,6 @@ function ExpenseReportListItemInner<TItem extends ListItem>({
allViolations: liveViolationsForSnapshotTransactions,
rules,
conciergeChat,
bankAccountList,
});
}, [
currentSearchHash,
Expand Down Expand Up @@ -368,7 +366,6 @@ function ExpenseReportListItemInner<TItem extends ListItem>({
liveViolationsForSnapshotTransactions,
rules,
conciergeChat,
bankAccountList,
shouldShowMarkAsDoneCopy,
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,6 @@ function ReportListItemHeaderInner<TItem extends ListItem>({
delegateEmail,
delegateAccountID,
conciergeChat,
bankAccountList,
} = useReportPaymentContext({
chatReportPolicyID: chatReport?.policyID,
});
Expand Down Expand Up @@ -356,7 +355,6 @@ function ReportListItemHeaderInner<TItem extends ListItem>({
allViolations,
rules,
conciergeChat,
bankAccountList,
});
};
return !isLargeScreenWidth ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ function TransactionListItemInner<TItem extends ListItem>({
delegateEmail,
delegateAccountID,
conciergeChat,
bankAccountList,
} = useReportPaymentContext({
chatReportPolicyID: chatReport?.policyID,
});
Expand Down Expand Up @@ -267,7 +266,6 @@ function TransactionListItemInner<TItem extends ListItem>({
allViolations,
rules,
conciergeChat,
bankAccountList,
});
};

Expand Down
5 changes: 2 additions & 3 deletions src/components/SettlementButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import {getLastPolicyBankAccountID, getLastPolicyPaymentMethod} from '@libs/acti
import {isBankAccountPartiallySetup, showUnlockAlreadyRequestedModal} from '@libs/BankAccountUtils';
import Navigation from '@libs/Navigation/Navigation';
import {formatPaymentMethods, getActivePaymentType, getBusinessBankAccountOptions, matchesCurrency} from '@libs/PaymentUtils';
import {canAccessPolicyBankAccount} from '@libs/PolicyPaymentUtils';
import {isPaidGroupPolicy, isPolicyAdmin, sortPoliciesByName} from '@libs/PolicyUtils';
import {hasRequestFromCurrentAccount} from '@libs/ReportActionsUtils';
import {
Expand Down Expand Up @@ -152,8 +151,8 @@ function SettlementButton({
const formattedPaymentMethods = formatPaymentMethods(bankAccountList ?? {}, fundList ?? {}, styles, translate);
const hasIntentToPay =
((formattedPaymentMethods.length === 1 && isIOUReport(iouReport)) ||
(canAccessPolicyBankAccount(policy, bankAccountList) &&
(policy?.achAccount?.state === CONST.BANK_ACCOUNT.STATE.OPEN || policy?.achAccount?.state === CONST.BANK_ACCOUNT.STATE.LOCKED))) &&
policy?.achAccount?.state === CONST.BANK_ACCOUNT.STATE.OPEN ||
policy?.achAccount?.state === CONST.BANK_ACCOUNT.STATE.LOCKED) &&
!lastPaymentMethod;
const {isBetaEnabled} = usePermissions();
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED);
Expand Down
5 changes: 1 addition & 4 deletions src/hooks/usePaymentContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import {delegateEmailSelector} from '@src/selectors/Account';
import {hasSeenTourSelector} from '@src/selectors/Onboarding';
import type {BankAccountList, BillingGraceEndPeriod, IntroSelected, Policy, Report} from '@src/types/onyx';
import type {BillingGraceEndPeriod, IntroSelected, Policy, Report} from '@src/types/onyx';

import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';

Expand Down Expand Up @@ -36,7 +36,6 @@ type PaymentContextValue = {
defaultWorkspaceName: string;
delegateEmail: string | undefined;
delegateAccountID: number | undefined;
bankAccountList: OnyxEntry<BankAccountList>;
};

type ReportPaymentContextValue = PaymentContextValue & {
Expand Down Expand Up @@ -69,7 +68,6 @@ function usePaymentContextValues(): PaymentContextValue {
const [delegateEmail] = useOnyx(ONYXKEYS.ACCOUNT, {selector: delegateEmailSelector});
const delegateAccountID = useDelegateAccountID();
const activePolicy = usePolicy(activePolicyID);
const [bankAccountList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST);

const defaultWorkspaceName = generateDefaultWorkspaceName(email ?? '', displayName, lastWorkspaceNumber, translate);

Expand All @@ -91,7 +89,6 @@ function usePaymentContextValues(): PaymentContextValue {
defaultWorkspaceName,
delegateEmail,
delegateAccountID,
bankAccountList,
};
}

Expand Down
8 changes: 2 additions & 6 deletions src/hooks/useSearchBulkActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ import Navigation from '@libs/Navigation/Navigation';
import TransitionTracker from '@libs/Navigation/TransitionTracker';
import Parser from '@libs/Parser';
import {getLoginByAccountID} from '@libs/PersonalDetailsUtils';
import {canAccessPolicyBankAccount} from '@libs/PolicyPaymentUtils';
import {getConnectedIntegration, isAdminOfCardEnabledPolicy, isSubmitPolicy} from '@libs/PolicyUtils';
import {getReportAccountingExportActions, isMergeActionForSelectedTransactions} from '@libs/ReportSecondaryActionUtils';
import {
Expand Down Expand Up @@ -1036,18 +1035,15 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) {
const policyIDsWithVBBA = useMemo(() => {
const result = [];
for (const policy of Object.values(policies ?? {})) {
// Bulk pay funds from the workspace bank account when no account was picked in the menu, so a workspace only
// counts here if the workspace account is actually shared with the current user. Anyone else has to open the
// report and pick an account of their own. That includes a payer the account was never shared with.
if (!policy || !canAccessPolicyBankAccount(policy, bankAccountList)) {
if (!policy?.achAccount?.bankAccountID) {
continue;
}

result.push(policy.id);
}

return result;
}, [policies, bankAccountList]);
}, [policies]);

const exportSearchData = searchResults?.data;
const exportSearchType = searchResults?.search.type ?? queryJSON?.type;
Expand Down
61 changes: 0 additions & 61 deletions src/libs/PolicyPaymentUtils.ts

This file was deleted.

12 changes: 0 additions & 12 deletions src/libs/PolicyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -818,17 +818,6 @@ function isPolicyPayer(policy: OnyxEntry<Policy>, currentUserLogin: string | und
return canPayOnPolicy && currentUserLogin === reimburserEmail;
}

/**
* Whether an admin/payments admin who isn't the designated workspace payer can still pay reports on the policy.
* Unlike `isPolicyPayer`/`isPayer`, this must not drive active prompting (badges, GBRs, next steps, pay to-dos), which stay payer-only.
*/
function canAdminPayReport(policy: OnyxInputOrEntry<Policy>, currentUserLogin: string): boolean {
const isReimbursementConfigured =
policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_YES || policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_MANUAL;

return isGroupPolicy(policy) && isReimbursementConfigured && canMemberWrite(policy, currentUserLogin, CONST.POLICY.POLICY_FEATURE.WORKFLOWS_PAYMENTS);
}

/** Check if the passed employee is an approver in the policy's employeeList */
function isPolicyApprover(policy: OnyxInputOrEntry<Policy>, employeeLogin: string) {
if (policy?.approver === employeeLogin) {
Expand Down Expand Up @@ -3723,7 +3712,6 @@ export {
isPolicyMember,
isMemberInHomeAndOfficeWorkspace,
isPolicyPayer,
canAdminPayReport,
getReimburserEmail,
getOwnerChangePayerSuccessData,
PAYER_ROLES,
Expand Down
13 changes: 0 additions & 13 deletions src/libs/ReportAlternateTextUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import type {CurrencyListActionsContextType} from '@hooks/useCurrencyList';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {
BankAccountList,
Card,
CardList,
PersonalDetails,
Expand Down Expand Up @@ -503,7 +502,6 @@ function getLastMessageTextForReport({
oneTransactionThreadReportID,
lastOriginalAction,
rules,
bankAccountList,
}: {
translate: LocalizedTranslate;
convertToDisplayString: CurrencyListActionsContextType['convertToDisplayString'];
Expand Down Expand Up @@ -531,9 +529,6 @@ function getLastMessageTextForReport({
oneTransactionThreadReportID?: string;
lastOriginalAction?: OnyxEntry<ReportAction>;
rules: OnyxCollection<Rule>;

/** The current user's bank accounts, used to name the account a report was paid with in the preview. */
bankAccountList?: OnyxEntry<BankAccountList>;
}): string {
const reportID = report?.reportID;
const canUserPerformWrite = canUserPerformWriteAction(report, isReportArchived);
Expand Down Expand Up @@ -603,7 +598,6 @@ function getLastMessageTextForReport({
shouldConsiderScanningReceiptOrPendingRoute: true,
policy,
isForListPreview: true,
bankAccountList,
});
lastMessageTextFromReport = formatReportLastMessageText(Parser.htmlToText(properSchemaForMoneyRequestMessage));
} else if (isReportPreviewAction(lastReportAction)) {
Expand Down Expand Up @@ -632,7 +626,6 @@ function getLastMessageTextForReport({
policy,
isForListPreview: true,
originalReportAction: lastReportAction,
bankAccountList,
});
lastMessageTextFromReport = formatReportLastMessageText(Parser.htmlToText(reportPreviewMessage));
}
Expand Down Expand Up @@ -980,7 +973,6 @@ function getLastMessageTextForReport({
shouldConsiderScanningReceiptOrPendingRoute: true,
policy,
isForListPreview: true,
bankAccountList,
}),
),
) || lastVisibleMessage?.lastMessageText;
Expand Down Expand Up @@ -1198,9 +1190,6 @@ type GetReportAlternateTextParams = {
convertToDisplayString: CurrencyListActionsContextType['convertToDisplayString'];
convertToDisplayStringWithoutCurrency: CurrencyListActionsContextType['convertToDisplayStringWithoutCurrency'];
rules: OnyxCollection<Rule>;

/** The current user's bank accounts, used to name the account a report was paid with in the preview. */
bankAccountList?: OnyxEntry<BankAccountList>;
};

/**
Expand Down Expand Up @@ -1239,7 +1228,6 @@ function getReportAlternateText({
convertToDisplayString,
convertToDisplayStringWithoutCurrency,
rules,
bankAccountList,
}: GetReportAlternateTextParams): string | undefined {
let alternateText: string | undefined;
const isChatRoomReport = isChatRoom(report);
Expand Down Expand Up @@ -1304,7 +1292,6 @@ function getReportAlternateText({
oneTransactionThreadReportID: resolvedOneTransactionThreadReportID,
lastOriginalAction,
rules,
bankAccountList,
});

const getLastActorDisplayNamePrefix = () =>
Expand Down
8 changes: 1 addition & 7 deletions src/libs/ReportNameUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import createDynamicRoute from './Navigation/helpers/dynamicRoutesUtils/createDy
import {getCurrentUserEmail} from './Network/NetworkStore';
import Parser from './Parser';
import {getPersonalDetailsByID, temporaryGetDisplayNameOrDefault} from './PersonalDetailsUtils';
import {wasPaidWithPolicyBankAccount} from './PolicyPaymentUtils';
import {getCleanedTagName, isPolicyAdmin, isPolicyFieldListEmpty} from './PolicyUtils';
import {
getActionableCard3DSTransactionApprovalMessage,
Expand Down Expand Up @@ -853,12 +852,7 @@ function computeReportNameBasedOnReportAction({

if (isMoneyRequestAction(parentReportAction)) {
const originalMessage = getOriginalMessage(parentReportAction);

// Prefer the account stored on the action: the payer is not always the workspace payer, so the policy's
// ACH account can belong to a different bank account than the one the report was actually paid with, and
// attributing it to a non-payer admin's payment shows a different account to every other viewer.
const policyAccountNumber = wasPaidWithPolicyBankAccount(reportPolicy, parentReportAction?.actorAccountID) ? reportPolicy?.achAccount?.accountNumber : undefined;
const last4Digits = (originalMessage?.accountNumber ?? policyAccountNumber)?.slice(-4) ?? '';
const last4Digits = originalMessage?.accountNumber?.slice(-4) ?? reportPolicy?.achAccount?.accountNumber?.slice(-4) ?? '';

if (originalMessage?.type === CONST.IOU.REPORT_ACTION_TYPE.PAY) {
if (originalMessage.paymentType === CONST.IOU.PAYMENT_TYPE.ELSEWHERE) {
Expand Down
10 changes: 8 additions & 2 deletions src/libs/ReportPreviewActionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import type {ValueOf} from 'type-fest';

import {
arePaymentsEnabled,
canAdminPayReport,
canMemberWrite,
getReimbursementChoice,
getSubmitToAccountID,
getValidConnectedIntegration,
hasDynamicExternalWorkflow,
hasIntegrationAutoSync,
isArchivedOrPendingDeletePolicy,
isGroupPolicy,
isPreferredExporter,
isSubmitterApproveBlockedOnSubmitWorkspace,
} from './PolicyUtils';
Expand Down Expand Up @@ -137,7 +139,11 @@ function canPay(
const isReportPayer = isPayer(currentUserAccountID, currentUserLogin, report, bankAccountList, policy, false);

// The admin pay path is for workspace expense reports. Personal policies should only offer Pay to the actual payer.
const canPayReport = isReportPayer || canAdminPayReport(policy, currentUserLogin);
const canPayReport =
isReportPayer ||
(isGroupPolicy(policy) &&
getReimbursementChoice(policy) === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_MANUAL &&
canMemberWrite(policy, currentUserLogin, CONST.POLICY.POLICY_FEATURE.WORKFLOWS_PAYMENTS));
const isPaymentsEnabled = arePaymentsEnabled(policy);
const isProcessing = isProcessingReport(report);
const isApprovalEnabled = policy ? policy.approvalMode && policy.approvalMode !== CONST.POLICY.APPROVAL_MODE.OPTIONAL : false;
Expand Down
Loading
Loading