Merge pull request #1976 from Azhar-Webkul/gli-3319

Fixed: Multiple order and refund related bugs in both front-office and back-office.
This commit is contained in:
Rohit Jain
2026-10-27 11:40:23 +05:30
committed by GitHub
12 changed files with 101 additions and 52 deletions

View File

@@ -47,6 +47,7 @@
var currency_sign = '';
var currency_blank = false;
var priceDisplayPrecision = {$smarty.const._PS_PRICE_DISPLAY_PRECISION_|intval};
var current_order_total = {$order_total|floatval};
$(document).ready(function() {
$(document).on('change', '#add_new_room_services_form select[name="price_calculation_type"]', function() {
@@ -718,6 +719,10 @@
updateCartLine(response.curr_booking_info, cart_row);
updateCartSummaryData(response.cart_info);
updateCartVouchers(response.cart_info.summary.discounts);
var $totalTaxesTrigger = $('#total_taxes').closest('.data-focus').find('.ui-tooltip-trigger');
initUITooltip($totalTaxesTrigger, function() {
return $totalTaxesTrigger.next('.tooltip-content').html();
});
}
});
}
@@ -782,9 +787,8 @@
$('#total_taxes_tourism').html(formatCurrency(totalTaxesTourismAmt, currency_format, currency_sign, currency_blank));
$('#total_with_taxes').html(formatCurrency(parseFloat(jsonSummary.summary.total_price), currency_format, currency_sign, currency_blank));
if (parseInt($('input[name="is_full_payment"]:checked').val())) {
$('#payment_amount').val(jsonSummary.summary.total_price);
}
current_order_total = parseFloat(jsonSummary.summary.total_price);
$('#payment_amount').val(jsonSummary.summary.total_price);
$('#full_payment_amount_value').html(formatCurrency(parseFloat(jsonSummary.summary.total_price), currency_format, currency_sign, currency_blank));
if (jsonSummary.summary.is_advance_payment_active) {
@@ -1322,9 +1326,8 @@
}
$('#order_message').val(jsonSummary.order_message);
$('#payment_amount').siblings('.input-group-addon').html(currency_sign);
if (parseInt($('input[name="is_full_payment"]:checked').val())) {
$('#payment_amount').val(jsonSummary.summary.total_price);
}
current_order_total = parseFloat(jsonSummary.summary.total_price);
$('#payment_amount').val(jsonSummary.summary.total_price);
$('#full_payment_amount_value').html(formatCurrency(parseFloat(jsonSummary.summary.total_price), currency_format, currency_sign, currency_blank));
if (jsonSummary.summary.is_advance_payment_active) {
@@ -1671,12 +1674,12 @@
$(document).on('change', 'input[name="is_full_payment"]', function() {
if (parseInt($('input[name="is_full_payment"]:checked').val())) {
$('#payment_amount').val({$order_total|floatval}).attr('disabled', true);
$('#payment_amount').val(current_order_total).attr('disabled', true);
$('#payment_amount').closest('.form-group').hide(200);
$('#payment_type, #payment_module_name, #payment_transaction_id').closest('.form-group').show(200);
} else {
$('#payment_amount').val({$order_total|floatval}).attr('disabled', false);
$('#payment_amount').val(current_order_total).attr('disabled', false);
$('#payment_amount').closest('.form-group').show(200);
managePaymentOptions();

View File

@@ -233,15 +233,17 @@ abstract class PaymentModuleCore extends Module
$full_cart_total = (float)Tools::ps_round((float)$this->context->cart->getOrderTotal(true, Cart::BOTH), _PS_PRICE_COMPUTE_PRECISION_);
$amount_paid = !$dont_touch_amount ? Tools::ps_round((float)$amount_paid, _PS_PRICE_COMPUTE_PRECISION_) : $amount_paid;
$is_advance_payment = false;
if ($amount_paid >= $full_cart_total) {
$is_advance_payment = false;
$cart_total_paid = $full_cart_total;
} else {
} elseif ($this->context->cart->is_advance_payment) {
$is_advance_payment = true;
$cart_total_paid = (float)Tools::ps_round(
(float)$this->context->cart->getOrderTotal(true, Cart::ADVANCE_PAYMENT),
_PS_PRICE_COMPUTE_PRECISION_
);
} else {
$cart_total_paid = $full_cart_total;
}
foreach ($cart_delivery_option as $id_address => $key_carriers) {

View File

@@ -6865,6 +6865,13 @@ class ProductCore extends ObjectModel
$price = $price * $quantity;
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);
}
$tourismTaxHotelId = $idHotel;
if (!$tourismTaxHotelId && $idProductRoomType) {
$objRoomType = new HotelRoomType();
@@ -6906,12 +6913,6 @@ 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;
}

View File

@@ -146,6 +146,7 @@ class OrderTaxDetailCore extends ObjectModel
WHERE tt.`id_order` = ' . $idOrder . '
AND spod.`id_htl_booking_detail` != 0
AND spod.`is_refunded` = 0
AND spod.`id_htl_booking_detail` NOT IN (' . OrderReturn::getRefundedBookingIdsSubquery() . ')
AND ex.`id_order_tax_exemption` IS NULL
GROUP BY spod.`id_htl_booking_detail`';
$rows = Db::getInstance()->executeS($sql);
@@ -760,7 +761,8 @@ class OrderTaxDetailCore extends ObjectModel
ON tl.`id_tax` = ott.`id_tax` AND tl.`id_lang` = ' . $idLang . '
WHERE ott.`id_order` = ' . $idOrder . '
AND ((ott.`id_htl_booking` != 0 AND ott.`id_htl_booking` NOT IN (' . OrderReturn::getRefundedBookingIdsSubquery() . '))
OR (ott.`id_htl_booking` = 0 AND spod.`is_refunded` = 0))
OR (ott.`id_htl_booking` = 0 AND spod.`is_refunded` = 0
AND (spod.`id_htl_booking_detail` = 0 OR spod.`id_htl_booking_detail` IS NULL OR spod.`id_htl_booking_detail` NOT IN (' . OrderReturn::getRefundedBookingIdsSubquery() . '))))
AND ex.`id_order_tax_exemption` IS NULL
GROUP BY ott.`id_tax`, tl.`name`'
);
@@ -797,7 +799,8 @@ class OrderTaxDetailCore extends ObjectModel
OR (ott.`id_htl_booking` = 0 AND (spod.`id_htl_booking_detail` = 0 OR spod.`id_htl_booking_detail` IS NULL) AND ex.`id_service_product_order_detail` = ott.`id_service_product_order_detail` AND ex.`id_htl_booking` = 0)
WHERE ott.`id_order` = ' . $idOrder . '
AND ((ott.`id_htl_booking` != 0 AND ott.`id_htl_booking` NOT IN (' . OrderReturn::getRefundedBookingIdsSubquery() . '))
OR (ott.`id_htl_booking` = 0 AND spod.`is_refunded` = 0))
OR (ott.`id_htl_booking` = 0 AND spod.`is_refunded` = 0
AND (spod.`id_htl_booking_detail` = 0 OR spod.`id_htl_booking_detail` IS NULL OR spod.`id_htl_booking_detail` NOT IN (' . OrderReturn::getRefundedBookingIdsSubquery() . '))))
AND ex.`id_order_tax_exemption` IS NULL
GROUP BY ott.`id_order_detail`'
);

View File

@@ -177,7 +177,13 @@ class HTMLTemplateBookingVoucherCore extends HTMLTemplate
);
if (isset($additionalServices[(int)$booking['id']]['additional_services'])) {
foreach ($additionalServices[(int)$booking['id']]['additional_services'] as $service) {
$bookingServices[] = array('name' => $service['name'], 'quantity' => (int)$service['quantity']);
$bookingServices[] = array(
'name' => $service['name'],
'quantity' => (int)$service['quantity'],
'unit_price_tax_excl' => (float)$service['unit_price_tax_excl'],
'total_price_tax_excl' => (float)$service['total_price_tax_excl'],
'allow_multiple_quantity' => (int)$service['allow_multiple_quantity'],
);
}
}

View File

@@ -2004,6 +2004,10 @@ class AdminOrdersControllerCore extends AdminController
$this->errors[] = Tools::displayError('Please enter a reason for the booking cancellation.');
}
if (!$order->isReturnable()) {
$this->errors[] = Tools::displayError('Refund is not allowed for this hotel.');
}
if (!count($this->errors)) {
// create refund request
$objOrderReturn = new OrderReturn();
@@ -3084,6 +3088,8 @@ class AdminOrdersControllerCore extends AdminController
$initialPaymentStatus = $this->l('Full Payment');
} elseif (isset($orderHistory[0]['id_order_state']) && ($orderHistory[0]['id_order_state'] == Configuration::get('PS_OS_PARTIAL_PAYMENT_ACCEPTED'))) {
$initialPaymentStatus = $this->l('Partial Payment');
} elseif (isset($orderHistory[0]['id_order_state']) && ($orderHistory[0]['id_order_state'] == Configuration::get('PS_OS_ERROR'))) {
$initialPaymentStatus = $this->l('Payment Error');
} else {
$initialPaymentStatus = $this->l('No Payment Received');
}
@@ -3091,7 +3097,7 @@ class AdminOrdersControllerCore extends AdminController
$helper->icon = 'icon-home';
$helper->color = 'color3';
$helper->title = $this->l('Initial Payment Status');
$helper->tooltip = $this->l('Initial Payment Status defines whether the order was fully paid, partially paid, or had no payment received at the time the order was placed.');
$helper->tooltip = $this->l('Initial Payment Status defines whether the order was fully paid, partially paid, had a payment error, or had no payment received at the time the order was placed.');
$helper->value = $initialPaymentStatus;
$this->kpis[] = $helper;
@@ -9084,28 +9090,31 @@ class AdminOrdersControllerCore extends AdminController
? OrderReturn::EVENT_TYPE_CANCELLATION
: OrderReturn::EVENT_TYPE_NO_SHOW;
$objOrderReturn = new OrderReturn();
$objOrderReturn->id_customer = $order->id_customer;
$objOrderReturn->id_order = $order->id;
$objOrderReturn->state = 0;
$objOrderReturn->by_admin = 1;
$objOrderReturn->question = $statusRemark;
$objOrderReturn->refunded_amount = 0;
$objOrderReturn->event_type = $eventType;
$objOrderReturn->save();
// no refund request is created if refund is disabled for the hotel
if ($order->isReturnable()) {
$objOrderReturn = new OrderReturn();
$objOrderReturn->id_customer = $order->id_customer;
$objOrderReturn->id_order = $order->id;
$objOrderReturn->state = 0;
$objOrderReturn->by_admin = 1;
$objOrderReturn->question = $statusRemark;
$objOrderReturn->refunded_amount = 0;
$objOrderReturn->event_type = $eventType;
$objOrderReturn->save();
$objOrderReturnDetail = new OrderReturnDetail();
$objOrderReturnDetail->id_order_return = $objOrderReturn->id;
$objOrderReturnDetail->id_order_detail = $objHotelBookingDetail->id_order_detail;
$objOrderReturnDetail->product_quantity = HotelHelper::getNumberOfDays(
$objHotelBookingDetail->date_from,
$objHotelBookingDetail->date_to
);
$objOrderReturnDetail->id_htl_booking = $objHotelBookingDetail->id;
$objOrderReturnDetail->refunded_amount = 0;
$objOrderReturnDetail->save();
$objOrderReturnDetail = new OrderReturnDetail();
$objOrderReturnDetail->id_order_return = $objOrderReturn->id;
$objOrderReturnDetail->id_order_detail = $objHotelBookingDetail->id_order_detail;
$objOrderReturnDetail->product_quantity = HotelHelper::getNumberOfDays(
$objHotelBookingDetail->date_from,
$objHotelBookingDetail->date_to
);
$objOrderReturnDetail->id_htl_booking = $objHotelBookingDetail->id;
$objOrderReturnDetail->refunded_amount = 0;
$objOrderReturnDetail->save();
$objOrderReturn->changeIdOrderReturnState(Configuration::get('PS_ORS_PENDING'));
$objOrderReturn->changeIdOrderReturnState(Configuration::get('PS_ORS_PENDING'));
}
// the room's own status (htl_booking_detail.id_status) flips right
// away — that's a factual room-state decision, independent of the

View File

@@ -475,6 +475,7 @@ class OrderDetailControllerCore extends FrontController
'ROOM_STATUS_ASSIGNED' => HotelBookingDetail::STATUS_ASSIGNED,
'ROOM_STATUS_CHECKED_IN' => HotelBookingDetail::STATUS_CHECKED_IN,
'ROOM_STATUS_CHECKED_OUT' => HotelBookingDetail::STATUS_CHECKED_OUT,
'ROOM_STATUS_NO_SHOW' => HotelBookingDetail::STATUS_NO_SHOW,
)
);
@@ -575,6 +576,8 @@ class OrderDetailControllerCore extends FrontController
$objOrderReturn = new OrderReturn();
if (!(Validate::isLoadedObject($objOrder) && $objOrder->id_customer == $this->context->customer->id)) {
$this->errors[] = Tools::displayError('Something went wrong. Please try later.');
} elseif (!$objOrder->isReturnable()) {
$this->errors[] = Tools::displayError('Refund is not allowed for this hotel.');
} else {
if ($idsHtlBooking) {
foreach ($idsHtlBooking as $idHtlBooking) {
@@ -586,7 +589,7 @@ class OrderDetailControllerCore extends FrontController
// the room has already been checked in/checked out, room will not be able to be cancelled by the customer
if ($objHotelBookingDetail->id_status != HotelBookingDetail::STATUS_ASSIGNED) {
$this->errors[] = Tools::displayError('Some selected rooms have already been checked-in/checked-out.');
$this->errors[] = Tools::displayError('Some selected rooms have already been checked-in/checked-out or marked as no-show.');
break;
}

View File

@@ -417,6 +417,10 @@ class Blockcart extends Module
if ($useTax && TaxConfiguration::isGrossedUp($tourismTaxRoom)) {
$totalRoomsPrice += $tourismTaxRoom;
}
$tourismTaxService = (float) $tourismTaxTotals['tourism_tax_service'];
if ($useTax && TaxConfiguration::isGrossedUp($tourismTaxService)) {
$totalAdditionalServicesWithoutAutoAddPrice += $tourismTaxService;
}
if ($useTax && TaxConfiguration::isGrossedUp($tourismTaxConvenienceFee)) {
$totalConvenienceFee += $tourismTaxConvenienceFee;
}

View File

@@ -29,6 +29,16 @@ class QhrHotelReviewHelper
return false;
}
// At least one room must be actually checked out, otherwise an order with all rooms cancelled would count as checked out
if (!Db::getInstance()->getValue(
'SELECT COUNT(*) FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
WHERE hbd.`id_status` = '.(int) HotelBookingDetail::STATUS_CHECKED_OUT.'
AND hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().')
AND hbd.`id_order` = '.(int) $idOrder
)) {
return false;
}
return (bool) !Db::getInstance()->getValue(
'SELECT COUNT(*) FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
WHERE hbd.`id_status` != '.(int) HotelBookingDetail::STATUS_CHECKED_OUT.'
@@ -73,9 +83,11 @@ class QhrHotelReviewHelper
$maxDate = Db::getInstance()->getValue(
'SELECT MAX(DATE(hbd.`date_to`)) FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
WHERE hbd.`id_order` = '.(int) $idOrder
WHERE hbd.`id_status` != '.(int) HotelBookingDetail::STATUS_CANCELLED.'
AND hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().')
AND hbd.`id_order` = '.(int) $idOrder
);
return date('Y-m-d') >= $maxDate;
return $maxDate && date('Y-m-d') >= $maxDate;
}
public static function sendReviewRequestMail($idOrder)

View File

@@ -171,24 +171,28 @@
<table class="bordered-table" width="100%" cellpadding="5" cellspacing="0">
<tbody>
<tr>
<th colspan="3" class="header-left small">{l s='SERVICES DETAILS' pdf='true'}</th>
<th colspan="5" class="header-left small">{l s='SERVICES DETAILS' pdf='true'}</th>
</tr>
<tr>
<th class="header-left small" width="35%">{l s='Room Type' pdf='true'}</th>
<th class="header-left small" width="45%">{l s='Service Name' pdf='true'}</th>
<th class="header-left small" width="20%">{l s='Qty' pdf='true'}</th>
<th class="header-left small" width="25%">{l s='Room Type' pdf='true'}</th>
<th class="header-left small" width="25%">{l s='Service Name' pdf='true'}</th>
<th class="header-left small" width="20%">{l s='Unit Price (tax excl.)' pdf='true'}</th>
<th class="header-left small" width="10%">{l s='Qty' pdf='true'}</th>
<th class="header-left small" width="20%">{l s='Total (tax excl.)' pdf='true'}</th>
</tr>
{foreach from=$service_groups item=group}
{foreach from=$group.services item=service name=service_loop}
<tr>
{if $smarty.foreach.service_loop.first}
<td class="small white" width="35%" rowspan="{$group.services|@count}">{$group.room_type_name|escape:'html':'UTF-8'}<br />
<td class="small white" width="25%" rowspan="{$group.services|@count}">{$group.room_type_name|escape:'html':'UTF-8'}<br />
{$group.check_in_date|escape:'html':'UTF-8'} - {$group.check_out_date|escape:'html':'UTF-8'}<br />
{l s='Room' pdf='true'} - {$group.room_count|intval}
</td>
{/if}
<td class="small white" width="45%">{$service.name|escape:'html':'UTF-8'}</td>
<td class="small white" width="20%">{$service.quantity|intval}</td>
<td class="small white" width="25%">{$service.name|escape:'html':'UTF-8'}</td>
<td class="small white" width="20%">{displayPrice currency=$order->id_currency price=$service.unit_price_tax_excl}</td>
<td class="small white" width="10%">{if $service.allow_multiple_quantity}{$service.quantity|intval}{else}--{/if}</td>
<td class="small white" width="20%">{displayPrice currency=$order->id_currency price=$service.total_price_tax_excl}</td>
</tr>
{/foreach}
{/foreach}

View File

@@ -46,7 +46,7 @@
{assign var=countRoom value=1}
{foreach from=$occupancies key=key item=$occupancy name=occupancyInfo}
<div class="occupancy_info_block selected" occ_block_index="{$key|escape:'htmlall':'UTF-8'}">
<div class="occupancy_info_head"><span class="room_num_wrapper">{$room_type_info['selling_object_name']|escape:'htmlall':'UTF-8'} - {$countRoom|escape:'htmlall':'UTF-8'} </span>{if !$smarty.foreach.occupancyInfo.first}<a class="remove-stay-link pull-right" href="#">{l s='Remove'}</a>{/if}</div>
<div class="occupancy_info_head"><span class="room_num_wrapper">{$room_type_info['selling_object_name']|escape:'htmlall':'UTF-8'} - {$countRoom|escape:'htmlall':'UTF-8'} </span>{if !$smarty.foreach.occupancyInfo.first}<a class="remove-room-link pull-right" href="#">{l s='Remove'}</a>{/if}</div>
<div class="row">
<div class="form-group col-sm-5 col-xs-6 occupancy_count_block">
<div class="row">

View File

@@ -334,6 +334,7 @@
{assign var=room_services_price_tax_incl value=($order->getTotalProductsWithTaxes(false, false, Product::SELLING_PREFERENCE_WITH_ROOM_TYPE))}
{assign var=total_tax_without_discount value=(($room_price_tax_incl - $room_price_tax_excl) + ($room_services_price_tax_incl - $room_services_price_tax_excl) - ($total_tourism_tax|default:0))}
{if $total_tax_without_discount < 0}{assign var=total_tax_without_discount value=0}{/if}
{assign var=total_standard_products_tax_incl value=($order->getTotalProductsWithTaxes(false, false, Product::SELLING_PREFERENCE_WITH_STANDALONE) + $order->getTotalProductsWithTaxes(false, false, Product::SELLING_PREFERENCE_WITH_HOTEL))}
{assign var=total_standard_products_tax_excl value=($order->getTotalProductsWithoutTaxes(false, false, Product::SELLING_PREFERENCE_WITH_STANDALONE) + $order->getTotalProductsWithoutTaxes(false, false, Product::SELLING_PREFERENCE_WITH_HOTEL))}
@@ -773,6 +774,7 @@
{assign var=total_standard_products_tax_excl value=($order->getTotalProductsWithoutTaxes(false, false, Product::SELLING_PREFERENCE_WITH_STANDALONE) + $order->getTotalProductsWithoutTaxes(false, false, Product::SELLING_PREFERENCE_WITH_HOTEL))}
{assign var=total_tax_without_discount value=(($room_price_tax_incl - $room_price_tax_excl) + ($room_services_price_tax_incl - $room_services_price_tax_excl) + ($total_standard_products_tax_incl - $total_standard_products_tax_excl) - ($total_tourism_tax|default:0))}
{if $total_tax_without_discount < 0}{assign var=total_tax_without_discount value=0}{/if}
{if isset($cart_htl_data) && $cart_htl_data}
<tr>
@@ -1034,7 +1036,7 @@
</label>
<span>({$hotel_booking_detail.adults|string_format:'%02d'} {if $hotel_booking_detail.adults > 1}{l s='Adults'}{else}{l s='Adult'}{/if}{if $hotel_booking_detail.children > 0}{l s=', '}{$hotel_booking_detail.children|string_format:'%02d'} {if $hotel_booking_detail.children > 1}{l s='Children'}{else}{l s='Child'}{/if}{/if})</span>
{if $hotel_booking_detail.is_cancelled}<span class="badge badge-danger badge-cancelled">{l s='Cancelled'}</span>{else if $hotel_booking_detail.is_refunded}<span class="badge badge-danger badge-cancelled">{l s='Refunded'}</span>{else if $hotel_booking_detail.refund_denied}<span class="badge badge-danger badge-cancelled">{l s='Refund denied'}</span> {include file='_partials/ui-tooltip.tpl' tooltip_content={l s='Refund for this booking is denied. Please contact admin for more detail.'}}{else if $hotel_booking_detail.id_status != $ROOM_STATUS_ASSIGNED}<span class="badge badge-danger badge-cancelled">{if $hotel_booking_detail.id_status == $ROOM_STATUS_CHECKED_OUT}{l s='Checked-Out'}{else}{l s='Checked-In'}{/if}</span>{/if}
{if $hotel_booking_detail.is_cancelled}<span class="badge badge-danger badge-cancelled">{l s='Cancelled'}</span>{else if $hotel_booking_detail.is_refunded}<span class="badge badge-danger badge-cancelled">{l s='Refunded'}</span>{else if $hotel_booking_detail.refund_denied}<span class="badge badge-danger badge-cancelled">{l s='Refund denied'}</span> {include file='_partials/ui-tooltip.tpl' tooltip_content={l s='Refund for this booking is denied. Please contact admin for more detail.'}}{else if $hotel_booking_detail.id_status != $ROOM_STATUS_ASSIGNED}<span class="badge badge-danger badge-cancelled">{if $hotel_booking_detail.id_status == $ROOM_STATUS_CHECKED_OUT}{l s='Checked-Out'}{else if $hotel_booking_detail.id_status == $ROOM_STATUS_NO_SHOW}{l s='No-show'}{else}{l s='Checked-In'}{/if}</span>{/if}
</div>
</div>