Skip to content

A local-first personal finance app

feat(currency): add to reports (#5283)

Michael Süssemilch74b95ca83ebc
diff --git a/packages/desktop-client/src/components/reports/Change.test.tsx b/packages/desktop-client/src/components/reports/Change.test.tsx
index 1cd3767c45..697ac2249e 100644
--- a/packages/desktop-client/src/components/reports/Change.test.tsx
+++ b/packages/desktop-client/src/components/reports/Change.test.tsx
@@ -1,34 +1,53 @@
import React from 'react';
+import { Provider } from 'react-redux';
import { theme } from '@actual-app/components/theme';
import { render, screen } from '@testing-library/react';
import { Change } from './Change';
+import { store } from '@desktop-client/redux/store';
+
describe('Change', () => {
it('renders a positive amount with a plus sign and green color', () => {
- render(<Change amount={12345} />);
+ render(
+ <Provider store={store}>
+ <Change amount={12345} />
+ </Provider>,
+ );
const el = screen.getByText('+123.45');
expect(el).toBeInTheDocument();
expect(el).toHaveStyle(`color: ${theme.noticeTextLight}`);
});
it('renders zero with a plus sign and green color', () => {
- render(<Change amount={0} />);
+ render(
+ <Provider store={store}>
+ <Change amount={0} />
+ </Provider>,
+ );
const el = screen.getByText('+0.00');
expect(el).toBeInTheDocument();
expect(el).toHaveStyle(`color: ${theme.noticeTextLight}`);
});
it('renders a negative amount with a minus sign and red color', () => {
- render(<Change amount={-9876} />);
+ render(
+ <Provider store={store}>
+ <Change amount={-9876} />
+ </Provider>,
+ );
const el = screen.getByText('-98.76');
expect(el).toBeInTheDocument();
expect(el).toHaveStyle(`color: ${theme.errorText}`);
});
it('merges custom style prop', () => {
- render(<Change amount={1000} style={{ fontWeight: 'bold' }} />);
+ render(
+ <Provider store={store}>
+ <Change amount={1000} style={{ fontWeight: 'bold' }} />
+ </Provider>,
+ );
const el = screen.getByText('+10.00');
expect(el).toHaveStyle('font-weight: bold');
expect(el).toHaveStyle(`color: ${theme.noticeTextLight}`);
diff --git a/packages/desktop-client/src/components/reports/Change.tsx b/packages/desktop-client/src/components/reports/Change.tsx
index 0face74c2b..f2682190a5 100644
--- a/packages/desktop-client/src/components/reports/Change.tsx
+++ b/packages/desktop-client/src/components/reports/Change.tsx
@@ -4,7 +4,7 @@ import { Block } from '@actual-app/components/block';
import { styles } from '@actual-app/components/styles';
import { theme } from '@actual-app/components/theme';
-import { integerToCurrency } from 'loot-core/shared/util';
+import { useFormat } from '@desktop-client/hooks/useFormat';
export function Change({
amount,
@@ -13,6 +13,8 @@ export function Change({
amount: number;
style?: CSSProperties;
}) {
+ const format = useFormat();
+
return (
<Block
style={{
@@ -22,7 +24,7 @@ export function Change({
}}
>
{amount >= 0 ? '+' : ''}
- {integerToCurrency(amount)}
+ {format(amount, 'financial')}
</Block>
);
}
diff --git a/packages/desktop-client/src/components/reports/ReportSummary.tsx b/packages/desktop-client/src/components/reports/ReportSummary.tsx
index 66557eee68..dd50269e3b 100644
--- a/packages/desktop-client/src/components/reports/ReportSummary.tsx
+++ b/packages/desktop-client/src/components/reports/ReportSummary.tsx
@@ -7,11 +7,6 @@ import { theme } from '@actual-app/components/theme';
import { View } from '@actual-app/components/view';
import * as monthUtils from 'loot-core/shared/months';
-import {
- amountToCurrency,
- integerToCurrency,
- amountToInteger,
-} from 'loot-core/shared/util';
import {
type balanceTypeOpType,
type DataEntity,
@@ -20,6 +15,7 @@ import {
import { ReportOptions } from './ReportOptions';
import { PrivacyFilter } from '@desktop-client/components/PrivacyFilter';
+import { useFormat } from '@desktop-client/hooks/useFormat';
import { useLocale } from '@desktop-client/hooks/useLocale';
type ReportSummaryProps = {
@@ -41,6 +37,8 @@ export function ReportSummary({
}: ReportSummaryProps) {
const locale = useLocale();
const { t } = useTranslation();
+ const format = useFormat();
+
const net =
balanceTypeOp === 'netAssets'
? t('DEPOSIT')
@@ -49,7 +47,7 @@ export function ReportSummary({
: Math.abs(data.totalDebts) > Math.abs(data.totalAssets)
? t('PAYMENT')
: t('DEPOSIT');
- const average = amountToInteger(data[balanceTypeOp]) / intervalsCount;
+ const average = Math.round(data[balanceTypeOp] / intervalsCount);
return (
<View
style={{
@@ -127,7 +125,9 @@ export function ReportSummary({
fontWeight: 800,
}}
>
- <PrivacyFilter>{amountToCurrency(data[balanceTypeOp])}</PrivacyFilter>
+ <PrivacyFilter>
+ {format(data[balanceTypeOp], 'financial')}
+ </PrivacyFilter>
</Text>
<Text style={{ fontWeight: 600 }}>
<Trans>For this time period</Trans>
@@ -165,7 +165,7 @@ export function ReportSummary({
}}
>
<PrivacyFilter>
- {!isNaN(average) && integerToCurrency(Math.round(average))}
+ {!isNaN(average) && format(average, 'financial')}
</PrivacyFilter>
</Text>
<Text style={{ fontWeight: 600 }}>
diff --git a/packages/desktop-client/src/components/reports/SummaryNumber.tsx b/packages/desktop-client/src/components/reports/SummaryNumber.tsx
index 8cb6cc4507..bdbcc6ebb9 100644
--- a/packages/desktop-client/src/components/reports/SummaryNumber.tsx
+++ b/packages/desktop-client/src/components/reports/SummaryNumber.tsx
@@ -4,12 +4,11 @@ import { useTranslation } from 'react-i18next';
import { View } from '@actual-app/components/view';
import { debounce } from 'debounce';
-import { amountToCurrency } from 'loot-core/shared/util';
-
import { chartTheme } from './chart-theme';
import { LoadingIndicator } from './LoadingIndicator';
import { PrivacyFilter } from '@desktop-client/components/PrivacyFilter';
+import { useFormat } from '@desktop-client/hooks/useFormat';
import { useMergedRefs } from '@desktop-client/hooks/useMergedRefs';
import { useResizeObserver } from '@desktop-client/hooks/useResizeObserver';
@@ -18,6 +17,7 @@ const CONTAINER_MARGIN = 8;
type SummaryNumberProps = {
value: number;
+ contentType: string;
animate?: boolean;
suffix?: string;
loading?: boolean;
@@ -27,6 +27,7 @@ type SummaryNumberProps = {
export function SummaryNumber({
value,
+ contentType,
animate = false,
suffix = '',
loading = true,
@@ -36,7 +37,14 @@ export function SummaryNumber({
const { t } = useTranslation();
const [fontSize, setFontSize] = useState<number>(initialFontSize);
const refDiv = useRef<HTMLDivElement>(null);
- const displayAmount = amountToCurrency(Math.abs(value)) + suffix;
+ const format = useFormat();
+
+ let displayAmount =
+ contentType === 'percentage'
+ ? format(Math.abs(value), 'number')
+ : format(Math.round(value), 'financial');
+
+ displayAmount += suffix;
const handleResize = debounce(() => {
if (!refDiv.current) return;
diff --git a/packages/desktop-client/src/components/reports/graphs/AreaGraph.tsx b/packages/desktop-client/src/components/reports/graphs/AreaGraph.tsx
index 7facee1e27..bb13052c69 100644
--- a/packages/desktop-client/src/components/reports/graphs/AreaGraph.tsx
+++ b/packages/desktop-client/src/components/reports/graphs/AreaGraph.tsx
@@ -15,10 +15,6 @@ import {
ResponsiveContainer,
} from 'recharts';
-import {
- amountToCurrency,
- amountToCurrencyNoDecimal,
-} from 'loot-core/shared/util';
import {
type balanceTypeOpType,
type DataEntity,
@@ -28,6 +24,7 @@ import { adjustTextSize } from './adjustTextSize';
import { renderCustomLabel } from './renderCustomLabel';
import { Container } from '@desktop-client/components/reports/Container';
+import { type FormatType, useFormat } from '@desktop-client/hooks/useFormat';
import { usePrivacyMode } from '@desktop-client/hooks/usePrivacyMode';
type PayloadItem = {
@@ -45,12 +42,14 @@ type CustomTooltipProps = {
active?: boolean;
payload?: PayloadItem[];
balanceTypeOp: balanceTypeOpType;
+ format: (value: unknown, type: FormatType) => string;
};
const CustomTooltip = ({
active,
payload,
balanceTypeOp,
+ format,
}: CustomTooltipProps) => {
const { t } = useTranslation();
@@ -75,25 +74,25 @@ const CustomTooltip = ({
{['totalAssets', 'totalTotals'].includes(balanceTypeOp) && (
<AlignedText
left={t('Assets:')}
- right={amountToCurrency(payload[0].payload.totalAssets)}
+ right={format(payload[0].payload.totalAssets, 'financial')}
/>
)}
{['totalDebts', 'totalTotals'].includes(balanceTypeOp) && (
<AlignedText
left={t('Debts:')}
- right={amountToCurrency(payload[0].payload.totalDebts)}
+ right={format(payload[0].payload.totalDebts, 'financial')}
/>
)}
{['netAssets'].includes(balanceTypeOp) && (
<AlignedText
left={t('Net Assets:')}
- right={amountToCurrency(payload[0].payload.netAssets)}
+ right={format(payload[0].payload.netAssets, 'financial')}
/>
)}
{['netDebts'].includes(balanceTypeOp) && (
<AlignedText
left={t('Net Debts:')}
- right={amountToCurrency(payload[0].payload.netDebts)}
+ right={format(payload[0].payload.netDebts, 'financial')}
/>
)}
{['totalTotals'].includes(balanceTypeOp) && (
@@ -101,7 +100,7 @@ const CustomTooltip = ({
left={t('Net:')}
right={
<strong>
- {amountToCurrency(payload[0].payload.totalTotals)}
+ {format(payload[0].payload.totalTotals, 'financial')}
</strong>
}
/>
@@ -127,10 +126,12 @@ const customLabel = ({
props,
width,
end,
+ format,
}: {
props: PropsItem;
width: number;
end: number;
+ format: (value: unknown, type: FormatType) => string;
}) => {
//Add margin to first and last object
const calcX =
@@ -142,7 +143,7 @@ const customLabel = ({
const textAnchor = props.index === 0 ? 'left' : 'middle';
const display =
typeof props.value !== 'string' && props.value !== 0
- ? `${amountToCurrencyNoDecimal(props.value || 0)}`
+ ? `${format(props.value || 0, 'financial-no-decimals')}`
: '';
const textSize = adjustTextSize({ sized: width, type: 'area' });
@@ -166,6 +167,8 @@ export function AreaGraph({
viewLabels,
showTooltip = true,
}: AreaGraphProps) {
+ const format = useFormat();
+
const privacyMode = usePrivacyMode();
const dataMax = Math.max(...data.intervalData.map(i => i[balanceTypeOp]));
const dataMin = Math.min(...data.intervalData.map(i => i[balanceTypeOp]));
@@ -189,7 +192,7 @@ export function AreaGraph({
const lastLabel = data.intervalData.length - 1;
const tickFormatter = (tick: number) => {
- if (!privacyMode) return `${amountToCurrencyNoDecimal(tick)}`; // Formats the tick values as strings with commas
+ if (!privacyMode) return `${format(tick, 'financial-no-decimals')}`; // Formats the tick values as strings with commas
return '...';
};
@@ -255,7 +258,12 @@ export function AreaGraph({
)}
{showTooltip && (
<Tooltip
- content={<CustomTooltip balanceTypeOp={balanceTypeOp} />}
+ content={
+ <CustomTooltip
+ balanceTypeOp={balanceTypeOp}
+ format={format}
+ />
+ }
isAnimationActive={false}
/>
)}
@@ -312,7 +320,12 @@ export function AreaGraph({
<LabelList
dataKey={balanceTypeOp}
content={props =>
- customLabel({ props, width, end: lastLabel })
+ customLabel({
+ props,
+ width,
+ end: lastLabel,
+ format,
+ })
}
/>
)}
diff --git a/packages/desktop-client/src/components/reports/graphs/BarGraph.tsx b/packages/desktop-client/src/components/reports/graphs/BarGraph.tsx
index 166fa1782f..80bf4c4230 100644
--- a/packages/desktop-client/src/components/reports/graphs/BarGraph.tsx
+++ b/packages/desktop-client/src/components/reports/graphs/BarGraph.tsx
@@ -18,10 +18,6 @@ import {
ResponsiveContainer,
} from 'recharts';
-import {
- amountToCurrency,
- amountToCurrencyNoDecimal,
-} from 'loot-core/shared/util';
import {
type balanceTypeOpType,
type DataEntity,
@@ -37,6 +33,7 @@ import { getCustomTick } from '@desktop-client/components/reports/getCustomTick'
import { numberFormatterTooltip } from '@desktop-client/components/reports/numberFormatter';
import { useAccounts } from '@desktop-client/hooks/useAccounts';
import { useCategories } from '@desktop-client/hooks/useCategories';
+import { type FormatType, useFormat } from '@desktop-client/hooks/useFormat';
import { useNavigate } from '@desktop-client/hooks/useNavigate';
import { usePrivacyMode } from '@desktop-client/hooks/usePrivacyMode';
@@ -66,6 +63,7 @@ type CustomTooltipProps = {
payload?: PayloadItem[];
balanceTypeOp?: balanceTypeOpType;
yAxis?: string;
+ format: (value: unknown, type: FormatType) => string;
};
const CustomTooltip = ({
@@ -73,6 +71,7 @@ const CustomTooltip = ({
payload,
balanceTypeOp,
yAxis,
+ format,
}: CustomTooltipProps) => {
const { t } = useTranslation();
@@ -97,25 +96,25 @@ const CustomTooltip = ({
{['totalAssets', 'totalTotals'].includes(balanceTypeOp) && (
<AlignedText
left={t('Assets:')}
- right={amountToCurrency(payload[0].payload.totalAssets)}
+ right={format(payload[0].payload.totalAssets, 'financial')}
/>
)}
{['totalDebts', 'totalTotals'].includes(balanceTypeOp) && (
<AlignedText
left={t('Debts:')}
- right={amountToCurrency(payload[0].payload.totalDebts)}
+ right={format(payload[0].payload.totalDebts, 'financial')}
/>
)}
{['netAssets'].includes(balanceTypeOp) && (
<AlignedText
left={t('Net Assets:')}
- right={amountToCurrency(payload[0].payload.netAssets)}
+ right={format(payload[0].payload.netAssets, 'financial')}
/>
)}
{['netDebts'].includes(balanceTypeOp) && (
<AlignedText
left={t('Net Debts:')}
- right={amountToCurrency(payload[0].payload.netDebts)}
+ right={format(payload[0].payload.netDebts, 'financial')}
/>
)}
{['totalTotals'].includes(balanceTypeOp) && (
@@ -123,7 +122,7 @@ const CustomTooltip = ({
left={t('Net:')}
right={
<strong>
- {amountToCurrency(payload[0].payload.totalTotals)}
+ {format(payload[0].payload.totalTotals, 'financial')}
</strong>
}
/>
@@ -135,12 +134,12 @@ const CustomTooltip = ({
}
};
-const customLabel = (props, typeOp) => {
+const customLabel = (props, typeOp, format) => {
const calcX = props.x + props.width / 2;
const calcY = props.y - (props.value > 0 ? 15 : -15);
const textAnchor = 'middle';
const display =
- props.value !== 0 && `${amountToCurrencyNoDecimal(props.value)}`;
+ props.value !== 0 && `${format(props.value, 'financial-no-decimals')}`;
const textSize = adjustTextSize({
sized: props.width,
type: typeOp === 'totalTotals' ? 'default' : 'variable',
@@ -179,6 +178,8 @@ export function BarGraph({
const categories = useCategories();
const accounts = useAccounts();
const privacyMode = usePrivacyMode();
+ const format = useFormat();
+
const [pointer, setPointer] = useState('');
const yAxis = groupBy === 'Interval' ? 'date' : 'name';
@@ -235,6 +236,7 @@ export function BarGraph({
<CustomTooltip
balanceTypeOp={balanceTypeOp}
yAxis={yAxis}
+ format={format}
/>
}
formatter={numberFormatterTooltip}
@@ -256,7 +258,7 @@ export function BarGraph({
<YAxis
tickFormatter={value =>
getCustomTick(
- amountToCurrencyNoDecimal(value),
+ format(value, 'financial-no-decimals'),
privacyMode,
)
}
@@ -298,7 +300,7 @@ export function BarGraph({
{viewLabels && !compact && (
<LabelList
dataKey={val => getVal(val)}
- content={e => customLabel(e, balanceTypeOp)}
+ content={e => customLabel(e, balanceTypeOp, format)}
/>
)}
{data.legend.map((entry, index) => (
diff --git a/packages/desktop-client/src/components/reports/graphs/BarLineGraph.tsx b/packages/desktop-client/src/components/reports/graphs/BarLineGraph.tsx
index 12f9de2e71..3d98d3512a 100644
--- a/packages/desktop-client/src/components/reports/graphs/BarLineGraph.tsx
+++ b/packages/desktop-client/src/components/reports/graphs/BarLineGraph.tsx
@@ -16,11 +16,10 @@ import {
ResponsiveContainer,
} from 'recharts';
-import { amountToCurrencyNoDecimal } from 'loot-core/shared/util';
-
import { PrivacyFilter } from '@desktop-client/components/PrivacyFilter';
import { Container } from '@desktop-client/components/reports/Container';
import { numberFormatterTooltip } from '@desktop-client/components/reports/numberFormatter';
+import { useFormat } from '@desktop-client/hooks/useFormat';
type PayloadItem = {
payload: {
@@ -89,8 +88,9 @@ export function BarLineGraph({
compact,
showTooltip = true,
}: BarLineGraphProps) {
+ const format = useFormat();
const tickFormatter = tick => {
- return `${amountToCurrencyNoDecimal(Math.round(tick))}`; // Formats the tick values as strings with commas
+ return `${format(Math.round(tick), 'financial')}`; // Formats the tick values as strings with commas
};
return (
diff --git a/packages/desktop-client/src/components/reports/graphs/CalendarGraph.tsx b/packages/desktop-client/src/components/reports/graphs/CalendarGraph.tsx
index c4a9df8dc8..c35bdc5e6e 100644
--- a/packages/desktop-client/src/components/reports/graphs/CalendarGraph.tsx
+++ b/packages/desktop-client/src/components/reports/graphs/CalendarGraph.tsx
@@ -8,18 +8,18 @@ import { Tooltip } from '@actual-app/components/tooltip';
import { View } from '@actual-app/components/view';
import {
addDays,
- format,
+ format as formatDate,
getDate,
isSameMonth,
startOfMonth,
startOfWeek,
} from 'date-fns';
-import { amountToCurrency } from 'loot-core/shared/util';
import { type SyncedPrefs } from 'loot-core/types/prefs';
import { PrivacyFilter } from '@desktop-client/components/PrivacyFilter';
import { chartTheme } from '@desktop-client/components/reports/chart-theme';
+import { useFormat } from '@desktop-client/hooks/useFormat';
import { useResizeObserver } from '@desktop-client/hooks/useResizeObserver';
type CalendarGraphProps = {
@@ -42,6 +42,8 @@ export function CalendarGraph({
isEditing,
onDayClick,
}: CalendarGraphProps) {
+ const format = useFormat();
+
const startingDate = startOfWeek(new Date(), {
weekStartsOn:
firstDayOfWeekIdx !== undefined &&
@@ -88,7 +90,7 @@ export function CalendarGraph({
marginBottom: 4,
}}
>
- {format(addDays(startingDate, index), 'EEEEE')}
+ {formatDate(addDays(startingDate, index), 'EEEEE')}
</View>
))}
</View>
@@ -115,7 +117,7 @@ export function CalendarGraph({
content={
<View>
<View style={{ marginBottom: 10 }}>
- <strong>{format(day.date, 'MMM dd')}</strong>
+ <strong>{formatDate(day.date, 'MMM dd')}</strong>
</View>
<View style={{ lineHeight: 1.5 }}>
<View
@@ -141,7 +143,7 @@ export function CalendarGraph({
>
{day.incomeValue !== 0 ? (
<PrivacyFilter>
- {amountToCurrency(day.incomeValue)}
+ {format(day.incomeValue, 'financial')}
</PrivacyFilter>
) : (
''
@@ -170,7 +172,7 @@ export function CalendarGraph({
>
{day.expenseValue !== 0 ? (
<PrivacyFilter>
- {amountToCurrency(day.expenseValue)}
+ {format(day.expenseValue, 'financial')}
</PrivacyFilter>
) : (
''
@@ -245,7 +247,7 @@ function DayButton({ day, onPress, fontSize, resizeRef }: DayButtonProps) {
return (
<Button
ref={resizeRef}
- aria-label={format(day.date, 'MMMM d, yyyy')}
+ aria-label={formatDate(day.date, 'MMMM d, yyyy')}
style={{
borderColor: 'transparent',
backgroundColor: theme.calendarCellBackground,
diff --git a/packages/desktop-client/src/components/reports/graphs/CashFlowGraph.tsx b/packages/desktop-client/src/components/reports/graphs/CashFlowGraph.tsx
index 0385a8a615..95dc115ad3 100644
--- a/packages/desktop-client/src/components/reports/graphs/CashFlowGraph.tsx
+++ b/packages/desktop-client/src/components/reports/graphs/CashFlowGraph.tsx
@@ -18,13 +18,9 @@ import {
type TooltipProps,
} from 'recharts';
-import {
- amountToCurrency,
- amountToCurrencyNoDecimal,
-} from 'loot-core/shared/util';
-
import { chartTheme } from '@desktop-client/components/reports/chart-theme';
import { Container } from '@desktop-client/components/reports/Container';
+import { type FormatType, useFormat } from '@desktop-client/hooks/useFormat';
import { useLocale } from '@desktop-client/hooks/useLocale';
import { usePrivacyMode } from '@desktop-client/hooks/usePrivacyMode';
@@ -33,9 +29,15 @@ const ANIMATION_DURATION = 1000; // in ms
type CustomTooltipProps = TooltipProps<number, 'date'> & {
isConcise: boolean;
+ format: (value: unknown, type?: FormatType) => string;
};
-function CustomTooltip({ active, payload, isConcise }: CustomTooltipProps) {
+function CustomTooltip({
+ active,
+ payload,
+ isConcise,
+ format,
+}: CustomTooltipProps) {
const locale = useLocale();
const { t } = useTranslation();
@@ -67,27 +69,29 @@ function CustomTooltip({ active, payload, isConcise }: CustomTooltipProps) {
<div style={{ lineHeight: 1.5 }}>
<AlignedText
left={t('Income:')}
- right={amountToCurrency(data.income)}
+ right={format(data.income, 'financial')}
/>
<AlignedText
left={t('Expenses:')}
- right={amountToCurrency(data.expenses)}
+ right={format(data.expenses, 'financial')}
/>
<AlignedText
left={t('Change:')}
right={
- <strong>{amountToCurrency(data.income + data.expenses)}</strong>
+ <strong>
+ {format(data.income + data.expenses, 'financial')}
+ </strong>
}
/>
{data.transfers !== 0 && (
<AlignedText
left={t('Transfers:')}
- right={amountToCurrency(data.transfers)}
+ right={format(data.transfers, 'financial')}
/>
)}
<AlignedText
left={t('Balance:')}
- right={amountToCurrency(data.balance)}
+ right={format(data.balance, 'financial')}
/>
</div>
</div>
@@ -115,6 +119,7 @@ export function CashFlowGraph({
const locale = useLocale();
const privacyMode = usePrivacyMode();
const [yAxisIsHovered, setYAxisIsHovered] = useState(false);
+ const format = useFormat();
const data = graphData.expenses.map((row, idx) => ({
date: row.x,
@@ -152,7 +157,7 @@ export function CashFlowGraph({
tickFormatter={value =>
privacyMode && !yAxisIsHovered
? '...'
- : amountToCurrencyNoDecimal(value)
+ : format(value, 'financial-no-decimals')
}
onMouseEnter={() => setYAxisIsHovered(true)}
onMouseLeave={() => setYAxisIsHovered(false)}
@@ -164,7 +169,7 @@ export function CashFlowGraph({
locale,
});
}}
- content={<CustomTooltip isConcise={isConcise} />}
+ content={<CustomTooltip isConcise={isConcise} format={format} />}
isAnimationActive={false}
/>
diff --git a/packages/desktop-client/src/components/reports/graphs/DonutGraph.tsx b/packages/desktop-client/src/components/reports/graphs/DonutGraph.tsx
index 2f4ae515c9..867636e175 100644
--- a/packages/desktop-client/src/components/reports/graphs/DonutGraph.tsx
+++ b/packages/desktop-client/src/components/reports/graphs/DonutGraph.tsx
@@ -4,7 +4,6 @@ import React, { useState, type CSSProperties } from 'react';
import { theme } from '@actual-app/components/theme';
import { PieChart, Pie, Cell, Sector, ResponsiveContainer } from 'recharts';
-import { amountToCurrency } from 'loot-core/shared/util';
import {
type balanceTypeOpType,
type DataEntity,
@@ -19,6 +18,7 @@ import { PrivacyFilter } from '@desktop-client/components/PrivacyFilter';
import { Container } from '@desktop-client/components/reports/Container';
import { useAccounts } from '@desktop-client/hooks/useAccounts';
import { useCategories } from '@desktop-client/hooks/useCategories';
+import { useFormat } from '@desktop-client/hooks/useFormat';
import { useNavigate } from '@desktop-client/hooks/useNavigate';
const RADIAN = Math.PI / 180;
@@ -37,6 +37,7 @@ const ActiveShapeMobile = props => {
payload,
percent,
value,
+ format,
} = props;
const yAxis = payload.name ?? payload.date;
@@ -63,7 +64,7 @@ const ActiveShapeMobile = props => {
textAnchor="end"
fill={fill}
>
- {`${amountToCurrency(value)}`}
+ {`${format(value, 'financial')}`}
</text>
<text
x={cx + outerRadius * Math.cos(-RADIAN * 330) + 10}
@@ -97,6 +98,10 @@ const ActiveShapeMobile = props => {
);
};
+const ActiveShapeMobileWithFormat = props => (
+ <ActiveShapeMobile {...props} format={props.format} />
+);
+
const ActiveShape = props => {
const {
cx,
@@ -110,6 +115,7 @@ const ActiveShape = props => {
payload,
percent,
value,
+ format,
} = props;
const yAxis = payload.name ?? payload.date;
const sin = Math.sin(-RADIAN * midAngle);
@@ -161,7 +167,7 @@ const ActiveShape = props => {
dy={18}
textAnchor={textAnchor}
fill={fill}
- >{`${amountToCurrency(value)}`}</text>
+ >{`${format(value, 'financial')}`}</text>
<text
x={ex + (cos <= 0 ? 1 : -1) * 16}
y={ey}
@@ -176,6 +182,10 @@ const ActiveShape = props => {
);
};
+const ActiveShapeWithFormat = props => (
+ <ActiveShape {...props} format={props.format} />
+);
+
const customLabel = props => {
const radius =
props.innerRadius + (props.outerRadius - props.innerRadius) * 0.5;
@@ -225,6 +235,8 @@ export function DonutGraph({
showOffBudget,
showTooltip = true,
}: DonutGraphProps) {
+ const format = useFormat();
+
const yAxis = groupBy === 'Interval' ? 'date' : 'name';
const splitData = groupBy === 'Interval' ? 'intervalData' : 'data';
@@ -264,8 +276,18 @@ export function DonutGraph({
width < 220 || height < 130
? undefined
: compact
- ? ActiveShapeMobile
- : ActiveShape
+ ? props => (
+ <ActiveShapeMobileWithFormat
+ {...props}
+ format={format}
+ />
+ )
+ : props => (
+ <ActiveShapeWithFormat
+ {...props}
+ format={format}
+ />
+ )
}
dataKey={val => getVal(val)}
nameKey={yAxis}
diff --git a/packages/desktop-client/src/components/reports/graphs/LineGraph.tsx b/packages/desktop-client/src/components/reports/graphs/LineGraph.tsx
index 9d17f17aeb..ea6b7808a2 100644
--- a/packages/desktop-client/src/components/reports/graphs/LineGraph.tsx
+++ b/packages/desktop-client/src/components/reports/graphs/LineGraph.tsx
@@ -15,10 +15,6 @@ import {
ResponsiveContainer,
} from 'recharts';
-import {
- amountToCurrency,
- amountToCurrencyNoDecimal,
-} from 'loot-core/shared/util';
import {
type balanceTypeOpType,
type DataEntity,
@@ -32,6 +28,7 @@ import { getCustomTick } from '@desktop-client/components/reports/getCustomTick'
import { numberFormatterTooltip } from '@desktop-client/components/reports/numberFormatter';
import { useAccounts } from '@desktop-client/hooks/useAccounts';
import { useCategories } from '@desktop-client/hooks/useCategories';
+import { type FormatType, useFormat } from '@desktop-client/hooks/useFormat';
import { useNavigate } from '@desktop-client/hooks/useNavigate';
import { usePrivacyMode } from '@desktop-client/hooks/usePrivacyMode';
@@ -50,6 +47,7 @@ type CustomTooltipProps = {
tooltip: string;
active?: boolean;
payload?: PayloadItem[];
+ format: (value: unknown, type: FormatType) => string;
};
const CustomTooltip = ({
@@ -57,6 +55,7 @@ const CustomTooltip = ({
tooltip,
active,
payload,
+ format,
}: CustomTooltipProps) => {
const { t } = useTranslation();
if (active && payload && payload.length) {
@@ -87,7 +86,7 @@ const CustomTooltip = ({
<AlignedText
key={index}
left={p.dataKey}
- right={amountToCurrency(p.value)}
+ right={format(p.value, 'financial')}
style={{
color: p.color,
textDecoration:
@@ -100,7 +99,7 @@ const CustomTooltip = ({
{payload.length > 5 && compact && '...'}
<AlignedText
left={t('Total')}
- right={amountToCurrency(sumTotals)}
+ right={format(sumTotals, 'financial')}
style={{
fontWeight: 600,
}}
@@ -141,6 +140,8 @@ export function LineGraph({
const categories = useCategories();
const accounts = useAccounts();
const privacyMode = usePrivacyMode();
+ const format = useFormat();
+
const [pointer, setPointer] = useState('');
const [tooltip, setTooltip] = useState('');
@@ -190,7 +191,11 @@ export function LineGraph({
{showTooltip && (
<Tooltip
content={
- <CustomTooltip compact={compact} tooltip={tooltip} />
+ <CustomTooltip
+ compact={compact}
+ tooltip={tooltip}
+ format={format}
+ />
}
formatter={numberFormatterTooltip}
isAnimationActive={false}
@@ -208,7 +213,7 @@ export function LineGraph({
<YAxis
tickFormatter={value =>
getCustomTick(
- amountToCurrencyNoDecimal(value),
+ format(value, 'financial-no-decimals'),
privacyMode,
)
}
diff --git a/packages/desktop-client/src/components/reports/graphs/NetWorthGraph.tsx b/packages/desktop-client/src/components/reports/graphs/NetWorthGraph.tsx
index 0aa8eee843..f6f6e71752 100644
--- a/packages/desktop-client/src/components/reports/graphs/NetWorthGraph.tsx
+++ b/packages/desktop-client/src/components/reports/graphs/NetWorthGraph.tsx
@@ -17,10 +17,11 @@ import {
ResponsiveContainer,
} from 'recharts';
-import { amountToCurrencyNoDecimal } from 'loot-core/shared/util';
+import { computePadding } from './util/computePadding';
import { Container } from '@desktop-client/components/reports/Container';
import { numberFormatterTooltip } from '@desktop-client/components/reports/numberFormatter';
+import { useFormat } from '@desktop-client/hooks/useFormat';
import { usePrivacyMode } from '@desktop-client/hooks/usePrivacyMode';
type NetWorthGraphProps = {
@@ -54,6 +55,7 @@ export function NetWorthGraph({
const { t } = useTranslation();
const privacyMode = usePrivacyMode();
const id = useId();
+ const format = useFormat();
// Use more aggressive smoothening for high-frequency data
const interpolationType =
@@ -62,7 +64,7 @@ export function NetWorthGraph({
const tickFormatter = tick => {
const res = privacyMode
? '...'
- : `${amountToCurrencyNoDecimal(Math.round(tick))}`; // Formats the tick values as strings with commas
+ : `${format(Math.round(tick), 'financial-no-decimals')}`;
return res;
};
@@ -173,7 +175,12 @@ export function NetWorthGraph({
margin={{
top: 0,
right: 0,
- left: compact ? 0 : computePadding(graphData.data),
+ left: compact
+ ? 0
+ : computePadding(
+ graphData.data.map(item => item.y),
+ value => format(value, 'financial-no-decimals'),
+ ),
bottom: 0,
}}
>
@@ -237,22 +244,3 @@ export function NetWorthGraph({
</Container>
);
}
-
-/**
- * Add left padding for Y-axis for when large amounts get clipped
- * @param netWorthData
- * @returns left padding for Net worth graph
- */
-function computePadding(netWorthData: Array<{ y: number }>) {
- /**
- * Convert to string notation, get longest string length
- */
- const maxLength = Math.max(
- ...netWorthData.map(({ y }) => {
- return amountToCurrencyNoDecimal(Math.round(y)).length;
- }),
- );
-
- // No additional left padding is required for upto 5 characters
- return Math.max(0, (maxLength - 5) * 5);
-}
diff --git a/packages/desktop-client/src/components/reports/graphs/SpendingGraph.tsx b/packages/desktop-client/src/components/reports/graphs/SpendingGraph.tsx
index a612594d14..a02d7a62bf 100644
--- a/packages/desktop-client/src/components/reports/graphs/SpendingGraph.tsx
+++ b/packages/desktop-client/src/components/reports/graphs/SpendingGraph.tsx
@@ -15,14 +15,13 @@ import {
ResponsiveContainer,
} from 'recharts';
-import {
- amountToCurrency,
- amountToCurrencyNoDecimal,
-} from 'loot-core/shared/util';
import { type SpendingEntity } from 'loot-core/types/models';
+import { computePadding } from './util/computePadding';
+
import { Container } from '@desktop-client/components/reports/Container';
import { numberFormatterTooltip } from '@desktop-client/components/reports/numberFormatter';
+import { useFormat, type FormatType } from '@desktop-client/hooks/useFormat';
import { usePrivacyMode } from '@desktop-client/hooks/usePrivacyMode';
type PayloadItem = {
@@ -48,6 +47,7 @@ type CustomTooltipProps = {
balanceTypeOp: 'cumulative';
selection: string | 'budget' | 'average';
compare: string;
+ format: (value: unknown, type?: FormatType) => string;
};
const CustomTooltip = ({
@@ -56,6 +56,7 @@ const CustomTooltip = ({
balanceTypeOp,
selection,
compare,
+ format,
}: CustomTooltipProps) => {
const { t } = useTranslation();
@@ -93,8 +94,9 @@ const CustomTooltip = ({
{payload[0].payload.months[compare]?.cumulative ? (
<AlignedText
left={t('Compare:')}
- right={amountToCurrency(
+ right={format(
payload[0].payload.months[compare]?.cumulative * -1,
+ 'financial',
)}
/>
) : null}
@@ -107,15 +109,18 @@ const CustomTooltip = ({
? t('Budgeted:')
: t('To:')
}
- right={amountToCurrency(comparison)}
+ right={format(Math.round(comparison), 'financial')}
/>
)}
{payload[0].payload.months[compare]?.cumulative ? (
<AlignedText
left={t('Difference:')}
- right={amountToCurrency(
- payload[0].payload.months[compare]?.cumulative * -1 -
- comparison,
+ right={format(
+ Math.round(
+ payload[0].payload.months[compare]?.cumulative * -1 -
+ comparison,
+ ),
+ 'financial',
)}
/>
) : null}
@@ -145,6 +150,7 @@ export function SpendingGraph({
}: SpendingGraphProps) {
const privacyMode = usePrivacyMode();
const balanceTypeOp = 'cumulative';
+ const format = useFormat();
const selection = mode === 'single-month' ? compareTo : mode;
@@ -170,7 +176,7 @@ export function SpendingGraph({
);
const tickFormatter: ComponentProps<typeof YAxis>['tickFormatter'] = tick => {
- if (!privacyMode) return `${amountToCurrencyNoDecimal(tick)}`; // Formats the tick values as strings with commas
+ if (!privacyMode) return `${format(tick, 'financial-no-decimals')}`;
return '...';
};
@@ -219,7 +225,12 @@ export function SpendingGraph({
margin={{
top: 0,
right: 0,
- left: 0,
+ left: computePadding(
+ data.intervalData
+ .map(item => getVal(item, maxYAxis ? compare : selection))
+ .filter(value => value !== undefined),
+ (value: number) => format(value, 'financial-no-decimals'),
+ ),
bottom: 0,
}}
>
@@ -249,6 +260,7 @@ export function SpendingGraph({
balanceTypeOp={balanceTypeOp}
selection={selection}
compare={compare}
+ format={format}
/>
}
formatter={numberFormatterTooltip}
diff --git a/packages/desktop-client/src/components/reports/graphs/StackedBarGraph.tsx b/packages/desktop-client/src/components/reports/graphs/StackedBarGraph.tsx
index 4ec4b7275f..ebbe02b9bc 100644
--- a/packages/desktop-client/src/components/reports/graphs/StackedBarGraph.tsx
+++ b/packages/desktop-client/src/components/reports/graphs/StackedBarGraph.tsx
@@ -16,10 +16,6 @@ import {
ResponsiveContainer,
} from 'recharts';
-import {
- amountToCurrency,
- amountToCurrencyNoDecimal,
-} from 'loot-core/shared/util';
import {
type balanceTypeOpType,
type DataEntity,
@@ -34,6 +30,7 @@ import { getCustomTick } from '@desktop-client/components/reports/getCustomTick'
import { numberFormatterTooltip } from '@desktop-client/components/reports/numberFormatter';
import { useAccounts } from '@desktop-client/hooks/useAccounts';
import { useCategories } from '@desktop-client/hooks/useCategories';
+import { useFormat, type FormatType } from '@desktop-client/hooks/useFormat';
import { useNavigate } from '@desktop-client/hooks/useNavigate';
import { usePrivacyMode } from '@desktop-client/hooks/usePrivacyMode';
@@ -53,6 +50,7 @@ type CustomTooltipProps = {
active?: boolean;
payload?: PayloadItem[];
label?: string;
+ format: (value: unknown, type: FormatType) => string;
};
const CustomTooltip = ({
@@ -61,6 +59,7 @@ const CustomTooltip = ({
active,
payload,
label,
+ format,
}: CustomTooltipProps) => {
const { t } = useTranslation();
if (active && payload && payload.length) {
@@ -93,7 +92,7 @@ const CustomTooltip = ({
<AlignedText
key={pay.name}
left={pay.name}
- right={amountToCurrency(pay.value)}
+ right={format(pay.value, 'financial')}
style={{
color: pay.color,
textDecoration:
@@ -106,7 +105,7 @@ const CustomTooltip = ({
{payload.length > 5 && compact && '...'}
<AlignedText
left={t('Total')}
- right={amountToCurrency(sumTotals)}
+ right={format(sumTotals, 'financial')}
style={{
fontWeight: 600,
}}
@@ -122,7 +121,8 @@ const customLabel = props => {
const calcX = props.x + props.width / 2;
const calcY = props.y + props.height / 2;
const textAnchor = 'middle';
- const display = props.value && `${amountToCurrencyNoDecimal(props.value)}`;
+ const display =
+ props.value && `${props.format(props.value, 'financial-no-decimals')}`;
const textSize = '12px';
const showLabel = props.height;
const showLabelThreshold = 20;
@@ -171,6 +171,10 @@ export function StackedBarGraph({
const categories = useCategories();
const accounts = useAccounts();
const privacyMode = usePrivacyMode();
+ const format = useFormat();
+
+ const customLabelWithFormat = props => customLabel({ ...props, format });
+
const [pointer, setPointer] = useState('');
const [tooltip, setTooltip] = useState('');
@@ -203,7 +207,11 @@ export function StackedBarGraph({
{showTooltip && (
<Tooltip
content={
- <CustomTooltip compact={compact} tooltip={tooltip} />
+ <CustomTooltip
+ compact={compact}
+ tooltip={tooltip}
+ format={format}
+ />
}
formatter={numberFormatterTooltip}
isAnimationActive={false}
@@ -220,7 +228,7 @@ export function StackedBarGraph({
<YAxis
tickFormatter={value =>
getCustomTick(
- amountToCurrencyNoDecimal(value),
+ format(value, 'financial-no-decimals'),
privacyMode,
)
}
@@ -269,7 +277,10 @@ export function StackedBarGraph({
}
>
{viewLabels && !compact && (
- <LabelList dataKey={entry.name} content={customLabel} />
+ <LabelList
+ dataKey={entry.name}
+ content={customLabelWithFormat}
+ />
)}
</Bar>
))}
diff --git a/packages/desktop-client/src/components/reports/graphs/tableGraph/ReportTableRow.tsx b/packages/desktop-client/src/components/reports/graphs/tableGraph/ReportTableRow.tsx
index d750596f8e..59999eab5a 100644
--- a/packages/desktop-client/src/components/reports/graphs/tableGraph/ReportTableRow.tsx
+++ b/packages/desktop-client/src/components/reports/graphs/tableGraph/ReportTableRow.tsx
@@ -10,11 +10,6 @@ import { Text } from '@actual-app/components/text';
import { theme } from '@actual-app/components/theme';
import { View } from '@actual-app/components/view';
-import {
- amountToCurrency,
- amountToInteger,
- integerToCurrency,
-} from 'loot-core/shared/util';
import {
type balanceTypeOpType,
type GroupedEntity,
@@ -25,6 +20,7 @@ import { showActivity } from '@desktop-client/components/reports/graphs/showActi
import { Row, Cell } from '@desktop-client/components/table';
import { useAccounts } from '@desktop-client/hooks/useAccounts';
import { useCategories } from '@desktop-client/hooks/useCategories';
+import { useFormat } from '@desktop-client/hooks/useFormat';
import { useNavigate } from '@desktop-client/hooks/useNavigate';
type ReportTableRowProps = {
@@ -76,8 +72,9 @@ export const ReportTableRow = memo(
interval,
colorized,
}: ReportTableRowProps) => {
- const average = amountToInteger(item[balanceTypeOp]) / intervalsCount;
+ const average = Math.round(item[balanceTypeOp] / intervalsCount);
const groupByItem = groupBy === 'Interval' ? 'date' : 'name';
+ const format = useFormat();
const navigate = useNavigate();
const { isNarrowWidth } = useResponsive();
@@ -150,10 +147,10 @@ export const ReportTableRow = memo(
<Text style={hoverUnderline}>{value}</Text>
)}
valueStyle={compactStyle}
- value={amountToCurrency(intervalItem[balanceTypeOp])}
+ value={format(intervalItem[balanceTypeOp], 'financial')}
title={
Math.abs(intervalItem[balanceTypeOp]) > 100000
- ? amountToCurrency(intervalItem[balanceTypeOp])
+ ? format(intervalItem[balanceTypeOp], 'financial')
: undefined
}
onClick={() =>
@@ -185,10 +182,10 @@ export const ReportTableRow = memo(
: balanceTypeOp === 'totalTotals' && (
<>
<Cell
- value={amountToCurrency(item.totalAssets)}
+ value={format(item.totalAssets, 'financial')}
title={
Math.abs(item.totalAssets) > 100000
- ? amountToCurrency(item.totalAssets)
+ ? format(item.totalAssets, 'financial')
: undefined
}
width="flex"
@@ -225,10 +222,10 @@ export const ReportTableRow = memo(
}
/>
<Cell
- value={amountToCurrency(item.totalDebts)}
+ value={format(item.totalDebts, 'financial')}
title={
Math.abs(item.totalDebts) > 100000
- ? amountToCurrency(item.totalDebts)
+ ? format(item.totalDebts, 'financial')
: undefined
}
width="flex"
@@ -267,10 +264,10 @@ export const ReportTableRow = memo(
</>
)}
<Cell
- value={amountToCurrency(item[balanceTypeOp])}
+ value={format(item[balanceTypeOp], 'financial')}
title={
Math.abs(item[balanceTypeOp]) > 100000
- ? amountToCurrency(item[balanceTypeOp])
+ ? format(item[balanceTypeOp], 'financial')
: undefined
}
style={{
@@ -306,10 +303,10 @@ export const ReportTableRow = memo(
privacyFilter
/>
<Cell
- value={integerToCurrency(Math.round(average))}
+ value={format(average, 'financial')}
title={
- Math.abs(Math.round(average / 100)) > 100000
- ? integerToCurrency(Math.round(average))
+ Math.abs(average / 100) > 100000
+ ? format(average, 'financial')
: undefined
}
style={{
diff --git a/packages/desktop-client/src/components/reports/graphs/util/computePadding.ts b/packages/desktop-client/src/components/reports/graphs/util/computePadding.ts
new file mode 100644
index 0000000000..f39f33f63f
--- /dev/null
+++ b/packages/desktop-client/src/components/reports/graphs/util/computePadding.ts
@@ -0,0 +1,21 @@
+/**
+ * Calculates the left padding needed for chart axis based on formatted number length
+ * @param values Array of numeric values
+ * @param formatter Function to format numbers to strings
+ * @returns Padding amount in pixels
+ */
+export function computePadding(
+ values: number[],
+ formatter: (value: number) => string,
+) {
+ if (values.length === 0) {
+ return 0;
+ }
+
+ const maxLength = Math.max(
+ ...values.map(value => {
+ return formatter(Math.round(value)).length;
+ }),
+ );
+ return Math.max(0, (maxLength - 5) * 5);
+}
diff --git a/packages/desktop-client/src/components/reports/reports/Calendar.tsx b/packages/desktop-client/src/components/reports/reports/Calendar.tsx
index 09fb3b733b..aa6bee80d5 100644
--- a/packages/desktop-client/src/components/reports/reports/Calendar.tsx
+++ b/packages/desktop-client/src/components/reports/reports/Calendar.tsx
@@ -23,13 +23,12 @@ import { theme } from '@actual-app/components/theme';
import { View } from '@actual-app/components/view';
import { css } from '@emotion/css';
import { useDrag } from '@use-gesture/react';
-import { format, parseISO } from 'date-fns';
+import { format as formatDate, parseISO } from 'date-fns';
import { send } from 'loot-core/platform/client/fetch';
import * as monthUtils from 'loot-core/shared/months';
import { q, type Query } from 'loot-core/shared/query';
import { ungroupTransactions } from 'loot-core/shared/transactions';
-import { amountToCurrency } from 'loot-core/shared/util';
import {
type CalendarWidget,
type RuleConditionEntity,
@@ -64,6 +63,7 @@ import { useAccounts } from '@desktop-client/hooks/useAccounts';
import { SchedulesProvider } from '@desktop-client/hooks/useCachedSchedules';
import { useCategories } from '@desktop-client/hooks/useCategories';
import { useDateFormat } from '@desktop-client/hooks/useDateFormat';
+import { type FormatType, useFormat } from '@desktop-client/hooks/useFormat';
import { useLocale } from '@desktop-client/hooks/useLocale';
import { useMergedRefs } from '@desktop-client/hooks/useMergedRefs';
import { useNavigate } from '@desktop-client/hooks/useNavigate';
@@ -104,6 +104,8 @@ type CalendarInnerProps = {
function CalendarInner({ widget, parameters }: CalendarInnerProps) {
const locale = useLocale();
const { t } = useTranslation();
+ const format = useFormat();
+
const [initialStart, initialEnd, initialMode] = calculateTimeRange(
widget?.meta?.timeFrame,
{
@@ -569,6 +571,7 @@ function CalendarInner({ widget, parameters }: CalendarInnerProps) {
firstDayOfWeekIdx={firstDayOfWeekIdx}
conditions={conditions}
conditionsOp={conditionsOp}
+ format={format}
/>
))}
</View>
@@ -579,6 +582,7 @@ function CalendarInner({ widget, parameters }: CalendarInnerProps) {
totalExpense={totalExpense}
totalIncome={totalIncome}
isNarrowWidth={isNarrowWidth}
+ format={format}
/>
</View>
</View>
@@ -742,6 +746,7 @@ type CalendarWithHeaderProps = {
firstDayOfWeekIdx: string;
conditions: RuleConditionEntity[];
conditionsOp: 'and' | 'or';
+ format: (value: unknown, type: FormatType) => string;
};
function CalendarWithHeader({
@@ -750,6 +755,7 @@ function CalendarWithHeader({
firstDayOfWeekIdx,
conditions,
conditionsOp,
+ format,
}: CalendarWithHeaderProps) {
const { t } = useTranslation();
@@ -796,7 +802,7 @@ function CalendarWithHeader({
{
field: 'date',
op: 'is',
- value: format(calendar.start, 'yyyy-MM'),
+ value: formatDate(calendar.start, 'yyyy-MM'),
options: {
month: true,
},
@@ -807,7 +813,7 @@ function CalendarWithHeader({
});
}}
>
- {format(calendar.start, 'MMMM yyyy')}
+ {formatDate(calendar.start, 'MMMM yyyy')}
</Button>
<View
style={{ display: 'grid', gridTemplateColumns: '16px 1fr', gap: 2 }}
@@ -827,7 +833,7 @@ function CalendarWithHeader({
aria-label={t('Income')}
>
<PrivacyFilter>
- {amountToCurrency(calendar.totalIncome)}
+ {format(calendar.totalIncome, 'financial')}
</PrivacyFilter>
</View>
<SvgArrowThickDown
@@ -845,7 +851,7 @@ function CalendarWithHeader({
aria-label={t('Expenses')}
>
<PrivacyFilter>
- {amountToCurrency(calendar.totalExpense)}
+ {format(calendar.totalExpense, 'financial')}
</PrivacyFilter>
</View>
</View>
@@ -862,7 +868,7 @@ function CalendarWithHeader({
{
field: 'date',
op: 'is',
- value: format(date, 'yyyy-MM-dd'),
+ value: formatDate(date, 'yyyy-MM-dd'),
},
],
conditionsOp: 'and',
@@ -889,6 +895,7 @@ type CalendarCardHeaderProps = {
totalIncome: number;
totalExpense: number;
isNarrowWidth: boolean;
+ format: (value: unknown, type: FormatType) => string;
};
function CalendarCardHeader({
@@ -897,6 +904,7 @@ function CalendarCardHeader({
totalIncome,
totalExpense,
isNarrowWidth,
+ format,
}: CalendarCardHeaderProps) {
return (
<View
@@ -936,7 +944,7 @@ function CalendarCardHeader({
<Trans>Income:</Trans>
</View>
<View style={{ color: chartTheme.colors.blue }}>
- <PrivacyFilter>{amountToCurrency(totalIncome)}</PrivacyFilter>
+ <PrivacyFilter>{format(totalIncome, 'financial')}</PrivacyFilter>
</View>
<View
@@ -948,7 +956,7 @@ function CalendarCardHeader({
<Trans>Expenses:</Trans>
</View>
<View style={{ color: chartTheme.colors.red }}>
- <PrivacyFilter>{amountToCurrency(totalExpense)}</PrivacyFilter>
+ <PrivacyFilter>{format(totalExpense, 'financial')}</PrivacyFilter>
</View>
</View>
</View>
diff --git a/packages/desktop-client/src/components/reports/reports/CalendarCard.tsx b/packages/desktop-client/src/components/reports/reports/CalendarCard.tsx
index 65af1a5753..6350a8d8bb 100644
--- a/packages/desktop-client/src/components/reports/reports/CalendarCard.tsx
+++ b/packages/desktop-client/src/components/reports/reports/CalendarCard.tsx
@@ -21,11 +21,10 @@ import { styles } from '@actual-app/components/styles';
import { theme } from '@actual-app/components/theme';
import { Tooltip } from '@actual-app/components/tooltip';
import { View } from '@actual-app/components/view';
-import { format } from 'date-fns';
+import { format as formatDate } from 'date-fns';
import { debounce } from 'debounce';
import * as monthUtils from 'loot-core/shared/months';
-import { amountToCurrency } from 'loot-core/shared/util';
import { type CalendarWidget } from 'loot-core/types/models';
import { type SyncedPrefs } from 'loot-core/types/prefs';
@@ -42,6 +41,7 @@ import {
calendarSpreadsheet,
} from '@desktop-client/components/reports/spreadsheets/calendar-spreadsheet';
import { useReport } from '@desktop-client/components/reports/useReport';
+import { type FormatType, useFormat } from '@desktop-client/hooks/useFormat';
import { useMergedRefs } from '@desktop-client/hooks/useMergedRefs';
import { useNavigate } from '@desktop-client/hooks/useNavigate';
import { useResizeObserver } from '@desktop-client/hooks/useResizeObserver';
@@ -64,6 +64,8 @@ export function CalendarCard({
firstDayOfWeekIdx,
}: CalendarCardProps) {
const { t } = useTranslation();
+ const format = useFormat();
+
const [start, end] = calculateTimeRange(meta?.timeFrame, {
start: monthUtils.dayFromDate(monthUtils.currentMonth()),
end: monthUtils.currentDay(),
@@ -225,7 +227,7 @@ export function CalendarCard({
<View style={{ color: chartTheme.colors.blue }}>
{totalIncome !== 0 ? (
<PrivacyFilter>
- {amountToCurrency(totalIncome)}
+ {format(totalIncome, 'financial')}
</PrivacyFilter>
) : (
''
@@ -246,7 +248,7 @@ export function CalendarCard({
<View style={{ color: chartTheme.colors.red }}>
{totalExpense !== 0 ? (
<PrivacyFilter>
- {amountToCurrency(totalExpense)}
+ {format(totalExpense, 'financial')}
</PrivacyFilter>
) : (
''
@@ -307,6 +309,7 @@ export function CalendarCard({
index={index}
widgetId={widgetId}
isEditing={isEditing}
+ format={format}
/>
))
) : (
@@ -333,6 +336,7 @@ type CalendarCardInnerProps = {
index: number;
widgetId: string;
isEditing?: boolean;
+ format: (value: unknown, type: FormatType) => string;
};
function CalendarCardInner({
calendar,
@@ -342,6 +346,7 @@ function CalendarCardInner({
index,
widgetId,
isEditing,
+ format,
}: CalendarCardInnerProps) {
const { t } = useTranslation();
const [monthNameVisible, setMonthNameVisible] = useState(true);
@@ -410,10 +415,10 @@ function CalendarCardInner({
const navigate = useNavigate();
const monthFormats = [
- { format: 'MMMM yyyy', text: format(calendar.start, 'MMMM yyyy') },
- { format: 'MMM yyyy', text: format(calendar.start, 'MMM yyyy') },
- { format: 'MMM yy', text: format(calendar.start, 'MMM yy') },
- { format: 'MMM', text: format(calendar.start, 'MMM') },
+ { format: 'MMMM yyyy', text: formatDate(calendar.start, 'MMMM yyyy') },
+ { format: 'MMM yyyy', text: formatDate(calendar.start, 'MMM yyyy') },
+ { format: 'MMM yy', text: formatDate(calendar.start, 'MMM yy') },
+ { format: 'MMM', text: formatDate(calendar.start, 'MMM') },
{ format: '', text: '' },
];
@@ -454,12 +459,12 @@ function CalendarCardInner({
}}
onPress={() => {
navigate(
- `/reports/calendar/${widgetId}?month=${format(calendar.start, 'yyyy-MM')}`,
+ `/reports/calendar/${widgetId}?month=${formatDate(calendar.start, 'yyyy-MM')}`,
);
}}
>
{selectedMonthNameFormat &&
- format(calendar.start, selectedMonthNameFormat)}
+ formatDate(calendar.start, selectedMonthNameFormat)}
</Button>
</View>
<View
@@ -485,7 +490,7 @@ function CalendarCardInner({
style={{ flexShrink: 0 }}
/>
<PrivacyFilter>
- {amountToCurrency(calendar.totalIncome)}
+ {format(calendar.totalIncome, 'financial')}
</PrivacyFilter>
</>
) : (
@@ -508,7 +513,7 @@ function CalendarCardInner({
style={{ flexShrink: 0 }}
/>
<PrivacyFilter>
- {amountToCurrency(calendar.totalExpense)}
+ {format(calendar.totalExpense, 'financial')}
</PrivacyFilter>
</>
) : (
@@ -525,7 +530,7 @@ function CalendarCardInner({
onDayClick={date => {
if (date) {
navigate(
- `/reports/calendar/${widgetId}?day=${format(date, 'yyyy-MM-dd')}`,
+ `/reports/calendar/${widgetId}?day=${formatDate(date, 'yyyy-MM-dd')}`,
);
} else {
navigate(`/reports/calendar/${widgetId}`);
diff --git a/packages/desktop-client/src/components/reports/reports/CashFlow.tsx b/packages/desktop-client/src/components/reports/reports/CashFlow.tsx
index 533c82f431..47b5ac33a0 100644
--- a/packages/desktop-client/src/components/reports/reports/CashFlow.tsx
+++ b/packages/desktop-client/src/components/reports/reports/CashFlow.tsx
@@ -14,7 +14,6 @@ import * as d from 'date-fns';
import { send } from 'loot-core/platform/client/fetch';
import * as monthUtils from 'loot-core/shared/months';
-import { integerToCurrency } from 'loot-core/shared/util';
import {
type CashFlowWidget,
type RuleConditionEntity,
@@ -36,6 +35,7 @@ import { LoadingIndicator } from '@desktop-client/components/reports/LoadingIndi
import { calculateTimeRange } from '@desktop-client/components/reports/reportRanges';
import { cashFlowByDate } from '@desktop-client/components/reports/spreadsheets/cash-flow-spreadsheet';
import { useReport } from '@desktop-client/components/reports/useReport';
+import { useFormat } from '@desktop-client/hooks/useFormat';
import { useLocale } from '@desktop-client/hooks/useLocale';
import { useNavigate } from '@desktop-client/hooks/useNavigate';
import { useRuleConditionFilters } from '@desktop-client/hooks/useRuleConditionFilters';
@@ -72,6 +72,7 @@ function CashFlowInner({ widget }: CashFlowInnerProps) {
const locale = useLocale();
const dispatch = useDispatch();
const { t } = useTranslation();
+ const format = useFormat();
const {
conditions,
@@ -111,8 +112,16 @@ function CashFlowInner({ widget }: CashFlowInnerProps) {
const params = useMemo(
() =>
- cashFlowByDate(start, end, isConcise, conditions, conditionsOp, locale),
- [start, end, isConcise, conditions, conditionsOp, locale],
+ cashFlowByDate(
+ start,
+ end,
+ isConcise,
+ conditions,
+ conditionsOp,
+ locale,
+ format,
+ ),
+ [start, end, isConcise, conditions, conditionsOp, locale, format],
);
const data = useReport('cash_flow', params);
@@ -287,7 +296,9 @@ function CashFlowInner({ widget }: CashFlowInnerProps) {
}
right={
<Text style={{ fontWeight: 600 }}>
- <PrivacyFilter>{integerToCurrency(totalIncome)}</PrivacyFilter>
+ <PrivacyFilter>
+ {format(totalIncome, 'financial')}
+ </PrivacyFilter>
</Text>
}
/>
@@ -302,7 +313,7 @@ function CashFlowInner({ widget }: CashFlowInnerProps) {
right={
<Text style={{ fontWeight: 600 }}>
<PrivacyFilter>
- {integerToCurrency(totalExpenses)}
+ {format(totalExpenses, 'financial')}
</PrivacyFilter>
</Text>
}
@@ -318,7 +329,7 @@ function CashFlowInner({ widget }: CashFlowInnerProps) {
right={
<Text style={{ fontWeight: 600 }}>
<PrivacyFilter>
- {integerToCurrency(totalTransfers)}
+ {format(totalTransfers, 'financial')}
</PrivacyFilter>
</Text>
}
diff --git a/packages/desktop-client/src/components/reports/reports/CashFlowCard.tsx b/packages/desktop-client/src/components/reports/reports/CashFlowCard.tsx
index 5956d502b2..0708ac1d19 100644
--- a/packages/desktop-client/src/components/reports/reports/CashFlowCard.tsx
+++ b/packages/desktop-client/src/components/reports/reports/CashFlowCard.tsx
@@ -5,7 +5,6 @@ import { theme } from '@actual-app/components/theme';
import { View } from '@actual-app/components/view';
import { Bar, BarChart, LabelList, ResponsiveContainer } from 'recharts';
-import { integerToCurrency } from 'loot-core/shared/util';
import { type CashFlowWidget } from 'loot-core/types/models';
import { defaultTimeFrame } from './CashFlow';
@@ -21,6 +20,7 @@ import { ReportCardName } from '@desktop-client/components/reports/ReportCardNam
import { calculateTimeRange } from '@desktop-client/components/reports/reportRanges';
import { simpleCashFlow } from '@desktop-client/components/reports/spreadsheets/cash-flow-spreadsheet';
import { useReport } from '@desktop-client/components/reports/useReport';
+import { useFormat } from '@desktop-client/hooks/useFormat';
type CustomLabelProps = {
value?: number;
@@ -41,6 +41,8 @@ function CustomLabel({
width: barWidth = 0,
height: barHeight = 0,
}: CustomLabelProps) {
+ const format = useFormat();
+
const valueLengthOffset = 20;
const yOffset = barHeight < 25 ? 105 : y;
@@ -76,7 +78,7 @@ function CustomLabel({
textAnchor={anchorValue[position]}
fill={theme.tableText}
>
- <PrivacyFilter>{integerToCurrency(value)}</PrivacyFilter>
+ <PrivacyFilter>{format(value, 'financial')}</PrivacyFilter>
</text>
</>
);
diff --git a/packages/desktop-client/src/components/reports/reports/CustomReport.tsx b/packages/desktop-client/src/components/reports/reports/CustomReport.tsx
index 73cecd7aa0..716ae29e74 100644
--- a/packages/desktop-client/src/components/reports/reports/CustomReport.tsx
+++ b/packages/desktop-client/src/components/reports/reports/CustomReport.tsx
@@ -13,7 +13,6 @@ import * as d from 'date-fns';
import { send } from 'loot-core/platform/client/fetch';
import * as monthUtils from 'loot-core/shared/months';
-import { amountToCurrency } from 'loot-core/shared/util';
import {
type CategoryEntity,
type balanceTypeOpType,
@@ -62,6 +61,7 @@ import {
} from '@desktop-client/components/reports/util';
import { useAccounts } from '@desktop-client/hooks/useAccounts';
import { useCategories } from '@desktop-client/hooks/useCategories';
+import { useFormat } from '@desktop-client/hooks/useFormat';
import { useLocale } from '@desktop-client/hooks/useLocale';
import { useLocalPref } from '@desktop-client/hooks/useLocalPref';
import { useNavigate } from '@desktop-client/hooks/useNavigate';
@@ -131,6 +131,8 @@ type CustomReportInnerProps = {
function CustomReportInner({ report: initialReport }: CustomReportInnerProps) {
const locale = useLocale();
const { t } = useTranslation();
+ const format = useFormat();
+
const categories = useCategories();
const { isNarrowWidth } = useResponsive();
const [_firstDayOfWeekIdx] = useSyncedPref('firstDayOfWeekIdx');
@@ -913,7 +915,7 @@ function CustomReportInner({ report: initialReport }: CustomReportInnerProps) {
right={
<Text>
<PrivacyFilter>
- {amountToCurrency(data[balanceTypeOp])}
+ {format(data[balanceTypeOp], 'financial')}
</PrivacyFilter>
</Text>
}
diff --git a/packages/desktop-client/src/components/reports/reports/NetWorth.tsx b/packages/desktop-client/src/components/reports/reports/NetWorth.tsx
index cdfebf2162..341c046c0a 100644
--- a/packages/desktop-client/src/components/reports/reports/NetWorth.tsx
+++ b/packages/desktop-client/src/components/reports/reports/NetWorth.tsx
@@ -15,7 +15,6 @@ import * as d from 'date-fns';
import { send } from 'loot-core/platform/client/fetch';
import * as monthUtils from 'loot-core/shared/months';
-import { integerToCurrency } from 'loot-core/shared/util';
import { type TimeFrame, type NetWorthWidget } from 'loot-core/types/models';
import { EditablePageHeaderTitle } from '@desktop-client/components/EditablePageHeaderTitle';
@@ -36,6 +35,7 @@ import { createSpreadsheet as netWorthSpreadsheet } from '@desktop-client/compon
import { useReport } from '@desktop-client/components/reports/useReport';
import { fromDateRepr } from '@desktop-client/components/reports/util';
import { useAccounts } from '@desktop-client/hooks/useAccounts';
+import { useFormat } from '@desktop-client/hooks/useFormat';
import { useLocale } from '@desktop-client/hooks/useLocale';
import { useNavigate } from '@desktop-client/hooks/useNavigate';
import { useRuleConditionFilters } from '@desktop-client/hooks/useRuleConditionFilters';
@@ -66,6 +66,7 @@ function NetWorthInner({ widget }: NetWorthInnerProps) {
const locale = useLocale();
const dispatch = useDispatch();
const { t } = useTranslation();
+ const format = useFormat();
const accounts = useAccounts();
const {
@@ -107,6 +108,7 @@ function NetWorthInner({ widget }: NetWorthInnerProps) {
locale,
interval,
firstDayOfWeekIdx,
+ format,
),
[
start,
@@ -117,6 +119,7 @@ function NetWorthInner({ widget }: NetWorthInnerProps) {
locale,
interval,
firstDayOfWeekIdx,
+ format,
],
);
const data = useReport('net_worth', reportParams);
@@ -279,7 +282,7 @@ function NetWorthInner({ widget }: NetWorthInnerProps) {
<View
style={{ ...styles.largeText, fontWeight: 400, marginBottom: 5 }}
>
- <PrivacyFilter>{integerToCurrency(data.netWorth)}</PrivacyFilter>
+ <PrivacyFilter>{format(data.netWorth, 'financial')}</PrivacyFilter>
</View>
<PrivacyFilter>
<Change amount={data.totalChange} />
diff --git a/packages/desktop-client/src/components/reports/reports/NetWorthCard.tsx b/packages/desktop-client/src/components/reports/reports/NetWorthCard.tsx
index 0353b75ae4..66ea922d49 100644
--- a/packages/desktop-client/src/components/reports/reports/NetWorthCard.tsx
+++ b/packages/desktop-client/src/components/reports/reports/NetWorthCard.tsx
@@ -6,7 +6,6 @@ import { useResponsive } from '@actual-app/components/hooks/useResponsive';
import { styles } from '@actual-app/components/styles';
import { View } from '@actual-app/components/view';
-import { integerToCurrency } from 'loot-core/shared/util';
import {
type AccountEntity,
type NetWorthWidget,
@@ -22,6 +21,7 @@ import { ReportCardName } from '@desktop-client/components/reports/ReportCardNam
import { calculateTimeRange } from '@desktop-client/components/reports/reportRanges';
import { createSpreadsheet as netWorthSpreadsheet } from '@desktop-client/components/reports/spreadsheets/net-worth-spreadsheet';
import { useReport } from '@desktop-client/components/reports/useReport';
+import { useFormat } from '@desktop-client/hooks/useFormat';
import { useLocale } from '@desktop-client/hooks/useLocale';
import { useSyncedPref } from '@desktop-client/hooks/useSyncedPref';
@@ -48,6 +48,8 @@ export function NetWorthCard({
const [_firstDayOfWeekIdx] = useSyncedPref('firstDayOfWeekIdx');
const firstDayOfWeekIdx = _firstDayOfWeekIdx || '0';
+ const format = useFormat();
+
const [nameMenuOpen, setNameMenuOpen] = useState(false);
const [start, end] = calculateTimeRange(meta?.timeFrame);
@@ -66,6 +68,7 @@ export function NetWorthCard({
locale,
meta?.interval || 'Monthly',
firstDayOfWeekIdx,
+ format,
),
[
start,
@@ -76,6 +79,7 @@ export function NetWorthCard({
locale,
meta?.interval,
firstDayOfWeekIdx,
+ format,
],
);
const data = useReport('net_worth', params);
@@ -139,7 +143,7 @@ export function NetWorthCard({
}}
>
<PrivacyFilter activationFilters={[!isCardHovered]}>
- {integerToCurrency(data.netWorth)}
+ {format(data.netWorth, 'financial')}
</PrivacyFilter>
</Block>
<PrivacyFilter activationFilters={[!isCardHovered]}>
diff --git a/packages/desktop-client/src/components/reports/reports/Spending.tsx b/packages/desktop-client/src/components/reports/reports/Spending.tsx
index 96724ab3a1..127a1c9c50 100644
--- a/packages/desktop-client/src/components/reports/reports/Spending.tsx
+++ b/packages/desktop-client/src/components/reports/reports/Spending.tsx
@@ -18,7 +18,6 @@ import * as d from 'date-fns';
import { send } from 'loot-core/platform/client/fetch';
import * as monthUtils from 'loot-core/shared/months';
-import { amountToCurrency } from 'loot-core/shared/util';
import {
type SpendingWidget,
type RuleConditionEntity,
@@ -42,6 +41,7 @@ import { calculateSpendingReportTimeRange } from '@desktop-client/components/rep
import { createSpendingSpreadsheet } from '@desktop-client/components/reports/spreadsheets/spending-spreadsheet';
import { useReport } from '@desktop-client/components/reports/useReport';
import { fromDateRepr } from '@desktop-client/components/reports/util';
+import { useFormat } from '@desktop-client/hooks/useFormat';
import { useLocale } from '@desktop-client/hooks/useLocale';
import { useNavigate } from '@desktop-client/hooks/useNavigate';
import { useRuleConditionFilters } from '@desktop-client/hooks/useRuleConditionFilters';
@@ -71,6 +71,7 @@ function SpendingInternal({ widget }: SpendingInternalProps) {
const locale = useLocale();
const dispatch = useDispatch();
const { t } = useTranslation();
+ const format = useFormat();
const {
conditions,
@@ -507,8 +508,9 @@ function SpendingInternal({ widget }: SpendingInternalProps) {
right={
<Text style={{ fontWeight: 600 }}>
<PrivacyFilter>
- {amountToCurrency(
+ {format(
Math.abs(data.intervalData[todayDay].compare),
+ 'financial',
)}
</PrivacyFilter>
</Text>
@@ -540,8 +542,9 @@ function SpendingInternal({ widget }: SpendingInternalProps) {
right={
<Text style={{ fontWeight: 600 }}>
<PrivacyFilter>
- {amountToCurrency(
+ {format(
Math.abs(data.intervalData[todayDay].compareTo),
+ 'financial',
)}
</PrivacyFilter>
</Text>
@@ -564,8 +567,11 @@ function SpendingInternal({ widget }: SpendingInternalProps) {
right={
<Text style={{ fontWeight: 600 }}>
<PrivacyFilter>
- {amountToCurrency(
- Math.abs(data.intervalData[todayDay].budget),
+ {format(
+ Math.round(
+ Math.abs(data.intervalData[todayDay].budget),
+ ),
+ 'financial',
)}
</PrivacyFilter>
</Text>
@@ -595,8 +601,9 @@ function SpendingInternal({ widget }: SpendingInternalProps) {
right={
<Text style={{ fontWeight: 600 }}>
<PrivacyFilter>
- {amountToCurrency(
+ {format(
Math.abs(data.intervalData[todayDay].average),
+ 'financial',
)}
</PrivacyFilter>
</Text>
diff --git a/packages/desktop-client/src/components/reports/reports/SpendingCard.tsx b/packages/desktop-client/src/components/reports/reports/SpendingCard.tsx
index d54df5c31d..e0153b685a 100644
--- a/packages/desktop-client/src/components/reports/reports/SpendingCard.tsx
+++ b/packages/desktop-client/src/components/reports/reports/SpendingCard.tsx
@@ -7,7 +7,6 @@ import { theme } from '@actual-app/components/theme';
import { View } from '@actual-app/components/view';
import * as monthUtils from 'loot-core/shared/months';
-import { amountToCurrency } from 'loot-core/shared/util';
import { type SpendingWidget } from 'loot-core/types/models';
import { PrivacyFilter } from '@desktop-client/components/PrivacyFilter';
@@ -19,6 +18,7 @@ import { ReportCardName } from '@desktop-client/components/reports/ReportCardNam
import { calculateSpendingReportTimeRange } from '@desktop-client/components/reports/reportRanges';
import { createSpendingSpreadsheet } from '@desktop-client/components/reports/spreadsheets/spending-spreadsheet';
import { useReport } from '@desktop-client/components/reports/useReport';
+import { useFormat } from '@desktop-client/hooks/useFormat';
type SpendingCardProps = {
widgetId: string;
@@ -36,6 +36,7 @@ export function SpendingCard({
onRemove,
}: SpendingCardProps) {
const { t } = useTranslation();
+ const format = useFormat();
const [compare, compareTo] = calculateSpendingReportTimeRange(meta ?? {});
@@ -137,7 +138,7 @@ export function SpendingCard({
<PrivacyFilter activationFilters={[!isCardHovered]}>
{data &&
(difference && difference > 0 ? '+' : '') +
- amountToCurrency(difference || 0)}
+ format(difference || 0, 'financial')}
</PrivacyFilter>
</Block>
</View>
diff --git a/packages/desktop-client/src/components/reports/reports/Summary.tsx b/packages/desktop-client/src/components/reports/reports/Summary.tsx
index d1382bb7dc..943f855ffd 100644
--- a/packages/desktop-client/src/components/reports/reports/Summary.tsx
+++ b/packages/desktop-client/src/components/reports/reports/Summary.tsx
@@ -17,7 +17,6 @@ import { parseISO } from 'date-fns';
import { send } from 'loot-core/platform/client/fetch';
import * as monthUtils from 'loot-core/shared/months';
-import { amountToCurrency } from 'loot-core/shared/util';
import {
type SummaryContent,
type SummaryWidget,
@@ -43,6 +42,7 @@ import { calculateTimeRange } from '@desktop-client/components/reports/reportRan
import { summarySpreadsheet } from '@desktop-client/components/reports/spreadsheets/summary-spreadsheet';
import { useReport } from '@desktop-client/components/reports/useReport';
import { fromDateRepr } from '@desktop-client/components/reports/util';
+import { useFormat } from '@desktop-client/hooks/useFormat';
import { useLocale } from '@desktop-client/hooks/useLocale';
import { useNavigate } from '@desktop-client/hooks/useNavigate';
import { useRuleConditionFilters } from '@desktop-client/hooks/useRuleConditionFilters';
@@ -74,6 +74,8 @@ type FilterObject = ReturnType<typeof useRuleConditionFilters>;
function SummaryInner({ widget }: SummaryInnerProps) {
const locale = useLocale();
const { t } = useTranslation();
+ const format = useFormat();
+
const [initialStart, initialEnd, initialMode] = calculateTimeRange(
widget?.meta?.timeFrame,
{
@@ -262,6 +264,15 @@ function SummaryInner({ widget }: SummaryInnerProps) {
);
}
+ const getDivisorFormatted = (contentType: string, value: number) => {
+ if (contentType === 'avgPerMonth') {
+ return format(value, 'number');
+ } else if (contentType === 'avgPerTransact') {
+ return format(value, 'number');
+ }
+ return format(Math.round(value), 'financial');
+ };
+
return (
<Page
header={
@@ -408,7 +419,7 @@ function SummaryInner({ widget }: SummaryInnerProps) {
}}
>
<PrivacyFilter>
- {amountToCurrency(data?.dividend ?? 0)}
+ {format(data?.dividend ?? 0, 'financial')}
</PrivacyFilter>
</Text>
<div
@@ -428,7 +439,7 @@ function SummaryInner({ widget }: SummaryInnerProps) {
}}
>
<PrivacyFilter>
- {amountToCurrency(data?.divisor ?? 0)}
+ {getDivisorFormatted(content.type, data?.divisor ?? 0)}
</PrivacyFilter>
</Text>
</View>
@@ -453,7 +464,9 @@ function SummaryInner({ widget }: SummaryInnerProps) {
}}
>
<PrivacyFilter>
- {amountToCurrency(Math.abs(data?.total ?? 0))}
+ {content.type === 'percentage'
+ ? format(Math.abs(data?.total ?? 0), 'number')
+ : format(Math.round(data?.total ?? 0), 'financial')}
{content.type === 'percentage' ? '%' : ''}
</PrivacyFilter>
</View>
diff --git a/packages/desktop-client/src/components/reports/reports/SummaryCard.tsx b/packages/desktop-client/src/components/reports/reports/SummaryCard.tsx
index d7559c396b..f7544a8129 100644
--- a/packages/desktop-client/src/components/reports/reports/SummaryCard.tsx
+++ b/packages/desktop-client/src/components/reports/reports/SummaryCard.tsx
@@ -36,6 +36,7 @@ export function SummaryCard({
}: SummaryCardProps) {
const locale = useLocale();
const { t } = useTranslation();
+
const [start, end] = calculateTimeRange(meta?.timeFrame, {
start: monthUtils.dayFromDate(monthUtils.currentMonth()),
end: monthUtils.currentDay(),
@@ -131,6 +132,7 @@ export function SummaryCard({
{data ? (
<SummaryNumber
value={data?.total ?? 0}
+ contentType={content.type}
suffix={content.type === 'percentage' ? '%' : ''}
loading={!data}
initialFontSize={content.fontSize}
diff --git a/packages/desktop-client/src/components/reports/spreadsheets/calendar-spreadsheet.ts b/packages/desktop-client/src/components/reports/spreadsheets/calendar-spreadsheet.ts
index 629ecc8936..fa2617cb1d 100644
--- a/packages/desktop-client/src/components/reports/spreadsheets/calendar-spreadsheet.ts
+++ b/packages/desktop-client/src/components/reports/spreadsheets/calendar-spreadsheet.ts
@@ -242,17 +242,17 @@ function recalculate(
daysArray.push({
date: currentDate,
incomeSize: getBarLength(currentIncome),
- incomeValue: Math.abs(currentIncome) / 100,
+ incomeValue: Math.abs(currentIncome),
expenseSize: getBarLength(currentExpense),
- expenseValue: Math.abs(currentExpense) / 100,
+ expenseValue: Math.abs(currentExpense),
});
}
}
return {
data: daysArray as CalendarDataType[],
- totalExpense: (totalExpenseValue ?? 0) / 100,
- totalIncome: (totalIncomeValue ?? 0) / 100,
+ totalExpense: totalExpenseValue ?? 0,
+ totalIncome: totalIncomeValue ?? 0,
};
};
diff --git a/packages/desktop-client/src/components/reports/spreadsheets/cash-flow-spreadsheet.tsx b/packages/desktop-client/src/components/reports/spreadsheets/cash-flow-spreadsheet.tsx
index 14dbaa9123..e7c8341899 100644
--- a/packages/desktop-client/src/components/reports/spreadsheets/cash-flow-spreadsheet.tsx
+++ b/packages/desktop-client/src/components/reports/spreadsheets/cash-flow-spreadsheet.tsx
@@ -8,10 +8,10 @@ import { t } from 'i18next';
import { send } from 'loot-core/platform/client/fetch';
import * as monthUtils from 'loot-core/shared/months';
import { q } from 'loot-core/shared/query';
-import { integerToCurrency, integerToAmount } from 'loot-core/shared/util';
import { type RuleConditionEntity } from 'loot-core/types/models';
import { runAll, indexCashFlow } from '@desktop-client/components/reports/util';
+import { type FormatType } from '@desktop-client/hooks/useFormat';
import { type useSpreadsheet } from '@desktop-client/hooks/useSpreadsheet';
export function simpleCashFlow(
@@ -77,6 +77,7 @@ export function cashFlowByDate(
conditions: RuleConditionEntity[] = [],
conditionsOp: 'and' | 'or',
locale: Locale,
+ format: (value: unknown, type?: FormatType) => string,
) {
const start = monthUtils.firstDayOfMonth(startMonth);
const end = monthUtils.lastDayOfMonth(endMonth);
@@ -137,7 +138,7 @@ export function cashFlowByDate(
makeQuery().filter({ amount: { $lt: 0 } }),
],
data => {
- setData(recalculate(data, start, fixedEnd, isConcise, locale));
+ setData(recalculate(data, start, fixedEnd, isConcise, locale, format));
},
);
};
@@ -153,6 +154,7 @@ function recalculate(
end: string,
isConcise: boolean,
locale: Locale,
+ format: (value: unknown, type?: FormatType) => string,
) {
const [startingBalance, income, expense] = data;
const convIncome = income.map(trans => {
@@ -219,39 +221,39 @@ function recalculate(
<div style={{ lineHeight: 1.5 }}>
<AlignedText
left={t('Income:')}
- right={integerToCurrency(income)}
+ right={format(income, 'financial')}
/>
<AlignedText
left={t('Expenses:')}
- right={integerToCurrency(expense)}
+ right={format(expense, 'financial')}
/>
<AlignedText
left={t('Change:')}
- right={<strong>{integerToCurrency(income + expense)}</strong>}
+ right={<strong>{format(income + expense, 'financial')}</strong>}
/>
{creditTransfers + debitTransfers !== 0 && (
<AlignedText
left={t('Transfers:')}
- right={integerToCurrency(creditTransfers + debitTransfers)}
+ right={format(creditTransfers + debitTransfers, 'financial')}
/>
)}
<AlignedText
left={t('Balance:')}
- right={integerToCurrency(balance)}
+ right={format(balance, 'financial')}
/>
</div>
</div>
);
- res.income.push({ x, y: integerToAmount(income) });
- res.expenses.push({ x, y: integerToAmount(expense) });
+ res.income.push({ x, y: income });
+ res.expenses.push({ x, y: expense });
res.transfers.push({
x,
- y: integerToAmount(creditTransfers + debitTransfers),
+ y: creditTransfers + debitTransfers,
});
res.balances.push({
x,
- y: integerToAmount(balance),
+ y: balance,
premadeLabel: label,
amount: balance,
});
diff --git a/packages/desktop-client/src/components/reports/spreadsheets/custom-spreadsheet.ts b/packages/desktop-client/src/components/reports/spreadsheets/custom-spreadsheet.ts
index 79c0c5d976..e50959908a 100644
--- a/packages/desktop-client/src/components/reports/spreadsheets/custom-spreadsheet.ts
+++ b/packages/desktop-client/src/components/reports/spreadsheets/custom-spreadsheet.ts
@@ -2,7 +2,6 @@ import * as d from 'date-fns';
import { send } from 'loot-core/platform/client/fetch';
import * as monthUtils from 'loot-core/shared/months';
-import { integerToAmount } from 'loot-core/shared/util';
import {
type AccountEntity,
type PayeeEntity,
@@ -213,7 +212,7 @@ export function createCustomSpreadsheet({
stackAmounts += netAmounts;
}
if (stackAmounts !== 0) {
- stacked[item.name] = integerToAmount(stackAmounts);
+ stacked[item.name] = stackAmounts; // TODO: not sure yet
}
perIntervalNetAssets =
@@ -244,11 +243,11 @@ export function createCustomSpreadsheet({
index + 1 === intervals.length
? endDate
: monthUtils.subDays(intervals[index + 1], 1),
- totalAssets: integerToAmount(perIntervalAssets),
- totalDebts: integerToAmount(perIntervalDebts),
- netAssets: integerToAmount(perIntervalNetAssets),
- netDebts: integerToAmount(perIntervalNetDebts),
- totalTotals: integerToAmount(perIntervalTotals),
+ totalAssets: perIntervalAssets,
+ totalDebts: perIntervalDebts,
+ netAssets: perIntervalNetAssets,
+ netDebts: perIntervalNetDebts,
+ totalTotals: perIntervalTotals,
});
return arr;
@@ -293,11 +292,11 @@ export function createCustomSpreadsheet({
legend,
startDate,
endDate,
- totalAssets: integerToAmount(totalAssets),
- totalDebts: integerToAmount(totalDebts),
- netAssets: integerToAmount(netAssets),
- netDebts: integerToAmount(netDebts),
- totalTotals: integerToAmount(totalAssets + totalDebts),
+ totalAssets,
+ totalDebts,
+ netAssets,
+ netDebts,
+ totalTotals: totalAssets + totalDebts,
});
setDataCheck?.(true);
};
diff --git a/packages/desktop-client/src/components/reports/spreadsheets/net-worth-spreadsheet.ts b/packages/desktop-client/src/components/reports/spreadsheets/net-worth-spreadsheet.ts
index 7f64527b82..fb32235fb2 100644
--- a/packages/desktop-client/src/components/reports/spreadsheets/net-worth-spreadsheet.ts
+++ b/packages/desktop-client/src/components/reports/spreadsheets/net-worth-spreadsheet.ts
@@ -5,17 +5,13 @@ import keyBy from 'lodash/keyBy';
import { send } from 'loot-core/platform/client/fetch';
import * as monthUtils from 'loot-core/shared/months';
import { q } from 'loot-core/shared/query';
-import {
- integerToCurrency,
- integerToAmount,
- amountToInteger,
-} from 'loot-core/shared/util';
import {
type AccountEntity,
type RuleConditionEntity,
} from 'loot-core/types/models';
import { ReportOptions } from '@desktop-client/components/reports/ReportOptions';
+import { type FormatType } from '@desktop-client/hooks/useFormat';
import { type useSpreadsheet } from '@desktop-client/hooks/useSpreadsheet';
import { aqlQuery } from '@desktop-client/queries/aqlQuery';
@@ -33,6 +29,7 @@ export function createSpreadsheet(
locale: Locale,
interval: string = 'Monthly',
firstDayOfWeekIdx: string = '0',
+ format: (value: unknown, type?: FormatType) => string,
) {
return async (
spreadsheet: ReturnType<typeof useSpreadsheet>,
@@ -143,6 +140,7 @@ export function createSpreadsheet(
locale,
interval,
firstDayOfWeekIdx,
+ format,
),
);
};
@@ -159,6 +157,7 @@ function recalculate(
locale: Locale,
interval: string = 'Monthly',
firstDayOfWeekIdx: string = '0',
+ format: (value: unknown, type?: FormatType) => string,
) {
// Get intervals using the same pattern as other working spreadsheets
const intervals =
@@ -229,7 +228,7 @@ function recalculate(
x = d.parseISO(intervalItem + '-01');
}
- const change = last ? total - amountToInteger(last.y) : 0;
+ const change = last ? total - last.y : 0;
if (arr.length === 0) {
startNetWorth = total;
@@ -251,11 +250,11 @@ function recalculate(
const graphPoint = {
x: d.format(x, displayFormat, { locale }),
- y: integerToAmount(total),
- assets: integerToCurrency(assets),
- debt: `-${integerToCurrency(debt)}`,
- change: integerToCurrency(change),
- networth: integerToCurrency(total),
+ y: total,
+ assets: format(assets, 'financial'),
+ debt: `-${format(debt, 'financial')}`,
+ change: format(change, 'financial'),
+ networth: format(total, 'financial'),
date: d.format(x, tooltipFormat, { locale }),
};
diff --git a/packages/desktop-client/src/components/reports/spreadsheets/recalculate.ts b/packages/desktop-client/src/components/reports/spreadsheets/recalculate.ts
index e920636ac2..b6177011fd 100644
--- a/packages/desktop-client/src/components/reports/spreadsheets/recalculate.ts
+++ b/packages/desktop-client/src/components/reports/spreadsheets/recalculate.ts
@@ -1,5 +1,4 @@
import * as monthUtils from 'loot-core/shared/months';
-import { amountToInteger, integerToAmount } from 'loot-core/shared/util';
import {
type GroupedEntity,
type IntervalEntity,
@@ -81,16 +80,14 @@ export function recalculate({
const intervalTotals = intervalAssets + intervalDebts;
- const change = last
- ? intervalTotals - amountToInteger(last.totalTotals)
- : 0;
+ const change = last ? intervalTotals - last.totalTotals : 0;
arr.push({
- totalAssets: integerToAmount(intervalAssets),
- totalDebts: integerToAmount(intervalDebts),
- netAssets: intervalTotals > 0 ? integerToAmount(intervalTotals) : 0,
- netDebts: intervalTotals < 0 ? integerToAmount(intervalTotals) : 0,
- totalTotals: integerToAmount(intervalTotals),
+ totalAssets: intervalAssets,
+ totalDebts: intervalDebts,
+ netAssets: intervalTotals > 0 ? intervalTotals : 0,
+ netDebts: intervalTotals < 0 ? intervalTotals : 0,
+ totalTotals: intervalTotals,
change,
intervalStartDate: index === 0 ? startDate : intervalItem,
intervalEndDate:
@@ -109,11 +106,11 @@ export function recalculate({
return {
id: item.id || '',
name: item.name,
- totalAssets: integerToAmount(totalAssets),
- totalDebts: integerToAmount(totalDebts),
- netAssets: totalTotals > 0 ? integerToAmount(totalTotals) : 0,
- netDebts: totalTotals < 0 ? integerToAmount(totalTotals) : 0,
- totalTotals: integerToAmount(totalTotals),
+ totalAssets,
+ totalDebts,
+ netAssets: totalTotals > 0 ? totalTotals : 0,
+ netDebts: totalTotals < 0 ? totalTotals : 0,
+ totalTotals,
intervalData,
};
}
diff --git a/packages/desktop-client/src/components/reports/spreadsheets/spending-spreadsheet.ts b/packages/desktop-client/src/components/reports/spreadsheets/spending-spreadsheet.ts
index b01736408f..08be443610 100644
--- a/packages/desktop-client/src/components/reports/spreadsheets/spending-spreadsheet.ts
+++ b/packages/desktop-client/src/components/reports/spreadsheets/spending-spreadsheet.ts
@@ -4,7 +4,6 @@ import keyBy from 'lodash/keyBy';
import { send } from 'loot-core/platform/client/fetch';
import * as monthUtils from 'loot-core/shared/months';
import { q } from 'loot-core/shared/query';
-import { integerToAmount } from 'loot-core/shared/util';
import {
type RuleConditionEntity,
type SpendingMonthEntity,
@@ -133,8 +132,7 @@ export function createSpendingSpreadsheet({
const dailyBudget =
budgets &&
- integerToAmount(budgets.reduce((a, v) => (a = a + v.amount), 0)) /
- compareInterval.length;
+ budgets.reduce((a, v) => (a = a + v.amount), 0) / compareInterval.length;
const intervals = monthUtils.dayRangeInclusive(startDate, endDate);
if (endDateTo < startDate || startDateTo > endDate) {
@@ -224,14 +222,12 @@ export function createSpendingSpreadsheet({
arr.push({
date: intervalItem,
- totalDebts: integerToAmount(perIntervalDebts),
- totalAssets: integerToAmount(perIntervalAssets),
- totalTotals: integerToAmount(
- perIntervalDebts + perIntervalAssets,
- ),
+ totalDebts: perIntervalDebts,
+ totalAssets: perIntervalAssets,
+ totalTotals: perIntervalDebts + perIntervalAssets,
cumulative:
intervalItem <= monthUtils.currentDay()
- ? integerToAmount(cumulativeDebts + cumulativeAssets)
+ ? cumulativeDebts + cumulativeAssets
: null,
});
}
@@ -255,7 +251,7 @@ export function createSpendingSpreadsheet({
return {
months: indexedData,
day,
- average: integerToAmount(averageSum) / monthCount,
+ average: Math.round(averageSum / monthCount),
compare: dayData.filter(c => c.month === compare)[0].cumulative,
compareTo: dayData.filter(c => c.month === compareTo)[0].cumulative,
budget: totalBudget,
@@ -266,9 +262,9 @@ export function createSpendingSpreadsheet({
intervalData,
startDate,
endDate,
- totalDebts: integerToAmount(totalDebts),
- totalAssets: integerToAmount(totalAssets),
- totalTotals: integerToAmount(totalAssets + totalDebts),
+ totalDebts,
+ totalAssets,
+ totalTotals: totalAssets + totalDebts,
});
};
}
diff --git a/packages/desktop-client/src/components/reports/spreadsheets/summary-spreadsheet.ts b/packages/desktop-client/src/components/reports/spreadsheets/summary-spreadsheet.ts
index bbecdb805f..aa9aa37585 100644
--- a/packages/desktop-client/src/components/reports/spreadsheets/summary-spreadsheet.ts
+++ b/packages/desktop-client/src/components/reports/spreadsheets/summary-spreadsheet.ts
@@ -132,8 +132,8 @@ export function summarySpreadsheet(
case 'sum':
setData({
...dateRanges,
- total: (data.data[0]?.amount ?? 0) / 100,
- dividend: (data.data[0]?.amount ?? 0) / 100,
+ total: data.data[0]?.amount ?? 0,
+ dividend: data.data[0]?.amount ?? 0,
divisor: 0,
});
break;
@@ -142,10 +142,10 @@ export function summarySpreadsheet(
setData({
...dateRanges,
total:
- ((data.data[0]?.count ?? 0)
+ (data.data[0]?.count ?? 0)
? (data.data[0]?.amount ?? 0) / data.data[0].count
- : 0) / 100,
- dividend: (data.data[0]?.amount ?? 0) / 100,
+ : 0,
+ dividend: data.data[0]?.amount ?? 0,
divisor: data.data[0].count,
});
break;
@@ -211,8 +211,8 @@ function calculatePerMonth(
const averageAmountPerMonth = totalAmount / numMonths;
return {
- total: averageAmountPerMonth / 100,
- dividend: totalAmount / 100,
+ total: averageAmountPerMonth,
+ dividend: totalAmount,
divisor: numMonths,
};
}
@@ -295,7 +295,7 @@ async function calculatePercentage(
const dividend = data.reduce((prev, ac) => prev + (ac?.amount ?? 0), 0);
return {
total: Math.round(((dividend ?? 0) / (divisorValue ?? 1)) * 10000) / 100,
- divisor: (divisorValue ?? 0) / 100,
- dividend: (dividend ?? 0) / 100,
+ divisor: divisorValue ?? 0,
+ dividend: dividend ?? 0,
};
}
diff --git a/upcoming-release-notes/5283.md b/upcoming-release-notes/5283.md
new file mode 100644
index 0000000000..d8cb58e888
--- /dev/null
+++ b/upcoming-release-notes/5283.md
@@ -0,0 +1,6 @@
+---
+category: Features
+authors: [misu-dev]
+---
+
+Add currency display to reports