Gross-to-net payroll with TSD declaration
A complete Estonian payroll calculation engine that processes gross-to-net for all employees in a payroll run. Applies all Estonian tax formulas: 33% social tax (employer), 22% income tax, 1.6% unemployment insurance (employee), 0.8% unemployment insurance (employer), and funded pension at 2%, 3%, or 6% depending on the employee's tier. Handles the basic tax exemption, pre-tax and post-tax voluntary deductions, and pro-rating for mid-month starts/exits. Generates TSD declaration XML files for direct upload to the EMTA (Estonian Tax and Customs Board) portal.
Load payroll run and verify status is "draft"
Fetch all active employees with compensation records, tax settings, and voluntary deductions
Load Estonian tax rates from payroll tax jurisdiction configuration
For each employee: calculate gross pay (pro-rated if mid-month start/exit)
Calculate employee deductions: unemployment insurance (1.6%), funded pension (2%/3%/6%)
Apply pre-tax voluntary deductions
Calculate taxable income = gross - unemployment - pension - pre-tax deductions - basic exemption
Calculate income tax = max(0, taxable income x 22%)
Apply post-tax voluntary deductions
Calculate net pay = gross - all employee taxes and deductions
Calculate employer costs: social tax (33%), employer unemployment (0.8%)
Validate: net pay = gross - total taxes - total deductions (within 0.02 tolerance)
Submit calculation results and show summary table
Fetch calculated or approved payroll run data
Build structured JSON input with per-employee tax details
Run generate_tsd.py script to produce validated XML
Output includes header, summary totals, and Annex 1 per-employee lines
XML ready for upload to e-MTA portal
If any checkpoint fails, the workflow stops and reports the issue. Nothing posts to the ledger until every check passes.
Formulas, templates, regulatory rules — not hardcoded values. Forkable per firm, per client.
Designed to work out-of-the-box with the Arfiti ledger. Claude fetches your data, runs calculations, validates results, and submits entries automatically through MCP.
Or fork it. Skills, commands, validation logic, and reference data are all MIT-licensed. Swap the MCP tool calls for your own backend, or use the reference files as standalone Claude project resources.
Get the next post in your inbox.
Practitioner notes on AI-native finance. One email when something new ships. Unsubscribe any time.