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

+35 -8
View File
@@ -1,11 +1,13 @@
import { createQuery, keepPreviousData } from "@tanstack/svelte-query";
import { lists } from "#lib/api/lists.js";
import type { TransactionGroup } from "#lib/api/types.js";
import { ratesQuery } from "#lib/dashboard/primary.svelte.js";
import { today } from "#lib/dates.js";
import { display } from "#lib/money/display.svelte.js";
import { period } from "#lib/period.svelte.js";
import type { Flow } from "#lib/reports/flows.js";
import { ledgerQuery, ledgerWindow, ownFlows } from "#lib/reports/ledger.js";
import { pages } from "#lib/reports/queries.js";
import { impliedRates } from "#lib/reports/rates.js";
import { typicalMonths } from "#lib/reports/typical.js";
import { session } from "#lib/session.svelte.js";
import { board, type Kind, monthDay } from "./merchants.js";
@@ -35,19 +37,43 @@ export function useMerchants(kind: () => Kind) {
}),
queryKey: ["merchants-period", period.start, period.end],
}));
const rates = createQuery(() => ({ ...ratesQuery(), enabled: true }));
const flows = $derived(
const own = $derived(
ledger.data && accounts.data ? ownFlows(ledger.data, accounts.data) : []
);
const periodFlows = $derived.by(() => {
const ownPeriod = $derived.by(() => {
if (inside) {
return flows;
return own;
}
return extra.data && accounts.data
? ownFlows(extra.data, accounts.data)
: [];
});
const rates = $derived.by(() => {
if (!display.active) {
return null;
}
const map = new Map<string, number>();
for (const code of new Set([...own, ...ownPeriod].map((f) => f.currency))) {
const rate = display.rate(code);
if (rate === null) {
return null;
}
map.set(code, rate);
}
return map;
});
const merge = $derived(rates ? display.code : null);
const inTarget = (list: Flow[]) =>
rates
? list.map((flow) => ({
...flow,
amount: flow.amount * (rates.get(flow.currency) ?? 0),
}))
: list;
const flows = $derived(inTarget(own));
const periodFlows = $derived(inside ? flows : inTarget(ownPeriod));
const implied = $derived(impliedRates(ledger.data ?? []));
const day = $derived(monthDay(period.range, now));
const result = $derived.by(() => {
if (!(accounts.data && ledger.data && (inside || extra.data))) {
@@ -58,14 +84,15 @@ export function useMerchants(kind: () => Kind) {
(first, flow) => (flow.date < first ? flow.date : first),
now
);
const primary = session.primary?.code ?? "";
const base = merge ?? session.primary?.code ?? "";
return board(accounts.data, flows, periodFlows, {
day,
kind: kind(),
merge,
months: window.months.filter((m) => m <= month),
past: typicalMonths(window.months, period.end, since),
range: period.range,
rate: (code) => rates.data?.[code]?.rate ?? (code === primary ? 1 : 0),
rate: (code) => implied(code, base) ?? 0,
});
});
@@ -80,7 +107,7 @@ export function useMerchants(kind: () => Kind) {
return accounts.error ?? ledger.error ?? extra.error ?? null;
},
get loading() {
return result === null || rates.isPending;
return result === null;
},
get stale() {
return ledger.isFetching || extra.isPlaceholderData;