From a09953cc06c2bfc0c91023a845383de8a1b2730a Mon Sep 17 00:00:00 2001 From: Benjamin Randolph Date: Mon, 8 Jan 2024 14:34:02 -0700 Subject: [PATCH] Refactor how fed tax is calculated --- app/services/income_tax_calculator_service.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/services/income_tax_calculator_service.rb b/app/services/income_tax_calculator_service.rb index e98be81..a3fe483 100644 --- a/app/services/income_tax_calculator_service.rb +++ b/app/services/income_tax_calculator_service.rb @@ -31,7 +31,8 @@ def initialize(income:) def calculate_fed_tax bracket = FederalTaxBracket.where("bottom_range_cents <= ?", @annual_income.cents).order(:bottom_range_cents).last - rated = bracket.rate * @annual_income + taxable_at_bracket_rate = Money.new(@annual_income.cents - bracket.bottom_range_cents) + rated = bracket.rate * taxable_at_bracket_rate rated + bracket.cumulative end