feat(deadlines): årsstämma replaces bokslut + moms_yearly auto-complete + EU-sales suggestion (#1059)

* feat(deadlines): gate F-skatt reminders on debited preliminary tax, add durable dismissal

The f_skatt deadline was gated on the F-skatt approval flag (DB default
true), giving nearly every company 12 monthly payment reminders for a tax
Skatteverket may not have debited at all (64% of all system deadline rows,
one lifetime completion). Approval carries no recurring obligation; the
monthly duty is payment of debiterad preliminarskatt and exists only while
the debited amount is > 0 (SFL 62 kap. 4-5 par., 55 kap. 2 par.).

- Gate the f_skatt deadline on preliminary_tax_monthly > 0 (field already
  collected at onboarding, previously unread) and retitle it as a payment.
- Storforetag keep the 12th in August (January-only 17th, 62 kap. 3 par.).
- Declare the prod-only preliminary_tax_monthly column in a migration so
  installs built purely from migrations stop failing tax-settings saves.
- Add deadlines.dismissed_at: DELETE on a system deadline now soft-dismisses
  it durably (hard deletes were resurrected by the nightly backfill within
  24h); generator, backfill, and every read surface respect it.
- Prune upcoming f_skatt rows for companies with no debited amount.

Closes part of #1028.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* feat(deadlines): gate AGI on employer registration, stop completing AGI deadline at XML generation

The arbetsgivardeklaration deadline was gated on pays_salaries, which is
wrong in both directions: a registered employer must file AGI every month
including nil months (SFL 26 kap. 3 par.), and companies actively running
payroll with the flag off got no AGI reminders at all (each missed monthly
filing risks a forseningsavgift).

- New company_settings.employer_registered (nullable, no default) gates
  AGI and the storforetag skatteinbetalning row; pays_salaries remains a
  fallback for rows saved before the flag existed and keeps its UI meaning.
- Migration backfills employer_registered=true from pays_salaries=true and
  from actual payroll activity (salary_runs).
- New employer_seasonal flag: sasongsregistrerade file only for payment
  months plus a December nil declaration, so only the December-period row
  is generated.
- Settings UI: registration + seasonal checkboxes (sv/en strings).
- AGI XML generation no longer auto-completes the deadline as submitted:
  SFL 26 kap. deems the obligation satisfied only when the declaration has
  come in to Skatteverket. The Skatteverket extension's kvittens reconcile
  remains the confirming path; manual filers tick the deadline themselves.

Part of #1028.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* feat(deadlines): statutory arsstamma replaces bokslut, moms_yearly auto-complete, EU-sales suggestion

- Replace the non-statutory 'bokslut' deadline (3 months after FY end, no
  legal basis, off-by-one month math for broken FYs) with the statutory
  arsstamma deadline: within 6 months of FY end per ABL 7 kap. 10 par.,
  the corporate act that gates the arsredovisning filing chain. Migration
  deletes pending bokslut rows; the backfill cron generates arsstamma rows.
- Complete moms_yearly on Skatteverket submission/kvittens: the yearly
  branch previously returned null with a stale comment claiming annual VAT
  has no deadline type, leaving yearly filers with an eternally open row.
  The fiscal-year tax_period label is derived from company settings.
- Add /api/settings/eu-trade-signal + a tax-settings callout: companies
  with booked EU sales (3108/3308/3107, last 15 months) but EU-trade/PS
  flags off are prompted to confirm the periodisk sammanstallning
  obligation (SFL 35 kap., 1 250 kr late fee per report). Suggestion only,
  never auto-enables.

Part of #1028.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* fix(deadlines): include dismissed_at in DeadlineForm payload

The Deadline type gained the required dismissed_at field; the form's
submit payload literal must carry it for the Omit<Deadline, ...> shape.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* fix(deadlines): make system-deadline dismissal atomic

Constrain the dismiss update to source='system' and verify a row was
actually updated: a concurrent regeneration can delete the row between
lookup and update, and the route must not report a phantom success.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Jakob Wennberg
2026-07-17 17:02:49 +02:00
committed by GitHub
co-authored by Claude Fable 5
parent da4d5a39ae
commit 05b954ac1d
17 changed files with 297 additions and 45 deletions
+3 -1
View File
@@ -248,11 +248,13 @@ describe('Enum schemas', () => {
const types = [
'moms_monthly', 'moms_quarterly', 'moms_yearly', 'f_skatt',
'arbetsgivardeklaration', 'inkomstdeklaration_ef', 'inkomstdeklaration_ab',
'arsredovisning', 'periodisk_sammanstallning', 'bokslut',
'arsredovisning', 'arsstamma', 'periodisk_sammanstallning',
]
for (const t of types) {
expect(TaxDeadlineTypeSchema.safeParse(t).success).toBe(true)
}
// Retired: replaced by the statutory arsstamma deadline (ABL 7:10).
expect(TaxDeadlineTypeSchema.safeParse('bokslut').success).toBe(false)
})
it('NormalBalanceSchema and MappingRuleTypeSchema', () => {
+1 -1
View File
@@ -260,8 +260,8 @@ export const TaxDeadlineTypeSchema = z.enum([
'inkomstdeklaration_ef',
'inkomstdeklaration_ab',
'arsredovisning',
'arsstamma',
'periodisk_sammanstallning',
'bokslut',
])
export const DeadlineSourceSchema = z.enum(['system', 'user'])
+1 -1
View File
@@ -182,8 +182,8 @@ function getSwedishTaxTypeLabel(type: string): string {
inkomstdeklaration_ef: 'Inkomstdeklaration EF',
inkomstdeklaration_ab: 'Inkomstdeklaration AB',
arsredovisning: 'Årsredovisning',
arsstamma: 'Årsstämma',
periodisk_sammanstallning: 'Periodisk sammanställning',
bokslut: 'Bokslut',
}
return labels[type] || type
}
+32
View File
@@ -296,6 +296,38 @@ describe('inkomstdeklaration_ab: digital filing deadlines', () => {
})
})
describe('arsstamma: 6 months after FY end (ABL 7:10)', () => {
const config = getConfig('arsstamma')
it('applies only to aktiebolag', () => {
expect(config.condition(makeSettings())).toBe(true)
expect(config.condition(makeSettings({ entity_type: 'enskild_firma' }))).toBe(false)
})
it('FY end Dec (calendar year) → Jun 30 next year', () => {
const dates = config.generateDates(2026, makeSettings({ fiscal_year_start_month: 1 }))
expect(dates.length).toBe(1)
expect(dates[0]).toMatchObject({ day: 30, month: 5, year: 2026, period: '2025' })
})
it('FY end Apr → Oct 31 same year, broken-FY period label', () => {
const dates = config.generateDates(2026, makeSettings({ fiscal_year_start_month: 5 }))
expect(dates.length).toBe(1)
expect(dates[0]).toMatchObject({ day: 31, month: 9, year: 2026, period: '2025/2026' })
})
it('uses the last day of the deadline month (handles Feb)', () => {
// FY end Aug 2026 → +6 months = Feb 2027
const dates = config.generateDates(2027, makeSettings({ fiscal_year_start_month: 9 }))
expect(dates.length).toBe(1)
expect(dates[0]).toMatchObject({ day: 28, month: 1, year: 2027 })
})
it('no bokslut deadline type exists anymore', () => {
expect(TAX_DEADLINE_CONFIGS.find((c) => (c.type as string) === 'bokslut')).toBeUndefined()
})
})
describe('arsredovisning: 7 months after FY end (ÅRL 8:3)', () => {
const config = getConfig('arsredovisning')
+30 -16
View File
@@ -441,28 +441,42 @@ export const TAX_DEADLINE_CONFIGS: TaxDeadlineConfig[] = [
},
},
// Bokslut (AB) - 31 mars for calendar year
// Årsstämma (AB): within 6 months of FY end per ABL 7 kap. 10 §. Replaces
// the former non-statutory 'bokslut' milestone (3 months had no legal
// basis). The stämma gates the årsredovisning chain: the AR is presented
// and adopted there, and the Bolagsverket filing (arsredovisning row,
// 7 months) requires the adopted AR.
{
type: 'bokslut',
titleTemplate: 'Bokslut räkenskapsår {periodLabel}',
description: 'Bokslut för aktiebolag',
type: 'arsstamma',
titleTemplate: 'Årsstämma räkenskapsår {periodLabel}',
description: 'Årsstämma för aktiebolag (senast sex månader efter räkenskapsårets utgång)',
condition: (s) => s.entity_type === 'aktiebolag',
priority: 'important',
linkedReportType: null,
generateDates: (year, settings) => {
// For calendar year, December 31 is fiscal year end, deadline March 31
if (settings.fiscal_year_start_month === 1) {
return [
{ day: 31, month: 2, year, period: `${year - 1}`, periodLabel: `${year - 1}` }, // March
]
// FY end month (1-indexed)
const fyEndMonth = settings.fiscal_year_start_month === 1 ? 12 : settings.fiscal_year_start_month - 1
// Last day of (FY end month + 6). Swedish fiscal years always end on
// the last day of a calendar month (BFL 3 kap.), so this equals the
// statutory six-month limit.
const results: DeadlineInstance[] = []
for (const endYr of [year - 1, year]) {
const dlMonth0 = ((fyEndMonth - 1) + 6) % 12
const dlYear = (fyEndMonth - 1) + 6 >= 12 ? endYr + 1 : endYr
if (dlYear === year) {
const lastDay = new Date(dlYear, dlMonth0 + 1, 0).getDate()
const periodLabel = fyEndMonth === 12 ? `${endYr}` : `${endYr - 1}/${endYr}`
results.push({
day: lastDay,
month: dlMonth0,
year: dlYear,
period: periodLabel,
periodLabel,
})
}
}
// For non-calendar fiscal years, 3 months after year end
const fiscalYearEnd = settings.fiscal_year_start_month - 1
const deadlineMonth = (fiscalYearEnd + 3) % 12
const deadlineYear = deadlineMonth < fiscalYearEnd ? year + 1 : year
return [
{ day: 31, month: deadlineMonth, year: deadlineYear, period: `${year - 1}/${year}`, periodLabel: `${year - 1}/${year}` },
]
return results
},
},
]