Rebate Option
This commit is contained in:
@@ -32,48 +32,49 @@ class SaleItem < ApplicationRecord
|
||||
|
||||
# Calculate food total and beverage total
|
||||
def self.calculate_food_beverage(sale_items)
|
||||
food_prices=0
|
||||
beverage_prices=0
|
||||
|
||||
sale_items.each do |si|
|
||||
food_price, beverage_price = self.get_price(si.sale_item_id)
|
||||
|
||||
food_prices = food_prices + food_price
|
||||
beverage_prices = beverage_prices + beverage_price
|
||||
rebateacc = Account.where("rebate=?",true)
|
||||
puts "Account that can rebate"
|
||||
rebateacc.each do |i|
|
||||
puts i.title
|
||||
end
|
||||
puts food_prices
|
||||
puts beverage_prices
|
||||
return food_prices, beverage_prices
|
||||
prices=0
|
||||
sale_items.each do |si|
|
||||
price = self.get_price(si.sale_item_id,rebateacc)
|
||||
|
||||
prices = prices + price
|
||||
end
|
||||
return prices
|
||||
end
|
||||
|
||||
# get food price or beverage price for item
|
||||
def self.get_price(sale_item_id)
|
||||
food_price=0
|
||||
beverage_price=0
|
||||
def self.get_price(sale_item_id,rebateacc)
|
||||
price=0
|
||||
|
||||
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)
|
||||
if item[0].account_id == 1
|
||||
food_price = item[0].price
|
||||
else
|
||||
beverage_price = item[0].price
|
||||
end
|
||||
|
||||
return food_price, beverage_price
|
||||
end
|
||||
|
||||
def self.get_overall_discount(sale_id)
|
||||
price = 0.0
|
||||
item=SaleItem.where("product_code=?", sale_id)
|
||||
|
||||
item.each do|i|
|
||||
price += i.price
|
||||
rebateacc.each do |i|
|
||||
if item[0].account_id == i.id
|
||||
price = item[0].price
|
||||
end
|
||||
end
|
||||
|
||||
return price
|
||||
end
|
||||
|
||||
# def self.get_overall_discount(sale_id)
|
||||
# price = 0.0
|
||||
# item=SaleItem.where("product_code=?", sale_id)
|
||||
#
|
||||
# item.each do|i|
|
||||
# price += i.price
|
||||
# end
|
||||
#
|
||||
# return price
|
||||
# end
|
||||
|
||||
private
|
||||
def generate_custom_id
|
||||
self.sale_item_id = SeedGenerator.generate_id(self.class.name, "SLI")
|
||||
|
||||
@@ -241,7 +241,9 @@ class SalePayment < ApplicationRecord
|
||||
end
|
||||
|
||||
def rebat(sObj)
|
||||
food_prices, beverage_prices = SaleItem.calculate_food_beverage(sObj.sale_items)
|
||||
rebate_prices = SaleItem.calculate_food_beverage(sObj.sale_items)
|
||||
puts "rebate_prices"
|
||||
puts rebate_prices
|
||||
generic_customer_id = sObj.customer.membership_id
|
||||
if generic_customer_id != nil || generic_customer_id != "" || generic_customer_id != 0
|
||||
paypar = sObj.sale_payments
|
||||
@@ -251,12 +253,10 @@ class SalePayment < ApplicationRecord
|
||||
payparcost = payparcost + pp.payment_amount
|
||||
end
|
||||
end
|
||||
overall_dis = SaleItem.get_overall_discount(sObj.id)
|
||||
total_amount = food_prices - payparcost + overall_dis
|
||||
puts "total_amount"
|
||||
puts food_prices
|
||||
puts payparcost
|
||||
puts total_amount
|
||||
# overall_dis = SaleItem.get_overall_discount(sObj.id)
|
||||
overall_dis = sObj.total_discount
|
||||
|
||||
total_amount = rebate_prices - payparcost + overall_dis
|
||||
if total_amount > 0
|
||||
receipt_no = sObj.receipt_no
|
||||
membership = MembershipSetting.find_by_membership_type("paypar_url")
|
||||
|
||||
Reference in New Issue
Block a user