<?php
	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']);
	//-------------------------
	$StrONE=trim(V($_GET['CmdB']));	
	//-------------------------
	$StrAlm=V($_POST['CboAlm']);
	$StrCod=V($_POST['TxtCod']);		
	$StrLin=V($_POST['CboLin']);
	$StrDes=V($_POST['TxtDes']);
	$StrMar=V($_POST['CboMar']);
	
	if($_SESSION['SYS_USER_ALM']=="%"){
		if(strlen($StrAlm)==0)$StrAlm=GetSO("alm_nombre","almacenes","","alm_nombre");
	}else{
		$StrAlm=$_SESSION['SYS_USER_ALM'];
	}
	$StrCodT=$StrCod."%";
	$StrLinT=VCbo($StrLin);
	$StrDesT=$StrDes."%";
	$StrMarT=VCbo($StrMar);


$w="ALM LIKE '$StrAlm' 
	AND COD LIKE '$StrCodT' 
	AND LIN LIKE '$StrLinT' 
	AND DES LIKE '$StrDesT' 
	AND MAR LIKE '$StrMarT' ";
	//-------------------------
$LStrTR=gn("count(*)","vis_productos_stock2",$w);
$LStrPag=V($_POST['TxtPag']);	
if($StrCmd=="F"){$LStrPag="1";}
$VP_RegXPag=50000;	
$LStrPag=PagGet($LStrPag,$StrCmd,$LStrTR,$VP_RegXPag);
?>
<!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=iso-8859-1" />
<title>Reporte de productos</title>
<!--CSS_NEW------------------------------------->
<link rel="stylesheet" type="text/css" href="estiloss.css"  />
<link rel="stylesheet" type="text/css" href="basic.css"  />
<!--CSS_NEW------------------------------------->
<script type="text/javascript" src="funciones.js"></script>
<script src="jquery-1.7.2.min.js" type="text/javascript"></script>
<script src="jquery.maskedinput.min.js" type="text/javascript"></script>
<script>
$(document).ready(function(){
$("#TxtDex").mask("99-99-99");
});


function fGenPDF(){	
	document.getElementById("TxtAc").value="GEN_PDF";
	document.getElementById("Frm").submit();
}

</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">
.cF {height:600px;width:900px;<?php cF(300,450)?>;}
body {background-color: #CCC;}
</style>
<!----------------------------------------------->

</head>
<body  <?php echo $StrMsg;?>>
<div Id="DivFRM"  class="cF" style="position:absolute; background-color:#006699;">
<form id="Frm" name="Frm" method="post" action="rep_productos3.php">


<div class="TITULO BLANCO" style="left: 116px; top: 30px; width: 412px;">
REPORTE DE PRODUCTOS</div>

<div class="ICONO" style="left: 46px; top: 25px; width: 64px;">
<img src="img/buscar.png" width="57" height="60" /></div>


<div class="s1" style="left: 22px; top: 112px; width: 52px;">ALMACEN</div>
<select name="CboAlm" id="CboAlm" style="left: 22px; top: 129px; width:143px" 
onkeydown="return SoloTextoEx(event,'TxtCod');" 
tabindex="1"><?php echo ListALM($StrAlm); ?>
</select>

<div class="s1" style="left: 178px; top: 112px; width: 52px;">CODIGO</div>
<input name="TxtCod" type="text" id="TxtCod" 
style="left: 178px; top: 130px; width:93px" value="<?php echo $StrCod;?>"  
onkeydown="return SoloTextoEx(event,'CboLin');"
tabindex="1" />

<div class="s1" style="left: 285px; top: 112px; width: 136px;">LINEA DE PRODUCTO</div>
<select name="CboLin" id="CboLin" style="left: 282px; top: 130px; width:180px" 
onkeydown="return SoloTextoEx(event,'TxtDes');" 
tabindex="2"><?php echo FCBO_("lin_nombre","lineas","id_linea>0",$StrLin,"S","");?>
</select>

<div class="s1" style="left: 470px; top: 112px; width: 136px;">DESCRIPCION</div>
<input name="TxtDes" type="text" id="TxtDes" style="left: 469px; top: 130px; width:180px" 
value="<?php echo $StrDes;?>"  
onkeydown="return SoloTextoExX(event,'CboMar');"  
tabindex="3" />

<div class="s1" style="left: 664px; top: 112px; width: 136px;">MARCA</div>
<select name="CboMar" id="CboMar" style="left: 662px; top: 130px; width:140px" 
onkeydown="return SoloTextoEx(event,'CmdB');" 
tabindex="4"><?php echo FCBO_("mar_nombre","marcas","id_marca>0",$StrMar,"S","");?>
</select>

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


<div class="ps" style="left: 116px; top: 50px; width: 189px;">
<input name="CmdV" type="button" id="CmdV" 
value="Volver" onclick="fVolver('menu.php');" />
¡
<input name="CmdPDF" type="button" id="CmdPDF" 
value="Generar PDF" onclick="fGenPDF();"
tabindex="38"/>

<input type="hidden" name="TxtAc" id="TxtAc" />
<input name="TxtPag" id="TxtPag" type="hidden" 
value="<?php echo $LStrPag; ?>" />
</div>

<div class="datagrid" style="position:absolute; left: 22px; top: 161px; width: 847px; height: 413px; overflow:auto">
<select name="LbDatos" size="15" id="LbDatos"  
style="position:absolute; top:21px; left:3px; width:800px; font-family:'Courier New', Courier; border:none">
<option value="0"></option>
<?php	
$CX=1;	  		
$s="SELECT COD,LIN,DES,MAR,STOCK,ID_ALM,ID_PRO FROM vis_productos_stock2
	WHERE $w ORDER BY DES ";
	//echo $s;
	//$s=PagSql($s,$LStrPag,$VP_RegXPag,$LStrTR);
	$result = grs($s);
	while ($row = $result->fetch_assoc()){
	$StrLin="";
	$StrCod=vbr("00000".$CX,6);
	$StrLin=$StrLin.$StrCod.vbfill("&nbsp",8-strlen($StrCod))." | ";	
	$StrLin=$StrLin.$row['COD'].vbfill("&nbsp",12-strlen($row['COD']))." | ";
	$StrLin=$StrLin.$row['DES'].vbfill("&nbsp",20-strlen($row['DES']))." | ";
	$StrLin=$StrLin.$row['MAR'].vbfill("&nbsp",20-strlen($row['MAR']))." | ";
	$StrLin=$StrLin.$row['STOCK'].vbfill("&nbsp",20-strlen($row['STOCK']))." | ";
	
?>
<option value="<?php echo $row['COD'];?>"><?php echo $StrLin;;?></option>
	
<?php
}
?>

</select>
</div>
</form>

<form action="ficheroExcel.php" 
method="post" target="_blank" 
id="FormularioExportacion" >

<div style="position:absolute; left: 270px; 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>
<?php
if($StrCmd=="GEN_PDF"){
	$_PDF=GEN_PDF($w,$StrAlm,$StrCod,$StrLin,$StrDes,$StrMar);
	$StrDESCARGAR=$_PDF;
}

function GEN_PDF($w,$StrAlm,$StrCod,$StrLin,$StrDes,$StrMar){
$_CxL=90;
$_S=10;	

$pdf = new PDF('P','mm',A4);
$pdf->AddPage();$pdf->SetFont('courier','',10);
$pdf->Cell(0,4,"",0,1);	
$pdf->Cell(0,4,"REPORTE DE PRODUCTOS PRECIOS Y STOCK POR ALMACEN",0,1);	
$pdf->Cell(0,4,"",0,1);	
//------------------------------------------
if(strlen($StrAlm)>0){
$_ENC=vbl("ALMACEN".vbfill(" ",15),15)." ".vbl(":".vbfill(" ",1),1);
$_ENC=$_ENC." ".vbl($StrAlm.vbfill(" ",30),30);
$pdf->Cell(0,4,$_ENC,0,1);	
}

if(strlen($StrCod)>0){
$_ENC=vbl("CODIGO".vbfill(" ",15),15)." ".vbl(":".vbfill(" ",1),1);
$_ENC=$_ENC." ".vbl($StrCod.vbfill(" ",30),30);
$pdf->Cell(0,4,$_ENC,0,1);	
}

if(strlen($StrLin)>0){
$_ENC=vbl("LINEA.PRODUCTO".vbfill(" ",15),15)." ".vbl(":".vbfill(" ",1),1);
$_ENC=$_ENC." ".vbl($StrLin.vbfill(" ",30),30);
$pdf->Cell(0,4,$_ENC,0,1);	
}

if(strlen($StrDes)>0){
$_ENC=vbl("DESCRIPCION".vbfill(" ",15),15)." ".vbl(":".vbfill(" ",1),1);
$_ENC=$_ENC." ".vbl($StrDes.vbfill(" ",30),30);
$pdf->Cell(0,4,$_ENC,0,1);	
}

if(strlen($StrMar)>0){
$_ENC=vbl("MARCA".vbfill(" ",15),15)." ".vbl(":".vbfill(" ",1),1);
$_ENC=$_ENC." ".vbl($StrMar.vbfill(" ",30),30);
$pdf->Cell(0,4,$_ENC,0,1);	
}
$pdf->Cell(0,4,"",0,1);	

//------------------------------------------
$pdf->Cell(0,4,vbfill("-",$_CxL),0,1);
$_ENC=vbl("CODIGO".vbfill(" ",12),12);
$_ENC=$_ENC." ".vbl("LINEA".vbfill(" ",16),16);
$_ENC=$_ENC." ".vbl("DESCRIPCION".vbfill(" ",30),30);
$_ENC=$_ENC." ".vbl("MARCA".vbfill(" ",15),15);
$_ENC=$_ENC." ".vbr(vbfill(" ",6)."PRECIO",6);
$_ENC=$_ENC." ".vbr(vbfill(" ",6)."STOCK",6);
$pdf->Cell(0,4,$_ENC,0,1);	
$pdf->Cell(0,4,vbfill("-",$_CxL),0,1);	
//
$s="SELECT COD,LIN,DES,MAR,PRE,STOCK
	FROM vis_productos_stock 
	WHERE $w 
	ORDER BY DES ";

$result = grs($s);
while ($row = $result->fetch_row()){
	$_ENC=vbl($row[0].vbfill(" ",12),12);
	$_ENC=$_ENC." ".vbl($row[1].vbfill(" ",16),16);
	$_ENC=$_ENC." ".vbl($row[2].vbfill(" ",30),30);
	$_ENC=$_ENC." ".vbl($row[3].vbfill(" ",15),15);
	$_ENC=$_ENC." ".vbr(vbfill(" ",6).NF2($row[4],1),6);
	$_ENC=$_ENC." ".vbr(vbfill(" ",6).$row[5],6);
	$pdf->Cell(0,4,$_ENC,0,1);	
}
$pdf->Cell(0,4,vbfill("-",$_CxL),0,1);	
$pdf->Cell(0,4,$_TI." ".$_TD,0,1);	

$_S=20;
$pdf->Cell(0,4,"",0,1);	
$pdf->Cell(0,4,"",0,1);	
//
$PDF_NAME="precios_por_almacen.pdf";
$pdf->Output($PDF_NAME);		
return $PDF_NAME;
}
?>

<?php
if(strlen($StrDESCARGAR)>0){
echo "<div id=\"layer51\" 
	  style=\"position:absolute; left: 118px; top: 82px; 
	  width: 214px; background-color: #FFCC00; layer-background-color: #FFCC00; 
	  border: 1px none #000000; height: 17px;\">";
echo "<div align=\"center\" class=\"Estilo2\"> ";
echo " <a href=\"$StrDESCARGAR\" download>Descargar PDF</a> ";
echo "</div>";
echo "</div>";
}
?>
</div>
</body>
</html>
