<?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 src="js/function-ajax.js"></script>

<link href="css/professional/default.css" rel="stylesheet" type="text/css" />
 <h2 align="center">Search ITEMS</h2>
<form action="requisition_items.php" method="post" >
<table align="center" border="0">
<tr> <td><strong>Item main category </strong></td>
<td>
<?php  
 $item_query="select stockmaincategoryname, stockmaincategoryid from stockmaincategory where stockmaincategoryid != 'FG' ";
  $res=DB_query($item_query ,$db);
  //echo DB_num_rows($res);
?>
<select name="CategoryID"  onchange="ShowDiv(this.value,'hid-subcatitem','disp_subcatitem.php')" >
	<option value="0">Select</option>
<?php	
		while($item_row1=DB_fetch_array($res))
		{?>
		 <option value="<?php echo $item_row1['stockmaincategoryid'];?>" <?php echo $_REQUEST['CategoryID']==$item_row1['stockmaincategoryid']?'selected':'' ;?>>
		 <?php echo $item_row1['stockmaincategoryname'];?></option>
          <?php 	} ?>
        </select>
		</td>
</tr>
<tr><td><strong>Item sub category</strong></td>
<td>
<div id='hid-subcatitem'>
<select name="SubCategoryID">
<option value="0">Select</option>
<?php $item_query1="select categoryid, categorydescription from stockcategory ";
		$res1=DB_query($item_query1 ,$db);
		while($item_row2=DB_fetch_array($res1))
		{?>
<option value="<?php echo $item_row2['categoryid'];?>" <?php echo $_REQUEST['SubCategoryID']==$item_row2['categoryid']?'selected':'' ;?>><?php echo $item_row2['categorydescription'];?></option>
<?php } ?></select>
</div></td>
</tr>
<tr><td><strong>Item code</strong></td>
  <td><input name="StockID" type="text" id="StockID" size="25" /></td>
  </tr>
<tr><td colspan="2"><input type="submit" value="Show" name="submit" /></td></tr>
</table></form>

<?php 
if($_REQUEST['Select']!='')
{
	
	 
	$item_array=array();
	$item_array=$_REQUEST['row_id'];
 		$_SESSION['ACGRequisition-ItemList']=$item_array;
 	 if(isset($_SESSION['ACGRequisition-ItemList']))
		$_SESSION['ACGRequisition-ItemList']=array_unique($_SESSION['ACGRequisition-ItemList']);
	
	

	if(!empty($_SESSION['ACGRequisition-ItemList']))
	{
	$itemlist=implode("#",$_SESSION['ACGRequisition-ItemList']);
	$_SESSION['ACGRequisition-ItemList_1']=$itemlist;
	 
	}
	 
	  
if(count($_SESSION['ACGRequisition-ItemList'])==0)
{
	unset($_SESSION['ACGRequisition-ItemList']);
	unset($_SESSION['ACGRequisition-ItemList_1']);
 
}
}

 ?>
 
 
  <?php
 //---------------------------Search Starts here-------------------------------
if(isset($_POST['submit']))
{
  $_SESSION['ACGRequisition-ItemList']=array();

		$sql_search='';
		$CategoryID=$_REQUEST['CategoryID'];
		$SubCategoryID=$_REQUEST['SubCategoryID'];
		$StockID=$_REQUEST['StockID'];
		$flexo_offset=$_REQUEST['flexo_offset'];
		
		$sql_search = "select * from item_master where 1=1 ";
		
		
		if(!empty($CategoryID))
		{
			$sql_search .=" and  CategoryID = '".$CategoryID."'";
		} 
		if(!empty($SubCategoryID) || $SubCategoryID!='000')
		{
			$sql_search .=" and SubCategoryID = '".$SubCategoryID."'";
		}
		if(!empty($StockID))
		{
			$sql_search .=" and StockID LIKE '%".$StockID."%'";
		}
		if(!empty($flexo_offset))
		{
			$sql_search .=" and flexo_offset = '".$flexo_offset."'";
		}
		
		// echo $sql_search ;
			$search_result = DB_query($sql_search, $db);
			//echo $sql_search;
	
			
}?>
<script type="text/javascript">
function ExitWindow()
{
 
opener.window.location="index.php?route=edit_misc_purchase_bill&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&editId=<?php echo $_REQUEST['editId'];?>";self.close();
}
</script>

<form name="form1" action="" method="post">
 <input type="hidden" 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"></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="32%"><strong>ITEM CODE</strong></th>
          <th width="34%"><strong>ITEM NAME</strong></th>
          <th width="21%"><strong>UNIT</strong></th>
        </tr>
<?php
$i=0;
  	if($i%2==0)
	{$bg="#CCCCCC";}
	else
	$bg="#C8BECB";

if(isset($_REQUEST['submit']))
{
	if(DB_num_rows($search_result)>0)
	{
	 	while($myrow = DB_fetch_array($search_result))
	 	{
	 		$c='';
			 
			if( in_array($myrow['StockID'],$_SESSION['ACGRequisition-ItemList']) && count($_SESSION['ACGRequisition-ItemList'])>0) 
			{
					
			  	$c="checked";
 				$f=0;
			}
	 	?>
        <?php 	
  $parameter=$myrow['StockID'];
  ?>
        <tr bgcolor="<?php echo $bg;?>">
		 
		  
          <td> <input type="checkbox" name="row_id[<?php echo $i;?>]" id="row_id_<?php echo $i;?>" value="<?php echo $parameter;?>"<?php echo $c;?> /></td>
          <td><strong><?php echo $myrow['StockID'];?></strong></td>
          <td><?php echo $myrow['item_name'];?></td>
          <td><?php $unit=$s->getField('unitsofmeasure','unitid',$myrow['unit'],'unitname'); echo $unit;?></td>
        </tr>
        <?php $i++;
	 } 
  }
	else
	{?>
	 <tr>
      <td colspan="9"><h3 align="center">No Items Found</h3></td>
    </tr>
        <?php 
	}
?>
     
 <?php } //----------------end of Search---------------- 
else 
{
   	$sql=DB_query("Select * from item_master where CategoryID!='FG'",$db); 	
	if(DB_num_rows($sql)>0)
	{
		while($myrow=DB_fetch_array($sql))
	  	{
		$c='';
		  if(isset($_SESSION['ACGRequisition-ItemList']))
		  {
			if( in_array($myrow['StockID'],$_SESSION['ACGRequisition-ItemList'])) 
			{
					
			  	$c="checked";
 			 
			} 	
		 }	
	 	 $parameter=$myrow['StockID'];
  ?>
 <tr bgcolor="<?php echo $bg;?>">
      <td width="13%"><input type="checkbox" name="row_id[<?php echo $i;?>]2" 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['unit'],'unitname'); echo $unit;?></td>
     
    </tr>
<?php $i++;
		} 
}?>
<input type="hidden" name="row_sount" id="row_count" value="<?php echo $i;?>">
</table>
 
<?php } 
 ?>
  </form>

