Class: Workarea::Pricing::Discount::BuySomeGetSome::ItemApplication

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_quantityObject (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_totalMoney

The item total before this discount is applied.

Returns:



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_totalMoney

The total price of the portion of units that get the discount applied.

Returns:



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_quantityInteger

The portion of the total quantity that should be charged a standard price without discount applied.

Returns:

  • (Integer)


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_totalMoney

The total price of the number of units that get charged the pre-buy-some-get-some-discount price.

Returns:



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

#valueMoney

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.

Returns:



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