added cancel booking functionality for new booking page(admin dashboard)

This commit is contained in:
Juthatip McDevitt 2024-06-27 19:45:34 -05:00
parent b35c134eee
commit d9e8e58ed9
2 changed files with 33 additions and 2 deletions

View file

@ -25,7 +25,8 @@
<td>$data[order_id]</td> <td>$data[order_id]</td>
<td style='font-size: 14px;'> <td style='font-size: 14px;'>
<b>Room:</b> $data[room_name]<br> <b>Room:</b> $data[room_name]<br>
<b>Price:</b> $$data[price] <b>Price:</b> $$data[price]/night<br>
<b>Total:</b> $$data[total_pay]
</td> </td>
<td style='font-size: 14px;'> <td style='font-size: 14px;'>
<b>Book date:</b> $date<br> <b>Book date:</b> $date<br>
@ -34,7 +35,7 @@
</td> </td>
<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' 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> <button type='button' onclick='cancel_booking($data[booking_id])' class='btn-cancel text-white fw-bold' style='font-size: 12px;'>Cancel Booking</button>
</td> </td>
</tr> </tr>
"; ";
@ -53,4 +54,13 @@
echo ($res == 2) ? 1 : 0; echo ($res == 2) ? 1 : 0;
} }
if(isset($_POST['cancel_booking'])){
$frm_data = filteration($_POST);
$query = "UPDATE `booking_order` SET `booking_status` =? WHERE booking_id =?";
$values = ['cancel', $frm_data['booking_id']];
$res = update($query, $values, 'si');
echo $res;
}
?> ?>

View file

@ -125,6 +125,27 @@
xhr.send(data); xhr.send(data);
}); });
function cancel_booking(id){
if(confirm("Are you sure you want to cancel this booking?")){
let data = new FormData();
data.append('booking_id', id);
data.append('cancel_booking', '');
let xhr = new XMLHttpRequest();
xhr.open("POST", "ajax/new_booking.php", true)
xhr.onload = function(){
if(this.responseText == 1){
alert('success', 'This booking was successfully cancel!');
get_booking();
} else{
alert('error', 'Fail to cancel this booking');
}
}
xhr.send(data);
}
}
window.onload = function(){ window.onload = function(){
get_booking(); get_booking();