<link rel="stylesheet" href="css/new_mxerp.css">
<?php session_name('CAKEPHP'); session_start();
$PageSecurity = 2;
if (empty($_GET['identifier'])) {
			 $identifier=date('U');
		} else {
			$identifier=$_GET['identifier'];
		}
$title = _('Material Receipt Note');
$_SESSION['modid']=$_REQUEST['modid'];
$_SESSION['frmid']=$_REQUEST['frmid'];
$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];
?>
<script src="js/jsapi.js" type="text/javascript">
</script>
<script type="text/javascript">
google.load("jquery", "1"); 
</script>
<style>
#slidingDiv {
    display: none;
	height:100px;
	background-color: #D9D6DA;
	padding:20px;
}
</style>
<?php
	$type="paging";
	$rowsPerPage = 10;
	$pageNum = 1;
	if(isset($_GET['page']))
	{
		$pageNum = $_GET['page'];
	}
	$offset = ($pageNum - 1) * $rowsPerPage;

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']);
}


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

$urldata="route=MaterialReceiptNote&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($_GET['orderno']) && isset($_GET['orderno'])!='' && isset($_GET['DeleteOnly']) ==1 && isset($_GET['mrnid']) !='')
 {
$sql = 'Delete From addmrn Where id='.$_GET['mrnid'].'';
$Delresult = DB_query($sql,$db);
$Delsql = 'Delete From addmrnqty Where issue_id ='.$_GET['mrnid'].'';
$issuedelresult = DB_query($Delsql,$db);
$chargedelete="delete from mrn_charges where MRN_id='".$_GET['mrnid']."'";
$charge_res=DB_query($chargedelete,$db);

$poqty_sql="Delete from po_quantity where orderno='".$_GET['orderno']."' ";
$poqty_res=DB_query($poqty_sql,$db);
echo "<script>location.href='index.php?route=MaterialReceiptNote&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
prnMsg(_('MaterialReceiptNote Number') . '  ' . $_GET['mrnid'] . ' ' . _('has been Deleted') ,'success');
}
?>

<div class="body_contain">
<div class="tab_div">

<?php

if ($_SESSION['UserStockLocation'] == $_SESSION['UserStockLocation'])
  {
	if (!isset($RequisitionNumber) or $RequisitionNumber==''){
	
		echo '<h1>' . ' ' . $title.'</h1>';
?>		

<?php if($_SESSION['frmAdd']=='1'){?>
<a href="index.php?route=AddMRN&NewOrder=Yes&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>">ADD NEW</a><?php }?>




<div id="container">
<script type="text/javascript">
function showSlidingDiv(){
$("#slidingDiv").animate({"height": "toggle"}, { duration: 700 });
}
</script>
<div align="center"><a href="#" onClick="showSlidingDiv(); return false;">SEARCH</a></div>
<div id="slidingDiv" class="centre">
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
  <tr class="row1"><td class="tabledata1">MRN Number</td>
    <td><input type="text" name="MRnumber"  style="width:50%" /></td>
	 <td class="tabledata1">Site</td>
    <td> <select name="StockLocation"> 
	<option  value="000">Select Site</option>
		<?php 
		$sql = "SELECT loccode, locationname FROM locations";
		$resultStkLocs = DB_query($sql,$db);
		while ($myrow=DB_fetch_array($resultStkLocs)){
 				echo '<option Value="' . $myrow['loccode'] . '">' . $myrow['locationname'].'</option>';
 		}
}
	?> </select></td></tr>
	
	<tr class="row1">
	<td class="tabledata1">From Date</td>
	<td><input type="text" name="fromdate" class="datepicker"  style="width:50%" /></td>
	<td class="tabledata1">To Date</td>
	<td><input type="text" name="todate" class="datepicker"  style="width:90%"  /></td>
	</tr>
  <tr class="row1">
    <td class="tabledata1">Vendor</td>
    <td>
		<select name="vendor" id="vendor" style="width:50%">
		<option value="000">---Select Vendor---</option>
		<?php 
		$vendor_sql=DB_query("Select vendor_code,vendor_name from suppliers",$db);
		while($vendor_res=DB_fetch_array($vendor_sql))
		{?>
		<option value="<?php echo $vendor_res['vendor_code'];?>"><?php echo $vendor_res['vendor_name'];?></option>
		<?php } ?>
		</select>
	</td>

    <td class="tabledata1">Client</td>
    <td><select name="client" id="client">
		<option value="000">---Select Client---</option>
		<?php 
		$client_sql=DB_query("Select client_code,c_name from clientmaster",$db);
		while($client_res=DB_fetch_array($client_sql))
		{?>
		<option value="<?php echo $client_res['client_code'];?>"><?php echo $client_res['c_name'];?></option>
		<?php } ?>
		</select></td>
  </tr>

    

</table>
  <p align="left" style="padding-left:10px;"><input name="Search" type="submit" value="Search" /></p>
	</div>
	<br />
	<br />
	<?php
if(isset($_POST['Search']))
{
 
	$filter=array();
	$MRnumber=$_POST['MRnumber'];
	$StockLocation=$_POST['StockLocation'];
	$fromdate=ConvertSQLDate($_POST['fromdate']);;
	$todate=ConvertSQLDate($_POST['todate']); 
	if($MRnumber!='')
	{
	   $filter[]="MRNNo  like '%".$MRnumber."'";
	}
	
	if($StockLocation!='0')
	{
	   $filter[]="OrderFromSite   ='".$StockLocation."'";
	}
	
	if($fromdate!='//' ||$todate!='//')
	{
	   $filter[]="MRNDate BETWEEN '".$fromdate."' AND '".$todate."'";
	}
	
	if($_POST['vendor']!='000')
	{
		$filter[]="ReceivedFrom   ='".$_POST['vendor']."'";
	}
	if($_POST['pc']!='000')
	{
		$filter[]="ReceivedFrom   ='".$_POST['pc']."'";
	}
	if($_POST['client']!='000')
	{
		$filter[]="ReceivedFrom   ='".$_POST['client']."'";
	}
	
	if( isset($filter))
	{
 			if(count($filter)>0)
			{
	  		$filter1=implode(" and	 ",$filter);
			}else{
			$filter1="1=1";
			}
 	 $SQL = "Select * from addmrn
			 		 Where CompanyId='".$_SESSION['ACGCompanyId']."' and $filter1 ORDER BY MRNNo ASC";
 			 $resultpaging_SQL = "Select MRNNo, MRNDate, OrderFromSite, StoreName, ReceivedAgainst, createdby from addmrn
			 		 			  Where $filter1 ORDER BY MRNNo ASC ";
 	}
	}	
else 
{   
 $SQL = "SELECT * FROM addmrn  where CompanyId='".$_SESSION['ACGCompanyId']."' order by id DESC ";
 $resultpaging_SQL = "Select MRNNo, MRNDate, OrderFromSite, StoreName, ReceivedAgainst, createdby from addmrn
					  Where 1=1 ORDER BY MRNNo ASC ";}
		 
		//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 */
	?>
	<div style="width:810px; overflow:auto; margin-left:auto; margin-right:auto;">
	
		<table cellpadding="3" cellspacing="0" WIDTH="100%" border="1">
		<tr>
		<td class="tabledata">MRN No</th>
		<td class="tabledata">MRN Date</th>
		<td class="tabledata">Site</th>
		<td class="tabledata">Challan/Bill</th>
		<td class="tabledata">No.</th>
		<td class="tabledata">Received Against</th>
		<td class="tabledata">Created by</th>
		<td class="tabledata">View</th>
		<td class="tabledata">Edit</th>
		<td class="tabledata">Delete</th>
		</tr>
		<?php 
		$j = 1;$i=1;
		$k=0;
		if(DB_num_rows($purchordersResult)>0){
		while ($myrow=DB_fetch_array($purchordersResult)) 
		{
			if ($k==1){/*alternate bgcolour of row for highlighting */ ?>
				<tr class="EvenTableRows">
			<?php	$k=0;
			} else {?>
				<tr class="OddTableRows">
		<?php 		$k++;
			}
			$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";
				$modification = '<a href="index.php?route=view_MRN&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].'&Type='. $myrow['Type'].'&ModfingOnly=1&mrnid='.$myrow['id'].'">' . "Edit". '</a>';
				$view = '<a href="index.php?route=MR_View_MRN&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].'&ViewingOnly=1&mrnid='.$myrow['id'].'">' . "View". '</a>';
				$delete = '<a href="' . $rootpath . '/MaterialReceiptNote.php?' . SID . '&orderno=' . $myrow['order_no'] .'&DeleteOnly=1&mrnid='.$myrow['id'].'" onclick="return confirm("Are You Sure You Want To Delete This Record?")">' . "Delete". '</a>';
			}
			if ($myrow["allowprint"]==1){
				$PrintPurchOrder = '<a target="_blank" href="' . $rootpath . '/MR_PDFMaterialRequisition.php?' . SID . '&RequisitionNo=' . $myrow['requisitionno'] . ' ">' . _('Print Now') . '</a>';
			} else {
			}
			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';
			}
			$site_query=DB_query("Select locationname from locations where loccode='".$myrow['OrderFromSite']."'",$db);
			$site_row=DB_fetch_array($site_query);
		?>
<tr bgcolor="#c1c1c1">
			<td><?php echo $myrow['MRNNo'];?></td>
			<td><?php echo ConvertSQLDate($myrow['MRNDate']);?></td>
			<td><?php echo $site_row['locationname'];?></td>
			<td><?php echo $myrow['DocumentType'];?></td>
			<td><?php echo $myrow['BillNo'];?></td>
			<td><?php echo $myrow['ReceivedAgainst'];?></td>
			<td><?php echo $myrow['createdby'];?></td>
			<td width="4%"><?php if($_SESSION['frmView']=='1'){echo $view;}else{echo "No Permission";}?></td>
			<td width="4%"><?php if($_SESSION['frmEdit']=='1'){echo $modification;}else{echo "No Permission";}?></td>
			<td width="6%"><?php if($_SESSION['frmDelete']=='1'){?><a href="index.php?route=MaterialReceiptNote&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&orderno=<?php echo $myrow['order_no'];?>&DeleteOnly=1&mrnid=<?php echo $myrow['id'];?>" onclick="return confirm('Are You Sure You Want To Delete This Record?')">Delete</a><?php }else{echo "No Permission";}?></td>
			</tr>
			<?php 
			$j++;
			If ($j == 12){
				$j=1;
				 echo $TableHeader;
			}
		//end of page full new headings if
		}
		}
		else
		{?>
		<tr>
		<td colspan="10"><h4 align="center"><strong><font color="#FF0000">No Record Found!</font></strong></h4></td>
		</tr>	
		<?php }
		//end of while loop ?>
		</table>
		
	</div>

	<input type="hidden" name="ReqNo" value="<?php echo $_POST['ShowRequisition'];?>">
	<?php 
	echo "<script>defaultControl(document.forms[0].StockCode);</script>"; ?>
	</form>
<?php 
}
else 
{
	$urldata="route=MaterialReceiptNote&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 ($_POST['Keywords']) {
				//insert wildcard characters in spaces
		//	$completed = "purchorderdetails.completed=0 AND ";
				$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.quantityord-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.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 
					AND 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);
		}
	
			echo '<p class="page_title_text"><img src="'.$rootpath.'/css/'.$theme.'/images/magnifier.png" title="' . _('Search') . '" alt="">' . ' ' . $title;
			echo '<br><br>&nbsp;&nbsp;<a href="' . $rootpath . '/MR_Header.php?' .SID . '&NewOrder=Yes">' . _('Add Puchase Requisition') . '</a>';
			echo '<div class="centre">'._('Puchase Requisition number') . ': <input type=text name="RequisitionNumber" MAXLENGTH =8 size=9>  ' . _('Into Site') . ':<select name="StockLocation"> ';
			$sql = 'SELECT locationname FROM locations WHERE loccode='."'$_SESSION[UserStockLocation]'".';';
			$resultStkLocs = DB_query($sql,$db);
			while ($myrow=DB_fetch_array($resultStkLocs)){
		if (isset($_POST['StockLocation'])){
			if ($myrow['loccode'] == $_POST['StockLocation']){
				echo '<option selected Value="' . $myrow['loccode'] . '">' . $myrow['locationname'];
			} else {
				echo '<option Value="' . $myrow['loccode'] . '">' . $myrow['locationname'];
			}
		} elseif ($myrow['loccode']== $_SESSION['UserStockLocation']){
			echo '<option selected Value="' . $myrow['loccode'] . '">' . $myrow['locationname'];
		} else {
			echo '<option Value="' . $myrow['loccode'] . '">' . $myrow['locationname'];
		}
	}
		echo '</select>  <input type=submit name="SearchOrders" VALUE="' . _('Search Puchase Requisition') . '"></div>';
				
	$SQL='SELECT categoryid, categorydescription FROM stockcategory ORDER BY categorydescription';
	$result1 = DB_query($SQL,$db);
	
	?>
<hr />
<br>
	<br>
	<?php
	
	if (isset($StockItemsResult)) {
	
		echo '<table cellpadding=2 colspan=7 BORDER=2>';
		$TableHeader = 	'<tr><th>' . _('Code') . '</th>
				<th>' . _('Description') . '</th>
				<th>' . _('On Hand') . '</th>
				<th>' . _('Orders') . '<br>' . _('Outstanding') . '</th>
				<th>' . _('Units') . '</th>
				</tr>';
		echo $TableHeader;
		$j = 1;
		$k=0; //row colour counter
	
		while ($myrow=DB_fetch_array($StockItemsResult)) {
	
			if ($k==1){
				echo '<tr class="EvenTableRows">';
				$k=0;
			} else {
				echo '<tr class="OddTableRows">';
				$k=1;
			}
	
			printf("<td><input type=submit name='SelectedStockItem' VALUE='%s'</td>
					<td>%s</td>
				<td align=right>%s</td>
				<td align=right>%s</td>
				<td>%s</td></tr>",
				$myrow['stockid'],
				$myrow['description'],
				$myrow['qoh'],
				$myrow['qord'],
				$myrow['units']);
	
			$j++;
			If ($j == 12){
				$j=1;
				echo $TableHeader;
			}
	//end of page full new headings if
		}
	//end of while loop
	
		echo '</table>';
	
	}	
	//end if stock search results to show
	else 
	{
		//figure out the SQL required from the inputs available
	$completed = " AND purchorderdetails.completed=0";
		if (isset($RequisitionNumber) && $RequisitionNumber !='') 
		{
				$SQL = 'SELECT * FROM addmrn';
		} 
		else if (isset($SelectedSupplier)) 
		{
				if (!isset($_POST['StockLocation'])) 
				{
					$_POST['StockLocation']='';
				}
				
				if (isset($SelectedStockItem)) 
				{
				$SQL = 'SELECT * FROM addmrn';
				} else 
				{
					$SQL = 'SELECT * FROM addmrn';
				}
			} 
			else 
			{ //no supplier selected
				if (!isset($_POST['StockLocation'])) {$_POST['StockLocation']='';
				}
				if (isset($SelectedStockItem) and isset($_POST['StockLocation'])) {
					$SQL = 'SELECT * FROM addmrn';
				} 
				else 
				{
				$SQL = 'SELECT * FROM addmrn';
				}
			} //end selected supplier
		} //end not order number selected
		$ErrMsg = _('No orders were returned by the SQL because');
		$PurchOrdersResult = DB_query($SQL,$db,$ErrMsg);
	
		/*show a table of the orders returned by the SQL */
	
		echo '<table cellpadding=2 colspan=7 WIDTH=100%>';
	
	//	               '</td><td class="tableheader">' . _('Receive') .	
		$TableHeader = '<tr><th>' . _('Site Name') .
		        '</th><th>' . _('Purchase Req. No.') .
				'</th><th>' . _('Purchase Req. Date') .
				'</th><th>' . _('Purchase At') .
				'</th><th>' . _('Created by') .
				'</th><th>' . _('Create Vendor Quotation') .
				'</th><th>' . _('Create Comperitive Quotation') .
		'</th></tr>';
	
		echo $TableHeader;
		$j = 1;
		$k=0; //row colour counter
		while ($myrow=DB_fetch_array($PurchOrdersResult)) {
	
	
			if ($k==1){ /*alternate bgcolour of row for highlighting */
				echo '<tr class="EvenTableRows">';
				$k=0;
			} else {
				echo '<tr class="OddTableRows">';
				$k++;
			}
	
			$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 . '&RequisitionNumber=' . $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 . '/PO_PDFPurchOrder.php?' . SID . '&OrderNo=' . $myrow['orderno'] . '&realorderno=' . $myrow['realorderno'] . '&ViewingOnly=2">' . _('Print') . '</a>';
			} else {
				$PrintPurchOrder = 'Print';
			}
			$PrintPurchOrder2 = '<a target="_blank" href="' . $rootpath . '/PO_PDFPurchOrder.php?' . SID . '&OrderNo=' . $myrow['orderno'] . '&realorderno=' . $myrow['realorderno'] . '&ViewingOnly=1">' . _('Show') . '</a>';
			$s2 = '<a target="_blank" href="' . $rootpath . '/PO_PDFPurchOrder.php?' . SID . '&OrderNo=' . $myrow['orderno'] . '&realorderno=' . $myrow['realorderno'] . '&ViewingOnly=1">' . $myrow['realorderno']. '</a>';
	
			$FormatedOrderDate = ConvertSQLDate($myrow['orddate']);
			$FormatedOrderValue = number_format($myrow['ordervalue'],2);
	        $VenderQuotation = '<a href="' . $rootpath . '/VenderQutations.php?' . SID . '&RequisitionNo=' . $myrow['requisitionno'] . '&ViewingOnly=1">' . "Create Vendor Quotation". '</a>';
			$ComperitiveQuotation = '<a href="' . $rootpath . '/Comperitive.php?' . SID . '&RequisitionNo=' . $myrow['requisitionno'] . '&ViewingOnly=1">' . "Create Comperitive Quotation". '</a>';
			$RequisitionNo=$myrow["requisitionno"];
	// the tailed two column
	//			<td>%s</font></td>
	//			<td align=right>%s</font></td>
	//			$myrow['requisitionno'],	
	//			$myrow['initiator']);
	//			'</td><td class="tableheader">' . _('Requisition') .
	//			'</td><td class="tableheader">' . _('Initiator') .	               		
	//		        <td><a href='%s'>" . _('Receive') . "</a></td>			
			printf("<td><input type=submit name='ShowRequisition' value='%s'></td>
				<td>%s</td>
				<td>%s</td>
				<td>%s</td>
				<td>%s</font></td>
				<td>%s</font></td>
				<td>%s</font></td>
				</tr>",
				$RequisitionNo,						
				ConvertSQLDate($myrow['req_date']),
				$myrow['requisition_site'],	
				$myrow['intostocklocation'],		
				$myrow['initiator'],			
				$VenderQuotation,
				$ComperitiveQuotation
				);
	
			$j++;
			If ($j == 12){
				$j=1;
				 echo $TableHeader;
			}
		//end of page full new headings if
		}
		//end of while loop
	
							
	}
	
					$rows = DB_num_rows($resultpaging);
					$maxPage = ceil($rows/$rowsPerPage);
					$self = $_SERVER['PHP_SELF'];
					$nav  = '';
				     for($page = 1; $page <= $maxPage; $page++)
				     {
					if ($page == $pageNum)
					{
						$nav .= " $page "; 
					}
					else
					{
					   $nav .= " <a href=\"$self?page=$page\" class=\"gllink\">$page</a> ";
					} 
				}
				if ($pageNum > 1)
				{
					$page  = $pageNum - 1;
					echo $first = " <a href=\"$self?page=1\" class=\"gllink\">[First Page]</a> ";
					echo $prev  = " <a href=\"$self?page=$page\" class=\"gllink\">[Prev]</a> ";
				} 
				else
				{
				  echo $prev  = "&nbsp;"; 
				  echo $first = "&nbsp;";
				}
				if ($pageNum < $maxPage)
				{
					$page = $pageNum + 1;
					echo $next = " <a href=\"$self?page=$page\" class=\"gllink\">[Next]</a>";
					echo $last = " <a href=\"$self?page=$maxPage\" class=\"gllink\">[Last Page]</a>";
				} 
				else
				{
				   echo $next = "&nbsp;";
				   echo $last = "&nbsp;"; 
				}
		
	echo '<input type="hidden" name="ReqNo" value="'.$_POST['ShowRequisition'].'">';
	echo "<script>defaultControl(document.forms[0].StockCode);</script>";
	echo '</table>';
	echo '</div></div>';
	echo '</form>';
  
//include('includes/footer.inc');
?>
<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>
$(function() {
$(".datepicker").datepicker({ dateFormat: 'dd/mm/yy' ,changeMonth: true,
		changeYear: true,
		yearRange: '-80:+20'});
});
</script>