-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathInit.php
79 lines (66 loc) · 2.23 KB
/
Init.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
/**
* Copyright (C) 2019-2024 Carlos Garcia Gomez <carlos@facturascripts.com>
*/
namespace FacturaScripts\Plugins\Tickets;
require_once __DIR__ . '/vendor/autoload.php';
use FacturaScripts\Core\Base\DataBase;
use FacturaScripts\Core\Template\InitClass;
use FacturaScripts\Core\Tools;
use FacturaScripts\Dinamic\Controller\SendTicket;
use FacturaScripts\Dinamic\Lib\ExportManager;
use FacturaScripts\Dinamic\Lib\Tickets\Gift;
use FacturaScripts\Dinamic\Lib\Tickets\Normal;
use FacturaScripts\Dinamic\Lib\Tickets\PaymentReceipt;
/**
* @author Carlos Garcia Gomez <carlos@facturascripts.com>
*/
final class Init extends InitClass
{
public function init(): void
{
ExportManager::addOption('Ticket', 'ticket', 'fas fa-receipt');
$this->loadFormatTickets();
}
public function uninstall(): void
{
}
public function update(): void
{
// activamos la API
$this->setAPI();
// renombramos la tabla de tickets de antiguas versiones
$this->renameTicketsTable('tickets', 'tickets_docs');
}
private function loadFormatTickets(): void
{
$models = ['PresupuestoCliente', 'PedidoCliente', 'AlbaranCliente', 'FacturaCliente'];
foreach ($models as $model) {
SendTicket::addFormat(Normal::class, $model, 'normal');
SendTicket::addFormat(Gift::class, $model, 'gift');
}
SendTicket::addFormat(PaymentReceipt::class, 'ReciboCliente', 'receipt');
}
private function renameTicketsTable(string $oldTable, string $newTable): void
{
$dataBase = new DataBase();
if (false === $dataBase->tableExists($oldTable)) {
return;
}
// comprobamos las columnas de la tabla antigua
$columns = $dataBase->getColumns($oldTable);
if (isset($columns['id']) && isset($columns['idprinter'])) {
$dataBase->exec("RENAME TABLE " . $oldTable . " TO " . $newTable . ";");
}
}
private function setAPI(): void
{
// si hay clave de API en el config, no hacemos nada
if (defined('FS_API_KEY')) {
return;
}
// activamos la API
Tools::settingsSet('default', 'enable_api', true);
Tools::settingsSave();
}
}