$(document).ready(function() {
// history.pushState(null, null, location.href); history.back(); history.forward(); window.onpopstate = function () { history.go(1); };
$('.battery_level').bind('click', function() {
var bat_lev=android.getBatteryLevel();
$(this).text(new Date().getTime()+' : '+bat_lev);
});
$('.setup .mode').bind('change',function() {
var mode=$(this).val();
$.ajax({
type: "POST",
//dataType: "json",
url: "/ajax",
data: "set_mode=1&mode="+mode,
beforeSend: function() {
$('.logo').addClass('rot');
},
success: function(res) {
var num_options='';
$.each(res, function(k,v) {
num_options+='';
});
$('.setup .number').html(num_options).removeClass('hide');
$('.setup .number').bind('change',function() {
var num=$(this).val();
$('.setup .enter').removeClass('hide');
$('.setup .enter').bind('click',function() {
document.location='/'+mode+'/'+num;
});
});
$('.logo').removeClass('rot');
}
});
});
});
function getCookieByName(name) {
const cookies = document.cookie.split(";");
for (let cookie of cookies) {
cookie = cookie.trim();
if (cookie.startsWith(name + "=")) {
return cookie.substring(name.length + 1);
}
}
return null;
}
var STR_PAD_LEFT = 1;
var STR_PAD_RIGHT = 2;
var STR_PAD_BOTH = 3;
function strpad(str, len, pad, dir) {
if (typeof(len) == "undefined") { var len = 0; }
if (typeof(pad) == "undefined") { var pad = ' '; }
if (typeof(dir) == "undefined") { var dir = STR_PAD_RIGHT; }
if (len + 1 >= str.length) {
switch (dir){
case STR_PAD_LEFT:
str = Array(len + 1 - str.length).join(pad) + str;
break;
case STR_PAD_BOTH:
var right = Math.ceil((padlen = len - str.length) / 2);
var left = padlen - right;
str = Array(left+1).join(pad) + str + Array(right+1).join(pad);
break;
default:
str = str + Array(len + 1 - str.length).join(pad);
break;
} // switch
}
return str;
}
function printReceipt(order) {
var printServerHost=$('input:hidden#printServerHost').val();
var printerName=$('input:hidden#printerName').val();
var waiter=$('input:hidden#waiter').val();
var receipt={
"UniqueSaleNumber" : printerName.toUpperCase()+"-"+waiter.padStart(4, 0)+"-"+String(order[Object.keys(order)[0]].order_id).padStart(7, 0),
"items": [],
"payments": []
};
var total=0;
$.each(order, function(k,v) {
receipt.items.push({
"text" : v.name,
"quantity": v.qty,
"unitPrice": Math.round(v.price/100, 2),
"taxGroup": 1
});
if (v.descr) {
var comment='';
$.each(v.descr, function(k1,v1) {
if (v1) {
comment+='+'+k1+',';
} else {
comment+='-'+k1+',';
}
});
receipt.items.push({
"type" : "comment",
"text" : comment.slice(0, -1)
});
}
total=parseInt(total)+(v.price*parseInt(v.qty));
});
receipt.payments.push({
"amount": Math.round(total/100, 2),
"paymentType": "cash"
});
$.ajax({
type: "POST",
dataType: "json",
contentType: "application/json",
url: printServerHost+"/printers/"+printerName+"/receipt",
data: JSON.stringify(receipt),
beforeSend: function() {
},
success: function(res) {
}
});
}
function printToKitchen(order) {
var btprinter=$('input:hidden#btprinter').val();
var PRINTER_OK = 0;
var PRINTER_NOT_FOUND = -1;
var PRINTER_ERROR = -2;
var PRINTER_NO_PAPER = -3;
var MODE_DF = (0 << 0) // Default mode
var MODE_SF = (1 << 0) // Small font
var MODE_BL = (1 << 3) // Bold
var MODE_DH = (1 << 4) // Double height
var MODE_DW = (1 << 5) // Double width
var MODE_DS = MODE_DH | MODE_DW // Double size
var MODE_UL = (1 << 7) // Underline
// document.getElementById("demo").innerHTML = "Connecting to printer...";
var status = android.openPrinter(btprinter); // "68:AA:D2:00:CD:F0"
if (status != PRINTER_OK) {
// document.getElementById("demo").innerHTML += "ERROR " + status;
android.closePrinter();
return;
} else {
// document.getElementById("demo").innerHTML += "OK";
}
// document.getElementById("demo").innerHTML += "
Get paper status...";
status = android.getPrinterStatus();
if (status != PRINTER_OK) {
if (status == PRINTER_NO_PAPER) {
// document.getElementById("demo").innerHTML += "NO PAPER";
} else {
// document.getElementById("demo").innerHTML += "ERROR " + status;
}
android.closePrinter();
return;
} else {
// document.getElementById("demo").innerHTML += "OK";
}
android.printLogo(1);
android.printLine(MODE_DF, " Rock'N'Rolla Рок Kлуб ");
android.printLine(MODE_DF, " ул. Граф Игнатиев 1 ");
android.printLine(MODE_DF, " гр. София ");
android.printLine(MODE_DF, " Тел. +359(0)888-13-1318 ");
android.printLine(MODE_DF, " www.www.rocknrolla.bg ");
android.printLine(MODE_DF, " Добре Дошли в Rock'N'Rolla ");
android.printLine(MODE_DF, " ");
android.printLine(MODE_DF, " ");
// android.printLine(MODE_DS|MODE_SF, "Order:#"+strpad(order_id, 5, 0, STR_PAD_LEFT)+" Table: "+table+"\r\n");
android.printLine(MODE_DS|MODE_SF, "Маса: "+table+"\r\n");
var d=new Date();
var date=d.getDate()+"/"+(d.getMonth()+1)+"/"+d.getFullYear()+" "+d.getHours()+":"+d.getMinutes();
android.printLine(MODE_DF, "Дата: "+date+"\r\n");
android.printLine(MODE_DF, "Сервитьор: Жоро ");
android.printLine(MODE_DF, "--------------------------------");
var total_price=0;
var total_qty=0;
$.each(order, function(k,v) {
total_price=parseFloat(total_price)+parseFloat(v.price*v.qty);
total_qty=parseInt(total_qty)+parseInt(v.qty);
android.printLine(MODE_DF, strpad(v.qty+" x "+v.name, 25, ' ', STR_PAD_RIGHT)+strpad((parseFloat(v.price)/100).toFixed(2), 7, ' ', STR_PAD_LEFT));
});
android.printLine(MODE_DF, "--------------------------------");
android.printLine(MODE_DF, "Общо: "+strpad(total_qty, 6, ' ', STR_PAD_LEFT)+" брой(я)"+strpad((total_price/100).toFixed(2), 17, ' ', STR_PAD_LEFT));
android.printLine(MODE_DF, "ДДС 20%");
android.printLine(MODE_DF, "--------------------------------");
android.printLine(MODE_DS|MODE_SF, "Общо Сума: "+strpad(((total_price/100)*1.2).toFixed(2), 10, ' ', STR_PAD_LEFT)); // 21
android.printLine(MODE_DF, " ");
//android.printLine(MODE_UL, "Tip guide ");
//android.printLine(MODE_DF, "15%="+strpad(((total_price/100)*1.15*1.1).toFixed(2), 11, ' ', STR_PAD_RIGHT)+" 20%="+strpad(((total_price/100)*1.2*1.1).toFixed(2), 11, ' ', STR_PAD_RIGHT));
android.printLine(MODE_DF, " Благодарим Ви! ");
android.printLine(MODE_DF, " Очакваме Ви скоро! ");
android.printLine(MODE_SF, "(C)2019 Rock'N'Rolla. Всички права запазeни"); //42
android.printLine(MODE_DF, " ");
android.printLine(MODE_DF, " ");
android.printLine(MODE_DF, " ");
android.closePrinter();
/*
var total_price='';
$.each(order, function(k,v) {
total_price=total_price+v;
android.printLine(MODE_DF, v.name+" "+(v.price/100).toFixed(2));
});
*/
}