<?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;}
$StrId=V($_POST['TxtId']);
$StrCmd=V($_POST['TxtAc']);
//-------------------------
		
$StrSer=V($_POST['TxtSer']);		
$StrNum=V($_POST['TxtNum']);		
$StrDex=V($_POST['TxtDex']);		
$StrHax=V($_POST['TxtHax']);
if(strlen($StrDex)==0)$StrDex=date("d-m-y");			
if(strlen($StrHax)==0)$StrHax=date("d-m-y");			
$StrPro=V($_POST['TxtPro']);
$StrVend=V($_POST['TxtVend']);
$Tdp=V($_POST['Tdp']);
$Tdp_=trim(vbmid(LIKE($Tdp),1,2));
$StrSN=V($_POST['CboSN']);	
$StrOpe=V($_POST['TxtOpe']);
//++
$IdUsu=vbval(V($_SESSION['SYS_USER_ID']));
//
if($_SESSION['SYS_USER_ALM']=="%"){
if(strlen($StrAlm)==0)$StrAlm=T($StrAlm);//$StrAlm=GetSO("alm_nombre","almacenes","","alm_nombre");
}else{
$StrAlm=$_SESSION['SYS_USER_ALM'];
}	

$StrAlm=T($StrAlm);
		
if(strlen($StrCom)==0) $StrCom="TODOS";	
//-------------------------
if($StrCom=="TODOS"){
$StrCom_="%";
}else{
$StrCom_=$StrCom;
}
$StrNum_=$StrNum."%";
$StrSer_=$StrSer."%";
if(strlen($StrDex)==0){
$StrDex_="2000-01-01";
}else{
$StrDex_=ToDate($StrDex);
}
if(strlen($StrHax)==0){
$StrHax_="2020-12-01";
}else{
$StrHax_=ToDate($StrHax);
}
if(strlen($StrSN)==0 || $StrSN=="TODOS"){
$StrSN_="%";
}else{
$StrSN_=substr($StrSN,0,1);
}
$StrPro_=$StrPro."%";
$StrVend_=$StrVend."%";
$StrOpe_=$StrOpe."%";
//-------------------------
$FF="ID>0 AND ALM LIKE '$StrAlm' AND COM LIKE '$StrCom_' AND
NUM LIKE '$StrNum_' AND SER LIKE '$StrSer_' AND 
FEC >= '$StrDex_' AND FEC <= '$StrHax_' AND 
CLI LIKE '$StrPro_' AND ANU LIKE '$StrSN_' AND 
VEND LIKE '$StrVend_' AND OPE LIKE '$StrOpe_' AND TDP LIKE '$Tdp_' ";
if($IdUsu>0){
	$FF=$FF." AND IDU=".$IdUsu;
}
//++
$LStrTR=gn("count(*)","vventas",$FF);
$LStrPag=V($_POST['TxtPag']);
if($StrCmd=="F"){$LStrPag="1";}
$VP_RegXPag=19;	
$LStrPag=PagGet($LStrPag,$StrCmd,$LStrTR,$VP_RegXPag);
$AT=gs("at","usuarios","id_usuario=$IdUsu");
?>

<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="target-densitydpi=device-dpi, initial-scale=1.0, user-scalable=no" />
<title>Ventas - Buscar</title>
<!----------------------------------------->
<?php AddJs(); ?>
<script type="text/javascript" src="ja/funciones.js"></script>

<!----------------------------------------->
<link href="css/bootstrap.css" rel="stylesheet">
<!----------------------------------------->
<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;}

.cmd{
	margin-top:1rem; margin-right:0.5rem;width:8rem;
}
</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 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="ventas_busscar.php" autocomplete="off"
style="margin:0px; padding:0px; display:inline;" onSubmit="return false;">

<!----------------------------------------->
<div class="form-row" style="margin:0 0 0 0; padding: 0 0 0 0;">
    <div style="width:100%; background-color:#2E4994; min-height:60px;">
        <table width="100%" border="0">
        <tr>
        <td width="15px">&nbsp;</td>
        <td width="48px"><img src="b.png" width="48" height="48" longdesc="../sales.png"></td>
        <td style="color:#FFF"><b>VENTAS BUSCAR</b></td>
        <td >&nbsp;</td>
        </tr>
        </table>
    </div>
</div>
<!----------------------------------------->

    
<div class="form-row d-flex justify-content-start" style="text-align:left; margin-left:15px; margin-right:15px">    
<div class="form-group col-sm-12"  >
<input name="CmdB" type="button" id="CmdB" class="btn btn-primary cmd"
value="Buscar" onClick="fFiltrar();"  
tabindex="<?php echo ++$TI;?>" />

<input name="CmdB" type="button" id="CmdZ" class="btn btn-primary cmd"
value="Volver" onClick="fBuscar('ventas_respon.php?TxtAc=X');"  
tabindex="<?php echo ++$TI;?>" />

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

</div>
</div>

<div class="form-row" style=" margin-left:15px; margin-right:15px">    
    <div class="form-group col-sm-4" style="margin:0 0 0 0; padding: 0 0 0 0;">
    <table style="margin:0 0 0 0; padding: 0 0 0 0; ">
    <tr>
    <td>&nbsp;</td>        
    </tr>
    </table> 
    </div>     
</div>

    <div class="form-row" style=" margin-left:15px; margin-right:15px">    
    	<div class="form-group col-sm-3" style="margin:0 0 0 0; padding: 0 0 0 0;">
        <table style="margin:0 0 0 0; padding: 0 0 0 0; ">
        <tr>
        <td  width="40%">
        <label >ALMACEN</label>                
        <select name="CboAlm" id="CboAlm" 
        class="form-control lt" 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>        
        </td>
        
        <td  width="40%">
        <label >COMPROBANTE</label>                     
        <select name="CboCom" id="CboCom"
        class="form-control lt" tabindex="<?php echo ++$TI;?>">
        <?php 
            echo FCBO("com_nombre",
                      "comprobantes",
                      "id_comprobante>0 AND com_nombre IN('NOTA DE VENTA')",$StrCom,"S","N");?>
        </select>
        </td>
                
        <td  width="20%">
        <label >SERIE</label>                     
        <input name="TxtSer" type="text" id="TxtSer" 
        class="form-control lt" value="<?php echo $StrSer;?>"  
        tabindex="<?php echo ++$TI;?>"/>
        </td> 
               
        </tr>
        </table> 
        </div> 
        
    	<div class="form-group col-sm-3" style="margin:0 0 0 0; padding: 0 0 0 0;">
        <table style="margin:0 0 0 0; padding: 0 0 0 0; ">
        <tr>
        <td  width="40%">
        <label >NUMERO</label>        
        <input name="TxtNum" type="text" id="TxtNum" 
        class="form-control lt" value="<?php echo $StrNum;?>"  
        tabindex="<?php echo ++$TI;?>"/>
        </td>
        <td  width="30%">
        <label >DESDE</label>        
        <input name="TxtDex" type="text" id="TxtDex" 
        class="form-control fe" value="<?php echo $StrDex;?>"  
        tabindex="<?php echo ++$TI;?>"/>
        </td>        
        <td  width="30%">
        <label >HASTA</label>        
        <input name="TxtHax" type="text" id="TxtHax" 
        class="form-control fe" value="<?php echo $StrHax;?>"  
        tabindex="<?php echo ++$TI;?>"/>
        </td>
        
        </tr>
        </table> 
        </div> 
        
    	<div class="form-group col-sm-4" style="margin:0 0 0 0; padding: 0 0 0 0;">
        <table style="margin:0 0 0 0; padding: 0 0 0 0; ">
        <tr>
        <td  width="40%">
        <label >CLIENTE</label>        
        <input name="TxtPro" type="text" id="TxtPro" 
        class="form-control lt" value="<?php echo $StrPro;?>"  
        tabindex="<?php echo ++$TI;?>"/>
        </td>  
        
        <td  width="40%">
        <label >VENDEDOR</label>        
        <input name="TxtVend" type="text" id="TxtVend" 
        class="form-control lt" value="<?php echo $StrVend;?>"  
        tabindex="<?php echo ++$TI;?>"/>
        </td>
        
        <td  width="20%">
        <label >TIP.PAGO</label>        
        <select name="Tdp" id="Tdp" 
        class="form-control lt" tabindex="<?php echo ++$TI;?>">
        <?php echo FCBO_("tipp_nombre","tipos_pagos","",$Tdp,"S","N");?>
        </select>
        </td>      
        </tr>
        </table> 
        </div>   
        
    	<div class="form-group col-sm-2" style="margin:0 0 0 0; padding: 0 0 0 0;">
        <table style="margin:0 0 0 0; padding: 0 0 0 0; ">
        <tr>
        <td  width="60%">
        <label >NRO.OPERACION</label>        
        <input name="TxtOpe" type="text" id="TxtOpe" 
        class="form-control lt" value="<?php echo $StrOpe;?>"  
        tabindex="<?php echo ++$TI;?>"/>
        </td>  
        
        <td  width="40%">
        <label >ANULADO</label>        
        <select name="CboSN" id="CboSN" 
        class="form-control lt" onkeydown="return SoloTextoEx(event,'CmdB');" 
        tabindex="<?php echo ++$TI;?>">
        <?php
        echo FCBO("aux_nom","auxiliar","aux_des='SN'",$StrSN,"S","N");
        ?>
        </select>
        </td>
      
        </tr>
        </table> 
        </div>        
	</div>

<div class="form-row" style=" margin-left:15px; margin-right:15px">    
    <div class="form-group col-sm-4" style="margin:0 0 0 0; padding: 0 0 0 0;">
    <table style="margin:0 0 0 0; padding: 0 0 0 0; ">
    <tr>
    <td>&nbsp;</td>        
    </tr>
    </table> 
    </div>     
</div>

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

<div class="tableFixHead" id="DivT" style="border:1px solid; border-color:#666;height:100%;background-color:#FFF;overflow:auto; margin-left:15px; margin-right:15px">
<table id="Exportar_a_Excel" width="100%" style="font-size:0.9rem;">
<thead>
<tr>
<th width="74" style="text-align:left; background:#999">ALMACEN</th>
<th width="97" style="text-align:left; background:#999"">COMPROB</th>
<th width="90"  style="text-align:left; background:#999"">NUMERO</th>
<th width="67"  style="text-align:left; background:#999"">FECHA</th>
<th width="241"  style="text-align:left; background:#999"">CLIENTE</th>
<th width="146" style="text-align:left; background:#999"">VENDEDOR</th>
<th width="50" style="text-align:left; background:#999"">T.PAGO</th>
<th width="138" style="text-align:left; background:#999"">Nro OPERACION</th>
<th width="12" style="text-align:left; background:#999"">A</th>
<th width="65" style="text-align:right; background:#999"">TOTAL</th>
<th width="68" style="text-align:right; background:#999"">C.ENVIO</th>
<th width="78" style="text-align:right; background:#999"">T.FINAL</th>
<th width="78" style="text-align:right; background:#999"">&nbsp;</th>
</tr>
</thead>
<tbody>
<?php		  		
$i=0;
$ST=0;
$CE=0;
$TF=0;
$s="SELECT ID,ALM,COM,CONCAT(SER,'-',NUM) as SER_NUM,
DATE_FORMAT(FEC,'%d-%m-%y') as FEX,CLI,
VEND,ANU,TOT,OPE,TDP,COS_ENV ,IMP_TOT
FROM vventas WHERE ".$FF." ORDER BY ALM,COM,SER,NUM,FEC,CLI ";

$s=PagSql($s,$LStrPag,$VP_RegXPag,$LStrTR);
$result = grs($s);				
while ($row = $result->fetch_assoc()){
	$i++;
	$CSS="";
	if($i%2==0){
		$CSS=" style=\"background-color:#E2E2E2\" ";
	}
	?>	
	<tr onDblClick="location.href='ventas_respon.php?Id=<?php echo $row['ID'];?>&Pag=0'" <?php echo $CSS;?>>
	<!----------------------------------------------->
	<td><?php echo vbl($row['ALM'],16);?></td>  
	<td><?php echo $row['COM'];?></td> 
	<td><a target="_blank" href="ventas_respon.php?Id=<?php echo $row['ID'];?>">'<?php echo $row['SER_NUM'];?></a></td>
	<td><?php echo $row['FEX'];?></td>
	<td><?php echo vbl($row['CLI'],30);?></td> 
	<td><?php echo vbl($row['VEND'],41);?></td>
    <td><?php echo $row['TDP'];?></td>
    <td><?php echo $row['OPE'];?></td>
    <td><?php echo $row['ANU'];?></td>
	<td style="text-align:right"><?php echo NF2($row['TOT'],1);?></td>
    <td style="text-align:right"><?php echo NF2($row['COS_ENV'],1);?></td>
    <td style="text-align:right"><?php echo NF2($row['IMP_TOT'],1);?></td> 
	<!----------------------------------------------->
    
    </td>
    <td class="tdx" align="center">
    <a href="#" onClick="location.href='proformas.php?Id=<?php echo $r['ID'];?>&Pag=0&COPIAR=1'">
    <img src="copiar.png" width="16" height="16">
    </a>
    </td>
	</tr>
	<?php
	$CE=$CE+$row['COS_ENV'];
	$TF=$TF+$row['IMP_TOT'];
	$ST=$ST+$row['TOT'];
	
}

?>		  
</tbody>
</table>
</div>

 
<div class="form-row" style=" margin-left:15px; margin-right:15px">        
    <div class="form-group col-sm-6" style="margin:0 0 0 0; padding: 0 0 0 0;">
        <table style="margin:0 0 0 0; padding: 0 0 0 0;min-width:95%">
        <tr>        
        <td width="60%"> 
        <label ><b>Doble Click sobre el registro para activar Actualizacion</b></label>          

        </td>        
        </tr>
        </table>                 
    </div>  
    
    <div class="form-group col-sm-2" style="margin:0 0 0 0; padding: 0 0 0 0;">
        <table style="margin:0 0 0 0; padding: 0 0 0 0;min-width:95%">
        <tr>        
        <td width="50%" style="text-align:right">
        <label ><b>TOTAL</b></label>
        </td>        
        <td width="50%" style="text-align:right">
        <label ><b><?php echo  NF2($ST,1);?></b></label>
        </td>      
        </tr>
        </table>                 
    </div>   
    
    <div class="form-group col-sm-2" style="margin:0 0 0 0; padding: 0 0 0 0;">
        <table style="margin:0 0 0 0; padding: 0 0 0 0;min-width:95%">
        <tr>        
        <td width="50%" style="text-align:right">
        <label ><b>T.ENVIO</b></label>
        </td>        
        <td width="50%" style="text-align:right">
        <label ><b><?php echo  NF2($ST,1);?></b></label>
        </td>       
        </tr>
        </table>                 
    </div> 

    <div class="form-group col-sm-2" style="margin:0 0 0 0; padding: 0 0 0 0;">
        <table style="margin:0 0 0 0; padding: 0 0 0 0;min-width:95%">
        <tr>        
        <td width="50%" style="text-align:right">
        <label ><b>T.FINAL</b></label>
        </td>        
        <td width="50%" style="text-align:right">
        <label ><b><?php echo  NF2($ST,1);?></b></label>
        </td>       
        </tr>
        </table>                 
    </div>     
</div>
<!----------------------------------------->
<?php include("ocultos.php");?>
<!----------------------------------------->
</form>

<form action="ficheroExcel.php" 
    method="post" target="_blank" id="FormularioExportacion" >
    
    <div style="position: absolute; left: 300px; top: 60px; width: 45px; height: 15px;">  
    <input name="" type="button" class="botonExcel btn btn-primary cmd" 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>
