 <?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']."' order by Comprative_date desc";
}
else
{
	$sql = "select * from comprative_detail order by Comprative_date desc";
} 
	 
   $PurchOrdersResult = DB_query($sql,$db);?>
   <h3>Purchase Order Approval </h3>
   <table  border="0" width="100%" cellspacing="2" cellpadding="2">
	<tr>
	<th><strong>Comparison Number</strong></th>
	<th><strong>Comparison Date</strong></th>
	 
	<th><strong>Vendor Code</strong></th>
	<th><strong>Vendor</strong></th>

	<th><strong>PO Status</strong></th>
	 
	<th><strong>Process PO/View</strong></th>
	<th><strong>Delete</strong></th>
	</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['comprative_id']."'" ,'orderno'); 
		 if( $CHECK_POSTATUS!=0){
	?>
	<tr bgcolor="#FFFFFF" onmouseover="this.style.backgroundColor='#fffeb3'; this.style.color='#00f';" onmouseout="this.style.backgroundColor='#FFF'; this.style.color='#000000';">
	<td> 
	
	
	<?php echo $row['comprative_no'];?></td>
	<td> <?php echo ConvertSQLDate($row['Comprative_date']);?></td>
		<td> <?php echo $s->GetFieldValue('suppliers',"id='".$row['vendor_id']."'" ,'vendor_code');
		?></td>
 <td> <?php echo  $s->GetFieldValue('suppliers',"id='".$row['vendor_id']."'" ,'vendor_name');;?></td>
	<td>
<?php 	
	  $CHECK_POSTATUS=    $s->GetFieldValue('purchorders',"mst_comperitive='".$row['comprative_id']."'" ,'orderno'); 
	 echo   $CHECK_POSTATUS!=0?'Generated':'Not Generated' ;?></td>
	<td>  
	 
	<?php if($CHECK_POSTATUS!=0){?>
	<a href="index.php?route=POModule/POrderview<?php echo $rurl;?>&CPID=<?php echo $row['comprative_id']?>"> <img src="images/search.gif"  width="20" height="20"/></a>
 <?php } else { ?>
 	<a href="index.php?route=POModule/POrder<?php echo $rurl;?>&CPID=<?php echo $row['comprative_id']?>&site=<?php echo $row['sitecode']?>"> <img src="images/search.gif"  width="20" height="20"/></a>

	<?php } ?>
	
	</td>
	<td>
	<?php  $chkpogenraed= $s->GetFieldValue('purchorders',"mst_comperitive='".$row['comprative_id']."'" ,'orderno');
if( $chkpogenraed==0)
{?>
<a href="index.php?route=POModule/Comp-order-list&action=del<?php echo $rurl;?>&CPID=<?php echo $row['comprative_id']?>&CGROUP=<?php echo $_REQUEST['CGROUP']?>">
<img src="images/Icon_Delete.png" /></a>
<?php } 
	else {
	echo "Delete";
	}?>
	</td>
	</tr>
<?php
		$j++;
		 }
		}
 		
	 
	}
	else
	{?>
		<tr>
		<td colspan="5"><font color="#FF0000"><h2 align="center">No Record Found!</h2></font></td>
		</tr>
	<?php }
	?>
</table>
