<?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;}
	//-------------------------		
	if(vbval($_SESSION['SYS_USER_GI'])!=USU_GET_GI($_SESSION['SYS_USER_ID'])){
		JsDir("cerrar.php");	
		return;
	}
	$HW=$_SESSION['SYS_HW'];
	$HW=$HW."_SP";
	//-------------------------
	$StrId=V($_POST['TxtId']);
	$StrCmd=V($_POST['TxtAc']);	
	//-------------------------
	$StrONE=trim(V($_GET['CmdB']));	
	//-------------------------
	$StrEmp=V($_POST['CboEmp']);		
	$StrCod=V($_POST['TxtCod']);		
	$StrDes=V($_POST['TxtDes']);
	$StrMar=V($_POST['CboMar']);
	$Sto=V($_POST['Sto']);
	$Sep=V($_POST['Sep']);
	$Tra=V($_POST['Tra']);
	$Uso=V($_POST['Uso']);
	//
	if(strlen($Sto)==0)$Sto="TODOS";
	if(strlen($Sep)==0)$Sep="TODOS";
	if(strlen($Tra)==0)$Tra="TODOS";
	if(strlen($Uso)==0)$Uso="TODOS";
	if(strlen($StrEmp)==0)$StrEmp=GE("S");
	//
	$StrEmp_=LIKE($StrEmp);
	if(strlen($StrCmd)==0)$StrCmd=V($_GET['TxtAc']);
	if($StrCmd=="X" || strlen($StrCmd)==0){
		$StrLin="TODOS";
		$StrMar="TODOS";	
	}
	//-------------------------
	$StrCodT=$StrCod."%";
	$StrDesT=$StrDes."%";
	$StrMarT=$StrMar;
	if($StrMarT=="TODOS") $StrMarT="%";
	if($Uso=="TODOS"){
		$UsoT="%";
	}else{
		if($Uso=="SI"){
			$UsoT="S";
		}else{
			$UsoT="N";
		}
	}
	$B=V($_GET['B']);
	//-------------------------
	$LStrFoc="document.getElementById('TxtCod').focus();";
	$LStrMsg="onload=\"$LStrFoc;\"";
?>
<!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>Reporte de Stock (Stock, separado o en transito mayor a cero)</title>
<?php AddJs();?>
<script type="text/javascript" src="fe/funciones.js"></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>

<style type="text/css">
<!--
body {
	background-color: #CCC;
}


#Layer1 {
	position:absolute;
	left:345px;
	top:115px;
	width:123px;
	height:35px;
	z-index:1;
}
.estilo888 {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
color: #003366;
font-weight: bold;
}
.centrarFrm{
	width:1800px;
	height:600px;
	position:relative;
	left:0px;
	top:10px;
	background-color:#006699;

}
#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;}
.eS4 {color: #000099}
.Estilo5 {color: #000000}
#Frm center #DivFRM #layer3 .f2 table tr td {
	color: #000;
	text-align: left;
}
#Frm center #DivFRM #layer3 .f2 table {
	font-weight: normal;
}

-->
</style>
<style type="text/css">
  table th { text-align: right; }
  table td { text-align: left; }
</style>
</head>
<body  <?php echo $StrMsg;?>>
<div Id="DivFRM"  class="centrarFrm" >
<form id="Frm" name="Frm" method="post" action="stockpersonalizado_sz.php">
<center> 

    <div id="layer6" style="position:absolute; left: 169px; top: 89px; width: 64px;">
      <div align="left" class="f2" >CODIGO</div>
    </div>
    <div id="layer5" style="position:absolute; left: 69px; top: 50px; width: 205px; height: 28px;">
      <div align="left" class="f2">
        <input name="CmdV" type="button" id="CmdV" 
        value="Volver" onclick="fVolver('menu.php');" />
        <input type="hidden" name="TxtAc" id="TxtAc" />
        <input type="hidden" name="TxtPag" id="TxtPag" value="<?php echo $LStrPag; ?>" />
      </div>
    </div>
<div align="left" 
style="height:382px; width:1747px; overflow-x:hidden; position:absolute; left: 21px; top:145px; overflow-y:scroll; color: #0FF; background-color: #FFFFFF; layer-background-color: #FFFFFF; border: 1px none #000000;">
<?php
		$COLOR=0;
		$Mar=$P3."%";
		$Cod=$P4."%";
		$T=110+400+120+180+(gn("count(*)","vis_almacenes","IDA>0 AND ENC LIKE '$StrEmp_'")*60)+120;
		$s="<table id=\"Exportar_a_Excel\" style=\"width:$T"."px; top:0px\" border=\"1\" cellpadding=\"0\" ".
		   "cellspacing=\"0\" bgcolor=\"#FFFFFF\" class=\"estilo888\" >";
		$t=$s;
		$s="";
		$cx=0;
		$F="";
		//
		$F="<tr  height=\"10 px\">";
		$F=$F."<td style=\"width:110px\" bgcolor=\"#CCCCCC\">CODIGO</td> ";
		$F=$F."<td style=\"width:400px\" bgcolor=\"#CCCCCC\">DESCRIPCION</td>";
		$F=$F."<td style=\"width:120px\" bgcolor=\"#CCCCCC\">LINEA</td>";
		$F=$F."<th style=\"width:60px\" bgcolor=\"#CCCCCC\">PV MIN</th>";
		$F=$F."<th style=\"width:60px\" bgcolor=\"#CCCCCC\">PV MAX</th>";
		$F=$F."<th style=\"width:60px\" bgcolor=\"#CCCCCC\">STOCK</th>";
		//
		$TIE_CX=0;
		$TIE_AR[$TIE_CX]=0;
		$z="SELECT ANC,IDA FROM vis_almacenes ".
		   "WHERE IDA>0 AND ENC LIKE '$StrEmp_' ORDER BY ANC";
		$result = grs($z);
		while ($roww = $result->fetch_row()){		 
			$F=$F."<td  align=\"right\" style=\"width:60px\" bgcolor=\"#CCCCCC\">$roww[0]</td>";
			$TIE_CX++;
			$TIE_AR[$TIE_CX]=$roww[1];
		}
		//echo $s;		
		$F=$F."<td style=\"width:60px\" align=\"right\" bgcolor=\"#CCCCCC\">SEP.</td>";
		$F=$F."<td style=\"width:60px\" align=\"right\" bgcolor=\"#CCCCCC\">E.T.</td>";
		$F=$F."</tr>";
		$s=$s.$F;
		////////////////////////////////////////////////////////////////////////////////////
		if($B=="N"){
			$WW="pro_id= -1";
		}else{			
			$WW="id_pro>0 AND pro_cod LIKE '$StrCodT' AND pro_des LIKE '$StrDesT' AND pro_lin LIKE '$StrMarT' AND  pro_uso LIKE '$UsoT' ";
			if($Sto!="TODOS"){
				if($Sto=="MAYOR A CERO"){
					$WW=$WW." AND pro_sto>0 ";
				}else{
					if($Sto=="IGUAL A CERO"){
						$WW=$WW." AND pro_sto=0 ";
					}else{
						$WW=$WW." AND pro_sto<0 ";
					}
				}
			}
			if($Sep!="TODOS"){
				if($Sep=="MAYOR A CERO"){
					$WW=$WW." AND pro_sep>0 ";
				}else{
					if($Sep=="IGUAL A CERO"){
						$WW=$WW." AND pro_sep=0 ";
					}else{
						$WW=$WW." AND pro_sep<0 ";
					}
				}
			}
			if($Tra!="TODOS"){
				if($Tra=="MAYOR A CERO"){
					$WW=$WW." AND pro_etr>0 ";
				}else{
					if($Tra=="IGUAL A CERO"){
						$WW=$WW." AND pro_etr=0 ";
					}else{
						$WW=$WW." AND pro_etr<0 ";
					}
				}
			}
		}
		$SUMA_STOCK=0;
		$sql="SELECT pro_id as ID, pro_cod as COD,pro_pie as PIE,TRIM(LEFT(pro_des,45)) as DES,
			  TRIM(LEFT(pro_lin,35)) as LIN,pro_roj as ROJ,pro_ama as AMA,
			  ROUND(pro_pmi,3) as PMI,ROUND(pro_pma,3) as PMA,pro_sep as SEP,
			  pro_etr as TRA,pro_sto as STO
			  FROM t_productos
			  WHERE $WW ORDER BY pro_cod,pro_des ";
		//echo $sql;
		if($StrEmp=="TODOS"){			
			$result = grs($sql);
			while ($row = $result->fetch_assoc()){		 
				  $IDP=$row['ID'];
				  $COD=$row['COD'];
				  $DES=$row['DES'];
				  $LIN=$row['LIN'];
				  $ROJ=$row['ROJ'];
				  $AMA=$row['AMA'];
				  $PIE=$row['PIE'];			  
				  $SEP=$row['SEP'];			  
				  $TRA=$row['TRA'];			  
				  $PMI=$row['PMI'];			  
				  $PMA=$row['PMA'];			  
				  $STO=$row['STO'];			  
				  //
				  $s=$s."<tr>";
				  $s=$s."<td>".$COD."x".$PIE."</td>";
				  $s=$s."<td>".$DES."</td>";
				  $s=$s."<td>".$LIN."</td>";			  
				  $s=$s."<td>".$PMI."</td>";
				  $s=$s."<td>".$PMA."</td>";			  
				  if($STO<=$ROJ){
					  $COLOR="#FC8686";	
				  }else{
					  if($STO<=$AMA){
						  $COLOR="#FAEF9F";	
					  }else{
						  $COLOR="#CDDDEF";
					  }				  
				  }			  
				  $s=$s."<td bgcolor=\"$COLOR\" > ".$STO."</td>";			  
				  //
				  for($i=1;$i<=$TIE_CX;$i++){  		 
					$ss="SELECT IF(SUM(sp_cantidad) IS NULL,0,SUM(sp_cantidad)) AS ST 
						 FROM stocks_presentaciones 
						 WHERE sp_id_producto=$IDP AND sp_presentacion=$PIE AND sp_id_almacen=".$TIE_AR[$i];		 
					$rss = grs($ss);
					$roww = $rss->fetch_row();
					$STO= $roww[0];		 				
					$s=$s."<td>$STO</td>";
				  }
				  //			  
				  $s=$s."<td>$SEP</td>"; 
				  $s=$s."<td>$TRA</td>"; 
				  $s=$s."</tr>";
				  //
			}		
		}else{
			$result = grs($sql);
			while ($row = $result->fetch_assoc()){		 
				  $IDP=$row['ID'];				 
				  $PIE=$row['PIE'];	
				  //
				  $oo="";
				  $SUMA_STOCK=0;
				  for($i=1;$i<=$TIE_CX;$i++){  		 
					$ss="SELECT IF(SUM(sp_cantidad) IS NULL,'@',SUM(sp_cantidad)) AS ST 
						 FROM stocks_presentaciones 
						 WHERE sp_id_producto=$IDP AND sp_presentacion=$PIE AND sp_id_almacen=".$TIE_AR[$i];		 
					$rss = grs($ss);
					$roww = $rss->fetch_row();
					$STO= $roww[0];	
					$SUMA_STOCK=$SUMA_STOCK+$STO;
					$oo=$oo."<td>$STO</td>";
				  }
				  $ti_null=substr_count($oo,"@");
				  if($ti_null!=$TIE_CX){
				      $oo=str_replace("@","0",$oo);
					  $COD=$row['COD'];
					  $DES=$row['DES'];
					  $LIN=$row['LIN'];
					  $ROJ=$row['ROJ'];
					  $AMA=$row['AMA'];
					  $SEP=$row['SEP'];			  
					  $TRA=$row['TRA'];			  
					  $PMI=$row['PMI'];			  
					  $PMA=$row['PMA'];			  
					  $STO=$row['STO'];			 
					  $s=$s."<tr>";
					  $s=$s."<td>".$COD."x".$PIE."</td>";
					  $s=$s."<td>".$DES."</td>";
					  $s=$s."<td>".$LIN."</td>";			  
					  $s=$s."<td>".$PMI."</td>";
					  $s=$s."<td>".$PMA."</td>";			  
					  if($SUMA_STOCK<=$ROJ){
						  $COLOR="#FC8686";	
					  }else{
						  if($SUMA_STOCK<=$AMA){
							  $COLOR="#FAEF9F";	
						  }else{
							  $COLOR="#CDDDEF";
						  }				  
					  }			  
					  $s=$s."<td bgcolor=\"$COLOR\" > ".$SUMA_STOCK."</td>";			  
					  //
					  $s=$s.$oo;
					  //			  
					  $s=$s."<td>$SEP</td>"; 
					  $s=$s."<td>$TRA</td>"; 
					  $s=$s."</tr>";
				  }
				  //
			}		
		}
		////////////////////////////////////////////////////////////////////////////////////
		if($s!=""){
        	$s=$t.$s."</table>";		
		}		
		echo $s;	
?>
</div>
<div style="position:absolute; left:18px; top: 89px; width: 64px;">
<div align="left" class="f2" >EMPRESA</div>
</div>
<select name="CboEmp" id="CboEmp" 
style="position:absolute; left:18px; top:109px; width: 139px;" 
onkeydown="return SoloTextoEx(event,'CboAlm');" tabindex="1">
<?php 
	echo LE($StrEmp,"S","N"); 
?>
</select>

<div style="position:absolute; left: 69px; top: 30px; width: 533px; height: 24px;">
<div align="left" class="Estilo1">REPORTE DE STOCK PERSONALIZADO </div>
</div>
<input name="TxtCod" type="text" id="TxtCod" 
style="position:absolute; left: 166px; top: 109px; width: 106px;" value="<?php echo $StrCod;?>"  
onkeydown="return SoloTextoEx(event,'TxtDes');"
tabindex="1" />

    <div id="LblTit" style="position:absolute; left: 10px; top: 25px; width: 64px;">
    <div align="left" class="Estilo1"><img src="img/buscar.png" width="57" height="60" /></div>
  </div>	

<div  align="left" style="height:19px; width:1455px; position:absolute; left: 20px; top: 143px; color: #0FF; background-color: #FFFFFF; layer-background-color: #FFFFFF; border: 1px none #000000;">
<?php
$T=110+400+120+180+(gn("count(*)","vis_almacenes","IDA>0 AND ENC LIKE '$StrEmp_'")*60)+120;
?>
<table style="width:<?php echo $T;?>px" border="1" cellpadding="0" cellspacing="0" bgcolor="#d4e3e5" 
class="estilo888">
<tbody>
<tr height="10px">
<td style="width:110px" bgcolor="#CCCCCC" >CODIGO</td>
<td style="width:400px" bgcolor="#CCCCCC">DESCRIPCION</td>
<td style="width:120px" bgcolor="#CCCCCC">LINEA</td>
<td style="width:60px" align="right" bgcolor="#CCCCCC">PV MIN</td>
<td style="width:60px" align="right" bgcolor="#CCCCCC">PV MAX</td>
<td style="width:60px" align="right" bgcolor="#CCCCCC">STOCK</td>
<?php
$s="";
$z="SELECT ANC FROM vis_almacenes ".
   "WHERE IDA>0 AND ENC LIKE '$StrEmp_' ORDER BY ANC";
$result = grs($z);
while ($roww = $result->fetch_row()){		 
	$s=$s."<td  align=\"right\" style=\"width:60px\" bgcolor=\"#CCCCCC\">$roww[0]</td>";
}
echo $s;
?>
<td style="width:60px" align="right" bgcolor="#CCCCCC">SEP.</td>
<td style="width:60px" align="right" bgcolor="#CCCCCC">E.T.</td>
</tr>
</tbody>
</table>
</div>
    <div id="layer8" style="position:absolute; left: 288px; top: 89px; width: 136px;">
      <div align="left" class="f2">DESCRIPCION</div>
</div>
<input name="TxtDes" type="text" id="TxtDes" style="position:absolute; left: 285px; top: 109px; width: 311px;" 
value="<?php echo $StrDes;?>"  
onkeydown="return SoloTextoEx(event,'CboMar');"
tabindex="1" />

<div style="position:absolute; left: 606px; top: 89px; width: 86px;">
<div align="left" class="f2">LINEA</div>
</div>
<select name="CboMar" id="CboMar" style="position:absolute; left: 608px; top: 109px; width: 128px;" 
onkeydown="return SoloTextoEx(event,'Sto');">
<?php	
echo FCBO_("lin_nombre","lineas","id_linea>0",$StrMar,"S","N");
?>
</select>

<div style="position:absolute; left: 747px; top: 89px; width: 86px;">
<div align="left" class="f2">STOCK'</div>
</div>
<select name="Sto" id="Sto" style="position:absolute; left:747px; top: 109px; width: 140px;" 
onkeydown="return SoloTextoEx(event,'Sep');">
<?php	
echo FCBOO("au_item","auxiliar","au_tab='MM'",$Sto,"S","N","au_orden");
?>
</select>

<div style="position:absolute; left: 894px; top: 89px; width: 86px;">
<div align="left" class="f2">SEPARADO'</div>
</div>
<select name="Sep" id="Sep" style="position:absolute; left:894px; top: 109px; width: 140px;" 
onkeydown="return SoloTextoEx(event,'Tra');">
<?php	
echo FCBOO("au_item","auxiliar","au_tab='MM'",$Sep,"S","N","au_orden");
?>
</select>

<div style="position:absolute; left: 1045px; top: 89px; width: 86px;">
<div align="left" class="f2">EN TRANSITO'</div>
</div>
<select name="Tra" id="Tra" style="position:absolute; left:1045px; top: 109px; width: 140px;" 
onkeydown="return SoloTextoEx(event,'Uso');">
<?php	
echo FCBOO("au_item","auxiliar","au_tab='MM'",$Tra,"S","N","au_orden");
?>
</select>

<div style="position:absolute; left: 1197px; top: 89px; width: 106px;">
<div align="left" class="f2">EN USO'</div>
</div>
<select name="Uso" id="Uso" style="position:absolute; left:1199px; top: 109px; width: 107px;" 
onkeydown="return SoloTextoEx(event,'CmdB');">
<?php	
echo FCBOO("au_item","auxiliar","au_tab='SI_NO'",$Uso,"S","N","au_orden");
?>
</select>

<input name="CmdB" type="button" id="CmdB" 
style="position:absolute; left: 1328px; top: 109px; width: 143px;"
value="Filtrar" onclick="fFiltrar();" />



</center>	
</form>

<form action="ficheroExcel.php" method="post" target="_blank" id="FormularioExportacion" >
<div style="position:absolute; left: 184px; top: 50px; 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>
</body>
</html>
