Created
August 20, 2014 12:19
-
-
Save lnaia/93b6f00f1d03ba32435c to your computer and use it in GitHub Desktop.
Calculate irish net income
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=begin | |
Tax Income | |
20% up to 32,800€ | |
41% above 32,800€ | |
Universal Social Charge (USC) | |
2% first 10,036€ | |
4% next 5,980€ | |
7% on balance | |
Pay Related Social Insurance (PRSI) | |
4% Class A1 | |
=end | |
require "csv" | |
require "awesome_print" | |
def calculate_income_tax(income) | |
tax_break_point = 32800 | |
lower_rate = tax_break_point*0.2 | |
high_rate = (income - tax_break_point) * 0.41 | |
tax_credits = 3300 | |
net_tax = lower_rate + high_rate - tax_credits | |
end | |
def calculate_prsi(income) | |
income * 0.04 | |
end | |
def calculate_usc(income) | |
breaking_point_1 = 10036 | |
breaking_point_2 = 5980 | |
first = breaking_point_1 * 0.02 | |
second = breaking_point_2 * 0.04 | |
third = first + second + (income - breaking_point_1 - breaking_point_2) * 0.07 | |
end | |
def calculate_net_income(income) | |
income_tax = calculate_income_tax(income) | |
prsi = calculate_prsi(income) | |
usc = calculate_usc(income) | |
net_income = income - (income_tax + prsi + usc) | |
tax = { | |
:income_tax => income_tax, | |
:prsi => prsi, | |
:usc => usc, | |
:annual_net_income => net_income, | |
:monthly_net_income => (net_income / 12).round(2) | |
} | |
end | |
increase_vs_last = 0 | |
total_increase_vs_first = 0 | |
start_income = 40000 | |
end_income = 55000 | |
start_monthly_income = calculate_net_income(start_income)[:monthly_net_income] | |
last_monthly_income = start_monthly_income | |
results = [] | |
(start_income..end_income).step(500).to_a.each do |value| | |
net = calculate_net_income(value) | |
pension = (0.05 * value / 12).round(2) | |
increase_vs_last = net[:monthly_net_income] - last_monthly_income | |
increase_vs_first = net[:monthly_net_income] - start_monthly_income | |
last_monthly_income = net[:monthly_net_income] | |
results.push( | |
{ | |
:gross_income => value, | |
:income_tax => net[:income_tax], | |
:prsi => net[:prsi], | |
:usc => net[:usc], | |
:monthly_net_income => net[:monthly_net_income], | |
:monthly_pension => pension, | |
:monthly_net_income_after_pension => net[:monthly_net_income] - pension, | |
:increase_vs_last => increase_vs_last, | |
:increase_vs_first => increase_vs_first | |
} | |
) | |
end | |
CSV.open("data.csv", "wb") do |csv| | |
csv << results[0].keys | |
results.each do |hash| | |
csv << hash.values | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment