<?php 
//session_start();
//error_reporting(0); 
//set time zone
include("session_set.php");
//error_reporting(0); 

$bill_id = $_GET["bill_id"];

 $sqlPayments = "select payments.id as payment_id, payments.receipt_no, payments.amount_paid , payments.created_at, users.name, bills.issue_date, tenants.tenant_name, tenant_rental_rate.rental_rate, properties.unit_no, locations.location_name,
				payments_paymenttype_bridge.ref_no, payment_type.id as payment_type_id, payment_type.payment_type_desc, bills.bill_type_id, tenants.id as tenant_id  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 tenant_rental_rate on tenants.id = tenant_rental_rate.tenant_id
				inner join properties on tenants.property_id = properties.id
				inner join locations on properties.location_id = locations.id
				inner join projects on locations.project_id = projects.id
				inner join users on payments.created_by =  users.id
				where payments.bill_id = $bill_id 
				";
$runPayment = mysqli_query($link, $sqlPayments);
if($runPayment === FALSE){
	die(mysqli_error($link));
}

date_default_timezone_set("Asia/Kuala_Lumpur");
$page = "printPaymenFromBills.php";

while($resultPayment = mysqli_fetch_array($runPayment)){
	$payment_id = $resultPayment["payment_id"];
	$receiptNoPayment_rental = $resultPayment["receipt_no"];
	$list_amount_paid = $resultPayment["amount_paid"];
	$created_at = $resultPayment["created_at"];
	$pic_name = $resultPayment["name"];
	$list_monthYear_issuedate = $resultPayment["issue_date"];
	$tenant_name = $resultPayment["tenant_name"];
	$rental_rate = $resultPayment["rental_rate"];
	$unit_no = $resultPayment["unit_no"];
	$location_name = $resultPayment["location_name"];
	$refNo_rental = $resultPayment["ref_no"];
	$payment_type_desc = $resultPayment["payment_type_desc"];
	$rental_payment_type = $resultPayment["payment_type_id"];
	$bill_type_id = $resultPayment["bill_type_id"];
	$tenant_id = $resultPayment["tenant_id"];
?>

<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("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("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("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>
<?php } ?>
</body>
<script>
	
	//window.close();
    window.onunload = refreshParent;
    function refreshParent() {
        window.opener.location.reload();
    }
</script >
