diff --git a/Lib/Tickets/BaseTicket.php b/Lib/Tickets/BaseTicket.php index fbfc2b2..c69377c 100644 --- a/Lib/Tickets/BaseTicket.php +++ b/Lib/Tickets/BaseTicket.php @@ -38,7 +38,7 @@ abstract class BaseTicket /** @var array */ protected static $lines; - private static $openDrawer = true; + private static $openDrawer = false; abstract public static function print(ModelClass $model, TicketPrinter $printer, User $user, ?Agente $agent = null): bool; @@ -47,7 +47,13 @@ public static function setLines(?array $lines = null): void static::$lines = $lines; } - protected static function setOpenDrawer(bool $openDrawer): void + /** + * Esta función tiene que ser llamada antes que print() o getBody() para que tenga efecto. + * + * Esto es debido a que modifica la variable $openDrawer que si está activada injecta el código de abrir + * cajón en el body. + */ + protected static function setOpenDrawer(bool $openDrawer = true): void { static::$openDrawer = $openDrawer; } diff --git a/Model/TicketPrinter.php b/Model/TicketPrinter.php index edf2ab9..50fb013 100644 --- a/Model/TicketPrinter.php +++ b/Model/TicketPrinter.php @@ -5,6 +5,7 @@ namespace FacturaScripts\Plugins\Tickets\Model; +use FacturaScripts\Core\Session; use FacturaScripts\Core\Template\ModelClass; use FacturaScripts\Core\Template\ModelTrait; use FacturaScripts\Core\Tools; @@ -165,6 +166,28 @@ public function getDashLine(): string return $line; } + /** + * Abre la caja de una impresora + * + * Esto lo consigue creando un ticket vacío que solo contiene la instrucción de abrir cajón + * + * @return true si se ha enviado la instrucción de abrir cajón y false en cambio. + */ + public function openDrawer(): bool + { + $ticket = new Ticket(); + $ticket->idprinter = $this->id; + $ticket->title = Tools::trans('open-drawer'); + $ticket->body = $this->getCommandStr('open'); + + $user = Session::user(); + if ($user) { + $ticket->nick = $user->nick; + } + + return $ticket->save(); + } + public function install(): string { // dependencias