text changes and update getdashboard data logic
This commit is contained in:
@@ -1383,39 +1383,108 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
return Db::getInstance()->getValue($sql);
|
||||
}
|
||||
|
||||
public static function getOccupancyData($dateFrom, $dateTo, $idHotel = false)
|
||||
public static function getOccupancyData($dateFrom, $dateTo, $idsHotel = false)
|
||||
{
|
||||
$objHotelBookingDetail = new HotelBookingDetail();
|
||||
$objHotelBranchInformation = new HotelBranchInformation();
|
||||
$context = Context::getContext();
|
||||
$idsHotel = $objHotelBranchInformation->getProfileAccessedHotels($context->employee->id_profile, 1, 1);
|
||||
$occupancyData = array('count_total' => 0, 'count_occupied' => 0, 'count_available' => 0, 'count_unavailable' => 0);
|
||||
if(!$idHotel){
|
||||
$dataStats = [
|
||||
'num_unavail'=> 0,
|
||||
'num_booked'=> 0,
|
||||
'num_avail'=> 0,
|
||||
'total_rooms'=> 0,
|
||||
];
|
||||
foreach ($idsHotel ?:[] as $idHotel) {
|
||||
$bookingData = $objHotelBookingDetail->getDateWiseBooking($dateFrom , $dateTo , $idHotel);
|
||||
$dataStats['num_avail'] += $bookingData['stats']['available'];
|
||||
$dataStats['num_unavail'] += $bookingData['stats']['unavailable'];
|
||||
$dataStats['num_booked'] += $bookingData['stats']['booked'];
|
||||
$dataStats['total_rooms'] += $bookingData['stats']['total_rooms'];
|
||||
}
|
||||
$occupancyData['count_available'] = $dataStats['num_avail'];
|
||||
$occupancyData['count_occupied'] = $dataStats['num_booked'];
|
||||
$occupancyData['count_unavailable'] = $dataStats['num_unavail'];
|
||||
$occupancyData['count_total'] = $dataStats['total_rooms'];
|
||||
if ($dateFrom == $dateTo) {
|
||||
$dateTo = date('Y-m-d', strtotime('+1 day', strtotime($dateTo)));
|
||||
}
|
||||
else{
|
||||
$bookingData = $objHotelBookingDetail->getDateWiseBooking($dateFrom , $dateTo , $idHotel);
|
||||
$occupancyData['count_available'] = $bookingData['stats']['available'];
|
||||
$occupancyData['count_occupied'] = $bookingData['stats']['booked'];
|
||||
$occupancyData['count_unavailable'] = $bookingData['stats']['unavailable'];
|
||||
$occupancyData['count_total'] = $bookingData['stats']['total_rooms'];
|
||||
}
|
||||
|
||||
try {
|
||||
$dtFrom = new DateTime($dateFrom);
|
||||
$dtTo = new DateTime($dateTo);
|
||||
$numNights = (int)$dtFrom->diff($dtTo)->days;
|
||||
} catch (Exception $e) {
|
||||
$tsFrom = strtotime((string)$dateFrom);
|
||||
$tsTo = strtotime((string)$dateTo);
|
||||
$numNights = ($tsFrom && $tsTo) ? (int)(($tsTo - $tsFrom) / 86400) : 1;
|
||||
}
|
||||
if ($numNights <= 0) {
|
||||
$numNights = 1;
|
||||
}
|
||||
|
||||
$occupancyData = array('count_total' => 0, 'count_occupied' => 0, 'count_available' => 0, 'count_unavailable' => 0);
|
||||
|
||||
$countRooms = (int)self::getTotalRooms($idsHotel, true);
|
||||
$countTotal = $countRooms * $numNights;
|
||||
$occupancyData['count_total'] = (int)$countTotal;
|
||||
|
||||
// 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`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'product` p
|
||||
ON (p.`id_product` = hri.`id_product`)
|
||||
WHERE 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')
|
||||
);
|
||||
$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') : '')
|
||||
);
|
||||
|
||||
$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
|
||||
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 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') : '')
|
||||
);
|
||||
|
||||
$countUnavailable = ($countInactiveRooms * $numNights) + $countTemporarilyInactiveNights;
|
||||
$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;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<header class="panel-heading">
|
||||
<i class="icon-bar-chart"></i>
|
||||
<span>{l s='Occupancy' mod='dashoccupancy'} </span>
|
||||
<i class="icon-info-circle label-tooltip" data-toggle="tooltip" data-original-title="{l s='Occupancy information will be displayed for the selected date range.' mod='dashoccupancy'}"></i>
|
||||
<i class="icon-info-circle label-tooltip" data-toggle="tooltip" data-original-title="{l s='Displays the total number of nights (occupied, available, and unavailable) for the selected date range.' mod='dashoccupancy'}"></i>
|
||||
<span class="panel-heading-action">
|
||||
<a class="list-toolbar-btn" href="javascript:void(0);" title="Refresh" onclick="refreshDashboard('dashoccupancy'); return false;">
|
||||
<i class="process-icon-refresh"></i>
|
||||
@@ -34,7 +34,7 @@
|
||||
<div class="row text-center avil-chart-head">
|
||||
<div class="col-md-4 col-xs-4">
|
||||
<div class="row">
|
||||
<div class="col-md-11 label-tooltip col-lg-11 avail-pie-label-container" style="background: #A569DF;" data-toggle="tooltip" data-original-title="{l s='The total number of room nights booked for the selected date range out of total available room nights.' mod='dashoccupancy'}">
|
||||
<div class="col-md-11 label-tooltip col-lg-11 avail-pie-label-container" style="background: #A569DF;" data-toggle="tooltip" data-original-title="{l s='The total number of booked room nights in the selected date range out of total available room nights.' mod='dashoccupancy'}">
|
||||
<div class="">
|
||||
<p class="avail-pie-text">
|
||||
{l s='Occupied' mod='dashoccupancy'}
|
||||
@@ -50,7 +50,7 @@
|
||||
</div>
|
||||
<div class="col-md-4 col-xs-4">
|
||||
<div class="row">
|
||||
<div class="col-md-11 col-lg-11 avail-pie-label-container label-tooltip" style="background: #56CE56;" data-toggle="tooltip" data-original-title="{l s='The total number of room nights available for booking for the selected date range.' mod='dashoccupancy'}">
|
||||
<div class="col-md-11 col-lg-11 avail-pie-label-container label-tooltip" style="background: #56CE56;" data-toggle="tooltip" data-original-title="{l s='The total number of available room nights in the selected date range.' mod='dashoccupancy'}">
|
||||
<div class="">
|
||||
<p class="avail-pie-text">
|
||||
{l s='Available' mod='dashoccupancy'}
|
||||
@@ -66,7 +66,7 @@
|
||||
</div>
|
||||
<div class="col-md-4 col-xs-4">
|
||||
<div class="row">
|
||||
<div class="col-md-11 col-lg-11 avail-pie-label-container label-tooltip" style="background: #FF655C;" data-toggle="tooltip" data-original-title="{l s='The total number of room nights unavailable for booking for the selected date range.' mod='dashoccupancy'}">
|
||||
<div class="col-md-11 col-lg-11 avail-pie-label-container label-tooltip" style="background: #FF655C;" data-toggle="tooltip" data-original-title="{l s='The total number of unavailable room nights in the selected date range out of total available room nights.' mod='dashoccupancy'}">
|
||||
<div class="">
|
||||
<p class="avail-pie-text">
|
||||
{l s='Unavailable' mod='dashoccupancy'}
|
||||
|
||||
@@ -3798,157 +3798,4 @@ class HotelBookingDetail extends ObjectModel
|
||||
|
||||
return parent::add($auto_date, $null_values);
|
||||
}
|
||||
//Datewise Booking Data
|
||||
public function getDateWiseBooking($dateFrom, $dateTo, $idHotel)
|
||||
{
|
||||
$objBookingDetail = new HotelBookingDetail();
|
||||
// if same date selected, extend by 1 day
|
||||
if ($dateFrom == $dateTo) {
|
||||
$dateTo = date('Y-m-d', strtotime($dateTo . ' +1 day'));
|
||||
}
|
||||
|
||||
$bookingParams = [
|
||||
'date_from' => $dateFrom,
|
||||
'date_to' => $dateTo,
|
||||
'search_available' => 1,
|
||||
'search_partial' => 1,
|
||||
'search_booked' => 1,
|
||||
'search_unavai' => 1,
|
||||
'hotel_id' => $idHotel,
|
||||
];
|
||||
$bookingData = $objBookingDetail->getBookingData($bookingParams);
|
||||
|
||||
$bookedDates = [];
|
||||
$partialUnavailableDates = [];
|
||||
$permanentUnavailableDates = [];
|
||||
|
||||
if (!empty($bookingData['rm_data'])) {
|
||||
foreach ($bookingData['rm_data'] as $key => $roomType) {
|
||||
$roomTypeId = $roomType['id_product'];
|
||||
// Get all rooms of this room type
|
||||
|
||||
$rooms = HotelRoomInformation::getHotelRoomsInfo($idHotel, $roomTypeId);
|
||||
$bookingData['rm_data'][$key]['all_rooms'] = [];
|
||||
foreach ($rooms ?: [] as $room) {
|
||||
$bookingData['rm_data'][$key]['all_rooms'][$room['id']] = [
|
||||
'id_room' => $room['id'],
|
||||
'room_num' => $room['room_num'],
|
||||
];
|
||||
}
|
||||
|
||||
//booked rooms
|
||||
foreach ($roomType['data']['booked'] ?: [] as $bookedRoom) {
|
||||
foreach ($bookedRoom['detail'] ?: [] as $detail) {
|
||||
$start = date('Y-m-d', strtotime($detail['date_from']));
|
||||
$end = date('Y-m-d', strtotime($detail['date_to']));
|
||||
for ($d = $start; $d < $end; $d = date('Y-m-d', strtotime('+1 day', strtotime($d)))) {
|
||||
$bookedDates[$d][$roomTypeId][$bookedRoom['id_room']] =
|
||||
$bookedRoom['id_room'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// unavailable rooms
|
||||
foreach ($roomType['data']['unavailable'] ?: [] as $unavailableRoom) {
|
||||
foreach ($unavailableRoom['detail'] ?: [] as $detail) {
|
||||
// permanent unavailable rooms
|
||||
if (empty($detail['date_from']) && empty($detail['date_to'])) {
|
||||
for ( $d = date('Y-m-d', strtotime($dateFrom)); $d < date('Y-m-d', strtotime($dateTo)); $d = date('Y-m-d', strtotime('+1 day', strtotime($d)))
|
||||
) {
|
||||
$permanentUnavailableDates[$d][$roomTypeId][$unavailableRoom['id_room']] =
|
||||
$unavailableRoom['id_room'];
|
||||
}
|
||||
} else {
|
||||
//partial unavailable rooms
|
||||
$start = date('Y-m-d', strtotime($detail['date_from']));
|
||||
$end = date('Y-m-d', strtotime($detail['date_to']));
|
||||
for ($d = $start; $d < $end; $d = date('Y-m-d', strtotime('+1 day', strtotime($d)))) {
|
||||
$partialUnavailableDates[$d][$roomTypeId][$unavailableRoom['id_room']] =
|
||||
$unavailableRoom['id_room'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$response = [
|
||||
'data' => [],
|
||||
'stats' => [
|
||||
'total_rooms' => 0,
|
||||
'available' => 0,
|
||||
'booked' => 0,
|
||||
'unavailable' => 0,
|
||||
'partial_unavailable' => 0,
|
||||
'permanent_unavailable' => 0,
|
||||
],
|
||||
];
|
||||
for (
|
||||
$currentDate = date('Y-m-d', strtotime($dateFrom));
|
||||
$currentDate < date('Y-m-d', strtotime($dateTo));
|
||||
$currentDate = date('Y-m-d', strtotime('+1 day', strtotime($currentDate)))
|
||||
) {
|
||||
|
||||
$nextDate = date('Y-m-d', strtotime('+1 day', strtotime($currentDate)));
|
||||
|
||||
$dateWiseInfo = [
|
||||
'id_hotel' => $idHotel,
|
||||
'date_from' => $currentDate,
|
||||
'date_to' => $nextDate,
|
||||
'room_types'=> [],
|
||||
];
|
||||
|
||||
foreach ($bookingData['rm_data'] ?: [] as $roomType) {
|
||||
$roomTypeId = $roomType['id_product'];
|
||||
$allRooms = $roomType['all_rooms'] ?: [];
|
||||
$available = $allRooms;
|
||||
$booked = [];
|
||||
$partial = [];
|
||||
$permanent = [];
|
||||
//remove booked
|
||||
if (!empty($bookedDates[$currentDate][$roomTypeId])) {
|
||||
|
||||
$booked = array_intersect_key(
|
||||
$allRooms,
|
||||
$bookedDates[$currentDate][$roomTypeId]
|
||||
);
|
||||
|
||||
$available = array_diff_key($available, $booked);
|
||||
}
|
||||
//permanent unavailbale
|
||||
if (!empty($permanentUnavailableDates[$currentDate][$roomTypeId])) {
|
||||
$permanent = array_intersect_key(
|
||||
$allRooms,
|
||||
$permanentUnavailableDates[$currentDate][$roomTypeId]
|
||||
);
|
||||
$available = array_diff_key($available, $permanent);
|
||||
}
|
||||
//partial unavailbale
|
||||
if (!empty($partialUnavailableDates[$currentDate][$roomTypeId])) {
|
||||
$partial = array_intersect_key(
|
||||
$allRooms,
|
||||
$partialUnavailableDates[$currentDate][$roomTypeId]
|
||||
);
|
||||
$available = array_diff_key($available, $partial);
|
||||
}
|
||||
$response['stats']['total_rooms'] += count($allRooms);
|
||||
$response['stats']['available'] += count($available);
|
||||
$response['stats']['booked'] += count($booked);
|
||||
$response['stats']['partial_unavailable'] += count($partial);
|
||||
$response['stats']['permanent_unavailable'] += count($permanent);
|
||||
$response['stats']['unavailable'] += count($partial) + count($permanent);
|
||||
$dateWiseInfo['room_types'][] = [
|
||||
'id_room_type' => $roomTypeId,
|
||||
'name' => $roomType['name'],
|
||||
'rooms' => [
|
||||
'available' => $available,
|
||||
'booked' => $booked,
|
||||
'partial_unavailable' => $partial,
|
||||
'permanent_unavailable' => $permanent,
|
||||
],
|
||||
];
|
||||
}
|
||||
$response['data'][] = $dateWiseInfo;
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user