diff --git a/admin/themes/default/template/controllers/products/booked_room_date_ranges_list.tpl b/admin/themes/default/template/controllers/products/booked_room_date_ranges_list.tpl new file mode 100644 index 000000000..1f5623253 --- /dev/null +++ b/admin/themes/default/template/controllers/products/booked_room_date_ranges_list.tpl @@ -0,0 +1,25 @@ +{** +* 2010-2023 Webkul. +* +* NOTICE OF LICENSE +* +* All right is reserved, +* Please go through LICENSE.txt file inside our module +* +* DISCLAIMER +* +* Do not edit or add to this file if you wish to upgrade this module to newer +* versions in the future. If you wish to customize this module for your +* needs please refer to CustomizationPolicy.txt file inside our module for more information. +* +* @author Webkul IN +* @copyright 2010-2023 Webkul IN +* @license LICENSE.txt +*} + +{l s='This room already has bookings for highlighted date range(s). Please reselect the date ranges:'} + +{foreach from=$booked_rows_list item=booked_row} +
+ {dateFormat date=$booked_row->date_from} {l s='to'} {dateFormat date=$booked_row->date_to} - #{$booked_row->id_order|intval} +{/foreach} diff --git a/admin/themes/default/template/controllers/products/configuration.tpl b/admin/themes/default/template/controllers/products/configuration.tpl index 9372e0bf5..bbe73602b 100644 --- a/admin/themes/default/template/controllers/products/configuration.tpl +++ b/admin/themes/default/template/controllers/products/configuration.tpl @@ -240,8 +240,6 @@ var prod_link = "{$link->getAdminLink('AdminProducts')}"; var rm_status = {$rm_status|@json_encode}; var currentRoomRow = 0; - var datesMissing = "{$datesMissing}"; - var datesOverlapping = "{$datesOverlapping}"; $(document).ready(function() { const DisableDatesModal = { @@ -303,13 +301,12 @@ }); }, showErrors: function(errors) { - $('#deactiveDatesModal .errors-wrap').stop().html(errors); - $('#deactiveDatesModal .errors-wrap').show(200); + $('#deactiveDatesModal .errors-wrap').html(errors); + $('#deactiveDatesModal .errors-wrap').show(); }, hideErrors: function() { - $('#deactiveDatesModal .errors-wrap').hide(200, function() { - $('#deactiveDatesModal .errors-wrap').html(''); - }); + $('#deactiveDatesModal .errors-wrap').hide(); + $('#deactiveDatesModal .errors-wrap').html(''); }, addInvalidRowDataMarkers: function(rowsToHighlight) { rowsToHighlight.map(function (rowIndex) { @@ -380,9 +377,19 @@ } disableDates = JSON.parse(disableDates); + DisableDatesModal.hideErrors(); DisableDatesModal.populateWithDatesInfo(disableDates); }); + // Disable dates data filling when model open + $('#deactiveDatesModal').on('hide.bs.modal', function(e) { + const disableDates = DisableDatesModal.getDisableDatesInfo(); + console.log(disableDates); + const roomRowIndex = parseInt($('#deactiveDatesModal table.room-disable-dates').attr('data-room-row-index')); + const roomRow = $('#product-configuration .hotel-room tr.room_data_values[data-row-index='+roomRowIndex+']'); + $(roomRow).find('.disable_dates_json').val(JSON.stringify(disableDates)); + }); + // copy json formatted dates to room $(document).on('click', '.deactiveDatesModalSubmit', function() { DisableDatesModal.validateDisableDates(function () { diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php index e9e8a3af7..0afcd844c 100644 --- a/controllers/admin/AdminProductsController.php +++ b/controllers/admin/AdminProductsController.php @@ -2779,8 +2779,6 @@ class AdminProductsControllerCore extends AdminController 'product' => $obj, 'htl_info' => $hotelInfo, 'rm_status' => $roomStatus, - 'datesMissing' => $this->l('Some dates are missing. Please select all the date ranges.'), - 'datesOverlapping' => $this->l('Some dates are conflicting with each other. Please check and reselect the date ranges.'), ) ); } else { @@ -4640,6 +4638,7 @@ class AdminProductsControllerCore extends AdminController $disableDates = Tools::getValue('disable_dates'); $rowsToHighlight = array(); + $bookedRows = array(); if (is_array($disableDates) && count($disableDates)) { foreach ($disableDates as $key => $dateRange) { if (!Validate::isDate($dateRange['date_from']) || !Validate::isDate($dateRange['date_to'])) { @@ -4652,8 +4651,8 @@ class AdminProductsControllerCore extends AdminController foreach ($disableDates as $keyOuter => $dateRangeOuter) { foreach ($disableDates as $keyInner => $dateRangeInner) { if ($keyInner != $keyOuter) { - if ((strtotime($dateRangeOuter['date_from']) <= strtotime($dateRangeInner['date_to'])) - && (strtotime($dateRangeInner['date_from']) <= strtotime($dateRangeOuter['date_to'])) + if ((($dateRangeOuter['date_from'] >= $dateRangeInner['date_from']) && ($dateRangeOuter['date_from'] < $dateRangeInner['date_to'])) + || (($dateRangeInner['date_from'] >= $dateRangeOuter['date_from']) && ($dateRangeInner['date_from'] < $dateRangeOuter['date_to'])) ) { $this->errors[] = $this->l('Some dates are conflicting with each other. Please check and reselect the date ranges.'); $rowsToHighlight[] = $keyOuter; @@ -4668,8 +4667,8 @@ class AdminProductsControllerCore extends AdminController if ($idRoom) { $objHotelBookingDetail = new HotelBookingDetail(); foreach ($disableDates as $key => $dateRange) { - if ($objHotelBookingDetail->chechRoomBooked($idRoom, $dateRange['date_from'], $dateRange['date_to'])) { - $this->errors[] = $this->l('This room has been booked for highlighted date range(s). Please reselect the date ranges.'); + if ($bookingRow = $objHotelBookingDetail->chechRoomBooked($idRoom, $dateRange['date_from'], $dateRange['date_to'])) { + $bookedRows[] = new HotelBookingDetail($bookingRow['id']); $rowsToHighlight[] = $key; } } @@ -4677,8 +4676,17 @@ class AdminProductsControllerCore extends AdminController } } + if (count($bookedRows)) { + $this->context->smarty->assign(array( + 'link' => $this->context->link, + 'booked_rows_list' => $bookedRows, + )); + + $this->errors[] = $this->context->smarty->fetch('controllers/products/booked_room_date_ranges_list.tpl'); + } + $this->errors = array_unique($this->errors); - $rowsToHighlight = array_unique($rowsToHighlight); + $rowsToHighlight = array_values(array_unique($rowsToHighlight)); if (!count($this->errors)) { $response['status'] = true; diff --git a/modules/hotelreservationsystem/classes/HotelBookingDetail.php b/modules/hotelreservationsystem/classes/HotelBookingDetail.php index 1a459053b..09ec0a525 100644 --- a/modules/hotelreservationsystem/classes/HotelBookingDetail.php +++ b/modules/hotelreservationsystem/classes/HotelBookingDetail.php @@ -1254,7 +1254,7 @@ class HotelBookingDetail extends ObjectModel // This function algo is same as available rooms algo and it not similar to booked rooms algo. public function chechRoomBooked($id_room, $date_from, $date_to) { - $sql = 'SELECT `id_product`, `id_order`, `id_cart`, `id_room`, `id_hotel`, `id_customer` + $sql = 'SELECT `id`, `id_product`, `id_order`, `id_cart`, `id_room`, `id_hotel`, `id_customer` FROM `'._DB_PREFIX_.'htl_booking_detail` WHERE `id_room` = '.(int)$id_room. ' AND `is_back_order` = 0 AND `is_refunded` = 0 AND ((date_from <= \''.pSQL($date_from).'\' AND date_to > \''. pSQL($date_from).'\' AND date_to <= \''.pSQL($date_to).'\') OR (date_from > \''.pSQL($date_from).