Skip to content

Commit

Permalink
Merge pull request #871 from shreesh-webkul/gli-1659
Browse files Browse the repository at this point in the history
Updated: Tax of room type will be applied  to auto add services having "price added to room price"
  • Loading branch information
rohit053 authored Mar 17, 2024
2 parents 2909966 + ff84c47 commit 0e675bb
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,14 @@ $(document).ready(function () {
</div>
</div>
</div>
<div class="form-group">
<div class="form-group {if $product->auto_add_to_cart && $product->price_addition_type == Product::PRICE_ADDITION_TYPE_WITH_ROOM}show_on_auto_add_Withroom{/if}" {if !$product->auto_add_to_cart || $product->price_addition_type != Product::PRICE_ADDITION_TYPE_WITH_ROOM}style="display:none"{/if}>
<div class="col-lg-9 col-lg-offset-3">
<div class="alert alert-info">
{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'}
</div>
</div>
</div>
<div class="form-group {if $product->auto_add_to_cart && $product->price_addition_type == Product::PRICE_ADDITION_TYPE_WITH_ROOM}hide_on_auto_add_Withroom{/if}" {if $product->auto_add_to_cart && $product->price_addition_type == Product::PRICE_ADDITION_TYPE_WITH_ROOM}style="display:none"{/if}>
<div class="col-lg-1"><span class="pull-right">{include file="controllers/products/multishop/checkbox.tpl" field="id_tax_rules_group" type="default"}</span></div>
<label class="control-label col-lg-2" for="id_tax_rules_group">
{l s='Tax rule:'}
Expand Down Expand Up @@ -193,7 +200,7 @@ $(document).ready(function () {
<input maxlength="27" id="ecotax" name="ecotax" type="text" value="{$product->ecotax|string_format:$priceDisplayPrecisionFormat}" onkeyup="$('#priceType').val('TI');if (isArrowKey(event))return; calcPriceTE(); this.value = this.value.replace(/,/g, '.'); if (parseInt(this.value) > getE('priceTE').value) this.value = getE('priceTE').value; if (isNaN(this.value)) this.value = 0;" />
</div>
</div>
<div class="form-group" {if !$country_display_tax_label || $tax_exclude_taxe_option}style="display:none;"{/if} >
<div class="form-group {if $product->auto_add_to_cart && $product->price_addition_type == Product::PRICE_ADDITION_TYPE_WITH_ROOM}hide_on_auto_add_Withroom{/if}" {if !$country_display_tax_label || $tax_exclude_taxe_option}style="display:none;"{/if} {if $product->auto_add_to_cart && $product->price_addition_type == Product::PRICE_ADDITION_TYPE_WITH_ROOM}style="display:none"{/if}>
<label class="control-label col-lg-3" for="priceTI">{l s='Retail price with tax'}</label>
<div class="input-group col-lg-2">
<span class="input-group-addon">{$currency->prefix}{$currency->suffix}</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,21 @@
</div>
</td>
<td>
<div class="fixed-width-xl">
<select class="service_product_id_tax_rules_group" name="{$inputs_prefix}id_tax_rules_group">
<option value="0">{l s='No Tax'}</option>
{foreach from=$tax_rules_groups item=tax_rules_group}
<option value="{$tax_rules_group.id_tax_rules_group}" {if $service_product.association_info.id_tax_rules_group == $tax_rules_group.id_tax_rules_group}selected="selected"{/if} >
{$tax_rules_group['name']|htmlentitiesUTF8}
</option>
{/foreach}
</select>
</div>
<div class="help-block">{l s='Default tax rule: %s' sprintf=$service_product.association_info.default_tax_rules_group_name}</div>
{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}
<div class="fixed-width-xl">
<select class="service_product_id_tax_rules_group" name="{$inputs_prefix}id_tax_rules_group">
<option value="0">{l s='No Tax'}</option>
{foreach from=$tax_rules_groups item=tax_rules_group}
<option value="{$tax_rules_group.id_tax_rules_group}" {if $service_product.association_info.id_tax_rules_group == $tax_rules_group.id_tax_rules_group}selected="selected"{/if} >
{$tax_rules_group['name']|htmlentitiesUTF8}
</option>
{/foreach}
</select>
</div>
<div class="help-block">{l s='Default tax rule: %s' sprintf=$service_product.association_info.default_tax_rules_group_name}</div>
{/if}
</td>
</tr>
{/foreach}
Expand Down
17 changes: 8 additions & 9 deletions classes/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -2999,7 +2999,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();
Expand Down Expand Up @@ -3065,9 +3065,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);
Expand Down Expand Up @@ -3121,7 +3121,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;
Expand Down Expand Up @@ -3155,9 +3155,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;

Expand All @@ -3184,7 +3183,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(
Expand Down Expand Up @@ -3248,10 +3247,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
);
}
Expand Down
6 changes: 6 additions & 0 deletions controllers/admin/AdminNormalProductsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1905,6 +1905,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;
Expand Down
5 changes: 4 additions & 1 deletion controllers/admin/AdminProductsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3007,6 +3007,7 @@ public function initFormServiceProduct($obj)
$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;
Expand Down Expand Up @@ -3137,7 +3138,9 @@ public function processServiceProduct()
}

$objRoomTypeServiceProductPrice->price = $price;
$objRoomTypeServiceProductPrice->id_tax_rules_group = $idTaxRulesGroup;
if ($idTaxRulesGroup) {
$objRoomTypeServiceProductPrice->id_tax_rules_group = $idTaxRulesGroup;
}

$objRoomTypeServiceProductPrice->save();
} else {
Expand Down
18 changes: 18 additions & 0 deletions js/admin/normal_products.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,24 @@ public static function deleteRoomProductPrices($idProduct, $elementType = 0, $id

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)
Expand Down

0 comments on commit 0e675bb

Please sign in to comment.