Improve room management: introduce connected rooms in Back Office

This commit is contained in:
azhar bhat
2026-02-17 15:33:31 +05:30
parent a27e55c049
commit 48e08bed87
12 changed files with 501 additions and 3 deletions

View File

@@ -51,7 +51,11 @@
{assign var=curr_id value=$cart->id_currency|intval}
{foreach from=$cart_detail_data item=data}
<tr data-id-booking-data="{$data.id}" data-id-product="{$data.id_product}" data-id-room="{$data.id_room}" data-date-from="{$data.date_from}" data-date-to="{$data.date_to}" >
<td>{$data.room_num|escape:'html':'UTF-8'} {hook h='displayRoomNumAfter' data=$data type='adminOrder'}</td>
<td>{$data.room_num|escape:'html':'UTF-8'}
{if isset($data['connected_rooms'][$data['id_room']]) && $data['connected_rooms'][$data['id_room']]|@count > 0}
{include file="controllers/products/connected-rooms.tpl" htl_connected_rooms= $data['connected_rooms'][$data['id_room']]}
{/if}
{hook h='displayRoomNumAfter' data=$data type='adminOrder'}</td>
<td><img src="{$data.image_link|escape:'html':'UTF-8'}" title="Room image" /></td>
<td>
<p>{$data.room_type|escape:'html':'UTF-8'}</p>

View File

@@ -29,6 +29,9 @@
{if $data.is_back_order}
<span class="overbooked_room">{l s='overbooked'}</span>
{/if}
{if isset($data['connected_rooms'][$data['id_room']]) && $data['connected_rooms'][$data['id_room']]|@count > 0}
{include file="controllers/products/connected-rooms.tpl" htl_connected_rooms=$data['connected_rooms'][$data['id_room']]}
{/if}
</td>
<td><img src="{$data.image_link}" title="{l s='Room image'}"></td>
<td>

View File

@@ -67,6 +67,14 @@
</span>
</label>
</th>
<th class="col-sm-1 center">
<label class="control-label">
<span class="label-tooltip" data-toggle="tooltip"
data-original-title="{l s='Manage connected rooms for this room'}">
{l s='Connected Rooms'}
</span>
</label>
</th>
{hook h='displayHotelRoomListTableHeaderColumn'}
<th class="col-sm-1 center">
{l s='--'}
@@ -108,6 +116,16 @@
<input type="hidden" class="form-control disable_dates_json" name="{$var_name_room_info|cat:'[disable_dates_json]'}" {if $room_info['id_status'] == $rm_status['STATUS_TEMPORARY_INACTIVE']['id']}value="{$room_info['disable_dates_json']|escape:'html':'UTF-8'}"{/if}>
</td>
{* Since the data can also be used from post incase of errors, which will cause issues with the id index *}
<td class="col-sm-1 center">
{if isset($room_info['id'])}
<a href="#" class="btn btn-default connectedRoomModal" data-toggle="modal"
data-target="#connectedRoomModal" data-id-room="{$room_info['id']}"
data-id-hotel="{$room_info['id_hotel']}" data-room-num="{$room_info['room_num']}"
data-room-type="{$room_info['id_product']}">
<i class="icon-random"></i>
</a>
{/if}
</td>
{if isset($room_info['id'])}
{hook h='displayHotelRoomListTableRowColumn' index=$key id_room=$room_info['id']}
{else}
@@ -1885,6 +1903,141 @@
return false;
}
}
//connected modal
$(document).on('click', '.connectedRoomModal', function(e) {
e.preventDefault();
let roomId = $(this).data('id-room');
let hotelId = $(this).data('id-hotel');
let currentRoomType = $('[name="id_product"]').val();
$.ajax({
type: 'POST',
url: prod_link,
dataType: 'json',
data: {
ajax: true,
action: 'getModalConnectedRooms',
room_id: roomId,
hotel_id: hotelId,
current_roomtype: currentRoomType,
},
success: function(response) {
$('#modalLoader').remove();
if (response.success) {
if ($('#connectedRoomModal').length) {
$('#connectedRoomModal').modal('hide');
$('#connectedRoomModal').data('bs.modal', null);
$('#connectedRoomModal').remove();
}
$('.modal-backdrop').remove();
$('body').removeClass('modal-open');
$("#footer").next(".bootstrap").append(response.html);
$('#connectedRoomModal').modal({
backdrop: 'static',
keyboard: true
});
} else {
alert(response.message);
}
}
});
});
function filterRoomsByType() {
var selectedType = $('#connect_room_type').val();
var firstVisible = null;
$('#connect_room option').each(function() {
if ($(this).data('type') == selectedType) {
$(this).show();
if (!firstVisible) firstVisible = $(this);
} else {
$(this).hide();
}
});
if (firstVisible) {
firstVisible.prop('selected', true);
}
}
$(document).on('change', '#connect_room_type', function() {
filterRoomsByType();
});
$(document).on('shown.bs.modal', '#connectedRoomModal', function() {
filterRoomsByType();
});
//add connected room
$(document).on('click', '#save_connected_room', function() {
var mainRoomId = $('#connected_room_main_id').val();
var connectedRoomId = $('#connect_room').val();
var hotelId = $('#hotel_id').val();
let currentRoomType = $('[name="id_product"]').val();
if (!connectedRoomId) {
alert('Please select a room');
return;
}
$.ajax({
url: prod_link,
type: 'POST',
dataType: 'json',
data: {
ajax: true,
action: 'ManageConnectedRoom',
mode: 'add',
hotel_id: hotelId,
room_id: mainRoomId,
connected_room_id: connectedRoomId,
current_roomtype: currentRoomType,
},
beforeSend: function() {
$('#save_connected_room').prop('disabled', true);
},
success: function(response) {
if (response.success) {
showSuccessMessage(response.message);
$('#connectedRoomModal .modal-content').replaceWith($(response.html).find('.modal-content'));
filterRoomsByType();
} else {
alert(response.message);
}
},
complete: function() {
$('#save_connected_room').prop('disabled', false);
}
});
});
//remove connected room
$(document).on('click', '.delete-connected-room', function() {
var roomId = $(this).data('room-id');
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,
type: 'POST',
dataType: 'json',
data: {
ajax: true,
action: 'ManageConnectedRoom',
mode: 'delete',
room_id: roomId,
connected_room_id: connectedRoomId,
connected_id: connectedId,
hotel_id: hotelId,
current_roomtype: currentRoomType,
},
success: function(response) {
if (response.success) {
showSuccessMessage(response.message);
$('#connectedRoomModal .modal-content').replaceWith($(response.html).find(
'.modal-content'));
filterRoomsByType();
} else {
alert(response.message);
}
}
});
});
});
</script>

View File

@@ -0,0 +1,87 @@
{**
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License version 3.0
* that is bundled with this package in the file LICENSE.md
* It is also available through the world-wide-web at this URL:
* https://opensource.org/license/osl-3-0-php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to support@qloapps.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to a newer
* versions in the future. If you wish to customize this module for your needs
* please refer to https://store.webkul.com/customisation-guidelines for more information.
*
* @author Webkul IN
* @copyright Since 2010 Webkul
* @license https://opensource.org/license/osl-3-0-php Open Software License version 3.0
*}
{if isset($htl_connected_rooms) && $htl_connected_rooms|@count > 0}
<span class="connected-room-popup-wrapper">
<i class="icon-random connected-room-icon"></i>
<div class="connected-room-popup">
<div class="popup-title">{l s='Connected Rooms'}</div>
<div class="popup-content">
{foreach from=$htl_connected_rooms key=conn_type item=rooms_by_type}
<div class="connected-room-type"> {$conn_type|escape:'html':'UTF-8'}</div>
<ul class="connected-room-list">
{foreach from=$rooms_by_type item=room}
<li>
{$room.connected_room_num|escape:'html':'UTF-8'}
</li>
{/foreach}
</ul>
{/foreach}
</div>
</div>
</span>
{/if}
<style>
.connected-room-popup-wrapper {
position: relative;
display: inline-block;
cursor: pointer;
color: #333;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
.connected-room-icon {
color: #008abd;
}
.connected-room-popup {
display: none;
position: absolute;
top: 130%;
left: 50%;
background: #ffffff;
padding: 12px 16px;
border-radius: 6px;
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
font-size: 14px;
min-width: 200px;
z-index: 1000;
}
.connected-room-popup-wrapper:hover .connected-room-popup {
display: block;
}
.popup-title {
font-weight: 600;
font-size: 16px;
border-bottom: 1px solid rgba(0, 0, 0, 0.15);
padding-bottom: 4px;
margin-bottom: 4px;
}
.connected-room-type {
font-weight: bold;
margin-bottom: 2px;
}
.connected-room-list {
padding-left: 15px;
}
.connected-room-list li {
list-style: none;
margin: 0px;
}
</style>

View File

@@ -0,0 +1,148 @@
{**
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License version 3.0
* that is bundled with this package in the file LICENSE.md
* It is also available through the world-wide-web at this URL:
* https://opensource.org/license/osl-3-0-php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to support@qloapps.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to a newer
* versions in the future. If you wish to customize this module for your needs
* please refer to https://store.webkul.com/customisation-guidelines for more information.
*
* @author Webkul IN
* @copyright Since 2010 Webkul
* @license https://opensource.org/license/osl-3-0-php Open Software License version 3.0
*}
<div class="modal fade" id="connectedRoomModal" tabindex="-1" role="dialog">
<div class="modal-dialog modal-md">
<div class="modal-content">
<!-- header -->
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">
<i class="icon-random"></i>
{l s='Manage Connected Rooms'} -
<strong id="connected_room_title"></strong>
</h4>
</div>
<form id="connected_rooms_form">
<div class="modal-body">
<input type="hidden" id="connected_room_main_id" name="main_room_id" value="{$main_room_id}">
<div class="panel panel-default">
<div class="panel-heading">
<i class="icon-plus-circle"></i>
{l s='Add Connection'}
</div>
<div class="panel-body">
<div class="row">
<!-- room type -->
<div class="form-group col-sm-6">
<label class="control-label">
{l s='Room Type'}
</label>
<select class="form-control" id="connect_room_type" name="connect_room_type">
{assign var=types value=[]}
{foreach from=$htl_not_connected_rooms item=room}
{if !in_array($room.id_product, $types)}
{append var=types value=$room.id_product}
<option value="{$room.id_product}"
{if $room.id_product == $current_roomtype}selected{/if}>
{$room.room_type}
</option>
{/if}
{/foreach}
</select>
</div>
<!-- rooms -->
<div class="form-group col-sm-6">
<label class="control-label">
{l s='Room'}
</label>
<select class="form-control" id="connect_room" name="connect_room">
{foreach from=$htl_not_connected_rooms item=room}
<option value="{$room.id}" class="room-option" data-type="{$room.id_product}">
{$room.room_num}
</option>
{/foreach}
</select>
</div>
<!-- add -->
<div class="col-sm-12 text-right">
<button type="button" id="save_connected_room" class="btn btn-primary">
<i class="icon-plus"></i> {l s='Add'}
</button>
</div>
</div>
</div>
</div>
<!-- connectedrooms list -->
<div class="panel panel-default">
<div class="panel-heading">
<i class="icon-link"></i>
{l s='Connected Rooms'}
</div>
<div class="panel-body">
<div id="connected_rooms_list">
{if isset($htl_connected_rooms) && $htl_connected_rooms|count > 0}
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>{l s='Room'}</th>
<th>{l s='Room Type'}</th>
<th width="60" class="text-center">
{l s='Action'}
</th>
</tr>
</thead>
<tbody>
{foreach from=$htl_connected_rooms item=hotelRooms}
{foreach from=$hotelRooms key=roomType item=rooms}
{foreach from=$rooms item=row}
<tr>
<td>{$row.connected_room_num}</td>
<td>{$row.connected_room_type}</td>
<td class="text-center">
<a href="javascript:void(0);" class="delete-connected-room text-danger"
data-connected-id="{$row.id_connected_room}"
data-room-id="{$row.id_room_information}"
data-connected-room-id="{$row.id_room}"
data-hotel-id="{$row.id_hotel}" title="{l s='Remove'}">
<i class="icon-trash"></i>
</a>
</td>
</tr>
{/foreach}
{/foreach}
{/foreach}
</tbody>
</table>
{else}
<p class="text-muted text-center">
{l s='No connected rooms.'}
</p>
{/if}
</div>
</div>
</div>
</div>
<!-- footer -->
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">
<i class="icon-remove"></i>
{l s='Close'}
</button>
</div>
</form>
</div>
</div>
<input type="hidden" id="hotel_id" value="{$hotel_id}">
</div>

View File

@@ -3485,6 +3485,7 @@ class AdminOrdersControllerCore extends AdminController
$order_detail_data[$key]['amt_with_qty_tax_incl'] = $value['total_price_tax_incl'];
$order_detail_data[$key]['room_type_info'] = $objHotelRoomType->getRoomTypeInfoByIdProduct($value['id_product']);
$order_detail_data[$key]['total_room_tax'] = $order_detail_data[$key]['total_room_price_ti'] - $order_detail_data[$key]['total_room_price_te'];
$order_detail_data[$key]['connected_rooms'] = HotelRoomConnected::getConnectedRoomsByHotel($value['id_hotel'], Context::getContext()->language->id, $value['id_room'], true);
if (isset($value['refund_info'])
&& $value['refund_info']['refunded']

View File

@@ -1331,6 +1331,7 @@ class HotelCartBookingData extends ObjectModel
);
$cart_detail_data[$key]['amt_with_qty'] = $roomTypeDateRangePrice['total_price_tax_excl'];
$cart_detail_data[$key]['connected_rooms'] = HotelRoomConnected::getConnectedRoomsByHotel($obj_htl_room_info->id_hotel, Context::getContext()->language->id, $obj_htl_room_info->id, true);
}
}
if ($cart_detail_data) {

View File

@@ -552,6 +552,14 @@ class HotelReservationSystemDb
SELECT 5, `id_lang`, 'Hotel Amenities Block', 'Configure Hotels Amenities settings. You can display hotel amenities images using this block. This block will be displayed on home page.'
FROM `"._DB_PREFIX_."lang`
ORDER BY `id_lang`;",
"CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_connected_room` (
`id_connected_room` int(11) NOT NULL AUTO_INCREMENT,
`id_room_information` int(11) NOT NULL,
`id_room` int(11) NOT NULL,
`date_add` datetime NOT NULL,
`date_upd` datetime NOT NULL,
PRIMARY KEY (`id_connected_room`)
) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;",
);
}
@@ -615,7 +623,8 @@ class HotelReservationSystemDb
`'._DB_PREFIX_.'htl_room_type_bed_type`,
`'._DB_PREFIX_.'htl_access`,
`'._DB_PREFIX_.'htl_settings_link`,
`'._DB_PREFIX_.'htl_settings_link_lang`'
`'._DB_PREFIX_.'htl_settings_link_lang`
`'._DB_PREFIX_.'htl_connected_room`'
);
}
}

View File

@@ -0,0 +1,86 @@
<?php
/**
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License version 3.0
* that is bundled with this package in the file LICENSE.md
* It is also available through the world-wide-web at this URL:
* https://opensource.org/license/osl-3-0-php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to support@qloapps.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to a newer
* versions in the future. If you wish to customize this module for your needs
* please refer to https://store.webkul.com/customisation-guidelines for more information.
*
* @author Webkul IN
* @copyright Since 2010 Webkul
* @license https://opensource.org/license/osl-3-0-php Open Software License version 3.0
*/
class HotelRoomConnected extends ObjectModel
{
public $id_connected_room;
public $id_room_information;
public $id_room;
public $date_add;
public $date_upd;
public static $definition = array(
'table' => 'htl_connected_room',
'primary' => 'id_connected_room',
'fields' => array(
'id_room_information' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
'id_room' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
'date_add' => array('type' => self::TYPE_DATE),
'date_upd' => array('type' => self::TYPE_DATE),
),
);
public static function getConnectedRoomsByHotel($idHotel, $idLang, $roomId = null, $isConnected = true)
{
if ($isConnected) {
$sql = 'SELECT
hcr.id_connected_room,hcr.id_room_information,hcr.id_room,main_room.id_hotel,main_room.room_num AS main_room_num,connected_room.room_num AS connected_room_num,
main_pl.name AS main_room_type,conn_pl.name AS connected_room_type
FROM `' . _DB_PREFIX_ . 'htl_connected_room` hcr
INNER JOIN `' . _DB_PREFIX_ . 'htl_room_information` main_room ON main_room.id = hcr.id_room_information
INNER JOIN `' . _DB_PREFIX_ . 'htl_room_information` connected_room ON connected_room.id = hcr.id_room
LEFT JOIN `' . _DB_PREFIX_ . 'product_lang` main_pl ON (main_pl.id_product = main_room.id_product AND main_pl.id_lang = ' . $idLang . ')
LEFT JOIN `' . _DB_PREFIX_ . 'product_lang` conn_pl ON (conn_pl.id_product = connected_room.id_product AND conn_pl.id_lang = ' . $idLang . ')
WHERE main_room.id_hotel = ' . $idHotel . '
AND connected_room.id_hotel = ' . $idHotel;
if (!empty($roomId)) {
$sql .= ' AND main_room.id = ' . (int) $roomId;
$results = Db::getInstance()->executeS($sql);
} else {
$results = Db::getInstance()->executeS($sql);
}
$grouped = [];
foreach ($results as $row) {
$roomId = $row['id_room_information'];
$connType = $row['connected_room_type'];
if (!isset($grouped[$roomId])) {
$grouped[$roomId] = [];
}
if (!isset($grouped[$roomId][$connType])) {
$grouped[$roomId][$connType] = [];
}
$grouped[$roomId][$connType][] = $row;
}
return $grouped;
} else {
$sql = 'SELECT hri.*, pl.name AS room_type
FROM `' . _DB_PREFIX_ . 'htl_room_information` hri
LEFT JOIN `' . _DB_PREFIX_ . 'product_lang` pl ON (pl.id_product = hri.id_product AND pl.id_lang = ' . $idLang . ')
WHERE hri.id_hotel = ' . (int) $idHotel . '
AND hri.id != ' . (int) $roomId . '
AND NOT EXISTS (SELECT 1 FROM `' . _DB_PREFIX_ . 'htl_connected_room` cr WHERE cr.id_room_information = ' . (int) $roomId . ' AND cr.id_room = hri.id)
ORDER BY hri.room_num ASC';
return Db::getInstance()->executeS($sql);
}
}
}

View File

@@ -387,6 +387,7 @@ class AdminHotelRoomsBookingController extends ModuleAdminController
'max_child_in_room' => Configuration::get('WK_GLOBAL_MAX_CHILD_IN_ROOM'),
'link' => $this->context->link,
'ALLOTMENT_MANUAL' => HotelBookingDetail::ALLOTMENT_MANUAL,
'htl_connected_rooms' => HotelRoomConnected::getConnectedRoomsByHotel($this->id_hotel, $this->context->language->id, 0, true),
));
if (Configuration::get('PS_BACKOFFICE_SEARCH_TYPE') == HotelBookingDetail::SEARCH_TYPE_OWS) {

View File

@@ -49,6 +49,7 @@ require_once 'classes/HotelRoomDisableDates.php';
require_once 'classes/HotelBranchRefundRules.php';
require_once 'classes/HotelBedType.php';
require_once 'classes/HotelRoomTypeBedType.php';
require_once 'classes/HotelRoomConnected.php';
// linked products
require_once 'classes/RoomTypeServiceProduct.php';

View File

@@ -40,7 +40,11 @@
<tbody>
{foreach from=$book_v['data']['available'] key=avai_k item=avai_v}
<tr>
<td>{$avai_v['room_num']|escape:'htmlall':'UTF-8'} {hook h='displayRoomNumAfter' data=$avai_v type='available'}</td>
<td>{$avai_v['room_num']|escape:'htmlall':'UTF-8'}
{if isset($htl_connected_rooms[$avai_v['id_room']]) && $htl_connected_rooms[$avai_v['id_room']]|@count > 0}
{include file="controllers/products/connected-rooms.tpl" htl_connected_rooms=$htl_connected_rooms[$avai_v['id_room']]}
{/if}
{hook h='displayRoomNumAfter' data=$avai_v type='available'}</td>
{assign var="is_full_date" value=($show_full_date && ($date_from|date_format:'%D' == $date_to|date_format:'%D'))}
<td>{dateFormat date=$date_from full=$is_full_date} - {dateFormat date=$date_to full=$is_full_date}</td>
<td>{$avai_v['room_comment']|escape:'htmlall':'UTF-8'}</td>