diff --git a/classes/order/Order.php b/classes/order/Order.php index fcb958174..656bce9cc 100644 --- a/classes/order/Order.php +++ b/classes/order/Order.php @@ -2527,11 +2527,6 @@ class OrderCore extends ObjectModel $id_order_detail = $order_detail['id_order_detail']; $id_order_slip = $order_detail['id_order_slip'] ?? 0; // Only in case of order slip - $taxesList = OrderDetail::getTaxListStatic($id_order_detail); - if (!$taxesList) { - continue; - } - $tax_calculator = OrderDetail::getTaxCalculatorStatic($id_order_detail); $quantity = $order_detail['product_quantity']; @@ -2569,18 +2564,30 @@ class OrderCore extends ObjectModel // Note: Only calculate in case of Order Invoice if (!$id_order_slip) { + $taxesList = OrderDetail::getTaxListStatic($id_order_detail); + if (!$taxesList) { + continue; + } + if (!$order_detail['is_booking_product']) { $objServiceProductOrderDetail = new ServiceProductOrderDetail(); if ($serviceProductDetail = $objServiceProductOrderDetail->getServiceProductsInOrder( $order_detail['id_order'], $id_order_detail )) { - $totals = array_reduce($serviceProductDetail, function ($carry, $item) { + $totals = array_reduce($serviceProductDetail, function ($carry, $item) use ($order_detail) { + $objHotelBookingDetail = new HotelBookingDetail((int) $item['id_htl_booking_detail']); + if ((Product::PRICE_CALCULATION_METHOD_PER_DAY == $order_detail['product_price_calculation_method']) + && (!$numDays = HotelHelper::getNumberOfDays($objHotelBookingDetail->date_from, $objHotelBookingDetail->date_to)) + ) { + $numDays = 1; + } + if (!empty($item['id_tax_rules_group'])) { $qty = isset($item['quantity']) ? $item['quantity'] : 0; $price = isset($item['total_price_tax_excl']) ? $item['total_price_tax_excl'] : 0; - $carry['quantity'] += $qty; + $carry['quantity'] += ($qty * $numDays); $carry['total_price_tax_excl'] += $price; } return $carry; @@ -2625,6 +2632,12 @@ class OrderCore extends ObjectModel // We are getting auto added service for specific room.There will be only on htl_booking_detail but can have multiple auto added service with room. // Note: All the auto added service with room have same id_tax_rule group $autoAddedServiceData = array_shift($autoAddedServiceData); + $numDays = 1; + if ((Product::PRICE_CALCULATION_METHOD_PER_DAY == $order_detail['product_price_calculation_method']) + && (!$numDays = HotelHelper::getNumberOfDays($autoAddedServiceData['date_from'], $autoAddedServiceData['date_to'])) + ) { + $numDays = 1; + } $autoAddedServices = $autoAddedServiceData['additional_services']; // Calculate total quantity of auto-added services @@ -2633,6 +2646,8 @@ class OrderCore extends ObjectModel return $quantity + $qty; }, 0); + $totalAutoAddedQty = $totalAutoAddedQty * $numDays; + $firstAutoAddedService = array_shift($autoAddedServices); $idTaxRuleGroup = $firstAutoAddedService['id_tax_rules_group']; diff --git a/classes/order/OrderDetail.php b/classes/order/OrderDetail.php index f93010c04..db3859367 100644 --- a/classes/order/OrderDetail.php +++ b/classes/order/OrderDetail.php @@ -450,6 +450,12 @@ class OrderDetailCore extends ObjectModel $taxGroupInfo['id_room_type'], )) { $serviceProductData = array_shift($serviceProductData); + $numDays = 1; + if ((Product::PRICE_CALCULATION_METHOD_PER_DAY == $this->product_price_calculation_method) + && (!$numDays = HotelHelper::getNumberOfDays($serviceProductData['date_from'], $serviceProductData['date_to'])) + ) { + $numDays = 1; + } $unit_price_tax_excl = array_reduce($serviceProductData['additional_services'], function ($totalPriceTaxExcl, $item) { return $totalPriceTaxExcl + (isset($item['unit_price_tax_excl']) ? $item['unit_price_tax_excl'] : 0); @@ -459,6 +465,8 @@ class OrderDetailCore extends ObjectModel return $totalQty + (isset($item['quantity']) ? $item['quantity'] : 0); }, 0); + $quantity = $quantity * $numDays; + $firstServiceProduct = array_shift($serviceProductData['additional_services']); $tax_manager = TaxManagerFactory::getManager($this->vat_address, (int)$firstServiceProduct['id_tax_rules_group']); $this->tax_calculator = $tax_manager->getTaxCalculator(); @@ -477,6 +485,18 @@ class OrderDetailCore extends ObjectModel $quantity = array_reduce($serviceProductData, function ($totalQty, $item) { return $totalQty + (isset($item['quantity']) ? $item['quantity'] : 0); }, 0); + + $serviceProductData = array_shift($serviceProductData); + + $numDays = 1; + if ((Product::PRICE_CALCULATION_METHOD_PER_DAY == $this->product_price_calculation_method) + && (!$numDays = HotelHelper::getNumberOfDays($serviceProductData['date_from'], $serviceProductData['date_to'])) + ) { + $numDays = 1; + } + + + $quantity = $quantity * $numDays; } if ($this->tax_calculator == null) { diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index 5e55c0e17..f60ca7d0e 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -6169,7 +6169,9 @@ class AdminOrdersControllerCore extends AdminController $oldProductQuantity = $objServiceProductOrderDetail->quantity * $oldNumDays; $newProductQuantity = $objServiceProductOrderDetail->quantity * $newNumDays; $objOrderDetail->product_quantity += ($newProductQuantity - $oldProductQuantity); + $objOrderDetail->save(); + $objOrderDetail->updateTaxAmount($order); if (isset($order_invoice)) { $order_invoice->total_paid_tax_excl -= $objServiceProductOrderDetail->total_price_tax_excl;