<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<title>SIVI</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<LINK REL="SHORTCUT ICON" HREF="../sivi.ico">
<LINK href="../general.css" type=text/css rel=stylesheet>
<link href="../bootstrap/css/bootstrap.min.css" rel="stylesheet">
<script src="../bootstrap/js/bootstrap.min.js"></script>
 

</head>


<BODY onLoad="parametros.minimo.focus();">
<?php
 @session_start();
  $vg_login=$_SESSION["usuario"];
  if($vg_login<>""){}
 else
  {echo "<script>";
   echo "window.location='../index.php';";
   echo "</script>";
  }	
include "../valida_permisos.php";
$vg_programa = F_programa();
include "../seguridad.php";
$ip=getenv("REMOTE_ADDR");

include "../conexion.php";
$id=$_REQUEST["id"];$nombre="";$estado="";$descripcion="";
$preciounitario="";$precioventa="";$productofamilia="";$marca="";$iva="";$codigobarra="";
$minimo="";$maximo="";
if($id>0)
{	
$sql_datosrs=mysqli_query($conexion,"SELECT id,nombre,descripcion,preciounitario,precioventa,productofamilia,marca,iva,
								codigobarra,estado,ubicacion ,paqueteunidad,cantidadpaquete,preciopaquete
								from producto
								where id='".$_REQUEST["id"]."'");
while($datos= mysqli_fetch_row($sql_datosrs)){ $nombre=$datos[1];}

 $sql_datosrs=mysqli_query($conexion,"SELECT count(*) as contar	from Producto_MinMax
								where producto='".$_REQUEST["id"]."'");
 while($datorss= mysqli_fetch_row($sql_datosrs)){ $contar=$datorss[0];}
 if($contar>=1)
   {
	 $sql_datosrs=mysqli_query($conexion,"SELECT minimo,maximo	from Producto_MinMax
									where producto='".$_REQUEST["id"]."'");
	  while($datorss= mysqli_fetch_row($sql_datosrs)){ $minimo=$datorss[0]; $maximo=$datorss[1];}
   }
}   							  
if(isset($_REQUEST["oculto"]))
{ 

	$id=$_REQUEST["id"];   		
	$minimo=$_REQUEST["minimo"];  		
	$maximo=$_REQUEST["maximo"];


  if($_REQUEST["oguardar"]==1)
    {
	  		 $sql_datoscontar=mysqli_query($conexion,"select count(*) as cantidad  from Producto_MinMax
											where producto='".$_REQUEST["id"]."'",);
			  while($datorss= mysqli_fetch_row($sql_datoscontar)){ $vl_contar=$datorss[0];}
			 if($vl_contar>=1)
			    { 
				  $sql_insert=mysqli_query($conexion,"update Producto_MinMax   set minimo='".$minimo."',maximo='".$maximo."'
				 							where producto='".$_REQUEST["id"]."'");
							 if ($sql_insert) 
								{   $mensaje="Guardo";$mensa="Registro actualizado con exito";
								?>
									<div class="alert alert-success alert-dismissible" id="myAlert">
                                        <strong>Success!</strong> Registro Actualizado.
								  </div>
							  <?php
									$valor=1;	
								}
							 else
								 { ?>
										<div class="alert alert-success alert-dismissible" id="myAlert">
											<strong>Success!</strong> Error al Actualizar el Registro.
									    </div>
								  <?php }
				
				}
			 else
			  { 

			   $sql_insert=mysqli_query($conexion,"INSERT INTO Producto_MinMax    (producto,minimo,maximo)
											VALUES    ('".$id."','".$minimo."','".$maximo."')");
							 if ($sql_insert) 
								{  
									?>
										<div class="alert alert-success alert-dismissible" id="myAlert">
											<strong>Success!</strong> Registro Guardado.
									    </div>
								  <?php
								  
									$valor=1;	
								}
							 else
								 { ?>
										<div class="alert alert-success alert-dismissible" id="myAlert">
											<strong>Success!</strong> Error al Guardar.
									    </div>
								  <?php
								 
								 }
			  }		
	
	}

}


?>
<form name="parametros" method="post" action="" >
<div id="informes" class="container text-center" style="width:100%;">
    <div class="panel panel-default">
      <div class="panel-heading" align="left">  PRODUCTO MINIMOS Y MAXIMOS</div>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="texto" >
                    <tr> 
                      <td width="136" height="0"> Codigo                        </td>
                      <td height="0" colspan="3"><div align="left">
                        <input name="id" type="text"   id="id" value="<?php echo $id; ?>" size="10" readonly
                        class="form-control" data-placement="right" title="Digite Codigo Item" style="width: 150px" 
								onKeyPress="if(event.keyCode==13){titulo.nombre();} if(event.keyCode>=48 && event.keyCode<=58){} else {event.keyCode=8;}"
								onFocus="this.style.background='#ccffff'" onBlur="this.style.background='#ffffff'">
                      </div></td>
                    </tr>
                    <tr> 
                      <td height="1"> Nombre                      </td>
                      <td height="1" colspan="3"><div align="left">
                        <textarea name="nombre" cols="10" id="nombre" onFocus="this.style.background='#ccffff'" onBlur="this.style.background='#ffffff'" 
                        class="form-control" data-placement="right" title="Digite Descripcion" style="width: 350px"  readonly="true"
                        onKeyPress="if(event.keyCode==13){Obuscar.value=1;submit();} else {event.keyCode=8;}
                        if(event.keyCode==121){	javascript:window.close();}"><?php echo $nombre; ?></textarea>
                      </div></td>
                    </tr>
                    <tr> 
                      <td height="0">Minimo</td>
                      <td width="102"><input name="minimo" type="text"   id="minimo" value="<?php echo $minimo; ?>" size="10" 
                        class="form-control" data-placement="right" title="Digite Codigo Item" style="width: 150px" 
								onKeyPress="if(event.keyCode==13){titulo.nombre();} if(event.keyCode>=48 && event.keyCode<=58){} else {event.keyCode=8;}"
								onFocus="this.style.background='#ccffff'" onBlur="this.style.background='#ffffff'"></td>
                      <td width="139">Maximo</td>
                      <td width="958" height="0"><input name="maximo" type="text"   id="maximo" value="<?php echo $maximo; ?>" size="10" 
                        class="form-control" data-placement="right" title="Digite Codigo Item" style="width: 150px" 
								onKeyPress="if(event.keyCode==13){titulo.nombre();} if(event.keyCode>=48 && event.keyCode<=58){} else {event.keyCode=8;}"
								onFocus="this.style.background='#ccffff'" onBlur="this.style.background='#ffffff'"></td>
                    </tr>
                    <tr> 
                      <td colspan="4"><div align="center"> 
                          <input name="guardar" type="submit" id="guardar" value="Guardar" title="Clic para procesar"  class="btn btn-primary" onClick="oguardar.value=1;submit();" >
                          <input name="cerrar" type="submit" id="cerrar" value="Cerrar" title="Clic para cerrar"  class="btn btn-primary"" onClick="window.close();" >
                          <input name="oguardar" type="hidden" id="oguardar">
                          <input name="oculto" type="hidden" id="oculto">
                          <br>
                        </div></td>
                    </tr>
                  </table>
                    
</TD>
                </TR>
            </TBODY>
            </TABLE>
 </div>
</div>  
 
  
</form>
<div id="resultado"></div>
</body>
</html>
