Passed
Push — master ( 48fa57...539c4e )
by Joe Nilson
01:55
created

EditFacturaProveedor::verifyDocument()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 2
eloc 10
c 1
b 1
f 0
nc 2
nop 0
dl 0
loc 13
rs 9.9332
1
<?php
2
/*
3
 * Copyright (C) 2021 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\Extension\Controller;
19
20
use Closure;
21
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...
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\FacturaProveedor;
0 ignored issues
show
Bug introduced by
The type FacturaScripts\Dinamic\Model\FacturaProveedor 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\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...
25
use FacturaScripts\Dinamic\Model\NCFTipoAnulacion;
0 ignored issues
show
Bug introduced by
The type FacturaScripts\Dinamic\Model\NCFTipoAnulacion 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\Lib\CommonFunctionsDominicanRepublic;
27
use FacturaScripts\Plugins\fsRepublicaDominicana\Lib\WebserviceDgii;
28
29
class EditFacturaProveedor
30
{
31
    public function createViews(): Closure
32
    {
33
        return function () {
34
            parent::createViews();
35
            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...
36
            AssetManager::add('js', \FS_ROUTE . '/Plugins/fsRepublicaDominicana/Assets/JS/CommonDomFunctions.js');
37
        };
38
    }
39
40
    public function execPreviousAction()
41
    {
42
        return function ($action) {
43
            switch ($action) {
44
                case 'busca_tipo':
45
                    $this->setTemplate(false);
0 ignored issues
show
Bug introduced by
The method setTemplate() does not exist on FacturaScripts\Plugins\f...er\EditFacturaProveedor. ( Ignorable by Annotation )

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

45
                    $this->/** @scrutinizer ignore-call */ 
46
                           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...
46
                    CommonFunctionsDominicanRepublic::ncfTipoComprobante($_REQUEST['tipodocumento']);
47
                    break;
48
                case 'busca_movimiento':
49
                    $this->setTemplate(false);
50
                    CommonFunctionsDominicanRepublic::ncfTipoMovimiento($_REQUEST['tipomovimiento']);
51
                    break;
52
                case 'busca_tipoanulacion':
53
                    $this->setTemplate(false);
54
                    CommonFunctionsDominicanRepublic::ncfTipoAnulacion($_REQUEST['tipoanulacion']);
55
                    break;
56
                case 'busca_pago':
57
                    $this->setTemplate(false);
58
                    CommonFunctionsDominicanRepublic::ncfTipoPago($_REQUEST['tipopago']);
59
                    break;
60
                case "verifica_documento":
61
                    $this->setTemplate(false);
62
                    $this->verifyDocument();
63
                    break;
64
                case 'busca_correlativo':
65
                    $this->setTemplate(false);
66
                    CommonFunctionsDominicanRepublic::ncfCorrelativo($_REQUEST['tipocomprobante'], $this->empresa->idempresa);
0 ignored issues
show
Bug Best Practice introduced by
The property empresa does not exist on FacturaScripts\Plugins\f...er\EditFacturaProveedor. Did you maybe forget to declare it?
Loading history...
67
                    break;
68
                case 'busca_rnc':
69
                    $this->setTemplate(false);
70
                    $consulta = new WebserviceDgii();
71
                    $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...er\EditFacturaProveedor. ( Ignorable by Annotation )

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

71
                    $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...
72
                    $respuesta = $consulta->getExternalAPI($_REQUEST['cifnif']);
73
                    $registros = $respuesta->totalResults;
74
                    if ($registros !== 0) {
75
                        $resultado = $respuesta->entry[0];
76
                        if ($resultado) {
77
                            $arrayResultado = [];
78
                            $arrayResultado["RGE_RUC"] = $resultado->rnc;
79
                            $arrayResultado["RGE_NOMBRE"] = $resultado->nombre;
80
                            $arrayResultado["NOMBRE_COMERCIAL"] = $resultado->razonsocial;
81
                            $arrayResultado["ESTATUS"] = $resultado->estado;
82
                            echo json_encode($arrayResultado);
83
                        } else {
84
                            echo '{"RGE_ERROR": "true", "message": "'.$rncNotFound.'"}';
85
                        }
86
                    } else {
87
                        echo '{"RGE_ERROR": "true", "message": "'.$rncNotFound.'"}';
88
                    }
89
                    break;
90
                default:
91
                    break;
92
            }
93
        };
94
    }
95
96
    private function verifyDocument()
97
    {
98
        $facturasProveedores = new FacturaProveedor();
99
        $where = [
100
            new DataBaseWhere('numeroncf', $_REQUEST['ncf']),
101
            new DataBaseWhere('codproveedor', $_REQUEST['proveedor'])
102
        ];
103
        $verificacion = $facturasProveedores->all($where);
104
        if (!$verificacion) {
105
            echo json_encode(['success' => true], JSON_THROW_ON_ERROR);
106
        } else {
107
            $message = "Factura: " . $verificacion[0]->idfactura . " Fecha: " . $verificacion[0]->fecha;
108
            echo json_encode(['error' => true, 'message' => $message], JSON_THROW_ON_ERROR);
109
        }
110
    }
111
112
    public function ncftipo()
113
    {
114
        return function () {
115
            return NCFTipo::allVentas();
116
        };
117
    }
118
119
    public function ncftipoanulacion()
120
    {
121
        return function () {
122
            $tiposAnulacion = new NCFTipoAnulacion();
123
            return $tiposAnulacion->all();
124
        };
125
    }
126
}