-
Notifications
You must be signed in to change notification settings - Fork 246
/
EditSecuenciaDocumento.php
143 lines (127 loc) · 6.19 KB
/
EditSecuenciaDocumento.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
<?php
/**
* This file is part of FacturaScripts
* Copyright (C) 2019-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\Core\Controller;
use FacturaScripts\Core\Base\DataBase\DataBaseWhere;
use FacturaScripts\Core\Lib\BusinessDocumentCode;
use FacturaScripts\Core\Lib\ExtendedController\EditController;
/**
* Controller to edit a single item from the SecuenciaDocumento model.
*
* @author Carlos García Gómez <carlos@facturascripts.com>
* @author Cristo M. Estévez Hernández <cristom.estevez@gmail.com>
*/
class EditSecuenciaDocumento extends EditController
{
public function getModelClassName(): string
{
return 'SecuenciaDocumento';
}
public function getPageData(): array
{
$data = parent::getPageData();
$data['menu'] = 'admin';
$data['title'] = 'document-sequence';
$data['icon'] = 'fas fa-code';
return $data;
}
protected function createViews()
{
parent::createViews();
$this->setTabsPosition('bottom');
// desactivamos la columna de empresa si solo hay una
if ($this->empresa->count() < 2) {
$this->views[$this->getMainViewName()]->disableColumn('company');
}
// desactivamos los botones de opciones e imprimir
$this->setSettings($this->getMainViewName(), 'btnOptions', false);
$this->setSettings($this->getMainViewName(), 'btnPrint', false);
// añadimos las vistas de los documentos
$this->createViewsDocuments('ListFacturaCliente', 'FacturaCliente', 'customer-invoices');
$this->createViewsDocuments('ListFacturaProveedor', 'FacturaProveedor', 'supplier-invoices');
$this->createViewsDocuments('ListAlbaranCliente', 'AlbaranCliente', 'customer-delivery-notes');
$this->createViewsDocuments('ListAlbaranProveedor', 'AlbaranProveedor', 'supplier-delivery-notes');
$this->createViewsDocuments('ListPedidoCliente', 'PedidoCliente', 'customer-orders');
$this->createViewsDocuments('ListPedidoProveedor', 'PedidoProveedor', 'supplier-orders');
$this->createViewsDocuments('ListPresupuestoCliente', 'PresupuestoCliente', 'customer-quotes');
$this->createViewsDocuments('ListPresupuestoProveedor', 'PresupuestoProveedor', 'supplier-quotes');
}
protected function createViewsDocuments(string $viewName, string $model, string $title): void
{
$this->addListView($viewName, $model, $title, 'fas fa-copy')
->addOrderBy(['fecha', $this->tableColToNumber('numero')], 'date', 1)
->addOrderBy([$this->tableColToNumber('numero')], 'number')
->addSearchFields(['cifnif', 'codigo', 'numero', 'observaciones']);
// desactivamos los botones de nuevo y eliminar
$this->setSettings($viewName, 'btnNew', false);
$this->setSettings($viewName, 'btnDelete', false);
}
protected function loadData($viewName, $view)
{
$mvn = $this->getMainViewName();
switch ($viewName) {
case 'ListAlbaranCliente':
case 'ListAlbaranProveedor':
case 'ListFacturaCliente':
case 'ListFacturaProveedor':
case 'ListPedidoCliente':
case 'ListPedidoProveedor':
case 'ListPresupuestoCliente':
case 'ListPresupuestoProveedor':
$where = [
new DataBaseWhere('codserie', $this->getViewModelValue($mvn, 'codserie')),
new DataBaseWhere('idempresa', $this->getViewModelValue($mvn, 'idempresa'))
];
// si tiene ejercicio, solo mostramos los resultados de ese ejercicio
if ($this->views[$mvn]->model->codejercicio) {
$where[] = new DataBaseWhere('codejercicio', $this->views[$mvn]->model->codejercicio);
$view->loadData('', $where);
break;
}
// no tiene ejercicio, mostramos los resultados otros ejercicios que no están en otras secuencias
$other = implode(',', BusinessDocumentCode::getOtherExercises($this->views[$mvn]->model));
if (!empty($other)) {
$where[] = new DataBaseWhere('codejercicio', $other, 'NOT IN');
}
$view->loadData('', $where);
break;
case $mvn:
parent::loadData($viewName, $view);
// desactivamos todas las pestañas de documentos
$this->setSettings('ListAlbaranCliente', 'active', false);
$this->setSettings('ListAlbaranProveedor', 'active', false);
$this->setSettings('ListFacturaCliente', 'active', false);
$this->setSettings('ListFacturaProveedor', 'active', false);
$this->setSettings('ListPedidoCliente', 'active', false);
$this->setSettings('ListPedidoProveedor', 'active', false);
$this->setSettings('ListPresupuestoCliente', 'active', false);
$this->setSettings('ListPresupuestoProveedor', 'active', false);
// en función del tipo de documento, mostramos o no la pestaña de facturas de cliente
if ($view->model->tipodoc) {
$this->setSettings('List' . $view->model->tipodoc, 'active', true);
}
break;
}
}
private function tableColToNumber(string $name): string
{
return strtolower(FS_DB_TYPE) == 'postgresql' ?
'CAST(' . $name . ' as integer)' :
'CAST(' . $name . ' as unsigned)';
}
}