Promotion multiple order

This commit is contained in:
Phyo
2017-09-04 10:22:54 +06:30
parent 09ba513c1c
commit 2eaf891748
2 changed files with 36 additions and 28 deletions

View File

@@ -28,8 +28,13 @@ class Promotion < ApplicationRecord
end
def self.combine_item(saleObj)
order_id = saleObj.sale_orders[0].order_id
itemList = OrderItem.where("order_id = ?", order_id).group(:item_instance_code).sum(:qty)
# order_id = saleObj.sale_orders[0].order_id
# itemList = OrderItem.where("order_id = ?", order_id).group(:item_instance_code).sum(:qty)
itemList = []
saleObj.sale_orders.each do |so|
itemList << OrderItem.where("order_id = ?",so.order_id).group(:item_instance_code).sum(:qty)
end
return itemList
end
def self.is_promo_day(promoList, day, orderitemList, sale_id)
@@ -46,13 +51,15 @@ class Promotion < ApplicationRecord
def self.find_promo_item(promo, orderitem, sale_id)
# item_code = OrderItem.find_by_item_instance_code(orderitem[0]).item_code
if promo.original_product.to_s == orderitem[0]
if promo.min_qty.to_i > orderitem[1].to_i
return false
else
check_promo_type(promo,orderitem, sale_id)
end
end
orderitem.each do |odr_item|
if promo.original_product.to_s == odr_item[0]
if promo.min_qty.to_i > odr_item[1].to_i
return false
else
check_promo_type(promo,odr_item, sale_id)
end
end
end
end
def self.check_promo_type(promo, orderitem, sale_id)
@@ -126,7 +133,6 @@ class Promotion < ApplicationRecord
# AA - 10 # 3 # BB # orderList, #S34345
def self.give_promotion_second_product(orderitem_count, foc_min_qty, promo_product, orderitem, sale_id)
puts "..... orderitem_count: " + orderitem_count.to_s + " / foc_min_qty: " + foc_min_qty.to_s + " /promo_product: " + promo_product + " orderitem: " + orderitem.to_s
byebug
promotion_qty = orderitem_count.to_i / foc_min_qty.to_i # get foc item qty
foc_qty = find_second_item_qty(sale_id, promo_product)
if (foc_qty < promotion_qty)
@@ -212,9 +218,11 @@ class Promotion < ApplicationRecord
saleObj = Sale.find_by_sale_id(sale_id)
itemList = combine_item(saleObj)
itemList.each do |item|
if item[0] == promo_item
return item[1]
end
item.each do |i|
if i[0] == promo_item
return i[1]
end
end
end
return 0
end