- {if !$order->hasBeenDelivered() && $currentState->id != Configuration::get('PS_OS_REFUND') && $currentState->id != Configuration::get('PS_OS_CANCELED')}
+ {if $can_edit && (!$order->hasBeenDelivered() && $currentState->id != Configuration::get('PS_OS_REFUND') && $currentState->id != Configuration::get('PS_OS_CANCELED'))}
@@ -851,61 +863,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}
{/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}
{/if}
- {if $service_products_price_tax_excl}
-
- {/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}
- {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}
@@ -921,41 +938,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}
@@ -969,7 +986,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}
@@ -1023,7 +1040,7 @@
{l s='Voucher'}
- {if $can_edit}
+ {if $can_edit && $order->total_paid > 0}
{l s='Add new voucher'}
@@ -1139,49 +1156,53 @@
{l s='Show all messages'}
diff --git a/admin/themes/default/template/controllers/orders/modals/_booking_documents.tpl b/admin/themes/default/template/controllers/orders/modals/_booking_documents.tpl
index 930c61a38..627ae014c 100644
--- a/admin/themes/default/template/controllers/orders/modals/_booking_documents.tpl
+++ b/admin/themes/default/template/controllers/orders/modals/_booking_documents.tpl
@@ -34,47 +34,49 @@
-
-
diff --git a/classes/PaymentModule.php b/classes/PaymentModule.php
index 660cbe306..a41e558b0 100644
--- a/classes/PaymentModule.php
+++ b/classes/PaymentModule.php
@@ -191,14 +191,14 @@ abstract class PaymentModuleCore extends Module
if (!$this->active) {
PrestaShopLogger::addLog('PaymentModule::validateOrder - Module is not active', 3, null, 'Cart', (int)$id_cart, true);
- die(Tools::displayError());
+ die(Tools::displayError('Error in processing order. Payment module is not active.'));
}
// Does order already exists ?
if (Validate::isLoadedObject($this->context->cart) && $this->context->cart->OrderExists() == false) {
if ($secure_key !== false && $secure_key != $this->context->cart->secure_key) {
PrestaShopLogger::addLog('PaymentModule::validateOrder - Secure key does not match', 3, null, 'Cart', (int)$id_cart, true);
- die(Tools::displayError());
+ die(Tools::displayError('Error processing order. Secure key does not match.'));
}
// For each package, generate an order
diff --git a/classes/order/Order.php b/classes/order/Order.php
index 67e8e48c2..99fab549f 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;
@@ -2847,4 +2853,32 @@ class OrderCore extends ObjectModel
return $result;
}
+
+ /**
+ * @param bool $useTax: if true, total with tax, if false, total without tax
+ * @param bool $withDiscounts: if true, total including discount, if false, total excluding discount
+ * @return float total of the order
+ */
+ public function getOrderTotal($useTax = true, $withDiscounts = true)
+ {
+ // Get total of rooms and services
+ if ($useTax) {
+ $totalRoomsAndServices = $this->getTotalProductsWithTaxes();
+ } else {
+ $totalRoomsAndServices = $this->getTotalProductsWithoutTaxes();
+ }
+
+ // Get total of extra demands
+ $objBookingDemand = new HotelBookingDemands();
+ $totalExtraDemands = $objBookingDemand->getRoomTypeBookingExtraDemands($this->id, 0, 0, 0, 0, 0, 1, $useTax);
+
+ // Get cart rules total
+ $orderTotalDiscount = $this->getCartRulesTotal($useTax);
+
+ // Update order with new amounts after removing cart rule
+ $totalOrder = ($totalExtraDemands + $totalRoomsAndServices) - $orderTotalDiscount;
+ $totalOrder = $totalOrder > 0 ? $totalOrder : 0;
+
+ return $totalOrder;
+ }
}
diff --git a/classes/pdf/HTMLTemplateInvoice.php b/classes/pdf/HTMLTemplateInvoice.php
index 118acabc8..89f340ded 100644
--- a/classes/pdf/HTMLTemplateInvoice.php
+++ b/classes/pdf/HTMLTemplateInvoice.php
@@ -310,8 +310,11 @@ class HTMLTemplateInvoiceCore extends HTMLTemplate
$this->context = Context::getContext();
+ $cart_htl_data = array();
+ $service_product_data = array();
+ $room_extra_demands = array();
+ $room_additinal_services = array();
if (Module::isInstalled('hotelreservationsystem')) {
-
$obj_htl_bk_dtl = new HotelBookingDetail();
$obj_rm_type = new HotelRoomType();
$objRoomTypeServiceProductOrderDetail = new RoomTypeServiceProductOrderDetail();
@@ -319,11 +322,6 @@ class HTMLTemplateInvoiceCore extends HTMLTemplate
$customer = new Customer($this->order->id_customer);
if (!empty($order_details)) {
$processed_product = array();
- $cart_htl_data = array();
- $service_product_data = array();
- $room_extra_demands = array();
- $room_additinal_services = array();
-
$totalDemandsPriceTE = 0;
$totalDemandsPriceTI = 0;
foreach ($order_details as $type_key => $type_value) {
diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php
index 93755f1bf..d2dc4d1fe 100644
--- a/controllers/admin/AdminOrdersController.php
+++ b/controllers/admin/AdminOrdersController.php
@@ -103,7 +103,7 @@ class AdminOrdersControllerCore extends AdminController
$this->_orderWay = 'DESC';
$this->_use_found_rows = true;
- $this->_group = ' GROUP BY hbd.`id_order`';
+ $this->_group = ' GROUP BY a.`id_order`';
// if request for resolvable overbooked orders filter comes the set condition for this
if (Tools::getIsset('resolvable_overbooked_orders') && Tools::getValue('resolvable_overbooked_orders')) {
@@ -501,18 +501,20 @@ class AdminOrdersControllerCore extends AdminController
'class' => 'icon-print',
);
- if (((int) $order->isReturnable()) && !$order->hasCompletelyRefunded(Order::ORDER_COMPLETE_CANCELLATION_OR_REFUND_REQUEST_FLAG)) {
- $orderTotalPaid = $order->getTotalPaid();
- $orderDiscounts = $order->getCartRules();
- $hasOrderDiscountOrPayment = ((float)$orderTotalPaid > 0 || $orderDiscounts) ? true : false;
- $this->toolbar_btn['cancel'] = array(
- 'short' => ($hasOrderDiscountOrPayment) ? $this->l('Refund') : $this->l('Cancel'),
- 'href' => '#refundForm',
- 'id' => 'desc-order-standard_refund',
- 'desc' => ($hasOrderDiscountOrPayment) ? $this->l('Initiate refund') : $this->l('Cancel bookings'),
- 'class' => 'icon-exchange',
- 'target' => true,
- );
+ if ($this->tabAccess['edit'] == 1) {
+ if (((int) $order->isReturnable()) && !$order->hasCompletelyRefunded(Order::ORDER_COMPLETE_CANCELLATION_OR_REFUND_REQUEST_FLAG)) {
+ $orderTotalPaid = $order->getTotalPaid();
+ $orderDiscounts = $order->getCartRules();
+ $hasOrderDiscountOrPayment = ((float)$orderTotalPaid > 0 || $orderDiscounts) ? true : false;
+ $this->toolbar_btn['cancel'] = array(
+ 'short' => ($hasOrderDiscountOrPayment) ? $this->l('Refund') : $this->l('Cancel'),
+ 'href' => '#refundForm',
+ 'id' => 'desc-order-standard_refund',
+ 'desc' => ($hasOrderDiscountOrPayment) ? $this->l('Initiate refund') : $this->l('Cancel bookings'),
+ 'class' => 'icon-exchange',
+ 'target' => true,
+ );
+ }
}
}
}
@@ -528,22 +530,24 @@ class AdminOrdersControllerCore extends AdminController
{
$response['hasError'] = 1;
if (Validate::isLoadedObject($objOrder = new Order(Tools::getValue('id_order')))) {
+ $this->context->smarty->assign('can_edit', $this->tabAccess['edit']);
// set modal details
$modal = array(
'modal_id' => 'booking-documents-modal',
'modal_class' => 'modal-md order_detail_modal',
'modal_title' => '  '.$this->l('Documents'),
'modal_content' => $this->context->smarty->fetch('controllers/orders/modals/_booking_documents.tpl'),
- 'modal_actions' => array(
- array(
- 'type' => 'button',
- 'value' => 'submitDocument',
- 'class' => 'btn-primary pull-right submitDocument',
- 'label' => ' '.$this->l('Upload'),
- ),
- ),
);
+ if ($this->tabAccess['edit'] == 1) {
+ $modal['modal_actions'][] = array(
+ 'type' => 'button',
+ 'value' => 'submitDocument',
+ 'class' => 'btn-primary pull-right submitDocument',
+ 'label' => ' '.$this->l('Upload'),
+ );
+ }
+
$this->context->smarty->assign($modal);
$response['hasError'] = 0;
$response['modalHtml'] = $this->context->smarty->fetch('modal.tpl');
@@ -569,16 +573,17 @@ class AdminOrdersControllerCore extends AdminController
'modal_class' => 'order_detail_modal',
'modal_title' => '  '.$this->l('Note'),
'modal_content' => $this->context->smarty->fetch('controllers/orders/modals/_document_note.tpl'),
- 'modal_actions' => array(
- array(
- 'type' => 'button',
- 'value' => 'submitDocumentNote',
- 'class' => 'submitDocumentNote btn-primary pull-right',
- 'label' => ' '.$this->l('Save Note'),
- ),
- ),
);
+ if ($this->tabAccess['edit'] == 1) {
+ $modal['modal_actions'][] = array(
+ 'type' => 'button',
+ 'value' => 'submitDocumentNote',
+ 'class' => 'submitDocumentNote btn-primary pull-right',
+ 'label' => ' '.$this->l('Save Note'),
+ );
+ }
+
$this->context->smarty->assign($modal);
$response['hasError'] = 0;
$response['modalHtml'] = $this->context->smarty->fetch('modal.tpl');
@@ -1033,7 +1038,7 @@ class AdminOrdersControllerCore extends AdminController
$this->addJqueryUI('ui.datepicker');
$this->addJS(_PS_JS_DIR_.'vendor/d3.v3.min.js');
- if ($this->tabAccess['edit'] == 1 && $this->display == 'view') {
+ if ($this->display == 'view') {
if ($this->loadObject()) {
$this->addJS(_PS_JS_DIR_.'admin/orders.js');
}
@@ -1086,7 +1091,7 @@ class AdminOrdersControllerCore extends AdminController
if (Tools::isSubmit('submitUpdateOrderStatus')
&& ($id_order_state = (int)Tools::getValue('id_order_state'))) {
if ($this->tabAccess['edit'] !== '1') {
- $this->errors[] = Tools::displayError('You do not have permission to edit this.');
+ $this->errors[] = Tools::displayError('You do not have permission to edit this order.');
} else {
$order_state = new OrderState($id_order_state);
@@ -1194,7 +1199,7 @@ class AdminOrdersControllerCore extends AdminController
}
}
} else {
- $this->errors[] = $this->l('You do not have permission to edit this.');
+ $this->errors[] = $this->l('You do not have permission to edit this order.');
}
}
@@ -1236,12 +1241,16 @@ class AdminOrdersControllerCore extends AdminController
}
}
} else {
- $this->errors[] = $this->l('You do not have permission to edit this.');
+ $this->errors[] = $this->l('You do not have permission to edit this order.');
}
}
// To update order status when admin changes from order detail page
if (Tools::isSubmit('submitbookingOrderStatus')) {
- $this->changeRoomStatus();
+ if ($this->tabAccess['edit'] === '1') {
+ $this->changeRoomStatus();
+ } else {
+ $this->errors[] = $this->l('You do not have permission to edit this order.');
+ }
}
// If id_order is sent, we instanciate a new Order object
@@ -1312,7 +1321,7 @@ class AdminOrdersControllerCore extends AdminController
}
}
} else {
- $this->errors[] = Tools::displayError('You do not have permission to edit this.');
+ $this->errors[] = Tools::displayError('You do not have permission to edit this order.');
}
}
@@ -1326,7 +1335,7 @@ class AdminOrdersControllerCore extends AdminController
$this->errors = array_merge($this->errors, $result['errors']);
}
} else {
- $this->errors[] = Tools::displayError('You do not have permission to edit this.');
+ $this->errors[] = Tools::displayError('You do not have permission to edit this order.');
}
}
@@ -1429,7 +1438,7 @@ class AdminOrdersControllerCore extends AdminController
}
}
} else {
- $this->errors[] = Tools::displayError('You do not have permission to edit this.');
+ $this->errors[] = Tools::displayError('You do not have permission to edit this order.');
}
}
@@ -1532,7 +1541,7 @@ class AdminOrdersControllerCore extends AdminController
Tools::redirectAdmin(self::$currentIndex.'&id_order='.$order->id.'&vieworder&conf=3&token='.$this->token);
}
} else {
- $this->errors[] = Tools::displayError('You do not have permission to edit this.');
+ $this->errors[] = Tools::displayError('You do not have permission to edit this order.');
}
} elseif (Tools::isSubmit('messageReaded')) {
Message::markAsReaded(Tools::getValue('messageReaded'), $this->context->employee->id);
@@ -1599,7 +1608,7 @@ class AdminOrdersControllerCore extends AdminController
}
}
} else {
- $this->errors[] = Tools::displayError('You do not have permission to edit this.');
+ $this->errors[] = Tools::displayError('You do not have permission to edit this order.');
}
} elseif (Tools::isSubmit('submitEditNote')) {
$note = Tools::getValue('note');
@@ -1614,7 +1623,7 @@ class AdminOrdersControllerCore extends AdminController
$this->errors[] = Tools::displayError('The invoice note was not saved.');
}
} else {
- $this->errors[] = Tools::displayError('You do not have permission to edit this.');
+ $this->errors[] = Tools::displayError('You do not have permission to edit this order.');
}
} else {
$this->errors[] = Tools::displayError('Invalid note found.');
@@ -1774,7 +1783,7 @@ class AdminOrdersControllerCore extends AdminController
$this->errors[] = Tools::displayError('This address can\'t be loaded');
}
} else {
- $this->errors[] = Tools::displayError('You do not have permission to edit this.');
+ $this->errors[] = Tools::displayError('You do not have permission to edit this order.');
}
} elseif (Tools::isSubmit('submitChangeCurrency') && isset($order)) {
if ($this->tabAccess['edit'] === '1') {
@@ -2022,7 +2031,7 @@ class AdminOrdersControllerCore extends AdminController
$this->errors[] = Tools::displayError('You cannot change the currency.');
}
} else {
- $this->errors[] = Tools::displayError('You do not have permission to edit this.');
+ $this->errors[] = Tools::displayError('You do not have permission to edit this order.');
}
} elseif (Tools::isSubmit('submitGenerateInvoice') && isset($order)) {
if (!Configuration::get('PS_INVOICE', null, null, $order->id_shop)) {
@@ -2054,25 +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()) {
+ // 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;
- $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_);
-
- // Delete Order Cart Rule and update Order
- $order_cart_rule->delete();
- $order->update();
+ $order->total_paid = Tools::ps_round(
+ $order->getOrderTotal(),
+ _PS_PRICE_COMPUTE_PRECISION_
+ );
+ $order->total_paid_tax_incl = Tools::ps_round(
+ $order->getOrderTotal(),
+ _PS_PRICE_COMPUTE_PRECISION_
+ );
+ $order->total_paid_tax_excl = Tools::ps_round(
+ $order->getOrderTotal(false),
+ _PS_PRICE_COMPUTE_PRECISION_
+ );
+ $order->update();
+ }
Tools::redirectAdmin(self::$currentIndex.'&id_order='.$order->id.'&vieworder&conf=4&token='.$this->token);
} else {
$this->errors[] = Tools::displayError('You cannot edit this cart rule.');
}
} else {
- $this->errors[] = Tools::displayError('You do not have permission to edit this.');
+ $this->errors[] = Tools::displayError('You do not have permission to edit this order.');
}
} elseif (Tools::isSubmit('submitNewVoucher') && isset($order)) {
if ($this->tabAccess['edit'] === '1') {
@@ -2229,9 +2246,10 @@ class AdminOrdersControllerCore extends AdminController
$order->total_discounts = Tools::ps_round($order->total_discounts + $order_cart_rule->value, _PS_PRICE_COMPUTE_PRECISION_);
$order->total_discounts_tax_incl = Tools::ps_round($order->total_discounts_tax_incl + $order_cart_rule->value, _PS_PRICE_COMPUTE_PRECISION_);
$order->total_discounts_tax_excl = Tools::ps_round($order->total_discounts_tax_excl + $order_cart_rule->value_tax_excl, _PS_PRICE_COMPUTE_PRECISION_);
- $order->total_paid = Tools::ps_round($order->total_paid - $order_cart_rule->value, _PS_PRICE_COMPUTE_PRECISION_);
- $order->total_paid_tax_incl = Tools::ps_round($order->total_paid_tax_incl - $order_cart_rule->value, _PS_PRICE_COMPUTE_PRECISION_);
- $order->total_paid_tax_excl = Tools::ps_round($order->total_paid_tax_excl - $order_cart_rule->value_tax_excl, _PS_PRICE_COMPUTE_PRECISION_);
+
+ $order->total_paid = Tools::ps_round($order->getOrderTotal(), _PS_PRICE_COMPUTE_PRECISION_);
+ $order->total_paid_tax_incl = Tools::ps_round($order->getOrderTotal(), _PS_PRICE_COMPUTE_PRECISION_);
+ $order->total_paid_tax_excl = Tools::ps_round($order->getOrderTotal(false), _PS_PRICE_COMPUTE_PRECISION_);
}
// Update Order
@@ -2246,7 +2264,7 @@ class AdminOrdersControllerCore extends AdminController
}
}
} else {
- $this->errors[] = Tools::displayError('You do not have permission to edit this.');
+ $this->errors[] = Tools::displayError('You do not have permission to edit this order.');
}
} elseif (Tools::isSubmit('sendStateEmail') && Tools::getValue('sendStateEmail') > 0 && Tools::getValue('id_order') > 0) {
if ($this->tabAccess['edit'] === '1') {
@@ -2267,7 +2285,7 @@ class AdminOrdersControllerCore extends AdminController
}
}
} else {
- $this->errors[] = Tools::displayError('You do not have permission to edit this.');
+ $this->errors[] = Tools::displayError('You do not have permission to edit this order.');
}
} elseif(Tools::getIsset('resolve_overbooking') && Tools::getValue('resolve_overbooking')) {
$objHotelBookingDetail = new HotelBookingDetail();
@@ -2765,7 +2783,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();
@@ -2917,11 +2935,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'];
}
}
}
@@ -3084,7 +3102,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();
@@ -3189,33 +3207,37 @@ class AdminOrdersControllerCore extends AdminController
{
$response = array('status' => false);
- $idHtlBooking = (int) Tools::getValue('id_htl_booking');
- $title = Tools::getValue('title');
+ if ($this->tabAccess['edit'] === '1') {
+ $idHtlBooking = (int) Tools::getValue('id_htl_booking');
+ $title = Tools::getValue('title');
- // validations
- $objHotelBookingDetail = new HotelBookingDetail($idHtlBooking);
- if (!Validate::isLoadedObject($objHotelBookingDetail)) {
- $this->errors[] = $this->l('Booking detail not found.');
- }
-
- if (!$title) {
- $title = '--';
- } else {
- if (!Validate::isCatalogName($title)) {
- $this->errors[] = $this->l('Please enter a valid Title.');
+ // validations
+ $objHotelBookingDetail = new HotelBookingDetail($idHtlBooking);
+ if (!Validate::isLoadedObject($objHotelBookingDetail)) {
+ $this->errors[] = $this->l('Booking detail not found.');
}
- }
- $objHotelBookingDocument = new HotelBookingDocument();
- $objHotelBookingDocument->setFileInfoForUploadedDocument('booking_document');
- if (!count($objHotelBookingDocument->fileInfo)) {
- $this->errors[] = $this->l('Please select a file to upload.');
- } elseif ($objHotelBookingDocument->fileInfo['size'] > Tools::getMaxUploadSize()) {
- $this->errors[] = $this->l('Uploaded file size is too large.');
- } elseif(!(ImageManager::isRealImage($objHotelBookingDocument->fileInfo['tmp_name'])
- || $objHotelBookingDocument->fileInfo['mime'] == 'application/pdf')
- ) {
- $this->errors[] = $this->l('Please upload an image or a PDF file only. Allowed image formats: .gif, .jpg, .jpeg and .png');
+ if (!$title) {
+ $title = '--';
+ } else {
+ if (!Validate::isCatalogName($title)) {
+ $this->errors[] = $this->l('Please enter a valid Title.');
+ }
+ }
+
+ $objHotelBookingDocument = new HotelBookingDocument();
+ $objHotelBookingDocument->setFileInfoForUploadedDocument('booking_document');
+ if (!count($objHotelBookingDocument->fileInfo)) {
+ $this->errors[] = $this->l('Please select a file to upload.');
+ } elseif ($objHotelBookingDocument->fileInfo['size'] > Tools::getMaxUploadSize()) {
+ $this->errors[] = $this->l('Uploaded file size is too large.');
+ } elseif(!(ImageManager::isRealImage($objHotelBookingDocument->fileInfo['tmp_name'])
+ || $objHotelBookingDocument->fileInfo['mime'] == 'application/pdf')
+ ) {
+ $this->errors[] = $this->l('Please upload an image or a PDF file only. Allowed image formats: .gif, .jpg, .jpeg and .png');
+ }
+ } else {
+ $this->errors[] = Tools::displayError('You do not have permission to edit this order.');
}
if (!count($this->errors)) {
@@ -3249,16 +3271,23 @@ class AdminOrdersControllerCore extends AdminController
{
$response = array('status' => false);
- $idHtlBookingDocument = (int) Tools::getValue('id_htl_booking_document');
+ if ($this->tabAccess['edit'] == '1') {
+ $idHtlBookingDocument = (int) Tools::getValue('id_htl_booking_document');
- $objHotelBookingDocument = new HotelBookingDocument($idHtlBookingDocument);
- if (Validate::isLoadedObject($objHotelBookingDocument)) {
- $idHtlBooking = $objHotelBookingDocument->id_htl_booking;
- if ($objHotelBookingDocument->delete()) {
- $response['html'] = $this->getRenderedBookingDocuments($idHtlBooking);
- $response['num_checkin_documents'] = HotelBookingDocument::getCountByIdHtlBooking($idHtlBooking);
- $response['status'] = true;
+ $objHotelBookingDocument = new HotelBookingDocument($idHtlBookingDocument);
+ if (Validate::isLoadedObject($objHotelBookingDocument)) {
+ $idHtlBooking = $objHotelBookingDocument->id_htl_booking;
+ if ($objHotelBookingDocument->delete()) {
+ $response['html'] = $this->getRenderedBookingDocuments($idHtlBooking);
+ $response['num_checkin_documents'] = HotelBookingDocument::getCountByIdHtlBooking($idHtlBooking);
+ $response['status'] = true;
+ }
}
+ } else {
+ $this->errors[] = Tools::displayError('You do not have permission to edit this order.');
+ $this->context->smarty->assign(array('errors' => $this->errors));
+ $response['status'] = false;
+ $response['errors'] = $this->context->smarty->fetch('alerts.tpl');
}
$this->ajaxDie(json_encode($response));
@@ -3270,40 +3299,46 @@ class AdminOrdersControllerCore extends AdminController
'hasError' => false,
'errors' => array(),
);
- if (Validate::isLoadedObject($order = new Order(Tools::getValue('id_order')))) {
- $objCustomerGuestDetail = new OrderCustomerGuestDetail();
- $response['errors'] = $objCustomerGuestDetail->validateController();
- if (!$response['errors']) {
- if ($id_customer_guest_detail = OrderCustomerGuestDetail::isCustomerGuestBooking($order->id)) {
- if (Validate::isLoadedObject($objCustomerGuestDetail = new OrderCustomerGuestDetail($id_customer_guest_detail))) {
- $id_gender = Tools::getValue('id_gender');
- $firstname = Tools::getValue('firstname');
- $lastname = Tools::getValue('lastname');
- $email = Tools::getValue('email');
- $phone = Tools::getValue('phone');
- $objCustomerGuestDetail->id_gender = $id_gender;
- $objCustomerGuestDetail->firstname = $firstname;
- $objCustomerGuestDetail->lastname = $lastname;
- $objCustomerGuestDetail->email = $email;
- $objCustomerGuestDetail->phone = $phone;
- if ($objCustomerGuestDetail->save()) {
- $gender = new Gender($objCustomerGuestDetail->id_gender, $this->context->language->id);
- $response['data']['gender_name'] = $gender->name;
- $response['data']['guest_name'] = $objCustomerGuestDetail->firstname.' '.$objCustomerGuestDetail->lastname ;
- $response['data']['guest_email'] = $objCustomerGuestDetail->email;
- $response['data']['guest_phone'] = $objCustomerGuestDetail->phone;
- $response['msg'] = $this->l('Guest details are updated.');
+ // Check tab access is allowed to edit
+ if ($this->tabAccess['edit'] == 1) {
+ if (Validate::isLoadedObject($order = new Order(Tools::getValue('id_order')))) {
+ $objCustomerGuestDetail = new OrderCustomerGuestDetail();
+ $response['errors'] = $objCustomerGuestDetail->validateController();
+ if (!$response['errors']) {
+ if ($id_customer_guest_detail = OrderCustomerGuestDetail::isCustomerGuestBooking($order->id)) {
+ if (Validate::isLoadedObject($objCustomerGuestDetail = new OrderCustomerGuestDetail($id_customer_guest_detail))) {
+ $id_gender = Tools::getValue('id_gender');
+ $firstname = Tools::getValue('firstname');
+ $lastname = Tools::getValue('lastname');
+ $email = Tools::getValue('email');
+ $phone = Tools::getValue('phone');
+ $objCustomerGuestDetail->id_gender = $id_gender;
+ $objCustomerGuestDetail->firstname = $firstname;
+ $objCustomerGuestDetail->lastname = $lastname;
+ $objCustomerGuestDetail->email = $email;
+ $objCustomerGuestDetail->phone = $phone;
+ if ($objCustomerGuestDetail->save()) {
+ $gender = new Gender($objCustomerGuestDetail->id_gender, $this->context->language->id);
+ $response['data']['gender_name'] = $gender->name;
+ $response['data']['guest_name'] = $objCustomerGuestDetail->firstname.' '.$objCustomerGuestDetail->lastname ;
+ $response['data']['guest_email'] = $objCustomerGuestDetail->email;
+ $response['data']['guest_phone'] = $objCustomerGuestDetail->phone;
+
+ $response['msg'] = $this->l('Guest details are updated.');
+ } else {
+ $response['errors'][] = $this->l('Unable to save guest details.');
+ }
} else {
- $response['errors'][] = $this->l('Unable to save guest details.');
+ $response['errors'][] = $this->l('Guest details not found.');
}
} else {
$response['errors'][] = $this->l('Guest details not found.');
}
- } else {
- $response['errors'][] = $this->l('Guest details not found.');
}
}
+ } else {
+ $response['errors'][] = $this->l('You do not have permission to edit this order.');
}
if ($response['errors']) {
@@ -3321,6 +3356,7 @@ class AdminOrdersControllerCore extends AdminController
$bookingDocuments = HotelBookingDocument::getDocumentsByIdHtlBooking($idHtlBooking);
$this->context->smarty->assign(array(
+ 'can_edit' => $this->tabAccess['edit'],
'link' => $this->context->link,
'booking_documents' => $bookingDocuments,
'pdf_icon_link' => $this->context->link->getBaseLink().'modules/hotelreservationsystem/views/img/pdf-icon.jpg',
@@ -3547,6 +3583,14 @@ class AdminOrdersControllerCore extends AdminController
public function ajaxProcessAddServiceProductOnOrder()
{
+ // Check tab access is allowed to edit
+ if (!$this->tabAccess['edit'] == 1) {
+ die(json_encode(array(
+ 'result' => false,
+ 'error' => Tools::displayError('You do not have permission to edit this order.')
+ )));
+ }
+
// Load object
$order = new Order((int)Tools::getValue('id_order'));
if (!Validate::isLoadedObject($order)) {
@@ -3767,9 +3811,9 @@ class AdminOrdersControllerCore extends AdminController
$order->total_products += (float)$cart->getOrderTotal(false, Cart::ONLY_PRODUCTS);
$order->total_products_wt += (float)$cart->getOrderTotal($use_taxes, Cart::ONLY_PRODUCTS);
- $order->total_paid += (float)$cart->getOrderTotal(true, $total_method);
- $order->total_paid_tax_excl += (float)$cart->getOrderTotal(false, $total_method);
- $order->total_paid_tax_incl += (float)$cart->getOrderTotal($use_taxes, $total_method);
+ $order->total_paid = Tools::ps_round($order->getOrderTotal(), _PS_PRICE_COMPUTE_PRECISION_);
+ $order->total_paid_tax_incl = Tools::ps_round($order->getOrderTotal(), _PS_PRICE_COMPUTE_PRECISION_);
+ $order->total_paid_tax_excl = Tools::ps_round($order->getOrderTotal(false), _PS_PRICE_COMPUTE_PRECISION_);
if (isset($order_invoice) && Validate::isLoadedObject($order_invoice)) {
$order->total_shipping = $order_invoice->total_shipping_tax_incl;
@@ -3878,9 +3922,15 @@ class AdminOrdersControllerCore extends AdminController
$order->total_discounts += $order_cart_rule->value;
$order->total_discounts_tax_incl += $order_cart_rule->value;
$order->total_discounts_tax_excl += $order_cart_rule->value_tax_excl;
+
$order->total_paid -= $order_cart_rule->value;
+ $order->total_paid = $order->total_paid > 0 ? $order->total_paid : 0;
+
$order->total_paid_tax_incl -= $order_cart_rule->value;
+ $order->total_paid_tax_incl = $order->total_paid_tax_incl > 0 ? $order->total_paid_tax_incl : 0;
+
$order->total_paid_tax_excl -= $order_cart_rule->value_tax_excl;
+ $order->total_paid_tax_excl = $order->total_paid_tax_excl > 0 ? $order->total_paid_tax_excl : 0;
}
// Update Order
@@ -3889,7 +3939,7 @@ class AdminOrdersControllerCore extends AdminController
die(Tools::jsonEncode(array(
'result' => true,
'view' => $this->createTemplate('_product_line.tpl')->fetch(),
- 'can_edit' => $this->tabAccess['add'],
+ 'can_edit' => $this->tabAccess['edit'],
'order' => $order,
'invoices' => $invoice_array,
'documents_html' => $this->createTemplate('_documents.tpl')->fetch(),
@@ -3900,6 +3950,14 @@ class AdminOrdersControllerCore extends AdminController
public function ajaxProcessAddProductOnOrder()
{
+ // Check tab access is allowed to edit
+ if (!$this->tabAccess['edit'] == 1) {
+ die(json_encode(array(
+ 'result' => false,
+ 'error' => Tools::displayError('You do not have permission to edit this order.')
+ )));
+ }
+
// Load object
$id_order = (int) Tools::getValue('id_order');
$order = new Order($id_order);
@@ -3924,7 +3982,7 @@ class AdminOrdersControllerCore extends AdminController
/*By Webkul Code is added to add order information In our table while adding product in the process order edit from order detail page.*/
$date_from = date('Y-m-d H:i:s', strtotime($product_informations['date_from']));
$date_to = date('Y-m-d H:i:s', strtotime($product_informations['date_to']));
- $curr_date = date('Y-m-d H:i:s');
+ $curr_date = date('Y-m-d');
$occupancy = Tools::getValue('occupancy');
/*Validations*/
if ($date_from == '') {
@@ -4322,9 +4380,10 @@ class AdminOrdersControllerCore extends AdminController
// update totals amount of order
$order->total_products += (float)$cart->getOrderTotal(false, Cart::ONLY_PRODUCTS);
$order->total_products_wt += (float)$cart->getOrderTotal($use_taxes, Cart::ONLY_PRODUCTS);
- $order->total_paid += (float)$cart->getOrderTotal(true, $total_method);
- $order->total_paid_tax_excl += (float)$cart->getOrderTotal(false, $total_method);
- $order->total_paid_tax_incl += (float)$cart->getOrderTotal($use_taxes, $total_method);
+
+ $order->total_paid = Tools::ps_round($order->getOrderTotal(), _PS_PRICE_COMPUTE_PRECISION_);
+ $order->total_paid_tax_incl = Tools::ps_round($order->getOrderTotal(), _PS_PRICE_COMPUTE_PRECISION_);
+ $order->total_paid_tax_excl = Tools::ps_round($order->getOrderTotal(false), _PS_PRICE_COMPUTE_PRECISION_);
if (isset($order_invoice) && Validate::isLoadedObject($order_invoice)) {
$order->total_shipping = $order_invoice->total_shipping_tax_incl;
@@ -4413,9 +4472,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'];
@@ -4428,9 +4487,15 @@ class AdminOrdersControllerCore extends AdminController
$order->total_discounts += $order_cart_rule->value;
$order->total_discounts_tax_incl += $order_cart_rule->value;
$order->total_discounts_tax_excl += $order_cart_rule->value_tax_excl;
+
$order->total_paid -= $order_cart_rule->value;
+ $order->total_paid = $order->total_paid > 0 ? $order->total_paid : 0;
+
$order->total_paid_tax_incl -= $order_cart_rule->value;
+ $order->total_paid_tax_incl = $order->total_paid_tax_incl > 0 ? $order->total_paid_tax_incl : 0;
+
$order->total_paid_tax_excl -= $order_cart_rule->value_tax_excl;
+ $order->total_paid_tax_excl = $order->total_paid_tax_excl > 0 ? $order->total_paid_tax_excl : 0;
}
// Update Order
@@ -4581,7 +4646,7 @@ class AdminOrdersControllerCore extends AdminController
die(json_encode(array(
'result' => true,
//'view' => $this->createTemplate('_product_line.tpl')->fetch(),
- 'can_edit' => $this->tabAccess['add'],
+ 'can_edit' => $this->tabAccess['edit'],
'order' => $order,
'invoices' => $invoice_array,
'documents_html' => $this->createTemplate('_documents.tpl')->fetch(),
@@ -4590,7 +4655,6 @@ class AdminOrdersControllerCore extends AdminController
)));
}
-
/**
* This function is called when order is changed (Add/Edit/Delete room on order)
*/
@@ -4654,6 +4718,14 @@ class AdminOrdersControllerCore extends AdminController
public function ajaxProcessEditRoomOnOrder()
{
+ // Check tab access is allowed to edit
+ if (!$this->tabAccess['edit'] == 1) {
+ die(json_encode(array(
+ 'result' => false,
+ 'error' => Tools::displayError('You do not have permission to edit this order.')
+ )));
+ }
+
// Return value
$res = true;
$id_order = (int) Tools::getValue('id_order');
@@ -4773,10 +4845,13 @@ class AdminOrdersControllerCore extends AdminController
// Apply changes on Order
$order = new Order($order_detail->id_order);
$order->total_products += (float)$diff_price_tax_excl;
+ $order->total_products = $order->total_products > 0 ? $order->total_products : 0;
$order->total_products_wt += (float)$diff_price_tax_incl;
- $order->total_paid += (float)$diff_price_tax_incl;
- $order->total_paid_tax_excl += (float)$diff_price_tax_excl;
- $order->total_paid_tax_incl += (float)$diff_price_tax_incl;
+ $order->total_products_wt = $order->total_products_wt > 0 ? $order->total_products_wt : 0;
+
+ $order->total_paid = Tools::ps_round($order->getOrderTotal(), _PS_PRICE_COMPUTE_PRECISION_);
+ $order->total_paid_tax_incl = Tools::ps_round($order->getOrderTotal(), _PS_PRICE_COMPUTE_PRECISION_);
+ $order->total_paid_tax_excl = Tools::ps_round($order->getOrderTotal(false), _PS_PRICE_COMPUTE_PRECISION_);
$res &= $order->update();
}
@@ -4931,36 +5006,27 @@ class AdminOrdersControllerCore extends AdminController
)) {
// update extra demands total prices if dates are changes (price calc method for each day)
if ($extraDemands) {
- $objOrder = new Order($id_order);
+ $order = new Order($id_order);
foreach ($extraDemands as $demand) {
if (isset($demand['extra_demands']) && $demand['extra_demands']) {
foreach ($demand['extra_demands'] as $rDemand) {
if ($rDemand['price_calc_method'] == HotelRoomTypeGlobalDemand::WK_PRICE_CALC_METHOD_EACH_DAY) {
$objBookingDemand = new HotelBookingDemands($rDemand['id_booking_demand']);
- // change order total
- $objOrder->total_paid_tax_excl -= $objBookingDemand->total_price_tax_excl;
- $objOrder->total_paid_tax_incl -= $objBookingDemand->total_price_tax_incl;
- $objOrder->total_paid -= $objBookingDemand->total_price_tax_incl;
-
$numDays = $obj_booking_detail->getNumberOfDays($new_date_from, $new_date_to);
$demandPriceTE = Tools::processPriceRounding(
($objBookingDemand->unit_price_tax_excl * $numDays),
1,
- $objOrder->round_type,
- $objOrder->round_mode
+ $order->round_type,
+ $order->round_mode
);
$demandPriceTI = Tools::processPriceRounding(
($objBookingDemand->unit_price_tax_incl * $numDays),
1,
- $objOrder->round_type,
- $objOrder->round_mode
+ $order->round_type,
+ $order->round_mode
);
- $objOrder->total_paid_tax_excl += $demandPriceTE;
- $objOrder->total_paid_tax_incl += $demandPriceTI;
- $objOrder->total_paid += $demandPriceTI;
-
$objBookingDemand->total_price_tax_excl = $demandPriceTE;
$objBookingDemand->total_price_tax_incl = $demandPriceTI;
@@ -4970,14 +5036,18 @@ class AdminOrdersControllerCore extends AdminController
}
}
// change order total save
- $objOrder->save();
+ $order->total_paid = Tools::ps_round($order->getOrderTotal(), _PS_PRICE_COMPUTE_PRECISION_);
+ $order->total_paid_tax_incl = Tools::ps_round($order->getOrderTotal(), _PS_PRICE_COMPUTE_PRECISION_);
+ $order->total_paid_tax_excl = Tools::ps_round($order->getOrderTotal(false), _PS_PRICE_COMPUTE_PRECISION_);
+
+ $order->save();
}
if (isset($orderServiceProducts)
&& is_array($orderServiceProducts)
&& count($orderServiceProducts)
) {
- $objOrder = new Order((int) $id_order);
+ $order = new Order((int) $id_order);
foreach ($orderServiceProducts as $orderServiceProduct) {
if (isset($orderServiceProduct['additional_services'])
&& is_array($orderServiceProduct['additional_services'])
@@ -4993,28 +5063,22 @@ class AdminOrdersControllerCore extends AdminController
$newTotalPriceTaxExcl = Tools::processPriceRounding(
($newNumDays * $unitPriceTaxExcl),
$objRoomTypeServiceProductOrderDetail->quantity,
- $objOrder->round_type,
- $objOrder->round_mode
+ $order->round_type,
+ $order->round_mode
);
$newTotalPriceTaxIncl = Tools::processPriceRounding(
($newNumDays * $unitPriceTaxIncl),
$objRoomTypeServiceProductOrderDetail->quantity,
- $objOrder->round_type,
- $objOrder->round_mode
+ $order->round_type,
+ $order->round_mode
);
- $objOrder->total_products -= $objRoomTypeServiceProductOrderDetail->total_price_tax_excl;
- $objOrder->total_products_wt -= $objRoomTypeServiceProductOrderDetail->total_price_tax_incl;
- $objOrder->total_paid_tax_excl -= $objRoomTypeServiceProductOrderDetail->total_price_tax_excl;
- $objOrder->total_paid_tax_incl -= $objRoomTypeServiceProductOrderDetail->total_price_tax_incl;
- $objOrder->total_paid -= $objRoomTypeServiceProductOrderDetail->total_price_tax_incl;
+ $order->total_products -= $objRoomTypeServiceProductOrderDetail->total_price_tax_excl;
+ $order->total_products_wt -= $objRoomTypeServiceProductOrderDetail->total_price_tax_incl;
// change order total
- $objOrder->total_products += $newTotalPriceTaxExcl;
- $objOrder->total_products_wt += $newTotalPriceTaxIncl;
- $objOrder->total_paid_tax_excl += $newTotalPriceTaxExcl;
- $objOrder->total_paid_tax_incl += $newTotalPriceTaxIncl;
- $objOrder->total_paid += $newTotalPriceTaxIncl;
+ $order->total_products += $newTotalPriceTaxExcl;
+ $order->total_products_wt += $newTotalPriceTaxIncl;
$objOrderDetail = new OrderDetail((int) $serviceProduct['id_order_detail']);
$objOrderDetail->total_price_tax_excl -= $objRoomTypeServiceProductOrderDetail->total_price_tax_excl;
@@ -5039,7 +5103,10 @@ class AdminOrdersControllerCore extends AdminController
}
}
- $objOrder->save();
+ $order->total_paid = Tools::ps_round($order->getOrderTotal(), _PS_PRICE_COMPUTE_PRECISION_);
+ $order->total_paid_tax_incl = Tools::ps_round($order->getOrderTotal(), _PS_PRICE_COMPUTE_PRECISION_);
+ $order->total_paid_tax_excl = Tools::ps_round($order->getOrderTotal(false), _PS_PRICE_COMPUTE_PRECISION_);
+ $order->save();
}
}
@@ -5053,7 +5120,7 @@ class AdminOrdersControllerCore extends AdminController
die(json_encode(array(
'result' => $res,
'view' => $view,
- 'can_edit' => $this->tabAccess['add'],
+ 'can_edit' => $this->tabAccess['edit'],
'invoices_collection' => $invoice_collection,
'order' => $order,
'invoices' => $invoice_array,
@@ -5065,6 +5132,14 @@ class AdminOrdersControllerCore extends AdminController
public function ajaxProcessEditProductOnOrder()
{
+ // Check tab access is allowed to edit
+ if (!$this->tabAccess['edit'] == 1) {
+ die(json_encode(array(
+ 'result' => false,
+ 'error' => Tools::displayError('You do not have permission to edit this order.')
+ )));
+ }
+
// Return value
$res = true;
@@ -5135,10 +5210,13 @@ class AdminOrdersControllerCore extends AdminController
// Apply changes on Order
$order = new Order($order_detail->id_order);
$order->total_products += $diff_price_tax_excl;
+ $order->total_products = $order->total_products > 0 ? $order->total_products : 0;
$order->total_products_wt += $diff_price_tax_incl;
- $order->total_paid += $diff_price_tax_incl;
- $order->total_paid_tax_excl += $diff_price_tax_excl;
- $order->total_paid_tax_incl += $diff_price_tax_incl;
+ $order->total_products_wt = $order->total_products_wt > 0 ? $order->total_products_wt : 0;
+
+ $order->total_paid = Tools::ps_round($order->getOrderTotal(), _PS_PRICE_COMPUTE_PRECISION_);
+ $order->total_paid_tax_incl = Tools::ps_round($order->getOrderTotal(), _PS_PRICE_COMPUTE_PRECISION_);
+ $order->total_paid_tax_excl = Tools::ps_round($order->getOrderTotal(false), _PS_PRICE_COMPUTE_PRECISION_);
$res &= $order->update();
}
@@ -5236,7 +5314,7 @@ class AdminOrdersControllerCore extends AdminController
die(Tools::jsonEncode(array(
'result' => $res,
'view' => $view,
- 'can_edit' => $this->tabAccess['add'],
+ 'can_edit' => $this->tabAccess['edit'],
'invoices_collection' => $invoice_collection,
'order' => $order,
'invoices' => $invoice_array,
@@ -5248,6 +5326,14 @@ class AdminOrdersControllerCore extends AdminController
public function ajaxProcessDeleteRoomLine()
{
+ // Check tab access is allowed to edit
+ if (!$this->tabAccess['edit'] == 1) {
+ die(json_encode(array(
+ 'result' => false,
+ 'error' => Tools::displayError('You do not have permission to edit this order.')
+ )));
+ }
+
$res = true;
$order_detail = new OrderDetail((int) Tools::getValue('id_order_detail'));
$id_order = (int) Tools::getValue('id_order');
@@ -5397,16 +5483,14 @@ class AdminOrdersControllerCore extends AdminController
$res &= $order_invoice->update();
}
+ // Reinject quantity in stock
+ $order_detail->reinjectQuantity($order_detail, $order_detail->product_quantity, $delete);
+
// Update Order
// values changes as values are calculated accoding to the quantity of the product by webkul
- $order->total_paid -= ($diff_products_tax_incl + $roomExtraDemandTI + $additionlServicesTI);
- $order->total_paid = $order->total_paid > 0 ? $order->total_paid : 0;
-
- $order->total_paid_tax_incl -= ($diff_products_tax_incl + $roomExtraDemandTI + $additionlServicesTI);
- $order->total_paid_tax_incl = $order->total_paid_tax_incl > 0 ? $order->total_paid_tax_incl : 0;
-
- $order->total_paid_tax_excl -= ($diff_products_tax_excl + $roomExtraDemandTE + $additionlServicesTE);
- $order->total_paid_tax_excl = $order->total_paid_tax_excl > 0 ? $order->total_paid_tax_excl : 0;
+ $order->total_paid = Tools::ps_round($order->getOrderTotal(), _PS_PRICE_COMPUTE_PRECISION_);
+ $order->total_paid_tax_incl = Tools::ps_round($order->getOrderTotal(), _PS_PRICE_COMPUTE_PRECISION_);
+ $order->total_paid_tax_excl = Tools::ps_round($order->getOrderTotal(false), _PS_PRICE_COMPUTE_PRECISION_);
$order->total_products -= ($diff_products_tax_excl + $additionlServicesTE);
$order->total_products = $order->total_products > 0 ? $order->total_products : 0;
@@ -5416,9 +5500,6 @@ class AdminOrdersControllerCore extends AdminController
$res &= $order->update();
- // Reinject quantity in stock
- $order_detail->reinjectQuantity($order_detail, $order_detail->product_quantity, $delete);
-
// Update weight SUM
$order_carrier = new OrderCarrier((int) $order->getIdOrderCarrier());
if (Validate::isLoadedObject($order_carrier)) {
@@ -5470,6 +5551,25 @@ 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();
+ }
+
+ // If no rooms left in the order, Update Order total and discounts to 0
+ $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,
@@ -5492,6 +5592,14 @@ class AdminOrdersControllerCore extends AdminController
public function ajaxProcessDeleteProductLine()
{
+ // Check tab access is allowed to edit
+ if (!$this->tabAccess['edit'] == 1) {
+ die(json_encode(array(
+ 'result' => false,
+ 'error' => Tools::displayError('You do not have permission to edit this order.')
+ )));
+ }
+
$res = true;
$order_detail = new OrderDetail((int)Tools::getValue('id_order_detail'));
@@ -5510,11 +5618,15 @@ class AdminOrdersControllerCore extends AdminController
}
// Update Order
- $order->total_paid -= Tools::ps_round($order_detail->total_price_tax_incl, _PS_PRICE_COMPUTE_PRECISION_);
- $order->total_paid_tax_incl -= Tools::ps_round($order_detail->total_price_tax_incl, _PS_PRICE_COMPUTE_PRECISION_);
- $order->total_paid_tax_excl -= Tools::ps_round($order_detail->total_price_tax_excl, _PS_PRICE_COMPUTE_PRECISION_);
+ $order->total_paid = Tools::ps_round($order->getOrderTotal(), _PS_PRICE_COMPUTE_PRECISION_);
+ $order->total_paid_tax_incl = Tools::ps_round($order->getOrderTotal(), _PS_PRICE_COMPUTE_PRECISION_);
+ $order->total_paid_tax_excl = Tools::ps_round($order->getOrderTotal(false), _PS_PRICE_COMPUTE_PRECISION_);
+
$order->total_products -= Tools::ps_round($order_detail->total_price_tax_excl, _PS_PRICE_COMPUTE_PRECISION_);
+ $order->total_products = $order->total_products > 0 ? $order->total_products : 0;
+
$order->total_products_wt -= Tools::ps_round($order_detail->total_price_tax_incl, _PS_PRICE_COMPUTE_PRECISION_);
+ $order->total_products_wt = $order->total_products_wt > 0 ? $order->total_products_wt : 0;
$res &= $order->update();
@@ -5590,6 +5702,19 @@ class AdminOrdersControllerCore extends AdminController
}
}
+ /**
+ * Check if the room edit is valid. Check for the following things:
+ * - Check if the hotel booking is refunded or cancelled
+ * - Check if the room price, tax incl and excl is valid
+ * - Check if the room is already booked for the new date range
+ * - Check if the room is disabled for the new date range
+ * - Check if the hotel booking is with occupancy and children age is valid
+ * - Check if the new date is before current date
+ * @param OrderDetail $order_detail
+ * @param Order $order
+ * @param OrderInvoice $order_invoice
+ * @return bool
+ */
protected function doEditRoomValidation(OrderDetail $order_detail, Order $order, OrderInvoice $order_invoice = null)
{
$this->doEditValidation($order_detail, $order, $order_invoice);
@@ -6185,182 +6310,116 @@ class AdminOrdersControllerCore extends AdminController
public function ajaxProcessUpdateRoomAdditionalServices()
{
$response = array('hasError' => false);
- $id_room_type_service_product_order_detail = Tools::getValue('id_room_type_service_product_order_detail');
- $quantity = Tools::getValue('qty');
- $unitPrice = Tools::getValue('unit_price');
+ // Check tab access is allowed to edit
+ if ($this->tabAccess['edit'] == 1) {
+ $id_room_type_service_product_order_detail = Tools::getValue('id_room_type_service_product_order_detail');
+ $quantity = Tools::getValue('qty');
+ $unitPrice = Tools::getValue('unit_price');
- if (Validate::isLoadedObject($objRoomTypeServiceProductOrderDetail = new RoomTypeServiceProductOrderDetail($id_room_type_service_product_order_detail))) {
- $objOrderDetail = new OrderDetail($objRoomTypeServiceProductOrderDetail->id_order_detail);
- if (!$objOrderDetail->product_allow_multiple_quantity && $quantity > 1) {
- $response['hasError'] = true;
- $response['errors'] = $this->l('cannot order multiple quanitity for this service');
- } else if (!Validate::isUnsignedInt($quantity)) {
- $response['hasError'] = true;
- $response['errors'] = $this->l('Invalid quantity provided');
- }
-
- if (!ValidateCore::isPrice($unitPrice)) {
- $response['hasError'] = true;
- $response['errors'] = $this->l('Invalid unit price');
- }
-
- $objHotelBookingDetail = new HotelBookingDetail($objRoomTypeServiceProductOrderDetail->id_htl_booking_detail);
- $res = true;
- if (!$response['hasError']) {
- $order = new Order($objRoomTypeServiceProductOrderDetail->id_order);
-
- $oldUnitPriceTaxExcl = $objRoomTypeServiceProductOrderDetail->unit_price_tax_excl;
- $oldUnitPriceTaxIncl = $objRoomTypeServiceProductOrderDetail->unit_price_tax_incl;
-
- $oldTotalPriceTaxExcl = $objRoomTypeServiceProductOrderDetail->total_price_tax_excl;
- $oldTotalPriceTaxIncl = $objRoomTypeServiceProductOrderDetail->total_price_tax_incl;
-
- $oldQuantity = $objRoomTypeServiceProductOrderDetail->quantity;
-
- if ($oldUnitPriceTaxExcl > 0) {
- $oldTaxMultiplier = $oldUnitPriceTaxIncl / $oldUnitPriceTaxExcl;
- } else {
- $oldTaxMultiplier = 1;
- }
- if ($quantity <= 0) {
- $quantity = 1;
+ if (Validate::isLoadedObject($objRoomTypeServiceProductOrderDetail = new RoomTypeServiceProductOrderDetail($id_room_type_service_product_order_detail))) {
+ $objOrderDetail = new OrderDetail($objRoomTypeServiceProductOrderDetail->id_order_detail);
+ if (!$objOrderDetail->product_allow_multiple_quantity && $quantity > 1) {
+ $response['hasError'] = true;
+ $response['errors'] = $this->l('cannot order multiple quanitity for this service');
+ } else if (!Validate::isUnsignedInt($quantity)) {
+ $response['hasError'] = true;
+ $response['errors'] = $this->l('Invalid quantity provided');
}
- $objRoomTypeServiceProductOrderDetail->quantity = $quantity;
- $objRoomTypeServiceProductOrderDetail->unit_price_tax_excl = $unitPrice;
- $objRoomTypeServiceProductOrderDetail->unit_price_tax_incl = $unitPrice * $oldTaxMultiplier;
-
- $numDays = 1;
- if ($objOrderDetail->product_price_calculation_method == Product::PRICE_CALCULATION_METHOD_PER_DAY) {
- $numDays = HotelHelper::getNumberOfDays(
- $objHotelBookingDetail->date_from,
- $objHotelBookingDetail->date_to
- );
+ if (!ValidateCore::isPrice($unitPrice)) {
+ $response['hasError'] = true;
+ $response['errors'] = $this->l('Invalid unit price');
}
- $objRoomTypeServiceProductOrderDetail->total_price_tax_excl = Tools::processPriceRounding(
- ($objRoomTypeServiceProductOrderDetail->unit_price_tax_excl * $numDays),
- $quantity,
- $order->round_type,
- $order->round_mode
- );
- $objRoomTypeServiceProductOrderDetail->total_price_tax_incl = Tools::processPriceRounding(
- ($objRoomTypeServiceProductOrderDetail->unit_price_tax_incl * $numDays),
- $quantity,
- $order->round_type,
- $order->round_mode
- );
- if ($res &= $objRoomTypeServiceProductOrderDetail->save()) {
- $priceDiffTaxExcl = $objRoomTypeServiceProductOrderDetail->total_price_tax_excl - $oldTotalPriceTaxExcl;
- $priceDiffTaxIncl = $objRoomTypeServiceProductOrderDetail->total_price_tax_incl - $oldTotalPriceTaxIncl;
+ $objHotelBookingDetail = new HotelBookingDetail($objRoomTypeServiceProductOrderDetail->id_htl_booking_detail);
+ $res = true;
+ if (!$response['hasError']) {
+ $order = new Order($objRoomTypeServiceProductOrderDetail->id_order);
- $quantityDiff = $objRoomTypeServiceProductOrderDetail->quantity - $oldQuantity;
+ $oldUnitPriceTaxExcl = $objRoomTypeServiceProductOrderDetail->unit_price_tax_excl;
+ $oldUnitPriceTaxIncl = $objRoomTypeServiceProductOrderDetail->unit_price_tax_incl;
- $objOrderDetail->product_quantity += $quantityDiff;
- $objOrderDetail->total_price_tax_excl += $priceDiffTaxExcl;
- $objOrderDetail->total_price_tax_incl += $priceDiffTaxIncl;
+ $oldTotalPriceTaxExcl = $objRoomTypeServiceProductOrderDetail->total_price_tax_excl;
+ $oldTotalPriceTaxIncl = $objRoomTypeServiceProductOrderDetail->total_price_tax_incl;
- $objOrderDetail->unit_price_tax_excl = ($objOrderDetail->total_price_tax_excl / $objOrderDetail->product_quantity);
- $objOrderDetail->unit_price_tax_incl = ($objOrderDetail->total_price_tax_incl / $objOrderDetail->product_quantity);
+ $oldQuantity = $objRoomTypeServiceProductOrderDetail->quantity;
- $res &= $objOrderDetail->updateTaxAmount($order);
-
- $res &= $objOrderDetail->update();
-
- if ($objOrderDetail->id_order_invoice != 0) {
- // values changes as values are calculated accoding to the quantity of the product by webkul
- $order_invoice = new OrderInvoice($objOrderDetail->id_order_invoice);
- $order_invoice->total_paid_tax_excl = Tools::ps_round((float)($order_invoice->total_paid_tax_excl + $priceDiffTaxExcl), _PS_PRICE_COMPUTE_PRECISION_);
- $order_invoice->total_paid_tax_incl = Tools::ps_round((float)($order_invoice->total_paid_tax_incl + $priceDiffTaxIncl), _PS_PRICE_COMPUTE_PRECISION_);
- $res &= $order_invoice->update();
+ if ($oldUnitPriceTaxExcl > 0) {
+ $oldTaxMultiplier = $oldUnitPriceTaxIncl / $oldUnitPriceTaxExcl;
+ } else {
+ $oldTaxMultiplier = 1;
+ }
+ if ($quantity <= 0) {
+ $quantity = 1;
}
- $order->total_products = Tools::ps_round((float)($order->total_products + $priceDiffTaxExcl), _PS_PRICE_COMPUTE_PRECISION_);
- $order->total_products_wt = Tools::ps_round((float)($order->total_products_wt + $priceDiffTaxIncl), _PS_PRICE_COMPUTE_PRECISION_);
- $order->total_paid_tax_excl = Tools::ps_round((float)($order->total_paid_tax_excl + $priceDiffTaxExcl), _PS_PRICE_COMPUTE_PRECISION_);
- $order->total_paid_tax_incl = Tools::ps_round((float)($order->total_paid_tax_incl + $priceDiffTaxIncl), _PS_PRICE_COMPUTE_PRECISION_);
- $order->total_paid = Tools::ps_round((float)($order->total_paid + $priceDiffTaxIncl), _PS_PRICE_COMPUTE_PRECISION_);
+ $objRoomTypeServiceProductOrderDetail->quantity = $quantity;
+ $objRoomTypeServiceProductOrderDetail->unit_price_tax_excl = $unitPrice;
+ $objRoomTypeServiceProductOrderDetail->unit_price_tax_incl = $unitPrice * $oldTaxMultiplier;
- $res &= $order->update();
- }
- }
- if (!$res) {
- $response['hasError'] = true;
- $response['errors'] = $this->l('Error while updating service, please try refresing the page');
- }
-
- $response['service_panel']= $servicesBlock = $this->processRenderServicesPanel(
- $objOrderDetail->id_order,
- $objHotelBookingDetail->id_product,
- $objHotelBookingDetail->date_from,
- $objHotelBookingDetail->date_to,
- $objHotelBookingDetail->id_room,
- $objHotelBookingDetail->id,
- true
- );
- } else {
- $response['hasError'] = true;
- $response['errors'] = $this->l('Additional service not found');
- }
-
- die(json_encode($response));
- }
-
- public function ajaxProcessDeleteRoomAdditionalService()
- {
- $response = array('hasError' => false);
- $id_room_type_service_product_order_detail = Tools::getValue('id_room_type_service_product_order_detail');
-
- if (Validate::isLoadedObject($objRoomTypeServiceProductOrderDetail = new RoomTypeServiceProductOrderDetail($id_room_type_service_product_order_detail))) {
- $objOrderDetail = new OrderDetail($objRoomTypeServiceProductOrderDetail->id_order_detail);
- $priceTaxExcl = $objRoomTypeServiceProductOrderDetail->total_price_tax_excl;
- $priceTaxIncl = $objRoomTypeServiceProductOrderDetail->total_price_tax_incl;
- $quantity = $objRoomTypeServiceProductOrderDetail->quantity;
- $res = true;
- $objHotelBookingDetail = new HotelBookingDetail($objRoomTypeServiceProductOrderDetail->id_htl_booking_detail);
-
- if ($res &= $objRoomTypeServiceProductOrderDetail->delete()) {
- $order = new Order($objRoomTypeServiceProductOrderDetail->id_order);
- if ($quantity >= $objOrderDetail->product_quantity) {
- $objOrderDetail->delete();
- } else {
- $objOrderDetail->product_quantity -= $quantity;
-
- $objOrderDetail->total_price_tax_excl -= Tools::processPriceRounding(
- $priceTaxExcl,
- 1,
+ $numDays = 1;
+ if ($objOrderDetail->product_price_calculation_method == Product::PRICE_CALCULATION_METHOD_PER_DAY) {
+ $numDays = HotelHelper::getNumberOfDays(
+ $objHotelBookingDetail->date_from,
+ $objHotelBookingDetail->date_to
+ );
+ }
+ $objRoomTypeServiceProductOrderDetail->total_price_tax_excl = Tools::processPriceRounding(
+ ($objRoomTypeServiceProductOrderDetail->unit_price_tax_excl * $numDays),
+ $quantity,
$order->round_type,
$order->round_mode
);
- $objOrderDetail->total_price_tax_incl -= Tools::processPriceRounding(
- $priceTaxIncl,
- 1,
+ $objRoomTypeServiceProductOrderDetail->total_price_tax_incl = Tools::processPriceRounding(
+ ($objRoomTypeServiceProductOrderDetail->unit_price_tax_incl * $numDays),
+ $quantity,
$order->round_type,
$order->round_mode
);
- $res &= $objOrderDetail->updateTaxAmount($order);
+ if ($res &= $objRoomTypeServiceProductOrderDetail->save()) {
+ $priceDiffTaxExcl = $objRoomTypeServiceProductOrderDetail->total_price_tax_excl - $oldTotalPriceTaxExcl;
+ $priceDiffTaxIncl = $objRoomTypeServiceProductOrderDetail->total_price_tax_incl - $oldTotalPriceTaxIncl;
- $res &= $objOrderDetail->update();
+ $quantityDiff = $objRoomTypeServiceProductOrderDetail->quantity - $oldQuantity;
+
+ $objOrderDetail->product_quantity += $quantityDiff;
+ $objOrderDetail->total_price_tax_excl += $priceDiffTaxExcl;
+ $objOrderDetail->total_price_tax_incl += $priceDiffTaxIncl;
+
+ $objOrderDetail->unit_price_tax_excl = ($objOrderDetail->total_price_tax_excl / $objOrderDetail->product_quantity);
+ $objOrderDetail->unit_price_tax_incl = ($objOrderDetail->total_price_tax_incl / $objOrderDetail->product_quantity);
+
+ $res &= $objOrderDetail->updateTaxAmount($order);
+
+ $res &= $objOrderDetail->update();
+
+ if ($objOrderDetail->id_order_invoice != 0) {
+ // values changes as values are calculated accoding to the quantity of the product by webkul
+ $order_invoice = new OrderInvoice($objOrderDetail->id_order_invoice);
+ $order_invoice->total_paid_tax_excl = Tools::ps_round((float)($order_invoice->total_paid_tax_excl + $priceDiffTaxExcl), _PS_PRICE_COMPUTE_PRECISION_);
+ $order_invoice->total_paid_tax_incl = Tools::ps_round((float)($order_invoice->total_paid_tax_incl + $priceDiffTaxIncl), _PS_PRICE_COMPUTE_PRECISION_);
+ $res &= $order_invoice->update();
+ }
+
+ $order->total_products = Tools::ps_round((float)($order->total_products + $priceDiffTaxExcl), _PS_PRICE_COMPUTE_PRECISION_);
+ $order->total_products = $order->total_products > 0 ? $order->total_products : 0;
+
+ $order->total_products_wt = Tools::ps_round((float)($order->total_products_wt + $priceDiffTaxIncl), _PS_PRICE_COMPUTE_PRECISION_);
+ $order->total_products_wt = $order->total_products_wt > 0 ? $order->total_products_wt : 0;
+
+ $order->total_paid = Tools::ps_round($order->getOrderTotal(), _PS_PRICE_COMPUTE_PRECISION_);
+ $order->total_paid_tax_incl = Tools::ps_round($order->getOrderTotal(), _PS_PRICE_COMPUTE_PRECISION_);
+ $order->total_paid_tax_excl = Tools::ps_round($order->getOrderTotal(false), _PS_PRICE_COMPUTE_PRECISION_);
+
+ $res &= $order->update();
+ }
+ }
+ if (!$res) {
+ $response['hasError'] = true;
+ $response['errors'] = $this->l('Error while updating service, please try refresing the page');
}
- if ($objOrderDetail->id_order_invoice != 0) {
- // values changes as values are calculated
- $objOrderInvoice = new OrderInvoice($objOrderDetail->id_order_invoice);
- $objOrderInvoice->total_paid_tax_excl = Tools::ps_round((float)($objOrderInvoice->total_paid_tax_excl - $priceTaxExcl), _PS_PRICE_COMPUTE_PRECISION_);
- $objOrderInvoice->total_paid_tax_incl = Tools::ps_round((float)($objOrderInvoice->total_paid_tax_incl - $priceTaxIncl), _PS_PRICE_COMPUTE_PRECISION_);
- $res &= $objOrderInvoice->update();
- }
-
- $order->total_products = Tools::ps_round((float)($order->total_products - $priceTaxExcl), _PS_PRICE_COMPUTE_PRECISION_);
- $order->total_products_wt = Tools::ps_round((float)($order->total_products_wt - $priceTaxIncl), _PS_PRICE_COMPUTE_PRECISION_);
- $order->total_paid_tax_excl = Tools::ps_round((float)($order->total_paid_tax_excl - $priceTaxExcl), _PS_PRICE_COMPUTE_PRECISION_);
- $order->total_paid_tax_incl = Tools::ps_round((float)($order->total_paid_tax_incl - $priceTaxIncl), _PS_PRICE_COMPUTE_PRECISION_);
- $order->total_paid = Tools::ps_round((float)($order->total_paid - $priceTaxIncl), _PS_PRICE_COMPUTE_PRECISION_);
-
- $res &= $order->update();
- }
- if ($res) {
$response['service_panel']= $servicesBlock = $this->processRenderServicesPanel(
$objOrderDetail->id_order,
$objHotelBookingDetail->id_product,
@@ -6370,10 +6429,96 @@ class AdminOrdersControllerCore extends AdminController
$objHotelBookingDetail->id,
true
);
+ } else {
+ $response['hasError'] = true;
+ $response['errors'] = $this->l('Additional service not found');
}
} else {
$response['hasError'] = true;
- $response['errors'] = $this->l('Additional service not found');
+ $response['errors'] = $this->l('You do not have permission to edit this order.');
+ }
+
+ die(json_encode($response));
+ }
+
+ public function ajaxProcessDeleteRoomAdditionalService()
+ {
+ $response = array('hasError' => false);
+ // Check tab access is allowed to edit
+ if ($this->tabAccess['edit'] == 1) {
+ $id_room_type_service_product_order_detail = Tools::getValue('id_room_type_service_product_order_detail');
+
+ if (Validate::isLoadedObject($objRoomTypeServiceProductOrderDetail = new RoomTypeServiceProductOrderDetail($id_room_type_service_product_order_detail))) {
+ $objOrderDetail = new OrderDetail($objRoomTypeServiceProductOrderDetail->id_order_detail);
+ $priceTaxExcl = $objRoomTypeServiceProductOrderDetail->total_price_tax_excl;
+ $priceTaxIncl = $objRoomTypeServiceProductOrderDetail->total_price_tax_incl;
+ $quantity = $objRoomTypeServiceProductOrderDetail->quantity;
+ $res = true;
+ $objHotelBookingDetail = new HotelBookingDetail($objRoomTypeServiceProductOrderDetail->id_htl_booking_detail);
+
+ if ($res &= $objRoomTypeServiceProductOrderDetail->delete()) {
+ $order = new Order($objRoomTypeServiceProductOrderDetail->id_order);
+ if ($quantity >= $objOrderDetail->product_quantity) {
+ $objOrderDetail->delete();
+ } else {
+ $objOrderDetail->product_quantity -= $quantity;
+
+ $objOrderDetail->total_price_tax_excl -= Tools::processPriceRounding(
+ $priceTaxExcl,
+ 1,
+ $order->round_type,
+ $order->round_mode
+ );
+ $objOrderDetail->total_price_tax_incl -= Tools::processPriceRounding(
+ $priceTaxIncl,
+ 1,
+ $order->round_type,
+ $order->round_mode
+ );
+
+ $res &= $objOrderDetail->updateTaxAmount($order);
+
+ $res &= $objOrderDetail->update();
+ }
+
+ if ($objOrderDetail->id_order_invoice != 0) {
+ // values changes as values are calculated
+ $objOrderInvoice = new OrderInvoice($objOrderDetail->id_order_invoice);
+ $objOrderInvoice->total_paid_tax_excl = Tools::ps_round((float)($objOrderInvoice->total_paid_tax_excl - $priceTaxExcl), _PS_PRICE_COMPUTE_PRECISION_);
+ $objOrderInvoice->total_paid_tax_incl = Tools::ps_round((float)($objOrderInvoice->total_paid_tax_incl - $priceTaxIncl), _PS_PRICE_COMPUTE_PRECISION_);
+ $res &= $objOrderInvoice->update();
+ }
+
+ $order->total_products = Tools::ps_round((float)($order->total_products - $priceTaxExcl), _PS_PRICE_COMPUTE_PRECISION_);
+ $order->total_products = $order->total_products > 0 ? $order->total_products : 0;
+
+ $order->total_products_wt = Tools::ps_round((float)($order->total_products_wt - $priceTaxIncl), _PS_PRICE_COMPUTE_PRECISION_);
+ $order->total_products_wt = $order->total_products_wt > 0 ? $order->total_products_wt : 0;
+
+ $order->total_paid = Tools::ps_round($order->getOrderTotal(), _PS_PRICE_COMPUTE_PRECISION_);
+ $order->total_paid_tax_incl = Tools::ps_round($order->getOrderTotal(), _PS_PRICE_COMPUTE_PRECISION_);
+ $order->total_paid_tax_excl = Tools::ps_round($order->getOrderTotal(false), _PS_PRICE_COMPUTE_PRECISION_);
+
+ $res &= $order->update();
+ }
+ if ($res) {
+ $response['service_panel']= $servicesBlock = $this->processRenderServicesPanel(
+ $objOrderDetail->id_order,
+ $objHotelBookingDetail->id_product,
+ $objHotelBookingDetail->date_from,
+ $objHotelBookingDetail->date_to,
+ $objHotelBookingDetail->id_room,
+ $objHotelBookingDetail->id,
+ true
+ );
+ }
+ } else {
+ $response['hasError'] = true;
+ $response['errors'] = $this->l('Additional service not found');
+ }
+ } else {
+ $response['hasError'] = true;
+ $response['errors'] = $this->l('You do not have permission to edit this order.');
}
die(json_encode($response));
@@ -6381,233 +6526,240 @@ class AdminOrdersControllerCore extends AdminController
public function ajaxProcessAddRoomAdditionalServices()
{
- $idBookingDetail = Tools::getValue('id_booking_detail');
$response = array('hasError' => false);
- if ($selectedServices = Tools::getValue('selected_service')) {
- // valiadate services being added
- if (Validate::isLoadedObject($objHotelBookingDetail = new HotelBookingDetail($idBookingDetail))) {
- $objOrder = new Order($objHotelBookingDetail->id_order);
- $objOrderDetail = new OrderDetail($objHotelBookingDetail->id_order_detail);
- $objOrderInvoice = new OrderInvoice($objOrderDetail->id_order_invoice);
+ // Check tab access is allowed to edit
+ if ($this->tabAccess['edit'] == 1) {
+ $idBookingDetail = Tools::getValue('id_booking_detail');
+ if ($selectedServices = Tools::getValue('selected_service')) {
+ // valiadate services being added
+ if (Validate::isLoadedObject($objHotelBookingDetail = new HotelBookingDetail($idBookingDetail))) {
+ $objOrder = new Order($objHotelBookingDetail->id_order);
+ $objOrderDetail = new OrderDetail($objHotelBookingDetail->id_order_detail);
+ $objOrderInvoice = new OrderInvoice($objOrderDetail->id_order_invoice);
- // set context currency So that we can get prices in the order currency
- $this->context->currency = new Currency($objOrder->id_currency);
+ // set context currency So that we can get prices in the order currency
+ $this->context->currency = new Currency($objOrder->id_currency);
- $objRoomTypeServiceProduct = new RoomTypeServiceProduct();
- $qty = Tools::getValue('service_qty');
- $price = Tools::getValue('service_price');
- foreach ($selectedServices as $key => $service) {
- if ($objRoomTypeServiceProduct->isRoomTypeLinkedWithProduct($objHotelBookingDetail->id_product, $service)) {
- $objProduct = new Product($service, false, $this->context->language->id);
- if ($objProduct->allow_multiple_quantity) {
- if (!Validate::isUnsignedInt($qty[$service])) {
+ $objRoomTypeServiceProduct = new RoomTypeServiceProduct();
+ $qty = Tools::getValue('service_qty');
+ $price = Tools::getValue('service_price');
+ foreach ($selectedServices as $key => $service) {
+ if ($objRoomTypeServiceProduct->isRoomTypeLinkedWithProduct($objHotelBookingDetail->id_product, $service)) {
+ $objProduct = new Product($service, false, $this->context->language->id);
+ if ($objProduct->allow_multiple_quantity) {
+ if (!Validate::isUnsignedInt($qty[$service])) {
+ $response['hasError'] = true;
+ $response['errors'][] = sprintf($this->l('The quantity you\'ve entered is invalid for %s.'), $objProduct->name);
+ }
+ } else {
+ $qty[$service] = 1;
+ }
+ if (!ValidateCore::isPrice($price[$service])) {
$response['hasError'] = true;
- $response['errors'][] = sprintf($this->l('The quantity you\'ve entered is invalid for %s.'), $objProduct->name);
+ $response['errors'][] = sprintf($this->l('Invalid unit price for %s.'), $objProduct->name);
}
+ $selectedServices[$key] = array(
+ 'id' => $service,
+ 'qty' => $qty[$service],
+ 'price' => $price[$service],
+ 'name' => $objProduct->name,
+ );
} else {
- $qty[$service] = 1;
- }
- if (!ValidateCore::isPrice($price[$service])) {
$response['hasError'] = true;
- $response['errors'][] = sprintf($this->l('Invalid unit price for %s.'), $objProduct->name);
+ $response['errors'][] = sprintf($this->l('The service %s is not avaialable for current room.'), $objProduct->name);
}
- $selectedServices[$key] = array(
- 'id' => $service,
- 'qty' => $qty[$service],
- 'price' => $price[$service],
- 'name' => $objProduct->name,
- );
- } else {
- $response['hasError'] = true;
- $response['errors'][] = sprintf($this->l('The service %s is not avaialable for current room.'), $objProduct->name);
}
- }
- $objHotelCartBookingData = new HotelCartBookingData();
- $roomHtlCartInfo = $objHotelCartBookingData->getRoomRowByIdProductIdRoomInDateRange(
- $objHotelBookingDetail->id_cart,
- $objHotelBookingDetail->id_product,
- $objHotelBookingDetail->date_from,
- $objHotelBookingDetail->date_to,
- $objHotelBookingDetail->id_room
- );
+ $objHotelCartBookingData = new HotelCartBookingData();
+ $roomHtlCartInfo = $objHotelCartBookingData->getRoomRowByIdProductIdRoomInDateRange(
+ $objHotelBookingDetail->id_cart,
+ $objHotelBookingDetail->id_product,
+ $objHotelBookingDetail->date_from,
+ $objHotelBookingDetail->date_to,
+ $objHotelBookingDetail->id_room
+ );
- // add services in room
- $order = new Order($objHotelBookingDetail->id_order);
- if (!$response['hasError']) {
- $this->context->currency = new Currency($order->id_currency);
- foreach ($selectedServices as $service) {
- // Create new cart
- $cart = new Cart();
- $cart->id_shop_group = $order->id_shop_group;
- $cart->id_shop = $order->id_shop;
- $cart->id_customer = $order->id_customer;
- $cart->id_carrier = $order->id_carrier;
- $cart->id_address_delivery = $order->id_address_delivery;
- $cart->id_address_invoice = $order->id_address_invoice;
- $cart->id_currency = $order->id_currency;
- $cart->id_lang = $order->id_lang;
- $cart->secure_key = $order->secure_key;
+ // add services in room
+ $order = new Order($objHotelBookingDetail->id_order);
+ if (!$response['hasError']) {
+ $this->context->currency = new Currency($order->id_currency);
+ foreach ($selectedServices as $service) {
+ // Create new cart
+ $cart = new Cart();
+ $cart->id_shop_group = $order->id_shop_group;
+ $cart->id_shop = $order->id_shop;
+ $cart->id_customer = $order->id_customer;
+ $cart->id_carrier = $order->id_carrier;
+ $cart->id_address_delivery = $order->id_address_delivery;
+ $cart->id_address_invoice = $order->id_address_invoice;
+ $cart->id_currency = $order->id_currency;
+ $cart->id_lang = $order->id_lang;
+ $cart->secure_key = $order->secure_key;
- // Save new cart
- $cart->add();
+ // Save new cart
+ $cart->add();
- $this->context->cart = $cart;
- $this->context->customer = new Customer($order->id_customer);
+ $this->context->cart = $cart;
+ $this->context->customer = new Customer($order->id_customer);
- $numDays = 1;
- if (Product::getProductPriceCalculation($service['id']) == Product::PRICE_CALCULATION_METHOD_PER_DAY) {
- $numDays = HotelHelper::getNumberOfDays($objHotelBookingDetail->date_from, $objHotelBookingDetail->date_to);
- }
+ $numDays = 1;
+ if (Product::getProductPriceCalculation($service['id']) == Product::PRICE_CALCULATION_METHOD_PER_DAY) {
+ $numDays = HotelHelper::getNumberOfDays($objHotelBookingDetail->date_from, $objHotelBookingDetail->date_to);
+ }
- $objRoomTypeServiceProductPrice = new RoomTypeServiceProductPrice();
- $initialServicePrice = $objRoomTypeServiceProductPrice->getServicePrice(
- (int)$service['id'],
- $roomHtlCartInfo['id_product'],
- 1,
- $objHotelBookingDetail->date_from,
- $objHotelBookingDetail->date_to,
- false
- ) / $numDays;
+ $objRoomTypeServiceProductPrice = new RoomTypeServiceProductPrice();
+ $initialServicePrice = $objRoomTypeServiceProductPrice->getServicePrice(
+ (int)$service['id'],
+ $roomHtlCartInfo['id_product'],
+ 1,
+ $objHotelBookingDetail->date_from,
+ $objHotelBookingDetail->date_to,
+ false
+ ) / $numDays;
- if ($initialServicePrice != $service['price']) {
- $specific_price = new SpecificPrice();
- $specific_price->id_shop = 0;
- $specific_price->id_shop_group = 0;
- $specific_price->id_cart = $cart->id;
- $specific_price->id_currency = $order->id_currency;
- $specific_price->id_country = 0;
- $specific_price->id_group = 0;
- $specific_price->id_customer = $order->id_customer;
- $specific_price->id_product = $service['id'];
- $specific_price->id_product_attribute = 0;
- $specific_price->price = $service['price'];
- $specific_price->from_quantity = 1;
- $specific_price->reduction = 0;
- $specific_price->reduction_type = 'amount';
- $specific_price->reduction_tax = 0;
- $specific_price->from = '0000-00-00 00:00:00';
- $specific_price->to = '0000-00-00 00:00:00';
- $specific_price->add();
- }
+ if ($initialServicePrice != $service['price']) {
+ $specific_price = new SpecificPrice();
+ $specific_price->id_shop = 0;
+ $specific_price->id_shop_group = 0;
+ $specific_price->id_cart = $cart->id;
+ $specific_price->id_currency = $order->id_currency;
+ $specific_price->id_country = 0;
+ $specific_price->id_group = 0;
+ $specific_price->id_customer = $order->id_customer;
+ $specific_price->id_product = $service['id'];
+ $specific_price->id_product_attribute = 0;
+ $specific_price->price = $service['price'];
+ $specific_price->from_quantity = 1;
+ $specific_price->reduction = 0;
+ $specific_price->reduction_type = 'amount';
+ $specific_price->reduction_tax = 0;
+ $specific_price->from = '0000-00-00 00:00:00';
+ $specific_price->to = '0000-00-00 00:00:00';
+ $specific_price->add();
+ }
- $objRoomTypeServiceProductCartDetail = new RoomTypeServiceProductCartDetail();
- $objRoomTypeServiceProductCartDetail->addServiceProductInCart(
- $service['id'],
- $service['qty'],
- $cart->id,
- $roomHtlCartInfo['id']
- );
- $productList = $cart->getProducts();
- $objHotelRoomType = new HotelRoomType();
- $roomInfo = $objHotelRoomType->getRoomTypeInfoByIdProduct($objHotelBookingDetail->id_product);
- $totalPriceChangeTaxExcl = 0;
- $totalPriceChangeTaxIncl = 0;
- $unitPriceTaxIncl = 0;
- $unitPriceTaxExcl = 0;
- foreach ($productList as $product) {
- // This is used to get the actual quanity of the service as it is calculated incorrectly if the service is per night
- if ($id_room_type_service_product_cart_detail = $objRoomTypeServiceProductCartDetail->alreadyExists(
+ $objRoomTypeServiceProductCartDetail = new RoomTypeServiceProductCartDetail();
+ $objRoomTypeServiceProductCartDetail->addServiceProductInCart(
$service['id'],
+ $service['qty'],
$cart->id,
- $roomHtlCartInfo['id'])
- ) {
- $objRoomTypeServiceProductCartDetail = new RoomTypeServiceProductCartDetail((int) $id_room_type_service_product_cart_detail);
+ $roomHtlCartInfo['id']
+ );
+ $productList = $cart->getProducts();
+ $objHotelRoomType = new HotelRoomType();
+ $roomInfo = $objHotelRoomType->getRoomTypeInfoByIdProduct($objHotelBookingDetail->id_product);
+ $totalPriceChangeTaxExcl = 0;
+ $totalPriceChangeTaxIncl = 0;
+ $unitPriceTaxIncl = 0;
+ $unitPriceTaxExcl = 0;
+ foreach ($productList as &$product) {
+ // This is used to get the actual quanity of the service as it is calculated incorrectly if the service is per night
+ if ($id_room_type_service_product_cart_detail = $objRoomTypeServiceProductCartDetail->alreadyExists(
+ $service['id'],
+ $cart->id,
+ $roomHtlCartInfo['id'])
+ ) {
+ $objRoomTypeServiceProductCartDetail = new RoomTypeServiceProductCartDetail((int) $id_room_type_service_product_cart_detail);
- $unitPriceTaxExcl = $objRoomTypeServiceProductPrice->getServicePrice(
- (int)$product['id_product'],
- $roomHtlCartInfo['id_product'],
- 1,
- $objHotelBookingDetail->date_from,
- $objHotelBookingDetail->date_to,
- false,
- $cart->id
- ) / $numDays;
- $unitPriceTaxIncl = $objRoomTypeServiceProductPrice->getServicePrice(
- (int)$product['id_product'],
- $roomHtlCartInfo['id_product'],
- 1,
- $objHotelBookingDetail->date_from,
- $objHotelBookingDetail->date_to,
- true,
- $cart->id
- ) / $numDays;
+ $unitPriceTaxExcl = $objRoomTypeServiceProductPrice->getServicePrice(
+ (int)$product['id_product'],
+ $roomHtlCartInfo['id_product'],
+ 1,
+ $objHotelBookingDetail->date_from,
+ $objHotelBookingDetail->date_to,
+ false,
+ $cart->id
+ ) / $numDays;
+ $unitPriceTaxIncl = $objRoomTypeServiceProductPrice->getServicePrice(
+ (int)$product['id_product'],
+ $roomHtlCartInfo['id_product'],
+ 1,
+ $objHotelBookingDetail->date_from,
+ $objHotelBookingDetail->date_to,
+ true,
+ $cart->id
+ ) / $numDays;
- $totalPriceChangeTaxExcl += $totalPriceTaxExcl = Tools::processPriceRounding(
- ($unitPriceTaxExcl * $numDays),
- $objRoomTypeServiceProductCartDetail->quantity,
- $objOrder->round_type,
- $objOrder->round_mode
- );
- $totalPriceChangeTaxIncl += $totalPriceTaxIncl = Tools::processPriceRounding(
- ($unitPriceTaxIncl * $numDays),
- $objRoomTypeServiceProductCartDetail->quantity,
- $objOrder->round_type,
- $objOrder->round_mode
- );
+ $totalPriceChangeTaxExcl += $totalPriceTaxExcl = Tools::processPriceRounding(
+ ($unitPriceTaxExcl * $numDays),
+ $objRoomTypeServiceProductCartDetail->quantity,
+ $objOrder->round_type,
+ $objOrder->round_mode
+ );
+ $totalPriceChangeTaxIncl += $totalPriceTaxIncl = Tools::processPriceRounding(
+ ($unitPriceTaxIncl * $numDays),
+ $objRoomTypeServiceProductCartDetail->quantity,
+ $objOrder->round_type,
+ $objOrder->round_mode
+ );
- $product['total'] = $totalPriceTaxExcl;
- $product['total_wt'] = $totalPriceTaxIncl;
+ $product['total'] = $totalPriceTaxExcl;
+ $product['total_wt'] = $totalPriceTaxIncl;
+ }
+ }
+
+ $order_detail = new OrderDetail();
+ $order_detail->createList($order, $cart, $order->getCurrentOrderState(), $productList, (isset($objOrderInvoice) ? $objOrderInvoice->id : 0), true);
+
+ $objRoomTypeServiceProductOrderDetail = new RoomTypeServiceProductOrderDetail();
+ $objRoomTypeServiceProductOrderDetail->id_product = $service['id'];
+ $objRoomTypeServiceProductOrderDetail->id_order = $objHotelBookingDetail->id_order;
+ $objRoomTypeServiceProductOrderDetail->id_order_detail = $order_detail->id;
+ $objRoomTypeServiceProductOrderDetail->id_cart = $cart->id;
+ $objRoomTypeServiceProductOrderDetail->id_htl_booking_detail = $objHotelBookingDetail->id;
+ $objRoomTypeServiceProductOrderDetail->unit_price_tax_excl = $unitPriceTaxExcl;
+ $objRoomTypeServiceProductOrderDetail->unit_price_tax_incl = $unitPriceTaxIncl;
+ $objRoomTypeServiceProductOrderDetail->total_price_tax_excl = $totalPriceTaxExcl;
+ $objRoomTypeServiceProductOrderDetail->total_price_tax_incl = $totalPriceTaxIncl;
+ $objRoomTypeServiceProductOrderDetail->name = $service['name'];
+ $objRoomTypeServiceProductOrderDetail->quantity = $objRoomTypeServiceProductCartDetail->quantity;
+ $objRoomTypeServiceProductOrderDetail->save();
+
+ // update totals amount of order
+ $order->total_products = Tools::ps_round((float)($order->total_products + $totalPriceChangeTaxExcl), _PS_PRICE_COMPUTE_PRECISION_);
+ $order->total_products_wt = Tools::ps_round((float)($order->total_products_wt + $totalPriceChangeTaxIncl), _PS_PRICE_COMPUTE_PRECISION_);
+
+ $order->total_paid = Tools::ps_round($order->getOrderTotal(), _PS_PRICE_COMPUTE_PRECISION_);
+ $order->total_paid_tax_incl = Tools::ps_round($order->getOrderTotal(), _PS_PRICE_COMPUTE_PRECISION_);
+ $order->total_paid_tax_excl = Tools::ps_round($order->getOrderTotal(false), _PS_PRICE_COMPUTE_PRECISION_);
+
+ // update invoice total
+ if (isset($objOrderInvoice) && Validate::isLoadedObject($objOrderInvoice)) {
+ $objOrderInvoice->total_paid_tax_excl += Tools::ps_round((float)$totalPriceChangeTaxExcl, _PS_PRICE_COMPUTE_PRECISION_);
+ $objOrderInvoice->total_paid_tax_incl += Tools::ps_round((float)$totalPriceChangeTaxIncl, _PS_PRICE_COMPUTE_PRECISION_);
+ $objOrderInvoice->save();
+ }
+
+ // discount
+ $order->total_discounts += (float)abs($cart->getOrderTotal(true, Cart::ONLY_DISCOUNTS));
+ $order->total_discounts_tax_excl += (float)abs($cart->getOrderTotal(false, Cart::ONLY_DISCOUNTS));
+ $order->total_discounts_tax_incl += (float)abs($cart->getOrderTotal(true, Cart::ONLY_DISCOUNTS));
+
+ // Save changes of order
+ $order->update();
+ if (Validate::isLoadedObject($specific_price)) {
+ $specific_price->delete();
+ unset($specific_price);
}
}
-
- $order_detail = new OrderDetail();
- $order_detail->createList($order, $cart, $order->getCurrentOrderState(), $productList, (isset($objOrderInvoice) ? $objOrderInvoice->id : 0), true);
-
- $objRoomTypeServiceProductOrderDetail = new RoomTypeServiceProductOrderDetail();
- $objRoomTypeServiceProductOrderDetail->id_product = $service['id'];
- $objRoomTypeServiceProductOrderDetail->id_order = $objHotelBookingDetail->id_order;
- $objRoomTypeServiceProductOrderDetail->id_order_detail = $order_detail->id;
- $objRoomTypeServiceProductOrderDetail->id_cart = $cart->id;
- $objRoomTypeServiceProductOrderDetail->id_htl_booking_detail = $objHotelBookingDetail->id;
- $objRoomTypeServiceProductOrderDetail->unit_price_tax_excl = $unitPriceTaxExcl;
- $objRoomTypeServiceProductOrderDetail->unit_price_tax_incl = $unitPriceTaxIncl;
- $objRoomTypeServiceProductOrderDetail->total_price_tax_excl = $totalPriceTaxExcl;
- $objRoomTypeServiceProductOrderDetail->total_price_tax_incl = $totalPriceTaxIncl;
- $objRoomTypeServiceProductOrderDetail->name = $service['name'];
- $objRoomTypeServiceProductOrderDetail->quantity = $objRoomTypeServiceProductCartDetail->quantity;
- $objRoomTypeServiceProductOrderDetail->save();
-
- // update totals amount of order
- $order->total_products = Tools::ps_round((float)($order->total_products + $totalPriceChangeTaxExcl), _PS_PRICE_COMPUTE_PRECISION_);
- $order->total_products_wt = Tools::ps_round((float)($order->total_products_wt + $totalPriceChangeTaxIncl), _PS_PRICE_COMPUTE_PRECISION_);
- $order->total_paid = Tools::ps_round((float)($order->total_paid + $totalPriceChangeTaxIncl), _PS_PRICE_COMPUTE_PRECISION_);
- $order->total_paid_tax_excl = Tools::ps_round((float)($order->total_paid_tax_excl + $totalPriceChangeTaxExcl), _PS_PRICE_COMPUTE_PRECISION_);
- $order->total_paid_tax_incl = Tools::ps_round((float)($order->total_paid_tax_incl + $totalPriceChangeTaxIncl), _PS_PRICE_COMPUTE_PRECISION_);
-
- // update invoice total
- if (isset($objOrderInvoice) && Validate::isLoadedObject($objOrderInvoice)) {
- $objOrderInvoice->total_paid_tax_excl += Tools::ps_round((float)$totalPriceChangeTaxExcl, _PS_PRICE_COMPUTE_PRECISION_);
- $objOrderInvoice->total_paid_tax_incl += Tools::ps_round((float)$totalPriceChangeTaxIncl, _PS_PRICE_COMPUTE_PRECISION_);
- $objOrderInvoice->save();
- }
-
- // discount
- $order->total_discounts += (float)abs($cart->getOrderTotal(true, Cart::ONLY_DISCOUNTS));
- $order->total_discounts_tax_excl += (float)abs($cart->getOrderTotal(false, Cart::ONLY_DISCOUNTS));
- $order->total_discounts_tax_incl += (float)abs($cart->getOrderTotal(true, Cart::ONLY_DISCOUNTS));
-
- // Save changes of order
- $order->update();
- if (Validate::isLoadedObject($specific_price)) {
- $specific_price->delete();
- unset($specific_price);
- }
}
+ $response['service_panel'] = $this->processRenderServicesPanel(
+ $order->id,
+ $objHotelBookingDetail->id_product,
+ $objHotelBookingDetail->date_from,
+ $objHotelBookingDetail->date_to,
+ $objHotelBookingDetail->id_room,
+ $objHotelBookingDetail->id,
+ true
+ );
+ } else {
+ $response['hasError'] = true;
+ $response['errors'][] = $this->l('Room not found');
}
- $response['service_panel'] = $this->processRenderServicesPanel(
- $order->id,
- $objHotelBookingDetail->id_product,
- $objHotelBookingDetail->date_from,
- $objHotelBookingDetail->date_to,
- $objHotelBookingDetail->id_room,
- $objHotelBookingDetail->id,
- true
- );
- } else {
- $response['hasError'] = true;
- $response['errors'][] = $this->l('Room not found');
}
+ } else {
+ $response['hasError'] = true;
+ $response['errors'][] = $this->l('You do not have permission to edit this order.');
}
die(json_encode($response));
@@ -6634,102 +6786,202 @@ class AdminOrdersControllerCore extends AdminController
public function ajaxProcessAddRoomExtraDemands()
{
$response = array('success' => false, 'hasError' => false);
- if ($idHtlBooking = Tools::getValue('id_htl_booking')) {
- if (Validate::isLoadedObject($objBookingDetail = new HotelBookingDetail($idHtlBooking))) {
- $roomDemands = Tools::getValue('room_demands');
- if ($roomDemands = json_decode($roomDemands, true)) {
- $order = new Order($objBookingDetail->id_order);
- // set context currency So that we can get prices in the order currency
- $this->context->currency = new Currency($order->id_currency);
+ if ($this->tabAccess['edit'] == 1) {
+ if ($idHtlBooking = Tools::getValue('id_htl_booking')) {
+ if (Validate::isLoadedObject($objBookingDetail = new HotelBookingDetail($idHtlBooking))) {
+ $roomDemands = Tools::getValue('room_demands');
+ if ($roomDemands = json_decode($roomDemands, true)) {
+ $order = new Order($objBookingDetail->id_order);
+ // set context currency So that we can get prices in the order currency
+ $this->context->currency = new Currency($order->id_currency);
- $vatAddress = new Address((int)$order->id_address_tax);
- $idLang = (int)$order->id_lang;
- $idProduct = $objBookingDetail->id_product;
- $objHtlBkDtl = new HotelBookingDetail();
- $objRoomDemandPrice = new HotelRoomTypeDemandPrice();
- foreach ($roomDemands as $demand) {
- if (!ValidateCore::isPrice($demand['unit_price'])) {
- $objGlobalDemand = new HotelRoomTypeGlobalDemand($demand['id_global_demand'], $idLang);
- $response['hasError'] = true;
- $response['errors'][] = sprintf($this->l('Invalid unit price for %s.'), $objGlobalDemand->name);
+ $vatAddress = new Address((int)$order->id_address_tax);
+ $idLang = (int)$order->id_lang;
+ $idProduct = $objBookingDetail->id_product;
+ $objHtlBkDtl = new HotelBookingDetail();
+ $objRoomDemandPrice = new HotelRoomTypeDemandPrice();
+ foreach ($roomDemands as $demand) {
+ if (!ValidateCore::isPrice($demand['unit_price'])) {
+ $objGlobalDemand = new HotelRoomTypeGlobalDemand($demand['id_global_demand'], $idLang);
+ $response['hasError'] = true;
+ $response['errors'][] = sprintf($this->l('Invalid unit price for %s.'), $objGlobalDemand->name);
+ }
+ }
+ if (!$response['hasError']) {
+ foreach ($roomDemands as $demand) {
+ $idGlobalDemand = $demand['id_global_demand'];
+ $idOption = $demand['id_option'];
+ $objBookingDemand = new HotelBookingDemands();
+ $objBookingDemand->id_htl_booking = $idHtlBooking;
+ $objGlobalDemand = new HotelRoomTypeGlobalDemand($idGlobalDemand, $idLang);
+ if ($idOption) {
+ $objOption = new HotelRoomTypeGlobalDemandAdvanceOption($idOption, $idLang);
+ $objBookingDemand->name = $objOption->name;
+ } else {
+ $idOption = 0;
+ $objBookingDemand->name = $objGlobalDemand->name;
+ }
+ $objBookingDemand->unit_price_tax_excl = $demand['unit_price'];
+ $objBookingDemand->unit_price_tax_incl = HotelRoomTypeDemand::getPriceStatic(
+ $idProduct,
+ $idGlobalDemand,
+ $idOption,
+ 1,
+ 6,
+ null,
+ null,
+ null,
+ null,
+ $demand['unit_price']
+ );
+ $numDays = 1;
+ if ($objGlobalDemand->price_calc_method == HotelRoomTypeGlobalDemand::WK_PRICE_CALC_METHOD_EACH_DAY) {
+ $numDays = $objHtlBkDtl->getNumberOfDays(
+ $objBookingDetail->date_from,
+ $objBookingDetail->date_to
+ );
+ }
+ $objBookingDemand->total_price_tax_excl = $totalPriceTaxIncl = Tools::processPriceRounding(
+ ($objBookingDemand->unit_price_tax_excl * $numDays),
+ 1,
+ $order->round_type,
+ $order->round_mode
+ );
+ $objBookingDemand->total_price_tax_incl = $totalPriceTaxIncl = Tools::processPriceRounding(
+ ($objBookingDemand->unit_price_tax_incl * $numDays),
+ 1,
+ $order->round_type,
+ $order->round_mode
+ );
+
+ $order_detail = new OrderDetail($objBookingDetail->id_order_detail);
+ // Update OrderInvoice of this OrderDetail
+ if ($order_detail->id_order_invoice != 0) {
+ // values changes as values are calculated accoding to the quantity of the product by webkul
+ $order_invoice = new OrderInvoice($order_detail->id_order_invoice);
+ $order_invoice->total_paid_tax_excl = Tools::ps_round((float)($order_invoice->total_paid_tax_excl + $objBookingDemand->total_price_tax_excl), _PS_PRICE_COMPUTE_PRECISION_);
+ $order_invoice->total_paid_tax_incl = Tools::ps_round((float)($order_invoice->total_paid_tax_incl + $objBookingDemand->total_price_tax_incl), _PS_PRICE_COMPUTE_PRECISION_);
+ $res &= $order_invoice->update();
+ }
+
+ $objBookingDemand->price_calc_method = $objGlobalDemand->price_calc_method;
+ $objBookingDemand->id_tax_rules_group = $objGlobalDemand->id_tax_rules_group;
+ $taxManager = TaxManagerFactory::getManager(
+ $vatAddress,
+ $objGlobalDemand->id_tax_rules_group
+ );
+ $taxCalc = $taxManager->getTaxCalculator();
+ $objBookingDemand->tax_computation_method = (int)$taxCalc->computation_method;
+ if ($objBookingDemand->save()) {
+ $objBookingDemand->tax_calculator = $taxCalc;
+ // Now save tax details of the extra demand
+ $objBookingDemand->setBookingDemandTaxDetails();
+ }
+ }
+
+ $order->total_paid = Tools::ps_round($order->getOrderTotal(), _PS_PRICE_COMPUTE_PRECISION_);
+ $order->total_paid_tax_incl = Tools::ps_round($order->getOrderTotal(), _PS_PRICE_COMPUTE_PRECISION_);
+ $order->total_paid_tax_excl = Tools::ps_round($order->getOrderTotal(false), _PS_PRICE_COMPUTE_PRECISION_);
+ if ($order->save()) {
+ $response['facilities_panel'] = $this->processRenderFacilitiesBlock(
+ $order->id,
+ $objBookingDetail->id_product,
+ $objBookingDetail->date_from,
+ $objBookingDetail->date_to,
+ $objBookingDetail->id_room,
+ $objBookingDetail->id,
+ true
+ );
+ $response['success'] = true;
+ }
}
}
- if (!$response['hasError']) {
- foreach ($roomDemands as $demand) {
- $idGlobalDemand = $demand['id_global_demand'];
- $idOption = $demand['id_option'];
- $objBookingDemand = new HotelBookingDemands();
- $objBookingDemand->id_htl_booking = $idHtlBooking;
- $objGlobalDemand = new HotelRoomTypeGlobalDemand($idGlobalDemand, $idLang);
- if ($idOption) {
- $objOption = new HotelRoomTypeGlobalDemandAdvanceOption($idOption, $idLang);
- $objBookingDemand->name = $objOption->name;
- } else {
- $idOption = 0;
- $objBookingDemand->name = $objGlobalDemand->name;
- }
- $objBookingDemand->unit_price_tax_excl = $demand['unit_price'];
- $objBookingDemand->unit_price_tax_incl = HotelRoomTypeDemand::getPriceStatic(
- $idProduct,
- $idGlobalDemand,
- $idOption,
- 1,
- 6,
- null,
- null,
- null,
- null,
- $demand['unit_price']
- );
- $numDays = 1;
- if ($objGlobalDemand->price_calc_method == HotelRoomTypeGlobalDemand::WK_PRICE_CALC_METHOD_EACH_DAY) {
- $numDays = $objHtlBkDtl->getNumberOfDays(
- $objBookingDetail->date_from,
- $objBookingDetail->date_to
- );
- }
- $objBookingDemand->total_price_tax_excl = $totalPriceTaxIncl = Tools::processPriceRounding(
- ($objBookingDemand->unit_price_tax_excl * $numDays),
- 1,
- $order->round_type,
- $order->round_mode
- );
- $objBookingDemand->total_price_tax_incl = $totalPriceTaxIncl = Tools::processPriceRounding(
- ($objBookingDemand->unit_price_tax_incl * $numDays),
- 1,
- $order->round_type,
- $order->round_mode
- );
+ }
+ }
+ } else {
+ $response['hasError'] = true;
+ $response['errors'][] = $this->l('You do not have permission to edit this order.');
+ }
+ die(json_encode($response));
+ }
- $order_detail = new OrderDetail($objBookingDetail->id_order_detail);
- // Update OrderInvoice of this OrderDetail
- if ($order_detail->id_order_invoice != 0) {
- // values changes as values are calculated accoding to the quantity of the product by webkul
- $order_invoice = new OrderInvoice($order_detail->id_order_invoice);
- $order_invoice->total_paid_tax_excl = Tools::ps_round((float)($order_invoice->total_paid_tax_excl + $objBookingDemand->total_price_tax_excl), _PS_PRICE_COMPUTE_PRECISION_);
- $order_invoice->total_paid_tax_incl = Tools::ps_round((float)($order_invoice->total_paid_tax_incl + $objBookingDemand->total_price_tax_incl), _PS_PRICE_COMPUTE_PRECISION_);
- $res &= $order_invoice->update();
- }
+ public function ajaxProcessUpdateRoomExtraDemands()
+ {
+ $response = array('success' => false);
+ if ($this->tabAccess['edit'] == 1) {
+ if ($idBookingDemand = Tools::getValue('id_booking_demand')) {
+ if (Validate::isLoadedObject($objBookingDemand = new HotelBookingDemands($idBookingDemand))) {
+ $unitPrice = Tools::getValue('unit_price');
+ if (!$unitPrice || !ValidateCore::isPrice($unitPrice)) {
+ $response['hasError'] = true;
+ $response['errors'] = $this->l('Invalid unit price');
+ }
+ $oldPriceTaxExcl = $objBookingDemand->unit_price_tax_excl;
+ $oldPriceTaxIncl = $objBookingDemand->unit_price_tax_incl;
+ if ($oldPriceTaxExcl > 0) {
+ $oldTaxMultiplier = $oldPriceTaxIncl / $oldPriceTaxExcl;
+ } else {
+ $oldTaxMultiplier = 1;
+ }
- // change order total
- $order->total_paid_tax_excl = Tools::ps_round((float)($order->total_paid_tax_excl + $objBookingDemand->total_price_tax_excl), _PS_PRICE_COMPUTE_PRECISION_);
- $order->total_paid_tax_incl = Tools::ps_round((float)($order->total_paid_tax_incl + $objBookingDemand->total_price_tax_incl), _PS_PRICE_COMPUTE_PRECISION_);
- $order->total_paid = Tools::ps_round((float)($order->total_paid + $objBookingDemand->total_price_tax_incl), _PS_PRICE_COMPUTE_PRECISION_);
+ $objBookingDemand->unit_price_tax_excl = $unitPrice;
+ $objBookingDemand->unit_price_tax_incl = $unitPrice * $oldTaxMultiplier;
- $objBookingDemand->price_calc_method = $objGlobalDemand->price_calc_method;
- $objBookingDemand->id_tax_rules_group = $objGlobalDemand->id_tax_rules_group;
- $taxManager = TaxManagerFactory::getManager(
- $vatAddress,
- $objGlobalDemand->id_tax_rules_group
- );
- $taxCalc = $taxManager->getTaxCalculator();
- $objBookingDemand->tax_computation_method = (int)$taxCalc->computation_method;
- if ($objBookingDemand->save()) {
- $objBookingDemand->tax_calculator = $taxCalc;
- // Now save tax details of the extra demand
- $objBookingDemand->setBookingDemandTaxDetails();
- }
+ $objBookingDetail = new HotelBookingDetail($objBookingDemand->id_htl_booking);
+ $order = new Order($objBookingDetail->id_order);
+ if ($objBookingDemand->price_calc_method == HotelRoomTypeGlobalDemand::WK_PRICE_CALC_METHOD_EACH_DAY) {
+ $numDays = $objBookingDetail->getNumberOfDays(
+ $objBookingDetail->date_from,
+ $objBookingDetail->date_to
+ );
+
+ $objBookingDemand->total_price_tax_excl = Tools::processPriceRounding(
+ ($objBookingDemand->unit_price_tax_excl * $numDays),
+ 1,
+ $order->round_type,
+ $order->round_mode
+ );
+ $objBookingDemand->total_price_tax_excl = Tools::processPriceRounding(
+ ($objBookingDemand->unit_price_tax_incl * $numDays),
+ 1,
+ $order->round_type,
+ $order->round_mode
+ );
+ } else {
+ $objBookingDemand->total_price_tax_excl = Tools::processPriceRounding(
+ $objBookingDemand->unit_price_tax_excl,
+ 1,
+ $order->round_type,
+ $order->round_mode
+ );
+ $objBookingDemand->total_price_tax_incl = Tools::processPriceRounding(
+ $objBookingDemand->unit_price_tax_incl,
+ 1,
+ $order->round_type,
+ $order->round_mode
+ );
+ }
+ if ($objBookingDemand->save()) {
+ $objBookingDemand->setBookingDemandTaxDetails(1);
+
+ $priceDiffTaxExcl = $objBookingDemand->total_price_tax_excl - $oldPriceTaxExcl;
+ $priceDiffTaxIncl = $objBookingDemand->total_price_tax_incl - $oldPriceTaxIncl;
+
+
+ $order_detail = new OrderDetail($objBookingDetail->id_order_detail);
+ // Update OrderInvoice of this OrderDetail
+ if ($order_detail->id_order_invoice != 0) {
+ // values changes as values are calculated accoding to the quantity of the product by webkul
+ $order_invoice = new OrderInvoice($order_detail->id_order_invoice);
+
+ $order_invoice->total_paid_tax_excl = Tools::ps_round((float)($order_invoice->total_paid_tax_excl + $priceDiffTaxExcl), _PS_PRICE_COMPUTE_PRECISION_);
+ $order_invoice->total_paid_tax_incl = Tools::ps_round((float)($order_invoice->total_paid_tax_incl + $priceDiffTaxIncl), _PS_PRICE_COMPUTE_PRECISION_);
+ $order_invoice->update();
}
+
+ $order->total_paid_tax_excl = Tools::ps_round((float)($order->total_paid_tax_excl + $priceDiffTaxExcl), _PS_PRICE_COMPUTE_PRECISION_);
+ $order->total_paid_tax_incl = Tools::ps_round((float)($order->total_paid_tax_incl + $priceDiffTaxIncl), _PS_PRICE_COMPUTE_PRECISION_);
+ $order->total_paid = Tools::ps_round((float)($order->total_paid + $priceDiffTaxIncl), _PS_PRICE_COMPUTE_PRECISION_);
if ($order->save()) {
$response['facilities_panel'] = $this->processRenderFacilitiesBlock(
$order->id,
@@ -6749,146 +7001,56 @@ class AdminOrdersControllerCore extends AdminController
die(json_encode($response));
}
- public function ajaxProcessUpdateRoomExtraDemands()
- {
- $response = array('success' => false);
- if ($idBookingDemand = Tools::getValue('id_booking_demand')) {
- if (Validate::isLoadedObject($objBookingDemand = new HotelBookingDemands($idBookingDemand))) {
- $unitPrice = Tools::getValue('unit_price');
- if (!$unitPrice || !ValidateCore::isPrice($unitPrice)) {
- $response['hasError'] = true;
- $response['errors'] = $this->l('Invalid unit price');
- }
- $oldPriceTaxExcl = $objBookingDemand->unit_price_tax_excl;
- $oldPriceTaxIncl = $objBookingDemand->unit_price_tax_incl;
- if ($oldPriceTaxExcl > 0) {
- $oldTaxMultiplier = $oldPriceTaxIncl / $oldPriceTaxExcl;
- } else {
- $oldTaxMultiplier = 1;
- }
-
- $objBookingDemand->unit_price_tax_excl = $unitPrice;
- $objBookingDemand->unit_price_tax_incl = $unitPrice * $oldTaxMultiplier;
-
- $objBookingDetail = new HotelBookingDetail($objBookingDemand->id_htl_booking);
- $order = new Order($objBookingDetail->id_order);
- if ($objBookingDemand->price_calc_method == HotelRoomTypeGlobalDemand::WK_PRICE_CALC_METHOD_EACH_DAY) {
- $numDays = $objBookingDetail->getNumberOfDays(
- $objBookingDetail->date_from,
- $objBookingDetail->date_to
- );
-
- $objBookingDemand->total_price_tax_excl = Tools::processPriceRounding(
- ($objBookingDemand->unit_price_tax_excl * $numDays),
- 1,
- $order->round_type,
- $order->round_mode
- );
- $objBookingDemand->total_price_tax_excl = Tools::processPriceRounding(
- ($objBookingDemand->unit_price_tax_incl * $numDays),
- 1,
- $order->round_type,
- $order->round_mode
- );
- } else {
- $objBookingDemand->total_price_tax_excl = Tools::processPriceRounding(
- $objBookingDemand->unit_price_tax_excl,
- 1,
- $order->round_type,
- $order->round_mode
- );
- $objBookingDemand->total_price_tax_excl = Tools::processPriceRounding(
- $objBookingDemand->unit_price_tax_incl,
- 1,
- $order->round_type,
- $order->round_mode
- );
- }
- if ($objBookingDemand->save()) {
- $objBookingDemand->setBookingDemandTaxDetails(1);
-
- $priceDiffTaxExcl = $objBookingDemand->total_price_tax_excl - $oldPriceTaxExcl;
- $priceDiffTaxIncl = $objBookingDemand->total_price_tax_incl - $oldPriceTaxIncl;
-
-
- $order_detail = new OrderDetail($objBookingDetail->id_order_detail);
- // Update OrderInvoice of this OrderDetail
- if ($order_detail->id_order_invoice != 0) {
- // values changes as values are calculated accoding to the quantity of the product by webkul
- $order_invoice = new OrderInvoice($order_detail->id_order_invoice);
-
- $order_invoice->total_paid_tax_excl = Tools::ps_round((float)($order_invoice->total_paid_tax_excl + $priceDiffTaxExcl), _PS_PRICE_COMPUTE_PRECISION_);
- $order_invoice->total_paid_tax_incl = Tools::ps_round((float)($order_invoice->total_paid_tax_incl + $priceDiffTaxIncl), _PS_PRICE_COMPUTE_PRECISION_);
- $order_invoice->update();
- }
-
- $order->total_paid_tax_excl = Tools::ps_round((float)($order->total_paid_tax_excl + $priceDiffTaxExcl), _PS_PRICE_COMPUTE_PRECISION_);
- $order->total_paid_tax_incl = Tools::ps_round((float)($order->total_paid_tax_incl + $priceDiffTaxIncl), _PS_PRICE_COMPUTE_PRECISION_);
- $order->total_paid = Tools::ps_round((float)($order->total_paid + $priceDiffTaxIncl), _PS_PRICE_COMPUTE_PRECISION_);
- if ($order->save()) {
- $response['facilities_panel'] = $this->processRenderFacilitiesBlock(
- $order->id,
- $objBookingDetail->id_product,
- $objBookingDetail->date_from,
- $objBookingDetail->date_to,
- $objBookingDetail->id_room,
- $objBookingDetail->id,
- true
- );
- $response['success'] = true;
- }
- }
- }
- }
- die(json_encode($response));
- }
-
// delete room extra demand while order edit
public function ajaxProcessDeleteRoomExtraDemand()
{
$response = array('success' => false);
- $res = true;
- if ($idBookingDemand = Tools::getValue('id_booking_demand')) {
- if (Validate::isLoadedObject($objBookingDemand = new HotelBookingDemands($idBookingDemand))) {
- // first delete the tax details of the booking demand
- if ($objBookingDemand->deleteBookingDemandTaxDetails($idBookingDemand)) {
- if ($objBookingDemand->delete()) {
- if (Validate::isLoadedObject($objBookingDetail = new HotelBookingDetail($objBookingDemand->id_htl_booking))) {
- // change order total
- $order = new Order($objBookingDetail->id_order);
+ // Check tab access is allowed to edit
+ if ($this->tabAccess['edit'] == 1) {
+ $res = true;
+ if ($idBookingDemand = Tools::getValue('id_booking_demand')) {
+ if (Validate::isLoadedObject($objBookingDemand = new HotelBookingDemands($idBookingDemand))) {
+ // first delete the tax details of the booking demand
+ if ($objBookingDemand->deleteBookingDemandTaxDetails($idBookingDemand)) {
+ if ($objBookingDemand->delete()) {
+ if (Validate::isLoadedObject($objBookingDetail = new HotelBookingDetail($objBookingDemand->id_htl_booking))) {
+ // change order total
+ $order = new Order($objBookingDetail->id_order);
- $order->total_paid_tax_excl = Tools::ps_round((float)($order->total_paid_tax_excl - $objBookingDemand->total_price_tax_excl), _PS_PRICE_COMPUTE_PRECISION_);
- $order->total_paid_tax_incl = Tools::ps_round((float)($order->total_paid_tax_incl - $objBookingDemand->total_price_tax_incl), _PS_PRICE_COMPUTE_PRECISION_);
- $order->total_paid = Tools::ps_round((float)($order->total_paid - $objBookingDemand->total_price_tax_incl), _PS_PRICE_COMPUTE_PRECISION_);
+ $order->total_paid = Tools::ps_round($order->getOrderTotal(), _PS_PRICE_COMPUTE_PRECISION_);
+ $order->total_paid_tax_incl = Tools::ps_round($order->getOrderTotal(), _PS_PRICE_COMPUTE_PRECISION_);
+ $order->total_paid_tax_excl = Tools::ps_round($order->getOrderTotal(false), _PS_PRICE_COMPUTE_PRECISION_);
- $order->save();
+ $order->save();
- $order_detail = new OrderDetail($objBookingDetail->id_order_detail);
- // Update OrderInvoice of this OrderDetail
- if ($order_detail->id_order_invoice != 0) {
- // values changes as values are calculated accoding to the quantity of the product by webkul
- $order_invoice = new OrderInvoice($order_detail->id_order_invoice);
- $order_invoice->total_paid_tax_excl = Tools::ps_round((float)($order_invoice->total_paid_tax_excl - $objBookingDemand->total_price_tax_excl), _PS_PRICE_COMPUTE_PRECISION_);
- $order_invoice->total_paid_tax_incl = Tools::ps_round((float)($order_invoice->total_paid_tax_incl - $objBookingDemand->total_price_tax_incl), _PS_PRICE_COMPUTE_PRECISION_);
- $res &= $order_invoice->update();
- }
- if ($res) {
- $response['facilities_panel'] = $this->processRenderFacilitiesBlock(
- $order->id,
- $objBookingDetail->id_product,
- $objBookingDetail->date_from,
- $objBookingDetail->date_to,
- $objBookingDetail->id_room,
- $objBookingDetail->id,
- true
- );
- $response['success'] = true;
+ $order_detail = new OrderDetail($objBookingDetail->id_order_detail);
+ // Update OrderInvoice of this OrderDetail
+ if ($order_detail->id_order_invoice != 0) {
+ // values changes as values are calculated accoding to the quantity of the product by webkul
+ $order_invoice = new OrderInvoice($order_detail->id_order_invoice);
+ $order_invoice->total_paid_tax_excl = Tools::ps_round((float)($order_invoice->total_paid_tax_excl - $objBookingDemand->total_price_tax_excl), _PS_PRICE_COMPUTE_PRECISION_);
+ $order_invoice->total_paid_tax_incl = Tools::ps_round((float)($order_invoice->total_paid_tax_incl - $objBookingDemand->total_price_tax_incl), _PS_PRICE_COMPUTE_PRECISION_);
+ $res &= $order_invoice->update();
+ }
+ if ($res) {
+ $response['facilities_panel'] = $this->processRenderFacilitiesBlock(
+ $order->id,
+ $objBookingDetail->id_product,
+ $objBookingDetail->date_from,
+ $objBookingDetail->date_to,
+ $objBookingDetail->id_room,
+ $objBookingDetail->id,
+ true
+ );
+ $response['success'] = true;
+ }
}
}
}
}
}
}
+
die(json_encode($response));
}
@@ -7065,4 +7227,4 @@ class AdminOrdersControllerCore extends AdminController
$this->ajaxDie(json_encode($result));
}
-}
\ No newline at end of file
+}
diff --git a/js/admin/orders.js b/js/admin/orders.js
index 948ef9513..ac24e8167 100644
--- a/js/admin/orders.js
+++ b/js/admin/orders.js
@@ -2017,30 +2017,33 @@ const BookingDocumentsModal = {
});
},
deleteDocument: function($this) {
- BookingDocumentsModal.hideErrors();
- let idHtlBookingDocument = parseInt($($this).attr('data-id-htl-booking-document'));
- let data = {
- ajax: true,
- action: 'deleteBookingDocument',
- id_htl_booking_document: idHtlBookingDocument,
- };
+ BookingDocumentsModal.beforeSubmit(function() {
+ let idHtlBookingDocument = parseInt($($this).attr('data-id-htl-booking-document'));
+ let data = {
+ ajax: true,
+ action: 'deleteBookingDocument',
+ id_htl_booking_document: idHtlBookingDocument,
+ };
- $(".loading_overlay").show();
- $.ajax({
- url: admin_order_tab_link,
- data: data,
- type: 'POST',
- dataType: 'JSON',
- success: function(response) {
- if (response.status) {
- BookingDocumentsModal.setBodyHtml(response.html);
- BookingDocumentsModal.setDocumentsCount(response.num_checkin_documents);
- showSuccessMessage(txt_booking_document_delete_success);
+ $(".loading_overlay").show();
+ $.ajax({
+ url: admin_order_tab_link,
+ data: data,
+ type: 'POST',
+ dataType: 'JSON',
+ success: function(response) {
+ if (response.status) {
+ BookingDocumentsModal.setBodyHtml(response.html);
+ BookingDocumentsModal.setDocumentsCount(response.num_checkin_documents);
+ showSuccessMessage(txt_booking_document_delete_success);
+ } else {
+ BookingDocumentsModal.showErrors(response.errors);
+ }
+ },
+ complete: function() {
+ $(".loading_overlay").hide();
}
- },
- complete: function() {
- $(".loading_overlay").hide();
- }
+ });
});
},
showErrors: function(errors) {
diff --git a/modules/hotelreservationsystem/classes/HotelBookingDemands.php b/modules/hotelreservationsystem/classes/HotelBookingDemands.php
index a8d50ea81..f4f51bbef 100644
--- a/modules/hotelreservationsystem/classes/HotelBookingDemands.php
+++ b/modules/hotelreservationsystem/classes/HotelBookingDemands.php
@@ -268,7 +268,7 @@ class HotelBookingDemands extends ObjectModel
$numDays = $objBkDetail->getNumberOfDays($objBkDetail->date_from, $objBkDetail->date_to);
}
- $totalTaxBase = $unitAmount * $numDays;
+ $totalTaxBase = $priceTaxExcl * $numDays;
$detail['total_tax_base'] = $totalTaxBase;
}