|
11 | 11 | let { report }: { report: Report } = $props() |
12 | 12 | const r = $derived(report) |
13 | 13 |
|
14 | | - type Src = { qty: number; basis: number } |
| 14 | + // premium is a component of basis (paid over melt at acquisition), tracked as a |
| 15 | + // display memo alongside it — NEVER summed into melt/qty/fineOz. |
| 16 | + type Src = { qty: number; basis: number; premium: number } |
15 | 17 | type Group = { |
16 | 18 | key: string |
17 | 19 | product: string |
|
33 | 35 | g = { |
34 | 36 | key, product: l.product, metal: l.metal, fineness: l.fineness, |
35 | 37 | qty: 0, fineOz: 0, melt: 0, |
36 | | - bought: { qty: 0, basis: 0 }, found: { qty: 0, basis: 0 }, |
| 38 | + bought: { qty: 0, basis: 0, premium: 0 }, found: { qty: 0, basis: 0, premium: 0 }, |
37 | 39 | } |
38 | 40 | m.set(key, g) |
39 | 41 | } |
|
43 | 45 | const src = l.activity === 'crh' ? g.found : g.bought |
44 | 46 | src.qty += l.qty |
45 | 47 | src.basis += l.basis_usd |
| 48 | + src.premium += l.premium_usd ?? 0 // memo only — deliberately NOT added to melt/qty/fineOz |
46 | 49 | } |
47 | 50 | return [...m.values()].sort((a, b) => b.melt - a.melt) |
48 | 51 | }) |
|
55 | 58 |
|
56 | 59 | // sourced from both bought + found — the case that "felt wrong", now unified |
57 | 60 | const mixed = (g: Group) => g.bought.qty > 0 && g.found.qty > 0 |
| 61 | +
|
| 62 | + // "bought 3 ($4,621, incl. $225 prem)" — premium surfaced AS A COMPONENT of the |
| 63 | + // basis figure, never as its own total. Suppressed when there's no premium. |
| 64 | + const srcLabel = (verb: string, s: Src) => |
| 65 | + `${verb} ${num(s.qty)} (${money(s.basis)}${s.premium > 0 ? `, incl. ${money(s.premium)} prem` : ''})` |
58 | 66 | </script> |
59 | 67 |
|
60 | 68 | <section class="space-y-2"> |
|
85 | 93 | {g.metal}{g.fineness ? ` · ${g.fineness}` : ''} |
86 | 94 | {#if g.bought.qty > 0 || g.found.qty > 0} |
87 | 95 | <span class={mixed(g) ? 'font-medium text-foreground' : ''}> |
88 | | - · {#if g.bought.qty > 0}bought {num(g.bought.qty)} ({money(g.bought.basis)}){/if}{#if mixed(g)} · {/if}{#if g.found.qty > 0}found {num(g.found.qty)} ({money(g.found.basis)}){/if} |
| 96 | + · {#if g.bought.qty > 0}{srcLabel('bought', g.bought)}{/if}{#if mixed(g)} · {/if}{#if g.found.qty > 0}{srcLabel('found', g.found)}{/if} |
89 | 97 | </span> |
90 | 98 | {/if} |
91 | 99 | </div> |
|
0 commit comments