Merge branch 'master' of bitbucket.org:code2lab/sxrestaurant into adminbsb_ui_changes

This commit is contained in:
phyusin
2018-06-07 16:22:13 +06:30

View File

@@ -139,11 +139,10 @@ class Promotion < ApplicationRecord
# item = OrderItem.find_by_item_code(promo_product) # item = OrderItem.find_by_item_code(promo_product)
item = OrderItem.where("item_code = '#{promo_product}' and order_id = '#{orderitem[0][1]}'").first item = OrderItem.where("item_code = '#{promo_product}' and order_id = '#{orderitem[0][1]}'").first
end end
source = Order.find(item.order_id).source if !item.nil?
update_existing_item(foc_qty, item, sale_id, "promotion", item.price,source) 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 end
puts "FOC - " + foc_qty.to_s
end end
# 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)
@@ -155,9 +154,10 @@ class Promotion < ApplicationRecord
end end
# item = OrderItem.find_by_item_instance_code(promo_product) # item = OrderItem.find_by_item_instance_code(promo_product)
item = OrderItem.where("item_instance_code = '#{promo_product}' and order_id = '#{orderitem[0][1]}'").first item = OrderItem.where("item_instance_code = '#{promo_product}' and order_id = '#{orderitem[0][1]}'").first
if !item.nil?
source = Order.find(item.order_id).source source = Order.find(item.order_id).source
update_existing_item(promotion_qty, item, sale_id, "promotion", item.price,source) update_existing_item(promotion_qty, item, sale_id, "promotion", item.price,source)
end
end end
@@ -190,15 +190,21 @@ class Promotion < ApplicationRecord
foc_qty = orderitem[1].to_i / foc_min_qty foc_qty = orderitem[1].to_i / foc_min_qty
# item = OrderItem.find_by_item_instance_code(orderitem[0][0]) # 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 item = OrderItem.where("item_instance_code = '#{orderitem[0][0]}' and order_id = '#{orderitem[0][1]}'").first
source = Order.find(item.order_id).source if !item.nil?
update_existing_item(foc_qty, item, sale_id, "promotion nett off", promo_product.net_off,source) 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 else
foc_qty = orderitem[1].to_i / foc_min_qty foc_qty = orderitem[1].to_i / foc_min_qty
# 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_instance_code(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 item = OrderItem.where("item_instance_code = '#{promo_product.item_code}' and order_id = '#{orderitem[0][1]}'").first
source = Order.find(item.order_id).source if !item.nil?
update_existing_item(foc_qty, item, sale_id, "promotion nett off", promo_product.net_off,source) 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
end end
@@ -208,9 +214,12 @@ class Promotion < ApplicationRecord
foc_qty = orderitem[1].to_i / foc_min_qty 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.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 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 if !item.nil?
source = Order.find(item.order_id).source price = item.price.to_i - promo_product.net_price.to_i
update_existing_item(foc_qty, item, sale_id, "promotion nett price", price,source) source = Order.find(item.order_id).source
update_existing_item(foc_qty, item, sale_id, "promotion nett price", price,source)
end
else else
order_qty = find_second_item_qty(sale_id, promo_product.item_code)# need to check for qty 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 foc_qty = orderitem[1].to_i / foc_min_qty
@@ -220,9 +229,12 @@ class Promotion < ApplicationRecord
end end
# item = OrderItem.find_by_item_instance_code(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 item = OrderItem.where("item_instance_code = '#{promo_product.item_code}' and order_id = '#{orderitem[0][1]}'").first
price = item.price - promo_product.net_price if !item.nil?
source = Order.find(item.order_id).source price = item.price - promo_product.net_price
update_existing_item(foc_qty, item, sale_id, "promotion nett price", price,source) source = Order.find(item.order_id).source
update_existing_item(foc_qty, item, sale_id, "promotion nett price", price,source)
end
end end
end end
@@ -233,10 +245,13 @@ class Promotion < ApplicationRecord
# item = OrderItem.find_by_item_instance_code(orderitem[0][0]) # 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 item = OrderItem.where("item_instance_code = '#{orderitem[0][0]}' and order_id = '#{orderitem[0][1]}'").first
# total = orderitem[1].to_i * item.price # total = orderitem[1].to_i * item.price
total = item.price if !item.nil?
price = calculate_discount(total, promo_product.percentage) total = item.price
source = Order.find(item.order_id).source price = calculate_discount(total, promo_product.percentage)
update_existing_item(foc_qty, item, sale_id, "promotion discount", price,source) source = Order.find(item.order_id).source
update_existing_item(foc_qty, item, sale_id, "promotion discount", price,source)
end
else else
order_qty = find_second_item_qty(sale_id, promo_product.item_code) #need to check order_qty = find_second_item_qty(sale_id, promo_product.item_code) #need to check
foc_qty = orderitem[1].to_i / foc_min_qty 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.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 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 * foc_qty
total = item.price if !item.nil?
price = calculate_discount(total, promo_product.percentage) total = item.price
source = Order.find(item.order_id).source price = calculate_discount(total, promo_product.percentage)
update_existing_item(foc_qty, item, sale_id, "promotion discount", price,source) source = Order.find(item.order_id).source
update_existing_item(foc_qty, item, sale_id, "promotion discount", price,source)
end
end end
end end