Skip to content

Commit 9335466

Browse files
committed
Update de layouts, integração com QZ TRAY e impressão manual de pedidos
1 parent 01e6db9 commit 9335466

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

routes/web.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@
192192

193193
//** === ROTA PRINTPEDIDO
194194
$app->get('/imprimir-pedido/{id}', [PrintController::class, 'printOrder']);
195+
$app->get('/admin/print-order/{id}', [PrintController::class, 'printOrder']);
195196

196197
// === LOGS
197198
//$app->get('/admin/logs', function ($request, $response) {

views/templates/admin/dashboard.blade.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<title>{{ $pageTitle }}</title>
77
<script src="https://cdn.tailwindcss.com"></script>
88
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
9+
<script src="https://cdn.jsdelivr.net/npm/qz-tray@2.1.0/qz-tray.js"></script> {{-- Ativando QZ Tray para impressão direta --}}
910
</head>
1011
<body class="bg-gray-100">
1112
<!-- Header -->
@@ -253,5 +254,29 @@ class="block p-6 bg-purple-50 rounded-lg hover:bg-purple-100 transition-colors">
253254
</div>
254255
</div>
255256
</main>
257+
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
258+
<script src="assets/js/admin-print-poll.js"></script>
259+
<script>
260+
// Função para abrir a janela de impressão
261+
document.querySelectorAll('.print-btn').forEach(button => {
262+
button.addEventListener('click', async () => {
263+
const orderId = button.getAttribute('data-order-id');
264+
if (!window.qz) {
265+
alert('QZ Tray não está disponível. Instale e permita o acesso.');
266+
return;
267+
}
268+
try {
269+
const resp = await fetch('/admin/print-order/' + orderId);
270+
if (!resp.ok) throw new Error('Erro ao buscar dados de impressão');
271+
const printData = await resp.json();
272+
const config = qz.configs.create(null); // impressora padrão
273+
const data = printData.map(line => line.content || '');
274+
await qz.print(config, data);
275+
} catch (e) {
276+
alert('Erro ao imprimir: ' + (e.message || e));
277+
}
278+
});
279+
});
280+
</script>
256281
</body>
257282
</html>

0 commit comments

Comments
 (0)