<?php

if(!$_REQUEST['m'])$_REQUEST['m']=1;
?>

<table cellspacing="0" cellpadding="0" border="0"><tr><td><img src="themes/Sugar/images/EcmProducts.gif" style="margin-top: 3px; margin-right: 3px;" alt="EcmProducts" width="16" border="0" height="16"></td><td><h2>Zamówienie towaru: Lista produktów </h2></td></tr></table><br />
<ul class="tablist" style="width:100%;">
<li>
	<a class="current" href="#">Podstawowe wyszukiwanie</a>
</li>		
</ul>
<table style="border-top: 0px none; margin-bottom: 4px;width:100%" class="tabForm" border="0" cellpadding="0" cellspacing="0">
<tbody>
	<tr>			
		<td class="dataLabel" width="10%" nowrap="nowrap">Średnia sprzedaży w ostatnich 3 miesiącach * </td>
		<td class="dataField" nowrap="nowrap">
			<input name="m" tabindex="" id="m" size="1" style="width:13px;" value="<?php echo $_REQUEST['m'];?>" title="" type="text">
			&gt; Inwentarz
		</td>

	 </tr>
</tbody>
</table>
<input type="button" class="button" name="search" value="Szukaj" onclick="location.href='index.php?module=EcmInsideOrders&action=ListProduction&m='+document.getElementById('m').value;" /><br /><br />

<?php
include_once("modules/EcmSales/productionHelper.php");

$t.='<form method="post" action="index.php?module=EcmInsideOrders&action=EditView&production=1">';
$t.=$tbs;
$t.=$trs;
	$t.=$tds1;
		$t.="&nbsp;";
	$t.=$tde;
	$t.=$tds1;
		$t.="Index";
	$t.=$tde;
	$t.=$tds1;
		$t.="Nazwa";
	$t.=$tde;
	$t.=$tds1;
		$t.="Składniki";
	$t.=$tde;
	$t.=$tds1;
		$t.="Ilość 3m";
	$t.=$tde;
	$t.=$tds1;
		$t.="Inwentarz";
	$t.=$tde;
$t.=$tre;
$z="select * from ecmproducts where deleted='0' order by code asc";
$w=mysql_query($z);
while($r=mysql_fetch_array($w)){
	$i++;
	$inv=getStatesFromMainInventory($r['id']);
	$sales=getSalesLast3m($r['id']);
	$com=hasComponents($r['id']);
	if($_REQUEST['m']*$inv>=$sales || $com==0)continue;
	$t.=$trs;
		$t.=$tds;
			$t.='<input type="checkbox" name="check[]" value="'.$r['id'].'">';
		$t.=$tde;
		$t.=$tds;
			$t.=$r['code'];
		$t.=$tde;
		$t.=$tds;
			$t.='<a href="index.php?module=EcmProducts&action=DetailView&record='.$r['id'].'">'.$r['name'].'</a>';
		$t.=$tde;
		$t.=$tds;
			$t.=(int)$com;
		$t.=$tde;
		$t.=$tds;
			$t.=number_format($sales,0,",",".");
		$t.=$tde;
		$t.=$tds;
			$t.=((int)$inv);
		$t.=$tde;
	$t.=$tre;
	$sum_inv+=$inv;
	$sum_sales+=$sales;
}
$t.=$trs;
	$t.=$tds1;
		$t.="&nbsp;";
	$t.=$tde;
	$t.=$tds1;
		$t.="&nbsp;";
	$t.=$tde;
	$t.=$tds1;
		$t.="&nbsp;";
	$t.=$tde;
	$t.=$tds1;
		$t.="&nbsp;";
	$t.=$tde;
	$t.=$tds1;
			$t.=number_format(($sum_sales)/$i,2,",",".");
	$t.=$tde;
	$t.=$tds1;
		$t.=(int)$sum_inv;
	$t.=$tde;
$t.=$tre;

$t.=$tbe;
$t.='<input type="submit" class="button" name="make_production" value="Utwórz zamówienie" />';
$t.='</form>';
echo $t;
?>