Created
March 11, 2020 05:27
-
-
Save parzibyte/c9d4bacf685a9d914359f76fd945c61f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function ticket(Request $request) | |
{ | |
$venta = Venta::findOrFail($request->get("id")); | |
$nombreImpresora = env("NOMBRE_IMPRESORA"); | |
$connector = new WindowsPrintConnector($nombreImpresora); | |
$impresora = new Printer($connector); | |
$impresora->setJustification(Printer::JUSTIFY_CENTER); | |
$impresora->setEmphasis(true); | |
$impresora->text("Ticket de venta\n"); | |
$impresora->text($venta->created_at . "\n"); | |
$impresora->setEmphasis(false); | |
$impresora->text("Cliente: "); | |
$impresora->text($venta->cliente->nombre . "\n"); | |
$impresora->text("\nhttps://parzibyte.me/blog\n"); | |
$impresora->text("\n===============================\n"); | |
$total = 0; | |
foreach ($venta->productos as $producto) { | |
$subtotal = $producto->cantidad * $producto->precio; | |
$total += $subtotal; | |
$impresora->setJustification(Printer::JUSTIFY_LEFT); | |
$impresora->text(sprintf("%.2fx%s\n", $producto->cantidad, $producto->descripcion)); | |
$impresora->setJustification(Printer::JUSTIFY_RIGHT); | |
$impresora->text('$' . number_format($subtotal, 2) . "\n"); | |
} | |
$impresora->setJustification(Printer::JUSTIFY_CENTER); | |
$impresora->text("\n===============================\n"); | |
$impresora->setJustification(Printer::JUSTIFY_RIGHT); | |
$impresora->setEmphasis(true); | |
$impresora->text("Total: $" . number_format($total, 2) . "\n"); | |
$impresora->setJustification(Printer::JUSTIFY_CENTER); | |
$impresora->setTextSize(1, 1); | |
$impresora->text("Gracias por su compra\n"); | |
$impresora->text("https://parzibyte.me/blog"); | |
$impresora->feed(5); | |
$impresora->close(); | |
return redirect()->back()->with("mensaje", "Ticket impreso"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment