// This is a manifest file that'll be compiled into application.js, which will include all the files // listed below. // // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path. // // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the // compiled file. JavaScript code in this file should be added after the last require_* statement. // // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details // about supported directives. // //= require jquery //= require tether //= require bootstrap //= require jquery_ujs //= require turbolinks //= require cable $(document).ready(function(){ // auto refresh every 10 seconds // setTimeout(function(){ // window.location.reload(1); // }, 10000); $(".nav-completed").on("click", function(){ $("#completed").removeClass('hide') $(".oqs_append").addClass('hide') }); $(".oqs_click").on("click", function(){ $("#completed").addClass('hide') $(".oqs_append").removeClass('hide') var oqs_id = $(this).find(".oqs-id").text(); var url = 'oqs/get_items/'+oqs_id; show_details(url); }); //End Click function show_details(url){ var oqs_append = $('.oqs_append'); oqs_append.empty(); //Start Ajax $.ajax({ type: "GET", url: url, data: {}, dataType: "json", success: function(data) { for(var field in data) { var price = parseFloat(data[field].price).toFixed(2); if (data[field]["options"] == "[]") { var options = ""; }else{ var options = data.options; } var date = new Date(data[field]["created_at"]); var show_date = date.getDate() + "-" + date.getMonth() + "-" + date.getFullYear() + ' ' + date.getHours()+ ':' + date.getMinutes(); row ='
' +'
' +'

' +''+data[field]["table_type"]+'- ' +''+ data[field]["zone"] +'' +''+ data[field]["order_id"] +'- ' +'

' +'

' +''+ data[field]["item_name"] +'- ' +''+ data[field]["qty"] +'- ' +'

' +'

'+ options +'

' +'

' +'Order at' +''+ show_date +' - ' +''+ data[field]["item_order_by"] +' ' +' ' +'

' +' ' +' ' +'
' +'' +'
'; $('.oqs_append').append(row); } } }); //end Ajax } $(document).on('click', '.queue_station', function(event){ var orderZone=$(this).children().children().children('.order-zone').text().trim(); // var orderItem=$(this).children().children().children('.order-item').text(); var assigned_item_id = $(this).children().find(".assigned-order-item").text(); var orderQty = $(this).children().children().children('.order-qty').text(); var orderBy = $(this).children().children().children().children('.order-by').text(); var orderAt = $(this).children().children().children().children('.order-at').text(); var orderCustomer = $(this).children().children('.order-customer').text(); var order_status = $(this).children().children('.order-status').text(); $('#order-title').text("ORDER DETAILS - " + orderZone); $('#order-by').text(orderBy); $('#order-at').text(orderAt); $('#order-customer').text(orderCustomer); $('#order-from').text(orderZone); // clear order items $("#oqs-order-details-table").children("tbody").empty(); // Call get_order_items() for Order Items by dining $.ajax({ type: 'GET', url: '/oqs/' + orderZone, data: { 'status' : order_status }, success: function(res){ for (i = 0; i < res.length; i++) { var data = JSON.stringify(res[i]); var parse_data = JSON.parse(data); var order_item_row = "" + "" + parse_data.item_name + "" + "" + parse_data.qty + "" + ""; $("#oqs-order-details-table").children("tbody").append(order_item_row); } } }) // $('#order-items').text(orderItem); // $('#order-qty').text(orderQty); $('.queue_station').removeClass('selected-item'); $(this).addClass('selected-item'); }); $(document).on('click', '.order-item-edit', function(event){ var _self = $(this); // To know in ajax return var assigned_item_id=$(this).attr('id').substr(5); window.location.href = '/oqs/'+ assigned_item_id + "/edit" }); // complete for queue item $(document).on('click', '.order-complete', function(event){ //e.preventDefault(); var _self = $(this); // To know in ajax return var assigned_item_id=$(this).attr('id').substr(15); var params = { 'id':assigned_item_id }; // Call update_delivery_status() for changed delivery and move to delivery $.ajax({ type: 'POST', url: '/oqs/update_delivery', data: params, dataType: 'json', success: function(data){ for (i = 0; i < data.length; i++) { var queue_station = $('#assigned_queue_' + data[i]).parent().parent(".queue_station"); var station = queue_station.parent().parent().attr('id'); // Remove a queue card from current station queue_station.remove(); // Remove a queue card from current station queue_station.children('.card-footer').remove(); // Add removed queue card from station to completed $("#completed").children('.card-columns').append(queue_station); // update queue item count in each station var station_count=parseInt($("#"+station+"_count").text()) - 1; $("#"+station+"_count").text(station_count); } // update queue item count in completed station $("#completed_count").text(parseInt($("#completed_count").text()) + data.length); alert("updated!"); // Page reload location.reload(); } }); }); // Print Order Item $(document).on('click', '#print_order_item', function(event){ var assigned_item_id = $('.selected-item').children('.card-block').children('.assigned-order-item').text(); var options = $('.selected-item').children('.card-block').find('.item-options').text(); var params = { 'options':options }; $.ajax({ type: 'GET', url: '/oqs/print/print/'+assigned_item_id, success: function(data){ } }); }); // Print Order Summary // $('#print_order_summary').on('click',function(){ $(document).on('click', '#print_order_summary', function(event){ var table_name=$('.selected-item').children().children().children('.order-zone').text().trim(); var assigned_item_id=$('.selected-item').children('.card-block').children('.assigned-order-item').text(); var params = { 'table_name':table_name }; $.ajax({ type: 'GET', url: '/oqs/print/print_order_summary/'+assigned_item_id, data: params, success: function(data){ } }); }); // Qty update for OQS Edit Controller $('#qty-update').on('click', function(){ var qty_weight = $("input[name='qty_weight']").val(); var remarks = $("textarea[name='remarks']").val(); var order_items_id = $(this).attr('data-id'); var params = { 'order_items_id': order_items_id, 'qty_weight': qty_weight, 'remarks': remarks } $.ajax({ type: 'POST', url: '/oqs/' + order_items_id, data: params, success: function(result){ alert("Updated!"); window.location.href = '/oqs'; } }); }); });