Add option to disable backdate order from admin
This commit is contained in:
@@ -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'),
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -904,6 +904,9 @@
|
||||
</configuration>
|
||||
<configuration id="PS_SERVICE_PRODUCT_CATEGORY_FILTER" name="PS_SERVICE_PRODUCT_CATEGORY_FILTER">
|
||||
<value>1</value>
|
||||
</configuration>
|
||||
<configuration id="BACKDATE_ORDER_EMPLOYEES" name="BACKDATE_ORDER_EMPLOYEES">
|
||||
<value>1</value>
|
||||
</configuration>
|
||||
</entities>
|
||||
</entity_configuration>
|
||||
@@ -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].
|
||||
*
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 ) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user