Skip to content

Commit

Permalink
Merge pull request #851 from shreesh-webkul/gli-1110
Browse files Browse the repository at this point in the history
Updated: Same day room checkin - checkout and select time along with checkin - checkout
  • Loading branch information
rohit053 authored Mar 17, 2024
2 parents 54f3f80 + 30a0788 commit 7ca3813
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,8 @@
{/if}

{* field for the current date *}
<input class="room_status_date wk-input-date" type="text" name="status_date" value="{if $data['id_status'] == $hotel_order_status['STATUS_CHECKED_IN']['id_status']}{$data['date_to']|date_format:"%d-%m-%Y"}{else}{$data['date_from']|date_format:"%d-%m-%Y"}{/if}" readonly/>

<input class="room_status_date wk-input-date" type="text" name="status_date" value="{if $data['id_status'] == $hotel_order_status['STATUS_CHECKED_IN']['id_status']}{$data['date_to']|date_format:"%d-%m-%Y"} {$data['check_out_time']}{else}{$data['date_from']|date_format:"%d-%m-%Y"} {$data['check_in_time']}{/if}" readonly/>
<input type="hidden" name="id_hotel_booking_detail" value="{$data['id']}" />
<input type="hidden" name="date_from" value="{$data['date_from']|date_format:"%Y-%m-%d"}" />
<input type="hidden" name="date_to" value="{$data['date_to']|date_format:"%Y-%m-%d"}" />
<input type="hidden" name="id_room" value="{$data['id_room']}" />
Expand Down Expand Up @@ -1722,12 +1722,11 @@
{* open date picker for the date input of check-in checkout dates *}
$(document).on('focus', '.room_status_date', function() {
var dateFrom = $(this).closest('.room_status_info_form').find('[name="date_from"]').val();
minDate = $.datepicker.parseDate('yy-mm-dd', dateFrom);
minDate = new Date(dateFrom+'T00:00:00');
var dateTo = $(this).closest('.room_status_info_form').find('[name="date_to"]').val();
maxDate = $.datepicker.parseDate('yy-mm-dd', dateTo);
$(this).datepicker({
maxDate = new Date(dateTo+'T23:59:59');
$(this).datetimepicker({
dateFormat: 'dd-mm-yy',
minDate: minDate,
maxDate: maxDate,
Expand Down
138 changes: 55 additions & 83 deletions controllers/admin/AdminOrdersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5997,97 +5997,69 @@ public function ajaxProcessUpdateServiceProduct()
// To change the status of the room
public function changeRoomStatus()
{
$idRoom = (int) Tools::getValue('id_room');
$idOrder = (int) Tools::getValue('id_order');
$dateFrom = Tools::getValue('date_from');
$dateTo = Tools::getValue('date_to');
$newStatus = (int) Tools::getValue('booking_order_status');

// date choosen for the status change
if ($statusDate = Tools::getValue('status_date')) {
$statusDate = date('Y-m-d', strtotime($statusDate));
}
// Lets validate the fields
if (!$idRoom) {
$this->errors[] = Tools::displayError('Room information not found.');
}
if (!$idOrder) {
$this->errors[] = Tools::displayError('Order information not found.');
}
if (!$dateFrom
|| !$dateTo
|| !Validate::isDate($dateFrom)
|| !Validate::isDate($dateTo)
) {
$this->errors[] = Tools::displayError('Invalid dates found.');
}

if (!$newStatus) {
$this->errors[] = Tools::displayError('Invalid booking status found.');
} elseif (
$newStatus == HotelBookingDetail::STATUS_CHECKED_IN
|| $newStatus == HotelBookingDetail::STATUS_CHECKED_OUT
) {
if (!$statusDate || !Validate::isDate($statusDate)) {
$this->errors[] = Tools::displayError('Invalid dates found.');
} elseif ((strtotime($statusDate) < strtotime($dateFrom))
|| (strtotime($statusDate) > strtotime($dateTo))
) {
$this->errors[] = Tools::displayError('Invalid dates found.');
$idHotelBookingDetail = (int) Tools::getValue('id_hotel_booking_detail');
if (Validate::isLoadedObject($objHotelBookingDetail = new HotelBookingDetail($idHotelBookingDetail))) {
$newStatus = (int) Tools::getValue('booking_order_status');
// date choosen for the status change
if ($statusDate = Tools::getValue('status_date')) {
$statusDate = date('Y-m-d H:i:s', strtotime($statusDate));
}
}

if (!count($this->errors)) {
$objBookingDetail = new HotelBookingDetail();
if ($roomBookingInfo = $objBookingDetail->getRoomBookingData($idRoom, $idOrder, $dateFrom, $dateTo)) {
// if admin choose Check-Out status
if ($newStatus == HotelBookingDetail::STATUS_CHECKED_OUT
&& $roomBookingInfo['check_in'] == '0000-00-00 00:00:00'
$dateFrom = date('Y-m-d H:i:s', strtotime(date('Y-m-d', strtotime($objHotelBookingDetail->date_from))));
$dateTo = date('Y-m-d H:i:s', strtotime(date('Y-m-d', strtotime($objHotelBookingDetail->date_to)).' 23:59:59'));
if (!$newStatus) {
$this->errors[] = Tools::displayError('Invalid booking status found.');
} elseif ($newStatus == HotelBookingDetail::STATUS_CHECKED_IN
|| $newStatus == HotelBookingDetail::STATUS_CHECKED_OUT
) {
if (!$statusDate || !Validate::isDate($statusDate)) {
$this->errors[] = Tools::displayError('Invalid dates found.');
} elseif ((strtotime($statusDate) < strtotime($dateFrom))
|| (strtotime($statusDate) > strtotime($dateTo))
) {
$this->errors[] = Tools::displayError('Date should be between booking from date and to date.');
}
}
if ($newStatus == HotelBookingDetail::STATUS_CHECKED_OUT) {
if ($objHotelBookingDetail->check_in == '0000-00-00 00:00:00') {
$this->errors[] = Tools::displayError('Room status must be set to Check-In before setting the room status to Check-Out.');
} elseif ($newStatus == HotelBookingDetail::STATUS_CHECKED_OUT
&& $roomBookingInfo['check_in'] != '0000-00-00 00:00:00'
&& strtotime($roomBookingInfo['check_in']) >= strtotime($statusDate)
) {
$this->errors[] = Tools::displayError('Check-Out date can not be before Check-In date').
'('.date('d-m-Y', strtotime($roomBookingInfo['check_in'])).')';
} elseif ($newStatus == HotelBookingDetail::STATUS_CHECKED_IN && $roomBookingInfo['check_out'] == '0000-00-00 00:00:00'
&& strtotime($roomBookingInfo['check_in']) >= strtotime($dateTo)
) {
$this->errors[] = Tools::displayError('Check-In date can not be after Check-Out date').
'('.date('d-m-Y', strtotime($roomBookingInfo['date_to'])).')';
} elseif ($newStatus == HotelBookingDetail::STATUS_CHECKED_IN && $roomBookingInfo['check_out'] != '0000-00-00 00:00:00'
&& strtotime($roomBookingInfo['check_out']) <= strtotime($statusDate)
) {
$this->errors[] = Tools::displayError('Check-In date can not be after Check-Out date').
'('.date('d-m-Y', strtotime($roomBookingInfo['check_out'])).')';
} elseif (strtotime($objHotelBookingDetail->check_in) > strtotime($statusDate)) {
$this->errors[] = sprintf(
Tools::displayError('Check-Out date can not be before Check-In date (%s)'),
date('d-m-Y', strtotime($objHotelBookingDetail->check_in))
);
}
}

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 {
if ($objBookingDetail->updateBookingOrderStatusByOrderId(
$idOrder,
$newStatus,
$idRoom,
$dateFrom,
$dateTo,
$statusDate
)) {
Hook::exec(
'actionRoomBookingStatusUpdateAfter',
array(
'id_order' => $idOrder,
'id_room' => $idRoom,
'date_from' => $dateFrom,
'date_to' => $dateTo
)
);
$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) $idOrder.'&vieworder&token='.$this->token.'&conf=4');
} else {
$this->errors[] = Tools::displayError('Some error occurred. Please try again.');
}
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 {
$this->errors[] = Tools::displayError('Invalid booking information. Please try again.');
}
} else {
$this->errors[] = Tools::displayError('Invalid booking information. Please try again.');
}
}

Expand Down

0 comments on commit 7ca3813

Please sign in to comment.