From bc7b1dc0c37acd7ba17cd8cad003097c0ca7c3fd Mon Sep 17 00:00:00 2001 From: Benjamin Randolph <104036158+neb417@users.noreply.github.com> Date: Mon, 8 Jan 2024 14:35:33 -0700 Subject: [PATCH] Refactor how fed tax is calculated (#23) --- 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