From 0ba6d04b1f220c43912d035cbb02aee0a221aabc Mon Sep 17 00:00:00 2001 From: shazar rahman Date: Thu, 15 Oct 2026 17:54:27 +0530 Subject: [PATCH 1/2] Fixed: Tourism tax global exemption from back office does not allow selecting specific rooms needed to be exempted Co-authored-by: Name --- .../orders/_tourism_tax_actions.tpl | 183 ++++++++++++++---- classes/order/OrderTaxDetail.php | 16 +- controllers/admin/AdminOrdersController.php | 42 ++-- 3 files changed, 183 insertions(+), 58 deletions(-) diff --git a/admin-dev/themes/default/template/controllers/orders/_tourism_tax_actions.tpl b/admin-dev/themes/default/template/controllers/orders/_tourism_tax_actions.tpl index 7bcdcccab..ba1492436 100644 --- a/admin-dev/themes/default/template/controllers/orders/_tourism_tax_actions.tpl +++ b/admin-dev/themes/default/template/controllers/orders/_tourism_tax_actions.tpl @@ -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} + + + diff --git a/classes/order/OrderTaxDetail.php b/classes/order/OrderTaxDetail.php index 9d3f96bf1..3459d488d 100644 --- a/classes/order/OrderTaxDetail.php +++ b/classes/order/OrderTaxDetail.php @@ -1310,21 +1310,25 @@ class OrderTaxDetailCore extends ObjectModel } /** - * Apply tourism tax for every booking and every standalone service line of an order; returns only - * the failing entries. A booking/line with nothing applicable (neither the room nor any attached + * Apply tourism tax for the bookings and standalone service lines of an order — every one of them by + * default, or only the given ids; returns only the failing entries. A booking/line with nothing applicable (neither the room nor any attached * service, or the standalone line itself, has a tourism tax rule) is not a failure — it's silently * skipped, same as if it had simply been left alone. * * @param int $idOrder * @param int $idEmployee PS employee id (0 = resolved from Context) * @param string|null $autoMsgLabel Pre-translated "Tourism Tax Applied" label — null skips the Order Notes entry entirely, for every booking/line in the order + * @param int[]|null $idsHtlBooking Only these bookings are applied (ids that don't belong to the order are ignored); null = every booking + * @param int[]|null $idsServiceLines Only these standalone service lines are applied (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 applyForOrder($idOrder, $idEmployee = 0, $autoMsgLabel = null) + public static function applyForOrder($idOrder, $idEmployee = 0, $autoMsgLabel = null, $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) { @@ -1336,6 +1340,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::applyBooking($booking['id'], $idEmployee, $autoMsgLabel); if ($result !== self::APPLY_OK && $result !== self::APPLY_ERROR_NOT_APPLICABLE) { $failures[] = array('id_htl_booking' => (int) $booking['id'], 'result' => $result); @@ -1343,6 +1350,9 @@ class OrderTaxDetailCore extends ObjectModel } } foreach (ServiceProductOrderDetail::getActiveStandaloneIdsByOrder($idOrder) as $idServiceLine) { + if ($selectedServiceLineIds !== null && !isset($selectedServiceLineIds[$idServiceLine])) { + continue; + } $result = self::applyServiceLine($idServiceLine, $idEmployee, $autoMsgLabel); if ($result !== self::APPLY_OK && $result !== self::APPLY_ERROR_NOT_APPLICABLE) { $failures[] = array('id_service_product_order_detail' => $idServiceLine, 'result' => $result); diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index 973e56995..b9c788ebd 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -9254,15 +9254,22 @@ class AdminOrdersControllerCore extends AdminController } /** - * Apply tourism tax to 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::applyBooking()/applyServiceLine(). + * Apply tourism tax to the rooms (id_htl_booking[]) and/or standalone service lines + * (id_service_product_order_detail[]) selected in the apply modal of an order (id_order) — + * see OrderTaxDetail::applyForOrder(). */ public function ajaxProcessApplyTourismTax() { - $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; $autoMsgLabel = $this->l('Tourism Tax Applied'); $errors = array(); @@ -9271,20 +9278,15 @@ class AdminOrdersControllerCore extends AdminController OrderTaxDetail::APPLY_ERROR_NOT_APPLICABLE => $this->l('Tourism tax is not applicable for this booking.'), ); - if ($idHtlBooking) { - $result = OrderTaxDetail::applyBooking($idHtlBooking, $idEmployee, $autoMsgLabel); - if (isset($messagesByResult[$result])) { - $errors[] = $messagesByResult[$result]; - } - } elseif ($idServiceProductOrderDetail) { - $result = OrderTaxDetail::applyServiceLine($idServiceProductOrderDetail, $idEmployee, $autoMsgLabel); - if (isset($messagesByResult[$result])) { - $errors[] = $messagesByResult[$result]; - } - } elseif ($idOrder) { - $errors = self::tourismTaxErrorsFromResults(OrderTaxDetail::applyForOrder($idOrder, $idEmployee, $autoMsgLabel), $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::applyForOrder($idOrder, $idEmployee, $autoMsgLabel, $idsHtlBooking, $idsServiceProductOrderDetail), + $messagesByResult + ); } die(Tools::jsonEncode(array(