-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathInit.php
148 lines (125 loc) · 5.43 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php
/**
* This file is part of Anticipos plugin for FacturaScripts
* Copyright (C) 2024 Carlos Garcia Gomez <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace FacturaScripts\Plugins\Anticipos;
use FacturaScripts\Core\Plugins;
use FacturaScripts\Core\Tools;
use FacturaScripts\Core\Base\InitClass;
use FacturaScripts\Core\Base\DataBase;
use FacturaScripts\Dinamic\Lib\ExportManager;
use FacturaScripts\Dinamic\Model\EmailNotification;
/**
* Description of Init
*
* @author Jorge-Prebac <[email protected]>
*/
class Init extends InitClass
{
public function init()
{
$this->loadExtension(new Extension\Controller\EditCliente());
$this->loadExtension(new Extension\Controller\EditPresupuestoCliente());
$this->loadExtension(new Extension\Controller\EditPedidoCliente());
$this->loadExtension(new Extension\Controller\EditAlbaranCliente());
$this->loadExtension(new Extension\Controller\EditFacturaCliente());
$this->loadExtension(new Extension\Controller\ListPresupuestoCliente());
$this->loadExtension(new Extension\Controller\ListPedidoCliente());
$this->loadExtension(new Extension\Controller\ListAlbaranCliente());
$this->loadExtension(new Extension\Controller\ListFacturaCliente());
$this->loadExtension(new Extension\Controller\EditProveedor());
$this->loadExtension(new Extension\Controller\EditPresupuestoProveedor());
$this->loadExtension(new Extension\Controller\EditPedidoProveedor());
$this->loadExtension(new Extension\Controller\EditAlbaranProveedor());
$this->loadExtension(new Extension\Controller\EditFacturaProveedor());
$this->loadExtension(new Extension\Controller\ListPresupuestoProveedor());
$this->loadExtension(new Extension\Controller\ListPedidoProveedor());
$this->loadExtension(new Extension\Controller\ListAlbaranProveedor());
$this->loadExtension(new Extension\Controller\ListFacturaProveedor());
$this->loadExtension(new Extension\Lib\BusinessDocumentGenerator());
if (Plugins::isEnabled('Proyectos')) {
$this->loadExtension(new Extension\Controller\EditProyecto());
}
// export manager
ExportManager::addOptionModel('PDFanticiposExport', 'PDF', 'Anticipo');
ExportManager::addOptionModel('MAILanticiposExport', 'MAIL', 'Anticipo');
ExportManager::addOptionModel('PDFanticiposExport', 'PDF', 'AnticipoP');
ExportManager::addOptionModel('MAILanticiposExport', 'MAIL', 'AnticipoP');
}
public function update()
{
$Tables = array("anticiposp", "anticipos");
foreach ($Tables as $Table) {
$this->updateUserToNick($Table);
}
$this->setupSettings();
$this->updateEmailNotifications();
}
private function setupSettings()
{
if (empty(Tools::settings('anticipos', 'pdAnticipos'))) {
Tools::settingsSet('anticipos', 'pdAnticipos', false);
}
if (empty(Tools::settings('anticipos', 'level'))) {
Tools::settingsSet('anticipos', 'level', 20);
}
Tools::settingsSave();
}
private function updateEmailNotifications() : void
{
$notificationModel = new EmailNotification();
$keys = [
'sendmail-Anticipo'
];
foreach ($keys as $key) {
if ($notificationModel->loadFromCode($key)) {
continue;
}
$notificationModel->name = $key;
$notificationModel->body = Tools::lang()->trans($key . '-body');
$notificationModel->subject = Tools::lang()->trans($key);
$notificationModel->enabled = true;
$notificationModel->save();
}
}
protected function updateUserToNick($Table)
{
$dataBase = new DataBase();
// Comprobamos si se ha encontrado la columna "user" en la tabla
$sql = "SELECT column_name
FROM information_schema.columns
WHERE table_name = '" . $Table . "'
AND column_name = 'user';";
$resultado = $dataBase->select($sql);
/* Cuando NO está vacío el Array $resultado, realiza el proceso de
cambiar el nombre de la columna USER por NICK */
if (!empty($resultado) && isset($resultado[0]['column_name'])) {
Tools::Log()->info('La columna USER existe en la tabla ' . $Table . '. Procediendo a renombrar.');
// Cambiamos el nombre de la columna USER por el de NICK
$sql = FS_DB_TYPE == 'postgresql'
? "ALTER TABLE \" . $Table . \" RENAME COLUMN \"user\" TO \"nick\";"
: "ALTER TABLE `" . $Table . "` CHANGE `user` `nick` VARCHAR(50);";
if (false === ($dataBase->exec($sql))) {
Tools::Log()->warning('Error al cambiar la columna USER por NICK en la tabla ' . $Table);
} else {
Tools::Log()->info('Se ha cambiado el nombre de la columna USER por el de NICK con éxito en la tabla ' . $Table);
}
} else {
Tools::Log()->info('No existe la columna USER en la tabla ' . $Table . '!!!, contacte con el desarrollador del plugin');
}
}
}