From 43cc7a8a1e66e30b71deaa7f5ec621d6dccddbeb Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Wed, 11 Sep 2024 13:10:25 +0530 Subject: [PATCH] update price calculation for service product --- .../classes/HotelRoomTypeFeaturePricing.php | 70 ++++++++++++------- .../classes/RoomTypeServiceProduct.php | 29 ++------ .../RoomTypeServiceProductCartDetail.php | 6 +- 3 files changed, 56 insertions(+), 49 deletions(-) diff --git a/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php b/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php index a3c9d09cb..af66bf054 100644 --- a/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php +++ b/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php @@ -718,32 +718,54 @@ class HotelRoomTypeFeaturePricing extends ObjectModel } } if ($with_auto_room_services) { - if ($servicesWithTax = RoomTypeServiceProduct::getAutoAddServices( - $id_product, - $date_from, - $date_to, - Product::PRICE_ADDITION_TYPE_WITH_ROOM, - true, - $id_cart, - $id_room, - $use_reduc - )) { - foreach($servicesWithTax as $service) { - $totalPrice['total_price_tax_incl'] += Tools::processPriceRounding($service['price']); + if ($id_cart) { + $objRoomTypeServiceProductCartDetail = new RoomTypeServiceProductCartDetail(); + if ($roomServicesServices = $objRoomTypeServiceProductCartDetail->getServiceProductsInCart( + $id_cart, + 0, + 0, + $id_product, + $date_from, + $date_to, + 0, + 0, + null, + null, + null, + null, + $id_room + )) { + $selectedServices = array_shift($roomServicesServices); } } - if ($servicesWithoutTax = RoomTypeServiceProduct::getAutoAddServices( - $id_product, - $date_from, - $date_to, - Product::PRICE_ADDITION_TYPE_WITH_ROOM, - false, - $id_cart, - $id_room, - $use_reduc - )) { - foreach($servicesWithoutTax as $service) { - $totalPrice['total_price_tax_excl'] += Tools::processPriceRounding($service['price']); + + if (isset($selectedServices)) { + $totalPrice['total_price_tax_incl'] += Tools::processPriceRounding($selectedServices['total_price_tax_incl']); + $totalPrice['total_price_tax_excl'] += Tools::processPriceRounding($selectedServices['total_price_tax_excl']); + } else { + if ($servicesWithTax = RoomTypeServiceProduct::getAutoAddServices( + $id_product, + $date_from, + $date_to, + Product::PRICE_ADDITION_TYPE_WITH_ROOM, + true, + $use_reduc + )) { + foreach($servicesWithTax as $service) { + $totalPrice['total_price_tax_incl'] += Tools::processPriceRounding($service['price']); + } + } + if ($servicesWithoutTax = RoomTypeServiceProduct::getAutoAddServices( + $id_product, + $date_from, + $date_to, + Product::PRICE_ADDITION_TYPE_WITH_ROOM, + false, + $use_reduc + )) { + foreach($servicesWithoutTax as $service) { + $totalPrice['total_price_tax_excl'] += Tools::processPriceRounding($service['price']); + } } } } diff --git a/modules/hotelreservationsystem/classes/RoomTypeServiceProduct.php b/modules/hotelreservationsystem/classes/RoomTypeServiceProduct.php index 0b327b14d..7c80b17e1 100644 --- a/modules/hotelreservationsystem/classes/RoomTypeServiceProduct.php +++ b/modules/hotelreservationsystem/classes/RoomTypeServiceProduct.php @@ -135,33 +135,14 @@ class RoomTypeServiceProduct extends ObjectModel return Db::getInstance()->getValue($sql); } - public static function getAutoAddServices($idProduct, - $dateFrom = null, - $dateTo = null, - $priceAdditionType = null, - $useTax = null, - $idCart = 0, - $idRoom = 0, - $use_reduc = 1 - ) { + public static function getAutoAddServices($idProduct, $dateFrom = null, $dateTo = null, $priceAdditionType = null, $useTax = null, $use_reduc = 1) + { if (Product::isBookingProduct($idProduct)) { $sql = 'SELECT p.`id_product` FROM `'._DB_PREFIX_.'htl_room_type_service_product` rsp - INNER JOIN `'._DB_PREFIX_.'product` p ON (rsp.`id_product` = p.`id_product` AND p.`auto_add_to_cart` = 1)'; - if ($idCart || ($dateFrom && $dateTo) || $idRoom) { - $sql .= ' INNER JOIN `'._DB_PREFIX_.'htl_room_type_service_product_cart_detail` spcd - ON (rsp.`id_product` = spcd.`id_product` AND spcd.`id_cart` = '.(int)$idCart.') - INNER JOIN `'._DB_PREFIX_.'htl_cart_booking_data` hcbd - ON (hcbd.`id` = spcd.`htl_cart_booking_id`)'; - } - $sql .= ' WHERE p.`active` = 1 AND `id_element` = '.(int)$idProduct.' AND `element_type` = '.self::WK_ELEMENT_TYPE_ROOM_TYPE; + INNER JOIN `'._DB_PREFIX_.'product` p ON (rsp.`id_product` = p.`id_product` AND p.`auto_add_to_cart` = 1) + WHERE p.`active` = 1 AND `id_element` = '.(int)$idProduct.' AND `element_type` = '.self::WK_ELEMENT_TYPE_ROOM_TYPE; if (!is_null($priceAdditionType)) { - $sql .= ' AND p.`price_addition_type` = '.(int)$priceAdditionType; - } - if ($dateFrom && $dateTo) { - $sql .= ' AND hcbd.`date_from` = \''.pSQL($dateFrom).'\' AND hcbd.`date_to` = \''.pSQL($dateTo).'\''; - } - if ($idRoom) { - $sql .= ' AND hcbd.`id_room` = '.(int)$idRoom; + $sql .= ' AND p.`price_addition_type` = '.$priceAdditionType; } if ($services = Db::getInstance()->executeS($sql)) { $objRoomTypeServiceProductPrice = new RoomTypeServiceProductPrice(); diff --git a/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php b/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php index 0690e7374..0267f2117 100644 --- a/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php +++ b/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php @@ -211,7 +211,8 @@ class RoomTypeServiceProductCartDetail extends ObjectModel $useTax = null, $autoAddToCart = 0, $id_address = null, - $priceAdditionType = null + $priceAdditionType = null, + $idRoom = 0 ) { if ($useTax === null) $useTax = Product::$_taxCalculationMethod == PS_TAX_EXC ? false : true; @@ -256,6 +257,9 @@ class RoomTypeServiceProductCartDetail extends ObjectModel if ($dateFrom && $dateTo) { $sql .= ' AND cbd.`date_from` = \''.pSQL($dateFrom).'\' AND cbd.`date_to` = \''.pSQL($dateTo).'\''; } + if ($idRoom) { + $sql .= ' AND cbd.`id_room`='.(int) $idRoom; + } if ($htlCartBookingId) { $sql .= ' AND cbd.`id`='.(int) $htlCartBookingId; }