{#snippet actions()} Create new piggy bankc {/snippet} {#snippet tools()} {#if failure} {failure} {/if} {/snippet} {#if piggies.isPending}

Loading piggy banks

{:else if piggies.error}

{piggies.error.message}

{:else if rows.length === 0}

No piggy banks yet. Create a piggy bank

{:else} open || (armed = false)}>
{#each sections as section, s (section.id)} {#each section.items as item, j (item.id)} {@const i = offsets[s] + j} {@const p = item.attributes} {@const pct = p.percentage} nav.click(i, e)} oncontextmenu={() => { menuFor = item; nav.cursor = i; }} > {#if editing?.id === item.id} {/if} {/each} {/each}
Piggy bank Saved so far Target amount Left to save
{section.title} {section.items.length}
{p.name} {#if pct !== null && pct !== undefined}
= 100 ? tones.income : undefined, value: toNumber(p.current_amount), }, ]} /> {percent(pct / 100)}
{/if}
{#if toNumber(p.target_amount) > 0} {formatMoney(piggyMoney(p, p.target_amount))} {/if} {#if toNumber(p.left_to_save) > 0} {formatMoney(piggyMoney(p, p.left_to_save))} {/if}
(editing = null)} piggy={item} rooms={room} />
{#if menuFor} {@const target = menuFor} goto(`/piggy-banks/show/${target.id}`)} >Show goto(`/piggy-banks/edit/${target.id}`)} >Edit startMoney(target, "add")} >Add money startMoney(target, "remove")} >Remove money location.assign( oldUiUrl(`${location.origin}/piggy-banks/show/${target.id}`) )} >Open in old UI { if (!armed) { e.preventDefault(); armed = true; return; } remove(target); }} variant="destructive" >{armed ? "Press again to delete" : "Delete"} {/if}
{/if} {#snippet footer()} Create new piggy bank {/snippet}
{#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 )} {/each}
Account Balance Left for piggy banks Sum of piggy banks Saved so far Left to save
{a?.name ?? id} {formatMoney({ ...money, amount: targets })} {formatMoney({ ...money, amount: Math.max(0, targets - r.earmarked), })}
{/if}