<?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;}
//+++++++
include("ges_facturas_bx.php");
$IdUsu=0;
$AT=gs("at","usuarios","id_usuario=$IdUsu");
?>
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Facturas Xml - Buscar</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("EmiRuc");
});

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 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" action="ges_facturas_b.php" 
autocomplete="off"
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">FACTURAS XML - BUSCAR</div>
</div>

<!----------------------------------------->
<div class="s1" style="left: 270px; top: 105px; width: 45px;">
<b>FACTURA</b>
</div>
<div class="s1" style="left: 35px; top: 121px; width: 98px;">
EMISOR RUC
</div>
<input name="EmiRuc" type="text" id="EmiRuc" 
class="lt" style="left: 35px; top: 138px; width: 97px;"
value="<?php echo $EmiRuc;?>"  maxlength="11"
tabindex="<?php echo ++$TI;?>"/>



<div class="s1" style="left: 141px; top: 121px; width: 168px;"> EMISOR NOMBRE
</div>
<input name="EmiNom" type="text" id="EmiNom" 
class="lt" style="left: 141px; top: 138px; width: 118px;"
value="<?php echo $EmiNom;?>"  
tabindex="<?php echo ++$TI;?>"/>

<div class="s1" style="left: 270px; top: 121px; width: 44px;">
<b>SERIE</b></div>
<input name="FacSer" type="text" id="FacSer" 
class="lt" style="left: 270px; top: 138px; width: 71px;"
value="<?php echo $FacSer;?>"  
tabindex="<?php echo ++$TI;?>"/>

<div class="s1" style="left: 350px; top: 121px; width: 44px;">
<b>NUMERO</b></div>
<input name="FacNum" type="text" id="FacNum" 
class="lt" style="left: 350px; top: 138px; width: 71px;"
value="<?php echo $FacNum;?>"  
tabindex="<?php echo ++$TI;?>"/>


<div class="s1" style="left: 430px; top: 105px; width: 45px;">
DESDE</div>
<div class="s1" style="left: 430px; top: 121px; width: 69px;">
dd-mm-yy</div>
<input name="Dex" type="text" id="Dex" 
class="fe tcal" style="left: 429px; top: 138px; width: 90px;"
value="<?php echo $Dex;?>"  
tabindex="<?php echo ++$TI;?>"/>

<div class="s1" style="left: 529px; top: 105px; width: 60px;">
HASTA</div>
<div class="s1" style="left: 528px; top: 121px; width: 69px;">
dd-mm-yy</div>
<input name="Hax" type="text" id="Hax" 
class="fe" style="left: 527px; top: 138px; width: 90px;" 
value="<?php echo $Hax;?>"  
tabindex="<?php echo ++$TI;?>"/>



<div class="s1" style="left: 631px; top: 121px; width: 118px;">
CLIENTE RUC
</div>
<input name="CliRuc" type="text" id="CliRuc" 
class="lt" style="left: 630px; top: 138px; width: 104px;"
value="<?php echo $CliRuc;?>"   maxlength="11"
tabindex="<?php echo ++$TI;?>"/>

<div class="s1" style="left: 748px; top: 121px; width: 118px;">
CLIENTE NOMBRE
</div>
<input name="CliNom" type="text" id="CliNom" 
class="lt" style="left: 748px; top: 138px; width: 186px;"
value="<?php echo $CliNom;?>"  
tabindex="<?php echo ++$TI;?>"/>


<div class="s1" style="left: 944px; top: 121px; width: 69px;">
PAGADO</div>
<select name="Pag" id="Pag"  
class="lt" style="left: 944px; top: 138px; width: 70px" 
tabindex="<?php echo ++$TI;?>">
<?php
	echo FCBO("aux_nom","auxiliar","aux_des='SN'",$Pag,"S","N");
?>
</select>


<div class="s1" style="left: 1024px; top: 106px; width: 79px;"> CON RETENCION
</div>
<select name="Ret" id="Ret"  
class="lt" style="left: 1024px; top: 138px; width: 75px" 
tabindex="<?php echo ++$TI;?>">
<?php
	echo FCBO("aux_nom","auxiliar","aux_des='SN'",$Ret,"S","N");
?>
</select>


<div class="s1" style="left: 1111px; top: 121px; width: 91px;">
LOTE
</div>
<input name="Lot" type="text" id="Lot" 
class="lt" style="left: 1111px; top: 138px; width: 103px;"
value="<?php echo $Lot;?>"   maxlength="50"
tabindex="<?php echo ++$TI;?>"/>


<!----------------------------------------->
<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="CmdB" type="button" id="CmdZ" class="btm"
value="Volver" onClick="fBuscar('ges_facturas.php?TxtAc=X');"  
tabindex="<?php echo ++$TI;?>" />

<input name="CmdPDF" type="button" id="CmdPDF" class="btm" 
value="Generar PDF" onClick="fGenPDF();" style="display:none"
tabindex="<?php echo ++$TI;?>" />
</div>

<div  style="position:absolute; top:165px; left:35px; 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: 35px; top: 194px; 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>

<th width="6%" style="text-align:left; background:#999"">SERIE</th>
<th width="8%" style="text-align:left; background:#999"">NUMERO</th>
<th width="7%" style="text-align:left; background:#999"">FECHA</th>
<th width="12%" style="text-align:left; background:#999"">EMISOR RUC</th>
<th width="15%" style="text-align:left; background:#999"">EMISOR NOMBRE</th>
<th width="12%" style="text-align:left; background:#999"">CLIENTE RUC</th>
<th width="16%" style="text-align:left; background:#999"">CLIENTE NOMBRE </th>
<th width="14%" style="text-align:right; background:#999"">TOTAL</th>
<th width="3%" style="text-align:right; background:#999"">RET.</th>
<th width="5%" style="background:#999"">PAGADO</th>
<th width="5%" style="background:#999"">LOTE</th>
<th width="2%" style="text-align:center; background:#999"">&gt;</th>
</tr>
</thead>
<tbody>
<?php	
$TOT=0;	  		
$i=0;
$s="SELECT * FROM ges_xml WHERE ".$FF." ORDER BY xml_fec DESC ";
//echo $s."<br>";
$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" ';	
	$TOT=$TOT + $r['xml_tot'];
?>	
	<tr onDblClick="location.href='ges_facturas.php?Id=<?php echo $r['id_xml'];?>&Pag=0'" <?php echo $CSS;?>>
	<!----------------------------------------------->
	<td style="white-space: nowrap;"><?php echo $r['xml_ser'];?></td>
	<td style="white-space: nowrap;"><?php echo $r['xml_num'];?></td> 
	<td style="white-space: nowrap;"><?php echo FEP($r['xml_fec']);?></td>
    <td style="white-space: nowrap;"><?php echo $r['xml_emi_ruc'];?></td>   
    <td style="white-space: nowrap;"><?php echo $r['xml_emi_nom'];?></td>   
    <td style="white-space: nowrap;"><?php echo $r['xml_cli_ruc'];?></td>    
    <td style="white-space: nowrap;"><?php echo $r['xml_cli_nom'];?></td>    
    <td style="white-space: nowrap;" align="right"><?php echo NF2($r['xml_tot'],2);?></td>    
    <td style="white-space: nowrap;" align="center"><?php echo $r['xml_ret'];?></td>
    <td style="white-space: nowrap;" align="center"><?php echo $r['xml_pagado'];?></td>   
    <td style="white-space: nowrap;" align="center"><?php echo $r['xml_nom_tmp'];?></td>  
	<!----------------------------------------------->
    <td align="center">
    <a href="ges_facturas.php?Id=<?php echo $r['id_xml'];?>&Pag=0" target="_blank" >
    <img src="open.png"  border="0"/></a></td>
	</tr>
<?php
}
?>		  
</tbody>
</table>
</div>
<div class="s1" style="left: 1100px; top:577px; width: 116px; text-align:right">
  TOTAL : <b><?php echo  NF2($TOT,2);?></b></div>
<!----------------------------------------->
<?php include("ocultos.php");?>

<div class="s1" style="left: 38px; top: 579px; width: 421px;">
Doble Click sobre el registro para activar la edicion</div>
</form>

<form action="ficheroExcel.php" 
    method="post" target="_blank" id="FormularioExportacion" >
    
    <div style="position: absolute; left: 313px; 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,$StrVend,$StrSN);
	$StrDESCARGAR=$_PDF;
}

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

if(strlen($StrSN)>0){
$_ENC=vbl("ANULADO S/N".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,"",0,1);	
//------------------------------------------
$pdf->Cell(0,4,vbfill("-",$_CxL),0,1);
$P=0;
$P++; $T[$P]=11;	$_ENC=vbl("ALMACEN".vbfill(" ",$T[$P]),$T[$P]);
$P++; $T[$P]=8;		$_ENC=$_ENC." ".vbl("COMPROB".vbfill(" ",$T[$P]),$T[$P]);
$P++; $T[$P]=10;	$_ENC=$_ENC." ".vbl("NUMERO".vbfill(" ",$T[$P]),$T[$P]);
$P++; $T[$P]=8;		$_ENC=$_ENC." ".vbl("FECHA".vbfill(" ",$T[$P]),$T[$P]);
$P++; $T[$P]=19;	$_ENC=$_ENC." ".vbl("CLIENTE".vbfill(" ",$T[$P]),$T[$P]);
$P++; $T[$P]=18;	$_ENC=$_ENC." ".vbl("VENDEDOR".vbfill(" ",$T[$P]),$T[$P]);
$P++; $T[$P]=1;		$_ENC=$_ENC." ".vbl("A".vbfill(" ",$T[$P]),$T[$P]);
$P++; $T[$P]=8;		$_ENC=$_ENC." ".vbr(vbfill(" ",$T[$P])."TOTAL",$T[$P]);
$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,
VEND,ANU,TOT
FROM vventas WHERE ".$FF." ORDER BY ALM,COM,SER,NUM,FEC,CLI ";

$result = grs($s);
while ($row = $result->fetch_row()){
	$P=0;
	$P++; $_ENC=vbl($row[1].vbfill(" ",$T[$P]),$T[$P]);
	$P++; $_ENC=$_ENC." ".vbl($row[2].vbfill(" ",$T[$P]),$T[$P]);
	$P++; $_ENC=$_ENC." ".vbl($row[3].vbfill(" ",$T[$P]),$T[$P]);
	$P++; $_ENC=$_ENC." ".vbl($row[4].vbfill(" ",$T[$P]),$T[$P]);
	$P++; $_ENC=$_ENC." ".vbl($row[5].vbfill(" ",$T[$P]),$T[$P]);
	$P++; $_ENC=$_ENC." ".vbl($row[6].vbfill(" ",$T[$P]),$T[$P]);
	$P++; $_ENC=$_ENC." ".vbl($row[7].vbfill(" ",$T[$P]),$T[$P]);
	$P++; $_ENC=$_ENC." ".vbr(vbfill(" ",$T[$P]).NF2($row[8],1),$T[$P]);
	$pdf->Cell(0,4,$_ENC,0,1);	
	$TOT=$TOT+$row[8];
}
$pdf->Cell(0,4,vbfill("-",$_CxL),0,1);	

$_TI=vbr(vbfill(" ",75)."TOTAL :",75);
$_TD=vbr(vbfill(" ",14).NF2($TOT,1),14);
$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.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>
