tax_easy 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.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +34 -0
- data/lib/tasks/tax_easy_tasks.rake +4 -0
- data/lib/tax_easy/calculator/installment.rb +16 -0
- data/lib/tax_easy/financial/brazil/iof.rb +76 -0
- data/lib/tax_easy/version.rb +3 -0
- data/lib/tax_easy.rb +4 -0
- metadata +93 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b801401f6727d9ffbf7838dfd26eb7a849545be8
|
4
|
+
data.tar.gz: a8ebad4b88b66cf754cb182000fa4e5970e023cf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cc2b5fb7a150438e50444a9a373bf36c861790c63769ceb75c5f200be038913b62b69552a42e363520fe9d7523cfa44c7201c254045f8278e67d15359b5e9364
|
7
|
+
data.tar.gz: d43114b33f6ee99018d0d9d8617136c9dc4d5d2c6250cc4c5e0b8fb8d44ff3bedae21d0c5de927613504101bd99c92797e37c6315f216d61f3ba881de8558689
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2016 Victor Alencar
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'TaxEasy'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
Bundler::GemHelper.install_tasks
|
23
|
+
|
24
|
+
require 'rake/testtask'
|
25
|
+
|
26
|
+
Rake::TestTask.new(:test) do |t|
|
27
|
+
t.libs << 'lib'
|
28
|
+
t.libs << 'test'
|
29
|
+
t.pattern = 'test/**/*_test.rb'
|
30
|
+
t.verbose = false
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
task default: :test
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'exonio'
|
2
|
+
|
3
|
+
module TaxEasy
|
4
|
+
module Calculator
|
5
|
+
class Installment
|
6
|
+
|
7
|
+
def initialize(overrides = {})
|
8
|
+
@calculator = overrides.fetch(:calculator) { Exonio }
|
9
|
+
end
|
10
|
+
|
11
|
+
def calculate(interest, financing_time_months, total)
|
12
|
+
@calculator.pmt(interest/100, financing_time_months, -total)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'tax_easy/calculator/installment'
|
2
|
+
|
3
|
+
module TaxEasy
|
4
|
+
module Financial
|
5
|
+
module Brazil
|
6
|
+
class IOF
|
7
|
+
DEFAULT_IOF_DAY = 0.000041
|
8
|
+
DEFAULT_IOF_ADDITIONAL = 0.0038
|
9
|
+
|
10
|
+
def initialize(overrides = {})
|
11
|
+
@iof_day = overrides.fetch(:iof_day) { DEFAULT_IOF_DAY }
|
12
|
+
@iof_additional = overrides.fetch(:iof_additional) { DEFAULT_IOF_ADDITIONAL }
|
13
|
+
@installment_calculator = overrides.fetch(:installment_calculator) { TaxEasy::Calculator::Installment.new }
|
14
|
+
end
|
15
|
+
|
16
|
+
# Calculates IOF for Loan in Brazil
|
17
|
+
# @param loan_value [Float]
|
18
|
+
# @param financing_time_months [Integer] The number of payments to be made
|
19
|
+
# @param interest_rate [Float] The interest rate as decimal (not per cent) per period
|
20
|
+
# @param loan_date [Date] The loan request date
|
21
|
+
# @return [Float]
|
22
|
+
#
|
23
|
+
# @example
|
24
|
+
# TaxEasy::Financial::Brazil::IOF.new.calculate(20_000, 48, 1.5) # ==> 356.70671942746617
|
25
|
+
#
|
26
|
+
def calculate(loan_value, financing_time_months, interest_rate, loan_date = Date.today)
|
27
|
+
balance = loan_value
|
28
|
+
installment = installment_value(interest_rate, financing_time_months, loan_value)
|
29
|
+
installment_date = loan_date.next_month
|
30
|
+
iof = 0
|
31
|
+
|
32
|
+
financing_time_months.step(1, -1) do |_|
|
33
|
+
amortization = installment - interest_part(balance, interest_rate)
|
34
|
+
|
35
|
+
days = past_days(loan_date, installment_date)
|
36
|
+
|
37
|
+
iof += amortization*(@iof_day*(minimal_days(days)))
|
38
|
+
iof += amortization*@iof_additional
|
39
|
+
|
40
|
+
balance -= amortization
|
41
|
+
installment_date = installment_date.next_month
|
42
|
+
end
|
43
|
+
|
44
|
+
loan_iof(iof, loan_value)
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
## Calcualtes installment value for loan
|
50
|
+
def installment_value(interest_rate, financing_time_months, loan_value)
|
51
|
+
@installment_calculator.calculate(interest_rate, financing_time_months, loan_value)
|
52
|
+
end
|
53
|
+
|
54
|
+
## Calculates the final IOF base on IOF not loan value
|
55
|
+
def loan_iof(iof, loan_value)
|
56
|
+
(iof*loan_value)/(loan_value-iof)
|
57
|
+
end
|
58
|
+
|
59
|
+
## Interest part to be payed on specific installment
|
60
|
+
def interest_part(balance, interest_rate)
|
61
|
+
balance*(interest_rate/100)
|
62
|
+
end
|
63
|
+
|
64
|
+
## Past days from specific date
|
65
|
+
def past_days(start_date, end_date)
|
66
|
+
(end_date - start_date).to_i
|
67
|
+
end
|
68
|
+
|
69
|
+
## Minimal days from 365 to calculate IOF
|
70
|
+
def minimal_days(past_days)
|
71
|
+
[past_days, 365].min
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
data/lib/tax_easy.rb
ADDED
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tax_easy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Victor Alencar
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-06-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: exonio
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.5.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.5.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.99.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.99.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry-byebug
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.1.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.1.0
|
55
|
+
description: TaxEasy - Calculate Taxes
|
56
|
+
email:
|
57
|
+
- victor.a.alencar@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- MIT-LICENSE
|
63
|
+
- Rakefile
|
64
|
+
- lib/tasks/tax_easy_tasks.rake
|
65
|
+
- lib/tax_easy.rb
|
66
|
+
- lib/tax_easy/calculator/installment.rb
|
67
|
+
- lib/tax_easy/financial/brazil/iof.rb
|
68
|
+
- lib/tax_easy/version.rb
|
69
|
+
homepage: https://github.com/valencar/tax_easy
|
70
|
+
licenses:
|
71
|
+
- MIT
|
72
|
+
metadata: {}
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
requirements: []
|
88
|
+
rubyforge_project:
|
89
|
+
rubygems_version: 2.4.8
|
90
|
+
signing_key:
|
91
|
+
specification_version: 4
|
92
|
+
summary: TaxEasy - Calculate Taxes
|
93
|
+
test_files: []
|