Prevent room status update to inactive or delete if room has future booking
This commit is contained in:
@@ -101,6 +101,8 @@
|
||||
</td>
|
||||
<td class="col-sm-1 center">
|
||||
{if isset($room_info['id'])}
|
||||
<input type="hidden" class="booked-dates" name="{$var_name_room_info|cat:'[booked_dates]'}" value="{$room_info['booked_dates']|escape:'html':'UTF-8'}">
|
||||
<a href="#" class="view_htl_room btn btn-default" data-toggle="modal" data-target="#room-dates-modal" data-id-room="{$room_info['id']}"><i class="icon-info"></i></a>
|
||||
<a href="#" class="rm_htl_room btn btn-default" data-id-htl-info="{$room_info['id']}"><i class="icon-trash"></i></a>
|
||||
<input type="hidden" name="{$var_name_room_info|cat:'[id]'}" value="{$room_info['id']}">
|
||||
{else}
|
||||
@@ -224,6 +226,58 @@
|
||||
</div>
|
||||
{*END*}
|
||||
|
||||
<div class="modal fade" id="room-dates-modal" tabindex="-1" role="dialog" aria-labelledby="">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close margin-right-10" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
<h4 class="modal-title"><i class="icon-calendar"></i> {l s='Room Insights'}</h4>
|
||||
</div>
|
||||
<div class="room-booked-dates-table modal-body">
|
||||
<h4>{l s='Room Booked Dates'}</h4>
|
||||
<div class="table-responsive">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><span>{l s='Order'}</span></th>
|
||||
<th><span>{l s='Date From'}</span></th>
|
||||
<th><span>{l s='Date To'}</span></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody></tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="room-disable-dates-table modal-body">
|
||||
<h4>{l s='Room Disabled Dates'}</h4>
|
||||
<div class="table-responsive">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
<span>{l s='Date From'}</span>
|
||||
</th>
|
||||
<th>
|
||||
<span>{l s='Date To'}</span>
|
||||
</th>
|
||||
<th>
|
||||
<span>{l s='Reason'}</span>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody></tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal" aria-label="Close">{l s='Done'}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.deactiveDatesModal {
|
||||
cursor: pointer;
|
||||
@@ -400,6 +454,44 @@
|
||||
});
|
||||
});
|
||||
|
||||
{literal}
|
||||
$('#room-dates-modal').on('show.bs.modal', function(e) {
|
||||
const triggerRoom = $(e.relatedTarget);
|
||||
$('#room-dates-modal tbody').html('');
|
||||
var bookedDates = JSON.parse($(triggerRoom).closest('tr').find('.booked-dates').val());
|
||||
console.log(bookedDates.length);
|
||||
if (bookedDates.length) {
|
||||
if (bookedDates.length) {
|
||||
$('#room-dates-modal .room-booked-dates-table').show();
|
||||
$(bookedDates).each(function() {
|
||||
$('#room-dates-modal .room-booked-dates-table tbody').append(`<tr>
|
||||
<td><a href="{/literal}{$link->getAdminLink('AdminOrders')|escape:'html':'UTF-8'}{literal}&vieworder&id_order=${this.id_order}" target="_blank">#${this.id_order}</a></td>
|
||||
<td>${this.date_from_formatted}</td>
|
||||
<td>${this.date_to_formatted}</td>
|
||||
</tr>`);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
$('#room-dates-modal .room-booked-dates-table tbody').append(`<tr>
|
||||
<td colspan="3" class="center">{/literal}{l s='No Booking for this room'}{literal}</td>
|
||||
</tr>`);
|
||||
}
|
||||
if ($(triggerRoom).closest('tr').find('.disable_dates_json').val().length) {
|
||||
$('.room-disable-dates-table').show();
|
||||
var disableDates = JSON.parse($(triggerRoom).closest('tr').find('.disable_dates_json').val());
|
||||
$(disableDates).each(function() {
|
||||
$('#room-dates-modal .room-disable-dates-table tbody').append(`<tr>
|
||||
<td>${this.date_from_formatted}</td>
|
||||
<td>${this.date_to_formatted}</td>
|
||||
<td>${this.reason ? this.reason : '--' }</td>
|
||||
</tr>`);
|
||||
});
|
||||
} else {
|
||||
$('.room-disable-dates-table').hide();
|
||||
}
|
||||
});
|
||||
{/literal}
|
||||
|
||||
// Add new room detail
|
||||
$('#add-more-rooms-button').on('click',function() {
|
||||
var lengthRooms = parseInt($('.room_data_values').length);
|
||||
@@ -444,18 +536,19 @@
|
||||
$.ajax({
|
||||
url: prod_link,
|
||||
type: 'POST',
|
||||
dataType: 'text',
|
||||
dataType: 'JSON',
|
||||
data: {
|
||||
ajax:true,
|
||||
action:'deleteHotelRoom',
|
||||
id: id_htl_info,
|
||||
},
|
||||
success: function (result) {
|
||||
if (parseInt(result) == 1) {
|
||||
success: function (response) {
|
||||
if (response.success) {
|
||||
showSuccessMessage("{l s='Removed successfully'}");
|
||||
$current.closest(".room_data_values").remove();
|
||||
} else {
|
||||
showErrorMessage("{l s='Some error occurred'}");
|
||||
if (response.errors)
|
||||
showErrorMessage(response.errors);
|
||||
}
|
||||
},
|
||||
error: function(XMLHttpRequest, textStatus, errorThrown) {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -249,7 +249,12 @@ class HotelRoomInformation extends ObjectModel
|
||||
|
||||
public function getRoomTypeBookedRoomsForDateRange($id_hotel, $id_product, $date_from, $date_to)
|
||||
{
|
||||
return Db::getInstance()->executeS('SELECT * FROM `'._DB_PREFIX_.'htl_booking_detail` where `date_from`< \''.pSQL($date_to).'\' AND `date_to`>\''.$date_from.'\' AND `id_product`='.(int) $id_product.' AND `id_hotel`='.(int) $id_hotel);
|
||||
return Db::getInstance()->executeS('SELECT * FROM `'._DB_PREFIX_.'htl_booking_detail` where `date_from`< \''.pSQL($date_to).'\' AND `date_to`>\''.pSQL($date_from).'\' AND `id_product`='.(int) $id_product.' AND `id_hotel`='.(int) $id_hotel);
|
||||
}
|
||||
|
||||
public function getFutureBookingDates($idRoom)
|
||||
{
|
||||
return Db::getInstance()->executeS('SELECT `id`, `id_order`, `date_from`, `date_to` FROM `'._DB_PREFIX_.'htl_booking_detail` where (`date_from` >= \''.pSQL(date('Y-m-d')).'\' OR `date_to` > \''.pSQL(date('Y-m-d')).'\') AND `is_refunded` = 0 AND `id_room`='.(int) $idRoom);
|
||||
}
|
||||
|
||||
// Webservice :: webservice add function
|
||||
|
||||
Reference in New Issue
Block a user