FacturaProveedor::cleanRefundData()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 0
dl 0
loc 10
rs 10
c 0
b 0
f 0
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\Model;
19
20
use Closure;
21
use FacturaScripts\Core\Tools;
22
use FacturaScripts\Dinamic\Model\NCFRango;
0 ignored issues
show
Bug introduced by
The type FacturaScripts\Dinamic\Model\NCFRango 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;
24
use FacturaScripts\Dinamic\Model\NCFTipoMovimiento;
0 ignored issues
show
Bug introduced by
The type FacturaScripts\Dinamic\Model\NCFTipoMovimiento 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\Proveedor;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, FacturaScripts\Plugins\f...tension\Model\Proveedor. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
Bug introduced by
The type FacturaScripts\Dinamic\Model\Proveedor 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\DGII\CommonModelFunctions;
27
28
/**
29
 * @property $codproveedor
30
 */
31
class FacturaProveedor
32
{
33
    /**
34
     * @var date
0 ignored issues
show
Bug introduced by
The type FacturaScripts\Plugins\f...na\Extension\Model\date 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...
35
     */
36
    public $ncffechavencimiento;
37
    /**
38
     * @var string
39
     */
40
    public $tipocomprobante;
41
    /**
42
     * @var string
43
     */
44
    public $ncftipopago;
45
    /**
46
     * @var string
47
     */
48
    public $ncftipomovimiento;
49
    /**
50
     * @var string
51
     */
52
    public $ncftipoanulacion;
53
54
    /**
55
     * @var string
56
     */
57
    public $numeroncf;
58
59
    public $ecf_recibido = null;
60
61
    public $ecf_aprobacion_comercial = null;
62
63
    public $ecf_codigo_seguridad = null;
64
65
    public $ecf_fecha_firma = null;
66
67
    public $ecf_pdf_firmado = null;
68
    public $ecf_xml_firmado = null;
69
70
    public $totalexento;
71
72
    public $totaladdedtaxes;
73
74
    public $totalplustaxes;
75
76
    public function saveBefore(): Closure
77
    {
78
        return function () {
79
            //$ArrayTipoNCFCompras = ['','','04','05','11', '12', '16', '17','31','32','34','35','46','47'];
80
            $ArrayTipoNCFCompras = ['11','13','41','43'];
81
            $ncfrango = new NCFRango();
82
            $proveedor = new Proveedor();
83
            $actualProveedor = $proveedor::find($this->codproveedor);
0 ignored issues
show
Bug Best Practice introduced by
The property codproveedor does not exist on FacturaScripts\Plugins\f...\Model\FacturaProveedor. Did you maybe forget to declare it?
Loading history...
84
85
            if (null === $actualProveedor) {
86
                Tools::log()->error("no-supplier-found");
87
                return false;
88
            }
89
90
            $actualProveedor->idempresa = Tools::settings('default', 'idempresa');
91
            $this->tipocomprobante = $_REQUEST['tipocomprobanter'] ?? $this->tipocomprobante;
92
            $this->numeroncf = $_REQUEST['numeroncfr'] ?? $this->numeroncf;
93
            $this->ecf_fecha_firma = $_REQUEST['ecf_fecha_firmar'] ?? $this->ecf_fecha_firma;
94
            $this->ecf_fecha_firma = (empty($this->ecf_fecha_firma) ? null : $this->ecf_fecha_firma);
95
            $this->ecf_codigo_seguridad = $_REQUEST['ecf_codigo_seguridadr'] ?? $this->ecf_codigo_seguridad;
96
            $tipocomprobante = $this->tipocomprobante;
97
            if ($tipocomprobante && in_array($tipocomprobante, $ArrayTipoNCFCompras, true)) {
98
                if (!CommonModelFunctions::setCFRango($actualProveedor, $ncfrango, $tipocomprobante, $this)) {
99
                    return false;
100
                }
101
            }
102
            if (in_array($this->tipocomprobante, ['03', '04', '33', '34'], true)) {
103
                $this->ncftipoanulacion = $_REQUEST['ncftipoanulacionr'] ?? $this->ncftipoanulacion;
104
                $this->ncffechavencimiento = $_REQUEST['ncffechavencimientor'] ?? $this->ncffechavencimiento;
105
            }
106
            $this->ncffechavencimiento = $this->ncffechavencimiento !== '' ? $this->ncffechavencimiento : null;
107
        };
108
    }
109
110
    public function descripcionTipoComprobante(): Closure
111
    {
112
        return function () {
113
            $ncftipocomprobante = new NCFTipo();
114
            $ncftipocomprobante->load($this->tipocomprobante);
115
            return $ncftipocomprobante->descripcion;
116
        };
117
    }
118
119
    protected function cleanRefundData(): Closure
120
    {
121
        return function () {
122
            $this->numeroncf = '';
123
            $this->tipocomprobante = null;
124
            $this->ncffechavencimiento = null;
125
            $this->ncftipomovimiento = null;
126
            $this->ncftipopago = null;
127
            $this->ecf_fecha_firma = null;
128
            $this->ecf_codigo_seguridad = null;
129
        };
130
    }
131
}