update promotion

This commit is contained in:
Aung Myo
2018-05-29 16:54:21 +06:30
parent a062c5574a
commit 63751d047b
2 changed files with 12 additions and 9 deletions

View File

@@ -18,6 +18,7 @@ class Promotion < ApplicationRecord
puts "promoList - " + promoList.size.to_s puts "promoList - " + promoList.size.to_s
if promoList.size > 0 if promoList.size > 0
itemList = combine_item(saleObj) itemList = combine_item(saleObj)
puts itemList.to_json
is_promo_day(promoList,day, itemList, saleObj.sale_id) is_promo_day(promoList,day, itemList, saleObj.sale_id)
end end
end end
@@ -52,7 +53,8 @@ class Promotion < ApplicationRecord
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 # item_code = OrderItem.find_by_item_instance_code(orderitem[0]).item_code
orderitem.each do |odr_item| orderitem.each do |odr_item|
if promo.original_product.to_s == odr_item[0]
if promo.original_product.downcase.to_s == odr_item[0]
if promo.min_qty.to_i > odr_item[1].to_i if promo.min_qty.to_i > odr_item[1].to_i
return false return false
else else
@@ -165,6 +167,7 @@ class Promotion < ApplicationRecord
sale_item.product_alt_name = item.alt_name sale_item.product_alt_name = item.alt_name
sale_item.account_id = item.account_id sale_item.account_id = item.account_id
sale_item.remark = type sale_item.remark = type
sale_item.status = "promotion"
sale_item.qty = qty * (-1) sale_item.qty = qty * (-1)
sale_item.unit_price = item_price # * (-1) sale_item.unit_price = item_price # * (-1)
@@ -242,7 +245,7 @@ class Promotion < ApplicationRecord
itemList = combine_item(saleObj) itemList = combine_item(saleObj)
itemList.each do |item| itemList.each do |item|
item.each do |i| item.each do |i|
if i[0] == promo_item if i[0] == promo_item.downcase
return i[1] return i[1]
end end
end end

View File

@@ -164,10 +164,10 @@ class SaleItem < ApplicationRecord
def self.get_all_sale_items(sale_id) def self.get_all_sale_items(sale_id)
sale_items = SaleItem.select("sale_id,product_code,item_instance_code, sale_items = SaleItem.select("sale_id,product_code,item_instance_code,
product_name,product_alt_name,account_id,status,remark, 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, unit_price,
taxable_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") is_taxable")
.where("sale_id = ?",sale_id) .where("sale_id = ?",sale_id)
.order("product_name asc") .order("product_name asc")