lib/train/tax/calculator.rb in train-tax-calculator-1.0.1 vs lib/train/tax/calculator.rb in train-tax-calculator-1.1.0

- old
+ new

@@ -5,27 +5,72 @@ module Train module Tax module Calculator - def self.for_philhealth(salary_base) - Philhealth.compute(salary_base) - end + class << self - def self.for_pagibig(salary_base) - Pagibig.compute(salary_base) - end + def withholding_tax(basic_salary) + deductions = for_philhealth(basic_salary) + for_pagibig(basic_salary) + for_sss_es(basic_salary) + taxable_income = basic_salary - deductions - def self.for_sss(salary_base) - Sss.compute(salary_base) - end + compute_withholding_for(taxable_income).round(2) + end - def self.for_sss_es(salary_base) - Sss.compute_employee_share(salary_base) + def net_income(basic_salary) + basic_salary - withholding_tax(basic_salary) + end + + def for_philhealth(basic_salary) + Philhealth.compute(basic_salary) + end + + def for_pagibig(basic_salary) + Pagibig.compute(basic_salary) + end + + def for_sss(basic_salary) + Sss.compute(basic_salary) + end + + def for_sss_es(basic_salary) + Sss.compute_employee_share(basic_salary) + end + + def for_sss_er(basic_salary) + Sss.compute_employer_share(basic_salary) + end + end - def self.for_sss_er(salary_base) - Sss.compute_employer_share(salary_base) + private + + def self.compute_withholding_for(income) + if income >= 666_667.00 + + 200_833.33 + ((income - 666_667.00) * 0.35) + + elsif income >= 166_667.00 + + 40_833.33 + ((income - 166_667.00) * 0.32) + + elsif income >= 66_667.00 + + 10_833.33 + ((income - 66_667.00) * 0.30) + + elsif income >= 33_333.00 + + 2_500.00 + ((income - 33_333.00) * 0.25) + + elsif income >= 20_833.00 + + 0.00 + ((income - 20_833.00) * 0.20) + + else + + 0.00 + + end end end end end