<?php

header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=Reporte_inventario.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"];

     $cdgfam=$_GET["Familia"];
	 $cdglin=$_GET["Linea"];
	 $cdgpro=$_GET["cdgpro"];

	$where="1=1";
if ($cdglin <> "") { $where.=" AND cdglin='$cdglin'"; }
if ($cdgfam <> "") { $where.=" AND cdgfam='$cdgfam'"; }
if ($cdgpro <> "") { $where.=" AND cdgpro='$cdgpro'"; }


				
	 
	 if ($cdgfam=="") {
	 
	$dscfam="TODAS LAS FAMILIAS";
	 
	     } else {

		
					$query_facturas = "SELECT * FROM familias WHERE cdgfam=$cdgfam ";
					$rs_facturas = $mysqli->query($query_facturas);
					$row = $rs_facturas->fetch_assoc();
					
					$dscfam = $row["dscfam"];
		
		
     }	
	 

	 
	 if ($cdglin=="") {
	 
	$dsclin="TODAS LAS LINEAS";
	 
	     } else {

		
					$query_facturas2 = "SELECT * FROM Lineas WHERE cdglin=$cdglin ";
					$rs_facturas2 = $mysqli->query($query_facturas2);
					$row = $rs_facturas2->fetch_assoc();
					
					$dsclin = $row["dsclin"];
		
		
     }	
	 
	 
	 
	 	 
	 if ($cdgpro=="") {
	 
	$dscpro="TODOS LOS PROVEEDORES";
	 
	     } else {

		
					$query_facturas3 = "SELECT * FROM proveedores WHERE cdgpro=$cdgpro ";
					$rs_facturas3 = $mysqli->query($query_facturas3);
					$row3 = $rs_facturas3->fetch_assoc();
					
					$dscpro= $row3["dscpro"];
		
		
     }	
	 
	 

?>
<!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 DE INVENTARIO</title>
</head>
<body>
<table width="50%" border="0" cellspacing="0" cellpadding="0">
    <tr>   </tr>
  <tr>
     <td></td>
 <td colspan="6"  bgcolor="skyblue"><div align="center"><strong>REPORTE LISTA DE INVENTARIO</strong></div></td>
  </tr>
  
   <tr>
     <td></td>
 <td colspan="6"  bgcolor="skyblue"><div align="center"><strong><?php echo $cdgpro." - ". $dscpro ; ?></strong></div></td>
  </tr>
  
     <tr>
     <td></td>
 <td colspan="6"  bgcolor="skyblue"><div align="center"><strong><?php echo "FAMILIA : ". $dscfam." -  LINEA : " . $dsclin ; ?></strong></div></td>
  </tr>
  
     <tr>   </tr>
  <tr>
      <td width="10%"></td>
    <td  border="1" width="10%"><div align="center"><strong>CODIGO</strong></div></td>
    <td width="12%"><div align="center"><strong>BARRAS</strong></div></td>
    <td width="37%"><div align="center"><strong>DESCRIPCION</strong></div></td>
    <td width="16%"><div align="center"><strong>EXISTENCIA</strong></div></td>
    <td width="25%"><div align="center"><strong>NORMAL</strong></div></td>
	<td width="25%"><div align="center"><strong>MAYOREO</strong></div></td>
  </tr>
  
<?PHP
    
	 
$cdgfam2="";

 $consulta= "select cdgart,cdgbar,dscart,exiact,Pre001, Pre002,cdgfam,COB_IV from web_1001 WHERE ".$where."ORDER BY cdgfam , dscart";
	if ($resultado = $mysqli->query($consulta)) 

  	while ($res = $resultado->fetch_assoc()) {
	
	$codigo  = $res["cdgart"];
	$cdgbar  = $res["cdgbar"];
	$cdgbar2 = "Cod. ".$cdgbar;
	$dscart  = $res["dscart"];
	$exiact  = number_format ( $res["exiact"], 2, '.', ',');
	$Pre001  = number_format ( $res["Pre001"], 2, '.', ',');
	$Pre002  = number_format ( $res["Pre002"], 2, '.', ',');
	$cdgfam  = $res["cdgfam"];
	$cob_iv  = $res["COB_IV"];
	$cdgfam  = sprintf("%03d",$cdgfam); 
				
if ($cob_iv  == 1 ){$impuesto="GRAVADO";} else {$impuesto="EXENTO";};

?>  


<?php  if ($cdgfam <> $cdgfam2 ){ 

						
		$consulta1 = "SELECT * FROM familias  WHERE cdgfam='$cdgfam' AND cdgfam <> 0 ";
		$result = $mysqli->query($consulta1);
		$row = $result->fetch_array();
		
		$cdgfam  = $row["cdgfam"];	
		$dscfam  = $row["dscfam"];	

  ?>


 <tr>
   <td></td>
   <td  bgcolor="skyblue">FAMILIA</td>
   <td  bgcolor="skyblue"><?php echo $cdgfam." - ". $dscfam ?></td>
   <td  bgcolor="skyblue">&nbsp;</td>
   <td  bgcolor="skyblue">&nbsp;</td>
   <td  bgcolor="skyblue">&nbsp;</td>
     <td  bgcolor="skyblue">&nbsp;</td>
 </tr>
<?php  }    ?>
 <tr>
   <td></td>
   <td><div align="left"><?php echo $codigo; ?></div></td>
	<td><div align="left"><?php echo $cdgbar2; ?></div></td>
	<td><?php echo $dscart; ?></td>
	<td><div align="center"><?php echo $exiact; ?></div></td>
	<td><div align="right"><?php echo $Pre001; ?></div></td>    
	<td><div align="center"><?php echo $Pre002; ?></div></td>                    
 </tr> 
  <?php
  
  $cdgfam2=$res["cdgfam"];
  $cdgfam2=sprintf("%03d",$cdgfam2); 
}
  ?>
</table>
</body>
</html>