<?php
//
ini_set("session.cookie_lifetime",60*60*10);
ini_set("session.gc_maxlifetime", 60*60*10);
session_start();
include("cls_conexion.php");$CNN=new ClsMySQL();include("conexion23.php");
$StrMsg="";
//if(strlen($_SESSION['SYS_USER_ID'])==0){JsDir("login.php");	return;}
$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'");
	$StrUni=gn("dscto","temp_compras","temc_index=$StrI AND cod_temc='$StrH'");
}else{
	$StrPre="";
	$StrCan="";
	$StrUni="";
}
//-------------------------
if($StrCmd=="OK"){
	$StrC=V($_POST['TxtCan']);	
	$StrP=V($_POST['TxtPre']);
	$StrU=V($_POST['TxtUni']);
	$StrI=V($_POST['TxtI']);
	$StrH=V($_POST['TxtH']);
	$StrX=round((vbval($StrC) * vbval($StrU)) * vbval($StrP),2);
	$SQL="UPDATE temp_compras SET 
			temc_cant=$StrC,
			temc_precio=$StrP,
			dscto=$StrU,
			temc_imp=$StrX 
		WHERE cod_temc='$StrH' AND temc_index=$StrI";
	ejt($SQL);
	$StrMsg="onload=\"window.opener.document.Frm.CmdUP.click();window.close();\"";	
}

?>
<!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=utf-8" />
<title>COMPRAS - EDITAR</title>
<script src="jquery-1.7.2.min.js" type="text/javascript"></script>
<script src="jquery.maskedinput.min.js" type="text/javascript"></script>
<script type="text/javascript" src="fe/funciones.js"></script>
<script type="text/javascript">

function Aceptar(){	
	var c=gv("TxtCan");
	var p=gv("TxtPre");
	var z=gv("TxtUni");
	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;
	}
	if(jVal(z)<=0){
		alert("La cantidad de piezas debe ser mayor a cero");
		jFocus("TxtCan");
		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 Uni=document.getElementById("TxtUni").value;
	var Importe=parseFloat("0");

	if(Pre.trim().length==0)Pre="0";
	if(Can.trim().length==0)Can="0";
	if(Uni.trim().length==0)Can="0";

	Pre=jVal(Pre);
	Can=jVal(Can);
	Uni=jVal(Uni);

	Importe=(Can * Uni) * Pre;
	Importe=Importe.toFixed(2);
	document.getElementById("TxtImp").value=Importe;
}

</script>
<script>
$(document).ready(function(){
   $("#TxtDex").mask("99-99-99");
   $("#TxtHax").mask("99-99-99");
   jFocus("TxtPre");
});
</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:280px;
	position:absolute;
	left:50%;
	top:50%;
	background-color:#646464;
	margin:-140px 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;
}
.f2 {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="compras_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">COMPRAS 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: 465px;">
<div align="left" class="f2">COD : <?php 
$SEPARADOR=gs("aux_des","auxiliares","aux_tip='SIM'");
if(strlen($SEPARADOR)==0){$SEPARADOR="x";}

echo gs("COD","vproductos","ID=$IDPRO").$SEPARADOR.$StrUni;?></div></div>

<div id="layer6" style="position:absolute; left: 19px; top: 70px; width: 515px;">
<div align="left" class="f2">DES : <?php echo gs("DESCRIPCION","vproductos","ID=$IDPRO");?></div></div>

<div id="layer6" style="position:absolute; left: 19px; top: 105px; width: 461px;">
<div align="left" class="f2">MAR : <?php echo gs("MARCA","vproductos","ID=$IDPRO");?></div></div>


<div id="layer15" style="position:absolute; left: 25px; top: 152px; width: 52px;">
<div align="left" class="f2">PRECIO</div></div>
<input name="TxtPre" type="text" id="TxtPre" 
style="position:absolute; left: 24px; top: 169px; width: 70px;"
value="<?php echo $StrPre;?>"  
onkeydown="return SoloNum(this,event,'TxtCan');"
onkeyup="fImporte();"
tabindex="1" />

<div id="layer6" style="position:absolute; left: 108px; top: 152px; width: 59px;">
<div align="left" class="f2">CANTIDAD</div></div>
<input name="TxtCan" type="text" id="TxtCan" 
style="position:absolute; left: 108px; top: 169px; width: 70px;"
value="<?php echo $StrCan;?>"  
onkeydown="return SoloNum(this,event,'TxtUni');" 
onkeyup="fImporte();"
tabindex="2" />

<div id="layer6" style="position:absolute; left: 193px; top: 152px; width: 59px;">
<div align="left" class="f2">PIEZAS</div></div>
<input name="TxtUni" type="text" id="TxtUni" 
style="position:absolute; left: 192px; top: 169px; width: 70px;"
value="<?php echo $StrUni;?>"  
onkeydown="return SoloNum(this,event,'CmdB');" 
onkeyup="fImporte();"
tabindex="3" />

<div id="layer15" style="position:absolute; left: 277px; top: 152px; width: 52px;">
<div align="left" class="f2">IMPORTE</div></div>
<input name="TxtImp" type="text" id="TxtImp" 
style="position:absolute; left: 275px; top: 169px; width: 70px; background-color:#CCC; text-align:right"
value="<?php echo $StrImp;?>"  
onkeydown="return SoloNum(this,event,'CmdB');"
readonly="readonly" />


<input name="CmdB" type="button" 
style="position:absolute; left: 357px; top: 169px; width: 76px;"
id="CmdB" value="Aceptar" onclick="Aceptar();" tabindex="3" />
</div>
</center>	
</form>
</body>
</html>
