diff --git a/admin/themes/default/template/controllers/products/lengthofstay.tpl b/admin/themes/default/template/controllers/products/lengthofstay.tpl new file mode 100644 index 000000000..3e0541b04 --- /dev/null +++ b/admin/themes/default/template/controllers/products/lengthofstay.tpl @@ -0,0 +1,284 @@ +{if isset($product->id)} +
+

{l s='Length Of Stay'}

+ + +
+
+ {l s='Please read below important points regarding length of stay management'} +
    +
  • {l s='Set 1 day for setting no limit on Minimum length of stay'}
  • +
  • {l s='Set 0 day for setting no limit on Maximum length of stay'}
  • +
  • {l s='Enable "Length of stay for date ranges" for setting values of \"Minimum length of stay\" and \"Maximum length of stay\" according to different date ranges'}
  • +
  • {l s='Length of stays (minimum|maximum) of all the dates which does not fall under the date ranges of \"Length of stay for date ranges\", will be taken from the global values of length of stays of this room type.'}
  • +
  • {l s='\"Date to\" will not be included in the date range of \"Length of stay for date ranges\".'}
  • +
+
+ +
+ +
+
+ + {l s='Day(s)'} +
+
+
+ +
+ +
+
+ + {l s='Day(s)'} +
+
+
+
+ +
+ +
+ + + + + + + + + +
+
+ +
+ + + + + + + + + + {if isset($smarty.post.active_restriction_dates) && $smarty.post.active_restriction_dates && isset($smarty.post.restriction_date_from) && $smarty.post.restriction_date_from} + {assign var="restrictionDataRange" value=[]} + {foreach from=$smarty.post.restriction_date_from item=restrictionDateFromVal key=restrictionKey} + {assign var="restrictionDataRangeTemp" value=['date_from' => $restrictionDateFromVal, 'date_to' => $smarty.post.restriction_date_to[$restrictionKey], 'min_los' => $smarty.post.restriction_min_los[$restrictionKey], 'max_los' => $smarty.post.restriction_max_los[$restrictionKey]]} + + {if isset($smarty.post.id_rt_restriction) && isset($smarty.post.id_rt_restriction[$restrictionKey])} + {$restrictionDataRangeTemp['id_rt_restriction'] = $smarty.post.id_rt_restriction[$restrictionKey]} + {/if} + + {$restrictionDataRange[] = $restrictionDataRangeTemp} + {/foreach} + {elseif isset($roomTypeInfo['restrictionDataRange']) && $roomTypeInfo['restrictionDataRange']} + {assign var="restrictionDataRange" value=$roomTypeInfo['restrictionDataRange']} + {else} + {assign var="restrictionDataRange" value=[['date_from' => '', 'date_to' => '', 'min_los' => '', 'max_los' => '']]} + {/if} + + {foreach from=$restrictionDataRange item=restrictionInfo} + + + + + + + + {/foreach} + +
{l s='Date From'}{l s='Date To'}{l s='Minimum length of stay'}{l s='Maximum length of stay'}
+
+ + +
+
+
+ + +
+
+
+ + {l s='day(s)'} +
+
+
+ + {l s='day(s)'} +
+
+ {if isset($restrictionInfo['id_rt_restriction'])} + + {/if} + +
+ +
+ + +
+{/if} + + \ No newline at end of file diff --git a/controllers/admin/AdminPPreferencesController.php b/controllers/admin/AdminPPreferencesController.php index ffb9f0007..11c4203d3 100644 --- a/controllers/admin/AdminPPreferencesController.php +++ b/controllers/admin/AdminPPreferencesController.php @@ -108,6 +108,14 @@ class AdminPPreferencesControllerCore extends AdminController 'cast' => 'intval', 'required' => false, 'type' => 'bool' + ), + 'PS_LOS_RESTRICTION_BO' => array( + 'title' => $this->l('Apply Min and Max lenght of stay restrictions for back-office bookings'), + 'hint' => $this->l('While creating bookings from back-office, apply minimum and maximum lenght of stay restrictions'), + 'validation' => 'isBool', + 'cast' => 'intval', + 'required' => false, + 'type' => 'bool' ) ), 'submit' => array('title' => $this->l('Save')) diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php index 1b9457489..5789d1168 100644 --- a/controllers/admin/AdminProductsController.php +++ b/controllers/admin/AdminProductsController.php @@ -112,6 +112,7 @@ class AdminProductsControllerCore extends AdminController 'Warehouses' => $this->l('Warehouses'), 'Configuration' => $this->l('Configuration'), 'Occupancy' => $this->l('Occupancy'), + 'LengthOfStay' => $this->l('Length of Stay'), 'Booking' => $this->l('Booking Information'), ); @@ -133,7 +134,8 @@ class AdminProductsControllerCore extends AdminController //'Suppliers' => 13, 'Configuration' => 14, 'Occupancy' => 15, - 'Booking' => 16, + 'LengthOfStay' => 16, + 'Booking' => 17, )); } @@ -2225,6 +2227,9 @@ class AdminProductsControllerCore extends AdminController if ($this->isTabSubmitted('Occupancy')) { $this->processOccupancy(); } + if ($this->isTabSubmitted('LengthOfStay')) { + $this->processLengthOfStay(); + } if ($this->isTabSubmitted('Configuration')) { $this->processConfiguration(); } @@ -3473,6 +3478,141 @@ class AdminProductsControllerCore extends AdminController } } + // send information for the length of stay tab + public function initFormLengthOfStay($product) + { + $data = $this->createTemplate($this->tpl_form); + if ($product->id) { + if ($this->product_exists_in_shop) { + // Check if any hotel is created or not + $objRoomType = new HotelRoomType(); + if ($roomTypeInfo = $objRoomType->getRoomTypeInfoByIdProduct($product->id)) { + if ($roomTypeInfo['id_hotel']) { + // send length of stay date ranges for this room type + $objRoomTypeRestrictionDates = new HotelRoomTypeRestrictionDateRange(); + $roomTypeInfo['restrictionDataRange'] = $objRoomTypeRestrictionDates->getRoomTypeLengthOfStayRestriction($product->id); + $smartyVars['roomTypeInfo'] = $roomTypeInfo; + } else { + $this->displayWarning($this->l('No hotel is attached to this room type.')); + } + } else { + $this->displayWarning($this->l('Room type information is missing.')); + } + } else { + $this->displayWarning($this->l('You must save room type before managing length of stay.')); + } + } else { + $this->displayWarning($this->l('You must save room type before managing length of stay.')); + } + + $smartyVars['product'] = $product; + $data->assign($smartyVars); + $this->tpl_form_vars['custom_form'] = $data->fetch(); + } + + public function processLengthOfStay() + { + if ($this->tabAccess['edit'] == 1) { + + $idProduct = Tools::getValue('id_product'); + if (Validate::isLoadedObject($product = new Product((int)$idProduct))) { + $objRoomType = new HotelRoomType(); + if ($roomTypeInfo = $objRoomType->getRoomTypeInfoByIdProduct($idProduct)) { + $roomTypeMinLos = Tools::getValue('min_los'); + $roomTypeMaxLos = Tools::getValue('max_los'); + + // validate length of stay global values for room type + if (!$roomTypeMinLos || $roomTypeMinLos == null) { + $this->errors[] = Tools::displayError('Global minimum length of stay is a required field.'); + } elseif (!Validate::isUnsignedInt($roomTypeMinLos)) { + $this->errors[] = Tools::displayError('Global minimum length of stay value is invalid. Please enter integer value. Set 1 day incase of setting no limit on global minimum length of stay.'); + } + + if ($roomTypeMaxLos == null) { + $this->errors[] = Tools::displayError('Global maximum length of stay is a required field.'); + } elseif (!Validate::isUnsignedInt($roomTypeMaxLos)) { + $this->errors[] = Tools::displayError('Invalid value entered for global maximum length of stay field. Please enter integer value. Set 0 day incase of setting no limit on maximum length of stay.'); + } elseif ($roomTypeMinLos && $roomTypeMaxLos > 0 && ($roomTypeMinLos > $roomTypeMaxLos)) { + $this->errors[] = Tools::displayError('Value of global maximum length of stay must be greater than global minimum length of stay.'); + } + + if (Tools::getValue('active_restriction_dates')) { + if (Tools::getValue('restriction_date_from') && Tools::getValue('restriction_date_to')) { + $objRoomTypeRestrictDateRange = new HotelRoomTypeRestrictionDateRange(); + $dateFromRestriction = Tools::getValue('restriction_date_from'); + $dateToRestriction = Tools::getValue('restriction_date_to'); + $minLosDays = Tools::getValue('restriction_min_los'); + $maxLosDays = Tools::getValue('restriction_max_los'); + + $this->errors = array_merge($this->errors, $objRoomTypeRestrictDateRange->validateRoomTypeLengthOfStayRestriction($dateFromRestriction, $dateToRestriction, $minLosDays, $maxLosDays)); + } else { + $this->errors[] = Tools::displayError('Please add at least one Minimum & maximum length of stay restriction for date range if \'Length of stay for date ranges\' option is enable.'); + } + } + + if (!$this->errors) { + $objRoomType = new HotelRoomType($roomTypeInfo['id']); + $objRoomType->min_los = $roomTypeMinLos; + $objRoomType->max_los = $roomTypeMaxLos; + if ($objRoomType->save()) { + if (Tools::getValue('active_restriction_dates') && Tools::getValue('restriction_date_from')) { + // @ToDo: we should validate this room type restriction ids belongs to this room type + $idRoomTypeRestriction = Tools::getValue('id_rt_restriction'); + + foreach ($dateFromRestriction as $restrictionKey => $dateFrom) { + // change into database compatible format + $dateFrom = date('Y-m-d', strtotime($dateFrom)); + $dateTo = date('Y-m-d', strtotime($dateToRestriction[$restrictionKey])); + + if ($idRoomTypeRestriction[$restrictionKey]) { + $objRoomTypeRestrictDateRange = new HotelRoomTypeRestrictionDateRange($idRoomTypeRestriction[$restrictionKey]); + } else { + $objRoomTypeRestrictDateRange = new HotelRoomTypeRestrictionDateRange(); + } + + $objRoomTypeRestrictDateRange->id_product = $idProduct; + $objRoomTypeRestrictDateRange->date_from = $dateFrom; + $objRoomTypeRestrictDateRange->date_to = $dateTo; + $objRoomTypeRestrictDateRange->min_los = $minLosDays[$restrictionKey]; + $objRoomTypeRestrictDateRange->max_los = $maxLosDays[$restrictionKey]; + $objRoomTypeRestrictDateRange->save(); + } + } else { + // if disabled length of stay for date ranges then delete all previously saved + $objRoomTypeRestrictDateRange = new HotelRoomTypeRestrictionDateRange(); + if ($losRestrictions = $objRoomTypeRestrictDateRange->getRoomTypeLengthOfStayRestriction($idProduct)) { + foreach ($losRestrictions as $losDate) { + $objRoomTypeRestrictDateRange = new HotelRoomTypeRestrictionDateRange($losDate['id_rt_restriction']); + $objRoomTypeRestrictDateRange->delete(); + } + } + } + } else { + $this->errors[] = Tools::displayError('Something went wrong while saving global minimum & maximum length of stay values. Please try again !!'); + } + } + } + } + } else { + $this->errors[] = Tools::displayError('You do not have the right permission.'); + } + } + + // delete the rows of length of stay on date range + public function ajaxProcessDeleteRoomTypeLengthOfStayRestriction() + { + if ($this->tabAccess['edit'] == 1) { + $objRoomTypeRestrictionDates = new HotelRoomTypeRestrictionDateRange(Tools::getValue('id_rt_restriction')); + if ($objRoomTypeRestrictionDates->delete()) { + die(json_encode(array('success' => $this->l('Successfully deleted')))); + } else { + die(json_encode(array('error' => $this->l('Something went wrong. Please reload the page and try again !!')))); + } + } else { + die(json_encode(array('error' => $this->l('You do not have the right permission')))); + } + } + public function validateDisableDateRanges($disableDates) { if (count($disableDates)) { diff --git a/modules/hotelreservationsystem/classes/HotelBookingDetail.php b/modules/hotelreservationsystem/classes/HotelBookingDetail.php index 69557aab5..3f020f1ff 100644 --- a/modules/hotelreservationsystem/classes/HotelBookingDetail.php +++ b/modules/hotelreservationsystem/classes/HotelBookingDetail.php @@ -225,6 +225,7 @@ class HotelBookingDetail extends ObjectModel */ public function getBookingData($params) { + $this->context = Context::getContext(); // extract all keys and values of the array [$params] into variables and values extract($this->getBookingDataParams($params)); if ($date_from && $date_to && $hotel_id) { @@ -248,12 +249,19 @@ class HotelBookingDetail extends ObjectModel $num_cart = 0; $new_part_arr = array(); $booking_data = array(); + $applyLosRestriction = true; if ($search_partial) { $this->partAvaiDates = array(); $this->allReqDates = $this->createDateRangeArray($date_from, $date_to, 1); } + if (isset(Context::getContext()->employee->id)) { + if (!Configuration::get('PS_LOS_RESTRICTION_BO')) { + $applyLosRestriction = false; + } + } + foreach ($room_types as $key => $room_type) { if ($search_partial) { $this->dltDates = array(); @@ -261,6 +269,10 @@ class HotelBookingDetail extends ObjectModel $total_rooms += $obj_room_info->getHotelRoomInfo($room_type['id_product'], $hotel_id, 1); + // Get min & max LOS + $objRoomTypeRestriction = new HotelRoomTypeRestrictionDateRange(); + $losRestriction = $objRoomTypeRestriction->getRoomTypeLengthOfStay($room_type['id_product'], $date_from); + $obj_product = new Product((int) $room_type['id_product']); $product_name = $obj_product->name[Configuration::get('PS_LANG_DEFAULT')]; @@ -309,7 +321,15 @@ class HotelBookingDetail extends ObjectModel if ($search_unavai) { $sql1 = 'SELECT `id_product`, `id_hotel`, `room_num`, `comment` AS `room_comment` FROM `'._DB_PREFIX_.'htl_room_information` - WHERE `id_hotel`='.(int)$hotel_id.' AND `id_product` ='.(int)$room_type['id_product'].' AND `id_status` = '. HotelRoomInformation::STATUS_INACTIVE; + WHERE `id_hotel`='.(int)$hotel_id.' AND `id_product` ='.(int)$room_type['id_product'].' AND (`id_status` = '. HotelRoomInformation::STATUS_INACTIVE; + if ($applyLosRestriction) { + $sql1 .= ' OR ( DATEDIFF(\''.$date_to.'\', \''.$date_from.'\') < '.(int)$losRestriction['min_los']; + if ((int)$losRestriction['max_los']) { + $sql1 .= ' OR DATEDIFF(\''.$date_to.'\', \''.$date_from.'\') > '.(int)$losRestriction['max_los']; + } + $sql1 .= ')'; + } + $sql1 .= ')'; $sql2 = 'SELECT hri.`id_product`, hri.`id_hotel`, hri.`room_num`, hri.`comment` AS `room_comment` FROM `'._DB_PREFIX_.'htl_room_information` AS hri @@ -357,7 +377,18 @@ class HotelBookingDetail extends ObjectModel $joinAvailRoomSearch = ''; - $whereAvailRoomSearch = 'WHERE ri.`id_hotel`='.(int)$hotel_id.' AND ri.`id_product`='.(int)$room_type['id_product'].' AND ri.`id_status` != '. HotelRoomInformation::STATUS_INACTIVE .' AND ri.`id` NOT IN ('.$exclude_ids.')'; + $whereAvailRoomSearch = 'WHERE ri.`id_hotel`='.(int)$hotel_id.' AND ri.`id_product`='.(int)$room_type['id_product'].' AND ri.`id_status` != '. HotelRoomInformation::STATUS_INACTIVE; + + // Check min & max LOS restrictions + if ($applyLosRestriction) { + $whereAvailRoomSearch .= ' AND DATEDIFF(\''.$date_to.'\', \''.$date_from.'\') >= '.(int)$losRestriction['min_los']; + // check max LOS restriction is greater than zero + if ((int)$losRestriction['max_los']) { + $whereAvailRoomSearch .= ' AND DATEDIFF(\''.$date_to.'\', \''.$date_from.'\') <= '.(int)$losRestriction['max_los']; + } + } + + $whereAvailRoomSearch .= ' AND ri.`id` NOT IN ('.$exclude_ids.')'; $groupByAvailRoomSearch = ''; $orderByAvailRoomSearch = ''; diff --git a/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php b/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php index 26d3c5a4b..c88ff1324 100644 --- a/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php +++ b/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php @@ -29,6 +29,8 @@ class HotelReservationSystemDb `id_hotel` int(11) NOT NULL, `adult` smallint(6) NOT NULL, `children` smallint(6) NOT NULL, + `min_los` smallint(6) NOT NULL DEFAULT '1', + `max_los` smallint(6) NOT NULL DEFAULT '0', `date_add` datetime NOT NULL, `date_upd` datetime NOT NULL, PRIMARY KEY (`id`) @@ -352,6 +354,18 @@ class HotelReservationSystemDb PRIMARY KEY (`id`) ) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;", + "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_room_type_restriction_date_range` ( + `id_rt_restriction` int(11) NOT NULL AUTO_INCREMENT, + `id_product` int(11) NOT NULL, + `min_los` smallint(6) unsigned NOT NULL DEFAULT '1', + `max_los` smallint(6) unsigned NOT NULL DEFAULT '0', + `date_from` date NOT NULL, + `date_to` date NOT NULL, + `date_add` datetime NOT NULL, + `date_upd` datetime NOT NULL, + PRIMARY KEY (`id_rt_restriction`) + ) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;", + "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_access` ( `id_profile` int(10) unsigned NOT NULL, `id_hotel` int(10) unsigned NOT NULL, @@ -408,6 +422,7 @@ class HotelReservationSystemDb `'._DB_PREFIX_.'htl_room_type_demand_price`, `'._DB_PREFIX_.'htl_room_type_demand`, `'._DB_PREFIX_.'htl_room_disable_dates`, + `'._DB_PREFIX_.'htl_room_type_restriction_date_range`, `'._DB_PREFIX_.'htl_access`' ); } diff --git a/modules/hotelreservationsystem/classes/HotelRoomType.php b/modules/hotelreservationsystem/classes/HotelRoomType.php index dc070b202..49cde494f 100644 --- a/modules/hotelreservationsystem/classes/HotelRoomType.php +++ b/modules/hotelreservationsystem/classes/HotelRoomType.php @@ -25,6 +25,8 @@ class HotelRoomType extends ObjectModel public $id_hotel; public $adult; public $children; + public $min_los; + public $max_los; public $date_add; public $date_upd; @@ -36,6 +38,8 @@ class HotelRoomType extends ObjectModel 'id_hotel' => array('type' => self::TYPE_INT, 'validate' => 'isInt'), 'adult' => array('type' => self::TYPE_INT, 'validate' => 'isInt'), 'children' => array('type' => self::TYPE_INT, 'validate' => 'isInt'), + 'min_los' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'default' => 1), + 'max_los' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'default' => 0), 'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'), 'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'), ), @@ -211,14 +215,17 @@ class HotelRoomType extends ObjectModel * * @return [array|false] [If data found returns array containing information of the room type else returns false] */ - public function getRoomTypeInfoByIdProduct($id_product) + public function getRoomTypeInfoByIdProduct($id_product, $idLang = false) { - $idLang = Context::getContext()->language->id; - $sql = 'SELECT hrt.`id`,hrt.`id_hotel`, hrt.`adult`, hrt.`children`, hbl.`hotel_name` + if (!$idLang) { + $idLang = Context::getContext()->language->id; + } + + $sql = 'SELECT hrt.`id`,hrt.`id_hotel`, hrt.`adult`, hrt.`children`, hbl.`hotel_name`, hrt.`min_los`, hrt.`max_los` FROM `'._DB_PREFIX_.'htl_room_type` AS hrt INNER JOIN `'._DB_PREFIX_.'htl_branch_info_lang` AS hbl ON (hbl.`id` = hrt.`id_hotel` AND hbl.`id_lang` = '.(int)$idLang.') - WHERE `id_product` = '.(int)$id_product; + WHERE hrt.`id_product` = '.(int)$id_product; return Db::getInstance()->getRow($sql); } diff --git a/modules/hotelreservationsystem/classes/HotelRoomTypeRestrictionDateRange.php b/modules/hotelreservationsystem/classes/HotelRoomTypeRestrictionDateRange.php new file mode 100644 index 000000000..1d8806597 --- /dev/null +++ b/modules/hotelreservationsystem/classes/HotelRoomTypeRestrictionDateRange.php @@ -0,0 +1,202 @@ + +* @copyright 2010-2021 Webkul IN +* @license https://store.webkul.com/license.html +*/ + +class HotelRoomTypeRestrictionDateRange extends ObjectModel +{ + public $id_rt_restriction; + public $id_product; + public $min_los; + public $max_los; + public $date_from; + public $date_to; + public $date_add; + public $date_upd; + + const WK_ROOM_TYPE_MIN_LOS = 1; + const WK_ROOM_TYPE_MAX_LOS = 2; + + public static $definition = array( + 'table' => 'htl_room_type_restriction_date_range', + 'primary' => 'id_rt_restriction', + 'fields' => array( + 'id_product' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true), + 'min_los' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true, 'default' => 1), + 'max_los' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true, 'default' => 0), + 'date_from' => array('type' => self::TYPE_DATE, 'validate' => 'isDate', 'required' => true), + 'date_to' => array('type' => self::TYPE_DATE, 'validate' => 'isDate', 'required' => true), + 'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'), + 'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate') + ), + ); + + protected $webserviceParameters = array( + 'objectMethods' => array( + 'add' => 'addWs', + 'update' => 'updateWs', + 'delete' => 'deleteWs', + ), + 'objectsNodeName' => 'restriction_date_ranges', + 'objectNodeName' => 'restriction_date_range', + 'fields' => array( + 'id_product' => array( + 'xlink_resource' => array( + 'resourceName' => 'room_types', + ) + ), + ), + ); + + public function getRoomTypeLengthOfStayRestriction($idRoomType) + { + $sql = 'SELECT * FROM `'._DB_PREFIX_.'htl_room_type_restriction_date_range` WHERE `id_product` = '.(int)$idRoomType; + return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); + } + + public function getRoomTypeLengthOfStay($idRoomType, $date = false, $losRestrictionType = false) + { + $losRestriction = array(); + + // if date is given the return LOS for date range + if ($date) { + $date = date('Y-m-d', strtotime($date)); + + $sql = 'SELECT `min_los`, `max_los` + FROM `'._DB_PREFIX_.'htl_room_type_restriction_date_range` + WHERE `id_product` = '.(int) $idRoomType.' AND `date_from` <= \''.pSQL($date).'\' AND `date_to` > \''.pSQL($date).'\''; + + $losRestriction = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql); + } + + // if no LOS for date range the find it for room type + if (!$losRestriction) { + $sql = 'SELECT `min_los`, `max_los` + FROM `'._DB_PREFIX_.'htl_room_type` + WHERE `id_product` = '.(int) $idRoomType; + + $losRestriction = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql); + } + + if ($losRestriction) { + if ($losRestrictionType) { + if ($losRestrictionType == self::WK_ROOM_TYPE_MIN_LOS) { + return $losRestriction['min_los']; + } elseif ($losRestrictionType == self::WK_ROOM_TYPE_MAX_LOS) { + return $losRestriction['max_los']; + } + } + + return $losRestriction; + } + + return false; + } + + public function validateRoomTypeLengthOfStayRestriction($dateFromRestriction, $dateToRestriction, $minLosDays, $maxLosDays) + { + $errors = array(); + $objModule = Module::getinstanceByName('hotelreservationsystem'); + foreach ($dateFromRestriction as $dateFromKey => $dateFrom) { + $dateTo = $dateToRestriction[$dateFromKey]; + $minDay = $minLosDays[$dateFromKey]; + $maxDay = $maxLosDays[$dateFromKey]; + + // validate the fields before saving in the table + if (!$minDay) { + $errors[] = $objModule->l('Minimum length of stay is required.', 'HotelRoomTypeLosDateRanges'). + ' [ '.$objModule->l('LOS for date range in row no.', 'HotelRoomTypeLosDateRanges').' : '.($dateFromKey+1).' ]'; + } elseif (!Validate::isUnsignedInt($minDay)) { + $errors[] = $objModule->l('Minimum length of stay is invalid.', 'HotelRoomTypeLosDateRanges').' + [ '.$objModule->l('LOS for date range in row no.', 'HotelRoomTypeLosDateRanges').' : '.($dateFromKey+1).' ]'; + } + + if ($maxDay == null) { + $errors[] = $objModule->l('Maximum length of stay is required.', 'HotelRoomTypeLosDateRanges'). + ' [ '.$objModule->l('LOS for date range in row no.', 'HotelRoomTypeLosDateRanges').' : '.($dateFromKey+1).' ]'; + } elseif (!Validate::isUnsignedInt($maxDay)) { + $errors[] = $objModule->l('Maximum length of stay is invalid.', 'HotelRoomTypeLosDateRanges'). + ' [ '.$objModule->l('LOS for date range in row no.', 'HotelRoomTypeLosDateRanges').' : '.($dateFromKey+1).' ]'; + } elseif ($minDay && $maxDay > 0 && ($minDay > $maxDay)) { + $this->errors[] = Tools::displayError('Value of global maximum length of stay must be greater than global minimum length of stay.'); + } + + if (!$dateFrom || $dateFrom == '') { + $errors[] = $objModule->l('Date from is required.', 'HotelRoomTypeLosDateRanges'). + ' [ '.$objModule->l('LOS for date range in row no.', 'HotelRoomTypeLosDateRanges').' : '.($dateFromKey+1).' ]'; + } else { + $dateFrom = date('Y-m-d', strtotime($dateFrom)); + if (!Validate::isDate($dateFrom)) { + $errors[] = $objModule->l('Date from is invalid.', 'HotelRoomTypeLosDateRanges'). + ' [ '.$objModule->l('LOS for date range in row no.', 'HotelRoomTypeLosDateRanges').' : '.($dateFromKey+1).' ]'; + } + } + + if (!$dateTo || $dateTo == '') { + $errors[] = $objModule->l('Date to is required.', 'HotelRoomTypeLosDateRanges').' + [ '.$objModule->l('LOS for date range in row no.', 'HotelRoomTypeLosDateRanges').' : '.($dateFromKey+1).' ]'; + } else { + $dateTo = date('Y-m-d', strtotime($dateTo)); + if (!Validate::isDate($dateTo)) { + $errors[] = $objModule->l('Date to is invalid.', 'HotelRoomTypeLosDateRanges'). + ' [ '.$objModule->l('LOS for date range in row no.', 'HotelRoomTypeLosDateRanges').' : '.($dateFromKey+1).' ]'; + } elseif (strtotime($dateTo) <= strtotime($dateFrom)) { + $errors[] = $dateFrom.' and '.$dateTo . $objModule->l('\'Date to\' must be a greater than \'date from\'.', 'HotelRoomTypeLosDateRanges'). + ' [ '.$objModule->l('LOS for date range in row no.', 'HotelRoomTypeLosDateRanges').' : '.($dateFromKey+1).' ]'; + } else { + // validate date ranges from other date ranges + foreach ($dateToRestriction as $dateToKey => $newDateTo) { + if ($dateFromKey > $dateToKey) { + if (!((strtotime($dateFrom) < strtotime($dateFromRestriction[$dateToKey]) && strtotime($dateTo) <= strtotime($dateFromRestriction[$dateToKey])) || (strtotime($dateFrom) >= strtotime($newDateTo) && strtotime($dateTo) > strtotime($newDateTo)))) { + $errors[] = $objModule->l('Date ranges are conflicting with each other.', 'HotelRoomTypeLosDateRanges').' [ '.$objModule->l('Conflicting rows are', 'HotelRoomTypeLosDateRanges').' : '.($dateFromKey+1).', '.($dateToKey+1).' ]'; + } + } + } + } + } + } + + return $errors; + } + + // Webservice :: webservice add function + public function addWs($autodate = true, $null_values = false) + { + $objRoomType = new HotelRoomType(); + if ($roomTypeInfo = $objRoomType->getRoomTypeInfoByIdProduct($this->id_product)) { + return $this->add($autodate, $null_values); + } + return false; + } + + // Webservice :: webservice update function + public function updateWs($null_values = false) + { + $objRoomType = new HotelRoomType(); + if ($roomTypeInfo = $objRoomType->getRoomTypeInfoByIdProduct($this->id_product)) { + return $this->update($null_values); + } + return false; + } + + // Webservice :: webservice delete function + public function deleteWs() + { + return $this->delete(); + } +} diff --git a/modules/hotelreservationsystem/define.php b/modules/hotelreservationsystem/define.php index 6218e15af..982227138 100644 --- a/modules/hotelreservationsystem/define.php +++ b/modules/hotelreservationsystem/define.php @@ -39,6 +39,7 @@ require_once 'classes/HotelRoomTypeGlobalDemand.php'; require_once 'classes/HotelRoomTypeGlobalDemandAdvanceOption.php'; require_once 'classes/HotelRoomTypeDemandPrice.php'; require_once 'classes/HotelRoomTypeDemand.php'; +require_once 'classes/HotelRoomTypeRestrictionDateRange.php'; require_once 'classes/QloWebservice.php'; require_once 'classes/QloRoomType.php'; @@ -47,4 +48,4 @@ require_once 'classes/HotelBranchRefundRules.php'; // Web services classes require_once 'classes/WebserviceSpecificManagementQlo.php'; -require_once 'classes/WebserviceSpecificManagementHotelImages.php'; \ No newline at end of file +require_once 'classes/WebserviceSpecificManagementHotelImages.php';