fix(bookkeeping): book pre-FY bank transactions on the fiscal year's first day (#1828)

A newly registered company whose first rakenskapsar starts on the
Bolagsverket registration date could not book the aktiekapital deposit,
because the bank transaction is dated BEFORE the registration. Every
surface dead-ended: the manual booking dialog hard-blocked with the date
locked and only offered creating a (legally wrong) pre-registration
fiscal year, and the categorize paths either marked the row categorized
WITHOUT a verifikat ("Delvis bokforda") or silently minted a bogus
calendar-year period before the company existed.

Root cause: entry_date was hard-wired to the bank date with no clamp
against the company's first fiscal period, and the duplicated
ensureFiscalPeriod helpers upserted a calendar-year period for any
uncovered date.

Fix, per BFL (the event belongs to the first fiscal year; the real
affarshaendelse date is preserved on the verifikat):
- createTransactionJournalEntry clamps a pre-FY date into the earliest
  OPEN unlocked fiscal period with entry_date = period_start and appends
  "Affarshaendelse <date>, bokford pa rakenskapsarets forsta dag" to the
  verifikationstext. Interior gaps, future dates, and a closed/locked
  first year keep the old null return.
- Both ensureFiscalPeriod copies (categorize core + web route) skip the
  calendar-period upsert when the date predates the earliest period.
- JournalEntryForm's no_period block offers "Bokfor pa rakenskapsarets
  forsta dag (<date>)" for pre-FY dates instead of proposing a
  pre-registration year; "Skapa rakenskapsar" remains for the other
  no_period cases.

No schema, RPC, or trigger changes: the /book route and the DB triggers
already accept the clamped booking.

Fixes #1825


Claude-Session: https://claude.ai/code/session_01SyDuePXxUFowaPBKpAv8SF

Co-authored-by: Jakob Wennberg <311770904+jakobwennberg-oss@users.noreply.github.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Jakob Wennberg
2026-08-24 13:19:50 +02:00
committed by GitHub
co-authored by Jakob Wennberg Claude Fable 5
parent 62135c0c02
commit 8e3015e541
11 changed files with 470 additions and 20 deletions
+3
View File
@@ -5210,6 +5210,8 @@
"series": "Series",
"no_period_warning": "No fiscal year matches the date {date}",
"no_period_help": "Create a fiscal year that covers this date so you can post it.",
"pre_fy_help": "The date is before the company's first fiscal year. Business events before the fiscal year's start are posted on its first day; the event date is noted in the voucher text.",
"pre_fy_book_on_first_day": "Post on the fiscal year's first day ({date})",
"create_period": "Create fiscal year",
"currency": "Currency",
"exchange_rate_label": "Exchange rate (1 {currency} = ? SEK)",
@@ -5247,6 +5249,7 @@
"validation_description": "Enter a description",
"validation_period": "Select a fiscal period",
"validation_no_matching_period": "Create a fiscal year that matches the date",
"validation_pre_fy": "The date is before the first fiscal year: use Post on the fiscal year's first day",
"validation_uploading": "Wait until files have finished uploading",
"validation_incomplete_lines": "All lines with an amount must have an account (and vice versa)",
"validation_min_lines": "At least two lines with account and amount are required",
+3
View File
@@ -5210,6 +5210,8 @@
"series": "Serie",
"no_period_warning": "Inget räkenskapsår matchar datumet {date}",
"no_period_help": "Skapa ett räkenskapsår som täcker detta datum för att kunna bokföra.",
"pre_fy_help": "Datumet ligger före företagets första räkenskapsår. Affärshändelser före räkenskapsårets start bokförs på årets första dag; händelsedatumet anges i verifikationstexten.",
"pre_fy_book_on_first_day": "Bokför på räkenskapsårets första dag ({date})",
"create_period": "Skapa räkenskapsår",
"currency": "Valuta",
"exchange_rate_label": "Omräkningskurs (1 {currency} = ? SEK)",
@@ -5247,6 +5249,7 @@
"validation_description": "Ange en beskrivning",
"validation_period": "Välj en räkenskapsperiod",
"validation_no_matching_period": "Skapa ett räkenskapsår som matchar datumet",
"validation_pre_fy": "Datumet ligger före första räkenskapsåret: välj Bokför på räkenskapsårets första dag",
"validation_uploading": "Vänta tills filerna laddats upp",
"validation_incomplete_lines": "Alla rader med belopp måste ha ett konto (och tvärtom)",
"validation_min_lines": "Minst två rader med konto och belopp krävs",