<?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_det_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 detallado</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"  />

<link rel="stylesheet" type="text/css" href="tcal.css" />
<script type="text/javascript" src="tcal.js"></script> 
<script src="https://cdn.jsdelivr.net/npm/xlsx/dist/xlsx.full.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2pdf.js/0.10.1/html2pdf.bundle.min.js"></script>

<script src="https://cdn.jsdelivr.net/npm/jspdf@latest/dist/jspdf.umd.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jspdf-autotable@latest/dist/jspdf.plugin.autotable.min.js"></script>

<!----------------------------------------->
<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_det_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 DETALLADO</div>
</div>

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



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

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

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


<div class="s1" style="left: 411px; top: 120px; width: 45px;">
<b>DESDE</b></div>
<input name="Dex" type="text" id="Dex" 
class="fez tcal" style="left: 410px; top: 138px; width: 101px;"
value="<?php echo $Dex;?>"  
tabindex="<?php echo ++$TI;?>"/>

<div class="s1" style="left: 523px; top: 120px; width: 60px;">
<b>HASTA</b></div>
<input name="Hax" type="text" id="Hax" 
class="fez tcal" style="left: 521px; top: 138px; width: 101px;" 
value="<?php echo $Hax;?>"  
tabindex="<?php echo ++$TI;?>"/>



<div class="s1" style="left: 633px; top: 122px; width: 103px;">
CLIENTE RUC
</div>
<input name="CliRuc" type="text" id="CliRuc" 
class="lt" style="left: 632px; top: 138px; width: 107px;"
value="<?php echo $CliRuc;?>"   maxlength="11"
tabindex="<?php echo ++$TI;?>"/>

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



<div class="s1" style="left: 910px; top: 105px; width: 167px;"> CUOTA FECHA DE VCTO.
</div>
<div class="s1" style="left: 910px; top: 122px; width: 69px;">
  DESDE</div>
<input name="CuoFecVenDex" type="text" id="CuoFecVenDex" 
class="fez tcal" style="left: 910px; top: 138px; width: 101px;"
value="<?php echo $CuoFecVenDex;?>"  
tabindex="<?php echo ++$TI;?>"/>


<div class="s1" style="left: 1017px; top: 122px; width: 69px;">
  HASTA</div>
<input name="CuoFecVenHax" type="text" id="CuoFecVenHax" 
class="fez tcal" style="left: 1017px; top: 138px; width: 101px;"
value="<?php echo $CuoFecVenHax;?>"  
tabindex="<?php echo ++$TI;?>"/>


<div class="s1" style="left: 1131px; top: 105px; width: 76px;">
CUOTA PROGRAMADA</div>
<select name="CuoPro" id="CuoPro"  
class="lt" style="left: 1131px; top: 138px; width: 92px" 
tabindex="<?php echo ++$TI;?>">
<?php
	echo FCBO("aux_nom","auxiliar","aux_des='SN'",$CuoPro,"S","N");
?>
</select>







<div class="s1" style="left: 35px; top: 168px; width: 116px;">
  FEC. PROG. DESDE</div>
<input name="CuoProDex" type="text" id="CuoProDex" 
class="fez tcal" style="left: 35px; top: 185px; width: 124px;"
value="<?php echo $CuoProDex;?>"  
tabindex="<?php echo ++$TI;?>"/>


<div class="s1" style="left: 169px; top: 166px; width: 114px;">
FEC.PROG.HASTA</div>
<input name="CuoProHax" type="text" id="CuoProHax" 
class="fez tcal" style="left: 169px; top: 185px; width: 124px;"
value="<?php echo $CuoProHax;?>"  
tabindex="<?php echo ++$TI;?>"/>



<div class="s1" style="left: 304px; top: 168px; width: 107px;">
CUOTA PAGADA</div>
<select name="CuoPag" id="CuoPag"  
class="lt" style="left: 304px; top: 185px; width: 95px" 
tabindex="<?php echo ++$TI;?>">
<?php
	echo FCBO("aux_nom","auxiliar","aux_des='SN'",$CuoPag,"S","N");
?>
</select>


<div class="s1" style="left: 413px; top: 168px; width: 116px;">
FEC. PAG. DESDE</div>
<input name="PagFecDes" type="text" id="PagFecDes" 
class="fez tcal" style="left: 413px; top: 185px; width: 117px;"
value="<?php echo $PagFecDes;?>"  
tabindex="<?php echo ++$TI;?>"/>


<div class="s1" style="left: 544px; top: 168px; width: 116px;">
FEC. PAG. HASTA</div>
<input name="PagFecHas" type="text" id="PagFecHas" 
class="fez tcal" style="left: 544px; top: 185px; width: 117px;"
value="<?php echo $PagFecHas;?>"  
tabindex="<?php echo ++$TI;?>"/>


<div class="s1" style="left: 672px; top: 168px; width: 156px;">
NUMERO DE OPERACION
</div>
<input name="PagNroOpe" type="text" id="PagNroOpe" 
class="lt" style="left: 672px; top: 185px; width: 227px;"
value="<?php echo $PagNroOpe;?>"  
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;?>" />


<input name="CmdB" type="button" id="CmdXls" class="btm" style="width:150px"
value="Exportar a Excel" onClick="fxXls()"  
tabindex="<?php echo ++$TI;?>" />

<input name="CmdB" type="button" id="CmdPdf" class="btm" style="width:150px"
value="Exportar a PDF" onClick="generarPDF()"  
tabindex="<?php echo ++$TI;?>" />

</div>

<script>
function generarPDF(){
	const { jsPDF } = window.jspdf;

    const doc = new jsPDF({
        orientation: 'landscape'
    });

    doc.text("Reporte de Clientes", 14, 15);

    doc.autoTable({
        html: '#Exportar_a_Excel',
        startY: 25
    });

    doc.save('reporte.pdf');
}
function fxPdf(){
	//html2pdf(document.getElementById('Exportar_a_Excel'));
	
	html2pdf()
    .set({
        margin: [20, 10, 10, 10], // arriba, izquierda, abajo, derecha
        filename: 'reporte.pdf',
        jsPDF: {
            orientation: 'landscape', // horizontal
            unit: 'mm',
            format: 'a4'
        }
    })
    .from(document.getElementById('Exportar_a_Excel'))
    .save();
	
}
function fxXls(){
	/*
	var tabla =document.getElementById("Exportar_a_Excel");
	tabla.querySelectorAll(
		".no-exportar"
	).forEach(function(td){
		td.remove();
	});
	//
	var libro =XLSX.utils.table_to_book(tabla);
    XLSX.writeFile(
        libro,
        "reporte.xlsx"
    );
	*/
	
	// Clonar tabla
    var tabla =
        document
        .getElementById("Exportar_a_Excel")
        .cloneNode(true);

    // columnas a eliminar
    // empieza desde 0
    var excluir = [14,17,24];

    // recorrer filas
    var filas = tabla.rows;

    for (var i = 0;
         i < filas.length;
         i++) {

        // borrar desde atrás
        for (var j =
             excluir.length - 1;
             j >= 0;
             j--) {

            filas[i]
            .deleteCell(
                excluir[j]
            );
        }
    }

    // exportar
    var html =
        tabla.outerHTML;

    var blob =
        new Blob(
            ['\ufeff' + html],
            {
                type:
                'application/vnd.ms-excel'
            }
        );

    var url =
        URL.createObjectURL(
            blob
        );

    var a =
        document.createElement('a');

    a.href = url;
    a.download =
        'reporte.xls';

    a.click();

    URL.revokeObjectURL(url);
	
}
</script>

<div  style="position: absolute; top: 212px; 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: 244px; width: 1180px; height: 330px; 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 style="text-align:left; background:#999;border: 1px solid black;white-space: nowrap">SERIE</th>
<th style="text-align:left; background:#999;border: 1px solid black;white-space: nowrap">NUMERO</th>
<th style="text-align:left; background:#999;border: 1px solid black;white-space: nowrap">FECHA</th>
<th style="text-align:left; background:#999;border: 1px solid black;white-space: nowrap">EMISOR RUC</th>
<th style="text-align:left; background:#999;border: 1px solid black;white-space: nowrap">EMISOR NOMBRE</th>
<th style="text-align:left; background:#999;border: 1px solid black;white-space: nowrap">CLIENTE RUC</th>
<th style="text-align:left; background:#999;border: 1px solid black;white-space: nowrap">CLIENTE NOMBRE </th>
<th style="text-align:right; background:#999;border: 1px solid black;white-space: nowrap">TOT.FACTURA</th>
<th style="background:#999;border: 1px solid black;white-space: nowrap">C.NRO</th>
<th style="background:#999;border: 1px solid black;white-space: nowrap">C.FEC.VCTO.</th>
<th style="background:#999;border: 1px solid black;white-space: nowrap">C.TOTAL</th>
<th style="background:#999;border: 1px solid black;white-space: nowrap">C.TIPO</th>
<th style="background:#999;border: 1px solid black;white-space: nowrap">C.ANU.</th>
<th style="background:#999;border: 1px solid black;white-space: nowrap">C.F.PROGR.</th>
<th style="background:#999;border: 1px solid black;white-space: nowrap" class="no-exportar">#</th>

<th style="background:#999;border: 1px solid black;white-space: nowrap">C.P.REGULAR</th>
<th style="background:#999;border: 1px solid black;white-space: nowrap">C.P.R.ESTADO</th>

<th style="background:#999;border: 1px solid black;white-space: nowrap" class="no-exportar">#</th>


<th style="background:#999;border: 1px solid black;white-space: nowrap">C.P.R.FEC.PAG</th>
<th style="background:#999;border: 1px solid black;white-space: nowrap">C.P.R.NRO.OPE</th>

<th style="background:#999;border: 1px solid black;white-space: nowrap">C.P.RETENCION</th>
<th style="background:#999;border: 1px solid black;white-space: nowrap">C.P.RET.ESTADO</th>
<th style="background:#999;border: 1px solid black;white-space: nowrap">C.P.RET.FEC.PAG</th>
<th style="background:#999;border: 1px solid black;white-space: nowrap">C.P.RET.SER.NUM</th>
<th style="text-align:center; background:#999;border: 1px solid black;white-space: nowrap" class="no-exportar">&gt;</th>

</tr>
</thead>
<tbody>
<?php	
$TOT_CUO=0;	  		
$i=0;
$s="SELECT * FROM vis_ges_xml_cuo WHERE ".$FF." ORDER BY 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_CUO=$TOT_CUO + $r['C_TOT'];
	$PAG_REG_EST="PENDIENTE";
	if($r['CUO_PAG_TOT']>0){
		$PAG_REG_EST="PAGADO";
	}
	$PAG_RET_EST="PENDIENTE";
	if($r['CUO_RET_TOT']>0){
		$PAG_RET_EST="PAGADO";
	}
	//
	
?>	
	<tr onDblClick="location.href='ges_facturas.php?Id=<?php echo $r['ID_XML'];?>&Pag=0'" <?php echo $CSS;?>>
	<!----------------------------------------------->
 
	<td style="white-space: nowrap;border: 1px solid black;"><?php echo $r['SER'];?></td>
	<td style="white-space: nowrap;border: 1px solid black;"><?php echo $r['NUM'];?></td> 
	<td style="white-space: nowrap;border: 1px solid black;"><?php echo FEP($r['FEC']);?></td>
    <td style="white-space: nowrap;border: 1px solid black;">'<?php echo $r['EMI_RUC'];?></td>   
    <td style="white-space: nowrap;border: 1px solid black;"><?php echo $r['EMI_NOM'];?></td>   
    <td style="white-space: nowrap;border: 1px solid black;">'<?php echo $r['CLI_RUC'];?></td>    
    <td style="white-space: nowrap;border: 1px solid black;"><?php echo $r['CLI_NOM'];?></td>        
    <td style="white-space: nowrap;border: 1px solid black;" align="right"><?php echo NF2($r['TOT'],2);?></td>    
    <td style="white-space: nowrap;border: 1px solid black;" align="center"><?php echo $r['C_NRO'];?></td> 
    <td style="white-space: nowrap;border: 1px solid black;" align="center"><?php echo FEP($r['C_FEC']);?></td> 
    <td style="white-space: nowrap;border: 1px solid black;" align="right"><?php echo NF2($r['C_TOT'],2);?></td> 
    <td style="white-space: nowrap;border: 1px solid black;"><?php echo $r['C_TIP'];?></td>
    <td style="white-space: nowrap;border: 1px solid black;" align="center"><?php echo $r['C_ANU'];?></td> 
    <td style="white-space: nowrap;border: 1px solid black;" align="center"><?php echo FEP($r['FEP']);?></td>   
    
    
    <td style="white-space: nowrap;border: 1px solid black;" class="no-exportar" >
	<img src="img/b_edit.png" width="16" height="16" style="cursor:pointer" onClick="fxFecPro('<?php echo $r['ID_CUO'];?>','<?php echo $r['C_ANU'];?>')">      
    </td> 
      
    <td style="white-space: nowrap;border: 1px solid black;" align="center"><?php echo $r['CUO_TOT_PAG'];?></td>     
    <td style="white-space: nowrap;border: 1px solid black;"><?php echo $PAG_REG_EST;?></td> 
    
    <td style="white-space: nowrap;border: 1px solid black;" class="no-exportar" >
    <input onDblClick="event.stopPropagation();" 
    onClick="fxCuoPag('<?php echo $r['ID_CUO'];?>',this,'<?php echo $r['C_ANU'];?>')" 
    type="button" value="Ver" style="width:50px">   
    </td> 
    
    
    <td style="white-space: nowrap;border: 1px solid black;" align="center"><?php echo FEP($r['C_PAG_FEC']);?></td> 
    <td style="white-space: nowrap;border: 1px solid black;"><?php echo $r['CUO_PAG_NRO_OPE'];?></td>  
    
	<td style="white-space: nowrap;border: 1px solid black;" align="center"><?php echo $r['CUO_TOT_RET'];?></td> 
    <td style="white-space: nowrap;border: 1px solid black;"><?php echo $PAG_RET_EST;?></td>
    <td style="white-space: nowrap;border: 1px solid black;" align="center"><?php echo FEP($r['CUO_RET_FEC']);?></td>
    <td style="white-space: nowrap;border: 1px solid black;"><?php echo $r['CUO_RET_SER_NUM'];?></td>
	<!----------------------------------------------->
    <td align="center" style="white-space: nowrap;border: 1px solid black;" class="no-exportar">
    <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: 1004px; top: 577px; width: 212px; text-align: right">
TOTAL CUOTA :<b><?php echo  NF2($TOT_CUO,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>
<script>
	function fxCuoPag(id,obj,anu){	
		if(anu=="SI"){
			alert("Registro anulado");
			return;
		}
		Ow("ges_facturas_pagar.php?MOD=1&KEY="+id,750,560);	
	}
	function POP_ACT(){	
		SM("ACTUALIZAR");
	}
	//++
	function fxFecPro(id,anu){
		if(anu=="SI"){
			alert("Registro anulado");
			return;
		}
		Ow("ges_facturas_fecha.php?MOD=1&KEY="+id,540,270);
	}
</script>
</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>

