From 23db315bf8b2e2e9ea52a003b6db07c77f7c52ab Mon Sep 17 00:00:00 2001 From: Georgia Monahan Date: Wed, 11 Oct 2023 13:02:14 +0100 Subject: [PATCH 1/5] Show on ReportPreview if there are nonreimbursable transactions. --- .../ReportActionItem/ReportPreview.js | 8 ++++++-- src/languages/en.ts | 2 ++ src/languages/es.ts | 2 ++ src/libs/ReportUtils.js | 18 ++++++++++++++++++ src/libs/TransactionUtils.ts | 9 +++++++++ 5 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/components/ReportActionItem/ReportPreview.js b/src/components/ReportActionItem/ReportPreview.js index d89d1e02d7a9..eb63135de492 100644 --- a/src/components/ReportActionItem/ReportPreview.js +++ b/src/components/ReportActionItem/ReportPreview.js @@ -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]) @@ -164,7 +164,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); diff --git a/src/languages/en.ts b/src/languages/en.ts index f69f9ea4bedd..16f9cb99930f 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -542,6 +542,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`, diff --git a/src/languages/es.ts b/src/languages/es.ts index 83e09b2a62c0..1e6e0f6683bf 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -534,6 +534,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`, diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index b5fc0bff6ec7..a78336de9659 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -1267,6 +1267,18 @@ 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 @@ -1344,6 +1356,11 @@ function getMoneyRequestReportName(report, policy = undefined) { return `${payerPaidAmountMesssage} • ${Localize.translateLocal('iou.pending')}`; } + if (hasNonReimbursableTransactions(report)) { + return Localize.translateLocal('iou.payerSpentAmount', {payer: payerName, amount: formattedAmount}); + + } + if (report.hasOutstandingIOU) { return Localize.translateLocal('iou.payerOwesAmount', {payer: payerName, amount: formattedAmount}); } @@ -3955,6 +3972,7 @@ export { areAllRequestsBeingSmartScanned, getReportPreviewDisplayTransactions, getTransactionsWithReceipts, + hasNonReimbursableTransactions, hasMissingSmartscanFields, getIOUReportActionDisplayMessage, isWaitingForTaskCompleteFromAssignee, diff --git a/src/libs/TransactionUtils.ts b/src/libs/TransactionUtils.ts index beb1f9c323d6..d5ad481d4b60 100644 --- a/src/libs/TransactionUtils.ts +++ b/src/libs/TransactionUtils.ts @@ -302,6 +302,14 @@ function hasEreceipt(transaction: Transaction): boolean { return !!transaction?.hasEReceipt; } +/** + * Check if the transaction is Non-reimbursable + */ +function isNonReimbursable(transaction: Transaction): boolean { + // We want to specifically check that reimbursable is set to false + return !!(transaction?.reimbursable === false); +} + /** * Get the transactions related to a report preview with receipts * Get the details linked to the IOU reportAction @@ -394,6 +402,7 @@ export { hasRoute, isReceiptBeingScanned, getValidWaypoints, + isNonReimbursable, isDistanceRequest, getWaypoints, hasMissingSmartscanFields, From 99494f44eb77fe3401773a547803c257b6cd9b3d Mon Sep 17 00:00:00 2001 From: Georgia Monahan Date: Wed, 11 Oct 2023 13:05:11 +0100 Subject: [PATCH 2/5] Remove unused function --- src/libs/TransactionUtils.ts | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/libs/TransactionUtils.ts b/src/libs/TransactionUtils.ts index d5ad481d4b60..beb1f9c323d6 100644 --- a/src/libs/TransactionUtils.ts +++ b/src/libs/TransactionUtils.ts @@ -302,14 +302,6 @@ function hasEreceipt(transaction: Transaction): boolean { return !!transaction?.hasEReceipt; } -/** - * Check if the transaction is Non-reimbursable - */ -function isNonReimbursable(transaction: Transaction): boolean { - // We want to specifically check that reimbursable is set to false - return !!(transaction?.reimbursable === false); -} - /** * Get the transactions related to a report preview with receipts * Get the details linked to the IOU reportAction @@ -402,7 +394,6 @@ export { hasRoute, isReceiptBeingScanned, getValidWaypoints, - isNonReimbursable, isDistanceRequest, getWaypoints, hasMissingSmartscanFields, From 167ea638123b66eff50c43a2c6e71dad71ee8465 Mon Sep 17 00:00:00 2001 From: Georgia Monahan Date: Wed, 11 Oct 2023 13:06:09 +0100 Subject: [PATCH 3/5] prettier --- src/components/ReportActionItem/ReportPreview.js | 2 +- src/libs/ReportUtils.js | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/components/ReportActionItem/ReportPreview.js b/src/components/ReportActionItem/ReportPreview.js index eb63135de492..3b7990baef33 100644 --- a/src/components/ReportActionItem/ReportPreview.js +++ b/src/components/ReportActionItem/ReportPreview.js @@ -165,7 +165,7 @@ function ReportPreview(props) { } const managerName = isPolicyExpenseChat ? ReportUtils.getPolicyName(props.chatReport) : ReportUtils.getDisplayNameForParticipant(managerID, true); let paymentVerb = hasNonReimbursableTransactions ? 'iou.payerSpent' : 'iou.payerOwes'; - if (iouSettled || props.iouReport.isWaitingOnBankAccount){ + if (iouSettled || props.iouReport.isWaitingOnBankAccount) { paymentVerb = 'iou.payerPaid'; } return props.translate(paymentVerb, {payer: managerName}); diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index a78336de9659..64cf01bfceb4 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -1278,7 +1278,6 @@ function hasNonReimbursableTransactions(iouReportID) { return _.filter(allTransactions, (transaction) => transaction.reimbursable === false).length > 0; } - /** * @param {Object} report * @param {Object} allReportsDict @@ -1358,7 +1357,6 @@ function getMoneyRequestReportName(report, policy = undefined) { if (hasNonReimbursableTransactions(report)) { return Localize.translateLocal('iou.payerSpentAmount', {payer: payerName, amount: formattedAmount}); - } if (report.hasOutstandingIOU) { From f748a17805628a34e4305f5b6e1f17f2c298e4c8 Mon Sep 17 00:00:00 2001 From: Georgia Monahan Date: Fri, 13 Oct 2023 19:35:38 +0100 Subject: [PATCH 4/5] Update helper functions --- src/libs/ReportUtils.js | 5 +++-- src/libs/actions/IOU.js | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 35df72a0ed1d..d7ec9f52a2d4 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -1355,7 +1355,7 @@ function getMoneyRequestReportName(report, policy = undefined) { return `${payerPaidAmountMesssage} • ${Localize.translateLocal('iou.pending')}`; } - if (hasNonReimbursableTransactions(report)) { + if (hasNonReimbursableTransactions(report.reportID)) { return Localize.translateLocal('iou.payerSpentAmount', {payer: payerName, amount: formattedAmount}); } @@ -1580,7 +1580,8 @@ function getReportPreviewMessage(report, reportAction = {}, shouldConsiderReceip return Localize.translateLocal('iou.waitingOnBankAccount', {submitterDisplayName}); } - return Localize.translateLocal('iou.payerOwesAmount', {payer: payerName, amount: formattedAmount}); + const hasNonReimbursableTransactions = hasNonReimbursableTransactions(report.reportID); + return Localize.translateLocal(hasNonReimbursableTransactions ? 'iou.payerSpentAmount' : 'iou.payerOwesAmount', {payer: payerName, amount: formattedAmount}); } /** diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 7f5f6d74ed67..a95d69243ec8 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -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), }); @@ -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), }); From 8786ad4c1b1f887fb26e197470071822860451e5 Mon Sep 17 00:00:00 2001 From: Georgia Monahan Date: Fri, 13 Oct 2023 19:43:08 +0100 Subject: [PATCH 5/5] fix error with same function/var name --- src/libs/ReportUtils.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index d7ec9f52a2d4..8c8f203f8f18 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -1580,8 +1580,8 @@ function getReportPreviewMessage(report, reportAction = {}, shouldConsiderReceip return Localize.translateLocal('iou.waitingOnBankAccount', {submitterDisplayName}); } - const hasNonReimbursableTransactions = hasNonReimbursableTransactions(report.reportID); - return Localize.translateLocal(hasNonReimbursableTransactions ? 'iou.payerSpentAmount' : 'iou.payerOwesAmount', {payer: payerName, amount: formattedAmount}); + const containsNonReimbursable = hasNonReimbursableTransactions(report.reportID); + return Localize.translateLocal(containsNonReimbursable ? 'iou.payerSpentAmount' : 'iou.payerOwesAmount', {payer: payerName, amount: formattedAmount}); } /**