philippines_mandatory_contributions 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d670beb98faa1de00a726c4492397bb463e6fa4f
4
+ data.tar.gz: 4e9534de620d8165b9f265f73d3e2b076330bf17
5
+ SHA512:
6
+ metadata.gz: 544de5831bc2065897fa967cc38a7e16b328d28b116051ad70d58e8cbf21ffef800779af0722ad07a0577d1024df37e798e2b203e63bb2758749aa5f9d77e288
7
+ data.tar.gz: 7953254061fbda4ce694614b1f26859cee71f104ca34d713c3b55ad0029694cf02d158775d7a970f08f01ecc16967d516c02bd42043b54b7ac035e47377804aa
@@ -0,0 +1,37 @@
1
+ module Helpers
2
+ def get_rows_from_csv(filename)
3
+ gem_root = File.expand_path("../..", __FILE__)
4
+ csv_text = File.read("#{gem_root}/lib/tables/#{filename}")
5
+ csv_headers = CSV.parse(csv_text, headers: true).headers
6
+
7
+ keys = csv_headers
8
+ csv = CSV.parse(csv_text, headers: false).map { |a| Hash[ keys.zip(a) ] }
9
+
10
+ # convert strings as floats
11
+ csv.each do |row|
12
+ row.each_pair { | k, v | row[k] = Float(v) rescue v }
13
+ end
14
+
15
+ # change last row[:max] to infinity
16
+ last_row = csv.length - 1
17
+ csv[last_row]["max"] = Float::INFINITY
18
+
19
+ # delete first row
20
+ csv.shift
21
+
22
+ csv
23
+ end
24
+
25
+ def with_excess_centavo?(a)
26
+ decimals(a) > 2
27
+ end
28
+
29
+ def decimals(a)
30
+ num = 0
31
+ while(a != a.to_i)
32
+ num += 1
33
+ a *= 10
34
+ end
35
+ num
36
+ end
37
+ end
@@ -0,0 +1,47 @@
1
+ require 'csv'
2
+ require 'helpers'
3
+
4
+ class Pagibig < MandatoryContributionCalculator
5
+ include Helpers
6
+
7
+ MAX_ALLOWABLE_COMPENSATION = 5000.freeze
8
+
9
+ def call
10
+ load_csv
11
+ reset_compensation if more_than_allowed_compensation?
12
+ set_bracket
13
+ set_employer_share
14
+ set_employee_share
15
+ return_contributions
16
+ end
17
+
18
+ private
19
+
20
+ def load_csv
21
+ @csv = get_rows_from_csv("pagibig_table.csv")
22
+ end
23
+
24
+ def set_bracket
25
+ @bracket = @csv.select { |row| row["min"] <= @compensation && row["max"] >= @compensation }.first
26
+ end
27
+
28
+ def more_than_allowed_compensation?
29
+ @compensation >= MAX_ALLOWABLE_COMPENSATION
30
+ end
31
+
32
+ def reset_compensation
33
+ @compensation = MAX_ALLOWABLE_COMPENSATION
34
+ end
35
+
36
+ def set_employee_share
37
+ @employee_share = @compensation * @bracket["employee_share"]
38
+ end
39
+
40
+ def set_employer_share
41
+ @employer_share = @compensation * @bracket["employer_share"]
42
+ end
43
+
44
+ def return_contributions
45
+ { employee_share: @employee_share, employer_share: @employer_share }
46
+ end
47
+ end
@@ -0,0 +1,67 @@
1
+ require 'csv'
2
+ require 'helpers'
3
+
4
+ class Philhealth < MandatoryContributionCalculator
5
+ include Helpers
6
+
7
+ MULTIPLIER = 0.0275.freeze
8
+
9
+ def call
10
+ load_csv
11
+ set_bracket
12
+ set_monthly_premium
13
+ set_employer_share
14
+ set_personal_share
15
+ deduct_excess_centavo_from_employer if with_excess_centavo?(@employer_share)
16
+ return_contributions
17
+ end
18
+
19
+ private
20
+
21
+ # read CSV then create array of hashes for each row
22
+ def load_csv
23
+ @csv = get_rows_from_csv("philhealth_table.csv")
24
+ end
25
+
26
+ def set_bracket
27
+ @bracket = @csv.select { |row| row["min"] <= @compensation && row["max"] >= @compensation }.first
28
+ end
29
+
30
+ def set_monthly_premium
31
+ case
32
+ when bracket_1?, bracket_3?
33
+ @monthly_premium = @bracket["monthly_premium"]
34
+ when bracket_2?
35
+ @monthly_premium = (@compensation * MULTIPLIER).round(2)
36
+ end
37
+ end
38
+
39
+ def bracket_1?
40
+ @bracket == @csv[0]
41
+ end
42
+
43
+ def bracket_2?
44
+ @bracket == @csv[1]
45
+ end
46
+
47
+ def bracket_3?
48
+ @bracket == @csv[2]
49
+ end
50
+
51
+ def set_employer_share
52
+ @employer_share = @monthly_premium / 2
53
+ end
54
+
55
+ def set_personal_share
56
+ @personal_share = @monthly_premium / 2
57
+ end
58
+
59
+ def return_contributions
60
+ { employer_share: @employer_share, personal_share: @personal_share }
61
+ end
62
+
63
+ def deduct_excess_centavo_from_employer
64
+ @employer_share += 0.005
65
+ @personal_share -= 0.005
66
+ end
67
+ end
@@ -0,0 +1,9 @@
1
+ class MandatoryContributionCalculator
2
+ def initialize(options)
3
+ @compensation = options[:compensation].round(2)
4
+ end
5
+ end
6
+
7
+ require 'pagibig_calculator'
8
+ require 'philhealth_calculator'
9
+ require 'sss_calculator'
@@ -0,0 +1,43 @@
1
+ require 'csv'
2
+ require 'helpers'
3
+
4
+ class SSS < MandatoryContributionCalculator
5
+ include Helpers
6
+
7
+ def call
8
+ load_csv
9
+ set_bracket
10
+ set_er
11
+ set_ee
12
+ set_ec
13
+ return_contributions
14
+ end
15
+
16
+ private
17
+
18
+ # read CSV then create array of hashes for each row
19
+ def load_csv
20
+ @csv = get_rows_from_csv("sss_table.csv")
21
+ end
22
+
23
+ def set_bracket
24
+ @bracket = @csv.select { |row| row["min"] <= @compensation && row["max"] >= @compensation }
25
+ @bracket = @bracket.any? ? @bracket.first : { er: 0, ee: 0, ec: 0 }
26
+ end
27
+
28
+ def set_er
29
+ @er = @bracket["er"]
30
+ end
31
+
32
+ def set_ee
33
+ @ee = @bracket["ee"]
34
+ end
35
+
36
+ def set_ec
37
+ @ec = @bracket["ec"]
38
+ end
39
+
40
+ def return_contributions
41
+ { er: @er, ee: @ee, ec: @ec}
42
+ end
43
+ end
@@ -0,0 +1,3 @@
1
+ min,max,employee_share,employer_share
2
+ 0,1500,0.01,0.02
3
+ 1500,,0.02,0.02
@@ -0,0 +1,4 @@
1
+ min,max,monthly_premium
2
+ 0,10000,275
3
+ 10000.01,39999.99,
4
+ 40000.00,,1100
@@ -0,0 +1,32 @@
1
+ min,max,er,ee,ec
2
+ 1000,1249.99,73.7,36.3,10
3
+ 1250,1749.99,110.5,54.5,10
4
+ 1750,2249.99,147.3,72.7,10
5
+ 2250,2749.99,184.2,90.8,10
6
+ 2750,3249.99,221,109,10
7
+ 3250,3749.99,257,127.2,10
8
+ 3750,4249.99,294.7,145.3,10
9
+ 4250,4749.99,331.5,163.5,10
10
+ 4750,5249.99,368.3,181.7,10
11
+ 5250,5749.99,405.2,199.8,10
12
+ 5750,6249.99,442,218,10
13
+ 6250,6749.99,47808,236.2,10
14
+ 6750,7249.99,515.7,254.3,10
15
+ 7250,7749.99,552.8,272.5,10
16
+ 7750,8249.99,589.3,290.7,10
17
+ 8250,8749.99,626.2,308.8,10
18
+ 8750,9249.99,663,327,10
19
+ 9250,9749.99,699.8,345.2,10
20
+ 9750,10249.99,736.7,363.3,10
21
+ 10250,10749.99,773.5,381.5,10
22
+ 10750,11249.99,810.3,399.7,10
23
+ 11250,11749.99,847.2,417.8,10
24
+ 11750,12249.99,884,436,10
25
+ 12250,12749.99,920.8,454.2,10
26
+ 12750,13249.99,957.7,472.3,10
27
+ 13250,13749.99,994.5,490.5,10
28
+ 13750,14249.99,1031.3,508.7,10
29
+ 14250,14749.99,1068.2,526.8,10
30
+ 14750,15249.99,1105.00,545,30
31
+ 15250,15749.99,1141.8,563.2,30
32
+ 15750,,1178.7,581.3,30
metadata ADDED
@@ -0,0 +1,51 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: philippines_mandatory_contributions
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Rei Ramos
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-09-28 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Calculate SSS, Philhealth, and Pagibig
14
+ email: reiallenramos@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/helpers.rb
20
+ - lib/pagibig_calculator.rb
21
+ - lib/philhealth_calculator.rb
22
+ - lib/philippines_mandatory_contributions.rb
23
+ - lib/sss_calculator.rb
24
+ - lib/tables/pagibig_table.csv
25
+ - lib/tables/philhealth_table.csv
26
+ - lib/tables/sss_table.csv
27
+ homepage: https://github.com/reiallenramos/philippines_mandatory_contributions
28
+ licenses:
29
+ - MIT
30
+ metadata: {}
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ requirements: []
46
+ rubyforge_project:
47
+ rubygems_version: 2.6.11
48
+ signing_key:
49
+ specification_version: 4
50
+ summary: Mandatory Government Contributions in the Philippines
51
+ test_files: []