Money tracker: accounts can be left out of total wealth (include_in_total)
All checks were successful
Deploy production / deploy (push) Successful in 2m32s

Adds money.accounts.include_in_total (default true). Excluded accounts keep their own balance and line, but are left out of net worth, invested, this month, the projection and the total/All accounts lines.
This commit is contained in:
2026-10-24 02:14:03 +00:00
parent 6f82d1350e
commit a022c45499
7 changed files with 13822 additions and 14 deletions

View File

@@ -127,6 +127,7 @@ export const actions: Actions = {
const name = textField(form, 'name', 80);
const openingBalanceCents = cents(form.get('openingBalance'));
const kind = String(form.get('kind') ?? 'spendable');
const includeInTotal = form.get('includeInTotal') === 'on';
const colorRaw = String(form.get('color') ?? '').trim();
const color = colorRaw ? colorRaw.toLowerCase() : null;
if (!name || openingBalanceCents == null || !['spendable', 'investment'].includes(kind))
@@ -137,14 +138,14 @@ export const actions: Actions = {
if (id) {
const [row] = await db
.update(moneyAccounts)
.set({ name, openingBalanceCents, kind, color })
.set({ name, openingBalanceCents, kind, includeInTotal, color })
.where(and(eq(moneyAccounts.id, id), eq(moneyAccounts.userId, user.id)))
.returning({ id: moneyAccounts.id });
if (!row) error(404, 'Account not found');
} else
await db
.insert(moneyAccounts)
.values({ userId: user.id, name, openingBalanceCents, kind, color });
.values({ userId: user.id, name, openingBalanceCents, kind, includeInTotal, color });
} catch (cause) {
if (typeof cause === 'object' && cause && 'code' in cause && cause.code === '23505')
return invalid('An account with that name already exists.');

View File

@@ -79,9 +79,13 @@
let actualTransactions = $derived(data.transactions.filter((item) => item.date <= data.today));
let futureTransactions = $derived(data.transactions.filter((item) => item.date > data.today));
let balances = $derived(accountBalances(data.accounts, actualTransactions));
let total = $derived([...balances.values()].reduce((sum, value) => sum + value, 0));
let totalAccounts = $derived(data.accounts.filter((account) => account.includeInTotal !== false));
let totalIds = $derived(new Set(totalAccounts.map((account) => account.id)));
let total = $derived(
totalAccounts.reduce((sum, account) => sum + (balances.get(account.id) ?? 0), 0)
);
let invested = $derived(
data.accounts
totalAccounts
.filter((account) => account.kind === 'investment')
.reduce((sum, account) => sum + (balances.get(account.id) ?? 0), 0)
);
@@ -90,7 +94,9 @@
);
let monthNet = $derived(
actualTransactions
.filter((item) => item.date.slice(0, 7) === data.today.slice(0, 7))
.filter(
(item) => item.date.slice(0, 7) === data.today.slice(0, 7) && totalIds.has(item.accountId)
)
.reduce((sum, item) => sum + item.amountCents, 0)
);
let monthlyInsurance = $derived(
@@ -270,7 +276,7 @@
<section class="stat-strip" aria-label="Summary">
<div class="stat net">
<p class="eyebrow">Net worth · {data.accounts.length} accounts</p>
<p class="eyebrow">Net worth · {totalAccounts.length} accounts</p>
<p class="stat-value">{@render signed(total)}</p>
</div>
<div class="stat">
@@ -388,9 +394,10 @@
onclick={() => toggleAccount(account.id)}
>{@render swatch(account.id)}<span
><strong>{account.name}</strong><small class="capitalize"
>{account.kind} · {#if account.bankBalanceAt}bank {amount(
account.bankBalanceCents ?? 0
)}, {new Date(account.bankBalanceAt).toLocaleDateString('en-GB', {
>{account.kind}{#if account.includeInTotal === false}&nbsp;· not in total{/if} · {#if account.bankBalanceAt}bank
{amount(account.bankBalanceCents ?? 0)}, {new Date(
account.bankBalanceAt
).toLocaleDateString('en-GB', {
day: 'numeric',
month: 'short',
hour: '2-digit',
@@ -903,6 +910,10 @@
>Investment accounts are included in total wealth but excluded from the cash reserve.</small
></label
>
<label class="field check-field"
><Checkbox name="includeInTotal" value="on" checked={active.includeInTotal !== false} /> Count
toward total wealth</label
>
<label class="field"
>Color<Input
name="color"