* 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
47 lines
1.8 KiB
TypeScript
47 lines
1.8 KiB
TypeScript
import { describe, it, expect } from 'vitest'
|
||
import { calculateEngangsskatt } from '../engangsskatt'
|
||
|
||
describe('calculateEngangsskatt', () => {
|
||
it('calculates 0% tax for very low annual income', () => {
|
||
const result = calculateEngangsskatt(5000, 1000)
|
||
// Annual: 1000 × 12 + 5000 = 17,000 → bracket 0-20,000 → 0%
|
||
expect(result.taxRate).toBe(0.00)
|
||
expect(result.taxAmount).toBe(0)
|
||
})
|
||
|
||
it('calculates tax for moderate annual income', () => {
|
||
const result = calculateEngangsskatt(10000, 25000)
|
||
// Annual: 25000 × 12 + 10000 = 310,000 → bracket 200,001-350,000 → 30%
|
||
expect(result.taxRate).toBe(0.30)
|
||
expect(result.taxAmount).toBe(3000)
|
||
})
|
||
|
||
it('calculates higher tax when annual income crosses state tax threshold', () => {
|
||
const result = calculateEngangsskatt(50000, 55000)
|
||
// Annual: 55000 × 12 + 50000 = 710,000 → bracket 660,401-950,000 → 52%
|
||
expect(result.taxRate).toBe(0.52)
|
||
expect(result.taxAmount).toBe(26000)
|
||
})
|
||
|
||
it('uses total annual income including bonus for bracket lookup', () => {
|
||
const result = calculateEngangsskatt(100000, 40000)
|
||
// Annual: 40000 × 12 + 100000 = 580,000 → bracket 500,001-660,400 → 34%
|
||
expect(result.taxRate).toBe(0.34)
|
||
expect(result.taxAmount).toBe(34000)
|
||
})
|
||
|
||
it('returns calculation steps for transparency', () => {
|
||
const result = calculateEngangsskatt(10000, 30000)
|
||
expect(result.steps.length).toBe(2)
|
||
expect(result.steps[0].label).toBe('Beräknad årsinkomst')
|
||
expect(result.annualIncomeEstimate).toBe(370000) // 30000 × 12 + 10000
|
||
})
|
||
|
||
it('handles very high income bracket', () => {
|
||
const result = calculateEngangsskatt(200000, 120000)
|
||
// Annual: 120000 × 12 + 200000 = 1,640,000 → bracket ≥1,500,001 → 57%
|
||
expect(result.taxRate).toBe(0.57)
|
||
expect(result.taxAmount).toBe(114000)
|
||
})
|
||
})
|