created admin dashboard-new bookings and added room number functionality

This commit is contained in:
Juthatip McDevitt 2024-06-27 16:24:03 -05:00
parent 1b16d2db0a
commit b35c134eee
3 changed files with 192 additions and 1 deletions

View file

@ -0,0 +1,56 @@
<?php
require('../components/utils.php');
require('../components/db_config.php');
adminLogin();
date_default_timezone_set("UTC");
if(isset($_POST['get_booking'])){
$query = "SELECT bo.*, bd.* FROM `booking_order` bo INNER JOIN `booking_detail` bd ON bo.booking_id = bd.booking_id WHERE bo.booking_status = 'pending' AND bo.arrival = 0 ORDER BY bo.booking_id ASC";
$res = mysqli_query($con, $query);
$i = 1;
$table_data = "";
while($data = mysqli_fetch_assoc($res)){
$date = date("M-d-Y", strtotime($data['datentime']));
$checkin = date("M-d-Y", strtotime($data['check_in']));
$checkout = date("M-d-Y", strtotime($data['check_out']));
$table_data .= "
<tr>
<td>$i</td>
<td> $data[user_name] $data[user_lastname]<br>
</td>
<td>$data[order_id]</td>
<td style='font-size: 14px;'>
<b>Room:</b> $data[room_name]<br>
<b>Price:</b> $$data[price]
</td>
<td style='font-size: 14px;'>
<b>Book date:</b> $date<br>
<b>Check-in:</b> $checkin<br>
<b>Check-out:</b> $checkout<br>
</td>
<td>
<button type='button' onclick='room_number($data[booking_id])' class='btn-third text-white fw-bold mb-2' style='font-size: 12px;' data-bs-toggle='modal' data-bs-target='#room-number'>Room Number</button><br>
<button type='button' class='btn-cancel text-white fw-bold' style='font-size: 12px;'>Cancel Booking</button>
</td>
</tr>
";
$i++;
}
echo $table_data;
}
if(isset($_POST['room_number'])){
$frm_data = filteration($_POST);
$query = "UPDATE `booking_order` bo INNER JOIN `booking_detail` bd ON bo.booking_id = bd.booking_id SET bo.arrival = ?, bd.room_no = ? WHERE bo.booking_id = ?";
$values = [1, $frm_data['room_no'], $frm_data['booking_id']];
$res = update($query, $values, 'isi');
echo ($res == 2) ? 1 : 0;
}
?>

View file

@ -14,7 +14,7 @@
$verified = "<span class='badge bg-danger'>No</span>";
if($row['is_verified']){
$verified = "<span class='badge bg-success'>Yes</span>";
$verified = "<span class='badge' style='background-color: #135D66;'>Yes</span>";
$delete_btn = "";
}

View file

@ -0,0 +1,135 @@
<?php
require('components/utils.php');
require('components/db_config.php');
adminLogin();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin Dashboard-new booking | Midtown Hotel</title>
<?php require('components/link.php') ?>
<style>
.custom-alert-t{
position:fixed;
top: 100px;
right: 25px;
z-index: 10000;
}
</style>
</head>
<body>
<?php require('components/sidebar.php')?>
<div class="container-fluid" id="dashboard-body">
<div class="row">
<div class="col-lg-10 ms-auto p-4 overflow-hidden">
<h4 class="mb-4">New Bookings</h4>
<div class="card mb-4">
<div class="card-body">
<div class="mb-4 text-end">
<input type="text" oninput="search_users(this.value)" class="form-control w-25 ms-auto shadow-none" placeholder="Search">
</div>
<div class="table-responsive">
<table class="table table-hover border">
<thead>
<tr style="background-color: #D3D3D3;">
<th scope="col">#</th>
<th scope="col">User Detail</th>
<th scope="col">Order Number</th>
<th scope="col">Room Detail</th>
<th scope="col">Booking Detail</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody id="table_data">
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
<!--Room Number-->
<div class="modal fade" id="room-number" data-bs-backdrop="static" data-bs-keyboard="true" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
<div class="modal-dialog">
<form id="room_number_form">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Room Number</h5>
</div>
<div class="modal-body">
<div class="mb-2">
<label class="form-label" style="font-weight: 600;">Room Number</label>
<input type="text" name="room_no" class="form-control shadow-none" required/>
</div>
<span style="color: red; font-size: 14px;">Room number will be assigned only when a customer make a payment at the hotel reception desk.</span>
<input type="hidden" name="booking_id">
</div>
<div class="modal-footer">
<button type="reset" class="btn-cancel" data-bs-dismiss="modal">Cancel</button>
<button type="submit" class="btn-third">Submit</button>
</div>
</div>
</form>
</div>
</div>
<?php require('components/script.php') ?>
<script>
let room_number_form = document.getElementById('room_number_form');
function get_booking(){
let xhr = new XMLHttpRequest();
xhr.open("POST", "ajax/new_booking.php", true);
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xhr.onload = function(){
document.getElementById('table_data').innerHTML = this.responseText;
}
xhr.send('get_booking');
}
function room_number(id){
room_number_form.elements['booking_id'].value = id;
}
room_number_form.addEventListener('submit', function(e) {
e. preventDefault();
let data = new FormData();
data.append('room_no', room_number_form.elements['room_no'].value);
data.append('booking_id', room_number_form.elements['booking_id'].value);
data.append('room_number', '');
let xhr = new XMLHttpRequest();
xhr.open("POST", "ajax/new_booking.php", true);
xhr.onload = function(){
console.log(this.responseText);
var myModal = document.getElementById('room-number');
var modal = bootstrap.Modal.getInstance(myModal);
modal.hide()
if(this.responseText == 1){
alert('success', 'Room number is assigned.');
room_number_form.reset();
get_booking();
} else{
alert('error', 'Fail to assign room number at this time, please try again later!');
}
}
xhr.send(data);
});
window.onload = function(){
get_booking();
}
</script>
</body>
</html>