diff --git a/EtiquetasPDF.php b/EtiquetasPDF.php
new file mode 100644
index 0000000..71cda4e
--- /dev/null
+++ b/EtiquetasPDF.php
@@ -0,0 +1,175 @@
+
+
+ * @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 .
+ *
+ */
+require_once 'phpqrcode.php';
+
+class EtiquetasPDF {
+
+ /**
+ *
+ * @var basedatos Controlador de la base de datos
+ */
+ private $bdd;
+ 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
+ * @param basedatos $bdd manejador de la base de datos
+ * @param string $definicion fichero con la definición del informe en XML
+ * @param boolean $registrado usuario registrado si/no
+ * @return ficheroPDF
+ * todo: cambiar este comentario
+ */
+ public function __construct($bdd, $definicion, $registrado)
+ {
+ if (!$registrado) {
+ return 'Debe registrarse para acceder a este apartado';
+ }
+ // Recuperamos la definición del informe
+ $this->def = simplexml_load_file($definicion);
+ $this->bdd = $bdd;
+ $this->pdf = new FPDF();
+ $this->pdf->SetMargins(0.2, 0.2, 0.2);
+ $this->pdf->SetFont('Arial', '', 11);
+ //echo $def->Titulo.$def->Cabecera;
+ $this->pdf->setAuthor(AUTOR, true);
+ $creador = CENTRO . " " . PROGRAMA . VERSION;
+ $this->pdf->setCreator(html_entity_decode($creador), true);
+ $this->pdf->setSubject($this->def->Titulo, true);
+ //$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->bdd->ejecuta(trim($this->def->Datos->Consulta));
+ //Ejecuta la consulta y prepara las variables de la base de datos.
+ //$this->bdd->ejecuta(trim($this->def->Datos->Consulta));
+ //Inicializa las variables para el control de las etiquetas.
+ $this->pdf->AddPage();
+ $tamLinea = 5;
+ $fila = -1;
+ $primero = true; $i = 0;
+ $url = split("/", $_SERVER['SCRIPT_NAME']);
+ $aplicacion = $url[1];
+ $enlace = "http://".$_SERVER['SERVER_NAME']."/".$aplicacion."/index.php?elementos&opc=editar&id=";
+ while($tupla = $this->bdd->procesaResultado()) {
+ if ($i % 2) {
+ //Columna 2
+ $etiq1 = 136;
+ $etiq2 = 105;
+ } else {
+ //Columna 1
+ $etiq1 = 30;
+ $etiq2 = 1;
+ $fila++;
+ }
+ if ($i % 14 == 0) {
+ if (!$primero) {
+ $this->pdf->AddPage();
+ $fila = 0;
+ }
+ $primero = false;
+ }
+ $py = 6 + 39 * $fila;
+ $enlace2=$enlace.$tupla['idEl'];
+ $fichero = "tmp/etiq".rand(1000,9999).".png";
+ QRcode::png($enlace2, $fichero);
+ $this->pdf->image($fichero, $etiq2, $py, 30, 30);
+ unlink($fichero);
+ $this->pdf->setxy($etiq1, $py);
+ $this->pdf->Cell(30, 10, utf8_decode($tupla['descripcion']));
+ $py+=$tamLinea;
+ $this->pdf->setxy($etiq1, $py);
+ $this->pdf->Cell(30, 10, utf8_decode($tupla['marca']));
+ $py+=$tamLinea;
+ $this->pdf->setxy($etiq1, $py);
+ $this->pdf->Cell(30, 10, utf8_decode($tupla['modelo']));
+ $py+=$tamLinea;
+ $this->pdf->setxy($etiq1, $py);
+ $this->pdf->Cell(30, 10, utf8_decode($tupla['numserie']));
+ $py+=$tamLinea;
+ $this->pdf->setxy($etiq1, $py);
+ $this->pdf->Cell(30, 10, $tupla['fechaCompra']);
+ $py+=$tamLinea;
+ $this->pdf->setxy($etiq2, $py);
+ $cadena = "idElemento=" . $tupla['idEl'] . " / idArticulo=" . $tupla['idArt'] . " / idUbicacion=" . $tupla['idUbic'];
+ $this->pdf->Cell(30, 10, $cadena);
+ $i++;
+ }
+ //$this->pdf->MultiCell(0,30,var_export($filas,true));
+ }
+
+ 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;
+ }
+
+}
+
+?>
diff --git a/InformeInventario.php b/InformeInventario.php
index fffee4e..678cd5d 100644
--- a/InformeInventario.php
+++ b/InformeInventario.php
@@ -40,12 +40,19 @@ class InformeInventario {
private function listarUbicacion() {
$salidaInforme = isset($_POST['salida']) ? $_POST['salida'] : 'pantalla';
- if ($salidaInforme == "pantalla") {
- $fichero = "xml/inventarioUbicacion.xml";
- $salida = "tmp/inventarioUbicacion.xml";
- } else {
- $fichero = "xml/inventarioUbicacionCSV.xml";
- $salida = "tmp/inventarioUbicacionCSV.xml";
+ switch ($salidaInforme) {
+ case "pantalla":
+ $fichero = "xml/inventarioUbicacion.xml";
+ $salida = "tmp/inventarioUbicacion.xml";
+ break;
+ case "csv":
+ $fichero = "xml/inventarioUbicacionCSV.xml";
+ $salida = "tmp/inventarioUbicacionCSV.xml";
+ break;
+ case "etiquetas":
+ $fichero = "xml/inventarioUbicacionEtiquetas.xml";
+ $salida = "tmp/inventarioUbicacionEtiquetas.xml";
+ break;
}
$plantilla = file_get_contents($fichero) or die('Fallo en la apertura de la plantilla ' . $fichero);
$id = $_POST['id'] == NULL ? $_GET['id'] : $_POST['id'];
@@ -58,30 +65,47 @@ class InformeInventario {
$plantilla = str_replace("{id}", $id, $plantilla);
$plantilla = str_replace("{Descripcion}", $fila['Descripcion'], $plantilla);
file_put_contents($salida, $plantilla) or die('Fallo en la escritura de la plantilla ' . $salida);
- if ($salidaInforme == "pantalla") {
- $informe = new InformePDF($this->bdd, $salida, true);
- $informe->crea($salida);
- $informe->cierraPDF();
- $informe->guardaArchivo("tmp/Informe.pdf");
- echo '';
- } else {
- //Genera una hoja de cálculo en formato csv
- $nombre = "tmp/Ubicacion" . strftime("%Y%m%d") . rand(100, 999) . ".csv";
- $hoja = new Csv($this->bdd);
- $hoja->crea($nombre);
- $hoja->ejecutaConsulta($salida);
- echo '';
+ switch ($salidaInforme) {
+ case "pantalla":
+ $informe = new InformePDF($this->bdd, $salida, true);
+ $informe->crea($salida);
+ $informe->cierraPDF();
+ $informe->guardaArchivo("tmp/Informe.pdf");
+ echo '';
+ break;
+ case "csv":
+ //Genera una hoja de cálculo en formato csv
+ $nombre = "tmp/Ubicacion" . strftime("%Y%m%d") . rand(100, 999) . ".csv";
+ $hoja = new Csv($this->bdd);
+ $hoja->crea($nombre);
+ $hoja->ejecutaConsulta($salida);
+ echo '';
+ break;
+ case "etiquetas":
+ $etiquetas = new EtiquetasPDF($this->bdd, $salida, true);
+ $etiquetas->crea($salida);
+ $etiquetas->cierraPDF();
+ $etiquetas->guardaArchivo("tmp/EtiquetasUbicacion.pdf");
+ echo '';
+ break;
}
}
private function listarArticulo() {
$salidaInforme = isset($_POST['salida']) ? $_POST['salida'] : 'pantalla';
- if ($salidaInforme == "pantalla") {
- $fichero = "xml/inventarioArticulo.xml";
- $salida = "tmp/inventarioArticulo.xml";
- } else {
- $fichero = "xml/inventarioArticuloCSV.xml";
- $salida = "tmp/inventarioArticuloCSV.xml";
+ switch ($salidaInforme) {
+ case "pantalla":
+ $fichero = "xml/inventarioArticulo.xml";
+ $salida = "tmp/inventarioArticulo.xml";
+ break;
+ case "csv":
+ $fichero = "xml/inventarioArticuloCSV.xml";
+ $salida = "tmp/inventarioArticuloCSV.xml";
+ break;
+ case "etiquetas":
+ $fichero = "xml/inventarioArticuloEtiquetas.xml";
+ $salida = "tmp/inventarioArticuloEtiquetas.xml";
+ break;
}
$plantilla = file_get_contents($fichero) or die('Fallo en la apertura de la plantilla ' . $fichero);
$id = $_POST['id'] == NULL ? $_GET['id'] : $_POST['id'];
@@ -96,21 +120,30 @@ class InformeInventario {
$plantilla = str_replace("{Marca}", $fila['marca'], $plantilla);
$plantilla = str_replace("{Modelo}", $fila['modelo'], $plantilla);
file_put_contents($salida, $plantilla) or die('Fallo en la escritura de la plantilla ' . $salida);
- if ($salidaInforme == "pantalla") {
- $informe = new InformePDF($this->bdd, $salida, true);
- $informe->crea($salida);
- $informe->cierraPDF();
- $informe->guardaArchivo("tmp/Informe.pdf");
- echo '';
- } else {
- //Genera una hoja de cálculo en formato csv
- $nombre = "tmp/Articulo" . strftime("%Y%m%d") . rand(100, 999) . ".csv";
- $hoja = new Csv($this->bdd);
- $hoja->crea($nombre);
- $hoja->ejecutaConsulta($salida);
- echo '';
+ switch ($salidaInforme) {
+ case "pantalla":
+ $informe = new InformePDF($this->bdd, $salida, true);
+ $informe->crea($salida);
+ $informe->cierraPDF();
+ $informe->guardaArchivo("tmp/Informe.pdf");
+ echo '';
+ break;
+ case "csv":
+ //Genera una hoja de cálculo en formato csv
+ $nombre = "tmp/Articulo" . strftime("%Y%m%d") . rand(100, 999) . ".csv";
+ $hoja = new Csv($this->bdd);
+ $hoja->crea($nombre);
+ $hoja->ejecutaConsulta($salida);
+ echo '';
+ break;
+ case "etiquetas":
+ $etiquetas = new EtiquetasPDF($this->bdd, $salida, true);
+ $etiquetas->crea($salida);
+ $etiquetas->cierraPDF();
+ $etiquetas->guardaArchivo("tmp/EtiquetasArticulo.pdf");
+ echo '';
+ break;
}
- //header('Location: index.php');
}
private function listaUbicaciones() {
@@ -149,6 +182,7 @@ class InformeInventario {
$salida.="
";
$salida.='
';
$salida.='';
+ $salida.='';
$salida.="
";
$salida.='
' . "\n";
return $salida;
@@ -192,7 +226,6 @@ class InformeInventario {
$informe->cierraPDF();
$informe->imprimeInforme();
}
-
}
?>
diff --git a/InformeInventario2.php b/InformeInventario2.php
deleted file mode 100644
index f34b6bd..0000000
--- a/InformeInventario2.php
+++ /dev/null
@@ -1,147 +0,0 @@
-.
- *
- */
- class InformeInventario {
- private $bdd;
- public function __construct($baseDatos)
- {
- $this->bdd=$baseDatos;
- }
- public function ejecuta()
- {
- $opc=$_GET['opc'];
- switch ($opc) {
- case 'Ubicacion':return $this->formularioUbicacion();
- case 'listarUbicacion':return $this->listarUbicacion();
- case 'listarArticulo':return $this->listarArticulo();
- case 'Articulo':return $this->formularioArticulo();
- case 'Total':return $this->inventarioTotal();
- }
- }
- private function listarUbicacion()
- {
- $fichero="xml/inventarioUbicacion.xml";
- $salida="tmp/inventarioUbicacion.xml";
- $plantilla=file_get_contents($fichero)
- or die('Fallo en la apertura de la plantilla '.$fichero);
- $comando="select * from Ubicaciones where id='".$_POST['id']."';";
- $resultado=$this->bdd->ejecuta($comando);
- if (!$resultado) {
- return $this->bdd->mensajeError($comando);
- }
- $fila=$this->bdd->procesaResultado();
- $plantilla=str_replace("{id}",$_POST['id'],$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);
- $informe=new InformePDF($this->bdd,$salida,true);
- }
- private function listarArticulo()
- {
- $fichero="xml/inventarioArticulo.xml";
- $salida="tmp/inventarioArticulo.xml";
- $plantilla=file_get_contents($fichero)
- or die('Fallo en la apertura de la plantilla '.$fichero);
- $comando="select * from Articulos where id='".$_POST['id']."';";
- $resultado=$this->bdd->ejecuta($comando);
- if (!$resultado) {
- return $this->bdd->mensajeError($comando);
- }
- $fila=$this->bdd->procesaResultado();
- $plantilla=str_replace("{id}",$_POST['id'],$plantilla);
- $plantilla=str_replace("{Descripcion}",utf8_encode($fila['descripcion']),$plantilla);
- $plantilla=str_replace("{Marca}",utf8_encode($fila['marca']),$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);
- $informe=new InformePDF($this->bdd,$salida,true);
- }
- private function listaUbicaciones()
- {
- $salida="\n";
- return $salida;
- }
- private function listaArticulos()
- {
- $salida="\n";
- return $salida;
- }
- private function formulario($accion,$etiqueta,$lista)
- {
- $salida='