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

+25 -9
View File
@@ -13,6 +13,7 @@ const TOP = 5;
export interface Line {
amount: number;
approx: boolean;
base: number;
code: string;
months: number[];
@@ -40,6 +41,7 @@ export interface Merchant {
export interface Total {
amount: number;
approx: boolean;
base: number;
code: string;
ratio: number | null;
@@ -65,6 +67,7 @@ export interface Board {
export interface Context {
day: number | null;
kind: Kind;
merge: string | null;
months: string[];
past: string[];
range: Range;
@@ -72,6 +75,8 @@ export interface Context {
}
const sum = (values: number[]) => values.reduce((a, b) => a + b, 0);
const foreign = (flows: Flow[], code: string) =>
flows.some((flow) => flow.currency !== code);
function monthly(flows: Flow[]): Map<string, number> {
const map = new Map<string, number>();
@@ -88,6 +93,7 @@ function lineOf(code: string, year: Flow[], now: Flow[], ctx: Context): Line {
const base = ctx.day === null ? 0 : typicalToDay(year, ctx.past, ctx.day);
return {
amount,
approx: foreign(year, code) || foreign(now, code),
base,
code,
months: ctx.months.slice(-SPARK_MONTHS).map((m) => byMonth.get(m) ?? 0),
@@ -131,6 +137,8 @@ function bucket<T>(items: T[], key: (item: T) => string): Map<string, T[]> {
return map;
}
const codeOf = (ctx: Context) => (flow: Flow) => ctx.merge ?? flow.currency;
const latest = (flows: Flow[]) =>
flows.reduce((last, flow) => (flow.date > last ? flow.date : last), "");
@@ -142,8 +150,8 @@ function merchantOf(
now: Flow[],
ctx: Context
): Omit<Merchant, "share"> {
const yearBy = bucket(year, (flow) => flow.currency);
const nowBy = bucket(now, (flow) => flow.currency);
const yearBy = bucket(year, codeOf(ctx));
const nowBy = bucket(now, codeOf(ctx));
const codes = new Set([...yearBy.keys(), ...nowBy.keys()]);
const quiet = now.length === 0;
const lines = [...codes]
@@ -221,8 +229,8 @@ export function board(
}
function totalsOf(year: Flow[], now: Flow[], ctx: Context): Total[] {
const nowBy = bucket(now, (flow) => flow.currency);
const yearBy = bucket(year, (flow) => flow.currency);
const nowBy = bucket(now, codeOf(ctx));
const yearBy = bucket(year, codeOf(ctx));
return [...nowBy]
.map(([code, list]) => {
const amount = sum(list.map((flow) => flow.amount));
@@ -232,6 +240,7 @@ function totalsOf(year: Flow[], now: Flow[], ctx: Context): Total[] {
: typicalToDay(yearBy.get(code) ?? [], ctx.past, ctx.day);
return {
amount,
approx: foreign(list, code),
base,
code,
ratio: ctx.day === null ? null : versus(amount, base),
@@ -254,13 +263,20 @@ export const sortBy =
ORDER[key](a, b) || ORDER.last(a, b) || ORDER.name(a, b);
export function sumLines(merchants: Merchant[]): Total[] {
const map = new Map<string, number>();
const map = new Map<string, Total>();
for (const line of merchants.flatMap((m) => m.lines)) {
map.set(line.code, (map.get(line.code) ?? 0) + line.amount);
const total = map.get(line.code) ?? {
amount: 0,
approx: false,
base: 0,
code: line.code,
ratio: null,
};
total.amount += line.amount;
total.approx ||= line.approx;
map.set(line.code, total);
}
return [...map]
.filter(([, amount]) => amount > 0)
.map(([code, amount]) => ({ amount, base: 0, code, ratio: null }));
return [...map.values()].filter((total) => total.amount > 0);
}
export function byCategory(merchants: Merchant[], none: string): Section[] {