Promotion multiple order
This commit is contained in:
@@ -28,8 +28,13 @@ class Promotion < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.combine_item(saleObj)
|
def self.combine_item(saleObj)
|
||||||
order_id = saleObj.sale_orders[0].order_id
|
# order_id = saleObj.sale_orders[0].order_id
|
||||||
itemList = OrderItem.where("order_id = ?", order_id).group(:item_instance_code).sum(:qty)
|
# itemList = OrderItem.where("order_id = ?", order_id).group(:item_instance_code).sum(:qty)
|
||||||
|
itemList = []
|
||||||
|
saleObj.sale_orders.each do |so|
|
||||||
|
itemList << OrderItem.where("order_id = ?",so.order_id).group(:item_instance_code).sum(:qty)
|
||||||
|
end
|
||||||
|
return itemList
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.is_promo_day(promoList, day, orderitemList, sale_id)
|
def self.is_promo_day(promoList, day, orderitemList, sale_id)
|
||||||
@@ -46,13 +51,15 @@ 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
|
||||||
if promo.original_product.to_s == orderitem[0]
|
orderitem.each do |odr_item|
|
||||||
if promo.min_qty.to_i > orderitem[1].to_i
|
if promo.original_product.to_s == odr_item[0]
|
||||||
return false
|
if promo.min_qty.to_i > odr_item[1].to_i
|
||||||
else
|
return false
|
||||||
check_promo_type(promo,orderitem, sale_id)
|
else
|
||||||
end
|
check_promo_type(promo,odr_item, sale_id)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.check_promo_type(promo, orderitem, sale_id)
|
def self.check_promo_type(promo, orderitem, sale_id)
|
||||||
@@ -126,7 +133,6 @@ class Promotion < ApplicationRecord
|
|||||||
# AA - 10 # 3 # BB # orderList, #S34345
|
# AA - 10 # 3 # BB # orderList, #S34345
|
||||||
def self.give_promotion_second_product(orderitem_count, foc_min_qty, promo_product, orderitem, sale_id)
|
def self.give_promotion_second_product(orderitem_count, foc_min_qty, promo_product, orderitem, sale_id)
|
||||||
puts "..... orderitem_count: " + orderitem_count.to_s + " / foc_min_qty: " + foc_min_qty.to_s + " /promo_product: " + promo_product + " orderitem: " + orderitem.to_s
|
puts "..... orderitem_count: " + orderitem_count.to_s + " / foc_min_qty: " + foc_min_qty.to_s + " /promo_product: " + promo_product + " orderitem: " + orderitem.to_s
|
||||||
byebug
|
|
||||||
promotion_qty = orderitem_count.to_i / foc_min_qty.to_i # get foc item qty
|
promotion_qty = orderitem_count.to_i / foc_min_qty.to_i # get foc item qty
|
||||||
foc_qty = find_second_item_qty(sale_id, promo_product)
|
foc_qty = find_second_item_qty(sale_id, promo_product)
|
||||||
if (foc_qty < promotion_qty)
|
if (foc_qty < promotion_qty)
|
||||||
@@ -212,9 +218,11 @@ class Promotion < ApplicationRecord
|
|||||||
saleObj = Sale.find_by_sale_id(sale_id)
|
saleObj = Sale.find_by_sale_id(sale_id)
|
||||||
itemList = combine_item(saleObj)
|
itemList = combine_item(saleObj)
|
||||||
itemList.each do |item|
|
itemList.each do |item|
|
||||||
if item[0] == promo_item
|
item.each do |i|
|
||||||
return item[1]
|
if i[0] == promo_item
|
||||||
end
|
return i[1]
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -42,13 +42,13 @@
|
|||||||
|
|
||||||
<div class="row checkboxes">
|
<div class="row checkboxes">
|
||||||
<%= f.hidden_field :promo_day, :value => "", :class => "form-control col-md-1" %>
|
<%= f.hidden_field :promo_day, :value => "", :class => "form-control col-md-1" %>
|
||||||
<div class="col-md-1"><input class="select" type="checkbox" name="Sunday" value="0" id="0"> Sun</div>
|
<div class="col-md-1"><input class="selectDay" type="checkbox" name="Sunday" value="0" id="0"> Sun</div>
|
||||||
<div class="col-md-1"><input class="select" type="checkbox" name="Monday" value="1" id="1">Mon</div>
|
<div class="col-md-1"><input class="selectDay" type="checkbox" name="Monday" value="1" id="1">Mon</div>
|
||||||
<div class="col-md-1"><input class="select" type="checkbox" name="Tuesday" value="2" id="2"> Tue</div>
|
<div class="col-md-1"><input class="selectDay" type="checkbox" name="Tuesday" value="2" id="2"> Tue</div>
|
||||||
<div class="col-md-1"><input class="select" type="checkbox" name="Wednesday" value="3" id="3"> Wed</div>
|
<div class="col-md-1"><input class="selectDay" type="checkbox" name="Wednesday" value="3" id="3"> Wed</div>
|
||||||
<div class="col-md-1"><input class="select" type="checkbox" name="Thursday" value="4" id="4">Thu</div>
|
<div class="col-md-1"><input class="selectDay" type="checkbox" name="Thursday" value="4" id="4">Thu</div>
|
||||||
<div class="col-md-1"><input class="select" type="checkbox" name="Friday" value="5" id="5">Fri</div>
|
<div class="col-md-1"><input class="selectDay" type="checkbox" name="Friday" value="5" id="5">Fri</div>
|
||||||
<div class="col-md-1"><input class="select" type="checkbox" name="Saturday" value="6" id="6">Sat</div>
|
<div class="col-md-1"><input class="selectDay" type="checkbox" name="Saturday" value="6" id="6">Sat</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
@@ -166,12 +166,12 @@ $(document).ready(function(){
|
|||||||
|
|
||||||
|
|
||||||
var form = document.getElementById("new_promotion");
|
var form = document.getElementById("new_promotion");
|
||||||
var inputs = form.getElementsByTagName("input");
|
var inputs = $("input");
|
||||||
var arr = [];
|
var arr = [];
|
||||||
var count = 0;
|
var count = 0;
|
||||||
var day = "[";
|
var day = "[";
|
||||||
|
|
||||||
$(".select").click(function() {
|
$(".selectDay").click(function() {
|
||||||
|
|
||||||
// debugger;
|
// debugger;
|
||||||
day = "[";
|
day = "[";
|
||||||
|
|||||||
Reference in New Issue
Block a user