Module: SK::Calc::Item
- Includes:
- Helper
- 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
Class Method Summary collapse
Instance Method Summary collapse
-
#discount_total ⇒ BigDecimal
The discount amount.
-
#discount_total_4 ⇒ BigDecimal
The discount amount.
-
#discount_total_base ⇒ BigDecimal
The discount amount unrounded.
-
#gross_single ⇒ BigDecimal
Single gross price rounded 2.
-
#gross_single_4 ⇒ BigDecimal
Single gross price rounded 2.
- #gross_single_base ⇒ Object
-
#gross_total ⇒ BigDecimal
Total gross price incl.
-
#gross_total_4 ⇒ BigDecimal
Total gross price incl.
-
#gross_total_base ⇒ BigDecimal
Total gross price incl.
-
#net_single ⇒ BigDecimal
Single net price with discount applied rounded 2.
-
#net_single_4 ⇒ BigDecimal
Single net price with discount applied rounded 2.
-
#net_single_base ⇒ BigDecimal
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 ⇒ BigDecimal
Total net price(2 decimals) incl.
-
#net_total_4 ⇒ BigDecimal
Total net price.
-
#net_total_base ⇒ BigDecimal
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 ⇒ BigDecimal
Rounded 2 decimals.
-
#tax_total_4 ⇒ BigDecimal
Rounded 4 decimals.
-
#tax_total_base ⇒ BigDecimal
Total amount of tax.
-
#total ⇒ BigDecimal
Unrounded item total price * quantity, excl discount Use it to do calculations!.
Class Method Details
.round_mode ⇒ Object
35 36 37 |
# File 'lib/sk_calc/item.rb', line 35 def self.round_mode @rmd || BigDecimal::ROUND_HALF_UP end |
.round_mode=(mode) ⇒ Object
38 39 40 |
# File 'lib/sk_calc/item.rb', line 38 def self.round_mode=(mode) @rmd = mode end |
Instance Method Details
#discount_total ⇒ BigDecimal
The discount amount
119 120 121 |
# File 'lib/sk_calc/item.rb', line 119 def discount_total discount_total_base.round(2) end |
#discount_total_4 ⇒ BigDecimal
The discount amount
166 167 168 |
# File 'lib/sk_calc/item.rb', line 166 def discount_total_4 discount_total_base.round(4) end |
#discount_total_base ⇒ BigDecimal
The discount amount unrounded
82 83 84 |
# File 'lib/sk_calc/item.rb', line 82 def discount_total_base total * (conv_discount / 100) end |
#gross_single ⇒ BigDecimal
Single gross price rounded 2. DONT use this method to calculate(eg. totals for a document) use net_total or gross_total instead
135 136 137 |
# File 'lib/sk_calc/item.rb', line 135 def gross_single gross_single_base.round(2) end |
#gross_single_4 ⇒ BigDecimal
Single gross price rounded 2. DONT use this method to calculate(eg. totals for a document) use net_total or gross_total instead
183 184 185 |
# File 'lib/sk_calc/item.rb', line 183 def gross_single_4 gross_single_base.round(4) end |
#gross_single_base ⇒ Object
70 71 72 |
# File 'lib/sk_calc/item.rb', line 70 def gross_single_base net_single_base * ( 1 + conv_tax / 100) end |
#gross_total ⇒ BigDecimal
Total gross price incl. discount
102 103 104 |
# File 'lib/sk_calc/item.rb', line 102 def gross_total gross_total_base.round(2) end |
#gross_total_4 ⇒ BigDecimal
Total gross price incl. discount
148 149 150 |
# File 'lib/sk_calc/item.rb', line 148 def gross_total_4 gross_total_base.round(4) end |
#gross_total_base ⇒ BigDecimal
Total gross price incl. discount
76 77 78 |
# File 'lib/sk_calc/item.rb', line 76 def gross_total_base net_total_base + tax_total_base end |
#net_single ⇒ BigDecimal
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
127 128 129 |
# File 'lib/sk_calc/item.rb', line 127 def net_single net_single_base.round(2) end |
#net_single_4 ⇒ BigDecimal
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
175 176 177 |
# File 'lib/sk_calc/item.rb', line 175 def net_single_4 net_single_base.round(4) end |
#net_single_base ⇒ BigDecimal
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
66 67 68 |
# File 'lib/sk_calc/item.rb', line 66 def net_single_base conv_price_single * ( 1 - (conv_discount / 100 ) ) end |
#net_total ⇒ BigDecimal
Total net price(2 decimals) incl. discount
108 109 110 |
# File 'lib/sk_calc/item.rb', line 108 def net_total net_total_base.round(2) end |
#net_total_4 ⇒ BigDecimal
Total net price
154 155 156 |
# File 'lib/sk_calc/item.rb', line 154 def net_total_4 net_total_base.round(4) end |
#net_total_base ⇒ BigDecimal
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
53 54 55 |
# File 'lib/sk_calc/item.rb', line 53 def net_total_base (100 - conv_discount) * total / 100 end |
#tax_total ⇒ BigDecimal
Returns rounded 2 decimals.
113 114 115 |
# File 'lib/sk_calc/item.rb', line 113 def tax_total tax_total_base.round(2) end |
#tax_total_4 ⇒ BigDecimal
Returns rounded 4 decimals.
160 161 162 |
# File 'lib/sk_calc/item.rb', line 160 def tax_total_4 tax_total_base.round(4) end |
#tax_total_base ⇒ BigDecimal
Returns total amount of tax.
58 59 60 |
# File 'lib/sk_calc/item.rb', line 58 def tax_total_base (net_total_base * conv_tax) / 100 end |
#total ⇒ BigDecimal
Unrounded item total price * quantity, excl discount Use it to do calculations!
89 90 91 |
# File 'lib/sk_calc/item.rb', line 89 def total conv_price_single * ( quantity || 0) end |