Skip to content

Instantly share code, notes, and snippets.

@swombat
Created December 10, 2024 10:00
Show Gist options
  • Save swombat/3beff70925f06a1aded6c00f8154138d to your computer and use it in GitHub Desktop.
Save swombat/3beff70925f06a1aded6c00f8154138d to your computer and use it in GitHub Desktop.
UK Corporation Tax Calculator
class CorporationTax
def self.calculate_ct(profit, period_start_on, period_end_on)
if period_end_on < Date.new(2023, 4, 1)
calculate_ct_before_2023(profit)
elsif period_start_on >= Date.new(2023, 4, 1)
calculate_ct_after_2023(profit)
else
period_split = split_periods(period_start_on, period_end_on)
period_1_profit = profit * period_split[0] / (period_split[0] + period_split[1])
period_2_profit = profit * period_split[1] / (period_split[0] + period_split[1])
calculate_ct_before_2023(period_1_profit) + calculate_ct_after_2023(period_2_profit, period_split[1])
end
end
def self.calculate_ct_after_2023(profit, days=366.0)
lower_limit = 50_000
upper_limit = 250_000
main_rate = 0.25
small_profits_rate = 0.19
marginal_relief_fraction = 3.0 / 200
if profit <= lower_limit
tax = profit * small_profits_rate
elsif profit > upper_limit
tax = profit * main_rate
else
adjusted_upper_limit = upper_limit * days / 366.0
marginal_relief = (adjusted_upper_limit - profit) * marginal_relief_fraction
tax = (profit * main_rate) - marginal_relief
end
tax
end
def self.calculate_ct_before_2023(profit)
tax = profit * 0.19
tax
end
def self.split_periods(period_start_on, period_end_on)
[Date.new(2023, 3, 31) - period_start_on + 1, period_end_on - Date.new(2023, 4, 1) + 1.0]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment