Passed
Push — master ( 8a423f...9c95d4 )
by Joe Nilson
01:52
created

NCFTipo::install()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 14
nc 1
nop 0
dl 0
loc 16
rs 9.7998
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
27
/**
28
 * Description of NCFTipo
29
 *
30
 * @author "Joe Zegarra <joenilson at gmail dot com>"
31
 */
32
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...
33
{
34
    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...
35
    
36
    /**
37
     * Movement Class can be sum or rest suma|resta
38
     * @var string
39
     */
40
    public $clasemovimiento;
41
    /**
42
     * If the NCF Type is about purchase movement then must to have an X as value
43
     * @var string
44
     */
45
    public $compras;
46
    /**
47
     * If the NCF Type is about regular sales or purchase movements then must to have an X as value
48
     * @var string
49
     */
50
    public $contribuyente;
51
    /**
52
     * The description of the NCF Type
53
     * @var string
54
     */
55
    public $descripcion;
56
    /**
57
     * The status of the record
58
     * @var bool 
59
     */
60
    public $estado;
61
    /**
62
     * If the NCF Type is about sales movement then must to have an X as value
63
     * @var string
64
     */
65
    public $ventas;
66
    /**
67
     * This is the key value that contains the two code type of document
68
     * @var string 
69
     */
70
    public $tipocomprobante;
71
    
72
    /**
73
     * List of NCF types
74
     * @var array
75
     */
76
    public $arrayComprobantes = array(
77
        array ('tipocomprobante' => '01', 'descripcion' => 'FACTURA DE CREDITO FISCAL', 'clasemovimiento'=>'suma', 'ventas'=>'Y', 'compras'=>'Y', 'contribuyente'=>'Y'),
78
        array ('tipocomprobante' => '02', 'descripcion' => 'FACTURA DE CONSUMO', 'clasemovimiento'=>'suma', 'ventas'=>'Y', 'compras'=>'N', 'contribuyente'=>'Y'),
79
        array ('tipocomprobante' => '03', 'descripcion' => 'NOTA DE DEBITO', 'clasemovimiento'=>'suma', 'ventas'=>'Y', 'compras'=>'Y', 'contribuyente'=>'N'),
80
        array ('tipocomprobante' => '04', 'descripcion' => 'NOTA DE CREDITO', 'clasemovimiento'=>'resta', 'ventas'=>'Y', 'compras'=>'Y', 'contribuyente'=>'N'),
81
        array ('tipocomprobante' => '11', 'descripcion' => 'COMPROBANTE DE COMPRAS', 'clasemovimiento'=>'suma', 'ventas'=>'N', 'compras'=>'Y', 'contribuyente'=>'Y'),
82
        array ('tipocomprobante' => '12', 'descripcion' => 'REGISTRO UNICO DE INGRESOS', 'clasemovimiento'=>'suma', 'ventas'=>'Y', 'compras'=>'N', 'contribuyente'=>'N'),
83
        array ('tipocomprobante' => '13', 'descripcion' => 'COMPROBANTE PARA GASTOS MENORES', 'clasemovimiento'=>'suma', 'ventas'=>'N', 'compras'=>'Y', 'contribuyente'=>'N'),
84
        array ('tipocomprobante' => '14', 'descripcion' => 'COMPROBANTE DE REGIMENES ESPECIALES', 'clasemovimiento'=>'suma', 'ventas'=>'Y', 'compras'=>'Y', 'contribuyente'=>'Y'),
85
        array ('tipocomprobante' => '15', 'descripcion' => 'COMPROBANTE GUBERNAMENTAL', 'clasemovimiento'=>'suma', 'ventas'=>'Y', 'compras'=>'Y', 'contribuyente'=>'Y'),
86
        array ('tipocomprobante' => '16', 'descripcion' => 'COMPROBANTE PARA EXPORTACIONES', 'clasemovimiento'=>'suma', 'ventas'=>'Y', 'compras'=>'Y', 'contribuyente'=>'Y'),
87
        array ('tipocomprobante' => '17', 'descripcion' => 'COMPROBANTE PARA PAGOS AL EXTERIOR', 'clasemovimiento'=>'suma', 'ventas'=>'N', 'compras'=>'Y', 'contribuyente'=>'Y'),
88
    );
89
    
90
    /**
91
     * 
92
     * @return string
93
     */
94
    public static function primaryColumn()
95
    {
96
        return 'tipocomprobante';
97
    }
98
    
99
    /**
100
     * 
101
     * @return string
102
     */
103
    public static function tableName()
104
    {
105
        return 'rd_ncftipo';
106
    }
107
    
108
    /**
109
     * 
110
     * @return string
111
     */
112
    public function install() 
113
    {
114
        parent::install();
115
        $sql = "INSERT INTO rd_ncftipo (tipocomprobante, descripcion, estado, clasemovimiento, ventas, compras, contribuyente ) VALUES " .
116
            "('01','FACTURA DE CREDITO FISCAL',TRUE, 'suma','Y','Y','Y')," .
117
            "('02','FACTURA DE CONSUMO',TRUE, 'suma','Y','N','Y')," .
118
            "('03','NOTA DE DEBITO',TRUE, 'suma','Y','Y','N')," . 
119
            "('04','NOTA DE CREDITO',TRUE, 'resta','Y','Y','N')," .
120
            "('11','COMPROBANTE DE COMPRAS',TRUE, 'suma','N','Y','Y')," .
121
            "('12','REGISTRO UNICO DE INGRESOS',TRUE, 'suma','Y','N','N')," .
122
            "('13','COMPROBANTE PARA GASTOS MENORES',TRUE, 'suma','N','Y','N')," .
123
            "('14','COMPROBANTE DE REGIMENES ESPECIALES',TRUE, 'suma','Y','Y','Y')," .
124
            "('15','COMPROBANTE GUBERNAMENTAL',TRUE, 'suma','Y','Y','Y')," .
125
            "('16','COMPROBANTE PARA EXPORTACIONES',TRUE, 'suma','Y','Y','Y')," .
126
            "('17','COMPROBANTE PARA PAGOS AL EXTERIOR',TRUE, 'suma','N', 'Y','Y');";
127
        return($sql);
128
    }
129
    
130
    public function restoreData()
131
    {
132
        $dataBase = new DataBase();
133
        $sqlClean = "DELETE FROM " . $this->tableName() . ";";
134
        $dataBase->exec($sqlClean);
135
        foreach ($this->arrayComprobantes as $arrayItem) {
136
            $initialData = new NCFTipo($arrayItem);
137
            $initialData->save();
138
        }
139
        $this->clear();
140
    }
141
142
    public function allFor($type = "ventas", $movimiento = "suma")
143
    {
144
        $where = [new DataBaseWhere($type, 'Y'),new DataBaseWhere('clasemovimiento', $movimiento)];
145
        return $this->all($where, ['tipocomprobante' => 'ASC'], 0, 50);
146
    }
147
}
148