Passed
Push — master ( d9f4f6...a1d016 )
by Carlos
01:10 queued 15s
created

ListSecuenciaDocumento::createCompanyFilter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 1
1
<?php
2
/**
3
 * This file is part of FacturaScripts
4
 * Copyright (C) 2019 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
namespace FacturaScripts\Core\Controller;
20
21
use FacturaScripts\Core\Lib\ExtendedController\ListController;
22
23
/**
24
 * Controller to list the items in the FormatoDocumento model
25
 *
26
 * @author Cristo M. Estévez Hernández  <[email protected]>
27
 * @author Carlos García Gómez          <[email protected]>
28
 */
29
class ListSecuenciaDocumento extends ListController
30
{
31
32
    /**
33
     * Returns basic page attributes
34
     *
35
     * @return array
36
     */
37
    public function getPageData()
38
    {
39
        $data = parent::getPageData();
40
        $data['menu'] = 'admin';
41
        $data['title'] = 'document-configuration';
42
        $data['icon'] = 'fas fa-copy';
43
        return $data;
44
    }
45
46
    /**
47
     * 
48
     * @param string $viewName
49
     */
50
    protected function createCompanyFilter(string $viewName)
51
    {
52
        $companies = $this->codeModel->all('empresas', 'idempresa', 'nombrecorto');
53
        $this->addFilterSelect($viewName, 'idempresa', 'company', 'idempresa', $companies);
54
    }
55
56
    /**
57
     * 
58
     * @param string $viewName
59
     */
60
    protected function createDocTypeFilter(string $viewName)
61
    {
62
        $types = $this->codeModel->all('estados_documentos', 'tipodoc', 'tipodoc');
63
64
        /// custom translation
65
        foreach ($types as $key => $value) {
66
            if (!empty($value->code)) {
67
                $types[$key]->description = $this->toolBox()->i18n()->trans($value->code);
68
            }
69
        }
70
71
        $this->addFilterSelect($viewName, 'tipodoc', 'doc-type', 'tipodoc', $types);
72
    }
73
74
    /**
75
     * Load views
76
     */
77
    protected function createViews()
78
    {
79
        $this->createViewSequences();
80
        $this->createViewStates();
81
        $this->createViewFormats();
82
    }
83
84
    /**
85
     * 
86
     * @param string $viewName
87
     */
88
    protected function createViewFormats(string $viewName = 'ListFormatoDocumento')
89
    {
90
        $this->addView($viewName, 'FormatoDocumento', 'printing-formats', 'fas fa-print');
91
        $this->addSearchFields($viewName, ['nombre', 'titulo', 'texto']);
92
        $this->addOrderBy($viewName, ['nombre'], 'name');
93
        $this->addOrderBy($viewName, ['titulo'], 'title');
94
95
        /// Filters
96
        $this->createDocTypeFilter($viewName);
97
        $this->createCompanyFilter($viewName);
98
99
        $series = $this->codeModel->all('series', 'codserie', 'descripcion');
100
        $this->addFilterSelect($viewName, 'codserie', 'serie', 'codserie', $series);
101
    }
102
103
    /**
104
     * 
105
     * @param string $viewName
106
     */
107
    protected function createViewSequences(string $viewName = 'ListSecuenciaDocumento')
108
    {
109
        $this->addView($viewName, 'SecuenciaDocumento', 'sequences', 'fas fa-code');
110
        $this->addSearchFields($viewName, ['patron', 'tipodoc']);
111
        $this->addOrderBy($viewName, ['codejercicio'], 'exercise');
112
        $this->addOrderBy($viewName, ['codserie'], 'serie');
113
        $this->addOrderBy($viewName, ['numero'], 'number');
114
115
        /// Filters
116
        $this->createDocTypeFilter($viewName);
117
        $this->createCompanyFilter($viewName);
118
119
        $exercises = $this->codeModel->all('ejercicios', 'codejercicio', 'nombre');
120
        $this->addFilterSelect($viewName, 'codejercicio', 'exercise', 'codejercicio', $exercises);
121
122
        $series = $this->codeModel->all('series', 'codserie', 'descripcion');
123
        $this->addFilterSelect($viewName, 'codserie', 'serie', 'codserie', $series);
124
    }
125
126
    /**
127
     * 
128
     * @param string $viewName
129
     */
130
    protected function createViewStates(string $viewName = 'ListEstadoDocumento')
131
    {
132
        $this->addView($viewName, 'EstadoDocumento', 'states', 'fas fa-tags');
133
        $this->addSearchFields($viewName, ['nombre']);
134
        $this->addOrderBy($viewName, ['idestado'], 'id');
135
        $this->addOrderBy($viewName, ['nombre'], 'name');
136
137
        /// Filters
138
        $this->createDocTypeFilter($viewName);
139
140
        $this->addFilterSelect($viewName, 'actualizastock', 'update-stock', 'actualizastock', $this->getActualizastockValues());
141
        $this->addFilterCheckbox($viewName, 'predeterminado', 'default', 'predeterminado');
142
        $this->addFilterCheckbox($viewName, 'editable', 'editable', 'editable');
143
    }
144
145
    /**
146
     * 
147
     * @return array
148
     */
149
    protected function getActualizastockValues()
150
    {
151
        return [
152
            ['code' => null, 'description' => '------'],
153
            ['code' => -2, 'description' => $this->toolBox()->i18n()->trans('book')],
154
            ['code' => -1, 'description' => $this->toolBox()->i18n()->trans('subtract')],
155
            ['code' => 0, 'description' => $this->toolBox()->i18n()->trans('do-nothing')],
156
            ['code' => 1, 'description' => $this->toolBox()->i18n()->trans('add')],
157
            ['code' => 2, 'description' => $this->toolBox()->i18n()->trans('foresee')],
158
        ];
159
    }
160
}
161