Passed
Push — master ( 1582ee...f22301 )
by Joe Nilson
01:53
created

ListNCFRango::inputExists()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 1
nc 2
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Copyright (C) 2019 joenilson.
5
 *
6
 * This library is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU Lesser General Public
8
 * License as published by the Free Software Foundation; either
9
 * version 3 of the License, or (at your option) any later version.
10
 *
11
 * This library 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 GNU
14
 * Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public
17
 * License along with this library; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA 02110-1301  USA
20
 */
21
22
namespace FacturaScripts\Plugins\fsRepublicaDominicana\Controller;
23
24
use FacturaScripts\Core\Base\DataBase\DataBaseWhere;
0 ignored issues
show
Bug introduced by
The type FacturaScripts\Core\Base\DataBase\DataBaseWhere was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
25
use FacturaScripts\Core\Lib\ExtendedController\ListController;
0 ignored issues
show
Bug introduced by
The type FacturaScripts\Core\Lib\...ntroller\ListController was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
26
use FacturaScripts\Plugins\fsRepublicaDominicana\Model\NCFRango;
27
use FacturaScripts\Plugins\fsRepublicaDominicana\Model\NCFTipoMovimiento;
28
29
/**
30
 * Description of ListNCFRango
31
 *
32
 * @author joenilson
33
 */
34
class ListNCFRango extends ListController
35
{
36
    public function getPageData(): array
37
    {
38
        $pageData = parent::getPageData();
39
        $pageData['menu'] = 'accounting';
40
        $pageData['submenu'] = 'Republica Dominicana';
41
        $pageData['title'] = 'ncf-master';
42
        $pageData['icon'] = 'fas fa-list';
43
        
44
        return $pageData;
45
    }
46
    
47
    protected function createViews()
48
    {
49
        $this->addView('ListNCFRango', 'NCFRango');
50
        $this->addSearchFields('ListNCFRango', ['tipocomprobante']);
51
        $this->addOrderBy('ListNCFRango', ['tipocomprobante','correlativo'], 'tipocomprobante');
52
        
53
        $this->setSettings('ListNCFRango', 'modalInsert', 'ncf-rango-insert');
54
        $this->setCustomWidgetValues('ListNCFRango');
55
    }
56
57
    public function setCustomWidgetValues($viewName)
58
    {
59
        $customValues = [];
60
        $customValues[] = ['value'=>'', 'title'=>'-----------'];
61
        foreach (\range('A', 'Z') as $i) {
62
            $customValues[] = ['value'=>$i, 'title'=>$i];
63
        }
64
        $columnToModify = $this->views[$viewName]->columnModalForName('serie_nueva');
65
        if ($columnToModify) {
66
            $columnToModify->widget->setValuesFromArray($customValues);
67
        }
68
    }
69
70
    /**
71
     * @throws \JsonException
72
     */
73
    public function execPreviousAction($action)
74
    {
75
        switch ($action) {
76
            case 'ncf-rango-insert':
77
                $valueIdEmpresa = $this->request->request->get('idempresa');
78
                $valueSerie = $this->request->request->get('serie_nueva');
79
                $valueUsuarioCreacion = $this->request->request->get('usuariocreacion');
80
                $valueFechaCreacion = $this->request->request->get('fechacreacion');
81
                $data = $this->request->request->all();
82
                $data['serie']=($this->inputExists($valueSerie))?$valueSerie:$data['serie'];
83
                $data['idempresa']=($this->inputExists($valueIdEmpresa))?$valueIdEmpresa:$this->empresa->idempresa;
84
                $data['usuariomodificacion']=($this->inputExists($valueFechaCreacion))?$this->user->nick:null;
85
                $data['usuariocreacion']=($this->inputExists($valueUsuarioCreacion))
86
                                        ?$valueUsuarioCreacion
87
                                        :$this->user->nick;
88
                $data['fechacreacion']=($this->inputExists($valueFechaCreacion))
89
                                        ?$valueFechaCreacion
90
                                        :\date('Y-m-d');
91
                $rangoNuevo = new NCFRango();
92
                $rangoNuevo->loadFromData($data);
93
                $rangoNuevo->save();
94
                $this->toolBox()->log()->notice('Rango nuevo guardado exitosamente');
95
                break;
96
            case 'busca_correlativo':
97
                $this->setTemplate(false);
98
                $tipocomprobante = new NCFRango();
99
                $where = [
100
                    new DatabaseWhere('tipocomprobante', $_REQUEST['tipocomprobante']),
101
                    new DatabaseWhere('idempresa', $this->empresa->idempresa),
102
                    new DatabaseWhere('estado', true)
103
                ];
104
                $comprobante = $tipocomprobante->all($where);
105
                if ($comprobante) {
106
                    //header('Content-Type: application/json');
107
                    echo json_encode(['existe' => $comprobante], JSON_THROW_ON_ERROR);
108
                } else {
109
                    echo json_encode(['existe' => false], JSON_THROW_ON_ERROR);
110
                }
111
                break;
112
        }
113
        return parent::execPreviousAction($action);
114
    }
115
116
    private function inputExists($input)
117
    {
118
        return isset($input) and $input !== '';
119
    }
120
}
121