Quitado el mensaje de usuario demo

Añadida la clase csv que se encargará de gestionar este tipo de ficheros para exportar e importar información
Añadidas las opciones de exportar a fichero el inventario de un Artículo y el inventario de una Ubicación. 
Añadida la opción de importar un fichero csv (a medio)
This commit is contained in:
rmontanana
2014-02-18 11:22:53 +01:00
parent 9487e41c8c
commit 063564c948
9 changed files with 185 additions and 33 deletions

View File

@@ -134,7 +134,7 @@ class AportaContenido {
if ($this->usuario_inc) {
$salida.=USUARIO_INCORRECTO;
}
$salida.=MENSAJE_DEMO;
//$salida.=MENSAJE_DEMO;
return $salida;
}
case 'opcion':
@@ -154,6 +154,7 @@ class AportaContenido {
return 'Configuración y Preferencias.';
case 'informeInventario':return "Informe de Inventario";
case 'descuadres':return 'Informe de descuadres';
case 'importacion': return 'Importación de datos';
}
return '';
case 'control':
@@ -201,7 +202,7 @@ class AportaContenido {
$conf = new Configuracion();
return $conf->ejecuta();
} else {
return $this->mensajePermisos('Configuracion');
return $this->mensajePermisos('Configuración');
}
case 'informeInventario':
if ($this->perfil['Informe']) {
@@ -221,6 +222,13 @@ class AportaContenido {
} else {
return $this->mensajePermisos('Informes');
}
case 'importacion':
if ($this->perfil['Modificacion'] && $this->perfil['Borrado']) {
$import = new Importacion($this->bdd, $this->registrado);
return $import->ejecuta();
} else {
return $this->mensajePermisos("Actualización, creación y borrado de elementos");
}
} // Fin del contenido
case 'usuario_incorrecto':
$this->usuario_inc = true;

60
Importacion.php Normal file
View File

@@ -0,0 +1,60 @@
<?php
/**
* @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 Importacion {
private $bdd;
public function __construct($baseDatos, $registrado) {
if (!$registrado) {
return 'Debe registrarse para acceder a este apartado';
}
$this->bdd = $baseDatos;
}
public function ejecuta() {
$opc = $_GET['opc'];
switch ($opc) {
case 'form':return $this->formulario();
case 'importar':return $this->importarFichero();
}
}
private function importarFichero() {
$uploadfile = "tmp/" . basename($_FILES['fichero']['name']);
if (!move_uploaded_file($_FILES['fichero']['tmp_name'], $uploadfile)) {
die('No se pudo subir el fichero ' . $_FILES['userfile']['tmp_name']);
}
$csv = new Csv($this->bdd);
return $csv->cargaCSV($uploadfile);
}
private function formulario() {
$accion = "index.php?importacion&opc=importar";
$salida = '<form enctype="multipart/form-data" name="importacion.form" method="post" action="' . $accion . '">' . "\n";
$salida.="<fieldset style=\"width: 96%;\"><p><legend style=\"color: red;\"><b>Elige Archivo</b></legend>\n";
$salida.= '<input type="file" name="fichero" id="fichero">';
$salida.='<p align="center"><button type=submit>Aceptar</button></p><br>' . "\n";
return $salida;
}
}
?>

View File

@@ -39,8 +39,14 @@ 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";
}
$plantilla = file_get_contents($fichero) or die('Fallo en la apertura de la plantilla ' . $fichero);
$id = $_POST['id'] == NULL ? $_GET['id'] : $_POST['id'];
$comando = "select * from Ubicaciones where id='" . $id . "';";
@@ -52,16 +58,32 @@ class InformeInventario {
$plantilla = str_replace("{id}", $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);
if ($salidaInforme == "pantalla") {
$informe = new InformePDF($this->bdd, $salida, true);
$informe->crea($salida);
$informe->cierraPDF();
$informe->guardaArchivo("tmp/Informe.pdf");
echo '<script type="text/javascript"> window.open( "tmp/Informe.pdf" ) </script>';
} 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);
$hoja->cierra();
echo '<script type="text/javascript"> window.open( "' . $nombre . '" ) </script>';
}
}
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";
}
$plantilla = file_get_contents($fichero) or die('Fallo en la apertura de la plantilla ' . $fichero);
$id = $_POST['id'] == NULL ? $_GET['id'] : $_POST['id'];
$comando = "select * from Articulos where id='" . $id . "';";
@@ -75,11 +97,21 @@ class InformeInventario {
$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);
if ($salidaInforme == "pantalla") {
$informe = new InformePDF($this->bdd, $salida, true);
$informe->crea($salida);
$informe->cierraPDF();
$informe->guardaArchivo("tmp/Informe.pdf");
echo '<script type="text/javascript"> window.open( "tmp/Informe.pdf" ) </script>';
} 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);
$hoja->cierra();
echo '<script type="text/javascript"> window.open( "' . $nombre . '" ) </script>';
}
}
private function listaUbicaciones() {
@@ -111,10 +143,13 @@ class InformeInventario {
}
private function formulario($accion, $etiqueta, $lista) {
$salida = '<form name="mantenimiento.form" method="post" action="' . $accion . '">' . "\n";
$salida = '<form name="informeInventario.form" method="post" action="' . $accion . '">' . "\n";
$salida.="<fieldset style=\"width: 96%;\"><p><legend style=\"color: red;\"><b>Elige $etiqueta</b></legend>\n";
$salida.="<br><br><label>$etiqueta</label>";
$salida.=$lista;
$salida.="<br><br>Salida del informe por: Pantalla ";
$salida.='<input type="radio" name="salida" value="pantalla" checked>';
$salida.=' Hoja de c&aacute;lculo <input type="radio" name="salida" value="Hoja de cálculo">';
$salida.="<br><br></fieldset><p>";
$salida.='<p align="center"><button type=submit>Aceptar</button></p><br>' . "\n";
return $salida;

View File

@@ -150,7 +150,7 @@ class Mantenimiento {
}
}
$this->campoBusca = $dato[1];
$valor = '<a target="_blank" href="index.php?informeInventario&opc=listar' . $datoEnlace . '&id=' . $id . '">' . $valor;
$valor = '<a title="Inventario de '.$valor.'" $target="_blank" href="index.php?informeInventario&opc=listar' . $datoEnlace . '&id=' . $id . '">' . $valor;
}
$salida.="<td>$valor</td>\n";
}

View File

@@ -29,10 +29,10 @@ class Menu {
// Obtenemos la lista de pares Opción|Enlace
$elementos=explode("\n", $contenido);
foreach($elementos as $elemento) {
list($tipo, $opcion, $enlace, $destino)=explode('|', $elemento);
list($tipo, $opcion, $enlace, $destino, $titulo)=explode('|', $elemento);
// Los guardamos en la matriz de opciones
if ($tipo)
$this->opciones[]=$tipo.",".$opcion.",".$enlace.",".$destino;
$this->opciones[]=$tipo.",".$opcion.",".$enlace.",".$destino.",".$titulo;
}
}
public function insertaMenu()
@@ -40,9 +40,9 @@ class Menu {
$salida="";
reset($this->opciones);
foreach($this->opciones as $opcion) {
list($tipo,$opcion,$enlace,$destino)=explode(",",$opcion);
list($tipo,$opcion,$enlace,$destino,$titulo)=explode(",",$opcion);
if ($tipo==2)
$salida.='<a href="'.$enlace.'" target="'.$destino.'">'.$opcion.'</a><br />';
$salida.='<a href="'.$enlace.'" target="'.$destino.'" title="'.$titulo.'">'.$opcion.'</a><br />';
else
$salida.='<label class="key">'.$opcion.'</label><br/>';
}

View File

@@ -1,12 +1,13 @@
1|Maestros|
2|Ubicaciones|index.php?ubicaciones&opc=inicial|_self
2|Art&iacute;culos|index.php?articulos&opc=inicial|_self
2|Elementos|index.php?elementos&opc=inicial&orden=ubicacion&sentido=asc|_self
2|Usuarios|index.php?usuarios&opc=inicial|_self
2|Ubicaciones|index.php?ubicaciones&opc=inicial|_self|Ubicaciones del centro
2|Art&iacute;culos|index.php?articulos&opc=inicial|_self|Art&iacute;culos inventariados
2|Elementos|index.php?elementos&opc=inicial&orden=ubicacion&sentido=asc|_self|Art&iacute;culos distribuidos en las ubicaciones
2|Usuarios|index.php?usuarios&opc=inicial|_self|Usuarios autorizados a utilizar la aplicaci&oacute;n
1|Inventario|
2|Ubicaci&oacute;n|index.php?informeInventario&opc=Ubicacion|_self
2|Art&iacute;culo|index.php?informeInventario&opc=Articulo|_self
2|Total|index.php?informeInventario&opc=Total|_blank
2|Descuadres|index.php?descuadres|_blank
2|Ubicaci&oacute;n|index.php?informeInventario&opc=Ubicacion|_self|Inventario de una ubicaci&oacute;n
2|Art&iacute;culo|index.php?informeInventario&opc=Articulo|_self|Inventario de un Art&iacute;culo
2|Total|index.php?informeInventario&opc=Total|_blank|Inventario de todas las ubicaciones
2|Descuadres|index.php?descuadres|_blank|Diferencias entre art&iacute;culos y elementos
1|Varios|
2|Configuraci&oacute;n|index.php?configuracion|_self
2|Configuraci&oacute;n|index.php?configuracion|_self|Opciones configurables de la aplicaci&oacute;n
2|Importaci&oacute;n|index.php?importacion&opc=form|_self|Importa datos de una hoja de c&aacute;lculo

View File

@@ -3,8 +3,8 @@
<Titulo Texto="{Descripcion}" />
<Datos>
<Consulta>
select A.id as id,U.Descripcion as ubicacion,E.fechaCompra as fechaCompra,
E.numSerie as numserie,E.Cantidad as cantidad
select A.id as id,U.Descripcion as ubicacion,E.numserie as numserie,
E.fechaCompra as fechaCompra,E.Cantidad as cantidad
from Elementos E, Articulos A, Ubicaciones U where A.id=E.id_Articulo and U.id=E.id_Ubicacion
and A.id='{id}' order by U.Descripcion,numserie;
</Consulta>

View File

@@ -0,0 +1,23 @@
<?xml version="1.0"?>
<Informe>
<Titulo Texto="{Descripcion}" id="{id}"/>
<Datos>
<Consulta>
select A.id as id,E.id as idEl, U.id as idUb,U.Descripcion as ubicacion,E.numserie as numserie,
E.fechaCompra as fechaCompra,E.Cantidad as cantidad
from Elementos E, Articulos A, Ubicaciones U where A.id=E.id_Articulo and U.id=E.id_Ubicacion
and A.id='{id}' order by U.Descripcion,numserie;
</Consulta>
</Datos>
<Pagina Orientacion="P" Formato="A4">
<Cabecera>Inventario de Articulo</Cabecera>
<Cuerpo>
<Col Nombre="idEl" Ancho="10" Ajuste="R" Titulo="idElem"/>
<Col Nombre="idUb" Ancho="10" Ajuste="R" Titulo="idUbic"/>
<Col Nombre="ubicacion" Ancho="80" Ajuste="L" Titulo="Ubicación"/>
<Col Nombre="numserie" Ancho="40" Ajuste="L" Titulo="N Serie"/>
<Col Nombre="fechaCompra" Ancho="40" Ajuste="L" Titulo="Fecha C." />
<Col Nombre="cantidad" Ancho="20" Ajuste="D" Titulo="Cantidad" Total="S"/>
</Cuerpo>
</Pagina>
</Informe>

View File

@@ -0,0 +1,25 @@
<?xml version="1.0"?>
<Informe>
<Titulo Texto="{Descripcion}" id="{id}"/>
<Datos>
<Consulta>
select A.id as id,E.id as idEl,A.Marca as marca,A.Modelo as modelo,E.numSerie as numserie,
E.fechaCompra as fechaCompra,A.Descripcion as descripcion,E.Cantidad as cantidad
from Elementos E, Articulos A, Ubicaciones U where A.id=E.id_Articulo and U.id=E.id_Ubicacion
and U.id='{id}' order by A.descripcion;
</Consulta>
</Datos>
<Pagina Orientacion="L" Formato="A4">
<Cabecera>Inventario de Ubicacion</Cabecera>
<Cuerpo>
<Col Nombre="idEl" Ancho="10" Ajuste="R" Titulo="idElem"/>
<Col Nombre="id" Ancho="10" Ajuste="R" Titulo="idArt"/>
<Col Nombre="descripcion" Ancho="70" Ajuste="L" Titulo="Artículo"/>
<Col Nombre="marca" Ancho="50" Ajuste="L" Titulo="Marca"/>
<Col Nombre="modelo" Ancho="50" Ajuste="L" Titulo="Modelo"/>
<Col Nombre="numserie" Ancho="40" Ajuste="L" Titulo="N Serie"/>
<Col Nombre="fechaCompra" Ancho="35" Ajuste="L" Titulo="Fecha C." />
<Col Nombre="cantidad" Ancho="20" Ajuste="D" Titulo="Cantidad" Total="S"/>
</Cuerpo>
</Pagina>
</Informe>