Files
accounted/lib/salary/__tests__/pain001.test.ts
T
Mattsson 04dbb31d7e 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
2026-04-15 11:17:39 +02:00

93 lines
3.1 KiB
TypeScript

import { describe, it, expect } from 'vitest'
import { generatePain001 } from '../payment/pain001-generator'
describe('generatePain001', () => {
const company = {
name: 'Test AB',
orgNumber: '556123-4567',
iban: 'SE1234567890123456789012',
bic: 'ESSESESS',
}
const employees = [
{ name: 'Anna Andersson', clearingNumber: '5678', bankAccountNumber: '1234567890', netSalary: 28000 },
{ name: 'Erik Eriksson', clearingNumber: '1234', bankAccountNumber: '9876543210', netSalary: 32000 },
]
const options = {
messageId: 'GNUBOK-5561234567-2026-04',
paymentDate: '2026-04-25',
periodLabel: '2026-04',
}
it('generates valid XML structure', () => {
const xml = generatePain001(company, employees, options)
expect(xml).toContain('<?xml version="1.0" encoding="UTF-8"?>')
expect(xml).toContain('pain.001.001.03')
expect(xml).toContain('<CstmrCdtTrfInitn>')
expect(xml).toContain('</Document>')
})
it('includes group header with correct counts', () => {
const xml = generatePain001(company, employees, options)
expect(xml).toContain(`<NbOfTxs>2</NbOfTxs>`)
expect(xml).toContain(`<CtrlSum>60000.00</CtrlSum>`)
})
it('includes company details', () => {
const xml = generatePain001(company, employees, options)
expect(xml).toContain('<Nm>Test AB</Nm>')
expect(xml).toContain('SE1234567890123456789012')
expect(xml).toContain('ESSESESS')
})
it('includes SALA category purpose for salary', () => {
const xml = generatePain001(company, employees, options)
expect(xml).toContain('<Cd>SALA</Cd>')
})
it('includes per-employee credit transfers', () => {
const xml = generatePain001(company, employees, options)
expect(xml).toContain('<Nm>Anna Andersson</Nm>')
expect(xml).toContain('<InstdAmt Ccy="SEK">28000.00</InstdAmt>')
expect(xml).toContain('<Nm>Erik Eriksson</Nm>')
expect(xml).toContain('<InstdAmt Ccy="SEK">32000.00</InstdAmt>')
})
it('includes bank account details per employee', () => {
const xml = generatePain001(company, employees, options)
expect(xml).toContain('56781234567890') // Anna's clearing + account
expect(xml).toContain('12349876543210') // Erik's clearing + account
})
it('includes remittance info with period label', () => {
const xml = generatePain001(company, employees, options)
expect(xml).toContain('Lon 2026-04')
})
it('includes payment date', () => {
const xml = generatePain001(company, employees, options)
expect(xml).toContain('<ReqdExctnDt>2026-04-25</ReqdExctnDt>')
})
it('escapes XML special characters', () => {
const specialCompany = { ...company, name: 'Test & Sons <AB>' }
const xml = generatePain001(specialCompany, employees, options)
expect(xml).toContain('Test &amp; Sons &lt;AB&gt;')
expect(xml).not.toContain('Test & Sons <AB>')
})
it('formats amounts with 2 decimal places', () => {
const empWithDecimals = [
{ name: 'Test', clearingNumber: '1234', bankAccountNumber: '5678', netSalary: 28333.33 },
]
const xml = generatePain001(company, empWithDecimals, options)
expect(xml).toContain('28333.33')
})
})