Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added: Upgrade of rooms while reallocation and also fixed reallocation and swapping issues #901

Merged
merged 5 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion admin/themes/default/sass/controllers/_order.sass
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,23 @@
img
max-height: 55px
max-width: 55px
.loading_overlay
display: none
position: fixed
left: 0
top: 0
height: 100%
width: 100%
background-color: rgba(0, 0, 0, 0.5)
z-index: 100000
.loading-img
position: absolute
top: 50%
left: 0
right: 0
margin: 0 auto


.room_status_info_form
.room_status
white-space: normal
white-space: normal
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@
</button>
<ul class="dropdown-menu" role="menu">
<li>
<a href="#" data-toggle="modal" data-target="#mySwappigModal" data-id_order="{$order->id}" data-room_num='{$data.room_num}' data-date_from='{$data.date_from}' data-date_to='{$data.date_to}' data-id_room='{$data.id_room}' data-cust_name='{$data.alloted_cust_name}' data-cust_email='{$data.alloted_cust_email}' data-avail_rm_swap='{$data.avail_rooms_to_swap|@json_encode}' data-avail_rm_realloc='{$data.avail_rooms_to_realloc|@json_encode}'>
<a href="#" id="reallocate_room_{$data['id']}" data-room_type_name="{$data['room_type_name']}" data-toggle="modal" data-target="#mySwappigModal" data-id_htl_booking="{$data['id']}" data-room_num='{$data.room_num}' data-id_room_type='{$data.id_product}' data-cust_name='{$data.alloted_cust_name}' data-cust_email='{$data.alloted_cust_email}' data-avail_rm_swap='{$data.avail_rooms_to_swap|@json_encode}' data-avail_realloc_room_types='{$data.avail_room_types_to_realloc|@json_encode}'>
<i class="icon-refresh"></i>
{l s='Reallocate/Swap Room'}
</a>
Expand Down
370 changes: 260 additions & 110 deletions admin/themes/default/template/controllers/orders/helpers/view/view.tpl

Large diffs are not rendered by default.

161 changes: 110 additions & 51 deletions controllers/admin/AdminOrdersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,9 @@ public function __construct()
}

parent::__construct();

$this->_conf[52] = $this->l('Room in the booking is successfully reallocated');
$this->_conf[53] = $this->l('Room in the booking is successfully swapped');
}

public static function setOrderCurrency($echo, $tr)
Expand Down Expand Up @@ -603,75 +606,94 @@ public function renderList()

public function postProcess()
{
// by webkul for reallocation of rooms
// Process reallocation of rooms
if (Tools::isSubmit('realloc_allocated_rooms')) {
if ($this->tabAccess['edit'] === '1') {
$order_id = Tools::getValue('id_order');
$current_room_id = Tools::getValue('modal_id_room');
$current_room = Tools::getValue('modal_curr_room_num');
$date_from = Tools::getValue('modal_date_from');
$date_to = Tools::getValue('modal_date_to');
$realloc_room_id = Tools::getValue('realloc_avail_rooms');

if ($realloc_room_id == 0) {
$this->errors[] = Tools::displayError('Please select a room to swap with this room.');
}
if ($current_room_id == 0) {
$this->errors[] = Tools::displayError('Cuurent room is missing.');
}
if ($date_from == 0) {
$this->errors[] = Tools::displayError('Check In date is missing.');
}
if ($date_to == 0) {
$this->errors[] = Tools::displayError('Check Out date is missing.');
$idOrder = Tools::getValue('id_order');
$idHtlBookingFrom = Tools::getValue('id_htl_booking');
$idNewRoomType = Tools::getValue('realloc_avail_room_type');
$idRoomToReallocate = Tools::getValue('realloc_avail_rooms');
$priceDiff = Tools::getValue('reallocation_price_diff');

$objBookingDetail = new HotelBookingDetail();
if ($idRoomToReallocate) {
// check if room is from selected room type
if (Validate::isLoadedObject($objRoomInfo = new HotelRoomInformation($idRoomToReallocate))) {
if ($objRoomInfo->id_product != $idNewRoomType) {
$this->errors[] = $this->l('Invalid room selected for reallocation.');
} elseif (!Validate::isLoadedObject($objHotelBooking = new HotelBookingDetail($idHtlBookingFrom))) {
$this->errors[] = $this->l('Invalid booking found for reallocation.');
} elseif (!$availableRooms = $objBookingDetail->getAvailableRoomsForReallocation(
$objHotelBooking->date_from,
$objHotelBooking->date_to,
$idNewRoomType,
$objHotelBooking->id_hotel
)) {
$this->errors[] = $this->l('Selected room is not available for reallocation.');
} elseif (!in_array($idRoomToReallocate, array_column($availableRooms, 'id_room'))) {
$this->errors[] = $this->l('Selected room is not available for reallocation.');
} elseif (!Validate::isFloat($priceDiff)) {
$this->errors[] = $this->l('Invalid price difference of the room types.');
}
} else {
$this->errors[] = $this->l('Selected room is not available for reallocation.');
}
} else {
$this->errors[] = $this->l('Please select a room to reallocate with this room.');
}

if (!count($this->errors)) {
$objBookingDetail = new HotelBookingDetail();
$room_swapped = $objBookingDetail->reallocateRoomWithAvailableSameRoomType($current_room_id, $date_from, $date_to, $realloc_room_id);
if (!$room_swapped) {
$this->errors[] = Tools::displayError('Some error occured. Please try again.');
// Finally, reallocate the room
if ($objBookingDetail->reallocateBooking($idHtlBookingFrom, $idRoomToReallocate, $priceDiff)) {
Tools::redirectAdmin(self::$currentIndex.'&id_order='.(int) $idOrder.'&vieworder&conf=52&token='.$this->token);
} else {
Tools::redirectAdmin(self::$currentIndex.'&id_order='.(int) $order_id.'&vieworder&token='.$this->token);
$this->errors[] = $this->l('Some error occured. Please try again.');
}
}
} else {
$this->errors[] = Tools::displayError('You do not have permission to edit this.');
$this->errors[] = $this->l('You do not have permission to edit this.');
}
}

// Process swap of rooms
if (Tools::isSubmit('swap_allocated_rooms')) {
if ($this->tabAccess['edit'] === '1') {
$order_id = Tools::getValue('id_order');
$current_room_id = Tools::getValue('modal_id_room');
$current_room = Tools::getValue('modal_curr_room_num');
$date_from = Tools::getValue('modal_date_from');
$date_to = Tools::getValue('modal_date_to');
$swapped_room_id = Tools::getValue('swap_avail_rooms');

if ($swapped_room_id == 0) {
$this->errors[] = Tools::displayError('Please select a room to swap with this room.');
}
if ($current_room_id == 0) {
$this->errors[] = Tools::displayError('Cuurent room is missing.');
}
if ($date_from == 0) {
$this->errors[] = Tools::displayError('Check In date is missing.');
}
if ($date_to == 0) {
$this->errors[] = Tools::displayError('Check Out date is missing.');
$idOrder = Tools::getValue('id_order');
$idHtlBookingFrom = Tools::getValue('id_htl_booking');
$idHtlBookingToSwap = Tools::getValue('swap_avail_rooms');

if (!Validate::isLoadedObject($objHotelBooking = new HotelBookingDetail($idHtlBookingFrom))) {
$this->errors[] = $this->l('Selected room is not available to swap.');
} else {
if (!Validate::isLoadedObject($objHotelBookingTo = new HotelBookingDetail($idHtlBookingToSwap))) {
$this->errors[] = $this->l('Please select a room to swap with this room booking.');
} else {
if ($availableRooms = $objHotelBooking->getAvailableRoomsForSwapping(
$objHotelBooking->date_from,
$objHotelBooking->date_to,
$objHotelBooking->id_product,
$objHotelBooking->id_hotel,
$objHotelBooking->id_room
)) {
if (!in_array($idHtlBookingToSwap, array_column($availableRooms, 'id_hotel_booking'))) {
$this->errors[] = $this->l('Selected room is not available to swap.');
}
} else {
$this->errors[] = $this->l('Selected room is not available to swap.');
}
}
}

if (!count($this->errors)) {
$objBookingDetail = new HotelBookingDetail();
$room_swapped = $objBookingDetail->swapRoomWithAvailableSameRoomType($current_room_id, $date_from, $date_to, $swapped_room_id);
if (!$room_swapped) {
$this->errors[] = Tools::displayError('Some error occured. Please try again.');
if ($objBookingDetail->swapBooking($idHtlBookingFrom, $idHtlBookingToSwap)) {
Tools::redirectAdmin(self::$currentIndex.'&id_order='.(int)$idOrder.'&vieworder&conf=53&token='.$this->token);
} else {
Tools::redirectAdmin(self::$currentIndex.'&id_order='.(int) $order_id.'&vieworder&token='.$this->token);
$this->errors[] = $this->l('Some error occured. Please try again.');
}
}
} else {
$this->errors[] = Tools::displayError('You do not have permission to edit this.');
$this->errors[] = $this->l('You do not have permission to edit this.');
}
}
// To update order status when admin changes from order detail page
Expand Down Expand Up @@ -2012,7 +2034,7 @@ public function renderView()
$order_detail_data[$key]['alloted_cust_email'] = $this->l('No customer name found');
}

$order_detail_data[$key]['avail_rooms_to_realloc'] = $objBookingDetail->getAvailableRoomsForReallocation($value['date_from'], $value['date_to'], $value['id_product'], $value['id_hotel']);
$order_detail_data[$key]['avail_room_types_to_realloc'] = $objBookingDetail->getAvailableRoomsForReallocation($value['date_from'], $value['date_to'], 0, $value['id_hotel'], 1);
$order_detail_data[$key]['avail_rooms_to_swap'] = $objBookingDetail->getAvailableRoomsForSwapping($value['date_from'], $value['date_to'], $value['id_product'], $value['id_hotel'], $value['id_room']);

/*Product price when order was created*/
Expand Down Expand Up @@ -5593,8 +5615,6 @@ public function ajaxProcessAddRoomAdditionalServices()
$product['total_wt'] = Tools::ps_round($totalPriceTaxIncl, _PS_PRICE_COMPUTE_PRECISION_) * (int)$product['cart_quantity'];
break;
}


}

$order_detail = new OrderDetail();
Expand Down Expand Up @@ -5970,4 +5990,43 @@ public function changeRoomStatus()
}
}
}

// ajax request to get room type upgrade/degrade changes information to reallocate
public function ajaxProcessChangeRoomTypeToReallocate()
{
$result = array();
$result['success'] = 0;
$result['has_price_changes'] = 0;
$result['has_room_type_change'] = 0;

$idHotelBooking = Tools::getValue('id_htl_booking');
$idNewRoomType = Tools::getValue('id_new_room_type');

// if room type id is present in the ajax request or not
if ($idNewRoomType) {
// validate the booking is valid or not
if (Validate::isLoadedObject($objHotelBooking = new HotelBookingDetail($idHotelBooking))) {
$result['success'] = 1;
// if room is changing in the reallocation
if ($objHotelBooking->id_product != $idNewRoomType) {
$result['has_room_type_change'] = 1;
$newRoomTotalPrice = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice(
$idNewRoomType,
$objHotelBooking->date_from,
$objHotelBooking->date_to
);
if ($objHotelBooking->total_price_tax_excl != $newRoomTotalPrice['total_price_tax_excl']) {
$result['has_price_changes'] = 1;
$result['price_diff'] = $newRoomTotalPrice['total_price_tax_excl'] - $objHotelBooking->total_price_tax_excl;
}
}
} else {
$result['error'] = $this->l('Invalid booking information. Please try again.');
}
} else {
$result['error'] = $this->l('Selected room type not found. Please try again.');
}

$this->ajaxDie(json_encode($result));
}
}
Binary file modified img/admin/ajax-loader.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading