<?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");
//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']);	
$GR=V($_GET['GR']);
if(strlen($GR)==0){
	$GR=V($_POST['TxtGR']);
}
//-------------------------
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.close();window.opener.document.Frm.CmdUP.click();\"";	
}else{
	$StrMsg="onload=\"document.getElementById('TxtPre').focus();document.getElementById('TxtPre').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=utf-8" />
<title>VENTAS - 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 po=gv("TxtPreO");
	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(p)<jVal(po)){
		if(gv("TxtAut")!=gv("TxtPAS")){
			alert("Para ingresar un precio menor ingrese la autorizacion");
			jFocus("TxtAut");
			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=parseFloat(Pre);
	Can=parseFloat(Can);
	Uni=parseFloat(Uni);

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

</script>
<script>
$(document).ready(function(){
   
});
</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:#666666;
	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="ventas_editar.php">
<center> 
<div Id="DivFRM"  class="centrarFrm" >
<div id="layer" style="position:absolute; left:30px; top: 24px; 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="TxtGR" type="hidden" id="TxtGR" value="<?php echo $GR;?>"/>
<input name="TxtAc" type="hidden" id="TxtAc" value="" />
<?php
$CLAVE=gs("valor","valores","dato='CLAVE_PRECIO'");
?>
<input name="TxtPAS" type="hidden" id="TxtPAS" value="<?php echo $CLAVE;?>"/>
</div>

<div id="layer6" style="position:absolute; left:30px; top: 68px; 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:30px; top: 92px; width: 480px;">
<div align="left" class="f2">DES : <?php echo gs("DESCRIPCION","vproductos","ID=$IDPRO");?></div></div>

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


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

<?php
$RO="";
$CSS="";
if(vbval($GR)==1){
	$RO=' readonly="readonly" ';
	$CSS='background-color:#CCC';
}
?>
<div id="layer6" style="position:absolute; left: 101px; top: 164px; width: 59px;">
<div align="left" class="f2">CANTIDAD</div></div>
<input name="TxtCan" type="text" id="TxtCan" 
style="position:absolute; left: 100px; top: 181px; width: 66px;<?php echo $CSS;?>"
value="<?php echo $StrCan;?>"  <?php echo $RO;?> 
onkeydown="return SoloNum(this,event,'TxtUni');" 
onkeyup="fImporte();" onfocus="this.select();"
tabindex="2" />



<div id="layer6" style="position:absolute; left: 177px; top: 164px; width: 59px;">
<div align="left" class="f2">PIEZAS</div></div>
<input name="TxtUni" type="text" id="TxtUni" 
style="position:absolute; left: 176px; top: 181px; width: 70px;<?php echo $CSS;?>"
value="<?php echo $StrUni;?>"  <?php echo $RO;?> 
onkeydown="return SoloNum(this,event,'CmdB');" onfocus="this.select();"
onkeyup="fImporte();"
tabindex="3" />

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

<div style="position:absolute; left: 428px; top: 162px; width: 59px;">
<div align="left" class="f2">AUTORIZAR</div></div>
<input name="TxtAut" type="password" id="TxtAut" 
style="position:absolute; left: 423px; top: 181px; width: 78px;"
tabindex="6" onkeydown="return SoloTextoEx(event,'CmdB');" 
value="" maxlength="15"
 />


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