accounts and discount updated

This commit is contained in:
Yan
2017-06-23 17:05:08 +06:30
parent 55c8ab80da
commit 3a0e26b2ea
14 changed files with 114 additions and 59 deletions

View File

@@ -30,9 +30,24 @@ class SaleItem < ApplicationRecord
# end
end
# Calculate food total and beverage total
def self.calculate_food_beverage(sale_items)
def self.calculate_price_by_accounts(sale_items)
price_accounts = []
Account.all.each do |a|
account_price = {:name => a.title, :price => 0}
sale_items.each do |si|
if si.account_id == a.id
account_price[:price] = account_price[:price] + si.price
end
end
price_accounts.push(account_price)
end
return price_accounts
end
# Calculate rebate_by_account
def self.calculate_rebate_by_account(sale_items)
rebateacc = Account.where("rebate=?",true)
puts "Account that can rebate"
rebateacc.each do |i|
@@ -40,7 +55,7 @@ class SaleItem < ApplicationRecord
end
prices=0
sale_items.each do |si|
price = self.get_price(si.sale_item_id,rebateacc)
price = self.get_rebate_price(si.sale_item_id,rebateacc)
prices = prices + price
end
@@ -48,7 +63,7 @@ class SaleItem < ApplicationRecord
end
# get food price or beverage price for item
def self.get_price(sale_item_id,rebateacc)
def self.get_rebate_price(sale_item_id,rebateacc)
price=0
item=SaleItem.select("sale_items.price , menu_items.account_id")