diff --git a/app/assets/javascripts/addorder.js b/app/assets/javascripts/addorder.js index ff899c13..4b158946 100755 --- a/app/assets/javascripts/addorder.js +++ b/app/assets/javascripts/addorder.js @@ -221,6 +221,9 @@ $(function() { +"' data-option='"+JSON.stringify(result["options"]) +"' data-min-qty='"+item_sets[field]["min_selectable_qty"] +"' data-max-qty='"+item_sets[field]["max_selectable_qty"] + +"' data-parent-code='"+instances[0]['code'] + +"' data-parent-id='"+instances[0]['id'] + +"' data-sub-item='true" +"'>" +'
' +''+result["name"]+'' @@ -246,6 +249,7 @@ $(function() { $('.set-item').attr('data-name',instances[0]['name']); $('.set-item').attr('data-price',instances[0]['price']); $('.set-item').attr('data-options','[]'); + $('.set-item').attr('data-parent',true); $('#set_change_qty').val(1); $('#set_item_instances').text(instances); @@ -326,12 +330,14 @@ $(function() { if (items.length >= min_qty) { attribute_arr = [] option_arr = [] + var rowCount = $('.summary-items tbody tr').length+1; - $(items).each(function(i){ - code = $(items[i]).attr('data-code'); - name = $(items[i]).attr('data-name'); - price = $(items[i]).attr('data-price'); - option = $(items[i]).attr('data-options'); + option_arr = [] + code = $('.set-item').attr('data-code'); + name = $('.set-item').attr('data-name'); + price = $('.set-item').attr('data-price'); + option = $('.set-item').attr('data-options'); + parent = $('.set-item').attr('data-parent'); total = qty * price ; option_arr.push(option); row ="" + +option_arr+"' data-row ='"+rowCount+ "' data-parent ='"+parent+ "'>" + +''+rowCount+'' + +'' + item_name+ ' ' + name +'' + +'' + qty + '' + +'' + + parseFloat(total).toFixed(2) + +'' + +''; + $(".summary-items tbody").append(row); + + var rowCount = $('.summary-items tbody tr').length+1; + $(items).each(function(i){ + code = $(items[i]).attr('data-code'); + name = $(items[i]).attr('data-name'); + price = $(items[i]).attr('data-price'); + option = $(items[i]).attr('data-options'); + sub_item = $(items[i]).attr('data-sub-item'); + total = qty * price ; + option_arr.push(option); + row ="" +''+rowCount+'' +'' + item_name+ ' ' + name +'' +'' + qty + '' @@ -351,28 +381,6 @@ $(function() { rowCount = rowCount + 1; }); - var rowCount = $('.summary-items tbody tr').length+1; - option_arr = [] - code = $('.set-item').attr('data-code'); - name = $('.set-item').attr('data-name'); - price = $('.set-item').attr('data-price'); - option = $('.set-item').attr('data-options'); - total = qty * price ; - option_arr.push(option); - row ="" - +''+rowCount+'' - +'' + item_name+ ' ' + name +'' - +'' + qty + '' - +'' - + parseFloat(total).toFixed(2) - +'' - +''; - $(".summary-items tbody").append(row); calculate_sub_total(); $(".sx_item_set_detailModal").css({ 'display': "none" }); }else{ @@ -711,7 +719,6 @@ $(function() { } var table_type = $('#table_type').text(); var order_items = JSON.stringify(get_order_item_rows()); - var ajax_url = '../addorders/create'; var params = {'order_source': "cashier", 'order_type': "dine_in", @@ -827,6 +834,14 @@ $(function() { order_item.order_item_id = $(item_row[i]).attr('data-row'); order_item.item_instance_code = $(item_row[i]).attr('data-instance-code'); order_item.quantity = $(item_row[i]).children('#item_qty').text(); +//parent id + if ($(item_row[i]).attr('data-parent')=="true") { + parent_id = $(item_row[i]).attr('data-row'); + } + if ($(item_row[i]).attr('data-sub-item')=="true") { + order_item.parent_order_item_id = parent_id + } +//end parent id order_item.options = $(item_row[i]).attr('data-options'); order_items.push(order_item); }); diff --git a/app/models/menu.rb b/app/models/menu.rb index 05adfac4..65d00d90 100755 --- a/app/models/menu.rb +++ b/app/models/menu.rb @@ -2,7 +2,7 @@ class Menu < ApplicationRecord has_many :menu_categories, dependent: :destroy validates_presence_of :name, :valid_days, :valid_time_from, :valid_time_to - validates_format_of :valid_days, :with => /\A([0-7]{1}(,[0-7]{1})*)?\Z/i + # validates_format_of :valid_days, :with => /\A([0-7]{1}(,[0-7]{1})*)?\Z/i #Default Scope to pull the active version only default_scope { where(is_active: true).order("created_at desc") } diff --git a/app/models/menu_category.rb b/app/models/menu_category.rb index 1f45b3ff..3c1a39ab 100755 --- a/app/models/menu_category.rb +++ b/app/models/menu_category.rb @@ -41,19 +41,41 @@ class MenuCategory < ApplicationRecord menu_category = MenuCategory.find(self.id) menu = Menu.find(menu_category.menu_id) - from = menu.valid_time_from.strftime("%H:%M:%S") - to = menu.valid_time_to.strftime("%H:%M:%S") - current = Time.now.utc.getlocal.strftime("%H:%M:%S") - from = from.split(':').map { |a| a.to_i }.inject(0) { |a, b| a * 60 + b} - to = to.split(':').map { |a| a.to_i }.inject(0) { |a, b| a * 60 + b} - current = current.split(':').map { |a| a.to_i }.inject(0) { |a, b| a * 60 + b} + from_t = Time.parse(menu.valid_time_from.strftime("%H:%M:%S")) + to_t = Time.parse(menu.valid_time_to.strftime("%H:%M:%S")) + current_t = Time.parse(Time.now.utc.getlocal.strftime("%H:%M:%S")) + + from = from_t.hour * 3600 + from_t.min*60 + from_t.sec + to = to_t.hour * 3600 + to_t.min* 60 + to_t.sec + current = current_t.hour * 3600 + current_t.min*60+current_t.sec + if from > to + h = to_t.hour + if h < 12 # before noon + if h = 0 + to = 24 + to = to * 3600 + to_t.min* 60 + to_t.sec + end + else # (after) noon + if h > 12 + to -= 12 + to = to * 3600 + to_t.min* 60 + to_t.sec + end + end + end - if current.between?(from, to) + # from = from.split(':').map { |a| a.to_i }.inject(0) { |a, b| a * 60 + b} + # to = to.split(':').map { |a| a.to_i }.inject(0) { |a, b| a * 60 + b} + # current = current.split(':').map { |a| a.to_i }.inject(0) { |a, b| a * 60 + b} + + day = Date.today.wday + dayresult = menu.valid_days.include?(day.to_s) + + if current.between?(from, to) && menu.valid_days.include?(day.to_s) return true - else + else return nil - end + end end private diff --git a/app/views/settings/menus/_form.html.erb b/app/views/settings/menus/_form.html.erb index c8b5e41a..ffbee4ec 100755 --- a/app/views/settings/menus/_form.html.erb +++ b/app/views/settings/menus/_form.html.erb @@ -8,7 +8,21 @@
<%= f.input :name,:input_html=>{:class=>"col-md-9"} %> <%= f.input :is_active,:input_html=>{:class=>"col-md-9"} %> - <%= f.input :valid_days,:input_html=>{:class=>"col-md-9"} %> +
+
+ +
+ <%= f.hidden_field :valid_days, :class => "form-control", :id => "valid_day" %> +
+    +    +    +    +    +    + +
+
@@ -69,5 +83,34 @@
+