Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed: Incorrect room price and final price when admin remove service product or update room price from admin end and proceed for payment at front office #924

Merged
merged 2 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion classes/PaymentModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,11 @@ public function validateOrder($id_cart, $id_order_state, $amount_paid, $payment_
$objBookingDetail->total_paid_amount = $objAdvancedPayment->getRoomMinAdvPaymentAmount(
$idProduct,
$objCartBookingData->date_from,
$objCartBookingData->date_to
$objCartBookingData->date_to,
1,
$objCartBookingData->id_room,
$objCartBookingData->id_cart,
$objCartBookingData->id_guest
);
}
}
Expand Down
22 changes: 19 additions & 3 deletions modules/hotelreservationsystem/classes/HotelAdvancedPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,13 @@ public function getProductMinAdvPaymentAmountByIdCart(
$roomTotalPrices = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice(
$cartRoomInfo['id_product'],
$cartRoomInfo['date_from'],
$cartRoomInfo['date_to']
$cartRoomInfo['date_to'],
0,
0,
$idCart,
$cartRoomInfo['id_guest'],
$cartRoomInfo['id_room'],
0
);

$roomTypeTotalTI += $roomTotalPrices['total_price_tax_incl'];
Expand Down Expand Up @@ -319,7 +325,7 @@ public function _checkFreeAdvancePaymentOrder()
* @param integer $withTaxes : Amount with(1) or without tax (0)
* @return [float] advance payment amount of the room type in the cart
*/
public function getRoomMinAdvPaymentAmount($idProduct, $dateFrom, $dateTo, $withTaxes = 1)
public function getRoomMinAdvPaymentAmount($idProduct, $dateFrom, $dateTo, $withTaxes = 1, $idRoom = 0, $idCart = 0, $idGuest = 0)
{
$dateFrom = date('Y-m-d', strtotime($dateFrom));
$dateTo = date('Y-m-d', strtotime($dateTo));
Expand All @@ -328,7 +334,17 @@ public function getRoomMinAdvPaymentAmount($idProduct, $dateFrom, $dateTo, $with
$advGlobalPercent = Configuration::get('WK_ADVANCED_PAYMENT_GLOBAL_MIN_AMOUNT');
$advGlobalTaxIncl = Configuration::get('WK_ADVANCED_PAYMENT_INC_TAX');

$roomTotalPrices = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice($idProduct, $dateFrom, $dateTo);
$roomTotalPrices = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice(
$idProduct,
$dateFrom,
$dateTo,
0,
0,
$idCart,
$idGuest,
$idRoom,
0
);
$roomTypeTotalTI = $roomTotalPrices['total_price_tax_incl'];
$roomTypeTotalTE = $roomTotalPrices['total_price_tax_excl'];

Expand Down
24 changes: 0 additions & 24 deletions modules/hotelreservationsystem/classes/HotelBookingDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -1947,29 +1947,6 @@ public function UpdateHotelCartHotelOrderOnOrderEdit(
$newTotalPriceTI = $unitRoomPriceTI * $newNumDays;
}

// calculate `total_paid_amount`
$totalPaidAmount = 0;
$isAdvancePayment = Db::getInstance()->getValue(
'SELECT o.`is_advance_payment`
FROM `'._DB_PREFIX_.'orders` o
WHERE o.`id_order` = '.(int) $idOrder
);

if ($isAdvancePayment) {
$objHotelAdvancedPayment = new HotelAdvancedPayment();
$productAdvancePayment = $objHotelAdvancedPayment->getIdAdvPaymentByIdProduct($objHotelBookingDetail->id_product);

if (!$productAdvancePayment || (isset($productAdvancePayment['payment_type']) && $productAdvancePayment['payment_type'])) {
$totalPaidAmount = $objHotelAdvancedPayment->getRoomMinAdvPaymentAmount(
$objHotelBookingDetail->id_product,
$newDateFrom,
$newDateTo
);
}
} else {
$totalPaidAmount = $newTotalPriceTI;
}

// update $objHotelCartBookingData
$objHotelCartBookingData->date_from = $newDateFrom;
$objHotelCartBookingData->date_to = $newDateTo;
Expand All @@ -1983,7 +1960,6 @@ public function UpdateHotelCartHotelOrderOnOrderEdit(
$objHotelBookingDetail->date_to = $newDateTo;
$objHotelBookingDetail->total_price_tax_excl = Tools::ps_round($newTotalPriceTE, 6);
$objHotelBookingDetail->total_price_tax_incl = Tools::ps_round($newTotalPriceTI, 6);
$objHotelBookingDetail->total_paid_amount = Tools::ps_round($totalPaidAmount, 6);
$objHotelBookingDetail->adults = $occupancy['adults'];
$objHotelBookingDetail->children = $occupancy['children'];
$objHotelBookingDetail->child_ages = json_encode($occupancy['child_ages']);
Expand Down
26 changes: 18 additions & 8 deletions modules/hotelreservationsystem/classes/HotelCartBookingData.php
Original file line number Diff line number Diff line change
Expand Up @@ -1340,17 +1340,22 @@ public static function getHotelCartBookingData($detailed = 1)
$roomTypeDateRangePrice = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice(
$product['id_product'],
$data_v['date_from'],
$data_v['date_to']
$data_v['date_to'],
0,
0,
$context->cart->id,
$context->cart->id_guest,
$data_v['id_room']
);
$roomTypeDateRangePriceWithoutAutoAdd = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice(
$product['id_product'],
$data_v['date_from'],
$data_v['date_to'],
0,
0,
0,
0,
0,
$context->cart->id,
$context->cart->id_guest,
$data_v['id_room'],
0
);
if (!$price_tax) {
Expand Down Expand Up @@ -1382,17 +1387,22 @@ public static function getHotelCartBookingData($detailed = 1)
$roomTypeDateRangePrice = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice(
$product['id_product'],
$data_v['date_from'],
$data_v['date_to']
$data_v['date_to'],
0,
0,
$context->cart->id,
$context->cart->id_guest,
$data_v['id_room']
);
$roomTypeDateRangePriceWithoutAutoAdd = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice(
$product['id_product'],
$data_v['date_from'],
$data_v['date_to'],
0,
0,
0,
0,
0,
$context->cart->id,
$context->cart->id_guest,
$data_v['id_room'],
0
);
if (!$price_tax) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -719,12 +719,28 @@ public static function getRoomTypeTotalPrice(
}
}
if ($with_auto_room_services) {
if ($servicesWithTax = RoomTypeServiceProduct::getAutoAddServices($id_product, $date_from, $date_to, Product::PRICE_ADDITION_TYPE_WITH_ROOM, true)) {
if ($servicesWithTax = RoomTypeServiceProduct::getAutoAddServices(
$id_product,
$date_from,
$date_to,
Product::PRICE_ADDITION_TYPE_WITH_ROOM,
true,
$id_cart,
$id_guest
)) {
foreach($servicesWithTax as $service) {
$totalPrice['total_price_tax_incl'] += $service['price'];
}
}
if ($servicesWithoutTax = RoomTypeServiceProduct::getAutoAddServices($id_product, $date_from, $date_to, Product::PRICE_ADDITION_TYPE_WITH_ROOM, false)) {
if ($servicesWithoutTax = RoomTypeServiceProduct::getAutoAddServices(
$id_product,
$date_from,
$date_to,
Product::PRICE_ADDITION_TYPE_WITH_ROOM,
false,
$id_cart,
$id_guest
)) {
foreach($servicesWithoutTax as $service) {
$totalPrice['total_price_tax_excl'] += $service['price'];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,16 @@ public function isRoomTypeLinkedWithProduct($idProductRoomType, $idServiceProduc
return Db::getInstance()->getValue($sql);
}

public static function getAutoAddServices($idProduct, $dateFrom = null, $dateTo = null, $priceAdditionType = null, $useTax = null)
public static function getAutoAddServices($idProduct, $dateFrom = null, $dateTo = null, $priceAdditionType = null, $useTax = null, $idCart = 0, $idGuest = 0)
{
if (Product::isBookingProduct($idProduct)) {
$sql = 'SELECT p.`id_product` FROM `'._DB_PREFIX_.'htl_room_type_service_product` rsp
INNER JOIN `'._DB_PREFIX_.'product` p ON (rsp.`id_product` = p.`id_product` AND p.`auto_add_to_cart` = 1)
WHERE p.`active` = 1 AND `id_element` = '.(int)$idProduct.' AND `element_type` = '.self::WK_ELEMENT_TYPE_ROOM_TYPE;
INNER JOIN `'._DB_PREFIX_.'product` p ON (rsp.`id_product` = p.`id_product` AND p.`auto_add_to_cart` = 1)';
if ($idCart) {
$sql .= ' INNER JOIN `'._DB_PREFIX_.'htl_room_type_service_product_cart_detail` spcd
ON (rsp.`id_product` = spcd.`id_product` AND spcd.`id_cart` = '.(int)$idCart.')';
}
$sql .= ' WHERE p.`active` = 1 AND `id_element` = '.(int)$idProduct.' AND `element_type` = '.self::WK_ELEMENT_TYPE_ROOM_TYPE;
if (!is_null($priceAdditionType)) {
$sql .= ' AND p.`price_addition_type` = '.$priceAdditionType;
}
Expand Down