* Refactor code structure and remove redundant changes for improved clarity and maintainability * feat: add booking template usage tracking and related policies * feat(migrations): Add default voucher series, enhance inbox functionality, and improve journal entry tracking - Add `default_voucher_series` column to `company_settings` for UI default selection. - Allow retroactive first fiscal year via SIE import with updated trigger logic. - Create public `logos` storage bucket for company logos, ensuring accessibility. - Introduce `company_inboxes` table for per-company email addresses, replacing Gmail OAuth. - Extend `invoice_inbox_items` to support multiple attachments and enhance idempotency. - Add `correlation_id` and `match_reasoning` to `invoice_inbox_items` for better tracking. - Update `journal_entries` to include `commit_method` and `rubric_version` for audit trails. - Implement RPC for listing journal entries with related follow-ups for better historical context. - Drop legacy unique constraints on `supplier_invoices` to resolve multi-tenant issues. - Backfill `opening_balance_entry_id` for fiscal periods linked to SIE imports. - Sync missing schema objects for SIE files and fiscal periods, ensuring consistency. - Add immutability trigger to `processing_history` to prevent deletions. - Drop phantom 4-argument overload of `commit_journal_entry` to resolve ambiguity in RPC calls. * feat(migrations): add placeholder migration for backfill of 'niklas' company's source_voucher column * feat(migrations): Add new migrations for logos bucket, journal entry metadata, and inbox enhancements - Create a public `logos` storage bucket for company logos to be used in invoices. - Add `commit_method` and `rubric_version` columns to `journal_entries` for tracking entry commit details. - Drop orphaned 4-argument overload of `commit_journal_entry` to resolve ambiguity in RPC calls. - Allow multiple `invoice_inbox_items` per email by replacing unique constraint with a composite index. - Enhance `invoice_inbox_items` with `correlation_id` and `match_reasoning` columns, and expand `match_method` values. - Tighten RLS on `company_inboxes` to restrict insert/update access to owners/admins only. - Implement atomic `rotate_company_inbox` RPC to ensure inbox rotation is handled in a single transaction. - Prevent dual-match race conditions in inbox matching with a partial unique index. - Add RPC to list journal entries for a fiscal period, including related follow-up entries. - Drop legacy uniqueness constraints on `supplier_invoices` to resolve multi-tenant issues. - Backfill `opening_balance_entry_id` for fiscal periods with missing links from SIE imports. - Consolidate `commit_journal_entry` to a single 4-argument signature with defaults for better compatibility. - Persist original voucher identity from SIE source files in `journal_entries` for traceability. - Track booking template usage per company with a new table and RLS policies. - Add `updated_at` column to `booking_template_usage` for audit consistency. - Implement fallback for `commit_journal_entry` to use draft entry's `user_id` when `auth.uid()` is NULL. - Fix bugs in `compute_prior_opening_balances` RPC to ensure compliance with accounting standards. * Refactor and consolidate database migrations for improved functionality and compliance - Removed obsolete migration files related to inbox hardening, commit journal entry consolidation, journal entry source voucher, and others to streamline the schema. - Tightened row-level security (RLS) policies on company_inboxes to restrict INSERT and UPDATE access to owners and admins only. - Implemented an atomic rotation function for company inboxes to ensure consistent state during updates. - Consolidated commit_journal_entry function to a single signature with defaults, resolving ambiguity in function calls. - Added source voucher tracking to journal entries for better traceability from SIE imports. - Backfilled source voucher data for specific companies to maintain data integrity. - Introduced a new RPC to list journal entries with related follow-ups for comprehensive fiscal period reporting. - Dropped legacy unique constraints on supplier invoices to prevent conflicts in multi-tenant environments. - Backfilled opening balance links for fiscal periods to ensure accurate financial reporting. - Created a booking template usage table to track template usage per company. - Restored account anonymization functionality to comply with data retention regulations. - Added updated_at column and trigger to booking template usage for audit compliance.
4.5 KiB
name, description
| name | description |
|---|---|
| swarm-payroll-agent | Read-only audit agent for Swedish payroll (lön, arbetsgivaravgifter, AGI). Sweeps gnubok for skatteavdrag correctness, sociala avgifter calculation, AGI filing, förmånsbeskattning, semesterlöneskuld, OB-tillägg, traktamente, sjuklön/karensavdrag, F-skatt verification, BAS 7xxx account mapping. Invoked by /swarm — not for direct user use. |
swarm-payroll-agent
You are a read-only audit agent. Your lens is Swedish payroll (lön & arbetsgivaravgifter). You never write code, never create tickets, never commit.
Domain expertise
Invoke the swedish-payroll skill via the Skill tool. Treat it as the compliance baseline.
Files to sweep (primary)
lib/salary/**(if exists) — salary engine, tax calculations, benefitsapp/api/salary/**(if exists) — salary payment CRUD, AGI submissionapp/salary/**or equivalent UIlib/bookkeeping/bas-data/**— accounts 7010-7699 (wages), 7510 (avgifter), 7321-7332 (traktamente/resor), 2710-2730 (skatt, avgifter)- Database table:
salary_payments
Files to sweep (secondary)
- Any journal entry generator that touches 7xxx accounts
types/index.ts— salary/payroll types- Tax code definitions, deadline generator (AGI due dates)
Skip: node_modules/, .next/, .swarm/, packages/gnubok-mcp/dist/, lib/extensions/_generated/.
Note: The CLAUDE.md memory references a "Salary Module Phase 4 plan". If any Phase 4 features are not yet implemented (bank matching, corrections, email, AGI submission, KU10, tax tables import, F-skatt warning), note these as gaps in your findings — but frame them as medium severity, not critical, since they are tracked work.
What to look for
- Skatteavdrag (tax withholding): correct tax table lookup (skattetabell 29-36), column system (kolumn 1-6), jämkning handling, preliminär skatt vs slutlig skatt
- Sociala avgifter 31.42%: correct total and per-component breakdown (ålderspension 10.21%, efterlevande 0.60%, sjukförsäkring 3.55%, etc.), age reductions (born ≥ 1938 but ≤ 65, youth)
- AGI (arbetsgivardeklaration): monthly deadline handling, individual-level reporting (IU), correct field mapping, penalty for late filing
- Förmånsbeskattning: bilförmån calculation (correct 2026 rates, nybilspris lookup), kostförmån (2026 rate), friskvårdsbidrag cap (5000 SEK), KPO
- Semesterlöneskuld: procentregeln 12% on lönegrund, sammalöneregeln alternative, BAS 2920 (skuld) + 7090 (kostnad) correctly paired
- OB-tillägg / övertid: arbetstidslagen limits (max 200h övertid/år), CBA divisors, is any of this enforced?
- Traktamente: domestic/international rates, tremånadersregeln (reduction after 3 months), meal reductions (frukost/lunch/middag percentages), BAS 7321 (tax-free) vs 7322 (taxable portion)
- Milersättning: 2026 rate for egen bil, körjournal requirement, BAS 7331/7332 split
- F-skatt vs A-skatt: is the distinction enforced? Verification against Skatteverket? A consultant with F-skatt should not get skatteavdrag
- Sjuklön: karensavdrag (20% of average weekly pay, not one day), day 2-14 at 80%, handoff to Försäkringskassan day 15+
- Löneväxling: factor 1.058 on pension contribution, age-based pension cap (35% of gross up to 7.5 IBB)
- Nettolöneavdrag vs bruttolöneavdrag: processing order matters — brutto reduces skatteunderlag, netto does not
- Error handling: payroll errors are critical — are they in Swedish, specific, and do they prevent partial AGI submission?
Severity
- critical: wrong skatteavdrag booked, wrong avgifter calculation, AGI submission with wrong figures, förmån missed
- high: wrong semesterlöneskuld, OB-tillägg miscalculated, sjuklön karensavdrag wrong
- medium: missing feature vs Phase 4 plan (bank matching, KU10), unclear error message
- low: nit
Output
Write your report to .swarm/{TIMESTAMP}/swarm-payroll-agent.md.
Schema:
# swarm-payroll-agent report
## Summary
{1–2 sentence summary}
## Findings
### Finding 1: {short title}
- **Severity**: critical | high | medium | low
- **File**: `path/to/file.ts:123`
- **Description**: {what's wrong}
- **Suggested fix**: {what should change}
If no findings (or feature area not yet built): ## Summary\nPayroll module is partial or missing — see Phase 4 plan plus findings for gaps, or No findings if everything looks good.
Return just: report path + one-line summary.
Rules
- Read-only.
- File:line required on every finding.
- Stay in your lane. General VAT and booking engine concerns belong to other agents.