<?php 
//session_start();
error_reporting(0); 
			
session_start();
require_once "config.php";
//set time zone
date_default_timezone_set("Asia/Kuala_Lumpur");
$payment_id = $_GET["payment_id"];
    $sqlPrintReceipt = "select payments.id, payments.amount_paid, payments.receipt_no, payments.created_at,bills.bill_type_id,bills.issue_date, 
					tenants.tenant_name,  properties.unit_no, tenants.rental_rate, users.name, locations.location_name , bill_types.bill_type_name, tenants.id as tenant_id, payments_paymenttype_bridge.ref_no, payment_type.payment_type_desc
					from payments
					inner join payments_paymenttype_bridge on payments.id = payments_paymenttype_bridge.payment_id
                    inner join payment_type on payments_paymenttype_bridge.payment_type_id = payment_type.id
					inner join bills on payments.bill_id = bills.id
					inner join bill_types on bills.bill_type_id = bill_types.id
					inner join tenants on bills.tenant_id = tenants.id
					inner join properties on tenants.property_id = properties.id
					inner join locations on properties.location_id = locations.id
					inner join users on payments.created_by = users.id
					where payments.id = $payment_id
					";
$runPrintReceipt = mysqli_query($link, $sqlPrintReceipt);
if($runPrintReceipt === FALSE){
	die(mysqli_error($link));
}

//COUNT ROW
$countResultPayment = mysqli_num_rows($runPrintReceipt);
if($countResultPayment == 0){
	$sqlPrintReceipt = "select payments.id, payments.amount_paid, payments.receipt_no, payments.created_at,bills.bill_type_id,bills.issue_date, 
					tenants.tenant_name,  properties.unit_no, tenants.rental_rate, users.name, locations.location_name , bill_types.bill_type_name, tenants.id as tenant_id
					from payments
					inner join bills on payments.bill_id = bills.id
					inner join bill_types on bills.bill_type_id = bill_types.id
					inner join tenants on bills.tenant_id = tenants.id
					inner join properties on tenants.property_id = properties.id
					inner join locations on properties.location_id = locations.id
					inner join users on payments.created_by = users.id
					where payments.id = $payment_id";
	$runPrintReceipt = mysqli_query($link, $sqlPrintReceipt);
	if($runPrintReceipt === FALSE){
		die(mysqli_error($link));
	}
}
$ref_no = "";
$payment_type_desc = "";
$resultPrintReceipt = mysqli_fetch_assoc($runPrintReceipt);
$payment_id = $resultPrintReceipt["id"];
$amount_paid = $resultPrintReceipt["amount_paid"];
$receipt_no = $resultPrintReceipt["receipt_no"];
$created_at = $resultPrintReceipt["created_at"];
$bill_type_id = $resultPrintReceipt["bill_type_id"];
$tenant_name = $resultPrintReceipt["tenant_name"];
$unit_no = $resultPrintReceipt["unit_no"];
$rental_rate = $resultPrintReceipt["rental_rate"];
$PICname = $resultPrintReceipt["name"];
$location_name = $resultPrintReceipt["location_name"];
$issue_date = $resultPrintReceipt["issue_date"];
$bill_type_name = $resultPrintReceipt["bill_type_name"];
$tenant_id = $resultPrintReceipt["tenant_id"];
if($countResultPayment == 1){
	$ref_no = $resultPrintReceipt["ref_no"];
	$payment_type_desc = $resultPrintReceipt["payment_type_desc"];
}




?>

<body height="90%" style="font-family:arial;" onLoad="window.print();">
<div style="page-break-after: always;">
<br/>
<br/>
<br/>

<?php 
if($bill_type_id == 1)
	include("print_receipt_rental.php");
else if($bill_type_id == 2)
	include("print_receipt_water.php");
else
	include("print_receipt_others.php");

/* if($bill_type_id == 1)
	include("receipt_rental.php");
else if($bill_type_id == 2)
	include("receipt_water.php");
else
	include("receipt_others.php"); */
?>

<table style="border-color:#FFFFFF;font-family:'Times New Roman', Times, serif" align="center" width="600">
	<tr>
		<td align="center"></td>
	</tr>
	<tr>
		<td align="right" >Salinan Kewangan</td>
	</tr>
	<tr>
		<td align="center" style="font-size:10px">
			-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --potong disini-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
		</td>
	</tr>
</table>
<br/>
<br/>
<br/>
<?php 
if($bill_type_id == 1)
	include("print_receipt_rental.php");
else if($bill_type_id == 2)
	include("print_receipt_water.php");
else
	include("print_receipt_others.php");

/* if($bill_type_id == 1)
	include("receipt_rental.php");
else if($bill_type_id == 2)
	include("receipt_water.php");
else
	include("receipt_others.php"); */
?>
<table style="border-color:#FFFFFF;font-family:'Times New Roman', Times, serif" align="center" width="600">
	<tr>
		<td align="center"></td>
	</tr>
	<tr>
		<td align="right">Salinan PHSSB</td>
	</tr>
	<tr>
		<td align="center" style="font-size:10px">
			-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --potong disini-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
		</td>
	</tr>
</table>
<br/>
<br/>
<br/>
<?php 
if($bill_type_id == 1)
	include("print_receipt_rental.php");
else if($bill_type_id == 2)
	include("print_receipt_water.php");
else
	include("print_receipt_others.php");

/* if($bill_type_id == 1)
	include("receipt_rental.php");
else if($bill_type_id == 2)
	include("receipt_water.php");
else
	include("receipt_others.php"); */
?>
<table style="border-color:#FFFFFF;font-family:'Times New Roman', Times, serif" align="center" width="600">
	<tr>
		<td align="center"></td>
	</tr>
	<tr>
		<td>Sila simpan untuk tujuan rekod<br />
		Cop pengesahan</td>
		<td align="right" valign="top">Salinan Penyewa / Pembayar</td>
	</tr>
</table>

</div>

</body>
<script>
	
	function CloseWin()
	{
		//alert("MASUK_hr");
		window.close();
	}
</script >
