πŸƒ Card Ledger: what did I actually spend on cards?

Card Ledger turns a spreadsheet of trading card purchases into one private page: spend KPIs, a monthly chart, a per-vendor breakdown and searchable order and line-item grids. Unknown prices stay unknown, and unverified entries are flagged instead of guessed.

By Dennis Bruijn Β· Β· 8 min read Β· #projects #web-apps #react #echarts #ag-grid #vite

Every Magic player has a question they'd rather not answer out loud. Mine sat in a Google Sheet with a tab per vendor, a Line Items tab and a Summary Overview, and it was thorough but no fun to read. So I gave it a front end. It's one page, it has no backend, and it's careful to say when it doesn't know something.

Watch the 31-second Card Ledger explainer

Brand graphics and React mockups rebuilt in Montage, filled with a synthetic demo ledger. No real orders, amounts or names appear anywhere in this post.

The Card Ledger purchase overview with four KPI cards, a monthly Spend over time bar chart, the By vendor list with five colored tracks and the collapsed Review notes panel

Spend over time, by vendor, under one filter

Four KPIs sit at the top of the page: Purchase spend, Orders, Sales revenue and Net spend. Below them, an Apache ECharts bar chart draws one bar per month in brand violet #6854d9, with an axis tooltip in euros and a ResizeObserver that keeps it the size of its card. Next to it, By vendor lists the five vendors in their own colors, each with its spend and a track showing its share of the filtered total.

One vendor select drives all of it. Pick a vendor and the KPIs, the chart, the vendor list and both grids narrow to that vendor. The chart re-lays its months and axis for that vendor's orders.

Cycling through the five vendors while the KPIs, the monthly bars and the vendor tracks re-animate on each pick

Cycling through the five vendors, with synthetic data (8 seconds). Mockup rebuilt from source with Montage.

Then there's the toggle I'm fondest of: Exclude unverified legacy entries. Any order or line item whose ID starts with BOM- is an old Bazaar of Magic entry that was never checked against an order email. They're in by default. Tick the box and every number on the page recalculates without them.

The cursor ticks Exclude unverified legacy entries, the legacy share of the bars drops out and the order count falls, then the box is unticked and the bars grow back

The hatched gray share and the amber chip are there to explain the GIF. The app just recalculates.

The filtering is plain React state. Every render filters the orders, then sums what's left for the KPIs, the vendor tracks and the monthly chart. Here it is in miniature, with made-up orders and a CSS bar chart standing in for ECharts. Edit the list and see what happens:

<style>
  body { margin: 0; padding: 16px; font: 14px/1.4 system-ui, sans-serif; background: #f6f5fb; color: #1d1b2a; }
  .bar { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
  select { font: inherit; padding: 4px 6px; }
  .kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 12px; }
  .kpi { background: #fff; border-radius: 10px; padding: 10px 12px; box-shadow: 0 1px 2px rgb(0 0 0 / .08); }
  .kpi span { color: #6b6880; font-size: 12px; }
  .kpi b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
  .chart { display: flex; align-items: flex-end; gap: 8px; height: 120px; background: #fff; border-radius: 10px; padding: 12px 12px 26px; }
  .col { flex: 1; min-height: 2px; background: #6854d9; border-radius: 4px 4px 0 0; position: relative; transition: height .3s; }
  .col i { position: absolute; bottom: -20px; left: 50%; transform: translateX(-50%); font: 11px system-ui; color: #6b6880; }
</style>
<div class="bar">
  <select id="vendor"></select>
  <label><input type="checkbox" id="legacy"> Exclude unverified legacy entries</label>
</div>
<div class="kpis">
  <div class="kpi"><span>Purchase spend</span><b id="spend"></b></div>
  <div class="kpi"><span>Orders</span><b id="orders"></b></div>
</div>
<div class="chart" id="chart"></div>
<script>
  // Made-up orders. The real ledger stays in its private repo.
  const orders = [
    { id: "BOM-0001", vendor: "Bazaar of Magic", month: "2025-12", amount: 64 },
    { id: "BOM-0002", vendor: "Bazaar of Magic", month: "2026-01", amount: 38.5 },
    { id: "BAZ-1001", vendor: "Bazaar of Magic", month: "2026-02", amount: 21.9 },
    { id: "SL-2001", vendor: "Secret Lair", month: "2025-12", amount: 29.99 },
    { id: "SL-2002", vendor: "Secret Lair", month: "2026-03", amount: 59.98 },
    { id: "CT-3001", vendor: "CardTrader", month: "2026-01", amount: 17.4 },
    { id: "CT-3002", vendor: "CardTrader", month: "2026-02", amount: 46.25 },
    { id: "CT-3003", vendor: "CardTrader", month: "2026-03", amount: 12.8 },
    { id: "EV-4001", vendor: "Magic Con & Events", month: "2026-02", amount: 75 },
    { id: "PO-5001", vendor: "Private & Other", month: "2026-01", amount: 20 },
  ];
  const vendors = ["Bazaar of Magic", "Secret Lair", "CardTrader", "Magic Con & Events", "Private & Other"];
  const names = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
  const eur = new Intl.NumberFormat("en-NL", { style: "currency", currency: "EUR" });
  const $ = (id) => document.getElementById(id);
  $("vendor").innerHTML = ["All vendors", ...vendors].map((v) => `<option>${v}</option>`).join("");

  function render() {
    const vendor = $("vendor").value;
    const hideLegacy = $("legacy").checked;
    const rows = orders.filter((o) =>
      (vendor === "All vendors" || o.vendor === vendor) && !(hideLegacy && o.id.startsWith("BOM-")));
    $("spend").textContent = eur.format(rows.reduce((sum, o) => sum + o.amount, 0));
    $("orders").textContent = rows.length;
    const byMonth = {};
    for (const o of rows) byMonth[o.month] = (byMonth[o.month] || 0) + o.amount;
    const max = Math.max(1, ...Object.values(byMonth));
    $("chart").innerHTML = Object.keys(byMonth).sort().map((m) =>
      `<div class="col" style="height:${(byMonth[m] / max) * 100}%" title="${m}: ${eur.format(byMonth[m])}"><i>${names[+m.slice(5) - 1]}</i></div>`
    ).join("") || "<p>No orders left.</p>";
  }
  $("vendor").onchange = $("legacy").onchange = render;
  render();
</script>

One honest wrinkle: sales aren't split by vendor, so with a single vendor selected Net spend still subtracts all recorded sales. For a small vendor it happily goes below zero. That's a known limitation, not a bug.

Two grids for the receipts

Charts are nice. Receipts win arguments. Under the charts, an AG Grid Community view switches between Orders (7 columns) and Line items (6 columns), on the Quartz theme tinted violet. Every column sorts on click, filters from its menu and resizes by dragging its edge. A single field, Search orders, cards, vendors…, filters the current grid across all of its columns as you type, and pages hold 25, 50 or 100 rows.

The expanded Review notes panel above the Line items grid, filtered by the search term Collector and sorted by date, with an em dash in the Line total column for an unknown price

Searched for "Collector" and sorted by date, with synthetic data. Mockup rebuilt from source with Montage.

See that em dash in the Line total column? That's the rule I care most about in this project.

Unknown prices stay unknown

Some order emails give only an order total, not a price per line. Spreading the total across the lines would look tidy and be made up. So Card Ledger doesn't. A line total that isn't a number is kept as null and shown as β€”. This is the actual mapping in src/main.jsx, reformatted for reading:

const money = (n) =>
  new Intl.NumberFormat("en-NL", { style: "currency", currency: "EUR" }).format(n)

// Spreadsheet dates are serial numbers: days since 1899-12-30.
const date = (n) =>
  new Date(Date.UTC(1899, 11, 30) + n * 86400000).toISOString().slice(0, 10)

// In the Line Items mapping: no number, no price.
amount: typeof r[6] === "number" ? r[6] : null

Here's the same idea with one made-up order. Give the last line a price, or set another one to null, and watch the note change its tune:

<style>
  body { margin: 0; padding: 16px; font: 14px/1.4 system-ui, sans-serif; background: #f6f5fb; color: #1d1b2a; }
  table { width: 100%; border-collapse: collapse; background: #fff; border-radius: 10px; overflow: hidden; }
  th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid #ecebf3; }
  th { font-size: 12px; color: #6b6880; font-weight: 600; }
  .num { text-align: right; font-variant-numeric: tabular-nums; }
  .note { margin: 12px 0 0; padding: 10px 12px; border-left: 3px solid #6854d9; background: #fff; border-radius: 0 8px 8px 0; }
</style>
<table>
  <thead><tr><th>Qty</th><th>Product</th><th class="num">Line total</th></tr></thead>
  <tbody id="rows"></tbody>
</table>
<p class="note" id="note"></p>
<script>
  // One made-up order whose email gave only an order total for the last line.
  const lines = [
    { quantity: 1, product: "Collector booster", total: 24.95 },
    { quantity: 4, product: "Sleeves, 100 count", total: 39.8 },
    { quantity: 2, product: "Foil single", total: null },
  ];
  const eur = new Intl.NumberFormat("en-NL", { style: "currency", currency: "EUR" });
  const show = (v) => (typeof v === "number" ? eur.format(v) : "β€”");

  document.getElementById("rows").innerHTML = lines.map((l) =>
    `<tr><td>${l.quantity}</td><td>${l.product}</td><td class="num">${show(l.total)}</td></tr>`).join("");

  const known = lines.filter((l) => typeof l.total === "number");
  const sum = known.reduce((s, l) => s + l.total, 0);
  const unknown = lines.length - known.length;
  document.getElementById("note").textContent = unknown
    ? `${known.length} priced lines add up to ${eur.format(sum)}. ${unknown} line has no price, so that is not the order total, and nothing pretends it is.`
    : `Every line has a price, so ${eur.format(sum)} is the sum of the order.`;
</script>

The same honesty runs through the rest of the page. Review notes is a collapsible panel that explains the unverified legacy entries, the two recorded subtotal discrepancies (two emails whose item sums come out above their stated totals) and how empty line prices come about. The ledger keeps the source figures with explicit reconciliation adjustments rather than quietly fixing them.

A prompt instead of a sync

Here's the twist: Card Ledger never talks to Gmail or Google Sheets. Not once. It shows a snapshot, src/data.json, that Vite bundles in at build time. Nothing is fetched at runtime apart from the Inter font.

So how does it stay current? Generate update prompt opens a modal called Refresh your collection data with a ready-made prompt in a read-only text area. Copy update prompt puts it on the clipboard and flips to Copied βœ“. You paste it into an assistant that has Gmail, Google Sheets and the project source (the modal names ChatGPT), and the assistant does the legwork.

The Refresh your collection data modal over the dashboard, with the update prompt in a text area and the copy button reading Copied βœ“

Mockup rebuilt from source with Montage, with synthetic data.

The prompt asks the assistant to:

  1. Search every page of the order-confirmation emails from Bazaar of Magic, Secret Lair and CardTrader, plus refunds, cancellations and shipment updates.
  2. Read the live sheet first, reconcile by vendor and order ID, keep quantities, variants and original prices, count CardTrader merchandise and shipping once each, and keep unknown item prices null.
  3. Leave the unverified legacy entries flagged and the two recorded discrepancies as they are.
  4. Update the vendor tabs, Line Items and Summary Overview, then check rows, formulas, totals and duplicates and report what it couldn't resolve.
  5. Refresh src/data.json from all seven tabs, set the verification date, run npm install and npm run build, deploy the private Site and hand back the updated source as a ZIP.

The whole loop, drawn the boring way:

Order emails (Gmail)
      β”‚
      β–Ό
Google Sheet ──────────► src/data.json ──► src/main.jsx ──► Dashboard
vendor tabs, Line Items   snapshot, 7 tabs  orders, items    KPIs, ECharts, AG Grid
      β–²                                                          β”‚
      β”‚                                                   update prompt
      └──────────── Assistant with Gmail + Sheets β—„β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

One small detail I like: if the clipboard write fails, the button selects the text for you instead. Here's that behavior with a shortened stand-in prompt (not the real one, which contains the sheet link). Sandboxed frames like this one can block the clipboard, so you may well get to see the fallback:

<style>
  body { margin: 0; padding: 16px; font: 14px/1.4 system-ui, sans-serif; background: #f6f5fb; color: #1d1b2a; }
  .modal { background: #fff; border-radius: 12px; padding: 16px; box-shadow: 0 8px 30px rgb(0 0 0 / .12); }
  h3 { margin: 0 0 10px; font-size: 16px; }
  textarea { width: 100%; box-sizing: border-box; font: 12px/1.5 ui-monospace, monospace; border: 1px solid #dcdae8; border-radius: 8px; padding: 8px; resize: none; }
  button { margin-top: 10px; font: inherit; color: #fff; background: #6854d9; border: 0; border-radius: 8px; padding: 8px 14px; cursor: pointer; }
  small { display: block; margin-top: 8px; color: #6b6880; min-height: 1.4em; }
</style>
<div class="modal">
  <h3>Refresh your collection data</h3>
  <textarea id="prompt" rows="5" readonly>Stand-in prompt. Search the order-confirmation emails, read the live sheet first, reconcile by vendor and order ID, keep unknown item prices null, leave legacy entries flagged, then refresh src/data.json and rebuild.</textarea>
  <button id="copy">Copy update prompt</button>
  <small id="hint"></small>
</div>
<script>
  const button = document.getElementById("copy");
  const prompt = document.getElementById("prompt");
  const hint = document.getElementById("hint");
  button.onclick = async () => {
    try {
      await navigator.clipboard.writeText(prompt.value);
      button.textContent = "Copied βœ“";
      hint.textContent = "";
    } catch {
      prompt.focus();
      prompt.select();
      hint.textContent = "The clipboard said no, so the text is selected. Copy it yourself.";
    }
  };
</script>

Under the hood

JavaScript Β· React 19 Β· Vite 7 Β· Apache ECharts 6 Β· AG Grid Community. That's the list.

  • One file of app. src/main.jsx holds the whole app: data mapping, KPIs, chart, grid and update prompt. src/style.css has the layout, colors and two breakpoints: below 1000 px the charts stack, and below 650 px the sidebar folds into a top bar.
  • The data. src/data.json is an array of sheet tabs read by position. Tabs 0 to 4 are the five vendors (the tab name is the vendor), tab 5 is Card Sales & Income (not read by the UI yet) and tab 6 is Line Items. On load, the vendor tabs are flattened into one list of orders and BOM- IDs get flagged as legacy.
  • The chart. Chart creates an ECharts instance on a div, groups the rows by YYYY-MM into monthly bars and disposes of the instance when the rows change or the component unmounts.
  • The grid. AgGridReact registers AllCommunityModule, uses themeQuartz with the violet accent and Inter at 13 px, and gets its search straight from the quickFilterText prop.
  • No config at all. There's no vite.config and no environment variable, so npm run build produces plain static files that any static host can serve.

The shape of one tab, with placeholder values:

[
  { "name": "CardTrader", "values": [["<order ID>", 46000, "<purchase>", "<category>", 12.5, "<status>"]] }
]

And the whole developer workflow:

npm install      # React, ECharts, AG Grid and Vite
npm run dev      # Vite dev server with the bundled snapshot
npm run build    # static files in dist/, the only build check there is
npm run preview  # serve dist/ locally

You need a current browser, npm and Node.js 22.12 or later.

Privacy, because it's my wallet

The snapshot in the repo is real: src/data.json holds my actual purchase records, and the update prompt carries the sheet link and the hosting Site ID. All of it ends up in dist/, so anyone who can open the build can read it. That's why the repo and the deployed Site are private. There's no backend, no accounts and no analytics, and the app never signs in to Google. The clipboard is touched only when you click Copy update prompt. The one third-party request is the Inter font from Google Fonts.

Every image and video in this post is synthetic. None of them shows the real ledger.

What's not there yet

Card Ledger is in development. The honest list:

  • It's a snapshot, not live. New orders show up only after src/data.json is replaced and the app is rebuilt.
  • Some text is hard-coded. The checked date, the Review notes copy, the figures quoted in the update prompt and the Sales revenue value are constants in src/main.jsx.
  • Light theme only. The app has no dark mode yet. The pure-black variants in the README are designed, not real.
  • No tests, no linter, no lockfile. A change is checked with npm run build and a look at the page. Each install resolves the ^ ranges fresh, and Vite warns that the single 2.4 MB JavaScript bundle is above its 500 kB chunk size hint.

And the roadmap:

  • Read Sales revenue from the Card Sales & Income tab and split it by vendor.
  • Derive the checked date, the Review notes counts and the prompt's figures from src/data.json.
  • Add a synthetic src/data.demo.json and a switch to load it, so the app can be shown and developed without personal data.
  • Commit a lockfile and run npm run build on every push.
  • Show the parsed category field as a grid column and as a chart breakdown.

So, what did I actually spend on cards? The dashboard knows. It's private, and it's staying that way.

Card Ledger has its own card on the projects page, with the demo loop, the explainer and the stack at a glance.

Curious about the source? It's private, but access can be granted to anyone interested in contributing. Get in touch.

Unofficial. Not affiliated with or endorsed by Google, OpenAI, Wizards of the Coast or any of the vendors named here. Gmail and Google Sheets are trademarks of Google LLC. ChatGPT is a trademark of OpenAI. Magic: The Gathering and Secret Lair are trademarks of Wizards of the Coast LLC.