Optimized code for the max global booking dates

This commit is contained in:
vishalsingh.qlo325
2024-07-08 18:33:58 +05:30
parent f13c672400
commit fa86af848a
4 changed files with 10 additions and 19 deletions

View File

@@ -82,23 +82,21 @@ class AdminOrderPreferencesControllerCore extends AdminController
)
);
$maxOrderDate = (Tools::getValue('MAX_GLOBAL_BOOKING_DATE'))? Tools::getValue('MAX_GLOBAL_BOOKING_DATE') : Configuration::get('MAX_GLOBAL_BOOKING_DATE');
$maxOrderDate = Tools::getValue('MAX_GLOBAL_BOOKING_DATE', Configuration::get('MAX_GLOBAL_BOOKING_DATE'));
$this->fields_options = array(
'order_restrict' => array(
'title' => $this->l('Order Restrict'),
'icon' => 'icon-cogs',
'fields' => array(
'max_global_booking_date_formatted' => array(
'MAX_GLOBAL_BOOKING_DATE' => array(
'title' => $this->l('Maximum Global Check-out Date to book a room'),
'hint' => $this->l('Maximum date of check-out for which rooms of your hotels can be booked.'),
'defaultValue' => date('d-m-Y', strtotime($maxOrderDate)),
'type' => 'text',
'id' => 'max_global_book_date',
'auto_value' => false,
'value' => date('d-m-Y', strtotime($maxOrderDate)),
'class' => 'fixed-width-xxl readonly',
),
'MAX_GLOBAL_BOOKING_DATE' => array(
'type' => 'hidden',
),
'GLOBAL_PREPARATION_TIME' => array(
'title' => $this->l('Preparation time'),
'hint' => $this->l('Number of days required to prepare a room for a guest\'s stay. For example, if you set this value to 3 and someone is booking on 2nd of March he can only book rooms for dates from and after 3 days, i.e, 5th of March.'),
@@ -334,8 +332,6 @@ class AdminOrderPreferencesControllerCore extends AdminController
$this->errors[] = Tools::displayError('Please assign a valid CMS page for Terms and Conditions.');
}
// To prevent this from saving in the configuration table
unset($_POST['max_global_booking_date_formatted']);
$_POST['MAX_GLOBAL_BOOKING_DATE'] = date('Y-m-d', strtotime(Tools::getValue('MAX_GLOBAL_BOOKING_DATE')));
$maxGlobalBookingDate = Tools::getValue('MAX_GLOBAL_BOOKING_DATE');
$globalPreparationTime = Tools::getValue('GLOBAL_PREPARATION_TIME');

View File

@@ -162,9 +162,9 @@ class AdminAddHotelController extends ModuleAdminController
$restrictDateInfo = HotelOrderRestrictDate::getDataByHotelId($idHotel);
if ($restrictDateInfo) {
if ($restrictDateInfo['max_order_date'] == '0000-00-00') {
$restrictDateInfo['max_order_date'] = date('Y-m-d', strtotime('1 year'));
$restrictDateInfo['max_order_date'] = date('d-m-Y', strtotime('1 year'));
} else {
$restrictDateInfo['max_order_date'] = date('Y-m-d', strtotime($restrictDateInfo['max_order_date']));
$restrictDateInfo['max_order_date'] = date('d-m-Y', strtotime($restrictDateInfo['max_order_date']));
}
}
$smartyVars['order_restrict_date_info'] = $restrictDateInfo;

View File

@@ -556,8 +556,6 @@ $(document).ready(function() {
$("#max_global_book_date").datepicker({
defaultDate: new Date(),
dateFormat: 'dd-mm-yy',
altFormat: 'yy-mm-dd',
altField: 'input[name="MAX_GLOBAL_BOOKING_DATE"]',
minDate: 0,
});
@@ -803,19 +801,17 @@ $(document).ready(function() {
}
// manage hotel page
$('#maximum_booking_date_formatted').datepicker({
$('#maximum_booking_date').datepicker({
defaultDate: new Date(),
dateFormat: 'dd-mm-yy',
altFormat: 'yy-mm-dd',
altField: 'input[name="maximum_booking_date"]',
minDate: 0,
});
$('input[name="enable_use_global_max_order_date"]').on('change', function () {
if (parseInt($(this).val())) {
$('input[name="maximum_booking_date_formatted"]').closest('.form-group').hide(200);
$('input[name="maximum_booking_date"]').closest('.form-group').hide(200);
} else {
$('input[name="maximum_booking_date_formatted"]').closest('.form-group').show(200);
$('input[name="maximum_booking_date"]').closest('.form-group').show(200);
}
});

View File

@@ -363,8 +363,7 @@
<div class="form-group" {if isset($smarty.post.enable_use_global_max_order_date)}{if !$smarty.post.enable_use_global_max_order_date}style="display:block;"{else}style="display:none;"{/if}{elseif isset($order_restrict_date_info.use_global_max_order_date) && !$order_restrict_date_info.use_global_max_order_date}style="display:block;" {else} style="display:none;" {/if}>
<label class="control-label col-sm-3 required" for="maximum_booking_date">{l s='Maximum Check-out Date to book a room :' mod='hotelreservationsystem'}</label>
<div class="col-sm-2">
<input type="text" class="form-control" id="maximum_booking_date_formatted" name="maximum_booking_date_formatted" value="{if isset($smarty.post.maximum_booking_date_formatted)}{$smarty.post.maximum_booking_date_formatted|escape:'html':'UTF-8'}{elseif isset($edit) && isset($order_restrict_date_info.max_order_date)}{date('d-m-Y', strtotime($order_restrict_date_info.max_order_date|escape:'htmlall':'UTF-8'))}{/if}" />
<input type="hidden" name="maximum_booking_date" value="{if isset($order_restrict_date_info.max_order_date)}{$order_restrict_date_info.max_order_date|escape:'htmlall':'UTF-8'}{/if}"/>
<input type="text" class="form-control" id="maximum_booking_date" name="maximum_booking_date" value="{if isset($order_restrict_date_info.max_order_date)}{$order_restrict_date_info.max_order_date|escape:'htmlall':'UTF-8'}{/if}" />
</div>
</div>
<div class="form-group">