<?php

//header("Content-type: text/html; charset=UTF8");
//Report Version For Common
session_start();
if($HTTP_SESSION_VARS['dbName']==""){
header("location:../index.php");
}

if ($TransType == 'PV')       { $Title = 'PAYMENT VOUCHER';      $Type_dbcd1 = 'D';  $Type_dbcd2 = 'C'; }
else if ($TransType == 'RV')  { $Title = 'RECEIPT VOUCHER';      $Type_dbcd1 = 'C';  $Type_dbcd2 = 'D'; } 
else if ($TransType == 'CV')  { $Title = 'CREDIT NOTE VOUCHER';  $Type_dbcd1 = 'C';  $Type_dbcd2 = 'D'; }
else if ($TransType == 'DV')  { $Title = 'DEBIT NOTE VOUCHER';   $Type_dbcd1 = 'D';  $Type_dbcd2 = 'C'; }
else if ($TransType == 'CT')  { $Title = 'CONTRA VOUCHER';       $Type_dbcd1 = 'D';  $Type_dbcd2 = 'C'; }

$HeaderTitle = ucfirst(strtolower($Title)).' Report';

print <<< HERE
<HTML>
<HEAD>


<TITLE> $HeaderTitle </TITLE>

<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="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;
                   }				 
				 

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


//mysql_query("SET NAMES 'utf8'"); 
//mysql_query('SET CHARACTER SET utf8'); 		
//mysql_set_charset('utf8', $connection);

//Read From Setup Table							
$querysetup= " select DecimalBase, DecimalBase1, DecimalBase2, base1, base2, grid_color1, grid_color2, Company_Name, Company_Memo , Date_Format(Setup_VatStartDate,'%d/%m/%Y') As Setup_VatStartDate  from setup ";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
	extract($rowsetup);
}


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

$TotalQty = 0;

	$top = 'border-top:1px solid black';	
	$bottom = 'border-bottom:1px solid black';	
	$left = 'border-left:1px solid black';	
	$right = 'border-right:1px solid black';
	
if($TransId != ''){
	$sub_query1 = " Select Trans_ID, Trans_Reference, Date_Format(Trans_Date,'%d/%m/%Y') As Trans_Date, ".
				  " Trans_Type, Trans_Remark, Trans_Representative, Trans_CashReference, CashType_code,  ".
				  " Trans_ManualNo, Trans.Project_Code, Trans.Costcent_code, Journal.Journal_folio, Journal.Journal_refgovernment, Currency_Code As Trans_Curr,  ".
				  " Round(ifNull(Trans_AmountDb1,0), ".$DecimalBase1.") As Trans_AmountDb1, Round(ifNull(Trans_AmountDb2,0), ".$DecimalBase1.") As Trans_AmountDb2, ".
				  " Round(ifNull(Trans_Amountcd1,0), ".$DecimalBase2.") As Trans_Amountcd1, Round(ifNull(Trans_Amountcd2,0), ".$DecimalBase2.") As Trans_Amountcd2".
				  " From Trans As Trans ".
				  " Left Join Journal on Trans.Journal_ID = Journal.Journal_ID ".
				  " Where Trans_ID = '".$TransId."'";
				  
					//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);
					}
			$Company_Memo = str_replace("\n", "<br>", $Company_Memo);
					if($bank==''){		
						echo "<table border=0 width=740 cellspacing=0 cellpadding=0>
							  <tr><td align='left'>";
							  if ($TransType=='RV') {
								  echo "<table border='0' width='740' cellspacing=0 cellpadding=0 class='master' style='table-layout:fixed;' >
							  <col width=300>
							  <col width=340>
							  <col width=200>";
								echo "<tr>
								<td valign='top' colspan='2'> <img src='LogoFile.php' width='200px' height='80px' /> </td>
									  <td style='text-align: right'>
										  <span style='font-weight:bold; font-size:20px; text-align: right'> $Company_Name </span>
									  <br>
									  <br><span style='font-size:14px; text-align: right'>$Company_Memo</span>
																		 
									  
									
									  </tr>";
								echo "</table></td></tr>";
							  }
							else  if ($TransType == 'PV'){
								  echo "<table border='0' width='740' cellspacing=0 cellpadding=0 class='master' style='table-layout:fixed;' >
							  <col width=300>
							  <col width=340>
							  <col width=200>";
								echo "<tr>
								<td valign='top' colspan='2'> <img src='LogoFile.php' width='200px' height='80px' /> </td>
									  <td style='text-align: right'>
										  <span style='font-weight:bold; font-size:20px; text-align: right'> $Company_Name </span>
									  <br>
									  <br><span style='font-size:14px; text-align: right'>$Company_Memo</span>
																		 
									  
									
									  </tr>";
								echo "</table></td></tr>";
							 
							  }
							  else  if ($TransType == 'CV'){
								  echo "<table border='0' width='740' cellspacing=0 cellpadding=0 class='master' style='table-layout:fixed;' >
							  <col width=300>
							  <col width=340>
							  <col width=200>";
								echo "<tr>
								<td valign='top' colspan='2'> <img src='LogoFile.php' width='200px' height='80px' /> </td>
									  <td style='text-align: right'>
										  <span style='font-weight:bold; font-size:20px; text-align: right'> $Company_Name </span>
									  <br>
									  <br><span style='font-size:14px; text-align: right'>$Company_Memo</span>
																		 
									  
									
									  </tr>";
								echo "</table></td></tr>";
							 
							  }
							  
							  else  if ($TransType == 'DV'){
								  echo "<table border='0' width='740' cellspacing=0 cellpadding=0 class='master' style='table-layout:fixed;' >
							  <col width=300>
							  <col width=340>
							  <col width=200>";
								echo "<tr>
								<td valign='top' colspan='2'> <img src='LogoFile.php' width='200px' height='80px' /> </td>
									  <td style='text-align: right'>
										  <span style='font-weight:bold; font-size:20px; text-align: right'> $Company_Name </span>
									  <br>
									  <br><span style='font-size:14px; text-align: right'>$Company_Memo</span>
																		 
									  
									
									  </tr>";
								echo "</table></td></tr>";
							 
							  }
							 

							 else {
						echo "<table border='0' width='640' cellspacing=0 cellpadding=0 class='master' style='table-layout:fixed;' >
							  <col width=100>
							  <col width=340>
							  <col width=200>";
						echo "<tr>";
						echo "	<td align='center' valign='top' rowspan='3' ><img src='LogoFile.php' width='90px' height='100px' /></td>";
						echo "	<td align='left' valign='top' style='font-size:20px; font-weight:bold;'>".nl2br($Company_Name)."</td>";
						echo "	<td align='right' valign='top' rowspan='3' ><font size='2'><b>Printed&nbsp;Date</b>&nbsp;&nbsp;".$printdate[2]."/".$printdate[1]."/".$printdate[0] .
								"<br><b>Time</b>&nbsp;&nbsp;&nbsp;".$dt[1]." ".$dt[2];
						echo"	</td>";
						echo "</tr>";
						echo "<tr>";
						echo "	<td align='left' style='font-size:11px;'>".nl2br($Company_Memo)."</td>";
						echo "</tr>";
						echo "<tr>
								<td align='center' style='font-size:20px; font-weight:bold; height:50px; '>".$Title."</td>
							  </tr>";
						echo "</table></td></tr>";
							  }
							  
							if ($TransType=='RV') {
								echo"<tr height='50px'> 
									<td align='center' colspan='3'><span style='font-size:20px; font-weight:bold;font-family: Arial'> Receipt Voucher</span></tr>
									</tr>
									";
							}
							else if ($TransType=='PV') {
								echo"<tr height='50px'> 
									<td align='center' colspan='3'><span style='font-size:20px; font-weight:bold;font-family: Arial'> Payment Voucher</span></tr>
									</tr>
									";
							}
							else if ($TransType=='CV') {
								echo"<tr height='50px'> 
									<td align='center' colspan='3'><span style='font-size:20px; font-weight:bold;font-family: Arial'> Credit Note Voucher</span></tr>
									</tr>
									";
							}
							
							else if ($TransType=='DV') {
								echo"<tr height='50px'> 
									<td align='center' colspan='3'><span style='font-size:20px; font-weight:bold;font-family: Arial'> Debit Note Voucher</span></tr>
									</tr>
									";
							}
							
							else {
						echo "<tr><td>
							  <table border=0 width='630' cellspacing=2 cellpadding=0 class='master' style='table-layout:fixed;' >
							  <col width=70>
							  <col width=60>
							  <col width=60>
							  <col width=100>
							  <col width=60>
							  <col width=100>
							  <col width=60>
							  <col width=120>";
							
								
								echo "<tr height='10'><td colspan='8'><hr></td></tr>";
								
								echo "<tr>";
								echo "  <th align='left' >Reference</th>";
								echo "  <td align='left' >$Trans_Reference</td>";
								echo "  <th align='left' >JV Ref.</th>";
								echo "  <td align='left' >$Journal_refgovernment</td>";
								echo "  <th align='left' >Folio</th>";
								echo "  <td align='left' >$Journal_folio</td>";
								echo "  <th align='left' >Date</th>";
								echo "  <td align='left' >$Trans_Date</td>";
								echo "</tr>";
								
								echo "<tr>";
								echo "  <th align='left' valign='top' colspan='2'>Representative</th>";
								echo "  <td align='left' colspan='6'>$Trans_Representative</td>";
								echo "</tr>";
								
								echo "<tr>";
								echo "  <th align='left' valign='top' colspan='2'>Remark</th>";
								echo "  <td align='left' colspan='6'>$Trans_Remark</td>";
								echo "</tr>";
								
								echo "<tr height='10'><td colspan='8'><hr></td></tr>";
								echo "</table></td></tr>";
					}
					}

	$sub_query2 = " Select TransDt.TransDt_id As TransDtId1, TransDt.Ledger_Number, Ledger.Ledger_Name, TransDt_Description, TransDt.Currency_Code, ".
				  " Round(Transdt_Amount, ".$DecimalBase.") As Transdt_Amount, Round(Transdt_Amount1, ".$DecimalBase1."), Round(Transdt_Amount2, ".$DecimalBase2."), ".
				  " Date_Format(TransDt_ValueDate,'%d/%m/%Y') As TransDt_ValueDate , Project_Name ".
				  " From TransDt Left Join Ledger on TransDt.Ledger_Number = Ledger.Ledger_Number
					left join trans t on t.Trans_ID = TransDt.Trans_ID
				    left join project p on p.project_code = t.project_code".
				  " Where TransDt.Trans_ID = '".$TransId."' ".
				  " And TransDt.TransDt_dbcd = '".$Type_dbcd1."' ".
				  " Order By TransDt.Ledger_Number ";
	//echo $sub_query2;
					if($bank==''){
						
						if($TransType=='RV'){
							
							$sub_query23 = " Select TransDt.TransDt_id As TransDtId2, TransDt.Ledger_Number, Ledger.Ledger_Name, TransDt_Description, TransDt.Currency_Code as tcur, ".
								  " Round(Transdt_Amount, ".$DecimalBase.") As Transdt_Amount, Round(Transdt_Amount1, ".$DecimalBase1."), Round(Transdt_Amount2, ".$DecimalBase2."), ".
								  " Date_Format(TransDt_ValueDate,'%d/%m/%Y') As TransDt_ValueDate ".
								  " From TransDt Left Join Ledger on TransDt.Ledger_Number = Ledger.Ledger_Number ".
								  " Where TransDt.Trans_ID = '".$TransId."' ".
								  " And TransDt.TransDt_dbcd = '".$Type_dbcd2."' ".
								  " Order By TransDt.Ledger_Number ";
								 // echo $sub_query23;
						$sub_result23=mysql_query($sub_query23,$connection) or die(mysql_error());
						$sub_rows23=mysql_fetch_array($sub_result23);
						extract($sub_rows23);
							$sub_result2=mysql_query($sub_query2,$connection) or die(mysql_error());
						while($sub_rows2=mysql_fetch_array($sub_result2)){
							extract($sub_rows2);
							echo "<tr><td align='left'>";
							echo "<table border=0 width='100%' cellspacing=0 class='detail' style='table-layout:fixed;' >
								  <col width='150'>
								  <col width='270'>
								  <col width='210'>";
							echo "
							<tr height='35px'>
								  <td style='border-left: solid 2px #000000; border-top: solid 2px #000000; padding: 3px'><span style='font-size:14px; font-weight: bold'></span></td>
								  <td colspan='1' style='border-top: solid 2px #000000;  padding: 3px'><span style='font-size:14px;'></span> </td>
								  <td style=' border-top: solid 2px #000000; padding: 3px'><span style='font-size:18px; font-weight: bold'>Ref #: </span></td>
								  <td colspan='1' style='border-top: solid 2px #000000; border-right: solid 2px #000000; padding: 3px; text-align: left'><span style='font-size:18px;'> $Trans_Reference</span> </td>
								  
								  </tr>
							<tr height='35px'>
								  <td style='border-left: solid 2px #000000;  padding: 3px'><span style='font-size:16px; font-weight: bold'>Received from: </span></td>
								  <td colspan='1' style=' padding: 3px'><span style='font-size:18px;'> $Ledger_Name</span> </td>
								  <td style='padding: 3px'><span style='font-size:18px; font-weight: bold'>Date: </span></td>
								  <td colspan='1' style='border-right: solid 2px #000000; padding: 3px; text-align: left'><span style='font-size:18px;'> $Trans_Date</span> </td>
								  </tr>
								  <tr height='35px'>
								  <td style='border-left: solid 2px #000000;  padding: 3px'><span style='font-size:16px; font-weight: bold'>Description: </span></td>
								  <td colspan='3' style='border-right: solid 2px #000000; padding: 3px'><span style='font-size:18px;'> $TransDt_Description</span> </td>
								  </tr>
								  <tr height='35px'>
								  <td style='border-left: solid 2px #000000;  padding: 3px'><span style='font-size:16px; font-weight: bold'>Amount </span></td>
								  <td colspan='3' style='border-right: solid 2px #000000; padding: 3px'><span style='font-size:18px;'>$Transdt_Amount $tcur</span></td>
								  
								  
								  </tr>
								   <tr height='35px'>
								  <td style='border-left: solid 2px #000000;  padding: 3px'><span style='font-size:16px; font-weight: bold'>The sum of </span></td>
								 
								  <td colspan='3' style='border-right: solid 2px #000000; padding: 3px'><span style='font-size:18px;'>";
								  $queryalpha  = " SELECT Alpha_Num ('ENGLISH', '".$tcur."', ".$Transdt_Amount.") As AlphaAmount FROM Dual ";
		$resultalpha = mysql_query($queryalpha,$connection) or die(mysql_error());
		$rowalpha=mysql_fetch_array($resultalpha);
		$TotalAmountLetter = $rowalpha[0];
		echo $TotalAmountLetter;
								  echo " </span></td>
								
								  
								  </tr>
								  
								  <tr height='35px'>
								  <td style='border-left: solid 2px #000000;  padding: 3px'><span style='font-size:16px; font-weight: bold'>Mode of Payment:  </span></td>
								  <td colspan='3' style='border-right: solid 2px #000000; padding: 3px'><span style='font-size:18px;'> $sub_rows23[1] - $sub_rows23[2]</span> </td>
								  </tr> 
								  <tr height='35px'>
								  <td style='border-right: solid 2px #000000; border-left: solid 2px #000000; padding: 3px' colspan='4'></td>
								  </tr>
								  <tr height='35px'>
								  <td style='text-align: center; font-size: 16px; font-weight: bold; border-left: solid 2px #000000;'>Direction<br>______________________</td>
								  <td style='text-align: center; font-size: 16px; font-weight: bold;' colspan='2'>Cashier<br>______________________</td>
								  <td style='text-align: center; border-right: solid 2px #000000; font-size: 16px; font-weight: bold;'>Beneficiary<br>______________________</td>
								  </tr>
								  <tr height='45px'>
								  <td style='border-bottom: solid 2px #000000; border-right: solid 2px #000000; border-left: solid 2px #000000; padding: 3px' colspan='4'></td>
								  </tr>
								  </table> </td> </tr>
								  ";
						}}
							
						else if ($TransType=='PV'){
						
							
							$sub_query23 = " Select TransDt.TransDt_id As TransDtId2, TransDt.Ledger_Number, Ledger.Ledger_Name, TransDt_Description, TransDt.Currency_Code as tcur, ".
								  " Round(Transdt_Amount, ".$DecimalBase.") As Transdt_Amount, Round(Transdt_Amount1, ".$DecimalBase1."), Round(Transdt_Amount2, ".$DecimalBase2."), ".
								  " Date_Format(TransDt_ValueDate,'%d/%m/%Y') As TransDt_ValueDate ".
								  " From TransDt Left Join Ledger on TransDt.Ledger_Number = Ledger.Ledger_Number ".
								  " Where TransDt.Trans_ID = '".$TransId."' ".
								  " And TransDt.TransDt_dbcd = '".$Type_dbcd2."' ".
								  " Order By TransDt.Ledger_Number ";
								 //echo $sub_query23;
						$sub_result23=mysql_query($sub_query23,$connection) or die(mysql_error());
						$sub_rows23=mysql_fetch_array($sub_result23);
						extract($sub_rows23);
							$sub_result2=mysql_query($sub_query2,$connection) or die(mysql_error());
						while($sub_rows2=mysql_fetch_array($sub_result2)){
							extract($sub_rows2);
							echo "<tr><td align='left'>";
							echo "<table border=0 width='100%' cellspacing=0 class='detail' style='table-layout:fixed;' >
								  <col width='150'>
								  <col width='270'>
								  <col width='210'>";
							echo "
							<tr height='35px'>
								  <td style='border-left: solid 2px #000000; border-top: solid 2px #000000; padding: 3px'><span style='font-size:14px; font-weight: bold'></span></td>
								  <td colspan='1' style='border-top: solid 2px #000000;  padding: 3px'><span style='font-size:14px;'></span> </td>
								  <td style=' border-top: solid 2px #000000; padding: 3px'><span style='font-size:18px; font-weight: bold'>Ref #: </span></td>
								  <td colspan='1' style='border-top: solid 2px #000000; border-right: solid 2px #000000; padding: 3px; text-align: left'><span style='font-size:18px;'> $Trans_Reference</span> </td>
								  
								  </tr>
							<tr height='35px'>
								  <td style='border-left: solid 2px #000000;  padding: 3px'><span style='font-size:16px; font-weight: bold'>Paid To: </span></td>
								  <td colspan='1' style=' padding: 3px'><span style='font-size:18px;'> $sub_rows23[2]</span> </td>
								  <td style='padding: 3px'><span style='font-size:18px; font-weight: bold'>Date: </span></td>
								  <td colspan='1' style='border-right: solid 2px #000000; padding: 3px; text-align: left'><span style='font-size:18px;'> $Trans_Date</span> </td>
								  </tr>
								  <tr height='35px'>
								  <td style='border-left: solid 2px #000000;  padding: 3px'><span style='font-size:16px; font-weight: bold'>Description: </span></td>
								  <td colspan='3' style='border-right: solid 2px #000000; padding: 3px'><span style='font-size:18px;'> $TransDt_Description</span> </td>
								  </tr>
								  <tr height='35px'>
								  <td style='border-left: solid 2px #000000;  padding: 3px'><span style='font-size:16px; font-weight: bold'>Amount </span></td>
								  <td colspan='3' style='border-right: solid 2px #000000; padding: 3px'><span style='font-size:18px;'>$Transdt_Amount $tcur</span></td>
								  
								  
								  </tr>
								   <tr height='35px'>
								  <td style='border-left: solid 2px #000000;  padding: 3px'><span style='font-size:16px; font-weight: bold'>The sum of </span></td>
								 
								  <td colspan='3' style='border-right: solid 2px #000000; padding: 3px'><span style='font-size:18px;'>";
								  $queryalpha  = " SELECT Alpha_Num ('ENGLISH', '".$tcur."', ".$Transdt_Amount.") As AlphaAmount FROM Dual ";
		$resultalpha = mysql_query($queryalpha,$connection) or die(mysql_error());
		$rowalpha=mysql_fetch_array($resultalpha);
		$TotalAmountLetter = $rowalpha[0];
		echo $TotalAmountLetter;
								  echo " </span></td>
								
								  
								  </tr>
								  
								  <tr height='35px'>
								  <td style='border-left: solid 2px #000000;  padding: 3px'><span style='font-size:16px; font-weight: bold'>Mode of Payment:  </span></td>
								  <td colspan='3' style='border-right: solid 2px #000000; padding: 3px'><span style='font-size:18px;'> $sub_rows23[1] - $sub_rows23[2]</span> </td>
								  </tr> 
								  <tr height='35px'>
								  <td style='border-right: solid 2px #000000; border-left: solid 2px #000000; padding: 3px' colspan='4'></td>
								  </tr>
								  <tr height='35px'>
								  <td style='text-align: center; font-size: 16px; font-weight: bold; border-left: solid 2px #000000;'>Direction<br>______________________</td>
								  <td style='text-align: center; font-size: 16px; font-weight: bold;' colspan='2'>Cashier<br>______________________</td>
								  <td style='text-align: center; border-right: solid 2px #000000; font-size: 16px; font-weight: bold;'>Beneficiary<br>______________________</td>
								  </tr>
								  <tr height='45px'>
								  <td style='border-bottom: solid 2px #000000; border-right: solid 2px #000000; border-left: solid 2px #000000; padding: 3px' colspan='4'></td>
								  </tr>
								  </table> </td> </tr>
								  ";
								 
								
						}}

else if ($TransType=='DV'){
						
							
							$sub_query23 = " Select TransDt.TransDt_id As TransDtId2, TransDt.Ledger_Number, Ledger.Ledger_Name, TransDt_Description, TransDt.Currency_Code as tcur, ".
								  " Round(Transdt_Amount, ".$DecimalBase.") As Transdt_Amount, Round(Transdt_Amount1, ".$DecimalBase1."), Round(Transdt_Amount2, ".$DecimalBase2."), ".
								  " Date_Format(TransDt_ValueDate,'%d/%m/%Y') As TransDt_ValueDate ".
								  " From TransDt Left Join Ledger on TransDt.Ledger_Number = Ledger.Ledger_Number ".
								  " Where TransDt.Trans_ID = '".$TransId."' ".
								  " And TransDt.TransDt_dbcd = '".$Type_dbcd2."' ".
								  " Order By TransDt.Ledger_Number ";
								 //echo $sub_query23;
						$sub_result23=mysql_query($sub_query23,$connection) or die(mysql_error());
						$sub_rows23=mysql_fetch_array($sub_result23);
						extract($sub_rows23);
							$sub_result2=mysql_query($sub_query2,$connection) or die(mysql_error());
						while($sub_rows2=mysql_fetch_array($sub_result2)){
							extract($sub_rows2);
							echo "<tr><td align='left'>";
							echo "<table border=0 width='100%' cellspacing=0 class='detail' style='table-layout:fixed;' >
								  <col width='150'>
								  <col width='270'>
								  <col width='210'>";
							echo "
							<tr height='35px'>
								  <td style='border-left: solid 2px #000000; border-top: solid 2px #000000; padding: 3px'><span style='font-size:14px; font-weight: bold'></span></td>
								  <td colspan='1' style='border-top: solid 2px #000000;  padding: 3px'><span style='font-size:14px;'></span> </td>
								  <td style=' border-top: solid 2px #000000; padding: 3px'><span style='font-size:18px; font-weight: bold'>Ref #: </span></td>
								  <td colspan='1' style='border-top: solid 2px #000000; border-right: solid 2px #000000; padding: 3px; text-align: left'><span style='font-size:18px;'> $Trans_Reference</span> </td>
								  
								  </tr>
							<tr height='35px'>
								  <td style='border-left: solid 2px #000000;  padding: 3px'><span style='font-size:16px; font-weight: bold'>Debit To: </span></td>
								  <td colspan='1' style=' padding: 3px'><span style='font-size:18px;'> $sub_rows23[2]</span> </td>
								  <td style='padding: 3px'><span style='font-size:18px; font-weight: bold'>Date: </span></td>
								  <td colspan='1' style='border-right: solid 2px #000000; padding: 3px; text-align: left'><span style='font-size:18px;'> $Trans_Date</span> </td>
								  </tr>
								  <tr height='35px'>
								  <td style='border-left: solid 2px #000000;  padding: 3px'><span style='font-size:16px; font-weight: bold'>Description: </span></td>
								  <td colspan='3' style='border-right: solid 2px #000000; padding: 3px'><span style='font-size:18px;'> $TransDt_Description</span> </td>
								  </tr>
								  <tr height='35px'>
								  <td style='border-left: solid 2px #000000;  padding: 3px'><span style='font-size:16px; font-weight: bold'>Amount </span></td>
								  <td colspan='3' style='border-right: solid 2px #000000; padding: 3px'><span style='font-size:18px;'>$Transdt_Amount $tcur</span></td>
								  
								  
								  </tr>
								   <tr height='35px'>
								  <td style='border-left: solid 2px #000000;  padding: 3px'><span style='font-size:16px; font-weight: bold'>The sum of </span></td>
								 
								  <td colspan='3' style='border-right: solid 2px #000000; padding: 3px'><span style='font-size:18px;'>";
								  $queryalpha  = " SELECT Alpha_Num ('ENGLISH', '".$tcur."', ".$Transdt_Amount.") As AlphaAmount FROM Dual ";
		$resultalpha = mysql_query($queryalpha,$connection) or die(mysql_error());
		$rowalpha=mysql_fetch_array($resultalpha);
		$TotalAmountLetter = $rowalpha[0];
		echo $TotalAmountLetter;
								  echo " </span></td>
								
								  
								  </tr>
								  
								  <tr height='35px'>
								  <td style='border-left: solid 2px #000000;  padding: 3px'><span style='font-size:16px; font-weight: bold'>Mode of Payment:  </span></td>
								  <td colspan='3' style='border-right: solid 2px #000000; padding: 3px'><span style='font-size:18px;'> $sub_rows23[1] - $sub_rows23[2]</span> </td>
								  </tr> 
								  <tr height='35px'>
								  <td style='border-right: solid 2px #000000; border-left: solid 2px #000000; padding: 3px' colspan='4'></td>
								  </tr>
								  <tr height='35px'>
								  <td style='text-align: center; font-size: 16px; font-weight: bold; border-left: solid 2px #000000;'>Direction<br>______________________</td>
								  <td style='text-align: center; font-size: 16px; font-weight: bold;' colspan='2'>Cashier<br>______________________</td>
								  <td style='text-align: center; border-right: solid 2px #000000; font-size: 16px; font-weight: bold;'>Beneficiary<br>______________________</td>
								  </tr>
								  <tr height='45px'>
								  <td style='border-bottom: solid 2px #000000; border-right: solid 2px #000000; border-left: solid 2px #000000; padding: 3px' colspan='4'></td>
								  </tr>
								  </table> </td> </tr>
								  ";
								 
								
						}}							
							else if ($TransType=='CV'){
						
							
							$sub_query23 = " Select TransDt.TransDt_id As TransDtId2, TransDt.Ledger_Number, Ledger.Ledger_Name, TransDt_Description, TransDt.Currency_Code as tcur, ".
								  " Round(Transdt_Amount, ".$DecimalBase.") As Transdt_Amount, Round(Transdt_Amount1, ".$DecimalBase1."), Round(Transdt_Amount2, ".$DecimalBase2."), ".
								  " Date_Format(TransDt_ValueDate,'%d/%m/%Y') As TransDt_ValueDate ".
								  " From TransDt Left Join Ledger on TransDt.Ledger_Number = Ledger.Ledger_Number ".
								  " Where TransDt.Trans_ID = '".$TransId."' ".
								  " And TransDt.TransDt_dbcd = '".$Type_dbcd2."' ".
								  " Order By TransDt.Ledger_Number ";
								 //echo $sub_query23;
						$sub_result23=mysql_query($sub_query23,$connection) or die(mysql_error());
						$sub_rows23=mysql_fetch_array($sub_result23);
						extract($sub_rows23);
							$sub_result2=mysql_query($sub_query2,$connection) or die(mysql_error());
						while($sub_rows2=mysql_fetch_array($sub_result2)){
							extract($sub_rows2);
							echo "<tr><td align='left'>";
							echo "<table border=0 width='100%' cellspacing=0 class='detail' style='table-layout:fixed;' >
								  <col width='150'>
								  <col width='270'>
								  <col width='210'>";
							echo "
							<tr height='35px'>
								  <td style='border-left: solid 2px #000000; border-top: solid 2px #000000; padding: 3px'><span style='font-size:14px; font-weight: bold'></span></td>
								  <td colspan='1' style='border-top: solid 2px #000000;  padding: 3px'><span style='font-size:14px;'></span> </td>
								  <td style=' border-top: solid 2px #000000; padding: 3px'><span style='font-size:18px; font-weight: bold'>Ref #: </span></td>
								  <td colspan='1' style='border-top: solid 2px #000000; border-right: solid 2px #000000; padding: 3px; text-align: left'><span style='font-size:18px;'> $Trans_Reference</span> </td>
								  
								  </tr>
							<tr height='35px'>
								  <td style='border-left: solid 2px #000000;  padding: 3px'><span style='font-size:16px; font-weight: bold'>Credit To: </span></td>
								  <td colspan='1' style=' padding: 3px'><span style='font-size:18px;'> $sub_rows23[2]</span> </td>
								  <td style='padding: 3px'><span style='font-size:18px; font-weight: bold'>Date: </span></td>
								  <td colspan='1' style='border-right: solid 2px #000000; padding: 3px; text-align: left'><span style='font-size:18px;'> $Trans_Date</span> </td>
								  </tr>
								  <tr height='35px'>
								  <td style='border-left: solid 2px #000000;  padding: 3px'><span style='font-size:16px; font-weight: bold'>Description: </span></td>
								  <td colspan='3' style='border-right: solid 2px #000000; padding: 3px'><span style='font-size:18px;'> $TransDt_Description</span> </td>
								  </tr>
								  <tr height='35px'>
								  <td style='border-left: solid 2px #000000;  padding: 3px'><span style='font-size:16px; font-weight: bold'>Amount </span></td>
								  <td colspan='3' style='border-right: solid 2px #000000; padding: 3px'><span style='font-size:18px;'>$Transdt_Amount $tcur</span></td>
								  
								  
								  </tr>
								   <tr height='35px'>
								  <td style='border-left: solid 2px #000000;  padding: 3px'><span style='font-size:16px; font-weight: bold'>The sum of </span></td>
								 
								  <td colspan='3' style='border-right: solid 2px #000000; padding: 3px'><span style='font-size:18px;'>";
								  $queryalpha  = " SELECT Alpha_Num ('ENGLISH', '".$tcur."', ".$Transdt_Amount.") As AlphaAmount FROM Dual ";
		$resultalpha = mysql_query($queryalpha,$connection) or die(mysql_error());
		$rowalpha=mysql_fetch_array($resultalpha);
		$TotalAmountLetter = $rowalpha[0];
		echo $TotalAmountLetter;
								  echo " </span></td>
								
								  
								  </tr>
								  
								  <tr height='35px'>
								  <td style='border-left: solid 2px #000000;  padding: 3px'><span style='font-size:16px; font-weight: bold'>Mode of Payment:  </span></td>
								  <td colspan='3' style='border-right: solid 2px #000000; padding: 3px'><span style='font-size:18px;'> $sub_rows23[1] - $sub_rows23[2]</span> </td>
								  </tr> 
								  <tr height='35px'>
								  <td style='border-right: solid 2px #000000; border-left: solid 2px #000000; padding: 3px' colspan='4'></td>
								  </tr>
								  <tr height='35px'>
								  <td style='text-align: center; font-size: 16px; font-weight: bold; border-left: solid 2px #000000;'>Direction<br>______________________</td>
								  <td style='text-align: center; font-size: 16px; font-weight: bold;' colspan='2'>Cashier<br>______________________</td>
								  <td style='text-align: center; border-right: solid 2px #000000; font-size: 16px; font-weight: bold;'>Beneficiary<br>______________________</td>
								  </tr>
								  <tr height='45px'>
								  <td style='border-bottom: solid 2px #000000; border-right: solid 2px #000000; border-left: solid 2px #000000; padding: 3px' colspan='4'></td>
								  </tr>
								  </table> </td> </tr>
								  ";
								 
								
						}}	
							else {
						echo "<tr><td align='left'>";
						echo "<table border=0 width='630' cellspacing=2 class='detail' style='table-layout:fixed;' >
							  <col width=90>
							  <col width=300>
							  <col width=60>
							  <col width=100>
							  <col width=80>
							  ";
						echo "<tr bgcolor=#D8D8D8>";
						echo "   <th align='left'>Ledger No.</th>";
						echo "   <th align='left'>Name/Description</th>";
						echo "	 <th align='center'>Cur.</th>";
						echo "	 <th align='center'>Amount</th>";
						echo "	 <th align='center'>Value Date</th>";
						echo "</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='left' valign='top'>$Ledger_Name</td>";
							echo "  <td align='center' valign='top'>$Currency_Code</td>";
							echo "	<td align='right' valign='top'>".number_format($Transdt_Amount, $DecimalBase)."</td>";
							echo "	<td align='center' valign='top'>$TransDt_ValueDate</td>";
							echo "</tr>";
							
							echo "<tr>";
							echo "  <td align='left' valign='top'>&nbsp;</td>";
							echo "  <td align='left' valign='top' colspan='4'>$TransDt_Description</td>";
							echo "</tr>";
							
						}	
					}
				}
					// Display Checks
					
					$sub_query4 = " Select ChkJourDt_Id, ChkJourDt.Chk_number, ChkJourDt.Chk_bank, Date_Format(ChkJourDt.Chk_ValueDate,'%d/%m/%Y') As Chk_ValueDate, ChkJourDt.Currency_Code As Chk_Currency, ChkJourDt.Ledger_Number, ".
								  " ChkJourDt.Chk_Type, Round(ChkJourDt.Chk_Amount, ".$DecimalBase.") As Chk_Amount, Round(ChkJourDt.Chk_Amount1, ".$DecimalBase1."), Round(ChkJourDt.Chk_Amount2, ".$DecimalBase2.") ".
								  " From ChkJourDt ".
								  " Where ChkJourDt.TransDt_id = '".$TransDtId1."' ".
								  " Order By ChkJourDt.Chk_number ";
					$sub_result4=mysql_query($sub_query4,$connection) or die(mysql_error());			  
					$ChkCount = mysql_num_rows($sub_result4);
		
					if($bank==''){			
						if ($ChkCount > 0) {
								if ($TransType=='RV') {
									
								}
						else if ($TransType=='PV') {
							
						}
						else if ($TransType=='CV') {
							
						}
						else if ($TransType=='DV') {
							
						}
								else {
							echo "<tr><td colspan='5'>";	
							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 BillJourDt_Id, BillJourDt.Bill_number, BillJourDt.Bill_bank, Date_Format(BillJourDt.Bill_ValueDate,'%d/%m/%Y') As Bill_ValueDate, BillJourDt.Currency_Code As Bill_Currency, BillJourDt.Ledger_Number, ".
								  " BillJourDt.Bill_Type, Round(BillJourDt.Bill_Amount, ".$DecimalBase.") As Bill_Amount, Round(BillJourDt.Bill_Amount1, ".$DecimalBase1."), Round(BillJourDt.Bill_Amount2, ".$DecimalBase2.") ".
								  " From BillJourDt ".
								  " Where BillJourDt.TransDt_id = '".$TransDtId1."' ".
								  " Order By BillJourDt.Bill_number ";
					
					$sub_result5=mysql_query($sub_query5,$connection) or die(mysql_error());			  
					$BillCount = mysql_num_rows($sub_result5);
		
					if($bank==''){
							if ($TransType=='RV') {
									
								}
						else if ($TransType=='PV') {
							
						}
						else if ($TransType=='cV') {
							
						}
						else if ($TransType=='DV') {
							
						}
								else {
						if ($BillCount > 0) {			  
							echo "<tr><td colspan='5'>";	
							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 CstJourDt_id, Project_code, Costcenter_Code, CstjourDt_Per, Round(CstJourDt_Amount, ".$DecimalBase.") As CstJourDt_Amount, ".
								  " Round(CstJourDt_Amount1, ".$DecimalBase1."), Round(CstJourDt_Amount2, ".$DecimalBase2.") ".
								  " From CstjourDt ".
								  " Where TransDt_id = '".$TransDtId1."' ".
								  " Order By Project_code ";			  
					
					$sub_result6=mysql_query($sub_query6,$connection) or die(mysql_error());			  
					$CstCount = mysql_num_rows($sub_result6);
		
					if($bank==''){			
						if ($CstCount > 0) {
							if ($TransType=='RV') {
									
								}
						else if ($TransType=='PV') {
							
						}
						else if ($TransType=='DV') {
							
						}
						else if ($TransType=='CV') {
							
						}
								else {							
							echo "<tr><td colspan='5'>";	
							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($CstjourDt_Per, $DecimalBase)."%</td>";
								echo "	<td align='center' valign='top'>&nbsp;</td>";
								echo "	<td align='right' valign='top'>".number_format($CstJourDt_Amount, $DecimalBase)."</td>";
								echo "  <td align='left' valign='top'>&nbsp;</td>";
								echo "</tr>";
							}	
							echo"</table></td></tr>";
						}
					}
					}					
					// Display Acclink/Invoices
					$sub_query10 = " Select Journal_Id As JournalId, Link_Ref As LinkRef, Link_Type As LinkType, Journal_Type As JournalType, ".
								   " Round(Sale_NetTotal, ".$DecimalBase.") As SaleNetTotal, Round(Sale_NetTotalBase1, ".$DecimalBase1.") As SaleNetTotalBase1, Round(Sale_NetTotalBase2, ".$DecimalBase2.") As SaleNetTotalBase2, ".
								   " Round(Sale_PaidAmnt, ".$DecimalBase.") As SalePaidAmnt, Round(Sale_PaidAmntbase1, ".$DecimalBase1.") As SalePaidAmntbase1, Round(Sale_PaidAmntbase2, ".$DecimalBase2.") As SalePaidAmntbase2, ".
								   " Round(Sale_RemainAmnt, ".$DecimalBase.") As SaleRemainAmnt, Round(Sale_RemainAmntBase1, ".$DecimalBase1.") As SaleRemainAmntBase1, Round(Sale_RemainAmntBase2, ".$DecimalBase2.") As SaleRemainAmntBase2 ".
								   " From ".$_SESSION['dbLabel'].".AccLink ".
								   " Where AccLink.Journal_Id = '".$TransDtId1."' ".
								   " And AccLink.Journal_Type = '".$Trans_Type."' ";
					
					$sub_result10=mysql_query($sub_query10,$connection) or die(mysql_error());			  
					$AcclinkCount = mysql_num_rows($sub_result10);
					
					if($bank==''){			
						if ($AcclinkCount > 0) {
							if ($TransType=='RV') {
									
								}
						else if ($TransType=='PV') {
							
						}
						else if ($TransType=='CV') {
							
						}
						else if ($TransType=='DV') {
							
						}
								else {							
							echo "<tr><td colspan='5'>";	
							echo "<table border=0 width='630' cellspacing=1 class='subdetail' style='table-layout:fixed;' >
								  <col width=90>
								  <col width=80>
								  <col width=100>
								  <col width=100>
								  <col width=100>
								  <col width=160>";
							echo "<tr>";
							echo "   <th align='left'>&nbsp;</th>";
							echo "   <th align='center'>Invoice Ref.</th>";
							echo "	 <th align='center'>Invoice Total</th>";
							echo "	 <th align='center'>Paid Amount</th>";
							echo "	 <th align='center'>Remain Amount</th>";
							echo "   <th align='left'>&nbsp;</th>";
							echo "</tr>";	
							
							$sub_result10=mysql_query($sub_query10,$connection) or die(mysql_error());
							while($sub_rows10=mysql_fetch_array($sub_result10)){
								extract($sub_rows10);
								
								echo "<tr>";
								echo "  <td align='left' valign='top'>&nbsp;</td>";
								echo "  <td align='left' valign='top'>$LinkRef</td>";
								echo "	<td align='right' valign='top'>".number_format($SaleNetTotal, $DecimalBase)."</td>";
								echo "	<td align='right' valign='top'>".number_format($SalePaidAmnt, $DecimalBase)."</td>";
								echo "	<td align='right' valign='top'>".number_format($SaleRemainAmnt, $DecimalBase)."</td>";
								echo "  <td align='left'>&nbsp;</td>";
								echo "</tr>";
								
							}	
							echo"</table></td></tr>";
						}
						}
						echo "</td></tr>";
					}
					
					$sub_query3 = " Select TransDt.TransDt_id As TransDtId2, TransDt.Ledger_Number, Ledger.Ledger_Name, TransDt_Description, TransDt.Currency_Code, ".
								  " Round(Transdt_Amount, ".$DecimalBase.") As Transdt_Amount, Round(Transdt_Amount1, ".$DecimalBase1."), Round(Transdt_Amount2, ".$DecimalBase2."), ".
								  " Date_Format(TransDt_ValueDate,'%d/%m/%Y') As TransDt_ValueDate ".
								  " From TransDt Left Join Ledger on TransDt.Ledger_Number = Ledger.Ledger_Number ".
								  " Where TransDt.Trans_ID = '".$TransId."' ".
								  " And TransDt.TransDt_dbcd = '".$Type_dbcd2."' ".
								  " Order By TransDt.Ledger_Number ";
					//echo $sub_query3;
					if($bank==''){
						if ($TransType=='RV') {
							
									//echo "<tr height='100px'> <td valign='bottom' align='right' style='font-size:20px; $Cambria; position:relative ;right:100px;'><i> Thank You! </i></td>";

									echo"<tr><td>
									<table border='0px' width='850px'>
									<col width=350>
									<col width=300>
									<col width=200>
									
									</table> </td> </tr>";
								}
						else if ($TransType=='PV') {
							
							 
						}
						else if ($TransType=='CV') {
							
							 
						}
						else if ($TransType=='DV') {
							
							 
						}
								else {
						echo "<tr><td align='left'>";
						echo "<table border=0 width='630' cellspacing=2 class='detail' style='table-layout:fixed;' >
							  <col width=90>
							  <col width=300>
							  <col width=60>
							  <col width=100>
							  <col width=80>
							  ";
						echo "<tr bgcolor=#D8D8D8>";
						echo "   <th align='left'>Ledger No.</th>";
						echo "   <th align='left'>Name/Description</th>";
						echo "	 <th align='center'>Cur.</th>";
						echo "	 <th align='center'>Amount</th>";
						echo "	 <th align='center'>Value Date</th>";
						echo "</tr>";			
							  
					}
					}	
					$querypv = "select ledger.ledger_name as debitname, transdt.Transdt_Amount as Transdt_Amountdb, concat (d2.Ledger_number,' - ', l2.ledger_name) as creditname
							from transdt
							left join ledger on ledger.Ledger_number = transdt.Ledger_number
							left join transdt d2 on d2.trans_id = transdt.trans_id and d2.TransDt_dbcd = 'C'
							left join ledger l2 on l2.Ledger_number = d2.Ledger_number
							where transdt.trans_id=$TransId and transdt.TransDt_dbcd = 'D'";					
						$sub_resultpv=mysql_query($querypv,$connection) or die(mysql_error());
						while($sub_rowspv=mysql_fetch_array($sub_resultpv)){
							extract($sub_rowspv);
		
					if($bank==''){
					if ($TransType=='RV') {
									
								}
						else if ($TransType=='PV') {
							
						}
						else if ($TransType=='CV') {
							
						}
						else if ($TransType=='DV') {
							
						}
								else {						
							echo "<tr>";
							echo "  <td align='left' valign='top'>$Ledger_Number</td>";
							echo "  <td align='left' valign='top'>$Ledger_Name</td>";
							echo "  <td align='center' valign='top'>$Currency_Code</td>";
							echo "	<td align='right' valign='top'>".number_format($Transdt_Amount, $DecimalBase)."</td>";
							echo "	<td align='center' valign='top'>$TransDt_ValueDate</td>";
							echo "</tr>";
							
							echo "<tr>";
							echo "  <td align='left' valign='top'>&nbsp;</td>";
							echo "  <td align='left' valign='top' colspan='4'>$TransDt_Description</td>";
							echo "</tr>";	
					}
					}					
						$sub_query7 = " Select ChkJourDt_Id, ChkJourDt.Chk_number, ChkJourDt.Chk_bank, Date_Format(ChkJourDt.Chk_ValueDate,'%d/%m/%Y') As Chk_ValueDate, 
						ChkJourDt.Currency_Code As Chk_Currency, ChkJourDt.Ledger_Number, ".
									  " ChkJourDt.Chk_Type, Round(ChkJourDt.Chk_Amount, ".$DecimalBase.") As Chk_Amount, 
									  Round(ChkJourDt.Chk_Amount1, ".$DecimalBase1.") As Chk_Amount1, Round(ChkJourDt.Chk_Amount2, ".$DecimalBase2.") As Chk_Amount2, a.TransDt_Description AS transdt_desc ,b.ledger_desc AS ledger_desc".
									  " From ChkJourDt ".
									  "left join transdt a on chkJourDt.transdt_id=a.transdt_id ".
									  " left join ledger b on a.ledger_number=b.ledger_number".
									  " Where ChkJourDt.TransDt_id = '".$TransDtId2."' AND a.TransDt_dbcd='C'".
									  " Order By ChkJourDt.Chk_number ";

							//	echo $sub_query7;
						$sub_result7=mysql_query($sub_query7,$connection) or die(mysql_error());			  
						$ChkCount = mysql_num_rows($sub_result7);
						$sub_result7=mysql_query($sub_query7,$connection) or die(mysql_error());
							while($sub_rows7=mysql_fetch_array($sub_result7)){
							extract($sub_rows7);}
					
					if($bank==''){			
						if ($ChkCount > 0) {
							if ($TransType=='RV') {
									
								}
						else if ($TransType=='PV') {
							
						}
						else if ($TransType=='CV') {
							
						}
						else if ($TransType=='DV') {
							
						}
								else {							
							echo "<tr><td colspan='5'>";	
							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 BillJourDt_Id, BillJourDt.Bill_number, BillJourDt.Bill_bank, Date_Format(BillJourDt.Bill_ValueDate,'%d/%m/%Y') As Bill_ValueDate, BillJourDt.Currency_Code As Bill_Currency, BillJourDt.Ledger_Number, ".
								  " BillJourDt.Bill_Type, Round(BillJourDt.Bill_Amount, ".$DecimalBase.") As Bill_Amount, Round(BillJourDt.Bill_Amount1, ".$DecimalBase1."), Round(BillJourDt.Bill_Amount2, ".$DecimalBase2.") ".
								  " From BillJourDt ".
								  " Where BillJourDt.TransDt_id = '".$TransDtId2."' ".
								  " Order By BillJourDt.Bill_number ";
					
					$sub_result8=mysql_query($sub_query8,$connection) or die(mysql_error());			  
					$BillCount = mysql_num_rows($sub_result8);
		
					if($bank==''){			
						if ($BillCount > 0) {
					if ($TransType=='RV') {
									
								}
						else if ($TransType=='PV') {
							
						}
						else if ($TransType=='CV') {
							
						}
						else if ($TransType=='DV') {
							
						}
								else {							
							echo "<tr><td colspan='5'>";	
							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 CstJourDt_id, Project_code, Costcenter_Code, CstjourDt_Per, Round(CstJourDt_Amount, ".$DecimalBase.") As CstJourDt_Amount, ".
								  " Round(CstJourDt_Amount1, ".$DecimalBase1."), Round(CstJourDt_Amount2, ".$DecimalBase2.") ".
								  " From CstjourDt ".
								  " Where TransDt_id = '".$TransDtId2."' ".
								  " Order By Project_code ";			  
					
					$sub_result9=mysql_query($sub_query9,$connection) or die(mysql_error());			  
					$CstCount = mysql_num_rows($sub_result9);
		
					if($bank==''){			
						if ($CstCount > 0) {
						if ($TransType=='RV') {
									
								}
						else if ($TransType=='PV') {
							
						}
						else if ($TransType=='CV') {
							
						}
						else if ($TransType=='DV') {
							
						}
								else {							
							echo "<tr><td colspan='5'>";	
							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);
								$CstCount = mysql_num_rows($sub_result9);
								
								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($CstjourDt_Per, $DecimalBase)."%</td>";
								echo "	<td align='center' valign='top'>&nbsp;</td>";
								echo "	<td align='right' valign='top'>".number_format($CstJourDt_Amount, $DecimalBase)."</td>";
								echo "  <td align='left' valign='top'>&nbsp;</td>";
								echo "</tr>";
								
							}	
						}
						}
						echo"</table></td></tr>";
					}	
						// Display Acclink/Invoices
						$sub_query11 = " Select Journal_Id As JournalId, Link_Ref As LinkRef, Link_Type As LinkType, Journal_Type As JournalType, ".
								   " Round(Sale_NetTotal, ".$DecimalBase.") As SaleNetTotal, Round(Sale_NetTotalBase1, ".$DecimalBase1.") As SaleNetTotalBase1, Round(Sale_NetTotalBase2, ".$DecimalBase2.") As SaleNetTotalBase2, ".
								   " Round(Sale_PaidAmnt, ".$DecimalBase.") As SalePaidAmnt, Round(Sale_PaidAmntbase1, ".$DecimalBase1.") As SalePaidAmntbase1, Round(Sale_PaidAmntbase2, ".$DecimalBase2.") As SalePaidAmntbase2, ".
								   " Round(Sale_RemainAmnt, ".$DecimalBase.") As SaleRemainAmnt, Round(Sale_RemainAmntBase1, ".$DecimalBase1.") As SaleRemainAmntBase1, Round(Sale_RemainAmntBase2, ".$DecimalBase2.") As SaleRemainAmntBase2 ".
								   " From ".$_SESSION['dbLabel'].".AccLink ".
								   " Where AccLink.Journal_Id = '".$TransDtId2."' ".
								   " And AccLink.Journal_Type = '".$Trans_Type."' ";
						$sub_result11=mysql_query($sub_query11,$connection) or die(mysql_error());			  
						$AcclinkCount = mysql_num_rows($sub_result11);
					if($bank==''){			
						if ($AcclinkCount > 0) {
							if ($TransType=='RV') {
									
								}
						else if ($TransType=='PV') {
							
						}
						else if ($TransType=='CV') {
							
						}
						else if ($TransType=='DV') {
							
						}
								else {							
							echo "<tr><td colspan='5'>";	
							echo "<table border=0 width='630' cellspacing=1 class='subdetail' style='table-layout:fixed;' >
								  <col width=90>
								  <col width=80>
								  <col width=100>
								  <col width=100>
								  <col width=100>
								  <col width=160>";
							echo "<tr>";
							echo "   <th align='left'>&nbsp;</th>";
							echo "   <th align='center'>Invoice Ref.</th>";
							echo "	 <th align='center'>Invoice Total</th>";
							echo "	 <th align='center'>Paid Amount</th>";
							echo "	 <th align='center'>Remain Amount</th>";
							echo "   <th align='left'>&nbsp;</th>";
							echo "</tr>";	
							
							$sub_result11=mysql_query($sub_query11,$connection) or die(mysql_error());
							while($sub_rows11=mysql_fetch_array($sub_result11)){
								extract($sub_rows11);
					
								echo "<tr>";
								echo "  <td align='left' valign='top'>&nbsp;</td>";
								echo "  <td align='left' valign='top'>$LinkRef</td>";
								echo "	<td align='right' valign='top'>".number_format($SaleNetTotal, $DecimalBase)."</td>";
								echo "	<td align='right' valign='top'>".number_format($SalePaidAmnt, $DecimalBase)."</td>";
								echo "	<td align='right' valign='top'>".number_format($SaleRemainAmnt, $DecimalBase)."</td>";
								echo "  <td align='left'>&nbsp;</td>";
								echo "</tr>";
							}	
						echo"</table></td></tr>";
						}
						}
						if ($TransType=='RV') {
									
								}
						else if ($TransType=='PV') {
							
						}
						else if ($TransType=='CV') {
							
						}
						else if ($TransType=='DV') {
							
						}
								else {
						echo "<tr height='10'><td colspan=7><hr></td></tr>";
								}
						echo "</table></td></tr>";
					}	

					if ($TransType == 'PV' || $TransType == 'RV')	{
						if (empty($Trans_AmountDb1)) $Trans_AmountDb1 = 0;
						$Trans_TotalAmount = ConvertCurrency($base1, $Trans_Curr, insertMySQLDate($Trans_Date), $Trans_AmountDb1, $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);
						
						if ($TransType == 'PV') {
							$Label1 = 'Paid to';
							$Label2 = 'Paid by';
							$Label3 = 'Checked by';
							$Label4 = 'Authorized by';
						} else {
							$Label1 = 'Received from';
							$Label2 = 'Received by';
							$Label3 = 'Checked by';
							$Label4 = 'Authorized by';
						}
					}
					if($bank==''){		
						echo "</table>";
						echo "<br>";
					}
	
				if($bank=='bankmed'){
					//HEADER
					$width="900";
echo " 				<table border='0' width='$width' cellspacing=0 cellpadding=0 class='master' style='table-layout:fixed; border-bottom:1px solid black;' >
					  <col width=300>
					  <col width=300>
					  <col width=300>
						<tr height='120'></tr>
						<tr><br><br>
							<td align='left' style='font-size:16px;'>&nbsp;&nbsp; &nbsp;&nbsp; ";echo $Trans_Date; echo "<b> تاريخ</b></td>
							<td align='center'style='font-size:20px;'>&nbsp;&nbsp; &nbsp;&nbsp; <b>سند صرف</b><br>&nbsp;&nbsp; &nbsp;&nbsp; $Trans_Reference <b>رقم</b></td>
							<td></td>
						</tr>
					</table>
					<br><br>
					<table border='0' width='$width' cellspacing=0 cellpadding=0 class='master' style='table-layout:fixed;' >
					  <col width=400>
					  <col width=300>
					  <col width=70>
						<tr height='20'></tr>
						<tr>
							<td align='left' style='font-size:18px;'></td>
							<td align='right'style='font-size:16px'><b>المحترمين&nbsp;&nbsp; $Trans_Representative &nbsp;السادة</b></td>
							<td align='right'><span style='font-size:15px;'><b>إدفعو لأمر<b></span> </td>
						</tr>
					</table>
					
					<table border='0' width='$width' cellspacing=0 cellpadding=0 class='master' style='table-layout:fixed;' >
					  <col width=400>
					  <col width=300>
					  <col width=70>
					  <col width=80>
						<tr height='20'></tr>
						<tr><br>
							<td align='right'></td>";
							if($Trans_Curr=='USD')
echo "						<td align='right'>&nbsp;&nbsp; ".Number2Text($Chk_Amount)."&nbsp; دولار أميركي فقط لا غير &nbsp;&nbsp;&nbsp;&nbsp;</td>";
							else{
echo "						<td align='right'>".Number2Text($Chk_Amount)."&nbsp;ليرة لبنانية فقط لا غير&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>	";
							}
echo"						<td align='center' height='30' style='border:1px solid black;'>".number_format($Chk_Amount, $DecimalBase)."</td>
							<td align='right'><span style='font-size:15px;'><b>مبلغ<b></span> </td>
						</tr>
					</table>
					<br>
					<table border='0' width='$width' cellspacing=0 cellpadding=0 class='master' style='table-layout:fixed;' >
					  <col width=400>
					  <col width=300>
					  <col width=70>
					  <col width=80>
						<tr height='20'></tr>
						<tr>
							<td align='right'></td>
							<td align='right'></td>
							<td align='right'>$Chk_number</td>
							<td align='right'><span style='font-size:15px;'><b>رقم الشيك<b></span> </td>
						</tr>
					</table>
					<br>
					<table border='0' width='$width' cellspacing=0 cellpadding=0 class='master' style='table-layout:fixed;' >
					  <col width=300>
					  <col width=100>
					  <col width=300>
					  <col width=80>
						<tr height='20'></tr>
						<tr>
							<td align='right'></td>
							<td align='right'  colspan=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$ledger_desc</td>
							<td align='right'><span style='font-size:15px;'><b>مسحوب على<b></span> </td>
						</tr>
					</table>
					
					<table border='0' width='$width' cellspacing=0 cellpadding=0 class='master' style='table-layout:fixed;' >
					  <col width=300>
					  <col width=100>
					  <col width=300>
					  <col width=80>
						<tr height='20'></tr>
						<tr height='20'><br>
							<td align='right'></td>
							<td align='right' colspan=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$transdt_desc</td>
							<td align='right'><span style='font-size:15px;'><b>وذلك<b></span> </td>
						</tr>
					</table>
					<br>
					<table border='1' width='$width' cellspacing=0 cellpadding=0 class='master' style='table-layout:fixed;' >
					  <col width=300>
					  <col width=300>
					  <col width=300>
						<tr height='130px'>
							<td align='right'><span style='font-size:15px;'><b>إستلمه<b></span><br><br><span style='font-size:15px;'><b>التوقيع</span> </td>
							<td align='right'><span style='font-size:15px;'><b>المفوض بالتوقيع&nbsp;<b></span><br><br><br></td>
							<td align='right'><span style='font-size:15px;'><b>راجعة&nbsp;<b></span><br><br><br></td>
						</tr>
					</table>
				
					<table border='0' width='$width' cellspacing=0 cellpadding=0 class='master' style='table-layout:fixed;' >
					  <col width=280>
					  <col width=400>
					  <col width=300>
						<tr height='100'>
							<td align='right'><span style='font-size:16px;'></span></td>
							<td align='right'><span style='font-size:16px;'></span></td>
							<td align='center'><span style='font-size:18px;'><div style='position: relative;bottom: 15px;'> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//".number_format($Chk_Amount, $DecimalBase)."//</div></td>
						</tr>
						<tr height='20'>	
							<td align='right'><span style='font-size:16px;'></span></td>
							<td align='right' style='font-size:18px' colspan=2><b> المحترمين&nbsp;&nbsp; $Trans_Representative &nbsp;السادة&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b></td>
						</tr>
						<tr height='20' >	
							<td align='right'><span style='font-size:16px;'></span></td>
							<td align='right'style='font-size:18px; padding-top:22px' valign='80px' colspan=2><b> &nbsp;&nbsp; ".Number2Text($Chk_Amount)."&nbsp; دولار أميركي فقط لا غير &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b></td>
						</tr>
						<tr height='140'> <br><br>	
							<td align='right'><span style='font-size:18px;'></span></td>
							<td align='center'>$Chk_ValueDate</td>
							<td align='center'></td>
						</tr>
					</table>
					
					
					<table border='0' width='$width' cellspacing=0 cellpadding=0 class='master' style='table-layout:fixed;' >
					  <col width=280>
					  <col width=400>
					  <col width=300>
						<tr height='90'><br>
							<td align='right'><span style='font-size:16px;'></span></td>
							<td align='right'><span style='font-size:16px;'></span></td>
							<td align='center'><span style='font-size:18px;'> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //".number_format($Chk_Amount, $DecimalBase)."//</td>
						</tr>
						<tr height='20'><td></td></tr>
						<tr height='20'><br><br>	
							<td align='right'><span style='font-size:16px;'></span></td>
							<td align='right' style='font-size:18px' colspan=2><b> المحترمين&nbsp;&nbsp; $Trans_Representative &nbsp;السادة&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b></td>
						</tr>
						<tr height='20'>	
							<td align='right'><span style='font-size:16px;'></span></td>
							<td align='right' style='font-size:18px; padding-top:22px' valign='80px' colspan=2><b> &nbsp;&nbsp; ".Number2Text($Chk_Amount)."&nbsp; دولار أميركي فقط لا غير  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b></td>
						</tr><tr height='60'><td></td></tr>
						<tr height='20'><br><br><br>	
							<td align='right'><span style='font-size:18px;'></span></td>
							<td align='center'>$Chk_ValueDate</td>
							<td align='center'></td>
						</tr>
					</table>";
			}
			
			// Richard
						$styletdd="style='font-size:25px; font-weight:bold'";
						if($bank=='bankaudi'){
					//HEADER
					$width="1450"; 
		echo"      	<div style='margin-left:950px'>
					<table width='250' border='0' cellspacing=0 cellpadding=0>
					<col width='250'>
					<tr height='30'>
					<td style='font-size:23px; font-weight:bold;padding-right:50px;padding-bottom:25px;' align='center' valing='center' >" .number_format($Trans_AmountDb1, 2)."   </td>
					</tr>
					</table>
					</div>
					<br> <br> <br>  
					<div style='margin-right:200px' >    ";
					$queryalpha  = " SELECT Alpha_Num ('ENGLISH', '".$Trans_Curr."', ".$Trans_AmountDb1.") As AlphaAmount FROM Dual ";
					$resultalpha = mysql_query($queryalpha,$connection) or die(mysql_error());
					$rowalpha=mysql_fetch_array($resultalpha);
					$TotalAmountLetter = $rowalpha[0];
					$output[0] = substr($TotalAmountLetter, 0, 45);
					$output[1] = substr($TotalAmountLetter, 45);

		echo " 		<table border='0' width='$width' cellspacing=0 cellpadding=0 class='master' style='table-layout:fixed;' >
					<col width='210'><col width='800'><col width='440'>
					<tr height='50'><td></td> <td align='left' colspan='2' style='font-size:23px; font-weight:bold;;padding-left:30px;'> $Trans_Representative </td></tr>
					
					<tr height='80'><td></td>
					<td align='left' style='font-size:23px; font-weight:bold;line-height:50px;' >U.S. DOLLARS ".$TotalAmountLetter."</td><td></td> 
					</tr>
									
					</table>
					</div> 
					<div style=' margin-right:520 ; ' >
					<table border='0' width='700' border='0' cellspacing=0 cellpadding=0>
					<col width='350'>
					<col width='250'>
					
					<tr height='20'>
					<td align='right' style='font-size:23px; font-weight:bold;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $Trans_Date </td>
					<td align='right' style='font-size:23px; font-weight:bold;'> Fanar &nbsp;</td>
					</tr>
					</table>
					</div>
					";
						}  
	}
}
	



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

function Number2Text($numberValue){

	$textResult = ''; // so i can use .=
	$numberValue = "$numberValue";
	
	if($numberValue[0] == '-'){
		$textResult .= 'ليرة ';
		$numberValue = substr($numberValue,1);
	}
	
	$numberValue = (int) $numberValue;	
	
	$def = array(	"0" => 'صفر',
					"1" => 'واحد',
					"2" => 'اثنان',
					"3" => 'ثلاث',
					"4" => 'اربع',
					"5" => 'خمس',
					"6" => 'ست',
					"7" => 'سبع',
					"8" => 'ثمان',
					"9" => 'تسع',
					"10" => 'عشر',
					"11" => 'أحد عشر',
					"12" => 'اثنا عشر',
					"100" => 'مائة',
					"200" => 'مئتان',
					"1000" => 'ألف',
					"2000" => 'ألفين',
					"1000000" => 'مليون',
					"2000000" => 'مليونان',
					"1000000000" => 'مليار',
					"2000000000" => 'ملياران'
					);

	// check for defind values	
	if(isset($def[$numberValue])) { 
		// checking for numbers from 2 to 10 :reson = 2 to 10 uses 'ة' at the end
		if($numberValue < 11 && $numberValue > 2){
			$textResult .= $def[$numberValue].'ة';
		}
		else{
			// the rest of the defined numbers
			$textResult .= $def[$numberValue];
			//echo " ".$numberValue." "; 
		}
	}
	else{ 
		$tensCheck = $numberValue%10;
		$numberValue = "$numberValue";
		
		for($x = strlen($numberValue); $x > 0; $x--){
			$places[$x] = $numberValue[strlen($numberValue)-$x];
		}

		switch(count($places)){
			case 2: // 2 numbers
			case 1: // or 1 number
			{
				$textResult .= ($places[1] != 0) ? $def[$places[1]].(($places[1] > 2 || $places[2] == 1) ? 'ة' : '').(($places[2] != 1) ? ' و' : ' ') : '';
				$textResult .= (($places[2] > 2) ? $def[$places[2]].'ون' : $def[10].(($places[2] != 2) ? '' : 'ون'));				
			}
			break;
			case 3: // 3 numbers
			{
				$lastTwo = (int) $places[2].$places[1];
				$textResult .= ($places[3] > 2) ? $def[$places[3]].' '.$def[100] : $def[(int) $places[3]."00"];
				if($lastTwo != 0){
					$textResult .= ' و'.Number2Text($lastTwo);
				}
			}
			break; 
			case 4: // 4 numbrs
			{
				$lastThree = (int) $places[3].$places[2].$places[1];
				$textResult .= ($places[4] > 2) ? $def[$places[4]].'ة الاف' : $def[(int) $places[4]."000"];
				if($lastThree != 0){
					$textResult .= ' و'.Number2Text($lastThree);
				}
			}
			break;
			case 5: // 5 numbers
			{	
				$lastThree = (int) $places[3].$places[2].$places[1];
				$textResult .= Number2Text((int) $places[5].$places[4]).((((int) $places[5].$places[4]) != 10) ? ' الفاً' : ' الاف');
				if($lastThree != 0){
					$textResult .= ' و'.Number2Text($lastThree);
				}
			}
			break;
			case 6: // 6 numbers
			{	
				$lastThree = (int) $places[3].$places[2].$places[1];
				$textResult .= Number2Text((int) $places[6].$places[5].$places[4]).((((int) $places[5].$places[4]) != 10) ? ' الفاً' : ' الاف');
				if($lastThree != 0){
					$textResult .= ' و'.Number2Text($lastThree);
				}
			}
			break;
			case 7: // 7 numbers 1 mill
			{	
				$textResult .= ($places[7] > 2) ? $def[$places[7]].' ملايين' : $def[(int) $places[7]."000000"];
				$textResult .= ' و';
				$textResult .= Number2Text((int) $places[6].$places[5].$places[4].$places[3].$places[2].$places[1]);
			}
			break;
			case 8: // 8 numbers 10 mill
			case 9: // 9 numbers 100 mill
			{	
				$places[9] = (isset($places[9])) ? $places[9] : '';
				$firstThree = (int) $places[9].$places[8].$places[7];
				$textResult .= 	Number2Text($firstThree);
				$textResult .=	($firstThree < 11) ? ' ملايين ' : ' مليون ';
				if(((int) $places[6].$places[5].$places[4].$places[3].$places[2].$places[1]) != 0){
					$textResult .= ' و';
					$textResult .=	Number2Text((int) $places[6].$places[5].$places[4].$places[3].$places[2].$places[1]);
				}
			}
			
			break;
			case 10: // 10 numbers 1 billion
			{	
				$textResult .= ($places[10] > 2) ? $def[$places[10]].' مليارات' : $def[(int) $places[10]."000000000"];
				$textResult .= ' و';
				$textResult .= Number2Text((int) $places[9].$places[8].$places[7].$places[6].$places[5].$places[4].$places[3].$places[2].$places[1]);
			}
			break;
			case 11: // 11 numbers 10 bill
			case 12: // 12 numbers 100 bill
			{	
				$places[12] = (isset($places[12])) ? $places[12] : '';
				$firstThree = (int) $places[12].$places[11].$places[10];
				$textResult .= 	Number2Text($firstThree);
				$textResult .=	($firstThree < 11) ? ' مليارات ' : ' مليار ';
				if(((int) $places[9].$places[8].$places[7].$places[6].$places[5].$places[4].$places[3].$places[2].$places[1]) != 0){
					$textResult .= ' و';
					$textResult .=	Number2Text((int) $places[9].$places[8].$places[7].$places[6].$places[5].$places[4].$places[3].$places[2].$places[1]);
				}
			}
			
			break;
			default:
			{
				$textResult = 'هذا رقم كبير .. ';
			}
		}

	}
	
	return $textResult;
}

print <<< HERE

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

