<?php
session_start();
include("cls_conexion.php");$CNN=new ClsMySQL();include("conexion23.php");
include("phpmnu_fun.php");
//
if(strlen($_SESSION['SYS_USER_ID'])==0){JsDir("login.php");	return;}
//
$IdUsu=$_SESSION['SYS_USER_ID'];
include("deos_rep_stock_bx.php");
?>
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Reporte de Stock</title>
<!----------------------------------------->
<?php AddJs(); ?>
<script type="text/javascript" src="ja/funciones.js"></script>

<!----------------------------------------->
<link rel="stylesheet" type="text/css" href="css/estiloss.css"  />
<link rel="stylesheet" type="text/css" href="css/basic.css"  />
<link rel="stylesheet" type="text/css" href="css/mnu.css"  />
<!----------------------------------------->
<style type="text/css">
.tableFixHead          { overflow-y: auto; }
.tableFixHead thead th { position: sticky; top: 0; }

table  {border-collapse:collapse;width:100%;}
th, td {padding: 3px 3px;}
th     {background:#666;}


.cF {height:600px;width:1250px;position:relative;top:0px}
.mM {height:34px;width:1250px;position:relative;top:0px;background-color:#09C; z-index:500;}

</style>

<!----------------------------------------->
<script>
$(document).ready(function(){  
   Inicializar();
   jF("CboAlm");
});

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

function AjImprimir(){
	document.getElementById("CmdI").disabled=true;
	DImp=document.getElementById("DivP");
	DImp.style.visibility="visible";
	DImp.innerHTML="<img src='load2.gif' width='15' height='15' />";	
	//
	var CboAlm=gv("CboAlm");
	var TxtCod=gv("TxtCod");
	var TxtDes=gv("TxtDes");
	var CboMar=gv("CboMar");
	var CboSto=gv("CboSto");
	var CboLin=gv("CboLin");
	//
	var stru="rep_stock_z.php?CboAlm="+CboAlm+
	"&TxtCod="+TxtCod+
	"&TxtDes="+TxtDes+
	"&CboMar="+CboMar+
	"&CboSto="+CboSto+
	"&CboLin="+CboLin;
	//a=prompt(stru,stru);
	try{	
	ajax=CreateAJAX();
	ajax.open("GET",stru);	
	ajax.onreadystatechange=function() {
	   if (ajax.readyState==4) {
		   var Rpt = (ajax.responseText);
		   Rpt=Rpt.trim();		    
		   if(jLen(Rpt)>0){
			   DImp.innerHTML=Rpt;	
		   }else{
			   DImp.innerHTML="";
			   alert("No se pudo generar el reporte");
		   }
		   document.getElementById("CmdI").disabled=false;
	   }
	}
    ajax.send(null);
	}
	catch(err){
	}
	//	
}


$(document).keydown(function(e){
	var AT=gv("TxtAT");

	if(e.which==66 && e.altKey){
		if(AT=="1"){	
		document.getElementById("CmdB").click();
		return;
		}
	}

	if(e.which==86 && e.altKey){
		if(AT=="1"){
		document.getElementById("CmdZ").click();
		return;
		}
	}
  
});
</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>
<!----------------------------------------->

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

<div class="mM" align="left" style="font-size:12px">
<?php
//$HTM=file_get_contents("http://inversionessounduniversal.com/ventas/phpmnu.php?USER_ID=$IdUsu");
echo GEN_MENU(vbval(V($_SESSION['SYS_USER_ID'])));
?>
</div>

<div Id="DivFRM"  class="cF" style="background-color:#FFFFFF;" >
<form id="Frm" name="Frm" method="post" autocomplete="off"
action="rep_stock.php" 
style="margin:0px; padding:0px; display:inline;" onSubmit="return false;">
<!----------------------------------------->
<div id="DivT" class="dT"  style="width:1250px;">
<img src="b.png" class="iT" />
<div class="tT">REPORTE DE STOCK</div>
</div>

<!----------------------------------------->

<div class="s1" style="left:35px; top: 114px; width: 102px;">
ALMACEN</div>
<select name="CboAlm" id="CboAlm" 
class="lt" style="left: 35px; top: 129px; width: 167px" 
tabindex="<?php echo ++$TI;?>">
<?php 
	if($IdUsu>=1 && V($_SESSION['SYS_USER_ALM'])!="%"){
		echo ListALM($StrAlm); 
	}else{
    	echo FCBO("alm_nombre","almacenes","id_almacen>0",$StrAlm,"N","N");
    }
?>
</select>

<div class="s1" style="left: 211px; top: 114px; width: 52px;">
CODIGO</div>
<input name="TxtCod" type="text" id="TxtCod" 
class="lt" style="left: 211px; top: 129px; width: 135px" 
value="<?php echo $StrCod;?>"  
tabindex="<?php echo ++$TI;?>"/>
<div class="s1" style="left: 356px; top: 114px; width: 238px;">
  DESCRIPCION</div>
<input name="TxtDes" type="text" id="TxtDes" 
class="lt" style="left: 355px; top: 129px; width: 417px;"
value="<?php echo $StrDes;?>"  
tabindex="<?php echo ++$TI;?>"/>

<div class="s1" style="left: 782px; top: 114px; width: 118px;">
MARCA</div>
<select name="CboMar" id="CboMar" 
class="lt" style="left: 778px; top: 129px; width: 136px;"
tabindex="<?php echo ++$TI;?>">
<?php	echo FCBO_("mar_nombre","marcas","id_marca>0",$StrMar,"S","")?>  
</select>

<div class="s1" style="left: 922px; top: 114px; width: 127px;"> TIPO DE PRODUCTO
</div>
<select name="CboLin" id="CboLin" 
class="lt" style="left: 919px; top: 129px; width: 133px;"
tabindex="<?php echo ++$TI;?>">
<?php	echo FCBO_("lin_nombre","lineas","id_linea>0",$StrLin,"S","")?>  
</select>

<div class="s1" style="left: 1060px; top: 114px; width: 143px;">
ESTADO.STOCK</div>
<select name="CboSto" id="CboSto" 
class="lt" style="left: 1058px; top: 129px; width: 158px;"
tabindex="<?php echo ++$TI;?>">
<?php 
	echo FCBO_("aux_nom","auxiliar","aux_des='ST'",$CboSto,"S","");
?>
</select>



<!----------------------------------------->
<div id="DivBtn" align="left" style="position:absolute; left: 33px; top: 71px; width: 551px; height: 26px;">
<input name="CmdB" type="button" id="CmdB" class="btm"
value="Buscar" onClick="fFiltrar();"  
tabindex="<?php echo ++$TI;?>" />

<input name="CmdPDF" type="button" id="CmdPDF" class="btm"  style="display:none"
value="Generar PDF" onClick="fGenPDF();"
tabindex="<?php echo ++$TI;?>" />
</div>
    
<!----------------------------------------->
<div  style="position:absolute; top:158px; left:36px; height:27px; background-color:#FFF; width: 1180px;">
<table width="100%" style="font-family:Arial, Helvetica, sans-serif; font-size:11px" border="0">
<tr>
<td align="center">
	<?php echo PagBtn($LStrTR,$VP_RegXPag,$LStrPag);?>
</td>
</tr>
</table>
</div> 

<div class="tableFixHead" 
style="position:absolute; left: 36px; top: 187px; width: 1180px; height: 380px; overflow:auto; border:solid 1px #363636 ">
<table id="Exportar_a_Excel" width="100%" style="font-family:Arial, Helvetica, sans-serif; font-size:11px">
<thead>
<tr>
<tr height="18">
<th width="116" style="text-align:left; background:#999">CODIGO</th>
<th width="258" style="text-align:left; background:#999">TIPO DE PRODUCTO*</th>
<th width="355" style="text-align:left; background:#999">DESCRIPCION*</th>
<th width="222" style="text-align:left; background:#999">MARCA</th
><th width="138" style="text-align:left; background:#999">PRECIO DE VENTA</th>
<th width="61" 	style="text-align:right; background:#999">STOCK</th>
</tr> 
</thead>
<tbody> 
<?php
$i=0;
$s="SELECT * FROM viz_stock WHERE $FF ORDER BY ID";
$s=PagSql($s,$LStrPag,$VP_RegXPag,$LStrTR);				
$rs = grs($s);
while($r=$rs->fetch_assoc()){
	$i++;
	$CSS="";
	if($i%2==0){
		$CSS=" style=\"background-color:#E2E2E2\" ";
	}
?>	
	<tr <?php echo $CSS;?> >
	<!----------------------------------------------->
	<td>'<?php echo $r['COD'];?></td>  
	<td><?php echo $r['TIP'];?></td>  
	<td><?php echo $r['DES'];?></td> 
	<td><?php echo $r['MAR'];?></td> 
    <td align="right"><?php echo $r['PVE'];?></td> 
	<td style="text-align:right"><?php echo $r['STOCK'];?></td> 
	<!----------------------------------------------->
	</tr>
<?php
}
?>

</tbody>	
</table>

</div>

<!----------------------------------------->    
<?php include("ocultos.php");?>

</form>

<form action="ficheroExcel.php" 
    method="post" target="_blank" id="FormularioExportacion" >
    
    <div style="position: absolute; left: 220px; top: 71px; width: 45px; height: 15px;">  
    <input name="" type="button" class="botonExcel btm" value="Exportar"  />
    <input type="hidden" id="datos_a_enviar" name="datos_a_enviar" />
    </div>
</form>

<?php
if($StrCmd=="GEN_PDF"){
	$_PDF=GEN_PDF($FF,$StrAlm,$StrCod,$StrDes,$StrMar,$CboSto,$StrLin,$Fab,$Mod);
	$StrDESCARGAR=$_PDF;
}

function GEN_PDF($FF,$StrAlm,$StrCod,$StrDes,$StrMar,$CboSto,$StrLin,$Fab,$Mod){
$_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 STOCK",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".vbfill(" ",15),15)." ".vbl(":".vbfill(" ",1),1);
	$_ENC=$_ENC." ".vbl($StrLin.vbfill(" ",30),30);
	$pdf->Cell(0,4,$_ENC,0,1);	
}

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

if(strlen($Mod)>0){
	$_ENC=vbl("MODELO".vbfill(" ",15),15)." ".vbl(":".vbfill(" ",1),1);
	$_ENC=$_ENC." ".vbl($Mod.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);	
}

if(strlen($CboSto)>0){
	$_ENC=vbl("STOCK".vbfill(" ",15),15)." ".vbl(":".vbfill(" ",1),1);
	$_ENC=$_ENC." ".vbl($CboSto.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(" ",18),18);
$_ENC=$_ENC." ".vbl("FABRICANTE".vbfill(" ",15),15);
$_ENC=$_ENC." ".vbl("MODELO".vbfill(" ",10),10); 
$_ENC=$_ENC." ".vbl("DESCRIPCION".vbfill(" ",25),25);
$_ENC=$_ENC." ".vbr(vbfill(" ",5)."STOCK",5);
//------------------------------------------
$pdf->Cell(0,4,$_ENC,0,1);	
$pdf->Cell(0,4,vbfill("-",$_CxL),0,1);	
//
$s="SELECT ID,COD,LINEA,DESCRIPCION,MARCA,STOCK,FAB,MODELO   
    FROM v_stocks WHERE ".$FF."	ORDER BY DESCRIPCION,MARCA,LINEA ";

$result = grs($s);
while ($row = $result->fetch_row()){
	$_ENC=vbl($row[1].vbfill(" ",12),12);
	$_ENC=$_ENC." ".vbl($row[2].vbfill(" ",18),18);
	$_ENC=$_ENC." ".vbl($row[6].vbfill(" ",15),15);
	$_ENC=$_ENC." ".vbl($row[7].vbfill(" ",10),10);
	$_ENC=$_ENC." ".vbl($row[3].vbfill(" ",25),25);	
	$_ENC=$_ENC." ".vbr(vbfill(" ",5).$row[5],5);
	$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="Reporte de Stock.pdf";
$pdf->Output($PDF_NAME);		
return $PDF_NAME;
}
?>

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

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