Skip to content

Commit

Permalink
Merge pull request #48014 from rezkiy37/feature/45170-paid-invoice-view
Browse files Browse the repository at this point in the history
Showing the paid invoice in the invoice room
  • Loading branch information
madmax330 authored Sep 4, 2024
2 parents dd2d479 + b9ceaa4 commit ec8a5d9
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/components/ReportActionItem/ReportPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ function ReportPreview({

const shouldShowSettlementButton = (shouldShowPayButton || shouldShowApproveButton) && !showRTERViolationMessage;

const shouldPromptUserToAddBankAccount = ReportUtils.hasMissingPaymentMethod(userWallet, iouReportID);
const shouldPromptUserToAddBankAccount = ReportUtils.hasMissingPaymentMethod(userWallet, iouReportID) || ReportUtils.hasMissingInvoiceBankAccount(iouReportID);
const shouldShowRBR = hasErrors;

/*
Expand Down
1 change: 1 addition & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,7 @@ export default {
managerApproved: ({manager}: ManagerApprovedParams) => `${manager} approved:`,
managerApprovedAmount: ({manager, amount}: ManagerApprovedAmountParams) => `${manager} approved ${amount}`,
payerSettled: ({amount}: PayerSettledParams) => `paid ${amount}`,
payerSettledWithMissingBankAccount: ({amount}: PayerSettledParams) => `paid ${amount}. Add a bank account to receive your payment.`,
approvedAmount: ({amount}: ApprovedAmountParams) => `approved ${amount}`,
forwardedAmount: ({amount}: ForwardedAmountParams) => `approved ${amount}`,
rejectedThisReport: 'rejected this report',
Expand Down
1 change: 1 addition & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,7 @@ export default {
managerApproved: ({manager}: ManagerApprovedParams) => `${manager} aprobó:`,
managerApprovedAmount: ({manager, amount}: ManagerApprovedAmountParams) => `${manager} aprobó ${amount}`,
payerSettled: ({amount}: PayerSettledParams) => `pagó ${amount}`,
payerSettledWithMissingBankAccount: ({amount}: PayerSettledParams) => `pagó ${amount}. Agrega una cuenta bancaria para recibir tu pago.`,
approvedAmount: ({amount}: ApprovedAmountParams) => `aprobó ${amount}`,
forwardedAmount: ({amount}: ForwardedAmountParams) => `aprobó ${amount}`,
rejectedThisReport: 'rechazó este informe',
Expand Down
28 changes: 27 additions & 1 deletion src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2596,6 +2596,18 @@ function requiresAttentionFromCurrentUser(optionOrReport: OnyxEntry<Report> | Op
return true;
}

if (hasMissingInvoiceBankAccount(optionOrReport.reportID)) {
return true;
}

if (isInvoiceRoom(optionOrReport)) {
const invoiceRoomReportActions = ReportActionsUtils.getAllReportActions(optionOrReport.reportID);

return Object.values(invoiceRoomReportActions).some(
(reportAction) => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW && reportAction.childReportID && hasMissingInvoiceBankAccount(reportAction.childReportID),
);
}

return false;
}

Expand Down Expand Up @@ -6920,7 +6932,7 @@ function getIOUReportActionDisplayMessage(reportAction: OnyxEntry<ReportAction>,

switch (originalMessage.paymentType) {
case CONST.IOU.PAYMENT_TYPE.ELSEWHERE:
translationKey = 'iou.paidElsewhereWithAmount';
translationKey = hasMissingInvoiceBankAccount(IOUReportID ?? '-1') ? 'iou.payerSettledWithMissingBankAccount' : 'iou.paidElsewhereWithAmount';
break;
case CONST.IOU.PAYMENT_TYPE.EXPENSIFY:
case CONST.IOU.PAYMENT_TYPE.VBBA:
Expand Down Expand Up @@ -7750,6 +7762,19 @@ function getApprovalChain(policy: OnyxEntry<Policy>, employeeAccountID: number,
return approvalChain;
}

/**
* Checks if the user has missing bank account for the invoice room.
*/
function hasMissingInvoiceBankAccount(iouReportID: string): boolean {
const invoiceReport = getReport(iouReportID);

if (!isInvoiceReport(invoiceReport)) {
return false;
}

return invoiceReport?.ownerAccountID === currentUserAccountID && isEmptyObject(getPolicy(invoiceReport?.policyID)?.invoice?.bankAccount ?? {}) && isSettled(iouReportID);
}

function isSubmittedExpenseReportManagerWithoutParentAccess(report: OnyxEntry<Report>) {
return isExpenseReport(report) && report?.hasParentAccess === false && report?.managerID === currentUserAccountID && isProcessingReport(report);
}
Expand Down Expand Up @@ -8060,6 +8085,7 @@ export {
getArchiveReason,
getApprovalChain,
isIndividualInvoiceRoom,
hasMissingInvoiceBankAccount,
};

export type {
Expand Down
29 changes: 27 additions & 2 deletions src/pages/home/report/ReportActionItemMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ import type {StyleProp, TextStyle, ViewStyle} from 'react-native';
import {View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
import Button from '@components/Button';
import Text from '@components/Text';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import Navigation from '@libs/Navigation/Navigation';
import * as ReportActionsUtils from '@libs/ReportActionsUtils';
import * as ReportUtils from '@libs/ReportUtils';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {ReportAction, Transaction} from '@src/types/onyx';
import TextCommentFragment from './comment/TextCommentFragment';
import ReportActionItemFragment from './ReportActionItemFragment';
Expand Down Expand Up @@ -120,14 +123,36 @@ function ReportActionItemMessage({action, transaction, displayAsGroup, reportID,

// Approving or submitting reports in oldDot results in system messages made up of multiple fragments of `TEXT` type
// which we need to wrap in `<Text>` to prevent them rendering on separate lines.

return shouldWrapInText ? <Text style={styles.ltr}>{reportActionItemFragments}</Text> : reportActionItemFragments;
};

const openWorkspaceInvoicesPage = () => {
const policyID = ReportUtils.getReport(reportID)?.policyID;

if (!policyID) {
return;
}

// TODO: Uncomment the following line when the invoices screen is ready - https://github.com/Expensify/App/issues/45175.
// Navigation.navigate(ROUTES.WORKSPACE_INVOICES.getRoute(policyID))
Navigation.navigate(ROUTES.WORKSPACE_MORE_FEATURES.getRoute(policyID));
};

return (
<View style={[styles.chatItemMessage, style]}>
{!isHidden ? (
renderReportActionItemFragments(isApprovedOrSubmittedReportAction)
<>
{renderReportActionItemFragments(isApprovedOrSubmittedReportAction)}
{action.actionName === CONST.REPORT.ACTIONS.TYPE.IOU && ReportUtils.hasMissingInvoiceBankAccount(reportID) && (
<Button
style={[styles.mt2, styles.alignSelfStart]}
medium
success
text={translate('workspace.invoices.paymentMethods.addBankAccount')}
onPress={openWorkspaceInvoicesPage}
/>
)}
</>
) : (
<Text style={[styles.textLabelSupporting, styles.lh20]}>{translate('moderation.flaggedContent')}</Text>
)}
Expand Down
9 changes: 9 additions & 0 deletions src/types/onyx/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1311,6 +1311,15 @@ type PolicyInvoicingDetails = OnyxCommon.OnyxValueWithOfflineFeedback<{

/** Stripe Connect company website */
companyWebsite?: string;

/** Bank account */
bankAccount?: {
/** Account balance */
stripeConnectAccountBalance?: number;

/** bankAccountID of selected BBA for payouts */
transferBankAccountID?: number;
};
}>;

/** Names of policy features */
Expand Down

0 comments on commit ec8a5d9

Please sign in to comment.