diff --git a/admin/themes/default/template/controllers/orders/_product_line.tpl b/admin/themes/default/template/controllers/orders/_product_line.tpl index 18ceebacc..3bdfaf032 100644 --- a/admin/themes/default/template/controllers/orders/_product_line.tpl +++ b/admin/themes/default/template/controllers/orders/_product_line.tpl @@ -193,18 +193,22 @@ {/if} - {if (isset($refundReqBookings) && $refundReqBookings) || (isset($isCancelledRoom) && $isCancelledRoom)} + {if (isset($refundReqBookings) && $refundReqBookings)} - {if $data.is_cancelled} - {l s='Cancelled'} - {elseif isset($data.refund_info) && $data.refund_info} - {$data.refund_info.name|escape:'html':'UTF-8'} + {if $data.id|in_array:$refundReqBookings} + {if $data.is_cancelled} + {l s='Cancelled'} + {elseif isset($data.refund_info) && (!$data.refund_info.refunded || $data.refund_info.id_customization)} + {$data.refund_info.name|escape:'html':'UTF-8'} + {else} + -- + {/if} {else} - -- - {/if} + -- + {/if} - {if isset($data.refund_info) && $data.refund_info} + {if $data.is_refunded && isset($data.refund_info) && $data.refund_info} {convertPriceWithCurrency price=$data.refund_info.refunded_amount currency=$currency->id} {else} -- diff --git a/admin/themes/default/template/controllers/orders/_rooms_informaion_table.tpl b/admin/themes/default/template/controllers/orders/_rooms_informaion_table.tpl index cd9914afa..8fa049382 100644 --- a/admin/themes/default/template/controllers/orders/_rooms_informaion_table.tpl +++ b/admin/themes/default/template/controllers/orders/_rooms_informaion_table.tpl @@ -33,7 +33,7 @@ {l s='Extra Services/Fee (Tax excl.)'} {l s='Total Tax'} {l s='Total Price (Tax incl.)'} - {if (isset($refundReqBookings) && $refundReqBookings) || (isset($isCancelledRoom) && $isCancelledRoom)} + {if (isset($refundReqBookings) && $refundReqBookings)} {l s='Refund/Cancel Status'} {l s='Refunded amount'} {/if} diff --git a/admin/themes/default/template/controllers/orders/helpers/view/view.tpl b/admin/themes/default/template/controllers/orders/helpers/view/view.tpl index 077a3bb15..f8c071960 100644 --- a/admin/themes/default/template/controllers/orders/helpers/view/view.tpl +++ b/admin/themes/default/template/controllers/orders/helpers/view/view.tpl @@ -102,7 +102,7 @@ {l s='Duration'} {l s='Documents'} {l s='Room Status'} - {l s='Action'} + {l s='Action'} @@ -133,7 +133,7 @@ {/if} - {if $data.is_refunded || $data.is_cancelled} + {if isset($refundReqBookings) && $refundReqBookings && $data.id|in_array:$refundReqBookings && $data.is_refunded} {if $data.is_cancelled}{l s='Cancelled'}{else}{l s='Refunded'}{/if} {else} @@ -246,7 +246,7 @@
@@ -1250,6 +1250,8 @@ {addJsDef ROOM_STATUS_ALLOTED=$ROOM_STATUS_ALLOTED|escape:'quotes':'UTF-8'} {addJsDef ROOM_STATUS_CHECKED_IN=$ROOM_STATUS_CHECKED_IN|escape:'quotes':'UTF-8'} {addJsDef ROOM_STATUS_CHECKED_OUT=$ROOM_STATUS_CHECKED_OUT|escape:'quotes':'UTF-8'} + {addJsDef PS_OS_CANCELED=Configuration::get('PS_OS_CANCELED')|escape:'quotes':'UTF-8'} + {addJsDef PS_OS_REFUND=Configuration::get('PS_OS_REFUND')|escape:'quotes':'UTF-8'} {addJsDefL name=txt_booking_document_upload_success}{l s='Document uploaded successfully.' js=1}{/addJsDefL} {addJsDefL name=txt_booking_document_delete_confirm}{l s='Are you sure?' js=1}{/addJsDefL} diff --git a/admin/themes/default/template/controllers/orders/modals/_cancel_room_bookings.tpl b/admin/themes/default/template/controllers/orders/modals/_cancel_room_bookings.tpl index f2d0875b7..5fbe2f90d 100644 --- a/admin/themes/default/template/controllers/orders/modals/_cancel_room_bookings.tpl +++ b/admin/themes/default/template/controllers/orders/modals/_cancel_room_bookings.tpl @@ -65,7 +65,7 @@
- {l s='No room bookings found.'} + {l s='No room bookings found to cancel'}
{/if} diff --git a/classes/order/Order.php b/classes/order/Order.php index 74fc0a450..72e19deff 100644 --- a/classes/order/Order.php +++ b/classes/order/Order.php @@ -2631,9 +2631,12 @@ public static function getAllOrdersByCartId($id_cart) * 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 + * + * @param integer includeCheckIn = 1: If you want to get result for rooms that are refunded or cancelled Or Checkin/Checkout. Send $action = 0 + * * @return boolean: true if order has been completely refunded as per requested parameters or false */ - public function hasCompletelyRefunded($action = 0) + public function hasCompletelyRefunded($action = 0, $includeCheckIn = 0) { $objHotelBooking = new HotelBookingdetail(); if ($orderBookings = $objHotelBooking->getOrderCurrentDataByOrderId($this->id)) { @@ -2658,11 +2661,18 @@ public function hasCompletelyRefunded($action = 0) } 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'])) { + // If booking refund request is created and request is completed but booking is not refunded then return false + if ($bookingRefundDetail = OrderReturn::getOrdersReturnDetail($this->id, 0, $booking['id'])) { + $bookingRefundDetail = reset($bookingRefundDetail); + if ($bookingRefundDetail['refunded']) { + return false; + } + } else { return false; } } } + return true; // Default process to check if order is fully refunded or cancelled or not } else { @@ -2670,6 +2680,16 @@ public function hasCompletelyRefunded($action = 0) $uniqueRefundedBookings = array_unique(array_column($orderBookings, 'is_refunded')); if (count($uniqueRefundedBookings) == 1 && $uniqueRefundedBookings[0] == 1) { return true; + } elseif ($includeCheckIn) { + foreach ($orderBookings as $booking) { + if ($booking['is_refunded'] == 0 + && !OrderReturn::getOrdersReturnDetail($this->id, 0, $booking['id']) + && $booking['id_status'] == HotelBookingDetail::STATUS_ALLOTED + ) { + return false; + } + } + return true; } } } @@ -2727,7 +2747,12 @@ public function ChangeOrderStatus() if ($orderBookings = $objHotelBooking->getOrderCurrentDataByOrderId($this->id)) { foreach ($orderBookings as $orderBooking) { // If booking is refunded then no need to check inventory - if ((OrderReturn::getOrdersReturnDetail($this->id, 0, $orderBooking['id']) && $orderBooking['is_refunded']) + if ($bookingRefundDetail = OrderReturn::getOrdersReturnDetail($this->id, 0, $orderBooking['id'])) { + $bookingRefundDetail = reset($bookingRefundDetail); + } + + // $bookingRefundDetail['id_customization'] is 1 for only refunded request completed and refunded bookings + if (($bookingRefundDetail && $bookingRefundDetail['refunded'] && $orderBooking['is_refunded'] && $bookingRefundDetail['id_customization']) || ($orderBooking['is_cancelled'] && $orderBooking['is_refunded']) ) { continue; diff --git a/classes/order/OrderReturn.php b/classes/order/OrderReturn.php index aaace5681..4d8ab297a 100644 --- a/classes/order/OrderReturn.php +++ b/classes/order/OrderReturn.php @@ -177,9 +177,18 @@ public function countProduct() return (int)($data['total']); } - public function getOrderRefundRequestedBookings($idOrder, $idOrderReturn = 0, $onlyBookingIds = 0, $customerView = 0) + /** + * Get order refund requested bookings + * @param integer $idOrder + * @param integer $idOrderReturn + * @param integer $onlyBookingIds + * @param integer $customerView + * @param integer $skipReqCompletedNonRefunded: send 1 if you want to skip refund request completed but non-refunded booking + * @return array of refund requested bookings + */ + public function getOrderRefundRequestedBookings($idOrder, $idOrderReturn = 0, $onlyBookingIds = 0, $customerView = 0, $skipReqCompletedNonRefunded = 0) { - $sql = 'SELECT hbd.*, ord.* FROM `'._DB_PREFIX_.'order_return` orr'; + $sql = 'SELECT hbd.*, ord.*, orr.`state` as id_return_state FROM `'._DB_PREFIX_.'order_return` orr'; $sql .= ' LEFT JOIN `'._DB_PREFIX_.'order_return_detail` ord ON (orr.`id_order_return` = ord.`id_order_return`)'; $sql .= ' LEFT JOIN `'._DB_PREFIX_.'htl_booking_detail` hbd ON (hbd.`id` = ord.`id_htl_booking`)'; $sql .= ' WHERE orr.`id_order` = '.(int)$idOrder; @@ -189,79 +198,92 @@ public function getOrderRefundRequestedBookings($idOrder, $idOrderReturn = 0, $o } if ($returnDetails = Db::getInstance()->executeS($sql)) { - if ($onlyBookingIds) { - return array_column($returnDetails, 'id_htl_booking'); - } - if ($customerView) { $returnsCustView = array(); } + $objOrder = new Order($idOrder); $objBookingDemands = new HotelBookingDemands(); $objRoomTypeServiceProductOrderDetail = new RoomTypeServiceProductOrderDetail(); - $objOrder = new Order($idOrder); - foreach ($returnDetails as &$bookingRow) { - $bookingRow['extra_service_total_paid_amount'] = 0; - $bookingRow['extra_service_total_price_tax_incl'] = 0; - $bookingRow['room_paid_amount'] = 0; - if ($bookingRow['total_price_tax_incl'] > 0) { - if ($objOrder->total_paid_real > 0) { - $bookingRow['room_paid_amount'] = ($objOrder->total_paid_real*$bookingRow['total_price_tax_incl'])/$objOrder->total_paid_tax_incl; + + foreach ($returnDetails as $key => &$bookingRow) { + if ($skipReqCompletedNonRefunded) { + $objReturnState = new OrderReturnState($bookingRow['id_return_state']); + if ($objReturnState->refunded && !$bookingRow['is_refunded']) { + unset($returnDetails[$key]); + continue; } } - $roomSelectedDemands = $objBookingDemands->getRoomTypeBookingExtraDemands( - $idOrder, - $bookingRow['id_product'], - $bookingRow['id_room'], - $bookingRow['date_from'], - $bookingRow['date_to'], - 0 - ); - if (count($roomSelectedDemands)) { - foreach ($roomSelectedDemands as $demand) { - if ($demand['total_price_tax_incl'] > 0) { - if ($objOrder->total_paid_real > 0) { - $bookingRow['extra_service_total_paid_amount'] += ($objOrder->total_paid_real*$demand['total_price_tax_incl'])/$objOrder->total_paid_tax_incl; + + if (!$onlyBookingIds) { + $bookingRow['extra_service_total_paid_amount'] = 0; + $bookingRow['extra_service_total_price_tax_incl'] = 0; + $bookingRow['room_paid_amount'] = 0; + if ($bookingRow['total_price_tax_incl'] > 0) { + if ($objOrder->total_paid_real > 0) { + $bookingRow['room_paid_amount'] = ($objOrder->total_paid_real*$bookingRow['total_price_tax_incl'])/$objOrder->total_paid_tax_incl; + } + } + $roomSelectedDemands = $objBookingDemands->getRoomTypeBookingExtraDemands( + $idOrder, + $bookingRow['id_product'], + $bookingRow['id_room'], + $bookingRow['date_from'], + $bookingRow['date_to'], + 0 + ); + if (count($roomSelectedDemands)) { + foreach ($roomSelectedDemands as $demand) { + if ($demand['total_price_tax_incl'] > 0) { + if ($objOrder->total_paid_real > 0) { + $bookingRow['extra_service_total_paid_amount'] += ($objOrder->total_paid_real*$demand['total_price_tax_incl'])/$objOrder->total_paid_tax_incl; + } + $bookingRow['extra_service_total_price_tax_incl'] += $demand['total_price_tax_incl']; } - $bookingRow['extra_service_total_price_tax_incl'] += $demand['total_price_tax_incl']; } } - } - if ($roomSelectedServices = $objRoomTypeServiceProductOrderDetail->getSelectedServicesForRoom( - $bookingRow['id_htl_booking'] - )) { - if (count($roomSelectedServices['additional_services'])) { - foreach ($roomSelectedServices['additional_services'] as $service) { - if ($service['total_price_tax_incl'] > 0) { - if ($objOrder->total_paid_real > 0) { - $bookingRow['extra_service_total_paid_amount'] += ($objOrder->total_paid_real*$service['total_price_tax_incl'])/$objOrder->total_paid_tax_incl; + if ($roomSelectedServices = $objRoomTypeServiceProductOrderDetail->getSelectedServicesForRoom( + $bookingRow['id_htl_booking'] + )) { + if (count($roomSelectedServices['additional_services'])) { + foreach ($roomSelectedServices['additional_services'] as $service) { + if ($service['total_price_tax_incl'] > 0) { + if ($objOrder->total_paid_real > 0) { + $bookingRow['extra_service_total_paid_amount'] += ($objOrder->total_paid_real*$service['total_price_tax_incl'])/$objOrder->total_paid_tax_incl; + } + $bookingRow['extra_service_total_price_tax_incl'] += $service['total_price_tax_incl']; } - $bookingRow['extra_service_total_price_tax_incl'] += $service['total_price_tax_incl']; } } } - } - if ($customerView) { - $dateJoin = $bookingRow['id_product'].'_'.strtotime($bookingRow['date_from']).strtotime($bookingRow['date_to']); - if (isset($returnsCustView[$dateJoin]['num_rooms'])) { - $returnsCustView[$dateJoin]['num_rooms'] += 1; - $returnsCustView[$dateJoin]['refunded_amount'] += $bookingRow['refunded_amount']; - $returnsCustView[$dateJoin]['total_price_tax_incl'] += $bookingRow['total_price_tax_incl']; - $returnsCustView[$dateJoin]['total_paid_amount'] += $bookingRow['total_paid_amount']; - } else { - unset($bookingRow['id_room']); - unset($bookingRow['room_num']); - unset($bookingRow['id_htl_booking']); - $returnsCustView[$dateJoin] = $bookingRow; - $returnsCustView[$dateJoin]['num_rooms'] = 1; + if ($customerView) { + $dateJoin = $bookingRow['id_product'].'_'.strtotime($bookingRow['date_from']).strtotime($bookingRow['date_to']); + if (isset($returnsCustView[$dateJoin]['num_rooms'])) { + $returnsCustView[$dateJoin]['num_rooms'] += 1; + $returnsCustView[$dateJoin]['refunded_amount'] += $bookingRow['refunded_amount']; + $returnsCustView[$dateJoin]['total_price_tax_incl'] += $bookingRow['total_price_tax_incl']; + $returnsCustView[$dateJoin]['total_paid_amount'] += $bookingRow['total_paid_amount']; + } else { + unset($bookingRow['id_room']); + unset($bookingRow['room_num']); + unset($bookingRow['id_htl_booking']); + $returnsCustView[$dateJoin] = $bookingRow; + $returnsCustView[$dateJoin]['num_rooms'] = 1; + } } } } + + if ($onlyBookingIds) { + return array_column($returnDetails, 'id_htl_booking'); + } + if ($customerView) { return $returnsCustView; } } + return $returnDetails; } @@ -297,8 +319,21 @@ public static function getOrdersReturn($customer_id, $order_id = false, $no_deni return $data; } - public static function getOrdersReturnDetail($idOrder, $idOrderReturn = 0, $idHtlBooking = 0, $idLang = 0) - { + /** + * @param $idOrder + * @param int $idOrderReturn + * @param int $idHtlBooking + * @param int $idLang + * @param int $orderByLatestRequest : If you want to return request with in the Desc order of refund requests + * @return array + */ + public static function getOrdersReturnDetail( + $idOrder, + $idOrderReturn = 0, + $idHtlBooking = 0, + $idLang = 0, + $orderByLatestRequest = 1 + ) { if (!$idLang) { $idLang = Context::getContext()->language->id; } @@ -316,6 +351,10 @@ public static function getOrdersReturnDetail($idOrder, $idOrderReturn = 0, $idHt $sql .= ' AND ord.`id_htl_booking` = '.(int)$idHtlBooking; } + if ($orderByLatestRequest) { + $sql .= ' ORDER BY orr.`id_order_return` DESC'; + } + return Db::getInstance()->executeS($sql); } @@ -449,8 +488,8 @@ public function changeIdOrderReturnState($newOrderReturnState, $idLang = 0) '{order_reference}' => $objOrder->reference, '{order_date}' => date('Y-m-d h:i:s', strtotime($objOrder->date_add)), '{refunded_amount}' => Tools::displayPrice($this->refunded_amount, new Currency($objOrder->id_currency)), - '{payment_mode}' => $this->payment_mode, - '{id_transaction}' => $this->id_transaction, + '{payment_mode}' => $this->payment_mode ? $this->payment_mode : '--', + '{id_transaction}' => $this->id_transaction ? $this->id_transaction : '--', ); // if mail is true for the customer then send mail to customer with selected template diff --git a/classes/order/OrderReturnDetail.php b/classes/order/OrderReturnDetail.php index b956347c1..9975ee40a 100644 --- a/classes/order/OrderReturnDetail.php +++ b/classes/order/OrderReturnDetail.php @@ -30,9 +30,15 @@ class OrderReturnDetailCore extends ObjectModel public $refunded_amount; public $id_order_detail; + + // Used to manage refunded or refunde denied bookings in a refund request : 1 for only refunded request completed and refunded bookings public $id_customization; public $product_quantity; + const REFUND_REQUEST_STATUS_LATEST = 1; + const REFUND_REQUEST_STATUS_PENDING = 2; + const REFUND_REQUEST_STATUS_COMPLETED = 3; + /** * @see ObjectModel::$definition */ diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index d56966e0c..334d07db8 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -494,11 +494,14 @@ public function initToolbar() ); if (((int) $order->isReturnable()) && !$order->hasCompletelyRefunded(Order::ORDER_COMPLETE_CANCELLATION_OR_REFUND_REQUEST_FLAG)) { + $orderTotalPaid = $order->getTotalPaid(); + $orderDiscounts = $order->getCartRules(); + $hasOrderDiscountOrPayment = ((float)$orderTotalPaid > 0 || $orderDiscounts) ? true : false; $this->toolbar_btn['cancel'] = array( - 'short' => ((float) $order->getTotalPaid()) ? $this->l('Refund') : $this->l('Cancel'), + 'short' => ($hasOrderDiscountOrPayment) ? $this->l('Refund') : $this->l('Cancel'), 'href' => '#refundForm', 'id' => 'desc-order-standard_refund', - 'desc' => ((float) $order->getTotalPaid()) ? $this->l('Initiate refund') : $this->l('Cancel bookings'), + 'desc' => ($hasOrderDiscountOrPayment) ? $this->l('Initiate refund') : $this->l('Cancel bookings'), 'class' => 'icon-exchange', 'target' => true, ); @@ -938,7 +941,7 @@ public function ajaxProcessInitCancelRoomBookingModal() // get booking information by order $objBookingDetail = new HotelBookingDetail(); $objOrderReturn = new OrderReturn(); - $refundReqBookings = $objOrderReturn->getOrderRefundRequestedBookings($objOrder->id, 0, 1); + $refundReqBookings = $objOrderReturn->getOrderRefundRequestedBookings($objOrder->id, 0, 1, 0, 1); if ($bookingOrderInfo = $objBookingDetail->getBookingDataByOrderId($objOrder->id)) { foreach($bookingOrderInfo as $key => $booking) { if ((in_array($booking['id'], $refundReqBookings)) || $booking['is_refunded']) { @@ -946,6 +949,7 @@ public function ajaxProcessInitCancelRoomBookingModal() } } } + $this->context->smarty->assign( array( 'order' => $objOrder, @@ -958,15 +962,18 @@ public function ajaxProcessInitCancelRoomBookingModal() 'modal_class' => 'modal-md order_detail_modal', 'modal_title' => '  '.$this->l('Cancel Bookings'), 'modal_content' => $this->context->smarty->fetch('controllers/orders/modals/_cancel_room_bookings.tpl'), - 'modal_actions' => array( + ); + + if ($bookingOrderInfo) { + $modal['modal_actions'] = array( array( 'type' => 'button', 'value' => 'submitCancelBooking', 'class' => 'submitCancelBooking btn-primary pull-right', 'label' => ' '.$this->l('Cancel Bookings'), - ), - ), - ); + ) + ); + } $this->context->smarty->assign($modal); $response['hasError'] = 0; @@ -1375,19 +1382,22 @@ public function postProcess() } } } else { - $this->errors[] = Tools::displayError('You do not have permission to delete this.'); + $this->errors[] = Tools::displayError('You do not have permission to edit this.'); } } /* booking refunds from order */ elseif (Tools::isSubmit('initiateRefund') && isset($order)) { - if ($this->tabAccess['delete'] === '1') { + if ($this->tabAccess['edit'] === '1') { $bookings = Tools::getValue('id_htl_booking'); if ($bookings && count($bookings)) { foreach ($bookings as $idHtlBooking) { - if (OrderReturn::getOrdersReturnDetail($order->id, 0, $idHtlBooking)) { - $this->errors[] = Tools::displayError('Wrong bookings found for booking cancelation.'); - break; + if ($bookingRefundDetail = OrderReturn::getOrdersReturnDetail($order->id, 0, $idHtlBooking)) { + $bookingRefundDetail = reset($bookingRefundDetail); + if (!$bookingRefundDetail['refunded']) { + $this->errors[] = Tools::displayError('Wrong bookings found for booking cancelation.'); + break; + } } } } else { @@ -1399,50 +1409,65 @@ public function postProcess() } if (!count($this->errors)) { - // 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(); + // create refund request + $objOrderReturn = new OrderReturn(); + $objOrderReturn->id_customer = $order->id_customer; + $objOrderReturn->id_order = $order->id; + $objOrderReturn->state = 0; + $objOrderReturn->by_admin = 1; + $objOrderReturn->question = $refundReason; + $objOrderReturn->refunded_amount = 0; + $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->refunded_amount = 0; + if (!$order->getCartRules() && $order->getTotalPaid() <= 0) { + $objOrderReturnDetail->id_customization = 1; } + $objOrderReturnDetail->save(); } - } else { - // cancel the booking directly + } + + // Change order refund state + // Emails to customer, superadmin and employees on refund request state change + $objOrderReturn->changeIdOrderReturnState(Configuration::get('PS_ORS_PENDING')); + + // process direct cancellations + if (!$order->getCartRules() && $order->getTotalPaid() <= 0) { + // Process refund in booking tables foreach ($bookings as $idHtlBooking) { $objHtlBooking = new HotelBookingDetail($idHtlBooking); 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; + // As object order is already changed in processRefundInBookingTables + $order = new Order($order->id); + // complete the booking refund directly in the refund request + $objOrderReturn->changeIdOrderReturnState(Configuration::get('PS_ORS_REFUNDED')); + // if all bookings are getting cancelled/Refunded then Cancel/Refund the order also + $idOrderState = 0; + if ($order->hasCompletelyRefunded(Order::ORDER_COMPLETE_REFUND_FLAG)) { + $idOrderState = Configuration::get('PS_OS_REFUND'); + } elseif ($order->hasCompletelyRefunded(Order::ORDER_COMPLETE_CANCELLATION_FLAG)) { $idOrderState = Configuration::get('PS_OS_CANCELED'); + } + + if ($idOrderState) { + $objOrderHistory = new OrderHistory(); + $objOrderHistory->id_order = (int)$order->id; $useExistingPayment = false; if (!$order->hasInvoice()) { @@ -1460,7 +1485,7 @@ public function postProcess() Tools::redirectAdmin(self::$currentIndex.'&id_order='.$order->id.'&vieworder&conf=3&token='.$this->token); } } else { - $this->errors[] = Tools::displayError('You do not have permission to delete this.'); + $this->errors[] = Tools::displayError('You do not have permission to edit this.'); } } elseif (Tools::isSubmit('messageReaded')) { Message::markAsReaded(Tools::getValue('messageReaded'), $this->context->employee->id); @@ -2546,7 +2571,7 @@ public function renderView() $totalConvenienceFeeTI = 0; $totalDemandsPriceTE = 0; $totalDemandsPriceTI = 0; - + $totalRefundedRooms = 0; if ($order_detail_data = $objBookingDetail->getOrderFormatedBookinInfoByIdOrder($order->id)) { $objBookingDemand = new HotelBookingDemands(); $objHotelRoomType = new HotelRoomType(); @@ -2707,6 +2732,15 @@ public function renderView() $order_detail_data[$key]['amt_with_qty_tax_incl'] = $value['total_price_tax_incl']; $order_detail_data[$key]['room_type_info'] = $objHotelRoomType->getRoomTypeInfoByIdProduct($value['id_product']); $order_detail_data[$key]['total_room_tax'] = $order_detail_data[$key]['total_room_price_ti'] - $order_detail_data[$key]['total_room_price_te']; + + if (isset($value['refund_info']) + && $value['refund_info']['refunded'] + && $value['refund_info']['id_customization'] + && $value['is_refunded'] + && !$value['is_cancelled'] + ) { + $totalRefundedRooms += 1; + } } } else { $order_detail_data = array(); @@ -2714,19 +2748,25 @@ public function renderView() $objOrderReturn = new OrderReturn(); $refundedAmount = 0; - if ($refundReqBookings = $objOrderReturn->getOrderRefundRequestedBookings($order->id, 0, 1)) { + if ($refundReqBookings = $objOrderReturn->getOrderRefundRequestedBookings($order->id, 0, 1, 0, 1)) { $refundedAmount = $objOrderReturn->getRefundedAmount($order->id); } // get booking information by order $bookingOrderInfo = $objBookingDetail->getBookingDataByOrderId($order->id); foreach ($bookingOrderInfo as &$bookingOrderRoomInfo) { + // Get last refund request for booking + if ($bookingRefundDetail = OrderReturn::getOrdersReturnDetail($bookingOrderRoomInfo['id_order'], 0, $bookingOrderRoomInfo['id'])) { + $bookingRefundDetail = reset($bookingRefundDetail); + if (!$bookingRefundDetail['id_customization']) { + $bookingOrderRoomInfo['is_refunded'] = 0; + } + } $bookingOrderRoomInfo['num_checkin_documents'] = HotelBookingDocument::getCountByIdHtlBooking($bookingOrderRoomInfo['id']); } $objHotelBookingDetail = new HotelBookingDetail(); $htlBookingDetail = $objHotelBookingDetail->getOrderCurrentDataByOrderId($order->id); - $isCancelledRoom = in_array(1, array_column($htlBookingDetail, 'is_cancelled')); // hotel booking statuses $htlOrderStatus = HotelBookingDetail::getAllHotelOrderStatus(); @@ -2745,15 +2785,13 @@ public function renderView() $orderOverBookings = $objHotelBookingDetail->getOverbookedRooms($order->id, 0, '', '', 0, 0, 1); $this->tpl_view_vars = array( - // refund info + 'totalRefundedRooms' => $totalRefundedRooms, 'orderOverBookings' => $orderOverBookings, 'refund_allowed' => (int) $order->isReturnable(), 'applicable_refund_policies' => $applicableRefundPolicies, 'returns' => OrderReturn::getOrdersReturn($order->id_customer, $order->id), 'refundReqBookings' => $refundReqBookings, '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, @@ -2840,7 +2878,6 @@ public function renderView() 'products' => $products, 'customer' => $customer) ), - 'isCancelledRoom' => $isCancelledRoom, 'orderDocuments' => $order->getDocuments(), 'ROOM_STATUS_ALLOTED' => HotelBookingDetail::STATUS_ALLOTED, 'ROOM_STATUS_CHECKED_IN' => HotelBookingDetail::STATUS_CHECKED_IN, diff --git a/controllers/front/GuestTrackingController.php b/controllers/front/GuestTrackingController.php index e7017e12f..6a097dbc2 100644 --- a/controllers/front/GuestTrackingController.php +++ b/controllers/front/GuestTrackingController.php @@ -249,6 +249,7 @@ protected function assignOrderTracking($order_collection) $total_demands_price_ti = 0; $total_convenience_fee_te = 0; $total_convenience_fee_ti = 0; + foreach ($orderProducts as $type_key => $type_value) { if (in_array($type_value['product_id'], $processedProducts)) { continue; @@ -306,13 +307,6 @@ protected function assignOrderTracking($order_collection) if ($data_v['is_back_order']) { $anyBackOrder = 1; } - if ($data_v['is_refunded']) { - $cartHotelData[$type_key]['date_diff'][$date_join]['count_refunded'] += 1; - } - if ($data_v['is_cancelled']) { - $cartHotelData[$type_key]['date_diff'][$date_join]['count_cancelled'] += 1; - $cartHotelData[$type_key]['date_diff'][$date_join]['count_refunded'] -= 1; - } } else { $num_days = $objBookingDetail->getNumberOfDays($data_v['date_from'], $data_v['date_to']); $cartHotelData[$type_key]['date_diff'][$date_join]['num_rm'] = 1; @@ -332,15 +326,6 @@ protected function assignOrderTracking($order_collection) if ($data_v['is_back_order']) { $anyBackOrder = 1; } - $cartHotelData[$type_key]['date_diff'][$date_join]['count_cancelled'] = 0; - $cartHotelData[$type_key]['date_diff'][$date_join]['count_refunded'] = 0; - if ($data_v['is_refunded']) { - $cartHotelData[$type_key]['date_diff'][$date_join]['count_refunded'] += 1; - } - if ($data_v['is_cancelled']) { - $cartHotelData[$type_key]['date_diff'][$date_join]['count_cancelled'] += 1; - $cartHotelData[$type_key]['date_diff'][$date_join]['count_refunded'] -= 1; - } } $cartHotelData[$type_key]['date_diff'][$date_join]['is_refunded'] = $data_v['is_refunded']; diff --git a/controllers/front/OrderDetailController.php b/controllers/front/OrderDetailController.php index 93442f5ad..6bebed805 100644 --- a/controllers/front/OrderDetailController.php +++ b/controllers/front/OrderDetailController.php @@ -83,339 +83,348 @@ public function initContent() } - //by webkul to show order details properly on order history page - - // if (Module::isInstalled('hotelreservationsystem')) { - // include_once _PS_MODULE_DIR_.'hotelreservationsystem/define.php'; - // $objHtlBranchInfo = new HotelBranchInformation(); - $objBookingDetail = new HotelBookingDetail(); - $objRoomType = new HotelRoomType(); - $objBookingDemand = new HotelBookingDemands(); - $objRoomTypeServiceProductOrderDetail = new RoomTypeServiceProductOrderDetail(); - $anyBackOrder = 0; - $processedProducts = array(); - $cartHotelData = array(); - $cartServiceProducts = array(); - $total_demands_price_te = 0; - $total_demands_price_ti = 0; - $total_convenience_fee_te = 0; - $total_convenience_fee_ti = 0; - $roomTypes = array(); - if (!empty($products)) { - foreach ($products as $type_key => $type_value) { - if (in_array($type_value['product_id'], $processedProducts)) { - continue; + //To show order details properly on order history page + $objBookingDetail = new HotelBookingDetail(); + $objRoomType = new HotelRoomType(); + $objBookingDemand = new HotelBookingDemands(); + $objRoomTypeServiceProductOrderDetail = new RoomTypeServiceProductOrderDetail(); + $anyBackOrder = 0; + $processedProducts = array(); + $cartHotelData = array(); + $cartServiceProducts = array(); + $total_demands_price_te = 0; + $total_demands_price_ti = 0; + $total_convenience_fee_te = 0; + $total_convenience_fee_ti = 0; + $roomTypes = array(); + $objOrderReturn = new OrderReturn(); + $refundedAmount = 0; + if ($refundReqBookings = $objOrderReturn->getOrderRefundRequestedBookings($order->id, 0, 1)) { + $refundedAmount = $objOrderReturn->getRefundedAmount($order->id); + } + + if (!empty($products)) { + foreach ($products as $type_key => $type_value) { + if (in_array($type_value['product_id'], $processedProducts)) { + continue; + } + if ($type_value['is_booking_product']) { + $processedProducts[] = $type_value['product_id']; + + $product = new Product($type_value['product_id'], false, $this->context->language->id); + $cover_image_arr = $product->getCover($type_value['product_id']); + + if (!empty($cover_image_arr)) { + $cover_img = $this->context->link->getImageLink($product->link_rewrite, $product->id.'-'.$cover_image_arr['id_image'], 'home_default'); + } else { + $cover_img = $this->context->link->getImageLink($product->link_rewrite, $this->context->language->iso_code.'-default', 'home_default'); } - if ($type_value['is_booking_product']) { - $processedProducts[] = $type_value['product_id']; - $product = new Product($type_value['product_id'], false, $this->context->language->id); - $cover_image_arr = $product->getCover($type_value['product_id']); + if (isset($customer->id)) { + $obj_cart = new Cart($order->id_cart); + $order_bk_data = $objBookingDetail->getOnlyOrderBookingData($order->id, $obj_cart->id_guest, $type_value['product_id'], $customer->id); + } else { + $order_bk_data = $objBookingDetail->getOnlyOrderBookingData($order->id, $customer->id_guest, $type_value['product_id']); + } + $cartHotelData[$type_key]['id_product'] = $type_value['product_id']; + $cartHotelData[$type_key]['cover_img'] = $cover_img; - if (!empty($cover_image_arr)) { - $cover_img = $this->context->link->getImageLink($product->link_rewrite, $product->id.'-'.$cover_image_arr['id_image'], 'home_default'); - } else { - $cover_img = $this->context->link->getImageLink($product->link_rewrite, $this->context->language->iso_code.'-default', 'home_default'); - } - if (isset($customer->id)) { - $obj_cart = new Cart($order->id_cart); - $order_bk_data = $objBookingDetail->getOnlyOrderBookingData($order->id, $obj_cart->id_guest, $type_value['product_id'], $customer->id); - } else { - $order_bk_data = $objBookingDetail->getOnlyOrderBookingData($order->id, $customer->id_guest, $type_value['product_id']); + $objBookingDemand = new HotelBookingDemands(); + foreach ($order_bk_data as $data_k => $data_v) { + $date_join = strtotime($data_v['date_from']).strtotime($data_v['date_to']); + + $cartHotelData[$type_key]['adults'] = $data_v['adults']; + $cartHotelData[$type_key]['children'] = $data_v['children']; + /*Product price when order was created*/ + $order_details_obj = new OrderDetail($data_v['id_order_detail']); + $cartHotelData[$type_key]['name'] = $order_details_obj->product_name; + $cartHotelData[$type_key]['paid_unit_price_tax_excl'] = ($order_details_obj->total_price_tax_excl)/$order_details_obj->product_quantity; + $cartHotelData[$type_key]['paid_unit_price_tax_incl'] = ($order_details_obj->total_price_tax_incl)/$order_details_obj->product_quantity; + + // Get last refund request for booking + if ($bookingRefundDetail = OrderReturn::getOrdersReturnDetail($data_v['id_order'], 0, $data_v['id'])) { + $bookingRefundDetail = reset($bookingRefundDetail); } - $cartHotelData[$type_key]['id_product'] = $type_value['product_id']; - $cartHotelData[$type_key]['cover_img'] = $cover_img; - - - $objBookingDemand = new HotelBookingDemands(); - foreach ($order_bk_data as $data_k => $data_v) { - $date_join = strtotime($data_v['date_from']).strtotime($data_v['date_to']); - - $cartHotelData[$type_key]['adults'] = $data_v['adults']; - $cartHotelData[$type_key]['children'] = $data_v['children']; - /*Product price when order was created*/ - $order_details_obj = new OrderDetail($data_v['id_order_detail']); - $cartHotelData[$type_key]['name'] = $order_details_obj->product_name; - $cartHotelData[$type_key]['paid_unit_price_tax_excl'] = ($order_details_obj->total_price_tax_excl)/$order_details_obj->product_quantity; - $cartHotelData[$type_key]['paid_unit_price_tax_incl'] = ($order_details_obj->total_price_tax_incl)/$order_details_obj->product_quantity; - - if (isset($cartHotelData[$type_key]['date_diff'][$date_join])) { - $cartHotelData[$type_key]['date_diff'][$date_join]['num_rm'] += 1; - - $num_days = $cartHotelData[$type_key]['date_diff'][$date_join]['num_days']; - $var_quant = (int) $cartHotelData[$type_key]['date_diff'][$date_join]['num_rm']; - - $cartHotelData[$type_key]['date_diff'][$date_join]['adults'] += $data_v['adults']; - $cartHotelData[$type_key]['date_diff'][$date_join]['children'] += $data_v['children']; - - $cartHotelData[$type_key]['date_diff'][$date_join]['paid_unit_price_tax_excl'] = $data_v['total_price_tax_excl']/$num_days; - $cartHotelData[$type_key]['date_diff'][$date_join]['paid_unit_price_tax_incl'] = $data_v['total_price_tax_incl']/$num_days; - $cartHotelData[$type_key]['date_diff'][$date_join]['avg_paid_unit_price_tax_excl'] += $cartHotelData[$type_key]['date_diff'][$date_join]['paid_unit_price_tax_excl']; - $cartHotelData[$type_key]['date_diff'][$date_join]['avg_paid_unit_price_tax_incl'] += $cartHotelData[$type_key]['date_diff'][$date_join]['paid_unit_price_tax_incl']; - $cartHotelData[$type_key]['date_diff'][$date_join]['amount_tax_incl'] += $data_v['total_price_tax_incl']; - $cartHotelData[$type_key]['date_diff'][$date_join]['amount_tax_excl'] += $data_v['total_price_tax_excl']; - $cartHotelData[$type_key]['date_diff'][$date_join]['is_backorder'] = $data_v['is_back_order']; - if ($data_v['is_back_order']) { - $anyBackOrder = 1; - } - if ($data_v['is_refunded']) { - $cartHotelData[$type_key]['date_diff'][$date_join]['count_refunded'] += 1; - } + + if (isset($cartHotelData[$type_key]['date_diff'][$date_join])) { + $cartHotelData[$type_key]['date_diff'][$date_join]['num_rm'] += 1; + + $num_days = $cartHotelData[$type_key]['date_diff'][$date_join]['num_days']; + $var_quant = (int) $cartHotelData[$type_key]['date_diff'][$date_join]['num_rm']; + + $cartHotelData[$type_key]['date_diff'][$date_join]['adults'] += $data_v['adults']; + $cartHotelData[$type_key]['date_diff'][$date_join]['children'] += $data_v['children']; + + $cartHotelData[$type_key]['date_diff'][$date_join]['paid_unit_price_tax_excl'] = $data_v['total_price_tax_excl']/$num_days; + $cartHotelData[$type_key]['date_diff'][$date_join]['paid_unit_price_tax_incl'] = $data_v['total_price_tax_incl']/$num_days; + $cartHotelData[$type_key]['date_diff'][$date_join]['avg_paid_unit_price_tax_excl'] += $cartHotelData[$type_key]['date_diff'][$date_join]['paid_unit_price_tax_excl']; + $cartHotelData[$type_key]['date_diff'][$date_join]['avg_paid_unit_price_tax_incl'] += $cartHotelData[$type_key]['date_diff'][$date_join]['paid_unit_price_tax_incl']; + $cartHotelData[$type_key]['date_diff'][$date_join]['amount_tax_incl'] += $data_v['total_price_tax_incl']; + $cartHotelData[$type_key]['date_diff'][$date_join]['amount_tax_excl'] += $data_v['total_price_tax_excl']; + $cartHotelData[$type_key]['date_diff'][$date_join]['is_backorder'] = $data_v['is_back_order']; + if ($data_v['is_back_order']) { + $anyBackOrder = 1; + } + + if ($refundReqBookings && in_array($data_v['id'], $refundReqBookings) && $data_v['is_refunded']) { if ($data_v['is_cancelled']) { $cartHotelData[$type_key]['date_diff'][$date_join]['count_cancelled'] += 1; - $cartHotelData[$type_key]['date_diff'][$date_join]['count_refunded'] -= 1; - } - } else { - $num_days = $objBookingDetail->getNumberOfDays($data_v['date_from'], $data_v['date_to']); - $cartHotelData[$type_key]['date_diff'][$date_join]['num_rm'] = 1; - $cartHotelData[$type_key]['date_diff'][$date_join]['data_form'] = $data_v['date_from']; - $cartHotelData[$type_key]['date_diff'][$date_join]['data_to'] = $data_v['date_to']; - $cartHotelData[$type_key]['date_diff'][$date_join]['num_days'] = $num_days; - $cartHotelData[$type_key]['date_diff'][$date_join]['adults'] = $data_v['adults']; - $cartHotelData[$type_key]['date_diff'][$date_join]['children'] = $data_v['children']; - - $cartHotelData[$type_key]['date_diff'][$date_join]['paid_unit_price_tax_excl'] = $data_v['total_price_tax_excl']/$num_days; - $cartHotelData[$type_key]['date_diff'][$date_join]['paid_unit_price_tax_incl'] = $data_v['total_price_tax_incl']/$num_days; - $cartHotelData[$type_key]['date_diff'][$date_join]['avg_paid_unit_price_tax_excl'] = $cartHotelData[$type_key]['date_diff'][$date_join]['paid_unit_price_tax_excl']; - $cartHotelData[$type_key]['date_diff'][$date_join]['avg_paid_unit_price_tax_incl'] = $cartHotelData[$type_key]['date_diff'][$date_join]['paid_unit_price_tax_incl']; - $cartHotelData[$type_key]['date_diff'][$date_join]['amount_tax_incl'] = $data_v['total_price_tax_incl']; - $cartHotelData[$type_key]['date_diff'][$date_join]['amount_tax_excl'] = $data_v['total_price_tax_excl']; - $cartHotelData[$type_key]['date_diff'][$date_join]['is_backorder'] = $data_v['is_back_order']; - if ($data_v['is_back_order']) { - $anyBackOrder = 1; - } - $cartHotelData[$type_key]['date_diff'][$date_join]['count_cancelled'] = 0; - $cartHotelData[$type_key]['date_diff'][$date_join]['count_refunded'] = 0; - if ($data_v['is_refunded']) { + } elseif ($bookingRefundDetail && $bookingRefundDetail['refunded'] && $bookingRefundDetail['id_customization']) { $cartHotelData[$type_key]['date_diff'][$date_join]['count_refunded'] += 1; } + } + } else { + $num_days = $objBookingDetail->getNumberOfDays($data_v['date_from'], $data_v['date_to']); + $cartHotelData[$type_key]['date_diff'][$date_join]['num_rm'] = 1; + $cartHotelData[$type_key]['date_diff'][$date_join]['data_form'] = $data_v['date_from']; + $cartHotelData[$type_key]['date_diff'][$date_join]['data_to'] = $data_v['date_to']; + $cartHotelData[$type_key]['date_diff'][$date_join]['num_days'] = $num_days; + $cartHotelData[$type_key]['date_diff'][$date_join]['adults'] = $data_v['adults']; + $cartHotelData[$type_key]['date_diff'][$date_join]['children'] = $data_v['children']; + + $cartHotelData[$type_key]['date_diff'][$date_join]['paid_unit_price_tax_excl'] = $data_v['total_price_tax_excl']/$num_days; + $cartHotelData[$type_key]['date_diff'][$date_join]['paid_unit_price_tax_incl'] = $data_v['total_price_tax_incl']/$num_days; + $cartHotelData[$type_key]['date_diff'][$date_join]['avg_paid_unit_price_tax_excl'] = $cartHotelData[$type_key]['date_diff'][$date_join]['paid_unit_price_tax_excl']; + $cartHotelData[$type_key]['date_diff'][$date_join]['avg_paid_unit_price_tax_incl'] = $cartHotelData[$type_key]['date_diff'][$date_join]['paid_unit_price_tax_incl']; + $cartHotelData[$type_key]['date_diff'][$date_join]['amount_tax_incl'] = $data_v['total_price_tax_incl']; + $cartHotelData[$type_key]['date_diff'][$date_join]['amount_tax_excl'] = $data_v['total_price_tax_excl']; + $cartHotelData[$type_key]['date_diff'][$date_join]['is_backorder'] = $data_v['is_back_order']; + if ($data_v['is_back_order']) { + $anyBackOrder = 1; + } + + $cartHotelData[$type_key]['date_diff'][$date_join]['count_cancelled'] = 0; + $cartHotelData[$type_key]['date_diff'][$date_join]['count_refunded'] = 0; + if ($refundReqBookings && in_array($data_v['id'], $refundReqBookings) && $data_v['is_refunded']) { if ($data_v['is_cancelled']) { $cartHotelData[$type_key]['date_diff'][$date_join]['count_cancelled'] += 1; - $cartHotelData[$type_key]['date_diff'][$date_join]['count_refunded'] -= 1; + } elseif ($bookingRefundDetail && $bookingRefundDetail['refunded'] && $bookingRefundDetail['id_customization']) { + $cartHotelData[$type_key]['date_diff'][$date_join]['count_refunded'] += 1; } } + } - $cartHotelData[$type_key]['date_diff'][$date_join]['hotel_booking_details'][$data_v['id']]['id_htl_booking'] = $data_v['id']; - $cartHotelData[$type_key]['date_diff'][$date_join]['hotel_booking_details'][$data_v['id']]['id_room'] = $data_v['id_room']; - $cartHotelData[$type_key]['date_diff'][$date_join]['hotel_booking_details'][$data_v['id']]['adults'] = $data_v['adults']; - $cartHotelData[$type_key]['date_diff'][$date_join]['hotel_booking_details'][$data_v['id']]['children'] = $data_v['children']; - $cartHotelData[$type_key]['date_diff'][$date_join]['hotel_booking_details'][$data_v['id']]['child_ages'] = $data_v['child_ages']; - $cartHotelData[$type_key]['date_diff'][$date_join]['hotel_booking_details'][$data_v['id']]['is_refunded'] = $data_v['is_refunded']; - $cartHotelData[$type_key]['date_diff'][$date_join]['hotel_booking_details'][$data_v['id']]['is_cancelled'] = $data_v['is_cancelled']; - - $cartHotelData[$type_key]['date_diff'][$date_join]['is_refunded'] = $data_v['is_refunded']; - - $cartHotelData[$type_key]['date_diff'][$date_join]['ids_htl_booking_detail'][] = $data_v['id']; - $cartHotelData[$type_key]['date_diff'][$date_join]['ids_rooms'][] = $data_v['id_room']; - - $cartHotelData[$type_key]['date_diff'][$date_join]['extra_demands'] = $objBookingDemand->getRoomTypeBookingExtraDemands( - $id_order, - $type_value['product_id'], - 0, - $data_v['date_from'], - $data_v['date_to'] - ); - if (empty($cartHotelData[$type_key]['date_diff'][$date_join]['extra_demands_price_ti'])) { - $cartHotelData[$type_key]['date_diff'][$date_join]['extra_demands_price_ti'] = 0; - } - $cartHotelData[$type_key]['date_diff'][$date_join]['extra_demands_price_ti'] += $extraDemandPriceTI = $objBookingDemand->getRoomTypeBookingExtraDemands( - $id_order, - $type_value['product_id'], - $data_v['id_room'], - $data_v['date_from'], - $data_v['date_to'], - 0, - 1, - 1 - ); - if (empty($cartHotelData[$type_key]['date_diff'][$date_join]['extra_demands_price_te'])) { - $cartHotelData[$type_key]['date_diff'][$date_join]['extra_demands_price_te'] = 0; - } - $cartHotelData[$type_key]['date_diff'][$date_join]['extra_demands_price_te'] += $extraDemandPriceTE = $objBookingDemand->getRoomTypeBookingExtraDemands( - $id_order, - $type_value['product_id'], - $data_v['id_room'], - $data_v['date_from'], - $data_v['date_to'], - 0, - 1, - 0 - ); - $total_demands_price_ti += $extraDemandPriceTI; - $total_demands_price_te += $extraDemandPriceTE; - $cartHotelData[$type_key]['date_diff'][$date_join]['product_price_tax_excl'] = $order_details_obj->unit_price_tax_excl; - $cartHotelData[$type_key]['date_diff'][$date_join]['product_price_tax_incl'] = $order_details_obj->unit_price_tax_incl; - $cartHotelData[$type_key]['date_diff'][$date_join]['product_price_without_reduction_tax_excl'] = $order_details_obj->unit_price_tax_excl + $order_details_obj->reduction_amount_tax_excl; - $cartHotelData[$type_key]['date_diff'][$date_join]['product_price_without_reduction_tax_incl'] = $order_details_obj->unit_price_tax_incl + $order_details_obj->reduction_amount_tax_incl; - - $feature_price_diff = (float)($cartHotelData[$type_key]['date_diff'][$date_join]['product_price_without_reduction_tax_incl'] - $cartHotelData[$type_key]['date_diff'][$date_join]['paid_unit_price_tax_incl']); - $cartHotelData[$type_key]['date_diff'][$date_join]['feature_price_diff'] = $feature_price_diff; - - $cartHotelData[$type_key]['hotel_name'] = $data_v['hotel_name']; - // add additional services products in hotel detail. - $cartHotelData[$type_key]['date_diff'][$date_join]['additional_services'] = $objRoomTypeServiceProductOrderDetail->getroomTypeServiceProducts( - $id_order, - 0, - 0, - $type_value['product_id'], - $data_v['date_from'], - $data_v['date_to'] - ); - - if (empty($cartHotelData[$type_key]['date_diff'][$date_join]['additional_services_price_ti'])) { - $cartHotelData[$type_key]['date_diff'][$date_join]['additional_services_price_ti'] = 0; - } - $cartHotelData[$type_key]['date_diff'][$date_join]['additional_services_price_ti'] += $additionalServicesPriceTI = $objRoomTypeServiceProductOrderDetail->getroomTypeServiceProducts( - $id_order, - 0, - 0, - $type_value['product_id'], - $data_v['date_from'], - $data_v['date_to'], - $data_v['id_room'], - 1, - 1 - ); - if (empty($cartHotelData[$type_key]['date_diff'][$date_join]['additional_services_price_te'])) { - $cartHotelData[$type_key]['date_diff'][$date_join]['additional_services_price_te'] = 0; - } - $cartHotelData[$type_key]['date_diff'][$date_join]['additional_services_price_te'] += $additionalServicesPriceTE = $objRoomTypeServiceProductOrderDetail->getroomTypeServiceProducts( - $id_order, - 0, - 0, - $type_value['product_id'], - $data_v['date_from'], - $data_v['date_to'], - $data_v['id_room'], - 1, - 0 - ); - // get auto added price to be displayed with room price - if (empty($cartHotelData[$type_key]['date_diff'][$date_join]['additional_services_price_auto_add_ti'])) { - $cartHotelData[$type_key]['date_diff'][$date_join]['additional_services_price_auto_add_ti'] = 0; - } - $cartHotelData[$type_key]['date_diff'][$date_join]['additional_services_price_auto_add_ti'] += $objRoomTypeServiceProductOrderDetail->getroomTypeServiceProducts( - $id_order, - 0, - 0, - $type_value['product_id'], - $data_v['date_from'], - $data_v['date_to'], - $data_v['id_room'], - 1, - 1, - 1, - Product::PRICE_ADDITION_TYPE_WITH_ROOM - ); - if (empty($cartHotelData[$type_key]['date_diff'][$date_join]['additional_services_price_auto_add_te'])) { - $cartHotelData[$type_key]['date_diff'][$date_join]['additional_services_price_auto_add_te'] = 0; - } - $cartHotelData[$type_key]['date_diff'][$date_join]['additional_services_price_auto_add_te'] += $objRoomTypeServiceProductOrderDetail->getroomTypeServiceProducts( - $id_order, - 0, - 0, - $type_value['product_id'], - $data_v['date_from'], - $data_v['date_to'], - $data_v['id_room'], - 1, - 0, - 1, - Product::PRICE_ADDITION_TYPE_WITH_ROOM - ); + $cartHotelData[$type_key]['date_diff'][$date_join]['hotel_booking_details'][$data_v['id']]['id_htl_booking'] = $data_v['id']; + $cartHotelData[$type_key]['date_diff'][$date_join]['hotel_booking_details'][$data_v['id']]['id_room'] = $data_v['id_room']; + $cartHotelData[$type_key]['date_diff'][$date_join]['hotel_booking_details'][$data_v['id']]['adults'] = $data_v['adults']; + $cartHotelData[$type_key]['date_diff'][$date_join]['hotel_booking_details'][$data_v['id']]['children'] = $data_v['children']; + $cartHotelData[$type_key]['date_diff'][$date_join]['hotel_booking_details'][$data_v['id']]['child_ages'] = $data_v['child_ages']; + $cartHotelData[$type_key]['date_diff'][$date_join]['hotel_booking_details'][$data_v['id']]['is_refunded'] = $data_v['is_refunded']; + $cartHotelData[$type_key]['date_diff'][$date_join]['hotel_booking_details'][$data_v['id']]['is_cancelled'] = $data_v['is_cancelled']; + $cartHotelData[$type_key]['date_diff'][$date_join]['hotel_booking_details'][$data_v['id']]['id_status'] = $data_v['id_status']; + + $cartHotelData[$type_key]['date_diff'][$date_join]['hotel_booking_details'][$data_v['id']]['refund_denied'] = 0; + if ($bookingRefundDetail && $bookingRefundDetail['refunded'] && !$bookingRefundDetail['id_customization']) { + $cartHotelData[$type_key]['date_diff'][$date_join]['hotel_booking_details'][$data_v['id']]['refund_denied'] = 1; } - // calculate averages now - foreach ($cartHotelData[$type_key]['date_diff'] as $key => &$value) { - $value['avg_paid_unit_price_tax_excl'] = Tools::ps_round($value['avg_paid_unit_price_tax_excl'] / $value['num_rm'], 6); - $value['avg_paid_unit_price_tax_incl'] = Tools::ps_round($value['avg_paid_unit_price_tax_incl'] / $value['num_rm'], 6); - $value['avg_price_diff_tax_excl'] = abs(Tools::ps_round($value['avg_paid_unit_price_tax_excl'] - $value['product_price_tax_excl'], 6)); - $value['avg_price_diff_tax_incl'] = abs(Tools::ps_round($value['avg_paid_unit_price_tax_incl'] - $value['product_price_tax_incl'], 6)); + $cartHotelData[$type_key]['date_diff'][$date_join]['is_refunded'] = $data_v['is_refunded']; + + $cartHotelData[$type_key]['date_diff'][$date_join]['ids_htl_booking_detail'][] = $data_v['id']; + $cartHotelData[$type_key]['date_diff'][$date_join]['ids_rooms'][] = $data_v['id_room']; + + $cartHotelData[$type_key]['date_diff'][$date_join]['extra_demands'] = $objBookingDemand->getRoomTypeBookingExtraDemands( + $id_order, + $type_value['product_id'], + 0, + $data_v['date_from'], + $data_v['date_to'] + ); + if (empty($cartHotelData[$type_key]['date_diff'][$date_join]['extra_demands_price_ti'])) { + $cartHotelData[$type_key]['date_diff'][$date_join]['extra_demands_price_ti'] = 0; } - } else if ($type_value['product_service_type'] == Product::SERVICE_PRODUCT_WITH_ROOMTYPE) { - if ($type_value['product_auto_add'] && $type_value['product_price_addition_type'] == Product::PRICE_ADDITION_TYPE_INDEPENDENT) { - $total_convenience_fee_ti += $objRoomTypeServiceProductOrderDetail->getroomTypeServiceProducts( - $id_order, - $type_value['product_id'], - 0, - 0, - 0, - 0, - 0, - 1, - 1, - 1 - ); - $total_convenience_fee_te += $objRoomTypeServiceProductOrderDetail->getroomTypeServiceProducts( - $id_order, - $type_value['product_id'], - 0, - 0, - 0, - 0, - 0, - 1, - 0, - 1 - ); + $cartHotelData[$type_key]['date_diff'][$date_join]['extra_demands_price_ti'] += $extraDemandPriceTI = $objBookingDemand->getRoomTypeBookingExtraDemands( + $id_order, + $type_value['product_id'], + $data_v['id_room'], + $data_v['date_from'], + $data_v['date_to'], + 0, + 1, + 1 + ); + if (empty($cartHotelData[$type_key]['date_diff'][$date_join]['extra_demands_price_te'])) { + $cartHotelData[$type_key]['date_diff'][$date_join]['extra_demands_price_te'] = 0; } - } else { - // get all products that are independent. - if ($type_value['product_service_type'] == Product::SERVICE_PRODUCT_WITHOUT_ROOMTYPE) { - $product = new Product($type_value['product_id'], false, $this->context->language->id); - $cover_image_arr = $product->getCover($type_value['product_id']); - - if (!empty($cover_image_arr)) { - $type_value['cover_img'] = $this->context->link->getImageLink($product->link_rewrite, $product->id.'-'.$cover_image_arr['id_image'], 'small_default'); - } else { - $type_value['cover_img'] = $this->context->link->getImageLink($product->link_rewrite, $this->context->language->iso_code.'-default', 'small_default'); - } - $cartServiceProducts[] = $type_value; + $cartHotelData[$type_key]['date_diff'][$date_join]['extra_demands_price_te'] += $extraDemandPriceTE = $objBookingDemand->getRoomTypeBookingExtraDemands( + $id_order, + $type_value['product_id'], + $data_v['id_room'], + $data_v['date_from'], + $data_v['date_to'], + 0, + 1, + 0 + ); + $total_demands_price_ti += $extraDemandPriceTI; + $total_demands_price_te += $extraDemandPriceTE; + $cartHotelData[$type_key]['date_diff'][$date_join]['product_price_tax_excl'] = $order_details_obj->unit_price_tax_excl; + $cartHotelData[$type_key]['date_diff'][$date_join]['product_price_tax_incl'] = $order_details_obj->unit_price_tax_incl; + $cartHotelData[$type_key]['date_diff'][$date_join]['product_price_without_reduction_tax_excl'] = $order_details_obj->unit_price_tax_excl + $order_details_obj->reduction_amount_tax_excl; + $cartHotelData[$type_key]['date_diff'][$date_join]['product_price_without_reduction_tax_incl'] = $order_details_obj->unit_price_tax_incl + $order_details_obj->reduction_amount_tax_incl; + + $feature_price_diff = (float)($cartHotelData[$type_key]['date_diff'][$date_join]['product_price_without_reduction_tax_incl'] - $cartHotelData[$type_key]['date_diff'][$date_join]['paid_unit_price_tax_incl']); + $cartHotelData[$type_key]['date_diff'][$date_join]['feature_price_diff'] = $feature_price_diff; + + $cartHotelData[$type_key]['hotel_name'] = $data_v['hotel_name']; + // add additional services products in hotel detail. + $cartHotelData[$type_key]['date_diff'][$date_join]['additional_services'] = $objRoomTypeServiceProductOrderDetail->getroomTypeServiceProducts( + $id_order, + 0, + 0, + $type_value['product_id'], + $data_v['date_from'], + $data_v['date_to'] + ); + + if (empty($cartHotelData[$type_key]['date_diff'][$date_join]['additional_services_price_ti'])) { + $cartHotelData[$type_key]['date_diff'][$date_join]['additional_services_price_ti'] = 0; + } + $cartHotelData[$type_key]['date_diff'][$date_join]['additional_services_price_ti'] += $additionalServicesPriceTI = $objRoomTypeServiceProductOrderDetail->getroomTypeServiceProducts( + $id_order, + 0, + 0, + $type_value['product_id'], + $data_v['date_from'], + $data_v['date_to'], + $data_v['id_room'], + 1, + 1 + ); + if (empty($cartHotelData[$type_key]['date_diff'][$date_join]['additional_services_price_te'])) { + $cartHotelData[$type_key]['date_diff'][$date_join]['additional_services_price_te'] = 0; + } + $cartHotelData[$type_key]['date_diff'][$date_join]['additional_services_price_te'] += $additionalServicesPriceTE = $objRoomTypeServiceProductOrderDetail->getroomTypeServiceProducts( + $id_order, + 0, + 0, + $type_value['product_id'], + $data_v['date_from'], + $data_v['date_to'], + $data_v['id_room'], + 1, + 0 + ); + // get auto added price to be displayed with room price + if (empty($cartHotelData[$type_key]['date_diff'][$date_join]['additional_services_price_auto_add_ti'])) { + $cartHotelData[$type_key]['date_diff'][$date_join]['additional_services_price_auto_add_ti'] = 0; } + $cartHotelData[$type_key]['date_diff'][$date_join]['additional_services_price_auto_add_ti'] += $objRoomTypeServiceProductOrderDetail->getroomTypeServiceProducts( + $id_order, + 0, + 0, + $type_value['product_id'], + $data_v['date_from'], + $data_v['date_to'], + $data_v['id_room'], + 1, + 1, + 1, + Product::PRICE_ADDITION_TYPE_WITH_ROOM + ); + if (empty($cartHotelData[$type_key]['date_diff'][$date_join]['additional_services_price_auto_add_te'])) { + $cartHotelData[$type_key]['date_diff'][$date_join]['additional_services_price_auto_add_te'] = 0; + } + $cartHotelData[$type_key]['date_diff'][$date_join]['additional_services_price_auto_add_te'] += $objRoomTypeServiceProductOrderDetail->getroomTypeServiceProducts( + $id_order, + 0, + 0, + $type_value['product_id'], + $data_v['date_from'], + $data_v['date_to'], + $data_v['id_room'], + 1, + 0, + 1, + Product::PRICE_ADDITION_TYPE_WITH_ROOM + ); + } + + // calculate averages now + foreach ($cartHotelData[$type_key]['date_diff'] as $key => &$value) { + $value['avg_paid_unit_price_tax_excl'] = Tools::ps_round($value['avg_paid_unit_price_tax_excl'] / $value['num_rm'], 6); + $value['avg_paid_unit_price_tax_incl'] = Tools::ps_round($value['avg_paid_unit_price_tax_incl'] / $value['num_rm'], 6); + + $value['avg_price_diff_tax_excl'] = abs(Tools::ps_round($value['avg_paid_unit_price_tax_excl'] - $value['product_price_tax_excl'], 6)); + $value['avg_price_diff_tax_incl'] = abs(Tools::ps_round($value['avg_paid_unit_price_tax_incl'] - $value['product_price_tax_incl'], 6)); + } + } else if ($type_value['product_service_type'] == Product::SERVICE_PRODUCT_WITH_ROOMTYPE) { + if ($type_value['product_auto_add'] && $type_value['product_price_addition_type'] == Product::PRICE_ADDITION_TYPE_INDEPENDENT) { + $total_convenience_fee_ti += $objRoomTypeServiceProductOrderDetail->getroomTypeServiceProducts( + $id_order, + $type_value['product_id'], + 0, + 0, + 0, + 0, + 0, + 1, + 1, + 1 + ); + $total_convenience_fee_te += $objRoomTypeServiceProductOrderDetail->getroomTypeServiceProducts( + $id_order, + $type_value['product_id'], + 0, + 0, + 0, + 0, + 0, + 1, + 0, + 1 + ); } + } else { + // get all products that are independent. + if ($type_value['product_service_type'] == Product::SERVICE_PRODUCT_WITHOUT_ROOMTYPE) { + $product = new Product($type_value['product_id'], false, $this->context->language->id); + $cover_image_arr = $product->getCover($type_value['product_id']); - $roomTypes[$type_value['id_product']] = $type_value; + if (!empty($cover_image_arr)) { + $type_value['cover_img'] = $this->context->link->getImageLink($product->link_rewrite, $product->id.'-'.$cover_image_arr['id_image'], 'small_default'); + } else { + $type_value['cover_img'] = $this->context->link->getImageLink($product->link_rewrite, $this->context->language->iso_code.'-default', 'small_default'); + } + $cartServiceProducts[] = $type_value; + } } - $redirectTermsLink = $this->context->link->getCMSLink(new CMS(3, $this->context->language->id), null, $this->context->language->id); + $roomTypes[$type_value['id_product']] = $type_value; } - $objHotelBookingDetail = new HotelBookingDetail(); - $htlBookingDetail = $objHotelBookingDetail->getOrderCurrentDataByOrderId($order->id); - $idHotel = HotelBookingDetail::getIdHotelByIdOrder($order->id); - $objHotelBranchInformation = new HotelBranchInformation($idHotel, $this->context->language->id); - $hotelAddressInfo = HotelBranchInformation::getAddress($idHotel); + $redirectTermsLink = $this->context->link->getCMSLink(new CMS(3, $this->context->language->id), null, $this->context->language->id); + } - $objHotelBranchRefundRules = new HotelBranchRefundRules(); - $hotelRefundRules = $objHotelBranchRefundRules->getHotelRefundRules($idHotel, 0, 1); + $objHotelBookingDetail = new HotelBookingDetail(); + $htlBookingDetail = $objHotelBookingDetail->getOrderCurrentDataByOrderId($order->id); + $idHotel = HotelBookingDetail::getIdHotelByIdOrder($order->id); + $objHotelBranchInformation = new HotelBranchInformation($idHotel, $this->context->language->id); + $hotelAddressInfo = HotelBranchInformation::getAddress($idHotel); - $this->context->smarty->assign( - array( - 'id_cms_refund_policy' => Configuration::get('WK_GLOBAL_REFUND_POLICY_CMS'), - 'THEME_DIR' => _THEME_DIR_, - 'total_convenience_fee_ti' => $total_convenience_fee_ti, - 'total_convenience_fee_te' => $total_convenience_fee_te, - 'total_demands_price_ti' => $total_demands_price_ti, - 'total_demands_price_te' => $total_demands_price_te, - 'any_back_order' => $anyBackOrder, - 'shw_bo_msg' => Configuration::get('WK_SHOW_MSG_ON_BO'), - 'back_ord_msg' => Configuration::get('WK_BO_MESSAGE'), - 'order_has_invoice' => $order->hasInvoice(), - 'cart_htl_data' => $cartHotelData, - 'cart_service_products' => $cartServiceProducts, - 'obj_hotel_branch_information' => $objHotelBranchInformation, - 'hotel_address_info' => $hotelAddressInfo, - 'hotel_refund_rules' => $hotelRefundRules, - ) - ); - // } + $objHotelBranchRefundRules = new HotelBranchRefundRules(); + $hotelRefundRules = $objHotelBranchRefundRules->getHotelRefundRules($idHotel, 0, 1); - $objOrderReturn = new OrderReturn(); - $refundedAmount = 0; - if ($refundReqBookings = $objOrderReturn->getOrderRefundRequestedBookings($order->id, 0, 1)) { - $refundedAmount = $objOrderReturn->getRefundedAmount($order->id); - } + $this->context->smarty->assign( + array( + 'id_cms_refund_policy' => Configuration::get('WK_GLOBAL_REFUND_POLICY_CMS'), + 'THEME_DIR' => _THEME_DIR_, + 'total_convenience_fee_ti' => $total_convenience_fee_ti, + 'total_convenience_fee_te' => $total_convenience_fee_te, + 'total_demands_price_ti' => $total_demands_price_ti, + 'total_demands_price_te' => $total_demands_price_te, + 'any_back_order' => $anyBackOrder, + 'shw_bo_msg' => Configuration::get('WK_SHOW_MSG_ON_BO'), + 'back_ord_msg' => Configuration::get('WK_BO_MESSAGE'), + 'order_has_invoice' => $order->hasInvoice(), + 'cart_htl_data' => $cartHotelData, + 'cart_service_products' => $cartServiceProducts, + 'obj_hotel_branch_information' => $objHotelBranchInformation, + 'hotel_address_info' => $hotelAddressInfo, + 'hotel_refund_rules' => $hotelRefundRules, + ) + ); $this->context->smarty->assign( array( @@ -424,7 +433,7 @@ public function initContent() 'refund_allowed' => (int) $order->isReturnable(), 'returns' => OrderReturn::getOrdersReturn($order->id_customer, $order->id), 'refundReqBookings' => $refundReqBookings, - 'completeRefundRequestOrCancel' => $order->hasCompletelyRefunded(Order::ORDER_COMPLETE_CANCELLATION_OR_REFUND_REQUEST_FLAG), + 'completeRefundRequestOrCancel' => $order->hasCompletelyRefunded(0, 1), 'refundedAmount' => $refundedAmount, 'shop_name' => strval(Configuration::get('PS_SHOP_NAME')), 'order' => $order, @@ -457,6 +466,9 @@ public function initContent() 'use_tax' => Configuration::get('PS_TAX'), 'group_use_tax' => (Group::getPriceDisplayMethod($customer->id_default_group) == PS_TAX_INC), 'reorderingAllowed' => !(bool) Configuration::get('PS_DISALLOW_HISTORY_REORDERING'), + 'ROOM_STATUS_ALLOTED' => HotelBookingDetail::STATUS_ALLOTED, + 'ROOM_STATUS_CHECKED_IN' => HotelBookingDetail::STATUS_CHECKED_IN, + 'ROOM_STATUS_CHECKED_OUT' => HotelBookingDetail::STATUS_CHECKED_OUT, ) ); @@ -563,6 +575,12 @@ public function displayAjaxSubmitRefundRequest() break; } + // the room has already been checked in/checked out, room will not be able to be cancelled by the customer + if ($objHotelBookingDetail->id_status != HotelBookingDetail::STATUS_ALLOTED) { + $this->errors[] = Tools::displayError('Some selected rooms have already been checked-in/checked-out.'); + break; + } + if (OrderReturn::getOrdersReturnDetail($objOrder->id, 0, $idHtlBooking)) { $this->errors[] = Tools::displayError('Some selected rooms have already been requested for cancellation.'); break; @@ -571,66 +589,61 @@ public function displayAjaxSubmitRefundRequest() } if (!count($this->errors)) { - if ((int) $objOrder->total_paid_real == 0) { + // create refund request + $objOrderReturn = new OrderReturn(); + $objOrderReturn->id_customer = $objOrder->id_customer; + $objOrderReturn->id_order = $objOrder->id; + $objOrderReturn->state = 0; + $objOrderReturn->by_admin = 0; + $objOrderReturn->question = $cancellationReason; + $objOrderReturn->refunded_amount = 0; + $objOrderReturn->save(); + if ($objOrderReturn->id) { foreach ($idsHtlBooking as $idHtlBooking) { $objHtlBooking = new HotelBookingDetail($idHtlBooking); - $objHtlBooking->save(); + $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->refunded_amount = 0; + if (!$objOrder->getCartRules() && $objOrder->getTotalPaid() <= 0) { + $objOrderReturnDetail->id_customization = 1; + } + $objOrderReturnDetail->save(); } } - // if amount paid is > 0 then create refund request else cancel the booking directly - if ($objOrder->getTotalPaid() > 0) { - $objOrderReturn = new OrderReturn(); - $objOrderReturn->id_customer = $objOrder->id_customer; - $objOrderReturn->id_order = $objOrder->id; - $objOrderReturn->state = 0; - $objOrderReturn->by_admin = 0; - $objOrderReturn->question = $cancellationReason; - $objOrderReturn->save(); - if ($objOrderReturn->id) { - foreach ($idsHtlBooking as $idHtlBooking) { - $objHotelBookingDetail = new HotelBookingDetail($idHtlBooking); - $numDays = $objHotelBookingDetail->getNumberOfDays( - $objHotelBookingDetail->date_from, - $objHotelBookingDetail->date_to - ); + // Emails to customer, superadmin and employees on refund request state change + $objOrderReturn->changeIdOrderReturnState(Configuration::get('PS_ORS_PENDING')); - $objOrderReturnDetail = new OrderReturnDetail(); - $objOrderReturnDetail->id_order_return = $objOrderReturn->id; - $objOrderReturnDetail->id_order_detail = $objHotelBookingDetail->id_order_detail; - $objOrderReturnDetail->product_quantity = $numDays; - $objOrderReturnDetail->id_htl_booking = $idHtlBooking; - $objOrderReturnDetail->save(); - } - } - - // Emails to customer, superadmin and employees on refund request state change - $objOrderReturn->changeIdOrderReturnState(Configuration::get('PS_ORS_PENDING')); - } else { - // cancel the booking directly + if (!$objOrder->getCartRules() && $objOrder->getTotalPaid() <= 0) { + // Process refund in booking tables foreach ($idsHtlBooking as $idHtlBooking) { - $objHotelBookingDetail = new HotelBookingDetail($idHtlBooking); - if (!$objHotelBookingDetail->processRefundInBookingTables()) { - $this->errors[] = Tools::displayError('Something went wrong. Please try later.'); - } else { - // set the message for the cancellation - $message = Tools::displayError(sprintf( - "1 room from %s has been cancelled by hotel.\nReason: %s", - $objHotelBookingDetail->room_type_name, - $cancellationReason - )); - - $objHotelBookingDetail->setBookingCancellationMessage($message); + $objHtlBooking = new HotelBookingDetail($idHtlBooking); + if (!$objHtlBooking->processRefundInBookingTables()) { + $this->errors[] = Tools::displayError('An error occurred while cancelling the booking.'); } } + // complete the booking refund directly in the refund request + $objOrderReturn->changeIdOrderReturnState(Configuration::get('PS_ORS_REFUNDED')); + + // if all bookings are getting cancelled/Refunded then Cancel/Refund the order also + $idOrderState = 0; + if ($objOrder->hasCompletelyRefunded(Order::ORDER_COMPLETE_REFUND_FLAG)) { + $idOrderState = Configuration::get('PS_OS_REFUND'); + } elseif ($objOrder->hasCompletelyRefunded(Order::ORDER_COMPLETE_CANCELLATION_FLAG)) { + $idOrderState = Configuration::get('PS_OS_CANCELED'); + } - // if all bookings are getting cancelled then cancel the order also - if ($objOrder->hasCompletelyRefunded(Order::ORDER_COMPLETE_CANCELLATION_FLAG)) { + if ($idOrderState) { $objOrderHistory = new OrderHistory(); $objOrderHistory->id_order = (int)$objOrder->id; - $idOrderState = Configuration::get('PS_OS_CANCELED'); - $useExistingPayment = false; if (!$objOrder->hasInvoice()) { $useExistingPayment = true; @@ -807,4 +820,4 @@ public function setMedia() } } } -} +} \ No newline at end of file diff --git a/controllers/front/OrderOpcController.php b/controllers/front/OrderOpcController.php index 95a0adceb..1730af000 100644 --- a/controllers/front/OrderOpcController.php +++ b/controllers/front/OrderOpcController.php @@ -591,7 +591,6 @@ public function initContent() if (!empty($cartProducts)) { if ($cartBookingInfo = HotelCartBookingData::getHotelCartBookingData()) { - // ddd($cartBookingInfo); $this->context->smarty->assign('cart_htl_data', $cartBookingInfo); } $objHotelServiceProductCartDetail = new HotelServiceProductCartDetail(); diff --git a/controllers/front/OrderReturnController.php b/controllers/front/OrderReturnController.php index 7a57ef229..4fe62ec09 100644 --- a/controllers/front/OrderReturnController.php +++ b/controllers/front/OrderReturnController.php @@ -50,22 +50,23 @@ public function initContent() $objOrder = new Order($objOrderReturn->id_order); $orderCurrency = new Currency($objOrder->id_currency); - $refundReqBookings = $objOrderReturn->getOrderRefundRequestedBookings($objOrderReturn->id_order, $objOrderReturn->id, 0, 1); - $isCanceled = false; + $refundReqBookings = $objOrderReturn->getOrderRefundRequestedBookings($objOrderReturn->id_order, $objOrderReturn->id); + $isCanceledBookings = false; if (count(array_unique(array_column($refundReqBookings, 'is_cancelled'))) === 1 && array_unique(array_column($refundReqBookings, 'is_cancelled'))[0] != 0 ) { - $isCanceled = true; + $isCanceledBookings = true; } $voucher = ''; if (Validate::isLoadedObject($objCartRule = new CartRule($objOrderReturn->id_return_type))) { $voucher = $objCartRule->name[$this->context->language->id]; } + $this->context->smarty->assign( array ( 'orderReturnInfo' => (array)$objOrderReturn, 'refundReqBookings' => $refundReqBookings, - 'isCanceled' => $isCanceled, + 'isCanceledBookings' => $isCanceledBookings, 'orderInfo' => (array) $objOrder, 'orderCurrency' => (array) $orderCurrency, 'currentStateInfo' => (array) new OrderReturnState($objOrderReturn->state, diff --git a/js/admin/orders.js b/js/admin/orders.js index 097961a27..109dad2b4 100644 --- a/js/admin/orders.js +++ b/js/admin/orders.js @@ -1233,6 +1233,14 @@ function setRoomTypeGuestOccupancy(booking_occupancy_wrapper) var flagRefund = ''; $(document).ready(function() { + // when change order state to cancel or refund then show modal of bookings cancellation + $(document).on('change', '#id_order_state', function(e) { + if ($(this).val() == PS_OS_CANCELED || $(this).val() == PS_OS_REFUND) { + e.preventDefault(); + CancelRoomBookingModal.show(); + } + }); + $('#desc-order-partial_refund').click(function() { $('.cancel_product_change_link:visible').trigger('click'); if (flagRefund == 'partial') { diff --git a/modules/hotelreservationsystem/classes/HotelBookingDetail.php b/modules/hotelreservationsystem/classes/HotelBookingDetail.php index e7abb8d20..b35f70a95 100644 --- a/modules/hotelreservationsystem/classes/HotelBookingDetail.php +++ b/modules/hotelreservationsystem/classes/HotelBookingDetail.php @@ -2196,7 +2196,7 @@ public function getOrderFormatedBookinInfoByIdOrder($id_order) $order_detail_data[$key]['child_ages'] = json_decode($value['child_ages']); // Check if this booking as any refund history then enter refund data - if ($refundInfo = OrderReturnCore::getOrdersReturnDetail($id_order, 0, $value['id'])) { + if ($refundInfo = OrderReturn::getOrdersReturnDetail($id_order, 0, $value['id'])) { $order_detail_data[$key]['refund_info'] = reset($refundInfo); } } @@ -2870,9 +2870,12 @@ public function processRefundInBookingTables() ); $objOrder = new Order($this->id_order); $orderTotalPaid = $objOrder->getTotalPaid(); + $orderDiscounts = $objOrder->getCartRules(); + + $hasOrderDiscountOrPayment = ((float)$orderTotalPaid > 0 || $orderDiscounts) ? true : false; // things to do if order is not paid - if ((float) $orderTotalPaid <= 0) { + if (!$hasOrderDiscountOrPayment) { $objHotelBookingDemands = new HotelBookingDemands(); $objRoomTypeServiceProductOrderDetail = new RoomTypeServiceProductOrderDetail(); @@ -2919,8 +2922,14 @@ public function processRefundInBookingTables() $objOrderDetail->product_quantity_refunded = $objOrderDetail->product_quantity; } - $objOrderDetail->total_price_tax_excl -= Tools::ps_round((float) $objRoomTypeServiceProductOrderDetail->total_price_tax_excl, 6); - $objOrderDetail->total_price_tax_incl -= Tools::ps_round((float) $objRoomTypeServiceProductOrderDetail->total_price_tax_incl, 6); + $objOrderDetail->total_price_tax_excl = Tools::ps_round( + ($objOrderDetail->total_price_tax_excl - $objRoomTypeServiceProductOrderDetail->total_price_tax_excl), + 6 + ); + $objOrderDetail->total_price_tax_incl = Tools::ps_round( + ($objOrderDetail->total_price_tax_incl - $objRoomTypeServiceProductOrderDetail->total_price_tax_incl), + 6 + ); $objOrderDetail->save(); } @@ -2945,16 +2954,47 @@ public function processRefundInBookingTables() $objOrderDetail->product_quantity_refunded = $objOrderDetail->product_quantity; } - if ((float) $orderTotalPaid <= 0) { + if (!$hasOrderDiscountOrPayment) { // reduce room amount from order and order detail - $objOrderDetail->total_price_tax_incl -= Tools::ps_round((float) $this->total_price_tax_incl, 6); - $objOrderDetail->total_price_tax_excl -= Tools::ps_round((float) $this->total_price_tax_excl, 6); + $objOrderDetail->total_price_tax_incl = Tools::ps_round( + ($objOrderDetail->total_price_tax_incl - $this->total_price_tax_incl), + 6 + ); + $objOrderDetail->total_price_tax_excl = Tools::ps_round( + ($objOrderDetail->total_price_tax_excl - $this->total_price_tax_excl), + 6 + ); if (Validate::isLoadedObject($objOrder = new Order($this->id_order))) { - $objOrder->total_paid -= $reduction_amount['total_price_tax_incl']; - $objOrder->total_paid_tax_excl -= Tools::ps_round((float) $reduction_amount['total_price_tax_excl'], 6); - $objOrder->total_paid_tax_incl -= Tools::ps_round((float) $reduction_amount['total_price_tax_incl'], 6); - $objOrder->total_products -= Tools::ps_round((float) $reduction_amount['total_products_tax_excl'], 6); - $objOrder->total_products_wt -= Tools::ps_round((float) $reduction_amount['total_products_tax_incl'], 6); + $objOrder->total_paid = Tools::ps_round( + ($objOrder->total_paid - $reduction_amount['total_price_tax_incl']), + 6 + ); + $objOrder->total_paid = $objOrder->total_paid > 0 ? $objOrder->total_paid : 0; + + $objOrder->total_paid_tax_excl = Tools::ps_round( + ($objOrder->total_paid_tax_excl - $reduction_amount['total_price_tax_excl']), + 6 + ); + $objOrder->total_paid_tax_excl = $objOrder->total_paid_tax_excl > 0 ? $objOrder->total_paid_tax_excl : 0; + + $objOrder->total_paid_tax_incl = Tools::ps_round( + ($objOrder->total_paid_tax_incl - $reduction_amount['total_price_tax_incl']), + 6 + ); + $objOrder->total_paid_tax_incl = $objOrder->total_paid_tax_incl > 0 ? $objOrder->total_paid_tax_incl : 0; + + $objOrder->total_products = Tools::ps_round( + ($objOrder->total_products - $reduction_amount['total_products_tax_excl']), + 6 + ); + $objOrder->total_products = $objOrder->total_products > 0 ? $objOrder->total_products : 0; + + $objOrder->total_products_wt = Tools::ps_round( + ($objOrder->total_products_wt - $reduction_amount['total_products_tax_incl']), + 6 + ); + $objOrder->total_products_wt = $objOrder->total_products_wt > 0 ? $objOrder->total_products_wt : 0; + $objOrder->save(); } } @@ -2964,7 +3004,7 @@ public function processRefundInBookingTables() // as refund is completed then set the booking as refunded $this->is_refunded = 1; - if ((float) $orderTotalPaid <= 0) { + if (!$hasOrderDiscountOrPayment) { // Reduce room amount from htl_booking_detail $this->is_cancelled = 1; $this->total_price_tax_excl = 0; @@ -2979,66 +3019,6 @@ public function processRefundInBookingTables() return false; } - public function setBookingCancellationMessage($message, $byAdmin = 0) - { - if (Validate::isLoadedObject($this)) { - // First save the message for the admin for the refund - $objectMessage = new Message(); - $objectMessage->message = $message; - $objectMessage->id_cart = (int)$this->id_cart; - $objectMessage->id_customer = (int)($this->id_customer); - $objectMessage->id_order = (int)$this->id_order; - $objectMessage->private = 1; - - // If cancelled by admin then set the employee id who is doing this cancellation else put 0 - $context = Context::getContext(); - if ($byAdmin) { - $objectMessage->id_employee = (int)$context->employee->id; - } else { - $objectMessage->id_employee = 0; - } - - $objectMessage->add(); - - // save this message for the customer - $objCustomer = new Customer($this->id_customer); - $idCustomerThread = CustomerThread::getIdCustomerThreadByEmailAndIdOrder($objCustomer->email, $this->id_order); - if (!$idCustomerThread) { - $objCustomerThread = new CustomerThread(); - $objCustomerThread->id_contact = 0; - $objCustomerThread->id_customer = (int)$this->id_customer; - $objCustomerThread->id_shop = (int)$context->shop->id; - $objCustomerThread->id_order = (int)$this->id_order; - $objCustomerThread->id_lang = (int)$context->language->id; - $objCustomerThread->email = $objCustomer->email; - $objCustomerThread->status = 'open'; - $objCustomerThread->token = Tools::passwdGen(12); - $objCustomerThread->add(); - } else { - $objCustomerThread = new CustomerThread((int)$idCustomerThread); - } - - $objCustomerMessage = new CustomerMessage(); - $objCustomerMessage->id_customer_thread = $objCustomerThread->id; - - // If cancelled by admin then set the employee id who is doing this cancellation else put 0 - if ($byAdmin) { - $objCustomerMessage->id_employee = (int)$context->employee->id; - } else { - $objCustomerMessage->id_employee = 0; - } - - $objCustomerMessage->message = $message; - $objCustomerMessage->private = 0; - - $objCustomerMessage->add(); - - return true; - } - - return false; - } - /** * Get overbooked rooms in the order|hotel * @param [int] $idOrder : id of the order diff --git a/modules/hotelreservationsystem/controllers/admin/AdminOrderRefundRequestsController.php b/modules/hotelreservationsystem/controllers/admin/AdminOrderRefundRequestsController.php index e39b3b30b..02798b4af 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminOrderRefundRequestsController.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminOrderRefundRequestsController.php @@ -223,9 +223,13 @@ public function renderView() } } + $orderTotalPaid = $objOrder->getTotalPaid(); + $orderDiscounts = $objOrder->getCartRules(); + $hasOrderDiscountOrPayment = ((float)$orderTotalPaid > 0 || $orderDiscounts) ? true : false; $this->context->smarty->assign( array ( - 'orderTotalPaid' => $objOrder->getTotalPaid(), + 'hasOrderDiscountOrPayment' => $hasOrderDiscountOrPayment, + 'orderTotalPaid' => $orderTotalPaid, 'customer_name' => $objCustomer->firstname.' '.$objCustomer->lastname, 'customer_email' => $objCustomer->email, 'orderReturnInfo' => (array)$objOrderReturn, @@ -257,11 +261,14 @@ public function postProcess() if (Validate::isLoadedObject($objOrderReturn = new OrderReturn($idOrderReturn))) { $objOrder = new Order($objOrderReturn->id_order); $orderTotalPaid = $objOrder->getTotalPaid(); + $orderDiscounts = $objOrder->getCartRules(); + $hasOrderDiscountOrPayment = ((float)$orderTotalPaid > 0 || $orderDiscounts) ? true : false; + $idRefundState = Tools::getValue('id_refund_state'); if (Validate::isLoadedObject($objRefundState = new OrderReturnState($idRefundState))) { if ($objRefundState->refunded) { $refundedAmounts = Tools::getValue('refund_amounts'); - if ((float) $orderTotalPaid > 0) { + if ($hasOrderDiscountOrPayment) { if ($idsReturnDetail && count($idsReturnDetail)) { if ($refundedAmounts) { foreach ($idsReturnDetail as $idRetDetail) { @@ -346,6 +353,8 @@ public function postProcess() // save individual booking amount for every booking refund $refundedAmount = $refundedAmounts[$idRetDetail]; $objOrderReturnDetail->refunded_amount = $refundedAmount; + // set the id_customization to check if in this request which bookings are refunded or not for future + $objOrderReturnDetail->id_customization = 1; $objOrderReturnDetail->save(); // sum the refund amount for total order refund amount @@ -372,7 +381,7 @@ public function postProcess() } // if bookings are refunded then set the payment information - if ((float) $orderTotalPaid > 0) { + if ($hasOrderDiscountOrPayment) { if (Tools::isSubmit('refundTransactionAmount')) { $objOrderReturn->payment_mode = $paymentMode; $objOrderReturn->id_transaction = $idTransaction; @@ -395,7 +404,7 @@ public function postProcess() $idOrderState = 0; if ($objOrder->hasCompletelyRefunded(Order::ORDER_COMPLETE_REFUND_FLAG)) { $idOrderState = Configuration::get('PS_OS_REFUND'); - } elseif ($objOrder->hasCompletelyRefunded(Order::ORDER_COMPLETE_REFUND_FLAG)) { + } elseif ($objOrder->hasCompletelyRefunded(Order::ORDER_COMPLETE_CANCELLATION_FLAG)) { $idOrderState = Configuration::get('PS_OS_CANCELED'); } diff --git a/modules/hotelreservationsystem/views/templates/admin/order_refund_requests/helpers/view/view.tpl b/modules/hotelreservationsystem/views/templates/admin/order_refund_requests/helpers/view/view.tpl index e65a96df7..e69a38a28 100644 --- a/modules/hotelreservationsystem/views/templates/admin/order_refund_requests/helpers/view/view.tpl +++ b/modules/hotelreservationsystem/views/templates/admin/order_refund_requests/helpers/view/view.tpl @@ -131,8 +131,12 @@ {if !$isRefundCompleted} {l s='Rooms cancelation charges' mod='hotelreservationsystem'} {/if} - {if $orderTotalPaid|floatval} + {if $hasOrderDiscountOrPayment || $isRefundCompleted} {l s='Refund amount' mod='hotelreservationsystem'} + + {if $isRefundCompleted} + {l s='Refund status' mod='hotelreservationsystem'} + {/if} {/if} {foreach $refundReqBookings as $booking} @@ -184,11 +188,11 @@ {/if} {/if} - {if $orderTotalPaid|floatval} + {if $hasOrderDiscountOrPayment || $isRefundCompleted}
{if $isRefundCompleted} - {displayPrice price=$booking['refunded_amount'] currency=$orderCurrency['id']} + {displayPrice price=$booking['refunded_amount'] currency=$orderCurrency['id']} {else} {$orderCurrency['sign']|escape:'html':'UTF-8'} @@ -196,6 +200,18 @@ {/if}
+ {if $isRefundCompleted} + + {if $booking['is_cancelled']} + {l s='Cancelled' mod='hotelreservationsystem'} + {* used id_customization to check if in this request which bookings are refunded or not*} + {else if $booking['id_customization']} + {l s='Refunded' mod='hotelreservationsystem'} + {else} + {l s='Denied' mod='hotelreservationsystem'} + {/if} + + {/if} {/if} {/foreach} @@ -279,7 +295,7 @@
{* Fields to submit refund information *} - {if $orderTotalPaid|floatval} + {if $hasOrderDiscountOrPayment}
diff --git a/themes/hotel-reservation-theme/css/order-detail.css b/themes/hotel-reservation-theme/css/order-detail.css index c84de4477..b6119076e 100644 --- a/themes/hotel-reservation-theme/css/order-detail.css +++ b/themes/hotel-reservation-theme/css/order-detail.css @@ -277,6 +277,13 @@ border-bottom: 1px solid #E5E5E5; } +@media (min-width: 576px) { + .booking-room-detail .num-refunded-rooms { + float: right; + display: inline-block; + } +} + @media (max-width: 576px) { .room-details .card-header { flex-direction: column; @@ -287,6 +294,11 @@ margin-top: 10px; margin-left: -10px; } + + .booking-room-detail .num-refunded-rooms { + display: block; + float: none; + } } @media (min-width: 768px) and (max-width: 1200px) { @@ -321,17 +333,12 @@ top: -1px; } -.booking-room-detail .num-refunded-rooms { - position: absolute; - top: 20px; - right: 20px; -} - .booking-room-detail .num-refunded-rooms .badge { padding: 5px; font-weight: normal; font-size: 12px; border-radius: 2px; + margin-top: 5px; } .booking-room-detail .btn-view-extra-services { @@ -891,8 +898,6 @@ background-color: #F5F5F5; } #create-new-refund-popup .tab-content .room-details.cancelled .badge-cancelled { - position: absolute; - top: -4px; margin-left: 6px; padding: 5px 10px; border-radius: 31px; diff --git a/themes/hotel-reservation-theme/js/order-detail.js b/themes/hotel-reservation-theme/js/order-detail.js index 6a54f74b0..a56a5e68f 100644 --- a/themes/hotel-reservation-theme/js/order-detail.js +++ b/themes/hotel-reservation-theme/js/order-detail.js @@ -97,6 +97,42 @@ function initPriceTooltip() { } } +// initialize tooltip for +function initRefundDeniedTooltip() { + if ($('.refund-denied-info').length) { + $('.refund-denied-info').each(function () { + $(this).tooltip({ + content: $(this).data('refund_denied_info'), + items: 'i', + trigger: 'hover', + tooltipClass: 'refund-denied-tootip', + open: function (event, ui) { + if (typeof (event.originalEvent) === 'undefined') { + return false; + } + + var $id = $(ui.tooltip).attr('id'); + + // close any lingering tooltips + if ($('div.ui-tooltip').not('#' + $id).length) { + return false; + } + }, + close: function (event, ui) { + ui.tooltip.hover(function () { + $(this).stop(true).fadeTo(400, 1); + }, + function () { + $(this).fadeOut('400', function () { + $(this).remove(); + }); + }); + } + }); + }); + } +} + function initMap() { const hotelLocation = { lat: Number(hotel_location.latitude), @@ -232,6 +268,9 @@ const BookingRefundManager = { href: '#popup-cancellation-submit-success', wrapCSS: 'fancybox-order-detail feedback', padding: 0, + afterClose: function() { + location.reload(); + }, }); }, showOrderCancelSuccessMessage: function() { @@ -341,4 +380,6 @@ $(document).ready(function () { ) { initMap(); } + + initRefundDeniedTooltip(); }); diff --git a/themes/hotel-reservation-theme/order-detail.tpl b/themes/hotel-reservation-theme/order-detail.tpl index ad1ca8629..75654732f 100644 --- a/themes/hotel-reservation-theme/order-detail.tpl +++ b/themes/hotel-reservation-theme/order-detail.tpl @@ -774,15 +774,16 @@
{foreach from=$rm_v['hotel_booking_details'] item=$hotel_booking_detail name=foreachRefundRooms} {assign var=is_room_cancelled value=(isset($refundReqBookings) && in_array($hotel_booking_detail.id_htl_booking, $refundReqBookings))} -
+
+ ({$hotel_booking_detail.adults|string_format:'%02d'} {if $hotel_booking_detail.adults > 1}{l s='Adults'}{else}{l s='Adult'}{/if}{if $hotel_booking_detail.children > 0}{l s=', '}{$hotel_booking_detail.children|string_format:'%02d'} {if $hotel_booking_detail.children > 1}{l s='Children'}{else}{l s='Child'}{/if}{/if}) - {if $hotel_booking_detail.is_refunded || $hotel_booking_detail.is_cancelled}{l s='Cancelled'}{/if} + {if $hotel_booking_detail.is_cancelled}{l s='Cancelled'}{else if $hotel_booking_detail.is_refunded}{l s='Refunded'}{else if $hotel_booking_detail.refund_denied}{l s='Refund denied'} {else if $hotel_booking_detail.id_status != $ROOM_STATUS_ALLOTED}{if $hotel_booking_detail.id_status == $ROOM_STATUS_CHECKED_OUT}{l s='Checked-Out'}{else}{l s='Checked-In'}{/if}{/if}
diff --git a/themes/hotel-reservation-theme/order-follow.tpl b/themes/hotel-reservation-theme/order-follow.tpl index 4b0871ab0..25b7831f3 100644 --- a/themes/hotel-reservation-theme/order-follow.tpl +++ b/themes/hotel-reservation-theme/order-follow.tpl @@ -61,13 +61,7 @@ {$return.total_rooms|escape:'html':'UTF-8'} - - {if $return.is_cancelled} - {l s='Cancelled'} - {else} - {$return.state_name|escape:'html':'UTF-8'} - {/if} - + {$return.state_name|escape:'html':'UTF-8'} {dateFormat date=$return.date_add full=0} diff --git a/themes/hotel-reservation-theme/order-return.tpl b/themes/hotel-reservation-theme/order-return.tpl index dd45651ea..fa00f6878 100644 --- a/themes/hotel-reservation-theme/order-return.tpl +++ b/themes/hotel-reservation-theme/order-return.tpl @@ -49,29 +49,40 @@
+ - {if $isRefundCompleted} + {/if} - {foreach $refundReqBookings as $booking} + {foreach from=$refundReqBookings item=$booking name=refundRequest} + - {if $isRefundCompleted} + {/if} {/foreach} @@ -83,12 +94,7 @@ {l s='Current refund state'}
- - {if $isCanceled} - {l s='Cancelled'} - {else} - {$currentStateInfo['name']|escape:'html':'UTF-8'} - {/if} + {$currentStateInfo['name']|escape:'html':'UTF-8'}
{l s='Rooms'} {l s='Room type'} {l s='Hotel'} {l s='Duration'}{l s='Num rooms'} {l s='Total rooms price (tax incl.)'} {l s='Extra services price (tax incl.)'}{l s='Refund amount'}{l s='Refund Status'}
{l s='Room'} - {$smarty.foreach.refundRequest.iteration|string_format:'%02d'} {$booking['room_type_name']|escape:'htmlall':'UTF-8'} {$booking['hotel_name']|escape:'htmlall':'UTF-8'} {$booking['date_from']|date_format:"%d-%m-%Y"} {l s='To'} {$booking['date_to']|date_format:"%d-%m-%Y"}{$booking['num_rooms']|escape:'htmlall':'UTF-8'} {displayPrice price=$booking['total_price_tax_incl'] currency=$orderCurrency['id']} {displayPrice price=$booking['extra_service_total_price_tax_incl'] currency=$orderCurrency['id']} {displayPrice price=$booking['refunded_amount'] currency=$orderCurrency['id']} + {if $booking['is_cancelled']} + {l s='Cancelled' mod='hotelreservationsystem'} + {* used id_customization to check if in this request which bookings are refunded or not*} + {else if $booking['id_customization']} + {l s='Refunded' mod='hotelreservationsystem'} + {else} + {l s='Denied' mod='hotelreservationsystem'} + {/if} +