Passed
Push — master ( c9eccd...e32a8b )
by Joe Nilson
03:55
created

ConsultaDGII   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 66
c 2
b 0
f 0
dl 0
loc 90
rs 10
wmc 8

4 Methods

Rating   Name   Duplication   Size   Complexity  
A addUpdateButton() 0 13 1
A execAfterAction() 0 36 5
A getPageData() 0 9 1
A createViews() 0 24 1
1
<?php
2
/*
3
 * Copyright (C) 2022 Joe Nilson <[email protected]>
4
 *
5
 * This program is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU Lesser General Public License as
7
 * published by the Free Software Foundation, either version 3 of the
8
 * License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU Lesser General Public License for more details.
14
 * You should have received a copy of the GNU Lesser General Public License
15
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
 */
17
18
namespace FacturaScripts\Plugins\fsRepublicaDominicana\Controller;
19
20
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...
21
use FacturaScripts\Core\Base\ToolBox;
0 ignored issues
show
Bug introduced by
The type FacturaScripts\Core\Base\ToolBox 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...
22
use FacturaScripts\Core\Base\Translator;
0 ignored issues
show
Bug introduced by
The type FacturaScripts\Core\Base\Translator 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...
23
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...
24
use FacturaScripts\Plugins\fsRepublicaDominicana\Lib\WebserviceDgii;
25
26
class ConsultaDGII extends ListController
27
{
28
    public function getPageData(): array
29
    {
30
        $pageData = parent::getPageData();
31
        $pageData['menu'] = 'accounting';
32
        $pageData['submenu'] = 'Republica Dominicana';
33
        $pageData['title'] = 'ncf-dgii-db';
34
        $pageData['icon'] = 'fas fa-file-archive';
35
36
        return $pageData;
37
    }
38
39
    public function addUpdateButton($viewName)
40
    {
41
        $updateButton = [
42
            'color' => 'warning',
43
            'icon' => 'fas fa-file-archive',
44
            'label' => 'update-dgiidb-data',
45
            'title' => 'update-dgiidb-data',
46
            'type' => 'action',
47
            'action' => 'update-data',
48
            'hint' => 'update-dgiidb-data',
49
            'confirm' => true
50
        ];
51
        $this->addButton($viewName, $updateButton);
52
    }
53
54
    protected function createViews()
55
    {
56
        $this->addView('ConsultaDGII', 'RNCDGIIDB');
57
        $this->addSearchFields('ConsultaDGII', ['rnc', 'nombre', 'razonsocial', 'estado'], 'rnc');
58
        $this->addOrderBy('ConsultaDGII', ['rnc', ], 'rnc');
59
        $this->addOrderBy('ConsultaDGII', ['nombre'], 'nombre');
60
        $this->addOrderBy('ConsultaDGII', ['razonsocial'], 'razonsocial');
61
        $this->addOrderBy('ConsultaDGII', ['estado'], 'estado');
62
        $this->addUpdateButton('ConsultaDGII');
63
64
        $estados = [
65
            ['code' => 'ACTIVO', 'description' => 'Activo'],
66
            ['code' => 'SUSPENDIDO', 'description' => 'Suspendido'],
67
            ['code' => 'DADO DE BAJA', 'description' => 'Dado de Baja'],
68
            ['code' => 'RECHAZADO', 'description' => 'Rechazado'],
69
            ['code' => 'ANULADO', 'description' => 'Anulado'],
70
            ['code' => 'CESE TEMPORAL', 'description' => 'Cese Temporal'],
71
        ];
72
        $this->addFilterSelect('ConsultaDGII', 'estado', 'status', 'estado', $estados);
73
        $this->addFilterPeriod('ConsultaDGII', 'inicioactividad', 'period', 'inicioactividad');
74
75
        $this->setSettings('ConsultaDGII', 'clickable', false);
76
        $this->setSettings('ConsultaDGII', 'btnDelete', false);
77
        $this->setSettings('ConsultaDGII', 'btnNew', false);
78
    }
79
80
    protected function execAfterAction($action)
81
    {
82
        switch ($action) {
83
            case 'update-data':
84
                $this->views['ConsultaDGII']->model->updateFile();
85
                $this->views['ConsultaDGII']->model->clear();
86
                self::toolBox()->cache()->clear();
87
                self::toolBox()->i18nLog()->notice('updated-rnc-data');
88
89
                break;
90
            case 'busca_rnc':
91
                $this->setTemplate(false);
92
                $consulta = new WebserviceDgii();
93
                $rncNotFound = self::toolBox()->i18n()->trans('rnc-not-found');
94
                $respuesta = $consulta->getExternalAPI($_REQUEST['cifnif']);
95
                $registros = $respuesta->totalResults;
96
                if ($registros !== 0) {
97
                    $resultado = $respuesta->entry[0];
98
                    if ($resultado) {
99
                        $arrayResultado = [];
100
                        $arrayResultado["RGE_RUC"] = $resultado->rnc;
101
                        $arrayResultado["RGE_NOMBRE"] = $resultado->nombre;
102
                        $arrayResultado["NOMBRE_COMERCIAL"] = $resultado->razonsocial;
103
                        $arrayResultado["ESTATUS"] = $resultado->estado;
104
                        echo json_encode($arrayResultado);
105
                    } else {
106
                        echo '{"RGE_ERROR": "true", "message": "'.$rncNotFound.'"}';
107
                    }
108
                } else {
109
                    echo '{"RGE_ERROR": "true", "message": "'.$rncNotFound.'"}';
110
                }
111
                break;
112
            default:
113
                break;
114
        }
115
        parent::execPreviousAction($action);
116
    }
117
118
119
}