death_and_taxes 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +48 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +82 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +1 -0
- data/config/ca.yml +17 -0
- data/death_and_taxes-0.0.1.gem +0 -0
- data/death_and_taxes.gemspec +22 -0
- data/lib/death_and_taxes/hook.rb +7 -0
- data/lib/death_and_taxes/instance_methods.rb +5 -0
- data/lib/death_and_taxes/railtie.rb +10 -0
- data/lib/death_and_taxes/taxes/country.rb +38 -0
- data/lib/death_and_taxes/taxes/state.rb +5 -0
- data/lib/death_and_taxes/taxes/tax.rb +10 -0
- data/lib/death_and_taxes/version.rb +3 -0
- data/lib/death_and_taxes.rb +16 -0
- data/lib/generators/death_and_taxes/migration/migration_generator.rb +33 -0
- data/lib/generators/death_and_taxes/migration/templates/active_record/migration.rb +17 -0
- data/test/helper.rb +18 -0
- data/test/test_death_and_taxes.rb +7 -0
- metadata +90 -0
data/.document
ADDED
data/.gitignore
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# rcov generated
|
2
|
+
coverage
|
3
|
+
|
4
|
+
# rdoc generated
|
5
|
+
rdoc
|
6
|
+
|
7
|
+
# yard generated
|
8
|
+
doc
|
9
|
+
.yardoc
|
10
|
+
|
11
|
+
# bundler
|
12
|
+
.bundle
|
13
|
+
|
14
|
+
# jeweler generated
|
15
|
+
pkg
|
16
|
+
|
17
|
+
# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
|
18
|
+
#
|
19
|
+
# * Create a file at ~/.gitignore
|
20
|
+
# * Include files you want ignored
|
21
|
+
# * Run: git config --global core.excludesfile ~/.gitignore
|
22
|
+
#
|
23
|
+
# After doing this, these files will be ignored in all your git projects,
|
24
|
+
# saving you from having to 'pollute' every project you touch with them
|
25
|
+
#
|
26
|
+
# Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
|
27
|
+
#
|
28
|
+
# For MacOS:
|
29
|
+
#
|
30
|
+
#.DS_Store
|
31
|
+
|
32
|
+
# For TextMate
|
33
|
+
#*.tmproj
|
34
|
+
#tmtags
|
35
|
+
|
36
|
+
# For emacs:
|
37
|
+
#*~
|
38
|
+
#\#*
|
39
|
+
#.\#*
|
40
|
+
|
41
|
+
# For vim:
|
42
|
+
#*.swp
|
43
|
+
|
44
|
+
# For redcar:
|
45
|
+
#.redcar
|
46
|
+
|
47
|
+
# For rubinius:
|
48
|
+
#*.rbc
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
death_and_taxes (0.0.0)
|
5
|
+
rails
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
abstract (1.0.0)
|
11
|
+
actionmailer (3.0.9)
|
12
|
+
actionpack (= 3.0.9)
|
13
|
+
mail (~> 2.2.19)
|
14
|
+
actionpack (3.0.9)
|
15
|
+
activemodel (= 3.0.9)
|
16
|
+
activesupport (= 3.0.9)
|
17
|
+
builder (~> 2.1.2)
|
18
|
+
erubis (~> 2.6.6)
|
19
|
+
i18n (~> 0.5.0)
|
20
|
+
rack (~> 1.2.1)
|
21
|
+
rack-mount (~> 0.6.14)
|
22
|
+
rack-test (~> 0.5.7)
|
23
|
+
tzinfo (~> 0.3.23)
|
24
|
+
activemodel (3.0.9)
|
25
|
+
activesupport (= 3.0.9)
|
26
|
+
builder (~> 2.1.2)
|
27
|
+
i18n (~> 0.5.0)
|
28
|
+
activerecord (3.0.9)
|
29
|
+
activemodel (= 3.0.9)
|
30
|
+
activesupport (= 3.0.9)
|
31
|
+
arel (~> 2.0.10)
|
32
|
+
tzinfo (~> 0.3.23)
|
33
|
+
activeresource (3.0.9)
|
34
|
+
activemodel (= 3.0.9)
|
35
|
+
activesupport (= 3.0.9)
|
36
|
+
activesupport (3.0.9)
|
37
|
+
arel (2.0.10)
|
38
|
+
builder (2.1.2)
|
39
|
+
erubis (2.6.6)
|
40
|
+
abstract (>= 1.0.0)
|
41
|
+
i18n (0.5.0)
|
42
|
+
mail (2.2.19)
|
43
|
+
activesupport (>= 2.3.6)
|
44
|
+
i18n (>= 0.4.0)
|
45
|
+
mime-types (~> 1.16)
|
46
|
+
treetop (~> 1.4.8)
|
47
|
+
mime-types (1.16)
|
48
|
+
polyglot (0.3.2)
|
49
|
+
rack (1.2.3)
|
50
|
+
rack-mount (0.6.14)
|
51
|
+
rack (>= 1.0.0)
|
52
|
+
rack-test (0.5.7)
|
53
|
+
rack (>= 1.0)
|
54
|
+
rails (3.0.9)
|
55
|
+
actionmailer (= 3.0.9)
|
56
|
+
actionpack (= 3.0.9)
|
57
|
+
activerecord (= 3.0.9)
|
58
|
+
activeresource (= 3.0.9)
|
59
|
+
activesupport (= 3.0.9)
|
60
|
+
bundler (~> 1.0)
|
61
|
+
railties (= 3.0.9)
|
62
|
+
railties (3.0.9)
|
63
|
+
actionpack (= 3.0.9)
|
64
|
+
activesupport (= 3.0.9)
|
65
|
+
rake (>= 0.8.7)
|
66
|
+
rdoc (~> 3.4)
|
67
|
+
thor (~> 0.14.4)
|
68
|
+
rake (0.9.2)
|
69
|
+
rdoc (3.9.1)
|
70
|
+
sqlite3 (1.3.4)
|
71
|
+
thor (0.14.6)
|
72
|
+
treetop (1.4.10)
|
73
|
+
polyglot
|
74
|
+
polyglot (>= 0.3.1)
|
75
|
+
tzinfo (0.3.29)
|
76
|
+
|
77
|
+
PLATFORMS
|
78
|
+
ruby
|
79
|
+
|
80
|
+
DEPENDENCIES
|
81
|
+
death_and_taxes!
|
82
|
+
sqlite3
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Guillaume Malette
|
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/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= death_and_taxes
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to death_and_taxes
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
9
|
+
* Fork the project
|
10
|
+
* Start a feature/bugfix branch
|
11
|
+
* Commit and push until you are happy with your contribution
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2011 Guillaume Malette. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/config/ca.yml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
taxes:
|
2
|
+
-
|
3
|
+
start_date: 2011-01-01
|
4
|
+
end_date: 2012-01-01
|
5
|
+
percentage: 5.0
|
6
|
+
name: gst
|
7
|
+
states:
|
8
|
+
qc:
|
9
|
+
-
|
10
|
+
start_date: 2011-01-01
|
11
|
+
end_date: 2012-01-01
|
12
|
+
percentage: 8.5
|
13
|
+
name: pst
|
14
|
+
rule:
|
15
|
+
country: ['gst']
|
16
|
+
state:
|
17
|
+
compound: ['gst', 'pst']
|
Binary file
|
@@ -0,0 +1,22 @@
|
|
1
|
+
$:.push File.join(File.dirname(__FILE__), '/lib')
|
2
|
+
|
3
|
+
require 'death_and_taxes/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.name = "death_and_taxes"
|
7
|
+
gem.authors = ['Guillaume Malette']
|
8
|
+
gem.date = %q{2011-08-09}
|
9
|
+
gem.description = %q{Death and Taxes allows to 'easily' calculate taxes on a model}
|
10
|
+
gem.summary = "Tax calculations"
|
11
|
+
gem.email = 'gmalette@gmail.com'
|
12
|
+
gem.homepage = ''
|
13
|
+
|
14
|
+
gem.add_runtime_dependency 'rails'
|
15
|
+
gem.add_development_dependency 'sqlite3'
|
16
|
+
|
17
|
+
gem.executables = []
|
18
|
+
gem.files = `git ls-files`.split("\n")
|
19
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
|
+
gem.require_paths = ['lib']
|
21
|
+
gem.version = DeathAndTaxes::VERSION
|
22
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
class DeathAndTaxes::Taxes::Country
|
2
|
+
|
3
|
+
def initialize tax_infos
|
4
|
+
@taxes = tax_infos['taxes'].collect do |tax|
|
5
|
+
Tax.new tax, :country => self
|
6
|
+
end
|
7
|
+
|
8
|
+
@states = {}
|
9
|
+
tax_infos['states'].each do |name, tax|
|
10
|
+
@states[name] = Tax.new(tax)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def apply_taxes product, from, to, options = {}
|
15
|
+
if from[:country] == to[:country]
|
16
|
+
if (state = @states[from[:state]] && state.matches?(from, to))
|
17
|
+
state.apply_taxes product, from, to, options
|
18
|
+
else
|
19
|
+
apply_tax product, from, to, options
|
20
|
+
end
|
21
|
+
end
|
22
|
+
[]
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
def apply_tax product, from, to, options
|
27
|
+
options.reverse_merge!({:time => Time.now})
|
28
|
+
|
29
|
+
find_tax product, options[:date]
|
30
|
+
end
|
31
|
+
|
32
|
+
def find_tax product, date
|
33
|
+
@taxes.select do |tax|
|
34
|
+
tax.period.cover?(date)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
require 'active_record/version'
|
3
|
+
|
4
|
+
require 'active_support/core_ext'
|
5
|
+
|
6
|
+
|
7
|
+
require File.join(File.dirname(__FILE__), 'death_and_taxes/railtie')
|
8
|
+
|
9
|
+
module DeathAndTaxes
|
10
|
+
autoload :Hook, File.join(File.dirname(__FILE__), "death_and_taxes/hook")
|
11
|
+
autoload :InstanceMethods, File.join(File.dirname(__FILE__), "death_and_taxes/instance_methods")
|
12
|
+
|
13
|
+
@taxes = Dir[File.join( File.dirname(__FILE__), '..', 'config', '*.yml' )].map do |filename|
|
14
|
+
DeathAndTaxes::Taxes::Country.new(YAML.load_file(file_name))
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'rails/generators/active_record'
|
2
|
+
require 'rails/generators/migration'
|
3
|
+
|
4
|
+
# Blindly copied from acts-as-taggable-on
|
5
|
+
module DeathAndTaxes
|
6
|
+
class MigrationGenerator < Rails::Generators::Base
|
7
|
+
include Rails::Generators::Migration
|
8
|
+
|
9
|
+
desc "Generates migrations for taxations"
|
10
|
+
|
11
|
+
def self.orm
|
12
|
+
Rails::Generators.options[:rails][:orm]
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.source_root
|
16
|
+
File.join(File.dirname(__FILE__), 'templates', (orm.to_s unless orm.class.eql?(String)))
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.orm_has_migration?
|
20
|
+
[:active_record].include? orm
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.next_migration_number path
|
24
|
+
ActiveRecord::Generators::Base.next_migration_number path
|
25
|
+
end
|
26
|
+
|
27
|
+
def create_migration_file
|
28
|
+
if self.class.orm_has_migration?
|
29
|
+
migration_template 'migration.rb', 'db/migrate/death_and_taxes_migration'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class DeathAndTaxesMigration < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :taxations do |t|
|
4
|
+
t.references :taxable, :polymorphic => true
|
5
|
+
t.integer :amount
|
6
|
+
t.float :percentage
|
7
|
+
t.string :level
|
8
|
+
t.string :name
|
9
|
+
end
|
10
|
+
|
11
|
+
add_index :taxations, [:taxable_id, :taxable_type]
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.down
|
15
|
+
drop_table :taxations
|
16
|
+
end
|
17
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
require 'shoulda'
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
require 'death_and_taxes'
|
16
|
+
|
17
|
+
class Test::Unit::TestCase
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: death_and_taxes
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Guillaume Malette
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-08-09 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: &2157922740 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2157922740
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: sqlite3
|
27
|
+
requirement: &2157922200 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2157922200
|
36
|
+
description: Death and Taxes allows to 'easily' calculate taxes on a model
|
37
|
+
email: gmalette@gmail.com
|
38
|
+
executables: []
|
39
|
+
extensions: []
|
40
|
+
extra_rdoc_files: []
|
41
|
+
files:
|
42
|
+
- .document
|
43
|
+
- .gitignore
|
44
|
+
- Gemfile
|
45
|
+
- Gemfile.lock
|
46
|
+
- LICENSE.txt
|
47
|
+
- README.rdoc
|
48
|
+
- Rakefile
|
49
|
+
- config/ca.yml
|
50
|
+
- death_and_taxes-0.0.1.gem
|
51
|
+
- death_and_taxes.gemspec
|
52
|
+
- lib/death_and_taxes.rb
|
53
|
+
- lib/death_and_taxes/hook.rb
|
54
|
+
- lib/death_and_taxes/instance_methods.rb
|
55
|
+
- lib/death_and_taxes/railtie.rb
|
56
|
+
- lib/death_and_taxes/taxes/country.rb
|
57
|
+
- lib/death_and_taxes/taxes/state.rb
|
58
|
+
- lib/death_and_taxes/taxes/tax.rb
|
59
|
+
- lib/death_and_taxes/version.rb
|
60
|
+
- lib/generators/death_and_taxes/migration/migration_generator.rb
|
61
|
+
- lib/generators/death_and_taxes/migration/templates/active_record/migration.rb
|
62
|
+
- test/helper.rb
|
63
|
+
- test/test_death_and_taxes.rb
|
64
|
+
homepage: ''
|
65
|
+
licenses: []
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ! '>='
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
requirements: []
|
83
|
+
rubyforge_project:
|
84
|
+
rubygems_version: 1.8.6
|
85
|
+
signing_key:
|
86
|
+
specification_version: 3
|
87
|
+
summary: Tax calculations
|
88
|
+
test_files:
|
89
|
+
- test/helper.rb
|
90
|
+
- test/test_death_and_taxes.rb
|