<?php
session_start();
if($HTTP_SESSION_VARS['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($HTTP_SESSION_VARS['dbName'],$connection) or die("Could not find DB");

$query_redeempoints  = "select date_format(redeem_date, '%d/%m/%Y %H:%i:%s') as RedeemDate, collected_points, redeemed_points, retail.Sale_Reference as RetailRef, redeempoints.retail_id as RetailId
                        from redeempoints inner join retail on retail.Sale_id = redeempoints.retail_id 
					    where redeempoints.customer_code = '$customer_code'";
$result_redeempoints = mysql_query($query_redeempoints, $connection);
?>
<html>
<head>
<title>List of Redeems</title>
<script>
function openInvoice(invoice_id){
	var str = "Form_RetailSlip.php?RetailId="+invoice_id+"&nopreview=1";
	window.open(str, 'Form_RetailSlip', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=350,height=500,top=100');	
}
</script>
</head>
<body>
<table width=500 style="border-collapse: collapse">
<tr>
<th style="width: 85px; font-family: Arial; font-size: 14px; border: solid 1px #000; padding: 5px;">Invoice #</th>
<th style="width: 160px; font-family: Arial; font-size: 14px; border: solid 1px #000; padding: 5px;">Date</th>
<th style="width: 127.5px; font-family: Arial; font-size: 14px; border: solid 1px #000; padding: 5px;">Collected Points</th>
<th style="width: 127.5px; font-family: Arial; font-size: 14px; border: solid 1px #000; padding: 5px;">Redeemed Points</th>
</tr>
<?php
while($row_redeempoints = mysql_fetch_array($result_redeempoints)){
	extract($row_redeempoints);
	?>
	<tr>
<td style="width: 85px; font-family: Arial; font-size: 13px; text-align: center; border: solid 1px #000; padding: 5px; cursor: pointer" onclick="openInvoice('<?php echo $RetailId; ?>')"><?php echo $RetailRef; ?></th>
<td style="width: 160px; font-family: Arial; font-size: 13px; text-align: center; border: solid 1px #000; padding: 5px;"><?php echo $RedeemDate; ?></th>
<td style="width: 127.5px; font-family: Arial; font-size: 13px; text-align: right; font-weight: bold; border: solid 1px #000; padding: 5px;"><?php echo $collected_points; ?></th>
<td style="width: 127.5px; font-family: Arial; font-size: 13px; text-align: right; font-weight: bold; border: solid 1px #000; padding: 5px;"><?php echo $redeemed_points; ?></th>
</tr>
	<?php
}
?>
</table>
</body>
</html>