From f9b41e44a6027bdc914b705ed2e834b2fea06c48 Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Tue, 17 Jun 2025 20:03:38 +0530 Subject: [PATCH] Code optmization, add changed the view for the date range restrictions in the advance price rules --- .../classes/HotelRoomTypeFeaturePricing.php | 11 +- .../HotelRoomTypeFeaturePricingRule.php | 2 +- .../admin/AdminHotelFeaturePricesSettings.php | 5 +- .../views/css/HotelReservationAdmin.css | 30 ++--- .../views/js/HotelReservationAdmin.js | 109 ++++++++++++++---- .../admin/_partials/feature_price_rules.tpl | 66 ++++++++--- .../helpers/form/form.tpl | 4 +- 7 files changed, 165 insertions(+), 62 deletions(-) diff --git a/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php b/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php index 8ee68dcfd..1052aeaf2 100644 --- a/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php +++ b/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php @@ -128,7 +128,8 @@ class HotelRoomTypeFeaturePricing extends ObjectModel $this->cleanGroups(); $objFeaturePriceRule = new HotelRoomTypeFeaturePricingRule(); if ($oldFeaturePriceRules = $objFeaturePriceRule->getRulesByIdFeaturePrice($this->id)) { - $objFeaturePriceRule->deleteFeaturePriceRules($oldFeaturePriceRules); + $oldFeaturePriceRules = array_column($oldFeaturePriceRules, 'id_feature_price_rule', 'id_feature_price_rule'); + $objFeaturePriceRule->deleteFeaturePriceRulesById($oldFeaturePriceRules); } return parent::delete(); @@ -180,7 +181,7 @@ class HotelRoomTypeFeaturePricing extends ObjectModel return Db::getInstance()->executeS($sql); } - public function saveUpdateFeaturePrices($idFeaturePrice, $featurePriceRules) + public function saveFeaturePricesRules($idFeaturePrice, $featurePriceRules) { $res = true; $objFeaturePriceRule = new HotelRoomTypeFeaturePricingRule(); @@ -222,7 +223,7 @@ class HotelRoomTypeFeaturePricing extends ObjectModel } if ($oldFeaturePriceRules) { - $res &= $objFeaturePriceRule->deleteFeaturePriceRules($oldFeaturePriceRules); + $res &= $objFeaturePriceRule->deleteFeaturePriceRulesById($oldFeaturePriceRules); } return $res; @@ -657,7 +658,7 @@ class HotelRoomTypeFeaturePricing extends ObjectModel } } - return $this->saveUpdateFeaturePrices($this->id, $priceRules); + return $this->saveFeaturePricesRules($this->id, $priceRules); } public function validateExistingFeaturePrice( @@ -865,7 +866,7 @@ class HotelRoomTypeFeaturePricing extends ObjectModel $objFeaturePricing->active = isset($params['active']) ? $params['active'] : 1; $objFeaturePricing->groupBox = !empty($params['groupBox']) ? $params['groupBox'] : array_column(Group::getGroups($context->language->id), 'id_group'); if ($objFeaturePricing->add()) { - $objFeaturePricing->saveUpdateFeaturePrices($objFeaturePricing->id, $params['price_rules']); + $objFeaturePricing->saveFeaturePricesRules($objFeaturePricing->id, $params['price_rules']); } return $objFeaturePricing->id; diff --git a/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricingRule.php b/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricingRule.php index 769708ad7..c2505d3ad 100644 --- a/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricingRule.php +++ b/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricingRule.php @@ -64,7 +64,7 @@ class HotelRoomTypeFeaturePricingRule extends ObjectModel return Db::getInstance()->executeS($sql); } - public function deleteFeaturePriceRules($featurePriceRules) + public function deleteFeaturePriceRulesById($featurePriceRules) { $res = true; if ($featurePriceRules) { diff --git a/modules/hotelreservationsystem/controllers/admin/AdminHotelFeaturePricesSettings.php b/modules/hotelreservationsystem/controllers/admin/AdminHotelFeaturePricesSettings.php index 02d335244..3fcabe368 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminHotelFeaturePricesSettings.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminHotelFeaturePricesSettings.php @@ -562,7 +562,7 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController $objFeaturePricing->id_product = $idRoomType; $objFeaturePricing->feature_price_name = $featurePricingName[$idRoomType]; $objFeaturePricing->add(); - $objFeaturePricing->saveUpdateFeaturePrices($objFeaturePricing->id, $priceRules); + $objFeaturePricing->saveFeaturePricesRules($objFeaturePricing->id, $priceRules); } Tools::redirectAdmin(self::$currentIndex.'&conf=3&token='.$this->token); @@ -572,7 +572,7 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController $conf = $idFeaturePrice ? 4 : 3; if ($objFeaturePricing->save()) { - $objFeaturePricing->saveUpdateFeaturePrices($objFeaturePricing->id, $priceRules); + $objFeaturePricing->saveFeaturePricesRules($objFeaturePricing->id, $priceRules); if (Tools::isSubmit('submitAdd'.$this->table.'AndStay')) { Tools::redirectAdmin( self::$currentIndex.'&id_feature_price='.(int) $objFeaturePricing->id. @@ -648,7 +648,6 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController 'fixed' => HotelRoomTypeFeaturePricing::IMPACT_TYPE_FIXED_PRICE, ), 'week_days' => $this->getWeekDays(), - 'priceRuleHeadingText' => $this->l('Price rule restriction', null, true), 'dateSelectionTitle' => $this->l('Date Selection type', null, true), 'specificDateText' => $this->l('Specific Date', null, true), 'dateFromText' => $this->l('Date From', null, true), diff --git a/modules/hotelreservationsystem/views/css/HotelReservationAdmin.css b/modules/hotelreservationsystem/views/css/HotelReservationAdmin.css index 588e8be99..32debf8aa 100644 --- a/modules/hotelreservationsystem/views/css/HotelReservationAdmin.css +++ b/modules/hotelreservationsystem/views/css/HotelReservationAdmin.css @@ -507,7 +507,7 @@ p.room_cat_data display: flex; } .week_days .checkboxes-wrap .day-wrap { - min-width: 50px; + min-width: 45px; } .room_type_search_results_ul { padding: 0px; @@ -616,23 +616,27 @@ body.adminhotelroomsbooking .ui-tooltip { border: 1px solid #ddd } -a.remove_advanced_price_rule { - position: absolute; - right: 5px; - top: -8px;} #advanced_price_rule_group .panel.advanced_price_rule { padding: 0px;} -#advanced_price_rule_group .advance_price_rule_header { +#advanced_price_rule_group .advance_price_rule_header_container { padding: 15px;} -#advanced_price_rule_group .advance_price_rule_header:hover { +#advanced_price_rule_group .advance_price_rule_header_container:hover { cursor: pointer;} -.advance_price_rule_header i.icon-caret-down, -.advance_price_rule_header.collapsed i.icon-caret-up{ +.advance_price_rule_header_container { display: none;} -.advance_price_rule_header.collapsed i.icon-caret-down{ - display: block;} -.advanced_price_rule_body { - border-top: 1px solid #d3d3d3;} +.advance_price_rule_header_container.shown{ + align-items: center; + display: flex;} +.advanced_price_rule_body .advanced_price_rule_body_actions{ + display: none; +} +.advanced_price_rule_body.in .advanced_price_rule_body_actions, +.advanced_price_rule_body.in .advanced_price_rule_body_actions{ + display: block; +} +.special_days_heading{ + font-size: 11px; +} .advanced_price_rule_body .form-group:first-child { margin-top: 15px;} .error-border { diff --git a/modules/hotelreservationsystem/views/js/HotelReservationAdmin.js b/modules/hotelreservationsystem/views/js/HotelReservationAdmin.js index 1502f6205..f7903eb0e 100644 --- a/modules/hotelreservationsystem/views/js/HotelReservationAdmin.js +++ b/modules/hotelreservationsystem/views/js/HotelReservationAdmin.js @@ -631,6 +631,62 @@ $(document).ready(function() { }); const dateToday = $.datepicker.formatDate('yy-mm-dd', new Date()); + const tomorrow = new Date(); + tomorrow.setDate(tomorrow.getDate() + 1); + const dateTomorrow = $.datepicker.formatDate('yy-mm-dd', tomorrow); + $(document).find('.advanced_price_rule').each(function () { + udpateCollapseHeading($(this)); + }); + $(document).on('hide.bs.collapse', function(e) { + if ($(e.target).hasClass('advanced_price_rule_body')) { + let elem = $(e.target).closest('.advanced_price_rule'); + udpateCollapseHeading(elem); + $(elem).find('.advance_price_rule_header_container').addClass('shown'); + } + }); + + function udpateCollapseHeading(elem) { + let priceRuleHeadingText = ''; + let rowIndex = parseInt($(elem).data('advanced_price_rule_index')); + let selecteDateType = $('#date_selection_type_'+rowIndex).val(); + if (selecteDateType == date_selection_types.range.value) { + let dateFrom = $('#feature_plan_date_from_'+rowIndex).val(); + let dateTo = $('#feature_plan_date_to_'+rowIndex).val(); + priceRuleHeadingText = date_selection_types.range.title + ' ('+ dateFrom+ ' - '+ dateTo +')' + if (parseInt($('[name="advance_price_rule['+rowIndex+'][is_special_days_exists]"]:checked').val())) { + let special_days = []; + $('[name="advance_price_rule['+rowIndex+'][special_days][]"]').each(function(){ + if ($(this).prop('checked')) { + special_days.push($(this).parent().text().trim()); + } + }); + + if (special_days.length != 0) { + priceRuleHeadingText += '
(' + $(special_days).each(function(index, value) { + priceRuleHeadingText += value; + if (index != special_days.length-1) { + priceRuleHeadingText += ', '; + } + }); + priceRuleHeadingText += ')' + } + } + } else if (selecteDateType == date_selection_types.specific.value) { + priceRuleHeadingText = date_selection_types.specific.title; + let date = $('#specific_date_'+rowIndex).val(); + priceRuleHeadingText += ' ('+ date +')' + } + + $(elem).find('.advance_price_rule_header').html(priceRuleHeadingText); + } + + $(document).on('shown.bs.collapse', function(e) { + if ($(e.target).hasClass('advanced_price_rule_body')) { + $(e.target).closest('.advanced_price_rule').find('.advance_price_rule_header_container').removeClass('shown'); + } + }); + $(document).on('click', '#add_more_dates_button', function() { let dateSeletionOptions = $('').attr('type', 'hidden').attr('name', 'advance_price_rule['+panelIndex+'][id]') - let headerElem = $('
').addClass('row advance_price_rule_header collapsed').attr({'data-toggle':"collapse", 'data-target':"#advanced_price_rule_"+panelIndex}) - .append($('
').addClass('col-xs-8 col-sm-10').text(priceRuleHeadingText)) - .append($('
').addClass('col-xs-1 pull-right') - .append($('
').addClass('col-xs-8') + let headerElem = $('
').addClass('row advance_price_rule_header_container advance_price_rule_collapse').attr({'data-toggle':"collapse", 'data-target':"#advanced_price_rule_"+panelIndex}) + .append($('
').addClass('col-xs-8 advance_price_rule_header')) + .append($('
').addClass('col-xs-4') + .append($('
').addClass('col-xs-7')) + .append($('
').addClass('col-xs-2') + .append($('').addClass('btn btn-default remove_advanced_price_rule') + .append($('').append($('').addClass('icon-trash'))))) + .append($('
').addClass('col-xs-1')) + .append($('
').addClass('col-xs-2') + .append($('').addClass('btn btn-default') + .append($('').addClass('icon-caret-down'))))); + + let dateSelectionElem = $('
').addClass('form-group') + .append($('
').addClass('col-xs-5') + .append($(dateSeletionOptions).attr({'name': 'advance_price_rule['+panelIndex+'][date_selection_type]', 'id': 'date_selection_type_'+panelIndex}))) + .append($('
').addClass('col-xs-3 advanced_price_rule_body_actions') + .append($('
').addClass('col-xs-offset-4 col-xs-4') .append($('').addClass('btn btn-default remove_advanced_price_rule') .append($('').append($('').addClass('icon-trash'))))) .append($('
').addClass('col-xs-4') - .append($('').addClass('icon-caret-down')) - .append($('').addClass('icon-caret-up')))); - - let dateSelectionElem = $('
').addClass('form-group') - .append($('
').addClass('col-xs-6') - .append($(dateSeletionOptions).attr({'name': 'advance_price_rule['+panelIndex+'][date_selection_type]', 'id': 'date_selection_type_'+panelIndex}))); + .append($('').addClass('btn btn-default').attr({'data-toggle':"collapse", 'data-target':"#advanced_price_rule_"+panelIndex}) + .append($('').addClass('icon-caret-up'))))); let specificDateElem = $('
').addClass('form-group specific_date_type_'+panelIndex).css('display', 'none') - .append($('
').addClass('col-xs-6') + .append($('
').addClass('col-xs-5') .append($('').addClass('specific_date form-control datepicker-input') .attr({type:'text', id: 'specific_date_'+panelIndex, name: 'advance_price_rule['+panelIndex+'][specific_date]', value: dateToday, readonly: 'readonly'}))); let dateFromElem = $('
').addClass('form-group date_range_type_'+panelIndex) - .append($('
').addClass('col-xs-6') + .append($('
').addClass('col-xs-5') .append($('').addClass('feature_plan_date_from form-control datepicker-input') .attr({type:'text', id: 'feature_plan_date_from_'+panelIndex, name: 'advance_price_rule['+panelIndex+'][date_from]', value: dateToday, readonly: 'readonly'}))); let dateToElem = $('
').addClass('form-group date_range_type_'+panelIndex) - .append($('
').addClass('col-xs-6') + .append($('
').addClass('col-xs-5') .append($('').addClass('feature_plan_date_to form-control datepicker-input') - .attr({type:'text', id: 'feature_plan_date_to_'+panelIndex, name: 'advance_price_rule['+panelIndex+'][date_to]', value: dateToday, readonly: 'readonly'}))); + .attr({type:'text', id: 'feature_plan_date_to_'+panelIndex, name: 'advance_price_rule['+panelIndex+'][date_to]', value: dateTomorrow, readonly: 'readonly'}))); let specialDaysElement = $('
').addClass('form-group special_days_content_'+panelIndex) .append($('
').addClass('col-xs-6') + .append($('').addClass('label-tooltip').attr({'data-toggle': 'tooltip', 'data-html':'true', 'title': '', 'data-original-title': specialDaysTooltipText}).text(' '+specialDaysText))) + .append($('
').addClass('col-xs-5') .append($('').addClass('switch prestashop-switch fixed-width-lg') .append($('').attr({'type': 'radio', 'value': 1, 'name': 'advance_price_rule['+panelIndex+'][is_special_days_exists]', 'id': 'advance_price_rule['+panelIndex+'][is_special_days_exists_on]'}).addClass('is_special_days_exists')) .append($('
').addClass('form-group week_days week_days_'+panelIndex) - .append($('
').addClass('col-xs-8 checkboxes-wrap').append($(weekDaysOptions).html())) - let bodyElem = $('
').attr('id', 'advanced_price_rule_'+panelIndex).addClass('collapse advanced_price_rule_body') + let bodyElem = $('
').attr('id', 'advanced_price_rule_'+panelIndex).addClass('in advanced_price_rule_body') .append(dateSelectionElem) .append(specificDateElem) .append(dateFromElem) diff --git a/modules/hotelreservationsystem/views/templates/admin/_partials/feature_price_rules.tpl b/modules/hotelreservationsystem/views/templates/admin/_partials/feature_price_rules.tpl index 0e62baf1f..eeb9b470e 100644 --- a/modules/hotelreservationsystem/views/templates/admin/_partials/feature_price_rules.tpl +++ b/modules/hotelreservationsystem/views/templates/admin/_partials/feature_price_rules.tpl @@ -1,28 +1,50 @@ +{** +* 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 +*}
-
-
- {l s='Price rule restriction' mod='hotelreservationsystem'} -
-
-
+
+
+
+
+ -
- - +
+
-
+
-
-
+
@@ -47,7 +81,7 @@ -
+
@@ -55,7 +89,7 @@ -
+
@@ -66,7 +100,7 @@ {l s='Restrict to Week Days' mod='hotelreservationsystem'} -
+
@@ -77,7 +111,7 @@
-
+
diff --git a/modules/hotelreservationsystem/views/templates/admin/hotel_feature_prices_settings/helpers/form/form.tpl b/modules/hotelreservationsystem/views/templates/admin/hotel_feature_prices_settings/helpers/form/form.tpl index 8673ff040..d8ee18507 100644 --- a/modules/hotelreservationsystem/views/templates/admin/hotel_feature_prices_settings/helpers/form/form.tpl +++ b/modules/hotelreservationsystem/views/templates/admin/hotel_feature_prices_settings/helpers/form/form.tpl @@ -114,7 +114,7 @@
@@ -127,7 +127,7 @@ {include file="../../../_partials/feature_price_rules.tpl" key=$key advancePriceRule=$rule} {/foreach} {else} - {include file="../../../_partials/feature_price_rules.tpl" key=0} + {include file="../../../_partials/feature_price_rules.tpl" key=0 collapse=true} {/if}