promotion
This commit is contained in:
@@ -97,11 +97,9 @@ class Promotion < ApplicationRecord
|
||||
end
|
||||
# same, promo_product = check_giveaway_product(promo, orderitem[0][0])
|
||||
if promo.promo_type == Promotion::PROMO_TYPE1
|
||||
if same
|
||||
puts "Hello this is same"
|
||||
if same
|
||||
give_promotion_same_product(orderitem[:qty], promo.min_qty, promo_product.min_qty, orderitem, sale_id,promo_product.item_code)
|
||||
else
|
||||
puts "Hello this is not same"
|
||||
else
|
||||
give_promotion_second_product(orderitem[:qty], promo.min_qty, promo_product.item_code, orderitem, sale_id)
|
||||
end
|
||||
|
||||
@@ -227,31 +225,33 @@ class Promotion < ApplicationRecord
|
||||
|
||||
|
||||
def self.update_existing_item(qty, item, sale_id, type, item_price,source)
|
||||
menu_category = MenuCategory.get_menu_category(item[:item_code]) #get menu category for menu items
|
||||
|
||||
sale_item = SaleItem.new
|
||||
if !menu_category.nil?
|
||||
sale_item.menu_category_code = menu_category.code
|
||||
sale_item.menu_category_name = menu_category.name
|
||||
if qty >0
|
||||
menu_category = MenuCategory.get_menu_category(item[:item_code]) #get menu category for menu items
|
||||
|
||||
sale_item = SaleItem.new
|
||||
if !menu_category.nil?
|
||||
sale_item.menu_category_code = menu_category.code
|
||||
sale_item.menu_category_name = menu_category.name
|
||||
end
|
||||
sale_item.product_code = item[:item_code]
|
||||
sale_item.item_instance_code = item[:item_instance_code]
|
||||
sale_item.product_name = item[:item_name] + "(promotion)"
|
||||
sale_item.product_alt_name = item[:alt_name]
|
||||
sale_item.account_id = item[:account_id]
|
||||
sale_item.remark = type
|
||||
sale_item.status = "promotion"
|
||||
sale_item.qty = qty * (-1)
|
||||
|
||||
sale_item.unit_price = item_price # * (-1)
|
||||
sale_item.taxable_price = (qty * item_price) * (-1)
|
||||
sale_item.price = qty * item_price * (-1)
|
||||
|
||||
sale_item.is_taxable = 1
|
||||
sale_item.sale_id = sale_id
|
||||
sale_item.save
|
||||
sale = Sale.find(sale_id)
|
||||
sale.compute_by_sale_items(sale.id, sale.sale_items, sale.total_discount,nil,source)
|
||||
end
|
||||
sale_item.product_code = item[:item_code]
|
||||
sale_item.item_instance_code = item[:item_instance_code]
|
||||
sale_item.product_name = item[:item_name] + "(promotion)"
|
||||
sale_item.product_alt_name = item[:alt_name]
|
||||
sale_item.account_id = item[:account_id]
|
||||
sale_item.remark = type
|
||||
sale_item.status = "promotion"
|
||||
sale_item.qty = qty * (-1)
|
||||
|
||||
sale_item.unit_price = item_price # * (-1)
|
||||
sale_item.taxable_price = (qty * item_price) * (-1)
|
||||
sale_item.price = qty * item_price * (-1)
|
||||
|
||||
sale_item.is_taxable = 1
|
||||
sale_item.sale_id = sale_id
|
||||
sale_item.save
|
||||
sale = Sale.find(sale_id)
|
||||
sale.compute_by_sale_items(sale.id, sale.sale_items, sale.total_discount,nil,source)
|
||||
end
|
||||
|
||||
|
||||
@@ -290,7 +290,7 @@ class Promotion < ApplicationRecord
|
||||
# item = OrderItem.where("item_instance_code = '#{promo_product.item_code}' and order_id = '#{orderitem[0][1]}'").first
|
||||
sale_order.each do|order|
|
||||
source = Order.find(order.order_id).source
|
||||
end
|
||||
end
|
||||
item = OrderItem.where("item_instance_code = ?",promo_product.item_code).order("order_items_id DESC").first
|
||||
item ={
|
||||
item_code:item.item_code,
|
||||
@@ -304,7 +304,7 @@ class Promotion < ApplicationRecord
|
||||
# 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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user