<?
global $mod_strings;
$_SESSION['stock_order_by']=$_REQUEST['order_by'];
$_SESSION['stock_sorder']=$_REQUEST['sorder'];
$_SESSION['stock_sorder']=$_REQUEST['sorder'];
$_SESSION['stock_id']=$_REQUEST['pricebook_id'];

$r=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select name from ecmcashs where id='".$_REQUEST['stock_id']."'"));
$name=$r['name'];

function sortLink($order_by,$sorder,$title)
{
	if($order_by==$_REQUEST['order_by'])
	{
		if($sorder=="desc")
		{
			$img='<img border="0" src="themes/Sugar/images/arrow_down.gif" width="8" height="10" align="absmiddle" alt="">';
			$s="asc";
		}
		else
		{
			$img='<img border="0" src="themes/Sugar/images/arrow_up.gif" width="8" height="10" align="absmiddle" alt="">';
			$s="desc";
		}
	}
	else
	{
		$img='<img border="0" src="themes/Sugar/images/arrow.gif" width="8" height="10" align="absmiddle" alt="">';
		$s=$sorder;
	}
	
	return '<a style="cursor:pointer;" onclick="mintajaxget(\'index.php?to_pdf=1&module=EcmCashs&action=ListViewProductsAjax&stock_id='.$_REQUEST['stock_id'].'&order_by='.$order_by.'&sorder='.$s.'\',\'products\');">'.$title.'&nbsp;'.$img.'</a>';
}


$c=array("ecmcashin.price_in","ecmcashin.date_in","ecmcashin.quantity_in","ecmcashin.quantity_out","ecmcashin.pz_id");
$t=array($mod_strings['LBL_PRICE'],$mod_strings['LBL_DATE'],$mod_strings['LBL_QTY_IN'],$mod_strings['LBL_QTY_OUT'],$mod_strings['LBL_PZ']);

$sorder=$_REQUEST['sorder'];
print '<h4>Products List:</h4><br>';
print '<table cellpadding="0" cellspacing="0" width="100%" border="0" class="ListView"><tr>';
print '<td class="listViewThS1">'.sortLink("ecmproducts.name",$sorder,$mod_strings['LBL_PRODUCT_NAME']).'</td>';
for($i=0;$i<count($t);$i++)
{
	$corder_by=$c[$i];
	if($t[$i])print '<td class="listViewThS1">'.sortLink($corder_by,$sorder,$t[$i]).'</td>';
}
print '<td class="listViewThS1">&nbsp;</td>';
print '<td class="listViewThS1">&nbsp;</td>';
print '</tr>';
$z="select ecmcashins.*,ecmproducts.name as product_name,ecmcashdocins.name as pz_name from ecmcashins inner join ecmproducts on ecmproducts.id=ecmcashins.product_id inner join ecmcashdocins on ecmcashdocins.id=ecmcashins.pz_id where ecmcashins.stock_id='".$_REQUEST['stock_id']."' order by ".$_REQUEST['order_by']." ".$_REQUEST['sorder'];

$result = $GLOBALS['db']->query($z);

while($row=$GLOBALS['db']->fetchByAssoc($result))
{
	print '<tr>';
	print '<td class="oddListRowS1"><a href="index.php?module=EcmProducts&action=DetailView&record='.$row['product_id'].'">'.$row['product_name'].'</a></td>';
	for($i=0;$i<count($t);$i++)
	{
		if($t[$i])
		{
			if($c[$i]=="ecmcashin.pz_id")print '<td class="oddListRowS1"><a href="index.php?module=EcmCashDocIns&action=DetailView&record='.$row['pz_id'].'">'.$row['pz_name'].'</a></td>';
			elseif($c[$i]=="ecmcashin.date_in")print '<td class="oddListRowS1">'.$timedate->to_display($row['date_in'],"Y-m-d",$timedate->get_date_format()).'</td>';
			elseif($c[$i]=="ecmcashin.price_in")print '<td class="oddListRowS1">'.number_format($row['price_in'],2,$GLOBALS['sugar_config']['default_decimal_seperator'],$GLOBALS['sugar_config']['default_number_grouping_seperator']).'</td>';
			else print '<td class="oddListRowS1">'.$row[str_replace("ecmcashin.","",$c[$i])].'</td>';
		}
	}
	print '</tr>';
}
print '</table>';

?>
