diff --git a/src/components/Reports/FinancialAccountsReport/AccountTransactions/AccountTransactions.tsx b/src/components/Reports/FinancialAccountsReport/AccountTransactions/AccountTransactions.tsx index 3a60253bff..2d6f872c0e 100644 --- a/src/components/Reports/FinancialAccountsReport/AccountTransactions/AccountTransactions.tsx +++ b/src/components/Reports/FinancialAccountsReport/AccountTransactions/AccountTransactions.tsx @@ -9,8 +9,7 @@ import { headerHeight } from 'src/components/Shared/Header/ListHeader'; import { useDebouncedValue } from 'src/hooks/useDebounce'; import useGetAppSettings from 'src/hooks/useGetAppSettings'; import { useLocale } from 'src/hooks/useLocale'; -import { currencyFormat, dateFormatShort } from 'src/lib/intlFormat'; -import { formatNumber } from '../AccountSummary/AccountSummaryHelper'; +import { dateFormatShort } from 'src/lib/intlFormat'; import { FinancialAccountContext, FinancialAccountType, @@ -27,6 +26,25 @@ const Container = styled(Box)(() => ({ overflowY: 'auto', })); +/** + * Converts the "amount" string to a number to remove ".0" + * If the value is 0 or isExpense is true, it returns the value as is. + * Otherwise, it removes the '-' character if present, or prepends it if absent. + */ +const formatAmountForExport = ( + amount?: string | null, + isExpense?: boolean, +): number => { + if (!amount) { + return 0; + } + + if (amount === '0' || isExpense) { + return Number(amount); + } + return amount?.[0] === '-' ? Number(amount.substring(1)) : -Number(amount); +}; + const formatDateRange = (startDate?: DateTime, endDate?: DateTime) => { if (!startDate) { startDate = DateTime.local().minus({ months: 1 }).plus({ days: 1 }); @@ -129,18 +147,10 @@ export const AccountTransactions: React.FC = () => { entry.description ?? '', entry.category?.name ?? entry.category?.code ?? '', entry.type === FinancialAccountEntryTypeEnum.Debit - ? currencyFormat( - formatNumber(entry.amount), - entry.currency, - locale, - ).replace(/[\xA0\u2000-\u200B\uFEFF]/g, ' ') + ? `${formatAmountForExport(entry.amount, true)}` : '', entry.type === FinancialAccountEntryTypeEnum.Credit - ? currencyFormat( - formatNumber(entry.amount), - entry.currency, - locale, - ).replace(/[\xA0\u2000-\u200B\uFEFF]/g, ' ') + ? `${formatAmountForExport(entry.amount)}` : '', ], ];