<?php
session_name('CAKEPHP'); session_start();
$PageSecurity = 4;
$PageName = 'Add Items';
include('includes/DefinePOClass.php');
include('includes/session.inc');
include('includes/SQL_CommonFunctions.inc');
include('includes/DefineSuppTransClass.php');
include('includes/header.inc');
$Sql = "select itemcode,description,Make,Color,Gread,UOM,sum(reciveqty),avg(itemprice) from addmrnqty 
group by itemcode, Make,   Color ,  Gread";
$Result = DB_query($Sql,$db,$ErrMsg);
?>
<h2 align="center"><b><?php echo $title; ?></b></h2></td>
<link rel="stylesheet" href="css/jquery.ui.all.css">
<script src="js/jquery-1.5.1.js"> </script>
<script src="ui/jquery.ui.core.js"> </script>
<script src="ui/jquery.ui.widget.js"></script>


<br />
<br />
<br />
<form action="" method="post">
<table width="100%" border="0" align="center" cellpadding="1" cellspacing="3">
      <tr>
        <th><strong>Item Code</strong></th>
        <th><strong>Item Name </strong></th>
		
		<th><strong>UOM</strong></th>
		<th><strong>Stock Balance</strong></th>
      </tr>
	  <?php   
	  $counter = $_REQUEST['rowcount'];
	  $ct = explode("_",$counter);
	  while($myrow =DB_fetch_array($Result))
	  {  
	 // $_SESSION['product_id'] =$myrow['stockid'];
		$itemname="Select item_name from item_master where StockID='".$myrow['itemcode']."'";
		$item_res=DB_query($itemname,$db);
		$item_row=DB_fetch_array($item_res);
		
		$u_sql=DB_query("Select unitname from unitsofmeasure where unitid='".$myrow['UOM']."'",$db);
		$u_row=DB_fetch_array($u_sql);
		
	  ?>
	  <tr bgcolor="#FFFFFF">
      <td><a href="javascript:loadValue('<?php echo $myrow['itemcode'];?>,<?php echo $item_row['item_name'];?>,<?php echo $myrow['Make'];?>,<?php echo $make_row['manufacturer'];?>,<?php echo $myrow['Color'];?>,<?php echo $color_row['color'];?>,<?php echo $myrow['Gread'];?>,<?php echo $grade_row['grade'];?>,<?php echo $myrow['UOM'];?>,<?php echo $u_row['unitname']?>,<?php echo $myrow['sum(reciveqty)'];?>,<?php echo $myrow['avg(itemprice)'];?>','<?php echo $ct[2];?>')"><?php echo $myrow['itemcode'];?></a></td>
        <td><?php echo $item_row['item_name'];?></td>
		
		<td><?php echo $u_row['unitname'];?></td>
		<td><div align="center"><?php echo $myrow['sum(reciveqty)'];?></div></td>
      </tr>
	  <?php } ?>
</table>
</form>
<script>
function loadValue(str,ct)
{
	var spl = str.split(",");
	var code = spl[0];
	var name = spl[1];
	var makeid = spl[2];
	var makename = spl[3];
	var colorid = spl[4];
	var colorname = spl[5];
	var gradeid = spl[6];
	var gradename = spl[7];
	var uomid = spl[8];
	var uomname = spl[9];
	var received = spl[10];
	var average = spl[11];
	
	if(ct)
	{
		window.opener.document.getElementById('washing_profile_'+ct).value = code;
		window.opener.document.getElementById('desc_'+ct).value = name;
		
		window.opener.document.getElementById('uom_'+ct).value = uomname;
		window.opener.document.getElementById('Stockbalance_'+ct).value = received;
	}
	else
	{
		window.opener.document.getElementById('washing_profile').value = code;
		window.opener.document.getElementById('desc').value = name;
		
		window.opener.document.getElementById('uom').value = uomname;
		window.opener.document.getElementById('Stockbalance').value = received;
	}
	window.close();
}
</script>
	