<?php

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

$where2="1=1";

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

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


if ($tipostock <> ""){

if ($tipostock == "normal"){ $where2.=" AND EXIACT <= stockmax AND EXIACT >= stockmin ";}
else if ($tipostock == "bajo"){ $where2.=" AND EXIACT < stockmin";}
else if($tipostock == "sobre"){ $where2.=" AND EXIACT > stockmax";}// por encima del maximo
}

 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 ($tipostock=="") {
	   
	   	$dscstock="TODOS LOS TIPOS";
	 
	     } else {
		 
if ($tipostock == "normal"){ $dscstock="STOCK NORMAL";}
else if ($tipostock == "bajo"){ $dscstock="BAJO STOCK";}
else if($tipostock == "sobre"){ $dscstock="SOBRE STOCK";}// por encima del maximo

	
     }
	  
	 
?>
<!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="5"  bgcolor="skyblue"><div align="center"><strong>REPORTE LISTA DE INVENTARIO</strong></div></td>
  </tr>
   <tr>
       <td></td>
       <td colspan="5"   border="1"><div align="center"><font size="3" >PROVEEDOR -  <?php echo $dscpro; ?></font></div></td>
     </tr>
	 <tr>
       <td></td>
       <td colspan="5"   border="1"><div align="center"><font size="3" >TIPO STOCK -  <?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="16%"><div align="center"><strong>EXISTENCIA</strong></div></td>
    <td width="25%"><div align="center"><strong>DIFERENCIA</strong></div></td>
  </tr>
  
<?php


					   					
				$consulta = "SELECT CDGART, CDGBAR,DSCART,EXIACT,stockmax,stockmin FROM web_1001  WHERE  estart=1 AND tipart=1 AND ".$where2. "  ORDER BY   dscart 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"];

							/*
							
							if (($exiact < $stockmax) && ($exiact > $stockmin)  ){
							
							$diferencia   = $fila["EXIACT"];
							
							}
							
						else if  ($exiact > $stockmax){  // por encima del maximo
							
							$diferencia =$exiact -$stockmax; 
							
							}
							
							
								else if ($exiact < $stockmin){  // por debajo del minimo
							
							$diferencia =$exiact -$stockmin;
							
							}
							
		*/

?>  

 <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>
	
	
							<?php	if (($exiact < $stockmax) && ($exiact > $stockmin)  ){
							
							$diferencia   = $fila["EXIACT"]; ?>
							<td ><div align="right"><?php echo number_format($diferencia ,2)  ?></div></td>
							<?php } 
							
							
								else if  ($exiact > $stockmax){  // por encima del maximo
							
							$diferencia =$exiact -$stockmax; ?>
							
									
									  
									  
							<td  ><div align="right"><?php echo number_format($diferencia ,2)  ?></div></td>
							<?php } 
									
								else if ($exiact < $stockmin){  // por debajo del minimo
							
							$diferencia =$exiact -$stockmin; ?>
							<td  ><div align="right"><?php echo number_format($diferencia ,2)  ?></div></td>
							<?php } else { ?>
																	
								<td  ><div align="right"><?php echo number_format($exiact ,2)  ?></div></td>
								<?php }  ?>
									
								

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