Passed
Push — master ( ff2dcb...dea4eb )
by Joe Nilson
01:34
created

Init::uninstall()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 0
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 2
rs 10
1
<?php
2
/*
3
 * Copyright (C) 2020-2024 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;
22
23
use FacturaScripts\Core\Lib\AjaxForms\SalesLineHTML;
0 ignored issues
show
Bug introduced by
The type FacturaScripts\Core\Lib\AjaxForms\SalesLineHTML 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\Lib\AjaxForms\SalesFooterHTML;
0 ignored issues
show
Bug introduced by
The type FacturaScripts\Core\Lib\AjaxForms\SalesFooterHTML 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\Lib\AjaxForms\PurchasesFooterHTML;
0 ignored issues
show
Bug introduced by
The type FacturaScripts\Core\Lib\...rms\PurchasesFooterHTML 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\Lib\Calculator;
0 ignored issues
show
Bug introduced by
The type FacturaScripts\Core\Lib\Calculator 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\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...
28
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...
29
use FacturaScripts\Core\Template\InitClass;
0 ignored issues
show
Bug introduced by
The type FacturaScripts\Core\Template\InitClass 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\Core\Tools;
31
32
use FacturaScripts\Core\Model\Impuesto;
0 ignored issues
show
Bug introduced by
The type FacturaScripts\Core\Model\Impuesto 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
use FacturaScripts\Core\Plugins;
34
use FacturaScripts\Dinamic\Controller\SendTicket;
35
use FacturaScripts\Dinamic\Lib\AssetManager;
0 ignored issues
show
Bug introduced by
The type FacturaScripts\Dinamic\Lib\AssetManager 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
use FacturaScripts\Dinamic\Lib\Tickets\RepDominicana;
37
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...
38
use FacturaScripts\Dinamic\Model\EstadoDocumento;
0 ignored issues
show
Bug introduced by
The type FacturaScripts\Dinamic\Model\EstadoDocumento 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...
39
use FacturaScripts\Dinamic\Model\FacturaCliente;
0 ignored issues
show
Bug introduced by
The type FacturaScripts\Dinamic\Model\FacturaCliente 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...
40
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...
41
use FacturaScripts\Dinamic\Model\FacturaProveedor;
0 ignored issues
show
Bug introduced by
The type FacturaScripts\Dinamic\Model\FacturaProveedor 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...
42
use FacturaScripts\Plugins\fsRepublicaDominicana\Model\ImpuestoProducto;
43
use FacturaScripts\Plugins\fsRepublicaDominicana\Model\NCFRango;
44
use FacturaScripts\Plugins\fsRepublicaDominicana\Model\NCFTipo;
45
use FacturaScripts\Plugins\fsRepublicaDominicana\Model\NCFTipoAnulacion;
46
use FacturaScripts\Plugins\fsRepublicaDominicana\Model\NCFTipoMovimiento;
47
use FacturaScripts\Plugins\fsRepublicaDominicana\Model\NCFTipoPago;
48
49
/**
50
 * Description of Init
51
 *
52
 * @author Joe Zegarra
53
 */
54
class Init extends InitClass
55
{
56
    public function init(): void
57
    {
58
        $this->loadExtension(new Extension\Model\Cliente());
59
        $this->loadExtension(new Extension\Model\FacturaCliente());
60
        $this->loadExtension(new Extension\Model\FacturaProveedor());
61
        $this->loadExtension(new Extension\Model\Producto());
62
        $this->loadExtension(new Extension\Controller\EditCliente());
63
        $this->loadExtension(new Extension\Controller\EditProveedor());
64
        $this->loadExtension(new Extension\Controller\EditFacturaCliente());
65
        $this->loadExtension(new Extension\Controller\EditFacturaProveedor());
66
        $this->loadExtension(new Extension\Controller\EditProducto());
67
        $this->loadExtension(new Extension\Controller\EditSettings());
68
69
        AssetManager::add('js', \FS_ROUTE . '/Plugins/fsRepublicaDominicana/Assets/JS/CommonDomFunctions.js');
0 ignored issues
show
Bug introduced by
The constant FS_ROUTE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
70
        SalesLineHTML::addMod(new Mod\SalesLineMod());
71
        SalesFooterHTML::addMod(new Mod\SalesFooterMod());
72
        PurchasesFooterHTML::addMod(new Mod\PurchasesFooterMod());
73
        Calculator::addMod(new Mod\CalculatorMod());
74
75
        if (Plugins::isEnabled('Tickets')) {
76
            SendTicket::addFormat(RepDominicana::class, 'FacturaCliente', 'ncf-dominicana');
77
        }
78
    }
79
80
    private function actualizarEstados(): void
81
    {
82
        $arrayDocumentos = [
83
            'FacturaCliente',
84
            'FacturaProveedor',
85
            'AlbaranCliente',
86
            'AlbaranProveedor',
87
            'PedidoCliente',
88
            'PedidoProveedor'
89
        ];
90
        $estados = new EstadoDocumento();
91
92
        foreach ($arrayDocumentos as $documento) {
93
            $lista = $estados::all(
94
                [
95
                    new DataBaseWhere('nombre', 'Anulada'),
96
                    new DataBaseWhere('tipodoc', $documento)
97
                ]
98
            );
99
100
            if (count($lista) === 0) {
101
                $nuevoDocumento = new EstadoDocumento();
102
                $nuevoDocumento->nombre = 'Anulada';
103
                $nuevoDocumento->tipodoc = $documento;
104
                $nuevoDocumento->icon = 'fa-solid fa-handshake-slash';
105
                $nuevoDocumento->editable = false;
106
                $nuevoDocumento->bloquear = true;
107
                $nuevoDocumento->actualizastock = 0;
108
                $nuevoDocumento->predeterminado = false;
109
                $nuevoDocumento->save();
110
            }
111
        }
112
    }
113
114
    private function actualizarNumeroNCF(): void
115
    {
116
        $dataBase = new DataBase();
117
        $dataBase->exec("UPDATE facturascli SET numeroncf = numero2 WHERE numero2 != '' and tipocomprobante != '' AND numeroncf is null;");
118
        $dataBase->exec("UPDATE facturasprov SET numeroncf = numproveedor WHERE numproveedor != '' and tipocomprobante != '' AND numeroncf is null;");
119
    }
120
121
    private function actualizarImpuestos(): void
122
    {
123
        $impuesto = new Impuesto();
124
        $isc = $impuesto->get('ISC');
125
        if ($isc === false) {
126
            $isc = new Impuesto();
127
            $isc->codimpuesto = 'ISC';
128
            $isc->descripcion = 'ISC 10%';
129
            $isc->iva = 10;
130
            $isc->recargo = 0;
131
            $isc->tipo = 1;
132
            $isc->save();
133
        }
134
135
        $cdt = $impuesto->get('CDT');
136
        if ($cdt === false) {
137
            $cdt = new Impuesto();
138
            $cdt->codimpuesto = 'CDT';
139
            $cdt->descripcion = 'CDT 2%';
140
            $cdt->iva = 2;
141
            $cdt->recargo = 0;
142
            $cdt->tipo = 1;
143
            $cdt->save();
144
        }
145
    }
146
147
    private function actualizarECF(): void
148
    {
149
        $arrayECF = [
150
            ['tipocomprobante' => '31', 'descripcion' => 'FACTURA DE CRÉDITO FISCAL ELECTRÓNICA', 'clasemovimiento'=> 'suma', 'ventas' => 'Y', 'compras' => 'Y', 'contribuyente' => 'Y', 'estado' => true ],
151
            ['tipocomprobante' => '32', 'descripcion' => 'FACTURA DE CONSUMO ELECTRÓNICA', 'clasemovimiento'=> 'suma', 'ventas' => 'Y', 'compras' => 'Y', 'contribuyente' => 'Y', 'estado' => true ],
152
            ['tipocomprobante' => '33', 'descripcion' => 'NOTA DE DÉBITO ELECTRÓNICA', 'clasemovimiento'=> 'suma', 'ventas' => 'Y', 'compras' => 'Y', 'contribuyente' => 'N', 'estado' => true ],
153
            ['tipocomprobante' => '34', 'descripcion' => 'NOTA DE CRÉDITO ELECTRÓNICA', 'clasemovimiento'=> 'resta', 'ventas' => 'Y', 'compras' => 'Y', 'contribuyente' => 'N', 'estado' => true ],
154
            ['tipocomprobante' => '41', 'descripcion' => 'COMPROBANTE ELECTRÓNICO DE COMPRAS', 'clasemovimiento'=> 'suma', 'ventas' => 'N', 'compras' => 'Y', 'contribuyente' => 'Y', 'estado' => true ],
155
            ['tipocomprobante' => '43', 'descripcion' => 'COMPROBANTE ELECTRÓNICO PARA GASTOS MENORES', 'clasemovimiento'=> 'suma', 'ventas' => 'N', 'compras' => 'Y', 'contribuyente' => 'N', 'estado' => true ],
156
            ['tipocomprobante' => '44', 'descripcion' => 'COMPROBANTE ELECTRÓNICO PARA REGÍMENES ESPECIALES', 'clasemovimiento'=> 'suma', 'ventas' => 'Y', 'compras' => 'Y', 'contribuyente' => 'Y', 'estado' => true ],
157
            ['tipocomprobante' => '45', 'descripcion' => 'COMPROBANTE ELECTRÓNICO GUBERNAMENTAL', 'clasemovimiento'=> 'suma', 'ventas' => 'Y', 'compras' => 'Y', 'contribuyente' => 'Y', 'estado' => true ],
158
            ['tipocomprobante' => '46', 'descripcion' => 'COMPROBANTE ELECTRÓNICO PARA EXPORTACIONES', 'clasemovimiento'=> 'suma', 'ventas' => 'Y', 'compras' => 'Y', 'contribuyente' => 'Y', 'estado' => true ],
159
            ['tipocomprobante' => '47', 'descripcion' => 'COMPROBANTE ELECTRÓNICO PARA PAGOS AL EXTERIOR', 'clasemovimiento'=> 'suma', 'ventas' => 'N', 'compras' => 'Y', 'contribuyente' => 'Y', 'estado' => true ],
160
        ];
161
162
        $tipoComprobantes = new NCFTipo();
163
        foreach ($arrayECF as $ecf) {
164
            $registro = $tipoComprobantes->get($ecf['tipocomprobante']);
165
            if($registro === false) {
166
                $registro = new NCFTipo();
167
                $registro->tipocomprobante = $ecf['tipocomprobante'];
168
                $registro->descripcion = $ecf['descripcion'];
169
                $registro->clasemovimiento = $ecf['clasemovimiento'];
170
                $registro->ventas = $ecf['ventas'];
171
                $registro->compras = $ecf['compras'];
172
                $registro->contribuyente = $ecf['contribuyente'];
173
                $registro->estado = $ecf['estado'];
174
                $registro->save();
175
            }
176
        }
177
    }
178
    
179
    public function update(): void
180
    {
181
        new NCFTipoPago();
182
        new NCFTipoAnulacion();
183
        new NCFTipoMovimiento();
184
        new NCFTipo();
185
        new NCFRango();
186
        new Cliente();
187
        new FacturaCliente();
188
        new Proveedor();
189
        new FacturaProveedor();
190
        new ImpuestoProducto();
191
        $this->actualizarEstados();
192
        $this->actualizarNumeroNCF();
193
        $this->actualizarImpuestos();
194
        $this->actualizarECF();
195
    }
196
197
198
    public function uninstall(): void
199
    {
200
        // código de desinstalación aquí
201
    }
202
}
203