Promotion by Instance
This commit is contained in:
@@ -23,7 +23,7 @@ class Promotion < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.is_between_promo_datetime(current_day,current_time) #database is not local time
|
def self.is_between_promo_datetime(current_day,current_time) #database is not local time
|
||||||
promoList = Promotion.where("(date_format(promo_start_date, 'YYYY-MM-DD') <=? AND date_format(promo_end_date, 'YYYY-MM-DD') >=?) AND (promo_start_hour < ? AND promo_end_hour > ?)", current_day, current_day, current_time, current_time)
|
promoList = Promotion.where("(TO_CHAR(promo_start_date, 'YYYY-MM-DD') <=? AND TO_CHAR(promo_end_date, 'YYYY-MM-DD') >=?) AND (promo_start_hour < ? AND promo_end_hour > ?)", current_day, current_day, current_time, current_time)
|
||||||
return promoList
|
return promoList
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -45,8 +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)
|
||||||
item_code = OrderItem.find_by_item_instance_code(orderitem[0]).item_code
|
# item_code = OrderItem.find_by_item_instance_code(orderitem[0]).item_code
|
||||||
if promo.original_product.to_s == item_code
|
if promo.original_product.to_s == orderitem[0]
|
||||||
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
|
||||||
@@ -77,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.find_by_item_instance_code(orderitem).item_code
|
if promo_product.item_code == orderitem
|
||||||
return true, promo_product
|
return true, promo_product
|
||||||
else
|
else
|
||||||
return false, promo_product
|
return false, promo_product
|
||||||
@@ -113,12 +113,11 @@ class Promotion < ApplicationRecord
|
|||||||
charge_qty += qty
|
charge_qty += qty
|
||||||
end
|
end
|
||||||
item = OrderItem.find_by_item_instance_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
|
||||||
# if promo_product == OrderItem.find_by_item_instance_code(orderitem[0]).item_code
|
item = OrderItem.find_by_item_instance_code(orderitem[0])
|
||||||
# item = OrderItem.find_by_item_instance_code(orderitem[0])
|
else
|
||||||
# else
|
item = OrderItem.find_by_item_code(promo_product)
|
||||||
# item = OrderItem.find_by_item_code(promo_product)
|
end
|
||||||
# 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
|
||||||
@@ -127,12 +126,13 @@ class Promotion < ApplicationRecord
|
|||||||
# AA - 10 # 3 # BB # orderList, #S34345
|
# AA - 10 # 3 # BB # orderList, #S34345
|
||||||
def self.give_promotion_second_product(orderitem_count, foc_min_qty, promo_product, orderitem, sale_id)
|
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
|
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
|
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)
|
foc_qty = find_second_item_qty(sale_id, promo_product)
|
||||||
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_instance_code(promo_product,orderID)
|
item = OrderItem.find_by_item_instance_code(promo_product)
|
||||||
update_existing_item(promotion_qty, item, sale_id, "promotion", item.price)
|
update_existing_item(promotion_qty, item, sale_id, "promotion", item.price)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -152,7 +152,6 @@ class Promotion < ApplicationRecord
|
|||||||
|
|
||||||
sale_item.is_taxable = false
|
sale_item.is_taxable = false
|
||||||
sale_item.sale_id = sale_id
|
sale_item.sale_id = sale_id
|
||||||
|
|
||||||
sale_item.save
|
sale_item.save
|
||||||
sale = Sale.find(sale_id)
|
sale = Sale.find(sale_id)
|
||||||
sale.compute_by_sale_items(sale.id, sale.sale_items, sale.total_discount)
|
sale.compute_by_sale_items(sale.id, sale.sale_items, sale.total_discount)
|
||||||
@@ -213,7 +212,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 OrderItem.find_by_item_instance_code(item[0]).item_code == promo_item
|
if item[0] == promo_item
|
||||||
return item[1]
|
return item[1]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user