Promo Phrase 1

This commit is contained in:
Phyo
2017-08-30 09:20:35 +06:30
parent 63d97cce26
commit 2208b8a526

View File

@@ -28,7 +28,8 @@ class Promotion < ApplicationRecord
end
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
def self.is_promo_day(promoList, day, orderitemList, sale_id)
@@ -44,7 +45,8 @@ class Promotion < ApplicationRecord
end
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
return false
else
@@ -75,7 +77,7 @@ class Promotion < ApplicationRecord
def self.check_giveaway_product(promo, orderitem)
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
else
return false, promo_product
@@ -110,7 +112,13 @@ class Promotion < ApplicationRecord
else
charge_qty += qty
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)
puts "Charged - " + charge_qty.to_s
@@ -124,7 +132,7 @@ class Promotion < ApplicationRecord
if (foc_qty < promotion_qty)
promotion_qty = foc_qty
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)
end
@@ -156,11 +164,11 @@ class Promotion < ApplicationRecord
if same
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)
else
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)
end
end
@@ -170,12 +178,12 @@ class Promotion < ApplicationRecord
if same
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
update_existing_item(foc_qty, item, sale_id, "promotion nett price", price)
else
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
update_existing_item(foc_qty, item, sale_id, "promotion nett price", price)
end
@@ -186,14 +194,14 @@ class Promotion < ApplicationRecord
if same
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 = item.price
price = calculate_discount(total, promo_product.percentage)
update_existing_item(foc_qty, item, sale_id, "promotion discount", price)
else
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
price = calculate_discount(total, promo_product.percentage)
@@ -205,7 +213,7 @@ class Promotion < ApplicationRecord
saleObj = Sale.find_by_sale_id(sale_id)
itemList = combine_item(saleObj)
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]
end
end