<?php
session_name('CAKEPHP'); session_start();
$PageSecurity = 4;
$PageName = 'Add Items';
include('includes/session.inc');
include('includes/SQL_CommonFunctions.inc');
include('includes/DefineSuppTransClass.php');
?>
<h2 align="center"><b><?php echo $title; ?></b></h2>
<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>


<form action="" method="post"><div align="center">
<table width="60%" border="0" align="center" cellpadding="1" cellspacing="3" >
<tr><td>Item Name</td><td><input type="text" name="item_name1" />&nbsp;<input type="submit" value="Search" name="Search" /></td>	
</tr>
     
      <tr>
      	<td><div align="center"><div style="margin:0px; padding:0px; overflow:scroll; width:700px; height:300px">
<table width="100%" border="0" align="center" cellpadding="1" cellspacing="3" id="tab">
      <tr>
        <th><strong>Item Code</strong></th>
        <th><strong>Item Name </strong></th>
		<th><strong>Description </strong></th>
		<th><strong>UOM</strong></th>
		
      </tr>
      <?php   
	  $counter = $_REQUEST['rowcount'];
	  $ct = explode("_",$counter);	 
	  if(isset($_POST['Search']))
	  {
	  $itemname="select * from item_master where item_name like '%".$_REQUEST['item_name1']."%' and CompanyId='".$_SESSION['ACGCompanyId']."'";	
	  }
	  else {
		  $itemname="Select * from item_master where CompanyId='".$_SESSION['ACGCompanyId']."'";
	  }
	
		$item_res=DB_query($itemname,$db);
		 while($myrow =DB_fetch_array($item_res))
	     {  
		$u_sql=DB_query("Select unitname from unitsofmeasure where unitid='".$myrow['mst_unitid']."'",$db);
		$u_row=DB_fetch_array($u_sql);
		$group=DB_query("select categorydescription from stockcategory where CategoryID='".$myrow['SubCategoryID']."'",$db);
		$groupdata=DB_fetch_array($group);
		$m_sql=DB_query("Select manufacturer from product_manufacture where id='".$myrow['make']."'",$db);
		$m_row=DB_fetch_array($m_sql);
		$g_sql=DB_query("Select grade from product_grade where id='".$myrow['grade']."'",$db);
		$g_row=DB_fetch_array($g_sql);
		$gs_sql=DB_query("Select gsm from gsm where id='".$myrow['gsm']."'",$db);
		$gs_row=DB_fetch_array($gs_sql);
		
	  ?>
	  <tr bgcolor="#FFFFFF">
      <td><a href="javascript:loadValue('<?php echo $myrow['StockID'];?>,<?php echo $myrow['item_name'];?>,<?php echo $u_row['unitname'];?>,<?php echo $groupdata['categorydescription']; ?>,<?php echo $m_row['manufacturer']; ?>,<?php echo $g_row['grade']; ?>,<?php echo $gs_row['gsm']; ?> ,<?php echo $myrow['size']; ?>','<?php echo $ct[2];?>')"><?php echo $myrow['StockID'];?></a></td>
        <td><?php echo $myrow['item_name'];?></td>
		<td><?php echo $myrow['descriptions'];?></td>
		<td><?php echo $myrow['UOM'];?></td>
		      </tr>
	  <?php } ?>
</table>
</div>
</div></td></tr></table></div>
        

</form>	
	
	
	


<script>
function loadValue(str,ct)
{  
	var spl = str.split(",");
	var code = spl[0];
	var name = spl[1];
	var uomid = spl[2];	
	var group = spl[3];	
	var make=spl[4];
	var grade=spl[5];
	var gsm=spl[6];
	var size=spl[7];
	var cost=spl[8];
	if(ct)
	{
		window.opener.document.getElementById('itemcode_'+ct).value = code;
		window.opener.document.getElementById('item_name_'+ct).value = name;
		window.opener.document.getElementById('uom_'+ct).value = uomid;
		window.opener.document.getElementById('group_'+ct).value = group;
		window.opener.document.getElementById('make_'+ct).value = make;
		window.opener.document.getElementById('grade_'+ct).value = grade;
		window.opener.document.getElementById('gsm_'+ct).value = gsm;
		window.opener.document.getElementById('size_'+ct).value = size;
			
	}		
	else
	{
		window.opener.document.getElementById('itemcode'+ct).value = code;
		window.opener.document.getElementById('item_name'+ct).value = name;
		window.opener.document.getElementById('uom'+ct).value = uomid;
		window.opener.document.getElementById('group'+ct).value = group;
		window.opener.document.getElementById('make'+ct).value = make;
		window.opener.document.getElementById('grade'+ct).value = grade;
		window.opener.document.getElementById('gsm'+ct).value = gsm;
		window.opener.document.getElementById('size'+ct).value = size;
		
		
	}
	window.close();
}
</script>
	