Fixed:Issue on admin orders after admin removes rooms from order having cart rules
This commit is contained in:
@@ -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}
|
||||
<tr id="total_products">
|
||||
<td class="text-right">{l s='Total Rooms Cost (Tax excl.)'}</td>
|
||||
<td class="amount text-right nowrap">
|
||||
{displayPrice price=$room_price_tax_excl currency=$currency->id}
|
||||
{displayPrice price=$total_rooms_price_tax_excl currency=$currency->id}
|
||||
</td>
|
||||
<td class="partial_refund_fields current-edit" style="display:none;"></td>
|
||||
</tr>
|
||||
{/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}
|
||||
<tr id="total_products">
|
||||
<td class="text-right">{l s='Total Extra services (Tax excl.)'}</td>
|
||||
<td class="amount text-right nowrap">
|
||||
{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}
|
||||
</td>
|
||||
<td class="partial_refund_fields current-edit" style="display:none;"></td>
|
||||
</tr>
|
||||
{/if}
|
||||
{if $service_products_price_tax_excl}
|
||||
<tr id="total_products">
|
||||
<td class="text-right">{l s='Total service products cost (Tax excl.)'}</td>
|
||||
<td class="amount text-right nowrap">
|
||||
{displayPrice price=$service_products_price_tax_excl currency=$currency->id}
|
||||
</td>
|
||||
<td class="partial_refund_fields current-edit" style="display:none;"></td>
|
||||
</tr>
|
||||
{/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}
|
||||
<tr id="total_products">
|
||||
<td class="text-right">
|
||||
{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)}
|
||||
<span role="button" id="view_convenience_services" class="pull-left"><i class="icon-angle-down icon-bold"></i><i class="icon-angle-up icon-bold" style="display:none;"></i></span>
|
||||
{/if}
|
||||
</td>
|
||||
<td class="amount text-right nowrap">
|
||||
{displayPrice price=$convenience_fee_price_tax_excl currency=$currency->id}
|
||||
{displayPrice price=$total_convenience_fee_tax_excl currency=$currency->id}
|
||||
</td>
|
||||
<td class="partial_refund_fields current-edit" style="display:none;"></td>
|
||||
</tr>
|
||||
{if isset($booking_auto_added_services) && count($booking_auto_added_services)}
|
||||
{if isset($order_convenience_fee_services) && count($order_convenience_fee_services)}
|
||||
<tr id="convenience_services" style="display:none;">
|
||||
<td colspan="3" class="panel">
|
||||
<table class="table table-responsive">
|
||||
<tbody>
|
||||
{foreach $booking_auto_added_services as $service}
|
||||
{foreach $order_convenience_fee_services as $service}
|
||||
<tr>
|
||||
<td class="text-left"><span>{$service.name}</span></td>
|
||||
<td class="text-right"><span>{displayPrice price=$service.total_price_tax_excl currency=$currency->id}</span></td>
|
||||
@@ -932,41 +937,41 @@
|
||||
<tr id="total_taxes">
|
||||
<td class="text-right">
|
||||
<strong>{l s='Total Taxes'} </strong>
|
||||
{if ($order->total_paid_tax_incl - $order->total_paid_tax_excl) > 0}
|
||||
{if ($order_total_price_tax_incl - $order_total_price_tax_excl) > 0}
|
||||
<span role="button" id="view_order_tax_details" class="pull-left"><i class="icon-angle-down icon-bold"></i><i class="icon-angle-up icon-bold" style="display:none;"></i></span>
|
||||
{/if}
|
||||
</td>
|
||||
<td class="amount text-right nowrap" ><strong>{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}</strong>
|
||||
<td class="amount text-right nowrap" ><strong>{displayPrice price=($order_total_price_tax_incl - $order_total_price_tax_excl) currency=$currency->id}</strong>
|
||||
</td>
|
||||
<td class="partial_refund_fields current-edit" style="display:none;"></td>
|
||||
</tr>
|
||||
{if ($order->total_paid_tax_incl - $order->total_paid_tax_excl) > 0}
|
||||
{if ($order_total_price_tax_incl - $order_total_price_tax_excl) > 0}
|
||||
<tr id="order_tax_details" style="display:none;">
|
||||
<td colspan="3" class="panel">
|
||||
<table class="table table-responsive">
|
||||
<tbody>
|
||||
{if $room_price_tax_excl}
|
||||
{if $total_rooms_price_tax_excl}
|
||||
<tr>
|
||||
<td class="text-left">{l s='Total Rooms Tax'}</td>
|
||||
<td class="text-right">
|
||||
{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}
|
||||
</td>
|
||||
</tr>
|
||||
{/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}
|
||||
<tr>
|
||||
<td class="text-left">{l s='Extra services Tax'}</td>
|
||||
<td class="text-right nowrap">
|
||||
{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}
|
||||
</td>
|
||||
<td class="partial_refund_fields current-edit" style="display:none;"></td>
|
||||
</tr>
|
||||
{/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}
|
||||
<tr id="total_products">
|
||||
<td class="text-left">{l s='Convenience Fee Tax'}</td>
|
||||
<td class="amount text-right nowrap">
|
||||
{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}
|
||||
</td>
|
||||
<td class="partial_refund_fields current-edit" style="display:none;"></td>
|
||||
</tr>
|
||||
@@ -980,7 +985,7 @@
|
||||
<tr id="total_discounts" {if $order->total_discounts_tax_incl == 0}style="display: none;"{/if}>
|
||||
<td class="text-right"><strong>{l s='Total Booking Amount'}</strong></td>
|
||||
<td class="amount text-right nowrap">
|
||||
<strong>{displayPrice price=($order->total_paid_tax_incl + $order->total_discounts_tax_incl) currency=$currency->id}</strong>
|
||||
<strong>{displayPrice price=($order_total_price_tax_incl) currency=$currency->id}</strong>
|
||||
</td>
|
||||
<td class="partial_refund_fields current-edit" style="display:none;"></td>
|
||||
</tr>
|
||||
@@ -1034,7 +1039,7 @@
|
||||
<div class="panel panel-vouchers">
|
||||
<div class="panel-heading">
|
||||
<span><i class="icon-tag"></i> {l s='Voucher'}</span>
|
||||
{if $can_edit}
|
||||
{if $can_edit && $order->total_paid > 0}
|
||||
<button id="add_voucher" class="btn btn-primary pull-right" type="button" >
|
||||
<i class="icon-ticket"></i> {l s='Add new voucher'}
|
||||
</button>
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user