From f4758e23968699258ec4eb362ebf3a4b8e662477 Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Mon, 18 Sep 2023 14:46:05 +0530 Subject: [PATCH 01/26] Add option to disable backdate order from admin --- .../admin/AdminOrderPreferencesController.php | 5 ++++ controllers/admin/AdminOrdersController.php | 4 +++ install/data/xml/configuration.xml | 3 ++ .../classes/HotelCartBookingData.php | 28 +++++++++++++++++++ .../RoomTypeServiceProductCartDetail.php | 25 ++++++++++++++++- .../AdminHotelRoomsBookingController.php | 17 +++++++++-- .../hotelreservationsystem.php | 20 ++----------- .../views/js/admin/hotel_rooms_booking.js | 2 ++ 8 files changed, 82 insertions(+), 22 deletions(-) diff --git a/controllers/admin/AdminOrderPreferencesController.php b/controllers/admin/AdminOrderPreferencesController.php index 21b31f6a7..170fe675a 100644 --- a/controllers/admin/AdminOrderPreferencesController.php +++ b/controllers/admin/AdminOrderPreferencesController.php @@ -78,6 +78,11 @@ class AdminOrderPreferencesControllerCore extends AdminController 'class' => 'fixed-width-xl', 'suffix' => $this->l('day(s)'), ), + 'BACKDATE_ORDER_EMPLOYEES' => array( + 'title' => $this->l('Allow backdate order from Back-office'), + 'hint' => $this->l('Allow backoffice employees to create bookings for backdate'), + 'type' => 'bool', + ), ), 'submit' => array( 'title' => $this->l('Save'), diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index 63a271ecd..dc98bbe1b 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -286,6 +286,10 @@ class AdminOrdersControllerCore extends AdminController $cart_order_exists = $cart->orderExists(); if (!$cart_order_exists) { $this->context->cart = $cart; + if (!Configuration::get('BACKDATE_ORDER_EMPLOYEES')) { + $objHotelCartBookingData = new HotelCartBookingData(); + $objHotelCartBookingData->removeBackdateRoomsFromCart($this->context->cart->id); + } $this->context->currency = new Currency((int)$cart->id_currency); $cart_detail_data = array(); $cart_detail_data_obj = new HotelCartBookingData(); diff --git a/install/data/xml/configuration.xml b/install/data/xml/configuration.xml index 935de20ba..5ec2a0371 100644 --- a/install/data/xml/configuration.xml +++ b/install/data/xml/configuration.xml @@ -904,6 +904,9 @@ 1 + + + 1 \ No newline at end of file diff --git a/modules/hotelreservationsystem/classes/HotelCartBookingData.php b/modules/hotelreservationsystem/classes/HotelCartBookingData.php index afae39dcb..8376b6942 100644 --- a/modules/hotelreservationsystem/classes/HotelCartBookingData.php +++ b/modules/hotelreservationsystem/classes/HotelCartBookingData.php @@ -766,6 +766,34 @@ class HotelCartBookingData extends ObjectModel return false; } + /** + * [removeBackdateRoomsFromCart :: To delete the rooms from cart whose booking date is before the current date + * + * @param [int] $idCart [Id of the cart] + * + * @return [boolean] [If removed successfully returns true else returns false] + */ + public function removeBackdateRoomsFromCart($idCart) + { + if ($cartBookingData = $this->getCartCurrentDataByCartId($idCart)) { + $res = true; + foreach ($cartBookingData as $cartRoom) { + if (strtotime($cartRoom['date_from']) < strtotime(date('Y-m-d'))) { + $res = $res && $this->deleteRoomDataFromOrderLine( + $cartRoom['id_cart'], + $cartRoom['id_guest'], + $cartRoom['id_product'], + $cartRoom['date_from'], + $cartRoom['date_to'] + ); + } + } + return $res; + } + + return true; + } + /** * [getCustomerIdRoomsByIdCartIdProduct :: To get array of rooms ids in the cart booked by a customer for a date range]. * diff --git a/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php b/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php index b1917b305..d9db5b6ea 100644 --- a/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php +++ b/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php @@ -95,7 +95,30 @@ class RoomTypeServiceProductCartDetail extends ObjectModel )) { if ($objRoomTypeServiceProductCartDetail->delete()) { $objCart = new Cart($product['id_cart']); - $objCart->updateQty((int)($product['quantity']), $product['id_product'], null, false, 'down'); + if (isset(Context::getContext()->controller->controller_type)) { + $controllerType = Context::getContext()->controller->controller_type; + } else { + $controllerType = 'front'; + } + if ($controllerType == 'admin' || $controllerType == 'moduleadmin') { + if ($cartQty = Cart::getProductQtyInCart($product['id_cart'], $product['id_product'])) { + if ($product['quantity'] < $cartQty) { + Db::getInstance()->update( + 'cart_product', + array('quantity' => (int)($cartQty - $product['quantity'])), + '`id_product` = '.(int)$product['id_product'].' AND `id_cart` = '.(int)$product['id_cart'] + ); + } else { + //if room type has no qty remaining in cart then delete row + Db::getInstance()->delete( + 'cart_product', + '`id_product` = '.(int)$product['id_product'].' AND `id_cart` = '.(int)$product['id_cart'] + ); + } + } + } else { + $objCart->updateQty((int)($product['quantity']), $product['id_product'], null, false, 'down'); + } } } } diff --git a/modules/hotelreservationsystem/controllers/admin/AdminHotelRoomsBookingController.php b/modules/hotelreservationsystem/controllers/admin/AdminHotelRoomsBookingController.php index 6146e43f4..4e6f07575 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminHotelRoomsBookingController.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminHotelRoomsBookingController.php @@ -63,6 +63,11 @@ class AdminHotelRoomsBookingController extends ModuleAdminController $objCustomer->id_guest = (int) $this->context->cookie->id_guest; $this->context->customer = $objCustomer; + + if (!Configuration::get('BACKDATE_ORDER_EMPLOYEES')) { + $htlCart = new HotelCartBookingData(); + $htlCart->removeBackdateRoomsFromCart($this->context->cart->id); + } } protected function createNewCart() @@ -92,13 +97,18 @@ class AdminHotelRoomsBookingController extends ModuleAdminController } else { $date_from = date('Y-m-d'); } + if (!Configuration::get('BACKDATE_ORDER_EMPLOYEES')) { + if (strtotime(date('Y-m-d')) > strtotime($date_from)) { + $date_from = date('Y-m-d'); + } + } if (Tools::getValue('date_to')) { $date_to = Tools::getValue('date_to'); } else { $date_to = date('Y-m-d'); - if (strtotime($date_from) >= strtotime($date_to)) { - $date_to = date('Y-m-d', strtotime('+1 day', strtotime($date_to))); - } + } + if (strtotime($date_from) >= strtotime($date_to)) { + $date_to = date('Y-m-d', strtotime('+1 day', strtotime($date_to))); } if (Tools::getValue('id_hotel')) { @@ -842,6 +852,7 @@ class AdminHotelRoomsBookingController extends ModuleAdminController 'years_txt' => $this->l('years', null, true), 'all_children_txt' => $this->l('All Children', null, true), 'invalid_occupancy_txt' => $this->l('Invalid occupancy(adults/children) found.', null, true), + 'BACKDATE_ORDER_EMPLOYEES' => Configuration::get('BACKDATE_ORDER_EMPLOYEES'), // 'check_calender_var' => $check_calender_var, ); if (Configuration::get('PS_BACKOFFICE_SEARCH_TYPE') == HotelBookingDetail::SEARCH_TYPE_OWS ) { diff --git a/modules/hotelreservationsystem/hotelreservationsystem.php b/modules/hotelreservationsystem/hotelreservationsystem.php index e1240de49..7546ea6f8 100644 --- a/modules/hotelreservationsystem/hotelreservationsystem.php +++ b/modules/hotelreservationsystem/hotelreservationsystem.php @@ -76,24 +76,8 @@ class HotelReservationSystem extends Module if (!Configuration::get('PS_CATALOG_MODE')) { /*To remove room from cart before todays date*/ if (isset($this->context->cart->id) && $this->context->cart->id) { - $htlCart = new HotelCartBookingData(); - if ($cartBookingData = $htlCart->getCartBookingDetailsByIdCartIdGuest( - $this->context->cart->id, - $this->context->cart->id_guest, - $this->context->language->id - )) { - foreach ($cartBookingData as $cartRoom) { - if (strtotime($cartRoom['date_from']) < strtotime(date('Y-m-d'))) { - $htlCart->deleteRoomDataFromOrderLine( - $cartRoom['id_cart'], - $cartRoom['id_guest'], - $cartRoom['id_product'], - $cartRoom['date_from'], - $cartRoom['date_to'] - ); - } - } - } + $objHotelCartBookingData = new HotelCartBookingData(); + $objHotelCartBookingData->removeBackdateRoomsFromCart($this->context->cart->id); } } //End diff --git a/modules/hotelreservationsystem/views/js/admin/hotel_rooms_booking.js b/modules/hotelreservationsystem/views/js/admin/hotel_rooms_booking.js index d02a0b756..31b7593a5 100644 --- a/modules/hotelreservationsystem/views/js/admin/hotel_rooms_booking.js +++ b/modules/hotelreservationsystem/views/js/admin/hotel_rooms_booking.js @@ -220,6 +220,7 @@ $(document).ready(function() { dateFormat: 'dd-mm-yy', altFormat: 'yy-mm-dd', altField: '#date_from', + minDate: BACKDATE_ORDER_EMPLOYEES == 1 ? null : 0, beforeShowDay: function (date) { return highlightDateBorder($("#from_date").val(), date); }, @@ -236,6 +237,7 @@ $(document).ready(function() { dateFormat: 'dd-mm-yy', altFormat: 'yy-mm-dd', altField: '#date_to', + minDate: BACKDATE_ORDER_EMPLOYEES == 1 ? null : 1, beforeShowDay: function (date) { return highlightDateBorder($("#to_date").val(), date); }, From a04597763035314ece1e0085c4e6702c76f5a63e Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Fri, 22 Sep 2023 15:11:52 +0530 Subject: [PATCH 02/26] added msg regarding occupancy field errors --- controllers/front/CartController.php | 4 +-- .../views/css/wk-global-search.css | 2 ++ .../views/js/wk-room-search-block.js | 22 ++++++++++++++ .../views/templates/hook/searchForm.tpl | 3 ++ .../_partials/occupancy_field.tpl | 2 ++ .../hotel-reservation-theme/css/occupancy.css | 2 ++ themes/hotel-reservation-theme/global.tpl | 4 +++ .../hotel-reservation-theme/js/occupancy.js | 29 +++++++++++++++++++ 8 files changed, 66 insertions(+), 2 deletions(-) diff --git a/controllers/front/CartController.php b/controllers/front/CartController.php index e3a37df06..a4569cbd0 100644 --- a/controllers/front/CartController.php +++ b/controllers/front/CartController.php @@ -364,10 +364,10 @@ class CartControllerCore extends FrontController if ($occupancyRequiredForBooking) { foreach($occupancy as $key => $roomOccupancy) { if ($roomOccupancy['adults'] > $roomTypeInfo['max_adults']) { - $this->errors[] = sprintf(Tools::displayError('Room %s cannot have adults more than %s'), $key + 1, $roomTypeInfo['max_adults']); + $this->errors[] = sprintf(Tools::displayError('Room %s cannot have adults more than %s adults'), $key + 1, $roomTypeInfo['max_adults']); } if ($roomOccupancy['children'] > $roomTypeInfo['max_children']) { - $this->errors[] = sprintf(Tools::displayError('Room %s cannot have children more than %s'), $key + 1, $roomTypeInfo['max_children']); + $this->errors[] = sprintf(Tools::displayError('Room %s cannot have children more than %s children'), $key + 1, $roomTypeInfo['max_children']); } if ($roomOccupancy['adults'] + $roomOccupancy['children'] > $roomTypeInfo['max_guests']) { $this->errors[] = sprintf(Tools::displayError('Room %s cannot have total guests more than %s'), $key + 1, $roomTypeInfo['max_guests']); diff --git a/modules/wkroomsearchblock/views/css/wk-global-search.css b/modules/wkroomsearchblock/views/css/wk-global-search.css index a9f773a21..d70fd2e11 100644 --- a/modules/wkroomsearchblock/views/css/wk-global-search.css +++ b/modules/wkroomsearchblock/views/css/wk-global-search.css @@ -273,6 +273,8 @@ font-weight: 400;} #search_occupancy_wrapper .occupancy_info_block .qty_direction .occupancy_quantity_down { margin-top: 3px;} + #search_occupancy_wrapper .occupancy-input-errors { + font-weight: 700;} #search_occupancy_wrapper .children_ages { display: grid; diff --git a/modules/wkroomsearchblock/views/js/wk-room-search-block.js b/modules/wkroomsearchblock/views/js/wk-room-search-block.js index bfb5f13bc..f5d180d16 100644 --- a/modules/wkroomsearchblock/views/js/wk-room-search-block.js +++ b/modules/wkroomsearchblock/views/js/wk-room-search-block.js @@ -447,6 +447,16 @@ $(document).ready(function() { // set input field value $(this).closest('.occupancy_count_block').find('.occupancy_count > span').text(elementVal); + } else { + if (elementVal >= max_child_in_room) { + if (elementVal == 0) { + showOccupancyError(no_children_allowed_txt, $(this).closest(".occupancy_info_block")); + } else { + showOccupancyError(max_children_txt, $(this).closest(".occupancy_info_block")); + } + } else { + showOccupancyError(max_occupancy_reached_txt, $(this).closest(".occupancy_info_block")); + } } } else { element.val(elementVal); @@ -458,6 +468,18 @@ $(document).ready(function() { setGuestOccupancy(); }); + var errorMsgTime; + function showOccupancyError(msg, occupancy_info_block) + { + var errorMsgBlock = $(occupancy_info_block).find('.occupancy-input-errors') + $(errorMsgBlock).html(msg).parent().show('fast'); + clearTimeout(errorMsgTime); + errorMsgTime = setTimeout(function() { + $(errorMsgBlock).parent().hide('fast'); + }, 1000); + + } + $(document).on('click', '#search_occupancy_wrapper .occupancy_quantity_down', function(e) { e.preventDefault(); // set input field value diff --git a/modules/wkroomsearchblock/views/templates/hook/searchForm.tpl b/modules/wkroomsearchblock/views/templates/hook/searchForm.tpl index 79e7bcf2f..9629b5e69 100644 --- a/modules/wkroomsearchblock/views/templates/hook/searchForm.tpl +++ b/modules/wkroomsearchblock/views/templates/hook/searchForm.tpl @@ -112,6 +112,8 @@

({l s='Below' mod='wkroomsearchblock'} {$max_child_age|escape:'htmlall':'UTF-8'} {l s='years' mod='wkroomsearchblock'})

+

+
@@ -186,6 +188,7 @@

({l s='Below' mod='wkroomsearchblock'} {$max_child_age|escape:'htmlall':'UTF-8'} {l s='years' mod='wkroomsearchblock'})

+

diff --git a/themes/hotel-reservation-theme/_partials/occupancy_field.tpl b/themes/hotel-reservation-theme/_partials/occupancy_field.tpl index 4adb17599..5b94b704f 100644 --- a/themes/hotel-reservation-theme/_partials/occupancy_field.tpl +++ b/themes/hotel-reservation-theme/_partials/occupancy_field.tpl @@ -84,6 +84,7 @@
+

@@ -162,6 +163,7 @@
+

diff --git a/themes/hotel-reservation-theme/css/occupancy.css b/themes/hotel-reservation-theme/css/occupancy.css index 6523d35ee..ce5bc70e0 100644 --- a/themes/hotel-reservation-theme/css/occupancy.css +++ b/themes/hotel-reservation-theme/css/occupancy.css @@ -30,6 +30,8 @@ margin-top: 15px; margin-right: -20px; margin-left: -20px;} + .booking_occupancy_wrapper .occupancy-input-errors { + font-weight: 700;} .booking_occupancy_wrapper .children_age_info_block { display: none;} .booking_occupancy_wrapper .children_age_info_block label { diff --git a/themes/hotel-reservation-theme/global.tpl b/themes/hotel-reservation-theme/global.tpl index ebcc94da3..d94e78288 100644 --- a/themes/hotel-reservation-theme/global.tpl +++ b/themes/hotel-reservation-theme/global.tpl @@ -61,6 +61,10 @@ {addJsDef max_child_age=$max_child_age} {addJsDef max_child_in_room=$max_child_in_room} +{addJsDefL name='max_occupancy_reached_txt'}{l s='Room Maximum occupancy reached' js=1}{/addJsDefL} +{addJsDefL name='max_adults_txt'}{l s='Cannot add more adults' js=1}{/addJsDefL} +{addJsDefL name='max_children_txt'}{l s='Cannot add more children' js=1}{/addJsDefL} +{addJsDefL name='no_children_allowed_txt'}{l s='This room cannot accomodate children' js=1}{/addJsDefL} {addJsDefL name='select_occupancy_txt'}{l s='Select Occupancy' js=1}{/addJsDefL} {addJsDefL name='select_age_txt'}{l s='Select age' js=1}{/addJsDefL} {addJsDefL name='under_1_age'}{l s='Under 1' js=1}{/addJsDefL} diff --git a/themes/hotel-reservation-theme/js/occupancy.js b/themes/hotel-reservation-theme/js/occupancy.js index d8a0da637..3edb43a81 100644 --- a/themes/hotel-reservation-theme/js/occupancy.js +++ b/themes/hotel-reservation-theme/js/occupancy.js @@ -78,6 +78,16 @@ $(document).ready(function(){ // set input field value $(this).closest('.occupancy_count_block').find('.occupancy_count > span').text(elementVal + 1); + } else { + if (elementVal >= max_child_in_room) { + if (elementVal == 0) { + showOccupancyError(no_children_allowed_txt, $(this).closest(".booking_occupancy_wrapper")); + } else { + showOccupancyError(max_children_txt, $(this).closest(".booking_occupancy_wrapper")); + } + } else { + showOccupancyError(max_occupancy_reached_txt, $(this).closest(".booking_occupancy_wrapper")); + } } } else { let max_adults_in_room; @@ -87,11 +97,30 @@ $(document).ready(function(){ if (elementVal < max_adults_in_room && elementVal < max_allowed_for_current) { element.val(elementVal + 1); $(this).closest('.occupancy_count_block').find('.occupancy_count > span').text(elementVal + 1); + } else { + if (elementVal >= max_adults_in_room) { + showOccupancyError(max_adults_txt, $(this).closest(".booking_occupancy_wrapper")); + } else { + showOccupancyError(max_occupancy_reached_txt, $(this).closest(".booking_occupancy_wrapper")); + } } } setRoomTypeGuestOccupancy($(this).closest('.booking_occupancy_wrapper')); }); + var errorMsgTime; + $('.occupancy-input-errors').parent().hide(); + function showOccupancyError(msg, booking_occupancy_wrapper) + { + var errorMsgBlock = $(booking_occupancy_wrapper).find('.occupancy-input-errors') + $(errorMsgBlock).html(msg).parent().show('fast'); + clearTimeout(errorMsgTime); + errorMsgTime = setTimeout(function() { + $(errorMsgBlock).parent().hide('fast'); + }, 1000); + + } + $(document).on('click', '.booking_occupancy_wrapper .occupancy_quantity_down', function(e) { e.preventDefault(); From 6d9d4e97d1ff0c59881cc70d7c15c010fa0e1c5e Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Wed, 27 Sep 2023 11:43:10 +0530 Subject: [PATCH 03/26] Allow updating same day checkin and checkout in room status --- controllers/admin/AdminOrdersController.php | 34 ++++++++------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index 63a271ecd..e16e1087f 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -5437,7 +5437,7 @@ class AdminOrdersControllerCore extends AdminController } elseif ((strtotime($statusDate) < strtotime($dateFrom)) || (strtotime($statusDate) > strtotime($dateTo)) ) { - $this->errors[] = Tools::displayError('Invalid dates found.'); + $this->errors[] = Tools::displayError('Date should be between booking from date and to date.'); } } @@ -5445,27 +5445,17 @@ class AdminOrdersControllerCore extends AdminController $objBookingDetail = new HotelBookingDetail(); if ($roomBookingInfo = $objBookingDetail->getRoomBookingData($idRoom, $idOrder, $dateFrom, $dateTo)) { // if admin choose Check-Out status - if ($newStatus == HotelBookingDetail::STATUS_CHECKED_OUT - && $roomBookingInfo['check_in'] == '0000-00-00 00:00:00' - ) { - $this->errors[] = Tools::displayError('Room status must be set to Check-In before setting the room status to Check-Out.'); - } elseif ($newStatus == HotelBookingDetail::STATUS_CHECKED_OUT - && $roomBookingInfo['check_in'] != '0000-00-00 00:00:00' - && strtotime($roomBookingInfo['check_in']) >= strtotime($statusDate) - ) { - $this->errors[] = Tools::displayError('Check-Out date can not be before Check-In date'). - '('.date('d-m-Y', strtotime($roomBookingInfo['check_in'])).')'; - } elseif ($newStatus == HotelBookingDetail::STATUS_CHECKED_IN && $roomBookingInfo['check_out'] == '0000-00-00 00:00:00' - && strtotime($roomBookingInfo['check_in']) >= strtotime($dateTo) - ) { - $this->errors[] = Tools::displayError('Check-In date can not be after Check-Out date'). - '('.date('d-m-Y', strtotime($roomBookingInfo['date_to'])).')'; - } elseif ($newStatus == HotelBookingDetail::STATUS_CHECKED_IN && $roomBookingInfo['check_out'] != '0000-00-00 00:00:00' - && strtotime($roomBookingInfo['check_out']) <= strtotime($statusDate) - ) { - $this->errors[] = Tools::displayError('Check-In date can not be after Check-Out date'). - '('.date('d-m-Y', strtotime($roomBookingInfo['check_out'])).')'; - } else { + if ($newStatus == HotelBookingDetail::STATUS_CHECKED_OUT) { + if ($roomBookingInfo['check_in'] == '0000-00-00 00:00:00') { + $this->errors[] = Tools::displayError('Room status must be set to Check-In before setting the room status to Check-Out.'); + } elseif (strtotime($roomBookingInfo['check_in']) > strtotime($statusDate)) { + $this->errors[] = sprintf( + Tools::displayError('Check-Out date can not be before Check-In date (%s)'), + date('d-m-Y', strtotime($roomBookingInfo['check_in'])) + ); + } + } + if (empty($this->errors)) { if ($objBookingDetail->updateBookingOrderStatusByOrderId( $idOrder, $newStatus, From 251b7c882bacceb2d92727ea3bba21e4f3432361 Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Thu, 5 Oct 2023 16:00:30 +0530 Subject: [PATCH 04/26] add time while updating room checkin and checkout --- .../controllers/orders/helpers/view/view.tpl | 157 +++++++++--------- controllers/admin/AdminOrdersController.php | 136 +++++++-------- 2 files changed, 134 insertions(+), 159 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 b72c4e4cb..bb3e95e52 100644 --- a/admin/themes/default/template/controllers/orders/helpers/view/view.tpl +++ b/admin/themes/default/template/controllers/orders/helpers/view/view.tpl @@ -262,84 +262,80 @@ {l s='Booking cancellation requests has raised from this order. To see booking cancelation requests'} {l s='Click here'}.
{/if} -
-
-
- - {l s='Rooms Status'} -
-
-
-
- +
+
+ + {l s='Rooms Status'} +
+
+
+
+
+ + + + + + + + {if isset($htl_booking_order_data) && $htl_booking_order_data} + {foreach from=$htl_booking_order_data item=data} + {if !$data.is_refunded} + + + + + + + + {/if} + {/foreach} + {else} - - - - - + - {if isset($htl_booking_order_data) && $htl_booking_order_data} - {foreach from=$htl_booking_order_data item=data} - {if !$data.is_refunded} - - - - - - - - {/if} - {/foreach} - {else} - - - - {/if} -
{l s='Room No.'}{l s='Hotel Name'}{l s='Duration'}{l s='Documents'}{l s='Order Status'}
+ {$data['room_num']} + + + {$data['hotel_name']} + + + {dateFormat date=$data['date_from']} - {dateFormat date=$data['date_to']} + + + + {l s='Documents'} {$data.num_checkin_documents} + + +
+
+ + + {if $data['id_status'] == $hotel_order_status['STATUS_CHECKED_IN']['id_status']} +

{l s='Checked in on'} {dateFormat full=1 date=$data['check_in']}

+ {elseif $data['id_status'] == $hotel_order_status['STATUS_CHECKED_OUT']['id_status']} +

{l s='Checked out on'} {dateFormat full=1 date=$data['check_out']}

+ {/if} + + {* field for the current date *} + + + + +
+
+ +
+
+
{l s='Room No.'}{l s='Hotel Name'}{l s='Duration'}{l s='Documents'}{l s='Order Status'}{l s='No data found.'}
- {$data['room_num']} - - - {$data['hotel_name']} - - - {dateFormat date=$data['date_from']} - {dateFormat date=$data['date_to']} - - - - {l s='Documents'} {$data.num_checkin_documents} - - -
-
- - - {if $data['id_status'] == $hotel_order_status['STATUS_CHECKED_IN']['id_status']} -

{l s='Checked in on'} {dateFormat date=$data['check_in']}

- {elseif $data['id_status'] == $hotel_order_status['STATUS_CHECKED_OUT']['id_status']} -

{l s='Checked out on'} {dateFormat date=$data['check_out']}

- {/if} - - {* field for the current date *} - - - - - - -
-
- -
-
-
{l s='No data found.'}
-
+ {/if} +
@@ -1655,14 +1651,11 @@ {* open date picker for the date input of check-in checkout dates *} $(document).on('focus', '.room_status_date', function() { var dateFrom = $(this).closest('.room_status_info_form').find('[name="date_from"]').val(); - dateFrom = dateFrom.split("-"); - minDate = new Date($.datepicker.formatDate('yy-mm-dd', new Date(dateFrom[0], dateFrom[1] - 1, dateFrom[2]))); + minDate = new Date(dateFrom+'T00:00:00'); var dateTo = $(this).closest('.room_status_info_form').find('[name="date_to"]').val(); - dateTo = dateTo.split("-"); - maxDate = new Date($.datepicker.formatDate('yy-mm-dd', new Date(dateTo[0], dateTo[1] - 1, dateTo[2]))); - - $(this).datepicker({ + maxDate = new Date(dateTo+'T23:59:59'); + $(this).datetimepicker({ dateFormat: 'dd-mm-yy', minDate: minDate, maxDate: maxDate, diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index e16e1087f..faf5cfd6c 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -5401,87 +5401,69 @@ class AdminOrdersControllerCore extends AdminController // To change the status of the room public function changeRoomStatus() { - $idRoom = (int) Tools::getValue('id_room'); - $idOrder = (int) Tools::getValue('id_order'); - $dateFrom = Tools::getValue('date_from'); - $dateTo = Tools::getValue('date_to'); - $newStatus = (int) Tools::getValue('booking_order_status'); + $idHotelBookingDetail = (int) Tools::getValue('id_hotel_booking_detail'); + if (Validate::isLoadedObject($objHotelBookingDetail = new HotelBookingDetail($idHotelBookingDetail))) { + $newStatus = (int) Tools::getValue('booking_order_status'); + // date choosen for the status change + if ($statusDate = Tools::getValue('status_date')) { + $statusDate = date('Y-m-d H:i:s', strtotime($statusDate)); + } - // date choosen for the status change - if ($statusDate = Tools::getValue('status_date')) { - $statusDate = date('Y-m-d', strtotime($statusDate)); - } - // Lets validate the fields - if (!$idRoom) { - $this->errors[] = Tools::displayError('Room information not found.'); - } - if (!$idOrder) { - $this->errors[] = Tools::displayError('Order information not found.'); - } - if (!$dateFrom - || !$dateTo - || !Validate::isDate($dateFrom) - || !Validate::isDate($dateTo) - ) { - $this->errors[] = Tools::displayError('Invalid dates found.'); - } - - if (!$newStatus) { - $this->errors[] = Tools::displayError('Invalid booking status found.'); - } elseif ( - $newStatus == HotelBookingDetail::STATUS_CHECKED_IN - || $newStatus == HotelBookingDetail::STATUS_CHECKED_OUT - ) { - if (!$statusDate || !Validate::isDate($statusDate)) { - $this->errors[] = Tools::displayError('Invalid dates found.'); - } elseif ((strtotime($statusDate) < strtotime($dateFrom)) - || (strtotime($statusDate) > strtotime($dateTo)) + $dateFrom = date('Y-m-d H:i:s', strtotime(date('Y-m-d', strtotime($objHotelBookingDetail->date_from)))); + $dateTo = date('Y-m-d H:i:s', strtotime(date('Y-m-d', strtotime($objHotelBookingDetail->date_to)).' 23:59:59')); + if (!$newStatus) { + $this->errors[] = Tools::displayError('Invalid booking status found.'); + } elseif ($newStatus == HotelBookingDetail::STATUS_CHECKED_IN + || $newStatus == HotelBookingDetail::STATUS_CHECKED_OUT ) { - $this->errors[] = Tools::displayError('Date should be between booking from date and to date.'); - } - } - - if (!count($this->errors)) { - $objBookingDetail = new HotelBookingDetail(); - if ($roomBookingInfo = $objBookingDetail->getRoomBookingData($idRoom, $idOrder, $dateFrom, $dateTo)) { - // if admin choose Check-Out status - if ($newStatus == HotelBookingDetail::STATUS_CHECKED_OUT) { - if ($roomBookingInfo['check_in'] == '0000-00-00 00:00:00') { - $this->errors[] = Tools::displayError('Room status must be set to Check-In before setting the room status to Check-Out.'); - } elseif (strtotime($roomBookingInfo['check_in']) > strtotime($statusDate)) { - $this->errors[] = sprintf( - Tools::displayError('Check-Out date can not be before Check-In date (%s)'), - date('d-m-Y', strtotime($roomBookingInfo['check_in'])) - ); - } + if (!$statusDate || !Validate::isDate($statusDate)) { + $this->errors[] = Tools::displayError('Invalid dates found.'); + } elseif ((strtotime($statusDate) < strtotime($dateFrom)) + || (strtotime($statusDate) > strtotime($dateTo)) + ) { + $this->errors[] = Tools::displayError('Date should be between booking from date and to date.'); } - if (empty($this->errors)) { - if ($objBookingDetail->updateBookingOrderStatusByOrderId( - $idOrder, - $newStatus, - $idRoom, - $dateFrom, - $dateTo, - $statusDate - )) { - Hook::exec( - 'actionRoomBookingStatusUpdateAfter', - array( - 'id_order' => $idOrder, - 'id_room' => $idRoom, - 'date_from' => $dateFrom, - 'date_to' => $dateTo - ) - ); - - Tools::redirectAdmin(self::$currentIndex.'&id_order='.(int) $idOrder.'&vieworder&token='.$this->token.'&conf=4'); - } else { - $this->errors[] = Tools::displayError('Some error occurred. Please try again.'); - } - } - } else { - $this->errors[] = Tools::displayError('Invalid booking information. Please try again.'); } + if ($newStatus == HotelBookingDetail::STATUS_CHECKED_OUT) { + if ($objHotelBookingDetail->check_in == '0000-00-00 00:00:00') { + $this->errors[] = Tools::displayError('Room status must be set to Check-In before setting the room status to Check-Out.'); + } elseif (strtotime($objHotelBookingDetail->check_in) > strtotime($statusDate)) { + $this->errors[] = sprintf( + Tools::displayError('Check-Out date can not be before Check-In date (%s)'), + date('d-m-Y', strtotime($objHotelBookingDetail->check_in)) + ); + } + } + + if (empty($this->errors)) { + $objHotelBookingDetail->id_status = $newStatus; + if ($newStatus == HotelBookingDetail::STATUS_CHECKED_IN) { + $objHotelBookingDetail->check_in = $statusDate; + } elseif ($newStatus == HotelBookingDetail::STATUS_CHECKED_OUT) { + $objHotelBookingDetail->check_out = $statusDate; + } else { + $objHotelBookingDetail->check_in = ''; + $objHotelBookingDetail->check_out = ''; + } + if ($objHotelBookingDetail->save()) { + Hook::exec( + 'actionRoomBookingStatusUpdateAfter', + array( + 'id_hotel_booking_detail' => $objHotelBookingDetail->id, + 'id_order' => $objHotelBookingDetail->id_order, + 'id_room' => $objHotelBookingDetail->id_room, + 'date_from' => $objHotelBookingDetail->date_from, + 'date_to' => $objHotelBookingDetail->date_to + ) + ); + + Tools::redirectAdmin(self::$currentIndex.'&id_order='.(int) $objHotelBookingDetail->id_order.'&vieworder&token='.$this->token.'&conf=4'); + } else { + $this->errors[] = Tools::displayError('Some error occurred. Please try again.'); + } + } + } else { + $this->errors[] = Tools::displayError('Invalid booking information. Please try again.'); } } } \ No newline at end of file From 263ba57ac54bdc6ad4d9d4c6a524b6687fd99c1f Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Mon, 16 Oct 2023 18:57:39 +0530 Subject: [PATCH 05/26] added different configuration for backdate order for superadmin and employees --- .../admin/AdminOrderPreferencesController.php | 21 ++++++++++++---- controllers/admin/AdminOrdersController.php | 7 +++++- install/data/xml/configuration.xml | 5 +++- .../AdminHotelRoomsBookingController.php | 24 +++++++++++++++---- .../views/js/admin/hotel_rooms_booking.js | 4 ++-- 5 files changed, 48 insertions(+), 13 deletions(-) diff --git a/controllers/admin/AdminOrderPreferencesController.php b/controllers/admin/AdminOrderPreferencesController.php index 170fe675a..31372ae8d 100644 --- a/controllers/admin/AdminOrderPreferencesController.php +++ b/controllers/admin/AdminOrderPreferencesController.php @@ -78,11 +78,6 @@ class AdminOrderPreferencesControllerCore extends AdminController 'class' => 'fixed-width-xl', 'suffix' => $this->l('day(s)'), ), - 'BACKDATE_ORDER_EMPLOYEES' => array( - 'title' => $this->l('Allow backdate order from Back-office'), - 'hint' => $this->l('Allow backoffice employees to create bookings for backdate'), - 'type' => 'bool', - ), ), 'submit' => array( 'title' => $this->l('Save'), @@ -202,6 +197,22 @@ class AdminOrderPreferencesControllerCore extends AdminController ), 'submit' => array('title' => $this->l('Save')) ), + 'back_date_order' => array( + 'title' => $this->l('Backdate Order Restrictions'), + 'icon' => 'icon-cogs', + 'fields' => array( + 'PS_BACKDATE_ORDER_SUPERADMIN' => array( + 'title' => $this->l('Allow backdate order from Back-office for super-admin'), + 'hint' => $this->l('Allow superadmin to create bookings for backdate'), + 'type' => 'bool', + ), + 'PS_BACKDATE_ORDER_EMPLOYEES' => array( + 'title' => $this->l('Allow backdate order from Back-office for employees'), + 'hint' => $this->l('Allow employees to create bookings for backdate'), + 'type' => 'bool', + ), + ) + ) ); if (!Configuration::get('PS_ALLOW_MULTISHIPPING')) { diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index dc98bbe1b..3a611b3ee 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -286,7 +286,12 @@ class AdminOrdersControllerCore extends AdminController $cart_order_exists = $cart->orderExists(); if (!$cart_order_exists) { $this->context->cart = $cart; - if (!Configuration::get('BACKDATE_ORDER_EMPLOYEES')) { + if ($this->context->employee->isSuperAdmin()) { + $backOrderConfigKey = 'PS_BACKDATE_ORDER_SUPERADMIN'; + } else { + $backOrderConfigKey = 'PS_BACKDATE_ORDER_EMPLOYEES'; + } + if (!Configuration::get($backOrderConfigKey)) { $objHotelCartBookingData = new HotelCartBookingData(); $objHotelCartBookingData->removeBackdateRoomsFromCart($this->context->cart->id); } diff --git a/install/data/xml/configuration.xml b/install/data/xml/configuration.xml index 5ec2a0371..29d13d5ed 100644 --- a/install/data/xml/configuration.xml +++ b/install/data/xml/configuration.xml @@ -905,7 +905,10 @@ 1 - + + 1 + + 1 diff --git a/modules/hotelreservationsystem/controllers/admin/AdminHotelRoomsBookingController.php b/modules/hotelreservationsystem/controllers/admin/AdminHotelRoomsBookingController.php index 4e6f07575..04a2aa885 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminHotelRoomsBookingController.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminHotelRoomsBookingController.php @@ -63,8 +63,12 @@ class AdminHotelRoomsBookingController extends ModuleAdminController $objCustomer->id_guest = (int) $this->context->cookie->id_guest; $this->context->customer = $objCustomer; - - if (!Configuration::get('BACKDATE_ORDER_EMPLOYEES')) { + if ($this->context->employee->isSuperAdmin()) { + $backOrderConfigKey = 'PS_BACKDATE_ORDER_SUPERADMIN'; + } else { + $backOrderConfigKey = 'PS_BACKDATE_ORDER_EMPLOYEES'; + } + if (!Configuration::get($backOrderConfigKey)) { $htlCart = new HotelCartBookingData(); $htlCart->removeBackdateRoomsFromCart($this->context->cart->id); } @@ -97,7 +101,12 @@ class AdminHotelRoomsBookingController extends ModuleAdminController } else { $date_from = date('Y-m-d'); } - if (!Configuration::get('BACKDATE_ORDER_EMPLOYEES')) { + if ($this->context->employee->isSuperAdmin()) { + $backOrderConfigKey = 'PS_BACKDATE_ORDER_SUPERADMIN'; + } else { + $backOrderConfigKey = 'PS_BACKDATE_ORDER_EMPLOYEES'; + } + if (!Configuration::get($backOrderConfigKey)) { if (strtotime(date('Y-m-d')) > strtotime($date_from)) { $date_from = date('Y-m-d'); } @@ -811,6 +820,13 @@ class AdminHotelRoomsBookingController extends ModuleAdminController if (Configuration::get('PS_BACKOFFICE_ROOM_BOOKING_TYPE') == HotelBookingDetail::PS_ROOM_UNIT_SELECTION_TYPE_OCCUPANCY) { $occupancyRequiredForBooking = true; } + if ($this->context->employee->isSuperAdmin()) { + $backOrderConfigKey = 'PS_BACKDATE_ORDER_SUPERADMIN'; + } else { + $backOrderConfigKey = 'PS_BACKDATE_ORDER_EMPLOYEES'; + } + $PS_BACKDATE_ORDER_ALLOW = (int)Configuration::get($backOrderConfigKey); + $jsVars = array( 'currency_prefix' => $currency->prefix, 'currency_suffix' => $currency->suffix, @@ -852,7 +868,7 @@ class AdminHotelRoomsBookingController extends ModuleAdminController 'years_txt' => $this->l('years', null, true), 'all_children_txt' => $this->l('All Children', null, true), 'invalid_occupancy_txt' => $this->l('Invalid occupancy(adults/children) found.', null, true), - 'BACKDATE_ORDER_EMPLOYEES' => Configuration::get('BACKDATE_ORDER_EMPLOYEES'), + 'PS_BACKDATE_ORDER_ALLOW' => $PS_BACKDATE_ORDER_ALLOW, // 'check_calender_var' => $check_calender_var, ); if (Configuration::get('PS_BACKOFFICE_SEARCH_TYPE') == HotelBookingDetail::SEARCH_TYPE_OWS ) { diff --git a/modules/hotelreservationsystem/views/js/admin/hotel_rooms_booking.js b/modules/hotelreservationsystem/views/js/admin/hotel_rooms_booking.js index 31b7593a5..98da293f4 100644 --- a/modules/hotelreservationsystem/views/js/admin/hotel_rooms_booking.js +++ b/modules/hotelreservationsystem/views/js/admin/hotel_rooms_booking.js @@ -220,7 +220,7 @@ $(document).ready(function() { dateFormat: 'dd-mm-yy', altFormat: 'yy-mm-dd', altField: '#date_from', - minDate: BACKDATE_ORDER_EMPLOYEES == 1 ? null : 0, + minDate: PS_BACKDATE_ORDER_ALLOW == 1 ? null : 0, beforeShowDay: function (date) { return highlightDateBorder($("#from_date").val(), date); }, @@ -237,7 +237,7 @@ $(document).ready(function() { dateFormat: 'dd-mm-yy', altFormat: 'yy-mm-dd', altField: '#date_to', - minDate: BACKDATE_ORDER_EMPLOYEES == 1 ? null : 1, + minDate: PS_BACKDATE_ORDER_ALLOW == 1 ? null : 1, beforeShowDay: function (date) { return highlightDateBorder($("#to_date").val(), date); }, From c2af89bb61ae710c2808f763304b4328741c7193 Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Thu, 19 Oct 2023 13:14:03 +0530 Subject: [PATCH 06/26] Update admin translations process, only update changed fields in translation files --- .../helpers/view/translation_errors.tpl | 1 + .../helpers/view/translation_form.tpl | 1 + .../view/translation_inputs_update.tpl | 31 +++++++ .../helpers/view/translation_modules.tpl | 1 + .../admin/AdminTranslationsController.php | 81 ++++++++++++++----- 5 files changed, 95 insertions(+), 20 deletions(-) create mode 100644 admin/themes/default/template/controllers/translations/helpers/view/translation_inputs_update.tpl diff --git a/admin/themes/default/template/controllers/translations/helpers/view/translation_errors.tpl b/admin/themes/default/template/controllers/translations/helpers/view/translation_errors.tpl index db367c079..558975584 100644 --- a/admin/themes/default/template/controllers/translations/helpers/view/translation_errors.tpl +++ b/admin/themes/default/template/controllers/translations/helpers/view/translation_errors.tpl @@ -26,6 +26,7 @@ {extends file="helpers/view/view.tpl"} {block name="override_tpl"} + {include file="./translation_inputs_update.tpl"} {if $mod_security_warning}
{l s='Apache mod_security is activated on your server. This could result in some Bad Request errors'} diff --git a/admin/themes/default/template/controllers/translations/helpers/view/translation_form.tpl b/admin/themes/default/template/controllers/translations/helpers/view/translation_form.tpl index 98f54235c..72fec199a 100644 --- a/admin/themes/default/template/controllers/translations/helpers/view/translation_form.tpl +++ b/admin/themes/default/template/controllers/translations/helpers/view/translation_form.tpl @@ -26,6 +26,7 @@ {extends file="helpers/view/view.tpl"} {block name="override_tpl"} + {include file="./translation_inputs_update.tpl"} {if $mod_security_warning}
{l s='Apache mod_security is activated on your server. This could result in some Bad Request errors'} diff --git a/admin/themes/default/template/controllers/translations/helpers/view/translation_inputs_update.tpl b/admin/themes/default/template/controllers/translations/helpers/view/translation_inputs_update.tpl new file mode 100644 index 000000000..2a9fc59c4 --- /dev/null +++ b/admin/themes/default/template/controllers/translations/helpers/view/translation_inputs_update.tpl @@ -0,0 +1,31 @@ +{** + * 2010-2023 Webkul. + * + * NOTICE OF LICENSE + * + * All right is reserved, + * Please go through LICENSE.txt file inside our module + * + * DISCLAIMER + * + * Do not edit or add to this file if you wish to upgrade this module to newer + * versions in the future. If you wish to customize this module for your + * needs please refer to CustomizationPolicy.txt file inside our module for more information. + * + * @author Webkul IN + * @copyright 2010-2023 Webkul IN + * @license LICENSE.txt + *} + + \ No newline at end of file diff --git a/admin/themes/default/template/controllers/translations/helpers/view/translation_modules.tpl b/admin/themes/default/template/controllers/translations/helpers/view/translation_modules.tpl index 49a2d828d..58363e68c 100644 --- a/admin/themes/default/template/controllers/translations/helpers/view/translation_modules.tpl +++ b/admin/themes/default/template/controllers/translations/helpers/view/translation_modules.tpl @@ -26,6 +26,7 @@ {extends file="helpers/view/view.tpl"} {block name="override_tpl"} + {include file="./translation_inputs_update.tpl"} {if $mod_security_warning}
{l s='Apache mod_security is activated on your server. This could result in some Bad Request errors'} diff --git a/controllers/admin/AdminTranslationsController.php b/controllers/admin/AdminTranslationsController.php index 71ae8481b..73d3addbf 100644 --- a/controllers/admin/AdminTranslationsController.php +++ b/controllers/admin/AdminTranslationsController.php @@ -292,32 +292,63 @@ class AdminTranslationsControllerCore extends AdminController } } - if ($fd = fopen($file_path, 'w')) { - // Get value of button save and stay - $save_and_stay = Tools::isSubmit('submitTranslations'.$type.'AndStay'); + // Get value of button save and stay + $save_and_stay = Tools::isSubmit('submitTranslations'.$type.'AndStay'); - // Get language - $lang = strtolower(Tools::getValue('lang')); + // Get language + $lang = strtolower(Tools::getValue('lang')); - // Unset all POST which are not translations - unset( - $_POST['submitTranslations'.$type], - $_POST['submitTranslations'.$type.'AndStay'], - $_POST['lang'], - $_POST['token'], - $_POST['theme'], - $_POST['type'] - ); + // Unset all POST which are not translations + unset( + $_POST['submitTranslations'.$type], + $_POST['submitTranslations'.$type.'AndStay'], + $_POST['lang'], + $_POST['token'], + $_POST['theme'], + $_POST['type'] + ); - // Get all POST which aren't empty - $to_insert = array(); - foreach ($_POST as $key => $value) { - if (!empty($value)) { - $to_insert[$key] = $value; + // Get all POST which aren't empty + $to_update = array(); + $keysToUpdate = array(); + foreach ($_POST as $key => $value) { + $keysToUpdate[] = $key; + $to_update[$key] = $value; + } + include_once($file_path); + switch($this->type_selected) { + case 'front': + $to_insert = $GLOBALS['_LANG']; + break; + case 'back': + $to_insert = $GLOBALS['_LANGADM']; + break; + case 'errors': + $to_insert = $GLOBALS['_ERRORS']; + break; + case 'fields': + $to_insert = $GLOBALS['_FIELDS']; + break; + case 'pdf': + $to_insert = $GLOBALS['_LANGPDF']; + break; + + } + foreach ($to_insert as $key => $value) { + if (in_array($key, $keysToUpdate)) { + if ($to_update[$key]) { + $to_insert[$key] = $to_update[$key]; + } else { + unset($to_insert[$key]); } + unset($to_update[$key]); } + } + foreach ($to_update as $key => $value) { + $to_insert[$key] = $value; + } - // translations array is ordered by key (easy merge) + if ($fd = fopen($file_path, 'w')) { ksort($to_insert); $tab = $translation_informations['var']; fwrite($fd, "total_expression++; } } + foreach ($module_existing_translations as $key => $value) { + if (!in_array('\''.$key.'\'', $array_check_duplicate)) { + $str_write .= '$_MODULE[\''.$key.'\'] = \''.pSQL(str_replace(array("\r\n", "\r", "\n"), ' ', $value)).'\';'."\n"; + + } + } + } } From 1b851d20643186fa0a1f8f2746770598fb5a1411 Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Fri, 27 Oct 2023 18:32:48 +0530 Subject: [PATCH 07/26] Fix wrong data in statstics when exporting data --- classes/module/ModuleGraph.php | 10 +++--- modules/statsequipment/statsequipment.php | 10 ++++-- modules/statsnewsletter/statsnewsletter.php | 10 +++--- modules/statsorigin/statsorigin.php | 5 ++- .../statspersonalinfos/statspersonalinfos.php | 35 ++++++++++++++++--- modules/statsproduct/statsproduct.php | 7 ++-- .../statsregistrations/statsregistrations.php | 5 ++- modules/statssales/statssales.php | 15 ++++++-- modules/statsvisits/statsvisits.php | 9 +++-- 9 files changed, 80 insertions(+), 26 deletions(-) diff --git a/classes/module/ModuleGraph.php b/classes/module/ModuleGraph.php index a68560201..9596c9e9b 100644 --- a/classes/module/ModuleGraph.php +++ b/classes/module/ModuleGraph.php @@ -102,7 +102,7 @@ abstract class ModuleGraphCore extends Module $this->_values[$j][$i] = 0; } } - $this->_legend[$i] = ($i % 2) ? '' : sprintf('%02d', $i); + $this->_legend[$i] = sprintf('%02d', $i); } } if (is_callable(array($this, 'setMonthValues'))) { @@ -195,15 +195,15 @@ abstract class ModuleGraphCore extends Module if (count($this->_legend)) { $total = 0; if ($datas['type'] == 'pie') { - foreach ($this->_legend as $key => $legend) { + // foreach ($this->_legend as $key => $legend) { for ($i = 0, $total_main = (is_array($this->_titles['main']) ? count($this->_values) : 1); $i < $total_main; ++$i) { - $total += (is_array($this->_values[$i]) ? $this->_values[$i][$key] : $this->_values[$key]); + $total += (is_array($this->_values[$i]) ? $this->_values[$i][$key] : $this->_values[$i]); } - } + // } } foreach ($this->_legend as $key => $legend) { $this->_csv .= $legend.';'; - for ($i = 0, $total_main = (is_array($this->_titles['main']) ? count($this->_values) : 1); $i < $total_main; ++$i) { + for ($i = 0, $total_main = (is_array($this->_titles['main']) ? (count($this->_titles['main']) - 1) : 1); $i < $total_main; ++$i) { if (!isset($this->_values[$i]) || !is_array($this->_values[$i])) { if (isset($this->_values[$key])) { // We don't want strings to be divided. Example: product name diff --git a/modules/statsequipment/statsequipment.php b/modules/statsequipment/statsequipment.php index 69a596cea..5827f13ff 100644 --- a/modules/statsequipment/statsequipment.php +++ b/modules/statsequipment/statsequipment.php @@ -179,7 +179,10 @@ class StatsEquipment extends ModuleGraph { switch ($option) { case 'wb': - $this->_titles['main'] = $this->l('Web browser used'); + $this->_titles['main'][] = $this->l('Web browser used'); + if (Tools::getValue('export')) { + $this->_titles['main'][] = ''; + } $this->query = 'SELECT wb.`name`, COUNT(g.`id_web_browser`) AS total FROM `'._DB_PREFIX_.'web_browser` wb LEFT JOIN `'._DB_PREFIX_.'guest` g ON g.`id_web_browser` = wb.`id_web_browser` @@ -191,7 +194,10 @@ class StatsEquipment extends ModuleGraph break; case 'os': - $this->_titles['main'] = $this->l('Operating system used'); + $this->_titles['main'][] = $this->l('Operating system used'); + if (Tools::getValue('export')) { + $this->_titles['main'][] = ''; + } $this->query = 'SELECT os.`name`, COUNT(g.`id_operating_system`) AS total FROM `'._DB_PREFIX_.'operating_system` os LEFT JOIN `'._DB_PREFIX_.'guest` g ON g.`id_operating_system` = os.`id_operating_system` diff --git a/modules/statsnewsletter/statsnewsletter.php b/modules/statsnewsletter/statsnewsletter.php index ea837ec28..19938822f 100644 --- a/modules/statsnewsletter/statsnewsletter.php +++ b/modules/statsnewsletter/statsnewsletter.php @@ -125,10 +125,12 @@ class StatsNewsletter extends ModuleGraph protected function getData($layers) { - $this->_titles['main'][0] = $this->l('Customers'); - $this->_titles['main'][1] = $this->l('Visitors'); - $this->_titles['main'][2] = $this->l('Newsletter statistics'); - $this->_titles['main'][3] = $this->l('Both'); + if (Tools::getValue('export')) { + $this->_titles['main'][] = $this->l('Date'); + } + $this->_titles['main'][] = $this->l('Customers'); + $this->_titles['main'][] = $this->l('Visitors'); + $this->_titles['main'][] = $this->l('Both'); $this->_query = 'SELECT newsletter_date_add FROM `'._DB_PREFIX_.'customer` diff --git a/modules/statsorigin/statsorigin.php b/modules/statsorigin/statsorigin.php index 32bfe8f82..020ca10e3 100644 --- a/modules/statsorigin/statsorigin.php +++ b/modules/statsorigin/statsorigin.php @@ -142,7 +142,10 @@ class StatsOrigin extends ModuleGraph protected function getData($layers) { - $this->_titles['main'] = $this->l('Top ten referral websites'); + $this->_titles['main'][] = $this->l('Top ten referral websites'); + if (Tools::getValue('export')) { + $this->_titles['main'][] = $this->l('Referal percentage'); + } $websites = $this->getOrigins($this->getDate()); $total = 0; $total2 = 0; diff --git a/modules/statspersonalinfos/statspersonalinfos.php b/modules/statspersonalinfos/statspersonalinfos.php index a08bee698..7b4e21af9 100644 --- a/modules/statspersonalinfos/statspersonalinfos.php +++ b/modules/statspersonalinfos/statspersonalinfos.php @@ -212,7 +212,12 @@ class StatsPersonalInfos extends ModuleGraph { switch ($this->option) { case 'gender': - $this->_titles['main'] = $this->l('Gender distribution'); + if (Tools::getValue('export')) { + $this->_titles['main'][] = $this->l('Gender'); + $this->_titles['main'][] = ''; + } else { + $this->_titles['main'] = $this->l('Gender distribution'); + } $genders = array( 0 => $this->l('Male'), 1 => $this->l('Female'), @@ -243,7 +248,12 @@ class StatsPersonalInfos extends ModuleGraph break; case 'age': - $this->_titles['main'] = $this->l('Age range'); + if (Tools::getValue('export')) { + $this->_titles['main'][] = $this->l('Age'); + $this->_titles['main'][] = ''; + } else { + $this->_titles['main'] = $this->l('Age range'); + } // 0 - 18 years $sql = 'SELECT COUNT(`id_customer`) as total @@ -334,7 +344,12 @@ class StatsPersonalInfos extends ModuleGraph break; case 'country': - $this->_titles['main'] = $this->l('Country distribution'); + if (Tools::getValue('export')) { + $this->_titles['main'][] = $this->l('Country'); + $this->_titles['main'][] = ''; + } else { + $this->_titles['main'] = $this->l('Country distribution'); + } $sql = 'SELECT cl.`name`, COUNT(c.`id_country`) AS total FROM `'._DB_PREFIX_.'address` a LEFT JOIN `'._DB_PREFIX_.'customer` cu ON cu.id_customer = a.id_customer @@ -351,7 +366,12 @@ class StatsPersonalInfos extends ModuleGraph break; case 'currency': - $this->_titles['main'] = $this->l('Currency distribution'); + if (Tools::getValue('export')) { + $this->_titles['main'][] = $this->l('Currency'); + $this->_titles['main'][] = ''; + } else { + $this->_titles['main'] = $this->l('Currency distribution'); + } $sql = 'SELECT c.`name`, COUNT(c.`id_currency`) AS total FROM `'._DB_PREFIX_.'orders` o LEFT JOIN `'._DB_PREFIX_.'currency` c ON o.`id_currency` = c.`id_currency` @@ -366,7 +386,12 @@ class StatsPersonalInfos extends ModuleGraph break; case 'language': - $this->_titles['main'] = $this->l('Language distribution'); + if (Tools::getValue('export')) { + $this->_titles['main'][] = $this->l('Language'); + $this->_titles['main'][] = ''; + } else { + $this->_titles['main'] = $this->l('Language distribution'); + } $sql = 'SELECT c.`name`, COUNT(c.`id_lang`) AS total FROM `'._DB_PREFIX_.'orders` o LEFT JOIN `'._DB_PREFIX_.'lang` c ON o.`id_lang` = c.`id_lang` diff --git a/modules/statsproduct/statsproduct.php b/modules/statsproduct/statsproduct.php index fcd91f0e6..feba386e3 100644 --- a/modules/statsproduct/statsproduct.php +++ b/modules/statsproduct/statsproduct.php @@ -339,8 +339,11 @@ class StatsProduct extends ModuleGraph $date_between = $this->getDate(); switch ($this->option) { case 1: - $this->_titles['main'][0] = $this->l('Room nights'); - $this->_titles['main'][1] = $this->l('Views (x100)'); + if (Tools::getValue('export')) { + $this->_titles['main'][] = $this->l('Date'); + } + $this->_titles['main'][] = $this->l('Room nights'); + $this->_titles['main'][] = $this->l('Views (x100)'); $this->_titles['x'] = $this->l('Date'); $this->_titles['y'] = $this->l('Room nights, Views (x100)'); diff --git a/modules/statsregistrations/statsregistrations.php b/modules/statsregistrations/statsregistrations.php index 6931a4cc6..030958cc0 100644 --- a/modules/statsregistrations/statsregistrations.php +++ b/modules/statsregistrations/statsregistrations.php @@ -170,7 +170,10 @@ class StatsRegistrations extends ModuleGraph WHERE 1 '.Shop::addSqlRestriction(Shop::SHARE_CUSTOMER).' AND `date_add` BETWEEN'; - $this->_titles['main'] = $this->l('Number of customer registrations'); + if (Tools::getValue('export')) { + $this->_titles['main'][] = $this->l('Date'); + } + $this->_titles['main'][] = $this->l('Number of customer registrations'); $this->setDateGraph($layers, true); } diff --git a/modules/statssales/statssales.php b/modules/statssales/statssales.php index c56931ab6..6ae972257 100644 --- a/modules/statssales/statssales.php +++ b/modules/statssales/statssales.php @@ -216,14 +216,23 @@ class StatsSales extends ModuleGraph list($this->option, $this->id_country, $this->id_hotel) = explode('-', $options); switch ($this->option) { case 1: - $this->_titles['main'] = $this->l('Orders placed'); + if (Tools::getValue('export')) { + $this->_titles['main'][] = $this->l('Date'); + } + $this->_titles['main'][] = $this->l('Orders placed'); break; case 2: + if (Tools::getValue('export')) { + $this->_titles['main'][] = $this->l('Date'); + } $currency = new Currency((int)Configuration::get('PS_CURRENCY_DEFAULT')); - $this->_titles['main'] = sprintf($this->l('Revenue currency: %s'), $currency->iso_code); + $this->_titles['main'][] = sprintf($this->l('Revenue currency: %s'), $currency->iso_code); break; case 3: - $this->_titles['main'] = $this->l('Percentage of orders per status.'); + if (Tools::getValue('export')) { + $this->_titles['main'][] = $this->l('Payment method'); + } + $this->_titles['main'][] = $this->l('Percentage of orders per status.'); break; } } diff --git a/modules/statsvisits/statsvisits.php b/modules/statsvisits/statsvisits.php index f96716af5..aab29d1d8 100644 --- a/modules/statsvisits/statsvisits.php +++ b/modules/statsvisits/statsvisits.php @@ -137,9 +137,12 @@ class StatsVisits extends ModuleGraph { switch ($option) { case 3: - $this->_titles['main'][0] = $this->l('Visits'); - $this->_titles['main'][1] = $this->l('Number of visits and unique visitors'); - $this->_titles['main'][2] = $this->l('Visitors'); + if (Tools::getValue('export')) { + $this->_titles['main'][] = $this->l('Date'); + } + + $this->_titles['main'][] = $this->l('Visits'); + $this->_titles['main'][] = $this->l('Number of visits and unique visitors'); $this->query[0] = 'SELECT date_add, COUNT(`date_add`) as total FROM `'._DB_PREFIX_.'connections` WHERE 1 From 4a7f85e6a334ed47f409dfcfbc0da64a05e38b21 Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Fri, 3 Nov 2023 18:17:42 +0530 Subject: [PATCH 08/26] auto add services with add price with room type will have tax rule same as room type --- .../controllers/normal_products/prices.tpl | 4 +-- .../controllers/products/serviceproduct.tpl | 28 +++++++++++-------- classes/Product.php | 17 ++++++----- .../admin/AdminNormalProductsController.php | 6 ++++ controllers/admin/AdminProductsController.php | 5 +++- .../classes/RoomTypeServiceProductPrice.php | 23 +++++++++++---- 6 files changed, 53 insertions(+), 30 deletions(-) diff --git a/admin/themes/default/template/controllers/normal_products/prices.tpl b/admin/themes/default/template/controllers/normal_products/prices.tpl index 9b91f7206..269ef84af 100644 --- a/admin/themes/default/template/controllers/normal_products/prices.tpl +++ b/admin/themes/default/template/controllers/normal_products/prices.tpl @@ -139,7 +139,7 @@ $(document).ready(function () {
-
+
auto_add_to_cart && $product->price_addition_type == Product::PRICE_ADDITION_TYPE_WITH_ROOM}style="display:none"{/if}>
{include file="controllers/products/multishop/checkbox.tpl" field="id_tax_rules_group" type="default"}
-
+
auto_add_to_cart && $product->price_addition_type == Product::PRICE_ADDITION_TYPE_WITH_ROOM}style="display:none"{/if}>
{$currency->prefix}{$currency->suffix} diff --git a/admin/themes/default/template/controllers/products/serviceproduct.tpl b/admin/themes/default/template/controllers/products/serviceproduct.tpl index 668c5e0d6..f606dd275 100644 --- a/admin/themes/default/template/controllers/products/serviceproduct.tpl +++ b/admin/themes/default/template/controllers/products/serviceproduct.tpl @@ -55,18 +55,22 @@
{l s='Default price: %s' sprintf={displayPrice price=$service_product.default_price currency=$currency->id}} - {if isset($service_product.tax_rules_group_name) && $service_product.tax_rules_group_name}{$service_product.tax_rules_group_name}{else}{$service_product.default_tax_rules_group_name}{/if} - -
{l s='Default tax rule: %s' sprintf=$service_product.default_tax_rules_group_name} + {if $service_product.auto_add_to_cart && $service_product.price_addition_type == Product::PRICE_ADDITION_TYPE_WITH_ROOM} + {l s='-'} + {else} + {if isset($service_product.tax_rules_group_name) && $service_product.tax_rules_group_name}{$service_product.tax_rules_group_name}{else}{$service_product.default_tax_rules_group_name}{/if} + +
{l s='Default tax rule: %s' sprintf=$service_product.default_tax_rules_group_name} + {/if} diff --git a/classes/Product.php b/classes/Product.php index 9af80ed4f..44b16ae67 100644 --- a/classes/Product.php +++ b/classes/Product.php @@ -2997,7 +2997,7 @@ class ProductCore extends ObjectModel public static function getPriceStatic($id_product, $usetax = true, $id_product_attribute = null, $decimals = 6, $divisor = null, $only_reduc = false, $usereduc = true, $quantity = 1, $force_associated_tax = false, $id_customer = null, $id_cart = null, $id_address = null, &$specific_price_output = null, $with_ecotax = true, $use_group_reduction = true, Context $context = null, - $use_customer_price = true, $id_roomtype = false) + $use_customer_price = true, $id_product_roomtype = false) { if (!$context) { $context = Context::getContext(); @@ -3063,9 +3063,9 @@ class ProductCore extends ObjectModel if (!$id_address) { if (!Product::isBookingProduct($id_product)) { - if ($id_roomtype) { + if ($id_product_roomtype) { // if room type is provided with product then we know that the service product price should be calculated accroding to roomt type - $id_address = Cart::getIdAddressForTaxCalculation($id_roomtype); + $id_address = Cart::getIdAddressForTaxCalculation($id_product_roomtype); } } else { $id_address = Cart::getIdAddressForTaxCalculation($id_product); @@ -3119,7 +3119,7 @@ class ProductCore extends ObjectModel $use_customer_price, $id_cart, $cart_quantity, - $id_roomtype + $id_product_roomtype ); return $return; @@ -3153,9 +3153,8 @@ class ProductCore extends ObjectModel **/ public static function priceCalculation($id_shop, $id_product, $id_product_attribute, $id_country, $id_state, $zipcode, $id_currency, $id_group, $quantity, $use_tax, $decimals, $only_reduc, $use_reduc, $with_ecotax, &$specific_price, $use_group_reduction, - $id_customer = 0, $use_customer_price = true, $id_cart = 0, $real_quantity = 0, $id_roomtype = false) + $id_customer = 0, $use_customer_price = true, $id_cart = 0, $real_quantity = 0, $id_product_roomtype = false) { - static $address = null; static $context = null; @@ -3182,7 +3181,7 @@ class ProductCore extends ObjectModel $cache_id = (int)$id_product.'-'.(int)$id_shop.'-'.(int)$id_currency.'-'.(int)$id_country.'-'.$id_state.'-'.$zipcode.'-'.(int)$id_group. '-'.(int)$quantity.'-'.(int)$id_product_attribute. '-'.(int)$with_ecotax.'-'.(int)$id_customer.'-'.(int)$use_group_reduction.'-'.(int)$id_cart.'-'.(int)$real_quantity. - '-'.($only_reduc?'1':'0').'-'.($use_reduc?'1':'0').'-'.($use_tax?'1':'0').'-'.(int)$decimals.'-'.($id_roomtype?(int)$id_roomtype:'0'); + '-'.($only_reduc?'1':'0').'-'.($use_reduc?'1':'0').'-'.($use_tax?'1':'0').'-'.(int)$decimals.'-'.($id_product_roomtype?(int)$id_product_roomtype:'0'); // reference parameter is filled before any returns $specific_price = SpecificPrice::getSpecificPrice( @@ -3246,10 +3245,10 @@ class ProductCore extends ObjectModel $result = self::$_pricesLevel2[$cache_id_2][(int)$id_product_attribute]; // get price per room type - if ($id_roomtype) { + if ($id_product_roomtype) { $priceForRoomInfo = RoomTypeServiceProductPrice::getProductRoomTypePriceAndTax( $id_product, - $id_roomtype, + $id_product_roomtype, RoomTypeServiceProduct::WK_ELEMENT_TYPE_ROOM_TYPE ); } diff --git a/controllers/admin/AdminNormalProductsController.php b/controllers/admin/AdminNormalProductsController.php index b9c184cdc..728bd0ec8 100644 --- a/controllers/admin/AdminNormalProductsController.php +++ b/controllers/admin/AdminNormalProductsController.php @@ -1898,6 +1898,12 @@ class AdminNormalProductsControllerCore extends AdminController // set product visibility to none for current flow. $object->visibility = 'none'; + // if service is auto_added and price addition is in room price, then the tax rule is applied of room price. + // so setting tax rule as no tax for now + if ($object->auto_add_to_cart && $object->price_addition_type == Product::PRICE_ADDITION_TYPE_WITH_ROOM) { + $object->id_tax_rules_group = 0; + } + // Duplicate combinations if not associated to shop if ($this->context->shop->getContext() == Shop::CONTEXT_SHOP && !$object->isAssociatedToShop()) { $is_associated_to_shop = false; diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php index 542c4bdb6..8be3ba093 100644 --- a/controllers/admin/AdminProductsController.php +++ b/controllers/admin/AdminProductsController.php @@ -1162,7 +1162,9 @@ class AdminProductsControllerCore extends AdminController } $objRoomTypeServiceProductPrice->price = $price; - $objRoomTypeServiceProductPrice->id_tax_rules_group = $id_tax_rules_group; + if ($id_tax_rules_group) { + $objRoomTypeServiceProductPrice->id_tax_rules_group = $id_tax_rules_group; + } if (!$objRoomTypeServiceProductPrice->save()) { $error = $this->l('Unable to save price, please try again.'); @@ -2843,6 +2845,7 @@ class AdminProductsControllerCore extends AdminController $serviceProduct['id_product'] = $product->id; $serviceProduct['name'] = $product->name; $serviceProduct['auto_add_to_cart'] = $product->auto_add_to_cart; + $serviceProduct['price_addition_type'] = $product->price_addition_type; $serviceProduct['category'] = $product->category; $serviceProduct['default_price'] = $product->price; $serviceProduct['id_tax_rules_group'] = $product->id_tax_rules_group; diff --git a/modules/hotelreservationsystem/classes/RoomTypeServiceProductPrice.php b/modules/hotelreservationsystem/classes/RoomTypeServiceProductPrice.php index ea8879f6e..7dcc50da7 100644 --- a/modules/hotelreservationsystem/classes/RoomTypeServiceProductPrice.php +++ b/modules/hotelreservationsystem/classes/RoomTypeServiceProductPrice.php @@ -65,12 +65,23 @@ class RoomTypeServiceProductPrice extends ObjectModel public static function getProductRoomTypePriceAndTax($idProduct, $idElement, $elementType) { - return Db::getInstance()->getRow( - 'SELECT `price`, `id_tax_rules_group` FROM `'._DB_PREFIX_.'htl_room_type_service_product_price` - WHERE `id_product`='.(int)$idProduct. - ' AND `id_element`='.(int)$idElement. - ' AND `element_type`='.(int)$elementType - ); + if ($result = Db::getInstance()->getRow(' + SELECT spp.`price`, spp.`id_tax_rules_group`, p.`auto_add_to_cart`, p.`price_addition_type` + FROM `'._DB_PREFIX_.'product` p + LEFT JOIN `'._DB_PREFIX_.'htl_room_type_service_product_price` spp ON (spp.`id_product` = p.`id_product`) + WHERE p.`id_product`='.(int)$idProduct. + ' AND spp.`id_element`='.(int)$idElement. + ' AND spp.`element_type`='.(int)$elementType) + ) { + if ($result['auto_add_to_cart'] && $result['price_addition_type'] == Product::PRICE_ADDITION_TYPE_WITH_ROOM) { + // if service is auto add to cart and added in room price, we need to find room type tax rule group + if ($elementType == RoomTypeServiceProduct::WK_ELEMENT_TYPE_ROOM_TYPE) { + $result['id_tax_rules_group'] = Product::getIdTaxRulesGroupByIdProduct((int)$idElement); + } + } + } + + return $result; } public function getProductRoomTypeLinkPriceInfo($idProduct, $idElement, $elementType) From 7b938aa0232ecfdbc242dc592bc5a638e7c45312 Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Mon, 20 Nov 2023 16:01:54 +0530 Subject: [PATCH 09/26] Remove address as required in booking/order flow --- classes/PaymentModule.php | 12 ---- .../CheckoutCustomerDetailsStep.php | 32 ++------- classes/controller/FrontController.php | 11 +-- classes/module/Module.php | 6 +- controllers/front/OrderOpcController.php | 3 - controllers/front/ParentOrderController.php | 70 +++++++++---------- .../bankwire/controllers/front/validation.php | 2 +- .../cheque/controllers/front/validation.php | 2 +- 8 files changed, 52 insertions(+), 86 deletions(-) diff --git a/classes/PaymentModule.php b/classes/PaymentModule.php index 3e89319f2..fbca539bf 100644 --- a/classes/PaymentModule.php +++ b/classes/PaymentModule.php @@ -181,9 +181,6 @@ abstract class PaymentModuleCore extends Module ShopUrl::resetMainDomainCache(); $id_currency = $currency_special ? (int)$currency_special : (int)$this->context->cart->id_currency; $this->context->currency = new Currency((int)$id_currency, null, (int)$this->context->shop->id); - if (Configuration::get('PS_TAX_ADDRESS_TYPE') == 'id_address_delivery') { - $context_country = $this->context->country; - } $order_status = new OrderState((int)$id_order_state, (int)$this->context->language->id); if (!Validate::isLoadedObject($order_status)) { @@ -463,15 +460,6 @@ abstract class PaymentModuleCore extends Module } } - // The country can only change if the address used for the calculation is the delivery address, and if multi-shipping is activated - if (Configuration::get('PS_TAX_ADDRESS_TYPE') == 'id_address_delivery') { - $this->context->country = $context_country; - } - - if (!$this->context->country->active) { - PrestaShopLogger::addLog('PaymentModule::validateOrder - Country is not active', 3, null, 'Cart', (int)$id_cart, true); - throw new PrestaShopException('The order address country is not active.'); - } if (self::DEBUG_MODE) { PrestaShopLogger::addLog('PaymentModule::validateOrder - Payment is about to be added', 1, null, 'Cart', (int)$id_cart, true); diff --git a/classes/checkoutProcess/CheckoutCustomerDetailsStep.php b/classes/checkoutProcess/CheckoutCustomerDetailsStep.php index b8933ae06..6bccd6e83 100644 --- a/classes/checkoutProcess/CheckoutCustomerDetailsStep.php +++ b/classes/checkoutProcess/CheckoutCustomerDetailsStep.php @@ -33,13 +33,9 @@ class CheckoutCustomerDetailsStepCore extends AbstractCheckoutStepCore if (Tools::getValue('proceed_to_customer_dtl')) { $this->step_is_reachable = 1; $this->step_is_current = 1; - if ($idAddressDelivery) { - if (!Validate::isLoadedObject($objAddress)) { - if ($this->context->cookie->__get('customer_details_proceeded')) { - $this->step_is_current = 0; - $this->step_is_complete = 1; - } - } + if ($this->context->cookie->__get('customer_details_proceeded')) { + $this->step_is_current = 0; + $this->step_is_complete = 1; } } elseif (Tools::getValue('proceed_to_payment')) { $guestInfoComplete = true; @@ -52,34 +48,20 @@ class CheckoutCustomerDetailsStepCore extends AbstractCheckoutStepCore } $this->step_is_reachable = 1; $this->step_is_current = 1; - if ($idAddressDelivery && $guestInfoComplete) { - if (Validate::isLoadedObject($objAddress)) { - $this->step_is_current = 0; - $this->step_is_complete = 1; - $this->context->cookie->__set('customer_details_proceeded', 1); - } + if ($guestInfoComplete) { + $this->step_is_current = 0; + $this->step_is_complete = 1; + $this->context->cookie->__set('customer_details_proceeded', 1); } } elseif ($this->context->cookie->__get('customer_details_proceeded') || $this->context->cookie->__get('cart_summary_proceeded') ) { - if ($idAddressDelivery) { - if (!Validate::isLoadedObject($objAddress)) { - $this->context->cookie->__set('customer_details_proceeded', 0); - $this->step_is_reachable = 1; - $this->step_is_current = 1; - } - } else { - $this->step_is_reachable = 1; - $this->step_is_current = 1; - $this->context->cookie->__set('customer_details_proceeded', 0); - } } elseif ($this->context->customer->logged) { $this->step_is_reachable = 1; if ($idAddressDelivery) { $this->step_is_complete = 1; } else { $this->step_is_complete = 0; - $this->step_is_current = 1; } } } diff --git a/classes/controller/FrontController.php b/classes/controller/FrontController.php index 2f19b9f61..ae6ab2da5 100644 --- a/classes/controller/FrontController.php +++ b/classes/controller/FrontController.php @@ -416,11 +416,12 @@ class FrontControllerCore extends Controller $display_tax_label = $this->context->country->display_tax_label; if (isset($cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}) && $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}) { - $infos = Address::getCountryAndState((int)$cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); - $country = new Country((int)$infos['id_country']); - $this->context->country = $country; - if (Validate::isLoadedObject($country)) { - $display_tax_label = $country->display_tax_label; + if ($infos = Address::getCountryAndState((int)$cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')})) { + $country = new Country((int)$infos['id_country']); + $this->context->country = $country; + if (Validate::isLoadedObject($country)) { + $display_tax_label = $country->display_tax_label; + } } } diff --git a/classes/module/Module.php b/classes/module/Module.php index 04c4a2cbe..3ed023503 100644 --- a/classes/module/Module.php +++ b/classes/module/Module.php @@ -2065,8 +2065,8 @@ abstract class ModuleCore public static function getPaymentModules() { $context = Context::getContext(); - if (isset($context->cart)) { - $billing = new Address((int)$context->cart->id_address_invoice); + if (Validate::isLoadedObject($context->country)) { + $id_country = (int)$context->country->id; } $use_groups = Group::isFeatureActive(); @@ -2097,7 +2097,7 @@ abstract class ModuleCore LEFT JOIN `'._DB_PREFIX_.'hook_module` hm ON hm.`id_module` = m.`id_module` LEFT JOIN `'._DB_PREFIX_.'hook` h ON hm.`id_hook` = h.`id_hook` WHERE h.`name` = \''.pSQL($hook_payment).'\' - '.(isset($billing) && $frontend ? 'AND mc.id_country = '.(int)$billing->id_country : '').' + '.(isset($id_country) && $frontend ? 'AND mc.id_country = '.(int)$id_country : '').' AND (SELECT COUNT(*) FROM '._DB_PREFIX_.'module_shop ms WHERE ms.id_module = m.id_module AND ms.id_shop IN('.implode(', ', $list).')) = '.count($list).' AND hm.id_shop IN('.implode(', ', $list).') '.((count($groups) && $frontend && $use_groups) ? 'AND (mg.`id_group` IN ('.implode(', ', $groups).'))' : '').' diff --git a/controllers/front/OrderOpcController.php b/controllers/front/OrderOpcController.php index 17ef02dcb..e74ed1ed7 100644 --- a/controllers/front/OrderOpcController.php +++ b/controllers/front/OrderOpcController.php @@ -735,9 +735,6 @@ class OrderOpcControllerCore extends ParentOrderController } $address_delivery = new Address($this->context->cart->id_address_delivery); $address_invoice = ($this->context->cart->id_address_delivery == $this->context->cart->id_address_invoice ? $address_delivery : new Address($this->context->cart->id_address_invoice)); - if (!$this->context->cart->id_address_delivery || !$this->context->cart->id_address_invoice || !Validate::isLoadedObject($address_delivery) || !Validate::isLoadedObject($address_invoice) || $address_invoice->deleted || $address_delivery->deleted) { - return '

'.Tools::displayError('Error: Please select an address.').'

'; - } if (count($this->context->cart->getDeliveryOptionList()) == 0 && !$this->context->cart->isVirtualCart()) { if ($this->context->cart->isMultiAddressDelivery()) { return '

'.Tools::displayError('Error: None of your chosen carriers deliver to some of the addresses you have selected.').'

'; diff --git a/controllers/front/ParentOrderController.php b/controllers/front/ParentOrderController.php index eb2bf17d7..7bac1b5d9 100644 --- a/controllers/front/ParentOrderController.php +++ b/controllers/front/ParentOrderController.php @@ -399,56 +399,54 @@ class ParentOrderControllerCore extends FrontController Tools::redirect(''); } elseif (!Customer::getAddressesTotalById($this->context->customer->id)) { $multi = (int)Tools::getValue('multi-shipping'); - Tools::redirect('index.php?controller=address&back='.urlencode('order.php?step=1'.($multi ? '&multi-shipping='.$multi : ''))); } $customer = $this->context->customer; if (Validate::isLoadedObject($customer)) { /* Getting customer addresses */ - $customerAddresses = $customer->getAddresses($this->context->language->id); + if ($customerAddresses = $customer->getAddresses($this->context->language->id)) { + // Getting a list of formated address fields with associated values + $formatedAddressFieldsValuesList = array(); - // Getting a list of formated address fields with associated values - $formatedAddressFieldsValuesList = array(); + foreach ($customerAddresses as $i => $address) { + if (!Address::isCountryActiveById((int)$address['id_address'])) { + unset($customerAddresses[$i]); + } + $tmpAddress = new Address($address['id_address']); + $formatedAddressFieldsValuesList[$address['id_address']]['ordered_fields'] = AddressFormat::getOrderedAddressFields($address['id_country']); + $formatedAddressFieldsValuesList[$address['id_address']]['formated_fields_values'] = AddressFormat::getFormattedAddressFieldsValues( + $tmpAddress, + $formatedAddressFieldsValuesList[$address['id_address']]['ordered_fields']); - foreach ($customerAddresses as $i => $address) { - if (!Address::isCountryActiveById((int)$address['id_address'])) { - unset($customerAddresses[$i]); + unset($tmpAddress); } - $tmpAddress = new Address($address['id_address']); - $formatedAddressFieldsValuesList[$address['id_address']]['ordered_fields'] = AddressFormat::getOrderedAddressFields($address['id_country']); - $formatedAddressFieldsValuesList[$address['id_address']]['formated_fields_values'] = AddressFormat::getFormattedAddressFieldsValues( - $tmpAddress, - $formatedAddressFieldsValuesList[$address['id_address']]['ordered_fields']); - unset($tmpAddress); - } + $customerAddresses = array_values($customerAddresses); - $customerAddresses = array_values($customerAddresses); + if (!count($customerAddresses) && !Tools::isSubmit('ajax')) { + $bad_delivery = false; + if (($bad_delivery = (bool)!Address::isCountryActiveById((int)$this->context->cart->id_address_delivery)) || !Address::isCountryActiveById((int)$this->context->cart->id_address_invoice)) { + $params = array(); + if ($this->step) { + $params['step'] = (int)$this->step; + } + if ($multi = (int)Tools::getValue('multi-shipping')) { + $params['multi-shipping'] = $multi; + } + $back_url = $this->context->link->getPageLink('order', true, (int)$this->context->language->id, $params); + + $params = array('back' => $back_url, 'id_address' => ($bad_delivery ? (int)$this->context->cart->id_address_delivery : (int)$this->context->cart->id_address_invoice)); + if ($multi) { + $params['multi-shipping'] = $multi; + } - if (!count($customerAddresses) && !Tools::isSubmit('ajax')) { - $bad_delivery = false; - if (($bad_delivery = (bool)!Address::isCountryActiveById((int)$this->context->cart->id_address_delivery)) || !Address::isCountryActiveById((int)$this->context->cart->id_address_invoice)) { - $params = array(); - if ($this->step) { - $params['step'] = (int)$this->step; } - if ($multi = (int)Tools::getValue('multi-shipping')) { - $params['multi-shipping'] = $multi; - } - $back_url = $this->context->link->getPageLink('order', true, (int)$this->context->language->id, $params); - - $params = array('back' => $back_url, 'id_address' => ($bad_delivery ? (int)$this->context->cart->id_address_delivery : (int)$this->context->cart->id_address_invoice)); - if ($multi) { - $params['multi-shipping'] = $multi; - } - - Tools::redirect($this->context->link->getPageLink('address', true, (int)$this->context->language->id, $params)); } + $this->context->smarty->assign(array( + 'addresses' => $customerAddresses, + 'formatedAddressFieldsValuesList' => $formatedAddressFieldsValuesList) + ); } - $this->context->smarty->assign(array( - 'addresses' => $customerAddresses, - 'formatedAddressFieldsValuesList' => $formatedAddressFieldsValuesList) - ); /* Setting default addresses for cart */ if (count($customerAddresses)) { diff --git a/modules/bankwire/controllers/front/validation.php b/modules/bankwire/controllers/front/validation.php index 5df9b7411..e9cd89014 100644 --- a/modules/bankwire/controllers/front/validation.php +++ b/modules/bankwire/controllers/front/validation.php @@ -35,7 +35,7 @@ class BankwireValidationModuleFrontController extends ModuleFrontController public function postProcess() { $cart = $this->context->cart; - if ($cart->id_customer == 0 || $cart->id_address_delivery == 0 || $cart->id_address_invoice == 0 || !$this->module->active) + if ($cart->id_customer == 0 || !$this->module->active) Tools::redirect('index.php?controller=order&step=1'); // Check that this payment option is still available in case the customer changed his address just before the end of the checkout process diff --git a/modules/cheque/controllers/front/validation.php b/modules/cheque/controllers/front/validation.php index f280abd3f..8c79afea1 100644 --- a/modules/cheque/controllers/front/validation.php +++ b/modules/cheque/controllers/front/validation.php @@ -33,7 +33,7 @@ class ChequeValidationModuleFrontController extends ModuleFrontController { $cart = $this->context->cart; - if ($cart->id_customer == 0 || $cart->id_address_delivery == 0 || $cart->id_address_invoice == 0 || !$this->module->active) + if ($cart->id_customer == 0 || !$this->module->active) Tools::redirect('index.php?controller=order&step=1'); // Check that this payment option is still available in case the customer changed his address just before the end of the checkout process From 8cff333d57c62bb98e99db471ddf0cddd46f927b Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Mon, 20 Nov 2023 16:14:45 +0530 Subject: [PATCH 10/26] hide invoice address panel when customer address was not available while booking --- pdf/invoice.addresses-tab.tpl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pdf/invoice.addresses-tab.tpl b/pdf/invoice.addresses-tab.tpl index 1e17a445e..d4d9f0701 100644 --- a/pdf/invoice.addresses-tab.tpl +++ b/pdf/invoice.addresses-tab.tpl @@ -22,6 +22,7 @@ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA *} +{if $invoice_address}