Skip to content

Instantly share code, notes, and snippets.

@joshuamiller
Created April 26, 2011 19:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshuamiller/942864 to your computer and use it in GitHub Desktop.
Save joshuamiller/942864 to your computer and use it in GitHub Desktop.
def total
line_items.map {|i| i.price.to_f * i.quantity.to_i }.sum *
(1.0 - quantity_discount)
end
def remaining_total
total - payments.map(&:amount).compact.sum
end
def quantity_discount
return 0 unless catalog.quantity_discounts.present?
pieces = line_items.map {|i| i.quantity.to_i}.sum
catalog.quantity_discounts.select do |qty, discount|
qty < pieces
end.max.try(:[], 1) || 0
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment