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
if !item.nil?
source = Order.find(item.order_id).source source = Order.find(item.order_id).source
update_existing_item(foc_qty, item, sale_id, "promotion", item.price,source) update_existing_item(foc_qty, item, sale_id, "promotion", item.price,source)
end
puts "Charged - " + charge_qty.to_s
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,10 +154,11 @@ 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
def self.update_existing_item(qty, item, sale_id, type, item_price,source) def self.update_existing_item(qty, item, sale_id, type, item_price,source)
@@ -190,16 +190,22 @@ 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
if !item.nil?
source = Order.find(item.order_id).source source = Order.find(item.order_id).source
update_existing_item(foc_qty, item, sale_id, "promotion nett off", promo_product.net_off,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
if !item.nil?
source = Order.find(item.order_id).source source = Order.find(item.order_id).source
update_existing_item(foc_qty, item, sale_id, "promotion nett off", promo_product.net_off,source) update_existing_item(foc_qty, item, sale_id, "promotion nett off", promo_product.net_off,source)
end end
end
end end
def self.give_promotion_nett_price(same, promo_product, foc_min_qty, orderitem, sale_id) def self.give_promotion_nett_price(same, promo_product, foc_min_qty, orderitem, sale_id)
@@ -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
if !item.nil?
price = item.price.to_i - promo_product.net_price.to_i price = item.price.to_i - promo_product.net_price.to_i
source = Order.find(item.order_id).source source = Order.find(item.order_id).source
update_existing_item(foc_qty, item, sale_id, "promotion nett price", price,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,10 +229,13 @@ 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
if !item.nil?
price = item.price - promo_product.net_price price = item.price - promo_product.net_price
source = Order.find(item.order_id).source source = Order.find(item.order_id).source
update_existing_item(foc_qty, item, sale_id, "promotion nett price", price,source) update_existing_item(foc_qty, item, sale_id, "promotion nett price", price,source)
end end
end
end end
def self.give_promotion_discount(same, promo_product, foc_min_qty, orderitem, sale_id) def self.give_promotion_discount(same, promo_product, foc_min_qty, orderitem, sale_id)
@@ -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
if !item.nil?
total = item.price total = item.price
price = calculate_discount(total, promo_product.percentage) price = calculate_discount(total, promo_product.percentage)
source = Order.find(item.order_id).source source = Order.find(item.order_id).source
update_existing_item(foc_qty, item, sale_id, "promotion discount", price,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,12 +263,14 @@ 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
if !item.nil?
total = item.price total = item.price
price = calculate_discount(total, promo_product.percentage) price = calculate_discount(total, promo_product.percentage)
source = Order.find(item.order_id).source source = Order.find(item.order_id).source
update_existing_item(foc_qty, item, sale_id, "promotion discount", price,source) update_existing_item(foc_qty, item, sale_id, "promotion discount", price,source)
end end
end end
end
def self.find_second_item_qty(sale_id, promo_item) def self.find_second_item_qty(sale_id, promo_item)
saleObj = Sale.find_by_sale_id(sale_id) saleObj = Sale.find_by_sale_id(sale_id)