diff --git a/admin/themes/default/template/controllers/orders/form.tpl b/admin/themes/default/template/controllers/orders/form.tpl
index ceaf56d69..31f3380ce 100644
--- a/admin/themes/default/template/controllers/orders/form.tpl
+++ b/admin/themes/default/template/controllers/orders/form.tpl
@@ -386,28 +386,51 @@
});
$(document).on('change', '.num_occupancy', function(e) {
+ let elementVal = parseInt($(this).val());
let current_room_occupancy = 0;
$(this).closest('.occupancy_info_block').find('.num_occupancy').each(function(){
current_room_occupancy += parseInt($(this).val());
});
let max_guests_in_room = $(this).closest(".booking_occupancy_wrapper").find('.max_guests').val();
let max_allowed_for_current = (max_guests_in_room - current_room_occupancy) + parseInt($(this).val());
- if ($(this).val() > $(this).attr('max')) {
- $(this).val($(this).attr('max'));
- }
- if ($(this).val() > max_allowed_for_current) {
- $(this).val(max_allowed_for_current);
- }
+ let haserror = false
if ($(this).hasClass('num_children')) {
- var totalChilds = $(this).closest('.occupancy_info_block').find('.guest_child_age').length;
- if (totalChilds < $(this).val()) {
- if (totalChilds < max_child_in_room) {
+ max_child_in_room = $(this).closest(".booking_occupancy_wrapper").find('.max_children').val();
+ console.log(no_children_allowed_txt);
+ if (elementVal > max_child_in_room) {
+ $(this).val(max_child_in_room);
+ if (elementVal == 1) {
+ showOccupancyError(no_children_allowed_txt, $(this).closest(".occupancy_info_block"));
+ haserror = true;
+ } else {
+ showOccupancyError(max_children_txt, $(this).closest(".occupancy_info_block"));
+ haserror = true;
+ }
+ } else if (elementVal > max_allowed_for_current) {
+ $(this).val(max_allowed_for_current);
+ showOccupancyError(max_occupancy_reached_txt, $(this).closest(".occupancy_info_block"));
+ haserror = true;
+ }
+ } else {
+ max_adults_in_room = $(this).closest(".booking_occupancy_wrapper").find('.max_adults').val();
+ if (elementVal >= max_adults_in_room) {
+ $(this).val(max_adults_in_room);
+ showOccupancyError(max_adults_txt, $(this).closest(".occupancy_info_block"));
+ haserror = true;
+ } else if (elementVal > max_allowed_for_current) {
+ $(this).val(max_allowed_for_current);
+ showOccupancyError(max_occupancy_reached_txt, $(this).closest(".occupancy_info_block"));
+ haserror = true;
+ }
+ }
+
+ if (!haserror) {
+ if ($(this).hasClass('num_children')) {
+ let totalChilds = $(this).closest('.occupancy_info_block').find('.guest_child_age').length;
+ if (totalChilds < $(this).val()) {
$(this).closest('.occupancy_info_block').find('.children_age_info_block').show();
while ($(this).closest('.occupancy_info_block').find('.guest_child_age').length < $(this).val()) {
-
-
var roomBlockIndex = parseInt($(this).closest('.occupancy_info_block').attr('occ_block_index'));
-
var childAgeSelect = '
';
$(this).closest('.occupancy_info_block').find('.children_ages').append(childAgeSelect);
}
- }
- } else {
- let child = $(this).val();
- $(this).closest('.occupancy_info_block').find('.guest_child_age').each(function(ind, element) {
- if (child <= ind) {
- $(element).parent().remove();
+ } else {
+ let child = $(this).val();
+ $(this).closest('.occupancy_info_block').find('.guest_child_age').each(function(ind, element) {
+ if (child <= ind) {
+ $(element).parent().remove();
+ }
+ });
+ if (child == 0) {
+ $(this).closest('.occupancy_info_block').find('.children_age_info_block').hide();
}
- });
- if (child == 0) {
- $(this).closest('.occupancy_info_block').find('.children_age_info_block').hide();
- }
+ }
}
}
setRoomTypeGuestOccupancy($(this).closest('.booking_occupancy_wrapper'));
-
});
+ var errorMsgTime;
+ $('.occupancy-input-errors').parent().hide();
+ function showOccupancyError(msg, occupancy_info_block)
+ {
+ var errorMsgBlock = $(occupancy_info_block).find('.occupancy-input-errors')
+ $(errorMsgBlock).html(msg).parent().show('fast');
+ clearTimeout(errorMsgTime);
+ errorMsgTime = setTimeout(function() {
+ $(errorMsgBlock).parent().hide('fast');
+ }, 1000);
+
+ }
+
$(document).on('click', '.booking_guest_occupancy', function(e) {
$(this).parent().toggleClass('open');
@@ -2146,7 +2181,13 @@
{addJsDefL name='below_txt'}{l s='Below' js=1}{/addJsDefL}
{addJsDefL name='years_txt'}{l s='years' js=1}{/addJsDefL}
{addJsDefL name='all_children_txt'}{l s='All Children' js=1}{/addJsDefL}
+ {addJsDefL name='max_occupancy_reached_txt'}{l s='Maximum room occupancy reached' js=1}{/addJsDefL}
+ {addJsDefL name='max_adults_txt'}{l s='Maximum adult occupancy reached' js=1}{/addJsDefL}
+ {addJsDefL name='max_children_txt'}{l s='Maximum children occupancy reached' js=1}{/addJsDefL}
+ {addJsDefL name='no_children_allowed_txt'}{l s='Only adults can be accommodated' js=1}{/addJsDefL}
{addJsDefL name='invalid_occupancy_txt'}{l s='Invalid occupancy(adults/children) found.' js=1}{/addJsDefL}
+
+
{/strip}
diff --git a/admin/themes/default/template/controllers/orders/helpers/view/view.tpl b/admin/themes/default/template/controllers/orders/helpers/view/view.tpl
index 3fb70b88a..ca76425e0 100644
--- a/admin/themes/default/template/controllers/orders/helpers/view/view.tpl
+++ b/admin/themes/default/template/controllers/orders/helpers/view/view.tpl
@@ -1687,6 +1687,10 @@
{addJsDefL name='below_txt'}{l s='Below' js=1}{/addJsDefL}
{addJsDefL name='years_txt'}{l s='years' js=1}{/addJsDefL}
{addJsDefL name='all_children_txt'}{l s='All Children' js=1}{/addJsDefL}
+ {addJsDefL name='max_occupancy_reached_txt'}{l s='Maximum room occupancy reached' js=1}{/addJsDefL}
+ {addJsDefL name='max_adults_txt'}{l s='Maximum adult occupancy reached' js=1}{/addJsDefL}
+ {addJsDefL name='max_children_txt'}{l s='Maximum children occupancy reached' js=1}{/addJsDefL}
+ {addJsDefL name='no_children_allowed_txt'}{l s='Only adults can be accommodated' js=1}{/addJsDefL}
{addJsDefL name='invalid_occupancy_txt'}{l s='Invalid occupancy(adults/children) found.' js=1}{/addJsDefL}
{addJsDefL name='select_room_txt'}{l s='Select room' js=1}{/addJsDefL}
{addJsDef max_child_age=$max_child_age|escape:'quotes':'UTF-8'}
diff --git a/controllers/front/CartController.php b/controllers/front/CartController.php
index 25ed52255..6485da946 100644
--- a/controllers/front/CartController.php
+++ b/controllers/front/CartController.php
@@ -347,10 +347,10 @@ class CartControllerCore extends FrontController
if (!count($this->errors)) {
foreach($occupancy as $key => $roomOccupancy) {
if ($roomOccupancy['adults'] > $roomTypeInfo['max_adults']) {
- $this->errors[] = sprintf(Tools::displayError('Room %s cannot have adults more than %s'), $key + 1, $roomTypeInfo['max_adults']);
+ $this->errors[] = sprintf(Tools::displayError('Room %s cannot have adults more than %s adults'), $key + 1, $roomTypeInfo['max_adults']);
}
if ($roomOccupancy['children'] > $roomTypeInfo['max_children']) {
- $this->errors[] = sprintf(Tools::displayError('Room %s cannot have children more than %s'), $key + 1, $roomTypeInfo['max_children']);
+ $this->errors[] = sprintf(Tools::displayError('Room %s cannot have children more than %s children'), $key + 1, $roomTypeInfo['max_children']);
}
if ($roomOccupancy['adults'] + $roomOccupancy['children'] > $roomTypeInfo['max_guests']) {
$this->errors[] = sprintf(Tools::displayError('Room %s cannot have total guests more than %s'), $key + 1, $roomTypeInfo['max_guests']);
@@ -373,7 +373,6 @@ class CartControllerCore extends FrontController
$this->errors[] = Tools::displayError('You can\'t book room after date '.$maxOrdDate);
}
}
-
if (!$this->errors) {
$objBookingDetail = new HotelBookingDetail();
$num_days = $objBookingDetail->getNumberOfDays($date_from, $date_to);
diff --git a/js/admin/orders.js b/js/admin/orders.js
index 80d0a6c63..9fb0f6572 100644
--- a/js/admin/orders.js
+++ b/js/admin/orders.js
@@ -557,46 +557,98 @@ function initProductEvents()
});
$(document).on('change', '.num_occupancy', function(e) {
+ let elementVal = parseInt($(this).val());
let current_room_occupancy = 0;
$(this).closest('.occupancy_info_block').find('.num_occupancy').each(function(){
current_room_occupancy += parseInt($(this).val());
});
-
- if ($(this).hasClass('num_children')) {
- var totalChilds = $(this).closest('.occupancy_info_block').find('.guest_child_age').length;
- if (totalChilds < $(this).val()) {
- $(this).closest('.occupancy_info_block').find('.children_age_info_block').show();
- while ($(this).closest('.occupancy_info_block').find('.guest_child_age').length < $(this).val()) {
- var roomBlockIndex = parseInt($(this).closest('.occupancy_info_block').attr('occ_block_index'));
-
- var childAgeSelect = '
';
- childAgeSelect += '';
- childAgeSelect += '
';
- $(this).closest('.occupancy_info_block').find('.children_ages').append(childAgeSelect);
+ let max_guests_in_room = $(this).closest(".booking_occupancy_wrapper").find('.max_guests').val();
+ let max_allowed_for_current = (max_guests_in_room - current_room_occupancy) + parseInt($(this).val());
+ let haserror = false
+ if ($(this).hasClass('num_children')) {
+ max_child_in_room = $(this).closest(".booking_occupancy_wrapper").find('.max_children').val();
+ if (elementVal > max_child_in_room) {
+ $(this).val(max_child_in_room);
+ if (elementVal == 1) {
+ showOccupancyError(no_children_allowed_txt, $(this).closest(".occupancy_info_block"));
+ haserror = true;
+ } else {
+ showOccupancyError(max_children_txt, $(this).closest(".occupancy_info_block"));
+ haserror = true;
}
- } else {
- let child = $(this).val();
- $(this).closest('.occupancy_info_block').find('.guest_child_age').each(function(ind, element) {
- if (child <= ind) {
- $(element).parent().remove();
+ } else if (elementVal > max_allowed_for_current) {
+ $(this).val(max_allowed_for_current);
+ showOccupancyError(max_occupancy_reached_txt, $(this).closest(".occupancy_info_block"));
+ haserror = true;
+ }
+ } else {
+ max_adults_in_room = $(this).closest(".booking_occupancy_wrapper").find('.max_adults').val();
+ if (elementVal >= max_adults_in_room) {
+ $(this).val(max_adults_in_room);
+ showOccupancyError(max_adults_txt, $(this).closest(".occupancy_info_block"));
+ haserror = true;
+ } else if (elementVal > max_allowed_for_current) {
+ $(this).val(max_allowed_for_current);
+ showOccupancyError(max_occupancy_reached_txt, $(this).closest(".occupancy_info_block"));
+ haserror = true;
+ }
+ }
+ if (!haserror) {
+ if ($(this).hasClass('num_children')) {
+ var totalChilds = $(this).closest('.occupancy_info_block').find('.guest_child_age').length;
+ if (totalChilds < $(this).val()) {
+ let max_child_in_room;
+ if ($(this).closest(".booking_occupancy_wrapper").find('.max_children').val()) {
+ max_child_in_room = $(this).closest(".booking_occupancy_wrapper").find('.max_children').val();
+ } else {
+ max_child_in_room = window.max_child_in_room;
}
- });
- if (child == 0) {
- $(this).closest('.occupancy_info_block').find('.children_age_info_block').hide();
- }
+ if (totalChilds < max_child_in_room) {
+ $(this).closest('.occupancy_info_block').find('.children_age_info_block').show();
+ while ($(this).closest('.occupancy_info_block').find('.guest_child_age').length < $(this).val()) {
+
+ var roomBlockIndex = parseInt($(this).closest('.occupancy_info_block').attr('occ_block_index'));
+
+ var childAgeSelect = '
';
+ childAgeSelect += '';
+ childAgeSelect += '
';
+ $(this).closest('.occupancy_info_block').find('.children_ages').append(childAgeSelect);
+ }
+ }
+ } else {
+ let child = $(this).val();
+ $(this).closest('.occupancy_info_block').find('.guest_child_age').each(function(ind, element) {
+ if (child <= ind) {
+ $(element).parent().remove();
+ }
+ });
+ if (child == 0) {
+ $(this).closest('.occupancy_info_block').find('.children_age_info_block').hide();
+ }
+ }
}
}
-
setRoomTypeGuestOccupancy($(this).closest('.booking_occupancy_wrapper'));
});
+ var errorMsgTime;
+ $('.occupancy-input-errors').parent().hide();
+ function showOccupancyError(msg, occupancy_info_block)
+ {
+ var errorMsgBlock = $(occupancy_info_block).find('.occupancy-input-errors')
+ $(errorMsgBlock).html(msg).parent().show('fast');
+ clearTimeout(errorMsgTime);
+ errorMsgTime = setTimeout(function() {
+ $(errorMsgBlock).parent().hide('fast');
+ }, 1000);
+ }
$(document).on('click', '.booking_guest_occupancy:not(.disabled)', function(e) {
$(this).parent().toggleClass('open');
@@ -1114,6 +1166,13 @@ function initRoomEvents()
$('tr#new_product .booking_guest_occupancy').removeClass('disabled');
setRoomTypeGuestOccupancy($('tr#new_product .booking_occupancy_wrapper'));
}
+ if (data.room_type_info) {
+ $('tr#new_product .max_adults').val(data.room_type_info.max_adults);
+ $('tr#new_product .max_children').val(data.room_type_info.max_children);
+ $('tr#new_product .max_guests').val(data.room_type_info.max_guests);
+ // $('tr#new_product .num_adults').attr('max', data.room_type_info.max_adults);
+ // $('tr#new_product .num_children').attr('max', data.room_type_info.max_children);
+ }
// Keep product variable
current_product = data;
diff --git a/modules/hotelreservationsystem/controllers/admin/AdminHotelRoomsBookingController.php b/modules/hotelreservationsystem/controllers/admin/AdminHotelRoomsBookingController.php
index ebbfa95eb..a6144ba0e 100644
--- a/modules/hotelreservationsystem/controllers/admin/AdminHotelRoomsBookingController.php
+++ b/modules/hotelreservationsystem/controllers/admin/AdminHotelRoomsBookingController.php
@@ -912,6 +912,10 @@ class AdminHotelRoomsBookingController extends ModuleAdminController
'below_txt' => $this->l('Below', null, true),
'years_txt' => $this->l('years', null, true),
'all_children_txt' => $this->l('All Children', null, true),
+ 'max_occupancy_reached_txt' => $this->l('Maximum room occupancy reached', null, true),
+ 'max_adults_txt' => $this->l('Maximum adult occupancy reached', null, true),
+ 'max_children_txt' => $this->l('Maximum children occupancy reached', null, true),
+ 'no_children_allowed_txt' => $this->l('Only adults can be accommodated', null, true),
'invalid_occupancy_txt' => $this->l('Invalid occupancy(adults/children) found.', null, true),
// 'check_calender_var' => $check_calender_var,
'txtSomeErr' => $this->l('Some error occurred. Please try again.'),
diff --git a/modules/hotelreservationsystem/views/js/admin/hotel_rooms_booking.js b/modules/hotelreservationsystem/views/js/admin/hotel_rooms_booking.js
index f4518217b..712731073 100644
--- a/modules/hotelreservationsystem/views/js/admin/hotel_rooms_booking.js
+++ b/modules/hotelreservationsystem/views/js/admin/hotel_rooms_booking.js
@@ -597,55 +597,91 @@ $(document).ready(function() {
});
$(document).on('change', '.num_occupancy', function(e) {
-
+ let elementVal = parseInt($(this).val());
let current_room_occupancy = 0;
$(this).closest('.occupancy_info_block').find('.num_occupancy').each(function(){
current_room_occupancy += parseInt($(this).val());
});
let max_guests_in_room = $(this).closest(".booking_occupancy_wrapper").find('.max_guests').val();
let max_allowed_for_current = (max_guests_in_room - current_room_occupancy) + parseInt($(this).val());
- if ($(this).val() > $(this).attr('max')) {
- $(this).val($(this).attr('max'));
- }
- if ($(this).val() > max_allowed_for_current) {
- $(this).val(max_allowed_for_current);
- }
-
+ let haserror = false
if ($(this).hasClass('num_children')) {
- let totalChilds = $(this).closest('.occupancy_info_block').find('.guest_child_age').length;
- if (totalChilds < $(this).val()) {
- $(this).closest('.occupancy_info_block').find('.children_age_info_block').show();
- while ($(this).closest('.occupancy_info_block').find('.guest_child_age').length < $(this).val()) {
- var roomBlockIndex = parseInt($(this).closest('.occupancy_info_block').attr('occ_block_index'));
- var childAgeSelect = '
';
- childAgeSelect += '';
- childAgeSelect += '
';
- $(this).closest('.occupancy_info_block').find('.children_ages').append(childAgeSelect);
+ max_child_in_room = $(this).closest(".booking_occupancy_wrapper").find('.max_children').val();
+ if (elementVal > max_child_in_room) {
+ $(this).val(max_child_in_room);
+ if (elementVal == 1) {
+ showOccupancyError(no_children_allowed_txt, $(this).closest(".occupancy_info_block"));
+ haserror = true;
+ } else {
+ showOccupancyError(max_children_txt, $(this).closest(".occupancy_info_block"));
+ haserror = true;
}
- } else {
- let child = $(this).val();
- $(this).closest('.occupancy_info_block').find('.guest_child_age').each(function(ind, element) {
- if (child <= ind) {
- $(element).parent().remove();
- }
- });
- if (child == 0) {
- $(this).closest('.occupancy_info_block').find('.children_age_info_block').hide();
- }
-
+ } else if (elementVal > max_allowed_for_current) {
+ $(this).val(max_allowed_for_current);
+ showOccupancyError(max_occupancy_reached_txt, $(this).closest(".occupancy_info_block"));
+ haserror = true;
+ }
+ } else {
+ max_adults_in_room = $(this).closest(".booking_occupancy_wrapper").find('.max_adults').val();
+ if (elementVal >= max_adults_in_room) {
+ $(this).val(max_adults_in_room);
+ showOccupancyError(max_adults_txt, $(this).closest(".occupancy_info_block"));
+ haserror = true;
+ } else if (elementVal > max_allowed_for_current) {
+ $(this).val(max_allowed_for_current);
+ showOccupancyError(max_occupancy_reached_txt, $(this).closest(".occupancy_info_block"));
+ haserror = true;
}
}
- setRoomTypeGuestOccupancy($(this).closest('.booking_occupancy_wrapper'));
+ if (!haserror) {
+ if ($(this).hasClass('num_children')) {
+ let totalChilds = $(this).closest('.occupancy_info_block').find('.guest_child_age').length;
+ if (totalChilds < $(this).val()) {
+ $(this).closest('.occupancy_info_block').find('.children_age_info_block').show();
+ while ($(this).closest('.occupancy_info_block').find('.guest_child_age').length < $(this).val()) {
+ var roomBlockIndex = parseInt($(this).closest('.occupancy_info_block').attr('occ_block_index'));
+ var childAgeSelect = '
';
+ childAgeSelect += '';
+ childAgeSelect += '
';
+ $(this).closest('.occupancy_info_block').find('.children_ages').append(childAgeSelect);
+ }
+ } else {
+ let child = $(this).val();
+ $(this).closest('.occupancy_info_block').find('.guest_child_age').each(function(ind, element) {
+ if (child <= ind) {
+ $(element).parent().remove();
+ }
+ });
+ if (child == 0) {
+ $(this).closest('.occupancy_info_block').find('.children_age_info_block').hide();
+ }
+ }
+ }
+ }
+ setRoomTypeGuestOccupancy($(this).closest('.booking_occupancy_wrapper'));
});
+ var errorMsgTime;
+ $('.occupancy-input-errors').parent().hide();
+ function showOccupancyError(msg, occupancy_info_block)
+ {
+ var errorMsgBlock = $(occupancy_info_block).find('.occupancy-input-errors')
+ $(errorMsgBlock).html(msg).parent().show('fast');
+ clearTimeout(errorMsgTime);
+ errorMsgTime = setTimeout(function() {
+ $(errorMsgBlock).parent().hide('fast');
+ }, 1000);
+ }
+
+
$(document).on('click', '.booking_guest_occupancy', function(e) {
$(this).parent().toggleClass('open');
});
diff --git a/modules/hotelreservationsystem/views/templates/admin/hotel_rooms_booking/helpers/view/_partials/booking-rooms.tpl b/modules/hotelreservationsystem/views/templates/admin/hotel_rooms_booking/helpers/view/_partials/booking-rooms.tpl
index 98d231639..70bcd1cd3 100644
--- a/modules/hotelreservationsystem/views/templates/admin/hotel_rooms_booking/helpers/view/_partials/booking-rooms.tpl
+++ b/modules/hotelreservationsystem/views/templates/admin/hotel_rooms_booking/helpers/view/_partials/booking-rooms.tpl
@@ -69,14 +69,15 @@
+
+
';
occupancy_block += '