Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GBR and Settlement button for the receiver on the invoice report preview #41859

Merged
merged 25 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
665b508
updated settlement button, added invoice payment
waterim May 8, 2024
22edb59
remove unused activeUserID
waterim May 8, 2024
5e56c7f
fixed payments and ts issues
waterim May 9, 2024
1ea1fc3
remove unused canIOUbePaid part, remove unused useState
waterim May 10, 2024
8afc6fc
added translations
waterim May 10, 2024
a4daf61
Merge remote-tracking branch 'upstream/main' into feat-40437-invoice
waterim May 13, 2024
faaa568
update params in payInvoice
waterim May 13, 2024
1505652
remove PERSONAL & BUSINESS payment types
waterim May 13, 2024
a52e68d
update isSettled
waterim May 14, 2024
bff509d
Merge remote-tracking branch 'upstream/main' into feat-40437-invoice
waterim May 16, 2024
6c2b1a1
new view of the settlement button
waterim May 17, 2024
86f6fb2
fix modal, show amount, update text
waterim May 21, 2024
524d640
update hover, remove business button
waterim May 21, 2024
e0ed718
Revert "draft fix"
waterim May 21, 2024
6da0e8e
Revert "Revert "draft fix""
waterim May 21, 2024
7ca70bf
update wallet for invoiceReport
waterim May 22, 2024
97a41aa
stylings change
waterim May 23, 2024
cba930e
updated stylings
waterim May 23, 2024
35da70f
fixed focus
waterim May 24, 2024
e5e73cc
translations
waterim May 24, 2024
1003662
Merge branch 'main' into feat-40437-invoice
VickyStash May 29, 2024
bb88d41
Update back title inside the submenu
VickyStash May 29, 2024
e600f02
Merge branch 'main' into feat-40437-invoice
VickyStash May 31, 2024
9b7056f
Minor UI fix
VickyStash May 31, 2024
54de5b5
Merge branch 'main' into feat-40437-invoice
VickyStash Jun 4, 2024
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
3 changes: 3 additions & 0 deletions assets/images/checkmark-circle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1511,6 +1511,8 @@ const CONST = {
ELSEWHERE: 'Elsewhere',
EXPENSIFY: 'Expensify',
VBBA: 'ACH',
PERSONAL: 'PERSONAL',
BUSINESS: 'BUSINESS',
waterim marked this conversation as resolved.
Show resolved Hide resolved
},
ACTION: {
EDIT: 'edit',
Expand Down
2 changes: 2 additions & 0 deletions src/components/Icon/Expensicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import ChatBubbleReply from '@assets/images/chatbubble-reply.svg';
import ChatBubbleUnread from '@assets/images/chatbubble-unread.svg';
import ChatBubble from '@assets/images/chatbubble.svg';
import ChatBubbles from '@assets/images/chatbubbles.svg';
import CheckmarkCircle from '@assets/images/checkmark-circle.svg';
import Checkmark from '@assets/images/checkmark.svg';
import Close from '@assets/images/close.svg';
import ClosedSign from '@assets/images/closed-sign.svg';
Expand Down Expand Up @@ -336,4 +337,5 @@ export {
Lightbulb,
DocumentPlus,
Clear,
CheckmarkCircle,
};
8 changes: 5 additions & 3 deletions src/components/MoneyReportHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ function MoneyReportHeader({

const shouldDisableApproveButton = shouldShowApproveButton && !ReportUtils.isAllowedToApproveExpenseReport(moneyRequestReport);

const shouldShowSettlementButton = !ReportUtils.isInvoiceReport(moneyRequestReport) && (shouldShowPayButton || shouldShowApproveButton);
const shouldShowSettlementButton = shouldShowPayButton || shouldShowApproveButton;

const shouldShowSubmitButton = isDraft && reimbursableSpend !== 0;
const shouldDisableSubmitButton = shouldShowSubmitButton && !ReportUtils.isAllowedToSubmitDraftExpenseReport(moneyRequestReport);
Expand All @@ -126,14 +126,16 @@ function MoneyReportHeader({
const isMoreContentShown = shouldShowNextStep || (shouldShowAnyButton && shouldUseNarrowLayout);

const confirmPayment = (type?: PaymentMethodType | undefined) => {
if (!type) {
if (!type || !chatReport) {
return;
}
setPaymentType(type);
setRequestType('pay');
if (ReportUtils.hasHeldExpenses(moneyRequestReport.reportID)) {
setIsHoldMenuVisible(true);
} else if (chatReport) {
} else if (ReportUtils.isInvoiceReport(moneyRequestReport)) {
IOU.payInvoice(type, chatReport, moneyRequestReport);
} else {
IOU.payMoneyRequest(type, chatReport, moneyRequestReport, true);
}
};
Expand Down
17 changes: 14 additions & 3 deletions src/components/ReportActionItem/ReportPreview.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useMemo} from 'react';
import React, {useMemo, useState} from 'react';

Check failure on line 1 in src/components/ReportActionItem/ReportPreview.tsx

View workflow job for this annotation

GitHub Actions / Run ESLint

'useState' is defined but never used
waterim marked this conversation as resolved.
Show resolved Hide resolved
import type {StyleProp, ViewStyle} from 'react-native';
import {View} from 'react-native';
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
Expand Down Expand Up @@ -208,7 +208,7 @@

const shouldDisableApproveButton = shouldShowApproveButton && !ReportUtils.isAllowedToApproveExpenseReport(iouReport);

const shouldShowSettlementButton = !ReportUtils.isInvoiceReport(iouReport) && (shouldShowPayButton || shouldShowApproveButton);
const shouldShowSettlementButton = shouldShowPayButton || shouldShowApproveButton;

const shouldPromptUserToAddBankAccount = ReportUtils.hasMissingPaymentMethod(userWallet, iouReportID);
const shouldShowRBR = !iouSettled && hasErrors;
Expand Down Expand Up @@ -241,6 +241,17 @@
};
}, [formattedMerchant, formattedDescription, moneyRequestComment, translate, numberOfRequests, numberOfScanningReceipts, numberOfPendingRequests]);

const confirmPayment = (paymentMethodType?: PaymentMethodType) => {
if (!paymentMethodType || !chatReport || !iouReport) {
return;
}
if (ReportUtils.isInvoiceReport(iouReport)) {
IOU.payInvoice(paymentMethodType, chatReport, iouReport);
} else {
IOU.payMoneyRequest(paymentMethodType, chatReport, iouReport);
}
};

return (
<OfflineWithFeedback
pendingAction={iouReport?.pendingFields?.preview}
Expand Down Expand Up @@ -318,7 +329,7 @@
policyID={policyID}
chatReportID={chatReportID}
iouReport={iouReport}
onPress={(paymentType?: PaymentMethodType) => chatReport && iouReport && paymentType && IOU.payMoneyRequest(paymentType, chatReport, iouReport)}
onPress={confirmPayment}
enablePaymentsRoute={ROUTES.ENABLE_PAYMENTS}
addBankAccountRoute={bankAccountRoute}
shouldHidePaymentOptions={!shouldShowPayButton}
Expand Down
14 changes: 13 additions & 1 deletion src/components/SettlementButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import type {LastPaymentMethod, Policy, Report} from '@src/types/onyx';
import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage';
import type AnchorAlignment from '@src/types/utils/AnchorAlignment';
import type {EmptyObject} from '@src/types/utils/EmptyObject';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import ButtonWithDropdownMenu from './ButtonWithDropdownMenu';
import type {PaymentType} from './ButtonWithDropdownMenu/types';
import * as Expensicons from './Icon/Expensicons';
Expand Down Expand Up @@ -149,9 +150,10 @@ function SettlementButton({

const session = useSession();
const chatReport = ReportUtils.getReport(chatReportID);
const isInvoiceReport = (!isEmptyObject(iouReport) && ReportUtils.isInvoiceReport(iouReport)) || false;
const isPaidGroupPolicy = ReportUtils.isPaidGroupPolicyExpenseChat(chatReport);
const shouldShowPaywithExpensifyOption = !isPaidGroupPolicy || (!shouldHidePaymentOptions && ReportUtils.isPayer(session, iouReport as OnyxEntry<Report>));
const shouldShowPayElsewhereOption = !isPaidGroupPolicy || policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_MANUAL;
const shouldShowPayElsewhereOption = (!isPaidGroupPolicy || policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_MANUAL) && !isInvoiceReport;
const paymentButtonOptions = useMemo(() => {
const buttonOptions = [];
const isExpenseReport = ReportUtils.isExpenseReport(iouReport);
Expand All @@ -171,6 +173,11 @@ function SettlementButton({
icon: Expensicons.Cash,
value: CONST.IOU.PAYMENT_TYPE.ELSEWHERE,
},
[CONST.IOU.PAYMENT_TYPE.PERSONAL]: {
text: translate('iou.settlePersonal', {formattedAmount}),
icon: Expensicons.User,
value: CONST.IOU.PAYMENT_TYPE.PERSONAL,
},
};
const approveButtonOption = {
text: translate('iou.approve'),
Expand Down Expand Up @@ -199,6 +206,10 @@ function SettlementButton({
buttonOptions.push(paymentMethods[CONST.IOU.PAYMENT_TYPE.ELSEWHERE]);
}

if (isInvoiceReport) {
buttonOptions.push(paymentMethods[CONST.IOU.PAYMENT_TYPE.PERSONAL]);
}

if (shouldShowApproveButton) {
buttonOptions.push(approveButtonOption);
}
Expand All @@ -211,6 +222,7 @@ function SettlementButton({
// We don't want to reorder the options when the preferred payment method changes while the button is still visible
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [currency, formattedAmount, iouReport, policyID, translate, shouldHidePaymentOptions, shouldShowApproveButton, shouldDisableApproveButton]);

const selectPaymentType = (event: KYCFlowEvent, iouPaymentType: PaymentMethodType, triggerKYCFlow: TriggerKYCFlow) => {
if (iouPaymentType === CONST.IOU.PAYMENT_TYPE.EXPENSIFY || iouPaymentType === CONST.IOU.PAYMENT_TYPE.VBBA) {
triggerKYCFlow(event, iouPaymentType);
Expand Down
10 changes: 10 additions & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,8 @@ export default {
settledExpensify: 'Paid',
settledElsewhere: 'Paid elsewhere',
settleExpensify: ({formattedAmount}: SettleExpensifyCardParams) => (formattedAmount ? `Pay ${formattedAmount} with Expensify` : `Pay with Expensify`),
settlePersonal: ({formattedAmount}: SettleExpensifyCardParams) => (formattedAmount ? `Pay ${formattedAmount} as an individual` : `Pay as an individual`),
settleBusiness: ({formattedAmount}: SettleExpensifyCardParams) => (formattedAmount ? `Pay ${formattedAmount} as a business` : `Pay as a business`),
payElsewhere: ({formattedAmount}: SettleExpensifyCardParams) => (formattedAmount ? `Pay ${formattedAmount} elsewhere` : `Pay elsewhere`),
nextStep: 'Next Steps',
finished: 'Finished',
Expand Down Expand Up @@ -2379,6 +2381,14 @@ export default {
viewUnpaidInvoices: 'View unpaid invoices',
sendInvoice: 'Send invoice',
sendFrom: 'Send from',
paymentMethods: {
personal: 'Personal',
business: 'Business',
chooseInvoiceMethod: 'Choose a payment method below:',
addBankAccount: 'Add bank account',
payingAsIndividual: 'Paying as an individual',
payingAsBusiness: 'Paying as a business',
},
},
travel: {
unlockConciergeBookingTravel: 'Unlock Concierge travel booking',
Expand Down
10 changes: 10 additions & 0 deletions src/languages/es.ts
waterim marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,8 @@ export default {
settledElsewhere: 'Pagado de otra forma',
settleExpensify: ({formattedAmount}: SettleExpensifyCardParams) => (formattedAmount ? `Pagar ${formattedAmount} con Expensify` : `Pagar con Expensify`),
payElsewhere: ({formattedAmount}: SettleExpensifyCardParams) => (formattedAmount ? `Pagar ${formattedAmount} de otra forma` : `Pagar de otra forma`),
settlePersonal: ({formattedAmount}: SettleExpensifyCardParams) => (formattedAmount ? `Pay ${formattedAmount} as an individual` : `Pay as an individual`),
settleBusiness: ({formattedAmount}: SettleExpensifyCardParams) => (formattedAmount ? `Pay ${formattedAmount} as a business` : `Pay as a business`),
nextStep: 'Pasos Siguientes',
finished: 'Finalizado',
sendInvoice: ({amount}: RequestAmountParams) => `Enviar factura de ${amount}`,
Expand Down Expand Up @@ -2415,6 +2417,14 @@ export default {
viewUnpaidInvoices: 'Ver facturas emitidas pendientes',
sendInvoice: 'Enviar factura',
sendFrom: 'Enviar desde',
paymentMethods: {
personal: 'Personal',
business: 'Business',
chooseInvoiceMethod: 'Choose a payment method below:',
addBankAccount: 'Add bank account',
payingAsIndividual: 'Paying as an individual',
payingAsBusiness: 'Paying as a business',
},
},
travel: {
unlockConciergeBookingTravel: 'Desbloquea la reserva de viajes con Concierge',
Expand Down
9 changes: 9 additions & 0 deletions src/libs/API/parameters/PayInvoiceParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage';

type PayInvoiceParams = {
reportID: string;
reportActionID: string;
paymentMethodType: PaymentMethodType;
};

export default PayInvoiceParams;
1 change: 1 addition & 0 deletions src/libs/API/parameters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,4 @@ export type {default as LeavePolicyParams} from './LeavePolicyParams';
export type {default as OpenPolicyAccountingPageParams} from './OpenPolicyAccountingPageParams';
export type {default as SearchParams} from './Search';
export type {default as SendInvoiceParams} from './SendInvoiceParams';
export type {default as PayInvoiceParams} from './PayInvoiceParams';
2 changes: 2 additions & 0 deletions src/libs/API/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ const WRITE_COMMANDS = {
LEAVE_POLICY: 'LeavePolicy',
ACCEPT_SPOTNANA_TERMS: 'AcceptSpotnanaTerms',
SEND_INVOICE: 'SendInvoice',
PAY_INVOICE: 'PayInvoice',
} as const;

type WriteCommand = ValueOf<typeof WRITE_COMMANDS>;
Expand Down Expand Up @@ -432,6 +433,7 @@ type WriteCommandParameters = {
[WRITE_COMMANDS.LEAVE_POLICY]: Parameters.LeavePolicyParams;
[WRITE_COMMANDS.ACCEPT_SPOTNANA_TERMS]: EmptyObject;
[WRITE_COMMANDS.SEND_INVOICE]: Parameters.SendInvoiceParams;
[WRITE_COMMANDS.PAY_INVOICE]: Parameters.PayInvoiceParams;
};

const READ_COMMANDS = {
Expand Down
2 changes: 1 addition & 1 deletion src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ function isPolicyExpenseChat(report: OnyxEntry<Report> | Participant | EmptyObje
return getChatType(report) === CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT || (report?.isPolicyExpenseChat ?? false);
}

function isInvoiceRoom(report: OnyxEntry<Report>): boolean {
function isInvoiceRoom(report: OnyxEntry<Report> | EmptyObject): boolean {
return getChatType(report) === CONST.REPORT.CHAT_TYPE.INVOICE;
}

Expand Down
35 changes: 32 additions & 3 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type {
DeleteMoneyRequestParams,
DetachReceiptParams,
EditMoneyRequestParams,
PayInvoiceParams,
PayMoneyRequestParams,
ReplaceReceiptParams,
RequestMoneyParams,
Expand Down Expand Up @@ -5651,6 +5652,8 @@ function getPayMoneyRequestParams(
paymentMethodType: PaymentMethodType,
full: boolean,
): PayMoneyRequestData {
const isInvoiceReport = ReportUtils.isInvoiceReport(iouReport);

let total = (iouReport.total ?? 0) - (iouReport.nonReimbursableTotal ?? 0);
if (ReportUtils.hasHeldExpenses(iouReport.reportID) && !full && !!iouReport.unheldTotal) {
total = iouReport.unheldTotal;
Expand All @@ -5675,9 +5678,12 @@ function getPayMoneyRequestParams(
if (reportPreviewAction) {
optimisticReportPreviewAction = ReportUtils.updateReportPreview(iouReport, reportPreviewAction, true);
}

const currentNextStep = allNextSteps[`${ONYXKEYS.COLLECTION.NEXT_STEP}${iouReport.reportID}`] ?? null;
const optimisticNextStep = NextStepUtils.buildNextStep(iouReport, CONST.REPORT.STATUS_NUM.REIMBURSED, {isPaidWithExpensify: paymentMethodType === CONST.IOU.PAYMENT_TYPE.VBBA});
let currentNextStep = null;
let optimisticNextStep = null;
if (!isInvoiceReport) {
currentNextStep = allNextSteps[`${ONYXKEYS.COLLECTION.NEXT_STEP}${iouReport.reportID}`];
optimisticNextStep = NextStepUtils.buildNextStep(iouReport, CONST.REPORT.STATUS_NUM.REIMBURSED, {isPaidWithExpensify: paymentMethodType === CONST.IOU.PAYMENT_TYPE.VBBA});
}

const optimisticData: OnyxUpdate[] = [
{
Expand Down Expand Up @@ -5874,6 +5880,10 @@ function canIOUBePaid(iouReport: OnyxEntry<OnyxTypes.Report> | EmptyObject, chat
return false;
}

if (ReportUtils.isInvoiceRoom(iouReport) && iouReport?.managerID === userAccountID) {
return true;
}
waterim marked this conversation as resolved.
Show resolved Hide resolved

if (ReportUtils.isInvoiceReport(iouReport)) {
if (chatReport?.invoiceReceiver?.type === CONST.REPORT.INVOICE_RECEIVER_TYPE.INDIVIDUAL) {
return chatReport?.invoiceReceiver?.accountID === userAccountID;
waterim marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -6286,6 +6296,24 @@ function payMoneyRequest(paymentType: PaymentMethodType, chatReport: OnyxTypes.R
Navigation.dismissModalWithReport(chatReport);
}

function payInvoice(paymentMethodType: PaymentMethodType, chatReport: OnyxTypes.Report, invoiceReport: OnyxTypes.Report) {
const recipient = {accountID: invoiceReport.ownerAccountID};
const {
optimisticData,
successData,
failureData,
params: {reportActionID},
} = getPayMoneyRequestParams(chatReport, invoiceReport, recipient, paymentMethodType, true);

const params: PayInvoiceParams = {
reportID: chatReport.reportID,
waterim marked this conversation as resolved.
Show resolved Hide resolved
reportActionID,
paymentMethodType,
};

API.write(WRITE_COMMANDS.PAY_INVOICE, params, {optimisticData, successData, failureData});
}

function detachReceipt(transactionID: string) {
const transaction = allTransactions[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`];
const newTransaction = transaction ? {...transaction, filename: '', receipt: {}} : null;
Expand Down Expand Up @@ -6673,6 +6701,7 @@ export {
initMoneyRequest,
navigateToStartStepIfScanFileCannotBeRead,
payMoneyRequest,
payInvoice,
putOnHold,
replaceReceipt,
requestMoney,
Expand Down
Loading