Merge branch 'august_spring' of bitbucket.org:code2lab/sxrestaurant into august_spring
* 'august_spring' of bitbucket.org:code2lab/sxrestaurant: Timepicker Bug Fix Show data in Edit Promotion Destory Bug Fix
This commit is contained in:
@@ -69,6 +69,9 @@ class Settings::PromotionsController < ApplicationController
|
|||||||
# DELETE /promotions/1
|
# DELETE /promotions/1
|
||||||
# DELETE /promotions/1.json
|
# DELETE /promotions/1.json
|
||||||
def destroy
|
def destroy
|
||||||
|
@promotion.promotion_products.each do |pp|
|
||||||
|
pp.destroy
|
||||||
|
end
|
||||||
@promotion.destroy
|
@promotion.destroy
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { redirect_to settings_promotions_path, notice: 'Promotion was successfully destroyed.' }
|
format.html { redirect_to settings_promotions_path, notice: 'Promotion was successfully destroyed.' }
|
||||||
@@ -87,6 +90,21 @@ class Settings::PromotionsController < ApplicationController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def find_parent_item
|
||||||
|
res = []
|
||||||
|
item = MenuItemInstance.find_by_item_instance_code(params[:item_instance_code])
|
||||||
|
if item.nil?
|
||||||
|
product = Product.where("item_code = ?",params[:item_instance_code]).pluck(:name,:item_code)
|
||||||
|
res.push(product.name)
|
||||||
|
res.push(product.item_code)
|
||||||
|
else
|
||||||
|
# menu_item = item.menu_item.pluck(:name,:item_code)
|
||||||
|
res.push(item.item_instance_name)
|
||||||
|
res.push(item.menu_item.item_code)
|
||||||
|
end
|
||||||
|
render json: res
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
# Use callbacks to share common setup or constraints between actions.
|
# Use callbacks to share common setup or constraints between actions.
|
||||||
def set_promotion
|
def set_promotion
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
class Promotion < ApplicationRecord
|
class Promotion < ApplicationRecord
|
||||||
validates_presence_of :promo_code,:promo_start_date,:promo_end_date,:promo_start_hour,:promo_end_hour,:promo_day,:promo_type,:original_product,:min_qty
|
validates_presence_of :promo_code,:promo_start_date,:promo_end_date,:promo_start_hour,:promo_end_hour,:promo_type,:original_product,:min_qty
|
||||||
|
|
||||||
has_many :promotion_products
|
has_many :promotion_products
|
||||||
|
|
||||||
|
|||||||
@@ -39,18 +39,19 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<br>
|
||||||
<div class="row checkboxes">
|
<div class="row checkboxes">
|
||||||
<%= f.hidden_field :promo_day, :value => "", :class => "form-control col-md-1" %>
|
<div class="col-md-2"><label class="control-label"><abbr title="required">*</abbr> Promotion Day</label></div>
|
||||||
<div class="col-md-1"><input class="selectDay" type="checkbox" name="Sunday" value="0" id="0"> Sun</div>
|
<%= f.hidden_field :promo_day, :class => "form-control" %>
|
||||||
<div class="col-md-1"><input class="selectDay" type="checkbox" name="Monday" value="1" id="1">Mon</div>
|
<div class="col-md-1"><label><input class="selectDay" type="checkbox" name="Sunday" value="0" id="0"> Sun</label></div>
|
||||||
<div class="col-md-1"><input class="selectDay" type="checkbox" name="Tuesday" value="2" id="2"> Tue</div>
|
<div class="col-md-1"><label><input class="selectDay" type="checkbox" name="Monday" value="1" id="1">Mon</label></div>
|
||||||
<div class="col-md-1"><input class="selectDay" type="checkbox" name="Wednesday" value="3" id="3"> Wed</div>
|
<div class="col-md-1"><label><input class="selectDay" type="checkbox" name="Tuesday" value="2" id="2"> Tue</label></div>
|
||||||
<div class="col-md-1"><input class="selectDay" type="checkbox" name="Thursday" value="4" id="4">Thu</div>
|
<div class="col-md-1"><label><input class="selectDay" type="checkbox" name="Wednesday" value="3" id="3"> Wed</label></div>
|
||||||
<div class="col-md-1"><input class="selectDay" type="checkbox" name="Friday" value="5" id="5">Fri</div>
|
<div class="col-md-1"><label><input class="selectDay" type="checkbox" name="Thursday" value="4" id="4"> Thu</label></div>
|
||||||
<div class="col-md-1"><input class="selectDay" type="checkbox" name="Saturday" value="6" id="6">Sat</div>
|
<div class="col-md-1"><label><input class="selectDay" type="checkbox" name="Friday" value="5" id="5"> Fri</label></div>
|
||||||
|
<div class="col-md-1"><label><input class="selectDay" type="checkbox" name="Saturday" value="6" id="6"> Sat</label></div>
|
||||||
</div>
|
</div>
|
||||||
|
<br>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<%= f.input :promo_type,input_html: { class: "" },
|
<%= f.input :promo_type,input_html: { class: "" },
|
||||||
@@ -73,11 +74,12 @@
|
|||||||
<% code = menuiteminstance.menu_item.item_code %>
|
<% code = menuiteminstance.menu_item.item_code %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
<option value="" selected>Choose Something</option>
|
||||||
<% arr.each do |a| %>
|
<% arr.each do |a| %>
|
||||||
<% if a[1] == code %>
|
<% if a[1] == code %>
|
||||||
<option value="<%= a[1]%>" selected><%= a[0] %></option>
|
<option value="<%= a[1]%>" selected><%= a[0] %></option>
|
||||||
<% else %>
|
<% else %>
|
||||||
<option value="<%= a[1]%>"><%= a[0] %></option>
|
<option value="<%= a[1]%>"><%= a[0] %></option>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</select>
|
</select>
|
||||||
@@ -109,19 +111,23 @@
|
|||||||
<div class="row"></div >
|
<div class="row"></div >
|
||||||
<%= f.fields_for :promotion_products do |pro| %>
|
<%= f.fields_for :promotion_products do |pro| %>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
<%= pro.hidden_field :item_code,:class => "promo_product" %>
|
||||||
<% arr = MenuItem.active.order("name desc").pluck(:name,:item_code) %>
|
<% arr = MenuItem.active.order("name desc").pluck(:name,:item_code) %>
|
||||||
<% Product.order("name desc").pluck(:name,:item_code).each do |p| %>
|
<% Product.order("name desc").pluck(:name,:item_code).each do |p| %>
|
||||||
<% arr.push(p) %>
|
<% arr.push(p) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<div class="col-md-2" style="text-align:left">
|
<div class="col-md-2 menu_item_choose" style="text-align:left">
|
||||||
<select class="form-control item_code_place1">
|
<select class="form-control item_code_place1">
|
||||||
|
<option value="">Choose Something</option>
|
||||||
<% arr.each do |a| %>
|
<% arr.each do |a| %>
|
||||||
<option value="<%= a[1 ]%>"><%= a[0] %></option>
|
<option value="<%= a[1 ]%>"><%= a[0] %></option>
|
||||||
<% end %>
|
<% end %>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<% sample = [] %>
|
<!-- <% sample = [] %> -->
|
||||||
<div class="col-md-2" style="text-align:left"><%= pro.input :item_code, :class => 'promoproduct', collection: sample,input_html: { selected: 2 }, label: false %></div>
|
|
||||||
|
<div class="col-md-2" style="text-align:left"><%= pro.input :item_code, :class => 'promoproduct', collection:[],input_html: { selected: 2 }, label: false %></div>
|
||||||
|
|
||||||
<div class="col-md-2"><%= pro.input :min_qty , label: false%></div>
|
<div class="col-md-2"><%= pro.input :min_qty , label: false%></div>
|
||||||
<div class="col-md-2"><%= pro.input :net_off , label: false %></div>
|
<div class="col-md-2"><%= pro.input :net_off , label: false %></div>
|
||||||
<div class="col-md-2"><%= pro.input :net_price , label: false %></div>
|
<div class="col-md-2"><%= pro.input :net_price , label: false %></div>
|
||||||
@@ -156,14 +162,24 @@ $(document).ready(function(){
|
|||||||
$('#promotion_promo_start_hour').datetimepicker({
|
$('#promotion_promo_start_hour').datetimepicker({
|
||||||
datepicker:false,
|
datepicker:false,
|
||||||
format:'H:m'
|
format:'H:m'
|
||||||
});
|
});
|
||||||
$('#promotion_promo_end_hour').datetimepicker({
|
$('#promotion_promo_end_hour').datetimepicker({
|
||||||
datepicker:false,
|
datepicker:false,
|
||||||
format:'H:m'
|
format:'H:m'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('#promotion_promo_start_hour').on('change', function(event) {
|
||||||
|
$('#promotion_promo_start_hour').val($('#promotion_promo_start_hour').val().split(":")[0]+":00");
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#promotion_promo_end_hour').on('change', function(event) {
|
||||||
|
$('#promotion_promo_end_hour').val($('#promotion_promo_end_hour').val().split(":")[0]+":00");
|
||||||
|
});
|
||||||
|
|
||||||
|
var dayy = $("#promotion_promo_day").val().replace("[","").replace("]","");
|
||||||
|
jQuery.each( dayy.split(","), function( i, d ) {
|
||||||
|
$("input.selectDay[value='"+d+"']").prop( "checked", true );
|
||||||
|
});
|
||||||
|
|
||||||
var form = document.getElementById("new_promotion");
|
var form = document.getElementById("new_promotion");
|
||||||
var inputs = $("input");
|
var inputs = $("input");
|
||||||
@@ -197,7 +213,7 @@ $(".selectDay").click(function() {
|
|||||||
$("#promotion_original_product").select2();
|
$("#promotion_original_product").select2();
|
||||||
$(".item_code_place").select2();
|
$(".item_code_place").select2();
|
||||||
$(".item_code_place").on('change', function(event) {
|
$(".item_code_place").on('change', function(event) {
|
||||||
var ajax_url = "<%= settings_find_item_instance_path %>";
|
var ajax_url = "<%= settings_find_item_instance_path %>";
|
||||||
var item_code = this.value;
|
var item_code = this.value;
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "GET",
|
type: "GET",
|
||||||
@@ -223,6 +239,29 @@ $(".selectDay").click(function() {
|
|||||||
callforpromoproduct();
|
callforpromoproduct();
|
||||||
}, 0);
|
}, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// for promotion products data showing
|
||||||
|
var promopdt = $(".promo_product");
|
||||||
|
jQuery.each( promopdt, function( i, ppdt ) {
|
||||||
|
var ajax_url = "<%= settings_find_parent_item_path %>";
|
||||||
|
var item_code = ppdt.value;
|
||||||
|
var select_id = ppdt.id;
|
||||||
|
$.ajax({
|
||||||
|
type: "GET",
|
||||||
|
url: ajax_url,
|
||||||
|
data: 'item_instance_code=' + item_code,
|
||||||
|
success: function (result) {
|
||||||
|
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")
|
||||||
|
$("select#"+select_id).parent().parent().siblings("div.menu_item_choose").find("select").select2();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// promotion_promotion_products_attributes_0_item_code
|
||||||
function callforpromoproduct(){
|
function callforpromoproduct(){
|
||||||
$(".item_code_place1").select2();
|
$(".item_code_place1").select2();
|
||||||
$(".item_code_place1").on('change', function(event) {
|
$(".item_code_place1").on('change', function(event) {
|
||||||
@@ -234,16 +273,17 @@ $(".selectDay").click(function() {
|
|||||||
url: ajax_url,
|
url: ajax_url,
|
||||||
data: 'item_code=' + item_code,
|
data: 'item_code=' + item_code,
|
||||||
success: function (result) {
|
success: function (result) {
|
||||||
$("#"+id).empty();
|
$("select#"+id).empty();
|
||||||
var itemlist;
|
var itemlist;
|
||||||
for (var i = 0; i < result.length; i++) {
|
for (var i = 0; i < result.length; i++) {
|
||||||
itemlist += "<option value ="+result[i][1]+">"+result[i][0]+"</option>"
|
itemlist += "<option value ="+result[i][1]+">"+result[i][0]+"</option>"
|
||||||
}
|
}
|
||||||
$("#"+id).append(itemlist);
|
$("select#"+id).append(itemlist);
|
||||||
$("#"+id).select2();
|
$("select#"+id).select2();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -299,6 +299,7 @@ Rails.application.routes.draw do
|
|||||||
resources :promotion_products
|
resources :promotion_products
|
||||||
end
|
end
|
||||||
get '/find_item_instance' => 'promotions#find_item_instance', as:'find_item_instance'
|
get '/find_item_instance' => 'promotions#find_item_instance', as:'find_item_instance'
|
||||||
|
get '/find_parent_item' => 'promotions#find_parent_item', as:'find_parent_item'
|
||||||
|
|
||||||
# commission
|
# commission
|
||||||
resources :commissions
|
resources :commissions
|
||||||
|
|||||||
Reference in New Issue
Block a user