From 8f5c50e2bf56e0abd2576ceecdf555144af34d01 Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Thu, 13 Apr 2023 20:00:04 +0530 Subject: [PATCH 1/6] fix service product update process from opc page --- .../RoomTypeServiceProductCartDetail.php | 26 ++++++++++--------- .../hotel-reservation-theme/js/order-opc.js | 15 ++++++++--- themes/hotel-reservation-theme/order-opc.tpl | 1 + 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php b/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php index 53bd5a8a0..b1917b305 100644 --- a/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php +++ b/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php @@ -63,19 +63,21 @@ class RoomTypeServiceProductCartDetail extends ObjectModel $objRoomTypeServiceProductCartDetail->id_cart = $idCart; } - $updateQty = $quantity - $objRoomTypeServiceProductCartDetail->quantity; + if ($updateQty = $quantity - $objRoomTypeServiceProductCartDetail->quantity) { + if (Product::getProductPriceCalculation($idProduct) == Product::PRICE_CALCULATION_METHOD_PER_DAY) { + $objHotelCartBookingData = new HotelCartBookingData($idHtlCartData); + $numdays = HotelHelper::getNumberOfDays($objHotelCartBookingData->date_from, $objHotelCartBookingData->date_to); + $updateQty *= $numdays; - if (Product::getProductPriceCalculation($idProduct) == Product::PRICE_CALCULATION_METHOD_PER_DAY) { - $objHotelCartBookingData = new HotelCartBookingData($idHtlCartData); - $numdays = HotelHelper::getNumberOfDays($objHotelCartBookingData->date_from, $objHotelCartBookingData->date_to); - $updateQty *= $numdays; - - } - $way = $updateQty > 0 ? 'up' : 'down'; - $objRoomTypeServiceProductCartDetail->quantity = $quantity; - if ($objRoomTypeServiceProductCartDetail->save()) { - $objCart = new Cart($idCart); - return $objCart->updateQty((int)abs($updateQty), $idProduct, null, false, $way); + } + $way = $updateQty > 0 ? 'up' : 'down'; + $objRoomTypeServiceProductCartDetail->quantity = $quantity; + if ($objRoomTypeServiceProductCartDetail->save()) { + $objCart = new Cart($idCart); + return $objCart->updateQty((int)abs($updateQty), $idProduct, null, false, $way); + } + } else { + return true; } return false; diff --git a/themes/hotel-reservation-theme/js/order-opc.js b/themes/hotel-reservation-theme/js/order-opc.js index bc79fef42..12cd79467 100644 --- a/themes/hotel-reservation-theme/js/order-opc.js +++ b/themes/hotel-reservation-theme/js/order-opc.js @@ -509,8 +509,14 @@ $(document).ready(function() var newQuantity = parseInt(qtyfield.val()) + 1; if (qtyfield.data('max_quantity') && qtyfield.data('max_quantity') < newQuantity) { newQuantity = qtyfield.data('max_quantity'); - } - qtyfield.val(newQuantity).trigger('focusout'); + if (qtyfield.val() != qtyfield.data('max_quantity')) { + qtyfield.trigger('focusout'); + } else { + showSuccessMessage(txtMaxQuantityAdded); + } + } else { + qtyfield.val(newQuantity).trigger('focusout'); + } }); $(document).on('click', '#rooms_extra_services .qty_down', function(e) { @@ -520,7 +526,10 @@ $(document).ready(function() if (!isNaN(currentVal) && currentVal > 1) { qtyfield.val(currentVal - 1).trigger('focusout'); } else { - qtyfield.val(1).trigger('focusout'); + qtyfield.val(1); + if (currentVal != 1) { + qtyfield.trigger('focusout'); + } } }); diff --git a/themes/hotel-reservation-theme/order-opc.tpl b/themes/hotel-reservation-theme/order-opc.tpl index f63d65626..8cdc91e23 100644 --- a/themes/hotel-reservation-theme/order-opc.tpl +++ b/themes/hotel-reservation-theme/order-opc.tpl @@ -506,6 +506,7 @@ {capture}{l s='Update' js=1}{/capture} {addJsDefL name=liUpdate}{$smarty.capture.default|@addcslashes:'\''}{/addJsDefL} {addJsDefL name=txtExtraDemandSucc}{l s='Updated Successfully' js=1}{/addJsDefL} + {addJsDefL name=txtMaxQuantityAdded}{l s='Maximum quantity of service added' js=1}{/addJsDefL} {addJsDefL name=txtExtraDemandErr}{l s='Some error occurred while updating demands' js=1}{/addJsDefL} {/strip} {/if} From 25db54e64bad44f18b2c88957b683d065fb8aafc Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Fri, 14 Apr 2023 10:40:31 +0530 Subject: [PATCH 2/6] update invoice totals tab summary --- pdf/invoice.total-tab.tpl | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/pdf/invoice.total-tab.tpl b/pdf/invoice.total-tab.tpl index 748cfbc77..6744dac03 100644 --- a/pdf/invoice.total-tab.tpl +++ b/pdf/invoice.total-tab.tpl @@ -52,6 +52,16 @@ {/if} + {if $footer.product_discounts_tax_excl > 0} + + + {l s='Total Discounts' pdf='true'} + + + - {displayPrice currency=$order->id_currency price=$footer.product_discounts_tax_excl} + + + {/if} {* {if isset($footer.product_taxes) && $footer.product_taxes} @@ -92,6 +102,7 @@ {/if} *} + {l s='Total (Tax excl.)' pdf='true'} @@ -110,16 +121,7 @@ {/if} - {if $footer.product_discounts_tax_excl > 0} - - - {l s='Total Discounts' pdf='true'} - - - - {displayPrice currency=$order->id_currency price=$footer.product_discounts_tax_excl} - - - {/if} + From bf5457aac83c17a6fb4d42ddafdc6a8ecc1a1602 Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Fri, 14 Apr 2023 13:17:06 +0530 Subject: [PATCH 3/6] update max quantity msg popup --- themes/hotel-reservation-theme/js/order-opc.js | 2 +- themes/hotel-reservation-theme/js/product.js | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/themes/hotel-reservation-theme/js/order-opc.js b/themes/hotel-reservation-theme/js/order-opc.js index 12cd79467..0649a68dd 100644 --- a/themes/hotel-reservation-theme/js/order-opc.js +++ b/themes/hotel-reservation-theme/js/order-opc.js @@ -512,7 +512,7 @@ $(document).ready(function() if (qtyfield.val() != qtyfield.data('max_quantity')) { qtyfield.trigger('focusout'); } else { - showSuccessMessage(txtMaxQuantityAdded); + showErrorMessage(txtMaxQuantityAdded); } } else { qtyfield.val(newQuantity).trigger('focusout'); diff --git a/themes/hotel-reservation-theme/js/product.js b/themes/hotel-reservation-theme/js/product.js index bf1139758..8697c9def 100644 --- a/themes/hotel-reservation-theme/js/product.js +++ b/themes/hotel-reservation-theme/js/product.js @@ -1255,7 +1255,12 @@ $(document).ready(function() { $(that).closest('.service_product_action_block').find('input.service_product_qty').val(1); $(that).closest('.service_product_action_block').find('.qty_count span').text(1); if (result.msg) { - showSuccessMessage(result.msg); + debugger + if (result.add) { + showSuccessMessage(result.msg); + } else { + showErrorMessage(result.msg); + } } BookingForm.refresh(); } else { From ed12611348f5d4b12feebdf641460a736510a3b0 Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Fri, 14 Apr 2023 14:32:33 +0530 Subject: [PATCH 4/6] fix price calculation in total summary --- classes/order/Order.php | 25 ++++++++++++---- classes/pdf/HTMLTemplateInvoice.php | 45 ++++++----------------------- pdf/invoice.total-tab.tpl | 2 +- 3 files changed, 30 insertions(+), 42 deletions(-) diff --git a/classes/order/Order.php b/classes/order/Order.php index 6949bfec5..a379ae014 100644 --- a/classes/order/Order.php +++ b/classes/order/Order.php @@ -586,8 +586,12 @@ class OrderCore extends ObjectModel return self::$_historyCache[$this->id.'_'.$id_order_state.'_'.$filters]; } - public function getProductsDetail($is_booking = null, $product_service_type = null) - { + public function getProductsDetail( + $is_booking = null, + $product_service_type = null, + $product_auto_add = null, + $product_price_addition_type = null + ) { $sql = 'SELECT * FROM `'._DB_PREFIX_.'order_detail` od LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.id_product = od.product_id) @@ -598,6 +602,12 @@ class OrderCore extends ObjectModel if (!$is_booking && $product_service_type !== null) { $sql .= ' AND od.`product_service_type` = '. (int)$product_service_type; } + if (!$is_booking && $product_service_type == Product::SERVICE_PRODUCT_WITH_ROOMTYPE && $product_auto_add !== null) { + $sql .= ' AND od.`product_auto_add` = '. (int)$product_auto_add; + } + if (!$is_booking && $product_service_type == Product::SERVICE_PRODUCT_WITH_ROOMTYPE && $product_auto_add == 1 && $product_price_addition_type !== null) { + $sql .= ' AND od.`product_price_addition_type` = '. (int)$product_price_addition_type; + } } return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); } @@ -1063,11 +1073,16 @@ class OrderCore extends ObjectModel * * @return Product total without taxes */ - public function getTotalProductsWithoutTaxes($products = false, $bookingProducts = null, $product_service_type = null) - { + public function getTotalProductsWithoutTaxes( + $products = false, + $bookingProducts = null, + $product_service_type = null, + $product_auto_add = null, + $product_price_addition_type = null + ) { // update if (!$products) { - $products = $this->getProductsDetail($bookingProducts, $product_service_type); + $products = $this->getProductsDetail($bookingProducts, $product_service_type, $product_auto_add, $product_price_addition_type); } $return = 0; diff --git a/classes/pdf/HTMLTemplateInvoice.php b/classes/pdf/HTMLTemplateInvoice.php index 300367e9f..236780c7d 100644 --- a/classes/pdf/HTMLTemplateInvoice.php +++ b/classes/pdf/HTMLTemplateInvoice.php @@ -324,8 +324,6 @@ class HTMLTemplateInvoiceCore extends HTMLTemplate $room_extra_demands = array(); $room_additinal_services = array(); - $totalConvenienceFeeTE = 0; - $totalConvenienceFeeTI = 0; $totalDemandsPriceTE = 0; $totalDemandsPriceTI = 0; foreach ($order_details as $type_key => $type_value) { @@ -504,32 +502,7 @@ class HTMLTemplateInvoiceCore extends HTMLTemplate 1, 0 ); - $totalConvenienceFeeTI += $cart_htl_data[$type_key]['date_diff'][$date_join]['convenience_fee_ti'] = $objRoomTypeServiceProductOrderDetail->getroomTypeServiceProducts( - $order_obj->id, - 0, - 0, - $data_v['id_product'], - $data_v['date_from'], - $data_v['date_to'], - $data_v['id_room'], - 1, - 1, - 1, - Product::PRICE_ADDITION_TYPE_INDEPENDENT - ); - $totalConvenienceFeeTE += $cart_htl_data[$type_key]['date_diff'][$date_join]['convenience_fee_te'] = $objRoomTypeServiceProductOrderDetail->getroomTypeServiceProducts( - $order_obj->id, - 0, - 0, - $data_v['id_product'], - $data_v['date_from'], - $data_v['date_to'], - $data_v['id_room'], - 1, - 0, - 1, - Product::PRICE_ADDITION_TYPE_INDEPENDENT - ); + $cart_htl_data[$type_key]['date_diff'][$date_join]['additional_services_price_auto_add_ti'] = $objRoomTypeServiceProductOrderDetail->getroomTypeServiceProducts( $order_obj->id, 0, @@ -636,16 +609,16 @@ class HTMLTemplateInvoiceCore extends HTMLTemplate // enter extra demands price to the footer total details $footer['total_extra_demands_ti'] = $totalDemandsPriceTI; $footer['total_extra_demands_te'] = $totalDemandsPriceTE; - $footer['total_convenience_fee_ti'] = $totalConvenienceFeeTI; - $footer['total_convenience_fee_te'] = $totalConvenienceFeeTE; } } - $footer['room_price_tax_excl'] = $this->order->getTotalProductsWithoutTaxes(false, true); - $footer['room_price_tax_incl'] = $this->order->getTotalProductsWithTaxes(false, true); - $footer['service_products_price_tax_excl'] = $this->order->getTotalProductsWithoutTaxes(false, false, Product::SERVICE_PRODUCT_WITHOUT_ROOMTYPE); - $footer['service_products_price_tax_incl'] = $this->order->getTotalProductsWithTaxes(false, false, Product::SERVICE_PRODUCT_WITHOUT_ROOMTYPE); - $footer['additional_service_price_tax_excl'] = $this->order->getTotalProductsWithoutTaxes(false, false, Product::SERVICE_PRODUCT_WITH_ROOMTYPE) + $totalDemandsPriceTE; - $footer['additional_service_price_tax_incl'] = $this->order->getTotalProductsWithTaxes(false, false, Product::SERVICE_PRODUCT_WITH_ROOMTYPE) + $totalDemandsPriceTI; + $footer['room_price_tax_excl'] = $this->order->getTotalProductsWithoutTaxes(false, true) + $this->order->getTotalProductsWithoutTaxes(false, false, Product::SERVICE_PRODUCT_WITH_ROOMTYPE, 1, Product::PRICE_ADDITION_TYPE_WITH_ROOM); + $footer['room_price_tax_incl'] = $this->order->getTotalProductsWithTaxes(false, true) + $this->order->getTotalProductsWithoutTaxes(false, false, Product::SERVICE_PRODUCT_WITH_ROOMTYPE, 1, Product::PRICE_ADDITION_TYPE_WITH_ROOM); + // $footer['service_products_price_tax_excl'] = $this->order->getTotalProductsWithoutTaxes(false, false, Product::SERVICE_PRODUCT_WITHOUT_ROOMTYPE); + // $footer['service_products_price_tax_incl'] = $this->order->getTotalProductsWithTaxes(false, false, Product::SERVICE_PRODUCT_WITHOUT_ROOMTYPE); + $footer['additional_service_price_tax_excl'] = $this->order->getTotalProductsWithoutTaxes(false, false, Product::SERVICE_PRODUCT_WITH_ROOMTYPE, 0) + $totalDemandsPriceTE; + $footer['additional_service_price_tax_incl'] = $this->order->getTotalProductsWithTaxes(false, false, Product::SERVICE_PRODUCT_WITH_ROOMTYPE, 0) + $totalDemandsPriceTI; + $footer['total_convenience_fee_te'] = $this->order->getTotalProductsWithoutTaxes(false, false, Product::SERVICE_PRODUCT_WITH_ROOMTYPE, 1, Product::PRICE_ADDITION_TYPE_INDEPENDENT); + $footer['total_convenience_fee_ti'] = $this->order->getTotalProductsWithTaxes(false, false, Product::SERVICE_PRODUCT_WITH_ROOMTYPE, 1, Product::PRICE_ADDITION_TYPE_INDEPENDENT); $data = array( 'cart_htl_data' => $cart_htl_data, 'service_product_data' => $service_product_data, diff --git a/pdf/invoice.total-tab.tpl b/pdf/invoice.total-tab.tpl index 6744dac03..2f70c1267 100644 --- a/pdf/invoice.total-tab.tpl +++ b/pdf/invoice.total-tab.tpl @@ -38,7 +38,7 @@ {l s='Extra Services Cost (tax excl.)' pdf='true'} - {displayPrice currency=$order->id_currency price=($footer.additional_service_price_tax_excl - $footer.total_convenience_fee_te)} + {displayPrice currency=$order->id_currency price=($footer.additional_service_price_tax_excl)} {/if} From 57ee0be614149296b8524398ca98c6d8815efb3c Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Fri, 14 Apr 2023 16:50:46 +0530 Subject: [PATCH 5/6] removed debugger code --- themes/hotel-reservation-theme/js/product.js | 1 - 1 file changed, 1 deletion(-) diff --git a/themes/hotel-reservation-theme/js/product.js b/themes/hotel-reservation-theme/js/product.js index 8697c9def..c3ee9ae7f 100644 --- a/themes/hotel-reservation-theme/js/product.js +++ b/themes/hotel-reservation-theme/js/product.js @@ -1255,7 +1255,6 @@ $(document).ready(function() { $(that).closest('.service_product_action_block').find('input.service_product_qty').val(1); $(that).closest('.service_product_action_block').find('.qty_count span').text(1); if (result.msg) { - debugger if (result.add) { showSuccessMessage(result.msg); } else { From dd27980c76d1cb1e6d1f52cfbec9cfde60f4eefb Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Fri, 14 Apr 2023 16:52:59 +0530 Subject: [PATCH 6/6] changes getTotalOrderWithTaxes function --- classes/order/Order.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/classes/order/Order.php b/classes/order/Order.php index a379ae014..79ba75e60 100644 --- a/classes/order/Order.php +++ b/classes/order/Order.php @@ -1098,11 +1098,16 @@ class OrderCore extends ObjectModel * * @return Product total with taxes */ - public function getTotalProductsWithTaxes($products = false, $bookingProducts = null, $product_service_type = null) - { + public function getTotalProductsWithTaxes( + $products = false, + $bookingProducts = null, + $product_service_type = null, + $product_auto_add = null, + $product_price_addition_type = null + ) { /* Retro-compatibility (now set directly on the validateOrder() method) */ if (!$products) { - $products = $this->getProductsDetail($bookingProducts, $product_service_type); + $products = $this->getProductsDetail($bookingProducts, $product_service_type, $product_auto_add, $product_price_addition_type); } $return = 0;