feat: every page follows the one-currency mode

Totals, info boxes, section headers, group subtotals, shares and the
per-currency charts on the dashboard, transactions, search, accounts,
merchants, statement, budgets, categories, tags, groups, piggy banks,
reports and the category, tag, budget and merchant pages sum into one
converted amount when the mode is on; charts split by currency merge
into one lane. Inputs, reconciliation and the Foreign column stay exact.

Money moved to or from a debt, loan or mortgage no longer counts as
income or spending in the transaction list boxes; it shows as From
debts and To debts. The running balance of an incoming foreign-currency
transfer shows in the account's currency.
This commit is contained in:
hh committed 2026-10-16 18:49:16 +00:00
1 parent 94466d9be9
commit 617a4700e2
61 files changed
+1427 -798

No files matched your search

+101 -75
View File
@@ -17,13 +17,14 @@
import Box from "#lib/components/Box.svelte";
import Sparkline from "#lib/components/charts/Sparkline.svelte";
import { type Row, useColumn } from "#lib/dashboard/column.svelte.js";
import {
formatPrimary,
inPrimaryTotal,
ratesQuery,
} from "#lib/dashboard/primary.svelte.js";
import { addDays, today } from "#lib/dates.js";
import { formatDate, formatMoney, toNumber } from "#lib/format.js";
import {
formatDate,
formatMoney,
type Money,
toNumber,
} from "#lib/format.js";
import { display } from "#lib/money/display.svelte.js";
import { period } from "#lib/period.svelte.js";
import { session } from "#lib/session.svelte.js";
import {
@@ -37,7 +38,6 @@
accountsChartQuery,
accountsQuery,
byCurrency,
type Cur,
seriesPoints,
} from "./data.js";
@@ -55,7 +55,6 @@
const chart = createQuery(() =>
accountsChartQuery(addDays(now, -TREND_DAYS), now)
);
const rates = createQuery(() => ratesQuery());
const recent = createQueries(() => ({
queries: expanded.map((id) => ({
queryFn: () =>
@@ -97,45 +96,63 @@
);
}
const groups = $derived(
byCurrency(shown, (a) => a.attributes.currency_code ?? "").map(
([code, accounts]) => {
const first = accounts[0].attributes;
return {
accounts,
balance: accounts.reduce(
(s, a) => s + toNumber(a.attributes.current_balance),
0
),
change: accounts.reduce(
(s, a) => s + toNumber(a.attributes.balance_difference),
0
),
code,
cur: {
code,
decimals: first.currency_decimal_places ?? 2,
symbol: first.currency_symbol ?? code,
},
trend: sumSeries(
accounts.map((a) => trends.get(a.attributes.name) ?? [])
),
};
}
)
);
const converted = $derived({
balance: inPrimaryTotal(
groups.map((g) => ({ amount: g.balance, code: g.code })),
rates.data
),
change: inPrimaryTotal(
groups.map((g) => ({ amount: g.change, code: g.code })),
rates.data
),
const moneyOf = (a: Account, amount: Money["amount"]): Money => ({
amount,
code: a.currency_code,
decimals: a.currency_decimal_places ?? 2,
symbol: a.currency_symbol ?? a.currency_code,
});
const balances = $derived(
shown.map((a) => moneyOf(a.attributes, a.attributes.current_balance))
);
const changes = $derived(
shown.map((a) => moneyOf(a.attributes, a.attributes.balance_difference))
);
const total = $derived(display.total(balances));
const change = $derived(display.total(changes));
const sumOf = (
accounts: Item<Account>[],
pick: (a: Account) => string | null | undefined
) => accounts.reduce((s, a) => s + toNumber(pick(a.attributes)), 0);
const converted = (a: Item<Account>) =>
display.convert(
toNumber(a.attributes.current_balance),
a.attributes.currency_code
) ?? 0;
const groups = $derived(
total
? [
{
accounts: shown.toSorted((a, b) => converted(b) - converted(a)),
balance: null,
change: null,
code: total.code,
trend: [],
},
]
: byCurrency(shown, (a) => a.attributes.currency_code ?? "").map(
([code, accounts]) => ({
accounts,
balance: moneyOf(
accounts[0].attributes,
sumOf(accounts, (a) => a.current_balance)
),
change: moneyOf(
accounts[0].attributes,
sumOf(accounts, (a) => a.balance_difference)
),
code,
trend: sumSeries(
accounts.map((a) => trends.get(a.attributes.name) ?? [])
),
})
)
);
const recentRows = $derived(
new Map(
expanded.map((id, i) => [
@@ -221,26 +238,31 @@
{/snippet}
{#snippet balance(
amount: number,
cur: Cur
money: Money
)}
<span class="num font-medium {amount < 0 ? "text-expense" : "text-cladd-fg"}"
>{formatMoney({ amount, ...cur })}</span
<span
class="num font-medium {toNumber(money.amount) < 0
? "text-expense"
: "text-cladd-fg"}"
title={display.active && money.code !== display.code
? formatMoney(money)
: undefined}
>{display.text([money])}</span
>
{/snippet}
<Box body="p-0" href="/accounts/asset" title="Accounts">
{#snippet tools()}
{#if converted.balance !== null}
{#if total}
<span class="num font-semibold text-[13px] text-cladd-fg"
>{formatPrimary(converted.balance)}</span
>{display.text(balances)}</span
>
{#if converted.change}
{#if change?.amount}
<span
class="num text-[12px] {converted.change < 0
class="num text-[12px] {change.amount < 0
? "text-expense"
: "text-income"}"
>{formatPrimary(converted.change, true)}</span
>{display.text(changes, true)}</span
>
{/if}
{/if}
@@ -271,25 +293,29 @@
</thead>
{#each groups as group (group.code)}
<tbody class="border-cladd-outline border-t">
<tr class="h-7 bg-cladd-surface-next/60 font-semibold">
<th
class="pl-3 text-left text-[12px] text-cladd-fg"
scope="rowgroup"
>
{group.code}
</th>
<td class="whitespace-nowrap px-2 text-right">
{@render balance(group.balance, group.cur)}
</td>
<td class="whitespace-nowrap px-2 text-right">
{#if group.change !== 0}
<Amount amount={group.change} signed {...group.cur} />
{/if}
</td>
<td class="hidden pr-3 sm:table-cell">
<div class="flex justify-end">{@render spark(group.trend)}</div>
</td>
</tr>
{#if group.balance && group.change}
<tr class="h-7 bg-cladd-surface-next/60 font-semibold">
<th
class="pl-3 text-left text-[12px] text-cladd-fg"
scope="rowgroup"
>
{group.code}
</th>
<td class="whitespace-nowrap px-2 text-right">
{@render balance(group.balance)}
</td>
<td class="whitespace-nowrap px-2 text-right">
{#if toNumber(group.change.amount) !== 0}
<Amount {...group.change} signed />
{/if}
</td>
<td class="hidden pr-3 sm:table-cell">
<div class="flex justify-end">
{@render spark(group.trend)}
</div>
</td>
</tr>
{/if}
{#each group.accounts as account (account.id)}
{@const a = account.attributes}
{@const key = accountKey(account.id)}
@@ -325,11 +351,11 @@
</div>
</td>
<td class="whitespace-nowrap px-2 text-right">
{@render balance(toNumber(a.current_balance), group.cur)}
{@render balance(moneyOf(a, a.current_balance))}
</td>
<td class="whitespace-nowrap px-2 text-right">
{#if toNumber(a.balance_difference) !== 0}
<Amount amount={a.balance_difference} signed {...group.cur} />
<Amount {...moneyOf(a, a.balance_difference)} signed />
{/if}
</td>
<td class="hidden pr-3 sm:table-cell">