informes_fiscales::reporteVentasAgente()   B
last analyzed

Complexity

Conditions 6
Paths 16

Size

Total Lines 42
Code Lines 37

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 2 Features 0
Metric Value
cc 6
eloc 37
c 2
b 2
f 0
nc 16
nop 2
dl 0
loc 42
rs 8.7057
1
<?php
2
3
/*
4
 * Copyright (C) 2017 joenilson at gmail dot com
5
 *
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU Lesser 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/facturacion_base/extras/xlsxwriter.class.php';
20
require_once 'plugins/republica_dominicana/extras/rd_controller.php';
21
/**
22
 * Description of reportes_fiscales
23
 *
24
 * @author joenilson
25
 */
26
class informes_fiscales extends rd_controller
27
{
28
    public $almacen;
29
    public $almacenes;
30
    public $almacenes_seleccionados;
31
    public $codalmacen;
32
    public $fecha_inicio;
33
    public $fecha_fin;
34
    public $reporte;
35
    public $resultados_consolidado;
36
    public $resultados_ventas;
37
    public $resultados_compras;
38
    public $resultados_606;
39
    public $resultados_607;
40
    public $resultados_608;
41
    public $resultados_detalle_ventas;
42
    public $resultados_detalle_compras;
43
    public $resultados_resumen_ventas;
44
    public $resultados_ventas_agente;
45
    public $total_resultados_consolidado;
46
    public $total_resultados_ventas;
47
    public $total_resultados_compras;
48
    public $total_resultados_606;
49
    public $total_resultados_607;
50
    public $total_resultados_608;
51
    public $total_resultados_detalle_compras;
52
    public $total_resultados_detalle_ventas;
53
    public $total_resultados_resumen_ventas;
54
    public $total_resultados_ventas_agente;
55
    public $total_forma_pago;
56
    public $total_forma_pago_dgii;
57
    public $sumaVentas;
58
    public $sumaVentasPagadas;
59
    public $sumaCompras;
60
    public $sumaComprasPagadas;
61
    public $saldoConsolidado;
62
    public $saldoConsolidadoPagadas;
63
    public $totalDescuento;
64
    public $totalDocumentos;
65
    public $totalCantidad;
66
    public $totalNeto;
67
    public $totalItbis;
68
    public $totalMonto;
69
    public $archivoXLSX;
70
    public $writer;
71
    public $archivoXLSXPath;
72
    public $documentosDir;
73
    public $exportDir;
74
    public $publicPath;
75
76
    //Variables de Busqueda
77
    public $limit;
78
    public $offset;
79
    public $sort;
80
    public $order;
81
    public $search;
82
83
    public function __construct()
84
    {
85
        parent::__construct(__CLASS__, 'Informes Fiscales', 'informes', false, true, false);
86
    }
87
88
    protected function private_core()
89
    {
90
        parent::private_core();
91
        $this->share_extensions();
92
        $this->almacenes = new almacen();
0 ignored issues
show
Bug introduced by
The type almacen 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...
93
        $this->init_variables();
94
        $this->crear_carpetas_reportes();
95
        $codalmacen = $this->filter_request_array('codalmacen');
96
        $almacen_defecto = false;
97
        if (count($this->almacenes->all())===1) {
98
            $almacen_defecto = $this->empresa->codalmacen;
99
        }
100
101
        $this->codalmacen = ($codalmacen)?$codalmacen:$almacen_defecto;
102
        $this->almacenes_seleccionados = (is_array($this->codalmacen))?$this->codalmacen:array($this->codalmacen);
103
104
        $this->verificar_tipo_reporte();
105
    }
106
107
    public function verificar_tipo_reporte()
108
    {
109
        $tiporeporte = \filter_input(INPUT_POST, 'tipo-reporte');
110
        $offset = \filter_input(INPUT_GET, 'offset');
111
        $limit = \filter_input(INPUT_GET, 'limit');
112
        $search = \filter_input(INPUT_GET, 'search');
113
        $sort = \filter_input(INPUT_GET, 'sort');
114
        $order = \filter_input(INPUT_GET, 'order');
115
        $this->fecha_inicio = $this->filter_request('inicio');
116
        $this->fecha_fin = $this->filter_request('fin');
117
        $this->offset = $this->confirmarValor($offset,0);
118
        $this->limit = $this->confirmarValor($limit,FS_ITEM_LIMIT);
0 ignored issues
show
Bug introduced by
The constant FS_ITEM_LIMIT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
119
        $this->search = $this->confirmarValor($search,false);
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type string expected by parameter $valor2 of rd_controller::confirmarValor(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

119
        $this->search = $this->confirmarValor($search,/** @scrutinizer ignore-type */ false);
Loading history...
120
        $this->sort = ($sort and $sort!='undefined')?$sort:'fecha, ncf';
121
        $this->order = ($order and $order!='undefined')?$order:'ASC';
122
        if (!empty($tiporeporte)) {
123
            $this->reporte = $tiporeporte;
124
            $this->mostrar_reporte();
125
        }
126
        if (\filter_input(INPUT_GET, 'tabla_reporte')) {
127
            $this->datos_reporte(\filter_input(INPUT_GET, 'tabla_reporte'), true);
128
        }
129
    }
130
131
    private function mostrar_reporte()
132
    {
133
        switch ($this->reporte) {
134
            case 'reporte-consolidado':
135
                $this->consolidado();
136
                break;
137
            case 'reporte-ventas':
138
                $this->ventas();
139
                break;
140
            case 'detalle-ventas-agente':
141
                $this->ventas_agente();
142
                break;
143
            case 'reporte-compras':
144
                $this->compras();
145
                break;
146
            case 'detalle-compras':
147
                $this->detalle_compras();
148
                break;
149
            case 'reporte-606':
150
                $this->dgii606();
151
                break;
152
            case 'reporte-607':
153
                $this->dgii607();
154
                break;
155
            case 'reporte-608':
156
                $this->dgii608();
157
                break;
158
            case 'detalle-ventas':
159
                $this->detalle_ventas();
160
                break;
161
            case 'resumen-ventas':
162
                $this->resumen_ventas();
163
                break;
164
            default:
165
                break;
166
        }
167
    }
168
169
    private function init_variables()
170
    {
171
        $this->fecha_inicio = \date('01-m-Y');
172
        $this->fecha_fin = \date('d-m-Y');
173
        $this->reporte = '';
174
        $this->resultados_ventas = '';
175
        $this->resultados_compras = '';
176
        $this->resultados_606 = '';
177
        $this->resultados_607 = '';
178
        $this->resultados_608 = '';
179
        $this->resultados_detalle_compras = '';
180
        $this->resultados_detalle_ventas = '';
181
        $this->resultados_resumen_ventas = '';
182
        $this->resultados_ventas_agente = '';
183
        $this->total_resultados_consolidado = 0;
184
        $this->total_resultados_ventas = 0;
185
        $this->total_resultados_compras = 0;
186
        $this->total_resultados_606 = 0;
187
        $this->total_resultados_607 = 0;
188
        $this->total_resultados_608 = 0;
189
        $this->total_resultados_detalle_compras = 0;
190
        $this->total_resultados_detalle_ventas = 0;
191
        $this->total_resultados_resumen_ventas = 0;
192
        $this->total_resultados_ventas_agente = 0;
193
    }
194
195
    private function crear_carpetas_reportes()
196
    {
197
        //Verificamos que exista la carpeta de documentos
198
        $basepath = dirname(dirname(dirname(__DIR__)));
199
        $this->documentosDir = $basepath . DIRECTORY_SEPARATOR . FS_MYDOCS . 'documentos';
0 ignored issues
show
Bug introduced by
The constant FS_MYDOCS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
200
        $this->exportDir = $this->documentosDir . DIRECTORY_SEPARATOR . "informes_rd";
201
        $this->publicPath = FS_PATH . FS_MYDOCS . 'documentos' . DIRECTORY_SEPARATOR . 'informes_rd';
0 ignored issues
show
Bug introduced by
The constant FS_PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
202
203
        if (!is_dir($this->documentosDir)) {
204
            mkdir($this->documentosDir);
205
        }
206
207
        if (!is_dir($this->exportDir)) {
208
            mkdir($this->exportDir);
209
        }
210
    }
211
    
212
    public function datos_reporte($reporte, $json = false)
213
    {
214
        $resultados = array();
215
        $total_informacion = 0;
216
        $almacenes = implode("','", $this->almacenes_seleccionados);
217
        switch ($reporte) {
218
            case "reporte-consolidado":
219
                list($resultados, $total_informacion) = $this->reporteConsolidado($almacenes, $json);
220
                break;
221
            case "reporte-ventas":
222
                list($resultados, $total_informacion) = $this->reporteVentas($almacenes, $json);
223
                break;
224
            case "detalle-ventas-agente":
225
                list($resultados, $total_informacion) = $this->reporteVentasAgente($almacenes, $json);
226
                break;
227
            case "detalle-ventas":
228
                list($resultados, $total_informacion) = $this->reporteDetalleVentas($almacenes, $json);
229
                break;
230
            case "resumen-ventas":
231
                list($resultados, $total_informacion) = $this->reporteResumenVentas($almacenes, $json);
232
                break;
233
            case "reporte-compras":
234
                list($resultados, $total_informacion) = $this->reporteCompras($almacenes, $json);
235
                break;
236
            case "detalle-compras":
237
                list($resultados, $total_informacion) = $this->reporteDetalleCompras($almacenes, $json);
238
                break;
239
            case "reporte-606":
240
                list($resultados, $total_informacion) = $this->reporte606($almacenes, $json);
241
                break;
242
            case "reporte-607":
243
                list($resultados, $total_informacion) = $this->reporte607($almacenes, $json);
244
                break;
245
            case "reporte-608":
246
                list($resultados, $total_informacion) = $this->reporte608($almacenes, $json);
247
                break;
248
            default:
249
                break;
250
        }
251
        if ($json) {
252
            $data = array();
253
            $this->template = false;
254
            header('Content-Type: application/json');
255
            $data['rows'] = $resultados;
256
            $data['total'] = $total_informacion;
257
            echo json_encode($data);
258
        } else {
259
            return $resultados;
260
        }
261
    }
262
263
    public function reporteConsolidado($almacenes, $json)
264
    {
265
        $total_informacion = 0;
266
        $sql_consolidado = "( ".
267
            " SELECT 'Venta' as tipo, nv.codalmacen,nv.fecha,f.nombrecliente as nombre, ".
268
            " CASE WHEN f.anulada THEN 'Anulado' ELSE 'Activo' END as condicion, ".
269
            " CASE WHEN f.pagada THEN 'Si' ELSE 'No' END as pagada, ".
270
            " ncf, ".
271
            " CASE WHEN f.anulada = TRUE THEN 0 ELSE f.totaliva END as totaliva, ".
272
            " CASE WHEN f.anulada = TRUE THEN 0 ELSE f.neto END as neto, ".
273
            " CASE WHEN f.anulada = TRUE THEN 0 ELSE f.total END as total ,".
274
            " codpago ".
275
            " FROM ncf_ventas as nv ".
276
            " JOIN facturascli as f ON (f.idfactura = nv.documento) ".
277
            " WHERE idempresa = ".$this->empresa->intval($this->empresa->id)." AND nv.fecha between ".$this->empresa->var2str(\date("Y-m-d", strtotime($this->fecha_inicio))).
278
            " AND ".$this->empresa->var2str(\date("Y-m-d", strtotime($this->fecha_fin)))." AND nv.codalmacen IN ('".$almacenes."') ".
279
            " ) ".
280
            " UNION ALL ".
281
            " ( ".
282
            " SELECT 'Compra' as tipo, codalmacen, fecha, nombre, ".
283
            " CASE WHEN anulada THEN 'Anulado' ELSE 'Activo' END as condicion, ".
284
            " CASE WHEN pagada THEN 'Si' ELSE 'No' END as pagada, ".
285
            " numproveedor as ncf, ".
286
            " CASE WHEN anulada = TRUE THEN 0 else totaliva END as totaliva, ".
287
            " CASE WHEN anulada = TRUE THEN 0 else neto END as neto, ".
288
            " CASE WHEN anulada = TRUE THEN 0 else total END as total, ".
289
            " codpago ".
290
            " FROM facturasprov ".
291
            " WHERE fecha between ".$this->empresa->var2str(\date("Y-m-d", strtotime($this->fecha_inicio))).
292
            " AND ".$this->empresa->var2str(\date("Y-m-d", strtotime($this->fecha_fin)))." AND codalmacen IN ('".$almacenes."') ".
293
            " ) ".
294
            " ORDER BY codalmacen,".$this->sort." ".$this->order;
295
        $sql_cantidad = "SELECT count(*) as total FROM ( ".$sql_consolidado." ) as t1;";
296
        $data_cantidad = $this->db->select($sql_cantidad);
297
        $sql_resumen = "SELECT t1.tipo,sum(CASE WHEN pagada = 'Si' THEN total ELSE 0 END) as total_pagada,sum(total) as total_general FROM (".
298
                $sql_consolidado.") as t1 GROUP BY t1.tipo;";
299
        $data_resumen = $this->db->select($sql_resumen);
300
301
        $sql_forma_pago = "SELECT codpago, sum(total) as total ".
302
        " FROM (".
303
        $sql_consolidado.") as t1 WHERE tipo = 'Venta' group by codpago ORDER BY codpago;";
304
        $data_forma_pago = $this->db->select($sql_forma_pago);
305
        $this->total_forma_pago = array();
306
        if($data_forma_pago) {
307
            foreach($data_forma_pago as $fpago){
308
                $this->total_forma_pago[] = (object) $fpago;
309
            }
310
        }
311
312
        if ($json) {
313
            $resultados = $this->db->select_limit($sql_consolidado, $this->limit, $this->offset);
314
        } else {
315
            $resultados = $this->db->select($sql_consolidado);
316
        }
317
        $total_informacion+=$data_cantidad[0]['total'];
318
        foreach ($data_resumen as $linea) {
319
            if ($linea['tipo']=='Venta') {
320
                $this->sumaVentasPagadas += $linea['total_pagada'];
321
                $this->sumaVentas += $linea['total_general'];
322
            } elseif ($linea['tipo']=='Compra') {
323
                $this->sumaComprasPagadas += $linea['total_pagada'];
324
                $this->sumaCompras += $linea['total_general'];
325
            }
326
        }
327
328
        return array($resultados, $total_informacion);
329
    }
330
331
    /**
332
     * Reporte consolidado de Ventas y Compras
333
     */
334
    public function consolidado()
335
    {
336
        $this->sumaVentas = 0;
337
        $this->sumaCompras = 0;
338
        $this->saldoConsolidado = 0;
339
        $this->sumaVentasPagadas = 0;
340
        $this->sumaComprasPagadas = 0;
341
        $this->saldoConsolidadoPagadas = 0;
342
        $this->resultados_consolidado = $this->datos_reporte($this->reporte);
343
        $this->saldoConsolidado = $this->sumaVentas - $this->sumaCompras;
344
        $this->saldoConsolidadoPagadas = $this->sumaVentasPagadas - $this->sumaComprasPagadas;
345
346
        $this->generar_excel(
347
            array('Tipo','Almacén','Fecha','Cliente/Proveedor','Condición','Pagada','NCF','ITBIS','Neto','Total','F. Pago'),
0 ignored issues
show
Bug introduced by
array('Tipo', 'Almacén'...o', 'Total', 'F. Pago') of type array<integer,string> is incompatible with the type type expected by parameter $cabecera of informes_fiscales::generar_excel(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

347
            /** @scrutinizer ignore-type */ array('Tipo','Almacén','Fecha','Cliente/Proveedor','Condición','Pagada','NCF','ITBIS','Neto','Total','F. Pago'),
Loading history...
348
            $this->resultados_consolidado,
349
            array('','','','','','','','','','',''),
0 ignored issues
show
Bug introduced by
array('', '', '', '', '', '', '', '', '', '', '') of type array<integer,string> is incompatible with the type type expected by parameter $pie of informes_fiscales::generar_excel(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

349
            /** @scrutinizer ignore-type */ array('','','','','','','','','','',''),
Loading history...
350
            false,
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type type expected by parameter $estilo_cab of informes_fiscales::generar_excel(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

350
            /** @scrutinizer ignore-type */ false,
Loading history...
351
            array(array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'right')),
0 ignored issues
show
Bug introduced by
array(array('halign' => ...y('halign' => 'right')) of type array<integer,array<string,string>> is incompatible with the type type expected by parameter $estilo_datos of informes_fiscales::generar_excel(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

351
            /** @scrutinizer ignore-type */ array(array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'right')),
Loading history...
352
            false
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type type expected by parameter $estilo_pie of informes_fiscales::generar_excel(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

352
            /** @scrutinizer ignore-type */ false
Loading history...
353
        );
354
    }
355
356
    public function reporteDetalleCompras($almacenes, $json)
357
    {
358
        $total_informacion = 0;
359
        $sql_dcompras = "SELECT  codalmacen, fecha, numproveedor as ncf, f.idfactura as documento, referencia, descripcion, cantidad, pvpunitario as precio, pvptotal as monto ".
360
            " FROM facturasprov as f".
361
            " JOIN lineasfacturasprov as fl on (f.idfactura = fl.idfactura)".
362
            " WHERE fecha between ".$this->empresa->var2str(\date("Y-m-d", strtotime($this->fecha_inicio))).
363
            " AND ".$this->empresa->var2str(\date("Y-m-d", strtotime($this->fecha_fin))).
364
            " AND anulada = FALSE ".
365
            " AND codalmacen IN ('".$almacenes."') ".
366
            " ORDER BY codalmacen,".$this->sort." ".$this->order;
367
        $sql_cantidad = "SELECT count(*) as total FROM ( ".$sql_dcompras." ) as t1;";
368
        $data_cantidad = $this->db->select($sql_cantidad);
369
        $sql_resumen = "SELECT sum(cantidad) as cantidad, ".
370
                " sum(monto) as total FROM (".
371
                $sql_dcompras.") as t1;";
372
        $data_resumen = $this->db->select($sql_resumen);
373
        if ($json) {
374
            $resultados = $this->db->select_limit($sql_dcompras, $this->limit, $this->offset);
375
        } else {
376
            $resultados = $this->db->select($sql_dcompras);
377
            $this->totalCantidad += $data_resumen[0]['cantidad'];
378
            $this->totalMonto += $data_resumen[0]['total'];
379
        }
380
        $total_informacion+=$data_cantidad[0]['total'];
381
        return array($resultados, $total_informacion);
382
    }
383
384
    public function detalle_compras()
385
    {
386
        $this->totalCantidad = 0;
387
        $this->totalMonto = 0;
388
        $this->resultados_detalle_compras = $this->datos_reporte($this->reporte);
389
        $this->total_resultados_detalle_compras = 0;
390
        $this->generar_excel(
391
            array('Almacén','Fecha','NCF','Documento','Referencia','Descripción','Cantidad','Precio','Monto'),
0 ignored issues
show
Bug introduced by
array('Almacén', 'Fecha...ad', 'Precio', 'Monto') of type array<integer,string> is incompatible with the type type expected by parameter $cabecera of informes_fiscales::generar_excel(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

391
            /** @scrutinizer ignore-type */ array('Almacén','Fecha','NCF','Documento','Referencia','Descripción','Cantidad','Precio','Monto'),
Loading history...
392
            $this->resultados_detalle_compras,
393
            array('Total','','','','','',$this->totalCantidad, '', $this->totalMonto),
0 ignored issues
show
Bug introduced by
array('Total', '', '', '... '', $this->totalMonto) of type array<integer,mixed|string> is incompatible with the type type expected by parameter $pie of informes_fiscales::generar_excel(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

393
            /** @scrutinizer ignore-type */ array('Total','','','','','',$this->totalCantidad, '', $this->totalMonto),
Loading history...
394
            false,
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type type expected by parameter $estilo_cab of informes_fiscales::generar_excel(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

394
            /** @scrutinizer ignore-type */ false,
Loading history...
395
            array(array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'right')),
0 ignored issues
show
Bug introduced by
array(array('halign' => ...y('halign' => 'right')) of type array<integer,array<string,string>> is incompatible with the type type expected by parameter $estilo_datos of informes_fiscales::generar_excel(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

395
            /** @scrutinizer ignore-type */ array(array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'right')),
Loading history...
396
            false
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type type expected by parameter $estilo_pie of informes_fiscales::generar_excel(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

396
            /** @scrutinizer ignore-type */ false
Loading history...
397
        );
398
    }
399
400
    public function reporteDetalleVentas($almacenes,$json)
401
    {
402
        $total_informacion = 0;
403
        $sql_detalle = "SELECT codalmacen, fecha, ncf, documento, referencia, descripcion, cantidad, ".
404
            "pvpunitario as precio,((pvpunitario*cantidad)*(dtopor/100)) as descuento, pvptotal as monto ".
405
            " FROM ncf_ventas ".
406
            " JOIN lineasfacturascli on (documento = idfactura)".
407
            " WHERE idempresa = ".$this->empresa->intval($this->empresa->id).
408
            " AND fecha between ".$this->empresa->var2str(\date("Y-m-d", strtotime($this->fecha_inicio))).
409
            " AND ".$this->empresa->var2str(\date("Y-m-d", strtotime($this->fecha_fin))).
410
            " AND estado = TRUE ".
411
            " AND codalmacen IN ('".$almacenes."') ".
412
            " ORDER BY codalmacen,".$this->sort." ".$this->order;
413
        $sql_cantidad = "SELECT count(*) as total FROM ( ".$sql_detalle." ) as t1;";
414
        $data_cantidad = $this->db->select($sql_cantidad);
415
        $sql_resumen = "SELECT sum(cantidad) as total_cantidad, ".
416
                "sum(monto) as total_monto FROM (".
417
                $sql_detalle.") as t1;";
418
        $data_resumen = $this->db->select($sql_resumen);
419
        if ($json) {
420
            $resultados = $this->db->select_limit($sql_detalle, $this->limit, $this->offset);
421
        } else {
422
            $resultados = $this->db->select($sql_detalle);
423
            $this->totalCantidad += $data_resumen[0]['total_cantidad'];
424
            $this->totalMonto += $data_resumen[0]['total_monto'];
425
        }
426
        $total_informacion+=$data_cantidad[0]['total'];
427
        return array($resultados, $total_informacion);
428
    }
429
430
    public function detalle_ventas()
431
    {
432
        $this->totalCantidad = 0;
433
        $this->totalMonto = 0;
434
        $this->resultados_detalle_ventas = $this->datos_reporte($this->reporte);
435
        $this->total_resultados_detalle_ventas = 0;
436
        $this->generar_excel(
437
            array('Almacén','Fecha','NCF','Documento','Referencia','Descripción','Cantidad','Precio','Descuento','Monto'),
0 ignored issues
show
Bug introduced by
array('Almacén', 'Fecha..., 'Descuento', 'Monto') of type array<integer,string> is incompatible with the type type expected by parameter $cabecera of informes_fiscales::generar_excel(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

437
            /** @scrutinizer ignore-type */ array('Almacén','Fecha','NCF','Documento','Referencia','Descripción','Cantidad','Precio','Descuento','Monto'),
Loading history...
438
            $this->resultados_detalle_ventas,
439
            array('Total','','','','','',$this->totalCantidad,'', '',$this->totalMonto),
0 ignored issues
show
Bug introduced by
array('Total', '', '', '... '', $this->totalMonto) of type array<integer,mixed|string> is incompatible with the type type expected by parameter $pie of informes_fiscales::generar_excel(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

439
            /** @scrutinizer ignore-type */ array('Total','','','','','',$this->totalCantidad,'', '',$this->totalMonto),
Loading history...
440
            false,
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type type expected by parameter $estilo_cab of informes_fiscales::generar_excel(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

440
            /** @scrutinizer ignore-type */ false,
Loading history...
441
            array(array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'right')),
0 ignored issues
show
Bug introduced by
array(array('halign' => ...y('halign' => 'right')) of type array<integer,array<string,string>> is incompatible with the type type expected by parameter $estilo_datos of informes_fiscales::generar_excel(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

441
            /** @scrutinizer ignore-type */ array(array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'right')),
Loading history...
442
            false
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type type expected by parameter $estilo_pie of informes_fiscales::generar_excel(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

442
            /** @scrutinizer ignore-type */ false
Loading history...
443
        );
444
    }
445
446
    public function reporteResumenVentas($almacenes, $json)
447
    {
448
        $total_informacion = 0;
449
        $sql_rventas = "SELECT codalmacen, ncf_tipo.tipo_comprobante as tipo_comprobante, ncf_tipo.descripcion as tc_descripcion, ".
450
            "referencia, lineasfacturascli.descripcion as descripcion, sum(cantidad) as cantidad, sum(pvptotal) as monto ".
451
            " from ncf_ventas ".
452
            " join lineasfacturascli on (documento = idfactura) ".
453
            " join ncf_tipo on (ncf_ventas.tipo_comprobante = ncf_tipo.tipo_comprobante) ".
454
            " where idempresa = ".$this->empresa->intval($this->empresa->id).
455
            " AND fecha between ".$this->empresa->var2str(\date("Y-m-d", strtotime($this->fecha_inicio))).
456
            " AND ".$this->empresa->var2str(\date("Y-m-d", strtotime($this->fecha_fin))).
457
            " AND ncf_ventas.estado = TRUE ".
458
            " AND codalmacen IN ('".$almacenes."') ".
459
            " GROUP BY codalmacen,ncf_tipo.tipo_comprobante,ncf_tipo.descripcion, referencia, lineasfacturascli.descripcion ".
460
            " ORDER BY codalmacen,ncf_tipo.tipo_comprobante";
461
        $sql_cantidad = "SELECT count(*) as total FROM ( ".$sql_rventas." ) as t1;";
462
        $data_cantidad = $this->db->select($sql_cantidad);
463
        $sql_resumen = "SELECT sum(cantidad) as total_cantidad, ".
464
                "sum(monto) as total_monto FROM (".
465
                $sql_rventas.") as t1;";
466
        $data_resumen = $this->db->select($sql_resumen);
467
        if ($json) {
468
            $resultados = $this->db->select_limit($sql_rventas, $this->limit, $this->offset);
469
        } else {
470
            $resultados = $this->db->select($sql_rventas);
471
            $this->totalCantidad += $data_resumen[0]['total_cantidad'];
472
            $this->totalMonto += $data_resumen[0]['total_monto'];
473
        }
474
        $total_informacion+=$data_cantidad[0]['total'];
475
        return array($resultados, $total_informacion);
476
    }
477
478
    public function resumen_ventas()
479
    {
480
        $this->totalCantidad = 0;
481
        $this->totalMonto = 0;
482
        $this->resultados_resumen_ventas = $this->datos_reporte($this->reporte);
483
        $this->total_resultados_resumen_ventas = 0;
484
        $this->generar_excel(
485
            array('Almacén','Tipo NCF','Descripción NCF','Referencia','Descripción Artículo','Cantidad','monto'),
0 ignored issues
show
Bug introduced by
array('Almacén', 'Tipo ...', 'Cantidad', 'monto') of type array<integer,string> is incompatible with the type type expected by parameter $cabecera of informes_fiscales::generar_excel(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

485
            /** @scrutinizer ignore-type */ array('Almacén','Tipo NCF','Descripción NCF','Referencia','Descripción Artículo','Cantidad','monto'),
Loading history...
486
            $this->resultados_resumen_ventas,
487
            array('Total','','','','',$this->totalCantidad,$this->totalMonto),
0 ignored issues
show
Bug introduced by
array('Total', '', '', '...dad, $this->totalMonto) of type array<integer,mixed|string> is incompatible with the type type expected by parameter $pie of informes_fiscales::generar_excel(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

487
            /** @scrutinizer ignore-type */ array('Total','','','','',$this->totalCantidad,$this->totalMonto),
Loading history...
488
            false,
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type type expected by parameter $estilo_cab of informes_fiscales::generar_excel(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

488
            /** @scrutinizer ignore-type */ false,
Loading history...
489
            array(array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'right'),array('halign'=>'right')),
0 ignored issues
show
Bug introduced by
array(array('halign' => ...y('halign' => 'right')) of type array<integer,array<string,string>> is incompatible with the type type expected by parameter $estilo_datos of informes_fiscales::generar_excel(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

489
            /** @scrutinizer ignore-type */ array(array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'right'),array('halign'=>'right')),
Loading history...
490
            false
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type type expected by parameter $estilo_pie of informes_fiscales::generar_excel(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

490
            /** @scrutinizer ignore-type */ false
Loading history...
491
        );
492
    }
493
494
    public function reporteVentas($almacenes, $json)
495
    {
496
        $total_informacion = 0;
497
        $sql_ventas = "SELECT nv.fecha,nv.codalmacen,f.nombrecliente,nv.cifnif,ncf,ncf_modifica,tipo_comprobante, ".
498
            " CASE WHEN f.anulada = TRUE THEN 0 ELSE f.neto END as neto, ".
499
            " CASE WHEN f.anulada = TRUE THEN 0 ELSE f.totaliva END as totaliva, ".
500
            " CASE WHEN f.anulada = TRUE THEN 0 ELSE f.total END as total, ".
501
            " CASE WHEN f.anulada THEN 'Anulado' ELSE 'Activo' END as condicion, ".
502
            " nv.estado ".
503
            //" CASE WHEN length(nv.cifnif)=9 THEN 1 ELSE 2 END as cifnif_tipo ".
504
            " FROM ncf_ventas as nv ".
505
            " JOIN facturascli as f ON (f.idfactura = nv.documento) ".
506
            " WHERE idempresa = ".$this->empresa->intval($this->empresa->id)." AND ".
507
            " nv.fecha between ".$this->empresa->var2str(\date("Y-m-d", strtotime($this->fecha_inicio))).
508
            " AND ".$this->empresa->var2str(\date("Y-m-d", strtotime($this->fecha_fin))).
509
            " AND nv.codalmacen IN ('".$almacenes."') ".
510
            " ORDER BY codalmacen,".$this->sort." ".$this->order;
511
        $sql_cantidad = "SELECT count(*) as total FROM ( ".$sql_ventas." ) as t1;";
512
        $data_cantidad = $this->db->select($sql_cantidad);
513
        $sql_resumen = "SELECT sum(CASE WHEN t1.condicion = 'Activo' then neto else 0 end) as neto, ".
514
                "sum(CASE WHEN t1.condicion = 'Activo' then totaliva else 0 end) as totaliva,".
515
                "sum(CASE WHEN t1.condicion = 'Activo' then total else 0 end) as total FROM (".
516
                $sql_ventas.") as t1;";
517
        $data_resumen = $this->db->select($sql_resumen);
518
        if ($json) {
519
            $resultados = $this->db->select_limit($sql_ventas, $this->limit, $this->offset);
520
        } else {
521
            $resultados = $this->db->select($sql_ventas);
522
            $this->totalNeto += $data_resumen[0]['neto'];
523
            $this->totalItbis += $data_resumen[0]['totaliva'];
524
            $this->totalMonto += $data_resumen[0]['total'];
525
        }
526
        $total_informacion+=$data_cantidad[0]['total'];
527
        return array($resultados, $total_informacion);
528
    }
529
530
    public function ventas()
531
    {
532
        $this->resultados_ventas = array();
533
        $this->totalCantidad = 0;
534
        $this->totalDescuento = 0;
535
        $this->totalMonto = 0;
536
        $this->resultados_ventas = $this->datos_reporte($this->reporte);
537
        $this->total_resultados_ventas = 0;
538
        $this->generar_excel(
539
            array('Fecha','Almacén','Cliente','RNC','NCF','NCF Modifica','Tipo','Base Imp.','Itbis','Total','Condicion','Estado'),
0 ignored issues
show
Bug introduced by
array('Fecha', 'Almacén... 'Condicion', 'Estado') of type array<integer,string> is incompatible with the type type expected by parameter $cabecera of informes_fiscales::generar_excel(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

539
            /** @scrutinizer ignore-type */ array('Fecha','Almacén','Cliente','RNC','NCF','NCF Modifica','Tipo','Base Imp.','Itbis','Total','Condicion','Estado'),
Loading history...
540
            $this->resultados_ventas,
541
            array('Total','','','','','','',$this->totalNeto,$this->totalItbis,$this->totalMonto,'',''),
0 ignored issues
show
Bug introduced by
array('Total', '', '', '...is->totalMonto, '', '') of type array<integer,mixed|string> is incompatible with the type type expected by parameter $pie of informes_fiscales::generar_excel(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

541
            /** @scrutinizer ignore-type */ array('Total','','','','','','',$this->totalNeto,$this->totalItbis,$this->totalMonto,'',''),
Loading history...
542
            false,
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type type expected by parameter $estilo_cab of informes_fiscales::generar_excel(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

542
            /** @scrutinizer ignore-type */ false,
Loading history...
543
            array(array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'left'),array('halign'=>'left')),
0 ignored issues
show
Bug introduced by
array(array('halign' => ...ay('halign' => 'left')) of type array<integer,array<string,string>> is incompatible with the type type expected by parameter $estilo_datos of informes_fiscales::generar_excel(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

543
            /** @scrutinizer ignore-type */ array(array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'left'),array('halign'=>'left')),
Loading history...
544
            false
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type type expected by parameter $estilo_pie of informes_fiscales::generar_excel(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

544
            /** @scrutinizer ignore-type */ false
Loading history...
545
        );
546
    }
547
548
    public function reporteVentasAgente($almacenes, $json)
549
    {
550
        $disabled = array();
551
        if (defined('FS_DISABLED_PLUGINS')) {
552
            foreach (explode(',', FS_DISABLED_PLUGINS) as $aux) {
0 ignored issues
show
Bug introduced by
The constant FS_DISABLED_PLUGINS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
553
                $disabled[] = $aux;
554
            }
555
        }
556
        $sql_data_nomina = (in_array('nomina', $GLOBALS['plugins']) and ! in_array('nomina', $disabled)) ? "',' ',a.segundo_apellido'":"";
557
        $total_informacion = 0;
558
        $sql_ventas_agente = "SELECT fecha,f.codalmacen, f.codagente, concat(a.nombre$sql_data_nomina) as nombre_vendedor, ".
559
            " g.nombre as grupo_cliente, f.nombrecliente, f.cifnif, f.direccion, ".
560
            " numero2 as ncf, f.idfactura, f.idfacturarect as afecta_a, referencia, lf.descripcion, ".
561
            " cantidad, pvpunitario as precio,((pvpunitario*cantidad)*(dtopor/100)) as descuento, pvptotal as monto, ".
562
            " fp.descripcion as forma_pago, ".
563
            " case when idfacturarect is null then 'VENTA' else 'DEVOLUCION' end as tipo ".
564
            " FROM facturascli as f ".
565
            " JOIN lineasfacturascli as lf on (f.idfactura = lf.idfactura) ".
566
            " JOIN formaspago as fp on (f.codpago = fp.codpago) ".
567
            " JOIN agentes as a on (f.codagente = a.codagente) ".
568
            " JOIN clientes as c on (f.codcliente = c.codcliente) ".
569
            " LEFT JOIN gruposclientes as g on (c.codgrupo = g.codgrupo) ".
570
            " WHERE fecha between ".$this->empresa->var2str(\date("Y-m-d", strtotime($this->fecha_inicio))).
571
            " AND ".$this->empresa->var2str(\date("Y-m-d", strtotime($this->fecha_fin))).
572
            " AND anulada = false AND f.codalmacen IN ('".$almacenes."') ".
573
            " ORDER BY codalmacen,".$this->sort." ".$this->order;
574
        $sql_cantidad = "SELECT count(*) as total FROM ( ".$sql_ventas_agente." ) as t1;";
575
        $data_cantidad = $this->db->select($sql_cantidad);
576
        $sql_resumen = "SELECT sum(cantidad) as total_cantidad, sum(descuento) as total_descuento, ".
577
                "sum(monto) as total_monto FROM (".
578
                $sql_ventas_agente.") as t1;";
579
        $data_resumen = $this->db->select($sql_resumen);
580
        if ($json) {
581
            $resultados = $this->db->select_limit($sql_ventas_agente, $this->limit, $this->offset);
582
        } else {
583
            $resultados = $this->db->select($sql_ventas_agente);
584
            $this->totalCantidad += $data_resumen[0]['total_cantidad'];
585
            $this->totalDescuento += $data_resumen[0]['total_descuento'];
586
            $this->totalMonto += $data_resumen[0]['total_monto'];
587
        }
588
        $total_informacion+=$data_cantidad[0]['total'];
589
        return array($resultados, $total_informacion);
590
    }
591
592
    public function ventas_agente()
593
    {
594
        $this->resultados_ventas = array();
595
        $this->totalCantidad = 0;
596
        $this->totaldescuento = 0;
0 ignored issues
show
Bug Best Practice introduced by
The property totaldescuento does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
597
        $this->totalMonto = 0;
598
        $this->resultados_ventas_agente = $this->datos_reporte($this->reporte);
599
        $this->total_resultados_ventas = 0;
600
        $this->generar_excel(
601
            array('Fecha','Almacén','Cod Vend.','Nombre Vendedor','Grupo de Cliente','Cliente','RNC','Direccion','NCF','Id Fact','Afecta A','Articulo','Descripcion','Cantidad','Precio','Descuento','Monto','Forma Pago','Tipo'),
0 ignored issues
show
Bug introduced by
array('Fecha', 'Almacén..., 'Forma Pago', 'Tipo') of type array<integer,string> is incompatible with the type type expected by parameter $cabecera of informes_fiscales::generar_excel(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

601
            /** @scrutinizer ignore-type */ array('Fecha','Almacén','Cod Vend.','Nombre Vendedor','Grupo de Cliente','Cliente','RNC','Direccion','NCF','Id Fact','Afecta A','Articulo','Descripcion','Cantidad','Precio','Descuento','Monto','Forma Pago','Tipo'),
Loading history...
602
            $this->resultados_ventas_agente,
603
            array('Total','','','','','','','','','','','',$this->totalCantidad,'',$this->totalDescuento,$this->totalMonto,'',''),
0 ignored issues
show
Bug introduced by
array('Total', '', '', '...is->totalMonto, '', '') of type array<integer,mixed|string> is incompatible with the type type expected by parameter $pie of informes_fiscales::generar_excel(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

603
            /** @scrutinizer ignore-type */ array('Total','','','','','','','','','','','',$this->totalCantidad,'',$this->totalDescuento,$this->totalMonto,'',''),
Loading history...
604
            false,
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type type expected by parameter $estilo_cab of informes_fiscales::generar_excel(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

604
            /** @scrutinizer ignore-type */ false,
Loading history...
605
            array(array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'right'),array('halign'=>'left'),array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'left'),array('halign'=>'left')),
0 ignored issues
show
Bug introduced by
array(array('halign' => ...ay('halign' => 'left')) of type array<integer,array<string,string>> is incompatible with the type type expected by parameter $estilo_datos of informes_fiscales::generar_excel(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

605
            /** @scrutinizer ignore-type */ array(array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'right'),array('halign'=>'left'),array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'left'),array('halign'=>'left')),
Loading history...
606
            false
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type type expected by parameter $estilo_pie of informes_fiscales::generar_excel(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

606
            /** @scrutinizer ignore-type */ false
Loading history...
607
        );
608
    }
609
610
    public function reporteCompras($almacenes, $json)
611
    {
612
        $total_informacion = 0;
613
        $sql_compras = " SELECT fecha, codalmacen, nombre, cifnif, ".
614
            " idfactura, numproveedor as ncf, ".
615
            " CASE WHEN anulada = TRUE THEN 0 else totaliva END as totaliva, ".
616
            " CASE WHEN anulada = TRUE THEN 0 else neto END as neto, ".
617
            " CASE WHEN anulada = TRUE THEN 0 else total END as total, ".
618
            " CASE WHEN anulada THEN 'Anulado' ELSE 'Activo' END as condicion, ".
619
            " CASE WHEN anulada THEN 'Si' ELSE 'No' END as estado ".
620
            " FROM facturasprov ".
621
            " WHERE fecha between ".$this->empresa->var2str(\date("Y-m-d", strtotime($this->fecha_inicio))).
622
            " AND ".$this->empresa->var2str(\date("Y-m-d", strtotime($this->fecha_fin))).
623
            " AND codalmacen IN ('".$almacenes."') AND anulada = FALSE".
624
            " ORDER BY codalmacen,".$this->sort." ".$this->order;
625
        $sql_cantidad = "SELECT count(*) as total FROM ( ".$sql_compras." ) as t1;";
626
        $data_cantidad = $this->db->select($sql_cantidad);
627
        $sql_resumen = "SELECT sum(neto) as neto, sum(totaliva) as totaliva, ".
628
                " sum(total) as total FROM (".
629
                $sql_compras.") as t1;";
630
        $data_resumen = $this->db->select($sql_resumen);
631
        if ($json) {
632
            $resultados = $this->db->select_limit($sql_compras, $this->limit, $this->offset);
633
        } else {
634
            $resultados = $this->db->select($sql_compras);
635
            $this->totalNeto += $data_resumen[0]['neto'];
636
            $this->totalItbis += $data_resumen[0]['totaliva'];
637
            $this->totalMonto += $data_resumen[0]['total'];
638
        }
639
        $total_informacion+=$data_cantidad[0]['total'];
640
        return array($resultados, $total_informacion);
641
    }
642
643
    public function compras()
644
    {
645
        $this->resultados_compras = array();
646
        $this->totalNeto = 0;
647
        $this->totalItbis = 0;
648
        $this->totalMonto = 0;
649
        $this->resultados_compras = $this->datos_reporte($this->reporte);
650
        $this->total_resultados_compras = 0;
651
        $this->generar_excel(
652
            array('Fecha','Almacén','Proveedor','RNC','Factura','NCF','Base Imp.','Itbis','Total','Condicion','Anulada'),
0 ignored issues
show
Bug introduced by
array('Fecha', 'Almacén...'Condicion', 'Anulada') of type array<integer,string> is incompatible with the type type expected by parameter $cabecera of informes_fiscales::generar_excel(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

652
            /** @scrutinizer ignore-type */ array('Fecha','Almacén','Proveedor','RNC','Factura','NCF','Base Imp.','Itbis','Total','Condicion','Anulada'),
Loading history...
653
            $this->resultados_compras,
654
            array('Total','','','','','',$this->totalNeto,$this->totalItbis,$this->totalMonto,'',''),
0 ignored issues
show
Bug introduced by
array('Total', '', '', '...is->totalMonto, '', '') of type array<integer,mixed|string> is incompatible with the type type expected by parameter $pie of informes_fiscales::generar_excel(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

654
            /** @scrutinizer ignore-type */ array('Total','','','','','',$this->totalNeto,$this->totalItbis,$this->totalMonto,'',''),
Loading history...
655
            false,
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type type expected by parameter $estilo_cab of informes_fiscales::generar_excel(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

655
            /** @scrutinizer ignore-type */ false,
Loading history...
656
            array(array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'left'),array('halign'=>'left')),
0 ignored issues
show
Bug introduced by
array(array('halign' => ...ay('halign' => 'left')) of type array<integer,array<string,string>> is incompatible with the type type expected by parameter $estilo_datos of informes_fiscales::generar_excel(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

656
            /** @scrutinizer ignore-type */ array(array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'left'),array('halign'=>'left')),
Loading history...
657
            false
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type type expected by parameter $estilo_pie of informes_fiscales::generar_excel(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

657
            /** @scrutinizer ignore-type */ false
Loading history...
658
        );
659
    }
660
661
    public function reporte606($almacenes, $json)
662
    {
663
        $total_informacion = 0;
664
        $sql_606 = " SELECT fp.cifnif, ".
665
            " CASE WHEN length(fp.cifnif)=9 THEN 1 WHEN length(fp.cifnif)=11 THEN 1 ELSE 3 END as tipo_id, ".
666
            " concat(ncftc.codigo,' - ',ncftc.descripcion) as descripcion, ".
667
            " fp.numproveedor as ncf, fp2.numproveedor as ncf_modifica, ".
668
            " concat(extract(year from fp.fecha),lpad(CAST(extract(month from fp.fecha) as char),2,'0'), lpad(CAST(extract(day from fp.fecha) as char),2,'0')) as fecha, ".
669
            " concat(extract(year from ca.fecha),lpad(CAST(extract(month from ca.fecha) as char),2,'0'), lpad(CAST(extract(day from ca.fecha) as char),2,'0')) as fechap, ".
670
            " CASE WHEN ncfc.total_servicios < 0 THEN  ncfc.total_servicios*-1 ELSE ncfc.total_servicios END AS total_servicios, "
671
            . " CASE WHEN ncfc.total_bienes < 0 THEN ncfc.total_bienes*-1 ELSE ncfc.total_bienes END AS total_bienes, "
672
            . "CASE WHEN fp.coddivisa != 'DOP' AND fp.neto < 0 "
673
                    . "THEN round(((fp.neto)*-1 / (select tasaconv from divisas as div1 where div1.coddivisa = fp.coddivisa) * 1) / 1 * (select tasaconv from divisas as div2 where div2.coddivisa = 'DOP'),2) "
674
                . "WHEN fp.coddivisa != 'DOP' AND fp.neto > 0 "
675
                    . "THEN round((fp.neto / (select tasaconv from divisas as div1 where div1.coddivisa = fp.coddivisa) * 1) / 1 * (select tasaconv from divisas as div2 where div2.coddivisa = 'DOP'),2) "
676
                . "WHEN fp.coddivisa = 'DOP' AND fp.neto < 0 "
677
                . " THEN fp.neto*-1 "
678
                . "ELSE fp.neto END as totalfacturado, "
679
            . "CASE WHEN fp.coddivisa != 'DOP' AND fp.totaliva < 0 "
680
                    . "THEN round(((fp.totaliva)*-1 / (select tasaconv from divisas as div1 where div1.coddivisa = fp.coddivisa) * 1) / 1 * (select tasaconv from divisas as div2 where div2.coddivisa = 'DOP'),2) "
681
                . "WHEN fp.coddivisa != 'DOP' AND fp.totaliva > 0 "
682
                    . "THEN round((fp.totaliva / (select tasaconv from divisas as div1 where div1.coddivisa = fp.coddivisa) * 1) / 1 * (select tasaconv from divisas as div2 where div2.coddivisa = 'DOP'),2) "
683
                . "WHEN fp.coddivisa = 'DOP' AND fp.totaliva < 0 "
684
                . " THEN fp.totaliva*-1 "
685
                . "ELSE fp.totaliva END as totaliva, "
686
            . " 0 as totalivaretenido, 0 as totalivasujeto, 0 as totalivallevadocosto, ".
687
            " 0 as totalivaporadelantar, 0 as totalivapercibidocompras, '' as tiporetencionisr, 0 as totalretencionrenta,0 as totalisrpercibidocompra, 0 as totalisc, ".
688
            " 0 as totalotrosimpuestos, 0 as totalpropinalegal, CONCAT(ncftpc.codigo,' - ',ncftpc.descripcion) as codpago ".
689
            " FROM facturasprov as fp ".
690
            " JOIN proveedores as p on (fp.codproveedor = p.codproveedor) ".
691
            " left JOIN ncf_compras as ncfc on (fp.idfactura = ncfc.documento) ".
692
            " left JOIN ncf_tipo_compras as ncftc on (ncfc.tipo_compra = ncftc.codigo) ".
693
            " left JOIN ncf_tipo_pagos_compras as ncftpc on (ncfc.tipo_pago = ncftpc.codigo) ".
694
            " left join facturasprov as fp2 on (fp.idfacturarect = fp2.idfactura) ".
695
            " left join co_asientos as ca on (fp.idasientop = ca.idasiento AND fp.codejercicio = ca.codejercicio) ".
696
            " WHERE fp.fecha between ".$this->empresa->var2str(\date("Y-m-d", strtotime($this->fecha_inicio))).
697
            " AND ".$this->empresa->var2str(\date("Y-m-d", strtotime($this->fecha_fin))).
698
            " AND fp.codalmacen IN ('".$almacenes."') AND fp.anulada = FALSE".
699
            " ORDER BY fp.codalmacen,fp.".$this->sort." ".$this->order;
700
        $sql_cantidad = "SELECT count(*) as total FROM ( ".$sql_606." ) as t1;";
701
        $data_cantidad = $this->db->select($sql_cantidad);
702
        $sql_resumen = "SELECT sum(totaliva) as totaliva, ".
703
                " sum(totalfacturado) as totalneto FROM (".
704
                $sql_606.") as t1;";
705
        $data_resumen = $this->db->select($sql_resumen);
706
        if ($json) {
707
            $resultados = $this->db->select_limit($sql_606, $this->limit, $this->offset);
708
        } else {
709
            $resultados = $this->db->select($sql_606);
710
            $this->totalDocumentos += $data_cantidad[0]['total'];
711
            $this->totalItbis += $data_resumen[0]['totaliva'];
712
            $this->totalNeto += $data_resumen[0]['totalneto'];
713
        }
714
        $total_informacion+=$data_cantidad[0]['total'];
715
        return array($resultados, $total_informacion);
716
    }
717
718
    public function dgii606()
719
    {
720
        $this->totalDocumentos = 0;
721
        $this->totalNeto = 0;
722
        $this->totalItbis = 0;
723
        $this->resultados_606 = array();
724
        $this->resultados_606 = $this->datos_reporte($this->reporte);
725
        $this->total_resultados_606 = 0;
726
        $this->generar_excel(
727
            array('RNC/Cédula','Tipo Id','Tipo Compra','NCF','NCF Modifica','Fecha Documento','Fecha Pago','Total Servicios','Total Bienes','Total Facturado','ITBIS Facturado','ITBIS Retenido','ITBIS sujeto a Proporcionalidad (Art. 349)','ITBIS llevado al Costo','ITBIS por Adelantar','ITBIS percibido en compras','Tipo de Retención en ISR','Monto Retencion Renta','ISR Percibido en compras','Impuesto Selectivo al Consumo','Otros Impuestos/Tasas','Monto Propina Legal','Forma de Pago'),
0 ignored issues
show
Bug introduced by
array('RNC/Cédula', 'Ti...egal', 'Forma de Pago') of type array<integer,string> is incompatible with the type type expected by parameter $cabecera of informes_fiscales::generar_excel(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

727
            /** @scrutinizer ignore-type */ array('RNC/Cédula','Tipo Id','Tipo Compra','NCF','NCF Modifica','Fecha Documento','Fecha Pago','Total Servicios','Total Bienes','Total Facturado','ITBIS Facturado','ITBIS Retenido','ITBIS sujeto a Proporcionalidad (Art. 349)','ITBIS llevado al Costo','ITBIS por Adelantar','ITBIS percibido en compras','Tipo de Retención en ISR','Monto Retencion Renta','ISR Percibido en compras','Impuesto Selectivo al Consumo','Otros Impuestos/Tasas','Monto Propina Legal','Forma de Pago'),
Loading history...
728
            $this->resultados_606,
729
            false,
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type type expected by parameter $pie of informes_fiscales::generar_excel(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

729
            /** @scrutinizer ignore-type */ false,
Loading history...
730
            false,
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type type expected by parameter $estilo_cab of informes_fiscales::generar_excel(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

730
            /** @scrutinizer ignore-type */ false,
Loading history...
731
            array(array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'left')),
0 ignored issues
show
Bug introduced by
array(array('halign' => ...ay('halign' => 'left')) of type array<integer,array<string,string>> is incompatible with the type type expected by parameter $estilo_datos of informes_fiscales::generar_excel(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

731
            /** @scrutinizer ignore-type */ array(array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'left')),
Loading history...
732
            false
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type type expected by parameter $estilo_pie of informes_fiscales::generar_excel(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

732
            /** @scrutinizer ignore-type */ false
Loading history...
733
        );
734
    }
735
736
    public function reporte607($almacenes, $json)
737
    {
738
        $total_informacion = 0;
739
        $sql_607 = "SELECT ".
740
            " CASE WHEN length(nv.cifnif)=9 THEN nv.cifnif WHEN length(nv.cifnif)=11 THEN nv.cifnif ELSE NULL END as cifnif, ".
741
            " CASE WHEN length(nv.cifnif)=9 THEN 1 WHEN length(nv.cifnif)=11 THEN 1 ELSE 3 END as tipo_id, ".
742
            " ncf, ncf_modifica, ".
743
            " CASE WHEN nv.tipo_ingreso is null THEN 1 ELSE tipo_ingreso END as tipo_ingreso, ".
744
            " concat(extract(year from nv.fecha),lpad(CAST(extract(month from nv.fecha) as char),2,'0'),lpad(CAST(extract(day from nv.fecha) as char),2,'0')) as fecha, ".
745
            " '' as fecha_retencion, ".
746
            " CASE WHEN anulada = TRUE THEN 0 "
747
                . " WHEN anulada = FALSE AND neto < 0 THEN neto*-1 "
748
                . "else neto END as neto, ".
749
            " CASE WHEN anulada = TRUE THEN 0 "
750
                . "WHEN anulada = FALSE AND neto < 0 THEN neto*-1 "
751
                . "else totaliva END as totaliva, ".
752
            " 0 as totalivaretenido, 0 as totalivapercibido, 0 as totalrentencionrenta, 0 as totalisrpercibido, 0 as totalisc, ".
753
            " 0 as totalotrosimpuestos, 0 as totalpropinalegal, ".
754
            " CASE WHEN tipo_pago IS NULL OR tipo_pago = '' OR tipo_pago = '17' THEN neto else 0 END as totalefectivo, ".
755
            " CASE WHEN tipo_pago = '18' THEN neto else 0 END as totalcheque, ".
756
            " CASE WHEN tipo_pago = '19' THEN neto else 0 END as totaltarjeta, ".
757
            " CASE WHEN tipo_pago = '20' THEN neto else 0 END as totalcredito, ".
758
            " CASE WHEN tipo_pago = '21' THEN neto else 0 END as totalbonos, ".
759
            " CASE WHEN tipo_pago = '22' THEN neto else 0 END as totalpermuta, ".
760
            " CASE WHEN tipo_pago = '23' THEN neto else 0 END as totalotrasformas, ".
761
            " CASE WHEN estado THEN 'Activo' ELSE 'Anulado' END as estado, ".
762
            " codpago ".
763
            " FROM ncf_ventas as nv JOIN facturascli as f on (f.idfactura = nv.documento)".
764
            " WHERE idempresa = ".$this->empresa->intval($this->empresa->id)." AND ".
765
            " nv.fecha between ".$this->empresa->var2str(\date("Y-m-d", strtotime($this->fecha_inicio))).
766
            " AND ".$this->empresa->var2str(\date("Y-m-d", strtotime($this->fecha_fin))).
767
            " AND nv.codalmacen IN ('".$almacenes."') ".
768
            " ORDER BY nv.codalmacen,nv.".$this->sort." ".$this->order;
769
        $sql_cantidad = "SELECT count(*) as total FROM ( ".$sql_607." ) as t1;";
770
        $data_cantidad = $this->db->select($sql_cantidad);
771
        $sql_resumen = "SELECT sum(totaliva) as totaliva, ".
772
                " sum(neto) as totalneto FROM (".
773
                $sql_607.") as t1;";
774
        $data_resumen = $this->db->select($sql_resumen);
775
        $sql_forma_pago = "SELECT codpago, sum(totaliva) as totaliva, ".
776
                " sum(neto) as totalneto FROM (".
777
                $sql_607.") as t1 group by codpago ORDER BY codpago;";
778
        $data_forma_pago = $this->db->select($sql_forma_pago);
779
        $this->total_forma_pago_dgii = array();
780
        if($data_forma_pago) {
781
            foreach($data_forma_pago as $fpago){
782
                $this->total_forma_pago_dgii[] = (object) $fpago;
783
            }
784
        }
785
        if ($json) {
786
            $resultados = $this->db->select_limit($sql_607, $this->limit, $this->offset);
787
        } else {
788
            $resultados = $this->db->select($sql_607);
789
            $this->totalDocumentos += $data_cantidad[0]['total'];
790
            $this->totalItbis += $data_resumen[0]['totaliva'];
791
            $this->totalNeto += $data_resumen[0]['totalneto'];
792
        }
793
        $total_informacion+=$data_cantidad[0]['total'];
794
        return array($resultados, $total_informacion);
795
    }
796
797
    public function dgii607()
798
    {
799
        $this->totalDocumentos = 0;
800
        $this->totalNeto = 0;
801
        $this->totalItbis = 0;
802
        $this->resultados_607 = array();
803
        $this->resultados_607 = $this->datos_reporte($this->reporte);
804
        $this->total_resultados_607 = 0;
805
        $this->generar_excel(
806
            array('RNC/Cédula','Tipo Id','NCF','NCF Modifica','Tipo de Ingreso','Fecha Comprobante','Fecha Retención','Monto Facturado','ITBIS Facturado','ITBIS Retenido por Terceros','ITBIS Percibido','Retención Renta por Terceros','ISR Percibido','Impuesto Selectivo al Consumo','Otros Impuestos/Tasas','Monto Propina Legal','Efectivo','Cheque/Transferencia/Depósito','Tarjeta Débito/Crédito','Venta a Crédito','Bonos o Certificados de Regalo','Permuta','Otras Formas de Ventas','Estado','F. Pago'),
0 ignored issues
show
Bug introduced by
array('RNC/Cédula', 'Ti...', 'Estado', 'F. Pago') of type array<integer,string> is incompatible with the type type expected by parameter $cabecera of informes_fiscales::generar_excel(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

806
            /** @scrutinizer ignore-type */ array('RNC/Cédula','Tipo Id','NCF','NCF Modifica','Tipo de Ingreso','Fecha Comprobante','Fecha Retención','Monto Facturado','ITBIS Facturado','ITBIS Retenido por Terceros','ITBIS Percibido','Retención Renta por Terceros','ISR Percibido','Impuesto Selectivo al Consumo','Otros Impuestos/Tasas','Monto Propina Legal','Efectivo','Cheque/Transferencia/Depósito','Tarjeta Débito/Crédito','Venta a Crédito','Bonos o Certificados de Regalo','Permuta','Otras Formas de Ventas','Estado','F. Pago'),
Loading history...
807
            $this->resultados_607,
808
            array('Total',count($this->resultados_607).' Documentos','','','','','','','','','','','','','','','','','','','','','','',''),
0 ignored issues
show
Bug introduced by
array('Total', count($th...'', '', '', '', '', '') of type array<integer,string> is incompatible with the type type expected by parameter $pie of informes_fiscales::generar_excel(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

808
            /** @scrutinizer ignore-type */ array('Total',count($this->resultados_607).' Documentos','','','','','','','','','','','','','','','','','','','','','','',''),
Loading history...
809
            false,
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type type expected by parameter $estilo_cab of informes_fiscales::generar_excel(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

809
            /** @scrutinizer ignore-type */ false,
Loading history...
810
            array(array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),
0 ignored issues
show
Bug introduced by
array(array('halign' => ...ay('halign' => 'left')) of type array<integer,array<string,string>> is incompatible with the type type expected by parameter $estilo_datos of informes_fiscales::generar_excel(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

810
            /** @scrutinizer ignore-type */ array(array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),
Loading history...
811
                array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'right'),
812
                array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'right'),
813
                array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'right'),
814
                array('halign'=>'right'),array('halign'=>'right'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),
815
                array('halign'=>'left')),
816
            false
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type type expected by parameter $estilo_pie of informes_fiscales::generar_excel(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

816
            /** @scrutinizer ignore-type */ false
Loading history...
817
        );
818
    }
819
820
    public function reporte608($almacenes, $json)
821
    {
822
        $total_informacion = 0;
823
        $sql_608 = "SELECT ncf, ".
824
            " concat(extract(year from nv.fecha),lpad(CAST(extract(month from nv.fecha) as char),2,'0'),lpad(CAST(extract(day from nv.fecha) as char),2,'0')) as fecha,".
825
            " motivo,".
826
            " CASE WHEN estado THEN 'Activo' ELSE 'Anulado' END as estado  FROM ncf_ventas as nv ".
827
            " WHERE idempresa = ".$this->empresa->intval($this->empresa->id)." AND ".
828
            " fecha between ".$this->empresa->var2str(\date("Y-m-d", strtotime($this->fecha_inicio))).
829
            " AND ".$this->empresa->var2str(\date("Y-m-d", strtotime($this->fecha_fin))).
830
            " AND codalmacen IN ('".$almacenes."') and estado = false ".
831
            " ORDER BY codalmacen,".$this->sort." ".$this->order;
832
        $sql_cantidad = "SELECT count(*) as total FROM ( ".$sql_608." ) as t1;";
833
        $data_cantidad = $this->db->select($sql_cantidad);
834
        if ($json) {
835
            $resultados = $this->db->select_limit($sql_608, $this->limit, $this->offset);
836
        } else {
837
            $resultados = $this->db->select($sql_608);
838
        }
839
        $total_informacion+=$data_cantidad[0]['total'];
840
        return array($resultados, $total_informacion);
841
    }
842
843
    public function dgii608()
844
    {
845
        $this->totalDocumentos = 0;
846
        $this->resultados_608 = array();
847
        $this->resultados_608 = $this->datos_reporte($this->reporte);
848
        $this->total_resultados_608 = 0;
849
        $this->generar_excel(
850
            array('NCF','Fecha','Motivo','Estado'),
0 ignored issues
show
Bug introduced by
array('NCF', 'Fecha', 'Motivo', 'Estado') of type array<integer,string> is incompatible with the type type expected by parameter $cabecera of informes_fiscales::generar_excel(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

850
            /** @scrutinizer ignore-type */ array('NCF','Fecha','Motivo','Estado'),
Loading history...
851
            $this->resultados_608,
852
            array('Total',count($this->resultados_608).' Documentos','',''),
0 ignored issues
show
Bug introduced by
array('Total', count($th... ' Documentos', '', '') of type array<integer,string> is incompatible with the type type expected by parameter $pie of informes_fiscales::generar_excel(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

852
            /** @scrutinizer ignore-type */ array('Total',count($this->resultados_608).' Documentos','',''),
Loading history...
853
            false,
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type type expected by parameter $estilo_cab of informes_fiscales::generar_excel(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

853
            /** @scrutinizer ignore-type */ false,
Loading history...
854
            array(array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left')),
0 ignored issues
show
Bug introduced by
array(array('halign' => ...ay('halign' => 'left')) of type array<integer,array<string,string>> is incompatible with the type type expected by parameter $estilo_datos of informes_fiscales::generar_excel(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

854
            /** @scrutinizer ignore-type */ array(array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left'),array('halign'=>'left')),
Loading history...
855
            false
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type type expected by parameter $estilo_pie of informes_fiscales::generar_excel(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

855
            /** @scrutinizer ignore-type */ false
Loading history...
856
        );
857
    }
858
859
    public function facturas_proveedor($desde, $hasta, $codalmacen)
860
    {
861
        $lista = array();
862
        $sql = "SELECT * FROM facturasprov ".
863
            " WHERE codalmacen = ".$this->empresa->var2str($codalmacen).
864
            " AND fecha between ".$this->empresa->var2str($desde)." AND ".$this->empresa->var2str($hasta).
865
            " ORDER BY fecha, idfactura;";
866
        $data = $this->db->select($sql);
867
        if ($data) {
868
            foreach ($data as $d) {
869
                $item = new factura_proveedor($d);
870
                $lista[] = $item;
871
            }
872
        }
873
        return $lista;
874
    }
875
876
    public function factura_modifica_proveedor($idfactura)
877
    {
878
        $sql = "SELECT idfactura,numproveedor from facturasprov WHERE idfactura = ".$this->empresa->intval($idfactura);
879
        return $this->db->select($sql);
880
    }
881
882
    /**
883
     *
884
     * @param type $cabecera
885
     * @param type $datos
886
     * @param type $pie
887
     * @param type $estilo_cab
888
     * @param type $estilo_datos
889
     * @param type $estilo_pie
890
     */
891
    public function generar_excel($cabecera, $datos, $pie, $estilo_cab, $estilo_datos, $estilo_pie)
892
    {
893
        if ($datos) {
0 ignored issues
show
introduced by
$datos is of type type, thus it always evaluated to true.
Loading history...
894
            //Revisamos que no haya un archivo ya cargado
895
            $archivo = str_replace("-", "_", $this->reporte);
896
            $this->archivoXLSX = $this->exportDir . DIRECTORY_SEPARATOR . $archivo . "_" . $this->user->nick . ".xlsx";
897
            $this->archivoXLSXPath = $this->publicPath . DIRECTORY_SEPARATOR . $archivo . "_" . $this->user->nick . ".xlsx";
898
            if (file_exists($this->archivoXLSX)) {
899
                unlink($this->archivoXLSX);
900
            }
901
            //Variables para cada parte del excel
902
            $estilo_cabecera = ($estilo_cab)?$estilo_cab:array('border'=>'left,right,top,bottom','font-style'=>'bold');
0 ignored issues
show
introduced by
$estilo_cab is of type type, thus it always evaluated to true.
Loading history...
903
            $estilo_cuerpo = ($estilo_datos)?$estilo_datos:array('halign'=>'none');
0 ignored issues
show
introduced by
$estilo_datos is of type type, thus it always evaluated to true.
Loading history...
904
            $estilo_footer = ($estilo_pie)?$estilo_pie:array('border'=>'left,right,top,bottom','font-style'=>'bold','color'=>'#FFFFFF','fill'=>'#000000');
0 ignored issues
show
introduced by
$estilo_pie is of type type, thus it always evaluated to true.
Loading history...
905
            //Inicializamos la clase
906
            $this->writer = new XLSXWriter();
0 ignored issues
show
Bug introduced by
The type XLSXWriter 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...
907
            $this->writer->setAuthor('FacturaScripts '.\date('Y-m-d H:i:s'));
908
            $nombre_hoja = ucfirst(str_replace('-', ' ', $this->reporte));
909
            $this->writer->writeSheetHeader($nombre_hoja, array(), true);
910
            $this->writer->writeSheetRow($nombre_hoja, $cabecera, $estilo_cabecera);
911
            foreach ($datos as $linea) {
912
                $this->writer->writeSheetRow($nombre_hoja, (array) $linea, $estilo_cuerpo);
913
            }
914
            
915
            if (!empty($pie)) {
916
                $this->writer->writeSheetRow($nombre_hoja, (array) $pie, $estilo_footer);
917
            }
918
            $this->writer->writeToFile($this->archivoXLSX);
919
        }
920
    }
921
    
922
    private function share_extensions()
923
    {
924
        $extensiones = array(
925
            array(
926
                'name' => '001_informes_fiscales_js',
927
                'page_from' => __CLASS__,
928
                'page_to' => __CLASS__,
929
                'type' => 'head',
930
                'text' => '<script src="' . FS_PATH . 'plugins/republica_dominicana/view/js/plugins/validator.min.js" type="text/javascript"></script>',
0 ignored issues
show
Bug introduced by
The constant FS_PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
931
                'params' => ''
932
            ),
933
            array(
934
                'name' => '002_informes_fiscales_js',
935
                'page_from' => __CLASS__,
936
                'page_to' => __CLASS__,
937
                'type' => 'head',
938
                'text' => '<script src="' . FS_PATH . 'plugins/republica_dominicana/view/js/bootstrap-select.min.js" type="text/javascript"></script>',
939
                'params' => ''
940
            ),
941
            array(
942
                'name' => '003_informes_fiscales_js',
943
                'page_from' => __CLASS__,
944
                'page_to' => __CLASS__,
945
                'type' => 'head',
946
                'text' => '<script src="' . FS_PATH . 'plugins/republica_dominicana/view/js/bootstrap-table.min.js" type="text/javascript"></script>',
947
                'params' => ''
948
            ),
949
            array(
950
                'name' => '004_informes_fiscales_js',
951
                'page_from' => __CLASS__,
952
                'page_to' => __CLASS__,
953
                'type' => 'head',
954
                'text' => '<script src="' . FS_PATH . 'plugins/republica_dominicana/view/js/locale/bootstrap-table-es-MX.min.js" type="text/javascript"></script>',
955
                'params' => ''
956
            ),
957
            array(
958
                'name' => '005_informes_fiscales_js',
959
                'page_from' => __CLASS__,
960
                'page_to' => __CLASS__,
961
                'type' => 'head',
962
                'text' => '<script src="' . FS_PATH . 'plugins/republica_dominicana/view/js/plugins/bootstrap-table-filter.min.js" type="text/javascript"></script>',
963
                'params' => ''
964
            ),
965
            array(
966
                'name' => '006_informes_fiscales_js',
967
                'page_from' => __CLASS__,
968
                'page_to' => __CLASS__,
969
                'type' => 'head',
970
                'text' => '<script src="' . FS_PATH . 'plugins/republica_dominicana/view/js/plugins/bootstrap-table-toolbar.min.js" type="text/javascript"></script>',
971
                'params' => ''
972
            ),
973
            array(
974
                'name' => '007_informes_fiscales_js',
975
                'page_from' => __CLASS__,
976
                'page_to' => __CLASS__,
977
                'type' => 'head',
978
                'text' => '<script src="' . FS_PATH . 'plugins/republica_dominicana/view/js/plugins/bootstrap-table-mobile.min.js" type="text/javascript"></script>',
979
                'params' => ''
980
            ),
981
            array(
982
                'name' => '001_informes_fiscales_css',
983
                'page_from' => __CLASS__,
984
                'page_to' => __CLASS__,
985
                'type' => 'head',
986
                'text' => '<link rel="stylesheet" type="text/css" media="screen" href="' . FS_PATH . 'plugins/republica_dominicana/view/css/bootstrap-select.min.css"/>',
987
                'params' => ''
988
            ),
989
990
            array(
991
                'name' => '002_informes_fiscales_css',
992
                'page_from' => __CLASS__,
993
                'page_to' => __CLASS__,
994
                'type' => 'head',
995
                'text' => '<link rel="stylesheet" type="text/css" media="screen" href="' . FS_PATH . 'plugins/republica_dominicana/view/css/bootstrap-table.min.css"/>',
996
                'params' => ''
997
            ),
998
        );
999
1000
        foreach ($extensiones as $ext) {
1001
            $fext = new fs_extension($ext);
0 ignored issues
show
Bug introduced by
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...
1002
            if (!$fext->save()) {
1003
                $this->new_error_msg('Imposible guardar los datos de la extensión ' . $ext['name'] . '.');
1004
            }
1005
        }
1006
    }
1007
1008
    /**
1009
     * @url http://snippets.khromov.se/convert-comma-separated-values-to-array-in-php/
1010
     * @param $string - Input string to convert to array
0 ignored issues
show
Documentation Bug introduced by
The doc comment - at position 0 could not be parsed: Unknown type name '-' at position 0 in -.
Loading history...
1011
     * @param string $separator - Separator to separate by (default: ,)
1012
     *
1013
     * @return array
1014
     */
1015
    private function comma_separated_to_array($string, $separator = ',')
0 ignored issues
show
Unused Code introduced by
The method comma_separated_to_array() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
1016
    {
1017
        //Explode on comma
1018
        $vals = explode($separator, $string);
1019
1020
        //Trim whitespace
1021
        foreach ($vals as $key => $val) {
1022
            $vals[$key] = trim($val);
1023
        }
1024
        //Return empty array if no items found
1025
        //http://php.net/manual/en/function.explode.php#114273
1026
        return array_diff($vals, array(""));
1027
    }
1028
}
1029