From 2058dd270178af0319bfbfd60e78a7bada407307 Mon Sep 17 00:00:00 2001 From: Sumit Panwar Date: Wed, 25 Sep 2024 19:06:21 +0530 Subject: [PATCH 01/13] Showing incorrect final booking amount after changing the order status to Payment Accepted and then increase the date range of booking. --- controllers/admin/AdminOrdersController.php | 58 ++++++++++----------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index 9a4a3da7d..0eaee3512 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -4930,7 +4930,7 @@ 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) { @@ -4938,27 +4938,27 @@ class AdminOrdersControllerCore extends AdminController $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; + $order->total_paid_tax_excl -= $objBookingDemand->total_price_tax_excl; + $order->total_paid_tax_incl -= $objBookingDemand->total_price_tax_incl; + $order->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; + $order->total_paid_tax_excl += $demandPriceTE; + $order->total_paid_tax_incl += $demandPriceTI; + $order->total_paid += $demandPriceTI; $objBookingDemand->total_price_tax_excl = $demandPriceTE; $objBookingDemand->total_price_tax_incl = $demandPriceTI; @@ -4969,14 +4969,14 @@ class AdminOrdersControllerCore extends AdminController } } // change order total save - $objOrder->save(); + $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']) @@ -4992,28 +4992,28 @@ 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; + $order->total_paid_tax_excl -= $objRoomTypeServiceProductOrderDetail->total_price_tax_excl; + $order->total_paid_tax_incl -= $objRoomTypeServiceProductOrderDetail->total_price_tax_incl; + $order->total_paid -= $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; + $order->total_paid_tax_excl += $newTotalPriceTaxExcl; + $order->total_paid_tax_incl += $newTotalPriceTaxIncl; + $order->total_paid += $newTotalPriceTaxIncl; $objOrderDetail = new OrderDetail((int) $serviceProduct['id_order_detail']); $objOrderDetail->total_price_tax_excl -= $objRoomTypeServiceProductOrderDetail->total_price_tax_excl; @@ -5038,7 +5038,7 @@ class AdminOrdersControllerCore extends AdminController } } - $objOrder->save(); + $order->save(); } } @@ -7064,4 +7064,4 @@ class AdminOrdersControllerCore extends AdminController $this->ajaxDie(json_encode($result)); } -} \ No newline at end of file +} From 41c88e9e3abc8ce944a4064c68c7c2af8b6047d2 Mon Sep 17 00:00:00 2001 From: Sumit Panwar Date: Wed, 25 Sep 2024 20:03:44 +0530 Subject: [PATCH 02/13] Fixed: Not receiving a success deletion message after removing a non-auto-added service product from the order detail page --- controllers/admin/AdminOrdersController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index 0eaee3512..15c8d1eea 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -6504,7 +6504,7 @@ class AdminOrdersControllerCore extends AdminController $totalPriceChangeTaxIncl = 0; $unitPriceTaxIncl = 0; $unitPriceTaxExcl = 0; - foreach ($productList as $product) { + 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'], From bebebe5fbc870ef8509c8099965c69193e942179 Mon Sep 17 00:00:00 2001 From: Sumit Panwar Date: Fri, 27 Sep 2024 18:42:54 +0530 Subject: [PATCH 03/13] Fixed: Undefined variable notices on the admin orders controller while using the bulk update option. --- classes/pdf/HTMLTemplateInvoice.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/classes/pdf/HTMLTemplateInvoice.php b/classes/pdf/HTMLTemplateInvoice.php index 75d696ffd..0e41b4b0d 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) { From 687e9a433c634197079052107ee7551aa3b48d83 Mon Sep 17 00:00:00 2001 From: Sumit Panwar Date: Mon, 30 Sep 2024 11:27:10 +0530 Subject: [PATCH 04/13] Fixed: Order row not showing in the order list if admin removes all rooms from an order in back-office --- controllers/admin/AdminOrdersController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index 15c8d1eea..c88491135 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')) { From 93ebf5313aaef93e7380bcd90d4e6f874af04039 Mon Sep 17 00:00:00 2001 From: Sumit Panwar Date: Tue, 1 Oct 2024 20:27:44 +0530 Subject: [PATCH 05/13] Fixed: Edit permission issues in Order detail page in back-office --- .../orders/_booking_document_line.tpl | 8 +- .../controllers/orders/_documents.tpl | 4 +- .../controllers/orders/helpers/view/view.tpl | 162 +- .../orders/modals/_booking_documents.tpl | 80 +- controllers/admin/AdminOrdersController.php | 1474 +++++++++-------- js/admin/orders.js | 47 +- 6 files changed, 958 insertions(+), 817 deletions(-) diff --git a/admin/themes/default/template/controllers/orders/_booking_document_line.tpl b/admin/themes/default/template/controllers/orders/_booking_document_line.tpl index 9411ae1b8..77badd8ff 100644 --- a/admin/themes/default/template/controllers/orders/_booking_document_line.tpl +++ b/admin/themes/default/template/controllers/orders/_booking_document_line.tpl @@ -35,9 +35,11 @@ - - - + {if $can_edit} + + + + {/if} {/foreach} diff --git a/admin/themes/default/template/controllers/orders/_documents.tpl b/admin/themes/default/template/controllers/orders/_documents.tpl index a47bc8a5a..25ad36aef 100644 --- a/admin/themes/default/template/controllers/orders/_documents.tpl +++ b/admin/themes/default/template/controllers/orders/_documents.tpl @@ -95,7 +95,7 @@  {l s='Edit note'} {/if} - {if $document->getRestPaid()} + {if $can_edit && $document->getRestPaid()}  {l s='Enter payment'} @@ -117,7 +117,7 @@ - {if !$orderDocuments|count && isset($invoice_management_active) && $invoice_management_active} + {if $can_edit && !$orderDocuments|count && isset($invoice_management_active) && $invoice_management_active}
{l s='Generate invoice'} diff --git a/admin/themes/default/template/controllers/orders/helpers/view/view.tpl b/admin/themes/default/template/controllers/orders/helpers/view/view.tpl index 7a0554fbc..481c41a80 100644 --- a/admin/themes/default/template/controllers/orders/helpers/view/view.tpl +++ b/admin/themes/default/template/controllers/orders/helpers/view/view.tpl @@ -145,7 +145,7 @@ {if isset($refundReqBookings) && $refundReqBookings && $data.id|in_array:$refundReqBookings && $data.is_refunded} {if $data.is_cancelled}{l s='Cancelled'}{else}{l s='Refunded'}{/if} - {else} + {elseif $can_edit} {l s='Edit'} @@ -219,14 +219,17 @@ {$row['ostate_name']|stripslashes} {if $row['employee_lastname']}{$row['employee_firstname']|stripslashes} {$row['employee_lastname']|stripslashes}{/if} {dateFormat date=$row['date_add'] full=true} - - {if $row['send_email']|intval} - - - {l s='Resend email'} - - {/if} - + + {if $can_edit} + + {if $row['send_email']|intval} + + + {l s='Resend email'} + + {/if} + + {/if} {else} @@ -234,14 +237,16 @@ {$row['ostate_name']|stripslashes} {if $row['employee_lastname']}{$row['employee_firstname']|stripslashes} {$row['employee_lastname']|stripslashes}{else} {/if} {dateFormat date=$row['date_add'] full=true} - - {if $row['send_email']|intval} - - - {l s='Resend email'} - - {/if} - + {if $can_edit} + + {if $row['send_email']|intval} + + + {l s='Resend email'} + + {/if} + + {/if} {/if} {/foreach} @@ -250,7 +255,7 @@
{* If current state is refunded or cancelled the further order status changes are not allowed *} - {if !isset($currentState) || (isset($currentState) && ($currentState->id != Configuration::get('PS_OS_REFUND') && $currentState->id != Configuration::get('PS_OS_CANCELED')))} + {if $can_edit && (!isset($currentState) || (isset($currentState) && ($currentState->id != Configuration::get('PS_OS_REFUND') && $currentState->id != Configuration::get('PS_OS_CANCELED'))))}
@@ -474,12 +479,14 @@
-
- -
- {if (!$order->valid && sizeof($currencies) > 1)} + {if $can_edit} +
+ +
+ {/if} + {if $can_edit && (!$order->valid && sizeof($currencies) > 1)}
@@ -560,8 +567,11 @@ - -

{l s='This feature will generate a random password and send an email to the customer.'}

+ + {if $can_edit} + +

{l s='This feature will generate a random password and send an email to the customer.'}

+ {/if} {else}
@@ -603,13 +613,15 @@
-
-
- + {if $can_edit} +
+
+ +
-
+ {/if}
@@ -811,7 +823,7 @@
 {l s='Rooms Booking Detail'} {$order_detail_data|@count} - {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'))} @@ -1138,49 +1150,53 @@ {l s='Show all messages'}
-
-
+ {if $can_edit} + +
+
+ +

+ +

+ +
+ +
+ + +
+
- -

- -

-
- - {l s='Configure predefined messages'} - - +

+ +

+
+ + + +
+
- -
- - -
- -
-

- -

-
- - - -
- -
-
- + + {else} +
{l s='You do not have permission to edit this order.'}
+ {/if}
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 @@ -
-
-
- -
-
- - -
-
-
-
- -
-
- - - - + {if $can_edit} +
+
+ + +
+
+ +
-

- {l s='Upload a PDF or an image file. Allowed image formats: .gif, .jpg, .jpeg and .png'} -

-
- - -
+
+
+ +
+
+ + + + +
+

+ {l s='Upload a PDF or an image file. Allowed image formats: .gif, .jpg, .jpeg and .png'} +

+
+
+ + +
+ {/if}
diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index 67b911f43..7e42061ab 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -342,6 +342,8 @@ class AdminOrdersControllerCore extends AdminController parent::__construct(); + $this->tabAccess['edit'] = 1; + // overbooking success status $this->_conf[51] = $this->l('Overbooking is successfully resolved'); $this->_conf[52] = $this->l('Room in the booking is successfully reallocated'); @@ -501,18 +503,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 +532,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 +575,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 +1040,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 +1093,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 +1201,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 +1243,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 +1323,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 +1337,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 +1440,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 +1543,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 +1610,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 +1625,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 +1785,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 +2033,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)) { @@ -2072,7 +2083,7 @@ class AdminOrdersControllerCore extends AdminController $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') { @@ -2246,7 +2257,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 +2278,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(); @@ -3188,33 +3199,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)) { @@ -3248,16 +3263,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)); @@ -3269,40 +3291,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']) { @@ -3320,6 +3348,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', @@ -3546,6 +3575,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)) { @@ -3888,7 +3925,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(), @@ -3899,6 +3936,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); @@ -4580,7 +4625,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(), @@ -4589,7 +4634,6 @@ class AdminOrdersControllerCore extends AdminController ))); } - /** * This function is called when order is changed (Add/Edit/Delete room on order) */ @@ -4653,6 +4697,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'); @@ -5052,7 +5104,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, @@ -5064,6 +5116,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; @@ -5235,7 +5295,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, @@ -5247,6 +5307,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'); @@ -5491,6 +5559,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')); @@ -5589,6 +5665,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); @@ -6184,182 +6273,112 @@ 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_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_); + + $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, @@ -6369,10 +6388,92 @@ 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_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, + $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)); @@ -6380,233 +6481,239 @@ 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((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); } } - - $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)); @@ -6633,102 +6740,203 @@ 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(); + } + + // 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->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(); + } + } + 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_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, @@ -6748,146 +6956,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_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->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)); } 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) { From afbbb346dfb88fd85644e36e47f684eb3cf9a46e Mon Sep 17 00:00:00 2001 From: Sumit Panwar Date: Wed, 2 Oct 2024 10:49:37 +0530 Subject: [PATCH 06/13] Removed: unwanted code added --- controllers/admin/AdminOrdersController.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index 7e42061ab..30ab82d1a 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -342,8 +342,6 @@ class AdminOrdersControllerCore extends AdminController parent::__construct(); - $this->tabAccess['edit'] = 1; - // overbooking success status $this->_conf[51] = $this->l('Overbooking is successfully resolved'); $this->_conf[52] = $this->l('Room in the booking is successfully reallocated'); From a882ca6ef35ce0b998901348301efd479b16275e Mon Sep 17 00:00:00 2001 From: Sumit Panwar Date: Wed, 2 Oct 2024 14:49:06 +0530 Subject: [PATCH 07/13] Fixed: Error if negative value of prices in order table --- controllers/admin/AdminOrdersController.php | 56 +++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index 30ab82d1a..d3cdf98f0 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -2238,9 +2238,15 @@ 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 = $order->total_paid > 0 ? $order->total_paid : 0; + $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_incl = $order->total_paid_tax_incl > 0 ? $order->total_paid_tax_incl : 0; + $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_tax_excl = $order->total_paid_tax_excl > 0 ? $order->total_paid_tax_excl : 0; } // Update Order @@ -3912,9 +3918,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 @@ -4470,9 +4482,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 @@ -4822,10 +4840,15 @@ 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_products_wt = $order->total_products_wt > 0 ? $order->total_products_wt : 0; $order->total_paid += (float)$diff_price_tax_incl; + $order->total_paid = $order->total_paid > 0 ? $order->total_paid : 0; $order->total_paid_tax_excl += (float)$diff_price_tax_excl; + $order->total_paid_tax_excl = $order->total_paid_tax_excl > 0 ? $order->total_paid_tax_excl : 0; $order->total_paid_tax_incl += (float)$diff_price_tax_incl; + $order->total_paid_tax_incl = $order->total_paid_tax_incl > 0 ? $order->total_paid_tax_incl : 0; $res &= $order->update(); } @@ -5019,6 +5042,7 @@ class AdminOrdersControllerCore extends AdminController } } // change order total save + ppp($order); $order->save(); } @@ -5192,10 +5216,15 @@ 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_products_wt = $order->total_products_wt > 0 ? $order->total_products_wt : 0; $order->total_paid += $diff_price_tax_incl; + $order->total_paid = $order->total_paid > 0 ? $order->total_paid : 0; $order->total_paid_tax_excl += $diff_price_tax_excl; + $order->total_paid_tax_excl = $order->total_paid_tax_excl > 0 ? $order->total_paid_tax_excl : 0; $order->total_paid_tax_incl += $diff_price_tax_incl; + $order->total_paid_tax_incl = $order->total_paid_tax_incl > 0 ? $order->total_paid_tax_incl : 0; $res &= $order->update(); } @@ -5584,10 +5613,19 @@ 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 = $order->total_paid > 0 ? $order->total_paid : 0; + $order->total_paid_tax_incl -= Tools::ps_round($order_detail->total_price_tax_incl, _PS_PRICE_COMPUTE_PRECISION_); + $order->total_paid_tax_incl = $order->total_paid_tax_incl > 0 ? $order->total_paid_tax_incl : 0; + $order->total_paid_tax_excl -= Tools::ps_round($order_detail->total_price_tax_excl, _PS_PRICE_COMPUTE_PRECISION_); + $order->total_paid_tax_excl = $order->total_paid_tax_excl > 0 ? $order->total_paid_tax_excl : 0; + $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(); @@ -6364,10 +6402,19 @@ class AdminOrdersControllerCore extends AdminController } $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_tax_excl = Tools::ps_round((float)($order->total_paid_tax_excl + $priceDiffTaxExcl), _PS_PRICE_COMPUTE_PRECISION_); + $order->total_paid_tax_excl = $order->total_paid_tax_excl > 0 ? $order->total_paid_tax_excl : 0; + $order->total_paid_tax_incl = Tools::ps_round((float)($order->total_paid_tax_incl + $priceDiffTaxIncl), _PS_PRICE_COMPUTE_PRECISION_); + $order->total_paid_tax_incl = $order->total_paid_tax_incl > 0 ? $order->total_paid_tax_incl : 0; + $order->total_paid = Tools::ps_round((float)($order->total_paid + $priceDiffTaxIncl), _PS_PRICE_COMPUTE_PRECISION_); + $order->total_paid = $order->total_paid > 0 ? $order->total_paid : 0; $res &= $order->update(); } @@ -6447,10 +6494,19 @@ class AdminOrdersControllerCore extends AdminController } $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_tax_excl = Tools::ps_round((float)($order->total_paid_tax_excl - $priceTaxExcl), _PS_PRICE_COMPUTE_PRECISION_); + $order->total_paid_tax_excl = $order->total_paid_tax_excl > 0 ? $order->total_paid_tax_excl : 0; + $order->total_paid_tax_incl = Tools::ps_round((float)($order->total_paid_tax_incl - $priceTaxIncl), _PS_PRICE_COMPUTE_PRECISION_); + $order->total_paid_tax_incl = $order->total_paid_tax_incl > 0 ? $order->total_paid_tax_incl : 0; + $order->total_paid = Tools::ps_round((float)($order->total_paid - $priceTaxIncl), _PS_PRICE_COMPUTE_PRECISION_); + $order->total_paid = $order->total_paid > 0 ? $order->total_paid : 0; $res &= $order->update(); } From e43627d9ca5254e29edf04a8bb7d3ecec185163f Mon Sep 17 00:00:00 2001 From: Sumit Panwar Date: Wed, 2 Oct 2024 14:51:42 +0530 Subject: [PATCH 08/13] Fixed: notices where no string is passed in the Tools::DisplayError() in the PaymentOrder.php --- classes/PaymentModule.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/classes/PaymentModule.php b/classes/PaymentModule.php index 9c2cfb082..b854b8281 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 From e73f66b45bfcc35305b6c73f62e21d1fb40d4d1e Mon Sep 17 00:00:00 2001 From: Sumit Panwar Date: Wed, 2 Oct 2024 18:53:03 +0530 Subject: [PATCH 09/13] Fixed:Issue on admin orders after admin removes rooms from order having cart rules --- .../controllers/orders/helpers/view/view.tpl | 81 ++++++++++--------- classes/order/Order.php | 6 ++ controllers/admin/AdminOrdersController.php | 72 ++++++++++++----- 3 files changed, 101 insertions(+), 58 deletions(-) diff --git a/admin/themes/default/template/controllers/orders/helpers/view/view.tpl b/admin/themes/default/template/controllers/orders/helpers/view/view.tpl index 481c41a80..9c374affe 100644 --- a/admin/themes/default/template/controllers/orders/helpers/view/view.tpl +++ b/admin/themes/default/template/controllers/orders/helpers/view/view.tpl @@ -862,61 +862,66 @@ {assign var=order_shipping_price value=$order->total_shipping_tax_incl} {/if} - {assign var=room_price_tax_excl value=$order->getTotalProductsWithoutTaxes(false, true)} - {assign var=room_price_tax_incl value=$order->getTotalProductsWithTaxes(false, true)} - {assign var=service_products_price_tax_excl value=$order->getTotalProductsWithoutTaxes(false, false, Product::SERVICE_PRODUCT_WITHOUT_ROOMTYPE)} - {assign var=service_products_price_tax_incl value=$order->getTotalProductsWithTaxes(false, false, Product::SERVICE_PRODUCT_WITHOUT_ROOMTYPE)} - {assign var=convenience_fee_price_tax_excl value=$order->getTotalProductsWithoutTaxes(false, false, Product::SERVICE_PRODUCT_WITH_ROOMTYPE, 1, Product::PRICE_ADDITION_TYPE_INDEPENDENT)} - {assign var=convenience_fee_price_tax_incl value=$order->getTotalProductsWithTaxes(false, false, Product::SERVICE_PRODUCT_WITH_ROOMTYPE, 1, Product::PRICE_ADDITION_TYPE_INDEPENDENT)} - {assign var=additional_service_price_tax_excl value=($order->getTotalProductsWithoutTaxes(false, false, Product::SERVICE_PRODUCT_WITH_ROOMTYPE) + $totalDemandsPriceTE)} - {assign var=additional_service_price_tax_incl value=($order->getTotalProductsWithTaxes(false, false, Product::SERVICE_PRODUCT_WITH_ROOMTYPE) + $totalDemandsPriceTI)} - {if $room_price_tax_excl} + {* total extra demands prices *} + {* $totalDemandsPriceTE + $totalDemandsPriceTI *} + + {* Get total rooms prices *} + {assign var=total_rooms_price_tax_excl value=$order->getTotalProductsWithoutTaxes(false, true)} + {assign var=total_rooms_price_tax_incl value=$order->getTotalProductsWithTaxes(false, true)} + + {* Get total extra services including convenience fees prices *} + {assign var=total_services_price_tax_excl value=$order->getTotalProductsWithoutTaxes(false, false)} + {assign var=total_services_price_tax_incl value=$order->getTotalProductsWithTaxes(false, false)} + + {* Get total of extra services and extra demands prices(excluding convenience fee) *} + {assign var=total_room_services_and_demands_tax_excl value=($order->getTotalProductsWithoutTaxes(false, false, Product::SERVICE_PRODUCT_WITH_ROOMTYPE) + $totalDemandsPriceTE)} + {assign var=total_room_services_and_demands_tax_incl value=($order->getTotalProductsWithTaxes(false, false, Product::SERVICE_PRODUCT_WITH_ROOMTYPE) + $totalDemandsPriceTI)} + + {* Get total of only convenience fees prices *} + {assign var=total_convenience_fee_tax_excl value=$order->getTotalProductsWithoutTaxes(false, false, Product::SERVICE_PRODUCT_WITH_ROOMTYPE, 1, Product::PRICE_ADDITION_TYPE_INDEPENDENT)} + {assign var=total_convenience_fee_tax_incl value=$order->getTotalProductsWithTaxes(false, false, Product::SERVICE_PRODUCT_WITH_ROOMTYPE, 1, Product::PRICE_ADDITION_TYPE_INDEPENDENT)} + + {assign var=order_total_price_tax_excl value=($total_rooms_price_tax_excl + $total_services_price_tax_excl + $totalDemandsPriceTE)} + {assign var=order_total_price_tax_incl value=($total_rooms_price_tax_incl + $total_services_price_tax_incl + $totalDemandsPriceTI)} + + {if $total_rooms_price_tax_excl} {l s='Total Rooms Cost (Tax excl.)'} - {displayPrice price=$room_price_tax_excl currency=$currency->id} + {displayPrice price=$total_rooms_price_tax_excl currency=$currency->id} {/if} - {if isset($additional_service_price_tax_excl) && $additional_service_price_tax_excl > 0} + {if isset($total_room_services_and_demands_tax_excl) && $total_room_services_and_demands_tax_excl > 0} {l s='Total Extra services (Tax excl.)'} - {displayPrice price=($additional_service_price_tax_excl - $convenience_fee_price_tax_excl) currency=$currency->id} + {displayPrice price=($total_room_services_and_demands_tax_excl - $total_convenience_fee_tax_excl) currency=$currency->id} {/if} - {if $service_products_price_tax_excl} - - {l s='Total service products cost (Tax excl.)'} - - {displayPrice price=$service_products_price_tax_excl currency=$currency->id} - - - - {/if} - - {if isset($convenience_fee_price_tax_excl) && $convenience_fee_price_tax_excl > 0} + {if isset($total_convenience_fee_tax_excl) && $total_convenience_fee_tax_excl > 0} {l s='Convenience Fee (Tax excl.)'} - {if isset($booking_auto_added_services) && count($booking_auto_added_services)} + {if isset($order_convenience_fee_services) && count($order_convenience_fee_services)} {/if} - {displayPrice price=$convenience_fee_price_tax_excl currency=$currency->id} + {displayPrice price=$total_convenience_fee_tax_excl currency=$currency->id} - {if isset($booking_auto_added_services) && count($booking_auto_added_services)} + {if isset($order_convenience_fee_services) && count($order_convenience_fee_services)} - {foreach $booking_auto_added_services as $service} + {foreach $order_convenience_fee_services as $service} @@ -932,41 +937,41 @@ - - {if ($order->total_paid_tax_incl - $order->total_paid_tax_excl) > 0} + {if ($order_total_price_tax_incl - $order_total_price_tax_excl) > 0}
{$service.name} {displayPrice price=$service.total_price_tax_excl currency=$currency->id}
{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}