diff --git a/Csv.php b/Csv.php index 8fa0aa5..ec7eb2d 100644 --- a/Csv.php +++ b/Csv.php @@ -69,22 +69,10 @@ class Csv { /** * - * @param String $linea escribe la línea en el archivo, la línea debe estar formateada + * @param array $datos escribe la línea en el archivo */ - public function escribeLinea($linea) { - fwrite($this->fichero, $linea . "\n") or die("No puedo escribir en el fichero xml"); - } - - /** - * - * @param array $campos array de campos a escribir en el fichero - */ - public function escribeCampos($campos) { - $linea = ""; - foreach ($campos as $campo) { - $linea .= '"' . $campo . '",'; - } - $this->escribeLinea($linea); + public function escribeLinea($datos) { + fputcsv($this->fichero, $datos, ',', '"') or die("No puedo escribir en el fichero csv"); } public function cierra() { @@ -98,29 +86,21 @@ class Csv { public function ejecutaConsulta($fichero) { $consulta = simplexml_load_file($fichero) or die("No puedo cargar el fichero xml " . $fichero . " al csv"); // Escribe la cabecera del fichero - $this->escribeLinea('"' . utf8_decode($consulta->Titulo['Texto']) . '","' . $consulta->Titulo['id'] . '"'); - $this->escribeLinea(""); - $this->escribeLinea('"' . $consulta->Pagina->Cabecera . '"'); - $this->escribeLinea(""); - $campos = array("Baja"); + $this->escribeLinea(array($consulta->Pagina->Cabecera,$consulta->Titulo['id'],$consulta->Titulo['Texto'])); foreach ($consulta->Pagina->Cuerpo->Col as $campo) { $campos[] = utf8_decode($campo['Titulo']); } - $campos[] = "Cantidad Real"; - $this->escribeCampos($campos); + $this->escribeLinea($campos); // Escribe los datos de los campos $this->bdd->ejecuta($consulta->Datos->Consulta); while ($fila = $this->bdd->procesaResultado()) { - $campos = array(""); + $campos = array(); foreach ($consulta->Pagina->Cuerpo->Col as $campo) { $campos[] = $fila[(string) $campo['Nombre']]; } - //$campos = $fila; - //array_unshift($campos, ""); - $this->escribeCampos($campos); + $this->escribeLinea($campos); } } - private function quitaComillas($dato) { //return substr($dato, 1, -1); return str_replace("\"", "", $dato); @@ -129,9 +109,8 @@ class Csv { /** * * @param String $ficheroCSV Nombre del archivo csv - * @param String $ficheroXML Nombre del archivo que contiene la consulta xml */ - public function cargaCSV($ficheroCSV) { + public function cargaCSV2($ficheroCSV) { $this->nombre = $ficheroCSV; $this->fichero = fopen($this->nombre, "r") or die('No puedo abrir el archivo ' . $this->nombre . " para lectura."); $linea = fgets($this->fichero); @@ -164,39 +143,42 @@ class Csv { $this->numRegistros = $lineas; return $this->Resumen($cabecera, $idCabecera, $archivo, $datosFichero, $consulta); } + /** + * + * @param String $ficheroCSV Nombre del archivo csv + */ + public function cargaCSV($ficheroCSV) { + $this->nombre = $ficheroCSV; + $this->fichero = fopen($this->nombre, "r") or die('No puedo abrir el archivo ' . $this->nombre . " para lectura."); + list($archivo, $idCabecera, $cabecera) = fgetcsv($this->fichero); + while ($linea = fgetcsv($this->fichero)) { + $datosFichero[] = $linea; + } + return $this->Resumen($cabecera, $idCabecera, $archivo, $datosFichero); + } - public function Resumen($cabecera, $idCabecera, $archivo, $datosFichero, $consulta) { + public function Resumen($cabecera, $idCabecera, $archivo, $datosFichero) { + //$mensaje .= $mensaje = "

Archivo [inventario".utf8_decode($archivo)."]

"; - $mensaje .= "

id=[$idCabecera] Descripción=[".$cabecera."]


"; - $mensaje .= '

'; - $mensaje .= ""; - $campos = array("Baja"); - foreach ($consulta->Pagina->Cuerpo->Col as $campo) { - $dato = utf8_decode($campo["Titulo"]); + $mensaje .= "

id=[$idCabecera] Descripción=[".utf8_decode($cabecera)."]


"; + $mensaje .= '
Baja
'; + foreach ($datosFichero[0] as $campo) { + $dato = $campo; $mensaje .= ""; - $campos[] = $dato; } - $campos[] = "Cant Real"; - $mensaje .= ""; - $mensaje .= ''; - for ($i=0; $i < count($datosFichero['Baja']); $i++) { + $mensaje .=""; + //echo "$mensaje contar Datosfichero=[".count($datosFichero)."]"; + for ($i=1; $i < count($datosFichero); $i++) { $mensaje .= ""; - foreach($campos as $campo) { - $mensaje .= ""; + foreach($datosFichero[$i] as $dato) { + $mensaje .= ""; } - $mensaje .= ""; + $mensaje .= ""; } - foreach ($datosFichero as $clave => $dato) { - $mensaje .= ""; - } - $mensaje .= ""; $mensaje .= "
$datoCant. Real
".$datosFichero[$campo][$i]."".$dato."
$dato[$i]


"; $mensaje .= '
- -
'; - ob_start(); - var_dump($datosFichero); - $mensaje .= ob_get_clean(); + + '; return $mensaje; } diff --git a/InformeInventario.php b/InformeInventario.php index 8bf5ecd..c7331ae 100644 --- a/InformeInventario.php +++ b/InformeInventario.php @@ -112,6 +112,7 @@ class InformeInventario { $hoja->cierra(); echo ''; } + //header('Location: index.php'); } private function listaUbicaciones() { diff --git a/Inventario.php b/Inventario.php index 7170c3d..a6629b3 100644 --- a/Inventario.php +++ b/Inventario.php @@ -120,8 +120,10 @@ class Inventario { // Creamos un objeto Distribución facilitándole el // nombre del archivo plantilla y el objeto que aportará // el contenido - $opc = $_GET['opc']; - list($opcion, $parametro) = explode("&", $this->opcActual); + $opc = ''; + if (isset($_GET['opc'])) { + list($opcion, $parametro) = explode("&", $this->opcActual); + } switch ($opc) { case 'informe': $enlace = 'xml/informe' . ucfirst($opcion) . '.xml'; diff --git a/inc/inventario.menu b/inc/inventario.menu index f8d31e5..0acf506 100644 --- a/inc/inventario.menu +++ b/inc/inventario.menu @@ -1,13 +1,13 @@ -1|Maestros| +1|Maestros||| 2|Ubicaciones|index.php?ubicaciones&opc=inicial|_self|Ubicaciones del centro 2|Artículos|index.php?articulos&opc=inicial|_self|Artículos inventariados 2|Elementos|index.php?elementos&opc=inicial&orden=ubicacion&sentido=asc|_self|Artículos distribuidos en las ubicaciones 2|Usuarios|index.php?usuarios&opc=inicial|_self|Usuarios autorizados a utilizar la aplicación -1|Inventario| +1|Inventario||| 2|Ubicación|index.php?informeInventario&opc=Ubicacion|_self|Inventario de una ubicación 2|Artículo|index.php?informeInventario&opc=Articulo|_self|Inventario de un Artículo 2|Total|index.php?informeInventario&opc=Total|_blank|Inventario de todas las ubicaciones 2|Descuadres|index.php?descuadres|_blank|Diferencias entre artículos y elementos -1|Varios| +1|Varios||| 2|Configuración|index.php?configuracion|_self|Opciones configurables de la aplicación 2|Importación|index.php?importacion&opc=form|_self|Importa datos de una hoja de cálculo \ No newline at end of file diff --git a/xml/inventarioArticuloCSV.xml b/xml/inventarioArticuloCSV.xml index cc0c9d3..28e6192 100644 --- a/xml/inventarioArticuloCSV.xml +++ b/xml/inventarioArticuloCSV.xml @@ -4,20 +4,22 @@ 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 + E.fechaCompra as fechaCompra,E.Cantidad as cantidad, E.Cantidad as cantReal, 'N' as Baja 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; - Inventario de Articulo + Articulo - - - - - - + + + + + + + + diff --git a/xml/inventarioUbicacionCSV.xml b/xml/inventarioUbicacionCSV.xml index d385dd1..ded8605 100644 --- a/xml/inventarioUbicacionCSV.xml +++ b/xml/inventarioUbicacionCSV.xml @@ -4,22 +4,24 @@ 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 + E.fechaCompra as fechaCompra,A.Descripcion as descripcion,E.Cantidad as cantidad, E.Cantidad as cantReal, 'N' as Baja 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; - Inventario de Ubicacion + Ubicacion - - - - - - - - + + + + + + + + + + \ No newline at end of file