<?php 



	if(!$_SESSION['admin']){exit;}



	date_default_timezone_set('Asia/Kuala_Lumpur');

	

	if(isset($_GET['rvno'])){

		$getDate = getDetailByMysqliWhere('reservation','rv_no',$_GET['rvno'])['rv_ci_date'];

	}else{

		if(isset($_GET['date'])){

			$getDate = $_GET['date'];

		}else{

			header("Location: ?pagecontent=reservations&date=".date("Y-m-d"));

		}

	}



	if(!isset($_GET['rvno']) && !isset($_GET['date'])){exit;}

?>



<div class="right_col" role="main">

	<div class="">

		<div class="page-title">

			<div class="title_left">

				<h3>Reservation List - <?php echo $getDate;?></h3>

					<a href="?pagecontent=reservation_new"><button type="button" class="btn btn-dark">Add Reservation</button></a>



					<a href="?pagecontent=reservations&date=<?php echo addDaysToDate($getDate,1,"-"); ?>"><button type="button" class="btn btn-dark">Yesterday</button></a>

					<a href="?pagecontent=reservations"><button type="button" class="btn btn-dark">Today</button></a>

					<a href="?pagecontent=reservations&date=<?php echo addDaysToDate($getDate,1,"+"); ?>"><button type="button" class="btn btn-dark">Next Day</button></a>

					<a href="?pagecontent=reservation_checklist&date=<?php echo $getDate; ?>"><button type="button" class="btn btn-dark">Checklist</button></a>



					<form method="get">

						<input type="text" name="pagecontent" value="reservations" hidden="">

						<input class="form-control col-md-2" name="date" type="date" value="<?php echo $getDate; ?>">

						<input type="submit" class="btn btn-primary" value="Search">

					</form>

			</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="datatable1" class="table table-striped table-bordered">

							<thead>

								<tr>

								    <th>Reservation</th>

								    <th>Platform</th>

									<th>Guest</th>

									<th>Room</th>

									<th>Check In/Out</th>

									<th>Night</th>

									<th>CO Time</th>

									<th>Total</th>

									<th>Deposit</th>

									<th>Clear</th>

									<th>Status</th>

									<th>Action</th>

								</tr>

							</thead>

							<tbody>

								<?php

								

									if(isset($_REQUEST['date'])){

										$sql = "SELECT * FROM reservation WHERE '$getDate' BETWEEN rv_ci_date AND DATE_SUB(rv_co_date,INTERVAL 1 DAY) ORDER BY rv_ci_date DESC";

									}

								

									if(isset($_REQUEST['rvno'])){ $getReservationNo = $_GET['rvno'];

										$sql = "SELECT * FROM reservation WHERE rv_no='$getReservationNo'";

									}

								

									$result = mysqli_query($conn,$sql);

									

									while($row = mysqli_fetch_array($result))

									{

                                        // if($row['rv_status'] >= 2 && filterRoomAdmin($row['r_id'],$_SESSION['admin'][0])==true){

                                        //     continue;

                                        // }

								?>

								<tr style="<?php if($row['rv_status'] == 0 && $row['rv_ci_date'] == $getDate){echo 'background-color:#FFD5CC; font-weight: bold;'; }elseif($row['rv_status'] > 1 && $row['r_id']){echo 'background-color:#D6FFD1; font-weight: bold;'; }elseif($row['rv_status'] > 1 && !$row['r_id']){echo 'background-color:#FFFAB3; font-weight: bold;';} ?>">

								    <td><a onClick="navigator.clipboard.writeText('<?php echo $row['rv_no']; ?>')"><?php echo $row['rv_no']; ?></a></td>

									

									<td><?php 

										echo platformTitle($row['rv_platform']); echo "<br>";

										echo reservationByOwnerIdToTitle($row['rv_byowner']);

										?></td>

									

									<td><a href="?pagecontent=reservation_communication&rv=<?php echo $row['rv_id']; ?>">

                                        <?php if($row['rv_guest'])

                                        {echo $row['rv_guest'];}elseif(empty($row['rv_guest']) && !empty($row['rv_guest_name'])){

                                            echo $row['rv_guest_name'];

                                            ?> <span style="font-weight: bold; color: red;">(filled by guest)</span><?php

                                            }else{ ?><span style="color:red;";><?php echo $row['rv_apartment']; ?></span><?php

											} ?></a>

                                    </td>

									<td><a href="?pagecontent=report_profit_room&room=<?php echo $row['r_id']; ?>"><?php if($row['r_id']){echo getDetailFromTable('properties',getDetailFromTable('rooms',$row['r_id'])['p_id'])['pty_code']." ".getDetailFromTable('rooms',$row['r_id'])[1];} ?></a></td>

									<td><?php echo $row['rv_ci_date']." / ".$row['rv_co_date'];?></td>

									<td><?php echo $row['rv_night'];?></td>

									<td><?php echo date_format(date_create($row['rv_co_time']),"h:ia");?></td>

									<td style="<?php if($row['rv_total'] <= 0){echo 'background-color:#FFD5CC; font-weight: bold;';} ?>">

										<a href="?pagecontent=reservation_view&id=<?php echo $row['rv_id']; ?>"><?php if($row['rv_total']=="0.00"){echo "<span style='font-weight:bold; color:red;'>RM ".$row['rv_total']."</span>";}else{echo "RM ".$row['rv_total'];} ?></a>

										

									</td>

									<td>

										<a href="?pagecontent=reservation_view&id=<?php echo $row['rv_id']; ?>">

											<?php if(getDetailByMysqliWhere('deposit','rv_id',$row['rv_id'])){ ?>

												<span style="font-weight:bold; color:blue;"><?php echo "RM ".getDetailByMysqliWhere('deposit','rv_id',$row['rv_id'])['dp_amount']; ?></span>

											<?php }else{ ?>

												<span style="font-weight:bold; color:red;">NO RECORD</span>

											<?php } ?>

										</a>

									</td>

									<td>

										<a href="?pagecontent=reservation_view&id=<?php echo $row['rv_id']; ?>">

											<?php 

												$totalPaid = totalPaid($row['rv_id'])['totalPaid']; 

												if(!$totalPaid){$totalPaid = 0.00;} 

												if($totalPaid < $row['rv_total']){

													echo "<span style='font-weight:bold; color:red;'>RM ".$totalPaid."</span>";}else{

														echo "<span style='font-weight:bold; color:blue;'>CLEARED</span>";}?>

														</a>

									</td>

									<td>

										<?php if($row['rv_ci_date'] == $getDate){ ?>

										<a href="?pagecontent=reservation_status&id=<?php echo $row['rv_id'];?>">

										<?php

										switch($row['rv_status'])

											{

												case "0": echo '<span style="color:red;font-weight:bold;">Pending</span>';

												break;

												case "1": echo '<span style="color:red;font-weight:bold;">Cancelled</span>';

												break;

												case "2": echo '<span style="color:blue;font-weight:bold;">Confirmed</span>';

												break;

												case "3": echo '<span style="color:blue;font-weight:bold;">Arriving</span>';

												break;

												case "4": echo '<span style="color:blue;font-weight:bold;">Arrived</span>';

												break;

												case "5": echo '<span style="color:blue;font-weight:bold;">Checked In</span>';

												break;

												case "6": echo '<span style="color:blue;font-weight:bold;">Checked Out</span>';

												break;

												case "7": echo '<span style="color:black;font-weight:bold;">Completed</span>';

												break;

												default: echo '<span style="color:red;font-weight:bold;">Unknown</span>';

											}

										?></a>

										<?php }else{ ?>

											<span style="color:black;font-weight:bold;">Staying</span>

										<?php } ?>

									</td>

									<td>

										<a href="?pagecontent=reservation_update&id=<?php echo $row['rv_id']; ?>&date=<?php echo $getDate; ?>"><button class="btn btn-xs btn-primary">Update</button></a>

										

										<a href="index.php?pagecontent=reservation_new&name=<?php echo $row['rv_guest']; ?>&contact=<?php echo $row['rv_contact']; ?>&email=<?php echo $row['rv_email']; ?>&room=<?php echo $row['r_id']; ?>&date=<?php echo $row['rv_co_date']; ?>&price=<?php echo $row['rv_total']; ?>"><button class="btn btn-xs btn-warning">Extend</button></a>

									</td>

								</tr>

								<?php

									}

								?>



								<tr>

								    <td colspan="12" align="center">

										no further record

									</td>

								</tr>

						</table>

					</div>

				</div>

			</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="datatable2" class="table table-striped table-bordered">

							<thead>

								<tr>

								    <th>Reservation</th>

								    <th>Platform</th>

									<th>Guest</th>

									<th>Room</th>

									<th>Check In/Out</th>

									<th>Night</th>

									<th>CO Time</th>

									<th>Total</th>

									<th>Deposit</th>

									<th>Clear</th>

									<th>Status</th>

									<th>Action</th>

								</tr>

							</thead>

							<tbody>

								<?php

									if(isset($_REQUEST['date'])){

										$sql = "SELECT * FROM reservation WHERE '$getDate' BETWEEN rv_ci_date AND DATE_SUB(rv_co_date,INTERVAL 1 DAY) AND rv_status = 0 ORDER BY rv_ci_date DESC";

									}



									$result = mysqli_query($conn,$sql);

									

									while($row = mysqli_fetch_array($result))

									{

                                        // if($row['rv_status'] >= 2 && filterRoomAdmin($row['r_id'],$_SESSION['admin'][0])==true){

                                        //     continue;

                                        // }

								?>

								<tr style="<?php if($row['rv_status'] == 0 && $row['rv_ci_date'] == $getDate){echo 'background-color:#FFD5CC; font-weight: bold;'; }elseif($row['rv_status'] > 1 && $row['r_id']){echo 'background-color:#D6FFD1; font-weight: bold;'; }elseif($row['rv_status'] > 1 && !$row['r_id']){echo 'background-color:#FFFAB3; font-weight: bold;';} ?>">

								    <td><a onClick="navigator.clipboard.writeText('<?php echo $row['rv_no']; ?>')"><?php echo $row['rv_no']; ?></a></td>

									

									<td><?php 

										echo platformTitle($row['rv_platform']); echo "<br>";

										echo reservationByOwnerIdToTitle($row['rv_byowner']);

										?></td>

									

									<td><a href="?pagecontent=reservation_communication&rv=<?php echo $row['rv_id']; ?>">

                                        <?php if($row['rv_guest'])

                                        {echo $row['rv_guest'];}elseif(empty($row['rv_guest']) && !empty($row['rv_guest_name'])){

                                            echo $row['rv_guest_name'];

                                            ?> <span style="font-weight: bold; color: red;">(filled by guest)</span><?php

                                            }else{ ?><span style="color:red;";><?php echo $row['rv_apartment']; ?></span><?php

											} ?></a>

                                    </td>

									<td><a href="?pagecontent=report_profit_room&room=<?php echo $row['r_id']; ?>"><?php if($row['r_id']){echo getDetailFromTable('properties',getDetailFromTable('rooms',$row['r_id'])['p_id'])['pty_code']." ".getDetailFromTable('rooms',$row['r_id'])[1];} ?></a></td>

									<td><?php echo $row['rv_ci_date']." / ".$row['rv_co_date'];?></td>

									<td><?php echo $row['rv_night'];?></td>

									<td><?php echo date_format(date_create($row['rv_co_time']),"h:ia");?></td>

									<td style="<?php if($row['rv_total'] <= 0){echo 'background-color:#FFD5CC; font-weight: bold;';} ?>">

										<a href="?pagecontent=reservation_view&id=<?php echo $row['rv_id']; ?>"><?php if($row['rv_total']=="0.00"){echo "<span style='font-weight:bold; color:red;'>RM ".$row['rv_total']."</span>";}else{echo "RM ".$row['rv_total'];} ?></a>

										

									</td>

									<td>

										<a href="?pagecontent=reservation_view&id=<?php echo $row['rv_id']; ?>">

											<?php if(getDetailByMysqliWhere('deposit','rv_id',$row['rv_id'])){ ?>

												<span style="font-weight:bold; color:blue;"><?php echo "RM ".getDetailByMysqliWhere('deposit','rv_id',$row['rv_id'])['dp_amount']; ?></span>

											<?php }else{ ?>

												<span style="font-weight:bold; color:red;">NO RECORD</span>

											<?php } ?>

										</a>

									</td>

									<td>

										<a href="?pagecontent=reservation_view&id=<?php echo $row['rv_id']; ?>">

											<?php 

												$totalPaid = totalPaid($row['rv_id'])['totalPaid']; 

												if(!$totalPaid){$totalPaid = 0.00;} 

												if($totalPaid < $row['rv_total']){

													echo "<span style='font-weight:bold; color:red;'>RM ".$totalPaid."</span>";}else{

														echo "<span style='font-weight:bold; color:blue;'>CLEARED</span>";}?>

														</a>

									</td>

									<td>

										<?php if($row['rv_ci_date'] == $getDate){ ?>

										<a href="?pagecontent=reservation_status&id=<?php echo $row['rv_id'];?>">

										<?php

										switch($row['rv_status'])

											{

												case "0": echo '<span style="color:red;font-weight:bold;">Pending</span>';

												break;

												case "1": echo '<span style="color:red;font-weight:bold;">Cancelled</span>';

												break;

												case "2": echo '<span style="color:blue;font-weight:bold;">Confirmed</span>';

												break;

												case "3": echo '<span style="color:blue;font-weight:bold;">Arriving</span>';

												break;

												case "4": echo '<span style="color:blue;font-weight:bold;">Arrived</span>';

												break;

												case "5": echo '<span style="color:blue;font-weight:bold;">Checked In</span>';

												break;

												case "6": echo '<span style="color:blue;font-weight:bold;">Checked Out</span>';

												break;

												case "7": echo '<span style="color:black;font-weight:bold;">Completed</span>';

												break;

												default: echo '<span style="color:red;font-weight:bold;">Unknown</span>';

											}

										?></a>

										<?php }else{ ?>

											<span style="color:black;font-weight:bold;">Staying</span>

										<?php } ?>

									</td>

									<td>

										<a href="?pagecontent=reservation_update&id=<?php echo $row['rv_id']; ?>&date=<?php echo $getDate; ?>"><button class="btn btn-xs btn-primary">Update</button></a>

										

										<a href="index.php?pagecontent=reservation_new&name=<?php echo $row['rv_guest']; ?>&contact=<?php echo $row['rv_contact']; ?>&email=<?php echo $row['rv_email']; ?>&room=<?php echo $row['r_id']; ?>&date=<?php echo $row['rv_co_date']; ?>&price=<?php echo $row['rv_total']; ?>"><button class="btn btn-xs btn-warning">Extend</button></a>

									</td>

								</tr>

								<?php

									}

								?>



								<tr>

								    <td colspan="12" align="center">

										no further record

									</td>

								</tr>

						</table>

					</div>

				</div>

			</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="datatable3" class="table table-striped table-bordered">

							<thead>

								<tr>

								    <th>Reservation</th>

								    <th>Platform</th>

									<th>Guest</th>

									<th>Room</th>

									<th>Check In/Out</th>

									<th>Night</th>

									<th>CO Time</th>

									<th>Total</th>

									<th>Deposit</th>

									<th>Clear</th>

									<th>Status</th>

									<th>Action</th>

								</tr>

							</thead>

							<tbody>

								<?php

								

									if(isset($_REQUEST['date'])){

										$sql = "SELECT * FROM reservation WHERE '$getDate' BETWEEN rv_ci_date AND DATE_SUB(rv_co_date,INTERVAL 1 DAY) AND rv_status > 1 ORDER BY rv_ci_date DESC";

									}



									$result = mysqli_query($conn,$sql);

									

									while($row = mysqli_fetch_array($result))

									{

                                        // if($row['rv_status'] >= 2 && filterRoomAdmin($row['r_id'],$_SESSION['admin'][0])==true){

                                        //     continue;

                                        // }

								?>

								<tr style="<?php if($row['rv_status'] == 0 && $row['rv_ci_date'] == $getDate){echo 'background-color:#FFD5CC; font-weight: bold;'; }elseif($row['rv_status'] > 1 && $row['r_id']){echo 'background-color:#D6FFD1; font-weight: bold;'; }elseif($row['rv_status'] > 1 && !$row['r_id']){echo 'background-color:#FFFAB3; font-weight: bold;';} ?>">

								    <td><a onClick="navigator.clipboard.writeText('<?php echo $row['rv_no']; ?>')"><?php echo $row['rv_no']; ?></a></td>

									

									<td><?php 

										echo platformTitle($row['rv_platform']); echo "<br>";

										echo reservationByOwnerIdToTitle($row['rv_byowner']);

										?></td>

									

									<td><a href="?pagecontent=reservation_communication&rv=<?php echo $row['rv_id']; ?>">

                                        <?php if($row['rv_guest'])

                                        {echo $row['rv_guest'];}elseif(empty($row['rv_guest']) && !empty($row['rv_guest_name'])){

                                            echo $row['rv_guest_name'];

                                            ?> <span style="font-weight: bold; color: red;">(filled by guest)</span><?php

                                            }else{ ?><span style="color:red;";><?php echo $row['rv_apartment']; ?></span><?php

											} ?></a>

                                    </td>

									<td><a href="?pagecontent=report_profit_room&room=<?php echo $row['r_id']; ?>"><?php if($row['r_id']){echo getDetailFromTable('properties',getDetailFromTable('rooms',$row['r_id'])['p_id'])['pty_code']." ".getDetailFromTable('rooms',$row['r_id'])[1];} ?></a></td>

									<td><?php echo $row['rv_ci_date']." / ".$row['rv_co_date'];?></td>

									<td><?php echo $row['rv_night'];?></td>

									<td><?php echo date_format(date_create($row['rv_co_time']),"h:ia");?></td>

									<td style="<?php if($row['rv_total'] <= 0){echo 'background-color:#FFD5CC; font-weight: bold;';} ?>">

										<a href="?pagecontent=reservation_view&id=<?php echo $row['rv_id']; ?>"><?php if($row['rv_total']=="0.00"){echo "<span style='font-weight:bold; color:red;'>RM ".$row['rv_total']."</span>";}else{echo "RM ".$row['rv_total'];} ?></a>

										

									</td>

									<td>

										<a href="?pagecontent=reservation_view&id=<?php echo $row['rv_id']; ?>">

											<?php if(getDetailByMysqliWhere('deposit','rv_id',$row['rv_id'])){ ?>

												<span style="font-weight:bold; color:blue;"><?php echo "RM ".getDetailByMysqliWhere('deposit','rv_id',$row['rv_id'])['dp_amount']; ?></span>

											<?php }else{ ?>

												<span style="font-weight:bold; color:red;">NO RECORD</span>

											<?php } ?>

										</a>

									</td>

									<td>

										<a href="?pagecontent=reservation_view&id=<?php echo $row['rv_id']; ?>">

											<?php 

												$totalPaid = totalPaid($row['rv_id'])['totalPaid']; 

												if(!$totalPaid){$totalPaid = 0.00;} 

												if($totalPaid < $row['rv_total']){

													echo "<span style='font-weight:bold; color:red;'>RM ".$totalPaid."</span>";}else{

														echo "<span style='font-weight:bold; color:blue;'>CLEARED</span>";}?>

														</a>

									</td>

									<td>

										<?php if($row['rv_ci_date'] == $getDate){ ?>

										<a href="?pagecontent=reservation_status&id=<?php echo $row['rv_id'];?>">

										<?php

										switch($row['rv_status'])

											{

												case "0": echo '<span style="color:red;font-weight:bold;">Pending</span>';

												break;

												case "1": echo '<span style="color:red;font-weight:bold;">Cancelled</span>';

												break;

												case "2": echo '<span style="color:blue;font-weight:bold;">Confirmed</span>';

												break;

												case "3": echo '<span style="color:blue;font-weight:bold;">Arriving</span>';

												break;

												case "4": echo '<span style="color:blue;font-weight:bold;">Arrived</span>';

												break;

												case "5": echo '<span style="color:blue;font-weight:bold;">Checked In</span>';

												break;

												case "6": echo '<span style="color:blue;font-weight:bold;">Checked Out</span>';

												break;

												case "7": echo '<span style="color:black;font-weight:bold;">Completed</span>';

												break;

												default: echo '<span style="color:red;font-weight:bold;">Unknown</span>';

											}

										?></a>

										<?php }else{ ?>

											<span style="color:black;font-weight:bold;">Staying</span>

										<?php } ?>

									</td>

									<td>

										<a href="?pagecontent=reservation_update&id=<?php echo $row['rv_id']; ?>&date=<?php echo $getDate; ?>"><button class="btn btn-xs btn-primary">Update</button></a>

										

										<a href="index.php?pagecontent=reservation_new&name=<?php echo $row['rv_guest']; ?>&contact=<?php echo $row['rv_contact']; ?>&email=<?php echo $row['rv_email']; ?>&room=<?php echo $row['r_id']; ?>&date=<?php echo $row['rv_co_date']; ?>&price=<?php echo $row['rv_total']; ?>"><button class="btn btn-xs btn-warning">Extend</button></a>

									</td>

								</tr>

								<?php

									}

								?>



								<tr>

								    <td colspan="12" align="center">

										no further record

									</td>

								</tr>

						</table>

					</div>

				</div>

			</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="datatable4" class="table table-striped table-bordered">

							<thead>

								<tr>

								    <th>Reservation</th>

								    <th>Platform</th>

									<th>Guest</th>

									<th>Room</th>

									<th>Check In/Out</th>

									<th>Night</th>

									<th>CO Time</th>

									<th>Total</th>

									<th>Deposit</th>

									<th>Clear</th>

									<th>Status</th>

									<th>Action</th>

								</tr>

							</thead>

							<tbody>

								<?php

								

									if(isset($_REQUEST['date'])){

										$sql = "SELECT * FROM reservation WHERE '$getDate' BETWEEN rv_ci_date AND DATE_SUB(rv_co_date,INTERVAL 1 DAY) AND rv_status = 1 ORDER BY rv_ci_date DESC";

									}

									$result = mysqli_query($conn,$sql);

									

									while($row = mysqli_fetch_array($result))

									{

                                        // if($row['rv_status'] >= 2 && filterRoomAdmin($row['r_id'],$_SESSION['admin'][0])==true){

                                        //     continue;

                                        // }

								?>

								<tr style="<?php if($row['rv_status'] == 0 && $row['rv_ci_date'] == $getDate){echo 'background-color:#FFD5CC; font-weight: bold;'; }elseif($row['rv_status'] > 1 && $row['r_id']){echo 'background-color:#D6FFD1; font-weight: bold;'; }elseif($row['rv_status'] > 1 && !$row['r_id']){echo 'background-color:#FFFAB3; font-weight: bold;';} ?>">

								    <td><a onClick="navigator.clipboard.writeText('<?php echo $row['rv_no']; ?>')"><?php echo $row['rv_no']; ?></a></td>

									

									<td><?php 

										echo platformTitle($row['rv_platform']); echo "<br>";

										echo reservationByOwnerIdToTitle($row['rv_byowner']);

										?></td>

									

									<td><a href="?pagecontent=reservation_communication&rv=<?php echo $row['rv_id']; ?>">

                                        <?php if($row['rv_guest'])

                                        {echo $row['rv_guest'];}elseif(empty($row['rv_guest']) && !empty($row['rv_guest_name'])){

                                            echo $row['rv_guest_name'];

                                            ?> <span style="font-weight: bold; color: red;">(filled by guest)</span><?php

                                            }else{ ?><span style="color:red;";><?php echo $row['rv_apartment']; ?></span><?php

											} ?></a>

                                    </td>

									<td><a href="?pagecontent=report_profit_room&room=<?php echo $row['r_id']; ?>"><?php if($row['r_id']){echo getDetailFromTable('properties',getDetailFromTable('rooms',$row['r_id'])['p_id'])['pty_code']." ".getDetailFromTable('rooms',$row['r_id'])[1];} ?></a></td>

									<td><?php echo $row['rv_ci_date']." / ".$row['rv_co_date'];?></td>

									<td><?php echo $row['rv_night'];?></td>

									<td><?php echo date_format(date_create($row['rv_co_time']),"h:ia");?></td>

									<td style="<?php if($row['rv_total'] <= 0){echo 'background-color:#FFD5CC; font-weight: bold;';} ?>">

										<a href="?pagecontent=reservation_view&id=<?php echo $row['rv_id']; ?>"><?php if($row['rv_total']=="0.00"){echo "<span style='font-weight:bold; color:red;'>RM ".$row['rv_total']."</span>";}else{echo "RM ".$row['rv_total'];} ?></a>

										

									</td>

									<td>

										<a href="?pagecontent=reservation_view&id=<?php echo $row['rv_id']; ?>">

											<?php if(getDetailByMysqliWhere('deposit','rv_id',$row['rv_id'])){ ?>

												<span style="font-weight:bold; color:blue;"><?php echo "RM ".getDetailByMysqliWhere('deposit','rv_id',$row['rv_id'])['dp_amount']; ?></span>

											<?php }else{ ?>

												<span style="font-weight:bold; color:red;">NO RECORD</span>

											<?php } ?>

										</a>

									</td>

									<td>

										<a href="?pagecontent=reservation_view&id=<?php echo $row['rv_id']; ?>">

											<?php 

												$totalPaid = totalPaid($row['rv_id'])['totalPaid']; 

												if(!$totalPaid){$totalPaid = 0.00;} 

												if($totalPaid < $row['rv_total']){

													echo "<span style='font-weight:bold; color:red;'>RM ".$totalPaid."</span>";}else{

														echo "<span style='font-weight:bold; color:blue;'>CLEARED</span>";}?>

														</a>

									</td>

									<td>

										<?php if($row['rv_ci_date'] == $getDate){ ?>

										<a href="?pagecontent=reservation_status&id=<?php echo $row['rv_id'];?>">

										<?php

										switch($row['rv_status'])

											{

												case "0": echo '<span style="color:red;font-weight:bold;">Pending</span>';

												break;

												case "1": echo '<span style="color:red;font-weight:bold;">Cancelled</span>';

												break;

												case "2": echo '<span style="color:blue;font-weight:bold;">Confirmed</span>';

												break;

												case "3": echo '<span style="color:blue;font-weight:bold;">Arriving</span>';

												break;

												case "4": echo '<span style="color:blue;font-weight:bold;">Arrived</span>';

												break;

												case "5": echo '<span style="color:blue;font-weight:bold;">Checked In</span>';

												break;

												case "6": echo '<span style="color:blue;font-weight:bold;">Checked Out</span>';

												break;

												case "7": echo '<span style="color:black;font-weight:bold;">Completed</span>';

												break;

												default: echo '<span style="color:red;font-weight:bold;">Unknown</span>';

											}

										?></a>

										<?php }else{ ?>

											<span style="color:black;font-weight:bold;">Staying</span>

										<?php } ?>

									</td>

									<td>

										<a href="?pagecontent=reservation_update&id=<?php echo $row['rv_id']; ?>&date=<?php echo $getDate; ?>"><button class="btn btn-xs btn-primary">Update</button></a>

										

										<a href="index.php?pagecontent=reservation_new&name=<?php echo $row['rv_guest']; ?>&contact=<?php echo $row['rv_contact']; ?>&email=<?php echo $row['rv_email']; ?>&room=<?php echo $row['r_id']; ?>&date=<?php echo $row['rv_co_date']; ?>&price=<?php echo $row['rv_total']; ?>"><button class="btn btn-xs btn-warning">Extend</button></a>

									</td>

								</tr>

								<?php

									}

								?>



								<tr>

								    <td colspan="12" align="center">

										no further record

									</td>

								</tr>

						</table>

					</div>

				</div>

			</div>

        </div>



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

		

		

        <div class="row">

            <div class="col-md-6 col-sm-6 col-xs-12">

                <div class="x_panel">

					<div class="x_title">

						<h2>Find by Reservation No</h2>

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

					</div>



					<div class="x_content">

						<form class="form-horizontal form-label-left" method="get" action="index.php?pagecontent=reservations">

							

							<div class="item form-group">

								<label class="control-label" for="night">Reservation No 

								</label>

								<div class="">

									<input id="night" class="form-control col-md-3 col-xs-12" name="pagecontent" type="text" value="reservations" hidden="">

									<input id="night" class="form-control col-md-3 col-xs-12" name="rvno" type="text" value="">

								</div>

							</div>



							<div class="ln_solid"></div>



							<div class="form-group">

								<div class="">

									<button id="send" type="submit" class="btn btn-primary btn-block">Search</button>

								</div>

							</div>



						</form>

						

					</div>

                </div>

            </div>

			

            <div class="col-md-6 col-sm-6 col-xs-12">

                <div class="x_panel">

					<div class="x_title">

						<h2>Add by Contact</h2>

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

					</div>



					<div class="x_content">

						<form class="form-horizontal form-label-left" method="POST">

							

							<div class="item form-group">

								<label class="control-label" for="night">Contact No 

								</label>

								<div class="">

									<input id="night" class="form-control col-md-3 col-xs-12" name="pagecontent" type="text" value="reservations" hidden="">

									<input id="night" class="form-control col-md-3 col-xs-12" name="contact" type="text" value="">

								</div>

							</div>



							<div class="ln_solid"></div>



							<div class="form-group">

								<div class="">

									<button id="send" type="submit" class="btn btn-primary btn-block" name="searchAddBtn">Search & Add</button>

								</div>

							</div>

							<?php

								if(isset($_POST['searchAddBtn'])){

									

									$getContact = fixWhatsappNo($_POST['contact']);

									$getReservationId = getDetailByMysqliWhere('reservation','rv_contact',$getContact)['rv_id'];

									$getName = getDetailByTable('reservation',$getReservationId)['rv_guest'];

									$getEmail = getDetailByTable('reservation',$getReservationId)['rv_email'];

									$date = date("Y-m-d");



									header("Location: ?pagecontent=reservation_new&name=$getName&contact=$getContact&email=$getEmail&date=$date"); 

								}

							?>

						</form>

					</div>

                </div>

            </div>

		

		

        </div>

    </div>

</div>



<?php



	function reservationByOwnerIdToTitle($id){

		switch($id){

			case 0 : $title = ""; break;

			case 1 : $title = "By Owner"; break;

		}

		

		return $title;

	}



    // $result = mysqli_query($conn,"SELECT * FROM rooms WHERE r_status=1");

    // while($row = mysqli_fetch_assoc($result)){

    //     $roomId = $row['r_id'];

    //     $adminList = array(1,2,8,9,10);

    //     foreach($adminList as $adminId){

    //         mysqli_query($conn,"INSERT INTO room_admin (room_id,admin_id) VALUES ($roomId,$adminId)");

    //     }

    // }

?>