sk_calc 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- OWMxYjkzZDAwNGY2ZDk3ZjIwZDkxZTllNTkzZDliOTc1ZThiNGJjYg==
5
- data.tar.gz: !binary |-
6
- NDk4YmZjYzRjZTc4OGEyMjI1OTc5YzJhZWFjNGQ5NTFkNWQ1OTYwNg==
2
+ SHA1:
3
+ metadata.gz: 51ac1e01d1ba2a985d6b255cf9fd29ba85894154
4
+ data.tar.gz: e02b10b0129c7fa310aeeca46c131b0a7f60613d
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- MWYyMDU5NDkwMjYwMjJmNGI1YWVhNWI3YzA3ODM2YTJjMmYxMmRiNWY5M2Y4
10
- YjRiYzQ0MTAzNmRlNzI1ZGE1MmQwMDBhMjhjZTM0NWMzZDBhMDNkM2FiM2Yw
11
- YTYxNGFlNjUxNWZjYjM4MGU4ODk3MTJiYWRkMzQwNTlhMTk3MDQ=
12
- data.tar.gz: !binary |-
13
- ZTYzYTA1OTU4YjA3YzViZTQzODRhZTY3NmQ3MDc2MGU4ZTBlZWZjNjkyNmU3
14
- N2NhNzYxZjg5ZmMxZjc2ZjE5M2EwZTI0MTlmNWIxNGFiYjVmM2U4MDJiNTc5
15
- OTRkYjdjNTFmYzM3NTE3ZThjMzRmYzU5MjkwM2Y3ZjAyMmY3NjQ=
6
+ metadata.gz: ff9cd7c68678c4c64e061adc80cd995271d03f4b7aa2aaec58bc762c3b07b2660ce3b7364bc469c9087ef48ed02eb660c31fbdd06193a081652cd3eae6c61227
7
+ data.tar.gz: 24958ad3c941142f8b49ca42b3eb53cf61a2c44115e15961e60744b734a652a59b3024d314f99a47ad0e22f8da9e8dbda6fe5bcbf7cd14b91813a597491de9b3
data/.travis.yml CHANGED
@@ -1,3 +1,3 @@
1
1
  rvm:
2
- - 1.9.3
2
+ - 2.3
3
3
  - 2.2
data/README.md CHANGED
@@ -16,6 +16,8 @@ mixing it into your local classes.
16
16
 
17
17
  == Install
18
18
 
19
+ Ruby 2.2 tested, 1.9 should work to
20
+
19
21
  gem install sk_calc
20
22
 
21
23
 
@@ -34,4 +36,4 @@ read spec/sk_calc/*.rb to see examples
34
36
 
35
37
  == Tests
36
38
 
37
- Copyright (c) 2011-2016 Georg Leciejewski, released under the MIT license
39
+ Copyright (c) 2011-2024 Georg Leciejewski, released under the MIT license
data/lib/sk_calc/items.rb CHANGED
@@ -67,7 +67,7 @@ module SK::Calc::Items
67
67
  # [1] => 57 #(items sum = 300)
68
68
  #
69
69
  #
70
- # @return [Hash]
70
+ # @return [Array<Array>]
71
71
  def tax_grouped(items=nil)
72
72
  items ||= line_items
73
73
  result = {}
@@ -78,6 +78,27 @@ module SK::Calc::Items
78
78
  result.sort
79
79
  end
80
80
 
81
+ # @return [Array<Hash<Symbol,Mixed>>]
82
+ def tax_grouped_details(items=nil)
83
+ items ||= line_items
84
+ result = []
85
+ items.group_by(&:tax).each do |tax, item_group|
86
+ net_total_sum = item_group.to_a.sum(&:net_total_base)
87
+ tax_total = if tax && !tax.zero?
88
+ (net_total_sum * tax.to_r / 100.0).round(SK::Calc.precision)
89
+ else
90
+ 0.0
91
+ end
92
+ result << {
93
+ tax: tax,
94
+ net_total: net_total_sum,
95
+ gross_total: net_total_sum+tax_total,
96
+ tax_total: tax_total,
97
+ }
98
+ end
99
+ result.sort{|a,b| a[:tax] <=> b[:tax]}
100
+ end
101
+
81
102
  private
82
103
 
83
104
  # Init total with 0 if nil and cast to Rational
@@ -1,5 +1,5 @@
1
1
  module SK
2
2
  module Calc
3
- VERSION = '1.0.2'
3
+ VERSION = '1.0.3'
4
4
  end
5
5
  end
@@ -17,28 +17,28 @@ describe SK::Calc do
17
17
  describe 'private convert methods' do
18
18
  it 'conv_tax' do
19
19
  i = ItemWithoutFields.new
20
- i.send(:conv_tax).should == 0
20
+ expect(i.send(:conv_tax)).to eq 0
21
21
  end
22
22
  it 'conv_price_single' do
23
23
  i = ItemWithoutFields.new
24
- i.send(:conv_price_single).should == 0
24
+ expect(i.send(:conv_price_single)).to eq 0
25
25
  end
26
26
 
27
27
  it 'rounds to max 6 conv_price_single' do
28
28
  i = ItemWithoutFields.new
29
29
  i.price_single = 1.12345678
30
- i.send(:conv_price_single).to_f.should == 1.123457
30
+ expect(i.send(:conv_price_single).to_f).to eq 1.123457
31
31
  end
32
32
 
33
33
  it 'conv_discount' do
34
34
  i = ItemWithoutFields.new
35
- i.send(:conv_discount).should == 0
35
+ expect(i.send(:conv_discount)).to eq 0
36
36
  end
37
37
 
38
38
  it 'conv_quantity' do
39
39
  i = ItemWithoutFields.new
40
- i.send(:conv_quantity).should == 0
41
- i.send(:conv_quantity).should be_a Rational
40
+ expect(i.send(:conv_quantity)).to eq 0
41
+ expect(i.send(:conv_quantity)).to be_a Rational
42
42
  end
43
43
  end
44
44
 
@@ -53,31 +53,31 @@ describe SK::Calc do
53
53
  end
54
54
 
55
55
  it "has net_single" do
56
- @i.net_single.should == 10.00
56
+ expect(@i.net_single).to eq 10.00
57
57
  end
58
58
 
59
59
  it "has gross_single" do
60
- @i.gross_single.should == 11.90
60
+ expect(@i.gross_single).to eq 11.90
61
61
  end
62
62
 
63
63
  it "has total" do
64
- @i.total.should == 10.0
64
+ expect(@i.total).to eq 10.0
65
65
  end
66
66
 
67
67
  it "has net_total" do
68
- @i.net_total.should == 10.0
68
+ expect(@i.net_total).to eq 10.0
69
69
  end
70
70
 
71
71
  it "has gross_total" do
72
- @i.gross_total.should == 11.90
72
+ expect(@i.gross_total).to eq 11.90
73
73
  end
74
74
 
75
75
  it "has net_total_base" do
76
- @i.net_total_base.should == 10.00
76
+ expect(@i.net_total_base).to eq 10.00
77
77
  end
78
78
 
79
79
  it "has tax_total" do
80
- @i.tax_total.should == 1.90
80
+ expect(@i.tax_total).to eq 1.90
81
81
  end
82
82
  end
83
83
 
@@ -92,30 +92,30 @@ describe SK::Calc do
92
92
  end
93
93
 
94
94
  it "has total" do
95
- @i.total.should == 12.605
95
+ expect(@i.total).to eq 12.605
96
96
  end
97
97
 
98
98
  it "has net_total" do
99
- @i.net_total.to_f.should == 12.61
99
+ expect(@i.net_total.to_f).to eq 12.61
100
100
  end
101
101
 
102
102
  it "has gross_total" do
103
- @i.gross_total.should == 15.0
103
+ expect(@i.gross_total).to eq 15.0
104
104
  end
105
105
 
106
106
  it "has net_total_base" do
107
- @i.net_total_base.should == 12.605
107
+ expect(@i.net_total_base).to eq 12.605
108
108
  end
109
109
  it "has net_total" do
110
- @i.net_total.should == 12.61
110
+ expect(@i.net_total).to eq 12.61
111
111
  end
112
112
 
113
113
  it "has tax_total_base" do
114
- @i.tax_total_base.should == 2.39495
114
+ expect(@i.tax_total_base).to eq 2.39495
115
115
  end
116
116
 
117
117
  it "has tax_total" do
118
- @i.tax_total.should == 2.39
118
+ expect(@i.tax_total).to eq 2.39
119
119
  end
120
120
  end
121
121
 
@@ -125,8 +125,8 @@ describe SK::Calc do
125
125
  i = LineItem.new
126
126
  i.price_single = 12345.123456
127
127
  i.quantity = BigDecimal.new("1.0")
128
- i.total.should == 12345.123456
129
- i.total.should be_a Rational
128
+ expect(i.total).to eq 12345.123456
129
+ expect(i.total).to be_a Rational
130
130
  end
131
131
  end
132
132
 
@@ -27,26 +27,50 @@ describe SK::Calc, 'items calculations' do
27
27
 
28
28
  it "calc net_total" do
29
29
  @doc.sum_items
30
- @doc.net_total.should == 10.0
30
+ expect(@doc.net_total).to eq 10.0
31
31
  end
32
32
 
33
33
  it "calc gross_total" do
34
34
  @doc.sum_items
35
- @doc.gross_total.should == 11.90
35
+ expect(@doc.gross_total).to eq 11.90
36
36
  end
37
37
 
38
38
  it "sums totals" do
39
39
  @doc.sum_items
40
- @doc.price_total.should == 10.0
41
- @doc.price_tax.should == 1.90
40
+ expect(@doc.price_total).to eq 10.0
41
+ expect(@doc.price_tax).to eq 1.90
42
42
  end
43
43
 
44
44
  it "sums items with tax as rational" do
45
45
  @i.price_single = 7142.857143
46
46
  @i.tax = BigDecimal('19.0')
47
47
  @doc.sum_items
48
- @doc.price_total.should == 7142.857143
49
- @doc.price_tax.should == 1357.142857
50
- @doc.gross_total.should == 8500.00
48
+ expect(@doc.price_total).to eq 7142.857143
49
+ expect(@doc.price_tax).to eq 1357.142857
50
+ expect(@doc.gross_total).to eq 8500.00
51
51
  end
52
+
53
+ it "tax_grouped" do
54
+ @i.price_single = 7142.857143
55
+ @i.tax = BigDecimal('19.0')
56
+ res = @doc.tax_grouped
57
+ expect(res).to eq [[19.0, 1357.142857]]
58
+ end
59
+
60
+
61
+ it "tax_grouped_details" do
62
+ b = LineItem.new
63
+ b.tax=7.0
64
+ b.quantity=10
65
+ b.price_single=10
66
+ b.discount=0
67
+
68
+ @doc.line_items << b
69
+
70
+ res = @doc.tax_grouped_details
71
+ expect(res[0]).to eq( {net_total: 100.0, tax: 7.0, tax_total: 7.0, gross_total:107.0})
72
+ expect(res[1]).to eq( {net_total:10, tax:19.0, tax_total:1.9, gross_total:11.9})
73
+ end
74
+
75
+
52
76
  end
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sk_calc
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Georg Leciejewski
8
8
  - Mike Połtyn
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
  date: 2012-02-15 00:00:00.000000000 Z
@@ -15,56 +15,56 @@ dependencies:
15
15
  name: rspec
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - ! '>='
18
+ - - ">="
19
19
  - !ruby/object:Gem::Version
20
20
  version: '0'
21
21
  type: :development
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - ! '>='
25
+ - - ">="
26
26
  - !ruby/object:Gem::Version
27
27
  version: '0'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: simplecov
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - ! '>='
32
+ - - ">="
33
33
  - !ruby/object:Gem::Version
34
34
  version: '0'
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - ! '>='
39
+ - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: activesupport
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - ! '>='
46
+ - - ">="
47
47
  - !ruby/object:Gem::Version
48
48
  version: '0'
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - ! '>='
53
+ - - ">="
54
54
  - !ruby/object:Gem::Version
55
55
  version: '0'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: rake
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
- - - ! '>='
60
+ - - ">="
61
61
  - !ruby/object:Gem::Version
62
62
  version: 0.9.2
63
63
  type: :development
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
- - - ! '>='
67
+ - - ">="
68
68
  - !ruby/object:Gem::Version
69
69
  version: 0.9.2
70
70
  description: Calculate document and line item totals. This moule is used inside SalesKIng
@@ -74,8 +74,8 @@ executables: []
74
74
  extensions: []
75
75
  extra_rdoc_files: []
76
76
  files:
77
- - .gitignore
78
- - .travis.yml
77
+ - ".gitignore"
78
+ - ".travis.yml"
79
79
  - Gemfile
80
80
  - LICENSE
81
81
  - README.md
@@ -91,24 +91,24 @@ files:
91
91
  homepage: http://github.com/salesking/sk_calc
92
92
  licenses: []
93
93
  metadata: {}
94
- post_install_message:
94
+ post_install_message:
95
95
  rdoc_options: []
96
96
  require_paths:
97
97
  - lib
98
98
  required_ruby_version: !ruby/object:Gem::Requirement
99
99
  requirements:
100
- - - ! '>='
100
+ - - ">="
101
101
  - !ruby/object:Gem::Version
102
102
  version: '0'
103
103
  required_rubygems_version: !ruby/object:Gem::Requirement
104
104
  requirements:
105
- - - ! '>='
105
+ - - ">="
106
106
  - !ruby/object:Gem::Version
107
107
  version: '0'
108
108
  requirements: []
109
- rubyforge_project:
110
- rubygems_version: 2.2.2
111
- signing_key:
109
+ rubyforge_project:
110
+ rubygems_version: 2.4.5.5
111
+ signing_key:
112
112
  specification_version: 4
113
113
  summary: SalesKing Calculation Module
114
114
  test_files: []