update membership rebate for food and beverage

This commit is contained in:
Aung Myo
2017-07-18 18:05:27 +06:30
parent bd0b8681c9
commit 0ce6bc733b
5 changed files with 136 additions and 46 deletions

View File

@@ -66,26 +66,32 @@ class SaleItem < ApplicationRecord
return discount_accounts
end
# Calculate rebate_by_account
# 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|
puts i.title
end
prices=0
sale_items.each do |si|
price = self.get_rebate_price(si.sale_item_id,rebateacc)
price = 0
rebate_arr = []
rebateacc.each do |a|
account_price = {:type => a.title, :amount => 0}
prices = prices + price
# Check for actual sale items
sale_items.each do |si|
if si.account_id == a.id
account_price[:amount] = account_price[:amount] + si.price
price = price + si.price
end
end
rebate_arr.push(account_price)
end
return prices
return price,rebate_arr
end
# get food price or beverage price for item
def self.get_rebate_price(sale_item_id,rebateacc)
price=0
price = 0
type = ''
item=SaleItem.select("sale_items.price , menu_items.account_id")
.joins("left join menu_items on menu_items.item_code = sale_items.product_code")
.where("sale_items.sale_item_id=?", sale_item_id.to_s)
@@ -93,12 +99,14 @@ class SaleItem < ApplicationRecord
rebateacc.each do |i|
if item[0].account_id == i.id
price = item[0].price
type = i.title
end
end
return price
return price,type
end
# def self.get_overall_discount(sale_id)
# price = 0.0
# item=SaleItem.where("product_code=?", sale_id)