class Formulas::WithholdingTax
Attributes
origin_frequency[R]
Public Class Methods
new(gross_pay, origin_frequency, tax_rate, options: {})
click to toggle source
# File lib/formulas/withholding_tax.rb, line 9 def initialize(gross_pay, origin_frequency, tax_rate, options: {}) @gross_pay = gross_pay @origin_frequency = origin_frequency @tax_rate = tax_rate @options = options end
Public Instance Methods
net_pay(request_frequency:)
click to toggle source
# File lib/formulas/withholding_tax.rb, line 16 def net_pay(request_frequency:) annual_pay_after_tax = annual_gross_pay - calculate_tax(Formulas::ANNUALLY) if respond_to?(:levy) net_pay = annual_pay_after_tax - (acc_payable * send(:levy)) end return net_pay if request_frequency.to_s == Formulas::ANNUALLY.to_s send("convert_annually_to_#{request_frequency}", net_pay).round(2) end
Protected Instance Methods
calculate_tax(request_frequency)
click to toggle source
# File lib/formulas/withholding_tax.rb, line 30 def calculate_tax(request_frequency) @request_frequency = request_frequency return annual_tax if request_frequency.to_s == Formulas::ANNUALLY.to_s send("convert_annually_to_#{request_frequency}", annual_tax).round(2) end
Private Instance Methods
annual_gross_pay()
click to toggle source
# File lib/formulas/withholding_tax.rb, line 52 def annual_gross_pay return @gross_pay if @origin_frequency.to_s == Formulas::ANNUALLY.to_s send("convert_#{@origin_frequency}_to_annually", @gross_pay) end
annual_tax()
click to toggle source
# File lib/formulas/withholding_tax.rb, line 40 def annual_tax annual_result = 0 if gross_pay_tax_index > 0 @tax_rate[0..gross_pay_tax_index].each_with_index do |current, index| l = (index == gross_pay_tax_index) ? annual_gross_pay : current[0][1] annual_result += ((l - current[0][0]) * (current[1].to_f / 100)) end end annual_result end
gross_pay_tax_index()
click to toggle source
# File lib/formulas/withholding_tax.rb, line 57 def gross_pay_tax_index @tax_rate.index do |current| (current[0][0] <= annual_gross_pay && current[0][1].nil?) || (current[0][0] <= annual_gross_pay && current[0][1] >= annual_gross_pay) end end