From 63751d047b67f7f87fa3fb0701cf9d295acdd29b Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Tue, 29 May 2018 16:54:21 +0630 Subject: [PATCH] update promotion --- app/models/promotion.rb | 17 ++++++++++------- app/models/sale_item.rb | 4 ++-- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/app/models/promotion.rb b/app/models/promotion.rb index f1e19d98..420919e8 100755 --- a/app/models/promotion.rb +++ b/app/models/promotion.rb @@ -18,6 +18,7 @@ class Promotion < ApplicationRecord puts "promoList - " + promoList.size.to_s if promoList.size > 0 itemList = combine_item(saleObj) + puts itemList.to_json is_promo_day(promoList,day, itemList, saleObj.sale_id) end end @@ -49,13 +50,14 @@ class Promotion < ApplicationRecord end end - def self.find_promo_item(promo, orderitem, sale_id) + def self.find_promo_item(promo, orderitem, sale_id) # item_code = OrderItem.find_by_item_instance_code(orderitem[0]).item_code orderitem.each do |odr_item| - if promo.original_product.to_s == odr_item[0] - if promo.min_qty.to_i > odr_item[1].to_i + + if promo.original_product.downcase.to_s == odr_item[0] + if promo.min_qty.to_i > odr_item[1].to_i return false - else + else check_promo_type(promo,odr_item, sale_id) end end @@ -72,9 +74,9 @@ class Promotion < ApplicationRecord end # same, promo_product = check_giveaway_product(promo, orderitem[0]) if promo.promo_type == Promotion::PROMO_TYPE1 - if same + if same give_promotion_same_product(orderitem[1], promo.min_qty, promo_product.min_qty, orderitem, sale_id,promo_product.item_code) - else + else give_promotion_second_product(orderitem[1], promo.min_qty, promo_product.item_code, orderitem, sale_id) end @@ -165,6 +167,7 @@ class Promotion < ApplicationRecord 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) @@ -242,7 +245,7 @@ class Promotion < ApplicationRecord itemList = combine_item(saleObj) itemList.each do |item| item.each do |i| - if i[0] == promo_item + if i[0] == promo_item.downcase return i[1] end end diff --git a/app/models/sale_item.rb b/app/models/sale_item.rb index 313be6a3..d69782cd 100755 --- a/app/models/sale_item.rb +++ b/app/models/sale_item.rb @@ -164,10 +164,10 @@ class SaleItem < ApplicationRecord def self.get_all_sale_items(sale_id) sale_items = SaleItem.select("sale_id,product_code,item_instance_code, product_name,product_alt_name,account_id,status,remark, - (CASE WHEN qty > 0 AND remark IS NULL THEN SUM(qty) ELSE qty END) as qty, + (CASE WHEN (qty > 0 AND remark IS NULL) OR (status='promotion' AND remark = 'promotion nett price') THEN SUM(qty) ELSE qty END) as qty, unit_price, taxable_price, - (CASE WHEN price > 0 AND remark IS NULL THEN SUM(price) ELSE price END) as price, + (CASE WHEN (price > 0 AND remark IS NULL) OR (status='promotion' AND remark = 'promotion nett price') THEN SUM(price) ELSE price END) as price, is_taxable") .where("sale_id = ?",sale_id) .order("product_name asc")