summaryrefslogtreecommitdiffstatsabout
path: root/aceptar_nuevo_articulo.php
blob: 73df89b8b688447f122b5a77980d7691fa7b1d9f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<?
    /*  
  
    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		 
	
	*/
	
?>
<html>
<head>
<title>Galopin v1.0</title>
<link href="estilo.css" rel="stylesheet" type="text/css">
</head>
<body>
<?
// 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 . "<li>Ya existe un artículo con ese código. No puede haber códigos repetidos en la Base de Datos.</li><br>";
}

if ($codigo=="") $error = $error . "<li>Debe introducir obligatoriamente un código para el artículo.</li>" . "<br>";	
if ($descripcion=="") $error = $error . "<li>Debe introducir una descripción del artículo.</li>" . "<br>";
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 . "<li>El stock contiene caracteres<br>";
}

if ($stock=="") $error = $error . "<li>Debe introducir el stock." . "<br>";

//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 . "<li>El bajo minimos contiene caracteres<br>";
}

if ($bajominimo=="") $error = $error . "<li>Debe introducir el bajo minimos." . "<br>";


//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 . "<li>El precio de venta al público contiene caracteres<br>";
}

if ($pvp=="") $error = $error . "<li>Debe introducir el precio de venta al público." . "<br>";

?>
<img src="images/nuevas/administracionarticulos.jpg" alt="Administraci&oacute;n de Art&iacute;culos"><br>
<br>
	      <? 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 "<h2>No se ha podido copiar el archivo</h2>\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);
			}	
	
		  ?>
</body>
</html>