<?php session_name('CAKEPHP'); session_start();
$PageSecurity = 4;
$PageName = 'Add Products';
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'])
{
	$FGarray=array();
	$FGarray=$_REQUEST['ItemCode'];
	//print_r($FGarray);
	
	$FinalFGArray=implode(',',$FGarray);
	$_SESSION['FinalFGArray']=$FinalFGArray;
	//echo $_SESSION['FinalFGArray'];
if($_REQUEST['action']=='edit')
{?>
<script type="text/javascript" language="javascript">
opener.window.location="index.php?route=EditSalesOrder&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&EditID=<?php echo $_REQUEST['EditID'];?>&act=edit";
self.close();
</script>
<?php	
} else if($_REQUEST['action']=='add')
{
?>
<script type="text/javascript" language="javascript">
opener.window.location="index.php?route=sales_order_direct&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>";self.close();
</script>
<?php }
}
if($_SESSION['client']!=''){
$assignedItemsSql="Select assigned_items from clientmaster where client_code='".$_SESSION['client']."'";
$assignedResult=DB_query($assignedItemsSql,$db);
$assignedItems=DB_fetch_array($assignedResult);
$productArray=explode(",",$assignedItems['assigned_items']); 

$sql="Select * from item_master where CategoryID='FG' and id not in(".$assignedItems['assigned_items'].")";
$result=DB_query($sql,$db);
}
else {
$sql="Select * from item_master where CategoryID='FG'";
$result=DB_query($sql,$db); }
?>
<h2 align="center">ADD PRODUCTS</h2><br /><br />
<form action="" method="post">
<input type="submit" name="Select" value="Select">


<div style="overflow:auto; height:200px">
<table width="100%" border="0" cellspacing="1" cellpadding="2">
  <tr><th colspan="6"><div align="center">Assigned Items</div></th></tr>
  <tr>
  	<th><strong></strong></th>
    <th><strong>SUB CATEGORY </strong></th>
    <th><strong>ITEM CODE </strong></th>
    <th><strong>ITEM NAME </strong></th>
    <th><strong>UNIT</strong></th>
    <th><strong>FLEXO/OFFSET</strong></th>
  </tr>
  <?php 
  for($x=0;$x<count($productArray);$x++)
	{
		$itemsSql="Select * from item_master where id='".$productArray[$x]."'";
		$itemsResult=DB_query($itemsSql,$db);
		$itemsRow=DB_fetch_array($itemsResult);

  
  	if($x%2==0)
	{$bg="#CCCCCC";}
	else
	$bg="#C8BECB";
  ?>
  <tr bgcolor="<?php echo $bg;?>">
  	<td><input type="checkbox" name="ItemCode[<?php echo $x;?>]" id="ItemCode_<?php echo $x;?>" value="<?php echo $itemsRow['StockID'];?>"></td>
    <td><?php echo $itemsRow['SubCategoryID']; ?></td>
    <td><?php echo $itemsRow['StockID']; ?></td>
    <td><?php echo $itemsRow['item_name']; ?></td>
    <td><?php echo $itemsRow['unit']; ?></td>
    <td><?php echo $itemsRow['flexo_offset']; ?></td>
  </tr>
  <?php  }?>
</table>
</div>




<div style="overflow:auto; height:300px">
<table width="100%" border="0" cellspacing="1" cellpadding="2">
  <tr>
  	<th><strong></strong></th>
    <th><strong>SUB CATEGORY </strong></th>
    <th><strong>ITEM CODE </strong></th>
    <th><strong>ITEM NAME </strong></th>
    <th><strong>UNIT</strong></th>
    <th><strong>FLEXO/OFFSET</strong></th>
  </tr>
  <?php 
  $i=$x;
  while($myrow=DB_fetch_array($result))
  {
  	if($i%2==0)
	{$bg="#CCCCCC";}
	else
	$bg="#C8BECB";
  ?>
  <tr bgcolor="<?php echo $bg;?>">
  	<td><input type="checkbox" name="ItemCode[<?php echo $i;?>]" id="ItemCode_<?php echo $i;?>" value="<?php echo $myrow['StockID'];?>"></td>
    <td><?php echo $myrow['SubCategoryID']; ?></td>
    <td><?php echo $myrow['StockID']; ?></td>
    <td><?php echo $myrow['item_name']; ?></td>
    <td><?php echo $myrow['unit']; ?></td>
    <td><?php echo $myrow['flexo_offset']; ?></td>
  </tr>
  <?php $i++;} ?>
</table>
</div>
</form>














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