FacturaCliente::descripcionTipoComprobante()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 6
rs 10
1
<?php
2
/**
3
 * Copyright (C) 2020 joenilson.
4
 *
5
 * This library is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU Lesser General Public
7
 * License as published by the Free Software Foundation; either
8
 * version 3 of the License, or (at your option) any later version.
9
 *
10
 * This library 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 GNU
13
 * Lesser General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU Lesser General Public
16
 * License along with this library; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA 02110-1301  USA
19
 */
20
21
namespace FacturaScripts\Plugins\fsRepublicaDominicana\Extension\Model;
22
23
use Cassandra\Date;
24
use Closure;
25
use FacturaScripts\Core\Base\DataBase\DataBaseWhere;
26
use FacturaScripts\Core\Tools;
27
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...
28
use FacturaScripts\Dinamic\Model\NCFTipo;
29
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...
30
use FacturaScripts\Dinamic\Model\Cliente;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, FacturaScripts\Plugins\f...Extension\Model\Cliente. 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\Cliente 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...
31
use FacturaScripts\Plugins\fsRepublicaDominicana\Lib\DGII\CommonModelFunctions;
32
33
/**
34
 * Description of FacturaCliente
35
 *
36
 * @author joenilson
37
 */
38
class FacturaCliente
39
{
40
    /**
41
     * @var Date
42
     */
43
    public $ncffechavencimiento;
44
    /**
45
     * @var string
46
     */
47
    public $tipocomprobante;
48
    /**
49
     * @var string
50
     */
51
    public $numeroncf;
52
    /**
53
     *
54
     * @var string
55
     */
56
    public $ncftipopago;
57
    /**
58
     *
59
     * @var string
60
     */
61
    public $ncftipomovimiento;
62
    /**
63
     *
64
     * @var string
65
     */
66
    public $ncftipoanulacion;
67
68
    /**
69
     * @var string
70
     */
71
    public $facturarectnumero2;
72
73
    public $ecf_trackid = null;
74
75
    public $ecf_estado_dgii = null;
76
77
    public $ecf_codigo_seguridad = null;
78
79
    /**
80
     * @var \DateTime
81
     */
82
    public $ecf_fecha_firma = null;
83
84
    public $ecf_pdf_firmado = null;
85
    public $ecf_xml_firmado = null;
86
87
    public $totalexento;
88
89
    public $totaladdedtaxes;
90
91
    public $totalplustaxes;
92
93
    public function saveBefore(): Closure
94
    {
95
        return function () {
96
            if (null !== $this->codigorect && $this->idfactura === null) {
97
                $this->cleanRefundData();
98
            }
99
            $cliente = new Cliente();
100
            $actualCliente = $cliente::find($this->codcliente);
0 ignored issues
show
Bug Best Practice introduced by
The property codcliente does not exist on FacturaScripts\Plugins\f...on\Model\FacturaCliente. Did you maybe forget to declare it?
Loading history...
101
102
            if (null === $actualCliente) {
103
                Tools::log()->error("no-customer-found");
104
                return false;
105
            }
106
107
            $actualCliente->idempresa = Tools::settings('default', 'idempresa');
108
            $this->tipocomprobante = $this->tipocomprobante ?? $actualCliente->tipocomprobante;
109
            $this->tipocomprobante = $_REQUEST['tipocomprobanter'] ?? $this->tipocomprobante;
110
            $this->ecf_fecha_firma = $_REQUEST['ecf_fecha_firmar'] ?? $this->ecf_fecha_firma;
111
            $this->ecf_fecha_firma = (empty($this->ecf_fecha_firma) ? null : $this->ecf_fecha_firma);
112
            if ($this->tipocomprobante !== '' && \in_array($this->numeroncf, ['', null], true)) {
113
                $tipocomprobante = "02";
114
                if (($this->tipocomprobante !== null) === true) {
115
                    $tipocomprobante = $this->tipocomprobante;
116
                } elseif (($this->tipocomprobante === null) === true) {
117
                    $tipocomprobante = $actualCliente->tipocomprobante;
118
                }
119
120
                $ncfrango = new NCFRango();
121
                if (!CommonModelFunctions::setCFRango($actualCliente, $ncfrango, $tipocomprobante, $this)) return false;
122
123
                $arrayNCFTypes = ['03','04'];
124
                if (in_array($this->tipocomprobante, $arrayNCFTypes) === true) {
125
                    $this->ncftipoanulacion = $_REQUEST['ncftipoanulacionr'] ?? $this->ncftipoanulacion;
126
                    $this->ncffechavencimiento = $_REQUEST['ncffechavencimientor'] ?? $this->ncffechavencimiento;
127
                }
128
            }
129
            $this->ncffechavencimiento = ($this->ncffechavencimiento === '') ? null : $this->ncffechavencimiento;
130
            return $this;
131
        };
132
    }
133
134
    public function all(): Closure
135
    {
136
        return function () {
137
            $this->facturarectnumero2 = '';
138
            /** @var \FacturaScripts\Dinamic\Model\FacturaCliente $this */
139
            if ($this->idfacturarect !== '' || $this->idfacturarect !== null) {
140
                $this->loadFromData(['facturarectnumero2' => 'SI' ]);
141
                $this->facturarectnumero2 = $this::findWhere(['idfacturarect', $this->idfacturarect])->numero2;
142
            } else {
143
                $this->loadFromData(['facturarectnumero2' => 'NO HAY']);
144
            }
145
            return $this;
146
        };
147
    }
148
149
    public function descripcionTipoComprobante(): Closure
150
    {
151
        return function () {
152
            $ncftipocomprobante = new NCFTipo();
153
            $ncftipocomprobante->load($this->tipocomprobante);
154
            return $ncftipocomprobante->descripcion;
155
        };
156
    }
157
    protected function cleanRefundData(): Closure
158
    {
159
        return function () {
160
            $this->numeroncf = '';
161
            $this->tipocomprobante = null;
162
            $this->ncffechavencimiento = null;
163
            $this->ncftipomovimiento = null;
164
            $this->ncftipopago = null;
165
            $this->ecf_fecha_firma = null;
166
            $this->ecf_codigo_seguridad = null;
167
        };
168
    }
169
}
170