Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Lib/Tickets/BaseTicket.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}
Expand Down
23 changes: 23 additions & 0 deletions Model/TicketPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Loading