Issues (232)

Init.php (15 issues)

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