|
| 1 | +<?php |
| 2 | +namespace Parzibyte\Controladores; |
| 3 | + |
| 4 | +use Exception; |
| 5 | +use Mike42\Escpos\PrintConnectors\WindowsPrintConnector; |
| 6 | +use Mike42\Escpos\Printer; |
| 7 | +use Parzibyte\Modelos\ModeloPagos; |
| 8 | +use Parzibyte\Servicios\Comun; |
| 9 | + |
| 10 | +class ControladorTickets |
| 11 | +{ |
| 12 | + public static function imprimirTicketDePago($idPago) |
| 13 | + { |
| 14 | + try { |
| 15 | + $nombreImpresora = Comun::env("NOMBRE_IMPRESORA"); |
| 16 | + } catch (Exception $e) { |
| 17 | + return false; |
| 18 | + } |
| 19 | + $connector = new WindowsPrintConnector($nombreImpresora); |
| 20 | + $printer = new Printer($connector); |
| 21 | + $pago = ModeloPagos::obtenerPorId($idPago); |
| 22 | + if (!$pago) { |
| 23 | + return false; |
| 24 | + } |
| 25 | + $repeticiones = 20; |
| 26 | + $printer->setTextSize(2, 2); |
| 27 | + $printer->text("Comprobante"); |
| 28 | + $printer->feed(); |
| 29 | + $printer->setTextSize(1, 1); |
| 30 | + $printer->text(str_repeat("=", $repeticiones)); |
| 31 | + $printer->feed(); |
| 32 | + $printer->text("Nombre: " . $pago->persona); |
| 33 | + $printer->feed(); |
| 34 | + $printer->text("Monto: $" . number_format($pago->monto, 2, ".", ",")); |
| 35 | + $printer->feed(); |
| 36 | + $printer->text("Fecha: " . $pago->fecha); |
| 37 | + $printer->feed(); |
| 38 | + $printer->text("Hash: " . $pago->hash); |
| 39 | + $printer->feed(); |
| 40 | + $printer->text(str_repeat("=", $repeticiones)); |
| 41 | + $printer->feed(); |
| 42 | + |
| 43 | + $printer->feed(); |
| 44 | + $printer->text("Total abonado por ti: $" . number_format(ModeloPagos::totalDePersona($pago->idPersona), 2, ".", ",")); |
| 45 | + $printer->feed(); |
| 46 | + $printer->text("Total abonado por todos: $" . number_format(ModeloPagos::total(), 2, ".", ",")); |
| 47 | + $printer->feed(2); |
| 48 | + $printer->text("(Calculados en la fecha de impreso este ticket)"); |
| 49 | + |
| 50 | + $printer->feed(5); |
| 51 | + $printer->cut(); |
| 52 | + $printer->pulse(); |
| 53 | + $printer->close(); |
| 54 | + return true; |
| 55 | + } |
| 56 | +} |
0 commit comments