From d9e8e58ed912cd48cbe78446dcd34d60cabc165e Mon Sep 17 00:00:00 2001 From: Juthatip McDevitt Date: Thu, 27 Jun 2024 19:45:34 -0500 Subject: [PATCH] added cancel booking functionality for new booking page(admin dashboard) --- hotel_booking/admin/ajax/new_booking.php | 14 ++++++++++++-- hotel_booking/admin/new_booking.php | 21 +++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/hotel_booking/admin/ajax/new_booking.php b/hotel_booking/admin/ajax/new_booking.php index 6d8617e..dd0b931 100644 --- a/hotel_booking/admin/ajax/new_booking.php +++ b/hotel_booking/admin/ajax/new_booking.php @@ -25,7 +25,8 @@ $data[order_id] Room: $data[room_name]
- Price: $$data[price] + Price: $$data[price]/night
+ Total: $$data[total_pay] Book date: $date
@@ -34,7 +35,7 @@
- + "; @@ -53,4 +54,13 @@ 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; + } + ?> \ No newline at end of file diff --git a/hotel_booking/admin/new_booking.php b/hotel_booking/admin/new_booking.php index e6edf1d..65084d7 100644 --- a/hotel_booking/admin/new_booking.php +++ b/hotel_booking/admin/new_booking.php @@ -125,6 +125,27 @@ 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(){ get_booking();