editing printing

This commit is contained in:
Flatlogic Bot 2026-02-28 12:59:44 +00:00
parent c451a24982
commit 26095df612
4 changed files with 45 additions and 21 deletions

View File

@ -774,17 +774,19 @@ document.addEventListener('DOMContentLoaded', () => {
.catch(err => console.error(`Network Print Fetch Error (${type}):`, err)); .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) { window.printThermalReceipt = function(data) {
const width = 450; // Create or get the hidden iframe
const height = 800; let iframe = document.getElementById('print-iframe');
const left = (screen.width - width) / 2; if (!iframe) {
const top = (screen.height - height) / 2; iframe = document.createElement('iframe');
iframe.id = 'print-iframe';
const win = window.open('', '_blank', `width=${width},height=${height},top=${top},left=${left}`); iframe.style.display = 'none';
document.body.appendChild(iframe);
if (!win) {
alert('Please allow popups for this website to print thermal receipts.');
return;
} }
const tr = { const tr = {
@ -856,7 +858,7 @@ document.addEventListener('DOMContentLoaded', () => {
.order-info { font-size: 11px; margin-bottom: 10px; } .order-info { font-size: 11px; margin-bottom: 10px; }
.order-info-row { display: flex; justify-content: space-between; margin-bottom: 2px; } .order-info-row { display: flex; justify-content: space-between; margin-bottom: 2px; }
.rtl { direction: rtl; unicode-bidi: embed; } .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> </style>
</head> </head>
<body> <body>
@ -905,11 +907,27 @@ document.addEventListener('DOMContentLoaded', () => {
${settings.email ? `<div style="margin-top: 5px; font-size: 10px;">${settings.email}</div>` : ''} ${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 style="margin-top: 15px; font-size: 10px; color: #888;">Powered by Abidarcafe</div>
</div> </div>
<script>window.onload = function() { window.print(); setTimeout(function() { window.close(); }, 1500); }</script>
</body></html> </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() { window.openRatingQRModal = function() {

View File

@ -14,8 +14,13 @@ class PrinterService {
return ['success' => false, 'error' => 'Printer IP is not configured.']; 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 { try {
$fp = @fsockopen($ip, $port, $errno, $errstr, 5); $fp = @fsockopen($ip, $port, $errno, $errstr, $timeout);
if (!$fp) { if (!$fp) {
return ['success' => false, 'error' => "Could not connect to printer at $ip:$port. Error: $errstr ($errno)"]; return ['success' => false, 'error' => "Could not connect to printer at $ip:$port. Error: $errstr ($errno)"];
} }

View File

@ -108,11 +108,12 @@ class WablasService {
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload)); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 10); // Added 10 second timeout
$response = curl_exec($ch); $response = curl_exec($ch);
$curlError = curl_error($ch); $curlError = curl_error($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch); $curlCloseResult = curl_close($ch);
if ($curlError) { if ($curlError) {
return ['success' => false, 'message' => 'cURL Error: ' . $curlError]; return ['success' => false, 'message' => 'cURL Error: ' . $curlError];

View File

@ -281,7 +281,7 @@ function printKitchenTicket(orderId) {
<div style="border-top: 2px dashed #000; margin-top: 20px; padding-top: 10px; text-align: center;"> <div style="border-top: 2px dashed #000; margin-top: 20px; padding-top: 10px; text-align: center;">
<strong>*** END OF TICKET ***</strong> <strong>*** END OF TICKET ***</strong>
</div> </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> </body>
</html> </html>
`; `;