Passed
Push — master ( e40575...c62cbd )
by Joe Nilson
02:27
created

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