<?php
session_start();
include("cls_conexion.php");$CNN=new ClsMySQL();include("conexion23.php");
//
if(strlen($_SESSION['SYS_USER_ID'])==0){JsDir("login.php");	return;}
//
$HW=$_SESSION['SYS_HW'];
$StrGT="";$LStrMsg="";$LStrFoc="";$LStrMM="";
$LStrPag=V($_POST['TxtPag']);
//
include("lq_rpt_mov_fun.php");
//
$VP_RegXPag=200;
$LStrTR=gn("count(*)","t_productos","$FF");
$LStrPag=PagGet($LStrPag,$StrCmd,$LStrTR,$VP_RegXPag);	
$TI=0;

?>
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Reporte de movimiento de productos</title>
<!--INI_SCRIPT------------------------------------------------------------------------------>
<?php AddJs(); ?>
<script type="text/javascript" src="fe/funcionex.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:1300px;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();
});
});


</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="lq_rpt_mov.php">
<!--INI_TITULO-->
<div id="DivT" class="dT"  style="width:1300px">
<img src="img/unidades.png" class="iT" />
<div class="tT" style="width:1000px">REPORTE DE MOVIMIENTO DE PRODUCTOS</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: 108px; height: 18px;">LINEA</div>
<select name="Lin" id="Lin" 
class="lty" style="left:35px; top:149px; width: 110px;"
tabindex="<?php echo ++$TI;?>"  >
<?php
	echo FCBO("lin_nombre","lineas","id_linea>0",$Lin,"S","N");
?>
</select>

<div class="s1" style="left:153px; top: 132px; width:78px; height: 18px;">CODIGO</div>
<input name="Cod"  type="text" 
class="lt"  id="Cod" 
style="left:153px; top: 149px; width: 96px;"
maxlength="30" 
tabindex="<?php echo ++$TI;?>"
value="<?php echo $Cod;?>"   />

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

<div class="ad" style="left:489px; top:117px; width: 67px; height: 18px;">DESDE</div>
<div class="EV" style="left: 489px; top: 131px; width: 97px;"><u><a onClick="sh('Dex')">(dd-mm-yy) +</a></u></div>
<input name="Dex" type="text" id="Dex" 
class="fe"
style="left:489px; top: 149px; width: 84px;" value="<?php echo $Dex;?>"  
tabindex="<?php echo ++$TI;?>" />

<div class="ad" style="left:584px; top:117px; width: 65px; height: 18px;">HASTA</div>
<div class="EV" style="left:584px; top: 131px; width: 85px;"><u><a onClick="sh('Hax')">(dd-mm-yy) +</a></u></div>
<input name="Hax" type="text" id="Hax" 
class="fe"
style="left:584px; top: 149px; width: 80px;" value="<?php echo $Hax;?>"  
tabindex="<?php echo ++$TI;?>" />


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

<!--INI_TABLA----->
<div class="s1"
style="background:#ECF9FF; position:absolute; left: 35px; top: 182px; width: 1255px; height: 550px; overflow:auto;">
<div class="s1" style="left: 0px; top: 0px; width: 1231px; z-index:0;">
  <table id="Exportar_a_Excel" class="f4t" width="1223" border="1" style="border-collapse: collapse">
   <tr>
      <td colspan="10" bgcolor="#CCCCCC" height="18" align="center">
      <?php echo PagBtn($LStrTR,$VP_RegXPag,$LStrPag);?>
      </td>
      </tr>   
    <tr>
      <td width="140" bgcolor="#CCCCCC">CODIGO</td>
      <td width="380" bgcolor="#CCCCCC">DESCRIPCION</td>
      <td width="127" bgcolor="#CCCCCC">LINEA</td>
      <td width="108" bgcolor="#CCCCCC">PV. MIN</td>
      <td width="108" bgcolor="#CCCCCC">PV.MAX</td>
      <td width="136" bgcolor="#CCCCCC">TOT.INGRESO</td>
      <td width="89" bgcolor="#CCCCCC">TOT.SALIDA</td>
      <td width="83" bgcolor="#CCCCCC">STOCK</td>
      <td width="83" bgcolor="#CCCCCC">SEP</td>
      <td width="83" bgcolor="#CCCCCC">E.T.</td>
    </tr>   
    <?php
		$s="SELECT pro_pie,pro_id,pro_cod,pro_des,pro_lin,ROUND(pro_pmi,3) as PM,
		    ROUND(pro_pma,3) as PW,pro_sto,pro_sep,pro_etr
		    FROM t_productos WHERE $FF ORDER BY pro_cod,pro_pie";
		$s=PagSql($s,$LStrPag,$VP_RegXPag,$LStrTR);
		$rs = grs($s);
		while ($r = $rs->fetch_assoc()){
			$_PIE=$r['pro_pie'];
			$_IDP=$r['pro_id'];			
			//+++++++++++++++++++++++++++++++++++++++++++
			$z="SELECT SUM(CA) FROM vcom_control WHERE IDP=$_IDP AND PIE=$_PIE AND ANU='N' AND FEC>='$Dex_' AND FEC<='$Hax_' AND ET='NO'"; 	
			$rz = grs($z);
			$row = $rz->fetch_row();
			$RES= (is_null($row[0])) ? 0 : $row[0];
			$TOT_INGRESO=$RES;
			//echo "COM:".$RES."<br>";
			//
			$z="SELECT SUM(CA) FROM vdev_control WHERE IDP=$_IDP AND PIE=$_PIE AND ANU='N' AND FEC>='$Dex_' AND FEC<='$Hax_' AND TIP='D'"; 	
			$rz = grs($z);
			$row = $rz->fetch_row();
			$RES= (is_null($row[0])) ? 0 : $row[0];
			$TOT_INGRESO=$TOT_INGRESO + $RES;
			//echo "DEV:".$RES."<br>";
			//+
			$z="SELECT SUM(CA) FROM vaju_control WHERE IDP=$_IDP AND PIE=$_PIE AND ANU='N' AND FEC>='$Dex_' AND FEC<='$Hax_' AND ACC='A'"; 	
			$rz = grs($z);
			$row = $rz->fetch_row();
			$RES= (is_null($row[0])) ? 0 : $row[0];
			$TOT_INGRESO=$TOT_INGRESO + $RES;
			//echo "AJU:".$RES."<br>";
			//+
			$z="SELECT SUM(CAJ) FROM vajup_control WHERE IDP=$_IDP AND PIE_R=$_PIE AND ANU='N' AND FEC>='$Dex_' AND FEC<='$Hax_' AND ACC='Q'"; 	
			$rz = grs($z);
			$row = $rz->fetch_row();
			$RES= (is_null($row[0])) ? 0 : $row[0];
			$TOT_INGRESO=$TOT_INGRESO + $RES;
			//echo "AJUP:".$RES."<br>";
			//+			
			$z="SELECT SUM(CA) FROM vajux_control WHERE IDP=$_IDP AND PIE=$_PIE AND FEC>='$Dex_' AND FEC<='$Hax_' AND ACC='A'"; 	
			$rz = grs($z);
			$row = $rz->fetch_row();
			$RES= (is_null($row[0])) ? 0 : $row[0];
			$TOT_INGRESO=$TOT_INGRESO + $RES;
			//echo "AJUX:".$RES."<br>";
			//+
			$z="SELECT SUM(GE_KA) FROM vkar_transformaciones WHERE ID_PRO=$_IDP AND GE_PIE=$_PIE AND FEC>='$Dex_' AND FEC<='$Hax_'"; 	
			$rz = grs($z);
			$row = $rz->fetch_row();
			$RES= (is_null($row[0])) ? 0 : $row[0];
			$TOT_INGRESO=$TOT_INGRESO + $RES;
			//echo "TRANS:".$RES."<br>";
			//+
			$z="SELECT SUM(SU_KA) FROM vkar_transformaciones WHERE ID_PRO=$_IDP AND SU_PIE=$_PIE AND FEC>='$Dex_' AND FEC<='$Hax_'"; 	
			$rz = grs($z);
			$row = $rz->fetch_row();
			$RES= (is_null($row[0])) ? 0 : $row[0];
			$TOT_INGRESO=$TOT_INGRESO + $RES;
			//echo "TRANZ:".$RES."<br>";
			//+
			//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
			$z="SELECT SUM(CA) FROM vgin_control WHERE IDP=$_IDP AND PIE=$_PIE AND ANU='N' AND FEC>='$Dex_' AND FEC<='$Hax_' "; 	
			$rz = grs($z);
			$row = $rz->fetch_row();
			$RES= (is_null($row[0])) ? 0 : $row[0];
			$TOT_EGRESO=$RES;
			//echo "-GI:".$RES."<br>";
			//+
			$z="SELECT SUM(CA) FROM vaju_control WHERE IDP=$_IDP AND PIE=$_PIE AND ANU='N' AND FEC>='$Dex_' AND FEC<='$Hax_' AND ACC='Q'"; 	
			$rz = grs($z);
			$row = $rz->fetch_row();
			$RES= (is_null($row[0])) ? 0 : $row[0];
			$TOT_EGRESO=$TOT_EGRESO + $RES;
			//echo "-AJU:".$RES."<br>";
			//+
			$z="SELECT SUM(CAJ) FROM vajup_control WHERE IDP=$_IDP AND PIE_O=$_PIE AND ANU='N' AND FEC>='$Dex_' AND FEC<='$Hax_' AND ACC='Q'"; 	
			$rz = grs($z);
			$row = $rz->fetch_row();
			$RES= (is_null($row[0])) ? 0 : $row[0];
			$TOT_EGRESO=$TOT_EGRESO + $RES;
			//echo "-AJUP:".$RES."<br>";
			//+
			$z="SELECT SUM(CA) FROM vajux_control WHERE IDP=$_IDP AND PIE=$_PIE AND FEC>='$Dex_' AND FEC<='$Hax_' AND ACC='Q'"; 
			$rz = grs($z);
			$row = $rz->fetch_row();
			$RES= (is_null($row[0])) ? 0 : $row[0];
			$TOT_EGRESO=$TOT_EGRESO + $RES;
			//echo "-AJUX:".$RES."<br>";
			//+
			$z="SELECT SUM(CA) FROM vven_control WHERE IDP=$_IDP AND PIE=$_PIE AND FEC>='$Dex_' AND FEC<='$Hax_' AND ANU='N' AND ALTER_STOCK=1"; 	
			$rz = grs($z);
			$row = $rz->fetch_row();
			$RES= (is_null($row[0])) ? 0 : $row[0];
			$TOT_EGRESO=$TOT_EGRESO + $RES;
			//echo "-VEN:".$RES."<br>";
			//+
			$z="SELECT SUM(CA) FROM vguia_control WHERE IDP=$_IDP AND PIE=$_PIE AND FEC>='$Dex_' AND FEC<='$Hax_' AND ANU='N' AND ALTER_STOCK=1";	
			$rz = grs($z);
			$row = $rz->fetch_row();
			$RES= (is_null($row[0])) ? 0 : $row[0];
			$TOT_EGRESO=$TOT_EGRESO + $RES;
			//echo "-GIA:".$RES."<br>";
			//
			$z="SELECT SUM(SA_KA) FROM vkar_transformaciones WHERE ID_PRO=$_IDP AND SA_PIE=$_PIE AND FEC>='$Dex_' AND FEC<='$Hax_' ";	
			$rz = grs($z);
			$row = $rz->fetch_row();
			$RES= (is_null($row[0])) ? 0 : $row[0];
			$TOT_EGRESO=$TOT_EGRESO + $RES;
			//echo "-TRANS:".$RES."<br>";
			//
			$z="SELECT SUM(RE_KA) FROM vkar_transformaciones WHERE ID_PRO=$_IDP AND RE_PIE=$_PIE AND FEC>='$Dex_' AND FEC<='$Hax_' ";	
			$rz = grs($z);
			$row = $rz->fetch_row();
			$RES= (is_null($row[0])) ? 0 : $row[0];
			$TOT_EGRESO=$TOT_EGRESO + $RES;
			//echo "-TRANZ:".$RES."<br>";
			//+++++++++++++++++++++++++++++++++++++++++++
			$TOT_STOCK=$TOT_INGRESO - $TOT_EGRESO;
			$TOT_DIFER=	$TOT_STOCK - $r['pro_sto'];
	?>
    <tr>
        <td><?php echo $r['pro_cod']."x".$r['pro_pie'];?></td>
        <td><?php echo $r['pro_des'];?></td>
        <td><?php echo $r['pro_lin'];?></td>
        <td align="right" class="td_n"><?php echo $r['PM'];?></td>
        <td align="right" class="td_n"><?php echo $r['PW'];?></td>
        <td align="right" class="td_n"><?php echo $TOT_INGRESO;?></td>         
        <td align="right" class="td_n"><?php echo $TOT_EGRESO;?></td>         
        <td align="right" class="td_n"><?php echo $TOT_STOCK;?></td>
        <td align="right" class="td_n"><?php echo $r['pro_sep'];?></td>         
        <td align="right" class="td_n"><?php echo $r['pro_etr'];?></td>        
    </tr>			
    <?php
		}
	?>
  </table>
</div>
</div>
<!--FIN_TABLA----->
<!--INI_OCULTOS-------------------------------->
<?php include("ocultox.php");?>
<!--FIN_OCULTOS-------------------------------->
<!--INI_BOTONES----->
<div id="DivBtn"  align="left"
style="position:absolute; left: 33px; top: 71px; width: 703px; height: 26px;">
<input name="CmdB" type="button" id="CmdZ" class="btm"
value="Volver" onClick="fBuscar('menu.php');"  
tabindex="<?php echo ++$TI;?>" />
</div>
<!--FIN_BOTONES-->
</form>
<form action="ficheroExcel.php" method="post" target="_blank" id="FormularioExportacion" >
<div style="position:absolute; left: 149px; top: 72px; width: 45px; height: 15px;">  
<input name="" type="button" class="botonExcel" value="Exportar" />
<input type="hidden" id="datos_a_enviar" name="datos_a_enviar" />
</div>
</form>
</div>
</div>
</body>
</html>
