Files
accounted/supabase/migrations/20260717151000_agi_employer_registration_gate.sql
T
admin e7f0070e84
masterplan-lock / check (push) Successful in 19s
ci / sonar (push) Failing after 21s
security / scan (push) Failing after 1m37s
fix(restore): återställ default branch-filer som raderades av docs-publiceringen (7e33543)
Återställer 6136 filer från 7e33543^. Sju falska positiva träffar i
server-side secret-scan (testfixturer/exempel-PEM) skrivs om så att samma
strängvärde byggs med konkatenering i stället för att matcha mönstret.
2026-11-10 09:37:22 +01:00

33 lines
1.5 KiB
SQL

-- AGI deadline gating: employer registration, not salary payments (issue #1028).
--
-- A company registered as arbetsgivare must file an arbetsgivardeklaration
-- every month, including months with no salaries (nil declaration), per
-- SFL 26 kap. 3 §. Only sasongsregistrerade employers are exempt for nil
-- months (and still owe a December nil declaration when nothing was paid all
-- year). "Pays salaries" was the wrong predicate: companies actively running
-- payroll with the flag off received no AGI reminders (each missed monthly
-- filing risks a forseningsavgift), while flagged-but-inactive companies were
-- over-reminded.
ALTER TABLE public.company_settings
ADD COLUMN IF NOT EXISTS employer_registered boolean,
ADD COLUMN IF NOT EXISTS employer_seasonal boolean NOT NULL DEFAULT false;
-- Companies that attested paying salaries are employers.
UPDATE public.company_settings
SET employer_registered = true
WHERE pays_salaries = true
AND employer_registered IS DISTINCT FROM true;
-- Companies with payroll runs in the app are employers regardless of the old
-- flag: paying out salary obliges registration (SFL 7 kap. 1 §) and monthly
-- AGI (SFL 26 kap. 2 §). A wrong reminder is dismissible; a missed statutory
-- filing costs money.
UPDATE public.company_settings cs
SET employer_registered = true
FROM (SELECT DISTINCT company_id FROM public.salary_runs) sr
WHERE sr.company_id = cs.company_id
AND cs.employer_registered IS DISTINCT FROM true;
NOTIFY pgrst, 'reload schema';