NCFTipo::primaryColumn()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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