Passed
Push — master ( a90170...48fa57 )
by Joe Nilson
03:30
created

EditCliente::execPreviousAction()   A

Complexity

Conditions 4
Paths 1

Size

Total Lines 28
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 24
nc 1
nop 0
dl 0
loc 28
rs 9.536
c 0
b 0
f 0
1
<?php
2
/**
3
 * Copyright (C) 2020 Joe Nilson <joenilson at gmail dot com>
4
 * 
5
 * fsRepublicaDominicana is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU Lesser General Public License as published by
7
 * the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
9
 * 
10
 * fsRepublicaDominicana 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
 * 
15
 * You should have received a copy of the GNU Lesser General Public License
16
 * along with fsRepublicaDominicana. If not, see <http://www.gnu.org/licenses/>.
17
 */
18
19
namespace FacturaScripts\Plugins\fsRepublicaDominicana\Extension\Controller;
20
21
use Closure;
22
use FacturaScripts\Dinamic\Lib\AssetManager;
0 ignored issues
show
Bug introduced by
The type FacturaScripts\Dinamic\Lib\AssetManager 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\Dinamic\Model\NCFTipo;
0 ignored issues
show
Bug introduced by
The type FacturaScripts\Dinamic\Model\NCFTipo 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\Dinamic\Model\NCFTipoPago;
0 ignored issues
show
Bug introduced by
The type FacturaScripts\Dinamic\Model\NCFTipoPago 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\Plugins\fsRepublicaDominicana\Lib\WebserviceDgii;
26
use FacturaScripts\Plugins\fsRepublicaDominicana\Model\NCFTipoMovimiento;
27
28
class EditCliente
29
{
30
    public function createViews(): Closure
31
    {
32
        return function () {
33
            AssetManager::add('js', \FS_ROUTE . '/Plugins/fsRepublicaDominicana/Assets/JS/CommonModals.js');
0 ignored issues
show
Bug introduced by
The constant FS_ROUTE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
34
            AssetManager::add('js', \FS_ROUTE . '/Plugins/fsRepublicaDominicana/Assets/JS/CommonDomFunctions.js');
35
            AssetManager::add('js', \FS_ROUTE . '/Plugins/fsRepublicaDominicana/Assets/JS/BusquedaRNCDGII.js');
36
            $ncfTipo = new NCFTipo();
37
            $ncfTipos = $ncfTipo->allFor('ventas', 'suma');
38
            $customValues = [];
39
            $customValues[] = ['value'=>'', 'title'=>'-----------'];
40
            foreach ($ncfTipos as $tipo) {
41
                $customValues[] = ['value'=>$tipo->tipocomprobante, 'title'=>$tipo->descripcion];
42
            }
43
            $columnToModify = $this->views['EditCliente']->columnForName('tipocomprobante');
0 ignored issues
show
Bug Best Practice introduced by
The property views does not exist on FacturaScripts\Plugins\f...\Controller\EditCliente. Did you maybe forget to declare it?
Loading history...
44
            if ($columnToModify) {
45
                $columnToModify->widget->setValuesFromArray($customValues);
46
            }
47
48
            $ncfTipoPago = new NCFTipoPago();
49
            $ncfTiposPago = $ncfTipoPago->findAllByTipopago('01');
50
            $customValuesNTP = [];
51
            $customValuesNTP[] = ['value'=>'', 'title'=>'-----------'];
52
            foreach ($ncfTiposPago as $tipopago) {
53
                $customValuesNTP[] = ['value'=>$tipopago->codigo, 'title'=>$tipopago->descripcion];
54
            }
55
            $columnToModifyNTP = $this->views['EditCliente']->columnForName('ncf-payment-types');
56
            if ($columnToModifyNTP) {
57
                $columnToModifyNTP->widget->setValuesFromArray($customValuesNTP);
58
            }
59
        };
60
    }
61
62
    public function execPreviousAction()
63
    {
64
        return function ($action) {
65
            switch ($action) {
66
                case 'busca_rnc':
67
                    $this->setTemplate(false);
0 ignored issues
show
Bug introduced by
The method setTemplate() does not exist on FacturaScripts\Plugins\f...\Controller\EditCliente. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

67
                    $this->/** @scrutinizer ignore-call */ 
68
                           setTemplate(false);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
68
                    $consulta = new WebserviceDgii();
69
                    $rncNotFound = self::toolBox()->i18n()->trans('rnc-not-found');
0 ignored issues
show
Bug introduced by
The method toolBox() does not exist on FacturaScripts\Plugins\f...\Controller\EditCliente. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

69
                    $rncNotFound = self::/** @scrutinizer ignore-call */ toolBox()->i18n()->trans('rnc-not-found');

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
70
                    $respuesta = $consulta->getExternalAPI($_REQUEST['cifnif']);
71
                    $registros = $respuesta->totalResults;
72
                    if ($registros !== 0) {
73
                        $resultado = $respuesta->entry[0];
74
                        if ($resultado) {
75
                            $arrayResultado = [];
76
                            $arrayResultado["RGE_RUC"] = $resultado->rnc;
77
                            $arrayResultado["RGE_NOMBRE"] = $resultado->nombre;
78
                            $arrayResultado["NOMBRE_COMERCIAL"] = $resultado->razonsocial;
79
                            $arrayResultado["ESTATUS"] = $resultado->estado;
80
                            echo json_encode($arrayResultado);
81
                        } else {
82
                            echo '{"RGE_ERROR": "true", "message": "'.$rncNotFound.'"}';
83
                        }
84
                    } else {
85
                        echo '{"RGE_ERROR": "true", "message": "'.$rncNotFound.'"}';
86
                    }
87
                    break;
88
                default:
89
                    break;
90
            }
91
        };
92
    }
93
}
94