<?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');
if($_REQUEST['Select'] != '')
{
	$item_array=array();
	$item_array=$_REQUEST['row_id'];
	$_SESSION['POItems']=$item_array;
	//print_r($_SESSION['POItems']);
	
	$itemlist=implode("#",$_SESSION['POItems']);
	$_SESSION['POItemlist']=$itemlist;
	//print_r($_SESSION['POItemlist']); 
?>
<script type="text/javascript">
opener.window.location="index.php?route=POModule/ImportPO&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>";self.close();
</script>
<?php 
}
?>
<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>
<table width="100%" cellpadding="3" border="1" style="border-collapse:collapse; border:#999999 solid 1px;">
<form action="requisition_items.php" method="post">
<tr> <th><strong>Item main category </strong></th>
<td>
<select name="CategoryID" id="CategoryID " style="width:50%">
	<option value="0">Select</option>
<?php
 $item_query="select stockmaincategoryname, stockmaincategoryid from stockmaincategory where stockmaincategoryid != 'FG' ";
		$res=DB_query($item_query ,$db);
		while($item_row1=DB_fetch_array($res))
		{?>
		 <option value="<?php echo $item_row1['stockmaincategoryid'];?>"><?php echo $item_row1['stockmaincategoryname'];?></option>
          <?php 	} ?>
        </select></td></tr>
<tr><th><strong>Item sub category</strong></th><td>
<select name="SubCategoryID"  style="width:50%">
<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 $item_row2['categorydescription'];?></option>
<?php } ?></select></td></tr>
<tr><th><strong>Item code</strong></th>
  <td><input name="StockID" type="text" id="StockID"  style="width:50%" /></td></tr>
<tr><th><strong>Flexo/Offset</strong></th>
  <td><select name="flexo_offset" id="flexo_offset"  style="width:50%">
    <option value="0">Select</option>
    <option value="Flexo">Flexo</option>
    <option value="Offset">Offset</option>
  </select></td>
</tr>
<tr><td colspan="2"><input type="submit" value="Submit" name="submit" /></form></td></tr></table>

  <?php
 //---------------------------Search Starts here-------------------------------
if(isset($_POST['submit']))
{
		$sql_search='';
		$CategoryID=$_REQUEST['CategoryID'];
		$SubCategoryID=$_REQUEST['SubCategoryID'];
		$StockID=$_REQUEST['StockID'];
		$flexo_offset=$_REQUEST['flexo_offset'];
		if(empty($CategoryID) && empty($SubCategoryID) && empty($StockID) && empty($flexo_offset) )
		{
		$sql_search = "select * from item_master where 1 ";
		}
		else 
		{
			$sql_search = "select * from item_master where 0 ";
		}
		if(!empty($CategoryID))
		{
			$sql_search .=" OR CategoryID = '".$CategoryID."'";
		} 
		if(!empty($SubCategoryID))
		{
			$sql_search .=" OR SubCategoryID = '".$SubCategoryID."'";
		}
		if(!empty($StockID))
		{
			$sql_search .=" OR StockID LIKE '%".$StockID."%'";
		}
		if(!empty($flexo_offset))
		{
			$sql_search .=" OR flexo_offset = '".$flexo_offset."'";
		}
			$search_result = DB_query($sql_search, $db);
			//echo $sql_search;
	
			
}?>
<form name="form1" action="" method="post">
<input type="submit" name="Select" id="Select" value="Select">
<?php
$i=0;
  	if($i%2==0)
	{$bg="#CCCCCC";}
	else
	$bg="#C8BECB";

if(isset($_REQUEST['submit']))
{
//echo "inside IF IF ";
?>

<div style="overflow:auto; width:890px; margin-left:auto; margin-right:auto; height:250px">
<table width="100%" border="0" cellspacing="3" cellpadding="2" align="center">
    <tr>
      <th width="7%"><strong>SELECT</strong></th>
      <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>ITEM NO.</strong></th>
      <th width="13%"><strong>FLEXO/OFFSET</strong></th>
      <th width="10%"><strong>UNIT</strong></th>
	  <th width="10%"><strong>OD</strong></th>
      <th width="10%"><strong>SERIAL NO. </strong></th>
      <th width="7%"><strong>ORIGINAL/LOCAL</strong></th>
      <th width="7%"><strong>TYPE </strong></th>
      <th width="7%"><strong>SHADE</strong></th>
      <th width="7%"><strong>RUNNING METER/ROLL</strong></th>
      <th width="7%"><strong>VOLUME</strong></th>
      <th width="7%"><strong>TEETH</strong></th>
      <th width="7%"><strong>BCM</strong></th>
      <th width="7%"><strong>UPS</strong></th>
      <th width="7%"><strong>QUALITY</strong></th>
    </tr>
    <?php
	//echo "inside IF IF ";
	if(DB_num_rows($search_result)>0)
	{
	 	while($myrow = DB_fetch_array($search_result))
	 	{?>
    <?php 	
  $parameter=$myrow['StockID'];
  ?>
    <tr bgcolor="<?php echo $bg;?>">
      <td><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><strong><?php echo $myrow['StockID'];?></strong></td>
      <td><?php echo $myrow['item_name'];?></td>
      <td><?php echo $myrow['item_desc'];?></td>
      <td><?php echo $myrow['item_no'];?></td>
      <td><?php echo $myrow['flexo_offset'];?></td>
      <td><?php $unit=$s->getField('unitsofmeasure','unitid',$myrow['unit'],'unitname'); echo $unit;?></td>
	  <td><?php echo $myrow['od'];?></td>
      <td><?php echo $myrow['serial_no'];?></td>
      <td><?php echo $myrow['orig_local'];?></td>
      <td><?php echo $myrow['type_name'];?></td>
      <td><?php echo $myrow['shade'];?></td>
      <td><?php echo $myrow['running_roll'];?></td>
      <td><?php echo $myrow['volume'];?></td>
      <td><?php echo $myrow['teeth'];?></td>
      <td><?php echo $myrow['bcm'];?></td>
      <td><?php echo $myrow['ups'];?></td>
      <td><?php echo $myrow['quantity'];?></td>
    </tr>
    <?php $i++;} }
	else
	{?>
    <tr>
      <td colspan="9"><h3 align="center">No Items Found</h3></td>
    </tr>
    <?php 
	}
?>
  </table>
</div>

<?php } //----------------end of Search---------------- 
else 
{
?>

<div style="overflow:auto; width:890px; margin-left:auto; margin-right:auto; height:250px">
<table width="100%" border="1" cellspacing="3" cellpadding="0" style="border-collapse:collapse;">
  <tr>
  	<th><strong>SELECT</strong></th>
    <th><strong>ITEM CODE</strong></th>
    <th><strong>ITEM NAME</strong></th>
	<th><strong>ITEM DESCRIPTION </strong></th>
	<th><strong>ITEM NO.</strong></th>
	<th><strong>FLEXO/OFFSET</strong></th>
	<th><strong>UNIT</strong></th>
	<th><strong>OD</strong></th>
	<th><strong>SERIAL NO. </strong></th>
	<th><strong>ORIGINAL/LOCAL</strong></th>
	<th><strong>TYPE </strong></th>
	<th><strong>SHADE</strong></th>
	<th><strong>RUNNING METER/ROLL</strong></th>
	<th><strong>VOLUME</strong></th>
	<th><strong>TEETH</strong></th>
	<th><strong>BCM</strong></th>
	<th><strong>UPS</strong></th>
	<th><strong>QUALITY</strong></th>
  </tr>
<?php
	//echo "inside ELSE ";
	$sql=DB_query("Select * from item_master where CategoryID!='FG'",$db); 	
	if(DB_num_rows($sql)>0)
	{
		while($myrow=DB_fetch_array($sql))
	  	{ 	
	  $parameter=$myrow['StockID'];
  ?>
 <tr bgcolor="<?php echo $bg;?>">
      <td><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><strong><?php echo $myrow['StockID'];?></strong></td>
      <td><?php echo $myrow['item_name'];?></td>
      <td><?php echo $myrow['item_desc'];?></td>
      <td><?php echo $myrow['item_no'];?></td>
      <td><?php echo $myrow['flexo_offset'];?></td>
      <td><?php $unit=$s->getField('unitsofmeasure','unitid',$myrow['unit'],'unitname'); echo $unit;?></td>
	   <td><?php echo $myrow['od'];?></td>
      <td><?php echo $myrow['serial_no'];?></td>
      <td><?php echo $myrow['orig_local'];?></td>
      <td><?php echo $myrow['type_name'];?></td>
      <td><?php echo $myrow['shade'];?></td>
      <td><?php echo $myrow['running_roll'];?></td>
      <td><?php echo $myrow['volume'];?></td>
      <td><?php echo $myrow['teeth'];?></td>
      <td><?php echo $myrow['bcm'];?></td>
      <td><?php echo $myrow['ups'];?></td>
      <td><?php echo $myrow['quantity'];?></td>
    </tr>
<?php $i++;} }?>
<input type="hidden" name="row_sount" id="row_count" value="<?php echo $i;?>">
</table>
</div>
</form>
<?php } 
//end of page full new headings if

//end of while loop
?>
 </table></table>
<?php 
//include('includes/footer.inc');
?>