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

@@ -17,6 +17,7 @@
type ChartSet,
seriesPoints,
} from "#lib/components/dashboard/data.js";
import Money from "#lib/components/Money.svelte";
import PageHeader from "#lib/components/shell/PageHeader.svelte";
import {
ContextMenu,
@@ -27,8 +28,9 @@
ContextMenuTrigger,
} from "#lib/components/ui/context-menu/index.js";
import { daysBetween } from "#lib/dates.js";
import { formatDate, formatMoney, toNumber } from "#lib/format.js";
import { formatDate, toNumber } from "#lib/format.js";
import { ListNav } from "#lib/list-nav.svelte.js";
import { display } from "#lib/money/display.svelte.js";
import { period } from "#lib/period.svelte.js";
import { goto } from "$app/navigation";
import { page } from "$app/state";
@@ -201,6 +203,8 @@
function sortValue(item: Item<Account>, key: Key): string | number {
const a = item.attributes;
const shown = (value: string | null | undefined) =>
display.convert(toNumber(value), a.currency_code) ?? toNumber(value);
switch (key) {
case "name":
return a.name.toLowerCase();
@@ -215,15 +219,15 @@
case "number":
return formatIban(a);
case "balance":
return toNumber(a.current_balance);
return shown(a.current_balance);
case "due":
return toNumber(a.debt_amount);
return shown(a.debt_amount);
case "active":
return a.active ? 1 : 0;
case "activity":
return a.last_activity ?? "";
default:
return toNumber(a.balance_difference);
return shown(a.balance_difference);
}
}
@@ -265,11 +269,43 @@
return (a > b ? 1 : -1) * dir;
});
});
interface Total {
balance: number;
code: string;
decimals: number;
difference: number;
due: number;
symbol: string;
}
const totals = $derived.by(() => {
const map = new Map<string, Total>();
for (const { attributes: a } of matching) {
const code = a.currency_code ?? "";
const t = map.get(code) ?? {
balance: 0,
code,
decimals: a.currency_decimal_places ?? 2,
difference: 0,
due: 0,
symbol: a.currency_symbol ?? code,
};
t.balance += toNumber(a.current_balance);
t.difference += toNumber(a.balance_difference);
t.due += toNumber(a.debt_amount);
map.set(code, t);
}
return [...map.values()];
});
const parts = (list: Total[], key: "balance" | "difference" | "due") =>
list.map((t) => ({ ...t, amount: t[key] }));
const merged = $derived(display.total(parts(totals, "balance")) !== null);
const sections = $derived(perCurrency && !merged);
const grouped = $derived(
perCurrency || sorted.some((item) => item.attributes.object_group_title)
sections || sorted.some((item) => item.attributes.object_group_title)
);
const groups = $derived.by(() => {
if (perCurrency) {
if (sections) {
return byCurrency(
sorted,
(item) => item.attributes.currency_code ?? ""
@@ -298,34 +334,6 @@
const rows = $derived(groups.flatMap((g) => g.items));
const index = $derived(new Map(rows.map((item, i) => [item.id, i])));
interface Total {
balance: number;
code: string;
decimals: number;
difference: number;
due: number;
symbol: string;
}
const totals = $derived.by(() => {
const map = new Map<string, Total>();
for (const { attributes: a } of rows) {
const code = a.currency_code ?? "";
const t = map.get(code) ?? {
balance: 0,
code,
decimals: a.currency_decimal_places ?? 2,
difference: 0,
due: 0,
symbol: a.currency_symbol ?? code,
};
t.balance += toNumber(a.current_balance);
t.difference += toNumber(a.balance_difference);
t.due += toNumber(a.debt_amount);
map.set(code, t);
}
return [...map.values()];
});
const title = $derived(
active ? TYPE_TITLE[type] : `${TYPE_TITLE[type]} (inactive)`
);
@@ -471,7 +479,7 @@
</script>
{#snippet sums(
t: Total,
list: Total[],
label: string,
head = false
)}
@@ -489,23 +497,23 @@
>{label}</span
>
{#if head}
<Amount
{...t}
amount={t.difference}
<Money
class="ml-2 text-[12px] md:hidden"
inline
parts={parts(list, "difference")}
signed
/>
{/if}
{:else if col.key === "balance"}
<span class="num font-semibold"
>{formatMoney({ ...t, amount: t.balance })}</span
>{display.text(parts(list, "balance"))}</span
>
{:else if col.key === "due"}
<span class="num font-semibold"
>{formatMoney({ ...t, amount: t.due })}</span
>{display.text(parts(list, "due"))}</span
>
{:else if col.key === "difference"}
<Amount {...t} amount={t.difference} class="font-semibold" />
<Money class="font-semibold" parts={parts(list, "difference")} />
{/if}
</td>
{/each}
@@ -596,12 +604,13 @@
</thead>
<tbody>
{#each groups as group (group.title)}
{#if perCurrency}
{@const t = totals.find((x) => x.code === group.title)}
{#if sections}
<tr class="h-8 border-cladd-outline border-t-2">
{#if t}
{@render sums(t, group.title, true)}
{/if}
{@render sums(
totals.filter((t) => t.code === group.title),
group.title,
true
)}
</tr>
{:else if grouped}
<tr class="h-8 border-cladd-outline border-t">
@@ -706,13 +715,19 @@
</tr>
{/if}
</tbody>
{#if totals.length > 0 && !perCurrency}
{#if totals.length > 0 && !sections}
<tfoot class="border-cladd-outline border-t-2">
{#each totals as t (t.code)}
{#if merged}
<tr class="h-7">
{@render sums(t, `Total in ${t.code}`)}
{@render sums(totals, "Total")}
</tr>
{/each}
{:else}
{#each totals as t (t.code)}
<tr class="h-7">
{@render sums([t], `Total in ${t.code}`)}
</tr>
{/each}
{/if}
</tfoot>
{/if}
</table>