ordersprinter/webapp/bill.html

419 lines
14 KiB
HTML

<html>
<head>
<title>Ansicht Kassenbons</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="author" content="Stefan Pichel">
<link rel="stylesheet" type="text/css" href="css/bestformat.css?v=1.1.12">
<link rel="stylesheet" href="php/3rdparty/orderstyle/orderstyle.min.css" />
<link rel="stylesheet" href="php/3rdparty/orderstyle/jquery.mobile.icons.min.css" />
<link rel="stylesheet" href="php/3rdparty/jquery.mobile-1.4.0.min.css" type="text/css" />
<link rel="stylesheet" href="php/3rdparty/jquerymobiledatepicker/jquery.mobile.datepicker.css" />
<script src="php/3rdparty/jquerymobiledatepicker/jquery.mobile.datepicker.js"></script>
<script src="php/3rdparty/jquery-1.11.3.min.js"></script>
<script src="php/3rdparty/jquery.mobile-1.4.5.min.js"></script>
<link rel="stylesheet" href="php/3rdparty/jqueryui1-11-4/jquery-ui.min.css" />
<script src="php/3rdparty/jqueryui1-11-4/jquery-ui.min.js"></script>
<script src="php/3rdparty/jqueryui1-11-4/jquery-ui-i18n.min.js"></script>
<script src="utilities.js"></script>
<script src="receiptutils.js"></script>
<style>
@media handheld
{
.receipttable {width: 100%; background-color: #cccccc;}
}
@media all
{
.receipttable {width: 100%; background-color: #cccccc;}
}
@media all
{
#colWithBillOverview { vertical-align:top;}
}
@media all
{
#receiptbill {display: none;}
}
@media print
{
.receipttable {width: 100%;};
}
@media print
{
#receiptbill {width: 100%; display: block;};
}
@media print
{
#theheader,#modulemenu,#billlist,#thefooterr,#updatebtn,#datepickerarea {display: none;}
}
</style>
</head>
<body>
<script>
var BILL_TABLE = ["Tisch","Table","Mesa"];
var BILL_UPDATE = ["Aktualisieren","Update","Actualizar"];
var BILL_PRINT = ["Drucken","Print","Imprimir"];
var BILL_STORNO = ["Storno","Cancel","Contrapartida"];
var BILL_CLOSED = ["abgeschlossen","closed","cerrado"];
var BILL_TITLE = ["Kassenbons","Receipts","Tiques"];
var BILL_YES = ["Ja","Yes","Si"];
var BILL_NO = ["Nein","No","No"];
var BILL_STORNO_QUEST_TITLE = ["Storno?","Cancel?","Contrapartida?"];
var BILL_STORNO_QUEST_TEXT = ["Bon stornieren?","Cancel the receipt?","Contrapartida del tique"];
var BILL_NO_CANCEL_POSS = ["Der Stornovorgang ist fehlgeschlagen. Die wahrscheinlichste Ursache ist ein Tagesabschluss, der den zu stornierenden Bon einschließt. In diesem Fall darf der Bon rückwirkend nicht mehr annuliert werden.",
"Cancelling was not possible. Probably the receipt to cancel is already part of a closing. In this case the receipt cannot be cancelled.",
"Contrapartida no fue posible. Probablemente el tique esta ya cerrado."];
var BILL_DATE = ["Datum","Date","Fecha"];
var BILL_STORNO_REASON = ["Stornogrund","Reason","Razón"];
var lang = 0;
var when = 0;
var decpoint = ".";
// REM* contains the bill information from server
var jsonBills = "";
function setLanguage(language) {
lang = language;
$("#updatebtntxt").html(BILL_UPDATE[lang]);
$("#billtitletxt").html(BILL_TITLE[lang]);
$("#stornoyes").html(BILL_YES[lang]);
$("#stornono").html(BILL_NO[lang]);
$("#billnocancelposs").html(BILL_NO_CANCEL_POSS[lang]);
$("#datetxt").html(BILL_DATE[lang]);
$("#stornoreasontxt").html(BILL_STORNO_REASON[lang]);
var langtxt = "de";
if (lang == 1) {
langtxt = "en";
} else if (lang == 2) {
langtxt = "es";
}
var currentYear = new Date().getFullYear();
var yearRangeTxt = (currentYear-5) + ":" + (currentYear);
$("#datepicker").datepicker($.datepicker.regional[langtxt]).datepicker("option", {
changeMonth: true,
changeYear: true,
yearRange: yearRangeTxt,
});
$('#datepicker').datepicker('setDate', new Date());
}
function updatelistener() {
$("#updatebtn").off("click").on("click", function (e) {
e.stopImmediatePropagation();
e.preventDefault();
getLastBills();
});
}
function getLastBills() {
var date = $("#datepicker").datepicker("getDate");
var data = {
day: date.getDate(),
month: (date.getMonth() + 1),
year: date.getFullYear(),
};
doAjax("GET","php/contenthandler.php?module=bill&command=getLastBillsWithContent",data,displayBillsWithContent,"letzte Bons");
}
function doAjaxCancelBill(billid,stornocode,reason) {
var data = {
billid: billid,
stornocode: stornocode,
reason:reason.trim()
};
doAjax("POST","php/contenthandler.php?module=bill&command=cancelBill",data,cancelBill,"Bonstorno abgebrochen");
}
function cancelBill(jsonText) {
if (jsonText.status != "OK") {
alert("Fehler " + jsonText.code + ": " + jsonText.msg);
return;
}
setTimeout(function(){location.reload()},1000);
}
function displayBillsWithContent (jsonContent) {
if (jsonContent.status != "OK") {
$("#billlist").html("");
$('#billlist').trigger('create');
alert("Fehler " + jsonContent.code + ": " + jsonContent.msg);
return;
}
jsonBills = jsonContent;
$("#billlist").html("");
var currency = $("#bill-page").data("currency");
var txt = "";
jsonContent = jsonContent.msg;
for (var i=0;i<jsonContent.length;i++) {
var entry = jsonContent[i];
var id = entry.id;
var shortdate = entry.shortdate;
var longdate = entry.longdate;
var tablename = entry.tablename;
var brutto = (entry.brutto).replace(".",decpoint);
var collapse_elem_id = 'collapse_' + id;
var collapse_elem = '<div data-role="collapsible" data-content-theme="e" id="'+collapse_elem_id+'" data-collapsed="true" data-theme="c" class="billcollapsible">';
var header = '<h3>'+shortdate + ": " + BILL_TABLE[lang] + " &lt;" + tablename + "&gt; " + brutto + ' ' + currency + '</h3>';
if (entry.isClosed == 1) {
header = '<h3>'+shortdate + ": " + BILL_TABLE[lang] + " &lt;" + tablename + "&gt; " + brutto + ' ' + currency + ' -' + BILL_CLOSED[lang] + '-</h3>';
}
var waitTxt = '<p><img src=php/3rdparty/images/ajax-loader.gif /></p>';
txt += collapse_elem + header + waitTxt + "</div>";
}
$("#billlist").html(txt);
$('#billlist').trigger('create');
$(".billcollapsible").off("collapsibleexpand").on("collapsibleexpand", function (e) {
e.stopImmediatePropagation();
e.preventDefault();
var billid = this.id.split("_")[1];
var bill = getBillWithId(billid);
// REM* insert now the bill into collapsible_billid
$("#collapse_" + billid + " p").html(bill[0]);
var entry = bill[2];
var date_time = bill[1];
var longdate = entry.longdate;
var printbuttonid = 'print_' + billid;
var cancelbuttonid = 'cancel_' + billid;
$("#collapse_" + billid).find("#billdate").html(date_time);
var contentToPrint = new Array(id,longdate,bill[0]);
$("#" + printbuttonid).data("entrydata", contentToPrint);
if (entry.isClosed == 0) {
$("#" + cancelbuttonid).data("billid", id);
}
$("#collapse_" + billid).trigger("create");
$(".printbuttons").off("click").on("click", function (e) {
var billid = this.id.split("_")[1];
var contentToPrint = $("#print_" + billid).data("entrydata");
$("#receiptbill").html(contentToPrint[2]);
$("#receiptbill table").css('width', '100%');
$("#receiptbill").find("#billdate").html(contentToPrint[1]);
$("#receiptbill").find("#billid").html(contentToPrint[0]);
var payPrintType = $("#bill-page").data("payPrintType");
if (payPrintType == 's') {
printBill(billid);
} else {
window.print();
}
});
$(".cancelbuttons").off("click").on("click", function (e) {
var billid = this.id.split("_")[1];
$("#stornocode").val("");
$("#stornoreason").val("");
areYouSure(BILL_STORNO_QUEST_TITLE[lang], BILL_STORNO_QUEST_TEXT[lang], BILL_YES[lang], function() {
doAjaxCancelBill(billid,$("#stornocode").val(),$("#stornoreason").val());
});
});
});
}
function getBillWithId(id) {
var logoUrl = $("#bill-page").data("logourl");
var companyInfo = $("#bill-page").data("companyinfo");
var currency = $("#bill-page").data("currency");
var hosthtml = jsonBills.hosthtml;
var bills = jsonBills.msg;
// get entry with that billid
var entry = null;
for (var i=0;i<bills.length;i++) {
if (bills[i].id == id) {
entry = bills[i];
break
}
}
if (entry == null) {
alert("ERROR - Rechnung mit ID " + id + " konnte nicht gefunden werden");
return;
}
var content = generateHtmlBillFromScratch(lang,id,entry.billcontent,currency,decpoint,companyInfo,hosthtml);
var printbuttonid = 'print_' + id;
var cancelbuttonid = 'cancel_' + id;
var collapse_elem_id = 'collapse_' + id;
var printbutton = '<a href="#" data-role="button" id="' + printbuttonid + '" data-theme="f" class="printbuttons">' + BILL_PRINT[lang] + '</a>';
var cancelButton = '<a href="#" data-role="button" id="' + cancelbuttonid + '" data-theme="f" class="cancelbuttons">' + BILL_STORNO[lang] + '</a>';
var bi = entry.billcontent.billoverallinfo;
var date_time = bi.billday + "." + bi.billmonth + "." + bi.billyear + " " + bi.billhour + ":" + bi.billmin;
var txt = '<center>' + printbutton;
if (entry.isClosed == 0) {
// REM* bill is not closed - so can be printed AND cancelled
txt += cancelButton + '<br>' + content + '</center>';
} else {
// REM* bill is closed - only printing possible, no cancelling
txt += '<p><center>' + '<br>' + content + '</center>';
}
return [txt,date_time,entry];
}
function printBill(billid) {
doAjax("POST","php/contenthandler.php?module=printqueue&command=queueReceiptPrintJob",
{billid : billid }, null, "Druckfehler");
}
function areYouSure(text1, text2, button, callback) {
$("#sure .sure-1").text(text1);
$("#sure .sure-2").text(text2);
$("#sure .sure-do").text(button).off("click.sure").on("click.sure", function(e) {
e.stopImmediatePropagation();
e.preventDefault();
$("#nocancelbtn").off("click");
$( "#sure" ).dialog( "close" );
$.mobile.changePage("#bill-page");
callback();
$(this).off("click.sure");
});
$("#nocancelbtn").off("click").on("click", function (e) {
e.stopImmediatePropagation();
e.preventDefault();
$("#sure .sure-do").text(button).off("click.sure");
$( "#sure" ).dialog( "close" );
$.mobile.changePage("#bill-page");
});
$.mobile.changePage("#sure");
}
function getGeneralConfigItems() {
doAjax("GET", "php/contenthandler.php?module=admin&command=getGeneralConfigItems", null, insertGenConfigStartRest, "Fehler Konfigurationsdaten");
}
function insertGenConfigStartRest(configResult) {
if (configResult.status == "OK") {
var values = configResult.msg;
$("#bill-page").data("payPrintType",values.payprinttype);
$("#bill-page").data("currency",values.currency);
$("#bill-page").data("billanguage",values.billlanguage);
$("#bill-page").data("logourl",values.logourl);
$("#bill-page").data("companyinfo",values.companyinfo);
decpoint = values.decpoint;
setLanguage(values.userlanguage);
getLastBills();
updatelistener();
bindWhenSelection();
} else {
setTimeout(function(){document.location.href = "index.html"},250); // not logged in
}
}
function bindWhenSelection() {
$("#datepicker").off("change").on("change", function (e) {
var date = $("#datepicker").datepicker("getDate");
getLastBills();
updatelistener();
bindWhenSelection();
});
}
//pageinit event for first page
//triggers only once
//write all your on-load functions and event handlers pertaining to page1
$(document).on("pageinit", "#bill-page", function () {
initializeMainMenu("#modulemenu");
hideMenu();
$.ajaxSetup({ cache: false });
getGeneralConfigItems();
});
</script>
<div data-role="page" id="bill-page">
<div data-role="panel" id="modulepanel" data-position="right" data-display="overlay">
<ul data-role="listview" id="modulemenu" data-divider-theme="a" data-inset="true">
<li data-role="list-divider" data-theme="b" data-role="heading">Module</li>
</ul>
</div><!-- /panel -->
<div data-role="header" data-theme="b" data-position="fixed" id="theheader">
<h1><span id="billtitletxt">Kassenbons</span></h1>
<div data-type="horizontal" style="top:0px;position:absolute;float:right;z-index:10;display:inline;" align="right" class="ui-btn-right">
<a href="#" data-role="button" data-icon="arrow-d" data-ajax="false" id="menuswitch"><span id="modulstxt2">Module</span></a>
</div>
</div>
<div data-role="content">
<div data-role="fieldcontain" id="datepickerarea">
<label for="datepicker"><span id=datetxt>Datum</span>: </label>
<input data-role="date" data-inline="true" type="text" id="datepicker" data-theme="d">
</div>
<a href="#" data-role="button" data-theme="f" id="updatebtn"><span id="updatebtntxt">Aktualisieren</span></a>
<br><br>
<div id=billlist></div>
<div id=receiptbill></div>
</div>
<div data-role="footer" data-theme="b" id="thefooterr">
<div class="ui-grid-a">
<div class="ui-block-a userinfo" id="loggedinuser"></div>
<div class="ui-block-b grid_right" id="versioninfo"></div>
</div><!-- /grid-a -->
</div> <!-- footer -->
<div data-role="popup" id="cancelfailed" name="cancelfailed" data-overlay-theme="a" style="max-width:70%;" class="ui-corner-all">
<div data-role="header" class="ui-corner-top">
<h1>Storno fehlgeschlagen</h1>
</div>
<a href="#" data-rel="back" data-role="button" data-theme="a" data-icon="delete" data-iconpos="notext" class="ui-btn-right"></a>
<div data-role="content" class="ui-corner-bottom ui-content">
<p><span id="billnocancelposs">Der Stornovorgang ist fehlgeschlagen. Die wahrscheinlichste Ursache ist ein Tagesabschluss, der den zu
stornierenden Bon einschließt. In diesem Fall darf der Bon rückwirkend nicht mehr annuliert werden.</span></p>
</div>
</div> <!-- popup for reading sample queue data -->
</div>
<!-- Dialog page -->
<div data-role="dialog" id="sure" data-title="Entfernen?">
<div data-role="content">
<h3 class="sure-1">?</h3>
<p class="sure-2">?</p>
<form>
<label for="stornoreason"><span id="stornoreasontxt">Stornogrund:</span></label>
<input type="text" id="stornoreason" value="" data-mini="true /">
<label for="stornocode">Stornocode: </label>
<input type="password" id="stornocode" value="" data-mini="true">
<a href="#" class="sure-do" data-role="button" data-theme="b" data-rel="back"><span id="stornoyes">Ja</span></a>
<a href="#" data-role="button" data-theme="c" id="nocancelbtn"><span id="stornono">Nein</span></a>
</form>
</div>
</div>
</body>
</html>