fix(bookkeeping): harden correction flow and align VAT/cashflow reports (#726)
Bundles a set of bookkeeping-correctness fixes developed together. Correction / storno flow - correctEntry resolves (and seeds standard BAS) accounts for the corrected lines BEFORE writing the storno. The old order created and posted the storno first, then hit AccountsNotInChartError on the corrected lines and had to cancel it again — leaving a voided 0 kr storno in the chain and permanently burning a voucher number (an unexplained BFNAR 2013:2 gap). It now fails fast with nothing written. - correctEntry re-points the bank transaction and underlag from the reversed original to the live corrected entry, so the transaction keeps reading as booked (and stays correctable) and the underlag travels with it. recordateEntry delegates both relinks to correctEntry. - reverseEntry (engine) clears transactions.journal_entry_id for rows booked by the reversed entry, so a plain storno returns the bank row to "Att bokföra" with a re-booking affordance. The agent paths did this manually; the dashboard reverse route did not. - findUnresolvableAccounts replaces findMissingActiveAccounts in the categorize routes: a standard BAS account merely absent from the chart is seeded on demand by the engine, so pre-validation must not 400 on it — only unknown numbers or deactivated accounts block. - CorrectionChain dims cancelled (0 kr) entries and labels them so they no longer render like a live storno. Report accuracy - calculateVatLiability() (lib/reports/kpi.ts) is shared by the KPI route, the KPI xlsx export and the MCP period-summary tool, and uses the same 26xx accounts as the momsdeklaration (ruta 49). Reverse-charge and import pairs (e.g. 2614 credit + 2645 debit) net to zero instead of inflating the receivable (#715). VAT_OUTPUT_ACCOUNTS / VAT_INPUT_ACCOUNTS are derived from ACCOUNT_RUTA so the widget can never drift from the declaration. - Kassaflödesanalys records erhållna aktieägartillskott (2093) as a financing inflow and counts överkursfond (2086/2097) toward nyemission. 2093 was previously unmapped, so any contribution broke the 19xx reconciliation by exactly the contributed amount (#716). Wired through the report type, both PDF templates, the K3 PDF, the dashboard client and the årsredovisning summary type. Agent guidance - shared-rules: describe the real Accounted correction flow (Rätta rader / Rätta datum / Radera verifikat, on-demand BAS backfill) so the assistant stops inventing flows that don't exist. - verifikation-draft: clearer locked-period guidance. Tests cover all of the above (storno fail-fast + seeding + relink, reverseEntry unlink, findUnresolvableAccounts, VAT netting and the cashflow reconciliation cases). Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
7af4b96d10
commit
88f49c0ccc
+2
-2
@@ -3462,8 +3462,8 @@
|
||||
"def_outstandingReceivables_accounts": "Accounts receivable (1510)",
|
||||
"def_vatLiability_label": "VAT",
|
||||
"def_vatLiability_description": "VAT liability or receivable for the period",
|
||||
"def_vatLiability_formula": "Output VAT (2611 + 2621 + 2631) − Input VAT (2641 + 2645)",
|
||||
"def_vatLiability_accounts": "Output VAT (2611, 2621, 2631), Input VAT (2641, 2645)",
|
||||
"def_vatLiability_formula": "Output VAT (rutor 10–12, 30–32, 60–62) − Input VAT (ruta 48) — same accounts as the VAT declaration",
|
||||
"def_vatLiability_accounts": "Output VAT incl. reverse charge and import (2610–2638), Input VAT (2640–2649)",
|
||||
"def_grossMargin_label": "Gross margin",
|
||||
"def_grossMargin_description": "Share of revenue remaining after cost of goods",
|
||||
"def_grossMargin_formula": "(Revenue − Cost of goods class 4) ÷ Revenue × 100",
|
||||
|
||||
+2
-2
@@ -3462,8 +3462,8 @@
|
||||
"def_outstandingReceivables_accounts": "Kundfordringar (1510)",
|
||||
"def_vatLiability_label": "Moms",
|
||||
"def_vatLiability_description": "Momsskuld eller momsfordran för perioden",
|
||||
"def_vatLiability_formula": "Utgående moms (2611 + 2621 + 2631) − Ingående moms (2641 + 2645)",
|
||||
"def_vatLiability_accounts": "Utgående moms (2611, 2621, 2631), Ingående moms (2641, 2645)",
|
||||
"def_vatLiability_formula": "Utgående moms (rutor 10–12, 30–32, 60–62) − Ingående moms (ruta 48) — samma konton som momsdeklarationen",
|
||||
"def_vatLiability_accounts": "Utgående moms inkl. omvänd skattskyldighet och import (2610–2638), Ingående moms (2640–2649)",
|
||||
"def_grossMargin_label": "Bruttomarginal",
|
||||
"def_grossMargin_description": "Andel av intäkterna som blir kvar efter varuinköp",
|
||||
"def_grossMargin_formula": "(Intäkter − Varukostnad klass 4) ÷ Intäkter × 100",
|
||||
|
||||
Reference in New Issue
Block a user