diff --git a/admin/themes/default/template/controllers/products/configuration.tpl b/admin/themes/default/template/controllers/products/configuration.tpl index 20ed659b5..e7192e47b 100644 --- a/admin/themes/default/template/controllers/products/configuration.tpl +++ b/admin/themes/default/template/controllers/products/configuration.tpl @@ -120,7 +120,7 @@ {if isset($room_info['id'])} @@ -661,44 +661,55 @@ {/literal} // Add new room detail - $('#add-more-rooms-button').on('click',function() { - var lengthRooms = parseInt($('.room_data_values').length); + $('#add-more-rooms-button').on('click', function() { + var lengthRooms = parseInt($('.room_data_values').length); - var prefix = 'rooms_info['+lengthRooms+']'; - html = ''; + var prefix = 'rooms_info[' + lengthRooms + ']'; + html = ''; html += ''; - html += ''; + html += ''; html += ''; html += ''; - html += ''; + html += ''; html += ''; html += ''; - html += ''; + html += ''; html += ''; html += ''; - html += ''; + html += ''; html += ''; html += ''; - html += ''; + html += ''; html += ''; html += ''; - html += ''; - html += "{l s='Add Dates'}"; - html += ''; - html += ''; + html += + ''; + html += "{l s='Add Dates'}"; + html += ''; + html += ''; + html += ''; + html += ''; + html += ''; + html += ''; + html += ''; + html += '0'; + html += ''; + html += ''; html += ''; html += '{hook h='displayHotelRoomListTableRowColumn'}'; html += ''; - html += ''; + html += + ''; html += ''; - html += ''; + html += ''; - $('table.hotel-room tbody').append(html); - }); + $('table.hotel-room tbody').append(html); + }); // delete room $('.rm_htl_room').on('click',function(e) { @@ -714,13 +725,26 @@ action:'deleteHotelRoom', id: id_htl_info, }, - success: function (response) { + success: function(response) { if (response.success) { showSuccessMessage("{l s='Removed successfully'}"); $current.closest(".room_data_values").remove(); + if (response.affected_rooms && response.affected_rooms.length) { + $.each(response.affected_rooms, function(i, roomId) { + var $badge = $( + '.connectedRoomModal[data-id-room="' + + roomId + '"] .connected-room-count'); + if ($badge.length) { + var count = parseInt($badge.text().trim()); + if (count > 0) { + $badge.text(count - 1); + } + } + }); + } } else { if (response.errors) - showErrorMessage(response.errors); + showErrorMessage(response.errors); } }, error: function(XMLHttpRequest, textStatus, errorThrown) { @@ -1935,7 +1959,6 @@ e.preventDefault(); let roomId = $(this).data('id-room'); - let hotelId = $(this).data('id-hotel'); let roomNum = $(this).data('room-num'); let currentRoomType = $('[name="id_product"]').val(); $.ajax({ @@ -1946,7 +1969,6 @@ ajax: true, action: 'getModalConnectedRooms', room_id: roomId, - hotel_id: hotelId, current_roomtype: currentRoomType, }, success: function(response) { @@ -2051,7 +2073,6 @@ var $row = $(this).closest('tr'); var mainRoomId = $('#connected_room_main_id').val(); var connectedRoomId = $row.find('.connect-room').val(); - var hotelId = $('#hotel_id').val(); let currentRoomType = $('[name="id_product"]').val(); if (!connectedRoomId) { alert(selectRoomText); @@ -2065,7 +2086,6 @@ ajax: true, action: 'ManageConnectedRoom', mode: 'add', - hotel_id: hotelId, room_id: mainRoomId, connected_room_id: connectedRoomId, current_roomtype: currentRoomType, @@ -2109,7 +2129,6 @@ var mainRoomId = $('#connected_room_main_id').val(); var connectedRoomId = $(this).data('connected-room-id'); var connectedId = $(this).data('connected-id'); - var hotelId = $(this).data('hotel-id'); let currentRoomType = $('[name="id_product"]').val(); $.ajax({ url: prod_link, @@ -2122,7 +2141,6 @@ room_id: mainRoomId, connected_room_id: connectedRoomId, connected_id: connectedId, - hotel_id: hotelId, current_roomtype: currentRoomType, }, success: function(response) { diff --git a/admin/themes/default/template/controllers/products/modal-connected-rooms.tpl b/admin/themes/default/template/controllers/products/modal-connected-rooms.tpl index 5a92ed178..ea505ec4b 100644 --- a/admin/themes/default/template/controllers/products/modal-connected-rooms.tpl +++ b/admin/themes/default/template/controllers/products/modal-connected-rooms.tpl @@ -100,7 +100,7 @@ data-connected-id="{$row.id_connected_room|intval}" data-room-id="{$row.id_room_information|intval}" data-connected-room-id="{$row.id_room|intval}" - data-hotel-id="{$row.id_hotel|intval}" title="{l s='Remove'}"> + title="{l s='Remove'}"> @@ -183,5 +183,4 @@ - \ No newline at end of file diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php index cbcd46fd5..7025a9e79 100644 --- a/controllers/admin/AdminProductsController.php +++ b/controllers/admin/AdminProductsController.php @@ -3726,6 +3726,7 @@ class AdminProductsControllerCore extends AdminController $this->errors[] = $this->l('This room cannot be deleted as this room contains future booking.'); } if (empty($this->errors)) { + $response['affected_rooms'] = HotelConnectedRoom::getRoomConnectedWith($idRoom); if ($objRoomInfo->delete()) { $response['success'] = true; } else { @@ -5707,8 +5708,8 @@ class AdminProductsControllerCore extends AdminController ])); } - $objHotelRoomConnected = new HotelConnectedRoom($connectedId); - if ($objHotelRoomConnected->delete()) { + $objHotelConnectedRoom = new HotelConnectedRoom($connectedId); + if ($objHotelConnectedRoom->delete()) { $modalContent = $this->getConnectedRoomsModalHtml($roomId, $currentRoomType); die(json_encode([ 'success' => true, diff --git a/modules/hotelreservationsystem/classes/HotelConnectedRoom.php b/modules/hotelreservationsystem/classes/HotelConnectedRoom.php index 06150c251..ccdf75f61 100644 --- a/modules/hotelreservationsystem/classes/HotelConnectedRoom.php +++ b/modules/hotelreservationsystem/classes/HotelConnectedRoom.php @@ -97,4 +97,25 @@ class HotelConnectedRoom extends ObjectModel return ($results === false) ? array() : $results; } } + + public static function getRoomConnectedWith($roomId) + { + $objHotelRoomInformation = new HotelRoomInformation($roomId); + $idProduct = $objHotelRoomInformation->id_product; + if (!$idProduct) { + return array(); + } + $sql = 'SELECT DISTINCT case + WHEN hcr.id_room = ' . (int) $roomId . ' THEN hcr.id_room_connected + ELSE hcr.id_room + END AS affected_room_id + FROM `' . _DB_PREFIX_ . 'htl_connected_room` hcr + INNER JOIN `' . _DB_PREFIX_ . 'htl_room_information` hri + ON (hri.id = hcr.id_room OR hri.id = hcr.id_room_connected) + WHERE (hcr.id_room = ' . (int) $roomId . ' OR hcr.id_room_connected = ' . (int) $roomId . ') + AND hri.id != ' . (int) $roomId . ' + AND hri.id_product = ' . (int) $idProduct; + $results = Db::getInstance()->executeS($sql); + return $results ? array_column($results, 'affected_room_id') : array(); + } }