{l s='Available Rooms To Swap:'}
@@ -1979,6 +1985,7 @@
$('#mySwappigModal').on('shown.bs.modal', function (e)
{
+ $(".modal_id_htl_booking").val(e.relatedTarget.dataset.id_htl_booking);
$(".modal_id_order").val(e.relatedTarget.dataset.id_order);
$(".modal_date_from").val(e.relatedTarget.dataset.date_from);
$(".modal_date_to").val(e.relatedTarget.dataset.date_to);
@@ -1993,7 +2000,8 @@
html = '
';
$.each(json_arr_rm_swp, function(key,val) {
- html += ''+val.room_num+' ';
+ console.log(val);
+ html += ''+val.room_num+' ';
});
html += ' ';
$(".swap_avail_rooms_container").empty().append(html);
diff --git a/classes/PaymentModule.php b/classes/PaymentModule.php
index 3e89319f2..0d8eb5d19 100644
--- a/classes/PaymentModule.php
+++ b/classes/PaymentModule.php
@@ -776,15 +776,16 @@ abstract class PaymentModuleCore extends Module
// update order in htl tables
$objRoomType = new HotelRoomType();
-
$objAdvancedPayment = new HotelAdvancedPayment();
-
+ $objCartBookingData = new HotelCartBookingData();
+ $objBookingDetail = new HotelBookingDetail();
$vatAddress = new Address((int)$order->id_address_tax);
$idLang = (int)$this->context->cart->id_lang;
$normalProducts = array();
+ // variable to check max overbookings are created in the room in any date of the booking duration
+ $maxOverbookingCount = 0;
foreach ($order->product_list as $product) {
- $objCartBookingData = new HotelCartBookingData();
$idProduct = $product['id_product'];
$cartBookingData = $objCartBookingData->getOnlyCartBookingData($this->context->cart->id, $this->context->cart->id_guest, $idProduct);
if ($cartBookingData) {
@@ -792,8 +793,67 @@ abstract class PaymentModuleCore extends Module
$objCartBookingData = new HotelCartBookingData($bookingInfo['id']);
$objCartBookingData->id_order = $order->id;
$objCartBookingData->id_customer = $this->context->customer->id;
+
+ // check if still room available for this booking or not
+ $isRoomOverBooked = 1;
+
+ // get all the available rooms right now
+ $bookingParams = array(
+ 'date_from' => $objCartBookingData->date_from,
+ 'date_to' => $objCartBookingData->date_to,
+ 'hotel_id' => $objCartBookingData->id_hotel,
+ 'id_room_type' => $idProduct,
+ 'only_search_data' => 1
+ );
+
+ if ($searchRoomsInfo = $objBookingDetail->getBookingData($bookingParams)) {
+ if (isset($searchRoomsInfo['rm_data'][$idProduct]['data']['available'])
+ && $searchRoomsInfo['rm_data'][$idProduct]['data']['available']
+ ) {
+ $availableRoomsInfo = $searchRoomsInfo['rm_data'][$idProduct]['data']['available'];
+ if ($roomIdsAvailable = array_column($availableRoomsInfo, 'id_room')) {
+ // If room is still there in the available rooms list then it is not in back order
+ if (in_array($objCartBookingData->id_room, $roomIdsAvailable)) {
+ $isRoomOverBooked = 0;
+ } else {
+ $isRoomOverBooked = 1;
+ foreach ($roomIdsAvailable as $idRoom) {
+ if ($idRoom != $objCartBookingData->id_room) {
+ $objCartBookingData->id_room = $idRoom;
+ $isRoomOverBooked = 0;
+ break;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ // if room is not available right now the set it to back order
+ if ($isRoomOverBooked) {
+ $objCartBookingData->is_back_order = 1;
+
+ // max overbookings in a room datewise breakup. So that we can know no. of overbookings in every date
+ if ($roomOverBookings = $objBookingDetail->getOverbookedRooms(
+ 0,
+ $objCartBookingData->id_hotel,
+ $objCartBookingData->date_from,
+ $objCartBookingData->date_to,
+ 0,
+ 1
+ )) {
+ // check in the bokking duration what is the max overbookings in ay date in the date range
+ // replace $maxOverbookingCount with $maxOverbookingsInDate if it is greater
+ if ($maxOverbookingCount < $roomOverBookings) {
+ $maxOverbookingCount = $roomOverBookings;
+ }
+ }
+ } else {
+ $objCartBookingData->is_back_order = 0;
+ }
$objCartBookingData->save();
+ // Lets set data to the hotel booking detail table
$objBookingDetail = new HotelBookingDetail();
$id_order_detail = $objBookingDetail->getPsOrderDetailIdByIdProduct($idProduct, $order->id);
$objBookingDetail->id_product = $idProduct;
@@ -805,12 +865,9 @@ abstract class PaymentModuleCore extends Module
$objBookingDetail->id_customer = $this->context->customer->id;
$objBookingDetail->booking_type = $objCartBookingData->booking_type;
$objBookingDetail->id_status = 1;
+ $objBookingDetail->is_back_order = $objCartBookingData->is_back_order;
$objBookingDetail->comment = $objCartBookingData->comment;
- // For Back Order(Because of cart lock)
- if ($objCartBookingData->is_back_order) {
- $objBookingDetail->is_back_order = 1;
- }
$total_price = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice(
$idProduct,
$objCartBookingData->date_from,
@@ -1006,17 +1063,45 @@ abstract class PaymentModuleCore extends Module
$new_history = new OrderHistory();
$new_history->id_order = (int)$order->id;
if ($order_status->logable && $order->is_advance_payment && $order->advance_paid_amount < $order->total_paid_tax_incl) {
- $new_history->changeIdOrderState((int)Configuration::get('PS_OS_PARTIAL_PAYMENT'), $order, true);
- } else {
- $new_history->changeIdOrderState((int)$id_order_state, $order, true);
+ $id_order_state = (int)Configuration::get('PS_OS_PARTIAL_PAYMENT');
}
+ $new_history->changeIdOrderState((int)$id_order_state, $order, true);
$new_history->addWithemail(true, $extra_vars);
// Switch to back order if needed
- if (Configuration::get('PS_STOCK_MANAGEMENT') && ($order_detail->getStockState() || $order_detail->product_quantity_in_stock <= 0)) {
+ $objHotelBookingDetail = new HotelBookingDetail();
+ if ($objHotelBookingDetail->getOverbookedRooms($order->id)) {
+ $cancelOrder = 0;
+ // Take overbooking action as per order->overbooking Preferences else set order for cancellation
+ if (Configuration::get('PS_OVERBOOKING_ORDER_ACTION') == Order::OVERBOOKING_ORDER_CANCEL_ACTION) {
+ $cancelOrder = 1;
+ } else {
+ // check conditions for maximun overbookings allowed for the hotel else set order for cancellation
+ $maxAllowedOverbookings = Configuration::get('PS_MAX_OVERBOOKING_PER_HOTEL_PER_DAY');
+ // >= condition applied because equal case means already overbooked rooms limit exceeded before this booking
+ if ($maxAllowedOverbookings && ($maxOverbookingCount >= $maxAllowedOverbookings)) {
+ $cancelOrder = 1;
+ }
+ }
+
+ // set order status after all conditions checks
+ if ($cancelOrder) {
+ $id_order_state = Configuration::get('PS_OS_CANCELED');
+ } else {
+ if ($order->valid) {
+ if ($order->is_advance_payment && $order->advance_paid_amount < $order->total_paid_tax_incl) {
+ $id_order_state = Configuration::get('PS_OS_OVERBOOKING_PARTIAL_PAID');
+ } else {
+ $id_order_state = Configuration::get('PS_OS_OVERBOOKING_PAID');
+ }
+ } else {
+ $id_order_state = Configuration::get('PS_OS_OVERBOOKING_UNPAID');
+ }
+ }
+
$history = new OrderHistory();
$history->id_order = (int)$order->id;
- $history->changeIdOrderState(Configuration::get($order->valid ? 'PS_OS_OUTOFSTOCK_PAID' : 'PS_OS_OUTOFSTOCK_UNPAID'), $order, true);
+ $history->changeIdOrderState($id_order_state, $order, true);
$history->addWithemail();
}
@@ -1190,8 +1275,21 @@ abstract class PaymentModuleCore extends Module
PrestaShopLogger::addLog('PaymentModule::validateOrder - Mail is about to be sent', 1, null, 'Cart', (int)$id_cart, true);
}
- // Send order confirmation mails to the reciepients according to the order mail configuration
+ $orderStatusObj = new OrderState((int)$id_order_state, (int)$this->context->language->id);
+ $data['{order_status}'] = $orderStatusObj->name;
+ $data['{order_status_color}'] = $orderStatusObj->color;
+ // Send order confirmation/overbooking mails to the reciepients according to the order mail configuration
+ $overBookingStates = OrderState::getOverBookingStates();
+ $isOverBookingStatus = in_array($id_order_state, $overBookingStates);
if (Configuration::get('PS_ORDER_CONF_MAIL_TO_CUSTOMER')){
+ // If order currenct state is overbooking, the send overbooking email or send order confirmation email
+ if ($isOverBookingStatus) {
+ $subject = Mail::l('Order Not Confirmed', (int)$order->id_lang);
+ $template = 'overbooking';
+ } else {
+ $subject = Mail::l('Order confirmation', (int)$order->id_lang);
+ $template = 'order_conf';
+ }
if (Validate::isEmail($this->context->customer->email)) {
// send customer information
$data['{firstname}'] = $this->context->customer->firstname;
@@ -1199,8 +1297,8 @@ abstract class PaymentModuleCore extends Module
$data['{email}'] = $this->context->customer->email;
Mail::Send(
(int)$order->id_lang,
- 'order_conf',
- Mail::l('Order confirmation', (int)$order->id_lang),
+ $template,
+ $subject,
$data,
$this->context->customer->email,
$this->context->customer->firstname.' '.$this->context->customer->lastname,
@@ -1221,8 +1319,8 @@ abstract class PaymentModuleCore extends Module
$data['{email}'] = $objOrderCustomerGuestDetail->email;
Mail::Send(
(int)$order->id_lang,
- 'order_conf',
- Mail::l('Order confirmation', (int)$order->id_lang),
+ $template,
+ $subject,
$data,
$objOrderCustomerGuestDetail->email,
$objOrderCustomerGuestDetail->firstname.' '.$objOrderCustomerGuestDetail->lastname,
@@ -1239,6 +1337,15 @@ abstract class PaymentModuleCore extends Module
// send superadmin information
if (Validate::isLoadedObject($superAdmin = new Employee(_PS_ADMIN_PROFILE_))) {
if (Validate::isEmail($superAdmin->email)) {
+ // If order currenct state is overbooking, the send overbooking email or send order confirmation email
+ if ($isOverBookingStatus) {
+ $subject = Mail::l('Order Not Confirmed', (int)$order->id_lang);
+ $template = 'overbooking_admin';
+ } else {
+ $subject = Mail::l('Order confirmation', (int)$order->id_lang);
+ $template = 'order_conf_admin';
+ }
+
$data['{customer_name}'] = $this->context->customer->firstname.' '.$this->context->customer->lastname;
$data['{customer_email}'] = $this->context->customer->email;
$data['{firstname}'] = $superAdmin->firstname;
@@ -1246,8 +1353,8 @@ abstract class PaymentModuleCore extends Module
$data['{email}'] = $superAdmin->email;
Mail::Send(
(int)$order->id_lang,
- 'order_conf_admin',
- Mail::l('Order confirmation', (int)$order->id_lang),
+ $template,
+ $subject,
$data,
$superAdmin->email,
$superAdmin->firstname.' '.$superAdmin->lastname,
@@ -1263,6 +1370,14 @@ abstract class PaymentModuleCore extends Module
&& Validate::isLoadedObject($objHotel = new HotelBranchInformation($idHotel))
) {
if (Configuration::get('PS_ORDER_CONF_MAIL_TO_HOTEL_MANAGER')){
+ // If order currenct state is overbooking, the send overbooking email or send order confirmation email
+ if ($isOverBookingStatus) {
+ $subject = Mail::l('Order Not Confirmed', (int)$order->id_lang);
+ $template = 'overbooking_admin';
+ } else {
+ $subject = Mail::l('Order confirmation', (int)$order->id_lang);
+ $template = 'order_conf_admin';
+ }
// send hotel information
$data['{firstname}'] = '';
$data['{lastname}'] = '';
@@ -1272,8 +1387,8 @@ abstract class PaymentModuleCore extends Module
if (Validate::isEmail($objHotel->email)) {
Mail::Send(
(int)$order->id_lang,
- 'order_conf_admin',
- Mail::l('Order confirmation', (int)$order->id_lang),
+ $template,
+ $subject,
$data,
$objHotel->email,
null,
@@ -1288,6 +1403,16 @@ abstract class PaymentModuleCore extends Module
if ($htlAccesses = $objHotel->getHotelAccess($idHotel)) {
$data['{customer_name}'] = $this->context->customer->firstname.' '.$this->context->customer->lastname;
$data['{customer_email}'] = $this->context->customer->email;
+
+ // If order currenct state is overbooking, the send overbooking email or send order confirmation email
+ if ($isOverBookingStatus) {
+ $subject = Mail::l('Order Not Confirmed', (int)$order->id_lang);
+ $template = 'overbooking_admin';
+ } else {
+ $subject = Mail::l('Order confirmation', (int)$order->id_lang);
+ $template = 'order_conf_admin';
+ }
+
foreach ($htlAccesses as $access) {
if ($access['id_profile'] != _PS_ADMIN_PROFILE_) {
if ($htlEmployees = Employee::getEmployeesByProfile($access['id_profile'])) {
@@ -1299,8 +1424,8 @@ abstract class PaymentModuleCore extends Module
$data['{email}'] = $empl['email'];
Mail::Send(
(int)$order->id_lang,
- 'order_conf_admin',
- Mail::l('Order confirmation', (int)$order->id_lang),
+ $template,
+ $subject,
$data,
$empl['email'],
$empl['firstname'].' '.$empl['lastname'],
@@ -1318,7 +1443,6 @@ abstract class PaymentModuleCore extends Module
}
}
}
-
// updates stock in shops
if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')) {
$product_list = $order->getProducts();
diff --git a/classes/order/Order.php b/classes/order/Order.php
index 79ba75e60..eef2498c0 100644
--- a/classes/order/Order.php
+++ b/classes/order/Order.php
@@ -34,6 +34,10 @@ class OrderCore extends ObjectModel
const ORDER_PAYMENT_TYPE_FULL = 1;
const ORDER_PAYMENT_TYPE_ADVANCE = 2;
+ // actions when overbooking will be created
+ const OVERBOOKING_ORDER_CANCEL_ACTION = 1;
+ const OVERBOOKING_ORDER_NO_ACTION = 2;
+
/** @var int Delivery address id */
public $id_address_delivery;
diff --git a/classes/order/OrderState.php b/classes/order/OrderState.php
index 22e3d8db4..cd14adbf3 100644
--- a/classes/order/OrderState.php
+++ b/classes/order/OrderState.php
@@ -155,4 +155,13 @@ class OrderStateCore extends ObjectModel
{
return !($this->unremovable);
}
+
+ public static function getOverBookingStates()
+ {
+ return array(
+ Configuration::get('PS_OS_OVERBOOKING_PARTIAL_PAID'),
+ Configuration::get('PS_OS_OVERBOOKING_PAID'),
+ Configuration::get('PS_OS_OVERBOOKING_UNPAID'),
+ );
+ }
}
diff --git a/controllers/admin/AdminOrderPreferencesController.php b/controllers/admin/AdminOrderPreferencesController.php
index 21b31f6a7..78ae5fd9e 100644
--- a/controllers/admin/AdminOrderPreferencesController.php
+++ b/controllers/admin/AdminOrderPreferencesController.php
@@ -58,6 +58,18 @@ class AdminOrderPreferencesControllerCore extends AdminController
)
);
+ // actions when overbooking will be created
+ $overbookingAction = array(
+ array(
+ 'value' => Order::OVERBOOKING_ORDER_CANCEL_ACTION,
+ 'name' => $this->l('Cancel the booking')
+ ),
+ array(
+ 'value' => Order::OVERBOOKING_ORDER_NO_ACTION,
+ 'name' => $this->l('Take the overbooking')
+ )
+ );
+
$this->fields_options = array(
'order_restrict' => array(
'title' => $this->l('Order Restrict'),
@@ -163,33 +175,83 @@ class AdminOrderPreferencesControllerCore extends AdminController
'submit' => array('title' => $this->l('Save'))
),
'email' => array(
- 'title' => $this->l('Email'),
+ 'title' => $this->l('Order Confirmation / Overbooking Email'),
'icon' => 'icon-cogs',
'fields' => array(
'PS_ORDER_CONF_MAIL_TO_CUSTOMER' => array(
- 'title' => $this->l('Order confirmation mail to customer'),
- 'hint' => $this->l('Enable, if you want to send order confirmation email to the customer.'),
+ 'title' => $this->l('Send email to customer'),
+ 'hint' => $this->l('Enable, if you want to send order confirmation or overbooking or overbooking email to the customer.'),
'validation' => 'isBool',
'cast' => 'intval',
'type' => 'bool'
),
'PS_ORDER_CONF_MAIL_TO_SUPERADMIN' => array(
- 'title' => $this->l('Order confirmation mail to super admin'),
- 'hint' => $this->l('Enable, if you want to send order confirmation email to the super admin.'),
+ 'title' => $this->l('Send email to super admin'),
+ 'hint' => $this->l('Enable, if you want to send order confirmation or overbooking email to the super admin.'),
'validation' => 'isBool',
'cast' => 'intval',
'type' => 'bool'
),
'PS_ORDER_CONF_MAIL_TO_HOTEL_MANAGER' => array(
- 'title' => $this->l('Order confirmation mail to hotelier'),
- 'hint' => $this->l('Enable, if you want to send order confirmation email to the hotelier. Mail will be sent to the email saved while creating the hotel.'),
+ 'title' => $this->l('Send email to hotelier'),
+ 'hint' => $this->l('Enable, if you want to send order confirmation or overbooking email to the hotelier. Mail will be sent to the email saved while creating the hotel.'),
'validation' => 'isBool',
'cast' => 'intval',
'type' => 'bool'
),
'PS_ORDER_CONF_MAIL_TO_EMPLOYEE' => array(
- 'title' => $this->l('Order confirmation mail to employees'),
- 'hint' => $this->l('Enable, if you want to send order confirmation email to employees having permission to manage the hotel.'),
+ 'title' => $this->l('Send email to employees'),
+ 'hint' => $this->l('Enable, if you want to send order confirmation or overbooking email to employees having permission to manage the hotel.'),
+ 'validation' => 'isBool',
+ 'cast' => 'intval',
+ 'type' => 'bool'
+ ),
+ ),
+ 'submit' => array('title' => $this->l('Save'))
+ ),
+ 'overbooking' => array(
+ 'title' => $this->l('Overbooking'),
+ 'icon' => 'icon-cogs',
+ 'fields' => array(
+ 'PS_OVERBOOKING_ORDER_ACTION' => array(
+ 'title' => $this->l('Overbooking order action'),
+ 'hint' => $this->l('Please choose the action to take when overbooking is created in any order.'),
+ 'validation' => 'isInt',
+ 'type' => 'select',
+ 'cast' => 'intval',
+ 'validation' => 'isInt',
+ 'list' => $overbookingAction,
+ 'identifier' => 'value',
+ 'js' => "changeOverbookingOrderAction()"
+ ),
+ 'PS_MAX_OVERBOOKING_PER_HOTEL_PER_DAY' => array(
+ 'title' => $this->l('Maximun hotel overbookings per date'),
+ 'hint' => $this->l('Enter the maximum number of the overbookings on any date can be created for a hotel.(Set 0 for no limit)'),
+ 'desc' => $this->l('When maximun number of the overbookings on any date in the booking duration is reached, then the new overbooking order will be cancelled.(Set 0 for no limit)'),
+ 'validation' => 'isInt',
+ 'type' => 'text',
+ 'class' => 'fixed-width-xxl',
+ 'validation' => 'isInt',
+ 'id' => 'PS_MAX_OVERBOOKING_PER_HOTEL_PER_DAY',
+ ),
+ 'OVERBOOKING_ORDER_CANCEL_ACTION' => array(
+ 'title' => $this->l('Overbooking order cancel action value'),
+ 'type' => 'hidden',
+ 'value' => Order::OVERBOOKING_ORDER_CANCEL_ACTION,
+ 'auto_value' => false,
+ ),
+ 'OVERBOOKING_ORDER_NO_ACTION' => array(
+ 'title' => $this->l('Overbooking order no action value'),
+ 'validation' => 'isInt',
+ 'cast' => 'intval',
+ 'type' => 'hidden',
+ 'value' => Order::OVERBOOKING_ORDER_NO_ACTION,
+ 'auto_value' => false
+ ),
+ 'PS_OVERBOOKING_AUTO_RESOLVE' => array(
+ 'title' => $this->l('Resolve overbooking automatically'),
+ 'hint' => $this->l('Enable, if you want to resolve overbooking automatically when rooms are available to be replaced with overbooked rooms.'),
+ 'desc' => $this->l('If enabled, the overbookings in the order will be resolved automatically when rooms are available to be replaced with all overbooked rooms in the order.'),
'validation' => 'isBool',
'cast' => 'intval',
'type' => 'bool'
diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php
index 63a271ecd..504f3d75f 100644
--- a/controllers/admin/AdminOrdersController.php
+++ b/controllers/admin/AdminOrdersController.php
@@ -251,8 +251,10 @@ class AdminOrdersControllerCore extends AdminController
$this->access_where = ' WHERE hbd.id_hotel IN ('.implode(',', $acsHtls).')';
}
-
parent::__construct();
+
+ // overbooking success status
+ $this->_conf[51] = $this->l('Overbooking is successfully resolved');
}
public static function setOrderCurrency($echo, $tr)
@@ -261,6 +263,18 @@ class AdminOrdersControllerCore extends AdminController
return Tools::displayPrice($echo, (int)$order->id_currency);
}
+ public function initContent()
+ {
+ if (!$this->display) {
+ $objHotelBookingDetail = new HotelBookingDetail();
+ if ($resolvableOverBookings = $objHotelBookingDetail->getOverbookedRooms(0, 0, '', '', 0, 0, 2)) {
+ $this->context->smarty->assign('resolvableOverBookings', $resolvableOverBookings);
+ $this->content = $this->context->smarty->fetch('controllers/orders/_resolvable_overbookings.tpl');
+ }
+ }
+ parent::initContent();
+ }
+
public function renderForm()
{
if (Context::getContext()->shop->getContext() != Shop::CONTEXT_SHOP && Shop::isFeatureActive()) {
@@ -536,33 +550,23 @@ class AdminOrdersControllerCore extends AdminController
// by webkul for 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');
+ $idOrder = Tools::getValue('id_order');
+ $idHtlBookingFrom = Tools::getValue('id_htl_booking');
+ $idRoomToReallocate = Tools::getValue('realloc_avail_rooms');
- if ($realloc_room_id == 0) {
+ if ($idRoomToReallocate == 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.');
+ if ($idHtlBookingFrom == 0) {
+ $this->errors[] = Tools::displayError('Current room information is missing.');
}
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.');
+ if ($objBookingDetail->reallocateBooking($idHtlBookingFrom, $idRoomToReallocate)) {
+ Tools::redirectAdmin(self::$currentIndex.'&id_order='.(int) $idOrder.'&vieworder&conf=4&token='.$this->token);
} else {
- Tools::redirectAdmin(self::$currentIndex.'&id_order='.(int) $order_id.'&vieworder&token='.$this->token);
+ $this->errors[] = Tools::displayError('Some error occured. Please try again.');
}
}
} else {
@@ -571,33 +575,23 @@ class AdminOrdersControllerCore extends AdminController
}
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');
+ $idOrder = Tools::getValue('id_order');
+ $idHtlBookingFrom = Tools::getValue('id_htl_booking');
+ $idHtlBookingToSwap = Tools::getValue('swap_avail_rooms');
- if ($swapped_room_id == 0) {
- $this->errors[] = Tools::displayError('Please select a room to swap with this room.');
+ if (!$idHtlBookingToSwap) {
+ $this->errors[] = Tools::displayError('Please select a room to swap with this room booking.');
}
- 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.');
+ if (!$idHtlBookingFrom) {
+ $this->errors[] = Tools::displayError('Current room information is missing.');
}
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=4&token='.$this->token);
} else {
- Tools::redirectAdmin(self::$currentIndex.'&id_order='.(int) $order_id.'&vieworder&token='.$this->token);
+ $this->errors[] = Tools::displayError('Some error occured. Please try again.');
}
}
} else {
@@ -1354,7 +1348,16 @@ class AdminOrdersControllerCore extends AdminController
} else {
$this->errors[] = Tools::displayError('You do not have permission to edit this.');
}
+ } elseif(Tools::getIsset('resolve_overbooking') && Tools::getValue('resolve_overbooking')) {
+ $objHotelBookingDetail = new HotelBookingDetail();
+ // resolve an overbooking manually
+ if ($objHotelBookingDetail->resolveOverbookings(Tools::getValue('resolve_overbooking'))) {
+ Tools::redirectAdmin(self::$currentIndex.'&id_order='.$order->id.'&vieworder&conf=51&token='.$this->token);
+ } else {
+ $this->errors = Tools::displayError('An error occurred while resolving overbooking.');
+ }
}
+
parent::postProcess();
}
@@ -1751,8 +1754,13 @@ class AdminOrdersControllerCore extends AdminController
// applicable refund policies
$applicableRefundPolicies = HotelOrderRefundRules::getApplicableRefundRules($order->id);
+
+ // Overbookings information of the order
+ $orderOverBookings = $objHotelBookingDetail->getOverbookedRooms($order->id, 0, '', '', 0, 0, 1);
+
$this->tpl_view_vars = array(
// refund info
+ 'orderOverBookings' => $orderOverBookings,
'refund_allowed' => (int) $order->isReturnable(),
'applicable_refund_policies' => $applicableRefundPolicies,
'returns' => OrderReturn::getOrdersReturn($order->id_customer, $order->id),
diff --git a/controllers/front/HistoryController.php b/controllers/front/HistoryController.php
index 397325c41..fbef91e5a 100644
--- a/controllers/front/HistoryController.php
+++ b/controllers/front/HistoryController.php
@@ -64,6 +64,7 @@ class HistoryControllerCore extends FrontController
}
$this->context->smarty->assign(array(
'orders' => $orders,
+ 'overbooking_order_states' => OrderState::getOverBookingStates(),
'invoiceAllowed' => (int)Configuration::get('PS_INVOICE'),
'reorderingAllowed' => !(bool)Configuration::get('PS_DISALLOW_HISTORY_REORDERING'),
'slowValidation' => Tools::isSubmit('slowvalidation')
diff --git a/controllers/front/OrderDetailController.php b/controllers/front/OrderDetailController.php
index 196091216..f012bb100 100644
--- a/controllers/front/OrderDetailController.php
+++ b/controllers/front/OrderDetailController.php
@@ -647,6 +647,7 @@ class OrderDetailControllerCore extends FrontController
'invoice' => (OrderState::invoiceAvailable($id_order_state) && count($order->getInvoicesCollection())),
'logable' => (bool) $order_status->logable,
'order_history' => $order->getHistory($this->context->language->id, false, true),
+ 'overbooking_order_states' => OrderState::getOverBookingStates(),
'products' => $products,
'discounts' => $order->getCartRules(),
'carrier' => $carrier,
diff --git a/install/data/img/os/Overbooking_partial_paid.gif b/install/data/img/os/Overbooking_partial_paid.gif
new file mode 100644
index 000000000..7a8f831fc
Binary files /dev/null and b/install/data/img/os/Overbooking_partial_paid.gif differ
diff --git a/install/data/xml/configuration.xml b/install/data/xml/configuration.xml
index 935de20ba..dfdb8030b 100644
--- a/install/data/xml/configuration.xml
+++ b/install/data/xml/configuration.xml
@@ -335,6 +335,12 @@
0
+
+ 1
+
+
+ 0
+
1
@@ -434,6 +440,9 @@
11
+
+ 12
+
diff --git a/install/data/xml/order_state.xml b/install/data/xml/order_state.xml
index a1f70e4ec..cc016ffcd 100644
--- a/install/data/xml/order_state.xml
+++ b/install/data/xml/order_state.xml
@@ -26,7 +26,7 @@
-
+
@@ -34,7 +34,9 @@
-
+
+
+
diff --git a/install/langs/bg/data/order_state.xml b/install/langs/bg/data/order_state.xml
index f22b1f4be..a2e1941c9 100644
--- a/install/langs/bg/data/order_state.xml
+++ b/install/langs/bg/data/order_state.xml
@@ -33,11 +33,15 @@
- Overbooking (paid)
+ Overbooking (Paid)
- Overbooking (not paid)
+ Overbooking (Not paid)
+
+
+
+ Overbooking (Partial payment)
diff --git a/install/langs/bn/data/order_state.xml b/install/langs/bn/data/order_state.xml
index e966ff68a..5b6f1b8dd 100644
--- a/install/langs/bn/data/order_state.xml
+++ b/install/langs/bn/data/order_state.xml
@@ -33,11 +33,15 @@
- Overbooking (paid)
+ Overbooking (Paid)
- Overbooking (not paid)
+ Overbooking (Not paid)
+
+
+
+ Overbooking (Partial payment)
diff --git a/install/langs/br/data/order_state.xml b/install/langs/br/data/order_state.xml
index 62d5f9206..4da0e3beb 100644
--- a/install/langs/br/data/order_state.xml
+++ b/install/langs/br/data/order_state.xml
@@ -33,11 +33,15 @@
- Overbooking (paid)
+ Overbooking (Paid)
- Overbooking (not paid)
+ Overbooking (Not paid)
+
+
+
+ Overbooking (Partial payment)
diff --git a/install/langs/cs/data/order_state.xml b/install/langs/cs/data/order_state.xml
index f14803ab3..280c54375 100644
--- a/install/langs/cs/data/order_state.xml
+++ b/install/langs/cs/data/order_state.xml
@@ -33,11 +33,15 @@
- Overbooking (paid)
+ Overbooking (Paid)
- Overbooking (not paid)
+ Overbooking (Not paid)
+
+
+
+ Overbooking (Partial payment)
diff --git a/install/langs/de/data/order_state.xml b/install/langs/de/data/order_state.xml
index 2ac2ea90b..354ffa36e 100644
--- a/install/langs/de/data/order_state.xml
+++ b/install/langs/de/data/order_state.xml
@@ -33,11 +33,15 @@
- Overbooking (paid)
+ Overbooking (Paid)
- Overbooking (not paid)
+ Overbooking (Not paid)
+
+
+
+ Overbooking (Partial payment)
diff --git a/install/langs/en/data/order_state.xml b/install/langs/en/data/order_state.xml
index f22b1f4be..a2e1941c9 100644
--- a/install/langs/en/data/order_state.xml
+++ b/install/langs/en/data/order_state.xml
@@ -33,11 +33,15 @@
- Overbooking (paid)
+ Overbooking (Paid)
- Overbooking (not paid)
+ Overbooking (Not paid)
+
+
+
+ Overbooking (Partial payment)
diff --git a/install/langs/es/data/order_state.xml b/install/langs/es/data/order_state.xml
index 4f4b7059b..647bf19a2 100644
--- a/install/langs/es/data/order_state.xml
+++ b/install/langs/es/data/order_state.xml
@@ -33,11 +33,15 @@
- Overbooking (paid)
+ Overbooking (Paid)
- Overbooking (not paid)
+ Overbooking (Not paid)
+
+
+
+ Overbooking (Partial payment)
diff --git a/install/langs/fa/data/order_state.xml b/install/langs/fa/data/order_state.xml
index 75a6f109d..5b9ef9c06 100644
--- a/install/langs/fa/data/order_state.xml
+++ b/install/langs/fa/data/order_state.xml
@@ -33,11 +33,15 @@
- Overbooking (paid)
+ Overbooking (Paid)
- Overbooking (not paid)
+ Overbooking (Not paid)
+
+
+
+ Overbooking (Partial payment)
diff --git a/install/langs/fr/data/order_state.xml b/install/langs/fr/data/order_state.xml
index 55e21df4f..c2fae473b 100644
--- a/install/langs/fr/data/order_state.xml
+++ b/install/langs/fr/data/order_state.xml
@@ -33,11 +33,15 @@
- Overbooking (paid)
+ Overbooking (Paid)
- Overbooking (not paid)
+ Overbooking (Not paid)
+
+
+
+ Overbooking (Partial payment)
diff --git a/install/langs/he/data/order_state.xml b/install/langs/he/data/order_state.xml
index 1907a4f6b..8d7478724 100644
--- a/install/langs/he/data/order_state.xml
+++ b/install/langs/he/data/order_state.xml
@@ -33,11 +33,15 @@
- Overbooking (paid)
+ Overbooking (Paid)
- Overbooking (not paid)
+ Overbooking (Not paid)
+
+
+
+ Overbooking (Partial payment)
diff --git a/install/langs/hr/data/order_state.xml b/install/langs/hr/data/order_state.xml
index f22b1f4be..a2e1941c9 100644
--- a/install/langs/hr/data/order_state.xml
+++ b/install/langs/hr/data/order_state.xml
@@ -33,11 +33,15 @@
- Overbooking (paid)
+ Overbooking (Paid)
- Overbooking (not paid)
+ Overbooking (Not paid)
+
+
+
+ Overbooking (Partial payment)
diff --git a/install/langs/hu/data/order_state.xml b/install/langs/hu/data/order_state.xml
index f22b1f4be..a2e1941c9 100644
--- a/install/langs/hu/data/order_state.xml
+++ b/install/langs/hu/data/order_state.xml
@@ -33,11 +33,15 @@
- Overbooking (paid)
+ Overbooking (Paid)
- Overbooking (not paid)
+ Overbooking (Not paid)
+
+
+
+ Overbooking (Partial payment)
diff --git a/install/langs/id/data/order_state.xml b/install/langs/id/data/order_state.xml
index 16815db43..b84b96c29 100644
--- a/install/langs/id/data/order_state.xml
+++ b/install/langs/id/data/order_state.xml
@@ -33,11 +33,15 @@
- Overbooking (paid)
+ Overbooking (Paid)
- Overbooking (not paid)
+ Overbooking (Not paid)
+
+
+
+ Overbooking (Partial payment)
diff --git a/install/langs/it/data/order_state.xml b/install/langs/it/data/order_state.xml
index 9df4e2ac4..836892bcf 100644
--- a/install/langs/it/data/order_state.xml
+++ b/install/langs/it/data/order_state.xml
@@ -33,11 +33,15 @@
- Overbooking (paid)
+ Overbooking (Paid)
- Overbooking (not paid)
+ Overbooking (Not paid)
+
+
+
+ Overbooking (Partial payment)
diff --git a/install/langs/lt/data/order_state.xml b/install/langs/lt/data/order_state.xml
index f22b1f4be..a2e1941c9 100644
--- a/install/langs/lt/data/order_state.xml
+++ b/install/langs/lt/data/order_state.xml
@@ -33,11 +33,15 @@
- Overbooking (paid)
+ Overbooking (Paid)
- Overbooking (not paid)
+ Overbooking (Not paid)
+
+
+
+ Overbooking (Partial payment)
diff --git a/install/langs/mk/data/order_state.xml b/install/langs/mk/data/order_state.xml
index f22b1f4be..a2e1941c9 100644
--- a/install/langs/mk/data/order_state.xml
+++ b/install/langs/mk/data/order_state.xml
@@ -33,11 +33,15 @@
- Overbooking (paid)
+ Overbooking (Paid)
- Overbooking (not paid)
+ Overbooking (Not paid)
+
+
+
+ Overbooking (Partial payment)
diff --git a/install/langs/nl/data/order_state.xml b/install/langs/nl/data/order_state.xml
index 0b5e4683b..22a269c32 100644
--- a/install/langs/nl/data/order_state.xml
+++ b/install/langs/nl/data/order_state.xml
@@ -33,11 +33,15 @@
- Overbooking (paid)
+ Overbooking (Paid)
- Overbooking (not paid)
+ Overbooking (Not paid)
+
+
+
+ Overbooking (Partial payment)
diff --git a/install/langs/no/data/order_state.xml b/install/langs/no/data/order_state.xml
index f22b1f4be..a2e1941c9 100644
--- a/install/langs/no/data/order_state.xml
+++ b/install/langs/no/data/order_state.xml
@@ -33,11 +33,15 @@
- Overbooking (paid)
+ Overbooking (Paid)
- Overbooking (not paid)
+ Overbooking (Not paid)
+
+
+
+ Overbooking (Partial payment)
diff --git a/install/langs/pl/data/order_state.xml b/install/langs/pl/data/order_state.xml
index f216ff27c..ccdf7db53 100644
--- a/install/langs/pl/data/order_state.xml
+++ b/install/langs/pl/data/order_state.xml
@@ -33,11 +33,15 @@
- Overbooking (paid)
+ Overbooking (Paid)
- Overbooking (not paid)
+ Overbooking (Not paid)
+
+
+
+ Overbooking (Partial payment)
diff --git a/install/langs/pt/data/order_state.xml b/install/langs/pt/data/order_state.xml
index 709c8ce76..7a1d48388 100644
--- a/install/langs/pt/data/order_state.xml
+++ b/install/langs/pt/data/order_state.xml
@@ -33,11 +33,15 @@
- Overbooking (paid)
+ Overbooking (Paid)
- Overbooking (not paid)
+ Overbooking (Not paid)
+
+
+
+ Overbooking (Partial payment)
diff --git a/install/langs/qc/data/order_state.xml b/install/langs/qc/data/order_state.xml
index 3d7c8b67b..da31c3485 100644
--- a/install/langs/qc/data/order_state.xml
+++ b/install/langs/qc/data/order_state.xml
@@ -33,11 +33,15 @@
- Overbooking (paid)
+ Overbooking (Paid)
- Overbooking (not paid)
+ Overbooking (Not paid)
+
+
+
+ Overbooking (Partial payment)
diff --git a/install/langs/ro/data/order_state.xml b/install/langs/ro/data/order_state.xml
index 14f13d0e3..e869cf86c 100644
--- a/install/langs/ro/data/order_state.xml
+++ b/install/langs/ro/data/order_state.xml
@@ -33,11 +33,15 @@
- Overbooking (paid)
+ Overbooking (Paid)
- Overbooking (not paid)
+ Overbooking (Not paid)
+
+
+
+ Overbooking (Partial payment)
diff --git a/install/langs/ru/data/order_state.xml b/install/langs/ru/data/order_state.xml
index c2bcb5ccc..da47495ec 100644
--- a/install/langs/ru/data/order_state.xml
+++ b/install/langs/ru/data/order_state.xml
@@ -33,11 +33,15 @@
- Overbooking (paid)
+ Overbooking (Paid)
- Overbooking (not paid)
+ Overbooking (Not paid)
+
+
+
+ Overbooking (Partial payment)
diff --git a/install/langs/si/data/order_state.xml b/install/langs/si/data/order_state.xml
index f22b1f4be..a2e1941c9 100644
--- a/install/langs/si/data/order_state.xml
+++ b/install/langs/si/data/order_state.xml
@@ -33,11 +33,15 @@
- Overbooking (paid)
+ Overbooking (Paid)
- Overbooking (not paid)
+ Overbooking (Not paid)
+
+
+
+ Overbooking (Partial payment)
diff --git a/install/langs/sr/data/order_state.xml b/install/langs/sr/data/order_state.xml
index f22b1f4be..a2e1941c9 100644
--- a/install/langs/sr/data/order_state.xml
+++ b/install/langs/sr/data/order_state.xml
@@ -33,11 +33,15 @@
- Overbooking (paid)
+ Overbooking (Paid)
- Overbooking (not paid)
+ Overbooking (Not paid)
+
+
+
+ Overbooking (Partial payment)
diff --git a/install/langs/sv/data/order_state.xml b/install/langs/sv/data/order_state.xml
index f22b1f4be..a2e1941c9 100644
--- a/install/langs/sv/data/order_state.xml
+++ b/install/langs/sv/data/order_state.xml
@@ -33,11 +33,15 @@
- Overbooking (paid)
+ Overbooking (Paid)
- Overbooking (not paid)
+ Overbooking (Not paid)
+
+
+
+ Overbooking (Partial payment)
diff --git a/install/langs/tw/data/order_state.xml b/install/langs/tw/data/order_state.xml
index 05008b4f9..15377737c 100644
--- a/install/langs/tw/data/order_state.xml
+++ b/install/langs/tw/data/order_state.xml
@@ -33,11 +33,15 @@
- Overbooking (paid)
+ Overbooking (Paid)
- Overbooking (not paid)
+ Overbooking (Not paid)
+
+
+
+ Overbooking (Partial payment)
diff --git a/install/langs/vn/data/order_state.xml b/install/langs/vn/data/order_state.xml
index f2d195131..f348fb702 100644
--- a/install/langs/vn/data/order_state.xml
+++ b/install/langs/vn/data/order_state.xml
@@ -33,11 +33,15 @@
- Overbooking (paid)
+ Overbooking (Paid)
- Overbooking (not paid)
+ Overbooking (Not paid)
+
+
+
+ Overbooking (Partial payment)
diff --git a/install/langs/zh/data/order_state.xml b/install/langs/zh/data/order_state.xml
index f22b1f4be..a2e1941c9 100644
--- a/install/langs/zh/data/order_state.xml
+++ b/install/langs/zh/data/order_state.xml
@@ -33,11 +33,15 @@
- Overbooking (paid)
+ Overbooking (Paid)
- Overbooking (not paid)
+ Overbooking (Not paid)
+
+
+
+ Overbooking (Partial payment)
diff --git a/js/admin.js b/js/admin.js
index 4d474721a..561130ad9 100644
--- a/js/admin.js
+++ b/js/admin.js
@@ -504,6 +504,14 @@ function changeCMSActivationAuthorization()
getE('PS_CONDITIONS_CMS_ID').disabled = 'disabled';
}
+function changeOverbookingOrderAction()
+{
+ if (getE('PS_OVERBOOKING_ORDER_ACTION').value == $("input[name='OVERBOOKING_ORDER_CANCEL_ACTION']").val())
+ $('#PS_MAX_OVERBOOKING_PER_HOTEL_PER_DAY').closest('.form-group').hide();
+ else
+ $('#PS_MAX_OVERBOOKING_PER_HOTEL_PER_DAY').closest('.form-group').show();
+}
+
function disableZipFormat()
{
if ($('#need_zip_code_on').prop('checked') == false)
diff --git a/js/admin/orders.js b/js/admin/orders.js
index c3780bac7..4b037cd27 100644
--- a/js/admin/orders.js
+++ b/js/admin/orders.js
@@ -1800,6 +1800,11 @@ $(document).on('click', '#booking-documents-modal .documents-list .btn-delete-do
}
});
+$(document).on('click', '.reallocate_overbooking', function(e) {
+ e.preventDefault();
+ $('#reallocate_room_' + $(this).attr('id_htl_booking')).trigger('click');
+});
+
const BookingDocumentsModal = {
init: function(idHtlBooking, $this) {
BookingDocumentsModal.currentTr = $this;
diff --git a/mails/en/overbooking.html b/mails/en/overbooking.html
new file mode 100755
index 000000000..4fc0e43c6
--- /dev/null
+++ b/mails/en/overbooking.html
@@ -0,0 +1,381 @@
+
+
+
+
+
+ Message from {shop_name}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Hi {firstname} {lastname},
+ Thank you for selecting our hotel!
+ Bookings in this order are Not Confirmed yet !!
+ We are sorry for your inconvenience. Please contact hotel to get final confirmation for your bookings.
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Order details
+
+ Order: {order_name} Placed on {date}
+ Payment: {payment}
+ Status: {order_status}
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Room Image
+ Room Description
+ Hotel
+ Room Capcity
+ Unit Price
+ Rooms Qty
+ Check-in Date
+ Check-out Date
+ Total
+
+
+
+
+ {cart_booking_data_html}
+
+
+
+
+
+
+
+
+
+ {extra_demands_details_html}
+
+
+
+
+
+
+
+
+ {discounts}
+
+
+
+
+
+
+
+
+
+ Total Rooms Cost
+
+
+
+
+
+
+
+
+
+
+
+
+ {room_price_tax_excl}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Extra Services Cost
+
+
+
+
+
+
+
+
+
+
+
+
+ {additional_service_price_tax_excl}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Discounts
+
+
+
+
+
+
+
+
+
+
+
+
+ {total_discounts}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Total Convenience Fees
+
+
+
+
+
+
+
+
+
+
+
+
+ {total_convenience_fee_te}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Total Tax
+
+
+
+
+
+
+
+
+
+
+
+
+ {total_tax_paid}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Final Booking Amount
+
+
+
+
+
+
+
+
+
+
+
+
+ {total_paid}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Customer address
+
+ {invoice_block_html}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ You can review your order and download your invoice from the "Order history" section of your customer account by clicking "My account" on our shop.
+
+
+
+
+
+
+
+ If you have a guest account, you can follow your order via the "Guest Tracking" section on our shop.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/mails/en/overbooking.txt b/mails/en/overbooking.txt
new file mode 100644
index 000000000..a6bd05b32
--- /dev/null
+++ b/mails/en/overbooking.txt
@@ -0,0 +1,60 @@
+Message from {shop_name}
+Hi {firstname} {lastname},
+Thank you for selecting our hotel!
+Bookings in this order are Not Confirmed yet !!
+We are sorry for your inconvenience. Please contact hotel to get final confirmation for your bookings.
+
+Order details
+Order: {order_name} Placed on {date}
+Payment: {payment}
+Status: {order_status}
+
+Room Image
+Room Description
+Hotel
+Room Capcity
+Unit Price
+Rooms Qty
+Check-in Date
+Check-out Date
+Total
+
+{cart_booking_data_text}
+
+{extra_demands_details_text}
+
+{discounts}
+
+Total Rooms Cost
+{total_products}
+
+Total Extra Services Cost
+{total_extra_demands_te}
+
+Discounts
+{total_discounts}
+
+Total Rooms Tax
+{total_tax_paid}
+
+Extra Services Tax
+{extra_demands_tax}
+
+Final Booking Amount
+{total_paid}
+
+Customer address
+{invoice_block_html}
+
+You can review your order and download your invoice from the
+"Order history" [{history_url}] section of your
+customer account by clicking "My account"
+[{my_account_url}] on our shop.
+
+If you have a guest account, you can follow your order via the
+"Guest Tracking"
+[{guest_tracking_url}?id_order={order_name}] section
+on our shop.
+
+{shop_name} [{shop_url}] powered by
+Webkul(tm) [https://webkul.com]
\ No newline at end of file
diff --git a/mails/en/overbooking_admin.html b/mails/en/overbooking_admin.html
new file mode 100755
index 000000000..505142081
--- /dev/null
+++ b/mails/en/overbooking_admin.html
@@ -0,0 +1,353 @@
+
+
+
+
+
+ Message from {shop_name}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Hi {firstname} {lastname},
+ New Bookings created on {shop_name}!
+ Bookings in this order have Overbookings !!
+ This order is not confirmed yet. Please check the order details to resolve overbookings.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Customer details
+
+ Name: {customer_name}
+ Email: {customer_email}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Order details
+
+ Order: {order_name} Placed on {date}
+ Payment: {payment}
+ Status: {order_status}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Room Image
+ Room Description
+ Hotel
+ Room Capcity
+ Unit Price
+ Rooms Qty
+ Check-in Date
+ Check-out Date
+ Total
+
+
+
+ {cart_booking_data_html}
+
+
+
+
+
+ {extra_demands_details_html}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Total Rooms Cost
+
+
+
+
+
+
+
+
+
+
+
+
+ {room_price_tax_excl}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Extra Services Cost
+
+
+
+
+
+
+
+
+
+
+
+
+ {additional_service_price_tax_excl}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Discounts
+
+
+
+
+
+
+
+
+
+
+
+
+ {total_discounts}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Total Convenience Fees
+
+
+
+
+
+
+
+
+
+
+
+
+ {total_convenience_fee_te}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Total Tax
+
+
+
+
+
+
+
+
+
+
+
+
+ {total_tax_paid}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Final Booking Amount
+
+
+
+
+
+
+
+
+
+
+
+
+ {total_paid}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/mails/en/overbooking_admin.txt b/mails/en/overbooking_admin.txt
new file mode 100644
index 000000000..a9feed298
--- /dev/null
+++ b/mails/en/overbooking_admin.txt
@@ -0,0 +1,51 @@
+Message from {shop_name}
+Hi {firstname} {lastname},
+
+New Bookings created on {shop_name}!
+Bookings in this order have Overbookings !!
+This order is not confirmed yet. Please check the order details to resolve overbookings.
+
+Customer details
+Name: {customer_name}
+Email: {customer_email}
+
+Order details
+Order: {order_name} Placed on {date}
+Payment: {payment}
+Status: {order_status}
+
+Room Image
+Room Description
+Hotel
+Room Capcity
+Unit Price
+Rooms Qty
+Check-in Date
+Check-out Date
+Total
+
+{cart_booking_data_text}
+
+{extra_demands_details_text}
+
+{discounts}
+
+Total Rooms Cost
+{total_products}
+
+Total Extra Services Cost
+{total_extra_demands_te}
+
+Discounts
+{total_discounts}
+
+Total Rooms Tax
+{total_tax_paid}
+
+Extra Services Tax
+{extra_demands_tax}
+
+Final Booking Amount
+{total_paid}
+
+{shop_name} powered by Webkul™
\ No newline at end of file
diff --git a/modules/bankwire/controllers/front/validation.php b/modules/bankwire/controllers/front/validation.php
index 5df9b7411..1eedd0a92 100644
--- a/modules/bankwire/controllers/front/validation.php
+++ b/modules/bankwire/controllers/front/validation.php
@@ -55,9 +55,8 @@ class BankwireValidationModuleFrontController extends ModuleFrontController
// Check Order restrict condition before Payment by the customer
if (Module::isInstalled('hotelreservationsystem') && Module::isEnabled('hotelreservationsystem')) {
require_once _PS_MODULE_DIR_.'hotelreservationsystem/define.php';
- $order_restrict_error = HotelOrderRestrictDate::validateOrderRestrictDateOnPayment($this);
- if ($order_restrict_error) {
- die($this->errors);
+ if (HotelOrderRestrictDate::validateOrderRestrictDateOnPayment($this)) {
+ Tools::redirect('index.php?controller=order-opc');
}
}
diff --git a/modules/cheque/controllers/front/validation.php b/modules/cheque/controllers/front/validation.php
index f280abd3f..7debcbdf2 100644
--- a/modules/cheque/controllers/front/validation.php
+++ b/modules/cheque/controllers/front/validation.php
@@ -54,9 +54,8 @@ class ChequeValidationModuleFrontController extends ModuleFrontController
/*Check Order restrict condition before Payment by the customer*/
if (Module::isInstalled('hotelreservationsystem') && Module::isEnabled('hotelreservationsystem')) {
require_once _PS_MODULE_DIR_.'hotelreservationsystem/define.php';
- $order_restrict_error = HotelOrderRestrictDate::validateOrderRestrictDateOnPayment($this);
- if ($order_restrict_error) {
- die($this->errors);
+ if (HotelOrderRestrictDate::validateOrderRestrictDateOnPayment($this)) {
+ Tools::redirect('index.php?controller=order-opc');
}
}
/*END*/
diff --git a/modules/hotelreservationsystem/classes/HotelBookingDetail.php b/modules/hotelreservationsystem/classes/HotelBookingDetail.php
index 8f2b3ad49..518b780a8 100644
--- a/modules/hotelreservationsystem/classes/HotelBookingDetail.php
+++ b/modules/hotelreservationsystem/classes/HotelBookingDetail.php
@@ -168,6 +168,23 @@ class HotelBookingDetail extends ObjectModel
parent::__construct($id);
}
+ public function update($null_values = false)
+ {
+ $result = parent::update($null_values);
+
+ // if automatic overbooking resolution is enabled
+ if (Configuration::get('PS_OVERBOOKING_AUTO_RESOLVE')) {
+ // if room is getting free and this room is not already in back order then resolve the overbookings for this free room
+ // $this->is_cancelled == 1 is not checked because currently we always set is_refunded to 1 when room is free
+ // $this->is_back_order == 0 is checked because $this->is_back_order == 1 is used as room is free
+ if ($this->is_refunded == 1 && $this->is_back_order == 0) {
+ $this->resolveOverBookings();
+ }
+ }
+
+ return $result;
+ }
+
public function getBookingDataParams($params)
{
if (!isset($params['id_room_type'])) {
@@ -1671,74 +1688,97 @@ class HotelBookingDetail extends ObjectModel
*/
public function getAvailableRoomsForSwapping($date_from, $date_to, $id_room_type, $hotel_id, $id_room)
{
- $sql = 'SELECT `id` AS `id_room`, `id_product`, `id_hotel`, `room_num`, `comment` AS `room_comment`
- FROM `'._DB_PREFIX_.'htl_room_information`
- WHERE `id_hotel`='.(int)$hotel_id.' AND `id_product`='.(int)$id_room_type.'
- AND (id_status = '. HotelRoomInformation::STATUS_ACTIVE .' or id_status = '. HotelRoomInformation::STATUS_TEMPORARY_INACTIVE .')
- AND `id` IN (
- SELECT `id_room` FROM `'._DB_PREFIX_.'htl_booking_detail`
- WHERE `date_from` = \''.pSQL($date_from).'\' AND `date_to` = \''.pSQL($date_to).'\'
- AND `id_room`!='.(int)$id_room.' AND `is_refunded`=0 AND `is_back_order`=0
- )';
+ $sql = 'SELECT `id` as `id_hotel_booking`, `id_room`, `id_product`, `id_hotel`, `room_num`, `comment` AS `room_comment`
+ FROM `'._DB_PREFIX_.'htl_booking_detail`
+ WHERE `id_hotel` = '.(int)$hotel_id.' AND `id_product` = '.(int)$id_room_type.'
+ AND `date_from` = \''.pSQL($date_from).'\' AND `date_to` = \''.pSQL($date_to).'\'
+ AND `id_room`!='.(int)$id_room.' AND `is_refunded` = 0 AND `is_back_order` = 0';
return Db::getInstance()->executeS($sql);
}
/**
+ * @deprecated : use reallocateBooking() instead
* [reallocateRoomWithAvailableSameRoomType :: To reallocate rooms with available rooms in case of reallocation of the room].
- * @param [int] $current_room_id [Id of the room to be reallocated]
- * @param [date] $date_from [start date of the booking of the room]
- * @param [date] $date_to [end date of the booking of the room]
- * @param [date] $swapped_room_id [Id of the room with which the $current_room_id will be reallocated]
- *
+ * @param [int] $currentRoomId [id of the room to be reallocated]
+ * @param [date] $dateFrom [start date of the booking of the room]
+ * @param [date] $dateTo [end date of the booking of the room]
+ * @param [date] $swappedRoomId [id of the room with which the $current_room_id will be reallocated]
+ * @param [int] $idOrder [id of the order]
* @return [boolean] [true if rooms successfully reallocated else returns false]
*/
- public function reallocateRoomWithAvailableSameRoomType($currentRoomId, $dateFrom, $dateTo, $swappedRoomId)
+ public function reallocateRoomWithAvailableSameRoomType($currentRoomId, $dateFrom, $dateTo, $swappedRoomId, $idOrder = 0)
{
+ $result = false;
+
$dateFrom = date('Y-m-d H:i:s', strtotime($dateFrom));
$dateTo = date('Y-m-d H:i:s', strtotime($dateTo));
- $idHotelCartBookingData = Db::getInstance()->getValue(
- 'SELECT `id`
- FROM `'._DB_PREFIX_.'htl_cart_booking_data`
- WHERE date_from = "'.pSQL($dateFrom).'" AND date_to = "'.pSQL($dateTo).'"
- AND id_room = '.(int) $currentRoomId
- );
-
- if ($idHotelCartBookingData) {
- $objHotelCartBookingData = new HotelCartBookingData($idHotelCartBookingData);
- if (Validate::isLoadedObject($objHotelCartBookingData)) {
- $objHotelCartBookingData->id_room = $swappedRoomId;
- if ($objHotelCartBookingData->save()) {
- $objHotelRoomInformation = new HotelRoomInformation($swappedRoomId);
-
- $roomBookingData = $this->getRoomBookingData($currentRoomId, $objHotelCartBookingData->id_order, $dateFrom, $dateTo);
- $objHotelBookingDetail = new self($roomBookingData['id']);
- if (Validate::isLoadedObject($objHotelBookingDetail)) {
- $objHotelBookingDetail->id_room = $swappedRoomId;
- $objHotelBookingDetail->room_num = $objHotelRoomInformation->room_num;
- if ($objHotelBookingDetail->save()) {
- Hook::exec(
- 'actionRoomReAllocateAfter',
- array(
- 'room_id' => $currentRoomId,
- 'realloc_room_id' => $swappedRoomId,
- 'date_from' => $dateFrom,
- 'date_to' => $dateTo,
- )
- );
-
- return true;
- }
- }
- }
- }
+ if ($idHotelBooking = Db::getInstance()->getValue(
+ 'SELECT `id` FROM `'._DB_PREFIX_.'htl_booking_detail`
+ WHERE date_from = \''.pSQL($dateFrom).'\'
+ AND date_to = \''.pSQL($dateTo).'\'
+ AND id_room = '.(int) $currentRoomId.
+ ((int) $idOrder ? ' AND id_order = '.(int) $idOrder : '')
+ )) {
+ $result = $this->reallocateBooking($idHotelBooking, $swappedRoomId);
}
- return false;
+ return $result;
}
/**
+ * Reallocate the room in the booking with the available sent room
+ * @param [int] $idHotelBooking : id of the hotel booking which room has to be reallocated
+ * @param [int] $idRoom : id of the room which has to assigned in reallocation
+ * @return boolean
+ */
+ public function reallocateBooking($idHotelBooking, $idRoom)
+ {
+ $result = true;
+ // get the cart booking data for the given booking
+ if (Validate::isLoadedObject($objHotelBooking = new HotelBookingDetail($idHotelBooking))) {
+ $objHotelCartBooking = new HotelCartBookingData();
+ if ($cartBookingInfo = $objHotelCartBooking->getRoomRowByIdProductIdRoomInDateRange(
+ $objHotelBooking->id_cart,
+ $objHotelBooking->id_product,
+ $objHotelBooking->date_from,
+ $objHotelBooking->date_to,
+ $objHotelBooking->id_room
+ )) {
+ // Reallocate the rooms in the room cart booking table
+ if (Validate::isLoadedObject($objHotelCartBooking = new HotelCartBookingData($cartBookingInfo['id']))) {
+ $objHotelCartBooking->id_room = $idRoom;
+ $result &= $objHotelCartBooking->save();
+ }
+ }
+
+ // Reallocate the rooms in the room booking table
+ $objHotelRoomInfo = new HotelRoomInformation($idRoom);
+ $objHotelBooking->id_room = $idRoom;
+ $objHotelBooking->room_num = $objHotelRoomInfo->room_num;
+ // set backorder to 0 as available reallocate rooms will always be free
+ $objHotelBooking->is_back_order = 0;
+ $result &= $objHotelBooking->save();
+
+ if ($result) {
+ Hook::exec(
+ 'actionRoomReallocateAfter',
+ array(
+ 'id_htl_booking' => $idHotelBooking,
+ 'id_room' => $idRoom
+ )
+ );
+ }
+ } else {
+ $result = false;
+ }
+
+ return $result;
+ }
+
+ /**
+ * @deprecated : use swapBooking() instead
* [swapRoomWithAvailableSameRoomType :: To swap rooms with available rooms in case of reallocation of the room].
* @param [int] $current_room_id [Id of the room to be swapped]
* @param [date] $date_from [start date of the booking of the room]
@@ -1747,70 +1787,107 @@ class HotelBookingDetail extends ObjectModel
*
* @return [boolean] [true if rooms successfully swapped else returns false]
*/
- public function swapRoomWithAvailableSameRoomType($currentRoomId, $dateFrom, $dateTo, $swappedRoomId)
+ public function swapRoomWithAvailableSameRoomType($idRoomFrom, $dateFrom, $dateTo, $idRoomTo, $idOrderFrom = 0, $idOrderTo = 0)
{
+ $result = false;
+
$dateFrom = date('Y-m-d H:i:s', strtotime($dateFrom));
$dateTo = date('Y-m-d H:i:s', strtotime($dateTo));
- $idHotelCartBookingData1 = Db::getInstance()->getValue(
- 'SELECT `id` FROM `'._DB_PREFIX_.'htl_cart_booking_data` WHERE `is_refunded` = 0
- AND `date_from`=\''.pSQL($dateFrom).'\' AND `date_to`=\''.pSQL($dateTo).'\'
- AND `id_room`='.(int)$swappedRoomId
- );
- $idHotelCartBookingData2 = Db::getInstance()->getValue(
- 'SELECT `id` FROM `'._DB_PREFIX_.'htl_cart_booking_data` WHERE `is_refunded` = 0
- AND `date_from`=\''.pSQL($dateFrom).'\' AND `date_to`=\''.pSQL($dateTo).'\'
- AND `id_room`='.(int)$currentRoomId
- );
-
- $idHotelBookingDetail1 = Db::getInstance()->getValue(
+ // Get the booking details for the given rooms as per given parameters
+ $idHotelBookingFrom = Db::getInstance()->getValue(
'SELECT `id` FROM `'._DB_PREFIX_.'htl_booking_detail` WHERE `is_refunded` = 0
- AND `date_from`=\''.pSQL($dateFrom).'\' AND `date_to`=\''.pSQL($dateTo).'\'
- AND `id_room`='.(int)$swappedRoomId
+ AND `date_from`=\''.pSQL($dateFrom).'\'
+ AND `date_to`=\''.pSQL($dateTo).'\'
+ AND `id_room`='.(int)$idRoomFrom.
+ ((int) $idOrderFrom ? ' AND id_order = '.(int) $idOrderFrom : '')
);
- $idHotelBookingDetail2 = Db::getInstance()->getValue(
+
+ $idHotelBookingTo = Db::getInstance()->getValue(
'SELECT `id` FROM `'._DB_PREFIX_.'htl_booking_detail` WHERE `is_refunded` = 0
- AND `date_from`=\''.pSQL($dateFrom).'\' AND `date_to`=\''.pSQL($dateTo).'\'
- AND `id_room`='.(int)$currentRoomId
+ AND `date_from`=\''.pSQL($dateFrom).'\'
+ AND `date_to`=\''.pSQL($dateTo).'\'
+ AND `id_room`='.(int)$idRoomTo.
+ ((int) $idOrderTo ? ' AND id_order = '.(int) $idOrderTo : '')
);
- $objHotelCartBookingData1 = new HotelCartBookingData($idHotelCartBookingData1);
- $objHotelCartBookingData2 = new HotelCartBookingData($idHotelCartBookingData2);
-
- $temp = $objHotelCartBookingData1->id_room;
- $objHotelCartBookingData1->id_room = $objHotelCartBookingData2->id_room;
- $objHotelCartBookingData2->id_room = $temp;
-
- $objHotelBookingDetail1 = new HotelBookingDetail($idHotelBookingDetail1);
- $objHotelBookingDetail2 = new HotelBookingDetail($idHotelBookingDetail2);
-
- $temp = $objHotelBookingDetail1->id_room;
- $objHotelBookingDetail1->id_room = $objHotelBookingDetail2->id_room;
- $objHotelBookingDetail2->id_room = $temp;
-
- $temp = $objHotelBookingDetail1->room_num;
- $objHotelBookingDetail1->room_num = $objHotelBookingDetail2->room_num;
- $objHotelBookingDetail2->room_num = $temp;
-
- if ($objHotelCartBookingData1->save()
- && $objHotelCartBookingData2->save()
- && $objHotelBookingDetail1->save()
- && $objHotelBookingDetail2->save()
- ) {
- Hook::exec(
- 'actionRoomSwapAfter',
- array(
- 'room_id' => $currentRoomId,
- 'swapped_room_id' => $swappedRoomId,
- 'date_from' => $dateFrom,
- 'date_to' => $dateTo,
- )
- );
-
- return true;
+ if ($idHotelBookingFrom && $idHotelBookingTo) {
+ $result = $this->swapBooking($idHotelBookingFrom, $idHotelBookingTo);
}
- return false;
+ return $result;
+ }
+
+ public function swapBooking($idHotelBookingFrom, $idHotelBookingTo)
+ {
+ $result = true;
+ // get the cart booking data for the given booking
+ if (Validate::isLoadedObject($objHotelBookingFrom = new HotelBookingDetail($idHotelBookingFrom))
+ && Validate::isLoadedObject($objHotelBookingTo = new HotelBookingDetail($idHotelBookingTo))
+ ) {
+ // Swap the rooms in the room cart booking table
+ $objHotelCartBooking = new HotelCartBookingData();
+ $cartBookingInfoFrom = $objHotelCartBooking->getRoomRowByIdProductIdRoomInDateRange(
+ $objHotelBookingFrom->id_cart,
+ $objHotelBookingFrom->id_product,
+ $objHotelBookingFrom->date_from,
+ $objHotelBookingFrom->date_to,
+ $objHotelBookingFrom->id_room
+ );
+ $cartBookingInfoTo = $objHotelCartBooking->getRoomRowByIdProductIdRoomInDateRange(
+ $objHotelBookingTo->id_cart,
+ $objHotelBookingTo->id_product,
+ $objHotelBookingTo->date_from,
+ $objHotelBookingTo->date_to,
+ $objHotelBookingTo->id_room
+ );
+
+ if ($cartBookingInfoFrom && $cartBookingInfoTo) {
+ if (Validate::isLoadedObject($objHotelCartBookingFrom = new HotelCartBookingData($cartBookingInfoFrom['id']))
+ && Validate::isLoadedObject($objHotelCartBookingTo = new HotelCartBookingData($cartBookingInfoTo['id']))
+ ) {
+ $objHotelCartBookingFrom->id_room = $objHotelCartBookingTo->id_room;
+ $objHotelCartBookingTo->id_room = $objHotelCartBookingFrom->id_room;
+ $result &= $objHotelCartBookingFrom->save();
+ $result &= $objHotelCartBookingTo->save();
+ }
+ }
+
+ // Swap the rooms in the room booking table
+ // also transfer the backorder status of the room from which room is being swapped
+ $idRoomFrom = $objHotelBookingFrom->id_room;
+ $roomNumFrom = $objHotelBookingFrom->room_num;
+ $roomFromBackOrder = $objHotelBookingFrom->is_back_order;
+
+ $idRoomTo = $objHotelBookingTo->id_room;
+ $roomNumTo = $objHotelBookingTo->room_num;
+ $roomToBackOrder = $objHotelBookingTo->is_back_order;
+
+ $objHotelBookingFrom->id_room = $idRoomTo;
+ $objHotelBookingFrom->room_num = $roomNumTo;
+ $objHotelBookingFrom->is_back_order = $roomToBackOrder;
+
+ $objHotelBookingTo->id_room = $idRoomFrom;
+ $objHotelBookingTo->room_num = $roomNumFrom;
+ $objHotelBookingTo->is_back_order = $roomFromBackOrder;
+
+ $result &= $objHotelBookingFrom->save();
+ $result &= $objHotelBookingTo->save();
+
+ if ($result) {
+ Hook::exec(
+ 'actionRoomSwapAfter',
+ array(
+ 'id_htl_booking_from' => $idHotelBookingFrom,
+ 'id_htl_booking_to' => $idHotelBookingTo
+ )
+ );
+ }
+ } else {
+ $result = false;
+ }
+
+ return $result;
}
/**
@@ -1826,6 +1903,7 @@ class HotelBookingDetail extends ObjectModel
{
$table = 'htl_booking_detail';
$data = array('is_refunded' => (int) $is_refunded);
+
if ($id_rooms) {
foreach ($id_rooms as $key_rm => $val_rm) {
$where = 'id_order='.(int)$id_order.' AND id_room = '.(int)$val_rm['id_room'].' AND `date_from`= \''.
@@ -1833,8 +1911,15 @@ class HotelBookingDetail extends ObjectModel
$result = Db::getInstance()->update($table, $data, $where);
}
} else {
- return Db::getInstance()->update($table, $data, 'id_order='.(int)$id_order);
+ $result = Db::getInstance()->update($table, $data, 'id_order='.(int)$id_order);
}
+
+ // if automatic overbooking resolution is enabled
+ if ($result && Configuration::get('PS_OVERBOOKING_AUTO_RESOLVE') && $is_refunded) {
+ // if room is getting free and this room is not already in back order then resolve the overbookings for this free room
+ $this->resolveOverBookings();
+ }
+
return $result;
}
@@ -2703,4 +2788,189 @@ class HotelBookingDetail extends ObjectModel
Configuration::get('PS_OS_ERROR'),
));
}
-}
\ No newline at end of file
+
+ /**
+ * Get overbooked rooms in the order|hotel
+ * @param [int] $idOrder : id of the order
+ * @param [int] $idHotel : id of the hotel
+ * @param [string] $dateFrom
+ * @param [string] $dateTo
+ * @param [int] $datewiseBreakup : send 1 to get overbooked rooms in datewise breakup
+ * @param [int] $roomCount : send 1 to get the count of the rooms overbooked only
+ * @param [int] $bookedRoomFlag : send 0 for no action | send 1 to get booked room info | send 2 to get overbooked rooms which are free
+ *
+ * @return array | integer : array of overbooked rooms | count of overbooked rooms
+ */
+ public function getOverbookedRooms(
+ $idOrder = 0,
+ $idHotel = 0,
+ $dateFrom = '',
+ $dateTo = '',
+ $datewiseBreakup = 0,
+ $roomCount = 0,
+ $bookedRoomInfoFlag = 0
+ ) {
+ $result = array();
+
+ $sql = 'SELECT';
+ if ($roomCount) {
+ $sql .= ' COUNT(*)';
+ } else {
+ $sql .= ' *';
+ }
+
+ $sql .= ' FROM `'._DB_PREFIX_.'htl_booking_detail` WHERE `is_back_order` = 1 AND `is_refunded` = 0 AND `is_cancelled` = 0';
+
+ if ($idOrder) {
+ $sql .= ' AND `id_order` = '.(int) $idOrder;
+ }
+ if ($idHotel) {
+ $sql .= ' AND `id_hotel` = '.(int) $idHotel;
+ }
+
+ if ($datewiseBreakup && $dateFrom && $dateTo) {
+ for ($currentDate = $dateFrom; $currentDate < $dateTo; $currentDate = date('Y-m-d', strtotime('+1 day', strtotime($currentDate)))) {
+ $dateSql = $sql . ' AND `date_from` <= \''.pSQL($currentDate).'\' AND `date_to` > \''.pSQL($currentDate).'\'';
+
+ if ($roomCount) {
+ $result[$currentDate] = Db::getInstance()->getValue($dateSql);
+ } else {
+ $result[$currentDate] = Db::getInstance()->executeS($dateSql);
+ }
+ }
+ } else {
+ if ($dateFrom && $dateTo) {
+ $sql .= ' AND `date_from` < \''.pSQL($dateTo).'\' AND `date_to` > \''.pSQL($dateFrom).'\'';
+ }
+
+ if ($roomCount) {
+ $result = Db::getInstance()->getValue($sql);
+ } else {
+ $result = Db::getInstance()->executeS($sql);
+ }
+ }
+
+ if ($bookedRoomInfoFlag && !$roomCount && $result) {
+ $link = new Link();
+ foreach ($result as $key => $bookingInfo) {
+ $result[$key]['booked_room_info'] = $this->chechRoomBooked($bookingInfo['id_room'], $bookingInfo['date_from'], $bookingInfo['date_to']);
+ $result[$key]['orders_filter_link'] = $link->getAdminLink('AdminOrders');
+
+ // if need only rooms which are available to resolve overbooking the unset booked rooms
+ if ($bookedRoomInfoFlag == 2 && $result[$key]['booked_room_info']) {
+ unset($result[$key]);
+ }
+ }
+ }
+
+ return $result;
+ }
+
+ /**
+ * Get all the orders which are in overbooking
+ * @param integer $onlyFutureDates : for orders which bookings dates are in future
+ * @return array
+ */
+ public function getOverBookedOrders($onlyFutureDates = 0)
+ {
+ $sql = 'SELECT DISTINCT `id_order` FROM `'._DB_PREFIX_.'htl_booking_detail` WHERE `is_back_order` = 1 AND `is_refunded` = 0 AND `is_cancelled` = 0';
+
+ if ($onlyFutureDates) {
+ $sql .= ' AND `date_to` > \''.pSQL(date('Y-m-d')).'\'';
+ }
+ $sql .= ' ORDER BY `id_order` ASC';
+
+ $result = Db::getInstance()->executeS($sql);
+
+ return array_column($result, 'id_order');
+ }
+
+ // Resolve overbookings by checking current available rooms
+ // Overbookings resolution will only be done if all overbookings are getting resolved in the order
+ public function resolveOverBookings($idHotelBooking = 0)
+ {
+ $result = false;
+
+ $overBookedOrders = array();
+ if ($idHotelBooking) {
+ if (Validate::isLoadedObject($objHtlBookingDetail = new HotelBookingDetail($idHotelBooking))) {
+ $overBookedOrders = array($objHtlBookingDetail->id_order);
+ }
+ } else {
+ $overBookedOrders = $this->getOverBookedOrders(1);
+ }
+
+ if ($overBookedOrders) {
+ foreach ($overBookedOrders as $idOrder) {
+ // get all overbooked rooms in the order so that we can decide status of the order after overbooking resolved
+ $overBookedRooms = $this->getOverbookedRooms($idOrder);
+ $totalOverBookedInOrder = count($overBookedRooms);
+
+ // if request for specific booking resolve
+ if ($idHotelBooking) {
+ $overBookedRooms = array((array)($objHtlBookingDetail));
+ }
+
+ if ($overBookedRooms) {
+ $resolvableOverbookings = array();
+ foreach($overBookedRooms as $roomBooking) {
+ $params = array(
+ 'idHotel' => $roomBooking['id_hotel'],
+ 'dateFrom' => $roomBooking['date_from'],
+ 'dateTo' => $roomBooking['date_to'],
+ 'idRoomType' => $roomBooking['id_product'],
+ 'searchOccupancy' => 0,
+ 'allowedIdRoomTypes' => implode(",", array($roomBooking['id_product']))
+ );
+
+ if ($availableRooms = $this->getSearchAvailableRooms($params)) {
+ if (isset($availableRooms['availableRoomTypes']['roomTypes'][$roomBooking['id_product']]['rooms'])
+ && $availableRooms['availableRoomTypes']['roomTypes'][$roomBooking['id_product']]['rooms']
+ ) {
+ $availableRoomsInfo = $availableRooms['availableRoomTypes']['roomTypes'][$roomBooking['id_product']]['rooms'];
+ if ($roomIdsAvailable = array_column($availableRoomsInfo, 'id_room')) {
+ // If room is still there in the available rooms list then we can resolve its overbooking
+ if (in_array($roomBooking['id_room'], $roomIdsAvailable)) {
+ $resolvableOverbookings[] = $roomBooking['id'];
+ }
+ }
+ }
+ }
+ }
+
+ // if all overbooked rooms are resolved then resolve the overbooking by setting is_back_order to 0
+ if ($idHotelBooking || (count($resolvableOverbookings) == count($totalOverBookedInOrder))) {
+ foreach ($resolvableOverbookings as $idHtlBookingDtl) {
+ $objBookingDetail = new HotelBookingDetail($idHtlBookingDtl);
+ $objBookingDetail->is_back_order = 0;
+ $objBookingDetail->update();
+
+ $result = true;
+ }
+
+ // After all overbookings are resolved we can update the status of the order
+ $objOrder = new Order($idOrder);
+ $idOrderState = 0;
+ if ($objOrder->current_state == Configuration::get('PS_OS_OVERBOOKING_PAID')) {
+ $idOrderState = Configuration::get('PS_OS_PAYMENT_ACCEPTED');
+ } elseif ($objOrder->current_state == Configuration::get('PS_OS_OVERBOOKING_PARTIAL_PAID')) {
+ $idOrderState = Configuration::get('PS_OS_PARTIAL_PAYMENT_ACCEPTED');
+ } elseif ($objOrder->current_state == Configuration::get('PS_OS_OVERBOOKING_UNPAID')) {
+ $idOrderState = Configuration::get('PS_OS_AWAITING_PAYMENT');
+ }
+
+ // if we have order state to change
+ if ($idOrderState) {
+ $objOrderHistory = new OrderHistory();
+ $objOrderHistory->id_order = (int)$idOrder;
+ $objOrderHistory->changeIdOrderState((int)$idOrderState, $objOrder, true);
+ $objOrderHistory->add();
+ }
+ }
+ }
+ }
+ }
+
+ return $result;
+ }
+}
diff --git a/themes/hotel-reservation-theme/history.tpl b/themes/hotel-reservation-theme/history.tpl
index 8135b8fbc..47c3c7c92 100644
--- a/themes/hotel-reservation-theme/history.tpl
+++ b/themes/hotel-reservation-theme/history.tpl
@@ -84,7 +84,11 @@
{if isset($order.order_state)}
- {$order.order_state|escape:'html':'UTF-8'}
+ {if $order.current_state|in_array:$overbooking_order_states}
+ {l s='Order Not Confirmed'}
+ {else}
+ {$order.order_state|escape:'html':'UTF-8'}
+ {/if}
{/if}
diff --git a/themes/hotel-reservation-theme/order-detail.tpl b/themes/hotel-reservation-theme/order-detail.tpl
index e6a88a799..df55e7bfb 100644
--- a/themes/hotel-reservation-theme/order-detail.tpl
+++ b/themes/hotel-reservation-theme/order-detail.tpl
@@ -76,7 +76,15 @@
{foreach from=$order_history item=state name="orderStates"}
{dateFormat date=$state.date_add full=0}
- {$state.ostate_name|escape:'html':'UTF-8'}
+
+
+ {if $state.id_order_state|in_array:$overbooking_order_states}
+ {l s='Order Not Confirmed'}
+ {else}
+ {$state.ostate_name|escape:'html':'UTF-8'}
+ {/if}
+
+
{/foreach}