Issues (638)

controller/admin_rd.php (11 issues)

1
<?php
2
3
/*
4
 * Copyright (C) 2016 Joe Nilson <joenilson at gmail.com>
5
 *
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public License
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 */
19
require_once 'plugins/republica_dominicana/extras/rd_controller.php';
20
/**
21
 * Description of admin_rd
22
 *
23
 * @author Joe Nilson <joenilson at gmail.com>
24
 */
25
class admin_rd extends rd_controller
26
{
27
    public $conf_divisa;
28
    public $conf_impuestos;
29
    public $conf_pais;
30
    public $conf_regional;
31
    public $impuestos_rd;
32
    public $variables;
33
    public function __construct()
34
    {
35
        parent::__construct(__CLASS__, 'República Dominicana', 'admin');
36
    }
37
38
    protected function private_core()
39
    {
40
        parent::private_core();
41
        $this->share_extensions();
42
        $impuesto_empresa = new impuesto();
0 ignored issues
show
The type 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...
43
        $this->init_variables();
44
        $this->init_impuestos();
45
        
46
        $this->init_router();
47
        
48
        $this->get_config();
49
50
        $this->conf_divisa = ($this->empresa->coddivisa == 'DOP') ? true : false;
51
        $this->conf_pais = ($this->empresa->codpais == 'DOM') ? true : false;
52
        $this->conf_regional = ($GLOBALS['config2']['iva'] == 'ITBIS') ? true : false;
53
        $this->conf_impuestos = ($impuesto_empresa->get_by_iva(18)) ? true : false;
54
        //Cargamos el menu
55
        $this->check_menu();
56
    }
57
    
58
    public function init_models()
59
    {
60
        parent::init_models();
61
        new ncf_tipo();
62
        new ncf_entidad_tipo();
63
        new ncf_rango();
64
        new ncf_tipo_anulacion();
65
        new ncf_ventas();
66
    }
67
68
    public function init_variables()
69
    {
70
        $this->variables = array('zona_horaria'=>'America/Santo_Domingo',
71
                                'nf0' => "2", 'nf0_art' => "4", 'nf1' => ".", 'nf2' => ",",
72
                                'pos_divisa' => "left",
73
                                'factura' => "factura", 'facturas' => "facturas",
74
                                'factura_simplificada' => "Ticket", 'factura_rectificativa' => "nota de credito",
75
                                'albaran' => "conduce", 'albaranes' => "conduces", 
76
                                'pedido' => "pedido", 'pedidos' => "pedidos",
77
                                'presupuesto' => "presupuesto", 'presupuestos' => "presupuestos",
78
                                'provincia' => "provincia", 'apartado' => "apartado", 'cifnif' => "Cedula/RNC",
79
                                'iva' => "ITBIS", 'numero2' => "NCF", 'serie' => "serie", 'series' => "series");
80
    }
81
    
82
    public function init_impuestos()
83
    {
84
        $this->impuestos_rd = array(
85
            array('codigo' => 'ITBIS18', 'descripcion' => 'ITBIS 18%', 'porcentaje' => 18, 'recargo' => 0, 'subcuenta_compras' => '', 'subcuenta_ventas' => '', 'default'=>true),
86
            array('codigo' => 'ITBIS10', 'descripcion' => 'ITBIS 10%', 'porcentaje' => 10, 'recargo' => 0, 'subcuenta_compras' => '', 'subcuenta_ventas' => '', 'default'=>false),
87
            array('codigo' => 'ITBIS8', 'descripcion' => 'ITBIS 8%', 'porcentaje' => 8, 'recargo' => 0, 'subcuenta_compras' => '', 'subcuenta_ventas' => '', 'default'=>false),
88
            array('codigo' => 'EXENTO', 'descripcion' => 'EXENTO', 'porcentaje' => 0, 'recargo' => 0, 'subcuenta_compras' => '', 'subcuenta_ventas' => '', 'default'=>false)
89
        );
90
    }
91
    
92
    public function init_router()
93
    {
94
        $opcion = \filter_input(INPUT_GET, 'opcion');
95
        switch ($opcion) {
96
            case 'moneda':
97
                $this->moneda();
98
                break;
99
            case 'impuestos':
100
                $this->impuestos();
101
                break;
102
            case 'pais':
103
                $this->pais();
104
                break;
105
            case 'configuracion_regional':
106
                $this->configuracion_regional();
107
                break;
108
            case 'impresion':
109
                $this->impresion();
110
                break;
111
            default:
112
                break;
113
        }
114
    }
115
116
    /**
117
     * Cargamos el menú en la base de datos, pero en varias pasadas.
118
     */
119
    private function check_menu()
120
    {
121
        if (file_exists(__DIR__)) {
122
            $max = 25;
123
124
            /// leemos todos los controladores del plugin
125
            foreach (scandir(__DIR__) as $f) {
126
                if ($f != '.' and $f != '..' and is_string($f) and strlen($f) > 4 and ! is_dir($f) and $f != __CLASS__ . '.php') {
127
                    /// obtenemos el nombre
128
                    $page_name = substr($f, 0, -4);
129
130
                    /// lo buscamos en el menú
131
                    $encontrado = false;
132
                    foreach ($this->menu as $m) {
133
                        if ($m->name == $page_name) {
134
                            $encontrado = true;
135
                            break;
136
                        }
137
                    }
138
139
                    if (!$encontrado) {
140
                        require_once __DIR__ . '/' . $f;
141
                        $new_fsc = new $page_name();
142
143
                        if (!$new_fsc->page->save()) {
144
                            $this->new_error_msg("Imposible guardar la página " . $page_name);
145
                        }
146
147
                        unset($new_fsc);
148
149
                        if ($max > 0) {
150
                            $max--;
151
                        } else {
152
                            $this->recargar = true;
0 ignored issues
show
Bug Best Practice introduced by
The property recargar does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
153
                            $this->new_message('Instalando las entradas al menú para el plugin... &nbsp; <i class="fa fa-refresh fa-spin"></i>');
154
                            break;
155
                        }
156
                    }
157
                }
158
            }
159
        } else {
160
            $this->new_error_msg('No se encuentra el directorio ' . __DIR__);
161
        }
162
163
        $this->load_menu(true);
164
    }
165
166
    public function impresion()
167
    {
168
        $fsvar = new fs_var();
0 ignored issues
show
The type fs_var 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...
169
        $op_imprimir_cabecera_fcolor = \filter_input(INPUT_POST, 'rd_imprimir_cabecera_fcolor');
170
        $op_imprimir_cabecera_tcolor = \filter_input(INPUT_POST, 'rd_imprimir_cabecera_tcolor');
171
        $op_imprimir_detalle_color = \filter_input(INPUT_POST, 'rd_imprimir_detalle_color');
172
173
        $rd_config = array(
174
            'rd_imprimir_logo' => $this->setValor(\filter_input(INPUT_POST, 'rd_imprimir_logo'), 'TRUE', 'FALSE'),
175
            'rd_imprimir_marca_agua' => $this->setValor(\filter_input(INPUT_POST, 'rd_imprimir_marca_agua'), 'TRUE', 'FALSE'),
176
            'rd_imprimir_sello_pagado' => $this->setValor(\filter_input(INPUT_POST, 'rd_imprimir_sello_pagado'), 'TRUE', 'FALSE'),
177
            'rd_imprimir_bn' => $this->setValor(\filter_input(INPUT_POST, 'rd_imprimir_bn'), 'TRUE', 'FALSE'),
178
            'rd_imprimir_cliente_box' => $this->setValor(\filter_input(INPUT_POST, 'rd_imprimir_cliente_box'), 'TRUE', 'FALSE'),
179
            'rd_imprimir_detalle_box' =>  $this->setValor(\filter_input(INPUT_POST, 'rd_imprimir_detalle_box'), 'TRUE', 'FALSE'),
180
            'rd_imprimir_detalle_lineas' => $this->setValor(\filter_input(INPUT_POST, 'rd_imprimir_detalle_lineas'), 'TRUE', 'FALSE'),
181
            'rd_imprimir_detalle_colores' => $this->setValor(\filter_input(INPUT_POST, 'rd_imprimir_detalle_lineas'), 'TRUE', 'FALSE'),
182
            'rd_imprimir_cabecera_fcolor' => $this->confirmarValor($op_imprimir_cabecera_fcolor, '#000000'),
183
            'rd_imprimir_cabecera_tcolor' => $this->confirmarValor($op_imprimir_cabecera_tcolor, '#dadada'),
184
            'rd_imprimir_detalle_color' => $this->confirmarValor($op_imprimir_detalle_color, '#000000')
185
        );
186
187
        if ($fsvar->array_save($rd_config)) {
188
            $this->new_message('Opciones de impresión actualizadas correctamente.');
189
        } else {
190
            $this->new_error_msg('Ocurrió un error al intentar actualizar la información de impresión, por favor revise sus datos.');
191
        }
192
    }
193
194
    public function moneda()
195
    {
196
        $div0 = new divisa();
0 ignored issues
show
The type divisa 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...
197
        $tratamiento = false;
198
        //Validamos si existe la moneda DOP
199
        $this->moneda_dop($div0, $tratamiento);
200
        
201
        //Validamos si existe la moneda USD
202
        //por temas de operaciones en dolares
203
        $this->moneda_usd($div0, $tratamiento);
204
205
        if ($tratamiento) {
206
            $this->new_message('Datos de moneda DOP y USD actualizados correctamente.');
207
        }
208
209
        if ($this->empresa->coddivisa != 'DOP') {
210
            //Elegimos la divisa para la empresa como DOP si no esta generada
211
            $this->empresa->coddivisa = 'DOP';
212
            if ($this->empresa->save()) {
213
                $this->new_message('Datos de moneda para la empresa guardados correctamente.');
214
            }
215
        }
216
    }
217
    
218
    private function moneda_dop($div0, &$tratamiento)
219
    {
220
        
221
        $divisa1 = $div0->get('DOP');
222
        if (!$divisa1) {
223
            $div0->coddivisa = 'DOP';
224
            $div0->codiso = '214';
225
            $div0->descripcion = 'PESOS DOMINICANOS';
226
            $div0->simbolo = 'RD$';
227
            $div0->tasaconv = 57.1438;
228
            $div0->tasaconv_compra = 57.1438;
229
            $div0->save();    
230
        }
231
        $tratamiento = true;
232
    }
233
    
234
    private function moneda_usd($div0, &$tratamiento)
235
    {
236
        $divisa2 = $div0->get('USD');
237
        if (!$divisa2) {
238
            $div0->coddivisa = 'USD';
239
            $div0->codiso = '840';
240
            $div0->descripcion = 'DÓLARES EE.UU.';
241
            $div0->simbolo = '$';
242
            $div0->tasaconv = 1;
243
            $div0->tasaconv_compra = 1;
244
            $div0->save();
245
        }
246
        $tratamiento = true;
247
    }
248
249
    public function impuestos()
250
    {
251
        $impuestos = new impuesto();
252
        //Eliminamos los Impuestos que no son de RD
253
        $lista_impuestos = array();
254
        foreach ($this->impuestos_rd as $imp) {
255
            $lista_impuestos[] = $imp['porcentaje'];
256
        }
257
258
        foreach ($impuestos->all() as $imp) {
259
            $imp->delete();
260
        }
261
        $tratamiento=false;
262
        //Agregamos los Impuestos de RD
263
        $this->agregar_impuestos($tratamiento);
264
        
265
266
        //Corregimos la información de las Cuentas especiales con los nombres correctos
267
        $this->cuentas_especiales();
268
        
269
        //Cargamos el ejercicio configurando la longitud de cuentas a 8
270
        $this->corregir_ejercicio($tratamiento);
271
        
272
    }
273
    
274
    public function agregar_impuestos(&$tratamiento)
275
    {
276
        $impuestos = new impuesto();
277
        foreach ($this->impuestos_rd as $imp) {
278
            if (!$impuestos->get_by_iva($imp['porcentaje'])) {
279
                $imp0 = new impuesto();
280
                $imp0->codimpuesto = $imp['codigo'];
281
                $imp0->descripcion = $imp['descripcion'];
282
                $imp0->iva = $imp['porcentaje'];
283
                $imp0->recargo = $imp['recargo'];
284
                $imp0->codsubcuentasop = $imp['subcuenta_compras'];
285
                $imp0->codsubcuentarep = $imp['subcuenta_ventas'];
286
                $imp0->is_default();
287
                if ($imp0->save()) {
288
                    $tratamiento = true;
289
                }
290
                if($tratamiento===true AND $imp['default']){
291
                    $this->save_codimpuesto($imp['codigo']);
292
                }
293
            }
294
        }
295
    }
296
    
297
    public function corregir_ejercicio($tratamiento)
298
    {
299
        $cod = $this->empresa->codejercicio;
300
        $ejer0 = new ejercicio();
0 ignored issues
show
The type ejercicio 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...
301
        $ejer = $ejer0->get($cod);
302
        $ejer->longsubcuenta = 8;
303
        $ejer->save();
304
305
        if ($tratamiento) {
306
            $this->new_message('Información de impuestos actualizada correctamente');
307
        } else {
308
            $this->new_message('No se modificaron datos de impuestos previamente tratados.');
309
        }
310
    }
311
    
312
    private function cuentas_especiales()
313
    {
314
        $cuentas_especiales_rd = array();
315
        $cuentas_especiales_rd['IVAACR'] = 'Cuentas acreedoras de ITBIS en la regularización';
316
        $cuentas_especiales_rd['IVASOP'] = 'Cuentas de ITBIS Compras';
317
        $cuentas_especiales_rd['IVARXP'] = 'Cuentas de ITBIS exportaciones';
318
        $cuentas_especiales_rd['IVASIM'] = 'Cuentas de ITBIS importaciones';
319
        $cuentas_especiales_rd['IVAREX'] = 'Cuentas de ITBIS para clientes exentos';
320
        $cuentas_especiales_rd['IVAREP'] = 'Cuentas de ITBIS Ventas';
321
        $cuentas_especiales = new cuenta_especial();
0 ignored issues
show
The type cuenta_especial 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...
322
        foreach ($cuentas_especiales_rd as $id => $desc) {
323
            $linea = $cuentas_especiales->get($id);
324
            if ($linea->descripcion !== $desc) {
325
                $linea->descripcion = $desc;
326
                $linea->save();
327
            }
328
        }
329
    }
330
331
    public function pais()
332
    {
333
        $pais0 = new pais();
0 ignored issues
show
The type pais 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...
334
        $pais1 = $pais0->get('DOM');
335
        if (!$pais1) {
336
            $pais0->codpais = 'DOM';
337
            $pais0->codiso = 'DO';
338
            $pais0->nombre = 'República Dominicana';
339
            $pais0->save();
340
        }
341
342
        $pais2 = $pais0->get('USA');
343
        if (!$pais2) {
344
            $pais0->codpais = 'USA';
345
            $pais0->codiso = 'US';
346
            $pais0->nombre = 'Estados Unidos';
347
            $pais0->save();
348
        }
349
350
        $this->empresa->codpais = 'DOM';
351
        if ($this->empresa->save()) {
352
            $this->new_message('Datos guardados correctamente.');
353
        }
354
    }
355
356
    public function configuracion_regional()
357
    {
358
        //Configuramos la información básica para config2.ini
359
        $guardar = false;
360
        foreach ($GLOBALS['config2'] as $i => $value) {
361
            if (isset($this->variables[$i])) {
362
                $GLOBALS['config2'][$i] = $this->variables[$i];
363
                $guardar = true;
364
            }
365
        }
366
367
        if ($guardar) {
368
            $file = fopen('tmp/' . FS_TMP_NAME . 'config2.ini', 'w');
0 ignored issues
show
The constant FS_TMP_NAME was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
369
            if ($file) {
0 ignored issues
show
$file is of type resource, thus it always evaluated to false.
Loading history...
370
                foreach ($GLOBALS['config2'] as $i => $value) {
371
                    if (is_numeric($value)) {
372
                        fwrite($file, $i . " = " . $value . ";\n");
373
                    } else {
374
                        fwrite($file, $i . " = '" . $value . "';\n");
375
                    }
376
                }
377
                fclose($file);
378
            }
379
            $this->new_message('Datos de configuracion regional guardados correctamente.');
380
        }
381
    }
382
383
    private function share_extensions()
384
    {
385
        $fsext = new fs_extension();
0 ignored issues
show
The type fs_extension 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...
386
        $fsext->name = 'pcgr_completo';
387
        $fsext->from = __CLASS__;
388
        $fsext->to = 'contabilidad_ejercicio';
389
        $fsext->type = 'fuente';
390
        $fsext->text = 'Plan Contable República Dominicana <strong>para industrias</strong>';
391
        $fsext->params = 'plugins/republica_dominicana/extras/rd_completo.xml';
392
        $fsext->delete();
393
394
        $fsext->name = 'pcgr';
395
        $fsext->from = __CLASS__;
396
        $fsext->to = 'contabilidad_ejercicio';
397
        $fsext->type = 'fuente';
398
        $fsext->text = 'Plan Contable República Dominicana <strong>para pymes</strong>';
399
        $fsext->params = 'plugins/republica_dominicana/extras/rd_basico.xml';
400
        $fsext->save();
401
402
        $extensiones = array(
403
            array(
404
                'name' => '001_admin_rd_js',
405
                'page_from' => __CLASS__,
406
                'page_to' => __CLASS__,
407
                'type' => 'head',
408
                'text' => '<script src="' . FS_PATH . 'plugins/republica_dominicana/view/js/bootstrap-colorpicker.min.js" type="text/javascript"></script>',
0 ignored issues
show
The constant FS_PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
409
                'params' => ''
410
            ),
411
            array(
412
                'name' => '001_admin_rd_css',
413
                'page_from' => __CLASS__,
414
                'page_to' => __CLASS__,
415
                'type' => 'head',
416
                'text' => '<link rel="stylesheet" type="text/css" media="screen" href="' . FS_PATH . 'plugins/republica_dominicana/view/css/bootstrap-colorpicker.min.css"/>',
417
                'params' => ''
418
            ),
419
        );
420
        foreach ($extensiones as $ext) {
421
            $fext = new fs_extension($ext);
422
            if (!$fext->save()) {
423
                $this->new_error_msg('Imposible guardar los datos de la extensión ' . $ext['name'] . '.');
424
            }
425
        }
426
    }
427
}
428