Init::actualizarNumeroNCF()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 5
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\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;
25
use FacturaScripts\Core\Lib\AjaxForms\PurchasesLineHTML;
0 ignored issues
show
Bug introduced by
The type FacturaScripts\Core\Lib\...Forms\PurchasesLineHTML 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\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...
27
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...
28
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...
29
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...
30
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...
31
use FacturaScripts\Core\Plugins;
32
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...
33
use FacturaScripts\Core\Tools;
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\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...
41
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...
42
use FacturaScripts\Plugins\fsRepublicaDominicana\Model\ImpuestoAdicional;
43
use FacturaScripts\Plugins\fsRepublicaDominicana\Model\ImpuestoProducto;
44
use FacturaScripts\Plugins\fsRepublicaDominicana\Model\NCFRango;
45
use FacturaScripts\Plugins\fsRepublicaDominicana\Model\NCFTipo;
46
use FacturaScripts\Plugins\fsRepublicaDominicana\Model\NCFTipoAnulacion;
47
use FacturaScripts\Plugins\fsRepublicaDominicana\Model\NCFTipoMovimiento;
48
use FacturaScripts\Plugins\fsRepublicaDominicana\Model\NCFTipoPago;
49
50
/**
51
 * Description of Init
52
 *
53
 * @author Joe Zegarra
54
 */
55
class Init extends InitClass
56
{
57
    public function init(): void
58
    {
59
        $this->loadExtension(new Extension\Model\Cliente());
60
        $this->loadExtension(new Extension\Model\PedidoCliente());
61
        $this->loadExtension(new Extension\Model\AlbaranCliente());
62
        $this->loadExtension(new Extension\Model\FacturaCliente());
63
        $this->loadExtension(new Extension\Model\LineaPedidoCliente());
64
        $this->loadExtension(new Extension\Model\LineaAlbaranCliente());
65
        $this->loadExtension(new Extension\Model\LineaFacturaCliente());
66
        $this->loadExtension(new Extension\Model\PedidoProveedor());
67
        $this->loadExtension(new Extension\Model\AlbaranProveedor());
68
        $this->loadExtension(new Extension\Model\FacturaProveedor());
69
        $this->loadExtension(new Extension\Model\LineaPedidoProveedor());
70
        $this->loadExtension(new Extension\Model\LineaAlbaranProveedor());
71
        $this->loadExtension(new Extension\Model\LineaFacturaProveedor());
72
        $this->loadExtension(new Extension\Model\Producto());
73
        $this->loadExtension(new Extension\Controller\EditCliente());
74
        $this->loadExtension(new Extension\Controller\EditProveedor());
75
        $this->loadExtension(new Extension\Controller\EditFacturaCliente());
76
        $this->loadExtension(new Extension\Controller\EditFacturaProveedor());
77
        $this->loadExtension(new Extension\Controller\EditProducto());
78
        $this->loadExtension(new Extension\Controller\EditSettings());
79
80
        $route = Tools::config('route');
81
        AssetManager::addJs($route . '/Plugins/fsRepublicaDominicana/Assets/JS/CommonDomFunctions.js');
82
83
        SalesLineHTML::addMod(new Mod\SalesLineHTMLMod());
84
        SalesFooterHTML::addMod(new Mod\SalesFooterHTMLMod());
85
        PurchasesLineHTML::addMod(new Mod\PurchasesLineHTMLMod());
86
        PurchasesFooterHTML::addMod(new Mod\PurchasesFooterHTMLMod());
87
        Calculator::addMod(new Mod\CalculatorMod());
88
89
        if (Plugins::isEnabled('Tickets')) {
90
            SendTicket::addFormat(RepDominicana::class, 'FacturaCliente', 'ncf-dominicana');
91
        }
92
    }
93
94
    private function actualizarEstados(): void
95
    {
96
        $arrayDocumentos = [
97
            'FacturaCliente',
98
            'FacturaProveedor',
99
            'AlbaranCliente',
100
            'AlbaranProveedor',
101
            'PedidoCliente',
102
            'PedidoProveedor'
103
        ];
104
        $estados = new EstadoDocumento();
105
106
        foreach ($arrayDocumentos as $documento) {
107
            $lista = $estados::all(
108
                [
109
                    new DataBaseWhere('nombre', 'Anulada'),
110
                    new DataBaseWhere('tipodoc', $documento)
111
                ]
112
            );
113
114
            if (count($lista) === 0) {
115
                $nuevoDocumento = new EstadoDocumento();
116
                $nuevoDocumento->nombre = 'Anulada';
117
                $nuevoDocumento->tipodoc = $documento;
118
                $nuevoDocumento->icon = 'fa-solid fa-handshake-slash';
119
                $nuevoDocumento->editable = false;
120
                $nuevoDocumento->bloquear = true;
121
                $nuevoDocumento->actualizastock = 0;
122
                $nuevoDocumento->predeterminado = false;
123
                $nuevoDocumento->save();
124
            }
125
        }
126
    }
127
128
    private function actualizarEstadoFacturaElectronica(): void
129
    {
130
        $arrayDocumentos = [
131
            'FacturaCliente',
132
            'FacturaProveedor'
133
        ];
134
135
        $estados = new EstadoDocumento();
136
137
        foreach ($arrayDocumentos as $documento) {
138
            $listaEspera = $estados::all(
139
                [
140
                    new DataBaseWhere('nombre', 'En espera'),
141
                    new DataBaseWhere('tipodoc', $documento)
142
                ]
143
            );
144
145
            if (isset($listaEspera)) {
146
                foreach ($listaEspera as $espera) {
147
                    $espera->delete();
148
                }
149
            }
150
151
//            if (count($listaEspera) === 0) {
152
//                $nuevoDocumento = new EstadoDocumento();
153
//                $nuevoDocumento->nombre = 'En espera';
154
//                $nuevoDocumento->tipodoc = $documento;
155
//                $nuevoDocumento->icon = 'fa-solid fa-hourglass-start';
156
//                $nuevoDocumento->editable = false;
157
//                $nuevoDocumento->bloquear = true;
158
//                $nuevoDocumento->actualizastock = 0;
159
//                $nuevoDocumento->predeterminado = false;
160
//                $nuevoDocumento->save();
161
//            }
162
163
            $listaFirma = $estados::all(
164
                [
165
                    new DataBaseWhere('nombre', 'Firmada'),
166
                    new DataBaseWhere('tipodoc', $documento)
167
                ]
168
            );
169
170
171
            if (isset($listaFirma)) {
172
                foreach ($listaFirma as $firma) {
173
                    $firma->delete();
174
                }
175
            }
176
177
//            if (count($listaFirma) === 0) {
178
//                $nuevoDocumento = new EstadoDocumento();
179
//                $nuevoDocumento->nombre = 'Firmada';
180
//                $nuevoDocumento->tipodoc = $documento;
181
//                $nuevoDocumento->icon = 'fa-solid fa-file-circle-check';
182
//                $nuevoDocumento->editable = false;
183
//                $nuevoDocumento->bloquear = true;
184
//                $nuevoDocumento->actualizastock = 1;
185
//                $nuevoDocumento->predeterminado = false;
186
//                $nuevoDocumento->save();
187
//            }
188
        }
189
    }
190
191
    private function actualizarNumeroNCF(): void
192
    {
193
        $dataBase = new DataBase();
194
        $dataBase->exec("UPDATE facturascli SET numeroncf = numero2 WHERE numero2 != '' and tipocomprobante != '' AND numeroncf is null;");
195
        $dataBase->exec("UPDATE facturasprov SET numeroncf = numproveedor WHERE numproveedor != '' and tipocomprobante != '' AND numeroncf is null;");
196
    }
197
198
    private function actualizarImpuestos(): void
199
    {
200
        $impuesto = new Impuesto();
201
        $isc = $impuesto::find('ISC');
202
        if ($isc !== false) {
203
            $isc->delete();
204
        }
205
206
        $cdt = $impuesto::find('CDT');
207
        if ($cdt !== false) {
208
            $cdt->delete();
209
        }
210
211
        $dataBase = new DataBase();
212
        $dataBase->exec("DELETE FROM rd_impuestosadicionales where codigo IN ('006', '007', '008', '009', '010', '011', '012', '013', '014', '015', '016', '017', '018', '019', '020', '021', '022');");
213
    }
214
215
    private function actualizarECF(): void
216
    {
217
        $arrayECF = [
218
            ['tipocomprobante' => '31', 'descripcion' => 'FACTURA DE CRÉDITO FISCAL ELECTRÓNICA', 'clasemovimiento' => 'suma', 'ventas' => 'Y', 'compras' => 'Y', 'contribuyente' => 'Y', 'estado' => true],
219
            ['tipocomprobante' => '32', 'descripcion' => 'FACTURA DE CONSUMO ELECTRÓNICA', 'clasemovimiento' => 'suma', 'ventas' => 'Y', 'compras' => 'Y', 'contribuyente' => 'Y', 'estado' => true],
220
            ['tipocomprobante' => '33', 'descripcion' => 'NOTA DE DÉBITO ELECTRÓNICA', 'clasemovimiento' => 'suma', 'ventas' => 'Y', 'compras' => 'Y', 'contribuyente' => 'N', 'estado' => true],
221
            ['tipocomprobante' => '34', 'descripcion' => 'NOTA DE CRÉDITO ELECTRÓNICA', 'clasemovimiento' => 'resta', 'ventas' => 'Y', 'compras' => 'Y', 'contribuyente' => 'N', 'estado' => true],
222
            ['tipocomprobante' => '41', 'descripcion' => 'COMPROBANTE ELECTRÓNICO DE COMPRAS', 'clasemovimiento' => 'suma', 'ventas' => 'N', 'compras' => 'Y', 'contribuyente' => 'Y', 'estado' => true],
223
            ['tipocomprobante' => '43', 'descripcion' => 'COMPROBANTE ELECTRÓNICO PARA GASTOS MENORES', 'clasemovimiento' => 'suma', 'ventas' => 'N', 'compras' => 'Y', 'contribuyente' => 'N', 'estado' => true],
224
            ['tipocomprobante' => '44', 'descripcion' => 'COMPROBANTE ELECTRÓNICO PARA REGÍMENES ESPECIALES', 'clasemovimiento' => 'suma', 'ventas' => 'Y', 'compras' => 'Y', 'contribuyente' => 'Y', 'estado' => true],
225
            ['tipocomprobante' => '45', 'descripcion' => 'COMPROBANTE ELECTRÓNICO GUBERNAMENTAL', 'clasemovimiento' => 'suma', 'ventas' => 'Y', 'compras' => 'Y', 'contribuyente' => 'Y', 'estado' => true],
226
            ['tipocomprobante' => '46', 'descripcion' => 'COMPROBANTE ELECTRÓNICO PARA EXPORTACIONES', 'clasemovimiento' => 'suma', 'ventas' => 'Y', 'compras' => 'Y', 'contribuyente' => 'Y', 'estado' => true],
227
            ['tipocomprobante' => '47', 'descripcion' => 'COMPROBANTE ELECTRÓNICO PARA PAGOS AL EXTERIOR', 'clasemovimiento' => 'suma', 'ventas' => 'N', 'compras' => 'Y', 'contribuyente' => 'Y', 'estado' => true],
228
        ];
229
230
        $tipoComprobantes = new NCFTipo();
231
        foreach ($arrayECF as $ecf) {
232
            $registro = $tipoComprobantes->get($ecf['tipocomprobante']);
233
            if ($registro === false) {
234
                $registro = new NCFTipo();
235
                $registro->tipocomprobante = $ecf['tipocomprobante'];
236
                $registro->descripcion = $ecf['descripcion'];
237
                $registro->clasemovimiento = $ecf['clasemovimiento'];
238
                $registro->ventas = $ecf['ventas'];
239
                $registro->compras = $ecf['compras'];
240
                $registro->contribuyente = $ecf['contribuyente'];
241
                $registro->estado = $ecf['estado'];
242
                $registro->save();
243
            }
244
        }
245
    }
246
247
    public function update(): void
248
    {
249
        new NCFTipoPago();
250
        new NCFTipoAnulacion();
251
        new NCFTipoMovimiento();
252
        new NCFTipo();
253
        new NCFRango();
254
        new Cliente();
255
        new FacturaCliente();
256
        new Proveedor();
257
        new FacturaProveedor();
258
        new ImpuestoProducto();
259
        new ImpuestoAdicional();
260
        $this->actualizarEstados();
261
        $this->actualizarEstadoFacturaElectronica();
262
        $this->actualizarNumeroNCF();
263
        $this->actualizarImpuestos();
264
        $this->actualizarECF();
265
266
    }
267
268
    public function uninstall(): void
269
    {
270
        // código de desinstalación aquí
271
    }
272
}
273