Merge branch 'august_spring' of bitbucket.org:code2lab/sxrestaurant into august_spring
* 'august_spring' of bitbucket.org:code2lab/sxrestaurant: Promo Phrase 1
This commit is contained in:
@@ -28,7 +28,8 @@ class Promotion < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.combine_item(saleObj)
|
def self.combine_item(saleObj)
|
||||||
itemList = saleObj.sale_items.group(:product_code).sum(:qty)
|
order_id = saleObj.sale_orders[0].order_id
|
||||||
|
itemList = OrderItem.where("order_id = ?", order_id).group(:item_instance_code).sum(:qty)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.is_promo_day(promoList, day, orderitemList, sale_id)
|
def self.is_promo_day(promoList, day, orderitemList, sale_id)
|
||||||
@@ -44,7 +45,8 @@ class Promotion < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.find_promo_item(promo, orderitem, sale_id)
|
def self.find_promo_item(promo, orderitem, sale_id)
|
||||||
if promo.original_product.to_s == orderitem[0].to_s
|
item_code = OrderItem.find_by_item_instance_code(orderitem[0]).item_code
|
||||||
|
if promo.original_product.to_s == item_code
|
||||||
if promo.min_qty.to_i > orderitem[1].to_i
|
if promo.min_qty.to_i > orderitem[1].to_i
|
||||||
return false
|
return false
|
||||||
else
|
else
|
||||||
@@ -75,7 +77,7 @@ class Promotion < ApplicationRecord
|
|||||||
|
|
||||||
def self.check_giveaway_product(promo, orderitem)
|
def self.check_giveaway_product(promo, orderitem)
|
||||||
promo.promotion_products.each do |promo_product|
|
promo.promotion_products.each do |promo_product|
|
||||||
if promo_product.item_code == orderitem
|
if promo_product.item_code == OrderItem.find_by_item_instance_code(orderitem).item_code
|
||||||
return true, promo_product
|
return true, promo_product
|
||||||
else
|
else
|
||||||
return false, promo_product
|
return false, promo_product
|
||||||
@@ -110,7 +112,13 @@ class Promotion < ApplicationRecord
|
|||||||
else
|
else
|
||||||
charge_qty += qty
|
charge_qty += qty
|
||||||
end
|
end
|
||||||
item = OrderItem.find_by_item_code(orderitem[0])
|
item = OrderItem.find_by_item_instance_code(orderitem[0])
|
||||||
|
byebug
|
||||||
|
# if promo_product == OrderItem.find_by_item_instance_code(orderitem[0]).item_code
|
||||||
|
# item = OrderItem.find_by_item_instance_code(orderitem[0])
|
||||||
|
# else
|
||||||
|
# item = OrderItem.find_by_item_code(promo_product)
|
||||||
|
# end
|
||||||
update_existing_item(foc_qty, item, sale_id, "promotion", item.price)
|
update_existing_item(foc_qty, item, sale_id, "promotion", item.price)
|
||||||
|
|
||||||
puts "Charged - " + charge_qty.to_s
|
puts "Charged - " + charge_qty.to_s
|
||||||
@@ -124,7 +132,7 @@ class Promotion < ApplicationRecord
|
|||||||
if (foc_qty < promotion_qty)
|
if (foc_qty < promotion_qty)
|
||||||
promotion_qty = foc_qty
|
promotion_qty = foc_qty
|
||||||
end
|
end
|
||||||
item = OrderItem.find_by_item_code(promo_product)
|
item = OrderItem.find_by_item_instance_code(promo_product,orderID)
|
||||||
update_existing_item(promotion_qty, item, sale_id, "promotion", item.price)
|
update_existing_item(promotion_qty, item, sale_id, "promotion", item.price)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -156,11 +164,11 @@ class Promotion < ApplicationRecord
|
|||||||
|
|
||||||
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_code(orderitem[0])
|
item = OrderItem.find_by_item_instance_code(orderitem[0])
|
||||||
update_existing_item(foc_qty, item, sale_id, "promotion nett off", promo_product.net_off)
|
update_existing_item(foc_qty, item, sale_id, "promotion nett off", promo_product.net_off)
|
||||||
else
|
else
|
||||||
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_code(promo_product.item_code)
|
item = OrderItem.find_by_item_instance_code(promo_product.item_code)
|
||||||
update_existing_item(foc_qty, item, sale_id, "promotion nett off", promo_product.net_off)
|
update_existing_item(foc_qty, item, sale_id, "promotion nett off", promo_product.net_off)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -170,12 +178,12 @@ class Promotion < ApplicationRecord
|
|||||||
|
|
||||||
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_code(orderitem[0]) # need to specify with menu item instance
|
item = OrderItem.find_by_item_instance_code(orderitem[0]) # need to specify with menu item instance
|
||||||
price = item.price.to_i - promo_product.net_price.to_i
|
price = item.price.to_i - promo_product.net_price.to_i
|
||||||
update_existing_item(foc_qty, item, sale_id, "promotion nett price", price)
|
update_existing_item(foc_qty, item, sale_id, "promotion nett price", price)
|
||||||
else
|
else
|
||||||
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_code(promo_product.item_code)
|
item = OrderItem.find_by_item_instance_code(promo_product.item_code)
|
||||||
price = item.price - promo_product.net_price
|
price = item.price - promo_product.net_price
|
||||||
update_existing_item(foc_qty, item, sale_id, "promotion nett price", price)
|
update_existing_item(foc_qty, item, sale_id, "promotion nett price", price)
|
||||||
end
|
end
|
||||||
@@ -186,14 +194,14 @@ class Promotion < ApplicationRecord
|
|||||||
|
|
||||||
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_code(orderitem[0])
|
item = OrderItem.find_by_item_instance_code(orderitem[0])
|
||||||
# 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)
|
||||||
update_existing_item(foc_qty, item, sale_id, "promotion discount", price)
|
update_existing_item(foc_qty, item, sale_id, "promotion discount", price)
|
||||||
else
|
else
|
||||||
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_code(promo_product.item_code)
|
item = OrderItem.find_by_item_instance_code(promo_product.item_code)
|
||||||
# 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)
|
||||||
@@ -205,7 +213,7 @@ class Promotion < ApplicationRecord
|
|||||||
saleObj = Sale.find_by_sale_id(sale_id)
|
saleObj = Sale.find_by_sale_id(sale_id)
|
||||||
itemList = combine_item(saleObj)
|
itemList = combine_item(saleObj)
|
||||||
itemList.each do |item|
|
itemList.each do |item|
|
||||||
if item[0] == promo_item
|
if OrderItem.find_by_item_instance_code(item[0]).item_code == promo_item
|
||||||
return item[1]
|
return item[1]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user