Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created March 6, 2020 21:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/dcc8d00fbe9ea319a1b49fb340202d1d to your computer and use it in GitHub Desktop.
Save parzibyte/dcc8d00fbe9ea319a1b49fb340202d1d to your computer and use it in GitHub Desktop.
<?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->text("https://parzibyte.me/blog\n");
$impresora->setEmphasis(false);
$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