<?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, RMA_ClientTelephone, rma_remark2, RMA_Email, rma.Client_Email, rma.Client_Tel
			   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; height=125px'><!--<img src='img/tpro_logo.png' 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'></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 width=150></td>
<td style='font-size: 22px; font-weight: bold'>$title - $RMA_Reference</td>
<td width=150></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: 60px; font-size: 16px;  border-left: solid 2px #000000;'>Client</td>
<td style='width: 600px; font-size: 16px; ' colspan=5>$Client_Code&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$ClientName</td>
<td style='width: 50px; font-size: 16px; '>Date</td>
<td style='width: 130px; font-size: 16px;  border-right: solid 2px #000000;'>$RMA_Date</td>
</tr>
<tr style='height: 30px'>
<td style='width: 60px; font-size: 16px;  border-left: solid 2px #000000;'>Tel</td>
<td style='width: 372px; font-size: 16px; '>$Client_Tel</td>
<td style='width: 102px; font-size: 16px; '>";
if($RMA_ClientMobile != ""){
echo"Mobile";
}
echo"</td>
<td style='width: 102px; font-size: 16px; '>$RMA_ClientMobile</td>
<td style='width: 50px; font-size: 16px; '></td>
<td style='width: 160px; font-size: 14px; '>";
if($RMA_Email != ""){
echo"</td>
<td style='width: 100px; font-size: 16px; '>E-mail";
} else{
	echo"<td style='width: 100px; font-size: 16px; '>";
}
echo"</td>
<td style='width: 160px; font-size: 16px;  border-right: solid 2px #000000;'>$Client_Email</td>
</tr>
<tr style='height: 30px'>
<td style='width: 60px; font-size: 16px;  border-bottom: solid 2px #000000; border-left: solid 2px #000000;'>Remark</td>
<td style='width: 600px; font-size: 16px;  border-bottom: solid 2px #000000' colspan=5>$rma_remark2</td>
<td style='width: 50px; font-size: 16px;  border-bottom: solid 2px #000000'></td>
<td style='width: 130px; font-size: 16px;  border-bottom: solid 2px #000000; border-right: solid 2px #000000;'></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, RMADt_Remark2 as PickedUpBy
				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></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 height=90 style='vertical-align: top'><b>Problem</b></td>
<td style='vertical-align: top;'>$Problem</td>
</tr>
<tr>
<td width=110 height=30><b>Serial No</b></td>
<td>$SerialNumber</td>
</tr>
<tr>
<td width=110 height=30><b>Received with</b></td>
<td>$Received</td>
</tr>
<tr>
<td width=110 height=30><b>Notes</b></td>
<td>$Notes</td>
</tr>
</table>
</td>
</tr>";
}
echo"</table>";
echo "<div style='min-height: 500px;'></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.";
//echo"<br><br>Goods received in good condition and tested!";
echo"</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;
?>