Merge pull request #895 from sumitwebkul/overbooking_issues

Fixed: Overbooking issues in QloApps and added new configurations for overbooking handling
This commit is contained in:
Rohit Jain
2024-03-17 15:43:49 +05:30
committed by GitHub
58 changed files with 1747 additions and 104 deletions

View File

@@ -58,6 +58,18 @@ class AdminOrderPreferencesControllerCore extends AdminController
)
);
// actions when overbooking will be created
$overbookingAction = array(
array(
'value' => Order::OVERBOOKING_ORDER_CANCEL_ACTION,
'name' => $this->l('Cancel the booking')
),
array(
'value' => Order::OVERBOOKING_ORDER_NO_ACTION,
'name' => $this->l('Take the overbooking')
)
);
// Options to display currency in order list
$displayCurrencyOptions = array(
array(
@@ -195,33 +207,83 @@ class AdminOrderPreferencesControllerCore extends AdminController
'submit' => array('title' => $this->l('Save'))
),
'email' => array(
'title' => $this->l('Email'),
'title' => $this->l('Order Confirmation / Overbooking Email'),
'icon' => 'icon-cogs',
'fields' => array(
'PS_ORDER_CONF_MAIL_TO_CUSTOMER' => array(
'title' => $this->l('Order confirmation mail to customer'),
'hint' => $this->l('Enable, if you want to send order confirmation email to the customer.'),
'title' => $this->l('Send email to customer'),
'hint' => $this->l('Enable, if you want to send order confirmation or overbooking or overbooking email to the customer.'),
'validation' => 'isBool',
'cast' => 'intval',
'type' => 'bool'
),
'PS_ORDER_CONF_MAIL_TO_SUPERADMIN' => array(
'title' => $this->l('Order confirmation mail to super admin'),
'hint' => $this->l('Enable, if you want to send order confirmation email to the super admin.'),
'title' => $this->l('Send email to super admin'),
'hint' => $this->l('Enable, if you want to send order confirmation or overbooking email to the super admin.'),
'validation' => 'isBool',
'cast' => 'intval',
'type' => 'bool'
),
'PS_ORDER_CONF_MAIL_TO_HOTEL_MANAGER' => array(
'title' => $this->l('Order confirmation mail to hotelier'),
'hint' => $this->l('Enable, if you want to send order confirmation email to the hotelier. Mail will be sent to the email saved while creating the hotel.'),
'title' => $this->l('Send email to hotelier'),
'hint' => $this->l('Enable, if you want to send order confirmation or overbooking email to the hotelier. Mail will be sent to the email saved while creating the hotel.'),
'validation' => 'isBool',
'cast' => 'intval',
'type' => 'bool'
),
'PS_ORDER_CONF_MAIL_TO_EMPLOYEE' => array(
'title' => $this->l('Order confirmation mail to employees'),
'hint' => $this->l('Enable, if you want to send order confirmation email to employees having permission to manage the hotel.'),
'title' => $this->l('Send email to employees'),
'hint' => $this->l('Enable, if you want to send order confirmation or overbooking email to employees having permission to manage the hotel.'),
'validation' => 'isBool',
'cast' => 'intval',
'type' => 'bool'
),
),
'submit' => array('title' => $this->l('Save'))
),
'overbooking' => array(
'title' => $this->l('Overbooking'),
'icon' => 'icon-cogs',
'fields' => array(
'PS_OVERBOOKING_ORDER_ACTION' => array(
'title' => $this->l('Overbooking order action'),
'hint' => $this->l('Please choose the action to take when overbooking is created in any order.'),
'validation' => 'isInt',
'type' => 'select',
'cast' => 'intval',
'validation' => 'isInt',
'list' => $overbookingAction,
'identifier' => 'value',
'js' => "changeOverbookingOrderAction()"
),
'PS_MAX_OVERBOOKING_PER_HOTEL_PER_DAY' => array(
'title' => $this->l('Maximun hotel overbookings per date'),
'hint' => $this->l('Enter the maximum number of the overbookings on any date can be created for a hotel.(Set 0 for no limit)'),
'desc' => $this->l('When maximun number of the overbookings on any date in the booking duration is reached, then the new overbooking order will be cancelled.(Set 0 for no limit)'),
'validation' => 'isInt',
'type' => 'text',
'class' => 'fixed-width-xxl',
'validation' => 'isInt',
'id' => 'PS_MAX_OVERBOOKING_PER_HOTEL_PER_DAY',
),
'OVERBOOKING_ORDER_CANCEL_ACTION' => array(
'title' => $this->l('Overbooking order cancel action value'),
'type' => 'hidden',
'value' => Order::OVERBOOKING_ORDER_CANCEL_ACTION,
'auto_value' => false,
),
'OVERBOOKING_ORDER_NO_ACTION' => array(
'title' => $this->l('Overbooking order no action value'),
'validation' => 'isInt',
'cast' => 'intval',
'type' => 'hidden',
'value' => Order::OVERBOOKING_ORDER_NO_ACTION,
'auto_value' => false
),
'PS_OVERBOOKING_AUTO_RESOLVE' => array(
'title' => $this->l('Resolve overbooking automatically'),
'hint' => $this->l('Enable, if you want to resolve overbooking automatically when rooms are available to be replaced with overbooked rooms.'),
'desc' => $this->l('If enabled, the overbookings in the order will be resolved automatically when rooms are available to be replaced with all overbooked rooms in the order.'),
'validation' => 'isBool',
'cast' => 'intval',
'type' => 'bool'

View File

@@ -96,6 +96,22 @@ class AdminOrdersControllerCore extends AdminController
$this->_group = ' GROUP BY hbd.`id_order`';
// if request for resolvable overbooked orders filter comes the set condition for this
if (Tools::getIsset('resolvable_overbooked_orders') && Tools::getValue('resolvable_overbooked_orders')) {
$objHotelBookingDetail = new HotelBookingDetail();
$resolvableOrders = array();
// Overbookings information of the order
if ($orderOverBookings = $objHotelBookingDetail->getOverbookedRooms()) {
foreach ($orderOverBookings as $overBookedRoom) {
if (!in_array($overBookedRoom['id_order'], $resolvableOrders)) {
$resolvableOrders[$overBookedRoom['id_order']] = $overBookedRoom['id_order'];
}
}
}
$this->_where = ' AND a.`id_order` IN ('.implode(',', $resolvableOrders).')';
}
$statuses = OrderState::getOrderStates((int)$this->context->language->id);
foreach ($statuses as $status) {
$this->statuses_array[$status['id_order_state']] = $status['name'];
@@ -326,6 +342,8 @@ class AdminOrdersControllerCore extends AdminController
parent::__construct();
// overbooking success status
$this->_conf[51] = $this->l('Overbooking is successfully resolved');
$this->_conf[52] = $this->l('Room in the booking is successfully reallocated');
$this->_conf[53] = $this->l('Room in the booking is successfully swapped');
}
@@ -610,6 +628,13 @@ class AdminOrdersControllerCore extends AdminController
public function renderList()
{
// Show all resolvable overbookings if available
$objHotelBookingDetail = new HotelBookingDetail();
if ($resolvableOverBookings = $objHotelBookingDetail->getOverbookedRooms(0, 0, '', '', 0, 0, 2)) {
$this->context->smarty->assign('resolvableOverBookings', $resolvableOverBookings);
$this->content .= $this->context->smarty->fetch('controllers/orders/_resolvable_overbookings.tpl');
}
if (Tools::isSubmit('submitBulkupdateOrderStatus'.$this->table)) {
if (Tools::getIsset('cancel')) {
Tools::redirectAdmin(self::$currentIndex.'&token='.$this->token);
@@ -1701,7 +1726,20 @@ class AdminOrdersControllerCore extends AdminController
} else {
$this->errors[] = Tools::displayError('You do not have permission to edit this.');
}
} elseif(Tools::getIsset('resolve_overbooking') && Tools::getValue('resolve_overbooking')) {
$objHotelBookingDetail = new HotelBookingDetail();
// resolve an overbooking manually
if ($objHotelBookingDetail->resolveOverbookings(Tools::getValue('resolve_overbooking'))) {
if (Tools::getValue('id_order')) {
Tools::redirectAdmin(self::$currentIndex.'&id_order='.$order->id.'&vieworder&conf=51&token='.$this->token);
} else {
Tools::redirectAdmin(self::$currentIndex.'&conf=51&token='.$this->token);
}
} else {
$this->errors = Tools::displayError('An error occurred while resolving overbooking.');
}
}
parent::postProcess();
}
@@ -2111,8 +2149,12 @@ class AdminOrdersControllerCore extends AdminController
// applicable refund policies
$applicableRefundPolicies = HotelOrderRefundRules::getApplicableRefundRules($order->id);
// Overbookings information of the order
$orderOverBookings = $objHotelBookingDetail->getOverbookedRooms($order->id, 0, '', '', 0, 0, 1);
$this->tpl_view_vars = array(
// refund info
'orderOverBookings' => $orderOverBookings,
'refund_allowed' => (int) $order->isReturnable(),
'applicable_refund_policies' => $applicableRefundPolicies,
'returns' => OrderReturn::getOrdersReturn($order->id_customer, $order->id),

View File

@@ -66,6 +66,7 @@ class HistoryControllerCore extends FrontController
}
$this->context->smarty->assign(array(
'orders' => $orders,
'overbooking_order_states' => OrderState::getOverBookingStates(),
'invoiceAllowed' => (int)Configuration::get('PS_INVOICE'),
'reorderingAllowed' => !(bool)Configuration::get('PS_DISALLOW_HISTORY_REORDERING'),
'slowValidation' => Tools::isSubmit('slowvalidation')

View File

@@ -679,6 +679,7 @@ class OrderDetailControllerCore extends FrontController
'invoice' => (OrderState::invoiceAvailable($id_order_state) && count($order->getInvoicesCollection())),
'logable' => (bool) $order_status->logable,
'order_history' => $order->getHistory($this->context->language->id, false, true),
'overbooking_order_states' => OrderState::getOverBookingStates(),
'products' => $products,
'discounts' => $order->getCartRules(),
'carrier' => $carrier,