From 4a7f85e6a334ed47f409dfcfbc0da64a05e38b21 Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Fri, 3 Nov 2023 18:17:42 +0530 Subject: [PATCH 1/4] auto add services with add price with room type will have tax rule same as room type --- .../controllers/normal_products/prices.tpl | 4 +-- .../controllers/products/serviceproduct.tpl | 28 +++++++++++-------- classes/Product.php | 17 ++++++----- .../admin/AdminNormalProductsController.php | 6 ++++ controllers/admin/AdminProductsController.php | 5 +++- .../classes/RoomTypeServiceProductPrice.php | 23 +++++++++++---- 6 files changed, 53 insertions(+), 30 deletions(-) diff --git a/admin/themes/default/template/controllers/normal_products/prices.tpl b/admin/themes/default/template/controllers/normal_products/prices.tpl index 9b91f7206..269ef84af 100644 --- a/admin/themes/default/template/controllers/normal_products/prices.tpl +++ b/admin/themes/default/template/controllers/normal_products/prices.tpl @@ -139,7 +139,7 @@ $(document).ready(function () { -
+
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/products/serviceproduct.tpl b/admin/themes/default/template/controllers/products/serviceproduct.tpl index 668c5e0d6..f606dd275 100644 --- a/admin/themes/default/template/controllers/products/serviceproduct.tpl +++ b/admin/themes/default/template/controllers/products/serviceproduct.tpl @@ -55,18 +55,22 @@
{l s='Default price: %s' sprintf={displayPrice price=$service_product.default_price currency=$currency->id}} - {if isset($service_product.tax_rules_group_name) && $service_product.tax_rules_group_name}{$service_product.tax_rules_group_name}{else}{$service_product.default_tax_rules_group_name}{/if} - -
{l s='Default tax rule: %s' sprintf=$service_product.default_tax_rules_group_name} + {if $service_product.auto_add_to_cart && $service_product.price_addition_type == Product::PRICE_ADDITION_TYPE_WITH_ROOM} + {l s='-'} + {else} + {if isset($service_product.tax_rules_group_name) && $service_product.tax_rules_group_name}{$service_product.tax_rules_group_name}{else}{$service_product.default_tax_rules_group_name}{/if} + +
{l s='Default tax rule: %s' sprintf=$service_product.default_tax_rules_group_name} + {/if} diff --git a/classes/Product.php b/classes/Product.php index 9af80ed4f..44b16ae67 100644 --- a/classes/Product.php +++ b/classes/Product.php @@ -2997,7 +2997,7 @@ public static function getCover($id_product, Context $context = null) 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(); @@ -3063,9 +3063,9 @@ public static function getPriceStatic($id_product, $usetax = true, $id_product_a 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); @@ -3119,7 +3119,7 @@ public static function getPriceStatic($id_product, $usetax = true, $id_product_a $use_customer_price, $id_cart, $cart_quantity, - $id_roomtype + $id_product_roomtype ); return $return; @@ -3153,9 +3153,8 @@ public static function getPriceStatic($id_product, $usetax = true, $id_product_a **/ 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; @@ -3182,7 +3181,7 @@ public static function priceCalculation($id_shop, $id_product, $id_product_attri $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( @@ -3246,10 +3245,10 @@ public static function priceCalculation($id_shop, $id_product, $id_product_attri $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/controllers/admin/AdminNormalProductsController.php b/controllers/admin/AdminNormalProductsController.php index b9c184cdc..728bd0ec8 100644 --- a/controllers/admin/AdminNormalProductsController.php +++ b/controllers/admin/AdminNormalProductsController.php @@ -1898,6 +1898,12 @@ public function processUpdate() // 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/AdminProductsController.php b/controllers/admin/AdminProductsController.php index 542c4bdb6..8be3ba093 100644 --- a/controllers/admin/AdminProductsController.php +++ b/controllers/admin/AdminProductsController.php @@ -1162,7 +1162,9 @@ public function ajaxProcessUpdatedServiceProductPrice() } $objRoomTypeServiceProductPrice->price = $price; - $objRoomTypeServiceProductPrice->id_tax_rules_group = $id_tax_rules_group; + if ($id_tax_rules_group) { + $objRoomTypeServiceProductPrice->id_tax_rules_group = $id_tax_rules_group; + } if (!$objRoomTypeServiceProductPrice->save()) { $error = $this->l('Unable to save price, please try again.'); @@ -2843,6 +2845,7 @@ public function initFormServiceProduct($obj) $serviceProduct['id_product'] = $product->id; $serviceProduct['name'] = $product->name; $serviceProduct['auto_add_to_cart'] = $product->auto_add_to_cart; + $serviceProduct['price_addition_type'] = $product->price_addition_type; $serviceProduct['category'] = $product->category; $serviceProduct['default_price'] = $product->price; $serviceProduct['id_tax_rules_group'] = $product->id_tax_rules_group; diff --git a/modules/hotelreservationsystem/classes/RoomTypeServiceProductPrice.php b/modules/hotelreservationsystem/classes/RoomTypeServiceProductPrice.php index ea8879f6e..7dcc50da7 100644 --- a/modules/hotelreservationsystem/classes/RoomTypeServiceProductPrice.php +++ b/modules/hotelreservationsystem/classes/RoomTypeServiceProductPrice.php @@ -65,12 +65,23 @@ public static function deleteRoomProductPrices($idProduct, $elementType = 0) 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_price` spp ON (spp.`id_product` = p.`id_product`) + WHERE p.`id_product`='.(int)$idProduct. + ' AND spp.`id_element`='.(int)$idElement. + ' AND spp.`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) From 4d34a55a576b630074c26d1bfaba2a90d228df39 Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Wed, 24 Jan 2024 16:37:36 +0530 Subject: [PATCH 2/4] fix incorrect service product tax when room type wise price are not set --- .../classes/RoomTypeServiceProductPrice.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/hotelreservationsystem/classes/RoomTypeServiceProductPrice.php b/modules/hotelreservationsystem/classes/RoomTypeServiceProductPrice.php index 7dcc50da7..b329a4e0c 100644 --- a/modules/hotelreservationsystem/classes/RoomTypeServiceProductPrice.php +++ b/modules/hotelreservationsystem/classes/RoomTypeServiceProductPrice.php @@ -68,10 +68,11 @@ public static function getProductRoomTypePriceAndTax($idProduct, $idElement, $el 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 spp.`id_element`='.(int)$idElement. - ' AND spp.`element_type`='.(int)$elementType) + ' 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 From 5476695238f9122cb1b2e12346b255af5555e9d7 Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Wed, 13 Mar 2024 19:16:58 +0530 Subject: [PATCH 3/4] added service tax rule info note --- .../template/controllers/normal_products/prices.tpl | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/admin/themes/default/template/controllers/normal_products/prices.tpl b/admin/themes/default/template/controllers/normal_products/prices.tpl index 269ef84af..a37732305 100644 --- a/admin/themes/default/template/controllers/normal_products/prices.tpl +++ b/admin/themes/default/template/controllers/normal_products/prices.tpl @@ -139,6 +139,15 @@ $(document).ready(function () {
+ {if $product->auto_add_to_cart && $product->price_addition_type == Product::PRICE_ADDITION_TYPE_WITH_ROOM} +
+
+
+ {l s='This current service price is added to room price so room type tax rule will be applied on this service product'} +
+
+
+ {/if}
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"}
- {if $product->auto_add_to_cart && $product->price_addition_type == Product::PRICE_ADDITION_TYPE_WITH_ROOM} -
-
-
- {l s='This current service price is added to room price so room type tax rule 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}> +
+
+ {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'}
- {/if} -
auto_add_to_cart && $product->price_addition_type == Product::PRICE_ADDITION_TYPE_WITH_ROOM}style="display:none"{/if}> +
+
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}> +
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/js/admin/normal_products.js b/js/admin/normal_products.js index e15945f8b..116cd8032 100644 --- a/js/admin/normal_products.js +++ b/js/admin/normal_products.js @@ -499,7 +499,25 @@ product_tabs['Informations'] = new function(){ $("#allow_multiple_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 (){