<?php

header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=Reporte_Productos_por_vencer.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"];
	
	   
	   
$cdgpro=$_GET["cdgpro"];
$tipoven=$_GET["tipoven"];
$cdgbar=$_GET["cdgbar"];


$where2="1=1";

if ($cdgpro <> "") { $where2.=" AND cdgpro='$cdgpro'"; }

if ($cdgbar <> "") { $where2.=" AND CDGBAR='$cdgbar'"; }


if ($tipoven <> ""){

if ($tipoven == "5MESES"){ $where2.=" AND feclot between CURRENT_DATE() AND DATE(DATE_ADD(now(), INTERVAL 5 MONTH))"; }
if ($tipoven == "4MESES"){ $where2.=" AND feclot between CURRENT_DATE() AND DATE(DATE_ADD(now(), INTERVAL 4 MONTH))"; }
if ($tipoven == "3MESES"){ $where2.=" AND feclot between CURRENT_DATE() AND DATE(DATE_ADD(now(), INTERVAL 3 MONTH))"; }
if ($tipoven == "2MESES"){ $where2.=" AND feclot between CURRENT_DATE() AND DATE(DATE_ADD(now(), INTERVAL 2 MONTH))"; }

if ($tipoven == "VENCIDOS"){ $where2.=" AND feclot <= CURRENT_DATE() ";}

}

 if ($cdgpro=="") {
	   
	   	$dscpro="TODOS LOS PROVEEDORES";
	 
	     } else {

	 
	   $query_codcaj="SELECT * FROM proveedores WHERE cdgpro=$cdgpro ";
       $resultado = $mysqli->query( $query_codcaj);
       $row = $resultado->fetch_array();
        
		 $dscpro    = $row["dscpro"];
	
     }
	 
	if ($tipoven=="") {
	   
	   	$tipoven="TODOS LOS TIPOS";
	 
	     } else {
		 
if ($tipoven == "5MESES"){ $dscstock="5 MESES";}
else if ($tipoven == "4MESES"){ $dscstock="4 MESES";}
else if($tipoven == "3MESES"){ $dscstock="3 MESES";}//
else if($tipoven == "2MESES"){ $dscstock="2 MESES";}//

else if($tipoven == "VENCIDOS"){ $dscstock="VENCIDOS";}//




	
     }
	  
	 
?>
<!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>

<link href="../estilos/estilos.css" type="text/css" rel="stylesheet">

		
</head>
<body>
<table width="50%" border="0" cellspacing="0" cellpadding="0">
    <tr> 
   </tr>
  <tr>
     <td></td>
 <td colspan="7"  bgcolor="skyblue"><div align="center"><strong>REPORTE PRODUCTOS POR VENCER</strong></div></td>
  </tr>
   <tr>
       <td></td>
       <td colspan="7"   border="1"><div align="center"><font size="3" >PROVEEDOR -  <?php echo $dscpro; ?></font></div></td>
     </tr>
	 <tr>
       <td></td>
       <td colspan="7"   border="1"><div align="center"><font size="3" >A MESES POR VENCER-  <?php echo $dscstock; ?></font></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="37%"><div align="center"><strong># LOTE</strong></div></td>
	<td width="37%"><div align="center"><strong>FECHA LOTE</strong></div></td>
    <td width="16%"><div align="center"><strong>EXISTENCIA</strong></div></td>
    <td width="25%"><div align="center"><strong>DIAS POR VENCER</strong></div></td>
  </tr>
  
<?php


					   					
				$consulta = "SELECT CDGART, CDGBAR,DSCART,EXIACT,stockmax,stockmin,numlot,feclot, TIMESTAMPDIFF(DAY, CURRENT_DATE(), feclot) AS dias_difencia FROM web_1001 WHERE  estart=1 AND tipart=1  AND ".$where2. "  ORDER BY   feclot ASC  " ;

				if ($resultado = $mysqli->query($consulta)) 
				
				$diferencia   = 0;

  			   while ($fila = $resultado->fetch_assoc()) {		
					       
					        $codigo   = $fila["CDGART"];
							$cdgbar  = $fila["CDGBAR"];
							$cdgbar2 = "Cod. ".$cdgbar;
							$dscart   = $fila["DSCART"];
							$exiact   = $fila["EXIACT"];
							$stockmax   = $fila["stockmax"];
							$stockmin   = $fila["stockmin"];
							
							
							$numlot   = $fila["numlot"];
							$feclot   = $fila["feclot"];
							$dias_difencia   = $fila["dias_difencia"];
							$feclot= implode("-", array_reverse(explode("-", $feclot)));

							

?>  

 <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 $numlot; ?></div></td>
		<td><div align="center"><?php echo $feclot; ?></div></td>
			<td><div align="center"><?php echo $exiact; ?></div></td>
				<td><div align="center"><?php echo $dias_difencia; ?></div></td>
	
									
								

                
 </tr> 
  <?php
}
  ?>
</table>
</body>
</html>