<?php ob_start();
$PageSecurity = 2;
$_SESSION['modid']=$_REQUEST['modid'];
$_SESSION['frmid']=$_REQUEST['frmid'];
///get form permissions///
$frmpermission= $px->GetFileAccess($_SESSION['modid'],$_SESSION['frmid'],$_SESSION['ACGRoleId']);


$_SESSION['frmAdd']=$frmpermission[0];
$_SESSION['frmEdit']=$frmpermission[1];
$_SESSION['frmDelete']=$frmpermission[2]; 
$_SESSION['frmView']=$frmpermission[3]; 



///get from id through URL///
$formId=$px->GetFormId('VenderQutations');
$_SESSION['frmid2']=$formId;
///get form permissions///
$frmpermission2=$px->GetFileAccess($_SESSION['modid'],$_REQUEST['frmid'],$_SESSION['ACGRoleId']);
$_SESSION['vendorquotAdd']=$frmpermission2[0];
$_SESSION['comparative_formId']=$px->GetFormId('Comperitive_listing');
//echo "<br>-----------".$_SESSION['comparative_formId']."-----------<br>";
$frmpermission3=$px->GetFileAccess($_SESSION['modid'],$_SESSION['comparative_formId'],$_SESSION['ACGRoleId']);
$_SESSION['compAdd']=$frmpermission3[0];
$_SESSION['compEdit']=$frmpermission3[1];
$_SESSION['compDelete']=$frmpermission3[2];

unset($_REQUEST['ACGRequisition-ItemList']);
unset($_REQUEST['ACGRequisition-ItemList_1']);
unset($_SESSION['manvi']);
?>
<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>
<script src="ui/jquery.ui.datepicker.js"></script>
<script>
$(function() {
	$(".datepicker").datepicker({
		showOtherMonths: true,
		selectOtherMonths: true
	});
});
</script>
<script type="text/javascript">
function showSlidingDiv(){
$("#slidingDiv").animate({"height": "toggle"}, { duration: 900 });
}
function searchRecord(){
	if(document.getElementById('datepicker').value==''){
		alert('Pick start date');
		document.getElementById('datepicker').focus();
		return false;
	}
	if(document.getElementById('datepicker1').value==''){
		alert('Pick end date');
		document.getElementById('datepicker1').focus();
		return false;
	}
	return true;
}
function deletevalidation()
{
	alert("Test");
	
	
	
}
</script>
<?php
if (empty($_GET['identifier'])) {
			 $identifier=date('U');
		} else {
			$identifier=$_GET['identifier'];
		}
$title = _('Search Outstanding Purchase Requisition');
//include('includes/header.inc');
if (isset($_GET['SelectedStockItem'])){
	$SelectedStockItem=trim($_GET['SelectedStockItem']);
} elseif (isset($_POST['SelectedStockItem'])){
	$SelectedStockItem=trim($_POST['SelectedStockItem']);
}

if (isset($_GET['RequisitionNumber'])){
	$RequisitionNumber=trim($_GET['RequisitionNumber']);
} elseif (isset($_POST['RequisitionNumber'])){
	$RequisitionNumber=trim($_POST['RequisitionNumber']);
}

//echo '<a href="index.php">Main menu</a>';
if (isset($_GET['SelectedSupplier'])){
	$SelectedSupplier=trim($_GET['SelectedSupplier']);
} elseif (isset($_POST['SelectedSupplier'])){
	$SelectedSupplier=trim($_POST['SelectedSupplier']);
}
        $type="paging";
		$rowsPerPage = 10;
		$pageNum = 1;
		if(isset($_GET['page']))
		{
			$pageNum = $_GET['page'];
		}
		$offset = ($pageNum - 1) * $rowsPerPage;
$urldata="route=MR_SelectOSMaterialRequi&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."";
echo '<form action="' . $_SERVER['PHP_SELF'] . '?' . $urldata . '" method=post>';


if (isset($_POST['ResetPart'])){
     unset($SelectedStockItem);
}

/*if (isset($RequisitionNumber) && $RequisitionNumber!='') {
	if (!is_numeric($RequisitionNumber)){
		  echo '<br><b>' . _('The Requisition Number entered') . ' <U>' . _('MUST') . '</U> ' . _('be numeric') . '.</b><br>';
		  unset ($RequisitionNumber);
	} else {
		echo _('Requisition Number') . ' - ' . $RequisitionNumber;
	}} else */

{
	if (isset($SelectedSupplier)) 
	{
		echo '<br><div class="page_help_text">' . _('For supplier') . ': ' . $SelectedSupplier . ' ' . _('and') . ' ';
		echo '<input type=hidden name="SelectedSupplier" value="' . $SelectedSupplier . '"></div>';
	}
	if (isset($SelectedStockItem)) 
	{
		 echo '<input type=hidden name="SelectedStockItem" value="' . $SelectedStockItem . '">';
	}
}

if (isset($_POST['SearchParts'])) {
	//$completed='purchorderdetails.completed=0';

	if (isset($_POST['Keywords']) AND isset($_POST['StockCode'])) {
		echo '<div class="page_help_text">' ._('Stock description keywords have been used in preference to the Stock code extract entered') . '.</div>';
	}
	If ($_POST['Keywords']) {
		//insert wildcard characters in spaces
		$i=0;
		$SearchString = '%';
		while (strpos($_POST['Keywords'], ' ', $i)) {
			$wrdlen=strpos($_POST['Keywords'],' ',$i) - $i;
			$SearchString=$SearchString . substr($_POST['Keywords'],$i,$wrdlen) . '%';
			$i=strpos($_POST['Keywords'],' ',$i) +1;
		}
		$SearchString = $SearchString. substr($_POST['Keywords'],$i).'%';

 		$SQL = "SELECT stockmaster.stockid, 
				stockmaster.description, 
				SUM(locstock.quantity) AS qoh,  
				stockmaster.units, 
				SUM(purchorderdetails.quantityord-purchorderdetails.quantityrecd) AS qord 
			FROM stockmaster INNER JOIN locstock 
				ON stockmaster.stockid = locstock.stockid 
				INNER JOIN purchorderdetails 
					ON stockmaster.stockid=purchorderdetails.itemcode 
			WHERE $completed
			stockmaster.description " . LIKE . " $SearchString 
			AND stockmaster.categoryid='" . $_POST['StockCat'] . "' 
			GROUP BY stockmaster.stockid, 
				stockmaster.description, 
				stockmaster.units 
			ORDER BY stockmaster.stockid";
			
			
	 } 
	 elseif ($_POST['StockCode']){
		$SQL = "SELECT stockmaster.stockid, 
				stockmaster.description, 
				SUM(locstock.quantity) AS qoh, 
				SUM(purchorderdetails.quatity-purchorderdetails.quantityrecd) AS qord, 
				stockmaster.units 
			FROM stockmaster INNER JOIN locstock 
				ON stockmaster.stockid = locstock.stockid 
				INNER JOIN purchorderdetails 
					ON stockmaster.stockid=purchorderdetails.itemcode 
			WHERE $completed
			AND stockmaster.stockid " . LIKE . " '%" . $_POST['StockCode'] . "%' 
			AND stockmaster.categoryid='" . $_POST['StockCat'] . "' 
			GROUP BY stockmaster.stockid, 
				stockmaster.description, 
				stockmaster.units 
			ORDER BY stockmaster.stockid";
			
	 } 
	 elseif (!$_POST['StockCode'] AND !$_POST['Keywords']) 
	 {
		$SQL = "SELECT stockmaster.stockid, 
				stockmaster.description, 
				SUM(locstock.quantity) AS qoh, 
				stockmaster.units, 
				SUM(purchorderdetails.quatity-purchorderdetails.quantityrecd) AS qord 
			FROM stockmaster INNER JOIN locstock 
				ON stockmaster.stockid = locstock.stockid 
				INNER JOIN purchorderdetails 
					ON stockmaster.stockid=purchorderdetails.itemcode 
			WHERE stockmaster.categoryid='" . $_POST['StockCat'] . "' 
			GROUP BY stockmaster.stockid, 
				stockmaster.description, 
				stockmaster.units 
			ORDER BY stockmaster.stockid";
	 }

	$ErrMsg = _('No stock items were returned by the SQL because');
	$DbgMsg = _('The SQL used to retrieve the searched parts was');
	$StockItemsResult = DB_query($SQL,$db, $ErrMsg, $DbgMsg);
}
/* Not appropriate really to restrict search by date since user may miss older ouststanding orders
	$OrdersAfterDate = Date("d/m/Y",Mktime(0,0,0,Date("m")-2,Date("d"),Date("Y")));
*/
if(isset($_GET['status']) and $_GET['status'] == "1")
  {  
  if(isset($_POST['Approved']))
      {
	     $sql='SELECT id FROM requisitionorderdetails WHERE requsitionno='."'".$_GET['RequisitionNo']."'"; 
		 $result=DB_query($sql,$db);
		 $i=1;
		 $reqid = $_POST['reqid'];
		 $totalRec = $_POST['record_count'];
		 for($ct = 1; $ct<$totalRec; $ct++) 
		   {
				   $quantity = $_POST['AppQut'.$ct];
				   $id = $_POST['productid'.$ct];
			 	$sql=" UPDATE requisitionorderdetails SET 
			 			App_quantity='$quantity', approved_date='".date('Y-m-d')."', status='1' WHERE id='$id' and requsitionno='$reqid' " ;
			$result=DB_query($sql, $db);
			if($result){
				header("Location: MR_SelectOSMaterialRequi.php?identifier=".$_REQUEST['identifier']."&status=1&RequisitionNo=".$reqid);
			}
			$i++;		  
		   }		  
	  }
       
  }
 
	
	//if (!isset($RequisitionNumber) or $RequisitionNumber!=''){

		echo '<p class="page_title_text"><img src="'.$rootpath.'/css/'.$theme.'/images/magnifier1.png" title="' . _('Search') . '" alt="">' . ' ' . $title;
?>

<?php 
if($_SESSION['frmAdd']=='1'){
?>		

<fieldset>
<div style="text-align:left; margin-top:10px; margin-bottom:5px;"><a href="index.php?route=MR_Header&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&NewRequisition=Yes"><input type="button" class="bottonsview" value="Add"/></a>&nbsp;&nbsp; <?php 
		//echo '<a href="' . $rootpath . '/MR_Header.php?' .SID . '&NewRequisition=Yes" class="bottonsview" onClick="showSlidingDiv(); return false;">' . _('Search') . '</a><br>';
		?></div><?php } ?>
		<br>
		
		<div class="centre" id="slidingDiv">
		<table width="100%" cellpadding="2" align="center" border="1" style="border-collapse:collapse;">
		<tr>
		<th><strong>REQUISITION NUMBER</strong></th>
		<td><input type="text" name="RequisitionNumber" style="width:100%" value="<?php echo $_POST['RequisitionNumber'];?>"></td>
		<th><strong>SITE</strong></th>
		<td><select name="StockLocation" style="width:100%">
		<option value="000">---Select Site---</option>
		<?php 
		$sql = 'SELECT loccode, locationname FROM locations';
		$resultStkLocs = DB_query($sql,$db);
		while($myrow=DB_fetch_array($resultStkLocs))
		{	$p='';
			if($_POST['StockLocation']==$myrow['loccode'])
			$p="selected";
			?>
			<option value="<?php echo $myrow['loccode'];?>"<?php echo $p;?>><?php echo $myrow['locationname'];?></option>
	<?php } ?>
		</select></td></tr>
   <tr>
   <th><strong>FROM</strong></th>
   <td class="demo"><input type="text" name="fromdate" class="datepicker" style="width:100%" value="<?php echo $_POST['fromdate'];?>"/></td>
   <th><strong>TO</strong></th>
   <td><input type="text" name="todate" style="width:100%"  class="datepicker"  value="<?php echo $_POST['todate'];?>"/></td>
  </tr>
</table>
<p align="center"><input type="submit" name="Search" VALUE="Search" class="bottonsview1"></p>
	</div>
	<?php
	//end if stock search results to show
	
		//figure out the SQL required from the inputs available
		if($_REQUEST['Search']) 
		{
				   $fordate = $_POST['fromdate'];
				   $todate = $_POST['todate'];
				   $fromdate = explode("/", $fordate);
				   $daydate = $fromdate['0'];
				   $Monthdate = $fromdate['1'];
				   $yeardate = $fromdate['2'];
					   
				   $fdate = $yeardate."-".$Monthdate."-".$daydate;
					   
				   $tredate   = explode("/", $todate);
				   $dayda     = $tredate['0'];
				   $Monthda   = $tredate['1'];
				   $yearda    = $tredate['2'];
				   $toyrdate  = $yearda."-".$Monthda."-".$dayda;
			
			$SQL="select * from materialrequisitions";
			$resultpaging_SQL="select * from materialrequisitions";
			
			$filter = array();
			if(isset($_POST['RequisitionNumber']) && $_POST['RequisitionNumber'] != '')
			$filter[]="Reqno LIKE '%".$_POST['RequisitionNumber']."%' ";
			if(isset($_POST['StockLocation']) && $_POST['StockLocation'] != '000')
			$filter[]="sitecode = '".$_POST['StockLocation']."' ";
			if(isset($_POST['fromdate']) && $_POST['fromdate'] != '' && isset($_POST['todate']) && $_POST['todate'] != '')
			$filter[]="prdate BETWEEN '".$fdate."' AND '".$toyrdate."' ";
			
			if($filter != '')
			{
				$SQL=$SQL." where ".implode(" and ",$filter);
			}
			//echo $SQL;
		} 
		else 
		{
		 	 $SQL="select * from materialrequisitions order by requisitionno desc";
			$resultpaging_SQL="select * from materialrequisitions order by requisitionno desc";
		} //end not order number selected
		$ErrMsg = _('No orders were returned by the SQL because');
		$purchordersResult = DB_query($SQL,$db,$ErrMsg);
		$resultpaging = DB_query($resultpaging_SQL,$db,$ErrMsg);
		/*show a table of the orders returned by the SQL */?>



	<table border="1" cellpadding="3" cellspacing="0" class="inborder" WIDTH=100% style="border-collapse:collapse;border:#000000 solid 1px">
	<tr>
	<th class="th_center"><strong>Site Code</strong></th>
	<th class="th_center"><strong>Site Name</strong></th>
	<th class="th_center"><strong>Purchase Requisition No</strong></th>
	<th class="th_center"><strong>Purchase Requisition Date</strong></th>
	<th class="th_center"><strong>Created by</strong></th>
	<th class="th_center"><strong>Vendor Quotation</strong></th>
	<th class="th_center"><strong>Comparative</strong></th>
	<th class="th_center"><strong>View</strong></th>
	<th class="th_center"><strong>Edit</strong></th>
	<th class="th_center"><strong>Delete</strong></th>
	<th class="th_center"><strong>Status</strong></th>
	<th class="th_center"><strong>Approved By</strong></th>
	<th class="th_center"><strong>Print</strong></th>
	</tr><?php
	$j = 1;
		$k=0; //row colour counter
		if(DB_num_rows($purchordersResult) > 0)
		{
		while ($myrow=DB_fetch_array($purchordersResult)) 
		{ ?>

			<tr bgcolor="#FFFFFF" onMouseOver="this.style.backgroundColor='#fffeb3'; this.style.color='#00f';" onMouseOut="this.style.backgroundColor='#FFF'; this.style.color='#000000';">
				<?php
			$ModifyPage = $rootpath . "/MR_Header.php?" . SID . "&ModifyRequisitionNumber=" . $myrow["requisitionno"];
			if ($myrow['status']==_('Printed')) {
				$ReceiveOrder = "<a href='".$rootpath . "/GoodsReceived.php?" . SID . "&MRNumber=" . $myrow["requisitionno"]."'>".
					_('Create Purchase Order').'</a>';
			} else {
				//$ReceiveOrder = "Create Purchase Order";
				$ReceiveOrder = "<a href='".$rootpath . "/PO_Header.php?" . SID . "&MRNumber=" . $myrow["requisitionno"]."&sitename=" . $myrow["requisition_site"]."&purchaseat=" . $myrow["intostocklocation"]."&reqdate=" . $myrow["prdate"]."&status=" . $myrow["status"]."&identifier=" .$identifier."'>".
					_('Create Purchase Order').'</a>';
			}
			if ($myrow["allowprint"]==1){
				$PrintPurchOrder = '<a target="_blank" href="' . $rootpath . '/MR_PDFMaterialRequisition.php?' . SID . '&RequisitionNo=' . $myrow['requisitionno'] . '">' . _('Print Now') . '</a>';
			} else {
	// not open yet
	//$PrintPurchOrder = '<font color=GREY>' . _('Printed') . '</font>';
	
			}
			if ($myrow['status']==_('Authorised')) {
				$PrintPurchOrder = '<a target="_blank" href="' . $rootpath . '/MR_PDFMaterialRequisition.php?' . SID . '&RequisitionNo=' . $myrow['requisitionno'] . '&realorderno=' . $myrow['realorderno'] . '&ViewingOnly=2">' . _('Print') . '</a>';
			} else {
				$PrintPurchOrder = 'Print';
			}
			$PrintPurchOrder2 = '<a target="_blank" href="' . $rootpath . '/MR_PDFMaterialRequisition.php?' . SID . '&RequisitionNo=' . $myrow['requisitionno'] . '&realorderno=' . $myrow['realorderno'] . '&ViewingOnly=1">' . _('Show') . '</a>';
			$s2 = '<a target="_blank" href="' . $rootpath . '/MR_PDFMaterialRequisition.php?' . SID . '&RequisitionNo=' . $myrow['requisitionno'] . '&realorderno=' . $myrow['realorderno'] . '&ViewingOnly=1">' . $myrow['realorderno']. '</a>';
	
			$FormatedOrderDate = ConvertSQLDate($myrow['orddate']);
			$FormatedOrderValue = number_format($myrow['ordervalue'],2);
		 	  $count=0;
		 	   $sql="SELECT status,requisitionno FROM materialrequisitions WHERE requisitionno='".$myrow['requisitionno']."'";
			$result=DB_query($sql,$db);
			$strow=DB_fetch_array($result);
			//echo "select App_quantity,AppQty from requisitionorderdetails where requsitionno='".$strow['requisitionno']."'";
			$sql1=DB_query("select requisition_qty,App_quantity,AppQty from requisitionorderdetails where requsitionno='".$strow['requisitionno']."'",$db);
			while($sqldv=DB_fetch_array($sql1))
			{
			
			
				if($sqldv['App_quantity']!='')
				{
			    $countdata=$countdata+1;	
			    }
				
				
				if($sqldv['App_quantity']>=$sqldv['requisition_qty'])
				{$App_Status='not allowed';}
				elseif($sqldv['App_quantity']<$sqldv['requisition_qty'])
				{$App_Status='allow';}
				/*if($sqldv['AppQty']!='0')
				{
				   
					 $App_Status='allow';
				
				}
			
			    else
			   {
			     $App_Status='not allowed';
			    }*/
				
				
			
			}
			
			//echo $App_Status;
		
			 $Status=$strow['status'];
			
			if($Status==1 )
			{
			   $chkstatus="select SUM(quatity) AS TOTALPOQty from purchorderdetails where mst_reqino= '".$myrow['requisitionno']."'";
			 "<br/>";
				$res_chkstatus = DB_query($chkstatus,$db);
			$CheckRow=	DB_fetch_array($res_chkstatus);
				 $CheckRow['TOTALPOQty'];
					$ReqQty=DB_query("SELECT SUM(requisition_qty) as requisition_qty FROM requisitionorderdetails where requsitionno='".$myrow['requisitionno']."'",$db);
				$ReqRow=DB_fetch_array($ReqQty);
				 $ReqRow['requisition_qty'];
			if($CheckRow['TOTALPOQty']==$ReqRow['requisition_qty'])
			{
			
			 $VenderQuotation = "PO Generated";
				$ComperitiveQuotation ="PO Generated";
				$modify="Not allowed";
				 $delete="Not allowed";
			}
			else
			{
			
			 $VenderQuotation = '<a href="index.php?route=VenderQutations&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].'&RequisitionNo=' . $myrow['requisitionno'] . '&vendorsearch=1">' . "<div align='center'><input type='button' class='bottonsview' value='Create'/> </div>". '</a>';
				$ComperitiveQuotation = '<a href="index.php?route=Comperitive&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].'&RequisitionNo=' . $myrow['requisitionno'] . '&ViewingOnly=1">' . "<div align='center'>  <input type='button' class='bottonsview' value='Create'/> </div>". '</a>';
				$modify="Not allowed";
				 $delete="Not allowed";
				
				}
				
				if($App_Status=='allow')
				{
				
				$Approved='<a href="' . $rootpath . '/index.php?route=MR_Header&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].'&RequisitionNo=' . $myrow['requisitionno'] . '&Approve=1">' . "<div align='center'>  <input type='button' class='bottonsview' value='Pending'/> </div>". '</a>';
				
				}
				if($App_Status=='not allowed')
				{
			    $Approved="Approved";
				}
				
			
			}
			else
			{
			 $VenderQuotation =" Requisition <br>Not Approved"; 
			$ComperitiveQuotation ="Requisition <br> Not Approved";
			 $Approved='<a href="' . $rootpath . '/index.php?route=MR_Header&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].'&RequisitionNo=' . $myrow['requisitionno'] . '&Approve=1">' . "<div align='center'>  <input type='button' class='bottonsview' value='Pending'/> </div>". '</a>';
			  $modify= '<a href="index.php?route=MR_Edit_Header&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].'&RequisitionNo='.$myrow['requisitionno'].'&update=1">'."<img src='images/icon-edit.png' width='15' height='15'>".'</a>'; 
			   $delete = '<a href="index.php?route=MR_Header&' . SID . '&RequisitionNo=' . $myrow['requisitionno'].$rurl .'&Delete=1" onclick="show()")">' . "<input type='button' class='bottonsview' value='Delete'/>". '</a>';
			
			}
			
			
			
			
			
			
			
			/* $Status=$strow['status'];
			
		if($Status==1)
			{
			
			 if($App_Status=1)
			 {
	        	$VenderQuotation = '<a href="index.php?route=VenderQutations&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].'&RequisitionNo=' . $myrow['requisitionno'] . '&vendorsearch=1">' . "<div align='center'>Create </div>". '</a>';
				$ComperitiveQuotation = '<a href="index.php?route=Comperitive&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].'&RequisitionNo=' . $myrow['requisitionno'] . '&ViewingOnly=1">' . "<div align='center'>  Create </div>". '</a>';
				}
				else
				{
				
				}
				 $delete="NO permission";
				 if($App_Status==1)
				 {
				 $Approved="Approved";
				
				}
				else
				{
				 $Approved='<a href="' . $rootpath . '/index.php?route=MR_Header&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].'&RequisitionNo=' . $myrow['requisitionno'] . '&Approve=1">' . "<div align='center'>  Pending </div>". '</a>';
				
				}
				if($countdata>0)
				{
				$modify="NO Permission";
				}
               else
               {
				$modify="Edit";
			   }*/
				
			// WHEN PO ALREADY GENRATED
			//	echo "<br>------------------------------<br>";
  				   /* $chkstatus="select * from purchorders where mst_reqino= '".$myrow['requisitionno']."' and mst_comperitive in(select comprative_id from comprative_detail where RequisitionNo= '".$myrow['requisitionno']."' and status_active='1' ) ";
				$res_chkstatus = DB_query($chkstatus,$db);
				if(DB_num_rows($res_chkstatus)>0)
				{
							//$ComperitiveQuotation ="PO Proceed";
							$ComperitiveQuotation = '<a href="index.php?route=Comperitive&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].'&RequisitionNo=' . $myrow['requisitionno'] . '&ViewingOnly=1">' . "<div align='center'>  Create </div>". '</a>';
							
							$VenderQuotation = '<a href="index.php?route=VenderQutations&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].'&RequisitionNo=' . $myrow['requisitionno'] . '&vendorsearch=1">' . "<div align='center'>Create </div>". '</a>';
							//$VenderQuotation ="PO Proceed"; 
						  
						   $delete='PO Proceed';
				}
				else{
					$ComperitiveQuotation = '<a href="index.php?route=Comperitive&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].'&RequisitionNo=' . $myrow['requisitionno'] . '&ViewingOnly=1">' . "<div align='center'>  Create </div>". '</a>';*/
						//$modify= '<a href="index.php?route=MR_Edit_Header&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].'&RequisitionNo='.$myrow['requisitionno'].'&update=1">'."<img src='images/icon-edit.png' width='15' height='15'>".'</a>'; 
						/*$VenderQuotation = '<a href="index.php?route=VenderQutations&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].'&RequisitionNo=' . $myrow['requisitionno'] . '&vendorsearch=1">' . "<div align='center'>Create </div>". '</a>';
				    }
			
	 
			  }*/
			/* else
			{
			
			
			
			$VenderQuotation = '<a href="index.php?route=VenderQutations&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].'&RequisitionNo=' . $myrow['requisitionno'] . '&vendorsearch=1">' . "<div align='center'>Create </div>". '</a>';
				$ComperitiveQuotation = '<a href="index.php?route=Comperitive&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].'&RequisitionNo=' . $myrow['requisitionno'] . '&ViewingOnly=1">' . "<div align='center'>  Create </div>". '</a>';
				 $modify="NO Permission";
				// $delete='<a href="index.php?route=MR_Header&' . SID .'&RequisitionNo=' . $myrow['requisitionno'].$rurl. '&Delete=1" onclick="return confirm("Are You Sure You Want To Delete This Record?")">' . " Delete" . '</a>';
				 $delete="NO permission";
				 $Approved='<a href="' . $rootpath . '/index.php?route=MR_Header&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].'&RequisitionNo=' . $myrow['requisitionno'] . '&Approve=1">' . "<div align='center'>  Pending </div>". '</a>';
			
		
		 
		 
		 
		 
		    $VenderQuotation =" Requisition <br>Not Approved"; 
				 $ComperitiveQuotation ="Requisition <br> Not Approved";
				 $modify= '<a href="index.php?route=MR_Edit_Header&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].'&RequisitionNo='.$myrow['requisitionno'].'&update=1">'."<img src='images/icon-edit.png' width='15' height='15'>".'</a>'; 
				// $delete='<a href="index.php?route=MR_Header&' . SID .'&RequisitionNo=' . $myrow['requisitionno'].$rurl. '&Delete=1" onclick="return confirm("Are You Sure You Want To Delete This Record?")">' . " Delete" . '</a>';
				 $delete = '<a href="index.php?route=MR_Header&' . SID . '&RequisitionNo=' . $myrow['requisitionno'].$rurl .'&Delete=1" onclick="show()")">' . "Delete". '</a>';
				 $Approved='<a href="' . $rootpath . '/index.php?route=MR_Header&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].'&RequisitionNo=' . $myrow['requisitionno'] . '&Approve=1">' . "<div align='center'>  Pending </div>". '</a>';
		
		 
		 
			   }*/
			$RequisitionNo=$myrow["requisitionno"];
			$ModifyOrderNumber=$myrow["requisition_site"];
	
	$site_sql=DB_query("Select locationname from locations where loccode='".$myrow['sitecode']."'",$db);
	$site_row=DB_fetch_array($site_sql);
	?>
	<td><?php echo $myrow['sitecode'];?></td>
	<td><?php echo $site_row['locationname'];?></td>
	<td><?php echo $myrow['Reqno'];?></td>
	<td><?php echo ConvertSQLDate($myrow['prdate']);?></td>
	<td><?php echo	$username=$s->getField('www_users','id',$myrow['initiator'],'realname');	 ?></td>
	<td><?php if($_SESSION['vendorquotAdd']=='1'){echo $VenderQuotation;} else {echo "Not allowed";}?></td>
	<td><?php echo $ComperitiveQuotation;  ?></td>
	<td><?php if($_SESSION['frmView']=='1'){?><a href='index.php?route=MR_View&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&RequisitionNo=<?php echo $RequisitionNo;?>'><img src="images/search.gif" width="15" height="15"></a><?php } else {echo "Not allowed";}?></td>
	<td><?php if($_SESSION['frmEdit']=='1'){echo $modify;} else {echo "Not allowed";}?></td>
	<td> 
<!--	<a href="index.php?route=MR_Header&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&RequisitionNo=<?php echo $myrow['requisitionno'];?>&Delete=1" onclick="return confirm('This requisition will be deleted')"> Delete
	</a>-->
	<?php echo $delete;?>
	 </td>
	<td><?php echo $_SESSION['ACG_RoleApproval_Permission']=='Y'?$Approved:'Not allowed';?>
	</td>
	<td><?php echo $s->getField('www_users','id',$myrow['approved_by'],'realname');?></td>
	<td><a href="MR_View_Print.php?RequisitionNo=<?php echo $myrow['requisitionno'];?>" class="bottonsview" target="_blank"><input type='button' class='bottonsview' value='Print'/></a>
	</td>
	</tr>


	<?php
			If ($j == 12){
				$j=1;
				 echo $TableHeader;
			}
		//end of page full new headings if
		}
		}
		else
		{?>
			<tr>
					<td colspan="13"><font color="#FF0000"><h2 align="center">No Record</h2></font></td>
	</tr>
		<?php }
		?>
		</p></table>		
		
		 
		
		      
</fieldset>
<?php
 
include('includes/footer.inc');
?>
