Class: Caboose::Discount

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/caboose/discount.rb

Instance Method Summary collapse

Instance Method Details

#calculate_amountObject


17
18
19
20
21
22
23
24
25
26
# File 'app/models/caboose/discount.rb', line 17

def calculate_amount                                
  gc = self.gift_card      
  self.amount = case self.gift_card.card_type
    when GiftCard::CARD_TYPE_AMOUNT      then (self.invoice.total >= gc.balance ? gc.balance : self.invoice.total)
    when GiftCard::CARD_TYPE_PERCENTAGE  then self.invoice.subtotal * gc.total
    when GiftCard::CARD_TYPE_NO_SHIPPING then self.invoice.shipping
    when GiftCard::CARD_TYPE_NO_TAX      then self.invoice.tax
  end
  self.save
end