diff --git a/admin/themes/default/template/controllers/orders/helpers/view/view.tpl b/admin/themes/default/template/controllers/orders/helpers/view/view.tpl
index 4218b0515..c00752891 100644
--- a/admin/themes/default/template/controllers/orders/helpers/view/view.tpl
+++ b/admin/themes/default/template/controllers/orders/helpers/view/view.tpl
@@ -880,7 +880,7 @@
{assign var=order_total_price_tax_excl value=($total_rooms_price_tax_excl + $total_room_services_and_demands_tax_excl + $total_products_price_tax_excl)}
{assign var=order_total_price_tax_incl value=($total_rooms_price_tax_incl + $total_room_services_and_demands_tax_incl + $total_products_price_tax_incl)}
- {assign var=total_rooms_tax_only value=(($total_rooms_price_tax_incl - $total_rooms_price_tax_excl) - $tourism_tax_online_room)}
+ {assign var=total_rooms_tax_only value=(($total_rooms_price_tax_incl - $total_rooms_price_tax_excl) - $tourism_tax_room)}
{assign var=total_services_tax_only value=(($total_room_services_and_demands_vat_incl - $total_room_services_and_demands_tax_excl) - ($total_convenience_fee_vat_incl - $total_convenience_fee_tax_excl))}
{assign var=total_convenience_fee_tax_only value=($total_convenience_fee_vat_incl - $total_convenience_fee_tax_excl)}
@@ -966,11 +966,11 @@
{/if}
- {if $tourism_tax_online_room > 0}
+ {if $tourism_tax_room > 0}
{l s='Tourism Tax on Room'}
- {displayPrice price=$tourism_tax_online_room currency=$currency->id}
+ {displayPrice price=$tourism_tax_room currency=$currency->id}
{/if}
@@ -983,11 +983,11 @@
{/if}
- {if $tourism_tax_online_service > 0}
+ {if $tourism_tax_service > 0}
{l s='Tourism Tax on Extra Services'}
- {displayPrice price=$tourism_tax_online_service currency=$currency->id}
+ {displayPrice price=$tourism_tax_service currency=$currency->id}
diff --git a/classes/Cart.php b/classes/Cart.php
index 4b3b90367..aa13c2410 100644
--- a/classes/Cart.php
+++ b/classes/Cart.php
@@ -1549,9 +1549,7 @@ class CartCore extends ObjectModel
$compute_precision = $configuration->get('_PS_PRICE_COMPUTE_PRECISION_');
if (!$this->id) {
- return $type == Cart::ONLY_TOURISM_TAX
- ? array('tourism_tax_online' => 0.0, 'tourism_tax_online_service' => 0.0, 'tourism_tax_online_convenience_fee' => 0.0)
- : 0;
+ return $type == Cart::ONLY_TOURISM_TAX ? array('tourism_tax' => 0.0, 'tourism_tax_room' => 0.0, 'tourism_tax_service' => 0.0, 'tourism_tax_convenience_fee' => 0.0) : 0;
}
$type = (int)$type;
@@ -1642,8 +1640,9 @@ class CartCore extends ObjectModel
$products_total = array();
$ecotax_total = 0;
$tourism_tax_total = 0.0;
- $tourism_tax_online_service = 0.0;
- $tourism_tax_online_convenience_fee = 0.0;
+ $tourism_tax_room = 0.0;
+ $tourism_tax_service = 0.0;
+ $tourism_tax_convenience_fee = 0.0;
$totalDemandsPrice = 0;
$objCartBookingData = new HotelCartBookingData();
$objServiceProductCartDetail = new ServiceProductCartDetail();
@@ -1782,8 +1781,8 @@ class CartCore extends ObjectModel
}
if ($with_taxes && in_array($type, array(Cart::BOTH, Cart::BOTH_WITHOUT_SHIPPING, Cart::ONLY_TOURISM_TAX))) {
- $tourism_tax_total += $servicePorduct['tourism_tax_online'];
- $tourism_tax_online_service += $servicePorduct['tourism_tax_online'];
+ $tourism_tax_total += $servicePorduct['tourism_tax'];
+ $tourism_tax_service += $servicePorduct['tourism_tax'];
}
}
}
@@ -1840,8 +1839,8 @@ class CartCore extends ObjectModel
}
if ($with_taxes && in_array($type, array(Cart::BOTH, Cart::BOTH_WITHOUT_SHIPPING, Cart::ONLY_TOURISM_TAX))) {
- $tourism_tax_total += $servicePorduct['tourism_tax_online'];
- $tourism_tax_online_service += $servicePorduct['tourism_tax_online'];
+ $tourism_tax_total += $servicePorduct['tourism_tax'];
+ $tourism_tax_service += $servicePorduct['tourism_tax'];
}
}
}
@@ -1874,11 +1873,13 @@ class CartCore extends ObjectModel
}
if ($with_taxes && in_array($type, array(Cart::BOTH, Cart::BOTH_WITHOUT_SHIPPING, Cart::ONLY_TOURISM_TAX))) {
- $tourism_tax_total += $service['tourism_tax_online'];
+ $tourism_tax_total += $service['tourism_tax'];
if ($product['auto_add_to_cart'] && Product::PRICE_ADDITION_TYPE_INDEPENDENT == $product['price_addition_type']) {
- $tourism_tax_online_convenience_fee += $service['tourism_tax_online'];
+ $tourism_tax_convenience_fee += $service['tourism_tax'];
+ } elseif ($product['auto_add_to_cart'] && Product::PRICE_ADDITION_TYPE_WITH_ROOM == $product['price_addition_type']) {
+ $tourism_tax_room += $service['tourism_tax'];
} else {
- $tourism_tax_online_service += $service['tourism_tax_online'];
+ $tourism_tax_service += $service['tourism_tax'];
}
}
}
@@ -1937,7 +1938,26 @@ class CartCore extends ObjectModel
}
if ($with_taxes && in_array($type, array(Cart::BOTH, Cart::BOTH_WITHOUT_SHIPPING, Cart::ONLY_TOURISM_TAX))) {
- $tourism_tax_total += $roomTotalPrice['tourism_tax_online'];
+ if ($idTourismTaxRulesGroup = Product::getIdTourismTaxRulesGroupByIdProduct((int) $cartRoomInfo['id_product'])) {
+ $roomAddress = new Address((int) HotelRoomType::getHotelIdAddressByIdProduct($cartRoomInfo['id_product']));
+ $hotelBranch = new HotelBranchInformation((int) $roomAddress->id_hotel);
+ $numNights = max(1, (int) HotelHelper::getNumberOfDays($cartRoomInfo['date_from'], $cartRoomInfo['date_to']));
+ $unitPriceTe = (float) $roomTotalPrice['total_price_tax_excl'] / $numNights;
+ $childAges = !empty($occupancy[0]['child_ages']) ? (array) $occupancy[0]['child_ages'] : array();
+ $roomTaxCalculator = TaxManagerFactory::getManager($roomAddress, $idTourismTaxRulesGroup)->getTaxCalculator();
+ $roomTourismTax = $roomTaxCalculator->getTaxesTotalAmount(
+ $unitPriceTe,
+ $cartRoomInfo['date_from'],
+ $numNights,
+ $occupancy[0]['adults'],
+ $childAges,
+ (int) $hotelBranch->tourism_tax_collection_type,
+ 1,
+ (int) $this->id_currency
+ );
+ $tourism_tax_total += $roomTourismTax;
+ $tourism_tax_room += $roomTourismTax;
+ }
}
}
}
@@ -1949,9 +1969,10 @@ class CartCore extends ObjectModel
if ($type == Cart::ONLY_TOURISM_TAX) {
return array(
- 'tourism_tax_online' => $tourism_tax_total,
- 'tourism_tax_online_service' => $tourism_tax_online_service,
- 'tourism_tax_online_convenience_fee' => $tourism_tax_online_convenience_fee,
+ 'tourism_tax' => $tourism_tax_total,
+ 'tourism_tax_room' => $tourism_tax_room,
+ 'tourism_tax_service' => $tourism_tax_service,
+ 'tourism_tax_convenience_fee' => $tourism_tax_convenience_fee,
);
}
@@ -3985,14 +4006,14 @@ class CartCore extends ObjectModel
}
$tourismTaxTotals = $this->getOrderTotal(true, Cart::ONLY_TOURISM_TAX);
- $tourism_tax_online = $tourismTaxTotals['tourism_tax_online'];
- $tourism_tax_online_convenience_fee = $tourismTaxTotals['tourism_tax_online_convenience_fee'];
- $tourism_tax_online_service = $tourismTaxTotals['tourism_tax_online_service'];
- $tourism_tax_online_room = $tourism_tax_online - $tourism_tax_online_service - $tourism_tax_online_convenience_fee;
+ $tourism_tax = $tourismTaxTotals['tourism_tax'];
+ $tourism_tax_convenience_fee = $tourismTaxTotals['tourism_tax_convenience_fee'];
+ $tourism_tax_service = $tourismTaxTotals['tourism_tax_service'];
+ $tourism_tax_room = $tourismTaxTotals['tourism_tax_room'];
- $roomGrossUpAmount = TourismTax::isGrossedUp($tourism_tax_online_room) ? $tourism_tax_online_room : 0.0;
- $serviceGrossUpAmount = TourismTax::isGrossedUp($tourism_tax_online_service) ? $tourism_tax_online_service : 0.0;
- $convenienceFeeGrossUpAmount = TourismTax::isGrossedUp($tourism_tax_online_convenience_fee) ? $tourism_tax_online_convenience_fee : 0.0;
+ $roomGrossUpAmount = TaxConfiguration::isGrossedUp($tourism_tax_room) ? $tourism_tax_room : 0.0;
+ $serviceGrossUpAmount = TaxConfiguration::isGrossedUp($tourism_tax_service) ? $tourism_tax_service : 0.0;
+ $convenienceFeeGrossUpAmount = TaxConfiguration::isGrossedUp($tourism_tax_convenience_fee) ? $tourism_tax_convenience_fee : 0.0;
$total_rooms_wt += $roomGrossUpAmount;
$total_additional_services_wt += $serviceGrossUpAmount;
$convenience_fee_wt += $convenienceFeeGrossUpAmount;
@@ -4044,9 +4065,9 @@ class CartCore extends ObjectModel
'cart_total_without_discount_te' => $cart_total_without_discount_te,
'cart_total_without_discount_ti' => $cart_total_without_discount_ti,
'total_tax_without_discount' => $total_tax_without_discount,
- 'tourism_tax_online' => max(0.0, (float) $tourism_tax_online),
- 'total_tourism_tax' => max(0.0, (float) $tourism_tax_online),
- 'tourism_tax_grossed_up' => TourismTax::isGrossedUp($tourism_tax_online),
+ 'tourism_tax' => max(0.0, (float) $tourism_tax),
+ 'total_tourism_tax' => max(0.0, (float) $tourism_tax),
+ 'tourism_tax_grossed_up' => TaxConfiguration::isGrossedUp($tourism_tax),
);
$hook = Hook::exec('actionCartSummary', $summary, null, true);
if (is_array($hook)) {
diff --git a/classes/PaymentModule.php b/classes/PaymentModule.php
index 6c95943b2..22cff5476 100644
--- a/classes/PaymentModule.php
+++ b/classes/PaymentModule.php
@@ -904,17 +904,16 @@ abstract class PaymentModuleCore extends Module
}
}
if ($objBookingDetail->save()) {
+ OrderTaxDetail::updateVatScoping((int) $id_order_detail, (int) $objBookingDetail->id, 0);
+
if ($useTourismTax && ($idTourismTaxRulesGroup = Product::getIdTourismTaxRulesGroupByIdProduct($idProduct))) {
- $hotelTaxContext = TourismTax::resolveHotelAddressAndCollectionType(
- (int) $objCartBookingData->id_hotel,
- new Address((int) Cart::getIdAddressForTaxCalculation($idProduct))
- );
+ $hotelTaxContext = TaxConfiguration::resolveHotelAddressAndCollectionType($objCartBookingData->id_hotel, new Address((int) Cart::getIdAddressForTaxCalculation($idProduct)));
$numNights = max(1, (int) HotelHelper::getNumberOfDays($objBookingDetail->date_from, $objBookingDetail->date_to));
$numAdults = (int) $objCartBookingData->adults;
$childAges = !empty($objCartBookingData->child_ages) ? (array) json_decode($objCartBookingData->child_ages, true) : array();
$unitPriceTaxExcl = (float) $total_price['total_price_tax_excl'] / $numNights;
- OrderTourismTax::saveTourismTax(
+ OrderTaxDetail::saveTourismTax(
$idTourismTaxRulesGroup,
$hotelTaxContext['address'],
$unitPriceTaxExcl,
@@ -929,8 +928,7 @@ abstract class PaymentModuleCore extends Module
$order->id,
(int) $id_order_detail,
$objBookingDetail->id,
- 0,
- (int) $objCartBookingData->id_hotel
+ 0
);
}
@@ -1034,9 +1032,11 @@ abstract class PaymentModuleCore extends Module
$objServiceProductOrderDetail->quantity = $roomTypeService['quantity'];
$objServiceProductOrderDetail->auto_added = $product['auto_add_to_cart'];
if ($objServiceProductOrderDetail->save()) {
+ OrderTaxDetail::updateVatScoping((int) $objServiceProductOrderDetail->id_order_detail, 0, (int) $objServiceProductOrderDetail->id);
+
if ($useTourismTax && ($idTourismTaxRulesGroup = Product::getIdTourismTaxRulesGroupByIdProduct($idProduct))) {
- $tourismTaxContext = TourismTax::resolveServiceLineTaxContext($roomBookingDetail['id_hotel'], $roomBookingDetail['id'], new Address((int) Cart::getIdAddressForTaxCalculation($idProduct)));
- OrderTourismTax::saveTourismTax(
+ $tourismTaxContext = TaxConfiguration::resolveServiceLineTaxContext($roomBookingDetail['id_hotel'], $roomBookingDetail['id'], new Address((int) Cart::getIdAddressForTaxCalculation($idProduct)));
+ OrderTaxDetail::saveTourismTax(
$idTourismTaxRulesGroup,
$tourismTaxContext['address'],
(float) $objServiceProductOrderDetail->unit_price_tax_excl,
@@ -1051,8 +1051,7 @@ abstract class PaymentModuleCore extends Module
$order->id,
(int) $objServiceProductOrderDetail->id_order_detail,
0,
- (int) $objServiceProductOrderDetail->id,
- (int) $roomBookingDetail['id_hotel']
+ (int) $objServiceProductOrderDetail->id
);
}
}
@@ -1089,9 +1088,11 @@ abstract class PaymentModuleCore extends Module
}
$objServiceProductOrderDetail->quantity = $hotelProduct['quantity'];
if ($objServiceProductOrderDetail->save()) {
+ OrderTaxDetail::updateVatScoping((int) $objServiceProductOrderDetail->id_order_detail, 0, (int) $objServiceProductOrderDetail->id);
+
if ($useTourismTax && ($idTourismTaxRulesGroup = Product::getIdTourismTaxRulesGroupByIdProduct($idProduct))) {
- $tourismTaxContext = TourismTax::resolveServiceLineTaxContext($product['id_hotel'], 0, new Address((int) Cart::getIdAddressForTaxCalculation($idProduct)));
- OrderTourismTax::saveTourismTax(
+ $tourismTaxContext = TaxConfiguration::resolveServiceLineTaxContext($product['id_hotel'], 0, new Address((int) Cart::getIdAddressForTaxCalculation($idProduct)));
+ OrderTaxDetail::saveTourismTax(
$idTourismTaxRulesGroup,
$tourismTaxContext['address'],
(float) $objServiceProductOrderDetail->unit_price_tax_excl,
@@ -1106,8 +1107,7 @@ abstract class PaymentModuleCore extends Module
$order->id,
(int) $objServiceProductOrderDetail->id_order_detail,
0,
- (int) $objServiceProductOrderDetail->id,
- (int) $product['id_hotel']
+ (int) $objServiceProductOrderDetail->id
);
}
}
@@ -1139,9 +1139,11 @@ abstract class PaymentModuleCore extends Module
$objServiceProductOrderDetail->option_name = $standaloneProduct['option_name'];
$objServiceProductOrderDetail->quantity = $standaloneProduct['quantity'];
if ($objServiceProductOrderDetail->save()) {
+ OrderTaxDetail::updateVatScoping((int) $objServiceProductOrderDetail->id_order_detail, 0, (int) $objServiceProductOrderDetail->id);
+
if ($useTourismTax && ($idTourismTaxRulesGroup = Product::getIdTourismTaxRulesGroupByIdProduct($idProduct))) {
- $tourismTaxContext = TourismTax::resolveServiceLineTaxContext(0, 0, new Address((int) Cart::getIdAddressForTaxCalculation($idProduct)));
- OrderTourismTax::saveTourismTax(
+ $tourismTaxContext = TaxConfiguration::resolveServiceLineTaxContext(0, 0, new Address((int) Cart::getIdAddressForTaxCalculation($idProduct)));
+ OrderTaxDetail::saveTourismTax(
$idTourismTaxRulesGroup,
$tourismTaxContext['address'],
(float) $objServiceProductOrderDetail->unit_price_tax_excl,
@@ -1156,8 +1158,7 @@ abstract class PaymentModuleCore extends Module
$order->id,
(int) $objServiceProductOrderDetail->id_order_detail,
0,
- (int) $objServiceProductOrderDetail->id,
- 0
+ (int) $objServiceProductOrderDetail->id
);
}
}
@@ -1218,11 +1219,13 @@ abstract class PaymentModuleCore extends Module
$objServiceProductOrderDetail->auto_added = $product['auto_add_to_cart'];
}
if ($objServiceProductOrderDetail->save()) {
+ OrderTaxDetail::updateVatScoping((int) $objServiceProductOrderDetail->id_order_detail, 0, (int) $objServiceProductOrderDetail->id);
+
$idHotel = $serviceProduct['id_hotel'] ? $serviceProduct['id_hotel'] : (isset($roomBookingDetail['id_hotel']) ? (int) $roomBookingDetail['id_hotel'] : 0);
$idHtlBookingDetail = $serviceProduct['id_hotel'] ? 0 : (isset($roomBookingDetail['id']) ? (int) $roomBookingDetail['id'] : 0);
if ($useTourismTax && ($idTourismTaxRulesGroup = Product::getIdTourismTaxRulesGroupByIdProduct($idProduct))) {
- $tourismTaxContext = TourismTax::resolveServiceLineTaxContext($idHotel, $idHtlBookingDetail, new Address((int) Cart::getIdAddressForTaxCalculation($idProduct)));
- OrderTourismTax::saveTourismTax(
+ $tourismTaxContext = TaxConfiguration::resolveServiceLineTaxContext($idHotel, $idHtlBookingDetail, new Address((int) Cart::getIdAddressForTaxCalculation($idProduct)));
+ OrderTaxDetail::saveTourismTax(
$idTourismTaxRulesGroup,
$tourismTaxContext['address'],
(float) $objServiceProductOrderDetail->unit_price_tax_excl,
@@ -1237,8 +1240,7 @@ abstract class PaymentModuleCore extends Module
$order->id,
(int) $objServiceProductOrderDetail->id_order_detail,
0,
- (int) $objServiceProductOrderDetail->id,
- $idHotel
+ (int) $objServiceProductOrderDetail->id
);
}
}
@@ -1377,7 +1379,7 @@ abstract class PaymentModuleCore extends Module
$service_products_tax = ($standalone_products_price_tax_incl + $hotel_standalone_products_price_tax_incl) - ($standalone_products_price_tax_excl + $hotel_standalone_products_price_tax_excl);
- $totalTourismTax = OrderTourismTax::getOrderTourismTaxTotal((int) $order->id);
+ $totalTourismTax = OrderTaxDetail::getOrderTourismTaxTotal((int) $order->id);
$total_order_tax = max(0, $room_tax + $additional_service_tax + $total_convenience_fee_tax + $service_products_tax - $totalTourismTax);
$total_products = Tools::displayPrice(Product::getTaxCalculationMethod() == PS_TAX_EXC ? $order->total_products : $order->total_products_wt, $this->context->currency, false);
diff --git a/classes/Product.php b/classes/Product.php
index 76245cc31..10301fd86 100644
--- a/classes/Product.php
+++ b/classes/Product.php
@@ -6848,21 +6848,24 @@ class ProductCore extends ObjectModel
$idAddress = null,
$useReduc = 1,
$idGroup = null,
- $idCartBooking = 0
+ $idCartBooking = 0,
+ $includeTourismTax = false,
+ $numAdults = null,
+ $childrenAges = null
) {
if ($useTax === null) {
$useTax = Product::$_taxCalculationMethod == PS_TAX_EXC ? false : true;
}
$price = Product::getPriceStatic(
- (int)$idProduct,
+ $idProduct,
$useTax,
$idProductOption,
6,
null,
false,
$useReduc,
- (int)$quantity,
+ $quantity,
false,
null,
$idCart,
@@ -6872,8 +6875,8 @@ class ProductCore extends ObjectModel
true,
null,
true,
- (int)$idHotel,
- (int)$idProductRoomType,
+ $idHotel,
+ $idProductRoomType,
$idGroup,
$idCartBooking
);
@@ -6894,12 +6897,56 @@ class ProductCore extends ObjectModel
)
);
- if (Product::getProductPriceCalculation($idProduct) == Product::PRICE_CALCULATION_METHOD_PER_DAY
- && $dateFrom && $dateTo
- ) {
+ $isPerDay = Product::getProductPriceCalculation($idProduct) == Product::PRICE_CALCULATION_METHOD_PER_DAY
+ && $dateFrom && $dateTo;
+ if ($isPerDay) {
$price = $price * HotelHelper::getNumberOfDays($dateFrom, $dateTo);
}
- return $price * (int)$quantity;
+ $price = $price * $quantity;
+
+ $tourismTaxHotelId = $idHotel;
+ if (!$tourismTaxHotelId && $idProductRoomType) {
+ $objRoomType = new HotelRoomType();
+ if ($roomTypeInfo = $objRoomType->getRoomTypeInfoByIdProduct($idProductRoomType)) {
+ $tourismTaxHotelId = $roomTypeInfo['id_hotel'];
+ }
+ }
+
+ if ($includeTourismTax && $tourismTaxHotelId && ($idTourismTaxRulesGroup = Product::getIdTourismTaxRulesGroupByIdProduct($idProduct))) {
+ $priceCalcNumDays = $isPerDay ? HotelHelper::getNumberOfDays($dateFrom, $dateTo) : 1;
+ $unitPriceExcl = ($useTax ? Product::getServiceProductPrice($idProduct, $idProductOption, $idHotel, $idProductRoomType, false, 1, $dateFrom, $dateTo, $idCart, $idAddress, $useReduc, $idGroup, $idCartBooking) : $price / (int) $quantity) / $priceCalcNumDays;
+
+ $fallbackAddress = new Address(Cart::getIdAddressForTaxCalculation($idProduct));
+ if ($numAdults === null) {
+ // no explicit occupancy override: derive it from the actual booking/cart-booking, same as every order-persistence caller
+ $taxContext = TaxConfiguration::resolveServiceLineTaxContext($tourismTaxHotelId, 0, $fallbackAddress, $idCartBooking);
+ } else {
+ // caller supplied its own occupancy (e.g. a live search form) — use it as-is, only resolve address/collection type
+ $hotelContext = TaxConfiguration::resolveHotelAddressAndCollectionType($tourismTaxHotelId, $fallbackAddress);
+ $taxContext = array(
+ 'address' => $hotelContext['address'],
+ 'collectionType' => $hotelContext['collectionType'],
+ 'checkInDate' => $dateFrom,
+ 'numNights' => max(1, HotelHelper::getNumberOfDays($dateFrom, $dateTo)),
+ 'numAdults' => $numAdults,
+ 'childrenAges' => $childrenAges ?: array(),
+ );
+ }
+
+ // no $idCurrency passed — TaxCalculator::getTaxesAmount() already resolves it from the current context when null
+ $taxCalculator = TaxManagerFactory::getManager($taxContext['address'], $idTourismTaxRulesGroup)->getTaxCalculator();
+ $price += $taxCalculator->getTaxesTotalAmount(
+ $unitPriceExcl,
+ $taxContext['checkInDate'],
+ $taxContext['numNights'],
+ $taxContext['numAdults'],
+ $taxContext['childrenAges'],
+ $taxContext['collectionType'],
+ $quantity
+ );
+ }
+
+ return $price;
}
}
diff --git a/classes/order/Order.php b/classes/order/Order.php
index d69709bc9..4c26fb305 100644
--- a/classes/order/Order.php
+++ b/classes/order/Order.php
@@ -1157,11 +1157,16 @@ class OrderCore extends ObjectModel
$products = $this->getProductsDetail($bookingProducts, $selling_preference_type, $product_auto_add, $product_price_addition_type, $ids_order_detail);
}
+ $tourismTaxByOrderDetail = array();
+ if (!$includeTourismTax && $products) {
+ $tourismTaxByOrderDetail = OrderTaxDetail::getAmountsByOrderDetail((int) $this->id);
+ }
+
$return = 0;
foreach ($products as $row) {
$return += $row['total_price_tax_incl'];
if (!$includeTourismTax) {
- $return -= isset($row['tourism_tax_amount']) ? (float) $row['tourism_tax_amount'] : 0;
+ $return -= isset($tourismTaxByOrderDetail[$row['id_order_detail']]) ? $tourismTaxByOrderDetail[$row['id_order_detail']] : 0;
}
}
@@ -1813,10 +1818,11 @@ class OrderCore extends ObjectModel
// if one of the order details use the tax computation method the display will be different
return Db::getInstance()->getValue('
SELECT od.`tax_computation_method`
- FROM `'._DB_PREFIX_.'order_detail_tax` odt
+ FROM `'._DB_PREFIX_.'order_tax_detail` odt
LEFT JOIN `'._DB_PREFIX_.'order_detail` od ON (od.`id_order_detail` = odt.`id_order_detail`)
WHERE od.`id_order` = '.(int)$this->id.'
- AND od.`tax_computation_method` = '.(int)TaxCalculator::ONE_AFTER_ANOTHER_METHOD
+ AND od.`tax_computation_method` = '.(int)TaxCalculator::ONE_AFTER_ANOTHER_METHOD.'
+ AND NOT EXISTS (SELECT 1 FROM `'._DB_PREFIX_.'tax` tc WHERE tc.`id_tax` = odt.`id_tax` AND tc.`is_tourism_tax` = 1)'
);
}
@@ -2144,61 +2150,6 @@ class OrderCore extends ObjectModel
return $this->update();
}
- /**
- * Returns the correct product taxes breakdown.
- *
- * @since 1.5.0.1
- * @return array
- */
- public function getProductTaxesBreakdown()
- {
- $tmp_tax_infos = array();
- if ($this->useOneAfterAnotherTaxComputationMethod()) {
- // sum by taxes
- $taxes_by_tax = Db::getInstance()->executeS('
- SELECT odt.`id_order_detail`, t.`name`, t.`rate`, SUM(`total_amount`) AS `total_amount`
- FROM `'._DB_PREFIX_.'order_detail_tax` odt
- LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = odt.`id_tax`)
- LEFT JOIN `'._DB_PREFIX_.'order_detail` od ON (od.`id_order_detail` = odt.`id_order_detail`)
- WHERE od.`id_order` = '.(int)$this->id.'
- GROUP BY odt.`id_tax`
- ');
-
- // format response
- $tmp_tax_infos = array();
- foreach ($taxes_by_tax as $tax_infos) {
- $tmp_tax_infos[$tax_infos['rate']]['total_amount'] = $tax_infos['tax_amount'];
- $tmp_tax_infos[$tax_infos['rate']]['name'] = $tax_infos['name'];
- }
- } else {
- // sum by order details in order to retrieve real taxes rate
- $taxes_infos = Db::getInstance()->executeS('
- SELECT odt.`id_order_detail`, t.`rate` AS `name`, SUM(od.`total_price_tax_excl`) AS total_price_tax_excl, SUM(t.`rate`) AS rate, SUM(`total_amount`) AS `total_amount`
- FROM `'._DB_PREFIX_.'order_detail_tax` odt
- LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = odt.`id_tax`)
- LEFT JOIN `'._DB_PREFIX_.'order_detail` od ON (od.`id_order_detail` = odt.`id_order_detail`)
- WHERE od.`id_order` = '.(int)$this->id.'
- GROUP BY odt.`id_order_detail`
- ');
-
- // sum by taxes
- $tmp_tax_infos = array();
- foreach ($taxes_infos as $tax_infos) {
- if (!isset($tmp_tax_infos[$tax_infos['rate']])) {
- $tmp_tax_infos[$tax_infos['rate']] = array('total_amount' => 0,
- 'name' => 0,
- 'total_price_tax_excl' => 0);
- }
-
- $tmp_tax_infos[$tax_infos['rate']]['total_amount'] += $tax_infos['total_amount'];
- $tmp_tax_infos[$tax_infos['rate']]['name'] = $tax_infos['name'];
- $tmp_tax_infos[$tax_infos['rate']]['total_price_tax_excl'] += $tax_infos['total_price_tax_excl'];
- }
- }
-
- return $tmp_tax_infos;
- }
-
/**
* Returns the shipping taxes breakdown
*
@@ -2530,7 +2481,7 @@ class OrderCore extends ObjectModel
} else {
$order_details = $this->getOrderDetailList();
}
- $expected_total_tax = (float)$this->getTotalProductsWithTaxes($limitToOrderDetails) - (float)$this->getTotalProductsWithoutTaxes($limitToOrderDetails);
+ $expected_total_tax = (float)$this->getTotalProductsWithTaxes($limitToOrderDetails, null, null, null, null, [], false) - (float)$this->getTotalProductsWithoutTaxes($limitToOrderDetails);
$order_ecotax_tax = 0;
diff --git a/classes/order/OrderDetail.php b/classes/order/OrderDetail.php
index f4b516f1f..62fe161f1 100644
--- a/classes/order/OrderDetail.php
+++ b/classes/order/OrderDetail.php
@@ -131,9 +131,6 @@ class OrderDetailCore extends ObjectModel
/** @var float */
public $ecotax_tax_rate;
- /** @var float Tourism tax charged online for this order detail line */
- public $tourism_tax_amount = 0;
-
/** @var int */
public $discount_quantity_applied;
@@ -222,7 +219,6 @@ class OrderDetailCore extends ObjectModel
'id_tax_rules_group' => array('type' => self::TYPE_INT, 'validate' => 'isInt'),
'ecotax' => array('type' => self::TYPE_FLOAT, 'validate' => 'isFloat'),
'ecotax_tax_rate' => array('type' => self::TYPE_FLOAT, 'validate' => 'isFloat'),
- 'tourism_tax_amount' => array('type' => self::TYPE_FLOAT, 'validate' => 'isFloat'),
'discount_quantity_applied' => array('type' => self::TYPE_INT, 'validate' => 'isInt'),
'download_hash' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName'),
'download_nb' => array('type' => self::TYPE_INT, 'validate' => 'isInt'),
@@ -296,7 +292,11 @@ class OrderDetailCore extends ObjectModel
return false;
}
- Db::getInstance()->delete('order_detail_tax', 'id_order_detail='.(int)$this->id);
+ Db::getInstance()->execute(
+ 'DELETE otd FROM `'._DB_PREFIX_.'order_tax_detail` otd
+ WHERE otd.`id_order_detail` = '.(int)$this->id.'
+ AND NOT EXISTS (SELECT 1 FROM `'._DB_PREFIX_.'tax` tc WHERE tc.`id_tax` = otd.`id_tax` AND tc.`is_tourism_tax` = 1)'
+ );
return $res;
}
@@ -349,9 +349,10 @@ class OrderDetailCore extends ObjectModel
public static function getTaxCalculatorStatic($id_order_detail)
{
$sql = 'SELECT t.*, d.`tax_computation_method`
- FROM `'._DB_PREFIX_.'order_detail_tax` t
+ FROM `'._DB_PREFIX_.'order_tax_detail` t
LEFT JOIN `'._DB_PREFIX_.'order_detail` d ON (d.`id_order_detail` = t.`id_order_detail`)
- WHERE d.`id_order_detail` = '.(int)$id_order_detail;
+ WHERE d.`id_order_detail` = '.(int)$id_order_detail.'
+ AND NOT EXISTS (SELECT 1 FROM `'._DB_PREFIX_.'tax` tc WHERE tc.`id_tax` = t.`id_tax` AND tc.`is_tourism_tax` = 1)';
$computation_method = 1;
$taxes = array();
@@ -516,7 +517,7 @@ class OrderDetailCore extends ObjectModel
$total_amount = Tools::processPriceRounding($amount, $quantity, $order->round_type, $order->round_mode);
- $values .= '('.(int)$this->id.','.(int)$id_tax.','.(float)$amount.','.(float)$total_amount.'),';
+ $values .= '('.(int)$order->id.','.(int)$this->id.',0,0,'.(int)$id_tax.','.(float)$amount.','.(float)$total_amount.',NOW()),';
}
}
}
@@ -550,7 +551,7 @@ class OrderDetailCore extends ObjectModel
$total_amount = Tools::processPriceRounding($amount, $this->product_quantity, $order->round_type, $order->round_mode);
- $values .= '('.(int)$this->id.','.(int)$id_tax.','.(float)$amount.','.(float)$total_amount.'),';
+ $values .= '('.(int)$order->id.','.(int)$this->id.',0,0,'.(int)$id_tax.','.(float)$amount.','.(float)$total_amount.',NOW()),';
}
}
@@ -558,10 +559,15 @@ class OrderDetailCore extends ObjectModel
if ($values) {
if ($replace) {
- Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'order_detail_tax` WHERE id_order_detail='.(int)$this->id);
+ Db::getInstance()->execute(
+ 'DELETE otd FROM `'._DB_PREFIX_.'order_tax_detail` otd
+ WHERE otd.`id_order_detail` = '.(int)$this->id.'
+ AND NOT EXISTS (SELECT 1 FROM `'._DB_PREFIX_.'tax` tc WHERE tc.`id_tax` = otd.`id_tax` AND tc.`is_tourism_tax` = 1)'
+ );
}
- $sql = 'INSERT INTO `'._DB_PREFIX_.'order_detail_tax` (id_order_detail, id_tax, unit_amount, total_amount)
+ $sql = 'INSERT INTO `'._DB_PREFIX_.'order_tax_detail`
+ (id_order, id_order_detail, id_htl_booking, id_service_product_order_detail, id_tax, unit_amount, total_amount, date_add)
VALUES '.$values;
return Db::getInstance()->execute($sql);
@@ -597,8 +603,9 @@ class OrderDetailCore extends ObjectModel
public static function getTaxListStatic($id_order_detail)
{
- $sql = 'SELECT * FROM `'._DB_PREFIX_.'order_detail_tax`
- WHERE `id_order_detail` = '.(int)$id_order_detail;
+ $sql = 'SELECT * FROM `'._DB_PREFIX_.'order_tax_detail` t
+ WHERE t.`id_order_detail` = '.(int)$id_order_detail.'
+ AND NOT EXISTS (SELECT 1 FROM `'._DB_PREFIX_.'tax` tc WHERE tc.`id_tax` = t.`id_tax` AND tc.`is_tourism_tax` = 1)';
return Db::getInstance()->executeS($sql);
}
@@ -905,10 +912,11 @@ class OrderDetailCore extends ObjectModel
public function getWsTaxes()
{
$query = new DbQuery();
- $query->select('id_tax as id');
- $query->from('order_detail_tax', 'tax');
+ $query->select('tax.`id_tax` as id');
+ $query->from('order_tax_detail', 'tax');
$query->leftJoin('order_detail', 'od', 'tax.`id_order_detail` = od.`id_order_detail`');
$query->where('od.`id_order_detail` = '.(int)$this->id_order_detail);
+ $query->where('NOT EXISTS (SELECT 1 FROM `'._DB_PREFIX_.'tax` tc WHERE tc.`id_tax` = tax.`id_tax` AND tc.`is_tourism_tax` = 1)');
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
}
diff --git a/classes/order/OrderInvoice.php b/classes/order/OrderInvoice.php
index ec97d3a57..bbd997756 100644
--- a/classes/order/OrderInvoice.php
+++ b/classes/order/OrderInvoice.php
@@ -323,11 +323,12 @@ class OrderInvoiceCore extends ObjectModel
// if one of the order details use the tax computation method the display will be different
return Db::getInstance()->getValue('
SELECT od.`tax_computation_method`
- FROM `' . _DB_PREFIX_ . 'order_detail_tax` odt
+ FROM `' . _DB_PREFIX_ . 'order_tax_detail` odt
LEFT JOIN `' . _DB_PREFIX_ . 'order_detail` od ON (od.`id_order_detail` = odt.`id_order_detail`)
WHERE od.`id_order` = ' . (int) $this->id_order . '
AND od.`id_order_invoice` = ' . (int) $this->id . '
- AND od.`tax_computation_method` = ' . (int) TaxCalculator::ONE_AFTER_ANOTHER_METHOD)
+ AND od.`tax_computation_method` = ' . (int) TaxCalculator::ONE_AFTER_ANOTHER_METHOD . '
+ AND NOT EXISTS (SELECT 1 FROM `' . _DB_PREFIX_ . 'tax` tc WHERE tc.`id_tax` = odt.`id_tax` AND tc.`is_tourism_tax` = 1)')
|| Configuration::get('PS_INVOICE_TAXES_BREAKDOWN');
}
@@ -867,7 +868,7 @@ class OrderInvoiceCore extends ObjectModel
*/
public function getTourismTaxBreakdown()
{
- return OrderTourismTax::getBreakdownForInvoice((int) $this->id_order);
+ return OrderTaxDetail::getBreakdownForInvoice((int) $this->id_order);
}
/**
diff --git a/classes/order/OrderReturn.php b/classes/order/OrderReturn.php
index 6e0fcf5dc..daba4e55d 100644
--- a/classes/order/OrderReturn.php
+++ b/classes/order/OrderReturn.php
@@ -211,8 +211,8 @@ class OrderReturnCore extends ObjectModel
$calcServicePriceFirst = true;
}
- $appliedTourismTaxByBooking = OrderTourismTax::getAppliedTourismTaxTotals($idOrder, OrderTourismTax::SCOPE_ROOM);
- $appliedServiceTourismTaxByBooking = OrderTourismTax::getAppliedTourismTaxTotals($idOrder, OrderTourismTax::SCOPE_SERVICE);
+ $appliedTourismTaxByBooking = OrderTaxDetail::getAppliedTourismTaxTotals($idOrder, OrderTaxDetail::SCOPE_ROOM);
+ $appliedServiceTourismTaxByBooking = OrderTaxDetail::getAppliedTourismTaxTotals($idOrder, OrderTaxDetail::SCOPE_SERVICE);
foreach ($returnDetails as $key => &$bookingRow) {
if ($skipReqCompletedNonRefunded) {
diff --git a/classes/tourismtax/OrderTourismTax.php b/classes/order/OrderTaxDetail.php
similarity index 75%
rename from classes/tourismtax/OrderTourismTax.php
rename to classes/order/OrderTaxDetail.php
index d153aabdf..1651e8771 100644
--- a/classes/tourismtax/OrderTourismTax.php
+++ b/classes/order/OrderTaxDetail.php
@@ -21,7 +21,7 @@
* @license https://opensource.org/license/osl-3-0-php Open Software License version 3.0
*/
-class OrderTourismTaxCore extends ObjectModel
+class OrderTaxDetailCore extends ObjectModel
{
const STATUS_NONE = 0;
const STATUS_APPLIED = 1;
@@ -29,7 +29,6 @@ class OrderTourismTaxCore extends ObjectModel
const APPLY_OK = 0;
const APPLY_ERROR_RESTORE = 1;
- const APPLY_ERROR_NO_RULE = 2;
const APPLY_ERROR_REFUNDED = 3;
const EXEMPT_OK = 0;
@@ -41,38 +40,31 @@ class OrderTourismTaxCore extends ObjectModel
const SCOPE_ROOM_STATUS = 1;
const SCOPE_SERVICE = 2;
- public $id_order_tourism_tax;
+ const SCOPE_COLUMN_ROOM = 'id_htl_booking';
+ const SCOPE_COLUMN_SERVICE = 'id_service_product_order_detail';
+
+ public $id_order_tax_detail;
public $id_order;
public $id_order_detail;
public $id_htl_booking;
public $id_service_product_order_detail;
- public $id_hotel;
public $id_tax;
- public $id_currency;
- public $num_nights;
- public $num_adults;
+ public $unit_amount;
public $total_amount;
- public $is_refunded;
public $date_add;
- public $date_upd;
public static $definition = array(
- 'table' => 'order_tourism_tax',
- 'primary' => 'id_order_tourism_tax',
+ 'table' => 'order_tax_detail',
+ 'primary' => 'id_order_tax_detail',
'fields' => array(
'id_order' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
'id_order_detail' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
'id_htl_booking' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
'id_service_product_order_detail' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
- 'id_hotel' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
'id_tax' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
- 'id_currency' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
- 'num_nights' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
- 'num_adults' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
+ 'unit_amount' => array('type' => self::TYPE_FLOAT, 'validate' => 'isUnsignedFloat'),
'total_amount' => array('type' => self::TYPE_FLOAT, 'validate' => 'isUnsignedFloat'),
- 'is_refunded' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
- 'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
),
);
@@ -85,7 +77,7 @@ class OrderTourismTaxCore extends ObjectModel
public static function isBookingExempted($idHtlBooking)
{
return (bool) Db::getInstance()->getValue(
- 'SELECT 1 FROM `' . _DB_PREFIX_ . 'order_tourism_tax_exemption`
+ 'SELECT 1 FROM `' . _DB_PREFIX_ . 'order_tax_exemption`
WHERE `id_htl_booking` = ' . (int) $idHtlBooking . '
AND `id_service_product_order_detail` = 0'
);
@@ -100,7 +92,7 @@ class OrderTourismTaxCore extends ObjectModel
public static function isServiceLineExempted($idServiceProductOrderDetail)
{
return (bool) Db::getInstance()->getValue(
- 'SELECT 1 FROM `' . _DB_PREFIX_ . 'order_tourism_tax_exemption`
+ 'SELECT 1 FROM `' . _DB_PREFIX_ . 'order_tax_exemption`
WHERE `id_htl_booking` = 0
AND `id_service_product_order_detail` = ' . (int) $idServiceProductOrderDetail
);
@@ -118,7 +110,7 @@ class OrderTourismTaxCore extends ObjectModel
protected static function deleteExemptionMarker($idHtlBooking, $idServiceProductOrderDetail)
{
return Db::getInstance()->execute(
- 'DELETE FROM `' . _DB_PREFIX_ . 'order_tourism_tax_exemption`
+ 'DELETE FROM `' . _DB_PREFIX_ . 'order_tax_exemption`
WHERE `id_htl_booking` = ' . (int) $idHtlBooking . '
AND `id_service_product_order_detail` = ' . (int) $idServiceProductOrderDetail
);
@@ -136,7 +128,7 @@ class OrderTourismTaxCore extends ObjectModel
public static function getAppliedTourismTaxTotals($idOrder, $scope = self::SCOPE_ROOM)
{
$idOrder = (int) $idOrder;
- $cacheId = 'OrderTourismTax::getAppliedTourismTaxTotals-' . $idOrder . '-' . $scope;
+ $cacheId = 'OrderTaxDetail::getAppliedTourismTaxTotals-' . $idOrder . '-' . $scope;
if (Cache::isStored($cacheId)) {
return Cache::retrieve($cacheId);
}
@@ -144,16 +136,17 @@ class OrderTourismTaxCore extends ObjectModel
$result = array();
if ($scope === self::SCOPE_SERVICE) {
$sql = 'SELECT spod.`id_htl_booking_detail`, SUM(tt.`total_amount`) AS total_amount
- FROM `' . _DB_PREFIX_ . 'order_tourism_tax` tt
+ FROM `' . _DB_PREFIX_ . 'order_tax_detail` tt
+ INNER JOIN `' . _DB_PREFIX_ . 'tax` t ON t.`id_tax` = tt.`id_tax` AND t.`is_tourism_tax` = 1
INNER JOIN `' . _DB_PREFIX_ . 'service_product_order_detail` spod
ON spod.`id_service_product_order_detail` = tt.`id_service_product_order_detail`
- LEFT JOIN `' . _DB_PREFIX_ . 'order_tourism_tax_exemption` ex
+ LEFT JOIN `' . _DB_PREFIX_ . 'order_tax_exemption` ex
ON (spod.`id_htl_booking_detail` != 0 AND ex.`id_htl_booking` = spod.`id_htl_booking_detail`)
OR (spod.`id_htl_booking_detail` = 0 AND ex.`id_service_product_order_detail` = tt.`id_service_product_order_detail` AND ex.`id_htl_booking` = 0)
WHERE tt.`id_order` = ' . $idOrder . '
AND spod.`id_htl_booking_detail` != 0
- AND tt.`is_refunded` = 0
- AND ex.`id_exemption` IS NULL
+ AND spod.`is_refunded` = 0
+ AND ex.`id_order_tax_exemption` IS NULL
GROUP BY spod.`id_htl_booking_detail`';
$rows = Db::getInstance()->executeS($sql);
foreach ((array) $rows as $row) {
@@ -162,14 +155,17 @@ class OrderTourismTaxCore extends ObjectModel
} else {
$rows = Db::getInstance()->executeS(
'SELECT tt.`id_htl_booking`,
- SUM(CASE WHEN ex.`id_exemption` IS NULL THEN tt.`total_amount` ELSE 0 END) AS total_amount,
- MAX(CASE WHEN ex.`id_exemption` IS NULL THEN 1 ELSE 0 END) AS applied_count
- FROM `' . _DB_PREFIX_ . 'order_tourism_tax` tt
- LEFT JOIN `' . _DB_PREFIX_ . 'order_tourism_tax_exemption` ex
+ SUM(CASE WHEN ex.`id_order_tax_exemption` IS NULL THEN tt.`total_amount` ELSE 0 END) AS total_amount,
+ MAX(CASE WHEN ex.`id_order_tax_exemption` IS NULL THEN 1 ELSE 0 END) AS applied_count
+ FROM `' . _DB_PREFIX_ . 'order_tax_detail` tt
+ INNER JOIN `' . _DB_PREFIX_ . 'tax` t ON t.`id_tax` = tt.`id_tax` AND t.`is_tourism_tax` = 1
+ LEFT JOIN `' . _DB_PREFIX_ . 'htl_booking_detail` hbd
+ ON hbd.`id` = tt.`id_htl_booking`
+ LEFT JOIN `' . _DB_PREFIX_ . 'order_tax_exemption` ex
ON ex.`id_htl_booking` = tt.`id_htl_booking`
WHERE tt.`id_order` = ' . $idOrder . '
AND tt.`id_htl_booking` != 0
- AND tt.`is_refunded` = 0
+ AND hbd.`is_refunded` = 0
GROUP BY tt.`id_htl_booking`'
);
foreach ((array) $rows as $row) {
@@ -188,56 +184,38 @@ class OrderTourismTaxCore extends ObjectModel
return $result;
}
- /**
- * Mark all rows for a booking as refunded (used on room cancellation).
- *
- * @param int $idHtlBooking
- * @return bool
- */
- public static function setRefundedByHtlBooking($idHtlBooking)
- {
- return self::setRefundedForScope('id_htl_booking', (int) $idHtlBooking);
- }
-
- /**
- * Mark all rows for a service-product order-detail line as refunded (used on service refund).
- *
- * @param int $idServiceProductOrderDetail
- * @return bool
- */
- public static function setRefundedByServiceProductOrderDetail($idServiceProductOrderDetail)
- {
- return self::setRefundedForScope('id_service_product_order_detail', (int) $idServiceProductOrderDetail);
- }
-
- /**
- * Shared core for setRefundedByHtlBooking()/setRefundedByServiceProductOrderDetail().
- *
- * @param string $scopeColumn 'id_htl_booking' or 'id_service_product_order_detail'
- * @param int $scopeValue
- * @return bool
- */
- protected static function setRefundedForScope($scopeColumn, $scopeValue)
- {
- return Db::getInstance()->execute(
- 'UPDATE `' . _DB_PREFIX_ . 'order_tourism_tax`
- SET `is_refunded` = 1, `date_upd` = NOW()
- WHERE `' . bqSQL($scopeColumn) . '` = ' . (int) $scopeValue
- );
- }
-
/**
* Delete all snapshot rows for a scope.
*
- * @param string $scopeColumn 'id_htl_booking' or 'id_service_product_order_detail'
+ * @param string $scopeColumn self::SCOPE_COLUMN_ROOM or self::SCOPE_COLUMN_SERVICE
* @param int $scopeValue
* @return bool
*/
protected static function deleteForScope($scopeColumn, $scopeValue)
{
return Db::getInstance()->execute(
- 'DELETE FROM `' . _DB_PREFIX_ . 'order_tourism_tax`
- WHERE `' . bqSQL($scopeColumn) . '` = ' . (int) $scopeValue
+ 'DELETE otd FROM `' . _DB_PREFIX_ . 'order_tax_detail` otd
+ INNER JOIN `' . _DB_PREFIX_ . 'tax` t ON t.`id_tax` = otd.`id_tax` AND t.`is_tourism_tax` = 1
+ WHERE otd.`' . bqSQL($scopeColumn) . '` = ' . (int) $scopeValue
+ );
+ }
+
+ /**
+ *
+ * @param int $idOrderDetail
+ * @param int $idHtlBooking 0 for a service-line scope
+ * @param int $idServiceProductOrderDetail 0 for a room-booking scope
+ * @return bool
+ */
+ public static function updateVatScoping($idOrderDetail, $idHtlBooking, $idServiceProductOrderDetail)
+ {
+ return Db::getInstance()->execute(
+ 'UPDATE `' . _DB_PREFIX_ . 'order_tax_detail`
+ SET `id_htl_booking` = ' . (int) $idHtlBooking . ',
+ `id_service_product_order_detail` = ' . (int) $idServiceProductOrderDetail . '
+ WHERE `id_order_detail` = ' . (int) $idOrderDetail . '
+ AND `id_htl_booking` = 0
+ AND `id_service_product_order_detail` = 0'
);
}
@@ -252,9 +230,9 @@ class OrderTourismTaxCore extends ObjectModel
public static function hardDeleteForBooking($idHtlBooking, array $serviceLineIds)
{
$idHtlBooking = (int) $idHtlBooking;
- self::deleteForScope('id_htl_booking', $idHtlBooking);
+ self::deleteForScope(self::SCOPE_COLUMN_ROOM, $idHtlBooking);
foreach ($serviceLineIds as $idServiceLine) {
- self::deleteForScope('id_service_product_order_detail', (int) $idServiceLine);
+ self::deleteForScope(self::SCOPE_COLUMN_SERVICE, (int) $idServiceLine);
}
self::deleteExemptionMarker($idHtlBooking, 0);
}
@@ -263,16 +241,17 @@ class OrderTourismTaxCore extends ObjectModel
* Sum of total_amount for a booking/service-line scope (every row counts — exemption is never
* stored on the row itself, it's derived from marker existence at read time).
*
- * @param string $scopeColumn 'id_htl_booking' or 'id_service_product_order_detail'
+ * @param string $scopeColumn self::SCOPE_COLUMN_ROOM or self::SCOPE_COLUMN_SERVICE
* @param int $scopeValue
* @return float
*/
protected static function getScopedTotal($scopeColumn, $scopeValue)
{
return (float) Db::getInstance()->getValue(
- 'SELECT COALESCE(SUM(`total_amount`), 0)
- FROM `' . _DB_PREFIX_ . 'order_tourism_tax`
- WHERE `' . bqSQL($scopeColumn) . '` = ' . (int) $scopeValue
+ 'SELECT COALESCE(SUM(otd.`total_amount`), 0)
+ FROM `' . _DB_PREFIX_ . 'order_tax_detail` otd
+ INNER JOIN `' . _DB_PREFIX_ . 'tax` t ON t.`id_tax` = otd.`id_tax` AND t.`is_tourism_tax` = 1
+ WHERE otd.`' . bqSQL($scopeColumn) . '` = ' . (int) $scopeValue
);
}
@@ -281,7 +260,7 @@ class OrderTourismTaxCore extends ObjectModel
* ever refunded either. True means a fresh compute (buildRoomTaxParams()/buildServiceLineTaxParams()
* + saveTourismTaxFromParams()) is needed instead of restoring/reusing existing rows.
*
- * @param string $scopeColumn 'id_htl_booking' or 'id_service_product_order_detail'
+ * @param string $scopeColumn self::SCOPE_COLUMN_ROOM or self::SCOPE_COLUMN_SERVICE
* @param int $scopeValue
* @return bool
*/
@@ -292,8 +271,9 @@ class OrderTourismTaxCore extends ObjectModel
}
return !(bool) Db::getInstance()->getValue(
- 'SELECT COUNT(*) FROM `' . _DB_PREFIX_ . 'order_tourism_tax`
- WHERE `' . bqSQL($scopeColumn) . '` = ' . (int) $scopeValue
+ 'SELECT COUNT(*) FROM `' . _DB_PREFIX_ . 'order_tax_detail` otd
+ INNER JOIN `' . _DB_PREFIX_ . 'tax` t ON t.`id_tax` = otd.`id_tax` AND t.`is_tourism_tax` = 1
+ WHERE otd.`' . bqSQL($scopeColumn) . '` = ' . (int) $scopeValue
);
}
@@ -338,7 +318,6 @@ class OrderTourismTaxCore extends ObjectModel
* @param int $idOrderDetail
* @param int $idHtlBooking 0 for service lines
* @param int $idServiceProductOrderDetail 0 for room bookings
- * @param int $idHotel
* @return void
*/
public static function saveTourismTax(
@@ -356,8 +335,7 @@ class OrderTourismTaxCore extends ObjectModel
$idOrder,
$idOrderDetail,
$idHtlBooking,
- $idServiceProductOrderDetail,
- $idHotel
+ $idServiceProductOrderDetail
) {
$idTaxRulesGroup = (int) $idTaxRulesGroup;
$idOrderDetail = (int) $idOrderDetail;
@@ -366,50 +344,49 @@ class OrderTourismTaxCore extends ObjectModel
}
$taxCalculator = TaxManagerFactory::getManager($address, $idTaxRulesGroup)->getTaxCalculator();
- $rows = $taxCalculator->getTourismTaxRows(
+ $taxAmounts = $taxCalculator->getTaxesAmount(
$unitPriceTaxExcl,
$checkInDate,
$numNights,
$numAdults,
$childrenAges,
- $idCurrency,
$collectionType,
- $idLang,
- $quantity
- )['rows'];
+ $quantity,
+ $idCurrency
+ );
$idOrder = (int) $idOrder;
$idHtlBooking = (int) $idHtlBooking;
- $idHotel = (int) $idHotel;
- $idCurrency = (int) $idCurrency;
$idServiceProductOrderDetail = (int) $idServiceProductOrderDetail;
- $scopeColumn = $idServiceProductOrderDetail ? 'id_service_product_order_detail' : 'id_htl_booking';
+ $scopeColumn = $idServiceProductOrderDetail ? self::SCOPE_COLUMN_SERVICE : self::SCOPE_COLUMN_ROOM;
$scopeValue = $idServiceProductOrderDetail ?: $idHtlBooking;
$prevTotal = self::getScopedTotal($scopeColumn, $scopeValue);
self::deleteForScope($scopeColumn, $scopeValue);
$totalTourismTax = 0.0;
- foreach ($rows as $row) {
- $rowAmount = (float) $row['total_amount'];
+ foreach ($taxAmounts as $idTax => $rowAmount) {
+ $rowAmount = (float) $rowAmount;
- $taxRow = new OrderTourismTax();
+ $taxRow = new OrderTaxDetail();
$taxRow->id_order = $idOrder;
$taxRow->id_order_detail = $idOrderDetail;
$taxRow->id_htl_booking = $idHtlBooking;
$taxRow->id_service_product_order_detail = $idServiceProductOrderDetail;
- $taxRow->id_hotel = $idHotel;
- $taxRow->id_tax = (int) $row['id_tax'];
- $taxRow->id_currency = $idCurrency;
- $taxRow->num_nights = (int) $row['num_nights'];
- $taxRow->num_adults = (int) $row['num_adults'];
+ $taxRow->id_tax = (int) $idTax;
+ $taxRow->unit_amount = $quantity > 0 ? Tools::ps_round($rowAmount / $quantity, 6) : $rowAmount;
$taxRow->total_amount = $rowAmount;
- $taxRow->is_refunded = 0;
$taxRow->add();
$totalTourismTax += $rowAmount;
}
+ Db::getInstance()->execute(
+ 'UPDATE `' . _DB_PREFIX_ . 'order_detail`
+ SET `id_tourism_tax_rule_group` = ' . $idTaxRulesGroup . '
+ WHERE `id_order_detail` = ' . $idOrderDetail
+ );
+
if (!self::isScopeExempted($idHtlBooking, $idServiceProductOrderDetail)) {
self::adjustDependentTotals($idOrderDetail, $idHtlBooking, $idServiceProductOrderDetail, $prevTotal, $totalTourismTax);
}
@@ -437,10 +414,7 @@ class OrderTourismTaxCore extends ObjectModel
$result = $db->execute(
'UPDATE `' . _DB_PREFIX_ . 'order_detail`
- SET `tourism_tax_amount` = GREATEST(0, `tourism_tax_amount`
- - ' . $prevTotal . '
- + ' . $newTotal . '),
- `total_price_tax_incl` = `total_price_tax_incl`
+ SET `total_price_tax_incl` = `total_price_tax_incl`
- ' . $prevTotal . '
+ ' . $newTotal . ',
`unit_price_tax_incl` = `unit_price_tax_incl`
@@ -484,28 +458,30 @@ class OrderTourismTaxCore extends ObjectModel
{
$idOrder = (int) $idOrder;
$idLang = $idLang !== null ? (int) $idLang : (int) Context::getContext()->language->id;
- $cacheId = 'OrderTourismTax::getBreakdownForInvoice-' . $idOrder . '-' . $idLang;
+ $cacheId = 'OrderTaxDetail::getBreakdownForInvoice-' . $idOrder . '-' . $idLang;
if (Cache::isStored($cacheId)) {
return Cache::retrieve($cacheId);
}
$result = Db::getInstance()->executeS(
'SELECT ott.`id_tax`, tl.`name` AS tax_name,
- SUM(ott.`num_nights`) AS num_nights,
- SUM(ott.`num_adults`) AS num_adults,
SUM(ott.`total_amount`) AS total_amount
- FROM `' . _DB_PREFIX_ . 'order_tourism_tax` ott
+ FROM `' . _DB_PREFIX_ . 'order_tax_detail` ott
+ INNER JOIN `' . _DB_PREFIX_ . 'tax` t ON t.`id_tax` = ott.`id_tax` AND t.`is_tourism_tax` = 1
LEFT JOIN `' . _DB_PREFIX_ . 'service_product_order_detail` spod
ON spod.`id_service_product_order_detail` = ott.`id_service_product_order_detail`
- LEFT JOIN `' . _DB_PREFIX_ . 'order_tourism_tax_exemption` ex
+ LEFT JOIN `' . _DB_PREFIX_ . 'htl_booking_detail` hbd
+ ON hbd.`id` = ott.`id_htl_booking`
+ LEFT JOIN `' . _DB_PREFIX_ . 'order_tax_exemption` ex
ON (ott.`id_htl_booking` != 0 AND ex.`id_htl_booking` = ott.`id_htl_booking`)
OR (ott.`id_htl_booking` = 0 AND spod.`id_htl_booking_detail` != 0 AND ex.`id_htl_booking` = spod.`id_htl_booking_detail`)
OR (ott.`id_htl_booking` = 0 AND (spod.`id_htl_booking_detail` = 0 OR spod.`id_htl_booking_detail` IS NULL) AND ex.`id_service_product_order_detail` = ott.`id_service_product_order_detail` AND ex.`id_htl_booking` = 0)
LEFT JOIN `' . _DB_PREFIX_ . 'tax_lang` tl
ON tl.`id_tax` = ott.`id_tax` AND tl.`id_lang` = ' . $idLang . '
WHERE ott.`id_order` = ' . $idOrder . '
- AND ott.`is_refunded` = 0
- AND ex.`id_exemption` IS NULL
+ AND ((ott.`id_htl_booking` != 0 AND hbd.`is_refunded` = 0)
+ OR (ott.`id_htl_booking` = 0 AND spod.`is_refunded` = 0))
+ AND ex.`id_order_tax_exemption` IS NULL
GROUP BY ott.`id_tax`, tl.`name`'
);
Cache::store($cacheId, $result);
@@ -513,6 +489,50 @@ class OrderTourismTaxCore extends ObjectModel
return $result;
}
+ /**
+ * Applied (non-exempted, non-refunded) tourism tax total per order_detail line. Same
+ * exemption/refund-aware join as getBreakdownForInvoice(), grouped by id_order_detail instead of
+ * id_tax.
+ *
+ * @param int $idOrder
+ * @return array [id_order_detail => total_amount]
+ */
+ public static function getAmountsByOrderDetail($idOrder)
+ {
+ $idOrder = (int) $idOrder;
+ $cacheId = 'OrderTaxDetail::getAmountsByOrderDetail-' . $idOrder;
+ if (Cache::isStored($cacheId)) {
+ return Cache::retrieve($cacheId);
+ }
+
+ $rows = Db::getInstance()->executeS(
+ 'SELECT ott.`id_order_detail`, SUM(ott.`total_amount`) AS total_amount
+ FROM `' . _DB_PREFIX_ . 'order_tax_detail` ott
+ INNER JOIN `' . _DB_PREFIX_ . 'tax` t ON t.`id_tax` = ott.`id_tax` AND t.`is_tourism_tax` = 1
+ LEFT JOIN `' . _DB_PREFIX_ . 'service_product_order_detail` spod
+ ON spod.`id_service_product_order_detail` = ott.`id_service_product_order_detail`
+ LEFT JOIN `' . _DB_PREFIX_ . 'htl_booking_detail` hbd
+ ON hbd.`id` = ott.`id_htl_booking`
+ LEFT JOIN `' . _DB_PREFIX_ . 'order_tax_exemption` ex
+ ON (ott.`id_htl_booking` != 0 AND ex.`id_htl_booking` = ott.`id_htl_booking`)
+ OR (ott.`id_htl_booking` = 0 AND spod.`id_htl_booking_detail` != 0 AND ex.`id_htl_booking` = spod.`id_htl_booking_detail`)
+ OR (ott.`id_htl_booking` = 0 AND (spod.`id_htl_booking_detail` = 0 OR spod.`id_htl_booking_detail` IS NULL) AND ex.`id_service_product_order_detail` = ott.`id_service_product_order_detail` AND ex.`id_htl_booking` = 0)
+ WHERE ott.`id_order` = ' . $idOrder . '
+ AND ((ott.`id_htl_booking` != 0 AND hbd.`is_refunded` = 0)
+ OR (ott.`id_htl_booking` = 0 AND spod.`is_refunded` = 0))
+ AND ex.`id_order_tax_exemption` IS NULL
+ GROUP BY ott.`id_order_detail`'
+ );
+
+ $result = array();
+ foreach ((array) $rows as $row) {
+ $result[(int) $row['id_order_detail']] = (float) $row['total_amount'];
+ }
+ Cache::store($cacheId, $result);
+
+ return $result;
+ }
+
/**
* The single source of truth for an order's tourism tax total — applied, non-exempted, non-refunded.
*
@@ -525,17 +545,25 @@ class OrderTourismTaxCore extends ObjectModel
}
/**
- * Whether a scope has any refunded tourism tax rows — apply/exempt must not touch a cancelled booking/service line.
+ * Whether a scope is refunded — apply/exempt must not touch a cancelled booking/service line.
+ * Reads the authoritative flag directly (htl_booking_detail/service_product_order_detail),
+ * not a stored copy on order_tax_detail.
*
- * @param string $scopeColumn 'id_htl_booking' or 'id_service_product_order_detail'
+ * @param string $scopeColumn self::SCOPE_COLUMN_ROOM or self::SCOPE_COLUMN_SERVICE
* @param int $scopeValue
* @return bool
*/
protected static function hasRefundedRowsForScope($scopeColumn, $scopeValue)
{
+ $scopeValue = (int) $scopeValue;
+ if ($scopeColumn === self::SCOPE_COLUMN_ROOM) {
+ return (bool) Db::getInstance()->getValue(
+ 'SELECT `is_refunded` FROM `' . _DB_PREFIX_ . 'htl_booking_detail` WHERE `id` = ' . $scopeValue
+ );
+ }
return (bool) Db::getInstance()->getValue(
- 'SELECT COUNT(*) FROM `' . _DB_PREFIX_ . 'order_tourism_tax`
- WHERE `' . bqSQL($scopeColumn) . '` = ' . (int) $scopeValue . ' AND `is_refunded` = 1'
+ 'SELECT `is_refunded` FROM `' . _DB_PREFIX_ . 'service_product_order_detail`
+ WHERE `id_service_product_order_detail` = ' . $scopeValue
);
}
@@ -565,7 +593,7 @@ class OrderTourismTaxCore extends ObjectModel
}
$idHotel = (int) $booking->id_hotel;
- $hotelContext = TourismTax::resolveHotelAddressAndCollectionType($idHotel, new Address((int) $order->id_address_tax));
+ $hotelContext = TaxConfiguration::resolveHotelAddressAndCollectionType($idHotel, new Address((int) $order->id_address_tax));
$address = $hotelContext['address'];
if (!Validate::isLoadedObject($address)) {
return false;
@@ -603,7 +631,6 @@ class OrderTourismTaxCore extends ObjectModel
'idOrderDetail' => (int) $booking->id_order_detail,
'idHtlBooking' => $idHtlBooking,
'idServiceProductOrderDetail' => 0,
- 'idHotel' => $idHotel,
);
}
@@ -632,7 +659,7 @@ class OrderTourismTaxCore extends ObjectModel
}
$idHotel = (int) $serviceLine->id_hotel;
- $hotelContext = TourismTax::resolveHotelAddressAndCollectionType($idHotel, new Address((int) $order->id_address_tax));
+ $hotelContext = TaxConfiguration::resolveHotelAddressAndCollectionType($idHotel, new Address((int) $order->id_address_tax));
$address = $hotelContext['address'];
if (!Validate::isLoadedObject($address)) {
return false;
@@ -675,7 +702,6 @@ class OrderTourismTaxCore extends ObjectModel
'idOrderDetail' => (int) $serviceLine->id_order_detail,
'idHtlBooking' => 0,
'idServiceProductOrderDetail' => $idServiceProductOrderDetail,
- 'idHotel' => $idHotel,
);
}
@@ -702,8 +728,7 @@ class OrderTourismTaxCore extends ObjectModel
$params['idOrder'],
$params['idOrderDetail'],
$params['idHtlBooking'],
- $params['idServiceProductOrderDetail'],
- $params['idHotel']
+ $params['idServiceProductOrderDetail']
);
}
@@ -722,7 +747,7 @@ class OrderTourismTaxCore extends ObjectModel
if (self::isBookingExempted($idHtlBooking)) {
return self::EXEMPT_OK;
}
- if (self::hasRefundedRowsForScope('id_htl_booking', $idHtlBooking)) {
+ if (self::hasRefundedRowsForScope(self::SCOPE_COLUMN_ROOM, $idHtlBooking)) {
return self::EXEMPT_ERROR_REFUNDED;
}
@@ -731,13 +756,13 @@ class OrderTourismTaxCore extends ObjectModel
return self::EXEMPT_ERROR_NO_RULE;
}
- $objOrderTourismTaxExemption = new OrderTourismTaxExemption();
- $objOrderTourismTaxExemption->id_htl_booking = $idHtlBooking;
- $objOrderTourismTaxExemption->id_service_product_order_detail = 0;
- $objOrderTourismTaxExemption->id_order = (int) $booking->id_order;
- $objOrderTourismTaxExemption->id_employee = $idEmployee ? (int) $idEmployee : (int) Context::getContext()->employee->id;
- $objOrderTourismTaxExemption->note = $note;
- if (!$objOrderTourismTaxExemption->add()) {
+ $objOrderTaxExemption = new OrderTaxExemption();
+ $objOrderTaxExemption->id_htl_booking = $idHtlBooking;
+ $objOrderTaxExemption->id_service_product_order_detail = 0;
+ $objOrderTaxExemption->id_order = (int) $booking->id_order;
+ $objOrderTaxExemption->id_employee = $idEmployee ? (int) $idEmployee : (int) Context::getContext()->employee->id;
+ $objOrderTaxExemption->note = $note;
+ if (!$objOrderTaxExemption->add()) {
return self::EXEMPT_ERROR_SAVE;
}
@@ -761,7 +786,7 @@ class OrderTourismTaxCore extends ObjectModel
$wasExempted = self::isBookingExempted($idHtlBooking);
if ($wasExempted) {
- if (self::hasRefundedRowsForScope('id_htl_booking', $idHtlBooking)) {
+ if (self::hasRefundedRowsForScope(self::SCOPE_COLUMN_ROOM, $idHtlBooking)) {
return self::APPLY_ERROR_REFUNDED;
}
if (!self::deleteExemptionMarker($idHtlBooking, 0)) {
@@ -769,22 +794,24 @@ class OrderTourismTaxCore extends ObjectModel
}
}
- if (self::hasNeverBeenComputed('id_htl_booking', $idHtlBooking)) {
+ if (self::hasNeverBeenComputed(self::SCOPE_COLUMN_ROOM, $idHtlBooking)) {
$params = self::buildRoomTaxParams($idHtlBooking);
if ($params) {
+ $params['collectionType'] = HotelBranchInformation::TAX_COLLECTION_TYPE_ONLINE;
self::saveTourismTaxFromParams($params);
- self::adjustOrderTotalsForNewRows('id_htl_booking', $idHtlBooking, $params['idOrder']);
+ self::adjustOrderTotalsForNewRows(self::SCOPE_COLUMN_ROOM, $idHtlBooking, $params['idOrder']);
}
}
foreach (ServiceProductOrderDetail::getActiveIdsByHtlBookingDetail($idHtlBooking) as $idServiceLine) {
- if (!self::hasNeverBeenComputed('id_service_product_order_detail', $idServiceLine)) {
+ if (!self::hasNeverBeenComputed(self::SCOPE_COLUMN_SERVICE, $idServiceLine)) {
continue;
}
$svcParams = self::buildServiceLineTaxParams($idServiceLine);
if ($svcParams) {
+ $svcParams['collectionType'] = HotelBranchInformation::TAX_COLLECTION_TYPE_ONLINE;
self::saveTourismTaxFromParams($svcParams);
- self::adjustOrderTotalsForNewRows('id_service_product_order_detail', $idServiceLine, $svcParams['idOrder']);
+ self::adjustOrderTotalsForNewRows(self::SCOPE_COLUMN_SERVICE, $idServiceLine, $svcParams['idOrder']);
}
}
@@ -810,27 +837,26 @@ class OrderTourismTaxCore extends ObjectModel
if (self::isServiceLineExempted($idServiceProductOrderDetail)) {
return self::EXEMPT_OK;
}
- if (self::hasRefundedRowsForScope('id_service_product_order_detail', $idServiceProductOrderDetail)) {
+ if (self::hasRefundedRowsForScope(self::SCOPE_COLUMN_SERVICE, $idServiceProductOrderDetail)) {
return self::EXEMPT_ERROR_REFUNDED;
}
$serviceLine = new ServiceProductOrderDetail($idServiceProductOrderDetail);
if (!Validate::isLoadedObject($serviceLine) || $serviceLine->id_htl_booking_detail) {
- // Room-attached lines must go through exemptBooking() instead.
return self::EXEMPT_ERROR_NO_RULE;
}
- $objOrderTourismTaxExemption = new OrderTourismTaxExemption();
- $objOrderTourismTaxExemption->id_htl_booking = 0;
- $objOrderTourismTaxExemption->id_service_product_order_detail = $idServiceProductOrderDetail;
- $objOrderTourismTaxExemption->id_order = (int) $serviceLine->id_order;
- $objOrderTourismTaxExemption->id_employee = $idEmployee ? (int) $idEmployee : (int) Context::getContext()->employee->id;
- $objOrderTourismTaxExemption->note = $note;
- if (!$objOrderTourismTaxExemption->add()) {
+ $objOrderTaxExemption = new OrderTaxExemption();
+ $objOrderTaxExemption->id_htl_booking = 0;
+ $objOrderTaxExemption->id_service_product_order_detail = $idServiceProductOrderDetail;
+ $objOrderTaxExemption->id_order = (int) $serviceLine->id_order;
+ $objOrderTaxExemption->id_employee = $idEmployee ? (int) $idEmployee : (int) Context::getContext()->employee->id;
+ $objOrderTaxExemption->note = $note;
+ if (!$objOrderTaxExemption->add()) {
return self::EXEMPT_ERROR_SAVE;
}
- $total = self::getScopedTotal('id_service_product_order_detail', $idServiceProductOrderDetail);
+ $total = self::getScopedTotal(self::SCOPE_COLUMN_SERVICE, $idServiceProductOrderDetail);
if ($total) {
self::adjustDependentTotals((int) $serviceLine->id_order_detail, 0, $idServiceProductOrderDetail, $total, 0.0);
self::adjustOrderAndInvoiceTotals((int) $serviceLine->id_order, -$total);
@@ -851,7 +877,7 @@ class OrderTourismTaxCore extends ObjectModel
$wasExempted = self::isServiceLineExempted($idServiceProductOrderDetail);
if ($wasExempted) {
- if (self::hasRefundedRowsForScope('id_service_product_order_detail', $idServiceProductOrderDetail)) {
+ if (self::hasRefundedRowsForScope(self::SCOPE_COLUMN_SERVICE, $idServiceProductOrderDetail)) {
return self::APPLY_ERROR_REFUNDED;
}
if (!self::deleteExemptionMarker(0, $idServiceProductOrderDetail)) {
@@ -859,16 +885,17 @@ class OrderTourismTaxCore extends ObjectModel
}
}
- if (self::hasNeverBeenComputed('id_service_product_order_detail', $idServiceProductOrderDetail)) {
+ if (self::hasNeverBeenComputed(self::SCOPE_COLUMN_SERVICE, $idServiceProductOrderDetail)) {
$params = self::buildServiceLineTaxParams($idServiceProductOrderDetail);
if ($params) {
+ $params['collectionType'] = HotelBranchInformation::TAX_COLLECTION_TYPE_ONLINE;
self::saveTourismTaxFromParams($params);
- self::adjustOrderTotalsForNewRows('id_service_product_order_detail', $idServiceProductOrderDetail, $params['idOrder']);
+ self::adjustOrderTotalsForNewRows(self::SCOPE_COLUMN_SERVICE, $idServiceProductOrderDetail, $params['idOrder']);
}
}
if ($wasExempted) {
- $total = self::getScopedTotal('id_service_product_order_detail', $idServiceProductOrderDetail);
+ $total = self::getScopedTotal(self::SCOPE_COLUMN_SERVICE, $idServiceProductOrderDetail);
if ($total) {
$serviceLine = new ServiceProductOrderDetail($idServiceProductOrderDetail);
if (Validate::isLoadedObject($serviceLine)) {
@@ -934,7 +961,7 @@ class OrderTourismTaxCore extends ObjectModel
* (called inside saveTourismTax()) only syncs order_detail/htl_booking_detail/service_product_order_detail,
* never orders/order_invoice.
*
- * @param string $scopeColumn 'id_htl_booking' or 'id_service_product_order_detail'
+ * @param string $scopeColumn self::SCOPE_COLUMN_ROOM or self::SCOPE_COLUMN_SERVICE
* @param int $scopeValue
* @param int $idOrder
* @return void
@@ -963,7 +990,7 @@ class OrderTourismTaxCore extends ObjectModel
}
$totalDelta = 0.0;
- $roomTotal = self::getScopedTotal('id_htl_booking', $idHtlBooking);
+ $roomTotal = self::getScopedTotal(self::SCOPE_COLUMN_ROOM, $idHtlBooking);
if ($roomTotal) {
$prev = $nowIncluded ? 0.0 : $roomTotal;
$new = $nowIncluded ? $roomTotal : 0.0;
@@ -972,7 +999,7 @@ class OrderTourismTaxCore extends ObjectModel
}
foreach (ServiceProductOrderDetail::getActiveIdsByHtlBookingDetail($idHtlBooking) as $idServiceLine) {
- $serviceTotal = self::getScopedTotal('id_service_product_order_detail', $idServiceLine);
+ $serviceTotal = self::getScopedTotal(self::SCOPE_COLUMN_SERVICE, $idServiceLine);
if (!$serviceTotal) {
continue;
}
diff --git a/classes/tourismtax/OrderTourismTaxExemption.php b/classes/order/OrderTaxExemption.php
similarity index 91%
rename from classes/tourismtax/OrderTourismTaxExemption.php
rename to classes/order/OrderTaxExemption.php
index d40dff81c..dbbac21c3 100644
--- a/classes/tourismtax/OrderTourismTaxExemption.php
+++ b/classes/order/OrderTaxExemption.php
@@ -21,9 +21,9 @@
* @license https://opensource.org/license/osl-3-0-php Open Software License version 3.0
*/
-class OrderTourismTaxExemptionCore extends ObjectModel
+class OrderTaxExemptionCore extends ObjectModel
{
- public $id_exemption;
+ public $id_order_tax_exemption;
public $id_htl_booking;
public $id_service_product_order_detail;
public $id_order;
@@ -32,8 +32,8 @@ class OrderTourismTaxExemptionCore extends ObjectModel
public $date_add;
public static $definition = array(
- 'table' => 'order_tourism_tax_exemption',
- 'primary' => 'id_exemption',
+ 'table' => 'order_tax_exemption',
+ 'primary' => 'id_order_tax_exemption',
'fields' => array(
'id_htl_booking' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
'id_service_product_order_detail' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
diff --git a/classes/pdf/HTMLTemplateBookingVoucher.php b/classes/pdf/HTMLTemplateBookingVoucher.php
index a2dfcf011..6aa46a82d 100644
--- a/classes/pdf/HTMLTemplateBookingVoucher.php
+++ b/classes/pdf/HTMLTemplateBookingVoucher.php
@@ -321,7 +321,7 @@ class HTMLTemplateBookingVoucherCore extends HTMLTemplate
$footer['total_without_discount_te'] = $footer['room_price_tax_excl'] + $footer['total_convenience_fee_te'] + $footer['additional_service_price_tax_excl'] + $footer['service_products_price_tax_excl'];
$totalWithoutDiscountTaxIncl = $roomsCostTaxIncl + $serviceProductsCostTaxIncl + $additionalServicesCostTaxIncl + $convenienceFeeTaxIncl;
- $totalTourismTax = OrderTourismTax::getOrderTourismTaxTotal((int) $this->order->id);
+ $totalTourismTax = OrderTaxDetail::getOrderTourismTaxTotal((int) $this->order->id);
$footer['total_tax_without_discount'] = max(0, $totalWithoutDiscountTaxIncl - $footer['total_without_discount_te'] - $totalTourismTax);
$footer['total_tourism_tax'] = $totalTourismTax;
$grandTotal = max(0.0, $totalWithoutDiscountTaxIncl - $productDiscountsTaxIncl);
diff --git a/classes/pdf/HTMLTemplateInvoice.php b/classes/pdf/HTMLTemplateInvoice.php
index 9d99b108b..7936b6ae7 100644
--- a/classes/pdf/HTMLTemplateInvoice.php
+++ b/classes/pdf/HTMLTemplateInvoice.php
@@ -687,7 +687,7 @@ class HTMLTemplateInvoiceCore extends HTMLTemplate
$footer['total_without_discount_te'] = $footer['room_price_tax_excl'] + $footer['total_convenience_fee_te'] + $footer['additional_service_price_tax_excl'] + $footer['service_products_price_tax_excl'];
$footer['total_without_discount_ti'] = $footer['room_price_tax_incl'] + $footer['total_convenience_fee_ti'] + $footer['additional_service_price_tax_incl'] + $footer['service_products_price_tax_incl'];
- $footer['total_tourism_tax'] = OrderTourismTax::getOrderTourismTaxTotal((int) $this->order->id);
+ $footer['total_tourism_tax'] = OrderTaxDetail::getOrderTourismTaxTotal((int) $this->order->id);
$footer['total_tax_without_discount'] = $footer['total_without_discount_ti'] - $footer['total_without_discount_te'] - $footer['total_tourism_tax'];
if ($footer['total_tax_without_discount'] < 0) {
diff --git a/classes/pdf/HTMLTemplateOrderSlip.php b/classes/pdf/HTMLTemplateOrderSlip.php
index 16396243f..045eeb52a 100644
--- a/classes/pdf/HTMLTemplateOrderSlip.php
+++ b/classes/pdf/HTMLTemplateOrderSlip.php
@@ -267,10 +267,11 @@ class HTMLTemplateOrderSlipCore extends HTMLTemplateInvoice
// if one of the order details use the tax computation method the display will be different
return Db::getInstance()->getValue('
SELECT od.`tax_computation_method`
- FROM `' . _DB_PREFIX_ . 'order_detail_tax` odt
+ FROM `' . _DB_PREFIX_ . 'order_tax_detail` odt
LEFT JOIN `' . _DB_PREFIX_ . 'order_detail` od ON (od.`id_order_detail` = odt.`id_order_detail`)
WHERE od.`id_order` = ' . (int) $this->order->id . '
- AND od.`tax_computation_method` = ' . (int) TaxCalculator::ONE_AFTER_ANOTHER_METHOD)
+ AND od.`tax_computation_method` = ' . (int) TaxCalculator::ONE_AFTER_ANOTHER_METHOD . '
+ AND NOT EXISTS (SELECT 1 FROM `' . _DB_PREFIX_ . 'tax` tc WHERE tc.`id_tax` = odt.`id_tax` AND tc.`is_tourism_tax` = 1)')
|| Configuration::get('PS_INVOICE_TAXES_BREAKDOWN');
}
diff --git a/classes/tax/AverageTaxOfProductsTaxCalculator.php b/classes/tax/AverageTaxOfProductsTaxCalculator.php
index 272935920..3c07d12c6 100644
--- a/classes/tax/AverageTaxOfProductsTaxCalculator.php
+++ b/classes/tax/AverageTaxOfProductsTaxCalculator.php
@@ -20,9 +20,10 @@ class AverageTaxOfProductsTaxCalculator
$sql = 'SELECT t.id_tax, t.rate, od.total_price_tax_excl FROM '.$prefix.'orders o
INNER JOIN '.$prefix.'order_detail od ON od.id_order = o.id_order
- INNER JOIN '.$prefix.'order_detail_tax odt ON odt.id_order_detail = od.id_order_detail
+ INNER JOIN '.$prefix.'order_tax_detail odt ON odt.id_order_detail = od.id_order_detail
INNER JOIN '.$prefix.'tax t ON t.id_tax = odt.id_tax
- WHERE o.id_order = '.(int)$this->id_order;
+ WHERE o.id_order = '.(int)$this->id_order.'
+ AND NOT EXISTS (SELECT 1 FROM '.$prefix.'tax tc WHERE tc.id_tax = odt.id_tax AND tc.is_tourism_tax = 1)';
return $this->db->select($sql);
}
diff --git a/classes/tax/Tax.php b/classes/tax/Tax.php
index 57d600e6a..8bfff493c 100644
--- a/classes/tax/Tax.php
+++ b/classes/tax/Tax.php
@@ -137,11 +137,7 @@ class TaxCore extends ObjectModel
{
return Db::getInstance()->getValue('
SELECT `id_tax`
- FROM `'._DB_PREFIX_.'order_detail_tax`
- WHERE `id_tax` = '.(int)$this->id
- ) || Db::getInstance()->getValue('
- SELECT `id_tax`
- FROM `'._DB_PREFIX_.'order_tourism_tax`
+ FROM `'._DB_PREFIX_.'order_tax_detail`
WHERE `id_tax` = '.(int)$this->id
);
}
diff --git a/classes/tax/TaxCalculator.php b/classes/tax/TaxCalculator.php
index 5eb8a946e..be9ba424f 100644
--- a/classes/tax/TaxCalculator.php
+++ b/classes/tax/TaxCalculator.php
@@ -132,14 +132,129 @@ class TaxCalculatorCore
/**
* Return the tax amount associated to each taxes of the TaxCalculator
*
- * @param float $price_te
+ * @param float $price_te
+ * @param string|null $checkInDate
+ * @param int $numNights
+ * @param int $numAdults
+ * @param int[] $childrenAges
+ * @param int|null $collectionType
+ * @param int $quantity
+ * @param int|null $idCurrency
* @return array $taxes_amount
*/
- public function getTaxesAmount($price_te)
- {
+ public function getTaxesAmount(
+ $price_te,
+ $checkInDate = null,
+ $numNights = 1,
+ $numAdults = 1,
+ $childrenAges = array(),
+ $collectionType = null,
+ $quantity = 1,
+ $idCurrency = null
+ ) {
$taxes_amounts = array();
+ $tourismTaxIds = array();
+
+ if ($checkInDate !== null && $collectionType !== null && Configuration::get('QLO_USE_TOURISM_TAX') && $collectionType !== HotelBranchInformation::TAX_COLLECTION_TYPE_AT_HOTEL) {
+ if (!$idCurrency) {
+ $context = Context::getContext();
+ $idCurrency = Validate::isLoadedObject($context->currency) ? (int) $context->currency->id : (int) Configuration::get('PS_CURRENCY_DEFAULT');
+ }
+
+ $checkIn = new DateTime($checkInDate);
+ $isoDayIndex = $checkIn->format('N') - 1;
+
+ $infantMaxAge = Configuration::get('QLO_GLOBAL_MAX_INFANT_AGE');
+ $childMaxAge = Configuration::get('WK_GLOBAL_CHILD_MAX_AGE');
+ $eligibleChildAges = array_filter($childrenAges, function ($age) use ($infantMaxAge, $childMaxAge) {
+ return $age >= $infantMaxAge && $age < $childMaxAge;
+ });
+
+ $runningPriceExcl = (float) $price_te;
+
+ foreach ($this->taxes as $tax) {
+ $tourismTax = TaxConfiguration::getByTaxId((int) $tax->id);
+ if (!$tourismTax) {
+ continue;
+ }
+ $tourismTaxIds[] = $tax->id;
+
+ if (!empty($tourismTax->valid_from) && $tourismTax->valid_from !== '0000-00-00') {
+ $validFrom = new DateTime($tourismTax->valid_from);
+ if ($checkIn < $validFrom) {
+ continue;
+ }
+ }
+ if (!empty($tourismTax->valid_to) && $tourismTax->valid_to !== '0000-00-00') {
+ $validTo = new DateTime($tourismTax->valid_to);
+ if ($checkIn > $validTo) {
+ continue;
+ }
+ }
+ if ($tourismTax->special_days) {
+ $specialDays = json_decode($tourismTax->special_days, true);
+ if (!is_array($specialDays) || !in_array(TaxConfiguration::DAY_KEYS[$isoDayIndex], $specialDays)) {
+ continue;
+ }
+ }
+
+ $taxType = (int) $tourismTax->tax_calc_type;
+ $isPerNight = (bool) $tourismTax->is_per_night;
+
+ $baseValue = (float) $tourismTax->tax_value;
+ if ($tourismTax->is_tiered) {
+ $tier = TaxPriceTier::getMatchingTier((int) $tax->id, $runningPriceExcl);
+ if ($tier) {
+ $baseValue = (float) $tier['tax_value'];
+ }
+ }
+
+ $adultMultiplier = 1;
+ if ($isPerNight) {
+ $adultMultiplier *= $numNights;
+ }
+ if ($tourismTax->is_per_person) {
+ $adultMultiplier *= $numAdults;
+ }
+
+ if ($taxType === 0) {
+ $unitAmountAdult = $baseValue;
+ $totalAmountAdult = $baseValue * $adultMultiplier;
+ } else {
+ $unitAmountAdult = $runningPriceExcl * ($baseValue / 100);
+ $totalAmountAdult = $unitAmountAdult * $adultMultiplier;
+ }
+
+ $totalAmountChild = 0.0;
+ if ($tourismTax->has_child_rate && !empty($eligibleChildAges)) {
+ $contribution = TaxChildRange::getChildContribution(
+ $tax->id,
+ $eligibleChildAges,
+ $taxType,
+ $runningPriceExcl,
+ $baseValue,
+ $tourismTax->has_child_age_range
+ );
+ if ($contribution['count'] > 0) {
+ $nightMultiplier = $isPerNight ? $numNights : 1;
+ $totalAmountChild = $contribution['total'] * $nightMultiplier;
+ }
+ }
+
+ if ($this->computation_method == TaxCalculator::ONE_AFTER_ANOTHER_METHOD) {
+ $runningPriceExcl += $unitAmountAdult;
+ }
+
+ $totalAmountAdult = Tools::convertPrice($totalAmountAdult, $idCurrency);
+ $totalAmountChild = Tools::convertPrice($totalAmountChild, $idCurrency);
+ $taxes_amounts[$tax->id] = Tools::ps_round(($totalAmountAdult + $totalAmountChild) * max(1, $quantity), 6);
+ }
+ }
foreach ($this->taxes as $tax) {
+ if (in_array($tax->id, $tourismTaxIds)) {
+ continue;
+ }
if (!isset($taxes_amounts[$tax->id])) {
$taxes_amounts[$tax->id] = 0;
}
@@ -155,16 +270,23 @@ class TaxCalculatorCore
}
/**
- * Return the total taxes amount
*
* @param float $price_te
* @return float $amount
*/
- public function getTaxesTotalAmount($price_te)
- {
+ public function getTaxesTotalAmount(
+ $price_te,
+ $checkInDate = null,
+ $numNights = 1,
+ $numAdults = 1,
+ $childrenAges = array(),
+ $collectionType = null,
+ $quantity = 1,
+ $idCurrency = null
+ ) {
$amount = 0;
- $taxes = $this->getTaxesAmount($price_te);
+ $taxes = $this->getTaxesAmount($price_te, $checkInDate, $numNights, $numAdults, $childrenAges, $collectionType, $quantity, $idCurrency);
foreach ($taxes as $tax) {
$amount += $tax;
}
@@ -173,144 +295,34 @@ class TaxCalculatorCore
}
/**
- * @param float $unitPriceTaxExcl Room/service unit_price_tax_excl (% base and tier lookup)
- * @param string $checkInDate 'YYYY-MM-DD'
+ *
+ * @param float $price_te
+ * @param string $checkInDate
* @param int $numNights
* @param int $numAdults
- * @param int[] $childrenAges Ages at check-in date
- * @param int $idCurrency
- * @param int $collectionType HotelBranchInformation::tourism_tax_collection_type snapshot
- * @param int $idLang
- * @param int $quantity Line quantity multiplier. Rooms: always 1.
- * @return array ['tourism_tax_online' => float,
- * 'rows' => [['id_tax','tax_name','num_nights','num_adults','total_amount','collection_type'], ...]]
+ * @param int[] $childrenAges
+ * @param int $collectionType
+ * @param int $quantity
+ * @return float price with tourism tax
*/
- public function getTourismTaxRows(
- $unitPriceTaxExcl,
- $checkInDate,
- $numNights,
- $numAdults,
- $childrenAges,
- $idCurrency,
- $collectionType,
- $idLang,
- $quantity = 1
- ) {
- $result = array('tourism_tax_online' => 0.0, 'rows' => array());
+ public function addTourismTaxes($price_te, $checkInDate, $numNights, $numAdults, $childrenAges, $collectionType, $quantity = 1)
+ {
+ return $price_te + $this->getTaxesTotalAmount($price_te, $checkInDate, $numNights, $numAdults, $childrenAges, $collectionType, $quantity);
+ }
- if (!Configuration::get('QLO_USE_TOURISM_TAX')) {
- return $result;
- }
- if ($collectionType === TourismTax::COLLECTION_TYPE_AT_HOTEL) {
- return $result;
- }
-
- $checkIn = new DateTime($checkInDate);
- $isoDayIndex = $checkIn->format('N') - 1;
-
- $infantMaxAge = (int) Configuration::get('QLO_GLOBAL_MAX_INFANT_AGE');
- $childMaxAge = (int) Configuration::get('WK_GLOBAL_CHILD_MAX_AGE');
- $eligibleChildAges = array_filter($childrenAges, function ($age) use ($infantMaxAge, $childMaxAge) {
- $age = (int) $age;
- return $age >= $infantMaxAge && $age < $childMaxAge;
- });
-
- $rows = array();
- $runningPriceExcl = (float) $unitPriceTaxExcl;
-
- foreach ($this->taxes as $tax) {
- $tourismTax = TourismTax::getByTaxId((int) $tax->id);
- if (!$tourismTax) {
- continue;
- }
-
- if (!empty($tourismTax->valid_from) && $tourismTax->valid_from !== '0000-00-00') {
- $validFrom = new DateTime($tourismTax->valid_from);
- if ($checkIn < $validFrom) {
- continue;
- }
- }
- if (!empty($tourismTax->valid_to) && $tourismTax->valid_to !== '0000-00-00') {
- $validTo = new DateTime($tourismTax->valid_to);
- if ($checkIn > $validTo) {
- continue;
- }
- }
- if ($tourismTax->special_days) {
- $specialDays = json_decode($tourismTax->special_days, true);
- if (!is_array($specialDays) || !in_array(TourismTax::DAY_KEYS[$isoDayIndex], $specialDays)) {
- continue;
- }
- }
-
- $isTiered = (bool) $tourismTax->is_tiered;
- $taxType = (int) $tourismTax->tax_calc_type;
- $isPerNight = (bool) $tourismTax->is_per_night;
- $isPerPerson = (bool) $tourismTax->is_per_person;
- $hasChildRate = (bool) $tourismTax->has_child_rate;
-
- $baseValue = (float) $tourismTax->tax_value;
- if ($isTiered) {
- $tier = TourismTaxTier::getMatchingTier((int) $tax->id, $runningPriceExcl);
- if ($tier) {
- $baseValue = (float) $tier['tax_value'];
- }
- }
-
- $adultMultiplier = 1;
- if ($isPerNight) {
- $adultMultiplier *= $numNights;
- }
- if ($isPerPerson) {
- $adultMultiplier *= $numAdults;
- }
-
- if ($taxType === 0) {
- $unitAmountAdult = $baseValue;
- $totalAmountAdult = $baseValue * $adultMultiplier;
- } else {
- $unitAmountAdult = $runningPriceExcl * ($baseValue / 100);
- $totalAmountAdult = $unitAmountAdult * $adultMultiplier;
- }
-
- $totalAmountChild = 0.0;
-
- if ($hasChildRate && !empty($eligibleChildAges)) {
- $contribution = TourismTaxChildRange::getChildContribution(
- (int) $tax->id,
- $eligibleChildAges,
- $taxType,
- $runningPriceExcl,
- $baseValue,
- (bool) $tourismTax->has_child_age_range
- );
- if ((int) $contribution['count'] > 0) {
- $nightMultiplier = $isPerNight ? $numNights : 1;
- $totalAmountChild = $contribution['total'] * $nightMultiplier;
- }
- }
-
- if ($this->computation_method == TaxCalculator::ONE_AFTER_ANOTHER_METHOD) {
- $runningPriceExcl += $unitAmountAdult;
- }
-
- $totalAmountAdult = Tools::convertPrice($totalAmountAdult, $idCurrency);
- $totalAmountChild = Tools::convertPrice($totalAmountChild, $idCurrency);
- $totalAmount = Tools::ps_round(($totalAmountAdult + $totalAmountChild) * max(1, $quantity), 6);
-
- $rows[] = array(
- 'id_tax' => (int) $tax->id,
- 'tax_name' => (string) (isset($tax->name[$idLang]) ? $tax->name[$idLang] : ''),
- 'num_nights' => $numNights,
- 'num_adults' => $numAdults,
- 'total_amount' => $totalAmount,
- 'collection_type' => $collectionType,
- );
- }
-
- $result['rows'] = $rows;
- $result['tourism_tax_online'] = (float) array_sum(array_column($rows, 'total_amount'));
-
- return $result;
+ /**
+ *
+ * @param float $price_ti
+ * @param string $checkInDate 'YYYY-MM-DD'
+ * @param int $numNights
+ * @param int $numAdults
+ * @param int[] $childrenAges Ages at check-in date
+ * @param int $collectionType TaxConfiguration::COLLECTION_TYPE_*
+ * @param int $quantity Line quantity multiplier
+ * @return float price without tourism tax
+ */
+ public function removeTourismTaxes($price_ti, $checkInDate, $numNights, $numAdults, $childrenAges, $collectionType, $quantity = 1)
+ {
+ return $price_ti - $this->getTaxesTotalAmount($price_ti, $checkInDate, $numNights, $numAdults, $childrenAges, $collectionType, $quantity);
}
}
diff --git a/classes/tourismtax/TourismTaxChildRange.php b/classes/tax/TaxChildRange.php
similarity index 89%
rename from classes/tourismtax/TourismTaxChildRange.php
rename to classes/tax/TaxChildRange.php
index 207f92df0..17a8ce965 100644
--- a/classes/tourismtax/TourismTaxChildRange.php
+++ b/classes/tax/TaxChildRange.php
@@ -21,17 +21,17 @@
* @license https://opensource.org/license/osl-3-0-php Open Software License version 3.0
*/
-class TourismTaxChildRangeCore extends ObjectModel
+class TaxChildRangeCore extends ObjectModel
{
- public $id_child_range;
+ public $id_tax_child_range;
public $id_tax;
public $min_age;
public $max_age;
public $tax_value;
public static $definition = array(
- 'table' => 'tourism_tax_child_range',
- 'primary' => 'id_child_range',
+ 'table' => 'tax_child_range',
+ 'primary' => 'id_tax_child_range',
'fields' => array(
'id_tax' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
'min_age' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
@@ -41,7 +41,7 @@ class TourismTaxChildRangeCore extends ObjectModel
);
/**
- * All child age ranges for a tax in entry order (id_child_range order), cached per request.
+ * All child age ranges for a tax in entry order (id_tax_child_range order), cached per request.
*
* @param int $idTax
* @return array
@@ -49,15 +49,15 @@ class TourismTaxChildRangeCore extends ObjectModel
public static function getByTaxId($idTax)
{
$idTax = (int) $idTax;
- $cacheId = 'TourismTaxChildRange::getByTaxId-' . $idTax;
+ $cacheId = 'TaxChildRange::getByTaxId-' . $idTax;
if (Cache::isStored($cacheId)) {
return Cache::retrieve($cacheId);
}
$ranges = Db::getInstance()->executeS(
- 'SELECT * FROM `' . _DB_PREFIX_ . 'tourism_tax_child_range`
+ 'SELECT * FROM `' . _DB_PREFIX_ . 'tax_child_range`
WHERE `id_tax` = ' . $idTax . '
- ORDER BY `id_child_range` ASC'
+ ORDER BY `id_tax_child_range` ASC'
);
Cache::store($cacheId, $ranges);
@@ -76,14 +76,14 @@ class TourismTaxChildRangeCore extends ObjectModel
public static function saveAll($idTax, array $mins, array $maxs, array $values)
{
Db::getInstance()->execute(
- 'DELETE FROM `' . _DB_PREFIX_ . 'tourism_tax_child_range`
+ 'DELETE FROM `' . _DB_PREFIX_ . 'tax_child_range`
WHERE `id_tax` = ' . (int) $idTax
);
foreach ($values as $i => $value) {
if ($value === '' || $value === false) {
continue;
}
- $range = new TourismTaxChildRange();
+ $range = new TaxChildRange();
$range->id_tax = (int) $idTax;
$range->min_age = isset($mins[$i]) ? (int) $mins[$i] : 0;
$range->max_age = isset($maxs[$i]) ? (int) $maxs[$i] : 0;
diff --git a/classes/tourismtax/TourismTax.php b/classes/tax/TaxConfiguration.php
similarity index 88%
rename from classes/tourismtax/TourismTax.php
rename to classes/tax/TaxConfiguration.php
index 7513fb5b5..ebefa26ba 100644
--- a/classes/tourismtax/TourismTax.php
+++ b/classes/tax/TaxConfiguration.php
@@ -21,11 +21,8 @@
* @license https://opensource.org/license/osl-3-0-php Open Software License version 3.0
*/
-class TourismTaxCore extends ObjectModel
+class TaxConfigurationCore extends ObjectModel
{
- const COLLECTION_TYPE_ONLINE = 0;
- const COLLECTION_TYPE_AT_HOTEL = 1;
-
const DAY_KEYS = array('mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun');
public $id_tax;
@@ -42,7 +39,7 @@ class TourismTaxCore extends ObjectModel
public $special_days;
public static $definition = array(
- 'table' => 'tourism_tax',
+ 'table' => 'tax_configuration',
'primary' => 'id_tax',
'fields' => array(
'tax_calc_type' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
@@ -73,7 +70,7 @@ class TourismTaxCore extends ObjectModel
return false;
}
$result = Db::getInstance()->insert(
- 'tourism_tax',
+ 'tax_configuration',
array(
'id_tax' => $idTax,
'tax_calc_type' => (int) $this->tax_calc_type,
@@ -99,17 +96,17 @@ class TourismTaxCore extends ObjectModel
* Load a tourism tax subtype row by id_tax, cached per request.
*
* @param int $idTax
- * @return TourismTax|false
+ * @return TaxConfiguration|false
*/
public static function getByTaxId($idTax)
{
$idTax = (int) $idTax;
- $cacheId = 'TourismTax::getByTaxId-' . $idTax;
+ $cacheId = 'TaxConfiguration::getByTaxId-' . $idTax;
if (Cache::isStored($cacheId)) {
return Cache::retrieve($cacheId);
}
- $obj = new TourismTax($idTax);
+ $obj = new TaxConfiguration($idTax);
$result = Validate::isLoadedObject($obj) ? $obj : false;
Cache::store($cacheId, $result);
@@ -190,11 +187,11 @@ class TourismTaxCore extends ObjectModel
if (parent::delete()) {
$idTax = (int) $this->id;
Db::getInstance()->execute(
- 'DELETE FROM `' . _DB_PREFIX_ . 'tourism_tax_tier`
+ 'DELETE FROM `' . _DB_PREFIX_ . 'tax_price_tier`
WHERE `id_tax` = ' . $idTax
);
Db::getInstance()->execute(
- 'DELETE FROM `' . _DB_PREFIX_ . 'tourism_tax_child_range`
+ 'DELETE FROM `' . _DB_PREFIX_ . 'tax_child_range`
WHERE `id_tax` = ' . $idTax
);
return true;
@@ -205,12 +202,12 @@ class TourismTaxCore extends ObjectModel
/**
* Whether tourism tax should be visually folded into the displayed room/service price.
*
- * @param float $tourismTaxOnline
+ * @param float $tourismTax
* @return bool
*/
- public static function isGrossedUp($tourismTaxOnline)
+ public static function isGrossedUp($tourismTax)
{
- return (float) $tourismTaxOnline > 0 && (bool) Configuration::get('QLO_TOURISM_TAX_GROSSED_UP');
+ return (float) $tourismTax > 0 && (bool) Configuration::get('QLO_TOURISM_TAX_GROSSED_UP');
}
/**
@@ -235,7 +232,7 @@ class TourismTaxCore extends ObjectModel
$address = $fallbackAddress;
}
- $collectionType = self::COLLECTION_TYPE_ONLINE;
+ $collectionType = HotelBranchInformation::TAX_COLLECTION_TYPE_ONLINE;
if ($idHotel && Validate::isLoadedObject($hotelBranch = new HotelBranchInformation($idHotel))) {
$collectionType = (int) $hotelBranch->tourism_tax_collection_type;
}
@@ -310,25 +307,45 @@ class TourismTaxCore extends ObjectModel
* @param int $idLang
* @return array List of ['tax_calc_type','is_tiered','tax_value','tiers']
*/
- public static function getPreviewParams($idTaxRulesGroup, Address $address, $idLang, $collectionType = self::COLLECTION_TYPE_ONLINE)
+ public static function getPreviewParams($idTaxRulesGroup, Address $address, $idLang, $collectionType = HotelBranchInformation::TAX_COLLECTION_TYPE_ONLINE)
{
$idTaxRulesGroup = (int) $idTaxRulesGroup;
- if (!$idTaxRulesGroup || Tax::excludeTaxeOption() || (int) $collectionType === self::COLLECTION_TYPE_AT_HOTEL) {
+ if (!$idTaxRulesGroup || Tax::excludeTaxeOption() || (int) $collectionType === HotelBranchInformation::TAX_COLLECTION_TYPE_AT_HOTEL) {
return array();
}
$taxCalculator = TaxManagerFactory::getManager($address, $idTaxRulesGroup)->getTaxCalculator();
$preview = array();
+ $today = new DateTime();
+ $todayDayKey = self::DAY_KEYS[$today->format('N') - 1];
+
foreach ($taxCalculator->taxes as $tax) {
$tourismTax = self::getByTaxId((int) $tax->id);
if (!$tourismTax) {
continue;
}
+ if (!empty($tourismTax->valid_from) && $tourismTax->valid_from !== '0000-00-00'
+ && $today < new DateTime($tourismTax->valid_from)
+ ) {
+ continue;
+ }
+ if (!empty($tourismTax->valid_to) && $tourismTax->valid_to !== '0000-00-00'
+ && $today > new DateTime($tourismTax->valid_to)
+ ) {
+ continue;
+ }
+ if ($tourismTax->special_days) {
+ $specialDays = json_decode($tourismTax->special_days, true);
+ if (!is_array($specialDays) || !in_array($todayDayKey, $specialDays)) {
+ continue;
+ }
+ }
+
$tiers = array();
if ((bool) $tourismTax->is_tiered) {
- foreach (TourismTaxTier::getByTaxId((int) $tax->id) as $tier) {
+ foreach (TaxPriceTier::getByTaxId((int) $tax->id) as $tier) {
$tiers[] = array(
'min_amount' => (float) $tier['min_amount'],
'max_amount' => (float) $tier['max_amount'],
diff --git a/classes/tourismtax/TourismTaxTier.php b/classes/tax/TaxPriceTier.php
similarity index 85%
rename from classes/tourismtax/TourismTaxTier.php
rename to classes/tax/TaxPriceTier.php
index 21d0beb48..6bfb23d65 100644
--- a/classes/tourismtax/TourismTaxTier.php
+++ b/classes/tax/TaxPriceTier.php
@@ -21,17 +21,17 @@
* @license https://opensource.org/license/osl-3-0-php Open Software License version 3.0
*/
-class TourismTaxTierCore extends ObjectModel
+class TaxPriceTierCore extends ObjectModel
{
- public $id_tier;
+ public $id_tax_price_tier;
public $id_tax;
public $min_amount;
public $max_amount;
public $tax_value;
public static $definition = array(
- 'table' => 'tourism_tax_tier',
- 'primary' => 'id_tier',
+ 'table' => 'tax_price_tier',
+ 'primary' => 'id_tax_price_tier',
'fields' => array(
'id_tax' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
'min_amount' => array('type' => self::TYPE_FLOAT, 'validate' => 'isUnsignedFloat'),
@@ -41,7 +41,7 @@ class TourismTaxTierCore extends ObjectModel
);
/**
- * All tiers for a tax in entry order (id_tier order), cached per request.
+ * All tiers for a tax in entry order (id_tax_price_tier order), cached per request.
*
* @param int $idTax
* @return array
@@ -49,15 +49,15 @@ class TourismTaxTierCore extends ObjectModel
public static function getByTaxId($idTax)
{
$idTax = (int) $idTax;
- $cacheId = 'TourismTaxTier::getByTaxId-' . $idTax;
+ $cacheId = 'TaxPriceTier::getByTaxId-' . $idTax;
if (Cache::isStored($cacheId)) {
return Cache::retrieve($cacheId);
}
$tiers = Db::getInstance()->executeS(
- 'SELECT * FROM `' . _DB_PREFIX_ . 'tourism_tax_tier`
+ 'SELECT * FROM `' . _DB_PREFIX_ . 'tax_price_tier`
WHERE `id_tax` = ' . $idTax . '
- ORDER BY `id_tier` ASC'
+ ORDER BY `id_tax_price_tier` ASC'
);
Cache::store($cacheId, $tiers);
@@ -79,7 +79,7 @@ class TourismTaxTierCore extends ObjectModel
foreach ($tiers as $tier) {
$maxAmount = (float) $tier['max_amount'];
$inLower = ($unitPrice >= (float) $tier['min_amount']);
- $inUpper = ($maxAmount == 0 || $unitPrice < $maxAmount);
+ $inUpper = ($maxAmount == 0 || $unitPrice <= $maxAmount);
if ($inLower && $inUpper) {
return $tier;
}
@@ -100,14 +100,14 @@ class TourismTaxTierCore extends ObjectModel
{
$idTax = (int) $idTax;
Db::getInstance()->execute(
- 'DELETE FROM `' . _DB_PREFIX_ . 'tourism_tax_tier`
+ 'DELETE FROM `' . _DB_PREFIX_ . 'tax_price_tier`
WHERE `id_tax` = ' . $idTax
);
foreach ($values as $i => $value) {
if ($value === '' || $value === false) {
continue;
}
- $tier = new TourismTaxTier();
+ $tier = new TaxPriceTier();
$tier->id_tax = $idTax;
$tier->min_amount = isset($mins[$i]) ? (float) $mins[$i] : 0;
$tier->max_amount = isset($maxs[$i]) ? (float) $maxs[$i] : 0;
diff --git a/classes/tourismtax/index.php b/classes/tourismtax/index.php
deleted file mode 100644
index 3127284d7..000000000
--- a/classes/tourismtax/index.php
+++ /dev/null
@@ -1,35 +0,0 @@
-
-* @copyright 2007-2017 PrestaShop SA
-* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
-* International Registered Trademark & Property of PrestaShop SA
-*/
-
-header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
-header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
-
-header('Cache-Control: no-store, no-cache, must-revalidate');
-header('Cache-Control: post-check=0, pre-check=0', false);
-header('Pragma: no-cache');
-
-header('Location: ../../');
-exit;
diff --git a/classes/webservice/WebserviceSpecificManagementBookings.php b/classes/webservice/WebserviceSpecificManagementBookings.php
index 19763851a..cdac61df2 100644
--- a/classes/webservice/WebserviceSpecificManagementBookings.php
+++ b/classes/webservice/WebserviceSpecificManagementBookings.php
@@ -1105,7 +1105,11 @@ class WebserviceSpecificManagementBookingsCore Extends ObjectModel implements We
$this->wsRequestedRooms[$dateRoomJoinKey]['id_tax_rules_group'] = $this->createTaxRule(($this->wsRequestedRooms[$dateRoomJoinKey]['total_tax']/$objHotelBookingDetail->total_price_tax_excl)*100, $objAddress);
} else if (isset($this->wsRequestedRooms[$dateRoomJoinKey]['total_tax'])) {
$objOrderDetail->id_tax_rules_group = 0;
- Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'order_detail_tax` WHERE id_order_detail='.(int)$objOrderDetail->id);
+ Db::getInstance()->execute(
+ 'DELETE otd FROM `'._DB_PREFIX_.'order_tax_detail` otd
+ WHERE otd.`id_order_detail` = '.(int)$objOrderDetail->id.'
+ AND NOT EXISTS (SELECT 1 FROM `'._DB_PREFIX_.'tax` tc WHERE tc.`id_tax` = otd.`id_tax` AND tc.`is_tourism_tax` = 1)'
+ );
$priceWithTax = $objHotelBookingDetail->total_price_tax_excl + $this->wsRequestedRooms[$dateRoomJoinKey]['total_tax'];
}
@@ -1134,7 +1138,7 @@ class WebserviceSpecificManagementBookingsCore Extends ObjectModel implements We
$objOrderDetail->save();
if (isset($this->wsRequestedRooms[$dateRoomJoinKey]['id_tax_rules_group'])) {
- $this->saveTaxCalculator($objOrderDetail->id, $this->wsRequestedRooms[$dateRoomJoinKey]['id_tax_rules_group']);
+ $this->saveTaxCalculator($objOrderDetail->id, $this->wsRequestedRooms[$dateRoomJoinKey]['id_tax_rules_group'], (int) $objHotelBookingDetail->id, 0);
}
$objOrder->total_paid += $taxDiff;
$objOrder->total_paid_tax_incl += $taxDiff;
@@ -1146,17 +1150,22 @@ class WebserviceSpecificManagementBookingsCore Extends ObjectModel implements We
}
}
- public function saveTaxCalculator($idOrderDetail, $idTaxRulesGroup)
+ public function saveTaxCalculator($idOrderDetail, $idTaxRulesGroup, $idHtlBooking = 0, $idServiceProductOrderDetail = 0)
{
- Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'order_detail_tax` WHERE id_order_detail='.(int)$idOrderDetail);
+ Db::getInstance()->execute(
+ 'DELETE otd FROM `'._DB_PREFIX_.'order_tax_detail` otd
+ WHERE otd.`id_order_detail` = '.(int)$idOrderDetail.'
+ AND NOT EXISTS (SELECT 1 FROM `'._DB_PREFIX_.'tax` tc WHERE tc.`id_tax` = otd.`id_tax` AND tc.`is_tourism_tax` = 1)'
+ );
$idTax = $this->wsTaxRulesGroup[$idTaxRulesGroup]['tax'];
$objOrderDetail = new OrderDetail($idOrderDetail);
- $values = '('.(int)$objOrderDetail->id.','.(int)$idTax.','.
+ $values = '('.(int)$objOrderDetail->id_order.','.(int)$objOrderDetail->id.','.(int)$idHtlBooking.','.(int)$idServiceProductOrderDetail.','.(int)$idTax.','.
(float)($objOrderDetail->unit_price_tax_incl - $objOrderDetail->unit_price_tax_excl).','.
- (float)($objOrderDetail->total_price_tax_incl - $objOrderDetail->total_price_tax_excl).'),';
+ (float)($objOrderDetail->total_price_tax_incl - $objOrderDetail->total_price_tax_excl).',NOW()),';
$values = rtrim($values, ',');
- $sql = 'INSERT INTO `'._DB_PREFIX_.'order_detail_tax` (id_order_detail, id_tax, unit_amount, total_amount)
+ $sql = 'INSERT INTO `'._DB_PREFIX_.'order_tax_detail`
+ (id_order, id_order_detail, id_htl_booking, id_service_product_order_detail, id_tax, unit_amount, total_amount, date_add)
VALUES '.$values;
return Db::getInstance()->execute($sql);
@@ -1267,7 +1276,11 @@ class WebserviceSpecificManagementBookingsCore Extends ObjectModel implements We
$this->wsRequestedRoomTypes[$dateRoomJoinKey]['services'][$service['id_product']]['id_tax_rules_group'] = $this->createTaxRule(($this->wsRequestedRoomTypes[$dateRoomJoinKey]['services'][$service['id_product']]['total_tax']/$objServiceProductOrderDetail->total_price_tax_excl)*100, $objAddress);
} else if (isset($this->wsRequestedRoomTypes[$dateRoomJoinKey]['services'][$service['id_product']]['total_tax'])) {
$objOrderDetail->id_tax_rules_group = 0;
- Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'order_detail_tax` WHERE id_order_detail='.(int)$objOrderDetail->id);
+ Db::getInstance()->execute(
+ 'DELETE otd FROM `'._DB_PREFIX_.'order_tax_detail` otd
+ WHERE otd.`id_order_detail` = '.(int)$objOrderDetail->id.'
+ AND NOT EXISTS (SELECT 1 FROM `'._DB_PREFIX_.'tax` tc WHERE tc.`id_tax` = otd.`id_tax` AND tc.`is_tourism_tax` = 1)'
+ );
$unitPriceTaxIncl = $objServiceProductOrderDetail->total_price_tax_excl + $this->wsRequestedRoomTypes[$dateRoomJoinKey]['services'][$service['id_product']]['total_tax'];
$priceDiffTaxIncl = $unitPriceTaxIncl - $objServiceProductOrderDetail->total_price_tax_incl;
@@ -1296,7 +1309,7 @@ class WebserviceSpecificManagementBookingsCore Extends ObjectModel implements We
$objServiceProductOrderDetail->save();
$objOrderDetail->save();
if (!$isAutoAdded && isset($this->wsRequestedRoomTypes[$dateRoomJoinKey]['services'][$service['id_product']]['id_tax_rules_group'])) {
- $this->saveTaxCalculator($objOrderDetail->id, $this->wsRequestedRoomTypes[$dateRoomJoinKey]['services'][$service['id_product']]['id_tax_rules_group']);
+ $this->saveTaxCalculator($objOrderDetail->id, $this->wsRequestedRoomTypes[$dateRoomJoinKey]['services'][$service['id_product']]['id_tax_rules_group'], 0, (int) $objServiceProductOrderDetail->id);
}
}
}
@@ -2375,7 +2388,11 @@ class WebserviceSpecificManagementBookingsCore Extends ObjectModel implements We
$this->wsRequestedRoomTypes[$dateRoomJoinKey]['services'][$service['id_product']]['id_tax_rules_group'] = $this->createTaxRule(($this->wsRequestedRoomTypes[$dateRoomJoinKey]['services'][$service['id_product']]['total_tax']/$totalPriceTaxExcl)*100, $objAddress);
} else if (isset($this->wsRequestedRoomTypes[$dateRoomJoinKey]['services'][$service['id_product']]['total_tax'])) {
$objOrderDetail->id_tax_rules_group = 0;
- Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'order_detail_tax` WHERE id_order_detail='.(int)$objOrderDetail->id);
+ Db::getInstance()->execute(
+ 'DELETE otd FROM `'._DB_PREFIX_.'order_tax_detail` otd
+ WHERE otd.`id_order_detail` = '.(int)$objOrderDetail->id.'
+ AND NOT EXISTS (SELECT 1 FROM `'._DB_PREFIX_.'tax` tc WHERE tc.`id_tax` = otd.`id_tax` AND tc.`is_tourism_tax` = 1)'
+ );
$unitPriceTaxIncl = $objServiceProductOrderDetail->total_price_tax_excl + $this->wsRequestedRoomTypes[$dateRoomJoinKey]['services'][$service['id_product']]['total_tax'];
$priceDiffTaxIncl = $unitPriceTaxIncl - $objServiceProductOrderDetail->total_price_tax_incl;
}
@@ -2434,7 +2451,7 @@ class WebserviceSpecificManagementBookingsCore Extends ObjectModel implements We
}
if (!$isAutoAdded && isset($this->wsRequestedRoomTypes[$dateRoomJoinKey]['services'][$service['id_product']]['id_tax_rules_group'])) {
- $this->saveTaxCalculator($objOrderDetail->id, $this->wsRequestedRoomTypes[$dateRoomJoinKey]['services'][$service['id_product']]['id_tax_rules_group']);
+ $this->saveTaxCalculator($objOrderDetail->id, $this->wsRequestedRoomTypes[$dateRoomJoinKey]['services'][$service['id_product']]['id_tax_rules_group'], 0, (int) $objServiceProductOrderDetail->id);
}
}
@@ -3340,7 +3357,11 @@ class WebserviceSpecificManagementBookingsCore Extends ObjectModel implements We
$unitPriceTaxIncl = Tools::ps_round($totalPriceTaxIncl / $quantity, _PS_PRICE_COMPUTE_PRECISION_);
} else if (isset($services[$product['id_product']]['total_tax'])) {
$objOrderDetail->id_tax_rules_group = 0;
- Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'order_detail_tax` WHERE id_order_detail='.(int)$objOrderDetail->id);
+ Db::getInstance()->execute(
+ 'DELETE otd FROM `'._DB_PREFIX_.'order_tax_detail` otd
+ WHERE otd.`id_order_detail` = '.(int)$objOrderDetail->id.'
+ AND NOT EXISTS (SELECT 1 FROM `'._DB_PREFIX_.'tax` tc WHERE tc.`id_tax` = otd.`id_tax` AND tc.`is_tourism_tax` = 1)'
+ );
$unitPriceTaxIncl = $unitPriceTaxExcl + $services[$product['id_product']]['total_tax'];
$totalPriceTaxIncl = Tools::ps_round(($unitPriceTaxIncl * $quantity), _PS_PRICE_COMPUTE_PRECISION_);
}
@@ -3393,7 +3414,7 @@ class WebserviceSpecificManagementBookingsCore Extends ObjectModel implements We
$objOrderDetail->update();
if (!$isAutoAdded && isset($services[$product['id_product']]['id_tax_rules_group'])) {
- $this->saveTaxCalculator($objOrderDetail->id, $services[$product['id_product']]['id_tax_rules_group']);
+ $this->saveTaxCalculator($objOrderDetail->id, $services[$product['id_product']]['id_tax_rules_group'], 0, (int) $objServiceProductOrderDetail->id);
}
}
}
diff --git a/controllers/admin/AdminNormalProductsController.php b/controllers/admin/AdminNormalProductsController.php
index 8c0a79196..2681ad61f 100644
--- a/controllers/admin/AdminNormalProductsController.php
+++ b/controllers/admin/AdminNormalProductsController.php
@@ -588,7 +588,7 @@ class AdminNormalProductsControllerCore extends AdminController
$context = $this->context->cloneContext();
$context->shop = clone($context->shop);
$useTourismTax = (bool) Configuration::get('QLO_USE_TOURISM_TAX');
- $tourismTaxContext = $useTourismTax ? TourismTax::resolveServiceLineTaxContext(
+ $tourismTaxContext = $useTourismTax ? TaxConfiguration::resolveServiceLineTaxContext(
(int) Configuration::get('WK_PRIMARY_HOTEL'),
0,
new Address(0)
@@ -609,26 +609,25 @@ class AdminNormalProductsControllerCore extends AdminController
$unitPriceTaxExcl = Product::getPriceStatic($this->_list[$i]['id_product'], false, null,
6, null, false, true, 1, true, null, null, null, $nothing, true, true,
$context);
- $serviceTourismTax = array('tourism_tax_online' => 0.0);
+ $serviceTourismTaxAmount = 0.0;
$idTourismTaxRulesGroup = Product::getIdTourismTaxRulesGroupByIdProduct((int) $this->_list[$i]['id_product']);
if ($idTourismTaxRulesGroup) {
$taxCalculator = TaxManagerFactory::getManager(
$tourismTaxContext['address'],
$idTourismTaxRulesGroup
)->getTaxCalculator();
- $serviceTourismTax = $taxCalculator->getTourismTaxRows(
+ $serviceTourismTaxAmount = $taxCalculator->getTaxesTotalAmount(
(float) $unitPriceTaxExcl,
$tourismTaxContext['checkInDate'],
$tourismTaxContext['numNights'],
$tourismTaxContext['numAdults'],
$tourismTaxContext['childrenAges'],
- (int) $this->context->currency->id,
$tourismTaxContext['collectionType'],
- (int) $id_lang,
- 1
+ 1,
+ $this->context->currency->id
);
}
- $this->_list[$i]['price_tmp'] += (float) $serviceTourismTax['tourism_tax_online'];
+ $this->_list[$i]['price_tmp'] += $serviceTourismTaxAmount;
}
}
}
@@ -3416,7 +3415,7 @@ class AdminNormalProductsControllerCore extends AdminController
if (!$idTourismTaxRulesGroup) {
continue;
}
- $tourismTaxRates[$idTourismTaxRulesGroup] = TourismTax::getPreviewParams(
+ $tourismTaxRates[$idTourismTaxRulesGroup] = TaxConfiguration::getPreviewParams(
$idTourismTaxRulesGroup,
$address,
(int) $this->context->language->id
diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php
index f12b3e3e8..fa38e98ab 100644
--- a/controllers/admin/AdminOrdersController.php
+++ b/controllers/admin/AdminOrdersController.php
@@ -3406,8 +3406,8 @@ class AdminOrdersControllerCore extends AdminController
$totalRefundedRooms = 0;
$orderConvenienceFeeServices = array();
$useTourismTax = (bool) Configuration::get('QLO_USE_TOURISM_TAX');
- $bookingTourismTaxStatusMap = OrderTourismTax::getAppliedTourismTaxTotals($order->id, OrderTourismTax::SCOPE_ROOM_STATUS);
- $serviceTourismTaxMap = OrderTourismTax::getAppliedTourismTaxTotals($order->id, OrderTourismTax::SCOPE_SERVICE);
+ $bookingTourismTaxStatusMap = OrderTaxDetail::getAppliedTourismTaxTotals($order->id, OrderTaxDetail::SCOPE_ROOM_STATUS);
+ $serviceTourismTaxMap = OrderTaxDetail::getAppliedTourismTaxTotals($order->id, OrderTaxDetail::SCOPE_SERVICE);
if ($order_detail_data = $objBookingDetail->getOrderFormatedBookinInfoByIdOrder($order->id)) {
$objBookingDemand = new HotelBookingDemands();
$objHotelRoomType = new HotelRoomType();
@@ -3594,7 +3594,7 @@ class AdminOrdersControllerCore extends AdminController
$order_detail_data[$key]['room_type_info'] = $objHotelRoomType->getRoomTypeInfoByIdProduct($value['id_product']);
$order_detail_data[$key]['total_room_tax'] = $order_detail_data[$key]['total_room_price_ti'] - $order_detail_data[$key]['total_room_price_te'];
$bookingTourismTaxStatus = isset($bookingTourismTaxStatusMap[$value['id']]) ? $bookingTourismTaxStatusMap[$value['id']] : null;
- $order_detail_data[$key]['tourism_tax_status'] = $bookingTourismTaxStatus ? $bookingTourismTaxStatus['status'] : OrderTourismTax::STATUS_NONE;
+ $order_detail_data[$key]['tourism_tax_status'] = $bookingTourismTaxStatus ? $bookingTourismTaxStatus['status'] : OrderTaxDetail::STATUS_NONE;
$roomTourismTaxTotal = $bookingTourismTaxStatus ? $bookingTourismTaxStatus['total'] : 0.0;
$serviceTourismTaxTotal = isset($serviceTourismTaxMap[$value['id']]) ? $serviceTourismTaxMap[$value['id']] : 0.0;
$order_detail_data[$key]['tourism_tax_total'] = $roomTourismTaxTotal + $serviceTourismTaxTotal;
@@ -3620,7 +3620,7 @@ class AdminOrdersControllerCore extends AdminController
if ($useTourismTax && $order_detail_data) {
foreach ($order_detail_data as $bookingRow) {
if (isset($bookingRow['tourism_tax_status'])) {
- if ($bookingRow['tourism_tax_status'] === OrderTourismTax::STATUS_APPLIED) {
+ if ($bookingRow['tourism_tax_status'] === OrderTaxDetail::STATUS_APPLIED) {
$orderTourismTaxHasApplied = true;
} else {
$orderTourismTaxHasUnapplied = true;
@@ -3760,11 +3760,11 @@ class AdminOrdersControllerCore extends AdminController
'hotel_order_status' => $htlOrderStatus,
'order_detail_data' => $order_detail_data,
'use_tourism_tax' => $useTourismTax,
- 'tourism_tax_online_room' => array_sum(array_column($bookingTourismTaxStatusMap, 'total')),
- 'tourism_tax_online_service' => array_sum($serviceTourismTaxMap),
+ 'tourism_tax_room' => array_sum(array_column($bookingTourismTaxStatusMap, 'total')),
+ 'tourism_tax_service' => array_sum($serviceTourismTaxMap),
'info_icon_path' => $this->context->link->getMediaLink(_MODULE_DIR_.'hotelreservationsystem/views/img/Slices/icon-info.svg'),
- 'tourism_tax_status_applied' => OrderTourismTax::STATUS_APPLIED,
- 'tourism_tax_status_exempted' => OrderTourismTax::STATUS_EXEMPTED,
+ 'tourism_tax_status_applied' => OrderTaxDetail::STATUS_APPLIED,
+ 'tourism_tax_status_exempted' => OrderTaxDetail::STATUS_EXEMPTED,
'order_tourism_tax_has_applied' => $orderTourismTaxHasApplied,
'order_tourism_tax_has_unapplied' => $orderTourismTaxHasUnapplied,
'max_child_age' => Configuration::get('WK_GLOBAL_CHILD_MAX_AGE'),
@@ -5509,9 +5509,9 @@ class AdminOrdersControllerCore extends AdminController
}
$tourismTaxCollectionType = Validate::isLoadedObject($objHotelBranch)
? (int) $objHotelBranch->tourism_tax_collection_type
- : TourismTax::COLLECTION_TYPE_ONLINE;
+ : HotelBranchInformation::TAX_COLLECTION_TYPE_ONLINE;
- OrderTourismTax::saveTourismTax(
+ OrderTaxDetail::saveTourismTax(
$idTourismTaxRulesGroup,
$tourismTaxAddress,
(float) $objBookingDetail->total_price_tax_excl / $tourismTaxNumNights,
@@ -5526,8 +5526,7 @@ class AdminOrdersControllerCore extends AdminController
$order->id,
(int) $objBookingDetail->id_order_detail,
$objBookingDetail->id,
- 0,
- (int) $objCartBookingData->id_hotel
+ 0
);
// Whether the checkbox exempts this room+its services is decided once,
// after the auto-attached service loop below runs — see there for why.
@@ -5613,12 +5612,12 @@ class AdminOrdersControllerCore extends AdminController
if (Configuration::get('QLO_USE_TOURISM_TAX')) {
$idServiceTourismTaxRulesGroup = Product::getIdTourismTaxRulesGroupByIdProduct((int) $service['id_product']);
if ($idServiceTourismTaxRulesGroup) {
- $serviceTourismTaxContext = TourismTax::resolveServiceLineTaxContext(
+ $serviceTourismTaxContext = TaxConfiguration::resolveServiceLineTaxContext(
(int) $objCartBookingData->id_hotel,
$objBookingDetail->id,
new Address((int) Cart::getIdAddressForTaxCalculation((int) $service['id_product']))
);
- OrderTourismTax::saveTourismTax(
+ OrderTaxDetail::saveTourismTax(
$idServiceTourismTaxRulesGroup,
$serviceTourismTaxContext['address'],
$unitPriceTaxExcl,
@@ -5633,8 +5632,7 @@ class AdminOrdersControllerCore extends AdminController
$order->id,
(int) $objServiceProductOrderDetail->id_order_detail,
0,
- (int) $objServiceProductOrderDetail->id,
- (int) $objCartBookingData->id_hotel
+ (int) $objServiceProductOrderDetail->id
);
}
}
@@ -5643,7 +5641,7 @@ class AdminOrdersControllerCore extends AdminController
}
if (Configuration::get('QLO_USE_TOURISM_TAX') && empty($product_informations['apply_tourism_tax'])) {
- OrderTourismTax::exemptBooking($objBookingDetail->id);
+ OrderTaxDetail::exemptBooking($objBookingDetail->id);
}
}
}
@@ -6439,9 +6437,9 @@ class AdminOrdersControllerCore extends AdminController
}
}
if (Configuration::get('QLO_USE_TOURISM_TAX')) {
- $roomTourismTaxParams = OrderTourismTax::buildRoomTaxParams((int) $obj_booking_detail->id);
+ $roomTourismTaxParams = OrderTaxDetail::buildRoomTaxParams((int) $obj_booking_detail->id);
if ($roomTourismTaxParams) {
- OrderTourismTax::saveTourismTax(
+ OrderTaxDetail::saveTourismTax(
$roomTourismTaxParams['idTaxRulesGroup'],
$roomTourismTaxParams['address'],
$roomTourismTaxParams['unitPriceTaxExcl'],
@@ -6456,17 +6454,16 @@ class AdminOrdersControllerCore extends AdminController
$roomTourismTaxParams['idOrder'],
$roomTourismTaxParams['idOrderDetail'],
$roomTourismTaxParams['idHtlBooking'],
- $roomTourismTaxParams['idServiceProductOrderDetail'],
- $roomTourismTaxParams['idHotel']
+ $roomTourismTaxParams['idServiceProductOrderDetail']
);
}
foreach (ServiceProductOrderDetail::getActiveIdsByHtlBookingDetail((int) $obj_booking_detail->id) as $idActiveServiceLine) {
- $serviceTourismTaxParams = OrderTourismTax::buildServiceLineTaxParams($idActiveServiceLine);
+ $serviceTourismTaxParams = OrderTaxDetail::buildServiceLineTaxParams($idActiveServiceLine);
if (!$serviceTourismTaxParams) {
continue;
}
- OrderTourismTax::saveTourismTax(
+ OrderTaxDetail::saveTourismTax(
$serviceTourismTaxParams['idTaxRulesGroup'],
$serviceTourismTaxParams['address'],
$serviceTourismTaxParams['unitPriceTaxExcl'],
@@ -6481,8 +6478,7 @@ class AdminOrdersControllerCore extends AdminController
$serviceTourismTaxParams['idOrder'],
$serviceTourismTaxParams['idOrderDetail'],
$serviceTourismTaxParams['idHtlBooking'],
- $serviceTourismTaxParams['idServiceProductOrderDetail'],
- $serviceTourismTaxParams['idHotel']
+ $serviceTourismTaxParams['idServiceProductOrderDetail']
);
}
}
@@ -6934,7 +6930,7 @@ class AdminOrdersControllerCore extends AdminController
$objBookingDemand->deleteBookingDemands($idHotelBooking);
if (Configuration::get('QLO_USE_TOURISM_TAX')) {
- OrderTourismTax::hardDeleteForBooking(
+ OrderTaxDetail::hardDeleteForBooking(
$idHotelBooking,
ServiceProductOrderDetail::getActiveIdsByHtlBookingDetail($idHotelBooking)
);
@@ -8153,9 +8149,9 @@ class AdminOrdersControllerCore extends AdminController
$objServiceProductOrderDetail->save();
if (Configuration::get('QLO_USE_TOURISM_TAX')
- && ($serviceTourismTaxParams = OrderTourismTax::buildServiceLineTaxParams((int) $objServiceProductOrderDetail->id))
+ && ($serviceTourismTaxParams = OrderTaxDetail::buildServiceLineTaxParams((int) $objServiceProductOrderDetail->id))
) {
- OrderTourismTax::saveTourismTax(
+ OrderTaxDetail::saveTourismTax(
$serviceTourismTaxParams['idTaxRulesGroup'],
$serviceTourismTaxParams['address'],
$serviceTourismTaxParams['unitPriceTaxExcl'],
@@ -8170,8 +8166,7 @@ class AdminOrdersControllerCore extends AdminController
$serviceTourismTaxParams['idOrder'],
$serviceTourismTaxParams['idOrderDetail'],
$serviceTourismTaxParams['idHtlBooking'],
- $serviceTourismTaxParams['idServiceProductOrderDetail'],
- $serviceTourismTaxParams['idHotel']
+ $serviceTourismTaxParams['idServiceProductOrderDetail']
);
}
@@ -8466,9 +8461,9 @@ class AdminOrdersControllerCore extends AdminController
$objServiceProductOrderDetail->save();
if (Configuration::get('QLO_USE_TOURISM_TAX')
- && ($serviceTourismTaxParams = OrderTourismTax::buildServiceLineTaxParams((int) $objServiceProductOrderDetail->id))
+ && ($serviceTourismTaxParams = OrderTaxDetail::buildServiceLineTaxParams((int) $objServiceProductOrderDetail->id))
) {
- OrderTourismTax::saveTourismTax(
+ OrderTaxDetail::saveTourismTax(
$serviceTourismTaxParams['idTaxRulesGroup'],
$serviceTourismTaxParams['address'],
$serviceTourismTaxParams['unitPriceTaxExcl'],
@@ -8483,8 +8478,7 @@ class AdminOrdersControllerCore extends AdminController
$serviceTourismTaxParams['idOrder'],
$serviceTourismTaxParams['idOrderDetail'],
$serviceTourismTaxParams['idHtlBooking'],
- $serviceTourismTaxParams['idServiceProductOrderDetail'],
- $serviceTourismTaxParams['idHotel']
+ $serviceTourismTaxParams['idServiceProductOrderDetail']
);
}
@@ -9191,7 +9185,7 @@ class AdminOrdersControllerCore extends AdminController
/**
* Map per-booking tourism tax apply/exempt failures (whole-order bulk case) to deduplicated messages.
*
- * @param array $failures [{'id_htl_booking', 'result'}, ...] — see OrderTourismTax::applyForOrder()/exemptForOrder()
+ * @param array $failures [{'id_htl_booking', 'result'}, ...] — see OrderTaxDetail::applyForOrder()/exemptForOrder()
* @param array $messagesByResult [resultCode => '%s: ...' sprintf template]
* @return string[]
*/
@@ -9209,7 +9203,7 @@ class AdminOrdersControllerCore extends AdminController
}
/**
- * Apply tourism tax to a booking (id_htl_booking) or every booking of a whole order (id_order) — see OrderTourismTax::applyBooking().
+ * Apply tourism tax to a booking (id_htl_booking) or every booking of a whole order (id_order) — see OrderTaxDetail::applyBooking().
*/
public function ajaxProcessApplyTourismTax()
{
@@ -9219,17 +9213,17 @@ class AdminOrdersControllerCore extends AdminController
if ($idHtlBooking) {
$messagesByResult = array(
- OrderTourismTax::APPLY_ERROR_RESTORE => $this->l('Could not restore tourism tax.'),
- OrderTourismTax::APPLY_ERROR_REFUNDED => $this->l('Tourism tax cannot be applied, this was refunded.'),
+ OrderTaxDetail::APPLY_ERROR_RESTORE => $this->l('Could not restore tourism tax.'),
+ OrderTaxDetail::APPLY_ERROR_REFUNDED => $this->l('Tourism tax cannot be applied, this was refunded.'),
);
- $result = OrderTourismTax::applyBooking($idHtlBooking);
+ $result = OrderTaxDetail::applyBooking($idHtlBooking);
if (isset($messagesByResult[$result])) {
$errors[] = $messagesByResult[$result];
}
} elseif ($idOrder) {
- $errors = $this->tourismTaxErrorsFromResults(OrderTourismTax::applyForOrder($idOrder), array(
- OrderTourismTax::APPLY_ERROR_RESTORE => $this->l('%s: could not restore tourism tax.'),
- OrderTourismTax::APPLY_ERROR_REFUNDED => $this->l('%s: tourism tax cannot be applied, this was refunded.'),
+ $errors = $this->tourismTaxErrorsFromResults(OrderTaxDetail::applyForOrder($idOrder), array(
+ OrderTaxDetail::APPLY_ERROR_RESTORE => $this->l('%s: could not restore tourism tax.'),
+ OrderTaxDetail::APPLY_ERROR_REFUNDED => $this->l('%s: tourism tax cannot be applied, this was refunded.'),
));
} else {
$errors[] = $this->l('Invalid request parameters.');
@@ -9242,7 +9236,7 @@ class AdminOrdersControllerCore extends AdminController
}
/**
- * Exempt tourism tax for a booking (id_htl_booking) or every booking of a whole order (id_order) — see OrderTourismTax::exemptBooking().
+ * Exempt tourism tax for a booking (id_htl_booking) or every booking of a whole order (id_order) — see OrderTaxDetail::exemptBooking().
*/
public function ajaxProcessExemptTourismTax()
{
@@ -9255,17 +9249,17 @@ class AdminOrdersControllerCore extends AdminController
if ($idHtlBooking) {
$messagesByResult = array(
- OrderTourismTax::EXEMPT_ERROR_SAVE => $this->l('Could not exempt tourism tax.'),
- OrderTourismTax::EXEMPT_ERROR_REFUNDED => $this->l('Tourism tax cannot be exempted, this was refunded.'),
+ OrderTaxDetail::EXEMPT_ERROR_SAVE => $this->l('Could not exempt tourism tax.'),
+ OrderTaxDetail::EXEMPT_ERROR_REFUNDED => $this->l('Tourism tax cannot be exempted, this was refunded.'),
);
- $result = OrderTourismTax::exemptBooking($idHtlBooking, $idEmployee, $note);
+ $result = OrderTaxDetail::exemptBooking($idHtlBooking, $idEmployee, $note);
if (isset($messagesByResult[$result])) {
$errors[] = $messagesByResult[$result];
}
} elseif ($idOrder) {
- $errors = $this->tourismTaxErrorsFromResults(OrderTourismTax::exemptForOrder($idOrder, $idEmployee, $note), array(
- OrderTourismTax::EXEMPT_ERROR_SAVE => $this->l('%s: could not exempt tourism tax.'),
- OrderTourismTax::EXEMPT_ERROR_REFUNDED => $this->l('%s: tourism tax cannot be exempted, this was refunded.'),
+ $errors = $this->tourismTaxErrorsFromResults(OrderTaxDetail::exemptForOrder($idOrder, $idEmployee, $note), array(
+ OrderTaxDetail::EXEMPT_ERROR_SAVE => $this->l('%s: could not exempt tourism tax.'),
+ OrderTaxDetail::EXEMPT_ERROR_REFUNDED => $this->l('%s: tourism tax cannot be exempted, this was refunded.'),
));
} else {
$errors[] = $this->l('Invalid request parameters.');
diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php
index 20cdd2059..58d308fe4 100644
--- a/controllers/admin/AdminProductsController.php
+++ b/controllers/admin/AdminProductsController.php
@@ -738,19 +738,23 @@ class AdminProductsControllerCore extends AdminController
$idTourismTaxRulesGroup = (int) $this->_list[$i]['id_tourism_tax_rules_group'];
$idHotel = (int) $this->_list[$i]['id_hotel'];
if ($useTourismTax && $idTourismTaxRulesGroup && $idHotel) {
- $roomTotalPrice = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice(
- $this->_list[$i]['id_product'],
+ $idProduct = $this->_list[$i]['id_product'];
+ $vatAddress = new Address(HotelRoomType::getHotelIdAddressByIdProduct($idProduct));
+ $vatCalculator = TaxManagerFactory::getManager($vatAddress, Product::getIdTaxRulesGroupByIdProduct($idProduct))->getTaxCalculator();
+ $unitPriceTaxExcl = $vatCalculator->removeTaxes($this->_list[$i]['price_tmp']);
+
+ $hotelTaxContext = TaxConfiguration::resolveHotelAddressAndCollectionType($idHotel, $vatAddress);
+ $taxCalculator = TaxManagerFactory::getManager($hotelTaxContext['address'], $idTourismTaxRulesGroup)->getTaxCalculator();
+ $this->_list[$i]['price_tmp'] += $taxCalculator->getTaxesTotalAmount(
+ $unitPriceTaxExcl,
$todayDate,
- $tomorrowDate,
- array(array('adults' => 1, 'children' => 0, 'child_ages' => array())),
- 0,
- 0,
- 0,
- 0,
- 0,
- 1
+ 1,
+ 1,
+ array(),
+ $hotelTaxContext['collectionType'],
+ 1,
+ $this->context->currency->id
);
- $this->_list[$i]['price_tmp'] += (float) $roomTotalPrice['tourism_tax_online'];
}
}
}
@@ -4192,26 +4196,16 @@ class AdminProductsControllerCore extends AdminController
$data->assign('tourismTaxRulesGroups', $tourismTaxRulesGroups);
$data->assign('id_tourism_tax_rules_group', isset($product->id_tourism_tax_rules_group) ? (int) $product->id_tourism_tax_rules_group : 0);
- // Same "no matching rule -> naturally empty" pattern as the VAT rates loop above
- // (TaxManagerFactory::getManager($address, $trg)->taxes coming back empty for a
- // non-matching country) — here the mismatch is the hotel's collection type instead
- // of the address, so getPreviewParams() is handed it to resolve the same way.
$roomTypeInfo = (new HotelRoomType())->getRoomTypeInfoByIdProduct((int) $product->id);
$idHotel = $roomTypeInfo ? (int) $roomTypeInfo['id_hotel'] : 0;
- $collectionType = TourismTax::resolveHotelAddressAndCollectionType($idHotel, $address)['collectionType'];
+ $collectionType = TaxConfiguration::resolveHotelAddressAndCollectionType($idHotel, $address)['collectionType'];
$tourismTaxRates = array();
foreach ($tourismTaxRulesGroups as $tourismTaxRulesGroup) {
- $idTourismTaxRulesGroup = (int) $tourismTaxRulesGroup['id_tax_rules_group'];
- if (!$idTourismTaxRulesGroup) {
+ if (!$tourismTaxRulesGroup['id_tax_rules_group']) {
continue;
}
- $tourismTaxRates[$idTourismTaxRulesGroup] = TourismTax::getPreviewParams(
- $idTourismTaxRulesGroup,
- $address,
- (int) $this->context->language->id,
- $collectionType
- );
+ $tourismTaxRates[$tourismTaxRulesGroup['id_tax_rules_group']] = TaxConfiguration::getPreviewParams($tourismTaxRulesGroup['id_tax_rules_group'], $address, $this->context->language->id, $collectionType);
}
$data->assign('tourismTaxRatesByGroup', $tourismTaxRates);
}
diff --git a/controllers/admin/AdminTaxRulesGroupController.php b/controllers/admin/AdminTaxRulesGroupController.php
index d462545b1..f94b8e5e1 100644
--- a/controllers/admin/AdminTaxRulesGroupController.php
+++ b/controllers/admin/AdminTaxRulesGroupController.php
@@ -126,7 +126,7 @@ class AdminTaxRulesGroupControllerCore extends AdminController
$sql->from('tax', 't');
$sql->leftJoin('tax_lang', 'tl', 't.`id_tax` = tl.`id_tax` AND tl.`id_lang` = ' . $idLang);
if ($isTourism) {
- $sql->leftJoin('tourism_tax', 'tourism_tax', 'tourism_tax.`id_tax` = t.`id_tax`');
+ $sql->leftJoin('tax_configuration', 'tourism_tax', 'tourism_tax.`id_tax` = t.`id_tax`');
}
$sql->where('t.`deleted` != 1 AND t.`active` = 1');
$sql->where('t.`is_tourism_tax` = ' . ($isTourism ? 1 : 0));
@@ -209,7 +209,7 @@ class AdminTaxRulesGroupControllerCore extends AdminController
ON (a.`id_state` = s.`id_state`)
LEFT JOIN `'._DB_PREFIX_.'tax` t
ON (a.`id_tax` = t.`id_tax`)
- LEFT JOIN `'._DB_PREFIX_.'tourism_tax` tourism_tax
+ LEFT JOIN `'._DB_PREFIX_.'tax_configuration` tourism_tax
ON (tourism_tax.`id_tax` = t.`id_tax`)';
$this->_where = 'AND `id_tax_rules_group` = '.(int)$id_group;
$this->_use_found_rows = false;
@@ -457,7 +457,7 @@ class AdminTaxRulesGroupControllerCore extends AdminController
*/
public function displayTaxRuleRate($value, $row)
{
- return TourismTax::getFormattedRateForDisplay($value, $row, $this->context->currency);
+ return TaxConfiguration::getFormattedRateForDisplay($value, $row, $this->context->currency);
}
public function postProcess()
diff --git a/controllers/admin/AdminTaxesController.php b/controllers/admin/AdminTaxesController.php
index 8a9e264fd..ec7fb6cec 100644
--- a/controllers/admin/AdminTaxesController.php
+++ b/controllers/admin/AdminTaxesController.php
@@ -148,7 +148,7 @@ class AdminTaxesControllerCore extends AdminController
parent::__construct();
$this->_where .= ' AND a.deleted = 0';
- $this->_join .= ' LEFT JOIN `'._DB_PREFIX_.'tourism_tax` tourism_tax ON tourism_tax.`id_tax` = a.`id_tax`';
+ $this->_join .= ' LEFT JOIN `'._DB_PREFIX_.'tax_configuration` tourism_tax ON tourism_tax.`id_tax` = a.`id_tax`';
$extraSelect = 'IFNULL(tourism_tax.`tax_calc_type`, 0) AS `tourism_tax_calc_type`, IFNULL(tourism_tax.`tax_value`, 0) AS `tourism_tax_value`';
$this->_select = ($this->_select ? $this->_select . ', ' : '') . $extraSelect;
}
@@ -244,7 +244,7 @@ class AdminTaxesControllerCore extends AdminController
$isAnySubmit = Tools::isSubmit('submitAdd' . $this->table) || Tools::isSubmit('submitAdd' . $this->table . 'AndStay');
if ($idTax && !$isAnySubmit) {
- $subtype = TourismTax::getByTaxId($idTax);
+ $subtype = TaxConfiguration::getByTaxId($idTax);
if ($subtype) {
if ($subtype->valid_from === '0000-00-00') {
$subtype->valid_from = null;
@@ -262,8 +262,8 @@ class AdminTaxesControllerCore extends AdminController
$_POST['valid_from'] = $subtype->valid_from ?: '';
$_POST['valid_to'] = $subtype->valid_to ?: '';
- $tiers = TourismTaxTier::getByTaxId($idTax);
- $childRanges = TourismTaxChildRange::getByTaxId($idTax);
+ $tiers = TaxPriceTier::getByTaxId($idTax);
+ $childRanges = TaxChildRange::getByTaxId($idTax);
}
} elseif ($isAnySubmit) {
$postTierIds = (array) Tools::getValue('tier_id', array());
@@ -295,7 +295,7 @@ class AdminTaxesControllerCore extends AdminController
$taxType = (int) Tools::getValue('tax_calc_type', 0);
$baseTaxValue = Tools::getValue('tax_value', $subtype ? $subtype->tax_value : 0);
- $allDayKeys = TourismTax::DAY_KEYS;
+ $allDayKeys = TaxConfiguration::DAY_KEYS;
if ($subtype && $subtype->special_days) {
$defaultSpecialDays = json_decode($subtype->special_days, true) ?: $allDayKeys;
} else {
@@ -751,7 +751,7 @@ class AdminTaxesControllerCore extends AdminController
*/
public function displayRate($value, $row)
{
- return TourismTax::getFormattedRateForDisplay($value, $row, $this->context->currency);
+ return TaxConfiguration::getFormattedRateForDisplay($value, $row, $this->context->currency);
}
public function postProcess()
@@ -784,6 +784,10 @@ class AdminTaxesControllerCore extends AdminController
}
if ($wasTourismTax && !$isTourismTax) {
$this->cleanTaxFromTourismTaxRulesGroups($object->id);
+ $tourismTax = TaxConfiguration::getByTaxId($object->id);
+ if ($tourismTax) {
+ $tourismTax->delete();
+ }
}
if (!$wasTourismTax && $isTourismTax) {
$this->cleanTaxFromVatTaxRulesGroups($object->id);
@@ -1008,10 +1012,10 @@ class AdminTaxesControllerCore extends AdminController
protected function saveTourismTaxSubtype($idTax)
{
$idTax = (int) $idTax;
- $tourismTax = TourismTax::getByTaxId($idTax);
+ $tourismTax = TaxConfiguration::getByTaxId($idTax);
$tourismTaxExists = (bool) $tourismTax;
if (!$tourismTax) {
- $tourismTax = new TourismTax();
+ $tourismTax = new TaxConfiguration();
$tourismTax->id = $idTax;
}
$tourismTax->tax_calc_type = (int) Tools::getValue('tax_calc_type', 0);
@@ -1030,7 +1034,7 @@ class AdminTaxesControllerCore extends AdminController
if (!is_array($submittedDays)) {
$submittedDays = array();
}
- $submittedDays = array_values(array_intersect(TourismTax::DAY_KEYS, $submittedDays));
+ $submittedDays = array_values(array_intersect(TaxConfiguration::DAY_KEYS, $submittedDays));
if (empty($submittedDays) || count($submittedDays) === 7) {
$tourismTax->special_days = null;
} else {
@@ -1043,13 +1047,13 @@ class AdminTaxesControllerCore extends AdminController
$tourismTax->add();
}
- TourismTaxTier::saveAll(
+ TaxPriceTier::saveAll(
$idTax,
Tools::getValue('tier_min', array()),
Tools::getValue('tier_max', array()),
Tools::getValue('tier_value', array())
);
- TourismTaxChildRange::saveAll(
+ TaxChildRange::saveAll(
$idTax,
Tools::getValue('child_min', array()),
Tools::getValue('child_max', array()),
@@ -1065,7 +1069,7 @@ class AdminTaxesControllerCore extends AdminController
*/
protected function cleanTaxFromTourismTaxRulesGroups($idTax)
{
- $count = TourismTax::cleanFromTourismTaxRulesGroups((int) $idTax);
+ $count = TaxConfiguration::cleanFromTourismTaxRulesGroups($idTax);
if ($count) {
$this->warnings[] = sprintf(
$this->l('This tax was removed from %d tourism tax rules group(s) because it is no longer marked as a tourism tax.'),
@@ -1082,7 +1086,7 @@ class AdminTaxesControllerCore extends AdminController
*/
protected function cleanTaxFromVatTaxRulesGroups($idTax)
{
- $count = TourismTax::cleanFromVatTaxRulesGroups((int) $idTax);
+ $count = TaxConfiguration::cleanFromVatTaxRulesGroups($idTax);
if ($count) {
$this->warnings[] = sprintf(
$this->l('This tax was removed from %d standard tax rules group(s) because it is now marked as a tourism tax.'),
diff --git a/controllers/front/OrderConfirmationController.php b/controllers/front/OrderConfirmationController.php
index 667cbd347..ca461689f 100644
--- a/controllers/front/OrderConfirmationController.php
+++ b/controllers/front/OrderConfirmationController.php
@@ -155,7 +155,7 @@ class OrderConfirmationControllerCore extends FrontController
$idOrder = $cartOrder['id_order'];
$objCartOrder = new Order($idOrder);
$orderProducts = $objCartOrder->getProducts();
- $roomTourismTaxByBooking = OrderTourismTax::getAppliedTourismTaxTotals($idOrder, OrderTourismTax::SCOPE_ROOM);
+ $roomTourismTaxByBooking = OrderTaxDetail::getAppliedTourismTaxTotals($idOrder, OrderTaxDetail::SCOPE_ROOM);
if (!empty($orderProducts)) {
foreach ($orderProducts as $type_key => $type_value) {
@@ -436,7 +436,7 @@ class OrderConfirmationControllerCore extends FrontController
$orderTotalInfo['total_paid'] += $objCartOrder->total_paid;
$orderTotalInfo['total_paid_real'] += $objCartOrder->total_paid_real;
- $orderTotalInfo['total_tourism_tax'] += OrderTourismTax::getOrderTourismTaxTotal($idOrder);
+ $orderTotalInfo['total_tourism_tax'] += OrderTaxDetail::getOrderTourismTaxTotal($idOrder);
}
$totalTaxIncl = $orderTotalInfo['total_rooms_ti'] + $orderTotalInfo['total_services_ti'] + $orderTotalInfo['total_convenience_fee_ti'] + $orderTotalInfo['total_auto_add_services_ti'] + $orderTotalInfo['total_demands_price_ti'] + $orderTotalInfo['total_standalone_products_ti'];
diff --git a/controllers/front/OrderDetailController.php b/controllers/front/OrderDetailController.php
index b901df198..bde1ccf77 100644
--- a/controllers/front/OrderDetailController.php
+++ b/controllers/front/OrderDetailController.php
@@ -89,7 +89,7 @@ class OrderDetailControllerCore extends FrontController
$objRoomType = new HotelRoomType();
$objBookingDemand = new HotelBookingDemands();
$objServiceProductOrderDetail = new ServiceProductOrderDetail();
- $roomTourismTaxByBooking = OrderTourismTax::getAppliedTourismTaxTotals($order->id, OrderTourismTax::SCOPE_ROOM);
+ $roomTourismTaxByBooking = OrderTaxDetail::getAppliedTourismTaxTotals($order->id, OrderTaxDetail::SCOPE_ROOM);
$anyBackOrder = 0;
$processedProducts = array();
$cartHotelData = array();
@@ -425,7 +425,7 @@ class OrderDetailControllerCore extends FrontController
}
}
- $totalTourismTax = OrderTourismTax::getOrderTourismTaxTotal((int) $id_order);
+ $totalTourismTax = OrderTaxDetail::getOrderTourismTaxTotal((int) $id_order);
$this->context->smarty->assign(
array(
diff --git a/controllers/front/OrderOpcController.php b/controllers/front/OrderOpcController.php
index 69dd7ab4e..72f7616f8 100644
--- a/controllers/front/OrderOpcController.php
+++ b/controllers/front/OrderOpcController.php
@@ -1001,12 +1001,12 @@ class OrderOpcControllerCore extends ParentOrderController
1
);
foreach ($cartBookingData['selected_service'] as &$selectedService) {
- if ($selectedService['tourism_tax_online'] > 0 && TourismTax::isGrossedUp($selectedService['tourism_tax_online'])) {
- $selectedService['total_price_tax_incl'] += $selectedService['tourism_tax_online'];
+ if ($selectedService['tourism_tax'] > 0 && TaxConfiguration::isGrossedUp($selectedService['tourism_tax'])) {
+ $selectedService['total_price_tax_incl'] += $selectedService['tourism_tax'];
$quantity = $selectedService['quantity'] ?: 1;
$impliedNumDays = $selectedService['unit_price_tax_excl'] > 0 ? $selectedService['total_price_tax_excl'] / ($selectedService['unit_price_tax_excl'] * $quantity) : 1;
$unitDivisor = $impliedNumDays * $quantity;
- $selectedService['unit_price_tax_incl'] += $unitDivisor > 0 ? ($selectedService['tourism_tax_online'] / $unitDivisor) : 0;
+ $selectedService['unit_price_tax_incl'] += $unitDivisor > 0 ? ($selectedService['tourism_tax'] / $unitDivisor) : 0;
}
}
unset($selectedService);
diff --git a/controllers/front/ProductController.php b/controllers/front/ProductController.php
index 8b994aaaa..e31cb0012 100644
--- a/controllers/front/ProductController.php
+++ b/controllers/front/ProductController.php
@@ -497,8 +497,8 @@ class ProductControllerCore extends FrontController
$feature_price = HotelRoomTypeFeaturePricing::getRoomTypeFeaturePricesPerDay($this->product->id, $date_from, $date_to, false, 0, 0, 0, 0, 1, 1, $occupancy_value);
}
$productPriceWithoutReduction = $this->product->getPriceWithoutReduct(!$useTax);
- if ($useTax) {
- $totalsWithoutReduction = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice(
+ if ($useTax && (bool) Configuration::get('QLO_TOURISM_TAX_GROSSED_UP')) {
+ $totalExclTourismTax = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice(
$this->product->id,
$date_from,
$date_to,
@@ -510,10 +510,22 @@ class ProductControllerCore extends FrontController
1,
0
);
- if (TourismTax::isGrossedUp($totalsWithoutReduction['tourism_tax_online'])) {
- $numDaysInDuration = HotelHelper::getNumberOfDays($date_from, $date_to);
- $productPriceWithoutReduction += $totalsWithoutReduction['tourism_tax_online'] / $numDaysInDuration;
- }
+ $totalInclTourismTax = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice(
+ $this->product->id,
+ $date_from,
+ $date_to,
+ $occupancy_value,
+ 0,
+ 0,
+ 0,
+ 0,
+ 1,
+ 0,
+ true
+ );
+ $tourismTaxTotal = $totalInclTourismTax['total_price_tax_incl'] - $totalExclTourismTax['total_price_tax_incl'];
+ $numDaysInDuration = HotelHelper::getNumberOfDays($date_from, $date_to);
+ $productPriceWithoutReduction += $tourismTaxTotal / $numDaysInDuration;
}
$feature_price_diff = (float)($productPriceWithoutReduction - $feature_price);
$this->context->smarty->assign('feature_price', $feature_price);
@@ -750,6 +762,7 @@ class ProductControllerCore extends FrontController
// calculate room type price first
$useTax = HotelBookingDetail::useTax();
$totalPrice = 0;
+ $includeTourismTax = $useTax && Configuration::get('QLO_TOURISM_TAX_GROSSED_UP');
$priceWithoutDiscount = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice(
$idProduct,
$dateFrom,
@@ -760,13 +773,21 @@ class ProductControllerCore extends FrontController
0,
0,
1,
- 0
+ 0,
+ $includeTourismTax
);
$roomTypeDateRangePrice = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice(
$idProduct,
$dateFrom,
$dateTo,
- $occupancy
+ $occupancy,
+ 0,
+ 0,
+ 0,
+ 0,
+ 1,
+ 1,
+ $includeTourismTax
);
$featurePrice = 0;
@@ -785,16 +806,7 @@ class ProductControllerCore extends FrontController
$occupancy
);
$totalPriceWithoutDiscount = $priceWithoutDiscount['total_price_tax_incl'];
- if (TourismTax::isGrossedUp($priceWithoutDiscount['tourism_tax_online'])) {
- $totalPriceWithoutDiscount += $priceWithoutDiscount['tourism_tax_online'];
- }
-
- $roomTypeDateRangePriceTaxIncl = $roomTypeDateRangePrice['total_price_tax_incl'];
- if (TourismTax::isGrossedUp($roomTypeDateRangePrice['tourism_tax_online'])) {
- $roomTypeDateRangePriceTaxIncl += $roomTypeDateRangePrice['tourism_tax_online'];
- }
- $roomTypeDateRangePrice = $roomTypeDateRangePriceTaxIncl;
-
+ $roomTypeDateRangePrice = $roomTypeDateRangePrice['total_price_tax_incl'];
} else {
$featurePrice = HotelRoomTypeFeaturePricing::getRoomTypeFeaturePricesPerDay(
$idProduct,
@@ -868,7 +880,6 @@ class ProductControllerCore extends FrontController
$serviceOccupancy = (is_array($occupancy) && isset($occupancy[0])) ? $occupancy[0] : array('adults' => 1, 'child_ages' => array());
$serviceNumAdults = isset($serviceOccupancy['adults']) ? (int) $serviceOccupancy['adults'] : 1;
$serviceChildAges = !empty($serviceOccupancy['child_ages']) ? (array) $serviceOccupancy['child_ages'] : array();
- $serviceIdCurrency = (int) $this->context->cart->id_currency ?: (int) Configuration::get('PS_CURRENCY_DEFAULT');
foreach ($roomServiceProducts as &$product) {
if (!$objRoomTypeServiceProduct->isRoomTypeLinkedWithProduct($idProduct, $product['id_product'])) {
@@ -894,55 +905,17 @@ class ProductControllerCore extends FrontController
$useTax,
$product['quantity'],
$dateFrom,
- $dateTo
+ $dateTo,
+ false,
+ null,
+ 1,
+ null,
+ 0,
+ $useTax && Configuration::get('QLO_TOURISM_TAX_GROSSED_UP'),
+ $serviceNumAdults,
+ $serviceChildAges
);
- if ($useTax) {
- $servicePriceNumDays = 1;
- if ($objServiceProduct->price_calculation_method == Product::PRICE_CALCULATION_METHOD_PER_DAY) {
- $servicePriceNumDays = $numDays ?: 1;
- }
-
- $serviceUnitPriceTaxExcl = Product::getServiceProductPrice(
- $product['id_product'],
- 0,
- false,
- $idProduct,
- false,
- 1,
- $dateFrom,
- $dateTo
- ) / $servicePriceNumDays;
- $serviceTourismTax = array('tourism_tax_online' => 0.0);
- $idTourismTaxRulesGroup = Product::getIdTourismTaxRulesGroupByIdProduct((int) $product['id_product']);
- if ($idTourismTaxRulesGroup) {
- $tourismTaxContext = TourismTax::resolveServiceLineTaxContext(
- $idHotel,
- 0,
- new Address((int) Cart::getIdAddressForTaxCalculation((int) $product['id_product']))
- );
- $taxCalculator = TaxManagerFactory::getManager(
- $tourismTaxContext['address'],
- $idTourismTaxRulesGroup
- )->getTaxCalculator();
- $serviceTourismTax = $taxCalculator->getTourismTaxRows(
- $serviceUnitPriceTaxExcl,
- $dateFrom,
- max(1, (int) $numDays),
- $serviceNumAdults,
- $serviceChildAges,
- $serviceIdCurrency,
- $tourismTaxContext['collectionType'],
- $this->context->language->id,
- $product['quantity']
- );
- }
-
- if (TourismTax::isGrossedUp($serviceTourismTax['tourism_tax_online'])) {
- $productPrice += $serviceTourismTax['tourism_tax_online'];
- }
- }
-
$product['price'] = $productPrice;
$serviceProductsPrice += $productPrice;
}
diff --git a/install/data/db_structure.sql b/install/data/db_structure.sql
index c94b41599..29d39cccb 100644
--- a/install/data/db_structure.sql
+++ b/install/data/db_structure.sql
@@ -1196,16 +1196,7 @@ CREATE TABLE `PREFIX_orders` (
INDEX `date_add`(`date_add`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8 COLLATION;
-CREATE TABLE `PREFIX_order_detail_tax` (
- `id_order_detail` int(11) NOT NULL,
- `id_tax` int(11) NOT NULL,
- `unit_amount` DECIMAL(16, 6) NOT NULL DEFAULT '0.00',
- `total_amount` DECIMAL(16, 6) NOT NULL DEFAULT '0.00',
- KEY (`id_order_detail`),
- KEY `id_tax` (`id_tax`)
-) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8 COLLATION;
-
-CREATE TABLE `PREFIX_tourism_tax` (
+CREATE TABLE `PREFIX_tax_configuration` (
`id_tax` int(11) unsigned NOT NULL,
`tax_calc_type` tinyint(1) NOT NULL DEFAULT '0',
`is_per_night` tinyint(1) NOT NULL DEFAULT '1',
@@ -1221,58 +1212,52 @@ CREATE TABLE `PREFIX_tourism_tax` (
PRIMARY KEY (`id_tax`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8 COLLATION;
-CREATE TABLE `PREFIX_tourism_tax_tier` (
- `id_tier` int(11) unsigned NOT NULL AUTO_INCREMENT,
+CREATE TABLE `PREFIX_tax_price_tier` (
+ `id_tax_price_tier` int(11) unsigned NOT NULL AUTO_INCREMENT,
`id_tax` int(11) unsigned NOT NULL,
`min_amount` decimal(20,6) NOT NULL DEFAULT '0.000000',
`max_amount` decimal(20,6) NOT NULL DEFAULT '0.000000',
`tax_value` decimal(20,6) NOT NULL DEFAULT '0.000000',
- PRIMARY KEY (`id_tier`),
+ PRIMARY KEY (`id_tax_price_tier`),
KEY `id_tax` (`id_tax`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8 COLLATION;
-CREATE TABLE `PREFIX_tourism_tax_child_range` (
- `id_child_range` int(11) unsigned NOT NULL AUTO_INCREMENT,
+CREATE TABLE `PREFIX_tax_child_range` (
+ `id_tax_child_range` int(11) unsigned NOT NULL AUTO_INCREMENT,
`id_tax` int(11) unsigned NOT NULL,
`min_age` tinyint(3) unsigned NOT NULL DEFAULT '0',
`max_age` tinyint(3) unsigned NOT NULL DEFAULT '17',
`tax_value` decimal(20,6) NOT NULL DEFAULT '0.000000',
- PRIMARY KEY (`id_child_range`),
+ PRIMARY KEY (`id_tax_child_range`),
KEY `id_tax` (`id_tax`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8 COLLATION;
-CREATE TABLE `PREFIX_order_tourism_tax` (
- `id_order_tourism_tax` int(11) unsigned NOT NULL AUTO_INCREMENT,
+CREATE TABLE `PREFIX_order_tax_detail` (
+ `id_order_tax_detail` int(11) unsigned NOT NULL AUTO_INCREMENT,
`id_order` int(11) unsigned NOT NULL,
`id_order_detail` int(11) unsigned NOT NULL,
`id_htl_booking` int(11) unsigned NOT NULL,
`id_service_product_order_detail` int(11) unsigned NOT NULL DEFAULT '0',
- `id_hotel` int(11) unsigned NOT NULL,
`id_tax` int(11) unsigned NOT NULL,
- `id_currency` int(11) unsigned NOT NULL,
- `num_nights` smallint(5) unsigned NOT NULL DEFAULT '1',
- `num_adults` tinyint(3) unsigned NOT NULL DEFAULT '1',
+ `unit_amount` decimal(20,6) NOT NULL DEFAULT '0.000000',
`total_amount` decimal(20,6) NOT NULL DEFAULT '0.000000',
- `is_refunded` tinyint(1) NOT NULL DEFAULT '0',
`date_add` datetime NOT NULL,
- `date_upd` datetime NOT NULL,
- PRIMARY KEY (`id_order_tourism_tax`),
+ PRIMARY KEY (`id_order_tax_detail`),
KEY `id_order` (`id_order`),
KEY `id_order_detail` (`id_order_detail`),
- KEY `id_hotel` (`id_hotel`),
KEY `id_htl_booking` (`id_htl_booking`),
KEY `id_service_product_order_detail` (`id_service_product_order_detail`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8 COLLATION;
-CREATE TABLE `PREFIX_order_tourism_tax_exemption` (
- `id_exemption` int(11) unsigned NOT NULL AUTO_INCREMENT,
+CREATE TABLE `PREFIX_order_tax_exemption` (
+ `id_order_tax_exemption` int(11) unsigned NOT NULL AUTO_INCREMENT,
`id_htl_booking` int(11) unsigned NOT NULL DEFAULT '0',
`id_service_product_order_detail` int(11) unsigned NOT NULL DEFAULT '0',
`id_order` int(11) unsigned NOT NULL,
`id_employee` int(11) unsigned NOT NULL,
`note` text,
`date_add` datetime NOT NULL,
- PRIMARY KEY (`id_exemption`),
+ PRIMARY KEY (`id_order_tax_exemption`),
KEY `id_htl_booking` (`id_htl_booking`),
KEY `id_service_product_order_detail` (`id_service_product_order_detail`),
KEY `id_order` (`id_order`)
@@ -1345,12 +1330,12 @@ CREATE TABLE `PREFIX_order_detail` (
`product_supplier_reference` varchar(32) DEFAULT NULL,
`product_weight` DECIMAL(20,6) NOT NULL,
`id_tax_rules_group` INT(11) UNSIGNED DEFAULT '0',
+ `id_tourism_tax_rule_group` INT(11) UNSIGNED DEFAULT '0',
`tax_computation_method` tinyint(1) unsigned NOT NULL DEFAULT '0',
`tax_name` varchar(16) NOT NULL,
`tax_rate` DECIMAL(10,3) NOT NULL DEFAULT '0.000',
`ecotax` decimal(21,6) NOT NULL DEFAULT '0.00',
`ecotax_tax_rate` DECIMAL(5,3) NOT NULL DEFAULT '0.000',
- `tourism_tax_amount` DECIMAL(21,6) NOT NULL DEFAULT '0.000000',
`discount_quantity_applied` TINYINT(1) NOT NULL DEFAULT '0',
`download_hash` varchar(255) DEFAULT NULL,
`download_nb` int(10) unsigned DEFAULT '0',
diff --git a/js/admin/price.js b/js/admin/price.js
index 5be19f8f1..fe4ce1cfe 100644
--- a/js/admin/price.js
+++ b/js/admin/price.js
@@ -122,7 +122,7 @@ function getTourismTaxIncluded(priceTE)
if (t.is_tiered) {
for (var j = 0; j < t.tiers.length; j++) {
var tier = t.tiers[j];
- if (priceTE >= tier.min_amount && (tier.max_amount == 0 || priceTE < tier.max_amount)) {
+ if (priceTE >= tier.min_amount && (tier.max_amount == 0 || priceTE <= tier.max_amount)) {
baseValue = tier.tax_value;
break;
}
diff --git a/modules/blockcart/blockcart.php b/modules/blockcart/blockcart.php
index 3a028cf75..63c64beb5 100644
--- a/modules/blockcart/blockcart.php
+++ b/modules/blockcart/blockcart.php
@@ -208,15 +208,15 @@ class Blockcart extends Module
$wrappingCost = (float) ($params['cart']->getOrderTotal($useTax, Cart::ONLY_WRAPPING));
$totalToPay = $params['cart']->getOrderTotal($useTax);
$tourismTaxTotals = $params['cart']->getOrderTotal(true, Cart::ONLY_TOURISM_TAX);
- $tourismTaxOnline = (float) $tourismTaxTotals['tourism_tax_online'];
- $tourismTaxOnlineRoom = $tourismTaxOnline - (float) $tourismTaxTotals['tourism_tax_online_service'];
+ $tourismTax = (float) $tourismTaxTotals['tourism_tax'];
+ $tourismTaxRoom = (float) $tourismTaxTotals['tourism_tax_room'];
$tax_cost = 0;
$tourismTaxCost = Tools::displayPrice(0, $currency);
if ($useTax && $useTax) {
$totalToPayWithoutTaxes = $params['cart']->getOrderTotal(false);
- $tax_cost = Tools::displayPrice(($totalToPay - $totalToPayWithoutTaxes) - $tourismTaxOnline, $currency);
- $tourismTaxCost = Tools::displayPrice($tourismTaxOnline, $currency);
+ $tax_cost = Tools::displayPrice(($totalToPay - $totalToPayWithoutTaxes) - $tourismTax, $currency);
+ $tourismTaxCost = Tools::displayPrice($tourismTax, $currency);
}
// The cart content is altered for display
$orderProcess = Configuration::get('PS_ORDER_PROCESS_TYPE') ? 'order-opc' : 'order';
@@ -310,20 +310,24 @@ class Blockcart extends Module
);
$addedProduct['booking_product'] = $objProduct->booking_product;
if ($objProduct->booking_product) {
+ $includeTourismTax = ($priceDisplayMethod != PS_TAX_EXC) && (bool) Configuration::get('QLO_TOURISM_TAX_GROSSED_UP');
$price = $addedProduct['price'] = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice(
$objProduct->id,
$addedProduct['date_from'],
$addedProduct['date_to'],
- $addedProduct['occupancy']
+ $addedProduct['occupancy'],
+ 0,
+ 0,
+ 0,
+ 0,
+ 1,
+ 1,
+ $includeTourismTax
);
if ($priceDisplayMethod == PS_TAX_EXC) {
$addedProduct['price'] = Tools::displayPrice($price['total_price_tax_excl']);
} else {
- $roomPriceTaxIncl = (float) $price['total_price_tax_incl'];
- if (TourismTax::isGrossedUp($price['tourism_tax_online'])) {
- $roomPriceTaxIncl += (float) $price['tourism_tax_online'];
- }
- $addedProduct['price'] = Tools::displayPrice($roomPriceTaxIncl);
+ $addedProduct['price'] = Tools::displayPrice((float) $price['total_price_tax_incl']);
}
$fullDate = ($this->context->controller->show_full_date && (date('Y-m-d', strtotime($addedProduct['date_from'])) == date('Y-m-d', strtotime($addedProduct['date_to']))) ? true : false);
$addedProduct['date_from'] = Tools::displayDate($addedProduct['date_from'], null, $fullDate);
@@ -371,32 +375,15 @@ class Blockcart extends Module
}
$totalAdditionalServicesWithoutAutoAddPrice = $params['cart']->getOrderTotal($useTax, Cart::ONLY_ROOM_SERVICES_WITHOUT_AUTO_ADD);
- $totalAdditionalServicesWithAutoAddPrice = $params['cart']->getOrderTotal($useTax, Cart::ONLY_ROOM_SERVICES);
+ $totalAdditionalServicesWithAutoAddPrice = $params['cart']->getOrderTotal($useTax, Cart::ONLY_ROOM_SERVICES_WITH_AUTO_ADD_WITHOUT_CONVENIENCE_FEE);
$totalConvenienceFee = $params['cart']->getOrderTotal($useTax, Cart::ONLY_CONVENIENCE_FEE);
$totalRoomsPrice = $params['cart']->getOrderTotal($useTax, Cart::ONLY_ROOMS);
- $tourismTaxOnlineConvenienceFee = 0.0;
- if ($convenienceFeeServices = $objServiceProductCartDetail->getServiceProductsInCart(
- $params['cart']->id,
- [],
- null,
- null,
- null,
- null,
- null,
- null,
- 0,
- 1,
- Product::PRICE_ADDITION_TYPE_INDEPENDENT
- )) {
- foreach ($convenienceFeeServices as $convenienceFeeService) {
- $tourismTaxOnlineConvenienceFee += (float) $convenienceFeeService['tourism_tax_online'];
- }
+ $tourismTaxConvenienceFee = (float) $tourismTaxTotals['tourism_tax_convenience_fee'];
+ if ($useTax && TaxConfiguration::isGrossedUp($tourismTaxRoom)) {
+ $totalRoomsPrice += $tourismTaxRoom;
}
- if ($useTax && TourismTax::isGrossedUp($tourismTaxOnlineRoom)) {
- $totalRoomsPrice += $tourismTaxOnlineRoom;
- }
- if ($useTax && TourismTax::isGrossedUp($tourismTaxOnlineConvenienceFee)) {
- $totalConvenienceFee += $tourismTaxOnlineConvenienceFee;
+ if ($useTax && TaxConfiguration::isGrossedUp($tourismTaxConvenienceFee)) {
+ $totalConvenienceFee += $tourismTaxConvenienceFee;
}
$totalNormalProductPrice = $params['cart']->getOrderTotal($useTax, Cart::ONLY_STANDALONE_PRODUCTS);
@@ -415,11 +402,11 @@ class Blockcart extends Module
'use_tax' => $useTax,
'tax_cost' => $tax_cost,
'tourism_tax_cost' => $tourismTaxCost,
- 'tourism_tax_online' => $tourismTaxOnline,
+ 'tourism_tax' => $tourismTax,
'wrapping_cost' => Tools::displayPrice($wrappingCost, $currency),
'product_total' => Tools::displayPrice($params['cart']->getOrderTotal($useTax, Cart::ONLY_PRODUCTS), $currency),
'room_total' => ($totalRoomsPrice + $totalDemandsPrice + $totalAdditionalServicesWithAutoAddPrice),
- 'room_total_format' => Tools::displayPrice($totalRoomsPrice + $totalDemandsPrice + $totalAdditionalServicesWithAutoAddPrice - $totalConvenienceFee),
+ 'room_total_format' => Tools::displayPrice($totalRoomsPrice + $totalDemandsPrice + $totalAdditionalServicesWithAutoAddPrice),
'totalToPay' => $totalToPay,
'total_convenience_fee' => $totalConvenienceFee,
'total_convenience_fee_format' => Tools::displayPrice(($totalConvenienceFee), $currency),
diff --git a/modules/hotelreservationsystem/classes/HotelBookingDemands.php b/modules/hotelreservationsystem/classes/HotelBookingDemands.php
index fe0c0efd0..2236da849 100644
--- a/modules/hotelreservationsystem/classes/HotelBookingDemands.php
+++ b/modules/hotelreservationsystem/classes/HotelBookingDemands.php
@@ -243,11 +243,12 @@ class HotelBookingDemands extends ObjectModel
// if one of the order details use the tax computation method the display will be different
return Db::getInstance()->getValue('
SELECT od.`tax_computation_method`
- FROM `' . _DB_PREFIX_ . 'order_detail_tax` odt
+ FROM `' . _DB_PREFIX_ . 'order_tax_detail` odt
LEFT JOIN `' . _DB_PREFIX_ . 'order_detail` od ON (od.`id_order_detail` = odt.`id_order_detail`)
WHERE od.`id_order` = ' . (int) $this->id_order . '
AND od.`id_order_invoice` = ' . (int) $this->id . '
- AND od.`tax_computation_method` = ' . (int) TaxCalculator::ONE_AFTER_ANOTHER_METHOD)
+ AND od.`tax_computation_method` = ' . (int) TaxCalculator::ONE_AFTER_ANOTHER_METHOD . '
+ AND NOT EXISTS (SELECT 1 FROM `' . _DB_PREFIX_ . 'tax` tc WHERE tc.`id_tax` = odt.`id_tax` AND tc.`is_tourism_tax` = 1)')
|| Configuration::get('PS_INVOICE_TAXES_BREAKDOWN');
}
diff --git a/modules/hotelreservationsystem/classes/HotelBookingDetail.php b/modules/hotelreservationsystem/classes/HotelBookingDetail.php
index 69956133f..60ec3fde2 100644
--- a/modules/hotelreservationsystem/classes/HotelBookingDetail.php
+++ b/modules/hotelreservationsystem/classes/HotelBookingDetail.php
@@ -2518,35 +2518,6 @@ class HotelBookingDetail extends ObjectModel
$data['is_cancelled'] = (int) $is_cancelled;
}
- $tourismBookingIds = array();
- if ((int) $is_refunded) {
- if ($id_rooms) {
- foreach ($id_rooms as $val_rm) {
- $idHtlBooking = (int) Db::getInstance()->getValue(
- 'SELECT `id` FROM `'._DB_PREFIX_.'htl_booking_detail`
- WHERE `id_order` = '.(int) $id_order.'
- AND `id_room` = '.(int) $val_rm['id_room'].'
- AND `date_from` = \''.pSQL($date_from).'\'
- AND `date_to` = \''.pSQL($date_to).'\'
- AND `is_refunded` = 0'
- );
- if ($idHtlBooking) {
- $tourismBookingIds[] = $idHtlBooking;
- }
- }
- } else {
- $rows = Db::getInstance()->executeS(
- 'SELECT `id` FROM `'._DB_PREFIX_.'htl_booking_detail`
- WHERE `id_order` = '.(int) $id_order.' AND `is_refunded` = 0'
- );
- if ($rows) {
- foreach ($rows as $row) {
- $tourismBookingIds[] = (int) $row['id'];
- }
- }
- }
- }
-
if ($id_rooms) {
foreach ($id_rooms as $key_rm => $val_rm) {
$where = 'id_order='.(int)$id_order.' AND id_room = '.(int)$val_rm['id_room'].' AND `date_from`= \''.
@@ -2557,12 +2528,6 @@ class HotelBookingDetail extends ObjectModel
$result = Db::getInstance()->update($table, $data, 'id_order='.(int)$id_order);
}
- if ($result && $tourismBookingIds) {
- foreach ($tourismBookingIds as $idHtlBooking) {
- OrderTourismTax::setRefundedByHtlBooking($idHtlBooking);
- }
- }
-
// if automatic overbooking resolution is enabled
if ($result && Configuration::get('PS_OVERBOOKING_AUTO_RESOLVE') && $is_refunded) {
// if room is getting free and this room is not already in back order then resolve the overbookings for this free room
@@ -3639,8 +3604,6 @@ class HotelBookingDetail extends ObjectModel
$this->save();
- OrderTourismTax::setRefundedByHtlBooking($this->id);
-
return true;
}
diff --git a/modules/hotelreservationsystem/classes/HotelBranchInformation.php b/modules/hotelreservationsystem/classes/HotelBranchInformation.php
index 4acff2916..2979c9f8c 100644
--- a/modules/hotelreservationsystem/classes/HotelBranchInformation.php
+++ b/modules/hotelreservationsystem/classes/HotelBranchInformation.php
@@ -23,6 +23,9 @@
class HotelBranchInformation extends ObjectModel
{
+ const TAX_COLLECTION_TYPE_ONLINE = 0;
+ const TAX_COLLECTION_TYPE_AT_HOTEL = 1;
+
public $id_category;
public $hotel_name;
public $email;
diff --git a/modules/hotelreservationsystem/classes/HotelCartBookingData.php b/modules/hotelreservationsystem/classes/HotelCartBookingData.php
index bf7c7909f..f2bf8c0f4 100644
--- a/modules/hotelreservationsystem/classes/HotelCartBookingData.php
+++ b/modules/hotelreservationsystem/classes/HotelCartBookingData.php
@@ -1685,6 +1685,7 @@ class HotelCartBookingData extends ObjectModel
$cartHotelData[$prodKey]['date_diff'][$dateJoin]['child_ages'] = array_merge($cartHotelData[$prodKey]['date_diff'][$dateJoin]['child_ages'], json_decode($data_v['child_ages']));
}
$varQty = (int) $cartHotelData[$prodKey]['date_diff'][$dateJoin]['num_rm'];
+ $includeTourismTax = $price_tax && (bool) Configuration::get('QLO_TOURISM_TAX_GROSSED_UP');
$roomTypeDateRangePrice = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice(
$product['id_product'],
$data_v['date_from'],
@@ -1693,7 +1694,10 @@ class HotelCartBookingData extends ObjectModel
0,
$context->cart->id,
$context->cart->id_guest,
- $data_v['id_room']
+ $data_v['id_room'],
+ 1,
+ 1,
+ $includeTourismTax
);
$roomTypeDateRangePriceWithoutAutoAdd = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice(
$product['id_product'],
@@ -1704,7 +1708,9 @@ class HotelCartBookingData extends ObjectModel
$context->cart->id,
$context->cart->id_guest,
$data_v['id_room'],
- 0
+ 0,
+ 1,
+ $includeTourismTax
);
$priceWithoutDiscount = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice(
$product['id_product'],
@@ -1716,7 +1722,8 @@ class HotelCartBookingData extends ObjectModel
$context->cart->id_guest,
$data_v['id_room'],
1,
- 0
+ 0,
+ $includeTourismTax
);
if (!$price_tax) {
$amount = $roomTypeDateRangePrice['total_price_tax_excl'];
@@ -1726,11 +1733,6 @@ class HotelCartBookingData extends ObjectModel
$amount = $roomTypeDateRangePrice['total_price_tax_incl'];
$amountWithoutAutoAdd = $roomTypeDateRangePriceWithoutAutoAdd['total_price_tax_incl'];
$totalPriceWithoutDiscount = $priceWithoutDiscount['total_price_tax_incl'];
- if (TourismTax::isGrossedUp($roomTypeDateRangePrice['tourism_tax_online'])) {
- $amount += (float) $roomTypeDateRangePrice['tourism_tax_online'];
- $amountWithoutAutoAdd += (float) $roomTypeDateRangePriceWithoutAutoAdd['tourism_tax_online'];
- $totalPriceWithoutDiscount += (float) $priceWithoutDiscount['tourism_tax_online'];
- }
}
$cartHotelData[$prodKey]['date_diff'][$dateJoin]['amount'] += $amount;
$cartHotelData[$prodKey]['date_diff'][$dateJoin]['total_price_without_discount'] += $totalPriceWithoutDiscount;
@@ -1752,6 +1754,7 @@ class HotelCartBookingData extends ObjectModel
$cartHotelData[$prodKey]['date_diff'][$dateJoin]['children'] = $data_v['children'];
$cartHotelData[$prodKey]['date_diff'][$dateJoin]['child_ages'] = json_decode($data_v['child_ages']);
+ $includeTourismTax = $price_tax && (bool) Configuration::get('QLO_TOURISM_TAX_GROSSED_UP');
$roomTypeDateRangePrice = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice(
$product['id_product'],
$data_v['date_from'],
@@ -1760,7 +1763,10 @@ class HotelCartBookingData extends ObjectModel
0,
$context->cart->id,
$context->cart->id_guest,
- $data_v['id_room']
+ $data_v['id_room'],
+ 1,
+ 1,
+ $includeTourismTax
);
$roomTypeDateRangePriceWithoutAutoAdd = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice(
$product['id_product'],
@@ -1771,7 +1777,9 @@ class HotelCartBookingData extends ObjectModel
$context->cart->id,
$context->cart->id_guest,
$data_v['id_room'],
- 0
+ 0,
+ 1,
+ $includeTourismTax
);
$priceWithoutDiscount = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice(
$product['id_product'],
@@ -1783,7 +1791,8 @@ class HotelCartBookingData extends ObjectModel
$context->cart->id_guest,
$data_v['id_room'],
1,
- 0
+ 0,
+ $includeTourismTax
);
if (!$price_tax) {
$amount = $roomTypeDateRangePrice['total_price_tax_excl'];
@@ -1793,11 +1802,6 @@ class HotelCartBookingData extends ObjectModel
$amount = $roomTypeDateRangePrice['total_price_tax_incl'];
$amountWithoutAutoAdd = $roomTypeDateRangePriceWithoutAutoAdd['total_price_tax_incl'];
$totalPriceWithoutDiscount = $priceWithoutDiscount['total_price_tax_incl'];
- if (TourismTax::isGrossedUp($roomTypeDateRangePrice['tourism_tax_online'])) {
- $amount += (float) $roomTypeDateRangePrice['tourism_tax_online'];
- $amountWithoutAutoAdd += (float) $roomTypeDateRangePriceWithoutAutoAdd['tourism_tax_online'];
- $totalPriceWithoutDiscount += (float) $priceWithoutDiscount['tourism_tax_online'];
- }
}
$cartHotelData[$prodKey]['date_diff'][$dateJoin]['amount'] = $amount;
$cartHotelData[$prodKey]['date_diff'][$dateJoin]['amount_without_auto_add'] = $amountWithoutAutoAdd;
diff --git a/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php b/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php
index 65896aee9..d3fef9ddb 100644
--- a/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php
+++ b/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php
@@ -275,7 +275,8 @@ class HotelRoomTypeFeaturePricing extends ObjectModel
$id_guest = 0,
$id_room = 0,
$with_auto_room_services = 1,
- $use_reduc = 1
+ $use_reduc = 1,
+ $includeTourismTax = false
) {
$totalPrice = array();
$totalPrice['total_price_tax_incl'] = 0;
@@ -433,33 +434,24 @@ class HotelRoomTypeFeaturePricing extends ObjectModel
$totalPrice['total_price_tax_incl'] = $totalPrice['total_price_tax_incl'] * $quantity;
$totalPrice['total_price_tax_excl'] = $totalPrice['total_price_tax_excl'] * $quantity;
- $totalPrice['tourism_tax_online'] = 0.0;
- if (Configuration::get('QLO_USE_TOURISM_TAX')
- && is_array($occupancy) && !empty($occupancy) && isset($occupancy[0]['adults'])
- ) {
- $idTourismTaxRulesGroup = Product::getIdTourismTaxRulesGroupByIdProduct((int) $id_product);
- if ($idTourismTaxRulesGroup) {
+ if ($includeTourismTax && Configuration::get('QLO_USE_TOURISM_TAX') && is_array($occupancy) && !empty($occupancy) && isset($occupancy[0]['adults'])) {
+ if ($idTourismTaxRulesGroup = Product::getIdTourismTaxRulesGroupByIdProduct((int) $id_product)) {
$hotelBranch = new HotelBranchInformation((int) $objAddress->id_hotel);
$collectionType = (int) $hotelBranch->tourism_tax_collection_type;
$numNights = max(1, (int) HotelHelper::getNumberOfDays($date_from, $date_to));
$unitPriceTe = (float) $totalPrice['total_price_tax_excl'] / $numNights;
- $idLang = (int) Context::getContext()->language->id;
$taxCalculator = TaxManagerFactory::getManager($objAddress, $idTourismTaxRulesGroup)->getTaxCalculator();
- foreach ($occupancy as $roomOcc) {
- $childAges = !empty($roomOcc['child_ages']) ? (array) $roomOcc['child_ages'] : array();
- $tourismTaxResult = $taxCalculator->getTourismTaxRows(
- $unitPriceTe,
- $date_from,
- $numNights,
- $roomOcc['adults'],
- $childAges,
- $id_currency,
- $collectionType,
- $idLang,
- 1
- );
- $totalPrice['tourism_tax_online'] += $tourismTaxResult['tourism_tax_online'];
- }
+ $childAges = !empty($occupancy[0]['child_ages']) ? (array) $occupancy[0]['child_ages'] : array();
+ $totalPrice['total_price_tax_incl'] += $taxCalculator->getTaxesTotalAmount(
+ $unitPriceTe,
+ $date_from,
+ $numNights,
+ $occupancy[0]['adults'],
+ $childAges,
+ $collectionType,
+ 1,
+ $id_currency
+ );
}
}
@@ -488,6 +480,7 @@ class HotelRoomTypeFeaturePricing extends ObjectModel
) {
$dateFrom = date('Y-m-d H:i:s', strtotime($date_from));
$dateTo = date('Y-m-d H:i:s', strtotime($date_to));
+ $includeTourismTax = $use_tax && Configuration::get('QLO_TOURISM_TAX_GROSSED_UP');
$totalDurationPrice = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice(
$id_product,
$dateFrom,
@@ -498,16 +491,14 @@ class HotelRoomTypeFeaturePricing extends ObjectModel
$id_guest,
$id_room,
$with_auto_room_services,
- $use_reduc
+ $use_reduc,
+ $includeTourismTax
);
$totalDurationPriceTI = $totalDurationPrice['total_price_tax_incl'];
$totalDurationPriceTE = $totalDurationPrice['total_price_tax_excl'];
$numDaysInDuration = HotelHelper::getNumberOfDays($dateFrom, $dateTo);
if ($use_tax) {
- if (TourismTax::isGrossedUp($totalDurationPrice['tourism_tax_online'])) {
- $totalDurationPriceTI += $totalDurationPrice['tourism_tax_online'];
- }
$pricePerDay = $totalDurationPriceTI/$numDaysInDuration;
} else {
$pricePerDay = $totalDurationPriceTE/$numDaysInDuration;
diff --git a/modules/hotelreservationsystem/classes/RoomTypeServiceProduct.php b/modules/hotelreservationsystem/classes/RoomTypeServiceProduct.php
index 0a9be7309..d2031f6ee 100644
--- a/modules/hotelreservationsystem/classes/RoomTypeServiceProduct.php
+++ b/modules/hotelreservationsystem/classes/RoomTypeServiceProduct.php
@@ -203,7 +203,6 @@ class RoomTypeServiceProduct extends ObjectModel
$objHotelRoomType = new HotelRoomType();
$roomTypeInfo = $objHotelRoomType->getRoomTypeInfoByIdProduct($idProductRoomType);
$idHotel = $roomTypeInfo ? (int) $roomTypeInfo['id_hotel'] : 0;
- $idCurrency = (int) $context->cart->id_currency ?: (int) Configuration::get('PS_CURRENCY_DEFAULT');
foreach($serviceProducts as &$serviceProduct) {
$serviceProduct['price_tax_exc'] = Product::getServiceProductPrice(
(int)$serviceProduct['id_product'],
@@ -226,35 +225,14 @@ class RoomTypeServiceProduct extends ObjectModel
1,
null,
null,
- $context->cart->id
+ $context->cart->id,
+ null,
+ 1,
+ null,
+ 0,
+ Configuration::get('QLO_TOURISM_TAX_GROSSED_UP')
);
- $serviceTourismTax = array('tourism_tax_online' => 0.0);
- if ($idTourismTaxRulesGroup = Product::getIdTourismTaxRulesGroupByIdProduct((int) $serviceProduct['id_product'])) {
- $tourismTaxContext = TourismTax::resolveServiceLineTaxContext(
- $idHotel,
- 0,
- new Address((int) Cart::getIdAddressForTaxCalculation((int) $serviceProduct['id_product']))
- );
- $taxCalculator = TaxManagerFactory::getManager(
- $tourismTaxContext['address'],
- $idTourismTaxRulesGroup
- )->getTaxCalculator();
- $serviceTourismTax = $taxCalculator->getTourismTaxRows(
- (float) $serviceProduct['price_tax_exc'],
- $tourismTaxContext['checkInDate'],
- $tourismTaxContext['numNights'],
- $tourismTaxContext['numAdults'],
- $tourismTaxContext['childrenAges'],
- $idCurrency,
- $tourismTaxContext['collectionType'],
- $idLang
- );
- }
- if (TourismTax::isGrossedUp($serviceTourismTax['tourism_tax_online'])) {
- $serviceProduct['price_tax_incl'] += $serviceTourismTax['tourism_tax_online'];
- }
-
$useTax = Product::$_taxCalculationMethod == PS_TAX_EXC ? false : true;
$serviceProduct['price_without_reduction'] = Product::getServiceProductPrice(
(int)$serviceProduct['id_product'],
diff --git a/modules/hotelreservationsystem/classes/ServiceProductCartDetail.php b/modules/hotelreservationsystem/classes/ServiceProductCartDetail.php
index cdbc3b15e..8c66f269c 100644
--- a/modules/hotelreservationsystem/classes/ServiceProductCartDetail.php
+++ b/modules/hotelreservationsystem/classes/ServiceProductCartDetail.php
@@ -259,34 +259,6 @@ class ServiceProductCartDetail extends ObjectModel
$product['htl_cart_booking_id']
) / $numDays;
- $idCurrency = Validate::isLoadedObject($context->currency) ? (int) $context->currency->id : (int) Configuration::get('PS_CURRENCY_DEFAULT');
- $idHotelForTourismTax = (int) $product['id_hotel'] ?: ($objHotelCartBooking ? (int) $objHotelCartBooking->id_hotel : 0);
-
- $tourismTax = array('tourism_tax_online' => 0.0);
- if ($idTourismTaxRulesGroup = Product::getIdTourismTaxRulesGroupByIdProduct($objProduct->id)) {
- $tourismTaxContext = TourismTax::resolveServiceLineTaxContext(
- $idHotelForTourismTax,
- 0,
- new Address((int) Cart::getIdAddressForTaxCalculation($objProduct->id)),
- (int) $product['htl_cart_booking_id']
- );
- $taxCalculator = TaxManagerFactory::getManager(
- $tourismTaxContext['address'],
- $idTourismTaxRulesGroup
- )->getTaxCalculator();
- $tourismTax = $taxCalculator->getTourismTaxRows(
- $priceTaxExcl,
- $tourismTaxContext['checkInDate'],
- $tourismTaxContext['numNights'],
- $tourismTaxContext['numAdults'],
- $tourismTaxContext['childrenAges'],
- $idCurrency,
- $tourismTaxContext['collectionType'],
- (int) $language->id,
- $quantity
- );
- }
-
if ($getTotalPrice) {
$totalPrice += Product::getServiceProductPrice(
$objProduct->id,
@@ -301,11 +273,9 @@ class ServiceProductCartDetail extends ObjectModel
null,
1,
null,
- $product['htl_cart_booking_id']
+ $product['htl_cart_booking_id'],
+ $useTax && Configuration::get('QLO_TOURISM_TAX_GROSSED_UP')
);
- if ($useTax && TourismTax::isGrossedUp($tourismTax['tourism_tax_online'])) {
- $totalPrice += $tourismTax['tourism_tax_online'];
- }
} else {
$priceTaxIncl = Product::getServiceProductPrice(
$objProduct->id,
@@ -323,6 +293,42 @@ class ServiceProductCartDetail extends ObjectModel
$product['htl_cart_booking_id']
)/$numDays;
+ $tourismTaxAmount = 0.0;
+ if (Product::getIdTourismTaxRulesGroupByIdProduct($objProduct->id)) {
+ $totalExclTourismTax = Product::getServiceProductPrice(
+ $objProduct->id,
+ $product['id_product_option'],
+ $product['id_hotel'],
+ $product['id_product_room_type'],
+ false,
+ $quantity,
+ $product['date_from'],
+ $product['date_to'],
+ $idCart,
+ null,
+ 1,
+ null,
+ $product['htl_cart_booking_id']
+ );
+ $totalInclTourismTax = Product::getServiceProductPrice(
+ $objProduct->id,
+ $product['id_product_option'],
+ $product['id_hotel'],
+ $product['id_product_room_type'],
+ false,
+ $quantity,
+ $product['date_from'],
+ $product['date_to'],
+ $idCart,
+ null,
+ 1,
+ null,
+ $product['htl_cart_booking_id'],
+ true
+ );
+ $tourismTaxAmount = $totalInclTourismTax - $totalExclTourismTax;
+ }
+
$optionDetails = false;
if (ServiceProductOption::productHasOptions($product['id_product'])) {
$optionDetails = $objServiceProductOption->getProductOptions(
@@ -384,7 +390,7 @@ class ServiceProductCartDetail extends ObjectModel
$productInfo['id_room'] = 0;
}
- $productInfo['tourism_tax_online'] = $tourismTax['tourism_tax_online'];
+ $productInfo['tourism_tax'] = $tourismTaxAmount;
if ($detailedInfo) {
$objHotelBranchInformation = new HotelBranchInformation();
diff --git a/modules/hotelreservationsystem/classes/ServiceProductOrderDetail.php b/modules/hotelreservationsystem/classes/ServiceProductOrderDetail.php
index c1ab62dfc..596c636a9 100644
--- a/modules/hotelreservationsystem/classes/ServiceProductOrderDetail.php
+++ b/modules/hotelreservationsystem/classes/ServiceProductOrderDetail.php
@@ -595,8 +595,6 @@ class ServiceProductOrderDetail extends ObjectModel
$this->save();
- OrderTourismTax::setRefundedByServiceProductOrderDetail((int) $this->id);
-
return true;
}
diff --git a/modules/hotelreservationsystem/views/js/TourismTaxForm.js b/modules/hotelreservationsystem/views/js/TourismTaxForm.js
index dc376f12f..53eefaf22 100644
--- a/modules/hotelreservationsystem/views/js/TourismTaxForm.js
+++ b/modules/hotelreservationsystem/views/js/TourismTaxForm.js
@@ -25,13 +25,14 @@ $(document).ready(function () {
var childIdx = $('#tourism-tax-child-body tr').length;
$('#valid_from').datepicker({
+ dateFormat: 'yy-mm-dd',
onSelect: function () {
$('#valid_to').datepicker('option', 'minDate', $(this).datepicker('getDate'));
validateDates();
}
});
- $('#valid_to').datepicker({ onSelect: validateDates });
+ $('#valid_to').datepicker({ dateFormat: 'yy-mm-dd', onSelect: validateDates });
function validateDates() {
var from = $('#valid_from').val();
diff --git a/modules/hotelreservationsystem/views/templates/admin/order_refund_requests/helpers/view/view.tpl b/modules/hotelreservationsystem/views/templates/admin/order_refund_requests/helpers/view/view.tpl
index ae6788392..5241d694c 100644
--- a/modules/hotelreservationsystem/views/templates/admin/order_refund_requests/helpers/view/view.tpl
+++ b/modules/hotelreservationsystem/views/templates/admin/order_refund_requests/helpers/view/view.tpl
@@ -160,8 +160,8 @@
{/if}
{foreach $refundReqBookings as $booking}
- {assign var="tourismTaxAppliedAmount" value=(isset($booking['tourism_tax_applied_amount']) ? $booking['tourism_tax_applied_amount'] : 0)}
- {assign var="tourismTaxPaidAmount" value=(isset($booking['tourism_tax_paid_amount']) ? $booking['tourism_tax_paid_amount'] : 0)}
+ {assign var="tourismTaxAppliedAmount" value=$booking['tourism_tax_applied_amount']|default:0}
+ {assign var="tourismTaxPaidAmount" value=$booking['tourism_tax_paid_amount']|default:0}
{if !$isRefundCompleted}
diff --git a/themes/hotel-reservation-theme/js/modules/blockcart/ajax-cart.js b/themes/hotel-reservation-theme/js/modules/blockcart/ajax-cart.js
index 53218f0e1..5cd254709 100644
--- a/themes/hotel-reservation-theme/js/modules/blockcart/ajax-cart.js
+++ b/themes/hotel-reservation-theme/js/modules/blockcart/ajax-cart.js
@@ -1295,7 +1295,7 @@ var ajaxCart = {
$('.ajax_cart_tax_cost').text(jsonData.tax_cost);
$('.ajax_cart_tourism_tax_cost').text(jsonData.tourism_tax_cost);
- if (parseFloat(jsonData.tourism_tax_online) > 0) {
+ if (parseFloat(jsonData.tourism_tax) > 0) {
$('.ajax_cart_tourism_tax_line').show();
} else {
$('.ajax_cart_tourism_tax_line').hide();
diff --git a/themes/hotel-reservation-theme/modules/blockcart/blockcart.tpl b/themes/hotel-reservation-theme/modules/blockcart/blockcart.tpl
index 4e7783d9d..5ed92adf9 100644
--- a/themes/hotel-reservation-theme/modules/blockcart/blockcart.tpl
+++ b/themes/hotel-reservation-theme/modules/blockcart/blockcart.tpl
@@ -144,7 +144,7 @@
{/block}
{block name='blockcart_shopping_cart_total_tourism_tax'}
{if $show_tax && $use_tax}
-
+
{$tourism_tax_cost}
{l s='Total Tourism Tax' mod='blockcart'}
@@ -361,7 +361,7 @@
{if $show_tax && $use_tax}
{* Always rendered — see the matching dropdown block above for why a value-gated
{if} would break on later AJAX-only cart updates. *}
-
+
{l s='Total Tourism Tax' mod='blockcart'}
{$tourism_tax_cost}