Prevent room status update to inactive or delete if room has future booking
This commit is contained in:
@@ -2763,8 +2763,19 @@ class AdminProductsControllerCore extends AdminController
|
||||
$hotelRoomInfo = $objRoomInfo->getHotelRoomInfo($obj->id, $hotelRoomType['id_hotel']);
|
||||
if ($hotelRoomInfo) {
|
||||
foreach ($hotelRoomInfo as &$room) {
|
||||
$bookedDates = $objRoomInfo->getFutureBookingDates($room['id']);
|
||||
foreach($bookedDates as &$bookedDate) {
|
||||
$bookedDate['date_from_formatted'] = Tools::displayDate($bookedDate['date_from']);
|
||||
$bookedDate['date_to_formatted'] = Tools::displayDate($bookedDate['date_to']);
|
||||
}
|
||||
$room['booked_dates'] = json_encode($bookedDates);
|
||||
|
||||
if ($room['id_status'] == HotelRoomInformation::STATUS_TEMPORARY_INACTIVE) {
|
||||
$disabledDates = $objRoomDisableDates->getRoomDisableDates($room['id']);
|
||||
foreach($disabledDates as &$disabledDate) {
|
||||
$disabledDate['date_from_formatted'] = Tools::displayDate($disabledDate['date_from']);
|
||||
$disabledDate['date_to_formatted'] = Tools::displayDate($disabledDate['date_to']);
|
||||
}
|
||||
$room['disable_dates_json'] = json_encode($disabledDates);
|
||||
}
|
||||
}
|
||||
@@ -3243,10 +3254,15 @@ class AdminProductsControllerCore extends AdminController
|
||||
$this->errors[] = sprintf(Tools::displayError('Invalid floor for room %s.'), $roomIndex);
|
||||
}
|
||||
|
||||
if ($roomInfo['id_status'] == HotelRoomInformation::STATUS_TEMPORARY_INACTIVE) {
|
||||
if ($roomInfo['id_status'] == HotelRoomInformation::STATUS_INACTIVE) {
|
||||
$objHotelRoomInformation = new HotelRoomInformation();
|
||||
if (count($objHotelRoomInformation->getFutureBookingDates($roomInfo['id']))) {
|
||||
$this->errors[] = sprintf(Tools::displayError('Cannot change room %s status to inactive as it already has some bookings, Please check the bookings and move those bookings to another room if you want to disable this room'), $roomInfo['room_num']);
|
||||
}
|
||||
} elseif ($roomInfo['id_status'] == HotelRoomInformation::STATUS_TEMPORARY_INACTIVE) {
|
||||
$disableDates = json_decode($roomInfo['disable_dates_json'], true);
|
||||
if ($roomInfo['disable_dates_json'] !== 0) {
|
||||
$this->validateDisableDateRanges($disableDates, $roomIndex, $roomInfo['id']);
|
||||
$this->validateDisableDateRanges($disableDates, $roomInfo['room_num'], $roomInfo['id']);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3257,14 +3273,25 @@ class AdminProductsControllerCore extends AdminController
|
||||
|
||||
public function ajaxProcessDeleteHotelRoom()
|
||||
{
|
||||
$response = array(
|
||||
'success' => false
|
||||
);
|
||||
if ($this->tabAccess['edit'] == 1) {
|
||||
$idRoom = Tools::getValue('id');
|
||||
$objRoomInfo = new HotelRoomInformation((int)$idRoom);
|
||||
if ($objRoomInfo->delete()) {
|
||||
die('1');
|
||||
$objHotelRoomInformation = new HotelRoomInformation();
|
||||
if ($objHotelRoomInformation->getFutureBookingDates($idRoom)) {
|
||||
$this->errors = $this->l('This room cannot be deleted as this room contains future booking.');
|
||||
}
|
||||
if (empty($this->errors)) {
|
||||
if ($objRoomInfo->delete()) {
|
||||
$response['success'] = true;
|
||||
}
|
||||
} else {
|
||||
$response['errors'] = $this->errors;
|
||||
}
|
||||
}
|
||||
die('0');
|
||||
die(json_encode($response));
|
||||
}
|
||||
|
||||
public function initFormAdditionalFacilities($obj)
|
||||
|
||||
Reference in New Issue
Block a user