<?php
session_start();
header("Content-type: text/html; charset=".$_SESSION['encodingmode']);
if($_SESSION['dbName']==""){
header("location:../index.php");
}

include("config.inc.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");
$RMA_Id = $_GET['rma_id'];
$query_rma  = "select RMA_Id, RMA_Reference, date_format(RMA_Date, '%d/%m/%Y') as RMA_Date, Rma_RMAREF, date_format(RMA_PROMISEDDATE, '%d/%m/%Y') as RMA_PromissDate, rma.Client_Code, clients.ledger_name as ClientName, rma.Currency_code,
	           Rmacharge_amount, Rmacharge_amountbase1, Rmacharge_amountbase2, Rma_Remark, RMA_subject, Rma_EngineerName, rma_type
			   from rma left join clients on clients.ledger_number = rma.client_code
			   where rma_id = '$RMA_Id'";
//echo $query_rma;exit;
$result_rma = mysql_query($query_rma, $connection);
$row_rma    = mysql_fetch_array($result_rma);
extract($row_rma);

if($rma_type == "MR"){
	$title = "Return Repair Sheet";
}
else{
	$title = "Repair Sheet";
}
echo"
<html>
<head>";
echo"<title>$title</title>";
print <<<HERE
<style>
html,body{
	padding:0px; margin:0px;  width:100%; height:100%;
}
#container {
   min-height:100%; 
   position:relative;
}
</style>
</head>
<body>
<div id="container">
HERE;


$query_setup  = "select COMPANY_NAME, Company_memo, COMPANY_TELEPHONE from setup";
$result_setup = mysql_query($query_setup, $connection); 
$row_setup    = mysql_fetch_array($result_setup);
extract($row_setup);


echo"<table width=900 style='border-collapse: collapse'>
<tr>
<td width=65%>
<table>
<tr>
<td style='width: 135px'><img src='LogoFile.php' width=125 height=125  /></td>
<td style='vertical-align: top; '><span style='font-size: 20px; font-weight: bold'>$COMPANY_NAME</span><br>
<pre style='font-size: 16px; font-weight: bold; font-family: Times New Roman'>$Company_memo</pre></td>
</tr>
</table>
</td>
<td width=35% style='font-size: 16px; font-weight: bold; vertical-align: top'>Date & Time: ".date('d/m/Y H:i:s')."</td>
</tr>
<tr>
<th colspan=2 style='font-size: 22px; border-bottom: solid 2px #000000'><span style='vertical-align: top; '>
<table style='margin: auto;'>
<tr>
<td style='font-size: 22px; font-weight: bold'>$title $RMA_Reference</td>
<td>&nbsp;<img src='test_1D.php?text=$RMA_Reference' height='40px'  width='120px' border=0></td>
</tr>
</table>";
echo"</th>
</tr>
</table>
<table width=900 style='border-collapse: collapse'>
<tr style='height: 30px'>
<td style='width: 140px; font-size: 16px; font-weight: bold; border-left: solid 2px #000000;'>Client</td>
<td style='width: 510px; font-size: 16px; font-weight: bold' colspan=5>$Client_Code - $ClientName</td>
<td style='width: 120px; font-size: 16px; font-weight: bold'>Date</td>
<td style='width: 130px; font-size: 16px; font-weight: bold; border-right: solid 2px #000000;'>$RMA_Date</td>
</tr>
<tr style='height: 30px'>
<td style='width: 140px; font-size: 16px; font-weight: bold; border-left: solid 2px #000000;'>Tel</td>
<td style='width: 102px; font-size: 16px; font-weight: bold'>$RMA_ClientTelephone</td>
<td style='width: 102px; font-size: 16px; font-weight: bold'>";
if($RMA_ClientMobile != ""){
echo"Mobile";
}
echo"</td>
<td style='width: 102px; font-size: 16px; font-weight: bold'>$RMA_ClientMobile</td>
<td style='width: 50px; font-size: 16px; font-weight: bold'>";
if($Client_Email != ""){
echo"E-mail";
}
echo"</td>
<td style='width: 120px; font-size: 14px; font-weight: bold'>$Client_Email&nbsp;</td>
<td style='width: 100px; font-size: 16px; font-weight: bold'>Charge Amount</td>
<td style='width: 130px; font-size: 16px; font-weight: bold; border-right: solid 2px #000000;'>".number_format($Rmacharge_amount, 2)." $Currency_code</td>
</tr>
<tr style='height: 30px'>
<td style='width: 140px; font-size: 16px; font-weight: bold; border-bottom: solid 2px #000000; border-left: solid 2px #000000;'>Remark</td>
<td style='width: 510px; font-size: 16px; font-weight: bold; border-bottom: solid 2px #000000' colspan=5>$Rma_Remark</td>
<td style='width: 120px; font-size: 16px; font-weight: bold; border-bottom: solid 2px #000000'>Promissed Date</td>
<td style='width: 130px; font-size: 16px; font-weight: bold; border-bottom: solid 2px #000000; border-right: solid 2px #000000;'>$RMA_PromissDate</td>
</tr>
</table>";
echo "<table width=900 style='border-collapse: collapse'>
<tr>
<th width=150 style='text-align: left; padding: 3px; border-bottom: solid 2px #000000; border-left: solid 2px #000000; border-top:none;'>Item Code</th>
<th width=455 style='text-align: left; padding: 3px; border-bottom: solid 2px #000000; border-top:none;'>Description / Remark</th>
<th width=50 style='text-align: right; padding: 3px; border-bottom: solid 2px #000000; border-top:none;'>Qty</th>
<th width=120 style='text-align: left; padding: 3px; border-bottom: solid 2px #000000; border-top:none;'>&nbsp;Inv. Date</th>
<th width=75 style='text-align: left; padding: 3px; border-bottom: solid 2px #000000; border-top:none;'>Inv. No.</th>
<th width=50 style='text-align: left; padding: 3px; border-bottom: solid 2px #000000; border-top:none; border-right: solid 2px #000000;'>Warr.</th>
</tr>";
$query_rmadt = "select rmadt.item_code as ItemCode, items.Item_Description as ItemName, rmadt.RMADt_Remark as ItemRemark, RMADt_Quantity as Qty, date_format(Invoice_Date, '%d/%m/%Y') as InvoiceDate, Invoice_Number as InvoiceNumber, 
                if(Rmadt_Warranty = 1, 'Yes', 'No') as Warranty, rmadt_problem as Problem, Serial_Number as SerialNumber, rmadt_received as Received, rmadt_notes as Notes
				from rmadt left join items on items.item_code = rmadt.item_code
				where rma_id = '$RMA_Id'";
//echo $query_rmadt;
$result_rmadt = mysql_query($query_rmadt, $connection);
while($row_rmadt = mysql_fetch_array($result_rmadt)){
	extract($row_rmadt);
	echo"<tr>
<td width=150 style='text-align: left; padding: 3px; vertical-align: top; font-size: 16px'>$ItemCode</td>
<td width=455 style='text-align: left; padding: 3px; vertical-align: top; font-size: 16px'>$ItemName<br><b><u>Remark:</u></b> $ItemRemark</td>
<td width=50 style='text-align: right; padding: 3px; vertical-align: top; font-size: 16px'>$Qty</td>
<td width=120 style='text-align: left; padding: 3px; vertical-align: top; font-size: 16px'>&nbsp;$InvoiceDate</td>
<td width=75 style='text-align: left; padding: 3px; vertical-align: top;font-size: 16px'>$InvoiceNumber</td>
<td width=50 style='text-align: left; padding: 3px;vertical-align: top; font-size: 16px'>$Warranty</td>
</tr>";
echo "<tr>
<td colspan=6 style='border-bottom: solid 0.5px #a1a1a1; font-size: 16px'>
<div style='height: 25px'></div>
<table width=100%>
<tr>
<td width=110><b>Problem</b></td>
<td>$Problem</td>
</tr>
<tr>
<td width=110><b>Serial No</b></td>
<td>$SerialNumber</td>
</tr>
<tr>
<td width=110><b>Received with</b></td>
<td>$Received</td>
</tr>
<tr>
<td width=110><b>Notes</b></td>
<td>$Notes</td>
</tr>
</table>
</td>
</tr>";
}
echo"</table>";
echo "<div style='min-height: 320px;'></div>";
echo "<div style='position: absolute; bottom: 0px; width:900px; z-index: 0'>
<table style='width:100%; border-collapse: collapse'>
<tr>
<th style='text-align: left; border-top: solid 2px #000000; width: 120px '>Charge Amount</th>
<td style='border-top: solid 2px #000000; '>$Currency_code&nbsp;&nbsp;&nbsp;&nbsp;".number_format($Rmacharge_amount, 2)."</td>
<th style='text-align: left; border-top: solid 2px #000000; '>Signature</th>
</tr>
<tr style='height: 20px'>
<td></td>
</tr>
<tr>
<th style='text-align: left; width: 120px '></th>
<td style=' '></td>
<th style='text-align: left;  '>Date</th>
</tr>

</table>
<div style='height: 50px; border-bottom: solid 2px #000000;'></div>
<table width=900>
<tr>
<th colspan=3 style='text-align: left; font-size: 18px;'>NB: No Product will be exchanged, returned or replaced without the RMA receipt. The Client declares handing the hard disk clear from any data, and after keeping full security copies of its data/computer programs. The client waives any rights of whatsoever nature against T-Pro SAL, and acknowledges that the latter will not be liable for any claims, liabilities, damages, losses or expenses incurred by the Client, even if resulting from any negligence on the part of T-Pro SAL or its employees or agents, or even if resulting from the full damage or defect in the hard disk after one week as of the date its repair.</th>
</tr>
<tr>
<td style='height: 25px; border-bottom: solid 2px #000000'></td>
</tr>
</table>
</div>";
print <<<HERE

</div>
</body>
<script>
window.print();
</script>
</html>
HERE;
?>