mirror of
https://github.com/rmontanana/inventario2.git
synced 2025-08-15 15:35:56 +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) {
|
||||
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 = "<center><h1>Archivo [inventario".utf8_decode($archivo)."]</h1>";
|
||||
$mensaje .= "<h2>id=[$idCabecera] Descripción=[".$cabecera."]</h2><br>";
|
||||
$mensaje .= '<p align="center"><table border=1 class="tablaDatos"><tbody>';
|
||||
$mensaje .= "<th><b>Baja</b></th>";
|
||||
$campos = array("Baja");
|
||||
foreach ($consulta->Pagina->Cuerpo->Col as $campo) {
|
||||
$dato = utf8_decode($campo["Titulo"]);
|
||||
$mensaje .= "<h2>id=[$idCabecera] Descripción=[".utf8_decode($cabecera)."]</h2><br>";
|
||||
$mensaje .= '<table border=1 class="table table-striped table-bordered table-condensed table-hover"><theader>';
|
||||
foreach ($datosFichero[0] as $campo) {
|
||||
$dato = $campo;
|
||||
$mensaje .= "<th><b>$dato</b></th>";
|
||||
$campos[] = $dato;
|
||||
}
|
||||
$campos[] = "Cant Real";
|
||||
$mensaje .= "<th><b>Cant. Real</b></th>";
|
||||
$mensaje .= '<tr align="center" bottom="middle">';
|
||||
for ($i=0; $i < count($datosFichero['Baja']); $i++) {
|
||||
$mensaje .="</theader><tbody>";
|
||||
//echo "$mensaje contar Datosfichero=[".count($datosFichero)."]";
|
||||
for ($i=1; $i < count($datosFichero); $i++) {
|
||||
$mensaje .= "<tr>";
|
||||
foreach($campos as $campo) {
|
||||
$mensaje .= "<td>".$datosFichero[$campo][$i]."</td>";
|
||||
foreach($datosFichero[$i] as $dato) {
|
||||
$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 .= '<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="submit" name="Aceptar" value="Aceptar"></form></center>';
|
||||
ob_start();
|
||||
var_dump($datosFichero);
|
||||
$mensaje .= ob_get_clean();
|
||||
<input type="button" name="Cancelar" value="Cancelar" onClick="location.href=' . "'index.php'" .'" class="btn btn-danger">
|
||||
<input type="submit" name="Aceptar" value="Aceptar" class="btn btn-primary"></form></center>';
|
||||
return $mensaje;
|
||||
}
|
||||
|
||||
|
@@ -112,6 +112,7 @@ class InformeInventario {
|
||||
$hoja->cierra();
|
||||
echo '<script type="text/javascript"> window.open( "' . $nombre . '" ) </script>';
|
||||
}
|
||||
//header('Location: index.php');
|
||||
}
|
||||
|
||||
private function listaUbicaciones() {
|
||||
|
@@ -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';
|
||||
|
@@ -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
|
@@ -4,20 +4,22 @@
|
||||
<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
|
||||
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;
|
||||
</Consulta>
|
||||
</Datos>
|
||||
<Pagina Orientacion="P" Formato="A4">
|
||||
<Cabecera>Inventario de Articulo</Cabecera>
|
||||
<Cabecera>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"/>
|
||||
<Col Nombre="Baja" Titulo="Baja"/>
|
||||
<Col Nombre="idEl" Titulo="idElem"/>
|
||||
<Col Nombre="idUb" Titulo="idUbic"/>
|
||||
<Col Nombre="ubicacion" Titulo="Ubicación"/>
|
||||
<Col Nombre="numserie" Titulo="N Serie"/>
|
||||
<Col Nombre="fechaCompra" Titulo="Fecha C." />
|
||||
<Col Nombre="cantidad" Titulo="Cantidad"/>
|
||||
<Col Nombre="cantReal" Titulo="Cant. Real"/>
|
||||
</Cuerpo>
|
||||
</Pagina>
|
||||
</Informe>
|
||||
|
@@ -4,22 +4,24 @@
|
||||
<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
|
||||
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;
|
||||
</Consulta>
|
||||
</Datos>
|
||||
<Pagina Orientacion="L" Formato="A4">
|
||||
<Cabecera>Inventario de Ubicacion</Cabecera>
|
||||
<Cabecera>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"/>
|
||||
<Col Nombre="Baja" Titulo="Baja"/>
|
||||
<Col Nombre="idEl" Titulo="idElem"/>
|
||||
<Col Nombre="id" Titulo="idArt"/>
|
||||
<Col Nombre="descripcion" Titulo="Artículo"/>
|
||||
<Col Nombre="marca" Titulo="Marca"/>
|
||||
<Col Nombre="modelo" Titulo="Modelo"/>
|
||||
<Col Nombre="numserie" Titulo="N Serie"/>
|
||||
<Col Nombre="fechaCompra" Titulo="Fecha C." />
|
||||
<Col Nombre="cantidad" Titulo="Cantidad"/>
|
||||
<Col Nombre="cantReal" Titulo="Cant. Real"/>
|
||||
</Cuerpo>
|
||||
</Pagina>
|
||||
</Informe>
|
Reference in New Issue
Block a user