diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 705b1a97..5c3fb862 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -3,17 +3,14 @@ - - - - - - + + + - + @@ -28,7 +25,7 @@ - + @@ -55,41 +52,51 @@ - + - - + + - - + + - - + + - + - - + + - - + + - - + + + + + + + + + + + + @@ -98,42 +105,23 @@ - - - - - - - - - - - - - - - - - - - - - - + + - - - + + + + - - + + - - + + @@ -173,10 +161,6 @@ @@ -756,12 +744,12 @@ - + - @@ -774,7 +762,6 @@ - @@ -784,9 +771,9 @@ - + - + @@ -804,51 +791,11 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1088,7 +1035,7 @@ - + @@ -1106,7 +1053,7 @@ - + @@ -1151,18 +1098,18 @@ - + - - + + - + - - + + @@ -1179,42 +1126,87 @@ - + + + + + + + + + + + + + + + + + - + - + - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + diff --git a/app/controllers/origami/in_juties_controller.rb b/app/controllers/origami/in_juties_controller.rb index 6ac04659..ff76d3b1 100644 --- a/app/controllers/origami/in_juties_controller.rb +++ b/app/controllers/origami/in_juties_controller.rb @@ -1,5 +1,5 @@ class Origami::InJutiesController < BaseOrigamiController - before_action :set_in_juty, only: [:show, :edit, :update, :edit_in_juty, :update_for_in_juty , :destroy ,:destroy_in_juty] + before_action :set_in_juty, only: %i[show edit update edit_in_juty update_for_in_juty destroy destroy_in_juty] # GET /in_juties # GET /in_juties.json @@ -8,11 +8,12 @@ class Origami::InJutiesController < BaseOrigamiController end def index_in_juty - @juty_in= InJuty.where("dinning_id=?",params[:table_id]) + @juty_in = InJuty.where('dinning_id=?', params[:table_id]) @table = DiningFacility.find(params[:table_id]) - @in_juty = InJuty.new + @in_juty = InJuty.new @juties_in = Kaminari.paginate_array(@juty_in).page(params[:page]).per(10) end + # GET /in_juties/1 # GET /in_juties/1.json def show @@ -20,12 +21,15 @@ class Origami::InJutiesController < BaseOrigamiController # GET /in_juties/new def new + # this one use for new @in_juty = InJuty.new + @table = DiningFacility.find(params[:table_id]) + @commissioner = @in_juty.commissioner + render partial: 'form' end # GET /in_juties/1/edit def edit - end def edit_in_juty @@ -33,13 +37,15 @@ class Origami::InJutiesController < BaseOrigamiController @table = DiningFacility.find(params[:table_id]) @commissioner = @in_juty.commissioner - render json: {in_juty: @in_juty, commissioner: @commissioner} + # render json: {in_juty: @in_juty, commissioner: @commissioner} + render partial: 'form' end def assign_in_juty @in_juty = InJuty.new @table = DiningFacility.find(params[:table_id]) end + # POST /in_juties # POST /in_juties.json def create @@ -57,32 +63,53 @@ class Origami::InJutiesController < BaseOrigamiController end def create_for_in_juty + # this one use for create and update + in_juty = in_juty_params + in_time = DateTime.new in_juty['in_time(1i)'].to_i, in_juty['in_time(2i)'].to_i, in_juty['in_time(3i)'].to_i, in_juty['in_time(4i)'].to_i, in_juty['in_time(5i)'].to_i + in_time = in_time.change(offset: '+06:30') + out_time = DateTime.new in_juty['out_time(1i)'].to_i, in_juty['out_time(2i)'].to_i, in_juty['out_time(3i)'].to_i, in_juty['out_time(4i)'].to_i, in_juty['out_time(5i)'].to_i + out_time = out_time.change(offset: '+06:30') @in_juty = InJuty.new + in_juty_id = in_juty[:id] + unless in_juty_id.nil? + @in_juty = InJuty.find(in_juty_id.to_i) + end @in_juty.dinning_id = in_juty_params[:dinning_id] @in_juty.commissioner_ids = in_juty_params[:commissioner_ids] - @in_juty.in_time = in_juty_params[:in_time] - @in_juty.out_time = in_juty_params[:out_time] - + @in_juty.in_time = in_time + @in_juty.out_time = out_time respond_to do |format| if @in_juty.save - format.html { redirect_to origami_index_in_juty_path(in_juty_params[:dinning_id]), notice: 'In juty was successfully created.' } - format.json { render :show, status: :created, location: @in_juty } + if in_juty_id.nil? + format.html { redirect_to origami_index_in_juty_path(in_juty_params[:dinning_id]), notice: 'In juty was successfully created.' } + format.json { render :show, status: :created, location: @in_juty } + else + format.html { redirect_to origami_index_in_juty_path(in_juty_params[:dinning_id]), notice: 'In juty was successfully updated.' } + format.json { render :show, status: :created, location: @in_juty } + end else format.html { render :new } format.json { render json: @in_juty.errors, status: :unprocessable_entity } end end - end # PATCH/PUT /in_juties/1 # PATCH/PUT /in_juties/1.json def update + in_juty = in_juty_params + in_time = DateTime.new in_juty['in_time(1i)'].to_i, in_juty['in_time(2i)'].to_i, in_juty['in_time(3i)'].to_i, in_juty['in_time(4i)'].to_i, in_juty['in_time(5i)'].to_i + in_time = in_time.change(offset: '+06:30') + out_time = DateTime.new in_juty['out_time(1i)'].to_i, in_juty['out_time(2i)'].to_i, in_juty['out_time(3i)'].to_i, in_juty['out_time(4i)'].to_i, in_juty['out_time(5i)'].to_i + out_time = out_time.change(offset: '+06:30') + @in_juty.commissioner_ids = in_juty_params[:commissioner_ids] + @in_juty.in_time = in_time + @in_juty.out_time = out_time respond_to do |format| - if @in_juty.update(in_juty_params) - format.html { redirect_to origami_in_juty_path(@in_juty), notice: 'In juty was successfully updated.' } + if @in_juty.save + format.html { redirect_to origami_index_in_juty_path(in_juty_params[:dinning_id]), notice: 'In juty was successfully updated.' } format.json { render :show, status: :ok, location: @in_juty } else format.html { render :edit } @@ -91,28 +118,32 @@ class Origami::InJutiesController < BaseOrigamiController end end - - def update_for_in_juty - @in_juty.commissioner_ids = in_juty_params[:commissioner_ids] - @in_juty.in_time = in_juty_params[:in_time] - @in_juty.out_time = in_juty_params[:out_time] - respond_to do |format| - if @in_juty.save - format.html { redirect_to origami_index_in_juty_path(in_juty_params[:dinning_id]), notice: 'In juty was successfully updated.' } - format.json { render :show, status: :ok, location: @in_juty } - else - format.html { render :edit } - format.json { render json: @in_juty.errors, status: :unprocessable_entity } - end - end + def update_for_in_juty + in_juty = in_juty_params + in_time = DateTime.new in_juty['in_time(1i)'].to_i, in_juty['in_time(2i)'].to_i, in_juty['in_time(3i)'].to_i, in_juty['in_time(4i)'].to_i, in_juty['in_time(5i)'].to_i + in_time = in_time.change(offset: '+06:30') + out_time = DateTime.new in_juty['out_time(1i)'].to_i, in_juty['out_time(2i)'].to_i, in_juty['out_time(3i)'].to_i, in_juty['out_time(4i)'].to_i, in_juty['out_time(5i)'].to_i + out_time = out_time.change(offset: '+06:30') + @in_juty.commissioner_ids = in_juty_params[:commissioner_ids] + @in_juty.in_time = in_time + @in_juty.out_time = out_time + respond_to do |format| + if @in_juty.save + format.html { redirect_to origami_index_in_juty_path(in_juty_params[:dinning_id]), notice: 'In juty was successfully updated.' } + format.json { render :show, status: :ok, location: @in_juty } + else + format.html { render :edit } + format.json { render json: @in_juty.errors, status: :unprocessable_entity } + end end + end # DELETE /in_juties/1 # DELETE /in_juties/1.json def destroy @in_juty.destroy respond_to do |format| - format.html { redirect_to origami_in_juties_path, notice: 'In juty was successfully destroyed.' } + format.html { redirect_to origami_in_juties_path, notice: 'In juty was successfully removed.' } format.json { head :no_content } end end @@ -122,19 +153,20 @@ class Origami::InJutiesController < BaseOrigamiController @in_juty.destroy respond_to do |format| - format.html { redirect_to origami_index_in_juty_path(@table_id), notice: 'In juty was successfully destroyed.' } + format.html { redirect_to origami_index_in_juty_path(@table_id), notice: 'In juty was successfully removed.' } format.json { head :no_content } end end private - # Use callbacks to share common setup or constraints between actions. - def set_in_juty - @in_juty = InJuty.find(params[:id]) - end - # Never trust parameters from the scary internet, only allow the white list through. - def in_juty_params - params.require(:in_juty).permit(:id,:dinning_id,:commissioner_ids,:in_time,:out_time) - end + # Use callbacks to share common setup or constraints between actions. + def set_in_juty + @in_juty = InJuty.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def in_juty_params + params.require(:in_juty).permit(:id, :dinning_id, :commissioner_ids, :in_time, :out_time) + end end diff --git a/app/controllers/settings/promotions_controller.rb b/app/controllers/settings/promotions_controller.rb index ef972df9..af8bedc1 100644 --- a/app/controllers/settings/promotions_controller.rb +++ b/app/controllers/settings/promotions_controller.rb @@ -76,6 +76,17 @@ class Settings::PromotionsController < ApplicationController end end + def find_item_instance + item = MenuItem.find_by_item_code(params[:item_code]) + if item.nil? + product = Product.where("item_code = ?",params[:item_code]).pluck(:name,:item_code) + render json: product + else + menu_instance = MenuItemInstance.where("menu_item_id = ?",item.id).pluck(:item_instance_name,:item_instance_code) + render json: menu_instance + end + end + private # Use callbacks to share common setup or constraints between actions. def set_promotion diff --git a/app/models/menu_item.rb b/app/models/menu_item.rb index e7f53dcd..7ea5c3ad 100644 --- a/app/models/menu_item.rb +++ b/app/models/menu_item.rb @@ -19,6 +19,7 @@ class MenuItem < ApplicationRecord scope :simple_menu_item, -> { where(type: 'SimpleMenuItem') } scope :set_menu_item, -> { where(type: 'SetMenuItem') } + scope :active, -> { where(is_available: true) } # Item Image Uploader mount_uploader :image_path, MenuItemImageUploader diff --git a/app/models/promotion.rb b/app/models/promotion.rb index d60f25a9..dfab86e9 100644 --- a/app/models/promotion.rb +++ b/app/models/promotion.rb @@ -23,7 +23,7 @@ class Promotion < ApplicationRecord end def self.is_between_promo_datetime(current_day,current_time) #database is not local time - promoList = Promotion.where("(date_format(promo_start_date, 'YYYY-MM-DD') <=? AND date_format(promo_end_date, 'YYYY-MM-DD') >=?) AND (promo_start_hour < ? AND promo_end_hour > ?)", current_day, current_day, current_time, current_time) + promoList = Promotion.where("(TO_CHAR(promo_start_date, 'YYYY-MM-DD') <=? AND TO_CHAR(promo_end_date, 'YYYY-MM-DD') >=?) AND (promo_start_hour < ? AND promo_end_hour > ?)", current_day, current_day, current_time, current_time) return promoList end @@ -45,8 +45,8 @@ class Promotion < ApplicationRecord end def self.find_promo_item(promo, orderitem, sale_id) - item_code = OrderItem.find_by_item_instance_code(orderitem[0]).item_code - if promo.original_product.to_s == item_code + # item_code = OrderItem.find_by_item_instance_code(orderitem[0]).item_code + if promo.original_product.to_s == orderitem[0] if promo.min_qty.to_i > orderitem[1].to_i return false else @@ -77,7 +77,7 @@ class Promotion < ApplicationRecord def self.check_giveaway_product(promo, orderitem) promo.promotion_products.each do |promo_product| - if promo_product.item_code == OrderItem.find_by_item_instance_code(orderitem).item_code + if promo_product.item_code == orderitem return true, promo_product else return false, promo_product @@ -113,12 +113,11 @@ class Promotion < ApplicationRecord charge_qty += qty end item = OrderItem.find_by_item_instance_code(orderitem[0]) - byebug - # if promo_product == OrderItem.find_by_item_instance_code(orderitem[0]).item_code - # item = OrderItem.find_by_item_instance_code(orderitem[0]) - # else - # item = OrderItem.find_by_item_code(promo_product) - # end + if promo_product == OrderItem.find_by_item_instance_code(orderitem[0]).item_code + item = OrderItem.find_by_item_instance_code(orderitem[0]) + else + item = OrderItem.find_by_item_code(promo_product) + end update_existing_item(foc_qty, item, sale_id, "promotion", item.price) puts "Charged - " + charge_qty.to_s @@ -127,12 +126,13 @@ class Promotion < ApplicationRecord # AA - 10 # 3 # BB # orderList, #S34345 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 + byebug 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) if (foc_qty < promotion_qty) promotion_qty = foc_qty end - item = OrderItem.find_by_item_instance_code(promo_product,orderID) + item = OrderItem.find_by_item_instance_code(promo_product) update_existing_item(promotion_qty, item, sale_id, "promotion", item.price) end @@ -152,7 +152,6 @@ class Promotion < ApplicationRecord sale_item.is_taxable = false sale_item.sale_id = sale_id - sale_item.save sale = Sale.find(sale_id) sale.compute_by_sale_items(sale.id, sale.sale_items, sale.total_discount) @@ -163,7 +162,7 @@ class Promotion < ApplicationRecord puts " same: " + same.to_s + " promo_product: " + promo_product.item_code.to_s + " foc_min_qty: " + foc_min_qty.to_s + " orderitem: " + orderitem.to_s if same - foc_qty = orderitem[1].to_i / foc_min_qty + foc_qty = orderitem[1].to_i / foc_min_qty item = OrderItem.find_by_item_instance_code(orderitem[0]) update_existing_item(foc_qty, item, sale_id, "promotion nett off", promo_product.net_off) else @@ -213,7 +212,7 @@ class Promotion < ApplicationRecord saleObj = Sale.find_by_sale_id(sale_id) itemList = combine_item(saleObj) itemList.each do |item| - if OrderItem.find_by_item_instance_code(item[0]).item_code == promo_item + if item[0] == promo_item return item[1] end end diff --git a/app/views/origami/in_juties/_assign_in_juty.html.erb b/app/views/origami/in_juties/_assign_in_juty.html.erb index 62531529..b6363195 100644 --- a/app/views/origami/in_juties/_assign_in_juty.html.erb +++ b/app/views/origami/in_juties/_assign_in_juty.html.erb @@ -18,7 +18,7 @@ <%= f.input :in_time, :placeholder => "From Date", :class => "form-control" %> - <%= f.input :out_time, :placeholder => "From Date", :class => "form-control" %> + <%= f.input :out_time, :placeholder => "To Date", :class => "form-control" %>
diff --git a/app/views/origami/in_juties/_edit_in_juty.html.erb b/app/views/origami/in_juties/_edit_in_juty.html.erb index 9eaf8353..a297ac65 100644 --- a/app/views/origami/in_juties/_edit_in_juty.html.erb +++ b/app/views/origami/in_juties/_edit_in_juty.html.erb @@ -1,13 +1,14 @@ -<%= simple_form_for([:origami,@in_juty]) do |f| %> - <%= f.error_notification %> +<%= simple_form_for([:origami, @in_juty]) do |f| %> + <%= f.error_notification %> -
- <%= f.collection_select :commissioner_ids, Commissioner.all, :id, :name, {prompt: 'Select Commissioner'}, {class: 'form-control'} %>

- <%= f.input :in_time %> - <%= f.input :out_time %> -
+
+ <%= f.collection_select :commissioner_ids, Commissioner.all, :id, :name, {prompt: 'Select Commissioner'}, {class: 'form-control'} %> +

+ <%= f.input :in_time %> + <%= f.input :out_time %> +
-
- <%= f.button :submit %> -
-<% end %> \ No newline at end of file +
+ <%= f.button :submit %> +
+<% end %> diff --git a/app/views/origami/in_juties/_form.html.erb b/app/views/origami/in_juties/_form.html.erb index d67df51b..9bed9152 100644 --- a/app/views/origami/in_juties/_form.html.erb +++ b/app/views/origami/in_juties/_form.html.erb @@ -1,33 +1,43 @@ -
-<%= simple_form_for([:origami,@in_juty]) do |f| %> - <%= f.error_notification %> +<%= simple_form_for @in_juty, :url => origami_index_in_juty_path(@table.id), :method => :post do |f| %> + + <%= f.error_notification %> + <%= f.hidden_field :id, :class => "form-control col-md-6 " %> + +
+ + <%= f.hidden_field :dinning_id, :value => @table.id, :class => "form-control col-md-4 " %> + + + <%= @table.name %> +
+
+ + + <%= f.collection_select :commissioner_ids, Commissioner.all, :id, :name, {prompt: 'Select Commissioner'}, {class: 'form-control'} %> +

+ + <%= f.input :in_time, :placeholder => "From Date", :class => "form-control" %> + + <%= f.input :out_time, :placeholder => "To Date", :class => "form-control" %> + +

+ +
+ <% f.button :submit, "Create", :class => 'btn btn-primary ', :id => 'create' %> + <% f.button :submit, "Update", :class => 'btn btn-primary ', :disabled => '', :id => 'update' %> + <% f.button :button, "Reset", :class => 'btn btn-danger ', :id => 'reset' %> +
+
+ <%= f.button :submit, :class => 'btn btn-primary' %> +
-
- <%= f.label :dinning_id %> - <%= f.collection_select :dinning_id, DiningFacility.all, :id, :name, {prompt: 'Select Dining Facilities'}, {class: 'form-control'} %>
- <%= f.label :commissioner_ids %> - <%= f.collection_select :commissioner_ids, Commissioner.all, :id, :name, {prompt: 'Select Commissioner'}, {class: 'form-control'} %>
- - <%= f.text_field :in_time, :value=>DateTime.now.strftime("%Y-%m-%d / %I:%M %p"),:class=>"form-control datepicker"%>
- - <%= f.text_field :out_time, :value=>DateTime.now.strftime("%Y-%m-%d / %I:%M %p"),:class=>"form-control datepicker"%> -

-
- <%= link_to 'Back', origami_in_juties_path, class: 'btn btn-success' %> - <%= f.button :submit, class: 'btn btn-info' %> -
<% end %> -
+ \ No newline at end of file + }); + + diff --git a/app/views/origami/in_juties/index.html.erb b/app/views/origami/in_juties/index.html.erb index 6efeb999..ff5a0fd3 100644 --- a/app/views/origami/in_juties/index.html.erb +++ b/app/views/origami/in_juties/index.html.erb @@ -1,38 +1,91 @@ - -
-
- - - - - - - - - - - - - <% @in_juties.each do |in_juty| %> - - - - - - - - - - <% end %> - -
Dining Facility NameCommissioner IdsIn timeOut time
<%= in_juty.dining_facility.name rescue '-' %><%= in_juty.commissioner.name rescue '-' %><%= in_juty.in_time.utc.getlocal.strftime("%Y-%m-%d/%I:%M %p") rescue '-' %><%= in_juty.out_time.utc.getlocal.strftime("%Y-%m-%d/%I:%M %p") rescue '-' %><%= link_to 'Show', origami_in_juty_path(in_juty) %><%= link_to 'Edit', edit_origami_in_juty_path(in_juty) %><%= link_to 'Destroy', origami_in_juty_path(in_juty), method: :delete, data: {confirm: 'Are you sure?'} %>
+
+
+ + + diff --git a/app/views/origami/in_juties/index_in_juty.html.erb b/app/views/origami/in_juties/index_in_juty.html.erb index bbb9912b..52d79c89 100644 --- a/app/views/origami/in_juties/index_in_juty.html.erb +++ b/app/views/origami/in_juties/index_in_juty.html.erb @@ -22,7 +22,7 @@ <%= in_juty.commissioner.name rescue '-' %> <%= in_juty.in_time.utc.getlocal.strftime("%Y-%m-%d/%I:%M %p") rescue '-' %> <%= in_juty.out_time.utc.getlocal.strftime("%Y-%m-%d/%I:%M %p") rescue '-' %> - <%= link_to 'Destroy', origami_destroy_in_juty_path(in_juty.dining_facility.id, in_juty), method: :delete, data: {confirm: 'Are you sure?'} %> + <%= link_to 'Remove', origami_destroy_in_juty_path(in_juty.dining_facility.id, in_juty), method: :delete, data: {confirm: 'Are you sure?'} %> <% end %> @@ -30,13 +30,14 @@ <%= paginate @juties_in %>
-
- <%= render 'assign_in_juty', in_juty: @in_juty, table: @table %> +
+ <%= render 'form', in_juty: @in_juty, table: @table %>
-
- +
+      +
diff --git a/app/views/origami/in_juties/new.html.erb b/app/views/origami/in_juties/new.html.erb index eb34f01c..f59ff6fd 100644 --- a/app/views/origami/in_juties/new.html.erb +++ b/app/views/origami/in_juties/new.html.erb @@ -6,5 +6,5 @@
  • New
  • - <%= render 'form', in_juty: @in_juty %> + <%= render 'form', in_juty: @in_juty, table: @table %> diff --git a/app/views/settings/promotions/_form.html.erb b/app/views/settings/promotions/_form.html.erb index 1e4a3f86..7ac413d0 100644 --- a/app/views/settings/promotions/_form.html.erb +++ b/app/views/settings/promotions/_form.html.erb @@ -49,32 +49,79 @@
    -
    <%= f.input :original_product,collection: MenuItem.order("name desc").pluck(:name,:item_code),input_html: { selected: 2 } %>
    + <% 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 = [] %> + <% 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 %> + <% end %> +
    <%= f.input :original_product,collection: sample %>
    +
    <%= f.input :min_qty %>

    -
    Item Code
    +
    Item Code
    Min Qty
    Net off
    Net Price
    -
    Percentage
    -
    +
    Percentage
    +
    <%= f.fields_for :promotion_products do |pro| %>
    -
    <%= pro.input :item_code, label: false,collection: MenuItem.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| %> + <% arr.push(p) %> + <% end %> +
    + +
    + <% sample = [] %> +
    <%= pro.input :item_code, :class => 'promoproduct', collection: sample,input_html: { selected: 2 }, label: false %>
    <%= pro.input :min_qty , label: false%>
    <%= pro.input :net_off , label: false %>
    <%= pro.input :net_price , label: false %>
    -
    <%= pro.input :percentage , label: false %>
    -
    <%= pro.link_to_remove "X" %>
    +
    <%= pro.input :percentage , label: false %>
    +
    <%= pro.link_to_remove "X" %>
    <% end %>
    -
    <%= f.link_to_add "Add Product", :promotion_products, :class => 'btn btn-primary' %>
    +
    <%= f.link_to_add "Add Product", :promotion_products, :class => 'btn btn-primary addProduct' %>
    @@ -103,5 +150,56 @@ $(document).ready(function(){ datepicker:false, format:'H:m' }); + $("#promotion_original_product").select2(); + $(".item_code_place").select2(); + $(".item_code_place").on('change', function(event) { + var ajax_url = "<%= settings_find_item_instance_path %>"; + var item_code = this.value; + $.ajax({ + type: "GET", + url: ajax_url, + data: 'item_code=' + item_code, + success: function (result) { + $("#promotion_original_product").empty(); + var itemlist; + for (var i = 0; i < result.length; i++) { + itemlist += "" + } + $("#promotion_original_product").append(itemlist); + $("#promotion_original_product").select2(); + } + }); + }); + $(".promotion_promotion_products_item_code select").select2(); + $(".item_code_place1").select2(); + callforpromoproduct(); + $(".addProduct").on('click', function(event) { + setTimeout(function(){ + $(".promotion_promotion_products_item_code select").select2(); + callforpromoproduct(); + }, 0); + }); + function callforpromoproduct(){ + $(".item_code_place1").select2(); + $(".item_code_place1").on('change', function(event) { + id = $(this).parent().next().find("select").attr("id"); + var ajax_url = "<%= settings_find_item_instance_path %>"; + var item_code = this.value; + $.ajax({ + type: "GET", + url: ajax_url, + data: 'item_code=' + item_code, + success: function (result) { + $("#"+id).empty(); + var itemlist; + for (var i = 0; i < result.length; i++) { + itemlist += "" + } + $("#"+id).append(itemlist); + $("#"+id).select2(); + } + }); + }); + } }); diff --git a/config/routes.rb b/config/routes.rb index c6deb5aa..07550bfe 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -292,6 +292,7 @@ Rails.application.routes.draw do resources :promotions do resources :promotion_products end + get '/find_item_instance' => 'promotions#find_item_instance', as:'find_item_instance' # commission resources :commissions