<?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="100%" border="0" align="center">
      <tr>
        <th colspan="11"> 
		INVENTARIO DE ARTICULOS VS INVNETARIO FISICO
      	</th>
      </tr>
      <tr>
  	    <th><div align="center">ALMACEN</div></th>
        <th><div align="center">ARTICULO</div></th>
        <th><div align="center">ULT. COSTO</div></th>		
        <th><div align="center">P.P.</div></th>		
        <th><div align="center">EXISTENCIA</div></th>
        <th><div align="center">TOTAL</div></th>
        <th><div align="center">EXISTENCIA</div></th>
        <th><div align="center">TOTAL</div></th>
        <th><div align="center">DIFERENCIA</div></th>
        <th><div align="center">TOTAL DIF.</div></th>			
	  </tr>
  	 <?php

	 if ($_POST['botbus']){
	//se da formato a fechas
	$fecha_inicial = chfecha($_POST['fec_ini'],'d/m/Y','Y-m-d');
	$fecha_final = chfecha($_POST['fec_fin'],'d/m/Y','Y-m-d');
	$dataBus=NULL;
	if(trim($_POST['id_prod'])!="")
		$dataBus[]="nparte1='".$_POST['id_prod']."'";
	if(trim($_POST['almacen'])!="")
		$dataBus[]="t8='".$_POST['almacen']."'";
	if(trim($_POST['almacen'])=="")
		$dataBus[]="t8 >'0'";


//	$dataBus[]="fec_mov between '$fecha_inicial' AND '$fecha_final'";
	
	$WHERE=implode(" AND ",$dataBus);
	$sq="select * from farticulos WHERE $WHERE order by t8,np_desc1";
	$sql = mysqli_query($con ,$sq);
	$idProdAct='-1';
	while(@$reg = mysqli_fetch_array($sql)){
		$fec1 = $reg["fec_mov"];
		include('DF20000.php');
		echo "<tr>";
		echo "<td><div align=\"LEFT\">".$reg["t8"]."
		<input name='almacen[]' id='almacen_".$reg['nparte1']."' type='hidden' value='".$reg['t8']."'></div></td>";//  -------> ALMACEN.				
		echo "<td><div align=\"LEFT\">".$reg["nparte1"].'|'.$reg['np_desc1']."
		<input name='articulo[]' id='articulo_".$reg['nparte1']."' type='hidden' value='".$reg['nparte1']."'></div></td>";			
		echo "<td><div align=\"RIGHT\">" . '$ ' . number_format($reg["t3"], 2, '.', ',') ."
		<input name='ultimo[]' id='ultimo_".$reg['nparte1']."' type='hidden' value='".$reg['t3']."'></div></td>";			
		echo "<td><div align=\"RIGHT\">". '$ ' . number_format($reg["cos_prom"], 2, '.', ',') ." 
		<input name='precio[]' id='precio_".$reg['nparte1']."' type='hidden' value='".$reg['cos_prom']."'></div></td>";		
		echo "<td><div align=\"CENTER\">".$reg["t5"]."
		<input name='existencia[]' id='existencia_".$reg['nparte1']."' type='hidden' value='".$reg['t5']."'></div></td>";		
		echo "<td><div align=\"RIGHT\">". '$ ' . number_format(($reg["cos_prom"]*$reg["t5"]), 2, '.', ',') ."
		<input name='total1[]' id='total1_".$reg['nparte1']."' type='hidden' value='".($reg["cos_prom"]*$reg["t5"])."'></div></td>";		 ?>
		<td><div align=\"CENTER\"> <input name="exis[]" type="text" id="<?php
 echo 'exis_'.$reg['nparte1'].''; ?>" size="10" value="" onChange="document.frm1.total_<?php
 echo $reg['nparte1']; ?>.value=(this.value*document.frm1.precio_<?php
 echo $reg['nparte1']; ?>.value);
		  document.frm1.dif_<?php
 echo $reg['nparte1']; ?>.value=(document.frm1.exis_<?php
 echo $reg['nparte1']; ?>.value-document.frm1.existencia_<?php
 echo $reg['nparte1']; ?>.value);
		  document.frm1.totdif_<?php
 echo $reg['nparte1']; ?>.value=(document.frm1.total_<?php
 echo $reg['nparte1']; ?>.value-document.frm1.total1_<?php
 echo $reg['nparte1']; ?>.value); "></div></td>		
		<td><div align=\"CENTER\"> <input name="total[]" type="text" id="<?php
 echo 'total_'.$reg['nparte1'].''; ?>" size="10" value="0"></div></td>		
		<td><div align=\"CENTER\"> <input name="dif[]" type="text" id="<?php
 echo 'dif_'.$reg['nparte1'].''; ?>" size="10" value="0"></div></td>		
		<td><div align=\"CENTER\"> <input name="totdif[]" type="text" id="<?php
 echo 'totdif_'.$reg['nparte1'].''; ?>" size="10" value="0"></div></td>						
				
<?php
								
		echo "</tr>";
	
	}
	}
	mysqli_close($con);
	?>	  
    </table>
