<?php
session_start();
include("cls_conexion.php");$CNN=new ClsMySQL();include("conexion23.php");
//if(strlen($_SESSION['SYS_USER_ID'])==0){JsDir("login.php");	return;}
$IdU=$_SESSION['SYS_USER_ID'];
$POL_USU_MP=vbval(gs("mp","usuarios","id_usuario=$IdU"));
$StrId=V($_POST['TxtId']);
$StrCmd=V($_POST['TxtAc']);
//-------------------------
$StrI=V($_GET['I']);	
$StrH=V($_GET['H']);	
//-------------------------
if(strlen($StrI)>0){
	$StrPre=NF(gn("temc_precio","temp_compras","temc_index=$StrI AND cod_temc='$StrH'"),2);
	$StrCan=gn("temc_cant","temp_compras","temc_index=$StrI AND cod_temc='$StrH'");
	$StrImp=NF(gn("temc_imp","temp_compras","temc_index=$StrI AND cod_temc='$StrH'"),2);
	$IDPRO=gn("temc_id_producto","temp_compras","temc_index=$StrI AND cod_temc='$StrH'");
}else{
	$StrPre="";
	$StrCan="";
}
//-------------------------
if($StrCmd=="OK"){
	$StrC=V($_POST['TxtCan']);	
	$StrP=V($_POST['TxtPre']);
	$StrI=V($_POST['TxtI']);
	$StrH=V($_POST['TxtH']);
	$StrX=round(vbval($StrC) * vbval($StrP),2);
	ejt("UPDATE temp_compras ".
	    "SET temc_cant=$StrC,temc_precio=$StrP,temc_imp=$StrX ".
		"WHERE cod_temc='$StrH' AND temc_index=$StrI");
	$StrMsg="onload=\"window.opener.document.Frm.CmdUP.click();window.close();\"";	
}else{
	$StrMsg="onload=\"document.getElementById('TxtCan').focus();document.getElementById('TxtCan').select();\"";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Ventas - Buscar</title>

<?php AddJs(); ?>
<script type="text/javascript" src="funciones.js"></script>

<script type="text/javascript">
function Aceptar(){	
	var c=document.getElementById("TxtCan").value;
	var p=document.getElementById("TxtPre").value;
	if(jVal(c)<=0){
		alert("La cantidad debe ser un numero positivo");
		jFocus("TxtCan");
		return;
	}
	if(jVal(p)<0){
		alert("El precio no puede ser un valor negativo");
		jFocus("TxtPre");
		return;
	}
	document.getElementById("TxtAc").value="OK";
	document.getElementById("Frm").submit();
}

function fImporte(){
	var Pre=document.getElementById("TxtPre").value;
	var Can=document.getElementById("TxtCan").value;
	var Importe=parseFloat("0");
	if(Pre.trim().length==0)Pre="0";
	if(Can.trim().length==0)Can="0";
	Pre=parseFloat(Pre);
	Can=parseFloat(Can);
	Importe=Pre * Can;
	Importe=Importe.toFixed(2);
	document.getElementById("TxtImp").value=Importe;
}

</script>
<script>
$(document).ready(function(){
   $("#TxtDex").mask("99-99-99");
   $("#TxtHax").mask("99-99-99");
});
</script>
<style type="text/css">
<!--
body {
background-color: #CCC;
}
#Layer1 {
position:absolute;
left:345px;
top:115px;
width:123px;
height:35px;
z-index:1;
}
.centrarFrm{
	width:550px;
	height:200px;
	position:absolute;
	left:50%;
	top:50%;
	background-color:#666666;
	margin:-100px 0 0 -275px;
}
#Layer2 {
position:absolute;
left:409px;
top:205px;
width:82px;
height:24px;
z-index:1;
}
.Estilo1 {
font-family: Arial, Helvetica, sans-serif;
font-weight: bold;
color: #FFFFFF;
}
.Estilo2 {font-family: Arial, Helvetica, sans-serif; font-weight: bold; color: #FFFFFF; font-size: 12px; }
.Estilo3 {color: #FFFFFF; font-size: 12px; font-family: Arial, Helvetica, sans-serif;}
.Estilo4 {color: #000099}
.Estilo5 {color: #000000}

-->
</style>

</head>
<body  <?php echo $StrMsg;?>>
<form id="Frm" name="Frm" method="post" action="ventas_editar.php">
<center> 
<div Id="DivFRM"  class="centrarFrm" >
<div id="layer" style="position:absolute; left: 16px; top: 12px; width: 246px; height: 24px;">
<div align="left" class="Estilo1">VENTAS EDITAR</div></div>

<div >
<input name="TxtId" type="hidden" id="TxtId" value="<?php echo $StrId;?>"/>
<input name="TxtI" type="hidden" id="TxtI" value="<?php echo $StrI;?>"/>
<input name="TxtH" type="hidden" id="TxtH" value="<?php echo $StrH;?>"/>
<input name="TxtAc" type="hidden" id="TxtAc" value="" />
</div>

<div id="layer6" style="position:absolute; left: 19px; top: 39px; width: 42px;">
<div align="left" class="Estilo2">COD
</div></div>
<div id="layer6" style="position:absolute; left:82px; top: 39px; width: 42px;">
<div align="left" class="Estilo2">:
</div></div>

<div id="layer6" style="position:absolute; left: 95px; top: 39px; width: 338px;">
<div align="left" class="Estilo2"><?php echo gs("COD","vproductos","ID=$IDPRO");?>
</div></div>

<div id="layer6" style="position:absolute; left: 19px; top: 58px; width: 41px;">
<div align="left" class="Estilo2">DES
</div></div>
<div id="layer6" style="position:absolute; left: 82px; top: 58px; width: 41px;">
<div align="left" class="Estilo2">:
</div></div>

<div id="layer6" style="position:absolute; left: 95px; top: 58px; width: 440px;">
<div align="left" class="Estilo2">
<input name="TxtDes" type="text" id="TxtDes" 
style="width: 440px; background-color:#CCC;border-width:0;"
value="<?php echo gs("DESCRIPCION","vproductos","ID=$IDPRO");?>"  
tabindex="6" readonly="readonly" />
</div></div>

<div id="layer6" style="position:absolute; left: 19px; top: 82px; width: 44px;">
<div align="left" class="Estilo2">MARCA
</div></div>

<div id="layer6" style="position:absolute; left: 82px; top: 82px; width: 19px;">
<div align="left" class="Estilo2">:
</div></div>

<div id="layer6" style="position:absolute; left: 95px; top: 82px; width: 428px;">
<div align="left" class="Estilo2"><?php echo gs("MARCA","vproductos","ID=$IDPRO");?>
</div></div>

<div id="layer6" style="position:absolute; left: 19px; top: 102px; width: 60px;">
<div align="left" class="Estilo2">STOCK</div></div>

<div id="layer6" style="position:absolute; left: 95px; top: 102px; width: 424px;">
<div align="left" class="Estilo2">
<?php echo gn("SUM(stock)","stocks","id_producto=$IDPRO");?> / GENERAL
</div></div>

<div id="layer6" style="position:absolute; left:82px; top: 102px; width: 26px;">
<div align="left" class="Estilo2">:</div></div>

<div id="layer6" style="position:absolute; left: 98px; top: 141px; width: 59px;">
<div align="left" class="Estilo2">CANTIDAD</div></div>
<input name="TxtCan" type="text" id="TxtCan" 
style="position:absolute; left: 98px; top: 158px; width: 65px;"
value="<?php echo $StrCan;?>"  
onkeydown="return SoloNum(this,event,'TxtPre');" 
onkeyup="fImporte();"
tabindex="1" />

<div id="layer15" style="position:absolute; left: 177px; top: 141px; width: 52px;">
<div align="left" class="Estilo2">PRECIO</div></div>
<input name="TxtPre" type="text" id="TxtPre" 
style="position:absolute; left: 176px; top: 158px; width: 66px;"
value="<?php echo $StrPre;?>"   onfocus="this.select();"
onkeydown="return SoloNum(this,event,'CmdB');"
<?php
if($POL_USU_MP==0){
	echo " readonly=\"readonly\" ";
}
?>
onkeyup="fImporte();"
tabindex="2" />

<div id="layer15" style="position:absolute; left: 257px; top: 141px; width: 52px;">
<div align="left" class="Estilo2">IMPORTE</div></div>
<input name="TxtImp" type="text" id="TxtImp" 
style="position:absolute; left: 255px; top: 158px; width: 88px; background-color:#CCC; text-align:right"
value="<?php echo $StrImp;?>"  
onkeydown="return SoloNum(this,event,'TxtCant');"
tabindex="3" readonly="readonly" />

<input name="CmdB" type="button" 
style="position:absolute; left: 355px; top: 158px; width: 76px;"
id="CmdB" value="Aceptar" onclick="Aceptar();" tabindex="4" />

<input name="CmdB" type="button" 
style="position:absolute; left: 436px; top: 158px; width: 76px;"
id="CmdB" value="Cancelar" onclick="window.close();" tabindex="5" />
</div>
</center>	
</form>
</body>
</html>
