-
+ {if $ttExemptRooms|count > 0 && $ttExemptProducts|count > 0}
+
+ {/if}
+ {if $ttExemptRooms|count > 0 && $ttExemptProducts|count > 0}
+
+ {/if}
+ {if $ttExemptRooms|count}
+
+ {/if}
+ {if $ttExemptProducts|count}
+
+ {/if}
+ {if $ttExemptRooms|count > 0 && $ttExemptProducts|count > 0}
+
+ {/if}
-
+
+{assign var='ttApplyRooms' value=[]}
+{if isset($use_tourism_tax) && $use_tourism_tax && isset($order_detail_data) && $order_detail_data}
+ {foreach from=$order_detail_data item=ttApplyRoom}
+ {if isset($ttApplyRoom.tourism_tax_status) && $ttApplyRoom.tourism_tax_status != $tourism_tax_status_applied && $ttApplyRoom.tourism_tax_status != $tourism_tax_status_not_applicable && $ttApplyRoom.id_status != $ROOM_STATUS_CANCELLED && !$ttApplyRoom.is_refunded}
+ {append var='ttApplyRooms' value=$ttApplyRoom}
+ {/if}
+ {/foreach}
+{/if}
+{assign var='ttApplyProducts' value=[]}
+{if isset($use_tourism_tax) && $use_tourism_tax}
+ {if isset($hotel_service_products) && $hotel_service_products}
+ {foreach from=$hotel_service_products item=ttApplyProduct}
+ {if isset($ttApplyProduct.tourism_tax_status) && $ttApplyProduct.tourism_tax_status != $tourism_tax_status_applied && $ttApplyProduct.tourism_tax_status != $tourism_tax_status_not_applicable && !$ttApplyProduct.is_refunded && !$ttApplyProduct.is_cancelled}
+ {append var='ttApplyProducts' value=$ttApplyProduct}
+ {/if}
+ {/foreach}
+ {/if}
+ {if isset($standalone_service_products) && $standalone_service_products}
+ {foreach from=$standalone_service_products item=ttApplyProduct}
+ {if isset($ttApplyProduct.tourism_tax_status) && $ttApplyProduct.tourism_tax_status != $tourism_tax_status_applied && $ttApplyProduct.tourism_tax_status != $tourism_tax_status_not_applicable && !$ttApplyProduct.is_refunded && !$ttApplyProduct.is_cancelled}
+ {append var='ttApplyProducts' value=$ttApplyProduct}
+ {/if}
+ {/foreach}
+ {/if}
+{/if}
+
+
+
+
+
+
+ {if $ttApplyRooms|count > 0 && $ttApplyProducts|count > 0}
+
+ {/if}
+ {if $ttApplyRooms|count > 0 && $ttApplyProducts|count > 0}
+
+ {/if}
+ {if $ttApplyRooms|count}
+
+ {/if}
+ {if $ttApplyProducts|count}
+
+ {/if}
+ {if $ttApplyRooms|count > 0 && $ttApplyProducts|count > 0}
+
+ {/if}
+
+
+
+
+
+
diff --git a/classes/order/OrderTaxDetail.php b/classes/order/OrderTaxDetail.php
index a878a1c80..3459d488d 100644
--- a/classes/order/OrderTaxDetail.php
+++ b/classes/order/OrderTaxDetail.php
@@ -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);
@@ -1300,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) {
@@ -1326,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);
@@ -1333,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 ba55f0602..b9c788ebd 100644
--- a/controllers/admin/AdminOrdersController.php
+++ b/controllers/admin/AdminOrdersController.php
@@ -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'])) {
@@ -9252,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();
@@ -9269,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(
@@ -9292,15 +9296,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 +9323,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(