Class: Workarea::Pricing::Discount::BuySomeGetSome::ItemApplication
- Inherits:
-
Object
- Object
- Workarea::Pricing::Discount::BuySomeGetSome::ItemApplication
- Defined in:
- app/models/workarea/pricing/discount/buy_some_get_some/item_application.rb
Overview
This class is responsible for apply the discount results to a particular Order::Item.
Instance Attribute Summary collapse
-
#apply_quantity ⇒ Object
readonly
Returns the value of attribute apply_quantity.
Instance Method Summary collapse
-
#current_total ⇒ Money
The item total before this discount is applied.
-
#discounted_units_total ⇒ Money
The total price of the portion of units that get the discount applied.
-
#initialize(discount, item, apply_quantity) ⇒ ItemApplication
constructor
A new instance of ItemApplication.
-
#standard_quantity ⇒ Integer
The portion of the total quantity that should be charged a standard price without discount applied.
-
#standard_units_total ⇒ Money
The total price of the number of units that get charged the pre-buy-some-get-some-discount price.
-
#value ⇒ Money
The total value of this discount on this item, calculated as the total pre-discount and the total of standard units and the discounted units.
Constructor Details
#initialize(discount, item, apply_quantity) ⇒ ItemApplication
Returns a new instance of ItemApplication.
10 11 12 13 14 |
# File 'app/models/workarea/pricing/discount/buy_some_get_some/item_application.rb', line 10 def initialize(discount, item, apply_quantity) @discount = discount @item = item @apply_quantity = apply_quantity end |
Instance Attribute Details
#apply_quantity ⇒ Object (readonly)
Returns the value of attribute apply_quantity.
8 9 10 |
# File 'app/models/workarea/pricing/discount/buy_some_get_some/item_application.rb', line 8 def apply_quantity @apply_quantity end |
Instance Method Details
#current_total ⇒ Money
The item total before this discount is applied.
20 21 22 |
# File 'app/models/workarea/pricing/discount/buy_some_get_some/item_application.rb', line 20 def current_total @item.price_adjustments.adjusting('item').sum end |
#discounted_units_total ⇒ Money
The total price of the portion of units that get the discount applied.
47 48 49 |
# File 'app/models/workarea/pricing/discount/buy_some_get_some/item_application.rb', line 47 def discounted_units_total @item.current_unit_price * @apply_quantity * @discount.percent end |
#standard_quantity ⇒ Integer
The portion of the total quantity that should be charged a standard price without discount applied.
29 30 31 |
# File 'app/models/workarea/pricing/discount/buy_some_get_some/item_application.rb', line 29 def standard_quantity @item.quantity - @apply_quantity end |
#standard_units_total ⇒ Money
The total price of the number of units that get charged the pre-buy-some-get-some-discount price.
38 39 40 |
# File 'app/models/workarea/pricing/discount/buy_some_get_some/item_application.rb', line 38 def standard_units_total @item.current_unit_price * standard_quantity end |
#value ⇒ Money
The total value of this discount on this item, calculated as the total pre-discount and the total of standard units and the discounted units.
57 58 59 60 61 |
# File 'app/models/workarea/pricing/discount/buy_some_get_some/item_application.rb', line 57 def value @value ||= current_total - standard_units_total - discounted_units_total end |