Use NickelBridge to print receipts when possible, close #19

master
Skylar Ittner 6 years ago
parent c4c387cf62
commit da2fee3222

@ -310,7 +310,7 @@ switch ($VARS['action']) {
case "getreceipt":
require_once __DIR__ . "/lib/generatereceipt.php";
$format = "html";
$width = 64;
$width = 48;
if (isset($VARS['width']) && preg_match("/[0-9]+/", $VARS['width']) && (int) $VARS['width'] > 0) {
$width = (int) $VARS['width'];
}

@ -5,6 +5,9 @@
*/
var nickelbridge = false;
var receiptwidth = 48;
$('#name').on('input propertychange paste', function () {
$('#name_title').text($('#name').val());
});
@ -14,6 +17,7 @@ $("#zreport").on('change', function () {
if (cashid == "") {
return;
}
$("#zframe").data('cash', cashid);
$("#zframe").attr("src", "action.php?action=zreport&cash=" + cashid);
});
@ -22,5 +26,32 @@ $("#printzreportbtn").click(function () {
if (cashid == "") {
return;
}
document.getElementById("zframe").contentWindow.print();
if (nickelbridge) {
$.get('action.php', {
action: 'zreport',
format: 'json',
width: receiptwidth,
cash: $("#zframe").data('cash')
}, function (receipt) {
$.ajax("http://127.0.0.1:64269/print", {
data: JSON.stringify(receipt),
contentType: 'application/json',
type: 'POST',
success: function (resp) {
}
}).fail(function (resp) {
alert("Error: " + JSON.stringify(resp));
});
});
} else {
document.getElementById("zframe").contentWindow.print();
}
});
$.get('http://127.0.0.1:64269/status', {}, function (resp) {
if (resp.status == "OK") {
nickelbridge = true;
receiptwidth = resp.width;
}
});

@ -4,6 +4,9 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
var nickelbridge = false;
var receiptwidth = 48;
function recalculate() {
removezero();
var total = 0.0;
@ -66,4 +69,11 @@ $(document).ready(function () {
if ($("#return").length) {
recalculate();
}
$.get('http://127.0.0.1:64269/status', {}, function (resp) {
if (resp.status == "OK") {
nickelbridge = true;
receiptwidth = resp.width;
}
});
});

@ -117,6 +117,7 @@ function sendReturnToServer(callback) {
function showReceipt(txid) {
$("#receiptchangediv").removeClass("d-none");
$("#receiptframe").data("txid", txid);
$("#receiptframe").attr("src", 'action.php?action=getreceipt&txid=' + txid);
$("#receiptmodal").modal();
}
@ -150,7 +151,27 @@ $("#finishbtn").click(function () {
});
$("#receiptprintbtn").click(function () {
document.getElementById("receiptframe").contentWindow.print();
if (nickelbridge) {
$.get('action.php', {
action: 'getreceipt',
format: 'json',
width: receiptwidth,
txid: $("#receiptframe").data('txid')
}, function (receipt) {
$.ajax("http://127.0.0.1:64269/print", {
data: JSON.stringify(receipt),
contentType: 'application/json',
type: 'POST',
success: function (resp) {
}
}).fail(function (resp) {
alert("Error: " + JSON.stringify(resp));
});
});
} else {
document.getElementById("receiptframe").contentWindow.print();
}
});
$("#receiptmodal").on("hide.bs.modal", function () {

@ -11,7 +11,27 @@ $("#openmanagement").click(function () {
});
$("#xprintbtn").click(function () {
document.getElementById("xframe").contentWindow.print();
if (nickelbridge) {
$.get('action.php', {
action: 'xreport',
format: 'json',
width: receiptwidth,
register: $("#register").data('id')
}, function (receipt) {
$.ajax("http://127.0.0.1:64269/print", {
data: JSON.stringify(receipt),
contentType: 'application/json',
type: 'POST',
success: function (resp) {
}
}).fail(function (resp) {
alert("Error: " + JSON.stringify(resp));
});
});
} else {
document.getElementById("xframe").contentWindow.print();
}
});
function showTransactionList(search) {

Loading…
Cancel
Save