Fixed: Tourism tax global exemption from back office does not allow selecting specific rooms needed to be exempted

Co-authored-by: Name <sumit201@webkul.in>
This commit is contained in:
shazar rahman
2026-10-15 17:54:27 +05:30
parent 71d31c9872
commit 0ba6d04b1f
3 changed files with 183 additions and 58 deletions

View File

@@ -24,21 +24,116 @@
room table (_rooms_informaion_table.tpl) and/or a products table (_hotel_service_products_table.tpl /
_standalone_service_products_table.tpl) with tourism tax columns is rendered. *}
{assign var='ttExemptRooms' value=[]}
{if isset($use_tourism_tax) && $use_tourism_tax && isset($order_detail_data) && $order_detail_data}
{foreach from=$order_detail_data item=ttRoom}
{if isset($ttRoom.tourism_tax_status) && $ttRoom.tourism_tax_status == $tourism_tax_status_applied && $ttRoom.id_status != $ROOM_STATUS_CANCELLED && !$ttRoom.is_refunded}
{append var='ttExemptRooms' value=$ttRoom}
{/if}
{/foreach}
{/if}
{assign var='ttExemptProducts' value=[]}
{if isset($use_tourism_tax) && $use_tourism_tax}
{if isset($hotel_service_products) && $hotel_service_products}
{foreach from=$hotel_service_products item=ttProduct}
{if isset($ttProduct.tourism_tax_status) && $ttProduct.tourism_tax_status == $tourism_tax_status_applied && !$ttProduct.is_refunded && !$ttProduct.is_cancelled}
{append var='ttExemptProducts' value=$ttProduct}
{/if}
{/foreach}
{/if}
{if isset($standalone_service_products) && $standalone_service_products}
{foreach from=$standalone_service_products item=ttProduct}
{if isset($ttProduct.tourism_tax_status) && $ttProduct.tourism_tax_status == $tourism_tax_status_applied && !$ttProduct.is_refunded && !$ttProduct.is_cancelled}
{append var='ttExemptProducts' value=$ttProduct}
{/if}
{/foreach}
{/if}
{/if}
<div class="modal fade" id="exempt-tourism-tax-modal" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-dialog modal-md order_detail_modal" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><i class="icon-remove-sign"></i></button>
<h4 class="modal-title"><i class="icon-ban"></i> {l s='Exempt Tourism Tax'}</h4>
</div>
<div class="modal-body">
<div class="form-group" id="tt-exempt-targets-group">
<label class="control-label" id="tt-exempt-targets-label"><b>{l s='Rooms to be exempted'}</b></label>
<ul id="tt-exempt-targets-list" style="max-height:150px; overflow-y:auto; margin-bottom:0; padding-left:18px;"></ul>
</div>
{if $ttExemptRooms|count > 0 && $ttExemptProducts|count > 0}
<ul class="nav nav-tabs" role="tablist" id="tt-exempt-tabs">
<li role="presentation" class="active">
<a href="#tt_exempt_rooms_tab" role="tab" data-toggle="tab">{l s='Rooms'}</a>
</li>
<li role="presentation">
<a href="#tt_exempt_products_tab" role="tab" data-toggle="tab">{l s='Products'}</a>
</li>
</ul>
{/if}
{if $ttExemptRooms|count > 0 && $ttExemptProducts|count > 0}
<div class="form-group tab-content clearfix">
{/if}
{if $ttExemptRooms|count}
<div id="tt_exempt_rooms_tab" class="form-group table-responsive tab-pane active">
<table class="table" id="tt-exempt-rooms-table">
<thead>
<tr>
<th></th>
<th>{l s='Room No.'}</th>
<th>{l s='Room Type'}</th>
<th>{l s='Property Name'}</th>
<th>{l s='Duration'}</th>
<th>{l s='Total Price (Tax incl.)'}</th>
</tr>
</thead>
<tbody>
{foreach from=$ttExemptRooms item=ttRoom}
<tr class="tt-exempt-row" data-id_htl_booking="{$ttRoom.id|intval}">
<td>
<input type="checkbox" name="tt_exempt_id_htl_booking[]" value="{$ttRoom.id|intval}" checked="checked"/>
</td>
<td><b>{$ttRoom.room_num|escape:'html':'UTF-8'}</b></td>
<td>{$ttRoom.room_type_name|escape:'html':'UTF-8'}</td>
<td>{$ttRoom.hotel_name|escape:'html':'UTF-8'}</td>
{assign var="is_full_date" value=($show_full_date && ($ttRoom['date_from']|date_format:'%D' == $ttRoom['date_to']|date_format:'%D'))}
<td>{dateFormat date=$ttRoom.date_from full=$is_full_date} - {dateFormat date=$ttRoom.date_to full=$is_full_date}</td>
<td>{convertPriceWithCurrency price=$ttRoom.total_room_price_ti currency=$currency->id}</td>
</tr>
{/foreach}
</tbody>
</table>
</div>
{/if}
{if $ttExemptProducts|count}
<div id="tt_exempt_products_tab" class="form-group table-responsive tab-pane{if !$ttExemptRooms|count} active{/if}">
<table class="table" id="tt-exempt-products-table">
<thead>
<tr>
<th></th>
<th>{l s='Name'}</th>
<th>{l s='Quantity'}</th>
<th>{l s='Total Price (Tax incl.)'}</th>
</tr>
</thead>
<tbody>
{foreach from=$ttExemptProducts item=ttProduct}
<tr class="tt-exempt-row" data-id_service_product_order_detail="{$ttProduct.id_service_product_order_detail|intval}">
<td>
<input type="checkbox" name="tt_exempt_id_service_product_order_detail[]" value="{$ttProduct.id_service_product_order_detail|intval}" checked="checked"/>
</td>
<td><b>{$ttProduct.name|escape:'html':'UTF-8'}{if $ttProduct.option_name} : {$ttProduct.option_name|escape:'html':'UTF-8'}{/if}</b></td>
<td>{if $ttProduct.allow_multiple_quantity}{$ttProduct.quantity|escape:'html':'UTF-8'}{else}--{/if}</td>
<td>{convertPriceWithCurrency price=$ttProduct.total_price_tax_incl currency=$currency->id}</td>
</tr>
{/foreach}
</tbody>
</table>
</div>
{/if}
{if $ttExemptRooms|count > 0 && $ttExemptProducts|count > 0}
</div>
{/if}
<div class="form-group">
<label class="control-label">{l s='Reason for Exemption'}</label>
<textarea rows="3" class="textarea-autosize" id="tt-exempt-note"></textarea>
<textarea rows="2" id="tt-exempt-note"></textarea>
</div>
</div>
<div class="modal-footer">
@@ -52,7 +147,7 @@
<script>
$(document).ready(function () {
function ttAjax(action, data) {
function ttAjax(action, data, $button) {
$.ajax({
type: 'POST',
url: admin_order_tab_link,
@@ -60,6 +155,9 @@ $(document).ready(function () {
dataType: 'json',
beforeSend: function () {
$('#page-loader').show();
if ($button) {
$button.prop('disabled', true);
}
},
success: function (resp) {
if (resp.hasError && resp.errors && resp.errors.length) {
@@ -73,6 +171,9 @@ $(document).ready(function () {
},
complete: function () {
$('#page-loader').hide();
if ($button) {
$button.prop('disabled', false);
}
}
});
}
@@ -92,53 +193,63 @@ $(document).ready(function () {
ttAjax('ApplyTourismTax', { id_service_product_order_detail: $(this).data('id_service_product_order_detail') });
});
var ttExemptTarget = null;
var ttRoomsToBeExemptedLabel = '{l s='Rooms to be exempted' js=1}';
var ttProductsToBeExemptedLabel = '{l s='Products to be exempted' js=1}';
function ttShowExemptModal(labels, hasRooms) {
var $list = $('#tt-exempt-targets-list');
$list.empty();
$.each(labels, function (i, label) {
$list.append($('<li>').addClass('message-item-text').text(label));
});
$('#tt-exempt-targets-label b').text(hasRooms ? ttRoomsToBeExemptedLabel : ttProductsToBeExemptedLabel);
function ttShowExemptModal(onlyRow) {
var $modal = $('#exempt-tourism-tax-modal');
var $rows = $modal.find('.tt-exempt-row');
$rows.show().find('input[type=checkbox]').prop('checked', true);
if (onlyRow) {
$rows.each(function () {
var $row = $(this);
var isTarget = (onlyRow.id_htl_booking && $row.data('id_htl_booking') == onlyRow.id_htl_booking)
|| (onlyRow.id_service_product_order_detail && $row.data('id_service_product_order_detail') == onlyRow.id_service_product_order_detail);
if (!isTarget) {
$row.hide().find('input[type=checkbox]').prop('checked', false);
}
});
}
// show the tab holding the picked row, and hide the tab bar when a single row was picked
var $tabs = $('#tt-exempt-tabs');
if ($tabs.length) {
$tabs.toggle(!onlyRow);
var activeTab = (onlyRow && onlyRow.id_service_product_order_detail) ? '#tt_exempt_products_tab' : '#tt_exempt_rooms_tab';
$tabs.find('a[href="' + activeTab + '"]').tab('show');
}
$('#tt-exempt-note').val('');
$('#exempt-tourism-tax-modal').modal('show');
$modal.modal('show');
}
$(document).on('click', '.tt-exempt-booking', function (e) {
e.preventDefault();
ttExemptTarget = { id_htl_booking: $(this).data('id_htl_booking') };
ttShowExemptModal([$(this).data('label')], true);
ttShowExemptModal({ id_htl_booking: $(this).data('id_htl_booking') });
});
$(document).on('click', '.tt-exempt-all-bookings', function (e) {
e.preventDefault();
ttExemptTarget = { id_order: $(this).data('id_order') };
var labels = [];
var hasRooms = $('.tt-exempt-booking').length > 0;
$('.tt-exempt-booking').each(function () {
labels.push($(this).data('label'));
});
$('.tt-exempt-service-line').each(function () {
labels.push($(this).data('label'));
});
ttShowExemptModal(labels, hasRooms);
ttShowExemptModal(null);
});
$(document).on('click', '.tt-exempt-service-line', function (e) {
e.preventDefault();
ttExemptTarget = { id_service_product_order_detail: $(this).data('id_service_product_order_detail') };
ttShowExemptModal([$(this).data('label')], false);
ttShowExemptModal({ id_service_product_order_detail: $(this).data('id_service_product_order_detail') });
});
$(document).on('click', '#tt-exempt-confirm', function (e) {
if (!ttExemptTarget) {
var idsHtlBooking = $('#exempt-tourism-tax-modal input[name="tt_exempt_id_htl_booking[]"]:checked').map(function () {
return $(this).val();
}).get();
var idsServiceLine = $('#exempt-tourism-tax-modal input[name="tt_exempt_id_service_product_order_detail[]"]:checked').map(function () {
return $(this).val();
}).get();
if (!idsHtlBooking.length && !idsServiceLine.length) {
showErrorMessage('{l s='No booking/products has been selected.' js=1}');
return;
}
$('#exempt-tourism-tax-modal').modal('hide');
ttAjax('ExemptTourismTax', $.extend({ note: $('#tt-exempt-note').val() }, ttExemptTarget));
ttAjax('ExemptTourismTax', {
id_order: id_order,
id_htl_booking: idsHtlBooking,
id_service_product_order_detail: idsServiceLine,
note: $('#tt-exempt-note').val()
}, $(this));
});
});
</script>

View File

@@ -1258,21 +1258,25 @@ class OrderTaxDetailCore extends ObjectModel
}
/**
* Exempt tourism tax for every booking (room + attached services) and every standalone service line
* of an order; returns only the failing entries.
* Exempt tourism tax for the bookings (room + attached services) and standalone service lines
* of an order — every one of them by default, or only the given ids; returns only the failing entries.
*
* @param int $idOrder
* @param int $idEmployee
* @param string|null $note Reason for exemption, applied to every booking/line in the order
* @param string|null $autoMsgLabel Pre-translated "Tourism Tax Exempted" label — null skips the Order Notes entry entirely, for every booking/line in the order
* @param string $remarkLabel Pre-translated "Remark" label
* @param int[]|null $idsHtlBooking Only these bookings are exempted (ids that don't belong to the order are ignored); null = every booking
* @param int[]|null $idsServiceLines Only these standalone service lines are exempted (ids that don't belong to the order are ignored); null = every line
* @return array [{'id_htl_booking' => int, 'result' => int}, ...] plus
* [{'id_service_product_order_detail' => int, 'result' => int}, ...] — failures only
*/
public static function exemptForOrder($idOrder, $idEmployee = 0, $note = null, $autoMsgLabel = null, $remarkLabel = 'Remark')
public static function exemptForOrder($idOrder, $idEmployee = 0, $note = null, $autoMsgLabel = null, $remarkLabel = 'Remark', $idsHtlBooking = null, $idsServiceLines = null)
{
$idOrder = (int) $idOrder;
$failures = array();
$selectedBookingIds = ($idsHtlBooking !== null) ? array_flip(array_map('intval', $idsHtlBooking)) : null;
$selectedServiceLineIds = ($idsServiceLines !== null) ? array_flip(array_map('intval', $idsServiceLines)) : null;
$objBookingDetail = new HotelBookingDetail();
$bookings = $objBookingDetail->getBookingDataByOrderId($idOrder);
if ($bookings) {
@@ -1284,6 +1288,9 @@ class OrderTaxDetailCore extends ObjectModel
if (isset($refundedIds[$booking['id']]) || $booking['id_status'] == HotelBookingDetail::STATUS_CANCELLED) {
continue;
}
if ($selectedBookingIds !== null && !isset($selectedBookingIds[(int) $booking['id']])) {
continue;
}
$result = self::exemptBooking($booking['id'], $idEmployee, $note, $autoMsgLabel, $remarkLabel);
if ($result !== self::EXEMPT_OK) {
$failures[] = array('id_htl_booking' => (int) $booking['id'], 'result' => $result);
@@ -1291,6 +1298,9 @@ class OrderTaxDetailCore extends ObjectModel
}
}
foreach (ServiceProductOrderDetail::getActiveStandaloneIdsByOrder($idOrder) as $idServiceLine) {
if ($selectedServiceLineIds !== null && !isset($selectedServiceLineIds[$idServiceLine])) {
continue;
}
$result = self::exemptServiceLine($idServiceLine, $idEmployee, $note, $autoMsgLabel, $remarkLabel);
if ($result !== self::EXEMPT_OK) {
$failures[] = array('id_service_product_order_detail' => $idServiceLine, 'result' => $result);

View File

@@ -3672,7 +3672,9 @@ class AdminOrdersControllerCore extends AdminController
$orderTourismTaxHasUnapplied = false;
if ($useTourismTax && $order_detail_data) {
foreach ($order_detail_data as $bookingRow) {
if (!empty($bookingRow['is_cancelled']) || !empty($bookingRow['is_refunded'])) {
if (!empty($bookingRow['is_cancelled']) || !empty($bookingRow['is_refunded'])
|| $bookingRow['id_status'] == HotelBookingDetail::STATUS_CANCELLED
) {
continue;
}
if (isset($bookingRow['tourism_tax_status'])) {
@@ -9292,15 +9294,22 @@ class AdminOrdersControllerCore extends AdminController
}
/**
* Exempt tourism tax for a booking (id_htl_booking), a standalone service line
* (id_service_product_order_detail), or every booking of a whole order (id_order) —
* see OrderTaxDetail::exemptBooking()/exemptServiceLine().
* Exempt tourism tax for the rooms (id_htl_booking[]) and/or standalone service lines
* (id_service_product_order_detail[]) selected in the exemption modal of an order (id_order) —
* see OrderTaxDetail::exemptForOrder().
*/
public function ajaxProcessExemptTourismTax()
{
$idHtlBooking = (int) Tools::getValue('id_htl_booking', 0);
$idServiceProductOrderDetail = (int) Tools::getValue('id_service_product_order_detail', 0);
if ($this->tabAccess['edit'] !== 1) {
die(Tools::jsonEncode(array(
'hasError' => true,
'errors' => array(Tools::displayError('You do not have permission to edit this order.')),
)));
}
$idOrder = (int) Tools::getValue('id_order', 0);
$idsHtlBooking = array_filter(array_map('intval', (array) Tools::getValue('id_htl_booking', array())));
$idsServiceProductOrderDetail = array_filter(array_map('intval', (array) Tools::getValue('id_service_product_order_detail', array())));
$idEmployee = (int) Context::getContext()->employee->id;
$note = trim((string) Tools::getValue('note', ''));
$note = ($note !== '') ? $note : null;
@@ -9312,20 +9321,15 @@ class AdminOrdersControllerCore extends AdminController
OrderTaxDetail::EXEMPT_ERROR_SAVE => $this->l('Could not exempt tourism tax.'),
);
if ($idHtlBooking) {
$result = OrderTaxDetail::exemptBooking($idHtlBooking, $idEmployee, $note, $autoMsgLabel, $remarkLabel);
if (isset($messagesByResult[$result])) {
$errors[] = $messagesByResult[$result];
}
} elseif ($idServiceProductOrderDetail) {
$result = OrderTaxDetail::exemptServiceLine($idServiceProductOrderDetail, $idEmployee, $note, $autoMsgLabel, $remarkLabel);
if (isset($messagesByResult[$result])) {
$errors[] = $messagesByResult[$result];
}
} elseif ($idOrder) {
$errors = self::tourismTaxErrorsFromResults(OrderTaxDetail::exemptForOrder($idOrder, $idEmployee, $note, $autoMsgLabel, $remarkLabel), $messagesByResult);
} else {
if (!Validate::isLoadedObject(new Order($idOrder))) {
$errors[] = $this->l('Invalid request parameters.');
} elseif (!$idsHtlBooking && !$idsServiceProductOrderDetail) {
$errors[] = Tools::displayError('No booking/products has been selected.');
} else {
$errors = self::tourismTaxErrorsFromResults(
OrderTaxDetail::exemptForOrder($idOrder, $idEmployee, $note, $autoMsgLabel, $remarkLabel, $idsHtlBooking, $idsServiceProductOrderDetail),
$messagesByResult
);
}
die(Tools::jsonEncode(array(