sk_calc 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.gitignore +2 -0
- data/lib/sk_calc/helper.rb +1 -1
- data/lib/sk_calc/item.rb +10 -3
- data/lib/sk_calc/items.rb +4 -4
- data/lib/sk_calc/version.rb +1 -1
- data/spec/sk_calc/item_spec.rb +16 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
OWQ1Njk0NmNiZjk0NjM0OWUzMDA1NDMxMWIwMjZmZGQ0OGFiYjEyNg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YTNjOWU4YTViMmZiYjkwYTU0YWFiOWFhMGQ0OGUzMmI2ODM1ZDM0OA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MDk2NWU1ZjVmYjg4NjgzYTk3MTVmMTUxOWJmZTNiYzZjZjg1ZWY5YmIwZTQ4
|
10
|
+
NGIyMjU4Y2Q0ZmUyYmFkZjc3MzExYmE2MTBmNWNjNDcyNTFkMzA1NGFkN2Vj
|
11
|
+
YTk2YTk5Yzk3NjEzODMxZDljNzQxMDBiZDUxZjQ2MTgxMWFiYzQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZTYzODNiZTI5ZWQ0NjdhYzA0ZjY3ZjEwZTRiZTA1ZDlhMWZiMjEzMTFhYjQ0
|
14
|
+
ODBhMDRjZjg4MmEwMjZmZjMyYjI4MTY2NWNlNjM5ZjY3MDc4YzA3NmRlYzQ0
|
15
|
+
NjY3N2E5NzU4ZWY3NzdhZjUyYjU4MGRiMjY1YTcwNjgxN2FiNDM=
|
data/.gitignore
CHANGED
data/lib/sk_calc/helper.rb
CHANGED
data/lib/sk_calc/item.rb
CHANGED
@@ -51,7 +51,7 @@ module SK::Calc::Item
|
|
51
51
|
# used to output the rounded & formatted values
|
52
52
|
# @return [BigDecimal]
|
53
53
|
def net_total_base
|
54
|
-
(100 -
|
54
|
+
(100 - conv_discount) * total / 100
|
55
55
|
end
|
56
56
|
|
57
57
|
# @return [BigDecimal] total amount of tax
|
@@ -64,7 +64,7 @@ module SK::Calc::Item
|
|
64
64
|
# or gross_total instead
|
65
65
|
# @return [BigDecimal] rounded 2 decimals
|
66
66
|
def net_single_base
|
67
|
-
conv_price_single * ( 1 - (
|
67
|
+
conv_price_single * ( 1 - (conv_discount / 100 ) )
|
68
68
|
end
|
69
69
|
|
70
70
|
def gross_single_base
|
@@ -80,7 +80,7 @@ module SK::Calc::Item
|
|
80
80
|
# The discount amount unrounded
|
81
81
|
# @return [BigDecimal] rounded
|
82
82
|
def discount_total_base
|
83
|
-
total * (
|
83
|
+
total * (conv_discount / 100)
|
84
84
|
end
|
85
85
|
|
86
86
|
# Unrounded item total price * quantity, excl discount
|
@@ -192,4 +192,11 @@ module SK::Calc::Item
|
|
192
192
|
to_bd(price_single || 0)
|
193
193
|
end
|
194
194
|
|
195
|
+
# Init discount with 0 gracefully ignores if it is not defined.
|
196
|
+
# If nil and cast to BigDecimal
|
197
|
+
# @return [BigDecimal]
|
198
|
+
def conv_discount
|
199
|
+
to_bd( (self.respond_to?(:discount) && discount) || 0)
|
200
|
+
end
|
201
|
+
|
195
202
|
end
|
data/lib/sk_calc/items.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# Calculate totals for a multiple items eg in an invoice
|
2
2
|
# Including class MUST respond to:
|
3
|
-
# - price_total
|
4
|
-
# - price_tax
|
3
|
+
# - price_total: the sum of all items net totals, you must call #sum_items yourself to fill this and price tax
|
4
|
+
# - price_tax: the tax total for all items
|
5
5
|
# - line_items
|
6
6
|
module SK::Calc::Items
|
7
7
|
include SK::Calc::Helper
|
8
8
|
|
9
|
-
# Unrounded net total the taxation base
|
9
|
+
# Unrounded net total which is the sum of all items net_total, the taxation base
|
10
10
|
# @return [BigDecimal]
|
11
11
|
def net_total_base
|
12
12
|
conv_price_total
|
@@ -94,7 +94,7 @@ module SK::Calc::Items
|
|
94
94
|
|
95
95
|
private
|
96
96
|
|
97
|
-
# Init
|
97
|
+
# Init total with 0 if nil and cast to BigDecimal
|
98
98
|
# @return [BigDecimal]
|
99
99
|
def conv_price_total
|
100
100
|
to_bd(price_total || 0)
|
data/lib/sk_calc/version.rb
CHANGED
data/spec/sk_calc/item_spec.rb
CHANGED
@@ -6,8 +6,24 @@ class LineItem
|
|
6
6
|
calculates :item
|
7
7
|
end
|
8
8
|
|
9
|
+
class ItemWithoutFields
|
10
|
+
include SK::Calc
|
11
|
+
attr_accessor :price_single, :quantity
|
12
|
+
calculates :item
|
13
|
+
end
|
14
|
+
|
9
15
|
describe SK::Calc do
|
10
16
|
|
17
|
+
describe 'optional fields' do
|
18
|
+
it 'should have conv_tax' do
|
19
|
+
i = ItemWithoutFields.new
|
20
|
+
i.conv_tax.should == 0
|
21
|
+
end
|
22
|
+
it 'should have conv_discount' do
|
23
|
+
i = ItemWithoutFields.new
|
24
|
+
i.conv_discount.should == 0
|
25
|
+
end
|
26
|
+
end
|
11
27
|
describe 'item calculations' do
|
12
28
|
|
13
29
|
before :each do
|