<?php
 
session_cache_limiter('private');
session_start();
include("DMMYSQLG.php");
$name="Inventario.xls"; 
if(isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'],'MSIE'))
	header('Content-Type: application/force-download');
else
	header('Content-Type: application/octet-stream');
header('Content-disposition: attachment; filename="'.$name.'"');

?>

  <table width="748" border='1'>
         <tr>
       
        <th width="57"  nowrap><div align="center">Clave</div></th>
		<th width="91"  nowrap><div align="center">gdescrip</div></th>
		<th width="59"  nowrap><div align="center">Exi Min</div></th>
		<th width="53"  nowrap><div align="center">Exi Max</div></th>
		<th width="62"  nowrap><div align="center">Linea</div></th>
		<th width="62"  nowrap><div align="center">Grupo</div></th>
		<th width="62"  nowrap><div align="center">plan</div></th>
		<th width="56"  nowrap><div align="center">Exi Disp</div></th>
		<th width="45"  nowrap><div align="center">Precio</div></th>
		<th width="50"  nowrap><div align="center">IVA</div></th>
		<th width="100"  nowrap><div align="center">Afecta inventario </div></th>
		<th width="50"  nowrap><div align="center">Costo Compra </div></th>
      </tr>
      <?php


if($_POST['t1']=="clave") $sql ="SELECT * FROM ama_llaves WHERE ama_llaves.modulo='".$_SESSION['mod_sis']."' AND   n_reg = '".$_POST['b1']."' order by n_reg ";
elseif($_POST['t1']=="nombre") $sql="SELECT * FROM ama_llaves WHERE ama_llaves.modulo='".$_SESSION['mod_sis']."' AND   gdescrip like '%".$_POST['b1']."%' order by n_reg";
else $sql = "SELECT * FROM ama_llaves order by n_reg ";
	echo mysqli_error($con);
	$sq=mysqli_query($con ,$sql);
	while($reg = mysqli_fetch_array($sq)){
	  	echo "<tr height=\"60\">";
		echo "<td> <div align='center'>" . $reg["n_reg"] . "</div></td>";
		echo "<td> <div align='left'>" . $reg["gdescrip"] . "</div></td>";
		echo "<td> <div align='left'>" . $reg["exi_min"] . "</div></td>";
		echo "<td> <div align='left'>" . $reg["exi_max"] . "</div></td>";
		@$sq_linea = mysqli_query($con ,"SELECT * FROM dglineas WHERE linea = '".$reg['linea']."'");
		$row = mysqli_fetch_array($sq_linea);
		echo "<td> <div align='left'>" .$row["des_linea"] . "</div></td>";
		@$sq_basico = mysqli_query($con ,"SELECT * FROM dgbasico WHERE gpo_basico = '".$reg['gpo_basico']."'");
		$rew = mysqli_fetch_array($sq_basico);
		echo "<td> <div align='left'>" . $rew["des_basico"] . "</div></td>";
	   @$sq_plan = mysqli_query($con ,"SELECT * FROM dxplans WHERE cve_plan = '".$reg['cve_plan']."'");
		$riw = mysqli_fetch_array($sq_plan);
		echo "<td> <div align='left'>" . $riw["des_plan"] . "</div></td>";		
		echo "<td> <div align='right'>" . $reg["exi_dis"] . "</div></td>";
		echo "<td> <div align='right'> " .  number_format($reg['lim_vta1'], 2, '.', ',') . "</div></td>";
		echo "<td> <div align='left'>" . $reg["cve_iva"] . "</div></td>";
		echo "<td> <div align='left'>" . $tp . "</div></td>";
		if($reg["es_inv"]==1 || $reg["es_inv"]=='N'){
			$tp = "SI";
		}elseif($reg["es_inv"]==2 || $reg["es_inv"]=='S'){
			$tp = "SI";		
		}
		echo "<td> <div align='left'>" . $reg["cos_prom"] . "</div></td>";
		
		echo "</tr>";
	}
	mysqli_close($con);   
	?>
    </table>
