<?php

header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=Reporte_Clientes_Excel.xls");

include ("../conexion.php");

      $parametros = "SELECT * FROM web_0000 ";
       $result_parametros = $mysqli->query($parametros);
       $row_para = $result_parametros->fetch_array();
     
	   $NombreComercial =  $row_para["NOMCOM"];
	   $razon         =  $row_para["RAZSOC"];
	   $Direccion       =  $row_para["DIREMP"];
	   $Cedula          =  $row_para["CEDJUR"];
	   $Telefono        =  $row_para["NUMTEL"];


?>
<!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>Reporte Clientes Excel </title>
<style type="text/css">
<!--
.Estilo1 {color: #CCCCCC}
.Estilo4 {font-size: medium}
.Estilo6 {
	color: #000000;
	font-weight: bold;
}
.Estilo17 {color: #000000; font-weight: bold; font-size: 14px; }
-->
</style>
</head>
<body>
<table width="92%" border="0" cellspacing="0" cellpadding="0">
    
    <tr>
      <td><div align="center"></div></td>
      <td colspan="10"  ><div align="center"><font size=8 ><?php echo $NombreComercial?></font></div>
      <div align="center"></div><div align="center"></div></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td colspan="10" ><div align="center"><font size="3" ><?php echo $razon?></font></div></td>
    </tr>
    <tr>
      <td><div align="center"></div></td>
      <td colspan="10" ><div align="center"><font size="2" ><?php echo $Cedula; ?></font></div></td>
    </tr>
    <tr>
      <td><div align="center"></div></td>
      <td colspan="10" ><div align="center"><font size="2" ><?php echo $Direccion; ?></font></div></td>
    </tr>
    <tr>
      <td><div align="center"></div></td>
      <td colspan="10" ><div align="center"><font size="2" ><?php echo $Telefono; ?></font></div></td>
    </tr>
    <tr>
      <td><span class="Estilo1"></span></td>
      <td colspan="10" ><span class="Estilo1"></span></td>
    </tr>
  <tr>
     <td></td>
 <td colspan="10"  bgcolor="skyblue"><div align="center"><strong><font size="3" >Reporte Lista de Clientes</font>  </div></td>
  </tr>
     
     <tr>
       <td></td>
    
     </tr>
     
  <tr>
      <td width="1%"></td>


    <td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Codigo</strong></font></span></td>
    <td width="30%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Cliente</strong></font></span></td>
    <td width="20%" align="center" bgcolor="skyblue"><span class="Estilo4"><strong>Cedula</strong></font></span></td> 
	<td width="20%" align="center" bgcolor="skyblue"><span class="Estilo4"><strong>Telefono</strong></font></span></td>
	<td width="20%" align="center" bgcolor="skyblue"><span class="Estilo4"><strong>Contacto</strong></font></span></td>
    <td width="20%" align="center"bgcolor="skyblue"><span class="Estilo4"><strong>Direccion</strong></font></span></td>
    <td width="20%" align="center" bgcolor="skyblue"><span class="Estilo4"><strong>Correo</strong></font></span></td>
	<td width="20%" align="center" bgcolor="skyblue"><span class="Estilo4"><strong>Provincia</strong></font></span></td>
	<td width="20%" align="center" bgcolor="skyblue"><span class="Estilo4"><strong>Canton</strong></font></span></td>
	<td width="20%" align="center" bgcolor="skyblue"><span class="Estilo4"><strong>Distrito</strong></font></span></td>

  </tr>
  
<?PHP
		 $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'];
				$percon     = $dato1['PERCON'];
				$dircli     = $dato1['DIRCLI'];
				$cdgprovin  = $dato1['cdgprovin'];
				$cdgcanton  = $dato1['cdgcanton'];
				$cdgdistri  = $dato1['cdgdistri'];
				$provincia  = "INDEFINIDO"; 
   				$canton     = "INDEFINIDO";
   				$distrito   = "INDEFINIDO";
				
if (!empty($cdgprovin)){
	
	$query4 = "SELECT * FROM hac_provincias where cdgprovin = $cdgprovin ";
	$resultado4=$mysqli->query($query4);
	$query4 = $resultado4->fetch_array();			

	$query2 = "SELECT * FROM hac_cantones where cdgprovin = $cdgprovin  AND  cdgcanton = $cdgcanton  ";
	$resultado2=$mysqli->query($query2);
	$query2 = $resultado2->fetch_array();	
	

	$query3 = "SELECT * FROM hac_distritos where cdgprovin = $cdgprovin AND  cdgcanton = $cdgcanton AND  cdgdistri = $cdgdistri    ";
	$resultado3=$mysqli->query($query3);
	$query3 = $resultado3->fetch_array();	
  
  
   $provincia =  $query4['dscprovin']; 
   $canton    =  $query2['dsccanton'];
   $distrito  =  $query3['dscdistri'];

}
			
?>  

 <tr>
   <td></td>
   <td align="center"><font size=1 ><?php echo $cdgcli?></font></td>
   <td align="left"><font size=1 ><?php echo $dsccli ?></font></td>
   <td align="center"><font size=1 ><?php echo $cedcli  ?></font></td>
   <td align="center"><font size=1 ><?php echo $numtel ?></font></td>
   <td align="left"><font size=1 ><?php echo $percon ?></font></td>
   <td align="left"><font size=1 ><?php echo $dircli ?></font></td>
   <td align="left"><font size=1 ><?php echo $corcli ?></font></td>
   <td align="left"><font size=1 ><?php echo $provincia; ?></font></td>
   <td align="left"><font size=1 ><?php echo $canton; ?></font></td>
   <td align="left"><font size=1 ><?php echo $distrito; ?></font></td>

 </tr>
  
	<?php $contador++;
							}
						
	
  ?>
  
  
  
 



</body>
</html>