From 0acd533bfe944a841bd441c655113bc10695fd5e Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Wed, 28 Feb 2018 10:14:18 +0630 Subject: [PATCH] update add oredr --- app/assets/javascripts/addorder.js | 9 +- .../origami/addorders_controller.rb | 7 +- .../origami/quick_service_controller.rb | 3 +- app/models/menu_category.rb | 2 +- .../origami/addorders/_add_order.html.erb | 584 ++++++++++++++++++ app/views/origami/addorders/detail.html.erb | 584 +----------------- .../quick_service/_menu_item.json.jbuilder | 119 ++++ .../get_all_product.json.jbuilder | 4 + .../quick_service/get_menu.json.jbuilder | 1 + .../get_menu_category.json.jbuilder | 8 + .../get_menu_sub_category.json.jbuilder | 9 + .../origami/quick_service/index.html.erb | 3 + 12 files changed, 743 insertions(+), 590 deletions(-) create mode 100644 app/views/origami/addorders/_add_order.html.erb create mode 100755 app/views/origami/quick_service/_menu_item.json.jbuilder create mode 100755 app/views/origami/quick_service/get_all_product.json.jbuilder create mode 100644 app/views/origami/quick_service/get_menu.json.jbuilder create mode 100755 app/views/origami/quick_service/get_menu_category.json.jbuilder create mode 100644 app/views/origami/quick_service/get_menu_sub_category.json.jbuilder diff --git a/app/assets/javascripts/addorder.js b/app/assets/javascripts/addorder.js index c55525bc..475652af 100755 --- a/app/assets/javascripts/addorder.js +++ b/app/assets/javascripts/addorder.js @@ -76,8 +76,8 @@ $(function() { } //end show list function //click menu sidebar menu category - // $(".menu_category").on("click", function(){ $(document).on('click', '.menu_category', function(event){ + event.preventDefault(); var menu_id = $(this).attr("data-id"); var url = "get_menu_category/"+menu_id; show_menu_item_list(url); @@ -104,6 +104,8 @@ $(function() { data: {}, dataType: "json", success: function(data) { + console.log(data); + console.log("ememem") var menu_items_list = $('.menu_items_list'); menu_items_list.empty(); menu_items = data.menu_items; @@ -1099,7 +1101,8 @@ $(function() { //click menu sidebar menu category - $(".sub_click").on("click", function(){ + $(document).on('click', '.sub_click', function(event){ + event.preventDefault(); var menu_id = $(this).attr("data-id"); var url = "get_menu_sub_category/"+menu_id; sub_category = $(this).find('.sub_category_list'); @@ -1127,6 +1130,8 @@ $(function() { data: {}, dataType: "json", success: function(data) { + console.log(data) + console.log("ffffffffff") var sub_category_list = $('.sub_category_list'); sub_category_list.empty(); data = data.sub_category; diff --git a/app/controllers/origami/addorders_controller.rb b/app/controllers/origami/addorders_controller.rb index 42412c51..9c19bbf2 100755 --- a/app/controllers/origami/addorders_controller.rb +++ b/app/controllers/origami/addorders_controller.rb @@ -37,9 +37,10 @@ class Origami::AddordersController < ApplicationController#BaseOrigamiController def get_menu_category () if (params[:id]) - puts params[:id] + #Pull this menu @menu = MenuCategory.find_by_id(params[:id]) + # puts @menu.menu_items[1].item_attributes.to_json return @menu else @@ -49,7 +50,6 @@ class Origami::AddordersController < ApplicationController#BaseOrigamiController def get_menu() if (params[:id]) - puts params[:id] #Pull this menu @menu = Menu.find_by_id(params[:id]) @menu_category = MenuCategory.where("menu_id='#{@menu.id}'").order("order_by asc") @@ -61,10 +61,13 @@ class Origami::AddordersController < ApplicationController#BaseOrigamiController end def get_menu_sub_category () + id = params[:id] + if (id) #Pull this menu @sub_menu = MenuCategory.where("menu_category_id = #{id}").active + # puts @menu.menu_items[1].item_attributes.to_json return @sub_menu end diff --git a/app/controllers/origami/quick_service_controller.rb b/app/controllers/origami/quick_service_controller.rb index 2b943e7e..8516c493 100644 --- a/app/controllers/origami/quick_service_controller.rb +++ b/app/controllers/origami/quick_service_controller.rb @@ -14,7 +14,7 @@ class Origami::QuickServiceController < ApplicationController # @rooms = Room.all.active.order('zone_id asc').group("zone_id") # @all_table = Table.all.active.order('status desc') # @all_room = Room.all.active.order('status desc') - render "origami/addorders/detail" + # render "origami/addorders/detail" end def modify_order @@ -51,7 +51,6 @@ class Origami::QuickServiceController < ApplicationController else @booking = nil end - render "origami/addorders/detail" end def update_modify_order diff --git a/app/models/menu_category.rb b/app/models/menu_category.rb index 3c1a39ab..acb06c4f 100755 --- a/app/models/menu_category.rb +++ b/app/models/menu_category.rb @@ -52,7 +52,7 @@ class MenuCategory < ApplicationRecord if from > to h = to_t.hour if h < 12 # before noon - if h = 0 + if h == 0 to = 24 to = to * 3600 + to_t.min* 60 + to_t.sec end diff --git a/app/views/origami/addorders/_add_order.html.erb b/app/views/origami/addorders/_add_order.html.erb new file mode 100644 index 00000000..efe21d2a --- /dev/null +++ b/app/views/origami/addorders/_add_order.html.erb @@ -0,0 +1,584 @@ + + + + +<% type = request.path_info.include?('quick_service')%> +<% modify_order = request.path_info.include?('modify_order')%> + + + + +
+
+ +
  • + + + <%= @menus[0].name %> + + + +
  • + +
    + + + +
    +
    +
    +
    + +
    +
    +
    +
    + +
    + + <% if type && modify_order%> + + + + + <%elsif !modify_order && type%> + + + + + Select + + + <%else%> + + <%end%> +
    +
    + <% if type %> +
    +
    + ORDER DETAILS +
    + + <% if modify_order %> + <% if @table.nil? %> +
    Table :
    + + + <% else%> +
    Table : <%=@table.name%>
    + + + <% end%> + + + + + <% else%> + + <% end%> +
    + <% else %> +
    + ORDER DETAILS | Table-<%=@table.name%> + + + + +
    + <% end%> + +
    +
    +
    + + + + + + + + + + + + +
    #ItemsQTYPrice
    +
    + +
    +
    + + + + + + + + + + + + + <% if type && !modify_order%> + + <% end %> + \ No newline at end of file diff --git a/app/views/origami/addorders/detail.html.erb b/app/views/origami/addorders/detail.html.erb index 0c3e7bb5..1e96edc7 100755 --- a/app/views/origami/addorders/detail.html.erb +++ b/app/views/origami/addorders/detail.html.erb @@ -1,585 +1,3 @@ - <%= stylesheet_link_tag 'addorder', media: 'all', 'data-turbolinks-track': 'reload' %> <%= javascript_include_tag 'addorder', 'data-turbolinks-track': 'reload' %> - - -<% type = request.path_info.include?('quick_service')%> -<% modify_order = request.path_info.include?('modify_order')%> - - - - -
    -
    - -
  • - - - <%= @menus[0].name %> - - - -
  • - -
    - - - -
    -
    -
    -
    - -
    -
    -
    -
    - -
    - - <% if type && modify_order%> - - - - - <%elsif !modify_order && type%> - - - - - Select - - - <%else%> - - <%end%> -
    -
    - <% if type %> -
    -
    - ORDER DETAILS -
    - - <% if modify_order %> - <% if @table.nil? %> -
    Table :
    - - - <% else%> -
    Table : <%=@table.name%>
    - - - <% end%> - - - - - <% else%> - - <% end%> -
    - <% else %> -
    - ORDER DETAILS | Table-<%=@table.name%> - - - - -
    - <% end%> - -
    -
    -
    - - - - - - - - - - - - -
    #ItemsQTYPrice
    -
    - -
    -
    - - - - - - - - - - - - - <% if type && !modify_order%> - - <% end %> - \ No newline at end of file +<%= render 'add_order' %> \ No newline at end of file diff --git a/app/views/origami/quick_service/_menu_item.json.jbuilder b/app/views/origami/quick_service/_menu_item.json.jbuilder new file mode 100755 index 00000000..a18645c8 --- /dev/null +++ b/app/views/origami/quick_service/_menu_item.json.jbuilder @@ -0,0 +1,119 @@ +# Format for attributes json +attr_format = [] +# Format for attributes json +if item.item_attributes.count > 0 + item.item_attributes.each do|attr_id| + menu_attr = MenuItemAttribute.find(attr_id) + if attr_format.count == 0 + attr_format.push({ type: menu_attr.attribute_type, values: [menu_attr.name] }) + next + end + + attr_format.each do |af| + if menu_attr.attribute_type.in? attr_format.map {|k| k[:type]} + if menu_attr.attribute_type == af[:type] + af[:values].push(menu_attr.name) + end + else + new_attr = {type: menu_attr.attribute_type, values: [ menu_attr.name ] } + attr_format.push(new_attr) + break + end + end + end +end + +# Format for option json +opt_format = [] +# Format for attributes json +if item.item_options.count > 0 + item.item_options.each do|opt| + menu_opt = MenuItemOption.find(opt) + if opt_format.count == 0 + opt_format.push({ type: menu_opt.option_type, values: [menu_opt.name] }) + next + end + + opt_format.each do |of| + if menu_opt.option_type.in? opt_format.map {|k| k[:type]} + if menu_opt.option_type == of[:type] + of[:values].push(menu_opt.name) + end + else + new_opt = {type: menu_opt.option_type, values: [ menu_opt.name ] } + opt_format.push(new_opt) + break + end + end + end +end + +#Menu Item Information +json.id item.id +json.code item.item_code +json.name item.name +json.alt_name item.alt_name +json.image item.image_path.url +json.description item.description +json.information item.information +json.type item.type +json.account_id item.account_id +json.min_qty item.min_qty +json.is_available item.is_available +json.is_sub_item item.is_sub_item +json.unit item.unit + +# Item Sets of Menu Item +json.item_sets item.item_sets do |its| + json.id its.id + json.name its.name + json.alt_name its.alt_name + json.min_selectable_qty its.min_selectable_qty + json.max_selectable_qty its.max_selectable_qty + json.instances its.menu_item_instances do |i| + json.id i.id + end +end + +json.attributes attr_format +json.options opt_format +# json.min_selectable_item item.min_selectable_item +# json.max_selectable_item item.max_selectable_item + +#Item instance +# if item.menu_item_instances.count == 1 then +# item_instance = item.menu_item_instances[0] +# json.price = item_instance.price +# json.is_available = item_instance.is_available +# json.is_on_promotion = item_instance.is_on_promotion +# json.promotion_price = item_instance.promotion_price +# json.item_attributes = item_instance.item_attributes + +json.instances item.menu_item_instances do |is| + if is.is_available + # Convert id to name for attributes + instance_attr = [] + is.item_attributes.each do |ia| + mItemAttr = MenuItemAttribute.find(ia).name + instance_attr.push(mItemAttr) + end + + json.id is.id + json.code is.item_instance_code + json.name is.item_instance_name + json.price is.price + json.is_available is.is_available + json.is_default is.is_default + json.is_on_promotion is.is_on_promotion + json.promotion_price is.promotion_price + json.values instance_attr + # json.item_sets is.item_sets + end +end + +#Child Menu items +# if (item.children) then +# json.set_items item.children.each do |item| +# json.partial! 'api/restaurant/menu/menu_item', item: item +# end +# end \ No newline at end of file diff --git a/app/views/origami/quick_service/get_all_product.json.jbuilder b/app/views/origami/quick_service/get_all_product.json.jbuilder new file mode 100755 index 00000000..01921c59 --- /dev/null +++ b/app/views/origami/quick_service/get_all_product.json.jbuilder @@ -0,0 +1,4 @@ + +json.array! @product, :id, :item_code, :name, :alt_name,:image_path, + :description,:information,:taxable,:unit_price, :created_at, + :updated_at, :created_by \ No newline at end of file diff --git a/app/views/origami/quick_service/get_menu.json.jbuilder b/app/views/origami/quick_service/get_menu.json.jbuilder new file mode 100644 index 00000000..bbe18fff --- /dev/null +++ b/app/views/origami/quick_service/get_menu.json.jbuilder @@ -0,0 +1 @@ +json.array! @menu_category \ No newline at end of file diff --git a/app/views/origami/quick_service/get_menu_category.json.jbuilder b/app/views/origami/quick_service/get_menu_category.json.jbuilder new file mode 100755 index 00000000..91f659e8 --- /dev/null +++ b/app/views/origami/quick_service/get_menu_category.json.jbuilder @@ -0,0 +1,8 @@ +if @menu.menu_items + json.menu_items @menu.menu_items do |item| + if item.is_available + json.partial! 'origami/addorders/menu_item', item: item + end + + end +end diff --git a/app/views/origami/quick_service/get_menu_sub_category.json.jbuilder b/app/views/origami/quick_service/get_menu_sub_category.json.jbuilder new file mode 100644 index 00000000..d391e4c5 --- /dev/null +++ b/app/views/origami/quick_service/get_menu_sub_category.json.jbuilder @@ -0,0 +1,9 @@ +if @sub_menu + json.sub_category @sub_menu.each do |sub_cat| + json.id sub_cat.id + json.code sub_cat.code + json.name sub_cat.name + json.menu_id sub_cat.menu_id + json.menu_category_id sub_cat.menu_category_id + end +end diff --git a/app/views/origami/quick_service/index.html.erb b/app/views/origami/quick_service/index.html.erb index e69de29b..7108125b 100644 --- a/app/views/origami/quick_service/index.html.erb +++ b/app/views/origami/quick_service/index.html.erb @@ -0,0 +1,3 @@ +<%= stylesheet_link_tag 'addorder', media: 'all', 'data-turbolinks-track': 'reload' %> +<%= javascript_include_tag 'addorder', 'data-turbolinks-track': 'reload' %> +<%= render 'origami/addorders/add_order' %> \ No newline at end of file