<?php

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

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


       $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"];

     $fecini    = $_GET["fechainicio"];
	 $fecfin    = $_GET["fechafin"];
	 
     $fechainicio= implode("-", array_reverse(explode("-", $fecini))); 
	 $fechafin= implode("-", array_reverse(explode("-", $fecfin))); 
	
	$where="1=1";


if (($fechainicio<>"") and ($fechafin<>"")) {
	$where.=" AND pedidos_lineas.fecfac between '".$fechainicio."' AND '".$fechafin."'";
} else {
	if ($fechainicio<>"") {
		$where.=" and  pedidos_lineas.fecfac >='".$fechainicio."'";
	} else {
		if ($fechafin<>"") {
			$where.=" and  pedidos_lineas.fecfac <='".$fechafin."'";
		}
	}
}

	 
 $fechainicio= implode("-", array_reverse(explode("-", $fecini))); 
 $fechafin= implode("-", array_reverse(explode("-", $fecfin))); 

					
?>
<!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 Detallado de Pedidos </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="86%" border="0" cellspacing="0" cellpadding="0">
    
    <tr>
      <td><div align="center"></div></td>
      <td colspan="4"  ><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="4" ><div align="center"><font size="3" ><?php echo $razsoc?></font></div></td>
    </tr>
    <tr>
      <td><div align="center"></div></td>
      <td colspan="4" ><div align="center"><font size="2" ><?php echo $Cedula; ?></font></div></td>
    </tr>
    <tr>
      <td><div align="center"></div></td>
      <td colspan="4" ><div align="center"><font size="2" ><?php echo $Direccion; ?></font></div></td>
    </tr>
    <tr>
      <td><div align="center"></div></td>
      <td colspan="4" ><div align="center"><font size="2" ><?php echo $Telefono; ?></font></div></td>
    </tr>
    <tr>
      <td><span class="Estilo1"></span></td>
      <td colspan="4" ><span class="Estilo1"></span></td>
    </tr>
  <tr>
     <td></td>
 <td colspan="4"  bgcolor="skyblue"><div align="center"><strong><font size="3" >Reporte Detallado de Pedidos</font>  </div></td>
  </tr>
     
     <tr>
       <td></td>
       <td colspan="4"   border="1"><div align="center"><font size="3" >Fecha del <?php echo $fecini; ?> Al <?php echo $fecfin; ?></font></div></td>
     </tr>
     
  <tr>
      <td width="2%"></td>

    <td width="8%"  align="center"bgcolor="skyblue" ><span class="Estilo4"><strong>Codigo</strong></font></span></td>
    <td width="27%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Articulo</strong></font></span></td>
    <td width="8%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Cantidad</strong></font></span></td>
    <td width="55%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Detalle</strong></font></span></td>
  </tr>
  
<?php
		

	
	
	  $consulta= "SELECT SUM(mondes) AS mondes, SUM(importe) AS importe, SUM(impuesto) AS impuesto, SUM(cantidad) AS cantidad, pedidos_lineas.cdgfam, pedidos_lineas.borrado, pedidos_lineas.codigo, pedidos_lineas.dscart, pedidos_lineas.fecfac , familias.dscfam FROM pedidos_lineas,familias WHERE  pedidos_lineas.cdgfam=familias.cdgfam AND pedidos_lineas.borrado=0   AND ".$where. " GROUP BY  pedidos_lineas.codigo  ORDER BY    pedidos_lineas.dscart ASC " ;
    if ($resultado = $mysqli->query($consulta)){
        $count = 0;
  		while ($fila = $resultado->fetch_assoc()) {	
            $codigo        = $fila["codigo"];
            $dscart        = $fila["dscart"];
        	$cantidad = number_format($fila['cantidad'], 2);	
			

?>  

 <tr>
   <td></td>
   <td align="left"><font size=1 ><?php echo $codigo?></font></td>
   <td align="left"><font size=1 ><?php echo $dscart?></font></td>
   <td align="center"><font size=1 ><?php echo $cantidad?></font></td>
   <td align="center"><font size=1 ></font></td>
 </tr>
  
  <?php
	    $count++;
  	        
		 } 
		 
	 	 } 
		 
  ?>
 </table>
	

</body>
</html>