diff --git a/admin/themes/default/template/controllers/orders/_hotel_service_products_table.tpl b/admin/themes/default/template/controllers/orders/_hotel_service_products_table.tpl index eb4a22fd2..6d3920f82 100644 --- a/admin/themes/default/template/controllers/orders/_hotel_service_products_table.tpl +++ b/admin/themes/default/template/controllers/orders/_hotel_service_products_table.tpl @@ -25,18 +25,17 @@ - + {if isset($refundReqProducts) && $refundReqProducts} - - + {/if} - {if $can_edit} - + {if ($can_edit)} + {/if} @@ -92,27 +91,19 @@ {if (isset($refundReqProducts) && $refundReqProducts)} - {/if} - {if ($can_edit && !$order->hasBeenDelivered())} + {if ($can_edit)} - {assign var=colspan value=6} {if isset($refundReqProducts) && $refundReqProducts} - {assign var=colspan value=($colspan+2)} + {assign var=colspan value=($colspan+1)} {/if} {if ($can_edit)} {assign var=colspan value=($colspan+1)} diff --git a/admin/themes/default/template/controllers/orders/_new_service_product.tpl b/admin/themes/default/template/controllers/orders/_new_service_product.tpl index 0be06be98..2b91de478 100644 --- a/admin/themes/default/template/controllers/orders/_new_service_product.tpl +++ b/admin/themes/default/template/controllers/orders/_new_service_product.tpl @@ -69,7 +69,6 @@ {if ($order->hasBeenPaid())}{/if} {if $display_warehouse}{/if} - {if ($order->hasBeenDelivered())}{/if} {foreach from=$orderOverBookings item=data} - {if !$data.is_refunded} @@ -87,7 +86,6 @@ {/if} - {/if} {/foreach}
{l s='Image'}{l s='Image'} {l s='Name'} {l s='Quantity'} {l s='Price (Tax excl.)'} {l s='Total Tax'} {l s='Total Price (Tax incl.)'}{l s='Refund State'}{l s='Refunded amount'}
{l s='Refund'}
{l s='Refund requests'}
{l s='Actions'}{l s='Actions'}
- {if $product.id_service_product_order_detail|in_array:$refundReqProducts} - {if $product.is_cancelled} - {l s='Cancelled'} - {elseif isset($product.refund_info) && (!$product.refund_info.refunded || $product.refund_info.id_customization)} - {$product.refund_info.name|escape:'html':'UTF-8'} - {else} - -- + {if $product.refund_count} + {if $product.refund_amount} +

+ {convertPriceWithCurrency price=$product.refund_amount currency=$currency->id} +

{/if} + {$product.refund_count} {else} - -- - {/if} -
- {if $product.is_refunded && isset($product.refund_info) && $product.refund_info} - {convertPriceWithCurrency price=$product.refund_info.refunded_amount currency=$currency->id} - {else} - -- +

--

{/if}
+ {* edit/delete controls *} {if isset($refundReqProducts) && $refundReqProducts && $product.id_service_product_order_detail|in_array:$refundReqProducts && $product.is_cancelled}
diff --git a/admin/themes/default/template/controllers/orders/_overbookings.tpl b/admin/themes/default/template/controllers/orders/_overbookings.tpl index 46ea251d3..95711a30f 100644 --- a/admin/themes/default/template/controllers/orders/_overbookings.tpl +++ b/admin/themes/default/template/controllers/orders/_overbookings.tpl @@ -38,7 +38,6 @@ {l s='Resolve'}
{$data['room_num']} {$data['room_type_name']}
diff --git a/admin/themes/default/template/controllers/orders/_product_line.tpl b/admin/themes/default/template/controllers/orders/_product_line.tpl index cd5728889..a27076f75 100644 --- a/admin/themes/default/template/controllers/orders/_product_line.tpl +++ b/admin/themes/default/template/controllers/orders/_product_line.tpl @@ -124,32 +124,29 @@ {convertPriceWithCurrency price=($data['total_room_price_ti']) currency=$currency->id} + + {if isset($htl_booking_statuses[$data.id_status])} + {$htl_booking_statuses[$data.id_status].name|escape:'html':'UTF-8'} + {/if} + {if (isset($refundReqBookings) && $refundReqBookings)} -

- {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 $data.is_refunded && isset($data.refund_info) && $data.refund_info} -

- {convertPriceWithCurrency price=$data.refund_info.refunded_amount currency=$currency->id} -

- {/if} + {if $data.refund_count} + {if $data.refund_amount} +

+ {convertPriceWithCurrency price=$data.refund_amount currency=$currency->id} +

+ {/if} + {$data.refund_count} + {else} +

--

+ {/if} {/if} - {if ($can_edit && !$order->hasBeenDelivered())} + {if ($can_edit)}
- {if isset($refundReqBookings) && $refundReqBookings && $data.id|in_array:$refundReqBookings && $data.is_cancelled} + {if isset($refundReqBookings) && $refundReqBookings && $data.id|in_array:$refundReqBookings && ($data.id_status == $ROOM_STATUS_CANCELLED || $data.id_status == $ROOM_STATUS_NO_SHOW)}
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 a0ed4817e..c4f8cdeab 100644 --- a/admin/themes/default/template/controllers/orders/_rooms_informaion_table.tpl +++ b/admin/themes/default/template/controllers/orders/_rooms_informaion_table.tpl @@ -37,10 +37,11 @@
{l s='Extra Services'}
{l s='(Tax excl.)'}
{l s='Total Tax'}
{l s='Total Price'}
{l s='(Tax incl.)'}
+ {l s='Room status'} {if (isset($refundReqBookings) && $refundReqBookings)} - {l s='Refund'} +
{l s='Refunds'}
{/if} - {if (isset($can_edit) && $can_edit && !$order->hasBeenDelivered())} + {if (isset($can_edit) && $can_edit)} {l s='Actions'} {/if} diff --git a/admin/themes/default/template/controllers/orders/_standalone_service_products_table.tpl b/admin/themes/default/template/controllers/orders/_standalone_service_products_table.tpl index cdf901924..85438f428 100644 --- a/admin/themes/default/template/controllers/orders/_standalone_service_products_table.tpl +++ b/admin/themes/default/template/controllers/orders/_standalone_service_products_table.tpl @@ -25,18 +25,17 @@ - + {if isset($refundReqProducts) && $refundReqProducts} - - + {/if} {if ($can_edit)} - + {/if} @@ -92,27 +91,20 @@ {if (isset($refundReqProducts) && $refundReqProducts)} - {/if} - {if ($can_edit && !$order->hasBeenDelivered())} + {if ($can_edit)} - {assign var=colspan value=6} {if isset($refundReqProducts) && $refundReqProducts} - {assign var=colspan value=($colspan+2)} + {assign var=colspan value=($colspan+1)} {/if} {if ($can_edit)} {assign var=colspan value=($colspan+1)} 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 69ec1bb84..3b371bc1f 100644 --- a/admin/themes/default/template/controllers/orders/helpers/view/view.tpl +++ b/admin/themes/default/template/controllers/orders/helpers/view/view.tpl @@ -32,6 +32,8 @@ {l s='Refunded'} {elseif $currentState->id == Configuration::get('PS_OS_CANCELED')} {l s='Cancelled'} + {elseif $currentState->id == Configuration::get('PS_OS_NO_SHOW')} + {l s='No-show'} {else} {l s='Booked'} {/if} @@ -173,13 +175,13 @@ {* If current state is refunded or cancelled the further order status changes are not allowed *} - {if $can_edit && (!isset($currentState) || (isset($currentState) && ($currentState->id != Configuration::get('PS_OS_REFUND') && $currentState->id != Configuration::get('PS_OS_CANCELED'))))} + {if $can_edit && (!isset($currentState) || (isset($currentState) && ($currentState->id != Configuration::get('PS_OS_REFUND') && $currentState->id != Configuration::get('PS_OS_CANCELED') && $currentState->id != Configuration::get('PS_OS_NO_SHOW'))))}
@@ -765,7 +767,7 @@
 {l s='Rooms Booking Detail'} {$order_detail_data|@count} - {if $can_edit && (!$order->hasBeenDelivered() && $currentState->id != Configuration::get('PS_OS_REFUND') && $currentState->id != Configuration::get('PS_OS_CANCELED'))} + {if $can_edit && ($currentState->id != Configuration::get('PS_OS_REFUND') && $currentState->id != Configuration::get('PS_OS_CANCELED') && $currentState->id != Configuration::get('PS_OS_NO_SHOW'))} @@ -797,7 +799,7 @@
 {l s='Products Detail'} {$hotel_service_products|count} - {if $can_edit && (!$order->hasBeenDelivered() && $currentState->id != Configuration::get('PS_OS_REFUND') && $currentState->id != Configuration::get('PS_OS_CANCELED'))} + {if $can_edit && ($currentState->id != Configuration::get('PS_OS_REFUND') && $currentState->id != Configuration::get('PS_OS_CANCELED') && $currentState->id != Configuration::get('PS_OS_NO_SHOW'))} @@ -829,7 +831,7 @@
 {l s='Products Detail'} {$standalone_service_products|count} - {if $can_edit && (!$order->hasBeenDelivered() && $currentState->id != Configuration::get('PS_OS_REFUND') && $currentState->id != Configuration::get('PS_OS_CANCELED'))} + {if $can_edit && ($currentState->id != Configuration::get('PS_OS_REFUND') && $currentState->id != Configuration::get('PS_OS_CANCELED') && $currentState->id != Configuration::get('PS_OS_NO_SHOW'))} @@ -1349,9 +1351,12 @@ {addJsDefL name='no_children_allowed_txt'}{l s='Only adults can be accommodated' js=1}{/addJsDefL} {addJsDefL name='invalid_occupancy_txt'}{l s='Invalid occupancy(adults/children) found.' js=1}{/addJsDefL} {addJsDefL name='select_room_txt'}{l s='Select room' js=1}{/addJsDefL} + {addJsDefL name='room_status_sealed_warning_txt'}{l s='Are you sure? You cannot change the booking status after this.' js=1}{/addJsDefL} {addJsDef max_child_age=$max_child_age|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 ROOM_STATUS_NO_SHOW=$ROOM_STATUS_NO_SHOW|escape:'quotes':'UTF-8'} + {addJsDef ROOM_STATUS_CANCELLED=$ROOM_STATUS_CANCELLED|escape:'quotes':'UTF-8'} {addJsDef ALLOTMENT_MANUAL=$ALLOTMENT_MANUAL|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'} 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 2bd357bc6..1469f4d69 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 @@ -98,7 +98,7 @@
{/if}
- +
@@ -111,7 +111,7 @@
- {l s='No room bookings found to cancel'} + {l s='No room bookings found to refund.'}
{/if} diff --git a/admin/themes/default/template/controllers/orders/modals/_edit_room_tab_content.tpl b/admin/themes/default/template/controllers/orders/modals/_edit_room_tab_content.tpl index 7c94bc5d0..dd5eb9f22 100644 --- a/admin/themes/default/template/controllers/orders/modals/_edit_room_tab_content.tpl +++ b/admin/themes/default/template/controllers/orders/modals/_edit_room_tab_content.tpl @@ -31,7 +31,7 @@ - {if isset($data.id_status) && ($data.id_status != HotelBookingDetail::STATUS_ALLOTED)} + {if isset($data.id_status) && ($data.id_status != HotelBookingDetail::STATUS_ASSIGNED)}
{if $data.id_status == HotelBookingDetail::STATUS_CHECKED_IN} {l s='The check-in date cannot be changed as the booking has already been checked in.'} @@ -49,7 +49,7 @@ {if isset($refundReqBookings) && $refundReqBookings && $data.id|in_array:$refundReqBookings && $data.is_refunded} {dateFormat date=$data.date_from} {else} - +
{/if}
diff --git a/admin/themes/default/template/controllers/orders/modals/_room_status_form.tpl b/admin/themes/default/template/controllers/orders/modals/_room_status_form.tpl index 204395b1a..e3dc771d1 100644 --- a/admin/themes/default/template/controllers/orders/modals/_room_status_form.tpl +++ b/admin/themes/default/template/controllers/orders/modals/_room_status_form.tpl @@ -26,11 +26,11 @@
-
+
@@ -46,6 +46,11 @@
+
+ + +
+ diff --git a/classes/order/Order.php b/classes/order/Order.php index 0bfa151a7..c55320d9c 100644 --- a/classes/order/Order.php +++ b/classes/order/Order.php @@ -45,6 +45,7 @@ class OrderCore extends ObjectModel const ORDER_COMPLETE_REFUND_FLAG = 1; const ORDER_COMPLETE_CANCELLATION_FLAG = 2; const ORDER_COMPLETE_CANCELLATION_OR_REFUND_REQUEST_FLAG = 3; + const ORDER_COMPLETE_NOSHOW_FLAG = 4; /** @var int Delivery address id */ public $id_address_delivery; @@ -2855,7 +2856,15 @@ class OrderCore extends ObjectModel // check rooms in booking $objHotelBooking = new HotelBookingdetail(); - if ($orderBookings = $objHotelBooking->getOrderCurrentDataByOrderId($this->id)) { + $orderBookings = $objHotelBooking->getOrderCurrentDataByOrderId($this->id); + + // No-show is a room-only concept — a product-only order (no rooms at all) + // can never be "No-show", no matter how resolved its products are + if ($action == Order::ORDER_COMPLETE_NOSHOW_FLAG && !$orderBookings) { + return false; + } + + if ($orderBookings) { $res &= $this->checkList($orderBookings, $action, $includeCheckIn); $hasRoomsOrProducts = 1; } @@ -2875,9 +2884,36 @@ class OrderCore extends ObjectModel } public function checkList($list, $action = 0, $includeCheckIn = 0) { + // room-booking rows (from htl_booking_detail) carry id_status; service-product + // rows (from service_product_order_detail) never do — that's a different table + // with its own, unrelated is_refunded/is_cancelled columns, out of scope for + // this migration (only htl_booking_detail's flags are being retired). checkList() + // is always called with one or the other, never a mix of both (see callers in + // hasCompletelyRefunded()), so this check only needs to happen once per call. + $isRoomList = $list && isset($list[0]['id_status']); + if ($isRoomList) { + // one query for the whole list instead of one query per row + $refundedIds = array_flip(array_column( + Db::getInstance()->executeS(OrderReturn::getRefundedBookingIdsSubquery()), + 'id_htl_booking' + )); + } + // 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) { + if ($isRoomList) { + $hasNonCancelled = false; + foreach ($list as $product) { + if (!isset($refundedIds[$product['id']])) { + return false; + } + if ($product['id_status'] != HotelBookingDetail::STATUS_CANCELLED) { + $hasNonCancelled = true; + } + } + return $hasNonCancelled; + } $uniqueRefunded = array_unique(array_column($list, 'is_refunded')); if (count($uniqueRefunded) == 1 && $uniqueRefunded[0] == 1) { foreach ($list as $product) { @@ -2888,14 +2924,50 @@ class OrderCore extends ObjectModel } // 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) { + if ($isRoomList) { + foreach ($list as $product) { + if ($product['id_status'] != HotelBookingDetail::STATUS_CANCELLED) { + return false; + } + } + return true; + } $uniqueRefunded = array_unique(array_column($list, 'is_cancelled')); if (count($uniqueRefunded) == 1 && $uniqueRefunded[0] == 1) { return true; } + // If action is Order::ORDER_COMPLETE_NOSHOW_FLAG then every room must be + // terminal (No-show or Cancelled), with at least one actually No-show — + // No-show wins over Cancelled when an order mixes both. + } elseif ($action == Order::ORDER_COMPLETE_NOSHOW_FLAG) { + if (empty($list)) { + return false; + } + $hasNoShow = false; + foreach ($list as $product) { + if (isset($product['id_status'])) { + // room booking row + if ($product['id_status'] != HotelBookingDetail::STATUS_NO_SHOW + && $product['id_status'] != HotelBookingDetail::STATUS_CANCELLED + ) { + return false; + } + if ($product['id_status'] == HotelBookingDetail::STATUS_NO_SHOW) { + $hasNoShow = true; + } + } elseif (!$product['is_cancelled']) { + // service products can't be "no-show" — just require them to + // already be resolved, same bar as ORDER_COMPLETE_CANCELLATION_FLAG + return false; + } + } + + return $hasNoShow; // 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 ($list as $product) { - if (!$product['is_refunded']) { + $isResolved = $isRoomList ? isset($refundedIds[$product['id']]) : $product['is_refunded']; + if (!$isResolved) { // If booking refund request is created and request is completed but booking is not refunded then return false if ($refundDetail = OrderReturn::getOrdersReturnDetail( $this->id, @@ -2916,20 +2988,35 @@ class OrderCore extends ObjectModel 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 - $uniqueRefunded = array_unique(array_column($list, 'is_refunded')); - if (count($uniqueRefunded) == 1 && $uniqueRefunded[0] == 1) { - return true; - } elseif ($includeCheckIn) { + if ($isRoomList) { + $allResolved = !empty($list); foreach ($list as $product) { - if ($product['is_refunded'] == 0 - && !OrderReturn::getOrdersReturnDetail($this->id, 0, isset($product['id']) ? $product['id'] : 0) - && $product['id_status'] == HotelBookingDetail::STATUS_ALLOTED - ) { - return false; + if (!isset($refundedIds[$product['id']])) { + $allResolved = false; + break; } } - return true; + if ($allResolved) { + return true; + } elseif ($includeCheckIn) { + foreach ($list as $product) { + if (!isset($refundedIds[$product['id']]) + && !OrderReturn::getOrdersReturnDetail($this->id, 0, $product['id']) + && $product['id_status'] == HotelBookingDetail::STATUS_ASSIGNED + ) { + return false; + } + } + return true; + } + } else { + // if is_refunded is 1 means booking either is cancelled or refunded. So check all bookings must have is_refunded = 1 + $uniqueRefunded = array_unique(array_column($list, 'is_refunded')); + if (count($uniqueRefunded) == 1 && $uniqueRefunded[0] == 1) { + return true; + } + // note: $includeCheckIn is never true here in practice — hasCompletelyRefunded() + // always calls checkList() with $includeCheckIn=false for product lists } } @@ -2938,9 +3025,23 @@ class OrderCore extends ObjectModel public function getOrderCompleteRefundStatus() { + $objHotelBooking = new HotelBookingdetail(); + foreach ($objHotelBooking->getOrderCurrentDataByOrderId($this->id) as $booking) { + if ($booking['id_status'] != HotelBookingDetail::STATUS_CANCELLED + && $booking['id_status'] != HotelBookingDetail::STATUS_NO_SHOW + ) { + return 0; + } + } + // any completed refund anywhere in the order takes priority over + // No-show/Cancelled and is sticky (a refund never un-completes) + if ((new OrderReturn())->getRefundedAmount($this->id) > 0) { + return Configuration::get('PS_OS_REFUND'); + } + $idOrderState = 0; - if ($this->hasCompletelyRefunded(Order::ORDER_COMPLETE_REFUND_FLAG)) { - $idOrderState = Configuration::get('PS_OS_REFUND'); + if ($this->hasCompletelyRefunded(Order::ORDER_COMPLETE_NOSHOW_FLAG)) { + $idOrderState = Configuration::get('PS_OS_NO_SHOW'); } elseif ($this->hasCompletelyRefunded(Order::ORDER_COMPLETE_CANCELLATION_FLAG)) { $idOrderState = Configuration::get('PS_OS_CANCELED'); } elseif ($this->hasCompletelyRefunded()) { @@ -2950,6 +3051,30 @@ class OrderCore extends ObjectModel return $idOrderState; } + /** + * Bump the order's own status to match getOrderCompleteRefundStatus(), + * if it needs to change — the single place every caller that used to + * repeat this same 6-line block now goes through, so the "already at + * this state, don't re-bump" guard applies everywhere, not just one caller. + * + * @param bool $useEmail whether to email the customer about the change + * @return bool whether the order status was actually changed + */ + public function syncRefundStatus($useEmail = true) + { + $idOrderState = $this->getOrderCompleteRefundStatus(); + if (!$idOrderState || $idOrderState == $this->current_state) { + return false; + } + + $objOrderHistory = new OrderHistory(); + $objOrderHistory->id_order = (int) $this->id; + $objOrderHistory->changeIdOrderState($idOrderState, $this, !$this->hasInvoice()); + $useEmail ? $objOrderHistory->addWithemail() : $objOrderHistory->add(); + + return true; + } + public function getWsBookings() { return Db::getInstance()->executeS( @@ -2990,26 +3115,23 @@ class OrderCore extends ObjectModel if (!$objHotelBooking->getOverbookedRooms($this->id)) { $result['errors'][] = Tools::displayError('Order status can not be changed to any overbooking status as there are no overbooked rooms in the order.'); } - } elseif ($objNewOrderState->id == Configuration::get('PS_OS_REFUND') - && !$this->hasCompletelyRefunded(Order::ORDER_COMPLETE_REFUND_FLAG) - ) { - $result['errors'][] = Tools::displayError('Order status can not be set to Refunded until all bookings in the order are completely refunded.'); - } elseif ($objNewOrderState->id == Configuration::get('PS_OS_CANCELED') - && !$this->hasCompletelyRefunded(Order::ORDER_COMPLETE_CANCELLATION_FLAG, 0, 1) - ) { - $result['errors'][] = Tools::displayError('Order status can not be set to Cancelled until all bookings in the order are cancelled.'); + } elseif (in_array($objNewOrderState->id, array( + Configuration::get('PS_OS_REFUND'), + Configuration::get('PS_OS_CANCELED'), + Configuration::get('PS_OS_NO_SHOW'), + ))) { + // Refunded/Cancelled/No-show are never a direct manual pick — they're + // only ever reached automatically, via Order::syncRefundStatus(), when + // a refund completes or a room's status changes to Cancelled/No-show. + $result['errors'][] = Tools::displayError('Order status cannot be changed directly to Refunded, Cancelled, or No-show — it is set automatically based on the booking/refund status.'); } elseif ($objCurrentOrderState->id == Configuration::get('PS_OS_ERROR') && !($objNewOrderState->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 if ($orderBookings = $objHotelBooking->getOrderCurrentDataByOrderId($this->id)) { + $objOrderReturn = new OrderReturn(); foreach ($orderBookings as $orderBooking) { - // If booking is refunded then no need to check inventory - 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']) + // If booking is refunded (or cancelled) then no need to check inventory + if ($objOrderReturn->hasCompletelyRefundedBooking($orderBooking['id']) + || $orderBooking['id_status'] == HotelBookingDetail::STATUS_CANCELLED ) { continue; } else { @@ -3022,7 +3144,6 @@ class OrderCore extends ObjectModel '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'] @@ -3034,9 +3155,6 @@ class OrderCore extends ObjectModel $result['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 { $result['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.'); diff --git a/classes/order/OrderReturn.php b/classes/order/OrderReturn.php index 79785f982..88b035c70 100644 --- a/classes/order/OrderReturn.php +++ b/classes/order/OrderReturn.php @@ -57,6 +57,9 @@ class OrderReturnCore extends ObjectModel /** @var int whether $id_return_type is cart_rule or order_slip */ public $return_type; + /** @var int why this refund request exists: EVENT_TYPE_CANCELLATION/_NO_SHOW/_REFUND */ + public $event_type; + /** @var string Object creation date */ public $date_add; @@ -67,6 +70,11 @@ class OrderReturnCore extends ObjectModel const RETURN_TYPE_CART_RULE = 1; const RETURN_TYPE_ORDER_SLIP = 2; + /** possible values for $event_type */ + const EVENT_TYPE_CANCELLATION = 1; + const EVENT_TYPE_NO_SHOW = 2; + const EVENT_TYPE_REFUND = 3; + /** * @see ObjectModel::$definition */ @@ -84,6 +92,7 @@ class OrderReturnCore extends ObjectModel 'by_admin' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true), 'id_return_type' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), 'return_type' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), + 'event_type' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), 'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'), 'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'), ), @@ -177,16 +186,45 @@ class OrderReturnCore extends ObjectModel return (int)($data['total']); } + /** + * Subquery fragment: every id_htl_booking with at least one completed (actually + * refunded) return — the replacement for reading htl_booking_detail.is_refunded, + * which was only ever set true by processRefundInBookingTables() at this exact + * same moment. Used as `id NOT IN (...)` / `id IN (...)` in other queries, since + * this exact fragment is needed at many call sites across the codebase. + * + * @return string raw SQL, not a full query + */ + public static function getRefundedBookingIdsSubquery($eventType = null) + { + return 'SELECT ord.`id_htl_booking` FROM `'._DB_PREFIX_.'order_return_detail` ord + INNER JOIN `'._DB_PREFIX_.'order_return` orr ON orr.`id_order_return` = ord.`id_order_return` + INNER JOIN `'._DB_PREFIX_.'order_return_state` ors ON ors.`id_order_return_state` = orr.`state` + WHERE ors.`refunded` = 1'.(!is_null($eventType) ? ' AND orr.`event_type` = '.(int) $eventType : ''); + } + + /** + * Whether this one room booking has at least one completed (actually refunded) return. + * + * @param int $idHtlBooking + * @return bool + */ + public function hasCompletelyRefundedBooking($idHtlBooking) + { + return (bool) Db::getInstance()->getValue( + 'SELECT '.(int) $idHtlBooking.' IN ('.self::getRefundedBookingIdsSubquery().')' + ); + } + /** * 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) + public function getOrderRefundRequestedBookings($idOrder, $idOrderReturn = 0, $onlyBookingIds = 0, $customerView = 0) { $sql = 'SELECT hbd.*, ord.*, orr.`state` as id_return_state FROM `'._DB_PREFIX_.'order_return` orr'; $sql .= ' INNER JOIN `'._DB_PREFIX_.'order_return_detail` ord ON (orr.`id_order_return` = ord.`id_order_return`)'; @@ -214,14 +252,6 @@ class OrderReturnCore extends ObjectModel $appliedServiceTourismTaxByBooking = OrderTaxDetail::getAppliedTourismTaxTotals($idOrder, OrderTaxDetail::SCOPE_SERVICE); foreach ($returnDetails as $key => &$bookingRow) { - if ($skipReqCompletedNonRefunded) { - $objReturnState = new OrderReturnState($bookingRow['id_return_state']); - if ($objReturnState->refunded && !$bookingRow['is_refunded']) { - unset($returnDetails[$key]); - continue; - } - } - if (!$onlyBookingIds) { $bookingRow['extra_service_total_paid_amount'] = 0; $bookingRow['extra_service_total_price_tax_incl'] = 0; @@ -295,7 +325,7 @@ class OrderReturnCore extends ObjectModel } if ($onlyBookingIds) { - return array_column($returnDetails, 'id_htl_booking'); + return array_values(array_unique(array_column($returnDetails, 'id_htl_booking'))); } if ($customerView) { @@ -309,7 +339,7 @@ class OrderReturnCore extends ObjectModel /** * Get order refund request products */ - public function getOrderRefundRequestedProducts($idOrder, $idOrderReturn = 0, $onlyIds = 0, $skipReqCompletedNonRefunded = 0) + public function getOrderRefundRequestedProducts($idOrder, $idOrderReturn = 0, $onlyIds = 0) { $sql = 'SELECT spod.*, ord.*, orr.`state` as id_return_state, p.`allow_multiple_quantity` FROM `'._DB_PREFIX_.'order_return` orr'; $sql .= ' INNER JOIN `'._DB_PREFIX_.'order_return_detail` ord ON (orr.`id_order_return` = ord.`id_order_return`)'; @@ -323,14 +353,6 @@ class OrderReturnCore extends ObjectModel if ($returnDetails = Db::getInstance()->executeS($sql)) { $objOrder = new Order($idOrder); foreach ($returnDetails as $key => &$product) { - if ($skipReqCompletedNonRefunded) { - $objReturnState = new OrderReturnState($product['id_return_state']); - if ($objReturnState->refunded && !$product['is_refunded']) { - unset($returnDetails[$key]); - continue; - } - } - $product['paid_amount'] = 0; if ($product['total_price_tax_incl'] > 0) { if ($objOrder->total_paid_real > 0) { @@ -354,7 +376,7 @@ class OrderReturnCore extends ObjectModel } $sql = 'SELECT orr.`id_order`, orr.`state`, orr.`id_order_return`, orr.`payment_mode`, orr.`id_transaction`, orr.`id_return_type`, orr.`return_type`, ors.`id_cart_rule`, orr.`date_add`, orr.`date_upd`, orr.`refunded_amount`, - hbd.`is_cancelled`, SUM(IF(ord.`id_htl_booking`, 1, 0)) AS total_rooms, SUM(IF(ord.`id_service_product_order_detail`, 1, 0)) AS total_products + IF(hbd.`id_status` = '.HotelBookingDetail::STATUS_CANCELLED.', 1, 0) AS `is_cancelled`, SUM(IF(ord.`id_htl_booking`, 1, 0)) AS total_rooms, SUM(IF(ord.`id_service_product_order_detail`, 1, 0)) AS total_products FROM `'._DB_PREFIX_.'order_return` orr LEFT JOIN `'._DB_PREFIX_.'order_return_detail` ord ON (ord.`id_order_return` = orr.`id_order_return`) @@ -756,20 +778,40 @@ class OrderReturnCore extends ObjectModel return false; } - public function getRefundedAmount($idOrder, $idOrderReturn = 0, $idHtlBooking = 0) + /** + * @param int $idOrder + * @param int $idOrderReturn + * @param int $idHtlBooking + * @param bool $detailedInfo when true, also returns the number of refund + * requests (not just the refunded amount) — e.g. for the order + * detail page's per-room "Refund" column + * @return float|array plain refunded amount by default; array('amount', 'count') when $detailedInfo + */ + public function getRefundedAmount($idOrder, $idOrderReturn = 0, $idHtlBooking = 0, $detailedInfo = false, $idServiceProductOrderDetail = 0) { - $sql = 'SELECT SUM(ord.`refunded_amount`) FROM `'._DB_PREFIX_.'order_return_detail` ord'; - $sql .= ' LEFT JOIN `'._DB_PREFIX_.'order_return` orr ON (orr.`id_order_return` = ord.`id_order_return`)'; - $sql .= ' WHERE orr.`id_order` = '.(int)$idOrder; + $where = ' WHERE orr.`id_order` = '.(int) $idOrder; if ($idOrderReturn) { - $sql .= ' AND ord.`id_order_return` = '.(int)$idOrderReturn; + $where .= ' AND ord.`id_order_return` = '.(int) $idOrderReturn; } if ($idHtlBooking) { - $sql .= ' AND ord.`id_htl_booking` = '.(int)$idHtlBooking; + $where .= ' AND ord.`id_htl_booking` = '.(int) $idHtlBooking; } + if ($idServiceProductOrderDetail) { + $where .= ' AND ord.`id_service_product_order_detail` = '.(int) $idServiceProductOrderDetail; + } + + $from = ' FROM `'._DB_PREFIX_.'order_return_detail` ord + LEFT JOIN `'._DB_PREFIX_.'order_return` orr ON (orr.`id_order_return` = ord.`id_order_return`)'; + + if ($detailedInfo) { + $sql = 'SELECT COUNT(ord.`id_order_return_detail`) AS count, SUM(ord.`refunded_amount`) AS amount'.$from.$where; + return Db::getInstance()->getRow($sql); + } + + $sql = 'SELECT SUM(ord.`refunded_amount`) AS amount'.$from.$where; return Db::getInstance()->getValue($sql); } } diff --git a/classes/order/OrderReturnDetail.php b/classes/order/OrderReturnDetail.php index 2d7b8571e..07638fd46 100644 --- a/classes/order/OrderReturnDetail.php +++ b/classes/order/OrderReturnDetail.php @@ -77,12 +77,17 @@ class OrderReturnDetailCore extends ObjectModel public static function deleteReturnDetailByIdBookingDetail($idOrder, $idHtlBooking) { - if (Validate::isLoadedObject($objOrderReturnDetail = OrderReturnDetail::getReturnDetailByIdBookingDetail($idHtlBooking))) { - if ($objOrderReturnDetail->delete()) { - $objOrderReturn = new OrderReturn(); - if (empty($objOrderReturn->getOrderRefundRequestedBookings($idOrder, $objOrderReturnDetail->id_order_return, true))) { - $objOrderReturn = new OrderReturn($objOrderReturnDetail->id_order_return); - $objOrderReturn->delete(); + $orderReturnDetails = OrderReturn::getOrdersReturnDetail($idOrder, 0, $idHtlBooking); + + if ($orderReturnDetails) { + foreach ($orderReturnDetails as $row) { + $objOrderReturnDetail = new OrderReturnDetail((int) $row['id_order_return_detail']); + if (Validate::isLoadedObject($objOrderReturnDetail) && $objOrderReturnDetail->delete()) { + $objOrderReturn = new OrderReturn(); + if (empty($objOrderReturn->getOrderRefundRequestedBookings($idOrder, $objOrderReturnDetail->id_order_return, true))) { + $objOrderReturn = new OrderReturn($objOrderReturnDetail->id_order_return); + $objOrderReturn->delete(); + } } } } diff --git a/classes/order/OrderSlip.php b/classes/order/OrderSlip.php index d4334fd73..3445e16b5 100644 --- a/classes/order/OrderSlip.php +++ b/classes/order/OrderSlip.php @@ -468,6 +468,12 @@ class OrderSlipCore extends ObjectModel } foreach ($product_list as $productRow) { + // rows the loop above skipped (nothing left to credit — see the + // $quantity == 0 continue) never got unit_price_tax_excl/incl and + // total_price_tax_excl/incl set, so they must be skipped here too + if (!isset($productRow['unit_price_tax_excl'])) { + continue; + } $order_slip->addProductOrderSlip($productRow); } return $order_slip->id; diff --git a/classes/webservice/WebserviceSpecificManagementBookings.php b/classes/webservice/WebserviceSpecificManagementBookings.php index 54327aa11..c011d9a0f 100644 --- a/classes/webservice/WebserviceSpecificManagementBookings.php +++ b/classes/webservice/WebserviceSpecificManagementBookings.php @@ -159,7 +159,7 @@ class WebserviceSpecificManagementBookingsCore Extends ObjectModel implements We 'id_order' => 'o.id_order', 'reference' => 'o.reference', 'id_room' => 'hbd.id_room', - 'is_cancelled' => 'hbd.is_cancelled', + 'is_cancelled' => 'IF(hbd.id_status = '.HotelBookingDetail::STATUS_CANCELLED.', 1, 0)', 'stay' => 'stay', 'room_status' => 'hbd.id_status', 'booking_status' => 'o.current_state', diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index e39c5d6dd..20eb4c77d 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -87,7 +87,11 @@ class AdminOrdersControllerCore extends AdminController LEFT JOIN `'._DB_PREFIX_.'order_state_lang` osl ON (os.`id_order_state` = osl.`id_order_state` AND osl.`id_lang` = '.(int) $this->context->language->id.') LEFT JOIN `'._DB_PREFIX_.'htl_booking_detail` hbd ON (hbd.`id_order` = a.`id_order`) LEFT JOIN `'._DB_PREFIX_.'service_product_order_detail` spod ON (spod.`id_order` = a.`id_order`) - LEFT JOIN `'._DB_PREFIX_.'htl_branch_info_lang` hbil ON (IF(hbd.`id_hotel`, (hbil.`id` = hbd.`id_hotel`), (hbil.`id` = spod.`id_hotel`)))'; + LEFT JOIN `'._DB_PREFIX_.'htl_branch_info_lang` hbil ON (IF(hbd.`id_hotel`, (hbil.`id` = hbd.`id_hotel`), (hbil.`id` = spod.`id_hotel`))) + LEFT JOIN ( + SELECT hbd2.`id`, IF(hbd2.`id` IN ('.OrderReturn::getRefundedBookingIdsSubquery().'), 1, 0) AS is_room_refunded + FROM `'._DB_PREFIX_.'htl_booking_detail` hbd2 + ) rrb ON (rrb.`id` = hbd.`id`)'; $this->_orderBy = 'id_order'; $this->_orderWay = 'DESC'; @@ -330,7 +334,7 @@ class AdminOrdersControllerCore extends AdminController ), 'is_refunded' => array( 'title' => $this->l('Refunded / Cancelled Rooms'), - 'filter_key' => 'hbd!is_refunded', + 'filter_key' => 'rrb!is_room_refunded', 'type'=>'bool', 'displayed' => false, ), @@ -340,9 +344,11 @@ class AdminOrdersControllerCore extends AdminController 'displayed' => false, 'type' => 'select', 'list' => array( - HotelBookingDetail::STATUS_ALLOTED => $this->l('Alloted'), + HotelBookingDetail::STATUS_ASSIGNED => $this->l('Assigned'), HotelBookingDetail::STATUS_CHECKED_IN => $this->l('Checked in'), HotelBookingDetail::STATUS_CHECKED_OUT => $this->l('Checked out'), + HotelBookingDetail::STATUS_NO_SHOW => $this->l('No-show'), + HotelBookingDetail::STATUS_CANCELLED => $this->l('Cancelled'), ), ) )); @@ -475,16 +481,13 @@ class AdminOrdersControllerCore extends AdminController } if ($this->tabAccess['edit'] === 1) { - if (((int) $order->isReturnable()) - && !$order->hasCompletelyRefunded(Order::ORDER_COMPLETE_CANCELLATION_OR_REFUND_REQUEST_FLAG, 0, 0) - ) { - $orderTotalPaid = $order->getTotalPaid(); - $orderDiscounts = $order->getCartRules(); - $hasOrderDiscountOrPayment = ((float)$orderTotalPaid > 0 || $orderDiscounts) ? true : false; + if ((int) $order->isReturnable()) { + // always "Initiate refund" now, regardless of order status — + // cancelling a booking happens through Room Status only $this->page_header_toolbar_btn['cancel'] = array( - 'short' => ($hasOrderDiscountOrPayment) ? $this->l('Refund') : $this->l('Cancel'), + 'short' => $this->l('Refund'), 'id' => 'desc-order-standard_refund', - 'desc' => ($hasOrderDiscountOrPayment) ? $this->l('Initiate refund') : $this->l('Cancel bookings'), + 'desc' => $this->l('Initiate refund'), 'class' => 'icon-exchange', 'target' => true, ); @@ -881,14 +884,21 @@ class AdminOrdersControllerCore extends AdminController // set modal details $response['hasError'] = 1; if (Validate::isLoadedObject($objOrder = new Order(Tools::getValue('id_order')))) { - $htlOrderStatus = HotelBookingDetail::getAllHotelOrderStatus(); + $objHotelBookingStatus = new HotelBookingStatus(); + $currentRoomStatus = (int) Tools::getValue('current_room_status'); + $htlOrderStatus = $objHotelBookingStatus->getAllStatuses($this->context->language->id); + $allowedStatuses = HotelBookingStatus::getAllowedTransitions($currentRoomStatus); + foreach ($htlOrderStatus as &$status) { + $status['disabled'] = !in_array((int) $status['id_status'], $allowedStatuses); + } + unset($status); $this->context->smarty->assign( array( 'order' => $objOrder, 'current_index' => self::$currentIndex, 'hotel_order_status' => $htlOrderStatus, - 'ROOM_STATUS_ALLOTED' => HotelBookingDetail::STATUS_ALLOTED, - 'current_room_status' => Tools::getValue('current_room_status') + 'ROOM_STATUS_ASSIGNED' => HotelBookingDetail::STATUS_ASSIGNED, + 'current_room_status' => $currentRoomStatus ) ); $modal = array( @@ -909,7 +919,7 @@ class AdminOrdersControllerCore extends AdminController $this->context->smarty->assign($modal); $response['hasError'] = 0; - $response['STATUS_ALLOTED'] = HotelBookingDetail::STATUS_ALLOTED; + $response['STATUS_ASSIGNED'] = HotelBookingDetail::STATUS_ASSIGNED; $response['STATUS_CHECKED_IN'] = HotelBookingDetail::STATUS_CHECKED_IN; $response['STATUS_CHECKED_OUT'] = HotelBookingDetail::STATUS_CHECKED_OUT; $response['modalHtml'] = $this->context->smarty->fetch('modal.tpl'); @@ -1157,59 +1167,47 @@ class AdminOrdersControllerCore extends AdminController $objBookingDetail = new HotelBookingDetail(); $objServiceProductOrderDetail = new ServiceProductOrderDetail(); $objOrderReturn = new OrderReturn(); - $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']) { - unset($bookingOrderInfo[$key]); - } else { - $bookingOrderInfo[$key]['total_price_tax_incl'] += $objServiceProductOrderDetail->getRoomTypeServiceProducts( - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 1, - 1, - null, - null, - 0, - $booking['id'] - ); - $bookingOrderInfo[$key]['total_price_tax_excl'] += $objServiceProductOrderDetail->getRoomTypeServiceProducts( - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 1, - 0, - null, - null, - 0, - $booking['id'] - ); - } + // multiple refund requests are allowed per booking, no matter its + // current status — always selectable, never excluded from this list + $bookingOrderInfo[$key]['total_price_tax_incl'] += $objServiceProductOrderDetail->getRoomTypeServiceProducts( + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 1, + null, + null, + 0, + $booking['id'] + ); + $bookingOrderInfo[$key]['total_price_tax_excl'] += $objServiceProductOrderDetail->getRoomTypeServiceProducts( + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 0, + null, + null, + 0, + $booking['id'] + ); } } - $refundReqProducts = $objOrderReturn->getOrderRefundRequestedProducts($objOrder->id, 0, 1, 1); + // multiple refund requests are allowed per product, no matter its + // current status — always selectable, never excluded from this list $hotelProducts = $objServiceProductOrderDetail->getServiceProductsInOrder($objOrder->id, 0, 0, Product::SELLING_PREFERENCE_HOTEL_STANDALONE); - foreach($hotelProducts as $key => $product) { - if ((in_array($product['id_service_product_order_detail'], $refundReqProducts)) || $product['is_refunded']) { - unset($hotelProducts[$key]); - } - } $standaloneProducts = $objServiceProductOrderDetail->getServiceProductsInOrder($objOrder->id, 0, 0, Product::SELLING_PREFERENCE_STANDALONE); - foreach($standaloneProducts as $key => $product) { - if ((in_array($product['id_service_product_order_detail'], $refundReqProducts)) || $product['is_refunded']) { - unset($standaloneProducts[$key]); - } - } $this->context->smarty->assign( array( @@ -1223,7 +1221,7 @@ class AdminOrdersControllerCore extends AdminController $modal = array( 'modal_id' => 'cancel-room-booking-modal', 'modal_class' => 'modal-md order_detail_modal', - 'modal_title' => '  '.$this->l('Cancel Request'), + 'modal_title' => '  '.$this->l('Refund Request'), 'modal_content' => $this->context->smarty->fetch('controllers/orders/modals/_cancel_room_bookings.tpl'), ); @@ -1233,7 +1231,7 @@ class AdminOrdersControllerCore extends AdminController 'type' => 'button', 'value' => 'submitCancelBooking', 'class' => 'submitCancelBooking btn-primary pull-right', - 'label' => ' '.$this->l('Cancel Bookings'), + 'label' => ' '.$this->l('Initiate Refund'), ) ); } @@ -1565,7 +1563,7 @@ class AdminOrdersControllerCore extends AdminController LEFT JOIN ( SELECT GROUP_CONCAT( CASE - WHEN `id_status`='.HotelBookingDetail::STATUS_ALLOTED.' THEN \''.$this->l('Alloted').'\' + WHEN `id_status`='.HotelBookingDetail::STATUS_ASSIGNED.' THEN \''.$this->l('Assigned').'\' WHEN `id_status`='.HotelBookingDetail::STATUS_CHECKED_IN.' THEN \''.$this->l('Checked in').'\' WHEN `id_status`='.HotelBookingDetail::STATUS_CHECKED_OUT.' THEN \''.$this->l('Checked out').'\' ELSE \''.$this->l('Invalid status').'\' @@ -1983,30 +1981,8 @@ class AdminOrdersControllerCore extends AdminController /* booking refunds from order */ elseif (Tools::isSubmit('initiateRefund') && isset($order)) { if ($this->tabAccess['edit'] === 1) { - $objOrderReturn = new OrderReturn(); $bookings = Tools::getValue('id_htl_booking'); - if ($bookings && count($bookings)) { - $refundReqBookings = $objOrderReturn->getOrderRefundRequestedBookings($order->id, 0, 1, 0, 1); - foreach ($bookings as $idHtlBooking) { - $objBookingDetail = new HotelBookingDetail($idHtlBooking); - if ((in_array($idHtlBooking, $refundReqBookings)) || $objBookingDetail->is_refunded) { - $this->errors[] = Tools::displayError('Wrong bookings found for cancelation.'); - break; - } - } - } - $idServiceProductOrderDetails = Tools::getValue('id_service_product_order_detail'); - if ($idServiceProductOrderDetails) { - $refundReqProducts = $objOrderReturn->getOrderRefundRequestedProducts($order->id, 0, 1, 1); - foreach ($idServiceProductOrderDetails as $idServiceProductOrderDetail) { - $objServiceProductOrderDetail = new ServiceProductOrderDetail($idServiceProductOrderDetail); - if ((in_array($idServiceProductOrderDetail, $refundReqProducts)) || $objServiceProductOrderDetail->is_refunded) { - $this->errors[] = Tools::displayError('Wrong products found for cancelation.'); - break; - } - } - } if (!$bookings && !$idServiceProductOrderDetails) { $this->errors[] = Tools::displayError('No booking/products has been selected.'); @@ -2025,6 +2001,7 @@ class AdminOrdersControllerCore extends AdminController $objOrderReturn->by_admin = 1; $objOrderReturn->question = $refundReason; $objOrderReturn->refunded_amount = 0; + $objOrderReturn->event_type = OrderReturn::EVENT_TYPE_REFUND; $objOrderReturn->save(); if ($objOrderReturn->id) { if ($bookings) { @@ -2040,9 +2017,6 @@ class AdminOrdersControllerCore extends AdminController $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(); } } @@ -2056,9 +2030,6 @@ class AdminOrdersControllerCore extends AdminController $objOrderReturnDetail->product_quantity = $objServiceProductOrderDetail->quantity; $objOrderReturnDetail->id_service_product_order_detail = $idServiceProductOrderDetail; $objOrderReturnDetail->refunded_amount = 0; - if (!$order->getCartRules() && $order->getTotalPaid() <= 0) { - $objOrderReturnDetail->id_customization = 1; - } $objOrderReturnDetail->save(); } } @@ -2067,47 +2038,6 @@ class AdminOrdersControllerCore extends AdminController // 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 - if ($bookings) { - foreach ($bookings as $idHtlBooking) { - $objHtlBooking = new HotelBookingDetail($idHtlBooking); - if (!$objHtlBooking->processRefundInBookingTables()) { - $this->errors[] = Tools::displayError('An error occurred while cancelling the booking.'); - } - } - } - if ($idServiceProductOrderDetails) { - foreach ($idServiceProductOrderDetails as $idServiceProductOrderDetail) { - $objServiceProductOrderDetail = new ServiceProductOrderDetail($idServiceProductOrderDetail); - if (!$objServiceProductOrderDetail->processRefundInTables()) { - $this->errors[] = Tools::displayError('An error occurred while cancelling the product.'); - } - } - } - - // 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 = $order->getOrderCompleteRefundStatus(); - - if ($idOrderState) { - $objOrderHistory = new OrderHistory(); - $objOrderHistory->id_order = (int)$order->id; - - $useExistingPayment = false; - if (!$order->hasInvoice()) { - $useExistingPayment = true; - } - - $objOrderHistory->changeIdOrderState($idOrderState, $order, $useExistingPayment); - $objOrderHistory->addWithemail(); - } - } } // Redirect if no errors @@ -3187,7 +3117,7 @@ class AdminOrdersControllerCore extends AdminController $helper->color = 'color1'; $helper->title = $this->l('Arrivals', null, null, false); $helper->subtitle = $this->l('Today', null, null, false); - $helper->href = $this->context->link->getAdminLink('AdminOrders').'&submitResetorder&submitFilterorder=1&orderFilter_hbd!is_refunded=0&orderFilter_hbd!id_status='.HotelBookingDetail::STATUS_ALLOTED.'&orderFilter_hbd!date_from[]='.pSQL(date('Y-m-d')).'&orderFilter_hbd!date_from[]='.pSQL(date('Y-m-d')); + $helper->href = $this->context->link->getAdminLink('AdminOrders').'&submitResetorder&submitFilterorder=1&orderFilter_rrb!is_room_refunded=0&orderFilter_hbd!id_status='.HotelBookingDetail::STATUS_ASSIGNED.'&orderFilter_hbd!date_from[]='.pSQL(date('Y-m-d')).'&orderFilter_hbd!date_from[]='.pSQL(date('Y-m-d')); $helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=today_arrivals'; $helper->tooltip = $this->l('Total number of arrivals for today.', null, null, false); $this->kpis[] = $helper; @@ -3199,7 +3129,7 @@ class AdminOrdersControllerCore extends AdminController $helper->color = 'color2'; $helper->title = $this->l('Departures', null, null, false); $helper->subtitle = $this->l('Today', null, null, false); - $helper->href = $this->context->link->getAdminLink('AdminOrders').'&submitResetorder&submitFilterorder=1&orderFilter_hbd!is_refunded=0&orderFilter_hbd!id_status='.HotelBookingDetail::STATUS_CHECKED_IN.'&orderFilter_hbd!date_to[]='.pSQL(date('Y-m-d')).'&orderFilter_hbd!date_to[]='.pSQL(date('Y-m-d')); + $helper->href = $this->context->link->getAdminLink('AdminOrders').'&submitResetorder&submitFilterorder=1&orderFilter_rrb!is_room_refunded=0&orderFilter_hbd!id_status='.HotelBookingDetail::STATUS_CHECKED_IN.'&orderFilter_hbd!date_to[]='.pSQL(date('Y-m-d')).'&orderFilter_hbd!date_to[]='.pSQL(date('Y-m-d')); $helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=today_departures'; $helper->tooltip = $this->l('Total number of departures for today.', null, null, false); $this->kpis[] = $helper; @@ -3212,7 +3142,7 @@ class AdminOrdersControllerCore extends AdminController $helper->color = 'color4'; $helper->title = $this->l('Occupied Rooms', null, null, false); $helper->subtitle = $this->l('Today', null, null, false); - $helper->href = $this->context->link->getAdminLink('AdminOrders').'&submitResetorder&submitFilterorder=1&orderFilter_hbd!is_refunded=0&orderFilter_hbd!id_status='.HotelBookingDetail::STATUS_CHECKED_IN.'&orderFilter_hbd!date_to[]='.pSQL(date('Y-m-d', strtotime('+ 1 days'))).'&orderFilter_hbd!date_to[]='; + $helper->href = $this->context->link->getAdminLink('AdminOrders').'&submitResetorder&submitFilterorder=1&orderFilter_rrb!is_room_refunded=0&orderFilter_hbd!id_status='.HotelBookingDetail::STATUS_CHECKED_IN.'&orderFilter_hbd!date_to[]='.pSQL(date('Y-m-d', strtotime('+ 1 days'))).'&orderFilter_hbd!date_to[]='; $helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=occupied_rooms'; $helper->tooltip = $this->l('The count of rooms that are currently occupied by guests.', null, null, false); $this->kpis[] = $helper; @@ -3490,6 +3420,22 @@ class AdminOrdersControllerCore extends AdminController $cart_id = Cart::getCartIdByOrderId(Tools::getValue('id_order')); $cart_detail_data_obj = new HotelCartBookingData(); $objBookingDetail = new HotelBookingDetail(); + $objOrderReturn = new OrderReturn(); + + // same refund totals shown for room bookings (Refund column: amount + request + // count), for the Products Detail table's standalone/hotel service products + foreach ($orderHotelServiceProducts as &$hotelServiceProduct) { + $productRefundInfo = $objOrderReturn->getRefundedAmount($order->id, 0, 0, true, $hotelServiceProduct['id_service_product_order_detail']); + $hotelServiceProduct['refund_amount'] = $productRefundInfo['amount']; + $hotelServiceProduct['refund_count'] = (int) $productRefundInfo['count']; + } + unset($hotelServiceProduct); + foreach ($orderStandaloneServiceProducts as &$standaloneServiceProduct) { + $productRefundInfo = $objOrderReturn->getRefundedAmount($order->id, 0, 0, true, $standaloneServiceProduct['id_service_product_order_detail']); + $standaloneServiceProduct['refund_amount'] = $productRefundInfo['amount']; + $standaloneServiceProduct['refund_count'] = (int) $productRefundInfo['count']; + } + unset($standaloneServiceProduct); $total_room_tax = 0; $totalRoomsCostTE = 0; @@ -3655,11 +3601,16 @@ class AdminOrdersControllerCore extends AdminController $order_detail_data[$key]['num_checkin_documents'] = HotelBookingDocument::getCountByIdHtlBooking($value['id']); $order_detail_data[$key]['connected_rooms'] = HotelConnectedRoom::getConnectedRooms($value['id_room'], null, null, (int) Context::getContext()->language->id); + $roomRefundInfo = $objOrderReturn->getRefundedAmount($order->id, 0, $value['id'], true); + $order_detail_data[$key]['refund_amount'] = $roomRefundInfo['amount']; + $order_detail_data[$key]['refund_count'] = (int) $roomRefundInfo['count']; + $order_detail_data[$key]['is_refunded'] = $objOrderReturn->hasCompletelyRefundedBooking($value['id']); + if (isset($value['refund_info']) && $value['refund_info']['refunded'] && $value['refund_info']['id_customization'] - && $value['is_refunded'] - && !$value['is_cancelled'] + && $objOrderReturn->hasCompletelyRefundedBooking($value['id']) + && $value['id_status'] != HotelBookingDetail::STATUS_CANCELLED ) { $totalRefundedRooms += 1; } @@ -3730,23 +3681,34 @@ class AdminOrdersControllerCore extends AdminController } - $objOrderReturn = new OrderReturn(); $refundedAmount = $objOrderReturn->getRefundedAmount($order->id); - $refundReqBookings = $objOrderReturn->getOrderRefundRequestedBookings($order->id, 0, 1, 0, 1); - $refundReqProducts = $objOrderReturn->getOrderRefundRequestedProducts($order->id, 0, 1, 1); + $refundReqBookings = $objOrderReturn->getOrderRefundRequestedBookings($order->id, 0, 1); + $refundReqProducts = $objOrderReturn->getOrderRefundRequestedProducts($order->id, 0, 1); // get booking information by order $bookingOrderInfo = $objBookingDetail->getBookingDataByOrderId($order->id); foreach ($bookingOrderInfo as &$bookingOrderRoomInfo) { // Get last refund request for booking + $bookingOrderRoomInfo['is_sealed_no_show'] = false; + $bookingOrderRoomInfo['is_sealed_cancelled'] = false; + $bookingOrderRoomInfo['is_refunded'] = $objOrderReturn->hasCompletelyRefundedBooking($bookingOrderRoomInfo['id']); if ($bookingRefundDetail = OrderReturn::getOrdersReturnDetail($bookingOrderRoomInfo['id_order'], 0, $bookingOrderRoomInfo['id'])) { $bookingRefundDetail = reset($bookingRefundDetail); - if (!$bookingRefundDetail['id_customization']) { - $bookingOrderRoomInfo['is_refunded'] = 0; - } + // a Cancellation/No-show request seals the room the moment it's created — + // its fate doesn't wait for the refund to actually be approved/completed + $bookingOrderRoomInfo['is_sealed_no_show'] = ($bookingRefundDetail['event_type'] == OrderReturn::EVENT_TYPE_NO_SHOW); + $bookingOrderRoomInfo['is_sealed_cancelled'] = ($bookingRefundDetail['event_type'] == OrderReturn::EVENT_TYPE_CANCELLATION); } $bookingOrderRoomInfo['num_checkin_documents'] = HotelBookingDocument::getCountByIdHtlBooking($bookingOrderRoomInfo['id']); } + unset($bookingOrderRoomInfo); + + // catalog of the 5 booking statuses (id_booking_status => color/name), for the + // Rooms Booking Detail table's status badge + $htlBookingStatuses = array(); + foreach ((new HotelBookingStatus())->getAllStatuses($this->context->language->id) as $htlBookingStatus) { + $htlBookingStatuses[$htlBookingStatus['id_status']] = $htlBookingStatus; + } $objHotelBookingDetail = new HotelBookingDetail(); $htlBookingDetail = $objHotelBookingDetail->getOrderCurrentDataByOrderId($order->id); @@ -3802,6 +3764,36 @@ class AdminOrdersControllerCore extends AdminController } } + // merge in room status change history (with remarks) as Order Notes entries + if ($statusHistoryRows = (new HotelBookingStatusHistory())->getBookingStatusHistoryByOrder($order->id)) { + $roomStatusLabels = array( + HotelBookingDetail::STATUS_ASSIGNED => $this->l('Assigned'), + HotelBookingDetail::STATUS_CHECKED_IN => $this->l('Checked in'), + HotelBookingDetail::STATUS_CHECKED_OUT => $this->l('Checked out'), + HotelBookingDetail::STATUS_NO_SHOW => $this->l('No-show'), + HotelBookingDetail::STATUS_CANCELLED => $this->l('Cancelled'), + ); + foreach ($statusHistoryRows as $historyRow) { + $newStatusLabel = isset($roomStatusLabels[$historyRow['id_status_to']]) + ? $roomStatusLabels[$historyRow['id_status_to']] + : $historyRow['id_status_to']; + $roomType = Product::getProductName((int) $historyRow['id_product'], null, $this->context->language->id); + $autoMsg = $this->l('Room Status Update').': '.$historyRow['room_num'].' - '.$roomType.': (' + .date('d/m/Y', strtotime($historyRow['date_from'])).' - '.date('d/m/Y', strtotime($historyRow['date_to'])).') - '.$newStatusLabel; + $messages[] = array( + 'message' => $autoMsg.($historyRow['remark'] ? ' | '.$this->l('Remark').': '.$historyRow['remark'] : ''), + 'date_add' => $historyRow['date_add'], + 'efirstname' => $historyRow['efirstname'], + 'elastname' => $historyRow['elastname'], + 'cfirstname' => $historyRow['cfirstname'], + 'clastname' => $historyRow['clastname'], + ); + } + usort($messages, function ($a, $b) { + return (strtotime($a['date_add']) < strtotime($b['date_add'])) ? 1 : -1; + }); + } + // send hotel standalone and standalone products $objProduct = new Product(); $hotelStandaloneProducts = $objProduct->getServiceProducts(null, Product::SELLING_PREFERENCE_HOTEL_STANDALONE); @@ -3828,6 +3820,7 @@ class AdminOrdersControllerCore extends AdminController 'totalRoomsCostTE' => $totalRoomsCostTE, 'total_room_tax' => $total_room_tax, 'htl_booking_order_data' => $bookingOrderInfo, + 'htl_booking_statuses' => $htlBookingStatuses, 'hotel_order_status' => $htlOrderStatus, 'order_detail_data' => $order_detail_data, 'use_tourism_tax' => $useTourismTax, @@ -3925,6 +3918,8 @@ class AdminOrdersControllerCore extends AdminController 'orderDocuments' => $order->getDocuments(), 'ROOM_STATUS_CHECKED_IN' => HotelBookingDetail::STATUS_CHECKED_IN, 'ROOM_STATUS_CHECKED_OUT' => HotelBookingDetail::STATUS_CHECKED_OUT, + 'ROOM_STATUS_NO_SHOW' => HotelBookingDetail::STATUS_NO_SHOW, + 'ROOM_STATUS_CANCELLED' => HotelBookingDetail::STATUS_CANCELLED, 'ALLOTMENT_MANUAL' => HotelBookingDetail::ALLOTMENT_MANUAL, 'order_convenience_fee_services' => $orderConvenienceFeeServices, 'page_header_toolbar_btn' => $this->page_header_toolbar_btn, @@ -6109,15 +6104,8 @@ class AdminOrdersControllerCore extends AdminController public function updateOrderStatusOnOrderChange($objOrder) { // If order is completely refunded or cancelled then change the order state - if ($idOrderState = $objOrder->getOrderCompleteRefundStatus()) { - $objOrderHistory = new OrderHistory(); - $objOrderHistory->id_order = (int)$objOrder->id; - $useExistingPayment = false; - if (!$objOrder->hasInvoice()) { - $useExistingPayment = true; - } - $objOrderHistory->changeIdOrderState($idOrderState, $objOrder, $useExistingPayment); - $objOrderHistory->add(); + if ($objOrder->getOrderCompleteRefundStatus()) { + $objOrder->syncRefundStatus(false); } else { $currentOrderState = $objOrder->getCurrentOrderState(); if ($currentOrderState->paid == 1) { @@ -7247,14 +7235,19 @@ class AdminOrdersControllerCore extends AdminController $refundReqBookings = $objOrderReturn->getOrderRefundRequestedBookings($order->id, 0, 1); $objBookingDetail = new HotelBookingDetail($id_hotel_booking); if ($refundReqBookings && (in_array($id_hotel_booking, $refundReqBookings))) { - // If order is cancelled, we can't edit order - if ($objBookingDetail->is_refunded && $objBookingDetail->is_cancelled) { + // If booking is cancelled or no-show, we can't edit it at all + if (($objBookingDetail->id_status == HotelBookingDetail::STATUS_CANCELLED + || $objBookingDetail->id_status == HotelBookingDetail::STATUS_NO_SHOW) + && $objOrderReturn->hasCompletelyRefundedBooking($id_hotel_booking) + ) { die(json_encode(array( 'result' => false, - 'error' => Tools::displayError('Booking cannot be edited if booking is cancelled.'), + 'error' => ($objBookingDetail->id_status == HotelBookingDetail::STATUS_NO_SHOW) + ? Tools::displayError('Booking cannot be edited if booking is marked No-show.') + : Tools::displayError('Booking cannot be edited if booking is cancelled.'), ))); // If order is refunded, we can't edit dates - } elseif ($objBookingDetail->is_refunded + } elseif ($objOrderReturn->hasCompletelyRefundedBooking($id_hotel_booking) && (strtotime($old_date_from) != strtotime($new_date_from) || strtotime($old_date_to) != strtotime($new_date_to)) ) { die(json_encode(array( @@ -7264,7 +7257,7 @@ class AdminOrdersControllerCore extends AdminController } } - if ($objBookingDetail->id_status != HotelBookingDetail::STATUS_ALLOTED + if ($objBookingDetail->id_status != HotelBookingDetail::STATUS_ASSIGNED && strtotime($old_date_from) != strtotime($new_date_from) ) { die(json_encode(array( @@ -8784,6 +8777,7 @@ class AdminOrdersControllerCore extends AdminController $idHotelBookingDetail = (int) Tools::getValue('id_hotel_booking_detail'); if (Validate::isLoadedObject($objHotelBookingDetail = new HotelBookingDetail($idHotelBookingDetail))) { $newStatus = (int) Tools::getValue('booking_order_status'); + $statusRemark = Tools::getValue('status_remark'); // date choosen for the status change if ($statusDate = Tools::getValue('status_date')) { $statusDate = date('Y-m-d H:i:s', strtotime($statusDate)); @@ -8793,6 +8787,13 @@ class AdminOrdersControllerCore extends AdminController $dateTo = date('Y-m-d H:i:s', strtotime(date('Y-m-d', strtotime($objHotelBookingDetail->date_to)).' 23:59:59')); if (!$newStatus) { $this->errors[] = Tools::displayError('Invalid booking status found.'); + } elseif ($newStatus == $objHotelBookingDetail->id_status) { + $this->errors[] = Tools::displayError('This room is already set to the selected status.'); + } elseif (($newStatus == HotelBookingDetail::STATUS_NO_SHOW || $newStatus == HotelBookingDetail::STATUS_CANCELLED) + && ($objHotelBookingDetail->id_status == HotelBookingDetail::STATUS_CHECKED_IN + || $objHotelBookingDetail->id_status == HotelBookingDetail::STATUS_CHECKED_OUT) + ) { + $this->errors[] = Tools::displayError('Room status cannot be changed to No-show or Cancelled once the guest has already checked in.'); } elseif ($newStatus == HotelBookingDetail::STATUS_CHECKED_IN || $newStatus == HotelBookingDetail::STATUS_CHECKED_OUT ) { @@ -8803,6 +8804,8 @@ class AdminOrdersControllerCore extends AdminController ) { $this->errors[] = Tools::displayError('Date should be between booking from date and to date.'); } + } elseif ($newStatus == HotelBookingDetail::STATUS_NO_SHOW && strtotime($dateFrom) > time()) { + $this->errors[] = Tools::displayError('Room cannot be marked as No-show before the booking\'s check-in date.'); } if ($objHotelBookingDetail->id_status == HotelBookingDetail::STATUS_CHECKED_OUT @@ -8834,7 +8837,7 @@ class AdminOrdersControllerCore extends AdminController if ($newStatus == HotelBookingDetail::STATUS_CHECKED_OUT) { $orderBookings = $objHotelBookingDetail->getOrderCurrentDataByOrderId( $id_order, - array(HotelBookingDetail::STATUS_ALLOTED, HotelBookingDetail::STATUS_CHECKED_IN), + array(HotelBookingDetail::STATUS_ASSIGNED, HotelBookingDetail::STATUS_CHECKED_IN), 0, 0 ); @@ -8845,26 +8848,85 @@ class AdminOrdersControllerCore extends AdminController if ($remainingCheckoutRooms == 1 && $newStatus == HotelBookingDetail::STATUS_CHECKED_OUT && $hasPendingBills) { $this->errors[] = Tools::displayError('You cannot checkout the last room while there are pending bills for this order.'); } else { - $objHotelBookingDetail->id_status = $newStatus; if ($newStatus == HotelBookingDetail::STATUS_CHECKED_IN) { $objHotelBookingDetail->check_in = $statusDate; + // reverting from Checked-out: clear the stale check-out timestamp + $objHotelBookingDetail->check_out = ''; } elseif ($newStatus == HotelBookingDetail::STATUS_CHECKED_OUT) { $objHotelBookingDetail->check_out = $statusDate; } else { $objHotelBookingDetail->check_in = ''; $objHotelBookingDetail->check_out = ''; } - if ($objHotelBookingDetail->save()) { - Hook::exec( - 'actionRoomBookingStatusUpdateAfter', - array( - 'id_hotel_booking_detail' => $objHotelBookingDetail->id, - 'id_order' => $objHotelBookingDetail->id_order, - 'id_room' => $objHotelBookingDetail->id_room, - 'date_from' => $objHotelBookingDetail->date_from, - 'date_to' => $objHotelBookingDetail->date_to - ) + + $changeParams = array( + 'id_employee' => (int) $this->context->employee->id, + 'remark' => $statusRemark, + ); + + if ($newStatus == HotelBookingDetail::STATUS_CANCELLED || $newStatus == HotelBookingDetail::STATUS_NO_SHOW) { + // picking Cancelled/No-show also creates the matching refund + // request, always left Pending for approval in Manage Order + // Refund Requests — same regardless of order payment status + $eventType = ($newStatus == HotelBookingDetail::STATUS_CANCELLED) + ? OrderReturn::EVENT_TYPE_CANCELLATION + : OrderReturn::EVENT_TYPE_NO_SHOW; + + $objOrderReturn = new OrderReturn(); + $objOrderReturn->id_customer = $order->id_customer; + $objOrderReturn->id_order = $order->id; + $objOrderReturn->state = 0; + $objOrderReturn->by_admin = 1; + $objOrderReturn->question = $statusRemark; + $objOrderReturn->refunded_amount = 0; + $objOrderReturn->event_type = $eventType; + $objOrderReturn->save(); + + $objOrderReturnDetail = new OrderReturnDetail(); + $objOrderReturnDetail->id_order_return = $objOrderReturn->id; + $objOrderReturnDetail->id_order_detail = $objHotelBookingDetail->id_order_detail; + $objOrderReturnDetail->product_quantity = HotelHelper::getNumberOfDays( + $objHotelBookingDetail->date_from, + $objHotelBookingDetail->date_to ); + $objOrderReturnDetail->id_htl_booking = $objHotelBookingDetail->id; + $objOrderReturnDetail->refunded_amount = 0; + $objOrderReturnDetail->save(); + + $objOrderReturn->changeIdOrderReturnState(Configuration::get('PS_ORS_PENDING')); + + // the room's own status (htl_booking_detail.id_status) flips right + // away — that's a factual room-state decision, independent of the + // refund request's own approval state + $statusChanged = $objHotelBookingDetail->changeStatus($newStatus, $changeParams); + + if ($statusChanged) { + // if every room in the order is now No-show or Cancelled, bump + // the order's own status right away — that's decided by room + // status alone, independent of whether the underlying refund + // request has actually been approved yet + $order = new Order($order->id); + $order->syncRefundStatus(); + } + $success = $statusChanged; + } else { + $statusChanged = $objHotelBookingDetail->changeStatus($newStatus, $changeParams); + $success = $statusChanged; + } + + if ($success) { + if ($statusChanged) { + Hook::exec( + 'actionRoomBookingStatusUpdateAfter', + array( + 'id_hotel_booking_detail' => $objHotelBookingDetail->id, + 'id_order' => $objHotelBookingDetail->id_order, + 'id_room' => $objHotelBookingDetail->id_room, + 'date_from' => $objHotelBookingDetail->date_from, + 'date_to' => $objHotelBookingDetail->date_to + ) + ); + } Tools::redirectAdmin(self::$currentIndex . '&id_order=' . (int) $objHotelBookingDetail->id_order . '&vieworder&token=' . $this->token . '&conf=4'); } else { diff --git a/controllers/admin/AdminStatsController.php b/controllers/admin/AdminStatsController.php index d0df516d9..796d62080 100644 --- a/controllers/admin/AdminStatsController.php +++ b/controllers/admin/AdminStatsController.php @@ -1118,7 +1118,7 @@ class AdminStatsControllerCore extends AdminStatsTabController date('Y-m-d'), date('Y-m-d', strtotime('+1 day')), $idHotels, - HotelBookingDetail::STATUS_ALLOTED + HotelBookingDetail::STATUS_ASSIGNED ); break; @@ -1279,7 +1279,7 @@ class AdminStatsControllerCore extends AdminStatsTabController $totalArrivals = Db::getInstance()->getValue( 'SELECT COUNT(hbd.`id_room`) FROM `'._DB_PREFIX_.'htl_booking_detail` hbd - WHERE hbd.`is_refunded` = 0 AND hbd.`is_back_order` = 0 + WHERE hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().') AND hbd.`is_back_order` = 0 AND hbd.`date_from` BETWEEN "'.pSQL($date).' 00:00:00" AND "'.pSQL($date).' 23:59:59"'. HotelBranchInformation::addHotelRestriction($idHotel, 'hbd') ); @@ -1287,7 +1287,7 @@ class AdminStatsControllerCore extends AdminStatsTabController $arrived = Db::getInstance()->getValue( 'SELECT COUNT(hbd.`id_room`) FROM `'._DB_PREFIX_.'htl_booking_detail` hbd - WHERE hbd.`is_refunded` = 0 AND hbd.`is_back_order` = 0 + WHERE hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().') AND hbd.`is_back_order` = 0 AND hbd.`date_from` BETWEEN "'.pSQL($date).' 00:00:00" AND "'.pSQL($date).' 23:59:59" AND hbd.`id_status` = '.(int) HotelBookingDetail::STATUS_CHECKED_IN. HotelBranchInformation::addHotelRestriction($idHotel, 'hbd') @@ -1301,7 +1301,7 @@ class AdminStatsControllerCore extends AdminStatsTabController $totalDepartures = Db::getInstance()->getValue( 'SELECT COUNT(hbd.`id_room`) FROM `'._DB_PREFIX_.'htl_booking_detail` hbd - WHERE hbd.`is_refunded` = 0 + WHERE hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().') AND ((hbd.`id_status` = '.(int) HotelBookingDetail::STATUS_CHECKED_IN.') OR (hbd.`check_in` != "0000:00:00 00:00:00" AND hbd.`check_out` != "0000:00:00 00:00:00")) AND hbd.`date_to` BETWEEN "'.pSQL($date).' 00:00:00" AND "'.pSQL($date).' 23:59:59"'. @@ -1311,7 +1311,7 @@ class AdminStatsControllerCore extends AdminStatsTabController $departed = Db::getInstance()->getValue( 'SELECT COUNT(hbd.`id_room`) FROM `'._DB_PREFIX_.'htl_booking_detail` hbd - WHERE hbd.`is_refunded` = 0 + WHERE hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().') AND hbd.`date_to` BETWEEN "'.pSQL($date).' 00:00:00" AND "'.pSQL($date).' 23:59:59" AND hbd.`id_status` = '.(int) HotelBookingDetail::STATUS_CHECKED_OUT.' AND hbd.`check_in` != "0000:00:00 00:00:00"'. @@ -1336,7 +1336,7 @@ class AdminStatsControllerCore extends AdminStatsTabController return Db::getInstance()->getValue( 'SELECT COUNT(hbd.`id_room`) FROM `'._DB_PREFIX_.'htl_booking_detail` hbd - WHERE hbd.`is_refunded` = 0 AND hbd.`is_back_order` = 0 + WHERE hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().') AND hbd.`is_back_order` = 0 AND hbd.`id_status` = '.(int) HotelBookingDetail::STATUS_CHECKED_IN.' AND hbd.`date_to` > "'.pSQL($date).' 00:00:00"'. HotelBranchInformation::addHotelRestriction($idHotel, 'hbd') @@ -1364,7 +1364,7 @@ class AdminStatsControllerCore extends AdminStatsTabController return Db::getInstance()->getRow( 'SELECT SUM(hbd.`adults`) AS `adults`, SUM(hbd.`children`) AS `children` FROM `'._DB_PREFIX_.'htl_booking_detail` hbd - WHERE hbd.`is_refunded` = 0 AND hbd.`is_back_order` = 0 + WHERE hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().') AND hbd.`is_back_order` = 0 AND hbd.`date_from` BETWEEN "'.pSQL($date).' 00:00:00" AND "'.pSQL($date).' 23:59:59"'. HotelBranchInformation::addHotelRestriction($idHotel, 'hbd') ); @@ -1427,7 +1427,7 @@ class AdminStatsControllerCore extends AdminStatsTabController ON (p.`id_product` = hri.`id_product`) WHERE p.`active` = 1 AND p.`booking_product` = 1 - AND hbd.`is_refunded` = 0 + AND hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().') AND hbd.`date_from` < "'.pSQL($dateTo).'" AND IF(hbd.`id_status` = '.(int)HotelBookingDetail::STATUS_CHECKED_OUT.', DATE_FORMAT(hbd.`check_out`, "%Y-%m-%d"), @@ -1476,7 +1476,7 @@ class AdminStatsControllerCore extends AdminStatsTabController WHERE hri.`id_status` = '.(int)HotelRoomInformation::STATUS_INACTIVE.' AND p.`active` = 1 AND p.`booking_product` = 1 - AND hbd.`is_refunded` = 0 + AND hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().') AND hbd.`date_from` < "'.pSQL($dateTo).'" AND IF(hbd.`id_status` = '.(int)HotelBookingDetail::STATUS_CHECKED_OUT.', DATE_FORMAT(hbd.`check_out`, "%Y-%m-%d"), @@ -1540,7 +1540,7 @@ class AdminStatsControllerCore extends AdminStatsTabController WHERE hri.`id_status` = '.(int)HotelRoomInformation::STATUS_TEMPORARY_INACTIVE.' AND p.`active` = 1 AND p.`booking_product` = 1 - AND hbd.`is_refunded` = 0 + AND hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().') AND hrdd.`date_from` < "'.pSQL($dateTo).'" AND hrdd.`date_to` > "'.pSQL($dateFrom).'" AND hbd.`date_from` < "'.pSQL($dateTo).'" @@ -1637,7 +1637,7 @@ class AdminStatsControllerCore extends AdminStatsTabController $cancelledBookings = Db::getInstance()->getValue( 'SELECT COUNT(hbd.`id`) FROM `'._DB_PREFIX_.'htl_booking_detail` hbd - WHERE hbd.`is_refunded` = 1 AND hbd.`date_add` BETWEEN "'.pSQL($dateFrom).' 00:00:00" AND "'.pSQL($dateTo).' 23:59:59"'. + WHERE hbd.`id` IN ('.OrderReturn::getRefundedBookingIdsSubquery(OrderReturn::EVENT_TYPE_CANCELLATION).') AND hbd.`date_add` BETWEEN "'.pSQL($dateFrom).' 00:00:00" AND "'.pSQL($dateTo).' 23:59:59"'. HotelBranchInformation::addHotelRestriction($idHotel, 'hbd') ); @@ -1676,7 +1676,7 @@ class AdminStatsControllerCore extends AdminStatsTabController IF (hbd.`id_status` = '.(int) HotelBookingDetail::STATUS_CHECKED_OUT.', IF("'.$dateFrom.'" < check_in, check_in, "'.$dateFrom.'"), IF("'.$dateFrom.'" < date_from, date_from, "'.$dateFrom.'")) )), 0) FROM `'._DB_PREFIX_.'htl_booking_detail` hbd - WHERE hbd.`is_refunded` = 0 AND hbd.`is_back_order` = 0 AND + WHERE hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().') AND hbd.`is_back_order` = 0 AND (IF (hbd.`id_status` = '.(int) HotelBookingDetail::STATUS_CHECKED_OUT.', (hbd.`check_in` < \''.pSQL($dateTo).'\' AND hbd.`check_out` >= \''.pSQL($dateFrom).'\'), (hbd.`date_from` < \''.pSQL($dateTo).'\' AND hbd.`date_to` >= \''.pSQL($dateFrom).'\') @@ -1709,7 +1709,7 @@ class AdminStatsControllerCore extends AdminStatsTabController FROM `'._DB_PREFIX_.'htl_booking_detail` hbd LEFT JOIN `'._DB_PREFIX_.'orders` o ON (o.`id_order` = hbd.`id_order`) LEFT JOIN `'._DB_PREFIX_.'customer` c ON (c.`id_customer` = hbd.`id_customer`) - WHERE hbd.`is_refunded` = 0 AND hbd.`date_from` = "'.pSQL($date).' 00:00:00" + WHERE hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().') AND hbd.`date_from` = "'.pSQL($date).' 00:00:00" AND hbd.`id_status` != '.(int) HotelBookingDetail::STATUS_CHECKED_IN.' AND hbd.`id_status` != '.(int) HotelBookingDetail::STATUS_CHECKED_OUT. (!is_null($idHotel) ? HotelBranchInformation::addHotelRestriction($idHotel, 'hbd') : ''); @@ -1726,7 +1726,7 @@ class AdminStatsControllerCore extends AdminStatsTabController FROM `'._DB_PREFIX_.'htl_booking_detail` hbd LEFT JOIN `'._DB_PREFIX_.'orders` o ON (o.`id_order` = hbd.`id_order`) LEFT JOIN `'._DB_PREFIX_.'customer` c ON (c.`id_customer` = hbd.`id_customer`) - WHERE hbd.`is_refunded` = 0 AND hbd.`date_to` = "'.pSQL($date).' 00:00:00" + WHERE hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().') AND hbd.`date_to` = "'.pSQL($date).' 00:00:00" AND hbd.`id_status` = '.(int) HotelBookingDetail::STATUS_CHECKED_IN. (!is_null($idHotel) ? HotelBranchInformation::addHotelRestriction($idHotel, 'hbd') : ''); $result = Db::getInstance()->executeS($sql); @@ -1742,7 +1742,7 @@ class AdminStatsControllerCore extends AdminStatsTabController FROM `'._DB_PREFIX_.'htl_booking_detail` hbd LEFT JOIN `'._DB_PREFIX_.'orders` o ON (o.`id_order` = hbd.`id_order`) LEFT JOIN `'._DB_PREFIX_.'customer` c ON (c.`id_customer` = hbd.`id_customer`) - WHERE hbd.`is_refunded` = 0 + WHERE hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().') AND (hbd.`id_status` = '.(int) HotelBookingDetail::STATUS_CHECKED_IN.' OR (hbd.`id_status` = '.(int) HotelBookingDetail::STATUS_CHECKED_OUT.' AND hbd.`check_out` > "'.pSQL(date('Y-m-d')).' 00:00:00")) AND hbd.`date_to` != "'.pSQL(date('Y-m-d')).' 00:00:00"'. @@ -1773,7 +1773,7 @@ class AdminStatsControllerCore extends AdminStatsTabController return $result; } - public static function getCancellationsInfoByDate($date, $idHotel = null) + public static function getCancellationsInfoByDate($date, $idHotel = null, $eventType = null) { $sql = 'SELECT orr.`id_order_return`, orr.`id_customer`, hbd.`room_num`, hbd.`id_product`, hbd.`room_type_name`, o.`with_occupancy`, CONCAT(c.`firstname`, " ", c.`lastname`) AS customer_name, hbd.`id_hotel`, @@ -1786,6 +1786,7 @@ class AdminStatsControllerCore extends AdminStatsTabController LEFT JOIN `'._DB_PREFIX_.'customer` c ON (c.`id_customer` = orr.`id_customer`) WHERE orr.`date_add` BETWEEN "'.pSQL($date).' 00:00:00" AND "'.pSQL($date).' 23:59:59" AND orr.`state` = '.(int) OrderReturnState::ORDER_RETRUN_FIRST_STATUS. + (!is_null($eventType) ? ' AND orr.`event_type` = '.(int) $eventType : ''). (!is_null($idHotel) ? HotelBranchInformation::addHotelRestriction($idHotel, 'hbd') : '').' GROUP BY ord.`id_htl_booking` ORDER BY orr.`date_add` DESC'; @@ -1803,8 +1804,8 @@ class AdminStatsControllerCore extends AdminStatsTabController LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.`id_product` = hri.`id_product`) WHERE p.`active` = 1 - AND hbd.`is_refunded` = 0 - AND hbd.`is_cancelled` = 0 '. + AND hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().') + AND hbd.`id_status` != '.HotelBookingDetail::STATUS_CANCELLED.' '. (($dateFrom && $dateTo) ? ' AND hbd.`date_from` <= "'.pSQL($dateTo).' 00:00:00" AND hbd.`date_to` > "'.pSQL($dateFrom).' 00:00:00" ': ' '). (!is_null($roomBookingStatus) ? ' AND hbd.`id_status` = '.(int) $roomBookingStatus : ' '). (!is_null($idHotel) ? HotelBranchInformation::addHotelRestriction($idHotel, 'hbd') : ''); @@ -1818,7 +1819,7 @@ class AdminStatsControllerCore extends AdminStatsTabController { $sql = 'SELECT COUNT(hbd.`id_room`) FROM `'._DB_PREFIX_.'htl_booking_detail` hbd - WHERE hbd.`is_refunded` = 0 + WHERE hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().') AND hbd.`date_from` <= "'.pSQL($dateTo).' 00:00:00" AND hbd.`date_to` > "'.pSQL($dateFrom).' 00:00:00"'. (!is_null($idHotel) ? HotelBranchInformation::addHotelRestriction($idHotel, 'hbd') : ''); @@ -1855,7 +1856,7 @@ class AdminStatsControllerCore extends AdminStatsTabController LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.`id_product` = hri.`id_product`) WHERE p.`active` = 1 - AND hbd.`is_refunded` = 0 + AND hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().') AND hbd.`date_from` < "'.pSQL($discreteDate['date_to']).' 00:00:00" AND hbd.`date_to` > "'.pSQL($discreteDate['date_from']).' 00:00:00"'. (!is_null($idHotel) ? HotelBranchInformation::addHotelRestriction($idHotel, 'hbd') : ''); @@ -1896,7 +1897,7 @@ class AdminStatsControllerCore extends AdminStatsTabController LEFT JOIN `'._DB_PREFIX_.'orders` o ON (o.`id_order` = hbd.`id_order`) WHERE p.`active` = 1 AND o.`valid` = 1 - AND hbd.`is_refunded` = 0 + AND hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().') AND hbd.`date_from` < "'.pSQL($discreteDate['date_to']).' 00:00:00" AND hbd.`date_to` > "'.pSQL($discreteDate['date_from']).' 00:00:00"'. (!is_null($idHotel) ? HotelBranchInformation::addHotelRestriction($idHotel, 'hbd') : ''); @@ -1939,7 +1940,7 @@ class AdminStatsControllerCore extends AdminStatsTabController LEFT JOIN `'._DB_PREFIX_.'orders` o ON (o.`id_order` = hbd.`id_order`) WHERE p.`active` = 1 AND o.`valid` = 1 - AND hbd.`is_refunded` = 0 + AND hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().') AND hbd.`date_from` < "'.pSQL($discreteDate['date_to']).' 00:00:00" AND hbd.`date_to` > "'.pSQL($discreteDate['date_from']).' 00:00:00"'. (!is_null($idHotel) ? HotelBranchInformation::addHotelRestriction($idHotel, 'hbd') : ''); @@ -2008,7 +2009,7 @@ class AdminStatsControllerCore extends AdminStatsTabController LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.`id_product` = hri.`id_product`) WHERE p.`active` = 1 - AND hbd.`is_refunded` = 0 + AND hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().') AND hbd.`date_from` < "'.pSQL($discreteDate['date_to']).' 00:00:00" AND hbd.`date_to` > "'.pSQL($discreteDate['date_from']).' 00:00:00"'. (!is_null($idHotel) ? HotelBranchInformation::addHotelRestriction($idHotel, 'hbd') : '').' ) AS num_booked, @@ -2088,7 +2089,7 @@ class AdminStatsControllerCore extends AdminStatsTabController ON (p.`id_product` = hri.`id_product`) WHERE p.`active` = 1'. (!is_null($showAtFront) ? ' AND p.`show_at_front` = '.(int) $showAtFront : '').' - AND hbd.`is_refunded` = 0 + AND hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().') AND hbd.`date_from` < "'.pSQL($discreteDate['date_to']).' 00:00:00" AND hbd.`date_to` > "'.pSQL($discreteDate['date_from']).' 00:00:00"'. (!is_null($idHotel) ? HotelBranchInformation::addHotelRestriction($idHotel, 'hbd') : '').' ) AS num_booked, @@ -2392,7 +2393,7 @@ class AdminStatsControllerCore extends AdminStatsTabController LEFT JOIN `'._DB_PREFIX_.'orders` o ON (od.`id_order` = o.`id_order`) WHERE p.`active` = 1 AND o.`valid` = 1 - AND hbd.`is_refunded` = 0 + AND hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().') AND hbd.`date_from` < "'.pSQL($discreteDate['date_to']).' 00:00:00" AND hbd.`date_to` > "'.pSQL($discreteDate['date_from']).' 00:00:00"'. (!is_null($idHotel) ? HotelBranchInformation::addHotelRestriction($idHotel, 'hbd') : ''); @@ -2418,7 +2419,7 @@ class AdminStatsControllerCore extends AdminStatsTabController LEFT JOIN `'._DB_PREFIX_.'orders` o ON (od.`id_order` = o.`id_order`) WHERE p.`active` = 1 AND o.`valid` = 1 - AND hbd.`is_refunded` = 0 + AND hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().') AND hbd.`date_from` < "'.pSQL($discreteDate['date_to']).' 00:00:00" AND hbd.`date_to` > "'.pSQL($discreteDate['date_from']).' 00:00:00"'. (!is_null($idHotel) ? HotelBranchInformation::addHotelRestriction($idHotel, 'hbd') : ''); @@ -2548,7 +2549,7 @@ class AdminStatsControllerCore extends AdminStatsTabController FROM ( SELECT IF(DATEDIFF(hbd.`date_from`, \''.pSQL($dateFrom).'\') < 0, \''.pSQL($dateFrom).'\', hbd.`date_from`) AS date_from_final, IF(DATEDIFF(\''.pSQL($dateTo).'\', hbd.`date_to`) < 0, \''.pSQL($dateToNext).'\', hbd.`date_to`) AS date_to_final FROM `'._DB_PREFIX_.'htl_booking_detail` hbd - WHERE hbd.`is_refunded` = 0 + WHERE hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().') AND hbd.`date_from` <= \''.pSQL($dateTo).'\' AND hbd.`date_to` > \''.pSQL($dateFrom).'\''. (!is_null($idHotel) ? HotelBranchInformation::addHotelRestriction($idHotel, 'hbd') : '').' ) AS t @@ -2627,7 +2628,7 @@ class AdminStatsControllerCore extends AdminStatsTabController LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.`id_product` = hbd.`id_product`) WHERE p.`active` = 1 - AND hbd.`is_refunded` = 0 + AND hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().') AND hbd.`date_from` <= "'.pSQL($dateTo).' 00:00:00" AND hbd.`date_to` > "'.pSQL($dateFrom).' 00:00:00"'. (!is_null($idHotel) ? HotelBranchInformation::addHotelRestriction($idHotel, 'hbd') : ''); @@ -2640,7 +2641,7 @@ class AdminStatsControllerCore extends AdminStatsTabController LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.`id_product` = hbd.`id_product`) WHERE p.`active` = 1 - AND hbd.`is_refunded` = 0 + AND hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().') AND hbd.`date_from` <= "'.pSQL($dateTo).' 00:00:00" AND hbd.`date_to` > "'.pSQL($dateFrom).' 00:00:00"'. (!is_null($idHotel) ? HotelBranchInformation::addHotelRestriction($idHotel, 'hbd') : '').' ) AS t @@ -2740,7 +2741,7 @@ class AdminStatsControllerCore extends AdminStatsTabController public static function getAverageLeadTime($dateFrom = '', $dateTo = '', $idHotel = false) { $sql = 'SELECT (SUM(DATEDIFF(hbd.`date_from`, hbd.`date_add`)) / COUNT(hbd.`id`)) FROM `'._DB_PREFIX_.'htl_booking_detail` hbd - WHERE hbd.`is_refunded` = 0 AND hbd.`is_back_order` = 0' + WHERE hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().') AND hbd.`is_back_order` = 0' .(($dateFrom && $dateTo) ? ' AND hbd.`date_add` BETWEEN "'.pSQL($dateFrom).' 00:00:00" AND "'.pSQL($dateTo).' 23:59:59"' : '') .HotelBranchInformation::addHotelRestriction($idHotel, 'hbd'); @@ -2758,7 +2759,7 @@ class AdminStatsControllerCore extends AdminStatsTabController public static function getAverageGuestsPerBooking($dateFrom = '', $dateTo = '', $idHotel = false) { $sql = 'SELECT (SUM(hbd.`adults`) / COUNT(hbd.`id`)) as avg_adults, (SUM(hbd.`children`) / COUNT(hbd.`id`)) as avg_children FROM `'._DB_PREFIX_.'htl_booking_detail` hbd - WHERE hbd.`is_refunded` = 0 AND hbd.`is_back_order` = 0' + WHERE hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().') AND hbd.`is_back_order` = 0' .(($dateFrom && $dateTo) ? ' AND hbd.`date_add` BETWEEN "'.pSQL($dateFrom).' 00:00:00" AND "'.pSQL($dateTo).' 23:59:59"' : '') .HotelBranchInformation::addHotelRestriction($idHotel, 'hbd'); diff --git a/controllers/front/GuestTrackingController.php b/controllers/front/GuestTrackingController.php index 32b5cdce4..5583a2bf0 100644 --- a/controllers/front/GuestTrackingController.php +++ b/controllers/front/GuestTrackingController.php @@ -311,8 +311,8 @@ class GuestTrackingControllerCore extends FrontController $anyBackOrder = 1; } - if ($refundReqBookings && in_array($data_v['id'], $refundReqBookings) && $data_v['is_refunded']) { - if ($data_v['is_cancelled']) { + if ($refundReqBookings && in_array($data_v['id'], $refundReqBookings) && $objOrderReturn->hasCompletelyRefundedBooking($data_v['id'])) { + if ($data_v['id_status'] == HotelBookingDetail::STATUS_CANCELLED) { $cartHotelData[$type_key]['date_diff'][$date_join]['count_cancelled'] += 1; } else { $cartHotelData[$type_key]['date_diff'][$date_join]['count_refunded'] += 1; @@ -340,8 +340,8 @@ class GuestTrackingControllerCore extends FrontController $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']) { + if ($refundReqBookings && in_array($data_v['id'], $refundReqBookings) && $objOrderReturn->hasCompletelyRefundedBooking($data_v['id'])) { + if ($data_v['id_status'] == HotelBookingDetail::STATUS_CANCELLED) { $cartHotelData[$type_key]['date_diff'][$date_join]['count_cancelled'] += 1; } else { $cartHotelData[$type_key]['date_diff'][$date_join]['count_refunded'] += 1; @@ -349,7 +349,7 @@ class GuestTrackingControllerCore extends FrontController } } - $cartHotelData[$type_key]['date_diff'][$date_join]['is_refunded'] = $data_v['is_refunded']; + $cartHotelData[$type_key]['date_diff'][$date_join]['is_refunded'] = $objOrderReturn->hasCompletelyRefundedBooking($data_v['id']); $cartHotelData[$type_key]['date_diff'][$date_join]['ids_htl_booking_detail'][] = $data_v['id']; diff --git a/controllers/front/OrderDetailController.php b/controllers/front/OrderDetailController.php index 6bc12b74f..2df858bb0 100644 --- a/controllers/front/OrderDetailController.php +++ b/controllers/front/OrderDetailController.php @@ -168,8 +168,8 @@ class OrderDetailControllerCore extends FrontController $anyBackOrder = 1; } - if ($refundReqBookings && in_array($data_v['id'], $refundReqBookings) && $data_v['is_refunded']) { - if ($data_v['is_cancelled']) { + if ($refundReqBookings && in_array($data_v['id'], $refundReqBookings) && $objOrderReturn->hasCompletelyRefundedBooking($data_v['id'])) { + if ($data_v['id_status'] == HotelBookingDetail::STATUS_CANCELLED) { $cartHotelData[$type_key]['date_diff'][$date_join]['count_cancelled'] += 1; } elseif ($bookingRefundDetail && $bookingRefundDetail['refunded'] && $bookingRefundDetail['id_customization']) { $cartHotelData[$type_key]['date_diff'][$date_join]['count_refunded'] += 1; @@ -197,8 +197,8 @@ class OrderDetailControllerCore extends FrontController $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']) { + if ($refundReqBookings && in_array($data_v['id'], $refundReqBookings) && $objOrderReturn->hasCompletelyRefundedBooking($data_v['id'])) { + if ($data_v['id_status'] == HotelBookingDetail::STATUS_CANCELLED) { $cartHotelData[$type_key]['date_diff'][$date_join]['count_cancelled'] += 1; } elseif ($bookingRefundDetail && $bookingRefundDetail['refunded'] && $bookingRefundDetail['id_customization']) { $cartHotelData[$type_key]['date_diff'][$date_join]['count_refunded'] += 1; @@ -211,8 +211,8 @@ class OrderDetailControllerCore extends FrontController $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']]['is_refunded'] = $objOrderReturn->hasCompletelyRefundedBooking($data_v['id']); + $cartHotelData[$type_key]['date_diff'][$date_join]['hotel_booking_details'][$data_v['id']]['is_cancelled'] = ($data_v['id_status'] == HotelBookingDetail::STATUS_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; @@ -220,7 +220,7 @@ class OrderDetailControllerCore extends FrontController $cartHotelData[$type_key]['date_diff'][$date_join]['hotel_booking_details'][$data_v['id']]['refund_denied'] = 1; } - $cartHotelData[$type_key]['date_diff'][$date_join]['is_refunded'] = $data_v['is_refunded']; + $cartHotelData[$type_key]['date_diff'][$date_join]['is_refunded'] = $objOrderReturn->hasCompletelyRefundedBooking($data_v['id']); $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']; @@ -460,7 +460,7 @@ class OrderDetailControllerCore extends FrontController '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_ASSIGNED' => HotelBookingDetail::STATUS_ASSIGNED, 'ROOM_STATUS_CHECKED_IN' => HotelBookingDetail::STATUS_CHECKED_IN, 'ROOM_STATUS_CHECKED_OUT' => HotelBookingDetail::STATUS_CHECKED_OUT, ) @@ -556,6 +556,7 @@ class OrderDetailControllerCore extends FrontController if (!count($this->errors)) { $objOrder = new Order($idOrder); + $objOrderReturn = new OrderReturn(); if (!(Validate::isLoadedObject($objOrder) && $objOrder->id_customer == $this->context->customer->id)) { $this->errors[] = Tools::displayError('Something went wrong. Please try later.'); } else { @@ -568,12 +569,14 @@ class OrderDetailControllerCore extends FrontController } // 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) { + if ($objHotelBookingDetail->id_status != HotelBookingDetail::STATUS_ASSIGNED) { $this->errors[] = Tools::displayError('Some selected rooms have already been checked-in/checked-out.'); break; } - if (OrderReturn::getOrdersReturnDetail($objOrder->id, 0, $idHtlBooking)) { + // multiple refund requests are now allowed per booking — only still + // block a booking that's already fully refunded, not a re-request + if ($objOrderReturn->hasCompletelyRefundedBooking($idHtlBooking)) { $this->errors[] = Tools::displayError('Some selected rooms have already been requested for cancellation.'); break; } @@ -591,13 +594,13 @@ class OrderDetailControllerCore extends FrontController if (!count($this->errors)) { // 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->event_type = OrderReturn::EVENT_TYPE_REFUND; $objOrderReturn->save(); if ($objOrderReturn->id) { if ($idsHtlBooking) { @@ -617,6 +620,14 @@ class OrderDetailControllerCore extends FrontController $objOrderReturnDetail->id_customization = 1; } $objOrderReturnDetail->save(); + + // the room's own status flips right away, same as the admin + // side — only the refund processing below waits for approval + // when the order is paid + $objHtlBooking->changeStatus(HotelBookingDetail::STATUS_CANCELLED, array( + 'id_customer' => (int) $objOrder->id_customer, + 'remark' => $cancellationReason, + )); } } if ($idServiceProductOrderDetails) { @@ -665,20 +676,7 @@ class OrderDetailControllerCore extends FrontController $objOrderReturn->changeIdOrderReturnState(Configuration::get('PS_ORS_REFUNDED')); // if all bookings are getting cancelled/Refunded then Cancel/Refund the order also - $idOrderState = $objOrder->getOrderCompleteRefundStatus(); - - if ($idOrderState) { - $objOrderHistory = new OrderHistory(); - $objOrderHistory->id_order = (int)$objOrder->id; - - $useExistingPayment = false; - if (!$objOrder->hasInvoice()) { - $useExistingPayment = true; - } - - $objOrderHistory->changeIdOrderState($idOrderState, $objOrder, $useExistingPayment); - $objOrderHistory->addWithemail(); - + if ($objOrder->syncRefundStatus()) { $response['order_cancelled'] = true; } } diff --git a/controllers/front/OrderReturnController.php b/controllers/front/OrderReturnController.php index e2c6a476b..3bd9b6489 100644 --- a/controllers/front/OrderReturnController.php +++ b/controllers/front/OrderReturnController.php @@ -52,8 +52,8 @@ class OrderReturnControllerCore extends FrontController $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 + if (count(array_unique(array_column($refundReqBookings, 'id_status'))) === 1 + && array_unique(array_column($refundReqBookings, 'id_status'))[0] == HotelBookingDetail::STATUS_CANCELLED ) { $isCanceledBookings = true; } @@ -76,6 +76,7 @@ class OrderReturnControllerCore extends FrontController $this->context->language->id), 'isRefundCompleted' => $objOrderReturn->hasBeenCompleted(), 'voucher' => $voucher, + 'room_status_cancelled' => HotelBookingDetail::STATUS_CANCELLED, ) ); diff --git a/install/data/db_structure.sql b/install/data/db_structure.sql index 69e4c3bef..4504c819d 100644 --- a/install/data/db_structure.sql +++ b/install/data/db_structure.sql @@ -1427,6 +1427,7 @@ CREATE TABLE `PREFIX_order_return` ( `by_admin` tinyint(1) unsigned NOT NULL DEFAULT '0', `id_return_type` tinyint(1) unsigned NOT NULL DEFAULT '0', `return_type` tinyint(1) unsigned NOT NULL DEFAULT '0', + `event_type` tinyint(1) unsigned NOT NULL DEFAULT '0', `date_add` datetime NOT NULL, `date_upd` datetime NOT NULL, PRIMARY KEY (`id_order_return`), diff --git a/install/data/img/os/No_show.gif b/install/data/img/os/No_show.gif new file mode 100644 index 000000000..97949dc94 Binary files /dev/null and b/install/data/img/os/No_show.gif differ diff --git a/install/data/xml/configuration.xml b/install/data/xml/configuration.xml index e6fb3f0c0..b5cb8b5c2 100644 --- a/install/data/xml/configuration.xml +++ b/install/data/xml/configuration.xml @@ -461,6 +461,9 @@ 12 + + 13 + diff --git a/install/data/xml/order_state.xml b/install/data/xml/order_state.xml index cc016ffcd..b94ac7fd0 100644 --- a/install/data/xml/order_state.xml +++ b/install/data/xml/order_state.xml @@ -38,5 +38,7 @@ + diff --git a/install/langs/bg/data/order_state.xml b/install/langs/bg/data/order_state.xml index f4661ce31..7da450ff2 100644 --- a/install/langs/bg/data/order_state.xml +++ b/install/langs/bg/data/order_state.xml @@ -48,4 +48,8 @@ Получено частично плащане + + Неявяване + + diff --git a/install/langs/bn/data/order_state.xml b/install/langs/bn/data/order_state.xml index 079e3acba..6120bd93d 100644 --- a/install/langs/bn/data/order_state.xml +++ b/install/langs/bn/data/order_state.xml @@ -48,4 +48,8 @@ আংশিক পেমেন্ট প্রাপ্ত + + অনুপস্থিত + + diff --git a/install/langs/br/data/order_state.xml b/install/langs/br/data/order_state.xml index e9a75f914..537f37e0e 100644 --- a/install/langs/br/data/order_state.xml +++ b/install/langs/br/data/order_state.xml @@ -48,4 +48,8 @@ Pagamento parcial recebido + + Não comparecimento + + diff --git a/install/langs/cs/data/order_state.xml b/install/langs/cs/data/order_state.xml index bdbe0e77e..cafdf5e3c 100644 --- a/install/langs/cs/data/order_state.xml +++ b/install/langs/cs/data/order_state.xml @@ -48,4 +48,8 @@ Částečná platba přijata + + Nedostavení se + + \ No newline at end of file diff --git a/install/langs/de/data/order_state.xml b/install/langs/de/data/order_state.xml index ad480e2f2..a6fc39b7d 100644 --- a/install/langs/de/data/order_state.xml +++ b/install/langs/de/data/order_state.xml @@ -48,4 +48,8 @@ Teilzahlung erhalten + + Nichterscheinen + + diff --git a/install/langs/en/data/order_state.xml b/install/langs/en/data/order_state.xml index 16e519f1a..b0ec50351 100644 --- a/install/langs/en/data/order_state.xml +++ b/install/langs/en/data/order_state.xml @@ -48,4 +48,8 @@ Partial payment received + + No-show + + diff --git a/install/langs/es/data/order_state.xml b/install/langs/es/data/order_state.xml index f47bf65d3..33d2c0702 100644 --- a/install/langs/es/data/order_state.xml +++ b/install/langs/es/data/order_state.xml @@ -48,4 +48,8 @@ Pago parcial recibido + + No presentado + + diff --git a/install/langs/fa/data/order_state.xml b/install/langs/fa/data/order_state.xml index 8c992e07b..406c7a993 100644 --- a/install/langs/fa/data/order_state.xml +++ b/install/langs/fa/data/order_state.xml @@ -48,4 +48,8 @@ پرداخت جزئی دریافت شد + + عدم حضور + + diff --git a/install/langs/fr/data/order_state.xml b/install/langs/fr/data/order_state.xml index 55aa13404..17db50c0f 100644 --- a/install/langs/fr/data/order_state.xml +++ b/install/langs/fr/data/order_state.xml @@ -48,4 +48,8 @@ Paiement partiel reçu + + Non présentation + + diff --git a/install/langs/he/data/order_state.xml b/install/langs/he/data/order_state.xml index 7bfc432fc..5a144372a 100644 --- a/install/langs/he/data/order_state.xml +++ b/install/langs/he/data/order_state.xml @@ -48,4 +48,8 @@ תשלום חלקי התקבל + + אי-הגעה + + diff --git a/install/langs/hr/data/order_state.xml b/install/langs/hr/data/order_state.xml index 39eaaa302..a5d27a288 100644 --- a/install/langs/hr/data/order_state.xml +++ b/install/langs/hr/data/order_state.xml @@ -48,4 +48,8 @@ Primljena djelomična uplata + + Nedolazak + + diff --git a/install/langs/hu/data/order_state.xml b/install/langs/hu/data/order_state.xml index 9b2b9c956..270110126 100644 --- a/install/langs/hu/data/order_state.xml +++ b/install/langs/hu/data/order_state.xml @@ -48,4 +48,8 @@ Részleges kifizetés megérkezett + + Meg nem jelenés + + diff --git a/install/langs/id/data/order_state.xml b/install/langs/id/data/order_state.xml index 853175220..188fcf8d6 100644 --- a/install/langs/id/data/order_state.xml +++ b/install/langs/id/data/order_state.xml @@ -48,4 +48,8 @@ Pembayaran sebagian diterima + + Ketidakhadiran + + diff --git a/install/langs/it/data/order_state.xml b/install/langs/it/data/order_state.xml index a328ca9ae..eac9c3dd5 100644 --- a/install/langs/it/data/order_state.xml +++ b/install/langs/it/data/order_state.xml @@ -48,4 +48,8 @@ Pagamento parziale ricevuto + + Mancata presentazione + + diff --git a/install/langs/lt/data/order_state.xml b/install/langs/lt/data/order_state.xml index d58ef02e0..5e90358ce 100644 --- a/install/langs/lt/data/order_state.xml +++ b/install/langs/lt/data/order_state.xml @@ -48,4 +48,8 @@ Gautas dalinis apmokėjimas + + Neatvykimas + + diff --git a/install/langs/mk/data/order_state.xml b/install/langs/mk/data/order_state.xml index d128aebe8..360d441eb 100644 --- a/install/langs/mk/data/order_state.xml +++ b/install/langs/mk/data/order_state.xml @@ -48,4 +48,8 @@ Примено е делумно плаќање + + Непојавување + + diff --git a/install/langs/nl/data/order_state.xml b/install/langs/nl/data/order_state.xml index c970d6d93..92bb928d6 100644 --- a/install/langs/nl/data/order_state.xml +++ b/install/langs/nl/data/order_state.xml @@ -48,4 +48,8 @@ Gedeeltelijke betaling ontvangen + + Niet verschenen + + diff --git a/install/langs/no/data/order_state.xml b/install/langs/no/data/order_state.xml index 16e519f1a..f2f690a19 100644 --- a/install/langs/no/data/order_state.xml +++ b/install/langs/no/data/order_state.xml @@ -48,4 +48,8 @@ Partial payment received + + Ikke-møtt + + diff --git a/install/langs/pl/data/order_state.xml b/install/langs/pl/data/order_state.xml index 644e3d9ab..e97597d51 100644 --- a/install/langs/pl/data/order_state.xml +++ b/install/langs/pl/data/order_state.xml @@ -48,4 +48,8 @@ Otrzymano częściową płatność + + Niepojawienie się + + diff --git a/install/langs/pt/data/order_state.xml b/install/langs/pt/data/order_state.xml index 382b23550..cdaa92f4a 100644 --- a/install/langs/pt/data/order_state.xml +++ b/install/langs/pt/data/order_state.xml @@ -48,4 +48,8 @@ Pagamento parcial recebido + + Não comparência + + diff --git a/install/langs/qc/data/order_state.xml b/install/langs/qc/data/order_state.xml index fce19d5f6..352ac563e 100644 --- a/install/langs/qc/data/order_state.xml +++ b/install/langs/qc/data/order_state.xml @@ -48,4 +48,8 @@ Paiement partiel reçu + + Non présentation + + diff --git a/install/langs/ro/data/order_state.xml b/install/langs/ro/data/order_state.xml index 68afd22b7..1acc28b93 100644 --- a/install/langs/ro/data/order_state.xml +++ b/install/langs/ro/data/order_state.xml @@ -48,4 +48,8 @@ Plata parțială primită + + Neprezentare + + diff --git a/install/langs/ru/data/order_state.xml b/install/langs/ru/data/order_state.xml index 983bc12dc..010d39782 100644 --- a/install/langs/ru/data/order_state.xml +++ b/install/langs/ru/data/order_state.xml @@ -48,4 +48,8 @@ Частичная оплата получена + + Неявка + + diff --git a/install/langs/si/data/order_state.xml b/install/langs/si/data/order_state.xml index 73d97f838..f40d12b42 100644 --- a/install/langs/si/data/order_state.xml +++ b/install/langs/si/data/order_state.xml @@ -48,4 +48,8 @@ අර්ධ ගෙවීමක් ලැබී ඇත + + නොපැමිණි + + diff --git a/install/langs/sr/data/order_state.xml b/install/langs/sr/data/order_state.xml index f2a5e6529..6c346b528 100644 --- a/install/langs/sr/data/order_state.xml +++ b/install/langs/sr/data/order_state.xml @@ -48,4 +48,8 @@ Делимична уплата примљена + + Непојављивање + + diff --git a/install/langs/sv/data/order_state.xml b/install/langs/sv/data/order_state.xml index e55775740..eb8b67990 100644 --- a/install/langs/sv/data/order_state.xml +++ b/install/langs/sv/data/order_state.xml @@ -48,4 +48,8 @@ Delbetalning mottagen + + Utebliven ankomst + + diff --git a/install/langs/tw/data/order_state.xml b/install/langs/tw/data/order_state.xml index f535a0c61..e333ee2d0 100644 --- a/install/langs/tw/data/order_state.xml +++ b/install/langs/tw/data/order_state.xml @@ -48,4 +48,8 @@ 已收到部分付款 + + 未入住 + + diff --git a/install/langs/vn/data/order_state.xml b/install/langs/vn/data/order_state.xml index 9b79504d1..a1ff5b4f8 100644 --- a/install/langs/vn/data/order_state.xml +++ b/install/langs/vn/data/order_state.xml @@ -48,4 +48,8 @@ Đã nhận được một phần thanh toán + + Khách không đến + + diff --git a/install/langs/zh/data/order_state.xml b/install/langs/zh/data/order_state.xml index 7e868eec7..d55ac5a89 100644 --- a/install/langs/zh/data/order_state.xml +++ b/install/langs/zh/data/order_state.xml @@ -48,4 +48,8 @@ 已收到部分付款 + + 未入住 + + diff --git a/js/admin/orders.js b/js/admin/orders.js index 49beadcec..878f4786c 100644 --- a/js/admin/orders.js +++ b/js/admin/orders.js @@ -1021,9 +1021,11 @@ $(document).ready(function() { }, }); - // when change order state to cancel or refund then show modal of bookings cancellation + // when changing order state to Refund, show the booking/product selection + // modal first — Cancelled is no longer handled here, cancelling a booking + // only happens through Room Status now $(document).on('change', '#id_order_state', function(e) { - if ($(this).val() == PS_OS_CANCELED || $(this).val() == PS_OS_REFUND) { + if ($(this).val() == PS_OS_REFUND) { e.preventDefault(); CancelRoomBookingModal.show(); } @@ -1422,8 +1424,10 @@ $(document).ready(function() { // for updating Room status // toggle date input of check-in checkout dates as per status selected $(document).on('change', '.booking_order_status', function() { - var status = $(this).val(); - var $form = $(this).closest('.room_status_info_form'); + var $select = $(this); + var status = $select.val(); + var $form = $select.closest('.room_status_info_form'); + if (status == ROOM_STATUS_CHECKED_IN || status == ROOM_STATUS_CHECKED_OUT) { $form.find('.room_status_date').closest('.form-group').show(); var currentStatus = $form.data('current_status'); @@ -1468,6 +1472,10 @@ $(document).ready(function() { $(document).on('click', '.submitRoomStatus', function(e) { e.preventDefault(); + var status = $('#room-status-modal .booking_order_status').val(); + if ((status == ROOM_STATUS_NO_SHOW || status == ROOM_STATUS_CANCELLED) && !confirm(room_status_sealed_warning_txt)) { + return; + } RoomStatusModal.submit(); }); // End: RoomStatusModal: Processes diff --git a/mails/en/no_show.html b/mails/en/no_show.html new file mode 100644 index 000000000..e3185946f --- /dev/null +++ b/mails/en/no_show.html @@ -0,0 +1,159 @@ + + + + + + Message from {shop_name} + + + + + + +
{l s='Image'}{l s='Image'} {l s='Name'} {l s='Quantity'} {l s='Price (Tax excl.)'} {l s='Total Tax'} {l s='Total Price (Tax incl.)'}{l s='Refund State'}{l s='Refunded amount'}
{l s='Refund'}
{l s='Refund requests'}
{l s='Actions'}{l s='Actions'}
- {if $product.id_service_product_order_detail|in_array:$refundReqProducts} - {if $product.is_cancelled} - {l s='Cancelled'} - {elseif isset($product.refund_info) && (!$product.refund_info.refunded || $product.refund_info.id_customization)} - {$product.refund_info.name|escape:'html':'UTF-8'} - {else} - -- + {if $product.refund_count} + {if $product.refund_amount} +

+ {convertPriceWithCurrency price=$product.refund_amount currency=$currency->id} +

{/if} +

+ {$product.refund_count} {else} - -- - {/if} -

- {if $product.is_refunded && isset($product.refund_info) && $product.refund_info} - {convertPriceWithCurrency price=$product.refund_info.refunded_amount currency=$currency->id} - {else} - -- +

--

{/if}
+ {* edit/delete controls *} {if isset($refundReqProducts) && $refundReqProducts && $product.id_service_product_order_detail|in_array:$refundReqProducts && $product.is_cancelled}
+ + + + + +
  + + + + + + + + + + + + + + + + + + + + + + + +{extra_mail_content_html} + + + + + + + + + + + + + +
+ + Hi {firstname} {lastname}, + +
+ + + + + + +
  + +

+ Room marked No-show - {order_name} +

+ Your order with the reference {order_name} has been marked as No-show. +
+
 
+
+ + + + + + +
  + +

+ Here are your order details: +

+

+ Order reference: {order_name}
+ Order total: {total_paid}
+

+
+
+ {order_hotel_detail_html} +
 
+
+ + + You can review your order and download your invoice from the "Order history" section of your customer account by clicking "My account" on our website. + +
+ + + If you have a guest account, you can follow your order via the "Guest Tracking" section on our website. + +
+
 
+ + \ No newline at end of file diff --git a/mails/en/no_show.txt b/mails/en/no_show.txt new file mode 100644 index 000000000..70b07b093 --- /dev/null +++ b/mails/en/no_show.txt @@ -0,0 +1,31 @@ + +[/{shop_url}] + +Hi {firstname} {lastname}, + +Your order with the reference {order_name} from {hotel_hotel_name} has +been marked as No-show. + +Here are your order details: +Order reference: {order_name} +Order total: {total_paid} +Total Rooms: {num_rooms} + +Hotel details: +Hotel Name: {hotel_hotel_name} +Hotel Phone: {hotel_phone} +Hotel Email: {hotel_email} + +{extra_mail_content_txt} + +You can review your order and download your invoice from the +"Order history" [/{history_url}] section of your customer account by +clicking "My account" [/{my_account_url}] on our website. + +If you have a guest account, you can follow your order via the +"Guest Tracking" [/{guest_tracking_url}?id_order={order_name}] section +on our website. + +{shop_name} [/{shop_url}] powered by Webkul(tm) +[https://webkul.com] + diff --git a/modules/dashactivity/views/templates/hook/dashboard_zone_one.tpl b/modules/dashactivity/views/templates/hook/dashboard_zone_one.tpl index a1ee08c96..04cb49fb9 100644 --- a/modules/dashactivity/views/templates/hook/dashboard_zone_one.tpl +++ b/modules/dashactivity/views/templates/hook/dashboard_zone_one.tpl @@ -80,7 +80,7 @@
@@ -99,6 +105,12 @@ +
+ + + +
+
{hook h='displayDashGuestCycleTabContent'} diff --git a/modules/dashproducts/dashproducts.php b/modules/dashproducts/dashproducts.php index 3603141b8..486101e87 100644 --- a/modules/dashproducts/dashproducts.php +++ b/modules/dashproducts/dashproducts.php @@ -260,7 +260,7 @@ class DashProducts extends Module FROM `'._DB_PREFIX_.'htl_booking_detail` hbd LEFT JOIN `'._DB_PREFIX_.'orders` o ON (o.`id_order` = hbd.`id_order`) WHERE o.`invoice_date` BETWEEN "'.pSQL($date_from).' 00:00:00" AND "'.pSQL($date_to).' 23:59:59" - AND o.`valid` = 1 AND hbd.`is_refunded` = 0.'. + AND o.`valid` = 1 AND hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().').'. (!is_null($id_hotel) ? HotelBranchInformation::addHotelRestriction($id_hotel, 'hbd') : '').' GROUP BY hbd.`id_product` ORDER BY `sales` DESC @@ -568,7 +568,7 @@ class DashProducts extends Module return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue( 'SELECT COUNT(hbd.`id_product`) AS `count` FROM `'._DB_PREFIX_.'htl_booking_detail` hbd - WHERE hbd.`is_refunded` = 0 AND hbd.`is_back_order` = 0 AND hbd.`id_product` = '.(int)$id_product.' + WHERE hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().') AND hbd.`is_back_order` = 0 AND hbd.`id_product` = '.(int)$id_product.' AND hbd.`date_add` BETWEEN "'.pSQL($date_from).' 00:00:00" AND "'.pSQL($date_to).' 23:59:59"' ); } diff --git a/modules/hotelreservationsystem/classes/HotelBookingDetail.php b/modules/hotelreservationsystem/classes/HotelBookingDetail.php index 275d9acb1..2fb96aa37 100644 --- a/modules/hotelreservationsystem/classes/HotelBookingDetail.php +++ b/modules/hotelreservationsystem/classes/HotelBookingDetail.php @@ -125,8 +125,6 @@ class HotelBookingDetail extends ObjectModel public $total_paid_amount; // Advance payment amount for the room public $is_back_order; public $id_status; - public $is_refunded; - public $is_cancelled; // public $available_for_order; // hotel information/location/contact @@ -149,9 +147,11 @@ class HotelBookingDetail extends ObjectModel public $date_add; public $date_upd; protected $moduleInstance; - const STATUS_ALLOTED = 1; + const STATUS_ASSIGNED = 1; const STATUS_CHECKED_IN = 2; const STATUS_CHECKED_OUT = 3; + const STATUS_NO_SHOW = 4; + const STATUS_CANCELLED = 5; // booking allotment types const ALLOTMENT_AUTO = 1; @@ -190,8 +190,6 @@ class HotelBookingDetail extends ObjectModel 'total_price_tax_excl' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPrice', 'required' => true), 'total_price_tax_incl' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPrice', 'required' => true), 'total_paid_amount' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPrice', 'default' => 0, 'required' => true), - 'is_refunded' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), - 'is_cancelled' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), // 'available_for_order' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), 'is_back_order' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), @@ -244,17 +242,17 @@ class HotelBookingDetail extends ObjectModel $this->moduleInstance = Module::getInstanceByName('hotelreservationsystem'); parent::__construct($id); } - public function update($null_values = false) { $result = parent::update($null_values); // if automatic overbooking resolution is enabled if (Configuration::get('PS_OVERBOOKING_AUTO_RESOLVE')) { - // if room is getting free and this room is not already in back order then resolve the overbookings for this free room - // $this->is_cancelled == 1 is not checked because currently we always set is_refunded to 1 when room is free - // $this->is_back_order == 0 is checked because $this->is_back_order == 1 is used as room is free - if ($this->is_refunded == 1 && $this->is_back_order == 0) { + if ($this->is_back_order == 0 && ( + $this->id_status == self::STATUS_CANCELLED + || $this->id_status == self::STATUS_NO_SHOW + || (new OrderReturn())->getRefundedAmount($this->id_order, 0, $this->id) > 0 + )) { $this->resolveOverBookings(); } } @@ -763,7 +761,7 @@ class HotelBookingDetail extends ObjectModel $excludeRoomId = array(); $excludeRoomId['checked_out'] = 'SELECT `id_room` FROM `'._DB_PREFIX_.'htl_booking_detail` - WHERE `id_hotel` = '.(int)$idHotel.' AND `is_back_order` = 0 AND `is_refunded` = 0 AND IF(`id_status` = '. self::STATUS_CHECKED_OUT.', + WHERE `id_hotel` = '.(int)$idHotel.' AND `is_back_order` = 0 AND `id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().') AND IF(`id_status` = '. self::STATUS_CHECKED_OUT.', IF('.(int) $hourlyBooking.', 1, (DATE_FORMAT(`check_out`, "%Y-%m-%d") != DATE_FORMAT(\''.pSQL($dateFrom).'\', "%Y-%m-%d")) AND (`check_out` > \''.pSQL($dateFrom).'\' AND `check_out` <= \''.PSQL($dateTo).'\')) AND ( (`date_from` <= \''.pSQL($dateFrom).'\' AND `check_out` > \''.pSQL($dateFrom).'\' AND `check_out` <= \''.PSQL($dateTo).'\') OR (`date_from` >= \''.pSQL($dateFrom).'\' AND `check_out` > \''.pSQL($dateFrom).'\' AND `check_out` <= \''.pSQL($dateTo).'\') OR @@ -1093,7 +1091,7 @@ class HotelBookingDetail extends ObjectModel FROM `'._DB_PREFIX_.'htl_booking_detail` AS bd INNER JOIN `'._DB_PREFIX_.'htl_room_information` AS rf ON (rf.`id` = bd.`id_room`) INNER JOIN `'._DB_PREFIX_.'htl_room_type` AS hrt ON (hrt.`id_product` = rf.`id_product`) - WHERE bd.`id_hotel`='.(int)$idHotel.' AND rf.`id_status` != '. HotelRoomInformation::STATUS_INACTIVE .' AND bd.`is_back_order` = 0 AND bd.`is_refunded` = 0 AND IF(bd.`id_status` = '. self::STATUS_CHECKED_OUT .', IF('.(int) $hourlyBooking.', 1, (DATE_FORMAT(`check_out`, "%Y-%m-%d") != DATE_FORMAT(\''.pSQL($dateFrom).'\', "%Y-%m-%d")) AND (`check_out` > \''.pSQL($dateFrom).'\' AND `check_out` <= \''.PSQL($dateTo).'\')) AND ( + WHERE bd.`id_hotel`='.(int)$idHotel.' AND rf.`id_status` != '. HotelRoomInformation::STATUS_INACTIVE .' AND bd.`is_back_order` = 0 AND bd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().') AND IF(bd.`id_status` = '. self::STATUS_CHECKED_OUT .', IF('.(int) $hourlyBooking.', 1, (DATE_FORMAT(`check_out`, "%Y-%m-%d") != DATE_FORMAT(\''.pSQL($dateFrom).'\', "%Y-%m-%d")) AND (`check_out` > \''.pSQL($dateFrom).'\' AND `check_out` <= \''.PSQL($dateTo).'\')) AND ( (bd.`date_from` <= \''.pSQL($dateFrom).'\' AND bd.`check_out` > \''.pSQL($dateFrom).'\' AND bd.`check_out` < \''.pSQL($dateTo).'\') OR (bd.`date_from` > \''.pSQL($dateFrom).'\' AND bd.`date_from` < \''.pSQL($dateTo).'\' AND bd.`check_out` >= \''.pSQL($dateTo).'\') OR (bd.`date_from` > \''.pSQL($dateFrom).'\' AND bd.`date_from` < \''.pSQL($dateTo).'\' AND bd.`check_out` > \''.pSQL($dateFrom).'\' AND bd.`check_out` < \''.pSQL($dateTo).'\') @@ -1426,7 +1424,7 @@ class HotelBookingDetail extends ObjectModel $selectBookedRoomSearch = 'SELECT `id`, `id_order`, `id_product`, `id_room`, `id_hotel`, `id_customer`, `booking_type`, `id_status` AS booking_status, `comment`, `room_num`, `date_from`, IF(`id_status` = '. self::STATUS_CHECKED_OUT.', `check_out`,`date_to`) AS `date_to`, `check_in`, `check_out`, `date_to` AS `booking_date_to`'; $joinBookedRoomSearch = ''; - $whereBookedRoomSearch = 'WHERE `id_hotel` = '.(int)$idHotel.' AND `is_back_order` = 0 AND `is_refunded` = 0 AND IF(`id_status` = '. self::STATUS_CHECKED_OUT.', ( + $whereBookedRoomSearch = 'WHERE `id_hotel` = '.(int)$idHotel.' AND `is_back_order` = 0 AND `id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().') AND IF(`id_status` = '. self::STATUS_CHECKED_OUT.', ( (`date_from` <= \''.pSQL($dateFrom).'\' AND `check_out` > \''.pSQL($dateFrom).'\' AND `check_out` <= \''.PSQL($dateTo).'\') OR (`date_from` >= \''.pSQL($dateFrom).'\' AND `check_out` > \''.pSQL($dateFrom).'\' AND `check_out` <= \''.pSQL($dateTo).'\') OR (`date_from` >= \''.pSQL($dateFrom).'\' AND `date_from` < \''.pSQL($dateTo).'\' AND `check_out` >= \''.pSQL($dateTo).'\') OR @@ -1499,7 +1497,7 @@ class HotelBookingDetail extends ObjectModel $sql = 'SELECT `id`, `id_product`, `id_order`, `id_cart`, `id_room`, `id_hotel`, `id_customer`, `check_out`, `check_in`, `id_status` FROM `'._DB_PREFIX_.'htl_booking_detail` WHERE `id_room` = '.(int)$id_room. - ' AND `is_back_order` = 0 AND `is_refunded` = 0 AND ((date_from <= \''.pSQL($date_from).'\' AND date_to > \''. + ' AND `is_back_order` = 0 AND `id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().') AND ((date_from <= \''.pSQL($date_from).'\' AND date_to > \''. pSQL($date_from).'\' AND date_to <= \''.pSQL($date_to).'\') OR (date_from > \''.pSQL($date_from). '\' AND date_to < \''.pSQL($date_to).'\') OR (date_from >= \''.pSQL($date_from).'\' AND date_from < \''. pSQL($date_to).'\' AND date_to >= \''.pSQL($date_to).'\') OR (date_from < \''.pSQL($date_from). @@ -1686,6 +1684,64 @@ class HotelBookingDetail extends ObjectModel return $idHotel; } + /** + * The only place `id_status` is allowed to change on an already-existing booking row. + * Validates the transition against HotelBookingStatus::getAllowedTransitions(), saves, + * logs the change to HotelBookingStatusHistory, and fires actionBookingStatusBefore/After. + * + * Not for setting the initial status when a brand-new booking row is first created — + * that's plain field initialization, not a transition, and is unaffected by this method. + * + * @param int $newStatus one of HotelBookingDetail::STATUS_* + * @param array $params optional: 'remark' (string), 'id_employee' (int), 'id_customer' (int) + * @return bool + */ + public function changeStatus($newStatus, $params = array()) + { + if (!Validate::isLoadedObject($this)) { + return false; + } + + $idStatusFrom = (int) $this->id_status; + + if ($idStatusFrom == $newStatus) { + return false; + } + + if (!in_array($newStatus, HotelBookingStatus::getAllowedTransitions($idStatusFrom))) { + return false; + } + + Hook::exec('actionBookingStatusBefore', array( + 'object' => $this, + 'id_status_from' => $idStatusFrom, + 'id_status_to' => $newStatus, + )); + + $this->id_status = $newStatus; + + if (!$this->save()) { + return false; + } + + $objHistory = new HotelBookingStatusHistory(); + $objHistory->id_htl_booking = $this->id; + $objHistory->id_status_from = $idStatusFrom; + $objHistory->id_status_to = $newStatus; + $objHistory->id_employee = isset($params['id_employee']) ? (int) $params['id_employee'] : null; + $objHistory->id_customer = isset($params['id_customer']) ? (int) $params['id_customer'] : null; + $objHistory->remark = isset($params['remark']) ? $params['remark'] : ''; + $objHistory->save(); + + Hook::exec('actionBookingStatusAfter', array( + 'object' => $this, + 'id_status_from' => $idStatusFrom, + 'id_status_to' => $newStatus, + )); + + return true; + } + /** * [updateBookingOrderStatusBYOrderId :: To update the order status of a room in the booking]. * @param [int] $order_id [Id of the order] @@ -1712,18 +1768,15 @@ class HotelBookingDetail extends ObjectModel } if ($newStatus == self::STATUS_CHECKED_IN) { - $objHotelBookingDetail->id_status = $newStatus; $objHotelBookingDetail->check_in = ($statusDate > $dateTo ? $dateTo : $statusDate); } elseif ($newStatus == self::STATUS_CHECKED_OUT) { - $objHotelBookingDetail->id_status = $newStatus; $objHotelBookingDetail->check_out = ($statusDate > $dateTo ? $dateTo : $statusDate); } else { - $objHotelBookingDetail->id_status = $newStatus; $objHotelBookingDetail->check_in = ''; $objHotelBookingDetail->check_out = ''; } - return $objHotelBookingDetail->save(); + return $objHotelBookingDetail->changeStatus($newStatus); } return false; @@ -1910,7 +1963,7 @@ class HotelBookingDetail extends ObjectModel FROM `'._DB_PREFIX_.'htl_booking_detail` WHERE `id_hotel` = '.(int)$hotel_id.' AND `id_product` = '.(int)$id_room_type.' AND `date_from` = \''.pSQL($date_from).'\' AND `date_to` = \''.pSQL($date_to).'\' - AND `id_room`!='.(int)$id_room.' AND `is_refunded` = 0 AND `is_back_order` = 0'; + AND `id_room`!='.(int)$id_room.' AND `id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().') AND `is_back_order` = 0'; return Db::getInstance()->executeS($sql); } @@ -2506,7 +2559,7 @@ class HotelBookingDetail extends ObjectModel // Get the booking details for the given rooms as per given parameters $idHotelBookingFrom = Db::getInstance()->getValue( - 'SELECT `id` FROM `'._DB_PREFIX_.'htl_booking_detail` WHERE `is_refunded` = 0 + 'SELECT `id` FROM `'._DB_PREFIX_.'htl_booking_detail` WHERE `id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().') AND `date_from`=\''.pSQL($dateFrom).'\' AND `date_to`=\''.pSQL($dateTo).'\' AND `id_room`='.(int)$idRoomFrom. @@ -2514,7 +2567,7 @@ class HotelBookingDetail extends ObjectModel ); $idHotelBookingTo = Db::getInstance()->getValue( - 'SELECT `id` FROM `'._DB_PREFIX_.'htl_booking_detail` WHERE `is_refunded` = 0 + 'SELECT `id` FROM `'._DB_PREFIX_.'htl_booking_detail` WHERE `id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().') AND `date_from`=\''.pSQL($dateFrom).'\' AND `date_to`=\''.pSQL($dateTo).'\' AND `id_room`='.(int)$idRoomTo. @@ -2603,44 +2656,6 @@ class HotelBookingDetail extends ObjectModel return $result; } - /** - * [updateOrderRefundStatus :: To update the refund status of a room booked in the order if amount refunded by the admin]. - * @param [int] $id_order [Id of the order] - * @param [date] $date_from [start date of the bookin of the room] - * @param [date] $date_to [end date of the bookin of the room] - * @param [int] $id_room [id of the room for which refund is done] - * - * @return [boolean] [true if updated otherwise false] - */ - public function updateOrderRefundStatus($id_order, $date_from = false, $date_to = false, $id_rooms = array(), $is_refunded = 1, $is_cancelled = null) - { - $table = 'htl_booking_detail'; - $data = array('is_refunded' => (int) $is_refunded); - - if (!is_null($is_cancelled)) { - $data['is_cancelled'] = (int) $is_cancelled; - } - - if ($id_rooms) { - foreach ($id_rooms as $key_rm => $val_rm) { - $where = 'id_order='.(int)$id_order.' AND id_room = '.(int)$val_rm['id_room'].' AND `date_from`= \''. - pSQL($date_from).'\' AND `date_to` = \''.pSQL($date_to).'\''; - $result = Db::getInstance()->update($table, $data, $where); - } - } else { - $result = Db::getInstance()->update($table, $data, 'id_order='.(int)$id_order); - Db::getInstance()->update('service_product_order_detail', array('is_refunded' => (int) $is_refunded), 'id_order='.(int)$id_order); - } - - // if automatic overbooking resolution is enabled - if ($result && Configuration::get('PS_OVERBOOKING_AUTO_RESOLVE') && $is_refunded) { - // if room is getting free and this room is not already in back order then resolve the overbookings for this free room - $this->resolveOverBookings(); - } - - return $result; - } - /** * [useTax : To get whether tax is enabled for the current group or disabled]. * @@ -2706,7 +2721,7 @@ class HotelBookingDetail extends ObjectModel `date_to` != \''.pSQL($old_date_to).'\' AND `date_to` > \''.pSQL($new_date_from).'\', `check_out` != \''.pSQL($old_date_to).'\' AND `check_out` > \''.pSQL($new_date_from).'\' ) - AND `is_refunded`=0 AND `is_back_order`=0'; + AND `id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().') AND `is_back_order`=0'; return Db::getInstance()->executeS($sql); } @@ -2800,7 +2815,7 @@ class HotelBookingDetail extends ObjectModel $sql .= ' AND `id_status` IN ('.implode(',', array_map('intval', $idsStatus)).')'; } if (!is_null($isRefunded)) { - $sql .= ' AND `is_refunded` = '.(int) $isRefunded; + $sql .= ' AND `id` '.($isRefunded ? '' : 'NOT ').'IN ('.OrderReturn::getRefundedBookingIdsSubquery().')'; } if (!is_null($isBackOrder)) { $sql .= ' AND `is_back_order` = '.(int) $isBackOrder; @@ -3346,7 +3361,7 @@ class HotelBookingDetail extends ObjectModel $objHtlBooking->id_hotel = $objCartBooking->id_hotel; $objHtlBooking->id_customer = $cart->id_customer; $objHtlBooking->booking_type = $objCartBooking->booking_type; - $objHtlBooking->id_status = self::STATUS_ALLOTED; + $objHtlBooking->id_status = self::STATUS_ASSIGNED; $objHtlBooking->comment = $objCartBooking->comment; // For Back Order(Because of cart lock) @@ -3464,9 +3479,9 @@ class HotelBookingDetail extends ObjectModel $moduleInstance = Module::getInstanceByName('hotelreservationsystem'); $pages = array( - 'STATUS_ALLOTED' => array( - 'id_status' => self::STATUS_ALLOTED, - 'name' => $moduleInstance->l('Alloted', 'hotelreservationsystem') + 'STATUS_ASSIGNED' => array( + 'id_status' => self::STATUS_ASSIGNED, + 'name' => $moduleInstance->l('Assigned', 'hotelreservationsystem') ), 'STATUS_CHECKED_IN' => array( 'id_status' => self::STATUS_CHECKED_IN, @@ -3506,7 +3521,7 @@ class HotelBookingDetail extends ObjectModel } // process the booking tables changes when a booking refund/cancellation is processed - public function processRefundInBookingTables() + public function processRefundInBookingTables($refundedAmountTaxIncl = null) { if (Validate::isLoadedObject($this)) { $reduction_amount = array( @@ -3525,10 +3540,12 @@ class HotelBookingDetail extends ObjectModel if (!$hasOrderDiscountOrPayment) { $objServiceProductOrderDetail = new ServiceProductOrderDetail(); - $reduction_amount['total_price_tax_excl'] = (float) $this->total_price_tax_excl; - $reduction_amount['total_products_tax_excl'] = (float) $this->total_price_tax_excl; - $reduction_amount['total_price_tax_incl'] = (float) $this->total_price_tax_incl; - $reduction_amount['total_products_tax_incl'] = (float) $this->total_price_tax_incl; + $roomPriceTaxExcl = (float) $this->total_price_tax_excl; + $roomPriceTaxIncl = (float) $this->total_price_tax_incl; + $reduction_amount['total_price_tax_excl'] = $roomPriceTaxExcl; + $reduction_amount['total_products_tax_excl'] = $roomPriceTaxExcl; + $reduction_amount['total_price_tax_incl'] = $roomPriceTaxIncl; + $reduction_amount['total_products_tax_incl'] = $roomPriceTaxIncl; // reduce services amount from order and services_detail if ($roomServices = $objServiceProductOrderDetail->getRoomTypeServiceProducts( @@ -3604,10 +3621,11 @@ class HotelBookingDetail extends ObjectModel $objOrderDetail->product_quantity_refunded = $objOrderDetail->product_quantity; } - if (!$hasOrderDiscountOrPayment) { - // reduce room amount from order and order detail + if (!$hasOrderDiscountOrPayment && $refundedAmountTaxIncl === null) { + // reduce room amount from order and order detail — only for + // the legacy full-cancellation callers, see comment above $objOrderDetail->total_price_tax_incl -= Tools::processPriceRounding( - $this->total_price_tax_incl, + $reduction_amount['total_price_tax_incl'], 1, $objOrder->round_type, $objOrder->round_mode @@ -3615,7 +3633,7 @@ class HotelBookingDetail extends ObjectModel $objOrderDetail->total_price_tax_incl = $objOrderDetail->total_price_tax_incl > 0 ? $objOrderDetail->total_price_tax_incl : 0; $objOrderDetail->total_price_tax_excl -= Tools::processPriceRounding( - $this->total_price_tax_excl, + $reduction_amount['total_price_tax_excl'], 1, $objOrder->round_type, $objOrder->round_mode @@ -3666,17 +3684,23 @@ class HotelBookingDetail extends ObjectModel $objOrderDetail->save(); } - // as refund is completed then set the booking as refunded - $this->is_refunded = 1; - if (!$hasOrderDiscountOrPayment) { - // Reduce room amount from htl_booking_detail - $this->is_cancelled = 1; + if (!$hasOrderDiscountOrPayment && $refundedAmountTaxIncl === null) { + // Reduce room amount from htl_booking_detail — legacy full- + // cancellation callers only, see comment above $this->total_price_tax_excl = 0; $this->total_price_tax_incl = 0; } $this->save(); + // if automatic overbooking resolution is enabled and this room is now + // free (and not itself a back-order room), resolve overbookings for it — + // moved here from update() since this is the one real trigger point: + // a completed refund freeing up the room, which only ever happens here + if (Configuration::get('PS_OVERBOOKING_AUTO_RESOLVE') && $this->is_back_order == 0) { + $this->resolveOverBookings(); + } + return true; } @@ -3713,7 +3737,7 @@ class HotelBookingDetail extends ObjectModel $sql .= ' *'; } - $sql .= ' FROM `'._DB_PREFIX_.'htl_booking_detail` WHERE `is_back_order` = 1 AND `is_refunded` = 0 AND `is_cancelled` = 0'; + $sql .= ' FROM `'._DB_PREFIX_.'htl_booking_detail` WHERE `is_back_order` = 1 AND `id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().') AND `id_status` != '.self::STATUS_CANCELLED; if ($idOrder) { $sql .= ' AND `id_order` = '.(int) $idOrder; @@ -3771,7 +3795,7 @@ class HotelBookingDetail extends ObjectModel */ public function getOverBookedOrders($onlyFutureDates = 0) { - $sql = 'SELECT DISTINCT `id_order` FROM `'._DB_PREFIX_.'htl_booking_detail` WHERE `is_back_order` = 1 AND `is_refunded` = 0 AND `is_cancelled` = 0'; + $sql = 'SELECT DISTINCT `id_order` FROM `'._DB_PREFIX_.'htl_booking_detail` WHERE `is_back_order` = 1 AND `id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().') AND `id_status` != '.self::STATUS_CANCELLED; if ($onlyFutureDates) { $sql .= ' AND `date_to` > \''.pSQL(date('Y-m-d')).'\''; diff --git a/modules/hotelreservationsystem/classes/HotelBookingStatus.php b/modules/hotelreservationsystem/classes/HotelBookingStatus.php new file mode 100644 index 000000000..1694e5476 --- /dev/null +++ b/modules/hotelreservationsystem/classes/HotelBookingStatus.php @@ -0,0 +1,90 @@ + 'htl_booking_status', + 'primary' => 'id_booking_status', + 'multilang' => true, + 'fields' => array( + 'color' => array('type' => self::TYPE_STRING, 'validate' => 'isColor', 'required' => true), + 'is_terminal' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), + // lang fields + 'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isCatalogName', 'required' => true, 'size' => 64), + ), + ); + + /** + * Which statuses a booking is allowed to move to from its current status. + * + * @param int $currentStatus one of HotelBookingDetail::STATUS_* + * @return array list of HotelBookingDetail::STATUS_* values allowed as the next status + */ + public static function getAllowedTransitions($currentStatus) + { + $transitions = array( + HotelBookingDetail::STATUS_ASSIGNED => array( + HotelBookingDetail::STATUS_CHECKED_IN, + HotelBookingDetail::STATUS_NO_SHOW, + HotelBookingDetail::STATUS_CANCELLED, + ), + HotelBookingDetail::STATUS_CHECKED_IN => array( + HotelBookingDetail::STATUS_CHECKED_OUT, + // revert: undo an accidental check-in + HotelBookingDetail::STATUS_ASSIGNED, + ), + HotelBookingDetail::STATUS_CHECKED_OUT => array( + // revert: undo an accidental check-out + HotelBookingDetail::STATUS_ASSIGNED, + HotelBookingDetail::STATUS_CHECKED_IN, + ), + ); + + return isset($transitions[$currentStatus]) ? $transitions[$currentStatus] : array(); + } + + /** + * @param int $idLang + * @return array catalog rows (id_status = id_booking_status, color, is_terminal, name), ordered by id + */ + public function getAllStatuses($idLang = 0) + { + if (!$idLang) { + $idLang = Context::getContext()->language->id; + } + + $sql = 'SELECT hbs.*, hbs.`id_booking_status` AS id_status, hbsl.`name` FROM `'._DB_PREFIX_.$this->table.'` hbs + LEFT JOIN `'._DB_PREFIX_.$this->table.'_lang` hbsl ON hbs.`id_booking_status` = hbsl.`id_booking_status` AND hbsl.`id_lang` = '.(int) $idLang.' + ORDER BY hbs.`id_booking_status` ASC'; + + return Db::getInstance()->executeS($sql); + } +} diff --git a/modules/hotelreservationsystem/classes/HotelBookingStatusHistory.php b/modules/hotelreservationsystem/classes/HotelBookingStatusHistory.php new file mode 100644 index 000000000..87624c093 --- /dev/null +++ b/modules/hotelreservationsystem/classes/HotelBookingStatusHistory.php @@ -0,0 +1,65 @@ + 'htl_booking_status_history', + 'primary' => 'id_booking_status_history', + 'fields' => array( + 'id_htl_booking' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true), + 'id_status_from' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'allow_null' => true), + 'id_status_to' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true), + 'id_employee' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'allow_null' => true), + 'id_customer' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'allow_null' => true), + 'remark' => array('type' => self::TYPE_STRING, 'validate' => 'isCleanHtml'), + 'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'), + ), + ); + + public function getBookingStatusHistoryByOrder($idOrder) + { + $sql = 'SELECT h.*, hbd.room_num, hbd.id_product, hbd.date_from, hbd.date_to, + e.`firstname` AS efirstname, e.`lastname` AS elastname, + c.`firstname` AS cfirstname, c.`lastname` AS clastname + FROM `'._DB_PREFIX_.$this->table.'` h + INNER JOIN `'._DB_PREFIX_.'htl_booking_detail` hbd ON hbd.`id` = h.`id_htl_booking` + LEFT OUTER JOIN `'._DB_PREFIX_.'employee` e ON e.`id_employee` = h.`id_employee` + LEFT JOIN `'._DB_PREFIX_.'customer` c ON c.`id_customer` = h.`id_customer` + WHERE hbd.`id_order` = '.(int) $idOrder.' + ORDER BY h.`id_booking_status_history` ASC'; + + return Db::getInstance()->executeS($sql); + } +} diff --git a/modules/hotelreservationsystem/classes/HotelHelper.php b/modules/hotelreservationsystem/classes/HotelHelper.php index d444480a2..58aeeff9b 100644 --- a/modules/hotelreservationsystem/classes/HotelHelper.php +++ b/modules/hotelreservationsystem/classes/HotelHelper.php @@ -1227,6 +1227,101 @@ class HotelHelper ); } + public function createDefaultBookingStatuses() + { + $htlBookingStatuses = array( + array( + 'id' => HotelBookingDetail::STATUS_ASSIGNED, + 'color' => '#4169E1', + 'is_terminal' => 0, + 'name' => array( + 'en' => 'Assigned', + 'nl' => 'Toegewezen', + 'fr' => 'Assignée', + 'de' => 'Zugewiesen', + 'ru' => 'Назначено', + 'es' => 'Asignada', + ), + ), + array( + 'id' => HotelBookingDetail::STATUS_CHECKED_IN, + 'color' => '#17A2B8', + 'is_terminal' => 0, + 'name' => array( + 'en' => 'Checked-in', + 'nl' => 'Ingecheckt', + 'fr' => 'Enregistrée', + 'de' => 'Eingecheckt', + 'ru' => 'Заселено', + 'es' => 'Registrada', + ), + ), + array( + 'id' => HotelBookingDetail::STATUS_CHECKED_OUT, + 'color' => '#108510', + 'is_terminal' => 0, + 'name' => array( + 'en' => 'Checked-out', + 'nl' => 'Uitgecheckt', + 'fr' => 'Départ effectué', + 'de' => 'Ausgecheckt', + 'ru' => 'Выселено', + 'es' => 'Salida realizada', + ), + ), + array( + 'id' => HotelBookingDetail::STATUS_NO_SHOW, + 'color' => '#DC143C', + 'is_terminal' => 1, + 'name' => array( + 'en' => 'No-show', + 'nl' => 'Niet verschenen', + 'fr' => 'Non présentée', + 'de' => 'Nicht erschienen', + 'ru' => 'Неявка', + 'es' => 'No presentada', + ), + ), + array( + 'id' => HotelBookingDetail::STATUS_CANCELLED, + 'color' => '#FF8C00', + 'is_terminal' => 1, + 'name' => array( + 'en' => 'Cancelled', + 'nl' => 'Geannuleerd', + 'fr' => 'Annulée', + 'de' => 'Storniert', + 'ru' => 'Отменено', + 'es' => 'Cancelada', + ), + ), + ); + + $languages = Language::getLanguages(true); + foreach ($htlBookingStatuses as $htlBookingStatus) { + $objBookingStatus = new HotelBookingStatus(); + // fixed id: this catalog's rows are referenced by the HotelBookingDetail::STATUS_* constants + $objBookingStatus->id = $htlBookingStatus['id']; + $objBookingStatus->force_id = true; + $objBookingStatus->color = $htlBookingStatus['color']; + $objBookingStatus->is_terminal = $htlBookingStatus['is_terminal']; + + foreach ($languages as $lang) { + if (isset($htlBookingStatus['name'][$lang['iso_code']])) { + $objBookingStatus->name[$lang['id_lang']] = $htlBookingStatus['name'][$lang['iso_code']]; + } else { + $objBookingStatus->name[$lang['id_lang']] = $htlBookingStatus['name']['en']; + } + } + + if (!$objBookingStatus->add()) { + return false; + } + } + + return true; + } + public static function getPsProducts($id_lang, $start = 0, $limit = 0, $booking_product = null) { $sql = 'SELECT p.`id_product`, pl.`name`, p.`booking_product` diff --git a/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php b/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php index 27de4e77a..b1a1b597f 100644 --- a/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php +++ b/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php @@ -213,14 +213,38 @@ class HotelReservationSystemDb `adults` smallint(6) NOT NULL DEFAULT '0', `children` smallint(6) NOT NULL DEFAULT '0', `child_ages` text NOT NULL, - `is_refunded` tinyint(1) NOT NULL DEFAULT '0', - `is_cancelled` tinyint(1) NOT NULL DEFAULT '0', -- `available_for_order` tinyint(1) NOT NULL DEFAULT '0', `date_add` datetime NOT NULL, `date_upd` datetime NOT NULL, PRIMARY KEY (`id`) ) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;", + "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_booking_status` ( + `id_booking_status` int(11) NOT NULL AUTO_INCREMENT, + `color` varchar(32) NOT NULL, + `is_terminal` tinyint(1) NOT NULL DEFAULT '0', + PRIMARY KEY (`id_booking_status`) + ) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;", + + "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_booking_status_lang` ( + `id_booking_status` int(11) NOT NULL, + `id_lang` int(11) NOT NULL, + `name` varchar(64) NOT NULL, + PRIMARY KEY (`id_booking_status`, `id_lang`) + ) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8;", + + "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_booking_status_history` ( + `id_booking_status_history` int(11) NOT NULL AUTO_INCREMENT, + `id_htl_booking` int(11) NOT NULL, + `id_status_from` int(11) DEFAULT NULL, + `id_status_to` int(11) NOT NULL, + `id_employee` int(11) DEFAULT NULL, + `id_customer` int(11) DEFAULT NULL, + `remark` text, + `date_add` datetime NOT NULL, + PRIMARY KEY (`id_booking_status_history`) + ) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;", + "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_booking_document` ( `id_htl_booking_document` int(11) NOT NULL AUTO_INCREMENT, `id_htl_booking` int(11) NOT NULL, @@ -556,6 +580,9 @@ class HotelReservationSystemDb `'._DB_PREFIX_.'htl_amenity_lang`, `'._DB_PREFIX_.'htl_cart_booking_data`, `'._DB_PREFIX_.'htl_booking_detail`, + `'._DB_PREFIX_.'htl_booking_status`, + `'._DB_PREFIX_.'htl_booking_status_lang`, + `'._DB_PREFIX_.'htl_booking_status_history`, `'._DB_PREFIX_.'htl_booking_document`, `'._DB_PREFIX_.'htl_room_status`, `'._DB_PREFIX_.'htl_advance_payment`, diff --git a/modules/hotelreservationsystem/classes/HotelRoomInformation.php b/modules/hotelreservationsystem/classes/HotelRoomInformation.php index a97c67e0f..08708b8b1 100644 --- a/modules/hotelreservationsystem/classes/HotelRoomInformation.php +++ b/modules/hotelreservationsystem/classes/HotelRoomInformation.php @@ -293,7 +293,7 @@ class HotelRoomInformation extends ObjectModel public function getFutureBookings($idRoom) { - return Db::getInstance()->executeS('SELECT `id`, `id_order`, `date_from`, `date_to` FROM `'._DB_PREFIX_.'htl_booking_detail` where `date_to` > \''.pSQL(date('Y-m-d')).'\' AND `is_refunded` = 0 AND `id_room`='.(int) $idRoom); + return Db::getInstance()->executeS('SELECT `id`, `id_order`, `date_from`, `date_to` FROM `'._DB_PREFIX_.'htl_booking_detail` where `date_to` > \''.pSQL(date('Y-m-d')).'\' AND `id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().') AND `id_room`='.(int) $idRoom); } // Webservice :: webservice add function diff --git a/modules/hotelreservationsystem/classes/ServiceProductOrderDetail.php b/modules/hotelreservationsystem/classes/ServiceProductOrderDetail.php index 32a07182d..713045f68 100644 --- a/modules/hotelreservationsystem/classes/ServiceProductOrderDetail.php +++ b/modules/hotelreservationsystem/classes/ServiceProductOrderDetail.php @@ -519,7 +519,7 @@ class ServiceProductOrderDetail extends ObjectModel } // process the tables changes when a product refund/cancellation is processed - public function processRefundInTables() + public function processRefundInTables($refundedAmountTaxIncl = null) { if (Validate::isLoadedObject($this)) { $reduction_amount = array( @@ -538,10 +538,12 @@ class ServiceProductOrderDetail extends ObjectModel if (!$hasOrderDiscountOrPayment) { $objServiceProductOrderDetail = new ServiceProductOrderDetail(); - $reduction_amount['total_price_tax_excl'] = (float) $this->total_price_tax_excl; - $reduction_amount['total_products_tax_excl'] = (float) $this->total_price_tax_excl; - $reduction_amount['total_price_tax_incl'] = (float) $this->total_price_tax_incl; - $reduction_amount['total_products_tax_incl'] = (float) $this->total_price_tax_incl; + $priceTaxExcl = (float) $this->total_price_tax_excl; + $priceTaxIncl = (float) $this->total_price_tax_incl; + $reduction_amount['total_price_tax_excl'] = $priceTaxExcl; + $reduction_amount['total_products_tax_excl'] = $priceTaxExcl; + $reduction_amount['total_price_tax_incl'] = $priceTaxIncl; + $reduction_amount['total_products_tax_incl'] = $priceTaxIncl; } // enter refunded quantity in the order detail table @@ -553,17 +555,18 @@ class ServiceProductOrderDetail extends ObjectModel $objOrderDetail->product_quantity_refunded = $objOrderDetail->product_quantity; } - if (!$hasOrderDiscountOrPayment) { - // reduce room amount from order and order detail + if (!$hasOrderDiscountOrPayment && $refundedAmountTaxIncl === null) { + // reduce room amount from order and order detail — only for + // the legacy full-cancellation callers, see comment above $objOrderDetail->total_price_tax_incl -= Tools::processPriceRounding( - $this->total_price_tax_incl, + $reduction_amount['total_price_tax_incl'], 1, $objOrder->round_type, $objOrder->round_mode ); $objOrderDetail->total_price_tax_excl -= Tools::processPriceRounding( - $this->total_price_tax_excl, + $reduction_amount['total_price_tax_excl'], 1, $objOrder->round_type, $objOrder->round_mode @@ -605,8 +608,9 @@ class ServiceProductOrderDetail extends ObjectModel // as refund is completed then set the booking as refunded $this->is_refunded = 1; - if (!$hasOrderDiscountOrPayment) { - // Reduce room amount from htl_booking_detail + if (!$hasOrderDiscountOrPayment && $refundedAmountTaxIncl === null) { + // Reduce room amount from htl_booking_detail — legacy full- + // cancellation callers only, see comment above $this->is_cancelled = 1; $this->total_price_tax_excl = 0; $this->total_price_tax_incl = 0; diff --git a/modules/hotelreservationsystem/controllers/admin/AdminOrderRefundRequestsController.php b/modules/hotelreservationsystem/controllers/admin/AdminOrderRefundRequestsController.php index c2749ccfa..a7be0f538 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminOrderRefundRequestsController.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminOrderRefundRequestsController.php @@ -44,6 +44,17 @@ class AdminOrderRefundRequestsController extends ModuleAdminController $this->_join .= 'LEFT JOIN '._DB_PREFIX_.'order_return_state_lang orsl ON (orsl.`id_order_return_state` = a.`state` AND orsl.`id_lang` = '.(int)$this->context->language->id.')'; $this->_join .= ' LEFT JOIN `'._DB_PREFIX_.'order_return_detail` ordrd ON (a.`id_order_return` = ordrd.`id_order_return`)'; $this->_where = ' AND a.`id_order`='. (int)$idOrder; + // optional: narrow the list down to requests that include one specific + // booking or product — used by the Refund column's link on the order detail page + if ($idHtlBooking = (int) Tools::getValue('id_htl_booking')) { + $this->_where .= ' AND a.`id_order_return` IN ( + SELECT id_order_return FROM `'._DB_PREFIX_.'order_return_detail` WHERE id_htl_booking = '.$idHtlBooking.' + )'; + } elseif ($idServiceProductOrderDetail = (int) Tools::getValue('id_service_product_order_detail')) { + $this->_where .= ' AND a.`id_order_return` IN ( + SELECT id_order_return FROM `'._DB_PREFIX_.'order_return_detail` WHERE id_service_product_order_detail = '.$idServiceProductOrderDetail.' + )'; + } $this->_group = 'GROUP BY a.`id_order_return`'; } else { $this->_select .= ', ord.`total_paid_tax_incl` AS total_order, os.`id_order_state`, os.`color`, COUNT(IF(a.`state` = '.(int) Configuration::get('PS_ORS_PENDING').', 1, NULL)) AS total_pending_requests, SUM(a.`refunded_amount`) AS refunded_amount'; @@ -328,11 +339,8 @@ class AdminOrderRefundRequestsController extends ModuleAdminController } $orderTotalPaid = $objOrder->getTotalPaid(); - $orderDiscounts = $objOrder->getCartRules(); - $hasOrderDiscountOrPayment = ((float)$orderTotalPaid > 0 || $orderDiscounts) ? true : false; $this->context->smarty->assign( array ( - 'hasOrderDiscountOrPayment' => $hasOrderDiscountOrPayment, 'orderTotalPaid' => $orderTotalPaid, 'customer_name' => $objCustomer->firstname.' '.$objCustomer->lastname, 'customer_email' => $objCustomer->email, @@ -347,6 +355,7 @@ class AdminOrderRefundRequestsController extends ModuleAdminController $this->context->language->id), 'current_id_lang' => $this->context->language->id, 'refundStatuses' => $refundStatuses, + 'ROOM_STATUS_CANCELLED' => HotelBookingDetail::STATUS_CANCELLED, 'isRefundCompleted' => $objOrderReturn->hasBeenCompleted(), 'paymentMethods' => $paymentMethods, 'name_controller' => Tools::getValue('controller'), @@ -366,66 +375,62 @@ class AdminOrderRefundRequestsController extends ModuleAdminController 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 ($idRefundState != $objOrderReturn->state) { if ($objRefundState->refunded) { $refundedAmounts = Tools::getValue('refund_amounts'); - if ($hasOrderDiscountOrPayment) { - if ($idsReturnDetail && count($idsReturnDetail)) { - if ($refundedAmounts) { - foreach ($idsReturnDetail as $idRetDetail) { - if (!isset($refundedAmounts[$idRetDetail]) || !Validate::isPrice($refundedAmounts[$idRetDetail])) { - $this->errors[] = $this->l('Invalid refund amount(s) entered.'); - } - } - } else { - $this->errors[] = $this->l('Invalid refund amount(s) entered.'); - } - - // If there are no errors in the refund amounts the check validations depends on refund amount - if (!count($this->errors)) { - $totalRefundAmount = array_sum($refundedAmounts); - if (Tools::isSubmit('generateCreditSlip')) { - if ($totalRefundAmount <= 0) { - $this->errors[] = $this->l('Invalid refund amount(s) for generating credit slip.'); - } - } - if (Tools::isSubmit('generateDiscount')) { - if ($totalRefundAmount <= 0) { - $this->errors[] = $this->l('Invalid refund amount(s) for generating voucher.'); - } - } - - if (Tools::isSubmit('refundTransactionAmount')) { - if ($totalRefundAmount <= 0) { - $this->errors[] = $this->l('Invalid refund amount(s) for entering refund transaction details.'); - } else { - $paymentMode = Tools::getValue('payment_method'); - if (!$paymentMode) { - $paymentMode = Tools::getValue('other_payment_mode'); - if (!$paymentMode) { - $this->errors[] = $this->l('Please enter the payment mode of the refund transaction.'); - } elseif (!Validate::isGenericName($paymentMode)) { - $this->errors[] = $this->l('Invalid payment mode entered.'); - } - } - - $idTransaction = Tools::getValue('id_transaction'); - if (!$idTransaction) { - $this->errors[] = $this->l('Please enter the transaction id of the refund transaction.'); - } elseif (!Validate::isGenericName($idTransaction)) { - $this->errors[] = $this->l('Invalid transaction id entered.'); - } - } + if ($idsReturnDetail && count($idsReturnDetail)) { + if ($refundedAmounts) { + foreach ($idsReturnDetail as $idRetDetail) { + if (!isset($refundedAmounts[$idRetDetail]) || !Validate::isPrice($refundedAmounts[$idRetDetail])) { + $this->errors[] = $this->l('Invalid refund amount(s) entered.'); } } } else { - $this->errors[] = $this->l('Select at least one booking for refund.'); + $this->errors[] = $this->l('Invalid refund amount(s) entered.'); } + + // If there are no errors in the refund amounts the check validations depends on refund amount + if (!count($this->errors)) { + $totalRefundAmount = array_sum($refundedAmounts); + if (Tools::isSubmit('generateCreditSlip')) { + if ($totalRefundAmount <= 0) { + $this->errors[] = $this->l('Invalid refund amount(s) for generating credit slip.'); + } + } + if (Tools::isSubmit('generateDiscount')) { + if ($totalRefundAmount <= 0) { + $this->errors[] = $this->l('Invalid refund amount(s) for generating voucher.'); + } + } + + if (Tools::isSubmit('refundTransactionAmount')) { + if ($totalRefundAmount <= 0) { + $this->errors[] = $this->l('Invalid refund amount(s) for entering refund transaction details.'); + } else { + $paymentMode = Tools::getValue('payment_method'); + if (!$paymentMode) { + $paymentMode = Tools::getValue('other_payment_mode'); + if (!$paymentMode) { + $this->errors[] = $this->l('Please enter the payment mode of the refund transaction.'); + } elseif (!Validate::isGenericName($paymentMode)) { + $this->errors[] = $this->l('Invalid payment mode entered.'); + } + } + + $idTransaction = Tools::getValue('id_transaction'); + if (!$idTransaction) { + $this->errors[] = $this->l('Please enter the transaction id of the refund transaction.'); + } elseif (!Validate::isGenericName($idTransaction)) { + $this->errors[] = $this->l('Invalid transaction id entered.'); + } + } + } + } + } else { + $this->errors[] = $this->l('Select at least one booking for refund.'); } } } else { @@ -454,25 +459,34 @@ class AdminOrderRefundRequestsController extends ModuleAdminController if ($objRefundState->refunded) { foreach ($idsReturnDetail as $idRetDetail) { $objOrderReturnDetail = new OrderReturnDetail($idRetDetail); - // set booking as refunded if return state is refunded/denied - $reduction_amount = array( - 'total_price_tax_excl' => 0, - 'total_price_tax_incl' => 0, - 'total_products_tax_excl' => 0, - 'total_products_tax_incl' => 0, - ); + // the amount staff entered for this line + $refundedAmount = $refundedAmounts[$idRetDetail]; + if ($idHtlBooking = $objOrderReturnDetail->id_htl_booking) { $objHtlBooking = new HotelBookingDetail($idHtlBooking); // perform booking refund processes in the booking tables - $objHtlBooking->processRefundInBookingTables(); + $objHtlBooking->processRefundInBookingTables($refundedAmount); + + // paid Cancelled/No-show requests only flip the room's status + // once the refund is actually approved here + if ($objOrderReturn->event_type == OrderReturn::EVENT_TYPE_CANCELLATION) { + $objHtlBooking->changeStatus(HotelBookingDetail::STATUS_CANCELLED, array( + 'id_employee' => (int) $this->context->employee->id, + 'remark' => $objOrderReturn->question, + )); + } elseif ($objOrderReturn->event_type == OrderReturn::EVENT_TYPE_NO_SHOW) { + $objHtlBooking->changeStatus(HotelBookingDetail::STATUS_NO_SHOW, array( + 'id_employee' => (int) $this->context->employee->id, + 'remark' => $objOrderReturn->question, + )); + } } elseif ($id_service_product_order_detail = $objOrderReturnDetail->id_service_product_order_detail) { $objServiceProductOrderDetail = new ServiceProductOrderDetail($id_service_product_order_detail); // perform booking refund processes in the service product order tables - $objServiceProductOrderDetail->processRefundInTables(); + $objServiceProductOrderDetail->processRefundInTables($refundedAmount); } // 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; @@ -491,38 +505,47 @@ class AdminOrderRefundRequestsController extends ModuleAdminController $objHtlBooking = new HotelBookingDetail($idHtlBooking); $idOrderDetail = $objHtlBooking->id_order_detail; + // split the admin's single tax-incl entry using the booking's + // own tax ratio; (float) cast since DB decimals come back as + // strings like "0.000000", which PHP treats as truthy + $refundedAmountTaxExcl = (float) $objHtlBooking->total_price_tax_incl + ? $refundedAmount * ($objHtlBooking->total_price_tax_excl / $objHtlBooking->total_price_tax_incl) + : $refundedAmount; + $bookingList[$idRetDetail] = array( 'id_htl_booking' => $idHtlBooking, 'id_order_detail' => $idOrderDetail, 'quantity' => $numDays, 'num_days' => $numDays, - 'unit_price' => $refundedAmount / $numDays, - 'amount' => $refundedAmount, + 'unit_price' => $refundedAmountTaxExcl / $numDays, ); } elseif ($idServiceProductOrder = $objOrderReturnDetail->id_service_product_order_detail) { $objServiceProductOrderDetail = new ServiceProductOrderDetail($idServiceProductOrder); + + // same reasoning as the booking branch above + $refundedAmountTaxExcl = (float) $objServiceProductOrderDetail->total_price_tax_incl + ? $refundedAmount * ($objServiceProductOrderDetail->total_price_tax_excl / $objServiceProductOrderDetail->total_price_tax_incl) + : $refundedAmount; + $bookingList[$idRetDetail] = array( 'id_service_product_order_detail' => $idServiceProductOrder, 'id_order_detail' => $objServiceProductOrderDetail->id_order_detail, 'quantity' => $objServiceProductOrderDetail->quantity, - 'unit_price' => $refundedAmount / $objServiceProductOrderDetail->quantity, - 'amount' => $refundedAmount, + 'unit_price' => $refundedAmountTaxExcl / $objServiceProductOrderDetail->quantity, ); } } } // if bookings are refunded then set the payment information - if ($hasOrderDiscountOrPayment) { - if (Tools::isSubmit('refundTransactionAmount')) { - $objOrderReturn->payment_mode = $paymentMode; - $objOrderReturn->id_transaction = $idTransaction; - } elseif (Tools::isSubmit('generateDiscount')) { - $objOrderReturn->payment_mode = 'Voucher'; - } elseif (!((float) $orderTotalPaid)) { - $objOrderReturn->payment_mode = 'Unpaid by customer'; - $objOrderReturn->id_transaction = '-'; - } + if (Tools::isSubmit('refundTransactionAmount')) { + $objOrderReturn->payment_mode = $paymentMode; + $objOrderReturn->id_transaction = $idTransaction; + } elseif (Tools::isSubmit('generateDiscount')) { + $objOrderReturn->payment_mode = 'Voucher'; + } elseif (!((float) $orderTotalPaid)) { + $objOrderReturn->payment_mode = 'Unpaid by customer'; + $objOrderReturn->id_transaction = '-'; } } @@ -532,23 +555,11 @@ class AdminOrderRefundRequestsController extends ModuleAdminController $objOrderReturn->changeIdOrderReturnState($idRefundState); // change state of the order to refunded if all the room bookings in the order are completely refunded + // (syncRefundStatus() itself skips the bump if the order + // is already at that state — e.g. already bumped by a No-show/Cancelled + // room-status change before this request was ever approved) if ($objRefundState->refunded) { - $idOrderState = $objOrder->getOrderCompleteRefundStatus(); - - // If order is completely refunded or cancelled then change the order state - if ($idOrderState) { - // check if order is paid the set status of the order to refunded - $objOrderHistory = new OrderHistory(); - $objOrderHistory->id_order = (int)$objOrder->id; - - $useExistingPayment = false; - if (!$objOrder->hasInvoice()) { - $useExistingPayment = true; - } - - $objOrderHistory->changeIdOrderState($idOrderState, $objOrder, $useExistingPayment); - $objOrderHistory->addWithemail(); - } + $objOrder->syncRefundStatus(); } // E-mail params diff --git a/modules/hotelreservationsystem/controllers/admin/AdminRoomStatusesController.php b/modules/hotelreservationsystem/controllers/admin/AdminRoomStatusesController.php new file mode 100644 index 000000000..540efa9c0 --- /dev/null +++ b/modules/hotelreservationsystem/controllers/admin/AdminRoomStatusesController.php @@ -0,0 +1,164 @@ +bootstrap = true; + $this->table = 'htl_booking_status'; + $this->className = 'HotelBookingStatus'; + $this->identifier = 'id_booking_status'; + $this->context = Context::getContext(); + $this->lang = true; + + parent::__construct(); + $this->_new_list_header_design = true; + + // edit only — the 5 statuses are fixed (their IDs are the + // HotelBookingDetail::STATUS_* constants used everywhere), no add/delete + $this->addRowAction('edit'); + + $this->fields_list = array( + 'id_booking_status' => array( + 'title' => $this->l('ID'), + 'align' => 'center', + 'class' => 'fixed-width-xs', + ), + 'name' => array( + 'title' => $this->l('Name'), + 'align' => 'center', + 'color' => 'color', + ), + 'is_terminal' => array( + 'title' => $this->l('Terminal (final) status'), + 'align' => 'text-center', + 'type' => 'bool', + 'callback' => 'getTerminalStatusLabel', + 'orderby' => false, + 'class' => 'fixed-width-sm', + ), + ); + } + + public function getTerminalStatusLabel($value) + { + return $value ? $this->l('Yes') : $this->l('No'); + } + + public function initToolbar() + { + // no "Add new" toolbar button — statuses are fixed + $this->toolbar_btn = array(); + } + + public function postProcess() + { + // server-side guard, not just hidden buttons: this table's 5 rows are fixed + if (Tools::isSubmit('add'.$this->table) + || Tools::isSubmit('delete'.$this->table) + || Tools::isSubmit('submitBulkdelete'.$this->table) + ) { + $this->errors[] = $this->l('Room statuses cannot be added or deleted.'); + return; + } + + parent::postProcess(); + } + + public function renderForm() + { + if (!$this->loadObject()) { + return; + } + + // decoupled from the real 'is_terminal' field name on purpose: copyFromPost() + // writes any POST key matching a real object property, and 'disabled' on the + // switch only blocks submission client-side (removable via devtools). Using + // a name with no matching property makes server-side tampering impossible, + // not just hidden. + $this->fields_value['is_terminal_display'] = $this->object->is_terminal; + + $this->fields_form = array( + 'legend' => array( + 'title' => $this->l('Room Status'), + 'icon' => 'icon-bookmark', + ), + 'input' => array( + array( + 'type' => 'text', + 'label' => $this->l('Name'), + 'name' => 'name', + 'lang' => true, + 'required' => true, + 'col' => 4, + ), + array( + 'type' => 'color', + 'label' => $this->l('Color'), + 'name' => 'color', + 'required' => true, + ), + array( + 'type' => 'switch', + 'label' => $this->l('Terminal (final) status'), + 'name' => 'is_terminal_display', + 'hint' => $this->l('If set to Yes, a room with this status cannot be edited, only deleted. If No, the room can still be edited. This setting is fixed for each status, so it is disabled here.'), + 'disabled' => true, + 'values' => array( + array( + 'id' => 'is_terminal_on', + 'value' => 1, + 'label' => $this->l('Yes'), + ), + array( + 'id' => 'is_terminal_off', + 'value' => 0, + 'label' => $this->l('No'), + ), + ), + ), + ), + 'submit' => array( + 'title' => $this->l('Save'), + ), + ); + + return parent::renderForm(); + } + + public function processSave() + { + if (!$this->loadObject()) { + return; + } + + $defaultLangId = Configuration::get('PS_LANG_DEFAULT'); + $objDefaultLanguage = Language::getLanguage((int) $defaultLangId); + if (!trim(Tools::getValue('name_'.$defaultLangId))) { + $this->errors[] = $this->l('Status name is required at least in ').$objDefaultLanguage['name']; + } + + return parent::processSave(); + } +} diff --git a/modules/hotelreservationsystem/define.php b/modules/hotelreservationsystem/define.php index d7b44525f..893c6703c 100644 --- a/modules/hotelreservationsystem/define.php +++ b/modules/hotelreservationsystem/define.php @@ -31,6 +31,8 @@ require_once 'classes/HotelAmenities.php'; require_once 'classes/HotelBranchAmenities.php'; require_once 'classes/HotelRoomTypeAmenities.php'; require_once 'classes/HotelBookingDetail.php'; +require_once 'classes/HotelBookingStatus.php'; +require_once 'classes/HotelBookingStatusHistory.php'; require_once 'classes/HotelCartBookingData.php'; require_once 'classes/HotelAdvancedPayment.php'; require_once 'classes/HotelOrderRefundRules.php'; diff --git a/modules/hotelreservationsystem/hotelreservationsystem.php b/modules/hotelreservationsystem/hotelreservationsystem.php index fc4006c28..03e06e031 100644 --- a/modules/hotelreservationsystem/hotelreservationsystem.php +++ b/modules/hotelreservationsystem/hotelreservationsystem.php @@ -420,16 +420,12 @@ class HotelReservationSystem extends Module { $objHtlBkDtl = new HotelBookingDetail(); - // Make rooms available for booking if order status is cancelled, refunded or error - if (in_array($params['newOrderStatus']->id, $objHtlBkDtl->getOrderStatusToFreeBookedRoom())) { - // do not change is_cancelled if room is not getting cancelled - $isCancelled = null; - if ($params['newOrderStatus']->id == Configuration::get('PS_OS_CANCELED')) { - $isCancelled = 1; - } - if (!$objHtlBkDtl->updateOrderRefundStatus($params['id_order'], false, false, array(), 1, $isCancelled)) { - $this->context->controller->errors[] = $this->l('Error while making booked rooms available, attached with this order. Please try again !!'); - } + // If order status is cancelled, refunded or error, a room may have just + // become free — try to resolve any overbookings waiting on it + if (Configuration::get('PS_OVERBOOKING_AUTO_RESOLVE') + && in_array($params['newOrderStatus']->id, $objHtlBkDtl->getOrderStatusToFreeBookedRoom()) + ) { + $objHtlBkDtl->resolveOverBookings(); } } @@ -489,6 +485,8 @@ class HotelReservationSystem extends Module $this->installTab('AdminOrderRefundRequests', 'Manage Order Refund Requests', 'AdminHotelReservationSystemManagement'); $this->installTab('AdminHotelConfigurationSetting', 'General Settings', 'AdminHotelReservationSystemManagement'); + // parented under core Orders, next to the existing "Statuses" tab — same idea, for room statuses + $this->installTab('AdminRoomStatuses', 'Room Statuses', 'AdminParentOrders'); // Controllers without tabs $this->installTab('AdminHotelGeneralSettings', 'Hotel General Configuration', 'AdminHotelConfigurationSetting', false); $this->installTab('AdminHotelFeaturePricesSettings', 'Advanced Price Rules', 'AdminHotelConfigurationSetting', false); @@ -539,6 +537,7 @@ class HotelReservationSystem extends Module || !$this->callInstallTab() || !$objHtlHelper->insertDefaultHotelEntries() || !$objHtlHelper->createHotelRoomDefaultFeatures() + || !$objHtlHelper->createDefaultBookingStatuses() || !$objHtlHelper->insertHotelCommonAmenities() ) { return false; 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 000940747..0ad8b0641 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 @@ -125,6 +125,17 @@ {$currentStateInfo['name']|escape:'html':'UTF-8'} +
+
+ {l s='Request type' mod='hotelreservationsystem'} : +
+
+ {if $orderReturnInfo['event_type'] == OrderReturn::EVENT_TYPE_CANCELLATION}{l s='Cancellation' mod='hotelreservationsystem'} + {elseif $orderReturnInfo['event_type'] == OrderReturn::EVENT_TYPE_NO_SHOW}{l s='No-show' mod='hotelreservationsystem'} + {elseif $orderReturnInfo['event_type'] == OrderReturn::EVENT_TYPE_REFUND}{l s='Refund' mod='hotelreservationsystem'} + {else}--{/if} +
+
{* list of booking requested for refund by the customer *} {if isset($refundReqBookings) && $refundReqBookings} @@ -151,13 +162,11 @@ {if !$isRefundCompleted} {l s='Rooms cancelation charges' mod='hotelreservationsystem'} {/if} - {if $hasOrderDiscountOrPayment || $isRefundCompleted} - {l s='Refund amount' mod='hotelreservationsystem'} + {l s='Refund amount' mod='hotelreservationsystem'} {if $isRefundCompleted} {l s='Refund status' mod='hotelreservationsystem'} {/if} - {/if} {foreach $refundReqBookings as $booking} {assign var="tourismTaxAppliedAmount" value=$booking['tourism_tax_applied_amount']|default:0} @@ -219,21 +228,20 @@ {/if} {/if} - {if $hasOrderDiscountOrPayment || $isRefundCompleted} - -
- {if $isRefundCompleted} + +
+ {if $isRefundCompleted} {displayPrice price=$booking['refunded_amount'] currency=$orderCurrency['id']} - {else} - {$orderCurrency['sign']|escape:'html':'UTF-8'} - - {l s='tax incl.' mod='hotelreservationsystem'} - {/if} -
- + {else} + {$orderCurrency['sign']|escape:'html':'UTF-8'} + + {l s='tax incl.' mod='hotelreservationsystem'} + {/if} +
+ {if $isRefundCompleted} - {if $booking['is_cancelled']} + {if $booking['id_status'] == $ROOM_STATUS_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']} @@ -243,7 +251,6 @@ {/if} {/if} - {/if} {/foreach} @@ -271,12 +278,10 @@ {l s='Total cost (tax incl.)' mod='hotelreservationsystem'} {l s='Total paid amount (tax incl.)' mod='hotelreservationsystem'} - {if $hasOrderDiscountOrPayment || $isRefundCompleted} - {l s='Refund amount' mod='hotelreservationsystem'} + {l s='Refund amount' mod='hotelreservationsystem'} - {if $isRefundCompleted} - {l s='Refund status' mod='hotelreservationsystem'} - {/if} + {if $isRefundCompleted} + {l s='Refund status' mod='hotelreservationsystem'} {/if} {foreach $refundReqProducts as $product} @@ -288,30 +293,28 @@ {if $product['allow_multiple_quantity']}{$product['quantity']|escape:'htmlall':'UTF-8'}{else}--{/if} {displayPrice price=$product['total_price_tax_incl'] currency=$orderCurrency['id']} {displayPrice price=$product['paid_amount'] currency=$orderCurrency['id']} - {if $hasOrderDiscountOrPayment || $isRefundCompleted} + +
+ {if $isRefundCompleted} + {displayPrice price=$product['refunded_amount'] currency=$orderCurrency['id']} + {else} + {$orderCurrency['sign']|escape:'html':'UTF-8'} + + {l s='tax incl.' mod='hotelreservationsystem'} + {/if} +
+ + {if $isRefundCompleted} -
- {if $isRefundCompleted} - {displayPrice price=$product['refunded_amount'] currency=$orderCurrency['id']} - {else} - {$orderCurrency['sign']|escape:'html':'UTF-8'} - - {l s='tax incl.' mod='hotelreservationsystem'} - {/if} -
+ {if $product['is_cancelled']} + {l s='Cancelled' mod='hotelreservationsystem'} + {* used id_customization to check if in this request which bookings are refunded or not*} + {else if $product['id_customization']} + {l s='Refunded' mod='hotelreservationsystem'} + {else} + {l s='Denied' mod='hotelreservationsystem'} + {/if} - {if $isRefundCompleted} - - {if $product['is_cancelled']} - {l s='Cancelled' mod='hotelreservationsystem'} - {* used id_customization to check if in this request which bookings are refunded or not*} - {else if $product['id_customization']} - {l s='Refunded' mod='hotelreservationsystem'} - {else} - {l s='Denied' mod='hotelreservationsystem'} - {/if} - - {/if} {/if} {/foreach} @@ -395,7 +398,6 @@ {* Fields to submit refund information *} - {if $hasOrderDiscountOrPayment} - {/if} {/if} diff --git a/modules/qlohotelreview/classes/QhrHotelReviewHelper.php b/modules/qlohotelreview/classes/QhrHotelReviewHelper.php index 30a8c7ec9..bced1479c 100644 --- a/modules/qlohotelreview/classes/QhrHotelReviewHelper.php +++ b/modules/qlohotelreview/classes/QhrHotelReviewHelper.php @@ -32,8 +32,8 @@ class QhrHotelReviewHelper return (bool) !Db::getInstance()->getValue( 'SELECT COUNT(*) FROM `'._DB_PREFIX_.'htl_booking_detail` hbd WHERE hbd.`id_status` != '.(int) HotelBookingDetail::STATUS_CHECKED_OUT.' - AND hbd.`is_refunded` != 1 - AND hbd.`is_cancelled` != 1 + AND hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().') + AND hbd.`id_status` != '.(int) HotelBookingDetail::STATUS_CANCELLED.' AND hbd.`id_order` = '.(int) $idOrder ); } diff --git a/modules/statsbestcategories/statsbestcategories.php b/modules/statsbestcategories/statsbestcategories.php index c3eb94abf..356f53dce 100644 --- a/modules/statsbestcategories/statsbestcategories.php +++ b/modules/statsbestcategories/statsbestcategories.php @@ -165,7 +165,7 @@ class StatsBestCategories extends ModuleGrid SELECT IFNULL(SUM(DATEDIFF(LEAST(hbd.`date_to`, "'.pSQL($date_to).'"), GREATEST(hbd.`date_from`, "'.pSQL($date_from).'"))), 0) FROM `'._DB_PREFIX_.'htl_booking_detail` hbd LEFT JOIN `'._DB_PREFIX_.'orders` o ON (o.`id_order` = hbd.`id_order`) - WHERE hbd.`id_hotel` = hbi.`id` AND o.`valid` = 1 AND is_refunded = 0 + WHERE hbd.`id_hotel` = hbi.`id` AND o.`valid` = 1 AND hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().') AND hbd.`date_to` > "'.pSQL($date_from).'" AND hbd.`date_from` < "'.pSQL($date_to).'" ) AS totalRoomsBooked, ( diff --git a/themes/hotel-reservation-theme/order-detail.tpl b/themes/hotel-reservation-theme/order-detail.tpl index 65d0f00cf..63d17a30f 100644 --- a/themes/hotel-reservation-theme/order-detail.tpl +++ b/themes/hotel-reservation-theme/order-detail.tpl @@ -1007,16 +1007,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_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} + {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_ASSIGNED}{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-return.tpl b/themes/hotel-reservation-theme/order-return.tpl index 4ef1909b3..fb0822c93 100644 --- a/themes/hotel-reservation-theme/order-return.tpl +++ b/themes/hotel-reservation-theme/order-return.tpl @@ -84,7 +84,7 @@ {displayPrice price=$booking['refunded_amount'] currency=$orderCurrency['id']} - {if $booking['is_cancelled']} + {if $booking['id_status'] == $room_status_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']}