Order Status changes, Refund issues resolved and order cancellation process impeoved

This commit is contained in:
Sumit Panwar
2023-10-24 17:25:58 +05:30
parent ce93a9826f
commit 5c0d3cb2af
12 changed files with 695 additions and 373 deletions

View File

@@ -23,7 +23,7 @@
* International Registered Trademark & Property of PrestaShop SA
*}
<tr class="product-line-row" data-id_room="{$data.id_room}" data-id_product="{$data.id_product}" data-id_hotel="{$data.id_hotel}" data-date_from="{$data.date_from}" data-date_to="{$data.date_to}" data-product_price="{$data.unit_amt_tax_incl}" data-id_order_detail="{$data.id_order_detail}">
<tr class="product-line-row" data-id_htl_booking="{$data.id|escape:'html':'UTF-8'}" data-id_room="{$data.id_room}" data-id_product="{$data.id_product}" data-id_hotel="{$data.id_hotel}" data-date_from="{$data.date_from}" data-date_to="{$data.date_to}" data-product_price="{$data.unit_amt_tax_incl}" data-id_order_detail="{$data.id_order_detail}">
{if $refund_allowed}
<td class="standard_refund_fields" style="display:none">
<input type="checkbox" name="id_htl_booking[]" value="{$data.id|escape:'html':'UTF-8'}" {if isset($refundReqBookings) && ($data.id|in_array:$refundReqBookings)}disabled{/if}/>
@@ -265,7 +265,7 @@
<li>
<a href="#" data-toggle="modal" data-target="#mySwappigModal" data-id_order="{$order->id}" data-room_num='{$data.room_num}' data-date_from='{$data.date_from}' data-date_to='{$data.date_to}' data-id_room='{$data.id_room}' data-cust_name='{$data.alloted_cust_name}' data-cust_email='{$data.alloted_cust_email}' data-avail_rm_swap='{$data.avail_rooms_to_swap|@json_encode}' data-avail_rm_realloc='{$data.avail_rooms_to_realloc|@json_encode}'>
<i class="icon-refresh"></i>
{l s='Reallocate Room'}
{l s='Reallocate/Swap Room'}
</a>
</li>
<li>

View File

@@ -232,23 +232,26 @@
</table>
</div>
<!-- Change status form -->
<form action="{$currentIndex|escape:'html':'UTF-8'}&amp;vieworder&amp;token={$smarty.get.token}" method="post" class="form-horizontal well hidden-print">
<div class="row">
<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"{/if}>{$state['name']|escape}</option>
{/foreach}
</select>
<input type="hidden" name="id_order" value="{$order->id}" />
</div>
<div class="col-lg-3">
<button type="submit" name="submitState" class="btn btn-primary">
{l s='Update status'}
</button>
</div>
</div>
</form>
{* If current state is refunded or cancelled the further order status changes are not allowed *}
{if !isset($currentState) || (isset($currentState) && ($currentState->id != Configuration::get('PS_OS_REFUND') && $currentState->id != Configuration::get('PS_OS_CANCELED')))}
<form action="{$currentIndex|escape:'html':'UTF-8'}&amp;vieworder&amp;token={$smarty.get.token}" method="post" class="form-horizontal well hidden-print">
<div class="row">
<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>
{/foreach}
</select>
<input type="hidden" name="id_order" value="{$order->id}" />
</div>
<div class="col-lg-3">
<button type="submit" name="submitState" class="btn btn-primary">
{l s='Update status'}
</button>
</div>
</div>
</form>
{/if}
</div>
<!-- Tab documents -->
<div class="tab-pane" id="documents">
@@ -281,57 +284,65 @@
</tr>
{if isset($htl_booking_order_data) && $htl_booking_order_data}
{foreach from=$htl_booking_order_data item=data}
{if !$data.is_refunded}
<tr>
<td>
{$data['room_num']}
</td>
<td>
<a href="{$link->getAdminLink('AdminAddHotel')}&amp;id={$data['id_hotel']}&amp;updatehtl_branch_info" target="_blank">
<span>{$data['hotel_name']}</span>
</a>
</td>
<td>
{dateFormat date=$data['date_from']} - {dateFormat date=$data['date_to']}
</td>
<td>
<a class="btn btn-default" onclick="BookingDocumentsModal.init({$data.id|intval}, this); return false;">
<i class="icon icon-file-text"></i>
{l s='Documents'} <span class="badge badge-info count-documents">{$data.num_checkin_documents}</span>
</a>
</td>
<td>
<form action="" method="post" class="form-horizontal row room_status_info_form">
<div class="col-sm-7">
<select name="booking_order_status" class="form-control booking_order_status margin-bottom-5">
{foreach from=$hotel_order_status item=state}
<option value="{$state['id_status']|intval}" {if isset($data.id_status) && $state.id_status == $data.id_status} selected="selected" disabled="disabled"{/if}>{$state.name|escape}</option>
{/foreach}
</select>
<tr>
<td>
{$data['room_num']}
</td>
<td>
<a href="{$link->getAdminLink('AdminAddHotel')}&amp;id={$data['id_hotel']}&amp;updatehtl_branch_info" target="_blank">
<span>{$data['hotel_name']}</span>
</a>
</td>
<td>
{dateFormat date=$data['date_from']} - {dateFormat date=$data['date_to']}
</td>
<td>
<a class="btn btn-default" onclick="BookingDocumentsModal.init({$data.id|intval}, this); return false;">
<i class="icon icon-file-text"></i>
{l s='Documents'} <span class="badge badge-info count-documents">{$data.num_checkin_documents}</span>
</a>
</td>
<td>
<form action="" method="post" class="form-horizontal row room_status_info_form">
<div class="col-sm-7">
{if $data.is_refunded || $data.is_cancelled}
{if $data['id_status'] == $hotel_order_status['STATUS_ALLOTED']['id_status']}
<p><span class="badge badge-infomation">{l s='Room alloted'}</span></p>
{/if}
{else}
<select name="booking_order_status" class="form-control booking_order_status margin-bottom-5">
{foreach from=$hotel_order_status item=state}
<option value="{$state['id_status']|intval}" {if isset($data.id_status) && $state.id_status == $data.id_status} selected="selected" disabled="disabled"{/if}>{$state.name|escape}</option>
{/foreach}
</select>
{/if}
{if $data['id_status'] == $hotel_order_status['STATUS_CHECKED_IN']['id_status']}
<p class="text-center"><span class="badge badge-success margin-bottom-5">{l s='Checked in on'} {dateFormat date=$data['check_in']}</span></p>
{elseif $data['id_status'] == $hotel_order_status['STATUS_CHECKED_OUT']['id_status']}
<p class="text-center"><span class="badge badge-success margin-bottom-5">{l s='Checked out on'} {dateFormat date=$data['check_out']}</span></p>
{/if}
{if $data['id_status'] == $hotel_order_status['STATUS_CHECKED_IN']['id_status']}
<p><span class="badge badge-success">{l s='Checked in on'} {dateFormat date=$data['check_in']}</span></p>
{elseif $data['id_status'] == $hotel_order_status['STATUS_CHECKED_OUT']['id_status']}
<p><span class="badge badge-success">{l s='Checked out on'} {dateFormat date=$data['check_out']}</span></p>
{/if}
{* field for the current date *}
<input class="room_status_date wk-input-date" type="text" name="status_date" value="{if $data['id_status'] == $hotel_order_status['STATUS_CHECKED_IN']['id_status']}{$data['date_to']|date_format:"%d-%m-%Y"}{else}{$data['date_from']|date_format:"%d-%m-%Y"}{/if}" readonly/>
{* field for the current date *}
<input class="room_status_date wk-input-date" type="text" name="status_date" value="{if $data['id_status'] == $hotel_order_status['STATUS_CHECKED_IN']['id_status']}{$data['date_to']|date_format:"%d-%m-%Y"}{else}{$data['date_from']|date_format:"%d-%m-%Y"}{/if}" readonly/>
<input type="hidden" name="date_from" value="{$data['date_from']|date_format:"%Y-%m-%d"}" />
<input type="hidden" name="date_to" value="{$data['date_to']|date_format:"%Y-%m-%d"}" />
<input type="hidden" name="id_room" value="{$data['id_room']}" />
<input type="hidden" name="id_order" value="{$order->id}" />
</div>
<div class="col-sm-5">
<button type="submit" name="submitbookingOrderStatus" class="btn btn-primary">
{l s='Update Status'}
</button>
</div>
</form>
</td>
</tr>
{/if}
<input type="hidden" name="date_from" value="{$data['date_from']|date_format:"%Y-%m-%d"}" />
<input type="hidden" name="date_to" value="{$data['date_to']|date_format:"%Y-%m-%d"}" />
<input type="hidden" name="id_room" value="{$data['id_room']}" />
<input type="hidden" name="id_order" value="{$order->id}" />
</div>
<div class="col-sm-5 text-right">
{if $data.is_refunded || $data.is_cancelled}
<span class="badge badge-danger">{if $data.is_cancelled}{l s='Cancelled'}{else}{l s='Refunded'}{/if}</span>
{else}
<button type="submit" name="submitbookingOrderStatus" class="btn btn-primary">
{l s='Update Status'}
</button>
{/if}
</div>
</form>
</td>
</tr>
{/foreach}
{else}
<tr>
@@ -1185,9 +1196,11 @@
<input type="hidden" name="TaxMethod" value="1">
{/if}
{if $can_edit}
<div class="row-margin-bottom row-margin-top standard_refund_fields" style="display: none;">
<textarea class="cancellation_reason" name="cancellation_reason" placeholder="{l s='Enter reason to cancel bookings'}"></textarea>
</div>
{if $refund_allowed && !$hasCompletelyRefunded}
<div class="row-margin-bottom row-margin-top standard_refund_fields" style="display: none;">
<textarea class="cancellation_reason" name="cancellation_reason" placeholder="{l s='Enter reason to cancel bookings'}"></textarea>
</div>
{/if}
<div class="row-margin-bottom row-margin-top order_action">
{if !$order->hasBeenDelivered()}
{* <button type="button" id="add_product" class="btn btn-default">
@@ -1394,16 +1407,14 @@
</tr>
{/if}
{if $order->total_paid_tax_incl > $order->total_paid_real}
<tr>
<td class="text-right"><strong>{l s='Due Amount'}</strong></td>
<td class="amount text-right nowrap">
<strong>
{displayPrice currency=$order->id_currency price=($order->total_paid_tax_incl - $order->total_paid_real)}
</strong>
</td>
</tr>
{/if}
<tr>
<td class="text-right"><strong>{l s='Due Amount'}</strong></td>
<td class="amount text-right nowrap">
<strong>
{displayPrice currency=$order->id_currency price=($order->total_paid_tax_incl - $order->total_paid_real)}
</strong>
</td>
</tr>
</table>
</div>
</div>
@@ -1629,6 +1640,7 @@
{addJsDefL name='invalid_occupancy_txt'}{l s='Invalid occupancy(adults/children) found.' js=1}{/addJsDefL}
{addJsDef max_child_age=$max_child_age|escape:'quotes':'UTF-8'}
{addJsDef max_child_in_room=$max_child_in_room|escape:'quotes':'UTF-8'}
{addJsDefL name='undo_cancellation_success'}{l s='Booking cancellation undo process is done successfully.' js=1}{/addJsDefL}
{/strip}
{* Apply javascript for the page *}

View File

@@ -1005,11 +1005,9 @@ abstract class PaymentModuleCore extends Module
// Set the order status
$new_history = new OrderHistory();
$new_history->id_order = (int)$order->id;
if ($order_status->logable && $order->is_advance_payment && $order->advance_paid_amount < $order->total_paid_tax_incl) {
$new_history->changeIdOrderState((int)Configuration::get('PS_OS_PARTIAL_PAYMENT'), $order, true);
} else {
$new_history->changeIdOrderState((int)$id_order_state, $order, true);
}
$new_history->changeIdOrderState((int)$id_order_state, $order, true);
$new_history->addWithemail(true, $extra_vars);
// Switch to back order if needed

View File

@@ -34,6 +34,9 @@ class OrderCore extends ObjectModel
const ORDER_PAYMENT_TYPE_FULL = 1;
const ORDER_PAYMENT_TYPE_ADVANCE = 2;
const ORDER_COMPLETE_REFUND_FLAG = 1;
const ORDER_COMPLETE_CANCELLATION_FLAG = 2;
/** @var int Delivery address id */
public $id_address_delivery;
@@ -2599,51 +2602,41 @@ class OrderCore extends ObjectModel
return Db::getInstance()->executeS('SELECT * FROM '._DB_PREFIX_.'orders WHERE id_cart = '.(int)$id_cart);
}
// Order is considered as refunded if all bookings are requested for refund and all are with refunded status
// $refundFlag [ORDER_RETURN_STATE_FLAG_REFUNDED || ORDER_RETURN_STATE_FLAG_DENIED]
public function hasCompletelyRefunded($refundFlag = 0)
/**
* Function to check if order has been completely refunded
* @param integer action: Order::ORDER_COMPLETE_REFUND_FLAG for complete refunded and
* Order::ORDER_COMPLETE_CANCELLATION_FLAG for completely cancelled
* @return boolean: true if order has been completely refunded as per requested parameters or false
*/
public function hasCompletelyRefunded($action = 0)
{
$objHotelBooking = new HotelBookingdetail();
if ($refundBookings = OrderReturn::getOrdersReturnDetail($this->id)) {
if ($orderBookings = $objHotelBooking->getOrderCurrentDataByOrderId($this->id)) {
if (count($refundBookings) == count($orderBookings)) {
if ($refundFlag) {
foreach ($refundBookings as $refundRow) {
if (Validate::isLoadedObject(
$objReturnState = new OrderReturnState($refundRow['state']
))) {
if ($refundFlag == OrderReturnState::ORDER_RETURN_STATE_FLAG_REFUNDED
&& !$objReturnState->refunded
) {
return false;
}
if ($refundFlag == OrderReturnState::ORDER_RETURN_STATE_FLAG_DENIED
&& !$objReturnState->denied
) {
return false;
}
}
if ($orderBookings = $objHotelBooking->getOrderCurrentDataByOrderId($this->id)) {
// 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) {
$uniqueRefundedBookings = array_unique(array_column($orderBookings, 'is_refunded'));
if (count($uniqueRefundedBookings) == 1 && $uniqueRefundedBookings[0] == 1) {
foreach ($orderBookings as $booking) {
if ($booking['is_cancelled'] == 0) {
return true;
}
}
}
// 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) {
$uniqueRefundedBookings = array_unique(array_column($orderBookings, 'is_cancelled'));
if (count($uniqueRefundedBookings) == 1 && $uniqueRefundedBookings[0] == 1) {
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 ($orderBookings = $objHotelBooking->getOrderCurrentDataByOrderId($this->id)) {
if (count(array_unique(array_column($orderBookings, 'is_cancelled'))) === 1
&& array_unique(array_column($orderBookings, 'is_cancelled'))[0] != 0
) {
return true;
}
}
return false;
}
// Order is considered as denied if all bookings are requested for refund and all are with denied status
public function orderRefundHasBeenDenied()
{
if (OrderReturn::getOrdersReturn($this->id_customer, $this->id)) {
}
return false;

View File

@@ -158,7 +158,8 @@ class OrderReturnCore extends ObjectModel
public function hasBeenCompleted()
{
if (Validate::isLoadedObject($objReturnState = new OrderReturnState($this->state))) {
if ($objReturnState->denied || $objReturnState->refunded) {
// refund process will be considered as completed when the state is "Refunded"
if ($objReturnState->refunded) {
return true;
}
}

View File

@@ -251,8 +251,9 @@ class AdminOrdersControllerCore extends AdminController
$this->access_where = ' WHERE hbd.id_hotel IN ('.implode(',', $acsHtls).')';
}
parent::__construct();
$this->_conf[101] = $this->l('Booking cancellation undo has been done successfully.');
}
public static function setOrderCurrency($echo, $tr)
@@ -690,7 +691,74 @@ class AdminOrdersControllerCore extends AdminController
$this->errors[] = Tools::displayError('The new order status is invalid.');
} else {
$current_order_state = $order->getCurrentOrderState();
if ($current_order_state->id != $order_state->id) {
if ($current_order_state->id == Configuration::get('PS_OS_REFUND')) {
$this->errors[] = Tools::displayError('Order status can not be changed once order status is set to Refunded.');
} elseif ($current_order_state->id == Configuration::get('PS_OS_CANCELED')) {
$this->errors[] = Tools::displayError('Order status can not be changed once order status is set to Cancelled.');
} elseif (in_array($order_state->id, array (Configuration::get('PS_OS_OVERBOOKING_PAID'), Configuration::get('PS_OS_OVERBOOKING_UNPAID'), Configuration::get('PS_OS_OVERBOOKING_PARTIAL_PAID')))) {
$objHotelBooking = new HotelBookingDetail();
if (!$objHotelBooking->getOverbookedRooms($order->id)) {
$this->errors[] = Tools::displayError('Order status can not be changed to any overbooking status as there are no overbooked rooms in the order.');
}
} elseif ($order_state->id == Configuration::get('PS_OS_REFUND')
&& !$order->hasCompletelyRefunded(Order::ORDER_COMPLETE_REFUND_FLAG)
) {
$this->errors[] = Tools::displayError('Order status can not be set to Refunded until all bookings in the order are completely refunded.');
} elseif ($order_state->id == Configuration::get('PS_OS_CANCELED')
&& !$order->hasCompletelyRefunded(Order::ORDER_COMPLETE_CANCELLATION_FLAG)
) {
$this->errors[] = Tools::displayError('Order status can not be set to Cancelled until all bookings in the order are cancelled.');
} elseif ($current_order_state->id == Configuration::get('PS_OS_ERROR') && !$order_state->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
$objHotelBooking = new HotelBookingDetail();
if ($orderBookings = $objHotelBooking->getOrderCurrentDataByOrderId($order->id)) {
foreach ($orderBookings as $orderBooking) {
// If booking is refunded then no need to check inventory
if (OrderReturn::getOrdersReturnDetail($order->id, 0, $orderBooking['id']) && $orderBooking['is_refunded']) {
continue;
} else {
// if inventory is available for that booking
$bookingParams = array(
'date_from' => $orderBooking['date_from'],
'date_to' => $orderBooking['date_to'],
'hotel_id' => $orderBooking['id_hotel'],
'id_room_type' => $orderBooking['id_product'],
'only_search_data' => 1
);
// Check if undo booking cancellation is available for the booking or not
$objHotelBookingDetail = new HotelBookingDetail($orderBooking['id']);
if ($objHotelBookingDetail->isUndoBookingCancellationAvailable()) {
if ($searchRoomsInfo = $objHotelBooking->getBookingData($bookingParams)) {
if (isset($searchRoomsInfo['rm_data'][$orderBooking['id_product']]['data']['available'])
&& $searchRoomsInfo['rm_data'][$orderBooking['id_product']]['data']['available']
) {
$availableRoomsInfo = $searchRoomsInfo['rm_data'][$orderBooking['id_product']]['data']['available'];
if ($roomIdsAvailable = array_column($availableRoomsInfo, 'id_room')) {
// Check If room is still there in the available rooms list
if (!in_array($orderBooking['id_room'], $roomIdsAvailable)) {
$this->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 {
$this->errors[] = Tools::displayError('You can not change the order status as some rooms are not available for undoing booking cancellation.');
break;
}
}
}
}
} elseif ($current_order_state->id == $order_state->id) {
$this->errors[] = Tools::displayError('The order has already been assigned this status.');
}
// If no errors then we change the order status
if (!count($this->errors)) {
// Create new OrderHistory
$history = new OrderHistory();
$history->id_order = $order->id;
@@ -718,9 +786,8 @@ class AdminOrdersControllerCore extends AdminController
Tools::redirectAdmin(self::$currentIndex.'&id_order='.(int)$order->id.'&vieworder&token='.$this->token);
}
$this->errors[] = Tools::displayError('An error occurred while changing order status, or we were unable to send an email to the customer.');
} else {
$this->errors[] = Tools::displayError('The order has already been assigned this status.');
}
}
} else {
@@ -846,26 +913,58 @@ class AdminOrdersControllerCore extends AdminController
}
if (!count($this->errors)) {
$objOrderReturn = new OrderReturn();
$objOrderReturn->id_customer = $order->id_customer;
$objOrderReturn->id_order = $order->id;
$objOrderReturn->state = Configuration::get('PS_ORS_PENDING');
$objOrderReturn->by_admin = 1;
$objOrderReturn->question = $refundReason;
$objOrderReturn->save();
if ($objOrderReturn->id) {
// if amount paid is > 0 then create refund request else cancel the booking directly
if ($order->getTotalPaid() > 0) {
$objOrderReturn = new OrderReturn();
$objOrderReturn->id_customer = $order->id_customer;
$objOrderReturn->id_order = $order->id;
$objOrderReturn->state = Configuration::get('PS_ORS_PENDING');
$objOrderReturn->by_admin = 1;
$objOrderReturn->question = $refundReason;
$objOrderReturn->save();
if ($objOrderReturn->id) {
foreach ($bookings as $idHtlBooking) {
$objHtlBooking = new HotelBookingDetail($idHtlBooking);
$numDays = $objHtlBooking->getNumberOfDays(
$objHtlBooking->date_from,
$objHtlBooking->date_to
);
$objOrderReturnDetail = new OrderReturnDetail();
$objOrderReturnDetail->id_order_return = $objOrderReturn->id;
$objOrderReturnDetail->id_order_detail = $objHtlBooking->id_order_detail;
$objOrderReturnDetail->product_quantity = $numDays;
$objOrderReturnDetail->id_htl_booking = $idHtlBooking;
$objOrderReturnDetail->save();
}
}
} else {
// cancel the booking directly
foreach ($bookings as $idHtlBooking) {
$objHtlBooking = new HotelBookingDetail($idHtlBooking);
$numDays = $objHtlBooking->getNumberOfDays(
$objHtlBooking->date_from,
$objHtlBooking->date_to
);
$objOrderReturnDetail = new OrderReturnDetail();
$objOrderReturnDetail->id_order_return = $objOrderReturn->id;
$objOrderReturnDetail->id_order_detail = $objHtlBooking->id_order_detail;
$objOrderReturnDetail->product_quantity = $numDays;
$objOrderReturnDetail->id_htl_booking = $idHtlBooking;
$objOrderReturnDetail->save();
if (!$objHtlBooking->processRefundInBookingTables()) {
$this->errors[] = Tools::displayError('An error occurred while cancelling the booking.');
} else {
// set the message for the cancellation
$message = $this->l('Room').': '.$objHtlBooking->room_num.', '.$objHtlBooking->room_type_name.' '.$this->l('has been cancelled by the hotel.');
$message .= PHP_EOL.$this->l('Reasonn').': '.$refundReason;
$objHtlBooking->setBookingCancellationMessage($message, 1);
}
}
// if all bookings are getting refunded then cancel the order also
if ($order->hasCompletelyRefunded(Order::ORDER_COMPLETE_REFUND_FLAG)) {
$objOrderHistory = new OrderHistory();
$objOrderHistory->id_order = (int)$order->id;
$idOrderState = Configuration::get('PS_OS_CANCELED');
$useExistingPayment = false;
if (!$order->hasInvoice()) {
$useExistingPayment = true;
}
$objOrderHistory->changeIdOrderState($idOrderState, $order, $useExistingPayment);
$objOrderHistory->addWithemail();
}
}
}
@@ -1751,6 +1850,7 @@ class AdminOrdersControllerCore extends AdminController
// applicable refund policies
$applicableRefundPolicies = HotelOrderRefundRules::getApplicableRefundRules($order->id);
$this->tpl_view_vars = array(
// refund info
'refund_allowed' => (int) $order->isReturnable(),
@@ -1758,6 +1858,8 @@ class AdminOrdersControllerCore extends AdminController
'returns' => OrderReturn::getOrdersReturn($order->id_customer, $order->id),
'refundReqBookings' => $refundReqBookings,
'hasCompletelyRefunded' => $order->hasCompletelyRefunded(),
'allBookingsRefunded' => $order->hasCompletelyRefunded(Order::ORDER_COMPLETE_REFUND_FLAG),
'allBookingsCancelled' => $order->hasCompletelyRefunded(Order::ORDER_COMPLETE_CANCELLATION_FLAG),
'refundedAmount' => $refundedAmount,
'totalDemandsPriceTI' => $totalDemandsPriceTI,
'totalDemandsPriceTE' => $totalDemandsPriceTE,
@@ -4176,6 +4278,59 @@ class AdminOrdersControllerCore extends AdminController
)));
}
public function ajaxProcessUndoBookingCancellation()
{
$result = array();
$result['success'] = 0;
$result['error'] = '';
$idHotelBooking = Tools::getValue('id_htl_booking');;
if (Validate::isLoadedObject($objHotelBooking = new HotelBookingDetail($idHotelBooking))) {
Hook::exec('actionUndoBookingCancellation', array('id_htl_booking' => $idHotelBooking));
// if inventory is available for that booking
$bookingParams = array(
'date_from' => $objHotelBooking->date_from,
'date_to' => $objHotelBooking->date_to,
'hotel_id' => $objHotelBooking->id_hotel,
'id_room_type' => $objHotelBooking->id_product,
'only_search_data' => 1
);
if ($searchRoomsInfo = $objHotelBooking->getBookingData($bookingParams)) {
if (isset($searchRoomsInfo['rm_data'][$objHotelBooking->id_product]['data']['available'])
&& $searchRoomsInfo['rm_data'][$objHotelBooking->id_product]['data']['available']
) {
$availableRoomsInfo = $searchRoomsInfo['rm_data'][$objHotelBooking->id_product]['data']['available'];
if ($roomIdsAvailable = array_column($availableRoomsInfo, 'id_room')) {
// Check If room is still there in the available rooms list
if (in_array($objHotelBooking->id_room, $roomIdsAvailable)) {
// Undo the cancellation
$objHotelBooking->is_cancelled = 0;
$objHotelBooking->is_refunded = 0;
if ($objHotelBooking->save()) {
$result['success'] = 1;
$result['redirect'] = self::$currentIndex.'&id_order='.(int) $objHotelBooking->id_order.'&vieworder&conf=101&token='.$this->token;
}
} else {
$result['error'] = Tools::displayError('You can not undo the cancellation as this room is not available now.');
}
} else {
$result['error'] = Tools::displayError('You can not undo the cancellation as this room is not available now.');
}
} else {
$result['error'] = Tools::displayError('You can not undo the cancellation as this room is not available now.');
}
} else {
$result['error'] = Tools::displayError('Some error occurred while undoing the cancellation.');
}
} else {
$result['error'] = Tools::displayError('Some error occurred while undoing the cancellation.');
}
die(json_encode($result));
}
public function ajaxProcessDeleteProductLine()
{
$res = true;

View File

@@ -412,28 +412,28 @@ class AdminStatusesControllerCore extends AdminController
'name' => 'name'
),
),
array(
'type' => 'checkbox',
'name' => 'pdf_delivery',
'values' => array(
'query' => array(
array('id' => 'on', 'name' => $this->l('Attach delivery slip PDF to email.'), 'val' => '1'),
),
'id' => 'id',
'name' => 'name'
),
),
array(
'type' => 'checkbox',
'name' => 'shipped',
'values' => array(
'query' => array(
array('id' => 'on', 'name' => $this->l('Set the order as shipped.'), 'val' => '1'),
),
'id' => 'id',
'name' => 'name'
)
),
// array(
// 'type' => 'checkbox',
// 'name' => 'pdf_delivery',
// 'values' => array(
// 'query' => array(
// array('id' => 'on', 'name' => $this->l('Attach delivery slip PDF to email.'), 'val' => '1'),
// ),
// 'id' => 'id',
// 'name' => 'name'
// ),
// ),
// array(
// 'type' => 'checkbox',
// 'name' => 'shipped',
// 'values' => array(
// 'query' => array(
// array('id' => 'on', 'name' => $this->l('Set the order as shipped.'), 'val' => '1'),
// ),
// 'id' => 'id',
// 'name' => 'name'
// )
// ),
array(
'type' => 'checkbox',
'name' => 'paid',
@@ -445,17 +445,17 @@ class AdminStatusesControllerCore extends AdminController
'name' => 'name'
)
),
array(
'type' => 'checkbox',
'name' => 'delivery',
'values' => array(
'query' => array(
array('id' => 'on', 'name' => $this->l('Show delivery PDF.'), 'val' => '1'),
),
'id' => 'id',
'name' => 'name'
)
),
// array(
// 'type' => 'checkbox',
// 'name' => 'delivery',
// 'values' => array(
// 'query' => array(
// array('id' => 'on', 'name' => $this->l('Show delivery PDF.'), 'val' => '1'),
// ),
// 'id' => 'id',
// 'name' => 'name'
// )
// ),
array(
'type' => 'select_template',
'is_customer_template' => 1,

View File

@@ -244,41 +244,68 @@ class OrderDetailControllerCore extends FrontController
}
$res = true;
if (!$hasError) {
if ((int)$order->total_paid_real == 0){
// if amount paid is > 0 then create refund request else cancel the booking directly
if ($order->getTotalPaid() > 0) {
$objOrderReturn = new OrderReturn();
$objOrderReturn->id_customer = $order->id_customer;
$objOrderReturn->id_order = $order->id;
$objOrderReturn->state = 0;
$objOrderReturn->by_admin = 0;
$objOrderReturn->question = $refundReason;
$objOrderReturn->save();
if ($objOrderReturn->id) {
foreach ($bookingRefunds as $idHtlBooking) {
$objHtlBooking = new HotelBookingDetail($idHtlBooking);
$numDays = $objHtlBooking->getNumberOfDays(
$objHtlBooking->date_from,
$objHtlBooking->date_to
);
$objOrderReturnDetail = new OrderReturnDetail();
$objOrderReturnDetail->id_order_return = $objOrderReturn->id;
$objOrderReturnDetail->id_order_detail = $objHtlBooking->id_order_detail;
$objOrderReturnDetail->product_quantity = $numDays;
$objOrderReturnDetail->id_htl_booking = $idHtlBooking;
$objOrderReturnDetail->save();
}
}
// Emails to customer, admin on refund request state change
$objOrderReturn->changeIdOrderReturnState(Configuration::get('PS_ORS_PENDING'));
} else {
// cancel the booking directly
foreach ($bookingRefunds as $idHtlBooking) {
$objHtlBooking = new HotelBookingDetail($idHtlBooking);
$objHtlBooking->save();
if (!$objHtlBooking->processRefundInBookingTables()) {
die(json_encode(array('status' => 0)));
} else {
// set the message for the cancellation
$message = $this->l('1 Room from').' '.', '.$objHtlBooking->room_type_name.' '.$this->l('has been cancelled by the hotel.');
$message .= PHP_EOL.$this->l('Reasonn').': '.$refundReason;
$objHtlBooking->setBookingCancellationMessage($refundReason);
}
}
// if all bookings are getting refunded then cancel the order also
if ($order->hasCompletelyRefunded(Order::ORDER_COMPLETE_REFUND_FLAG)) {
$objOrderHistory = new OrderHistory();
$objOrderHistory->id_order = (int)$order->id;
$idOrderState = Configuration::get('PS_OS_CANCELED');
$useExistingPayment = false;
if (!$order->hasInvoice()) {
$useExistingPayment = true;
}
$objOrderHistory->changeIdOrderState($idOrderState, $order, $useExistingPayment);
$objOrderHistory->addWithemail();
}
}
$objOrderReturn = new OrderReturn();
$objOrderReturn->id_customer = $order->id_customer;
$objOrderReturn->id_order = $order->id;
$objOrderReturn->state = 0;
$objOrderReturn->by_admin = 0;
$objOrderReturn->question = $refundReason;
$objOrderReturn->save();
if ($objOrderReturn->id) {
foreach ($bookingRefunds as $idHtlBooking) {
$objHtlBooking = new HotelBookingDetail($idHtlBooking);
$numDays = $objHtlBooking->getNumberOfDays(
$objHtlBooking->date_from,
$objHtlBooking->date_to
);
$objOrderReturnDetail = new OrderReturnDetail();
$objOrderReturnDetail->id_order_return = $objOrderReturn->id;
$objOrderReturnDetail->id_order_detail = $objHtlBooking->id_order_detail;
$objOrderReturnDetail->product_quantity = $numDays;
$objOrderReturnDetail->id_htl_booking = $idHtlBooking;
$objOrderReturnDetail->save();
}
}
// Emails to customer, admin on refund request state change
$objOrderReturn->changeIdOrderReturnState(Configuration::get('PS_ORS_PENDING'));
die(json_encode(array('status' => 1)));
}
die(json_encode(array('status' => 0)));
}
} else {

View File

@@ -2703,4 +2703,190 @@ class HotelBookingDetail extends ObjectModel
Configuration::get('PS_OS_ERROR'),
));
}
}
public function isUndoBookingCancellationAvailable()
{
if (Validate::isLoadedObject($this)) {
$objOrder = new Order($this->id_order);
$orderTotalPaid = $objOrder->getTotalPaid();
// Undo cancellation is available only if checkout date is not passed and payment is not created for the order and room is cancelled not refunded
if ($this->is_cancelled && (strtotime($this->date_to) >= strtotime(date('Y-m-d'))) && $orderTotalPaid <= 0) {
return true;
}
}
return false;
}
// process the booking tables changes when a booking refund/cancellation is processed
public function processRefundInBookingTables()
{
if (Validate::isLoadedObject($this)) {
$reduction_amount = array(
'total_price_tax_excl' => 0,
'total_price_tax_incl' => 0,
'total_products_tax_excl' => 0,
'total_products_tax_incl' => 0,
);
$objOrder = new Order($this->id_order);
$orderTotalPaid = $objOrder->getTotalPaid();
// things to do if order is not paid
if ((float) $orderTotalPaid <= 0) {
$objHotelBookingDemands = new HotelBookingDemands();
$objRoomTypeServiceProductOrderDetail = new RoomTypeServiceProductOrderDetail();
$reduction_amount['total_price_tax_excl'] = $this->total_price_tax_excl;
$reduction_amount['total_products_tax_excl'] = $this->total_price_tax_excl;
$reduction_amount['total_price_tax_incl'] = $this->total_price_tax_incl;
$reduction_amount['total_products_tax_incl'] = $this->total_price_tax_incl;
// reduce facilities amount from order and services_detail
if ($roomDemands = $objHotelBookingDemands->getRoomTypeBookingExtraDemands(
$this->id_order,
$this->id_product,
$this->id_room,
$this->date_from,
$this->date_to,
0
)) {
foreach ($roomDemands as $roomDemand) {
$objHotelBookingDemands = new HotelBookingDemands($roomDemand['id_booking_demand']);
$reduction_amount['total_price_tax_excl'] += $objHotelBookingDemands->total_price_tax_excl;
$reduction_amount['total_price_tax_incl'] += $objHotelBookingDemands->total_price_tax_incl;
$objHotelBookingDemands->total_price_tax_excl = 0;
$objHotelBookingDemands->total_price_tax_incl = 0;
$objHotelBookingDemands->save();
}
}
// reduce services amount from order and services_detail
if ($roomServices = $objRoomTypeServiceProductOrderDetail->getSelectedServicesForRoom(
$this->id
)) {
foreach ($roomServices['additional_services'] as $roomService) {
$objRoomTypeServiceProductOrderDetail = new RoomTypeServiceProductOrderDetail(
$roomService['id_room_type_service_product_order_detail']
);
$reduction_amount['total_price_tax_excl'] += $objRoomTypeServiceProductOrderDetail->total_price_tax_excl;
$reduction_amount['total_products_tax_excl'] += $objRoomTypeServiceProductOrderDetail->total_price_tax_excl;
$reduction_amount['total_price_tax_incl'] += $objRoomTypeServiceProductOrderDetail->total_price_tax_incl;
$reduction_amount['total_products_tax_incl'] += $objRoomTypeServiceProductOrderDetail->total_price_tax_incl;
if (Validate::isLoadedObject($objOrderDetail = new OrderDetail($objRoomTypeServiceProductOrderDetail->id_order_detail))) {
$objOrderDetail->product_quantity_refunded += $objRoomTypeServiceProductOrderDetail->quantity;
if ($objOrderDetail->product_quantity_refunded > $objOrderDetail->product_quantity) {
$objOrderDetail->product_quantity_refunded = $objOrderDetail->product_quantity;
}
$objOrderDetail->total_price_tax_excl -= $objRoomTypeServiceProductOrderDetail->total_price_tax_excl;
$objOrderDetail->total_price_tax_incl -= $objRoomTypeServiceProductOrderDetail->total_price_tax_incl;
$objOrderDetail->save();
}
$objRoomTypeServiceProductOrderDetail->total_price_tax_excl = 0;
$objRoomTypeServiceProductOrderDetail->total_price_tax_incl = 0;
$objRoomTypeServiceProductOrderDetail->save();
}
}
}
// enter refunded quantity in the order detail table
$idOrderDetail = $this->id_order_detail;
if (Validate::isLoadedObject($objOrderDetail = new OrderDetail($idOrderDetail))) {
$numDays = $this->getNumberOfDays(
$this->date_from,
$this->date_to
);
$objOrderDetail->product_quantity_refunded += $numDays;
if ($objOrderDetail->product_quantity_refunded > $objOrderDetail->product_quantity) {
$objOrderDetail->product_quantity_refunded = $objOrderDetail->product_quantity;
}
if ((float) $orderTotalPaid <= 0) {
// reduce room amount from order and order detail
$objOrderDetail->total_price_tax_incl -= $this->total_price_tax_incl;
$objOrderDetail->total_price_tax_excl -= $this->total_price_tax_excl;
if (Validate::isLoadedObject($objOrder = new Order($this->id_order))) {
$objOrder->total_paid -= $reduction_amount['total_price_tax_incl'];
$objOrder->total_paid_tax_excl -= $reduction_amount['total_price_tax_excl'];
$objOrder->total_paid_tax_incl -= $reduction_amount['total_price_tax_incl'];
$objOrder->total_products -= $reduction_amount['total_products_tax_excl'];
$objOrder->total_products_wt -= $reduction_amount['total_products_tax_incl'];
$objOrder->save();
}
}
$objOrderDetail->save();
}
// as refund is completed then set the booking as refunded
$this->is_refunded = 1;
if ((float) $orderTotalPaid <= 0) {
// Reduce room amount from htl_booking_detail
$this->is_cancelled = 1;
$this->total_price_tax_excl = 0;
$this->total_price_tax_incl = 0;
}
$this->save();
return true;
}
return false;
}
public function setBookingCancellationMessage($message, $byAdmin = 0)
{
if (Validate::isLoadedObject($this)) {
// First save the message for the admin for the refund
$objectMessage = new Message();
$objectMessage->message = $message;
$objectMessage->id_cart = (int)$this->id_cart;
$objectMessage->id_customer = (int)($this->id_customer);
$objectMessage->id_order = (int)$this->id_order;
$objectMessage->private = 1;
$objectMessage->add();
// save this message for the customer
$objCustomer = new Customer($this->id_customer);
$idCustomerThread = CustomerThread::getIdCustomerThreadByEmailAndIdOrder($objCustomer->email, $this->id_order);
if (!$idCustomerThread) {
$objCustomerThread = new CustomerThread();
$objCustomerThread->id_contact = 0;
$objCustomerThread->id_customer = (int)$this->id_customer;
$objCustomerThread->id_shop = (int)$this->context->shop->id;
$objCustomerThread->id_order = (int)$this->id_order;
$objCustomerThread->id_lang = (int)$this->context->language->id;
$objCustomerThread->email = $objCustomer->email;
$objCustomerThread->status = 'open';
$objCustomerThread->token = Tools::passwdGen(12);
$objCustomerThread->add();
} else {
$objCustomerThread = new CustomerThread((int)$idCustomerThread);
}
$objCustomerMessage = new CustomerMessage();
$objCustomerMessage->id_customer_thread = $objCustomerThread->id;
// If cancelled by admin then set the employee id who is doing this cancellation else put 0
if ($byAdmin) {
$context = Context::getContext();
$objCustomerMessage->id_employee = (int)$context->employee->id;
} else {
$objCustomerMessage->id_employee = 0;
}
$objCustomerMessage->message = $message;
$objCustomerMessage->private = 0;
$objCustomerMessage->add();
return true;
}
return false;
}
}

View File

@@ -292,27 +292,46 @@ class AdminOrderRefundRequestsController extends ModuleAdminController
} else {
$this->errors[] = $this->l('Invalid refund amount(s) entered.');
}
} else {
$this->errors[] = $this->l('Select at least one booking for refund.');
}
if (Tools::isSubmit('refundTransactionAmount')) {
$paymentMode = Tools::getValue('payment_method');
if (!$paymentMode) {
$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.');
// 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('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 (!$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.');
}
}
}
@@ -320,149 +339,60 @@ class AdminOrderRefundRequestsController extends ModuleAdminController
$this->errors[] = $this->l('Invalid refund state.');
}
} else {
$this->errors[] = $this->l('Invalid refund info.');
$this->errors[] = $this->l('Invalid refund information found.');
}
if (!count($this->errors)) {
$bookingList = array();
$totalRefundedAmount = 0;
if ($objRefundState->refunded || $objRefundState->denied) {
$objHotelBookingDemands = new HotelBookingDemands();
$objRoomTypeServiceProductOrderDetail = new RoomTypeServiceProductOrderDetail();
// If refund is completed then work on the booking list
if ($objRefundState->refunded) {
foreach ($idsReturnDetail as $idRetDetail) {
$objOrderReturnDetail = new OrderReturnDetail($idRetDetail);
// set booking as refunded if return state is refunded/denied
$idHtlBooking = $objOrderReturnDetail->id_htl_booking;
$numDays = 1;
$idOrderDetail = 0;
$reduction_amount = array(
'total_price_tax_excl' => 0,
'total_price_tax_incl' => 0,
'total_products_tax_excl' => 0,
'total_products_tax_incl' => 0,
);
if (Validate::isLoadedObject($objHtlBooking = new HotelBookingDetail($idHtlBooking))) {
$objHtlBooking->is_refunded = 1;
$objHtlBooking = new HotelBooking($idHtlBooking);
// perform booking refund processes in the booking tables
$objHtlBooking->processRefundInBookingTables();
// save individual booking amount for every booking refund
$refundedAmount = $refundedAmounts[$idRetDetail];
$objOrderReturnDetail->refunded_amount = $refundedAmount;
$objOrderReturnDetail->save();
// sum the refund amount for total order refund amount
$totalRefundedAmount += $refundedAmount;
if (Tools::isSubmit('generateCreditSlip')) {
$numDays = $objHtlBooking->getNumberOfDays(
$objHtlBooking->date_from,
$objHtlBooking->date_to
);
if ((float) $orderTotalPaid <= 0) {
$reduction_amount['total_price_tax_excl'] = $objHtlBooking->total_price_tax_excl;
$reduction_amount['total_products_tax_excl'] = $objHtlBooking->total_price_tax_excl;
$reduction_amount['total_price_tax_incl'] = $objHtlBooking->total_price_tax_incl;
$reduction_amount['total_products_tax_incl'] = $objHtlBooking->total_price_tax_incl;
// reduce facilities amount from order and services_detail
if ($roomDemands = $objHotelBookingDemands->getRoomTypeBookingExtraDemands(
$objHtlBooking->id_order,
$objHtlBooking->id_product,
$objHtlBooking->id_room,
$objHtlBooking->date_from,
$objHtlBooking->date_to,
0
)) {
foreach ($roomDemands as $roomDemand) {
$objHotelBookingDemands = new HotelBookingDemands($roomDemand['id_booking_demand']);
$reduction_amount['total_price_tax_excl'] += $objHotelBookingDemands->total_price_tax_excl;
$reduction_amount['total_price_tax_incl'] += $objHotelBookingDemands->total_price_tax_incl;
$objHotelBookingDemands->total_price_tax_excl = 0;
$objHotelBookingDemands->total_price_tax_incl = 0;
$objHotelBookingDemands->save();
}
}
// reduce services amount from order and services_detail
if ($roomServices = $objRoomTypeServiceProductOrderDetail->getSelectedServicesForRoom(
$objHtlBooking->id
)) {
foreach ($roomServices['additional_services'] as $roomService) {
$objRoomTypeServiceProductOrderDetail = new RoomTypeServiceProductOrderDetail(
$roomService['id_room_type_service_product_order_detail']
);
$reduction_amount['total_price_tax_excl'] += $objRoomTypeServiceProductOrderDetail->total_price_tax_excl;
$reduction_amount['total_products_tax_excl'] += $objRoomTypeServiceProductOrderDetail->total_price_tax_excl;
$reduction_amount['total_price_tax_incl'] += $objRoomTypeServiceProductOrderDetail->total_price_tax_incl;
$reduction_amount['total_products_tax_incl'] += $objRoomTypeServiceProductOrderDetail->total_price_tax_incl;
if (Validate::isLoadedObject($objOrderDetail = new OrderDetail($objRoomTypeServiceProductOrderDetail->id_order_detail))) {
$objOrderDetail->product_quantity_refunded += $objRoomTypeServiceProductOrderDetail->quantity;
if ($objOrderDetail->product_quantity_refunded > $objOrderDetail->product_quantity) {
$objOrderDetail->product_quantity_refunded = $objOrderDetail->product_quantity;
}
$objOrderDetail->total_price_tax_excl -= $objRoomTypeServiceProductOrderDetail->total_price_tax_excl;
$objOrderDetail->total_price_tax_incl -= $objRoomTypeServiceProductOrderDetail->total_price_tax_incl;
$objOrderDetail->save();
}
$objRoomTypeServiceProductOrderDetail->total_price_tax_excl = 0;
$objRoomTypeServiceProductOrderDetail->total_price_tax_incl = 0;
$objRoomTypeServiceProductOrderDetail->save();
}
}
}
// enter refunded quantity in the order detail table
$objHtlBooking = new HotelBookingDetail($idHtlBooking);
$idOrderDetail = $objHtlBooking->id_order_detail;
if (Validate::isLoadedObject($objOrderDetail = new OrderDetail($idOrderDetail))) {
$objOrderDetail->product_quantity_refunded += $numDays;
if ($objOrderDetail->product_quantity_refunded > $objOrderDetail->product_quantity) {
$objOrderDetail->product_quantity_refunded = $objOrderDetail->product_quantity;
}
if ((float) $orderTotalPaid <= 0) {
// reduce room amount from order and order detail
$objOrderDetail->total_price_tax_incl -= $objHtlBooking->total_price_tax_incl;
$objOrderDetail->total_price_tax_excl -= $objHtlBooking->total_price_tax_excl;
if (Validate::isLoadedObject($objOrder = new Order($objHtlBooking->id_order))) {
$objOrder->total_paid -= $reduction_amount['total_price_tax_incl'];
$objOrder->total_paid_tax_excl -= $reduction_amount['total_price_tax_excl'];
$objOrder->total_paid_tax_incl -= $reduction_amount['total_price_tax_incl'];
$objOrder->total_products -= $reduction_amount['total_products_tax_excl'];
$objOrder->total_products_wt -= $reduction_amount['total_products_tax_incl'];
$objOrder->save();
}
}
$objOrderDetail->save();
}
if ((float) $orderTotalPaid <= 0) {
// reduce room amount from htl_booking_detail
$objHtlBooking->is_cancelled = 1;
$objHtlBooking->total_price_tax_excl = 0;
$objHtlBooking->total_price_tax_incl = 0;
}
$objHtlBooking->save();
$bookingList[$idHtlBooking] = array(
'id_htl_booking' => $idHtlBooking,
'id_order_detail' => $idOrderDetail,
'quantity' => $numDays,
'num_days' => $numDays,
'unit_price' => $refundedAmount / $numDays,
'amount' => $refundedAmount,
);
}
// save individual booking amount for every booking refund
if ($objRefundState->refunded) {
$refundedAmount = $refundedAmounts[$idRetDetail];
$objOrderReturnDetail->refunded_amount = $refundedAmount;
$objOrderReturnDetail->save();
// sum the refund amount for total order refund amount
$totalRefundedAmount += $refundedAmount;
if (Tools::isSubmit('generateCreditSlip')) {
$bookingList[$idHtlBooking] = array(
'id_htl_booking' => $idHtlBooking,
'id_order_detail' => $idOrderDetail,
'quantity' => $numDays,
'num_days' => $numDays,
'unit_price' => $refundedAmount / $numDays,
'amount' => $refundedAmount,
);
}
}
}
// if bookings are refunded then set the payment information
if ($objRefundState->refunded && (float) $orderTotalPaid > 0) {
if ((float) $orderTotalPaid > 0) {
if (Tools::isSubmit('refundTransactionAmount')) {
$objOrderReturn->payment_mode = $paymentMode;
$objOrderReturn->id_transaction = $idTransaction;
@@ -480,18 +410,20 @@ class AdminOrderRefundRequestsController extends ModuleAdminController
// change state of the order refund
$objOrderReturn->changeIdOrderReturnState($idRefundState);
// change state of the order to refunded if all the room bookings in the order are completely refunded
if ($objRefundState->refunded) {
// check if order is paid the set status of the order to refunded
$objOrderHistory = new OrderHistory();
$objOrderHistory->id_order = (int)$objOrder->id;
$idOrderState = 0;
if ($objOrder->hasCompletelyRefunded(Order::ORDER_COMPLETE_REFUND_FLAG)) {
$idOrderState = Configuration::get('PS_OS_REFUND');
} elseif ($objOrder->hasCompletelyRefunded(Order::ORDER_COMPLETE_REFUND_FLAG)) {
$idOrderState = Configuration::get('PS_OS_CANCELED');
}
if ($objOrder->hasCompletelyRefunded(OrderReturnState::ORDER_RETURN_STATE_FLAG_REFUNDED)) {
$idOrderState = null;
if ((float) $orderTotalPaid) {
$idOrderState = Configuration::get('PS_OS_REFUND');
} else {
$idOrderState = Configuration::get('PS_OS_CANCELED');
}
// If order is completely refunded or cancelled then change the order state
if ($idOrderState) {
// check if order is paid the set status of the order to refunded
$objOrderHistory = new OrderHistory();
$objOrderHistory->id_order = (int)$objOrder->id;
$useExistingPayment = false;
if (!$objOrder->hasInvoice()) {

View File

@@ -18,6 +18,10 @@
*/
$(document).ready(function() {
// manage refund options checkboxes as per the refund paramenters
if ($('#order_return_form .table input[name^="refund_amounts"]').length) {
manageRefundOptions();
}
// initialize tootip for room price
if ($('#rooms_refund_info .price_info').length) {
@@ -91,32 +95,38 @@ $(document).ready(function() {
});
$(document).on('keyup', '#order_return_form .table input[name^="refund_amounts"]', function() {
let refundAmountInputs = $('#order_return_form .table input[name^="refund_amounts"]');
manageRefundOptions();
});
});
let disableRefundOptions = false;
// This function manages (Enable/disable) the refund options check-boxes according to the refund parameters like refund amount
function manageRefundOptions()
{
let refundAmountInputs = $('#order_return_form .table input[name^="refund_amounts"]');
let disableRefundOptions = false;
$(refundAmountInputs).each(function(index, element) {
let val = parseFloat($(element).val().trim());
if (isNaN(val)) { // if at least one amount input is empty
disableRefundOptions = true;
return;
}
});
if (!disableRefundOptions) {
let hasAllZero = true;
$(refundAmountInputs).each(function(index, element) {
let val = parseFloat($(element).val().trim());
if (isNaN(val)) { // if at least one amount input is empty
disableRefundOptions = true;
if (val != 0) {
hasAllZero = false;
return;
}
});
if (!disableRefundOptions) {
let hasAllZero = true;
$(refundAmountInputs).each(function(index, element) {
let val = parseFloat($(element).val().trim());
if (val != 0) {
hasAllZero = false;
return;
}
});
if (hasAllZero) { // if all amount inputs are 0
disableRefundOptions = true;
}
if (hasAllZero) { // if all amount inputs are 0
disableRefundOptions = true;
}
}
$('#generateCreditSlip, #refundTransactionAmount, #generateDiscount').attr('disabled', disableRefundOptions);
});
});
$('#generateCreditSlip, #refundTransactionAmount, #generateDiscount').attr('disabled', disableRefundOptions);
}

View File

@@ -57,6 +57,14 @@
<input type="hidden" name="id_order_return" value="{$orderReturnInfo['id']|escape:'html':'UTF-8'}">
<div class="form-wrapper">
<div class="form-group row">
<div class="col-sm-3">
<strong>{l s='Order Id' mod='hotelreservationsystem'} :</strong>
</div>
<div class="col-sm-9">
<a href="{$link->getAdminLink('AdminOrders')|escape:'html':'UTF-8'}&amp;vieworder&amp;id_order={$orderInfo['id']|escape:'html':'UTF-8'}">#{$orderInfo['id']|escape:'html':'UTF-8'}</a>
</div>
</div>
<div class="form-group row">
<div class="col-sm-3">
<strong>{l s='Total order amount' mod='hotelreservationsystem'} :</strong>
@@ -365,4 +373,4 @@
</form>
</div>
</div>
</div>
</div>