ordersprinter/webapp/receiptutils.js

195 lines
7.2 KiB
JavaScript
Raw Normal View History

2020-11-19 22:47:44 +01:00
var P_SUM = ["Summe:","Sum:","Todo:"];
var P_TOTAL = ["Total","Total","Total"];
var P_MWST = ["MwSt","Tax","IVA"];
var P_NETTO = ["Netto","Net","Neto"];
var P_BRUTTO = ["Brutto","Gross","Bruto"];
var P_ID = ["Id:","Id:","Id:"];
var P_TABLE = ["Tisch:","Table:","Mesa:"];
var P_WAITER = ["Es bediente Sie:", "Waiter:", "Camarero:"];
var P_NO = ["Anz.", "No.", "Nú."];
var P_DESCR = ["Beschreibung","Description","Descripción"];
var P_PRICE = ["Preis","Price","Precio"];
function genCreateReceiptHeader(lang,billid,tablename,username,currency) {
var priceStyle = 'style="border: solid black 0px;padding: 3px;text-align:right;vertical-align:bottom;"';
var tableinfo = P_TABLE[lang] + " " + tablename;
var waiterinfo = P_WAITER[lang] + " " + username;
var header = '';
header += '<tr><td colspan=6>&nbsp;</tr>';
header += '<tr><td colspan=4>' + tableinfo + ' <td id="billid" colspan=2 ' + priceStyle + '>ID:' + billid + '</tr>';
header += '<tr><td colspan=4>&nbsp;<td id="billdate" colspan=2 ' + priceStyle + '></tr>';
header += '<tr><td colspan=6>' + waiterinfo + "</tr>";
header += '<tr><td colspan=6>&nbsp</tr>';
header += '<tr><td>' + P_NO[lang] + '<td colspan=3>' + P_DESCR[lang] + '<td ' + priceStyle + '>' + P_PRICE[lang] + '<td ' + priceStyle + '>' + P_TOTAL[lang] + '</tr>';
return header;
}
function genCreateReceiptFooterNoSum(taxGerFormat, lang, companyInfo, taxes) {
return genCreateReceiptFooter(taxGerFormat, lang, companyInfo,"","","", taxes);
}
// REM* taxes must be strings with decpoint already country-specific!
function genCreateReceiptFooter(taxGerFormat, lang, companyInfo,mwst,netto,sum, taxes) {
var priceStyle = 'style="border: solid black 0px;padding: 3px;text-align:right;vertical-align:bottom;"';
var infoStyle = 'style="text-align:center;vertical-align:bottom;"';
var emptyLine = '<tr><td colspan=6>&nbsp</tr>';
var footer = emptyLine;
footer += '<tr><td colspan=2>' + P_MWST[lang] + '% <td ' + priceStyle + '>' + P_MWST[lang] + '<td ' + priceStyle + '>' + P_NETTO[lang] + '<td ' + priceStyle + ' colspan=2>' + P_BRUTTO[lang] + '</tr>';
// REM* for each tax create a line
for (var i=0;i<taxes.length;i++) {
var tax = taxes[i];
tax = tax.replace(",","-");
footer += '<tr><td id="taxval' + tax + '" colspan=2><td id="mwst' + tax + '" ' + priceStyle + '>' + mwst + '<td id="netto' + tax + '" ' + priceStyle + '>' + netto + '<td id="brutto' + tax + '" ' + priceStyle + ' colspan=2>' + sum + '</tr>';
}
footer += emptyLine;
footer += '<tr><td> &nbsp; <td colspan=3>' + P_SUM[lang] + '<td id="priceinreceipt2" ' + priceStyle + ' colspan=2>' + sum + '</td></tr>';
footer += emptyLine;
footer += '<tr><td ' + infoStyle + ' colspan=6><center>&nbsp;<br>';
footer += toHtml(companyInfo).replace(/(?:\r\n|\r|\n)/g, '<br />');
footer += '</center></tr>';
return footer;
}
// REM* this method is called in bill.html - not paydesk
function createReceiptFooterFromDbTaxes(lang, companyInfo,sum,taxes,decPoint) {
var priceStyle = 'style="border: solid black 0px;padding: 3px;text-align:right;vertical-align:bottom;"';
var infoStyle = 'style="text-align:center;vertical-align:bottom;"';
var emptyLine = '<tr><td colspan=6>&nbsp</tr>';
var footer = emptyLine;
footer += '<tr><td colspan=2>' + P_MWST[lang] + '% <td ' + priceStyle + '>' + P_MWST[lang] + '<td ' + priceStyle + '>' + P_NETTO[lang] + '<td ' + priceStyle + ' colspan=2>' + P_BRUTTO[lang] + '</tr>';
for (var i=0;i<taxes.length;i++) {
var tax = taxes[i];
footer += "<tr><td colspan=2>" + tax.tax;
footer += "<td " + priceStyle + ">" + tax.mwst.replace(".",decPoint);
footer += "<td " + priceStyle + ">" + tax.netto.replace(".",decPoint);
footer += "<td colspan=2 " + priceStyle + ">" + tax.brutto.replace(".",decPoint);
footer += "</tr>";
}
footer += emptyLine;
footer += '<tr><td> &nbsp; <td colspan=3>' + P_SUM[lang] + '<td id="priceinreceipt2" ' + priceStyle + ' colspan=2>' + sum.toFixed(2).replace(".",decPoint) + '</td></tr>';
footer += emptyLine;
footer += '<tr><td ' + infoStyle + ' colspan=6><center>&nbsp;<br>';
footer += toHtml(companyInfo).replace(/(?:\r\n|\r|\n)/g, '<br />');
footer += '</center></tr>';
return footer;
}
2020-11-19 22:55:20 +01:00
function generateOneProdLine(count,productname,price,pricelevelname,decPoint,togo) {
2020-11-19 22:47:44 +01:00
var priceStyle = 'style="border: solid black 0px;padding: 3px;text-align:right;vertical-align:bottom;"';
var noStyle = 'style="border: solid black 0px;padding: 3px;text-align:center;vertical-align:bottom;"';
var formattedPrice = (parseFloat(price)).toFixed(2).replace(".",decPoint);
if (pricelevelname != "A") {
productname += " (" + pricelevelname + ")";
}
2020-11-19 22:55:20 +01:00
if (togo == 1) {
productname = "To-Go: " + productname;
}
2020-11-19 22:47:44 +01:00
var totalPrice = count * price;
var formattedTotal = totalPrice.toFixed(2).replace(".",decPoint);
var aProductLine = '<tr>';
var cutStyle = 'style="white-space: nowrap;overflow: hidden;text-overflow:ellipsis;width: 60%;"';
aProductLine += '<td ' + noStyle + ' id="count">' + count + '<td colspan=3 ' + cutStyle + '>' + productname;
aProductLine = aProductLine + '<td ' + priceStyle + '>' + formattedPrice;
aProductLine += '<td ' + priceStyle + '>' + totalPrice.toFixed(2).replace(".",decPoint) + '</tr>';
return aProductLine;
}
/**
* Generate the product part of a receipt on base of html table array elements
*
* @param decPoint
* @param entryListForReceipt
* @returns {String}
*/
function generateProdPart(decPoint,entryListForReceipt) {
var index=0;
tablecontent = '';
// REM* entryListForReceipt has entries of [0] count, [1] entry as object
for (index=0;index<entryListForReceipt.length;index++) {
// REM* for the html receipt
var anEntry = entryListForReceipt[index];
var count = parseInt(anEntry[0]);
var prodEntry = anEntry[1];
var productname = prodEntry.longname;
var price = prodEntry.price;
2020-11-19 22:55:20 +01:00
var togo = prodEntry.togo;
2020-11-19 22:47:44 +01:00
var pricelevelname = prodEntry.pricelevelname;
2020-11-19 22:55:20 +01:00
tablecontent += generateOneProdLine(count,productname,price,pricelevelname,decPoint,togo);
2020-11-19 22:47:44 +01:00
}
return tablecontent;
}
function generateProdPartByDbContent(decPoint,prods) {
var index=0;
tablecontent = '';
for (index=0;index<prods.length;index++) {
// for the html receipt
var anEntry = prods[index];
var count = anEntry.count;
var productname = anEntry.productname;
var price = anEntry.price;
var pricelevelname = anEntry.pricelevel;
tablecontent += generateOneProdLine(count,productname,price,pricelevelname,decPoint);
}
return tablecontent;
}
/**
* Generate HTML output on base of db content
*/
function generateHtmlBillFromScratch(lang,billid,billcontent,currency,decPoint,companyInfo,hosthtml) {
var table = '<table id="receiptpart" class="receipttable" border=1 style="table-layout: fixed;">';
var overallinfo = billcontent.billoverallinfo;
var prods = billcontent.products;
var username = overallinfo.username;
var tablename = overallinfo.table;
var header = genCreateReceiptHeader(lang,billid,tablename,username,currency);
var products = generateProdPartByDbContent(decPoint,prods);
var sum = parseFloat(overallinfo.brutto);
var footer = createReceiptFooterFromDbTaxes(lang, companyInfo,sum,billcontent.taxes,decPoint);
var receipt = table + header + products + footer;
if (overallinfo.host == 1) {
receipt += hosthtml;
}
receipt += "</table>";
return receipt;
}