<?php


session_start();
header("Content-type: text/html; charset=".$_SESSION['encodingmode']);
if($_SESSION['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.detail td.sr  { font-size: 10px; 
					  font-style: italic; 
                      font-family:Times-New-Roman;
                    }
				 
table.totals td.labels { font-size: 14px; 
                         font-weight: bold;
                         font-family:Times-New-Roman;
						 border-width: 0px;
						 border-style: none solid solid solid;
  						 border-color: #666666;
                       }					  
table.totals td.amounts { font-size: 14px; 
                          font-family:Times-New-Roman;
						  border-width: 0px;
						  border-style: none none solid none;
  						  border-color: #666666;
				        }
table.totals td.totalborder {
								font-size: 14px; 
								font-family:Times-New-Roman;
								border-width: 0px;
								border-style: none solid solid none;
								border-color: #666666;
							}						
				 
h4 { border-top-style: double; 
	 border-top-color: black; 
	 border-top-width: 1px;
   }
   
h3 { border-top-style: double; 
	 border-top-color: black; 
	 border-top-width: 2px;
	 width: 150px;
   }   
   
.bigfont{
	font-size: 150%; 
}

.inlinetable{
	display: inline-table;
}
   .midfont{
	  font-size: 100%;
   }
   
   .headerheight{
	height:200px;
}

html {
  height: 100%;
  box-sizing: border-box;
}

*,
*:before,
*:after {
  box-sizing: inherit;
}

body {
  position: relative;
  margin: 0;
  padding-bottom: 6rem;
  min-height: 100%;

}

.demo {
  margin: 0 auto;
  padding-top: 64px;
  width: 95%;
}




.footer {
position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
 padding: -10rem;
 
  text-align: center;
  
}
.footer table{
	font-size:11px;
}


.horizantalline{
	border-top:solid 1px black;
}

.dotted{
    //border-bottom: dotted 1px #000000;
	//border-collapse:collapse;
}

.containerdiv{
//	border:solid 1px yellow;
}
</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");

if(	$_SESSION['encodingmode'] == 'utf8' || $_SESSION['encodingmode'] == 'utf-8'){
	mysql_query("SET NAMES 'utf8'"); 
	mysql_query('SET CHARACTER SET utf8'); 
	mysql_set_charset('utf8', $connection);
}

//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,
				COMPANY_TELEPHONE, COMPANY_FAX as pobox, Setup_VatNo,
				Company_Name as CompanyName,Company_Memo as CompanyMemo, Company_NameF, Company_Memo, Company_MemoF, Company_Capital, Company_CapitalF,
			 company_telephone,company_city,company_fax,company_country,company_address,company_phone2,company_phone3
			 ,company_address2,company_city2,company_city_arabic,company_address_arabic,company_address2_arabic,
			 company_city_arabic,company_city2_arabic,company_country_arabic,company_name_arabic,company_memo_arabic,company_phone4,company_city3,company_city4,company_phone2_city3
			 ,company_phone1_city3,company_telephone_city3 ,company_phone2_city4
			 ,company_phone1_city4,company_telephone_city4,website,company_email
				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 as representtative, 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, Trans.Trans_Remark as tremark ".
				  " 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);
					}
					
					
	
					if($bank==''){		
						echo "<table border=0 width=100% cellspacing=0 cellpadding=0>
							  <tr><td align='left'>";
							  if ($TransType=='RV') {
								  $total="select TransDt.Currency_Code as cur, ".
								  " Round(Transdt_Amount, ".$DecimalBase.") As Transdt_Amount from TransDt 
								  where trans_id='".$TransId."'";
								  //echo $total;
								  $result=mysql_query($total,$connection) or die(mysql_error());
								  if($transtotal=mysql_fetch_array($result)){$totalamount=$transtotal[1];
								  $currency_code=$transtotal[0];}
								  echo "<div class='demo' >";
											//echo "<table border=0 ><tr><td>";
											echo "<table border=0 width=100% cellspacing=0 cellpadding=0>
											";
										echo "<tr><td align='left' ><table border='0' width='270px'> <col width=10><col width=10>";
										echo "<tr><td align='left'><table><tr><td align='center' class='bigfont'><b><pre>".str_replace( '\n', '<br>', $CompanyName)."<pre></b></td></tr>
											<tr><td align='center' class='midfont'><pre>".str_replace( '\n', '<br>', $CompanyMemo)."<pre></td></tr></table></td>";
								echo "</table></td>";
								echo "<td height='60' align='center'><img src='LogoFile.php' width='100' height='100' /></td>";
								
								echo "<td align='right'><table border='0'> <col width=10><col width=10>";
								echo "<tr><td align='right' ><table border='0'  width='270'><tr><td align='center' class='bigfont'><b><pre>".str_replace( '\n', '<br>', $company_name_arabic)."<pre></b></td></tr>
									<tr><td align='center' class='midfont'><pre>".str_replace( '\n', '<br>', $company_memo_arabic)."<pre></td></tr></table></td>";
								echo "</table></td>
									
								</tr><tr height=10px></tr></table>";
								echo "</div>";
								
								
							echo "<table width=100% border=0>
								 <col  width=270px><col width='100'><col width='270'>
								 <tr height='40' ><td align='center' colspan='2'><b><font size=5>  Reciept Voucher  <br> No $Trans_Reference</font></td></tr></table>";
							echo "<tr height='20'></tr>";

							echo "<tr><td> ";
							echo "<table  border='0' width='100%' cellpadding=10 cellspacing=0>";
							echo "<col width=120>
								<col width=80>
								<col width=90>
								<col width=150>
								<col width=150>
								<col width=150>
								<col width=100>
								<col width=200>
								 
								 ";
	$queryalpha  = " SELECT Alpha_Numeng ('ENGLISH', '".$currency_code."', ".$totalamount.") As AlphaAmount FROM Dual ";
	$resultalpha = mysql_query($queryalpha,$connection) or die(mysql_error());
	$rowalpha=mysql_fetch_array($resultalpha);
	//echo $queryalpha;
	$queryalpha  = " SELECT Alpha_Num ('ENGLISH', '".$currency_code."', ".$totalamount.") As AlphaAmount FROM Dual ";
	//echo $queryalpha;

								 echo "<tr><td colspan=2><b>Received From </b> </td><td>??</td></tr>";
								 echo "<tr><td colspan=2><b>The Sum Of  </b> </td><td colspan=2 style='$top; $bottom; $left; $right;'>$totalamount</td>";
								 
								 echo "<td  colspan=4 align='left' valign='top' style='font-size:14px; font-family:Times-New-Roman; '>".ucfirst($rowalpha[0])."</td>";
echo "</tr>";
								 echo "<tr height=30px></tr>";
					
								 $sub_query21="select transdt.ledger_number,transdt_dbcd,receipt_reference, Round(transdt_amount2, ".$DecimalBase.") As Transdt_Amount2 ,Round(transdt_amount1, ".$DecimalBase.") As transdt_amount1,
								 transdt_description
								  ,trans_amountdb1,ledger_name,sum(Round(transdt_amount1, ".$DecimalBase."))as totalsum
				  from transdt inner join trans on trans.trans_ID=transdt.trans_ID
				inner join ledger on ledger.ledger_number=transdt.ledger_number 
				Where                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
                              transdt.Trans_ID = '".$TransId."' and transdt_dbcd='D'
							  group by trans.trans_id";		
//echo $sub_query21;							  
				//echo $sub_query21;
				  $result_trandt=mysql_query($sub_query21,$connection) or die(mysql_error());
									echo "<tr>
											<td align='center' style='$top; $bottom; $left; $right;'>Account No</td>
	 
	
											<td align='center' style='$top; $bottom; $left; $right;'>Type</td>
											<td align='center' style='$top; $bottom; $left; $right;'>Reference</td>
											<td align='center' style='$top; $bottom; $left; $right;'>Bank Name</td>
											<td align='center' style='$top; $bottom; $left; $right;'>Amount</td>
											<td align='center' style='$top; $bottom; $left; $right;'>LBP Amount</td>
											<td align='center' style='$top; $bottom; $left; $right;'>Job</td>
											<td align='center' style='$top; $bottom; $left; $right;'>Narration</td>
						
										</tr>";
										
										while($transdetails=mysql_fetch_array($result_trandt)){
								

										echo "<tr height='30'>";
										echo"<td align='center' style='$top; $bottom; $left; $right;'>$transdetails[0]</td>
											<td align='center' style='$top; $bottom; $left; $right;'> check</td>
											
											<td align='center' style='$top; $bottom; $left; $right;'>??</td>
											<td align='center' style='$top; $bottom; $left; $right;'>$transdetails[7]</td>
											<td align='center' style='$top; $bottom; $left; $right;'>$transdetails[3]</td>
											<td align='center' style='$top; $bottom; $left; $right;'>$transdetails[4]</td>
											
											<td style='$top; $bottom; $left; $right;'>??</td>
											<td align='center' style='$top; $bottom; $left; $right;'>$transdetails[5]</td>
											
											";
										echo "</tr>";
										$totalamount=$transdetails[8];
										
										}
										
										
									
										
									

							
							echo "<tr><td colspan='4'></td>";
							
							echo "<td  style='$top; $bottom; $left;'>Total </td>
							<td style='$top; $bottom; $right;'>";
							echo "$totalamount </td></tr>";
							echo "</table>";
							echo "</table></td></tr>";
							
							
							echo "<tr><td><b>Being</b></td></tr>";
							echo "<tr><td>";
							echo "<table  border='0' width='100%' cellpadding=10 cellspacing=0>";
							echo "<col width=120>
								<col width=80>
								<col width=200>
								<col width=150>
								<col width=150>
								<col width=100>
								<col width=150>
							
								 
								 ";


								 echo "<tr height=30px></tr>";
					
								 $sub_query21="select transdt.ledger_number,transdt_dbcd,trans.trans_reference,Round(transdt_amount2, ".$DecimalBase.") As Transdt_Amount2 ,Round(transdt_amount1, ".$DecimalBase.") As transdt_amount1,transdt_description
								  ,trans_amountdb1,ledger_name,sum(Round(transdt_amount1, ".$DecimalBase."))as totalsum
				  from transdt inner join trans on trans.trans_ID=transdt.trans_ID 
				  inner join ledger on ledger.ledger_number=transdt.ledger_number Where                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
                              transdt.Trans_ID = '".$TransId."' and transdt_dbcd='C'
							  group by trans.trans_ID";				  
				//echo $sub_query21;
				  $result_trandt=mysql_query($sub_query21,$connection) or die(mysql_error());
									echo "<tr>
											<td align='center' style='$top; $bottom; $left; $right;'>Account No</td>
	 
	
											<td align='center' style='$top; $bottom; $left; $right;'>Ref</td>
											<td align='center' style='$top; $bottom; $left; $right;'>Name</td>
											
											<td align='center' style='$top; $bottom; $left; $right;'>Amount</td>
											<td align='center' style='$top; $bottom; $left; $right;'>LBP Amount</td>
											<td align='center' style='$top; $bottom; $left; $right;'>Job</td>
											<td align='center' style='$top; $bottom; $left; $right;'>Narration</td>
						
										</tr>";
										
										while($transdetails=mysql_fetch_array($result_trandt)){
								

										echo "<tr height='30'>";
										echo"<td align='center' style='$top; $bottom; $left; $right;'>$transdetails[0]</td>
											<td align='center' style='$top; $bottom; $left; $right;'>$transdetails[2]</td>
											
											
											
											<td align='center' style='$top; $bottom; $left; $right;'>$transdetails[7]</td>
											<td align='center' style='$top; $bottom; $left; $right;'>$transdetails[3]</td>
											<td align='center' style='$top; $bottom; $left; $right;'>$transdetails[4]</td>
											
											<td style='$top; $bottom; $left; $right;'>??</td>
											<td align='center' style='$top; $bottom; $left; $right;'>$transdetails[5]</td>
											
											";
										echo "</tr>";
										$totalamount=$transdetails[8];
										
										}
										
										
									
										
									

							
							echo "<tr><td colspan='3'></td>";
							
							echo "<td  style='$top; $bottom; $left;'>Total </td>
							<td style='$top; $bottom; $right;'>";
							echo "  $totalamount</td></tr>";
							echo "<tr height=30></tr><table> </td> </tr>";
							echo "</table>";
							echo "</table></td></tr>";
							
							
							  }
							else  if ($TransType == 'PV'){
								   echo "<table border='0' width='640' cellspacing=0 cellpadding=0 class='master' style='table-layout:fixed; padding-top:50px;' >
							  <col width=600>
							  <col width=340>
							  <col width=200>";
							echo"  <tr>
									<td align='left' colspan='2'><span style='font-size:20px;$Cambria'> Date: $Trans_Date</span></td>
									<td><img src='LogoFile.php' width='150px' height='100px' /> </td>
									</tr>
									</table></td></tr>";
							 
							  }
							 

							 else {
						echo "<table border='0' width='100%' 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:27px; font-weight:bold;$Cambria'> Receipt Voucher - $Trans_Reference </span></tr>
									</tr>
									 <tr height='30px'>
							
									
									 <td align='right' width=40% ><span style='font-weight:bold;font-size:20px;$Cambria'> Date: $Trans_Date</span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
									<td> </td>
									<td></td>
									
									 </tr>";*/
							}
							else if ($TransType=='PV') {
								 echo"<tr height='50px'> 
									<td align='center' colspan='3'><span style='font-size:27px; font-weight:bold;$Cambria'> Payment Voucher - $Trans_Reference </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 as curcode, ".
				  " 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,Costcent_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
                         left join costcent Cc on cc.costcent_code = t.costcent_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 as bankname, TransDt_Description, TransDt_Description2, 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, transdt.Currency_code as curcode ".
								  " 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 "; 
						$sub_result23=mysql_query($sub_query23,$connection) or die(mysql_error());
						$sub_rows23=mysql_fetch_row($sub_result23);
						
							$sub_result2=mysql_query($sub_query23,$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='630' cellspacing=0 class='detail' style='table-layout:fixed;' >
								  <col width='160'>
								  <col width='310'>
								  <col width='150'>";
							echo "<tr height='35px'>
								  <td><span style='font-size:18px;'>Received from: </span></td>
								  <td colspan='2'><span style='font-size:18px;'> $representtative</span> </td>
								  </tr>
								  <tr height='35px'>
								  <td><span style='font-size:18px;'>The sum of: </span></td>
								  <td colspan='2'><span style='font-size:18px;'> $Transdt_Amount &nbsp; $curcode </span> </td>
								  </tr>
								 
								  <tr height='35px'>
								  <td><span style='font-size:18px;'>Description:  </span></td>
									<td colspan='2'><span style='font-size:18px;'> $tremark</span> </td>
								  </tr>
								  <tr height='35px'>
								  <td><span style='font-size:18px;'>Mode of Payment: </span></td>
								  <td colspan='2'><span style='font-size:18px;'>$CashType_code  </span> </td>
								  </tr> ";
							if(strtoupper($CashType_code) == 'CHECK')	  
							echo "<tr height='35px'>
								  <td><span style='font-size:18px;'> Cheque No: $TransDt_Description </span></td>
								  <td align='center'><span style='font-size:18px;'> Bank: $TransDt_Description2  </span></td>
								  <td align='center'><span style='font-size:18px;'> Dated: $TransDt_ValueDate</span></td>
								  </tr>";
							else echo "<tr height='35px'>
								  <td></td> </tr>";	  
							echo" </table> </td> </tr>
								  ";
						}
						*/}//$sub_rows23[1] - $sub_rows23[2]
							
						else if ($TransType=='PV'){
						
							
							 echo "<tr height='40px'> <td> </td> </tr>";
							echo "<tr><td align='left'>";
							echo "<table border=0 width='1090px' cellspacing=0 class='detail' style='$top; $bottom; $right; $left;' >
								  <col width='250'>
								  <col width='840'>
								  ";
								  
								  $sub_result2=mysql_query($sub_query2,$connection) or die(mysql_error());
								  while($sub_rows2=mysql_fetch_array($sub_result2))
								  extract($sub_rows2); 
								  
							echo "<tr height='35px'>
								  <td><span style='font-size:20px; font-weight:bold;'>&nbsp;Project Name: </span></td>
								  <td colspan='2'><span style='font-size:18px;'> $Project_Name</span> </td>

								  </tr>
								  
								  <tr height='35px'>
								  <td><span style='font-size:20px; font-weight:bold;'>&nbsp;Program Name: </span></td>
								  </tr>
								  
								  <tr height='35px'>
								  <td><span style='font-size:20px; font-weight:bold;'>&nbsp;Donor: </span></td>
								  </tr>
								  
								  <tr height='35px'>
								  <td><span style='font-size:20px; font-weight:bold;'>&nbsp;Project Bank Sub-Account:  </span></td>
								  </tr>";
							
						
						echo"		  </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 {
							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 ($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 {							
							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 {							
							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 as curcode , ".
								  " 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') {
							
									$queryuser = "select trans.User_Account,if(users1.fullname='' or users1.fullname is null,users1.user_name, users1.fullname) as recvd_user,users1.description,
												Trans_UserConfirmed, if(users2.fullname='' or users2.fullname is null,users2.user_name, users2.fullname) as app_user, users2.description
												from trans
												left join accesslabelsapjm.users as users1 on users1.user_account = trans.user_account
												left join accesslabelsapjm.users as users2 on users2.user_account = trans.Trans_UserConfirmed
												where trans_id = $TransId;";
									$res = mysql_query($queryuser,$connection);
									$row = mysql_fetch_row($res);	
								//	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=200>
									<col width=300>
									<col width=200>
									
									<tr height='70px'> <td align='left' style='font-size:22px; font-weight:bold;$top;$left;$right;$bottom'> Checked By: </td> 
													   <td align='left' style='font-size:22px; font-weight:bold;$top;$left;$right;$bottom'> Authorized signature</td>
													   <td align='left' style='font-size:22px; font-weight:bold;$top;$left;$right;$bottom'> received by signature  </td></tr>";
								/*	echo "<tr height='50px'> <td align='left' style='font-size:18px ; $top;$left;$right;$bottom'> Name : $row[1]</td>
													   <td align='left' style='font-size:18px ; $top;$left;$right;$bottom'> Name :$row[4] </td> </tr>
									<tr height='50px'> <td align='left' style='font-size:18px ; $top;$left;$right;$bottom'> Title : $row[2]</td>
													   <td align='left' style='font-size:18px ; $top;$left;$right;$bottom'> Title : $row[5]</td> </tr>
									<tr height='50px'> <td align='left' style='font-size:18px ; $top;$left;$right;$bottom'>  Signature : </td>
													   <td align='left' style='font-size:18px ; $top;$left;$right;$bottom'>  Signature : </td> </tr>";*/
									echo "	<tr><td align='left' valign='top' colspan='2' ><font size='2'><b>Printed&nbsp;Date</b>&nbsp;&nbsp;".$printdate[2]."/".$printdate[1]."/".$printdate[0] .
								"<b> &nbsp; &nbsp; at </b>&nbsp;&nbsp;&nbsp;".$dt[1]." ".$dt[2];
						echo"	</td></tr>";
								}
						else if ($TransType=='PV') {
							
							 
						}
								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>";			
							  
					}
					}	
					$queryuser = "select PaymentRqst.user_account,ifnull(login1.Fullname,login1.user_name),login1.Description,Touser_account, ifnull(login2.Fullname,login2.user_name),login2.Description
								from trans
								left join PaymentRqst  on PaymentRqst.PaymentRqst_id = trans.PaymentRqst_id
								left join ".$_SESSION['dbLabel'].".users as login1 on login1.user_account = PaymentRqst.user_account
								left join ".$_SESSION['dbLabel'].".users as login2 on login2.user_account = Touser_account
								where trans_id=$TransId and upper(concat(login1.DefaultComp,'_',login1.DefaultYear)) = upper('".$_SESSION['dbName']."')
								and upper(concat(login2.DefaultComp,'_',login2.DefaultYear))  = upper('".$_SESSION['dbName']."')"; //echo $queryuser;
					$resuser=mysql_query($queryuser,$connection) or die(mysql_error());			
					$rwuser=mysql_fetch_array($resuser);
					$requestby = $rwuser[1];
					$requestbydesc = $rwuser[2];
					$apprby = $rwuser[4];
					$apprbydesc = $rwuser[5];
					
					$querypv = "select ledger.ledger_name as debitname, transdt.Transdt_Amount as Transdt_Amountdb, concat (d2.Ledger_number,' - ', l2.ledger_name) as creditname,transdt.currency_code as Currcode
							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') {
							echo "<tr height='40px'> <td> </td> </tr>";
							echo "<tr><td align='left'>";
							echo "<table border=0 width='1090' cellspacing=0 class='detail' style='table-layout:fixed;  $top; $bottom; $right; $left;' >
								  <col width='250'>
								  <col width='840'>
								  ";
							echo "<tr height='35px'>
								  <td><span style='font-size:20px; font-weight:bold;'>&nbsp;Amount: </span></td>
								  <td><span style='font-size:20px'> $Transdt_Amountdb &nbsp;$Currcode </span> </td>
								  </tr>
								  <tr height='35px'>
								  <td><span style='font-size:20px; font-weight:bold;'>&nbsp;To the order of: </span></td>
								  <td><span style='font-size:20px'> $representtative </span> </td>
								  </tr>
								  <tr height='35px'>
								  <td><span style='font-size:20px; font-weight:bold;'>&nbsp;Mode of Payment: </span> </td>
								  <td><span style='font-size:20px'>$creditname </span> </td>
								  </tr>
								  </table> </td> </tr>
								  ";
								  
							 echo "<tr height='40px'> <td> </td> </tr>";
							echo "<tr><td align='left'>";
							echo "<table border=0 width='1090' cellspacing=0 class='detail' style='table-layout:fixed;  $top; $bottom; $right; $left;' >
								  <col width='250'>
								  <col width='840'>
								  ";
							echo "<tr height='35px'>
								  <td><span style='font-size:20px; font-weight:bold;'>&nbsp;Budget Line 1: </span></td><td><span style='font-size:20px'> $Costcent_name </span> </td>

								  </tr>
								  <tr height='35px'>
								  <td><span style='font-size:20px; font-weight:bold;'>&nbsp;TBudget Line 2: </span></td></td><td><span style='font-size:20px'> $Project_Name </span> </td>

								  </tr>
								  <tr height='35px'>
								  <td><span style='font-size:20px; font-weight:bold;'>&nbsp;Description: </span></td>    <td><span style='font-size:20px'> $tremark </span> </td>

								  </tr>
								  </table> </td> </tr>
								  ";
							
					
							echo"<tr height='100px'> <td> </td> </tr>";
							echo"<tr><td>
									<table border='0px' width='850px'>
									<col width=350>
									<col width=300>
									<col width=200>
									
									<tr height='40px'> <td align='left' style='font-size:22px; font-weight:bold; text-decoration:underline'> Requested By: </td> 
													   <td align='left' style='font-size:22px; font-weight:bold;  text-decoration:underline'> Approved by: </td></tr>
									<tr height='30px'> <td align='left' style='font-size:18px ;'> Name : $requestby</td>
													   <td align='left' style='font-size:18px ;'>Name :  $apprby</td></tr>
									<tr height='30x'> <td align='left' style='font-size:18px ;'> Title : </td>
													   <td align='left' style='font-size:18px ;'> Title : ".($apprbydesc == ''?'Financial Officer':'')."</td> </tr>
									<tr height='30px'> <td align='left' style='font-size:18px ; '>  Signature :  </td>
														<td align='left' style='font-size:18px ; '> Signature: </td>
									 </tr>
									</table> </td> </tr>";
						}
								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 {							
							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 {							
							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 {							
							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 {							
							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 {
						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' || $bank=='bankmed2'){
					if($bank=='bankmed2'){
						$querycheck = "select date_format(transdt.Trans_Date,'%d-%m-%Y'), Trans_Reference,Trans_Representative,
									  trans.Currency_Code, Trans_Amountcd1,TransDt_Description2,TransDt_Description,
									  date_format(transdt.TransDt_ValueDate,'%d-%m-%Y')
									  from transdt
									  inner join trans on trans.trans_id = transdt.trans_id 
									  where transdt.trans_id = $TransId and TransDt_dbcd='C'; ";
						//echo $querycheck ;
						$rescheck = mysql_query($querycheck,$connection);
						$rowcheck = mysql_fetch_row($rescheck);
						$Trans_Date = $rowcheck[0];
						$Trans_Reference = $rowcheck[1];
						$Trans_Representative = $rowcheck[2];
						$Trans_Curr = $rowcheck[3];
						$Chk_Amount = $rowcheck[4];
						$Chk_number = $rowcheck[5];
						//$ledger_desc = $rowcheck[6];
						$transdt_desc = $rowcheck[6];
						$Chk_ValueDate = $rowcheck[7];
					}
					//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:1550px'>
					<table width='350' border='0' cellspacing=0 cellpadding=0>
					<col width='50'>
					<tr height='60'>
					<td $styletdd align='left'>&nbsp;" .number_format($Trans_AmountDb1, $DecimalBase)."   </td>
					</tr>
					</table>
					</div>
					<br> <br> <br>  <br> <br>
					<div style='margin-left:200px' >    ";
		echo " 		<table border='0' width='$width' cellspacing=0 cellpadding=0 class='master' style='table-layout:fixed;' >
					<tr height='80'> <td align='right' $styletdd> $Trans_Representative bbbbbbb </td></tr>
					
					<tr height='70'>
					<td align='right' $styletdd> ".Number2Text($Trans_AmountDb1)." &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </td> 
					</tr>
					<tr height='30'>  </tr>
					
					</table>
					</div> 
					<br><br>
					<div style=' margin-left:520 ; ' >
					<table border='0' width='700' border='0' cellspacing=0 cellpadding=0>
					<col width='250'>
					<col width='250'>
					<tr height='40'>
					<td $styletdd align='right' style=' padding-bottom:10px'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $Trans_Date </td>
					<td $styletdd align='right' style=' padding-bottom:10px'> Beiruut &nbsp;</td>
					</tr>
					</table>
					</div>
					";
						}  
	}
}

if ($TransType=='RV') {
	/*echo "</div>";
	echo "<div class='footer'><table><tr><td>fg</td></tr></table>";
//echo "<div class='horizantalline'></div>";
echo "<table border='0' class='inlinetable'><col width=150px><col width=150px><col width=150px><col width=150px><col width=150px><tr><td align='center'>";

echo "<table border='0'><tr><td><i>$website</i></td></tr><tr><td><i>$company_email</i></td></tr></table> </td>";

echo "<td><table border=0><col width='70'><col width=100><tr><th colspan='2'><i>
$company_city</i></th></tr><tr><td align='right'>phone:</td><td><i>$company_telephone</i></td></tr><tr><td></td><td><i>$company_phone2</i></td></tr><tr><td align='right'>fax:</td><td><i>$company_phone4</i></td></tr></table></td>
<td><table><tr><th colspan='2'><i> $company_city3  </i></th></tr><tr><td align='right'>phone:</td><td><i>$company_telephone_city3</i></td></tr><tr><td></td><td><i>$company_phone1_city3</i></td></tr><tr><td align='right'>fax:</td><td><i>$company_phone2_city3</i></td></tr></table></td>
<td><table border='0'><tr><th colspan='2'><i> $company_city4 </i></th></tr><tr><td align='right'>phone:</td><td><i>$company_telephone_city4</i></td></tr><tr><td></td><td><i>$company_phone1_city4</i></td></tr><tr><td align='right'>fax:</td><td><i>$company_phone2_city4</i></td></tr></table></td>
<td valign='top'><table border='0'><tr><th colspan='2'><i> $company_city2 </i> </th></tr><tr><td>phone:</td><td><i>$company_phone3</i></td></tr></table></td></tr>";
echo "<tr><td></td></tr>";
echo "</table><tfoot></table>";
echo "</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;
?>

