diff --git a/admin/themes/default/template/controllers/orders/helpers/view/view.tpl b/admin/themes/default/template/controllers/orders/helpers/view/view.tpl
index 481c41a80..9c374affe 100644
--- a/admin/themes/default/template/controllers/orders/helpers/view/view.tpl
+++ b/admin/themes/default/template/controllers/orders/helpers/view/view.tpl
@@ -862,61 +862,66 @@
{assign var=order_shipping_price value=$order->total_shipping_tax_incl}
{/if}
- {assign var=room_price_tax_excl value=$order->getTotalProductsWithoutTaxes(false, true)}
- {assign var=room_price_tax_incl value=$order->getTotalProductsWithTaxes(false, true)}
- {assign var=service_products_price_tax_excl value=$order->getTotalProductsWithoutTaxes(false, false, Product::SERVICE_PRODUCT_WITHOUT_ROOMTYPE)}
- {assign var=service_products_price_tax_incl value=$order->getTotalProductsWithTaxes(false, false, Product::SERVICE_PRODUCT_WITHOUT_ROOMTYPE)}
- {assign var=convenience_fee_price_tax_excl value=$order->getTotalProductsWithoutTaxes(false, false, Product::SERVICE_PRODUCT_WITH_ROOMTYPE, 1, Product::PRICE_ADDITION_TYPE_INDEPENDENT)}
- {assign var=convenience_fee_price_tax_incl value=$order->getTotalProductsWithTaxes(false, false, Product::SERVICE_PRODUCT_WITH_ROOMTYPE, 1, Product::PRICE_ADDITION_TYPE_INDEPENDENT)}
- {assign var=additional_service_price_tax_excl value=($order->getTotalProductsWithoutTaxes(false, false, Product::SERVICE_PRODUCT_WITH_ROOMTYPE) + $totalDemandsPriceTE)}
- {assign var=additional_service_price_tax_incl value=($order->getTotalProductsWithTaxes(false, false, Product::SERVICE_PRODUCT_WITH_ROOMTYPE) + $totalDemandsPriceTI)}
- {if $room_price_tax_excl}
+ {* total extra demands prices *}
+ {* $totalDemandsPriceTE
+ $totalDemandsPriceTI *}
+
+ {* Get total rooms prices *}
+ {assign var=total_rooms_price_tax_excl value=$order->getTotalProductsWithoutTaxes(false, true)}
+ {assign var=total_rooms_price_tax_incl value=$order->getTotalProductsWithTaxes(false, true)}
+
+ {* Get total extra services including convenience fees prices *}
+ {assign var=total_services_price_tax_excl value=$order->getTotalProductsWithoutTaxes(false, false)}
+ {assign var=total_services_price_tax_incl value=$order->getTotalProductsWithTaxes(false, false)}
+
+ {* Get total of extra services and extra demands prices(excluding convenience fee) *}
+ {assign var=total_room_services_and_demands_tax_excl value=($order->getTotalProductsWithoutTaxes(false, false, Product::SERVICE_PRODUCT_WITH_ROOMTYPE) + $totalDemandsPriceTE)}
+ {assign var=total_room_services_and_demands_tax_incl value=($order->getTotalProductsWithTaxes(false, false, Product::SERVICE_PRODUCT_WITH_ROOMTYPE) + $totalDemandsPriceTI)}
+
+ {* Get total of only convenience fees prices *}
+ {assign var=total_convenience_fee_tax_excl value=$order->getTotalProductsWithoutTaxes(false, false, Product::SERVICE_PRODUCT_WITH_ROOMTYPE, 1, Product::PRICE_ADDITION_TYPE_INDEPENDENT)}
+ {assign var=total_convenience_fee_tax_incl value=$order->getTotalProductsWithTaxes(false, false, Product::SERVICE_PRODUCT_WITH_ROOMTYPE, 1, Product::PRICE_ADDITION_TYPE_INDEPENDENT)}
+
+ {assign var=order_total_price_tax_excl value=($total_rooms_price_tax_excl + $total_services_price_tax_excl + $totalDemandsPriceTE)}
+ {assign var=order_total_price_tax_incl value=($total_rooms_price_tax_incl + $total_services_price_tax_incl + $totalDemandsPriceTI)}
+
+ {if $total_rooms_price_tax_excl}
| {l s='Total Rooms Cost (Tax excl.)'} |
- {displayPrice price=$room_price_tax_excl currency=$currency->id}
+ {displayPrice price=$total_rooms_price_tax_excl currency=$currency->id}
|
|
{/if}
- {if isset($additional_service_price_tax_excl) && $additional_service_price_tax_excl > 0}
+ {if isset($total_room_services_and_demands_tax_excl) && $total_room_services_and_demands_tax_excl > 0}
| {l s='Total Extra services (Tax excl.)'} |
- {displayPrice price=($additional_service_price_tax_excl - $convenience_fee_price_tax_excl) currency=$currency->id}
+ {displayPrice price=($total_room_services_and_demands_tax_excl - $total_convenience_fee_tax_excl) currency=$currency->id}
|
|
{/if}
- {if $service_products_price_tax_excl}
-
- | {l s='Total service products cost (Tax excl.)'} |
-
- {displayPrice price=$service_products_price_tax_excl currency=$currency->id}
- |
- |
-
- {/if}
-
- {if isset($convenience_fee_price_tax_excl) && $convenience_fee_price_tax_excl > 0}
+ {if isset($total_convenience_fee_tax_excl) && $total_convenience_fee_tax_excl > 0}
|
{l s='Convenience Fee (Tax excl.)'}
- {if isset($booking_auto_added_services) && count($booking_auto_added_services)}
+ {if isset($order_convenience_fee_services) && count($order_convenience_fee_services)}
{/if}
|
- {displayPrice price=$convenience_fee_price_tax_excl currency=$currency->id}
+ {displayPrice price=$total_convenience_fee_tax_excl currency=$currency->id}
|
|
- {if isset($booking_auto_added_services) && count($booking_auto_added_services)}
+ {if isset($order_convenience_fee_services) && count($order_convenience_fee_services)}
- {foreach $booking_auto_added_services as $service}
+ {foreach $order_convenience_fee_services as $service}
| {$service.name} |
{displayPrice price=$service.total_price_tax_excl currency=$currency->id} |
@@ -932,41 +937,41 @@
|
{l s='Total Taxes'}
- {if ($order->total_paid_tax_incl - $order->total_paid_tax_excl) > 0}
+ {if ($order_total_price_tax_incl - $order_total_price_tax_excl) > 0}
{/if}
|
- {displayPrice price=(($order->total_paid_tax_incl + $order->total_discounts_tax_incl) - ($order->total_paid_tax_excl + $order->total_discounts_tax_excl)) currency=$currency->id}
+ | {displayPrice price=($order_total_price_tax_incl - $order_total_price_tax_excl) currency=$currency->id}
|
|
- {if ($order->total_paid_tax_incl - $order->total_paid_tax_excl) > 0}
+ {if ($order_total_price_tax_incl - $order_total_price_tax_excl) > 0}
- {if $room_price_tax_excl}
+ {if $total_rooms_price_tax_excl}
| {l s='Total Rooms Tax'} |
- {displayPrice price=($room_price_tax_incl - $room_price_tax_excl) currency=$currency->id}
+ {displayPrice price=($total_rooms_price_tax_incl - $total_rooms_price_tax_excl) currency=$currency->id}
|
{/if}
- {if isset($additional_service_price_tax_incl) && (($additional_service_price_tax_incl - $additional_service_price_tax_excl) - ($convenience_fee_price_tax_incl - $convenience_fee_price_tax_excl)) > 0}
+ {if isset($total_room_services_and_demands_tax_incl) && (($total_room_services_and_demands_tax_incl - $total_room_services_and_demands_tax_excl) - ($total_convenience_fee_tax_incl - $total_convenience_fee_tax_excl)) > 0}
| {l s='Extra services Tax'} |
- {displayPrice price=(($additional_service_price_tax_incl - $additional_service_price_tax_excl) - ($convenience_fee_price_tax_incl - $convenience_fee_price_tax_excl)) currency=$currency->id}
+ {displayPrice price=(($total_room_services_and_demands_tax_incl - $total_room_services_and_demands_tax_excl) - ($total_convenience_fee_tax_incl - $total_convenience_fee_tax_excl)) currency=$currency->id}
|
|
{/if}
- {if isset($convenience_fee_price_tax_excl) && $convenience_fee_price_tax_excl > 0}
+ {if isset($total_convenience_fee_tax_excl) && $total_convenience_fee_tax_excl > 0}
| {l s='Convenience Fee Tax'} |
- {displayPrice price=($convenience_fee_price_tax_incl - $convenience_fee_price_tax_excl) currency=$currency->id}
+ {displayPrice price=($total_convenience_fee_tax_incl - $total_convenience_fee_tax_excl) currency=$currency->id}
|
|
@@ -980,7 +985,7 @@
total_discounts_tax_incl == 0}style="display: none;"{/if}>
| {l s='Total Booking Amount'} |
- {displayPrice price=($order->total_paid_tax_incl + $order->total_discounts_tax_incl) currency=$currency->id}
+ {displayPrice price=($order_total_price_tax_incl) currency=$currency->id}
|
|
@@ -1034,7 +1039,7 @@
{l s='Voucher'}
- {if $can_edit}
+ {if $can_edit && $order->total_paid > 0}
diff --git a/classes/order/Order.php b/classes/order/Order.php
index 67e8e48c2..6d72ae93b 100644
--- a/classes/order/Order.php
+++ b/classes/order/Order.php
@@ -867,6 +867,12 @@ class OrderCore extends ObjectModel
WHERE ocr.`id_order` = '.(int)$this->id);
}
+ public function getCartRulesTotal($useTax = false)
+ {
+ return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(
+ 'SELECT '.($useTax ? 'SUM(ocr.`value`)' : 'SUM(ocr.`value_tax_excl`)').' FROM `'._DB_PREFIX_.'order_cart_rule` ocr WHERE ocr.`id_order` = '.(int)$this->id);
+ }
+
public static function getDiscountsCustomer($id_customer, $id_cart_rule)
{
$cache_id = 'Order::getDiscountsCustomer_'.(int)$id_customer.'-'.(int)$id_cart_rule;
diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php
index d3cdf98f0..a976957b2 100644
--- a/controllers/admin/AdminOrdersController.php
+++ b/controllers/admin/AdminOrdersController.php
@@ -2063,18 +2063,33 @@ class AdminOrdersControllerCore extends AdminController
$order_invoice->update();
}
- // Update amounts of order
- $order->total_discounts = ($order->total_discounts - $order_cart_rule->value) > 0 ? ($order->total_discounts - $order_cart_rule->value) : 0;
- $order->total_discounts_tax_incl = ($order->total_discounts_tax_incl - $order_cart_rule->value) > 0 ? ($order->total_discounts_tax_incl - $order_cart_rule->value) : 0;
- $order->total_discounts_tax_excl = ($order->total_discounts_tax_excl - $order_cart_rule->value_tax_excl) > 0 ? ($order->total_discounts_tax_excl - $order_cart_rule->value_tax_excl) : 0;
+ if ($order_cart_rule->delete()) {
+ $orderTotalDiscountTE = $order->getCartRulesTotal();
+ $orderTotalDiscountTI = $order->getCartRulesTotal(true);
- $order->total_paid += Tools::ps_round($order_cart_rule->value, _PS_PRICE_COMPUTE_PRECISION_);
- $order->total_paid_tax_incl += Tools::ps_round($order_cart_rule->value, _PS_PRICE_COMPUTE_PRECISION_);
- $order->total_paid_tax_excl += Tools::ps_round($order_cart_rule->value_tax_excl, _PS_PRICE_COMPUTE_PRECISION_);
+ $totalRoomsAndServicesTI = $order->getTotalProductsWithTaxes();
+ $totalRoomsAndServicesTE = $order->getTotalProductsWithoutTaxes();
- // Delete Order Cart Rule and update Order
- $order_cart_rule->delete();
- $order->update();
+ $objBookingDemand = new HotelBookingDemands();
+ $totalExtraDemandsTE = $objBookingDemand->getRoomTypeBookingExtraDemands($order->id, 0, 0, 0, 0, 0, 1, 0);
+ $totalExtraDemandsTI = $objBookingDemand->getRoomTypeBookingExtraDemands($order->id, 0, 0, 0, 0, 0, 1, 1);
+
+ // Update amounts of order
+ $order->total_discounts = ($order->total_discounts - $order_cart_rule->value) > 0 ? ($order->total_discounts - $order_cart_rule->value) : 0;
+ $order->total_discounts_tax_incl = ($order->total_discounts_tax_incl - $order_cart_rule->value) > 0 ? ($order->total_discounts_tax_incl - $order_cart_rule->value) : 0;
+ $order->total_discounts_tax_excl = ($order->total_discounts_tax_excl - $order_cart_rule->value_tax_excl) > 0 ? ($order->total_discounts_tax_excl - $order_cart_rule->value_tax_excl) : 0;
+
+ // Update order with new amounts after removing cart rule
+ $totalOrderTE = ($totalExtraDemandsTE + $totalRoomsAndServicesTE) - $orderTotalDiscountTE;
+ $totalOrderTE = $totalOrderTE > 0 ? $totalOrderTE : 0;
+ $totalOrderTI = ($totalExtraDemandsTI + $totalRoomsAndServicesTI) - $orderTotalDiscountTI;
+ $totalOrderTI = $totalOrderTI > 0 ? $totalOrderTI : 0;
+
+ $order->total_paid = Tools::ps_round($totalOrderTI, _PS_PRICE_COMPUTE_PRECISION_);
+ $order->total_paid_tax_incl = Tools::ps_round($totalOrderTI, _PS_PRICE_COMPUTE_PRECISION_);
+ $order->total_paid_tax_excl = Tools::ps_round($totalOrderTE, _PS_PRICE_COMPUTE_PRECISION_);
+ $order->update();
+ }
Tools::redirectAdmin(self::$currentIndex.'&id_order='.$order->id.'&vieworder&conf=4&token='.$this->token);
} else {
@@ -2779,7 +2794,7 @@ class AdminOrdersControllerCore extends AdminController
$totalDemandsPriceTE = 0;
$totalDemandsPriceTI = 0;
$totalRefundedRooms = 0;
- $bookingAutoAddedServices = array();
+ $orderConvenienceFeeServices = array();
if ($order_detail_data = $objBookingDetail->getOrderFormatedBookinInfoByIdOrder($order->id)) {
$objBookingDemand = new HotelBookingDemands();
$objHotelRoomType = new HotelRoomType();
@@ -2931,11 +2946,11 @@ class AdminOrdersControllerCore extends AdminController
foreach($orderedRooms as $orderedRoom) {
if (isset($orderedRoom['additional_services']) && $orderedRoom['additional_services']) {
foreach ($orderedRoom['additional_services'] as $service) {
- if (isset($bookingAutoAddedServices[$service['id_product']])) {
- $bookingAutoAddedServices[$service['id_product']]['total_price_tax_excl'] += $service['total_price_tax_excl'];
+ if (isset($orderConvenienceFeeServices[$service['id_product']])) {
+ $orderConvenienceFeeServices[$service['id_product']]['total_price_tax_excl'] += $service['total_price_tax_excl'];
} else {
- $bookingAutoAddedServices[$service['id_product']]['name'] = $service['name'];
- $bookingAutoAddedServices[$service['id_product']]['total_price_tax_excl'] = $service['total_price_tax_excl'];
+ $orderConvenienceFeeServices[$service['id_product']]['name'] = $service['name'];
+ $orderConvenienceFeeServices[$service['id_product']]['total_price_tax_excl'] = $service['total_price_tax_excl'];
}
}
}
@@ -3098,7 +3113,7 @@ class AdminOrdersControllerCore extends AdminController
'ROOM_STATUS_CHECKED_IN' => HotelBookingDetail::STATUS_CHECKED_IN,
'ROOM_STATUS_CHECKED_OUT' => HotelBookingDetail::STATUS_CHECKED_OUT,
'ALLOTMENT_MANUAL' => HotelBookingDetail::ALLOTMENT_MANUAL,
- 'booking_auto_added_services' => $bookingAutoAddedServices,
+ 'order_convenience_fee_services' => $orderConvenienceFeeServices,
);
return parent::renderView();
@@ -4467,9 +4482,9 @@ class AdminOrdersControllerCore extends AdminController
// Create OrderCartRule
$rule = new CartRule($cart_rule['id_cart_rule']);
$values = array(
- 'tax_incl' => $rule->getContextualValue(true),
- 'tax_excl' => $rule->getContextualValue(false)
- );
+ 'tax_incl' => $rule->getContextualValue(true),
+ 'tax_excl' => $rule->getContextualValue(false)
+ );
$order_cart_rule = new OrderCartRule();
$order_cart_rule->id_order = $order->id;
$order_cart_rule->id_cart_rule = $cart_rule['id_cart_rule'];
@@ -5042,7 +5057,6 @@ class AdminOrdersControllerCore extends AdminController
}
}
// change order total save
- ppp($order);
$order->save();
}
@@ -5564,6 +5578,24 @@ class AdminOrdersControllerCore extends AdminController
$objCart = new Cart($objBookingDetail->id_cart);
$objCart->updateQty($product_quantity, $objBookingDetail->id_product, null, false, 'down', 0, null, true);
+ // If no rooms left in the order, delete all cart rules of the order
+ if (!$objBookingDetail->getBookingDataByOrderId($order->id)) {
+ if ($orderDiscounts = $order->getCartRules()) {
+ foreach ($orderDiscounts as $orderDiscount) {
+ $objOrderCartRule = new OrderCartRule($orderDiscount['id_order_cart_rule']);
+ $objOrderCartRule->delete();
+ }
+
+ $order->total_discounts = 0;
+ $order->total_discounts_tax_incl = 0;
+ $order->total_discounts_tax_excl = 0;
+ $order->total_paid = 0;
+ $order->total_paid_tax_incl = 0;
+ $order->total_paid_tax_excl = 0;
+ $order->update();
+ }
+ }
+
// Assign to smarty informations in order to show the new product line
$this->context->smarty->assign(array(
'order' => $order,
| |