<?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');
include('includes/function_lib.php');
?>
<script> 
function getdata1(str)
{  	
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
	 var data=xmlhttp.responseText.split("__");	 
	document.getElementById("ItemListDiv").innerHTML=data[1];
	document.getElementById("subcategory1").innerHTML=data[0];
		
    }
  }
  xmlhttp.open("GET","item_list_ajax.php?site="+str,true);
xmlhttp.send();

//xmlhttp.open("GET","getSort.php?s="+str+"&cat="+cat,true);

}	function getItems(str)
	{		
		//var arr=document.getElementById("arr").value;
		//alert(arr);
		
		if (window.XMLHttpRequest)
  		{// code for IE7+, Firefox, Chrome, Opera, Safari
  			xmlhttp=new XMLHttpRequest();}
		else
  		{// code for IE6, IE5
  			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
		
		xmlhttp.onreadystatechange=function()
  		{if (xmlhttp.readyState==4 && xmlhttp.status==200){
    		document.getElementById("ItemListDiv").innerHTML=xmlhttp.responseText;
    	
        		}}
xmlhttp.open("GET","item_list_ajax.php?q="+str+"&arra="+arr,true);
xmlhttp.send();
	}
function ExitWindow()
{
opener.window.location="index.php?route=Inventory/transation/material_receipt_note_add&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&type=<?php echo $_REQUEST['type']; ?>";self.close();
}
</script>
<link href="css/professional/default.css" rel="stylesheet" type="text/css" />
 <h2 align="center">Search ITEMS</h2>
<form action="" method="post" >
<table align="center" border="0">
  <tr><td><strong>Search By Category</strong></td>
  <td><select name="category" id="category" onchange="getdata1(this.value)" >
  	<option value="">Select Group</option>
            <?php 
		 $store_sql ="SELECT * FROM stockmaincategory where CompanyID='".$_SESSION['ACGCompanyId']."'";
		$store_result = DB_query($store_sql,$db);
		while($store_row = DB_fetch_array($store_result))
		{
			$p='';
			if($store_row['id'] == $_REQUEST['category'])	
			$p="selected";
		
		?>
            <option value="<?php echo $store_row['id']; ?>" <?php echo $p;?>><?php echo $store_row['stockmaincategoryname']; ?></option>
            <?php } ?>
</select>  	
  </td>
  </tr>
   <tr><td><strong>Search By Sub Category Category</strong></td>
     <td id="subcategory1"><select name="subcategory" id="subcategory" onchange="getItems(this.value)" >
  	 <option value="">Select Sub Group</option>
  	 <?php $store_sql = "SELECT * FROM stockcategory where CompanyID='".$_SESSION['ACGCompanyId']."' ";
		$store_result = DB_query($store_sql,$db);
		while($store_row = DB_fetch_array($store_result))
		{
			$p1='';
			if($store_row['categoryid'] == $_REQUEST['subcategory'])
			{	
			$p1="selected";		
		}
			?>
            <option value="<?php echo $store_row['id'] ?>"<?php echo $p1 ?>><?php echo $store_row['categorydescription']; ?></option>
          <?php  } ?>
  	 
           
</select>  	
  </td>
  </tr>
  <tr><td><strong>Enter Part Name/Part Code</strong></td>
  <td><input name="part_name" type="text" id="part_name" size="25" onkeyup="getItems(this.value)" />
  	  	
  </td>
  </tr>
</table></form>
  

<?php 
if($_REQUEST['Select'] != '')
{
	$item_array=array();
	$item_array=$_REQUEST['row_id'];
	$_SESSION['manvi_new']=$item_array;
	//print_r($_SESSION['manvi']);
	
	$itemlist=implode("#",$_SESSION['manvi_new']);
	$_SESSION['manvi_new']=$itemlist;
	//print_r($_SESSION['manvi_new']); 

	//print_r($_SESSION['ACGRequisition-ItemList']); 
if($_REQUEST['Reset']!='')
{
	unset($_SESSION['ACGRequisition-ItemList']);
	unset($_SESSION['manvi_new']);
	unset($_SESSION['IntermediateList']);
}
}
?>
<form name="form1" action="" method="post">
	<input type="text" value="<?php print_r($_SESSION['ACGRequisition-ItemList']);?>" id="arr" />
<table width="100%" border="0">
	<tr><td><input style="margin:0px 0px 10px 0px;" type="submit" name="Select" id="Select" value="Add To List"><input style="margin:0px 0px 10px 0px;" type="submit" name="Reset" id="Reset" value="Reset"></td>
		<td><div align="right"><input style="margin:0px 0px 10px 0px;" type="button" name="Exit" id="Exit" value="Exit" onclick="ExitWindow()" ></div>
		</td>
	</tr></table>

<input type="hidden" name="date" value="<?php echo $_SESSION['date'];?>" />
<input type="hidden" name="site" value="<?php echo $_SESSION['site'];?>" />
<input type="hidden" name="requisition_no" value="<?php echo $_SESSION['requisition_no'];?>" />
<input type="hidden" name="remarks" value="<?php echo $_SESSION['remarks'];?>" />

  <table width="100%" border="0" cellspacing="3" cellpadding="2" align="center">
        <tr>
          <th width="13%"><strong>SELECT</strong></th>
          <th width="30%"><strong>ITEM CODE</strong></th>
          <th width="34%"><strong>ITEM NAME</strong></th>
          <th width="23%"><strong>UNIT</strong></th>
        </tr></table>
<?php
$i=0;
  	if($i%2==0)
	{$bg="#CCCCCC";}
	else
	$bg="#C8BECB";

//echo "Select * from item_master where CategoryID!='FG'";
 	
	//echo "Select * from item_master where CategoryID!='FG' and CompanyId='".$_SESSION['ACGCompanyId']."'";
	$sql=DB_query("Select * from item_master where CategoryID!='FG' and CompanyId='".$_SESSION['ACGCompanyId']."'",$db); 	
	?>
	<div style="overflow: scroll; height: 300px" id="ItemListDiv"><table width="100%" border="0" cellspacing="3" cellpadding="2" align="center">
	<?php 
	if(DB_num_rows($sql)>0)
	{
		while($myrow=DB_fetch_array($sql))
	  	{ 	
	  		$parameter=$myrow['id'];
			$c='';
			for($x=0;$x<count($_SESSION['ACGRequisition-ItemList']);$x++)
			{
				if($parameter==$_SESSION['ACGRequisition-ItemList'][$x])
				$c="checked";
			}
  ?>
 <tr bgcolor="<?php echo $bg;?>">
      <td width="13%"><input type="checkbox" name="row_id[<?php echo $i;?>]" id="row_id_<?php echo $i;?>" value="<?php echo $parameter;?>"	<?php echo $c;?> /></td>
      <td width="32%"><strong><?php echo $myrow['StockID'];?></strong></td>
      <td width="34%"><?php echo $myrow['item_name'];?></td>
  
       <td width="21%"><?php $unit=$s->getField('unitsofmeasure','unitid',$myrow['mst_unitid'],'unitname'); echo $unit;?></td>
     
    </tr>
<?php $i++;
		} 
}?>
<input type="hidden" name="row_sount" id="row_count" value="<?php echo $i;?>">
</table></div>
  </form>


<?php
include('includes/footer.inc');
?>