diff --git a/app/models/promotion.rb b/app/models/promotion.rb index 0fd43d30..5bc6a686 100755 --- a/app/models/promotion.rb +++ b/app/models/promotion.rb @@ -154,7 +154,8 @@ class Promotion < ApplicationRecord promotion_qty = foc_qty end # item = OrderItem.find_by_item_instance_code(promo_product) - item = OrderItem.where("item_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 + source = Order.find(item.order_id).source update_existing_item(promotion_qty, item, sale_id, "promotion", item.price,source) end @@ -211,8 +212,12 @@ class Promotion < ApplicationRecord source = Order.find(item.order_id).source update_existing_item(foc_qty, item, sale_id, "promotion nett price", price,source) else - # foc_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 + + if foc_qty > order_qty + foc_qty = order_qty + 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 @@ -233,11 +238,13 @@ class Promotion < ApplicationRecord source = Order.find(item.order_id).source update_existing_item(foc_qty, item, sale_id, "promotion discount", price,source) else - # foc_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 # give total qty is 1 #foc_qty = (foc_qty - foc_qty) + 1 - + if foc_qty > order_qty + foc_qty = order_qty + 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 # total = item.price * foc_qty