<?php

include ("../conexion.php");
    
require_once '../dompdf/autoload.inc.php';


require_once '../dompdf/lib/html5lib/Parser.php';
require_once '../dompdf/lib/php-font-lib/src/FontLib/Autoloader.php';
require_once '../dompdf/lib/php-svg-lib/src/autoload.php';
require_once '../dompdf/src/Autoloader.php';
Dompdf\Autoloader::register();

use Dompdf\Dompdf;

		 

				

$codigoHTML='

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">





<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Lista</title>

</head>

   <script type="text/php">


        if ( isset($pdf) ) {

          $font = Font_Metrics::get_font("helvetica", "bold");
          $pdf->page_text(72, 18, "Header: {PAGE_NUM} of {PAGE_COUNT}", $font, 6, array(0,0,0));

        }
        
</script>
<body>
<div align="center">
  <p>&nbsp;</p>';
  
       $parametros = "SELECT * FROM web_0000 ";
       $result_parametros = $mysqli->query($parametros);
       $row_para = $result_parametros->fetch_array();
     
	   $NombreComercial =  $row_para["NOMCOM"];
	   $razsoc          =  $row_para["RAZSOC"];
	   $Direccion       =  $row_para["DIREMP"];
	   $Cedula          =  $row_para["CEDJUR"];
	   $Telefono        =  $row_para["NUMTEL"];

$codigoHTML='
    <table width="100%"  cellpadding="0" cellspacing="0"  border="0">
      <tr>
        <td width="13%" rowspan="4"><img src="../img/Logo_reportes.png"  /></td>
        <td width="87%"><font color="red" size=4><strong>'.$NombreComercial.'</strong></font></td>
      </tr>
      <tr>
        <td height="12"><font size=2 >Cedula '.$Cedula.'</font></td>
      </tr>
      <tr>
        <td height="12"><font size=2 >'.$Direccion.'</font></td>
      </tr>
      <tr>
        <td height="22"><font size=2 >Numero de Telefono '.$Telefono.'</font></td>
      </tr>
    </table>';
  



  
  if ($result = $mysqli->query("SELECT * FROM web_0301 WHERE ESTCLI ='ACTIVO'  and cdgcli != '9999' ")) {
   $filas = $result->num_rows;
   $result->close();
}


	
	 
	 $codigoHTML.='
  <table width="100%" height="16%" border="1" cellpadding="0" cellspacing="0" >
      <tr>
      <td width="100%" height="21" colspan="3" align="center"><font size=3 ><strong>REPORTE DE CLIENTES</strong></font></td>
	     </tr>
      <tr>
	       <td width="100%" height="21" colspan="3" align="center"><font size=3 ><strong>"TODOS LOS CLIENTES"</strong></font></td>
      </tr>
      <tr>
        
      </tr>
  </table>
  ';
	
	
	 $codigoHTML.='
<table width="100%" role="rows" cellpadding="0" cellspacing="0" border="1">
    <tr>
      
        <td width="10%"  align="center"bgcolor="#CCCCCC" ><font size=1 ><strong>Codigo</strong></font></td>  
		<td width="50%" align="center" bgcolor="#CCCCCC"><font size=1 ><strong>Cliente</strong></font></td> 
        <td width="20%" align="center" bgcolor="#CCCCCC"><font size=1 ><strong>Cedula</strong></font></td>
        <td width="20%" align="center" bgcolor="#CCCCCC"><font size=1 ><strong>Telefono</strong></font></td>
        <td width="35%" align="center" bgcolor="#CCCCCC"><font size=1 ><strong>Correo</strong></font></td>
	
 
    </tr>
  </table>';
          
		 $consulta="SELECT * FROM web_0301 WHERE ESTCLI ='ACTIVO' and cdgcli != '9999' ORDER BY  DSCCLI ASC   " ;
	    $count = 0;		  		
		$contador=0;
		if ($resultado = $mysqli->query($consulta)) 		

		  
  		while ($dato1 = $resultado->fetch_assoc()) {     //  si encuentra datos
			 
				$cdgcli     = $dato1['CDGCLI'];
	            $dsccli     = $dato1['DSCCLI'];
				$cedcli     = $dato1['CEDCLI'];
		     	$numtel     = $dato1['NUMTEL'];
				$corcli     = $dato1['corcli'];

	 if($count == 0 )		
                $codigoHTML.='<table width="100%"  rules="none" border="0">';

            $codigoHTML.=' 
    
      <tr>
  		
        <td width="10%" align="center" >  <font size=1 >'.$cdgcli.'</font></td>
   	    <td width="50%">  <font size=1 align="right">'.$dsccli.'</font></td>
		<td width="20%" align="center">  <font size=1 >'.$cedcli.'</font></td>
		<td width="20%" align="center">  <font size=1 >'.$numtel.'</font></td>
		<td width="35%" align="center">  <font size=1 >'.$corcli.'</font></td>
           </tr> ';
              $count++;
       }
        if($count > 1) 
            $codigoHTML.='</table>';
 
     

			
$codigoHTML.='
   </p>

</div>
</body>
</html>';

$codigoHTML=utf8_decode($codigoHTML);
$dompdf=new DOMPDF();
$dompdf->set_paper( "A4", "Portrait" ); // a4,horizontal
$dompdf->load_html($codigoHTML);
$dompdf->render();
// add the header
//$canvas = $dompdf->get_canvas();
//$font = Font_Metrics::get_font("helvetica", "bold");

// the same call as in my previous example
//$canvas->page_text(745, 555, "Pagina : {PAGE_NUM} de {PAGE_COUNT}",
//                   $font, 8, array(0,0,0));

ini_set("memory_limit","7000M");

$dompdf->stream("Lista de Clientes.pdf", array("Attachment" => false));
 


?>
