singapore_cpf_calculator 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (163) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +22 -0
  3. data/.rspec +2 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +97 -0
  7. data/Rakefile +2 -0
  8. data/circle.yml +3 -0
  9. data/lib/singapore_cpf_calculator.rb +125 -0
  10. data/lib/singapore_cpf_calculator/age_group.rb +71 -0
  11. data/lib/singapore_cpf_calculator/base_calculator.rb +114 -0
  12. data/lib/singapore_cpf_calculator/before_spr.rb +36 -0
  13. data/lib/singapore_cpf_calculator/citizen_or_spr_3_common.rb +27 -0
  14. data/lib/singapore_cpf_calculator/cpf_contribution.rb +28 -0
  15. data/lib/singapore_cpf_calculator/null_contribution_calculator.rb +17 -0
  16. data/lib/singapore_cpf_calculator/requirements.rb +10 -0
  17. data/lib/singapore_cpf_calculator/requirements/group_50_years_and_below.rb +13 -0
  18. data/lib/singapore_cpf_calculator/requirements/group_above_50_to_55_years.rb +13 -0
  19. data/lib/singapore_cpf_calculator/requirements/group_above_55_to_60_years.rb +13 -0
  20. data/lib/singapore_cpf_calculator/requirements/group_above_60_to_65_years.rb +13 -0
  21. data/lib/singapore_cpf_calculator/requirements/group_above_65_years.rb +13 -0
  22. data/lib/singapore_cpf_calculator/residency_module_common.rb +12 -0
  23. data/lib/singapore_cpf_calculator/spr_1_fg_common.rb +26 -0
  24. data/lib/singapore_cpf_calculator/spr_1_gg_common.rb +26 -0
  25. data/lib/singapore_cpf_calculator/spr_2_fg_common.rb +26 -0
  26. data/lib/singapore_cpf_calculator/spr_2_gg_common.rb +26 -0
  27. data/lib/singapore_cpf_calculator/spr_status.rb +52 -0
  28. data/lib/singapore_cpf_calculator/version.rb +3 -0
  29. data/lib/singapore_cpf_calculator/year_2014.rb +37 -0
  30. data/lib/singapore_cpf_calculator/year_2014/base.rb +17 -0
  31. data/lib/singapore_cpf_calculator/year_2014/citizen_or_spr_3.rb +35 -0
  32. data/lib/singapore_cpf_calculator/year_2014/citizen_or_spr_3/age_50_below_contribution_calculator.rb +32 -0
  33. data/lib/singapore_cpf_calculator/year_2014/citizen_or_spr_3/age_50_to_55_contribution_calculator.rb +33 -0
  34. data/lib/singapore_cpf_calculator/year_2014/citizen_or_spr_3/age_55_to_60_contribution_calculator.rb +32 -0
  35. data/lib/singapore_cpf_calculator/year_2014/citizen_or_spr_3/age_60_to_65_contribution_calculator.rb +32 -0
  36. data/lib/singapore_cpf_calculator/year_2014/citizen_or_spr_3/age_65_up_contribution_calculator.rb +32 -0
  37. data/lib/singapore_cpf_calculator/year_2014/spr_1_fg.rb +36 -0
  38. data/lib/singapore_cpf_calculator/year_2014/spr_1_fg/age_50_below_contribution_calculator.rb +33 -0
  39. data/lib/singapore_cpf_calculator/year_2014/spr_1_fg/age_50_to_55_contribution_calculator.rb +32 -0
  40. data/lib/singapore_cpf_calculator/year_2014/spr_1_fg/age_55_to_60_contribution_calculator.rb +32 -0
  41. data/lib/singapore_cpf_calculator/year_2014/spr_1_fg/age_60_to_65_contribution_calculator.rb +32 -0
  42. data/lib/singapore_cpf_calculator/year_2014/spr_1_fg/age_65_up_contribution_calculator.rb +32 -0
  43. data/lib/singapore_cpf_calculator/year_2014/spr_1_gg.rb +36 -0
  44. data/lib/singapore_cpf_calculator/year_2014/spr_1_gg/age_50_below_contribution_calculator.rb +32 -0
  45. data/lib/singapore_cpf_calculator/year_2014/spr_1_gg/age_50_to_55_contribution_calculator.rb +14 -0
  46. data/lib/singapore_cpf_calculator/year_2014/spr_1_gg/age_55_to_60_contribution_calculator.rb +14 -0
  47. data/lib/singapore_cpf_calculator/year_2014/spr_1_gg/age_60_to_65_contribution_calculator.rb +32 -0
  48. data/lib/singapore_cpf_calculator/year_2014/spr_1_gg/age_65_up_contribution_calculator.rb +32 -0
  49. data/lib/singapore_cpf_calculator/year_2014/spr_2_fg.rb +36 -0
  50. data/lib/singapore_cpf_calculator/year_2014/spr_2_fg/age_50_below_contribution_calculator.rb +32 -0
  51. data/lib/singapore_cpf_calculator/year_2014/spr_2_fg/age_50_to_55_contribution_calculator.rb +32 -0
  52. data/lib/singapore_cpf_calculator/year_2014/spr_2_fg/age_55_to_60_contribution_calculator.rb +32 -0
  53. data/lib/singapore_cpf_calculator/year_2014/spr_2_fg/age_60_to_65_contribution_calculator.rb +32 -0
  54. data/lib/singapore_cpf_calculator/year_2014/spr_2_fg/age_65_up_contribution_calculator.rb +32 -0
  55. data/lib/singapore_cpf_calculator/year_2014/spr_2_gg.rb +36 -0
  56. data/lib/singapore_cpf_calculator/year_2014/spr_2_gg/age_50_below_contribution_calculator.rb +32 -0
  57. data/lib/singapore_cpf_calculator/year_2014/spr_2_gg/age_50_to_55_contribution_calculator.rb +14 -0
  58. data/lib/singapore_cpf_calculator/year_2014/spr_2_gg/age_55_to_60_contribution_calculator.rb +32 -0
  59. data/lib/singapore_cpf_calculator/year_2014/spr_2_gg/age_60_to_65_contribution_calculator.rb +32 -0
  60. data/lib/singapore_cpf_calculator/year_2014/spr_2_gg/age_65_up_contribution_calculator.rb +32 -0
  61. data/lib/singapore_cpf_calculator/year_2015.rb +38 -0
  62. data/lib/singapore_cpf_calculator/year_2015/base.rb +17 -0
  63. data/lib/singapore_cpf_calculator/year_2015/citizen_or_spr_3.rb +35 -0
  64. data/lib/singapore_cpf_calculator/year_2015/citizen_or_spr_3/age_50_below_contribution_calculator.rb +32 -0
  65. data/lib/singapore_cpf_calculator/year_2015/citizen_or_spr_3/age_50_to_55_contribution_calculator.rb +32 -0
  66. data/lib/singapore_cpf_calculator/year_2015/citizen_or_spr_3/age_55_to_60_contribution_calculator.rb +32 -0
  67. data/lib/singapore_cpf_calculator/year_2015/citizen_or_spr_3/age_60_to_65_contribution_calculator.rb +32 -0
  68. data/lib/singapore_cpf_calculator/year_2015/citizen_or_spr_3/age_65_up_contribution_calculator.rb +32 -0
  69. data/lib/singapore_cpf_calculator/year_2015/spr_1_fg.rb +37 -0
  70. data/lib/singapore_cpf_calculator/year_2015/spr_1_fg/age_50_below_contribution_calculator.rb +32 -0
  71. data/lib/singapore_cpf_calculator/year_2015/spr_1_fg/age_50_to_55_contribution_calculator.rb +32 -0
  72. data/lib/singapore_cpf_calculator/year_2015/spr_1_fg/age_55_to_60_contribution_calculator.rb +32 -0
  73. data/lib/singapore_cpf_calculator/year_2015/spr_1_fg/age_60_to_65_contribution_calculator.rb +32 -0
  74. data/lib/singapore_cpf_calculator/year_2015/spr_1_fg/age_65_up_contribution_calculator.rb +32 -0
  75. data/lib/singapore_cpf_calculator/year_2015/spr_1_gg.rb +36 -0
  76. data/lib/singapore_cpf_calculator/year_2015/spr_1_gg/age_50_below_contribution_calculator.rb +32 -0
  77. data/lib/singapore_cpf_calculator/year_2015/spr_1_gg/age_50_to_55_contribution_calculator.rb +14 -0
  78. data/lib/singapore_cpf_calculator/year_2015/spr_1_gg/age_55_to_60_contribution_calculator.rb +14 -0
  79. data/lib/singapore_cpf_calculator/year_2015/spr_1_gg/age_60_to_65_contribution_calculator.rb +32 -0
  80. data/lib/singapore_cpf_calculator/year_2015/spr_1_gg/age_65_up_contribution_calculator.rb +14 -0
  81. data/lib/singapore_cpf_calculator/year_2015/spr_2_fg.rb +36 -0
  82. data/lib/singapore_cpf_calculator/year_2015/spr_2_fg/age_50_below_contribution_calculator.rb +32 -0
  83. data/lib/singapore_cpf_calculator/year_2015/spr_2_fg/age_50_to_55_contribution_calculator.rb +32 -0
  84. data/lib/singapore_cpf_calculator/year_2015/spr_2_fg/age_55_to_60_contribution_calculator.rb +32 -0
  85. data/lib/singapore_cpf_calculator/year_2015/spr_2_fg/age_60_to_65_contribution_calculator.rb +32 -0
  86. data/lib/singapore_cpf_calculator/year_2015/spr_2_fg/age_65_up_contribution_calculator.rb +32 -0
  87. data/lib/singapore_cpf_calculator/year_2015/spr_2_gg.rb +36 -0
  88. data/lib/singapore_cpf_calculator/year_2015/spr_2_gg/age_50_below_contribution_calculator.rb +32 -0
  89. data/lib/singapore_cpf_calculator/year_2015/spr_2_gg/age_50_to_55_contribution_calculator.rb +14 -0
  90. data/lib/singapore_cpf_calculator/year_2015/spr_2_gg/age_55_to_60_contribution_calculator.rb +32 -0
  91. data/lib/singapore_cpf_calculator/year_2015/spr_2_gg/age_60_to_65_contribution_calculator.rb +32 -0
  92. data/lib/singapore_cpf_calculator/year_2015/spr_2_gg/age_65_up_contribution_calculator.rb +32 -0
  93. data/lib/singapore_cpf_calculator/year_common.rb +29 -0
  94. data/singapore_cpf_calculator.gemspec +27 -0
  95. data/spec/acceptance/company_a.csv +1365 -0
  96. data/spec/acceptance/company_a_spec.rb +36 -0
  97. data/spec/singapore_cpf_calculator/age_group_spec.rb +65 -0
  98. data/spec/singapore_cpf_calculator/spr_status_spec.rb +48 -0
  99. data/spec/singapore_cpf_calculator/year_2014/citizen_or_spr_3/age_50_below_contribution_calculator_spec.rb +68 -0
  100. data/spec/singapore_cpf_calculator/year_2014/citizen_or_spr_3/age_50_to_55_contribution_calculator_spec.rb +68 -0
  101. data/spec/singapore_cpf_calculator/year_2014/citizen_or_spr_3/age_55_to_60_contribution_calculator_spec.rb +68 -0
  102. data/spec/singapore_cpf_calculator/year_2014/citizen_or_spr_3/age_60_to_65_contribution_calculator_spec.rb +68 -0
  103. data/spec/singapore_cpf_calculator/year_2014/citizen_or_spr_3/age_65_up_contribution_calculator_spec.rb +68 -0
  104. data/spec/singapore_cpf_calculator/year_2014/citizen_or_spr_3_spec.rb +176 -0
  105. data/spec/singapore_cpf_calculator/year_2014/spr_1_fg/age_50_below_contribution_calculator_spec.rb +73 -0
  106. data/spec/singapore_cpf_calculator/year_2014/spr_1_fg/age_50_to_55_contribution_calculator_spec.rb +73 -0
  107. data/spec/singapore_cpf_calculator/year_2014/spr_1_fg/age_55_to_60_contribution_calculator_spec.rb +73 -0
  108. data/spec/singapore_cpf_calculator/year_2014/spr_1_fg/age_60_to_65_contribution_calculator_spec.rb +73 -0
  109. data/spec/singapore_cpf_calculator/year_2014/spr_1_fg/age_65_up_contribution_calculator_spec.rb +73 -0
  110. data/spec/singapore_cpf_calculator/year_2014/spr_1_fg_spec.rb +176 -0
  111. data/spec/singapore_cpf_calculator/year_2014/spr_1_gg/age_50_below_contribution_calculator_spec.rb +73 -0
  112. data/spec/singapore_cpf_calculator/year_2014/spr_1_gg/age_50_to_55_contribution_calculator_spec.rb +73 -0
  113. data/spec/singapore_cpf_calculator/year_2014/spr_1_gg/age_55_to_60_contribution_calculator_spec.rb +73 -0
  114. data/spec/singapore_cpf_calculator/year_2014/spr_1_gg/age_60_to_65_contribution_calculator_spec.rb +73 -0
  115. data/spec/singapore_cpf_calculator/year_2014/spr_1_gg/age_65_up_contribution_calculator_spec.rb +73 -0
  116. data/spec/singapore_cpf_calculator/year_2014/spr_1_gg_spec.rb +176 -0
  117. data/spec/singapore_cpf_calculator/year_2014/spr_2_fg/age_50_below_contribution_calculator_spec.rb +73 -0
  118. data/spec/singapore_cpf_calculator/year_2014/spr_2_fg/age_50_to_55_contribution_calculator_spec.rb +73 -0
  119. data/spec/singapore_cpf_calculator/year_2014/spr_2_fg/age_55_to_60_contribution_calculator_spec.rb +73 -0
  120. data/spec/singapore_cpf_calculator/year_2014/spr_2_fg/age_60_to_65_contribution_calculator_spec.rb +73 -0
  121. data/spec/singapore_cpf_calculator/year_2014/spr_2_fg/age_65_up_contribution_calculator_spec.rb +73 -0
  122. data/spec/singapore_cpf_calculator/year_2014/spr_2_fg_spec.rb +176 -0
  123. data/spec/singapore_cpf_calculator/year_2014/spr_2_gg/age_50_below_contribution_calculator_spec.rb +73 -0
  124. data/spec/singapore_cpf_calculator/year_2014/spr_2_gg/age_50_to_55_contribution_calculator_spec.rb +73 -0
  125. data/spec/singapore_cpf_calculator/year_2014/spr_2_gg/age_55_to_60_contribution_calculator_spec.rb +73 -0
  126. data/spec/singapore_cpf_calculator/year_2014/spr_2_gg/age_60_to_65_contribution_calculator_spec.rb +73 -0
  127. data/spec/singapore_cpf_calculator/year_2014/spr_2_gg/age_65_up_contribution_calculator_spec.rb +73 -0
  128. data/spec/singapore_cpf_calculator/year_2014/spr_2_gg_spec.rb +176 -0
  129. data/spec/singapore_cpf_calculator/year_2014_spec.rb +183 -0
  130. data/spec/singapore_cpf_calculator/year_2015/citizen_or_spr_3/age_50_below_contribution_calculator_spec.rb +63 -0
  131. data/spec/singapore_cpf_calculator/year_2015/citizen_or_spr_3/age_50_to_55_contribution_calculator_spec.rb +63 -0
  132. data/spec/singapore_cpf_calculator/year_2015/citizen_or_spr_3/age_55_to_60_contribution_calculator_spec.rb +63 -0
  133. data/spec/singapore_cpf_calculator/year_2015/citizen_or_spr_3/age_60_to_65_contribution_calculator_spec.rb +63 -0
  134. data/spec/singapore_cpf_calculator/year_2015/citizen_or_spr_3/age_65_up_contribution_calculator_spec.rb +63 -0
  135. data/spec/singapore_cpf_calculator/year_2015/citizen_or_spr_3_spec.rb +176 -0
  136. data/spec/singapore_cpf_calculator/year_2015/spr_1_fg/age_50_below_contribution_calculator_spec.rb +63 -0
  137. data/spec/singapore_cpf_calculator/year_2015/spr_1_fg/age_50_to_55_contribution_calculator_spec.rb +63 -0
  138. data/spec/singapore_cpf_calculator/year_2015/spr_1_fg/age_55_to_60_contribution_calculator_spec.rb +63 -0
  139. data/spec/singapore_cpf_calculator/year_2015/spr_1_fg/age_60_to_65_contribution_calculator_spec.rb +63 -0
  140. data/spec/singapore_cpf_calculator/year_2015/spr_1_fg/age_65_up_contribution_calculator_spec.rb +63 -0
  141. data/spec/singapore_cpf_calculator/year_2015/spr_1_fg_spec.rb +176 -0
  142. data/spec/singapore_cpf_calculator/year_2015/spr_1_gg/age_50_below_contribution_calculator_spec.rb +63 -0
  143. data/spec/singapore_cpf_calculator/year_2015/spr_1_gg/age_50_to_55_contribution_calculator_spec.rb +63 -0
  144. data/spec/singapore_cpf_calculator/year_2015/spr_1_gg/age_55_to_60_contribution_calculator_spec.rb +63 -0
  145. data/spec/singapore_cpf_calculator/year_2015/spr_1_gg/age_60_to_65_contribution_calculator_spec.rb +63 -0
  146. data/spec/singapore_cpf_calculator/year_2015/spr_1_gg/age_65_up_contribution_calculator_spec.rb +63 -0
  147. data/spec/singapore_cpf_calculator/year_2015/spr_1_gg_spec.rb +176 -0
  148. data/spec/singapore_cpf_calculator/year_2015/spr_2_fg/age_50_below_contribution_calculator_spec.rb +63 -0
  149. data/spec/singapore_cpf_calculator/year_2015/spr_2_fg/age_50_to_55_contribution_calculator_spec.rb +63 -0
  150. data/spec/singapore_cpf_calculator/year_2015/spr_2_fg/age_55_to_60_contribution_calculator_spec.rb +63 -0
  151. data/spec/singapore_cpf_calculator/year_2015/spr_2_fg/age_60_to_65_contribution_calculator_spec.rb +63 -0
  152. data/spec/singapore_cpf_calculator/year_2015/spr_2_fg/age_65_up_contribution_calculator_spec.rb +63 -0
  153. data/spec/singapore_cpf_calculator/year_2015/spr_2_fg_spec.rb +176 -0
  154. data/spec/singapore_cpf_calculator/year_2015/spr_2_gg/age_50_below_contribution_calculator_spec.rb +63 -0
  155. data/spec/singapore_cpf_calculator/year_2015/spr_2_gg/age_50_to_55_contribution_calculator_spec.rb +63 -0
  156. data/spec/singapore_cpf_calculator/year_2015/spr_2_gg/age_55_to_60_contribution_calculator_spec.rb +63 -0
  157. data/spec/singapore_cpf_calculator/year_2015/spr_2_gg/age_60_to_65_contribution_calculator_spec.rb +63 -0
  158. data/spec/singapore_cpf_calculator/year_2015/spr_2_gg/age_65_up_contribution_calculator_spec.rb +63 -0
  159. data/spec/singapore_cpf_calculator/year_2015/spr_2_gg_spec.rb +176 -0
  160. data/spec/singapore_cpf_calculator/year_2015_spec.rb +187 -0
  161. data/spec/singapore_cpf_calculator_spec.rb +48 -0
  162. data/spec/spec_helper.rb +115 -0
  163. metadata +344 -0
@@ -0,0 +1,36 @@
1
+ require_relative "null_contribution_calculator"
2
+
3
+ module SingaporeCPFCalculator
4
+
5
+ # Residency module for Singaporean Permanent Residents before theirs status effectivity.
6
+ module BeforeSPR
7
+
8
+ class << self
9
+
10
+ # @param [String] status: ["citizen", "permanent_resident", "foreigner"]
11
+ # @param [Date] current_date: current date used to determine permanent residency's duration
12
+ # @param [Date] spr_start_date: date when the permanent residency started
13
+ # @return [true, false]
14
+ def applies_to?(
15
+ status:,
16
+ current_date:,
17
+ spr_start_date:,
18
+ **
19
+ )
20
+ status == "permanent_resident" && (
21
+ spr_start_date.year > current_date.year ||
22
+ (spr_start_date.year == current_date.year && spr_start_date.month > current_date.month)
23
+ )
24
+ end
25
+
26
+ # @param [Object] current_date
27
+ # @param [Object] birthdate
28
+ # @return [#calculator] returns the CPF calculator that matches the age.
29
+ def calculator_for(current_date, birthdate:)
30
+ NullContributionCalculator
31
+ end
32
+
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,27 @@
1
+ module SingaporeCPFCalculator
2
+ # Contains the calculators that are used for determining CPF contribution for 2014.
3
+ module CitizenOrSPR3Common
4
+
5
+ # @param [String] status: ["citizen", "permanent_resident", "foreigner"]
6
+ # @param [Date] current_date: current date used to determine permanent residency's duration
7
+ # @param [Date] spr_start_date: date when the permanent residency started
8
+ # @param [String] employee_contribution_type: ["full", "graduated"]
9
+ # @param [String] employer_contribution_type: ["full", "graduated"]
10
+ # @return [true, false]
11
+ def applies_to?(
12
+ status:,
13
+ current_date:,
14
+ spr_start_date:,
15
+ employee_contribution_type:,
16
+ employer_contribution_type:
17
+ )
18
+ status == "citizen" || (
19
+ status == "permanent_resident" && (
20
+ SPRStatus.get(current_date, status_start_date: spr_start_date) == :SPR3 ||
21
+ (employee_contribution_type == "full" && employer_contribution_type == "full")
22
+ )
23
+ )
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,28 @@
1
+ module SingaporeCPFCalculator
2
+
3
+ # Result object that describes the total, employee, and employer contribution.
4
+ class CPFContribution
5
+
6
+ # @return [BigDecimal]
7
+ attr_reader :total, :employee
8
+
9
+ # @param [BigDecimal] total the total contribution amount
10
+ # @param [BigDecimal] employee the employee contribution amount
11
+ def initialize(total:, employee:)
12
+ @total = total
13
+ @employee = employee
14
+ end
15
+
16
+ # @return [BigDecimal] difference between the total and employee contributions
17
+ def employer
18
+ @employer ||= total - employee
19
+ end
20
+
21
+ # @param [CPFContribution] other
22
+ # @return [TrueClass, FalseClass]
23
+ def ==(other)
24
+ total == other.total && employee == other.employee
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,17 @@
1
+ module SingaporeCPFCalculator
2
+
3
+ # Null CPF calculators.
4
+ module NullContributionCalculator
5
+
6
+ class << self
7
+
8
+ # returns zero value
9
+ def calculate(*)
10
+ CPFContribution.new total: BigDecimal.new("0.0"),
11
+ employee: BigDecimal.new("0.0")
12
+ end
13
+
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,10 @@
1
+ module SingaporeCPFCalculator
2
+ module Requirements
3
+ end
4
+ end
5
+
6
+ require_relative "requirements/group_50_years_and_below"
7
+ require_relative "requirements/group_above_50_to_55_years"
8
+ require_relative "requirements/group_above_55_to_60_years"
9
+ require_relative "requirements/group_above_60_to_65_years"
10
+ require_relative "requirements/group_above_65_years"
@@ -0,0 +1,13 @@
1
+ module SingaporeCPFCalculator
2
+ module Requirements
3
+ module Group50YearsAndBelow
4
+
5
+ private
6
+
7
+ def required_age_group
8
+ :group_50_years_and_below
9
+ end
10
+
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module SingaporeCPFCalculator
2
+ module Requirements
3
+ module GroupAbove50To55Years
4
+
5
+ private
6
+
7
+ def required_age_group
8
+ :group_above_50_to_55_years
9
+ end
10
+
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module SingaporeCPFCalculator
2
+ module Requirements
3
+ module GroupAbove55To60Years
4
+
5
+ private
6
+
7
+ def required_age_group
8
+ :group_above_55_to_60_years
9
+ end
10
+
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module SingaporeCPFCalculator
2
+ module Requirements
3
+ module GroupAbove60To65Years
4
+
5
+ private
6
+
7
+ def required_age_group
8
+ :group_above_60_to_65_years
9
+ end
10
+
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module SingaporeCPFCalculator
2
+ module Requirements
3
+ module GroupAbove65Years
4
+
5
+ private
6
+
7
+ def required_age_group
8
+ :group_above_65_years
9
+ end
10
+
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+ module SingaporeCPFCalculator
2
+ module ResidencyModuleCommon
3
+
4
+ # @param [Date] date current date to which the age is calculated
5
+ # @param [Date] birthdate
6
+ # @return [#calculator] returns the CPF calculator that matches the age.
7
+ def calculator_for(date, birthdate:)
8
+ calculators.find { |calculator| calculator.applies_to? date, birthdate: birthdate }
9
+ end
10
+
11
+ end
12
+ end
@@ -0,0 +1,26 @@
1
+
2
+ module SingaporeCPFCalculator
3
+ # Contains the calculators that are used for determining CPF contribution for 2014.
4
+ module SPR1FGCommon
5
+
6
+ # @param [String] status: ["citizen", "permanent_resident", "foreigner"]
7
+ # @param [Date] current_date: current date used to determine permanent residency's duration
8
+ # @param [Date] spr_start_date: date when the permanent residency started
9
+ # @param [String] employee_contribution_type: ["full", "graduated"]
10
+ # @param [String] employer_contribution_type: ["full", "graduated"]
11
+ # @return [true, false]
12
+ def applies_to?(
13
+ status:,
14
+ current_date:,
15
+ spr_start_date:,
16
+ employee_contribution_type:,
17
+ employer_contribution_type:
18
+ )
19
+ status == "permanent_resident" &&
20
+ SPRStatus.get(current_date, status_start_date: spr_start_date) == :SPR1 &&
21
+ employee_contribution_type == "graduated" &&
22
+ employer_contribution_type == "full"
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+
2
+ module SingaporeCPFCalculator
3
+ # Contains the calculators that are used for determining CPF contribution for 2014.
4
+ module SPR1GGCommon
5
+
6
+ # @param [String] status: ["citizen", "permanent_resident", "foreigner"]
7
+ # @param [Date] current_date: current date used to determine permanent residency's duration
8
+ # @param [Date] spr_start_date: date when the permanent residency started
9
+ # @param [String] employee_contribution_type: ["full", "graduated"]
10
+ # @param [String] employer_contribution_type: ["full", "graduated"]
11
+ # @return [true, false]
12
+ def applies_to?(
13
+ status:,
14
+ current_date:,
15
+ spr_start_date:,
16
+ employee_contribution_type:,
17
+ employer_contribution_type:
18
+ )
19
+ status == "permanent_resident" &&
20
+ SPRStatus.get(current_date, status_start_date: spr_start_date) == :SPR1 &&
21
+ employee_contribution_type == "graduated" &&
22
+ employer_contribution_type == "graduated"
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+
2
+ module SingaporeCPFCalculator
3
+ # Contains the calculators that are used for determining CPF contribution for 2014.
4
+ module SPR2FGCommon
5
+
6
+ # @param [String] status: ["citizen", "permanent_resident", "foreigner"]
7
+ # @param [Date] current_date: current date used to determine permanent residency's duration
8
+ # @param [Date] spr_start_date: date when the permanent residency started
9
+ # @param [String] employee_contribution_type: ["full", "graduated"]
10
+ # @param [String] employer_contribution_type: ["full", "graduated"]
11
+ # @return [true, false]
12
+ def applies_to?(
13
+ status:,
14
+ current_date:,
15
+ spr_start_date:,
16
+ employee_contribution_type:,
17
+ employer_contribution_type:
18
+ )
19
+ status == "permanent_resident" &&
20
+ SPRStatus.get(current_date, status_start_date: spr_start_date) == :SPR2 &&
21
+ employee_contribution_type == "graduated" &&
22
+ employer_contribution_type == "full"
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+
2
+ module SingaporeCPFCalculator
3
+ # Contains the calculators that are used for determining CPF contribution for 2014.
4
+ module SPR2GGCommon
5
+
6
+ # @param [String] status: ["citizen", "permanent_resident", "foreigner"]
7
+ # @param [Date] current_date: current date used to determine permanent residency's duration
8
+ # @param [Date] spr_start_date: date when the permanent residency started
9
+ # @param [String] employee_contribution_type: ["full", "graduated"]
10
+ # @param [String] employer_contribution_type: ["full", "graduated"]
11
+ # @return [true, false]
12
+ def applies_to?(
13
+ status:,
14
+ current_date:,
15
+ spr_start_date:,
16
+ employee_contribution_type:,
17
+ employer_contribution_type:
18
+ )
19
+ status == "permanent_resident" &&
20
+ SPRStatus.get(current_date, status_start_date: spr_start_date) == :SPR2 &&
21
+ employee_contribution_type == "graduated" &&
22
+ employer_contribution_type == "graduated"
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,52 @@
1
+ module SingaporeCPFCalculator
2
+
3
+ class SPRStatus
4
+
5
+ class << self
6
+ def get(current_date, status_start_date:)
7
+ new(current_date, status_start_date: status_start_date).get
8
+ end
9
+ end
10
+
11
+ def initialize(current_date, status_start_date:)
12
+ @current_date = current_date
13
+ @status_start_date = status_start_date
14
+ end
15
+
16
+ def get
17
+ case
18
+ when spr1_start <= current_date && current_date <= spr1_end then :SPR1
19
+ when spr2_start <= current_date && current_date <= spr2_end then :SPR2
20
+ when spr3_start <= current_date then :SPR3
21
+ else
22
+ nil # could not be determined
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ attr_reader :current_date, :status_start_date
29
+
30
+ def spr1_start
31
+ status_start_date
32
+ end
33
+
34
+ def spr1_end
35
+ @spr1_end ||= (spr1_start.beginning_of_month.advance years: 1).end_of_month
36
+ end
37
+
38
+ def spr2_start
39
+ @spr2_start ||= spr1_end.beginning_of_month.advance months: 1
40
+ end
41
+
42
+ def spr2_end
43
+ @spr2_end ||= spr2_start.dup.advance(months: 11).end_of_month
44
+ end
45
+
46
+ def spr3_start
47
+ spr2_end.beginning_of_month.advance(months: 1)
48
+ end
49
+
50
+ end
51
+
52
+ end
@@ -0,0 +1,3 @@
1
+ module SingaporeCPFCalculator
2
+ VERSION = "1.1.1"
3
+ end
@@ -0,0 +1,37 @@
1
+ require_relative "year_2014/base"
2
+ require_relative "year_2014/citizen_or_spr_3"
3
+ require_relative "year_2014/spr_2_gg"
4
+ require_relative "year_2014/spr_2_fg"
5
+ require_relative "year_2014/spr_1_gg"
6
+ require_relative "year_2014/spr_1_fg"
7
+
8
+ module SingaporeCPFCalculator
9
+ # Contains the calculators that are used for determining CPF contribution for 2014.
10
+ module Year2014
11
+
12
+ class << self
13
+
14
+ include YearCommon
15
+
16
+ # @param [Date] date when the CPF contribution is to be calculated for.
17
+ # @return [true, false] true when the date's year is 2014
18
+ def applies_to?(date)
19
+ date.year == 2014
20
+ end
21
+
22
+ private
23
+
24
+ def residency_modules
25
+ [
26
+ CitizenOrSPR3,
27
+ SPR2GG,
28
+ SPR2FG,
29
+ SPR1GG,
30
+ SPR1FG,
31
+ BeforeSPR,
32
+ ]
33
+ end
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,17 @@
1
+ module SingaporeCPFCalculator
2
+ module Year2014
3
+
4
+ # Base class for 2014 CPF calculators.
5
+ class Base < BaseCalculator
6
+
7
+ private
8
+
9
+ def capped_ordinary_wages
10
+ [d("5_000"), ordinary_wages].min
11
+ end
12
+
13
+ end
14
+
15
+ end
16
+
17
+ end