income-tax 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 67ee8d20356685914aaf57242d7a1cb84a631043
4
- data.tar.gz: bba76a62100eb3caf7a2b4329e51d11d7ee549e4
3
+ metadata.gz: 09ed2953aba2e33c5e4ef89a4bb53a7e10211d33
4
+ data.tar.gz: a4182214a3454f3762d1d7057ae1ca313dc7f065
5
5
  SHA512:
6
- metadata.gz: 7bec96d7e3d4b1362aaeb5366af2224ccb6f4254c8ff3b20c8f6a5bb026d3d291b30102c40e369d5e8b17655e3a7a433b709951665136439267a4973fdd4ee74
7
- data.tar.gz: 00ee3d234cbbf65e9637d174d35a3f22a0eef00b5a8ca3159178885f47ba4d7b0cb0325f40dba57379e582464c386e3c2ae3ca1c6aaedebc971e4d843037c617
6
+ metadata.gz: 725d3f2b5dc1465a56f2cc77ce98f4db32a01c4b8d423afc625d1ebe06e3c5cf7b1ca0cab633318989568185346bf4e20d7673906dd2f3a5470b23522ab312af
7
+ data.tar.gz: f9fdd789b6b51324ed3b204d70ca2fa4edb73279b47d268ca65f90b89fa221755c285ba95460da464e35cf5a0e70f0e70abf72c2236a596f41212fe9aa6a48be
@@ -1,13 +1,46 @@
1
1
  module IncomeTax
2
2
  module Countries
3
- class Canada < Models::Progressive
3
+ class Canada < Models::Generic
4
4
  register "Canada", "CA", "CAN"
5
5
  currency "CAD"
6
6
 
7
- level offset(44700), "15%"
8
- level offset(44700), "22%"
9
- level offset(49185), "26%"
10
- remainder "29%"
7
+ wants_options :territory
8
+
9
+ def setup(**options)
10
+ @federal = Federal.new(**options)
11
+ @territory = TerritoryRegister[territory].new(**options) if territory?
12
+ end
13
+
14
+ def territorial_taxes
15
+ return 0 unless territory?
16
+ @territory.taxes
17
+ end
18
+
19
+ def federal_taxes
20
+ @federal.taxes
21
+ end
22
+
23
+ def calculate
24
+ @taxes = federal_taxes + territorial_taxes
25
+ end
26
+
27
+ TerritoryRegister = Register.new("territory")
28
+ Territory = Class.new(Models::Progressive) { register_on TerritoryRegister }
29
+
30
+ require 'income_tax/countries/canada/federal'
31
+ require 'income_tax/countries/canada/alberta'
32
+ require 'income_tax/countries/canada/british_columbia'
33
+ require 'income_tax/countries/canada/manitoba'
34
+ require 'income_tax/countries/canada/new_brunswick'
35
+ require 'income_tax/countries/canada/newfoundland_and_labrador'
36
+ require 'income_tax/countries/canada/northwest_territories'
37
+ require 'income_tax/countries/canada/nova_scotia'
38
+ require 'income_tax/countries/canada/nunavut'
39
+ require 'income_tax/countries/canada/ontario'
40
+ require 'income_tax/countries/canada/prince_edward_island'
41
+ require 'income_tax/countries/canada/quebec'
42
+ require 'income_tax/countries/canada/saskatchewan'
43
+ require 'income_tax/countries/canada/yukon'
11
44
  end
12
45
  end
13
46
  end
@@ -0,0 +1,15 @@
1
+ module IncomeTax
2
+ module Countries
3
+ class Canada
4
+ class Alberta < Territory
5
+ register "Alberta", "AB"
6
+
7
+ level offset(125000), "10%"
8
+ level offset(25000), "12%"
9
+ level offset(50000), "13%"
10
+ level offset(100000), "14%"
11
+ remainder "15%"
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module IncomeTax
2
+ module Countries
3
+ class Canada
4
+ class BritishColumbia < Territory
5
+ register "British Columbia", "BC"
6
+
7
+ level offset(38210), "5.06%"
8
+ level offset(38211), "7.7%"
9
+ level offset(11320), "10.5%"
10
+ level offset(18802), "12.29%"
11
+ remainder "14.7%"
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,22 @@
1
+ module IncomeTax
2
+ module Countries
3
+ class Canada
4
+ class Federal < Models::Progressive
5
+ levels year: 2015 do
6
+ level offset(44700), "15%"
7
+ level offset(44700), "22%"
8
+ level offset(49185), "26%"
9
+ remainder "29%"
10
+ end
11
+
12
+ levels year: 2016 do
13
+ level offset(45282), "15%"
14
+ level offset(45281), "22%"
15
+ level offset(49825), "26%"
16
+ level offset(59612), "29%"
17
+ remainder "33%"
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,13 @@
1
+ module IncomeTax
2
+ module Countries
3
+ class Canada
4
+ class Manitoba < Territory
5
+ register "Manitoba", "MB"
6
+
7
+ level offset(31000), "10.8%"
8
+ level offset(36000), "12.75%"
9
+ remainder "17.4%"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,16 @@
1
+ module IncomeTax
2
+ module Countries
3
+ class Canada
4
+ class NewBrunswick < Territory
5
+ register "New Brunswick", "NB"
6
+
7
+ level offset(40492), "9.68%"
8
+ level offset(40493), "14.82%"
9
+ level offset(50679), "16.52%"
10
+ level offset(18336), "17.84%"
11
+ level offset(100000), "21%"
12
+ remainder "25.75%"
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,15 @@
1
+ module IncomeTax
2
+ module Countries
3
+ class Canada
4
+ class NewfoundlandAndLabrador < Territory
5
+ register "Newfoundland and Labrador", "Newfoundland", "Labrador", "NL"
6
+
7
+ level offset(35148), "7.7%"
8
+ level offset(35147), "12.5%"
9
+ level offset(55205), "13.3%"
10
+ level offset(50200), "14.3%"
11
+ remainder "15.3%"
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ module IncomeTax
2
+ module Countries
3
+ class Canada
4
+ class NorthwestTerritories < Territory
5
+ register "Northwest Territories", "NT"
6
+
7
+ level offset(41011), "5.9%"
8
+ level offset(41013), "8.6%"
9
+ level offset(51329), "12.2%"
10
+ remainder "14.05%"
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ module IncomeTax
2
+ module Countries
3
+ class Canada
4
+ class NovaScotia < Territory
5
+ register "Nova Scotia", "NS"
6
+
7
+ level offset(29590), "8.79%"
8
+ level offset(29590), "14.95%"
9
+ level offset(33820), "16.67%"
10
+ level offset(57000), "17.5%"
11
+ remainder "21%"
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ module IncomeTax
2
+ module Countries
3
+ class Canada
4
+ class Nunavut < Territory
5
+ register "Nunavut", "NU"
6
+
7
+ level offset(43176), "4%"
8
+ level offset(43175), "7%"
9
+ level offset(54037), "9%"
10
+ remainder "11.5%"
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ module IncomeTax
2
+ module Countries
3
+ class Canada
4
+ class Ontario < Territory
5
+ register "Ontario", "ON"
6
+
7
+ level offset(41536), "5.05%"
8
+ level offset(41539), "9.15%"
9
+ level offset(66925), "11.16%"
10
+ level offset(70000), "12.16%"
11
+ remainder "13.16%"
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,13 @@
1
+ module IncomeTax
2
+ module Countries
3
+ class Canada
4
+ class PrinceEdwardIsland < Territory
5
+ register "Prince Edward Island", "PE"
6
+
7
+ level offset(31984), "9.8%"
8
+ level offset(31985), "13.8%"
9
+ remainder "16.7%"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ module IncomeTax
2
+ module Countries
3
+ class Canada
4
+ class Quebec < Territory
5
+ register "Quebec", "Québec", "QC"
6
+
7
+ level 42390, "16%"
8
+ level 84780, "20%"
9
+ level 103150, "24%"
10
+ remainder "25.75%"
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,13 @@
1
+ module IncomeTax
2
+ module Countries
3
+ class Canada
4
+ class Saskatchewan < Territory
5
+ register "Saskatchewan", "SK"
6
+
7
+ level offset(44601), "11%"
8
+ level offset(82829), "13%"
9
+ remainder "15%"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ module IncomeTax
2
+ module Countries
3
+ class Canada
4
+ class Yukon < Territory
5
+ register "Yukon", "YT"
6
+
7
+ level offset(45282), "6.4%"
8
+ level offset(45281), "9%"
9
+ level offset(49825), "10.9%"
10
+ level offset(359612), "12.8%"
11
+ remainder "15%"
12
+ end
13
+ end
14
+ end
15
+ end
@@ -104,6 +104,11 @@ module IncomeTax
104
104
  other.class == self.class and other == self
105
105
  end
106
106
 
107
+ def ==(other)
108
+ return false unless other.is_a? Numeric
109
+ super
110
+ end
111
+
107
112
  def hash
108
113
  to_s.hash ^ to_d.hash
109
114
  end
@@ -1,3 +1,3 @@
1
1
  module IncomeTax
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
data/readme.md CHANGED
@@ -68,7 +68,7 @@ There is also a [full list of countries](locations.md).
68
68
 
69
69
  #### United States
70
70
 
71
- * **Federal only:** By default only federal taxes are calculated.
71
+ * **Federal only:** By default, only federal taxes are calculated.
72
72
  * **State taxes:** Passing in the `state` option with either the full name of the state of the two letter abbreviation will also take state taxes into account.
73
73
  * **Washington, D.C.:** Use the state option as if it was a state, which by the way it should be.
74
74
  * **Guam, Puerto Rico, and other territories:** Treat them like separate countries.
@@ -80,6 +80,16 @@ IncomeTax.new("US", "100k", state: "California")
80
80
  IncomeTax.new("Guam", "100k")
81
81
  ```
82
82
 
83
+ #### Canada
84
+
85
+ * **Federal only:** By default, only federal taxes are calculated.
86
+ * **Territorial taxes:** Passing in the `territory` option with either the full name of the state of the two letter abbreviation will also take state taxes into account.
87
+
88
+ ``` ruby
89
+ IncomeTax.new("CA", "100k")
90
+ IncomeTax.new("CA", "100k", territory: "British Columbia")
91
+ ```
92
+
83
93
  #### Switzerland
84
94
 
85
95
  You can use the `canton` option with either the full canton name or the two letter abbreviation.
@@ -1,99 +1,149 @@
1
1
  describe IncomeTax::Countries::Canada do
2
- subject(:result) { described_class.new(income: income, income_type: type, tax_year: tax_year) }
2
+ subject(:result) { described_class.new(income: income, income_type: type, tax_year: tax_year, territory: territory) }
3
3
  let(:type) { :gross }
4
+ let(:territory) { nil }
4
5
 
5
- describe "from gross income of 0" do
6
- let(:tax_year) { 2015 }
7
- let(:income) { 0 }
8
- its(:rate) { should be == Rational(0, 1) }
9
- its(:gross_income) { should be == 0 }
10
- its(:net_income) { should be == 0 }
11
- its(:taxes) { should be == 0 }
12
- end
6
+ describe "tax year 2015, federal taxes only" do
7
+ describe "from gross income of 0" do
8
+ let(:tax_year) { 2015 }
9
+ let(:income) { 0 }
10
+ its(:rate) { should be == Rational(0, 1) }
11
+ its(:gross_income) { should be == 0 }
12
+ its(:net_income) { should be == 0 }
13
+ its(:taxes) { should be == 0 }
14
+ end
13
15
 
14
- describe "from gross income of 1000" do
15
- let(:tax_year) { 2015 }
16
- let(:income) { 1000 }
17
- its(:rate) { should be == Rational(3, 20) }
18
- its(:gross_income) { should be == 1000 }
19
- its(:net_income) { should be == 850 }
20
- its(:taxes) { should be == 150 }
21
- end
16
+ describe "from gross income of 1000" do
17
+ let(:tax_year) { 2015 }
18
+ let(:income) { 1000 }
19
+ its(:rate) { should be == Rational(3, 20) }
20
+ its(:gross_income) { should be == 1000 }
21
+ its(:net_income) { should be == 850 }
22
+ its(:taxes) { should be == 150 }
23
+ end
22
24
 
23
- describe "from gross income of 10000" do
24
- let(:tax_year) { 2015 }
25
- let(:income) { 10000 }
26
- its(:rate) { should be == Rational(3, 20) }
27
- its(:gross_income) { should be == 10000 }
28
- its(:net_income) { should be == 8500 }
29
- its(:taxes) { should be == 1500 }
30
- end
25
+ describe "from gross income of 10000" do
26
+ let(:tax_year) { 2015 }
27
+ let(:income) { 10000 }
28
+ its(:rate) { should be == Rational(3, 20) }
29
+ its(:gross_income) { should be == 10000 }
30
+ its(:net_income) { should be == 8500 }
31
+ its(:taxes) { should be == 1500 }
32
+ end
31
33
 
32
- describe "from gross income of 100000" do
33
- let(:tax_year) { 2015 }
34
- let(:income) { 100000 }
35
- its(:rate) { should be == Rational(82, 425) }
36
- its(:gross_income) { should be == 100000 }
37
- its(:net_income) { should be == 80705 }
38
- its(:taxes) { should be == 19295 }
39
- end
34
+ describe "from gross income of 100000" do
35
+ let(:tax_year) { 2015 }
36
+ let(:income) { 100000 }
37
+ its(:rate) { should be == Rational(82, 425) }
38
+ its(:gross_income) { should be == 100000 }
39
+ its(:net_income) { should be == 80705 }
40
+ its(:taxes) { should be == 19295 }
41
+ end
40
42
 
41
- describe "from gross income of 100000000" do
42
- let(:tax_year) { 2015 }
43
- let(:income) { 100000000 }
44
- its(:rate) { should be == Rational(109, 376) }
45
- its(:gross_income) { should be == 100000000 }
46
- its(:net_income) { should be == "71010862.55".to_d }
47
- its(:taxes) { should be == "28989137.45".to_d }
48
- end
43
+ describe "from gross income of 100000000" do
44
+ let(:tax_year) { 2015 }
45
+ let(:income) { 100000000 }
46
+ its(:rate) { should be == Rational(109, 376) }
47
+ its(:gross_income) { should be == 100000000 }
48
+ its(:net_income) { should be == "71010862.55".to_d }
49
+ its(:taxes) { should be == "28989137.45".to_d }
50
+ end
49
51
 
50
- describe "from net income of 0" do
51
- let(:type) { :net }
52
- let(:tax_year) { 2015 }
53
- let(:income) { 0 }
54
- its(:rate) { should be == Rational(0, 1) }
55
- its(:gross_income) { should be == 0 }
56
- its(:net_income) { should be == 0 }
57
- its(:taxes) { should be == 0 }
58
- end
52
+ describe "from net income of 0" do
53
+ let(:type) { :net }
54
+ let(:tax_year) { 2015 }
55
+ let(:income) { 0 }
56
+ its(:rate) { should be == Rational(0, 1) }
57
+ its(:gross_income) { should be == 0 }
58
+ its(:net_income) { should be == 0 }
59
+ its(:taxes) { should be == 0 }
60
+ end
59
61
 
60
- describe "from net income of 1000" do
61
- let(:type) { :net }
62
- let(:tax_year) { 2015 }
63
- let(:income) { 1000 }
64
- its(:rate) { should be == Rational(3, 20) }
65
- its(:gross_income) { should be == "1176.47058823529412".to_d }
66
- its(:net_income) { should be == 1000 }
67
- its(:taxes) { should be == "176.470588235294118".to_d }
68
- end
62
+ describe "from net income of 1000" do
63
+ let(:type) { :net }
64
+ let(:tax_year) { 2015 }
65
+ let(:income) { 1000 }
66
+ its(:rate) { should be == Rational(3, 20) }
67
+ its(:gross_income) { should be == "1176.470588235294118".to_d }
68
+ its(:net_income) { should be == 1000 }
69
+ its(:taxes) { should be == "176.470588235294118".to_d }
70
+ end
69
71
 
70
- describe "from net income of 10000" do
71
- let(:type) { :net }
72
- let(:tax_year) { 2015 }
73
- let(:income) { 10000 }
74
- its(:rate) { should be == Rational(3, 20) }
75
- its(:gross_income) { should be == "11764.705882352941".to_d }
76
- its(:net_income) { should be == 10000 }
77
- its(:taxes) { should be == "1764.70588235294118".to_d }
78
- end
72
+ describe "from net income of 10000" do
73
+ let(:type) { :net }
74
+ let(:tax_year) { 2015 }
75
+ let(:income) { 10000 }
76
+ its(:rate) { should be == Rational(3, 20) }
77
+ its(:gross_income) { should be == "11764.70588235294118".to_d }
78
+ its(:net_income) { should be == 10000 }
79
+ its(:taxes) { should be == "1764.70588235294118".to_d }
80
+ end
81
+
82
+ describe "from net income of 100000" do
83
+ let(:type) { :net }
84
+ let(:tax_year) { 2015 }
85
+ let(:income) { 100000 }
86
+ its(:rate) { should be == Rational(85, 411) }
87
+ its(:gross_income) { should be == "126074.3243243243243".to_d }
88
+ its(:net_income) { should be == 100000 }
89
+ its(:taxes) { should be == "26074.3243243243243".to_d }
90
+ end
79
91
 
80
- describe "from net income of 100000" do
81
- let(:type) { :net }
82
- let(:tax_year) { 2015 }
83
- let(:income) { 100000 }
84
- its(:rate) { should be == Rational(85, 411) }
85
- its(:gross_income) { should be == "126074.324324324324".to_d }
86
- its(:net_income) { should be == 100000 }
87
- its(:taxes) { should be == "26074.3243243243243".to_d }
92
+ describe "from net income of 100000000" do
93
+ let(:type) { :net }
94
+ let(:tax_year) { 2015 }
95
+ let(:income) { 100000000 }
96
+ its(:rate) { should be == Rational(69, 238) }
97
+ its(:gross_income) { should be == "140829771.056338028".to_d }
98
+ its(:net_income) { should be == 100000000 }
99
+ its(:taxes) { should be == "40829771.056338028".to_d }
100
+ end
88
101
  end
89
102
 
90
- describe "from net income of 100000000" do
91
- let(:type) { :net }
92
- let(:tax_year) { 2015 }
93
- let(:income) { 100000000 }
94
- its(:rate) { should be == Rational(69, 238) }
95
- its(:gross_income) { should be == "140829771.056338028".to_d }
96
- its(:net_income) { should be == 100000000 }
97
- its(:taxes) { should be == "40829771.056338028".to_d }
103
+ describe "tax year 2016, taxes in Labrador" do
104
+ let(:tax_year) { 2016 }
105
+ let(:territory) { "Labrador" }
106
+
107
+ describe "from gross income of 0" do
108
+ let(:income) { 0 }
109
+ its(:rate) { should be == Rational(0, 1) }
110
+ its(:gross_income) { should be == 0 }
111
+ its(:net_income) { should be == 0 }
112
+ its(:taxes) { should be == 0 }
113
+ end
114
+
115
+ describe "from gross income of 1000" do
116
+ let(:income) { 1000 }
117
+ its(:rate) { should be == Rational(37, 163) }
118
+ its(:gross_income) { should be == 1000 }
119
+ its(:net_income) { should be == 773 }
120
+ its(:taxes) { should be == 227 }
121
+ end
122
+
123
+ describe "from gross income of 100000" do
124
+ let(:income) { 100000 }
125
+ its(:rate) { should be == Rational(82, 271) }
126
+ its(:gross_income) { should be == 100000 }
127
+ its(:net_income) { should be == "69741.724".to_d }
128
+ its(:taxes) { should be == "30258.276".to_d }
129
+ end
130
+
131
+ describe "from net income of 0" do
132
+ let(:type) { :net }
133
+ let(:income) { 0 }
134
+ its(:rate) { should be == Rational(0, 1) }
135
+ its(:gross_income) { should be == 0 }
136
+ its(:net_income) { should be == 0 }
137
+ its(:taxes) { should be == 0 }
138
+ end
139
+
140
+ describe "from net income of 100000" do
141
+ let(:type) { :net }
142
+ let(:income) { 100000 }
143
+ its(:rate) { should be == Rational(137, 491) }
144
+ its(:gross_income) { should be == "138702.1216683811839".to_d }
145
+ its(:net_income) { should be == 100000 }
146
+ its(:taxes) { should be == "38702.1216683811839".to_d }
147
+ end
98
148
  end
99
149
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: income-tax
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Konstantin Haase
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-29 00:00:00.000000000 Z
11
+ date: 2016-02-05 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Estimate Income Tax for different Countries
14
14
  email: income-tax-gem@rkh.im
@@ -61,6 +61,20 @@ files:
61
61
  - lib/income_tax/countries/cambodia.rb
62
62
  - lib/income_tax/countries/cameroon.rb
63
63
  - lib/income_tax/countries/canada.rb
64
+ - lib/income_tax/countries/canada/alberta.rb
65
+ - lib/income_tax/countries/canada/british_columbia.rb
66
+ - lib/income_tax/countries/canada/federal.rb
67
+ - lib/income_tax/countries/canada/manitoba.rb
68
+ - lib/income_tax/countries/canada/new_brunswick.rb
69
+ - lib/income_tax/countries/canada/newfoundland_and_labrador.rb
70
+ - lib/income_tax/countries/canada/northwest_territories.rb
71
+ - lib/income_tax/countries/canada/nova_scotia.rb
72
+ - lib/income_tax/countries/canada/nunavut.rb
73
+ - lib/income_tax/countries/canada/ontario.rb
74
+ - lib/income_tax/countries/canada/prince_edward_island.rb
75
+ - lib/income_tax/countries/canada/quebec.rb
76
+ - lib/income_tax/countries/canada/saskatchewan.rb
77
+ - lib/income_tax/countries/canada/yukon.rb
64
78
  - lib/income_tax/countries/cape_verde.rb
65
79
  - lib/income_tax/countries/caribbean_netherlands.rb
66
80
  - lib/income_tax/countries/cayman_islands.rb