Sha256: 94dfcc1d2579aee67c19339547738f3deb10b445e8eccd0d6775c4bbb2914cc3
Contents?: true
Size: 1.16 KB
Versions: 2
Compression:
Stored size: 1.16 KB
Contents
require 'pry' module Train::Tax::Calculator module WithholdingTax LOOKUP_TABLE = [ { lowest: 0.00, highest: 20_833.00, base: 0.00, excess: 0.00 }, { lowest: 20_833.00, highest: 33_333.00, base: 0.00, excess: 0.20 }, { lowest: 33_333.00, highest: 66_667.00, base: 2_500.00, excess: 0.25 }, { lowest: 66_667.00, highest: 166_667.00, base: 10_833.33, excess: 0.30 }, { lowest: 166_667.00, highest: 666_667.00, base: 40_833.33, excess: 0.32 }, { lowest: 666_667.00, highest: Float::INFINITY, base: 200_833.33, excess: 0.35 }, ] def self.compute(basic_salary) taxable_income = basic_salary - Deductions.get(basic_salary) if basic_salary > 90_000 monthly_taxable = ((basic_salary - 90_000) / 12.00) taxable_income = taxable_income + monthly_taxable end tax_bracket = LOOKUP_TABLE.select do |bracket| taxable_income >= bracket[:lowest] && taxable_income < bracket[:highest] end.first withholding_tax = ((taxable_income - tax_bracket[:lowest]) * tax_bracket[:excess]) + tax_bracket[:base] withholding_tax.round(2) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
train-tax-calculator-2.2.5 | lib/train/tax/calculator/withholding_tax.rb |
train-tax-calculator-2.2.4 | lib/train/tax/calculator/withholding_tax.rb |