mirror of
https://github.com/rmontanana/inventario2.git
synced 2025-08-17 16:35:58 +00:00
resolves #2
Modificada la Clase InformePDF para poder hacer informes con varias tablas.
This commit is contained in:
@@ -214,6 +214,8 @@ class AportaContenido {
|
|||||||
if ($this->perfil['Informe']) {
|
if ($this->perfil['Informe']) {
|
||||||
$enlace = 'xml/informe' . ucfirst($opcion) . '.xml';
|
$enlace = 'xml/informe' . ucfirst($opcion) . '.xml';
|
||||||
$informe = new InformePDF($this->bdd, $enlace, $this->registrado);
|
$informe = new InformePDF($this->bdd, $enlace, $this->registrado);
|
||||||
|
$informe->crea($enlace);
|
||||||
|
$informe->cierraPDF();
|
||||||
$informe->imprimeInforme();
|
$informe->imprimeInforme();
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
|
@@ -52,8 +52,10 @@ class InformeInventario {
|
|||||||
$plantilla = str_replace("{Descripcion}", utf8_encode($fila['Descripcion']), $plantilla);
|
$plantilla = str_replace("{Descripcion}", utf8_encode($fila['Descripcion']), $plantilla);
|
||||||
file_put_contents($salida, $plantilla) or die('Fallo en la escritura de la plantilla ' . $salida);
|
file_put_contents($salida, $plantilla) or die('Fallo en la escritura de la plantilla ' . $salida);
|
||||||
$informe = new InformePDF($this->bdd, $salida, true);
|
$informe = new InformePDF($this->bdd, $salida, true);
|
||||||
|
$informe->crea($salida);
|
||||||
|
$informe->cierraPDF();
|
||||||
$informe->guardaArchivo("tmp/Informe.pdf");
|
$informe->guardaArchivo("tmp/Informe.pdf");
|
||||||
echo '<script type="text/javascript"> window.open( "Informe.pdf" ) </script>';
|
echo '<script type="text/javascript"> window.open( "tmp/Informe.pdf" ) </script>';
|
||||||
}
|
}
|
||||||
|
|
||||||
private function listarArticulo() {
|
private function listarArticulo() {
|
||||||
@@ -72,8 +74,10 @@ class InformeInventario {
|
|||||||
$plantilla = str_replace("{Modelo}", utf8_encode($fila['modelo']), $plantilla);
|
$plantilla = str_replace("{Modelo}", utf8_encode($fila['modelo']), $plantilla);
|
||||||
file_put_contents($salida, $plantilla) or die('Fallo en la escritura de la plantilla ' . $salida);
|
file_put_contents($salida, $plantilla) or die('Fallo en la escritura de la plantilla ' . $salida);
|
||||||
$informe = new InformePDF($this->bdd, $salida, true);
|
$informe = new InformePDF($this->bdd, $salida, true);
|
||||||
|
$informe->crea($salida);
|
||||||
|
$informe->cierraPDF();
|
||||||
$informe->guardaArchivo("tmp/Informe.pdf");
|
$informe->guardaArchivo("tmp/Informe.pdf");
|
||||||
echo '<script type="text/javascript"> window.open( "Informe.pdf" ) </script>';
|
echo '<script type="text/javascript"> window.open( "tmp/Informe.pdf" ) </script>';
|
||||||
}
|
}
|
||||||
|
|
||||||
private function listaUbicaciones() {
|
private function listaUbicaciones() {
|
||||||
@@ -135,21 +139,22 @@ class InformeInventario {
|
|||||||
}
|
}
|
||||||
//Utiliza un nuevo manejador de base de datos para poder hacer una consulta en los informes
|
//Utiliza un nuevo manejador de base de datos para poder hacer una consulta en los informes
|
||||||
$bdatos = new Sql(SERVIDOR, USUARIO, CLAVE, BASEDATOS);
|
$bdatos = new Sql(SERVIDOR, USUARIO, CLAVE, BASEDATOS);
|
||||||
$mezcla = new FPDF_Merge();
|
$primero = true;
|
||||||
$i = 0;
|
|
||||||
while ($fila = $this->bdd->procesaResultado()) {
|
while ($fila = $this->bdd->procesaResultado()) {
|
||||||
//$fila=$this->bdd->procesaResultado();
|
//$fila=$this->bdd->procesaResultado();
|
||||||
$plantilla = file_get_contents($fichero) or die('Fallo en la apertura de la plantilla ' . $fichero);
|
$plantilla = file_get_contents($fichero) or die('Fallo en la apertura de la plantilla ' . $fichero);
|
||||||
$plantilla = str_replace("{id}", $fila['id'], $plantilla);
|
$plantilla = str_replace("{id}", $fila['id'], $plantilla);
|
||||||
$plantilla = str_replace("{Descripcion}", utf8_encode($fila['Descripcion']), $plantilla);
|
$plantilla = str_replace("{Descripcion}", utf8_encode($fila['Descripcion']), $plantilla);
|
||||||
file_put_contents($salida, $plantilla) or die('Fallo en la escritura de la plantilla ' . $salida);
|
file_put_contents($salida, $plantilla) or die('Fallo en la escritura de la plantilla ' . $salida);
|
||||||
$informe = new InformePDF($bdatos, $salida, true);
|
if ($primero) {
|
||||||
$nombre = "tmp/sal" . $i++ . ".pdf";
|
$primero = false;
|
||||||
$informe->guardaArchivo($nombre);
|
$informe = new InformePDF($bdatos, $salida, true);
|
||||||
$mezcla->add($nombre);
|
}
|
||||||
|
$informe->crea($salida);
|
||||||
}
|
}
|
||||||
$nombre = "tmp/total.pdf";
|
$nombre = "tmp/total.pdf";
|
||||||
$mezcla->output($nombre);
|
$informe->cierraPDF();
|
||||||
|
$informe->imprimeInforme();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
217
InformePDF.php
217
InformePDF.php
@@ -1,112 +1,121 @@
|
|||||||
|
|
||||||
<?php
|
<?php
|
||||||
/**
|
|
||||||
* genera un documento PDF a partir de una descripción dada en un archivo XML
|
|
||||||
* @author Ricardo Montañana <rmontanana@gmail.com>
|
|
||||||
* @version 1.0
|
|
||||||
* @package Inventario
|
|
||||||
* @copyright Copyright (c) 2008, Ricardo Montañana
|
|
||||||
* @package Inventario
|
|
||||||
* @copyright Copyright (c) 2008, Ricardo Montañana Gómez
|
|
||||||
* @license http://www.gnu.org/licenses/gpl-3.0.txt
|
|
||||||
* This file is part of Inventario.
|
|
||||||
* Inventario is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* Inventario is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with Inventario. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
class InformePDF
|
/**
|
||||||
{
|
* genera un documento PDF a partir de una descripción dada en un archivo XML
|
||||||
|
* @author Ricardo Montañana <rmontanana@gmail.com>
|
||||||
|
* @version 1.0
|
||||||
|
* @package Inventario
|
||||||
|
* @copyright Copyright (c) 2008, Ricardo Montañana
|
||||||
|
* @package Inventario
|
||||||
|
* @copyright Copyright (c) 2008, Ricardo Montañana Gómez
|
||||||
|
* @license http://www.gnu.org/licenses/gpl-3.0.txt
|
||||||
|
* This file is part of Inventario.
|
||||||
|
* Inventario is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Inventario is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Inventario. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class InformePDF {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @var basedatos Controlador de la base de datos
|
* @var basedatos Controlador de la base de datos
|
||||||
*/
|
*/
|
||||||
private $bdd;
|
private $bdd;
|
||||||
private $docu;
|
private $docu;
|
||||||
|
private $pdf;
|
||||||
|
private $def;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* El constructor recibe como argumento el nombre del archivo XML con la definición, encargándose de recuperarla y guardar toda la información localmente
|
* El constructor recibe como argumento el nombre del archivo XML con la definición, encargándose de recuperarla y guardar toda la información localmente
|
||||||
* @param basedatos $bdd manejador de la base de datos
|
* @param basedatos $bdd manejador de la base de datos
|
||||||
* @param string $definicion fichero con la definición del informe en XML
|
* @param string $definicion fichero con la definición del informe en XML
|
||||||
* @param boolean $registrado usuario registrado si/no
|
* @param boolean $registrado usuario registrado si/no
|
||||||
* @return ficheroPDF
|
* @return ficheroPDF
|
||||||
*/
|
* todo: cambiar este comentario
|
||||||
public function __construct($bdd,$definicion,$registrado)
|
*/
|
||||||
{
|
public function __construct($bdd, $definicion, $registrado) {
|
||||||
if (!$registrado) {
|
if (!$registrado) {
|
||||||
return 'Debe registrarse para acceder a este apartado';
|
return 'Debe registrarse para acceder a este apartado';
|
||||||
}
|
|
||||||
$this->bdd=$bdd;
|
|
||||||
// Recuperamos la definición del informe
|
|
||||||
$def=simplexml_load_file($definicion);
|
|
||||||
//print_r($def);echo $bdd;die();
|
|
||||||
// Iniciamos la creación del documento
|
|
||||||
$pdf=new Pdf_mysql_table($this->bdd->obtieneManejador(),(string)$def->Pagina['Orientacion'],
|
|
||||||
(string)$def->Pagina['Formato'],
|
|
||||||
(string)$def->Titulo['Texto'],(string)$def->Pagina->Cabecera);
|
|
||||||
echo $def->Titulo.$def->Cabecera;
|
|
||||||
$pdf->Open();
|
|
||||||
$pdf->setAuthor(utf8_decode(AUTOR));
|
|
||||||
$pdf->setCreator(html_entity_decode(APLICACION));
|
|
||||||
$pdf->setSubject(utf8_decode($def->Titulo));
|
|
||||||
$pdf->setAutoPageBreak(true,10);
|
|
||||||
$this->bdd->ejecuta(trim($def->Datos->Consulta));
|
|
||||||
$filas=$this->bdd->procesaResultado();
|
|
||||||
$pdf->AddPage();
|
|
||||||
// Recuperamos los datos del cuerpo
|
|
||||||
foreach($def->Pagina->Cuerpo->Col as $columna) {
|
|
||||||
$pdf->AddCol((string)$columna['Nombre'],(string)$columna['Ancho'],
|
|
||||||
(string)$columna['Titulo'],(string)$columna['Ajuste'],
|
|
||||||
(string)$columna['Total']);
|
|
||||||
}
|
|
||||||
$prop=array('HeaderColor'=>array(255,150,100),
|
|
||||||
'color1'=>array(210,245,255),
|
|
||||||
'color2'=>array(255,255,210),
|
|
||||||
'padding'=>2);
|
|
||||||
$pdf->Table($def->Datos->Consulta,$prop);
|
|
||||||
$pdf->Close();
|
|
||||||
// Obtenemos el documento y su longitud
|
|
||||||
$documento=$pdf->Output('','S');
|
|
||||||
$this->docu=$documento;
|
|
||||||
}
|
|
||||||
public function getContenido()
|
|
||||||
{
|
|
||||||
return $this->docu;
|
|
||||||
}
|
|
||||||
public function getCabecera()
|
|
||||||
{
|
|
||||||
$cabecera = "Content-type: application/pdf";
|
|
||||||
$cabecera = $cabecera . "Content-length: " . strlen($this->docu);
|
|
||||||
$cabecera = $cabecera . "Content-Disposition: inline; filename=Informe.pdf";
|
|
||||||
return $cabecera;
|
|
||||||
}
|
|
||||||
public function guardaArchivo($nombre = "tmp/Informe.pdf")
|
|
||||||
{
|
|
||||||
$fichero = fopen($nombre, "w");
|
|
||||||
fwrite($fichero,$this->getCabecera());
|
|
||||||
fwrite($fichero,$this->getContenido(), strlen($this->getContenido()));
|
|
||||||
fclose($fichero);
|
|
||||||
}
|
|
||||||
public function enviaCabecera()
|
|
||||||
{
|
|
||||||
header("Content-type: application/pdf");
|
|
||||||
$longitud=strlen($this->docu);
|
|
||||||
header("Content-length: $longitud");
|
|
||||||
header("Content-Disposition: inline; filename=Informe.pdf");
|
|
||||||
}
|
|
||||||
public function imprimeInforme()
|
|
||||||
{
|
|
||||||
$this->enviaCabecera();
|
|
||||||
echo $this->docu;
|
|
||||||
}
|
}
|
||||||
|
// Recuperamos la definición del informe
|
||||||
|
$this->def = simplexml_load_file($definicion);
|
||||||
|
$this->bdd = $bdd;
|
||||||
|
$this->pdf = new Pdf_mysql_table($this->bdd->obtieneManejador(), (string) $this->def->Pagina['Orientacion'], (string) $this->def->Pagina['Formato'], (string) $this->def->Titulo['Texto'], (string) $this->def->Pagina->Cabecera);
|
||||||
|
//echo $def->Titulo.$def->Cabecera;
|
||||||
|
$this->pdf->Open();
|
||||||
|
$this->pdf->setAuthor(utf8_decode(AUTOR));
|
||||||
|
$this->pdf->setCreator(html_entity_decode(APLICACION));
|
||||||
|
$this->pdf->setSubject(utf8_decode($this->def->Titulo));
|
||||||
|
$this->pdf->setAutoPageBreak(true, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function crea($definicion) {
|
||||||
|
|
||||||
|
//print_r($def);echo $bdd;die();
|
||||||
|
// Iniciamos la creación del documento
|
||||||
|
$this->def = simplexml_load_file($definicion);
|
||||||
|
$this->pdf->setTitulo($this->def->Titulo['Texto']);
|
||||||
|
$this->pdf->iniciaTotales();
|
||||||
|
$this->bdd->ejecuta(trim($this->def->Datos->Consulta));
|
||||||
|
//$filas = $this->bdd->procesaResultado();
|
||||||
|
$this->pdf->AddPage();
|
||||||
|
// Recuperamos los datos del cuerpo
|
||||||
|
foreach ($this->def->Pagina->Cuerpo->Col as $columna) {
|
||||||
|
$this->pdf->AddCol((string) $columna['Nombre'], (string) $columna['Ancho'], (string) $columna['Titulo'], (string) $columna['Ajuste'], (string) $columna['Total']);
|
||||||
|
}
|
||||||
|
$prop = array('HeaderColor' => array(255, 150, 100),
|
||||||
|
'color1' => array(210, 245, 255),
|
||||||
|
'color2' => array(255, 255, 210),
|
||||||
|
'padding' => 2);
|
||||||
|
$this->pdf->Table($this->def->Datos->Consulta, $prop);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function cierraPDF() {
|
||||||
|
$this->pdf->Close();
|
||||||
|
$this->docu = $this->pdf->Output('', 'S');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getContenido() {
|
||||||
|
return $this->docu;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCabecera() {
|
||||||
|
$cabecera = "Content-type: application/pdf";
|
||||||
|
$cabecera = $cabecera . "Content-length: " . strlen($this->docu);
|
||||||
|
$cabecera = $cabecera . "Content-Disposition: inline; filename=tmp/Informe.pdf";
|
||||||
|
return $cabecera;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function guardaArchivo($nombre = "tmp/Informe.pdf") {
|
||||||
|
$fichero = fopen($nombre, "w");
|
||||||
|
fwrite($fichero, $this->getCabecera());
|
||||||
|
fwrite($fichero, $this->getContenido(), strlen($this->getContenido()));
|
||||||
|
fclose($fichero);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function enviaCabecera() {
|
||||||
|
header("Content-type: application/pdf");
|
||||||
|
$longitud = strlen($this->docu);
|
||||||
|
header("Content-length: $longitud");
|
||||||
|
header("Content-Disposition: inline; filename=tmp/Informe.pdf");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function imprimeInforme() {
|
||||||
|
$this->enviaCabecera();
|
||||||
|
echo $this->docu;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
@@ -127,6 +127,8 @@ class Inventario {
|
|||||||
$enlace = 'xml/informe' . ucfirst($opcion) . '.xml';
|
$enlace = 'xml/informe' . ucfirst($opcion) . '.xml';
|
||||||
//$enlace="tmp/inventarioUbicacion.xml";
|
//$enlace="tmp/inventarioUbicacion.xml";
|
||||||
$informe = new InformePDF($this->bdd, $enlace, $this->registrado);
|
$informe = new InformePDF($this->bdd, $enlace, $this->registrado);
|
||||||
|
$informe->crea($enlace);
|
||||||
|
$informe->cierraPDF();
|
||||||
$informe->imprimeInforme();
|
$informe->imprimeInforme();
|
||||||
return;
|
return;
|
||||||
default:
|
default:
|
||||||
|
@@ -51,7 +51,10 @@ class Pdf_mysql_table extends Fpdf
|
|||||||
{
|
{
|
||||||
$this->titulo=$titulo;
|
$this->titulo=$titulo;
|
||||||
}
|
}
|
||||||
|
public function iniciaTotales()
|
||||||
|
{
|
||||||
|
$this->totales = array();
|
||||||
|
}
|
||||||
function Header()
|
function Header()
|
||||||
{
|
{
|
||||||
//Modficada por Ricardo Montañana
|
//Modficada por Ricardo Montañana
|
||||||
|
Reference in New Issue
Block a user