<?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.close();\"";
	
	//window.opener.document.Frm.TxtCant.focus();
	//window.opener.document.getElementById("Frm").submit();
	//window.close();
		
}else{
	$StrMsg="onload=\"document.getElementById('TxtCan').focus();document.getElementById('TxtCan').select();\"";
}*/
?>
<html>
<head>
<title>Ventas Editar</title> 
<meta charset="utf-8">
<meta name="viewport" content="target-densitydpi=device-dpi, initial-scale=1.0, user-scalable=no" />
<?php
AddJs();
?>
<link href="css/bootstrap.css" rel="stylesheet">
<script type="text/javascript" src="ja/funciones.js"></script>
<script type="text/javascript">
$(document).ready(function(){  
   Inicializar();
   jF("TxtCan");
});

function ParseFrm(){
	var width = document.body.clientWidth;
	var height = document.body.clientHeight;
	//document.getElementById("Cli").value=width;
	//width=width -10;
	//document.getElementById("DivT").style.width=width+"px";
}

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;
	}

	var StrC=gv("TxtCan");
	var StrP=gv("TxtPre");
	var StrI=gv("TxtI");
	var StrH=gv("TxtH");
	
	AX("FV_EDITAR",StrC,StrP,StrI,StrH);
	
	window.opener.document.Frm.TxtCod.focus();	
	window.opener.document.getElementById("Frm").submit();
	window.close();
}

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>


<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>

<body  style="background-color:#FFF;padding: 0 0 0 0; margin:0 0 0 0;overflow:hidden;"  onLoad="ParseFrm();" onResize="ParseFrm();">
<form id="Frm" style="padding: 0 0 0 0; margin:0 0 0 0"  method="post" action="ven_re_editar.php" autocomplete="off">

<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 class="container" style="max-width:100%; margin:0 0 0 0; padding:0 0 0 0">   
    <div  style="height:100vh;">  
       <table id="Tab"  border="0" cellspacing="0" cellpadding="0" style="background-color:#FFF; height:100%; width:100%">
       
       <tr style="height:5%;">
       <td valign="top">
       <div style="height:100%; width:100%; background-color:#09C; min-height:50px; vertical-align:middle" >
            <table width="100%" border="0" height="100%" style="margin:0 0 0 0; padding: 0 0 0 0">
            <tr>
            <td width="15px">&nbsp;</td>
            <td width="48px"><img src="b.png" width="48" height="48" longdesc="../sales.png"></td>
            <td style="color:#FFF"><b>VENTAS EDITAR</b></td>
            <td >&nbsp;</td>
            </tr>
            </table>
       </div>
       </td>
       </tr>
       
       <tr style="height:5%;">
       <td valign="top">
       
     <div class="form-row" style=" margin-left:0px; margin-right:0px">    
    	<div class="form-group col-sm-12" style="margin:0 0 0 0; padding: 0 0 0 0;">
            <table width="100%" border="0" height="100%" style="margin:0 0 0 0; padding: 0 0 0 0">
            <tr>
            <td width="30%">
            <label >CODIGO</label>
            <input name="TxtNom" type="text" id="TxtNom" 
            class="form-control roi" value="<?php echo gs("COD","vproductos","ID=$IDPRO");?>"  
            tabindex="<?php echo ++$TI;?>" />

            </td>            
            <td width="70%">
            <label >DESCRIPCION</label>
            <input name="TxtCon" type="text" id="TxtCon" 
            class="form-control roi" value="<?php echo gs("DESCRIPCION","vproductos","ID=$IDPRO");?>"  
            tabindex="<?php echo ++$TI;?>"/>
            </td>
            </tr>
            </table>
        </div>            
	</div>
    
     <div class="form-row" style=" margin-left:0px; margin-right:0px">    
    	<div class="form-group col-sm-12" style="margin:0 0 0 0; padding: 0 0 0 0;">
            <table width="100%" border="0" height="100%" style="margin:0 0 0 0; padding: 0 0 0 0">
            <tr>
            <td width="50%">
            <label >MARCA</label>
            <input name="TxtNom" type="text" id="TxtNom" 
            class="form-control roi" value="<?php echo gs("MARCA","vproductos","ID=$IDPRO");?>"  
            tabindex="<?php echo ++$TI;?>" />

            </td>            
            <td width="30%">
            <label >STOCK</label>
            <input name="TxtCon" type="text" id="TxtCon" 
            class="form-control roi" value="<?php echo gn("SUM(stock)","stocks","id_producto=$IDPRO");?> / GENERAL"  
            tabindex="<?php echo ++$TI;?>"/>
            </td>
            </tr>
            </table>
        </div>            
	</div>
    
    
     <div class="form-row" style=" margin-left:0px; margin-right:0px">    
    	<div class="form-group col-sm-12" style="margin:0 0 0 0; padding: 0 0 0 0;">
            <table width="100%" border="0" height="100%" style="margin:0 0 0 0; padding: 0 0 0 0">
           
            <tr>
            <td >&nbsp;
			
            </td>
            </tr>
            </table>
        </div>            
	</div>
    
    
     <div class="form-row" style=" margin-left:0px; margin-right:0px">    
    	<div class="form-group col-sm-12" style="margin:0 0 0 0; padding: 0 0 0 0;">
            <table width="100%" border="0" height="100%" style="margin:0 0 0 0; padding: 0 0 0 0">
            <tr>
            <td width="30%">
            <label >CANTIDAD</label>
            <input name="TxtCan" type="text" id="TxtCan" 
            class="form-control ned" value="<?php echo $StrCan;?>"  
            onkeyup="fImporte();" tabindex="<?php echo ++$TI;?>" />

            </td>            
            <td width="35%">
            <label >PRECIO</label>
            <input name="TxtPre" type="text" id="TxtPre" 
            class="form-control ndd" value="<?php echo $StrPre;?>"  
            onkeyup="fImporte();" tabindex="<?php echo ++$TI;?>"/>
            </td>

            <td width="35%">
            <label >IMPORTE</label>
            <input name="TxtImp" type="text" id="TxtImp" 
            class="form-control roi" value="<?php echo $StrImp;?>"  
            tabindex="<?php echo ++$TI;?>"/>
            </td>
            </tr>
            </table>
        </div>            
	</div>
    
     <div class="form-row" style=" margin-left:0px; margin-right:0px">    
    	<div class="form-group col-sm-12" style="margin:0 0 0 0; padding: 0 0 0 0;">
            <table width="100%" border="0" height="100%" style="margin:0 0 0 0; padding: 0 0 0 0">
           
            <tr>
            <td colspan="2" valign="bottom" width="50%">
            <button type="button" id="CmdB" name="CmdB" class="btnp" style="background-color:#F90;width:100%;" 
            onclick="Aceptar();" tabindex="<?php echo $CX++?>">ACEPTAR</button>
            </td>
            
            <td valign="bottom" width="50%">
            <button type="button" id="CmdX" name="CmdX" class="btnp" style="background-color:#F90;width:100%;" 
            onclick="window.close();" tabindex="<?php echo $CX++?>">CANCELAR</button>
            </td>
            </tr>
            </table>
        </div>            
	</div>
    


       
       </td>
       </tr>
       
       
       <tr style="height:90%">
       <td valign="top">
       
       </td>
       </tr>   
       </table>
    </div>
</div>
</form>
</body>
</html>
