Merge branch 'develop' into gli-2961
This commit is contained in:
@@ -51,25 +51,31 @@ class AdminModulesCatalogControllerCore extends AdminController
|
||||
parent::initContent();
|
||||
|
||||
$suggestedModules = Module::getSuggestedModules();
|
||||
$modulesDirOnDisk = Module::getModulesDirOnDisk();
|
||||
$localModuleNames = array();
|
||||
|
||||
$modulesToAdd = array();
|
||||
$dirModules = ModuleCore::getModulesOnDisk();
|
||||
$modules_name = array_column($suggestedModules, 'name');
|
||||
foreach ($dirModules as $mod) {
|
||||
if (($id = array_search($mod->name, $modules_name)) !== false) {
|
||||
if ($mod->installed) {
|
||||
unset($suggestedModules[$id]);
|
||||
} else {
|
||||
$suggestedModules[$id]->not_on_disk = false;
|
||||
}
|
||||
} else {
|
||||
if (!$mod->installed) {
|
||||
$modulesToAdd[] = $mod;
|
||||
}
|
||||
}
|
||||
foreach ($modulesDirOnDisk as $moduleName) {
|
||||
$localModuleNames[Tools::strtolower($moduleName)] = true;
|
||||
}
|
||||
|
||||
$modules = array_merge($suggestedModules, $modulesToAdd);
|
||||
$modules = array();
|
||||
|
||||
foreach ($suggestedModules as $suggestedModule) {
|
||||
$moduleName = Tools::strtolower($suggestedModule->name);
|
||||
if (isset($localModuleNames[$moduleName])) {
|
||||
continue;
|
||||
}
|
||||
if (!empty($suggestedModule->compatibility)) {
|
||||
$minVersion = isset($suggestedModule->compatibility['from']) ? $suggestedModule->compatibility['from'] : null;
|
||||
$maxVersion = isset($suggestedModule->compatibility['to']) ? $suggestedModule->compatibility['to'] : null;
|
||||
|
||||
if (($minVersion && version_compare(_QLOAPPS_VERSION_, $minVersion, '<')) || ($maxVersion && version_compare(_QLOAPPS_VERSION_, $maxVersion, '>'))) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$modules[] = $suggestedModule;
|
||||
}
|
||||
|
||||
$link_admin_modules = $this->context->link->getAdminLink('AdminModules', true);
|
||||
foreach ($modules as $key => $module) {
|
||||
|
||||
@@ -1449,8 +1449,8 @@ class AdminModulesControllerCore extends AdminController
|
||||
$modules_preferences[$v['module']] = $v;
|
||||
}
|
||||
|
||||
// Retrieve Modules List
|
||||
$modules = Module::getInstalledModulesOnDisk(true, $this->logged_on_addons, $this->id_employee);
|
||||
// Retrieve Modules List (installed + disabled + uninstalled)
|
||||
$modules = Module::getModulesOnDisk(true, $this->logged_on_addons, $this->id_employee);
|
||||
$this->initModulesList($modules);
|
||||
$this->nb_modules_total = count($modules);
|
||||
$module_errors = array();
|
||||
|
||||
@@ -786,6 +786,8 @@ class AdminOrdersControllerCore extends AdminController
|
||||
'order' => $objOrder,
|
||||
'current_index' => self::$currentIndex,
|
||||
'hotel_order_status' => $htlOrderStatus,
|
||||
'ROOM_STATUS_ALLOTED' => HotelBookingDetail::STATUS_ALLOTED,
|
||||
'current_room_status' => Tools::getValue('current_room_status')
|
||||
)
|
||||
);
|
||||
$modal = array(
|
||||
@@ -8723,30 +8725,49 @@ class AdminOrdersControllerCore extends AdminController
|
||||
}
|
||||
|
||||
if (empty($this->errors)) {
|
||||
$objHotelBookingDetail->id_status = $newStatus;
|
||||
if ($newStatus == HotelBookingDetail::STATUS_CHECKED_IN) {
|
||||
$objHotelBookingDetail->check_in = $statusDate;
|
||||
} elseif ($newStatus == HotelBookingDetail::STATUS_CHECKED_OUT) {
|
||||
$objHotelBookingDetail->check_out = $statusDate;
|
||||
} else {
|
||||
$objHotelBookingDetail->check_in = '';
|
||||
$objHotelBookingDetail->check_out = '';
|
||||
}
|
||||
if ($objHotelBookingDetail->save()) {
|
||||
Hook::exec(
|
||||
'actionRoomBookingStatusUpdateAfter',
|
||||
array(
|
||||
'id_hotel_booking_detail' => $objHotelBookingDetail->id,
|
||||
'id_order' => $objHotelBookingDetail->id_order,
|
||||
'id_room' => $objHotelBookingDetail->id_room,
|
||||
'date_from' => $objHotelBookingDetail->date_from,
|
||||
'date_to' => $objHotelBookingDetail->date_to
|
||||
)
|
||||
);
|
||||
|
||||
Tools::redirectAdmin(self::$currentIndex.'&id_order='.(int) $objHotelBookingDetail->id_order.'&vieworder&token='.$this->token.'&conf=4');
|
||||
$id_order = $objHotelBookingDetail->id_order;
|
||||
$order = new Order($id_order);
|
||||
$remainingCheckoutRooms = 0;
|
||||
if ($newStatus == HotelBookingDetail::STATUS_CHECKED_OUT) {
|
||||
$orderBookings = $objHotelBookingDetail->getOrderCurrentDataByOrderId(
|
||||
$id_order,
|
||||
array(HotelBookingDetail::STATUS_ALLOTED, HotelBookingDetail::STATUS_CHECKED_IN),
|
||||
0,
|
||||
0
|
||||
);
|
||||
$remainingCheckoutRooms = count($orderBookings);
|
||||
}
|
||||
$hasPendingBills = $order->getTotalPaid() < $order->getOrderTotal();
|
||||
|
||||
if ($remainingCheckoutRooms == 1 && $newStatus == HotelBookingDetail::STATUS_CHECKED_OUT && $hasPendingBills) {
|
||||
$this->errors[] = Tools::displayError('You cannot checkout the last room while there are pending bills for this order.');
|
||||
} else {
|
||||
$this->errors[] = Tools::displayError('Some error occurred. Please try again.');
|
||||
$objHotelBookingDetail->id_status = $newStatus;
|
||||
if ($newStatus == HotelBookingDetail::STATUS_CHECKED_IN) {
|
||||
$objHotelBookingDetail->check_in = $statusDate;
|
||||
} elseif ($newStatus == HotelBookingDetail::STATUS_CHECKED_OUT) {
|
||||
$objHotelBookingDetail->check_out = $statusDate;
|
||||
} else {
|
||||
$objHotelBookingDetail->check_in = '';
|
||||
$objHotelBookingDetail->check_out = '';
|
||||
}
|
||||
if ($objHotelBookingDetail->save()) {
|
||||
Hook::exec(
|
||||
'actionRoomBookingStatusUpdateAfter',
|
||||
array(
|
||||
'id_hotel_booking_detail' => $objHotelBookingDetail->id,
|
||||
'id_order' => $objHotelBookingDetail->id_order,
|
||||
'id_room' => $objHotelBookingDetail->id_room,
|
||||
'date_from' => $objHotelBookingDetail->date_from,
|
||||
'date_to' => $objHotelBookingDetail->date_to
|
||||
)
|
||||
);
|
||||
|
||||
Tools::redirectAdmin(self::$currentIndex . '&id_order=' . (int) $objHotelBookingDetail->id_order . '&vieworder&token=' . $this->token . '&conf=4');
|
||||
} else {
|
||||
$this->errors[] = Tools::displayError('Some error occurred. Please try again.');
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -149,6 +149,24 @@ class AdminPerformanceControllerCore extends AdminController
|
||||
'icon' => 'icon-bug'
|
||||
),
|
||||
'input' => array(
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Debug mode'),
|
||||
'name' => 'debug_mode',
|
||||
'class' => 't',
|
||||
'is_bool' => true,
|
||||
'values' => array(
|
||||
array(
|
||||
'value' => 1,
|
||||
'label' => $this->l('Enabled')
|
||||
),
|
||||
array(
|
||||
'value' => 0,
|
||||
'label' => $this->l('Disabled')
|
||||
)
|
||||
),
|
||||
'hint' => $this->l('Enable or disable debug mode. Debug mode will enable extended error reporting.')
|
||||
),
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Disable non QloApps modules'),
|
||||
@@ -196,6 +214,7 @@ class AdminPerformanceControllerCore extends AdminController
|
||||
);
|
||||
|
||||
$this->fields_value['native_module'] = Configuration::get('PS_DISABLE_NON_NATIVE_MODULE');
|
||||
$this->fields_value['debug_mode'] = _PS_MODE_DEV_;
|
||||
$this->fields_value['overrides'] = Configuration::get('PS_DISABLE_OVERRIDES');
|
||||
}
|
||||
|
||||
@@ -885,6 +904,12 @@ class AdminPerformanceControllerCore extends AdminController
|
||||
if (Tools::isSubmit('submitAddconfiguration')) {
|
||||
Configuration::updateGlobalValue('PS_DISABLE_NON_NATIVE_MODULE', (int)Tools::getValue('native_module'));
|
||||
Configuration::updateGlobalValue('PS_DISABLE_OVERRIDES', (int)Tools::getValue('overrides'));
|
||||
|
||||
$debugValue = ((int) Tools::getValue('debug_mode') === 1) ? 'true' : 'false';
|
||||
if (!$this->updateDebugMode($debugValue)) {
|
||||
$this->errors[] = $this->l('Unable to update debug mode. Please check file permissions.');
|
||||
}
|
||||
|
||||
Tools::generateIndex();
|
||||
}
|
||||
|
||||
@@ -894,6 +919,26 @@ class AdminPerformanceControllerCore extends AdminController
|
||||
}
|
||||
}
|
||||
|
||||
public function updateDebugMode($value)
|
||||
{
|
||||
$filename = _PS_ROOT_DIR_ . '/config/defines.inc.php';
|
||||
|
||||
if (is_readable($filename)) {
|
||||
$cleanedFileContent = php_strip_whitespace($filename);
|
||||
if (preg_match('/define\(\'_PS_MODE_DEV_\', ([a-zA-Z]+)\);/Ui', $cleanedFileContent)) {
|
||||
$fileContent = Tools::file_get_contents($filename);
|
||||
$fileContent = preg_replace('/define\(\'_PS_MODE_DEV_\', ([a-zA-Z]+)\);/Ui', 'define(\'_PS_MODE_DEV_\', ' . $value . ');', $fileContent);
|
||||
if (@file_put_contents($filename, $fileContent)) {
|
||||
if (function_exists('opcache_invalidate')) {
|
||||
@opcache_invalidate($filename);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function displayAjaxTestServer()
|
||||
{
|
||||
/* PrestaShop demo mode */
|
||||
|
||||
@@ -2024,6 +2024,16 @@ class AdminProductsControllerCore extends AdminController
|
||||
$this->errors[] = $error;
|
||||
}
|
||||
|
||||
if (!count($this->errors)) {
|
||||
$objHotelRoomType = new HotelRoomType();
|
||||
if ($roomTypeInfo = $objHotelRoomType->getRoomTypeInfoByIdProduct($this->object->id)) {
|
||||
$objHotelBranchInformation = new HotelBranchInformation((int)$roomTypeInfo['id_hotel']);
|
||||
if (!$objHotelBranchInformation->active && !$this->object->active) {
|
||||
$this->errors[] = $this->l('Room type can not be active as long as hotel is disabled.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (count($this->errors)) {
|
||||
return false;
|
||||
}
|
||||
@@ -2041,6 +2051,61 @@ class AdminProductsControllerCore extends AdminController
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function processBulkStatusSelection($status)
|
||||
{
|
||||
if (!is_array($this->boxes) || empty($this->boxes)) {
|
||||
return parent::processBulkStatusSelection($status);
|
||||
}
|
||||
|
||||
$disabledHotelRoomTypes = array();
|
||||
$objHotelRoomType = new HotelRoomType();
|
||||
$result = true;
|
||||
$hasSuccessfulUpdate = false;
|
||||
|
||||
foreach ($this->boxes as $id) {
|
||||
$id = (int) $id;
|
||||
$object = new $this->className($id);
|
||||
if (!Validate::isLoadedObject($object)) {
|
||||
$this->errors[] = sprintf($this->l('Invalid room type ID %d.'), $id);
|
||||
$result = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($status && ($roomTypeInfo = $objHotelRoomType->getRoomTypeInfoByIdProduct($id))) {
|
||||
$objHotelBranchInformation = new HotelBranchInformation((int) $roomTypeInfo['id_hotel']);
|
||||
if (!$objHotelBranchInformation->active) {
|
||||
$disabledHotelRoomTypes[] = Product::getProductName($id, null, (int)$this->context->language->id);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$object->setFieldsToUpdate(array('active' => true));
|
||||
$object->active = (int) $status;
|
||||
$isUpdated = (bool) $object->update();
|
||||
$result = $result && $isUpdated;
|
||||
$hasSuccessfulUpdate = $hasSuccessfulUpdate || $isUpdated;
|
||||
|
||||
if (!$isUpdated) {
|
||||
$this->errors[] = sprintf($this->l('Can\'t update #%d status.'), $id);
|
||||
}
|
||||
}
|
||||
|
||||
if ($disabledHotelRoomTypes) {
|
||||
$this->errors[] =
|
||||
$this->l('Room types linked to inactive hotels cannot be enabled.');
|
||||
}
|
||||
|
||||
if ($result && $hasSuccessfulUpdate && !$disabledHotelRoomTypes) {
|
||||
$this->redirect_after = self::$currentIndex.'&conf=5&token='.$this->token;
|
||||
} elseif ($result && $hasSuccessfulUpdate) {
|
||||
$this->confirmations[] = $this->l('The status has been updated for the room types linked to active hotels.');
|
||||
} elseif (!$result) {
|
||||
$this->errors[] = $this->l('An error occurred while updating the status.');
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function processToggleShowAtFront()
|
||||
{
|
||||
if (!$this->loadObject()) {
|
||||
@@ -2366,6 +2431,10 @@ class AdminProductsControllerCore extends AdminController
|
||||
} else if (!Validate::isLoadedObject($objHotel = new HotelBranchInformation($id_hotel))) {
|
||||
$this->errors[] = Tools::displayError('Selected Hotel not found');
|
||||
} else {
|
||||
// Prevent enabling a room type when its hotel is disabled
|
||||
if ((int)Tools::getValue('active') === 1 && isset($objHotel) && !$objHotel->active) {
|
||||
$this->errors[] = Tools::displayError('Room type can not be active as long as hotel is disabled.');
|
||||
}
|
||||
$hotelIdCategory = $objHotel->id_category;
|
||||
if (Validate::isLoadedObject($objCategory = new Category($hotelIdCategory))) {
|
||||
foreach($objCategory->getParentsCategories() as $category) {
|
||||
|
||||
@@ -1389,65 +1389,182 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
$dateTo = date('Y-m-d', strtotime('+1 day', strtotime($dateTo)));
|
||||
}
|
||||
|
||||
$dtFrom = new DateTime($dateFrom);
|
||||
$dtTo = new DateTime($dateTo);
|
||||
$numNights = (int)$dtFrom->diff($dtTo)->days;
|
||||
if ($numNights <= 0) {
|
||||
$numNights = 1;
|
||||
}
|
||||
|
||||
$occupancyData = array('count_total' => 0, 'count_occupied' => 0, 'count_available' => 0, 'count_unavailable' => 0);
|
||||
|
||||
$countTotal = self::getTotalRooms($idsHotel, true);
|
||||
$occupancyData['count_total'] = $countTotal;
|
||||
$countRooms = (int)self::getTotalRooms($idsHotel, true);
|
||||
$countTotal = $countRooms * $numNights;
|
||||
$occupancyData['count_total'] = (int)$countTotal;
|
||||
|
||||
// Occupied rooms are booked rooms that are not refunded in the date range
|
||||
$countOccupied = 0;
|
||||
$occupiedRooms = Db::getInstance()->executeS(
|
||||
'SELECT DISTINCT hbd.`id_room`
|
||||
// Occupied are booked room-nights (non-refunded) in the date range.
|
||||
$countOccupied = (int)Db::getInstance()->getValue(
|
||||
'SELECT IFNULL(SUM(
|
||||
GREATEST(
|
||||
0,
|
||||
DATEDIFF(
|
||||
LEAST(
|
||||
IF(hbd.`id_status` = '.(int)HotelBookingDetail::STATUS_CHECKED_OUT.',
|
||||
DATE_FORMAT(hbd.`check_out`, "%Y-%m-%d"),
|
||||
hbd.`date_to`
|
||||
),
|
||||
"'.pSQL($dateTo).'"
|
||||
),
|
||||
GREATEST(hbd.`date_from`, "'.pSQL($dateFrom).'")
|
||||
)
|
||||
)
|
||||
), 0)
|
||||
FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
|
||||
LEFT JOIN `'._DB_PREFIX_.'htl_room_information` hri
|
||||
ON (hri.`id` = hbd.`id_room`)
|
||||
ON (hri.`id` = hbd.`id_room`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'product` p
|
||||
ON (p.`id_product` = hri.`id_product`)
|
||||
ON (p.`id_product` = hri.`id_product`)
|
||||
WHERE p.`active` = 1
|
||||
AND p.`booking_product` = 1
|
||||
AND hbd.`is_refunded` = 0
|
||||
AND IF(hbd.`id_status` = '. HotelBookingDetail::STATUS_CHECKED_OUT .', hbd.`date_from` < DATE_FORMAT(hbd.`check_out`, "%Y-%m-%d") AND hbd.`date_from` < \''.pSQL($dateTo).'\' AND DATE_FORMAT(hbd.`check_out`, "%Y-%m-%d") > \''.pSQL($dateFrom).'\', hbd.`date_from` < \''.pSQL($dateTo).'\' AND hbd.`date_to` > \''.pSQL($dateFrom).'\')'.
|
||||
AND hbd.`date_from` < "'.pSQL($dateTo).'"
|
||||
AND IF(hbd.`id_status` = '.(int)HotelBookingDetail::STATUS_CHECKED_OUT.',
|
||||
DATE_FORMAT(hbd.`check_out`, "%Y-%m-%d"),
|
||||
hbd.`date_to`
|
||||
) > "'.pSQL($dateFrom).'"'.
|
||||
HotelBranchInformation::addHotelRestriction($idsHotel, 'hbd')
|
||||
);
|
||||
$occupancyData['count_occupied'] = $countOccupied;
|
||||
|
||||
// Unavailable are:
|
||||
// - inactive rooms (unavailable for all nights in the range)
|
||||
// - temporarily inactive rooms for overlapping disabled date ranges (night-wise)
|
||||
$countInactiveRooms = (int)Db::getInstance()->getValue(
|
||||
'SELECT IFNULL(COUNT(hri.`id`), 0)
|
||||
FROM `'._DB_PREFIX_.'htl_room_information` hri
|
||||
LEFT JOIN `'._DB_PREFIX_.'product` p
|
||||
ON (p.`id_product` = hri.`id_product`)
|
||||
WHERE hri.`id_status` = '.(int)HotelRoomInformation::STATUS_INACTIVE.'
|
||||
AND p.`active` = 1
|
||||
AND p.`booking_product` = 1'.
|
||||
(!is_null($idsHotel) ? HotelBranchInformation::addHotelRestriction($idsHotel, 'hri') : '')
|
||||
);
|
||||
|
||||
// Booked nights for rooms that are currently inactive should not be counted as unavailable.
|
||||
$countOccupiedInactiveNights = (int)Db::getInstance()->getValue(
|
||||
'SELECT IFNULL(SUM(
|
||||
GREATEST(
|
||||
0,
|
||||
DATEDIFF(
|
||||
LEAST(
|
||||
IF(hbd.`id_status` = '.(int)HotelBookingDetail::STATUS_CHECKED_OUT.',
|
||||
DATE_FORMAT(hbd.`check_out`, "%Y-%m-%d"),
|
||||
hbd.`date_to`
|
||||
),
|
||||
"'.pSQL($dateTo).'"
|
||||
),
|
||||
GREATEST(hbd.`date_from`, "'.pSQL($dateFrom).'")
|
||||
)
|
||||
)
|
||||
), 0)
|
||||
FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
|
||||
LEFT JOIN `'._DB_PREFIX_.'htl_room_information` hri
|
||||
ON (hri.`id` = hbd.`id_room`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'product` p
|
||||
ON (p.`id_product` = hri.`id_product`)
|
||||
WHERE hri.`id_status` = '.(int)HotelRoomInformation::STATUS_INACTIVE.'
|
||||
AND p.`active` = 1
|
||||
AND p.`booking_product` = 1
|
||||
AND hbd.`is_refunded` = 0
|
||||
AND hbd.`date_from` < "'.pSQL($dateTo).'"
|
||||
AND IF(hbd.`id_status` = '.(int)HotelBookingDetail::STATUS_CHECKED_OUT.',
|
||||
DATE_FORMAT(hbd.`check_out`, "%Y-%m-%d"),
|
||||
hbd.`date_to`
|
||||
) > "'.pSQL($dateFrom).'"'.
|
||||
HotelBranchInformation::addHotelRestriction($idsHotel, 'hbd')
|
||||
);
|
||||
|
||||
if ($occupiedRooms) {
|
||||
$occupiedRooms = array_column($occupiedRooms, 'id_room');
|
||||
$occupancyData['count_occupied'] = count($occupiedRooms);
|
||||
} else {
|
||||
$occupancyData['count_occupied'] = 0;
|
||||
}
|
||||
|
||||
// Unavailable rooms are rooms that are not booked for the date range and in the inactive status
|
||||
$countUnavailable = Db::getInstance()->getValue(
|
||||
'SELECT COUNT(hri.`id`)
|
||||
$countTemporarilyInactiveNights = (int)Db::getInstance()->getValue(
|
||||
'SELECT IFNULL(SUM(
|
||||
GREATEST(
|
||||
0,
|
||||
DATEDIFF(
|
||||
LEAST(hrdd.`date_to`, "'.pSQL($dateTo).'"),
|
||||
GREATEST(hrdd.`date_from`, "'.pSQL($dateFrom).'")
|
||||
)
|
||||
)
|
||||
), 0)
|
||||
FROM `'._DB_PREFIX_.'htl_room_information` hri
|
||||
LEFT JOIN `'._DB_PREFIX_.'htl_branch_info` hbi
|
||||
ON (hbi.`id` = hri.`id_hotel`)
|
||||
INNER JOIN `'._DB_PREFIX_.'htl_room_disable_dates` hrdd
|
||||
ON (hrdd.`id_room` = hri.`id`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'product` p
|
||||
ON (p.`id_product` = hri.`id_product`)
|
||||
WHERE p.`active` = 1 '.
|
||||
($occupiedRooms ? ' AND hri.`id` NOT IN ('.implode(',', $occupiedRooms).')' : '').
|
||||
' AND hri.`id_status` = '.(int) HotelRoomInformation::STATUS_INACTIVE.
|
||||
HotelBranchInformation::addHotelRestriction($idsHotel, 'hbi', 'id')
|
||||
);
|
||||
$occupancyData['count_unavailable'] = $countUnavailable;
|
||||
|
||||
// Available rooms are rooms that are not booked for the date range and in the temporary inactive for the date range
|
||||
$countDisabled = Db::getInstance()->getValue(
|
||||
'SELECT IFNULL(COUNT(hri.`id`), 0)
|
||||
FROM `'._DB_PREFIX_.'htl_room_information` hri
|
||||
LEFT JOIN `'._DB_PREFIX_.'htl_room_disable_dates` hrdd
|
||||
ON (hrdd.`id_room` = hri.`id`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'product` p
|
||||
ON (p.`id_product` = hri.`id_product`)
|
||||
WHERE hri.`id_status` = '.(int) HotelRoomInformation::STATUS_TEMPORARY_INACTIVE.
|
||||
($occupiedRooms ? ' AND hri.`id` NOT IN ('.implode(',', $occupiedRooms).')' : '').
|
||||
' AND ("'.pSQL($dateTo).'" > hrdd.`date_from` AND "'.pSQL($dateFrom).'" < hrdd.`date_to`)
|
||||
AND p.`active` = 1'.
|
||||
ON (p.`id_product` = hri.`id_product`)
|
||||
WHERE hri.`id_status` = '.(int)HotelRoomInformation::STATUS_TEMPORARY_INACTIVE.'
|
||||
AND hrdd.`date_from` < "'.pSQL($dateTo).'"
|
||||
AND hrdd.`date_to` > "'.pSQL($dateFrom).'"
|
||||
AND p.`active` = 1
|
||||
AND p.`booking_product` = 1'.
|
||||
(!is_null($idsHotel) ? HotelBranchInformation::addHotelRestriction($idsHotel, 'hri') : '')
|
||||
);
|
||||
$occupancyData['count_unavailable'] += $countDisabled;
|
||||
|
||||
$occupancyData['count_available'] = $occupancyData['count_total'] - $occupancyData['count_occupied'] - $occupancyData['count_unavailable'];
|
||||
// Booked nights overlapping temporary disable ranges should not be counted as unavailable.
|
||||
$countOccupiedTemporaryInactiveNights = (int)Db::getInstance()->getValue(
|
||||
'SELECT IFNULL(SUM(
|
||||
GREATEST(
|
||||
0,
|
||||
DATEDIFF(
|
||||
LEAST(
|
||||
IF(hbd.`id_status` = '.(int)HotelBookingDetail::STATUS_CHECKED_OUT.',
|
||||
DATE_FORMAT(hbd.`check_out`, "%Y-%m-%d"),
|
||||
hbd.`date_to`
|
||||
),
|
||||
hrdd.`date_to`,
|
||||
"'.pSQL($dateTo).'"
|
||||
),
|
||||
GREATEST(
|
||||
hbd.`date_from`,
|
||||
hrdd.`date_from`,
|
||||
"'.pSQL($dateFrom).'"
|
||||
)
|
||||
)
|
||||
)
|
||||
), 0)
|
||||
FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
|
||||
INNER JOIN `'._DB_PREFIX_.'htl_room_disable_dates` hrdd
|
||||
ON (hrdd.`id_room` = hbd.`id_room`)
|
||||
INNER JOIN `'._DB_PREFIX_.'htl_room_information` hri
|
||||
ON (hri.`id` = hbd.`id_room`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'product` p
|
||||
ON (p.`id_product` = hri.`id_product`)
|
||||
WHERE hri.`id_status` = '.(int)HotelRoomInformation::STATUS_TEMPORARY_INACTIVE.'
|
||||
AND p.`active` = 1
|
||||
AND p.`booking_product` = 1
|
||||
AND hbd.`is_refunded` = 0
|
||||
AND hrdd.`date_from` < "'.pSQL($dateTo).'"
|
||||
AND hrdd.`date_to` > "'.pSQL($dateFrom).'"
|
||||
AND hbd.`date_from` < "'.pSQL($dateTo).'"
|
||||
AND IF(hbd.`id_status` = '.(int)HotelBookingDetail::STATUS_CHECKED_OUT.',
|
||||
DATE_FORMAT(hbd.`check_out`, "%Y-%m-%d"),
|
||||
hbd.`date_to`
|
||||
) > "'.pSQL($dateFrom).'"'.
|
||||
HotelBranchInformation::addHotelRestriction($idsHotel, 'hbd')
|
||||
);
|
||||
|
||||
$inactiveUnavailable = ($countInactiveRooms * $numNights) - $countOccupiedInactiveNights;
|
||||
if ($inactiveUnavailable < 0) {
|
||||
$inactiveUnavailable = 0;
|
||||
}
|
||||
|
||||
$temporaryUnavailable = $countTemporarilyInactiveNights - $countOccupiedTemporaryInactiveNights;
|
||||
if ($temporaryUnavailable < 0) {
|
||||
$temporaryUnavailable = 0;
|
||||
}
|
||||
|
||||
$countUnavailable = $inactiveUnavailable + $temporaryUnavailable;
|
||||
$occupancyData['count_unavailable'] = (int)$countUnavailable;
|
||||
|
||||
$countAvailable = (int)$occupancyData['count_total'] - (int)$occupancyData['count_occupied'] - (int)$occupancyData['count_unavailable'];
|
||||
$occupancyData['count_available'] = $countAvailable > 0 ? $countAvailable : 0;
|
||||
|
||||
return $occupancyData;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user