update menu valid date and limit time ,addorder for parent order item id
This commit is contained in:
@@ -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"
|
||||
+"'>"
|
||||
+'<div class="custom-card-head card-head" style="line-height:14px;">'
|
||||
+'<span class="">'+result["name"]+'</span>'
|
||||
@@ -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 ="<tr class='item_box' data-price ='"
|
||||
@@ -339,7 +345,31 @@ $(function() {
|
||||
+name+ "' data-code='"+item_code+"' data-instance-code='"
|
||||
+code+"' data-attributes='"
|
||||
+attribute_arr+"' data-options ='"
|
||||
+option_arr+"' data-row ='"+rowCount+ "'>"
|
||||
+option_arr+"' data-row ='"+rowCount+ "' data-parent ='"+parent+ "'>"
|
||||
+'<td class="item-cell-no">'+rowCount+'</td>'
|
||||
+'<td class="item-cell-name" id="item_name" >' + item_name+ ' ' + name +'</td>'
|
||||
+'<td class="item-cell-qty" id="item_qty">' + qty + '</td>'
|
||||
+'<td class="item-cell-price" id="item_price">'
|
||||
+ parseFloat(total).toFixed(2)
|
||||
+'</td>'
|
||||
+'</tr>';
|
||||
$(".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 ="<tr class='item_box' data-price ='"
|
||||
+price+ "' data-toggle='modal' data-target='#sx_itemModal' 'data-instance ='"
|
||||
+name+ "' data-code='"+item_code+"' data-instance-code='"
|
||||
+code+"' data-attributes='"
|
||||
+attribute_arr+"' data-options ='"
|
||||
+option_arr+"' data-row ='"+rowCount+ "' data-sub-item ='"+sub_item+ "'>"
|
||||
+'<td class="item-cell-no">'+rowCount+'</td>'
|
||||
+'<td class="item-cell-name" id="item_name" >' + item_name+ ' ' + name +'</td>'
|
||||
+'<td class="item-cell-qty" id="item_qty">' + qty + '</td>'
|
||||
@@ -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 ="<tr class='item_box' data-price ='"
|
||||
+price+ "' data-toggle='modal' data-target='#sx_itemModal' 'data-instance ='"
|
||||
+name+ "' data-code='"+item_code+"' data-instance-code='"
|
||||
+code+"' data-attributes='"
|
||||
+attribute_arr+"' data-options ='"
|
||||
+option_arr+"' data-row ='"+rowCount+ "'>"
|
||||
+'<td class="item-cell-no">'+rowCount+'</td>'
|
||||
+'<td class="item-cell-name" id="item_name" >' + item_name+ ' ' + name +'</td>'
|
||||
+'<td class="item-cell-qty" id="item_qty">' + qty + '</td>'
|
||||
+'<td class="item-cell-price" id="item_price">'
|
||||
+ parseFloat(total).toFixed(2)
|
||||
+'</td>'
|
||||
+'</tr>';
|
||||
$(".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);
|
||||
});
|
||||
|
||||
@@ -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") }
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -8,7 +8,21 @@
|
||||
<div class="form-inputs p-l-25">
|
||||
<%= 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"} %>
|
||||
<div class="row checkboxes ">
|
||||
<div class="col-md-2">
|
||||
<label class="control-label"><abbr title="required">*</abbr> Valid Day</label>
|
||||
</div>
|
||||
<%= f.hidden_field :valid_days, :class => "form-control", :id => "valid_day" %>
|
||||
<div class="col-md-9">
|
||||
<label><input class="selectDay" type="checkbox" name="Sunday" value="0" id="0"> Sun</label>
|
||||
<label><input class="selectDay" type="checkbox" name="Monday" value="1" id="1">Mon</label>
|
||||
<label><input class="selectDay" type="checkbox" name="Tuesday" value="2" id="2"> Tue</label>
|
||||
<label><input class="selectDay" type="checkbox" name="Wednesday" value="3" id="3"> Wed</label>
|
||||
<label><input class="selectDay" type="checkbox" name="Thursday" value="4" id="4"> Thu</label>
|
||||
<label><input class="selectDay" type="checkbox" name="Friday" value="5" id="5"> Fri</label>
|
||||
<label><input class="selectDay" type="checkbox" name="Saturday" value="6" id="6"> Sat</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-9 form-group">
|
||||
<label>* Valid Time From</label>
|
||||
<div class="input-group">
|
||||
@@ -69,5 +83,34 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
$(document).ready(function(){
|
||||
|
||||
var dayy = $("#valid_day").val().replace("[","").replace("]","");
|
||||
$.each( dayy.split(","), function( i, d ) {
|
||||
$("input.selectDay[value='"+d+"']").prop( "checked", true );
|
||||
});
|
||||
|
||||
|
||||
$(".selectDay").click(function() {
|
||||
// debugger;
|
||||
var item_row = $('.selectDay');
|
||||
console.log(item_row);
|
||||
check = $(item_row).prop("checked");
|
||||
var attribute_arr = [];
|
||||
$(item_row).each(function(i){
|
||||
if ($(item_row[i]).prop("checked")) {
|
||||
value = $(item_row[i]).val();
|
||||
str = value;
|
||||
attribute_arr.push(str);
|
||||
}
|
||||
});
|
||||
document.getElementById("valid_day").value = '';
|
||||
document.getElementById("valid_day").value = attribute_arr;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user