From f56b7ab26e09465d92b5d493fec58f9e11f2d866 Mon Sep 17 00:00:00 2001 From: Phyo Date: Tue, 5 Sep 2017 10:44:33 +0630 Subject: [PATCH 1/3] Promotion Destory Bug Fix --- app/controllers/settings/promotions_controller.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/controllers/settings/promotions_controller.rb b/app/controllers/settings/promotions_controller.rb index af8bedc1..4ab33dba 100644 --- a/app/controllers/settings/promotions_controller.rb +++ b/app/controllers/settings/promotions_controller.rb @@ -69,6 +69,9 @@ class Settings::PromotionsController < ApplicationController # DELETE /promotions/1 # DELETE /promotions/1.json def destroy + @promotion.promotion_products.each do |pp| + pp.destroy + end @promotion.destroy respond_to do |format| format.html { redirect_to settings_promotions_path, notice: 'Promotion was successfully destroyed.' } From 4ca3b708c4a8fd80fe82171b716e6a55567a9e6c Mon Sep 17 00:00:00 2001 From: Phyo Date: Wed, 6 Sep 2017 17:01:33 +0630 Subject: [PATCH 2/3] Show data in Edit --- .../settings/promotions_controller.rb | 15 +++++ app/models/promotion.rb | 2 +- app/views/settings/promotions/_form.html.erb | 58 ++++++++++++++----- config/routes.rb | 1 + 4 files changed, 59 insertions(+), 17 deletions(-) diff --git a/app/controllers/settings/promotions_controller.rb b/app/controllers/settings/promotions_controller.rb index 4ab33dba..8acc7764 100644 --- a/app/controllers/settings/promotions_controller.rb +++ b/app/controllers/settings/promotions_controller.rb @@ -90,6 +90,21 @@ class Settings::PromotionsController < ApplicationController 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 # Use callbacks to share common setup or constraints between actions. def set_promotion diff --git a/app/models/promotion.rb b/app/models/promotion.rb index 624818f1..41dfaec6 100644 --- a/app/models/promotion.rb +++ b/app/models/promotion.rb @@ -1,5 +1,5 @@ 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 diff --git a/app/views/settings/promotions/_form.html.erb b/app/views/settings/promotions/_form.html.erb index c832461d..477731a1 100644 --- a/app/views/settings/promotions/_form.html.erb +++ b/app/views/settings/promotions/_form.html.erb @@ -39,9 +39,10 @@ <% end %> - +
- <%= f.hidden_field :promo_day, :value => "", :class => "form-control col-md-1" %> +
+ <%= f.hidden_field :promo_day, :value => "", :class => "form-control" %>
Sun
Mon
Tue
@@ -50,7 +51,7 @@
Fri
Sat
- +
<%= f.input :promo_type,input_html: { class: "" }, @@ -73,11 +74,12 @@ <% code = menuiteminstance.menu_item.item_code %> <% end %> <% end %> + <% arr.each do |a| %> <% if a[1] == code %> <% else %> - + <% end %> <% end %> @@ -109,19 +111,23 @@
<%= f.fields_for :promotion_products do |pro| %>
+ <%= pro.hidden_field :item_code,:class => "promo_product" %> <% arr = MenuItem.active.order("name desc").pluck(:name,:item_code) %> <% Product.order("name desc").pluck(:name,:item_code).each do |p| %> <% arr.push(p) %> <% end %> -
+ - <% sample = [] %> -
<%= pro.input :item_code, :class => 'promoproduct', collection: sample,input_html: { selected: 2 }, label: false %>
+ + +
<%= pro.input :item_code, :class => 'promoproduct', collection:[],input_html: { selected: 2 }, label: false %>
+
<%= pro.input :min_qty , label: false%>
<%= pro.input :net_off , label: false %>
<%= pro.input :net_price , label: false %>
@@ -156,15 +162,12 @@ $(document).ready(function(){ $('#promotion_promo_start_hour').datetimepicker({ datepicker:false, format:'H:m' - }); + }); $('#promotion_promo_end_hour').datetimepicker({ datepicker:false, format:'H:m' }); - - - var form = document.getElementById("new_promotion"); var inputs = $("input"); var arr = []; @@ -197,7 +200,7 @@ $(".selectDay").click(function() { $("#promotion_original_product").select2(); $(".item_code_place").select2(); $(".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; $.ajax({ type: "GET", @@ -223,6 +226,28 @@ $(".selectDay").click(function() { callforpromoproduct(); }, 0); }); + + 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(""); + $("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(){ $(".item_code_place1").select2(); $(".item_code_place1").on('change', function(event) { @@ -234,16 +259,17 @@ $(".selectDay").click(function() { url: ajax_url, data: 'item_code=' + item_code, success: function (result) { - $("#"+id).empty(); + $("select#"+id).empty(); var itemlist; for (var i = 0; i < result.length; i++) { itemlist += "" } - $("#"+id).append(itemlist); - $("#"+id).select2(); + $("select#"+id).append(itemlist); + $("select#"+id).select2(); } }); }); } + }); diff --git a/config/routes.rb b/config/routes.rb index 8dcdb956..18f3c0b5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -299,6 +299,7 @@ Rails.application.routes.draw do resources :promotion_products end 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 resources :commissions From 9d4741429252894d6aec0a593071a67d67c5d18d Mon Sep 17 00:00:00 2001 From: Phyo Date: Wed, 6 Sep 2017 18:03:53 +0630 Subject: [PATCH 3/3] Timepicker Bug Fix --- app/views/settings/promotions/_form.html.erb | 30 ++++++++++++++------ 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/app/views/settings/promotions/_form.html.erb b/app/views/settings/promotions/_form.html.erb index 477731a1..1760f894 100644 --- a/app/views/settings/promotions/_form.html.erb +++ b/app/views/settings/promotions/_form.html.erb @@ -42,14 +42,14 @@
- <%= f.hidden_field :promo_day, :value => "", :class => "form-control" %> -
Sun
-
Mon
-
Tue
-
Wed
-
Thu
-
Fri
-
Sat
+ <%= f.hidden_field :promo_day, :class => "form-control" %> +
+
+
+
+
+
+

@@ -168,6 +168,19 @@ $(document).ready(function(){ 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 inputs = $("input"); var arr = []; @@ -227,6 +240,7 @@ $(".selectDay").click(function() { }, 0); }); + // for promotion products data showing var promopdt = $(".promo_product"); jQuery.each( promopdt, function( i, ppdt ) { var ajax_url = "<%= settings_find_parent_item_path %>";