<?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.subdetail th { font-size: 12px; 
                     font-weight: bold;
                     font-family:Times-New-Roman;
                   }				 
				 
table.subdetail td { font-size: 11px; 
                     font-family:Times-New-Roman;
                   }				 
				 
.styleh {
	font-size: 15px;
    font-family: sans-serif;
    font-weight: bold;
}
.styled {
	font-size: 15px;
    font-family: sans-serif;
}
.sig {
    font-family: monospace;
    font-size: 15px;
    color: #383d42;
}
.footer {
	font-size: 10px;
    font-family: sans-serif;
    font-weight: bold;
}
</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);
}

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

if($TransId != '' && $TransType == 'RV'){
				
	echo "<table border='0' width='700px'>";
	echo "<tr><td><span style='font-family: sans-serif;font-size: 30px;'>".strtoupper($Company_Name)."</span></td></tr>";
	echo "<tr height='150px'><td></td></tr>";
	echo "</table>";
	
	$query = "select date_format(trans.Trans_Date,'%Y.%m.%d'), Trans_Reference, ledger_name, Transdt_Amount, transdt.Currency_code, Trans_Remark 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 upper(TransDt_dbcd) = 'C' limit 1;";
	$res = mysql_query($query,$connection);
	$rw = mysql_fetch_row($res);
	$Trans_Date 		= $rw[0];
	$Trans_Reference 	= $rw[1];
	$ledger_name 		= $rw[2];
	$Transdt_Amount 	= $rw[3];
	$Currency_code 		= $rw[4];
	$Trans_Remark 		= $rw[5];
	
	echo "<table border='0' width='700px'><col width='250px'><col width='225px'><col width='225px'>";
	echo "<tr ><td><table border = '0'  width='250px' height='90px'><col width='125px'><col width='125px'>";
	echo "<tr height='20px'>
				<td style='border-left: dotted 1.5px darkgrey; border-top: dotted 1.5px darkgrey; padding-left: 10px;'><span class='styleh'>Date</span></td>
				<td style='border-right: dotted 1.5px darkgrey; border-top: dotted 1.5px darkgrey; ' align='center'><span class='styleh'>$Trans_Date</span></td>
		  </tr>";
	echo "<tr height='20px'>
				<td style='border-left: dotted 1.5px darkgrey; border-bottom: dotted 1.5px darkgrey; padding-left: 10px;' ><span class='styleh'>Receipt #</span></td>
				<td style='border-right: dotted 1.5px darkgrey; border-bottom: dotted 1.5px darkgrey; ' align='center'><span class='styleh'>$Trans_Reference</span></td>
		 </tr>";
	echo "</table></td><td colspan='2'></td></tr>";
	
	echo "<tr height='40px'><td colspan='3'></td></tr>";
	
	echo "<tr>
				<td colspan='2'><span class='styleh'>We received from</span> &nbsp;&nbsp; <span class='styled'>$ledger_name</span> </td>
				<td></td>
		 </tr>";		
	
	echo "<tr height='40px'><td colspan='3'></td></tr>";	
	
	$queryalpha  = " SELECT Alpha_NumLower ('ENGLISH', '".$Currency_code."', ".$Transdt_Amount.") As AlphaAmount FROM Dual ";
	$resultalpha = mysql_query($queryalpha,$connection) or die(mysql_error());
	$rowalpha=mysql_fetch_row($resultalpha);
	
	echo "<tr height='40px'>
				<td colspan='2'><span class='styled'>The Sum of $rowalpha[0]</span> </td>
				<td><table border=0 width='225px' height='40px'>
					<tr><td style='border-left: dotted 1.5px darkgrey; border-top: dotted 1.5px darkgrey;border-bottom: dotted 1.5px darkgrey;padding-left: 10px;'>$Currency_code </td>
						<td style='border-right: dotted 1.5px darkgrey; border-top: dotted 1.5px darkgrey;border-bottom: dotted 1.5px darkgrey;padding-right: 10px;' align='right'>".number_format($Transdt_Amount, $DecimalBase)."</td>
					</tr>
				</table></td>	
		 </tr>";	
	
	echo "<tr height='40px'><td colspan='3'></td></tr>";
	
	echo "<tr>
				<td colspan='3'><span class='styled'>$Trans_Remark</span> </td>
		 </tr>";	
	
	echo "<tr height='40px'><td colspan='3'></td></tr>";
	
	echo "<tr>
				<td colspan='2'></td>
				<td  style='border-bottom: dotted 1.5px darkgrey;'></td>
		 </tr>";	
		 
	echo "<tr height='30px'><td colspan='3'></td></tr>";	 
	echo "<tr height='30px'>
				<td colspan='2'></td>
				<td align='center'><span class='sig'>Signature</span></td>
		 </tr>";	
	
	
	echo "</table>";
	
	echo "<div style='bottom:0; position: fixed;'>";
	echo "<table border=0 width='700px'><col width='250px'><col width='200px'><col width='250px'>";
	echo "<tr>
			<td><span class='footer'>
				Imm. Georges Hobeika <br>
				Blvd Pierre Amine Gemayel<br>
				Sin el Fil, Beyrouth. P.O. Box: 55410<br>
				Tel. +961 1 48 99 69<br>
				Fax. +961 1 51 10 51
			</span></td>
			<td><span class='footer'>
				Georges Hobeika<br>
				15 rue Royale<br>
				75008 Paris<br>
				Tel. +33 1 40 07 57 54<br>
				Fax. +33 1 40 07 01 86
			</span></td>
			<td><span class='footer'>
				info@georgeshobeika.com<br>
				www.georgeshobeika.com
			</span></td>
		</tr>	";
	echo "</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); 
}

print <<< HERE

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

