Merge branch 'Qloapps:develop' into gli-3097
This commit is contained in:
280
classes/Cart.php
280
classes/Cart.php
@@ -827,7 +827,7 @@ class CartCore extends ObjectModel
|
||||
$serviceProducts = array();
|
||||
$context = Context::getContext();
|
||||
foreach ($productList as $key => $product) {
|
||||
if (!$product['booking_product'] && (Product::SELLING_PREFERENCE_STANDALONE == $product['selling_preference_type'])) {
|
||||
if (!$product['booking_product'] && Product::isSellableAsStandalone($product['id_product']) && !Product::isSellableWithRoomType($product['id_product'])) {
|
||||
if (Validate::isLoadedObject(
|
||||
$objProduct = new Product($product['id_product'], false, $this->id_lang)
|
||||
)) {
|
||||
@@ -1649,6 +1649,10 @@ class CartCore extends ObjectModel
|
||||
$objAdvPayment = new HotelAdvancedPayment();
|
||||
foreach ($products as $product) {
|
||||
// skip products if selection os for only room or only normal products
|
||||
$canSellWithRoomType = Product::isSellableWithRoomType($product['id_product']);
|
||||
$canSellWithHotel = Product::isSellableWithHotel($product['id_product']);
|
||||
$canSellAsStandalone = Product::isSellableAsStandalone($product['id_product']);
|
||||
|
||||
if ($product['booking_product']) {
|
||||
if ($type == Cart::ONLY_ROOM_SERVICES
|
||||
|| $type == Cart::ONLY_STANDALONE_PRODUCTS
|
||||
@@ -1664,10 +1668,8 @@ class CartCore extends ObjectModel
|
||||
continue;
|
||||
}
|
||||
|
||||
if (Product::SELLING_PREFERENCE_WITH_ROOM_TYPE == $product['selling_preference_type']
|
||||
|| Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE == $product['selling_preference_type']
|
||||
) {
|
||||
if ($type == Cart::ONLY_STANDALONE_PRODUCTS && Product::SELLING_PREFERENCE_WITH_ROOM_TYPE == $product['selling_preference_type']) {
|
||||
if ($canSellWithRoomType) {
|
||||
if ($type == Cart::ONLY_STANDALONE_PRODUCTS && !$canSellAsStandalone && !$canSellWithHotel) {
|
||||
continue;
|
||||
}
|
||||
if ($product['auto_add_to_cart']) {
|
||||
@@ -1693,9 +1695,7 @@ class CartCore extends ObjectModel
|
||||
continue;
|
||||
}
|
||||
}
|
||||
} elseif (Product::SELLING_PREFERENCE_STANDALONE == $product['selling_preference_type']
|
||||
|| Product::SELLING_PREFERENCE_HOTEL_STANDALONE == $product['selling_preference_type']
|
||||
) {
|
||||
} elseif ($canSellAsStandalone || $canSellWithHotel) {
|
||||
if ($type == Cart::ONLY_ROOM_SERVICES
|
||||
|| $type == Cart::ONLY_CONVENIENCE_FEE
|
||||
|| $type == Cart::ONLY_ROOM_SERVICES_WITHOUT_AUTO_ADD
|
||||
@@ -1758,22 +1758,55 @@ class CartCore extends ObjectModel
|
||||
$products_total[$id_tax_rules_group.'_'.$id_address] = 0;
|
||||
}
|
||||
if (!$product['booking_product']) {
|
||||
if (Product::SELLING_PREFERENCE_STANDALONE == $product['selling_preference_type']) {
|
||||
if ($servicePorducts = $objServiceProductCartDetail->getServiceProductsInCart(
|
||||
$isRoomServiceTotalType = in_array($type, array(
|
||||
Cart::ONLY_ROOM_SERVICES,
|
||||
Cart::ONLY_CONVENIENCE_FEE,
|
||||
Cart::ONLY_ROOM_SERVICES_WITHOUT_AUTO_ADD,
|
||||
Cart::ONLY_ROOM_SERVICES_WITHOUT_CONVENIENCE_FEE,
|
||||
Cart::ONLY_ROOM_SERVICES_WITH_AUTO_ADD_WITHOUT_CONVENIENCE_FEE,
|
||||
));
|
||||
|
||||
|
||||
if ($param_product && isset($product['selling_preference_type'])) {
|
||||
$canSellWithRoomType = $canSellWithRoomType
|
||||
&& in_array((int) $product['selling_preference_type'], array(
|
||||
Product::SELLING_PREFERENCE_WITH_ROOM_TYPE,
|
||||
Product::SELLING_PREFERENCE_WITH_HOTEL_AND_WITH_ROOM_TYPE,
|
||||
Product::SELLING_PREFERENCE_WITH_STANDALONE_AND_WITH_ROOM_TYPE,
|
||||
Product::SELLING_PREFERENCE_WITH_HOTEL_AND_WITH_ROOM_TYPE_AND_WITH_STANDALONE,
|
||||
));
|
||||
$canSellWithHotel = $canSellWithHotel
|
||||
&& in_array((int) $product['selling_preference_type'], array(
|
||||
Product::SELLING_PREFERENCE_WITH_HOTEL,
|
||||
Product::SELLING_PREFERENCE_WITH_HOTEL_AND_WITH_ROOM_TYPE,
|
||||
Product::SELLING_PREFERENCE_WITH_HOTEL_AND_WITH_STANDALONE,
|
||||
Product::SELLING_PREFERENCE_WITH_HOTEL_AND_WITH_ROOM_TYPE_AND_WITH_STANDALONE,
|
||||
));
|
||||
$canSellAsStandalone = $canSellAsStandalone
|
||||
&& in_array((int) $product['selling_preference_type'], array(
|
||||
Product::SELLING_PREFERENCE_WITH_STANDALONE,
|
||||
Product::SELLING_PREFERENCE_WITH_HOTEL_AND_WITH_STANDALONE,
|
||||
Product::SELLING_PREFERENCE_WITH_STANDALONE_AND_WITH_ROOM_TYPE,
|
||||
Product::SELLING_PREFERENCE_WITH_HOTEL_AND_WITH_ROOM_TYPE_AND_WITH_STANDALONE,
|
||||
));
|
||||
}
|
||||
|
||||
if ($canSellAsStandalone && !$isRoomServiceTotalType) {
|
||||
if ($serviceProducts = $objServiceProductCartDetail->getServiceProductsInCart(
|
||||
$this->id,
|
||||
[],
|
||||
null,
|
||||
null,
|
||||
0,
|
||||
0,
|
||||
null,
|
||||
(int)$product['id_product']
|
||||
)) {
|
||||
foreach ($servicePorducts as $servicePorduct) {
|
||||
foreach ($serviceProducts as $serviceProduct) {
|
||||
if ($with_taxes) {
|
||||
$priceAdd = $servicePorduct['unit_price_tax_incl'];
|
||||
$priceAdd = $serviceProduct['unit_price_tax_incl'];
|
||||
} else {
|
||||
$priceAdd = $servicePorduct['unit_price_tax_excl'];
|
||||
$priceAdd = $serviceProduct['unit_price_tax_excl'];
|
||||
}
|
||||
$lineTotal = Tools::processPriceRounding($priceAdd, (int)$servicePorduct['quantity']);
|
||||
$lineTotal = Tools::processPriceRounding($priceAdd, (int)$serviceProduct['quantity']);
|
||||
if ($ps_round_type == Order::ROUND_TOTAL) {
|
||||
$products_total[$id_tax_rules_group.'_'.$id_address] += $lineTotal;
|
||||
} else {
|
||||
@@ -1781,22 +1814,21 @@ class CartCore extends ObjectModel
|
||||
}
|
||||
|
||||
if ($with_taxes && in_array($type, array(Cart::BOTH, Cart::BOTH_WITHOUT_SHIPPING, Cart::ONLY_TOURISM_TAX))) {
|
||||
$tourism_tax_total += $servicePorduct['tourism_tax'];
|
||||
$tourism_tax_standalone_products += $servicePorduct['tourism_tax'];
|
||||
$tourism_tax_total += $serviceProduct['tourism_tax'];
|
||||
$tourism_tax_standalone_products += $serviceProduct['tourism_tax'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else if (Product::SELLING_PREFERENCE_HOTEL_STANDALONE == $product['selling_preference_type']
|
||||
|| Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE == $product['selling_preference_type']
|
||||
) {
|
||||
}
|
||||
if ($canSellWithHotel) {
|
||||
if ($type == Cart::ONLY_ROOM_SERVICES
|
||||
|| $type == Cart::ONLY_CONVENIENCE_FEE
|
||||
|| $type == Cart::ONLY_ROOM_SERVICES_WITHOUT_AUTO_ADD
|
||||
|| $type == Cart::ONLY_ROOM_SERVICES_WITHOUT_CONVENIENCE_FEE
|
||||
|| $type == Cart::ONLY_ROOM_SERVICES_WITH_AUTO_ADD_WITHOUT_CONVENIENCE_FEE
|
||||
) {
|
||||
$servicePorducts = $objServiceProductCartDetail->getServiceProductsInCart(
|
||||
$serviceProducts = $objServiceProductCartDetail->getServiceProductsInCart(
|
||||
$this->id,
|
||||
[],
|
||||
0,
|
||||
@@ -1805,7 +1837,7 @@ class CartCore extends ObjectModel
|
||||
(int)$product['id_product']
|
||||
);
|
||||
} elseif ($type == Cart::ONLY_STANDALONE_PRODUCTS) {
|
||||
$servicePorducts = $objServiceProductCartDetail->getServiceProductsInCart(
|
||||
$serviceProducts = $objServiceProductCartDetail->getServiceProductsInCart(
|
||||
$this->id,
|
||||
[],
|
||||
null,
|
||||
@@ -1814,7 +1846,7 @@ class CartCore extends ObjectModel
|
||||
(int)$product['id_product']
|
||||
);
|
||||
} else {
|
||||
$servicePorducts = $objServiceProductCartDetail->getServiceProductsInCart(
|
||||
$serviceProducts = $objServiceProductCartDetail->getServiceProductsInCart(
|
||||
$this->id,
|
||||
[],
|
||||
isset($product['id_hotel']) ? $product['id_hotel'] : null,
|
||||
@@ -1824,27 +1856,31 @@ class CartCore extends ObjectModel
|
||||
);
|
||||
}
|
||||
|
||||
if ($servicePorducts) {
|
||||
foreach ($servicePorducts as $servicePorduct) {
|
||||
if ($with_taxes) {
|
||||
$priceAdd = $servicePorduct['total_price_tax_incl'];
|
||||
} else {
|
||||
$priceAdd = $servicePorduct['total_price_tax_excl'];
|
||||
}
|
||||
if ($serviceProducts) {
|
||||
foreach ($serviceProducts as $serviceProduct) {
|
||||
if (!empty($serviceProduct['id_hotel']) && empty($serviceProduct['id_hotel_cart_booking'])) {
|
||||
if ($with_taxes) {
|
||||
$priceAdd = $serviceProduct['total_price_tax_incl'];
|
||||
} else {
|
||||
$priceAdd = $serviceProduct['total_price_tax_excl'];
|
||||
}
|
||||
|
||||
if ($ps_round_type == Order::ROUND_TOTAL) {
|
||||
$products_total[$id_tax_rules_group.'_'.$id_address] += $priceAdd;
|
||||
} else {
|
||||
$products_total[$id_tax_rules_group] += $priceAdd;
|
||||
if ($ps_round_type == Order::ROUND_TOTAL) {
|
||||
$products_total[$id_tax_rules_group.'_'.$id_address] += $priceAdd;
|
||||
} else {
|
||||
$products_total[$id_tax_rules_group] += $priceAdd;
|
||||
}
|
||||
}
|
||||
|
||||
if ($with_taxes && in_array($type, array(Cart::BOTH, Cart::BOTH_WITHOUT_SHIPPING, Cart::ONLY_TOURISM_TAX))) {
|
||||
$tourism_tax_total += $servicePorduct['tourism_tax'];
|
||||
$tourism_tax_standalone_products += $servicePorduct['tourism_tax'];
|
||||
$tourism_tax_total += $serviceProduct['tourism_tax'];
|
||||
$tourism_tax_standalone_products += $serviceProduct['tourism_tax'];
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (Product::SELLING_PREFERENCE_WITH_ROOM_TYPE == $product['selling_preference_type']) {
|
||||
}
|
||||
if ($canSellWithRoomType && $type !== Cart::ONLY_STANDALONE_PRODUCTS) {
|
||||
|
||||
if ($servicesWithRoom = $objServiceProductCartDetail->getServiceProductsInCart(
|
||||
$this->id,
|
||||
[],
|
||||
@@ -1859,17 +1895,19 @@ class CartCore extends ObjectModel
|
||||
(int)$product['price_addition_type']
|
||||
)) {
|
||||
foreach ($servicesWithRoom as $service) {
|
||||
if ($with_taxes) {
|
||||
$servicePrice = $service['total_price_tax_incl'];
|
||||
} else {
|
||||
$servicePrice = $service['total_price_tax_excl'];
|
||||
}
|
||||
if(!empty($service['id_hotel_cart_booking']) && empty($service['id_hotel'])) {
|
||||
if ($with_taxes) {
|
||||
$servicePrice = $service['total_price_tax_incl'];
|
||||
} else {
|
||||
$servicePrice = $service['total_price_tax_excl'];
|
||||
}
|
||||
|
||||
// Rounding as per configurations
|
||||
if ($ps_round_type == Order::ROUND_TOTAL) {
|
||||
$products_total[$id_tax_rules_group.'_'.$id_address] += $servicePrice;
|
||||
} else {
|
||||
$products_total[$id_tax_rules_group] += $servicePrice;
|
||||
// Rounding as per configurations
|
||||
if ($ps_round_type == Order::ROUND_TOTAL) {
|
||||
$products_total[$id_tax_rules_group.'_'.$id_address] += $servicePrice;
|
||||
} else {
|
||||
$products_total[$id_tax_rules_group] += $servicePrice;
|
||||
}
|
||||
}
|
||||
|
||||
if ($with_taxes && in_array($type, array(Cart::BOTH, Cart::BOTH_WITHOUT_SHIPPING, Cart::ONLY_TOURISM_TAX))) {
|
||||
@@ -2469,9 +2507,7 @@ class CartCore extends ObjectModel
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (Product::SELLING_PREFERENCE_WITH_ROOM_TYPE == $product['selling_preference_type']
|
||||
|| Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE == $product['selling_preference_type']
|
||||
) {
|
||||
if (Product::isSellableWithRoomType($product['id_product'])) {
|
||||
// get standard products which are booked for room types
|
||||
// send id_hotel = 0 for standard products with room types
|
||||
if ($selectedServiceProducts = $objServiceProductCartDetail->getServiceProductsInCart(
|
||||
@@ -2484,6 +2520,9 @@ class CartCore extends ObjectModel
|
||||
)) {
|
||||
$array = array();
|
||||
foreach($selectedServiceProducts as $selectedProduct) {
|
||||
if (empty($selectedProduct['id_hotel_cart_booking'])) {
|
||||
continue;
|
||||
}
|
||||
if (isset($array[$selectedProduct['id_room_type_hotel']])) {
|
||||
$array[$selectedProduct['id_room_type_hotel']]['total_price_tax_excl'] += $selectedProduct['total_price_tax_excl'];
|
||||
$array[$selectedProduct['id_room_type_hotel']]['total_price_tax_incl'] += $selectedProduct['total_price_tax_incl'];
|
||||
@@ -2497,25 +2536,21 @@ class CartCore extends ObjectModel
|
||||
'id_hotel_cart_booking' => $selectedProduct['id_hotel_cart_booking'],
|
||||
);
|
||||
}
|
||||
if (Product::PRICE_CALCULATION_METHOD_PER_DAY == $selectedProduct['price_calculation_method']) {
|
||||
$numDays = HotelHelper::getNumberOfDays(
|
||||
$selectedProduct['date_from'],
|
||||
$selectedProduct['date_to']
|
||||
);
|
||||
$array[$selectedProduct['id_room_type_hotel']]['quantity'] += ($selectedProduct['quantity'] * $numDays);
|
||||
} else {
|
||||
$array[$selectedProduct['id_room_type_hotel']]['quantity'] += $selectedProduct['quantity'];
|
||||
|
||||
}
|
||||
$numDays = Product::getServicePriceBillableDays(
|
||||
$selectedProduct['price_calculation_method'],
|
||||
$selectedProduct['date_from'],
|
||||
$selectedProduct['date_to']
|
||||
);
|
||||
$array[$selectedProduct['id_room_type_hotel']]['quantity'] += ($selectedProduct['quantity'] * $numDays);
|
||||
}
|
||||
|
||||
|
||||
if ($array) {
|
||||
foreach($array as $selectedProduct) {
|
||||
$product['cart_quantity'] = $selectedProduct['quantity'];
|
||||
$product['total'] = $selectedProduct['total_price_tax_excl'];
|
||||
$product['total_wt'] = $selectedProduct['total_price_tax_incl'];
|
||||
$product['price_wt'] = $selectedProduct['total_price_tax_incl'] / $selectedProduct['quantity'];
|
||||
$product['price'] = $selectedProduct['total_price_tax_excl'] / $selectedProduct['quantity'];
|
||||
$product['price_wt'] = $selectedProduct['total_price_tax_incl'] / max($selectedProduct['quantity'], 1);
|
||||
$product['price'] = $selectedProduct['total_price_tax_excl'] / max($selectedProduct['quantity'], 1);
|
||||
$product['id_hotel'] = $selectedProduct['id_hotel'];
|
||||
$product['id_room_type'] = $selectedProduct['id_room_type'];
|
||||
$product['id_hotel_cart_booking'] = $selectedProduct['id_hotel_cart_booking'];
|
||||
@@ -2545,23 +2580,64 @@ class CartCore extends ObjectModel
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Product::isSellableAsStandalone($product['id_product'])) {
|
||||
if ($selectedServiceProducts = $objServiceProductCartDetail->getServiceProductsInCart(
|
||||
$this->id,
|
||||
[],
|
||||
0,
|
||||
0,
|
||||
null,
|
||||
(int)$product['id_product']
|
||||
)) {
|
||||
$array = array();
|
||||
foreach ($selectedServiceProducts as $selectedServiceProduct) {
|
||||
if ((int) $selectedServiceProduct['id_hotel'] === 0
|
||||
&& (int) $selectedServiceProduct['id_hotel_cart_booking'] === 0
|
||||
) {
|
||||
if (isset($array[$selectedServiceProduct['id_product']])) {
|
||||
$array[$selectedServiceProduct['id_product']]['total_price_tax_excl'] += $selectedServiceProduct['total_price_tax_excl'];
|
||||
$array[$selectedServiceProduct['id_product']]['total_price_tax_incl'] += $selectedServiceProduct['total_price_tax_incl'];
|
||||
$array[$selectedServiceProduct['id_product']]['quantity'] += $selectedServiceProduct['quantity'];
|
||||
} else {
|
||||
$array[$selectedServiceProduct['id_product']] = array(
|
||||
'quantity' => $selectedServiceProduct['quantity'],
|
||||
'total_price_tax_excl' => $selectedServiceProduct['total_price_tax_excl'],
|
||||
'total_price_tax_incl' => $selectedServiceProduct['total_price_tax_incl'],
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (Product::SELLING_PREFERENCE_STANDALONE == $product['selling_preference_type']) {
|
||||
if (!isset($standaloneProduct[$id_address])) {
|
||||
$standaloneProduct[$id_address] = array(
|
||||
'product_list' => array(),
|
||||
'warehouse_list' => $package['warehouse_list'],
|
||||
'carrier_list' => $product['carrier_list'],
|
||||
'id_warehouse' => $package['id_warehouse'],
|
||||
'id_carrier' => isset($package['id_carrier']) ? $package['id_carrier'] : 0
|
||||
);
|
||||
if ($array) {
|
||||
foreach ($array as $standaloneProductData) {
|
||||
$serviceProduct = $product;
|
||||
$serviceProduct['cart_quantity'] = $standaloneProductData['quantity'];
|
||||
$serviceProduct['total'] = $standaloneProductData['total_price_tax_excl'];
|
||||
$serviceProduct['total_wt'] = $standaloneProductData['total_price_tax_incl'];
|
||||
$serviceProduct['price'] = $standaloneProductData['total_price_tax_excl'] / $standaloneProductData['quantity'];
|
||||
$serviceProduct['price_wt'] = $standaloneProductData['total_price_tax_incl'] / $standaloneProductData['quantity'];
|
||||
$serviceProduct['selling_preference_type'] = Product::SELLING_PREFERENCE_WITH_STANDALONE;
|
||||
$serviceProduct['id_hotel'] = 0;
|
||||
$serviceProduct['id_hotel_cart_booking'] = 0;
|
||||
$serviceProduct['id_room_type'] = 0;
|
||||
if (!isset($standaloneProduct[$id_address])) {
|
||||
$standaloneProduct[$id_address] = array(
|
||||
'product_list' => array(),
|
||||
'warehouse_list' => $package['warehouse_list'],
|
||||
'carrier_list' => $product['carrier_list'],
|
||||
'id_warehouse' => $package['id_warehouse'],
|
||||
'id_carrier' => isset($package['id_carrier']) ? $package['id_carrier'] : 0
|
||||
);
|
||||
}
|
||||
$productinfo = $serviceProduct;
|
||||
|
||||
$standaloneProduct[$id_address]['product_list'][] = $productinfo;
|
||||
}
|
||||
}
|
||||
}
|
||||
$standaloneProduct[$id_address]['product_list'][] = $product;
|
||||
}
|
||||
|
||||
if (Product::SELLING_PREFERENCE_HOTEL_STANDALONE == $product['selling_preference_type']
|
||||
|| Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE == $product['selling_preference_type']
|
||||
) {
|
||||
if (Product::isSellableWithHotel($product['id_product'])) {
|
||||
if ($selectedServiceProducts = $objServiceProductCartDetail->getServiceProductsInCart(
|
||||
$this->id,
|
||||
[],
|
||||
@@ -2572,6 +2648,9 @@ class CartCore extends ObjectModel
|
||||
)) {
|
||||
$array = array();
|
||||
foreach($selectedServiceProducts as $hotelProduct) {
|
||||
if (!isset($hotelProduct['id_hotel']) || !$hotelProduct['id_hotel']) {
|
||||
continue;
|
||||
}
|
||||
if (isset($array[$hotelProduct['id_hotel']])) {
|
||||
$array[$hotelProduct['id_hotel']]['total_price_tax_excl'] += $hotelProduct['total_price_tax_excl'];
|
||||
$array[$hotelProduct['id_hotel']]['total_price_tax_incl'] += $hotelProduct['total_price_tax_incl'];
|
||||
@@ -2602,7 +2681,8 @@ class CartCore extends ObjectModel
|
||||
// if (!empty($hotelProducts['products'])) {
|
||||
// foreach($hotelProducts['products'] as $hotelProduct) {
|
||||
$productinfo = $serviceProduct;
|
||||
$productinfo['selling_preference_type'] = Product::SELLING_PREFERENCE_HOTEL_STANDALONE;
|
||||
$productinfo['selling_preference_type'] = Product::SELLING_PREFERENCE_WITH_HOTEL;
|
||||
|
||||
$orderPackage[$id_address][$hotelProduct['id_hotel']]['product_list'][] = $productinfo;
|
||||
if (!isset($orderPackage[$id_address][$hotelProduct['id_hotel']]['id_hotel'])) {
|
||||
$orderPackage[$id_address][$hotelProduct['id_hotel']]['id_hotel'] = $hotelProduct['id_hotel'];
|
||||
@@ -2647,6 +2727,7 @@ class CartCore extends ObjectModel
|
||||
}
|
||||
|
||||
$final_package_list = $hotelWisePackageList;
|
||||
/// ddd($final_package_list);
|
||||
// END $package_list hotel wise
|
||||
$cache[$cache_key] = $final_package_list;
|
||||
return $final_package_list;
|
||||
@@ -3187,33 +3268,24 @@ class CartCore extends ObjectModel
|
||||
$id_address = HotelRoomType::getHotelIdAddressByIdProduct($id_product);
|
||||
} else {
|
||||
// if the product is a standard product the get the address as per the selling preference
|
||||
$sellingPreferenceType = Product::getSellingPreferenceType($id_product);
|
||||
$canSellWithRoomType = Product::isSellableWithRoomType($id_product);
|
||||
$canSellWithHotel = Product::isSellableWithHotel($id_product);
|
||||
$canSellAsStandalone = Product::isSellableAsStandalone($id_product);
|
||||
|
||||
if ($sellingPreferenceType == Product::SELLING_PREFERENCE_WITH_ROOM_TYPE) {
|
||||
if ($id_product_room_type) {
|
||||
$objRoomType = new HotelRoomType();
|
||||
if ($roomTypeInfo = $objRoomType->getRoomTypeInfoByIdProduct($id_product_room_type)) {
|
||||
if ($htlAddress = HotelBranchInformation::getAddress($roomTypeInfo['id_hotel'])) {
|
||||
$id_address = $htlAddress['id_address'];
|
||||
}
|
||||
}
|
||||
}
|
||||
} elseif ($sellingPreferenceType == Product::SELLING_PREFERENCE_HOTEL_STANDALONE) {
|
||||
if ($canSellWithHotel) {
|
||||
if ($htlAddress = HotelBranchInformation::getAddress($id_hotel)) {
|
||||
$id_address = $htlAddress['id_address'];
|
||||
}
|
||||
} elseif ($sellingPreferenceType == Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE) {
|
||||
if ($htlAddress = HotelBranchInformation::getAddress($id_hotel)) {
|
||||
$id_address = $htlAddress['id_address'];
|
||||
} elseif ($id_product_room_type) {
|
||||
$objRoomType = new HotelRoomType();
|
||||
if ($roomTypeInfo = $objRoomType->getRoomTypeInfoByIdProduct($id_product_room_type)) {
|
||||
if ($htlAddress = HotelBranchInformation::getAddress($roomTypeInfo['id_hotel'])) {
|
||||
$id_address = $htlAddress['id_address'];
|
||||
}
|
||||
}
|
||||
|
||||
if (!$id_address && $canSellWithRoomType && $id_product_room_type) {
|
||||
$objRoomType = new HotelRoomType();
|
||||
if ($roomTypeInfo = $objRoomType->getRoomTypeInfoByIdProduct($id_product_room_type)) {
|
||||
if ($htlAddress = HotelBranchInformation::getAddress($roomTypeInfo['id_hotel'])) {
|
||||
$id_address = $htlAddress['id_address'];
|
||||
}
|
||||
}
|
||||
} elseif ($sellingPreferenceType == Product::SELLING_PREFERENCE_STANDALONE) {
|
||||
} elseif ($canSellAsStandalone) {
|
||||
$addressPreferenceType = Configuration::get('PS_STANDARD_PRODUCT_ORDER_ADDRESS_PREFRENCE');
|
||||
if ($addressPreferenceType == Product::STANDARD_PRODUCT_ADDRESS_PREFERENCE_CUSTOM) {
|
||||
$id_address = (int) Configuration::get('PS_STANDARD_PRODUCT_ORDER_ADDRESS_ID');
|
||||
@@ -3982,14 +4054,14 @@ class CartCore extends ObjectModel
|
||||
$objServiceProductCartDetail = new ServiceProductCartDetail();
|
||||
foreach ($products as &$product) {
|
||||
if (!$product['booking_product']) {
|
||||
if (Product::SELLING_PREFERENCE_STANDALONE == $product['selling_preference_type']) {
|
||||
if (Product::SELLING_PREFERENCE_WITH_STANDALONE == $product['selling_preference_type']) {
|
||||
$nbTotalProducts += (int) $product['cart_quantity'];
|
||||
} elseif (Product::SELLING_PREFERENCE_HOTEL_STANDALONE == $product['selling_preference_type']
|
||||
|| Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE == $product['selling_preference_type']
|
||||
} elseif (Product::SELLING_PREFERENCE_WITH_HOTEL == $product['selling_preference_type']
|
||||
|| Product::SELLING_PREFERENCE_WITH_HOTEL_AND_WITH_ROOM_TYPE == $product['selling_preference_type']
|
||||
) {
|
||||
if ($serviceProducts = $objServiceProductCartDetail->getServiceProductsInCart(
|
||||
$this->id,
|
||||
[Product::SELLING_PREFERENCE_HOTEL_STANDALONE, Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE],
|
||||
[Product::SELLING_PREFERENCE_HOTEL_STANDALONE, Product::SELLING_PREFERENCE_WITH_HOTEL_AND_WITH_ROOM_TYPE],
|
||||
null,
|
||||
0,
|
||||
null,
|
||||
|
||||
@@ -361,7 +361,7 @@ class CartRuleCore extends ObjectModel
|
||||
|
||||
// Remove cart rule if the cart contains a product from a hotel not covered by its hotel restriction
|
||||
foreach ($result as $key => $cart_rule) {
|
||||
if ($cart_rule['hotel_restriction']) {
|
||||
if (isset($cart_rule['hotel_restriction']) && $cart_rule['hotel_restriction']) {
|
||||
$total_cart_products = (int)Db::getInstance()->getValue('
|
||||
SELECT COUNT(cp.id_product)
|
||||
FROM '._DB_PREFIX_.'cart_product cp
|
||||
@@ -1007,7 +1007,7 @@ class CartRuleCore extends ObjectModel
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$cache_id .= '_'.(int)$product['id_product'].'_'.(int)$product['id_product_attribute'].(isset($product['in_stock']) ? '_'.(int)$product['in_stock'] : '');
|
||||
$cache_id .= '_'.(int)$product['id_product'].'_'.(int)$product['id_product_attribute'].'_'.(int)$product['cart_quantity'].(isset($product['in_stock']) ? '_'.(int)$product['in_stock'] : '');
|
||||
}
|
||||
|
||||
$package_products = $package['products'];
|
||||
|
||||
@@ -603,9 +603,9 @@ abstract class PaymentModuleCore extends Module
|
||||
}
|
||||
|
||||
if (!$product['booking_product']
|
||||
&& ($product['selling_preference_type'] == Product::SELLING_PREFERENCE_STANDALONE
|
||||
|| $product['selling_preference_type'] == Product::SELLING_PREFERENCE_HOTEL_STANDALONE
|
||||
|| $product['selling_preference_type'] == Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE
|
||||
&& ($product['selling_preference_type'] == Product::SELLING_PREFERENCE_WITH_STANDALONE
|
||||
|| $product['selling_preference_type'] == Product::SELLING_PREFERENCE_WITH_HOTEL
|
||||
|| $product['selling_preference_type'] == Product::SELLING_PREFERENCE_WITH_HOTEL_AND_WITH_ROOM_TYPE
|
||||
)
|
||||
) {
|
||||
$cover_image_arr = $objProduct->getCover($product['id_product']);
|
||||
@@ -901,6 +901,15 @@ abstract class PaymentModuleCore extends Module
|
||||
$objBookingDetail->zipcode = $hotelAddress['postcode'];
|
||||
$objBookingDetail->phone = $hotelAddress['phone'];
|
||||
}
|
||||
$objBookingDetail->property_type_name = $objHotelBranch->propertyTypeName;
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Save room selling object and property type names as they are at the time of order creation
|
||||
if ($roomTypeInfo = $objRoomType->getRoomTypeInfoByIdProduct($idProduct, $idLang)) {
|
||||
$objBookingDetail->selling_object_name = $roomTypeInfo['selling_object_name'];
|
||||
$objBookingDetail->selling_object_plural_name = $roomTypeInfo['selling_object_plural_name'];
|
||||
}
|
||||
|
||||
/*for saving details of the advance payment product wise*/
|
||||
@@ -974,6 +983,9 @@ abstract class PaymentModuleCore extends Module
|
||||
)) {
|
||||
$idOrderDetail = $objBookingDetail->getPsOrderDetailIdByIdProduct($idProduct, $order->id, $product['selling_preference_type']);
|
||||
foreach ($roomTypeServices as $roomTypeService) {
|
||||
if (!$roomTypeService['id_hotel_cart_booking']) {
|
||||
continue;
|
||||
}
|
||||
$roomBookingDetail = $objBookingDetail->getRowByIdOrderIdProductInDateRange(
|
||||
$order->id,
|
||||
$roomTypeService['id_room_type'],
|
||||
@@ -1020,7 +1032,7 @@ abstract class PaymentModuleCore extends Module
|
||||
}
|
||||
}
|
||||
}
|
||||
} elseif (Product::SELLING_PREFERENCE_HOTEL_STANDALONE == $product['selling_preference_type']) {
|
||||
} elseif (Product::SELLING_PREFERENCE_WITH_HOTEL == $product['selling_preference_type']) {
|
||||
if ($hotelProducts = $objServiceProductCartDetail->getServiceProductsInCart(
|
||||
$this->context->cart->id,
|
||||
[],
|
||||
@@ -1077,12 +1089,12 @@ abstract class PaymentModuleCore extends Module
|
||||
|
||||
}
|
||||
}
|
||||
} elseif (Product::SELLING_PREFERENCE_STANDALONE == $product['selling_preference_type']) {
|
||||
} elseif (Product::SELLING_PREFERENCE_WITH_STANDALONE == $product['selling_preference_type']) {
|
||||
if ($standaloneProducts = $objServiceProductCartDetail->getServiceProductsInCart(
|
||||
$this->context->cart->id,
|
||||
[Product::SELLING_PREFERENCE_STANDALONE],
|
||||
null,
|
||||
null,
|
||||
[],
|
||||
0,
|
||||
0,
|
||||
null,
|
||||
$product['id_product']
|
||||
)) {
|
||||
@@ -1128,7 +1140,7 @@ abstract class PaymentModuleCore extends Module
|
||||
|
||||
}
|
||||
}
|
||||
} elseif (Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE == $product['selling_preference_type']) {
|
||||
} elseif (Product::SELLING_PREFERENCE_WITH_HOTEL_AND_WITH_ROOM_TYPE == $product['selling_preference_type']) {
|
||||
$idProductRoomType = null;
|
||||
$idProductHotel = null;
|
||||
if (isset($product['id_room_type']) && $product['id_room_type']) {
|
||||
@@ -1146,7 +1158,7 @@ abstract class PaymentModuleCore extends Module
|
||||
)) {
|
||||
foreach ($serviceProducts as $serviceProduct) {
|
||||
if ($serviceProduct['id_hotel']) {
|
||||
$idOrderDetail = $objBookingDetail->getPsOrderDetailIdByIdProduct($idProduct, $order->id, Product::SELLING_PREFERENCE_HOTEL_STANDALONE);
|
||||
$idOrderDetail = $objBookingDetail->getPsOrderDetailIdByIdProduct($idProduct, $order->id, Product::SELLING_PREFERENCE_WITH_HOTEL);
|
||||
} else {
|
||||
$idOrderDetail = $objBookingDetail->getPsOrderDetailIdByIdProduct($idProduct, $order->id, Product::SELLING_PREFERENCE_WITH_ROOM_TYPE);
|
||||
}
|
||||
@@ -1335,10 +1347,10 @@ abstract class PaymentModuleCore extends Module
|
||||
$total_convenience_fee_tax = $total_convenience_fee_ti - $total_convenience_fee_te;
|
||||
|
||||
// service products
|
||||
$standalone_products_price_tax_excl = $order->getTotalProductsWithoutTaxes(false, false, Product::SELLING_PREFERENCE_STANDALONE);
|
||||
$standalone_products_price_tax_incl = $order->getTotalProductsWithTaxes(false, false, Product::SELLING_PREFERENCE_STANDALONE);
|
||||
$hotel_standalone_products_price_tax_excl = $order->getTotalProductsWithoutTaxes(false, false, Product::SELLING_PREFERENCE_HOTEL_STANDALONE);
|
||||
$hotel_standalone_products_price_tax_incl = $order->getTotalProductsWithTaxes(false, false, Product::SELLING_PREFERENCE_HOTEL_STANDALONE);
|
||||
$standalone_products_price_tax_excl = $order->getTotalProductsWithoutTaxes(false, false, Product::SELLING_PREFERENCE_WITH_STANDALONE);
|
||||
$standalone_products_price_tax_incl = $order->getTotalProductsWithTaxes(false, false, Product::SELLING_PREFERENCE_WITH_STANDALONE);
|
||||
$hotel_standalone_products_price_tax_excl = $order->getTotalProductsWithoutTaxes(false, false, Product::SELLING_PREFERENCE_WITH_HOTEL);
|
||||
$hotel_standalone_products_price_tax_incl = $order->getTotalProductsWithTaxes(false, false, Product::SELLING_PREFERENCE_WITH_HOTEL);
|
||||
|
||||
$service_products_tax = ($standalone_products_price_tax_incl + $hotel_standalone_products_price_tax_incl) - ($standalone_products_price_tax_excl + $hotel_standalone_products_price_tax_excl);
|
||||
|
||||
|
||||
@@ -56,6 +56,13 @@ class ProductCore extends ObjectModel
|
||||
/** @var string Manufacturer name */
|
||||
public $manufacturer_name;
|
||||
|
||||
/** @var string Room Type Selling Object name */
|
||||
public $selling_object_name;
|
||||
|
||||
/** @var string Room Type Selling Object plural name */
|
||||
public $selling_object_plural_name;
|
||||
|
||||
|
||||
/** @var string Supplier name */
|
||||
public $supplier_name;
|
||||
|
||||
@@ -250,6 +257,7 @@ class ProductCore extends ObjectModel
|
||||
public $is_virtual;
|
||||
public $booking_product;
|
||||
public $id_pack_product_attribute;
|
||||
public $id_selling_object;
|
||||
public $cache_default_attribute;
|
||||
|
||||
/**
|
||||
@@ -345,6 +353,7 @@ class ProductCore extends ObjectModel
|
||||
'show_price' => array('type' => self::TYPE_BOOL, 'shop' => true, 'validate' => 'isBool'),
|
||||
'indexed' => array('type' => self::TYPE_BOOL, 'shop' => true, 'validate' => 'isBool'),
|
||||
'visibility' => array('type' => self::TYPE_STRING, 'shop' => true, 'validate' => 'isProductVisibility', 'values' => array('both', 'catalog', 'search', 'none'), 'default' => 'both'),
|
||||
'id_selling_object' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => false),
|
||||
'cache_default_attribute' => array('type' => self::TYPE_INT, 'shop' => true),
|
||||
'advanced_stock_management' => array('type' => self::TYPE_BOOL, 'shop' => true, 'validate' => 'isBool'),
|
||||
'date_add' => array('type' => self::TYPE_DATE, 'shop' => true, 'validate' => 'isDate'),
|
||||
@@ -555,15 +564,24 @@ class ProductCore extends ObjectModel
|
||||
|
||||
// Product selling preference types
|
||||
const SELLING_PREFERENCE_WITH_ROOM_TYPE = 1; // Product to be sold with Room types
|
||||
const SELLING_PREFERENCE_HOTEL_STANDALONE = 2; // Product to be sold Standalone with Hotels
|
||||
const SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE = 3; // Product to be sold Standalone with Hotels and with Room types also
|
||||
const SELLING_PREFERENCE_STANDALONE = 4; // Product to be sold standalone
|
||||
const SELLING_PREFERENCE_WITH_HOTEL = 2; // Product to be sold Standalone with Hotels
|
||||
const SELLING_PREFERENCE_WITH_HOTEL_AND_WITH_ROOM_TYPE = 3; // Product to be sold Standalone with Hotels and with Room types also
|
||||
const SELLING_PREFERENCE_WITH_STANDALONE = 4; // Product to be sold standalone
|
||||
const SELLING_PREFERENCE_WITH_STANDALONE_AND_WITH_ROOM_TYPE = 5; // Product to be sold standalone and with Room types also
|
||||
const SELLING_PREFERENCE_WITH_HOTEL_AND_WITH_STANDALONE = 6; // Product to be sold standalone with Hotels and with Room types also
|
||||
const SELLING_PREFERENCE_WITH_HOTEL_AND_WITH_ROOM_TYPE_AND_WITH_STANDALONE = 7; // Product to be sold standalone with Hotels and with Room types also and standalone
|
||||
|
||||
const PRICE_ADDITION_TYPE_WITH_ROOM = 1;
|
||||
const PRICE_ADDITION_TYPE_INDEPENDENT = 2;
|
||||
|
||||
const PRICE_CALCULATION_METHOD_PER_BOOKING = 1;
|
||||
const PRICE_CALCULATION_METHOD_PER_DAY = 2;
|
||||
const PRICE_CALCULATION_METHOD_ON_CHECKIN_DAY = 1;
|
||||
const PRICE_CALCULATION_METHOD_ON_CHECKOUT_DAY = 2;
|
||||
const PRICE_CALCULATION_METHOD_CHECKIN_DAY_AND_CHECKOUT_DAY = 3;
|
||||
const PRICE_CALCULATION_METHOD_ON_DURING_STAY = 4;
|
||||
const PRICE_CALCULATION_METHOD_CHECKIN_AND_DURING_STAY = 5;
|
||||
const PRICE_CALCULATION_METHOD_CHECKOUT_AND_DURING_STAY = 6;
|
||||
const PRICE_CALCULATION_METHOD_CHECKIN_AND_CHECKOUT_AND_DURING_STAY = 7;
|
||||
const PRICE_CALCULATION_METHOD_ONCE_FOR_BOOKING = 8;
|
||||
|
||||
const STANDARD_PRODUCT_ADDRESS_PREFERENCE_CUSTOMER = 1;
|
||||
const STANDARD_PRODUCT_ADDRESS_PREFERENCE_HOTEL = 2;
|
||||
@@ -581,6 +599,9 @@ class ProductCore extends ObjectModel
|
||||
$this->tax_name = 'deprecated'; // The applicable tax may be BOTH the product one AND the state one (moreover this variable is some deadcode)
|
||||
$this->manufacturer_name = Manufacturer::getNameById((int)$this->id_manufacturer);
|
||||
$this->supplier_name = Supplier::getNameById((int)$this->id_supplier);
|
||||
$sellingObject = RoomTypeSellingObject::getRoomTypeSellingObjectBySellingObjectId((int)$this->id_selling_object, (int)$id_lang);
|
||||
$this->selling_object_name = $sellingObject ? $sellingObject['name'] : null;
|
||||
$this->selling_object_plural_name = $sellingObject ? $sellingObject['plural_name'] : null;
|
||||
$address = null;
|
||||
$id_address = Cart::getIdAddressForTaxCalculation($this->id);
|
||||
$this->tax_rate = $this->getTaxesRate(new Address($id_address));
|
||||
@@ -1441,7 +1462,10 @@ class ProductCore extends ObjectModel
|
||||
('.
|
||||
'(`element_type` = '.RoomTypeServiceProduct::WK_ELEMENT_TYPE_ROOM_TYPE.' AND `id_element` = '.(int)$this->id.')
|
||||
)
|
||||
AND (p.`selling_preference_type` = '.(int)self::SELLING_PREFERENCE_WITH_ROOM_TYPE. ' || p.`selling_preference_type` = '.(int)self::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE.')'. '
|
||||
AND (p.`selling_preference_type` = '.(int)self::SELLING_PREFERENCE_WITH_ROOM_TYPE. '
|
||||
|| p.`selling_preference_type` = '.(int)self::SELLING_PREFERENCE_WITH_HOTEL_AND_WITH_ROOM_TYPE.'
|
||||
|| p.`selling_preference_type` = '.(int)self::SELLING_PREFERENCE_WITH_HOTEL_AND_WITH_ROOM_TYPE_AND_WITH_STANDALONE.'
|
||||
|| p.`selling_preference_type` = '.(int)self::SELLING_PREFERENCE_WITH_STANDALONE_AND_WITH_ROOM_TYPE.')
|
||||
AND product_shop.`id_shop` = '.(int)$context->shop->id
|
||||
.($sub_category? ' AND product_shop.`id_category_default` = '.(int)$sub_category : '')
|
||||
.($front ? ' AND product_shop.`show_at_front` = 1':'')
|
||||
@@ -1485,7 +1509,10 @@ class ProductCore extends ObjectModel
|
||||
('.
|
||||
'(`element_type` = '.RoomTypeServiceProduct::WK_ELEMENT_TYPE_ROOM_TYPE.' AND `id_element` = '.(int)$this->id.')
|
||||
)
|
||||
AND (p.`selling_preference_type` = '.(int)self::SELLING_PREFERENCE_WITH_ROOM_TYPE. '|| p.`selling_preference_type` = '.(int)self::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE.')'. '
|
||||
AND (p.`selling_preference_type` = '.(int)self::SELLING_PREFERENCE_WITH_ROOM_TYPE. '
|
||||
|| p.`selling_preference_type` = '.(int)self::SELLING_PREFERENCE_WITH_HOTEL_AND_WITH_ROOM_TYPE.'
|
||||
|| p.`selling_preference_type` = '.(int)self::SELLING_PREFERENCE_WITH_HOTEL_AND_WITH_ROOM_TYPE_AND_WITH_STANDALONE.'
|
||||
|| p.`selling_preference_type` = '.(int)self::SELLING_PREFERENCE_WITH_STANDALONE_AND_WITH_ROOM_TYPE.')'. '
|
||||
AND product_shop.`id_shop` = '.(int)$context->shop->id
|
||||
.($sub_category? ' AND product_shop.`id_category_default` = '.(int)$sub_category : '')
|
||||
.($front ? ' AND product_shop.`show_at_front` = 1':'')
|
||||
@@ -1534,7 +1561,9 @@ class ProductCore extends ObjectModel
|
||||
'(`element_type` = '.RoomTypeServiceProduct::WK_ELEMENT_TYPE_ROOM_TYPE.' AND `id_element` = '.(int)$this->id.')
|
||||
)
|
||||
AND p.`selling_preference_type` = '.(int)self::SELLING_PREFERENCE_WITH_ROOM_TYPE.
|
||||
' || p.`selling_preference_type` = '.(int)self::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE.
|
||||
' || p.`selling_preference_type` = '.(int)self::SELLING_PREFERENCE_WITH_HOTEL_AND_WITH_ROOM_TYPE.
|
||||
' || p.`selling_preference_type` = '.(int)self::SELLING_PREFERENCE_WITH_HOTEL_AND_WITH_ROOM_TYPE_AND_WITH_STANDALONE.
|
||||
' || p.`selling_preference_type` = '.(int)self::SELLING_PREFERENCE_WITH_STANDALONE_AND_WITH_ROOM_TYPE.
|
||||
' AND product_shop.`id_shop` = '.(int)$context->shop->id;
|
||||
|
||||
$sql .= ' GROUP BY cl.`id_category`';
|
||||
@@ -3096,7 +3125,7 @@ class ProductCore extends ObjectModel
|
||||
}
|
||||
|
||||
if (!Product::isBookingProduct($id_product)
|
||||
&& (Product::getSellingPreferenceType($id_product) == Product::SELLING_PREFERENCE_STANDALONE)
|
||||
&& (Product::getSellingPreferenceType($id_product) == Product::SELLING_PREFERENCE_WITH_STANDALONE)
|
||||
&& !$id_address
|
||||
) {
|
||||
$serviceAddressPrefrenceType = Configuration::get('PS_STANDARD_PRODUCT_ORDER_ADDRESS_PREFRENCE');
|
||||
@@ -6821,11 +6850,12 @@ class ProductCore extends ObjectModel
|
||||
)
|
||||
);
|
||||
|
||||
$isPerDay = Product::getProductPriceCalculation($idProduct) == Product::PRICE_CALCULATION_METHOD_PER_DAY
|
||||
&& $dateFrom && $dateTo;
|
||||
if ($isPerDay) {
|
||||
$price = $price * HotelHelper::getNumberOfDays($dateFrom, $dateTo);
|
||||
}
|
||||
$numdays = Product::getServicePriceBillableDays(
|
||||
Product::getProductPriceCalculation($idProduct),
|
||||
$dateFrom,
|
||||
$dateTo
|
||||
);
|
||||
$price = $price * $numdays;
|
||||
|
||||
$price = $price * $quantity;
|
||||
|
||||
@@ -6870,9 +6900,118 @@ class ProductCore extends ObjectModel
|
||||
);
|
||||
}
|
||||
|
||||
if (!$specificPrice || ($specificPrice['id_cart'] == 0 && $specificPrice['id_htl_cart_booking'] == 0)) {
|
||||
if (!$idGroup || !Validate::isLoadedObject(new Group((int)$idGroup))) {
|
||||
$idGroup = (int)Group::getCurrent()->id;
|
||||
}
|
||||
$price = Product::applyGroupDiscount($price, $idProduct, $idGroup);
|
||||
}
|
||||
return $price;
|
||||
}
|
||||
|
||||
|
||||
public static function getServicePriceBillableDays(
|
||||
$priceCalculationMethod,
|
||||
$dateFrom,
|
||||
$dateTo,
|
||||
) {
|
||||
|
||||
$numNights = (int) HotelHelper::getNumberOfDays($dateFrom, $dateTo);
|
||||
if ($numNights < 1) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
$checkinDay = 1;
|
||||
$checkoutDay = 1;
|
||||
$stayDay = $numNights - 1;
|
||||
|
||||
switch ((int) $priceCalculationMethod) {
|
||||
case self::PRICE_CALCULATION_METHOD_ONCE_FOR_BOOKING:
|
||||
return 1;
|
||||
|
||||
case self::PRICE_CALCULATION_METHOD_ON_CHECKIN_DAY:
|
||||
return $checkinDay;
|
||||
|
||||
case self::PRICE_CALCULATION_METHOD_ON_CHECKOUT_DAY:
|
||||
return $checkoutDay;
|
||||
|
||||
case self::PRICE_CALCULATION_METHOD_ON_DURING_STAY:
|
||||
return $stayDay;
|
||||
|
||||
case self::PRICE_CALCULATION_METHOD_CHECKIN_DAY_AND_CHECKOUT_DAY:
|
||||
return $checkinDay + $checkoutDay;
|
||||
|
||||
case self::PRICE_CALCULATION_METHOD_CHECKIN_AND_DURING_STAY:
|
||||
return $checkinDay + $stayDay;
|
||||
|
||||
case self::PRICE_CALCULATION_METHOD_CHECKOUT_AND_DURING_STAY:
|
||||
return $checkoutDay + $stayDay;
|
||||
|
||||
case self::PRICE_CALCULATION_METHOD_CHECKIN_AND_CHECKOUT_AND_DURING_STAY:
|
||||
return $checkinDay + $checkoutDay + $stayDay;
|
||||
|
||||
default:
|
||||
return $numNights;
|
||||
}
|
||||
}
|
||||
|
||||
public static function getPriceCalculationMethodDaysLabel($priceCalculationMethod)
|
||||
{
|
||||
$priceCalculationMethod = (int) $priceCalculationMethod;
|
||||
$labels = array();
|
||||
static $module = null;
|
||||
if (is_null($module)) {
|
||||
$module = Module::getInstanceByName('hotelreservationsystem');
|
||||
}
|
||||
if ($priceCalculationMethod == self::PRICE_CALCULATION_METHOD_ONCE_FOR_BOOKING) {
|
||||
$labels[] = $module->l('Once per booking');
|
||||
|
||||
return $labels;
|
||||
}
|
||||
|
||||
if ($priceCalculationMethod & self::PRICE_CALCULATION_METHOD_ON_CHECKIN_DAY) {
|
||||
$labels[] = $module->l('Check-in day');
|
||||
}
|
||||
if ($priceCalculationMethod & self::PRICE_CALCULATION_METHOD_ON_DURING_STAY) {
|
||||
$labels[] = $module->l('During-stay days');
|
||||
}
|
||||
if ($priceCalculationMethod & self::PRICE_CALCULATION_METHOD_ON_CHECKOUT_DAY) {
|
||||
$labels[] = $module->l('Check-out day');
|
||||
}
|
||||
|
||||
return $labels;
|
||||
}
|
||||
|
||||
public static function isSellableWithRoomType($idProduct)
|
||||
{
|
||||
return in_array((int) self::getSellingPreferenceType($idProduct), [
|
||||
self::SELLING_PREFERENCE_WITH_ROOM_TYPE,
|
||||
self::SELLING_PREFERENCE_WITH_HOTEL_AND_WITH_ROOM_TYPE,
|
||||
self::SELLING_PREFERENCE_WITH_STANDALONE_AND_WITH_ROOM_TYPE,
|
||||
self::SELLING_PREFERENCE_WITH_HOTEL_AND_WITH_ROOM_TYPE_AND_WITH_STANDALONE,
|
||||
]);
|
||||
}
|
||||
|
||||
public static function isSellableWithHotel($idProduct)
|
||||
{
|
||||
return in_array((int) self::getSellingPreferenceType($idProduct), [
|
||||
self::SELLING_PREFERENCE_WITH_HOTEL,
|
||||
self::SELLING_PREFERENCE_WITH_HOTEL_AND_WITH_ROOM_TYPE,
|
||||
self::SELLING_PREFERENCE_WITH_HOTEL_AND_WITH_STANDALONE,
|
||||
self::SELLING_PREFERENCE_WITH_HOTEL_AND_WITH_ROOM_TYPE_AND_WITH_STANDALONE,
|
||||
]);
|
||||
}
|
||||
|
||||
public static function isSellableAsStandalone($idProduct)
|
||||
{
|
||||
return in_array((int) self::getSellingPreferenceType($idProduct), [
|
||||
self::SELLING_PREFERENCE_WITH_STANDALONE,
|
||||
self::SELLING_PREFERENCE_WITH_HOTEL_AND_WITH_STANDALONE,
|
||||
self::SELLING_PREFERENCE_WITH_STANDALONE_AND_WITH_ROOM_TYPE,
|
||||
self::SELLING_PREFERENCE_WITH_HOTEL_AND_WITH_ROOM_TYPE_AND_WITH_STANDALONE,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare grouped core features and values for a room type, with selection state.
|
||||
*
|
||||
|
||||
95
classes/RoomTypeSellingObject.php
Normal file
95
classes/RoomTypeSellingObject.php
Normal file
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
/**
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License version 3.0
|
||||
* that is bundled with this package in the file LICENSE.md
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/license/osl-3-0-php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to support@qloapps.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade this module to a newer
|
||||
* versions in the future. If you wish to customize this module for your needs
|
||||
* please refer to https://store.webkul.com/customisation-guidelines for more information.
|
||||
*
|
||||
* @author Webkul IN
|
||||
* @copyright Since 2010 Webkul
|
||||
* @license https://opensource.org/license/osl-3-0-php Open Software License version 3.0
|
||||
*/
|
||||
|
||||
class RoomTypeSellingObjectCore extends ObjectModel
|
||||
{
|
||||
public $active;
|
||||
public $date_add;
|
||||
public $date_upd;
|
||||
public $name;
|
||||
public $plural_name;
|
||||
|
||||
public static $definition = array(
|
||||
'table' => 'room_type_selling_object',
|
||||
'primary' => 'id_room_type_selling_object',
|
||||
'multilang' => true,
|
||||
'fields' => array(
|
||||
'active' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
|
||||
'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate', 'copy_post' => false),
|
||||
'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate', 'copy_post' => false),
|
||||
'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true),
|
||||
'plural_name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true),
|
||||
),
|
||||
);
|
||||
|
||||
public function isUsed()
|
||||
{
|
||||
return (bool) Db::getInstance()->getValue(
|
||||
'SELECT COUNT(*) FROM `'._DB_PREFIX_.'product` WHERE `id_selling_object` = '.(int) $this->id
|
||||
);
|
||||
}
|
||||
|
||||
public static function getRoomTypeSellingObjectBySellingObjectId($idSellingObject = null, $idLang = null)
|
||||
{
|
||||
if (!$idLang) {
|
||||
$idLang = Context::getContext()->language->id;
|
||||
}
|
||||
|
||||
$cache_key = 'RoomTypeSellingObject::getRoomTypeSellingObjectBySellingObjectId_'.(int)$idSellingObject.'_'.(int)$idLang;
|
||||
if (!Cache::isStored($cache_key)) {
|
||||
$sql = 'SELECT hrstl.`name`, hrstl.`plural_name`
|
||||
FROM `'._DB_PREFIX_.'room_type_selling_object` hrst
|
||||
LEFT JOIN `'._DB_PREFIX_.'room_type_selling_object_lang` hrstl
|
||||
ON (hrst.`id_room_type_selling_object` = hrstl.`id_room_type_selling_object`
|
||||
AND hrstl.`id_lang` = '.(int)$idLang.')
|
||||
WHERE hrst.`id_room_type_selling_object` = '.(int)$idSellingObject;
|
||||
$res = Db::getInstance()->getRow($sql);
|
||||
Cache::store($cache_key, $res);
|
||||
}
|
||||
|
||||
return Cache::retrieve($cache_key);
|
||||
}
|
||||
|
||||
public static function getRoomTypeSellingObjects($idLang = null, $active = true)
|
||||
{
|
||||
if (!$idLang) {
|
||||
$idLang = Context::getContext()->language->id;
|
||||
}
|
||||
|
||||
$cache_key = 'RoomTypeSellingObject::getRoomTypeSellingObjects'.(int)$idLang.'_'.(int)$active;
|
||||
if (!Cache::isStored($cache_key)) {
|
||||
$sql = 'SELECT hrst.`id_room_type_selling_object` AS `id_room_type_selling_object`, hrstl.`name`, hrstl.`plural_name`
|
||||
FROM `'._DB_PREFIX_.'room_type_selling_object` hrst
|
||||
LEFT JOIN `'._DB_PREFIX_.'room_type_selling_object_lang` hrstl
|
||||
ON (hrst.`id_room_type_selling_object` = hrstl.`id_room_type_selling_object`
|
||||
AND hrstl.`id_lang` = '.(int)$idLang.')'.
|
||||
($active ? ' WHERE hrst.`active` = 1' : '').
|
||||
' ORDER BY hrstl.`name` ASC';
|
||||
|
||||
$res = Db::getInstance()->executeS($sql);
|
||||
Cache::store($cache_key, $res);
|
||||
}
|
||||
|
||||
return Cache::retrieve($cache_key);
|
||||
}
|
||||
}
|
||||
@@ -45,6 +45,8 @@ class OrderCore extends ObjectModel
|
||||
const ORDER_COMPLETE_REFUND_FLAG = 1;
|
||||
const ORDER_COMPLETE_CANCELLATION_FLAG = 2;
|
||||
const ORDER_COMPLETE_CANCELLATION_OR_REFUND_REQUEST_FLAG = 3;
|
||||
const ORDER_COMPLETE_NOSHOW_FLAG = 4;
|
||||
|
||||
|
||||
/** @var int Delivery address id */
|
||||
public $id_address_delivery;
|
||||
@@ -1136,7 +1138,7 @@ class OrderCore extends ObjectModel
|
||||
$selling_preference_type = null,
|
||||
$product_auto_add = null,
|
||||
$product_price_addition_type = null,
|
||||
$ids_order_detail = []
|
||||
$ids_order_detail = [],
|
||||
) {
|
||||
// update
|
||||
if (!$products) {
|
||||
@@ -2555,12 +2557,11 @@ class OrderCore extends ObjectModel
|
||||
)) {
|
||||
$totals = array_reduce($serviceProductDetail, function ($carry, $item) use ($order_detail) {
|
||||
$objHotelBookingDetail = new HotelBookingDetail((int) $item['id_htl_booking_detail']);
|
||||
$numDays = 1;
|
||||
if ((Product::PRICE_CALCULATION_METHOD_PER_DAY == $order_detail['product_price_calculation_method'])
|
||||
&& (!$numDays = HotelHelper::getNumberOfDays($objHotelBookingDetail->date_from, $objHotelBookingDetail->date_to))
|
||||
) {
|
||||
$numDays = 1;
|
||||
}
|
||||
$numDays = Product::getServicePriceBillableDays(
|
||||
$order_detail['product_price_calculation_method'],
|
||||
$objHotelBookingDetail->date_from,
|
||||
$objHotelBookingDetail->date_to
|
||||
);
|
||||
|
||||
if (!empty($item['id_tax_rules_group'])) {
|
||||
$qty = isset($item['quantity']) ? $item['quantity'] : 0;
|
||||
@@ -2611,12 +2612,11 @@ 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;
|
||||
}
|
||||
$numDays = Product::getServicePriceBillableDays(
|
||||
$order_detail['product_price_calculation_method'],
|
||||
$autoAddedServiceData['date_from'],
|
||||
$autoAddedServiceData['date_to']
|
||||
);
|
||||
$autoAddedServices = $autoAddedServiceData['additional_services'];
|
||||
|
||||
// Calculate total quantity of auto-added services
|
||||
@@ -2855,18 +2855,26 @@ class OrderCore extends ObjectModel
|
||||
|
||||
// check rooms in booking
|
||||
$objHotelBooking = new HotelBookingdetail();
|
||||
if ($orderBookings = $objHotelBooking->getOrderCurrentDataByOrderId($this->id)) {
|
||||
$orderBookings = $objHotelBooking->getOrderCurrentDataByOrderId($this->id);
|
||||
|
||||
// No-show is a room-only concept — a product-only order (no rooms at all)
|
||||
// can never be "No-show", no matter how resolved its products are
|
||||
if ($action == Order::ORDER_COMPLETE_NOSHOW_FLAG && !$orderBookings) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($orderBookings) {
|
||||
$res &= $this->checkList($orderBookings, $action, $includeCheckIn);
|
||||
$hasRoomsOrProducts = 1;
|
||||
}
|
||||
// check hotel linked products
|
||||
$objServiceProductOrderDetail = new ServiceProductOrderDetail();
|
||||
if ($hotelProducts = $objServiceProductOrderDetail->getServiceProductsInOrder($this->id, 0, 0, Product::SELLING_PREFERENCE_HOTEL_STANDALONE)) {
|
||||
if ($hotelProducts = $objServiceProductOrderDetail->getServiceProductsInOrder($this->id, 0, 0, Product::SELLING_PREFERENCE_WITH_HOTEL)) {
|
||||
$res &= $this->checkList($hotelProducts, $action, false);
|
||||
$hasRoomsOrProducts = 1;
|
||||
}
|
||||
|
||||
if ($standaloneProducts = $objServiceProductOrderDetail->getServiceProductsInOrder($this->id, 0, 0, Product::SELLING_PREFERENCE_STANDALONE)) {
|
||||
if ($standaloneProducts = $objServiceProductOrderDetail->getServiceProductsInOrder($this->id, 0, 0, Product::SELLING_PREFERENCE_WITH_STANDALONE)) {
|
||||
$res &= $this->checkList($standaloneProducts, $action, false);
|
||||
$hasRoomsOrProducts = 1;
|
||||
}
|
||||
@@ -2875,9 +2883,36 @@ class OrderCore extends ObjectModel
|
||||
}
|
||||
|
||||
public function checkList($list, $action = 0, $includeCheckIn = 0) {
|
||||
// room-booking rows (from htl_booking_detail) carry id_status; service-product
|
||||
// rows (from service_product_order_detail) never do — that's a different table
|
||||
// with its own, unrelated is_refunded/is_cancelled columns, out of scope for
|
||||
// this migration (only htl_booking_detail's flags are being retired). checkList()
|
||||
// is always called with one or the other, never a mix of both (see callers in
|
||||
// hasCompletelyRefunded()), so this check only needs to happen once per call.
|
||||
$isRoomList = $list && isset($list[0]['id_status']);
|
||||
if ($isRoomList) {
|
||||
// one query for the whole list instead of one query per row
|
||||
$refundedIds = array_flip(array_column(
|
||||
Db::getInstance()->executeS(OrderReturn::getRefundedBookingIdsSubquery()),
|
||||
'id_htl_booking'
|
||||
));
|
||||
}
|
||||
|
||||
// If action is Order::ORDER_COMPLETE_REFUND_FLAG (for refunded) then we will check
|
||||
// that all rooms must be refunded and at least one booking is not cancelled
|
||||
if ($action == Order::ORDER_COMPLETE_REFUND_FLAG) {
|
||||
if ($isRoomList) {
|
||||
$hasNonCancelled = false;
|
||||
foreach ($list as $product) {
|
||||
if (!isset($refundedIds[$product['id']])) {
|
||||
return false;
|
||||
}
|
||||
if ($product['id_status'] != HotelBookingDetail::STATUS_CANCELLED) {
|
||||
$hasNonCancelled = true;
|
||||
}
|
||||
}
|
||||
return $hasNonCancelled;
|
||||
}
|
||||
$uniqueRefunded = array_unique(array_column($list, 'is_refunded'));
|
||||
if (count($uniqueRefunded) == 1 && $uniqueRefunded[0] == 1) {
|
||||
foreach ($list as $product) {
|
||||
@@ -2888,14 +2923,50 @@ class OrderCore extends ObjectModel
|
||||
}
|
||||
// If action is Order::ORDER_COMPLETE_CANCELLATION_FLAG (for cancelled) then we will check that all rooms must be cancelled
|
||||
} elseif ($action == Order::ORDER_COMPLETE_CANCELLATION_FLAG) {
|
||||
if ($isRoomList) {
|
||||
foreach ($list as $product) {
|
||||
if ($product['id_status'] != HotelBookingDetail::STATUS_CANCELLED) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
$uniqueRefunded = array_unique(array_column($list, 'is_cancelled'));
|
||||
if (count($uniqueRefunded) == 1 && $uniqueRefunded[0] == 1) {
|
||||
return true;
|
||||
}
|
||||
// If action is Order::ORDER_COMPLETE_NOSHOW_FLAG then every room must be
|
||||
// terminal (No-show or Cancelled), with at least one actually No-show —
|
||||
// No-show wins over Cancelled when an order mixes both.
|
||||
} elseif ($action == Order::ORDER_COMPLETE_NOSHOW_FLAG) {
|
||||
if (empty($list)) {
|
||||
return false;
|
||||
}
|
||||
$hasNoShow = false;
|
||||
foreach ($list as $product) {
|
||||
if (isset($product['id_status'])) {
|
||||
// room booking row
|
||||
if ($product['id_status'] != HotelBookingDetail::STATUS_NO_SHOW
|
||||
&& $product['id_status'] != HotelBookingDetail::STATUS_CANCELLED
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
if ($product['id_status'] == HotelBookingDetail::STATUS_NO_SHOW) {
|
||||
$hasNoShow = true;
|
||||
}
|
||||
} elseif (!$product['is_cancelled']) {
|
||||
// service products can't be "no-show" — just require them to
|
||||
// already be resolved, same bar as ORDER_COMPLETE_CANCELLATION_FLAG
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return $hasNoShow;
|
||||
// If action is Order::ORDER_COMPLETE_CANCELLATION_OR_REFUND_REQUEST_FLAG (for cancelled and refund requests) then we will check that all rooms are either cancelled or requested for refund
|
||||
} elseif ($action == Order::ORDER_COMPLETE_CANCELLATION_OR_REFUND_REQUEST_FLAG) {
|
||||
foreach ($list as $product) {
|
||||
if (!$product['is_refunded']) {
|
||||
$isResolved = $isRoomList ? isset($refundedIds[$product['id']]) : $product['is_refunded'];
|
||||
if (!$isResolved) {
|
||||
// If booking refund request is created and request is completed but booking is not refunded then return false
|
||||
if ($refundDetail = OrderReturn::getOrdersReturnDetail(
|
||||
$this->id,
|
||||
@@ -2916,20 +2987,35 @@ class OrderCore extends ObjectModel
|
||||
return true;
|
||||
// Default process to check if order is fully refunded or cancelled or not
|
||||
} else {
|
||||
// if is_refunded is 1 means booking either is cancelled or refunded. So check all bookings must have is_refunded = 1
|
||||
$uniqueRefunded = array_unique(array_column($list, 'is_refunded'));
|
||||
if (count($uniqueRefunded) == 1 && $uniqueRefunded[0] == 1) {
|
||||
return true;
|
||||
} elseif ($includeCheckIn) {
|
||||
if ($isRoomList) {
|
||||
$allResolved = !empty($list);
|
||||
foreach ($list as $product) {
|
||||
if ($product['is_refunded'] == 0
|
||||
&& !OrderReturn::getOrdersReturnDetail($this->id, 0, isset($product['id']) ? $product['id'] : 0)
|
||||
&& $product['id_status'] == HotelBookingDetail::STATUS_ALLOTED
|
||||
) {
|
||||
return false;
|
||||
if (!isset($refundedIds[$product['id']])) {
|
||||
$allResolved = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
if ($allResolved) {
|
||||
return true;
|
||||
} elseif ($includeCheckIn) {
|
||||
foreach ($list as $product) {
|
||||
if (!isset($refundedIds[$product['id']])
|
||||
&& !OrderReturn::getOrdersReturnDetail($this->id, 0, $product['id'])
|
||||
&& $product['id_status'] == HotelBookingDetail::STATUS_ASSIGNED
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
// if is_refunded is 1 means booking either is cancelled or refunded. So check all bookings must have is_refunded = 1
|
||||
$uniqueRefunded = array_unique(array_column($list, 'is_refunded'));
|
||||
if (count($uniqueRefunded) == 1 && $uniqueRefunded[0] == 1) {
|
||||
return true;
|
||||
}
|
||||
// note: $includeCheckIn is never true here in practice — hasCompletelyRefunded()
|
||||
// always calls checkList() with $includeCheckIn=false for product lists
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2938,9 +3024,23 @@ class OrderCore extends ObjectModel
|
||||
|
||||
public function getOrderCompleteRefundStatus()
|
||||
{
|
||||
$objHotelBooking = new HotelBookingdetail();
|
||||
foreach ($objHotelBooking->getOrderCurrentDataByOrderId($this->id) as $booking) {
|
||||
if ($booking['id_status'] != HotelBookingDetail::STATUS_CANCELLED
|
||||
&& $booking['id_status'] != HotelBookingDetail::STATUS_NO_SHOW
|
||||
) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
// any completed refund anywhere in the order takes priority over
|
||||
// No-show/Cancelled and is sticky (a refund never un-completes)
|
||||
if ((new OrderReturn())->getRefundedAmount($this->id) > 0) {
|
||||
return Configuration::get('PS_OS_REFUND');
|
||||
}
|
||||
|
||||
$idOrderState = 0;
|
||||
if ($this->hasCompletelyRefunded(Order::ORDER_COMPLETE_REFUND_FLAG)) {
|
||||
$idOrderState = Configuration::get('PS_OS_REFUND');
|
||||
if ($this->hasCompletelyRefunded(Order::ORDER_COMPLETE_NOSHOW_FLAG)) {
|
||||
$idOrderState = Configuration::get('PS_OS_NO_SHOW');
|
||||
} elseif ($this->hasCompletelyRefunded(Order::ORDER_COMPLETE_CANCELLATION_FLAG)) {
|
||||
$idOrderState = Configuration::get('PS_OS_CANCELED');
|
||||
} elseif ($this->hasCompletelyRefunded()) {
|
||||
@@ -2950,6 +3050,30 @@ class OrderCore extends ObjectModel
|
||||
return $idOrderState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bump the order's own status to match getOrderCompleteRefundStatus(),
|
||||
* if it needs to change — the single place every caller that used to
|
||||
* repeat this same 6-line block now goes through, so the "already at
|
||||
* this state, don't re-bump" guard applies everywhere, not just one caller.
|
||||
*
|
||||
* @param bool $useEmail whether to email the customer about the change
|
||||
* @return bool whether the order status was actually changed
|
||||
*/
|
||||
public function syncRefundStatus($useEmail = true)
|
||||
{
|
||||
$idOrderState = $this->getOrderCompleteRefundStatus();
|
||||
if (!$idOrderState || $idOrderState == $this->current_state) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$objOrderHistory = new OrderHistory();
|
||||
$objOrderHistory->id_order = (int) $this->id;
|
||||
$objOrderHistory->changeIdOrderState($idOrderState, $this, !$this->hasInvoice());
|
||||
$useEmail ? $objOrderHistory->addWithemail() : $objOrderHistory->add();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getWsBookings()
|
||||
{
|
||||
return Db::getInstance()->executeS(
|
||||
@@ -2990,26 +3114,23 @@ class OrderCore extends ObjectModel
|
||||
if (!$objHotelBooking->getOverbookedRooms($this->id)) {
|
||||
$result['errors'][] = Tools::displayError('Order status can not be changed to any overbooking status as there are no overbooked rooms in the order.');
|
||||
}
|
||||
} elseif ($objNewOrderState->id == Configuration::get('PS_OS_REFUND')
|
||||
&& !$this->hasCompletelyRefunded(Order::ORDER_COMPLETE_REFUND_FLAG)
|
||||
) {
|
||||
$result['errors'][] = Tools::displayError('Order status can not be set to Refunded until all bookings in the order are completely refunded.');
|
||||
} elseif ($objNewOrderState->id == Configuration::get('PS_OS_CANCELED')
|
||||
&& !$this->hasCompletelyRefunded(Order::ORDER_COMPLETE_CANCELLATION_FLAG, 0, 1)
|
||||
) {
|
||||
$result['errors'][] = Tools::displayError('Order status can not be set to Cancelled until all bookings in the order are cancelled.');
|
||||
} elseif (in_array($objNewOrderState->id, array(
|
||||
Configuration::get('PS_OS_REFUND'),
|
||||
Configuration::get('PS_OS_CANCELED'),
|
||||
Configuration::get('PS_OS_NO_SHOW'),
|
||||
))) {
|
||||
// Refunded/Cancelled/No-show are never a direct manual pick — they're
|
||||
// only ever reached automatically, via Order::syncRefundStatus(), when
|
||||
// a refund completes or a room's status changes to Cancelled/No-show.
|
||||
$result['errors'][] = Tools::displayError('Order status cannot be changed directly to Refunded, Cancelled, or No-show — it is set automatically based on the booking/refund status.');
|
||||
} elseif ($objCurrentOrderState->id == Configuration::get('PS_OS_ERROR') && !($objNewOrderState->id == Configuration::get('PS_OS_ERROR'))) {
|
||||
// All rooms must be available before changing status from Payment Error to Other status in which rooms are getting blocked again
|
||||
if ($orderBookings = $objHotelBooking->getOrderCurrentDataByOrderId($this->id)) {
|
||||
$objOrderReturn = new OrderReturn();
|
||||
foreach ($orderBookings as $orderBooking) {
|
||||
// If booking is refunded then no need to check inventory
|
||||
if ($bookingRefundDetail = OrderReturn::getOrdersReturnDetail($this->id, 0, $orderBooking['id'])) {
|
||||
$bookingRefundDetail = reset($bookingRefundDetail);
|
||||
}
|
||||
|
||||
// $bookingRefundDetail['id_customization'] is 1 for only refunded request completed and refunded bookings
|
||||
if (($bookingRefundDetail && $bookingRefundDetail['refunded'] && $orderBooking['is_refunded'] && $bookingRefundDetail['id_customization'])
|
||||
|| ($orderBooking['is_cancelled'] && $orderBooking['is_refunded'])
|
||||
// If booking is refunded (or cancelled) then no need to check inventory
|
||||
if ($objOrderReturn->hasCompletelyRefundedBooking($orderBooking['id'])
|
||||
|| $orderBooking['id_status'] == HotelBookingDetail::STATUS_CANCELLED
|
||||
) {
|
||||
continue;
|
||||
} else {
|
||||
@@ -3022,7 +3143,6 @@ class OrderCore extends ObjectModel
|
||||
'only_search_data' => 1
|
||||
);
|
||||
|
||||
$objHotelBookingDetail = new HotelBookingDetail($orderBooking['id']);
|
||||
if ($searchRoomsInfo = $objHotelBooking->getBookingData($bookingParams)) {
|
||||
if (isset($searchRoomsInfo['rm_data'][$orderBooking['id_product']]['data']['available'])
|
||||
&& $searchRoomsInfo['rm_data'][$orderBooking['id_product']]['data']['available']
|
||||
@@ -3034,9 +3154,6 @@ class OrderCore extends ObjectModel
|
||||
$result['errors'][] = Tools::displayError('You can not change the order status as some rooms are not available now in this order. You can reallocate/swap rooms with other rooms to make rooms available and then change the order status.');
|
||||
|
||||
break;
|
||||
} else {
|
||||
$objHotelBookingDetail->is_refunded = 0;
|
||||
$objHotelBookingDetail->save();
|
||||
}
|
||||
} else {
|
||||
$result['errors'][] = Tools::displayError('You can not change the order status as some rooms are not available now in this order. You can reallocate/swap rooms with other rooms to make rooms available and then change the order status.');
|
||||
@@ -3144,4 +3261,138 @@ class OrderCore extends ObjectModel
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ── REPORT METHODS ────────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Orders with unpaid balance for the outstanding-payments report.
|
||||
*
|
||||
* @param array $params date_from, date_to, id_hotel, id_order
|
||||
* @return array
|
||||
*/
|
||||
public static function getOutstandingBalance(array $params)
|
||||
{
|
||||
$dateFrom = pSQL($params['date_from']);
|
||||
$dateTo = pSQL(isset($params['date_to']) ? $params['date_to'] : $params['date_from']);
|
||||
$idsHotel = isset($params['ids_hotel']) ? $params['ids_hotel'] : (isset($params['id_hotel']) ? $params['id_hotel'] : false);
|
||||
$idOrder = isset($params['id_order']) ? (int) $params['id_order'] : 0;
|
||||
|
||||
$hotelFilter = HotelBranchInformation::addHotelRestriction($idsHotel, 'hbd');
|
||||
$hotelExists = $hotelFilter
|
||||
? ' AND EXISTS (SELECT 1 FROM `'._DB_PREFIX_.'htl_booking_detail` hbd WHERE hbd.`id_order` = o.`id_order`'.$hotelFilter.')'
|
||||
: '';
|
||||
|
||||
return Db::getInstance()->executeS(
|
||||
'SELECT o.`id_order`, o.`reference`, o.`id_customer`,
|
||||
CONCAT(c.`firstname`, " ", c.`lastname`) AS customer_name,
|
||||
c.`email`, a.`phone`,
|
||||
o.`total_paid_tax_incl` / o.`conversion_rate` AS total_charges,
|
||||
IFNULL((
|
||||
SELECT SUM(op.`amount`)
|
||||
FROM `'._DB_PREFIX_.'order_payment` op
|
||||
WHERE op.`order_reference` = o.`reference`
|
||||
), 0) / o.`conversion_rate` AS total_paid,
|
||||
(o.`total_paid_tax_incl` - IFNULL((
|
||||
SELECT SUM(op.`amount`)
|
||||
FROM `'._DB_PREFIX_.'order_payment` op
|
||||
WHERE op.`order_reference` = o.`reference`
|
||||
), 0)) / o.`conversion_rate` AS balance_due,
|
||||
(
|
||||
SELECT MAX(op.`date_add`)
|
||||
FROM `'._DB_PREFIX_.'order_payment` op
|
||||
WHERE op.`order_reference` = o.`reference`
|
||||
) AS last_payment_date
|
||||
FROM `'._DB_PREFIX_.'orders` o
|
||||
INNER JOIN `'._DB_PREFIX_.'customer` c ON (c.`id_customer` = o.`id_customer`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'address` a ON (a.`id_address` = o.`id_address_invoice`)
|
||||
WHERE o.`valid` = 1
|
||||
AND o.`date_add` BETWEEN "'.$dateFrom.' 00:00:00" AND "'.$dateTo.' 23:59:59"'
|
||||
.($idOrder ? ' AND o.`id_order` = '.$idOrder : '')
|
||||
.$hotelExists.'
|
||||
HAVING balance_due > 0.01
|
||||
ORDER BY balance_due DESC'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Total order-level discounts applied to hotel orders in the date range.
|
||||
* Returns positive number representing the discount amount.
|
||||
*
|
||||
* @param array $params date_from, date_to, id_hotel, id_customer
|
||||
* @return float
|
||||
*/
|
||||
public static function getTotalDiscounts(array $params)
|
||||
{
|
||||
$dateFrom = pSQL($params['date_from']);
|
||||
$dateTo = pSQL(isset($params['date_to']) ? $params['date_to'] : $params['date_from']);
|
||||
$idsHotel = isset($params['ids_hotel']) ? $params['ids_hotel'] : (isset($params['id_hotel']) ? $params['id_hotel'] : false);
|
||||
$idCustomer = isset($params['id_customer']) ? (int) $params['id_customer'] : 0;
|
||||
|
||||
$hotelExists = ' AND EXISTS (
|
||||
SELECT 1 FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
|
||||
WHERE hbd.`id_order` = o.`id_order`'
|
||||
.HotelBranchInformation::addHotelRestriction($idsHotel, 'hbd')
|
||||
.')';
|
||||
|
||||
return (float) Db::getInstance()->getValue(
|
||||
'SELECT IFNULL(SUM(o.`total_discounts_tax_excl` / o.`conversion_rate`), 0)
|
||||
FROM `'._DB_PREFIX_.'orders` o
|
||||
WHERE o.`valid` = 1
|
||||
AND o.`date_add` BETWEEN "'.$dateFrom.' 00:00:00" AND "'.$dateTo.' 23:59:59"'
|
||||
.($idCustomer ? ' AND o.`id_customer` = '.$idCustomer : '')
|
||||
.$hotelExists
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Guest directory — one row per customer with lifetime stay stats and contact info.
|
||||
* Date range (if given) filters by stay overlap (HAVING).
|
||||
*
|
||||
* @param array $params date_from, date_to, id_hotel, id_product, id_lang
|
||||
* @return array
|
||||
*/
|
||||
public static function getGuestDirectory(array $params)
|
||||
{
|
||||
$dateFrom = isset($params['date_from']) ? pSQL($params['date_from']) : '';
|
||||
$dateTo = isset($params['date_to']) ? pSQL($params['date_to']) : '';
|
||||
$idsHotel = isset($params['ids_hotel']) ? $params['ids_hotel'] : (isset($params['id_hotel']) ? $params['id_hotel'] : false);
|
||||
$idProduct = isset($params['id_product']) ? (int) $params['id_product'] : 0;
|
||||
$idLang = isset($params['id_lang']) ? (int) $params['id_lang'] : 0;
|
||||
if (!$idLang) {
|
||||
$idLang = Context::getContext()->language->id;
|
||||
}
|
||||
|
||||
return Db::getInstance()->executeS(
|
||||
'SELECT c.`id_customer`,
|
||||
CONCAT(c.`firstname`, " ", c.`lastname`) AS customer_name,
|
||||
c.`email`,
|
||||
c.`phone`, a.`address1`, a.`address2`, a.`city`, a.`postcode`, a.`vat_number`, a.`company`,
|
||||
cl.`name` AS country,
|
||||
st.`name` AS state,
|
||||
COUNT(DISTINCT o.`id_order`) AS total_stays,
|
||||
SUM(DATEDIFF(hbd.`date_to`, hbd.`date_from`)) AS total_nights,
|
||||
IFNULL(SUM(hbd.`total_price_tax_incl` / o.`conversion_rate`), 0) AS lifetime_revenue,
|
||||
IFNULL(SUM(hbd.`total_price_tax_incl` / o.`conversion_rate`) / NULLIF(COUNT(DISTINCT o.`id_order`), 0), 0) AS avg_spend_per_stay,
|
||||
MAX(hbd.`date_from`) AS last_stay
|
||||
FROM `'._DB_PREFIX_.'orders` o
|
||||
INNER JOIN `'._DB_PREFIX_.'customer` c ON (c.`id_customer` = o.`id_customer`)
|
||||
INNER JOIN `'._DB_PREFIX_.'htl_booking_detail` hbd
|
||||
ON (hbd.`id_order` = o.`id_order` AND hbd.`is_cancelled` = 0 AND hbd.`is_refunded` = 0)
|
||||
LEFT JOIN `'._DB_PREFIX_.'address` a
|
||||
ON (a.`id_customer` = c.`id_customer` AND a.`deleted` = 0
|
||||
AND a.`id_address` = (SELECT MAX(`id_address`) FROM `'._DB_PREFIX_.'address`
|
||||
WHERE `id_customer` = c.`id_customer` AND `deleted` = 0))
|
||||
LEFT JOIN `'._DB_PREFIX_.'country_lang` cl
|
||||
ON (cl.`id_country` = a.`id_country` AND cl.`id_lang` = '.(int) $idLang.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'state` st ON (st.`id_state` = a.`id_state`)
|
||||
WHERE o.`valid` = 1'
|
||||
.($idProduct ? ' AND hbd.`id_product` = '.$idProduct : '')
|
||||
.HotelBranchInformation::addHotelRestriction($idsHotel, 'hbd').'
|
||||
GROUP BY c.`id_customer`'
|
||||
.($dateFrom && $dateTo
|
||||
? ' HAVING MAX(IF(hbd.`date_from` <= "'.$dateTo.'" AND hbd.`date_to` > "'.$dateFrom.'", 1, 0)) = 1'
|
||||
: '').'
|
||||
ORDER BY total_stays DESC, lifetime_revenue DESC'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -465,10 +465,11 @@ class OrderDetailCore extends ObjectModel
|
||||
$totalPriceTaxExcl = 0.0;
|
||||
$firstServiceProduct = null;
|
||||
foreach ($serviceProductData as $bookingServiceData) {
|
||||
$bookingNumDays = 1;
|
||||
if (Product::PRICE_CALCULATION_METHOD_PER_DAY == $this->product_price_calculation_method) {
|
||||
$bookingNumDays = HotelHelper::getNumberOfDays($bookingServiceData['date_from'], $bookingServiceData['date_to']) ?: 1;
|
||||
}
|
||||
$bookingNumDays = Product::getServicePriceBillableDays(
|
||||
$this->product_price_calculation_method,
|
||||
$bookingServiceData['date_from'],
|
||||
$bookingServiceData['date_to']
|
||||
);
|
||||
foreach ($bookingServiceData['additional_services'] as $item) {
|
||||
$itemQuantity = (isset($item['quantity']) ? $item['quantity'] : 0) * $bookingNumDays;
|
||||
$quantity += $itemQuantity;
|
||||
@@ -498,10 +499,11 @@ class OrderDetailCore extends ObjectModel
|
||||
$quantity = 0;
|
||||
$totalPriceTaxExcl = 0.0;
|
||||
foreach ($serviceProductData as $cartServiceItem) {
|
||||
$itemNumDays = 1;
|
||||
if (Product::PRICE_CALCULATION_METHOD_PER_DAY == $this->product_price_calculation_method) {
|
||||
$itemNumDays = HotelHelper::getNumberOfDays($cartServiceItem['date_from'], $cartServiceItem['date_to']) ?: 1;
|
||||
}
|
||||
$itemNumDays = Product::getServicePriceBillableDays(
|
||||
$this->product_price_calculation_method,
|
||||
$cartServiceItem['date_from'],
|
||||
$cartServiceItem['date_to']
|
||||
);
|
||||
$itemQuantity = (isset($cartServiceItem['quantity']) ? $cartServiceItem['quantity'] : 0) * $itemNumDays;
|
||||
$quantity += $itemQuantity;
|
||||
$totalPriceTaxExcl += $itemQuantity * (isset($cartServiceItem['unit_price_tax_excl']) ? $cartServiceItem['unit_price_tax_excl'] : 0);
|
||||
|
||||
@@ -505,7 +505,8 @@ class OrderInvoiceCore extends ObjectModel
|
||||
$order_detail = array_filter($order_detail, function($v) {
|
||||
return (!$v['is_booking_product'] && !$v['product_auto_add'] && $v['selling_preference_type'] == Product::SELLING_PREFERENCE_WITH_ROOM_TYPE);
|
||||
});
|
||||
$details = $order->getProductTaxesDetails($order_detail, false, Product::SELLING_PREFERENCE_WITH_ROOM_TYPE);
|
||||
|
||||
$details = $order->getProductTaxesDetails($order_detail, false,Product::SELLING_PREFERENCE_WITH_ROOM_TYPE);
|
||||
|
||||
if ($sum_composite_taxes) {
|
||||
$grouped_details = array();
|
||||
@@ -634,10 +635,11 @@ class OrderInvoiceCore extends ObjectModel
|
||||
$order_detail = $this->getProducts();
|
||||
$order_detail = array_filter($order_detail, function($v) {
|
||||
return (!$v['is_booking_product'] && (
|
||||
$v['selling_preference_type'] == Product::SELLING_PREFERENCE_STANDALONE
|
||||
|| $v['selling_preference_type'] == Product::SELLING_PREFERENCE_HOTEL_STANDALONE
|
||||
$v['selling_preference_type'] == Product::SELLING_PREFERENCE_WITH_STANDALONE
|
||||
|| $v['selling_preference_type'] == Product::SELLING_PREFERENCE_WITH_HOTEL
|
||||
));
|
||||
});
|
||||
|
||||
|
||||
$details = $order->getProductTaxesDetails($order_detail, false);
|
||||
|
||||
|
||||
@@ -160,4 +160,63 @@ class OrderPaymentCore extends ObjectModel
|
||||
return Db::getInstance()->getValue('SELECT (SUM(`amount` * `conversion_rate`) / SUM(`amount`)) FROM `'._DB_PREFIX_.'order_payment` WHERE `order_reference` = \''.pSQL($order_reference).'\' AND `id_currency` = '.(int)$idCurrency);
|
||||
}
|
||||
|
||||
// ── REPORT METHODS ────────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Payment detail rows for the payment report.
|
||||
*
|
||||
* @param array $params date_from, date_to, id_hotel, id_order, id_customer, payment_method
|
||||
* @return array
|
||||
*/
|
||||
public static function getPaymentsInfo(array $params)
|
||||
{
|
||||
$dateFrom = pSQL($params['date_from']);
|
||||
$dateTo = pSQL(isset($params['date_to']) ? $params['date_to'] : $params['date_from']);
|
||||
$idHotel = isset($params['id_hotel']) ? $params['id_hotel'] : false;
|
||||
$idOrder = isset($params['id_order']) ? (int) $params['id_order'] : 0;
|
||||
$idCustomer = isset($params['id_customer']) ? (int) $params['id_customer'] : 0;
|
||||
$paymentMethod = isset($params['payment_method']) ? pSQL($params['payment_method']) : '';
|
||||
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(
|
||||
'SELECT op.`id_order_payment`, op.`date_add`, o.`id_order`, o.`id_customer`,
|
||||
op.`order_reference` AS reference,
|
||||
CONCAT(c.`firstname`, " ", c.`lastname`) AS customer_name,
|
||||
op.`payment_method`, op.`payment_type`, op.`amount`, op.`conversion_rate`,
|
||||
op.`transaction_id`, op.`id_currency`, cur.`iso_code` AS currency_iso, cur.`sign` AS currency_sign
|
||||
FROM `'._DB_PREFIX_.'order_payment` op
|
||||
INNER JOIN `'._DB_PREFIX_.'orders` o ON (o.`reference` = op.`order_reference` AND o.`valid` = 1)
|
||||
INNER JOIN `'._DB_PREFIX_.'customer` c ON (c.`id_customer` = o.`id_customer`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'currency` cur ON (cur.`id_currency` = op.`id_currency`)
|
||||
INNER JOIN `'._DB_PREFIX_.'htl_booking_detail` hbd
|
||||
ON (hbd.`id_order` = o.`id_order` AND hbd.`is_cancelled` = 0)
|
||||
WHERE op.`date_add` BETWEEN "'.$dateFrom.' 00:00:00" AND "'.$dateTo.' 23:59:59"'
|
||||
.($idOrder ? ' AND o.`id_order` = '.$idOrder : '')
|
||||
.($idCustomer ? ' AND o.`id_customer` = '.$idCustomer : '')
|
||||
.($paymentMethod ? ' AND op.`payment_method` = "'.$paymentMethod.'"' : '')
|
||||
.HotelBranchInformation::addHotelRestriction($idHotel, 'hbd').'
|
||||
GROUP BY op.`id_order_payment`
|
||||
ORDER BY op.`date_add` DESC'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Distinct payment methods used in hotel orders.
|
||||
*
|
||||
* @param int|false $idHotel
|
||||
* @return array rows: payment_method
|
||||
*/
|
||||
public static function getDistinctPaymentMethods($idHotel = false)
|
||||
{
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(
|
||||
'SELECT DISTINCT op.`payment_method`
|
||||
FROM `'._DB_PREFIX_.'order_payment` op
|
||||
INNER JOIN `'._DB_PREFIX_.'orders` o
|
||||
ON (o.`reference` = op.`order_reference` AND o.`valid` = 1)
|
||||
INNER JOIN `'._DB_PREFIX_.'htl_booking_detail` hbd
|
||||
ON (hbd.`id_order` = o.`id_order` AND hbd.`is_cancelled` = 0)
|
||||
WHERE op.`payment_method` IS NOT NULL AND op.`payment_method` != ""'
|
||||
.HotelBranchInformation::addHotelRestriction($idHotel, 'hbd').'
|
||||
ORDER BY op.`payment_method`'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,6 +57,9 @@ class OrderReturnCore extends ObjectModel
|
||||
/** @var int whether $id_return_type is cart_rule or order_slip */
|
||||
public $return_type;
|
||||
|
||||
/** @var int why this refund request exists: EVENT_TYPE_CANCELLATION/_NO_SHOW/_REFUND */
|
||||
public $event_type;
|
||||
|
||||
/** @var string Object creation date */
|
||||
public $date_add;
|
||||
|
||||
@@ -67,6 +70,11 @@ class OrderReturnCore extends ObjectModel
|
||||
const RETURN_TYPE_CART_RULE = 1;
|
||||
const RETURN_TYPE_ORDER_SLIP = 2;
|
||||
|
||||
/** possible values for $event_type */
|
||||
const EVENT_TYPE_CANCELLATION = 1;
|
||||
const EVENT_TYPE_NO_SHOW = 2;
|
||||
const EVENT_TYPE_REFUND = 3;
|
||||
|
||||
/**
|
||||
* @see ObjectModel::$definition
|
||||
*/
|
||||
@@ -84,6 +92,7 @@ class OrderReturnCore extends ObjectModel
|
||||
'by_admin' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
|
||||
'id_return_type' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
|
||||
'return_type' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
|
||||
'event_type' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
|
||||
'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
|
||||
'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
|
||||
),
|
||||
@@ -177,16 +186,45 @@ class OrderReturnCore extends ObjectModel
|
||||
return (int)($data['total']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Subquery fragment: every id_htl_booking with at least one completed (actually
|
||||
* refunded) return — the replacement for reading htl_booking_detail.is_refunded,
|
||||
* which was only ever set true by processRefundInBookingTables() at this exact
|
||||
* same moment. Used as `id NOT IN (...)` / `id IN (...)` in other queries, since
|
||||
* this exact fragment is needed at many call sites across the codebase.
|
||||
*
|
||||
* @return string raw SQL, not a full query
|
||||
*/
|
||||
public static function getRefundedBookingIdsSubquery($eventType = null)
|
||||
{
|
||||
return 'SELECT ord.`id_htl_booking` FROM `'._DB_PREFIX_.'order_return_detail` ord
|
||||
INNER JOIN `'._DB_PREFIX_.'order_return` orr ON orr.`id_order_return` = ord.`id_order_return`
|
||||
INNER JOIN `'._DB_PREFIX_.'order_return_state` ors ON ors.`id_order_return_state` = orr.`state`
|
||||
WHERE ors.`refunded` = 1'.(!is_null($eventType) ? ' AND orr.`event_type` = '.(int) $eventType : '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this one room booking has at least one completed (actually refunded) return.
|
||||
*
|
||||
* @param int $idHtlBooking
|
||||
* @return bool
|
||||
*/
|
||||
public function hasCompletelyRefundedBooking($idHtlBooking)
|
||||
{
|
||||
return (bool) Db::getInstance()->getValue(
|
||||
'SELECT '.(int) $idHtlBooking.' IN ('.self::getRefundedBookingIdsSubquery().')'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get order refund requested bookings
|
||||
* @param integer $idOrder
|
||||
* @param integer $idOrderReturn
|
||||
* @param integer $onlyBookingIds
|
||||
* @param integer $customerView
|
||||
* @param integer $skipReqCompletedNonRefunded: send 1 if you want to skip refund request completed but non-refunded booking
|
||||
* @return array of refund requested bookings
|
||||
*/
|
||||
public function getOrderRefundRequestedBookings($idOrder, $idOrderReturn = 0, $onlyBookingIds = 0, $customerView = 0, $skipReqCompletedNonRefunded = 0)
|
||||
public function getOrderRefundRequestedBookings($idOrder, $idOrderReturn = 0, $onlyBookingIds = 0, $customerView = 0)
|
||||
{
|
||||
$sql = 'SELECT hbd.*, ord.*, orr.`state` as id_return_state FROM `'._DB_PREFIX_.'order_return` orr';
|
||||
$sql .= ' INNER JOIN `'._DB_PREFIX_.'order_return_detail` ord ON (orr.`id_order_return` = ord.`id_order_return`)';
|
||||
@@ -214,14 +252,6 @@ class OrderReturnCore extends ObjectModel
|
||||
$appliedServiceTourismTaxByBooking = OrderTaxDetail::getAppliedTourismTaxTotals($idOrder, OrderTaxDetail::SCOPE_SERVICE);
|
||||
|
||||
foreach ($returnDetails as $key => &$bookingRow) {
|
||||
if ($skipReqCompletedNonRefunded) {
|
||||
$objReturnState = new OrderReturnState($bookingRow['id_return_state']);
|
||||
if ($objReturnState->refunded && !$bookingRow['is_refunded']) {
|
||||
unset($returnDetails[$key]);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$onlyBookingIds) {
|
||||
$bookingRow['extra_service_total_paid_amount'] = 0;
|
||||
$bookingRow['extra_service_total_price_tax_incl'] = 0;
|
||||
@@ -295,7 +325,7 @@ class OrderReturnCore extends ObjectModel
|
||||
}
|
||||
|
||||
if ($onlyBookingIds) {
|
||||
return array_column($returnDetails, 'id_htl_booking');
|
||||
return array_values(array_unique(array_column($returnDetails, 'id_htl_booking')));
|
||||
}
|
||||
|
||||
if ($customerView) {
|
||||
@@ -309,7 +339,7 @@ class OrderReturnCore extends ObjectModel
|
||||
/**
|
||||
* Get order refund request products
|
||||
*/
|
||||
public function getOrderRefundRequestedProducts($idOrder, $idOrderReturn = 0, $onlyIds = 0, $skipReqCompletedNonRefunded = 0)
|
||||
public function getOrderRefundRequestedProducts($idOrder, $idOrderReturn = 0, $onlyIds = 0)
|
||||
{
|
||||
$sql = 'SELECT spod.*, ord.*, orr.`state` as id_return_state, p.`allow_multiple_quantity` FROM `'._DB_PREFIX_.'order_return` orr';
|
||||
$sql .= ' INNER JOIN `'._DB_PREFIX_.'order_return_detail` ord ON (orr.`id_order_return` = ord.`id_order_return`)';
|
||||
@@ -323,14 +353,6 @@ class OrderReturnCore extends ObjectModel
|
||||
if ($returnDetails = Db::getInstance()->executeS($sql)) {
|
||||
$objOrder = new Order($idOrder);
|
||||
foreach ($returnDetails as $key => &$product) {
|
||||
if ($skipReqCompletedNonRefunded) {
|
||||
$objReturnState = new OrderReturnState($product['id_return_state']);
|
||||
if ($objReturnState->refunded && !$product['is_refunded']) {
|
||||
unset($returnDetails[$key]);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$product['paid_amount'] = 0;
|
||||
if ($product['total_price_tax_incl'] > 0) {
|
||||
if ($objOrder->total_paid_real > 0) {
|
||||
@@ -354,7 +376,7 @@ class OrderReturnCore extends ObjectModel
|
||||
}
|
||||
$sql = 'SELECT orr.`id_order`, orr.`state`, orr.`id_order_return`, orr.`payment_mode`, orr.`id_transaction`,
|
||||
orr.`id_return_type`, orr.`return_type`, ors.`id_cart_rule`, orr.`date_add`, orr.`date_upd`, orr.`refunded_amount`,
|
||||
hbd.`is_cancelled`, SUM(IF(ord.`id_htl_booking`, 1, 0)) AS total_rooms, SUM(IF(ord.`id_service_product_order_detail`, 1, 0)) AS total_products
|
||||
IF(hbd.`id_status` = '.HotelBookingDetail::STATUS_CANCELLED.', 1, 0) AS `is_cancelled`, SUM(IF(ord.`id_htl_booking`, 1, 0)) AS total_rooms, SUM(IF(ord.`id_service_product_order_detail`, 1, 0)) AS total_products
|
||||
FROM `'._DB_PREFIX_.'order_return` orr
|
||||
LEFT JOIN `'._DB_PREFIX_.'order_return_detail` ord
|
||||
ON (ord.`id_order_return` = orr.`id_order_return`)
|
||||
@@ -756,20 +778,40 @@ class OrderReturnCore extends ObjectModel
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getRefundedAmount($idOrder, $idOrderReturn = 0, $idHtlBooking = 0)
|
||||
/**
|
||||
* @param int $idOrder
|
||||
* @param int $idOrderReturn
|
||||
* @param int $idHtlBooking
|
||||
* @param bool $detailedInfo when true, also returns the number of refund
|
||||
* requests (not just the refunded amount) — e.g. for the order
|
||||
* detail page's per-room "Refund" column
|
||||
* @return float|array plain refunded amount by default; array('amount', 'count') when $detailedInfo
|
||||
*/
|
||||
public function getRefundedAmount($idOrder, $idOrderReturn = 0, $idHtlBooking = 0, $detailedInfo = false, $idServiceProductOrderDetail = 0)
|
||||
{
|
||||
$sql = 'SELECT SUM(ord.`refunded_amount`) FROM `'._DB_PREFIX_.'order_return_detail` ord';
|
||||
$sql .= ' LEFT JOIN `'._DB_PREFIX_.'order_return` orr ON (orr.`id_order_return` = ord.`id_order_return`)';
|
||||
$sql .= ' WHERE orr.`id_order` = '.(int)$idOrder;
|
||||
$where = ' WHERE orr.`id_order` = '.(int) $idOrder;
|
||||
|
||||
if ($idOrderReturn) {
|
||||
$sql .= ' AND ord.`id_order_return` = '.(int)$idOrderReturn;
|
||||
$where .= ' AND ord.`id_order_return` = '.(int) $idOrderReturn;
|
||||
}
|
||||
|
||||
if ($idHtlBooking) {
|
||||
$sql .= ' AND ord.`id_htl_booking` = '.(int)$idHtlBooking;
|
||||
$where .= ' AND ord.`id_htl_booking` = '.(int) $idHtlBooking;
|
||||
}
|
||||
|
||||
if ($idServiceProductOrderDetail) {
|
||||
$where .= ' AND ord.`id_service_product_order_detail` = '.(int) $idServiceProductOrderDetail;
|
||||
}
|
||||
|
||||
$from = ' FROM `'._DB_PREFIX_.'order_return_detail` ord
|
||||
LEFT JOIN `'._DB_PREFIX_.'order_return` orr ON (orr.`id_order_return` = ord.`id_order_return`)';
|
||||
|
||||
if ($detailedInfo) {
|
||||
$sql = 'SELECT COUNT(ord.`id_order_return_detail`) AS count, SUM(ord.`refunded_amount`) AS amount'.$from.$where;
|
||||
return Db::getInstance()->getRow($sql);
|
||||
}
|
||||
|
||||
$sql = 'SELECT SUM(ord.`refunded_amount`) AS amount'.$from.$where;
|
||||
return Db::getInstance()->getValue($sql);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,12 +77,17 @@ class OrderReturnDetailCore extends ObjectModel
|
||||
|
||||
public static function deleteReturnDetailByIdBookingDetail($idOrder, $idHtlBooking)
|
||||
{
|
||||
if (Validate::isLoadedObject($objOrderReturnDetail = OrderReturnDetail::getReturnDetailByIdBookingDetail($idHtlBooking))) {
|
||||
if ($objOrderReturnDetail->delete()) {
|
||||
$objOrderReturn = new OrderReturn();
|
||||
if (empty($objOrderReturn->getOrderRefundRequestedBookings($idOrder, $objOrderReturnDetail->id_order_return, true))) {
|
||||
$objOrderReturn = new OrderReturn($objOrderReturnDetail->id_order_return);
|
||||
$objOrderReturn->delete();
|
||||
$orderReturnDetails = OrderReturn::getOrdersReturnDetail($idOrder, 0, $idHtlBooking);
|
||||
|
||||
if ($orderReturnDetails) {
|
||||
foreach ($orderReturnDetails as $row) {
|
||||
$objOrderReturnDetail = new OrderReturnDetail((int) $row['id_order_return_detail']);
|
||||
if (Validate::isLoadedObject($objOrderReturnDetail) && $objOrderReturnDetail->delete()) {
|
||||
$objOrderReturn = new OrderReturn();
|
||||
if (empty($objOrderReturn->getOrderRefundRequestedBookings($idOrder, $objOrderReturnDetail->id_order_return, true))) {
|
||||
$objOrderReturn = new OrderReturn($objOrderReturnDetail->id_order_return);
|
||||
$objOrderReturn->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -468,6 +468,12 @@ class OrderSlipCore extends ObjectModel
|
||||
}
|
||||
|
||||
foreach ($product_list as $productRow) {
|
||||
// rows the loop above skipped (nothing left to credit — see the
|
||||
// $quantity == 0 continue) never got unit_price_tax_excl/incl and
|
||||
// total_price_tax_excl/incl set, so they must be skipped here too
|
||||
if (!isset($productRow['unit_price_tax_excl'])) {
|
||||
continue;
|
||||
}
|
||||
$order_slip->addProductOrderSlip($productRow);
|
||||
}
|
||||
return $order_slip->id;
|
||||
|
||||
@@ -287,8 +287,8 @@ class HTMLTemplateBookingVoucherCore extends HTMLTemplate
|
||||
if (!empty($idsOrderDetail)) {
|
||||
$footer['room_price_tax_excl'] = $this->order->getTotalProductsWithoutTaxes(false, true, null, null, null, $idsOrderDetail) + $this->order->getTotalProductsWithoutTaxes(false, false, Product::SELLING_PREFERENCE_WITH_ROOM_TYPE, 1, Product::PRICE_ADDITION_TYPE_WITH_ROOM, $idsOrderDetail);
|
||||
$roomsCostTaxIncl = $this->order->getTotalProductsWithTaxes(false, true, null, null, null, $idsOrderDetail) + $this->order->getTotalProductsWithTaxes(false, false, Product::SELLING_PREFERENCE_WITH_ROOM_TYPE, 1, Product::PRICE_ADDITION_TYPE_WITH_ROOM, $idsOrderDetail);
|
||||
$footer['service_products_price_tax_excl'] = $this->order->getTotalProductsWithoutTaxes(false, false, Product::SELLING_PREFERENCE_STANDALONE, false, false, $idsOrderDetail) + $this->order->getTotalProductsWithoutTaxes(false, false, Product::SELLING_PREFERENCE_HOTEL_STANDALONE, false, false, $idsOrderDetail);
|
||||
$serviceProductsCostTaxIncl = $this->order->getTotalProductsWithTaxes(false, false, Product::SELLING_PREFERENCE_STANDALONE, false, false, $idsOrderDetail) + $this->order->getTotalProductsWithTaxes(false, false, Product::SELLING_PREFERENCE_HOTEL_STANDALONE, false, false, $idsOrderDetail);
|
||||
$footer['service_products_price_tax_excl'] = $this->order->getTotalProductsWithoutTaxes(false, false, Product::SELLING_PREFERENCE_WITH_STANDALONE, false, false, $idsOrderDetail) + $this->order->getTotalProductsWithoutTaxes(false, false, Product::SELLING_PREFERENCE_WITH_HOTEL, false, false, $idsOrderDetail);
|
||||
$serviceProductsCostTaxIncl = $this->order->getTotalProductsWithTaxes(false, false, Product::SELLING_PREFERENCE_WITH_STANDALONE, false, false, $idsOrderDetail) + $this->order->getTotalProductsWithTaxes(false, false, Product::SELLING_PREFERENCE_WITH_HOTEL, false, false, $idsOrderDetail);
|
||||
$footer['additional_service_price_tax_excl'] = $this->order->getTotalProductsWithoutTaxes(false, false, Product::SELLING_PREFERENCE_WITH_ROOM_TYPE, 0, null, $idsOrderDetail) + $totalDemandsPriceTE;
|
||||
$additionalServicesCostTaxIncl = $this->order->getTotalProductsWithTaxes(false, false, Product::SELLING_PREFERENCE_WITH_ROOM_TYPE, 0, null, $idsOrderDetail) + $totalDemandsPriceTI;
|
||||
$footer['total_convenience_fee_te'] = $this->order->getTotalProductsWithoutTaxes(false, false, Product::SELLING_PREFERENCE_WITH_ROOM_TYPE, 1, Product::PRICE_ADDITION_TYPE_INDEPENDENT, $idsOrderDetail);
|
||||
|
||||
@@ -314,6 +314,7 @@ class HTMLTemplateInvoiceCore extends HTMLTemplate
|
||||
$service_product_data = array();
|
||||
$room_additinal_services = array();
|
||||
$formattedHotelAddress = '';
|
||||
$propertyType = '';
|
||||
if (Module::isInstalled('hotelreservationsystem')) {
|
||||
$obj_htl_bk_dtl = new HotelBookingDetail();
|
||||
$objServiceProductOrderDetail = new ServiceProductOrderDetail();
|
||||
@@ -392,6 +393,8 @@ class HTMLTemplateInvoiceCore extends HTMLTemplate
|
||||
$unit_price_tax_incl = $order_details_obj->unit_price_tax_incl;
|
||||
|
||||
$cart_htl_data[$type_key]['hotel_name'] = $data_v['hotel_name'];
|
||||
$propertyType = $data_v['property_type_name'];
|
||||
|
||||
$cart_htl_data[$type_key]['name'] = $order_details_obj->product_name;
|
||||
$cart_htl_data[$type_key]['unit_price_tax_excl'] = $unit_price_tax_excl;
|
||||
$cart_htl_data[$type_key]['unit_price_tax_incl'] = $unit_price_tax_incl;
|
||||
@@ -557,8 +560,8 @@ class HTMLTemplateInvoiceCore extends HTMLTemplate
|
||||
foreach ($cart_htl_data[$type_key]['date_diff'] as $key => &$value) {
|
||||
$value['avg_paid_unit_price_tax_excl'] = Tools::ps_round($value['avg_paid_unit_price_tax_excl'] / $value['num_rm'], 6);
|
||||
}
|
||||
} else if (Product::SELLING_PREFERENCE_HOTEL_STANDALONE == $type_value['selling_preference_type']
|
||||
|| Product::SELLING_PREFERENCE_STANDALONE == $type_value['selling_preference_type']
|
||||
} else if (Product::SELLING_PREFERENCE_WITH_HOTEL == $type_value['selling_preference_type']
|
||||
|| Product::SELLING_PREFERENCE_WITH_STANDALONE == $type_value['selling_preference_type']
|
||||
) {
|
||||
$serviceProducts = $objServiceProductOrderDetail->getServiceProductsInOrder($order_obj->id, $type_value['id_order_detail'], $type_value['product_id']);
|
||||
if ($taxes = OrderDetail::getTaxListStatic($type_value['id_order_detail'])) {
|
||||
@@ -597,8 +600,8 @@ class HTMLTemplateInvoiceCore extends HTMLTemplate
|
||||
if ($idsOrderDetail = array_column($order_details, 'id_order_detail')) {
|
||||
$footer['room_price_tax_excl'] = $this->order->getTotalProductsWithoutTaxes(false, true, null, null, null, $idsOrderDetail) + $this->order->getTotalProductsWithoutTaxes(false, false, Product::SELLING_PREFERENCE_WITH_ROOM_TYPE, 1, Product::PRICE_ADDITION_TYPE_WITH_ROOM, $idsOrderDetail);
|
||||
$footer['room_price_tax_incl'] = $this->order->getTotalProductsWithTaxes(false, true, null, null, null, $idsOrderDetail) + $this->order->getTotalProductsWithTaxes(false, false, Product::SELLING_PREFERENCE_WITH_ROOM_TYPE, 1, Product::PRICE_ADDITION_TYPE_WITH_ROOM, $idsOrderDetail);
|
||||
$footer['service_products_price_tax_excl'] = $this->order->getTotalProductsWithoutTaxes(false, false, Product::SELLING_PREFERENCE_STANDALONE, false, false, $idsOrderDetail) + $this->order->getTotalProductsWithoutTaxes(false, false, Product::SELLING_PREFERENCE_HOTEL_STANDALONE, false, false, $idsOrderDetail);
|
||||
$footer['service_products_price_tax_incl'] = $this->order->getTotalProductsWithTaxes(false, false, Product::SELLING_PREFERENCE_STANDALONE, false, false, $idsOrderDetail) + $this->order->getTotalProductsWithTaxes(false, false, Product::SELLING_PREFERENCE_HOTEL_STANDALONE, false, false, $idsOrderDetail);
|
||||
$footer['service_products_price_tax_excl'] = $this->order->getTotalProductsWithoutTaxes(false, false, Product::SELLING_PREFERENCE_WITH_STANDALONE, false, false, $idsOrderDetail) + $this->order->getTotalProductsWithoutTaxes(false, false, Product::SELLING_PREFERENCE_WITH_HOTEL, false, false, $idsOrderDetail);
|
||||
$footer['service_products_price_tax_incl'] = $this->order->getTotalProductsWithTaxes(false, false, Product::SELLING_PREFERENCE_WITH_STANDALONE, false, false, $idsOrderDetail) + $this->order->getTotalProductsWithTaxes(false, false, Product::SELLING_PREFERENCE_WITH_HOTEL, false, false, $idsOrderDetail);
|
||||
$footer['additional_service_price_tax_excl'] = $this->order->getTotalProductsWithoutTaxes(false, false, Product::SELLING_PREFERENCE_WITH_ROOM_TYPE, 0, null, $idsOrderDetail);
|
||||
$footer['additional_service_price_tax_incl'] = $this->order->getTotalProductsWithTaxes(false, false, Product::SELLING_PREFERENCE_WITH_ROOM_TYPE, 0, null, $idsOrderDetail);
|
||||
$footer['total_convenience_fee_te'] = $this->order->getTotalProductsWithoutTaxes(false, false, Product::SELLING_PREFERENCE_WITH_ROOM_TYPE, 1, Product::PRICE_ADDITION_TYPE_INDEPENDENT, $idsOrderDetail);
|
||||
@@ -628,6 +631,7 @@ class HTMLTemplateInvoiceCore extends HTMLTemplate
|
||||
'delivery_address' => $formatted_delivery_address,
|
||||
'invoice_address' => $formatted_invoice_address,
|
||||
'hotel_address' => $formattedHotelAddress,
|
||||
'property_type' => $propertyType,
|
||||
'addresses' => array('invoice' => $invoice_address, 'delivery' => $delivery_address),
|
||||
'tax_excluded_display' => $tax_excluded_display,
|
||||
'display_product_images' => $display_product_images,
|
||||
|
||||
@@ -349,8 +349,8 @@ class HTMLTemplateOrderSlipCore extends HTMLTemplateInvoice
|
||||
$breakdown = array();
|
||||
$order_detail = array_filter($this->order->products, function($v) {
|
||||
return (!$v['is_booking_product'] && (
|
||||
$v['selling_preference_type'] == Product::SELLING_PREFERENCE_STANDALONE
|
||||
|| $v['selling_preference_type'] == Product::SELLING_PREFERENCE_HOTEL_STANDALONE
|
||||
$v['selling_preference_type'] == Product::SELLING_PREFERENCE_WITH_STANDALONE
|
||||
|| $v['selling_preference_type'] == Product::SELLING_PREFERENCE_WITH_HOTEL
|
||||
));
|
||||
});
|
||||
|
||||
|
||||
@@ -159,7 +159,7 @@ class WebserviceSpecificManagementBookingsCore Extends ObjectModel implements We
|
||||
'id_order' => 'o.id_order',
|
||||
'reference' => 'o.reference',
|
||||
'id_room' => 'hbd.id_room',
|
||||
'is_cancelled' => 'hbd.is_cancelled',
|
||||
'is_cancelled' => 'IF(hbd.id_status = '.HotelBookingDetail::STATUS_CANCELLED.', 1, 0)',
|
||||
'stay' => 'stay',
|
||||
'room_status' => 'hbd.id_status',
|
||||
'booking_status' => 'o.current_state',
|
||||
@@ -1146,12 +1146,11 @@ class WebserviceSpecificManagementBookingsCore Extends ObjectModel implements We
|
||||
$objOrderDetail = new OrderDetail($service['id_order_detail']);
|
||||
$objServiceProductOrderDetail = new ServiceProductOrderDetail($service['id_service_product_order_detail']);
|
||||
$quantity = $objServiceProductOrderDetail->quantity;
|
||||
if ($objOrderDetail->product_price_calculation_method == Product::PRICE_CALCULATION_METHOD_PER_DAY) {
|
||||
$quantity = $quantity * HotelHelper::getNumberOfDays(
|
||||
$objHotelBookingDetail->date_from,
|
||||
$objHotelBookingDetail->date_to
|
||||
);
|
||||
}
|
||||
$quantity *= Product::getServicePriceBillableDays(
|
||||
$objOrderDetail->product_price_calculation_method,
|
||||
$objHotelBookingDetail->date_from,
|
||||
$objHotelBookingDetail->date_to
|
||||
);
|
||||
|
||||
if (isset($this->wsRequestedRoomTypes[$dateRoomJoinKey]['services'][$service['id_product']])) {
|
||||
$oldPriceTaxExcl = $objServiceProductOrderDetail->total_price_tax_excl;
|
||||
@@ -2195,10 +2194,13 @@ class WebserviceSpecificManagementBookingsCore Extends ObjectModel implements We
|
||||
))) {
|
||||
foreach ($services as $service) {
|
||||
$insertedServiceProductIdOrderDetail = $objBookingDetail->getLastInsertedServiceIdOrderDetail($objOrder->id, $service['id_product']);
|
||||
$numDays = 1;
|
||||
if (Product::getProductPriceCalculation($service['id_product']) == Product::PRICE_CALCULATION_METHOD_PER_DAY) {
|
||||
$numDays = HotelHelper::getNumberOfDays($objBookingDetail->date_from, $objBookingDetail->date_to);
|
||||
}
|
||||
|
||||
$numDays = Product::getServicePriceBillableDays(
|
||||
Product::getProductPriceCalculation($service['id_product']),
|
||||
$objBookingDetail->date_from,
|
||||
$objBookingDetail->date_to
|
||||
);
|
||||
|
||||
$totalPriceTaxExcl = Product::getServiceProductPrice(
|
||||
$service['id_product'],
|
||||
0,
|
||||
@@ -2528,9 +2530,12 @@ class WebserviceSpecificManagementBookingsCore Extends ObjectModel implements We
|
||||
foreach ($selectedAdditonalServices[$idHotelBooking]['additional_services'] as $service) {
|
||||
$serviceOrderDetail = new OrderDetail($service['id_order_detail']);
|
||||
$cart_quantity = $service['quantity'];
|
||||
if ($service['price_calculation_method'] == Product::PRICE_CALCULATION_METHOD_PER_DAY) {
|
||||
$cart_quantity = $cart_quantity * $quantity;
|
||||
}
|
||||
$serviceApplicableDays = Product::getServicePriceBillableDays(
|
||||
$service['price_calculation_method'],
|
||||
$dateFrom,
|
||||
$dateTo
|
||||
);
|
||||
$cart_quantity = $cart_quantity * $serviceApplicableDays;
|
||||
|
||||
if ($cart_quantity >= $serviceOrderDetail->product_quantity) {
|
||||
$serviceOrderDetail->delete();
|
||||
@@ -3036,10 +3041,11 @@ class WebserviceSpecificManagementBookingsCore Extends ObjectModel implements We
|
||||
$priceTaxExcl = $objServiceProductOrderDetail->total_price_tax_excl;
|
||||
$priceTaxIncl = $objServiceProductOrderDetail->total_price_tax_incl;
|
||||
$objHotelBookingDetail = new HotelBookingDetail($objServiceProductOrderDetail->id_htl_booking_detail);
|
||||
$numDays = 1;
|
||||
if (Product::getProductPriceCalculation($service['id_product']) == Product::PRICE_CALCULATION_METHOD_PER_DAY) {
|
||||
$numDays = HotelHelper::getNumberOfDays($objHotelBookingDetail->date_from, $objHotelBookingDetail->date_to);
|
||||
}
|
||||
$numDays = Product::getServicePriceBillableDays(
|
||||
Product::getProductPriceCalculation($service['id_product']),
|
||||
$objHotelBookingDetail->date_from,
|
||||
$objHotelBookingDetail->date_to
|
||||
);
|
||||
|
||||
$quantity = $objOrderDetail->product_quantity * $numDays;
|
||||
if ($objServiceProductOrderDetail->delete()) {
|
||||
@@ -3131,10 +3137,11 @@ class WebserviceSpecificManagementBookingsCore Extends ObjectModel implements We
|
||||
$insertedServiceProductIdOrderDetail = $objHotelBookingDetail->getLastInsertedServiceIdOrderDetail($objOrder->id, $service['id_product']);
|
||||
$objOrderDetail = new OrderDetail($insertedServiceProductIdOrderDetail);
|
||||
|
||||
$numDays = 1;
|
||||
if (Product::getProductPriceCalculation($product['id_product']) == Product::PRICE_CALCULATION_METHOD_PER_DAY) {
|
||||
$numDays = HotelHelper::getNumberOfDays($objHotelBookingDetail->date_from, $objHotelBookingDetail->date_to);
|
||||
}
|
||||
$numDays = Product::getServicePriceBillableDays(
|
||||
Product::getProductPriceCalculation($product['id_product']),
|
||||
$objHotelBookingDetail->date_from,
|
||||
$objHotelBookingDetail->date_to
|
||||
);
|
||||
|
||||
$quantity = $objServiceProductCartDetail->quantity * $numDays;
|
||||
|
||||
@@ -3691,7 +3698,7 @@ class WebserviceSpecificManagementBookingsCore Extends ObjectModel implements We
|
||||
|
||||
$objProduct = new Product($service['id_product']);
|
||||
$services['per_night'] = 0;
|
||||
if ($objProduct->price_calculation_method == Product::PRICE_CALCULATION_METHOD_PER_DAY) {
|
||||
if ($objProduct->price_calculation_method & Product::PRICE_CALCULATION_METHOD_ON_DURING_STAY) {
|
||||
$services['per_night'] = 1;
|
||||
}
|
||||
|
||||
@@ -3922,17 +3929,18 @@ class WebserviceSpecificManagementBookingsCore Extends ObjectModel implements We
|
||||
$services['id_service'] = (int) $service['id_product'];
|
||||
$services['name'] = $service['name'];
|
||||
$services['quantity'] = (int) $service['quantity'];
|
||||
$services['unit_price_without_tax'] = Tools::ps_round(($service['total_price_tax_excl'] / $services['quantity']), _PS_PRICE_COMPUTE_PRECISION_);
|
||||
$applicableDays = Product::getServicePriceBillableDays(
|
||||
$service['price_calculation_method'],
|
||||
$additionalService['date_from'],
|
||||
$additionalService['date_to']
|
||||
);
|
||||
$unitDivisor = max(1, ((int) $services['quantity'] * (int) $applicableDays));
|
||||
$services['unit_price_without_tax'] = Tools::ps_round(($service['total_price_tax_excl'] / $unitDivisor), _PS_PRICE_COMPUTE_PRECISION_);
|
||||
$services['total_price_without_tax'] = Tools::ps_round(($service['total_price_tax_excl']), _PS_PRICE_COMPUTE_PRECISION_);
|
||||
$services['total_tax'] = Tools::ps_round(($service['total_price_tax_incl'] - $service['total_price_tax_excl']), _PS_PRICE_COMPUTE_PRECISION_);
|
||||
|
||||
$objProduct = new Product($service['id_product']);
|
||||
$services['per_night'] = 0;
|
||||
if ($objProduct->price_calculation_method == Product::PRICE_CALCULATION_METHOD_PER_DAY) {
|
||||
$services['per_night'] = 1;
|
||||
}
|
||||
|
||||
$services['price_mode'] = (int) $objProduct->price_calculation_method;
|
||||
$services['per_night'] = ((int) $applicableDays > 1) ? 1 : 0;
|
||||
$services['price_mode'] = (int) $service['price_calculation_method'];
|
||||
$roomInfo['services'][] = $services;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user