Module: SK::Calc::Item
- Defined in:
- lib/sk_calc/item.rb
Overview
Calculate totals for a single item Including class MUST respond to:
-
discount
-
price_single
-
quantity
-
tax
Information
base data
price_single
quantity
discount %
tax %
unrounded calculations
total price_single * quantity
net_total_base total * discount
tax_total_base net_total_base * tax
rounded calculations
net_total
tax_total
gross_total
informative: should not be used in totals calc
net_single
gross_single
discount_total
Instance Method Summary collapse
-
#discount_total ⇒ Rational
The discount amount.
-
#discount_total_base ⇒ Rational
The discount amount unrounded.
-
#gross_single ⇒ Rational
Single gross price rounded 2.
- #gross_single_base ⇒ Object
-
#gross_total ⇒ Rational
Total gross price incl.
-
#gross_total_base ⇒ Rational
Total gross price incl.
-
#net_single ⇒ Rational
Single net price with discount applied rounded 2.
-
#net_single_base ⇒ Rational
Single net price with discount applied DO NOT use this method to calculate(eg. totals for a document) use net_total or gross_total instead.
-
#net_total ⇒ Rational
Total net price(2 decimals) incl.
-
#net_total_base ⇒ Rational
Total unrounded net basis incl discount Use this internally to do calculations! Differs from net_total_base which is used to output the rounded & formatted values.
-
#tax_total ⇒ Rational
Rounded 2 decimals.
-
#tax_total_base ⇒ Rational
Total amount of tax.
-
#total ⇒ Rational
Unrounded item total price * quantity, excl discount Use it to do calculations!.
Instance Method Details
#discount_total ⇒ Rational
The discount amount
111 112 113 |
# File 'lib/sk_calc/item.rb', line 111 def discount_total discount_total_base.round(2) end |
#discount_total_base ⇒ Rational
The discount amount unrounded
74 75 76 |
# File 'lib/sk_calc/item.rb', line 74 def discount_total_base total * (conv_discount / 100) end |
#gross_single ⇒ Rational
Single gross price rounded 2. DONT use this method to calculate(eg. totals for a document) use net_total or gross_total instead
127 128 129 |
# File 'lib/sk_calc/item.rb', line 127 def gross_single gross_single_base.round(2) end |
#gross_single_base ⇒ Object
62 63 64 |
# File 'lib/sk_calc/item.rb', line 62 def gross_single_base net_single_base * ( 1 + conv_tax / 100) end |
#gross_total ⇒ Rational
Total gross price incl. discount
94 95 96 |
# File 'lib/sk_calc/item.rb', line 94 def gross_total gross_total_base.round(2) end |
#gross_total_base ⇒ Rational
Total gross price incl. discount
68 69 70 |
# File 'lib/sk_calc/item.rb', line 68 def gross_total_base net_total_base + tax_total_base end |
#net_single ⇒ Rational
Single net price with discount applied rounded 2. DO NOT use this method to calculate(eg. totals for a document) use net_total or gross_total instead
119 120 121 |
# File 'lib/sk_calc/item.rb', line 119 def net_single net_single_base.round(2) end |
#net_single_base ⇒ Rational
Single net price with discount applied DO NOT use this method to calculate(eg. totals for a document) use net_total or gross_total instead
58 59 60 |
# File 'lib/sk_calc/item.rb', line 58 def net_single_base conv_price_single * ( 1 - (conv_discount / 100 ) ) end |
#net_total ⇒ Rational
Total net price(2 decimals) incl. discount
100 101 102 |
# File 'lib/sk_calc/item.rb', line 100 def net_total net_total_base.round(2) end |
#net_total_base ⇒ Rational
Total unrounded net basis incl discount Use this internally to do calculations! Differs from net_total_base which is used to output the rounded & formatted values
45 46 47 |
# File 'lib/sk_calc/item.rb', line 45 def net_total_base (100 - conv_discount) * total / 100 end |
#tax_total ⇒ Rational
105 106 107 |
# File 'lib/sk_calc/item.rb', line 105 def tax_total tax_total_base.round(2) end |
#tax_total_base ⇒ Rational
50 51 52 |
# File 'lib/sk_calc/item.rb', line 50 def tax_total_base (net_total_base * conv_tax) / 100 end |
#total ⇒ Rational
Unrounded item total price * quantity, excl discount Use it to do calculations!
81 82 83 |
# File 'lib/sk_calc/item.rb', line 81 def total conv_price_single * conv_quantity end |