Class: SingaporeCPFCalculator::BaseCalculator

Inherits:
Object
  • Object
show all
Defined in:
lib/singapore_cpf_calculator/base_calculator.rb

Overview

Base class for CPF calculators.

Direct Known Subclasses

Year2014::Base, Year2015::Base, Year2016::Base

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ordinary_wages:, additional_wages:, ytd_additional_wages: 0.0, ytd_ow_subject_to_cpf: 0.0, estimated_yearly_ow: 0.0) ⇒ BaseCalculator

Returns a new instance of BaseCalculator.



38
39
40
41
42
43
44
45
46
# File 'lib/singapore_cpf_calculator/base_calculator.rb', line 38

def initialize(ordinary_wages:, additional_wages:, ytd_additional_wages: 0.0, ytd_ow_subject_to_cpf: 0.0,
               estimated_yearly_ow: 0.0)
  @ordinary_wages = ordinary_wages
  @ytd_ow_subject_to_cpf = ytd_ow_subject_to_cpf
  @ytd_additional_wages = ytd_additional_wages
  @estimated_yearly_ow = estimated_yearly_ow
  @additional_wages = additional_wages
  clip_additional_wages_based_on_ceiling()
end

Class Method Details

.applies_to?(date, birthdate:) ⇒ true, false

Returns true if the calculator applies to the employee’s age.

Parameters:

  • age (Fixnum)

Returns:

  • (true, false)

    returns true if the calculator applies to the employee’s age.



8
9
10
# File 'lib/singapore_cpf_calculator/base_calculator.rb', line 8

def applies_to?(date, birthdate:)
  AgeGroup.get(date, birthdate: birthdate) == required_age_group
end

.calculate(ordinary_wages:, additional_wages:, ytd_additional_wages: 0.0, ytd_ow_subject_to_cpf: 0.0, estimated_yearly_ow: 0.0) ⇒ Hash

Returns the total, employee, employer amounts for the CPF contribution

Parameters:

  • ordinary_wages: (BigDecimal)

    Ordinary wages are wages due or granted in respect of employment and include allowances (e.g. food allowance and overtime payments) earned by an employee in the month and payable before the due date for payment of CPF contributions for that month.

  • additional_wages: (BigDecimal)

    Additional wages are wage supplements which are not granted wholly and exclusively for the month, such as annual bonus and leave pay. These and other incentive payments may be made at intervals of more than a month.

  • ytd_additional_wages (BigDecimal) (defaults to: 0.0)

    The year to date additional wages

  • ytd_ow_subject_to_cpf (BigDecimal) (defaults to: 0.0)

    The year to date ordinary wages

Returns:

  • (Hash)

    returns the total, employee, employer amounts for the CPF contribution



24
25
26
27
28
29
# File 'lib/singapore_cpf_calculator/base_calculator.rb', line 24

def calculate(ordinary_wages:, additional_wages:, ytd_additional_wages: 0.0, ytd_ow_subject_to_cpf: 0.0,
              estimated_yearly_ow: 0.0)
  new(ordinary_wages: ordinary_wages, additional_wages: additional_wages,
      ytd_ow_subject_to_cpf: ytd_ow_subject_to_cpf, ytd_additional_wages: ytd_additional_wages,
      estimated_yearly_ow: estimated_yearly_ow).calculate
end

Instance Method Details

#calculateHash

Returns the total, employee, employer amounts for the CPF contribution

Returns:

  • (Hash)

    returns the total, employee, employer amounts for the CPF contribution



49
50
51
52
53
54
# File 'lib/singapore_cpf_calculator/base_calculator.rb', line 49

def calculate
  CPFContribution.new total: total_contribution,
                      employee: employee_contribution,
                      aw_subject_to_cpf: additional_wages,
                      ow_subject_to_cpf: capped_ordinary_wages
end