@@ -277,61 +281,69 @@
{l s='Hotel Name'}
{l s='Duration'}
{l s='Documents'}
-
{l s='Order Status'}
+
{l s='Room Status'}
{if isset($htl_booking_order_data) && $htl_booking_order_data}
{foreach from=$htl_booking_order_data item=data}
- {if !$data.is_refunded}
-
-
- {$data['room_num']}
-
-
-
- {$data['hotel_name']}
-
-
-
- {dateFormat date=$data['date_from']} - {dateFormat date=$data['date_to']}
-
-
-
-
- {l s='Documents'} {$data.num_checkin_documents}
-
-
-
-
-
-
- {/if}
+
+
+ {$data['room_num']}
+
+
+
+ {$data['hotel_name']}
+
+
+
+ {dateFormat date=$data['date_from']} - {dateFormat date=$data['date_to']}
+
+
+
+
+ {l s='Documents'} {$data.num_checkin_documents}
+
+
+
+
+
+
{/foreach}
{else}
@@ -1187,9 +1199,11 @@
{/if}
{if $can_edit}
-
-
-
+ {if $refund_allowed && !$completeRefundRequestOrCancel}
+
+
+
+ {/if}
{if !$order->hasBeenDelivered()}
{*
@@ -1206,7 +1220,7 @@
{l s='Add a new discount'}
- {if $refund_allowed && !$hasCompletelyRefunded}
+ {if $refund_allowed && !$completeRefundRequestOrCancel}
{l s='Cancel'}
@@ -1396,16 +1410,14 @@
{/if}
- {if $order->total_paid_tax_incl > $order->total_paid_real}
-
- {l s='Due Amount'}
-
-
- {displayPrice currency=$order->id_currency price=($order->total_paid_tax_incl - $order->total_paid_real)}
-
-
-
- {/if}
+
+ {l s='Due Amount'}
+
+
+ {displayPrice currency=$order->id_currency price=($order->total_paid_tax_incl - $order->total_paid_real)}
+
+
+
@@ -1631,6 +1643,7 @@
{addJsDefL name='invalid_occupancy_txt'}{l s='Invalid occupancy(adults/children) found.' js=1}{/addJsDefL}
{addJsDef max_child_age=$max_child_age|escape:'quotes':'UTF-8'}
{addJsDef max_child_in_room=$max_child_in_room|escape:'quotes':'UTF-8'}
+ {addJsDefL name='undo_cancellation_success'}{l s='Booking cancellation undo process is done successfully.' js=1}{/addJsDefL}
{/strip}
{* Apply javascript for the page *}
@@ -2119,4 +2132,4 @@
});
-{/block}
\ No newline at end of file
+{/block}
diff --git a/classes/Cart.php b/classes/Cart.php
index 9c62bc7ed..5b3711f25 100644
--- a/classes/Cart.php
+++ b/classes/Cart.php
@@ -2387,7 +2387,6 @@ public function getPackageList($flush = false)
$array[$selectedProduct['id_hotel']] = array(
'quantity' => $selectedProduct['quantity'],
'id_hotel' => $selectedProduct['id_hotel'],
- 'unit_price_tax_incl' => $selectedProduct['unit_price_tax_incl'],
'total_price_tax_excl' => $selectedProduct['total_price_tax_excl'],
'total_price_tax_incl' => $selectedProduct['total_price_tax_incl'],
);
@@ -2397,7 +2396,8 @@ public function getPackageList($flush = false)
$product['cart_quantity'] = $selectedProduct['quantity'];
$product['total'] = $selectedProduct['total_price_tax_excl'];
$product['total_wt'] = $selectedProduct['total_price_tax_incl'];
- $product['price_wt'] = $selectedProduct['unit_price_tax_incl'];
+ $product['price_wt'] = $selectedProduct['total_price_tax_incl'] / $product['cart_quantity'];
+ $product['price'] = $selectedProduct['total_price_tax_excl'] / $product['cart_quantity'];
$product['id_hotel'] = $selectedProduct['id_hotel'];
$orderPackage[$id_address][$selectedProduct['id_hotel']]['product_list'][] = $product;
if (!isset($orderPackage[$id_address][$selectedProduct['id_hotel']]['id_hotel'])) {
@@ -2431,6 +2431,7 @@ public function getPackageList($flush = false)
$unitPriceWt = $objHotelServiceProductCartDetail->getHotelProductUnitPrice($this->id, $product['id_product'], $hotelProduct['id_hotel'], true);
$serviceProduct['total'] = $unitPrice * $hotelProduct['quantity'];
$serviceProduct['total_wt'] = $unitPriceWt * $hotelProduct['quantity'];
+ $serviceProduct['price'] = $unitPrice;
$serviceProduct['price_wt'] = $unitPriceWt;
// if (!empty($hotelProducts['products'])) {
// foreach($hotelProducts['products'] as $hotelProduct) {
diff --git a/classes/PaymentModule.php b/classes/PaymentModule.php
index 9d2c23fb4..d162178b6 100644
--- a/classes/PaymentModule.php
+++ b/classes/PaymentModule.php
@@ -1008,11 +1008,9 @@ public function validateOrder($id_cart, $id_order_state, $amount_paid, $payment_
// Set the order status
$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_ACCEPTED'), $order, true);
- } else {
- $new_history->changeIdOrderState((int)$id_order_state, $order, true);
- }
+
+ $new_history->changeIdOrderState((int)$id_order_state, $order, true);
+
$new_history->addWithemail(true, $extra_vars);
// Switch to back order if needed
diff --git a/classes/order/Order.php b/classes/order/Order.php
index a2bccc454..41b364657 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;
+ const ORDER_COMPLETE_REFUND_FLAG = 1;
+ const ORDER_COMPLETE_CANCELLATION_FLAG = 2;
+ const ORDER_COMPLETE_CANCELLATION_OR_REFUND_REQUEST_FLAG = 3;
+
/** @var int Delivery address id */
public $id_address_delivery;
@@ -2602,56 +2606,58 @@ public static function getAllOrdersByCartId($id_cart)
return Db::getInstance()->executeS('SELECT * FROM '._DB_PREFIX_.'orders WHERE id_cart = '.(int)$id_cart);
}
- // Order is considered as refunded if all bookings are requested for refund and all are with refunded status
- // $refundFlag [ORDER_RETURN_STATE_FLAG_REFUNDED || ORDER_RETURN_STATE_FLAG_DENIED]
- public function hasCompletelyRefunded($refundFlag = 0)
+ /**
+ * Function to check if order has been completely refunded
+ * @param integer action: can have 3 values as below
+ * Order::ORDER_COMPLETE_REFUND_FLAG for complete refunded and
+ * Order::ORDER_COMPLETE_CANCELLATION_FLAG for completely cancelled and
+ * Order::ORDER_COMPLETE_CANCELLATION_OR_REFUND_REQUEST_FLAG for all rooms are either cancelled or requested for refunded
+ * @return boolean: true if order has been completely refunded as per requested parameters or false
+ */
+ public function hasCompletelyRefunded($action = 0)
{
$objHotelBooking = new HotelBookingdetail();
- if ($refundBookings = OrderReturn::getOrdersReturnDetail($this->id)) {
- if ($orderBookings = $objHotelBooking->getOrderCurrentDataByOrderId($this->id)) {
- if (count($refundBookings) == count($orderBookings)) {
- if ($refundFlag) {
- foreach ($refundBookings as $refundRow) {
- if (Validate::isLoadedObject(
- $objReturnState = new OrderReturnState($refundRow['state']
- ))) {
- if ($refundFlag == OrderReturnState::ORDER_RETURN_STATE_FLAG_REFUNDED
- && !$objReturnState->refunded
- ) {
- return false;
- }
- if ($refundFlag == OrderReturnState::ORDER_RETURN_STATE_FLAG_DENIED
- && !$objReturnState->denied
- ) {
- return false;
- }
- }
+ if ($orderBookings = $objHotelBooking->getOrderCurrentDataByOrderId($this->id)) {
+ // If action is Order::ORDER_COMPLETE_REFUND_FLAG (for refunded) then we will check
+ // that all rooms must be refunded and at least one booking is not cancelled
+ if ($action == Order::ORDER_COMPLETE_REFUND_FLAG) {
+ $uniqueRefundedBookings = array_unique(array_column($orderBookings, 'is_refunded'));
+ if (count($uniqueRefundedBookings) == 1 && $uniqueRefundedBookings[0] == 1) {
+ foreach ($orderBookings as $booking) {
+ if ($booking['is_cancelled'] == 0) {
+ return true;
}
}
+ }
+ // If action is Order::ORDER_COMPLETE_CANCELLATION_FLAG (for cancelled) then we will check that all rooms must be cancelled
+ } elseif ($action == Order::ORDER_COMPLETE_CANCELLATION_FLAG) {
+ $uniqueRefundedBookings = array_unique(array_column($orderBookings, 'is_cancelled'));
+ if (count($uniqueRefundedBookings) == 1 && $uniqueRefundedBookings[0] == 1) {
return true;
}
- }
- } elseif ($orderBookings = $objHotelBooking->getOrderCurrentDataByOrderId($this->id)) {
- if (count(array_unique(array_column($orderBookings, 'is_cancelled'))) === 1
- && array_unique(array_column($orderBookings, 'is_cancelled'))[0] != 0
- ) {
+ // If action is Order::ORDER_COMPLETE_CANCELLATION_OR_REFUND_REQUEST_FLAG (for cancelled and refund requests) then we will check that all rooms are either cancelled or requested for refund
+ } elseif ($action == Order::ORDER_COMPLETE_CANCELLATION_OR_REFUND_REQUEST_FLAG) {
+ foreach ($orderBookings as $booking) {
+ if (!$booking['is_refunded']) {
+ if (!OrderReturn::getOrdersReturnDetail($this->id, 0, $booking['id'])) {
+ return false;
+ }
+ }
+ }
return true;
+ // Default process to check if order is fully refunded or cancelled or not
+ } else {
+ // if is_refunded is 1 means booking either is cancelled or refunded. So check all bookings must have is_refunded = 1
+ $uniqueRefundedBookings = array_unique(array_column($orderBookings, 'is_refunded'));
+ if (count($uniqueRefundedBookings) == 1 && $uniqueRefundedBookings[0] == 1) {
+ return true;
+ }
}
}
return false;
}
- // Order is considered as denied if all bookings are requested for refund and all are with denied status
- public function orderRefundHasBeenDenied()
- {
- if (OrderReturn::getOrdersReturn($this->id_customer, $this->id)) {
-
- }
-
- return false;
- }
-
public function getWsBookings()
{
return Db::getInstance()->executeS(
diff --git a/classes/order/OrderHistory.php b/classes/order/OrderHistory.php
index 49c5db350..cc933b8bb 100644
--- a/classes/order/OrderHistory.php
+++ b/classes/order/OrderHistory.php
@@ -313,7 +313,6 @@ public function changeIdOrderState($new_order_state, $id_order, $use_existing_pa
// set orders as paid
if ($new_os->paid == 1) {
- $invoices = $order->getInvoicesCollection();
if ($order->total_paid != 0) {
// if order is created by API then create a direct object instead of creating an object from module
if ($order->module == 'wsorder') {
@@ -323,22 +322,43 @@ public function changeIdOrderState($new_order_state, $id_order, $use_existing_pa
}
}
- foreach ($invoices as $invoice) {
- /** @var OrderInvoice $invoice */
- $rest_paid = $invoice->getRestPaid();
+ // if order has invoices then create payment entry for all the invoices
+ if ($invoices = $order->getInvoicesCollection()->getResults()) {
+ foreach ($invoices as $invoice) {
+ /** @var OrderInvoice $invoice */
+ $rest_paid = $invoice->getRestPaid();
+ if ($rest_paid > 0) {
+ if ($order->total_paid != 0) {
+ $payment_method = $payment_method->displayName;
+ } else {
+ $payment_method = null;
+ }
+ $order->addOrderPayment(
+ $rest_paid,
+ $payment_method,
+ null,
+ null,
+ null,
+ $invoice
+ );
+ }
+ }
+ } else {
+ $rest_paid = $order->total_paid_tax_incl - $order->total_paid_real;
if ($rest_paid > 0) {
if ($order->total_paid != 0) {
$payment_method = $payment_method->displayName;
} else {
$payment_method = null;
}
+
$order->addOrderPayment(
$rest_paid,
$payment_method,
null,
null,
null,
- $invoice
+ null
);
}
}
diff --git a/classes/order/OrderReturn.php b/classes/order/OrderReturn.php
index 36614990c..a9e653da1 100644
--- a/classes/order/OrderReturn.php
+++ b/classes/order/OrderReturn.php
@@ -158,7 +158,8 @@ public function checkEnoughProduct($order_detail_list, $product_qty_list, $custo
public function hasBeenCompleted()
{
if (Validate::isLoadedObject($objReturnState = new OrderReturnState($this->state))) {
- if ($objReturnState->denied || $objReturnState->refunded) {
+ // refund process will be considered as completed when the state is "Refunded"
+ if ($objReturnState->refunded) {
return true;
}
}
diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php
index 2cfb7a044..5a23049dd 100644
--- a/controllers/admin/AdminOrdersController.php
+++ b/controllers/admin/AdminOrdersController.php
@@ -251,7 +251,6 @@ public function __construct()
$this->access_where = ' WHERE hbd.id_hotel IN ('.implode(',', $acsHtls).')';
}
-
parent::__construct();
}
@@ -695,7 +694,79 @@ public function postProcess()
$this->errors[] = Tools::displayError('The new order status is invalid.');
} else {
$current_order_state = $order->getCurrentOrderState();
- if ($current_order_state->id != $order_state->id) {
+
+ if ($current_order_state->id == Configuration::get('PS_OS_REFUND')) {
+ $this->errors[] = Tools::displayError('Order status can not be changed once order status is set to Refunded.');
+ } elseif ($current_order_state->id == Configuration::get('PS_OS_CANCELED')) {
+ $this->errors[] = Tools::displayError('Order status can not be changed once order status is set to Cancelled.');
+ } elseif (in_array($order_state->id, array (Configuration::get('PS_OS_OVERBOOKING_PAID'), Configuration::get('PS_OS_OVERBOOKING_UNPAID'), Configuration::get('PS_OS_OVERBOOKING_PARTIAL_PAID')))) {
+ $objHotelBooking = new HotelBookingDetail();
+ if (!$objHotelBooking->getOverbookedRooms($order->id)) {
+ $this->errors[] = Tools::displayError('Order status can not be changed to any overbooking status as there are no overbooked rooms in the order.');
+ }
+ } elseif ($order_state->id == Configuration::get('PS_OS_REFUND')
+ && !$order->hasCompletelyRefunded(Order::ORDER_COMPLETE_REFUND_FLAG)
+ ) {
+ $this->errors[] = Tools::displayError('Order status can not be set to Refunded until all bookings in the order are completely refunded.');
+ } elseif ($order_state->id == Configuration::get('PS_OS_CANCELED')
+ && !$order->hasCompletelyRefunded(Order::ORDER_COMPLETE_CANCELLATION_FLAG)
+ ) {
+ $this->errors[] = Tools::displayError('Order status can not be set to Cancelled until all bookings in the order are cancelled.');
+ } elseif ($current_order_state->id == Configuration::get('PS_OS_ERROR') && !($order_state->id == Configuration::get('PS_OS_ERROR'))) {
+ // All rooms must be available before changing status from Payment Error to Other status in which rooms are getting blocked again
+ $objHotelBooking = new HotelBookingDetail();
+ if ($orderBookings = $objHotelBooking->getOrderCurrentDataByOrderId($order->id)) {
+ foreach ($orderBookings as $orderBooking) {
+ // If booking is refunded then no need to check inventory
+ if ((OrderReturn::getOrdersReturnDetail($order->id, 0, $orderBooking['id']) && $orderBooking['is_refunded'])
+ || ($orderBooking['is_cancelled'] && $orderBooking['is_refunded'])
+ ) {
+ continue;
+ } else {
+ // if inventory is available for that booking
+ $bookingParams = array(
+ 'date_from' => $orderBooking['date_from'],
+ 'date_to' => $orderBooking['date_to'],
+ 'hotel_id' => $orderBooking['id_hotel'],
+ 'id_room_type' => $orderBooking['id_product'],
+ 'only_search_data' => 1
+ );
+
+ $objHotelBookingDetail = new HotelBookingDetail($orderBooking['id']);
+ if ($searchRoomsInfo = $objHotelBooking->getBookingData($bookingParams)) {
+ if (isset($searchRoomsInfo['rm_data'][$orderBooking['id_product']]['data']['available'])
+ && $searchRoomsInfo['rm_data'][$orderBooking['id_product']]['data']['available']
+ ) {
+ $availableRoomsInfo = $searchRoomsInfo['rm_data'][$orderBooking['id_product']]['data']['available'];
+ if ($roomIdsAvailable = array_column($availableRoomsInfo, 'id_room')) {
+ // Check If room is still there in the available rooms list
+ if (!in_array($orderBooking['id_room'], $roomIdsAvailable)) {
+ $this->errors[] = Tools::displayError('You can not change the order status as some rooms are not available now in this order. You can reallocate/swap rooms with other rooms to make rooms available and then change the order status.');
+
+ break;
+ } else {
+ $objHotelBookingDetail->is_refunded = 0;
+ $objHotelBookingDetail->save();
+ }
+ } else {
+ $this->errors[] = Tools::displayError('You can not change the order status as some rooms are not available now in this order. You can reallocate/swap rooms with other rooms to make rooms available and then change the order status.');
+ break;
+ }
+ }
+ } else {
+ $this->errors[] = Tools::displayError('You can not change the order status as some rooms are not available now in this order. You can reallocate/swap rooms with other rooms to make rooms available and then change the order status.');
+
+ break;
+ }
+ }
+ }
+ }
+ } elseif ($current_order_state->id == $order_state->id) {
+ $this->errors[] = Tools::displayError('The order has already been assigned this status.');
+ }
+
+ // If no errors then we change the order status
+ if (!count($this->errors)) {
// Create new OrderHistory
$history = new OrderHistory();
$history->id_order = $order->id;
@@ -721,11 +792,10 @@ public function postProcess()
}
}
- Tools::redirectAdmin(self::$currentIndex.'&id_order='.(int)$order->id.'&vieworder&token='.$this->token);
+ Tools::redirectAdmin(self::$currentIndex.'&id_order='.(int)$order->id.'&conf=5&vieworder&token='.$this->token);
}
+
$this->errors[] = Tools::displayError('An error occurred while changing order status, or we were unable to send an email to the customer.');
- } else {
- $this->errors[] = Tools::displayError('The order has already been assigned this status.');
}
}
} else {
@@ -856,26 +926,58 @@ public function postProcess()
}
if (!count($this->errors)) {
- $objOrderReturn = new OrderReturn();
- $objOrderReturn->id_customer = $order->id_customer;
- $objOrderReturn->id_order = $order->id;
- $objOrderReturn->state = Configuration::get('PS_ORS_PENDING');
- $objOrderReturn->by_admin = 1;
- $objOrderReturn->question = $refundReason;
- $objOrderReturn->save();
- if ($objOrderReturn->id) {
+ // if amount paid is > 0 then create refund request else cancel the booking directly
+ if ($order->getTotalPaid() > 0) {
+ $objOrderReturn = new OrderReturn();
+ $objOrderReturn->id_customer = $order->id_customer;
+ $objOrderReturn->id_order = $order->id;
+ $objOrderReturn->state = Configuration::get('PS_ORS_PENDING');
+ $objOrderReturn->by_admin = 1;
+ $objOrderReturn->question = $refundReason;
+ $objOrderReturn->save();
+ if ($objOrderReturn->id) {
+ foreach ($bookings as $idHtlBooking) {
+ $objHtlBooking = new HotelBookingDetail($idHtlBooking);
+ $numDays = $objHtlBooking->getNumberOfDays(
+ $objHtlBooking->date_from,
+ $objHtlBooking->date_to
+ );
+ $objOrderReturnDetail = new OrderReturnDetail();
+ $objOrderReturnDetail->id_order_return = $objOrderReturn->id;
+ $objOrderReturnDetail->id_order_detail = $objHtlBooking->id_order_detail;
+ $objOrderReturnDetail->product_quantity = $numDays;
+ $objOrderReturnDetail->id_htl_booking = $idHtlBooking;
+ $objOrderReturnDetail->save();
+ }
+ }
+ } else {
+ // cancel the booking directly
foreach ($bookings as $idHtlBooking) {
$objHtlBooking = new HotelBookingDetail($idHtlBooking);
- $numDays = $objHtlBooking->getNumberOfDays(
- $objHtlBooking->date_from,
- $objHtlBooking->date_to
- );
- $objOrderReturnDetail = new OrderReturnDetail();
- $objOrderReturnDetail->id_order_return = $objOrderReturn->id;
- $objOrderReturnDetail->id_order_detail = $objHtlBooking->id_order_detail;
- $objOrderReturnDetail->product_quantity = $numDays;
- $objOrderReturnDetail->id_htl_booking = $idHtlBooking;
- $objOrderReturnDetail->save();
+ if (!$objHtlBooking->processRefundInBookingTables()) {
+ $this->errors[] = Tools::displayError('An error occurred while cancelling the booking.');
+ } else {
+ // set the message for the cancellation
+ $message = $this->l('Room').': '.$objHtlBooking->room_num.', '.$objHtlBooking->room_type_name.' '.$this->l('has been cancelled by the hotel.');
+ $message .= PHP_EOL.$this->l('Reasonn').': '.$refundReason;
+ $objHtlBooking->setBookingCancellationMessage($message, 1);
+ }
+ }
+
+ // if all bookings are getting cancelled then cancel the order also
+ if ($order->hasCompletelyRefunded(Order::ORDER_COMPLETE_CANCELLATION_FLAG)) {
+ $objOrderHistory = new OrderHistory();
+ $objOrderHistory->id_order = (int)$order->id;
+
+ $idOrderState = Configuration::get('PS_OS_CANCELED');
+
+ $useExistingPayment = false;
+ if (!$order->hasInvoice()) {
+ $useExistingPayment = true;
+ }
+
+ $objOrderHistory->changeIdOrderState($idOrderState, $order, $useExistingPayment);
+ $objOrderHistory->addWithemail();
}
}
}
@@ -1883,13 +1985,16 @@ public function renderView()
// applicable refund policies
$applicableRefundPolicies = HotelOrderRefundRules::getApplicableRefundRules($order->id);
+
$this->tpl_view_vars = array(
// refund info
'refund_allowed' => (int) $order->isReturnable(),
'applicable_refund_policies' => $applicableRefundPolicies,
'returns' => OrderReturn::getOrdersReturn($order->id_customer, $order->id),
'refundReqBookings' => $refundReqBookings,
- 'hasCompletelyRefunded' => $order->hasCompletelyRefunded(),
+ 'completeRefundRequestOrCancel' => $order->hasCompletelyRefunded(Order::ORDER_COMPLETE_CANCELLATION_OR_REFUND_REQUEST_FLAG),
+ 'allBookingsRefunded' => $order->hasCompletelyRefunded(Order::ORDER_COMPLETE_REFUND_FLAG),
+ 'allBookingsCancelled' => $order->hasCompletelyRefunded(Order::ORDER_COMPLETE_CANCELLATION_FLAG),
'refundedAmount' => $refundedAmount,
'totalDemandsPriceTI' => $totalDemandsPriceTI,
'totalDemandsPriceTE' => $totalDemandsPriceTE,
diff --git a/controllers/front/GuestTrackingController.php b/controllers/front/GuestTrackingController.php
index 3cc86d316..b72bdb1c2 100644
--- a/controllers/front/GuestTrackingController.php
+++ b/controllers/front/GuestTrackingController.php
@@ -205,7 +205,6 @@ protected function assignOrderTracking($order_collection)
$objRoomTypeServiceProductOrderDetail = new RoomTypeServiceProductOrderDetail();
$objRoomType = new HotelRoomType();
- $nonRequestedRooms = 0;
$anyBackOrder = 0;
foreach ($order_list as &$order) {
@@ -570,7 +569,6 @@ protected function assignOrderTracking($order_collection)
//end
Hook::exec('actionOrderDetail', array('carrier' => $order->carrier, 'order' => $order));
-
}
}
diff --git a/controllers/front/OrderConfirmationController.php b/controllers/front/OrderConfirmationController.php
index 40955333f..158c239b2 100644
--- a/controllers/front/OrderConfirmationController.php
+++ b/controllers/front/OrderConfirmationController.php
@@ -110,7 +110,6 @@ public function initContent()
/*By webkul to show order details properly on order history page*/
if (Module::isInstalled('hotelreservationsystem')) {
require_once _PS_MODULE_DIR_.'hotelreservationsystem/define.php';
- $non_requested_rooms = 0;
$any_back_order = 0;
$processed_product = array();
$orderTotalInfo = array();
@@ -186,12 +185,6 @@ public function initContent()
/*Product price when order was created*/
$order_details_obj = new OrderDetail($data_v['id_order_detail']);
$cart_htl_data[$type_key]['name'] = $order_details_obj->product_name;
- // $ord_refnd_info = $obj_ord_ref_info->getOderRefundInfoByIdOrderIdProductByDate($this->id_order, $type_value['product_id'], $data_v['date_from'], $data_v['date_to']);
- // if ($ord_refnd_info) {
- // $stage_name = $obj_refund_stages->getNameById($ord_refnd_info['refund_stage_id']);
- // } else {
- // $non_requested_rooms = 1;
- // }
$stage_name = '';
if (isset($cart_htl_data[$type_key]['date_diff'][$date_join])) {
$cart_htl_data[$type_key]['date_diff'][$date_join]['num_rm'] += 1;
@@ -403,7 +396,6 @@ public function initContent()
}
$this->context->smarty->assign('orderTotalInfo', $orderTotalInfo);
- $this->context->smarty->assign('non_requested_rooms', $non_requested_rooms);
$this->context->smarty->assign('orders_has_invoice', $orders_has_invoice);
}
diff --git a/controllers/front/OrderDetailController.php b/controllers/front/OrderDetailController.php
index 196091216..e5b3260e1 100644
--- a/controllers/front/OrderDetailController.php
+++ b/controllers/front/OrderDetailController.php
@@ -244,41 +244,70 @@ public function initContent()
}
$res = true;
if (!$hasError) {
- if ((int)$order->total_paid_real == 0){
+ $hasCancelled = 0;
+ // if amount paid is > 0 then create refund request else cancel the booking directly
+ if ($order->getTotalPaid() > 0) {
+ $objOrderReturn = new OrderReturn();
+ $objOrderReturn->id_customer = $order->id_customer;
+ $objOrderReturn->id_order = $order->id;
+ $objOrderReturn->state = 0;
+ $objOrderReturn->by_admin = 0;
+ $objOrderReturn->question = $refundReason;
+ $objOrderReturn->save();
+ if ($objOrderReturn->id) {
+ foreach ($bookingRefunds as $idHtlBooking) {
+ $objHtlBooking = new HotelBookingDetail($idHtlBooking);
+ $numDays = $objHtlBooking->getNumberOfDays(
+ $objHtlBooking->date_from,
+ $objHtlBooking->date_to
+ );
+
+ $objOrderReturnDetail = new OrderReturnDetail();
+ $objOrderReturnDetail->id_order_return = $objOrderReturn->id;
+ $objOrderReturnDetail->id_order_detail = $objHtlBooking->id_order_detail;
+ $objOrderReturnDetail->product_quantity = $numDays;
+ $objOrderReturnDetail->id_htl_booking = $idHtlBooking;
+ $objOrderReturnDetail->save();
+ }
+ }
+ // Emails to customer, admin on refund request state change
+ $objOrderReturn->changeIdOrderReturnState(Configuration::get('PS_ORS_PENDING'));
+ } else {
+ $hasCancelled = 1;
+ // cancel the booking directly
foreach ($bookingRefunds as $idHtlBooking) {
$objHtlBooking = new HotelBookingDetail($idHtlBooking);
- $objHtlBooking->save();
+ if (!$objHtlBooking->processRefundInBookingTables()) {
+ die(json_encode(array('status' => 0)));
+ } else {
+ // set the message for the cancellation
+ $message = Tools::displayError('1 Room from').' '.', '.$objHtlBooking->room_type_name.' '.Tools::displayError('has been cancelled by the hotel.');
+ $message .= PHP_EOL.Tools::displayError('Reason').': '.$refundReason;
+
+ $objHtlBooking->setBookingCancellationMessage($refundReason);
+ }
}
- }
- $objOrderReturn = new OrderReturn();
- $objOrderReturn->id_customer = $order->id_customer;
- $objOrderReturn->id_order = $order->id;
- $objOrderReturn->state = 0;
- $objOrderReturn->by_admin = 0;
- $objOrderReturn->question = $refundReason;
- $objOrderReturn->save();
- if ($objOrderReturn->id) {
- foreach ($bookingRefunds as $idHtlBooking) {
- $objHtlBooking = new HotelBookingDetail($idHtlBooking);
- $numDays = $objHtlBooking->getNumberOfDays(
- $objHtlBooking->date_from,
- $objHtlBooking->date_to
- );
-
- $objOrderReturnDetail = new OrderReturnDetail();
- $objOrderReturnDetail->id_order_return = $objOrderReturn->id;
- $objOrderReturnDetail->id_order_detail = $objHtlBooking->id_order_detail;
- $objOrderReturnDetail->product_quantity = $numDays;
- $objOrderReturnDetail->id_htl_booking = $idHtlBooking;
- $objOrderReturnDetail->save();
+ // if all bookings are getting cancelled then cancel the order also
+ if ($order->hasCompletelyRefunded(Order::ORDER_COMPLETE_CANCELLATION_FLAG)) {
+ $objOrderHistory = new OrderHistory();
+ $objOrderHistory->id_order = (int)$order->id;
+
+ $idOrderState = Configuration::get('PS_OS_CANCELED');
+
+ $useExistingPayment = false;
+ if (!$order->hasInvoice()) {
+ $useExistingPayment = true;
+ }
+
+ $objOrderHistory->changeIdOrderState($idOrderState, $order, $useExistingPayment);
+ $objOrderHistory->addWithemail();
}
}
- // Emails to customer, admin on refund request state change
- $objOrderReturn->changeIdOrderReturnState(Configuration::get('PS_ORS_PENDING'));
- die(json_encode(array('status' => 1)));
+ die(json_encode(array('status' => 1, 'has_cancelled' => $hasCancelled)));
}
+
die(json_encode(array('status' => 0)));
}
} else {
@@ -322,7 +351,6 @@ public function initContent()
$objRoomType = new HotelRoomType();
$objBookingDemand = new HotelBookingDemands();
$objRoomTypeServiceProductOrderDetail = new RoomTypeServiceProductOrderDetail();
- $nonRequestedRooms = 1;
$anyBackOrder = 0;
$processedProducts = array();
$cartHotelData = array();
@@ -618,7 +646,6 @@ public function initContent()
'order_has_invoice' => $order->hasInvoice(),
'cart_htl_data' => $cartHotelData,
'cart_service_products' => $cartServiceProducts,
- 'non_requested_rooms' => $nonRequestedRooms,
)
);
// }
@@ -635,7 +662,7 @@ public function initContent()
'refund_allowed' => (int) $order->isReturnable(),
'returns' => OrderReturn::getOrdersReturn($order->id_customer, $order->id),
'refundReqBookings' => $refundReqBookings,
- 'hasCompletelyRefunded' => $order->hasCompletelyRefunded(),
+ 'completeRefundRequestOrCancel' => $order->hasCompletelyRefunded(Order::ORDER_COMPLETE_CANCELLATION_OR_REFUND_REQUEST_FLAG),
'refundedAmount' => $refundedAmount,
'shop_name' => strval(Configuration::get('PS_SHOP_NAME')),
'order' => $order,
@@ -693,4 +720,4 @@ public function setMedia()
$this->addCSS(_THEME_CSS_DIR_.'addresses.css');
}
}
-}
\ No newline at end of file
+}
diff --git a/install/langs/bg/data/order_state.xml b/install/langs/bg/data/order_state.xml
index f22b1f4be..c1d4db4c4 100644
--- a/install/langs/bg/data/order_state.xml
+++ b/install/langs/bg/data/order_state.xml
@@ -5,7 +5,7 @@