File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change 192
192
193
193
//** === ROTA PRINTPEDIDO
194
194
$ app ->get ('/imprimir-pedido/{id} ' , [PrintController::class, 'printOrder ' ]);
195
+ $ app ->get ('/admin/print-order/{id} ' , [PrintController::class, 'printOrder ' ]);
195
196
196
197
// === LOGS
197
198
//$app->get('/admin/logs', function ($request, $response) {
Original file line number Diff line number Diff line change 6
6
<title >{{ $pageTitle } } </title >
7
7
<script src =" https://cdn.tailwindcss.com" ></script >
8
8
<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 --}}
9
10
</head >
10
11
<body class =" bg-gray-100" >
11
12
<!-- Header -->
@@ -253,5 +254,29 @@ class="block p-6 bg-purple-50 rounded-lg hover:bg-purple-100 transition-colors">
253
254
< / div>
254
255
< / div>
255
256
< / 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>
256
281
< / body>
257
282
< / html>
You can’t perform that action at this time.
0 commit comments