taxedo 0.0.4 → 0.0.5

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.
@@ -25,6 +25,10 @@ taxedo:
25
25
  currency: cad
26
26
  included: false
27
27
 
28
+ equation_types:
29
+ 19910101: compiled
30
+ 20130101: separated
31
+
28
32
  rules:
29
33
  standard: ['gst', 'qst']
30
34
  non_taxable: ['gst_zero', 'qst_zero']
@@ -42,5 +46,6 @@ taxedo:
42
46
  19980101: 750
43
47
  20110101: 850
44
48
  20120101: 950
49
+ 20130101: 997.5
45
50
  qst_zero:
46
51
  19910101: 0
@@ -1,5 +1,6 @@
1
1
  class Taxedo::Receipt
2
2
  attr_accessor :currency
3
+ attr_accessor :equation_type
3
4
 
4
5
  def initialize(region_id, amount)
5
6
  @region_id = region_id
@@ -13,11 +14,19 @@ class Taxedo::Receipt
13
14
  tax = Taxedo::Tax.new(id)
14
15
  tax.name = tax_name(id)
15
16
  tax.rate = rate
16
- tax.source_amount = (@taxes.empty? ? @amount : @taxes.last.subtotal)
17
+ tax.source_amount = get_source_amount
17
18
 
18
19
  @taxes << tax
19
20
  end
20
21
 
22
+ def get_source_amount
23
+ if @taxes.empty? or self.equation_type == 'separated'
24
+ @amount
25
+ else
26
+ @taxes.last.subtotal
27
+ end
28
+ end
29
+
21
30
  def language
22
31
  defined?(I18n) ? I18n.locale.to_s : 'fr'
23
32
  end
@@ -1,3 +1,4 @@
1
+ require 'yaml'
1
2
  require 'time'
2
3
 
3
4
  class Taxedo::Region
@@ -7,10 +8,11 @@ class Taxedo::Region
7
8
  end
8
9
 
9
10
  def calculate(amount, options={})
10
- options = { :on => Time.now, :rule => 'standard' }.merge(options)
11
+ options = { :on => Time.now, :rule => 'standard', :equations => 'compiled'}.merge(options)
11
12
 
12
13
  receipt = Taxedo::Receipt.new(@id, amount)
13
14
  receipt.currency = @data['currency']
15
+ receipt.equation_type = equation_type_from_date(options[:on]).nil? ? options[:equations] : equation_type_from_date(options[:on])
14
16
 
15
17
  taxes(options[:rule], options[:on]).each do |tax|
16
18
  receipt.add_tax tax[0], tax[1]
@@ -21,6 +23,15 @@ class Taxedo::Region
21
23
 
22
24
  private
23
25
 
26
+ def equation_type_from_date(start_at)
27
+ selection = Time.at(0)
28
+ @data['equation_types'].each do |equation_start_at, equation|
29
+ equation_start_at = Time.parse(equation_start_at.to_s)
30
+ selection = equation_start_at if equation_start_at <= start_at and equation_start_at > selection
31
+ end
32
+ @data['equation_types'][selection.strftime('%Y%m%d').to_i]
33
+ end
34
+
24
35
  def tax_from_start_date(tax_id, start_at)
25
36
  selection = Time.at(0)
26
37
 
metadata CHANGED
@@ -1,49 +1,64 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: taxedo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
5
4
  prerelease:
5
+ version: 0.0.5
6
6
  platform: ruby
7
7
  authors:
8
8
  - Sebastien Rosa
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-28 00:00:00.000000000 Z
12
+ date: 2013-01-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: rake
16
- requirement: &2153049320 !ruby/object:Gem::Requirement
17
- none: false
15
+ version_requirements: !ruby/object:Gem::Requirement
18
16
  requirements:
19
17
  - - ! '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: 0.8.7
20
+ none: false
21
+ name: rake
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *2153049320
25
- - !ruby/object:Gem::Dependency
26
- name: rspec
27
- requirement: &2153048540 !ruby/object:Gem::Requirement
24
+ requirement: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ! '>='
27
+ - !ruby/object:Gem::Version
28
+ version: 0.8.7
28
29
  none: false
30
+ - !ruby/object:Gem::Dependency
31
+ version_requirements: !ruby/object:Gem::Requirement
29
32
  requirements:
30
33
  - - ! '>='
31
34
  - !ruby/object:Gem::Version
32
35
  version: '2.0'
36
+ none: false
37
+ name: rspec
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *2153048540
36
- - !ruby/object:Gem::Dependency
37
- name: rspec-aspic
38
- requirement: &2153047200 !ruby/object:Gem::Requirement
40
+ requirement: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '2.0'
39
45
  none: false
46
+ - !ruby/object:Gem::Dependency
47
+ version_requirements: !ruby/object:Gem::Requirement
40
48
  requirements:
41
49
  - - ! '>='
42
50
  - !ruby/object:Gem::Version
43
51
  version: 0.0.2
52
+ none: false
53
+ name: rspec-aspic
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *2153047200
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: 0.0.2
61
+ none: false
47
62
  description: ''
48
63
  email:
49
64
  - sebastien@demarque.com
@@ -53,34 +68,34 @@ extra_rdoc_files:
53
68
  - LICENSE
54
69
  - README.md
55
70
  files:
56
- - data/README.md
57
71
  - data/regions.yml
58
- - languages/en.yml
72
+ - data/README.md
59
73
  - languages/fr.yml
60
- - lib/taxedo/builder/base.rb
61
- - lib/taxedo/builder/hash.rb
62
- - lib/taxedo/builder/html.rb
63
- - lib/taxedo/builder/json.rb
64
- - lib/taxedo/builder/price.rb
65
- - lib/taxedo/builder/text.rb
74
+ - languages/en.yml
75
+ - lib/taxedo/tax.rb
76
+ - lib/taxedo/receipt.rb
77
+ - lib/taxedo/implants.rb
66
78
  - lib/taxedo/builder.rb
67
- - lib/taxedo/implants/action_controller.rb
68
79
  - lib/taxedo/implants/railtie.rb
69
- - lib/taxedo/implants.rb
70
- - lib/taxedo/receipt.rb
80
+ - lib/taxedo/implants/action_controller.rb
71
81
  - lib/taxedo/region.rb
72
- - lib/taxedo/tax.rb
82
+ - lib/taxedo/builder/html.rb
83
+ - lib/taxedo/builder/hash.rb
84
+ - lib/taxedo/builder/base.rb
85
+ - lib/taxedo/builder/json.rb
86
+ - lib/taxedo/builder/text.rb
87
+ - lib/taxedo/builder/price.rb
73
88
  - lib/taxedo.rb
89
+ - spec/taxedo_spec.rb
74
90
  - spec/spec_helper.rb
75
- - spec/taxedo/builder/hash_spec.rb
76
- - spec/taxedo/builder/html_spec.rb
77
- - spec/taxedo/builder/json_spec.rb
78
- - spec/taxedo/builder/price_spec.rb
79
- - spec/taxedo/builder/text_spec.rb
80
91
  - spec/taxedo/receipt_spec.rb
81
92
  - spec/taxedo/region_spec.rb
82
93
  - spec/taxedo/tax_spec.rb
83
- - spec/taxedo_spec.rb
94
+ - spec/taxedo/builder/html_spec.rb
95
+ - spec/taxedo/builder/price_spec.rb
96
+ - spec/taxedo/builder/hash_spec.rb
97
+ - spec/taxedo/builder/text_spec.rb
98
+ - spec/taxedo/builder/json_spec.rb
84
99
  - LICENSE
85
100
  - README.md
86
101
  - Rakefile
@@ -93,20 +108,20 @@ rdoc_options: []
93
108
  require_paths:
94
109
  - lib
95
110
  required_ruby_version: !ruby/object:Gem::Requirement
96
- none: false
97
111
  requirements:
98
112
  - - ! '>='
99
113
  - !ruby/object:Gem::Version
100
114
  version: '0'
101
- required_rubygems_version: !ruby/object:Gem::Requirement
102
115
  none: false
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
117
  requirements:
104
118
  - - ! '>='
105
119
  - !ruby/object:Gem::Version
106
120
  version: '0'
121
+ none: false
107
122
  requirements: []
108
123
  rubyforge_project: taxedo
109
- rubygems_version: 1.8.17
124
+ rubygems_version: 1.8.24
110
125
  signing_key:
111
126
  specification_version: 3
112
127
  summary: ''