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 prices show in admin refund request controller #1120

Merged
merged 14 commits into from
Aug 14, 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
33 changes: 26 additions & 7 deletions classes/order/OrderReturn.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ public function getOrderRefundRequestedBookings($idOrder, $idOrderReturn = 0, $o
$objBookingDemands = new HotelBookingDemands();
$objRoomTypeServiceProductOrderDetail = new RoomTypeServiceProductOrderDetail();

$calcServicePriceFirst = false;
if ($objOrder->is_advance_payment && $objOrder->advance_paid_amount <= $objOrder->total_paid_real) {
$calcServicePriceFirst = true;
}

foreach ($returnDetails as $key => &$bookingRow) {
if ($skipReqCompletedNonRefunded) {
$objReturnState = new OrderReturnState($bookingRow['id_return_state']);
Expand All @@ -219,11 +224,7 @@ public function getOrderRefundRequestedBookings($idOrder, $idOrderReturn = 0, $o
$bookingRow['extra_service_total_paid_amount'] = 0;
$bookingRow['extra_service_total_price_tax_incl'] = 0;
$bookingRow['room_paid_amount'] = 0;
if ($bookingRow['total_price_tax_incl'] > 0) {
if ($objOrder->total_paid_real > 0) {
$bookingRow['room_paid_amount'] = ($objOrder->total_paid_real*$bookingRow['total_price_tax_incl'])/$objOrder->total_paid_tax_incl;
}
}

$roomSelectedDemands = $objBookingDemands->getRoomTypeBookingExtraDemands(
$idOrder,
$bookingRow['id_product'],
Expand All @@ -236,7 +237,11 @@ public function getOrderRefundRequestedBookings($idOrder, $idOrderReturn = 0, $o
foreach ($roomSelectedDemands as $demand) {
if ($demand['total_price_tax_incl'] > 0) {
if ($objOrder->total_paid_real > 0) {
$bookingRow['extra_service_total_paid_amount'] += ($objOrder->total_paid_real*$demand['total_price_tax_incl'])/$objOrder->total_paid_tax_incl;
if ($calcServicePriceFirst) {
$bookingRow['extra_service_total_paid_amount'] += $demand['total_price_tax_incl'];
} else {
$bookingRow['extra_service_total_paid_amount'] += ($objOrder->total_paid_real*$demand['total_price_tax_incl'])/($objOrder->total_paid_tax_incl + $objOrder->total_discounts_tax_incl);
}
}
$bookingRow['extra_service_total_price_tax_incl'] += $demand['total_price_tax_incl'];
}
Expand All @@ -250,13 +255,27 @@ public function getOrderRefundRequestedBookings($idOrder, $idOrderReturn = 0, $o
foreach ($roomSelectedServices['additional_services'] as $service) {
if ($service['total_price_tax_incl'] > 0) {
if ($objOrder->total_paid_real > 0) {
$bookingRow['extra_service_total_paid_amount'] += ($objOrder->total_paid_real*$service['total_price_tax_incl'])/$objOrder->total_paid_tax_incl;
if ($calcServicePriceFirst) {
$bookingRow['extra_service_total_paid_amount'] += $service['total_price_tax_incl'];
} else {
$bookingRow['extra_service_total_paid_amount'] += ($objOrder->total_paid_real*$service['total_price_tax_incl'])/($objOrder->total_paid_tax_incl + $objOrder->total_discounts_tax_incl);
}
}
$bookingRow['extra_service_total_price_tax_incl'] += $service['total_price_tax_incl'];
}
}
}
}
if ($bookingRow['total_price_tax_incl'] > 0) {
if ($objOrder->total_paid_real > 0) {
if ($calcServicePriceFirst) {
$totalRoomShare = ($objOrder->total_paid_real*($bookingRow['total_price_tax_incl'] + $bookingRow['extra_service_total_price_tax_incl'])/ ($objOrder->total_paid_tax_incl + $objOrder->total_discounts_tax_incl));
$bookingRow['room_paid_amount'] += $totalRoomShare - $bookingRow['extra_service_total_price_tax_incl'];
} else {
$bookingRow['room_paid_amount'] = ($objOrder->total_paid_real*$bookingRow['total_price_tax_incl'])/ ($objOrder->total_paid_tax_incl + $objOrder->total_discounts_tax_incl);
}
}
}
if ($customerView) {
$dateJoin = $bookingRow['id_product'].'_'.strtotime($bookingRow['date_from']).strtotime($bookingRow['date_to']);
if (isset($returnsCustView[$dateJoin]['num_rooms'])) {
Expand Down
25 changes: 25 additions & 0 deletions classes/order/OrderReturnDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,29 @@ class OrderReturnDetailCore extends ObjectModel
'refunded_amount' => array('type' => self::TYPE_FLOAT),
),
);

public static function getReturnDetailByIdBookingDetail($idHtlBooking)
{
$idOrderReturnDetail = Db::getInstance()->getValue('
SELECT `id_order_return_detail` FROM `'._DB_PREFIX_.'order_return_detail` ord
WHERE `id_htl_booking` = '.(int)$idHtlBooking
);

if ($idOrderReturnDetail) {
return new OrderReturnDetail($idOrderReturnDetail);
}
return null;
}

public static function deleteReturnDetailByIdBookingDetail($idOrder, $idHtlBooking)
{
$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();
}
}
}
}
3 changes: 3 additions & 0 deletions controllers/admin/AdminOrdersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5513,6 +5513,9 @@ public function ajaxProcessDeleteRoomLine()
$obj_htl_booking = new HotelBookingDetail();
$delete_room_order = $obj_htl_booking->deleteOrderedRoomFromOrder($id_order, $id_hotel, $id_room, $date_from, $date_to);

// delete refund request of the room if exists.
OrderReturnDetail::deleteReturnDetailByIdBookingDetail($id_order, $idHotelBooking);

// Assign to smarty informations in order to show the new product line
$this->context->smarty->assign(array(
'order' => $order,
Expand Down
13 changes: 4 additions & 9 deletions modules/hotelreservationsystem/classes/HotelOrderRefundRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public function getBookingCancellationDetails($idOrder, $idOrderReturn = 0, $idH
1,
1
);
$paidAmount = $objHtlBooking->total_paid_amount + $totalDemandsPrice + $totalServicesPrice;
$totalAmount = $objHtlBooking->total_price_tax_incl + $totalDemandsPrice + $totalServicesPrice;

if ($refundRules = $objHtlRefundRules->getHotelRefundRules($objHtlBooking->id_hotel, 0, 1)) {
$orderCurrency = $objOrder->id_currency;
Expand Down Expand Up @@ -185,7 +185,7 @@ public function getBookingCancellationDetails($idOrder, $idOrderReturn = 0, $idH

if ($refRule['payment_type'] == HotelOrderRefundRules::WK_REFUND_RULE_PAYMENT_TYPE_PERCENTAGE) {
$bookingCancellationDetail['reduction_type'] = HotelOrderRefundRules::WK_REFUND_RULE_PAYMENT_TYPE_PERCENTAGE;
$bookingCancellationDetail['cancelation_charge'] = $paidAmount * ($refundValue / 100);
$bookingCancellationDetail['cancelation_charge'] = $totalAmount * ($refundValue / 100);
} else {
$bookingCancellationDetail['reduction_type'] = HotelOrderRefundRules::WK_REFUND_RULE_PAYMENT_TYPE_FIXED;
if ($defaultCurrency != $orderCurrency) {
Expand All @@ -197,11 +197,6 @@ public function getBookingCancellationDetails($idOrder, $idOrderReturn = 0, $idH
} else {
$bookingCancellationDetail['cancelation_charge'] = $refundValue;
}

// if deduction amount is more than the order total cost
if ($bookingCancellationDetail['cancelation_charge'] > $paidAmount) {
$bookingCancellationDetail['cancelation_charge'] = $paidAmount;
}
}

$ruleApplied = true;
Expand All @@ -210,12 +205,12 @@ public function getBookingCancellationDetails($idOrder, $idOrderReturn = 0, $idH
}

if (!$ruleApplied) {
$bookingCancellationDetail['cancelation_charge'] = $paidAmount;
$bookingCancellationDetail['cancelation_charge'] = $totalAmount;
$bookingCancellationDetail['reduction_type'] = HotelOrderRefundRules::WK_REFUND_RULE_PAYMENT_TYPE_PERCENTAGE;
$bookingCancellationDetail['reduction_value'] = 100;
}
} else {
$bookingCancellationDetail['cancelation_charge'] = $paidAmount;
$bookingCancellationDetail['cancelation_charge'] = $totalAmount;
$bookingCancellationDetail['reduction_type'] = HotelOrderRefundRules::WK_REFUND_RULE_PAYMENT_TYPE_PERCENTAGE;
$bookingCancellationDetail['reduction_value'] = 100;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,61 +267,65 @@ public function postProcess()

$idRefundState = Tools::getValue('id_refund_state');
if (Validate::isLoadedObject($objRefundState = new OrderReturnState($idRefundState))) {
if ($objRefundState->refunded) {
$refundedAmounts = Tools::getValue('refund_amounts');
if ($hasOrderDiscountOrPayment) {
if ($idsReturnDetail && count($idsReturnDetail)) {
if ($refundedAmounts) {
foreach ($idsReturnDetail as $idRetDetail) {
if (!isset($refundedAmounts[$idRetDetail]) || !Validate::isPrice($refundedAmounts[$idRetDetail])) {
$this->errors[] = $this->l('Invalid refund amount(s) entered.');
if ($idRefundState != $objOrderReturn->state) {
if ($objRefundState->refunded) {
$refundedAmounts = Tools::getValue('refund_amounts');
if ($hasOrderDiscountOrPayment) {
if ($idsReturnDetail && count($idsReturnDetail)) {
if ($refundedAmounts) {
foreach ($idsReturnDetail as $idRetDetail) {
if (!isset($refundedAmounts[$idRetDetail]) || !Validate::isPrice($refundedAmounts[$idRetDetail])) {
$this->errors[] = $this->l('Invalid refund amount(s) entered.');
}
}
} else {
$this->errors[] = $this->l('Invalid refund amount(s) entered.');
}
} else {
$this->errors[] = $this->l('Invalid refund amount(s) entered.');
}

// If there are no errors in the refund amounts the check validations depends on refund amount
if (!count($this->errors)) {
$totalRefundAmount = array_sum($refundedAmounts);
if (Tools::isSubmit('generateCreditSlip')) {
if ($totalRefundAmount <= 0) {
$this->errors[] = $this->l('Invalid refund amount(s) for generating credit slip.');
// If there are no errors in the refund amounts the check validations depends on refund amount
if (!count($this->errors)) {
$totalRefundAmount = array_sum($refundedAmounts);
if (Tools::isSubmit('generateCreditSlip')) {
if ($totalRefundAmount <= 0) {
$this->errors[] = $this->l('Invalid refund amount(s) for generating credit slip.');
}
}
}
if (Tools::isSubmit('generateDiscount')) {
if ($totalRefundAmount <= 0) {
$this->errors[] = $this->l('Invalid refund amount(s) for generating voucher.');
if (Tools::isSubmit('generateDiscount')) {
if ($totalRefundAmount <= 0) {
$this->errors[] = $this->l('Invalid refund amount(s) for generating voucher.');
}
}
}

if (Tools::isSubmit('refundTransactionAmount')) {
if ($totalRefundAmount <= 0) {
$this->errors[] = $this->l('Invalid refund amount(s) for entering refund transaction details.');
} else {
$paymentMode = Tools::getValue('payment_method');
if (!$paymentMode) {
$paymentMode = Tools::getValue('other_payment_mode');
if (Tools::isSubmit('refundTransactionAmount')) {
if ($totalRefundAmount <= 0) {
$this->errors[] = $this->l('Invalid refund amount(s) for entering refund transaction details.');
} else {
$paymentMode = Tools::getValue('payment_method');
if (!$paymentMode) {
$this->errors[] = $this->l('Please enter the payment mode of the refund transaction.');
} elseif (!Validate::isGenericName($paymentMode)) {
$this->errors[] = $this->l('Invalid payment mode entered.');
$paymentMode = Tools::getValue('other_payment_mode');
if (!$paymentMode) {
$this->errors[] = $this->l('Please enter the payment mode of the refund transaction.');
} elseif (!Validate::isGenericName($paymentMode)) {
$this->errors[] = $this->l('Invalid payment mode entered.');
}
}
}

$idTransaction = Tools::getValue('id_transaction');
if (!$idTransaction) {
$this->errors[] = $this->l('Please enter the transaction id of the refund transaction.');
} elseif (!Validate::isGenericName($idTransaction)) {
$this->errors[] = $this->l('Invalid transaction id entered.');
$idTransaction = Tools::getValue('id_transaction');
if (!$idTransaction) {
$this->errors[] = $this->l('Please enter the transaction id of the refund transaction.');
} elseif (!Validate::isGenericName($idTransaction)) {
$this->errors[] = $this->l('Invalid transaction id entered.');
}
}
}
}
} else {
$this->errors[] = $this->l('Select at least one booking for refund.');
}
} else {
$this->errors[] = $this->l('Select at least one booking for refund.');
}
}
} else {
$this->errors[] = $this->l('Please select a different refund status.');
}
} else {
$this->errors[] = $this->l('Invalid refund state.');
Expand Down