/*
This program 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 2 of the License, or
(at your option) any later version.
This program 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 this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Autores: Pedro Obregón Mejías
Rubén D. Mancera Morán
Versión: 1.0
Fecha Liberación del código: 13/07/2004
Galopín para gnuLinEx 2004 -- Extremadura
*/
?>
Galopin v1.0
// Comprobación de errores
include ("conectar.php");
$error = "";
//comprobamos que no existe ya ese artículo en esa familia y subfamilia
$consulta = "select * from articulos where codigo='$codigo' and codfamilia=$familia and codsubfamilia=$subfamilia";
$query = mysql_query($consulta);
$total = mysql_num_rows($query);
if ($total>0)
{
$error = $error . "
Ya existe un artículo con ese código. No puede haber códigos repetidos en la Base de Datos.
";
}
if ($codigo=="") $error = $error . "
Debe introducir obligatoriamente un código para el artículo.
" . " ";
if ($detalles=="") $detalles="Sin Detalles";
//controlar también la coma y el punto
if ($stock=="") $stock=0;
$stock = str_replace(",",".",$stock);
if (!preg_match("/^[0-9 '-]*(.[0-9]{0,2})?$/", $stock))
{
$error = $error . "
El stock contiene caracteres ";
}
if ($stock=="") $error = $error . "
Debe introducir el stock." . " ";
//controlar también la coma y el punto
if ($bajominimo=="") $bajominimo=0;
$bajominimo = str_replace(",",".",$bajominimo);
if (!preg_match("/^[0-9]*(.[0-9]{0,2})?$/", $bajominimo))
{
$error = $error . "
El bajo minimos contiene caracteres ";
}
if ($bajominimo=="") $error = $error . "
Debe introducir el bajo minimos." . " ";
//controlar también la coma y el punto
if ($pvp=="") $pvp=0;
$pvp = str_replace(",",".",$pvp);
if (!preg_match("/^[0-9]*(.[0-9]{0,2})?$/", $pvp))
{
$error = $error . "
El precio de venta al público contiene caracteres ";
}
if ($pvp=="") $error = $error . "
Debe introducir el precio de venta al público." . " ";
?>
if ($error<>"")
{
//
//mostramos el mensaje de errores
//
$loguito="logomensaje.jpg";
$cabecera="articulos.jpg";
$texto="Errores: " . $error;
$actionimp="";
$namevar="";
$valuevar=$id;
$valueimp="";
$actionv="ges_articulos.php";
$valuev="Administración de artículos";
include ("mensaje.php");
}
else
{
if ($foto_name=="")
{
$foto_name="none";
};
//insertamos primero el artículo en la base de datos
//ya no tiene sentido
//$codigo = $codigo2 . $codigo;
$consulta="insert into articulos(codfamilia,codsubfamilia,codigo,descripcion,detalles,pvp,foto,stock,bajominimo) values('$familia','$subfamilia','$codigo','$descripcion','$detalles',$pvp,'$foto_name',$stock,$bajominimo);";
$query = mysql_query($consulta);
//guardamos la imagen el la carpeta de imagenes
if ($foto_name<>"none")
{
if (! copy ($foto, "imagenes/$foto_name"))
{
echo "
No se ha podido copiar el archivo
\n";
};
};
//
//mostramos el mensaje de errores
//
$loguito="logomensaje.jpg";
$cabecera="articulos.jpg";
$texto="Artículo insertado con éxito";
$actionimp="";
$namevar="";
$valuevar=$id;
$valueimp="Imprimir Artículos";
$actionv="ges_articulos.php";
$valuev="Administración de artículos";
include ("mensaje.php");
//Buscamos el artículo que hemos insertado
$consulta = "select max(id) from articulos";
$query = mysql_query($consulta);
$maximo = mysql_fetch_row($query);
//insertamos en artpro el artículo y sus proveedores
$consulta = "select * from tempartpro where articulo=$articulo and proveedor<>0";
$query = mysql_query($consulta);
while ($row=mysql_fetch_row($query))
{
$consulta2 = "insert into artpro(idarticulo,idproveedor,precio) values($maximo[0],$row[2],$row[3])";
$query2=mysql_query($consulta2);
};
//borramos los proveedores de la tabla temporal
$consulta = "delete from tempartpro where articulo=$articulo";
$query = mysql_query($consulta);
}
?>