<?php 
$PageSecurity = 15;
include('includes/session.inc');
include('includes/SQL_CommonFunctions.inc');
include('includes/DefineSuppTransClass.php');
?>

<link href="css/professional/default.css" rel="stylesheet" type="text/css" />
<h2 align="center">ADD ITEMS</h2>
<form  action="" method="post">
<table width="100%" style="border: solid 1px #CCCCCC">
<tr class="row1">
<th><strong>Item Name</strong></th>
<td><input type="text" value="" name="item"  onchange="abc(this.value);"/></td>
<td><input type="submit" name="Search"  value="Search"/></td></tr>		
</table>		
</form>
 <?php
 //---------------------------Search Starts here-------------------------------
if(isset($_POST['Search']))
{
		$sql_search='';
		$item_name=$_REQUEST['item'];
		
			$sql_search = "select * from item_master where StockID='".$item_name."' and CategoryID='FG' or SubCategoryID='06semi'";
		
}
else {
	 $sql_search = "SELECT * FROM item_master I INNER JOIN stockmaincategory C on C.id=I.CategoryID WHERE C.CompanyId='".$_SESSION['ACGCompanyId']."' and (C.stockmaincategoryid='FG' OR C.stockmaincategoryid='SF')";
}
			//echo $sql_search;				
    

	$search_result = DB_query($sql_search, $db);
?>
<form name="form1" action="" method="post">
<?php
$i=0;
  	if($i%2==0)
	{$bg="#CCCCCC";}
	else
	$bg="#C8BECB";

?>
<div style="overflow:auto; width:100%;">
<table width="100%" border="0" cellspacing="3" cellpadding="2" align="center">
    <tr>
       <th width="12%"><strong>ITEM CODE</strong></th>
      <th width="23%"><strong>ITEM NAME</strong></th>
      <th width="8%"><strong>ITEM DESCRIPTION </strong></th>
      <th width="10%"><strong>Unit No</strong></th>
      	   </tr>
    <?php
	//echo "inside IF IF ";
	if(DB_num_rows($search_result)>0)
	{
	 	while($myrow = DB_fetch_array($search_result))
	 	{
	 		$u_sql=DB_query("Select unitname from unitsofmeasure where unitid='".$myrow['mst_unitid']."'",$db);
		   $u_row=DB_fetch_array($u_sql);
		  	 		
	 		?>
    <?php 	
  $parameter=$myrow['StockID'];
  ?>
    <tr bgcolor="<?php echo $bg;?>">
      <td>
      	<a href="javascript:loadValue('<?php echo $myrow['StockID'];?>,<?php echo $myrow['item_name'];?>,<?php echo $u_row['unitname'];?>','<?php echo $ct[2];?>')">
      <?php echo $myrow['StockID'];?></a></td>
      <td><?php echo $myrow['item_name'];?></td>
      <td><?php echo $myrow['item_desc'];?></td>
      <td><?php echo $u_row['unitname']; ?></td>
         
	  
    </tr>
    <?php } }
	else
	{?>
    <tr>
      <td colspan="9"><h3 align="center">No Items Found</h3></td>
    </tr>
   <?php } ?>
  </table>
</div>

</form>


 <script>
function loadValue(str,ct)
{  
//alert(ct);
	var spl = str.split(",");
	var code = spl[0];
	var name = spl[1];
	var uomid = spl[2];	
	
		window.opener.document.getElementById('part_code').value = code;
		window.opener.document.getElementById('product_name').value = name;
		window.opener.document.getElementById('finished_uom').value = uomid;
	
	window.close();
}
</script>