From a5d3ddf6d512bc459cfa450c6b449c2e7a245373 Mon Sep 17 00:00:00 2001 From: Anders Betts Date: Fri, 18 Sep 2026 14:32:23 +0200 Subject: reports: Kapitas-style TUI tables, corrected moms rules (schema v3) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The report views dumped JSON; they now render Saldobalans, Resultatrapport (previous-year column, 89xx bokfört/ej bokfört), Balansrapport (Ing balans/Ing saldo/Period/Utg balans, Beräknat resultat) and Momsrapport ruta för ruta, with Swedish amount formatting (1 234,56). The moms starter rules missed 33xx sales, sent reverse-charge VAT 2614 to box 10 instead of 30 and had box 48 positive. Rules may now share a box and report.vat sums them; box 49 is the sum of the moms boxes only. Schema v3 replaces the rules for existing orgs. Verified on a copy of the live DB: 05=703 200, 10=175 800, 20=1 453, 30=851, 48=-1 030, 49=175 621, matching the Kapitas 2027 export. Ctrl+R reload passes --socket and auto-login no longer rewrites tui.conf; pty tests now run through scripts/tui-sandbox.sh so they cannot touch the real config, cache or bw session. --- docs/PROTOCOL.md | 6 +++++- docs/SCHEMA.md | 8 +++++++- docs/STATE.md | 25 ++++++++++++++++++++----- 3 files changed, 32 insertions(+), 7 deletions(-) (limited to 'docs') diff --git a/docs/PROTOCOL.md b/docs/PROTOCOL.md index 1baf607..35390ae 100644 --- a/docs/PROTOCOL.md +++ b/docs/PROTOCOL.md @@ -367,7 +367,11 @@ vouchers at posting time (`attachment_ids`) or afterwards via | `report.vat` | `from`, `to`, `period_type?` | momsdeklaration ruta för ruta | All reports are pure reads, respect locks, and return JSON rows. Amounts are -öre. `report.vat` returns `{"boxes":[{"box":"05","label":"...","amount_ore":...}],"period":{...}}`. +öre. `report.vat` returns `{"from","to","boxes":[{"box":"05","label":"...","amount_ore":...}],"note"}`. +Rules sharing a box are summed into a single entry. `box 49` is the sum of +the moms boxes (`10`,`11`,`12`,`30`,`31`,`32`,`48`,`60`,`61`,`62`), so box 48 +is signed like the blankett (ingående moms negative); underlag boxes do not +change what is payable. ### 7.7 SIE 4 diff --git a/docs/SCHEMA.md b/docs/SCHEMA.md index 4b22271..db03e43 100644 --- a/docs/SCHEMA.md +++ b/docs/SCHEMA.md @@ -393,6 +393,11 @@ is editable by owners when Skatteverket changes the blankett. The seed rules are data, not code: the system ships a reviewed default set per fiscal year and keeps older sets for older years. +Several rules may target the same `box`; `report.vat` sums them into one entry +per box. Ruta 49 is the sum of the payable boxes only (`10`,`11`,`12`,`30`, +`31`,`32`,`48`,`60`,`61`,`62`); the other boxes are underlag and never change +what is payable. + ### 10.1 Voucher templates (schema v2) Konteringsmallar: named sets of rows with a formula over the variable `x`. @@ -459,7 +464,8 @@ another voucher is posted in between) — clients must not persist it. ## 12. Migrations and versioning - `meta(key TEXT PRIMARY KEY, value TEXT)` holds `schema_version` (integer) - and `created_at`. Current version: **2** (v2 adds the two template tables). + and `created_at`. Current version: **3** (v3 replaces the seeded moms rules + with the corrected mapping; v2 adds the two template tables). - Migrations are forward-only, applied automatically at daemon start, each in one transaction, and require an automatic `VACUUM INTO` snapshot next to the database before starting (`bokfd.db.pre-migration-`). diff --git a/docs/STATE.md b/docs/STATE.md index 458833e..0f8a915 100644 --- a/docs/STATE.md +++ b/docs/STATE.md @@ -1,7 +1,7 @@ # bokf — project state Snapshot for resuming work in a new session. Read with `AGENTS.md` (rules) -and `docs/TUI-GUIDELINES.md` (UI conventions). Dated 2026-09-17. +and `docs/TUI-GUIDELINES.md` (UI conventions). Dated 2026-09-18. ## Status @@ -68,6 +68,17 @@ server/protocol/ledger only. differ. `scripts/deploy.sh --dev` cross-compiles the binaries here and hot-reloads the daemon (SIGHUP re-exec via `docker cp`), skipping the image build and container recreate. +15. **Reports in the TUI**: rendered as fixed-width Swedish tables that mirror + the Kapitas PDF exports (Saldobalans, Resultatrapport with previous-year + column and 89xx bokfört/ej bokfört, Balansrapport with Ing balans/Ing + saldo/Period/Utg balans and Beräknat resultat, Momsrapport ruta för ruta). + The TUI never shows report JSON. Amounts are Swedish formatted + (`1 234,56`); moms rutas are whole kronor truncated like Kapitas. +16. **Moms rules (schema v3)**: default seed covers 05 over 3000-3019, + 3100-3199, 3300-3399, reverse-charge sales (32xx) in 41, EU purchases in + 20/21, reverse-charge output VAT 2614/2624/2634 in 30/31/32, and box 48 + signed negative. Rules may share a box and are summed; box 49 is the sum + of the moms boxes only. v3 migrates existing databases. ## Pending decisions @@ -77,8 +88,9 @@ server/protocol/ledger only. key to link it to a voucher picked from a list. Waiting for a go-ahead. - Priority between **eSKD moms filing** and **bokslut/K2+SRU** for the next backend milestone (eSKD was suggested first). -- Moms `report_rules` seed is a reviewed starter mapping only; must be - checked against the current Skatteverket blankett before filing. +- Moms `report_rules` seed is a corrected starter mapping (schema v3), but + there is still no command/TUI to edit rules per org; add one before filing + if the mapping needs adjustments (SCHEMA.md §10 promises owner editing). ## Backlog (prioritized, from COMPLIANCE.md §10 and the audit) @@ -123,11 +135,14 @@ server/protocol/ledger only. it is still wanted. - TUI smoke tests: drive over a pty with `script -qec`; function-key escape sequences are timing-sensitive there (not an app bug). `Ctrl+N/C/F` are - single bytes and reliable. + single bytes and reliable. Always wrap the run in + `scripts/tui-sandbox.sh -- ./build/bokftui ...`: it isolates + `XDG_CONFIG_HOME`/`XDG_CACHE_HOME` so a test can never overwrite the real + `~/.config/bokf/tui.conf` or `~/.cache/bokf/tui.log`. ## Known caveats - Never commit unless the human asks. - SQLite files must not be backed up live with restic; use `backup.snapshot` (`VACUUM INTO`) and point restic at the snapshots. -- Schema version is 2; forward migrations are in `db.c`. +- Schema version is 3; forward migrations are in `db.c`. -- cgit v1.3