<?php

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


$Title = 'PAYMENT REQUEST';      
$Type_dbcd1 = 'D';  
$Type_dbcd2 = 'C';
$Label1 = 'Paid To / Description';
$Label2 = 'Ledger Name/Description';
$HeaderTitle = ucfirst(strtolower($Title)).' Report';

print <<< HERE
<HTML>
<HEAD>
<TITLE> $HeaderTitle </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">

<style type="text/css">

table.master th { font-size: 14px; 
                  font-weight: bold;
                  font-family:Times-New-Roman;
                }				 
table.master td { font-size: 14px; 
                  font-family:Times-New-Roman;
                 }
table.detail th { font-size: 14px; 
                  font-weight: bold;
                  font-family:Times-New-Roman;
                }				 
				 
table.detail td { font-size: 12px; 
                  font-family:Times-New-Roman;
                 }

table.subdetail th { font-size: 12px; 
                     font-weight: bold;
                     font-family:Times-New-Roman;
                   }				 
				 
table.subdetail td { font-size: 11px; 
                     font-family:Times-New-Roman;
                   }				 
				 
h4 { border-top-style: double; 
	 border-top-color: black; 
	 border-top-width: 1px;
   }
</style>


</HEAD>

<BODY>
HERE;

include("config.inc.php");
include("Functions_Trans.php");

$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");

//Read From Setup Table							
$querysetup= " select DecimalBase, DecimalBase1, DecimalBase2, base1, base2, grid_color1, grid_color2, Setup_VatNo, ".
			 " Company_Name As CompanyName, Company_Memo As CompanyMemo ".
			 " from setup ";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
	extract($rowsetup);
}

$querymodule=" Select ifNull(paymentrqstNoDt,0) As paymentrqstNoDt ".
			 " From paymentsetup";
$resultmodule=mysql_query($querymodule,$connection) or die(mysql_error());
while($rowmodule=mysql_fetch_array($resultmodule)){
	extract($rowmodule);
}


	
$now=current_server_time($connection);
$dt=split(" ",$now[0]);
$printdate=split("-",$dt[0]);

$TotalQty = 0;

				 
if($PaymentRqstId != '')
{
	$sub_query1 = " Select PaymentRqst_Id, PaymentRqst_RefGovernment, Date_Format(PaymentRqst_Date,'%d/%m/%Y') As PaymentRqst_Date, ".
				  " PaymentRqst_Remark, PaymentRqst_Name, PaymentRqst_ManualNo, PaymentRqst_Desc, ".
				  " PaymentRqst_App, Touser_account, PaymentRqst_Confirmed, User_Confirmed, ".
				  " PaymentRqst.Project_Code, PaymentRqst.Costcent_code, Currency_Code As Trans_Curr,  ".
				  " Round(ifNull(PaymentRqst_AmountD1,0), ".$DecimalBase1.") As PaymentRqst_AmountD1, Round(ifNull(PaymentRqst_AmountD2,0), ".$DecimalBase1.") As PaymentRqst_AmountD2, ".
				  " Round(ifNull(PaymentRqst_AmountC1,0), ".$DecimalBase2.") As PaymentRqst_AmountC1, Round(ifNull(PaymentRqst_AmountC2,0), ".$DecimalBase2.") As PaymentRqst_AmountC2, ".
				  " PaymentRqst.User_Account As UserAccount, ".
				  " paymentrqst_cash, paymentrqst_check, paymentrqst_costshare, paymentrqst_guarantee".
				  " From PaymentRqst As PaymentRqst ".
				  " Where PaymentRqst_Id = '".$PaymentRqstId."'";
		//echo $sub_query1;		 
	$sub_result1=mysql_query($sub_query1,$connection) or die(mysql_error());
	while($sub_rows1=mysql_fetch_array($sub_result1)){
		extract($sub_rows1);
	}
	
	
		
	echo "<table border=0 width=100% cellspacing=0 cellpadding=0><tr><td align='left'>";
	echo "<table border=0 width='630' cellspacing=2 cellpadding=0 class='master' style='table-layout:fixed;' >
		  <col width=120>
		  <col width=80>
		  <col width=250>
		  <col width=60>
		  <col width=120>";
	echo "<tr><td valign='top' colspan='3'><div style='float:left;'><img src='LogoFile.php' width='115' height='50' /></div>
				<div style='float:left;margin-left:10px;'><b><font size=4>$CompanyName</font></b>
				<br><span style='font-size:9px;'>".nl2br($CompanyMemo)."</span></div>
			  </td>
			  <td align='left' colspan=2 >&nbsp;</td></tr>";
	
	echo "<tr height='10'><td colspan='5'><h4></td></tr>";
	echo "<tr><td colspan='2' rowspan='2'>&nbsp;</td>
			  <td align='center' rowspan='2'><b><font size=4>$Title </font></td>
			  <td align='right' colspan=2 ><font size='2'><b>Printed&nbsp;Date:&nbsp;&nbsp;</b>";
	echo $printdate[2]."/".$printdate[1]."/".$printdate[0];
	echo "</font></td></tr>";
	
	echo "<tr><td align='right' colspan=2 ><font size='2'><b>&nbsp;Time:&nbsp;&nbsp;</b>";
	echo $dt[1]." ".$dt[2];
	echo "</font></td></tr>";
	
	echo "<tr height='10'><td colspan='5'><h4></td></tr>";
	
	echo "<tr>";
	echo "  <th align='left' >Reference</th>";
	echo "  <td align='left' >$PaymentRqst_RefGovernment</td>";
	echo "  <td align='left' >&nbsp;</td>";
	echo "  <th align='left' >Date</th>";
	echo "  <td align='left' >$PaymentRqst_Date</td>";
	echo "</tr>";
	
	echo "<tr>";
	echo "  <th align='left' valign='top'>Order Of</th>";
	echo "  <td align='left' colspan='4'>$PaymentRqst_Name</td>";
	echo "</tr>";
	
	echo "<tr>";
	echo "  <th align='left' valign='top'>Description</th>";
	echo "  <td align='left' colspan='4'>$PaymentRqst_Remark</td>";
	echo "</tr>";
	if($paymentrqstNoDt == 1){
	echo "<tr>";
	echo "  <th align='left' valign='top'>Type </th>";
	echo "  <td align='left' colspan='4'>"; 
	if($paymentrqst_cash == 1) echo "Cash "; 
	if($paymentrqst_check == 1) echo "Cheque ";
	if($paymentrqst_costshare == 1) echo "- Costshare ";
	if($paymentrqst_guarantee == 1) echo "- Guarantee ";
	echo "</td>";
	echo "</tr>";	
		
	}
	//echo "<tr height='10'><td colspan='5'><h4></td></tr>";
	echo "</table></td></tr>";
if($paymentrqstNoDt != 1){
	$sub_query2 = " Select PaymentRqstDt.PaymentRqstDt_Id As PaymentRqstDtId1, PaymentRqstDt.Ledger_Number, Ledger.Ledger_Name, PaymentRqstDt_Desc, PaymentRqstDt_Desc1, PaymentRqstDt.Currency_Code, ".
				  " Round(PaymentRqstDt_Amount, ".$DecimalBase.") As PaymentRqstDt_Amount, Round(PaymentRqstDt_Amount1, ".$DecimalBase1.") As PaymentRqstDt_Amount1, ".
				  " Round(PaymentRqstDt_Amount2, ".$DecimalBase2.") As PaymentRqstDt_Amount2, Date_Format(PaymentRqstDt_ValueDate,'%d/%m/%Y') As PaymentRqstDt_ValueDate ".
				  " From PaymentRqstDt Left Join Ledger on PaymentRqstDt.Ledger_Number = Ledger.Ledger_Number ".
				  " Where PaymentRqstDt.PaymentRqst_Id = '".$PaymentRqstId."' ".
				  " And PaymentRqstDt.PaymentRqstDt_dbcd = '".$Type_dbcd1."' ".
				  " Order By PaymentRqstDt.Ledger_Number ";
	//echo $sub_query2;
			
	echo "<tr><td align='left'>";
	echo "<table border=0 width='630' cellspacing=1 class='detail' style='table-layout:fixed;' >
		  <col width=80>
		  <col width=40>
		  <col width=170>
		  <col width=90>
		  <col width=90>
		  <col width=90>
		  <col width=75>";
		  
	
	echo "<tr bgcolor=#D8D8D8>";
	echo "   <th align='left'>Ledger No. </th>";
	echo "	 <th align='center'>Cur.</th>";
	echo "   <th align='left'>$Label1</th>";
	echo "	 <th align='center'>Amount</th>";
	echo "	 <th align='center'>$base1</th>";
	echo "	 <th align='center'>$base2</th>";
	echo "	 <th align='center'>Value Date</th>";
	echo "</tr>";			
	echo "<tr height='10'><td colspan='7'><h4></td></tr>";	
		  
	
	$sub_result2=mysql_query($sub_query2,$connection) or die(mysql_error());
	while($sub_rows2=mysql_fetch_array($sub_result2)){
		extract($sub_rows2);
		
		echo "<tr>";
		echo "  <td align='left' valign='top'>$Ledger_Number</td>";
		echo "  <td align='center' valign='top'>$Currency_Code</td>";
		echo "  <td align='left' valign='top'>$Ledger_Name</td>";
		echo "	<td align='right' valign='top'>".number_format($PaymentRqstDt_Amount, $DecimalBase)."</td>";
		echo "	<td align='right' valign='top'>".number_format($PaymentRqstDt_Amount1, $DecimalBase1)."</td>";
		echo "	<td align='right' valign='top'>".number_format($PaymentRqstDt_Amount2, $DecimalBase2)."</td>";
		echo "	<td align='center' valign='top'>$PaymentRqstDt_ValueDate</td>";
		echo "</tr>";		
		
		echo "<tr>";
		echo "  <td align='left' valign='top'>&nbsp;</td>";
		echo "  <td align='left' valign='top' colspan='6'>$PaymentRqstDt_Desc</td>";
		echo "</tr>";
		
					 
		// Display Checks
		$sub_query4 = " Select ChkRqst.Chk_number, ChkRqst.Chk_bank, Date_Format(ChkRqst.Chk_ValueDate,'%d/%m/%Y') As Chk_ValueDate, ChkRqst.Currency_Code As Chk_Currency, ChkRqst.Ledger_Number, ".
				      " ChkRqst.Chk_Type, Round(ChkRqst.Chk_Amount, ".$DecimalBase.") As Chk_Amount, Round(ChkRqst.Chk_Amount1, ".$DecimalBase1."), Round(ChkRqst.Chk_Amount2, ".$DecimalBase2.") ".
				      " From ChkRqst ".
				      " Where ChkRqst.PaymentRqstDt_Id = '".$PaymentRqstDtId1."' ".
				      " Order By ChkRqst.Chk_number ";
		$sub_result4=mysql_query($sub_query4,$connection) or die(mysql_error());			  
		$ChkCount = mysql_num_rows($sub_result4);
		
		if ($ChkCount > 0) {			  
			echo "<tr><td colspan='7'>";	
			echo "<table border=0 width='630' cellspacing=1 class='subdetail' style='table-layout:fixed;' >
				  <col width=90>
				  <col width=80>
				  <col width=200>
				  <col width=70>
				  <col width=55>
				  <col width=80>
				  <col width=50>";
			echo "<tr>";
			echo "   <th align='left'>&nbsp;</th>";
			echo "   <th align='left'>Check No.</th>";
			echo "	 <th align='left'>Bank</th>";
			echo "	 <th align='center'>Value Date</th>";
			echo "	 <th align='center'>Currency</th>";
			echo "	 <th align='center'>Amount</th>";
			echo "   <th align='left'>&nbsp;</th>";
			echo "</tr>";	
			
			$sub_result4=mysql_query($sub_query4,$connection) or die(mysql_error());
			while($sub_rows4=mysql_fetch_array($sub_result4)){
				extract($sub_rows4);
				
				echo "<tr>";
				echo "  <td align='left' valign='top'>&nbsp;</td>";
				echo "  <td align='left' valign='top'>$Chk_number</td>";
				echo "  <td align='left' valign='top'>$Chk_bank</td>";
				echo "	<td align='center' valign='top'>$Chk_ValueDate</td>";
				echo "	<td align='center' valign='top'>$Chk_Currency</td>";
				echo "	<td align='right' valign='top'>".number_format($Chk_Amount, $DecimalBase)."</td>";
				echo "  <td align='left' valign='top'>&nbsp;</td>";
				echo "</tr>";
				
			}	
			
			echo"</table></td></tr>";
		}
		
		// Display Bills
		$sub_query5 = " Select BillRqst.Bill_number, BillRqst.Bill_bank, Date_Format(BillRqst.Bill_ValueDate,'%d/%m/%Y') As Bill_ValueDate, BillRqst.Currency_Code As Bill_Currency, BillRqst.Ledger_Number, ".
				      " BillRqst.Bill_Type, Round(BillRqst.Bill_Amount, ".$DecimalBase.") As Bill_Amount, Round(BillRqst.Bill_Amount1, ".$DecimalBase1."), Round(BillRqst.Bill_Amount2, ".$DecimalBase2.") ".
				      " From BillRqst ".
				      " Where BillRqst.PaymentRqstDt_Id = '".$PaymentRqstDtId1."' ".
				      " Order By BillRqst.Bill_number ";
		
		$sub_result5=mysql_query($sub_query5,$connection) or die(mysql_error());			  
		$BillCount = mysql_num_rows($sub_result5);
		
		if ($BillCount > 0) {			  
			echo "<tr><td colspan='7'>";	
			echo "<table border=0 width='630' cellspacing=1 class='subdetail' style='table-layout:fixed;' >
				  <col width=90>
				  <col width=80>
				  <col width=200>
				  <col width=70>
				  <col width=55>
				  <col width=80>
				  <col width=50>";
			echo "<tr>";
			echo "   <th align='left'>&nbsp;</th>";
			echo "   <th align='left'>Bill No.</th>";
			echo "	 <th align='left'>Bank</th>";
			echo "	 <th align='center'>Value Date</th>";
			echo "	 <th align='center'>Currency</th>";
			echo "	 <th align='center'>Amount</th>";
			echo "   <th align='left'>&nbsp;</th>";
			echo "</tr>";	
			
			$sub_result5=mysql_query($sub_query5,$connection) or die(mysql_error());
			while($sub_rows5=mysql_fetch_array($sub_result5)){
				extract($sub_rows5);
				
				echo "<tr>";
				echo "  <td align='left' valign='top'>&nbsp;</td>";
				echo "  <td align='left' valign='top'>$Bill_number</td>";
				echo "  <td align='left' valign='top'>$Bill_bank</td>";
				echo "	<td align='center' valign='top'>$Bill_ValueDate</td>";
				echo "	<td align='center' valign='top'>$Bill_Currency</td>";
				echo "	<td align='right' valign='top'>".number_format($Bill_Amount, $DecimalBase)."</td>";
				echo "  <td align='left' valign='top'>&nbsp;</td>";
				echo "</tr>";
				
			}	
			
			echo"</table></td></tr>";
		}
		
				 
		// Display Projects/Costcenters
		$sub_query6 = " Select Project_code, Costcent_Code, CstRqst_Prcnt, Round(CstRqst_Amount, ".$DecimalBase.") As CstRqst_Amount, ".
				      " Round(CstRqst_Amount1, ".$DecimalBase1."), Round(CstRqst_Amount2, ".$DecimalBase2.") ".
				      " From CstRqst ".
				      " Where PaymentRqstDt_Id = '".$PaymentRqstDtId1."' ".
				      " Order By Project_code ";			  
		
		$sub_result6=mysql_query($sub_query6,$connection) or die(mysql_error());			  
		$CstCount = mysql_num_rows($sub_result6);
		
		if ($CstCount > 0) {			  
			echo "<tr><td colspan='7'>";	
			echo "<table border=0 width='630' cellspacing=1 class='subdetail' style='table-layout:fixed;' >
				  <col width=90>
				  <col width=80>
				  <col width=200>
				  <col width=70>
				  <col width=55>
				  <col width=80>
				  <col width=50>";
			echo "<tr>";
			echo "   <th align='left'>&nbsp;</th>";
			echo "   <th align='left'>Project</th>";
			echo "	 <th align='left'>Cost Center</th>";
			echo "	 <th align='center'>Percentage</th>";
			echo "	 <th align='center'>&nbsp;</th>";
			echo "	 <th align='center'>Amount</th>";
			echo "   <th align='left'>&nbsp;</th>";
			echo "</tr>";	
			
			
			$sub_result6=mysql_query($sub_query6,$connection) or die(mysql_error());
			while($sub_rows6=mysql_fetch_array($sub_result6)){
				extract($sub_rows6);
				
				echo "<tr>";
				echo "  <td align='left' valign='top'>&nbsp;</td>";
				echo "  <td align='left' valign='top'>$Project_code</td>";
				echo "  <td align='left' valign='top'>$Costcenter_Code</td>";
				echo "	<td align='center' valign='top'>".number_format($CstRqst_Prcnt, $DecimalBase)."%</td>";
				echo "	<td align='center' valign='top'>&nbsp;</td>";
				echo "	<td align='right' valign='top'>".number_format($CstRqst_Amount, $DecimalBase)."</td>";
				echo "  <td align='left' valign='top'>&nbsp;</td>";
				echo "</tr>";
				
			}	
			
			echo"</table></td></tr>";
		}
		
	}

	echo "</table></td></tr>";
}
	if($paymentrqstNoDt != 1){
	$sub_query3 = " Select PaymentRqstDt.PaymentRqstDt_Id As PaymentRqstDtId2, PaymentRqstDt.Ledger_Number, Ledger.Ledger_Name, PaymentRqstDt_Desc, PaymentRqstDt_Desc1, PaymentRqstDt.Currency_Code, ".
				  " Round(PaymentRqstDt_Amount, ".$DecimalBase.") As PaymentRqstDt_Amount, Round(PaymentRqstDt_Amount1, ".$DecimalBase1.") As PaymentRqstDt_Amount1, ".
				  " Round(PaymentRqstDt_Amount2, ".$DecimalBase2.") As PaymentRqstDt_Amount2, Date_Format(PaymentRqstDt_ValueDate,'%d/%m/%Y') As PaymentRqstDt_ValueDate ".
				  " From PaymentRqstDt Left Join Ledger on PaymentRqstDt.Ledger_Number = Ledger.Ledger_Number ".
				  " Where PaymentRqstDt.PaymentRqst_Id = '".$PaymentRqstId."' ".
				  " And PaymentRqstDt.PaymentRqstDt_dbcd = '".$Type_dbcd2."' ".
				  " Order By PaymentRqstDt.Ledger_Number ";
	//echo $sub_query3;
				
	echo "<tr><td align='left'>";
	echo "<table border=0 width='630' cellspacing=1 class='detail' style='table-layout:fixed;' >
		  <col width=80>
		  <col width=40>
		  <col width=170>
		  <col width=90>
		  <col width=90>
		  <col width=90>
		  <col width=75>";
			  
	echo "<tr bgcolor=#D8D8D8>";
	echo "   <th align='left'>Ledger No.</th>";
	echo "   <th align='left' colspan='2'>$Label2</th>";
	echo "	 <th align='center'>&nbsp;</th>";
	echo "	 <th align='center'>Value Date</th>";
	echo "	 <th align='center' colspan='2'>Amount</th>";
	echo "</tr>";	
	echo "<tr height='10'><td colspan='7'><h4></td></tr>";	
		
	$sub_result3=mysql_query($sub_query3,$connection) or die(mysql_error());
	while($sub_rows3=mysql_fetch_array($sub_result3)){
		extract($sub_rows3);
			
		echo "<tr>";
		echo "  <td align='left' valign='top'>$Ledger_Number</td>";
		echo "  <td align='left' valign='top' colspan='2'>$Ledger_Name</td>";
		echo "  <td align='center' valign='top'>&nbsp;</td>";
		echo "	<td align='center' valign='top'>$PaymentRqstDt_ValueDate</td>";
		echo "	<td align='right' valign='top' colspan='2'>".number_format($PaymentRqstDt_Amount, $DecimalBase)."  ".$Currency_Code."</td>";
		echo "</tr>";
			
		echo "<tr>";
		echo "  <td align='left' valign='top'>&nbsp;</td>";
		echo "  <td align='left' valign='top' colspan='6'>$PaymentRqstDt_Desc</td>";
		echo "</tr>";
			
			
		$sub_query7 = " Select ChkRqst.Chk_number, ChkRqst.Chk_bank, Date_Format(ChkRqst.Chk_ValueDate,'%d/%m/%Y') As Chk_ValueDate, ChkRqst.Currency_Code As Chk_Currency, ChkRqst.Ledger_Number, ".
					  " ChkRqst.Chk_Type, Round(ChkRqst.Chk_Amount, ".$DecimalBase.") As Chk_Amount, Round(ChkRqst.Chk_Amount1, ".$DecimalBase1."), Round(ChkRqst.Chk_Amount2, ".$DecimalBase2.") ".
					  " From ChkRqst ".
					  " Where ChkRqst.PaymentRqstDt_Id = '".$PaymentRqstDtId2."' ".
					  " Order By ChkRqst.Chk_number ";
		$sub_result7=mysql_query($sub_query7,$connection) or die(mysql_error());			  
		$ChkCount = mysql_num_rows($sub_result7);
			
		if ($ChkCount > 0) {			  
			echo "<tr><td colspan='7'>";	
			echo "<table border=0 width='630' cellspacing=1 class='subdetail' style='table-layout:fixed;' >
				  <col width=90>
				  <col width=80>
				  <col width=200>
				  <col width=70>
				  <col width=55>
				  <col width=80>
				  <col width=50>";
			echo "<tr>";
			echo "   <th align='left'>&nbsp;</th>";
			echo "   <th align='left'>Check No.</th>";
			echo "	 <th align='left'>Bank</th>";
			echo "	 <th align='center'>Value Date</th>";
			echo "	 <th align='center'>Currency</th>";
			echo "	 <th align='center'>Amount</th>";
			echo "   <th align='left'>&nbsp;</th>";
			echo "</tr>";	
				
			$sub_result7=mysql_query($sub_query7,$connection) or die(mysql_error());
			while($sub_rows7=mysql_fetch_array($sub_result7)){
				extract($sub_rows7);
					
				echo "<tr>";
				echo "  <td align='left' valign='top'>&nbsp;</td>";
				echo "  <td align='left' valign='top'>$Chk_number</td>";
				echo "  <td align='left' valign='top'>$Chk_bank</td>";
				echo "	<td align='center' valign='top'>$Chk_ValueDate</td>";
				echo "	<td align='center' valign='top'>$Chk_Currency</td>";
				echo "	<td align='right' valign='top'>".number_format($Chk_Amount, $DecimalBase)."</td>";
				echo "  <td align='left' valign='top'>&nbsp;</td>";
				echo "</tr>";
					
			}	
				
			echo"</table></td></tr>";
		}
			
			
		// Display Bills
		$sub_query8 = " Select BillRqst.Bill_number, BillRqst.Bill_bank, Date_Format(BillRqst.Bill_ValueDate,'%d/%m/%Y') As Bill_ValueDate, BillRqst.Currency_Code As Bill_Currency, BillRqst.Ledger_Number, ".
					  " BillRqst.Bill_Type, Round(BillRqst.Bill_Amount, ".$DecimalBase.") As Bill_Amount, Round(BillRqst.Bill_Amount1, ".$DecimalBase1."), Round(BillRqst.Bill_Amount2, ".$DecimalBase2.") ".
					  " From BillRqst ".
					  " Where BillRqst.PaymentRqstDt_Id = '".$PaymentRqstDtId2."' ".
					  " Order By BillRqst.Bill_number ";
			
		$sub_result8=mysql_query($sub_query8,$connection) or die(mysql_error());			  
		$BillCount = mysql_num_rows($sub_result8);
			
		if ($BillCount > 0) {			  
			echo "<tr><td colspan='7'>";	
			echo "<table border=0 width='630' cellspacing=1 class='subdetail' style='table-layout:fixed;' >
				  <col width=90>
				  <col width=80>
				  <col width=200>
				  <col width=70>
				  <col width=55>
				  <col width=80>
				  <col width=50>";
			echo "<tr>";
			echo "   <th align='left'>&nbsp;</th>";
			echo "   <th align='left'>Bill No.</th>";
			echo "	 <th align='left'>Bank</th>";
			echo "	 <th align='center'>Value Date</th>";
			echo "	 <th align='center'>Currency</th>";
			echo "	 <th align='center'>Amount</th>";
			echo "   <th align='left'>&nbsp;</th>";
			echo "</tr>";	
				
			$sub_result8=mysql_query($sub_query8,$connection) or die(mysql_error());
			while($sub_rows8=mysql_fetch_array($sub_result8)){
				extract($sub_rows8);
					
				echo "<tr>";
				echo "  <td align='left' valign='top'>&nbsp;</td>";
				echo "  <td align='left' valign='top'>$Bill_number</td>";
				echo "  <td align='left' valign='top'>$Bill_bank</td>";
				echo "	<td align='center' valign='top'>$Bill_ValueDate</td>";
				echo "	<td align='center' valign='top'>$Bill_Currency</td>";
				echo "	<td align='right' valign='top'>".number_format($Bill_Amount, $DecimalBase)."</td>";
				echo "  <td align='left' valign='top'>&nbsp;</td>";
				echo "</tr>";
					
			}	
				
			echo"</table></td></tr>";
		}
			
			
		// Display Projects/Costcenters
		$sub_query9 = " Select Project_code, Costcent_Code, CstRqst_Prcnt, Round(CstRqst_Amount, ".$DecimalBase.") As CstRqst_Amount, ".
					  " Round(CstRqst_Amount1, ".$DecimalBase1."), Round(CstRqst_Amount2, ".$DecimalBase2.") ".
					  " From CstRqst ".
					  " Where PaymentRqstDt_Id = '".$PaymentRqstDtId2."' ".
					  " Order By Project_code ";			  
			
		$sub_result9=mysql_query($sub_query9,$connection) or die(mysql_error());			  
		$CstCount = mysql_num_rows($sub_result9);
			
		if ($CstCount > 0) {			  
			echo "<tr><td colspan='7'>";	
			echo "<table border=0 width='630' cellspacing=1 class='subdetail' style='table-layout:fixed;' >
				  <col width=90>
				  <col width=80>
				  <col width=200>
				  <col width=70>
				  <col width=55>
				  <col width=80>
				  <col width=50>";
			echo "<tr>";
			echo "   <th align='left'>&nbsp;</th>";
			echo "   <th align='left'>Project</th>";
			echo "	 <th align='left'>Cost Center</th>";
			echo "	 <th align='center'>Percentage</th>";
			echo "	 <th align='center'>&nbsp;</th>";
			echo "	 <th align='center'>Amount</th>";
			echo "   <th align='left'>&nbsp;</th>";
			echo "</tr>";	
				
			$sub_result9=mysql_query($sub_query9,$connection) or die(mysql_error());
			while($sub_rows9=mysql_fetch_array($sub_result9)){
				extract($sub_rows9);
					
				echo "<tr>";
				echo "  <td align='left' valign='top'>&nbsp;</td>";
				echo "  <td align='left' valign='top'>$Project_code</td>";
				echo "  <td align='left' valign='top'>$Costcenter_Code</td>";
				echo "	<td align='center' valign='top'>".number_format($CstRqst_Prcnt, $DecimalBase)."%</td>";
				echo "	<td align='center' valign='top'>&nbsp;</td>";
				echo "	<td align='right' valign='top'>".number_format($CstRqst_Amount, $DecimalBase)."</td>";
				echo "  <td align='left' valign='top'>&nbsp;</td>";
				echo "</tr>";
					
			}	
				
			echo"</table></td></tr>";
		}
			
			
	}
		
	//echo "<tr height='10'><td colspan=7><h4></td></tr>";
	echo "</table></td></tr>";
	}
	
	if (empty($PaymentRqst_AmountD1)) $PaymentRqst_AmountD1 = 0;
	$Trans_TotalAmount = ConvertCurrency($base1, $Trans_Curr, insertMySQLDate($PaymentRqst_Date), $PaymentRqst_AmountD1, $connection);
		
	$queryalpha  = " SELECT Alpha_Num ('ENGLISH', '".$Trans_Curr."', ".$Trans_TotalAmount.") As AlphaAmount FROM Dual ";
	$resultalpha = mysql_query($queryalpha,$connection) or die(mysql_error());
	$rowalpha=mysql_fetch_array($resultalpha);
		
	$Label1 = 'Paid to';
	$Label2 = 'Prepared by';
	echo "<tr height='15'><td></td></tr>";		
	echo "<tr><td align='left'>";
	echo "<div style='border:1px black solid; width:630px;'> ";
	echo "<table border=0 width='630' cellspacing=2 class='master' style='table-layout:fixed;' >
		  <col width=80>
		  <col width=120>
		  <col width=160>
		  <col width=100>
		  <col width=170>
		  ";

	echo "<tr height='20'><th align='left'>Total</th><td align='right'>".number_format($Trans_TotalAmount, $DecimalBase)."</td><td align='left'>".$Trans_Curr."</td>";
	echo "	<td colspan='2'>&nbsp;</td></tr>";
			
	echo "<tr height='20'><th align='left'>The Sum of</th><td colspan='4' valign='top' >".$rowalpha[0]."</td></tr>";
	echo "<tr height='25'><td colspan='5'>&nbsp;</td></tr>";
	echo "<tr height='30'><td>&nbsp;</td><th align='center'>$Label1</th><td><div style='border-bottom:1px black solid; width:130px;'></div></td><th align='left'>$Label2</th><td><div style='border-bottom:1px black solid; width:150px;'></div></td></tr>";		
	echo "<tr height='40'><td colspan='5'>$UserAccount</td></tr>";
		
	echo "</table>";	
	echo "</div>";
	echo "</td></tr>";		
	
		
	
	echo "</table>";
	echo "<br>";
	

}


function current_server_time($connection){

  $string="Select date_format(NOW(),'%Y-%m-%d %h:%i %p') ";
  $result=mysql_query($string,$connection) or die(mysql_error());
  $now=mysql_fetch_row($result);

  return $now;
}

function format_currency($amount, $DecimalBase) { 

    if($amount < 0) 
        return "(".number_format(abs($amount),$DecimalBase).")"; 
 
    else return number_format($amount, $DecimalBase); 
} 

print <<< HERE

<script language=javascript>
if (typeof(window.print) != 'undefined')
{
    window.print();
}
</script>
</BODY>
</HTML>
HERE;
?>

