<div class="right_col" role="main">
	<div class="">
		<div class="page-title">
			<div class="title_left">
				<table>
					<tr>
						<td width="150px"><h3>Rental List</h3></td>
						<td><a href="index.php?pagecontent=room_new"><button type="button" class="btn btn-dark">Add Room</button></a></td>
					</tr>
				</table>
			</div>
		</div>
		<div class="clearfix"></div>
		<div class="row">
			<div class="col-md-12 col-sm-12 col-xs-12">
				<div class="x_panel">
					<div class="x_content">
						<table id="datatable" class="table table-striped table-bordered">
							<thead>
								<tr>
									<th>No</th>
									<th>Unit No</th>
									<th>Property</th>
									<th>Onwer</th>
									<th>Rental</th>
									<th>STATUS</th>
									<th>Action</th>
								</tr>
							</thead>
							<tbody>
								<?php
									$result=mysqli_query($conn, "SELECT * FROM rooms WHERE r_status=1 AND r_profit_type=1 ORDER BY p_id ASC") or die (mysql_error());
									while($row = mysqli_fetch_array($result))
									{
										$rid = $row['r_id'];
								?>
								<tr>
									<td><?php echo ++$no; ?></td>
									<td><a href="?pagecontent=report_profit_room&room=<?php echo $row['r_id']; ?>"><?php echo $row['r_no'];?></a></td>
									<td><?php echo getDetailByTable('properties',$row['p_id'])['pty_short']; ?></td>
									<td><?php echo getDetailByTable('owners',$row['o_id'])[4]; ?></a></td>
									<td><?php if($row['r_rental']){ echo "RM ".$row['r_rental'];}else{echo "Profit Sharing (".$row['r_profit_sharing']*100 ."%)";};?></td>
									<td><?php $totalRentalBalance = rentalTotal($row['r_id'])['rentalTotal'] - utilityPaymentTotal($row['r_id'])['paymentTotal']; if($totalRentalBalance > 0){echo "<span style='color:red; font-weight: bold;'>RM  ".$totalRentalBalance."</span>";}else{echo "<span style='color:blue; font-weight: bold;'>PAID</span>";} ?></span></td>
						
									<td>
										<a href="?pagecontent=rental_view&room=<?php echo $row['r_id']; ?>"><button class="btn btn-xs btn-warning">View</button></a>
										
										<a href="?pagecontent=rental_update&room=<?php echo $row['r_id']; ?>"><button class="btn btn-xs btn-primary">Update</button></a>
									</td>
								</tr>
								<?php
									}
								?>
						</table>
					</div>
				</div>
			</div>
        </div>
    </div>
</div>

<?php

	if(isset($_REQUEST['remove'])){
		
		$roomId = $_REQUEST['remove'];
		
		mysqli_query($conn,"DELETE FROM rooms WHERE r_id=$roomId") or die (mysql_error());
		
		header('Location: index.php?pagecontent=rooms');  
	}
?>