promotion
This commit is contained in:
@@ -160,9 +160,11 @@ class Promotion < ApplicationRecord
|
|||||||
price =0
|
price =0
|
||||||
source =''
|
source =''
|
||||||
sale_order.each do|order|
|
sale_order.each do|order|
|
||||||
item = OrderItem.where("item_instance_code = ? and order_id = ?",orderitem[:item_instance_code],order.order_id).first
|
|
||||||
source = Order.find(order.order_id).source
|
source = Order.find(order.order_id).source
|
||||||
item ={
|
end
|
||||||
|
|
||||||
|
item = OrderItem.where("item_instance_code = ?",orderitem[:item_instance_code]).order("order_items_id DESC").first
|
||||||
|
item ={
|
||||||
item_code:item.item_code,
|
item_code:item.item_code,
|
||||||
item_instance_code:item.item_instance_code,
|
item_instance_code:item.item_instance_code,
|
||||||
item_name:item.item_name,
|
item_name:item.item_name,
|
||||||
@@ -170,13 +172,13 @@ class Promotion < ApplicationRecord
|
|||||||
account_id:item.account_id,
|
account_id:item.account_id,
|
||||||
price:item.price
|
price:item.price
|
||||||
}
|
}
|
||||||
end
|
|
||||||
if promo_product.downcase != item[:item_instance_code]
|
if promo_product.downcase != item[:item_instance_code]
|
||||||
|
|
||||||
sale_order.each do|order|
|
sale_order.each do|order|
|
||||||
item = OrderItem.where("item_code = ? and order_id = ?",promo_product,order.order_id).first
|
|
||||||
source = Order.find(order.order_id).source
|
source = Order.find(order.order_id).source
|
||||||
item ={
|
end
|
||||||
|
item = OrderItem.where("item_code = ?",promo_product).order("order_items_id DESC").first
|
||||||
|
item ={
|
||||||
item_code:item.item_code,
|
item_code:item.item_code,
|
||||||
item_instance_code:item.item_instance_code,
|
item_instance_code:item.item_instance_code,
|
||||||
item_name:item.item_name,
|
item_name:item.item_name,
|
||||||
@@ -184,7 +186,6 @@ class Promotion < ApplicationRecord
|
|||||||
account_id:item.account_id,
|
account_id:item.account_id,
|
||||||
price:item.price
|
price:item.price
|
||||||
}
|
}
|
||||||
end
|
|
||||||
end
|
end
|
||||||
if !item.nil?
|
if !item.nil?
|
||||||
update_existing_item(foc_qty, item, sale_id, "promotion", item[:price],source)
|
update_existing_item(foc_qty, item, sale_id, "promotion", item[:price],source)
|
||||||
@@ -204,10 +205,10 @@ class Promotion < ApplicationRecord
|
|||||||
sale_order =SaleOrder.where("sale_id=?",sale_id)
|
sale_order =SaleOrder.where("sale_id=?",sale_id)
|
||||||
price =0
|
price =0
|
||||||
sale_order.each do|order|
|
sale_order.each do|order|
|
||||||
item = OrderItem.where("item_instance_code = ? and order_id = ?",orderitem[:item_instance_code],order.order_id).first
|
|
||||||
price +=item.price
|
|
||||||
source = Order.find(order.order_id).source
|
source = Order.find(order.order_id).source
|
||||||
item ={
|
end
|
||||||
|
item = OrderItem.where("item_instance_code = ?",orderitem[:item_instance_code]).order("order_items_id DESC").first
|
||||||
|
item ={
|
||||||
item_code:item.item_code,
|
item_code:item.item_code,
|
||||||
item_instance_code:item.item_instance_code,
|
item_instance_code:item.item_instance_code,
|
||||||
item_name:item.item_name,
|
item_name:item.item_name,
|
||||||
@@ -215,11 +216,10 @@ class Promotion < ApplicationRecord
|
|||||||
account_id:item.account_id,
|
account_id:item.account_id,
|
||||||
price:item.price
|
price:item.price
|
||||||
}
|
}
|
||||||
end
|
|
||||||
# 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?
|
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
|
end
|
||||||
|
|
||||||
@@ -264,10 +264,10 @@ class Promotion < ApplicationRecord
|
|||||||
|
|
||||||
price =0
|
price =0
|
||||||
sale_order.each do|order|
|
sale_order.each do|order|
|
||||||
item = OrderItem.where("item_instance_code = ? and order_id = ?",orderitem[:item_instance_code],order.order_id).first
|
|
||||||
price +=item.price
|
|
||||||
source = Order.find(order.order_id).source
|
source = Order.find(order.order_id).source
|
||||||
item ={
|
end
|
||||||
|
item = OrderItem.where("item_instance_code = ?",orderitem[:item_instance_code]).order("order_items_id DESC").first
|
||||||
|
item ={
|
||||||
item_code:item.item_code,
|
item_code:item.item_code,
|
||||||
item_instance_code:item.item_instance_code,
|
item_instance_code:item.item_instance_code,
|
||||||
item_name:item.item_name,
|
item_name:item.item_name,
|
||||||
@@ -275,7 +275,6 @@ class Promotion < ApplicationRecord
|
|||||||
account_id:item.account_id,
|
account_id:item.account_id,
|
||||||
price:item.price
|
price:item.price
|
||||||
}
|
}
|
||||||
end
|
|
||||||
# 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?
|
if !item.nil?
|
||||||
# source = Order.find(item.order_id).source
|
# source = Order.find(item.order_id).source
|
||||||
@@ -288,17 +287,17 @@ 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
|
||||||
sale_order.each do|order|
|
sale_order.each do|order|
|
||||||
item = OrderItem.where("item_instance_code = ? and order_id = ?",promo_product.item_code,order.order_id).first
|
|
||||||
source = Order.find(order.order_id).source
|
source = Order.find(order.order_id).source
|
||||||
item ={
|
|
||||||
item_code:item.item_code,
|
|
||||||
item_instance_code:item.item_instance_code,
|
|
||||||
item_name:item.item_name,
|
|
||||||
alt_name:item.alt_name,
|
|
||||||
account_id:item.account_id,
|
|
||||||
price:item.price
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
item = OrderItem.where("item_instance_code = ?",promo_product.item_code).order("order_items_id DESC").first
|
||||||
|
item ={
|
||||||
|
item_code:item.item_code,
|
||||||
|
item_instance_code:item.item_instance_code,
|
||||||
|
item_name:item.item_name,
|
||||||
|
alt_name:item.alt_name,
|
||||||
|
account_id:item.account_id,
|
||||||
|
price:item.price
|
||||||
|
}
|
||||||
if !item.nil?
|
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)
|
||||||
@@ -312,24 +311,22 @@ class Promotion < ApplicationRecord
|
|||||||
sale_order =SaleOrder.where("sale_id=?",sale_id)
|
sale_order =SaleOrder.where("sale_id=?",sale_id)
|
||||||
source =''
|
source =''
|
||||||
item =''
|
item =''
|
||||||
price =0
|
|
||||||
if same
|
if same
|
||||||
foc_qty = orderitem[1].to_i / foc_min_qty
|
foc_qty = orderitem[:qty].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
|
||||||
sale_order.each do|order|
|
sale_order.each do|order|
|
||||||
item = OrderItem.where("item_instance_code = ? and order_id = ?",orderitem[:item_instance_code],order.order_id).first
|
source = Order.find(order.order_id).source
|
||||||
source = Order.find(order.order_id).source
|
|
||||||
price +=item.price
|
|
||||||
item ={
|
|
||||||
item_code:item.item_code,
|
|
||||||
item_instance_code:item.item_instance_code,
|
|
||||||
item_name:item.item_name,
|
|
||||||
alt_name:item.alt_name,
|
|
||||||
account_id:item.account_id,
|
|
||||||
price:item.price
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
item = OrderItem.where("item_instance_code = ?",orderitem[:item_instance_code]).order("order_items_id DESC").first
|
||||||
|
item ={
|
||||||
|
item_code:item.item_code,
|
||||||
|
item_instance_code:item.item_instance_code,
|
||||||
|
item_name:item.item_name,
|
||||||
|
alt_name:item.alt_name,
|
||||||
|
account_id:item.account_id,
|
||||||
|
price:item.price
|
||||||
|
}
|
||||||
if !item.nil?
|
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
|
||||||
@@ -346,18 +343,18 @@ 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
|
||||||
sale_order.each do|order|
|
sale_order.each do|order|
|
||||||
item = OrderItem.where("item_instance_code = ? and order_id = ?",promo_product.item_code,order.order_id).first
|
|
||||||
source = Order.find(order.order_id).source
|
source = Order.find(order.order_id).source
|
||||||
price +=item.price
|
|
||||||
item ={
|
|
||||||
item_code:item.item_code,
|
|
||||||
item_instance_code:item.item_instance_code,
|
|
||||||
item_name:item.item_name,
|
|
||||||
alt_name:item.alt_name,
|
|
||||||
account_id:item.account_id,
|
|
||||||
price:item.price
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
item = OrderItem.where("item_instance_code",promo_product.item_code).order("order_items_id DESC").first
|
||||||
|
item ={
|
||||||
|
item_code:item.item_code,
|
||||||
|
item_instance_code:item.item_instance_code,
|
||||||
|
item_name:item.item_name,
|
||||||
|
alt_name:item.alt_name,
|
||||||
|
account_id:item.account_id,
|
||||||
|
price:item.price
|
||||||
|
}
|
||||||
|
|
||||||
if !item.nil?
|
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
|
||||||
@@ -372,24 +369,22 @@ class Promotion < ApplicationRecord
|
|||||||
sale_order =SaleOrder.where("sale_id=?",sale_id)
|
sale_order =SaleOrder.where("sale_id=?",sale_id)
|
||||||
source =''
|
source =''
|
||||||
item =''
|
item =''
|
||||||
price =0
|
|
||||||
if same
|
if same
|
||||||
foc_qty = orderitem[:qty].to_i / foc_min_qty
|
foc_qty = orderitem[:qty].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
|
||||||
sale_order.each do|order|
|
sale_order.each do|order|
|
||||||
item = OrderItem.where("item_instance_code = ? and order_id = ?",orderitem[:item_instance_code],order.order_id).first
|
source = Order.find(order.order_id).source
|
||||||
source = Order.find(order.order_id).source
|
|
||||||
price +=item.price
|
|
||||||
item ={
|
|
||||||
item_code:item.item_code,
|
|
||||||
item_instance_code:item.item_instance_code,
|
|
||||||
item_name:item.item_name,
|
|
||||||
alt_name:item.alt_name,
|
|
||||||
account_id:item.account_id,
|
|
||||||
price:item.price
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
item = OrderItem.where("item_instance_code = ?",orderitem[:item_instance_code]).order("order_items_id DESC").first
|
||||||
|
item ={
|
||||||
|
item_code:item.item_code,
|
||||||
|
item_instance_code:item.item_instance_code,
|
||||||
|
item_name:item.item_name,
|
||||||
|
alt_name:item.alt_name,
|
||||||
|
account_id:item.account_id,
|
||||||
|
price:item.price
|
||||||
|
}
|
||||||
# total = orderitem[1].to_i * item.price
|
# total = orderitem[1].to_i * item.price
|
||||||
if !item.nil?
|
if !item.nil?
|
||||||
total = item[:price]
|
total = item[:price]
|
||||||
@@ -400,7 +395,7 @@ class Promotion < ApplicationRecord
|
|||||||
|
|
||||||
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[:qty].to_i / foc_min_qty
|
||||||
# give total qty is 1
|
# give total qty is 1
|
||||||
#foc_qty = (foc_qty - foc_qty) + 1
|
#foc_qty = (foc_qty - foc_qty) + 1
|
||||||
if foc_qty > order_qty
|
if foc_qty > order_qty
|
||||||
@@ -409,17 +404,17 @@ 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
|
||||||
sale_order.each do|order|
|
sale_order.each do|order|
|
||||||
item = OrderItem.where("item_instance_code = ? and order_id = ?",promo_product.item_code,order.order_id).first
|
source = Order.find(order.order_id).source
|
||||||
source = Order.find(order.order_id).source
|
|
||||||
item ={
|
|
||||||
item_code:item.item_code,
|
|
||||||
item_instance_code:item.item_instance_code,
|
|
||||||
item_name:item.item_name,
|
|
||||||
alt_name:item.alt_name,
|
|
||||||
account_id:item.account_id,
|
|
||||||
price:item.price
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
item = OrderItem.where("item_instance_code = ?",promo_product.item_code).order("order_items_id DESC").first
|
||||||
|
item ={
|
||||||
|
item_code:item.item_code,
|
||||||
|
item_instance_code:item.item_instance_code,
|
||||||
|
item_name:item.item_name,
|
||||||
|
alt_name:item.alt_name,
|
||||||
|
account_id:item.account_id,
|
||||||
|
price:item.price
|
||||||
|
}
|
||||||
# total = item.price * foc_qty
|
# total = item.price * foc_qty
|
||||||
if !item.nil?
|
if !item.nil?
|
||||||
total = item[:price]
|
total = item[:price]
|
||||||
|
|||||||
Reference in New Issue
Block a user