Created
April 26, 2011 19:00
-
-
Save joshuamiller/942864 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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