update promotion for nil item
This commit is contained in:
@@ -139,11 +139,10 @@ class Promotion < ApplicationRecord
|
||||
# item = OrderItem.find_by_item_code(promo_product)
|
||||
item = OrderItem.where("item_code = '#{promo_product}' and order_id = '#{orderitem[0][1]}'").first
|
||||
end
|
||||
source = Order.find(item.order_id).source
|
||||
update_existing_item(foc_qty, item, sale_id, "promotion", item.price,source)
|
||||
|
||||
puts "Charged - " + charge_qty.to_s
|
||||
puts "FOC - " + foc_qty.to_s
|
||||
if !item.nil?
|
||||
source = Order.find(item.order_id).source
|
||||
update_existing_item(foc_qty, item, sale_id, "promotion", item.price,source)
|
||||
end
|
||||
end
|
||||
# AA - 10 # 3 # BB # orderList, #S34345
|
||||
def self.give_promotion_second_product(orderitem_count, foc_min_qty, promo_product, orderitem, sale_id)
|
||||
@@ -155,9 +154,10 @@ class Promotion < ApplicationRecord
|
||||
end
|
||||
# item = OrderItem.find_by_item_instance_code(promo_product)
|
||||
item = OrderItem.where("item_instance_code = '#{promo_product}' and order_id = '#{orderitem[0][1]}'").first
|
||||
|
||||
source = Order.find(item.order_id).source
|
||||
update_existing_item(promotion_qty, item, sale_id, "promotion", item.price,source)
|
||||
if !item.nil?
|
||||
source = Order.find(item.order_id).source
|
||||
update_existing_item(promotion_qty, item, sale_id, "promotion", item.price,source)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -190,15 +190,21 @@ class Promotion < ApplicationRecord
|
||||
foc_qty = orderitem[1].to_i / foc_min_qty
|
||||
# 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
|
||||
update_existing_item(foc_qty, item, sale_id, "promotion nett off", promo_product.net_off,source)
|
||||
if !item.nil?
|
||||
source = Order.find(item.order_id).source
|
||||
update_existing_item(foc_qty, item, sale_id, "promotion nett off", promo_product.net_off,source)
|
||||
end
|
||||
|
||||
else
|
||||
foc_qty = orderitem[1].to_i / foc_min_qty
|
||||
# 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.where("item_instance_code = '#{promo_product.item_code}' and order_id = '#{orderitem[0][1]}'").first
|
||||
source = Order.find(item.order_id).source
|
||||
update_existing_item(foc_qty, item, sale_id, "promotion nett off", promo_product.net_off,source)
|
||||
if !item.nil?
|
||||
source = Order.find(item.order_id).source
|
||||
update_existing_item(foc_qty, item, sale_id, "promotion nett off", promo_product.net_off,source)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -208,9 +214,12 @@ class Promotion < ApplicationRecord
|
||||
foc_qty = orderitem[1].to_i / foc_min_qty
|
||||
# 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
|
||||
source = Order.find(item.order_id).source
|
||||
update_existing_item(foc_qty, item, sale_id, "promotion nett price", price,source)
|
||||
if !item.nil?
|
||||
price = item.price.to_i - promo_product.net_price.to_i
|
||||
source = Order.find(item.order_id).source
|
||||
update_existing_item(foc_qty, item, sale_id, "promotion nett price", price,source)
|
||||
end
|
||||
|
||||
else
|
||||
order_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
|
||||
@@ -220,9 +229,12 @@ class Promotion < ApplicationRecord
|
||||
end
|
||||
# item = OrderItem.find_by_item_instance_code(promo_product.item_code)
|
||||
item = OrderItem.where("item_instance_code = '#{promo_product.item_code}' and order_id = '#{orderitem[0][1]}'").first
|
||||
price = item.price - promo_product.net_price
|
||||
source = Order.find(item.order_id).source
|
||||
update_existing_item(foc_qty, item, sale_id, "promotion nett price", price,source)
|
||||
if !item.nil?
|
||||
price = item.price - promo_product.net_price
|
||||
source = Order.find(item.order_id).source
|
||||
update_existing_item(foc_qty, item, sale_id, "promotion nett price", price,source)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -233,10 +245,13 @@ class Promotion < ApplicationRecord
|
||||
# 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 = item.price
|
||||
price = calculate_discount(total, promo_product.percentage)
|
||||
source = Order.find(item.order_id).source
|
||||
update_existing_item(foc_qty, item, sale_id, "promotion discount", price,source)
|
||||
if !item.nil?
|
||||
total = item.price
|
||||
price = calculate_discount(total, promo_product.percentage)
|
||||
source = Order.find(item.order_id).source
|
||||
update_existing_item(foc_qty, item, sale_id, "promotion discount", price,source)
|
||||
end
|
||||
|
||||
else
|
||||
order_qty = find_second_item_qty(sale_id, promo_product.item_code) #need to check
|
||||
foc_qty = orderitem[1].to_i / foc_min_qty
|
||||
@@ -248,10 +263,12 @@ class Promotion < ApplicationRecord
|
||||
# item = OrderItem.find_by_item_instance_code(promo_product.item_code)
|
||||
item = OrderItem.where("item_instance_code = '#{promo_product.item_code}' and order_id = '#{orderitem[0][1]}'").first
|
||||
# total = item.price * foc_qty
|
||||
total = item.price
|
||||
price = calculate_discount(total, promo_product.percentage)
|
||||
source = Order.find(item.order_id).source
|
||||
update_existing_item(foc_qty, item, sale_id, "promotion discount", price,source)
|
||||
if !item.nil?
|
||||
total = item.price
|
||||
price = calculate_discount(total, promo_product.percentage)
|
||||
source = Order.find(item.order_id).source
|
||||
update_existing_item(foc_qty, item, sale_id, "promotion discount", price,source)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user