Class: Item

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

Instance Method Summary collapse

Instance Method Details

#discountObject

relation of price to product price down from 100 %



29
30
31
32
# File 'app/models/item.rb', line 29

def discount
  return 0 unless product.price and product.price != 0
  (100 - (price/product.price)*100).round(0)
end

#productObject



12
13
14
# File 'app/models/item.rb', line 12

def product
  Product.unscoped.find self.product_id
end

#profitObject

profit is off course the sale price minus the cost but . .. while the sale price is copied to the item and thus remains correct when the cost changes over time, so does this “profit”.



24
25
26
# File 'app/models/item.rb', line 24

def profit
  (self.price - self.product.cost) * self.quantity
end

#single_item_taxObject



34
35
36
# File 'app/models/item.rb', line 34

def single_item_tax
  (self.price * self.tax / ( 100.0 + self.tax)).round(4)
end

#tax_amountObject

tax included in the total



17
18
19
# File 'app/models/item.rb', line 17

def tax_amount
  self.quantity * single_item_tax
end

#totalObject

total price, ie quantity times price



8
9
10
# File 'app/models/item.rb', line 8

def total
  self.price * self.quantity
end