diff --git a/app/services/federal_tax_calculator.rb b/app/services/federal_tax_calculator.rb index 4fc3eca..0ff5c4e 100644 --- a/app/services/federal_tax_calculator.rb +++ b/app/services/federal_tax_calculator.rb @@ -14,9 +14,14 @@ def call attr_accessor :income def calculate - bracket = FederalTaxBracket.where("bottom_range_cents <= ?", income.fractional).order(:bottom_range_cents).last - taxable_at_bracket_rate = Money.new(income - bracket.bottom_range) + bracket = FederalTaxBracket.where("bottom_range_cents <= ?", taxable_income.fractional).order(:bottom_range_cents).last + taxable_at_bracket_rate = Money.new(taxable_income - bracket.bottom_range) rated = bracket.rate * taxable_at_bracket_rate rated + bracket.cumulative end + + def taxable_income + # 2024 standard deduction = 13,850 + @taxable_income ||= income - Money.new(13_850_00) + end end diff --git a/spec/services/federal_tax_calculator_spec.rb b/spec/services/federal_tax_calculator_spec.rb index 0ab8377..334cd24 100644 --- a/spec/services/federal_tax_calculator_spec.rb +++ b/spec/services/federal_tax_calculator_spec.rb @@ -16,9 +16,10 @@ it "calculates federal tax" do # salary_income = $50,000 + # standard_deduction = $13,850 # tax_brackets = 10% on first $1,000, 15% from $1,001 to $100,000, 25% from $100,001 to $500,000 - expect(service.format).to eq("$7,449.85") - expect((salary_income.rate - service).format).to eq("$42,550.15") + expect(service.format).to eq("$5,372.35") + expect((salary_income.rate - service).format).to eq("$44,627.65") end end