<?php

include 'load.php';

?>
 
 <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0">
<meta name="description" content="POS - Eat More Resturant   | Pos & Invetory System | Dashboard">
<meta name="keywords" content="Eat More Resturant   | Pos & Invetory System | Dashboard">
<meta name="author" content="Eat More Resturant   | Pos & Invetory System | Dashboard">
<meta name="robots" content="noindex, nofollow">

<title>Rooms List | Eat More Resturant   | Pos & Invetory System | Dashboard</title>

<?php
require_once 'headercss.php';
?>

</head>
<body>
<div id="global-loader">
<div class="whirly-loader"> </div>
</div>

<div class="main-wrapper">
<?php
require_once 'header.php';
?>

<?php
require_once 'navbar.php';
?>

<div class="page-wrapper">
<div class="content">
<div class="page-header">
<div class="page-title">
<h4 style="text-align: center;">Rooms List</h4>

</div>

</div>
<div class="card mb-0" id="filter_inputs" style="display:block;">
							<div class="card-body pb-0">
								<div class="row">
									<div class="col-lg-12 col-sm-12">
										<form method="GET" enctype="multipart/form-data">
											<div class="row">
											<div class="col-lg-2 col-sm-3 col-12">
													<div class="form-group">
														<label for="start-date">Checkin Date:</label>
														<input type="date" id="start-date" name="start_date" value="<?php echo $_GET['start_date']; ?>" class="form-control">
													</div>
												</div>
												<div class="col-lg-2 col-sm-3 col-12">
													<div class="form-group">
														<label for="end-date">Checkout Date:</label>
														<input type="date" id="end-date" name="end_date" value="<?php echo $_GET['end_date']; ?>" class="form-control">
													</div>
												</div>
												
												<div class="col-lg-2 col-sm-4 col-12">
													<div class="form-group">
														<button type="submit" name="search" class="btn btn-block btn-outline-success active btn-md text-white" style="margin-top:33px;" class="btn btn-filters ms-auto">
														<i class="fa fa-search" aria-hidden="true"></i> Search
														</button>
													</div>
												</div>

											</div>
										</form>

									</div>
								</div>
							</div>
						</div>
<div class="row">

		<?php 
            $room = mysqli_query($conn, "SELECT * FROM mobileproducts WHERE producttype='Room' AND status='1' ORDER BY prid ASC");
			
            if (mysqli_num_rows($room) > 0) {
				
				while ($row = mysqli_fetch_assoc($room)) {
				
                ?>
					<div class="col-md-3">
					<div class="wrap">
                        <div class="wrap1">
								<div class="kot-no" style="background-color:#0f1ecf;<?php echo number_format((float)$row['sellprice'],2); ?>">
                                    <h6 style="font-size:16px;">Room Number - <?php echo $row['itemcode']; ?></h6>
                                </div>
								<div class="col-md-12">
								<?php if($row['cover']==""){$pro_img="assets/img/empty.png";}else{$pro_img="images/products/cover/".$row['cover'];} ?><img src="<?php echo $pro_img; ?>" alt="" width="100%" height="200">
								</div>
                                <div class="tb">
                                <table class="table">
                                    <thead class="thead-light">
                                        <tr>
                                        <th scope="col" style="font-size:18px;text-align:center;"><?php echo $row['proname']; ?></th>
                                        </tr>
                                    </thead>
                                    </table>
                                </div>
							</div>
							<br>
							<div class="row">
							<div class="col-md-6">
							<a href="" class="btn btn-warning btn-sm btn-block" style="width:100%;"><i class="fa fa-bed" aria-hidden="true"></i> <?php echo number_format((int)$row['qty']); ?></a>
							</div>
							<div class="col-md-6">
							<a href="" class="btn btn-secondary btn-sm btn-block" style="width:100%;"><i class="fa fa-money" aria-hidden="true"></i> Rs.<?php echo number_format((float)$row['sellprice'],2); ?></a>
							</div>
							<br><br>
							
								<?php   
								$s = 0;
								$prid = $row['prid'];
										if(isset($_GET['start_date']) && isset($_GET['end_date'])){
								        $checkindate = $_GET['start_date'];
										$checkoutdate = $_GET['end_date']; 
										$start = new DateTime($checkindate);
										$end = new DateTime($checkoutdate);
										$interval = $start->diff($end);
										$days = $interval->days;
										$datearr = array();
										$end->modify('+1 day');

										$interval = new DateInterval('P1D');
										
										$datePeriod = new DatePeriod($start, $interval, $end);
									
										foreach ($datePeriod as $date) {
											
											array_push($datearr,$date->format('Y-m-d'). PHP_EOL);
										}

										

										$result = mysqli_query($conn, "SELECT * FROM mobileroombooking WHERE room='$prid'");
										if ($result->num_rows > 0) {
											while($row1 = $result->fetch_assoc()) {
												$checkindate1 = $row1['checkindate'];
												$checkoutdate1 = $row1['checkoutdate'];

												$start1 = new DateTime($checkindate1);
												$end1 = new DateTime($checkoutdate1);
												$interval1 = $start1->diff($end1);
												$days = $interval1->days;
												
												$end1->modify('+1 day');

												$interval1 = new DateInterval('P1D');
												$datePeriod1 = new DatePeriod($start1, $interval1, $end1);

												foreach ($datePeriod1 as $date1) {
													if (in_array($date1->format('Y-m-d'). PHP_EOL,$datearr)){
														$s = 1;
														break;
													}
												}
											}
										}

									}
									
									if($s==1){ ?>
										<div class="col-md-12">
										<a href="" class="btn btn-danger btn-sm btn-block" style="font-size:16px;width:100%;"><i class="fa fa-book" aria-hidden="true"></i> AllReady Booked</a>
										</div>
									<?php }else{	?>
								<div class="col-md-12">
								<a href="" class="btn btn-success btn-sm btn-block" style="font-size:16px;width:100%;"><i class="fa fa-book" aria-hidden="true"></i> Available</a>
								</div>
								<?php } ?>
							</div>
					</div>  
					</div>
       

				<?php 
				}
				}
				?>

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

<style>
    .wrap{
        box-shadow: 0px 0px 30px 0px rgba(193, 193, 193, 0.5);
        background-color: #fff;
        padding: 10px;
    }
    .order-type{
        background-color: green;
        text-align: center;
        color: #fff;
        padding: 5px;
    }
    .kot-no{
        text-align: center;
        background: red;
        color: #fff;
        padding: 5px;
        margin-top: 5px;
        margin-bottom: 5px;;
    }
</style>

<?php require_once 'footerjs.php'; ?>

</body>
</html>