Skip to content

Commit

Permalink
Merge pull request #1097 from sumitwebkul/Refund-Process-Issues
Browse files Browse the repository at this point in the history
Fixed: Issues in Refund management flow and Improved Order cancellation flow
  • Loading branch information
rohit053 authored Jul 2, 2024
2 parents c5122a5 + 4442977 commit 9c2a9e2
Show file tree
Hide file tree
Showing 22 changed files with 802 additions and 620 deletions.
20 changes: 12 additions & 8 deletions admin/themes/default/template/controllers/orders/_product_line.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -193,18 +193,22 @@
</div>
{/if}
</td>
{if (isset($refundReqBookings) && $refundReqBookings) || (isset($isCancelledRoom) && $isCancelledRoom)}
{if (isset($refundReqBookings) && $refundReqBookings)}
<td>
{if $data.is_cancelled}
<span class="badge badge-danger">{l s='Cancelled'}</span>
{elseif isset($data.refund_info) && $data.refund_info}
<span class="badge" style="background-color:{$data.refund_info.color|escape:'html':'UTF-8'}">{$data.refund_info.name|escape:'html':'UTF-8'}</span>
{if $data.id|in_array:$refundReqBookings}
{if $data.is_cancelled}
<span class="badge badge-danger">{l s='Cancelled'}</span>
{elseif isset($data.refund_info) && (!$data.refund_info.refunded || $data.refund_info.id_customization)}
<span class="badge" style="background-color:{$data.refund_info.color|escape:'html':'UTF-8'}">{$data.refund_info.name|escape:'html':'UTF-8'}</span>
{else}
<span>--</span>
{/if}
{else}
<span>--</span>
{/if}
<span>--</span>
{/if}
</td>
<td>
{if isset($data.refund_info) && $data.refund_info}
{if $data.is_refunded && isset($data.refund_info) && $data.refund_info}
{convertPriceWithCurrency price=$data.refund_info.refunded_amount currency=$currency->id}
{else}
--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<th><span class="title_box">{l s='Extra Services/Fee (Tax excl.)'}</span></th>
<th><span class="title_box">{l s='Total Tax'}</span></th>
<th><span class="title_box">{l s='Total Price (Tax incl.)'}</span></th>
{if (isset($refundReqBookings) && $refundReqBookings) || (isset($isCancelledRoom) && $isCancelledRoom)}
{if (isset($refundReqBookings) && $refundReqBookings)}
<th><span class="title_box">{l s='Refund/Cancel Status'}</span></th>
<th><span class="title_box">{l s='Refunded amount'}</span></th>
{/if}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
<th>{l s='Duration'}</th>
<th>{l s='Documents'}</th>
<th>{l s='Room Status'}</th>
<th>{l s='Action'}</th>
<th class="text-center">{l s='Action'}</th>
</tr>
</thead>
<tbody>
Expand Down Expand Up @@ -133,7 +133,7 @@
{/if}
</td>
<td class="text-center">
{if $data.is_refunded || $data.is_cancelled}
{if isset($refundReqBookings) && $refundReqBookings && $data.id|in_array:$refundReqBookings && $data.is_refunded}
<span class="badge badge-danger">{if $data.is_cancelled}{l s='Cancelled'}{else}{l s='Refunded'}{/if}</span>
{else}
<a class="open_room_status_form btn btn-default" href="#" data-id_hotel_booking_detail="{$data['id']}" data-id_order="{$data['id_order']}" data-id_status="{$data['id_status']}" data-id_room="{$data['id_room']}" data-date_from="{$data['date_from']|date_format:"%Y-%m-%d"}" data-date_to="{$data['date_to']|date_format:"%Y-%m-%d"}" data-check_in_time="{$data['check_in_time']}" data-check_out_time="{$data['check_out_time']}">
Expand Down Expand Up @@ -246,7 +246,7 @@
<div class="col-lg-9">
<select id="id_order_state" class="chosen form-control" name="id_order_state">
{foreach from=$states item=state}
<option value="{$state['id_order_state']|intval}"{if isset($currentState) && $state['id_order_state'] == $currentState->id} selected="selected" disabled="disabled"{elseif ($state['id_order_state'] == Configuration::get('PS_OS_REFUND') && !$allBookingsRefunded)} disabled="disabled"{elseif ($state['id_order_state'] == Configuration::get('PS_OS_CANCELED') && !$allBookingsCancelled)} disabled="disabled"{elseif ($state['id_order_state'] == Configuration::get('PS_OS_OVERBOOKING_PAID') || $state['id_order_state'] == Configuration::get('PS_OS_OVERBOOKING_UNPAID') || $state['id_order_state'] == Configuration::get('PS_OS_OVERBOOKING_PARTIAL_PAID')) && (!isset($orderOverBookings) || !$orderOverBookings)} disabled="disabled"{/if}>{$state['name']|escape}</option>
<option value="{$state['id_order_state']|intval}"{if isset($currentState) && $state['id_order_state'] == $currentState->id} selected="selected" disabled="disabled"{elseif ($state['id_order_state'] == Configuration::get('PS_OS_REFUND') && ($total_paid <= 0 && !$discounts|count))} disabled="disabled"{elseif ($state['id_order_state'] == Configuration::get('PS_OS_CANCELED') && ($totalRefundedRooms || $discounts|count || $total_paid > 0))} disabled="disabled"{elseif ($state['id_order_state'] == Configuration::get('PS_OS_OVERBOOKING_PAID') || $state['id_order_state'] == Configuration::get('PS_OS_OVERBOOKING_UNPAID') || $state['id_order_state'] == Configuration::get('PS_OS_OVERBOOKING_PARTIAL_PAID')) && (!isset($orderOverBookings) || !$orderOverBookings)} disabled="disabled"{/if}>{$state['name']|escape}</option>
{/foreach}
</select>
<input type="hidden" name="id_order" value="{$order->id}" />
Expand Down Expand Up @@ -1250,6 +1250,8 @@
{addJsDef ROOM_STATUS_ALLOTED=$ROOM_STATUS_ALLOTED|escape:'quotes':'UTF-8'}
{addJsDef ROOM_STATUS_CHECKED_IN=$ROOM_STATUS_CHECKED_IN|escape:'quotes':'UTF-8'}
{addJsDef ROOM_STATUS_CHECKED_OUT=$ROOM_STATUS_CHECKED_OUT|escape:'quotes':'UTF-8'}
{addJsDef PS_OS_CANCELED=Configuration::get('PS_OS_CANCELED')|escape:'quotes':'UTF-8'}
{addJsDef PS_OS_REFUND=Configuration::get('PS_OS_REFUND')|escape:'quotes':'UTF-8'}

{addJsDefL name=txt_booking_document_upload_success}{l s='Document uploaded successfully.' js=1}{/addJsDefL}
{addJsDefL name=txt_booking_document_delete_confirm}{l s='Are you sure?' js=1}{/addJsDefL}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
<div class="list-empty">
<div class="list-empty-msg">
<i class="icon-warning-sign list-empty-icon"></i>
{l s='No room bookings found.'}
{l s='No room bookings found to cancel'}
</div>
</div>
{/if}
Expand Down
31 changes: 28 additions & 3 deletions classes/order/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -2631,9 +2631,12 @@ public static function getAllOrdersByCartId($id_cart)
* Order::ORDER_COMPLETE_REFUND_FLAG for complete refunded and
* Order::ORDER_COMPLETE_CANCELLATION_FLAG for completely cancelled and
* Order::ORDER_COMPLETE_CANCELLATION_OR_REFUND_REQUEST_FLAG for all rooms are either cancelled or requested for refunded
*
* @param integer includeCheckIn = 1: If you want to get result for rooms that are refunded or cancelled Or Checkin/Checkout. Send $action = 0
*
* @return boolean: true if order has been completely refunded as per requested parameters or false
*/
public function hasCompletelyRefunded($action = 0)
public function hasCompletelyRefunded($action = 0, $includeCheckIn = 0)
{
$objHotelBooking = new HotelBookingdetail();
if ($orderBookings = $objHotelBooking->getOrderCurrentDataByOrderId($this->id)) {
Expand All @@ -2658,18 +2661,35 @@ public function hasCompletelyRefunded($action = 0)
} elseif ($action == Order::ORDER_COMPLETE_CANCELLATION_OR_REFUND_REQUEST_FLAG) {
foreach ($orderBookings as $booking) {
if (!$booking['is_refunded']) {
if (!OrderReturn::getOrdersReturnDetail($this->id, 0, $booking['id'])) {
// If booking refund request is created and request is completed but booking is not refunded then return false
if ($bookingRefundDetail = OrderReturn::getOrdersReturnDetail($this->id, 0, $booking['id'])) {
$bookingRefundDetail = reset($bookingRefundDetail);
if ($bookingRefundDetail['refunded']) {
return false;
}
} else {
return false;
}
}
}

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
$uniqueRefundedBookings = array_unique(array_column($orderBookings, 'is_refunded'));
if (count($uniqueRefundedBookings) == 1 && $uniqueRefundedBookings[0] == 1) {
return true;
} elseif ($includeCheckIn) {
foreach ($orderBookings as $booking) {
if ($booking['is_refunded'] == 0
&& !OrderReturn::getOrdersReturnDetail($this->id, 0, $booking['id'])
&& $booking['id_status'] == HotelBookingDetail::STATUS_ALLOTED
) {
return false;
}
}
return true;
}
}
}
Expand Down Expand Up @@ -2727,7 +2747,12 @@ public function ChangeOrderStatus()
if ($orderBookings = $objHotelBooking->getOrderCurrentDataByOrderId($this->id)) {
foreach ($orderBookings as $orderBooking) {
// If booking is refunded then no need to check inventory
if ((OrderReturn::getOrdersReturnDetail($this->id, 0, $orderBooking['id']) && $orderBooking['is_refunded'])
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'])
) {
continue;
Expand Down
Loading

0 comments on commit 9c2a9e2

Please sign in to comment.