<?php

session_start();
if($_SESSION['dbName']==""){
header("location:../index.php");
}


include("config.inc.php");
set_time_limit(0);

$connection = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass']) or die("Could not connect to DB");
mysql_select_db($_SESSION['dbName'],$connection) or die("Could not find DB");

$querylog=" select ifNull(FI_DeliveryApp,0) As FI_DeliveryApp, ifNull(login_belongstogrp,0) As FI_BelongsToGrp, ifNull(FI_DeliverySalesPrice,0) As FI_DeliverySalesPrice, ".
		  " ifNull(FI_sorderconfirmed,0) As FI_SalesOrderConfirm, ifNull(login_disapprovesorder,0) As Login_DisapproveSorder, ifNull(FI_FrmRestrictWarehouse,0) As FI_FrmRestrictWarehouse, ".
          " ifnull(FI_TransferRequest,0) as FI_TransferRequest, ifnull(FI_StockOutRequest,0) as FI_StockOutRequest
		  ,ifnull(PorderApproved_Level,50) As PurorderApproved_Level  ".
          " ,ifnull(PrequestApproved_Level,50) As PrequestApproved_Level  ".
          " ,ifnull(TransferRequestApproved_Level,50) As TransferRequestApproved_Level  ".
          " ,ifnull(AdjustmentRequestApproved_Level,50) As AdjustmentRequestApproved_Level  ".
		  " ,ifnull(0,0) fi_pendingpurchaserequest".
		  " ,ifnull(fi_pendingtransferrequest,0) fi_pendingtransferrequest".
		  " ,ifnull(0,0) fi_pendingadjustmentrequest".
		  " ,ifnull(0,0) fi_pendingpaymentrequest".
		  " ,ifnull(0,0) fi_pendingpurchaseorder, ".
		  " ifNull(Login_PReqApprove,0) As Login_PReqApprove, ifNull(Login_PReqReject,0) As Login_PReqReject, ifNull(Login_PReqUndProc,0) As Login_PReqUndProc, ".
		  " ifNull(Login_POrdApprove,0) As Login_POrdApprove, ifNull(Login_POrdReject,0) As Login_POrdReject, ".
		  " ifNull(Login_TReqApprove,0) As Login_TReqApprove, ifNull(Login_TReqReject,0) As Login_TReqReject, ".
		  " ifNull(Login_AReqApprove,0) As Login_AReqApprove, ifNull(Login_AReqReject,0) As Login_AReqReject, ifNull(FI_PRequestConfirmed,0) As FI_PRequestConfirmed, ".
		  " PR_status1,PR_status2,PR_status3,PR_status4,PR_status5,PR_status6,PR_status7,PR_status8,PR_status9,PR_status10,PR_status11,PR_status12,PR_status13,PR_default,PO_default,TR_default,AD_default, PYR_default, ".
		  " TR_status1,TR_status2,TR_status3,AD_status1,AD_status2,AD_status3,PO_status1,PO_status2,PO_status3,PO_status4,PO_status5,PO_status6,PO_status7, ifNull(FI_PorderConfirmed,0) As FI_PorderConfirmed, ".
		  " PYR_status1,PYR_status2,PYR_status3,ifnull(PaymentRqstApproved_Level,50) As PaymentRqstApproved_Level, ifNull(Branch_Manager,0) as Branch_Manager,FI_ItemsApp ".
		  " from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' and Upper(Login_Schema) = Upper('".$_SESSION['dbName']."')  ";

$resultlog=mysql_query($querylog,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultlog)){
	extract($rows);
}

$EditHint = '';
$EditMode = '';

$querysetup="select DecimalBase, DecimalBase1, DecimalBase2, base1, base2, grid_color1, grid_color2, ifNull(Setup_VatPercentage,0) As Setup_VatPercentage from setup";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
	extract($rowsetup);
}



$querydflwh="select warehouse_code as defaultwarehouse from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."' and ifNull(default_warehouse,0) = 1 ";

$resultdflwh=mysql_query($querydflwh,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultdflwh)){
  extract($rows);
}

if($defaultwarehouse == ''){
	$q = "select warehouse from purchasesetup;";
			$rs = mysql_query($q,$connection); 
			$rw = mysql_fetch_row($rs);
			$defaultwarehouse = $rw[0];
}

//Read From Module Table
$querymodule=" Select ifNull(Module_AdditionalTaxes,0) As Module_AdditionalTaxes, ifNull(Module_Pack,0) As Module_Pack, ".
			 " ifNull(Module_Project,0) As Module_Project, ifNull(Module_Costcenter,0) As Module_CostCenter, ".
			 " ifNull(Module_RestrictProjCost,0) As Module_RestrictProjCost, ifNull(Module_RestrictCost,0) As Module_RestrictCost, ".
			 " ifNull(Module_ProjectDt,0) As Module_ProjectDt, ifNull(Module_CostCenterDt,0) As Module_CostCenterDt, ".
			 " ifNull(Module_PRequestConfirm,0) As Module_PRequestConfirm, ifNull(Module_DoubleUnit,0) As Module_DoubleUnit, ifNull(Module_Unit1Method,0) As Module_Unit1Method, ".
			 " ifnull(Module_PurchaseRequestPrice,0) as Module_PurchaseRequestPrice, ifNull(Module_Grn,0) as Module_Grn, ".
			 " ifnull(Module_PrintApprovedRqst,0) as Module_PrintApprovedRqst, ifNull(Module_PorderConfirm,0) As Module_PorderConfirm, ".
			 " ifNull(Module_PaymentLimit,0) as Module_PaymentLimit,module_CheckItem,module_pendingprocess as PendingProcess,PrequestReferenceByProject as RefProject ".
			 " From Module ";
$resultmodule=mysql_query($querymodule,$connection) or die(mysql_error());
while($rowmodule=mysql_fetch_array($resultmodule)){
	extract($rowmodule);
}


//Read From SalesSetup Table
$querySalesSetup="Select Warehouse As SetupDftWareHouse, ifNull(ShowCostCentLayout,0) As ShowCostCentLayout_Purchase, PurchaseTTC From PurchaseSetup";
$resultSalesSetup=mysql_query($querySalesSetup,$connection) or die(mysql_error());
while($rowSalesSetup=mysql_fetch_array($resultSalesSetup)){
	extract($rowSalesSetup);
}


//Read From AdjustmentSetup Table
$queryAdjustSetup="Select ifNull(ShowCostCentLayout,0) As ShowCostCentLayout_Adjustment From AdjustmentSetup ";
$resultAdjustSetup=mysql_query($queryAdjustSetup,$connection) or die(mysql_error());
while($rowAdjustSetup=mysql_fetch_array($resultAdjustSetup)){
	extract($rowAdjustSetup);
}

//Read From TransferSetup Table
$queryTrSetup="Select ifNull(ShowCostCentLayout,0) As ShowCostCentLayout_Transfer From TransferSetup ";
$resultTrSetup=mysql_query($queryTrSetup,$connection) or die(mysql_error());
while($rowAdjustSetup=mysql_fetch_array($resultTrSetup)){
	extract($rowAdjustSetup);
}



//Read From SalesSetup Table
$querySalesSetup="Select SalesTTC, ifNull(Sale_MinPendingQty,0) As Sale_MinPendingQty, ifNull(Sale_MaxExceedQty,0) As Sale_MaxExceedQty From SalesSetup";
$resultSalesSetup=mysql_query($querySalesSetup,$connection) or die(mysql_error());
while($rowSalesSetup=mysql_fetch_array($resultSalesSetup)){
	extract($rowSalesSetup);
}

//Read From Module Table
$querymodule=" Select ifNull(Module_AdditionalTaxes,0) As Module_AdditionalTaxes, ifNull(Module_Pack,0) As Module_Pack, ".
			 " ifNull(Module_ProjectParent,0) As Module_ProjectParent, ifNull(Module_CostCenterParent,0) As Module_CostCenterParent, ".
			 " ifNull(Module_Delivery,0) As Module_Delivery, ifNull(Module_TransferSorder,0) As Module_TransferSorder  From Module";
$resultmodule=mysql_query($querymodule,$connection) or die(mysql_error());
while($rowmodule=mysql_fetch_array($resultmodule)){
	extract($rowmodule);
}

$MainCompanyName=explode('_',$_SESSION['dbName']);

$queryperiod= " Select ifNull(LockViewPeriod,0) As LockViewPeriod, ViewPeriodDate, ifNull(ViewLockDaily,0) As ViewLockDaily, ViewNumberOfDays ".
              " From ".$_SESSION['dbLabel'].".ListUserDir  ".
			  " Where Usercode='".$_SESSION['useraccount']."' ".
			  " And Upper(CompanyName) = Upper('".$MainCompanyName[0]."') ".
			  " And Upper(Diryear) = Upper('".$MainCompanyName[1]."') ";
			  
$resultperiod = mysql_query($queryperiod,$connection) or die(mysql_error());
$rowsperiod   = mysql_num_rows($resultperiod);

while($rows=mysql_fetch_array($resultperiod)){
	extract($rows);
}	

			  
//echo $queryperiod;	

$queryproject=" select distinct project.project_code, project_name ".
              " from project left join ".$_SESSION['dbLabel'].".loginstk on (($Module_ProjectParent=1 and project.project_code like concat(ifnull(loginstk.project_code,project.project_code),'%')) or ($Module_ProjectParent=0 and project.project_code = loginstk.project_code )) ".
			  " where user_account='".$_SESSION['useraccount']."' ".
			  " and (loginstk.project_code is not null and loginstk.project_code != '') ".
			  " order by project.project_code";
$projectresult = mysql_query($queryproject,$connection) or die(mysql_error());
$projectexist  = mysql_num_rows($projectresult);	


$querycostcent=" select distinct costcent.costcent_code, costcent_name ".
               " from costcent left join ".$_SESSION['dbLabel'].".loginstk on (($Module_CostCenterParent=1 and costcent.costcent_code like concat(ifnull(loginstk.costcent_code,costcent.costcent_code),'%')) or ($Module_CostCenterParent=0 and costcent.costcent_code = loginstk.costcent_code )) ".
			   " where user_account='".$_SESSION['useraccount']."' ".
			   " and (loginstk.costcent_code is not null and loginstk.costcent_code != '') ".
			   " order by costcent.costcent_code";
$costcentresult = mysql_query($querycostcent,$connection) or die(mysql_error());
$costcentexist  = mysql_num_rows($costcentresult);	

$querywh=" select distinct warehouse.warehouse_code, warehouse_name ".
         " from warehouse inner join ".$_SESSION['dbLabel'].".loginstk on warehouse.warehouse_code = loginstk.warehouse_code ".
		 " where user_account='".$_SESSION['useraccount']."' ".
		 " and (loginstk.warehouse_code is not null and loginstk.warehouse_code != '')  ".
		 " order by warehouse.warehouse_code";
$whresult = mysql_query($querywh,$connection) or die(mysql_error());
$whexist  = mysql_num_rows($whresult);	  

$queryledger= " select distinct ledger_number, ledger_include ".
              " from ".$_SESSION['dbLabel'].".ledgerstk  ".
			  " where user_account='".$_SESSION['useraccount']."' ".
			  " and (ledger_number is not null and ledger_number != '') ".
			  " order by ledger_number";
$ledgerresult = mysql_query($queryledger,$connection) or die(mysql_error());
$ledgerexist  = mysql_num_rows($ledgerresult);	
$rows=mysql_fetch_array($ledgerresult) ;
$ledgerinclude = $rows[1];

//Get Default Project
$querydflproject="select project_code as defaultproject from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."' and default_project=1 ";
$resultdflproject=mysql_query($querydflproject,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultdflproject)){
	extract($rows);
}
	
//Get Default Coscenter
$querydflcostcent="select costcent_code as defaultcostcent from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."' and default_costcenter=1 ";
$resultdflcostcent=mysql_query($querydflcostcent,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultdflcostcent)){
	extract($rows);
}


$actionmode = $_POST["actionmode"]; if ($actionmode == ""){$actionmode = $_GET["actionmode"];}   
$mainaction = $_POST["mainaction"]; if ($mainaction == ""){$mainaction = $_GET["mainaction"];}   
$message 	= $_POST["message"]; if ($message == ""){$message = $_GET["message"];}   
$fromdate 	= $_POST["fromdate"]; if ($fromdate == ""){$fromdate = $_GET["fromdate"];}
$todate 	= $_POST["todate"]; if ($todate == ""){$todate = $_GET["todate"];}
$transtype 	= $_POST["transtype"]; if ($transtype == ""){$transtype = $_GET["transtype"];}
$priority 	= $_POST["priority"]; if ($priority == ""){$priority = $_GET["priority"];}
$itemstatus	= $_POST["itemstatus"]; if ($itemstatus == ""){$itemstatus = $_GET["itemstatus"];}
$startrange	= $_POST["startrange"]; if ($startrange == ""){$startrange = $_GET["startrange"];}
$perpage 	= $_POST["perpage"]; if ($perpage == ""){$perpage = $_GET["perpage"];}
$PMode 		= $_POST["PMode"]; if ($PMode == ""){$PMode = $_GET["PMode"];}
$PRef 		= $_POST["PRef"]; if ($PRef == ""){$PRef = $_GET["PRef"];}
$PProjectCode 	= $_POST["PProjectCode"]; if ($PProjectCode == ""){$PProjectCode = $_GET["PProjectCode"];}
$PCostCentCode 	= $_POST["PCostCentCode"]; if ($PCostCentCode == ""){$PCostCentCode = $_GET["PCostCentCode"];}
$SelectedRows 	= $_POST["SelectedRows"]; if ($SelectedRows == ""){$SelectedRows = $_GET["SelectedRows"];}
$GeneratedId 	= $_POST["GeneratedId"]; if ($GeneratedId == ""){$GeneratedId = $_GET["GeneratedId"];}
//$PRequestedBy 	= $_POST["PRequestedBy"]; if ($PRequestedBy == ""){$PRequestedBy = $_GET["PRequestedBy"];}

if (empty($fromdate)) $fromdate = displayFromDate(displayToday());
if (empty($todate))   $todate   = displayToday();


if ((!isset($PProjectCode)) && $Module_Project == 1)
	$PProjectCode = $defaultproject;
if ((!isset($PCostCentCode)) && $Module_CostCenter == 1)	
	$PCostCentCode = $defaultcostcent;		

print <<<HERE
<head>

<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
<meta name="viewport" content="width=device-width, initial-scale=1.0"> 
<link rel="stylesheet" type="text/css" media="all" href="css-v2/style.css">
<link rel="stylesheet" type="text/css" media="all" href="css/style.css">
<link type="text/css" rel="stylesheet" href="dhtmlgoodies_calendar.css?random=20051112" media="screen"></LINK>
<SCRIPT type="text/javascript" src="dhtmlgoodies_calendar.js?random=20060118"></script>
<title>Pending Request Items</title>

<style>

body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 11px;
}
body {
	margin-top: 2px;
	margin-left: 1px;
}
a:link {
	text-decoration: none;
	color: #0000FF;
}
a:visited {
	text-decoration: none;
	color: #0000FF;
}
a:hover {
	text-decoration: none;
	color: #0000FF;
}
a:active {
	text-decoration: none;
	color: #0000FF;
}
.style11 {color: #999999; font-weight: bold; }
.style12 {
	font-size: 9px;
	color: #999999;
	font-weight: bold;
}
.style15 {color: #5151FF; }
.style16 {
	font-size: 16px;
	color: #FF0000;
	font-weight: bold;
	font-family: "Times New Roman", Times, serif;
}
.style17 {font-size: 9px}
.style25 {color: #999999; font-weight: bold; font-size: 10px; }
.style26 {color: #FF0000}
.style27 {color: #999999 ;font-size: 10px;}
.style28 {color: #000000 ;font-size: 10px;}



table.grid_data1 {
	table-layout:fixed;
	border-width: 0px;
	border-spacing: 3px;
	border-style: double;
	border-color: gray;
	border-collapse: collapse;
	background-color: white;
}

		
table.grid_data1 th {
	
	color:#ffffff;
	font-weight: bold;
	font-size: 11px; 
	font-family:Verdana, Arial, Helvetica, sans-serif;
	padding: 3px;
	border-width: 1px;
	border-style: solid;
	border-color: #E5E5E5;
	/*border-left: 0px solid #000000;*/
}
table.grid_data1 td {
	padding: 3px;
	border-width: 1px;
	border-style: solid;
	border-color: #E5E5E5;
}


</style>


</style>

<link rel="stylesheet" type="text/css" media="all" href="js/grid/UI_DataGrid_V1.css">
<script type="text/javascript" src="js/grid/UI_DataGrid.js"></script>
<script type="text/javascript" src="js/grid/jquery-1.9.1.js"></script>


<link type="text/css" href="js/calendar/jquery.datepick.css" rel="stylesheet">
<script type="text/javascript" src="js/calendar/jquery.datepick.js"></script>

<link type="text/css" href="js/grid/scripts/jquery-ui.css" rel="stylesheet">
<script type="text/javascript" src="js/grid/scripts/jquery-ui.min.js"></script>

<script type="text/javascript" language="javascript">
	$(document).ready(function() { 
		
		$(document).on('focus', '.date', function() {
			$('.date').datepick({showTrigger: '#calImg'});
		});
		
		$(document).on('focusin', '.table-focus-g1', function() {
			AutoSaveRecordGrid(this.id);
		});
		
		
		//Set Scroll Positions on Page Load
		scrollToPage();
		
		$(window).scroll(function(){
			scrollPage();
		});
		
		//Set Cursor Position After Page Reload
		var NextElement = readCookie('so-nextcell');
		MoveNextRecord(NextElement);
		eraseCookie('so-nextcell');
		
	
	});
	
	
</script>

<script type="text/javascript" language="javascript">


function showlistWarehouse(vtype,vtext1,vtext2,vwidth,vheight,vitem,vdate){
	
	var text1value = document.getElementById(vtext1).value;

	win = window.open('List_WarehousesQtyExists.php?PRef='+text1value+'&str=10&vtype='+vtype+'&vtext1='+vtext1+'&vtext2='+vtext2+'&vitem='+vitem+'&vdate='+vdate
						+'&text1value='+text1value, 'Search', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width='+vwidth+',height='+vheight+',top=100,left=100');		
	win.creator = self;
	win.focus();	

	
}


function createtransferrequest(prqstid){

//alert(prqstid);

	
win = window.open('Form_CreateTransferRequest.php?prqstid='+prqstid,
						  'Form_CreateTransferRequest', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=800,height=400,left=100,top=100');		
		win.creator = self;
		win.focus();	


}

function createstockoutrequest(prqstid){

//alert(prqstid);

	
win = window.open('Form_CreateStockOutRequest.php?prqstid='+prqstid,
						  'Form_CreateStockOutRequest', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=750,height=400,left=100,top=100');		
		win.creator = self;
		win.focus();	


}

function updatequantity(indx,prqstdtid){

  $("#Loader").addClass("ajaxsaving");
  
 oqty = 'PRqstDt_OQuantity[' + indx + ']';
 cqty = 'PRqstDt_CQuantity[' + indx + ']';
 qty = 'PRqstDt_Quantity[' + indx + ']';
 
 
 oqty = document.getElementById(oqty).value;
 cqty = document.getElementById(cqty).value;
 
 if (cqty=='')
	cqty = 0;
	
 document.getElementById(qty).value = oqty -  cqty;
 
 qty = document.getElementById(qty).value;
 
 
 
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
				{ 
							var data = xmlhttp.responseText.split("[BRK]");	
							var resp = data[1];
							$("#Loader").removeClass("ajaxsaving");
							if (resp != '')
								alert(resp);
							
							
								
				}
		}
  }

	xmlhttp.open("GET","Form_PurchaseRequest_Actions.php?prqstdtid="+prqstdtid+"&actionmode=updatequantity&oqty="+oqty+"&cqty="+cqty+"&qty="+qty,true);
xmlhttp.send();


}
function stest(prqstdtid,indx,vtype){
alert();
}
function submitItemDt(prqstdtid,indx,vtype){

	$("#Loader").addClass("ajaxsaving");
	  
	itemcode = 'item_code' + indx ;
	itemcode = document.getElementById(itemcode).value;
	 
	if (itemcode != '') {
	
		if (window.XMLHttpRequest)
		{// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest();
		}
		else
		{// code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		
		xmlhttp.onreadystatechange=function()
		{
			if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{
				var data = xmlhttp.responseText.split("[BRK]");	
				var resp = data[0];
									
				$("#Loader").removeClass("ajaxsaving");
				
			}
		}

		xmlhttp.open("GET","Form_PurchaseRequest_Actions.php?prqstdtid="+prqstdtid+"&itemcode="+itemcode+"&actionmode=updateitemcode"+"&vtype="+vtype,true);
		xmlhttp.send();
	} else {
		alert('Please choose an item!.');
	}

}


function submitavailable(prqstdtid,indx){

	
	var prequestdt_availableqty = 'prequestdt_availableqty' + indx ;
	prequestdt_availableqty = document.getElementById(prequestdt_availableqty).value;
	$("#Loader").addClass("ajaxsaving");
	  
	
	 
	if (prequestdt_availableqty != '') {
	
		if (window.XMLHttpRequest)
		{// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest();
		}
		else
		{// code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		
		xmlhttp.onreadystatechange=function()
		{
			if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{
				var data = xmlhttp.responseText.split("[BRK]");	
				var resp = data[0];
									
				$("#Loader").removeClass("ajaxsaving");
				
			}
		}

		xmlhttp.open("GET","Form_PurchaseRequest_Actions.php?prqstdtid="+prqstdtid+"&prequestdt_availableqty="+prequestdt_availableqty+"&actionmode=updateavailable",true);
		xmlhttp.send();
	} else {
		alert('Please choose an item!.');
	}

}


function updatequantityTransfer(indx,transdtid){

  $("#Loader").addClass("ajaxsaving");
  
 qty = 'transferrequestdt_Quantity[' + indx + ']';
 price = 'TransferrequestDt_Price[' + indx + ']';
 total = 'total[' + indx + ']';
 
 
 qty = document.getElementById(qty).value;
 price = document.getElementById(price).value;
 if (qty=='')
	qty = 0;
	
 document.getElementById(total).value = qty *  price;
 

 
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
				{ 	
							var data = xmlhttp.responseText.split("[BRK]");	
							var resp = data[0];
							
							$("#Loader").removeClass("ajaxsaving");
							if (resp != '')
								alert(resp);
							
							
								
				}
		}
  }

	xmlhttp.open("GET","Form_TransferRequest_Actions.php?transdtid="+transdtid+"&actionmode=updatequantity&qty="+qty,true);
xmlhttp.send();


}



function updatequantityAdjustment(indx,transdtid){

  $("#Loader").addClass("ajaxsaving");
  
 qty = 'adjustmentRequestdt_quantity[' + indx + ']';
 
 
 qty = document.getElementById(qty).value;
 
 
 if (qty=='')
	qty = 0;
	
 
 
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
				{ 	
							var data = xmlhttp.responseText.split("[BRK]");	
							var resp = data[1];
							
							$("#Loader").removeClass("ajaxsaving");
							if (resp != '')
								alert(resp);
							
							
								
				}
		}
  }

	xmlhttp.open("GET","Form_AdjustmentRequest_Actions.php?transdtid="+transdtid+"&actionmode=updatequantity&qty="+qty,true);
xmlhttp.send();


}

function updateheader(PRqstid,objval,vtype,reason,amount,porderproject_code){

	if (objval=='r')
		vname = 'reject';
	else if (objval=='a')
		vname = 'approve';
	else if (objval=='p')	
		vname = 'roll back'
        else vname = 'process'

	
	if (confirm ( "Are you sure you want to "+vname+" this request?")){

		var xx = document.getElementById(reason).value;

		if ((objval == 'r') && (xx == '') ) {
			alert('Please fill reason');
			document.getElementById(reason).focus();
			return;
		}


		var vreason = xx;
		vreason = vreason.replace('&','%26');

			
		$("#Loader").addClass("ajaxsaving");
		if (window.XMLHttpRequest)
		{// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest();
		}
		else
		{// code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		
		xmlhttp.onreadystatechange=function()
		{
			if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{	
				var data = xmlhttp.responseText.split("[BRK]");	
				var resp = data[1];
									
				$("#Loader").removeClass("ajaxsaving");
				
				if (resp != '')
					alert(resp);
				else {
					document.search.action='Form_PurchaseRequestItemsTR.php';
					document.search.submit();
				}
										
				
			}
		}

		if (vtype=='PRO')
			xmlhttp.open("GET","Form_PurchaseOrder_Actions.php?PRqstid="+PRqstid+"&actionmode=updateitemstatus&objval="+objval+"&vtype="+vtype+"&vreason="+vreason+"&amount="+amount+"&porderproject_code="+porderproject_code,true);
		else if (vtype=='PRQ')
			xmlhttp.open("GET","Form_PurchaseRequest_Actions.php?PRqstid="+PRqstid+"&actionmode=updateitemstatus&objval="+objval+"&vtype="+vtype+"&vreason="+vreason,true);
		else if (vtype=='TRQ')
			xmlhttp.open("GET","Form_TransferRequest_Actions.php?PRqstid="+PRqstid+"&actionmode=updateitemstatus&objval="+objval+"&vtype="+vtype+"&vreason="+vreason,true);
		else if (vtype=='ADR')
			xmlhttp.open("GET","Form_AdjustmentRequest_Actions.php?PRqstid="+PRqstid+"&actionmode=updateitemstatus&objval="+objval+"&vtype="+vtype+"&vreason="+vreason,true);
		else if (vtype=='PYR')
			xmlhttp.open("GET","Form_PaymentRqst_Actions.php?PRqstid="+PRqstid+"&actionmode=updateitemstatus&objval="+objval+"&vtype="+vtype+"&vreason="+vreason,true);	
			
		xmlhttp.send();

	}
	else {
		document.search.submit();
	}
}



function updatedt(PRqstDtid,objval,vtype,approved,reason,indx,checking){


	if (objval=='r')
		vname = ' Reject ';
	else if (objval=='a')
		vname = ' Approve ';
	else	
		vname = ' Update ';

	if (confirm ( "Are you sure you want to "+vname+" the  record ?")){

		if(document.getElementById(reason)){
			var xx = document.getElementById(reason).value;
			reason = xx;
		}
		else reason = '';
		
		itemcode = 'item_code' + indx ;
		itemcode = document.getElementById(itemcode).value;

		if (vtype=='PRQ' && objval=='u' && itemcode == '' && approved == 1 ) {
			alert('Please enter an item code first!');
		}
		else {
		
			$("#Loader").addClass("ajaxsaving");
			
			if (window.XMLHttpRequest)
			{// code for IE7+, Firefox, Chrome, Opera, Safari
				xmlhttp=new XMLHttpRequest();
			}
			else
			{// code for IE6, IE5
				xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			xmlhttp.onreadystatechange=function()
			{
				if (xmlhttp.readyState==4 && xmlhttp.status==200)
				{
					{ 
						var data = xmlhttp.responseText.split("[BRK]");	
						var resp = data[1];
						$("#Loader").removeClass("ajaxsaving");
					
						if (resp != '')
							alert(resp);
					//	else document.search.submit();	
											
					}
				}
			}
			
			if (vtype=='PRO')
				xmlhttp.open("GET","Form_PurchaseOrder_Actions.php?PRqstDtid="+PRqstDtid+"&actionmode=updateitemstatus&objval="+objval+"&vtype="+vtype+"&approved="+approved+"&reason="+reason,true);
			else if (vtype=='PRQ')
				xmlhttp.open("GET","Form_PurchaseRequest_Actions.php?PRqstDtid="+PRqstDtid+"&actionmode=updateitemstatus&objval="+objval+"&vtype="+vtype+"&approved="+approved+"&reason="+reason,true);
			else if (vtype=='TRQ')
				xmlhttp.open("GET","Form_TransferRequest_Actions.php?PRqstDtid="+PRqstDtid+"&actionmode=updateitemstatus&objval="+objval+"&vtype="+vtype+"&approved="+approved+"&reason="+reason,true);
			else if (vtype=='ADR')
				xmlhttp.open("GET","Form_AdjustmentRequest_Actions.php?PRqstDtid="+PRqstDtid+"&actionmode=updateitemstatus&objval="+objval+"&vtype="+vtype+"&approved="+approved+"&reason="+reason,true);

			xmlhttp.send();
		} 
	}
	 /* else {
		document.search.submit();
	 }  */

}

function updatedtgrn(PRqstDtid,indx){
	
	chkname = 'chk' + indx ;
	
	objval = 0;
	if (document.getElementById(chkname)) {
		if (document.getElementById(chkname).checked) objval = 1;
	}	

	if (objval==1)
		vname = ' Reject ';
	else 
		vname = ' UnReject ';

	if (confirm ( "Are you sure you want to "+vname+" the  record ?")){

		$("#Loader").addClass("ajaxsaving");
			
		if (window.XMLHttpRequest)
		{// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest();
		}
		else
		{// code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		
		xmlhttp.onreadystatechange=function()
		{
			if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{
				var data = xmlhttp.responseText.split("[BRK]");	
				var resp = data[1];
				$("#Loader").removeClass("ajaxsaving");
					
				if (resp != '')	alert(resp);
				else document.search.submit();	
											
			}
		}
			
		xmlhttp.open("GET","Form_PurchaseOrder_Actions.php?PRqstDtid="+PRqstDtid+"&actionmode=updateitemgrn&objval="+objval,true);
		xmlhttp.send();
		
	}
	
}

function RefreshPage()
{
	document.search.itemstatus.value='';
	document.search.submit();
}

function ChangeItemStatus()
{
	document.search.submit();
}


function clearform()
{
	document.search.PRef.value='';
	document.search.PProjectCode.value='';
	document.search.PCostCentCode.value='';
	document.search.PRequestedBy.value='';
	document.search.PWarehouseCode.value='';
	document.search.action='Form_PurchaseRequestItemsTR.php';
	document.search.submit();

}

function LoadForm() 
{
	x=document.search;
	x.PRef.focus();
	
	ChangeLocation();
}

function SetNextPage(startrange,perpage){ 
	document.search.action='Form_VehicleLoad.php?PRef=&startrange='+startrange+'&perpage='+perpage;
	document.search.submit();
}

function SetPrvPage(startrange,perpage){
	document.search.action='Form_VehicleLoad.php?PRef=&startrange='+startrange+'&perpage='+perpage;
	document.search.submit();
}



function SelectRecord(RecordId){
	
	document.search.PMode.value=1;	
	document.search.action="Form_Delivery_Actions.php?mainmode=confirmedsorder&SSaId="+RecordId;
	document.search.submit();
	
	
	
	/*opener.document.sales.txtSaId.value=RecordId;
	opener.document.sales.mainaction.value='insert';
	opener.document.sales.actionmode.value='';
	
	
	
	self.close();*/
	

}

function UnConfirmOrder(SorId, SorRef){

	var vMainMode = '';
	var vMsg = '';
	
	vMainMode = 'unconfirmorder';
	vMsg = 'Are you sure you want to Unconfirm order with reference = '+SorRef+' ?';
	
	if (SorId != '') {
		if (confirm (vMsg) )
		{
			document.search.action="Form_Delivery_Actions.php?mainmode="+vMainMode+"&SSaId="+SorId;
			document.search.submit();
		}
	}
	
}

function DisapproveOrder(SorId, SorRef){

	if (SorId != '') {
		if (confirm ( "Are you sure you want to Disapprove order with reference = "+SorRef+" ?") )
		{
			document.search.action="Form_Delivery_Actions.php?mainmode=disapproveorder&SSaId="+SorId;
			document.search.submit();
		}
	}
	
}




function LoadData(){
	var vSelectedRows = document.search.SelectedRows.value;
	
	if (vSelectedRows != '') {
		var vSaID = document.search.PSaId.value;
		document.search.PMode.value=1;	
		document.search.action="Form_Delivery_Actions.php?mainmode=loadsorder&SSaId="+vSaID+"&SSaDtId="+vSelectedRows;
		document.search.submit();
	} else
		alert ('Please Select an Item.');
	
}


function ChangeLocation()
{
    if (document.search.PMode.value == 1) {
	    var GenId = document.search.GeneratedId.value;
		
		opener.document.sales.txtSaId.value=GenId;
	    opener.document.sales.mainaction.value='';
		opener.document.sales.actionmode.value='submitrecord';
		opener.document.sales.message.value = document.search.message.value;
		opener.document.sales.action='Form_Delivery.php';
		opener.document.sales.submit();
		self.close();
	}	
}

function SelectMaster(vName) {

   
   var MasterCheckName, DetailCheckName, RecName;
   var x, y, z, t;
   
   for (var i=1; i <= document.search.i.value; i++)
  {
    MasterCheckName='M'+i;
	RecName = 'Rec'+MasterCheckName;
	
	x = document.getElementById(MasterCheckName);
	y = document.getElementById(RecName);
	t = document.getElementById(vName);
	
	if (x.checked && x.value == t.value) {
		for (var j=1; j <= y.value; j++)
		{
			DetailCheckName=MasterCheckName+'D'+j;
	
			z = document.getElementById(DetailCheckName);
			z.checked = true;
		}	
	} 
	else if (!(x.checked) &&  x.value == t.value){ 
		for (var j=1; j <= y.value; j++)
		{
			DetailCheckName=MasterCheckName+'D'+j;
	
			z = document.getElementById(DetailCheckName);
			z.checked = false;
		}
	
	}
    
  }
  
  SelectDetail();
  

}

function setitemcode(val,vfield1,vfield2,vgridname,btnname){
alert();
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
				{ 	var data = xmlhttp.responseText.split("[BRK]");
					var resp = data[1];
					
					if (resp==0)
						{
							document.getElementById(btnname).click();
						}
						else
							document.getElementById(vfield2).value = resp;
						//showsearchpage('itemcode',vfield1,vfield2,800,500);

				}
		}
  }

xmlhttp.open("GET","Form_PurchaseRequest_Actions.php?vitemcode="+val+"&actionmode=checkitemcode",true);
xmlhttp.send();

}

function showsearchpage(vtype,vtext1,vtext2,vwidth,vheight){
	var text1value = document.getElementById(vtext1).value;

	win = window.open('List_PurItems.php?PItem_Code='+text1value+'&item=5&vtype='+vtype+'&vtext1='+vtext1+'&vtext2='+vtext2
						+'&text1value='+text1value, 'Search', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width='+vwidth+',height='+vheight+',top=100,left=100');		
	win.creator = self;
	win.focus();	
	}
	
function SelectDetail() {
	var MasterCheckName, DetailCheckName, RecName, vSelectedRows;
	var x, y, z;
	
	vSelectedRows = '';
	for (var i=1; i <= document.search.i.value; i++)
	{
		MasterCheckName='M'+i;
		RecName = 'Rec'+MasterCheckName;
		
		x = document.getElementById(MasterCheckName);
		y = document.getElementById(RecName);
		
		
		for (var j=1; j <= y.value; j++)
		{
			DetailCheckName=MasterCheckName+'D'+j;
		
			z = document.getElementById(DetailCheckName);
			
			if (z.checked)
				vSelectedRows = vSelectedRows + ',' + z.value;
		}	
		
		
	}
	
	vSelectedRows = vSelectedRows.substr(1);
	document.search.SelectedRows.value = vSelectedRows;
}

function SubmitForm()
{	
  
  document.search.submit();

}

function openhistory(vitemcode){

	win = window.open('Form_ItemHistory.php?PItem_Code='+vitemcode, 'History', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=990,height=600,top=60,left=100');		
	win.creator = self;
	win.focus();	

}

function ConfirmRequest(PreqId, PreqRef){

	var vMainMode = '';
	var vMsg = '';
	
	vMainMode = 'confirmrequestitem'; 
	vMsg = 'Are you sure you want to Confirm request with reference = '+PreqRef+' ?';
	
	if (PreqId != '') {
		if (confirm (vMsg) )
		{
			if (window.XMLHttpRequest)
			{// code for IE7+, Firefox, Chrome, Opera, Safari
				xmlhttp=new XMLHttpRequest();
			}
			else
			{// code for IE6, IE5
				xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			xmlhttp.onreadystatechange=function()
			{
				if (xmlhttp.readyState==4 && xmlhttp.status==200)
				{
					{ 
						var data = xmlhttp.responseText.split("[BRK]");	
						var resp = data[1];
						
						//if (resp != '')	alert(resp);
						//else 
						document.search.submit();	
											
					}
				}
			}
			
			xmlhttp.open("GET","Form_PurchaseRequest_Actions.php?mainmode="+vMainMode+"&SPreqId="+PreqId,true);
			xmlhttp.send();
			
		}
	}
	
}
function CancelRequest(PreqId, PreqRef){

	var vMainMode = '';
	var vMsg = '';
	
	vMainMode = 'cancelrequestitem'; 
	vMsg = 'Are you sure you want to Cancel request with reference = '+PreqRef+' ?';
	
	if (PreqId != '') {
		if (confirm (vMsg) )
		{
			if (window.XMLHttpRequest)
			{// code for IE7+, Firefox, Chrome, Opera, Safari
				xmlhttp=new XMLHttpRequest();
			}
			else
			{// code for IE6, IE5
				xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			xmlhttp.onreadystatechange=function()
			{
				if (xmlhttp.readyState==4 && xmlhttp.status==200)
				{
					{ 
						var data = xmlhttp.responseText.split("[BRK]");	
						var resp = data[1];
						alert(resp);
						//if (resp != '')	alert(resp);
						//else 
						document.search.submit();	
											
					}
				}
			}
			
			xmlhttp.open("GET","Form_PurchaseRequest_Actions.php?mainmode="+vMainMode+"&SPreqId="+PreqId,true);
			xmlhttp.send();
			
		}
	}
	
}
function ConfirmOrder(PorderId, PorderRef){

	var vMainMode = '';
	var vMsg = '';
	
	vMainMode = 'confirmrequestitem'; 
	vMsg = 'Are you sure you want to Confirm Order with reference = '+PorderRef+' ?';
	
	if (PorderId != '') {
		if (confirm (vMsg) )
		{
			if (window.XMLHttpRequest)
			{// code for IE7+, Firefox, Chrome, Opera, Safari
				xmlhttp=new XMLHttpRequest();
			}
			else
			{// code for IE6, IE5
				xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			xmlhttp.onreadystatechange=function()
			{
				if (xmlhttp.readyState==4 && xmlhttp.status==200)
				{
					{ 
						var data = xmlhttp.responseText.split("[BRK]");	
						var resp = data[1];
						
						//if (resp != '')	alert(resp);
						//else 
						document.search.submit();	
											
					}
				}
			}
			
			xmlhttp.open("GET","Form_PurchaseOrder_Actions.php?mainmode="+vMainMode+"&SPorId="+PorderId,true);
			xmlhttp.send();
			
		}
	}
	
}


function ConfirmPaymentRqst(PayRqstId, PayRqstRef){

	var vMainMode = '';
	var vMsg = '';
	
	vMainMode = 'confirmrequestitem'; 
	vMsg = 'Are you sure you want to Confirm Payment Request with reference = '+PayRqstRef+' ?';
	
	if (PayRqstId != '') {
		if (confirm (vMsg) )
		{
			if (window.XMLHttpRequest)
			{// code for IE7+, Firefox, Chrome, Opera, Safari
				xmlhttp=new XMLHttpRequest();
			}
			else
			{// code for IE6, IE5
				xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			xmlhttp.onreadystatechange=function()
			{
				if (xmlhttp.readyState==4 && xmlhttp.status==200)
				{
					{ 
						var data = xmlhttp.responseText.split("[BRK]");	
						var resp = data[1];
						
						document.search.submit();	
											
					}
				}
			}
			
			xmlhttp.open("GET","Form_PaymentRqst_Actions.php?mainmode="+vMainMode+"&STransId="+PayRqstId,true);
			xmlhttp.send();
			
		}
	}
	
}

function showlistProject(str){

  window.open('List_SorProject.php?frm=6&item='+str,'mywindow','width=850,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function showlistCostcenter(str){

  window.open('List_SorCostcenter.php?frm=6&item='+str,'mywindow','width=850,height=550,,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function showlistUsers(){
window.open('List_RequestedByUsers.php?frm=1','mywindow','width=850,height=550,,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
	
}

function filterlistWarehouse(str){

  window.open('List_SorWarehouse.php?frm=10&item='+str,'mywindow','width=850,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function ShowHideDetails(TransId, Option, startrange) {
	vSlideDivId = '#displaydetails'+TransId;
	$(vSlideDivId).slideToggle();

}

function UploadDocuments(transid,vform){
	win = window.open('UploadDocuments.php?vform='+vform+'&porderid='+transid+'&prqstid='+transid, 'Upload', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=990,height=600,top=60,left=100');		
	win.creator = self;
	win.focus();	

}
function PrintPreview(transid, option)
{
	var str = '';

	if (option == 'PO')
		str = 'Form_PurchaseOrderPreview.php?PorderId='+transid;
	else if (option == 'PR')
		str = 'Form_PurchaseRequestPreview.php?PrequestId='+transid;
	else if (option == 'PYR')
		str = 'Form_PaymentRqstPreview.php?PaymentRqstId='+transid;
		
	window.open(str);

}
function PrintPage(){
	var x = document.search;
	if(document.getElementById("txtprintdetails").checked)
	var checkDt =1;
	else var checkDt =0;
	var vtranstype = x.transtype.value;
	var vfromdate = x.fromdate.value;
	var vtodate = x.todate.value;
	var vPProjectCode = x.PProjectCode.value;
	var vPCostCentCode = x.PCostCentCode.value;
	if (vtranstype == 't' || vtranstype == 'a') var vPRequestedBy = '';
	else var vPRequestedBy = x.PRequestedBy.value;
	var vitemstatus = x.itemstatus.value;
	var vpriority = x.priority.value;
	win = window.open('Rep_ListRequestedItems.php?checkDt='+checkDt+'&transtype='+vtranstype+'&fromdate='+vfromdate+'&todate='+vtodate+'&PProjectCode='+vPProjectCode+'&PCostCentCode='+vPCostCentCode+'&PRequestedBy='+vPRequestedBy+'&itemstatus='+vitemstatus+'&priority='+vpriority, '_blank' );
}
function PrintPageExp(){
	var x = document.search;
	if(document.getElementById("txtprintdetails").checked)
	var checkDt =1;
	else var checkDt =0;
	var vtranstype = x.transtype.value;
	var vfromdate = x.fromdate.value;
	var vtodate = x.todate.value;
	var vPProjectCode = x.PProjectCode.value;
	var vPCostCentCode = x.PCostCentCode.value;
	if (vtranstype == 't' || vtranstype == 'a') var vPRequestedBy = '';
	else var vPRequestedBy = x.PRequestedBy.value;
	var vitemstatus = x.itemstatus.value;
	var vpriority = x.priority.value;
	win = window.open('Rep_ListRequestedItems.php?checkDt='+checkDt+'&transtype='+vtranstype+'&fromdate='+vfromdate+'&todate='+vtodate+'&PProjectCode='+vPProjectCode+'&PCostCentCode='+vPCostCentCode+'&PRequestedBy='+vPRequestedBy+'&itemstatus='+vitemstatus+'&priority='+vpriority+"&export=1", '_blank' );

}
</script>



</head>
<body onLoad='LoadForm();'>
<form name='search' method='post' action=''>
<input type='hidden' name='GeneratedId' value='$GeneratedId'>
<input type='hidden' name='SelectedRows' value='$SelectedRows'>

<input type='hidden' name='PSaDate' value='$PSaDate'>
<input type='hidden' name='PSaId' value='$PSaId'>
<input type='hidden' name='PSaMaturityDate' value='$PSaMaturityDate'>
<input type='hidden' name='PSaClientCode' value='$PSaClientCode'>
<input type='hidden' name='PSaSalesmanCode' value='$PSaSalesmanCode'>
<input type='hidden' name='PSaCurr' value='$PSaCurr'>
<input type='hidden' name='PSaProjectCode' value='$PSaProjectCode'>
<input type='hidden' name='PSaCostCentCode' value='$PSaCostCentCode'>
<input type='hidden' name='PSaDiscount' value='$PSaDiscount'>
<input type='hidden' name='PSaDiscountAmt' value='$PSaDiscountAmt'>
<input type='hidden' name='PSaVatChkbx' value='$PSaVatChkbx'>



HERE;
echo "<input type='hidden' name='message' value='".htmlspecialchars($message, ENT_QUOTES)."'>";
echo "<input type='hidden' name='PSaRemark' value='".htmlspecialchars($PSaRemark, ENT_QUOTES)."' > 
	  <input type='hidden' name='PSaDriverName' value='".htmlspecialchars($PSaDriverName, ENT_QUOTES)."' >
	  <input type='hidden' name='PSaVehicleNumber' value='".htmlspecialchars($PSaVehicleNumber, ENT_QUOTES)."' >
	  <input type='hidden' name='PSaDAddress' value='".htmlspecialchars($PSaDAddress, ENT_QUOTES)."' > 
	  <input type='hidden' name='PSaIAddress' value='".htmlspecialchars($PSaIAddress, ENT_QUOTES)."'> 
	  ";

echo"<table cellpadding='0' cellspacing='0' border='0'  align='center' class='layout-width'>";
include_once("header.php");
echo" <tr><td  valign='top'>";

include_once("sidemenu.php");
echo"  </td></tr>";


echo" <tr style='height:26px;'>
		<td  valign='top' id='content-top'>
			<table border='0' cellpadding='0' cellspacing='0' style='table-layout:fixed; height:26px;' class='layout-width'>
			<tr style='height:26px;'>
				<td style='width:38px; height:26px;'>&nbsp;</td>
				<td valign='middle' style='width:300px; height:26px;'><span class='title'>List of Pending Request Items</span></td>
				<td class='message' valign='middle' style='height:26px;'>".htmlspecialchars($message, ENT_QUOTES)."</td>
			</tr></table>
		</td>
	  </tr>";



echo"<tr>
		<td  height='34'  valign='top' id='content-top2'>
			<table border='0' cellpadding='0' cellspacing='0' class='layout-width'>
			<tr>
				<td width='30'  height='34'>&nbsp;</td>
				<td valign='middle' height='34' width='720px' align='left'>";
echo"	</td></tr></table>";
echo"</td></tr>";	
				
echo"	<div id='formlist'>";
echo"	<div id='Loader' class=''><div></div></div>";
echo"	<div id='itemslist'>";
echo"<tr><td id='content-body'>
		<table border='0' align='center' valign='top' width=100% class='tablecontent'>
		<col width=80>
		<col width=250>
		<col width=60>
		<col width=150>
		<col width=80>
		<col width=100>";
	
echo"	<tr>
			<td align='left'><span class='style1'>Reference</span></td>
			<td align='left' colspan='3'><span class='style1'><input type='text' name='PRef' id='PRef' value='$PRef' size='15' maxlength='30'/><input type='hidden' name='PMode' id='PMode' value='$PMode' size='15' maxlength='30'/></span>
				<button type='button' id='btnSubmit' name='btnSubmit' onclick='SubmitForm(); return false;' title='Find'><span><span>Find</span></span></button>
				<button type='button' id='btnCancel' name='btnCancel' onclick='clearform();return false;' title='Cancel'><span><span>Cancel</span></span></button>
				<button type='button' id='btnRefresh' name='btnRefresh' onclick='RefreshPage();return false;' title='Refresh'><span><span>Refresh</span></span></button>
				<button type='button' id='btnPrint' name='btnPrint' onclick='PrintPage();return false;' title='Print'><span><span>Print</span></span></button>
				<button type='button' id='btnPrintexcel' name='btnPrintexcel' onclick='PrintPageExp();return false;' title='Printexcel'><span><span>Excel</span></span></button>
				<input type='checkbox' name='txtprintdetails' id='txtprintdetails'><span class='style1'>Details</span>
			</td>";
echo "<td><span class='style4'>Warehouse</span></td>";
echo "<td align='left'><span class='style4'>
		    <input type='text' name='PWarehouseCode' id='PWarehouseCode' value='$PWarehouseCode' size='12' maxlength='15' /></span>
		    <label><span class='style4'><img src='img/btnopen.jpg' title=' Select Project ' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\" onClick='filterlistWarehouse(1); '  /></span></label></td>";
echo "</tr>
		<tr>
			<td align='left'><span class='style1'>Date From/To</span></td>
			<td align='left'>
				<input type='text' name='fromdate' value='$fromdate' maxlength='10' size='8'>
				<a href=\"#\" onClick=\"displayCalendar(document.search.fromdate,'dd/mm/yyyy',this); return false;\" NAME=\"anchor1\" ID=\"anchor1\"><image src='./img/cal.gif' border=0 align=center></image></a>
				<input type='text' name='todate' value='$todate' maxlength='10' size='8'>
				<a href=\"#\" onClick=\"displayCalendar(document.search.todate,'dd/mm/yyyy',this); return false;\" NAME=\"anchor1\" ID=\"anchor1\"><image src='./img/cal.gif' border=0 align=center></image></a>
			</td>";
			
if ($priority=='low')			$priority1 = ' selected ';
else if ($priority=='medium')	$priority2 = ' selected ';
else if ($priority=='high')		$priority3 = ' selected ';	
				
echo"		<td align='left'><span class='style1'>Priority</span></td>
			<td align='left'><select name='priority' id='priority' style='font-size:11px; width:150px; height:20px;' onchange='RefreshPage();' >";
				echo"<option></option>";
				echo"<option $priority1 value='low'>Low</option> ";
				echo"<option $priority2 value='medium'>Medium</option> ";
				echo"<option $priority3 value='high'>High</option> ";
				
echo"		</select></td>";

if ($Module_Project == 1) {
	echo" <td align='left'><span class='style4'>Project</span></td>
	      <td align='left'><span class='style4'>
		    <input type='text' name='PProjectCode' id='PProjectCode' value='$PProjectCode' size='12' maxlength='15' /></span>
		    <label><span class='style4'><img src='img/btnopen.jpg' title=' Select Project ' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistProject(1); '  /></span></label></td>";
} else {
	echo"<td align='left' colspan='2'>&nbsp;</td>";
}

echo"	</tr>
		<tr >
			<td align='left'><span class='style1'>Item Code/Desc</span></td>
			<td align='left'>";
    
		$i=0;		
echo"			<span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_small' onchange=setitemcode(this.value,'itemcode[$i]','itemdescription[$i]','','prqstdtitemcodeimage[$i]')    name='itemcode[$i]' id='itemcode[$i]' value='".$itemcode[$i]."' style='width:100px'></span>";
echo"			&nbsp;<span class='style4'><input type='text'   class='roundedtext_amortization_mediumlarge'    $KeyDown    name='itemdescription[$i]' id='itemdescription[$i]' value='".$itemdescription[$i]."' style='width:140px'> </span>
				<img src='img/scroll-down-1.png' width='20' height='20' id='prqstdtitemcodeimage[$i]' onmouseover=\"style.cursor='pointer'\"  onclick=\"showsearchpage('itemcode','itemcode[$i]','itemdescription[$i]','800','500')\">
			</td>";	
			
if (empty($transtype)) {
	if ($fi_pendingpurchaserequest==1) 		  $transtype = 'p';
	else if ($fi_pendingpurchaseorder==1) 	  $transtype = 'o';
	else if ($fi_pendingtransferrequest==1)   $transtype = 't';
	else if ($fi_pendingadjustmentrequest==1) $transtype = 'a';
	else if ($fi_pendingpaymentrequest==1) 	  $transtype = 'pyr';
}

//echo $itemstatus;echo " dft=".$TR_default;
if (empty($itemstatus)) {

	if ($transtype == 'p') {
		$itemstatus =$PR_default;
	}
	if ($transtype == 'o') {
		$itemstatus =$PO_default;
	}
	if ($transtype == 't') {
		$itemstatus =$TR_default;
	}
	if ($transtype == 'a') {
		$itemstatus =$AD_default;
	}
	if ($transtype == 'pyr') {
		$itemstatus =$PYR_default;
	}
}
//if(!isset($itemstatus)) $itemstatus = '1';




if ($itemstatus=='1')		$stat1 = ' selected ';
else if ($itemstatus=='2')	$stat2 = ' selected ';
else if ($itemstatus=='3')	$stat3 = ' selected ';	
else if ($itemstatus=='4')	$stat4 = ' selected ';	
else if ($itemstatus=='5')	$stat5 = ' selected ';	
else if ($itemstatus=='6')	$stat6 = ' selected ';	
else if ($itemstatus=='7')	$stat7 = ' selected ';	
else if ($itemstatus=='8')	$stat8 = ' selected ';	
else if ($itemstatus=='9')	$stat9 = ' selected ';	
else if ($itemstatus=='10')	$stat10 = ' selected ';	
else if ($itemstatus=='11')	$stat11 = ' selected ';	
else if ($itemstatus=='12')	$stat12 = ' selected ';	
else if ($itemstatus=='13')	$stat13 = ' selected ';	


echo"	    <td align='left'><span class='style1'>Status</span></td>
			<td align='left'><select name='itemstatus' id='itemstatus' style='font-size:11px; width:150px; height:20px;' onchange='ChangeItemStatus();' >";
			echo"<option value='-1'></option>";
			
			if ($Module_PRequestConfirm == 1 && $transtype == 'p' && $PR_status1=='1') {
				echo"<option $stat1 value='1'>MSR Working On</option> ";
			}
			
			if ($Module_PorderConfirm == 1 && $transtype == 'o' && $PO_status1=='1'){
				echo"<option $stat1 value='1'>LPO Working On</option> ";
			}
			
			if ($transtype == 'p') {
				if ($PR_status13=='1') echo"<option $stat13 value='13'>MSR Cancelled by PM</option> ";
				if ($PR_status2=='1') echo"<option $stat2 value='2'>MSR Pending Approval</option> ";
				if ($PR_status3=='1') echo"<option $stat3 value='3'>MSR Approved</option> ";
				if ($PR_status4=='1') echo"<option $stat4 value='4'>MSR Rejected</option> ";
				if ($PR_status5=='1') echo"<option $stat5 value='5'>MSR Transferred</option> ";
				
			}
			
			if ($transtype == 'o') {
				if ($PO_status2=='1') echo"<option $stat2 value='2'>LPO Pending Approval</option> ";
				if ($PO_status3=='1') echo"<option $stat3 value='3'>LPO Approved</option> ";
				if ($PO_status4=='1') echo"<option $stat4 value='4'>LPO Rejected</option> ";
				
			}
			
			if ($transtype == 't') {
				if ($TR_status1=='1') echo"<option $stat2 value='2'>Transfer Pending Approval</option> ";
				if ($TR_status2=='1') echo"<option $stat3 value='3'>Transfer Approved</option> ";
				if ($TR_status3=='1') echo"<option $stat4 value='4'>Transfer Rejected</option> ";
			}
			
			if ($transtype == 'a') {
				if ($AD_status1=='1') echo"<option $stat2 value='2'>Stock Out Pending Approval</option> ";
				if ($AD_status2=='1') echo"<option $stat3 value='3'>Stock Out Approved</option> ";
				if ($AD_status3=='1') echo"<option $stat4 value='4'>Stock Out Rejected</option> ";
			}
			
			if ($transtype == 'pyr') {
				if ($PYR_status1=='1') echo"<option $stat2 value='2'>Payment Req Pending Approval</option> ";
				if ($PYR_status2=='1') echo"<option $stat3 value='3'>Payment Req Approved</option> ";
				if ($PYR_status3=='1') echo"<option $stat4 value='4'>Payment Req Rejected</option> ";
			}
			
			
			if($transtype == 'p') {
				if ($PR_status5=='1' && $PendingProcess==1) echo"<option $stat5 value='5'>LPO Pending Process</option> ";
			if ($Module_PorderConfirm==1)
				if ($PR_status6=='1') echo"<option $stat6 value='6'>LPO Working On</option> ";
				if ($PR_status7=='1') echo"<option $stat7 value='7'>LPO Pending Approval</option> ";
				if ($PR_status8=='1') echo"<option $stat8 value='8'>LPO Approved</option> ";
				if ($PR_status9=='1') echo"<option $stat9 value='9'>LPO Rejected</option> ";
				
				if($Module_Grn == 1) {
					if ($PR_status10=='1') echo"<option $stat10 value='10'>GRN Pending</option> ";
					if ($PR_status12=='1') echo"<option $stat12 value='12'>GRN Rejected</option> ";
					if ($PR_status11=='1') echo"<option $stat11 value='11'>GRN Approved</option> ";
				}	
			}
			else if($transtype == 'o' && $Module_Grn == 1) {
				if ($PO_status5=='1') echo"<option $stat10 value='10'>GRN Pending</option> ";
				if ($PO_status7=='1') echo"<option $stat12 value='12'>GRN Rejected</option> ";
				if ($PO_status6=='1') echo"<option $stat11 value='11'>GRN Approved</option> ";
			}
			
			
echo"	</select></td>";	

if ($Module_CostCenter == 1) {		  
	echo" <td align='left'><span class='style4'>Costcenter</span></td>		
		  <td align='left'><span class='style4'>
		    <input type='text' name='PCostCentCode' id='PCostCentCode' value='$PCostCentCode' size='12' maxlength='15' /></span>
		    <label><span class='style4'><img src='img/btnopen.jpg' title=' Select Costcenter ' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  onClick='showlistCostcenter(1); ' /></span></label></td>";
			
} else {
	echo"<td align='left' colspan='2'>&nbsp;</td>";		
}	

echo" </tr>";




if ($transtype=='p')		$chk1 = ' selected ';
else if ($transtype=='o')	$chk0 = ' selected ';
else if ($transtype=='t')	$chk2 = ' selected ';
else if ($transtype=='a')	$chk3 = ' selected ';
else if ($transtype=='pyr')	$chk4 = ' selected ';
	
echo"<tr >
	    <td align='left'><span class='style1'>Type</span></td>
		<td align='left'><select name='transtype' id='transtype' style='font-size:11px; width:250px; height:20px;' onchange='RefreshPage();' >";
			if ($fi_pendingpurchaseorder==1)		echo"<option $chk0 value='o'>Purchase Order</option> ";
			if ($fi_pendingpurchaserequest==1)		echo"<option $chk1 value='p'>MSR</option> ";
			if ($fi_pendingtransferrequest==1)		echo"<option $chk2 value='t'>Transfer Request</option> ";		
			if ($fi_pendingadjustmentrequest==1)	echo"<option $chk3 value='a'>Adjustment Request</option> ";
			if ($fi_pendingpaymentrequest==1)		echo"<option $chk4 value='pyr'>Payment Request</option> ";

echo"	</select></td>";
echo"<td align='left' colspan='2'>&nbsp;</td>";
if($transtype=='p' || $transtype=='o') {
echo"<td align='left' colspan='1'><span class='style1'>Requested By </span></td>";
echo "<td align='left'><span class='style4'>
		    <input type='text' name='PRequestedBy' id='PRequestedBy' value='$PRequestedBy' size='12' maxlength='25' /></span>
		    <label><span class='style4'><img src='img/btnopen.jpg' title=' Select User ' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  onClick='showlistUsers(1); ' /></span></label></td>";
} else echo"<td align='left' colspan='2'></td>";
echo" </tr>	";






if ($fi_pendingpurchaserequest==1 && ($transtype=='' or $transtype=='p' )){

if ($Module_PRequestConfirm == 1 && $FI_PRequestConfirmed == 1 && $Prqst_Confirmed != 1) $widthsize = '85';
else $widthsize = '70';
	echo"<tr bgcolor='#F7F7F7'><td valign='top' align='left' colspan='6'>
		  <div id='container' style='width:1090px; height:330px;'>
		  <div id='grid_headerDiv' class='grid_headerDiv' style='height:80px;'>
		  <table  cellspacing='2' cellpadding='2' style='table-layout:fixed; width:2075px;' class='grid_data1'>
		  <col width=25>
		  <col width=25>
		  <col width=25>
		  <col width=$widthsize>
		  <col width=70>
		  <col width=70>
		  <col width=80>
		  <col width=120>
		  <col width=120>
		  <col width=200>
		  <col width=100>
		  <col width=120>
		  <col width=120>
		  <col width=110>
		  <col width=70>
		  <col width=80>
		  <col width=70>
		  <col width=70>
		  <col width=70>
		  <col width=60>
		  <col width=400>";
		  
	echo"<tr><td colspan=10 align=center><u><font color=red>MSR</font></u></td><td colspan='11'>&nbsp;</td></tr>";
	echo"<tr><td height='15' align='center' colspan='21'><font size='1' color='#FF0000' face='Verdana'><b>".$message."</b></font></td></tr>	
		 <tr bgcolor='#DAA520'>
			<th height='25' align='left'>&nbsp;</th>
			<th height='25' align='left'>&nbsp;</th>
			<th height='25' align='left'>&nbsp;</th>
			<th height='25' align='left'>Ref.</th>
			<th height='25' align='center'>Porder</th>
			<th height='25' align='center'>GRN</th>
			<th height='25' align='center'>Date</th>";
			
			if ($Module_Project == 1)
				echo"<th align='center'>Project</th>";
			else
				echo"<th align='center'>&nbsp;</th>";

			if ($ShowCostCentLayout_Purchase == 1)			
				echo"<th align='center'>Costcenter</th>";
			else
				echo"<th align='center'>&nbsp;</th>";
			
			
			echo"<th height='25' align='center'>Reason</th>";
			echo"<th height='25' align='center'>Status</th>";
			echo"<th height='25' align='center'>Created By</th>";
			echo"<th height='25' align='center'>Ordered By</th>";
			echo"<th height='25' align='center'>Approved By</th>";
			echo"<th height='25' align='center'>Priority</th>";
			echo"<th height='25' align='center' colspan='8'>&nbsp;</th>";
	echo"</tr>";
			
	echo"<tr bgcolor='#a8a8a8'>
			<th>&nbsp;</th>
			<th>&nbsp;</th>
			<th>&nbsp;</th>
			<th>&nbsp;</th>
			<th align='left' colspan='5'>Item Code \ Description</th>
			<th align='left'>New Item</th>
			<th align='left'>&nbsp;</th>";
			
			if ($Module_ProjectDt == 1)
				echo"<th align='center'>Project</th>";
			else
				echo"<th align='center'>&nbsp;</th>";

			if ($ShowCostCentLayout_Purchase == 1)			
				echo"<th align='center'>Costcenter</th>";
			else
				echo"<th align='center'>&nbsp;</th>";
			
			echo"<th align='center'>Main Wh.</th>
				<th align='center'>Exists.Qty</th>
				<th align='center'>Warehouse</th>
				<th align='center'>Ord.Qty</th>
				<th align='center'>Trans.Qty</th>
				<th align='center'>Qty</th>
				<th align='center'>Unit</th>
				<th align='center'>&nbsp;</th>";

	echo" </tr>";
	echo"</table></div>";
		

	if (empty($ViewPeriodDate))
	   $ViewPeriodDate = 'Null';
	if (empty($ViewNumberOfDays))   
	   $ViewNumberOfDays = 1;
			


	// purchase request part	
	$querysearch=" select prequest.prqst_reference as prqst_reference,date_format(prequest.prqst_date,'%d/%m/%Y') as prqst_date,prequest.currency_code as currency_code
					,prequest.prqst_total as prqst_total,prequestdt.item_code as item_code,items.item_description as item_description,prequestdt.item_description as item_description1 
					,PRqstDt_OQuantity,PRqstDt_CQuantity,PRqstDt_Quantity,PRqstDt_id,PRqstDt_status,prequest.PRqst_id as PRqst_id,ifnull(PRqstDt_approvedlevel,5000) as PRqstDt_approvedlevel
					,prequestdt.warehouse_code,prequest.project_code as prequestproject_code,prequest.costcent_code as prequestcostcent_code,prequestdt.project_code as project_code,prequestdt.costcent_code as costcent_code
					,ifnull(QtyExists(prequestdt.item_code , '".$defaultwarehouse."', prequest.prqst_date, 0, 'PQ', '', ''),0) as qtyexists,prequest.username as user_name
					,prequest.rejectedreason,costcent.costcent_name as costcent_name,project.project_name as project_name,costcent1.costcent_name prequestdtcostcent_name,project1.project_name as prequestdtproject_name
					,prequestdt.rejectedreason as prequestrejectedreason
					,prequestdt.prequestdt_availableqty prequestdt_availableqty, PRqst_Priority, ifNull(Prqst_Confirmed,0) as Prqst_Confirmed 
					,if(ifnull(Prqst_Cancelled,0)=1, 'Cancelled',if(ifnull(Prqst_Confirmed,0)=0, 'Working On',if(PRqstDt_Quantity=0,'Transferred', if(ifnull(PRqstDt_status,'x')='x', 'Pending Approval', if(ifnull(PRqstDt_status,'x')='a', 'Approved', if(ifnull(PRqstDt_status,'x')='r', 'Rejected', '')))))) as PRqstDtStatus
					,Items.Item_UnitSalesDesc as Item_UnitSalesDesc,prequest.prqst_requestBy as UserOrder,prequestdt.user_name as UserApp, PRqstDt_id as preqstdtid
					from prequest ";
					
	if ($projectexist >	0)
		$querysearch= $querysearch. " Inner join ( select distinct project_code from ".$_SESSION['dbLabel'].".loginstk ".
									"			   where loginstk.user_account='".$_SESSION['useraccount']."' ".
									"              and (project_code is not null and project_code != '') ".
									"			 ) Q1 on (($Module_ProjectParent=1 and prequest.project_code like concat(Q1.project_code,'%')) or ($Module_ProjectParent=0 and prequest.project_code = Q1.project_code )) ";
						
	$querysearch= $querysearch." left join project on project.project_code = prequest.project_code
								left join costcent on costcent.costcent_code = prequest.costcent_code
								,prequestdt left join items on items.item_code=prequestdt.item_code
								left join project project1 on project1.project_code = prequestdt.project_code
								left join costcent costcent1 on costcent1.costcent_code = prequestdt.costcent_code ";

	$querysearch= $querysearch." where prequest.prqst_id = prequestdt.prqst_id  
								 and if('$itemcode[0]'='',1=1,prequestdt.item_code='$itemcode[0]')
								 and if('$PRef'='',1=1,prequest.prqst_reference='$PRef')	
								 and date_format(prequest.prqst_date,'%Y-%m-%d') between ifnull('". explodedate($fromdate)."', date_format(prequest.prqst_date,'%Y-%m-%d')) and ifnull('". explodedate($todate)."', date_format(prequest.prqst_date,'%Y-%m-%d')) ";
								
	if ($PProjectCode != '')
		$querysearch= $querysearch." And prequest.project_code like concat('".$PProjectCode."','%') ";
	if ($PCostCentCode != '')
		$querysearch= $querysearch." And prequest.costcent_code like concat('".$PCostCentCode."','%') ";
	
	if ($PRequestedBy != '')
		$querysearch= $querysearch." And prequest.prqst_requestBy like concat('".$PRequestedBy."','%') ";
	
	if ($PWarehouseCode != '')
		$querysearch= $querysearch." And prequestdt.warehouse_code like concat('".$PWarehouseCode."','%') ";
									 
	if($itemstatus != '') {
		if($itemstatus == '1') {
			$querysearch = $querysearch." and (ifnull(Prqst_Confirmed,0) = 0 and ifnull(Prqst_Cancelled,0) = 0)";
		} 
		else if($itemstatus == '2') {
			$querysearch = $querysearch." and ifnull(Prqst_Confirmed,0) = 1 and ((ifnull(PRqstDt_status,'x') = 'x' and 1 = 1) or (ifnull(PRqstDt_status,'x') = 'a' and PRqstDt_approvedlevel > $PrequestApproved_Level)) ";
		} 
		else if($itemstatus == '3') {
			$querysearch = $querysearch." and ifnull(Prqst_Confirmed,0) = 1 and (ifnull(PRqstDt_status,'x') = 'a' or ifnull(PRqstDt_status,'x') = 'u') and PRqstDt_approvedlevel <= $PrequestApproved_Level ";
		}
		else if($itemstatus == '4') {
			$querysearch = $querysearch." and ifnull(PRqstDt_status,'x') = 'r' ";
		}
		else if($itemstatus == '5') {
			$querysearch = $querysearch." and PRqstDt_Quantity=0 ";
		}
		else if($itemstatus == '6') {
			$querysearch = $querysearch." and ifnull(PRqstDt_status,'x') = 'u' and not exists (select 1 from porderdt where porderdt.relateddt_id = prequestdt.PRqstDt_id) ";
		}
		else if($itemstatus == '7') {
			$querysearch = $querysearch." and ifnull(PRqstDt_status,'x') = 'u' and exists (select 1 from porderdt where porderdt.relateddt_id = prequestdt.PRqstDt_id and ifnull(porderdt.porderdt_approvedstatus,'x') = 'x') ";
		} 
		else if($itemstatus == '8') {
			$querysearch = $querysearch." and ifnull(PRqstDt_status,'x') = 'u' and exists (select 1 from porderdt where porderdt.relateddt_id = prequestdt.PRqstDt_id and ifnull(porderdt.porderdt_approvedstatus,'x') = 'a' ) ";
		}
		else if($itemstatus == '9') {
			$querysearch = $querysearch." and ifnull(PRqstDt_status,'x') = 'u' and exists (select 1 from porderdt where porderdt.relateddt_id = prequestdt.PRqstDt_id and ifnull(porderdt.porderdt_approvedstatus,'x') = 'r' ) ";
		}
		else if($itemstatus == '10') {
			$querysearch = $querysearch." and ifnull(PRqstDt_status,'x') = 'u' and exists (select 1 from porderdt where porderdt.relateddt_id = prequestdt.PRqstDt_id and ifnull(porderdt.porderdt_approvedstatus,'x') = 'a' and ifnull(porderdt_grnrejected,0) != 1 and not exists (select 1 from GrnPurchasesDt where GrnPurchasesDt.RelatedDt_Id = porderdt.PorderDt_id and GrnPurchasesDt.Journal_Type = 'PI')) ";
		}
		else if($itemstatus == '11') {
			$querysearch = $querysearch." and ifnull(PRqstDt_status,'x') = 'u' and exists (select 1 from porderdt where porderdt.relateddt_id = prequestdt.PRqstDt_id and ifnull(porderdt.porderdt_approvedstatus,'x') = 'a' and ifnull(porderdt_grnrejected,0) != 1 and exists ( select 1 from GrnPurchasesDt where GrnPurchasesDt.RelatedDt_Id = porderdt.PorderDt_id and GrnPurchasesDt.Journal_Type = 'PI' )) ";
		}
		else if($itemstatus == '12') {
			$querysearch = $querysearch." and ifnull(PRqstDt_status,'x') = 'u' and exists (select 1 from porderdt where porderdt.relateddt_id = prequestdt.PRqstDt_id and ifnull(porderdt_grnrejected,0) = 1 ) ";
		}
		else if($itemstatus == '13') {
			$querysearch = $querysearch." and ifnull(Prqst_Cancelled,0) = 1  ";
		}
	}
	
					
	if($priority != '') {
		$querysearch = $querysearch." and ifnull(PRqst_Priority,-1) = '".$priority."' ";
	}
					
	/*if($Module_PRequestConfirm == 1) {
		$querysearch = $querysearch." and ifnull(Prqst_Confirmed,0) = 1 ";
	}*/
					
	$querysearch = $querysearch."order by prequest.prqst_date";
					
	/*
	if ($projectexist >	0)
	  $querysearch= $querysearch." Inner join ( select distinct project_code from ".$_SESSION['dbLabel'].".loginstk ".
								 "			   where loginstk.user_account='".$_SESSION['useraccount']."' ".
								 "             and (project_code is not null and project_code != '') ".
								 "			 ) Q1 on (($Module_ProjectParent=1 and Sorder.project_code like concat(Q1.project_code,'%')) or ($Module_ProjectParent=0 and Sorder.project_code = Q1.project_code )) ";
								 
	if ($costcentexist > 0)
	  $querysearch= $querysearch." Inner join ( select distinct costcent_code from ".$_SESSION['dbLabel'].".loginstk ".
								 "			   where loginstk.user_account='".$_SESSION['useraccount']."' ".
								 "             and (costcent_code is not null and costcent_code != '') ".
								 "			 ) Q2 on (($Module_CostCenterParent=1 and Sorder.costcent_code like concat(Q2.costcent_code,'%')) or ($Module_CostCenterParent=0 and Sorder.costcent_code = Q2.costcent_code )) ";

	*/							 





	//echo $querysearch;
	//echo $querysearch; exit;

	$resultsearch=mysql_query($querysearch,$connection) or die(mysql_error());
	$totalrows = mysql_num_rows($resultsearch);
		
	if ($startrange=='' || $PRef != 'Null')
		$startrange = 0;
	if ($perpage=='')
		$perpage = 200;
			
	//$querysearch = $querysearch." limit ".$startrange.",".$perpage;

	$resultsearch=mysql_query($querysearch,$connection) or die(mysql_error());	
		
	//echo $querysearch;
	$i = 0;
	$k = 1;
	$ref = '';
	
	echo"<div id='grid_contentDiv' class='grid_contentDiv' style='height:250px;' onscroll=\"ScrollHeader('grid_headerDiv','grid_contentDiv')\">";
	echo"<table  cellspacing='2' cellpadding='2' style='table-layout:fixed; width:2075px;' class='grid_data1' >
		  <col width=25>
		  <col width=25>
		  <col width=25>
		  <col width=$widthsize>
		  <col width=70>
		  <col width=70>
		  <col width=80>
		  <col width=120>
		  <col width=120>
		  <col width=200>
		  <col width=100>
		  <col width=120>
		  <col width=120>
		  <col width=110>
		  <col width=70>
		  <col width=80>
		  <col width=70>
		  <col width=70>
		  <col width=70>
		  <col width=60>
		  <col width=400>";
		  
	while($rows=mysql_fetch_array($resultsearch)){
		
		
		extract($rows);
		
		$p = ''; $a = ''; $r = ''; $u = '';
		if ($PRqstDt_status=='a')		$a = ' checked ';
		else if ($PRqstDt_status=='r')	$r = ' checked ';
		else if ($PRqstDt_status=='u')	$u = ' checked ';	
		else $p = ' checked ';

			
		$sub_query  = " select if(ifnull(porderdt_grnrejected,0)=1, 'GRN Rejected', if(ifnull(porderdt_approvedstatus,'x')='a', 'LPO Approved', if(ifnull(porderdt_approvedstatus,'x')='r', 'LPO Rejected', 'LPO Pending Approval'))) ".
					  " from porder inner join porderdt on porderdt.porder_id = porder.porder_id ".
					  " where porderdt.relateddt_id = '".$PRqstDt_id."' ";
		$sub_result = mysql_query($sub_query,$connection) or die(mysql_error());
		$sub_rows = mysql_fetch_array($sub_result);
			
		$sub_query1  = " select count(*) from GrnPurchases where GrnPurchases.Porder_Ref = (select Porder_reference from porder where Prequest_Ref = '".$prqst_reference."' limit 1) and GrnPurchases.Journal_Type = 'PI' ";
		$sub_result1 = mysql_query($sub_query1,$connection) or die(mysql_error());
		$sub_rows1   = mysql_fetch_array($sub_result1);
		
		
		if ($PRqstDt_status=='u' && $sub_rows[0]==''){
			$PRequestStatus = 'LPO Working On';
		}	
		else if ($PRqstDt_status=='u' && $sub_rows[0]!='' && strtoupper(TRIM($sub_rows[0])) != 'LPO APPROVED') { 
			$PRequestStatus = $sub_rows[0];
		}
		else if ($PRqstDt_status=='u' && $sub_rows[0]!='' && strtoupper(TRIM($sub_rows[0])) == 'LPO APPROVED') {
			$PRequestStatus = 'GRN Pending';
			if ($sub_rows1[0] > 0) $PRequestStatus = 'GRN Approved';
		}		
		else if ($PRqstDt_status != 'u') {
			$PRequestStatus = $PRqstDtStatus;	
		}
		
		if ($ref != $PRqst_id)
		{	
			$k = 1;
			
			if ($ref != $PRqst_id && $ref != '') {
				echo"</table>";
				echo"</div></td></tr>";
			}

			
			
			if ($RefProject==1) {	
			
			$sub_query2  = " select Purchase_Reference from GrnPurchases where GrnPurchases.Porder_Ref = (select Porder_reference from porder where Project_code='".$prequestproject_code."' and Prequest_Ref = '".$prqst_reference."' limit 1) and GrnPurchases.Journal_Type = 'PI' Limit 1";
			
			} else {
			
			$sub_query2  = " select Purchase_Reference from GrnPurchases where GrnPurchases.Porder_Ref = (select Porder_reference from porder where Prequest_Ref = '".$prqst_reference."' limit 1) and GrnPurchases.Journal_Type = 'PI' Limit 1";
			
			}
			
			
			$sub_result2 = mysql_query($sub_query2,$connection) or die(mysql_error());
			$sub_rows2   = mysql_fetch_array($sub_result2);
			$GRNRef = $sub_rows2[0];
			
			//if 
			if ($RefProject==1) {			
			$sub_query2  = " select Porder_reference from porder where Project_code='".$prequestproject_code."'   and Prequest_Ref = '".$prqst_reference."' limit 1 ";
			} else {
			$sub_query2  = " select Porder_reference from porder where Prequest_Ref = '".$prqst_reference."' limit 1 ";
			}
			
			$sub_result2 = mysql_query($sub_query2,$connection) or die(mysql_error()); 
			$sub_rows2   = mysql_fetch_array($sub_result2);
			$PorderRef = $sub_rows2[0];
		
		
			//if ($ref != '') echo"<tr ><td colspan=16><hr></td></tr>";
			echo"<tr height=35px bgcolor='#0086B2'>";
			echo'<td align=center><span class="style5"><img src="img/details.png" onMouseOver="style.cursor=\'hand\'"  onclick="ShowHideDetails('.$PRqst_id.', \''.'S'.'\','.$startrange.');" title="Show Details" style="width:20px; height:20px; "></span></td>';
			echo '	<td align=center><span class="style5"><img src="img/openlist.png" onMouseOver="style.cursor=\'hand\'"  onclick="UploadDocuments('.$PRqst_id.', \''.'prequest'.'\');" title="Upload Documents" style="width:20px; height:20px; "></span></td>';
			
			if (($Module_PrintApprovedRqst == 1 && ($PRqstDt_status=='a' || $PRqstDt_status=='u')) || ($Module_PrintApprovedRqst != 1 && 1 == 1))
				echo '<td align=center><span class="style5"><img src="img/print.png" onMouseOver="style.cursor=\'hand\'"  onclick="PrintPreview('.$PRqst_id.', \''.'PR'.'\');" title="Print" style="width:20px; height:20px; "></span></td>';
			else
				echo '<td align=center><span class="style5">&nbsp;</span></td>';
				
			echo"	<td align=center>";
			
			if ($Module_PRequestConfirm == 1 && $FI_PRequestConfirmed == 1 && $Prqst_Confirmed != 1 && $itemstatus == 1) {
				echo"<input type='button' name='btnconf$i' onclick=\"ConfirmRequest('$PRqst_id','$prqst_reference');\" value='C' title='Confirm Request'>";
				echo" &nbsp;<input type='button' name='btncancel$i' onclick=\"CancelRequest('$PRqst_id','$prqst_reference');\" value='X' title='Cancel Request'>";
			}		
					
			echo"	$prqst_reference</td>	";
			echo"	<td>$PorderRef</td>";
			echo"	<td>$GRNRef </td>";
			echo"	<td>$prqst_date</td><td align=center>";
				
			if ($Module_Project == 1) echo "<span title='$project_name'>$prequestproject_code</span>";
			echo"</td><td align=center>";
				
			if ($ShowCostCentLayout_Purchase == 1)	echo "<span title='$costcent_name'>$prequestcostcent_code</span>";
				
			echo"</td><td><input type='text' name='rejectedreason$i' id='rejectedreason$i' value='$rejectedreason'></td>";
			echo"<td><span class='style1'>&nbsp;</span></td>";
			echo"<td><span class='style1'>$user_name</span></td>";
			echo"<td><span class='style1'>$UserOrder</span></td>";
			echo"<td><span class='style1'>$UserApp</span></td>";
			echo"<td><span class='style1'>$PRqst_Priority</span></td>";
			echo"<td colspan='3' align=left>";
			
			 if ($itemstatus == '2' || $itemstatus == '3' || $itemstatus == '4')
				echo"<span class='style15'><input type='radio' name='r1' id='r1' value='p'  onclick=\"updateheader('$PRqst_id',this.value,'PRQ','rejectedreason$i') ;return false;\"  onMouseOver=\"style.cursor='pointer'\" ><font color=#FFFFFF><b>Pend.</b></font></span>";
			if ($Login_PReqReject == 1 && ($itemstatus == '2' || $itemstatus == '4'))
				echo"<span class='style15'><input type='radio' name='r1' id='r1' value='r'  onclick=\"updateheader('$PRqst_id',this.value,'PRQ','rejectedreason$i') ;return false;\"  onMouseOver=\"style.cursor='pointer'\" ><font color=#FF0000><b>Rej.</b></font></span>";
			
			if ($PendingProcess==1) {
			if ($Login_PReqApprove == 1 && ($itemstatus == '2' || $itemstatus == '5'))
				echo"<span class='style15'><input type='radio' name='r1' id='r1' value='a'  onclick=\"updateheader('$PRqst_id',this.value,'PRQ','rejectedreason$i') ;return false;\"  onMouseOver=\"style.cursor='pointer'\" ><font color=#DAA520>App.</font></span>";
			} else {
			if ($Login_PReqApprove == 1 && ($itemstatus == '2' || $itemstatus == '5'))
				echo"<span class='style15'><input type='radio' name='r1' id='r1' value='u'  onclick=\"updateheader('$PRqst_id',this.value,'PRQ','rejectedreason$i') ;return false;\"  onMouseOver=\"style.cursor='pointer'\" ><font color=#DAA520>App.</font></span>";
			
			}
			if ($Login_PReqUndProc == 1 && $itemstatus == '5')
				echo"<span class='style15'><input type='radio' name='r1' id='r1' value='u'  onclick=\"updateheader('$PRqst_id',this.value,'PRQ','rejectedreason$i') ;return false;\"  onMouseOver=\"style.cursor='pointer'\" ><font color=#FFFFFF size=1>Working On</font></span>";	
 
				
			$querycheck = "select sum(ifnull(TransferrequestDt_Quantity,0)) from transferrequestdt,transferrequest where transferrequest.prqst_id = $PRqst_id
							and transferrequest.transferrequest_id = transferrequestdt.transferrequest_id";
			$resultcheck=mysql_query($querycheck,$connection) or die(mysql_error());	
			$rowcheck=mysql_fetch_array($resultcheck);
			$tot1 = $rowcheck[0];
				//echo $querycheck;
			$querycheck = " select sum(ifnull(PRqstDt_OQuantity,0)) - sum(ifnull(PRqstDt_CQuantity,0))
							from prequestdt,prequest where prequestdt.PRqst_id = prequest.PRqst_id
							and prequest.PRqst_id= $PRqst_id ";
				//	echo $querycheck;		
			$resultcheck=mysql_query($querycheck,$connection) or die(mysql_error());	
			$rowcheck=mysql_fetch_array($resultcheck);
			
				//$tot1 = $rowcheck[1];
				$tot2 = $rowcheck[0];

				
			if ( $tot2 == 0  )		
				$stat = ' disabled';
			else	
				$stat = '  ';
			
			
			echo"</td>";
			echo"<td align='center' colspan='3'>";
			if($FI_TransferRequest == 1 && $itemstatus == '2')
				echo"<input type='button' name='crt$i' $stat onclick=\"createtransferrequest('$PRqst_id');\" value='Transfer Req.'>";
				
			if($FI_StockOutRequest == 1)
				echo"&nbsp;&nbsp;&nbsp;<input type='button' name='crt$i' $stat onclick=\"createstockoutrequest('$PRqst_id');\" value='Stock Out Req.'>";
			echo"</td>";
			
			
			echo"<td colspan='3'>&nbsp;</td>";
			echo"</tr>";
			
			$SlideDivId = 'displaydetails'.$PRqst_id;
			echo'<tr>';	
			echo"<td colspan='18' valign='top' align='left'><div id='$SlideDivId' style='display:none;'>";
			echo"<table  cellspacing='2' cellpadding='2' style='table-layout:fixed; width:2075px;' class='grid_data1' >
				  <col width=25>
				  <col width=25>
				  <col width=25>
				  <col width=$widthsize>
				  <col width=70>
				  <col width=70>
				  <col width=80>
				  <col width=120>
				  <col width=120>
				  <col width=200>
				  <col width=100>
				  <col width=120>
				  <col width=120>
				  <col width=110>
				  <col width=70>
				  <col width=80>
				  <col width=70>
				  <col width=70>
				  <col width=70>
				  <col width=60>
				  <col width=400>";
		}
			
		
		
		$ct+=1;
		$i = $i + 1;

		if($ct%2==0)
			$Color="style='background-color:".$grid_color1."'";
		else			
			$Color="style='background-color:".$grid_color2."'";	
		
	
		
		if ($PRqstDt_approvedlevel=='')
			$canchange = ' ';
		else	
		if ( ($PrequestApproved_Level > $PRqstDt_approvedlevel)  )
			$canchange = 'disabled ';
		else 	
			$canchange = ' ';

		echo'<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>';	
		echo "<td colspan=5><span class='style15'>";

		//stopped by elie 
		//$item_code";

		$$val = $item_code;

		//stopped by elie 
		//if ($item_code=='')
		
				

		echo"<span class='style4'><input type='text' style='width:130px;font-size:11px'  name='item_code$i' id='item_code$i' value='".$$val."'   
		$KeyDown   class='roundedtext_amortization_small' readonly  onchange=\"setitemcode(this.value,'item_code".$i."','item_description".$i."','','','','','','','',1);\"  style='width:100px'></span>";
			
		if (($item_description1!='') && ($FI_ItemsApp==1))
			echo"<img src='img/scroll-down-1.png' width='20' height='20' id='trqstdtitemcodeimage$i' onmouseover=\"style.cursor='pointer'\"  onclick=\"showsearchpage('itemcode','item_code$i','item_description$i','800','500')\">";

		echo"</span>";

		//stopped by elie 
		//$item_description";

		$$val=$item_description;
		//if ($item_description=='')
		$xx = $prequestdt_availableqty;
		
		echo "&nbsp;<input type='text' style='width:270px;font-size:11px' value='".$$val."' name='item_description$i' readonly id='item_description$i'>";
		//echo "&nbsp;AQ.<input type='text' name='prequestdt_availableqty$i' id='prequestdt_availableqty$i'  value='$xx' onchange='submitavailable($PRqstDt_id,$i)' style='width:30'> ";
		//if ($item_description=='')	//elie	
		if (($item_description1!='') && ($FI_ItemsApp==1))
			echo"<img src='img/confirm-1.png' onmouseover=\"style.cursor='pointer'\" name='imgSubmitPTransReqDt[$i]' id='imgSubmitPTransReqDt[$i]' title='Save' onclick=\"submitItemDt('$PRqstDt_id','$i','1')\">";
		
		echo"</span></td>";


		echo "<td align='left'><span class='style15'>$item_description1</span></td>";
		echo "<td align='left'><span class='style15'>$PRequestStatus</span></td>";

		if ($Module_ProjectDt == 1)
			echo "<td align='left'><span class='style15'>$project_code</span></td>";
		else
			echo "<td align='left'><span class='style15'>&nbsp;</span></td>";

		if ($ShowCostCentLayout_Purchase == 1)
			echo "<td align='left'><span class='style15' title=' $prequestdtcostcent_name ' >$costcent_code</span></td>";
		else
			echo "<td align='left'><span class='style15'>&nbsp;</span></td>";
		
		$trans = 'transferqty[$i]';
		
		if($transferwarehousecode[$i] == '')
		$transferwarehousecode[$i] = $defaultwarehouse;
		
		if($transferwarehousecode[$i] != ''){
			$q2 = "select ifnull(QtyExists(prequestdt.item_code , '$transferwarehousecode[$i]', prequest.prqst_date, 0, 'PQ', '', ''),0) as qtyexists
					from prequest left join project on project.project_code = prequest.project_code
					left join costcent on costcent.costcent_code = prequest.costcent_code ,prequestdt
					left join items on items.item_code=prequestdt.item_code left join project project1 on project1.project_code = prequestdt.project_code
					left join costcent costcent1 on costcent1.costcent_code = prequestdt.costcent_code
					where prequest.prqst_id = prequestdt.prqst_id
					and prequestdt.PRqstDt_id = $PRqstDt_id;"; 
			$res2 = mysql_query($q2,$connection);
			$rw2 = mysql_fetch_row($res2);
			$qtyexists = $rw2[0];
		}
		
		echo"<td align='left'><span class='style15'>";
		if($itemstatus == 13) echo $transferwarehousecode[$i];
		else echo"	<input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='width:70px'  name='transferwarehousecode[$i]' id='transferwarehousecode[$i]' value='".$transferwarehousecode[$i]."' onchange=\"setwarehousecode(this.value,'transferwarehousecode[$i]','imgwarehousebtn[$i]');SetModRecord('ModRec_G1','$i');\"  > </span>
				<img src='img/scroll-down-1.png' title=' Select Warehouse ' id='imgwarehousebtn[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  onclick=\"showlistWarehouse('warehousecode','transferwarehousecode[$i]','transferqty[$i]','800','500','$item_code','$prqst_date') \" />";
		echo"</span></td>";
		echo"<td align='left'><span class='style15'>";
		if($itemstatus == 13) echo $qtyexists;
		else echo "<input name='transferqty[$i]' id='transferqty[$i]' value='$qtyexists' readonly style='width:40px;border-color:#F8F8F8;'>";
		echo "</span></td>";
		echo"<td align='left'><span class='style15'>$warehouse_code</span></td>";
		if($itemstatus == 13) {
			echo"<td align='left'><span class='style15'>$PRqstDt_OQuantity</span></td>";
		echo"<td align='left'><span class='style15'>$PRqstDt_CQuantity</span></td>";
		
		} else {
		echo"<td align='left'><span class='style15'><input type='text' name='PRqstDt_OQuantity[$i]'  $canchange value='$PRqstDt_OQuantity' id='PRqstDt_OQuantity[$i]' onchange=\"updatequantity('$i','$PRqstDt_id')\" style='width:40px;border-color:#F8F8F8'></span></td>";
		echo"<td align='left'><span class='style15'><input type='text' name='PRqstDt_CQuantity[$i]'  $canchange value='$PRqstDt_CQuantity' id='PRqstDt_CQuantity[$i]'  onchange=\"updatequantity('$i','$PRqstDt_id')\"  style='width:40px;border-color:#F8F8F8'></span></td>";
		}
		echo"<td align='left'><span class='style15'><input type='text' readonly name='PRqstDt_Quantity[$i]'  $canchange value='$PRqstDt_Quantity' id='PRqstDt_Quantity[$i]' style='width:40px;border-width:0px;background-color:transparent'></span></td>";
		echo"<td align='left'><span class='style15'>$Item_UnitSalesDesc</span></td>";
		
		echo"<td align='left'><span class='style15'>";
	
		if ($itemstatus == '2' || $itemstatus == '3' || $itemstatus == '4')
			echo"<input type='radio' name='r1$i' id='r1$i' value='p' $p $canchange onclick=\"updatedt('$PRqstDt_id',this.value,'PRQ','$PrequestApproved_Level','prequestrejectedreason$i','$i')\"  onMouseOver=\"style.cursor='pointer'\" ><font color=#DAA520 size=1>Pend.</font>";
		if ($Login_PReqReject == 1 && ($itemstatus == '2' || $itemstatus == '4'))
			echo"<input type='radio' name='r1$i' id='r1$i' value='r' $r  $canchange onclick=\"updatedt('$PRqstDt_id',this.value,'PRQ','$PrequestApproved_Level','prequestrejectedreason$i','$i')\" onMouseOver=\"style.cursor='pointer'\" ><font color=#FF0000>Rej.</font>";
		
		if ($PendingProcess==1) {
		if ($Login_PReqApprove == 1 && ($itemstatus == '2' || $itemstatus == '3'))
			echo"<input type='radio' name='r1$i' id='r1$i' value='a' $a  $canchange onclick=\"updatedt('$PRqstDt_id',this.value,'PRQ','$PrequestApproved_Level','prequestrejectedreason$i','$i')\"  onMouseOver=\"style.cursor='pointer'\" ><font color=#DAA520>App.</font>";
		
		} else {
		if ($Login_PReqApprove == 1 && ($itemstatus == '2' || $itemstatus == '3'))
			echo"<input type='radio' name='r1$i' id='r1$i' value='u' $u  $canchange onclick=\"updatedt('$PRqstDt_id',this.value,'PRQ','$PrequestApproved_Level','prequestrejectedreason$i','$i')\"  onMouseOver=\"style.cursor='pointer'\" ><font color=#DAA520>App.</font>";
		
		}
		if ($Login_PReqUndProc == 1 && $itemstatus == '5')
			echo"<input type='radio' name='r1$i' id='r1$i' value='u' $u  $canchange onclick=\"updatedt('$PRqstDt_id',this.value,'PRQ','$PrequestApproved_Level','prequestrejectedreason$i','$i',$module_CheckItem)\"  onMouseOver=\"style.cursor='pointer'\" ><font color=#DAA520 size=1>Working On</font>";
		if($itemstatus == '5') $txtreadonly = 'readonly';
		else $txtreadonly = '';
		echo"	<input type='text' name='prequestrejectedreason$i' id='prequestrejectedreason$i' value='$prequestrejectedreason' style='width:170px' $txtreadonly>
			</span></td>";
		echo"</tr>";
		
		
		$ref = $PRqst_id;
		$PRqstDt_status = '';
		$a = '';
		$c = '';
		$r = '';


		$k+=1;
	}
	
	
	//Ending Detail Div
	if ($ref != '') {
		echo"</table>";
		echo"</div></td></tr>";
	}

	echo"</table></div></div>";
	echo"</td></tr>";

} //end of purchaserequest




if ($fi_pendingpurchaseorder==1 && $transtype=='o' ){

	echo"<tr bgcolor='#F7F7F7'><td valign='top' align='left' colspan='6'>
		  <div id='container' style='width:1090px; height:330px;'>
		  <div id='grid_headerDiv' class='grid_headerDiv' style='height:80px;'>
		  <table  cellspacing='2' cellpadding='2' style='table-layout:fixed; width:1835px;' class='grid_data1'>
		  <col width=25>
		  <col width=25>
		  <col width=25>
		  <col width=70>
		  <col width=80>
		  <col width=70>
		  <col width=80>
		  <col width=100>
		  <col width=120>
		  <col width=120>
		  <col width=120>
		  <col width=120>
		  <col width=110>
		  <col width=80>
		  <col width=60>
		  <col width=50>
		  <col width=100>
		  <col width=120>
		  <col width=120>
		  <col width=120>
		  <col width=120>
		  <col width=120>
		  <col width=120>
		  <col width=120>
		  <col width=120>";
		  
	echo"<tr><td colspan='16' align=center><u><font color=red>Purchase Order</font></u></td></tr>";
	echo"<tr><td height='15' align='center' colspan='22'><font size='1' color='#FF0000' face='Verdana'><b>".$message."</b></font></td></tr>	";
	echo"<tr bgcolor='#DAA520'>
			<th  height='25' align='left'>&nbsp;</th>
			<th  height='25' align='left'>&nbsp;</th>
			<th  height='25' align='left'>&nbsp;</th>
			<th  height='25' align='left'>Ref.</th>
			<th  height='25' align='center'>MSR</th>
			<th  height='25' align='center'>GRN</th>
			<th  height='25' align='center'>Date </th>
			<th  height='25' align='center'>Delivery Date</th>";
		
	if ($Module_Project == 1)
		echo"<th align='center'>Project</th>";
	else
		echo"<th align='center'>&nbsp;</th>";

	if ($ShowCostCentLayout_Purchase == 1)
		echo"<th align='center'>Costcenter</th>";
	else
		echo"<th align='center'>&nbsp;</th>";
		
	echo"	<th align='center'>Supplier</th>";
	echo"	<th align='center'>Approved By</th>";
	echo"	<th align='center'>Status</th>";
	echo"	<th  height='25' align='center' colspan=4>Reason of Rejecting </th>";
	echo"	<th  height='25' align='center'>&nbsp;</th>";
	echo"	<th  height='25' align='center'>Requested By</th>";
	echo"	<th  height='25' align='center'>Created By</th>";
	
	echo"	<th  height='25' align='center'>Total Amount</th>";
	echo"	<th  height='25' align='center'>Paid Amount</th>";
	echo"	<th  height='25' align='center'>Remain Amount</th>";
	echo"	<th  height='25' align='center'>Down Pay %</th>";
	echo"	<th  height='25' align='center'>Down Amount</th>";
	echo" </tr>";
		
	echo"<tr bgcolor='#a8a8a8' >
			<th>&nbsp;</th>
			<th>&nbsp;</th>
			<th>&nbsp;</th>
			<th>&nbsp;</th>
			<th align='left' colspan=4>Item Code \ Description</th>
			<th align='left' colspan=2>Description1</th>";
			
	if ($Module_ProjectDt == 1)
		echo"<th align='center'>Project</th>";
	else
		echo"<th align='center'>&nbsp;</th>";

	if ($ShowCostCentLayout_Purchase == 1)			
		echo"<th align='left'>Costcenter</th>";
	else
		echo"<th align='center'>&nbsp;</th>";
		
	echo"	<th align='center'>&nbsp;</th>
			<th align='center'>Warehouse</th>
			<th align='center'>Qty</th>
			<th align='center'>Unit</th>
			<th align='center'>Curr</th>
			<th align='center'>Price</th>
			<th align='center'>Last Price</th>
			<th align='center'>Total</th>
			<th align='center' colspan='6'>&nbsp</th>";

	echo"</tr>";
	echo"</table></div>";

	

	if (empty($ViewPeriodDate))
	   $ViewPeriodDate = 'Null';
	if (empty($ViewNumberOfDays))   
	   $ViewNumberOfDays = 1;
			


	// purchase order part	
	$querysearch=" select porder.porder_reference as porder_reference,date_format(porder.porder_date,'%d/%m/%Y') as porderdate,porder.currency_code as currency_code
					,porder.porder_total as porder_total,porderdt.item_code as item_code,items.item_description as item_description,null as item_description1 
					,null,null,porderDt_Quantity as porderdt_quantity,PRqstDt_id,porder.porder_id as porder_id,porder.rejectedreason
					,porderdt.warehouse_code,porder.project_code as porderproject_code,porder.costcent_code as pordercostcent_code,porderdt.project_code as project_code,porderdt.costcent_code as costcent_code
					,null as qtyexists,porder.user_name as user_name,porderdt_id,porder_approvedlevel,porder_approvedstatus,approvedby
					,project.project_name porderproject_name,costcent.costcent_name as pordercostcent_name
					,project1.project_name porderdtproject_name,costcent1.costcent_name as porderdtcostcent_name,prequest.PRqst_reference as porder_prequestref,porder.Prequest_Ref
					,porderdt_price, (ifnull(porderdt_price,0)*ifnull(porderdt_quantity,0)) as porderdt_total
					,if(ifnull(Porder_Confirmed,0)=0, 'Working On', if(ifnull(porderdt_grnrejected,0)=1, 'GRN Rejected', if(ifnull(porderdt_approvedstatus,'x')='x', 'Pending Approval', if(ifnull(porderdt_approvedstatus,'x')='r', 'Rejected', '')))) as PorderDtStatus
					,date_format(porder.porder_requestdate,'%d/%m/%Y') as requestdate, Items.Item_UnitSalesDesc as Item_UnitSalesDesc 
					,(Porder.Porder_Total + IfNull(Porder.Porder_Vat,0) - IfNull(Porder.Porder_DiscountAmount,0) +  (ifNull(Porder.Porder_Tax1,0) + ifNull(Porder.Porder_Tax2,0) + ifNull(Porder.Porder_Tax3,0) + ifNull(Porder.Porder_Tax4,0) + ifNull(Porder.Porder_Tax5,0))) As nettotal  
					,suppliers.Ledger_name as suppliername, ifNull(Porder_Confirmed,0) as Porder_Confirmed, ifnull(porderdt_approvedlevel,5000) as porderdt_approvedlevel, porderdt_approvedstatus, ifnull(porderdt_grnrejected,0) as porderdt_grnrejected
					,GrnPurchases.Purchase_Reference as GRNPurchase_Reference,Porder.porder_downperc as DownPer,Porder.porder_downamount as DownAmount,Porder.user_account as CreatedUser,Porder.Porder_RequestBy as RequestedUser
					from porder ";
					
	if ($projectexist >	0) {
		$querysearch= $querysearch." Inner join ( select distinct project_code from ".$_SESSION['dbLabel'].".loginstk ".
								 "			   where loginstk.user_account='".$_SESSION['useraccount']."' ".
								 "             and (project_code is not null and project_code != '') ".
								 "			 ) Q1 on (($Module_ProjectParent=1 and porder.project_code like concat(Q1.project_code,'%')) or ($Module_ProjectParent=0 and porder.project_code = Q1.project_code )) ";
	}
						
						
	$querysearch= $querysearch." left join project on project.project_code = porder.project_code
								left join costcent on costcent.costcent_code = porder.costcent_code
								left join prequest  on prequest.prqst_id = porder.PRqst_id
								left join GrnPurchases on GrnPurchases.Porder_Ref = porder.porder_reference and GrnPurchases.Journal_Type = 'PI'
								left join suppliers on suppliers.ledger_number = porder.Supplier_code
								,porderdt left join items on items.item_code=porderdt.item_code
								left join project project1 on project1.project_code = porderdt.project_code
								left join costcent costcent1 on costcent1.costcent_code = porderdt.costcent_code ";
				
	$querysearch= $querysearch." where porder.porder_id = porderdt.porder_id 
								 and if('$itemcode[0]'='',1=1,porderdt.item_code='$itemcode[0]')
								 and if('$PRef'='',1=1,porder.porder_reference='$PRef')	
								 and date_format(porder.porder_date,'%Y-%m-%d') between ifnull('". explodedate($fromdate)."', date_format(porder.porder_date,'%Y-%m-%d')) and ifnull('". explodedate($todate)."', date_format(porder.porder_date,'%Y-%m-%d')) ";
						
	if ($PProjectCode != '')
		$querysearch= $querysearch." And porder.project_code like concat('".$PProjectCode."','%') ";
	if ($PCostCentCode != '')
		$querysearch= $querysearch." And porder.costcent_code like concat('".$PCostCentCode."','%') "; 
	if ($PRequestedBy != '')
		$querysearch= $querysearch." And Porder.Porder_RequestBy like concat('".$PRequestedBy."','%') ";
	
	if($itemstatus != '') {
		if($itemstatus == '1') {
			$querysearch = $querysearch." and ifnull(Porder_Confirmed,0) = 0 ";
		}
		else if($itemstatus == '2' && $Module_PorderConfirm != 1) {
			$querysearch = $querysearch." and ((ifnull(porderdt_approvedstatus,'x') = 'x' and 1 = 1) or (ifnull(porderdt_approvedstatus,'x') = 'a' and porderdt_approvedlevel > $PurorderApproved_Level)) ";
		} 
		else if($itemstatus == '2' && $Module_PorderConfirm == 1) {
			$querysearch = $querysearch." and ifnull(Porder_Confirmed,0) = 1 and ((ifnull(porderdt_approvedstatus,'x') = 'x' and 1 = 1) or (ifnull(porderdt_approvedstatus,'x') = 'a' and porderdt_approvedlevel > $PurorderApproved_Level)) ";
		} 
		else if($itemstatus == '3' && $Module_PorderConfirm != 1) {
			$querysearch = $querysearch." and ifnull(porderdt_approvedstatus,'x') = 'a' and porderdt_approvedlevel <= $PurorderApproved_Level ";
		}
		else if($itemstatus == '3' && $Module_PorderConfirm == 1) {
			$querysearch = $querysearch." and ifnull(Porder_Confirmed,0) = 1 and ifnull(porderdt_approvedstatus,'x') = 'a' and porderdt_approvedlevel <= $PurorderApproved_Level ";
		}
		else if($itemstatus == '4') {
			$querysearch = $querysearch." and ifnull(porderdt_approvedstatus,'x') = 'r' ";
		}
		else if($itemstatus == '12') {
			$querysearch = $querysearch." and ifnull(porderdt_approvedstatus,'x') = 'a' and ifnull(porderdt_grnrejected,0) = 1 ";
		}
		else if($itemstatus == '10') {
			$querysearch = $querysearch." and ifnull(porderdt_approvedstatus,'x') = 'a' and ifnull(porderdt_grnrejected,0) = 0 and not exists (select 1 from GrnPurchases where GrnPurchases.Porder_Ref = porder.Porder_Reference and GrnPurchases.Journal_Type = 'PI') ";
		}
		else if($itemstatus == '11') {
			$querysearch = $querysearch." and ifnull(porderdt_approvedstatus,'x') = 'a' and ifnull(porderdt_grnrejected,0) = 0 and exists (select 1 from GrnPurchases where GrnPurchases.Porder_Ref = porder.Porder_Reference and GrnPurchases.Journal_Type = 'PI' ) ";
		}
	}

	
	$querysearch= $querysearch." order by porder.porder_date";

	//echo $querysearch;
	//echo $querysearch; exit;

	$resultsearch=mysql_query($querysearch,$connection) or die(mysql_error());
	$totalrows = mysql_num_rows($resultsearch);
		
	if ($startrange=='' || $PRef != 'Null')
		$startrange = 0;
	if ($perpage=='')
		$perpage = 200;
			
	//$querysearch = $querysearch." limit ".$startrange.",".$perpage;

	$resultsearch=mysql_query($querysearch,$connection) or die(mysql_error());	
		
	//echo $querysearch;
	$i = 1000;
	$k = 1;
	$ref = '';
	
	echo"<div id='grid_contentDiv' class='grid_contentDiv' style='height:250px;' onscroll=\"ScrollHeader('grid_headerDiv','grid_contentDiv')\">";
	echo"<table  cellspacing='2' cellpadding='2' style='table-layout:fixed; width:1835px;' class='grid_data1'>
		  <col width=25>
		  <col width=25>
		  <col width=25>
		  <col width=70>
		  <col width=80>
		  <col width=70>
		  <col width=80>
		  <col width=100>
		  <col width=120>
		  <col width=120>
		  <col width=120>
		  <col width=120>
		  <col width=110>
		  <col width=80>
		  <col width=60>
		  <col width=50>
		  <col width=100>
		  <col width=120>
		  <col width=120>
		  <col width=120>
		  <col width=120>
		  <col width=120>
		  <col width=120>
		  <col width=120>
		  <col width=120>";
	while($rows=mysql_fetch_array($resultsearch)){
		extract($rows);
		
		$p = ''; $a = ''; $r = '';
		if ($porderdt_approvedstatus=='a')		$a = ' checked ';
		else if ($porderdt_approvedstatus=='r')	$r = ' checked ';
		else $p = ' checked ';
		
		$sub_query  = " select count(*) from GrnPurchases where GrnPurchases.Porder_Ref = '".$porder_reference."' and GrnPurchases.Journal_Type = 'PI' ";
		$sub_result = mysql_query($sub_query,$connection) or die(mysql_error());
		$sub_rows = mysql_fetch_array($sub_result);
		
		$PorderStatus = 'GRN Pending';
		if ($sub_rows[0] > 0) $PorderStatus = 'GRN Approved';
			
		if ($porderdt_approvedstatus != 'a' || ($porderdt_approvedstatus == 'a' && $porderdt_grnrejected == 1)) $PorderStatus = $PorderDtStatus;
			
	
		if ($ref != $porder_id){	
			$k = 1;
	
	
			$sub_query  = " select if(ifNull(PaymentRqst.PaymentRqst_App,0)=1, ifnull(PaymentRqst_amountD1,0), 0), ".
						  " if(ifNull(PaymentRqst.PaymentRqst_App,0)=1, ifnull(PaymentRqst_amountD2,0), 0), PaymentRqst_Date ".
						  " from paymentrqst where paymentrqst.Porder_Reference = '".$porder_reference."' ";
			$sub_result = mysql_query($sub_query,$connection) or die(mysql_error());
			$sub_rows = mysql_fetch_array($sub_result);
			
			if ($currency_code == $base1)
				$totalpaidamount = $sub_rows[0];
			else if ($currency_code == $base2)
				$totalpaidamount = $sub_rows[1];
			else if ($sub_rows[2]==''){			
			$totalpaidamount =0;
			} else $totalpaidamount = ConvertCurrency($base1, $currency_code, $sub_rows[2], $sub_rows[0], $connection);
			/* else	
				$totalpaidamount = ConvertCurrency($base1, $currency_code, $sub_rows[2], $sub_rows[0], $connection); 
			 */
			
			if(empty($totalpaidamount)) $totalpaidamount = 0;
			$totalremainamount = $nettotal - $totalpaidamount;
			

			if($Prequest_Ref!='')
				$ref1 = $Prequest_Ref;
			else if($porder_prequestref!='')
				$ref1 = $porder_prequestref;
				
			

				
			if ($ref != $porder_id && $ref != '') {
				echo"</table>";
				echo"</div></td></tr>";
			}
	
			//if($ref != '') echo"<tr><td colspan=12><hr></td></tr>";
			echo "<tr height=35px bgcolor='#0086B2'>";
			echo '	<td align=center><span class="style5"><img src="img/details.png" onMouseOver="style.cursor=\'hand\'"  onclick="ShowHideDetails('.$porder_id.', \''.'S'.'\','.$startrange.');" title="Show Details" style="width:20px; height:20px; "></span></td>';
			echo '	<td align=center><span class="style5"><img src="img/openlist.png" onMouseOver="style.cursor=\'hand\'"  onclick="UploadDocuments('.$porder_id.', \''.'purchaseorder'.'\');" title="Upload Documents" style="width:20px; height:20px; "></span></td>';
			
			if (($Module_PrintApprovedRqst == 1 && $porderdt_approvedstatus=='a') || ($Module_PrintApprovedRqst != 1 && 1 == 1))
				echo '<td align=center><span class="style5"><img src="img/print.png" onMouseOver="style.cursor=\'hand\'"  onclick="PrintPreview('.$porder_id.', \''.'PO'.'\');" title="Print" style="width:20px; height:20px; "></span></td>';
			else
				echo '<td align=center><span class="style5">&nbsp;</span></td>';
				
			echo "	<td align=center>";
			
			if ($Module_PRequestConfirm == 1 && $FI_PorderConfirmed == 1 && $Porder_Confirmed != 1) {
				echo"<input type='button' name='btnconf$i' onclick=\"ConfirmOrder('$porder_id','$porder_reference');\" value='C' title='Confirm Order'>";
			}	
			echo "	$porder_reference</td>";
			echo "	<td align='center'>$ref1</td>";
			echo "	<td align='center'>$GRNPurchase_Reference</td>";
			echo "	<td>$porderdate</td>";
			echo "	<td>$requestdate</td>";
			echo "	<td align=center>";
			
			if ($Module_Project == 1)
				echo "<span title='$porderproject_name'>$porderproject_code</span>";
			echo"</td><td align=center>";
			
			if ($ShowCostCentLayout_Purchase == 1)			
				echo "<span title='$pordercostcent_name'>$pordercostcent_code</span>";
			echo"</td>";
			
			echo"<td align='left'><span>$suppliername</span></td>";
			echo"<td align='left'><span>$user_name</span></td>";
			echo"<td align='left'><span>&nbsp;</span></td>";
			echo"<td align='left' colspan='4' ><input type='text' name='rejectedreason$i' id='rejectedreason$i' value='$rejectedreason'></td>";
			echo"<td align='left'><span class='style15'>";
			
			if ($itemstatus == '2' || $itemstatus == '3' || $itemstatus == '4')
				echo"<input type='radio' name='r1' id='r1' value='p' onclick=\"updateheader('$porder_id',this.value,'PRO','rejectedreason$i',$totalremainamount,'".htmlentities($porderproject_code)."') ;return false;\"  onMouseOver=\"style.cursor='pointer'\" ><font color=#FFFFFF>Pend.</font>";
			if ($Login_POrdReject == 1 && ($itemstatus == '2' || $itemstatus == '4'))
				echo"<input type='radio' name='r1' id='r1' value='r' onclick=\"updateheader('$porder_id',this.value,'PRO','rejectedreason$i',$totalremainamount,'".htmlentities($porderproject_code)."') ;return false;\"  onMouseOver=\"style.cursor='pointer'\" ><font color=#FF0000>Rej.</font>";
			if ($Login_POrdApprove == 1 && ($itemstatus == '2' ))	
				echo"<input type='radio' name='r1' id='r1' value='a' onclick=\"updateheader('$porder_id',this.value,'PRO','rejectedreason$i',$totalremainamount,'".htmlentities($porderproject_code)."') ;return false;\"  onMouseOver=\"style.cursor='pointer'\" ><font color=#DAA520>App.</font>";
				
			echo"	</span></td>";
			echo"	<td align='center'><span>$RequestedUser</span></td>";
			echo"	<td align='center'><span>$CreatedUser</span></td>";
			echo"	<td align='right'><span>".number_format($nettotal, 2)."df</span></td>";
			echo"	<td align='right'><span>".number_format($totalpaidamount, 2)."</span></td>";
			echo"	<td align='right'><span>".number_format(abs($totalremainamount), 2)."</span></td>";
			echo"	<td align='right'><span>".number_format($DownPer, 2)." %</span></td>";
			echo"	<td align='right'><span>".number_format($DownAmount, 2)."</span></td>";
			echo"</tr>";
			
			$SlideDivId = 'displaydetails'.$porder_id;
			echo'<tr>';	
			echo"<td colspan='23' valign='top' align='left'><div id='$SlideDivId' style='display:none;'>";
			echo"<table  cellspacing='2' cellpadding='2' style='table-layout:fixed; width:1835px;' class='grid_data1'>
				  <col width=25>
				  <col width=25>
				  <col width=25>
				  <col width=70>
				  <col width=80>
				  <col width=70>
				  <col width=80>
				  <col width=100>
				  <col width=120>
				  <col width=120>
				  <col width=120>
				  <col width=120>
				  <col width=110>
				  <col width=80>
				  <col width=60>
				  <col width=50>
				  <col width=100>
				  <col width=120>
				  <col width=120>
				  <col width=120>
				  <col width=120>
				  <col width=120>
				  <col width=120>
				  <col width=120>
				  <col width=120>";
			
		}
		
	
		
		$ct+=1;
		$i = $i + 1;

		if($ct%2==0)
			$Color="style='background-color:".$grid_color1."'";
		else			
			$Color="style='background-color:".$grid_color2."'";	
			
		
			
		if ($porderdt_approvedlevel=='')
			$canchange = ' ';
		else	
		if ( ($PurorderApproved_Level > $porderdt_approvedlevel)  )
			$canchange = 'disabled ';
		else 	
			$canchange = ' ';

				
		echo'<tr>';
		echo "	<td align='center'>&nbsp;</td>";
		echo "	<td align='center'>&nbsp;</td>";
		echo "	<td align='center'>&nbsp;</td>";
		echo "	<td align='center'><input type='button' name='btn$i' value='H' style='width:30px;text-align:center;font-size:10px' onclick=\"openhistory('$item_code')\" /></td>";	
		echo "	<td colspan=4><span class='style15'>";

		//stopped by elie 
		//$item_code";
	
		$$val = $item_code;
		$i_lpurp = 0;
				$sub_query = " SELECT if($PurchaseTTC = 1, PurchaseDt_PriceTTCBase1, PurchaseDt_PriceBase1), ifNull(PurchaseDt_DiscountPer,0), Purchase_Date FROM PurchasesDt ".
							 " WHERE Item_code = '".$$val."' And ifNull(PurchaseDt_Price,0) > 0 ".
							 " Order By Purchase_Date Desc Limit 1 "; 
				$sub_result = mysql_query($sub_query,$connection);
				$sub_row = mysql_fetch_row($sub_result);
				$i_lpurp = $sub_row[0];
				if(!isset($i_lpurp)) $i_lpurp = 0;
				
				$i_lpurp = ConvertCurrency($Base1, $txtCurrCode, insertMySQLDate($txtDate), $i_lpurp, $connection);
				if(!isset($i_lpurp)) $i_lpurp = 0;
				$txtLastPurPrice = $i_lpurp;
				
		echo"<span class='style4'><input type='text'  style='width:120px;font-size:11px'   name='item_code$i' readonly  id='item_code$i' value='".$$val."'   
				$KeyDown   class='roundedtext_amortization_small'   onchange=\"setitemcode(this.value,'item_code".$i."','item_description".$i."','','','','','','','',1);\"  style='width:100px'></span>";
				
		if (($item_description1!='') && ($Login_PReqApprove==1))
			echo"<img src='img/scroll-down-1.png' width='20' height='20' id='trqstdtitemcodeimage$i' onmouseover=\"style.cursor='pointer'\"  onclick=\"showsearchpage('itemcode','item_code$i','item_description$i','800','500')\">";
		echo"</span>";
		$$val=$item_description;

		echo "&nbsp;<input type='text' style='width:160px;font-size:11px' value='".$$val."' readonly name='item_description$i' id='item_description$i'>";
		if (($item_description1!='') && ($Login_PReqApprove==1))
			echo"<img src='img/confirm-1.png' onmouseover=\"style.cursor='pointer'\" name='' id='imgSubmitPTransReqDt[$i]' title='Save' onclick=\"submitItemDt('$porderdt_id','$i','2')\">";
			
		echo"</span></td>";

		echo "<td align='left' colspan='2'><span class='style15'>$item_description1</span></td>";

		if ($Module_ProjectDt == 1)
			echo "<td align='left'><span title='$porderdtproject_name' class='style15'>$project_code</span></td>";
		else
			echo "<td align='left'><span class='style15'>&nbsp;</span></td>";	

		if ($ShowCostCentLayout_Purchase == 1)
			echo "<td align='left'><span title='$porderdtcostcent_name' class=' class='style15'>$costcent_code</span></td>";
		else
			echo "<td align='left'><span class='style15'>&nbsp;</span></td>";
		
		
		$trans = 'transferqty[$i]';
		$transferwarehousecode[$i] = $defaultwarehouse;

		
				
		
		//echo "<td  colspan=1><span class='style15'>$qtyexists</span></td>";
		//<input type='text' name='qtyexists[$i]' id='qtyexists[$i]' value='$qtyexists' style='width:50px'>
		echo"	<td align='left'><span class='style15'>$PorderStatus</span></td>";
		echo"	<td align='left'><span class='style15'>$warehouse_code</span></td>";
		echo"	<td align='left'><span class='style15'>$porderdt_quantity</span></td>";
		echo"	<td align='left'><span class='style15'>$Item_UnitSalesDesc</span></td>";
		echo"	<td align='center'><span class='style15'>$currency_code</span></td>";
		echo"	<td align='right'><span class='style15'>".number_format($porderdt_price, 2)."</span></td>";
		echo"	<td align='right'><span class='style15'>".number_format($txtLastPurPrice, 2)."</span></td>";
		echo"	<td align='right'><span class='style15'>".number_format($porderdt_total, 2)."</span></td>";
	//	echo"	<td align='right'><span class='style15'>$i_lpurp</span></td>";
		echo"	<td align='center' colspan='2'><span class='style15'>";
		if ($itemstatus == '2' || $itemstatus == '3' || $itemstatus == '4')
			echo"<input type='radio' name='r1$i' id='r1$i' value='p' $p  $canchange onclick=\"updatedt('$porderdt_id',this.value,'PRO','$PurorderApproved_Level','rejectedreason$i','$i') ;return false;\"  onMouseOver=\"style.cursor='pointer'\" ><font color=#000000>Pend.</font>";
		if ($Login_POrdReject == 1 && ($itemstatus == '2' || $itemstatus == '4'))
			echo"<input type='radio' name='r1$i' id='r1$i' value='r' $r  $canchange onclick=\"updatedt('$porderdt_id',this.value,'PRO','$PurorderApproved_Level','rejectedreason$i','$i') ;return false;\"  onMouseOver=\"style.cursor='pointer'\" ><font color=#FF0000>Rej.</font>";
		if ($Login_POrdApprove == 1 && ($itemstatus == '2' ))	
			echo"<input type='radio' name='r1$i' id='r1$i' value='a' $a  $canchange onclick=\"updatedt('$porderdt_id',this.value,'PRO','$PurorderApproved_Level','rejectedreason$i','$i') ;return false;\"  onMouseOver=\"style.cursor='pointer'\" ><font color=#DAA520>App.</font>";
				
		if($itemstatus == '10' || $itemstatus == '12') {
			echo"<input type='checkbox' name='chk$i' id='chk$i' value='1' onclick=\"updatedtgrn('$porderdt_id','$i') ;return false;\"  onMouseOver=\"style.cursor='pointer'\" "; if ($porderdt_grnrejected==1) echo " checked "; echo"><font color=#DAA520>GRN Reject</font>";
		}			
			
		echo"	</span></td>";
		//echo"	<td align='center' colspan='2'><span class='style15'>&nbsp;</span></td>";
		echo"</tr>";

			  
		$ref = $porder_id;
	
		$k+=1;
	}
			 
	//Ending Detail Div
	if ($ref != '') {
		echo"</table>";
		echo"</div></td></tr>";
	}			
	
	echo"</table></div></div>";
	echo"</td></tr>";

} //end of purchaseorder


if ($fi_pendingtransferrequest==1 && $transtype=='t') {

	echo"<tr bgcolor='#F7F7F7'><td valign='top' align='left' colspan='6'>
		  <div id='container' style='width:1090px; height:330px;'>
		  <div id='grid_headerDiv' class='grid_headerDiv' style='height:80px;'>
		  <table  cellspacing='2' cellpadding='2' style='table-layout:fixed; width:1315px;' class='grid_data1'>
		  <col width=25>
		  <col width=70>
		  <col width=80>
		  <col width=80>
		  <col width=100>
		  <col width=100>
		  <col width=100>
		  <col width=100>
		  <col width=100>
		  <col width=100>
		  <col width=60>
		  <col width=100>
		  <col width=300>";
		  
	echo"<tr><td colspan='12' align=center><u><font color=red>Transfer Request</font></u></td></tr>";
	echo"<tr bgcolor='#DAA520'>
			<th  height='25' align='left'>&nbsp;</th>
			<th  height='25' align='left'>Ref.</th>
			<th  height='25' align='left'>MSR</th>
			<th  height='25' align='center'>Date </th>
			<th  height='25' align='center'>From WH.</span></th>
			<th  height='25' align='center'>To WH.</th>";
			
			
	if ($Module_Project == 1) {
		echo"<th  height='25' align='center'>From Project</th>";
		echo"<th  height='25' align='center'>To Project</th>";
	} else {
		echo"<th align='center' colspan='2'>&nbsp;</th>";
	}	
	if ($ShowCostCentLayout_Transfer == 1) {
		echo"<th  height='25' align='left'>From Costcenter</th>";
		echo"<th  height='25' align='left'>To Costcenter</th>";
	} else {
		echo"<th align='center' colspan='2'>&nbsp;</th>";
	}
		
	echo"	<th colspan='2' height='25' align='center'>&nbsp;</th>";
	echo"	<th  height='25' align='center'>&nbsp;</th>";
	echo"</tr>";
		
	echo"<tr  bgcolor='#a8a8a8'>
			<th>&nbsp;</th><th>&nbsp;</th>
			<th align=left colspan=3>Item Code \ Description</th>
			<th align='center'>From WH.</th>
			<th align='center'>To WH.</th>
			<th align='center'>Ord.Qty</th>
			<th align='center'>Canc.Qty</th>
			<th align='center'>Qty</th>
			<th align='center'>Unit</th>
			<th align='center'>Status</th>
			<th align='center'>&nbsp;</th>";
	echo"</tr>";
	echo"</table></div>";


// transfer request part
	$querysearch_transfer=" select transferrequest.transferrequest_reference as transferrequest_reference,date_format(transferrequest.transferrequest_date,'%d/%m/%Y') as transferrequest_date,
				transferrequestdt.item_code as item_code,items.item_description as item_description,transferrequest.transferrequest_id
				,transferrequestdt_Quantity,transferrequestdt.transferrequestdt_id as transferrequestdt_id,transferrequestdt_status
				,transferrequest.Transferrequest_WarehouseFrom as fromwarehouse,transferrequest.Transferrequest_WarehouseTo as towarehouse
				,TransferrequestDt_WarehouseFrom as fromwarehousedt,TransferrequestDt_WarehouseTO as towarehousedt,TransferrequestDt_Price,ifnull(TransferrequestDt_Price,0)*ifnull(transferrequestdt_Quantity,0) as total
				,ifnull(TransferrequestDt_approvedlevel,5000) as TransferrequestDt_approvedlevel
				,transferrequest.Project_code1,transferrequest.Project_code2,transferrequest.Costcenter_Code,transferrequest.ToCostcenter_Code
				,project.project_name transferproject_name1			
				,project2.project_name transferproject_name2
				,costcent.costcent_name as transfercostcent_name1			
				,costcent2.costcent_name as transferdtcostcent_name2
				,transferrequest.rejectedreason
				,transferrequestdt.rejectedreason as transferrequestdtrejectedreason,prequest.PRqst_reference
				,if(ifnull(transferrequestdt_status,'x')='x', 'Pending Approval', if(ifnull(transferrequestdt_status,'x')='a', 'Approved', if(ifnull(transferrequestdt_status,'x')='r', 'Rejected', ''))) as TransferReqDtStatus
				,Items.Item_UnitSalesDesc as Item_UnitSalesDesc
				from transferrequest
				left join project on project.project_code = transferrequest.project_code1
				left join project project2 on project2.project_code = transferrequest.project_code2
				left join costcent on costcent.costcent_code = transferrequest.costcenter_code
				left join costcent costcent2 on costcent2.costcent_code = transferrequest.ToCostcenter_Code ";
				
			
	 $querysearch_transfer= $querysearch_transfer."	left join prequest  on prequest.prqst_id = transferrequest.prqst_id
				,transferrequestdt 
				,items
				where transferrequest.transferrequest_id = transferrequestdt.transferrequest_id  
				and items.item_code=transferrequestdt.item_code
				and if('$itemcode[0]'='',1=1,transferrequestdt.item_code='$itemcode[0]')
				and if('$PRef'='',1=1,transferrequest.transferrequest_reference='$PRef')
				and date_format(transferrequest.transferrequest_date,'%Y-%m-%d') between ifnull('". explodedate($fromdate)."', date_format(transferrequest.transferrequest_date,'%Y-%m-%d')) and ifnull('". explodedate($todate)."', date_format(transferrequest.transferrequest_date,'%Y-%m-%d'))";
				
	if ($PProjectCode != '')
		$querysearch_transfer= $querysearch_transfer." And transferrequest.project_code1 like concat('".$PProjectCode."','%') ";
	if ($PCostCentCode != '')
		$querysearch_transfer= $querysearch_transfer." And transferrequest.costcenter_code like concat('".$PCostCentCode."','%') ";
	
	if($itemstatus != '') {
		if($itemstatus == '2') {
			$querysearch_transfer = $querysearch_transfer." and ((ifnull(transferrequestdt_status,'x') = 'x' and 1 = 1) or (ifnull(transferrequestdt_status,'x') = 'a' and TransferrequestDt_approvedlevel > $TransferRequestApproved_Level)) ";
		} 
		else if($itemstatus == '3') {
			$querysearch_transfer = $querysearch_transfer." and ifnull(transferrequestdt_status,'x') = 'a' and TransferrequestDt_approvedlevel <= $TransferRequestApproved_Level ";
		}
		else if($itemstatus == '4') {
			$querysearch_transfer = $querysearch_transfer." and ifnull(transferrequestdt_status,'x') = 'r' ";
		}
	}
				
	$querysearch_transfer= $querysearch_transfer." Order By transferrequest.transferrequest_date  ";
	
	$prqst_reference = '';
	$ref='';
	$a='';$r='';$c='';
	
	if ($startrange=='' || $PRef != 'Null')
		$startrange = 0;
	if ($perpage=='')
		$perpage = 200;
	
	echo"<div id='grid_contentDiv' class='grid_contentDiv' style='height:250px;' onscroll=\"ScrollHeader('grid_headerDiv','grid_contentDiv')\">";
	echo"<table  cellspacing='2' cellpadding='2' style='table-layout:fixed; width:1315px;' class='grid_data1'>
		  <col width=25>
		  <col width=70>
		  <col width=80>
		  <col width=80>
		  <col width=100>
		  <col width=100>
		  <col width=100>
		  <col width=100>
		  <col width=100>
		  <col width=100>
		  <col width=60>
		  <col width=100>
		  <col width=300>";
	
	$resultsearch=mysql_query($querysearch_transfer,$connection) or die(mysql_error());
	while($rows=mysql_fetch_array($resultsearch)){
		
		extract($rows);
		
		$p = ''; $a = ''; $r = '';
		if ($transferrequestdt_status=='a')		$a = ' checked ';
		else if ($transferrequestdt_status=='r')	$r = ' checked ';
		else $p = ' checked ';
			
			
		if ($ref != $transferrequest_id)	{
		
			if ($ref != $transferrequest_id && $ref != '') {
				echo"</table>";
				echo"</div></td></tr>";
			}
			
			//if ($ref != '') echo"<tr><td colspan='11'><hr></td></tr>";
			echo "<tr height=35px bgcolor='#0086B2'>";
			echo'	<td align=center><span class="style5"><img src="img/details.png" onMouseOver="style.cursor=\'hand\'"  onclick="ShowHideDetails('.$transferrequest_id.', \''.'S'.'\','.$startrange.'); return false;" title="Show Details" style="width:20px; height:20px; "></span></td>';	
			echo"	<td align=center>$transferrequest_reference</td>";
			echo"	<td align=center>$PRqst_reference</td>
					<td align=center>$transferrequest_date</td>
					<td align=center> $fromwarehouse</td>
					<td align=center> $towarehouse</td>";
					
			if ($Module_Project == 1) {
				echo"<td><span title='$transferproject_name1'>$Project_code1</span></td>
					 <td><span title='$transferproject_name2'>$Project_code2</span></td>";
			} else {
				echo"<td align='center' colspan='2'>&nbsp;</td>";
			}

			if ($ShowCostCentLayout_Transfer == 1) {
				echo"<td><span title='$transfercostcent_name2'>$Costcenter_Code</span></td>
					 <td><span title='$transfercostcent_name2'>$ToCostcenter_Code</span></td>";
			} else {
				echo"<td align='center' colspan='2'>&nbsp;</td>";
			}
			echo"	<td align='center' colspan='2'>&nbsp;</td>";		 
			echo"	<td align='left' ><span class='style15'>";
			
			if ($itemstatus == '2' || $itemstatus == '3' || $itemstatus == '4')
				echo"<input type='radio' name='r1' id='r1' value='p'  onclick=\"updateheader('$transferrequest_id',this.value,'TRQ','rejectedreason$i') ;return false;\"  onMouseOver=\"style.cursor='pointer'\" ><font color=#FFFFFF><b>Pend.</b></font>";
			if ($Login_TReqReject == 1 && ($itemstatus == '2' || $itemstatus == '4'))
				echo"<input type='radio' name='r1' id='r1' value='r'  onclick=\"updateheader('$transferrequest_id',this.value,'TRQ','rejectedreason$i') ;return false;\"  onMouseOver=\"style.cursor='pointer'\" ><font color=#FF0000><b>Rej.</b></font>";
			if ($Login_TReqApprove == 1 && ($itemstatus == '2' || $itemstatus == '3'))	
				echo"<input type='radio' name='r1' id='r1' value='a'  onclick=\"updateheader('$transferrequest_id',this.value,'TRQ','rejectedreason$i') ;return false;\"  onMouseOver=\"style.cursor='pointer'\" ><font color=#DAA520>App.</font>";
				
			echo"	<input type='text' name='rejectedreason$i' id='rejectedreason$i' value='$rejectedreason'>
					</span></td>";
			echo "</tr>";
			
			$SlideDivId = 'displaydetails'.$transferrequest_id;
			echo'<tr>';	
			echo"<td colspan='13' valign='top' align='left'><div id='$SlideDivId' style='display:none;'>";
			echo"<table  cellspacing='2' cellpadding='2' style='table-layout:fixed; width:1315px;' class='grid_data1'>
				  <col width=25>
				  <col width=60>
				  <col width=80>
				  <col width=80>
				  <col width=100>
				  <col width=100>
				  <col width=100>
				  <col width=100>
				  <col width=100>
				  <col width=100>
				  <col width=60>
				  <col width=100>
				  <col width=300>";
		}
			
		$ct+=1;
		$i = $i + 1;

		if($ct%2==0)
			$Color="style='background-color:".$grid_color1."'";
		else			
			$Color="style='background-color:".$grid_color2."'";	
		
		
		if ($TransferrequestDt_approvedlevel=='')
			$canchange1 = ' ';
		else	
		if ( ($TransferRequestApproved_Level > $TransferrequestDt_approvedlevel)  )
			$canchange1 = 'disabled ';
		else 	
			$canchange1 = ' ';


		echo'<tr><td>&nbsp;</td><td>&nbsp;</td>';	
		echo"	<td colspan=3><span class='style15'>";

		//stopped by elie 
		//$item_code";

		$$val = $item_code;
		echo "<input type='hidden' name='txtitem' id='txtitem$i' value='".$$txtitem."'>";
		if($$txtitem==5){
			echo "fgdgdfg";
		//	echo "<script>document.search.submit();</script>";
		}
		echo"<span class='style4'><input type='text'  style='width:90px;font-size:11px'   name='item_code$i' id='item_code$i' value='".$$val."'   
			$KeyDown  readonly class='roundedtext_amortization_small'   onchange=\"setitemcode(this.value,'item_code".$i."','item_description".$i."','','','','','','','',1);\"  style='width:100px'></span>";
			
		if (($item_description1!='') && ($Login_PReqApprove==1))
			echo"<img src='img/scroll-down-1.png' width='20' height='20' id='trqstdtitemcodeimage$i' onmouseover=\"style.cursor='pointer'\"  onclick=\"showsearchpage('itemcode','item_code$i','item_description$i','800','500')\">	";
		echo"</span>";
		$$val=$item_description;
		echo "&nbsp;<input type='text' style='width:110px;font-size:11px' value='".$$val."' name='item_description$i' id='item_description$i' >";
		//oninput=\"stest('$transferrequestdt_id','$i','3')\"
		if (($item_description1!='') && ($Login_PReqApprove==1))
			echo"<img src='img/confirm-1.png' onmouseover=\"style.cursor='pointer'\" name='' id='imgSubmitPTransReqDt[$i]' title='Save' onclick=\"submitItemDt('$transferrequestdt_id','$i','3')\">";
		
		echo"</span></td>";

		echo"<td align='left'><span class='style15'>$fromwarehousedt</span></td>";
		echo"<td align='left'><span class='style15'>$towarehousedt</span></td>";
		echo"<td align='left'><span class='style15'><input type='text'  $canchange1 name='transferrequestdt_Quantity[$i]' value='$transferrequestdt_Quantity' id='transferrequestdt_Quantity[$i]' onchange=\"updatequantityTransfer('$i','$transferrequestdt_id')\" style='width:50px;border-color:#F8F8F8'></span></td>";
		echo"<td align='left'><span class='style15'><input type='text'  $canchange1  readonly name='TransferrequestDt_Price[$i]' value='$TransferrequestDt_Price' id='TransferrequestDt_Price[$i]' style='width:50px;border-width:0px'></span></td>";
		echo"<td align='left'><span class='style15'><input type='text'  $canchange1 name='total[$i]' value='$total' id='total[$i]' style='width:50px;border-width:0px'></span></td>";
		echo"<td align='left'><span class='style15'>$Item_UnitSalesDesc</span></td>";
		echo"<td align='left'><span class='style15'>$TransferReqDtStatus</span></td>";
		echo"<td align='left'><span class='style15'>";
		
		if ($itemstatus == '2' || $itemstatus == '3' || $itemstatus == '4')
			echo"<input type='radio' name='r1$i' id='r1$i' value='p' $p $canchange1  onclick=\"updatedt('$transferrequestdt_id',this.value,'TRQ','$TransferRequestApproved_Level','transferrequestdtrejectedreason$i','$i')\"  onMouseOver=\"style.cursor='pointer'\" ><font color=#FFBBBB><b>Pend.<b></font>";
		if ($Login_TReqReject == 1 && ($itemstatus == '2' || $itemstatus == '4'))
			echo"<input type='radio' name='r1$i' id='r1$i' value='r' $r $canchange1  onclick=\"updatedt('$transferrequestdt_id',this.value,'TRQ','$TransferRequestApproved_Level','transferrequestdtrejectedreason$i','$i')\"  onMouseOver=\"style.cursor='pointer'\" ><font color=#FF0000><b>Rej.<b></font>";
		if ($Login_TReqApprove == 1 && ($itemstatus == '2' || $itemstatus == '3'))	
			echo"<input type='radio' name='r1$i' id='r1$i' value='a' $a $canchange1  onclick=\"updatedt('$transferrequestdt_id',this.value,'TRQ','$TransferRequestApproved_Level','transferrequestdtrejectedreason$i','$i')\"  onMouseOver=\"style.cursor='pointer'\" ><font color=#DAA520>App.</font>";
			
		echo"	<input type='text' name='transferrequestdtrejectedreason$i' id='transferrequestdtrejectedreason$i' value='$transferrequestdtrejectedreason' style='width:50px'>
			</span></td>";
		echo"</tr>";

		


			  
		$ref = $transferrequest_id;
		$a = '';
		$c = '';
		$r = '';
	} 
	
	//Ending Detail Div
	if ($ref != '') {
		echo"</table>";
		echo"</div></td></tr>";
	}	
	
	echo"</table></div></div>";
	echo"</td></tr>";

}//end of transfer



if ($fi_pendingadjustmentrequest==1 && $transtype=='a') {

	echo"<tr bgcolor='#F7F7F7'><td valign='top' align='left' colspan='6'>
	      <div id='container' style='width:1090px; height:330px;'>
		  <div id='grid_headerDiv' class='grid_headerDiv' style='height:80px;'>
		  <table  cellspacing='2' cellpadding='2' style='table-layout:fixed; width:1240px;' class='grid_data1'>
		  <col width=70>
		  <col width=80>
		  <col width=120>
		  <col width=120>
		  <col width=100>
		  <col width=110>
		  <col width=110>
		  <col width=70>
		  <col width=60>
		  <col width=100>
		  <col width=300>";
		  
	//echo"<tr height=20><td colspan='9' align=center><u></u></td></tr>";
	echo"<tr><td colspan='11' align=center><u><font color=red>Adjustment Request</font></u></td></tr>";
	echo"<tr bgcolor='#DAA520'>
			<th  height='25' align='left'>Ref.</th>
			<th  height='25' align='center'>Date </th>";
		
	if ($Module_Project==1)
		echo"<th  height='25' align='center'>Project</span></th>";
	else
		echo"<th align='center'>&nbsp;</th>";
		
	if ($ShowCostCentLayout_Adjustment==1)
		echo"<th  height='25' align='center'>Costcenter</th>";
	else
		echo"<th align='center'>&nbsp;</th>";
		
	echo"	<th  height='25' align='center' colspan='7'>&nbsp;</th>";
	echo"</tr>";
		
	echo"<tr  bgcolor='#a8a8a8' >
			<th>&nbsp;</th>
			<th align=left colspan=3>Item Code \ Description</th>
			<th align='center'>Warehouse</th>";
		
		
	if ($Module_ProjectDt==1)
		echo"<th align='center'>Project</th>";
	else
		echo"<th align='center'>&nbsp;</th>";	
		
	if ($ShowCostCentLayout_Adjustment==1)
		echo"<th align='center'>Costcenter</th>";
	else
		echo"<th align='center'>&nbsp;</th>";
		
	echo"	<th align='center'>Qty</th>";
	echo"	<th align='center'>Unit</th>";
	echo"	<th align='center'>Status</th>";
	echo"	<th align='center'>&nbsp;</th>";
	echo"</tr>";
	echo"</table></div>";


	// transfer request part
	$querysearch_adjs=" select adjustmentrequest.adjustmentrequest_reference as adjustmentrequest_reference
			,date_format(adjustmentrequest.adjustmentrequest_date,'%d/%m/%Y') as adjustmentrequest_date,
				adjustmentrequestdt.item_code as item_code,items.item_description as item_description,adjustmentrequest.adjustmentrequest_id as adjustmentrequest_id
				,adjustmentRequestdt_quantity,adjustmentrequestdt.adjustmentrequestdt_id as adjustmentrequestdt_id,adjustmentrequestdt_status,ifnull(adjustmentrequestdt_approvedlevel,5000) as adjustmentrequestdt_approvedlevel
				,adjustmentrequestdt.warehouse_code as warehouse_code,adjustmentrequest.Project_Code as HeaderProject_Code,adjustmentrequest.Costcent_Code as HeaderCostcent_Code,adjustmentrequestdt.Project_Code as Project_Code,adjustmentrequestdt.Costcent_Code as Costcent_Code
				,adjustmentRequest_TotalQuantity,adjustmentrequest.rejectedreason,adjustmentrequestdt.rejectedreason adjustmentrequestdtrejectedreason
				,project.project_name adjustmentreqproject_name,costcent.costcent_name as adjustmentreqcostcent_name
				,project1.project_name adjustmentreqdtproject_name,costcent1.costcent_name as adjustmentreqdtcostcent_name
				,if(ifnull(adjustmentrequestdt_status,'x')='x', 'Pending Approval', if(ifnull(adjustmentrequestdt_status,'x')='a', 'Approved', if(ifnull(adjustmentrequestdt_status,'x')='r', 'Rejected', ''))) as AdjustReqDtStatus
				,Items.Item_UnitSalesDesc as Item_UnitSalesDesc 
				from adjustmentrequest ";
	if ($projectexist >	0)
		$querysearch_adjs= $querysearch_adjs." Inner join ( select distinct project_code from ".$_SESSION['dbLabel'].".loginstk ".
							 "			   where loginstk.user_account='".$_SESSION['useraccount']."' ".
							 "             and (project_code is not null and project_code != '') ".
							 "			 ) Q1 on (($Module_ProjectParent=1 and adjustmentrequest.project_code  like concat(Q1.project_code,'%')) or ($Module_ProjectParent=0 and adjustmentrequest.project_code  = Q1.project_code )) ";
						
	$querysearch_adjs= $querysearch_adjs." left join project on project.project_code = adjustmentrequest.project_code
				left join costcent on costcent.costcent_code = adjustmentrequest.costcent_code
				,adjustmentrequestdt
				left join project project1 on project1.project_code = adjustmentrequestdt.project_code ";
				
			
	$querysearch_adjs= $querysearch_adjs."left join costcent costcent1 on costcent1.costcent_code = adjustmentrequestdt.costcent_code
				,items
				where adjustmentrequest.adjustmentrequest_id = adjustmentrequestdt.adjustmentrequest_id  
				and items.item_code=adjustmentrequestdt.item_code
				and if('$itemcode[0]'='',1=1,adjustmentrequestdt.item_code='$itemcode[0]')
				and if('$PRef'='',1=1,adjustmentrequest.adjustmentrequest_reference='$PRef')
				and date_format(adjustmentrequest.adjustmentrequest_date,'%Y-%m-%d') between ifnull('". explodedate($fromdate)."', date_format(adjustmentrequest.adjustmentrequest_date,'%Y-%m-%d')) and ifnull('". explodedate($todate)."', date_format(adjustmentrequest.adjustmentrequest_date,'%Y-%m-%d')) ";

	if($itemstatus != '') {
		if($itemstatus == '2') {
			$querysearch_adjs = $querysearch_adjs." and ((ifnull(adjustmentrequestdt_status,'x') = 'x' and 1 = 1) or (ifnull(adjustmentrequestdt_status,'x') = 'a' and adjustmentrequestdt_approvedlevel > $AdjustmentRequestApproved_Level)) ";
		} 
		else if($itemstatus == '3') {
			$querysearch_adjs = $querysearch_adjs." and ifnull(adjustmentrequestdt_status,'x') = 'a' and adjustmentrequestdt_approvedlevel <= $AdjustmentRequestApproved_Level ";
		}
		else if($itemstatus == '4') {
			$querysearch_adjs = $querysearch_adjs." and ifnull(adjustmentrequestdt_status,'x') = 'r' ";
		}
	}
	
	if ($PProjectCode != '')
		$querysearch_adjs= $querysearch_adjs." And adjustmentrequest.project_code like concat('".$PProjectCode."','%') ";
	if ($PCostCentCode != '')
		$querysearch_adjs= $querysearch_adjs." And adjustmentrequest.costcent_code like concat('".$PCostCentCode."','%') ";
		
	$querysearch_adjs= $querysearch_adjs." Order By adjustmentrequest.adjustmentrequest_date  ";
	//echo $querysearch_adjs;		
	
	$prqst_reference = '';
	$ref='';
	$a='';$r='';$c='';
	
	
	if ($startrange=='' || $PRef != 'Null')
		$startrange = 0;
	if ($perpage=='')
		$perpage = 200;
	
	echo"<div id='grid_contentDiv' class='grid_contentDiv' style='height:250px;' onscroll=\"ScrollHeader('grid_headerDiv','grid_contentDiv')\">";
	echo"<table  cellspacing='2' cellpadding='2' style='table-layout:fixed; width:1240px;' class='grid_data1'>
		  <col width=70>
		  <col width=80>
		  <col width=120>
		  <col width=120>
		  <col width=100>
		  <col width=110>
		  <col width=110>
		  <col width=70>
		  <col width=60>
		  <col width=100>
		  <col width=300>";
	
	$resultsearch=mysql_query($querysearch_adjs,$connection) or die(mysql_error());
	while($rows=mysql_fetch_array($resultsearch)){
		
		extract($rows);
		
		$p = ''; $a = ''; $r = '';
		if ($adjustmentrequestdt_status=='a')		$a = ' checked ';
		else if ($adjustmentrequestdt_status=='r')	$r = ' checked ';
		else $p = ' checked ';
			
			
		if ($ref != $adjustmentrequest_id) {	
		
			if ($ref != $adjustmentrequest_id && $ref != '') {
				echo"</table>";
				echo"</div></td></tr>";
			}
			
			//if ($ref != '') echo"<tr><td colspan=10><hr></td></tr>";
			echo"<tr height=35px bgcolor='#0086B2'>
					<td align=center>";
			echo'		<span class="style5"><img src="img/details.gif" onMouseOver="style.cursor=\'hand\'"  onclick="ShowHideDetails('.$adjustmentrequest_id.', \''.'S'.'\','.$startrange.');" title="Show Details" style="width:15px; height:15px; "></span>';
			echo"		$adjustmentrequest_reference</td>
					<td align=center>$adjustmentrequest_date</td>";
				
			if ($Module_Project==1)
				echo"<td align=left><span title='$adjustmentreqproject_name'> $HeaderProject_Code</span></td>";
			else
				echo"<td align='center'>&nbsp;</td>";
				
			if ($ShowCostCentLayout_Adjustment==1)
				echo"<td align=left><span title='$adjustmentreqcostcent_name'> $HeaderCostcent_Code</span></td>";
			else
				echo"<td align='center'>&nbsp;</td>";
				
			echo"<td align=left colspan='7'><span class='style15'>";
			
			if ($itemstatus == '2' || $itemstatus == '3' || $itemstatus == '4')
				echo"<input type='radio' name = 'r1' id = 'r1' value = 'p'  onclick = \"updateheader('$adjustmentrequest_id',this.value,'ADR','rejectedreason$i')\"  onMouseOver=\"style.cursor='pointer'\" ><font color=#FFFFFF><b>Pend.</b></font>";
			if ($Login_AReqReject == 1  && ($itemstatus == '2' || $itemstatus == '4'))
				echo"<input type='radio' name = 'r1' id = 'r1' value = 'r'  onclick = \"updateheader('$adjustmentrequest_id',this.value,'ADR','rejectedreason$i')\"  onMouseOver=\"style.cursor='pointer'\" ><font color=#FF0000><b>Rej.</b></font>";
			if ($Login_AReqApprove == 1  && ($itemstatus == '2' || $itemstatus == '3'))	
				echo"<input type='radio' name = 'r1' id = 'r1' value = 'a'  onclick = \"updateheader('$adjustmentrequest_id',this.value,'ADR','rejectedreason$i')\"  onMouseOver=\"style.cursor='pointer'\" ><font color=#DAA520>App.</font>";
				
			echo"	<input type='text' name='rejectedreason$i' id='rejectedreason$i' value='$rejectedreason'>
				</span></td>";
			echo "</tr>";
			
			$SlideDivId = 'displaydetails'.$adjustmentrequest_id;
			echo'<tr>';	
			echo"<td colspan='11' valign='top' align='left'><div id='$SlideDivId' style='display:none;'>";
			echo"<table  cellspacing='2' cellpadding='2' style='table-layout:fixed; width:1240px;' class='grid_data1'>
				  <col width=70>
				  <col width=80>
				  <col width=120>
				  <col width=120>
				  <col width=100>
				  <col width=110>
				  <col width=110>
				  <col width=70>
				  <col width=60>
				  <col width=100>
				  <col width=300>";
		}
			
		$ct+=1;
		$i = $i + 1;

		if($ct%2==0)
			$Color="style='background-color:".$grid_color1."'";
		else			
			$Color="style='background-color:".$grid_color2."'";	
		
		
		if ($adjustmentrequestdt_approvedlevel=='')
			$canchange2 = ' ';
		else	
		if ( ($AdjustmentRequestApproved_Level > $adjustmentrequestdt_approvedlevel)  )
			$canchange2 = 'disabled ';
		else 	
			$canchange2 = ' ';


		echo'<tr><td>&nbsp;</td>';	
		echo"	<td colspan=3><span class='style15'>";

		//stopped by elie 
		//$item_code";

		$$val = $item_code;
		echo"<span class='style4'><input type='text'  style='width:115px;font-size:11px'   name='item_code$i' id='item_code$i' value='".$$val."'   
				$KeyDown  readonly class='roundedtext_amortization_small'   onchange=\"setitemcode(this.value,'item_code".$i."','item_description".$i."','','','','','','','',1);\"  style='width:100px'></span>";
		if (($item_description1!='') && ($Login_PReqApprove==1))
			echo"<img src='img/scroll-down-1.png' width='20' height='20' id='trqstdtitemcodeimage$i' onmouseover=\"style.cursor='pointer'\"  onclick=\"showsearchpage('itemcode','item_code$i','item_description$i','800','500')\">	";
		echo"</span>";
		
		$$val=$item_description;
		echo "&nbsp;<input type='text' readonly style='width:150px;font-size:11px' value='".$$val."' name='item_description$i' id='item_description$i'>";

		if (($item_description1!='') && ($Login_PReqApprove==1))
			echo"<img src='img/confirm-1.png' onmouseover=\"style.cursor='pointer'\" name='' id='imgSubmitPTransReqDt[$i]' title='Save' onclick=\"submitItemDt('$adjustmentrequestdt_id','$i','4')\">";
			
		echo"</span></td>";
		echo"<td align='center'><span class='style15'>$warehouse_code</span></td>";

		if ($Module_ProjectDt==1)
			echo "<td align='center'><span class='style15'><span title='$adjustmentreqdtcostcent_name'>$Project_Code</span></span></td>";
		else
			echo"<td align='center'>&nbsp;</td>";
				
		if ($ShowCostCentLayout_Adjustment==1)
			echo "<td align='center'><span class='style15'><span title='$adjustmentreqdtcostcent_name'> $Costcent_Code</span></span></td>";
		else
			echo"<td align='center'>&nbsp;</td>";

		echo "<td align='center'><span class='style15'><input type='text' $canchange2 name='adjustmentRequestdt_quantity[$i]' value='$adjustmentRequestdt_quantity' id='adjustmentRequestdt_quantity[$i]' onchange=\"updatequantityAdjustment('$i','$adjustmentrequestdt_id')\" style='width:50px;border-color:#F8F8F8'></span></td>";
		echo"<td align='center'><span class='style15'>$Item_UnitSalesDesc</span></td>";
		echo"<td align='center'><span class='style15'>$AdjustReqDtStatus</span></td>";
		echo "<td align='left'><span class='style15'>";

		if ($itemstatus == '2' || $itemstatus == '3' || $itemstatus == '4')
			echo"<input type='radio'  $canchange2 name='r1$i' id='r1$i' value='p' $p onclick=\"updatedt('$adjustmentrequestdt_id',this.value,'ADR','$AdjustmentRequestApproved_Level','adjustmentrequestdtrejectedreason$i','$i')\"  onMouseOver=\"style.cursor='pointer'\" ><font color=#FFBBBB><b>Pend.</b></font>";
		if ($Login_AReqReject == 1 && ($itemstatus == '2' || $itemstatus == '4'))
			echo"<input type='radio'  $canchange2 name='r1$i' id='r1$i' value='r' $r onclick=\"updatedt('$adjustmentrequestdt_id',this.value,'ADR','$AdjustmentRequestApproved_Level','adjustmentrequestdtrejectedreason$i','$i')\"  onMouseOver=\"style.cursor='pointer'\" ><font color=#FF0000><b>Rej.</b></font>";
		if ($Login_AReqApprove == 1 && ($itemstatus == '2' || $itemstatus == '3'))	
			echo"<input type='radio'  $canchange2 name='r1$i' id='r1$i' value='a' $a onclick=\"updatedt('$adjustmentrequestdt_id',this.value,'ADR','$AdjustmentRequestApproved_Level','adjustmentrequestdtrejectedreason$i','$i')\"  onMouseOver=\"style.cursor='pointer'\" ><font color=#DAA520>App.</font>";
			
		echo"	<input type='text' name='adjustmentrequestdtrejectedreason$i' id='adjustmentrequestdtrejectedreason$i' value='$adjustmentrequestdtrejectedreason' style='width:50px'>
			</span></td>";

		echo"</tr>";

				  
		$ref = $adjustmentrequest_id;
		$a = '';
		$c = '';
		$r = '';
	} 
	
	//Ending Detail Div
	if ($ref != '') {
		echo"</table>";
		echo"</div></td></tr>";
	}	
	
	echo"</table></div></div>";
	echo"</td></tr>";

}



//paymentrequest
if ($fi_pendingpaymentrequest==1 && $transtype=='pyr' ){

	echo"<tr bgcolor='#F7F7F7'><td valign='top' align='left' colspan='6'>
		  <div id='container' style='width:1090px; height:330px;'>
		  <div id='grid_headerDiv' class='grid_headerDiv' style='height:87px;'>
		  <table border='0' cellspacing='0' cellpadding='0' style='table-layout:fixed; width:1945px;' class='grid_data1'>
		  <col width=25>
		  <col width=25>
		  <col width=25>
		  <col width=80>
		  <col width=80>
		  <col width=80>
		  <col width=150>
		  <col width=150>
		  <col width=120>
		  <col width=120>
		  <col width=120>
		  <col width=200>
		  <col width=200>
		  <col width=110>
		  <col width=110>
		  <col width=300>";
		  
	echo"<tr><td colspan='11' align=center><u><font color=red>Payment Request</font></u></td></tr>";
	echo"<tr><td height='15' align='center' colspan='16'><font size='1' color='#FF0000' face='Verdana'><b>".$message."</b></font></td></tr>	";
	echo"<tr bgcolor='#DAA520'>
			<th  height='25' align='left'>&nbsp;</th>
			<th  height='25' align='left'>&nbsp;</th>
			<th  height='25' align='left'>&nbsp;</th>
			<th  height='25' align='left'>Ref.</th>
			<th  height='25' align='center'>PO</th>
			<th  height='25' align='center'>Date </th>
			<th  height='25' align='center'>Name</th>
			<th  height='25' align='center'>Approved By</th>";
			
		
	if ($Module_Project == 1)
		echo"<th align='center'>Project</th>";
	else
		echo"<th align='center'>&nbsp;</th>";

	if ($Module_CostCenter == 1)
		echo"<th align='center'>CostCenter</th>";
	else
		echo"<th align='center'>&nbsp;</th>";
		
	echo"	<th  height='25' align='center'>Status</th>";
	echo"	<th  height='25' align='center'>&nbsp;</th>";
	echo"	<th  height='25' align='center'>Reason of Rejecting </th>";
	echo"	<th  height='25' align='center'>Amount $base1</th>";
	echo"	<th  height='25' align='center'>Amount $base2</th>";
	echo"	<th  height='25' align='center'>Remark</th>";
	echo" </tr>";
		
	
	echo"<tr bgcolor='#a8a8a8'><td colspan='16' valign='top'>";
	echo"<table  border='0' cellspacing='0' cellpadding='0' style='table-layout:fixed; width:1040px;'>
			<col width=100>
			<col width=250>
			<col width=250>
			<col width=100>
			<col width=120>
			<col width=120>
			<col width=100>";
	echo "<tr>
			<th height='20' align='left' style='border:0px;'>Ledger No.</th>
			<th height='20' align='left' style='border:0px;'>Ledger Desc.</th> 
			<th height='20' align='left' style='border:0px;'>Description</th> 
			<th height='20' align='center' style='border:0px;'>Currency</th>
			<th height='20' align='center' style='border:0px;'>Debit</th>
			<th height='20' align='center' style='border:0px;'>Credit</th>
			<th height='20' align='center' style='border:0px;'>Value Date</th>
		</tr>";
	echo"</table></td></tr>";	
	echo"</table></div>";

	

	if (empty($ViewPeriodDate))
	   $ViewPeriodDate = 'Null';
	if (empty($ViewNumberOfDays))   
	   $ViewNumberOfDays = 1;
			


	// payment request part	
	$querysearch=" Select PaymentRqst.PaymentRqst_ID, PaymentRqst.PaymentRqst_RefGovernment, Date_Format(PaymentRqst.PaymentRqst_Date,'%d-%m-%Y') As PaymentRqst_Date, ".
				 " PaymentRqst.PaymentRqst_Remark, PaymentRqst.PaymentRqst_Name, PaymentRqst.Touser_account, PaymentRqst.User_Confirmed, ".
				 " PaymentRqst.PaymentRqst_ManualNo, PaymentRqst.PaymentRqst_Desc, Project.Project_Name As ProjectName, Costcent.Costcent_name As CostcentName, ".
				 " Round(ifNull(PaymentRqst.PaymentRqst_AmountD1,0), ".$DecimalBase.") as PaymentRqst_AmountD1, Round(ifNull(PaymentRqst.PaymentRqst_AmountD2,0), ".$DecimalBase.") as PaymentRqst_AmountD2, ".
				 " Round(ifNull(PaymentRqst.PaymentRqst_AmountC1,0), ".$DecimalBase.") as PaymentRqst_AmountC1, Round(ifNull(PaymentRqst.PaymentRqst_AmountC2,0), ".$DecimalBase.") as PaymentRqst_AmountC2, ".
				 " ifnull(PaymentRqst_Confirmed,0) as PaymentRqst_Confirmed, Porder_Reference, PaymentRqst_ApprovedStatus, ifNull(PaymentRqst_ApprovedLevel,5000) as PaymentRqst_ApprovedLevel, PaymentRqst_RejectedReason, ".
				 " if(ifnull(PaymentRqst_ApprovedStatus,'x')='x', 'Pending Approval', if(ifnull(PaymentRqst_ApprovedStatus,'x')='r', 'Rejected', 'Approved')) as PaymentRqstStatus ".
				 " From PaymentRqst ".
				 " Left Join Project on PaymentRqst.Project_Code = Project.Project_Code ".
				 " Left Join Costcent on PaymentRqst.Costcent_code = Costcent.Costcent_code ";
				 
	if ($projectexist >	0)
		$querysearch = $querysearch." Inner join ( select distinct project_code from ".$_SESSION['dbLabel'].".loginstk ".
									"			   where loginstk.user_account='".$_SESSION['useraccount']."' ".
									"              and (project_code is not null and project_code != '') ".
									"			 ) Q1 on (($Module_ProjectParent=1 and PaymentRqst.project_code like concat(Q1.project_code,'%')) or ($Module_ProjectParent=0 and PaymentRqst.project_code = Q1.project_code )) ";
								 
	if ($costcentexist > 0)
		$querysearch = $querysearch." Inner join ( select distinct costcent_code from ".$_SESSION['dbLabel'].".loginstk ".
									"			   where loginstk.user_account='".$_SESSION['useraccount']."' ".
									"              and (costcent_code is not null and costcent_code != '') ".
									"			 ) Q2 on (($Module_CostCenterParent=1 and PaymentRqst.costcent_code like concat(Q2.costcent_code,'%')) or ($Module_CostCenterParent=0 and PaymentRqst.costcent_code = Q2.costcent_code )) ";

	$querysearch= $querysearch.											 
				 " Where if('$PRef'='',1=1,ifNull(PaymentRqst.PaymentRqst_RefGovernment,-1) = '$PRef') ".
				 " And Date_Format(PaymentRqst.PaymentRqst_Date,'%Y-%m-%d') between ifnull('". explodedate($fromdate)."', date_format(PaymentRqst.PaymentRqst_Date,'%Y-%m-%d')) and ifnull('". explodedate($todate)."', date_format(PaymentRqst.PaymentRqst_Date,'%Y-%m-%d'))  ";
				 
	if($itemstatus != '') {
		if($itemstatus == '2') {
			$querysearch = $querysearch." and ((ifnull(PaymentRqst_ApprovedStatus,'x') = 'x' and 1 = 1) or (ifnull(PaymentRqst_ApprovedStatus,'x') = 'a' and PaymentRqst_ApprovedLevel > $PaymentRqstApproved_Level)) ";
		} 
		else if($itemstatus == '3') {
			$querysearch = $querysearch." and ifnull(PaymentRqst_ApprovedStatus,'x') = 'a' and PaymentRqst_ApprovedLevel <= $PaymentRqstApproved_Level ";
		}
		else if($itemstatus == '4') {
			$querysearch = $querysearch." and ifnull(PaymentRqst_ApprovedStatus,'x') = 'r' ";
		}
	}

	
	if ($PProjectCode != '')
		$querysearch= $querysearch." And PaymentRqst.project_code like concat('".$PProjectCode."','%') ";
	if ($PCostCentCode != '')
		$querysearch= $querysearch." And PaymentRqst.costcent_code like concat('".$PCostCentCode."','%') ";			 

	$querysearch= $querysearch." Order By PaymentRqst.PaymentRqst_RefGovernment  ";	
	
			
	
	
	
	//echo $querysearch; exit;

	$resultsearch=mysql_query($querysearch,$connection) or die(mysql_error());
	$totalrows = mysql_num_rows($resultsearch);
		
	if ($startrange=='' || $PRef != 'Null')
		$startrange = 0;
	if ($perpage=='')
		$perpage = 200;
			
	//$querysearch = $querysearch." limit ".$startrange.",".$perpage;

	$resultsearch=mysql_query($querysearch,$connection) or die(mysql_error());	
		
	//echo $querysearch;
	$i = 1000;
	$k = 1;
	$ref = '';
	
	echo"<div id='grid_contentDiv' class='grid_contentDiv' style='height:250px;' onscroll=\"ScrollHeader('grid_headerDiv','grid_contentDiv')\">";
	echo"<table  cellspacing='2' cellpadding='2' style='table-layout:fixed; width:1945px;' class='grid_data1'>
		  <col width=25>
		  <col width=25>
		  <col width=25>
		  <col width=80>
		  <col width=80>
		  <col width=80>
		  <col width=150>
		  <col width=150>
		  <col width=120>
		  <col width=120>
		  <col width=120>
		  <col width=200>
		  <col width=200>
		  <col width=110>
		  <col width=110>
		  <col width=300>";
	while($rows=mysql_fetch_array($resultsearch)){
		extract($rows);
		
		$p = ''; $a = ''; $r = '';
		if ($PaymentRqst_ApprovedStatus=='a')		$a = ' checked ';
		else if ($PaymentRqst_ApprovedStatus=='r')	$r = ' checked ';
		else $p = ' checked ';
		
		if ($PaymentRqst_ApprovedLevel=='')
			$canchange = ' ';
		else if ( ($PaymentRqstApproved_Level > $PaymentRqst_ApprovedLevel)  )
			$canchange = 'disabled ';
		else 	
			$canchange = ' ';
		
	
		
		echo "<tr height=35px bgcolor='#0086B2'>";
		echo '	<td align=center><span class="style5"><img src="img/details.png" onMouseOver="style.cursor=\'hand\'"  onclick="ShowHideDetails('.$PaymentRqst_ID.', \''.'S'.'\','.$startrange.');" title="Show Details" style="width:20px; height:20px; "></span></td>';
			
		if (($Module_PrintApprovedRqst == 1 && $PaymentRqst_ApprovedStatus=='a') || ($Module_PrintApprovedRqst != 1 && 1 == 1))
			echo '<td align=center><span class="style5"><img src="img/print.png" onMouseOver="style.cursor=\'hand\'"  onclick="PrintPreview('.$PaymentRqst_ID.', \''.'PYR'.'\');" title="Print" style="width:20px; height:20px; "></span></td>';
		else
			echo '<td align=center><span class="style5">&nbsp;</span></td>';
				
				
		if ($Module_PaymentLimit == 1 && $Branch_Manager == 1 && $PaymentRqst_Confirmed != 1 && $PaymentRqst_ApprovedStatus=='a') {
			echo"<td align=center><input type='button' name='btnconf$k' onclick=\"ConfirmPaymentRqst('$PaymentRqst_ID','$PaymentRqst_RefGovernment');\" value='C' title='Confirm Request'></td>";
		} else {
			echo '<td align=center><span class="style5">&nbsp;</span></td>';	
		}	
			
		echo "	<td align='center'>$PaymentRqst_RefGovernment</td>";
		echo "	<td align='center'>$Porder_Reference</td>";
		echo "	<td align='center'>$PaymentRqst_Date</td>";
		echo"	<td align='left'><span>$PaymentRqst_Name</span></td>";
		echo"	<td align='left'><span>$Touser_account</span></td>";
			
				 
		if ($Module_Project == 1)
			echo "<td align=center>$ProjectName</td>";
		else
			echo "<td align=center>&nbsp;</td>";
			
		if ($Module_CostCenter == 1)			
			echo "<td align=center>$CostcentName</td>";
		else
			echo "<td align=center>&nbsp;</td>";
			
		
		echo"	<td align='left'><span>$PaymentRqstStatus</span></td>";
		
		echo"	<td align='left'><span class='style15'>";
		if ($itemstatus == '2' || $itemstatus == '3' || $itemstatus == '4')
			echo"<input type='radio' name='r1$k' id='r1$k' value='p' $p  $canchange onclick=\"updateheader('$PaymentRqst_ID',this.value,'PYR','PaymentRqst_RejectedReason$k') ;return false;\"  onMouseOver=\"style.cursor='pointer'\" ><font color=#FFFFFF>Pend.</font>";
		if ($Login_POrdReject == 1 && ($itemstatus == '2' || $itemstatus == '4'))
			echo"<input type='radio' name='r1$k' id='r1$k' value='r' $r  $canchange onclick=\"updateheader('$PaymentRqst_ID',this.value,'PYR','PaymentRqst_RejectedReason$k') ;return false;\"  onMouseOver=\"style.cursor='pointer'\" ><font color=#FF0000>Rej.</font>";
		if ($Login_POrdApprove == 1 && ($itemstatus == '2' || $itemstatus == '3'))	
			echo"<input type='radio' name='r1$k' id='r1$k' value='a' $a  $canchange onclick=\"updateheader('$PaymentRqst_ID',this.value,'PYR','PaymentRqst_RejectedReason$k') ;return false;\"  onMouseOver=\"style.cursor='pointer'\" ><font color=#DAA520>App.</font>";
			
		echo"	</span></td>";
		
		echo"	<td align='left'><input type='text' name='PaymentRqst_RejectedReason$k' id='PaymentRqst_RejectedReason$k' value='$PaymentRqst_RejectedReason'></td>";
		echo"	<td align='right'><span>".number_format($PaymentRqst_AmountD1, 2)."</span></td>";
		echo"	<td align='right'><span>".number_format($PaymentRqst_AmountD2, 2)."</span></td>";
		echo"	<td align='left'><span>$PaymentRqst_Remark</span></td>";
		echo"</tr>";
		
		
		$sub_query = " Select PaymentRqstDt.PaymentRqstDt_Id, PaymentRqstDt.Ledger_Number, Ledger.Ledger_Name, PaymentRqstDt_Desc, ".
					 " Date_Format(PaymentRqstDt_ValueDate,'%d/%m/%Y') As PaymentRqstDt_ValueDate, PaymentRqstDt_dbcd, PaymentRqstDt.Currency_Code, ".
					 " if (PaymentRqstDt_dbcd='D', Round(PaymentRqstDt_Amount, ".$DecimalBase."),'') As DebitAmount, ".
					 " if (PaymentRqstDt_dbcd='C', Round(PaymentRqstDt_Amount, ".$DecimalBase."),'') As CreditAmount ".
					 " From PaymentRqstDt ".
					 " Left Join Ledger on PaymentRqstDt.Ledger_Number = Ledger.Ledger_Number ".
					 " Where PaymentRqstDt.PaymentRqst_Id = ".$PaymentRqst_ID;
		$sub_result=mysql_query($sub_query,$connection) or die(mysql_error());	
		$sub_totalrows = mysql_num_rows($sub_result);
		
		if ($sub_totalrows > 0) {	
		
			$SlideDivId = 'displaydetails'.$PaymentRqst_ID;
			echo"<tr><td colspan='16' valign='top' align='left'><div id='$SlideDivId' style='display:none;'>";
			echo"<table border='0' cellspacing='0' cellpadding='0' style='table-layout:fixed; width:1040px;'>
					<col width=100>
					<col width=250>
					<col width=250>
					<col width=100>
					<col width=120>
					<col width=120>
					<col width=100>";
			
			while($sub_rows=mysql_fetch_array($sub_result)){
				echo "<tr><td>".$sub_rows[1]."</td>
						  <td>".$sub_rows[2]."</td>
						  <td>".$sub_rows[3]."</td>
						  <td align='center'>".$sub_rows[6]."</td>
						  <td align='right'>".number_format($sub_rows[7],$DecimalBase1)."</td>
						  <td align='right'>".number_format($sub_rows[8],$DecimalBase1)."</td>
						  <td align='center'>".$sub_rows[4]."</td>
					  </tr>";
			}
			
			echo "</table></div></td>";
			echo "</tr>";

		}
			  

	
		$k+=1;
	}
			 
	echo"</table>";
	echo"</div>";
	
	echo"</div>";
	echo"</td></tr>";

} //end of paymentrequest

echo"	</table></td></tr>"; 
echo"	</div></div>";
echo"   <tr height='30'><td align='center' id='content-bottom' ></td></tr>";  
echo"</table>";

//Return Today's Date in DD/MM/YYYY format
function displayToday(){
	return strftime("%d")."/".strftime("%m")."/".strftime("%Y");
}
//Return Date in DD/MM/YYYY format
function displayFromDate($data){
	return "01/01/".substr($data, 6, 4);		
}
function explodedate($date)
{
	$trim = explode('/',$date);
	$trim = "$trim[2]"."-"."$trim[1]"."-"."$trim[0]";
	return $trim;
}
function ConvertCurrency($FromCurr, $ToCurr, $FromDate, $Amount, $connection)
{
	$query = "SELECT ifNull(convertcurfunc('".$FromCurr."', '".$ToCurr."', '".$FromDate."', 0, 0, '', '', ifNull($Amount,0)),0) From Dual ";
	$result = selectData($connection, $query);
	//echo $query;
	Return	$result[0];

}

function insertMySQLDate($data){
	$data = insertDate($data);
	return substr($data, 0, 4) ."-". substr($data, 4, 2) ."-".substr($data, 6, 2)." ".strftime("%H").":".strftime("%M").":".strftime("%S");;
}
function insertDate($data){
	return substr($data, 6, 4) . substr($data, 3, 2) . substr($data, 0, 2);
}
function selectData($conn, $query){
	$result = mysql_query($query, $conn);
	$cur = mysql_fetch_row($result);		
	return $cur;
}

print <<<HERE

</form>
</body>

HERE;

?>