Merge branch 'develop' into gli-2563

This commit is contained in:
azhar bhat
2025-05-19 10:51:56 +05:30
6 changed files with 948 additions and 81 deletions

View File

@@ -1,5 +1,31 @@
#leave_bprice
margin-left: 0px
.padding-top-20
padding-top: 20px
.modal-subtitle
font-weight: 400
color: #333333
font-size: 13px
padding-bottom: 10px
.rooms-disable-dates-title
.rooms-disable-dates
thead
tr
background-color: #f1f1f1
margin-top: 15px
padding-bottom: 5px
font-size: 13px
border-bottom: solid 1px #EAEDEF
.rooms_bulk_actions
.dropdown-menu
li > a:hover
cursor: pointer
#bulk-update-rooms-button[disabled]
&:hover
cursor: not-allowed
border-color: $btn-default-border
.add_disable_date_row_container
margin-top: 5px
#deactiveDatesModal
.fc-popover-body .fc-daygrid-event-harness
@@ -114,4 +140,4 @@
padding: 15px
border-radius: 6px
.tooltip_action_block
min-width: unset
min-width: unset

View File

@@ -67,7 +67,7 @@ textarea:focus, input[type="text"]:focus, input[type="password"]:focus, input[ty
@include box-shadow(none)
&.btn-default[disabled]
border-color: $gray-light
color: $gray-light
color: $main-color
background-color: lighten($gray-light,35%)
.dropdown-menu

View File

@@ -28,6 +28,7 @@
<table class="table hotel-room">
<thead>
<tr class="nodrag nodrop">
<th class="center"></th>
<th class="col-sm-2 center">
<label class="control-label required">
<span class="label-tooltip" data-toggle="tooltip" data-original-title="{l s='Enter room number. For eg. A-101, A-102 etc. Invalid characters <>;=#{}'}">
@@ -70,7 +71,7 @@
</tr>
</thead>
<tbody>
{if isset($smarty.post.rooms_info) && is_array($smarty.post.rooms_info) && count($smarty.post.rooms_info)}
{if isset($smarty.post.rooms_info) && is_array($smarty.post.rooms_info) && count($smarty.post.rooms_info) && !isset($bulk_delete_rooms)}
{assign var="rooms_info" value=$smarty.post.rooms_info}
{elseif isset($htl_room_info) && is_array($htl_room_info) && count($htl_room_info)}
{assign var="rooms_info" value=$htl_room_info}
@@ -79,6 +80,9 @@
{foreach from=$rooms_info key=key item=room_info}
{assign var="var_name_room_info" value="rooms_info[`$key`]"}
<tr class="room_data_values" data-row-index="{$key}">
<td class="center">
<input type="checkbox" {if isset($room_info['id'])}value="{$room_info['id']}"{else}disabled{/if} name="selected_room_ids[]">
</td>
<td class="col-sm-1 center">
<input class="form-control" type="text" value="{$room_info['room_num']}" name="{$var_name_room_info|cat:'[room_num]'}">
</td>
@@ -100,10 +104,15 @@
</a>
<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>
{hook h='displayHotelRoomListTableRowColumn' index=$key id_room=$room_info['id']}
{* Since the data can also be used from post incase of errors, which will cause issues with the id index *}
{if isset($room_info['id'])}
{hook h='displayHotelRoomListTableRowColumn' index=$key id_room=$room_info['id']}
{else}
{hook h='displayHotelRoomListTableRowColumn' index=$key}
{/if}
<td class="col-sm-1 center">
{if isset($room_info['id'])}
{if isset($room_info['booked_dates']) && $room_info['booked_dates']}
{if isset($room_info['booked_dates']) && json_decode($room_info['booked_dates'])}
<input type="hidden" class="booked-dates" name="{$var_name_room_info|cat:'[booked_dates]'}" value='{$room_info['booked_dates']|escape:'html':'UTF-8'}'>
<a href="#" class="view_htl_room btn btn-default" data-toggle="modal" data-target="#room-dates-modal" data-id-room="{$room_info['id']}"><i class="icon-info"></i></a>
{/if}
@@ -119,6 +128,9 @@
{for $k=0 to 1}
{assign var="var_name_room_info" value="rooms_info[`$k`]"}
<tr class="room_data_values" data-row-index="{$k}">
<td class="center">
<input type="checkbox" value="" disabled name="selected_room_ids[]">
</td>
<td class="col-sm-1 center">
<input class="form-control" type="text" name="{$var_name_room_info|cat:'[room_num]'}">
</td>
@@ -156,6 +168,41 @@
</table>
<div class="form-group">
<div class="col-sm-12">
<div class="btn-group rooms_bulk_actions dropup">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
{l s='Bulk actions'}
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li>
<a href="#" id="select-all-rooms">
<i class="icon-check-sign"></i>&nbsp;{l s='Select all'}
</a>
</li>
<li>
<a href="#" id="unselect-all-rooms">
<i class="icon-check-empty"></i>&nbsp;{l s='Unselect all'}
</a>
</li>
<li class="divider"></li>
<li>
<a href="#" id="bulk-update-rooms-button" class="bulkUpdateRoomModal" data-toggle="modal" data-target="#bulkUpdateRoomModal" type="button" data-size="s" data-style="expand-right" disabled>
<i class="icon-edit"></i>&nbsp;{l s='Update selection'}
</a>
</li>
<li>
<a href="#" id="bulk-delete-rooms-button">
<i class="icon-trash"></i>&nbsp;{l s='Delete selection'}
</a>
</li>
<li class="divider"></li>
<li>
<a id="bulk-create-rooms-button" class="bulkCreateRoomModal" data-toggle="modal" data-target="#bulkCreateRoomModal" type="button" data-size="s" data-style="expand-right">
<i class="icon-plus"></i>&nbsp;{l s='Create Rooms'}
</a>
</li>
</ul>
</div>
<button id="add-more-rooms-button" class="btn btn-default" type="button" data-size="s" data-style="expand-right">
<i class="icon icon-plus"></i>
{l s='Add More Rooms'}
@@ -180,10 +227,6 @@
</div>
{/if}
<div id="modal_loader" class="loading_overlay" style="display: none;">
<img src="{$link->getMediaLink(($smarty.const._PS_ADMIN_IMG_))}ajax-loader.gif" class="loading-img"/>
</div>
{*Disable Dates Model*}
<div class="modal fade" id="deactiveDatesModal" tabindex="-1" role="dialog" aria-labelledby="deactiveDatesLabel">
<div class="modal-dialog modal-lg" role="document">
@@ -273,6 +316,184 @@
</div>
{*END*}
<div class="modal fade" id="bulkUpdateRoomModal" tabindex="-1" role="dialog" aria-labelledby="bulkUpdateRoomLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close margin-right-10" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
<h4 class="modal-title"><i class="icon-calendar"></i>&nbsp; {l s='Bulk Update Rooms'}</h4>
</div>
<div class="modal-body padding-top-20">
<div class="text-left errors-wrap" style="display: none;"></div>
<div class="form-group">
<label class="control-label col-lg-3">
<span>{l s='Floor'}</span>
</label>
<div class="col-lg-6">
<input type="text" name="bulk_update_room_floor"/>
</div>
</div>
<div class="form-group">
<label class="control-label col-lg-3">
<span>{l s='Status'}</span>
</label>
<div class="col-lg-6">
<select class="form-control bulk_update_room_status" name="bulk_update_room_status">
{foreach from=$rm_status item=room_stauts}
<option value="{$room_stauts['id']}">{$room_stauts['status']|escape:'htmlall':'UTF-8'}</option>
{/foreach}
</select>
</div>
</div>
<div class="form-group">
<label class="control-label col-lg-3">
<span>{l s='Extra Information'}</span>
</label>
<div class="col-lg-6">
<input type="text" name="bulk_update_room_comment"/>
</div>
</div>
<div class="from-group table-responsive-row clearfix" style="display:none;">
<div class="rooms-disable-dates-title">{l s='Disable Dates'}</div>
<table class="table rooms-disable-dates">
<thead>
<tr class="nodrag nodrop">
<th class="col-sm-1 center">
<div>{l s='Date From'}</span>
</th>
<th class="col-sm-2 center">
<span>{l s='Date To'}</span>
</th>
<th class="col-sm-2 center">
<span>{l s='Reason'}</span>
</th>
<th class="col-sm-1 center"></th>
</tr>
</thead>
<tbody></tbody>
</table>
<div class="form-group add_disable_date_row_container">
<div class="col-sm-12">
<a href="#" class="add_bulk_room_update_disable_date btn btn-default">
<i class="icon icon-plus"></i>
<span>{l s="Add More"}</span>
</a>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" name="submitBulkUpdateRooms">{l s='Submit'}</button>
</div>
</div>
</div>
</div>
</div>
<div class="modal fade" id="bulkCreateRoomModal" tabindex="-1" role="dialog" aria-labelledby="bulkCreateRoomLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close margin-right-10" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
<h4 class="modal-title"><i class="icon-calendar"></i>&nbsp; {l s='Bulk Create Rooms'}</h4>
</div>
<div class="modal-body padding-top-20">
<div class="text-left errors-wrap" style="display: none;"></div>
<div class="form-group">
<label class="control-label col-lg-3">
<span>{l s='Room prefix'}</span>
</label>
<div class="col-lg-6">
<input type="text" name="bulk_create_room_prefix"/>
</div>
</div>
<div class="form-group">
<label class="control-label col-lg-3">
<span>{l s='Starting Room No.'}</span>
</label>
<div class="col-lg-6">
<input type="text" name="bulk_create_room_num"/>
</div>
</div>
<div class="form-group">
<label class="control-label required col-lg-3">
<span>{l s='Number of Rooms'}</span>
</label>
<div class="col-lg-6">
<input type="text" name="bulk_create_room_qty"/>
</div>
</div>
<div class="form-group">
<label class="control-label col-lg-3">
<span>{l s='Floor'}</span>
</label>
<div class="col-lg-6">
<input type="text" name="bulk_create_room_floor"/>
</div>
</div>
<div class="form-group">
<label class="control-label col-lg-3">
<span>
{l s='Status'}
</span>
</label>
<div class="col-lg-6">
<select class="form-control bulk_create_room_status" name="bulk_create_room_status">
{foreach from=$rm_status item=room_stauts}
<option value="{$room_stauts['id']}">{$room_stauts['status']|escape:'htmlall':'UTF-8'}</option>
{/foreach}
</select>
</div>
</div>
<div class="form-group">
<label class="control-label col-lg-3">
<span>
{l s='Extra Information'}
</span>
</label>
<div class="col-lg-6">
<input type="text" name="bulk_create_room_comment"/>
</div>
</div>
<div class="from-group table-responsive-row clearfix" style="display:none;">
<div class="rooms-disable-dates-title">{l s='Disable Dates'}</div>
<table class="table rooms-disable-dates">
<thead>
<tr class="nodrag nodrop">
<th class="col-sm-1 center">
<div>{l s='Date From'}</span>
</th>
<th class="col-sm-2 center">
<span>{l s='Date To'}</span>
</th>
<th class="col-sm-2 center">
<span>{l s='Reason'}</span>
</th>
<th class="col-sm-1 center"></th>
</tr>
</thead>
<tbody></tbody>
</table>
<div class="form-group add_disable_date_row_container">
<div class="col-sm-12">
<a href="#" class="add_bulk_room_create_disable_date btn btn-default">
<i class="icon icon-plus"></i>
<span>{l s="Add More"}</span>
</a>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" name="submitBulkCreateRooms">{l s='Submit'}</button>
</div>
</div>
</div>
</div>
</div>
<div class="modal fade" id="room-dates-modal" tabindex="-1" role="dialog" aria-labelledby="">
<div class="modal-dialog" role="document">
<div class="modal-content">
@@ -398,6 +619,9 @@
var prefix = 'rooms_info['+lengthRooms+']';
html = '<tr class="room_data_values" data-row-index="'+lengthRooms+'">';
html += '<td class="center">';
html += '<input type="checkbox" disabled name="selected_room_ids[]">';
html += '</td>';
html += '<td class="col-sm-1 center">';
html += '<input class="form-control" type="text" name="'+prefix+'[room_num]">';
html += '</td>';
@@ -412,7 +636,7 @@
html += '</select>';
html += '</td>';
html += '<td class="col-sm-3 center">';
html += '<input class="form-control" type="text" name="'+prefix+'[comment]">';
html += '<input class="form-control" type="text" name="'+prefix+'[floor]">';
html += '</td>';
html += '<td class="center col-sm-2">';
html += '<a class="btn btn-default deactiveDatesModal disabled" data-toggle="modal" data-target="#deactiveDatesModal">';
@@ -697,14 +921,14 @@
// Called after the modal is shown, since the modal is hidden at first, the size of the fullcalendar is render incorrectly.
$('#deactiveDatesModal').on('shown.bs.modal', function(e) {
DisableDatesCalendar.updateSize();
$('#modal_loader').hide();
$('#page-loader').hide();
$('#deactiveDatesModal').css('visibility', 'visible');
});
// Reseting and populating the modal.
$('#deactiveDatesModal').on('show.bs.modal', function(e) {
$('#deactiveDatesModal').css('visibility', 'hidden');
$('#modal_loader').show();
$('#page-loader').show();
DisableDatesObj.reset();
DisableDatesObj.init($(e.relatedTarget));
});
@@ -719,7 +943,343 @@
DisableDatesObj.allowCalendarActions();
});
// Init full calander object.
$('[name="selected_room_ids[]"]').on('change', function(){
BulkUpdateRoomModal.toggleBulkUpdateButton();
});
$('[name="rooms_checkbox"]').on('change', function() {
BulkUpdateRoomModal.toggleBulkUpdateButton();
});
$('#select-all-rooms').on('click', function(e) {
e.preventDefault();
$('[type="checkbox"][name="selected_room_ids[]"]').each(function(){
if (!$(this).prop('disabled')) {
$(this).prop('checked', true);
}
});
BulkUpdateRoomModal.toggleBulkUpdateButton();
});
$('#unselect-all-rooms').on('click', function(e) {
e.preventDefault();
$('[type="checkbox"][name="selected_room_ids[]"]').each(function(){
$(this).prop('checked', false);
});
BulkUpdateRoomModal.toggleBulkUpdateButton();
});
$('#bulk-delete-rooms-button').on('click', function(e) {
e.preventDefault();
BulkUpdateRoomModal.submitBulkDelete();
});
$(document).on('change', 'select[name="bulk_update_room_status"], select[name="bulk_create_room_status"]', function(){
var status_val = $(this).val();
if (status_val == rm_status.STATUS_TEMPORARY_INACTIVE.id) {
$(this).closest('.modal-body').find('.rooms-disable-dates').parent().show();
} else {
$(this).closest('.modal-body').find('.rooms-disable-dates').parent().hide();
}
});
$(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)) {
$(this).closest('tr').find('.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);
},
});
});
$('#bulkUpdateRoomModal').on('show.bs.modal', function(e){
if (!$(e.relatedTarget).attr('disabled')) {
$('#bulkUpdateRoomModal table tbody').html('');
$('.bulk_update_room_status').val(rm_status.STATUS_ACTIVE.id).closest('.modal-body').find('.rooms-disable-dates').parent().hide();
$('[name="bulk_update_room_comment"]').val('');
$('[name="bulk_update_room_floor"]').val('');
$('#page-loader').show();
BulkUpdateRoomModal.init();
} else {
return false;
}
});
$('#bulkUpdateRoomModal').on('shown.bs.modal', function(e){
$('#page-loader').hide();
});
$('#bulkCreateRoomModal').on('show.bs.modal', function(e){
$('#bulkCreateRoomModal table tbody').html('');
$('.bulk_create_room_status').val(rm_status.STATUS_ACTIVE.id).closest('.modal-body').find('.rooms-disable-dates').parent().hide();
$('[name="bulk_create_room_comment"]').val('');
$('[name="bulk_create_room_floor"]').val('');
$('[name="bulk_create_room_prefix"]').val(''),
$('[name="bulk_create_room_num"]').val(''),
$('[name="bulk_create_room_qty"]').val(''),
BulkCreateRoomModal.init();
});
$('#bulkCreateRoomModal').on('shown.bs.modal', function(e){
$('#page-loader').hide();
});
$('.add_bulk_room_update_disable_date').on('click', function() {
BulkUpdateRoomModal.addNewRow();
});
$('.add_bulk_room_create_disable_date').on('click', function() {
BulkCreateRoomModal.addNewRow();
});
$(document).on('click','.remove-room-bulk-disable-dates-button',function(e) {
e.preventDefault();
$(this).closest('tr').remove();
});
$(document).on('click','button[name="submitBulkUpdateRooms"]',function(e) {
BulkUpdateRoomModal.submitBulkUpdateModal();
});
$(document).on('click','button[name="submitBulkCreateRooms"]',function(e) {
BulkCreateRoomModal.submitBulkCreateModal();
});
const BulkUpdateRoomModal = {
init: function() {
BulkUpdateRoomModal.addNewRow();
BulkUpdateRoomModal.hideErrors();
},
addNewRow: function() {
$('#bulkUpdateRoomModal tbody').append(this.getDisableDatesRowHtml());
},
removeAllInvalidRowDataMarkers: function(tr) {
$('#bulkUpdateRoomModal .room-disable-dates tr').css('outline', '');
$(tr).css('outline', '');
},
markRowDataInvalid: function(tr) {
$(tr).css({ 'outline': '1px solid #D27C82', 'border-radius': '2px' });
},
hideErrors: function() {
$('#bulkUpdateRoomModal .errors-wrap').hide();
$('#bulkUpdateRoomModal .errors-wrap').html('');
},
toggleBulkUpdateButton: function() {
let selectedRooms = BulkUpdateRoomModal.getSelectedRooms();
if (selectedRooms.length != 0) {
$('#bulk-update-rooms-button').attr('disabled', false);
} else {
$('#bulk-update-rooms-button').attr('disabled', true);
}
},
getSelectedRooms: function(){
let selectedRooms = [];
$('[type="checkbox"][name="selected_room_ids[]"]').each(function(){
if ($(this).prop('checked')) {
selectedRooms.push($(this).val());
}
})
return selectedRooms;
},
getSelectedDates: function() {
let disableDates = [];
$('#bulkUpdateRoomModal .rooms-disable-dates tbody tr').each(function(i, tr) {
let date_from = $(tr).find('.disabled_date_from').val().trim();
let date_to = $(tr).find('.disabled_date_to').val().trim();
let reason = $(tr).find('.room_disable_reason').val().trim();
disableDates.push({ date_from, date_to, reason});
});
return disableDates;
},
showErrors: function(errors) {
$('#bulkUpdateRoomModal .errors-wrap').html(errors);
$('#bulkUpdateRoomModal .errors-wrap').show();
},
submitBulkUpdateModal: function() {
let dates = this.getSelectedDates();
let data = {
ajax : 1,
action: 'bulkUpdateRooms',
id_rooms: this.getSelectedRooms(),
disable_dates: this.getSelectedDates(),
floor: $('[name="bulk_update_room_floor"]').val(),
room_comment: $('[name="bulk_update_room_comment"]').val(),
id_status: $('.bulk_update_room_status').val(),
id_product: $('[name="id_product"]').val()
};
$('#page-loader').show();
$.ajax({
url: prod_link,
type: 'POST',
data: data,
dataType: 'JSON',
success: function(response) {
if (response.status) {
window.location.href = response.href;
} else {
BulkUpdateRoomModal.showErrors(response.msg);
BulkUpdateRoomModal.addInvalidRowDataMarkers(response.rows_to_highlight);
}
},
complete: function() {
$('#page-loader').hide();
}
});
},
submitBulkDelete: function() {
if (confirm("{l s='Delete selected rooms?'}")) {
$('#product_form').append('<input type="hidden" name="submitBulkDeleteRooms" value="1"/>');
$('form#product_form').submit();
}
},
addInvalidRowDataMarkers: function(rowsToHighlight) {
if (rowsToHighlight.length != 0) {
rowsToHighlight.map(function (rowIndex) {
const tr = $('#bulkUpdateRoomModal .rooms-disable-dates tbody tr').eq(rowIndex);
BulkUpdateRoomModal.markRowDataInvalid(tr);
});
}
},
getDisableDatesRowHtml: function () {
let dateFromElem = $('<td>').addClass('col-sm-2 center').append($('<input>').attr('type', 'text').addClass('form-control disabled_date_from').prop('readonly', 'readonly'));
let dateToElem = $('<td>').addClass('col-sm-2 center').append($('<input>').attr('type', 'text').addClass('form-control disabled_date_to').prop('readonly', 'readonly'));
let reasonElem = $('<td>').addClass('col-sm-6 center').append($('<input>').attr('type', 'text').addClass('form-control room_disable_reason'));
let removeRowElem = $('<td>').addClass('col-sm-1 center').append($('<a>').attr('href', '#').addClass('remove-room-bulk-disable-dates-button btn btn-default').append($('<i>').addClass('icon-trash')));
let rowElem = $('<tr>').addClass('disabledDatesTr')
.append(dateFromElem)
.append(dateToElem)
.append(reasonElem)
.append(removeRowElem);
return $(rowElem).prop('outerHTML');
}
};
const BulkCreateRoomModal = {
init: function() {
BulkCreateRoomModal.addNewRow();
BulkCreateRoomModal.hideErrors();
},
addNewRow: function() {
$('#bulkCreateRoomModal tbody').append(this.getDisableDatesRowHtml());
},
removeAllInvalidRowDataMarkers: function(tr) {
$('#bulkCreateRoomModal .room-disable-dates tr').css('outline', '');
$(tr).css('outline', '');
},
markRowDataInvalid: function(tr) {
$(tr).css({ 'outline': '1px solid #D27C82', 'border-radius': '2px' });
},
hideErrors: function() {
$('#bulkCreateRoomModal .errors-wrap').hide();
$('#bulkCreateRoomModal .errors-wrap').html('');
},
getSelectedDates: function() {
let disableDates = [];
$('#bulkCreateRoomModal .rooms-disable-dates tbody tr').each(function(i, tr) {
let date_from = $(tr).find('.disabled_date_from').val().trim();
let date_to = $(tr).find('.disabled_date_to').val().trim();
let reason = $(tr).find('.room_disable_reason').val().trim();
disableDates.push({ date_from, date_to, reason});
});
return disableDates;
},
showErrors: function(errors) {
$('#bulkCreateRoomModal .errors-wrap').html(errors);
$('#bulkCreateRoomModal .errors-wrap').show();
},
submitBulkCreateModal: function() {
let dates = this.getSelectedDates();
let data = {
ajax : 1,
action: 'bulkCreateRooms',
disable_dates: this.getSelectedDates(),
prefix: $('[name="bulk_create_room_prefix"]').val(),
num: $('[name="bulk_create_room_num"]').val(),
qty: $('[name="bulk_create_room_qty"]').val(),
floor: $('[name="bulk_create_room_floor"]').val(),
room_comment: $('[name="bulk_create_room_comment"]').val(),
id_status: $('.bulk_create_room_status').val(),
id_product: $('[name="id_product"]').val()
};
$('#page-loader').show();
$.ajax({
url: prod_link,
type: 'POST',
data: data,
dataType: 'JSON',
success: function(response) {
if (response.status) {
window.location.href = response.href;
} else {
BulkCreateRoomModal.showErrors(response.msg);
BulkCreateRoomModal.addInvalidRowDataMarkers(response.rows_to_highlight);
}
},
complete: function() {
$('#page-loader').hide();
}
});
},
addInvalidRowDataMarkers: function(rowsToHighlight) {
if (rowsToHighlight.length != 0) {
rowsToHighlight.map(function (rowIndex) {
const tr = $('#bulkCreateRoomModal .rooms-disable-dates tbody tr').eq(rowIndex);
BulkCreateRoomModal.markRowDataInvalid(tr);
});
}
},
getDisableDatesRowHtml: function () {
let dateFromElem = $('<td>').addClass('col-sm-2 center').append($('<input>').attr('type', 'text').addClass('form-control disabled_date_from').prop('readonly', 'readonly'));
let dateToElem = $('<td>').addClass('col-sm-2 center').append($('<input>').attr('type', 'text').addClass('form-control disabled_date_to').prop('readonly', 'readonly'));
let reasonElem = $('<td>').addClass('col-sm-6 center').append($('<input>').attr('type', 'text').addClass('form-control room_disable_reason'));
let removeRowElem = $('<td>').addClass('col-sm-1 center').append($('<a>').attr('href', '#').addClass('remove-room-bulk-disable-dates-button btn btn-default').append($('<i>').addClass('icon-trash')));
let rowElem = $('<tr>').addClass('disabledDatesTr')
.append(dateFromElem)
.append(dateToElem)
.append(reasonElem)
.append(removeRowElem);
return $(rowElem).prop('outerHTML');
}
};
// Init full calender object.
const DisableDatesCalendar = new FullCalendar.Calendar($('#disable_dates_full_calendar').get(0), {
initialView: 'dayGridMonth',
initialDate: '{date('Y-m-d', time())}',

View File

@@ -246,37 +246,6 @@
}
return typeIsPack;
} *}
$("#product_form").validate({
ignore: '.updateCurrentText',
{* rules: {
inputPackItems: {
required: {
depends: checkIfProductTypeIsPack
},
}
}, *}
{* messages: {
inputPackItems: {
required: ""
}
}, *}
// override jquery validate plugin defaults for bootstrap 3
highlight: function(element) {
$(element).closest('.form-group').addClass('has-error');
},
unhighlight: function(element) {
$(element).closest('.form-group').removeClass('has-error');
},
errorElement: 'span',
errorClass: 'help-block',
errorPlacement: function(error, element) {
if(element.parent('.input-group').length) {
error.insertAfter(element.parent());
} else {
error.insertAfter(element);
}
}
});
});
</script>

View File

@@ -474,6 +474,19 @@ class AdminAddressesControllerCore extends AdminController
$this->_redirect = false;
// set deleted=1 as customer can have only one address and this address is for an order only
$_POST['deleted'] = 1;
// if the deleted address is the customer current address then we will create a new one using the same information.
if (($customerAddressId = Address::getFirstCustomerAddressId((int) $address->id_customer))
&& $customerAddressId == $address->id
) {
// initialized with the old address information
$objAddress = new Address($address->id);
$objAddress->id = $objAddress->id_address = null;
}
if ($address->isUsed() > 1) {
// If this address is used in other orders, we will create a new address, and will not update the older addresses.
$this->id_object = null;
}
}
// Check the requires fields which are settings in the BO
@@ -483,6 +496,10 @@ class AdminAddressesControllerCore extends AdminController
$return = false;
if (empty($this->errors)) {
$return = parent::processSave();
// creating new address here since the customer older address needs to be set as deleted first as customer can only have one active address.
if (isset($objAddress)) {
$objAddress->save();
}
} else {
// if we have errors, we stay on the form instead of going back to the list
$this->display = 'edit';

View File

@@ -1495,6 +1495,11 @@ class AdminProductsControllerCore extends AdminController
} else {
$this->errors[] = Tools::displayError('You do not have permission to edit this.');
}
}
// Room bulk deletion process
else if (Tools::isSubmit('submitBulkDeleteRooms')) {
$this->action = 'bulkDeleteRooms';
$this->display = 'edit';
} elseif (Tools::isSubmit('submitProductCustomization')) {
if ($this->tabAccess['edit'] === '1') {
$this->action = 'productCustomization';
@@ -3534,47 +3539,77 @@ class AdminProductsControllerCore extends AdminController
}
}
public function processBulkDeleteRooms()
{
if ($this->tabAccess['edit'] == 1) {
if ($idRooms = Tools::getValue('selected_room_ids')) {
foreach ($idRooms as $idRoom) {
$objRoomInfo = new HotelRoomInformation((int)$idRoom);
if ($objRoomInfo->getFutureBookings($idRoom)) {
$this->errors[] = sprintf(Tools::displayError('The %s room cannot be deleted as this room contains future booking.'), $objRoomInfo->room_num);
} else {
$objRoomInfo->delete();
}
}
} else {
$this->errors[] = Tools::displayError('You must select at least one room to delete.');
}
} else {
$this->errors[] = Tools::displayError('You do not have the permission for this action.');
}
if (empty($this->errors)) {
$this->redirect_after = self::$currentIndex.'&id_product='.$this->id_object.'&update'.$this->table.'&conf=2&key_tab=Configuration&token='.$this->token;
} else {
$this->context->smarty->assign('bulk_delete_rooms', true);
}
}
public function processConfiguration()
{
// Check if save of configuration tab is submitted
if (Tools::getValue('checkConfSubmit')) {
$id_product = Tools::getValue('id_product');
$id_hotel = Tools::getValue('id_hotel');
if ($this->tabAccess['edit'] == 1) {
if (Tools::getValue('checkConfSubmit')) {
$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.');
}
if (!$id_hotel || !Validate::isUnsignedInt($id_hotel)) {
$this->errors[] = Tools::displayError('Please select a hotel.');
}
if (!$id_product || !Validate::isUnsignedInt($id_product)) {
$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->validateConfigurationPostData();
if (!count($this->errors)) {
$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 = trim($roomInfo['room_num']);
$objHotelRoomInfo->id_status = $roomInfo['id_status'];
$objHotelRoomInfo->floor = trim($roomInfo['floor']);
$objHotelRoomInfo->comment = trim($roomInfo['comment']);
if ($objHotelRoomInfo->save()
&& $objHotelRoomInfo->id_status != HotelRoomInformation::STATUS_TEMPORARY_INACTIVE
) {
// directly deleting the dates since we are validating the dates using hooks before this.
$objRoomDisableDates = new HotelRoomDisableDates();
$objRoomDisableDates->deleteRoomDisableDates($objHotelRoomInfo->id);
$this->validateConfigurationPostData();
if (!count($this->errors)) {
$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 = trim($roomInfo['room_num']);
$objHotelRoomInfo->id_status = $roomInfo['id_status'];
$objHotelRoomInfo->floor = trim($roomInfo['floor']);
$objHotelRoomInfo->comment = trim($roomInfo['comment']);
if ($objHotelRoomInfo->save()
&& $objHotelRoomInfo->id_status != HotelRoomInformation::STATUS_TEMPORARY_INACTIVE
) {
// directly deleting the dates since we are validating the dates using hooks before this.
$objRoomDisableDates = new HotelRoomDisableDates();
$objRoomDisableDates->deleteRoomDisableDates($objHotelRoomInfo->id);
}
}
}
}
}
} else {
$this->errors[] = Tools::displayError('You do not have the permission for this action.');
}
}
@@ -3583,7 +3618,7 @@ class AdminProductsControllerCore extends AdminController
$roomsInfo = Tools::getValue('rooms_info');
if (is_array($roomsInfo) && count($roomsInfo)) {
foreach ($roomsInfo as $key => $roomInfo) {
if (!$roomInfo['room_num']) {
if (!trim($roomInfo['room_num'])) {
unset($_POST['rooms_info'][$key]);
}
}
@@ -3600,7 +3635,7 @@ class AdminProductsControllerCore extends AdminController
}
}
if (empty(trim($roomInfo['room_num'])) || !Validate::isGenericName($roomInfo['room_num'])) {
if ($roomInfo['room_num'] && !Validate::isGenericName($roomInfo['room_num'])) {
$this->errors[] = sprintf(Tools::displayError('Invalid room number for room %s.'), $roomIndex);
}
@@ -3634,9 +3669,8 @@ class AdminProductsControllerCore extends AdminController
);
if ($this->tabAccess['edit'] == 1) {
$idRoom = Tools::getValue('id');
$objRoomInfo = new HotelRoomInformation((int)$idRoom);
$objHotelRoomInformation = new HotelRoomInformation();
if ($objHotelRoomInformation->getFutureBookings($idRoom)) {
$objRoomInfo = new HotelRoomInformation((int) $idRoom);
if ($objRoomInfo->getFutureBookings($idRoom)) {
$this->errors[] = $this->l('This room cannot be deleted as this room contains future booking.');
}
if (empty($this->errors)) {
@@ -5246,6 +5280,267 @@ class AdminProductsControllerCore extends AdminController
$this->ajaxDie(json_encode($response));
}
public function ajaxProcessBulkUpdateRooms()
{
$response = array('status' => false);
$roomsInfo = array();
if ($this->tabAccess['edit'] === '1') {
if ($idRooms = Tools::getValue('id_rooms')) {
$rowsToHighlight = array();
$room = array();
if (trim($floor = Tools::getValue('floor'))) {
$room['floor'] = $floor;
if (!Validate::isGenericName($floor)) {
$this->errors[] = Tools::displayError('Invalid value for floor.');
}
}
if (trim($comment = Tools::getValue('room_comment'))) {
$room['comment'] = $comment;
}
$room['id_status'] = Tools::getValue('id_status');
$disableDates = array();
if ($room['id_status'] == HotelRoomInformation::STATUS_TEMPORARY_INACTIVE) {
$disableDates = Tools::getValue('disable_dates');
$room['disable_dates_json'] = json_encode($disableDates);
if (!$disableDates) {
$this->errors[] = Tools::displayError('Please add at least one date range for updating the rooms status to temporary inactive.');
} else {
$hasMissingRowError = false;
foreach ($disableDates as $key => $dateRange) {
if (!Validate::isDate($dateRange['date_from']) || !Validate::isDate($dateRange['date_to'])) {
if (!$hasMissingRowError) {
$hasMissingRowError = true;
$this->errors[] = Tools::displayError('Some dates are missing. Please select all the date ranges.');
}
$rowsToHighlight[] = $key;
}
}
if (!count($this->errors)) {
$error = false;
foreach ($disableDates as $keyOuter => $dateRangeOuter) {
foreach ($disableDates as $keyInner => $dateRangeInner) {
if ($keyInner != $keyOuter) {
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']))
) {
if (!$error) {
$error = Tools::displayError('Some dates are conflicting with each other. Please check and reselect the date ranges.');
}
$rowsToHighlight[] = $keyOuter;
$rowsToHighlight[] = $keyInner;
}
}
}
}
if ($error) {
$this->errors[] = $error;
}
}
}
}
if (empty($this->errors)) {
// we can not use the queries til all the data is validated prooperly
$objHotelBookingDetail = new HotelBookingDetail();
foreach ($idRooms as $idRoom) {
$objHotelRoomInfo = new HotelRoomInformation((int) $idRoom);
if ($room['id_status'] == HotelRoomInformation::STATUS_INACTIVE) {
if (count($objHotelRoomInfo->getFutureBookings($idRoom))) {
$this->errors[] = sprintf(Tools::displayError('Cannot change room %s status to inactive as it already has some bookings, Please check the bookings and move those bookings to another room if you want make this room inactive'), $objHotelRoomInfo->room_num);
}
} else if ($room['id_status'] == HotelRoomInformation::STATUS_TEMPORARY_INACTIVE && $disableDates) {
foreach ($disableDates as $key => $dateRange) {
if ($objHotelBookingDetail->chechRoomBooked($idRoom, $dateRange['date_from'], $dateRange['date_to'])) {
$rowsToHighlight[] = $key;
}
}
}
$room['id'] = $idRoom;
$roomsInfo[] = $room;
Hook::exec('actionValidateRoomInformation', array('room_information' => $room));
}
}
if (empty($this->errors)) {
foreach ($roomsInfo as $roomInfo) {
$objHotelRoomInfo = new HotelRoomInformation($roomInfo['id']);
$objHotelRoomInfo->id_status = $roomInfo['id_status'];
if (isset($roomInfo['floor']) && $roomInfo['floor'] != '') {
$objHotelRoomInfo->floor = $roomInfo['floor'];
}
if (isset($roomInfo['comment']) && $roomInfo['comment'] != '') {
$objHotelRoomInfo->comment = $roomInfo['comment'];
}
if ($objHotelRoomInfo->save()
&& $objHotelRoomInfo->id_status != HotelRoomInformation::STATUS_TEMPORARY_INACTIVE
) {
// directly deleting the dates since we are validating the dates using hooks before this.
$objRoomDisableDates = new HotelRoomDisableDates();
$objRoomDisableDates->deleteRoomDisableDates($objHotelRoomInfo->id);
} else {
foreach ($disableDates as $key => $dateRange) {
$objHotelRoomDisableDates = new HotelRoomDisableDates();
$objHotelRoomDisableDates->id_room_type = $objHotelRoomInfo->id_product;
$objHotelRoomDisableDates->id_room = $roomInfo['id'];
$objHotelRoomDisableDates->date_from = $dateRange['date_from'];
$objHotelRoomDisableDates->date_to = $dateRange['date_to'];
$objHotelRoomDisableDates->reason = $dateRange['reason'];
$objHotelRoomDisableDates->save();
}
}
}
$response['status'] = true;
$response['href'] = self::$currentIndex.'&update'.$this->table.'&id_product='.Tools::getValue('id_product').'&token='.$this->token.'&conf=4&key_tab=Configuration';
} else {
$rowsToHighlight = array_values(array_unique($rowsToHighlight));
$response['rows_to_highlight'] = $rowsToHighlight;
}
} else {
$this->errors[] = Tools::displayError('Please select at least on room for this operation.');
}
} else {
$this->errors[] = Tools::displayError('You do not have permission to perform this operation.');
}
$this->assignAlerts();
$response['msg'] = $this->context->smarty->fetch('alerts.tpl');
$this->ajaxDie(json_encode($response));
}
public function ajaxProcessBulkCreateRooms()
{
$response = array('status' => false);
if ($this->tabAccess['edit'] === '1') {
if (($idProduct = Tools::getValue('id_product'))
&& Validate::isLoadedObject($objProduct = new Product($idProduct, null, $this->context->language->id))
&& $objProduct->booking_product
) {
$objRoomType = new HotelRoomType();
$roomTypeInfo = $objRoomType->getRoomTypeInfoByIdProduct($objProduct->id);
$idHotel = $roomTypeInfo['id_hotel'];
$rowsToHighlight = array();
$roomsInfo = array();
if (trim($floor = Tools::getValue('floor'))) {
$roomsInfo['floor'] = $floor;
if (!Validate::isGenericName($floor)) {
$this->errors[] = Tools::displayError('Invalid value for floor.');
}
}
if (!empty($prefix = trim(Tools::getValue('prefix')))
&& !Validate::isGenericName($prefix)
) {
$this->errors[] = Tools::displayError('Invalid Prefix.');
}
if (!empty($roomNumber = trim(Tools::getValue('num')))
&& !Validate::isUnsignedInt($roomNumber)
) {
$this->errors[] = Tools::displayError('Invalid Starting Room No.');
}
if (!($roomQuantity = Tools::getValue('qty'))) {
$this->errors[] = Tools::displayError('Number of rooms is required.');
} else if ($roomQuantity < 1) {
$this->errors[] = Tools::displayError('Invalid value for number of rooms.');
}
if (trim($comment = Tools::getValue('room_comment'))) {
$roomsInfo['comment'] = $comment;
}
$roomsInfo['id_status'] = Tools::getValue('id_status');
$disableDates = array();
if ($roomsInfo['id_status'] == HotelRoomInformation::STATUS_TEMPORARY_INACTIVE) {
$disableDates = Tools::getValue('disable_dates');
$roomsInfo['disable_dates_json'] = json_encode($disableDates);
if (!$disableDates) {
$this->errors[] = Tools::displayError('Please add at least one date range for updating the rooms status to temporary inactive.');
} else {
$hasMissingRowError = false;
foreach ($disableDates as $key => $dateRange) {
if (!Validate::isDate($dateRange['date_from']) || !Validate::isDate($dateRange['date_to'])) {
if (!$hasMissingRowError) {
$hasMissingRowError = true;
$this->errors[] = Tools::displayError('Some dates are missing. Please select all the date ranges.');
}
$rowsToHighlight[] = $key;
}
}
}
}
if (empty($this->errors)) {
if (!$prefix) {
$roomsInfo['prefix'] = $objProduct->name[0].'R';
} else {
$roomsInfo['prefix'] = $prefix;
}
for ($i = 0; $i < $roomQuantity; $i++) {
$roomNum = $roomsInfo['prefix'];
if ((int) $roomNumber) {
$roomNum .= '-'.($roomNumber + $i);
}
$objHotelRoomInfo = new HotelRoomInformation();
$objHotelRoomInfo->id_product = $objProduct->id;
$objHotelRoomInfo->id_hotel = $idHotel;
$objHotelRoomInfo->id_status = $roomsInfo['id_status'];
$objHotelRoomInfo->room_num = trim($roomNum);
if (isset($roomsInfo['floor']) && $roomsInfo['floor'] != '') {
$objHotelRoomInfo->floor = $roomsInfo['floor'];
}
if (isset($roomsInfo['comment']) && $roomsInfo['comment'] != '') {
$objHotelRoomInfo->comment = $roomsInfo['comment'];
}
if ($objHotelRoomInfo->save() && $objHotelRoomInfo->id_status == HotelRoomInformation::STATUS_TEMPORARY_INACTIVE) {
foreach ($disableDates as $key => $dateRange) {
$objHotelRoomDisableDates = new HotelRoomDisableDates();
$objHotelRoomDisableDates->id_room_type = $objHotelRoomInfo->id_product;
$objHotelRoomDisableDates->id_room = $objHotelRoomInfo->id;
$objHotelRoomDisableDates->date_from = $dateRange['date_from'];
$objHotelRoomDisableDates->date_to = $dateRange['date_to'];
$objHotelRoomDisableDates->reason = $dateRange['reason'];
$objHotelRoomDisableDates->save();
}
}
}
$response['status'] = true;
$response['href'] = self::$currentIndex.'&update'.$this->table.'&id_product='.$idProduct.'&token='.$this->token.'&conf=4&key_tab=Configuration';
} else {
$rowsToHighlight = array_values(array_unique($rowsToHighlight));
$response['rows_to_highlight'] = $rowsToHighlight;
}
} else {
$this->errors[] = Tools::displayError('Room type not found.');
}
} else {
$this->errors[] = Tools::displayError('You do not have permission to perform this operation.');
}
$this->assignAlerts();
$response['msg'] = $this->context->smarty->fetch('alerts.tpl');
$this->ajaxDie(json_encode($response));
}
public function processImageLegends()
{
if (Tools::getValue('key_tab') == 'Images' && Tools::getValue('submitAddproductAndStay') == 'update_legends' && Validate::isLoadedObject($product = new Product((int)Tools::getValue('id_product')))) {