<?php
	include("cls_conexion.php");$CNN=new ClsMySQL();include("conexion23.php");
	$IDP=vbval($_GET['IDP']);
	$PIE=vbval($_GET['PIE']);
?>
<body bgcolor="#D8D8D8">
<table width="100%" border="0">
<?php
	$s="SELECT id_emp as ID,emp_noml as EMP FROM empresas WHERE id_emp>0 ORDER BY emp_noml";
	$rs = grs($s);			
	while ($r = $rs->fetch_assoc()){
?>
  <tr>
    <td colspan="3" style="font-family:Verdana; font-size:18px; color:#00C"><b><?php echo $r['EMP'];?></b></td>
  </tr>
  <tr>
    <td width="5%">&nbsp;</td>
    <td width="24%" style="font-family:Verdana; font-size:16px"><b>TIENDA</b></td>
    <td width="71%" style="font-family:Verdana; font-size:16px"><b>STOCK</b></td>
  </tr>
<?php
		$t="SELECT id_almacen as IDA,alm_obs as ALM 
			FROM almacenes WHERE id_almacen>0 AND alm_id_empresa=$r[ID] 
			ORDER BY alm_obs ";
		$rst = grs($t);			
		while ($rt = $rst->fetch_assoc()){
			$STO=gn("SUM(sp_cantidad)","stocks_presentaciones",
				   "sp_id_producto=$IDP AND sp_presentacion=$PIE AND sp_id_almacen=$rt[IDA]");
?>  
  <tr>
    <td>&nbsp;</td>
    <td style="font-family:Verdana; font-size:16px"><?php echo $rt['ALM'];?></td>
    <td width="71%" style="font-family:Verdana; font-size:16px"><?php echo $STO;?></td>
  </tr>
  
<?php
		}
	}
?>  
</table>
<?php
function FEC_ABB($A,$B){
	$s="SELECT DATEDIFF('".$B."','".$A."');";
	$rs = grs($s);
	$r = $rs->fetch_row();	
	return $r[0];
}
?>
<p><span style="font-size:1rem; font-family:Verdana, Geneva, sans-serif; color:#00C"><b>EN TRANSITO</b></span></p>
<table width="100%" border="0">
  <tr>
    <td width="0%">&nbsp;</td>
    <td width="6%" style="font-family:Verdana; font-size:16px"><b>CAJAS</b></td>
    <td width="0%">&nbsp;</td>
    <td width="11%" style="font-family:Verdana; font-size:16px"><b>PIEZAS</b></td>
    <td width="0%">&nbsp;</td>
    <td width="11%" style="font-family:Verdana; font-size:16px"><b>F.LLEGADA</b></td>
    <td width="2%">&nbsp;</td>
    <td width="70%" style="font-family:Verdana; font-size:16px"><b>CONTENEDOR</b></td>
    <td width="2%">&nbsp;</td>
  </tr>
<?php
	$HOY=date("Y-m-d");
	$s="SELECT SER,NUM,FEC, PIE, SUM( CAN ) as KAN FROM vis_compras_et
			WHERE IDP=$IDP 
			GROUP BY SER,NUM,FEC,  PIE
			ORDER BY FEC ASC ";
	$rs = grs($s);			
	while ($r = $rs->fetch_assoc()){	
		$SER=trim($r['SER']);
		$NUM=trim($r['NUM']);
		if(strcmp($r['FEC'],"1900-01-01")!=0){
			$D=explode("-",$r['FEC']);
			$FecLle=$D[2]."-".vbmid(gs("mes","meses","id_mes=".$D[1]),1,3)."-".($D[0]-2000);
		}else{
			$FecLle="xx-xx-xx";
			$XX="X";
		}
		if(strlen($SER)>0){
			$SER=$SER."-".$NUM;
		}else{
			$SER=$NUM;
		}
?>  
    <tr>
    <td>&nbsp;</td>    
    <td width="6%" align="center" style="font-family:Verdana; font-size:16px"><?php echo $r['KAN'];?></td>
    <td width="0%">&nbsp;</td>
    <td width="11%" align="center" style="font-family:Verdana; font-size:16px"><?php echo $r['PIE'];?></td>
    <td width="0%">&nbsp;</td>
    <td style="font-family:Verdana; font-size:16px"><?php echo $FecLle;?></td>
    <td width="2%">&nbsp;</td>
    <td align="left" style="font-family:Verdana; font-size:16px"><?php echo $SER;?></td>
    <td width="2%">&nbsp;</td>
    </tr>  
<?php
		
	}
?>  
</table>

</body>