<?php
 
session_cache_limiter('private');
session_start();
include("DMMYSQLG.php");
include("DF80000.php");
$name="Requisicion_De_Compra.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.'"');

?>
<?php

$fecha = isset($dt_empres['fec_alta'])?$dt_empres['fec_alta']:date('Y-m-d');
 	  $fecAlt = chfecha($fecha,'Y-m-d','d/m/Y');
	   list($ano,$mes,$dia) = explode ("-",$fecha); 
	   
	    $mes1=$mes-1;
	     $mes2=$mes-2;
	      $mes3=$mes-3;
	   
//	       $mesA = mesLetra($mes1);
//		    $mesB = mesLetra($mes2);
//			 $mesC = mesLetra($mes3);
?>
  <table width="748" border='1'>
         <tr>
        <th width="100"  nowrap><div align="center">Cant. Solicitada</div></th>
		<th width="100"  nowrap><div align="center">UNIDAD</div></th>
		<th width="350"  nowrap><div align="center">ARTICULO</div></th>
		<th width="100"  nowrap><div align="center">EXISTENCIA</div></th>
		<th width="100"  nowrap><div align="center"><?php
  $mesC = mesLetra($mes3);?></div></th>
		<th width="100"  nowrap><div align="center"><?php
 $mesB = mesLetra($mes2);?></div></th>
		<th width="100"  nowrap><div align="center"><?php
  $mesA = mesLetra($mes1);?></div></th>
		<th width="150"  nowrap colspan="3"><div align="center">VERICO</div></th>
      </tr>
      <?php

	  
	 
	   
	  
	  
	  $mysql=mysqli_fetch_array(mysqli_query($con ,"select * from fagrupadores where n_reg='".$_POST['agrupador']."'"));
	  
	  if($_POST['agrupador']!='T') {
		 $arrBus[]="WHERE t8='".$mysql['np_desc1']."'";		
	}
	if($_POST['sub']!='T') 
	{
	 	$arrBus[]="t7='".$_POST['sub']."'";
	    
	}else{
	    $sub=mysqli_query($con ,"SELECT distinct(np_desc1) FROM fsubagrupadores where almacen='$selPais' and t1='ACTIVO'");
	}	
	
 	//$WHERE=implode(" AND ",$arrBus);
	
	if ($_POST['sub']!='T'){
	echo "<tr>
          <td colspan='2'><div align='left'><strong>".$mysql['np_desc1']."-".$_POST['sub']."</strong></div></td>
          </tr>";
	}else{
	while($sql=mysqli_fetch_array($sub)){
	
	//echo "<tr>
      //    <td colspan='2' style='#9B0F1A'><div align='left'><strong>".$mysql['np_desc1']."-".$sql['np_desc1']."</strong></div></td>
       //   </tr>";
	}
	}
         if($_POST['agrupador']=='T'){
            $result = mysqli_query($con ,"select * from farticulos where t1='ACTIVO' order by nparte1");
        }else{
	$WHERE=implode(" AND ",$arrBus);
	$result = mysqli_query($con ,"select * from farticulos $WHERE order by np_desc1");

        }
	
	//$result = mysqli_query($con ,"select * from farticulos $WHERE order by np_desc1");
	$c=0;
	while($reg = mysqli_fetch_array($result))
	{
	$unidad=mysqli_fetch_array(mysqli_query($con ,"select np_desc1,codigo from dgmedida where nparte1='".$reg['pais']."'"));
	echo "<tr>";
	echo "<td> <div align='center'></div></td>";
	
	echo "<td> <div align='left'><strong>" . $unidad["np_desc1"] . "&nbsp;</strong></div></td>";
	
	
	
	echo "<td> <div align='left'><strong>" . utf8_decode($reg["np_desc1"]) . "&nbsp;</strong></div></td>";
	
	echo "<td> <div align='center'><strong>" . number_format($reg["t5"],0,'.',',') . "</strong></div></td>";
	
	
	
	$almacen=mysqli_fetch_array(mysqli_query($con ,"select np_desc1 from falmacen where nparte1='".$reg['sub']."'"));
	
$pedIdo1=mysqli_fetch_array(mysqli_query($con ,"SELECT SUM(tot_ent) as entradas from alconprom where id_art='".$reg['nparte1']."' and mes='$mes3'"));
	echo "<td> <div align='center'><strong>" . $pedIdo1['entradas'] . "</strong></div></td>";
	
$pedIdo2=mysqli_fetch_array(mysqli_query($con ,"SELECT SUM(tot_ent) as entradas from alconprom where id_art='".$reg['nparte1']."' and mes='$mes2'"));
	echo "<td> <div align='center'><strong>" . $pedIdo2['entradas'] . "</strong></div></td>";
	
$pedIdo3=mysqli_fetch_array(mysqli_query($con ,"SELECT SUM(tot_ent) as entradas from alconprom where id_art='".$reg['nparte1']."' and mes='$mes1'"));
	echo "<td> <div align='center'><strong>" . $pedIdo3['entradas'] . "</strong></div></td>";
	
	echo "<td> <div align='center'></div></td>";
	echo "<td> <div align='center'></div></td>";
	echo "<td> <div align='center'></div></td>";
			
		$c++;
		
	    }
	     
		echo "<tr>";
		echo "<td colspan='3'> <div align='right'><strong>".$c." Articulos Encontrados</strong></div></td>";
		
		echo "<td colspan='7' > <div align='center'><strong></strong></div></td></tr>";
		
	mysqli_close($con);
	  
	?>
    </table>
