diff --git a/controllers/admin/AdminOrderPreferencesController.php b/controllers/admin/AdminOrderPreferencesController.php index bc5587710..5d75b728f 100644 --- a/controllers/admin/AdminOrderPreferencesController.php +++ b/controllers/admin/AdminOrderPreferencesController.php @@ -59,6 +59,30 @@ class AdminOrderPreferencesControllerCore extends AdminController ); $this->fields_options = array( + 'order_restrict' => array( + 'title' => $this->l('Order Restrict'), + 'icon' => 'icon-cogs', + 'fields' => array( + 'MAX_GLOBAL_BOOKING_DATE' => array( + 'title' => $this->l('Maximum Global Date to book a room'), + 'hint' => $this->l('Maximum date by which rooms of your hotels can be booked.'), + 'type' => 'text', + 'id' => 'max_global_book_date', + 'class' => 'fixed-width-xxl readonly', + ), + 'GLOBAL_PREPARATION_TIME' => array( + 'title' => $this->l('Preparation time'), + 'hint' => $this->l('Number of days required to prepare a room for stay.'), + 'desc' => $this->l('Set to 0 to disable this feature.'), + 'type' => 'text', + 'class' => 'fixed-width-xl', + 'suffix' => $this->l('day(s)'), + ), + ), + 'submit' => array( + 'title' => $this->l('Save'), + ), + ), 'general' => array( 'title' => $this->l('General'), 'icon' => 'icon-cogs', @@ -183,9 +207,34 @@ class AdminOrderPreferencesControllerCore extends AdminController public function beforeUpdateOptions() { $sql = 'SELECT `id_cms` FROM `'._DB_PREFIX_.'cms` - WHERE id_cms = '.(int)Tools::getValue('PS_CONDITIONS_CMS_ID'); + WHERE id_cms = '.(int)Tools::getValue('PS_CONDITIONS_CMS_ID'); if (Tools::getValue('PS_CONDITIONS') && (Tools::getValue('PS_CONDITIONS_CMS_ID') == 0 || !Db::getInstance()->getValue($sql))) { $this->errors[] = Tools::displayError('Please assign a valid CMS page for Terms and Conditions.'); } + + $maxGlobalBookingDate = Tools::getValue('MAX_GLOBAL_BOOKING_DATE'); + $globalPreparationTime = Tools::getValue('GLOBAL_PREPARATION_TIME'); + $maxGlobalBookingDateFormatted = date('Y-m-d', strtotime($maxGlobalBookingDate)); + + if ($maxGlobalBookingDate == '') { + $this->errors[] = Tools::displayError('Field \'Maximum Global Date to book a room\' can not be empty.'); + } elseif (!Validate::isDate($maxGlobalBookingDateFormatted)) { + $this->errors[] = Tools::displayError('Field \'Maximum Global Date to book a room\' is invalid.'); + } elseif (strtotime($maxGlobalBookingDateFormatted) < strtotime(date('Y-m-d'))) { + $this->errors[] = Tools::displayError('Field \'Maximum Global Date to book a room\' can not be a past date. Please use a future date.'); + } + + if ($globalPreparationTime === '') { + $this->errors[] = Tools::displayError('Field \'Preparation time\' can not be empty.'); + } elseif ($globalPreparationTime !== '0' && !Validate::isUnsignedInt($globalPreparationTime)) { + $this->errors[] = Tools::displayError('Field \'Preparation time\' is invalid.'); + } + } + + public function setMedia() + { + parent::setMedia(); + $this->addCSS(_MODULE_DIR_.'hotelreservationsystem/views/css/HotelReservationAdmin.css'); + $this->addJS(_MODULE_DIR_.'hotelreservationsystem/views/js/HotelReservationAdmin.js'); } } diff --git a/controllers/front/ProductController.php b/controllers/front/ProductController.php index 321d94752..0ae89d2da 100644 --- a/controllers/front/ProductController.php +++ b/controllers/front/ProductController.php @@ -323,6 +323,8 @@ class ProductControllerCore extends FrontController } } /*End*/ + // booking preparation time + $preparationTime = (int) HotelOrderRestrictDate::getPreparationTime($hotel_id); $hotelImageLink = null; if ($coverImage = HotelImage::getCover($hotel_id)) { @@ -347,6 +349,7 @@ class ProductControllerCore extends FrontController array( 'isHotelRefundable' => $hotel_branch_obj->isRefundable(), 'max_order_date' => $max_order_date, + 'preparation_time' => $preparationTime, 'warning_num' => Configuration::get('WK_ROOM_LEFT_WARNING_NUMBER'), 'product_controller_url' => $this->context->link->getPageLink('product'), 'date_from' => $date_from, diff --git a/modules/hotelreservationsystem/classes/HotelHelper.php b/modules/hotelreservationsystem/classes/HotelHelper.php index 44b43a517..8ae0c1621 100644 --- a/modules/hotelreservationsystem/classes/HotelHelper.php +++ b/modules/hotelreservationsystem/classes/HotelHelper.php @@ -222,6 +222,8 @@ class HotelHelper date('d-m-Y', strtotime(date('Y-m-d', time()).' + 1 year')) ); + Configuration::updateValue('GLOBAL_PREPARATION_TIME', 0); + Configuration::updateValue('HTL_FEATURE_PRICING_PRIORITY', 'specific_date;special_day;date_range'); Configuration::updateValue('WK_GOOGLE_ACTIVE_MAP', 0); Configuration::updateValue('WK_MAP_HOTEL_ACTIVE_ONLY', 1); diff --git a/modules/hotelreservationsystem/classes/HotelOrderRestrictDate.php b/modules/hotelreservationsystem/classes/HotelOrderRestrictDate.php index 3d490af2c..52ce74120 100644 --- a/modules/hotelreservationsystem/classes/HotelOrderRestrictDate.php +++ b/modules/hotelreservationsystem/classes/HotelOrderRestrictDate.php @@ -22,7 +22,10 @@ class HotelOrderRestrictDate extends ObjectModel { public $id; public $id_hotel; + public $use_global_max_order_date; public $max_order_date; + public $use_global_preparation_time; + public $preparation_time; public $date_add; public $date_upd; @@ -31,49 +34,54 @@ class HotelOrderRestrictDate extends ObjectModel 'primary' => 'id', 'fields' => array( 'id_hotel' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), - 'max_order_date' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'), + 'use_global_max_order_date' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), + 'max_order_date' => array('type' => self::TYPE_DATE, 'validate' => 'isDateFormat'), + 'use_global_preparation_time' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), + 'preparation_time' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), 'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'), 'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'), ), ); - public function getDataByHotelId($id_hotel) + public static function getDataByHotelId($idHotel) { - $result = Db::getInstance()->getRow('SELECT * FROM `'._DB_PREFIX_.'htl_order_restrict_date` WHERE `id_hotel`='.$id_hotel); - if ($result) { - return $result; - } - - return false; + return Db::getInstance()->getRow( + 'SELECT * FROM `'._DB_PREFIX_.'htl_order_restrict_date` ord WHERE ord.`id_hotel` = '.(int) $idHotel + ); } /*Max date of ordering for order restrict*/ - public static function getMaxOrderDate($id_hotel) + public static function getMaxOrderDate($idHotel) { - $global_max_order_date = Configuration::get('MAX_GLOBAL_BOOKING_DATE'); - $obj_ord_rest = new self(); - $order_restrict_data = $obj_ord_rest->getDataByHotelId($id_hotel); - - if (isset($order_restrict_data['max_order_date']) && $order_restrict_data['max_order_date']) { - $max_order_date = $order_restrict_data['max_order_date']; - } elseif (isset($global_max_order_date) && $global_max_order_date) { - $max_order_date = $global_max_order_date; - } else { - $max_order_date = 0; + $result = self::getDataByHotelId($idHotel); + if (is_array($result) && count($result) && !$result['use_global_max_order_date']) { + return $result['max_order_date']; } - return $max_order_date; + if ($globalBookingDate = Configuration::get('MAX_GLOBAL_BOOKING_DATE')) { + return $globalBookingDate; + } + + return 0; } - public function getUnsavedHotelsForOrderRestrict() + /** + * @param int $id_hotel + * @return int|false + */ + public static function getPreparationTime($idHotel) { - $idLang = Context::getContext()->language->id; - $sql = 'SELECT hbi.`id`, hbl.`hotel_name` FROM `'._DB_PREFIX_.'htl_branch_info` hbi - LEFT JOIN `'._DB_PREFIX_.'htl_branch_info_lang` hbl - ON (hbl.`id` = hbi.`id` AND hbl.`id_lang` = '.(int)$idLang.') - WHERE hbi.`id` NOT IN (SELECT DISTINCT id_hotel FROM `'._DB_PREFIX_.'htl_order_restrict_date`)'; + $result = self::getDataByHotelId($idHotel); + if (is_array($result) && count($result) && !$result['use_global_preparation_time']) { + return (int) $result['preparation_time']; + } - return Db::getInstance()->executeS($sql); + $globalPreparationTime = Configuration::get('GLOBAL_PREPARATION_TIME'); + if ($globalPreparationTime != '0') { + return (int) $globalPreparationTime; + } + + return false; } public static function validateOrderRestrictDateOnPayment(&$controller) @@ -88,23 +96,45 @@ class HotelOrderRestrictDate extends ObjectModel $obj_htl_bk_dtl = new HotelBookingDetail(); $obj_rm_type = new HotelRoomType(); - if ($cart_bk_data = $objCartBookingData->getOnlyCartBookingData( - $context->cart->id, - $context->cart->id_guest, - $product['id_product'] - )) { - $cart_data = array(); - foreach ($cart_bk_data as $data) { - $objCartBookingData = new HotelCartBookingData($data['id']); - if ($maxOrderDate = HotelOrderRestrictDate::getMaxOrderDate($objCartBookingData->id_hotel)) { - if (strtotime('-1 day', strtotime($maxOrderDate)) < strtotime($objCartBookingData->date_from) - || strtotime($maxOrderDate) < strtotime($objCartBookingData->date_to) - ) { - $objBranchInfo = new HotelBranchInformation( - $objCartBookingData->id_hotel, - $context->language->id - ); - $controller->errors[] = $moduleInstance->l('You can not Book room after date', 'HotelOrderRestrictDate').' \''.date('d-m-Y', strtotime($maxOrderDate)).'\' '.$moduleInstance->l('For hotel', 'HotelOrderRestrictDate').' \''.$objBranchInfo->hotel_name.'\'. '.$moduleInstance->l('Please remove rooms from cart from', 'HotelOrderRestrictDate').' \''.$objBranchInfo->hotel_name.'\' '.$moduleInstance->l('after date', 'HotelOrderRestrictDate').' \''.date('d-m-Y', strtotime($maxOrderDate)).'\' '.$moduleInstance->l('to proceed.', 'HotelOrderRestrictDate'); + if ($cart_bk_data = $objCartBookingData->getOnlyCartBookingData( + $context->cart->id, + $context->cart->id_guest, + $product['id_product'] + )) { + $cart_data = array(); + foreach ($cart_bk_data as $data) { + $objCartBookingData = new HotelCartBookingData($data['id']); + if ($maxOrderDate = HotelOrderRestrictDate::getMaxOrderDate($objCartBookingData->id_hotel)) { + if (strtotime('-1 day', strtotime($maxOrderDate)) < strtotime($objCartBookingData->date_from) + || strtotime($maxOrderDate) < strtotime($objCartBookingData->date_to) + ) { + $objBranchInfo = new HotelBranchInformation( + $objCartBookingData->id_hotel, + $context->language->id + ); + $controller->errors[] = sprintf( + 'You can not book rooms for hotel \'%s\' after date %s. Please remove these rooms to proceed.', + $objBranchInfo->hotel_name, + Tools::displayDate($maxOrderDate) + ); + $error = true; + } + } + $preparationTime = HotelOrderRestrictDate::getPreparationTime($objCartBookingData->id_hotel); + if ($preparationTime !== false) { + $minOrderDate = date('Y-m-d', strtotime('+'. ($preparationTime) .' days')); + if (strtotime($minOrderDate) > strtotime($objCartBookingData->date_from) + || strtotime($minOrderDate . ' +1 day')> strtotime($objCartBookingData->date_to) + ) { + $objBranchInfo = new HotelBranchInformation( + $objCartBookingData->id_hotel, + $context->language->id + ); + $controller->errors[] = sprintf( + 'You can not book rooms for hotel \'%s\' before date %s. Please remove these rooms to proceed.', + $objBranchInfo->hotel_name, + Tools::displayDate($minOrderDate) + ); $error = true; } } diff --git a/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php b/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php index c88ff1324..f06d81471 100644 --- a/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php +++ b/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php @@ -250,7 +250,10 @@ class HotelReservationSystemDb "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_order_restrict_date` ( `id` int(11) NOT NULL AUTO_INCREMENT, `id_hotel` int(11) NOT NULL, - `max_order_date` datetime NOT NULL, + `use_global_max_order_date` tinyint(1) NOT NULL, + `max_order_date` date NOT NULL, + `use_global_preparation_time` tinyint(1) NOT NULL, + `preparation_time` int(11) NOT NULL, `date_add` datetime NOT NULL, `date_upd` datetime NOT NULL, PRIMARY KEY (`id`) diff --git a/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php b/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php index db62b4f9f..f096c1052 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php @@ -162,6 +162,16 @@ class AdminAddHotelController extends ModuleAdminController $smartyVars['hotelRefundRules'] = array_column($hotelRefundRules, 'id_refund_rule'); } } + + $restrictDateInfo = HotelOrderRestrictDate::getDataByHotelId($idHotel); + if ($restrictDateInfo) { + if ($restrictDateInfo['max_order_date'] == '0000-00-00') { + $restrictDateInfo['max_order_date'] = date('d-m-Y', strtotime('1 year')); + } else { + $restrictDateInfo['max_order_date'] = date('d-m-Y', strtotime($restrictDateInfo['max_order_date'])); + } + } + $smartyVars['order_restrict_date_info'] = $restrictDateInfo; } $smartyVars['enabledDisplayMap'] = Configuration::get('WK_GOOGLE_ACTIVE_MAP'); @@ -197,6 +207,10 @@ class AdminAddHotelController extends ModuleAdminController $address = Tools::getValue('address'); $active = Tools::getValue('ENABLE_HOTEL'); $activeRefund = Tools::getValue('active_refund'); + $enableUseGlobalMaxOrderDate = Tools::getValue('enable_use_global_max_order_date'); + $maximumBookingDate = Tools::getValue('maximum_booking_date'); + $enableUseGlobalPreparationTime = Tools::getValue('enable_use_global_preparation_time'); + $preparationTime = Tools::getValue('preparation_time'); $latitude = Tools::getValue('loclatitude'); $longitude = Tools::getValue('loclongitude'); $map_formated_address = Tools::getValue('locformatedAddr'); @@ -291,6 +305,27 @@ class AdminAddHotelController extends ModuleAdminController $this->errors[] = $this->l('Enter a Valid City Name.'); } + if ($idHotel) { + if (!$enableUseGlobalMaxOrderDate) { + $maximumBookingDateFormatted = date('Y-m-d', strtotime($maximumBookingDate)); + if ($maximumBookingDate == '') { + $this->errors[] = Tools::displayError('Maximum Global Date to book a room is a required field.'); + } elseif (!Validate::isDate($maximumBookingDateFormatted)) { + $this->errors[] = Tools::displayError('Maximum Global Date to book a room is invalid.'); + } elseif (strtotime($maximumBookingDateFormatted) < strtotime(date('Y-m-d'))) { + $this->errors[] = Tools::displayError('Maximum Global Date to book a room can not be a past date. Please use a future date.'); + } + } + + if (!$enableUseGlobalPreparationTime) { + if ($preparationTime === '') { + $this->errors[] = Tools::displayError('Preparation time is a required field.'); + } elseif ($preparationTime !== '0' && !Validate::isUnsignedInt($preparationTime)) { + $this->errors[] = Tools::displayError('Preparation time is invalid.'); + } + } + } + if (!count($this->errors)) { if ($idHotel) { $objHotelBranch = new HotelBranchInformation($idHotel); @@ -474,6 +509,28 @@ class AdminAddHotelController extends ModuleAdminController } } + if ($idHotel) { + // save maximum booking date and preparation time + $objHotelOrderRestrictDate = new HotelOrderRestrictDate(); + $restrictDateInfo = HotelOrderRestrictDate::getDataByHotelId($newIdHotel); + if ($restrictDateInfo) { + $objHotelOrderRestrictDate = new HotelOrderRestrictDate($restrictDateInfo['id']); + } else { + $objHotelOrderRestrictDate = new HotelOrderRestrictDate(); + } + + $objHotelOrderRestrictDate->id_hotel = $newIdHotel; + $objHotelOrderRestrictDate->use_global_max_order_date = $enableUseGlobalMaxOrderDate; + if (!$enableUseGlobalMaxOrderDate) { + $objHotelOrderRestrictDate->max_order_date = $maximumBookingDateFormatted; + } + $objHotelOrderRestrictDate->use_global_preparation_time = $enableUseGlobalPreparationTime; + if (!$enableUseGlobalPreparationTime) { + $objHotelOrderRestrictDate->preparation_time = $preparationTime; + } + $objHotelOrderRestrictDate->save(); + } + if (Tools::isSubmit('submitAdd'.$this->table.'AndStay')) { if ($idHotel) { Tools::redirectAdmin( diff --git a/modules/hotelreservationsystem/controllers/admin/AdminHotelConfigurationSettingController.php b/modules/hotelreservationsystem/controllers/admin/AdminHotelConfigurationSettingController.php index aa756be79..9680cf5e4 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminHotelConfigurationSettingController.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminHotelConfigurationSettingController.php @@ -26,7 +26,6 @@ class AdminHotelConfigurationSettingController extends ModuleAdminController $this->tpl_view_vars = array( 'feature_price_setting_link' => $this->context->link->getAdminLink('AdminHotelFeaturePricesSettings'), 'general_setting_link' => $this->context->link->getAdminLink('AdminHotelGeneralSettings'), - 'order_restrict_setting_link' => $this->context->link->getAdminLink('AdminOrderRestrictSettings'), 'additional_demand_setting_link' => $this->context->link->getAdminLink('AdminRoomTypeGlobalDemand'), ); diff --git a/modules/hotelreservationsystem/controllers/admin/AdminOrderRestrictSettingsController.php b/modules/hotelreservationsystem/controllers/admin/AdminOrderRestrictSettingsController.php deleted file mode 100644 index 07d5bcb84..000000000 --- a/modules/hotelreservationsystem/controllers/admin/AdminOrderRestrictSettingsController.php +++ /dev/null @@ -1,208 +0,0 @@ -table = 'htl_order_restrict_date'; - $this->className = 'HotelOrderRestrictDate'; - $this->bootstrap = true; - $this->identifier = 'id'; - $this->context = Context::getContext(); - - // START send access query information to the admin controller - $this->access_select = ' SELECT a.`id` FROM '._DB_PREFIX_.'htl_order_restrict_date a'; - $this->access_join = ' INNER JOIN '._DB_PREFIX_.'htl_branch_info hbi ON (hbi.id = a.id_hotel)'; - if ($acsHtls = HotelBranchInformation::getProfileAccessedHotels($this->context->employee->id_profile, 1, 1)) { - $this->access_where = ' WHERE hbi.id IN ('.implode(',', $acsHtls).')'; - } - - parent::__construct(); - $this->_join .= ' LEFT JOIN `'._DB_PREFIX_.'htl_branch_info` hb ON (a.`id_hotel` = hb.`id`)'; - $this->_join .= 'LEFT JOIN `'._DB_PREFIX_.'address` ad ON (ad.`id_hotel` = hb.`id`)'; - $this->_join .= ' LEFT JOIN `'._DB_PREFIX_.'htl_branch_info_lang` hbl - ON (hb.`id` = hbl.`id` AND hbl.`id_lang` = '.(int)$this->context->language->id.')'; - $this->_join .= ' LEFT JOIN `'._DB_PREFIX_.'state` s ON (s.`id_state` = ad.`id_state`)'; - $this->_join .= ' LEFT JOIN `'._DB_PREFIX_.'country_lang` cl - ON (cl.`id_country` = ad.`id_country` AND cl.`id_lang` = '.(int)$this->context->language->id.')'; - $this->_select = 's.`name` as `state_name`, cl.`name` as country_name, hbl.`hotel_name`, ad.`city`, '; - $this->fields_options = array( - 'orderrestrict' => array( - 'title' => $this->l('Order Restriction Setting'), - 'fields' => array( - 'MAX_GLOBAL_BOOKING_DATE' => array( - 'title' => $this->l('Maximum Global Date To Book a room'), - 'type' => 'text', - 'id' => 'max_global_book_date', - 'hint' => $this->l('Maximum date by which rooms of your hotels can be booked.'), - ), - ), - 'submit' => array('title' => $this->l('Save')), - ), - ); - $this->fields_list = array( - 'id' => array( - 'title' => $this->l('ID'), - 'align' => 'center', - ), - 'hotel_name' => array( - 'title' => $this->l('Hotel Name'), - 'align' => 'center', - ), - 'city' => array( - 'title' => $this->l('City'), - 'align' => 'center', - ), - 'state_name' => array( - 'title' => $this->l('State'), - 'align' => 'center', - 'filter_key' => 's!name', - ), - 'country_name' => array( - 'title' => $this->l('Country'), - 'align' => 'center', - 'filter_key' => 'cl!name', - ), - 'max_order_date' => array( - 'title' => $this->l('Maximum Booking Date'), - 'align' => 'center', - 'type' => 'date', - ), - ); - $this->bulk_actions = array( - 'delete' => array( - 'text' => $this->l('Delete selected'), - 'icon' => 'icon-trash', - 'confirm' => $this->l('Delete selected items?'), - ), - ); - } - - public function renderList() - { - $this->addRowAction('edit'); - $this->addRowAction('delete'); - - return parent::renderList(); - } - - public function initToolbar() - { - parent::initToolbar(); - $this->page_header_toolbar_btn['new'] = array( - 'href' => self::$currentIndex.'&add'.$this->table.'&token='.$this->token, - 'desc' => $this->l('Add new Date'), - ); - } - - public function renderForm() - { - if ($this->display == 'add') { - $order_restrict_date = new HotelOrderRestrictDate(); - $hotels_list = $order_restrict_date->getUnsavedHotelsForOrderRestrict(); - // filter hotels as per accessed hotels - $hotels_list = HotelBranchInformation::filterDataByHotelAccess( - $hotels_list, - $this->context->employee->id_profile, - 1 - ); - $this->context->smarty->assign('hotels_list', $hotels_list); - } elseif ($this->display == 'edit') { - $id = Tools::getValue('id'); - $obj_order_restrict = new HotelOrderRestrictDate($id); - $hotel_info_obj = new HotelBranchInformation( - $obj_order_restrict->id_hotel, - (int)$this->context->language->id - ); - $ordr_restrict_data['hotel_name'] = $hotel_info_obj->hotel_name; - $ordr_restrict_data['id_hotel'] = $obj_order_restrict->id_hotel; - $ordr_restrict_data['max_date'] = date('d-m-Y', strtotime($obj_order_restrict->max_order_date)); - $ordr_restrict_data['hidden_max_date'] = date('Y-m-d', strtotime($obj_order_restrict->max_order_date)); - - $this->context->smarty->assign( - array( - 'ordr_restrict_hotel_data' => $ordr_restrict_data, - 'id' => $id, - 'edit' => 1 - ) - ); - } - $this->fields_form = array( - 'submit' => array( - 'title' => $this->l('Save'), - ), - ); - return parent::renderForm(); - } - - public function processSave() - { - $id = Tools::getValue('id'); - $hotel_id = Tools::getValue('hotel_id'); - $max_htl_book_date = Tools::getValue('max_htl_book_date'); - if (!$hotel_id) { - $this->errors[] = $this->l('Please Select a Hotel.'); - } - if (!$max_htl_book_date) { - $this->errors[] = $this->l('Please select maximum order date of booking.'); - } else { - $max_htl_book_date = date('Y-m-d', strtotime($max_htl_book_date)); - if (!Validate::isDate($max_htl_book_date)) { - $this->errors[] = $this->l('Enter a valid date.'); - } - } - - if (!count($this->errors)) { - $obj_order_restrict = new HotelOrderRestrictDate(); - $ordr_restrict_data = $obj_order_restrict->getDataByHotelId($hotel_id); - if (isset($ordr_restrict_data['id']) && $ordr_restrict_data['id']) { - $obj_order_restrict = new HotelOrderRestrictDate($ordr_restrict_data['id']); - } - - $obj_order_restrict->id_hotel = $hotel_id; - $obj_order_restrict->max_order_date = $max_htl_book_date; - $obj_order_restrict->save(); - $new_id = $obj_order_restrict->id; - if (Tools::isSubmit('submitAdd'.$this->table.'AndStay')) { - if (isset($new_id) && $new_id) { - Tools::redirectAdmin( - self::$currentIndex.'&id='.(int) $new_id.'&update'.$this->table.'&conf=4&token='.$this->token - ); - } else { - Tools::redirectAdmin( - self::$currentIndex.'&add'.$this->table.'&conf=4&token='.$this->token - ); - } - } else { - Tools::redirectAdmin($this->context->link->getAdminLink('AdminOrderRestrictSettings').'&conf=4'); - } - } else { - $this->display = 'add'; - } - } - - public function postProcess() - { - if (Tools::isSubmit('submitOptionshtl_order_restrict_date')) { - $max_global_date = Tools::getValue('MAX_GLOBAL_BOOKING_DATE'); - $max_global_date_frm = date('Y-m-d', strtotime($max_global_date)); - if (!Validate::isDate($max_global_date_frm)) { - $this->errors[] = $this->l('Enter a valid date.'); - } else if (strtotime(date('Y-m-d')) > strtotime($max_global_date_frm)) { - $this->errors[] = $this->l('Maximum Global Date can not be before current date.'); - } - if (!count($this->errors)) { - parent::postProcess(); - } - } else { - parent::postProcess(); - } - } - - public function setMedia() - { - parent::setMedia(); - $this->addJs(_MODULE_DIR_.'hotelreservationsystem/views/js/HotelReservationAdmin.js'); - $this->addCSS(_MODULE_DIR_.'hotelreservationsystem/views/css/HotelReservationAdmin.css'); - } -} diff --git a/modules/hotelreservationsystem/hotelreservationsystem.php b/modules/hotelreservationsystem/hotelreservationsystem.php index f99e09875..e552451b9 100644 --- a/modules/hotelreservationsystem/hotelreservationsystem.php +++ b/modules/hotelreservationsystem/hotelreservationsystem.php @@ -489,7 +489,6 @@ class HotelReservationSystem extends Module ); // Controllers without tabs - $this->installTab('AdminOrderRestrictSettings', 'Order Restrict Configuration', false, false); $this->installTab('AdminHotelGeneralSettings', 'Hotel General configuration', false, false); $this->installTab('AdminHotelFeaturePricesSettings', 'Advanced Price Rules', false, false); $this->installTab('AdminRoomTypeGlobalDemand', 'Additional Demand Configuration', false, false); diff --git a/modules/hotelreservationsystem/views/js/HotelReservationAdmin.js b/modules/hotelreservationsystem/views/js/HotelReservationAdmin.js index 0f14cd5b4..5d9bacea1 100644 --- a/modules/hotelreservationsystem/views/js/HotelReservationAdmin.js +++ b/modules/hotelreservationsystem/views/js/HotelReservationAdmin.js @@ -109,7 +109,7 @@ var GoogleMapsManager = { that.autocomplete.addListener('place_changed', function() { that.clearAllMarkers(); var place = that.autocomplete.getPlace(); - + if (place.geometry.viewport) { that.map.fitBounds(place.geometry.viewport); } else { @@ -136,7 +136,7 @@ var GoogleMapsManager = { e.preventDefault(); } }); - + if(cb && typeof cb === 'function') { cb(); } @@ -903,7 +903,7 @@ $(document).ready(function() { //$( "#max_global_book_date" ).datepicker( "option", "maxDate", '20 Mar 2020'); /*END*/ - + /* ---- AdminHotelFeaturePricesSettingsController Admin ---- */ $('#date_selection_type').on('change', function() { @@ -1159,6 +1159,29 @@ $(document).ready(function() { }); } + // manage hotel page + $('#maximum_booking_date').datepicker({ + defaultDate: new Date(), + dateFormat: 'dd-mm-yy', + minDate: 0, + }); + + $('input[name="enable_use_global_max_order_date"]').on('change', function () { + if (parseInt($(this).val())) { + $('input[name="maximum_booking_date"]').closest('.form-group').hide(200); + } else { + $('input[name="maximum_booking_date"]').closest('.form-group').show(200); + } + }); + + $('input[name="enable_use_global_preparation_time"]').on('change', function () { + if (parseInt($(this).val())) { + $('input[name="preparation_time"]').closest('.form-group').hide(200); + } else { + $('input[name="preparation_time"]').closest('.form-group').show(200); + } + }); + initGoogleMaps(); }); diff --git a/modules/hotelreservationsystem/views/templates/admin/add_hotel/helpers/form/form.tpl b/modules/hotelreservationsystem/views/templates/admin/add_hotel/helpers/form/form.tpl index 0a081f036..f0127c0b4 100644 --- a/modules/hotelreservationsystem/views/templates/admin/add_hotel/helpers/form/form.tpl +++ b/modules/hotelreservationsystem/views/templates/admin/add_hotel/helpers/form/form.tpl @@ -68,6 +68,12 @@ {l s='Images' mod='hotelreservationsystem'} +