Skip to content

Commit

Permalink
Edits to the export to ensure the actual amounts are shown without ro…
Browse files Browse the repository at this point in the history
…unding or the currency sign
  • Loading branch information
dr-bizz committed Oct 16, 2024
1 parent 08d8f6b commit 6249be4
Showing 1 changed file with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 });
Expand Down Expand Up @@ -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)}`
: '',
],
];
Expand Down

0 comments on commit 6249be4

Please sign in to comment.