Files
accounted/supabase/migrations/20260517100000_salary_run_employees_agi_removed.sql
T
Mattsson a652dcae1a Skv/e2e overview (#515)
* feat(agi): refactor AGI XML generation and data handling

- Remove deprecated AGI field codes from field-codes.ts.
- Update generate-declaration.ts to include new employee fields and handle absence data with stable specification numbers.
- Enhance XML generation in xml-generator.ts to support new flags for housing benefits and adjusted benefits.
- Introduce new database migrations to support:
  - `removed_from_agi` flag for tombstoning individuppgifter.
  - `benefits_adjusted` flag for tracking adjustments to benefits.
  - `franvaro_specifikationsnummer` for stable absence event identification.
  - `housing_benefit_type` to differentiate between housing benefit types.

* feat: Implement strict validation for AGI employee data and introduce pre-flight validation schemas

- Added Zod schemas for validating employee data in AGI declarations to ensure all required fields are present and correctly typed, preventing silent errors during processing.
- Introduced AGI pre-flight validation schemas for Skatteverket endpoints to validate individual and head unit submissions before sending to the API.
- Created a new audit log table for tracking all outbound calls to Skatteverket, ensuring compliance and traceability for AGI and moms submissions.
- Implemented advisory locks in the database to manage concurrent updates to absence specification numbers, enhancing data integrity.
- Added compliance documentation for GDPR processing activities related to AGI and moms submissions, detailing data handling and retention policies.

* feat: Extend DELETE RLS policy to protect 'declined' signatures in årsredovisning

* fix: Update date handling in salary absence migrations to use immutable year-month key

* fix: Update SELECT policy in skatteverket_api_audit_log to use IN clause for company_id

* feat: Add skatteverket_api_audit_log and salary_absence_franvaro_audit tables with RLS policies and immutable triggers
2026-05-17 23:52:49 +02:00

18 lines
986 B
SQL

-- Add `removed_from_agi` flag to salary_run_employees so a correction can
-- tombstone a previously-submitted individuppgift via Skatteverket FK205
-- Borttag. The xml generator emits the IU with only identity fields
-- (FK201/FK215/FK570/FK006) plus <Borttag>1</Borttag> when this is set —
-- Skatteverket matches on (AgRegistreradId, BetalningsmottagarId,
-- RedovisningsPeriod, Specifikationsnummer) and removes the prior IU.
--
-- Defaults to false. Only meaningful for runs that have an AGI declaration
-- already filed for the period — the UI gates the toggle on that state.
ALTER TABLE salary_run_employees
ADD COLUMN removed_from_agi BOOLEAN NOT NULL DEFAULT false;
COMMENT ON COLUMN salary_run_employees.removed_from_agi IS
'When true, emit this IU as FK205 Borttag in the next AGI XML so Skatteverket removes the prior individuppgift for this employee+period. Use for corrections where an employee should not have been in the run.';
NOTIFY pgrst, 'reload schema';