<?php
session_start();
include("cls_conexion.php");$CNN=new ClsMySQL();include("conexion23.php");
//
if(strlen($_SESSION['SYS_USER_ID'])==0){JsDir("login.php");	return;}
if(vbval($_SESSION['SYS_USER_GI'])!=USU_GET_GI($_SESSION['SYS_USER_ID'])){
	JsDir("cerrar.php");	
	return;
}
//++
$HW=V($_SESSION['SYS_HW']);
$StrGT="";$LStrMsg="";$LStrFoc="";$LStrMM="";
$LStrPag=V($_POST['TxtPag']);
//
include("compras_ep_fun.php");
//
$VP_RegXPag=20;
$LStrTR=0;//gn("count(*)","vproductos",$FF);
$LStrPag=PagGet($LStrPag,$StrCmd,$LStrTR,$VP_RegXPag);	
$TI=0;
?>
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Actualizar precios de compra</title>
<!--INI_SCRIPT------------------------------------------------------------------------------>
<?php AddJs(); ?>
<script type="text/javascript" src="fe/funcioney.js"></script>
<script type="text/javascript" src="fe/compras_ed.js"></script>
<!--FIN_SCRIPT------------------------------------->
<link rel="stylesheet" type="text/css" href="estilox.css"  />
<link rel="stylesheet" type="text/css" href="basix.css"  />
<style type="text/css">
.cF {height:800px;width:1100px;position:relative; <?php echo "top:0px";?>}
</style>
<script>
$(document).ready(function(){  
   Inicializar();   
});
</script>
<script language="javascript">
$(document).ready(function() {
	$(".botonExcel").click(function(event) {
		$("#datos_a_enviar").val( $("<div>").append( $("#Exportar_a_Excel").eq(0).clone()).html());
		$("#FormularioExportacion").submit();
});
});
function CAL(CAN,PIE,PRE,IMP){	
	var can=document.getElementById(CAN).value;
	var uni=document.getElementById(PIE).value;
	var pre=document.getElementById(PRE).value;
	var imp=0;
	//
	var Pre=jVal(pre);
	var Can=jVal(can);
	var Uni=jVal(uni);
	imp=Pre * Uni * Can;
	sv(IMP,imp.toFixed(2));
	RE_CAL();
}

function RE_CAL(){
	var new_tot=0;
	frm = document.getElementById("Frm");
	if (!frm) return;var mayor=0;	
	for(i=0; i<frm.elements.length; i++){
		var n=frm.elements[i].name;		
		if(n.indexOf("IMP_")>=0){
			new_tot=new_tot + jVal(frm.elements[i].value);
		}
	}
	sv("NEW_TOT_IMP",formatMoney(new_tot.toFixed(2),2,".",","));
	//
	var a=replaceAll(gv("TXT_TOT_IMP"),",","");
	var b=replaceAll(gv("NEW_TOT_IMP"),",","");
	var d=jVal(b)-jVal(a);
	sv("TXT_DIF",formatMoney(d.toFixed(2),2,".",","));
	
}
</script>
</head>

<body  <?php echo $LStrMsg;?>  >
<div align="center">

<div Id="DivFRM"  class="cF" style="background-color:#FFFFFF;" >
<form id="Frm" name="Frm" method="post" action="compras_ep.php">
<!--INI_TITULO-->
<div id="DivT" class="dT"  style="width:1100px">
<img src="img/unidades.png" class="iT" />
<div class="tT" style="width:500px">ACTUALIZAR PRECIOS DE COMPRA</div>
</div>
<!--FIN_TITULO-->
<div class="s1" style="left:177px; top: 114px; width: 142px; height: 18px;">
  <?php
	if(strlen($_PDF)>0){
		echo "<a href=\"$_PDF\" target=\"_new\">DESCARGAR</a>";	
	}
?>
  
</div>

<div class="ad" style="left:35px; top:132px; width: 139px; height: 18px;">COMPROBANTE</div>
<select name="Com" id="Com" 
class="lty" style="left:35px; top:149px; width: 139px;"
tabindex="<?php echo ++$TI;?>"  >
<?php
	echo FCBO_("com_nombre","comprobantes","com_nombre IN ('FACTURA','BOLETA','CONTENEDOR')",$Com,"N","S");
?>
</select>

<div class="s1" style="left:184px; top: 132px; width: 54px; height: 18px;">SERIE</div>
<input name="Ser"  type="text" 
class="lt"  id="Ser" 
style="left:184px; top: 149px; width: 67px;"
maxlength="11" 
tabindex="<?php echo ++$TI;?>"
value="<?php echo $Ser;?>"   />

<div class="s1" style="left:260px; top: 132px; width: 89px; height: 18px;">
NUMERO</div>
<input name="Num"  type="text" 
class="lt"  id="Num" 
style="left:259px; top: 149px; width: 97px;"
maxlength="150" 
tabindex="<?php echo ++$TI;?>"
value="<?php echo $Num;?>"   />

<div class="s1" style="left:365px; top: 132px; width: 89px; height: 18px;">
DAM</div>
<input name="Dam"  type="text" 
class="lt"  id="Dam" 
style="left:365px; top: 149px; width: 97px;"
maxlength="150" 
tabindex="<?php echo ++$TI;?>"
value="<?php echo $Dam;?>"   />


<input name="CmdF" type="button" id="CmdF"  
style="position:absolute; top:149px; left:481px; width: 92px;"
value="Filtrar" onClick="fFiltrar();"  
tabindex="<?php echo ++$TI;?>" />

<!--INI_TABLA----->
<div class="s1"
style="background:#ECF9FF; position:absolute; left: 35px; top: 182px; width: 1040px; height: 550px; overflow:auto;">
<div class="s1" style="left: 0px; top: 0px; width: 1030px;">
  <table id="Exportar_a_Excel" class="f4t" width="1016" border="1" style="border-collapse: collapse">
   <tr>
      <td colspan="12" bgcolor="#CCCCCC" height="18" align="center">
      <?php //echo PagBtn($LStrTR,$VP_RegXPag,$LStrPag);?>
      </td>
      </tr>   
    <tr>
      <td width="7" bgcolor="#CCCCCC">#</td>
      <td width="101" bgcolor="#CCCCCC">COMPROBANTE</td>
      <td width="40" bgcolor="#CCCCCC">SERIE</td>
      <td width="63" bgcolor="#CCCCCC">NUMERO</td>
      <td width="95" bgcolor="#CCCCCC">DAM</td>
      <td width="84" bgcolor="#CCCCCC">CODIGO</td>
      <td width="234" bgcolor="#CCCCCC">DESCRIPCION</td>
      <td width="106" bgcolor="#CCCCCC">LINEA</td>
      <td width="45" bgcolor="#CCCCCC">CANT</td>
      <td width="45" bgcolor="#CCCCCC">PIEZAS</td>
      <td width="55" bgcolor="#CCCCCC">$PRECIO</td>
      <td width="65" bgcolor="#CCCCCC">IMPORTE</td>
    </tr>   
    <?php
		$ZX=0;
		$TOT_IMP=0;
		$_COM="";
		$TOT_COM=0;
		$s="SELECT * FROM vcompras_det_ WHERE $FF ORDER BY CX";
		//$s=PagSql($s,$LStrPag,$VP_RegXPag,$LStrTR);
		//echo $s;  
		$rs = grs($s);
		while ($r = $rs->fetch_assoc()){
			$ZX++;
			$ID=$r['ID'];
			$PRE_ID="PRE_".$r['ID']."_".$r['CX']."_".$r['ID_PRO'];
			$CAN_ID="CAN_".$r['ID']."_".$r['CX']."_".$r['ID_PRO'];
			$PIE_ID="PIE_".$r['ID']."_".$r['CX']."_".$r['ID_PRO'];
			$IMP_ID="IMP_".$r['ID']."_".$r['CX']."_".$r['ID_PRO'];
			$CSS="";
			if($ZX%2==0){
				$CSS=" style=\"background-color:#DADADA\" ";
			}
			$TOT_IMP=$TOT_IMP + $r['IMP'];
			$COM=$r['COM'].$r['SER'].$r['NUM'].$r['DAM'];
			if($COM!=$_COM){
				$TOT_COM++;
				$_COM=$COM;
			}
	?>
    <tr <?php echo $CSS; ?>>
        <td ><?php echo $ZX;?></td>
        <td><?php echo $r['COM'];?></td> 
        <td><?php echo $r['SER'];?></td> 
        <td><?php echo $r['NUM'];?></td> 
        <td><?php echo $r['DAM'];?></td> 
        <td><?php echo $r['COD'];?></td>      
        <td><?php echo $r['DES'];?></td>
        <td><?php echo $r['LINEA'];?></td>
        <td>
        <input name="<?php echo $CAN_ID;?>" id="<?php echo $CAN_ID;?>"          
        class="ndd"  readonly
        style="position:inherit; width:45px; border:none; background-color:transparent; font-size:12px; padding-right:5px"  
        type="text" value="<?php echo $r['KA'];?>"  >
        </td>
        <td>
        <input name="<?php echo $PIE_ID;?>" id="<?php echo $PIE_ID;?>"          
        class="ndd"  readonly
        style="position:inherit; width:45px; border:none; background-color:transparent; font-size:12px; padding-right:5px"  
        type="text" value="<?php echo $r['PIEZAS'];?>"  >
        </td>
        <td>
        <input name="<?php echo $PRE_ID;?>" id="<?php echo $PRE_ID;?>"  onFocus="this.select()"
        class="ndd" style="position:inherit; width:55px"  
        onKeyUp="CAL('<?php echo $CAN_ID;?>','<?php echo $PIE_ID;?>','<?php echo $PRE_ID;?>','<?php echo $IMP_ID;?>')" 
        type="text" value="<?php echo $r['PR'];?>" tabindex="<?php echo ++$TI;?>" ></td>
		<td>
        <input name="<?php echo $IMP_ID;?>" id="<?php echo $IMP_ID;?>"          
        class="ndd" 
        style="position:inherit; width:65px; border:none; background-color:transparent; font-size:12px"  
        type="text" value="<?php echo NF($r['IMP'],2);?>"  >
        </td>     
    </tr>			
    <?php
		}
		$TOT_DIF=0;		
	?>
  </table>
</div>
</div>

<div class="s1" style="left:35px; top: 751px; width: 105px; height: 18px;">
<b>No COMPRAS</b> :</div>
<input name="NRO_COM"  type="text" 
class="rod"  id="NRO_COM"  readonly
style="left:127px; top: 748px; width: 64px;" 
maxlength="150" value="<?php echo $TOT_COM;?>"   />

<div class="s1" style="left:379px; top: 751px; width: 105px; height: 18px;">
TOTAL IMPORTE :</div>
<input name="TXT_TOT_IMP"  type="text" 
class="rod"  id="TXT_TOT_IMP"  readonly
style="left:488px; top: 748px; width: 100px;" 
maxlength="150" value="<?php echo NF2($TOT_IMP,2);?>"   />

<div class="s1" style="left:601px; top: 751px; width: 152px; height: 18px;">
NUEVO TOTAL IMPORTE :</div>
<input name="NEW_TOT_IMP"  type="text" 
class="rod"  id="NEW_TOT_IMP"  readonly
style="left:757px; top: 748px; width: 113px;" 
maxlength="150" value="<?php echo NF2($TOT_IMP,2);?>"   />

<div class="s1" style="left:878px; top: 751px; width: 89px; height: 18px;">
DIFERENCIA :</div>
<input name="TXT_DIF"  type="text" 
class="rod"  id="TXT_DIF"  readonly
style="left:970px; top: 748px; width: 105px;" 
maxlength="150" value="<?php echo NF2($TOT_DIF,2);?>"   />


<!--FIN_TABLA----->
<!--INI_OCULTOS-------------------------------->
<?php include("ocultox.php");?>
<input name="TXT_COM" id="TXT_COM" type="hidden" value="<?php echo $Com;?>">
<input name="TXT_SER" id="TXT_SER" type="hidden" value="<?php echo $Ser;?>">
<input name="TXT_NUM" id="TXT_NUM" type="hidden" value="<?php echo $Num;?>">
<input name="TXT_DAM" id="TXT_DAM" type="hidden" value="<?php echo $Dam;?>">
<!--FIN_OCULTOS-------------------------------->
<!--INI_BOTONES----->
<div id="DivBtn"  align="left"
style="position:absolute; left: 33px; top: 71px; width: 703px; height: 26px;">
<input name="CmdP" type="button" id="CmdP" class="btm"
value="Guardar" onClick="flGuardar();"  
tabindex="<?php echo ++$TI;?>" />
<input name="CmdB" type="button" id="CmdZ" class="btm"
value="Menu" onClick="fBuscar('menu.php');"  
tabindex="<?php echo ++$TI;?>" />
</div>
<!--FIN_BOTONES-->
</form>
<form action="ficheroExcel.php" 
method="post" target="_blank" 
id="FormularioExportacion" >
</form>

</div>
</div>
</body>
</html>
