From 356cd1f569d314d34ebe51f245520b7e3f7d72e8 Mon Sep 17 00:00:00 2001 From: Aman deep sharma Date: Thu, 19 Jun 2025 16:24:26 +0530 Subject: [PATCH 01/11] Fixed: Tax rate calculation and breakdown --- classes/PaymentModule.php | 2 - classes/order/Order.php | 190 +++++++++++++----- classes/order/OrderDetail.php | 137 +++++++++++-- .../classes/HotelReservationSystemDb.php | 2 + .../classes/ServiceProductOrderDetail.php | 45 +++++ 5 files changed, 309 insertions(+), 67 deletions(-) diff --git a/classes/PaymentModule.php b/classes/PaymentModule.php index f1eba0008..9cca21cb6 100644 --- a/classes/PaymentModule.php +++ b/classes/PaymentModule.php @@ -1571,8 +1571,6 @@ abstract class PaymentModuleCore extends Module } } } - - $order->updateOrderDetailTax(); } else { $error = Tools::displayError('Order creation failed'); PrestaShopLogger::addLog($error, 4, '0000002', 'Cart', intval($order->id_cart)); diff --git a/classes/order/Order.php b/classes/order/Order.php index abcd65007..99814f532 100644 --- a/classes/order/Order.php +++ b/classes/order/Order.php @@ -2520,78 +2520,162 @@ class OrderCore extends ObjectModel $order_ecotax_tax = 0; - $tax_rates = array(); - foreach ($order_details as $order_detail) { + $tax_rates = array(); $id_order_detail = $order_detail['id_order_detail']; + + $taxesList = OrderDetail::getTaxListStatic($id_order_detail); + if (!$taxesList) { + continue; + } + $tax_calculator = OrderDetail::getTaxCalculatorStatic($id_order_detail); - - // TODO: probably need to make an ecotax tax breakdown here instead, - // but it seems unlikely there will be different tax rates applied to the - // ecotax in the same order in the real world - $unit_ecotax_tax = $order_detail['ecotax'] * $order_detail['ecotax_tax_rate'] / 100.0; - $order_ecotax_tax += $order_detail['product_quantity'] * $unit_ecotax_tax; - - $discount_ratio = 0; - - if ($this->total_products > 0) { - $discount_ratio = ($order_detail['unit_price_tax_excl'] + $order_detail['ecotax']) / $this->total_products; - } - - // share of global discount - $discounted_price_tax_excl = $order_detail['unit_price_tax_excl'] - $discount_ratio * $order_discount_tax_excl; - // specific discount - if (!empty($product_specific_discounts[$order_detail['product_id']])) { - $discounted_price_tax_excl -= $product_specific_discounts[$order_detail['product_id']]; - } - $quantity = $order_detail['product_quantity']; + $unit_price_tax_excl = $order_detail['total_price_tax_excl'] / $quantity; + + /* + * Discounted taxes are intentionally not calculated here, as we do not want to display them. + * + * TODO: Consider implementing a proper ecotax breakdown if needed in future. + * However, it is unlikely that different tax rates would apply to ecotax within the same order. + * + * + * $unit_ecotax_tax = $order_detail['ecotax'] * $order_detail['ecotax_tax_rate'] / 100.0; + * $order_ecotax_tax += $order_detail['product_quantity'] * $unit_ecotax_tax; + * + * $discount_ratio = 0; + * if ($this->total_products > 0) { + * $discount_ratio = ($order_detail['unit_price_tax_excl'] + $order_detail['ecotax']) / $this->total_products; + * } + * + * // Apply share of global discount + * $discounted_price_tax_excl = $order_detail['unit_price_tax_excl'] - $discount_ratio * $order_discount_tax_excl; + * + * // Apply specific product-level discount + * if (!empty($product_specific_discounts[$order_detail['product_id']])) { + * $discounted_price_tax_excl -= $product_specific_discounts[$order_detail['product_id']]; + * } + */ foreach ($tax_calculator->taxes as $tax) { $tax_rates[$tax->id] = $tax->rate; } - foreach ($tax_calculator->getTaxesAmount($discounted_price_tax_excl) as $id_tax => $unit_amount) { - $total_tax_base = 0; - $total_tax_base = Tools::processPriceRounding($discounted_price_tax_excl, $quantity); - $total_amount = Tools::processPriceRounding($unit_amount, $quantity); - if (!isset($breakdown[$id_tax])) { - $breakdown[$id_tax] = array('tax_base' => 0, 'tax_amount' => 0); - } - - $breakdown[$id_tax]['tax_base'] += $total_tax_base; - $breakdown[$id_tax]['tax_amount'] += $total_amount; - - $order_detail_tax_rows[] = array( - 'id_order_detail' => $id_order_detail, - 'id_tax' => $id_tax, - 'tax_rate' => $tax_rates[$id_tax], - 'unit_tax_base' => $discounted_price_tax_excl, - 'total_tax_base' => $total_tax_base, - 'unit_amount' => $unit_amount, - 'total_amount' => $total_amount + if (!Product::isBookingProduct($order_detail['product_id'])) { + $quantity = Db::getInstance()->getValue( + 'SELECT SUM(`quantity`) + FROM `'._DB_PREFIX_.'service_product_order_detail` + WHERE `id_order_detail` = '.(int)$id_order_detail.' + AND `id_tax_rules_group` > 0 ' ); } - } - if (!empty($order_detail_tax_rows)) { - foreach ($breakdown as $data) { - $actual_total_tax += Tools::ps_round($data['tax_amount'], _PS_PRICE_COMPUTE_PRECISION_, $this->round_mode); - $actual_total_base += Tools::ps_round($data['tax_base'], _PS_PRICE_COMPUTE_PRECISION_, $this->round_mode); + $totalTaxBase = Tools::processPriceRounding($unit_price_tax_excl, $quantity); + + $objServiceProductOrderDetail = new ServiceProductOrderDetail(); + $groupedTaxDetails = array(); + $additionalTaxAmounts = array(); + + if ( + Product::isBookingProduct($order_detail['product_id']) && + $autoAddedPriceExcl = $objServiceProductOrderDetail->getRoomTypeServiceProducts( + $order_detail['id_order'], + 0, 0, + $order_detail['product_id'], + 0, 0, 0, + true, false, true, + Product::PRICE_ADDITION_TYPE_WITH_ROOM + ) + ) { + $additionalTaxAmounts = $tax_calculator->getTaxesAmount($autoAddedPriceExcl); + $totalTaxBase += $autoAddedPriceExcl; } - $order_ecotax_tax = Tools::ps_round($order_ecotax_tax, _PS_PRICE_COMPUTE_PRECISION_, $this->round_mode); + $taxBaseShare = $totalTaxBase / count($tax_rates); - $tax_rounding_error = $expected_total_tax - $actual_total_tax - $order_ecotax_tax; - if ($tax_rounding_error != 0) { - Tools::spreadAmount($tax_rounding_error, _PS_PRICE_COMPUTE_PRECISION_, $order_detail_tax_rows, 'total_amount'); + foreach ($taxesList as $detailTax) { + $taxId = $detailTax['id_tax']; + + $unitAmount = $detailTax['unit_amount'] + ($additionalTaxAmounts[$taxId] ?? 0); + $totalAmount = $detailTax['total_amount'] + ($additionalTaxAmounts[$taxId] ?? 0); + + if (!isset($groupedTaxDetails[$taxId])) { + $groupedTaxDetails[$taxId] = array( + 'id_order_detail' => $id_order_detail, + 'id_tax' => $taxId, + 'tax_rate' => $tax_rates[$taxId], + 'unit_tax_base' => $unit_price_tax_excl, + 'total_tax_base' => $taxBaseShare, + 'unit_amount' => $unitAmount, + 'total_amount' => $totalAmount, + ); + } else { + $groupedTaxDetails[$taxId]['total_amount'] += $totalAmount; + } } - $base_rounding_error = $expected_total_base - $actual_total_base; - if ($base_rounding_error != 0) { - Tools::spreadAmount($base_rounding_error, _PS_PRICE_COMPUTE_PRECISION_, $order_detail_tax_rows, 'total_tax_base'); + if (!empty($groupedTaxDetails)) { + foreach ($groupedTaxDetails as $item) { + $order_detail_tax_rows[] = $item; + } } + + /* + * This tax recalculation logic is intentionally disabled. + * + * Taxes have already been calculated and stored in the `order_detail_tax` table, + * so there is no need to recompute them here. + * + * foreach ($tax_calculator->getTaxesAmount($discounted_price_tax_excl) as $id_tax => $unit_amount) { + * $total_tax_base = 0; + * $total_tax_base = Tools::processPriceRounding($discounted_price_tax_excl, $quantity); + * $total_amount = Tools::processPriceRounding($unit_amount, $quantity); + * + * if (!isset($breakdown[$id_tax])) { + * $breakdown[$id_tax] = array('tax_base' => 0, 'tax_amount' => 0); + * } + * + * $breakdown[$id_tax]['tax_base'] += $total_tax_base; + * $breakdown[$id_tax]['tax_amount'] += $total_amount; + * + * $order_detail_tax_rows[] = array( + * 'id_order_detail' => $id_order_detail, + * 'id_tax' => $id_tax, + * 'tax_rate' => $tax_rates[$id_tax], + * 'unit_tax_base' => $discounted_price_tax_excl, + * 'total_tax_base' => $total_tax_base, + * 'unit_amount' => $unit_amount, + * 'total_amount' => $total_amount + * ); + * } + */ + } + /* + * The following tax adjustment logic was disabled as it is not currently in use. + * It was intended to handle rounding errors in tax and base amounts by spreading + * the discrepancy across order detail tax rows. However, this logic is not required + * due to updated tax calculation and breakdown handling. + */ + + // if (!empty($order_detail_tax_rows)) { + // foreach ($breakdown as $data) { + // $actual_total_tax += Tools::ps_round($data['tax_amount'], _PS_PRICE_COMPUTE_PRECISION_, $this->round_mode); + // $actual_total_base += Tools::ps_round($data['tax_base'], _PS_PRICE_COMPUTE_PRECISION_, $this->round_mode); + // } + + // $order_ecotax_tax = Tools::ps_round($order_ecotax_tax, _PS_PRICE_COMPUTE_PRECISION_, $this->round_mode); + + // $tax_rounding_error = $expected_total_tax - $actual_total_tax - $order_ecotax_tax; + // if ($tax_rounding_error != 0) { + // Tools::spreadAmount($tax_rounding_error, _PS_PRICE_COMPUTE_PRECISION_, $order_detail_tax_rows, 'total_amount'); + // } + + // $base_rounding_error = $expected_total_base - $actual_total_base; + // if ($base_rounding_error != 0) { + // Tools::spreadAmount($base_rounding_error, _PS_PRICE_COMPUTE_PRECISION_, $order_detail_tax_rows, 'total_tax_base'); + // } + // } return $order_detail_tax_rows; } diff --git a/classes/order/OrderDetail.php b/classes/order/OrderDetail.php index 17b1a420e..b0e165b1d 100644 --- a/classes/order/OrderDetail.php +++ b/classes/order/OrderDetail.php @@ -398,27 +398,140 @@ class OrderDetailCore extends ObjectModel } } - $ratio = $this->unit_price_tax_excl / $order->total_products; - $order_reduction_amount = ($order->total_discounts_tax_excl - $shipping_tax_amount) * $ratio; - $discounted_price_tax_excl = $this->unit_price_tax_excl - $order_reduction_amount; - $values = ''; - foreach ($this->tax_calculator->getTaxesAmount($discounted_price_tax_excl) as $id_tax => $amount) { + $idCart = $order->id_cart; - $total_amount = Tools::processPriceRounding($amount, $this->product_quantity, $order->round_type, $order->round_mode); + /** + * Calculate tax rule groups for the service product based on each associated room type. + */ + if (!Product::isBookingProduct($this->product_id)) { + // Get all associated room type IDs for this service product and cart + $associatedRoomTypes = Db::getInstance()->executeS( + 'SELECT hcbd.`id_product` + FROM `'._DB_PREFIX_.'htl_cart_booking_data` hcbd + INNER JOIN `'._DB_PREFIX_.'service_product_cart_detail` spcd + ON spcd.`htl_cart_booking_id` = hcbd.`id` + WHERE spcd.`id_product` = '.(int)$this->product_id.' + AND spcd.`id_cart` = '.(int)$idCart + ); - $values .= '('.(int)$this->id.','.(int)$id_tax.','.(float)$amount.','.(float)$total_amount.'),'; + if (!empty($associatedRoomTypes)) { + $associatedRoomTypeIds = array_column($associatedRoomTypes, 'id_product'); + $taxGroupInfoList = array(); + + foreach ($associatedRoomTypeIds as $idRoomType) { + $taxGroupInfo = Db::getInstance()->getRow( + 'SELECT `id_element`, `id_tax_rules_group` + FROM `'._DB_PREFIX_.'htl_room_type_service_product_price` + WHERE `id_product` = '.(int)$this->product_id.' + AND `id_element` = '.(int)$idRoomType + ); + + if ($taxGroupInfo) { + // Specific tax rules found + $taxGroupInfoList[] = $taxGroupInfo; + } else { + // Use default tax rule for the service product + $defaultTaxGroupId = (int)Product::getIdTaxRulesGroupByIdProduct($this->product_id, $this->context); + $taxGroupInfoList[] = array( + 'id_element' => $idRoomType, + 'id_tax_rules_group' => $defaultTaxGroupId + ); + } + } + } } + + /** + * Calculate service product tax separately for each room type because + * a service product can be attached to multiple room types with different tax rules. + */ + if (!Product::isBookingProduct($this->product_id) && isset($taxGroupInfoList) && $taxGroupInfoList) { + $objServiceProductCartDetail = new ServiceProductCartDetail(); + // Saving tax details according to the service product tax groups for different rooms + foreach ($taxGroupInfoList as $taxGroupInfo) { + $tax_manager = TaxManagerFactory::getManager($this->vat_address, (int)$taxGroupInfo['id_tax_rules_group']); + $this->tax_calculator = $tax_manager->getTaxCalculator(); - if ($replace) { - Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'order_detail_tax` WHERE id_order_detail='.(int)$this->id); + if ($this->tax_calculator == null) { + continue; + } + + if (!($this->tax_calculator instanceof TaxCalculator)) { + continue; + } + + if (count($this->tax_calculator->taxes) == 0) { + continue; + } + + $serviceProductCartData = $objServiceProductCartDetail->getServiceProductsInCart( + $idCart, + array(), + null, + null, + $taxGroupInfo['id_element'], + $this->product_id + ); + $serviceProduct = array_shift($serviceProductCartData); + $unit_price_tax_excl = $serviceProduct['unit_price_tax_excl']; + + foreach ($this->tax_calculator->getTaxesAmount($unit_price_tax_excl) as $id_tax => $amount) { + + $total_amount = Tools::processPriceRounding($amount, $serviceProduct['quantity'], $order->round_type, $order->round_mode); + + $values .= '('.(int)$this->id.','.(int)$id_tax.','.(float)$amount.','.(float)$total_amount.'),'; + } + } + } else { + if ($this->tax_calculator == null) { + return true; + } + + if (!($this->tax_calculator instanceof TaxCalculator)) { + return false; + } + + if (count($this->tax_calculator->taxes) == 0) { + return true; + } + + if ($order->total_products <= 0) { + return true; + } + + $unit_price_tax_excl = $this->total_price_tax_excl / $this->product_quantity; + /* + * The logic for distributing discount proportionally across products is intentionally skipped, + * as we do not want to save taxes on discounted amounts. + * + * $ratio = $unit_price_tax_excl / $order->total_products; + * $order_reduction_amount = ($order->total_discounts_tax_excl - $shipping_tax_amount) * $ratio; + * $discounted_price_tax_excl = $unit_price_tax_excl - $order_reduction_amount; + */ + + foreach ($this->tax_calculator->getTaxesAmount($unit_price_tax_excl) as $id_tax => $amount) { + + $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 = rtrim($values, ','); - $sql = 'INSERT INTO `'._DB_PREFIX_.'order_detail_tax` (id_order_detail, id_tax, unit_amount, total_amount) - VALUES '.$values; - return Db::getInstance()->execute($sql); + if ($values) { + if ($replace) { + Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'order_detail_tax` WHERE id_order_detail='.(int)$this->id); + } + + $sql = 'INSERT INTO `'._DB_PREFIX_.'order_detail_tax` (id_order_detail, id_tax, unit_amount, total_amount) + VALUES '.$values; + + return Db::getInstance()->execute($sql); + } + + return true; } public function updateTaxAmount($order) diff --git a/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php b/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php index d103e1576..a91163edb 100644 --- a/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php +++ b/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php @@ -430,6 +430,8 @@ class HotelReservationSystemDb `id_hotel` int(11) NOT NULL, `id_htl_booking_detail` int(11) NOT NULL, `id_product_option` int(11) NOT NULL, + `tax_computation_method` tinyint(1) unsigned NOT NULL DEFAULT '0', + `id_tax_rules_group` int(11) unsigned NOT NULL DEFAULT '0', `unit_price_tax_excl` decimal(20,6) NOT NULL, `unit_price_tax_incl` decimal(20,6) NOT NULL, `total_price_tax_excl` decimal(20,6) NOT NULL, diff --git a/modules/hotelreservationsystem/classes/ServiceProductOrderDetail.php b/modules/hotelreservationsystem/classes/ServiceProductOrderDetail.php index 173e2fe3f..76151f738 100644 --- a/modules/hotelreservationsystem/classes/ServiceProductOrderDetail.php +++ b/modules/hotelreservationsystem/classes/ServiceProductOrderDetail.php @@ -28,6 +28,8 @@ class ServiceProductOrderDetail extends ObjectModel public $id_hotel; public $id_htl_booking_detail; public $id_product_option; + public $tax_computation_method; + public $id_tax_rules_group; public $unit_price_tax_excl; public $unit_price_tax_incl; public $total_price_tax_excl; @@ -53,6 +55,8 @@ class ServiceProductOrderDetail extends ObjectModel 'id_hotel' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), 'id_htl_booking_detail' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), 'id_product_option' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), + 'tax_computation_method' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), + 'id_tax_rules_group' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), 'unit_price_tax_excl' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPrice', 'required' => true), 'unit_price_tax_incl' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPrice', 'required' => true), 'total_price_tax_excl' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPrice', 'required' => true), @@ -69,6 +73,47 @@ class ServiceProductOrderDetail extends ObjectModel ) ); + public function add($autodate = true, $null_values = true) + { + if (Validate::isLoadedObject($objOrder = new Order((int)$this->id_order)) + && Validate::isLoadedObject($objServiceProduct = new Product((int)$this->id_product)) + ) { + $objAddress = new Address((int)$objOrder->id_address_tax); + $idRoomType = Db::getInstance()->getValue( + 'SELECT `id_product` + FROM `'._DB_PREFIX_.'htl_booking_detail` + WHERE `id` = '.(int)$this->id_htl_booking_detail + ); + + if ($objServiceProduct->price_addition_type == Product::PRICE_ADDITION_TYPE_WITH_ROOM && $objServiceProduct->auto_add_to_cart) { + if (Validate::isLoadedObject($objRoomTypeProduct = new Product((int)$idRoomType))) { + $this->id_tax_rules_group = $objRoomTypeProduct->id_tax_rules_group; + } + } else { + $idTaxRulesGroup = Db::getInstance()->getValue( + 'SELECT `id_tax_rules_group` + FROM `'._DB_PREFIX_.'htl_room_type_service_product_price` + WHERE `id_product` = '.(int)$this->id_product.' + AND `id_element` = '.(int)$idRoomType + ); + + if ($idTaxRulesGroup === false || $idTaxRulesGroup === null) { + // Use default tax rule for the service product + $idTaxRulesGroup = (int)Product::getIdTaxRulesGroupByIdProduct($this->id_product, Context::getContext()); + } + + $this->id_tax_rules_group = $idTaxRulesGroup; + } + + $taxCalculator = TaxManagerFactory::getManager($objAddress, $this->id_tax_rules_group)->getTaxCalculator(); + $this->tax_computation_method = (int)$taxCalculator->computation_method; + + return parent::add($autodate, $null_values); + } + + return false; + } + public function getServiceProductsInOrder( $idOrder, $idOrderDetail = 0, From f0eac28b42a492450e8ddeac7c9a6e1e9d126424 Mon Sep 17 00:00:00 2001 From: Aman deep sharma Date: Fri, 20 Jun 2025 15:39:19 +0530 Subject: [PATCH 02/11] Remove isBookingProduct usage and optimize related logic --- classes/PaymentModule.php | 6 +++ classes/order/Order.php | 34 ++++++++---- classes/order/OrderDetail.php | 48 +++++++++-------- .../classes/ServiceProductOrderDetail.php | 54 ++++++++++--------- 4 files changed, 87 insertions(+), 55 deletions(-) diff --git a/classes/PaymentModule.php b/classes/PaymentModule.php index 9cca21cb6..dde838155 100644 --- a/classes/PaymentModule.php +++ b/classes/PaymentModule.php @@ -1571,6 +1571,12 @@ abstract class PaymentModuleCore extends Module } } } + /** + * This function is not being called because taxes are already saved correctly. + * The issue lies only in displaying the tax breakdown. + * + * $order->updateOrderDetailTax(); + */ } else { $error = Tools::displayError('Order creation failed'); PrestaShopLogger::addLog($error, 4, '0000002', 'Cart', intval($order->id_cart)); diff --git a/classes/order/Order.php b/classes/order/Order.php index 99814f532..39fe39691 100644 --- a/classes/order/Order.php +++ b/classes/order/Order.php @@ -2561,22 +2561,38 @@ class OrderCore extends ObjectModel $tax_rates[$tax->id] = $tax->rate; } - if (!Product::isBookingProduct($order_detail['product_id'])) { - $quantity = Db::getInstance()->getValue( - 'SELECT SUM(`quantity`) - FROM `'._DB_PREFIX_.'service_product_order_detail` - WHERE `id_order_detail` = '.(int)$id_order_detail.' - AND `id_tax_rules_group` > 0 ' - ); - } $totalTaxBase = Tools::processPriceRounding($unit_price_tax_excl, $quantity); + if (!$order_detail['is_booking_product']) { + $objServiceProductOrderDetail = new ServiceProductOrderDetail(); + $serviceProductDetail = $objServiceProductOrderDetail->getServiceProductsInOrder( + $order_detail['id_order'], + $id_order_detail + ); + if ($serviceProductDetail = $objServiceProductOrderDetail->getServiceProductsInOrder( + $order_detail['id_order'], + $id_order_detail + )) { + $totals = array_reduce($serviceProductDetail, function ($carry, $item) { + if (!empty($item['id_tax_rules_group'])) { + $qty = isset($item['quantity']) ? $item['quantity'] : 0; + $price = isset($item['unit_price_tax_excl']) ? $item['unit_price_tax_excl'] : 0; + + $carry['quantity'] += $qty; + $carry['total_price_tax_excl'] += $price; + } + return $carry; + }, ['quantity' => 0, 'total_price_tax_excl' => 0]); + $quantity = $totals['quantity']; + $totalTaxBase = $totals['total_price_tax_excl']; + } + } $objServiceProductOrderDetail = new ServiceProductOrderDetail(); $groupedTaxDetails = array(); $additionalTaxAmounts = array(); if ( - Product::isBookingProduct($order_detail['product_id']) && + $order_detail['is_booking_product'] && $autoAddedPriceExcl = $objServiceProductOrderDetail->getRoomTypeServiceProducts( $order_detail['id_order'], 0, 0, diff --git a/classes/order/OrderDetail.php b/classes/order/OrderDetail.php index b0e165b1d..75d254e40 100644 --- a/classes/order/OrderDetail.php +++ b/classes/order/OrderDetail.php @@ -404,7 +404,7 @@ class OrderDetailCore extends ObjectModel /** * Calculate tax rule groups for the service product based on each associated room type. */ - if (!Product::isBookingProduct($this->product_id)) { + if (!$this->is_booking_product && $this->selling_preference_type == Product::SELLING_PREFERENCE_WITH_ROOM_TYPE) { // Get all associated room type IDs for this service product and cart $associatedRoomTypes = Db::getInstance()->executeS( 'SELECT hcbd.`id_product` @@ -420,22 +420,21 @@ class OrderDetailCore extends ObjectModel $taxGroupInfoList = array(); foreach ($associatedRoomTypeIds as $idRoomType) { - $taxGroupInfo = Db::getInstance()->getRow( - 'SELECT `id_element`, `id_tax_rules_group` - FROM `'._DB_PREFIX_.'htl_room_type_service_product_price` - WHERE `id_product` = '.(int)$this->product_id.' - AND `id_element` = '.(int)$idRoomType - ); - - if ($taxGroupInfo) { - // Specific tax rules found - $taxGroupInfoList[] = $taxGroupInfo; - } else { - // Use default tax rule for the service product - $defaultTaxGroupId = (int)Product::getIdTaxRulesGroupByIdProduct($this->product_id, $this->context); + if ($serviceProductPriceRoomInfo = RoomTypeServiceProductPrice::getProductRoomTypePriceAndTax( + $this->product_id, + $idRoomType, + RoomTypeServiceProduct::WK_ELEMENT_TYPE_ROOM_TYPE + )) { + //Special tax rule group for the Service product accroding to Room type $taxGroupInfoList[] = array( - 'id_element' => $idRoomType, - 'id_tax_rules_group' => $defaultTaxGroupId + 'id_room_type' => $idRoomType, + 'id_tax_rules_group' => $serviceProductPriceRoomInfo['id_tax_rules_group'] + ); + } else { + // Use default tax rule group for the service product + $taxGroupInfoList[] = array( + 'id_room_type' => $idRoomType, + 'id_tax_rules_group' => $objOrderDetail->id_tax_rules_group ); } } @@ -446,7 +445,7 @@ class OrderDetailCore extends ObjectModel * Calculate service product tax separately for each room type because * a service product can be attached to multiple room types with different tax rules. */ - if (!Product::isBookingProduct($this->product_id) && isset($taxGroupInfoList) && $taxGroupInfoList) { + if (!$this->is_booking_product && isset($taxGroupInfoList) && $taxGroupInfoList) { $objServiceProductCartDetail = new ServiceProductCartDetail(); // Saving tax details according to the service product tax groups for different rooms foreach ($taxGroupInfoList as $taxGroupInfo) { @@ -470,15 +469,22 @@ class OrderDetailCore extends ObjectModel array(), null, null, - $taxGroupInfo['id_element'], + $taxGroupInfo['id_room_type'], $this->product_id ); - $serviceProduct = array_shift($serviceProductCartData); - $unit_price_tax_excl = $serviceProduct['unit_price_tax_excl']; + $total_price_tax_excl = array_reduce($serviceProductCartData, function ($totalPriceTaxExcl, $item) { + return $totalPriceTaxExcl + (isset($item['total_price_tax_excl']) ? $item['total_price_tax_excl'] : 0); + }, 0); + + $quantity = array_reduce($serviceProductCartData, function ($totalQty, $item) { + return $totalQty + (isset($item['quantity']) ? $item['quantity'] : 0); + }, 0); + + $unit_price_tax_excl = $total_price_tax_excl / $quantity; foreach ($this->tax_calculator->getTaxesAmount($unit_price_tax_excl) as $id_tax => $amount) { - $total_amount = Tools::processPriceRounding($amount, $serviceProduct['quantity'], $order->round_type, $order->round_mode); + $total_amount = Tools::processPriceRounding($amount, $quantity, $order->round_type, $order->round_mode); $values .= '('.(int)$this->id.','.(int)$id_tax.','.(float)$amount.','.(float)$total_amount.'),'; } diff --git a/modules/hotelreservationsystem/classes/ServiceProductOrderDetail.php b/modules/hotelreservationsystem/classes/ServiceProductOrderDetail.php index 76151f738..6802a6700 100644 --- a/modules/hotelreservationsystem/classes/ServiceProductOrderDetail.php +++ b/modules/hotelreservationsystem/classes/ServiceProductOrderDetail.php @@ -77,37 +77,41 @@ class ServiceProductOrderDetail extends ObjectModel { if (Validate::isLoadedObject($objOrder = new Order((int)$this->id_order)) && Validate::isLoadedObject($objServiceProduct = new Product((int)$this->id_product)) + && Validate::isLoadedObject($objOrderDetail = new OrderDetail((int)$this->id_order_detail)) ) { - $objAddress = new Address((int)$objOrder->id_address_tax); - $idRoomType = Db::getInstance()->getValue( - 'SELECT `id_product` - FROM `'._DB_PREFIX_.'htl_booking_detail` - WHERE `id` = '.(int)$this->id_htl_booking_detail - ); + if ($objOrderDetail->selling_preference_type == Product::SELLING_PREFERENCE_WITH_ROOM_TYPE) { + if ($this->id_htl_booking_detail + && Validate::isLoadedObject($objHotelBookingDetail = new HotelBookingDetail((int)$this->id_htl_booking_detail)) + ) { + $idRoomType = $objHotelBookingDetail->id_product; + $objAddress = new Address((int)$objOrder->id_address_tax); + if ($objServiceProduct->auto_add_to_cart && $objServiceProduct->price_addition_type == Product::PRICE_ADDITION_TYPE_WITH_ROOM) { + if (Validate::isLoadedObject($objRoomTypeProduct = new Product((int)$idRoomType))) { + $this->id_tax_rules_group = $objRoomTypeProduct->id_tax_rules_group; + } + } else { + if ($serviceProductPriceRoomInfo = RoomTypeServiceProductPrice::getProductRoomTypePriceAndTax( + $this->id_product, + $idRoomType, + RoomTypeServiceProduct::WK_ELEMENT_TYPE_ROOM_TYPE + )) { + //Special tax rule group for the Service product accroding to Room type + $this->id_tax_rules_group = $serviceProductPriceRoomInfo['id_tax_rules_group']; + } else { + // Use default tax rule group for the service product + $this->id_tax_rules_group = $objOrderDetail->id_tax_rules_group; + } + } - if ($objServiceProduct->price_addition_type == Product::PRICE_ADDITION_TYPE_WITH_ROOM && $objServiceProduct->auto_add_to_cart) { - if (Validate::isLoadedObject($objRoomTypeProduct = new Product((int)$idRoomType))) { - $this->id_tax_rules_group = $objRoomTypeProduct->id_tax_rules_group; + $taxCalculator = TaxManagerFactory::getManager($objAddress, $this->id_tax_rules_group)->getTaxCalculator(); + $this->tax_computation_method = (int)$taxCalculator->computation_method; } } else { - $idTaxRulesGroup = Db::getInstance()->getValue( - 'SELECT `id_tax_rules_group` - FROM `'._DB_PREFIX_.'htl_room_type_service_product_price` - WHERE `id_product` = '.(int)$this->id_product.' - AND `id_element` = '.(int)$idRoomType - ); - - if ($idTaxRulesGroup === false || $idTaxRulesGroup === null) { - // Use default tax rule for the service product - $idTaxRulesGroup = (int)Product::getIdTaxRulesGroupByIdProduct($this->id_product, Context::getContext()); - } - - $this->id_tax_rules_group = $idTaxRulesGroup; + // Use default tax rule group for the service product + $this->id_tax_rules_group = $objOrderDetail->id_tax_rules_group; + $this->tax_computation_method = $objOrderDetail->tax_computation_method; } - $taxCalculator = TaxManagerFactory::getManager($objAddress, $this->id_tax_rules_group)->getTaxCalculator(); - $this->tax_computation_method = (int)$taxCalculator->computation_method; - return parent::add($autodate, $null_values); } From 0a4d532c16d9906e5325de76229d0b5512857b19 Mon Sep 17 00:00:00 2001 From: Aman deep sharma Date: Fri, 20 Jun 2025 17:30:11 +0530 Subject: [PATCH 03/11] Fix tax details in order invoice and credit slip --- classes/order/Order.php | 2 +- classes/order/OrderInvoice.php | 15 +++++---------- classes/pdf/HTMLTemplateOrderSlip.php | 3 +-- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/classes/order/Order.php b/classes/order/Order.php index 39fe39691..775ddac36 100644 --- a/classes/order/Order.php +++ b/classes/order/Order.php @@ -2606,7 +2606,7 @@ class OrderCore extends ObjectModel $totalTaxBase += $autoAddedPriceExcl; } - $taxBaseShare = $totalTaxBase / count($tax_rates); + $taxBaseShare = $totalTaxBase; foreach ($taxesList as $detailTax) { $taxId = $detailTax['id_tax']; diff --git a/classes/order/OrderInvoice.php b/classes/order/OrderInvoice.php index 6319dc68d..3531e04ac 100644 --- a/classes/order/OrderInvoice.php +++ b/classes/order/OrderInvoice.php @@ -365,14 +365,13 @@ class OrderInvoiceCore extends ObjectModel if (!isset($grouped_details[$row['id_order_detail']])) { $grouped_details[$row['id_order_detail']] = array( 'tax_rate' => 0, - 'total_tax_base' => 0, + 'total_tax_base' => $row['total_tax_base'], 'total_amount' => 0, 'id_tax' => $row['id_tax'], ); } $grouped_details[$row['id_order_detail']]['tax_rate'] += $row['tax_rate']; - $grouped_details[$row['id_order_detail']]['total_tax_base'] += $row['total_tax_base']; $grouped_details[$row['id_order_detail']]['total_amount'] += $row['total_amount']; } $details = $grouped_details; @@ -430,14 +429,13 @@ class OrderInvoiceCore extends ObjectModel if (!isset($grouped_details[$row['id_order_detail']])) { $grouped_details[$row['id_order_detail']] = array( 'tax_rate' => 0, - 'total_tax_base' => 0, + 'total_tax_base' => $row['total_tax_base'], 'total_amount' => 0, 'id_tax' => $row['id_tax'], ); } $grouped_details[$row['id_order_detail']]['tax_rate'] += $row['tax_rate']; - $grouped_details[$row['id_order_detail']]['total_tax_base'] += $row['total_tax_base']; $grouped_details[$row['id_order_detail']]['total_amount'] += $row['total_amount']; } $details = $grouped_details; @@ -494,14 +492,13 @@ class OrderInvoiceCore extends ObjectModel if (!isset($grouped_details[$row['id_order_detail']])) { $grouped_details[$row['id_order_detail']] = array( 'tax_rate' => 0, - 'total_tax_base' => 0, + 'total_tax_base' => $row['total_tax_base'], 'total_amount' => 0, 'id_tax' => $row['id_tax'], ); } $grouped_details[$row['id_order_detail']]['tax_rate'] += $row['tax_rate']; - $grouped_details[$row['id_order_detail']]['total_tax_base'] += $row['total_tax_base']; $grouped_details[$row['id_order_detail']]['total_amount'] += $row['total_amount']; } $details = $grouped_details; @@ -563,14 +560,13 @@ class OrderInvoiceCore extends ObjectModel if (!isset($grouped_details[$row['id_order_detail']])) { $grouped_details[$row['id_order_detail']] = array( 'tax_rate' => 0, - 'total_tax_base' => 0, + 'total_tax_base' => $row['total_tax_base'], 'total_amount' => 0, 'id_tax' => $row['id_tax'], ); } $grouped_details[$row['id_order_detail']]['tax_rate'] += $row['tax_rate']; - $grouped_details[$row['id_order_detail']]['total_tax_base'] += $row['total_tax_base']; $grouped_details[$row['id_order_detail']]['total_amount'] += $row['total_amount']; } $details = $grouped_details; @@ -632,14 +628,13 @@ class OrderInvoiceCore extends ObjectModel if (!isset($grouped_details[$row['id_order_detail']])) { $grouped_details[$row['id_order_detail']] = array( 'tax_rate' => 0, - 'total_tax_base' => 0, + 'total_tax_base' => $row['total_tax_base'], 'total_amount' => 0, 'id_tax' => $row['id_tax'], ); } $grouped_details[$row['id_order_detail']]['tax_rate'] += $row['tax_rate']; - $grouped_details[$row['id_order_detail']]['total_tax_base'] += $row['total_tax_base']; $grouped_details[$row['id_order_detail']]['total_amount'] += $row['total_amount']; } $details = $grouped_details; diff --git a/classes/pdf/HTMLTemplateOrderSlip.php b/classes/pdf/HTMLTemplateOrderSlip.php index 9c1dc2579..c520fe521 100644 --- a/classes/pdf/HTMLTemplateOrderSlip.php +++ b/classes/pdf/HTMLTemplateOrderSlip.php @@ -298,14 +298,13 @@ class HTMLTemplateOrderSlipCore extends HTMLTemplateInvoice if (!isset($grouped_details[$row['id_order_detail']])) { $grouped_details[$row['id_order_detail']] = array( 'tax_rate' => 0, - 'total_tax_base' => 0, + 'total_tax_base' => $row['total_tax_base'], 'total_amount' => 0, 'id_tax' => $row['id_tax'], ); } $grouped_details[$row['id_order_detail']]['tax_rate'] += $row['tax_rate']; - $grouped_details[$row['id_order_detail']]['total_tax_base'] += $row['total_tax_base']; $grouped_details[$row['id_order_detail']]['total_amount'] += $row['total_amount']; } $details = $grouped_details; From e89a3940eb37cf0b7e7e5d8476f98c8a6c36e20b Mon Sep 17 00:00:00 2001 From: Aman deep sharma Date: Fri, 20 Jun 2025 19:03:12 +0530 Subject: [PATCH 04/11] Fix: Ensure accurate saving of order detail tax data --- classes/order/OrderDetail.php | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/classes/order/OrderDetail.php b/classes/order/OrderDetail.php index 75d254e40..3e23ccdd6 100644 --- a/classes/order/OrderDetail.php +++ b/classes/order/OrderDetail.php @@ -372,23 +372,6 @@ class OrderDetailCore extends ObjectModel */ public function saveTaxCalculator(Order $order, $replace = false) { - // Nothing to save - if ($this->tax_calculator == null) { - return true; - } - - if (!($this->tax_calculator instanceof TaxCalculator)) { - return false; - } - - if (count($this->tax_calculator->taxes) == 0) { - return true; - } - - if ($order->total_products <= 0) { - return true; - } - $shipping_tax_amount = 0; foreach ($order->getCartRules() as $cart_rule) { From 75e8455ebf80e70abbaeaa0ee7e5cb52700b0523 Mon Sep 17 00:00:00 2001 From: Aman deep sharma Date: Sat, 21 Jun 2025 19:54:11 +0530 Subject: [PATCH 05/11] Fixed: No tax applied if catalog price rule is created --- classes/order/OrderDetail.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/order/OrderDetail.php b/classes/order/OrderDetail.php index 3e23ccdd6..32aaaad93 100644 --- a/classes/order/OrderDetail.php +++ b/classes/order/OrderDetail.php @@ -652,7 +652,7 @@ class OrderDetailCore extends ObjectModel if ($product !== null) { $this->setContext((int)$product['id_shop']); } - $id_tax_rules = (int)Product::getIdTaxRulesGroupByIdProduct((int)$this->specificPrice['id_product'], $this->context); + $id_tax_rules = (int)Product::getIdTaxRulesGroupByIdProduct((int)$this->product_id, $this->context); $tax_manager = TaxManagerFactory::getManager($this->vat_address, $id_tax_rules); $this->tax_calculator = $tax_manager->getTaxCalculator(); From 1e74c4c1c3982dcbab53105c10f3549d9fde6f31 Mon Sep 17 00:00:00 2001 From: Aman deep sharma Date: Thu, 26 Jun 2025 11:46:48 +0530 Subject: [PATCH 06/11] Fixed: Wrong function call and syntax error --- classes/order/OrderDetail.php | 13 ++++++++----- classes/tax/TaxRulesGroup.php | 4 ++++ .../classes/ServiceProductOrderDetail.php | 3 ++- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/classes/order/OrderDetail.php b/classes/order/OrderDetail.php index 32aaaad93..01e9b32da 100644 --- a/classes/order/OrderDetail.php +++ b/classes/order/OrderDetail.php @@ -388,11 +388,14 @@ class OrderDetailCore extends ObjectModel * Calculate tax rule groups for the service product based on each associated room type. */ if (!$this->is_booking_product && $this->selling_preference_type == Product::SELLING_PREFERENCE_WITH_ROOM_TYPE) { + if ($this->product_auto_add && $this->product_price_addition_type == Product::PRICE_ADDITION_TYPE_WITH_ROOM) { + return true; + } // Get all associated room type IDs for this service product and cart $associatedRoomTypes = Db::getInstance()->executeS( - 'SELECT hcbd.`id_product` + 'SELECT hcbd.`id_product` FROM `'._DB_PREFIX_.'htl_cart_booking_data` hcbd - INNER JOIN `'._DB_PREFIX_.'service_product_cart_detail` spcd + INNER JOIN `'._DB_PREFIX_.'service_product_cart_detail` spcd ON spcd.`htl_cart_booking_id` = hcbd.`id` WHERE spcd.`id_product` = '.(int)$this->product_id.' AND spcd.`id_cart` = '.(int)$idCart @@ -401,9 +404,9 @@ class OrderDetailCore extends ObjectModel if (!empty($associatedRoomTypes)) { $associatedRoomTypeIds = array_column($associatedRoomTypes, 'id_product'); $taxGroupInfoList = array(); - + $objRoomTypeServiceProductPrice = new RoomTypeServiceProductPrice(); foreach ($associatedRoomTypeIds as $idRoomType) { - if ($serviceProductPriceRoomInfo = RoomTypeServiceProductPrice::getProductRoomTypePriceAndTax( + if ($serviceProductPriceRoomInfo = $objRoomTypeServiceProductPrice->getProductRoomTypeLinkPriceInfo( $this->product_id, $idRoomType, RoomTypeServiceProduct::WK_ELEMENT_TYPE_ROOM_TYPE @@ -417,7 +420,7 @@ class OrderDetailCore extends ObjectModel // Use default tax rule group for the service product $taxGroupInfoList[] = array( 'id_room_type' => $idRoomType, - 'id_tax_rules_group' => $objOrderDetail->id_tax_rules_group + 'id_tax_rules_group' => $this->id_tax_rules_group ); } } diff --git a/classes/tax/TaxRulesGroup.php b/classes/tax/TaxRulesGroup.php index fda98ba26..c37d6367a 100644 --- a/classes/tax/TaxRulesGroup.php +++ b/classes/tax/TaxRulesGroup.php @@ -101,6 +101,10 @@ class TaxRulesGroupCore extends ObjectModel UPDATE '._DB_PREFIX_.'product SET id_tax_rules_group='.(int)$tax_rules_group->id.' WHERE id_tax_rules_group='.(int)$this->id) && + Db::getInstance()->execute(' + UPDATE '._DB_PREFIX_.'htl_room_type_service_product_price + SET id_tax_rules_group='.(int)$tax_rules_group->id.' + WHERE id_tax_rules_group='.(int)$this->id) && Db::getInstance()->execute(' UPDATE '._DB_PREFIX_.'product_shop SET id_tax_rules_group='.(int)$tax_rules_group->id.' diff --git a/modules/hotelreservationsystem/classes/ServiceProductOrderDetail.php b/modules/hotelreservationsystem/classes/ServiceProductOrderDetail.php index 6802a6700..33202537b 100644 --- a/modules/hotelreservationsystem/classes/ServiceProductOrderDetail.php +++ b/modules/hotelreservationsystem/classes/ServiceProductOrderDetail.php @@ -90,7 +90,8 @@ class ServiceProductOrderDetail extends ObjectModel $this->id_tax_rules_group = $objRoomTypeProduct->id_tax_rules_group; } } else { - if ($serviceProductPriceRoomInfo = RoomTypeServiceProductPrice::getProductRoomTypePriceAndTax( + $objRoomTypeServiceProductPrice = new RoomTypeServiceProductPrice(); + if ($serviceProductPriceRoomInfo = $objRoomTypeServiceProductPrice->getProductRoomTypeLinkPriceInfo( $this->id_product, $idRoomType, RoomTypeServiceProduct::WK_ELEMENT_TYPE_ROOM_TYPE From 25285d67b63d439932bd5bac6eac5196b3b228be Mon Sep 17 00:00:00 2001 From: Aman deep sharma Date: Thu, 26 Jun 2025 16:01:48 +0530 Subject: [PATCH 07/11] Fixed tax issues on order edit --- classes/order/OrderDetail.php | 68 +++++++++++++++++++++++------------ 1 file changed, 45 insertions(+), 23 deletions(-) diff --git a/classes/order/OrderDetail.php b/classes/order/OrderDetail.php index 01e9b32da..c13878059 100644 --- a/classes/order/OrderDetail.php +++ b/classes/order/OrderDetail.php @@ -382,7 +382,10 @@ class OrderDetailCore extends ObjectModel } $values = ''; - $idCart = $order->id_cart; + $idCart = $this->context->cart->id ?? $order->id_cart; + if (empty($this->vat_address)) { + $this->vat_address = new Address((int)$order->id_address_tax); + } /** * Calculate tax rule groups for the service product based on each associated room type. @@ -406,19 +409,20 @@ class OrderDetailCore extends ObjectModel $taxGroupInfoList = array(); $objRoomTypeServiceProductPrice = new RoomTypeServiceProductPrice(); foreach ($associatedRoomTypeIds as $idRoomType) { + $key = $this->product_id.'_'.$idRoomType; if ($serviceProductPriceRoomInfo = $objRoomTypeServiceProductPrice->getProductRoomTypeLinkPriceInfo( $this->product_id, $idRoomType, RoomTypeServiceProduct::WK_ELEMENT_TYPE_ROOM_TYPE )) { //Special tax rule group for the Service product accroding to Room type - $taxGroupInfoList[] = array( + $taxGroupInfoList[$key] = array( 'id_room_type' => $idRoomType, 'id_tax_rules_group' => $serviceProductPriceRoomInfo['id_tax_rules_group'] ); } else { // Use default tax rule group for the service product - $taxGroupInfoList[] = array( + $taxGroupInfoList[$key] = array( 'id_room_type' => $idRoomType, 'id_tax_rules_group' => $this->id_tax_rules_group ); @@ -433,6 +437,7 @@ class OrderDetailCore extends ObjectModel */ if (!$this->is_booking_product && isset($taxGroupInfoList) && $taxGroupInfoList) { $objServiceProductCartDetail = new ServiceProductCartDetail(); + $objServiceProductOrderDetail = new ServiceProductOrderDetail(); // Saving tax details according to the service product tax groups for different rooms foreach ($taxGroupInfoList as $taxGroupInfo) { $tax_manager = TaxManagerFactory::getManager($this->vat_address, (int)$taxGroupInfo['id_tax_rules_group']); @@ -450,29 +455,46 @@ class OrderDetailCore extends ObjectModel continue; } - $serviceProductCartData = $objServiceProductCartDetail->getServiceProductsInCart( - $idCart, - array(), - null, - null, - $taxGroupInfo['id_room_type'], - $this->product_id - ); - $total_price_tax_excl = array_reduce($serviceProductCartData, function ($totalPriceTaxExcl, $item) { - return $totalPriceTaxExcl + (isset($item['total_price_tax_excl']) ? $item['total_price_tax_excl'] : 0); - }, 0); + if ($serviceProductData = $objServiceProductOrderDetail->getRoomTypeServiceProducts( + $this->id_order, + $this->product_id, + 0, + $taxGroupInfo['id_room_type'], + )) { + $total_price_tax_excl = array_reduce($serviceProductData, function ($totalPriceTaxExcl, $item) { + return $totalPriceTaxExcl + (isset($item['total_price_tax_excl']) ? $item['total_price_tax_excl'] : 0); + }, 0); - $quantity = array_reduce($serviceProductCartData, function ($totalQty, $item) { - return $totalQty + (isset($item['quantity']) ? $item['quantity'] : 0); - }, 0); + $serviceProductData = array_shift($serviceProductData); - $unit_price_tax_excl = $total_price_tax_excl / $quantity; + $quantity = array_reduce($serviceProductData['additional_services'], function ($totalQty, $item) { + return $totalQty + (isset($item['quantity']) ? $item['quantity'] : 0); + }, 0); + } elseif ($serviceProductData = $objServiceProductCartDetail->getServiceProductsInCart( + $idCart, + array(), + null, + null, + $taxGroupInfo['id_room_type'], + $this->product_id + )) { + $total_price_tax_excl = array_reduce($serviceProductData, function ($totalPriceTaxExcl, $item) { + return $totalPriceTaxExcl + (isset($item['total_price_tax_excl']) ? $item['total_price_tax_excl'] : 0); + }, 0); + + $quantity = array_reduce($serviceProductData, function ($totalQty, $item) { + return $totalQty + (isset($item['quantity']) ? $item['quantity'] : 0); + }, 0); + } - foreach ($this->tax_calculator->getTaxesAmount($unit_price_tax_excl) as $id_tax => $amount) { - - $total_amount = Tools::processPriceRounding($amount, $quantity, $order->round_type, $order->round_mode); - - $values .= '('.(int)$this->id.','.(int)$id_tax.','.(float)$amount.','.(float)$total_amount.'),'; + if (isset($quantity) && isset($total_price_tax_excl)) { + $unit_price_tax_excl = $total_price_tax_excl / $quantity; + foreach ($this->tax_calculator->getTaxesAmount($unit_price_tax_excl) as $id_tax => $amount) { + + $total_amount = Tools::processPriceRounding($amount, $quantity, $order->round_type, $order->round_mode); + + $values .= '('.(int)$this->id.','.(int)$id_tax.','.(float)$amount.','.(float)$total_amount.'),'; + } } } } else { From 1d57c006c66c54a6b213fc76b7b14098baac4b95 Mon Sep 17 00:00:00 2001 From: Aman deep sharma Date: Thu, 26 Jun 2025 16:43:49 +0530 Subject: [PATCH 08/11] Fixed worng base price in invoice tax breakdown --- classes/order/Order.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/classes/order/Order.php b/classes/order/Order.php index 775ddac36..3268193c2 100644 --- a/classes/order/Order.php +++ b/classes/order/Order.php @@ -2564,10 +2564,6 @@ class OrderCore extends ObjectModel $totalTaxBase = Tools::processPriceRounding($unit_price_tax_excl, $quantity); if (!$order_detail['is_booking_product']) { $objServiceProductOrderDetail = new ServiceProductOrderDetail(); - $serviceProductDetail = $objServiceProductOrderDetail->getServiceProductsInOrder( - $order_detail['id_order'], - $id_order_detail - ); if ($serviceProductDetail = $objServiceProductOrderDetail->getServiceProductsInOrder( $order_detail['id_order'], $id_order_detail @@ -2575,7 +2571,7 @@ class OrderCore extends ObjectModel $totals = array_reduce($serviceProductDetail, function ($carry, $item) { if (!empty($item['id_tax_rules_group'])) { $qty = isset($item['quantity']) ? $item['quantity'] : 0; - $price = isset($item['unit_price_tax_excl']) ? $item['unit_price_tax_excl'] : 0; + $price = isset($item['total_price_tax_excl']) ? $item['total_price_tax_excl'] : 0; $carry['quantity'] += $qty; $carry['total_price_tax_excl'] += $price; From a54eac9403a4270b8a171cc8026b9548f243bda0 Mon Sep 17 00:00:00 2001 From: Sumit Panwar Date: Fri, 27 Jun 2025 12:04:27 +0530 Subject: [PATCH 09/11] Fixed: Issues in standard product price and quantity calculations --- classes/Cart.php | 8 +- controllers/admin/AdminOrdersController.php | 4 +- .../admin/AdminPPreferencesController.php | 148 +++++++++--------- modules/blockcart/ajax-cart.js | 2 +- .../js/modules/blockcart/ajax-cart.js | 2 +- 5 files changed, 82 insertions(+), 82 deletions(-) diff --git a/classes/Cart.php b/classes/Cart.php index b1e132d31..b5d1eb461 100644 --- a/classes/Cart.php +++ b/classes/Cart.php @@ -1816,15 +1816,15 @@ class CartCore extends ObjectModel if ($servicePorducts) { foreach ($servicePorducts as $servicePorduct) { if ($with_taxes) { - $priceAdd = $servicePorduct['unit_price_tax_incl']; + $priceAdd = $servicePorduct['total_price_tax_incl']; } else { - $priceAdd = $servicePorduct['unit_price_tax_excl']; + $priceAdd = $servicePorduct['total_price_tax_excl']; } if ($ps_round_type == Order::ROUND_TOTAL) { - $products_total[$id_tax_rules_group.'_'.$id_address] += Tools::processPriceRounding($priceAdd, (int)$servicePorduct['quantity']); + $products_total[$id_tax_rules_group.'_'.$id_address] += $priceAdd; } else { - $products_total[$id_tax_rules_group] += Tools::processPriceRounding($priceAdd, (int)$servicePorduct['quantity']); + $products_total[$id_tax_rules_group] += $priceAdd; } } } diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index ad992ba1d..a97598697 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -6139,7 +6139,7 @@ class AdminOrdersControllerCore extends AdminController $product_quantity = $editProductInfo['product_quantity']; if ($updateQty = (int)($product_quantity - $objServiceProductOrderDetail->quantity)) { - $this->checkStockAvailable($objOrderDetail, ($product_quantity - $objOrderDetail->product_quantity)); + $this->checkStockAvailable($objOrderDetail, $updateQty); } $taxRate = $objServiceProductOrderDetail->unit_price_tax_incl / $objServiceProductOrderDetail->unit_price_tax_excl; @@ -6207,7 +6207,7 @@ class AdminOrdersControllerCore extends AdminController // Update product available quantity if ($updateQty) { - $result &= StockAvailable::updateQuantity($objOrderDetail->product_id, $objOrderDetail->product_attribute_id, $updateQty, $objOrder->id_shop); + $result &= StockAvailable::updateQuantity($objOrderDetail->product_id, $objOrderDetail->product_attribute_id, -(int)$updateQty, $objOrder->id_shop); } if (!$result) { diff --git a/controllers/admin/AdminPPreferencesController.php b/controllers/admin/AdminPPreferencesController.php index c5bd1dfbb..4794c1f9a 100644 --- a/controllers/admin/AdminPPreferencesController.php +++ b/controllers/admin/AdminPPreferencesController.php @@ -331,80 +331,80 @@ class AdminPPreferencesControllerCore extends AdminController ), 'submit' => array('title' => $this->l('Save')) ), - 'stock' => array( - 'title' => $this->l('Products stock'), - 'fields' => array( - 'PS_ORDER_OUT_OF_STOCK' => array( - 'title' => $this->l('Allow ordering of out-of-stock products'), - 'hint' => $this->l('By default, the Add to Cart button is hidden when a product is unavailable. You can choose to have it displayed in all cases.'), - 'validation' => 'isBool', - 'cast' => 'intval', - 'required' => false, - 'type' => 'bool' - ), - 'PS_STOCK_MANAGEMENT' => array( - 'title' => $this->l('Enable stock management'), - 'validation' => 'isBool', - 'cast' => 'intval', - 'required' => false, - 'type' => 'bool', - 'js' => array( - 'on' => 'onchange="stockManagementActivationAuthorization()"', - 'off' => 'onchange="stockManagementActivationAuthorization()"' - ) - ), - // 'PS_ADVANCED_STOCK_MANAGEMENT' => array( - // 'title' => $this->l('Enable advanced stock management'), - // 'hint' => $this->l('Allows you to manage physical stock, warehouses and supply orders in a new Stock menu.'), - // 'validation' => 'isBool', - // 'cast' => 'intval', - // 'required' => false, - // 'type' => 'bool', - // 'visibility' => Shop::CONTEXT_ALL, - // 'js' => array( - // 'on' => 'onchange="advancedStockManagementActivationAuthorization()"', - // 'off' => 'onchange="advancedStockManagementActivationAuthorization()"' - // ) - // ), - // 'PS_FORCE_ASM_NEW_PRODUCT' => array( - // 'title' => $this->l('New products use advanced stock management'), - // 'hint' => $this->l('New products will automatically use advanced stock management and depends on stock, but no warehouse will be selected'), - // 'validation' => 'isBool', - // 'cast' => 'intval', - // 'required' => false, - // 'type' => 'bool', - // 'visibility' => Shop::CONTEXT_ALL, - // ), - // 'PS_DEFAULT_WAREHOUSE_NEW_PRODUCT' => array( - // 'title' => $this->l('Default warehouse on new products'), - // 'hint' => $this->l('Automatically set a default warehouse when new product is created'), - // 'type' => 'select', - // 'list' => $warehouse_list, - // 'identifier' => 'id_warehouse' - // ), - // 'PS_PACK_STOCK_TYPE' => array( - // 'title' => $this->l('Default pack stock management'), - // 'type' => 'select', - // 'list' =>array( - // array( - // 'pack_stock' => 0, - // 'name' => $this->l('Decrement pack only.') - // ), - // array( - // 'pack_stock' => 1, - // 'name' => $this->l('Decrement products in pack only.') - // ), - // array( - // 'pack_stock' => 2, - // 'name' => $this->l('Decrement both.') - // ), - // ), - // 'identifier' => 'pack_stock', - // ), - ), - // 'bottom' => '', - 'submit' => array('title' => $this->l('Save')) - ), + // 'stock' => array( + // 'title' => $this->l('Products stock'), + // 'fields' => array( + // 'PS_ORDER_OUT_OF_STOCK' => array( + // 'title' => $this->l('Allow ordering of out-of-stock products'), + // 'hint' => $this->l('By default, the Add to Cart button is hidden when a product is unavailable. You can choose to have it displayed in all cases.'), + // 'validation' => 'isBool', + // 'cast' => 'intval', + // 'required' => false, + // 'type' => 'bool' + // ), + // 'PS_STOCK_MANAGEMENT' => array( + // 'title' => $this->l('Enable stock management'), + // 'validation' => 'isBool', + // 'cast' => 'intval', + // 'required' => false, + // 'type' => 'bool', + // 'js' => array( + // 'on' => 'onchange="stockManagementActivationAuthorization()"', + // 'off' => 'onchange="stockManagementActivationAuthorization()"' + // ) + // ), + // // 'PS_ADVANCED_STOCK_MANAGEMENT' => array( + // // 'title' => $this->l('Enable advanced stock management'), + // // 'hint' => $this->l('Allows you to manage physical stock, warehouses and supply orders in a new Stock menu.'), + // // 'validation' => 'isBool', + // // 'cast' => 'intval', + // // 'required' => false, + // // 'type' => 'bool', + // // 'visibility' => Shop::CONTEXT_ALL, + // // 'js' => array( + // // 'on' => 'onchange="advancedStockManagementActivationAuthorization()"', + // // 'off' => 'onchange="advancedStockManagementActivationAuthorization()"' + // // ) + // // ), + // // 'PS_FORCE_ASM_NEW_PRODUCT' => array( + // // 'title' => $this->l('New products use advanced stock management'), + // // 'hint' => $this->l('New products will automatically use advanced stock management and depends on stock, but no warehouse will be selected'), + // // 'validation' => 'isBool', + // // 'cast' => 'intval', + // // 'required' => false, + // // 'type' => 'bool', + // // 'visibility' => Shop::CONTEXT_ALL, + // // ), + // // 'PS_DEFAULT_WAREHOUSE_NEW_PRODUCT' => array( + // // 'title' => $this->l('Default warehouse on new products'), + // // 'hint' => $this->l('Automatically set a default warehouse when new product is created'), + // // 'type' => 'select', + // // 'list' => $warehouse_list, + // // 'identifier' => 'id_warehouse' + // // ), + // // 'PS_PACK_STOCK_TYPE' => array( + // // 'title' => $this->l('Default pack stock management'), + // // 'type' => 'select', + // // 'list' =>array( + // // array( + // // 'pack_stock' => 0, + // // 'name' => $this->l('Decrement pack only.') + // // ), + // // array( + // // 'pack_stock' => 1, + // // 'name' => $this->l('Decrement products in pack only.') + // // ), + // // array( + // // 'pack_stock' => 2, + // // 'name' => $this->l('Decrement both.') + // // ), + // // ), + // // 'identifier' => 'pack_stock', + // // ), + // ), + // // 'bottom' => '', + // 'submit' => array('title' => $this->l('Save')) + // ), ); } diff --git a/modules/blockcart/ajax-cart.js b/modules/blockcart/ajax-cart.js index 0c25d3a45..e3e4ac26f 100644 --- a/modules/blockcart/ajax-cart.js +++ b/modules/blockcart/ajax-cart.js @@ -878,7 +878,7 @@ var ajaxCart = { content += ''; if ((parseInt(product.selling_preference_type) == SELLING_PREFERENCE_HOTEL_STANDALONE || parseInt(product.selling_preference_type) == SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE) - && (typeof(hotel_wise_data) != 'undefined' && hotel_wise_data.length) + && (typeof(hotel_wise_data) != 'undefined' && typeof(hotel_wise_data.hotel_name) != 'undefined') ) { content += '
' + hotel_wise_data.hotel_name + '
'; } 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 0c25d3a45..e3e4ac26f 100644 --- a/themes/hotel-reservation-theme/js/modules/blockcart/ajax-cart.js +++ b/themes/hotel-reservation-theme/js/modules/blockcart/ajax-cart.js @@ -878,7 +878,7 @@ var ajaxCart = { content += ''; if ((parseInt(product.selling_preference_type) == SELLING_PREFERENCE_HOTEL_STANDALONE || parseInt(product.selling_preference_type) == SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE) - && (typeof(hotel_wise_data) != 'undefined' && hotel_wise_data.length) + && (typeof(hotel_wise_data) != 'undefined' && typeof(hotel_wise_data.hotel_name) != 'undefined') ) { content += '
' + hotel_wise_data.hotel_name + '
'; } From a376efc10d5ae0a61504eebd43866b30a6095ba9 Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Fri, 27 Jun 2025 12:45:15 +0530 Subject: [PATCH 10/11] Updated: QloApps installation URL length 64 => 256 --- classes/shop/ShopUrl.php | 4 ++-- install/data/db_structure.sql | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/classes/shop/ShopUrl.php b/classes/shop/ShopUrl.php index 5e43b1aee..94d62f51f 100644 --- a/classes/shop/ShopUrl.php +++ b/classes/shop/ShopUrl.php @@ -49,8 +49,8 @@ class ShopUrlCore extends ObjectModel 'domain' => array('type' => self::TYPE_STRING, 'required' => true, 'size' => 255, 'validate' => 'isCleanHtml'), 'domain_ssl' => array('type' => self::TYPE_STRING, 'size' => 255, 'validate' => 'isCleanHtml'), 'id_shop' => array('type' => self::TYPE_INT, 'required' => true), - 'physical_uri' => array('type' => self::TYPE_STRING, 'size' => 64), - 'virtual_uri' => array('type' => self::TYPE_STRING, 'size' => 64), + 'physical_uri' => array('type' => self::TYPE_STRING, 'size' => 256), + 'virtual_uri' => array('type' => self::TYPE_STRING, 'size' => 256), ), ); diff --git a/install/data/db_structure.sql b/install/data/db_structure.sql index 0afb0273e..079d3e928 100644 --- a/install/data/db_structure.sql +++ b/install/data/db_structure.sql @@ -2175,8 +2175,8 @@ CREATE TABLE IF NOT EXISTS `PREFIX_shop_url` ( `id_shop` int(11) unsigned NOT NULL, `domain` varchar(150) NOT NULL, `domain_ssl` varchar(150) NOT NULL, - `physical_uri` varchar(64) NOT NULL, - `virtual_uri` varchar(64) NOT NULL, + `physical_uri` varchar(256) NOT NULL, + `virtual_uri` varchar(256) NOT NULL, `main` TINYINT(1) NOT NULL, `active` TINYINT(1) NOT NULL, PRIMARY KEY (`id_shop_url`), From dcb99c21464c918994205d0f4f0c2ed7dc915a5f Mon Sep 17 00:00:00 2001 From: Sumit Panwar Date: Fri, 27 Jun 2025 14:39:10 +0530 Subject: [PATCH 11/11] Fixed: Price issue with multiple autoadd services with a room --- .../classes/HotelRoomTypeFeaturePricing.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php b/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php index ca621a1fd..0e668ccbd 100644 --- a/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php +++ b/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php @@ -389,9 +389,10 @@ class HotelRoomTypeFeaturePricing extends ObjectModel 1, Product::PRICE_ADDITION_TYPE_WITH_ROOM )) { - $selectedServices = array_shift($roomServicesServices); - $totalPrice['total_price_tax_incl'] += $selectedServices['total_price_tax_incl']; - $totalPrice['total_price_tax_excl'] += $selectedServices['total_price_tax_excl']; + foreach($roomServicesServices as $selectedService) { + $totalPrice['total_price_tax_incl'] += $selectedService['total_price_tax_incl']; + $totalPrice['total_price_tax_excl'] += $selectedService['total_price_tax_excl']; + } } }