From fd7db19b6592190aa2be7a72a418bbec85e4c0d8 Mon Sep 17 00:00:00 2001 From: ai-bot Date: Sat, 14 Nov 2026 16:16:39 +0000 Subject: [PATCH] Add static/index.js for the main sheet --- static/index.js | 69 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 static/index.js diff --git a/static/index.js b/static/index.js new file mode 100644 index 0000000..37eed13 --- /dev/null +++ b/static/index.js @@ -0,0 +1,69 @@ +/* Skuld — the main sheet: one row per account, the totals, the non-taxable + * accounts and the TOT rows, in the order of docs/spec.md section 7.2. */ + +(function () { + "use strict"; + + var rows = document.querySelector("[data-rows]"); + var sheet = document.querySelector("[data-sheet]"); + var empty = document.querySelector("[data-empty]"); + var yearInput = document.querySelector('[name="year"]'); + + function currentYear() { + return new Date().getFullYear(); + } + + function render(markets, report) { + rows.textContent = ""; + if (!markets.length) { + empty.hidden = false; + sheet.hidden = true; + return; + } + empty.hidden = true; + sheet.hidden = false; + + var totalSats = report.accounts.reduce(function (sum, account) { + return sum + account.sats; + }, 0); + + rows.appendChild(Skuld.totalsRow(report.totals, totalSats)); + report.accounts.forEach(function (account) { + rows.appendChild(Skuld.sheetRow(account)); + }); + + if (report.non_taxable.length) { + rows.appendChild(Skuld.gapRow()); + report.non_taxable.forEach(function (account) { + rows.appendChild(Skuld.satsOnlyRow(account.name, account.sats, "")); + }); + } + + if (report.custody_totals.length) { + rows.appendChild(Skuld.gapRow()); + report.custody_totals.forEach(function (reconciliation) { + rows.appendChild(Skuld.totRow(reconciliation)); + }); + } + } + + function load() { + var year = Number(yearInput.value) || currentYear(); + yearInput.value = year; + Skuld.clearErrors(); + return Promise.all([ + Skuld.api("GET", "/api/markets"), + Skuld.api("GET", "/api/report?year=" + year) + ]).then(function (results) { + render(results[0], results[1]); + }); + } + + Skuld.on("index", function () { + yearInput.value = currentYear(); + yearInput.addEventListener("change", function () { + load().catch(Skuld.showError); + }); + return load(); + }); +})();