<?php
session_start();
include("cls_conexion.php");$CNN=new ClsMySQL();include("conexion23.php");
//
if(strlen($_SESSION['SYS_USER_ID'])==0){JsDir("login.php");	return;}
//

$IdUsu=$_SESSION['SYS_USER_ID'];

include("deos_ventas_xcredito_bx.php");

$AT=gs("at","usuarios","id_usuario=$IdUsu");
?>

<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Consulta de ventas al credito</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">
.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(){	
	var CboAlm=document.getElementById("CboAlm").value;
	if(CboAlm=="TODOS"){
		alert("Seleccione un Almacen");
		document.getElementById("CboAlm").focus();
		return;
	}
	document.getElementById("TxtAc").value="GEN_PDF";
	document.getElementById("Frm").submit();
}


$(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 $HTM;
?>
</div>

<div Id="DivFRM"  class="cF" style="background-color:#FFFFFF;" >
<form id="Frm" name="Frm" method="post" action="ventas_al_credito.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">CONSULTA VENTAS AL CREDITO</div>
</div>

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

<div class="s1" style="left: 35px; top: 121px; width: 102px;">
ALMACEN</div>
<select name="CboAlm" id="CboAlm" 
class="lt" style="left: 35px; top: 138px; width: 212px" 
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,"S","N");
    }
?>
</select>

<div class="s1" style="left: 256px; top: 121px; width: 102px;">
COMPROBANTE</div>
<select name="CboCom" id="CboCom"
class="lt" style="left: 256px; top: 138px; width: 192px;"
tabindex="<?php echo ++$TI;?>">
<?php echo FCBO_("com_nombre","comprobantes","id_comprobante>0",$StrCom,"S","");?>
</select>

<div class="s1" style="left: 457px; top: 121px; width: 63px;">
SERIE</div>
<input name="TxtSer" type="text" id="TxtSer" 
class="lt" style="left: 455px; top: 138px; width: 70px;"
value="<?php echo $StrSer;?>"  
tabindex="<?php echo ++$TI;?>"/>

<div class="s1" style="left: 534px; top: 121px; width: 63px;">
NUMERO</div>
<input name="TxtNum" type="text" id="TxtNum" 
class="lt" style="position: absolute; left: 534px; top: 138px; width: 63px;"
value="<?php echo $StrNum;?>"  
tabindex="<?php echo ++$TI;?>" />

<div class="s1" style="left: 604px; top: 102px; width: 45px;">DESDE</div>
<div class="s1" style="left: 604px; top: 121px; width: 69px;">dd-mm-yy</div>
<input name="TxtDex" type="text" id="TxtDex" 
class="fe" style="position: absolute; left: 604px; top: 138px; width: 65px;"
value="<?php echo $StrDex;?>"  
tabindex="<?php echo ++$TI;?>"/>

<div class="s1" style="left: 677px; top: 102px; width: 60px;">HASTA</div>
<div class="s1" style="left: 677px; top: 121px; width: 69px;">dd-mm-yy</div>
<input name="TxtHax" type="text" id="TxtHax" 
class="fe" style="position: absolute; left: 677px; top: 138px; width: 64px;" 
value="<?php echo $StrHax;?>"  
tabindex="<?php echo ++$TI;?>"/>

<div class="s1" style="left: 750px; top: 121px; width: 100px;">
CLIENTE</div>
<input name="TxtPro" type="text" id="TxtPro" 
class="lt" style="position: absolute; left: 750px; top: 138px; width: 319px;"
value="<?php echo $StrPro;?>"  
tabindex="<?php echo ++$TI;?>"/>

<div class="s1" style="left: 1077px; top: 121px; width: 75px;">
CANCELADO</div>
<select name="CboSN" id="CboSN" 
class="lt" style="position: absolute; left: 1077px; top: 138px; width: 97px;"
tabindex="<?php echo ++$TI;?>">
<?php
if($StrSN=="" || $StrSN=="TODOS"){
AD("TODOS",1);AD("NO",0);AD("SI",0);
}
if($StrSN=="NO"){
AD("TODOS",0);AD("NO",1);AD("SI",0);
}
if($StrSN=="SI"){
AD("TODOS",0);AD("NO",0);AD("SI",1);
}

?>
</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" 
value="Generar PDF" onClick="fGenPDF();"
tabindex="<?php echo ++$TI;?>" />
</div>
    
<!----------------------------------------->

<div class="datagrid" style="position: absolute; left: 35px; top: 165px; width: 1180px; height: 416px; overflow: auto">
<table id="Exportar_a_Excel" width="100%">
<thead>
<tr>
<td colspan="9" align="center"><?php echo PagBtn($LStrTR,$VP_RegXPag,$LStrPag);?></td>
</tr>

<tr>
<th width="161" style="text-align:left; background:#999">ALMACEN</th>
<th width="118" style="text-align:left; background:#999">COMPROBANTE</th>
<th width="82"  style="text-align:left; background:#999">NUMERO</th>
<th width="73"  style="text-align:left; background:#999">FECHA</th>
<th width="468"  style="text-align:left; background:#999">CLIENTE</th>
<th width="82" style="text-align:right; background:#999">TOTAL</th>
<th width="55" style="text-align:center; background:#999">CAN</th>
<th width="73" style="text-align:left; background:#999">FEC.CAN</th>
<th width="26" style="text-align:right; background:#999">&nbsp;</th>
</tr>
</thead>
<tbody>


<?php		  		
$TOTAL=0;
$s="SELECT ID,ALM,COM,CONCAT(SER,'-',NUM),".
"DATE_FORMAT(FEC,'%d-%m-%y'),CLI,TOT,CAN ".
"FROM vventas WHERE ".$FF." ORDER BY ALM,COM,SER,NUM,FEC,CLI ";


$result = grs($s);				
while ($row = $result->fetch_row()){
	if($row[7]=="S"){
		$StrFec=gs("DATE_FORMAT(FE,'%d-%m-%y')",
		"vis_cobros_ventas_det","IV=$row[0]");
	}else{
		$StrFec="";
	}
	?>	
	<tr>
	<!----------------------------------------------->
    <td><?php echo vbl($row[1],22);?></td>  
	<td><?php echo $row[2];?></td>
	<td>'<?php echo $row[3];?></td>
	<td><?php echo $row[4];?></td>
	<td><?php echo $row[5];?></td> 
	<td style="text-align:right"><?php echo NF2($row[6],1);?></td>
    <td style="text-align:center"><?php echo $row[7];?></td>
    <td style="text-align:left"><?php echo $StrFec;?></td>
	<td align="center">
	<a target="_blank" href="ventas.php?Id=<?php echo $row[0];?>&Pag=0" >
	<img src="img/icono.png"  border="0"/>
	</a>
	</td>
	<!----------------------------------------------->
	</tr>
	<?php
	$TOTAL=$TOTAL + $row[6];
	}


?>
	  
<tr>
<td colspan="5" bgcolor="#FFFFFF" align="right"><span class="Est5">TOTAL</span></td>
<td bgcolor="#FFFFFF" align="right"><span class="Est5"><?php echo NF2($TOTAL,2); ?></span></td>
</tr>

</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,$StrCom,$StrSer,$StrNum,$StrDex,$StrHax,$StrPro,$StrSN);
	$StrDESCARGAR=$_PDF;
}

function GEN_PDF($FF,$StrAlm,$StrCom,$StrSer,$StrNum,$StrDex,$StrHax,$StrPro,$StrSN){
$_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 VENTAS AL CREDITO",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($StrCom)>0){
$_ENC=vbl("COMPROBANTE".vbfill(" ",15),15)." ".vbl(":".vbfill(" ",1),1);
$_ENC=$_ENC." ".vbl($StrCom.vbfill(" ",30),30);
$pdf->Cell(0,4,$_ENC,0,1);	
}

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

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

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

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

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

if(strlen($StrSN)>0){
$_ENC=vbl("CANCELADO".vbfill(" ",15),15)." ".vbl(":".vbfill(" ",1),1);
$_ENC=$_ENC." ".vbl($StrSN.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("ALMACEN".vbfill(" ",15),15);
$_ENC=$_ENC." ".vbl("COMPROBANTE".vbfill(" ",11),11);
$_ENC=$_ENC." ".vbl("NUMERO".vbfill(" ",10),10);
$_ENC=$_ENC." ".vbl("FECHA".vbfill(" ",8),8);
$_ENC=$_ENC." ".vbl("CLIENTE".vbfill(" ",20),20);

$_ENC=$_ENC." ".vbr(vbfill(" ",9)."TOTAL",9);
$_ENC=$_ENC." ".vbl("CAN".vbfill(" ",3),3);
$_ENC=$_ENC." ".vbl("FEC.CAN".vbfill(" ",8),8);

$pdf->Cell(0,4,$_ENC,0,1);	
$pdf->Cell(0,4,vbfill("-",$_CxL),0,1);	
//
$s="SELECT ID,ALM,COM,CONCAT(SER,'-',NUM),".
"DATE_FORMAT(FEC,'%d-%m-%y'),CLI,TOT,CAN ".
"FROM vventas WHERE ".$FF." ORDER BY ALM,COM,SER,NUM,FEC,CLI ";

$result = grs($s);
while ($row = $result->fetch_row()){
	$_ENC=vbl($row[1].vbfill(" ",15),15);
	$_ENC=$_ENC." ".vbl($row[2].vbfill(" ",11),11);
	$_ENC=$_ENC." ".vbl($row[3].vbfill(" ",10),10);
	$_ENC=$_ENC." ".vbl($row[4].vbfill(" ",8),8);
	$_ENC=$_ENC." ".vbl($row[5].vbfill(" ",20),20);

	$_ENC=$_ENC." ".vbr(vbfill(" ",9).NF2($row[6],1),9);
	$_ENC=$_ENC." ".vbl($row[7].vbfill(" ",3),3);
	$_ENC=$_ENC." ".vbl($row[8].vbfill(" ",8),8);
	$pdf->Cell(0,4,$_ENC,0,1);	
	$TOT=$TOT+$row[6];
}
$pdf->Cell(0,4,vbfill("-",$_CxL),0,1);	

$_TI=vbr(vbfill(" ",64)."TOTAL :",64);
$_TD=vbr(vbfill(" ",13).NF2($TOT,1),13);
$pdf->Cell(0,4,$_TI." ".$_TD,0,1);	

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

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

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