lib/train/tax/calculator.rb in train-tax-calculator-2.0.2 vs lib/train/tax/calculator.rb in train-tax-calculator-2.1.0
- old
+ new
@@ -1,23 +1,24 @@
require "train/tax/calculator/version"
require "train/tax/calculator/philhealth"
require "train/tax/calculator/pagibig"
require "train/tax/calculator/sss"
+require "train/tax/calculator/deductions"
module Train
module Tax
module Calculator
def self.call(basic_salary)
hash = Hash.new
- hash[:sss] = for_sss_es(basic_salary)
- hash[:philhealth] = for_philhealth(basic_salary)
- hash[:pagibig] = for_pagibig(basic_salary)
- hash[:total_deductions] = hash[:sss] + hash[:philhealth] + hash[:pagibig]
- hash[:withholding_tax] = withholding_tax(basic_salary)
- hash[:net_income] = basic_salary - hash[:withholding_tax]
+ hash[:sss] = Sss.compute_employee_share(basic_salary)
+ hash[:pagibig] = Pagibig.compute(basic_salary)
+ hash[:philhealth] = Philhealth.compute(basic_salary)
+ hash[:total_deductions] = Deductions.get(basic_salary)
+ hash[:withholding_tax] = withholding_tax(hash[:total_deductions], basic_salary)
+ hash[:net_income] = basic_salary - hash[:withholding_tax]
hash
end
private
@@ -28,14 +29,12 @@
LOW_BRACKET = 33_333.00
LOWEST_BRACKET = 20_833.00
class << self
- def withholding_tax(basic_salary)
- deductions = for_philhealth(basic_salary) + for_pagibig(basic_salary) + for_sss_es(basic_salary)
+ def withholding_tax(deductions, basic_salary)
taxable_income = basic_salary - deductions
-
compute_withholding_for(taxable_income).round(2)
end
def compute_withholding_for(income)
if income >= HIGHEST_BRACKET
@@ -63,29 +62,9 @@
0.00
end
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
-
end
end
end