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 935498f70..881a89196 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 @@ -33,6 +33,7 @@ {l s='Total Price (Tax incl.)'} {if isset($refundReqProducts) && $refundReqProducts} {l s='Refund State'} + {l s='Refund'} {l s='Refunded amount'} {/if} {if $can_edit} @@ -87,6 +88,13 @@ -- {/if} + + {if $product.refund_count} + {convertPriceWithCurrency price=$product.refund_amount currency=$currency->id} ({$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} @@ -156,7 +164,7 @@ {assign var=colspan value=6} {if isset($refundReqProducts) && $refundReqProducts} - {assign var=colspan value=($colspan+2)} + {assign var=colspan value=($colspan+3)} {/if} {if ($can_edit)} {assign var=colspan value=($colspan+1)} 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'} {foreach from=$orderOverBookings item=data} - {if !$data.is_refunded} {$data['room_num']} {$data['room_type_name']} @@ -87,7 +86,6 @@ {/if} - {/if} {/foreach} diff --git a/admin/themes/default/template/controllers/orders/_product_line.tpl b/admin/themes/default/template/controllers/orders/_product_line.tpl index 205c0c5e8..8197b7a5b 100644 --- a/admin/themes/default/template/controllers/orders/_product_line.tpl +++ b/admin/themes/default/template/controllers/orders/_product_line.tpl @@ -89,10 +89,15 @@ {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} + {if $data.id_status == $ROOM_STATUS_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'} @@ -103,6 +108,13 @@ -- {/if} + + {if $data.refund_count} + {convertPriceWithCurrency price=$data.refund_amount currency=$currency->id} ({$data.refund_count}) + {else} + -- + {/if} + {if $data.is_refunded && isset($data.refund_info) && $data.refund_info} {convertPriceWithCurrency price=$data.refund_info.refunded_amount currency=$currency->id} @@ -114,7 +126,7 @@ {if ($can_edit && !$order->hasBeenDelivered())}
- {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 743254785..456f2b6c3 100644 --- a/admin/themes/default/template/controllers/orders/_rooms_informaion_table.tpl +++ b/admin/themes/default/template/controllers/orders/_rooms_informaion_table.tpl @@ -36,8 +36,10 @@ {l s='Extra Services/Fee (Tax excl.)'} {l s='Total Tax'} {l s='Total Price (Tax incl.)'} + {l s='Room status'} {if (isset($refundReqBookings) && $refundReqBookings)} {l s='Refund/Cancel Status'} + {l s='Refund'} {l s='Refunded amount'} {/if} {if ($can_edit && !$order->hasBeenDelivered())} 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 34ea13b93..9fe3833cc 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 @@ -33,6 +33,7 @@ {l s='Total Price (Tax incl.)'} {if isset($refundReqProducts) && $refundReqProducts} {l s='Refund State'} + {l s='Refund'} {l s='Refunded amount'} {/if} {if ($can_edit)} @@ -87,6 +88,13 @@ -- {/if} + + {if $product.refund_count} + {convertPriceWithCurrency price=$product.refund_amount currency=$currency->id} ({$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} @@ -156,7 +164,7 @@ {assign var=colspan value=6} {if isset($refundReqProducts) && $refundReqProducts} - {assign var=colspan value=($colspan+2)} + {assign var=colspan value=($colspan+3)} {/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 fd867ee75..21c74ee23 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} @@ -104,8 +106,6 @@ {l s='Check-In'} {l s='Check-Out'} {l s='Allotment'} - {l s='Room status'} - {l s='Refund'} {l s='Action'} @@ -142,27 +142,15 @@ {l s='Auto'} {/if} - - {if isset($htl_booking_statuses[$data.id_status])} - {$htl_booking_statuses[$data.id_status].name|escape:'html':'UTF-8'} - {/if} - - - {if $data.refund_count} - {displayPrice price=$data.refund_amount currency=$currency->id} ({$data.refund_count}) - {else} - -- - {/if} - {if $data.num_checkin_documents > 0}{$data.num_checkin_documents}{else}0{/if} - {if $data.id_status == $ROOM_STATUS_NO_SHOW || $data.id_status == $ROOM_STATUS_CANCELLED} - {if $data.id_status == $ROOM_STATUS_NO_SHOW}{l s='No-show'}{else}{l s='Cancelled'}{/if} - {elseif isset($refundReqBookings) && $refundReqBookings && $data.id|in_array:$refundReqBookings && $data.is_refunded} - {if $data.is_cancelled}{l s='Cancelled'}{else}{l s='Refunded'}{/if} + {if $data.id_status == $ROOM_STATUS_NO_SHOW || (isset($data.is_sealed_no_show) && $data.is_sealed_no_show)} + {$htl_booking_statuses[$ROOM_STATUS_NO_SHOW].name|escape:'html':'UTF-8'} + {elseif $data.id_status == $ROOM_STATUS_CANCELLED || (isset($data.is_sealed_cancelled) && $data.is_sealed_cancelled)} + {$htl_booking_statuses[$ROOM_STATUS_CANCELLED].name|escape:'html':'UTF-8'} {elseif $can_edit} {l s='Edit'} @@ -273,7 +261,7 @@ {* 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'))))}
@@ -863,7 +851,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 && (!$order->hasBeenDelivered() && $currentState->id != Configuration::get('PS_OS_REFUND') && $currentState->id != Configuration::get('PS_OS_CANCELED') && $currentState->id != Configuration::get('PS_OS_NO_SHOW'))} @@ -883,7 +871,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 && (!$order->hasBeenDelivered() && $currentState->id != Configuration::get('PS_OS_REFUND') && $currentState->id != Configuration::get('PS_OS_CANCELED') && $currentState->id != Configuration::get('PS_OS_NO_SHOW'))} @@ -903,7 +891,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 && (!$order->hasBeenDelivered() && $currentState->id != Configuration::get('PS_OS_REFUND') && $currentState->id != Configuration::get('PS_OS_CANCELED') && $currentState->id != Configuration::get('PS_OS_NO_SHOW'))} diff --git a/classes/order/Order.php b/classes/order/Order.php index 52b6cbbd4..df0724f98 100644 --- a/classes/order/Order.php +++ b/classes/order/Order.php @@ -2908,9 +2908,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) { @@ -2921,6 +2948,14 @@ 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; @@ -2950,7 +2985,8 @@ class OrderCore extends ObjectModel // 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, @@ -2971,20 +3007,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_ASSIGNED - ) { - 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 } } @@ -3061,15 +3112,11 @@ class OrderCore extends ObjectModel } 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->hasCompletedRefund($orderBooking['id']) + || $orderBooking['id_status'] == HotelBookingDetail::STATUS_CANCELLED ) { continue; } else { @@ -3082,7 +3129,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'] @@ -3094,9 +3140,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 c4d62e05e..1c9b6f0e2 100644 --- a/classes/order/OrderReturn.php +++ b/classes/order/OrderReturn.php @@ -186,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() + { + 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'; + } + + /** + * Whether this one room booking has at least one completed (actually refunded) return. + * + * @param int $idHtlBooking + * @return bool + */ + public function hasCompletedRefund($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`)'; @@ -221,14 +250,6 @@ class OrderReturnCore extends ObjectModel } 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; @@ -333,7 +354,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`)'; @@ -347,14 +368,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) { @@ -378,7 +391,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`) @@ -789,7 +802,7 @@ class OrderReturnCore extends ObjectModel * 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) + public function getRefundedAmount($idOrder, $idOrderReturn = 0, $idHtlBooking = 0, $detailedInfo = false, $idServiceProductOrderDetail = 0) { $where = ' WHERE orr.`id_order` = '.(int) $idOrder; @@ -801,6 +814,10 @@ class OrderReturnCore extends ObjectModel $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`)'; diff --git a/classes/order/OrderSlip.php b/classes/order/OrderSlip.php index 3f1b2694c..563014b5b 100644 --- a/classes/order/OrderSlip.php +++ b/classes/order/OrderSlip.php @@ -454,6 +454,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 19763851a..2b6d7cb5e 100644 --- a/classes/webservice/WebserviceSpecificManagementBookings.php +++ b/classes/webservice/WebserviceSpecificManagementBookings.php @@ -169,7 +169,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 25511823e..674f6dacf 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -81,7 +81,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'; @@ -303,7 +307,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, ), @@ -785,10 +789,9 @@ class AdminOrdersControllerCore extends AdminController $response['hasError'] = 1; if (Validate::isLoadedObject($objOrder = new Order(Tools::getValue('id_order')))) { $objHotelBookingStatus = new HotelBookingStatus(); - $htlOrderStatus = $objHotelBookingStatus->getAllStatuses( - $this->context->language->id, - (int) Tools::getValue('current_room_status') - ); + // show every status here — PHP-side validation in changeStatus()/changeRoomStatus() + // rejects an invalid pick, so the dropdown doesn't need to pre-filter to allowed ones + $htlOrderStatus = $objHotelBookingStatus->getAllStatuses($this->context->language->id); $this->context->smarty->assign( array( 'order' => $objOrder, @@ -1070,80 +1073,67 @@ class AdminOrdersControllerCore extends AdminController if ($bookingOrderInfo = $objBookingDetail->getBookingDataByOrderId($objOrder->id)) { $objBookingDemand = new HotelBookingDemands(); foreach($bookingOrderInfo as $key => $booking) { - // multiple refund requests are now allowed per booking — only still - // exclude a booking that's already fully refunded, not a re-request - if ($booking['is_refunded']) { - unset($bookingOrderInfo[$key]); - } else { - $bookingOrderInfo[$key]['total_price_tax_incl'] += $objBookingDemand->getRoomTypeBookingExtraDemands( - $objOrder->id, - $booking['id_product'], - $booking['id_room'], - $booking['date_from'], - $booking['date_to'], - 0, - 1, - 1, - $booking['id'] - ); - $bookingOrderInfo[$key]['total_price_tax_excl'] += $objBookingDemand->getRoomTypeBookingExtraDemands( - $objOrder->id, - $booking['id_product'], - $booking['id_room'], - $booking['date_from'], - $booking['date_to'], - 0, - 1, - 0, - $booking['id'] - ); - $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'] += $objBookingDemand->getRoomTypeBookingExtraDemands( + $objOrder->id, + $booking['id_product'], + $booking['id_room'], + $booking['date_from'], + $booking['date_to'], + 0, + 1, + 1, + $booking['id'] + ); + $bookingOrderInfo[$key]['total_price_tax_excl'] += $objBookingDemand->getRoomTypeBookingExtraDemands( + $objOrder->id, + $booking['id_product'], + $booking['id_room'], + $booking['date_from'], + $booking['date_to'], + 0, + 1, + 0, + $booking['id'] + ); + $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( @@ -1918,31 +1908,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)) { - // multiple refund requests are now allowed per booking — only still - // block a booking that's already fully refunded, not a re-request - foreach ($bookings as $idHtlBooking) { - $objBookingDetail = new HotelBookingDetail($idHtlBooking); - if ($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.'); @@ -3126,7 +3093,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_ASSIGNED.'&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; @@ -3138,7 +3105,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; @@ -3151,7 +3118,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; @@ -3400,6 +3367,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; @@ -3592,11 +3575,16 @@ class AdminOrdersControllerCore extends AdminController $order_detail_data[$key]['total_room_tax'] = $order_detail_data[$key]['total_room_price_ti'] - $order_detail_data[$key]['total_room_price_te']; $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->hasCompletedRefund($value['id']); + if (isset($value['refund_info']) && $value['refund_info']['refunded'] && $value['refund_info']['id_customization'] - && $value['is_refunded'] - && !$value['is_cancelled'] + && $objOrderReturn->hasCompletedRefund($value['id']) + && $value['id_status'] != HotelBookingDetail::STATUS_CANCELLED ) { $totalRefundedRooms += 1; } @@ -3633,26 +3621,25 @@ 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->hasCompletedRefund($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']); - - $roomRefundInfo = $objOrderReturn->getRefundedAmount($bookingOrderRoomInfo['id_order'], 0, $bookingOrderRoomInfo['id'], true); - $bookingOrderRoomInfo['refund_amount'] = $roomRefundInfo['amount']; - $bookingOrderRoomInfo['refund_count'] = (int) $roomRefundInfo['count']; } unset($bookingOrderRoomInfo); @@ -7012,14 +6999,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->hasCompletedRefund($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->hasCompletedRefund($id_hotel_booking) && (strtotime($old_date_from) != strtotime($new_date_from) || strtotime($old_date_to) != strtotime($new_date_to)) ) { die(json_encode(array( @@ -8836,6 +8828,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 ) { @@ -8944,31 +8943,32 @@ class AdminOrdersControllerCore extends AdminController $objOrderReturn->changeIdOrderReturnState(Configuration::get('PS_ORS_PENDING')); - $statusChanged = false; - if (!$hasOrderDiscountOrPayment) { - $statusChanged = $objHotelBookingDetail->changeStatus($newStatus, $changeParams); - if ($statusChanged) { - $objHotelBookingDetail->processRefundInBookingTables(); - $objOrderReturn->changeIdOrderReturnState(Configuration::get('PS_ORS_REFUNDED')); + // the room's own status (htl_booking_detail.id_status) flips right + // away either way — that's a factual room-state decision. Only the + // money side (processRefundInBookingTables()) waits for approval + // on a paid booking, same as before + $statusChanged = $objHotelBookingDetail->changeStatus($newStatus, $changeParams); - // if every room in the order is now No-show (or fully - // cancelled/refunded), bump the order's own status — - // same pattern already used by the initiateRefund handler - $order = new Order($order->id); - if ($idOrderState = $order->getOrderCompleteRefundStatus()) { - $objOrderHistory = new OrderHistory(); - $objOrderHistory->id_order = (int) $order->id; - $useExistingPayment = !$order->hasInvoice(); - $objOrderHistory->changeIdOrderState($idOrderState, $order, $useExistingPayment); - $objOrderHistory->addWithemail(); - } - } - $success = $statusChanged; - } else { - // paid: request is Pending, room status doesn't change yet — - // nothing to announce via the room-status-update hook below - $success = true; + if ($statusChanged && !$hasOrderDiscountOrPayment) { + $objHotelBookingDetail->processRefundInBookingTables(); + $objOrderReturn->changeIdOrderReturnState(Configuration::get('PS_ORS_REFUNDED')); } + + 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); + if ($idOrderState = $order->getOrderCompleteRefundStatus()) { + $objOrderHistory = new OrderHistory(); + $objOrderHistory->id_order = (int) $order->id; + $useExistingPayment = !$order->hasInvoice(); + $objOrderHistory->changeIdOrderState($idOrderState, $order, $useExistingPayment); + $objOrderHistory->addWithemail(); + } + } + $success = $statusChanged; } else { $statusChanged = $objHotelBookingDetail->changeStatus($newStatus, $changeParams); $success = $statusChanged; diff --git a/controllers/admin/AdminStatsController.php b/controllers/admin/AdminStatsController.php index 87947d0b4..d18aa5286 100644 --- a/controllers/admin/AdminStatsController.php +++ b/controllers/admin/AdminStatsController.php @@ -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') ); @@ -1426,7 +1426,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"), @@ -1475,7 +1475,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"), @@ -1539,7 +1539,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).'" @@ -1636,7 +1636,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().') AND hbd.`date_add` BETWEEN "'.pSQL($dateFrom).' 00:00:00" AND "'.pSQL($dateTo).' 23:59:59"'. HotelBranchInformation::addHotelRestriction($idHotel, 'hbd') ); @@ -1675,7 +1675,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).'\') @@ -1708,7 +1708,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') : ''); @@ -1725,7 +1725,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); @@ -1741,7 +1741,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"'. @@ -1772,7 +1772,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`, @@ -1785,6 +1785,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'; @@ -1802,8 +1803,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') : ''); @@ -1817,7 +1818,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') : ''); @@ -1854,7 +1855,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') : ''); @@ -1895,7 +1896,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') : ''); @@ -1938,7 +1939,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') : ''); @@ -1955,7 +1956,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') : ''); @@ -2024,7 +2025,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, @@ -2104,7 +2105,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, @@ -2408,7 +2409,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') : ''); @@ -2434,7 +2435,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') : ''); @@ -2564,7 +2565,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 @@ -2643,7 +2644,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') : ''); @@ -2656,7 +2657,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 @@ -2756,7 +2757,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'); @@ -2774,7 +2775,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 596d54185..6f7f28f73 100644 --- a/controllers/front/GuestTrackingController.php +++ b/controllers/front/GuestTrackingController.php @@ -324,8 +324,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->hasCompletedRefund($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; @@ -353,8 +353,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->hasCompletedRefund($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; @@ -362,7 +362,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->hasCompletedRefund($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 3ce20f47e..b95ef6c02 100644 --- a/controllers/front/OrderDetailController.php +++ b/controllers/front/OrderDetailController.php @@ -170,8 +170,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->hasCompletedRefund($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; @@ -199,8 +199,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->hasCompletedRefund($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; @@ -213,8 +213,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->hasCompletedRefund($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; @@ -222,7 +222,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->hasCompletedRefund($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']; @@ -598,6 +598,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 { @@ -617,7 +618,7 @@ class OrderDetailControllerCore extends FrontController // multiple refund requests are now allowed per booking — only still // block a booking that's already fully refunded, not a re-request - if ($objHotelBookingDetail->is_refunded) { + if ($objOrderReturn->hasCompletedRefund($idHtlBooking)) { $this->errors[] = Tools::displayError('Some selected rooms have already been requested for cancellation.'); break; } @@ -635,7 +636,6 @@ 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; @@ -662,6 +662,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) { 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/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/js/admin/orders.js b/js/admin/orders.js index ac97af925..165112a9a 100644 --- a/js/admin/orders.js +++ b/js/admin/orders.js @@ -1590,8 +1590,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'); @@ -1605,10 +1607,6 @@ $(document).ready(function() { } else { $form.find('.room_status_date').closest('.form-group').hide(); } - - if (status == ROOM_STATUS_NO_SHOW || status == ROOM_STATUS_CANCELLED) { - showErrorMessage(room_status_sealed_warning_txt); - } }); // open date picker for the date input of check-in checkout dates @@ -1640,6 +1638,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/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 58933d4c5..6b34b1390 100644 --- a/modules/hotelreservationsystem/classes/HotelBookingDetail.php +++ b/modules/hotelreservationsystem/classes/HotelBookingDetail.php @@ -46,8 +46,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 @@ -113,8 +111,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'), @@ -175,23 +171,6 @@ class HotelBookingDetail extends ObjectModel parent::__construct($id); } - public function update($null_values = false) - { - $result = parent::update($null_values); - - // if automatic overbooking resolution is enabled - if (Configuration::get('PS_OVERBOOKING_AUTO_RESOLVE')) { - // if room is getting free and this room is not already in back order then resolve the overbookings for this free room - // $this->is_cancelled == 1 is not checked because currently we always set is_refunded to 1 when room is free - // $this->is_back_order == 0 is checked because $this->is_back_order == 1 is used as room is free - if ($this->is_refunded == 1 && $this->is_back_order == 0) { - $this->resolveOverBookings(); - } - } - - return $result; - } - public function getBookingDataParams(&$params) { if (!isset($params['id_room_type'])) { @@ -693,7 +672,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 @@ -1023,7 +1002,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).'\') @@ -1356,7 +1335,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 @@ -1429,7 +1408,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). @@ -1902,7 +1881,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); } @@ -2462,7 +2441,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. @@ -2470,7 +2449,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. @@ -2559,43 +2538,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); - } - - // 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]. * @@ -2661,7 +2603,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); } @@ -2755,7 +2697,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; @@ -3652,17 +3594,22 @@ 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; $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; } @@ -3699,7 +3646,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; @@ -3757,7 +3704,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 index ffaa49b2e..79e93038f 100644 --- a/modules/hotelreservationsystem/classes/HotelBookingStatus.php +++ b/modules/hotelreservationsystem/classes/HotelBookingStatus.php @@ -72,29 +72,17 @@ class HotelBookingStatus extends ObjectModel /** * @param int $idLang - * @param int|null $allowedFromStatus when given, only returns statuses reachable from this - * one (per getAllowedTransitions()) instead of the full catalog — e.g. to build the - * room-status dropdown for a booking currently at this status. * @return array catalog rows (id_status = id_booking_status, color, is_terminal, name), ordered by id */ - public function getAllStatuses($idLang = 0, $allowedFromStatus = null) + 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; - - if ($allowedFromStatus !== null) { - $allowed = self::getAllowedTransitions((int) $allowedFromStatus); - if (!$allowed) { - return array(); - } - $sql .= ' WHERE hbs.`id_booking_status` IN ('.implode(',', array_map('intval', $allowed)).')'; - } - - $sql .= ' ORDER BY hbs.`id_booking_status` ASC'; + 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/HotelReservationSystemDb.php b/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php index b39b54b76..b0e2689d8 100644 --- a/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php +++ b/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php @@ -178,8 +178,6 @@ 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, diff --git a/modules/hotelreservationsystem/classes/HotelRoomInformation.php b/modules/hotelreservationsystem/classes/HotelRoomInformation.php index a3ff65ac3..bad79a3b7 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/controllers/admin/AdminOrderRefundRequestsController.php b/modules/hotelreservationsystem/controllers/admin/AdminOrderRefundRequestsController.php index 295338ce6..13a8712a2 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminOrderRefundRequestsController.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminOrderRefundRequestsController.php @@ -347,6 +347,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'), @@ -506,22 +507,31 @@ class AdminOrderRefundRequestsController extends ModuleAdminController $objHtlBooking = new HotelBookingDetail($idHtlBooking); $idOrderDetail = $objHtlBooking->id_order_detail; + // refund_amounts entered by the admin is a single tax-incl figure; + // derive the tax-excl portion using the booking's own tax ratio + $refundedAmountTaxExcl = $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); + + $refundedAmountTaxExcl = $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, ); } } @@ -550,8 +560,12 @@ class AdminOrderRefundRequestsController extends ModuleAdminController if ($objRefundState->refunded) { $idOrderState = $objOrder->getOrderCompleteRefundStatus(); - // If order is completely refunded or cancelled then change the order state - if ($idOrderState) { + // If order is completely refunded or cancelled then change the order + // state — but only if it isn't already there (a No-show/Cancelled + // order may have already been bumped to this same state earlier, + // right when the room status itself changed, before this request + // was ever approved — don't log a duplicate history row/email for that) + if ($idOrderState && $idOrderState != $objOrder->current_state) { // check if order is paid the set status of the order to refunded $objOrderHistory = new OrderHistory(); $objOrderHistory->id_order = (int)$objOrder->id; diff --git a/modules/hotelreservationsystem/controllers/admin/AdminBookingStatusesController.php b/modules/hotelreservationsystem/controllers/admin/AdminRoomStatusesController.php similarity index 69% rename from modules/hotelreservationsystem/controllers/admin/AdminBookingStatusesController.php rename to modules/hotelreservationsystem/controllers/admin/AdminRoomStatusesController.php index 0546234bd..41a0dde89 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminBookingStatusesController.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminRoomStatusesController.php @@ -21,7 +21,7 @@ * @license https://opensource.org/license/osl-3-0-php Open Software License version 3.0 */ -class AdminBookingStatusesController extends ModuleAdminController +class AdminRoomStatusesController extends ModuleAdminController { public function __construct() { @@ -53,13 +53,18 @@ class AdminBookingStatusesController extends ModuleAdminController 'title' => $this->l('Terminal (final) status'), 'align' => 'text-center', 'type' => 'bool', + 'callback' => 'printYesNo', 'orderby' => false, - 'search' => false, 'class' => 'fixed-width-sm', ), ); } + public function printYesNo($value) + { + return $value ? $this->l('Yes') : $this->l('No'); + } + public function initToolbar() { // no "Add new" toolbar button — statuses are fixed @@ -73,7 +78,7 @@ class AdminBookingStatusesController extends ModuleAdminController || Tools::isSubmit('delete'.$this->table) || Tools::isSubmit('submitBulkdelete'.$this->table) ) { - $this->errors[] = $this->l('Booking statuses cannot be added or deleted.'); + $this->errors[] = $this->l('Room statuses cannot be added or deleted.'); return; } @@ -86,9 +91,16 @@ class AdminBookingStatusesController extends ModuleAdminController 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('Booking Status'), + 'title' => $this->l('Room Status'), 'icon' => 'icon-bookmark', ), 'input' => array( @@ -106,6 +118,25 @@ class AdminBookingStatusesController extends ModuleAdminController 'name' => 'color', 'required' => true, ), + array( + 'type' => 'switch', + 'label' => $this->l('Terminal (final) status'), + 'name' => 'is_terminal_display', + 'hint' => $this->l('A terminal status is final — once a room reaches it, it can\'t move to any other status. Fixed per status, cannot be changed 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'), diff --git a/modules/hotelreservationsystem/hotelreservationsystem.php b/modules/hotelreservationsystem/hotelreservationsystem.php index 3d16900d7..63f8bb1ab 100644 --- a/modules/hotelreservationsystem/hotelreservationsystem.php +++ b/modules/hotelreservationsystem/hotelreservationsystem.php @@ -445,16 +445,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(); } } @@ -526,8 +522,8 @@ class HotelReservationSystem extends Module $this->installTab('AdminHotelConfigurationSetting', 'General Settings', 'AdminHotelReservationSystemManagement'); $this->installTab('AdminHotelBedTypes', 'Bed Types', 'AdminCatalog'); - // parented under core Orders, next to the existing "Statuses" tab — same idea, for booking statuses - $this->installTab('AdminBookingStatuses', 'Booking Statuses', 'AdminParentOrders'); + // 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); 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 7ce642490..2ec15a329 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 @@ -234,7 +234,7 @@ {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']} 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-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']}