From 8e9e286965c9aac088f8540042cd34e3026952e2 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Thu, 31 May 2018 16:41:13 +0630 Subject: [PATCH] update promotion --- app/models/promotion.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/models/promotion.rb b/app/models/promotion.rb index 260dc8a1..0fd43d30 100755 --- a/app/models/promotion.rb +++ b/app/models/promotion.rb @@ -153,7 +153,8 @@ class Promotion < ApplicationRecord if (foc_qty < promotion_qty) promotion_qty = foc_qty end - item = OrderItem.find_by_item_instance_code(promo_product) + # item = OrderItem.find_by_item_instance_code(promo_product) + item = OrderItem.where("item_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) end @@ -194,8 +195,7 @@ class Promotion < ApplicationRecord 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 = '#{orderitem[0][0]}' 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 update_existing_item(foc_qty, item, sale_id, "promotion nett off", promo_product.net_off,source) end @@ -214,7 +214,7 @@ class Promotion < ApplicationRecord # foc_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 # item = OrderItem.find_by_item_instance_code(promo_product.item_code) - item = OrderItem.where("item_instance_code = '#{orderitem[0][0]}' 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 source = Order.find(item.order_id).source update_existing_item(foc_qty, item, sale_id, "promotion nett price", price,source) @@ -239,7 +239,7 @@ class Promotion < ApplicationRecord #foc_qty = (foc_qty - foc_qty) + 1 # item = OrderItem.find_by_item_instance_code(promo_product.item_code) - item = OrderItem.where("item_instance_code = '#{orderitem[0][0]}' 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 price = calculate_discount(total, promo_product.percentage)