Passed
Push — master ( 8e49de...855750 )
by Joe Nilson
03:05
created

NCFTipo::tipoCliente()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Copyright (C) 2019 Joe Zegarra.
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\Model;
22
23
use FacturaScripts\Core\Base\DataBase;
0 ignored issues
show
Bug introduced by
The type FacturaScripts\Core\Base\DataBase 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\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...
25
use FacturaScripts\Core\Model\Base;
0 ignored issues
show
Bug introduced by
The type FacturaScripts\Core\Model\Base 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\Dinamic\Model\Cliente;
0 ignored issues
show
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...
27
28
/**
29
 * Description of NCFTipo
30
 *
31
 * @author "Joe Zegarra <joenilson at gmail dot com>"
32
 */
33
class NCFTipo extends Base\ModelClass
0 ignored issues
show
Bug introduced by
The type FacturaScripts\Core\Model\Base\ModelClass 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...
34
{
35
    use Base\ModelTrait;
0 ignored issues
show
Bug introduced by
The type FacturaScripts\Core\Model\Base\ModelTrait 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...
36
    
37
    /**
38
     * Movement Class can be sum or rest suma|resta
39
     * @var string
40
     */
41
    public $clasemovimiento;
42
    /**
43
     * If the NCF Type is about purchase movement then must to have an X as value
44
     * @var string
45
     */
46
    public $compras;
47
    /**
48
     * If the NCF Type is about regular sales or purchase movements then must to have an X as value
49
     * @var string
50
     */
51
    public $contribuyente;
52
    /**
53
     * The description of the NCF Type
54
     * @var string
55
     */
56
    public $descripcion;
57
    /**
58
     * The status of the record
59
     * @var bool 
60
     */
61
    public $estado;
62
    /**
63
     * If the NCF Type is about sales movement then must to have an X as value
64
     * @var string
65
     */
66
    public $ventas;
67
    /**
68
     * This is the key value that contains the two code type of document
69
     * @var string
70
     */
71
    public $tipocomprobante;
72
    
73
    /**
74
     * List of NCF types
75
     * @var array
76
     */
77
    private $arrayComprobantes = array(
78
        [
79
            'tipocomprobante' => '01', 'descripcion' => 'FACTURA DE CREDITO FISCAL', 'clasemovimiento'=>'suma',
80
            'ventas'=>'Y', 'compras'=>'Y', 'contribuyente'=>'Y', 'estado' => true
81
        ],
82
        [
83
            'tipocomprobante' => '02', 'descripcion' => 'FACTURA DE CONSUMO', 'clasemovimiento'=>'suma',
84
            'ventas'=>'Y', 'compras'=>'Y', 'contribuyente'=>'Y', 'estado' => true
85
        ],
86
        [
87
            'tipocomprobante' => '03', 'descripcion' => 'NOTA DE DEBITO', 'clasemovimiento'=>'suma',
88
            'ventas'=>'Y', 'compras'=>'Y', 'contribuyente'=>'N', 'estado' => true
89
        ],
90
        [
91
            'tipocomprobante' => '04', 'descripcion' => 'NOTA DE CREDITO', 'clasemovimiento'=>'resta',
92
            'ventas'=>'Y', 'compras'=>'Y', 'contribuyente'=>'N', 'estado' => true
93
        ],
94
        [
95
            'tipocomprobante' => '11', 'descripcion' => 'COMPROBANTE DE COMPRAS', 'clasemovimiento'=>'suma',
96
            'ventas'=>'N', 'compras'=>'Y', 'contribuyente'=>'Y', 'estado' => true
97
        ],
98
        [
99
            'tipocomprobante' => '12', 'descripcion' => 'REGISTRO UNICO DE INGRESOS', 'clasemovimiento'=>'suma',
100
            'ventas'=>'Y', 'compras'=>'N', 'contribuyente'=>'N', 'estado' => true
101
        ],
102
        [
103
            'tipocomprobante' => '13', 'descripcion' => 'COMPROBANTE PARA GASTOS MENORES', 'clasemovimiento'=>'suma',
104
            'ventas'=>'N', 'compras'=>'Y', 'contribuyente'=>'N', 'estado' => true
105
        ],
106
        [
107
        'tipocomprobante' => '14', 'descripcion' => 'COMPROBANTE DE REGIMENES ESPECIALES', 'clasemovimiento'=>'suma',
108
            'ventas'=>'Y', 'compras'=>'Y', 'contribuyente'=>'Y', 'estado' => true
109
        ],
110
        [
111
            'tipocomprobante' => '15', 'descripcion' => 'COMPROBANTE GUBERNAMENTAL', 'clasemovimiento'=>'suma',
112
            'ventas'=>'Y', 'compras'=>'Y', 'contribuyente'=>'Y', 'estado' => true
113
        ],
114
        [
115
            'tipocomprobante' => '16', 'descripcion' => 'COMPROBANTE PARA EXPORTACIONES', 'clasemovimiento'=>'suma',
116
            'ventas'=>'Y', 'compras'=>'N', 'contribuyente'=>'Y', 'estado' => true
117
        ],
118
        [
119
            'tipocomprobante' => '17', 'descripcion' => 'COMPROBANTE PARA PAGOS AL EXTERIOR', 'clasemovimiento'=>'suma',
120
            'ventas'=>'N', 'compras'=>'Y', 'contribuyente'=>'Y', 'estado' => true
121
        ],
122
    );
123
    
124
    /**
125
     * @return string
126
     */
127
    public static function primaryColumn(): string
128
    {
129
        return 'tipocomprobante';
130
    }
131
    
132
    /**
133
     * 
134
     * @return string
135
     */
136
    public static function tableName()
137
    {
138
        return 'rd_ncftipo';
139
    }
140
    
141
    /**
142
     * 
143
     * @return string
144
     */
145
    public function install() 
146
    {
147
        parent::install();
148
        $sql = "INSERT INTO rd_ncftipo (".
149
            "tipocomprobante, descripcion, estado, clasemovimiento, ventas, compras, contribuyente".
150
            " ) VALUES " .
151
            "('01','FACTURA DE CREDITO FISCAL',true, 'suma','Y','Y','Y')," .
152
            "('02','FACTURA DE CONSUMO',true, 'suma','Y','Y','Y')," .
153
            "('03','NOTA DE DEBITO',true, 'suma','Y','Y','N')," .
154
            "('04','NOTA DE CREDITO',true, 'resta','Y','Y','N')," .
155
            "('11','COMPROBANTE DE COMPRAS',true, 'suma','N','Y','Y')," .
156
            "('12','REGISTRO UNICO DE INGRESOS',true, 'suma','Y','N','N')," .
157
            "('13','COMPROBANTE PARA GASTOS MENORES',true, 'suma','N','Y','N')," .
158
            "('14','COMPROBANTE DE REGIMENES ESPECIALES',true, 'suma','Y','Y','Y')," .
159
            "('15','COMPROBANTE GUBERNAMENTAL',true, 'suma','Y','Y','Y')," .
160
            "('16','COMPROBANTE PARA EXPORTACIONES',true, 'suma','Y','N','Y')," .
161
            "('17','COMPROBANTE PARA PAGOS AL EXTERIOR',true, 'suma','N', 'Y','Y');";
162
        return($sql);
163
    }
164
    
165
    public function restoreData()
166
    {
167
        $dataBase = new DataBase();
168
        $sqlClean = "DELETE FROM " . $this->tableName() . ";";
169
        $dataBase->exec($sqlClean);
170
        foreach ($this->arrayComprobantes as $arrayItem) {
171
            $initialData = new NCFTipo($arrayItem);
172
            $initialData->save();
173
        }
174
        $this->clear();
175
    }
176
177
    public function allFor($type = "ventas", $movimiento = "suma")
178
    {
179
        $where = [new DataBaseWhere($type, 'Y'),new DataBaseWhere('clasemovimiento', $movimiento)];
180
        return $this->all($where, ['tipocomprobante' => 'ASC'], 0, 50);
181
    }
182
183
    public function tipoCliente($codcliente) {
184
        $where = [new DatabaseWhere( 'codcliente', $_REQUEST['codcliente'])];
0 ignored issues
show
Unused Code introduced by
The assignment to $where is dead and can be removed.
Loading history...
185
        $clientes = new Cliente();
186
        $cliente = $clientes->get($codcliente);
187
        return ['tipocomprobante' => $cliente->tipocomprobante, 'ncftipopago' => $cliente->ncftipopago];
188
    }
189
}
190