diff --git a/admin/themes/default/template/controllers/orders/_current_cart_details_data.tpl b/admin/themes/default/template/controllers/orders/_current_cart_details_data.tpl index 214705745..fb6f389c2 100644 --- a/admin/themes/default/template/controllers/orders/_current_cart_details_data.tpl +++ b/admin/themes/default/template/controllers/orders/_current_cart_details_data.tpl @@ -71,17 +71,18 @@
- +
- + ({l s='Below'} {$max_child_age|escape:'htmlall':'UTF-8'} {l s='years'})
+

diff --git a/admin/themes/default/template/controllers/orders/_new_product.tpl b/admin/themes/default/template/controllers/orders/_new_product.tpl index 4082199eb..423f2af17 100644 --- a/admin/themes/default/template/controllers/orders/_new_product.tpl +++ b/admin/themes/default/template/controllers/orders/_new_product.tpl @@ -88,6 +88,7 @@ ({l s='Below'} {$max_child_age|escape:'htmlall':'UTF-8'} {l s='years'})
+

+

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 = '

'; childAgeSelect += ''; - childAgeSelect += ''; - childAgeSelect += ''; - for (let age = 1; age < max_child_age; age++) { - 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 @@
- +
- + ({l s='Below' mod='hotelreservationsystem'} {$max_child_age|escape:'htmlall':'UTF-8'} {l s='years' mod='hotelreservationsystem'})
+

+

diff --git a/themes/hotel-reservation-theme/css/occupancy.css b/themes/hotel-reservation-theme/css/occupancy.css index 37e510c0a..ece8ddeae 100644 --- a/themes/hotel-reservation-theme/css/occupancy.css +++ b/themes/hotel-reservation-theme/css/occupancy.css @@ -30,6 +30,8 @@ margin-top: 15px; margin-right: -20px; margin-left: -20px;} + .booking_occupancy_wrapper .occupancy-input-errors { + font-weight: 700;} .booking_occupancy_wrapper .children_age_info_block { display: none;} .booking_occupancy_wrapper .children_age_info_block label { diff --git a/themes/hotel-reservation-theme/global.tpl b/themes/hotel-reservation-theme/global.tpl index b9576d43d..5fb5d0025 100644 --- a/themes/hotel-reservation-theme/global.tpl +++ b/themes/hotel-reservation-theme/global.tpl @@ -62,6 +62,10 @@ {addJsDef max_child_age=$max_child_age} {addJsDef max_child_in_room=$max_child_in_room} +{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='select_occupancy_txt'}{l s='Select Occupancy' js=1}{/addJsDefL} {addJsDefL name='select_age_txt'}{l s='Select age' js=1}{/addJsDefL} {addJsDefL name='under_1_age'}{l s='Under 1' js=1}{/addJsDefL} diff --git a/themes/hotel-reservation-theme/js/occupancy.js b/themes/hotel-reservation-theme/js/occupancy.js index c3cf72eed..7aba90111 100644 --- a/themes/hotel-reservation-theme/js/occupancy.js +++ b/themes/hotel-reservation-theme/js/occupancy.js @@ -78,6 +78,16 @@ $(document).ready(function(){ // set input field value $(this).closest('.occupancy_count_block').find('.occupancy_count > span').text(elementVal + 1); + } else { + if (elementVal >= max_child_in_room) { + if (elementVal == 0) { + showOccupancyError(no_children_allowed_txt, $(this).closest(".occupancy_info_block")); + } else { + showOccupancyError(max_children_txt, $(this).closest(".occupancy_info_block")); + } + } else { + showOccupancyError(max_occupancy_reached_txt, $(this).closest(".occupancy_info_block")); + } } } else { let max_adults_in_room; @@ -87,11 +97,30 @@ $(document).ready(function(){ if (elementVal < max_adults_in_room && elementVal < max_allowed_for_current) { element.val(elementVal + 1); $(this).closest('.occupancy_count_block').find('.occupancy_count > span').text(elementVal + 1); + } else { + if (elementVal >= max_adults_in_room) { + showOccupancyError(max_adults_txt, $(this).closest(".occupancy_info_block")); + } else { + showOccupancyError(max_occupancy_reached_txt, $(this).closest(".occupancy_info_block")); + } } } 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_occupancy_wrapper .occupancy_quantity_down', function(e) { e.preventDefault(); @@ -247,6 +276,7 @@ $(document).ready(function(){ occupancy_block += '
'; occupancy_block += '
'; occupancy_block += '
'; + occupancy_block += '

'; occupancy_block += '
'; occupancy_block += ''; occupancy_block += '
';