diff --git a/action.php b/action.php index 8553509..79477d5 100644 --- a/action.php +++ b/action.php @@ -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']; } diff --git a/static/js/editregister.js b/static/js/editregister.js index 7f6b125..90cf382 100644 --- a/static/js/editregister.js +++ b/static/js/editregister.js @@ -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; + } }); \ No newline at end of file diff --git a/static/js/pos.js b/static/js/pos.js index 4b5be09..baf91e9 100644 --- a/static/js/pos.js +++ b/static/js/pos.js @@ -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; + } + }); }); \ No newline at end of file diff --git a/static/js/pos_finish.js b/static/js/pos_finish.js index 91556b5..a13c9d5 100644 --- a/static/js/pos_finish.js +++ b/static/js/pos_finish.js @@ -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 () { diff --git a/static/js/pos_management.js b/static/js/pos_management.js index 62da8d4..d27f805 100644 --- a/static/js/pos_management.js +++ b/static/js/pos_management.js @@ -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) {