For few years now I have using google sheets to keep track of taxes and check payroll tax calculations (trust but verify, Right?). Anyway, I decided to move to Jupyter notebook/python combo to do the calculations. This is small code to calculate the Irish tax (PAYE, USC, PRSI). I have a bigger dashboard with ESPP, RSU and bonus but I thought it would be an overkill here.

Jupyter Link to heading

To start a Jupyter notebook:

jupyter notebook

And we are good to go.

Tax calculations Link to heading

Full disclosure, I tried to make it generic as much as I can but I ignored PRSI credit because it is 12 euro (I think).

from collections import namedtuple
Deduction = namedtuple("Deduction", "name value per is_paye is_usc is_prsi")
Extra     = namedtuple("Extra", "name value")

# info from tax cert
tax_cred = 200
paye_tax_band = [
    (40000, 0.2), 
    (0,     0.4)
]
usc_tax_band = [
    (12012,0.005),
    (10908,0.02),
    (47124,0.045),
    (0,0.08)
]
prsi_tax_band = 0.04

# Info from payslip
gross_yearly = 0 # <<<<<<<<<<<<<<<<<<< GROSS before tax
extra = [
        Extra("BIK", ),
]

ded = [
    Deduction("DCP",         0,      .07,  0, 1, 1),
    Deduction("bus",         80,      0,    0, 0, 0),
    Deduction("bike",        0,      0,    0, 0, 0),   
    Deduction("ESPP",        0,      0,    1, 1, 1),    
]

# Calculations
gross_monthly       = gross_yearly/12
gross_monthly_total = gross_monthly + sum([x.value for x in extra])

gross_monthly_paye  = gross_monthly_total - sum([
    (x.value  + (x.per * gross_monthly)) if x.is_paye==0 else 0  for x in ded
])

gross_monthly_usc   = gross_monthly_total - sum([
    (x.value  + (x.per * gross_monthly)) if x.is_usc==0 else 0  for x in ded
])

gross_monthly_prsi  = gross_monthly_total - sum([
    (x.value  + (x.per * gross_monthly)) if x.is_prsi==0 else 0  for x in ded
])

def calc(g, band):
    tax = 0
    for (v, t) in band:
        v = v if (g >= v) else (g - v)
        v = v if (v!= 0) else g # Handle special case of last range
        if v <= 0:
            break
        tax += v * t
        g = g - v
    return  tax

tax_paye =  calc(  gross_monthly_paye * 12 ,paye_tax_band )/12 - (tax_cred/12)
tax_usc = calc(  gross_monthly_usc * 12 ,usc_tax_band )/12
tax_prsi = prsi_tax_band * gross_monthly_prsi

tax  = round(tax_prsi + tax_usc + tax_paye,2) 
net = round(gross_monthly - tax - sum([ (x.value  + (x.per * gross_monthly)) for x in ded]), 2)

print(f"PAYE:{tax_paye}\nUSC:{tax_usc}\nPRSI:{tax_prsi}")
print(f"net:{net}")