Fix: restrict use of getbooking method on each day of calender
Co-authored-by: Name <sumit201@webkul.in>
This commit is contained in:
@@ -515,13 +515,9 @@ class AdminHotelRoomsBookingController extends ModuleAdminController
|
||||
$this->ajaxDie(json_encode($response));
|
||||
}
|
||||
|
||||
public function ajaxProcessGetCalenderData()
|
||||
public function ajaxProcessGetCalenderData()
|
||||
{
|
||||
$events = array();
|
||||
// No use of adults, child, num_rooms
|
||||
$adults = 0;
|
||||
$children = 0;
|
||||
$num_rooms = 1;
|
||||
|
||||
$start_date = date('Y-m-d', strtotime(Tools::getValue('start')));
|
||||
$last_day_this_month = date('Y-m-d', strtotime(Tools::getValue('end')));
|
||||
@@ -533,10 +529,6 @@ class AdminHotelRoomsBookingController extends ModuleAdminController
|
||||
$bookingParams = array();
|
||||
$bookingParams['hotel_id'] = $searchIdHotel;
|
||||
$bookingParams['id_room_type'] = $searchIdRoomType;
|
||||
$bookingParams['adults'] = $adults;
|
||||
$bookingParams['children'] = $children;
|
||||
$bookingParams['num_rooms'] = $num_rooms;
|
||||
$bookingParams['for_calendar'] = 1;
|
||||
$bookingParams['search_available'] = 1;
|
||||
$bookingParams['search_partial'] = 1;
|
||||
$bookingParams['search_booked'] = 1;
|
||||
@@ -547,27 +539,134 @@ class AdminHotelRoomsBookingController extends ModuleAdminController
|
||||
|
||||
$objBookingDetail = new HotelBookingDetail();
|
||||
|
||||
while ($start_date <= $last_day_this_month) {
|
||||
$cal_date_from = $start_date;
|
||||
$cal_date_to = date('Y-m-d', strtotime('+1 day', strtotime($cal_date_from)));
|
||||
$bookingParams['date_from'] = $cal_date_from;
|
||||
$bookingParams['date_to'] = $cal_date_to;
|
||||
$eventData = $objBookingDetail->getBookingData($bookingParams);
|
||||
if (!$eventData) {
|
||||
$eventData['stats'] = array(
|
||||
'total_room_type' => 0,
|
||||
'total_rooms' => 0,
|
||||
'max_avail_occupancy' => 0,
|
||||
'num_unavail' => 0,
|
||||
'num_cart' => 0,
|
||||
'num_booked' => 0,
|
||||
'num_avail' => 0,
|
||||
'num_part_avai' => 0,
|
||||
$rangeParams = $bookingParams;
|
||||
$rangeParams['date_from'] = $start_date;
|
||||
$rangeParams['date_to'] = date('Y-m-d', strtotime('+1 day', strtotime($last_day_this_month)));
|
||||
$rangeParams['search_available'] = 0;
|
||||
$rangeParams['search_partial'] = 0;
|
||||
$bookingData = $objBookingDetail->getBookingData($rangeParams);
|
||||
|
||||
$bookedDates = array();
|
||||
$unavailableDates = array();
|
||||
$cartDates = array();
|
||||
$numCart = 0;
|
||||
|
||||
if (!empty($bookingData['rm_data'])) {
|
||||
$roomsByProduct = array();
|
||||
foreach (HotelRoomInformation::getHotelRoomsInfo($searchIdHotel, $searchIdRoomType) ?: array() as $room) {
|
||||
$roomsByProduct[$room['id_product']][$room['id']] = array(
|
||||
'id_room' => $room['id'],
|
||||
'room_num' => $room['room_num'],
|
||||
);
|
||||
}
|
||||
|
||||
$eventData['date_format'] = Tools::displayDate($cal_date_from);
|
||||
$stats = $eventData['stats'];
|
||||
foreach ($bookingData['rm_data'] as $key => $roomType) {
|
||||
$bookingData['rm_data'][$key]['all_rooms'] = isset($roomsByProduct[$roomType['id_product']])
|
||||
? $roomsByProduct[$roomType['id_product']]
|
||||
: array();
|
||||
|
||||
// booked rooms.
|
||||
foreach ($roomType['data']['booked'] ?: array() as $bookedRoom) {
|
||||
foreach ($bookedRoom['detail'] as $detail) {
|
||||
for (
|
||||
$d = date('Y-m-d', strtotime($detail['date_from']));
|
||||
strtotime($d) < strtotime($detail['date_to']);
|
||||
$d = date('Y-m-d', strtotime('+1 day', strtotime($d)))
|
||||
) {
|
||||
$bookedDates[$d][$roomType['id_product']][$bookedRoom['id_room']] = $bookedRoom['id_room'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// unavailable rooms
|
||||
foreach ($roomType['data']['unavailable'] ?: array() as $unavailableRoom) {
|
||||
foreach ($unavailableRoom['detail'] as $detail) {
|
||||
if ($detail['date_from'] && $detail['date_to']) {
|
||||
$unavailFrom = $detail['date_from'];
|
||||
$unavailTo = $detail['date_to'];
|
||||
} else {
|
||||
$unavailFrom = $rangeParams['date_from'];
|
||||
$unavailTo = $rangeParams['date_to'];
|
||||
}
|
||||
for (
|
||||
$d = date('Y-m-d', strtotime($unavailFrom));
|
||||
strtotime($d) < strtotime($unavailTo);
|
||||
$d = date('Y-m-d', strtotime('+1 day', strtotime($d)))
|
||||
) {
|
||||
$unavailableDates[$d][$roomType['id_product']][$unavailableRoom['id_room']] = $unavailableRoom['id_room'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// cart-rooms
|
||||
foreach ($roomType['data']['cart_rooms'] ?: array() as $cartRoom) {
|
||||
$numCart++;
|
||||
for (
|
||||
$d = date('Y-m-d', strtotime($cartRoom['date_from']));
|
||||
strtotime($d) < strtotime($cartRoom['date_to']);
|
||||
$d = date('Y-m-d', strtotime('+1 day', strtotime($d)))
|
||||
) {
|
||||
$cartDates[$d][$roomType['id_product']][$cartRoom['id_room']] = $cartRoom['id_room'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while ($start_date <= $last_day_this_month) {
|
||||
$cal_date_from = $start_date;
|
||||
|
||||
$stats = array(
|
||||
'total_room_type' => 0,
|
||||
'total_rooms' => 0,
|
||||
'max_avail_occupancy' => 0,
|
||||
'num_unavail' => 0,
|
||||
'num_cart' => $numCart,
|
||||
'num_booked' => 0,
|
||||
'num_avail' => 0,
|
||||
'num_part_avai' => 0,
|
||||
);
|
||||
|
||||
if (!empty($bookingData['rm_data'])) {
|
||||
$stats['total_room_type'] = $bookingData['stats']['total_room_type'];
|
||||
$stats['total_rooms'] = $bookingData['stats']['total_rooms'];
|
||||
|
||||
foreach ($bookingData['rm_data'] as $roomType) {
|
||||
$allRooms = $roomType['all_rooms'] ?: array();
|
||||
|
||||
// available initially all rooms
|
||||
$available = $allRooms;
|
||||
$booked = array();
|
||||
$unavail = array();
|
||||
|
||||
// remove booked rooms
|
||||
if (!empty($bookedDates[$cal_date_from][$roomType['id_product']])) {
|
||||
$booked = array_intersect_key($allRooms, $bookedDates[$cal_date_from][$roomType['id_product']]);
|
||||
$available = array_diff_key($available, $booked);
|
||||
}
|
||||
|
||||
// remove unavailable rooms
|
||||
if (!empty($unavailableDates[$cal_date_from][$roomType['id_product']])) {
|
||||
$unavail = array_intersect_key($allRooms, $unavailableDates[$cal_date_from][$roomType['id_product']]);
|
||||
$available = array_diff_key($available, $unavail);
|
||||
}
|
||||
|
||||
// remove cart rooms
|
||||
if (!empty($cartDates[$cal_date_from][$roomType['id_product']])) {
|
||||
$available = array_diff_key($available, array_intersect_key($allRooms, $cartDates[$cal_date_from][$roomType['id_product']]));
|
||||
}
|
||||
|
||||
$stats['num_booked'] += count($booked);
|
||||
$stats['num_unavail'] += count($unavail);
|
||||
$stats['num_avail'] += count($available);
|
||||
$stats['max_avail_occupancy'] += count($available) * (int) $roomType['max_guests'];
|
||||
}
|
||||
}
|
||||
|
||||
$eventData = array(
|
||||
'stats' => $stats,
|
||||
'date_format' => Tools::displayDate($cal_date_from),
|
||||
);
|
||||
|
||||
if ($stats['num_avail'] > 0) {
|
||||
$cellBgColor = $this->eventColors['available']['cell'];
|
||||
} elseif ($stats['num_part_avai'] > 0) {
|
||||
@@ -577,9 +676,9 @@ class AdminHotelRoomsBookingController extends ModuleAdminController
|
||||
} else {
|
||||
$cellBgColor = $this->eventColors['unavailable']['cell'];
|
||||
}
|
||||
$events[strtotime($bookingParams['date_from'])] = array(
|
||||
$events[strtotime($cal_date_from)] = array(
|
||||
'is_notification' => 1,
|
||||
'start' => date('Y-m-d', strtotime($bookingParams['date_from'])),
|
||||
'start' => $cal_date_from,
|
||||
'display' => 'background',
|
||||
'backgroundColor' => $cellBgColor,
|
||||
'data' => $eventData
|
||||
|
||||
Reference in New Issue
Block a user