diff --git a/app/assets/javascripts/addorder.js b/app/assets/javascripts/addorder.js index 4b158946..60bcbcc3 100755 --- a/app/assets/javascripts/addorder.js +++ b/app/assets/javascripts/addorder.js @@ -83,9 +83,12 @@ $(function() { //show menu item list when click menu category function show_menu_item_list(url_item){ - var menu_list = $('.menu_items_list'); menu_list.empty(); + if ($('#type').val() == 'true') { + url_item = 'addorders/'+url_item + } + //Start Ajax $.ajax({ type: "GET", @@ -702,26 +705,41 @@ $(function() { } } - // Pay Discount for Payment + // Create Order $("#create_order").on('click', function(e){ + $(this).attr('disabled', 'disabled'); e.preventDefault(); $("#oqs_loading_wrapper").show(); - var table_id = $('#table_id').text(); - var customer_id = $('#customer_id').text(); - var booking_id = $('#booking_id').text(); + + type = $('#type').val(); + if (type == 'true') { + type = 'cashier' + + var table_type = $('#table_id').find("option:selected").data('type'); + var table_id = $('#table_id').val(); + var customer_id = $('#customer_id').val(); + var booking_id = $('#booking_id').text(); + var ajax_url = 'addorders/create'; + }else{ + type = 'cashier' + var table_type = $('#table_type').text(); + var table_id = $('#table_id').text(); + var customer_id = $('#customer_id').text(); + var booking_id = $('#booking_id').text(); + var ajax_url = '../addorders/create'; + } if (!booking_id.length > 0) { - var params = {'order_source': "cashier", 'order_type': "dine_in", + var params = {'order_source': type, 'order_type': "dine_in", 'customer_id': customer_id, 'guest_info': "",'booking_id':booking_id, 'table_id': table_id, 'order_items': order_items }; } - 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", + var params = {'order_source': type, 'order_type': "dine_in", 'customer_id': customer_id, 'guest_info': "", 'table_id': table_id, 'order_items': order_items }; @@ -731,27 +749,61 @@ $(function() { data: params, dataType: "json", success:function(result){ - // $("#oqs_loading_wrapper").hide(); - // swal({ - // title: "Information !", - // text: 'Order has been successfully created', - // confirmButtonColor: "green", - // confirmButtonText: "Yes!", - // closeOnConfirm: false, - // }, function (isConfirm) { - // if (isConfirm) { + if(table_type == "Table"){ window.location.href = "/origami/table/" + table_id } else { window.location.href = "/origami/room/" + table_id - } - // } - // }); + } } }); }); + + // Pay Discount for Payment + $("#create_pay_order").on('click', function(e){ + + $(this).attr('disabled', 'disabled'); + e.preventDefault(); + $("#oqs_loading_wrapper").show(); + + type = $('#type').val(); + type = 'quick_service' + var table_type = $('#table_id').find("option:selected").data('type'); + var table_id = $('#table_id').val(); + var customer_id = $('#customer_id').val(); + var booking_id = $('#booking_id').text(); + var ajax_url = 'addorders/create'; + + if (!booking_id.length > 0) { + + var params = {'order_source': type, 'order_type': "dine_in", + 'customer_id': customer_id, 'guest_info': "",'booking_id':booking_id, + 'table_id': table_id, + 'order_items': order_items }; + } + var order_items = JSON.stringify(get_order_item_rows()); + + var params = {'order_source': type, 'order_type': "dine_in", + 'customer_id': customer_id, 'guest_info': "", + 'table_id': table_id, + 'order_items': order_items }; + $.ajax({ + type: "POST", + url: ajax_url, + data: params, + dataType: "json", + success:function(result){ + console.log(result) + if (result.status) { + window.location.href = "/origami/sale/"+result.data["sale_id"]+"/payment" + } + // window.location.href = "/origami/quick_service" + } + }); + }); + //click item row for update qty $('.summary-items').on('click', '.item_box', function(){ $(this).attr('data-active',true); @@ -863,11 +915,21 @@ $(function() { $("#back").on("click", function(){ var table_id = $('#table_id').text(); var table_type = $('#table_type').text(); - if(table_type == "Table"){ - window.location.href = "/origami/table/" + table_id - }else { - window.location.href = "/origami/room/" + table_id - } + type = $('#type').val(); + if (type == 'true') { + var table_type = $('#table_id').find("option:selected").data('type'); + var table_id = $('#table_id').val(); + window.location.href = "/origami/dashboard" + }else{ + var table_type = $('#table_type').text(); + var table_id = $('#table_id').text(); + + if(table_type == "Table"){ + window.location.href = "/origami/table/" + table_id + }else { + window.location.href = "/origami/room/" + table_id + } + } }); // Get Selected Class @@ -970,6 +1032,9 @@ $(function() { $(".sub_click").on("click", function(){ var menu_id = $(this).attr("data-id"); var url = "get_menu_sub_category/"+menu_id; + if ($('#type').val() == 'true') { + url = 'addorders/'+url + } sub_category = $(this).find('.sub_category_list'); show_sub_category_list(url,sub_category); }); @@ -992,7 +1057,12 @@ $(function() { data = data.sub_category; if (data.length>0) { - $(sub_category).removeClass('hidden'); + if ((sub_category.hasClass('hidden'))) { + $(sub_category).removeClass('hidden'); + }else{ + $(sub_category).addClass('hidden'); + } + for(var i in data) { row = '