-
Notifications
You must be signed in to change notification settings - Fork 6
/
Init.php
156 lines (141 loc) · 5.98 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
149
150
151
152
153
154
155
156
<?php
/**
* This file is part of Proyectos plugin for FacturaScripts
* Copyright (C) 2020-2024 Carlos Garcia Gomez <carlos@facturascripts.com>
*
* 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\Proyectos;
use FacturaScripts\Core\Base\AjaxForms\PurchasesHeaderHTML;
use FacturaScripts\Core\Base\AjaxForms\SalesHeaderHTML;
use FacturaScripts\Core\Base\DataBase;
use FacturaScripts\Core\Base\DataBase\DataBaseWhere;
use FacturaScripts\Core\Model\Role;
use FacturaScripts\Core\Model\RoleAccess;
use FacturaScripts\Core\Template\InitClass;
use FacturaScripts\Core\Tools;
use FacturaScripts\Dinamic\Model\AlbaranCliente;
use FacturaScripts\Dinamic\Model\AlbaranProveedor;
use FacturaScripts\Dinamic\Model\FacturaCliente;
use FacturaScripts\Dinamic\Model\FacturaProveedor;
use FacturaScripts\Dinamic\Model\PedidoCliente;
use FacturaScripts\Dinamic\Model\PedidoProveedor;
use FacturaScripts\Dinamic\Model\PresupuestoCliente;
use FacturaScripts\Dinamic\Model\PresupuestoProveedor;
/**
* Description of Init
*
* @author Carlos Garcia Gomez <carlos@facturascripts.com>
*/
final class Init extends InitClass
{
const ROLE_NAME = 'Proyectos';
public function init(): void
{
$this->loadExtension(new Extension\Controller\DocumentStitcher());
$this->loadExtension(new Extension\Controller\EditAlbaranCliente());
$this->loadExtension(new Extension\Controller\EditAlbaranProveedor());
$this->loadExtension(new Extension\Controller\EditCliente());
$this->loadExtension(new Extension\Controller\EditFacturaCliente());
$this->loadExtension(new Extension\Controller\EditFacturaProveedor());
$this->loadExtension(new Extension\Controller\EditPedidoCliente());
$this->loadExtension(new Extension\Controller\EditPedidoProveedor());
$this->loadExtension(new Extension\Controller\EditPresupuestoCliente());
$this->loadExtension(new Extension\Controller\EditPresupuestoProveedor());
$this->loadExtension(new Extension\Controller\EditProducto());
$this->loadExtension(new Extension\Controller\ListAlbaranCliente());
$this->loadExtension(new Extension\Controller\ListAlbaranProveedor());
$this->loadExtension(new Extension\Controller\ListFacturaCliente());
$this->loadExtension(new Extension\Controller\ListFacturaProveedor());
$this->loadExtension(new Extension\Controller\ListPedidoCliente());
$this->loadExtension(new Extension\Controller\ListPedidoProveedor());
$this->loadExtension(new Extension\Controller\ListPresupuestoCliente());
$this->loadExtension(new Extension\Controller\ListPresupuestoProveedor());
$this->loadExtension(new Extension\Model\Base\BusinessDocument());
$this->loadExtension(new Extension\Model\Stock());
PurchasesHeaderHTML::addMod(new Mod\PurchasesHeaderHTMLMod());
SalesHeaderHTML::addMod(new Mod\SalesHeaderHTMLMod());
if (class_exists('FacturaScripts\\Dinamic\\Controller\\Randomizer')) {
$this->loadExtension(new Extension\Controller\Randomizer());
}
}
public function uninstall(): void
{
}
public function update(): void
{
// init models
new Model\UserProyecto();
new AlbaranCliente();
new AlbaranProveedor();
new FacturaCliente();
new FacturaProveedor();
new PedidoCliente();
new PedidoProveedor();
new PresupuestoCliente();
new PresupuestoProveedor();
$this->setupSettings();
$this->createRoleForPlugin();
}
private function createRoleForPlugin(): void
{
$dataBase = new DataBase();
$dataBase->beginTransaction();
// creates the role if not exists
$role = new Role();
if (false === $role->loadFromCode(self::ROLE_NAME)) {
$role->codrole = $role->descripcion = self::ROLE_NAME;
if (false === $role->save()) {
// exit and rollback on fail
$dataBase->rollback();
return;
}
}
// check the role permissions
$controllerNames = [
'AdminProyectos', 'EditNotaProyecto', 'EditProyecto', 'EditTareaProyecto', 'ListProyecto',
'ListTareaProyecto'
];
foreach ($controllerNames as $controllerName) {
$roleAccess = new RoleAccess();
$where = [
new DataBaseWhere('codrole', self::ROLE_NAME),
new DataBaseWhere('pagename', $controllerName)
];
if ($roleAccess->loadFromCode('', $where)) {
// permission exists? the skip
continue;
}
// creates the permission if not exists
$roleAccess->allowdelete = true;
$roleAccess->allowupdate = true;
$roleAccess->codrole = self::ROLE_NAME;
$roleAccess->pagename = $controllerName;
$roleAccess->onlyownerdata = false;
if (false === $roleAccess->save()) {
// exit and rollback on fail
$dataBase->rollback();
return;
}
}
// without problems = Commit
$dataBase->commit();
}
private function setupSettings(): void
{
Tools::settings('proyectos', 'patron', 'PR-{ANYO}-{NUM}');
Tools::settings('proyectos', 'longnumero', 6);
Tools::settingsSave();
}
}