diff --git a/app/assets/javascripts/addorder.js b/app/assets/javascripts/addorder.js index 75de7392..f6768182 100755 --- a/app/assets/javascripts/addorder.js +++ b/app/assets/javascripts/addorder.js @@ -562,51 +562,9 @@ $(function() { // click plus icon for add $(document).on('click', '.add_icon', function(event){ - if($(this).hasClass('product_item')) { - $('.sx_item_detailModal').modal('hide'); - - var item_data = $(this); - code = $(this).data('instance-code'); - - if ($('#server_mode').val() != "cloud" && second_display_lookup == 2) { - item = get_item(item_data,"add_icon"); - customer_display_view(item,"add"); - } - show_item_detail(item_data,"add_icon"); - calculate_sub_total(); - autoScrollToItem(code) - - return - } - - if ($(this).data('instances').length == 1) { - - $('.sx_item_detailModal').modal('hide'); - - if ($(this).data('instances')[0].out_of_stock == false ) { - var item_data = $(this); - code = $(this).data('instance-code'); - - if ($('#server_mode').val() != "cloud" && second_display_lookup == 2) { - item = get_item(item_data,"add_icon"); - customer_display_view(item,"add"); - } - show_item_detail(item_data,"add_icon"); - calculate_sub_total(); - autoScrollToItem(code) - - } - return - - } else { - count = 0 - for (var i in $(this).data('instances')) { - if(!$(this).data('instances')[i].out_of_stock) { - count += 1; - } - } - - if (count === 1) { + if (window.location.pathname.includes('out_of_stock') == false) { + + if($(this).hasClass('product_item')) { $('.sx_item_detailModal').modal('hide'); var item_data = $(this); @@ -619,16 +577,61 @@ $(function() { show_item_detail(item_data,"add_icon"); calculate_sub_total(); autoScrollToItem(code) + return } - attributes = $(this).data('id'); - selected_item = $(this).data('attributes'); - instances = $(this).data('instances'); - item_options = $(this).data('options'); - data = $(this) + if ($(this).data('instances').length == 1) { - show_attribute_selection_modal(attributes, selected_item, instances, item_options, data) + $('.sx_item_detailModal').modal('hide'); + + if ($(this).data('instances')[0].out_of_stock == false ) { + var item_data = $(this); + code = $(this).data('instance-code'); + + if ($('#server_mode').val() != "cloud" && second_display_lookup == 2) { + item = get_item(item_data,"add_icon"); + customer_display_view(item,"add"); + } + show_item_detail(item_data,"add_icon"); + calculate_sub_total(); + autoScrollToItem(code) + + } + return + + } else { + count = 0 + for (var i in $(this).data('instances')) { + if(!$(this).data('instances')[i].out_of_stock) { + count += 1; + } + } + + if (count === 1) { + $('.sx_item_detailModal').modal('hide'); + + var item_data = $(this); + code = $(this).data('instance-code'); + + if ($('#server_mode').val() != "cloud" && second_display_lookup == 2) { + item = get_item(item_data,"add_icon"); + customer_display_view(item,"add"); + } + show_item_detail(item_data,"add_icon"); + calculate_sub_total(); + autoScrollToItem(code) + return + } + + attributes = $(this).data('id'); + selected_item = $(this).data('attributes'); + instances = $(this).data('instances'); + item_options = $(this).data('options'); + data = $(this) + + show_attribute_selection_modal(attributes, selected_item, instances, item_options, data) + } } }); //End Add Icon Click @@ -1082,9 +1085,45 @@ $(function() { // Create Order $("#create_order").on('click', function(e){ - - $(this).attr('disabled', 'disabled'); e.preventDefault(); + name_list = '' + count = 0; + $('.summary-items').find(`tr[data-oos='true']`).each(function() { + count += 1; + name = $(this).data('name') + name += $(this).data('instance').replace(/['"]+/g, '') + if ((count + 1) == $('.summary-items').find(`tr[data-oos='true']`).length) { + name += ' and ' + } else if(count != $('.summary-items').find(`tr[data-oos='true']`).length){ + name += ', ' + } + name_list += name + }); + wanring_text = name_list + 'are out of stock.' + if (name_list) { + + swal({ + title: "Out Of Stock Warning!", + text: wanring_text, + type: "warning", + showCancelButton: true, + confirmButtonColor: "#DD6B55", + confirmButtonText: "Confrim", + closeOnConfirm: false + }, function (isConfirm) { + if (isConfirm) { + create_order($(this)) + } + }); + + + } else { + create_order($(this)) + } + }); + + function create_order(data) { + data.attr('disabled', 'disabled'); $("#oqs_loading_wrapper").show(); var cashier_type = $("#link_type").val(); localStorage.setItem('cashier_type',cashier_type); @@ -1121,36 +1160,29 @@ $(function() { 'order_items': order_items,'create_type' : "create_only" }; } - // if (table_id.length>0 || role == 'waiter') { - $.ajax({ - type: "POST", - url: ajax_url, - data: params, - dataType: "json", - success:function(result){ - if (type == "quick_service" || type=="food_court") { - module_name = window.location.href.includes('foodcourt') ? 'foodcourt' : 'origami' - window.location.href = "/"+module_name+"/"+type; - }else{ - if(table_type == "Table"){ - window.location.href = "/origami/table/" + table_id; - } - else { - window.location.href = "/origami/room/" + table_id; - } - } - if ($('#server_mode').val() != "cloud" && second_display_lookup == 2){ - customer_display_view(null,"reload"); - } - } - }); - // }else{ - // $(this).removeAttr('disabled', ''); - // $("#oqs_loading_wrapper").hide(); - - // swal("Opps","Please Select Table or Room","warning"); - // } - }); + $.ajax({ + type: "POST", + url: ajax_url, + data: params, + dataType: "json", + success:function(result){ + if (type == "quick_service" || type=="food_court") { + module_name = window.location.href.includes('foodcourt') ? 'foodcourt' : 'origami' + window.location.href = "/"+module_name+"/"+type; + }else{ + if(table_type == "Table"){ + window.location.href = "/origami/table/" + table_id; + } + else { + window.location.href = "/origami/room/" + table_id; + } + } + if ($('#server_mode').val() != "cloud" && second_display_lookup == 2){ + customer_display_view(null,"reload"); + } + } + }); + } // Pay Discount for Payment @@ -1685,7 +1717,12 @@ $(function() { data_target = 'sx_item_set_detailModal'; data_modal = 'modal' add_icon = "set_item_box" - code = menu_items[field].code; + code = '' + menu_items[field].instances.forEach(ins => function (){ + if (ins.out_of_stock == false) { + code = ins.code; + } + }) name = menu_items[field].name; instances = menu_items[field].instances; $(instances).each(function(i){ @@ -1709,8 +1746,18 @@ $(function() { add_icon = "add_icon" menu_instances = []; + code = ''; + name = ''; + price = ''; + is_available = ''; + is_on_promotion = ''; + item_attributes = ''; + promotion_price = ''; + out_of_stock = ''; + menu_insta = ''; + $(instances).each(function(i){ - if (instances[i].is_default === true && !instances[i].out_of_stock) { + if (!instances[i].out_of_stock) { //instances[i].is_default === true && code = instances[i].code; name = instances[i].name; price = parseFloat(instances[i].price).toFixed(2); @@ -1718,13 +1765,10 @@ $(function() { is_on_promotion = instances[i].is_on_promotion; item_attributes = instances[i].values; promotion_price = instances[i].promotion_price; - code = instances[i].code; out_of_stock = instances[i].out_of_stock; menu_insta = [code,name,item_attributes]; - } - if(instances[i].out_of_stock === false){ menu_instances.push(menu_insta); - } + } }); } @@ -1745,9 +1789,9 @@ $(function() { }) if (status) { - price_tag = ''+status+'' + price_tag = ''+status+'' } else { - price_tag =''+price+'' + price_tag =''+price+'' } image_path = ''; diff --git a/app/assets/javascripts/channels/out_of_stock.js b/app/assets/javascripts/channels/out_of_stock.js index 54ff24af..bc02d24b 100644 --- a/app/assets/javascripts/channels/out_of_stock.js +++ b/app/assets/javascripts/channels/out_of_stock.js @@ -5,13 +5,10 @@ App.checkin = App.cable.subscriptions.create('OutOfStockChannel', { disconnected: function() {}, received: function(data) { - if (data && data.item_instance_code) { - console.log("out of stock channel!!!!"); - item_code = data.item_instance_code; - item_code_id = '#' + data.item_instance_code; - oos_id = '#oos' + data.item_instance_code; - head_oos = 'head' + data.item_instance_code; - rm_oos = '.' + head_oos; + if (data && data.item_code) { + item_code = data.item_code + item_instance_code = data.item_instance_code; + item_instance_code_id = '#' + item_instance_code; menus = localStorage.getItem('menus'); if (menus) { @@ -20,23 +17,119 @@ App.checkin = App.cable.subscriptions.create('OutOfStockChannel', { m.categories.forEach(c => { c.items.forEach(i => { i.instances.forEach(instance => { - if (instance.code == item_code) { - if (data.status == true) { - instance.out_of_stock = true; - oos_header = '