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
1 change: 0 additions & 1 deletion config/eslint/eslint.seatbelt.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,6 @@
"../../src/libs/actions/IOU/MoneyRequestBuilder.ts" "@typescript-eslint/no-deprecated/getReportTransactions" 2
"../../src/libs/actions/IOU/MoneyRequestBuilder.ts" "@typescript-eslint/no-deprecated/translateLocal" 1
"../../src/libs/actions/IOU/MoneyRequestBuilder.ts" "@typescript-eslint/no-unsafe-type-assertion" 2
"../../src/libs/actions/IOU/PayMoneyRequest.ts" "@typescript-eslint/no-deprecated/getReportTransactions" 2
"../../src/libs/actions/IOU/PayMoneyRequest.ts" "@typescript-eslint/no-unsafe-type-assertion" 2
"../../src/libs/actions/IOU/PayMoneyRequest.ts" "no-restricted-imports" 1
"../../src/libs/actions/IOU/PayMoneyRequest.ts" "no-restricted-syntax" 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ function MoneyReportHeaderSecondaryActionsInner({reportID, primaryAction, isRepo
const {transactions: reportTransactions, violations} = useTransactionsAndViolationsForReport(moneyRequestReport?.reportID);
// While offline, keep pending-delete transactions so a queued-for-delete expense still counts as a real transaction until the delete syncs.
const nonPendingDeleteTransactions = Object.values(reportTransactions).filter((t) => isOffline || t.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE);
const allTransactions = Object.values(reportTransactions);
const moneyReportTransactions = Object.values(reportTransactions);
const singleTransaction = nonPendingDeleteTransactions.length === 1 ? nonPendingDeleteTransactions.at(0) : undefined;
const [originalTransaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${getNonEmptyStringOnyxID(singleTransaction?.comment?.originalTransactionID)}`);
const isTrackIntentUser = isTrackOnboardingChoice(introSelected?.choice);
Expand All @@ -173,7 +173,7 @@ function MoneyReportHeaderSecondaryActionsInner({reportID, primaryAction, isRepo
const shouldCalculateTotals = useSearchShouldCalculateTotals(currentSearchKey, true);

const isInvoiceReport = isInvoiceReportUtil(moneyRequestReport);
const isAnyTransactionOnHold = hasHeldExpensesReportUtils(allTransactions);
const isAnyTransactionOnHold = hasHeldExpensesReportUtils(moneyReportTransactions);
const existingB2BInvoiceReport = useParticipantsInvoiceReport(activePolicyID, CONST.REPORT.INVOICE_RECEIVER_TYPE.BUSINESS, chatReport?.policyID);
const getChatReportActions = usePayChatReportActions(chatReport, existingB2BInvoiceReport);

Expand Down Expand Up @@ -209,6 +209,7 @@ function MoneyReportHeaderSecondaryActionsInner({reportID, primaryAction, isRepo
paymentMethodType: type,
chatReport,
invoiceReport: moneyRequestReport,
invoiceReportTransactions: moneyReportTransactions,
introSelected,
currentUserAccountIDParam: accountID,
currentUserEmailParam: email ?? '',
Expand All @@ -234,6 +235,7 @@ function MoneyReportHeaderSecondaryActionsInner({reportID, primaryAction, isRepo
paymentType: type,
chatReport,
iouReport: moneyRequestReport,
iouReportTransactions: moneyReportTransactions,
introSelected,
currentUserAccountID: accountID,
currentUserLogin: currentUserLogin ?? '',
Expand Down Expand Up @@ -283,9 +285,10 @@ function MoneyReportHeaderSecondaryActionsInner({reportID, primaryAction, isRepo
!canIOUBePaid &&
canIOUBePaidAction(moneyRequestReport, chatReport, policy, bankAccountList, currentUserLogin ?? '', accountID, undefined, true, isChatReportArchived, invoiceReceiverPolicy);
const shouldShowPayButton = isPaidAnimationRunning || canIOUBePaid || onlyShowPayElsewhere;
const hasOnlyPendingTransactions = allTransactions.length > 0 && allTransactions.every((t) => isPending(t));
const hasOnlyPendingTransactions = moneyReportTransactions.length > 0 && moneyReportTransactions.every((t) => isPending(t));
const shouldShowApproveButton =
(canApproveIOU(moneyRequestReport, policy, reportMetadata, currentUserPersonalDetails.accountID, allTransactions) && !hasOnlyPendingTransactions) || isApprovedAnimationRunning;
(canApproveIOU(moneyRequestReport, policy, reportMetadata, currentUserPersonalDetails.accountID, moneyReportTransactions) && !hasOnlyPendingTransactions) ||
isApprovedAnimationRunning;
const isApproveDisabled = shouldShowApproveButton && !isAllowedToApproveExpenseReport(moneyRequestReport);

const totalAmount = getTotalAmountForIOUReportPreviewButton(moneyRequestReport, policy, CONST.REPORT.PRIMARY_ACTIONS.PAY, nonPendingDeleteTransactions, convertToDisplayString);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ function PayPrimaryAction({reportID, chatReportID, isDisabled}: PayPrimaryAction
paymentMethodType: type,
chatReport,
invoiceReport: moneyRequestReport,
invoiceReportTransactions: transactions,
introSelected,
currentUserAccountIDParam: accountID,
currentUserEmailParam: email ?? '',
Expand All @@ -171,6 +172,7 @@ function PayPrimaryAction({reportID, chatReportID, isDisabled}: PayPrimaryAction
paymentType: type,
chatReport,
iouReport: moneyRequestReport,
iouReportTransactions: transactions,
introSelected,
currentUserAccountID: accountID,
currentUserLogin: currentUserLogin ?? '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ function PayActionButton() {
paymentMethodType: type,
chatReport: currentChatReport,
invoiceReport: iouReport,
invoiceReportTransactions: transactions,
introSelected,
currentUserAccountIDParam: currentUserAccountID,
currentUserEmailParam: currentUserEmail,
Expand All @@ -115,6 +116,7 @@ function PayActionButton() {
paymentType: type,
chatReport: currentChatReport,
iouReport,
iouReportTransactions: transactions,
introSelected,
currentUserAccountID,
currentUserLogin: currentUserDetails.login ?? '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ function PayActionCell({isLoading, policyID, reportID, hash, amount, shouldDisab
paymentMethodType: type,
chatReport,
invoiceReport: iouReport,
invoiceReportTransactions: transactions,
introSelected,
currentUserAccountIDParam: currentUserAccountID,
currentUserEmailParam: email ?? '',
Expand Down Expand Up @@ -178,6 +179,7 @@ function PayActionCell({isLoading, policyID, reportID, hash, amount, shouldDisab
chatReport: chatReportForPayment,
isFallbackChatReport,
iouReport,
iouReportTransactions: transactions,
introSelected,
currentUserAccountID,
currentUserLogin: currentUserLogin ?? '',
Expand Down
3 changes: 3 additions & 0 deletions src/hooks/useHoldMenuSubmit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import usePayChatReportActions from './usePayChatReportActions';
import usePermissions from './usePermissions';
import {usePersonalDetail} from './usePersonalDetails';
import usePolicy from './usePolicy';
import useReportTransactions from './useReportTransactions';

type ActionHandledType = DeepValueOf<typeof CONST.IOU.REPORT_ACTION_TYPE.PAY | typeof CONST.IOU.REPORT_ACTION_TYPE.APPROVE>;

Expand All @@ -47,6 +48,7 @@ function useHoldMenuSubmit({moneyRequestReport, chatReport, requestType, payment
const activePolicy = usePolicy(activePolicyID);
const policy = usePolicy(moneyRequestReport?.policyID);
const chatReportPolicy = usePolicy(chatReport?.policyID);
const moneyRequestReportTransactions = useReportTransactions(moneyRequestReport?.reportID);
const getChatReportActions = usePayChatReportActions(chatReport, undefined);
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED);
const [delegateEmail] = useOnyx(ONYXKEYS.ACCOUNT, {selector: delegateEmailSelector});
Expand Down Expand Up @@ -111,6 +113,7 @@ function useHoldMenuSubmit({moneyRequestReport, chatReport, requestType, payment
paymentType,
chatReport: currentChatReport,
iouReport: currentMoneyRequestReport,
iouReportTransactions: moneyRequestReportTransactions,
introSelected,
currentUserAccountID: currentUserDetails.accountID,
currentUserLogin: currentUserDetails.login ?? '',
Expand Down
4 changes: 4 additions & 0 deletions src/hooks/useSearchBulkActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1713,6 +1713,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) {
}

const isItemInvoice = isInvoiceReport(iouReport);
const iouReportTransactions = Object.values(allReportsTransactionsAndViolations?.[item.reportID]?.transactions ?? {});
const fallbackChatReportID = item.chatReportID ?? iouReport.chatReportID ?? iouReport.parentReportID;
const fallbackPolicyID = iouReport.policyID ?? item.policyID;
const {chatReport, isFallbackChatReport} = getChatReportWithFallback(
Expand Down Expand Up @@ -1779,6 +1780,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) {
paymentMethodType: paymentItem.paymentType as PaymentMethodType,
chatReport,
invoiceReport: iouReport,
invoiceReportTransactions: iouReportTransactions,
introSelected,
currentUserAccountIDParam: accountID,
currentUserEmailParam: email ?? '',
Expand Down Expand Up @@ -1808,6 +1810,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) {
paymentType: paymentItem.paymentType as PaymentMethodType,
chatReport,
iouReport,
iouReportTransactions,
introSelected,
currentUserAccountID: accountID,
currentUserLogin: currentUserLogin ?? '',
Expand Down Expand Up @@ -1864,6 +1867,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) {
personalPolicyID,
lastPaymentMethods,
allTransactions,
allReportsTransactionsAndViolations,
policyIDsWithVBBA,
clearSelectedTransactions,
accountID,
Expand Down
2 changes: 2 additions & 0 deletions src/hooks/useSelectionModePayment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ function useSelectionModePayment({
paymentMethodType: type,
chatReport,
invoiceReport: moneyRequestReport,
invoiceReportTransactions: transactions,
introSelected,
currentUserAccountIDParam: accountID,
currentUserEmailParam: email ?? '',
Expand All @@ -217,6 +218,7 @@ function useSelectionModePayment({
paymentType: type,
chatReport,
iouReport: moneyRequestReport,
iouReportTransactions: transactions,
introSelected,
currentUserAccountID: accountID,
currentUserLogin: currentUserLogin ?? '',
Expand Down
15 changes: 10 additions & 5 deletions src/libs/actions/IOU/PayMoneyRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
buildOptimisticCancelPaymentReportAction,
buildOptimisticIOUReportAction,
getReimbursableTotal,
getReportTransactions,
getUnheldReimbursableTotal,
hasHeldExpenses as hasHeldExpensesReportUtils,
hasOutstandingChildRequest,
Expand Down Expand Up @@ -63,6 +62,7 @@ type PayInvoiceArgs = {
paymentMethodType: PaymentMethodType;
chatReport: OnyxTypes.Report;
invoiceReport: OnyxEntry<OnyxTypes.Report>;
invoiceReportTransactions: OnyxTypes.Transaction[];
introSelected: OnyxEntry<OnyxTypes.IntroSelected>;
currentUserAccountIDParam: number;
currentUserEmailParam: string;
Expand Down Expand Up @@ -102,6 +102,7 @@ type PayMoneyRequestFunctionParams = {
paymentType: PaymentMethodType;
chatReport: OnyxTypes.Report;
iouReport: OnyxEntry<OnyxTypes.Report>;
iouReportTransactions: OnyxTypes.Transaction[];
introSelected: OnyxEntry<OnyxTypes.IntroSelected>;
currentUserAccountID: number;
currentUserLogin: string;
Expand Down Expand Up @@ -131,6 +132,7 @@ type PayMoneyRequestFunctionParams = {
function getPayMoneyRequestParams({
initialChatReport,
iouReport,
iouReportTransactions,
recipient,
paymentMethodType,
full,
Expand Down Expand Up @@ -158,6 +160,7 @@ function getPayMoneyRequestParams({
}: {
initialChatReport: OnyxTypes.Report;
iouReport: OnyxEntry<OnyxTypes.Report>;
iouReportTransactions: OnyxTypes.Transaction[];
recipient: Participant;
paymentMethodType: PaymentMethodType;
full: boolean;
Expand Down Expand Up @@ -254,14 +257,13 @@ function getPayMoneyRequestParams({
chatReport = existingB2BInvoiceReport;
}

const reportTransactions = getReportTransactions(iouReport?.reportID);
const unheldReimbursableTotal = getUnheldReimbursableTotal(iouReport);
let total = getReimbursableTotal(iouReport);
if (hasHeldExpensesReportUtils(reportTransactions) && !full && !!unheldReimbursableTotal) {
if (hasHeldExpensesReportUtils(iouReportTransactions) && !full && !!unheldReimbursableTotal) {
total = unheldReimbursableTotal;
}

const shouldMoveScanFailedTransactions = !!full && isExpenseReport(iouReport) && shouldSplitScanFailedTransactions(reportTransactions, iouReport);
const shouldMoveScanFailedTransactions = !!full && isExpenseReport(iouReport) && shouldSplitScanFailedTransactions(iouReportTransactions, iouReport);

const optimisticIOUReportAction = buildOptimisticIOUReportAction({
type: CONST.IOU.REPORT_ACTION_TYPE.PAY,
Expand Down Expand Up @@ -439,7 +441,6 @@ function getPayMoneyRequestParams({

// Optimistically unhold all transactions if we pay all requests
if (full) {
const iouReportTransactions = getReportTransactions(iouReport?.reportID);
for (const transaction of iouReportTransactions) {
onyxData.optimisticData?.push({
onyxMethod: Onyx.METHOD.MERGE,
Expand Down Expand Up @@ -868,6 +869,7 @@ function payMoneyRequest(params: PayMoneyRequestFunctionParams) {
paymentType,
chatReport,
iouReport,
iouReportTransactions,
introSelected,
currentUserAccountID,
currentUserLogin,
Expand Down Expand Up @@ -910,6 +912,7 @@ function payMoneyRequest(params: PayMoneyRequestFunctionParams) {
const {params: payMoneyRequestParams, onyxData} = getPayMoneyRequestParams({
initialChatReport: chatReport,
iouReport,
iouReportTransactions,
recipient,
paymentMethodType: paymentType,
full,
Expand Down Expand Up @@ -1116,6 +1119,7 @@ function payInvoice({
paymentMethodType,
chatReport,
invoiceReport,
invoiceReportTransactions,
introSelected,
currentUserAccountIDParam,
currentUserEmailParam,
Expand Down Expand Up @@ -1155,6 +1159,7 @@ function payInvoice({
} = getPayMoneyRequestParams({
initialChatReport: chatReport,
iouReport: invoiceReport,
iouReportTransactions: invoiceReportTransactions,
recipient,
paymentMethodType,
full: true,
Expand Down
4 changes: 4 additions & 0 deletions src/libs/actions/Search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ function handleActionButtonPress({
conciergeChat,
getCurrencyDecimals,
rules,
iouReportTransactions: allReportTransactions,
});
return;
case CONST.SEARCH.ACTION_TYPES.APPROVE:
Expand Down Expand Up @@ -636,6 +637,7 @@ type GetPayActionCallbackParams = {
conciergeChat: OnyxEntry<Report>;
getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals'];
rules: OnyxCollection<Rule>;
iouReportTransactions: Transaction[];
};

function getPayActionCallback({
Expand Down Expand Up @@ -666,6 +668,7 @@ function getPayActionCallback({
conciergeChat,
getCurrencyDecimals,
rules,
iouReportTransactions,
}: GetPayActionCallbackParams) {
if (!item.reportID) {
Log.info('[SearchPay] Dropping row pay: item has no reportID');
Expand Down Expand Up @@ -698,6 +701,7 @@ function getPayActionCallback({
paymentType: lastPolicyPaymentMethod,
chatReport: chatReportForPayment,
iouReport: snapshotReport,
iouReportTransactions,
introSelected,
currentUserAccountID: currentUserAccountID ?? CONST.DEFAULT_NUMBER_ID,
currentUserLogin: currentUserLogin ?? '',
Expand Down
Loading
Loading