Total Complexity | 144 |
Total Lines | 1027 |
Duplicated Lines | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
Complex classes like informe_facturas often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use informe_facturas, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
25 | class informe_facturas extends informe_albaranes |
||
26 | { |
||
27 | public $pais; |
||
28 | public $estado; |
||
29 | public $nombre_docs; |
||
30 | public $table_compras; |
||
31 | public $table_ventas; |
||
32 | public function __construct() |
||
33 | { |
||
34 | parent::__construct(__CLASS__, 'Facturas', 'informes'); |
||
35 | } |
||
36 | |||
37 | protected function private_core() |
||
38 | { |
||
39 | /// declaramos los objetos sólo para asegurarnos de que existen las tablas |
||
40 | new factura_cliente(); |
||
41 | new factura_proveedor(); |
||
42 | |||
43 | $this->nombre_docs = 'Facturas'; |
||
44 | $this->pais = new pais(); |
||
45 | $this->table_compras = 'facturasprov'; |
||
46 | $this->table_ventas = 'facturascli'; |
||
47 | |||
48 | parent::private_core(); |
||
49 | } |
||
50 | |||
51 | protected function generar_extra() |
||
52 | { |
||
53 | if ($_POST['generar'] === 'informe_compras') { |
||
54 | if ($_POST['unidades'] === 'TRUE') { |
||
55 | $this->informe_compras_unidades(); |
||
56 | } else { |
||
57 | $this->informe_compras(); |
||
58 | } |
||
59 | } elseif ($_POST['generar'] === 'informe_ventas') { |
||
60 | if ($_POST['unidades'] === 'TRUE') { |
||
61 | $this->informe_ventas_unidades(); |
||
62 | } else { |
||
63 | $this->informe_ventas(); |
||
64 | } |
||
65 | } |
||
66 | } |
||
67 | |||
68 | public function provincias() |
||
69 | { |
||
70 | return $this->fbase_sql_distinct('dirclientes', 'provincia'); |
||
71 | } |
||
72 | |||
73 | public function stats_series($tabla = 'facturasprov') |
||
74 | { |
||
75 | return parent::stats_series($tabla); |
||
76 | } |
||
77 | |||
78 | /** |
||
79 | * @param $tabla |
||
80 | * @return array |
||
81 | */ |
||
82 | public function stats_agentes($tabla = 'facturasprov') |
||
83 | { |
||
84 | return parent::stats_agentes($tabla); |
||
85 | } |
||
86 | |||
87 | public function stats_almacenes($tabla = 'facturasprov') |
||
88 | { |
||
89 | return parent::stats_almacenes($tabla); |
||
90 | } |
||
91 | |||
92 | public function stats_formas_pago($tabla = 'facturasprov') |
||
93 | { |
||
94 | return parent::stats_formas_pago($tabla); |
||
95 | } |
||
96 | |||
97 | public function stats_estados($tabla = 'facturasprov') |
||
98 | { |
||
99 | $stats = array(); |
||
100 | |||
101 | $where = $this->where_compras; |
||
102 | if ($tabla === $this->table_ventas) { |
||
103 | $where = $this->where_ventas; |
||
104 | } |
||
105 | |||
106 | /// aprobados |
||
107 | $sql = "select sum(neto) as total from " . $tabla; |
||
108 | $sql .= $where; |
||
109 | $sql .= " and idfactura is not null and anulada = false order by total desc;"; |
||
110 | |||
111 | $data = $this->db->select($sql); |
||
112 | if ($data && (float)$data[0]['total']) { |
||
113 | $stats[] = array( |
||
114 | 'txt' => 'facturado', |
||
115 | 'total' => round((float)$data[0]['total'], FS_NF0) |
||
116 | ); |
||
117 | } |
||
118 | |||
119 | /// pendientes |
||
120 | $sql = "select sum(neto) as total from " . $tabla; |
||
121 | $sql .= $where; |
||
122 | $sql .= " and idfactura is null and anulada = false order by total desc;"; |
||
123 | |||
124 | $data = $this->db->select($sql); |
||
125 | if ($data && (float)$data[0]['total']) { |
||
126 | $stats[] = array( |
||
127 | 'txt' => 'no facturado', |
||
128 | 'total' => round((float)$data[0]['total'], FS_NF0) |
||
129 | ); |
||
130 | } |
||
131 | |||
132 | return $stats; |
||
133 | } |
||
134 | |||
135 | protected function get_documentos($tabla) |
||
136 | { |
||
137 | $doclist = array(); |
||
138 | |||
139 | $where = $this->where_compras; |
||
140 | if ($tabla === $this->table_ventas) { |
||
141 | $where = $this->where_ventas; |
||
142 | } |
||
143 | |||
144 | $sql = "select * from " . $tabla . $where . " order by fecha asc, codigo asc;"; |
||
145 | $data = $this->db->select($sql); |
||
146 | if ($data) { |
||
147 | foreach ($data as $d) { |
||
148 | if ($tabla === $this->table_ventas) { |
||
149 | $sql = "SELECT * FROM lineasivafactcli WHERE idfactura = " . |
||
150 | $this->empresa->var2str($d['idfactura']) . " ORDER BY iva DESC"; |
||
151 | $dataiva = $this->db->select($sql); |
||
152 | if ($dataiva) { |
||
153 | $this->process_lineas_iva($doclist, $dataiva, $d, 'factura_cliente'); |
||
154 | } else { |
||
155 | $factura = new factura_cliente($d); |
||
156 | $factura->tasaiva = 0; |
||
157 | $factura->tasare = 0; |
||
158 | $doclist[] = $factura; |
||
159 | } |
||
160 | } else { |
||
161 | $sql = "SELECT * FROM lineasivafactprov WHERE idfactura = " . |
||
162 | $this->empresa->var2str($d['idfactura']) . " ORDER BY iva DESC"; |
||
163 | $dataiva = $this->db->select($sql); |
||
164 | if ($dataiva) { |
||
165 | $this->process_lineas_iva($doclist, $dataiva, $d, 'factura_proveedor'); |
||
166 | } else { |
||
167 | $factura = new factura_proveedor($d); |
||
168 | $factura->tasaiva = 0; |
||
169 | $factura->tasare = 0; |
||
170 | $doclist[] = $factura; |
||
171 | } |
||
172 | } |
||
173 | } |
||
174 | } |
||
175 | return $doclist; |
||
176 | } |
||
177 | |||
178 | /** |
||
179 | * A partir de los datos de lineasivafactcli (o prov) completamos el listado |
||
180 | * de facturas desglosando por tipo de iva. |
||
181 | * @param array $docList |
||
182 | * @param array $dataIVA |
||
183 | * @param array $dataFactura |
||
184 | * @param string $className |
||
185 | */ |
||
186 | private function process_lineas_iva(&$docList, &$dataIVA, &$dataFactura, $className) |
||
203 | } |
||
204 | } |
||
205 | |||
206 | /** |
||
207 | * Añade el desglose de impuestos al documento PDF. |
||
208 | * @param fs_pdf $pdf_doc |
||
209 | * @param string $tipo |
||
210 | */ |
||
211 | protected function desglose_impuestos_pdf(&$pdf_doc, $tipo) |
||
282 | } |
||
283 | } |
||
284 | |||
285 | /** |
||
286 | * @return void |
||
287 | */ |
||
288 | private function informe_compras() |
||
289 | { |
||
290 | $sql = "SELECT codproveedor,fecha,SUM(neto) as total FROM facturasprov" |
||
291 | . " WHERE fecha >= " . $this->empresa->var2str($this->desde) |
||
292 | . " AND anulada = false " |
||
398 | } |
||
399 | } |
||
400 | |||
401 | private function informe_ventas() |
||
402 | { |
||
403 | $sql = "SELECT codalmacen,codcliente,fecha,SUM(neto) as total FROM facturascli" |
||
404 | . " WHERE fecha >= " . $this->empresa->var2str($this->desde) |
||
405 | . " AND anulada = false " |
||
406 | . " AND fecha <= " . $this->empresa->var2str($this->hasta); |
||
407 | |||
408 | if ($_POST['codpais']) { |
||
409 | $sql .= " AND codpais = " . $this->empresa->var2str($_POST['codpais']); |
||
410 | } |
||
411 | |||
412 | if ($_POST['provincia']) { |
||
413 | $sql .= " AND lower(provincia) = lower(" . $this->empresa->var2str($_POST['provincia']) . ")"; |
||
414 | } |
||
415 | |||
416 | if ($this->cliente) { |
||
417 | $sql .= " AND codcliente = " . $this->empresa->var2str($this->cliente->codcliente); |
||
418 | } |
||
419 | |||
420 | if ($this->codserie) { |
||
421 | $sql .= " AND codserie = " . $this->empresa->var2str($this->codserie); |
||
422 | } |
||
423 | |||
424 | if ($this->codalmacen) { |
||
425 | $sql .= " AND codalmacen = " . $this->empresa->var2str($this->codalmacen); |
||
426 | } |
||
427 | |||
428 | if ($this->codagente) { |
||
429 | $sql .= " AND codagente = " . $this->empresa->var2str($this->codagente); |
||
430 | } |
||
431 | |||
432 | if ($_POST['minimo']) { |
||
433 | $sql .= " AND neto > " . $this->empresa->var2str($_POST['minimo']); |
||
434 | } |
||
435 | |||
436 | $sql .= " GROUP BY codalmacen,codcliente,fecha ORDER BY codcliente ASC, fecha DESC;"; |
||
437 | |||
438 | $data = $this->db->select($sql); |
||
439 | if ($data) { |
||
440 | $this->template = FALSE; |
||
441 | header("content-type:application/csv;charset=UTF-8"); |
||
442 | header("Content-Disposition: attachment; filename=\"informe_ventas.csv\""); |
||
443 | echo "almacen;codcliente;nombre;año;ene;feb;mar;abr;may;jun;jul;ago;sep;oct;nov;dic;total;%VAR\n"; |
||
444 | $cliente = new cliente(); |
||
445 | $stats = array(); |
||
446 | foreach ($data as $d) { |
||
447 | $anyo = date('Y', strtotime($d['fecha'])); |
||
448 | $mes = date('n', strtotime($d['fecha'])); |
||
449 | if (!isset($stats[$d['codcliente']][$anyo])) { |
||
450 | $stats[$d['codcliente']][$anyo] = [ |
||
451 | 1 => 0, |
||
452 | 2 => 0, |
||
453 | 3 => 0, |
||
454 | 4 => 0, |
||
455 | 5 => 0, |
||
456 | 6 => 0, |
||
457 | 7 => 0, |
||
458 | 8 => 0, |
||
459 | 9 => 0, |
||
460 | 10 => 0, |
||
461 | 11 => 0, |
||
462 | 12 => 0, |
||
463 | 13 => 0, |
||
464 | 14 => 0, |
||
465 | 15 => $d['codalmacen'] |
||
466 | ]; |
||
467 | } |
||
468 | |||
469 | $stats[$d['codcliente']][$anyo][$mes] += (float)$d['total']; |
||
470 | $stats[$d['codcliente']][$anyo][13] += (float)$d['total']; |
||
471 | } |
||
472 | |||
473 | $totales = array(); |
||
474 | foreach ($stats as $i => $value) { |
||
475 | /// calculamos la variación y los totales |
||
476 | $anterior = 0; |
||
477 | foreach (array_reverse($value, true) as $j => $value2) { |
||
478 | if ($anterior > 0) { |
||
479 | $value[$j][14] = ($value2[13] * 100 / $anterior) - 100; |
||
480 | } |
||
481 | |||
482 | $anterior = $value2[13]; |
||
483 | |||
484 | if (isset($totales[$j])) { |
||
485 | foreach ($value2 as $k => $value3) { |
||
486 | $totales[$j][$k] += $value3; |
||
487 | } |
||
488 | } else { |
||
489 | $totales[$j] = $value2; |
||
490 | } |
||
491 | } |
||
492 | |||
493 | $cli = $cliente->get($i); |
||
494 | foreach ($value as $j => $value2) { |
||
495 | if ($cli) { |
||
496 | echo '"' . $value[$j][15] . '";' . '"' . $i . '";' . fs_fix_html($cli->nombre) . ';' . $j; |
||
497 | } else { |
||
498 | echo '"' . $value[$j][15] . '";' . '"' . $i . '";-;' . $j; |
||
499 | } |
||
500 | |||
501 | foreach ($value2 as $x => $value3) { |
||
502 | if ($x < 15) { |
||
503 | echo ';' . $this->show_numero($value3, FS_NF0); |
||
504 | } |
||
505 | } |
||
506 | echo "\n"; |
||
507 | } |
||
508 | echo ";;;;;;;;;;;;;;;\n"; |
||
509 | } |
||
510 | foreach (array_reverse($totales, true) as $i => $value) { |
||
511 | echo ";TOTALES;" . $i; |
||
512 | $l_total = 0; |
||
513 | foreach ($value as $j => $value3) { |
||
514 | if ($j < 13) { |
||
515 | echo ';' . $this->show_numero($value3, FS_NF0); |
||
516 | } |
||
517 | } |
||
518 | echo ";" . $this->show_numero($l_total, FS_NF0) . ";\n"; |
||
519 | } |
||
520 | } else { |
||
521 | $this->new_error_msg('Sin resultados.'); |
||
522 | } |
||
523 | } |
||
524 | |||
525 | private function informe_compras_unidades() |
||
526 | { |
||
527 | $sql = "SELECT f.codalmacen,f.codproveedor,f.fecha,l.referencia,l.descripcion,SUM(l.cantidad) as total" |
||
528 | . " FROM facturasprov f, lineasfacturasprov l" |
||
529 | . " WHERE f.idfactura = l.idfactura AND l.referencia IS NOT NULL AND anulada = false " |
||
530 | . " AND f.fecha >= " . $this->empresa->var2str($this->desde) |
||
531 | . " AND f.fecha <= " . $this->empresa->var2str($this->hasta); |
||
532 | |||
533 | if ($this->codserie) { |
||
534 | $sql .= " AND f.codserie = " . $this->empresa->var2str($this->codserie); |
||
535 | } |
||
536 | |||
537 | if ($this->codalmacen) { |
||
538 | $sql .= " AND f.codalmacen = " . $this->empresa->var2str($this->codalmacen); |
||
539 | } |
||
540 | |||
541 | if ($this->codagente) { |
||
542 | $sql .= " AND f.codagente = " . $this->empresa->var2str($this->codagente); |
||
543 | } |
||
544 | |||
545 | if ($this->proveedor) { |
||
546 | $sql .= " AND codproveedor = " . $this->empresa->var2str($this->proveedor->codproveedor); |
||
547 | } |
||
548 | |||
549 | if ($_POST['minimo']) { |
||
550 | $sql .= " AND l.cantidad > " . $this->empresa->var2str($_POST['minimo']); |
||
551 | } |
||
552 | |||
553 | $sql .= " GROUP BY f.codalmacen,f.codproveedor,f.fecha,l.referencia,l.descripcion ORDER BY f.codproveedor ASC, l.referencia ASC, f.fecha DESC;"; |
||
554 | |||
555 | $data = $this->db->select($sql); |
||
556 | if ($data) { |
||
557 | $this->template = FALSE; |
||
558 | header("content-type:application/csv;charset=UTF-8"); |
||
559 | header("Content-Disposition: attachment; filename=\"informe_compras_unidades.csv\""); |
||
560 | echo "almacen;codproveedor;nombre;referencia;descripcion;año;ene;feb;mar;abr;may;jun;jul;ago;sep;oct;nov;dic;total;%VAR\n"; |
||
561 | |||
562 | $proveedor = new proveedor(); |
||
563 | $stats = array(); |
||
564 | |||
565 | foreach ($data as $d) { |
||
566 | $anyo = date('Y', strtotime($d['fecha'])); |
||
567 | $mes = date('n', strtotime($d['fecha'])); |
||
568 | if (!isset($stats[$d['codproveedor']][$d['referencia']][$anyo])) { |
||
569 | $stats[$d['codproveedor']][$d['referencia']][$anyo] = [ |
||
570 | 1 => 0, |
||
571 | 2 => 0, |
||
572 | 3 => 0, |
||
573 | 4 => 0, |
||
574 | 5 => 0, |
||
575 | 6 => 0, |
||
576 | 7 => 0, |
||
577 | 8 => 0, |
||
578 | 9 => 0, |
||
579 | 10 => 0, |
||
580 | 11 => 0, |
||
581 | 12 => 0, |
||
582 | 13 => 0, |
||
583 | 14 => 0, |
||
584 | 15 => $d['codalmacen'], |
||
585 | 16 => $d['descripcion'], |
||
586 | ]; |
||
587 | } |
||
588 | |||
589 | $stats[$d['codproveedor']][$d['referencia']][$anyo][$mes] += (float)$d['total']; |
||
590 | $stats[$d['codproveedor']][$d['referencia']][$anyo][13] += (float)$d['total']; |
||
591 | } |
||
592 | |||
593 | foreach ($stats as $i => $value) { |
||
594 | $pro = $proveedor->get($i); |
||
595 | foreach ($value as $j => $value2) { |
||
596 | /// calculamos la variación |
||
597 | $anterior = 0; |
||
598 | foreach (array_reverse($value2, true) as $k => $value3) { |
||
599 | if ($anterior > 0) { |
||
600 | $value2[$k][14] = ($value3[13] * 100 / $anterior) - 100; |
||
601 | } |
||
602 | $anterior = $value3[13]; |
||
603 | } |
||
604 | |||
605 | foreach ($value2 as $k => $value3) { |
||
606 | if ($pro) { |
||
607 | echo '"' . $value2[$k][15] . '";' . '"' . $i . '";' . fs_fix_html($pro->nombre) . ';"' . $j . '";' . '"' . $value2[$k][16] . '"' . ';' . $k; |
||
608 | } else { |
||
609 | echo '"' . $value2[$k][15] . '";' . '"' . $i . '";-;"' . $j . '";' . '"' . $value2[$k][16] . '"' . ';' . $k; |
||
610 | } |
||
611 | |||
612 | foreach ($value3 as $x => $value4) { |
||
613 | if ($x < 15) { |
||
614 | echo ';' . $this->show_numero($value4, FS_NF0); |
||
615 | } |
||
616 | } |
||
617 | echo "\n"; |
||
618 | } |
||
619 | echo ";;;;;;;;;;;;;;;\n"; |
||
620 | } |
||
621 | echo ";;;;;;;;;;;;;;;\n"; |
||
622 | } |
||
623 | } else { |
||
624 | $this->new_error_msg('Sin resultados.'); |
||
625 | } |
||
626 | } |
||
627 | |||
628 | private function informe_ventas_unidades() |
||
629 | { |
||
630 | $sql = "SELECT f.codalmacen,f.codcliente,f.fecha,l.referencia,l.descripcion,SUM(l.cantidad) as total" |
||
631 | . " FROM facturascli f, lineasfacturascli l" |
||
632 | . " WHERE f.idfactura = l.idfactura AND l.referencia IS NOT NULL AND anulada = false " |
||
633 | . " AND f.fecha >= " . $this->empresa->var2str($this->desde) |
||
634 | . " AND f.fecha <= " . $this->empresa->var2str($this->hasta); |
||
635 | |||
636 | if ($_POST['codpais']) { |
||
637 | $sql .= " AND f.codpais = " . $this->empresa->var2str($_POST['codpais']); |
||
638 | } |
||
639 | |||
640 | if ($_POST['provincia']) { |
||
641 | $sql .= " AND lower(f.provincia) = lower(" . $this->empresa->var2str($_POST['provincia']) . ")"; |
||
642 | } |
||
643 | |||
644 | if ($this->cliente) { |
||
645 | $sql .= " AND codcliente = " . $this->empresa->var2str($this->cliente->codcliente); |
||
646 | } |
||
647 | |||
648 | if ($this->codalmacen) { |
||
649 | $sql .= " AND f.codalmacen = " . $this->empresa->var2str($this->codalmacen); |
||
650 | } |
||
651 | |||
652 | if ($this->codserie) { |
||
653 | $sql .= " AND f.codserie = " . $this->empresa->var2str($this->codserie); |
||
654 | } |
||
655 | |||
656 | if ($this->codagente) { |
||
657 | $sql .= " AND f.codagente = " . $this->empresa->var2str($this->codagente); |
||
658 | } |
||
659 | |||
660 | if ($_POST['minimo']) { |
||
661 | $sql .= " AND l.cantidad > " . $this->empresa->var2str($_POST['minimo']); |
||
662 | } |
||
663 | |||
664 | $sql .= " GROUP BY f.codalmacen,f.codcliente,f.fecha,l.referencia,l.descripcion ORDER BY f.codcliente ASC, l.referencia ASC, f.fecha DESC;"; |
||
665 | |||
666 | $data = $this->db->select($sql); |
||
667 | if ($data) { |
||
668 | $this->template = FALSE; |
||
669 | |||
670 | header("content-type:application/csv;charset=UTF-8"); |
||
671 | header("Content-Disposition: attachment; filename=\"informe_ventas_unidades.csv\""); |
||
672 | echo "almacen;codcliente;nombre;referencia;descripcion;año;ene;feb;mar;abr;may;jun;jul;ago;sep;oct;nov;dic;total;%VAR\n"; |
||
673 | |||
674 | $cliente = new cliente(); |
||
675 | $stats = array(); |
||
676 | foreach ($data as $d) { |
||
677 | $anyo = date('Y', strtotime($d['fecha'])); |
||
678 | $mes = date('n', strtotime($d['fecha'])); |
||
679 | if (!isset($stats[$d['codcliente']][$d['referencia']][$anyo])) { |
||
680 | $stats[$d['codcliente']][$d['referencia']][$anyo] = array( |
||
681 | 1 => 0, |
||
682 | 2 => 0, |
||
683 | 3 => 0, |
||
684 | 4 => 0, |
||
685 | 5 => 0, |
||
686 | 6 => 0, |
||
687 | 7 => 0, |
||
688 | 8 => 0, |
||
689 | 9 => 0, |
||
690 | 10 => 0, |
||
691 | 11 => 0, |
||
692 | 12 => 0, |
||
693 | 13 => 0, |
||
694 | 14 => 0, |
||
695 | 15 => $d['codalmacen'], |
||
696 | 16 => $d['descripcion'], |
||
697 | ); |
||
698 | } |
||
699 | |||
700 | $stats[$d['codcliente']][$d['referencia']][$anyo][$mes] += (float)$d['total']; |
||
701 | $stats[$d['codcliente']][$d['referencia']][$anyo][13] += (float)$d['total']; |
||
702 | } |
||
703 | |||
704 | foreach ($stats as $i => $value) { |
||
705 | $cli = $cliente->get($i); |
||
706 | foreach ($value as $j => $value2) { |
||
707 | /// calculamos la variación |
||
708 | $anterior = 0; |
||
709 | foreach (array_reverse($value2, true) as $k => $value3) { |
||
710 | if ($anterior > 0) { |
||
711 | $value2[$k][14] = ($value3[13] * 100 / $anterior) - 100; |
||
712 | } |
||
713 | |||
714 | $anterior = $value3[13]; |
||
715 | } |
||
716 | |||
717 | foreach ($value2 as $k => $value3) { |
||
718 | if ($cli) { |
||
719 | echo '"' . $value2[$k][15] . '";' . '"' . $i . '";' . fs_fix_html($cli->nombre) . ';"' . $j . '";' . '"' . $value2[$k][16] . '"' . ';' . $k; |
||
720 | } else { |
||
721 | echo '"' . $value2[$k][15] . '";' . '"' . $i . '";-;"' . $j . '";' . '"' . $value2[$k][16] . '"' . ';' . $k; |
||
722 | } |
||
723 | |||
724 | foreach ($value3 as $x => $value4) { |
||
725 | if ($x < 15) { |
||
726 | echo ';' . $this->show_numero($value4, FS_NF0); |
||
727 | } |
||
728 | } |
||
729 | |||
730 | echo "\n"; |
||
731 | } |
||
732 | echo ";;;;;;;;;;;;;;;;\n"; |
||
733 | } |
||
734 | echo ";;;;;;;;;;;;;;;;\n"; |
||
735 | } |
||
736 | } else { |
||
737 | $this->new_error_msg('Sin resultados.'); |
||
738 | } |
||
739 | } |
||
740 | |||
741 | protected function ini_filters() |
||
742 | { |
||
743 | parent::ini_filters(); |
||
744 | |||
745 | $this->estado = FALSE; |
||
746 | if (isset($_REQUEST['estado'])) { |
||
747 | $this->estado = $_REQUEST['estado']; |
||
748 | } |
||
749 | } |
||
750 | |||
751 | protected function set_where() |
||
752 | { |
||
753 | parent::set_where(); |
||
754 | |||
755 | if ($this->estado) { |
||
756 | $estado = $this->estado === 'pagada' ? true : false; |
||
757 | $this->where_compras .= " AND pagada = " . $this->empresa->var2str($estado); |
||
758 | $this->where_ventas .= " AND pagada = " . $this->empresa->var2str($estado); |
||
759 | } |
||
760 | } |
||
761 | |||
762 | protected function generar_pdf($tipo = 'compra') |
||
920 | } |
||
921 | |||
922 | protected function generar_xls($tipo = 'compra') |
||
923 | { |
||
924 | /// desactivamos el motor de plantillas |
||
925 | $this->template = false; |
||
926 | |||
927 | header("Content-Disposition: attachment; filename=\"informe_" . $this->nombre_docs . "_" . time() . ".xlsx\""); |
||
928 | header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); |
||
929 | header('Content-Transfer-Encoding: binary'); |
||
930 | header('Cache-Control: must-revalidate'); |
||
931 | header('Pragma: public'); |
||
932 | |||
933 | $header = array( |
||
934 | 'serie' => 'string', |
||
935 | 'doc' => 'string', |
||
936 | FS_NUMERO2 => 'string', |
||
937 | 'num.proveedor' => 'string', |
||
938 | 'fecha' => 'string', |
||
939 | 'cliente' => 'string', |
||
940 | 'proveedor' => 'string', |
||
941 | FS_CIFNIF => 'string', |
||
942 | 'direccion' => 'string', |
||
943 | 'neto' => '#,##0.00;[RED]-#,##0.00', |
||
944 | 'tasaiva' => '#,##0.00;[RED]-#,##0.00', |
||
945 | FS_IVA => '#,##0.00;[RED]-#,##0.00', |
||
946 | 'tasare' => '#,##0.00;[RED]-#,##0.00', |
||
947 | 're' => '#,##0.00;[RED]-#,##0.00', |
||
948 | 'irpf' => '#,##0.00;[RED]-#,##0.00', |
||
949 | 'total' => '#,##0.00;[RED]-#,##0.00', |
||
950 | ); |
||
951 | |||
952 | if ($tipo === 'compra') { |
||
953 | $tabla = $this->table_compras; |
||
954 | unset($header[FS_NUMERO2]); |
||
955 | unset($header['cliente']); |
||
956 | } else { |
||
957 | $tabla = $this->table_ventas; |
||
958 | unset($header['num.proveedor']); |
||
959 | unset($header['proveedor']); |
||
960 | } |
||
961 | |||
962 | $writer = new XLSXWriter(); |
||
963 | $writer->setAuthor('FacturaScripts'); |
||
964 | $writer->writeSheetHeader($this->nombre_docs, $header); |
||
965 | |||
966 | foreach ($this->get_documentos($tabla) as $doc) { |
||
967 | $linea = array( |
||
968 | 'serie' => $doc->codserie, |
||
969 | 'doc' => $doc->codigo, |
||
970 | FS_NUMERO2 => '', |
||
971 | 'num.proveedor' => '', |
||
972 | 'fecha' => $doc->fecha, |
||
973 | 'cliente' => '', |
||
974 | 'proveedor' => '', |
||
975 | FS_CIFNIF => $doc->cifnif, |
||
976 | 'direccion' => $doc->direccion, |
||
977 | 'neto' => $doc->neto, |
||
978 | 'tasaiva' => $doc->tasaiva, |
||
979 | FS_IVA => $doc->totaliva, |
||
980 | 'tasare' => $doc->tasare, |
||
981 | 're' => $doc->totalrecargo, |
||
982 | 'irpf' => $doc->totalirpf, |
||
983 | 'total' => $doc->total, |
||
984 | ); |
||
985 | |||
986 | if ($tipo === 'compra') { |
||
987 | $linea['num.proveedor'] = $doc->numproveedor; |
||
988 | $linea['proveedor'] = $doc->nombre; |
||
989 | unset($linea[FS_NUMERO2]); |
||
990 | unset($linea['cliente']); |
||
991 | } else { |
||
992 | $linea[FS_NUMERO2] = $doc->numero2; |
||
993 | $linea['cliente'] = $doc->nombrecliente; |
||
994 | unset($linea['num.proveedor']); |
||
995 | unset($linea['proveedor']); |
||
996 | } |
||
997 | |||
998 | $writer->writeSheetRow($this->nombre_docs, $linea); |
||
999 | } |
||
1000 | |||
1001 | $writer->writeToStdOut(); |
||
1002 | } |
||
1003 | |||
1004 | protected function generar_csv($tipo = 'compra') |
||
1052 | } |
||
1053 | } |
||
1054 | } |
||
1055 |