class WithholdingTaxCalculator

Public Class Methods

new(options) click to toggle source

Calculate your Withholding Tax!

Example:

>> WithholdingTaxCalculator.new(payroll_period: "daily", compensation_level: 9000).call
=> 2469.19

Arguments

payroll_period: (string), possible values: ["daily", "monthly", "semimonthly", "monthly"]
compensation_level: (number)
# File lib/philippines_withholdingtax.rb, line 12
def initialize(options)
  @payroll_period = options[:payroll_period]
  @compensation_level = options[:compensation_level]
end

Public Instance Methods

call() click to toggle source
# File lib/philippines_withholdingtax.rb, line 17
def call
  set_period
  set_bracket
  set_minimum_tax
  set_percentage_on_excess
  calculate_excess
  calculate_tax_from_excess
  return_withholding_tax
end

Private Instance Methods

calculate_excess() click to toggle source
# File lib/philippines_withholdingtax.rb, line 62
def calculate_excess
  @excess = @compensation_level - @bracket[:compensation_level]
end
calculate_tax_from_excess() click to toggle source
# File lib/philippines_withholdingtax.rb, line 66
def calculate_tax_from_excess
  @tax_from_excess = @excess * @percentage_on_excess
end
return_withholding_tax() click to toggle source
# File lib/philippines_withholdingtax.rb, line 70
def return_withholding_tax
  @minimum_tax + @tax_from_excess
end
set_bracket() click to toggle source
# File lib/philippines_withholdingtax.rb, line 38
def set_bracket
  if @compensation_level >= @period[:bracket_6][:compensation_level]
    @bracket = @period[:bracket_6]
  elsif @compensation_level >= @period[:bracket_5][:compensation_level]
    @bracket = @period[:bracket_5]
  elsif @compensation_level >= @period[:bracket_4][:compensation_level]
    @bracket = @period[:bracket_4]
  elsif @compensation_level >= @period[:bracket_3][:compensation_level]
    @bracket = @period[:bracket_3]
  elsif @compensation_level >= @period[:bracket_2][:compensation_level]
    @bracket = @period[:bracket_2]
  elsif @compensation_level >= @period[:bracket_1][:compensation_level]
    @bracket = @period[:bracket_1]
  end
end
set_minimum_tax() click to toggle source
# File lib/philippines_withholdingtax.rb, line 54
def set_minimum_tax
  @minimum_tax = @bracket[:minimum_tax]
end
set_percentage_on_excess() click to toggle source
# File lib/philippines_withholdingtax.rb, line 58
def set_percentage_on_excess
  @percentage_on_excess = @bracket[:percentage_on_excess]
end
set_period() click to toggle source
# File lib/philippines_withholdingtax.rb, line 29
def set_period
  @period = case @payroll_period
            when "daily" then DAILY
            when "weekly" then WEEKLY
            when "semimonthly" then SEMIMONTHLY
            when "monthly" then MONTHLY
            end
end