Init   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 147
Duplicated Lines 0 %

Importance

Changes 7
Bugs 0 Features 1
Metric Value
eloc 101
c 7
b 0
f 1
dl 0
loc 147
rs 10
wmc 14

7 Methods

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