diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index fec64efaac7f..978685a9be2d 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -2783,7 +2783,7 @@ function getModifiedExpenseOriginalMessage( } if ('taxCode' in transactionChanges) { - originalMessage.oldTaxRate = policy?.taxRates?.taxes[TransactionUtils.getTaxCode(oldTransaction)].value; + originalMessage.oldTaxRate = policy?.taxRates?.taxes[TransactionUtils.getTaxCode(oldTransaction)]?.value; originalMessage.taxRate = transactionChanges?.taxCode && policy?.taxRates?.taxes[transactionChanges?.taxCode].value; } diff --git a/src/libs/TransactionUtils.ts b/src/libs/TransactionUtils.ts index af28133ecf3f..4244f20d0bc3 100644 --- a/src/libs/TransactionUtils.ts +++ b/src/libs/TransactionUtils.ts @@ -625,7 +625,7 @@ function getEnabledTaxRateCount(options: TaxRates) { */ function getDefaultTaxName(taxRates: TaxRatesWithDefault, transaction?: Transaction) { const defaultTaxKey = taxRates.defaultExternalID; - const defaultTaxName = (defaultTaxKey && `${taxRates.taxes[defaultTaxKey].name} (${taxRates.taxes[defaultTaxKey].value}) • ${Localize.translateLocal('common.default')}`) || ''; + const defaultTaxName = (defaultTaxKey && `${taxRates.taxes[defaultTaxKey]?.name} (${taxRates.taxes[defaultTaxKey]?.value}) • ${Localize.translateLocal('common.default')}`) || ''; return transaction?.taxRate?.text ?? defaultTaxName; } @@ -633,9 +633,9 @@ function getDefaultTaxName(taxRates: TaxRatesWithDefault, transaction?: Transact * Gets the tax name */ function getTaxName(taxes: TaxRates, transactionTaxCode: string) { - const taxName = `${taxes[transactionTaxCode].name}`; - const taxValue = `${taxes[transactionTaxCode].value}`; - return transactionTaxCode ? `${taxName} (${taxValue})` : ''; + const taxName = taxes[transactionTaxCode]?.name ?? ''; + const taxValue = taxes[transactionTaxCode]?.value ?? ''; + return transactionTaxCode && taxName && taxValue ? `${taxName} (${taxValue})` : ''; } export { diff --git a/src/pages/EditRequestPage.js b/src/pages/EditRequestPage.js index ec49e32a5f0f..bef826300af2 100644 --- a/src/pages/EditRequestPage.js +++ b/src/pages/EditRequestPage.js @@ -73,7 +73,7 @@ const defaultProps = { }; const getTaxAmount = (transactionAmount, transactionTaxCode, taxRates) => { - const percentage = (transactionTaxCode ? taxRates.taxes[transactionTaxCode].value : taxRates.defaultValue) || ''; + const percentage = (transactionTaxCode && taxRates.taxes[transactionTaxCode] ? taxRates.taxes[transactionTaxCode].value : taxRates.defaultValue) || ''; return CurrencyUtils.convertToBackendAmount(Number.parseFloat(TransactionUtils.calculateTaxAmount(percentage, transactionAmount))); };