diff options
| author | Anders Betts <anders.betts@gmail.com> | 2026-09-18 14:32:23 +0200 |
|---|---|---|
| committer | Anders Betts <anders.betts@gmail.com> | 2026-09-18 14:32:23 +0200 |
| commit | a5d3ddf6d512bc459cfa450c6b449c2e7a245373 (patch) | |
| tree | e14c2b28e3cd6d7b744f301b5bf498f5feb8f03e /src/db.c | |
| parent | 07b5e5890fedbf71a1503f984dfbc2baa872223c (diff) | |
| download | bokf-a5d3ddf6d512bc459cfa450c6b449c2e7a245373.tar.gz bokf-a5d3ddf6d512bc459cfa450c6b449c2e7a245373.zip | |
reports: Kapitas-style TUI tables, corrected moms rules (schema v3)v0.1.26
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.
Diffstat (limited to 'src/db.c')
| -rw-r--r-- | src/db.c | 30 |
1 files changed, 30 insertions, 0 deletions
@@ -8,6 +8,7 @@ #include "auth.h" #include "config.h" #include "log.h" +#include "seed.h" #include "util.h" static const char SCHEMA_V1[] = @@ -336,6 +337,31 @@ int db_migrate(sqlite3 *db, char **err) } /* Forward-only upgrades for existing databases. */ + +/* v3: the moms starter rules missed 33xx sales, sent 2614 to box 10 and + had box 48 with the wrong sign. Rules were never editable, so replace + them with the corrected defaults for every org. */ +static int db_upgrade_v3(sqlite3 *db, char **err) +{ + if (db_exec(db, "DELETE FROM report_rules WHERE report='vat'", err) != 0) + return -1; + sqlite3_stmt *st = NULL; + if (sqlite3_prepare_v2(db, "SELECT id FROM orgs", -1, &st, NULL) != + SQLITE_OK) { + set_err(err, "database error"); + return -1; + } + while (sqlite3_step(st) == SQLITE_ROW) { + int64_t id = sqlite3_column_int64(st, 0); + if (seed_vat_rules(db, id, err) != 0) { + sqlite3_finalize(st); + return -1; + } + } + sqlite3_finalize(st); + return 0; +} + static int db_upgrade(sqlite3 *db, int from, char **err) { if (db_exec(db, "BEGIN IMMEDIATE", err) != 0) @@ -344,6 +370,10 @@ static int db_upgrade(sqlite3 *db, int from, char **err) db_exec(db, "ROLLBACK", NULL); return -1; } + if (from < 3 && db_upgrade_v3(db, err) != 0) { + db_exec(db, "ROLLBACK", NULL); + return -1; + } char *sql = sqlite3_mprintf( "UPDATE meta SET value='%d' WHERE key='schema_version'", BOKF_SCHEMA_VERSION); |
