diff --git a/admin/themes/default/template/controllers/normal_products/helpers/form/form.tpl b/admin/themes/default/template/controllers/normal_products/helpers/form/form.tpl index 7b70d1c05..3fe9645bf 100644 --- a/admin/themes/default/template/controllers/normal_products/helpers/form/form.tpl +++ b/admin/themes/default/template/controllers/normal_products/helpers/form/form.tpl @@ -82,6 +82,9 @@ var with_room_type = {Product::SERVICE_PRODUCT_WITH_ROOMTYPE|intval}; var without_room_type = {Product::SERVICE_PRODUCT_WITHOUT_ROOMTYPE|intval}; + var price_addition_type_with_room = {Product::PRICE_ADDITION_TYPE_WITH_ROOM|intval}; + var price_addition_type_independent = {Product::PRICE_ADDITION_TYPE_INDEPENDENT|intval}; + var has_combinations = {$has_combinations|intval}; diff --git a/admin/themes/default/template/controllers/normal_products/prices.tpl b/admin/themes/default/template/controllers/normal_products/prices.tpl index 231a821a5..ecd8fbbcb 100644 --- a/admin/themes/default/template/controllers/normal_products/prices.tpl +++ b/admin/themes/default/template/controllers/normal_products/prices.tpl @@ -139,7 +139,14 @@ $(document).ready(function () { -
'; childAgeSelect += '
'; $(this).closest('.occupancy_info_block').find('.children_ages').append(childAgeSelect); } - } - } else { - let child = $(this).val(); - $(this).closest('.occupancy_info_block').find('.guest_child_age').each(function(ind, element) { - if (child <= ind) { - $(element).parent().remove(); + } else { + let child = $(this).val(); + $(this).closest('.occupancy_info_block').find('.guest_child_age').each(function(ind, element) { + if (child <= ind) { + $(element).parent().remove(); + } + }); + if (child == 0) { + $(this).closest('.occupancy_info_block').find('.children_age_info_block').hide(); } - }); - if (child == 0) { - $(this).closest('.occupancy_info_block').find('.children_age_info_block').hide(); - } + } } } setRoomTypeGuestOccupancy($(this).closest('.booking_occupancy_wrapper')); - }); + var errorMsgTime; + $('.occupancy-input-errors').parent().hide(); + function showOccupancyError(msg, occupancy_info_block) + { + var errorMsgBlock = $(occupancy_info_block).find('.occupancy-input-errors') + $(errorMsgBlock).html(msg).parent().show('fast'); + clearTimeout(errorMsgTime); + errorMsgTime = setTimeout(function() { + $(errorMsgBlock).parent().hide('fast'); + }, 1000); + + } + $(document).on('click', '.booking_guest_occupancy', function(e) { $(this).parent().toggleClass('open'); @@ -1390,21 +1425,14 @@ }); if (addresses.length == 0) { - $('#addresses_err').show().html('{l s='You must add at least one address to process the order.'}'); $('#address_delivery, #address_invoice').hide(); $("#new_address").show(); - - //by webkul (if there is no address then order can not be created) - $("button[name=\"submitAddOrder\"]").attr("disabled", "disabled"); } else { $('#addresses_err').hide(); $("#new_address").hide(); $('#address_delivery, #address_invoice').show(); - - //by webkul - $("button[name=\"submitAddOrder\"]").removeAttr("disabled"); } /*Changed by webkul to make delivery and invoice addresses same*/ @@ -2146,7 +2174,13 @@ {addJsDefL name='below_txt'}{l s='Below' js=1}{/addJsDefL} {addJsDefL name='years_txt'}{l s='years' js=1}{/addJsDefL} {addJsDefL name='all_children_txt'}{l s='All Children' js=1}{/addJsDefL} + {addJsDefL name='max_occupancy_reached_txt'}{l s='Maximum room occupancy reached' js=1}{/addJsDefL} + {addJsDefL name='max_adults_txt'}{l s='Maximum adult occupancy reached' js=1}{/addJsDefL} + {addJsDefL name='max_children_txt'}{l s='Maximum children occupancy reached' js=1}{/addJsDefL} + {addJsDefL name='no_children_allowed_txt'}{l s='Only adults can be accommodated' js=1}{/addJsDefL} {addJsDefL name='invalid_occupancy_txt'}{l s='Invalid occupancy(adults/children) found.' js=1}{/addJsDefL} + + {/strip}'.Tools::displayError('Error: Please select an address.').'
'; - } if (count($this->context->cart->getDeliveryOptionList()) == 0 && !$this->context->cart->isVirtualCart()) { if ($this->context->cart->isMultiAddressDelivery()) { return ''.Tools::displayError('Error: None of your chosen carriers deliver to some of the addresses you have selected.').'
'; diff --git a/controllers/front/ParentOrderController.php b/controllers/front/ParentOrderController.php index eb2bf17d7..7bac1b5d9 100644 --- a/controllers/front/ParentOrderController.php +++ b/controllers/front/ParentOrderController.php @@ -399,56 +399,54 @@ class ParentOrderControllerCore extends FrontController Tools::redirect(''); } elseif (!Customer::getAddressesTotalById($this->context->customer->id)) { $multi = (int)Tools::getValue('multi-shipping'); - Tools::redirect('index.php?controller=address&back='.urlencode('order.php?step=1'.($multi ? '&multi-shipping='.$multi : ''))); } $customer = $this->context->customer; if (Validate::isLoadedObject($customer)) { /* Getting customer addresses */ - $customerAddresses = $customer->getAddresses($this->context->language->id); + if ($customerAddresses = $customer->getAddresses($this->context->language->id)) { + // Getting a list of formated address fields with associated values + $formatedAddressFieldsValuesList = array(); - // Getting a list of formated address fields with associated values - $formatedAddressFieldsValuesList = array(); + foreach ($customerAddresses as $i => $address) { + if (!Address::isCountryActiveById((int)$address['id_address'])) { + unset($customerAddresses[$i]); + } + $tmpAddress = new Address($address['id_address']); + $formatedAddressFieldsValuesList[$address['id_address']]['ordered_fields'] = AddressFormat::getOrderedAddressFields($address['id_country']); + $formatedAddressFieldsValuesList[$address['id_address']]['formated_fields_values'] = AddressFormat::getFormattedAddressFieldsValues( + $tmpAddress, + $formatedAddressFieldsValuesList[$address['id_address']]['ordered_fields']); - foreach ($customerAddresses as $i => $address) { - if (!Address::isCountryActiveById((int)$address['id_address'])) { - unset($customerAddresses[$i]); + unset($tmpAddress); } - $tmpAddress = new Address($address['id_address']); - $formatedAddressFieldsValuesList[$address['id_address']]['ordered_fields'] = AddressFormat::getOrderedAddressFields($address['id_country']); - $formatedAddressFieldsValuesList[$address['id_address']]['formated_fields_values'] = AddressFormat::getFormattedAddressFieldsValues( - $tmpAddress, - $formatedAddressFieldsValuesList[$address['id_address']]['ordered_fields']); - unset($tmpAddress); - } + $customerAddresses = array_values($customerAddresses); - $customerAddresses = array_values($customerAddresses); + if (!count($customerAddresses) && !Tools::isSubmit('ajax')) { + $bad_delivery = false; + if (($bad_delivery = (bool)!Address::isCountryActiveById((int)$this->context->cart->id_address_delivery)) || !Address::isCountryActiveById((int)$this->context->cart->id_address_invoice)) { + $params = array(); + if ($this->step) { + $params['step'] = (int)$this->step; + } + if ($multi = (int)Tools::getValue('multi-shipping')) { + $params['multi-shipping'] = $multi; + } + $back_url = $this->context->link->getPageLink('order', true, (int)$this->context->language->id, $params); + + $params = array('back' => $back_url, 'id_address' => ($bad_delivery ? (int)$this->context->cart->id_address_delivery : (int)$this->context->cart->id_address_invoice)); + if ($multi) { + $params['multi-shipping'] = $multi; + } - if (!count($customerAddresses) && !Tools::isSubmit('ajax')) { - $bad_delivery = false; - if (($bad_delivery = (bool)!Address::isCountryActiveById((int)$this->context->cart->id_address_delivery)) || !Address::isCountryActiveById((int)$this->context->cart->id_address_invoice)) { - $params = array(); - if ($this->step) { - $params['step'] = (int)$this->step; } - if ($multi = (int)Tools::getValue('multi-shipping')) { - $params['multi-shipping'] = $multi; - } - $back_url = $this->context->link->getPageLink('order', true, (int)$this->context->language->id, $params); - - $params = array('back' => $back_url, 'id_address' => ($bad_delivery ? (int)$this->context->cart->id_address_delivery : (int)$this->context->cart->id_address_invoice)); - if ($multi) { - $params['multi-shipping'] = $multi; - } - - Tools::redirect($this->context->link->getPageLink('address', true, (int)$this->context->language->id, $params)); } + $this->context->smarty->assign(array( + 'addresses' => $customerAddresses, + 'formatedAddressFieldsValuesList' => $formatedAddressFieldsValuesList) + ); } - $this->context->smarty->assign(array( - 'addresses' => $customerAddresses, - 'formatedAddressFieldsValuesList' => $formatedAddressFieldsValuesList) - ); /* Setting default addresses for cart */ if (count($customerAddresses)) { diff --git a/install/data/xml/configuration.xml b/install/data/xml/configuration.xml index 6cc94000e..67b8602c1 100644 --- a/install/data/xml/configuration.xml +++ b/install/data/xml/configuration.xml @@ -904,6 +904,12 @@'; - childAgeSelect += ''; - childAgeSelect += '
'; - $(this).closest('.occupancy_info_block').find('.children_ages').append(childAgeSelect); + let max_guests_in_room = $(this).closest(".booking_occupancy_wrapper").find('.max_guests').val(); + let max_allowed_for_current = (max_guests_in_room - current_room_occupancy) + parseInt($(this).val()); + let haserror = false + if ($(this).hasClass('num_children')) { + max_child_in_room = $(this).closest(".booking_occupancy_wrapper").find('.max_children').val(); + if (elementVal > max_child_in_room) { + $(this).val(max_child_in_room); + if (elementVal == 1) { + showOccupancyError(no_children_allowed_txt, $(this).closest(".occupancy_info_block")); + haserror = true; + } else { + showOccupancyError(max_children_txt, $(this).closest(".occupancy_info_block")); + haserror = true; } - } else { - let child = $(this).val(); - $(this).closest('.occupancy_info_block').find('.guest_child_age').each(function(ind, element) { - if (child <= ind) { - $(element).parent().remove(); + } else if (elementVal > max_allowed_for_current) { + $(this).val(max_allowed_for_current); + showOccupancyError(max_occupancy_reached_txt, $(this).closest(".occupancy_info_block")); + haserror = true; + } + } else { + max_adults_in_room = $(this).closest(".booking_occupancy_wrapper").find('.max_adults').val(); + if (elementVal >= max_adults_in_room) { + $(this).val(max_adults_in_room); + showOccupancyError(max_adults_txt, $(this).closest(".occupancy_info_block")); + haserror = true; + } else if (elementVal > max_allowed_for_current) { + $(this).val(max_allowed_for_current); + showOccupancyError(max_occupancy_reached_txt, $(this).closest(".occupancy_info_block")); + haserror = true; + } + } + if (!haserror) { + if ($(this).hasClass('num_children')) { + var totalChilds = $(this).closest('.occupancy_info_block').find('.guest_child_age').length; + if (totalChilds < $(this).val()) { + let max_child_in_room; + if ($(this).closest(".booking_occupancy_wrapper").find('.max_children').val()) { + max_child_in_room = $(this).closest(".booking_occupancy_wrapper").find('.max_children').val(); + } else { + max_child_in_room = window.max_child_in_room; } - }); - if (child == 0) { - $(this).closest('.occupancy_info_block').find('.children_age_info_block').hide(); - } + if (totalChilds < max_child_in_room) { + $(this).closest('.occupancy_info_block').find('.children_age_info_block').show(); + while ($(this).closest('.occupancy_info_block').find('.guest_child_age').length < $(this).val()) { + + var roomBlockIndex = parseInt($(this).closest('.occupancy_info_block').attr('occ_block_index')); + + var childAgeSelect = ''; + childAgeSelect += ''; + childAgeSelect += '
'; + $(this).closest('.occupancy_info_block').find('.children_ages').append(childAgeSelect); + } + } + } else { + let child = $(this).val(); + $(this).closest('.occupancy_info_block').find('.guest_child_age').each(function(ind, element) { + if (child <= ind) { + $(element).parent().remove(); + } + }); + if (child == 0) { + $(this).closest('.occupancy_info_block').find('.children_age_info_block').hide(); + } + } } } - setRoomTypeGuestOccupancy($(this).closest('.booking_occupancy_wrapper')); }); + var errorMsgTime; + $('.occupancy-input-errors').parent().hide(); + function showOccupancyError(msg, occupancy_info_block) + { + var errorMsgBlock = $(occupancy_info_block).find('.occupancy-input-errors') + $(errorMsgBlock).html(msg).parent().show('fast'); + clearTimeout(errorMsgTime); + errorMsgTime = setTimeout(function() { + $(errorMsgBlock).parent().hide('fast'); + }, 1000); + } $(document).on('click', '.booking_guest_occupancy:not(.disabled)', function(e) { $(this).parent().toggleClass('open'); @@ -1124,6 +1176,13 @@ function initRoomEvents() $('tr#new_product .booking_guest_occupancy').removeClass('disabled'); setRoomTypeGuestOccupancy($('tr#new_product .booking_occupancy_wrapper')); } + if (data.room_type_info) { + $('tr#new_product .max_adults').val(data.room_type_info.max_adults); + $('tr#new_product .max_children').val(data.room_type_info.max_children); + $('tr#new_product .max_guests').val(data.room_type_info.max_guests); + // $('tr#new_product .num_adults').attr('max', data.room_type_info.max_adults); + // $('tr#new_product .num_children').attr('max', data.room_type_info.max_children); + } // Keep product variable current_product = data; @@ -1514,12 +1573,25 @@ function initRoomEvents() $('.add_room_date_to').datepicker('option', 'minDate', objDateToMin); }, + beforeShow : function () { + if(allowBackdateOrder) { + var minDate = null; + } else { + var minDate = new Date(); + } + $(this).datepicker("option", "minDate", minDate); + } }); $(".add_room_date_to").datepicker( { showOtherMonths: true, - dateFormat: 'dd-mm-yy' + dateFormat: 'dd-mm-yy', + beforeShow : function () { + var date_from = $.datepicker.parseDate('dd-mm-yy', $(this).closest('.bookingDuration').find('.add_room_date_from').val()); + date_from.setDate(date_from.getDate() + 1); + $(this).datepicker("option", "minDate", date_from); + } }); $(".edit_product_date_from").datepicker( @@ -1532,12 +1604,25 @@ function initRoomEvents() $('.edit_product_date_to').datepicker('option', 'minDate', objDateToMin); }, + beforeShow : function () { + if(allowBackdateOrder) { + var minDate = null; + } else { + var minDate = new Date(Math.min($.datepicker.parseDate('dd-mm-yy', $(this).data('min_date')), new Date())); + } + $(this).datepicker("option", "minDate", minDate); + } }); $(".edit_product_date_to").datepicker( { showOtherMonths: true, - dateFormat: 'dd-mm-yy' + dateFormat: 'dd-mm-yy', + beforeShow : function () { + var date_from = $.datepicker.parseDate('dd-mm-yy', $(this).closest('.form-group').find('.edit_product_date_from').val()); + date_from.setDate(date_from.getDate() + 1); + $(this).datepicker("option", "minDate", date_from); + } }); /*End*/ diff --git a/modules/bankwire/controllers/front/validation.php b/modules/bankwire/controllers/front/validation.php index 5df9b7411..e9cd89014 100644 --- a/modules/bankwire/controllers/front/validation.php +++ b/modules/bankwire/controllers/front/validation.php @@ -35,7 +35,7 @@ class BankwireValidationModuleFrontController extends ModuleFrontController public function postProcess() { $cart = $this->context->cart; - if ($cart->id_customer == 0 || $cart->id_address_delivery == 0 || $cart->id_address_invoice == 0 || !$this->module->active) + if ($cart->id_customer == 0 || !$this->module->active) Tools::redirect('index.php?controller=order&step=1'); // Check that this payment option is still available in case the customer changed his address just before the end of the checkout process diff --git a/modules/cheque/controllers/front/validation.php b/modules/cheque/controllers/front/validation.php index f280abd3f..8c79afea1 100644 --- a/modules/cheque/controllers/front/validation.php +++ b/modules/cheque/controllers/front/validation.php @@ -33,7 +33,7 @@ class ChequeValidationModuleFrontController extends ModuleFrontController { $cart = $this->context->cart; - if ($cart->id_customer == 0 || $cart->id_address_delivery == 0 || $cart->id_address_invoice == 0 || !$this->module->active) + if ($cart->id_customer == 0 || !$this->module->active) Tools::redirect('index.php?controller=order&step=1'); // Check that this payment option is still available in case the customer changed his address just before the end of the checkout process diff --git a/modules/hotelreservationsystem/classes/HotelCartBookingData.php b/modules/hotelreservationsystem/classes/HotelCartBookingData.php index 0ce580dcf..996995906 100644 --- a/modules/hotelreservationsystem/classes/HotelCartBookingData.php +++ b/modules/hotelreservationsystem/classes/HotelCartBookingData.php @@ -774,6 +774,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 94c40c1ec..443dd4b8e 100644 --- a/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php +++ b/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php @@ -64,14 +64,13 @@ class RoomTypeServiceProductCartDetail extends ObjectModel } if ($updateQty = $quantity - $objRoomTypeServiceProductCartDetail->quantity) { + $way = $updateQty > 0 ? 'up' : 'down'; + $objRoomTypeServiceProductCartDetail->quantity += $updateQty; if (Product::getProductPriceCalculation($idProduct) == Product::PRICE_CALCULATION_METHOD_PER_DAY) { $objHotelCartBookingData = new HotelCartBookingData($idHtlCartData); $numdays = HotelHelper::getNumberOfDays($objHotelCartBookingData->date_from, $objHotelCartBookingData->date_to); $updateQty *= $numdays; - } - $way = $updateQty > 0 ? 'up' : 'down'; - $objRoomTypeServiceProductCartDetail->quantity = $quantity; if ($objRoomTypeServiceProductCartDetail->save()) { $objCart = new Cart($idCart); return $objCart->updateQty((int)abs($updateQty), $idProduct, null, false, $way); @@ -86,16 +85,45 @@ class RoomTypeServiceProductCartDetail extends ObjectModel public function removeServiceProductByIdHtlCartBooking($htlCartBookingId) { if ($stadardProductsData = Db::getInstance()->executeS( - 'SELECT * FROM `'._DB_PREFIX_.'htl_room_type_service_product_cart_detail` - WHERE `htl_cart_booking_id` = '.(int)$htlCartBookingId + 'SELECT * FROM `' . _DB_PREFIX_ . 'htl_room_type_service_product_cart_detail` + WHERE `htl_cart_booking_id` = ' . (int)$htlCartBookingId )) { foreach ($stadardProductsData as $product) { if (Validate::isLoadedObject( $objRoomTypeServiceProductCartDetail = new RoomTypeServiceProductCartDetail($product['id_room_type_service_product_cart_detail']) )) { + $updateQty = $product['quantity']; + if (Product::getProductPriceCalculation($product['id_product']) == Product::PRICE_CALCULATION_METHOD_PER_DAY) { + $objHotelCartBookingData = new HotelCartBookingData($idHtlCartData); + $numdays = HotelHelper::getNumberOfDays($objHotelCartBookingData->date_from, $objHotelCartBookingData->date_to); + $updateQty *= $numdays; + } 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)($updateQty), $product['id_product'], null, false, 'down'); + } } } } diff --git a/modules/hotelreservationsystem/classes/RoomTypeServiceProductPrice.php b/modules/hotelreservationsystem/classes/RoomTypeServiceProductPrice.php index fc4235a05..bfbf62f2b 100644 --- a/modules/hotelreservationsystem/classes/RoomTypeServiceProductPrice.php +++ b/modules/hotelreservationsystem/classes/RoomTypeServiceProductPrice.php @@ -69,12 +69,24 @@ class RoomTypeServiceProductPrice extends ObjectModel public static function getProductRoomTypePriceAndTax($idProduct, $idElement, $elementType) { - return Db::getInstance()->getRow( - 'SELECT `price`, `id_tax_rules_group` FROM `'._DB_PREFIX_.'htl_room_type_service_product_price` - WHERE `id_product`='.(int)$idProduct. - ' AND `id_element`='.(int)$idElement. - ' AND `element_type`='.(int)$elementType - ); + if ($result = Db::getInstance()->getRow(' + SELECT spp.`price`, spp.`id_tax_rules_group`, p.`auto_add_to_cart`, p.`price_addition_type` + FROM `'._DB_PREFIX_.'product` p + LEFT JOIN `'._DB_PREFIX_.'htl_room_type_service_product` sp ON (sp.`id_product` = p.`id_product`) + LEFT JOIN `'._DB_PREFIX_.'htl_room_type_service_product_price` spp ON (spp.`id_product` = p.`id_product`) + WHERE p.`id_product`='.(int)$idProduct. + ' AND sp.`id_element`='.(int)$idElement. + ' AND sp.`element_type`='.(int)$elementType) + ) { + if ($result['auto_add_to_cart'] && $result['price_addition_type'] == Product::PRICE_ADDITION_TYPE_WITH_ROOM) { + // if service is auto add to cart and added in room price, we need to find room type tax rule group + if ($elementType == RoomTypeServiceProduct::WK_ELEMENT_TYPE_ROOM_TYPE) { + $result['id_tax_rules_group'] = Product::getIdTaxRulesGroupByIdProduct((int)$idElement); + } + } + } + + return $result; } public function getProductRoomTypeLinkPriceInfo($idProduct, $idElement, $elementType) diff --git a/modules/hotelreservationsystem/controllers/admin/AdminHotelRoomsBookingController.php b/modules/hotelreservationsystem/controllers/admin/AdminHotelRoomsBookingController.php index 32cb89c18..97805c21f 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminHotelRoomsBookingController.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminHotelRoomsBookingController.php @@ -69,6 +69,15 @@ class AdminHotelRoomsBookingController extends ModuleAdminController $objCustomer->id_guest = (int) $this->context->cookie->id_guest; $this->context->customer = $objCustomer; + if ($this->context->employee->isSuperAdmin()) { + $backOrderConfigKey = 'PS_BACKDATE_ORDER_SUPERADMIN'; + } else { + $backOrderConfigKey = 'PS_BACKDATE_ORDER_EMPLOYEES'; + } + if (!Configuration::get($backOrderConfigKey)) { + $htlCart = new HotelCartBookingData(); + $htlCart->removeBackdateRoomsFromCart($this->context->cart->id); + } } protected function createNewCart() @@ -98,13 +107,23 @@ class AdminHotelRoomsBookingController extends ModuleAdminController } else { $date_from = date('Y-m-d'); } + if ($this->context->employee->isSuperAdmin()) { + $backOrderConfigKey = 'PS_BACKDATE_ORDER_SUPERADMIN'; + } else { + $backOrderConfigKey = 'PS_BACKDATE_ORDER_EMPLOYEES'; + } + if (!Configuration::get($backOrderConfigKey)) { + 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')) { @@ -886,6 +905,13 @@ class AdminHotelRoomsBookingController extends ModuleAdminController if (Configuration::get('PS_BACKOFFICE_ROOM_BOOKING_TYPE') == HotelBookingDetail::PS_ROOM_UNIT_SELECTION_TYPE_OCCUPANCY) { $occupancyRequiredForBooking = true; } + if ($this->context->employee->isSuperAdmin()) { + $backOrderConfigKey = 'PS_BACKDATE_ORDER_SUPERADMIN'; + } else { + $backOrderConfigKey = 'PS_BACKDATE_ORDER_EMPLOYEES'; + } + $PS_BACKDATE_ORDER_ALLOW = (int)Configuration::get($backOrderConfigKey); + $jsVars = array( 'currency_prefix' => $currency->prefix, 'currency_suffix' => $currency->suffix, @@ -925,7 +951,12 @@ class AdminHotelRoomsBookingController extends ModuleAdminController 'below_txt' => $this->l('Below', null, true), 'years_txt' => $this->l('years', null, true), 'all_children_txt' => $this->l('All Children', null, true), + 'max_occupancy_reached_txt' => $this->l('Maximum room occupancy reached', null, true), + 'max_adults_txt' => $this->l('Maximum adult occupancy reached', null, true), + 'max_children_txt' => $this->l('Maximum children occupancy reached', null, true), + 'no_children_allowed_txt' => $this->l('Only adults can be accommodated', null, true), 'invalid_occupancy_txt' => $this->l('Invalid occupancy(adults/children) found.', null, true), + 'PS_BACKDATE_ORDER_ALLOW' => $PS_BACKDATE_ORDER_ALLOW, // 'check_calender_var' => $check_calender_var, 'txtSomeErr' => $this->l('Some error occurred. Please try again.'), 'no_rm_avail_txt' => $this->l('No room available.', null, true), diff --git a/modules/hotelreservationsystem/hotelreservationsystem.php b/modules/hotelreservationsystem/hotelreservationsystem.php index a511179d3..bf6473245 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 f4518217b..4e6390085 100644 --- a/modules/hotelreservationsystem/views/js/admin/hotel_rooms_booking.js +++ b/modules/hotelreservationsystem/views/js/admin/hotel_rooms_booking.js @@ -230,6 +230,7 @@ $(document).ready(function() { dateFormat: 'dd-mm-yy', altFormat: 'yy-mm-dd', altField: '#date_from', + minDate: PS_BACKDATE_ORDER_ALLOW == 1 ? null : 0, beforeShowDay: function (date) { return highlightDateBorder($("#from_date").val(), date); }, @@ -246,6 +247,11 @@ $(document).ready(function() { dateFormat: 'dd-mm-yy', altFormat: 'yy-mm-dd', altField: '#date_to', + beforeShow: function () { + from_date = $.datepicker.parseDate('dd-mm-yy', $("#from_date").val()); + from_date.setDate(from_date.getDate() + 1); + $("#to_date").datepicker("option", "minDate", from_date); + }, beforeShowDay: function (date) { return highlightDateBorder($("#to_date").val(), date); }, @@ -597,55 +603,91 @@ $(document).ready(function() { }); $(document).on('change', '.num_occupancy', function(e) { - + let elementVal = parseInt($(this).val()); let current_room_occupancy = 0; $(this).closest('.occupancy_info_block').find('.num_occupancy').each(function(){ current_room_occupancy += parseInt($(this).val()); }); let max_guests_in_room = $(this).closest(".booking_occupancy_wrapper").find('.max_guests').val(); let max_allowed_for_current = (max_guests_in_room - current_room_occupancy) + parseInt($(this).val()); - if ($(this).val() > $(this).attr('max')) { - $(this).val($(this).attr('max')); - } - if ($(this).val() > max_allowed_for_current) { - $(this).val(max_allowed_for_current); - } - + let haserror = false if ($(this).hasClass('num_children')) { - let totalChilds = $(this).closest('.occupancy_info_block').find('.guest_child_age').length; - if (totalChilds < $(this).val()) { - $(this).closest('.occupancy_info_block').find('.children_age_info_block').show(); - while ($(this).closest('.occupancy_info_block').find('.guest_child_age').length < $(this).val()) { - var roomBlockIndex = parseInt($(this).closest('.occupancy_info_block').attr('occ_block_index')); - var childAgeSelect = '({l s='Below' mod='wkroomsearchblock'} {$max_child_age|escape:'htmlall':'UTF-8'} {l s='years' mod='wkroomsearchblock'})