<?php session_name('CAKEPHP'); session_start();
$PageSecurity = 2; 
include('includes/session.inc');
include('includes/function_lib.php');
include('includes/SQL_CommonFunctions.inc');
$_REQUEST['filter']=stripslashes($_REQUEST['filter']);
$rurl="&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid'];
if($_REQUEST['flag']=="1")
{
?>
<table width="100%" cellpadding="3" cellspacing="0" border="1" style="border-collapse:collapse; border:#999999 solid 1px;">
<tr class="row1">
	<td class="tabledata"><strong>Sr No.</strong></td>
	<td class="tabledata"><strong>PO No</strong></td>
	<td class="tabledata"><strong>PO Date</strong></td>
	<td class="tabledata"><strong>Vendor</strong></td>
	<td class="tabledata"><strong>PO Type</strong></td>
	<td class="tabledata"><table width="100%" border="0" cellspacing="0" cellpadding="0">
		<tr><td class="tabledata" style="text-align:center;"  colspan="3"><strong>Action</strong></td></tr>
		<tr>
			<td class="tabledata"><strong>Cancel</strong></td>
			<td class="tabledata">View</td>
			<td class="tabledata">Print</td>
		</tr>
		</table></td>	
	<!--<td class="tabledata"><strong>Approve</strong></td>-->
</tr>
<?php
$i=0; 
if($_REQUEST['filter']!="site='0'")
	{
	//echo "1---SELECT * FROM direct_po where Approval_status='".$_REQUEST['flag']."' and ".$_REQUEST['filter']." and cancel_issue='0' order by id desc";
	$sqlPoApp=DB_query("SELECT * FROM direct_po where Approval_status='".$_REQUEST['flag']."' and ".$_REQUEST['filter']."  order by id desc",$db);
	}
	else
	{
	//echo "SELECT * FROM direct_po where Approval_status='".$_REQUEST['flag']."' and cancel_issue=='1' order by id desc""; 
	$sqlPoApp=DB_query("SELECT * FROM direct_po where Approval_status='".$_REQUEST['flag']."' order by id desc",$db);
	}
if(DB_num_rows($sqlPoApp)>0){
while($PoApp=DB_fetch_array($sqlPoApp)) {
$SOURL="index.php?route=POModule/direct_po_edit2&action=Edit&SID=".$PoApp['id'].$rurl;
	 $SO_VIEW="index.php?route=POModule/direct_po_view2&action=View&SID=".$PoApp['id'].$rurl;
	 $cancelissue=$s->getField('direct_po','id',$PoApp['id'],'cancel_issue_approv');
?>
<tr bgcolor="#c1c1c1">
	<td><?php echo $i+1; ?></td>
	<td><?php echo $PoApp['pr_no']; ?></td>
	<td><?php echo ConvertSQLDate($PoApp['pr_date']); ?></td>
	<td><?php echo $s->GetFieldValue('suppliers',"id='".$PoApp['vender_id']."'",'vendor_name'); ?></td>
<!--	<td><?php echo ConvertSQLDate($PoApp['valid_till']); ?></td>
-->	<td><?php if($PoApp['mst_potype']=='1'){echo 'Import Order';}
			  if($PoApp['mst_potype']=='2'){echo 'Domestic Order';}
			  if($PoApp['mst_potype']=='3'){echo 'Service Order';}
			  if($PoApp['mst_potype']=='4'){echo 'Asset Order';} ?></td>
			  <td style="padding-left:5px; padding-right:5px;">
				 <table width="100%" border="0" cellspacing="0" cellpadding="0">
		<tr class="rowdata">
		<td><center>
	<?php 	
	if($_SESSION['frmDelete']=='1')
	{
	if($cancelissue==1) 
	{ 
	?>
			 <input type="button" name="reason"  value="Cancelled" onclick="javascript:popup('ditectpo_cancel_reason.php?modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&id=<?php echo $PoApp['id'];?>',200,220)">
			 <? } 	else { ?>
			 <a onclick="popup('direct_approv_cancel.php?modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&id=<?php echo $PoApp['id'];?>',600,200)" href="#" >Cancel</a>
			 	<?php } }else { ?><a onclick="return false;" href="#" title="No Permission">Cancel</a><?php } ?></center>	</td>
			<td><a target="_blank" href="<?php echo $SO_VIEW;?>"><img src="images/search.gif" height="15" width="15" /></a></td>
			<td>
			<?php if($PoApp['Approval_status']==1) { ?>
			<a target="_blank" href="direct_purchase_print.php?id=<?php echo $PoApp['id']?>"><img src="images/icon_print.jpg" height="25" width="25" /></a>
			<?php }
			else { ?><a target="_blank" href="direct_purchase_print.php?id=<?php echo $PoApp['id']?>" onclick="return false;" title="No Permission"><img src="images/icon_edit.gif" height="28" width="15" /></a><?php } ?>
			</td>
		</tr>
		</table>
				</td>
	<!--<td>
	<input type="hidden" name="purchid[<?php echo $i; ?>]" value="<?php echo $PoApp['id'] ?>">
	<input type="checkbox" disabled name="approve[<?php echo $i; ?>]" value="1" id="approve"></td>-->
</tr>
<?php $i++;}?>
<tr class="row1">
<!--<td colspan="7"><p align="center"><input type="submit" name="Save" value="Save"  class="search" ></p></td>-->
</tr>
<?php  }else{?>
<tr class="row1">
	<td colspan="7" style="color:#FF0000;">No Record Found</td>
</tr>
<?php  }?>
</table>
<?php 
}
elseif($_REQUEST['flag']=="0")
{
?>
<table width="100%" cellpadding="3" cellspacing="0" border="1" style="border-collapse:collapse; border:#999999 solid 1px;">
<tr class="row1">
	<td class="tabledata"><strong>Sr No.</strong></td>
	<td class="tabledata"><strong>PO No</strong></td>
	<td class="tabledata"><strong>PO Date</strong></td>
	<td class="tabledata"><strong>Vendor</strong></td>
	<td class="tabledata"><strong>PO Type</strong></td>
	<td class="tabledata"><table width="100%" border="0" cellspacing="0" cellpadding="0">
		<tr><td class="tabledata" style="text-align:center;"  colspan="3"><strong>Action</strong></td></tr>
		<tr>
			<td class="tabledata">Edit</td>
			<td class="tabledata">View</td>
			<td class="tabledata"><strong>Cancel</strong></td>
		</tr>
		</table></td>	
	<td class="tabledata"><strong>Approve</strong></td>
</tr>
<?php
$i=0; 
if($_REQUEST['filter']!="site='0'")
	{
	$sqlPoApp=DB_query("SELECT * FROM direct_po where Approval_status='".$_REQUEST['flag']."' and cancel_issue='0' and ".$_REQUEST['filter']."",$db);
	}
	else
	{
	$sqlPoApp=DB_query("SELECT * FROM direct_po where Approval_status='".$_REQUEST['flag']."' and cancel_issue='0' order by id desc",$db);
	}
if(DB_num_rows($sqlPoApp)>0){
while($PoApp=DB_fetch_array($sqlPoApp)) {
$SOURL="index.php?route=POModule/direct_po_edit2&action=Edit&SID=".$PoApp['id'].$rurl;
	$SO_VIEW="index.php?route=POModule/direct_po_view2&action=View&SID=".$PoApp['id'].$rurl;
	$cancelissue=$s->getField('direct_po','id',$PoApp['id'],'cancel_issue');
?>
<tr bgcolor="#c1c1c1">
	<td><?php echo $i+1; ?></td>
	<td><?php echo $PoApp['pr_no']; ?></td>
	<td><?php echo ConvertSQLDate($PoApp['pr_date']); ?></td>
	<td><?php echo $s->GetFieldValue('suppliers',"id='".$PoApp['vender_id']."'",'vendor_name'); ?></td>
<!--	<td><?php echo ConvertSQLDate($PoApp['valid_till']); ?></td>
-->	<td><?php if($PoApp['mst_potype']=='1'){echo 'Import Order';}
			  if($PoApp['mst_potype']=='2'){echo 'Domestic Order';}
			  if($PoApp['mst_potype']=='3'){echo 'Service Order';}
			  if($PoApp['mst_potype']=='4'){echo 'Asset Order';} ?></td>
			  <td style="padding-left:5px; padding-right:5px;">
				 <table width="100%" border="0" cellspacing="0" cellpadding="0">
		<tr class="rowdata">
			<td>
			<?php if($PoApp['Approval_status']==0) { ?>
			<a target="_blank" href="<?php echo $SOURL;?>"><img src="images/icon_edit.gif" height="28" width="15" /></a>
			<?php }
			else { ?><td><a href="<?php echo $SOURL;?>" onclick="return false;" title="No Permission"><img src="images/icon_edit.gif" height="28" width="15" /></a><?php } ?>
			</td>
			<td><a target="_blank" href="<?php echo $SO_VIEW;?>"><img src="images/search.gif" height="15" width="15" /></a></td>
			<td><center>
	<?php 	
	if($_SESSION['frmDelete']=='1')
	{
	if($cancelissue==1) 
	{ 
	?>
			 <input type="button" name="reason"  value="Cancelled" onclick="javascript:popup('ditectpo_cancel_reason.php?modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&id=<?php echo $row_quotes['id'];?>',200,220)">
			 <? } 	else { ?>
			 <a onclick="popup('direct_po_cancel2.php?modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&id=<?php echo $row_quotes['id'];?>',600,200)" href="#" >Cancel</a>
			 	<?php } }else { ?><a onclick="return false;" href="#" title="No Permission">Cancel</a><?php } ?></center>	</td>
		</tr>
		</table>
				</td>
	<td>
	<input type="hidden" name="purchid[<?php echo $i; ?>]" value="<?php echo $PoApp['id'] ?>">
	<input type="checkbox" name="approve[<?php echo $i; ?>]" value="1" id="approve"></td>
</tr>
<?php $i++;}?>
<tr class="row1">
<td colspan="7"><p align="center"><input type="submit" name="Save" value="Save" onclick="return confirm('Are you sure you want to Approve?')"  class="search" ></p></td>
</tr>
<?php  }else{?>
<tr class="row1">
	<td colspan="7" style="color:#FF0000;">No Record Found</td>
</tr>
<?php  }?>
</table>
<?php
}
?>
