diff --git a/controllers/admin/AdminOrderPreferencesController.php b/controllers/admin/AdminOrderPreferencesController.php
index 21b31f6a7..170fe675a 100644
--- a/controllers/admin/AdminOrderPreferencesController.php
+++ b/controllers/admin/AdminOrderPreferencesController.php
@@ -78,6 +78,11 @@ class AdminOrderPreferencesControllerCore extends AdminController
'class' => 'fixed-width-xl',
'suffix' => $this->l('day(s)'),
),
+ 'BACKDATE_ORDER_EMPLOYEES' => array(
+ 'title' => $this->l('Allow backdate order from Back-office'),
+ 'hint' => $this->l('Allow backoffice employees to create bookings for backdate'),
+ 'type' => 'bool',
+ ),
),
'submit' => array(
'title' => $this->l('Save'),
diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php
index 63a271ecd..dc98bbe1b 100644
--- a/controllers/admin/AdminOrdersController.php
+++ b/controllers/admin/AdminOrdersController.php
@@ -286,6 +286,10 @@ class AdminOrdersControllerCore extends AdminController
$cart_order_exists = $cart->orderExists();
if (!$cart_order_exists) {
$this->context->cart = $cart;
+ if (!Configuration::get('BACKDATE_ORDER_EMPLOYEES')) {
+ $objHotelCartBookingData = new HotelCartBookingData();
+ $objHotelCartBookingData->removeBackdateRoomsFromCart($this->context->cart->id);
+ }
$this->context->currency = new Currency((int)$cart->id_currency);
$cart_detail_data = array();
$cart_detail_data_obj = new HotelCartBookingData();
diff --git a/install/data/xml/configuration.xml b/install/data/xml/configuration.xml
index 935de20ba..5ec2a0371 100644
--- a/install/data/xml/configuration.xml
+++ b/install/data/xml/configuration.xml
@@ -904,6 +904,9 @@
1
+
+
+ 1
\ No newline at end of file
diff --git a/modules/hotelreservationsystem/classes/HotelCartBookingData.php b/modules/hotelreservationsystem/classes/HotelCartBookingData.php
index afae39dcb..8376b6942 100644
--- a/modules/hotelreservationsystem/classes/HotelCartBookingData.php
+++ b/modules/hotelreservationsystem/classes/HotelCartBookingData.php
@@ -766,6 +766,34 @@ class HotelCartBookingData extends ObjectModel
return false;
}
+ /**
+ * [removeBackdateRoomsFromCart :: To delete the rooms from cart whose booking date is before the current date
+ *
+ * @param [int] $idCart [Id of the cart]
+ *
+ * @return [boolean] [If removed successfully returns true else returns false]
+ */
+ public function removeBackdateRoomsFromCart($idCart)
+ {
+ if ($cartBookingData = $this->getCartCurrentDataByCartId($idCart)) {
+ $res = true;
+ foreach ($cartBookingData as $cartRoom) {
+ if (strtotime($cartRoom['date_from']) < strtotime(date('Y-m-d'))) {
+ $res = $res && $this->deleteRoomDataFromOrderLine(
+ $cartRoom['id_cart'],
+ $cartRoom['id_guest'],
+ $cartRoom['id_product'],
+ $cartRoom['date_from'],
+ $cartRoom['date_to']
+ );
+ }
+ }
+ return $res;
+ }
+
+ return true;
+ }
+
/**
* [getCustomerIdRoomsByIdCartIdProduct :: To get array of rooms ids in the cart booked by a customer for a date range].
*
diff --git a/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php b/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php
index b1917b305..d9db5b6ea 100644
--- a/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php
+++ b/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php
@@ -95,7 +95,30 @@ class RoomTypeServiceProductCartDetail extends ObjectModel
)) {
if ($objRoomTypeServiceProductCartDetail->delete()) {
$objCart = new Cart($product['id_cart']);
- $objCart->updateQty((int)($product['quantity']), $product['id_product'], null, false, 'down');
+ if (isset(Context::getContext()->controller->controller_type)) {
+ $controllerType = Context::getContext()->controller->controller_type;
+ } else {
+ $controllerType = 'front';
+ }
+ if ($controllerType == 'admin' || $controllerType == 'moduleadmin') {
+ if ($cartQty = Cart::getProductQtyInCart($product['id_cart'], $product['id_product'])) {
+ if ($product['quantity'] < $cartQty) {
+ Db::getInstance()->update(
+ 'cart_product',
+ array('quantity' => (int)($cartQty - $product['quantity'])),
+ '`id_product` = '.(int)$product['id_product'].' AND `id_cart` = '.(int)$product['id_cart']
+ );
+ } else {
+ //if room type has no qty remaining in cart then delete row
+ Db::getInstance()->delete(
+ 'cart_product',
+ '`id_product` = '.(int)$product['id_product'].' AND `id_cart` = '.(int)$product['id_cart']
+ );
+ }
+ }
+ } else {
+ $objCart->updateQty((int)($product['quantity']), $product['id_product'], null, false, 'down');
+ }
}
}
}
diff --git a/modules/hotelreservationsystem/controllers/admin/AdminHotelRoomsBookingController.php b/modules/hotelreservationsystem/controllers/admin/AdminHotelRoomsBookingController.php
index 6146e43f4..4e6f07575 100644
--- a/modules/hotelreservationsystem/controllers/admin/AdminHotelRoomsBookingController.php
+++ b/modules/hotelreservationsystem/controllers/admin/AdminHotelRoomsBookingController.php
@@ -63,6 +63,11 @@ class AdminHotelRoomsBookingController extends ModuleAdminController
$objCustomer->id_guest = (int) $this->context->cookie->id_guest;
$this->context->customer = $objCustomer;
+
+ if (!Configuration::get('BACKDATE_ORDER_EMPLOYEES')) {
+ $htlCart = new HotelCartBookingData();
+ $htlCart->removeBackdateRoomsFromCart($this->context->cart->id);
+ }
}
protected function createNewCart()
@@ -92,13 +97,18 @@ class AdminHotelRoomsBookingController extends ModuleAdminController
} else {
$date_from = date('Y-m-d');
}
+ if (!Configuration::get('BACKDATE_ORDER_EMPLOYEES')) {
+ if (strtotime(date('Y-m-d')) > strtotime($date_from)) {
+ $date_from = date('Y-m-d');
+ }
+ }
if (Tools::getValue('date_to')) {
$date_to = Tools::getValue('date_to');
} else {
$date_to = date('Y-m-d');
- if (strtotime($date_from) >= strtotime($date_to)) {
- $date_to = date('Y-m-d', strtotime('+1 day', strtotime($date_to)));
- }
+ }
+ if (strtotime($date_from) >= strtotime($date_to)) {
+ $date_to = date('Y-m-d', strtotime('+1 day', strtotime($date_to)));
}
if (Tools::getValue('id_hotel')) {
@@ -842,6 +852,7 @@ class AdminHotelRoomsBookingController extends ModuleAdminController
'years_txt' => $this->l('years', null, true),
'all_children_txt' => $this->l('All Children', null, true),
'invalid_occupancy_txt' => $this->l('Invalid occupancy(adults/children) found.', null, true),
+ 'BACKDATE_ORDER_EMPLOYEES' => Configuration::get('BACKDATE_ORDER_EMPLOYEES'),
// 'check_calender_var' => $check_calender_var,
);
if (Configuration::get('PS_BACKOFFICE_SEARCH_TYPE') == HotelBookingDetail::SEARCH_TYPE_OWS ) {
diff --git a/modules/hotelreservationsystem/hotelreservationsystem.php b/modules/hotelreservationsystem/hotelreservationsystem.php
index e1240de49..7546ea6f8 100644
--- a/modules/hotelreservationsystem/hotelreservationsystem.php
+++ b/modules/hotelreservationsystem/hotelreservationsystem.php
@@ -76,24 +76,8 @@ class HotelReservationSystem extends Module
if (!Configuration::get('PS_CATALOG_MODE')) {
/*To remove room from cart before todays date*/
if (isset($this->context->cart->id) && $this->context->cart->id) {
- $htlCart = new HotelCartBookingData();
- if ($cartBookingData = $htlCart->getCartBookingDetailsByIdCartIdGuest(
- $this->context->cart->id,
- $this->context->cart->id_guest,
- $this->context->language->id
- )) {
- foreach ($cartBookingData as $cartRoom) {
- if (strtotime($cartRoom['date_from']) < strtotime(date('Y-m-d'))) {
- $htlCart->deleteRoomDataFromOrderLine(
- $cartRoom['id_cart'],
- $cartRoom['id_guest'],
- $cartRoom['id_product'],
- $cartRoom['date_from'],
- $cartRoom['date_to']
- );
- }
- }
- }
+ $objHotelCartBookingData = new HotelCartBookingData();
+ $objHotelCartBookingData->removeBackdateRoomsFromCart($this->context->cart->id);
}
}
//End
diff --git a/modules/hotelreservationsystem/views/js/admin/hotel_rooms_booking.js b/modules/hotelreservationsystem/views/js/admin/hotel_rooms_booking.js
index d02a0b756..31b7593a5 100644
--- a/modules/hotelreservationsystem/views/js/admin/hotel_rooms_booking.js
+++ b/modules/hotelreservationsystem/views/js/admin/hotel_rooms_booking.js
@@ -220,6 +220,7 @@ $(document).ready(function() {
dateFormat: 'dd-mm-yy',
altFormat: 'yy-mm-dd',
altField: '#date_from',
+ minDate: BACKDATE_ORDER_EMPLOYEES == 1 ? null : 0,
beforeShowDay: function (date) {
return highlightDateBorder($("#from_date").val(), date);
},
@@ -236,6 +237,7 @@ $(document).ready(function() {
dateFormat: 'dd-mm-yy',
altFormat: 'yy-mm-dd',
altField: '#date_to',
+ minDate: BACKDATE_ORDER_EMPLOYEES == 1 ? null : 1,
beforeShowDay: function (date) {
return highlightDateBorder($("#to_date").val(), date);
},