1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of FacturaScripts |
4
|
|
|
* Copyright (C) 2017-2023 Carlos Garcia Gomez <[email protected]> |
5
|
|
|
* |
6
|
|
|
* This program is free software: you can redistribute it and/or modify |
7
|
|
|
* it under the terms of the GNU Lesser General Public License as |
8
|
|
|
* published by the Free Software Foundation, either version 3 of the |
9
|
|
|
* License, or (at your option) any later version. |
10
|
|
|
* |
11
|
|
|
* This program is distributed in the hope that it will be useful, |
12
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14
|
|
|
* GNU Lesser General Public License for more details. |
15
|
|
|
* |
16
|
|
|
* You should have received a copy of the GNU Lesser General Public License |
17
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
namespace FacturaScripts\Core\Controller; |
21
|
|
|
|
22
|
|
|
use FacturaScripts\Core\Base\DataBase\DataBaseWhere; |
23
|
|
|
use FacturaScripts\Core\Lib\ExtendedController\BaseView; |
24
|
|
|
use FacturaScripts\Core\Lib\ExtendedController\EditController; |
25
|
|
|
use FacturaScripts\Core\Tools; |
26
|
|
|
use FacturaScripts\Dinamic\Lib\RegimenIVA; |
27
|
|
|
use FacturaScripts\Dinamic\Model\Empresa; |
28
|
|
|
use FacturaScripts\Dinamic\Model\SettingsModel; |
|
|
|
|
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Controller to edit a single item from the Empresa model |
32
|
|
|
* |
33
|
|
|
* @author Carlos García Gómez <[email protected]> |
34
|
|
|
* @author Jose Antonio Cuello Principal <[email protected]> |
35
|
|
|
* @author Daniel Fernández Giménez <[email protected]> |
36
|
|
|
*/ |
37
|
|
|
class EditEmpresa extends EditController |
38
|
|
|
{ |
39
|
|
|
public function getModelClassName(): string |
40
|
|
|
{ |
41
|
|
|
return 'Empresa'; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function getPageData(): array |
45
|
|
|
{ |
46
|
|
|
$data = parent::getPageData(); |
47
|
|
|
$data['menu'] = 'admin'; |
48
|
|
|
$data['title'] = 'company'; |
49
|
|
|
$data['icon'] = 'fas fa-building'; |
50
|
|
|
return $data; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
protected function checkViesAction(): bool |
54
|
|
|
{ |
55
|
|
|
$model = $this->getModel(); |
56
|
|
|
if (false === $model->loadFromCode($this->request->get('code'))) { |
57
|
|
|
return true; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
if ($model->checkVies()) { |
|
|
|
|
61
|
|
|
Tools::log()->notice('vies-check-success', ['%vat-number%' => $model->cifnif]); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
return true; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
protected function createViews() |
68
|
|
|
{ |
69
|
|
|
parent::createViews(); |
70
|
|
|
$this->createViewWarehouse(); |
71
|
|
|
$this->createViewBankAccounts(); |
72
|
|
|
$this->createViewPaymentMethods(); |
73
|
|
|
$this->createViewExercises(); |
74
|
|
|
$this->createViewSettings(); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
protected function createViewBankAccounts(string $viewName = 'ListCuentaBanco'): void |
78
|
|
|
{ |
79
|
|
|
$this->addListView($viewName, 'CuentaBanco', 'bank-accounts', 'fas fa-piggy-bank') |
80
|
|
|
->disableColumn('company'); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
protected function createViewExercises(string $viewName = 'ListEjercicio'): void |
84
|
|
|
{ |
85
|
|
|
$this->addListView($viewName, 'Ejercicio', 'exercises', 'fas fa-calendar-alt') |
86
|
|
|
->disableColumn('company'); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
protected function createViewPaymentMethods(string $viewName = 'ListFormaPago'): void |
90
|
|
|
{ |
91
|
|
|
$this->addListView($viewName, 'FormaPago', 'payment-method', 'fas fa-credit-card') |
92
|
|
|
->disableColumn('company'); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
protected function createViewWarehouse(string $viewName = 'EditAlmacen'): void |
96
|
|
|
{ |
97
|
|
|
$this->addListView($viewName, 'Almacen', 'warehouses', 'fas fa-warehouse') |
98
|
|
|
->disableColumn('company'); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
protected function createViewSettings(string $viewName = 'EditSettingsModel'): void |
102
|
|
|
{ |
103
|
|
|
$this->addEditView($viewName, 'SettingsModel', 'settings', 'fas fa-wrench'); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
protected function execPreviousAction($action): bool |
107
|
|
|
{ |
108
|
|
|
if ($this->active === 'EditSettingsModel' && in_array($action, ['edit', 'insert'])){ |
109
|
|
|
|
110
|
|
|
/** @var Empresa $empresa */ |
111
|
|
|
$empresa = $this->getModel(); |
112
|
|
|
$empresa->loadFromCode($this->request->get('code')); |
113
|
|
|
$this->request->request->set('idempresa', $empresa->primaryColumnValue()); |
114
|
|
|
|
115
|
|
|
/** @var SettingsModel $settingsModel */ |
116
|
|
|
$settingsModel = $this->views[$this->active]->model; |
117
|
|
|
$settingsModel->loadFromCode('', [ |
118
|
|
|
new DataBaseWhere('classnamemodel', get_class($empresa)), |
119
|
|
|
new DataBaseWhere('idmodel', $empresa->primaryColumnValue()), |
120
|
|
|
new DataBaseWhere('idempresa', $empresa->primaryColumnValue()), |
121
|
|
|
]); |
122
|
|
|
|
123
|
|
|
$settingsModel->classnamemodel = get_class($empresa); |
124
|
|
|
$settingsModel->idmodel = $empresa->primaryColumnValue(); |
125
|
|
|
$settingsModel->idempresa = $empresa->primaryColumnValue(); |
126
|
|
|
$settingsModel->settings = json_encode([ |
127
|
|
|
'codalmacen' => empty($this->request->request->get('codalmacen')) ? null : $this->request->request->get('codalmacen'), |
128
|
|
|
'codserie' => empty($this->request->request->get('codserie')) ? null : $this->request->request->get('codserie'), |
129
|
|
|
'coddivisa' => empty($this->request->request->get('coddivisa')) ? null : $this->request->request->get('coddivisa'), |
130
|
|
|
'codpago' => empty($this->request->request->get('codpago')) ? null : $this->request->request->get('codpago'), |
131
|
|
|
]); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
switch ($action) { |
135
|
|
|
case 'check-vies': |
136
|
|
|
return $this->checkViesAction(); |
137
|
|
|
|
138
|
|
|
default: |
139
|
|
|
return parent::execPreviousAction($action); |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Load view data procedure |
145
|
|
|
* |
146
|
|
|
* @param string $viewName |
147
|
|
|
* @param BaseView $view |
148
|
|
|
*/ |
149
|
|
|
protected function loadData($viewName, $view) |
150
|
|
|
{ |
151
|
|
|
$mvn = $this->getMainViewName(); |
152
|
|
|
|
153
|
|
|
switch ($viewName) { |
154
|
|
|
case 'EditAlmacen': |
155
|
|
|
case 'ListCuentaBanco': |
156
|
|
|
case 'ListEjercicio': |
157
|
|
|
case 'ListFormaPago': |
158
|
|
|
$id = $this->getViewModelValue($this->getMainViewName(), 'idempresa'); |
159
|
|
|
$where = [new DataBaseWhere('idempresa', $id)]; |
160
|
|
|
$view->loadData('', $where); |
161
|
|
|
break; |
162
|
|
|
case 'EditSettingsModel': |
163
|
|
|
/** @var Empresa $empresa */ |
164
|
|
|
$empresa = $this->getModel(); |
165
|
|
|
$empresa->loadFromCode($this->request->get('code')); |
166
|
|
|
|
167
|
|
|
/** @var SettingsModel $settingsModel */ |
168
|
|
|
$settingsModel = $this->views[$viewName]->model; |
169
|
|
|
$where = [ |
170
|
|
|
new DataBaseWhere('classnamemodel', get_class($empresa)), |
171
|
|
|
new DataBaseWhere('idempresa', $empresa->idempresa), |
172
|
|
|
]; |
173
|
|
|
$settingsModel->loadFromCode('', $where); |
174
|
|
|
|
175
|
|
|
if($settingsModel->exists()){ |
176
|
|
|
// agregamos al modelo las propiedades que hay dentro de settings |
177
|
|
|
// para conservar la clase con todas las propiedades y que detecte si el modelo existe o no. |
178
|
|
|
foreach ($this->views[$viewName]->model->settings as $key => $value) { |
179
|
|
|
$this->views[$viewName]->model->{$key} = $value; |
180
|
|
|
} |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
break; |
184
|
|
|
|
185
|
|
|
case $mvn: |
186
|
|
|
parent::loadData($viewName, $view); |
187
|
|
|
$this->setCustomWidgetValues($view); |
188
|
|
|
if ($view->model->exists() && $view->model->cifnif) { |
189
|
|
|
$this->addButton($viewName, [ |
190
|
|
|
'action' => 'check-vies', |
191
|
|
|
'color' => 'info', |
192
|
|
|
'icon' => 'fas fa-check-double', |
193
|
|
|
'label' => 'check-vies' |
194
|
|
|
]); |
195
|
|
|
} |
196
|
|
|
break; |
197
|
|
|
|
198
|
|
|
default: |
199
|
|
|
parent::loadData($viewName, $view); |
200
|
|
|
break; |
201
|
|
|
} |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
protected function setCustomWidgetValues(BaseView &$view): void |
205
|
|
|
{ |
206
|
|
|
$columnVATType = $view->columnForName('vat-regime'); |
207
|
|
|
if ($columnVATType && $columnVATType->widget->getType() === 'select') { |
208
|
|
|
$columnVATType->widget->setValuesFromArrayKeys(RegimenIVA::all(), true); |
|
|
|
|
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
$columnVATException = $view->columnForName('vat-exception'); |
212
|
|
|
if ($columnVATException && $columnVATException->widget->getType() === 'select') { |
213
|
|
|
$columnVATException->widget->setValuesFromArrayKeys(RegimenIVA::allExceptions(), true, true); |
214
|
|
|
} |
215
|
|
|
} |
216
|
|
|
} |
217
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths