Files
accounted/supabase/migrations/20260508120100_agi_tax_payment_tracking.sql
T
Mattsson 7e81f661b2 Add/skv salary agi (#423)
* feat: add Bankgirot LB-fil support for salary payments and tax payments

- Implemented `generateBgLb` for salary batch payments, producing opening, payment, and closing records.
- Added tests for `generateBgLb` to ensure correct record generation and validation.
- Created `generateBankgiroPaymentBgLb` for single tax payments to Skatteverket, including validation and formatting.
- Added tests for `generateBankgiroPaymentBgLb` to verify record structure and data integrity.
- Introduced `generateSkattekontoOcr` for generating valid OCR references for Skattekonto payments, with tests for various input formats.
- Updated database schema to track payment file formats and timestamps for salary runs and AGI declarations.
- Created a new table for logging salary payslip deliveries to ensure compliance with audit requirements.

* feat: add write permission check and company ID validation for payment file generation

* feat: add write permission check for salary payment file generation
2026-05-09 12:41:16 +02:00

27 lines
1.2 KiB
SQL

-- AGI tax payment tracking.
--
-- An AGI declaration represents both the filing obligation and the resulting
-- tax liability for the period (skatt + avgifter). We track when the payment
-- file (Bankgirot LB to BG 5050-1055) was generated and when the payment
-- actually cleared the bank.
--
-- This avoids a separate `tax_payment_runs` table — the AGI declaration is
-- already keyed on (company_id, period_year, period_month) and carries the
-- exact amounts owed.
ALTER TABLE public.agi_declarations
ADD COLUMN IF NOT EXISTS tax_payment_file_generated_at timestamptz,
ADD COLUMN IF NOT EXISTS tax_payment_file_format text,
ADD COLUMN IF NOT EXISTS tax_paid_at timestamptz,
ADD COLUMN IF NOT EXISTS tax_payment_journal_entry_id uuid REFERENCES public.journal_entries(id);
ALTER TABLE public.agi_declarations
DROP CONSTRAINT IF EXISTS agi_declarations_tax_payment_format_check;
ALTER TABLE public.agi_declarations
ADD CONSTRAINT agi_declarations_tax_payment_format_check
CHECK (tax_payment_file_format IS NULL OR tax_payment_file_format IN ('bg_lb'));
-- Reload PostgREST schema cache so the columns become visible to the API.
NOTIFY pgrst, 'reload schema';