{#if room.size > 0}
{#each [...room] as [id, r] (id)}
{@const linked = all.filter((p) =>
p.attributes.accounts?.some((a) => a.account_id === id)
)}
{@const a = r.account?.attributes}
{@const money = {
code: a?.currency_code,
decimals: a?.currency_decimal_places,
symbol: a?.currency_symbol,
}}
{@const targets = linked.reduce(
(t, p) => t + toNumber(p.attributes.target_amount),
0
)}
Account
Balance
Left for piggy banks
Sum of piggy banks
Saved so far
Left to save
{/each}
{a?.name ?? id}
{formatMoney({ ...money, amount: targets })}
{formatMoney({
...money,
amount: Math.max(0, targets - r.earmarked),
})}