feat(deadlines): gate AGI on employer registration + stop completing AGI at XML generation (#1062)

* 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>

* 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 16:04:05 +02:00
committed by GitHub
co-authored by Claude Fable 5
parent 3c0bf3f584
commit da4d5a39ae
14 changed files with 183 additions and 21 deletions
+60 -1
View File
@@ -17,6 +17,12 @@ export function TaxSettingsForm({ settings }: TaxSettingsFormProps) {
const [vatRegistered, setVatRegistered] = useState(settings.vat_registered ?? false)
const [fSkatt, setFSkatt] = useState(settings.f_skatt ?? true)
const [paysSalaries, setPaysSalaries] = useState(settings.pays_salaries ?? false)
// Fall back to pays_salaries for rows saved before the registration flag
// existed; saving attests the shown value.
const [employerRegistered, setEmployerRegistered] = useState(
settings.employer_registered ?? settings.pays_salaries ?? false,
)
const [employerSeasonal, setEmployerSeasonal] = useState(settings.employer_seasonal ?? false)
const [momsPeriod, setMomsPeriod] = useState(settings.moms_period || '')
const [vatTaxableBaseOver40m, setVatTaxableBaseOver40m] = useState(
settings.vat_taxable_base_over_40m ?? false,
@@ -340,7 +346,12 @@ export function TaxSettingsForm({ settings }: TaxSettingsFormProps) {
<Checkbox
id="pays_salaries"
checked={paysSalaries}
onCheckedChange={(v) => setPaysSalaries(v === true)}
onCheckedChange={(v) => {
const checked = v === true
setPaysSalaries(checked)
// Paying out salary obliges employer registration (SFL 7 kap. 1 §).
if (checked) setEmployerRegistered(true)
}}
/>
<input type="hidden" name="pays_salaries" value={paysSalaries ? 'true' : 'false'} />
<div className="space-y-1">
@@ -350,6 +361,54 @@ export function TaxSettingsForm({ settings }: TaxSettingsFormProps) {
</p>
</div>
</div>
<div className="flex items-start space-x-3">
<Checkbox
id="employer_registered"
checked={employerRegistered}
onCheckedChange={(v) => {
const checked = v === true
setEmployerRegistered(checked)
if (!checked) setEmployerSeasonal(false)
}}
/>
<input
type="hidden"
name="employer_registered"
value={employerRegistered ? 'true' : 'false'}
/>
<div className="space-y-1">
<Label htmlFor="employer_registered" className="cursor-pointer">
{t('employer_registered_label')}
</Label>
<p className="text-xs text-muted-foreground">
{t('employer_registered_help')}
</p>
</div>
</div>
{employerRegistered && (
<div className="flex items-start space-x-3 pl-7">
<Checkbox
id="employer_seasonal"
checked={employerSeasonal}
onCheckedChange={(v) => setEmployerSeasonal(v === true)}
/>
<input
type="hidden"
name="employer_seasonal"
value={employerSeasonal ? 'true' : 'false'}
/>
<div className="space-y-1">
<Label htmlFor="employer_seasonal" className="cursor-pointer">
{t('employer_seasonal_label')}
</Label>
<p className="text-xs text-muted-foreground">
{t('employer_seasonal_help')}
</p>
</div>
</div>
)}
</section>
{/* Preliminary tax */}
@@ -48,6 +48,7 @@ export function TaxSettingsContent() {
function handleSave(formData: FormData) {
const vatRegistered = formData.get('vat_registered') === 'true'
const paysSalaries = formData.get('pays_salaries') === 'true'
const employerRegistered = formData.get('employer_registered') === 'true'
const updates: Record<string, unknown> = {
f_skatt: formData.get('f_skatt') === 'true',
@@ -80,6 +81,10 @@ export function TaxSettingsContent() {
tax_contact_email: (formData.get('tax_contact_email') as string) || null,
fiscal_year_start_month: parseInt(formData.get('fiscal_year_start_month') as string) || 1,
pays_salaries: paysSalaries,
employer_registered: employerRegistered,
// The seasonal checkbox is unmounted when not registered; absence
// means false rather than "keep stored value".
employer_seasonal: employerRegistered && formData.get('employer_seasonal') === 'true',
preliminary_tax_monthly: parseFloat(formData.get('preliminary_tax_monthly') as string) || null,
}
return {