From 07bd2983d6bda70d8696c15c2d4cdf6184ae4f57 Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Mon, 7 Oct 2024 15:28:09 +0530 Subject: [PATCH 01/36] Added: occupancy in hook 'actionRoomTypeTotalPriceModifier' in functions HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice(), HotelRoomTypeFeaturePricing::getRoomTypeFeaturePricesPerDay() and in the calls. --- classes/Cart.php | 18 +++++++++-- classes/PaymentModule.php | 32 ++++++++++++++----- controllers/admin/AdminOrdersController.php | 19 +++++++++-- controllers/front/ProductController.php | 32 +++++++++++++------ modules/blockcart/blockcart.php | 2 +- .../classes/HotelAdvancedPayment.php | 9 +++++- .../classes/HotelBookingDetail.php | 14 ++++++-- .../classes/HotelRoomTypeFeaturePricing.php | 16 +++++++--- .../AdminHotelRoomsBookingController.php | 11 +++++-- .../classes/WkPaypalCommerceHelper.php | 10 +++++- .../wkhotelfilterblock/wkhotelfilterblock.php | 4 +-- 11 files changed, 132 insertions(+), 35 deletions(-) diff --git a/classes/Cart.php b/classes/Cart.php index 6fef5ee79..ed44f01b6 100644 --- a/classes/Cart.php +++ b/classes/Cart.php @@ -733,11 +733,18 @@ class CartCore extends ObjectModel $totalPriceByProductTaxExcl = 0; $priceDisplay = Group::getPriceDisplayMethod(Group::getCurrent()->id); foreach ($roomTypesByIdProduct as $key => $cartRoomInfo) { + $occupancy = array( + array( + 'adults' => $cartRoomInfo['adults'], + 'children' => $cartRoomInfo['children'], + 'child_ages' => json_decode($cartRoomInfo['child_ages']) + ) + ); $roomTotalPrice = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice( $cartRoomInfo['id_product'], $cartRoomInfo['date_from'], $cartRoomInfo['date_to'], - 0, + $occupancy, Group::getCurrent()->id, $cartRoomInfo['id_cart'], $cartRoomInfo['id_guest'], @@ -1782,12 +1789,19 @@ class CartCore extends ObjectModel $totalPriceByProduct = 0; $priceDisplay = Group::getPriceDisplayMethod(Group::getCurrent()->id); foreach ($roomTypesByIdProduct as $key => $cartRoomInfo) { + $occupancy = array( + array( + 'adults' => $cartRoomInfo['adults'], + 'children' => $cartRoomInfo['children'], + 'child_ages' => json_decode($cartRoomInfo['child_ages']) + ) + ); // get the real price of the room type $roomTotalPrice = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice( $cartRoomInfo['id_product'], $cartRoomInfo['date_from'], $cartRoomInfo['date_to'], - 0, + $occupancy, Group::getCurrent()->id, $cartRoomInfo['id_cart'], $cartRoomInfo['id_guest'], diff --git a/classes/PaymentModule.php b/classes/PaymentModule.php index a41e558b0..1e1326d96 100644 --- a/classes/PaymentModule.php +++ b/classes/PaymentModule.php @@ -808,11 +808,18 @@ abstract class PaymentModuleCore extends Module $objBookingDetail->is_back_order = $objCartBookingData->is_back_order; $objBookingDetail->comment = $objCartBookingData->comment; + $occupancy = array( + array( + 'adults' => $objCartBookingData->adults, + 'children' => $objCartBookingData->children, + 'child_ages' => json_decode($objCartBookingData->child_ages) + ) + ); $total_price = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice( $idProduct, $objCartBookingData->date_from, $objCartBookingData->date_to, - 0, + $occupancy, Group::getCurrent()->id, $objCartBookingData->id_cart, $objCartBookingData->id_guest, @@ -1694,6 +1701,7 @@ abstract class PaymentModuleCore extends Module } else { $cart_bk_data = $obj_htl_bk_dtl->getOnlyOrderBookingData($order->id, $customer->id_guest, $type_value['product_id']); } + if ($cart_bk_data) { $rm_dtl = $obj_rm_type->getRoomTypeInfoByIdProduct($type_value['product_id']); @@ -1714,11 +1722,20 @@ abstract class PaymentModuleCore extends Module $cart_htl_data[$type_key]['date_diff'][$date_join]['adults'] += $data_v['adults']; $cart_htl_data[$type_key]['date_diff'][$date_join]['children'] += $data_v['children']; + $occupancy = array( + array( + 'adults' => $data_v['adults'], + 'children' => $data_v['children'], + 'child_ages' => json_decode($data_v['child_ages']) + ) + ); - - - $roomTypeDateRangePrice = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice($type_value['id_product'], $data_v['date_from'], $data_v['date_to']); - + $roomTypeDateRangePrice = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice( + $type_value['id_product'], + $data_v['date_from'], + $data_v['date_to'], + $occupancy + ); $cart_htl_data[$type_key]['date_diff'][$date_join]['amount'] = $roomTypeDateRangePrice['total_price_tax_incl']*$vart_quant; $cart_htl_data[$type_key]['date_diff'][$date_join]['paid_unit_price_tax_incl'] = $data_v['total_price_tax_incl']/$num_days; @@ -1739,9 +1756,7 @@ abstract class PaymentModuleCore extends Module $cart_htl_data[$type_key]['date_diff'][$date_join]['adults'] = $data_v['adults']; $cart_htl_data[$type_key]['date_diff'][$date_join]['children'] = $data_v['children']; - - - // extra demands prices + // extra demands prices $cart_htl_data[$type_key]['date_diff'][$date_join]['extra_demands'] = $objBookingDemand->getRoomTypeBookingExtraDemands( $order->id, $type_value['product_id'], @@ -1825,6 +1840,7 @@ abstract class PaymentModuleCore extends Module } $result['cart_htl_data'] = $cart_htl_data; } + return $result; } } diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index d2dc4d1fe..57395c897 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -4536,11 +4536,19 @@ class AdminOrdersControllerCore extends AdminController $objBookingDetail->children = $objCartBookingData->children; $objBookingDetail->child_ages = $objCartBookingData->child_ages; + $occupancy = array( + array( + 'adults' => $objCartBookingData->adults, + 'children' => $objCartBookingData->children, + 'child_ages' => json_decode($objCartBookingData->child_ages) + ) + ); + $total_price = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice( $idProduct, $objCartBookingData->date_from, $objCartBookingData->date_to, - 0, + $occupancy, Group::getCurrent()->id, $this->context->cart->id, $this->context->cookie->id_guest, @@ -4781,7 +4789,7 @@ class AdminOrdersControllerCore extends AdminController $id_product, $new_date_from, $new_date_to, - 0, + array($occupancy), Group::getCurrent()->id, $cart->id, $cart->id_guest, @@ -7202,6 +7210,13 @@ class AdminOrdersControllerCore extends AdminController // set context currency So that we can get prices in the order currency $objOrder = new Order($objHotelBooking->id_order); $this->context->currency = new Currency($objOrder->id_currency); + $occupancy = array( + array( + 'adults' => $objHotelBooking->adults, + 'children' => $objHotelBooking->children, + 'child_ages' => json_decode($objHotelBooking->child_ages) + ) + ); $newRoomTotalPrice = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice( $idNewRoomType, $objHotelBooking->date_from, diff --git a/controllers/front/ProductController.php b/controllers/front/ProductController.php index d9222203d..105d9e5b0 100644 --- a/controllers/front/ProductController.php +++ b/controllers/front/ProductController.php @@ -419,7 +419,7 @@ class ProductControllerCore extends FrontController ) ); - $occupancy_value = array(); + $occupancy_value = Tools::getValue('occupancy', array()); if (Configuration::get('PS_FRONT_ROOM_UNIT_SELECTION_TYPE') == HotelBookingDetail::PS_ROOM_UNIT_SELECTION_TYPE_QUANTITY) { $occupancy_value = 1; } else { @@ -450,10 +450,10 @@ class ProductControllerCore extends FrontController // product price after imposing feature prices... if ($useTax) { $priceProduct = Product::getPriceStatic($this->product->id, true); - $feature_price = HotelRoomTypeFeaturePricing::getRoomTypeFeaturePricesPerDay($this->product->id, $date_from, $date_to, true); + $feature_price = HotelRoomTypeFeaturePricing::getRoomTypeFeaturePricesPerDay($this->product->id, $date_from, $date_to, true, 0, 0, 0, 0, 1, 1, $occupancy_value); } else { $priceProduct = Product::getPriceStatic($this->product->id, false); - $feature_price = HotelRoomTypeFeaturePricing::getRoomTypeFeaturePricesPerDay($this->product->id, $date_from, $date_to, false); + $feature_price = HotelRoomTypeFeaturePricing::getRoomTypeFeaturePricesPerDay($this->product->id, $date_from, $date_to, false, 0, 0, 0, 0, 1, 1, $occupancy_value); } $productPriceWithoutReduction = $this->product->getPriceWithoutReduct(!$useTax); $feature_price_diff = (float)($productPriceWithoutReduction - $feature_price); @@ -649,7 +649,7 @@ class ProductControllerCore extends FrontController $idProduct, $dateFrom, $dateTo, - 0, + $occupancy, 0, 0, 0, @@ -660,7 +660,8 @@ class ProductControllerCore extends FrontController $roomTypeDateRangePrice = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice( $idProduct, $dateFrom, - $dateTo + $dateTo, + $occupancy ); $featurePrice = 0; @@ -669,7 +670,14 @@ class ProductControllerCore extends FrontController $idProduct, $dateFrom, $dateTo, - true + true, + 0, + 0, + 0, + 0, + 1, + 1, + $occupancy ); $roomTypeDateRangePrice = $roomTypeDateRangePrice['total_price_tax_incl']; $totalPriceWithoutDiscount = $priceWithoutDiscount['total_price_tax_incl']; @@ -679,14 +687,20 @@ class ProductControllerCore extends FrontController $idProduct, $dateFrom, $dateTo, - false + false, + 0, + 0, + 0, + 0, + 1, + 1, + $occupancy ); $roomTypeDateRangePrice = $roomTypeDateRangePrice['total_price_tax_excl']; $totalPriceWithoutDiscount = $priceWithoutDiscount['total_price_tax_excl']; } - $totalPriceWithoutDiscount *= $quantity; - $totalRoomPrice = $roomTypeDateRangePrice * $quantity; + $totalRoomPrice = $roomTypeDateRangePrice; // calculate demand price now $demandsPricePerRoom = 0; $roomTypeDemands = $objHRTDemand->getRoomTypeDemands($idProduct); diff --git a/modules/blockcart/blockcart.php b/modules/blockcart/blockcart.php index eb4edfc71..deb0ab0d8 100644 --- a/modules/blockcart/blockcart.php +++ b/modules/blockcart/blockcart.php @@ -241,7 +241,7 @@ class Blockcart extends Module $objProduct->id, $addedProduct['date_from'], $addedProduct['date_to'], - $addedProduct['req_rm'] + $addedProduct['occupancy'] ); if ($priceDisplayMethod == PS_TAX_EXC) { $addedProduct['price'] = Tools::displayPrice($price['total_price_tax_excl']); diff --git a/modules/hotelreservationsystem/classes/HotelAdvancedPayment.php b/modules/hotelreservationsystem/classes/HotelAdvancedPayment.php index 076663010..b2702b310 100644 --- a/modules/hotelreservationsystem/classes/HotelAdvancedPayment.php +++ b/modules/hotelreservationsystem/classes/HotelAdvancedPayment.php @@ -105,11 +105,18 @@ class HotelAdvancedPayment extends ObjectModel $objHtlCartBook = new HotelCartBookingData(); if ($roomTypesByIdProduct = $objHtlCartBook->getCartInfoIdCartIdProduct((int) $idCart, (int)$idProduct)) { foreach ($roomTypesByIdProduct as $cartRoomInfo) { + $occupancy = array( + array( + 'adults' => $cartRoomInfo['adults'], + 'children' => $cartRoomInfo['children'], + 'child_ages' => json_decode($cartRoomInfo['child_ages']) + ) + ); $roomTotalPrices = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice( $cartRoomInfo['id_product'], $cartRoomInfo['date_from'], $cartRoomInfo['date_to'], - 0, + $occupancy, 0, $idCart, $cartRoomInfo['id_guest'], diff --git a/modules/hotelreservationsystem/classes/HotelBookingDetail.php b/modules/hotelreservationsystem/classes/HotelBookingDetail.php index 5686dad65..9e830293a 100644 --- a/modules/hotelreservationsystem/classes/HotelBookingDetail.php +++ b/modules/hotelreservationsystem/classes/HotelBookingDetail.php @@ -1699,14 +1699,14 @@ class HotelBookingDetail extends ObjectModel continue; } } - $productFeaturePrice = HotelRoomTypeFeaturePricing::getRoomTypeFeaturePricesPerDay($value['id_product'], $date_from, $date_to, self::useTax()); + $productFeaturePrice = HotelRoomTypeFeaturePricing::getRoomTypeFeaturePricesPerDay($value['id_product'], $date_from, $date_to, self::useTax(), 0, 0, 0, 0, 1, 1, $bookingParams['occupancy']); if (!empty($price) && ($price['from'] > $productFeaturePrice || $price['to'] < $productFeaturePrice)) { unset($bookingData['rm_data'][$key]); continue; } if (count($value['data']['available'])) { $prod_price = Product::getPriceStatic($value['id_product'], self::useTax()); - $productPriceWithoutReduction = HotelRoomTypeFeaturePricing::getRoomTypeFeaturePricesPerDay($value['id_product'], $date_from, $date_to, self::useTax(), 0, 0, 0, 0, 1, 0); + $productPriceWithoutReduction = HotelRoomTypeFeaturePricing::getRoomTypeFeaturePricesPerDay($value['id_product'], $date_from, $date_to, self::useTax(), 0, 0, 0, 0, 1, 0, $bookingParams['occupancy']); $cover_image_arr = Product::getCover($value['id_product']); if (!empty($cover_image_arr)) { $cover_img = $this->context->link->getImageLink($value['link_rewrite'], $value['id_product'].'-'.$cover_image_arr['id_image'], 'home_default'); @@ -2061,11 +2061,19 @@ class HotelBookingDetail extends ObjectModel $objBookingDetail->children = $objCartBookingData->children; $objBookingDetail->child_ages = $objCartBookingData->child_ages; + $occupancy = array( + array( + 'adults' => $objCartBookingData->adults, + 'children' => $objCartBookingData->children, + 'child_ages' => json_decode($objCartBookingData->child_ages) + ) + ); + $totalRoomTypePrice = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice( $idNewRoomType, $objCartBookingData->date_from, $objCartBookingData->date_to, - 0, + $occupancy, Group::getCurrent()->id, $this->context->cart->id, $this->context->cookie->id_guest, diff --git a/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php b/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php index fd1ef9d93..4e6267382 100644 --- a/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php +++ b/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php @@ -638,7 +638,7 @@ class HotelRoomTypeFeaturePricing extends ObjectModel $id_product, $date_from, $date_to, - $quantity = 0, + $occupancy = null, $id_group = 0, $id_cart = 0, $id_guest = 0, @@ -659,6 +659,12 @@ class HotelRoomTypeFeaturePricing extends ObjectModel $taxRate = 0; } + if (is_array($occupancy) && count($occupancy)) { + $quantity = count($occupancy); + } else { + $quantity = 1; + } + // Initializations if (!$id_group) { $id_group = (int)Group::getCurrent()->id; @@ -728,7 +734,8 @@ class HotelRoomTypeFeaturePricing extends ObjectModel 'id_guest' => $id_guest, 'id_group' => $id_group, 'use_reduc' => $use_reduc, - 'tax_rate' => $taxRate + 'tax_rate' => $taxRate, + 'occupancy' => $occupancy ) ); if ($with_auto_room_services) { @@ -807,7 +814,8 @@ class HotelRoomTypeFeaturePricing extends ObjectModel $id_guest = 0, $id_room = 0, $with_auto_room_services = 1, - $use_reduc = 1 + $use_reduc = 1, + $occupancy = array() ) { $dateFrom = date('Y-m-d H:i:s', strtotime($date_from)); $dateTo = date('Y-m-d H:i:s', strtotime($date_to)); @@ -815,7 +823,7 @@ class HotelRoomTypeFeaturePricing extends ObjectModel $id_product, $dateFrom, $dateTo, - 0, + $occupancy, $id_group, $id_cart, $id_guest, diff --git a/modules/hotelreservationsystem/controllers/admin/AdminHotelRoomsBookingController.php b/modules/hotelreservationsystem/controllers/admin/AdminHotelRoomsBookingController.php index 04d0dc8a6..b13a3037b 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminHotelRoomsBookingController.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminHotelRoomsBookingController.php @@ -198,7 +198,7 @@ class AdminHotelRoomsBookingController extends ModuleAdminController $this->errors[] = $this->l('Selected room is not available for reallocation.'); } elseif (!in_array($idRoomToReallocate, array_column($availableRooms, 'id_room'))) { $this->errors[] = $this->l('Selected room is not available for reallocation.'); - } elseif (!Validate::isFloat($priceDiff)) { + } elseif (!Validate::isPrice($priceDiff)) { $this->errors[] = $this->l('Invalid price difference of the room types.'); } } else { @@ -874,11 +874,18 @@ class AdminHotelRoomsBookingController extends ModuleAdminController // if room is changing in the reallocation if ($objHotelBooking->id_product != $idNewRoomType) { $result['has_room_type_change'] = 1; + $occupancy = array( + array( + 'adults' => $objHotelBooking->adults, + 'children' => $objHotelBooking->children, + 'child_ages' => json_decode($objHotelBooking->child_ages) + ) + ); $newRoomTotalPrice = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice( $idNewRoomType, $objHotelBooking->date_from, $objHotelBooking->date_to, - 0, + $occupancy, 0, 0, 0, diff --git a/modules/qlopaypalcommerce/classes/WkPaypalCommerceHelper.php b/modules/qlopaypalcommerce/classes/WkPaypalCommerceHelper.php index 46e32a741..389bd3107 100644 --- a/modules/qlopaypalcommerce/classes/WkPaypalCommerceHelper.php +++ b/modules/qlopaypalcommerce/classes/WkPaypalCommerceHelper.php @@ -351,10 +351,18 @@ class WkPaypalCommerceHelper $idProduct )) { foreach ($roomTypeBookings as $cartRoomInfo) { + $occupancy = array( + array( + 'adults' => $cartRoomInfo['adults'], + 'children' => $cartRoomInfo['children'], + 'child_ages' => json_decode($cartRoomInfo['child_ages']) + ) + ); $roomTotalPrice = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice( $idProduct, $cartRoomInfo['date_from'], - $cartRoomInfo['date_to'] + $cartRoomInfo['date_to'], + $occupancy ); $roomTotalPriceTE = $roomTotalPrice['total_price_tax_excl']; $roomTotalPriceTI = $roomTotalPrice['total_price_tax_incl']; diff --git a/modules/wkhotelfilterblock/wkhotelfilterblock.php b/modules/wkhotelfilterblock/wkhotelfilterblock.php index c4208f16b..98dab011d 100644 --- a/modules/wkhotelfilterblock/wkhotelfilterblock.php +++ b/modules/wkhotelfilterblock/wkhotelfilterblock.php @@ -195,16 +195,16 @@ class wkhotelfilterblock extends Module $obj_rm_type = new HotelRoomType(); $room_types = $obj_rm_type->getIdProductByHotelId($id_hotel, 0, 1, 1); + $occupancy = Tools::getValue('occupancy'); $prod_price = array(); if ($room_types) { foreach ($room_types as $key => $value) { - $prod_price[] = HotelRoomTypeFeaturePricing::getRoomTypeFeaturePricesPerDay($value['id_product'], $date_from, $date_to, HotelBookingDetail::useTax()); + $prod_price[] = HotelRoomTypeFeaturePricing::getRoomTypeFeaturePricesPerDay($value['id_product'], $date_from, $date_to, HotelBookingDetail::useTax(), 0, 0, 0, 0, 1, 1, $occupancy); } } // Create URL of category - $occupancy = Tools::getValue('occupancy'); $urlData = array ( 'date_from' => $date_from, 'date_to' => $date_to, From f861e10115160c768c6bc65bd71adfac9e12970a Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Fri, 8 Nov 2024 14:50:41 +0530 Subject: [PATCH 02/36] show correct pricing on checkout page --- controllers/admin/AdminOrdersController.php | 2 +- .../classes/HotelCartBookingData.php | 20 ++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index 80a65ee7d..5eb4c8496 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -4826,7 +4826,7 @@ class AdminOrdersControllerCore extends AdminController $id_product, $new_date_from, $new_date_to, - array($occupancy), + 0, Group::getCurrent()->id, $cart->id, $cart->id_guest, diff --git a/modules/hotelreservationsystem/classes/HotelCartBookingData.php b/modules/hotelreservationsystem/classes/HotelCartBookingData.php index 0cd9c678d..3038bb9b3 100644 --- a/modules/hotelreservationsystem/classes/HotelCartBookingData.php +++ b/modules/hotelreservationsystem/classes/HotelCartBookingData.php @@ -1557,7 +1557,13 @@ class HotelCartBookingData extends ObjectModel 1 ); $totalAdditionalServicePrice = $demandPrice + $serviceProductPrice; - + $occupancy = array( + array( + 'adults' => $data_v['adults'], + 'children' => $data_v['children'], + 'child_ages' => json_decode($data_v['child_ages']) + ) + ); if (isset($cartHotelData[$prodKey]['date_diff'][$dateJoin])) { $numDays = $objBookingDetail->getNumberOfDays($data_v['date_from'], $data_v['date_to']); $cartHotelData[$prodKey]['date_diff'][$dateJoin]['demand_price'] += $totalAdditionalServicePrice; @@ -1573,7 +1579,7 @@ class HotelCartBookingData extends ObjectModel $product['id_product'], $data_v['date_from'], $data_v['date_to'], - 0, + $occupancy, 0, $context->cart->id, $context->cart->id_guest, @@ -1583,7 +1589,7 @@ class HotelCartBookingData extends ObjectModel $product['id_product'], $data_v['date_from'], $data_v['date_to'], - 0, + $occupancy, 0, $context->cart->id, $context->cart->id_guest, @@ -1594,7 +1600,7 @@ class HotelCartBookingData extends ObjectModel $product['id_product'], $data_v['date_from'], $data_v['date_to'], - 0, + $occupancy, 0, $context->cart->id, $context->cart->id_guest, @@ -1635,7 +1641,7 @@ class HotelCartBookingData extends ObjectModel $product['id_product'], $data_v['date_from'], $data_v['date_to'], - 0, + $occupancy, 0, $context->cart->id, $context->cart->id_guest, @@ -1645,7 +1651,7 @@ class HotelCartBookingData extends ObjectModel $product['id_product'], $data_v['date_from'], $data_v['date_to'], - 0, + $occupancy, 0, $context->cart->id, $context->cart->id_guest, @@ -1656,7 +1662,7 @@ class HotelCartBookingData extends ObjectModel $product['id_product'], $data_v['date_from'], $data_v['date_to'], - 0, + $occupancy, 0, $context->cart->id, $context->cart->id_guest, From cd18dd90af15b29e8d9a055f2c9cdc557597d993 Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Mon, 11 Nov 2024 13:09:58 +0530 Subject: [PATCH 03/36] Fixed incorrect price in admin book now page --- .../classes/HotelCartBookingData.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/modules/hotelreservationsystem/classes/HotelCartBookingData.php b/modules/hotelreservationsystem/classes/HotelCartBookingData.php index 3038bb9b3..3ee7aad41 100644 --- a/modules/hotelreservationsystem/classes/HotelCartBookingData.php +++ b/modules/hotelreservationsystem/classes/HotelCartBookingData.php @@ -1114,7 +1114,13 @@ class HotelCartBookingData extends ObjectModel $cart_detail_data[$key]['date_to'] = $value['date_to']; $cart_detail_data[$key]['child_ages'] = json_decode($value['child_ages']); - + $occupancy = array( + array( + 'adults' => $value['adults'], + 'children' => $value['children'], + 'child_ages' => json_decode($value['child_ages']) + ) + ); $unit_price = Product::getPriceStatic($value['id_product'], true); $unit_price_tax_excl = Product::getPriceStatic($value['id_product'], false); $productPriceWithoutReduction = $productObj->getPriceWithoutReduct(false); @@ -1127,7 +1133,9 @@ class HotelCartBookingData extends ObjectModel $id_cart, $value['id_guest'], $value['id_room'], - 0 + 0, + 1, + $occupancy ); $feature_price_tax_excl = HotelRoomTypeFeaturePricing::getRoomTypeFeaturePricesPerDay( $value['id_product'], @@ -1138,7 +1146,9 @@ class HotelCartBookingData extends ObjectModel $id_cart, $value['id_guest'], $value['id_room'], - 0 + 0, + 1, + $occupancy ); $feature_price_diff = (float)($productPriceWithoutReduction - $feature_price); $cart_detail_data[$key]['product_price'] = $unit_price; @@ -1240,7 +1250,7 @@ class HotelCartBookingData extends ObjectModel $value['id_product'], $value['date_from'], $value['date_to'], - 0, + $occupancy, 0, $id_cart, $value['id_guest'], From 5f64bc6a96407db27be7f3f751d844cad0aabbb7 Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Fri, 15 Nov 2024 16:25:33 +0530 Subject: [PATCH 04/36] added feature to update ajax data using hook --- classes/controller/Controller.php | 4 ++-- controllers/admin/AdminOrdersController.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/classes/controller/Controller.php b/classes/controller/Controller.php index e9628c6a8..8908d6159 100644 --- a/classes/controller/Controller.php +++ b/classes/controller/Controller.php @@ -649,8 +649,8 @@ abstract class ControllerCore $method = $bt[1]['function']; } - Hook::exec('actionBeforeAjaxDie', array('controller' => $controller, 'method' => $method, 'value' => $value)); - Hook::exec('actionBeforeAjaxDie'.$controller.$method, array('value' => $value)); + Hook::exec('actionBeforeAjaxDie', array('controller' => $controller, 'method' => $method, 'value' => &$value)); + Hook::exec('actionBeforeAjaxDie'.$controller.$method, array('value' => &$value)); die($value); } diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index 5eb4c8496..feca42832 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -3501,7 +3501,7 @@ class AdminOrdersControllerCore extends AdminController } } } - $this->content = json_encode($to_return); + $this->ajaxDie(json_encode($to_return)); } // public function ajaxProcessSearchProducts() From 4d739bf63dc27a054e7e5378bbb958f8628c2878 Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Fri, 13 Dec 2024 15:26:05 +0530 Subject: [PATCH 05/36] fixed price issue when booking is donewithout occupancy --- .../classes/HotelRoomTypeFeaturePricing.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php b/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php index 4e6267382..97b60fcc5 100644 --- a/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php +++ b/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php @@ -662,7 +662,7 @@ class HotelRoomTypeFeaturePricing extends ObjectModel if (is_array($occupancy) && count($occupancy)) { $quantity = count($occupancy); } else { - $quantity = 1; + $quantity = $occupancy; } // Initializations From 67daa65ace1ba8feb3f7788115835e0a5b9158fb Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Tue, 21 Jan 2025 17:07:05 +0530 Subject: [PATCH 06/36] Added: feature to create Advanced price rules for multiple room types at once --- .../admin/AdminHotelFeaturePricesSettings.php | 230 +++++++++++++++++- .../helpers/form/form.tpl | 62 +++-- 2 files changed, 261 insertions(+), 31 deletions(-) diff --git a/modules/hotelreservationsystem/controllers/admin/AdminHotelFeaturePricesSettings.php b/modules/hotelreservationsystem/controllers/admin/AdminHotelFeaturePricesSettings.php index 0652f90c7..e05c8b43f 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminHotelFeaturePricesSettings.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminHotelFeaturePricesSettings.php @@ -189,8 +189,7 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController )) { - $this->errors[] = $this->l('An advanced price rule already exists in which some dates are common with this - plan. Please select a different date range.'); + $this->errors[] = $this->l('An advanced price rule already exists in which some dates are common with this plan. Please select a different date range.'); return ; } } @@ -202,17 +201,52 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController public function initToolbar() { parent::initToolbar(); - $this->page_header_toolbar_btn['new'] = array( - 'href' => self::$currentIndex.'&add'.$this->table.'&token='.$this->token, - 'desc' => $this->l('Add new rule'), - 'imgclass' => 'new' - ); + if (empty($this->display) || $this->display == 'list') { + $this->page_header_toolbar_btn['bulk_add'] = array( + 'href' => self::$currentIndex.'&add'.$this->table.'&bulkAdd'.$this->table.'=1&token='.$this->token, + 'desc' => $this->l('Bulk create rules'), + 'imgclass' => 'new' + ); + $this->page_header_toolbar_btn['new'] = array( + 'href' => self::$currentIndex.'&add'.$this->table.'&token='.$this->token, + 'desc' => $this->l('Add new rule'), + 'imgclass' => 'new' + ); + } + $this->toolbar_btn = array(); + } + + public function initToolbarTitle() + { + parent::initToolbarTitle(); + if (Tools::getValue('bulkAdd'.$this->table)) { + $this->toolbar_title[] = $this->l('Bulk Create', null, null, false); + $this->addMetaTitle($this->l('Bulk Create', null, null, false)); + } + } + + public function initProcess() + { + parent::initProcess(); + if (Tools::getValue('bulkAdd'.$this->table)) { + self::$currentIndex = self::$currentIndex.'&bulkAdd'.$this->table.'=1'; + } + + if (Tools::isSubmit('submitBulkAdd'.$this->table)) { + if ($this->tabAccess['add'] === '1') { + $this->action = 'bulkSave'; + $this->display = 'list'; + } else { + $this->errors[] = Tools::displayError('You do not have permission to add this.'); + } + } } public function renderList() { $this->addRowAction('edit'); $this->addRowAction('delete'); + return parent::renderList(); } @@ -246,10 +280,28 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController $smartyVars['feature_price_groups'] = $objFeaturePrice->getGroups($idFeaturePrice); } + $smartyVars['defaultcurrency_sign'] = $currencySign; $smartyVars['date_from'] = $dateFrom; $smartyVars['date_to'] = $dateTo; $smartyVars['groups'] = Group::getGroups($this->context->language->id); + $smartyVars['bulk_add'] = Tools::getValue('bulkAdd'.$this->table); + + if ($smartyVars['bulk_add']) { + $tree = new HelperTree('hotels-tree'); + $tree->setData(HotelHelper::generateTreeData([ + 'rootNode' => HotelHelper::NODE_HOTEL, + 'leafNode' => HotelHelper::NODE_ROOM_TYPE, + 'selectedElements' => array( + 'room_type' => Tools::getValue('room_type_box', array()) + ) + ])) + ->setUseCheckBox(true) + ->setAutoSelectChildren(true) + ->setUseBulkActions(true) + ->setUseSearch(true); + $smartyVars['hotel_tree'] = $tree->render(); + } $this->context->smarty->assign($smartyVars); $this->fields_form = array( 'submit' => array( @@ -374,8 +426,7 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController ); } if ($isPlanTypeExists) { - $this->errors[] = $this->l('An advanced price rule already exists in which some dates are common with this - plan. Please select a different date range.'); + $this->errors[] = $this->l('An advanced price rule already exists in which some dates are common with this plan. Please select a different date range.'); } else { if (!$roomTypeId) { $this->errors[] = $this->l('Room is not selected. Please try again.'); @@ -497,6 +548,167 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController } } + public function processBulkSave() + { + $enableFeaturePrice = Tools::getValue('enable_feature_price'); + $roomTypeIds = Tools::getValue('room_type_box'); + $dateFrom = Tools::getValue('date_from'); + $dateTo = Tools::getValue('date_to'); + $isSpecialDaysExists = Tools::getValue('is_special_days_exists'); + $specialDays = Tools::getValue('special_days'); + $priceImpactWay = Tools::getValue('price_impact_way'); + $priceImpactType = Tools::getValue('price_impact_type'); + $impactValue = Tools::getValue('impact_value'); + $dateSelectionType = Tools::getValue('date_selection_type'); + $specificDate = date('Y-m-d', strtotime(Tools::getValue('specific_date'))); + $groups = Tools::getValue('groupBox'); + $jsonSpecialDays = json_encode($specialDays); + $defaultLangId = Configuration::get('PS_LANG_DEFAULT'); + + $objFeaturePricing = new HotelRoomTypeFeaturePricing(); + + if ($priceImpactWay == HotelRoomTypeFeaturePricing::IMPACT_WAY_FIX_PRICE) { + $priceImpactType = HotelRoomTypeFeaturePricing::IMPACT_TYPE_FIXED_PRICE; + } + + $languages = Language::getLanguages(false); + $objDefaultLang = new language($defaultLangId); + $featurePricingName = array(); + + if ($dateSelectionType == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_SPECIFIC) { + $dateFrom = $specificDate; + $dateTo = date('Y-m-d', strtotime("+1 day", strtotime($specificDate))); + } + $isPlanTypeExists = 0; + + if (empty($roomTypeIds)) { + $this->errors[] = $this->l('Please select at least one room type for bulk creation.'); + } else { + if ($isSpecialDaysExists && $jsonSpecialDays == 'false') { + $this->errors[] = $this->l('Please select at least one day for week days restriction.'); + } else { + foreach ($roomTypeIds as $roomTypeId) { + $isPlanTypeExists = $this->validateExistingFeaturePrice( + $dateSelectionType, + $roomTypeId, + $dateFrom, + $dateTo, + $groups, + 0, + $isSpecialDaysExists, + $jsonSpecialDays + ); + + if ($isPlanTypeExists) { + $objProduct = new Product((int) $roomTypeId, false, $this->context->language->id); + $this->errors[] = sprintf($this->l('An advanced price rule already exists for "%s" for the selected date range. Please select a different date range.'), $objProduct->name); + } + } + } + + if (!Tools::getValue('feature_price_name_'.$defaultLangId)) { + $this->errors[] = sprintf( + $this->l('Advanced price rule name is required at least in %s'), + $objDefaultLang->name + ); + } + + $validateRules = call_user_func( + array('HotelRoomTypeFeaturePricing', 'getValidationRules'), + 'HotelRoomTypeFeaturePricing' + ); + foreach ($languages as $language) { + if (!Validate::isCatalogName(Tools::getValue('feature_price_name_'.$language['id_lang']))) { + $this->errors[] = $this->l('Advanced price rule name is invalid in ').$language['name']; + } elseif (Tools::strlen(Tools::getValue('feature_price_name_'.$language['id_lang'])) > $validateRules['sizeLang']['feature_price_name']) { + sprintf( + $this->l('Advanced price rule Name field is too long (%2$d chars max).'), + $validateRules['sizeLang']['feature_price_name'] + ); + } + + if (Tools::getValue('feature_price_name_'.$language['id_lang'])) { + $featurePricingName[$language['id_lang']] = Tools::getValue('feature_price_name_'.$language['id_lang']); + } else { + $featurePricingName[$language['id_lang']] = Tools::getValue('feature_price_name_'.$defaultLangId); + } + } + + if ($dateSelectionType == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_RANGE) { + if ($dateFrom == '') { + $this->errors[] = $this->l('Please choose Date from for the advanced price rule.'); + } + if ($dateTo == '') { + $this->errors[] = $this->l('Please choose Date to for the advanced price rule.'); + } + $dateFrom = date('Y-m-d', strtotime($dateFrom)); + $dateTo = date('Y-m-d', strtotime($dateTo)); + if (!Validate::isDate($dateFrom)) { + $this->errors[] = $this->l('Invalid Date From.'); + } + if (!Validate::isDate($dateTo)) { + $this->errors[] = $this->l('Invalid Date To.'); + } + if ($dateTo < $dateFrom) { + $this->errors[] = $this->l('Date To must be a date after Date From.'); + } + if ($isSpecialDaysExists) { + if (!isset($specialDays) || !$specialDays) { + $this->errors[] = $this->l('Please select at least one day for week days restriction.'); + } + } + } else { + if ($specificDate == '') { + $this->errors[] = $this->l('Please choose Date from for the advanced price rule.'); + } + $specificDate = date('Y-m-d', strtotime($specificDate)); + if (!Validate::isDate($specificDate)) { + $this->errors[] = $this->l('Invalid Date From.'); + } + } + + if (!$impactValue) { + $this->errors[] = $this->l('Please enter a valid impact value.'); + } else { + if (!Validate::isPrice($impactValue)) { + $this->errors[] = $this->l('Invalid value of impact value.'); + } + } + + if (!(bool)$groups) { + $this->errors[] = $this->l('Please select at least one group for the group access'); + } + + if (empty($this->errors)) { + $res = true; + foreach ($roomTypeIds as $roomTypeId) { + $objFeaturePricing = new HotelRoomTypeFeaturePricing(); + $objFeaturePricing->id_product = $roomTypeId; + $objFeaturePricing->feature_price_name = $featurePricingName; + $objFeaturePricing->date_selection_type = $dateSelectionType; + $objFeaturePricing->date_from = $dateFrom; + $objFeaturePricing->date_to = $dateTo; + $objFeaturePricing->impact_way = $priceImpactWay; + $objFeaturePricing->is_special_days_exists = $isSpecialDaysExists; + $objFeaturePricing->special_days = $jsonSpecialDays; + $objFeaturePricing->impact_type = $priceImpactType; + $objFeaturePricing->impact_value = $impactValue; + $objFeaturePricing->active = $enableFeaturePrice; + + // set the values of the groups for this feature price + $objFeaturePricing->groupBox = $groups; + $res &= $objFeaturePricing->save(); + } + + Tools::redirectAdmin(self::$currentIndex.'&conf=4&token='.$this->token); + } + } + + if (!empty($this->errors)) { + $this->display = 'add'; + } + } + public function ajaxProcessSearchProductByName() { $productName = Tools::getValue('room_type_name'); diff --git a/modules/hotelreservationsystem/views/templates/admin/hotel_feature_prices_settings/helpers/form/form.tpl b/modules/hotelreservationsystem/views/templates/admin/hotel_feature_prices_settings/helpers/form/form.tpl index d1191997d..e40b26f10 100644 --- a/modules/hotelreservationsystem/views/templates/admin/hotel_feature_prices_settings/helpers/form/form.tpl +++ b/modules/hotelreservationsystem/views/templates/admin/hotel_feature_prices_settings/helpers/form/form.tpl @@ -19,7 +19,9 @@
- {if isset($edit)} + {if isset($bulk_add) && $bulk_add} +  {l s='Bulk Create Advanced Price Rule' mod='hotelreservationsystem'} + {else if isset($edit)}  {l s='Edit Advanced Price Rule' mod='hotelreservationsystem'} {else}  {l s='Add New Advanced Price Rule' mod='hotelreservationsystem'} @@ -57,23 +59,33 @@ {/if}
-
- -
- - - - -
- {l s='Enter room type name and select the room for which you are going to create this advanced price rule.' mod='hotelreservationsystem'} + {if isset($bulk_add) && $bulk_add} +
+ +
+ {$hotel_tree}
- -
+ {else} +
+ +
+ + + + +
+ {l s='Enter room type name and select the room for which you are going to create this advanced price rule.' mod='hotelreservationsystem'} +
+
+
+ {/if}
From 144cbcee7cfdf2a7f2d9d15194b09cc3dfee28cc Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Mon, 27 Jan 2025 12:30:47 +0530 Subject: [PATCH 07/36] Added new columns in the exported data for customer, order and room type --- .../admin/AdminCustomersController.php | 34 ++++- controllers/admin/AdminOrdersController.php | 120 +++++++++++++++++- controllers/admin/AdminProductsController.php | 58 ++++++++- 3 files changed, 199 insertions(+), 13 deletions(-) diff --git a/controllers/admin/AdminCustomersController.php b/controllers/admin/AdminCustomersController.php index 38d0d82c9..ebfef0125 100644 --- a/controllers/admin/AdminCustomersController.php +++ b/controllers/admin/AdminCustomersController.php @@ -80,6 +80,7 @@ class AdminCustomersControllerCore extends AdminController $this->_join = 'LEFT JOIN '._DB_PREFIX_.'gender_lang gl ON (a.id_gender = gl.id_gender AND gl.id_lang = '.(int)$this->context->language->id.')'; $this->_join .= ' LEFT JOIN '._DB_PREFIX_.'group_lang grl ON (a.id_default_group = grl.id_group AND grl.id_lang = '.(int)$this->context->language->id.')'; $this->_join .= ' LEFT JOIN '._DB_PREFIX_.'orders o ON (a.id_customer = o.id_customer)'; + $this->_join .= ' LEFT JOIN `'._DB_PREFIX_.'cart_customer_guest_detail` cgd ON cgd.`email` = a.`email` AND cgd.`id_cart` = 0 '; $this->_group = 'GROUP BY a.`id_customer`'; $this->fields_list = array( @@ -97,13 +98,16 @@ class AdminCustomersControllerCore extends AdminController 'order_key' => 'gl!name' ), 'firstname' => array( - 'title' => $this->l('First name') + 'title' => $this->l('First name'), + 'filter_key' => 'a!firstname' ), 'lastname' => array( - 'title' => $this->l('Last name') + 'title' => $this->l('Last name'), + 'filter_key' => 'a!lastname' ), 'email' => array( - 'title' => $this->l('Email address') + 'title' => $this->l('Email address'), + 'filter_key' => 'a!email' ), ); @@ -141,6 +145,12 @@ class AdminCustomersControllerCore extends AdminController 'align' => 'text-right', 'badge_success' => true ), + 'phone' => array( + 'title' => $this->l('Phone'), + 'filter_key' => 'cgd!phone', + 'optional' => true, + 'visible_default' => false, + ), 'active' => array( 'title' => $this->l('Enabled'), 'align' => 'text-center', @@ -179,6 +189,7 @@ class AdminCustomersControllerCore extends AdminController 'title' => $this->l('Banned'), 'type' => 'bool', 'displayed' => false, + 'callback' => 'getCustomerStatusLabel', ), 'order_date' => array( 'title' => $this->l('Order date'), @@ -194,6 +205,7 @@ class AdminCustomersControllerCore extends AdminController $this->_select = ' a.date_add, gl.name as title, grl.name as default_group_name, COUNT(o.`id_order`) as total_orders, + cgd.`phone`, o.`date_add` as order_date, SUM(total_paid_real / conversion_rate) as total_spent, ( SELECT c.date_add FROM '._DB_PREFIX_.'guest g LEFT JOIN '._DB_PREFIX_.'connections c ON c.id_guest = g.id_guest @@ -230,6 +242,17 @@ class AdminCustomersControllerCore extends AdminController } } + public function getCustomerStatusLabel($deleted, $tr) + { + if ($deleted == Customer::STATUS_DELETED) { + return $this->l('Deleted'); + } else if ($deleted == Customer::STATUS_BANNED) { + return $this->l('Banned'); + } + + return; + } + public function initContent() { if ($this->action == 'select_delete') { @@ -263,8 +286,11 @@ class AdminCustomersControllerCore extends AdminController public function getList($id_lang, $orderBy = null, $orderWay = null, $start = 0, $limit = null, $id_lang_shop = null) { - parent::getList($id_lang, $orderBy, $orderWay, $start, $limit, $id_lang_shop); + if ($this->action == 'export') { + $this->deleted = false; + } + parent::getList($id_lang, $orderBy, $orderWay, $start, $limit, $id_lang_shop); if ($this->_list) { foreach ($this->_list as &$row) { $row['badge_success'] = $row['total_spent'] > 0; diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index 6dfcdaced..d0abec297 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -79,8 +79,7 @@ class AdminOrdersControllerCore extends AdminController LEFT JOIN `'._DB_PREFIX_.'order_state` os ON (os.`id_order_state` = a.`current_state`) LEFT JOIN `'._DB_PREFIX_.'order_state_lang` osl ON (os.`id_order_state` = osl.`id_order_state` AND osl.`id_lang` = '.(int) $this->context->language->id.') LEFT JOIN `'._DB_PREFIX_.'htl_booking_detail` hbd ON (hbd.`id_order` = a.`id_order`) - LEFT JOIN `'._DB_PREFIX_.'htl_branch_info_lang` hbil ON (hbil.`id` = hbd.`id_hotel`)'; - + LEFT JOIN `'._DB_PREFIX_.'htl_branch_info_lang` hbil ON (hbil.`id` = hbd.`id_hotel` AND osl.`id_lang` = hbil.`id_lang`)'; $this->_orderBy = 'id_order'; $this->_orderWay = 'DESC'; @@ -1189,6 +1188,123 @@ class AdminOrdersControllerCore extends AdminController return parent::renderList(); } + public function getList( + $id_lang, + $order_by = null, + $order_way = null, + $start = 0, + $limit = null, + $id_lang_shop = false + ){ + if ($this->action == 'export' && empty($this->_listsql)) { + $this->_select .= ', c.`email`, cgd.`phone`, a.`total_paid_real`, + orf.`cancellation_date`, orf.`cancellation_fee`, + cy.`iso_code` AS country, st.`iso_code` as state, ad.`city`, + CONCAT(ad.`address1`, \', \', ad.`postcode`) AS `cus_address`, + GROUP_CONCAT( + CASE + WHEN hbd.`id_status`='.HotelBookingDetail::STATUS_ALLOTED.' THEN \''.$this->l('Alloted').'\' + WHEN hbd.`id_status`='.HotelBookingDetail::STATUS_CHECKED_IN.' THEN \''.$this->l('Checked in').'\' + WHEN hbd.`id_status`='.HotelBookingDetail::STATUS_CHECKED_OUT.' THEN \''.$this->l('Checked out').'\' + ELSE \''.$this->l('Invalid status').'\' + END + ) AS `room_status`, + GROUP_CONCAT(DISTINCT(hbd.`room_type_name`)) AS `room_types`, + GROUP_CONCAT(hbd.`date_from`) AS `date_from`, + GROUP_CONCAT(hbd.`date_to`) AS `date_to`, + GROUP_CONCAT(hbd.`room_num`) AS `rooms`, + GROUP_CONCAT(hbd.`check_in`) AS `check_in_dates`, + GROUP_CONCAT(hbd.`check_out`) AS `check_out_dates`'; + + $this->_join .= ' LEFT JOIN `'._DB_PREFIX_.'cart_customer_guest_detail` cgd ON cgd.`email` = c.`email` AND cgd.`id_cart` = 0 + LEFT JOIN `'._DB_PREFIX_.'address` ad ON a.`id_customer`= ad.`id_customer` AND ad.`id_customer`!=0 + LEFT JOIN `'._DB_PREFIX_.'country` cy ON cy.`id_country`= ad.`id_country` + LEFT JOIN `'._DB_PREFIX_.'state` st ON st.`id_state`= ad.`id_state` + LEFT JOIN ( + SELECT ref.`id_order`, IF(refst.refunded = 1, GROUP_CONCAT(ref.`date_upd`), NULL) AS `cancellation_date`, + IF(refst.refunded = 1, SUM(ref.`refunded_amount`), NULL) AS `cancellation_fee` + FROM `'._DB_PREFIX_.'order_return` ref + LEFT JOIN `'._DB_PREFIX_.'order_return_state` refst + ON refst.`id_order_return_state` = ref.`state` AND refst.`refunded` = 1 + GROUP BY ref.`id_order` + ) AS orf ON orf.`id_order` = a.`id_order`'; + + $this->fields_list = array_merge($this->fields_list, array( + 'email' => array( + 'title' => $this->l('Email') + ), + 'phone' => array( + 'title' => $this->l('Phone') + ), + 'room_types' => array( + 'title' => $this->l('Room Types') + ), + 'rooms' => array( + 'title' => $this->l('Rooms') + ), + 'currency' => array( + 'title' => $this->l('Currency') + ), + 'total_paid_real' => array( + 'title' => $this->l('Amount Paid') + ), + 'check_in_dates' => array( + 'title' => $this->l('Check In') + ), + 'check_out_dates' => array( + 'title' => $this->l('Check Out') + ), + 'date_from' => array( + 'title' => $this->l('Date From'), + 'filter_key' => 'hbd!date_from', + ), + 'date_to' => array( + 'title' => $this->l('Date To'), + 'filter_key' => 'hbd!date_to', + ), + 'date_add' => array( + 'title' => $this->l('Reservation Date'), + 'filter_key' => 'a!date_add', + ), + 'room_status' => array( + 'title' => $this->l('Room Status'), + ), + 'country' => array( + 'title' => $this->l('Country'), + ), + 'state' => array( + 'title' => $this->l('State'), + ), + 'city' => array( + 'title' => $this->l('City'), + ), + 'cus_address' => array( + 'title' => $this->l('Address'), + ), + 'cancellation_date' => array( + 'title' => $this->l('Cancellation date'), + ), + 'cancellation_fee' => array( + 'title' => $this->l('Cancellation fee'), + ), + )); + + unset($this->fields_list['id_status']); + unset($this->fields_list['id_room_information']); + unset($this->fields_list['room_type_name']); + unset($this->fields_list['id_currency']); + } + + parent::getList( + $id_lang, + $order_by, + $order_way, + $start, + $limit, + $id_lang_shop + ); + } + public function postProcess() { // Process reallocation of rooms diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php index 80ac896f9..8473c0bca 100644 --- a/controllers/admin/AdminProductsController.php +++ b/controllers/admin/AdminProductsController.php @@ -201,7 +201,13 @@ class AdminProductsControllerCore extends AdminController LEFT JOIN `'._DB_PREFIX_.'address` aa ON (aa.`id_hotel` = hb.`id`) LEFT JOIN `'._DB_PREFIX_.'feature_product` fp ON (fp.`id_product` = a.`id_product`) LEFT JOIN `'._DB_PREFIX_.'htl_room_type_demand` hrtd ON (hrtd.`id_product` = a.`id_product`) - LEFT JOIN `'._DB_PREFIX_.'htl_room_type_service_product` hrtsp ON ((hrtsp.`element_type` = '.(int) RoomTypeServiceProduct::WK_ELEMENT_TYPE_HOTEL.' AND hrtsp.`id_element` = hrt.`id_hotel`) OR (hrtsp.`element_type` = '.(int) RoomTypeServiceProduct::WK_ELEMENT_TYPE_ROOM_TYPE.' AND hrtsp.`id_element` = a.`id_product`)) + LEFT JOIN ( + SELECT rsp.*, GROUP_CONCAT(pl.`name`) AS service_products + FROM `'._DB_PREFIX_.'htl_room_type_service_product` rsp + LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (pl.`id_product` = rsp.`id_product`) + WHERE pl.`id_lang`='.$this->context->language->id.' + GROUP BY rsp.`id_element`) + AS hrtsp ON ((hrtsp.`element_type` = '.(int) RoomTypeServiceProduct::WK_ELEMENT_TYPE_HOTEL.' AND hrtsp.`id_element` = hrt.`id_hotel`) OR (hrtsp.`element_type` = '.(int) RoomTypeServiceProduct::WK_ELEMENT_TYPE_ROOM_TYPE.' AND hrtsp.`id_element` = a.`id_product`)) LEFT JOIN `'._DB_PREFIX_.'htl_advance_payment` hap ON (hap.`id_product` = a.`id_product`)'; $this->_select .= ' a.`show_at_front`, (SELECT COUNT(hri.`id`) FROM `'._DB_PREFIX_.'htl_room_information` hri WHERE hri.`id_product` = a.`id_product`) as num_rooms, '; @@ -290,7 +296,7 @@ class AdminProductsControllerCore extends AdminController 'validation' => 'isFloat', 'align' => 'text-left', 'filter_key' => 'a!price', - 'callback' => 'displayBasePrice', + 'callback' => 'displayPrice', ); $this->fields_list['price_final'] = array( 'title' => $this->l('Final price'), @@ -298,7 +304,8 @@ class AdminProductsControllerCore extends AdminController 'align' => 'text-left', 'havingFilter' => true, 'orderby' => false, - 'search' => false + 'search' => false, + 'callback' => 'displayPrice', ); $this->fields_list['active'] = array( @@ -326,6 +333,7 @@ class AdminProductsControllerCore extends AdminController 'align' => 'text-center', 'type' => 'bool', 'active' => 'show_at_front', + 'callback' => 'formatStatusAsLabel', 'optional' => true, 'havingFilter' => true, 'visible_default' => true, @@ -335,7 +343,7 @@ class AdminProductsControllerCore extends AdminController if (Configuration::get('WK_ALLOW_ADVANCED_PAYMENT')) { $this->fields_list['advance_payment'] = array( 'title' => $this->l('Advance Payment'), - 'callback' => 'getAdvancePaymentStatus', + 'callback' => 'formatStatusAsLabel', 'badge_success' => true, 'badge_danger' => true, 'align' => 'text-center', @@ -445,8 +453,7 @@ class AdminProductsControllerCore extends AdminController ); } } - - public function getAdvancePaymentStatus($val, $row) + public function formatStatusAsLabel($val, $row) { if ($val) { $str_return = $this->l('Yes'); @@ -470,7 +477,7 @@ class AdminProductsControllerCore extends AdminController } } - public static function displayBasePrice($basePrice, $tr) + public static function displayPrice($basePrice, $tr) { return Tools::displayPrice($basePrice, (int) Configuration::get('PS_CURRENCY_DEFAULT')); } @@ -629,6 +636,43 @@ class AdminProductsControllerCore extends AdminController $orderBy = 'id_'.$this->table; $orderWay = 'ASC'; } + if ($this->action == 'export' && empty($this->_listsql)) { + $this->_select .= ' , trg.`name` AS `id_tax_rules_group`, GROUP_CONCAT(fpl.`name`) AS `features`, hrtdl.`global_demands`'; + $this->_join .= ' LEFT JOIN `'._DB_PREFIX_.'tax_rules_group` trg + ON trg.`id_tax_rules_group` = a.`id_tax_rules_group` + LEFT JOIN `'._DB_PREFIX_.'feature_lang` fpl + ON (fp.`id_feature` = fpl.`id_feature` AND fpl.`id_lang`='.(int) $this->context->language->id.')'; + + $this->_join .= ' LEFT JOIN (SELECT + `id_global_demand`, `id_lang`, + GROUP_CONCAT(`name`) AS `global_demands`, + GROUP_CONCAT(`id_global_demand`) + FROM `'._DB_PREFIX_.'htl_room_type_global_demand_lang` + WHERE `id_lang`='.(int) $this->context->language->id.' + GROUP BY `id_global_demand` + ) AS hrtdl ON (hrtdl.`id_global_demand` = hrtd.`id_global_demand` AND hrtdl.`id_lang`= b.`id_lang` )'; + + $this->fields_list = array_merge($this->fields_list, array( + 'id_tax_rules_group' => array( + 'title' => $this->l('Id Tax Rules group'), + 'filter_key' => 'a!id_tax_rules_group', + ), + 'features' => array( + 'title' => $this->l('Features'), + ), + 'service_products' => array( + 'title' => $this->l('Services Products'), + ), + 'global_demands' => array( + 'title' => $this->l('Additional Facilities'), + ) + ) + ); + + unset($this->fields_list['id_global_demand']); + unset($this->fields_list['id_feature']); + unset($this->fields_list['id_service_product']); + } parent::getList($id_lang, $orderBy, $orderWay, $start, $limit, $this->context->shop->id); /* update product quantity with attributes ...*/ From 7340afe6cee239b1f2d7cfccdb5e183ee34b11e5 Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Wed, 5 Feb 2025 19:21:43 +0530 Subject: [PATCH 08/36] Optimized: the room search flow, and validation process before process save --- .../admin/AdminHotelFeaturePricesSettings.php | 366 +++++++++--------- .../helpers/form/form.tpl | 6 +- 2 files changed, 185 insertions(+), 187 deletions(-) diff --git a/modules/hotelreservationsystem/controllers/admin/AdminHotelFeaturePricesSettings.php b/modules/hotelreservationsystem/controllers/admin/AdminHotelFeaturePricesSettings.php index e05c8b43f..7cd48a1ee 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminHotelFeaturePricesSettings.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminHotelFeaturePricesSettings.php @@ -203,7 +203,7 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController parent::initToolbar(); if (empty($this->display) || $this->display == 'list') { $this->page_header_toolbar_btn['bulk_add'] = array( - 'href' => self::$currentIndex.'&add'.$this->table.'&bulkAdd'.$this->table.'=1&token='.$this->token, + 'href' => self::$currentIndex.'&add'.$this->table.'&bulkAdd'.$this->table.'&token='.$this->token, 'desc' => $this->l('Bulk create rules'), 'imgclass' => 'new' ); @@ -219,7 +219,7 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController public function initToolbarTitle() { parent::initToolbarTitle(); - if (Tools::getValue('bulkAdd'.$this->table)) { + if (Tools::isSubmit('bulkAdd'.$this->table)) { $this->toolbar_title[] = $this->l('Bulk Create', null, null, false); $this->addMetaTitle($this->l('Bulk Create', null, null, false)); } @@ -228,8 +228,8 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController public function initProcess() { parent::initProcess(); - if (Tools::getValue('bulkAdd'.$this->table)) { - self::$currentIndex = self::$currentIndex.'&bulkAdd'.$this->table.'=1'; + if (Tools::isSubmit('bulkAdd'.$this->table)) { + self::$currentIndex = self::$currentIndex.'&bulkAdd'.$this->table.''; } if (Tools::isSubmit('submitBulkAdd'.$this->table)) { @@ -285,23 +285,32 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController $smartyVars['date_from'] = $dateFrom; $smartyVars['date_to'] = $dateTo; $smartyVars['groups'] = Group::getGroups($this->context->language->id); - $smartyVars['bulk_add'] = Tools::getValue('bulkAdd'.$this->table); - - if ($smartyVars['bulk_add']) { + if (Tools::isSubmit('bulkAdd'.$this->table)) { + $this->submit_action = 'submitBulkAdd'.$this->table; + $smartyVars['bulk_add'] = true; $tree = new HelperTree('hotels-tree'); - $tree->setData(HotelHelper::generateTreeData([ - 'rootNode' => HotelHelper::NODE_HOTEL, - 'leafNode' => HotelHelper::NODE_ROOM_TYPE, - 'selectedElements' => array( - 'room_type' => Tools::getValue('room_type_box', array()) - ) - ])) + if ($treeData = HotelHelper::generateTreeData([ + 'rootNode' => HotelHelper::NODE_HOTEL, + 'leafNode' => HotelHelper::NODE_ROOM_TYPE, + 'selectedElements' => array( + 'room_type' => Tools::getValue('room_type_box', array()) + ) + ])) { + foreach ($treeData as $idHotel => $data) { + if (!isset($data['children']) || empty($data['children'])) { + unset($treeData[$idHotel]); + } + } + } + + $tree->setData($treeData) ->setUseCheckBox(true) ->setAutoSelectChildren(true) ->setUseBulkActions(true) ->setUseSearch(true); $smartyVars['hotel_tree'] = $tree->render(); } + $this->context->smarty->assign($smartyVars); $this->fields_form = array( 'submit' => array( @@ -405,15 +414,84 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController $languages = Language::getLanguages(false); $objDefaultLang = new language($defaultLangId); + if (!Tools::getValue('feature_price_name_'.$defaultLangId)) { + $this->errors[] = sprintf( + $this->l('Advanced price rule name is required at least in %s'), + $objDefaultLang->name + ); + } + $validateRules = call_user_func( + array('HotelRoomTypeFeaturePricing', 'getValidationRules'), + 'HotelRoomTypeFeaturePricing' + ); + foreach ($languages as $language) { + if (!Validate::isCatalogName(Tools::getValue('feature_price_name_'.$language['id_lang']))) { + $this->errors[] = $this->l('Advanced price rule name is invalid in ').$language['name']; + } elseif (Tools::strlen(Tools::getValue('feature_price_name_'.$language['id_lang'])) > $validateRules['sizeLang']['feature_price_name']) { + sprintf( + $this->l('Advanced price rule Name field is too long (%2$d chars max).'), + $validateRules['sizeLang']['feature_price_name'] + ); + } + } + + if (!$roomTypeId) { + $this->errors[] = $this->l('Room is not selected. Please try again.'); + } + if ($dateSelectionType == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_SPECIFIC) { $dateFrom = $specificDate; $dateTo = date('Y-m-d', strtotime("+1 day", strtotime($specificDate))); + } else if ($dateSelectionType == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_RANGE) { + if ($dateFrom == '') { + $this->errors[] = $this->l('Please choose Date from for the advanced price rule.'); + } + if ($dateTo == '') { + $this->errors[] = $this->l('Please choose Date to for the advanced price rule.'); + } + $dateFrom = date('Y-m-d', strtotime($dateFrom)); + $dateTo = date('Y-m-d', strtotime($dateTo)); + if (!Validate::isDate($dateFrom)) { + $this->errors[] = $this->l('Invalid Date From.'); + } + if (!Validate::isDate($dateTo)) { + $this->errors[] = $this->l('Invalid Date To.'); + } + if ($dateTo < $dateFrom) { + $this->errors[] = $this->l('Date To must be a date after Date From.'); + } + if ($isSpecialDaysExists) { + if (!isset($specialDays) || !$specialDays) { + $this->errors[] = $this->l('Please select at least one day for week days restriction.'); + } + } + } else { + if ($specificDate == '') { + $this->errors[] = $this->l('Please choose Date from for the advanced price rule.'); + } + $specificDate = date('Y-m-d', strtotime($specificDate)); + if (!Validate::isDate($specificDate)) { + $this->errors[] = $this->l('Invalid Date From.'); + } } + if (!$impactValue) { + $this->errors[] = $this->l('Please enter a valid impact value.'); + } else { + if (!Validate::isPrice($impactValue)) { + $this->errors[] = $this->l('Invalid value of impact value.'); + } + } + + if (!(bool)$groups) { + $this->errors[] = $this->l('Please select at least one group for the group access'); + } + + $isPlanTypeExists = 0; if ($isSpecialDaysExists && $jsonSpecialDays == 'false') { $this->errors[] = $this->l('Please select at least one day for week days restriction.'); - } else { + } else if (empty($this->errors)) { $isPlanTypeExists = $this->validateExistingFeaturePrice( $dateSelectionType, $roomTypeId, @@ -428,75 +506,6 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController if ($isPlanTypeExists) { $this->errors[] = $this->l('An advanced price rule already exists in which some dates are common with this plan. Please select a different date range.'); } else { - if (!$roomTypeId) { - $this->errors[] = $this->l('Room is not selected. Please try again.'); - } - if (!Tools::getValue('feature_price_name_'.$defaultLangId)) { - $this->errors[] = sprintf( - $this->l('Advanced price rule name is required at least in %s'), - $objDefaultLang->name - ); - } - $validateRules = call_user_func( - array('HotelRoomTypeFeaturePricing', 'getValidationRules'), - 'HotelRoomTypeFeaturePricing' - ); - foreach ($languages as $language) { - if (!Validate::isCatalogName(Tools::getValue('feature_price_name_'.$language['id_lang']))) { - $this->errors[] = $this->l('Advanced price rule name is invalid in ').$language['name']; - } elseif (Tools::strlen(Tools::getValue('feature_price_name_'.$language['id_lang'])) > $validateRules['sizeLang']['feature_price_name']) { - sprintf( - $this->l('Advanced price rule Name field is too long (%2$d chars max).'), - $validateRules['sizeLang']['feature_price_name'] - ); - } - } - - if ($dateSelectionType == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_RANGE) { - if ($dateFrom == '') { - $this->errors[] = $this->l('Please choose Date from for the advanced price rule.'); - } - if ($dateTo == '') { - $this->errors[] = $this->l('Please choose Date to for the advanced price rule.'); - } - $dateFrom = date('Y-m-d', strtotime($dateFrom)); - $dateTo = date('Y-m-d', strtotime($dateTo)); - if (!Validate::isDate($dateFrom)) { - $this->errors[] = $this->l('Invalid Date From.'); - } - if (!Validate::isDate($dateTo)) { - $this->errors[] = $this->l('Invalid Date To.'); - } - if ($dateTo < $dateFrom) { - $this->errors[] = $this->l('Date To must be a date after Date From.'); - } - if ($isSpecialDaysExists) { - if (!isset($specialDays) || !$specialDays) { - $this->errors[] = $this->l('Please select at least one day for week days restriction.'); - } - } - } else { - if ($specificDate == '') { - $this->errors[] = $this->l('Please choose Date from for the advanced price rule.'); - } - $specificDate = date('Y-m-d', strtotime($specificDate)); - if (!Validate::isDate($specificDate)) { - $this->errors[] = $this->l('Invalid Date From.'); - } - } - - if (!$impactValue) { - $this->errors[] = $this->l('Please enter a valid impact value.'); - } else { - if (!Validate::isPrice($impactValue)) { - $this->errors[] = $this->l('Invalid value of impact value.'); - } - } - - if (!(bool)$groups) { - $this->errors[] = $this->l('Please select at least one group for the group access'); - } - if (!count($this->errors)) { if ($idFeaturePrice) { $objFeaturePricing = new HotelRoomTypeFeaturePricing($idFeaturePrice); @@ -574,16 +583,85 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController $languages = Language::getLanguages(false); $objDefaultLang = new language($defaultLangId); $featurePricingName = array(); + if (!Tools::getValue('feature_price_name_'.$defaultLangId)) { + $this->errors[] = sprintf( + $this->l('Advanced price rule name is required at least in %s'), + $objDefaultLang->name + ); + } + $validateRules = call_user_func( + array('HotelRoomTypeFeaturePricing', 'getValidationRules'), + 'HotelRoomTypeFeaturePricing' + ); + foreach ($languages as $language) { + if (!Validate::isCatalogName(Tools::getValue('feature_price_name_'.$language['id_lang']))) { + $this->errors[] = $this->l('Advanced price rule name is invalid in ').$language['name']; + } elseif (Tools::strlen(Tools::getValue('feature_price_name_'.$language['id_lang'])) > $validateRules['sizeLang']['feature_price_name']) { + sprintf( + $this->l('Advanced price rule Name field is too long (%2$d chars max).'), + $validateRules['sizeLang']['feature_price_name'] + ); + } + + if (Tools::getValue('feature_price_name_'.$language['id_lang'])) { + $featurePricingName[$language['id_lang']] = Tools::getValue('feature_price_name_'.$language['id_lang']); + } else { + $featurePricingName[$language['id_lang']] = Tools::getValue('feature_price_name_'.$defaultLangId); + } + } if ($dateSelectionType == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_SPECIFIC) { $dateFrom = $specificDate; $dateTo = date('Y-m-d', strtotime("+1 day", strtotime($specificDate))); - } - $isPlanTypeExists = 0; - - if (empty($roomTypeIds)) { - $this->errors[] = $this->l('Please select at least one room type for bulk creation.'); + } else if ($dateSelectionType == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_RANGE) { + if ($dateFrom == '') { + $this->errors[] = $this->l('Please choose Date from for the advanced price rule.'); + } + if ($dateTo == '') { + $this->errors[] = $this->l('Please choose Date to for the advanced price rule.'); + } + $dateFrom = date('Y-m-d', strtotime($dateFrom)); + $dateTo = date('Y-m-d', strtotime($dateTo)); + if (!Validate::isDate($dateFrom)) { + $this->errors[] = $this->l('Invalid Date From.'); + } + if (!Validate::isDate($dateTo)) { + $this->errors[] = $this->l('Invalid Date To.'); + } + if ($dateTo < $dateFrom) { + $this->errors[] = $this->l('Date To must be a date after Date From.'); + } + if ($isSpecialDaysExists) { + if (!isset($specialDays) || !$specialDays) { + $this->errors[] = $this->l('Please select at least one day for week days restriction.'); + } + } } else { + if ($specificDate == '') { + $this->errors[] = $this->l('Please choose Date from for the advanced price rule.'); + } + $specificDate = date('Y-m-d', strtotime($specificDate)); + if (!Validate::isDate($specificDate)) { + $this->errors[] = $this->l('Invalid Date From.'); + } + } + + if (!$impactValue) { + $this->errors[] = $this->l('Please enter a valid impact value.'); + } else { + if (!Validate::isPrice($impactValue)) { + $this->errors[] = $this->l('Invalid value of impact value.'); + } + } + + if (!(bool)$groups) { + $this->errors[] = $this->l('Please select at least one group for the group access'); + } + + $isPlanTypeExists = 0; + if (empty($roomTypeIds)) { + $this->errors[] = $this->l('Please select at least one room type for bulk creation process.'); + } else if (empty($this->errors)) { if ($isSpecialDaysExists && $jsonSpecialDays == 'false') { $this->errors[] = $this->l('Please select at least one day for week days restriction.'); } else { @@ -606,79 +684,6 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController } } - if (!Tools::getValue('feature_price_name_'.$defaultLangId)) { - $this->errors[] = sprintf( - $this->l('Advanced price rule name is required at least in %s'), - $objDefaultLang->name - ); - } - - $validateRules = call_user_func( - array('HotelRoomTypeFeaturePricing', 'getValidationRules'), - 'HotelRoomTypeFeaturePricing' - ); - foreach ($languages as $language) { - if (!Validate::isCatalogName(Tools::getValue('feature_price_name_'.$language['id_lang']))) { - $this->errors[] = $this->l('Advanced price rule name is invalid in ').$language['name']; - } elseif (Tools::strlen(Tools::getValue('feature_price_name_'.$language['id_lang'])) > $validateRules['sizeLang']['feature_price_name']) { - sprintf( - $this->l('Advanced price rule Name field is too long (%2$d chars max).'), - $validateRules['sizeLang']['feature_price_name'] - ); - } - - if (Tools::getValue('feature_price_name_'.$language['id_lang'])) { - $featurePricingName[$language['id_lang']] = Tools::getValue('feature_price_name_'.$language['id_lang']); - } else { - $featurePricingName[$language['id_lang']] = Tools::getValue('feature_price_name_'.$defaultLangId); - } - } - - if ($dateSelectionType == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_RANGE) { - if ($dateFrom == '') { - $this->errors[] = $this->l('Please choose Date from for the advanced price rule.'); - } - if ($dateTo == '') { - $this->errors[] = $this->l('Please choose Date to for the advanced price rule.'); - } - $dateFrom = date('Y-m-d', strtotime($dateFrom)); - $dateTo = date('Y-m-d', strtotime($dateTo)); - if (!Validate::isDate($dateFrom)) { - $this->errors[] = $this->l('Invalid Date From.'); - } - if (!Validate::isDate($dateTo)) { - $this->errors[] = $this->l('Invalid Date To.'); - } - if ($dateTo < $dateFrom) { - $this->errors[] = $this->l('Date To must be a date after Date From.'); - } - if ($isSpecialDaysExists) { - if (!isset($specialDays) || !$specialDays) { - $this->errors[] = $this->l('Please select at least one day for week days restriction.'); - } - } - } else { - if ($specificDate == '') { - $this->errors[] = $this->l('Please choose Date from for the advanced price rule.'); - } - $specificDate = date('Y-m-d', strtotime($specificDate)); - if (!Validate::isDate($specificDate)) { - $this->errors[] = $this->l('Invalid Date From.'); - } - } - - if (!$impactValue) { - $this->errors[] = $this->l('Please enter a valid impact value.'); - } else { - if (!Validate::isPrice($impactValue)) { - $this->errors[] = $this->l('Invalid value of impact value.'); - } - } - - if (!(bool)$groups) { - $this->errors[] = $this->l('Please select at least one group for the group access'); - } - if (empty($this->errors)) { $res = true; foreach ($roomTypeIds as $roomTypeId) { @@ -700,7 +705,7 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController $res &= $objFeaturePricing->save(); } - Tools::redirectAdmin(self::$currentIndex.'&conf=4&token='.$this->token); + Tools::redirectAdmin($this->context->link->getAdminLink('AdminHotelFeaturePricesSettings').'&conf=4&token='.$this->token); } } @@ -711,15 +716,14 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController public function ajaxProcessSearchProductByName() { - $productName = Tools::getValue('room_type_name'); - if ($productName) { - $productsByName = Product::searchByName($this->context->language->id, $productName); - // filter room types as per accessed hotels - $productsByName = HotelBranchInformation::filterDataByHotelAccess( - $productsByName, - $this->context->employee->id_profile - ); - if ($productsByName) { + $response = array('status' => 'failed'); + if ($productName = Tools::getValue('room_type_name')) { + if ($productsByName = Product::searchByName($this->context->language->id, $productName)) { + $productsByName = HotelBranchInformation::filterDataByHotelAccess( + $productsByName, + $this->context->employee->id_profile + ); + // filter room types as per accessed hotels foreach ($productsByName as &$product) { $hotelRoomType = new HotelRoomType(); $roomInfoByIdProduct = $hotelRoomType->getRoomTypeInfoByIdProduct($product['id_product']); @@ -729,22 +733,16 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController $product['name'].= ' / '.$onjBranchInfo->hotel_name; } } - echo json_encode($productsByName, true); - die; + + $response = $productsByName; } else { - die( - json_encode( - array('status' => 'failed', 'msg' => $this->l('No match found for entered room type name.')) - ) - ); + $response['msg'] = $this->l('No match found for entered room type name.'); } } else { - die( - json_encode( - array('status' => 'failed', 'msg' => $this->l('No match found for entered room type name.')) - ) - ); + $response['msg'] = $this->l('No match found for entered room type name.'); } + + $this->ajaxDie(json_encode($response)); } public function setMedia() diff --git a/modules/hotelreservationsystem/views/templates/admin/hotel_feature_prices_settings/helpers/form/form.tpl b/modules/hotelreservationsystem/views/templates/admin/hotel_feature_prices_settings/helpers/form/form.tpl index e40b26f10..a9c3c89a8 100644 --- a/modules/hotelreservationsystem/views/templates/admin/hotel_feature_prices_settings/helpers/form/form.tpl +++ b/modules/hotelreservationsystem/views/templates/admin/hotel_feature_prices_settings/helpers/form/form.tpl @@ -19,7 +19,7 @@
- {if isset($bulk_add) && $bulk_add} + {if isset($bulk_add)}  {l s='Bulk Create Advanced Price Rule' mod='hotelreservationsystem'} {else if isset($edit)}  {l s='Edit Advanced Price Rule' mod='hotelreservationsystem'} @@ -59,7 +59,7 @@ {/if}
- {if isset($bulk_add) && $bulk_add} + {if isset($bulk_add)}
-

{if isset($roomDemand['adv_option']) && $roomDemand['adv_option']}{convertPrice price = $roomDemand['adv_option'][$idGlobalDemand]['price']|escape:'html':'UTF-8'}{else}{convertPrice price = $roomDemand['price']|escape:'html':'UTF-8'}{/if}

+

+ {if isset($roomDemand['adv_option']) && $roomDemand['adv_option']} + {convertPrice price = $roomDemand['adv_option'][$demand['id_option']]['price']|escape:'html':'UTF-8'} + {else} + {convertPrice price = $roomDemand['price']|escape:'html':'UTF-8'} + {/if} +

{/if} diff --git a/controllers/admin/AdminCartsController.php b/controllers/admin/AdminCartsController.php index 2ce84593f..69e2d671c 100644 --- a/controllers/admin/AdminCartsController.php +++ b/controllers/admin/AdminCartsController.php @@ -302,6 +302,31 @@ class AdminCartsControllerCore extends AdminController $product['image'] = (isset($image['id_image']) ? ImageManager::thumbnail(_PS_IMG_DIR_.'p/'.$image_product->getExistingImgPath().'.jpg', 'product_mini_'.(int)$product['id_product'].(isset($product['id_product_attribute']) ? '_'.(int)$product['id_product_attribute'] : '').'.jpg', 45, 'jpg') : '--'); } + // by webkul to show rooms available in the cart + $cartHtlData = array(); + $objHotelCartBookingData = new HotelCartBookingData(); + $objHotelRoomType = new HotelRoomType(); + if ($cartHtlData = $objHotelCartBookingData->getCartFormatedBookinInfoByIdCart((int) $cart->id)) { + foreach ($cartHtlData as $key => $value) { + $cartHtlData[$key]['room_type_info'] = $objHotelRoomType->getRoomTypeInfoByIdProduct($value['id_product']); + if (isset($value['selected_services']) && $value['selected_services']) { + foreach ($value['selected_services'] as $service) { + if ($service['id_cart'] != $value['id_cart']) { + if ($tax_calculation_method == PS_TAX_EXC) { + $total_price += ($service['quantity'] * $service['total_price_tax_excl']); + $total_products += ($service['quantity'] * $service['total_price_tax_excl']); + } else { + $total_price += ($service['quantity'] * $service['total_price_tax_incl']); + $total_products += ($service['quantity'] * $service['total_price_tax_incl']); + } + } + } + } + } + } else { + $cartHtlData = array(); + } + $helper = new HelperKpi(); $helper->id = 'box-kpi-cart'; $helper->icon = 'icon-shopping-cart'; @@ -310,17 +335,6 @@ class AdminCartsControllerCore extends AdminController $helper->subtitle = sprintf($this->l('Cart #%06d', null, null, false), $cart->id); $helper->value = Tools::displayPrice($total_price, $currency); $kpi = $helper->generate(); - // by webkul to show rooms available in the cart - $cartHtlData = array(); - $objHotelCartBookingData = new HotelCartBookingData(); - $objHotelRoomType = new HotelRoomType(); - if ($cartHtlData = $objHotelCartBookingData->getCartFormatedBookinInfoByIdCart((int) $cart->id)) { - foreach ($cartHtlData as $key => $value) { - $cartHtlData[$key]['room_type_info'] = $objHotelRoomType->getRoomTypeInfoByIdProduct($value['id_product']); - } - } else { - $cartHtlData = array(); - } //end $this->tpl_view_vars = array( 'cart_htl_data' => $cartHtlData,//by webkul hotel rooms in order data diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index b852574d7..1ea20ab15 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -5442,6 +5442,15 @@ class AdminOrdersControllerCore extends AdminController $idHotelBooking ); + //This is added to remove the services from the cart along with room deletion process. + $objHotelCartBookingData = new HotelCartBookingData(); + $roomHtlCartInfo = $objHotelCartBookingData->getRoomRowByIdProductIdRoomInDateRange( + $objBookingDetail->id_cart, + $objBookingDetail->id_product, + $objBookingDetail->date_from, + $objBookingDetail->date_to, + $objBookingDetail->id_room + ); /*$totalProductPriceBeforeTE = $order_detail->total_price_tax_excl; $totalProductPriceBeforeTI = $order_detail->total_price_tax_incl;*/ @@ -5476,6 +5485,7 @@ class AdminOrdersControllerCore extends AdminController $res &= $order_detail->update(); } // update order detail for selected aditional services + $objRoomTypeServiceProductCartDetail = new RoomTypeServiceProductCartDetail(); foreach ($selectedAdditonalServices['additional_services'] as $service) { $serviceOrderDetail = new OrderDetail($service['id_order_detail']); @@ -5496,6 +5506,21 @@ class AdminOrdersControllerCore extends AdminController // Save order detail $res &= $serviceOrderDetail->update(); } + + if (isset($roomHtlCartInfo['id'])) { + if ($id_room_type_service_product_cart_detail = $objRoomTypeServiceProductCartDetail->alreadyExists( + $service['id_product'], + $service['id_cart'], + $roomHtlCartInfo['id'] + )) { + $objRoomTypeServiceProductCartDetail = new RoomTypeServiceProductCartDetail((int) $id_room_type_service_product_cart_detail); + $serviceQuantity = $objRoomTypeServiceProductCartDetail->quantity; + if ($objRoomTypeServiceProductCartDetail->delete()) { + $objCart = new Cart($service['id_cart']); + $objCart->updateQty((int)abs($serviceQuantity), $service['id_product'], null, false, 'down'); + } + } + } } /*End*/ @@ -5574,7 +5599,9 @@ class AdminOrdersControllerCore extends AdminController $objBookingDetail->id_product, $objBookingDetail->id_room, $objBookingDetail->date_from, - $objBookingDetail->date_to + $objBookingDetail->date_to, + 1, + 1 ); $objBookingDetail->delete(); @@ -6493,8 +6520,31 @@ class AdminOrdersControllerCore extends AdminController $quantity = $objRoomTypeServiceProductOrderDetail->quantity; $res = true; $objHotelBookingDetail = new HotelBookingDetail($objRoomTypeServiceProductOrderDetail->id_htl_booking_detail); + $idServiceProduct = $objRoomTypeServiceProductOrderDetail->id_product; + $objHotelCartBookingData = new HotelCartBookingData(); + $roomHtlCartInfo = $objHotelCartBookingData->getRoomRowByIdProductIdRoomInDateRange( + $objHotelBookingDetail->id_cart, + $objHotelBookingDetail->id_product, + $objHotelBookingDetail->date_from, + $objHotelBookingDetail->date_to, + $objHotelBookingDetail->id_room + ); + $objRoomTypeServiceProductCartDetail = new RoomTypeServiceProductCartDetail(); if ($res &= $objRoomTypeServiceProductOrderDetail->delete()) { + if (isset($roomHtlCartInfo['id'])) { + if ($id_room_type_service_product_cart_detail = $objRoomTypeServiceProductCartDetail->alreadyExists( + $idServiceProduct, + $objRoomTypeServiceProductOrderDetail->id_cart, + $roomHtlCartInfo['id'] + )) { + $objRoomTypeServiceProductCartDetail = new RoomTypeServiceProductCartDetail($id_room_type_service_product_cart_detail); + if ($objRoomTypeServiceProductCartDetail->delete()) { + $objCart = new Cart($objRoomTypeServiceProductOrderDetail->id_cart); + $objCart->updateQty((int)abs($quantity), $objRoomTypeServiceProductOrderDetail->id_product, null, false, 'down'); + } + } + } $order = new Order($objRoomTypeServiceProductOrderDetail->id_order); if ($quantity >= $objOrderDetail->product_quantity) { $objOrderDetail->delete(); diff --git a/modules/hotelreservationsystem/classes/HotelCartBookingData.php b/modules/hotelreservationsystem/classes/HotelCartBookingData.php index 7f8a3e151..9258f4cb1 100644 --- a/modules/hotelreservationsystem/classes/HotelCartBookingData.php +++ b/modules/hotelreservationsystem/classes/HotelCartBookingData.php @@ -346,7 +346,8 @@ class HotelCartBookingData extends ObjectModel $idRoom = 0, $dateFrom = 0, $dateTo = 0, - $updPsCart = 1 + $updPsCart = 1, + $excludeOrdered = 0 ) { $where = '1'; if ($idCart) { @@ -365,7 +366,9 @@ class HotelCartBookingData extends ObjectModel $where .= ' AND `date_to`=\''.pSQL($dateTo).'\''; } // we have to delete only rows which order is not created - $where .= ' AND `id_order`= 0'; + if (!$excludeOrdered) { + $where .= ' AND `id_order`= 0'; + } // If rooms is deleting from cart the we need to delete the ps_cart quantity of the product from table // if product will delete the prestashop will handle $numRooms = 0; diff --git a/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php b/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php index fec2fed2c..753d4ec3e 100644 --- a/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php +++ b/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php @@ -217,7 +217,7 @@ class RoomTypeServiceProductCartDetail extends ObjectModel $idLang = Context::getContext()->language->id; - $sql = 'SELECT rscd.`id_product`, rscd.`quantity`, cbd.`id_cart`, cbd.`id` as `htl_cart_booking_id` , + $sql = 'SELECT rscd.`id_product`, rscd.`quantity`, cbd.`id_cart`, rscd.`id_cart` as service_id_cart, cbd.`id` as `htl_cart_booking_id` , cbd.`id_product` as `room_type_id_product`, cbd.`adults`, cbd.`children`, cbd.`date_from`, cbd.`date_to`'; if (!$getTotalPrice) { $sql .= ', pl.`name`, cbd.`id_guest`, cbd.`id_customer`, p.`auto_add_to_cart`, p.`price_addition_type`, @@ -233,7 +233,8 @@ class RoomTypeServiceProductCartDetail extends ObjectModel $sql .= ' LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (pl.`id_product` = p.`id_product` AND pl.`id_lang` = '.(int)$idLang.')'; } - $sql .= ' WHERE 1'; + + $sql .= ' WHERE 1 AND rscd.`id_product`!=0'; if (!is_null($autoAddToCart)) { $sql .= ' AND p.`auto_add_to_cart` = '. (int)$autoAddToCart; @@ -334,6 +335,7 @@ class RoomTypeServiceProductCartDetail extends ObjectModel 'name' => $product['name'], 'quantity' => $product['quantity'], 'auto_add_to_cart' => $product['auto_add_to_cart'], + 'id_cart' => $product['service_id_cart'], 'allow_multiple_quantity' => $product['allow_multiple_quantity'], 'price_addition_type' => $product['price_addition_type'], 'price_calculation_method' => $product['price_calculation_method'], @@ -449,6 +451,7 @@ class RoomTypeServiceProductCartDetail extends ObjectModel 'quantity' => $product['quantity'], 'auto_add_to_cart' => $product['auto_add_to_cart'], 'allow_multiple_quantity' => $product['allow_multiple_quantity'], + 'id_cart' => $product['service_id_cart'], 'price_addition_type' => $product['price_addition_type'], 'price_calculation_method' => $product['price_calculation_method'], 'unit_price_tax_excl' => ($objRoomTypeServiceProductPrice->getServicePrice( diff --git a/modules/hotelreservationsystem/classes/RoomTypeServiceProductOrderDetail.php b/modules/hotelreservationsystem/classes/RoomTypeServiceProductOrderDetail.php index d8a236f66..af16ab91b 100644 --- a/modules/hotelreservationsystem/classes/RoomTypeServiceProductOrderDetail.php +++ b/modules/hotelreservationsystem/classes/RoomTypeServiceProductOrderDetail.php @@ -247,6 +247,7 @@ class RoomTypeServiceProductOrderDetail extends ObjectModel 'id_order_detail' => $product['id_order_detail'], 'id_product' => $product['id_product'], 'name' => $product['name'], + 'id_cart' => $product['id_cart'], 'quantity' => $product['quantity'], 'allow_multiple_quantity' => $product['product_allow_multiple_quantity'], 'max_quantity' => $product['max_quantity'], @@ -272,6 +273,7 @@ class RoomTypeServiceProductOrderDetail extends ObjectModel 'id_order_detail' => $product['id_order_detail'], 'id_product' => $product['id_product'], 'name' => $product['name'], + 'id_cart' => $product['id_cart'], 'quantity' => $product['quantity'], 'allow_multiple_quantity' => $product['product_allow_multiple_quantity'], 'max_quantity' => $product['max_quantity'], @@ -314,4 +316,4 @@ class RoomTypeServiceProductOrderDetail extends ObjectModel // delete entry from order detail table. return parent::delete(); } -} \ No newline at end of file +} From a4ef6e60cd4faebf6f60546dc7ff866c92314b80 Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Thu, 13 Mar 2025 16:34:40 +0530 Subject: [PATCH 12/36] Added validation for impact value when impact type is percentage for the advance price rule --- .../controllers/admin/AdminHotelFeaturePricesSettings.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/modules/hotelreservationsystem/controllers/admin/AdminHotelFeaturePricesSettings.php b/modules/hotelreservationsystem/controllers/admin/AdminHotelFeaturePricesSettings.php index 7cd48a1ee..830d1a635 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminHotelFeaturePricesSettings.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminHotelFeaturePricesSettings.php @@ -480,6 +480,10 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController } else { if (!Validate::isPrice($impactValue)) { $this->errors[] = $this->l('Invalid value of impact value.'); + } else if ($priceImpactType == HotelRoomTypeFeaturePricing::IMPACT_TYPE_PERCENTAGE + && $impactValue > 100 // check if percentage added is greater then 100 + ) { + $this->errors[] = $this->l('Invalid value of impact value.'); } } @@ -651,6 +655,10 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController } else { if (!Validate::isPrice($impactValue)) { $this->errors[] = $this->l('Invalid value of impact value.'); + } else if ($priceImpactType == HotelRoomTypeFeaturePricing::IMPACT_TYPE_PERCENTAGE + && $impactValue > 100 // check if percentage added is greater then 100 + ) { + $this->errors[] = $this->l('Invalid value of impact value.'); } } From 7937f7d65c0f9bfa69ca57fe0b87448ae2644bea Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Mon, 14 Apr 2025 11:20:07 +0530 Subject: [PATCH 13/36] Update the url generate for the bulk update action, updated the form to retain the submitted values in case of any error --- .../admin/AdminHotelFeaturePricesSettings.php | 4 ++- .../helpers/form/form.tpl | 32 +++++++++---------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/modules/hotelreservationsystem/controllers/admin/AdminHotelFeaturePricesSettings.php b/modules/hotelreservationsystem/controllers/admin/AdminHotelFeaturePricesSettings.php index 830d1a635..a3b83fab1 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminHotelFeaturePricesSettings.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminHotelFeaturePricesSettings.php @@ -203,7 +203,7 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController parent::initToolbar(); if (empty($this->display) || $this->display == 'list') { $this->page_header_toolbar_btn['bulk_add'] = array( - 'href' => self::$currentIndex.'&add'.$this->table.'&bulkAdd'.$this->table.'&token='.$this->token, + 'href' => self::$currentIndex.'&bulkAdd'.$this->table.'&token='.$this->token, 'desc' => $this->l('Bulk create rules'), 'imgclass' => 'new' ); @@ -230,6 +230,8 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController parent::initProcess(); if (Tools::isSubmit('bulkAdd'.$this->table)) { self::$currentIndex = self::$currentIndex.'&bulkAdd'.$this->table.''; + $this->action = 'new'; + $this->display = 'add'; } if (Tools::isSubmit('submitBulkAdd'.$this->table)) { diff --git a/modules/hotelreservationsystem/views/templates/admin/hotel_feature_prices_settings/helpers/form/form.tpl b/modules/hotelreservationsystem/views/templates/admin/hotel_feature_prices_settings/helpers/form/form.tpl index a9c3c89a8..2382c30e0 100644 --- a/modules/hotelreservationsystem/views/templates/admin/hotel_feature_prices_settings/helpers/form/form.tpl +++ b/modules/hotelreservationsystem/views/templates/admin/hotel_feature_prices_settings/helpers/form/form.tpl @@ -93,17 +93,17 @@
-
date_selection_type) && $objFeaturePrice->date_selection_type != HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_SPECIFIC}style="display:none;"{/if}{else}style="display:none;"{/if}> +
date_selection_type) && $objFeaturePrice->date_selection_type != HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_SPECIFIC)}style="display:none;"{else if !isset($edit) && !isset($smarty.post.date_selection_type)}style="display:none;"{/if}> @@ -112,24 +112,24 @@
-
date_selection_type) && $objFeaturePrice->date_selection_type == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_SPECIFIC}style="display:none;"{/if}> +
date_selection_type) && $objFeaturePrice->date_selection_type == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_SPECIFIC) || (isset($smarty.post.date_selection_type) && $smarty.post.date_selection_type != HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_RANGE)}style="display:none;"{/if}>
- +
-
date_selection_type) && $objFeaturePrice->date_selection_type == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_SPECIFIC}style="display:none;"{/if}> +
date_selection_type) && $objFeaturePrice->date_selection_type == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_SPECIFIC) || (isset($smarty.post.date_selection_type) && $smarty.post.date_selection_type != HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_RANGE)}style="display:none;"{/if}>
- +
-
date_selection_type) && $objFeaturePrice->date_selection_type == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_SPECIFIC}style="display:none;"{/if}> +
date_selection_type) && $objFeaturePrice->date_selection_type == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_SPECIFIC) || (isset($smarty.post.date_selection_type) && $smarty.post.date_selection_type != HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_RANGE)}style="display:none;"{/if}>
is_special_days_exists) && $objFeaturePrice->is_special_days_exists)}style="display:block;"{/if}> -
{/foreach}
From abfadf76bf43138bdcbc5a4e40098c0a5e20e4f8 Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Fri, 25 Apr 2025 12:58:14 +0530 Subject: [PATCH 18/36] Added max char to the hotel short description textarea --- .../controllers/admin/AdminAddHotelController.php | 1 + .../views/templates/admin/add_hotel/helpers/form/form.tpl | 1 + 2 files changed, 2 insertions(+) diff --git a/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php b/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php index 09e879372..0065efa52 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php @@ -123,6 +123,7 @@ class AdminAddHotelController extends ModuleAdminController $smartyVars['currentLang'] = Language::getLanguage((int) $currentLangId); $smartyVars['defaultCurrency'] = Configuration::get('PS_CURRENCY_DEFAULT'); + $smartyVars['PS_SHORT_DESC_LIMIT'] = Configuration::get('PS_SHORT_DESC_LIMIT'); $countries = Country::getCountries($this->context->language->id, true); $smartyVars['country_var'] = $countries; diff --git a/modules/hotelreservationsystem/views/templates/admin/add_hotel/helpers/form/form.tpl b/modules/hotelreservationsystem/views/templates/admin/add_hotel/helpers/form/form.tpl index 0a70e1433..68766826c 100644 --- a/modules/hotelreservationsystem/views/templates/admin/add_hotel/helpers/form/form.tpl +++ b/modules/hotelreservationsystem/views/templates/admin/add_hotel/helpers/form/form.tpl @@ -150,6 +150,7 @@
From 5b7f51a9181a09daccfd810cbdde2c3769e613cc Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Fri, 25 Apr 2025 18:01:28 +0530 Subject: [PATCH 19/36] Added: Hotel address in the invoice, removed hotel column from the room type table --- classes/order/Order.php | 11 +++++++++++ classes/pdf/HTMLTemplateInvoice.php | 9 +++++++++ pdf/invoice.addresses-tab.tpl | 7 ++++++- pdf/invoice.product-tab.tpl | 8 +------- 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/classes/order/Order.php b/classes/order/Order.php index d479ac256..8899d7ea2 100644 --- a/classes/order/Order.php +++ b/classes/order/Order.php @@ -2857,6 +2857,17 @@ class OrderCore extends ObjectModel return $result; } + /** + * Get the Hotel Id of the order + * @return int|bool Hotel Id of the order + */ + public function getOrderHotelId() + { + return Db::getInstance()->getValue( + 'SELECT `id_hotel` FROM `'._DB_PREFIX_.'htl_booking_detail` WHERE `id_order` = '.(int) $this->id + ); + } + /** * @param bool $useTax: if true, total with tax, if false, total without tax * @param bool $withDiscounts: if true, total including discount, if false, total excluding discount diff --git a/classes/pdf/HTMLTemplateInvoice.php b/classes/pdf/HTMLTemplateInvoice.php index e2a82cbf0..4dbacf732 100644 --- a/classes/pdf/HTMLTemplateInvoice.php +++ b/classes/pdf/HTMLTemplateInvoice.php @@ -314,10 +314,18 @@ class HTMLTemplateInvoiceCore extends HTMLTemplate $service_product_data = array(); $room_extra_demands = array(); $room_additinal_services = array(); + $formattedHotelAddress = false; if (Module::isInstalled('hotelreservationsystem')) { $obj_htl_bk_dtl = new HotelBookingDetail(); $obj_rm_type = new HotelRoomType(); $objRoomTypeServiceProductOrderDetail = new RoomTypeServiceProductOrderDetail(); + $objHotelBranchInfo = new HotelBranchInformation((int) $order_obj->getOrderHotelId()); + // since hotel address has same firstname and lastname we are going to remove the lastname + $invoiceAddressPatternRules['avoid'] = array('lastname'); + if ($idHotelAddress = $objHotelBranchInfo->getHotelIdAddress()) { + $objHotelAddress = new Address((int) $idHotelAddress); + $formattedHotelAddress = AddressFormat::generateAddress($objHotelAddress, $invoiceAddressPatternRules, '
', ' '); + } $customer = new Customer($this->order->id_customer); if (!empty($order_details)) { @@ -591,6 +599,7 @@ class HTMLTemplateInvoiceCore extends HTMLTemplate 'cart_rules' => $cart_rules, 'delivery_address' => $formatted_delivery_address, 'invoice_address' => $formatted_invoice_address, + 'hotel_address' => $formattedHotelAddress, 'addresses' => array('invoice' => $invoice_address, 'delivery' => $delivery_address), 'tax_excluded_display' => $tax_excluded_display, 'display_product_images' => $display_product_images, diff --git a/pdf/invoice.addresses-tab.tpl b/pdf/invoice.addresses-tab.tpl index 0b743c4f0..fe6efc706 100644 --- a/pdf/invoice.addresses-tab.tpl +++ b/pdf/invoice.addresses-tab.tpl @@ -31,7 +31,12 @@ {$delivery_address} {/if} --> - + + {l s='Hotel Detail' pdf='true'}

+ {if $hotel_address} + {$hotel_address} + {/if} + {l s='Customer Detail' pdf='true'}

diff --git a/pdf/invoice.product-tab.tpl b/pdf/invoice.product-tab.tpl index d6721f5d9..ed6859cf6 100644 --- a/pdf/invoice.product-tab.tpl +++ b/pdf/invoice.product-tab.tpl @@ -27,14 +27,13 @@ - + {if $display_product_images} {/if} - {* {if isset($layout.before_discount)} @@ -62,11 +61,6 @@ {$data_v['name']}

- From 2dc5ca660ccb1d163c6d4e463f42c342d666717a Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Mon, 28 Apr 2025 10:01:10 +0530 Subject: [PATCH 20/36] Fixed: hotel name in not shown properly in the invoice, in hotel detail --- classes/pdf/HTMLTemplateInvoice.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/classes/pdf/HTMLTemplateInvoice.php b/classes/pdf/HTMLTemplateInvoice.php index 4dbacf732..f0e889a56 100644 --- a/classes/pdf/HTMLTemplateInvoice.php +++ b/classes/pdf/HTMLTemplateInvoice.php @@ -317,13 +317,12 @@ class HTMLTemplateInvoiceCore extends HTMLTemplate $formattedHotelAddress = false; if (Module::isInstalled('hotelreservationsystem')) { $obj_htl_bk_dtl = new HotelBookingDetail(); - $obj_rm_type = new HotelRoomType(); $objRoomTypeServiceProductOrderDetail = new RoomTypeServiceProductOrderDetail(); - $objHotelBranchInfo = new HotelBranchInformation((int) $order_obj->getOrderHotelId()); - // since hotel address has same firstname and lastname we are going to remove the lastname + $objHotelBranchInfo = new HotelBranchInformation((int) $order_obj->getOrderHotelId(), $this->context->language->id); $invoiceAddressPatternRules['avoid'] = array('lastname'); if ($idHotelAddress = $objHotelBranchInfo->getHotelIdAddress()) { $objHotelAddress = new Address((int) $idHotelAddress); + $objHotelAddress->firstname = $objHotelBranchInfo->hotel_name; $formattedHotelAddress = AddressFormat::generateAddress($objHotelAddress, $invoiceAddressPatternRules, '
', ' '); } From 58a66a441d69f9277bdcf45f2ed434c2d154fa82 Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Mon, 28 Apr 2025 19:22:02 +0530 Subject: [PATCH 21/36] optimized the multiple price rules creation flow --- .../admin/AdminHotelFeaturePricesSettings.php | 392 +++++------------- .../views/js/HotelReservationAdmin.js | 22 + .../helpers/form/form.tpl | 63 ++- 3 files changed, 179 insertions(+), 298 deletions(-) diff --git a/modules/hotelreservationsystem/controllers/admin/AdminHotelFeaturePricesSettings.php b/modules/hotelreservationsystem/controllers/admin/AdminHotelFeaturePricesSettings.php index a3b83fab1..d3f61a5cb 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminHotelFeaturePricesSettings.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminHotelFeaturePricesSettings.php @@ -202,11 +202,6 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController { parent::initToolbar(); if (empty($this->display) || $this->display == 'list') { - $this->page_header_toolbar_btn['bulk_add'] = array( - 'href' => self::$currentIndex.'&bulkAdd'.$this->table.'&token='.$this->token, - 'desc' => $this->l('Bulk create rules'), - 'imgclass' => 'new' - ); $this->page_header_toolbar_btn['new'] = array( 'href' => self::$currentIndex.'&add'.$this->table.'&token='.$this->token, 'desc' => $this->l('Add new rule'), @@ -216,34 +211,6 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController $this->toolbar_btn = array(); } - public function initToolbarTitle() - { - parent::initToolbarTitle(); - if (Tools::isSubmit('bulkAdd'.$this->table)) { - $this->toolbar_title[] = $this->l('Bulk Create', null, null, false); - $this->addMetaTitle($this->l('Bulk Create', null, null, false)); - } - } - - public function initProcess() - { - parent::initProcess(); - if (Tools::isSubmit('bulkAdd'.$this->table)) { - self::$currentIndex = self::$currentIndex.'&bulkAdd'.$this->table.''; - $this->action = 'new'; - $this->display = 'add'; - } - - if (Tools::isSubmit('submitBulkAdd'.$this->table)) { - if ($this->tabAccess['add'] === '1') { - $this->action = 'bulkSave'; - $this->display = 'list'; - } else { - $this->errors[] = Tools::displayError('You do not have permission to add this.'); - } - } - } - public function renderList() { $this->addRowAction('edit'); @@ -281,15 +248,7 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController $smartyVars['edit'] = 1; $smartyVars['feature_price_groups'] = $objFeaturePrice->getGroups($idFeaturePrice); - } - - $smartyVars['defaultcurrency_sign'] = $currencySign; - $smartyVars['date_from'] = $dateFrom; - $smartyVars['date_to'] = $dateTo; - $smartyVars['groups'] = Group::getGroups($this->context->language->id); - if (Tools::isSubmit('bulkAdd'.$this->table)) { - $this->submit_action = 'submitBulkAdd'.$this->table; - $smartyVars['bulk_add'] = true; + } else { $tree = new HelperTree('hotels-tree'); if ($treeData = HotelHelper::generateTreeData([ 'rootNode' => HotelHelper::NODE_HOTEL, @@ -313,12 +272,18 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController $smartyVars['hotel_tree'] = $tree->render(); } + $smartyVars['defaultcurrency_sign'] = $currencySign; + $smartyVars['date_from'] = $dateFrom; + $smartyVars['date_to'] = $dateTo; + $smartyVars['groups'] = Group::getGroups($this->context->language->id); + $this->context->smarty->assign($smartyVars); $this->fields_form = array( 'submit' => array( 'title' => $this->l('Save'), ), ); + return parent::renderForm(); } @@ -406,38 +371,66 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController $groups = Tools::getValue('groupBox'); $jsonSpecialDays = json_encode($specialDays); $defaultLangId = Configuration::get('PS_LANG_DEFAULT'); + $createMultiple = Tools::getValue('create_multiple'); + if (!$createMultiple) { + $roomTypeIds = array($roomTypeId); + } else { + $roomTypeIds = Tools::getValue('room_type_box'); + } $objFeaturePricing = new HotelRoomTypeFeaturePricing(); - if ($priceImpactWay == HotelRoomTypeFeaturePricing::IMPACT_WAY_FIX_PRICE) { $priceImpactType = HotelRoomTypeFeaturePricing::IMPACT_TYPE_FIXED_PRICE; } $languages = Language::getLanguages(false); $objDefaultLang = new language($defaultLangId); - - if (!Tools::getValue('feature_price_name_'.$defaultLangId)) { + if (!($priceRuleNameDefault = Tools::getValue('feature_price_name_'.$defaultLangId))) { $this->errors[] = sprintf( $this->l('Advanced price rule name is required at least in %s'), $objDefaultLang->name ); + } else { + if (preg_match('{room_type_name}', $priceRuleNameDefault)) { + $priceRuleNameDefault = str_replace('{room_type_name}', '%s', $priceRuleNameDefault); + } } + $validateRules = call_user_func( array('HotelRoomTypeFeaturePricing', 'getValidationRules'), 'HotelRoomTypeFeaturePricing' ); - foreach ($languages as $language) { - if (!Validate::isCatalogName(Tools::getValue('feature_price_name_'.$language['id_lang']))) { - $this->errors[] = $this->l('Advanced price rule name is invalid in ').$language['name']; - } elseif (Tools::strlen(Tools::getValue('feature_price_name_'.$language['id_lang'])) > $validateRules['sizeLang']['feature_price_name']) { - sprintf( - $this->l('Advanced price rule Name field is too long (%2$d chars max).'), - $validateRules['sizeLang']['feature_price_name'] - ); + $featurePricingName = array(); + if ($roomTypeIds) { + foreach ($roomTypeIds as $idRoomType) { + $objProduct = new Product((int) $idRoomType); + foreach ($languages as $lang) { + $priceRuleName = Tools::getValue('feature_price_name_'.$lang['id_lang']); + if ($priceRuleName) { + if (preg_match('{room_type_name}', $priceRuleName)) { + $priceRuleName = str_replace('{room_type_name}', $objProduct->name[$lang['id_lang']], $priceRuleName); + } + } + + if (!Validate::isCatalogName($priceRuleName)) { + $this->errors[] = $this->l('Advanced price rule name is invalid in ').$lang['name']; + } elseif (Tools::strlen($priceRuleName) > $validateRules['sizeLang']['feature_price_name']) { + $this->errors[] = sprintf( + $this->l('Advanced price rule Name field is too long (%d chars max).'), + $validateRules['sizeLang']['feature_price_name'] + ); + } + + if ($priceRuleName) { + $featurePricingName[$idRoomType][$lang['id_lang']] = $priceRuleName; + } else { + $featurePricingName[$idRoomType][$lang['id_lang']] = $priceRuleNameDefault; + } + } } } - if (!$roomTypeId) { + if (!$roomTypeId && !$createMultiple) { $this->errors[] = $this->l('Room is not selected. Please try again.'); } @@ -460,7 +453,7 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController $this->errors[] = $this->l('Invalid Date To.'); } if ($dateTo < $dateFrom) { - $this->errors[] = $this->l('Date To must be a date after Date From.'); + $this->errors[] = $this->l('Date To cannot be smaller than Date From.'); } if ($isSpecialDaysExists) { if (!isset($specialDays) || !$specialDays) { @@ -479,81 +472,87 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController if (!$impactValue) { $this->errors[] = $this->l('Please enter a valid impact value.'); - } else { - if (!Validate::isPrice($impactValue)) { - $this->errors[] = $this->l('Invalid value of impact value.'); - } else if ($priceImpactType == HotelRoomTypeFeaturePricing::IMPACT_TYPE_PERCENTAGE - && $impactValue > 100 // check if percentage added is greater then 100 - ) { - $this->errors[] = $this->l('Invalid value of impact value.'); - } + } else if (!Validate::isPrice($impactValue)) { + $this->errors[] = $this->l('Invalid value of impact value.'); + } else if ($priceImpactType == HotelRoomTypeFeaturePricing::IMPACT_TYPE_PERCENTAGE + && $impactValue > 100 // check if percentage added is greater then 100 + ) { + $this->errors[] = $this->l('Invalid value of impact value.'); } if (!(bool)$groups) { $this->errors[] = $this->l('Please select at least one group for the group access'); } - $isPlanTypeExists = 0; if ($isSpecialDaysExists && $jsonSpecialDays == 'false') { $this->errors[] = $this->l('Please select at least one day for week days restriction.'); - } else if (empty($this->errors)) { - $isPlanTypeExists = $this->validateExistingFeaturePrice( - $dateSelectionType, - $roomTypeId, - $dateFrom, - $dateTo, - $groups, - $idFeaturePrice, - $isSpecialDaysExists, - $jsonSpecialDays - ); } - if ($isPlanTypeExists) { - $this->errors[] = $this->l('An advanced price rule already exists in which some dates are common with this plan. Please select a different date range.'); - } else { - if (!count($this->errors)) { - if ($idFeaturePrice) { - $objFeaturePricing = new HotelRoomTypeFeaturePricing($idFeaturePrice); - } - $objFeaturePricing->id_product = $roomTypeId; - // lang fields - foreach ($languages as $language) { - if (Tools::getValue('feature_price_name_'.$language['id_lang'])) { - $objFeaturePricing->feature_price_name[$language['id_lang']] = Tools::getValue( - 'feature_price_name_'.$language['id_lang'] - ); - } else { - $objFeaturePricing->feature_price_name[$language['id_lang']] = Tools::getValue( - 'feature_price_name_'.$defaultLangId - ); - } - } - $objFeaturePricing->date_selection_type = $dateSelectionType; - $objFeaturePricing->date_from = $dateFrom; - $objFeaturePricing->date_to = $dateTo; - $objFeaturePricing->impact_way = $priceImpactWay; - $objFeaturePricing->is_special_days_exists = $isSpecialDaysExists; - $objFeaturePricing->special_days = $jsonSpecialDays; - $objFeaturePricing->impact_type = $priceImpactType; - $objFeaturePricing->impact_value = $impactValue; - $objFeaturePricing->active = $enableFeaturePrice; - // set the values of the groups for this feature price - $objFeaturePricing->groupBox = $groups; + if ($createMultiple && empty($roomTypeIds)) { + $this->errors[] = $this->l('Please select at least one room type for creating multiple price rules.'); + } else if (empty($this->errors)) { + foreach ($roomTypeIds as $idRoomType) { + $isPlanTypeExists = $this->validateExistingFeaturePrice( + $dateSelectionType, + $idRoomType, + $dateFrom, + $dateTo, + $groups, + $idFeaturePrice, + $isSpecialDaysExists, + $jsonSpecialDays + ); - if ($objFeaturePricing->save()) { - if (Tools::isSubmit('submitAdd'.$this->table.'AndStay')) { - Tools::redirectAdmin( - self::$currentIndex.'&id_feature_price='.(int) $objFeaturePricing->id. - '&update'.$this->table.'&conf=4&token='.$this->token - ); - } else { - Tools::redirectAdmin(self::$currentIndex.'&conf=4&token='.$this->token); - } + if ($isPlanTypeExists) { + $objProduct = new Product((int) $idRoomType, false, $this->context->language->id); + $this->errors[] = sprintf($this->l('An advanced price rule already exists for "%s" for the selected date range. Please select a different date range.'), $objProduct->name); + } + } + } + + if (!$isPlanTypeExists && !count($this->errors)) { + if ($idFeaturePrice) { + $objFeaturePricing = new HotelRoomTypeFeaturePricing($idFeaturePrice); + } + + // lang fields + $objFeaturePricing->date_selection_type = $dateSelectionType; + $objFeaturePricing->date_from = $dateFrom; + $objFeaturePricing->date_to = $dateTo; + $objFeaturePricing->impact_way = $priceImpactWay; + $objFeaturePricing->is_special_days_exists = $isSpecialDaysExists; + $objFeaturePricing->special_days = $jsonSpecialDays; + $objFeaturePricing->impact_type = $priceImpactType; + $objFeaturePricing->impact_value = $impactValue; + $objFeaturePricing->active = $enableFeaturePrice; + + // set the values of the groups for this feature price + $objFeaturePricing->groupBox = $groups; + $objFeaturePricing->id_product = $roomTypeId; + if ($createMultiple) { + foreach ($roomTypeIds as $idRoomType) { + $objFeaturePricing->id_product = $idRoomType; + $objFeaturePricing->feature_price_name = $featurePricingName[$idRoomType]; + $objFeaturePricing->add(); + } + + Tools::redirectAdmin(self::$currentIndex.'&conf=3&token='.$this->token); + } else { + $objFeaturePricing->feature_price_name = $featurePricingName[$roomTypeId]; + } + + if ($objFeaturePricing->save()) { + if (Tools::isSubmit('submitAdd'.$this->table.'AndStay')) { + Tools::redirectAdmin( + self::$currentIndex.'&id_feature_price='.(int) $objFeaturePricing->id. + '&update'.$this->table.'&conf=4&token='.$this->token + ); } else { - $this->errors[] = $this->l('Some error occured while saving advanced price rule.'); + Tools::redirectAdmin(self::$currentIndex.'&conf=4&token='.$this->token); } + } else { + $this->errors[] = $this->l('Some error occured while saving advanced price rule.'); } } if (isset($idFeaturePrice) && $idFeaturePrice) { @@ -563,167 +562,6 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController } } - public function processBulkSave() - { - $enableFeaturePrice = Tools::getValue('enable_feature_price'); - $roomTypeIds = Tools::getValue('room_type_box'); - $dateFrom = Tools::getValue('date_from'); - $dateTo = Tools::getValue('date_to'); - $isSpecialDaysExists = Tools::getValue('is_special_days_exists'); - $specialDays = Tools::getValue('special_days'); - $priceImpactWay = Tools::getValue('price_impact_way'); - $priceImpactType = Tools::getValue('price_impact_type'); - $impactValue = Tools::getValue('impact_value'); - $dateSelectionType = Tools::getValue('date_selection_type'); - $specificDate = date('Y-m-d', strtotime(Tools::getValue('specific_date'))); - $groups = Tools::getValue('groupBox'); - $jsonSpecialDays = json_encode($specialDays); - $defaultLangId = Configuration::get('PS_LANG_DEFAULT'); - - $objFeaturePricing = new HotelRoomTypeFeaturePricing(); - - if ($priceImpactWay == HotelRoomTypeFeaturePricing::IMPACT_WAY_FIX_PRICE) { - $priceImpactType = HotelRoomTypeFeaturePricing::IMPACT_TYPE_FIXED_PRICE; - } - - $languages = Language::getLanguages(false); - $objDefaultLang = new language($defaultLangId); - $featurePricingName = array(); - if (!Tools::getValue('feature_price_name_'.$defaultLangId)) { - $this->errors[] = sprintf( - $this->l('Advanced price rule name is required at least in %s'), - $objDefaultLang->name - ); - } - - $validateRules = call_user_func( - array('HotelRoomTypeFeaturePricing', 'getValidationRules'), - 'HotelRoomTypeFeaturePricing' - ); - foreach ($languages as $language) { - if (!Validate::isCatalogName(Tools::getValue('feature_price_name_'.$language['id_lang']))) { - $this->errors[] = $this->l('Advanced price rule name is invalid in ').$language['name']; - } elseif (Tools::strlen(Tools::getValue('feature_price_name_'.$language['id_lang'])) > $validateRules['sizeLang']['feature_price_name']) { - sprintf( - $this->l('Advanced price rule Name field is too long (%2$d chars max).'), - $validateRules['sizeLang']['feature_price_name'] - ); - } - - if (Tools::getValue('feature_price_name_'.$language['id_lang'])) { - $featurePricingName[$language['id_lang']] = Tools::getValue('feature_price_name_'.$language['id_lang']); - } else { - $featurePricingName[$language['id_lang']] = Tools::getValue('feature_price_name_'.$defaultLangId); - } - } - if ($dateSelectionType == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_SPECIFIC) { - $dateFrom = $specificDate; - $dateTo = date('Y-m-d', strtotime("+1 day", strtotime($specificDate))); - } else if ($dateSelectionType == HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_RANGE) { - if ($dateFrom == '') { - $this->errors[] = $this->l('Please choose Date from for the advanced price rule.'); - } - if ($dateTo == '') { - $this->errors[] = $this->l('Please choose Date to for the advanced price rule.'); - } - $dateFrom = date('Y-m-d', strtotime($dateFrom)); - $dateTo = date('Y-m-d', strtotime($dateTo)); - if (!Validate::isDate($dateFrom)) { - $this->errors[] = $this->l('Invalid Date From.'); - } - if (!Validate::isDate($dateTo)) { - $this->errors[] = $this->l('Invalid Date To.'); - } - if ($dateTo < $dateFrom) { - $this->errors[] = $this->l('Date To must be a date after Date From.'); - } - if ($isSpecialDaysExists) { - if (!isset($specialDays) || !$specialDays) { - $this->errors[] = $this->l('Please select at least one day for week days restriction.'); - } - } - } else { - if ($specificDate == '') { - $this->errors[] = $this->l('Please choose Date from for the advanced price rule.'); - } - $specificDate = date('Y-m-d', strtotime($specificDate)); - if (!Validate::isDate($specificDate)) { - $this->errors[] = $this->l('Invalid Date From.'); - } - } - - if (!$impactValue) { - $this->errors[] = $this->l('Please enter a valid impact value.'); - } else { - if (!Validate::isPrice($impactValue)) { - $this->errors[] = $this->l('Invalid value of impact value.'); - } else if ($priceImpactType == HotelRoomTypeFeaturePricing::IMPACT_TYPE_PERCENTAGE - && $impactValue > 100 // check if percentage added is greater then 100 - ) { - $this->errors[] = $this->l('Invalid value of impact value.'); - } - } - - if (!(bool)$groups) { - $this->errors[] = $this->l('Please select at least one group for the group access'); - } - - $isPlanTypeExists = 0; - if (empty($roomTypeIds)) { - $this->errors[] = $this->l('Please select at least one room type for bulk creation process.'); - } else if (empty($this->errors)) { - if ($isSpecialDaysExists && $jsonSpecialDays == 'false') { - $this->errors[] = $this->l('Please select at least one day for week days restriction.'); - } else { - foreach ($roomTypeIds as $roomTypeId) { - $isPlanTypeExists = $this->validateExistingFeaturePrice( - $dateSelectionType, - $roomTypeId, - $dateFrom, - $dateTo, - $groups, - 0, - $isSpecialDaysExists, - $jsonSpecialDays - ); - - if ($isPlanTypeExists) { - $objProduct = new Product((int) $roomTypeId, false, $this->context->language->id); - $this->errors[] = sprintf($this->l('An advanced price rule already exists for "%s" for the selected date range. Please select a different date range.'), $objProduct->name); - } - } - } - - if (empty($this->errors)) { - $res = true; - foreach ($roomTypeIds as $roomTypeId) { - $objFeaturePricing = new HotelRoomTypeFeaturePricing(); - $objFeaturePricing->id_product = $roomTypeId; - $objFeaturePricing->feature_price_name = $featurePricingName; - $objFeaturePricing->date_selection_type = $dateSelectionType; - $objFeaturePricing->date_from = $dateFrom; - $objFeaturePricing->date_to = $dateTo; - $objFeaturePricing->impact_way = $priceImpactWay; - $objFeaturePricing->is_special_days_exists = $isSpecialDaysExists; - $objFeaturePricing->special_days = $jsonSpecialDays; - $objFeaturePricing->impact_type = $priceImpactType; - $objFeaturePricing->impact_value = $impactValue; - $objFeaturePricing->active = $enableFeaturePrice; - - // set the values of the groups for this feature price - $objFeaturePricing->groupBox = $groups; - $res &= $objFeaturePricing->save(); - } - - Tools::redirectAdmin($this->context->link->getAdminLink('AdminHotelFeaturePricesSettings').'&conf=4&token='.$this->token); - } - } - - if (!empty($this->errors)) { - $this->display = 'add'; - } - } - public function ajaxProcessSearchProductByName() { $response = array('status' => 'failed'); diff --git a/modules/hotelreservationsystem/views/js/HotelReservationAdmin.js b/modules/hotelreservationsystem/views/js/HotelReservationAdmin.js index 1e3bc80b5..802a4d99c 100644 --- a/modules/hotelreservationsystem/views/js/HotelReservationAdmin.js +++ b/modules/hotelreservationsystem/views/js/HotelReservationAdmin.js @@ -569,6 +569,28 @@ $(document).ready(function() { /* ---- AdminHotelFeaturePricesSettingsController Admin ---- */ + if ($('input[name="create_multiple"]:checked').val() == 1) { + $('.room-type-name').hide(); + $('.room-type-name-tree').show(); + $('[name="submitAddhtl_room_type_feature_pricingAndStay"]').hide(); + } else { + $('.room-type-name').show(); + $('[name="submitAddhtl_room_type_feature_pricingAndStay"]').show(); + $('.room-type-name-tree').hide(); + } + + $(document).on('change', 'input[name="create_multiple"]', function() { + if ($('input[name="create_multiple"]:checked').val() == 1) { + $('.room-type-name').hide(); + $('.room-type-name-tree').show(); + $('[name="submitAddhtl_room_type_feature_pricingAndStay"]').hide(); + } else { + $('.room-type-name').show(); + $('[name="submitAddhtl_room_type_feature_pricingAndStay"]').show(); + $('.room-type-name-tree').hide(); + } + }); + $('#date_selection_type').on('change', function() { if ($('#date_selection_type').val() == date_selection_types.specific) { $(".specific_date_type").show(200); diff --git a/modules/hotelreservationsystem/views/templates/admin/hotel_feature_prices_settings/helpers/form/form.tpl b/modules/hotelreservationsystem/views/templates/admin/hotel_feature_prices_settings/helpers/form/form.tpl index ca2d0340e..ac5bac0b4 100644 --- a/modules/hotelreservationsystem/views/templates/admin/hotel_feature_prices_settings/helpers/form/form.tpl +++ b/modules/hotelreservationsystem/views/templates/admin/hotel_feature_prices_settings/helpers/form/form.tpl @@ -57,36 +57,57 @@ {/if} +
+ {l s='Use {room_type_name} to generate dynamic feature price names.' mod='hotelreservationsystem'} +
- {if isset($bulk_add)} -
-
{l s='Rooms Details' pdf='true'}{l s='Rooms Details' pdf='true'}
{l s='Room Image' pdf='true'}{l s='Room Description' pdf='true'}{l s='Hotel' pdf='true'} {l s='Tax Rate(s)' pdf='true'}{l s='Base price' pdf='true'}
{l s='(Tax excl.)' pdf='true'}
-

- {$data_v['hotel_name']} -

-
{$data_v['order_detail_tax_label']}