<?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");

date_default_timezone_set('America/Bogota');
$hora=date("H:i:s");
$fecha=date("Y-m-d");
?>
<!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>
 
 
 <script language="javascript">
function format(input)
{
var num = input.value.replace(/\./g,'');
if(!isNaN(num)){
num = num.toString().split('').reverse().join('').replace(/(?=\d*\.?)(\d{3})/g,'$1.');
num = num.split('').reverse().join('').replace(/^[\.]/,'');
input.value = num;
}

else{ //alert('Solo se permiten numeros');
input.value = input.value.replace(/[^\d\.]*/g,'');
}
}
</script>

</head>


<BODY onLoad="parametros.nombre.focus();">
<?php


include "../conexion.php";
$producto=$_REQUEST["producto"];
		
$precioventa="";
$sql_datosrs=mysqli_query($conexion,"SELECT precioventa from producto where id='".$producto."'");
while($datosrs= mysqli_fetch_row($sql_datosrs)){ $precioventa=number_format($datosrs[0],0,'','.');}  


if(isset($_REQUEST["oculto"]))
{ 
		 $precioventa=$_REQUEST["precioventa"];  		

		if($_REQUEST["oguardar"])
		{       $precioventa=str_replace('.','',$_POST["precioventa"]);
				if($precioventa>=0)
				 {
					$sql_insert=mysqli_query($conexion,"update  producto  set   
														precioventa='".trim($precioventa)."'
														where id=".$producto.""); 									
					 if ($sql_insert) 
						{   $mensaje="modifico";$mensa="Se Modifico el precio de venta del producto";
							$valor=1;	
							$sql_insert=mysqli_query($conexion,"INSERT INTO producto_precio (producto,precio,fecha,hora,usuario)
											VALUES    ('".$producto."','".$precioventa."','".$fecha."','".$hora."','".$vg_login."')");
						}
					 else
						 { $mensaje="error";$mensa="Error al modificar el registro"; }
				 }
				 else
				  { $mensaje="error";$mensa="Digite el precio de venta nuevo"; }
		
		  echo "<script>";   echo "alert('$mensa')"; echo "</script>";
		}
		
}


?>
<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 PRECIOS</div>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="texto" >
                    <tr> 
                      <td width="30%" height="1">Previo Venta Nuevo</td>
                      <td height="1" colspan="5"><div align="left">
                        <input name="precioventa" type="text"  id="precioventa"
                      class="form-control" data-placement="right"  style="width: 100%" 
                              value="<?php echo $precioventa; ?>" size="10" maxlength="10"
							 onkeyup="format(this)" onchange="format(this)" onfocus="format(this)"  
                           onkeypress="return valida(event);"  autocomplete="off">
                      </div></td>
                      <td width="32%" height="0" colspan="6" align="left">
                        <strong>
                        <input name="eli" type="submit" id="wli" value="Guardar" title="Clic para Guardar"  class="btn btn-primary" onClick="oguardar.value=1;submit();" >
                        
                       
                        </strong>
                        <input name="buscar" type="hidden" id="buscar3" value="Busca" title="Clic para Buscar" class="btn1" onClick="jq_busca_datos_parametros(document.parametros.id.value,'producto');" >
                        <input name="oguardar" type="hidden" id="oguardar2">
                      <input name="oculto" type="hidden" id="oculto2">                      <strong><img src='../imagenes/salir.png' width='50px' height='50px' 
						 onClick="javascript:window.close();" title="Clic para Cerrar"  /></strong></td>
                    </tr>
                  </table>
                    
</TD>
                </TR>
            </TBODY>
            </TABLE>
 </div>
</div>  

  
 <?php
 
		  $sql_datosrs=mysqli_query($conexion,"SELECT count(*) as contar from inventario
											   where producto='".$producto."'");
		 while($datosrs= mysqli_fetch_row($sql_datosrs)){ $contar=$datosrs[0];}
		  if($contar>=1)
		  {
			 echo "<center> <table width='100%' border='1' cellpadding='0' cellspacing='0' class='table table-hover' >";
						echo "<tr>";
						echo "<td class='btn-primary' align='center'>Factura</td>";
						echo "<td class='btn-primary' align='center'>Cantidad</td>";
						echo "<td class='btn-primary' align='center'>Precio Compra</td>";						
						echo "<td class='btn-primary' align='center'>Fecha Ingreso</td>";			
						echo "<td class='btn-primary' align='center'>Usuario</td>";						
						echo "</tr>";
			  
			  $sql_datosrs=mysqli_query($conexion,"SELECT factura,cantidad,precio,fechaingreso,usuario,id from inventario
										  where producto='".$producto."'
										  and factura<>''
										  order by id desc");
				$c=1;
				 while($datos= mysqli_fetch_row($sql_datosrs))//04
					{
						 $factura=$datos[0];
						 $cantidad=$datos[1];
						 $precio=$datos[2];
						 $fechaingreso=$datos[3];
						 $joset=$datos[4];
												 
						  echo "<tr>							 
							 <td >$factura</td>																					
							 <td>$cantidad</font></td>							 							 
							 <td style='font-size:14px;'><div align='right'>".number_format($precio)."</div></td>	
							 <td>$fechaingreso</td>
							 <td>$joset</td>			
							</tr>";
							$c++;
					} 
					 echo "</table></center>";
		   } 
 ?> 


<script type="text/javascript">
 <!--
 function displayKeyCode(evt)
 {
	 var charCode = (evt.which) ? evt.which : event.keyCode
	 if (charCode == 27) {javascript:window.close(); }//  escape
	 if (charCode == 13) { window.reload(); }//  escape

	 /*textBox.value = String.fromCharCode(charCode);
	 if (charCode == 8) textBox.value = "backspace"; //  backspace
	 if (charCode == 9) textBox.value = "tab"; //  tab
	 if (charCode == 13) textBox.value = "enter"; //  enter
	 if (charCode == 16) textBox.value = "shift"; //  shift
	 if (charCode == 17) textBox.value = "ctrl"; //  ctrl
	 if (charCode == 18) textBox.value = "alt"; //  alt
	 if (charCode == 19) textBox.value = "pause/break"; //  pause/break
	 if (charCode == 20) textBox.value = "caps lock"; //  caps lock
	 if (charCode == 27) textBox.value = "escape"; //  escape
	 if (charCode == 33) textBox.value = "page up"; // page up, to avoid displaying alternate character and confusing people	         
	 if (charCode == 34) textBox.value = "page down"; // page down
	 if (charCode == 35) textBox.value = "end"; // end
	 if (charCode == 36) textBox.value = "home"; // home
	 if (charCode == 37) textBox.value = "left arrow"; // left arrow
	 if (charCode == 38) textBox.value = "up arrow"; // up arrow
	 if (charCode == 39) textBox.value = "right arrow"; // right arrow
	 if (charCode == 40) textBox.value = "down arrow"; // down arrow
	 if (charCode == 45) textBox.value = "insert"; // insert
	 if (charCode == 46) textBox.value = "delete"; // delete
	 if (charCode == 91) textBox.value = "left window"; // left window
	 if (charCode == 92) textBox.value = "right window"; // right window
	 if (charCode == 93) textBox.value = "select key"; // select key
	 if (charCode == 96) textBox.value = "numpad 0"; // numpad 0
	 if (charCode == 97) textBox.value = "numpad 1"; // numpad 1
	 if (charCode == 98) textBox.value = "numpad 2"; // numpad 2
	 if (charCode == 99) textBox.value = "numpad 3"; // numpad 3
	 if (charCode == 100) textBox.value = "numpad 4"; // numpad 4
	 if (charCode == 101) textBox.value = "numpad 5"; // numpad 5
	 if (charCode == 102) textBox.value = "numpad 6"; // numpad 6
	 if (charCode == 103) textBox.value = "numpad 7"; // numpad 7
	 if (charCode == 104) textBox.value = "numpad 8"; // numpad 8
	 if (charCode == 105) textBox.value = "numpad 9"; // numpad 9
	 if (charCode == 106) textBox.value = "multiply"; // multiply
	 if (charCode == 107) textBox.value = "add"; // add
	 if (charCode == 109) textBox.value = "subtract"; // subtract
	 if (charCode == 110) textBox.value = "decimal point"; // decimal point
	 if (charCode == 111) textBox.value = "divide"; // divide
	 if (charCode == 112) textBox.value = "F1"; // F1
	 if (charCode == 113) textBox.value = "F2"; // F2
	 if (charCode == 114) textBox.value = "F3"; // F3
	 if (charCode == 115) textBox.value = "F4"; // F4
	 if (charCode == 116) textBox.value = "F5"; // F5
	 if (charCode == 117) textBox.value = "F6"; // F6
	 if (charCode == 118) textBox.value = "F7"; // F7
	 if (charCode == 119) textBox.value = "F8"; // F8
	 if (charCode == 120) textBox.value = "F9"; // F9
	 if (charCode == 121) textBox.value = "F10"; // F10
	 if (charCode == 122) textBox.value = "F11"; // F11
	 if (charCode == 123) textBox.value = "F12"; // F12
	 if (charCode == 144) textBox.value = "num lock"; // num lock
	 if (charCode == 145) textBox.value = "scroll lock"; // scroll lock
	 if (charCode == 186) textBox.value = ";"; // semi-colon
	 if (charCode == 187) textBox.value = "="; // equal-sign
	 if (charCode == 188) textBox.value = ","; // comma
	 if (charCode == 189) textBox.value = "-"; // dash
	 if (charCode == 190) textBox.value = "."; // period
	 if (charCode == 191) textBox.value = "/"; // forward slash
	 if (charCode == 192) textBox.value = "`"; // grave accent
	 if (charCode == 219) textBox.value = "["; // open bracket
	 if (charCode == 220) textBox.value = "\\"; // back slash
	 if (charCode == 221) textBox.value = "]"; // close bracket
	 if (charCode == 222) textBox.value = "'"; // single quote
	 */

	 var lblCharCode = getObject('spnCode');
	lblCharCode.innerHTML = 'KeyCode:  ' + charCode;

	return false;

 }
 function getObject(obj)
  {
	  var theObj;
	  if (document.all) {
		  if (typeof obj=='string') {
			  return document.all(obj);
		  } else {
			  return obj.style;
		  }
	  }
	  if (document.getElementById) {
		  if (typeof obj=='string') {
			  return document.getElementById(obj);
		  } else {
			  return obj.style;
		  }
	  }
	  return null;
  }
 //-->

</script>




<script>
function valida(e){
    tecla = (document.all) ? e.keyCode : e.which;
	// Patron de entrada, en este caso solo acepta numeros
    patron =/[0-9]/;
    tecla_final = String.fromCharCode(tecla);
    return patron.test(tecla_final);
}
</script>
  
</form>
<div id="resultado"></div>
</body>
</html>
