From bdb75b6e4a116b3526ca60dd6ec3c84dccb0197a Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Mon, 11 Mar 2024 10:56:05 +0530 Subject: [PATCH 1/6] Fixed service product quantity was added incorrectly in cart --- .../RoomTypeServiceProductCartDetail.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php b/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php index 94c40c1ec..4632502a0 100644 --- a/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php +++ b/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php @@ -64,14 +64,13 @@ class RoomTypeServiceProductCartDetail extends ObjectModel } if ($updateQty = $quantity - $objRoomTypeServiceProductCartDetail->quantity) { + $way = $updateQty > 0 ? 'up' : 'down'; + $objRoomTypeServiceProductCartDetail->quantity += $updateQty; if (Product::getProductPriceCalculation($idProduct) == Product::PRICE_CALCULATION_METHOD_PER_DAY) { $objHotelCartBookingData = new HotelCartBookingData($idHtlCartData); $numdays = HotelHelper::getNumberOfDays($objHotelCartBookingData->date_from, $objHotelCartBookingData->date_to); $updateQty *= $numdays; - } - $way = $updateQty > 0 ? 'up' : 'down'; - $objRoomTypeServiceProductCartDetail->quantity = $quantity; if ($objRoomTypeServiceProductCartDetail->save()) { $objCart = new Cart($idCart); return $objCart->updateQty((int)abs($updateQty), $idProduct, null, false, $way); @@ -86,16 +85,22 @@ class RoomTypeServiceProductCartDetail extends ObjectModel public function removeServiceProductByIdHtlCartBooking($htlCartBookingId) { if ($stadardProductsData = Db::getInstance()->executeS( - 'SELECT * FROM `'._DB_PREFIX_.'htl_room_type_service_product_cart_detail` - WHERE `htl_cart_booking_id` = '.(int)$htlCartBookingId + 'SELECT * FROM `' . _DB_PREFIX_ . 'htl_room_type_service_product_cart_detail` + WHERE `htl_cart_booking_id` = ' . (int)$htlCartBookingId )) { foreach ($stadardProductsData as $product) { if (Validate::isLoadedObject( $objRoomTypeServiceProductCartDetail = new RoomTypeServiceProductCartDetail($product['id_room_type_service_product_cart_detail']) )) { + $updateQty = $product['quantity']; + if (Product::getProductPriceCalculation($product['id_product']) == Product::PRICE_CALCULATION_METHOD_PER_DAY) { + $objHotelCartBookingData = new HotelCartBookingData($idHtlCartData); + $numdays = HotelHelper::getNumberOfDays($objHotelCartBookingData->date_from, $objHotelCartBookingData->date_to); + $updateQty *= $numdays; + } if ($objRoomTypeServiceProductCartDetail->delete()) { $objCart = new Cart($product['id_cart']); - $objCart->updateQty((int)($product['quantity']), $product['id_product'], null, false, 'down'); + $objCart->updateQty((int)($updateQty), $product['id_product'], null, false, 'down'); } } } From acea7927233403b5f07e70d54a945be7bc0f31f7 Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Wed, 6 Mar 2024 17:56:18 +0530 Subject: [PATCH 2/6] Fixed: Price and quantity calculate for services having per night price calculation type --- controllers/admin/AdminOrdersController.php | 110 +++++++++++--------- 1 file changed, 62 insertions(+), 48 deletions(-) diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index eca7cbc80..762fea667 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -5073,57 +5073,71 @@ class AdminOrdersControllerCore extends AdminController $roomInfo = $objHotelRoomType->getRoomTypeInfoByIdProduct($objHotelBookingDetail->id_product); $totalPriceChangeTaxExcl = 0; $totalPriceChangeTaxIncl = 0; + $unitPriceTaxIncl = 0; + $unitPriceTaxExcl = 0; foreach ($productList as &$product) { - $totalPriceChangeTaxExcl += $totalPriceTaxExcl = $objRoomTypeServiceProductPrice->getServicePrice( - (int)$product['id_product'], - $roomInfo['id'], - $product['cart_quantity'], - $objHotelBookingDetail->date_from, - $objHotelBookingDetail->date_to, - false - ); - $totalPriceChangeTaxIncl += $totalPriceTaxIncl = $objRoomTypeServiceProductPrice->getServicePrice( - (int)$product['id_product'], - $roomInfo['id'], - $product['cart_quantity'], - $objHotelBookingDetail->date_from, - $objHotelBookingDetail->date_to, - true - ); - $unitPriceTaxExcl = $objRoomTypeServiceProductPrice->getServicePrice( - (int)$product['id_product'], - $roomInfo['id'], - 1, - $objHotelBookingDetail->date_from, - $objHotelBookingDetail->date_to, - false - ); - $unitPriceTaxIncl = $objRoomTypeServiceProductPrice->getServicePrice( - (int)$product['id_product'], - $roomInfo['id'], - 1, - $objHotelBookingDetail->date_from, - $objHotelBookingDetail->date_to, - true - ); - switch (Configuration::get('PS_ROUND_TYPE')) { - case Order::ROUND_TOTAL: - $product['total'] = $totalPriceTaxExcl; - $product['total_wt'] = $totalPriceTaxIncl; - break; - case Order::ROUND_LINE: - $product['total'] = Tools::ps_round($totalPriceTaxExcl, _PS_PRICE_COMPUTE_PRECISION_); - $product['total_wt'] = Tools::ps_round($totalPriceTaxIncl, _PS_PRICE_COMPUTE_PRECISION_); - break; + // This is used to get the actual quanity of the service as it is calculated incorrectly if the service is per night + if ($id_room_type_service_product_cart_detail = $objRoomTypeServiceProductCartDetail->alreadyExists( + $service['id'], + $cart->id, + $roomHtlCartInfo['id']) + ) { + $objRoomTypeServiceProductCartDetail = new RoomTypeServiceProductCartDetail((int) $id_room_type_service_product_cart_detail); + $product['cart_quantity'] = $objRoomTypeServiceProductCartDetail->quantity; + $totalPriceChangeTaxExcl += $totalPriceTaxExcl = $objRoomTypeServiceProductPrice->getServicePrice( + (int)$product['id_product'], + $roomInfo['id'], + $product['cart_quantity'], + $objHotelBookingDetail->date_from, + $objHotelBookingDetail->date_to, + false + ); + $totalPriceChangeTaxIncl += $totalPriceTaxIncl = $objRoomTypeServiceProductPrice->getServicePrice( + (int)$product['id_product'], + $roomInfo['id'], + $product['cart_quantity'], + $objHotelBookingDetail->date_from, + $objHotelBookingDetail->date_to, + true + ); + $numDays = 1; + if (Product::getProductPriceCalculation($product['id_product']) == Product::PRICE_CALCULATION_METHOD_PER_DAY) { + $numDays = HotelHelper::getNumberOfDays($objHotelBookingDetail->date_from, $objHotelBookingDetail->date_to); + } - case Order::ROUND_ITEM: - default: - $product['total'] = Tools::ps_round($totalPriceTaxExcl, _PS_PRICE_COMPUTE_PRECISION_) * (int)$product['cart_quantity']; - $product['total_wt'] = Tools::ps_round($totalPriceTaxIncl, _PS_PRICE_COMPUTE_PRECISION_) * (int)$product['cart_quantity']; - break; + $unitPriceTaxExcl = $objRoomTypeServiceProductPrice->getServicePrice( + (int)$product['id_product'], + $roomInfo['id'], + 1, + $objHotelBookingDetail->date_from, + $objHotelBookingDetail->date_to, + false + )/ $numDays; + $unitPriceTaxIncl = $objRoomTypeServiceProductPrice->getServicePrice( + (int)$product['id_product'], + $roomInfo['id'], + 1, + $objHotelBookingDetail->date_from, + $objHotelBookingDetail->date_to, + true + )/ $numDays; + switch (Configuration::get('PS_ROUND_TYPE')) { + case Order::ROUND_TOTAL: + $product['total'] = $totalPriceTaxExcl; + $product['total_wt'] = $totalPriceTaxIncl; + break; + case Order::ROUND_LINE: + $product['total'] = Tools::ps_round($totalPriceTaxExcl, _PS_PRICE_COMPUTE_PRECISION_); + $product['total_wt'] = Tools::ps_round($totalPriceTaxIncl, _PS_PRICE_COMPUTE_PRECISION_); + break; + + case Order::ROUND_ITEM: + default: + $product['total'] = Tools::ps_round($totalPriceTaxExcl, _PS_PRICE_COMPUTE_PRECISION_); + $product['total_wt'] = Tools::ps_round($totalPriceTaxIncl, _PS_PRICE_COMPUTE_PRECISION_); + break; + } } - - } $order_detail = new OrderDetail(); From 1db2d822bd15e2045e418286896a70eea09dc772 Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Fri, 8 Mar 2024 16:52:54 +0530 Subject: [PATCH 3/6] Fixed price of service products with price addition type per day on order dates update --- controllers/admin/AdminOrdersController.php | 144 +++++++++++++++----- 1 file changed, 110 insertions(+), 34 deletions(-) diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index 762fea667..0db899857 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -3655,6 +3655,20 @@ class AdminOrdersControllerCore extends AdminController // get extra demands of the room before changing in the booking table $objBookingDemand = new HotelBookingDemands(); + $objRoomTypeServiceProductOrderDetail = new RoomTypeServiceProductOrderDetail(); + $orderServiceProducts = $objRoomTypeServiceProductOrderDetail->getroomTypeServiceProducts( + $id_order, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + null, + null + ); + $extraDemands = $objBookingDemand->getRoomTypeBookingExtraDemands( $id_order, 0, @@ -3718,6 +3732,57 @@ class AdminOrdersControllerCore extends AdminController // change order total save $objOrder->save(); } + + if (isset($orderServiceProducts) + && is_array($orderServiceProducts) + && count($orderServiceProducts) + ) { + $objRoomTypeServiceProductPrice = new RoomTypeServiceProductPrice(); + foreach ($orderServiceProducts as $orderServiceProduct) { + if (isset($orderServiceProduct['additional_services']) + && is_array($orderServiceProduct['additional_services']) + && count($orderServiceProduct['additional_services']) + ) { + foreach ($orderServiceProduct['additional_services'] as $serviceProduct) { + if (Product::getProductPriceCalculation($serviceProduct['id_product']) == Product::PRICE_CALCULATION_METHOD_PER_DAY) { + $numDays = HotelHelper::getNumberOfDays($new_date_from, $new_date_to); + $objRoomTypeServiceProductOrderDetail = new RoomTypeServiceProductOrderDetail((int) $serviceProduct['id_room_type_service_product_order_detail']); + $totalPriceTaxExcl = $objRoomTypeServiceProductPrice->getServicePrice( + (int) $serviceProduct['id_product'], + $orderServiceProduct['id_room'], + $objRoomTypeServiceProductOrderDetail->quantity, + $new_date_from, + $new_date_to, + false + ); + $totalPriceTaxIncl = $objRoomTypeServiceProductPrice->getServicePrice( + (int) $serviceProduct['id_product'], + $orderServiceProduct['id_room'], + $objRoomTypeServiceProductOrderDetail->quantity, + $new_date_from, + $new_date_to, + true + ); + $unitPriceTaxExcl = $totalPriceTaxExcl / ($numDays * $objRoomTypeServiceProductOrderDetail->quantity); + $unitPriceTaxIncl = $totalPriceTaxIncl / ($numDays * $objRoomTypeServiceProductOrderDetail->quantity); + $objRoomTypeServiceProductOrderDetail->unit_price_tax_excl = $unitPriceTaxExcl; + $objRoomTypeServiceProductOrderDetail->unit_price_tax_incl = $unitPriceTaxIncl; + $objRoomTypeServiceProductOrderDetail->total_price_tax_excl = $totalPriceTaxExcl; + $objRoomTypeServiceProductOrderDetail->total_price_tax_incl = $totalPriceTaxIncl; + $objRoomTypeServiceProductOrderDetail->save(); + + $objOrderDetail = new OrderDetail((int) $serviceProduct['id_order_detail']); + $objOrderDetail->unit_price_tax_excl = $unitPriceTaxExcl; + $objOrderDetail->unit_price_tax_incl = $unitPriceTaxIncl; + $objOrderDetail->total_price_tax_excl = $totalPriceTaxExcl; + $objOrderDetail->total_price_tax_incl = $totalPriceTaxIncl; + $objOrderDetail->save(); + + } + } + } + } + } } if (is_array(Tools::getValue('product_quantity'))) { @@ -4888,46 +4953,57 @@ class AdminOrdersControllerCore extends AdminController $quantity = Tools::getValue('qty'); if (Validate::isLoadedObject($objRoomTypeServiceProductOrderDetail = new RoomTypeServiceProductOrderDetail($id_room_type_service_product_order_detail))) { - $objOrderDetail = new OrderDetail($objRoomTypeServiceProductOrderDetail->id_order_detail); - if ($objOrderDetail->product_allow_multiple_quantity) { - if (!Validate::isUnsignedInt($quantity)) { - $response['hasError'] = true; - $response['errors'] = $this->l('Invalid quantity provided'); - } else { - $objRoomTypeServiceProductOrderDetail->quantity = $quantity; - $oldPriceTaxExcl = $objRoomTypeServiceProductOrderDetail->total_price_tax_excl; - $oldPriceTaxIncl = $objRoomTypeServiceProductOrderDetail->total_price_tax_incl; - $objRoomTypeServiceProductOrderDetail->total_price_tax_excl = $objRoomTypeServiceProductOrderDetail->unit_price_tax_excl * $quantity; - $objRoomTypeServiceProductOrderDetail->total_price_tax_incl = $objRoomTypeServiceProductOrderDetail->unit_price_tax_incl * $quantity; - $res = true; - if ($res &= $objRoomTypeServiceProductOrderDetail->save()) { - $order = new Order($objRoomTypeServiceProductOrderDetail->id_order); - $priceDiffTaxExcl = $objRoomTypeServiceProductOrderDetail->total_price_tax_excl - $oldPriceTaxExcl; - $priceDiffTaxIncl = $objRoomTypeServiceProductOrderDetail->total_price_tax_incl - $oldPriceTaxIncl; - - $objOrderDetail->product_quantity = $quantity; - $objOrderDetail->total_price_tax_excl += $priceDiffTaxExcl; - $objOrderDetail->total_price_tax_incl += $priceDiffTaxIncl; - - $res &= $objOrderDetail->updateTaxAmount($order); - - $res &= $objOrderDetail->update(); - - $order->total_paid_tax_excl += $priceDiffTaxExcl; - $order->total_paid_tax_incl += $priceDiffTaxIncl; - $order->total_paid += $priceDiffTaxIncl; - - $res &= $order->update(); - } + if (Validate::isLoadedObject($objHotelBookingDetail = new HotelBookingDetail((int) $objRoomTypeServiceProductOrderDetail->id_htl_booking_detail))) { + $numDays = 1; + if (Product::getProductPriceCalculation($objRoomTypeServiceProductOrderDetail->id_product) == Product::PRICE_CALCULATION_METHOD_PER_DAY) { + $numDays = HotelHelper::getNumberOfDays($objHotelBookingDetail->date_from, $objHotelBookingDetail->date_to); } - if (!$res) { + + $objOrderDetail = new OrderDetail($objRoomTypeServiceProductOrderDetail->id_order_detail); + if ($objOrderDetail->product_allow_multiple_quantity) { + if (!Validate::isUnsignedInt($quantity)) { + $response['hasError'] = true; + $response['errors'] = $this->l('Invalid quantity provided'); + } else { + $objRoomTypeServiceProductOrderDetail->quantity = $quantity; + $oldPriceTaxExcl = $objRoomTypeServiceProductOrderDetail->total_price_tax_excl; + $oldPriceTaxIncl = $objRoomTypeServiceProductOrderDetail->total_price_tax_incl; + $objRoomTypeServiceProductOrderDetail->total_price_tax_excl = $objRoomTypeServiceProductOrderDetail->unit_price_tax_excl * $quantity * $numDays; + $objRoomTypeServiceProductOrderDetail->total_price_tax_incl = $objRoomTypeServiceProductOrderDetail->unit_price_tax_incl * $quantity * $numDays; + $res = true; + if ($res &= $objRoomTypeServiceProductOrderDetail->save()) { + $order = new Order($objRoomTypeServiceProductOrderDetail->id_order); + $priceDiffTaxExcl = $objRoomTypeServiceProductOrderDetail->total_price_tax_excl - $oldPriceTaxExcl; + $priceDiffTaxIncl = $objRoomTypeServiceProductOrderDetail->total_price_tax_incl - $oldPriceTaxIncl; + + $objOrderDetail->product_quantity = $quantity; + $objOrderDetail->total_price_tax_excl += $priceDiffTaxExcl; + $objOrderDetail->total_price_tax_incl += $priceDiffTaxIncl; + + $res &= $objOrderDetail->updateTaxAmount($order); + + $res &= $objOrderDetail->update(); + + $order->total_paid_tax_excl += $priceDiffTaxExcl; + $order->total_paid_tax_incl += $priceDiffTaxIncl; + $order->total_paid += $priceDiffTaxIncl; + + $res &= $order->update(); + } + } + if (!$res) { + $response['hasError'] = true; + $response['errors'] = $this->l('Error while updating service, please try refresing the page'); + } + } else { $response['hasError'] = true; - $response['errors'] = $this->l('Error while updating service, please try refresing the page'); + $response['errors'] = $this->l('cannot order multiple quanitity for this service'); } } else { $response['hasError'] = true; - $response['errors'] = $this->l('cannot order multiple quanitity for this service'); + $response['errors'] = $this->l('Additional service not found'); } + $objHotelBookingDetail = new HotelBookingDetail($objRoomTypeServiceProductOrderDetail->id_htl_booking_detail); $response['service_panel']= $servicesBlock = $this->processRenderServicesPanel( $objOrderDetail->id_order, From 4ec665427d01a25ec10df416aeac0e393a2ef331 Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Tue, 12 Mar 2024 18:53:42 +0530 Subject: [PATCH 4/6] Fixed: tax on the services on order date range update --- controllers/admin/AdminOrdersController.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index 0db899857..1a0d4fa10 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -3737,6 +3737,7 @@ class AdminOrdersControllerCore extends AdminController && is_array($orderServiceProducts) && count($orderServiceProducts) ) { + $objOrder = new Order((int) $id_order); $objRoomTypeServiceProductPrice = new RoomTypeServiceProductPrice(); foreach ($orderServiceProducts as $orderServiceProduct) { if (isset($orderServiceProduct['additional_services']) @@ -3765,6 +3766,16 @@ class AdminOrdersControllerCore extends AdminController ); $unitPriceTaxExcl = $totalPriceTaxExcl / ($numDays * $objRoomTypeServiceProductOrderDetail->quantity); $unitPriceTaxIncl = $totalPriceTaxIncl / ($numDays * $objRoomTypeServiceProductOrderDetail->quantity); + + $objOrder->total_paid_tax_excl -= $objRoomTypeServiceProductOrderDetail->total_price_tax_excl; + $objOrder->total_paid_tax_incl -= $objRoomTypeServiceProductOrderDetail->total_price_tax_incl; + $objOrder->total_paid -= $objRoomTypeServiceProductOrderDetail->total_price_tax_incl; + + // change order total + $objOrder->total_paid_tax_excl += $totalPriceTaxExcl; + $objOrder->total_paid_tax_incl += $totalPriceTaxIncl; + $objOrder->total_paid += $totalPriceTaxIncl; + $objRoomTypeServiceProductOrderDetail->unit_price_tax_excl = $unitPriceTaxExcl; $objRoomTypeServiceProductOrderDetail->unit_price_tax_incl = $unitPriceTaxIncl; $objRoomTypeServiceProductOrderDetail->total_price_tax_excl = $totalPriceTaxExcl; @@ -3777,11 +3788,12 @@ class AdminOrdersControllerCore extends AdminController $objOrderDetail->total_price_tax_excl = $totalPriceTaxExcl; $objOrderDetail->total_price_tax_incl = $totalPriceTaxIncl; $objOrderDetail->save(); - } } } } + + $objOrder->save(); } } From f9e331838c55bdb08a46a29fe3f6446017db3f85 Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Fri, 15 Mar 2024 09:57:05 +0530 Subject: [PATCH 5/6] Fixed the price calculation for same service on multiple rooms in order on order update --- controllers/admin/AdminOrdersController.php | 43 ++++++++------------- 1 file changed, 16 insertions(+), 27 deletions(-) diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index 1a0d4fa10..12850c83f 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -3661,9 +3661,9 @@ class AdminOrdersControllerCore extends AdminController 0, 0, 0, - 0, - 0, - 0, + $old_date_from, + $old_date_to, + $id_room, 0, null, null @@ -3748,24 +3748,11 @@ class AdminOrdersControllerCore extends AdminController if (Product::getProductPriceCalculation($serviceProduct['id_product']) == Product::PRICE_CALCULATION_METHOD_PER_DAY) { $numDays = HotelHelper::getNumberOfDays($new_date_from, $new_date_to); $objRoomTypeServiceProductOrderDetail = new RoomTypeServiceProductOrderDetail((int) $serviceProduct['id_room_type_service_product_order_detail']); - $totalPriceTaxExcl = $objRoomTypeServiceProductPrice->getServicePrice( - (int) $serviceProduct['id_product'], - $orderServiceProduct['id_room'], - $objRoomTypeServiceProductOrderDetail->quantity, - $new_date_from, - $new_date_to, - false - ); - $totalPriceTaxIncl = $objRoomTypeServiceProductPrice->getServicePrice( - (int) $serviceProduct['id_product'], - $orderServiceProduct['id_room'], - $objRoomTypeServiceProductOrderDetail->quantity, - $new_date_from, - $new_date_to, - true - ); - $unitPriceTaxExcl = $totalPriceTaxExcl / ($numDays * $objRoomTypeServiceProductOrderDetail->quantity); - $unitPriceTaxIncl = $totalPriceTaxIncl / ($numDays * $objRoomTypeServiceProductOrderDetail->quantity); + $unitPriceTaxExcl = $objRoomTypeServiceProductOrderDetail->unit_price_tax_excl; + $unitPriceTaxIncl = $objRoomTypeServiceProductOrderDetail->unit_price_tax_incl; + + $totalPriceTaxExcl = $numDays * $objRoomTypeServiceProductOrderDetail->quantity * $unitPriceTaxExcl; $unitPriceTaxIncl = $objRoomTypeServiceProductOrderDetail->unit_price_tax_incl; + $totalPriceTaxIncl = $numDays * $objRoomTypeServiceProductOrderDetail->quantity * $unitPriceTaxIncl; $objOrder->total_paid_tax_excl -= $objRoomTypeServiceProductOrderDetail->total_price_tax_excl; $objOrder->total_paid_tax_incl -= $objRoomTypeServiceProductOrderDetail->total_price_tax_incl; @@ -3776,18 +3763,20 @@ class AdminOrdersControllerCore extends AdminController $objOrder->total_paid_tax_incl += $totalPriceTaxIncl; $objOrder->total_paid += $totalPriceTaxIncl; + $objOrderDetail = new OrderDetail((int) $serviceProduct['id_order_detail']); + $objOrderDetail->total_price_tax_excl -= $objRoomTypeServiceProductOrderDetail->total_price_tax_excl; + $objOrderDetail->total_price_tax_incl -= $objRoomTypeServiceProductOrderDetail->total_price_tax_incl; + + $objOrderDetail->total_price_tax_excl += $totalPriceTaxExcl; + $objOrderDetail->total_price_tax_incl += $totalPriceTaxIncl; + $objOrderDetail->save(); + $objRoomTypeServiceProductOrderDetail->unit_price_tax_excl = $unitPriceTaxExcl; $objRoomTypeServiceProductOrderDetail->unit_price_tax_incl = $unitPriceTaxIncl; $objRoomTypeServiceProductOrderDetail->total_price_tax_excl = $totalPriceTaxExcl; $objRoomTypeServiceProductOrderDetail->total_price_tax_incl = $totalPriceTaxIncl; $objRoomTypeServiceProductOrderDetail->save(); - $objOrderDetail = new OrderDetail((int) $serviceProduct['id_order_detail']); - $objOrderDetail->unit_price_tax_excl = $unitPriceTaxExcl; - $objOrderDetail->unit_price_tax_incl = $unitPriceTaxIncl; - $objOrderDetail->total_price_tax_excl = $totalPriceTaxExcl; - $objOrderDetail->total_price_tax_incl = $totalPriceTaxIncl; - $objOrderDetail->save(); } } } From 2d87f66107dbe05355bcad587da84d9f0cc5accb Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Sun, 17 Mar 2024 13:53:34 +0530 Subject: [PATCH 6/6] fix service product quantity in order_detail table --- controllers/admin/AdminOrdersController.php | 36 ++++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index 12850c83f..5d24272e9 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -3738,7 +3738,6 @@ class AdminOrdersControllerCore extends AdminController && count($orderServiceProducts) ) { $objOrder = new Order((int) $id_order); - $objRoomTypeServiceProductPrice = new RoomTypeServiceProductPrice(); foreach ($orderServiceProducts as $orderServiceProduct) { if (isset($orderServiceProduct['additional_services']) && is_array($orderServiceProduct['additional_services']) @@ -3746,35 +3745,39 @@ class AdminOrdersControllerCore extends AdminController ) { foreach ($orderServiceProduct['additional_services'] as $serviceProduct) { if (Product::getProductPriceCalculation($serviceProduct['id_product']) == Product::PRICE_CALCULATION_METHOD_PER_DAY) { - $numDays = HotelHelper::getNumberOfDays($new_date_from, $new_date_to); + $newNumDays = HotelHelper::getNumberOfDays($new_date_from, $new_date_to); $objRoomTypeServiceProductOrderDetail = new RoomTypeServiceProductOrderDetail((int) $serviceProduct['id_room_type_service_product_order_detail']); $unitPriceTaxExcl = $objRoomTypeServiceProductOrderDetail->unit_price_tax_excl; $unitPriceTaxIncl = $objRoomTypeServiceProductOrderDetail->unit_price_tax_incl; - $totalPriceTaxExcl = $numDays * $objRoomTypeServiceProductOrderDetail->quantity * $unitPriceTaxExcl; $unitPriceTaxIncl = $objRoomTypeServiceProductOrderDetail->unit_price_tax_incl; - $totalPriceTaxIncl = $numDays * $objRoomTypeServiceProductOrderDetail->quantity * $unitPriceTaxIncl; + $newTotalPriceTaxExcl = $newNumDays * $objRoomTypeServiceProductOrderDetail->quantity * $unitPriceTaxExcl; $unitPriceTaxIncl = $objRoomTypeServiceProductOrderDetail->unit_price_tax_incl; + $newTotalPriceTaxIncl = $newNumDays * $objRoomTypeServiceProductOrderDetail->quantity * $unitPriceTaxIncl; $objOrder->total_paid_tax_excl -= $objRoomTypeServiceProductOrderDetail->total_price_tax_excl; $objOrder->total_paid_tax_incl -= $objRoomTypeServiceProductOrderDetail->total_price_tax_incl; $objOrder->total_paid -= $objRoomTypeServiceProductOrderDetail->total_price_tax_incl; // change order total - $objOrder->total_paid_tax_excl += $totalPriceTaxExcl; - $objOrder->total_paid_tax_incl += $totalPriceTaxIncl; - $objOrder->total_paid += $totalPriceTaxIncl; + $objOrder->total_paid_tax_excl += $newTotalPriceTaxExcl; + $objOrder->total_paid_tax_incl += $newTotalPriceTaxIncl; + $objOrder->total_paid += $newTotalPriceTaxIncl; $objOrderDetail = new OrderDetail((int) $serviceProduct['id_order_detail']); $objOrderDetail->total_price_tax_excl -= $objRoomTypeServiceProductOrderDetail->total_price_tax_excl; $objOrderDetail->total_price_tax_incl -= $objRoomTypeServiceProductOrderDetail->total_price_tax_incl; + $objOrderDetail->total_price_tax_excl += $newTotalPriceTaxExcl; + $objOrderDetail->total_price_tax_incl += $newTotalPriceTaxIncl; - $objOrderDetail->total_price_tax_excl += $totalPriceTaxExcl; - $objOrderDetail->total_price_tax_incl += $totalPriceTaxIncl; + $oldNumDays = HotelHelper::getNumberOfDays($old_date_from, $old_date_to); + $oldProductQuantity = $objRoomTypeServiceProductOrderDetail->quantity * $oldNumDays; + $newProductQuantity = $objRoomTypeServiceProductOrderDetail->quantity * $newNumDays; + $objOrderDetail->product_quantity += ($newProductQuantity - $oldProductQuantity); $objOrderDetail->save(); $objRoomTypeServiceProductOrderDetail->unit_price_tax_excl = $unitPriceTaxExcl; $objRoomTypeServiceProductOrderDetail->unit_price_tax_incl = $unitPriceTaxIncl; - $objRoomTypeServiceProductOrderDetail->total_price_tax_excl = $totalPriceTaxExcl; - $objRoomTypeServiceProductOrderDetail->total_price_tax_incl = $totalPriceTaxIncl; + $objRoomTypeServiceProductOrderDetail->total_price_tax_excl = $newTotalPriceTaxExcl; + $objRoomTypeServiceProductOrderDetail->total_price_tax_incl = $newTotalPriceTaxIncl; $objRoomTypeServiceProductOrderDetail->save(); } @@ -4966,6 +4969,7 @@ class AdminOrdersControllerCore extends AdminController $response['hasError'] = true; $response['errors'] = $this->l('Invalid quantity provided'); } else { + $oldQuantity = $objRoomTypeServiceProductOrderDetail->quantity; $objRoomTypeServiceProductOrderDetail->quantity = $quantity; $oldPriceTaxExcl = $objRoomTypeServiceProductOrderDetail->total_price_tax_excl; $oldPriceTaxIncl = $objRoomTypeServiceProductOrderDetail->total_price_tax_incl; @@ -4977,7 +4981,7 @@ class AdminOrdersControllerCore extends AdminController $priceDiffTaxExcl = $objRoomTypeServiceProductOrderDetail->total_price_tax_excl - $oldPriceTaxExcl; $priceDiffTaxIncl = $objRoomTypeServiceProductOrderDetail->total_price_tax_incl - $oldPriceTaxIncl; - $objOrderDetail->product_quantity = $quantity; + $objOrderDetail->product_quantity += (($quantity - $oldQuantity) * $numDays); $objOrderDetail->total_price_tax_excl += $priceDiffTaxExcl; $objOrderDetail->total_price_tax_incl += $priceDiffTaxIncl; @@ -5160,11 +5164,10 @@ class AdminOrdersControllerCore extends AdminController $roomHtlCartInfo['id']) ) { $objRoomTypeServiceProductCartDetail = new RoomTypeServiceProductCartDetail((int) $id_room_type_service_product_cart_detail); - $product['cart_quantity'] = $objRoomTypeServiceProductCartDetail->quantity; $totalPriceChangeTaxExcl += $totalPriceTaxExcl = $objRoomTypeServiceProductPrice->getServicePrice( (int)$product['id_product'], $roomInfo['id'], - $product['cart_quantity'], + $objRoomTypeServiceProductCartDetail->quantity, $objHotelBookingDetail->date_from, $objHotelBookingDetail->date_to, false @@ -5172,7 +5175,7 @@ class AdminOrdersControllerCore extends AdminController $totalPriceChangeTaxIncl += $totalPriceTaxIncl = $objRoomTypeServiceProductPrice->getServicePrice( (int)$product['id_product'], $roomInfo['id'], - $product['cart_quantity'], + $objRoomTypeServiceProductCartDetail->quantity, $objHotelBookingDetail->date_from, $objHotelBookingDetail->date_to, true @@ -5181,6 +5184,7 @@ class AdminOrdersControllerCore extends AdminController if (Product::getProductPriceCalculation($product['id_product']) == Product::PRICE_CALCULATION_METHOD_PER_DAY) { $numDays = HotelHelper::getNumberOfDays($objHotelBookingDetail->date_from, $objHotelBookingDetail->date_to); } + $product['cart_quantity'] = $objRoomTypeServiceProductCartDetail->quantity * $numDays; $unitPriceTaxExcl = $objRoomTypeServiceProductPrice->getServicePrice( (int)$product['id_product'], @@ -5231,7 +5235,7 @@ class AdminOrdersControllerCore extends AdminController $objRoomTypeServiceProductOrderDetail->total_price_tax_excl = $totalPriceTaxExcl; $objRoomTypeServiceProductOrderDetail->total_price_tax_incl = $totalPriceTaxIncl; $objRoomTypeServiceProductOrderDetail->name = $product['name']; - $objRoomTypeServiceProductOrderDetail->quantity = $product['cart_quantity']; + $objRoomTypeServiceProductOrderDetail->quantity = $objRoomTypeServiceProductCartDetail->quantity; $objRoomTypeServiceProductOrderDetail->save(); // update totals amount of order