forked from NeoRazorX/facturascripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathListProveedor.php
More file actions
155 lines (135 loc) · 6.66 KB
/
ListProveedor.php
File metadata and controls
155 lines (135 loc) · 6.66 KB
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
<?php
/**
* This file is part of FacturaScripts
* Copyright (C) 2017-2023 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\DataSrc\FormasPago;
use FacturaScripts\Core\DataSrc\Paises;
use FacturaScripts\Core\DataSrc\Retenciones;
use FacturaScripts\Core\DataSrc\Series;
use FacturaScripts\Core\Lib\ExtendedController\ListController;
use FacturaScripts\Core\Tools;
use FacturaScripts\Core\Where;
use FacturaScripts\Dinamic\Lib\InvoiceOperation;
use FacturaScripts\Dinamic\Lib\TaxExceptions;
/**
* Controller to list the items in the Proveedor model
*
* @author Carlos García Gómez <carlos@facturascripts.com>
* @author Cristo M. Estévez Hernández <cristom.estevez@gmail.com>
*/
class ListProveedor extends ListController
{
public function getPageData(): array
{
$data = parent::getPageData();
$data['menu'] = 'purchases';
$data['title'] = 'suppliers';
$data['icon'] = 'fa-solid fa-users';
return $data;
}
/**
* Load views
*/
protected function createViews()
{
$this->createViewSuppliers();
$this->createViewAddresses();
}
protected function createViewAddresses(string $viewName = 'ListContacto'): void
{
$this->addView($viewName, 'Contacto', 'addresses-and-contacts', 'fa-solid fa-address-book')
->addOrderBy(['descripcion'], 'description')
->addOrderBy(['direccion'], 'address')
->addOrderBy(['nombre'], 'name')
->addOrderBy(['fechaalta'], 'creation-date', 2)
->addSearchFields([
'apartado', 'apellidos', 'codpostal', 'descripcion', 'direccion', 'email', 'empresa',
'nombre', 'observaciones', 'telefono1', 'telefono2'
]);
// filtros
$values = [
[
'label' => Tools::trans('suppliers'),
'where' => [new DataBaseWhere('codproveedor', null, 'IS NOT')]
],
[
'label' => Tools::trans('all'),
'where' => []
]
];
$this->addFilterSelectWhere($viewName, 'type', $values);
$cargoValues = $this->codeModel->all('contactos', 'cargo', 'cargo');
$this->addFilterSelect($viewName, 'cargo', 'position', 'cargo', $cargoValues);
$this->addFilterSelect($viewName, 'codpais', 'country', 'codpais', Paises::codeModel());
$provinces = $this->codeModel->all('contactos', 'provincia', 'provincia');
$this->addFilterSelect($viewName, 'provincia', 'province', 'provincia', $provinces);
$cities = $this->codeModel->all('contactos', 'ciudad', 'ciudad');
$this->addFilterSelect($viewName, 'ciudad', 'city', 'ciudad', $cities);
$this->addFilterAutocomplete($viewName, 'codpostal', 'zip-code', 'codpostal', 'contactos', 'codpostal');
$this->addFilterCheckbox($viewName, 'verificado', 'verified', 'verificado');
// desactivamos el mega-search
$this->setSettings($viewName, 'megasearch', false);
}
protected function createViewSuppliers(string $viewName = 'ListProveedor'): void
{
$this->addView($viewName, 'Proveedor', 'suppliers', 'fa-solid fa-users')
->addOrderBy(['codproveedor'], 'code')
->addOrderBy(['cifnif'], 'fiscal-number')
->addOrderBy(['LOWER(nombre)'], 'name', 1)
->addOrderBy(['fechaalta'], 'creation-date')
->addSearchFields([
'cifnif', 'codproveedor', 'codsubcuenta', 'email', 'nombre', 'observaciones', 'razonsocial',
'telefono1', 'telefono2'
]);
// filtros
$this->addFilterSelectWhere($viewName, 'status', [
['label' => Tools::trans('only-active'), 'where' => [new DataBaseWhere('debaja', false)]],
['label' => Tools::trans('only-suspended'), 'where' => [new DataBaseWhere('debaja', true)]],
['label' => Tools::trans('all'), 'where' => []]
]);
$this->addFilterSelectWhere($viewName, 'type', [
['label' => Tools::trans('all'), 'where' => []],
['label' => Tools::trans('is-creditor'), 'where' => [new DataBaseWhere('acreedor', true)]],
['label' => Tools::trans('supplier'), 'where' => [new DataBaseWhere('acreedor', false)]],
]);
$fiscalIds = $this->codeModel->all('proveedores', 'tipoidfiscal', 'tipoidfiscal');
$this->addFilterSelect($viewName, 'tipoidfiscal', 'fiscal-id', 'tipoidfiscal', $fiscalIds);
$this->addFilterSelect($viewName, 'codserie', 'series', 'codserie', Series::codeModel());
$this->addFilterSelect($viewName, 'codretencion', 'retentions', 'codretencion', Retenciones::codeModel());
$this->addFilterSelect($viewName, 'codpago', 'payment-methods', 'codpago', FormasPago::codeModel());
$vatRegimes = $this->codeModel->all('proveedores', 'regimeniva', 'regimeniva', true, [Where::isNotNull('regimeniva')]);
$this->addFilterSelect($viewName, 'regimeniva', 'vat-regime', 'regimeniva', $vatRegimes);
$operations = $this->codeModel->all('proveedores', 'operacion', 'operacion', true, [Where::isNotNull('operacion')]);
foreach ($operations as &$item) {
$operationKey = InvoiceOperation::get($item->code);
if (null !== $operationKey) {
$item->description = Tools::trans($operationKey);
}
}
$this->addFilterSelect($viewName, 'operation', 'operation', 'operacion', $operations);
$vatExceptions = $this->codeModel->all('proveedores', 'excepcioniva', 'excepcioniva', true, [Where::isNotNull('excepcioniva')]);
foreach ($vatExceptions as &$item) {
$operationKey = InvoiceOperation::get($item->code);
if (null !== $operationKey) {
$item->description = Tools::trans($operationKey);
}
}
$this->addFilterSelect($viewName, 'vat-exception', 'vat-exception', 'excepcioniva', $vatExceptions);
}
}