* 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
64 lines
2.4 KiB
TypeScript
64 lines
2.4 KiB
TypeScript
import { describe, it, expect } from 'vitest'
|
|
import { lookupTaxAmount, calculateJamkningTax, calculateSidoinkomstTax } from '../tax-tables'
|
|
import type { TaxTableRate } from '../tax-tables'
|
|
|
|
const sampleRates: TaxTableRate[] = [
|
|
{ tableYear: 2026, tableNumber: 33, columnNumber: 1, incomeFrom: 0, incomeTo: 2200, taxAmount: 0 },
|
|
{ tableYear: 2026, tableNumber: 33, columnNumber: 1, incomeFrom: 2201, incomeTo: 20000, taxAmount: 2800 },
|
|
{ tableYear: 2026, tableNumber: 33, columnNumber: 1, incomeFrom: 20001, incomeTo: 30000, taxAmount: 5600 },
|
|
{ tableYear: 2026, tableNumber: 33, columnNumber: 1, incomeFrom: 30001, incomeTo: 40000, taxAmount: 8900 },
|
|
{ tableYear: 2026, tableNumber: 33, columnNumber: 1, incomeFrom: 40001, incomeTo: 50000, taxAmount: 12500 },
|
|
{ tableYear: 2026, tableNumber: 33, columnNumber: 1, incomeFrom: 50001, incomeTo: 60000, taxAmount: 16800 },
|
|
]
|
|
|
|
describe('lookupTaxAmount', () => {
|
|
it('returns 0 for income below minimum bracket', () => {
|
|
expect(lookupTaxAmount(33, 1, 1500, sampleRates)).toBe(0)
|
|
})
|
|
|
|
it('matches correct bracket for mid-range income', () => {
|
|
expect(lookupTaxAmount(33, 1, 25000, sampleRates)).toBe(5600)
|
|
})
|
|
|
|
it('matches bracket boundary exactly', () => {
|
|
expect(lookupTaxAmount(33, 1, 20001, sampleRates)).toBe(5600)
|
|
expect(lookupTaxAmount(33, 1, 30000, sampleRates)).toBe(5600)
|
|
})
|
|
|
|
it('uses last bracket for income exceeding all brackets', () => {
|
|
expect(lookupTaxAmount(33, 1, 100000, sampleRates)).toBe(16800)
|
|
})
|
|
|
|
it('falls back to 30% when table not found', () => {
|
|
expect(lookupTaxAmount(99, 1, 40000, sampleRates)).toBe(12000)
|
|
})
|
|
|
|
it('filters by correct column', () => {
|
|
const rates: TaxTableRate[] = [
|
|
...sampleRates,
|
|
{ tableYear: 2026, tableNumber: 33, columnNumber: 2, incomeFrom: 0, incomeTo: 50000, taxAmount: 999 },
|
|
]
|
|
expect(lookupTaxAmount(33, 2, 30000, rates)).toBe(999)
|
|
})
|
|
})
|
|
|
|
describe('calculateJamkningTax', () => {
|
|
it('calculates tax using custom percentage', () => {
|
|
expect(calculateJamkningTax(40000, 20)).toBe(8000)
|
|
})
|
|
|
|
it('rounds to 2 decimal places', () => {
|
|
expect(calculateJamkningTax(33333, 15.5)).toBe(5166.62)
|
|
})
|
|
})
|
|
|
|
describe('calculateSidoinkomstTax', () => {
|
|
it('calculates flat 30%', () => {
|
|
expect(calculateSidoinkomstTax(40000)).toBe(12000)
|
|
})
|
|
|
|
it('rounds to 2 decimal places', () => {
|
|
expect(calculateSidoinkomstTax(33333)).toBe(9999.90)
|
|
})
|
|
})
|