update promotion and takeaway for quickservice
This commit is contained in:
@@ -67,8 +67,6 @@ class Origami::AddordersController < BaseOrigamiController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def get_menu()
|
def get_menu()
|
||||||
puts "sssssssssssssss"
|
|
||||||
puts params[:id]
|
|
||||||
if (params[:id])
|
if (params[:id])
|
||||||
#Pull this menu
|
#Pull this menu
|
||||||
@menu = Menu.find_by_id(params[:id])
|
@menu = Menu.find_by_id(params[:id])
|
||||||
@@ -122,11 +120,11 @@ puts params[:id]
|
|||||||
items_arr.push(items)
|
items_arr.push(items)
|
||||||
}
|
}
|
||||||
# begin
|
# begin
|
||||||
# if params[:order_source] == "quick_service"
|
if params[:order_source] == "quick_service" && params[:table_id].to_i == 0
|
||||||
# customer_id = "CUS-000000000002" # for no customer id from mobile
|
customer_id = "CUS-000000000002" # for no customer id from mobile
|
||||||
# else
|
else
|
||||||
customer_id = params[:customer_id] == ""? "CUS-000000000001" : params[:customer_id] # for no customer id from mobile
|
customer_id = params[:customer_id] == ""? "CUS-000000000001" : params[:customer_id] # for no customer id from mobile
|
||||||
# end
|
end
|
||||||
@order = Order.new
|
@order = Order.new
|
||||||
@order.source = params[:order_source]
|
@order.source = params[:order_source]
|
||||||
@order.order_type = params[:order_type]
|
@order.order_type = params[:order_type]
|
||||||
|
|||||||
@@ -29,12 +29,13 @@ class Promotion < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.combine_item(saleObj)
|
def self.combine_item(saleObj)
|
||||||
# order_id = saleObj.sale_orders[0].order_id
|
# order_id = saleObj.sale_orders[0][0].order_id
|
||||||
# itemList = OrderItem.where("order_id = ?", order_id).group(:item_instance_code).sum(:qty)
|
# itemList = OrderItem.where("order_id = ?", order_id).group(:item_instance_code).sum(:qty)
|
||||||
itemList = []
|
itemList = []
|
||||||
saleObj.sale_orders.each do |so|
|
saleObj.sale_orders.each do |so|
|
||||||
itemList << OrderItem.where("order_id = ?",so.order_id).group(:item_instance_code).sum(:qty)
|
itemList << OrderItem.where("order_id = ?",so.order_id).group(["item_instance_code", "order_id"]).sum(:qty)
|
||||||
end
|
end
|
||||||
|
|
||||||
return itemList
|
return itemList
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -51,10 +52,9 @@ class Promotion < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.find_promo_item(promo, orderitem, sale_id)
|
def self.find_promo_item(promo, orderitem, sale_id)
|
||||||
# item_code = OrderItem.find_by_item_instance_code(orderitem[0]).item_code
|
# item_code = OrderItem.find_by_item_instance_code(orderitem[0][0]).item_code
|
||||||
orderitem.each do |odr_item|
|
orderitem.each do |odr_item|
|
||||||
|
if promo.original_product.downcase.to_s == odr_item[0][0]
|
||||||
if promo.original_product.downcase.to_s == odr_item[0]
|
|
||||||
if promo.min_qty.to_i > odr_item[1].to_i
|
if promo.min_qty.to_i > odr_item[1].to_i
|
||||||
return false
|
return false
|
||||||
else
|
else
|
||||||
@@ -66,13 +66,13 @@ class Promotion < ApplicationRecord
|
|||||||
|
|
||||||
def self.check_promo_type(promo, orderitem, sale_id)
|
def self.check_promo_type(promo, orderitem, sale_id)
|
||||||
promo.promotion_products.each do |promo_product|
|
promo.promotion_products.each do |promo_product|
|
||||||
if promo_product.item_code.downcase == orderitem[0]
|
if promo_product.item_code.downcase == orderitem[0][0]
|
||||||
same = true
|
same = true
|
||||||
else
|
else
|
||||||
# return false, promo_product
|
# return false, promo_product
|
||||||
same = false
|
same = false
|
||||||
end
|
end
|
||||||
# same, promo_product = check_giveaway_product(promo, orderitem[0])
|
# same, promo_product = check_giveaway_product(promo, orderitem[0][0])
|
||||||
if promo.promo_type == Promotion::PROMO_TYPE1
|
if promo.promo_type == Promotion::PROMO_TYPE1
|
||||||
if same
|
if same
|
||||||
give_promotion_same_product(orderitem[1], promo.min_qty, promo_product.min_qty, orderitem, sale_id,promo_product.item_code)
|
give_promotion_same_product(orderitem[1], promo.min_qty, promo_product.min_qty, orderitem, sale_id,promo_product.item_code)
|
||||||
@@ -132,11 +132,12 @@ class Promotion < ApplicationRecord
|
|||||||
else
|
else
|
||||||
charge_qty += qty
|
charge_qty += qty
|
||||||
end
|
end
|
||||||
item = OrderItem.find_by_item_instance_code(orderitem[0])
|
item = OrderItem.where("item_instance_code = '#{orderitem[0][0]}' and order_id = '#{orderitem[0][1]}'").first
|
||||||
if promo_product.downcase == OrderItem.find_by_item_instance_code(orderitem[0]).item_instance_code
|
if promo_product.downcase != item.item_instance_code
|
||||||
item = OrderItem.find_by_item_instance_code(orderitem[0])
|
# item = item
|
||||||
else
|
# else
|
||||||
item = OrderItem.find_by_item_code(promo_product)
|
# item = OrderItem.find_by_item_code(promo_product)
|
||||||
|
item = OrderItem.where("item_code = '#{promo_product}' and order_id = '#{orderitem[0][1]}'").first
|
||||||
end
|
end
|
||||||
source = Order.find(item.order_id).source
|
source = Order.find(item.order_id).source
|
||||||
update_existing_item(foc_qty, item, sale_id, "promotion", item.price,source)
|
update_existing_item(foc_qty, item, sale_id, "promotion", item.price,source)
|
||||||
@@ -185,13 +186,16 @@ class Promotion < ApplicationRecord
|
|||||||
puts " same: " + same.to_s + " promo_product: " + promo_product.item_code.to_s + " foc_min_qty: " + foc_min_qty.to_s + " orderitem: " + orderitem.to_s
|
puts " same: " + same.to_s + " promo_product: " + promo_product.item_code.to_s + " foc_min_qty: " + foc_min_qty.to_s + " orderitem: " + orderitem.to_s
|
||||||
if same
|
if same
|
||||||
foc_qty = orderitem[1].to_i / foc_min_qty
|
foc_qty = orderitem[1].to_i / foc_min_qty
|
||||||
item = OrderItem.find_by_item_instance_code(orderitem[0])
|
# item = OrderItem.find_by_item_instance_code(orderitem[0][0])
|
||||||
|
item = OrderItem.where("item_instance_code = '#{orderitem[0][0]}' and order_id = '#{orderitem[0][1]}'").first
|
||||||
source = Order.find(item.order_id).source
|
source = Order.find(item.order_id).source
|
||||||
update_existing_item(foc_qty, item, sale_id, "promotion nett off", promo_product.net_off,source)
|
update_existing_item(foc_qty, item, sale_id, "promotion nett off", promo_product.net_off,source)
|
||||||
else
|
else
|
||||||
foc_qty = orderitem[1].to_i / foc_min_qty
|
foc_qty = orderitem[1].to_i / foc_min_qty
|
||||||
# foc_qty = find_second_item_qty(sale_id, promo_product.item_code)
|
# foc_qty = find_second_item_qty(sale_id, promo_product.item_code)
|
||||||
item = OrderItem.find_by_item_instance_code(promo_product.item_code)
|
# item = OrderItem.find_by_item_instance_code(promo_product.item_code)
|
||||||
|
item = OrderItem.where("item_instance_code = '#{orderitem[0][0]}' and order_id = '#{orderitem[0][1]}'").first
|
||||||
|
|
||||||
source = Order.find(item.order_id).source
|
source = Order.find(item.order_id).source
|
||||||
update_existing_item(foc_qty, item, sale_id, "promotion nett off", promo_product.net_off,source)
|
update_existing_item(foc_qty, item, sale_id, "promotion nett off", promo_product.net_off,source)
|
||||||
end
|
end
|
||||||
@@ -201,14 +205,16 @@ class Promotion < ApplicationRecord
|
|||||||
puts " same: " + same.to_s + " promo_product: " + promo_product.item_code.to_s + " foc_min_qty: " + foc_min_qty.to_s + " orderitem: " + orderitem.to_s
|
puts " same: " + same.to_s + " promo_product: " + promo_product.item_code.to_s + " foc_min_qty: " + foc_min_qty.to_s + " orderitem: " + orderitem.to_s
|
||||||
if same
|
if same
|
||||||
foc_qty = orderitem[1].to_i / foc_min_qty
|
foc_qty = orderitem[1].to_i / foc_min_qty
|
||||||
item = OrderItem.find_by_item_instance_code(orderitem[0]) # need to specify with menu item instance
|
# item = OrderItem.find_by_item_instance_code(orderitem[0][0]) # need to specify with menu item instance
|
||||||
|
item = OrderItem.where("item_instance_code = '#{orderitem[0][0]}' and order_id = '#{orderitem[0][1]}'").first
|
||||||
price = item.price.to_i - promo_product.net_price.to_i
|
price = item.price.to_i - promo_product.net_price.to_i
|
||||||
source = Order.find(item.order_id).source
|
source = Order.find(item.order_id).source
|
||||||
update_existing_item(foc_qty, item, sale_id, "promotion nett price", price,source)
|
update_existing_item(foc_qty, item, sale_id, "promotion nett price", price,source)
|
||||||
else
|
else
|
||||||
# foc_qty = find_second_item_qty(sale_id, promo_product.item_code)# need to check for qty
|
# foc_qty = find_second_item_qty(sale_id, promo_product.item_code)# need to check for qty
|
||||||
foc_qty = orderitem[1].to_i / foc_min_qty
|
foc_qty = orderitem[1].to_i / foc_min_qty
|
||||||
item = OrderItem.find_by_item_instance_code(promo_product.item_code)
|
# item = OrderItem.find_by_item_instance_code(promo_product.item_code)
|
||||||
|
item = OrderItem.where("item_instance_code = '#{orderitem[0][0]}' and order_id = '#{orderitem[0][1]}'").first
|
||||||
price = item.price - promo_product.net_price
|
price = item.price - promo_product.net_price
|
||||||
source = Order.find(item.order_id).source
|
source = Order.find(item.order_id).source
|
||||||
update_existing_item(foc_qty, item, sale_id, "promotion nett price", price,source)
|
update_existing_item(foc_qty, item, sale_id, "promotion nett price", price,source)
|
||||||
@@ -219,7 +225,8 @@ class Promotion < ApplicationRecord
|
|||||||
puts " same: " + same.to_s + " promo_product: " + promo_product.item_code.to_s + " foc_min_qty: " + foc_min_qty.to_s + " orderitem: " + orderitem.to_s
|
puts " same: " + same.to_s + " promo_product: " + promo_product.item_code.to_s + " foc_min_qty: " + foc_min_qty.to_s + " orderitem: " + orderitem.to_s
|
||||||
if same
|
if same
|
||||||
foc_qty = orderitem[1].to_i / foc_min_qty
|
foc_qty = orderitem[1].to_i / foc_min_qty
|
||||||
item = OrderItem.find_by_item_instance_code(orderitem[0])
|
# item = OrderItem.find_by_item_instance_code(orderitem[0][0])
|
||||||
|
item = OrderItem.where("item_instance_code = '#{orderitem[0][0]}' and order_id = '#{orderitem[0][1]}'").first
|
||||||
# total = orderitem[1].to_i * item.price
|
# total = orderitem[1].to_i * item.price
|
||||||
total = item.price
|
total = item.price
|
||||||
price = calculate_discount(total, promo_product.percentage)
|
price = calculate_discount(total, promo_product.percentage)
|
||||||
@@ -231,7 +238,8 @@ class Promotion < ApplicationRecord
|
|||||||
# give total qty is 1
|
# give total qty is 1
|
||||||
#foc_qty = (foc_qty - foc_qty) + 1
|
#foc_qty = (foc_qty - foc_qty) + 1
|
||||||
|
|
||||||
item = OrderItem.find_by_item_instance_code(promo_product.item_code)
|
# item = OrderItem.find_by_item_instance_code(promo_product.item_code)
|
||||||
|
item = OrderItem.where("item_instance_code = '#{orderitem[0][0]}' and order_id = '#{orderitem[0][1]}'").first
|
||||||
# total = item.price * foc_qty
|
# total = item.price * foc_qty
|
||||||
total = item.price
|
total = item.price
|
||||||
price = calculate_discount(total, promo_product.percentage)
|
price = calculate_discount(total, promo_product.percentage)
|
||||||
@@ -245,7 +253,7 @@ class Promotion < ApplicationRecord
|
|||||||
itemList = combine_item(saleObj)
|
itemList = combine_item(saleObj)
|
||||||
itemList.each do |item|
|
itemList.each do |item|
|
||||||
item.each do |i|
|
item.each do |i|
|
||||||
if i[0] == promo_item.downcase
|
if i[0][0] == promo_item.downcase
|
||||||
return i[1]
|
return i[1]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user