<?php
	error_reporting(0);
	$servername = "localhost";
	$username = "adclubuser";
	$password = "W;yCg0H0k4z5";
	$dbname = "adclubmadras";

	// Create connection
	$conn = mysqli_connect($servername, $username, $password, $dbname);
	// Check connection
	if(!$conn){
	    die("Connection failed: " . mysqli_connect_error());
	}
	$sql = "select * from wp_payments ORDER BY id DESC";
	$result = $conn->query($sql);
	$filename = "PaymentReport.xls";

	$contents = "<table border='1' cellpadding=0 cellspacing=0>
		<tr>
			<th><strong>Membership ID</strong></th>
			<th><strong>Tracking ID</strong></th>
			<th><strong>Name</strong></th>
			<th><strong>Email</strong></th>
			<th><strong>Status</strong></th>
			<th><strong>Mode</strong></th>
			<th><strong>Amount (Rs.)</strong></th>
			<th><strong>Type</strong></th>
			<th><strong>Payment Date</strong></th>
		</tr>
	";
	$i = 0;
	while($report_rec = $result->fetch_assoc()){
		$i = $i + 1;
		$order_id = $report_rec["order_id"];
		$tracking_id = $report_rec["tracking_id"];
		$billing_name = $report_rec["billing_name"];
		$billing_email = $report_rec["billing_email"];
		$order_status = $report_rec["order_status"];
		$payment_mode = $report_rec["payment_mode"];
		$amount = $report_rec["amount"];
		$billing_tel = $report_rec["billing_tel"];
		$billing_address = $report_rec["billing_address"];
		$billing_zip = $report_rec["billing_zip"];
		$type = "";
		if($report_rec['merchant_param1'] == "members"){
			$type = "Registration";
		}else{
			$type = "Renewal";
		}
		$paymentDate = $report_rec['paymentDate'];
		
		$contents .= '<tr>
			<td>'.$order_id.'</td>
			<td>'.number_format($tracking_id).'</td>
			<td>'.$billing_name.'</td>
			<td>'.$billing_email.'</td>
			<td>'.$order_status.'</td>
			<td>'.$payment_mode.'</td>
			<td>'.$amount.'</td>
			<td>'.$type.'</td>
			<td>'.$paymentDate.'</td>
		</tr>';
	}
?>
<?php
	$contents .= "</table>";
	//echo $contents;die();
	$contents1 = "<html><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8'/></head><body>";
	header("Content-type: application/octet-stream");
	header('Content-type: application/ms-excel');
	header('Content-Disposition: attachment; filename='.$filename);
	header("Pragma: no-cache");
	header("Expires: 0");
	$contents1 .= $contents;
	$contents1 .= "</body></html>";
	echo $contents1;
	$conn->close();
?>