Fixed: KPI access is now under employee permission in back-office

Co-authored-by: Name <sumit201@webkul.in>
This commit is contained in:
shazar rahman
2026-06-12 17:50:59 +05:30
parent a27e55c049
commit 653fdf3f7f
203 changed files with 9719 additions and 1593 deletions

View File

@@ -368,6 +368,54 @@ class AdminOrdersControllerCore extends AdminController
'icon' => 'process-icon-new'
);
}
if ($this->display == 'view') {
/** @var Order $order */
if (Validate::isLoadedObject($order = $this->loadObject())) {
// hotel link in header
if ($idHotel = HotelBookingDetail::getIdHotelByIdOrder($order->id)) {
$this->page_header_toolbar_btn['hotel'] = array(
'href' => $this->context->link->getAdminLink('AdminAddHotel').'&id='.$idHotel.'&updatehtl_branch_info',
'desc' => $this->l('View Hotel'),
'class' => 'icon-building',
'target' => true,
);
}
if (Configuration::get('PS_INVOICE') && $order->hasInvoice() && !$this->lite_display) {
$this->page_header_toolbar_btn['file'] = array(
'short' => $this->l('Invoice'),
'href' => $this->context->link->getAdminLink('AdminPdf').'&submitAction=generateInvoicePDF&id_order='.$order->id,
'desc' => $this->l('View invoice'),
'class' => 'icon-file-text',
'target' => true,
);
}
$this->page_header_toolbar_btn['print'] = array(
'short' => $this->l('Print'),
'href' => 'javascript:window.print()',
'desc' => $this->l('Print order'),
'class' => 'icon-print',
);
if ($this->tabAccess['edit'] === 1) {
if (((int) $order->isReturnable())
&& !$order->hasCompletelyRefunded(Order::ORDER_COMPLETE_CANCELLATION_OR_REFUND_REQUEST_FLAG, 0, 0)
) {
$orderTotalPaid = $order->getTotalPaid();
$orderDiscounts = $order->getCartRules();
$hasOrderDiscountOrPayment = ((float)$orderTotalPaid > 0 || $orderDiscounts) ? true : false;
$this->page_header_toolbar_btn['cancel'] = array(
'short' => ($hasOrderDiscountOrPayment) ? $this->l('Refund') : $this->l('Cancel'),
'id' => 'desc-order-standard_refund',
'desc' => ($hasOrderDiscountOrPayment) ? $this->l('Initiate refund') : $this->l('Cancel bookings'),
'class' => 'icon-exchange',
'target' => true,
);
}
}
}
}
parent::initPageHeaderToolbar();
}
@@ -419,7 +467,9 @@ class AdminOrdersControllerCore extends AdminController
}
$paymentTypes = array();
foreach ($this->getPaymentsTypes() as $paymentType) {
$objOrder = new Order();
foreach ($objOrder->getPaymentsTypes() as $paymentType) {
if ($paymentType['value'] != OrderPayment::PAYMENT_TYPE_REMOTE_PAYMENT) {
$paymentTypes[] = $paymentType;
}
@@ -437,13 +487,13 @@ class AdminOrdersControllerCore extends AdminController
'advance_payment_amount_without_tax' => $cart->getOrderTotal(false, Cart::ADVANCE_PAYMENT),
'advance_payment_amount_with_tax' => $cart->getOrderTotal(true, Cart::ADVANCE_PAYMENT),
'cart' => $cart,
'customer' => $cart->id_customer ? new Customer($cart->id_customer): null ,
'currencies' => Currency::getCurrenciesByIdShop(Context::getContext()->shop->id),
'langs' => Language::getLanguages(true, Context::getContext()->shop->id),
'payment_modules' => $payment_modules,
'payment_types' => $paymentTypes,
'PAYMENT_TYPE_PAY_AT_HOTEL' => OrderPayment::PAYMENT_TYPE_PAY_AT_HOTEL,
'currency' => new Currency((int)$cart->id_currency),
'max_child_in_room' => Configuration::get('WK_GLOBAL_MAX_CHILD_IN_ROOM'),
'max_child_age' => Configuration::get('WK_GLOBAL_CHILD_MAX_AGE'),
'occupancy_required_for_booking' => $occupancyRequiredForBooking,
));
@@ -476,55 +526,6 @@ class AdminOrdersControllerCore extends AdminController
public function initToolbar()
{
if ($this->display == 'view') {
/** @var Order $order */
if (Validate::isLoadedObject($order = $this->loadObject())) {
// hotel link in header
if ($idHotel = HotelBookingDetail::getIdHotelByIdOrder($order->id)) {
$this->toolbar_btn['hotel'] = array(
'href' => $this->context->link->getAdminLink('AdminAddHotel').'&id='.$idHotel.'&updatehtl_branch_info',
'desc' => $this->l('View Hotel'),
'class' => 'icon-building',
'target' => true,
);
}
if (Configuration::get('PS_INVOICE') && $order->hasInvoice() && !$this->lite_display) {
$this->toolbar_btn['file'] = array(
'short' => $this->l('Invoice'),
'href' => $this->context->link->getAdminLink('AdminPdf').'&submitAction=generateInvoicePDF&id_order='.$order->id,
'desc' => $this->l('View invoice'),
'class' => 'icon-file-text',
'target' => true,
);
}
$this->toolbar_btn['print'] = array(
'short' => $this->l('Print'),
'href' => 'javascript:window.print()',
'desc' => $this->l('Print order'),
'class' => 'icon-print',
);
if ($this->tabAccess['edit'] === 1) {
if (((int) $order->isReturnable())
&& !$order->hasCompletelyRefunded(Order::ORDER_COMPLETE_CANCELLATION_OR_REFUND_REQUEST_FLAG, 0, 0)
) {
$orderTotalPaid = $order->getTotalPaid();
$orderDiscounts = $order->getCartRules();
$hasOrderDiscountOrPayment = ((float)$orderTotalPaid > 0 || $orderDiscounts) ? true : false;
$this->toolbar_btn['cancel'] = array(
'short' => ($hasOrderDiscountOrPayment) ? $this->l('Refund') : $this->l('Cancel'),
'id' => 'desc-order-standard_refund',
'desc' => ($hasOrderDiscountOrPayment) ? $this->l('Initiate refund') : $this->l('Cancel bookings'),
'class' => 'icon-exchange',
'target' => true,
);
}
}
}
}
$res = parent::initToolbar();
if (Context::getContext()->shop->getContext() != Shop::CONTEXT_SHOP && isset($this->toolbar_btn['new']) && Shop::isFeatureActive()) {
unset($this->toolbar_btn['new']);
@@ -683,7 +684,7 @@ class AdminOrdersControllerCore extends AdminController
'order' => $objOrder,
'currencies' => $currencies,
'payment_methods' => $payment_methods,
'payment_types' => $this->getPaymentsTypes(),
'payment_types' => $objOrder->getPaymentsTypes(),
'invoices_collection' => $objOrder->getInvoicesCollection(),
'current_id_lang' => $this->context->language->id,
)
@@ -786,6 +787,8 @@ class AdminOrdersControllerCore extends AdminController
'order' => $objOrder,
'current_index' => self::$currentIndex,
'hotel_order_status' => $htlOrderStatus,
'ROOM_STATUS_ALLOTED' => HotelBookingDetail::STATUS_ALLOTED,
'current_room_status' => Tools::getValue('current_room_status')
)
);
$modal = array(
@@ -1275,6 +1278,68 @@ class AdminOrdersControllerCore extends AdminController
die(Tools::jsonEncode($response));
}
public function ajaxProcessInitDeleteRoomBookingModal()
{
if ($this->tabAccess['edit'] !== 1) {
die(Tools::jsonEncode(array(
'hasError' => 1,
'error' => Tools::displayError('You do not have permission to edit this order.')
)));
}
// set modal details
$response['hasError'] = 1;
$id_order = (int) Tools::getValue('id_order');
$idProduct = (int) Tools::getValue('id_product');
$idOrderDetail = (int) Tools::getValue('id_order_detail');
$idRoom = (int) Tools::getValue('id_room');
$idHtlBooking = (int) Tools::getValue('id_htl_booking');
$idHotel = (int) Tools::getValue('id_hotel');
$dateFrom = (string) Tools::getValue('date_from');
$dateTo = (string) Tools::getValue('date_to');
if ($id_order
&& $idProduct
&& $idOrderDetail
&& $idRoom
&& $idHtlBooking
&& $idHotel
&& $dateFrom
&& $dateTo
) {
if (!Validate::isDate($dateFrom) || !Validate::isDate($dateTo)) {
die(Tools::jsonEncode(array(
'hasError' => 1,
'error' => Tools::displayError('Invalid date range.')
)));
}
$smartyVars = array(
'id_product' => $idProduct,
'id_order_detail' => $idOrderDetail,
'id_room' => $idRoom,
'date_from' => $dateFrom,
'date_to' => $dateTo,
'id_htl_booking' => $idHtlBooking,
'id_hotel' => $idHotel,
'id_order' => $id_order,
);
$this->context->smarty->assign($smartyVars);
$modal = array(
'modal_id' => 'delete-room-booking-modal',
'modal_class' => 'modal-md order_detail_modal',
'modal_title' => '<i class="icon icon-bed"></i> &nbsp'.$this->l('Delete Room'),
'modal_content' => $this->context->smarty->fetch('controllers/orders/modals/_delete_room_booking.tpl'),
);
$this->context->smarty->assign($modal);
$response['hasError'] = 0;
$response['modalHtml'] = $this->context->smarty->fetch('modal.tpl');
} else {
$response['error'] = Tools::displayError('Invalid data.');
}
die(Tools::jsonEncode($response));
}
public function setMedia()
{
@@ -1557,7 +1622,23 @@ class AdminOrdersControllerCore extends AdminController
if (!count($this->errors)) {
// Finally, reallocate the room
if ($objBookingDetail->reallocateBooking($idHtlBookingFrom, $idRoomToReallocate, $priceDiff)) {
if ($objBookingDetail->reallocateBooking($idHtlBookingFrom, $idRoomToReallocate, $priceDiff)) {
$order = new Order((int) $idOrder);
$fromRoomType = Product::getProductName($objHotelBooking->id_product, null, $this->context->language->id);
$toRoomType = Product::getProductName($objRoomInfo->id_product, null, $this->context->language->id);
$dateFrom = date('d/m/Y', strtotime($objHotelBooking->date_from));
$dateTo = date('d/m/Y', strtotime($objHotelBooking->date_to));
$autoMsg = $this->l('Room Reallocate').': '.$objHotelBooking->room_num.' - '.$fromRoomType.' '.$this->l('to').' '.$objRoomInfo->room_num.' - '.$toRoomType.': ('.$dateFrom.' - '.$dateTo.')';
$userRemark = Tools::getValue('message');
$noteMessage = $autoMsg.($userRemark && Validate::isMessage($userRemark) ? ' | '.$this->l('Remark').': '.$userRemark : '');
$message = new Message();
$message->message = $noteMessage;
$message->id_cart = (int)$order->id_cart;
$message->id_customer = (int)$order->id_customer;
$message->id_order = (int)$idOrder;
$message->id_employee = (int)$this->context->employee->id;
$message->private = 1;
$message->save();
Tools::redirectAdmin(self::$currentIndex.'&id_order='.(int) $idOrder.'&vieworder&conf=52&token='.$this->token);
} else {
$this->errors[] = $this->l('Some error occured. Please try again.');
@@ -1599,7 +1680,22 @@ class AdminOrdersControllerCore extends AdminController
if (!count($this->errors)) {
$objBookingDetail = new HotelBookingDetail();
if ($objBookingDetail->swapBooking($idHtlBookingFrom, $idHtlBookingToSwap)) {
if ($objBookingDetail->swapBooking($idHtlBookingFrom, $idHtlBookingToSwap)) {
$order = new Order((int) $idOrder);
$room1Type = Product::getProductName($objHotelBooking->id_product, null, $this->context->language->id);
$dateFrom = date('d/m/Y', strtotime($objHotelBooking->date_from));
$dateTo = date('d/m/Y', strtotime($objHotelBooking->date_to));
$autoMsg = $this->l('Room Swap').': ('.$room1Type.') '.$objHotelBooking->room_num.' '.$this->l('with').' '.$objHotelBookingTo->room_num.': ('.$dateFrom.' - '.$dateTo.')';
$userRemark = Tools::getValue('message');
$noteMessage = $autoMsg.($userRemark && Validate::isMessage($userRemark) ? ' | '.$this->l('Remark').': '.$userRemark : '');
$message = new Message();
$message->message = $noteMessage;
$message->id_cart = (int)$order->id_cart;
$message->id_customer = (int)$order->id_customer;
$message->id_order = (int)$idOrder;
$message->id_employee = (int)$this->context->employee->id;
$message->private = 1;
$message->save();
Tools::redirectAdmin(self::$currentIndex.'&id_order='.(int)$idOrder.'&vieworder&conf=53&token='.$this->token);
} else {
$this->errors[] = $this->l('Some error occured. Please try again.');
@@ -1745,7 +1841,7 @@ class AdminOrdersControllerCore extends AdminController
$id_customer_thread = CustomerThread::getIdCustomerThreadByEmailAndIdOrder($customer->email, $order->id);
if (!$id_customer_thread) {
$customer_thread = new CustomerThread();
$customer_thread->id_contact = (int)Configuration::get('PS_MAIL_EMAIL_MESSAGE');
$customer_thread->id_contact = (int)Configuration::get('PS_CUSTOMER_SERVICE_CONTACT');
$customer_thread->id_customer = (int)$order->id_customer;
$customer_thread->user_name = $customer->firstname.' '.$customer->lastname;
$customer_thread->phone = $customer->phone;
@@ -1761,7 +1857,6 @@ class AdminOrdersControllerCore extends AdminController
} else {
$customer_thread = new CustomerThread((int)$id_customer_thread);
}
$customer_message = new CustomerMessage();
$customer_message->id_customer_thread = $customer_thread->id;
$customer_message->id_employee = (int)$this->context->employee->id;
@@ -1785,7 +1880,7 @@ class AdminOrdersControllerCore extends AdminController
'{order_name}' => $order->getUniqReference(),
'{message}' => $message
);
if (@Mail::Send(
Mail::Send(
(int)$order->id_lang,
'order_merchant_comment',
Mail::l('New message regarding your booking', (int)$order->id_lang),
@@ -1799,11 +1894,10 @@ class AdminOrdersControllerCore extends AdminController
_PS_MAIL_DIR_,
true,
(int)$order->id_shop
)) {
Tools::redirectAdmin(self::$currentIndex.'&id_order='.$order->id.'&vieworder&conf=11'.'&token='.$this->token);
}
);
Tools::redirectAdmin(self::$currentIndex.'&id_order='.(int)$order->id.'&vieworder&conf=11&token='.$this->token);
}
$this->errors[] = Tools::displayError('An error occurred while sending an email to the customer.');
Tools::dieOrLog(Tools::displayError('An error occurred while sending an email to the customer.'),false);
}
}
} else {
@@ -3112,9 +3206,6 @@ class AdminOrdersControllerCore extends AdminController
$this->kpis[] = $helper;
}
Hook::exec('action'.$this->controller_name.'KPIListingModifier', array(
'kpis' => &$kpis,
));
return parent::renderKpis();
}
@@ -3124,8 +3215,9 @@ class AdminOrdersControllerCore extends AdminController
if (!Validate::isLoadedObject($order = new Order(Tools::getValue('id_order')))) {
return;
}
$this->content .= $this->renderKpis();
if ($this->tabAccess['kpi'] === 1) {
$this->content .= $this->renderKpis();
}
$customer = new Customer($order->id_customer);
$carrier = new Carrier($order->id_carrier);
@@ -3582,7 +3674,7 @@ class AdminOrdersControllerCore extends AdminController
}
$objCustomerThread = new CustomerThread();
$messages = Message::getMessagesByOrderId($order->id, true);
$messages = Message::getMessagesByOrderId($order->id, null);
if ($customerMessages = CustomerMessage::getMessagesByOrderId($order->id, true)) {
foreach ($messages as $messageKey => $message) {
foreach ($customerMessages as $customerMessageKey => $customerMessage) {
@@ -3592,10 +3684,11 @@ class AdminOrdersControllerCore extends AdminController
}
}
$messages = array_merge($customerMessages, $messages);
usort($messages, function ($a, $b) {
return strtotime($a['date_add']) < strtotime($b['date_add']);
});
if($messages = array_merge($customerMessages, $messages)){
usort($messages, function ($a, $b) {
return (strtotime($a['date_add']) < strtotime($b['date_add'])) ? 1 : -1;
});
}
}
// send hotel standalone and standalone products
@@ -3626,7 +3719,6 @@ class AdminOrdersControllerCore extends AdminController
'htl_booking_order_data' => $bookingOrderInfo,
'hotel_order_status' => $htlOrderStatus,
'order_detail_data' => $order_detail_data,
'max_child_in_room' => Configuration::get('WK_GLOBAL_MAX_CHILD_IN_ROOM'),
'max_child_age' => Configuration::get('WK_GLOBAL_CHILD_MAX_AGE'),
'hotel_service_products' => $orderHotelServiceProducts,
'standalone_service_products' => $orderStandaloneServiceProducts,
@@ -3674,8 +3766,9 @@ class AdminOrdersControllerCore extends AdminController
'invoices_collection' => $order->getInvoicesCollection(),
'not_paid_invoices_collection' => $order->getNotPaidInvoicesCollection(),
'payment_methods' => $payment_methods,
'payment_types' => $this->getPaymentsTypes(),
'payment_types' => $order->getPaymentsTypes(),
'invoice_management_active' => Configuration::get('PS_INVOICE', null, null, $order->id_shop),
'receipt_management_active' => Configuration::get('PS_PAYMENT_RECEIPTS', null, null, $order->id_shop),
'display_warehouse' => (int)Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT'),
'HOOK_CONTENT_ORDER' => Hook::exec(
'displayAdminOrderContentOrder',
@@ -3710,6 +3803,7 @@ class AdminOrdersControllerCore extends AdminController
'ROOM_STATUS_CHECKED_OUT' => HotelBookingDetail::STATUS_CHECKED_OUT,
'ALLOTMENT_MANUAL' => HotelBookingDetail::ALLOTMENT_MANUAL,
'order_convenience_fee_services' => $orderConvenienceFeeServices,
'page_header_toolbar_btn' => $this->page_header_toolbar_btn,
);
return parent::renderView();
@@ -5137,7 +5231,22 @@ class AdminOrdersControllerCore extends AdminController
$order->total_discounts_tax_incl += (float)abs($cart->getOrderTotal(true, Cart::ONLY_DISCOUNTS));
// Save changes of order
$order->update();
if($order->update()){
$roomType = Product::getProductName($product->id, null, $this->context->language->id);
$dateFromFormatted = date('d/m/Y', strtotime($date_from));
$dateToFormatted = date('d/m/Y', strtotime($date_to));
$autoMsg = $this->l('Room Add').': '.$roomType.': ('.$dateFromFormatted.' - '.$dateToFormatted.')';
$userRemark = Tools::getValue('message');
$noteMessage = $autoMsg.($userRemark && Validate::isMessage($userRemark) ? ' | '.$this->l('Remark').': '.$userRemark : '');
$message = new Message();
$message->message = $noteMessage;
$message->id_cart = (int)$this->context->cart->id;
$message->id_customer = (int)$this->context->cart->id_customer;
$message->id_order = (int)$order->id;
$message->id_employee = (int)$this->context->employee->id;
$message->private = 1;
$message->save();
}
// Update weight SUM
$order_carrier = new OrderCarrier((int)$order->getIdOrderCarrier());
@@ -6197,7 +6306,24 @@ class AdminOrdersControllerCore extends AdminController
$order->total_paid = Tools::ps_round($order->getOrderTotal(), _PS_PRICE_COMPUTE_PRECISION_);
$order->total_paid_tax_incl = Tools::ps_round($order->getOrderTotal(), _PS_PRICE_COMPUTE_PRECISION_);
$order->total_paid_tax_excl = Tools::ps_round($order->getOrderTotal(false), _PS_PRICE_COMPUTE_PRECISION_);
$order->save();
if($order->save()){
$roomType = Product::getProductName($id_product, null, $this->context->language->id);
$oldDateFromFormatted = date('d/m/Y', strtotime($old_date_from));
$oldDateToFormatted = date('d/m/Y', strtotime($old_date_to));
$newDateFromFormatted = date('d/m/Y', strtotime($new_date_from));
$newDateToFormatted = date('d/m/Y', strtotime($new_date_to));
$autoMsg = $this->l('Room Edit').': '.$obj_booking_detail->room_num.' - '.$roomType.': ('.$oldDateFromFormatted.' - '.$oldDateToFormatted.')';
$userRemark = Tools::getValue('message');
$noteMessage = $autoMsg.($userRemark && Validate::isMessage($userRemark) ? ' | '.$this->l('Remark').': '.$userRemark : '');
$message = new Message();
$message->message = $noteMessage;
$message->id_cart = (int)$this->context->cart->id;
$message->id_customer = (int)$this->context->cart->id_customer;
$message->id_order = (int)$order->id;
$message->id_employee = (int)$this->context->employee->id;
$message->private = 1;
$message->save();
}
// Save order invoice
if (isset($order_invoice) && $order_invoice instanceof OrderInvoice) {
@@ -6357,7 +6483,7 @@ class AdminOrdersControllerCore extends AdminController
public function ajaxProcessDeleteRoomLine()
{
// Check tab access is allowed to edit
if (!$this->tabAccess['edit'] === 1) {
if ($this->tabAccess['edit'] !== 1) {
die(json_encode(array(
'result' => false,
'error' => Tools::displayError('You do not have permission to edit this order.')
@@ -6636,7 +6762,22 @@ class AdminOrdersControllerCore extends AdminController
$objBookingDetail->id_order
);
$objBookingDetail->delete();
if($objBookingDetail->delete()){
$roomType = Product::getProductName($objBookingDetail->id_product, null, $this->context->language->id);
$dateFrom = date('d/m/Y', strtotime($objBookingDetail->date_from));
$dateTo = date('d/m/Y', strtotime($objBookingDetail->date_to));
$autoMsg = $this->l('Room Delete').': '.$objBookingDetail->room_num.' - '.$roomType.': ('.$dateFrom.' - '.$dateTo.')';
$userRemark = Tools::getValue('message');
$noteMessage = $autoMsg.($userRemark && Validate::isMessage($userRemark) ? ' | '.$this->l('Remark').': '.$userRemark : '');
$message = new Message();
$message->message = $noteMessage;
$message->id_cart = (int)$objBookingDetail->id_cart;
$message->id_customer = (int)$order->id_customer;
$message->id_order = (int)$order->id;
$message->id_employee = (int)$this->context->employee->id;
$message->private = 1;
$message->save();
}
// delete refund request of the room if exists.
OrderReturnDetail::deleteReturnDetailByIdBookingDetail($id_order, $idHotelBooking);
@@ -7136,26 +7277,6 @@ class AdminOrdersControllerCore extends AdminController
return $products;
}
protected function getPaymentsTypes()
{
return array(
OrderPayment::PAYMENT_TYPE_PAY_AT_HOTEL => array(
'key' => 'PAYMENT_TYPE_PAY_AT_HOTEL',
'value' => OrderPayment::PAYMENT_TYPE_PAY_AT_HOTEL,
'name' => $this->l('Pay at hotel')
),
OrderPayment::PAYMENT_TYPE_ONLINE => array(
'key' => 'PAYMENT_TYPE_ONLINE',
'value' => OrderPayment::PAYMENT_TYPE_ONLINE,
'name' => $this->l('Online')
),
OrderPayment::PAYMENT_TYPE_REMOTE_PAYMENT => array(
'key' => 'PAYMENT_TYPE_REMOTE_PAYMENT',
'value' => OrderPayment::PAYMENT_TYPE_REMOTE_PAYMENT,
'name' => $this->l('Remote payment')
),
);
}
/**
* @param OrderInvoice $order_invoice
@@ -7487,7 +7608,7 @@ class AdminOrdersControllerCore extends AdminController
$response['hasError'] = true;
$response['errors'][] = Tools::displayError('Invalid quantity provided for service').': '.$objServiceProductOrderDetail->name;
}
} elseif ($serviceQuantities[$idRoomTypeServiceProductOrderDetail] > 1) {
} elseif (is_array($serviceQuantities) && isset($serviceQuantities[$idRoomTypeServiceProductOrderDetail]) && $serviceQuantities[$idRoomTypeServiceProductOrderDetail] > 1) {
$response['hasError'] = true;
$response['errors'][] = Tools::displayError('Can not order multiple quanitity for service').': '.$objServiceProductOrderDetail->name;
}
@@ -7508,7 +7629,11 @@ class AdminOrdersControllerCore extends AdminController
$result = true;
foreach ($selectedServicesOrderDetails as $idRoomTypeServiceProductOrderDetail) {
$objServiceProductOrderDetail = new ServiceProductOrderDetail($idRoomTypeServiceProductOrderDetail);
$quantity = $serviceQuantities[$idRoomTypeServiceProductOrderDetail];
if(is_array($serviceQuantities) && isset($serviceQuantities[$idRoomTypeServiceProductOrderDetail])) {
$quantity = (int)$serviceQuantities[$idRoomTypeServiceProductOrderDetail];
} else {
$quantity = 1;
}
$unitPrice = $serviceUnitPrices[$idRoomTypeServiceProductOrderDetail];
$objHotelBookingDetail = new HotelBookingDetail($objServiceProductOrderDetail->id_htl_booking_detail);
@@ -8715,30 +8840,49 @@ class AdminOrdersControllerCore extends AdminController
}
if (empty($this->errors)) {
$objHotelBookingDetail->id_status = $newStatus;
if ($newStatus == HotelBookingDetail::STATUS_CHECKED_IN) {
$objHotelBookingDetail->check_in = $statusDate;
} elseif ($newStatus == HotelBookingDetail::STATUS_CHECKED_OUT) {
$objHotelBookingDetail->check_out = $statusDate;
} else {
$objHotelBookingDetail->check_in = '';
$objHotelBookingDetail->check_out = '';
}
if ($objHotelBookingDetail->save()) {
Hook::exec(
'actionRoomBookingStatusUpdateAfter',
array(
'id_hotel_booking_detail' => $objHotelBookingDetail->id,
'id_order' => $objHotelBookingDetail->id_order,
'id_room' => $objHotelBookingDetail->id_room,
'date_from' => $objHotelBookingDetail->date_from,
'date_to' => $objHotelBookingDetail->date_to
)
);
Tools::redirectAdmin(self::$currentIndex.'&id_order='.(int) $objHotelBookingDetail->id_order.'&vieworder&token='.$this->token.'&conf=4');
$id_order = $objHotelBookingDetail->id_order;
$order = new Order($id_order);
$remainingCheckoutRooms = 0;
if ($newStatus == HotelBookingDetail::STATUS_CHECKED_OUT) {
$orderBookings = $objHotelBookingDetail->getOrderCurrentDataByOrderId(
$id_order,
array(HotelBookingDetail::STATUS_ALLOTED, HotelBookingDetail::STATUS_CHECKED_IN),
0,
0
);
$remainingCheckoutRooms = count($orderBookings);
}
$hasPendingBills = $order->getTotalPaid() < $order->getOrderTotal();
if ($remainingCheckoutRooms == 1 && $newStatus == HotelBookingDetail::STATUS_CHECKED_OUT && $hasPendingBills) {
$this->errors[] = Tools::displayError('You cannot checkout the last room while there are pending bills for this order.');
} else {
$this->errors[] = Tools::displayError('Some error occurred. Please try again.');
$objHotelBookingDetail->id_status = $newStatus;
if ($newStatus == HotelBookingDetail::STATUS_CHECKED_IN) {
$objHotelBookingDetail->check_in = $statusDate;
} elseif ($newStatus == HotelBookingDetail::STATUS_CHECKED_OUT) {
$objHotelBookingDetail->check_out = $statusDate;
} else {
$objHotelBookingDetail->check_in = '';
$objHotelBookingDetail->check_out = '';
}
if ($objHotelBookingDetail->save()) {
Hook::exec(
'actionRoomBookingStatusUpdateAfter',
array(
'id_hotel_booking_detail' => $objHotelBookingDetail->id,
'id_order' => $objHotelBookingDetail->id_order,
'id_room' => $objHotelBookingDetail->id_room,
'date_from' => $objHotelBookingDetail->date_from,
'date_to' => $objHotelBookingDetail->date_to
)
);
Tools::redirectAdmin(self::$currentIndex . '&id_order=' . (int) $objHotelBookingDetail->id_order . '&vieworder&token=' . $this->token . '&conf=4');
} else {
$this->errors[] = Tools::displayError('Some error occurred. Please try again.');
}
}
}
} else {