var mode=''; var table=''; var waiter=''; var lang='bg'; $(document).ready(function() { mode=$('input:hidden#mode').val(); table=$('input:hidden#table').val(); waiter=$('input:hidden#waiter').val(); lng(lang); list_tables(); list_active(); list_orders(); list_checks(); list_bats(); today_total(waiter); setInterval(function() { list_rings(); // blink tables yell waiter list_active(); // check busy tables }, 1000); //5000 setInterval(function() { list_orders(); // new unseen order list_checks(); // requested checks }, 1000); //10000 setInterval(function() { today_total(waiter); // total amount of waiter for today list_bats(); // dispaly actual battery levels }, 1000);//60000 $('.content .tables').delegate('.table.ok','click',function() { // list_orders(); table=$(this).parent().attr('id'); ring_off(table); var curr_txt=$('input#curr:hidden').val(); var items_html=''; var tbl_order=table_order(table); $('.content .tables #'+table+' .table .unseen').addClass('hide'); var total_price=0; $.each(tbl_order, function(k,v) { if (v.seen==0) { var new_item="new"; } else { var new_item=""; } items_html+='
  • '; items_html+='
    '; items_html+='
    '+v.qty+'
    '; items_html+='
    '; items_html+='
    '; items_html+='
    '+v.name+'
    '; items_html+='
    '; $.each(v.descr, function(k2,v2) { if (v2) { items_html+=''+k2+''; } else { items_html+=''+k2+''; } }); items_html+='
    '; items_html+='
    '; var price_r=(v.price/100).toFixed(2).split('.') items_html+='
    '+price_r[0]+'.'+price_r[1]+' '+curr_txt+'
    '; items_html+='
    '; items_html+='
  • '; total_price=parseInt(total_price)+(parseInt(v.price)*v.qty); }); items_html+='

  • '; var total_r=(total_price/100).toFixed(2).split('.'); var check_txt=$('input#check:hidden').val(); var print_txt=$('input#print:hidden').val(); var total_txt=$('input#total:hidden').val(); items_html+='
  • '; items_html+=''; // items_html+=''; items_html+='
    '+total_r[0]+'.'+total_r[1]+' '+curr_txt+'
    '+total_txt+':
    '; items_html+='
  • '; $('.content .order_cloud .order_list').html(items_html); $('.content .order_cloud').removeClass('hide'); $('.content .order_cloud .order_list').scrollTop(100000000); $('.content .order_list').delegate('.check_print','click',function() { // printToKitchen(tbl_order); }); $('.content .order_cloud .minus').bind('click',function() { $('.content .order_cloud').addClass('hide'); }); $('.content .order_list').delegate('.check_close','click',function() { var check_close_txt=$('#close_check').val(); $('.confirm_cloud .confirm .txt').text(check_close_txt); $('.confirm_cloud').removeClass('hide'); $('.confirm_cloud button.ok').unbind().bind('click', function() { $.ajax({ type: "POST", // dataType: "json", url: "/ajax", data: "check_close=1&table="+table, beforeSend: function() { $('.preload').removeClass('hide'); }, success: function(res) { printReceipt(tbl_order); $('.preload').addClass('hide'); $('.content .order_cloud').addClass('hide'); $('.content .tables #'+table+' .table').removeClass('active'); $('.content .tables #'+table+' .table .unseen').addClass('hide'); $('.content .tables #'+table+' .table .check').addClass('hide'); today_total(waiter); } }); $('.confirm_cloud').addClass('hide'); }); $('.confirm_cloud button.cancel').bind('click', function() { $('.confirm_cloud').addClass('hide'); }); }); }); function ring_off(table) { var out=''; $.ajax({ type: "POST", // dataType: "json", url: "/ajax", data: "ring_off=1&table="+table, success: function(res) { $('.content .tables #'+table+' .table').removeClass('blink'); } }); } function table_order(table) { var out=''; $.ajax({ type: "POST", async: false, // dataType: "json", url: "/ajax", data: "table_order=1&table="+table+"&waiter="+waiter, success: function(res) { out=res; } }); return out; } function list_tables() { $.ajax({ type: "POST", // dataType: "json", url: "/ajax", data: "list_tables=1&waiter="+waiter, beforeSend: function() { $('.preload').removeClass('hide'); }, success: function(res) { $('.content .tables').empty(); var tbl_html='' $.each(res, function(k,v) { if (v.ok==1) { var ok='ok'; } else { var ok=''; } if (v.level=='N/A') { var bg_col='#999'; } else { if (v.level>15) { var bg_col='#090'; } else { var bg_col='#c00'; } } tbl_html+='
  • '; tbl_html+='
    '+k; tbl_html+='
    '; tbl_html+='
    '; tbl_html+='
    '; tbl_html+='
    '+v.level+'
    '; tbl_html+='
    '; tbl_html+=''; tbl_html+=''; tbl_html+='
    '; tbl_html+='
  • '; }); tbl_html+='
  • '; $('.content .tables').html(tbl_html); list_active(); $('.preload').addClass('hide'); } }); } function list_bats() { $.ajax({ type: "POST", // dataType: "json", url: "/ajax", data: "list_bats=1", success: function(res) { $('li .table .bat_container .level_digit').text('N/A'); $('li .table .bat_container .level').css('width','100%'); $('li .table .bat_container .level').css('background-color','#999'); $.each(res, function(k,v) { if (v!='N/A') { if (v>15) { var bg_col='#090'; } else { var bg_col='#c00'; } $('li#'+k+' .table .bat_container .level').css('width',v+'%'); $('li#'+k+' .table .bat_container .level').css('background-color',bg_col); $('li#'+k+' .table .bat_container .level_digit').text(v); } }); } }); } function list_rings() { $.ajax({ type: "POST", // dataType: "json", url: "/ajax", data: "list_rings=1&waiter="+waiter, success: function(res) { $('.content .tables li .table').removeClass('blink'); if (res) { if (typeof android != "undefined") { var vibra=android.vibrate([1000], -1); } $.each(res, function(k,v) { $('.content .tables #'+k+' .table').addClass('blink'); }); } } }); } function list_orders() { $.ajax({ type: "POST", // dataType: "json", url: "/ajax", data: "list_orders=1&waiter="+waiter, success: function(res) { $('.content .tables li .unseen').addClass('hide'); if (res) { if (typeof android != "undefined") { var vibra=android.vibrate([1000], -1); } $.each(res, function(k,v) { $('.content .tables #'+k+' .unseen').removeClass('hide'); }); } } }); } function list_active() { $.ajax({ type: "POST", // dataType: "json", url: "/ajax", data: "list_active=1&waiter="+waiter, success: function(res) { $('.content .tables li .table').removeClass('active'); $.each(res, function(k,v) { $('.content .tables #'+k+' .table').addClass('active'); }); } }); } function list_checks() { $.ajax({ type: "POST", // dataType: "json", url: "/ajax", data: "list_checks=1&waiter="+waiter, success: function(res) { $('.content .tables li .check').addClass('hide'); if (res) { if (typeof android != "undefined") { var vibra=android.vibrate([1000], -1); } } $.each(res, function(k,v) { $('.content .tables #'+k+' .check').removeClass('hide'); }); } }); } function lng(lng) { $.ajax({ type: "POST", dataType: "json", url: "/ajax", data: "get_lang="+lng, beforeSend: function() { $('.preload').removeClass('hide'); }, success: function(res) { $.each(res, function(k,v) { $('.lang#'+k).html(v); $('.lang#'+k).val(v); }); $('input:hidden#lang').val(lng); $('.preload').addClass('hide'); } }); } function today_total(waiter) { $.ajax({ type: "POST", // dataType: "json", url: "/ajax", data: "today_total=1&waiter="+waiter, success: function(res) { var total_r=(res/100).toFixed(2).split('.'); $('.total_price .ttl').html(total_r[0]+'.'+total_r[1]+''); $('.total_price').removeClass('hide'); } }); } });