<?php
	$roomId = $_GET['room'];
	$date = date("Y-m-d");

	$result = mysqli_query($conn, "SELECT * FROM rooms WHERE r_id=$roomId");
	$row = mysqli_fetch_assoc($result);

	$roomNo = $row['r_no'];
?>
<!-- page content -->
<div class="right_col" role="main">
  <div class="">
	<div class="page-title">
	  <div class="title_left">
		<h3>ROOM LIST & PROFITS</h3>
	  </div>

	  <div class="title_right">
		<div class="col-md-5 col-sm-5 col-xs-12 form-group pull-right top_search">
		  <div class="input-group">
			<input type="text" class="form-control" placeholder="Search for...">
			<span class="input-group-btn">
			  <button class="btn btn-default" type="button">Go!</button>
			</span>
		  </div>
		</div>
	  </div>
	</div>

	<div class="clearfix"></div>

	<div class="row">

	  <div class="clearfix"></div>

	  <div class="col-md-6 col-sm-6 col-xs-12">
		<div class="x_panel">
		  <div class="x_title">
			<h2>Overall Profit Report <small>Bordered table subtitle</small></h2>
			<ul class="nav navbar-right panel_toolbox">
			  <li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
			  </li>
			  <li class="dropdown">
				<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><i class="fa fa-wrench"></i></a>
				<ul class="dropdown-menu" role="menu">
				  <li><a href="#">Settings 1</a>
				  </li>
				  <li><a href="#">Settings 2</a>
				  </li>
				</ul>
			  </li>
			  <li><a class="close-link"><i class="fa fa-close"></i></a>
			  </li>
			</ul>
			<div class="clearfix"></div>
		  </div>
		  <div class="x_content">

			<table class="table table-bordered">
			  <thead>
				<tr>
				  <th>#</th>
				  <th>Room</th>
				  <th>Property</th>
				  <th>Earned</th>
				  <th>Profit</th>
				</tr>
			  </thead>
			  <tbody>
				  <?php
					$result = mysqli_query($conn, "SELECT * FROM rooms ORDER BY r_status DESC, r_no ASC");
					while($row = mysqli_fetch_assoc($result)){
                        if(filterRoomAdmin($row['r_id'],$_SESSION['admin'][0])==true){continue;};
				  ?>
				<tr>
				  <th scope="row"><?php echo ++$no; ?></th>
				  <td><a href="?pagecontent=report_profit_room&room=<?php echo $row['r_id']; ?>"><?php echo $row['r_no']; ?></a></td>
				  <td><?php echo getDetailFromTable('properties',$row['p_id'])['pty_title']; ?></td>
				  <td><?php $totalEarned = totalEarned($row['r_id'], $date); echo $totalEarned; ?></td>
				  <td><?php $profit = $totalEarned - $expenses; echo $profit; $total=$total+$profit;?></td>
				</tr>
				  <?php } ?>
				  
				<tr>
				  <td colspan="4">Total</td>
				  <td><?php echo $total; ?></td>
				</tr>
				  
			  </tbody>
			</table>

		  </div>
		</div>
	  </div>

	</div>
  </div>
</div>
<!-- /page content -->
