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
2 changes: 1 addition & 1 deletion src/components/ReportActionItem/MoneyReportView.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function MoneyReportView(props) {
const {totalDisplaySpend, nonReimbursableSpend, reimbursableSpend} = ReportUtils.getMoneyRequestSpendBreakdown(props.report);

const shouldShowBreakdown = nonReimbursableSpend && reimbursableSpend;
const formattedTotalAmount = CurrencyUtils.convertToDisplayString(totalDisplaySpend, props.report.currency);
const formattedTotalAmount = CurrencyUtils.convertToDisplayString(totalDisplaySpend, props.report.currency, ReportUtils.hasOnlyDistanceRequestTransactions(props.report.reportID));
const formattedOutOfPocketAmount = CurrencyUtils.convertToDisplayString(reimbursableSpend, props.report.currency);
const formattedCompanySpendAmount = CurrencyUtils.convertToDisplayString(nonReimbursableSpend, props.report.currency);

Expand Down
4 changes: 4 additions & 0 deletions src/components/ReportActionItem/ReportPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ function ReportPreview(props) {
const transactionsWithReceipts = ReportUtils.getTransactionsWithReceipts(props.iouReportID);
const numberOfScanningReceipts = _.filter(transactionsWithReceipts, (transaction) => TransactionUtils.isReceiptBeingScanned(transaction)).length;
const hasReceipts = transactionsWithReceipts.length > 0;
const hasOnlyDistanceRequests = ReportUtils.hasOnlyDistanceRequestTransactions(props.iouReportID);
const isScanning = hasReceipts && ReportUtils.areAllRequestsBeingSmartScanned(props.iouReportID, props.action);
const hasErrors = hasReceipts && ReportUtils.hasMissingSmartscanFields(props.iouReportID);
const lastThreeTransactionsWithReceipts = transactionsWithReceipts.slice(-3);
Expand All @@ -145,6 +146,9 @@ function ReportPreview(props) {
if (isScanning) {
return props.translate('iou.receiptScanning');
}
if (hasOnlyDistanceRequests) {
return props.translate('common.tbd');
}

// If iouReport is not available, get amount from the action message (Ex: "Domain20821's Workspace owes $33.00" or "paid ₫60" or "paid -₫60 elsewhere")
let displayAmount = '';
Expand Down
8 changes: 7 additions & 1 deletion src/libs/CurrencyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Onyx from 'react-native-onyx';
import ONYXKEYS, {OnyxValues} from '../ONYXKEYS';
import CONST from '../CONST';
import BaseLocaleListener from './Localize/LocaleListener/BaseLocaleListener';
import * as Localize from './Localize';
import * as NumberFormatUtils from './NumberFormatUtils';

let currencyList: OnyxValues[typeof ONYXKEYS.CURRENCY_LIST] = {};
Expand Down Expand Up @@ -96,8 +97,13 @@ function convertToFrontendAmount(amountAsInt: number): number {
*
* @param amountInCents – should be an integer. Anything after a decimal place will be dropped.
* @param currency - IOU currency
* @param shouldFallbackToTbd - whether to return 'TBD' instead of a falsy value (e.g. 0.00)
*/
function convertToDisplayString(amountInCents: number, currency: string = CONST.CURRENCY.USD): string {
function convertToDisplayString(amountInCents: number, currency: string = CONST.CURRENCY.USD, shouldFallbackToTbd = false): string {
if (shouldFallbackToTbd && !amountInCents) {
return Localize.translateLocal('common.tbd');
}

const convertedAmount = convertToFrontendAmount(amountInCents);
return NumberFormatUtils.format(BaseLocaleListener.getPreferredLocale(), convertedAmount, {
style: 'currency',
Expand Down
26 changes: 19 additions & 7 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,17 @@ function hasSingleParticipant(report) {
return report && report.participantAccountIDs && report.participantAccountIDs.length === 1;
}

/**
* Checks whether all the transactions linked to the IOU report are of the Distance Request type
*
* @param {string|null} iouReportID
* @returns {boolean}
*/
function hasOnlyDistanceRequestTransactions(iouReportID) {
const allTransactions = TransactionUtils.getAllReportTransactions(iouReportID);
return _.all(allTransactions, (transaction) => TransactionUtils.isDistanceRequest(transaction));
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't find the link or doc, but I thought we're going to prioritize using the built-in methods over lodash if they exist. We could use

    return allTransactions.every(transaction => TransactionUtils.isDistanceRequest(transaction));

@Julesssss Can you confirm this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I understand, this is more related to TypeScript, as it's more fail-safe. But if you insist, I can change to .every here

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am also not 100% sure on this one.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then I would like to keep it as is until the file is migrated to TypeScript, just to make it consistent with the rest of the functions

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets stick with the current solution

}

/**
* If the report is a thread and has a chat type set, it is a workspace chat.
*
Expand Down Expand Up @@ -1415,23 +1426,23 @@ function getPolicyExpenseChatName(report, policy = undefined) {
}

/**
* Get the title for a IOU or expense chat which will be showing the payer and the amount
* Get the title for an IOU or expense chat which will be showing the payer and the amount
*
* @param {Object} report
* @param {Object} [policy]
* @returns {String}
*/
function getMoneyRequestReportName(report, policy = undefined) {
const moneyRequestTotal = getMoneyRequestReimbursableTotal(report);
const formattedAmount = CurrencyUtils.convertToDisplayString(moneyRequestTotal, report.currency);
const formattedAmount = CurrencyUtils.convertToDisplayString(moneyRequestTotal, report.currency, hasOnlyDistanceRequestTransactions(report.reportID));
const payerName = isExpenseReport(report) ? getPolicyName(report, false, policy) : getDisplayNameForParticipant(report.managerID);
const payerPaidAmountMesssage = Localize.translateLocal('iou.payerPaidAmount', {
const payerPaidAmountMessage = Localize.translateLocal('iou.payerPaidAmount', {
payer: payerName,
amount: formattedAmount,
});

if (report.isWaitingOnBankAccount) {
return `${payerPaidAmountMesssage} • ${Localize.translateLocal('iou.pending')}`;
return `${payerPaidAmountMessage} • ${Localize.translateLocal('iou.pending')}`;
}

if (hasNonReimbursableTransactions(report.reportID)) {
Expand All @@ -1442,7 +1453,7 @@ function getMoneyRequestReportName(report, policy = undefined) {
return Localize.translateLocal('iou.payerOwesAmount', {payer: payerName, amount: formattedAmount});
}

return payerPaidAmountMesssage;
return payerPaidAmountMessage;
}

/**
Expand Down Expand Up @@ -1527,7 +1538,7 @@ function canEditReportAction(reportAction) {
/**
* Gets all transactions on an IOU report with a receipt
*
* @param {Object|null} iouReportID
* @param {string|null} iouReportID
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure we're getting a string here? I thought transactions is an object?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're not getting – it's the input parameter of the function, iouReportID.

* @returns {[Object]}
*/
function getTransactionsWithReceipts(iouReportID) {
Expand Down Expand Up @@ -1593,7 +1604,7 @@ function getTransactionReportName(reportAction) {
const {amount, currency, comment} = getTransactionDetails(transaction);

return Localize.translateLocal(ReportActionsUtils.isSentMoneyReportAction(reportAction) ? 'iou.threadSentMoneyReportName' : 'iou.threadRequestReportName', {
formattedAmount: CurrencyUtils.convertToDisplayString(amount, currency),
formattedAmount: CurrencyUtils.convertToDisplayString(amount, currency, TransactionUtils.isDistanceRequest(transaction)),
comment,
});
}
Expand Down Expand Up @@ -4079,6 +4090,7 @@ export {
buildTransactionThread,
areAllRequestsBeingSmartScanned,
getTransactionsWithReceipts,
hasOnlyDistanceRequestTransactions,
hasNonReimbursableTransactions,
hasMissingSmartscanFields,
getIOUReportActionDisplayMessage,
Expand Down