diff --git a/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php b/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php index 26ffaf3c4..ca621a1fd 100644 --- a/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php +++ b/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php @@ -85,8 +85,8 @@ class HotelRoomTypeFeaturePricing extends ObjectModel 'groups' => array('resource' => 'group'), 'restrictions' => array( 'resource' => 'price_rule', - 'getter' => 'getWsAdvancePriceRestriction', - 'setter' => 'setWsAdvancePriceRestriction', + 'getter' => 'getWsFeaturePriceRestriction', + 'setter' => 'setWsFeaturePriceRestriction', 'fields' => array( 'id' => array(), 'date_from' => array(), @@ -127,47 +127,50 @@ class HotelRoomTypeFeaturePricing extends ObjectModel // first call to delete all the group entries $this->cleanGroups(); $objFeaturePriceRestriction = new HotelRoomTypeFeaturePricingRestriction(); - if ($oldFeaturePriceRestrictions = $objFeaturePriceRestriction->getRestrictionsByIdFeaturePrice($this->id)) { - $oldFeaturePriceRestrictions = array_column($oldFeaturePriceRestrictions, 'id_feature_price_restriction', 'id_feature_price_restriction'); - $objFeaturePriceRestriction->deleteFeaturePriceRestrictionsById($oldFeaturePriceRestrictions); + if ($existingFeaturePrices = $objFeaturePriceRestriction->getRestrictionsByIdFeaturePrice($this->id)) { + $existingFeaturePrices = array_column($existingFeaturePrices, 'id_feature_price_restriction', 'id_feature_price_restriction'); + $objFeaturePriceRestriction->deleteFeaturePriceRestrictionsById($existingFeaturePrices); } return parent::delete(); } - public function getExistingFeaturePriceRules( + public function getFeaturePrices( $idRoomType, - $groups, - $idFeaturePrice, - $featurePriceRules + $restrictions = array(), + $groups = array(), + $skipFeaturePriceId = null, + $active = null ) { $sql = 'SELECT *, GROUP_CONCAT(rtfpg.`id_group`) AS id_group FROM `'._DB_PREFIX_.'htl_room_type_feature_pricing_restriction` rtfpr LEFT JOIN `'._DB_PREFIX_.'htl_room_type_feature_pricing` rtfp ON (rtfpr.`id_feature_price` = rtfp.`id_feature_price` AND rtfp.`id_product`='.(int) $idRoomType.') LEFT JOIN `'._DB_PREFIX_.'htl_room_type_feature_pricing_group` rtfpg - ON (rtfp.`id_feature_price` = rtfpg.`id_feature_price` AND rtfpg.`id_group` IN ('.pSQL(implode(', ',$groups)).')) - WHERE rtfpr.`id_feature_price`!='.(int) $idFeaturePrice.' AND rtfp.`active`= 1'; + ON (rtfp.`id_feature_price` = rtfpg.`id_feature_price` '.($groups ? ' AND rtfpg.`id_group` IN ('.pSQL(implode(', ',$groups)).')' : ' ' ).') + WHERE 1 '.( !is_null($active) ? ' AND rtfp.`active`= '.(int) $active: ' ').' ' .(!is_null($skipFeaturePriceId) ? ' AND rtfpr.`id_feature_price`!='.(int) $skipFeaturePriceId : ' '); $sqlWhere = ''; - foreach ($featurePriceRules as $featurePriceRule) { - if ($sqlWhere != '') { - $sqlWhere .= ' OR '; - } + if ($restrictions && is_array($restrictions)) { + foreach ($restrictions as $restriction) { + if ($sqlWhere != '') { + $sqlWhere .= ' OR '; + } - $dateFrom = date('Y-m-d', strtotime($featurePriceRule['date_from'])); - $dateTo = date('Y-m-d', strtotime($featurePriceRule['date_to'])); - if ($featurePriceRule['date_selection_type'] == self::DATE_SELECTION_TYPE_SPECIFIC) { - $sqlWhere .= ' (rtfpr.`date_selection_type` = '.(int) self::DATE_SELECTION_TYPE_SPECIFIC.' - AND rtfpr.`date_from` = \''.pSQL($dateFrom).'\')'; - } else if ($featurePriceRule['date_selection_type'] == self::DATE_SELECTION_TYPE_RANGE) { - if ($featurePriceRule['is_special_days_exists']) { - $sqlWhere .= ' (rtfpr.`is_special_days_exists`=1 - AND rtfpr.`date_from` <= \''.pSQL($dateTo).'\' - AND rtfpr.`date_to` >= \''.pSQL($dateFrom).'\')'; - } else { - $sqlWhere .= ' (rtfpr.`date_selection_type` = '.(int) self::DATE_SELECTION_TYPE_RANGE.' - AND rtfpr.`is_special_days_exists`=0 - AND rtfpr.`date_from` <= \''.pSQL($dateTo).'\' - AND rtfpr.`date_to` >= \''.pSQL($dateFrom).'\')'; + $dateFrom = date('Y-m-d', strtotime($restriction['date_from'])); + $dateTo = date('Y-m-d', strtotime($restriction['date_to'])); + if ($restriction['date_selection_type'] == self::DATE_SELECTION_TYPE_SPECIFIC) { + $sqlWhere .= ' (rtfpr.`date_selection_type` = '.(int) self::DATE_SELECTION_TYPE_SPECIFIC.' + AND rtfpr.`date_from` = \''.pSQL($dateFrom).'\')'; + } else if ($restriction['date_selection_type'] == self::DATE_SELECTION_TYPE_RANGE) { + if ($restriction['is_special_days_exists']) { + $sqlWhere .= ' (rtfpr.`is_special_days_exists`=1 + AND rtfpr.`date_from` <= \''.pSQL($dateTo).'\' + AND rtfpr.`date_to` >= \''.pSQL($dateFrom).'\')'; + } else { + $sqlWhere .= ' (rtfpr.`date_selection_type` = '.(int) self::DATE_SELECTION_TYPE_RANGE.' + AND rtfpr.`is_special_days_exists`=0 + AND rtfpr.`date_from` <= \''.pSQL($dateTo).'\' + AND rtfpr.`date_to` >= \''.pSQL($dateFrom).'\')'; + } } } } @@ -181,19 +184,19 @@ class HotelRoomTypeFeaturePricing extends ObjectModel return Db::getInstance()->executeS($sql); } - public function saveFeaturePriceRestrictions($idFeaturePrice, $featurePriceRules) + public function saveFeaturePriceRestrictions($idFeaturePrice, $restrictions) { $res = true; $objFeaturePriceRestriction = new HotelRoomTypeFeaturePricingRestriction(); - if ($oldFeaturePriceRestrictions = $objFeaturePriceRestriction->getRestrictionsByIdFeaturePrice($idFeaturePrice)) { - $oldFeaturePriceRestrictions = array_column($oldFeaturePriceRestrictions, 'id_feature_price_restriction', 'id_feature_price_restriction'); + if ($existingFeaturePrices = $objFeaturePriceRestriction->getRestrictionsByIdFeaturePrice($idFeaturePrice)) { + $existingFeaturePrices = array_column($existingFeaturePrices, 'id_feature_price_restriction', 'id_feature_price_restriction'); } - if ($featurePriceRules) { - foreach ($featurePriceRules as $featurePriceRule) { - if (isset($featurePriceRule['id']) && in_array($featurePriceRule['id'], $oldFeaturePriceRestrictions)) { + if ($restrictions) { + foreach ($restrictions as $featurePriceRule) { + if (isset($featurePriceRule['id']) && in_array($featurePriceRule['id'], $existingFeaturePrices)) { $objFeaturePriceRestriction = new HotelRoomTypeFeaturePricingRestriction($featurePriceRule['id']); - unset($oldFeaturePriceRestrictions[$featurePriceRule['id']]); + unset($existingFeaturePrices[$featurePriceRule['id']]); } else { $objFeaturePriceRestriction = new HotelRoomTypeFeaturePricingRestriction(); } @@ -222,14 +225,13 @@ class HotelRoomTypeFeaturePricing extends ObjectModel } } - if ($oldFeaturePriceRestrictions) { - $res &= $objFeaturePriceRestriction->deleteFeaturePriceRestrictionsById($oldFeaturePriceRestrictions); + if ($existingFeaturePrices) { + $res &= $objFeaturePriceRestriction->deleteFeaturePriceRestrictionsById($existingFeaturePrices); } return $res; } - /** * [countFeaturePriceSpecialDays returns number of special days between a date range] * @param [array] $specialDays [array containing special days to be counted] @@ -638,7 +640,7 @@ class HotelRoomTypeFeaturePricing extends ObjectModel return true; } - public function getWsAdvancePriceRestriction() + public function getWsFeaturePriceRestriction() { return Db::getInstance()->executeS( 'SELECT *, id_feature_price_restriction AS `id` FROM `'._DB_PREFIX_.'htl_room_type_feature_pricing_restriction` @@ -647,55 +649,56 @@ class HotelRoomTypeFeaturePricing extends ObjectModel } - public function setWsAdvancePriceRestriction($priceRules) + public function setWsFeaturePriceRestriction($restrictions) { - foreach ($priceRules as $ruleKey => $priceRule) { - if ($priceRule['date_selection_type'] == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_RANGE - && $priceRule['is_special_days_exists'] + foreach ($restrictions as $restrictionKey => $restriction) { + if ($restriction['date_selection_type'] == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_RANGE + && $restriction['is_special_days_exists'] ) { - $specialDays = json_decode($priceRule['special_days'], true); - $priceRules[$ruleKey]['special_days'] = $specialDays; + $specialDays = json_decode($restriction['special_days'], true); + $restrictions[$restrictionKey]['special_days'] = $specialDays; } } - return $this->saveFeaturePriceRestrictions($this->id, $priceRules); + return $this->saveFeaturePriceRestrictions($this->id, $restrictions); } - public function validateExistingFeaturePrice( + public function getDuplicateRestrictions( $roomTypeId, - $group, - $idFeaturePrice, - $featurePriceRules + $groups, + $skipFeaturePriceId, + $restrictions ) { - $duplicateRules = array(); - if ($oldPriceRules = $this->getExistingFeaturePriceRules( + $duplicateRestrictions = array(); + if ($existingFeturePrices = $this->getFeaturePrices( $roomTypeId, - $group, - $idFeaturePrice, - $featurePriceRules + $restrictions, + $groups, + $skipFeaturePriceId, + true )) { - foreach ($oldPriceRules as $oldPriceRule) { - foreach ($featurePriceRules as $ruleKey => $rule) { - if ($rule['date_selection_type'] == $oldPriceRule['date_selection_type']) { - if ($rule['date_selection_type'] == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_SPECIFIC) { - if (strtotime($rule['date_from']) != strtotime($oldPriceRule['date_from'])) { + foreach ($existingFeturePrices as $existingFeturePrice) { + foreach ($restrictions as $restrictionKey => $restriction) { + if ($restriction['date_selection_type'] == $existingFeturePrice['date_selection_type']) { + if ($restriction['date_selection_type'] == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_SPECIFIC) { + if (strtotime($restriction['date_from']) != strtotime($existingFeturePrice['date_from'])) { continue; } else { - $duplicateRules[] = $ruleKey; + $duplicateRestrictions[] = $restrictionKey; } - } else if ($rule['date_selection_type'] == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_RANGE) { - if (((strtotime($oldPriceRule['date_from']) < strtotime($rule['date_from'])) && (strtotime($oldPriceRule['date_to']) <= strtotime($rule['date_from']))) || ((strtotime($oldPriceRule['date_from']) > strtotime($rule['date_from'])) && (strtotime($oldPriceRule['date_from']) >= strtotime($rule['date_to'])))) { + } else if ($restriction['date_selection_type'] == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_RANGE) { + if (((strtotime($existingFeturePrice['date_from']) < strtotime($restriction['date_from'])) && (strtotime($existingFeturePrice['date_to']) <= strtotime($restriction['date_from']))) || ((strtotime($existingFeturePrice['date_from']) > strtotime($restriction['date_from'])) && (strtotime($existingFeturePrice['date_from']) >= strtotime($restriction['date_to'])))) { continue; } else { - if ($oldPriceRule['is_special_days_exists'] && $rule['is_special_days_exists']) { - if (!empty($oldPriceRule['special_days']) && !empty($rule['special_days'])) { - $existingDays = json_decode($oldPriceRule['special_days'], true); - if (array_intersect($existingDays, $rule['special_days'])) { - $duplicateRules[] = $ruleKey; + if ($existingFeturePrice['is_special_days_exists'] && $restriction['is_special_days_exists']) { + if (!empty($existingFeturePrice['special_days']) && !empty($restriction['special_days'])) { + $existingDays = json_decode($existingFeturePrice['special_days'], true); + if (array_intersect($existingDays, $restriction['special_days'])) { + $duplicateRestrictions[] = $restrictionKey; } } } else { - $duplicateRules[] = $ruleKey; + $duplicateRestrictions[] = $restrictionKey; } } } @@ -704,13 +707,13 @@ class HotelRoomTypeFeaturePricing extends ObjectModel } } - return $duplicateRules; + return $duplicateRestrictions; } public function validateFields($die = true, $error_return = false) { if (isset($this->webservice_validation) && $this->webservice_validation) { - $priceRules = array(); + $restrictions = array(); $idGroups = array(); if (isset($this->associations)) { foreach ($this->associations->children() as $association) { @@ -724,7 +727,7 @@ class HotelRoomTypeFeaturePricing extends ObjectModel $entry[$fieldName] = (string)$fieldValue; } - $priceRules[] = $entry; + $restrictions[] = $entry; } } else if ($association->getName() == 'groups') { $assocItems = $association->children(); @@ -745,15 +748,15 @@ class HotelRoomTypeFeaturePricing extends ObjectModel $idGroups = array_column($idGroups, 'id'); } - if ($priceRules) { + if ($restrictions) { $hasError = false; $weekDays = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun']; // check for invalid special days - foreach ($priceRules as $ruleKey => $priceRule) { - if ($priceRule['date_selection_type'] == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_RANGE) { - if ($priceRule['is_special_days_exists']) { - $specialDays = json_decode($priceRule['special_days'], true); - $priceRules[$ruleKey]['special_days'] = $specialDays; + foreach ($restrictions as $restrictionKey => $restriction) { + if ($restriction['date_selection_type'] == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_RANGE) { + if ($restriction['is_special_days_exists']) { + $specialDays = json_decode($restriction['special_days'], true); + $restrictions[$restrictionKey]['special_days'] = $specialDays; if (is_array($specialDays) && $specialDays) { if (count(array_diff($specialDays, $weekDays))) { $message = Tools::displayError('Invalid special days. format must match with : ["mon", "tue", "wed", "thu", "fri", "sat", "sun"].', true); @@ -771,25 +774,25 @@ class HotelRoomTypeFeaturePricing extends ObjectModel if (!$hasError) { // check for conflicting dates in the rules. - foreach ($priceRules as $priceRuleKey => $priceRule) { - foreach ($priceRules as $ruleKey => $rule) { - if ($priceRuleKey != $ruleKey) { - if ($rule['date_selection_type'] == $priceRule['date_selection_type']) { - if ($rule['date_selection_type'] == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_SPECIFIC) { - if (strtotime($rule['date_from']) != strtotime($priceRule['date_from'])) { + foreach ($restrictions as $restrictionKey => $restriction) { + foreach ($restrictions as $priceRestrictionKey => $priceRestriction) { + if ($priceRestrictionKey != $restrictionKey) { + if ($priceRestriction['date_selection_type'] == $restriction['date_selection_type']) { + if ($priceRestriction['date_selection_type'] == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_SPECIFIC) { + if (strtotime($priceRestriction['date_from']) != strtotime($restriction['date_from'])) { continue; } else { $message = Tools::displayError('You can not add conflicting dates.', true); $hasError = true; break; } - } else if ($rule['date_selection_type'] == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_RANGE) { - if (((strtotime($priceRule['date_from']) < strtotime($rule['date_from'])) && (strtotime($priceRule['date_to']) <= strtotime($rule['date_from']))) || ((strtotime($priceRule['date_from']) > strtotime($rule['date_from'])) && (strtotime($priceRule['date_from']) >= strtotime($rule['date_to'])))) { + } else if ($priceRestriction['date_selection_type'] == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_RANGE) { + if (((strtotime($restriction['date_from']) < strtotime($priceRestriction['date_from'])) && (strtotime($restriction['date_to']) <= strtotime($priceRestriction['date_from']))) || ((strtotime($restriction['date_from']) > strtotime($priceRestriction['date_from'])) && (strtotime($restriction['date_from']) >= strtotime($priceRestriction['date_to'])))) { continue; } else { - if ($priceRule['is_special_days_exists'] && $rule['is_special_days_exists']) { - if (!empty($priceRule['special_days']) && !empty($rule['special_days'])) { - if (array_intersect($priceRule['special_days'], $rule['special_days'])) { + if ($restriction['is_special_days_exists'] && $priceRestriction['is_special_days_exists']) { + if (!empty($restriction['special_days']) && !empty($priceRestriction['special_days'])) { + if (array_intersect($restriction['special_days'], $priceRestriction['special_days'])) { $message = Tools::displayError('You can not add conflicting days for similar date ranges.', true); $hasError = true; break; @@ -810,11 +813,11 @@ class HotelRoomTypeFeaturePricing extends ObjectModel } if (!$hasError) { - $hasDuplicate = $this->validateExistingFeaturePrice( + $hasDuplicate = $this->getDuplicateRestrictions( $this->id_product, $idGroups, $this->id, - $priceRules + $restrictions ); if ($hasDuplicate) { diff --git a/modules/hotelreservationsystem/controllers/admin/AdminHotelFeaturePricesSettings.php b/modules/hotelreservationsystem/controllers/admin/AdminHotelFeaturePricesSettings.php index 237cf880a..6bfbd4ee7 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminHotelFeaturePricesSettings.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminHotelFeaturePricesSettings.php @@ -176,7 +176,7 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController $objFeaturePricing = $this->loadObject(); $objFeaturePriceRule = new HotelRoomTypeFeaturePricingRestriction(); if (!$objFeaturePricing->active) { - if ($this->object->validateExistingFeaturePrice( + if ($this->object->getDuplicateRestrictions( $objFeaturePricing->id_product, $objFeaturePricing->getGroups($objFeaturePricing->id), $objFeaturePricing->id, @@ -243,19 +243,19 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController $smartyVars['edit'] = 1; $objFeaturePriceRule = new HotelRoomTypeFeaturePricingRestriction(); - if ($advancePriceRules = $objFeaturePriceRule->getRestrictionsByIdFeaturePrice($objFeaturePrice->id)) { - foreach ($advancePriceRules as $priceRuleKey => $advancePriceRule) { - if ($advancePriceRule['date_selection_type'] == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_SPECIFIC) { - $advancePriceRules[$priceRuleKey]['specific_date'] = $advancePriceRule['date_from']; - unset($advancePriceRules[$priceRuleKey]['date_from']); - unset($advancePriceRules[$priceRuleKey]['date_to']); - } else if ($advancePriceRule['is_special_days_exists']) { - $advancePriceRules[$priceRuleKey]['special_days'] = json_decode($advancePriceRule['special_days'], true); + if ($restrictions = $objFeaturePriceRule->getRestrictionsByIdFeaturePrice($objFeaturePrice->id)) { + foreach ($restrictions as $restrictionKey => $restriction) { + if ($restriction['date_selection_type'] == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_SPECIFIC) { + $restrictions[$restrictionKey]['specific_date'] = $restriction['date_from']; + unset($restrictions[$restrictionKey]['date_from']); + unset($restrictions[$restrictionKey]['date_to']); + } else if ($restriction['is_special_days_exists']) { + $restrictions[$restrictionKey]['special_days'] = json_decode($restriction['special_days'], true); } } } - $smartyVars['advancePriceRules'] = $advancePriceRules; + $smartyVars['restrictions'] = $restrictions; $smartyVars['feature_price_groups'] = $objFeaturePrice->getGroups($idFeaturePrice); } else { $tree = new HelperTree('hotels-tree'); @@ -349,7 +349,7 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController $defaultLangId = Configuration::get('PS_LANG_DEFAULT'); $createMultiple = Tools::getValue('create_multiple'); - $priceRules = Tools::getValue('advance_price_rule', array()); + $restrictions = Tools::getValue('restriction', array()); $objFeaturePricing = new HotelRoomTypeFeaturePricing(); if ($priceImpactWay == HotelRoomTypeFeaturePricing::IMPACT_WAY_FIX_PRICE) { $priceImpactType = HotelRoomTypeFeaturePricing::IMPACT_TYPE_FIXED_PRICE; @@ -426,35 +426,35 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController } $rowsToHighlight = []; - if (!$priceRules) { + if (!$restrictions) { $this->errors[] = $this->l('Atleast one restriction is required while creating advance price rule.'); } else { - foreach ($priceRules as $priceRuleKey => $priceRule) { - if (!$priceRule['is_special_days_exists']) { - unset($priceRules[$priceRuleKey]['special_days']); + foreach ($restrictions as $restrictionKey => $restriction) { + if (!$restriction['is_special_days_exists']) { + unset($restrictions[$restrictionKey]['special_days']); } - if ($priceRule['date_selection_type'] == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_SPECIFIC) { - if ($priceRule['specific_date']) { - $priceRules[$priceRuleKey]['date_from'] = $priceRule['specific_date']; - $priceRules[$priceRuleKey]['date_to'] = date('Y-m-d', strtotime("+1 day", strtotime($priceRule['specific_date']))); + if ($restriction['date_selection_type'] == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_SPECIFIC) { + if ($restriction['specific_date']) { + $restrictions[$restrictionKey]['date_from'] = $restriction['specific_date']; + $restrictions[$restrictionKey]['date_to'] = date('Y-m-d', strtotime("+1 day", strtotime($restriction['specific_date']))); } else { - $rowsToHighlight[] = $priceRuleKey; + $rowsToHighlight[] = $restrictionKey; $this->errors = $this->l('Specific Date is missing for price rule restriction.'); } - } else if ($priceRule['date_selection_type'] == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_RANGE) { - if ($priceRule['date_from'] == '') { - $rowsToHighlight[] = $priceRuleKey; + } else if ($restriction['date_selection_type'] == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_RANGE) { + if ($restriction['date_from'] == '') { + $rowsToHighlight[] = $restrictionKey; $this->errors[] = $this->l('Dates are invalid in price rule restriction.'); - } else if ($priceRule['date_to'] == '') { + } else if ($restriction['date_to'] == '') { $this->errors[] = $this->l('Dates are invalid in price rule restriction'); - $rowsToHighlight[] = $priceRuleKey; + $rowsToHighlight[] = $restrictionKey; } - $dateFrom = date('Y-m-d', strtotime($priceRule['date_from'])); - $dateTo = date('Y-m-d', strtotime($priceRule['date_to'])); + $dateFrom = date('Y-m-d', strtotime($restriction['date_from'])); + $dateTo = date('Y-m-d', strtotime($restriction['date_to'])); if (!Validate::isDate($dateFrom)) { $this->errors[] = $this->l('Dates are invalid in price rule restriction'); - $rowsToHighlight[] = $priceRuleKey; + $rowsToHighlight[] = $restrictionKey; } if (!Validate::isDate($dateTo)) { $this->errors[] = $this->l('Dates are invalid in price rule restriction'); @@ -462,46 +462,48 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController if ($dateTo < $dateFrom) { $this->errors[] = $this->l('Dates are invalid in price rule restriction'); } - if ($priceRule['is_special_days_exists']) { - if (!isset($priceRule['special_days']) || !$priceRule['special_days']) { + if ($restriction['is_special_days_exists']) { + if (!isset($restriction['special_days']) || !$restriction['special_days']) { $this->errors[] = $this->l('Special days are missing for price rule having restrict to week days'); - $rowsToHighlight[] = $priceRuleKey; + $rowsToHighlight[] = $restrictionKey; } } - unset($priceRules[$priceRuleKey]['specific_date']); + unset($restrictions[$restrictionKey]['specific_date']); } else { - unset($priceRules[$priceRuleKey]); + unset($restrictions[$restrictionKey]); } - if ($priceRule['is_special_days_exists'] && empty($priceRule['special_days'])) { - $rowsToHighlight[] = $priceRuleKey; + if ($restriction['is_special_days_exists'] && empty($restriction['special_days'])) { + $rowsToHighlight[] = $restrictionKey; $this->errors[] = $this->l('Please select at least one day for week days restriction.'); } + } - foreach ($priceRules as $ruleKey => $rule) { - if ($priceRuleKey != $ruleKey) { - if ($rule['date_selection_type'] == $priceRule['date_selection_type']) { - if ($rule['date_selection_type'] == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_SPECIFIC) { - if (strtotime($rule['specific_date']) != strtotime($priceRule['specific_date'])) { + foreach ($restrictions as $restrictionKey => $restriction) { + foreach ($restrictions as $priceRestrictionKey => $priceRestriction) { + if ($restrictionKey != $priceRestrictionKey) { + if ($priceRestriction['date_selection_type'] == $restriction['date_selection_type']) { + if ($priceRestriction['date_selection_type'] == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_SPECIFIC) { + if (strtotime($priceRestriction['specific_date']) != strtotime($restriction['specific_date'])) { continue; } else { $this->errors[] = $this->l('Some dates are conflicting. Please check and reselect the dates.'); - $rowsToHighlight[] = $priceRuleKey; + $rowsToHighlight[] = $restrictionKey; } - } else if ($rule['date_selection_type'] == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_RANGE) { - if (((strtotime($priceRule['date_from']) < strtotime($rule['date_from'])) && (strtotime($priceRule['date_to']) <= strtotime($rule['date_from']))) || ((strtotime($priceRule['date_from']) > strtotime($rule['date_from'])) && (strtotime($priceRule['date_from']) >= strtotime($rule['date_to'])))) { + } else if ($priceRestriction['date_selection_type'] == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_RANGE) { + if (((strtotime($restriction['date_from']) < strtotime($priceRestriction['date_from'])) && (strtotime($restriction['date_to']) <= strtotime($priceRestriction['date_from']))) || ((strtotime($restriction['date_from']) > strtotime($priceRestriction['date_from'])) && (strtotime($restriction['date_from']) >= strtotime($priceRestriction['date_to'])))) { continue; } else { - if ($priceRule['is_special_days_exists'] && $rule['is_special_days_exists']) { - if (!empty($priceRule['special_days']) && !empty($rule['special_days'])) { - if (array_intersect($priceRule['special_days'], $rule['special_days'])) { + if ($restriction['is_special_days_exists'] && $priceRestriction['is_special_days_exists']) { + if (!empty($restriction['special_days']) && !empty($priceRestriction['special_days'])) { + if (array_intersect($restriction['special_days'], $priceRestriction['special_days'])) { $this->errors[] = $this->l('Some days are conflicting. Please check and update the special days.'); - $rowsToHighlight[] = $priceRuleKey; + $rowsToHighlight[] = $restrictionKey; } } } else { $this->errors[] = $this->l('Some dates are conflicting. Please check and reselect the date ranges.'); - $rowsToHighlight[] = $priceRuleKey; + $rowsToHighlight[] = $restrictionKey; } } } @@ -521,19 +523,19 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController $this->errors[] = $this->l('Please select at least one group for the group access'); } - $duplicatePriceRuleKey = 0; + $duplicateRestrictionKey = 0; if (empty($this->errors) && $enableFeaturePrice) { $objFeaturePricing = new HotelRoomTypeFeaturePricing(); foreach ($roomTypeIds as $idRoomType) { - $duplicatePriceRuleKey = $this->object->validateExistingFeaturePrice( + $duplicateRestrictionKey = $this->object->getDuplicateRestrictions( $idRoomType, $groups, $idFeaturePrice, - $priceRules + $restrictions ); - if ($duplicatePriceRuleKey) { - $rowsToHighlight = array_merge($duplicatePriceRuleKey, $rowsToHighlight); + if ($duplicateRestrictionKey) { + $rowsToHighlight = array_merge($duplicateRestrictionKey, $rowsToHighlight); $objProduct = new Product((int) $idRoomType, false, $this->context->language->id); $this->errors[] = sprintf($this->l('An advanced price rule already exists for "%s". Please update the restrictions to avoid duplication.'), $objProduct->name); } @@ -561,7 +563,7 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController $objFeaturePricing->id_product = $idRoomType; $objFeaturePricing->feature_price_name = $featurePricingName[$idRoomType]; $objFeaturePricing->add(); - $objFeaturePricing->saveFeaturePriceRestrictions($objFeaturePricing->id, $priceRules); + $objFeaturePricing->saveFeaturePriceRestrictions($objFeaturePricing->id, $restrictions); } Tools::redirectAdmin(self::$currentIndex.'&conf=3&token='.$this->token); @@ -571,7 +573,7 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController $conf = $idFeaturePrice ? 4 : 3; if ($objFeaturePricing->save()) { - $objFeaturePricing->saveFeaturePriceRestrictions($objFeaturePricing->id, $priceRules); + $objFeaturePricing->saveFeaturePriceRestrictions($objFeaturePricing->id, $restrictions); if (Tools::isSubmit('submitAdd'.$this->table.'AndStay')) { Tools::redirectAdmin( self::$currentIndex.'&id_feature_price='.(int) $objFeaturePricing->id. diff --git a/modules/hotelreservationsystem/views/css/HotelReservationAdmin.css b/modules/hotelreservationsystem/views/css/HotelReservationAdmin.css index 336a83360..5dd54412f 100644 --- a/modules/hotelreservationsystem/views/css/HotelReservationAdmin.css +++ b/modules/hotelreservationsystem/views/css/HotelReservationAdmin.css @@ -617,7 +617,9 @@ body.adminhotelroomsbooking .ui-tooltip { } #advanced_price_rule_group .panel.advanced_price_rule { - padding: 10px 15px;} + padding: 10px 0px;} +#advanced_price_rule_group .advance_price_rule_header_container, .advanced_price_rule_body { + padding: 0px 20px;} #advanced_price_rule_group .advance_price_rule_header_container:hover { cursor: pointer;} .advance_price_rule_header_container { @@ -625,13 +627,6 @@ body.adminhotelroomsbooking .ui-tooltip { .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; } diff --git a/modules/hotelreservationsystem/views/js/HotelReservationAdmin.js b/modules/hotelreservationsystem/views/js/HotelReservationAdmin.js index 8f5e1fc0e..c6e6a80a2 100644 --- a/modules/hotelreservationsystem/views/js/HotelReservationAdmin.js +++ b/modules/hotelreservationsystem/views/js/HotelReservationAdmin.js @@ -586,14 +586,14 @@ $(document).ready(function() { $(".specific_date_type_"+panelIndex).hide(200); $(".date_range_type_"+panelIndex).show(200); $(".special_days_content_"+panelIndex).show(200); - if (parseInt($('[name="advance_price_rule['+panelIndex+'][is_special_days_exists]"]:checked').val())) { + if (parseInt($('[name="restriction['+panelIndex+'][is_special_days_exists]"]:checked').val())) { $('.week_days_'+panelIndex).show(200); } } else { $(".specific_date_type_"+panelIndex).hide(200); $(".date_range_type_"+panelIndex).show(200); $(".special_days_content_"+panelIndex).show(200); - if (parseInt($('[name="advance_price_rule['+panelIndex+'][is_special_days_exists]"]:checked').val())) { + if (parseInt($('[name="restriction['+panelIndex+'][is_special_days_exists]"]:checked').val())) { $('.week_days_'+panelIndex).show(200); } } @@ -602,7 +602,7 @@ $(document).ready(function() { $(document).on('change', '.is_special_days_exists', function() { let panelIndex = $(this).closest('.advanced_price_rule').data('advanced_price_rule_index'); - if (parseInt($('[name="advance_price_rule['+panelIndex+'][is_special_days_exists]"]:checked').val())) { + if (parseInt($('[name="restriction['+panelIndex+'][is_special_days_exists]"]:checked').val())) { $('.week_days_'+panelIndex).show(200); } else { $('.week_days_'+panelIndex).hide(200); @@ -642,6 +642,7 @@ $(document).ready(function() { let elem = $(e.target).closest('.advanced_price_rule'); udpateCollapseHeading(elem); $(elem).find('.advance_price_rule_header_container').addClass('shown'); + $(elem).find('.advanced_price_rule_body .advanced_price_rule_body_actions').hide(); } }); @@ -653,9 +654,9 @@ $(document).ready(function() { 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())) { + if (parseInt($('[name="restriction['+rowIndex+'][is_special_days_exists]"]:checked').val())) { let special_days = []; - $('[name="advance_price_rule['+rowIndex+'][special_days][]"]').each(function(){ + $('[name="restriction['+rowIndex+'][special_days][]"]').each(function(){ if ($(this).prop('checked')) { special_days.push($(this).parent().text().trim()); } @@ -684,6 +685,7 @@ $(document).ready(function() { $(document).on('show.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'); + $(e.target).closest('.advanced_price_rule').find('.advanced_price_rule_body .advanced_price_rule_body_actions').show(); } }); @@ -707,7 +709,7 @@ $(document).ready(function() { } let panelElem = $('