+
+
{l s='Please note that the date chosen for field \'Date To\' is not considered as a blocking date.'}
+
@@ -135,14 +200,17 @@
|
{l s='Reason'}
|
+ |
-
-
+
@@ -168,223 +236,257 @@
\ No newline at end of file
+ // delete room
+ $('.rm_htl_room').on('click',function(e) {
+ e.preventDefault();
+ var $current = $(this);
+ var id_htl_info = $(this).attr('data-id-htl-info');
+ $.ajax({
+ url: prod_link,
+ type: 'POST',
+ dataType: 'text',
+ data: {
+ ajax:true,
+ action:'deleteHotelRoom',
+ id: id_htl_info,
+ },
+ success: function (result) {
+ if (parseInt(result) == 1) {
+ showSuccessMessage("{l s='Removed successfully'}");
+ $current.closest(".room_data_values").remove();
+ } else {
+ showErrorMessage("{l s='Some error occurred'}");
+ }
+ },
+ error: function(XMLHttpRequest, textStatus, errorThrown) {
+ showErrorMessage("{l s='Some error occurred'}");
+ }
+ });
+ });
+
+ $(".checkConfigurationClick").on("click", function() {
+ $("#checkConfSubmit").val(1);
+ return true;
+ });
+
+ // remove room row
+ $(document).on('click','.remove-rooms-button',function(e) {
+ e.preventDefault();
+ $(this).closest('.room_data_values').remove();
+ $('#product-configuration table.hotel-room tr.room_data_values').each(function(iOuter, tr) {
+ $(tr).attr('data-row-index', iOuter);
+ $(tr).find('input, select').each(function (iInner, inputField) {
+ let fieldName = $(inputField).attr('name');
+ fieldName = fieldName.replace(/[0-9]+/, iOuter)
+ $(inputField).attr('name', fieldName);
+ });
+ });
+ });
+
+ // on changing the room status as disabled for some date range
+ $(document).on('change', '.room_status', function(){
+ var status_val = $(this).val();
+ if (status_val == rm_status.STATUS_TEMPORARY_INACTIVE.id) {
+ $(this).closest('.room_data_values').find('.deactiveDatesModal').removeClass('disabled');
+ } else {
+ $(this).closest('.room_data_values').find('.deactiveDatesModal').addClass('disabled');
+ }
+ });
+
+ $(document).on('focus', '.disabled_date_from, .disabled_date_to', function () {
+ $('.disabled_date_from').datepicker({
+ showOtherMonths: true,
+ dateFormat: 'yy-mm-dd',
+ minDate: 0,
+ onSelect: function(selectedDate) {
+ var date_format = selectedDate.split('-');
+ selectedDate = new Date($.datepicker.formatDate('yy-mm-dd', new Date(date_format[0], date_format[1] - 1, date_format[2])));
+ selectedDate.setDate(selectedDate.getDate() + 1);
+ $(this).closest('tr').find('.disabled_date_to').datepicker('option', 'minDate', selectedDate);
+ },
+ onClose: function(selectedDate) {
+ var dateTo = $(this).closest('tr').find('.disabled_date_to').val();
+ if (!dateTo || (dateTo && selectedDate >= dateTo)) {
+ $('.disabled_date_to').datepicker('show');
+ }
+ },
+ });
+
+ $('.disabled_date_to').datepicker({
+ showOtherMonths: true,
+ dateFormat: 'yy-mm-dd',
+ minDate: 0,
+ beforeShow: function (input, instance) {
+ var date_to = $(this).closest('tr').find('.disabled_date_from').val();
+ if (typeof date_to != 'undefined' && date_to != '') {
+ var date_format = date_to.split('-');
+ var selectedDate = new Date($.datepicker.formatDate('yy-mm-dd', new Date(date_format[0], date_format[1] - 1, date_format[2])));
+ } else {
+ var date_format = new Date();
+ var selectedDate = new Date($.datepicker.formatDate('yy-mm-dd', new Date()));
+ }
+ selectedDate.setDate(selectedDate.getDate()+1);
+ $(this).datepicker('option', 'minDate', selectedDate);
+ },
+ });
+ });
+
+ $('.add_more_room_disable_dates').on('click', function() {
+ DisableDatesModal.addNewRow();
+ });
+
+ $(document).on('click','.remove-disable-dates-button',function(e) {
+ e.preventDefault();
+ $(this).closest('tr').remove();
+ });
+ });
+
diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php
index ac8b09807..51f891e8b 100644
--- a/controllers/admin/AdminProductsController.php
+++ b/controllers/admin/AdminProductsController.php
@@ -3398,7 +3398,7 @@ class AdminProductsControllerCore extends AdminController
foreach ($hotelRoomInfo as &$room) {
if ($room['id_status'] == HotelRoomInformation::STATUS_TEMPORARY_INACTIVE) {
$disabledDates = $objRoomDisableDates->getRoomDisableDates($room['id']);
- $room['disabled_dates_json'] = json_encode($disabledDates);
+ $room['disable_dates_json'] = json_encode($disabledDates);
}
}
$data->assign('htl_room_info', $hotelRoomInfo);
@@ -3410,8 +3410,8 @@ class AdminProductsControllerCore extends AdminController
'product' => $obj,
'htl_info' => $hotelInfo,
'rm_status' => $roomStatus,
- 'datesMissing' => $this->l('Please fill all Date From and Date To'),
- 'datesOverlapping' => $this->l('Some date are conflicting with each other. Please check and reselect the date ranges.'),
+ '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 {
@@ -3487,121 +3487,88 @@ class AdminProductsControllerCore extends AdminController
}
}
- public function validateDisableDateRanges($disableDates)
+ public function validateDisableDateRanges($disableDates, $index)
{
if (count($disableDates)) {
foreach ($disableDates as $disable_key => $disableDate) {
if (!$disableDate['date_to'] && !$disableDate['date_from']) {
unset($disableDates[$disable_key]);
} elseif (!Validate::isDate($disableDate['date_from']) || !Validate::isDate($disableDate['date_to'])) {
- $this->errors[] = Tools::displayError('Please fill valid date in disable date fields.');
+ $this->errors[] = sprintf(
+ Tools::displayError('Please add valid disable dates for %s room.'),
+ $index
+ );
} elseif (($disableDate['date_from'] && !$disableDate['date_to']) || (!$disableDate['date_from'] && $disableDate['date_to'])) {
- $this->errors[] = Tools::displayError('Please fill all date from and date to for disable dates fields.');
+ $this->errors[] = sprintf(
+ Tools::displayError('Please fill date from and date to for disable dates for %s room.'),
+ $index
+ );
} else {
foreach ($disableDates as $key => $disDate) {
if ($key != $disable_key) {
if ((($disableDate['date_from'] < $disDate['date_from']) && ($disableDate['date_to'] <= $disDate['date_from'])) || (($disableDate['date_from'] > $disDate['date_from']) && ($disableDate['date_from'] >= $disDate['date_to']))) {
// continue
} else {
- $this->errors[] = Tools::displayError('Some date are conflicting with each other. Please check and reselect the date ranges.');
+ $this->errors[] = sprintf(
+ Tools::displayError('Disable dates are conflicting for %s room. Please add non-conflicting dates.'),
+ $index
+ );
}
}
}
}
}
} else {
- $this->errors[] = Tools::displayError('Please add dates for status temporary inactive.');
+ $this->errors[] = sprintf(Tools::displayError('Please add disable dates for %s room.'), $index);
}
}
public function processConfiguration()
{
- /*Check if save of configuration tab is submitted*/
+ // Check if save of configuration tab is submitted
if (Tools::getValue('checkConfSubmit')) {
- // htl_room_type id field use only in edit case
- $wk_id_room_type = Tools::getValue('wk_id_room_type');
-
- $id_product = Tools::getValue('id_product'); //room type
+ $id_product = Tools::getValue('id_product');
$id_hotel = Tools::getValue('id_hotel');
if (!$id_product || !Validate::isUnsignedInt($id_product)) {
- $this->errors[] = Tools::displayError('There is some problem while setting room information');
+ $this->errors[] = Tools::displayError('There is some problem while setting room information.');
}
if (!$id_hotel || !Validate::isUnsignedInt($id_hotel)) {
- $this->errors[] = Tools::displayError('Please select a hotel');
+ $this->errors[] = Tools::displayError('Please select a hotel.');
}
+
+ $this->validateConfigurationPostData();
if (!count($this->errors)) {
- $room_numbers = Tools::getValue('room_num');
- if ($room_numbers) {
- $room_floor = Tools::getValue('room_floor');
- $room_comment = Tools::getValue('room_comment');
- $disable_dates = Tools::getValue('disableDatesJSON');
- $room_status = Tools::getValue('room_status');
+ $roomsInfo = Tools::getValue('rooms_info');
+ if (is_array($roomsInfo) && count($roomsInfo)) {
+ foreach ($roomsInfo as $roomInfo) {
+ $objHotelRoomInfo = null;
+ if (isset($roomInfo['id']) && $roomInfo['id']) {
+ $objHotelRoomInfo = new HotelRoomInformation($roomInfo['id']);
+ } else {
+ $objHotelRoomInfo = new HotelRoomInformation();
+ }
+ $objHotelRoomInfo->id_product = $id_product;
+ $objHotelRoomInfo->id_hotel = $id_hotel;
+ $objHotelRoomInfo->room_num = $roomInfo['room_num'];
+ $objHotelRoomInfo->id_status = $roomInfo['id_status'];
+ $objHotelRoomInfo->floor = $roomInfo['floor'];
+ $objHotelRoomInfo->comment = $roomInfo['comment'];
+ if ($objHotelRoomInfo->save()) {
+ $idRoom = $objHotelRoomInfo->id;
+ if ($roomInfo['id_status'] == HotelRoomInformation::STATUS_TEMPORARY_INACTIVE) {
+ $hRDisableDates = new HotelRoomDisableDates();
+ $hRDisableDates->deleteRoomDisableDates($idRoom);
- if (count($room_numbers) != count($room_status)) {
- $this->errors[] = Tools::displayError('There is some problem while setting room information');
- } else {
- //validate room number
- foreach ($room_numbers as $roomNum) {
- if (!$roomNum || !Validate::isGenericName($roomNum)) {
- $this->errors[] = Tools::displayError('Invalid room number entered. please enter a valid room number.');
- }
- }
- //validate room status
- $disableDtsArr = array();
- foreach ($room_status as $key => $status) {
- if ($status == HotelRoomInformation::STATUS_TEMPORARY_INACTIVE) {
- $disableDtsArr[$key] = json_decode($disable_dates[$key], true);
- $this->validateDisableDateRanges($disableDtsArr[$key]);
- }
- }
- }
- if (!count($this->errors)) {
- if ($wk_id_room_type) {
- $objRoomType = new HotelRoomType($wk_id_room_type);
- $id_hotel = $objRoomType->id_hotel;
- }
-
- // Associate categories to Room Type
- $id_room_info = Tools::getValue('id_room_info');
- $objCartBookingData = new HotelCartBookingData();
- foreach ($room_numbers as $key => $value) {
- if ($value) {
- if ($id_room_info) {
- if ($key <= (count($id_room_info) - 1)) {
- $objRoomInfo = new HotelRoomInformation($id_room_info[$key]);
- } else {
- //if any new room is added at the time of edit
- $objRoomInfo = new HotelRoomInformation();
- $objRoomInfo->id_product = $id_product;
- $objRoomInfo->id_hotel = $id_hotel;
- }
- } else {
- $objRoomInfo = new HotelRoomInformation();
- $objRoomInfo->id_product = $id_product;
- $objRoomInfo->id_hotel = $id_hotel;
- }
- $objRoomInfo->room_num = $value;
- $objRoomInfo->id_status = $room_status[$key];
- $objRoomInfo->floor = $room_floor[$key];
- $objRoomInfo->comment = $room_comment[$key];
- if ($objRoomInfo->save()) {
- if ($room_status[$key] == HotelRoomInformation::STATUS_TEMPORARY_INACTIVE) {
- $objDisDts = new HotelRoomDisableDates();
- $objDisDts->deleteRoomDisableDates($objRoomInfo->id);
- if (isset($disableDtsArr[$key]) && $disableDtsArr[$key]) {
- // delete privious save dats
- foreach ($disableDtsArr[$key] as $disDtRange) {
- $objDisDts = new HotelRoomDisableDates();
- $objDisDts->id_room_type = $id_product;
- $objDisDts->id_room = $objRoomInfo->id;
- $objDisDts->date_from = $disDtRange['date_from'];
- $objDisDts->date_to = $disDtRange['date_to'];
- $objDisDts->reason = $disDtRange['reason'];
- $objDisDts->add();
- }
- }
- }
+ $disableDates = json_decode($roomInfo['disable_dates_json'], true);
+ foreach ($disableDates as $disableDate) {
+ $hRDisableDates = new HotelRoomDisableDates();
+ $hRDisableDates->id_room_type = $id_product;
+ $hRDisableDates->id_room = $idRoom;
+ $hRDisableDates->date_from = $disableDate['date_from'];
+ $hRDisableDates->date_to = $disableDate['date_to'];
+ $hRDisableDates->reason = $disableDate['reason'];
+ $hRDisableDates->add();
}
}
}
@@ -3611,6 +3578,49 @@ class AdminProductsControllerCore extends AdminController
}
}
+ public function validateConfigurationPostData()
+ {
+ $roomsInfo = Tools::getValue('rooms_info');
+ if (is_array($roomsInfo) && count($roomsInfo)) {
+ foreach ($roomsInfo as $key => $roomInfo) {
+ if (!$roomInfo['room_num']) {
+ unset($_POST['rooms_info'][$key]);
+ }
+ }
+ }
+
+ $roomsInfo = Tools::getValue('rooms_info'); // since $_POST['rooms_info'] has changed
+ if (is_array($roomsInfo) && count($roomsInfo)) {
+ $formatter = new NumberFormatter($this->context->language->language_code, NumberFormatter::ORDINAL);
+ foreach ($roomsInfo as $key => $roomInfo) {
+ $index = $formatter->format($key + 1);
+
+ if ($roomInfo['id_status'] == HotelRoomInformation::STATUS_TEMPORARY_INACTIVE) {
+ if ($roomInfo['disable_dates_json'] === 0) {
+ $this->errors[] = sprintf(Tools::displayError('Please add disable dates for %s room.'), $index);
+ }
+ }
+
+ if ($roomInfo['room_num'] && !Validate::isGenericName($roomInfo['room_num'])) {
+ $this->errors[] = sprintf(Tools::displayError('Invalid room number for %s room.'), $index);
+ }
+
+ if ($roomInfo['floor'] && !Validate::isGenericName($roomInfo['floor'])) {
+ $this->errors[] = sprintf(Tools::displayError('Invalid floor for %s room.'), $index);
+ }
+
+ if ($roomInfo['id_status'] == HotelRoomInformation::STATUS_TEMPORARY_INACTIVE) {
+ $disableDates = json_decode($roomInfo['disable_dates_json'], true);
+ if ($roomInfo['disable_dates_json'] !== 0) {
+ $this->validateDisableDateRanges($disableDates, $index);
+ }
+ }
+ }
+ } else {
+ $this->errors[] = Tools::displayError('Please add at least one room.');
+ }
+ }
+
public function ajaxProcessDeleteHotelRoom()
{
if ($this->tabAccess['edit'] == 1) {