editing printing
This commit is contained in:
parent
c451a24982
commit
26095df612
@ -774,17 +774,19 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
.catch(err => console.error(`Network Print Fetch Error (${type}):`, err));
|
||||
};
|
||||
|
||||
/**
|
||||
* Prints a thermal receipt using a hidden iframe for a smoother experience.
|
||||
* To achieve completely silent printing (Direct Print), run Chrome with:
|
||||
* chrome.exe --kiosk-printing --kiosk
|
||||
*/
|
||||
window.printThermalReceipt = function(data) {
|
||||
const width = 450;
|
||||
const height = 800;
|
||||
const left = (screen.width - width) / 2;
|
||||
const top = (screen.height - height) / 2;
|
||||
|
||||
const win = window.open('', '_blank', `width=${width},height=${height},top=${top},left=${left}`);
|
||||
|
||||
if (!win) {
|
||||
alert('Please allow popups for this website to print thermal receipts.');
|
||||
return;
|
||||
// Create or get the hidden iframe
|
||||
let iframe = document.getElementById('print-iframe');
|
||||
if (!iframe) {
|
||||
iframe = document.createElement('iframe');
|
||||
iframe.id = 'print-iframe';
|
||||
iframe.style.display = 'none';
|
||||
document.body.appendChild(iframe);
|
||||
}
|
||||
|
||||
const tr = {
|
||||
@ -856,7 +858,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
.order-info { font-size: 11px; margin-bottom: 10px; }
|
||||
.order-info-row { display: flex; justify-content: space-between; margin-bottom: 2px; }
|
||||
.rtl { direction: rtl; unicode-bidi: embed; }
|
||||
@media print { body { width: 80mm; padding: 5mm; } @page { size: 80mm auto; margin: 0; } }
|
||||
@media print { body { width: 80mm; padding: 2mm; } @page { size: 80mm auto; margin: 0; } }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
@ -905,11 +907,27 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
${settings.email ? `<div style="margin-top: 5px; font-size: 10px;">${settings.email}</div>` : ''}
|
||||
<div style="margin-top: 15px; font-size: 10px; color: #888;">Powered by Abidarcafe</div>
|
||||
</div>
|
||||
<script>window.onload = function() { window.print(); setTimeout(function() { window.close(); }, 1500); }</script>
|
||||
</body></html>
|
||||
`;
|
||||
win.document.write(html);
|
||||
win.document.close();
|
||||
|
||||
const doc = iframe.contentWindow.document;
|
||||
doc.open();
|
||||
doc.write(html);
|
||||
doc.close();
|
||||
|
||||
// Wait for resources (like logo) to load before printing
|
||||
iframe.contentWindow.onload = function() {
|
||||
iframe.contentWindow.focus();
|
||||
iframe.contentWindow.print();
|
||||
};
|
||||
|
||||
// Fallback if onload doesn't fire correctly
|
||||
setTimeout(() => {
|
||||
if (doc.readyState === 'complete') {
|
||||
iframe.contentWindow.focus();
|
||||
iframe.contentWindow.print();
|
||||
}
|
||||
}, 1000);
|
||||
};
|
||||
|
||||
window.openRatingQRModal = function() {
|
||||
@ -922,4 +940,4 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
const modal = new bootstrap.Modal(document.getElementById('qrRatingModal'));
|
||||
modal.show();
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
@ -14,8 +14,13 @@ class PrinterService {
|
||||
return ['success' => false, 'error' => 'Printer IP is not configured.'];
|
||||
}
|
||||
|
||||
// Determine if IP is local/private. If so, use a very short timeout
|
||||
// because cloud servers cannot reach local IPs anyway.
|
||||
$isLocalIp = preg_match('/^(127\.|10\.|192\.168\.|172\.(1[6-9]|2[0-9]|3[0-1])\.)/', $ip);
|
||||
$timeout = $isLocalIp ? 1 : 5; // 1 second for local, 5 for public
|
||||
|
||||
try {
|
||||
$fp = @fsockopen($ip, $port, $errno, $errstr, 5);
|
||||
$fp = @fsockopen($ip, $port, $errno, $errstr, $timeout);
|
||||
if (!$fp) {
|
||||
return ['success' => false, 'error' => "Could not connect to printer at $ip:$port. Error: $errstr ($errno)"];
|
||||
}
|
||||
@ -65,4 +70,4 @@ class PrinterService {
|
||||
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -108,11 +108,12 @@ class WablasService {
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 10); // Added 10 second timeout
|
||||
|
||||
$response = curl_exec($ch);
|
||||
$curlError = curl_error($ch);
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
$curlCloseResult = curl_close($ch);
|
||||
|
||||
if ($curlError) {
|
||||
return ['success' => false, 'message' => 'cURL Error: ' . $curlError];
|
||||
@ -130,4 +131,4 @@ class WablasService {
|
||||
|
||||
return ['success' => false, 'message' => 'HTTP Error ' . $httpCode . ': ' . (is_string($msg) ? $msg : 'Unknown')];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -281,7 +281,7 @@ function printKitchenTicket(orderId) {
|
||||
<div style="border-top: 2px dashed #000; margin-top: 20px; padding-top: 10px; text-align: center;">
|
||||
<strong>*** END OF TICKET ***</strong>
|
||||
</div>
|
||||
<script>window.onload = function() { window.print(); setTimeout(function() { window.close(); }, 500); }</script>
|
||||
<script>window.onload = function() { window.print(); setTimeout(function() { window.close(); }, 500); }<\/script>
|
||||
</body>
|
||||
</html>
|
||||
`;
|
||||
@ -383,4 +383,4 @@ setInterval(fetchOrders, 10000);
|
||||
</script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user