';
- $mensaje .= '
ATENCIÓN
';
+ private function panelMensaje($info, $tipo = "danger", $cabecera = "¡Atención!") {
+ $mensaje = '
';
+ $mensaje .= '
' . $cabecera . '
';
$mensaje .= '
';
$mensaje .= $info;
$mensaje .= '
';
$mensaje .= '
';
return $mensaje;
}
-
- private function escribeFic($comando)
- {
- $fp = fopen("tmp/comandos","a");
- fputs($fp,$comando);
+
+ private function escribeFic($comando) {
+ $fp = fopen("tmp/comandos", "a");
+ fputs($fp, $comando . "\n");
fclose($fp);
}
-
- private function bajaElemento($i)
- {
- $id = $this->datosFichero['idElem'][$i];
- $comando = 'delete from Elementos where id="'.$id.'";';
+
+ private function bajaElemento($i) {
+ $id = $this->datosFichero[$i][$this->idElemento];
+ $comando = 'delete from Elementos where id="' . $id . '";';
$this->escribeFic($comando);
}
-
- private function modificaElemento($i)
- {
- $id = $this->datosFichero['idElem'][$i];
- $comando = 'update Elementos set Cantidad="'.$datosFichero['cantidadReal'][$i].'" where id="'.$id.'";';
+
+ private function modificaElemento($i) {
+ $id = $this->datosFichero[$i][$this->idElemento];
+ $comando = 'update Elementos set Cantidad=' . $this->datosFichero[$i][$this->cantidadReal] . ' where id="' . $id . '";';
$this->escribeFic($comando);
}
-
- private function altaElemento($i)
- {
+
+ private function altaElemento($i) {
if ($this->cabecera[0] == "Articulo") {
- $idUbicacion = $this->datosFichero['idUbic'][$i];
+ $idUbicacion = $this->datosFichero[$i][$this->idUbicacion];
$idArticulo = $this->cabecera[1];
+ $comando = 'select id from Ubicaciones where Descripcion="'.$this->datosFichero[$i][$this->desUbicacion].'";';
} else {
$idUbicacion = $this->cabecera[1];
- $idArticulo = $this->datosFichero['idArt'][$i];
- }
- $idArt = $datosFichero['idArt'][$i];
- $comando = 'insert into Elementos () values (null,"'.$idArticulo.'","'.$idUbicacion.'","'.$this->datosFichero['N Serie'][$i]
- .'",'.$this->datosFichero['Cant. Real'][$i].',"'.$this->datosFichero['Fecha C.'].'");';
+ $idArticulo = $this->datosFichero[$i][$this->idArticulo];
+ }
+ $idArt = $datosFichero[$i];
+ $comando = 'insert into Elementos () values (null,' . $idArticulo . ',' . $idUbicacion . ',"' . $this->datosFichero[$i][$this->nSerie];
+ $comando .= '",' . $this->datosFichero[$i][$this->cantidadReal] . ',"' . $this->datosFichero[$i][$this->fechaCompra] . '");';
$this->escribeFic($comando);
}
+ private function cargaIndices($campos) {
+ for ($i = 0; $i < count($campos); $i++) {
+ switch ($campos[$i]) {
+ case "Cant. Real": $this->cantidadReal = $i;
+ break;
+ case "Fecha C.": $this->fechaCompra = $i;
+ break;
+ case "idUbic": $this->idUbicacion = $i;
+ break;
+ case "idArt": $this->idArticulo = $i;
+ break;
+ case "idElem": $this->idElemento = $i;
+ break;
+ case "Cantidad": $this->cantidad = $i;
+ break;
+ case "N Serie": $this->nSerie = $i;
+ break;
+ }
+ }
+ $this->EscribeFic("Cantreal=[$this->cantidadReal] fechacompra=[$this->fechaCompra] ubicacion=[$this->idUbicacion] articulo=[$this->idArticulo]");
+ $this->EscribeFic("idElemento=[$this->idElemento] Cantidad=[$this->cantidad] nserie=[$this->nserie]");
+ }
+
/**
* Procesa contra la base de datos todas las acciones del archivo
*/
public function ejecutaFichero() {
+ $this->cargaIndices($this->datosFichero[0]);
//Realiza una transacción para que no se ejecute parcialmente una actualización
try {
$this->bdd->comienzaTransaccion();
- $campos = $this->datosFichero[0];
+ $acciones = 0;
for ($i = 1; $i < count($this->datosFichero); $i++) {
switch ($this->datosFichero[$i][0]) {
case 'S':
$this->bajaElemento($i);
+ $acciones++;
break;
case 'Alta':
- $this->altaElemento($this->datosFichero[$i]);
+ $this->altaElemento($i);
+ $acciones++;
break;
case 'N':
- if ($this->compruebaCantidades($this->datosFichero[$i]) != 0) {
- $this->modificaElemento($this->datosFichero[$i]);
+ if ($this->compruebaCantidades($i) != 0) {
+ $this->modificaElemento($i);
+ $acciones++;
}
break;
default: throw new Exception("Acción no reconocida en la importacion [" . $this->datosFichero[0] . "]");
}
}
+ $mensaje = "Se han procesado correctamente $acciones acciones en la Base de Datos.";
+ return $this->panelMensaje($mensaje,"success", "Información");
} catch (Exception $e) {
$this->bdd->abortaTransaccion();
$mensaje = "Se ha producido el error [" . $e->getMessage() . "]
NO se ha realizado ningún cambio en la Base de Datos.";
@@ -285,17 +319,18 @@ class Csv {
}
}
- public function ejecutaFichero2() {
+ private function ejecutaFichero2() {
echo '';
for ($i = 1; $i < 80; $i++) {
//sleep(1);
$progreso = $i;
- echo '';
+ echo '';
//echo str_repeat(' ',1024*64);
flush();
//echo '$(".bar").css("width", "'.$progreso.'");';
}
}
+
}
?>
diff --git a/InformeInventario.php b/InformeInventario.php
index 43e5d53..6138e3a 100644
--- a/InformeInventario.php
+++ b/InformeInventario.php
@@ -70,7 +70,6 @@ class InformeInventario {
$hoja = new Csv($this->bdd);
$hoja->crea($nombre);
$hoja->ejecutaConsulta($salida);
- $hoja->cierra();
echo '';
}
}
@@ -109,7 +108,6 @@ class InformeInventario {
$hoja = new Csv($this->bdd);
$hoja->crea($nombre);
$hoja->ejecutaConsulta($salida);
- $hoja->cierra();
echo '';
}
//header('Location: index.php');
diff --git a/Sql.php b/Sql.php
index 46dc784..cd06898 100644
--- a/Sql.php
+++ b/Sql.php
@@ -199,7 +199,9 @@ class Sql {
}
public function abortaTransaccion()
{
- return $this->bdd->rollback();
+ $codigo = $this->bdd->rollback();
+ $this->bdd->autocommit(true);
+ return $codigo;
}
public function finalizaTransaccion()
{
diff --git a/plant/bootstrap.html b/plant/bootstrap.html
index 3f3364a..b7692cb 100644
--- a/plant/bootstrap.html
+++ b/plant/bootstrap.html
@@ -57,7 +57,7 @@