mirror of
https://github.com/rmontanana/inventario2.git
synced 2025-08-15 23:45:58 +00:00
ref #3 Arreglada la importación de datos. Sólo falta hacerla efectiva. Cambiados algunos aspectos menores de la clase inventario para evitar algún warning
This commit is contained in:
88
Csv.php
88
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) {
|
public function escribeLinea($datos) {
|
||||||
fwrite($this->fichero, $linea . "\n") or die("No puedo escribir en el fichero xml");
|
fputcsv($this->fichero, $datos, ',', '"') or die("No puedo escribir en el fichero csv");
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @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 cierra() {
|
public function cierra() {
|
||||||
@@ -98,29 +86,21 @@ class Csv {
|
|||||||
public function ejecutaConsulta($fichero) {
|
public function ejecutaConsulta($fichero) {
|
||||||
$consulta = simplexml_load_file($fichero) or die("No puedo cargar el fichero xml " . $fichero . " al csv");
|
$consulta = simplexml_load_file($fichero) or die("No puedo cargar el fichero xml " . $fichero . " al csv");
|
||||||
// Escribe la cabecera del fichero
|
// Escribe la cabecera del fichero
|
||||||
$this->escribeLinea('"' . utf8_decode($consulta->Titulo['Texto']) . '","' . $consulta->Titulo['id'] . '"');
|
$this->escribeLinea(array($consulta->Pagina->Cabecera,$consulta->Titulo['id'],$consulta->Titulo['Texto']));
|
||||||
$this->escribeLinea("");
|
|
||||||
$this->escribeLinea('"' . $consulta->Pagina->Cabecera . '"');
|
|
||||||
$this->escribeLinea("");
|
|
||||||
$campos = array("Baja");
|
|
||||||
foreach ($consulta->Pagina->Cuerpo->Col as $campo) {
|
foreach ($consulta->Pagina->Cuerpo->Col as $campo) {
|
||||||
$campos[] = utf8_decode($campo['Titulo']);
|
$campos[] = utf8_decode($campo['Titulo']);
|
||||||
}
|
}
|
||||||
$campos[] = "Cantidad Real";
|
$this->escribeLinea($campos);
|
||||||
$this->escribeCampos($campos);
|
|
||||||
// Escribe los datos de los campos
|
// Escribe los datos de los campos
|
||||||
$this->bdd->ejecuta($consulta->Datos->Consulta);
|
$this->bdd->ejecuta($consulta->Datos->Consulta);
|
||||||
while ($fila = $this->bdd->procesaResultado()) {
|
while ($fila = $this->bdd->procesaResultado()) {
|
||||||
$campos = array("");
|
$campos = array();
|
||||||
foreach ($consulta->Pagina->Cuerpo->Col as $campo) {
|
foreach ($consulta->Pagina->Cuerpo->Col as $campo) {
|
||||||
$campos[] = $fila[(string) $campo['Nombre']];
|
$campos[] = $fila[(string) $campo['Nombre']];
|
||||||
}
|
}
|
||||||
//$campos = $fila;
|
$this->escribeLinea($campos);
|
||||||
//array_unshift($campos, "");
|
|
||||||
$this->escribeCampos($campos);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function quitaComillas($dato) {
|
private function quitaComillas($dato) {
|
||||||
//return substr($dato, 1, -1);
|
//return substr($dato, 1, -1);
|
||||||
return str_replace("\"", "", $dato);
|
return str_replace("\"", "", $dato);
|
||||||
@@ -129,9 +109,8 @@ class Csv {
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param String $ficheroCSV Nombre del archivo 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->nombre = $ficheroCSV;
|
||||||
$this->fichero = fopen($this->nombre, "r") or die('No puedo abrir el archivo ' . $this->nombre . " para lectura.");
|
$this->fichero = fopen($this->nombre, "r") or die('No puedo abrir el archivo ' . $this->nombre . " para lectura.");
|
||||||
$linea = fgets($this->fichero);
|
$linea = fgets($this->fichero);
|
||||||
@@ -164,39 +143,42 @@ class Csv {
|
|||||||
$this->numRegistros = $lineas;
|
$this->numRegistros = $lineas;
|
||||||
return $this->Resumen($cabecera, $idCabecera, $archivo, $datosFichero, $consulta);
|
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 = "<center><h1>Archivo [inventario".utf8_decode($archivo)."]</h1>";
|
$mensaje = "<center><h1>Archivo [inventario".utf8_decode($archivo)."]</h1>";
|
||||||
$mensaje .= "<h2>id=[$idCabecera] Descripción=[".$cabecera."]</h2><br>";
|
$mensaje .= "<h2>id=[$idCabecera] Descripción=[".utf8_decode($cabecera)."]</h2><br>";
|
||||||
$mensaje .= '<p align="center"><table border=1 class="tablaDatos"><tbody>';
|
$mensaje .= '<table border=1 class="table table-striped table-bordered table-condensed table-hover"><theader>';
|
||||||
$mensaje .= "<th><b>Baja</b></th>";
|
foreach ($datosFichero[0] as $campo) {
|
||||||
$campos = array("Baja");
|
$dato = $campo;
|
||||||
foreach ($consulta->Pagina->Cuerpo->Col as $campo) {
|
|
||||||
$dato = utf8_decode($campo["Titulo"]);
|
|
||||||
$mensaje .= "<th><b>$dato</b></th>";
|
$mensaje .= "<th><b>$dato</b></th>";
|
||||||
$campos[] = $dato;
|
|
||||||
}
|
}
|
||||||
$campos[] = "Cant Real";
|
$mensaje .="</theader><tbody>";
|
||||||
$mensaje .= "<th><b>Cant. Real</b></th>";
|
//echo "$mensaje contar Datosfichero=[".count($datosFichero)."]";
|
||||||
$mensaje .= '<tr align="center" bottom="middle">';
|
for ($i=1; $i < count($datosFichero); $i++) {
|
||||||
for ($i=0; $i < count($datosFichero['Baja']); $i++) {
|
|
||||||
$mensaje .= "<tr>";
|
$mensaje .= "<tr>";
|
||||||
foreach($campos as $campo) {
|
foreach($datosFichero[$i] as $dato) {
|
||||||
$mensaje .= "<td>".$datosFichero[$campo][$i]."</td>";
|
$mensaje .= "<td>".$dato."</td>";
|
||||||
}
|
}
|
||||||
$mensaje .= "</tr>";
|
$mensaje .= "</tr>";
|
||||||
}
|
}
|
||||||
foreach ($datosFichero as $clave => $dato) {
|
|
||||||
$mensaje .= "<td>$dato[$i]</td>";
|
|
||||||
}
|
|
||||||
$mensaje .= "</tr>";
|
|
||||||
$mensaje .= "</tbody></table></p><br>";
|
$mensaje .= "</tbody></table></p><br>";
|
||||||
$mensaje .= '<form method="post" name="Aceptar" action="index.php?Importacion&opc=Ejecutar">
|
$mensaje .= '<form method="post" name="Aceptar" action="index.php?Importacion&opc=Ejecutar">
|
||||||
<input type="button" name="Cancelar" value="Cancelar" onClick="location.href=' . "'index.php'" .'">
|
<input type="button" name="Cancelar" value="Cancelar" onClick="location.href=' . "'index.php'" .'" class="btn btn-danger">
|
||||||
<input type="submit" name="Aceptar" value="Aceptar"></form></center>';
|
<input type="submit" name="Aceptar" value="Aceptar" class="btn btn-primary"></form></center>';
|
||||||
ob_start();
|
|
||||||
var_dump($datosFichero);
|
|
||||||
$mensaje .= ob_get_clean();
|
|
||||||
return $mensaje;
|
return $mensaje;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -112,6 +112,7 @@ class InformeInventario {
|
|||||||
$hoja->cierra();
|
$hoja->cierra();
|
||||||
echo '<script type="text/javascript"> window.open( "' . $nombre . '" ) </script>';
|
echo '<script type="text/javascript"> window.open( "' . $nombre . '" ) </script>';
|
||||||
}
|
}
|
||||||
|
//header('Location: index.php');
|
||||||
}
|
}
|
||||||
|
|
||||||
private function listaUbicaciones() {
|
private function listaUbicaciones() {
|
||||||
|
@@ -120,8 +120,10 @@ class Inventario {
|
|||||||
// Creamos un objeto Distribución facilitándole el
|
// Creamos un objeto Distribución facilitándole el
|
||||||
// nombre del archivo plantilla y el objeto que aportará
|
// nombre del archivo plantilla y el objeto que aportará
|
||||||
// el contenido
|
// el contenido
|
||||||
$opc = $_GET['opc'];
|
$opc = '';
|
||||||
list($opcion, $parametro) = explode("&", $this->opcActual);
|
if (isset($_GET['opc'])) {
|
||||||
|
list($opcion, $parametro) = explode("&", $this->opcActual);
|
||||||
|
}
|
||||||
switch ($opc) {
|
switch ($opc) {
|
||||||
case 'informe':
|
case 'informe':
|
||||||
$enlace = 'xml/informe' . ucfirst($opcion) . '.xml';
|
$enlace = 'xml/informe' . ucfirst($opcion) . '.xml';
|
||||||
|
@@ -1,13 +1,13 @@
|
|||||||
1|Maestros|
|
1|Maestros|||
|
||||||
2|Ubicaciones|index.php?ubicaciones&opc=inicial|_self|Ubicaciones del centro
|
2|Ubicaciones|index.php?ubicaciones&opc=inicial|_self|Ubicaciones del centro
|
||||||
2|Artículos|index.php?articulos&opc=inicial|_self|Artículos inventariados
|
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|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
|
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|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|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|Total|index.php?informeInventario&opc=Total|_blank|Inventario de todas las ubicaciones
|
||||||
2|Descuadres|index.php?descuadres|_blank|Diferencias entre artículos y elementos
|
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|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
|
2|Importación|index.php?importacion&opc=form|_self|Importa datos de una hoja de cálculo
|
@@ -4,20 +4,22 @@
|
|||||||
<Datos>
|
<Datos>
|
||||||
<Consulta>
|
<Consulta>
|
||||||
select A.id as id,E.id as idEl, U.id as idUb,U.Descripcion as ubicacion,E.numserie as numserie,
|
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
|
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;
|
and A.id='{id}' order by U.Descripcion,numserie;
|
||||||
</Consulta>
|
</Consulta>
|
||||||
</Datos>
|
</Datos>
|
||||||
<Pagina Orientacion="P" Formato="A4">
|
<Pagina Orientacion="P" Formato="A4">
|
||||||
<Cabecera>Inventario de Articulo</Cabecera>
|
<Cabecera>Articulo</Cabecera>
|
||||||
<Cuerpo>
|
<Cuerpo>
|
||||||
<Col Nombre="idEl" Ancho="10" Ajuste="R" Titulo="idElem"/>
|
<Col Nombre="Baja" Titulo="Baja"/>
|
||||||
<Col Nombre="idUb" Ancho="10" Ajuste="R" Titulo="idUbic"/>
|
<Col Nombre="idEl" Titulo="idElem"/>
|
||||||
<Col Nombre="ubicacion" Ancho="80" Ajuste="L" Titulo="Ubicación"/>
|
<Col Nombre="idUb" Titulo="idUbic"/>
|
||||||
<Col Nombre="numserie" Ancho="40" Ajuste="L" Titulo="N Serie"/>
|
<Col Nombre="ubicacion" Titulo="Ubicación"/>
|
||||||
<Col Nombre="fechaCompra" Ancho="40" Ajuste="L" Titulo="Fecha C." />
|
<Col Nombre="numserie" Titulo="N Serie"/>
|
||||||
<Col Nombre="cantidad" Ancho="20" Ajuste="D" Titulo="Cantidad" Total="S"/>
|
<Col Nombre="fechaCompra" Titulo="Fecha C." />
|
||||||
|
<Col Nombre="cantidad" Titulo="Cantidad"/>
|
||||||
|
<Col Nombre="cantReal" Titulo="Cant. Real"/>
|
||||||
</Cuerpo>
|
</Cuerpo>
|
||||||
</Pagina>
|
</Pagina>
|
||||||
</Informe>
|
</Informe>
|
||||||
|
@@ -4,22 +4,24 @@
|
|||||||
<Datos>
|
<Datos>
|
||||||
<Consulta>
|
<Consulta>
|
||||||
select A.id as id,E.id as idEl,A.Marca as marca,A.Modelo as modelo,E.numSerie as numserie,
|
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
|
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;
|
and U.id='{id}' order by A.descripcion;
|
||||||
</Consulta>
|
</Consulta>
|
||||||
</Datos>
|
</Datos>
|
||||||
<Pagina Orientacion="L" Formato="A4">
|
<Pagina Orientacion="L" Formato="A4">
|
||||||
<Cabecera>Inventario de Ubicacion</Cabecera>
|
<Cabecera>Ubicacion</Cabecera>
|
||||||
<Cuerpo>
|
<Cuerpo>
|
||||||
<Col Nombre="idEl" Ancho="10" Ajuste="R" Titulo="idElem"/>
|
<Col Nombre="Baja" Titulo="Baja"/>
|
||||||
<Col Nombre="id" Ancho="10" Ajuste="R" Titulo="idArt"/>
|
<Col Nombre="idEl" Titulo="idElem"/>
|
||||||
<Col Nombre="descripcion" Ancho="70" Ajuste="L" Titulo="Artículo"/>
|
<Col Nombre="id" Titulo="idArt"/>
|
||||||
<Col Nombre="marca" Ancho="50" Ajuste="L" Titulo="Marca"/>
|
<Col Nombre="descripcion" Titulo="Artículo"/>
|
||||||
<Col Nombre="modelo" Ancho="50" Ajuste="L" Titulo="Modelo"/>
|
<Col Nombre="marca" Titulo="Marca"/>
|
||||||
<Col Nombre="numserie" Ancho="40" Ajuste="L" Titulo="N Serie"/>
|
<Col Nombre="modelo" Titulo="Modelo"/>
|
||||||
<Col Nombre="fechaCompra" Ancho="35" Ajuste="L" Titulo="Fecha C." />
|
<Col Nombre="numserie" Titulo="N Serie"/>
|
||||||
<Col Nombre="cantidad" Ancho="20" Ajuste="D" Titulo="Cantidad" Total="S"/>
|
<Col Nombre="fechaCompra" Titulo="Fecha C." />
|
||||||
|
<Col Nombre="cantidad" Titulo="Cantidad"/>
|
||||||
|
<Col Nombre="cantReal" Titulo="Cant. Real"/>
|
||||||
</Cuerpo>
|
</Cuerpo>
|
||||||
</Pagina>
|
</Pagina>
|
||||||
</Informe>
|
</Informe>
|
Reference in New Issue
Block a user