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 () { -
+
auto_add_to_cart || $product->price_addition_type != Product::PRICE_ADDITION_TYPE_WITH_ROOM}style="display:none"{/if}> +
+
+ {l s='This service product price will be auto added to room price so the tax rule set on room type will be applied on this service product'} +
+
+
+
auto_add_to_cart && $product->price_addition_type == Product::PRICE_ADDITION_TYPE_WITH_ROOM}style="display:none"{/if}>
{include file="controllers/products/multishop/checkbox.tpl" field="id_tax_rules_group" type="default"}
-
+
auto_add_to_cart && $product->price_addition_type == Product::PRICE_ADDITION_TYPE_WITH_ROOM}style="display:none"{/if}>
{$currency->prefix}{$currency->suffix} diff --git a/admin/themes/default/template/controllers/orders/_current_cart_details_data.tpl b/admin/themes/default/template/controllers/orders/_current_cart_details_data.tpl index 214705745..fb6f389c2 100644 --- a/admin/themes/default/template/controllers/orders/_current_cart_details_data.tpl +++ b/admin/themes/default/template/controllers/orders/_current_cart_details_data.tpl @@ -71,17 +71,18 @@
- +
- + ({l s='Below'} {$max_child_age|escape:'htmlall':'UTF-8'} {l s='years'})
+

diff --git a/admin/themes/default/template/controllers/orders/_new_product.tpl b/admin/themes/default/template/controllers/orders/_new_product.tpl index 4082199eb..423f2af17 100644 --- a/admin/themes/default/template/controllers/orders/_new_product.tpl +++ b/admin/themes/default/template/controllers/orders/_new_product.tpl @@ -88,6 +88,7 @@ ({l s='Below'} {$max_child_age|escape:'htmlall':'UTF-8'} {l s='years'})
+

+

diff --git a/admin/themes/default/template/controllers/orders/form.tpl b/admin/themes/default/template/controllers/orders/form.tpl index ceaf56d69..419a395f7 100644 --- a/admin/themes/default/template/controllers/orders/form.tpl +++ b/admin/themes/default/template/controllers/orders/form.tpl @@ -386,28 +386,51 @@ }); $(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')) { - var totalChilds = $(this).closest('.occupancy_info_block').find('.guest_child_age').length; - if (totalChilds < $(this).val()) { - if (totalChilds < max_child_in_room) { + max_child_in_room = $(this).closest(".booking_occupancy_wrapper").find('.max_children').val(); + console.log(no_children_allowed_txt); + 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 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')) { + 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 = '

'; childAgeSelect += ' - + + @@ -1687,6 +1688,10 @@ {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} {addJsDefL name='select_room_txt'}{l s='Select room' js=1}{/addJsDefL} {addJsDef max_child_age=$max_child_age|escape:'quotes':'UTF-8'} @@ -1718,12 +1723,11 @@ {* open date picker for the date input of check-in checkout dates *} $(document).on('focus', '.room_status_date', function() { var dateFrom = $(this).closest('.room_status_info_form').find('[name="date_from"]').val(); - minDate = $.datepicker.parseDate('yy-mm-dd', dateFrom); + minDate = new Date(dateFrom+'T00:00:00'); var dateTo = $(this).closest('.room_status_info_form').find('[name="date_to"]').val(); - maxDate = $.datepicker.parseDate('yy-mm-dd', dateTo); - - $(this).datepicker({ + maxDate = new Date(dateTo+'T23:59:59'); + $(this).datetimepicker({ dateFormat: 'dd-mm-yy', minDate: minDate, maxDate: maxDate, diff --git a/admin/themes/default/template/controllers/products/serviceproduct.tpl b/admin/themes/default/template/controllers/products/serviceproduct.tpl index de03ff8de..e7b2001cb 100644 --- a/admin/themes/default/template/controllers/products/serviceproduct.tpl +++ b/admin/themes/default/template/controllers/products/serviceproduct.tpl @@ -81,17 +81,21 @@

-
- -
-
{l s='Default tax rule: %s' sprintf=$service_product.association_info.default_tax_rules_group_name}
+ {if $service_product.association_info.auto_add_to_cart && $service_product.association_info.price_addition_type == Product::PRICE_ADDITION_TYPE_WITH_ROOM} + {l s='-'} + {else} +
+ +
+
{l s='Default tax rule: %s' sprintf=$service_product.association_info.default_tax_rules_group_name}
+ {/if} {/foreach} diff --git a/admin/themes/default/template/controllers/translations/helpers/view/translation_errors.tpl b/admin/themes/default/template/controllers/translations/helpers/view/translation_errors.tpl index db367c079..558975584 100644 --- a/admin/themes/default/template/controllers/translations/helpers/view/translation_errors.tpl +++ b/admin/themes/default/template/controllers/translations/helpers/view/translation_errors.tpl @@ -26,6 +26,7 @@ {extends file="helpers/view/view.tpl"} {block name="override_tpl"} + {include file="./translation_inputs_update.tpl"} {if $mod_security_warning}
{l s='Apache mod_security is activated on your server. This could result in some Bad Request errors'} diff --git a/admin/themes/default/template/controllers/translations/helpers/view/translation_form.tpl b/admin/themes/default/template/controllers/translations/helpers/view/translation_form.tpl index 98f54235c..72fec199a 100644 --- a/admin/themes/default/template/controllers/translations/helpers/view/translation_form.tpl +++ b/admin/themes/default/template/controllers/translations/helpers/view/translation_form.tpl @@ -26,6 +26,7 @@ {extends file="helpers/view/view.tpl"} {block name="override_tpl"} + {include file="./translation_inputs_update.tpl"} {if $mod_security_warning}
{l s='Apache mod_security is activated on your server. This could result in some Bad Request errors'} diff --git a/admin/themes/default/template/controllers/translations/helpers/view/translation_inputs_update.tpl b/admin/themes/default/template/controllers/translations/helpers/view/translation_inputs_update.tpl new file mode 100644 index 000000000..2a9fc59c4 --- /dev/null +++ b/admin/themes/default/template/controllers/translations/helpers/view/translation_inputs_update.tpl @@ -0,0 +1,31 @@ +{** + * 2010-2023 Webkul. + * + * NOTICE OF LICENSE + * + * All right is reserved, + * Please go through LICENSE.txt file inside our module + * + * DISCLAIMER + * + * Do not edit or add to this file if you wish to upgrade this module to newer + * versions in the future. If you wish to customize this module for your + * needs please refer to CustomizationPolicy.txt file inside our module for more information. + * + * @author Webkul IN + * @copyright 2010-2023 Webkul IN + * @license LICENSE.txt + *} + + \ No newline at end of file diff --git a/admin/themes/default/template/controllers/translations/helpers/view/translation_modules.tpl b/admin/themes/default/template/controllers/translations/helpers/view/translation_modules.tpl index 49a2d828d..58363e68c 100644 --- a/admin/themes/default/template/controllers/translations/helpers/view/translation_modules.tpl +++ b/admin/themes/default/template/controllers/translations/helpers/view/translation_modules.tpl @@ -26,6 +26,7 @@ {extends file="helpers/view/view.tpl"} {block name="override_tpl"} + {include file="./translation_inputs_update.tpl"} {if $mod_security_warning}
{l s='Apache mod_security is activated on your server. This could result in some Bad Request errors'} diff --git a/classes/Hook.php b/classes/Hook.php index 356d7b5b5..6604c73dd 100644 --- a/classes/Hook.php +++ b/classes/Hook.php @@ -326,9 +326,9 @@ class HookCore extends ObjectModel } // For payment modules, we check that they are available in the contextual country elseif ($frontend) { - if (Validate::isLoadedObject($context->country)) { - $sql->where('((h.`name` = "displayPayment" OR h.`name` = "displayPaymentEU") AND (SELECT `id_country` FROM `'._DB_PREFIX_.'module_country` mc WHERE mc.`id_module` = m.`id_module` AND `id_country` = '.(int)$context->country->id.' AND `id_shop` = '.(int)$context->shop->id.' LIMIT 1) = '.(int)$context->country->id.')'); - } + // if (Validate::isLoadedObject($context->country)) { + // $sql->where('((h.`name` = "displayPayment" OR h.`name` = "displayPaymentEU") AND (SELECT `id_country` FROM `'._DB_PREFIX_.'module_country` mc WHERE mc.`id_module` = m.`id_module` AND `id_country` = '.(int)$context->country->id.' AND `id_shop` = '.(int)$context->shop->id.' LIMIT 1) = '.(int)$context->country->id.')'); + // } if (Validate::isLoadedObject($context->currency)) { $sql->where('((h.`name` = "displayPayment" OR h.`name` = "displayPaymentEU") AND (SELECT `id_currency` FROM `'._DB_PREFIX_.'module_currency` mcr WHERE mcr.`id_module` = m.`id_module` AND `id_currency` IN ('.(int)$context->currency->id.', -1, -2) LIMIT 1) IN ('.(int)$context->currency->id.', -1, -2))'); } diff --git a/classes/PaymentModule.php b/classes/PaymentModule.php index 58d1f7256..0e30ce63b 100644 --- a/classes/PaymentModule.php +++ b/classes/PaymentModule.php @@ -181,9 +181,6 @@ abstract class PaymentModuleCore extends Module ShopUrl::resetMainDomainCache(); $id_currency = $currency_special ? (int)$currency_special : (int)$this->context->cart->id_currency; $this->context->currency = new Currency((int)$id_currency, null, (int)$this->context->shop->id); - if (Configuration::get('PS_TAX_ADDRESS_TYPE') == 'id_address_delivery') { - $context_country = $this->context->country; - } $order_status = new OrderState((int)$id_order_state, (int)$this->context->language->id); if (!Validate::isLoadedObject($order_status)) { @@ -274,14 +271,6 @@ abstract class PaymentModuleCore extends Module $order = new Order(); $order->product_list = $package['product_list']; - if (Configuration::get('PS_TAX_ADDRESS_TYPE') == 'id_address_delivery') { - $address = new Address((int)$id_address); - $this->context->country = new Country((int)$address->id_country, (int)$this->context->cart->id_lang); - if (!$this->context->country->active && $this->name != 'wsorder') { - throw new PrestaShopException('The delivery address country is not active.'); - } - } - $carrier = null; if (!$this->context->cart->isVirtualCart() && isset($package['id_carrier'])) { $carrier = new Carrier((int)$package['id_carrier'], (int)$this->context->cart->id_lang); @@ -463,15 +452,6 @@ abstract class PaymentModuleCore extends Module } } - // The country can only change if the address used for the calculation is the delivery address, and if multi-shipping is activated - if (Configuration::get('PS_TAX_ADDRESS_TYPE') == 'id_address_delivery') { - $this->context->country = $context_country; - } - - if (!$this->context->country->active && $this->name != 'wsorder') { - PrestaShopLogger::addLog('PaymentModule::validateOrder - Country is not active', 3, null, 'Cart', (int)$id_cart, true); - throw new PrestaShopException('The order address country is not active.'); - } if (self::DEBUG_MODE) { PrestaShopLogger::addLog('PaymentModule::validateOrder - Payment is about to be added', 1, null, 'Cart', (int)$id_cart, true); diff --git a/classes/Product.php b/classes/Product.php index 3fb1f8ee5..d9fb9d6b3 100644 --- a/classes/Product.php +++ b/classes/Product.php @@ -2999,7 +2999,7 @@ class ProductCore extends ObjectModel public static function getPriceStatic($id_product, $usetax = true, $id_product_attribute = null, $decimals = 6, $divisor = null, $only_reduc = false, $usereduc = true, $quantity = 1, $force_associated_tax = false, $id_customer = null, $id_cart = null, $id_address = null, &$specific_price_output = null, $with_ecotax = true, $use_group_reduction = true, Context $context = null, - $use_customer_price = true, $id_roomtype = false) + $use_customer_price = true, $id_product_roomtype = false) { if (!$context) { $context = Context::getContext(); @@ -3065,9 +3065,9 @@ class ProductCore extends ObjectModel if (!$id_address) { if (!Product::isBookingProduct($id_product)) { - if ($id_roomtype) { + if ($id_product_roomtype) { // if room type is provided with product then we know that the service product price should be calculated accroding to roomt type - $id_address = Cart::getIdAddressForTaxCalculation($id_roomtype); + $id_address = Cart::getIdAddressForTaxCalculation($id_product_roomtype); } } else { $id_address = Cart::getIdAddressForTaxCalculation($id_product); @@ -3121,7 +3121,7 @@ class ProductCore extends ObjectModel $use_customer_price, $id_cart, $cart_quantity, - $id_roomtype + $id_product_roomtype ); return $return; @@ -3155,9 +3155,8 @@ class ProductCore extends ObjectModel **/ public static function priceCalculation($id_shop, $id_product, $id_product_attribute, $id_country, $id_state, $zipcode, $id_currency, $id_group, $quantity, $use_tax, $decimals, $only_reduc, $use_reduc, $with_ecotax, &$specific_price, $use_group_reduction, - $id_customer = 0, $use_customer_price = true, $id_cart = 0, $real_quantity = 0, $id_roomtype = false) + $id_customer = 0, $use_customer_price = true, $id_cart = 0, $real_quantity = 0, $id_product_roomtype = false) { - static $address = null; static $context = null; @@ -3184,7 +3183,7 @@ class ProductCore extends ObjectModel $cache_id = (int)$id_product.'-'.(int)$id_shop.'-'.(int)$id_currency.'-'.(int)$id_country.'-'.$id_state.'-'.$zipcode.'-'.(int)$id_group. '-'.(int)$quantity.'-'.(int)$id_product_attribute. '-'.(int)$with_ecotax.'-'.(int)$id_customer.'-'.(int)$use_group_reduction.'-'.(int)$id_cart.'-'.(int)$real_quantity. - '-'.($only_reduc?'1':'0').'-'.($use_reduc?'1':'0').'-'.($use_tax?'1':'0').'-'.(int)$decimals.'-'.($id_roomtype?(int)$id_roomtype:'0'); + '-'.($only_reduc?'1':'0').'-'.($use_reduc?'1':'0').'-'.($use_tax?'1':'0').'-'.(int)$decimals.'-'.($id_product_roomtype?(int)$id_product_roomtype:'0'); // reference parameter is filled before any returns $specific_price = SpecificPrice::getSpecificPrice( @@ -3248,10 +3247,10 @@ class ProductCore extends ObjectModel $result = self::$_pricesLevel2[$cache_id_2][(int)$id_product_attribute]; // get price per room type - if ($id_roomtype) { + if ($id_product_roomtype) { $priceForRoomInfo = RoomTypeServiceProductPrice::getProductRoomTypePriceAndTax( $id_product, - $id_roomtype, + $id_product_roomtype, RoomTypeServiceProduct::WK_ELEMENT_TYPE_ROOM_TYPE ); } diff --git a/classes/checkoutProcess/CheckoutCustomerDetailsStep.php b/classes/checkoutProcess/CheckoutCustomerDetailsStep.php index b8933ae06..6bccd6e83 100644 --- a/classes/checkoutProcess/CheckoutCustomerDetailsStep.php +++ b/classes/checkoutProcess/CheckoutCustomerDetailsStep.php @@ -33,13 +33,9 @@ class CheckoutCustomerDetailsStepCore extends AbstractCheckoutStepCore if (Tools::getValue('proceed_to_customer_dtl')) { $this->step_is_reachable = 1; $this->step_is_current = 1; - if ($idAddressDelivery) { - if (!Validate::isLoadedObject($objAddress)) { - if ($this->context->cookie->__get('customer_details_proceeded')) { - $this->step_is_current = 0; - $this->step_is_complete = 1; - } - } + if ($this->context->cookie->__get('customer_details_proceeded')) { + $this->step_is_current = 0; + $this->step_is_complete = 1; } } elseif (Tools::getValue('proceed_to_payment')) { $guestInfoComplete = true; @@ -52,34 +48,20 @@ class CheckoutCustomerDetailsStepCore extends AbstractCheckoutStepCore } $this->step_is_reachable = 1; $this->step_is_current = 1; - if ($idAddressDelivery && $guestInfoComplete) { - if (Validate::isLoadedObject($objAddress)) { - $this->step_is_current = 0; - $this->step_is_complete = 1; - $this->context->cookie->__set('customer_details_proceeded', 1); - } + if ($guestInfoComplete) { + $this->step_is_current = 0; + $this->step_is_complete = 1; + $this->context->cookie->__set('customer_details_proceeded', 1); } } elseif ($this->context->cookie->__get('customer_details_proceeded') || $this->context->cookie->__get('cart_summary_proceeded') ) { - if ($idAddressDelivery) { - if (!Validate::isLoadedObject($objAddress)) { - $this->context->cookie->__set('customer_details_proceeded', 0); - $this->step_is_reachable = 1; - $this->step_is_current = 1; - } - } else { - $this->step_is_reachable = 1; - $this->step_is_current = 1; - $this->context->cookie->__set('customer_details_proceeded', 0); - } } elseif ($this->context->customer->logged) { $this->step_is_reachable = 1; if ($idAddressDelivery) { $this->step_is_complete = 1; } else { $this->step_is_complete = 0; - $this->step_is_current = 1; } } } diff --git a/classes/controller/FrontController.php b/classes/controller/FrontController.php index 229412aa5..21aa82c4d 100644 --- a/classes/controller/FrontController.php +++ b/classes/controller/FrontController.php @@ -417,11 +417,12 @@ class FrontControllerCore extends Controller $display_tax_label = $this->context->country->display_tax_label; if (isset($cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}) && $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}) { - $infos = Address::getCountryAndState((int)$cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); - $country = new Country((int)$infos['id_country']); - $this->context->country = $country; - if (Validate::isLoadedObject($country)) { - $display_tax_label = $country->display_tax_label; + if ($infos = Address::getCountryAndState((int)$cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')})) { + $country = new Country((int)$infos['id_country']); + $this->context->country = $country; + if (Validate::isLoadedObject($country)) { + $display_tax_label = $country->display_tax_label; + } } } diff --git a/classes/module/Module.php b/classes/module/Module.php index 534666815..95d78ca09 100644 --- a/classes/module/Module.php +++ b/classes/module/Module.php @@ -2069,9 +2069,6 @@ abstract class ModuleCore public static function getPaymentModules() { $context = Context::getContext(); - if (isset($context->cart)) { - $billing = new Address((int)$context->cart->id_address_invoice); - } $use_groups = Group::isFeatureActive(); @@ -2101,7 +2098,6 @@ abstract class ModuleCore LEFT JOIN `'._DB_PREFIX_.'hook_module` hm ON hm.`id_module` = m.`id_module` LEFT JOIN `'._DB_PREFIX_.'hook` h ON hm.`id_hook` = h.`id_hook` WHERE h.`name` = \''.pSQL($hook_payment).'\' - '.(isset($billing) && $frontend ? 'AND mc.id_country = '.(int)$billing->id_country : '').' AND (SELECT COUNT(*) FROM '._DB_PREFIX_.'module_shop ms WHERE ms.id_module = m.id_module AND ms.id_shop IN('.implode(', ', $list).')) = '.count($list).' AND hm.id_shop IN('.implode(', ', $list).') '.((count($groups) && $frontend && $use_groups) ? 'AND (mg.`id_group` IN ('.implode(', ', $groups).'))' : '').' diff --git a/classes/module/ModuleGraph.php b/classes/module/ModuleGraph.php index c0ad40e9a..f087a0a2c 100644 --- a/classes/module/ModuleGraph.php +++ b/classes/module/ModuleGraph.php @@ -104,7 +104,7 @@ abstract class ModuleGraphCore extends Module $this->_values[$j][$i] = 0; } } - $this->_legend[$i] = ($i % 2) ? '' : sprintf('%02d', $i); + $this->_legend[$i] = sprintf('%02d', $i); } } if (is_callable(array($this, 'setMonthValues'))) { @@ -197,15 +197,15 @@ abstract class ModuleGraphCore extends Module if (count($this->_legend)) { $total = 0; if ($datas['type'] == 'pie') { - foreach ($this->_legend as $key => $legend) { + // foreach ($this->_legend as $key => $legend) { for ($i = 0, $total_main = (is_array($this->_titles['main']) ? count($this->_values) : 1); $i < $total_main; ++$i) { - $total += (is_array($this->_values[$i]) ? $this->_values[$i][$key] : $this->_values[$key]); + $total += (is_array($this->_values[$i]) ? $this->_values[$i][$key] : $this->_values[$i]); } - } + // } } foreach ($this->_legend as $key => $legend) { $this->_csv .= $legend.';'; - for ($i = 0, $total_main = (is_array($this->_titles['main']) ? count($this->_values) : 1); $i < $total_main; ++$i) { + for ($i = 0, $total_main = (is_array($this->_titles['main']) ? (count($this->_titles['main']) - 1) : 1); $i < $total_main; ++$i) { if (!isset($this->_values[$i]) || !is_array($this->_values[$i])) { if (isset($this->_values[$key])) { // We don't want strings to be divided. Example: product name diff --git a/classes/order/Order.php b/classes/order/Order.php index 6e8a54dbd..bf9a33801 100644 --- a/classes/order/Order.php +++ b/classes/order/Order.php @@ -1823,7 +1823,11 @@ class OrderCore extends ObjectModel $order_payment->order_reference = $this->reference; $order_payment->id_currency = ($currency ? $currency->id : $this->id_currency); // we kept the currency rate for historization reasons - $order_payment->conversion_rate = ($currency ? $currency->conversion_rate : 1); + $order_payment->conversion_rate = ( + $currency ? + $currency->conversion_rate : + (new Currency($this->id_currency))->getConversationRate() + ); // if payment_method is define, we used this $order_payment->payment_method = ($payment_method ? $payment_method : $this->payment); $order_payment->payment_type = ($payment_type ? $payment_type : $this->payment_type); diff --git a/controllers/admin/AdminCustomerPreferencesController.php b/controllers/admin/AdminCustomerPreferencesController.php index a9e94ae53..9acd1961b 100644 --- a/controllers/admin/AdminCustomerPreferencesController.php +++ b/controllers/admin/AdminCustomerPreferencesController.php @@ -120,13 +120,6 @@ class AdminCustomerPreferencesControllerCore extends AdminController 'cast' => 'intval', 'type' => 'bool' ), - 'PS_CUSTOMER_ADDRESS_CREATION' => array( - 'title' => $this->l('Address creation during checkout'), - 'hint' => $this->l('If disabled, Address form will not appear to user during checkout process. So by default hotel address, which rooms guest has in his cart will be considered as user address. Else user has to fill adress details.'), - 'validation' => 'isBool', - 'cast' => 'intval', - 'type' => 'bool' - ), ), 'submit' => array('title' => $this->l('Save')), ), diff --git a/controllers/admin/AdminNormalProductsController.php b/controllers/admin/AdminNormalProductsController.php index baeded608..89d0327ac 100644 --- a/controllers/admin/AdminNormalProductsController.php +++ b/controllers/admin/AdminNormalProductsController.php @@ -1905,6 +1905,12 @@ class AdminNormalProductsControllerCore extends AdminController // set product visibility to none for current flow. $object->visibility = 'none'; + // if service is auto_added and price addition is in room price, then the tax rule is applied of room price. + // so setting tax rule as no tax for now + if ($object->auto_add_to_cart && $object->price_addition_type == Product::PRICE_ADDITION_TYPE_WITH_ROOM) { + $object->id_tax_rules_group = 0; + } + // Duplicate combinations if not associated to shop if ($this->context->shop->getContext() == Shop::CONTEXT_SHOP && !$object->isAssociatedToShop()) { $is_associated_to_shop = false; diff --git a/controllers/admin/AdminOrderPreferencesController.php b/controllers/admin/AdminOrderPreferencesController.php index 77f3c791f..52c131480 100644 --- a/controllers/admin/AdminOrderPreferencesController.php +++ b/controllers/admin/AdminOrderPreferencesController.php @@ -90,6 +90,16 @@ class AdminOrderPreferencesControllerCore extends AdminController 'class' => 'fixed-width-xl', 'suffix' => $this->l('day(s)'), ), + 'PS_BACKDATE_ORDER_SUPERADMIN' => array( + 'title' => $this->l('Allow backdate order from Back-office for super-admin'), + 'hint' => $this->l('Allow superadmin to create bookings for backdate'), + 'type' => 'bool', + ), + 'PS_BACKDATE_ORDER_EMPLOYEES' => array( + 'title' => $this->l('Allow backdate order from Back-office for employees'), + 'hint' => $this->l('Allow 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 74b7398d5..b58c17844 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -365,6 +365,15 @@ class AdminOrdersControllerCore extends AdminController $cart_order_exists = $cart->orderExists(); if (!$cart_order_exists) { $this->context->cart = $cart; + if ($this->context->employee->isSuperAdmin()) { + $backOrderConfigKey = 'PS_BACKDATE_ORDER_SUPERADMIN'; + } else { + $backOrderConfigKey = 'PS_BACKDATE_ORDER_EMPLOYEES'; + } + if (!Configuration::get($backOrderConfigKey)) { + $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(); @@ -1173,15 +1182,23 @@ class AdminOrdersControllerCore extends AdminController Context::getContext()->currency = new Currency((int)$cart->id_currency); Context::getContext()->customer = new Customer((int)$cart->id_customer); - $bad_delivery = false; - if (($bad_delivery = (bool)!Address::isCountryActiveById((int)$cart->id_address_delivery)) - || !Address::isCountryActiveById((int)$cart->id_address_invoice)) { - if ($bad_delivery) { - $this->errors[] = Tools::displayError('This booking address country is not active.'); - } else { - $this->errors[] = Tools::displayError('This invoice address country is not active.'); - } + if ($this->context->employee->isSuperAdmin()) { + $backOrderConfigKey = 'PS_BACKDATE_ORDER_SUPERADMIN'; } else { + $backOrderConfigKey = 'PS_BACKDATE_ORDER_EMPLOYEES'; + } + if (!Configuration::get($backOrderConfigKey)) { + $objCartBookingData = new HotelCartBookingData(); + if ($cartBookingData = $objCartBookingData->getCartCurrentDataByCartId($cart->id)) { + foreach ($cartBookingData as $cartRoom) { + if (strtotime($cartRoom['date_from']) < strtotime(date('Y-m-d'))) { + $this->errors[] = Tools::displayError('You cannot book rooms before today date.'); + } + } + } + } + + if (empty($this->errors)) { $employee = new Employee((int)Context::getContext()->cookie->id_employee); $payment_module->validateOrder( (int)$cart->id, @@ -2084,6 +2101,13 @@ class AdminOrdersControllerCore extends AdminController // hotel booking statuses $htlOrderStatus = HotelBookingDetail::getAllHotelOrderStatus(); + if ($this->context->employee->isSuperAdmin()) { + $backOrderConfigKey = 'PS_BACKDATE_ORDER_SUPERADMIN'; + } else { + $backOrderConfigKey = 'PS_BACKDATE_ORDER_EMPLOYEES'; + } + $allowBackdateOrder = Configuration::get($backOrderConfigKey); + // applicable refund policies $applicableRefundPolicies = HotelOrderRefundRules::getApplicableRefundRules($order->id); @@ -2113,6 +2137,7 @@ class AdminOrdersControllerCore extends AdminController 'order' => $order, 'cart' => new Cart($order->id_cart), 'customer' => $customer, + 'allowBackdateOrder' => $allowBackdateOrder, 'gender' => $gender, 'customerGuestDetail' => $customerGuestDetail, 'genders' => Gender::getGenders(), @@ -3051,12 +3076,21 @@ class AdminOrdersControllerCore extends AdminController 'result' => false, 'error' => Tools::displayError('Please Enter a valid Check out Date.'), ))); - } elseif ($date_from < $curr_date) { - die(json_encode(array( - 'result' => false, - 'error' => Tools::displayError('Check In date should not be date before current date.'), - ))); - } elseif ($date_to <= $date_from) { + } + if ($this->context->employee->isSuperAdmin()) { + $backOrderConfigKey = 'PS_BACKDATE_ORDER_SUPERADMIN'; + } else { + $backOrderConfigKey = 'PS_BACKDATE_ORDER_EMPLOYEES'; + } + if (!Configuration::get($backOrderConfigKey)) { + if ($date_from < $curr_date) { + die(json_encode(array( + 'result' => false, + 'error' => Tools::displayError('Check In date should not be date before current date.'), + ))); + } + } + if ($date_to <= $date_from) { die(json_encode(array( 'result' => false, 'error' => Tools::displayError('Check out Date Should be after Check In date.'), @@ -4147,6 +4181,20 @@ class AdminOrdersControllerCore extends AdminController // get extra demands of the room before changing in the booking table $objBookingDemand = new HotelBookingDemands(); + $objRoomTypeServiceProductOrderDetail = new RoomTypeServiceProductOrderDetail(); + $orderServiceProducts = $objRoomTypeServiceProductOrderDetail->getroomTypeServiceProducts( + $id_order, + 0, + 0, + 0, + $old_date_from, + $old_date_to, + $id_room, + 0, + null, + null + ); + $extraDemands = $objBookingDemand->getRoomTypeBookingExtraDemands( $id_order, 0, @@ -4210,6 +4258,61 @@ class AdminOrdersControllerCore extends AdminController // change order total save $objOrder->save(); } + + if (isset($orderServiceProducts) + && is_array($orderServiceProducts) + && count($orderServiceProducts) + ) { + $objOrder = new Order((int) $id_order); + foreach ($orderServiceProducts as $orderServiceProduct) { + if (isset($orderServiceProduct['additional_services']) + && is_array($orderServiceProduct['additional_services']) + && count($orderServiceProduct['additional_services']) + ) { + foreach ($orderServiceProduct['additional_services'] as $serviceProduct) { + if (Product::getProductPriceCalculation($serviceProduct['id_product']) == Product::PRICE_CALCULATION_METHOD_PER_DAY) { + $newNumDays = HotelHelper::getNumberOfDays($new_date_from, $new_date_to); + $objRoomTypeServiceProductOrderDetail = new RoomTypeServiceProductOrderDetail((int) $serviceProduct['id_room_type_service_product_order_detail']); + $unitPriceTaxExcl = $objRoomTypeServiceProductOrderDetail->unit_price_tax_excl; + $unitPriceTaxIncl = $objRoomTypeServiceProductOrderDetail->unit_price_tax_incl; + + $newTotalPriceTaxExcl = $newNumDays * $objRoomTypeServiceProductOrderDetail->quantity * $unitPriceTaxExcl; $unitPriceTaxIncl = $objRoomTypeServiceProductOrderDetail->unit_price_tax_incl; + $newTotalPriceTaxIncl = $newNumDays * $objRoomTypeServiceProductOrderDetail->quantity * $unitPriceTaxIncl; + + $objOrder->total_paid_tax_excl -= $objRoomTypeServiceProductOrderDetail->total_price_tax_excl; + $objOrder->total_paid_tax_incl -= $objRoomTypeServiceProductOrderDetail->total_price_tax_incl; + $objOrder->total_paid -= $objRoomTypeServiceProductOrderDetail->total_price_tax_incl; + + // change order total + $objOrder->total_paid_tax_excl += $newTotalPriceTaxExcl; + $objOrder->total_paid_tax_incl += $newTotalPriceTaxIncl; + $objOrder->total_paid += $newTotalPriceTaxIncl; + + $objOrderDetail = new OrderDetail((int) $serviceProduct['id_order_detail']); + $objOrderDetail->total_price_tax_excl -= $objRoomTypeServiceProductOrderDetail->total_price_tax_excl; + $objOrderDetail->total_price_tax_incl -= $objRoomTypeServiceProductOrderDetail->total_price_tax_incl; + $objOrderDetail->total_price_tax_excl += $newTotalPriceTaxExcl; + $objOrderDetail->total_price_tax_incl += $newTotalPriceTaxIncl; + + $oldNumDays = HotelHelper::getNumberOfDays($old_date_from, $old_date_to); + $oldProductQuantity = $objRoomTypeServiceProductOrderDetail->quantity * $oldNumDays; + $newProductQuantity = $objRoomTypeServiceProductOrderDetail->quantity * $newNumDays; + $objOrderDetail->product_quantity += ($newProductQuantity - $oldProductQuantity); + $objOrderDetail->save(); + + $objRoomTypeServiceProductOrderDetail->unit_price_tax_excl = $unitPriceTaxExcl; + $objRoomTypeServiceProductOrderDetail->unit_price_tax_incl = $unitPriceTaxIncl; + $objRoomTypeServiceProductOrderDetail->total_price_tax_excl = $newTotalPriceTaxExcl; + $objRoomTypeServiceProductOrderDetail->total_price_tax_incl = $newTotalPriceTaxIncl; + $objRoomTypeServiceProductOrderDetail->save(); + + } + } + } + } + + $objOrder->save(); + } } if (is_array(Tools::getValue('product_quantity'))) { @@ -4823,12 +4926,22 @@ class AdminOrdersControllerCore extends AdminController 'result' => false, 'error' => Tools::displayError('Please Enter a valid Check out Date.'), ))); - } elseif ($new_date_from < $curr_date) { - die(json_encode(array( - 'result' => false, - 'error' => Tools::displayError('Check In date should not be after current date.'), - ))); - } elseif ($new_date_to <= $new_date_from) { + } + if ($this->context->employee->isSuperAdmin()) { + $backOrderConfigKey = 'PS_BACKDATE_ORDER_SUPERADMIN'; + } else { + $backOrderConfigKey = 'PS_BACKDATE_ORDER_EMPLOYEES'; + } + if (!Configuration::get($backOrderConfigKey)) { + $compareDate = min(date('Y-m-d'), $old_date_from); + if ($new_date_from < $compareDate) { + die(json_encode(array( + 'result' => false, + 'error' => sprintf(Tools::displayError('Check In date should not be date before %s.'),$compareDate) + ))); + } + } + if ($new_date_to <= $new_date_from) { die(json_encode(array( 'result' => false, 'error' => Tools::displayError('Check out Date Should be after Check In date.'), @@ -5390,46 +5503,58 @@ class AdminOrdersControllerCore extends AdminController $quantity = Tools::getValue('qty'); if (Validate::isLoadedObject($objRoomTypeServiceProductOrderDetail = new RoomTypeServiceProductOrderDetail($id_room_type_service_product_order_detail))) { - $objOrderDetail = new OrderDetail($objRoomTypeServiceProductOrderDetail->id_order_detail); - if ($objOrderDetail->product_allow_multiple_quantity) { - if (!Validate::isUnsignedInt($quantity)) { - $response['hasError'] = true; - $response['errors'] = $this->l('Invalid quantity provided'); - } else { - $objRoomTypeServiceProductOrderDetail->quantity = $quantity; - $oldPriceTaxExcl = $objRoomTypeServiceProductOrderDetail->total_price_tax_excl; - $oldPriceTaxIncl = $objRoomTypeServiceProductOrderDetail->total_price_tax_incl; - $objRoomTypeServiceProductOrderDetail->total_price_tax_excl = $objRoomTypeServiceProductOrderDetail->unit_price_tax_excl * $quantity; - $objRoomTypeServiceProductOrderDetail->total_price_tax_incl = $objRoomTypeServiceProductOrderDetail->unit_price_tax_incl * $quantity; - $res = true; - if ($res &= $objRoomTypeServiceProductOrderDetail->save()) { - $order = new Order($objRoomTypeServiceProductOrderDetail->id_order); - $priceDiffTaxExcl = $objRoomTypeServiceProductOrderDetail->total_price_tax_excl - $oldPriceTaxExcl; - $priceDiffTaxIncl = $objRoomTypeServiceProductOrderDetail->total_price_tax_incl - $oldPriceTaxIncl; - - $objOrderDetail->product_quantity = $quantity; - $objOrderDetail->total_price_tax_excl += $priceDiffTaxExcl; - $objOrderDetail->total_price_tax_incl += $priceDiffTaxIncl; - - $res &= $objOrderDetail->updateTaxAmount($order); - - $res &= $objOrderDetail->update(); - - $order->total_paid_tax_excl += $priceDiffTaxExcl; - $order->total_paid_tax_incl += $priceDiffTaxIncl; - $order->total_paid += $priceDiffTaxIncl; - - $res &= $order->update(); - } + if (Validate::isLoadedObject($objHotelBookingDetail = new HotelBookingDetail((int) $objRoomTypeServiceProductOrderDetail->id_htl_booking_detail))) { + $numDays = 1; + if (Product::getProductPriceCalculation($objRoomTypeServiceProductOrderDetail->id_product) == Product::PRICE_CALCULATION_METHOD_PER_DAY) { + $numDays = HotelHelper::getNumberOfDays($objHotelBookingDetail->date_from, $objHotelBookingDetail->date_to); } - if (!$res) { + + $objOrderDetail = new OrderDetail($objRoomTypeServiceProductOrderDetail->id_order_detail); + if ($objOrderDetail->product_allow_multiple_quantity) { + if (!Validate::isUnsignedInt($quantity)) { + $response['hasError'] = true; + $response['errors'] = $this->l('Invalid quantity provided'); + } else { + $oldQuantity = $objRoomTypeServiceProductOrderDetail->quantity; + $objRoomTypeServiceProductOrderDetail->quantity = $quantity; + $oldPriceTaxExcl = $objRoomTypeServiceProductOrderDetail->total_price_tax_excl; + $oldPriceTaxIncl = $objRoomTypeServiceProductOrderDetail->total_price_tax_incl; + $objRoomTypeServiceProductOrderDetail->total_price_tax_excl = $objRoomTypeServiceProductOrderDetail->unit_price_tax_excl * $quantity * $numDays; + $objRoomTypeServiceProductOrderDetail->total_price_tax_incl = $objRoomTypeServiceProductOrderDetail->unit_price_tax_incl * $quantity * $numDays; + $res = true; + if ($res &= $objRoomTypeServiceProductOrderDetail->save()) { + $order = new Order($objRoomTypeServiceProductOrderDetail->id_order); + $priceDiffTaxExcl = $objRoomTypeServiceProductOrderDetail->total_price_tax_excl - $oldPriceTaxExcl; + $priceDiffTaxIncl = $objRoomTypeServiceProductOrderDetail->total_price_tax_incl - $oldPriceTaxIncl; + + $objOrderDetail->product_quantity += (($quantity - $oldQuantity) * $numDays); + $objOrderDetail->total_price_tax_excl += $priceDiffTaxExcl; + $objOrderDetail->total_price_tax_incl += $priceDiffTaxIncl; + + $res &= $objOrderDetail->updateTaxAmount($order); + + $res &= $objOrderDetail->update(); + + $order->total_paid_tax_excl += $priceDiffTaxExcl; + $order->total_paid_tax_incl += $priceDiffTaxIncl; + $order->total_paid += $priceDiffTaxIncl; + + $res &= $order->update(); + } + } + if (!$res) { + $response['hasError'] = true; + $response['errors'] = $this->l('Error while updating service, please try refresing the page'); + } + } else { $response['hasError'] = true; - $response['errors'] = $this->l('Error while updating service, please try refresing the page'); + $response['errors'] = $this->l('cannot order multiple quanitity for this service'); } } else { $response['hasError'] = true; - $response['errors'] = $this->l('cannot order multiple quanitity for this service'); + $response['errors'] = $this->l('Additional service not found'); } + $objHotelBookingDetail = new HotelBookingDetail($objRoomTypeServiceProductOrderDetail->id_htl_booking_detail); $response['service_panel']= $servicesBlock = $this->processRenderServicesPanel( $objOrderDetail->id_order, @@ -5579,54 +5704,70 @@ class AdminOrdersControllerCore extends AdminController $roomInfo = $objHotelRoomType->getRoomTypeInfoByIdProduct($objHotelBookingDetail->id_product); $totalPriceChangeTaxExcl = 0; $totalPriceChangeTaxIncl = 0; + $unitPriceTaxIncl = 0; + $unitPriceTaxExcl = 0; foreach ($productList as &$product) { - $totalPriceChangeTaxExcl += $totalPriceTaxExcl = $objRoomTypeServiceProductPrice->getServicePrice( - (int)$product['id_product'], - $roomInfo['id'], - $product['cart_quantity'], - $objHotelBookingDetail->date_from, - $objHotelBookingDetail->date_to, - false - ); - $totalPriceChangeTaxIncl += $totalPriceTaxIncl = $objRoomTypeServiceProductPrice->getServicePrice( - (int)$product['id_product'], - $roomInfo['id'], - $product['cart_quantity'], - $objHotelBookingDetail->date_from, - $objHotelBookingDetail->date_to, - true - ); - $unitPriceTaxExcl = $objRoomTypeServiceProductPrice->getServicePrice( - (int)$product['id_product'], - $roomInfo['id'], - 1, - $objHotelBookingDetail->date_from, - $objHotelBookingDetail->date_to, - false - ); - $unitPriceTaxIncl = $objRoomTypeServiceProductPrice->getServicePrice( - (int)$product['id_product'], - $roomInfo['id'], - 1, - $objHotelBookingDetail->date_from, - $objHotelBookingDetail->date_to, - true - ); - switch (Configuration::get('PS_ROUND_TYPE')) { - case Order::ROUND_TOTAL: - $product['total'] = $totalPriceTaxExcl; - $product['total_wt'] = $totalPriceTaxIncl; - break; - case Order::ROUND_LINE: - $product['total'] = Tools::ps_round($totalPriceTaxExcl, _PS_PRICE_COMPUTE_PRECISION_); - $product['total_wt'] = Tools::ps_round($totalPriceTaxIncl, _PS_PRICE_COMPUTE_PRECISION_); - break; + // This is used to get the actual quanity of the service as it is calculated incorrectly if the service is per night + if ($id_room_type_service_product_cart_detail = $objRoomTypeServiceProductCartDetail->alreadyExists( + $service['id'], + $cart->id, + $roomHtlCartInfo['id']) + ) { + $objRoomTypeServiceProductCartDetail = new RoomTypeServiceProductCartDetail((int) $id_room_type_service_product_cart_detail); + $totalPriceChangeTaxExcl += $totalPriceTaxExcl = $objRoomTypeServiceProductPrice->getServicePrice( + (int)$product['id_product'], + $roomInfo['id'], + $objRoomTypeServiceProductCartDetail->quantity, + $objHotelBookingDetail->date_from, + $objHotelBookingDetail->date_to, + false + ); + $totalPriceChangeTaxIncl += $totalPriceTaxIncl = $objRoomTypeServiceProductPrice->getServicePrice( + (int)$product['id_product'], + $roomInfo['id'], + $objRoomTypeServiceProductCartDetail->quantity, + $objHotelBookingDetail->date_from, + $objHotelBookingDetail->date_to, + true + ); + $numDays = 1; + if (Product::getProductPriceCalculation($product['id_product']) == Product::PRICE_CALCULATION_METHOD_PER_DAY) { + $numDays = HotelHelper::getNumberOfDays($objHotelBookingDetail->date_from, $objHotelBookingDetail->date_to); + } + $product['cart_quantity'] = $objRoomTypeServiceProductCartDetail->quantity * $numDays; - case Order::ROUND_ITEM: - default: - $product['total'] = Tools::ps_round($totalPriceTaxExcl, _PS_PRICE_COMPUTE_PRECISION_) * (int)$product['cart_quantity']; - $product['total_wt'] = Tools::ps_round($totalPriceTaxIncl, _PS_PRICE_COMPUTE_PRECISION_) * (int)$product['cart_quantity']; - break; + $unitPriceTaxExcl = $objRoomTypeServiceProductPrice->getServicePrice( + (int)$product['id_product'], + $roomInfo['id'], + 1, + $objHotelBookingDetail->date_from, + $objHotelBookingDetail->date_to, + false + )/ $numDays; + $unitPriceTaxIncl = $objRoomTypeServiceProductPrice->getServicePrice( + (int)$product['id_product'], + $roomInfo['id'], + 1, + $objHotelBookingDetail->date_from, + $objHotelBookingDetail->date_to, + true + )/ $numDays; + switch (Configuration::get('PS_ROUND_TYPE')) { + case Order::ROUND_TOTAL: + $product['total'] = $totalPriceTaxExcl; + $product['total_wt'] = $totalPriceTaxIncl; + break; + case Order::ROUND_LINE: + $product['total'] = Tools::ps_round($totalPriceTaxExcl, _PS_PRICE_COMPUTE_PRECISION_); + $product['total_wt'] = Tools::ps_round($totalPriceTaxIncl, _PS_PRICE_COMPUTE_PRECISION_); + break; + + case Order::ROUND_ITEM: + default: + $product['total'] = Tools::ps_round($totalPriceTaxExcl, _PS_PRICE_COMPUTE_PRECISION_); + $product['total_wt'] = Tools::ps_round($totalPriceTaxIncl, _PS_PRICE_COMPUTE_PRECISION_); + break; + } } } @@ -5644,7 +5785,7 @@ class AdminOrdersControllerCore extends AdminController $objRoomTypeServiceProductOrderDetail->total_price_tax_excl = $totalPriceTaxExcl; $objRoomTypeServiceProductOrderDetail->total_price_tax_incl = $totalPriceTaxIncl; $objRoomTypeServiceProductOrderDetail->name = $product['name']; - $objRoomTypeServiceProductOrderDetail->quantity = $product['cart_quantity']; + $objRoomTypeServiceProductOrderDetail->quantity = $objRoomTypeServiceProductCartDetail->quantity; $objRoomTypeServiceProductOrderDetail->save(); // update totals amount of order @@ -5910,97 +6051,69 @@ class AdminOrdersControllerCore extends AdminController // To change the status of the room public function changeRoomStatus() { - $idRoom = (int) Tools::getValue('id_room'); - $idOrder = (int) Tools::getValue('id_order'); - $dateFrom = Tools::getValue('date_from'); - $dateTo = Tools::getValue('date_to'); - $newStatus = (int) Tools::getValue('booking_order_status'); + $idHotelBookingDetail = (int) Tools::getValue('id_hotel_booking_detail'); + if (Validate::isLoadedObject($objHotelBookingDetail = new HotelBookingDetail($idHotelBookingDetail))) { + $newStatus = (int) Tools::getValue('booking_order_status'); + // date choosen for the status change + if ($statusDate = Tools::getValue('status_date')) { + $statusDate = date('Y-m-d H:i:s', strtotime($statusDate)); + } - // date choosen for the status change - if ($statusDate = Tools::getValue('status_date')) { - $statusDate = date('Y-m-d', strtotime($statusDate)); - } - // Lets validate the fields - if (!$idRoom) { - $this->errors[] = Tools::displayError('Room information not found.'); - } - if (!$idOrder) { - $this->errors[] = Tools::displayError('Order information not found.'); - } - if (!$dateFrom - || !$dateTo - || !Validate::isDate($dateFrom) - || !Validate::isDate($dateTo) - ) { - $this->errors[] = Tools::displayError('Invalid dates found.'); - } - - if (!$newStatus) { - $this->errors[] = Tools::displayError('Invalid booking status found.'); - } elseif ( - $newStatus == HotelBookingDetail::STATUS_CHECKED_IN - || $newStatus == HotelBookingDetail::STATUS_CHECKED_OUT - ) { - if (!$statusDate || !Validate::isDate($statusDate)) { - $this->errors[] = Tools::displayError('Invalid dates found.'); - } elseif ((strtotime($statusDate) < strtotime($dateFrom)) - || (strtotime($statusDate) > strtotime($dateTo)) + $dateFrom = date('Y-m-d H:i:s', strtotime(date('Y-m-d', strtotime($objHotelBookingDetail->date_from)))); + $dateTo = date('Y-m-d H:i:s', strtotime(date('Y-m-d', strtotime($objHotelBookingDetail->date_to)).' 23:59:59')); + if (!$newStatus) { + $this->errors[] = Tools::displayError('Invalid booking status found.'); + } elseif ($newStatus == HotelBookingDetail::STATUS_CHECKED_IN + || $newStatus == HotelBookingDetail::STATUS_CHECKED_OUT ) { - $this->errors[] = Tools::displayError('Invalid dates found.'); - } - } - - if (!count($this->errors)) { - $objBookingDetail = new HotelBookingDetail(); - if ($roomBookingInfo = $objBookingDetail->getRoomBookingData($idRoom, $idOrder, $dateFrom, $dateTo)) { - // if admin choose Check-Out status - if ($newStatus == HotelBookingDetail::STATUS_CHECKED_OUT - && $roomBookingInfo['check_in'] == '0000-00-00 00:00:00' + if (!$statusDate || !Validate::isDate($statusDate)) { + $this->errors[] = Tools::displayError('Invalid dates found.'); + } elseif ((strtotime($statusDate) < strtotime($dateFrom)) + || (strtotime($statusDate) > strtotime($dateTo)) ) { - $this->errors[] = Tools::displayError('Room status must be set to Check-In before setting the room status to Check-Out.'); - } elseif ($newStatus == HotelBookingDetail::STATUS_CHECKED_OUT - && $roomBookingInfo['check_in'] != '0000-00-00 00:00:00' - && strtotime($roomBookingInfo['check_in']) >= strtotime($statusDate) - ) { - $this->errors[] = Tools::displayError('Check-Out date can not be before Check-In date'). - '('.date('d-m-Y', strtotime($roomBookingInfo['check_in'])).')'; - } elseif ($newStatus == HotelBookingDetail::STATUS_CHECKED_IN && $roomBookingInfo['check_out'] == '0000-00-00 00:00:00' - && strtotime($roomBookingInfo['check_in']) >= strtotime($dateTo) - ) { - $this->errors[] = Tools::displayError('Check-In date can not be after Check-Out date'). - '('.date('d-m-Y', strtotime($roomBookingInfo['date_to'])).')'; - } elseif ($newStatus == HotelBookingDetail::STATUS_CHECKED_IN && $roomBookingInfo['check_out'] != '0000-00-00 00:00:00' - && strtotime($roomBookingInfo['check_out']) <= strtotime($statusDate) - ) { - $this->errors[] = Tools::displayError('Check-In date can not be after Check-Out date'). - '('.date('d-m-Y', strtotime($roomBookingInfo['check_out'])).')'; - } else { - if ($objBookingDetail->updateBookingOrderStatusByOrderId( - $idOrder, - $newStatus, - $idRoom, - $dateFrom, - $dateTo, - $statusDate - )) { - Hook::exec( - 'actionRoomBookingStatusUpdateAfter', - array( - 'id_order' => $idOrder, - 'id_room' => $idRoom, - 'date_from' => $dateFrom, - 'date_to' => $dateTo - ) - ); - - Tools::redirectAdmin(self::$currentIndex.'&id_order='.(int) $idOrder.'&vieworder&token='.$this->token.'&conf=4'); - } else { - $this->errors[] = Tools::displayError('Some error occurred. Please try again.'); - } + $this->errors[] = Tools::displayError('Date should be between booking from date and to date.'); } - } else { - $this->errors[] = Tools::displayError('Invalid booking information. Please try again.'); } + if ($newStatus == HotelBookingDetail::STATUS_CHECKED_OUT) { + if ($objHotelBookingDetail->check_in == '0000-00-00 00:00:00') { + $this->errors[] = Tools::displayError('Room status must be set to Check-In before setting the room status to Check-Out.'); + } elseif (strtotime($objHotelBookingDetail->check_in) > strtotime($statusDate)) { + $this->errors[] = sprintf( + Tools::displayError('Check-Out date can not be before Check-In date (%s)'), + date('d-m-Y', strtotime($objHotelBookingDetail->check_in)) + ); + } + } + + 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'); + } else { + $this->errors[] = Tools::displayError('Some error occurred. Please try again.'); + } + } + } else { + $this->errors[] = Tools::displayError('Invalid booking information. Please try again.'); } } diff --git a/controllers/admin/AdminPaymentController.php b/controllers/admin/AdminPaymentController.php index 2985ff95a..007becbd7 100644 --- a/controllers/admin/AdminPaymentController.php +++ b/controllers/admin/AdminPaymentController.php @@ -205,13 +205,13 @@ class AdminPaymentControllerCore extends AdminController 'identifier' => 'id_group', 'icon' => 'icon-group', ), - array('items' =>Country::getCountries($this->context->language->id), - 'title' => $this->l('Country restrictions'), - 'desc' => $this->l('Please mark each checkbox for the country, or countries, in which you want the payment module(s) to be available.'), - 'name_id' => 'country', - 'identifier' => 'id_country', - 'icon' => 'icon-globe', - ) + // array('items' =>Country::getCountries($this->context->language->id), + // 'title' => $this->l('Country restrictions'), + // 'desc' => $this->l('Please mark each checkbox for the country, or countries, in which you want the payment module(s) to be available.'), + // 'name_id' => 'country', + // 'identifier' => 'id_country', + // 'icon' => 'icon-globe', + // ) ); foreach ($lists as $key_list => $list) { @@ -243,13 +243,13 @@ class AdminPaymentControllerCore extends AdminController } // If is a country list and the country is limited, remove it from list - if ($name_id == 'country' - && isset($module->limited_countries) - && !empty($module->limited_countries) - && is_array($module->limited_countries) - && !(in_array(strtoupper($item['iso_code']), array_map('strtoupper', $module->limited_countries)))) { - $list['items'][$key_item]['check_list'][$key_module] = null; - } + // if ($name_id == 'country' + // && isset($module->limited_countries) + // && !empty($module->limited_countries) + // && is_array($module->limited_countries) + // && !(in_array(strtoupper($item['iso_code']), array_map('strtoupper', $module->limited_countries)))) { + // $list['items'][$key_item]['check_list'][$key_module] = null; + // } } } // update list diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php index ccf491954..8d57d805d 100644 --- a/controllers/admin/AdminProductsController.php +++ b/controllers/admin/AdminProductsController.php @@ -3007,6 +3007,7 @@ class AdminProductsControllerCore extends AdminController $associationInfo['id_product'] = $objProduct->id; $associationInfo['name'] = $objProduct->name; $associationInfo['auto_add_to_cart'] = $objProduct->auto_add_to_cart; + $associationInfo['price_addition_type'] = $objProduct->price_addition_type; $associationInfo['category'] = $objProduct->category; $associationInfo['default_price'] = $objProduct->price; $associationInfo['id_tax_rules_group'] = $objProduct->id_tax_rules_group; @@ -3137,7 +3138,9 @@ class AdminProductsControllerCore extends AdminController } $objRoomTypeServiceProductPrice->price = $price; - $objRoomTypeServiceProductPrice->id_tax_rules_group = $idTaxRulesGroup; + if ($idTaxRulesGroup) { + $objRoomTypeServiceProductPrice->id_tax_rules_group = $idTaxRulesGroup; + } $objRoomTypeServiceProductPrice->save(); } else { diff --git a/controllers/admin/AdminTranslationsController.php b/controllers/admin/AdminTranslationsController.php index 71ae8481b..73d3addbf 100644 --- a/controllers/admin/AdminTranslationsController.php +++ b/controllers/admin/AdminTranslationsController.php @@ -292,32 +292,63 @@ class AdminTranslationsControllerCore extends AdminController } } - if ($fd = fopen($file_path, 'w')) { - // Get value of button save and stay - $save_and_stay = Tools::isSubmit('submitTranslations'.$type.'AndStay'); + // Get value of button save and stay + $save_and_stay = Tools::isSubmit('submitTranslations'.$type.'AndStay'); - // Get language - $lang = strtolower(Tools::getValue('lang')); + // Get language + $lang = strtolower(Tools::getValue('lang')); - // Unset all POST which are not translations - unset( - $_POST['submitTranslations'.$type], - $_POST['submitTranslations'.$type.'AndStay'], - $_POST['lang'], - $_POST['token'], - $_POST['theme'], - $_POST['type'] - ); + // Unset all POST which are not translations + unset( + $_POST['submitTranslations'.$type], + $_POST['submitTranslations'.$type.'AndStay'], + $_POST['lang'], + $_POST['token'], + $_POST['theme'], + $_POST['type'] + ); - // Get all POST which aren't empty - $to_insert = array(); - foreach ($_POST as $key => $value) { - if (!empty($value)) { - $to_insert[$key] = $value; + // Get all POST which aren't empty + $to_update = array(); + $keysToUpdate = array(); + foreach ($_POST as $key => $value) { + $keysToUpdate[] = $key; + $to_update[$key] = $value; + } + include_once($file_path); + switch($this->type_selected) { + case 'front': + $to_insert = $GLOBALS['_LANG']; + break; + case 'back': + $to_insert = $GLOBALS['_LANGADM']; + break; + case 'errors': + $to_insert = $GLOBALS['_ERRORS']; + break; + case 'fields': + $to_insert = $GLOBALS['_FIELDS']; + break; + case 'pdf': + $to_insert = $GLOBALS['_LANGPDF']; + break; + + } + foreach ($to_insert as $key => $value) { + if (in_array($key, $keysToUpdate)) { + if ($to_update[$key]) { + $to_insert[$key] = $to_update[$key]; + } else { + unset($to_insert[$key]); } + unset($to_update[$key]); } + } + foreach ($to_update as $key => $value) { + $to_insert[$key] = $value; + } - // translations array is ordered by key (easy merge) + if ($fd = fopen($file_path, 'w')) { ksort($to_insert); $tab = $translation_informations['var']; fwrite($fd, "total_expression++; } } + foreach ($module_existing_translations as $key => $value) { + if (!in_array('\''.$key.'\'', $array_check_duplicate)) { + $str_write .= '$_MODULE[\''.$key.'\'] = \''.pSQL(str_replace(array("\r\n", "\r", "\n"), ' ', $value)).'\';'."\n"; + + } + } + } } diff --git a/controllers/front/AuthController.php b/controllers/front/AuthController.php index 111c91863..fe8caa4a3 100644 --- a/controllers/front/AuthController.php +++ b/controllers/front/AuthController.php @@ -411,7 +411,10 @@ class AuthControllerCore extends FrontController $firstnameAddress = Tools::getValue('firstname'); $_POST['lastname'] = Tools::getValue('customer_lastname', $lastnameAddress); $_POST['firstname'] = Tools::getValue('customer_firstname', $firstnameAddress); - $addresses_types = array('address'); + $addresses_types = []; + if (Configuration::get('PS_REGISTRATION_PROCESS_TYPE')) { + $addresses_types[] = 'address'; + } if (!Configuration::get('PS_ORDER_PROCESS_TYPE') && Configuration::get('PS_GUEST_CHECKOUT_ENABLED') && Tools::getValue('invoice_address')) { $addresses_types[] = 'address_invoice'; @@ -435,36 +438,6 @@ class AuthControllerCore extends FrontController $this->errors[] = Tools::displayError('You must register at least one phone number.'); } - // if PS_CUSTOMER_ADDRESS_CREATION is disabled And customer has no addresses then create customer address - // with the details of first hotel which rooms he has in cart - if (!Configuration::get('PS_CUSTOMER_ADDRESS_CREATION') - && isset($this->context->cart->id) - && $this->context->cart->id - ) { - if (Module::isInstalled('hotelreservationsystem')) { - include_once _PS_MODULE_DIR_.'hotelreservationsystem/define.php'; - $objHtlCart = new HotelCartBookingData(); - if ($htlCartInfo = $objHtlCart->getCartCurrentDataByCartId($this->context->cart->id)) { - if (isset($htlCartInfo[0]['id_hotel']) && ($idHotel = $htlCartInfo[0]['id_hotel'])) { - if ($address_info = HotelBranchInformation::getAddress($idHotel)) { - $_POST['lastname'] = Tools::getValue('customer_lastname'); - $_POST['firstname'] = Tools::getValue('customer_firstname'); - $_POST['address1'] = $address_info['address1']; - $_POST['city'] = $address_info['city']; - $_POST['postcode'] = $address_info['postcode']; - $_POST['alias'] = 'My address'; - $_POST['id_country'] = $address_info['id_country']; - $_POST['id_state'] = $address_info['id_state']; - $_POST['auto_generated'] = true; - // if form is shorter then address name will be customer name - $lastnameAddress = $_POST['lastname']; - $firstnameAddress = $_POST['firstname']; - } - } - } - } - } - // End $this->errors = array_unique(array_merge($this->errors, $customer->validateController())); // Check the requires fields which are settings in the BO @@ -576,7 +549,7 @@ class AuthControllerCore extends FrontController } if ($country->need_identification_number) { - if (!Configuration::get('PS_CUSTOMER_ADDRESS_CREATION')) { + if (!Configuration::get('PS_REGISTRATION_PROCESS_TYPE')) { $$addresses_type->dni = null; } elseif (!Tools::getValue('dni') || !Validate::isDniLite(Tools::getValue('dni'))) { $this->errors[] = Tools::displayError('The identification number is incorrect or has already been used.'); diff --git a/controllers/front/CartController.php b/controllers/front/CartController.php index 25ed52255..6485da946 100644 --- a/controllers/front/CartController.php +++ b/controllers/front/CartController.php @@ -347,10 +347,10 @@ class CartControllerCore extends FrontController if (!count($this->errors)) { foreach($occupancy as $key => $roomOccupancy) { if ($roomOccupancy['adults'] > $roomTypeInfo['max_adults']) { - $this->errors[] = sprintf(Tools::displayError('Room %s cannot have adults more than %s'), $key + 1, $roomTypeInfo['max_adults']); + $this->errors[] = sprintf(Tools::displayError('Room %s cannot have adults more than %s adults'), $key + 1, $roomTypeInfo['max_adults']); } if ($roomOccupancy['children'] > $roomTypeInfo['max_children']) { - $this->errors[] = sprintf(Tools::displayError('Room %s cannot have children more than %s'), $key + 1, $roomTypeInfo['max_children']); + $this->errors[] = sprintf(Tools::displayError('Room %s cannot have children more than %s children'), $key + 1, $roomTypeInfo['max_children']); } if ($roomOccupancy['adults'] + $roomOccupancy['children'] > $roomTypeInfo['max_guests']) { $this->errors[] = sprintf(Tools::displayError('Room %s cannot have total guests more than %s'), $key + 1, $roomTypeInfo['max_guests']); @@ -373,7 +373,6 @@ class CartControllerCore extends FrontController $this->errors[] = Tools::displayError('You can\'t book room after date '.$maxOrdDate); } } - if (!$this->errors) { $objBookingDetail = new HotelBookingDetail(); $num_days = $objBookingDetail->getNumberOfDays($date_from, $date_to); diff --git a/controllers/front/OrderOpcController.php b/controllers/front/OrderOpcController.php index 7b0ca74e3..465c6a7ca 100644 --- a/controllers/front/OrderOpcController.php +++ b/controllers/front/OrderOpcController.php @@ -496,7 +496,7 @@ class OrderOpcControllerCore extends ParentOrderController // 'allDemands' => $allDemands, // 'defaultcurrencySign' => $objCurrency->sign, 'THEME_DIR' => _THEME_DIR_, - 'PS_CUSTOMER_ADDRESS_CREATION' => Configuration::get('PS_CUSTOMER_ADDRESS_CREATION'), + 'PS_REGISTRATION_PROCESS_TYPE' => Configuration::get('PS_REGISTRATION_PROCESS_TYPE'), 'PS_ROOM_PRICE_AUTO_ADD_BREAKDOWN' => Configuration::get('PS_ROOM_PRICE_AUTO_ADD_BREAKDOWN'), 'free_shipping' => $free_shipping, 'isGuest' => isset($this->context->cookie->is_guest) ? $this->context->cookie->is_guest : 0, @@ -767,9 +767,6 @@ class OrderOpcControllerCore extends ParentOrderController } $address_delivery = new Address($this->context->cart->id_address_delivery); $address_invoice = ($this->context->cart->id_address_delivery == $this->context->cart->id_address_invoice ? $address_delivery : new Address($this->context->cart->id_address_invoice)); - if (!$this->context->cart->id_address_delivery || !$this->context->cart->id_address_invoice || !Validate::isLoadedObject($address_delivery) || !Validate::isLoadedObject($address_invoice) || $address_invoice->deleted || $address_delivery->deleted) { - return '

'.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 @@ 1 + + + 1 + + + 0 diff --git a/js/admin/normal_products.js b/js/admin/normal_products.js index e602d75f1..c01ff7832 100644 --- a/js/admin/normal_products.js +++ b/js/admin/normal_products.js @@ -498,7 +498,25 @@ product_tabs['Informations'] = new function(){ $('#max_quantity_container').show('fast'); } } + toggleAutoAddWithRoomNotice(); }); + + $('#price_addition_type').on('change', function () { + toggleAutoAddWithRoomNotice(); + }); + + function toggleAutoAddWithRoomNotice() + { + if ($('#auto_add_to_cart_on').prop('checked') + && $('#price_addition_type').val() == price_addition_type_with_room + ) { + $('.hide_on_auto_add_Withroom').hide(); + $('.show_on_auto_add_Withroom').show(); + } else { + $('.hide_on_auto_add_Withroom').show(); + $('.show_on_auto_add_Withroom').hide(); + } + } } this.bindTagImage = function (){ diff --git a/js/admin/orders.js b/js/admin/orders.js index 299a9ece0..85e42020e 100644 --- a/js/admin/orders.js +++ b/js/admin/orders.js @@ -557,46 +557,98 @@ function initProductEvents() }); $(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()); }); - - if ($(this).hasClass('num_children')) { - var 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 = '

'; - 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 = '
'; - childAgeSelect += ''; - childAgeSelect += '
'; - $(this).closest('.occupancy_info_block').find('.children_ages').append(childAgeSelect); + 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(); - } - }); - if (child == 0) { - $(this).closest('.occupancy_info_block').find('.children_age_info_block').hide(); - } - + } 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; } } - setRoomTypeGuestOccupancy($(this).closest('.booking_occupancy_wrapper')); + if (!haserror) { + 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 = '
'; + 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', function(e) { $(this).parent().toggleClass('open'); }); diff --git a/modules/hotelreservationsystem/views/templates/admin/hotel_rooms_booking/helpers/view/_partials/booking-rooms.tpl b/modules/hotelreservationsystem/views/templates/admin/hotel_rooms_booking/helpers/view/_partials/booking-rooms.tpl index a33483217..20013d8d0 100644 --- a/modules/hotelreservationsystem/views/templates/admin/hotel_rooms_booking/helpers/view/_partials/booking-rooms.tpl +++ b/modules/hotelreservationsystem/views/templates/admin/hotel_rooms_booking/helpers/view/_partials/booking-rooms.tpl @@ -115,6 +115,7 @@ ({l s='Below'} {$max_child_age|escape:'htmlall':'UTF-8'} {l s='years' mod='hotelreservationsystem'})
+

+

+

+

+
@@ -186,6 +188,7 @@

({l s='Below' mod='wkroomsearchblock'} {$max_child_age|escape:'htmlall':'UTF-8'} {l s='years' mod='wkroomsearchblock'})

+

diff --git a/pdf/invoice.addresses-tab.tpl b/pdf/invoice.addresses-tab.tpl index 1e17a445e..d4d9f0701 100644 --- a/pdf/invoice.addresses-tab.tpl +++ b/pdf/invoice.addresses-tab.tpl @@ -22,6 +22,7 @@ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA *} +{if $invoice_address}