Skip to content

Commit

Permalink
Merge pull request #29287 from Expensify/georgia-cardTransactions-Rep…
Browse files Browse the repository at this point in the history
…ortPreview
  • Loading branch information
thienlnam authored Oct 13, 2023
2 parents 06ab1eb + 8786ad4 commit 5218714
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/components/ReportActionItem/ReportPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ function ReportPreview(props) {
const hasErrors = hasReceipts && ReportUtils.hasMissingSmartscanFields(props.iouReportID);
const lastThreeTransactionsWithReceipts = ReportUtils.getReportPreviewDisplayTransactions(props.action);
const lastThreeReceipts = _.map(lastThreeTransactionsWithReceipts, ({receipt, filename}) => ReceiptUtils.getThumbnailAndImageURIs(receipt.source, filename || ''));

const hasNonReimbursableTransactions = ReportUtils.hasNonReimbursableTransactions(props.iouReportID);
const hasOnlyOneReceiptRequest = numberOfRequests === 1 && hasReceipts;
const previewSubtitle = hasOnlyOneReceiptRequest
? TransactionUtils.getMerchant(transactionsWithReceipts[0])
Expand Down Expand Up @@ -166,7 +166,11 @@ function ReportPreview(props) {
return props.translate('iou.managerApproved', {manager: ReportUtils.getDisplayNameForParticipant(managerID, true)});
}
const managerName = isPolicyExpenseChat ? ReportUtils.getPolicyName(props.chatReport) : ReportUtils.getDisplayNameForParticipant(managerID, true);
return props.translate(iouSettled || props.iouReport.isWaitingOnBankAccount ? 'iou.payerPaid' : 'iou.payerOwes', {payer: managerName});
let paymentVerb = hasNonReimbursableTransactions ? 'iou.payerSpent' : 'iou.payerOwes';
if (iouSettled || props.iouReport.isWaitingOnBankAccount) {
paymentVerb = 'iou.payerPaid';
}
return props.translate(paymentVerb, {payer: managerName});
};

const bankAccountRoute = ReportUtils.getBankAccountRoute(props.chatReport);
Expand Down
2 changes: 2 additions & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,8 @@ export default {
payerOwes: ({payer}: PayerOwesParams) => `${payer} owes: `,
payerPaidAmount: ({payer, amount}: PayerPaidAmountParams): string => `${payer} paid ${amount}`,
payerPaid: ({payer}: PayerPaidParams) => `${payer} paid: `,
payerSpentAmount: ({payer, amount}: PayerPaidAmountParams): string => `${payer} spent ${amount}`,
payerSpent: ({payer}: PayerPaidParams) => `${payer} spent: `,
managerApproved: ({manager}: ManagerApprovedParams) => `${manager} approved:`,
payerSettled: ({amount}: PayerSettledParams) => `paid ${amount}`,
waitingOnBankAccount: ({submitterDisplayName}: WaitingOnBankAccountParams) => `started settling up, payment is held until ${submitterDisplayName} adds a bank account`,
Expand Down
2 changes: 2 additions & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,8 @@ export default {
payerOwes: ({payer}: PayerOwesParams) => `${payer} debe: `,
payerPaidAmount: ({payer, amount}: PayerPaidAmountParams) => `${payer} pagó ${amount}`,
payerPaid: ({payer}: PayerPaidParams) => `${payer} pagó: `,
payerSpentAmount: ({payer, amount}: PayerPaidAmountParams): string => `${payer} gastó ${amount}`,
payerSpent: ({payer}: PayerPaidParams) => `${payer} gastó: `,
managerApproved: ({manager}: ManagerApprovedParams) => `${manager} aprobó:`,
payerSettled: ({amount}: PayerSettledParams) => `pagó ${amount}`,
waitingOnBankAccount: ({submitterDisplayName}: WaitingOnBankAccountParams) => `inicio el pago, pero no se procesará hasta que ${submitterDisplayName} añada una cuenta bancaria`,
Expand Down
19 changes: 18 additions & 1 deletion src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1267,6 +1267,17 @@ function isWaitingForTaskCompleteFromAssignee(report, parentReportAction = {}) {
return isTaskReport(report) && isReportManager(report) && isOpenTaskReport(report, parentReportAction);
}

/**
* Returns number of transactions that are nonReimbursable
*
* @param {Object|null} iouReportID
* @returns {Number}
*/
function hasNonReimbursableTransactions(iouReportID) {
const allTransactions = TransactionUtils.getAllReportTransactions(iouReportID);
return _.filter(allTransactions, (transaction) => transaction.reimbursable === false).length > 0;
}

/**
* @param {Object} report
* @param {Object} allReportsDict
Expand Down Expand Up @@ -1344,6 +1355,10 @@ function getMoneyRequestReportName(report, policy = undefined) {
return `${payerPaidAmountMesssage}${Localize.translateLocal('iou.pending')}`;
}

if (hasNonReimbursableTransactions(report.reportID)) {
return Localize.translateLocal('iou.payerSpentAmount', {payer: payerName, amount: formattedAmount});
}

if (report.hasOutstandingIOU) {
return Localize.translateLocal('iou.payerOwesAmount', {payer: payerName, amount: formattedAmount});
}
Expand Down Expand Up @@ -1565,7 +1580,8 @@ function getReportPreviewMessage(report, reportAction = {}, shouldConsiderReceip
return Localize.translateLocal('iou.waitingOnBankAccount', {submitterDisplayName});
}

return Localize.translateLocal('iou.payerOwesAmount', {payer: payerName, amount: formattedAmount});
const containsNonReimbursable = hasNonReimbursableTransactions(report.reportID);
return Localize.translateLocal(containsNonReimbursable ? 'iou.payerSpentAmount' : 'iou.payerOwesAmount', {payer: payerName, amount: formattedAmount});
}

/**
Expand Down Expand Up @@ -3988,6 +4004,7 @@ export {
areAllRequestsBeingSmartScanned,
getReportPreviewDisplayTransactions,
getTransactionsWithReceipts,
hasNonReimbursableTransactions,
hasMissingSmartscanFields,
getIOUReportActionDisplayMessage,
isWaitingForTaskCompleteFromAssignee,
Expand Down
6 changes: 4 additions & 2 deletions src/libs/actions/IOU.js
Original file line number Diff line number Diff line change
Expand Up @@ -1767,7 +1767,8 @@ function editMoneyRequest(transactionID, transactionThreadReportID, transactionC
updatedMoneyRequestReport.lastMessageHtml = lastMessage[0].html;

// Update the last message of the chat report
const messageText = Localize.translateLocal('iou.payerOwesAmount', {
const hasNonReimbursableTransactions = ReportUtils.hasNonReimbursableTransactions(iouReport);
const messageText = Localize.translateLocal(hasNonReimbursableTransactions ? 'iou.payerSpentAmount' : 'iou.payerOwesAmount', {
payer: updatedMoneyRequestReport.managerEmail,
amount: CurrencyUtils.convertToDisplayString(updatedMoneyRequestReport.total, updatedMoneyRequestReport.currency),
});
Expand Down Expand Up @@ -1987,7 +1988,8 @@ function deleteMoneyRequest(transactionID, reportAction, isSingleTransactionView
updatedIOUReport.lastVisibleActionCreated = lastVisibleAction.created;

updatedReportPreviewAction = {...reportPreviewAction};
const messageText = Localize.translateLocal('iou.payerOwesAmount', {
const hasNonReimbursableTransactions = ReportUtils.hasNonReimbursableTransactions(iouReport);
const messageText = Localize.translateLocal(hasNonReimbursableTransactions ? 'iou.payerSpentAmount' : 'iou.payerOwesAmount', {
payer: updatedIOUReport.managerEmail,
amount: CurrencyUtils.convertToDisplayString(updatedIOUReport.total, updatedIOUReport.currency),
});
Expand Down

0 comments on commit 5218714

Please sign in to comment.