Salary module (#245)
* feat: implement salary module with personnummer encryption, salary entries, tax tables, and AGI tracking - Added personnummer encryption and decryption functions for secure storage. - Created salary entries handling for journal entries including gross salary, tax withholding, and employer contributions. - Implemented tax table lookup functionality for calculating tax amounts based on monthly income. - Developed SQL migration for salary module including tables for payroll configuration, tax rates, employees, salary runs, salary run employees, salary line items, and AGI declarations. - Established row-level security policies for all new tables to ensure company-scoped access. * feat: add salary calculation modules for 2026 - Implemented engångsskatt calculation for one-time payments with tax brackets. - Added löneväxling functionality for salary sacrifice to pension, including employer savings and warnings. - Created pain.001 generator for salary batch payments in compliance with Swedish banking standards. - Developed PDF template for payslips, including detailed breakdowns and employer costs. - Generated seed data for Swedish tax tables for 2026, including SQL insert statements. - Implemented traktamente calculations for per diem and mileage allowances, adhering to Skatteverket regulations. - Added seed script for populating tax tables in the database. * feat: Update meal reduction percentages in traktamente calculation fix: Remove obsolete seed script for 2026 tax tables feat: Extend SalaryRunStatus type to include 'corrected' status feat: Implement KU10 XML generation endpoint for annual employee income statements feat: Add endpoint for creating corrections to booked salary runs feat: Implement endpoint for sending payslip PDFs to employees feat: Create KU10 XML generator for annual reporting feat: Add salary transaction matcher for auto-linking bank transactions to salary entries chore: Add database migration for salary correction support * feat: replace select elements with custom Select component for employment and salary types * feat: enhance salary calculations with pension entry and avgifter category support
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,24 @@
|
||||
-- =============================================================================
|
||||
-- Salary Correction Support
|
||||
-- =============================================================================
|
||||
-- Per BFL 5 kap 5§: Corrections must preserve originals via storno entries.
|
||||
-- Adds 'corrected' status and correction tracking fields to salary_runs.
|
||||
|
||||
ALTER TABLE public.salary_runs
|
||||
DROP CONSTRAINT IF EXISTS salary_runs_status_check;
|
||||
ALTER TABLE public.salary_runs
|
||||
ADD CONSTRAINT salary_runs_status_check
|
||||
CHECK (status IN ('draft', 'review', 'approved', 'paid', 'booked', 'corrected'));
|
||||
|
||||
ALTER TABLE public.salary_runs
|
||||
ADD COLUMN IF NOT EXISTS is_correction boolean NOT NULL DEFAULT false,
|
||||
ADD COLUMN IF NOT EXISTS corrects_run_id uuid REFERENCES public.salary_runs(id);
|
||||
|
||||
-- Replace unique constraint to allow corrections for the same period.
|
||||
-- Only one non-corrected run per period per company.
|
||||
ALTER TABLE public.salary_runs DROP CONSTRAINT IF EXISTS salary_runs_company_id_period_year_period_month_key;
|
||||
CREATE UNIQUE INDEX idx_salary_runs_period_unique
|
||||
ON public.salary_runs (company_id, period_year, period_month)
|
||||
WHERE status != 'corrected';
|
||||
|
||||
NOTIFY pgrst, 'reload schema';
|
||||
@@ -0,0 +1,33 @@
|
||||
-- =============================================================================
|
||||
-- Fix 1: Add pension_entry_id to salary_runs
|
||||
-- Pension journal entries from löneväxling were created but never stored,
|
||||
-- causing them to be missed during correction reversals.
|
||||
-- =============================================================================
|
||||
|
||||
ALTER TABLE public.salary_runs
|
||||
ADD COLUMN pension_entry_id uuid REFERENCES public.journal_entries(id);
|
||||
|
||||
-- =============================================================================
|
||||
-- Fix 2: Add UNIQUE constraint on employees(company_id, specification_number)
|
||||
-- Prevents duplicate FK570 specification numbers from concurrent inserts.
|
||||
-- The assign_specification_number trigger uses SELECT MAX() without locking,
|
||||
-- so this constraint makes any race condition fail explicitly.
|
||||
-- =============================================================================
|
||||
|
||||
ALTER TABLE public.employees
|
||||
ADD CONSTRAINT employees_company_spec_number_unique
|
||||
UNIQUE (company_id, specification_number);
|
||||
|
||||
-- =============================================================================
|
||||
-- Fix 3: Add avgifter_category to salary_run_employees
|
||||
-- The avgifter rate alone cannot distinguish between reduced_65plus and
|
||||
-- vaxa_stod (both 10.21% in 2026). Store the category from the calculation
|
||||
-- engine so AGI XML generation uses the correct HU rutor breakdown.
|
||||
-- =============================================================================
|
||||
|
||||
ALTER TABLE public.salary_run_employees
|
||||
ADD COLUMN avgifter_category text
|
||||
CHECK (avgifter_category IN ('standard', 'reduced_65plus', 'youth', 'vaxa_stod', 'exempt'));
|
||||
|
||||
-- Schema reload for PostgREST
|
||||
NOTIFY pgrst, 'reload schema';
|
||||
Reference in New Issue
Block a user