 <?php extract($_POST);
$PageSecurity = 1;
 
global $db;

if($_REQUEST['action']=='del')
{
 
	  $delete_sql1="Delete from comprative_detail where comprative_id='".$_REQUEST['CPID']."'";
	  $delete_res1=DB_query($delete_sql1,$db);
 		$s->pageLocation("index.php?route=POModule/Comp-order-list".$rurl."&CGROUP=".$_REQUEST['CGROUP']);
  }
  
 
if($_REQUEST['CGROUP']!='')
{
	  $sql = "select * from comprative_detail  where comprative_no  ='".$_REQUEST['CGROUP']."' and status_active=0 order by Comprative_date DESC";
}
else
{
	 $sql = "SELECT A.id AS PID,A.site,A.comparative_no,A.comparative_date, 
B.*
FROM comprative A INNER JOIN comprative_detail B ON(A.id=B.parant_id)
GROUP BY B.sppliersId";
	//echo $sql="select * from comprative_detail A,purchorders B where A.status_active=0  and A.comprative_id!=B.mst_comperitive order by A.Comprative_date desc";
} 
//echo $sql; 
   $PurchOrdersResult = DB_query($sql,$db);?>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1>Purchase Order Approval</h1>
<table  border="1" width="100%" cellspacing="0" cellpadding="3">
<tr class="row1">
	<td class="tabledata"><strong>Comparison Number</strong></td>
	<td class="tabledata"><strong>Comparison Date</strong></td>
	<td class="tabledata"><strong>Vendor</strong></td>
	
	<td class="tabledata"><strong>PO Status</strong></td>
	
	<td class="tabledata"><strong>Process PO/View</strong></td>
	<td class="tabledata"><strong>Delete</strong></td>
</tr>
	<?php
	$j = 1;
	$k=0; //row colour counter

	if(DB_num_rows($PurchOrdersResult)>0)
	{
	while ($row=DB_fetch_array($PurchOrdersResult)) 
	{
		$CHECK_POSTATUS=$s->GetFieldValue('purchorders',"mst_comperitive='".$row['PID']."'" ,'orderno'); 
		if($CHECK_POSTATUS==0){?>
	<tr class="row1">
	<td> 
	<?php echo $row['comparative_no'];?></td>
	<td><?php echo ConvertSQLDate($row['comparative_date']);?></td>
 	<td><?php echo  $s->GetFieldValue('suppliers',"id='".$row['sppliersId']."'" ,'vendor_name');;?></td>
	<td>
<?php 	
	
	 echo   $CHECK_POSTATUS!=0?'Generated':'Not Generated' ;?></td>
	<td>  
	 
	<?php if($CHECK_POSTATUS!=0){?>
	<?php if($_SESSION['frmView']==1){ ?>
	<a href="index.php?route=POModule/POrderview<?php echo $rurl;?>&CPID=<?php echo $row['PID']?>"> <img src="images/search.gif"  width="20" height="20"/></a>
	<?php }else{ ?>
<?php echo 'No Permission'; ?>
<?php }?>
	
 <?php } else { 
 	if($row['Quotations_type']!='AMD')
	{?>
	
	<?php if($_SESSION['frmView']==1){ ?>
 	<a href="index.php?route=POModule/POrder<?php echo $rurl;?>&CPID=<?php echo $row['PID']?>&SupplierId=<?php echo $row['sppliersId'] ?>&site=<?php echo $row['site'];?>"> <img src="images/search.gif"  width="20" height="20"/></a>
		<?php }else{ ?>
<?php echo 'No Permission'; ?>
<?php }?>
	
<?php } else { ?>

	<?php if($_SESSION['frmView']==1){ ?>
	<a href="index.php?route=POModule/POrderamd<?php echo $rurl;?>&CPID=<?php echo $row['PID']?>&site=<?php echo $row['sitecode']?>"> <img src="images/search.gif"  width="20" height="20"/></a>

		<?php }else{ ?>
<?php echo 'No Permission'; ?>
<?php }?>

	<?php }?>
	<?php } ?>
	
	</td>
	<td>
	<?php  $chkpogenraed= $s->GetFieldValue('purchorders',"mst_comperitive='".$row['PID']."'" ,'orderno');
if( $chkpogenraed==0)
{?>
<?php if($_SESSION['frmDelete']==1){ ?>
<a href="index.php?route=POModule/Comp-order-list&action=del<?php echo $rurl;?>&CPID=<?php echo $row['PID']?>&CGROUP=<?php echo $_REQUEST['CGROUP']?>">
<img src="images/Icon_Delete.png" /></a>

<?php }else{ ?>
<?php echo 'No Permission'; ?>
<?php }?>

<?php } 
	else {
	echo "Delete";
	}?>
	</td>
	</tr>s
<?php     
		$j++;  }
		 
		}
 		
	 
	}
	else
	{?>
		<tr>
		<td colspan="5"><font color="#FF0000"><h2 align="center">No Record Found!</h2></font></td>
		</tr>
	<?php }
	?>
</table>
