<?php ob_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');
include('includes/function_lib.php');
//$Sql = "SELECT StockID,it.item_name,it.unit,a.manufacture,a.color,a.grade,a.gsm FROM item_master it JOIN item_specification a ON it.StockID = a.proc_id  GROUP BY it.StockID";
$Sql = "SELECT it.id As Stockid,StockID,it.item_name,it.unit,a.manufacture,a.color,a.grade,a.gsm FROM item_master it JOIN item_specification a ON it.StockID = a.proc_id  GROUP BY it.StockID";
$Result = DB_query($Sql,$db,$ErrMsg);
?>

<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>



<h2 align="center">ADD ITEMS</h2><br /><br />


<div align="center">
<div style="overflow:auto; width:600px; height:300px">
<form  action="" method="post">
<table width="100%" border="0" cellspacing="3" cellpadding="2" align="center">
  <tr>
        <th><strong>Item Code</strong></th>
        <th><strong>Item Name </strong></th>
		<th><strong>Make </strong></th>
		<th><strong>Color</strong></th>
		<th><strong>Grade</strong></th>
		<th><strong>Stock Balance</strong></th>
		<th><strong>Unit Name</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['StockID']."'";
		$item_res=DB_query($itemname,$db);
		$item_row=DB_fetch_array($item_res);
		
		$make_sql=DB_query("Select manufacturer from product_manufacture where id='".$myrow['manufacture']."'",$db);
		$make_row=DB_fetch_array($make_sql);
		
		$color_sql=DB_query("Select color from product_color where id='".$myrow['color']."'",$db);
		$color_row=DB_fetch_array($color_sql);
		
		$grade_sql=DB_query("Select grade from product_grade where id='".$myrow['grade']."'",$db);
		$grade_row=DB_fetch_array($grade_sql);
		
		$u_sql=DB_query("Select unitname from unitsofmeasure where unitid='".$myrow['unit']."'",$db);
		$u_row=DB_fetch_array($u_sql);
		
		
		$stock=DB_query("Select stockbalance from stock_maintenance where itemcode='".$myrow['StockID']."'",$db);
		$stock_row=DB_fetch_array($stock);
	  ?>
	  <tr bgcolor="#FFFFFF">
      <td><a href="javascript:loadValue('<?php echo $myrow['Stockid'];?>,<?php echo $myrow['StockID'];?>')"><?php echo $myrow['StockID'];?></a></td>
        <td><?php echo $item_row['item_name'];?></td>
		<td><?php echo $make_row['manufacturer'];?></td>
		<td><?php echo $color_row['color'];?></td>
		<td><?php echo $grade_row['grade'];?></td>
		<td><?php echo $stock_row['stockbalance'];?></td>
		<td><?php echo $u_row['unitname']; ?></td>
      </tr>
	  <?php } ?>
<input type="hidden" name="row_count" id="row_count" value="<?php echo $i;?>">
</table></form>
</div></div>

<script>
function loadValue(str,ct)
{

	var spl = str.split(",");
	
	var code = spl[0];
	var name = spl[1];
	
	
	
	
	window.opener.document.getElementById('product_id').value = name;
	window.opener.document.getElementById('itemcode').value = code;
		window.close();
}
</script>
