brir 0.2.0
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.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +80 -0
- data/Rakefile +8 -0
- data/brir.gemspec +20 -0
- data/lib/brir.rb +8 -0
- data/lib/brir/brir_api.rb +78 -0
- data/lib/brir/table_source/progressiveTable.yml +108 -0
- data/lib/brir/version.rb +3 -0
- data/spec/lib/brir_spec.rb +76 -0
- data/spec/spec_helper.rb +1 -0
- metadata +92 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Brunno dos Santos
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
# Brir
|
2
|
+
|
3
|
+
Brir is a interface to calculate the Brazilian Income Tax (Imposto de Renda Brasileiro - IRPF & IRPJ).
|
4
|
+
This gem was created to solve a unique issue that is calculate how many money the brazilians will pay to your country over your anual income.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'brir'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install brir
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
require 'brir'
|
23
|
+
|
24
|
+
# chose the exercise year or leave blank to use actual year
|
25
|
+
brir = Brir.new 2012
|
26
|
+
|
27
|
+
# call tax method passing your taxable income
|
28
|
+
income_tax_value = brir.tax 42000
|
29
|
+
|
30
|
+
puts income_tax_value
|
31
|
+
#=> 3109.53
|
32
|
+
|
33
|
+
## Progressive Table
|
34
|
+
|
35
|
+
This gem already have a progressive table with the following exercise years (Financial Year):
|
36
|
+
|
37
|
+
* 2012
|
38
|
+
* 2013
|
39
|
+
* 2014
|
40
|
+
* 2015
|
41
|
+
|
42
|
+
If you want to use your own Progressive Table, you must to create a YAML file into your config path. (Only for Rails Applications).
|
43
|
+
The file must be like these:
|
44
|
+
|
45
|
+
2012:
|
46
|
+
ranges:
|
47
|
+
first:
|
48
|
+
from: 0
|
49
|
+
to: 18799.32
|
50
|
+
aliquot:
|
51
|
+
portion: 0
|
52
|
+
second:
|
53
|
+
from: 18799.33
|
54
|
+
to: 28174.20
|
55
|
+
aliquot: 7.5
|
56
|
+
portion: 1409.95
|
57
|
+
third:
|
58
|
+
from: 28174.21
|
59
|
+
to: 37566.12
|
60
|
+
aliquot: 15
|
61
|
+
portion: 3523.01
|
62
|
+
fourth:
|
63
|
+
from: 37566.13
|
64
|
+
to: 46939.56
|
65
|
+
aliquot: 22.5
|
66
|
+
portion: 6340.47
|
67
|
+
fifth:
|
68
|
+
from: 46939.57
|
69
|
+
to:
|
70
|
+
aliquot: 27.5
|
71
|
+
portion: 8687.45
|
72
|
+
|
73
|
+
|
74
|
+
## Contributing
|
75
|
+
|
76
|
+
1. Fork it
|
77
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
78
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
79
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
80
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/brir.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/brir/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Brunno dos Santos"]
|
6
|
+
gem.email = ["brunno@brunno.me"]
|
7
|
+
gem.description = %q{Brir provide a interface to calculate Brazilian Icome Taxes (IRPF and IRPJ)}
|
8
|
+
gem.summary = %q{Calculate Brazilian Icome Taxes}
|
9
|
+
gem.homepage = "https://github.com/squiter85/brir"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "brir"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Brir::VERSION
|
17
|
+
|
18
|
+
gem.add_development_dependency 'rake'
|
19
|
+
gem.add_development_dependency 'rspec'
|
20
|
+
end
|
data/lib/brir.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
module Brir
|
2
|
+
class BrirApi
|
3
|
+
attr_accessor :exercise_year, :calendar_year, :ranges
|
4
|
+
|
5
|
+
def initialize(exercise_year = nil)
|
6
|
+
@exercise_year = (exercise_year.nil?) ? Time.new.year : exercise_year
|
7
|
+
@calendar_year = @exercise_year.to_i - 1
|
8
|
+
@ranges = table(@exercise_year)
|
9
|
+
end
|
10
|
+
|
11
|
+
def tax(income)
|
12
|
+
|
13
|
+
# prevent negative incomes
|
14
|
+
income = income.to_f.round 2
|
15
|
+
return 0.00 unless income > 0
|
16
|
+
|
17
|
+
case income
|
18
|
+
when @ranges["second"]["from"]..@ranges["second"]["to"]
|
19
|
+
|
20
|
+
# secound range
|
21
|
+
total = (((income.to_f - @ranges["second"]["from"])*@ranges["second"]["aliquot"])/100)
|
22
|
+
|
23
|
+
when @ranges["third"]["from"]..@ranges["third"]["to"]
|
24
|
+
|
25
|
+
# third range
|
26
|
+
total = (((@ranges["second"]["to"] - @ranges["second"]["from"])*@ranges["second"]["aliquot"])/100)
|
27
|
+
total = (total.round 2) + (((income.to_f - @ranges["second"]["to"])*@ranges["third"]["aliquot"])/100)
|
28
|
+
|
29
|
+
when @ranges["fourth"]["from"]..@ranges["fourth"]["to"]
|
30
|
+
|
31
|
+
# fourth range
|
32
|
+
total = (((@ranges["second"]["to"] - @ranges["second"]["from"])*@ranges["second"]["aliquot"])/100)
|
33
|
+
total = (total.round 2) + (((@ranges["third"]["to"] - @ranges["second"]["to"])*@ranges["third"]["aliquot"])/100)
|
34
|
+
total = (total.round 2) + (((income.to_f - @ranges["third"]["to"])*@ranges["fourth"]["aliquot"])/100)
|
35
|
+
|
36
|
+
when @ranges["fifth"]["from"]..(1.0/0.0)
|
37
|
+
|
38
|
+
#fifth range
|
39
|
+
total = (((@ranges["second"]["to"] - @ranges["second"]["from"])*@ranges["second"]["aliquot"])/100)
|
40
|
+
total = (total.round 2) + (((@ranges["third"]["to"] - @ranges["second"]["to"])*@ranges["third"]["aliquot"])/100)
|
41
|
+
total = (total.round 2) + (((@ranges["fourth"]["to"] - @ranges["third"]["to"])*@ranges["fourth"]["aliquot"])/100)
|
42
|
+
total = (total.round 2) + (((income.to_f - @ranges["fourth"]["to"])*@ranges["fifth"]["aliquot"])/100)
|
43
|
+
|
44
|
+
else
|
45
|
+
total = 0.00
|
46
|
+
end
|
47
|
+
total.to_f.round 2
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
def set_progressive_table()
|
52
|
+
require 'yaml'
|
53
|
+
|
54
|
+
begin
|
55
|
+
# Trying to get brir.yml into config path, for Rails Applications
|
56
|
+
file = File.join(Rails.root, "config", "brir.yml")
|
57
|
+
rescue
|
58
|
+
file = File.join(File.dirname(__FILE__),"table_source/progressiveTable.yml")
|
59
|
+
end
|
60
|
+
|
61
|
+
begin
|
62
|
+
yaml = YAML.load_file(file)
|
63
|
+
rescue Errno::ENOENT
|
64
|
+
puts "Fails"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def table(exercise_year)
|
69
|
+
yaml = set_progressive_table()
|
70
|
+
begin
|
71
|
+
yaml[exercise_year]["ranges"]
|
72
|
+
rescue Exception => e
|
73
|
+
nil
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
2012:
|
2
|
+
ranges:
|
3
|
+
first:
|
4
|
+
from: 0
|
5
|
+
to: 18799.32
|
6
|
+
aliquot:
|
7
|
+
portion: 0
|
8
|
+
second:
|
9
|
+
from: 18799.33
|
10
|
+
to: 28174.20
|
11
|
+
aliquot: 7.5
|
12
|
+
portion: 1409.95
|
13
|
+
third:
|
14
|
+
from: 28174.21
|
15
|
+
to: 37566.12
|
16
|
+
aliquot: 15
|
17
|
+
portion: 3523.01
|
18
|
+
fourth:
|
19
|
+
from: 37566.13
|
20
|
+
to: 46939.56
|
21
|
+
aliquot: 22.5
|
22
|
+
portion: 6340.47
|
23
|
+
fifth:
|
24
|
+
from: 46939.57
|
25
|
+
to:
|
26
|
+
aliquot: 27.5
|
27
|
+
portion: 8687.45
|
28
|
+
2013:
|
29
|
+
ranges:
|
30
|
+
first:
|
31
|
+
from: 0
|
32
|
+
to: 19645.32
|
33
|
+
aliquot:
|
34
|
+
portion: 0
|
35
|
+
second:
|
36
|
+
from: 19645.33
|
37
|
+
to: 29442.00
|
38
|
+
aliquot: 7.5
|
39
|
+
portion: 1473.40
|
40
|
+
third:
|
41
|
+
from: 29442.01
|
42
|
+
to: 39256.56
|
43
|
+
aliquot: 15
|
44
|
+
portion: 3681.55
|
45
|
+
fourth:
|
46
|
+
from: 39256.57
|
47
|
+
to: 49051.80
|
48
|
+
aliquot: 22.5
|
49
|
+
portion: 6625.79
|
50
|
+
fifth:
|
51
|
+
from: 49051.81
|
52
|
+
to:
|
53
|
+
aliquot: 27.5
|
54
|
+
portion: 9078.38
|
55
|
+
2014:
|
56
|
+
ranges:
|
57
|
+
first:
|
58
|
+
from: 0
|
59
|
+
to: 20529.36
|
60
|
+
aliquot:
|
61
|
+
portion: 0
|
62
|
+
second:
|
63
|
+
from: 20529.37
|
64
|
+
to: 30766.92
|
65
|
+
aliquot: 7.5
|
66
|
+
portion: 1539.70
|
67
|
+
third:
|
68
|
+
from: 30766.93
|
69
|
+
to: 41023.08
|
70
|
+
aliquot: 15
|
71
|
+
portion: 3847.22
|
72
|
+
fourth:
|
73
|
+
from: 41023.09
|
74
|
+
to: 51259.08
|
75
|
+
aliquot: 22.5
|
76
|
+
portion: 6923.95
|
77
|
+
fifth:
|
78
|
+
from: 51259.08
|
79
|
+
to:
|
80
|
+
aliquot: 27.5
|
81
|
+
portion: 9486.91
|
82
|
+
2015:
|
83
|
+
ranges:
|
84
|
+
first:
|
85
|
+
from: 0
|
86
|
+
to: 21453.24
|
87
|
+
aliquot:
|
88
|
+
portion: 0
|
89
|
+
second:
|
90
|
+
from: 21453.25
|
91
|
+
to: 32151.48
|
92
|
+
aliquot: 7.5
|
93
|
+
portion: 1608.99
|
94
|
+
third:
|
95
|
+
from: 32151.49
|
96
|
+
to: 42869.16
|
97
|
+
aliquot: 15
|
98
|
+
portion: 4020.35
|
99
|
+
fourth:
|
100
|
+
from: 42869.17
|
101
|
+
to: 53565.72
|
102
|
+
aliquot: 22.5
|
103
|
+
portion: 7235.54
|
104
|
+
fifth:
|
105
|
+
from: 53564.72
|
106
|
+
to:
|
107
|
+
aliquot: 27.5
|
108
|
+
portion: 9913.83
|
data/lib/brir/version.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Brir do
|
4
|
+
it 'should return a calendar year for a exercise year' do
|
5
|
+
brir = Brir.new(2015)
|
6
|
+
brir.should_not be_nil
|
7
|
+
brir.calendar_year.should == 2014
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should return a calendar year whithout a exercise year' do
|
11
|
+
brir = Brir.new
|
12
|
+
brir.should_not be_nil
|
13
|
+
brir.calendar_year.should == (Time.new.year.to_i - 1)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should consume the progressive table' do
|
17
|
+
brir = Brir.new(2012)
|
18
|
+
brir.ranges["first"]["from"].should == 0
|
19
|
+
brir.ranges["fifth"]["to"].should be_nil
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should know which incomes are free for taxes' do
|
23
|
+
brir = Brir.new(2012)
|
24
|
+
brir.tax(-20).should == 0.00
|
25
|
+
brir.tax(10000.00).should == 0.00
|
26
|
+
brir.tax(15000.00).should == 0.00
|
27
|
+
brir.tax(17500.43).should == 0.00
|
28
|
+
brir.tax(18700.30).should == 0.00
|
29
|
+
brir.tax(18799.32).should == 0.00
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should calculate all secound range incomes' do
|
33
|
+
brir = Brir.new(2012)
|
34
|
+
brir.tax(18799.32).should == 0.00
|
35
|
+
brir.tax(18799.40).should == 0.01
|
36
|
+
brir.tax(28000).should == 690.05
|
37
|
+
brir.tax(19500).should == 52.55
|
38
|
+
brir.tax(19600.34).should == 60.08
|
39
|
+
brir.tax(27699.20).should == 667.49
|
40
|
+
brir.tax(28174.20).should == 703.12
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should calculate all third range incomes' do
|
44
|
+
brir = Brir.new 2012
|
45
|
+
brir.tax(28174.21).should == 703.12
|
46
|
+
brir.tax(28174.40).should == 703.15
|
47
|
+
brir.tax(30000).should == 976.99
|
48
|
+
brir.tax(35500).should == 1801.99
|
49
|
+
brir.tax(37004.20).should == 2027.62
|
50
|
+
brir.tax(35666.50).should == 1826.96
|
51
|
+
brir.tax(37566.12).should == 2111.91
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should calculate all fourth range incomes' do
|
55
|
+
brir = Brir.new 2012
|
56
|
+
brir.tax(37566.13).should == 2111.91
|
57
|
+
brir.tax(37566.23).should == 2111.93
|
58
|
+
brir.tax(38000).should == 2209.53
|
59
|
+
brir.tax(40000).should == 2659.53
|
60
|
+
brir.tax(43560.98).should == 3460.75
|
61
|
+
brir.tax(46830).should == 4196.28
|
62
|
+
brir.tax(46830).should == 4196.28
|
63
|
+
brir.tax(46939.56).should == 4220.93
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'should calculate all fifth range incomes' do
|
67
|
+
brir = Brir.new 2012
|
68
|
+
brir.tax(46939.57).should == 4220.93
|
69
|
+
brir.tax(46939.66).should == 4220.96
|
70
|
+
brir.tax(47000).should == 4237.55
|
71
|
+
brir.tax(49666.40).should == 4970.81
|
72
|
+
brir.tax(69700.00).should == 10480.05
|
73
|
+
brir.tax(142500.00).should == 30500.05
|
74
|
+
brir.tax(14250000.00).should == 3910062.55
|
75
|
+
end
|
76
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'brir'
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: brir
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Brunno dos Santos
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-28 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: Brir provide a interface to calculate Brazilian Icome Taxes (IRPF and
|
47
|
+
IRPJ)
|
48
|
+
email:
|
49
|
+
- brunno@brunno.me
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- .gitignore
|
55
|
+
- Gemfile
|
56
|
+
- LICENSE
|
57
|
+
- README.md
|
58
|
+
- Rakefile
|
59
|
+
- brir.gemspec
|
60
|
+
- lib/brir.rb
|
61
|
+
- lib/brir/brir_api.rb
|
62
|
+
- lib/brir/table_source/progressiveTable.yml
|
63
|
+
- lib/brir/version.rb
|
64
|
+
- spec/lib/brir_spec.rb
|
65
|
+
- spec/spec_helper.rb
|
66
|
+
homepage: https://github.com/squiter85/brir
|
67
|
+
licenses: []
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ! '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
requirements: []
|
85
|
+
rubyforge_project:
|
86
|
+
rubygems_version: 1.8.24
|
87
|
+
signing_key:
|
88
|
+
specification_version: 3
|
89
|
+
summary: Calculate Brazilian Icome Taxes
|
90
|
+
test_files:
|
91
|
+
- spec/lib/brir_spec.rb
|
92
|
+
- spec/spec_helper.rb
|