change promotion with menu item and menu item instance
This commit is contained in:
@@ -106,39 +106,39 @@
|
||||
</div>
|
||||
-->
|
||||
<div class="row">
|
||||
<% arr = MenuItem.active.order("name desc").pluck(:name,:item_code) %>
|
||||
<% arr = MenuItem.active.joins("JOIN menu_item_instances as b ON b.menu_item_id=menu_items.id").group("menu_items.id").order("name desc").pluck(:name,:item_code) %>
|
||||
<% Product.order("name desc").pluck(:name,:item_code).each do |p| %>
|
||||
<% arr.push(p) %>
|
||||
<% arr.push(p) %>
|
||||
<% end %>
|
||||
<div class="col-md-3 form-group">
|
||||
<label class="control-label"><abbr title="required">*</abbr> Item</label>
|
||||
<select class="form-control item_code_place">
|
||||
<% if !@promotion.original_product.nil? %>
|
||||
<% menuiteminstance = MenuItemInstance.find_by_item_instance_code(@promotion.original_product) %>
|
||||
<% if menuiteminstance.nil?%>
|
||||
<% code = @promotion.original_product %>
|
||||
<% else %>
|
||||
<% code = menuiteminstance.menu_item.item_code %>
|
||||
<% end %>
|
||||
<% menuiteminstance = MenuItemInstance.find_by_item_instance_code(@promotion.original_product) %>
|
||||
<% if menuiteminstance.nil?%>
|
||||
<% code = @promotion.original_product %>
|
||||
<% else %>
|
||||
<% code = menuiteminstance.menu_item.item_code %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<option value="" selected>Choose Something</option>
|
||||
<% arr.each do |a| %>
|
||||
<% if a[1] == code %>
|
||||
<option value="<%= a[1]%>" selected><%= a[0] %></option>
|
||||
<% else %>
|
||||
<option value="<%= a[1]%>"><%= a[0] %></option>
|
||||
<% end %>
|
||||
<% if a[1] == code %>
|
||||
<option value="<%= a[1]%>" selected><%= a[0] %></option>
|
||||
<% else %>
|
||||
<option value="<%= a[1]%>"><%= a[0] %></option>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<% sample = [] %>
|
||||
<% if !@promotion.original_product.nil? %>
|
||||
<% if !MenuItemInstance.find_by_item_instance_code(@promotion.original_product).nil? %>
|
||||
<% sample = MenuItemInstance.where("item_instance_code=?",@promotion.original_product).pluck(:item_instance_name,:item_instance_code)%>
|
||||
<% else %>
|
||||
<% sample = Product.where("item_code=?",@promotion.original_product).pluck(:name,:item_code)%>
|
||||
<% end %>
|
||||
<% if !MenuItemInstance.find_by_item_instance_code(@promotion.original_product).nil? %>
|
||||
<% sample = MenuItemInstance.where("item_instance_code=?",@promotion.original_product).pluck(:item_instance_name,:item_instance_code)%>
|
||||
<% else %>
|
||||
<% sample = Product.where("item_code=?",@promotion.original_product).pluck(:name,:item_code)%>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<div class="col-md-3 form-group"><%= f.input :original_product,collection: sample %></div>
|
||||
<!-- <div class="col-md-6"><%= f.input :original_product,collection: MenuItemInstance.order("item_instance_name desc").pluck(:item_instance_name,:item_instance_code),input_html: { selected: 2 } %></div> -->
|
||||
@@ -160,7 +160,7 @@
|
||||
<%= f.fields_for :promotion_products do |pro| %>
|
||||
<div class="row">
|
||||
<%= pro.hidden_field :item_code,:class => "promo_product" %>
|
||||
<% arr = MenuItem.active.order("name desc").pluck(:name,:item_code) %>
|
||||
<% arr = MenuItem.joins("JOIN menu_item_instances as b ON b.menu_item_id=menu_items.id").group("menu_items.id").order("name desc").pluck(:name,:item_code) %>
|
||||
<% Product.order("name desc").pluck(:name,:item_code).each do |p| %>
|
||||
<% arr.push(p) %>
|
||||
<% end %>
|
||||
@@ -247,9 +247,10 @@
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
|
||||
$(document).ready(function(){
|
||||
if(($('.item_code_place').val()!=undefined) && ($('.item_code_place').val()!="")){
|
||||
getItemInstance($('.item_code_place').val());
|
||||
}
|
||||
|
||||
$('#promotion_promo_start_hour').on('change', function(event) {
|
||||
$('#promotion_promo_start_hour').val($('#promotion_promo_start_hour').val().split(":")[0]+":00");
|
||||
@@ -273,7 +274,7 @@
|
||||
});
|
||||
|
||||
var dayy = $("#promotion_promo_day").val().replace("[","").replace("]","");
|
||||
jQuery.each( dayy.split(","), function( i, d ) {
|
||||
$.each( dayy.split(","), function( i, d ) {
|
||||
$("input.selectDay[value='"+d+"']").prop( "checked", true );
|
||||
});
|
||||
|
||||
@@ -324,8 +325,13 @@
|
||||
// $(".item_code_place").select2();
|
||||
|
||||
$(".item_code_place").on('change', function(event) {
|
||||
var ajax_url = "<%= settings_find_item_instance_path %>";
|
||||
var item_code = this.value;
|
||||
getItemInstance(item_code);
|
||||
});
|
||||
|
||||
function getItemInstance(item_code) {
|
||||
var ajax_url = "<%= settings_find_item_instance_path %>";
|
||||
var original_product = "<%= @promotion.original_product %>";
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: ajax_url,
|
||||
@@ -334,13 +340,15 @@
|
||||
$("#promotion_original_product").empty();
|
||||
var itemlist;
|
||||
for (var i = 0; i < result.length; i++) {
|
||||
itemlist += "<option value ="+result[i][1]+">"+result[i][0]+"</option>"
|
||||
var selected = "";
|
||||
if(original_product == result[i][1]) selected = "selected";
|
||||
itemlist += "<option value ="+result[i][1]+" "+selected+">"+result[i][0]+"</option>"
|
||||
}
|
||||
$("#promotion_original_product").append(itemlist);
|
||||
//$("#promotion_original_product").select2();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//$(".promotion_promotion_products_item_code select").select2();
|
||||
//$(".item_code_place1").select2();
|
||||
@@ -356,7 +364,7 @@
|
||||
|
||||
// for promotion products data showing
|
||||
var promopdt = $(".promo_product");
|
||||
jQuery.each( promopdt, function( i, ppdt ) {
|
||||
$.each( promopdt, function( i, ppdt ) {
|
||||
var ajax_url = "<%= settings_find_parent_item_path %>";
|
||||
var item_code = ppdt.value;
|
||||
var select_id = ppdt.id;
|
||||
@@ -365,14 +373,33 @@
|
||||
url: ajax_url,
|
||||
data: 'item_instance_code=' + item_code,
|
||||
success: function (result) {
|
||||
// console.log(result);
|
||||
var par_item_code = "";
|
||||
var arr_item_inst = "";
|
||||
if((result[0]!=undefined) && (result[0]!="")){
|
||||
$.each(result[0],function(k,val){
|
||||
par_item_code = k;
|
||||
arr_item_inst = val;
|
||||
});
|
||||
}
|
||||
|
||||
if(result.length > 0){
|
||||
$("select#"+select_id).empty();
|
||||
$("select#"+select_id).append("<option value='"+item_code+"'>"+result[0]+"</option>");
|
||||
$("select#"+select_id).parent().parent().siblings("div.menu_item_choose").find("select").find("option[value='"+result[1]+"']").attr("selected","true")
|
||||
var iteminstlists;
|
||||
$.each(arr_item_inst,function(k2,v2al){
|
||||
$("select#"+select_id).empty();
|
||||
var selected = "";
|
||||
$.each(v2al,function(k3,v3al){
|
||||
if(k3 == item_code) selected = "selected";
|
||||
iteminstlists += "<option value='"+k3+"' "+selected+">"+v3al+"</option>";
|
||||
});
|
||||
});
|
||||
$("select#"+select_id).append(iteminstlists);
|
||||
|
||||
$("select#"+select_id).parent().parent().siblings("div.menu_item_choose").find("select").find("option[value='"+par_item_code+"']").attr("selected","true")
|
||||
// $("select#"+select_id).parent().parent().siblings("div.menu_item_choose").find("select").select2();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// promotion_promotion_products_attributes_0_item_code
|
||||
@@ -394,8 +421,8 @@
|
||||
}
|
||||
$("select#"+id).append(itemlist);
|
||||
//$("select#"+id).select2();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user