From d2c94913853ff575a3c9a5d7255820244890f182 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Tue, 19 Jul 2022 15:32:17 +0530 Subject: [PATCH] Add price modification for new orders at back office --- .../orders/_current_cart_details_data.tpl | 16 +- .../controllers/orders/_new_product.tpl | 4 +- .../controllers/orders/_product_line.tpl | 19 +- .../template/controllers/orders/form.tpl | 92 +++++---- .../controllers/orders/helpers/view/view.tpl | 2 +- classes/Cart.php | 18 +- classes/PaymentModule.php | 22 ++- controllers/admin/AdminCartsController.php | 72 +++++-- controllers/admin/AdminOrdersController.php | 187 ++++++++++++------ js/admin/orders.js | 4 + .../classes/HotelBookingDetail.php | 56 +++--- .../classes/HotelCartBookingData.php | 76 +++++-- .../classes/HotelReservationSystemDb.php | 3 + .../classes/HotelRoomTypeFeaturePricing.php | 61 +++++- .../admin/AdminHotelFeaturePricesSettings.php | 13 +- .../AdminHotelRoomsBookingController.php | 34 ++-- .../views/js/HotelReservationAdmin.js | 33 ++-- .../helpers/form/form.tpl | 6 +- 18 files changed, 505 insertions(+), 213 deletions(-) diff --git a/admin/themes/default/template/controllers/orders/_current_cart_details_data.tpl b/admin/themes/default/template/controllers/orders/_current_cart_details_data.tpl index adac13275..93727824a 100644 --- a/admin/themes/default/template/controllers/orders/_current_cart_details_data.tpl +++ b/admin/themes/default/template/controllers/orders/_current_cart_details_data.tpl @@ -59,12 +59,12 @@ {$data.date_from|escape:'html':'UTF-8'|date_format:"%d-%m-%Y"} -  {$data.date_to|escape:'html':'UTF-8'|date_format:"%d-%m-%Y"} -   - - {displayPrice price=$data.feature_price_tax_excl|escape:'html':'UTF-8'} - + {if $data.feature_price_diff != 0} + {assign var=shown_room_type_price value=$data.feature_price_tax_excl} + {else} + {assign var=shown_room_type_price value=$data.product_price_tax_excl} + {/if} + {if isset($data.extra_demands) && $data.extra_demands} @@ -73,8 +73,8 @@ {displayPrice price=0} {/if} - {displayPrice price=$data.amt_with_qty} - + {displayPrice price=$data.amt_with_qty} + {if isset($data.extra_demands) && $data.extra_demands} {displayPrice price=$data.amt_with_qty|escape:'html':'UTF-8'+$data.demand_price|escape:'html':'UTF-8'} {else} diff --git a/admin/themes/default/template/controllers/orders/_new_product.tpl b/admin/themes/default/template/controllers/orders/_new_product.tpl index 26c5708f6..e67cc63ff 100644 --- a/admin/themes/default/template/controllers/orders/_new_product.tpl +++ b/admin/themes/default/template/controllers/orders/_new_product.tpl @@ -69,7 +69,7 @@
{if $currency->format % 2}
{$currency->sign} {l s='tax excl.'}
{/if} - + {if !($currency->format % 2)}
{$currency->sign} {l s='tax excl.'}
{/if}
@@ -77,7 +77,7 @@
{if $currency->format % 2}
{$currency->sign} {l s='tax incl.'}
{/if} - + {if !($currency->format % 2)}
{$currency->sign} {l s='tax incl.'}
{/if}
diff --git a/admin/themes/default/template/controllers/orders/_product_line.tpl b/admin/themes/default/template/controllers/orders/_product_line.tpl index be6cdb1d3..73cd706ae 100644 --- a/admin/themes/default/template/controllers/orders/_product_line.tpl +++ b/admin/themes/default/template/controllers/orders/_product_line.tpl @@ -80,12 +80,19 @@ -   - - {convertPriceWithCurrency price=$data.paid_unit_price_tax_incl currency=$currency->id} - + + {if $data.feature_price_diff != 0} + + {convertPriceWithCurrency price=$data.unit_price_without_reduction_tax_excl currency=$currency->id} +   + {/if} + + {convertPriceWithCurrency price=$data.paid_unit_price_tax_excl currency=$currency->id} + + + {convertPriceWithCurrency price=$data.amt_with_qty_tax_incl currency=$currency->id} diff --git a/admin/themes/default/template/controllers/orders/form.tpl b/admin/themes/default/template/controllers/orders/form.tpl index e580593cb..1d80ec936 100644 --- a/admin/themes/default/template/controllers/orders/form.tpl +++ b/admin/themes/default/template/controllers/orders/form.tpl @@ -237,11 +237,19 @@ $(this).change(); return true; }); - $('.product_unit_price').live('change', function(e) { + $(document).on('change', '.room_unit_price', function(e) { e.preventDefault(); - var product = $(this).attr('rel').split('_'); - updateProductPrice(product[0], product[1], $(this).val()); - }); + var cart_row = $(this).closest('tr'); + var params = { + id_booking_data: parseInt($(this).attr('data-id-booking-data')), + id_product: parseInt($(this).attr('data-id-product')), + id_room: parseInt($(this).attr('data-id-room')), + date_from: $(this).attr('data-date-from'), + date_to: $(this).attr('data-date-to'), + price: $(this).val(), + }; + updateProductPrice(params, cart_row); + }) $('#order_message').live('change', function(e) { e.preventDefault(); $.ajax({ @@ -381,31 +389,45 @@ }); } - function updateProductPrice(id_product, id_product_attribute, new_price) - { + function updateProductPrice(params, cart_row) { + $.extend(params, { + id_cart: id_cart, + price: new Number(params.price.replace(",",".")).toFixed(4).toString(), + }); + $.ajax({ type:"POST", url: "{$link->getAdminLink('AdminCarts')|addslashes}", async: true, - dataType: "json", - data : { + dataType: "JSON", + data: { ajax: "1", token: "{getAdminToken tab='AdminCarts'}", tab: "AdminCarts", action: "updateProductPrice", - id_cart: id_cart, - id_product: id_product, - id_product_attribute: id_product_attribute, - id_customer: id_customer, - price: new Number(new_price.replace(",",".")).toFixed(4).toString() - }, - success : function(res) - { - displaySummary(res); + params: params, + }, + success : function(response) { + updateCartLine(response.curr_booking_info, cart_row); + updateCartSummaryData(response.cart_info); } }); } + function updateCartLine(data, cart_row) { + $(cart_row).find('.cart_line_total_rooms_price').html(data.amt_with_qty); + $(cart_row).find('.cart_line_total_price').html(data.total_price); + } + + function updateCartSummaryData(summaryData) { + $('#total_products').html(formatCurrency(parseFloat(summaryData.summary.total_products), currency_format, currency_sign, currency_blank)); + $('#total_extra_demands').html(formatCurrency(parseFloat(summaryData.summary.total_extra_demands_tax_exc), currency_format, currency_sign, currency_blank)); + $('#total_vouchers').html(formatCurrency(parseFloat(summaryData.summary.total_discounts_tax_exc), currency_format, currency_sign, currency_blank)); + $('#total_without_taxes').html(formatCurrency(parseFloat(summaryData.summary.total_price_without_tax), currency_format, currency_sign, currency_blank)); + $('#total_taxes').html(formatCurrency(parseFloat(summaryData.summary.total_tax), currency_format, currency_sign, currency_blank)); + $('#total_with_taxes').html(formatCurrency(parseFloat(summaryData.summary.total_price), currency_format, currency_sign, currency_blank)); + } + function displayQtyInStock(id) { var id_product = $('#id_product').val(); @@ -559,7 +581,6 @@ }); } - function setupCustomer(idCustomer) { //$('#carts').show();// by webkul @@ -863,8 +884,7 @@ return price; } - function displaySummary(jsonSummary) - { + function displaySummary(jsonSummary) { currency_format = jsonSummary.currency.format; currency_sign = jsonSummary.currency.sign; currency_blank = jsonSummary.currency.blank; @@ -874,37 +894,37 @@ updateCartVouchers(jsonSummary.summary.discounts); updateAddressesList(jsonSummary.addresses, jsonSummary.cart.id_address_delivery, jsonSummary.cart.id_address_invoice); - if (!jsonSummary.summary.products.length || !jsonSummary.addresses.length || !jsonSummary.delivery_option_list) + if (!jsonSummary.summary.products.length || !jsonSummary.addresses.length || !jsonSummary.delivery_option_list) { $('#carriers_part').hide(); - else + } else { $('#carriers_part').hide(); - - //original - /*if (!jsonSummary.summary.products.length || !jsonSummary.addresses.length || !jsonSummary.delivery_option_list) - $('#carriers_part,#summary_part').hide(); - else - $('#carriers_part,#summary_part').hide(); - */ + } updateDeliveryOptionList(jsonSummary.delivery_option_list); checkVirtualProduct(jsonSummary.summary.products,jsonSummary.delivery_option_list); - if (jsonSummary.cart.gift == 1) + if (jsonSummary.cart.gift == 1) { $('#order_gift').attr('checked', true); - else + } else { $('#carrier_gift').removeAttr('checked'); - if (jsonSummary.cart.recyclable == 1) + } + if (jsonSummary.cart.recyclable == 1) { $('#carrier_recycled_package').attr('checked', true); - else + } else { $('#carrier_recycled_package').removeAttr('checked'); - if (jsonSummary.free_shipping == 1) + } + if (jsonSummary.free_shipping == 1) { $('#free_shipping').attr('checked', true); - else + } else { $('#free_shipping_off').attr('checked', true); + } $('#gift_message').html(jsonSummary.cart.gift_message); - if (!changed_shipping_price) + + if (!changed_shipping_price) { $('#shipping_price').html('' + formatCurrency(parseFloat(jsonSummary.summary.total_shipping), currency_format, currency_sign, currency_blank) + ''); + } + shipping_price_selected_carrier = jsonSummary.summary.total_shipping; $('#total_vouchers').html(formatCurrency(parseFloat(jsonSummary.summary.total_discounts_tax_exc), currency_format, currency_sign, currency_blank)); diff --git a/admin/themes/default/template/controllers/orders/helpers/view/view.tpl b/admin/themes/default/template/controllers/orders/helpers/view/view.tpl index 6922cff6d..15a2ef097 100644 --- a/admin/themes/default/template/controllers/orders/helpers/view/view.tpl +++ b/admin/themes/default/template/controllers/orders/helpers/view/view.tpl @@ -977,7 +977,7 @@ {l s='Room Type'} {l s='Hotel Name'} {l s='Duration'} - {l s='Unit Price (Tax incl.)'} + {l s='Unit Price (Tax excl.)'} {l s='Total Price (Tax incl.)'} {if isset($refundReqBookings) && $refundReqBookings} {l s='Refund State'} diff --git a/classes/Cart.php b/classes/Cart.php index 9d08d6834..18b2c15cf 100644 --- a/classes/Cart.php +++ b/classes/Cart.php @@ -746,7 +746,16 @@ class CartCore extends ObjectModel $totalPriceByProductTaxExcl = 0; $priceDisplay = Group::getPriceDisplayMethod(Group::getCurrent()->id); foreach ($roomTypesByIdProduct as $key => $cartRoomInfo) { - $roomTotalPrice = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice($cartRoomInfo['id_product'], $cartRoomInfo['date_from'], $cartRoomInfo['date_to']); + $roomTotalPrice = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice( + $cartRoomInfo['id_product'], + $cartRoomInfo['date_from'], + $cartRoomInfo['date_to'], + 0, + Group::getCurrent()->id, + $cartRoomInfo['id_cart'], + $cartRoomInfo['id_guest'], + $cartRoomInfo['id_room'] + ); $totalPriceByProductTaxIncl += $roomTotalPrice['total_price_tax_incl']; $totalPriceByProductTaxExcl += $roomTotalPrice['total_price_tax_excl']; } @@ -1637,7 +1646,12 @@ class CartCore extends ObjectModel $roomTotalPrice = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice( $cartRoomInfo['id_product'], $cartRoomInfo['date_from'], - $cartRoomInfo['date_to'] + $cartRoomInfo['date_to'], + 0, + Group::getCurrent()->id, + $cartRoomInfo['id_cart'], + $cartRoomInfo['id_guest'], + $cartRoomInfo['id_room'] ); if ($with_taxes) { $totalPriceByProduct += $roomTotalPrice['total_price_tax_incl']; diff --git a/classes/PaymentModule.php b/classes/PaymentModule.php index 1e09d31e7..f205520e3 100644 --- a/classes/PaymentModule.php +++ b/classes/PaymentModule.php @@ -689,7 +689,7 @@ abstract class PaymentModuleCore extends Module } } - // update order in hlt tables + // update order in htl tables $objCartBookingData = new HotelCartBookingData(); $objBookingDetail = new HotelBookingDetail(); $objRoomType = new HotelRoomType(); @@ -731,7 +731,12 @@ abstract class PaymentModuleCore extends Module $total_price = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice( $idProduct, $objCartBookingData->date_from, - $objCartBookingData->date_to + $objCartBookingData->date_to, + 0, + Group::getCurrent()->id, + $objCartBookingData->id_cart, + $objCartBookingData->id_guest, + $objCartBookingData->id_room ); $objBookingDetail->date_from = $objCartBookingData->date_from; $objBookingDetail->date_to = $objCartBookingData->date_to; @@ -752,11 +757,11 @@ abstract class PaymentModuleCore extends Module $objBookingDetail->check_in_time = $objHotelBranch->check_in; $objBookingDetail->check_out_time = $objHotelBranch->check_out; if ($hotelAddress = $objHotelBranch->getAddress($objCartBkData->id_hotel)) { - $objHtlBkDtl->city = $hotelAddress['city']; - $objHtlBkDtl->state = $hotelAddress['state']; - $objHtlBkDtl->country = $hotelAddress['country']; - $objHtlBkDtl->zipcode = $hotelAddress['postcode']; - $objHtlBkDtl->phone = $hotelAddress['phone']; + $objBookingDetail->city = $hotelAddress['city']; + $objBookingDetail->state = $hotelAddress['state']; + $objBookingDetail->country = $hotelAddress['country']; + $objBookingDetail->zipcode = $hotelAddress['postcode']; + $objBookingDetail->phone = $hotelAddress['phone']; } } if ($roomTypeInfo = $objRoomType->getRoomTypeInfoByIdProduct($idProduct)) { @@ -843,6 +848,9 @@ abstract class PaymentModuleCore extends Module } } + // delete cart feature prices after booking creation success + HotelRoomTypeFeaturePricing::deleteByIdCart($cart->id); + if (isset($_COOKIE['wk_id_cart'])) { setcookie('wk_id_cart', ' ', time() - 86400, '/'); setcookie('wk_id_guest', ' ', time() - 86400, '/'); diff --git a/controllers/admin/AdminCartsController.php b/controllers/admin/AdminCartsController.php index ebd03b7a4..2b7b9323b 100644 --- a/controllers/admin/AdminCartsController.php +++ b/controllers/admin/AdminCartsController.php @@ -884,26 +884,60 @@ class AdminCartsControllerCore extends AdminController public function ajaxProcessUpdateProductPrice() { + $params = Tools::getValue('params'); + $id_booking_data = (int) $params['id_booking_data']; + $id_cart = (int) $params['id_cart']; + $id_product = (int) $params['id_product']; + $id_room = (int) $params['id_room']; + $date_from = $params['date_from']; + $date_to = $params['date_to']; + $price = (float) $params['price']; + + $this->context->cart = new Cart($id_cart); + + $date_from = date('Y-m-d', strtotime($date_from)); + $date_to = date('Y-m-d', strtotime($date_to)); + if ($this->tabAccess['edit'] === '1') { - SpecificPrice::deleteByIdCart((int)$this->context->cart->id, (int)Tools::getValue('id_product'), (int)Tools::getValue('id_product_attribute')); - $specific_price = new SpecificPrice(); - $specific_price->id_cart = (int)$this->context->cart->id; - $specific_price->id_shop = 0; - $specific_price->id_shop_group = 0; - $specific_price->id_currency = 0; - $specific_price->id_country = 0; - $specific_price->id_group = 0; - $specific_price->id_customer = (int)$this->context->customer->id; - $specific_price->id_product = (int)Tools::getValue('id_product'); - $specific_price->id_product_attribute = (int)Tools::getValue('id_product_attribute'); - $specific_price->price = (float)Tools::getValue('price'); - $specific_price->from_quantity = 1; - $specific_price->reduction = 0; - $specific_price->reduction_type = 'amount'; - $specific_price->from = '0000-00-00 00:00:00'; - $specific_price->to = '0000-00-00 00:00:00'; - $specific_price->add(); - echo json_encode($this->ajaxReturnVars()); + HotelRoomTypeFeaturePricing::deleteByIdCart($id_cart, $id_product, $id_room, $date_from, $date_to); + $feature_price_name = array(); + foreach (Language::getIDs(true) as $id_lang) { + $feature_price_name[$id_lang] = 'Auto-generated'; + } + + $hrt_feature_price = new HotelRoomTypeFeaturePricing(); + $hrt_feature_price->id_product = $id_product; + $hrt_feature_price->id_cart = $id_cart; + $hrt_feature_price->id_guest = (int) $this->context->cookie->id_guest; + $hrt_feature_price->id_room = $id_room; + $hrt_feature_price->feature_price_name = $feature_price_name; + $hrt_feature_price->date_selection_type = 1; // date range + $hrt_feature_price->date_from = $date_from; + $hrt_feature_price->date_to = $date_to; + $hrt_feature_price->is_special_days_exists = 0; + $hrt_feature_price->special_days = json_encode(false); + $hrt_feature_price->impact_way = 3; // fix price + $hrt_feature_price->impact_type = 2; // fixed price + $hrt_feature_price->impact_value = $price; + $hrt_feature_price->active = 1; + $hrt_feature_price->groupBox = array_column(Group::getGroups($this->context->language->id), 'id_group'); + $hrt_feature_price->add(); + + $objHotelCartBookingData = new HotelCartBookingData(); + $bookingsInfo = $objHotelCartBookingData->getCartFormatedBookinInfoByIdCart($id_cart); + foreach ($bookingsInfo as &$bookingInfo) { + if ($bookingInfo['id'] == $id_booking_data) { + $amt_with_qty = $bookingInfo['amt_with_qty']; + $bookingInfo['amt_with_qty'] = Tools::displayPrice($amt_with_qty); + $bookingInfo['total_price'] = Tools::displayPrice($amt_with_qty + $bookingInfo['demand_price']); + $response = array( + 'curr_booking_info' => $bookingInfo, + 'cart_info' => $this->ajaxReturnVars(), + ); + + die(json_encode($response)); + } + } } } diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index bd92223cb..b7864c952 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -159,7 +159,7 @@ class AdminOrdersControllerCore extends AdminController 'remove_onclick' => true ) )); - + $this->shopLinkType = 'shop'; $this->shopShareDatas = Shop::SHARE_ORDER; @@ -1867,6 +1867,35 @@ class AdminOrdersControllerCore extends AdminController $this->context->cart = $cart; $this->context->customer = new Customer($order->id_customer); + // always add taxes even if there are not displayed to the customer + $use_taxes = true; + $initial_product_price_tax_incl = Product::getPriceStatic( + $product->id, + $use_taxes, + isset($combination) ? $combination->id : null, + 2, + null, + false, + true, + 1, + false, + $order->id_customer, + $cart->id, + $order->{Configuration::get('PS_TAX_ADDRESS_TYPE', null, null, $order->id_shop)} + ); + + // creatie feature pricec if needed + $createFeaturePrice = $product_informations['product_price_tax_incl'] != $initial_product_price_tax_incl; + $featurePriceParams = array(); + if ($createFeaturePrice) { + $featurePriceParams = array( + 'id_cart' => $this->context->cart->id, + 'id_guest' => $this->context->cookie->id_guest, + 'price' => $product_informations['product_price_tax_excl'], + 'id_product' => $product->id, + ); + } + /*By Webkul to make entries in HotelCartBookingData */ $hotel_room_info_arr = $hotel_room_data['rm_data'][0]['data']['available']; $chkQty = 0; @@ -1887,54 +1916,19 @@ class AdminOrdersControllerCore extends AdminController $obj_htl_cart_booking_data->date_to = $date_to; $obj_htl_cart_booking_data->save(); ++$chkQty; + + // create feature price if needed + if ($createFeaturePrice) { + $featurePriceParams['id_room'] = $room_info['id_room']; + $featurePriceParams = array_merge($featurePriceParams, array('date_from' => $date_from, 'date_to' => $date_to)); + $this->createFeaturePrice($featurePriceParams); + } } else { break; } } } /*END*/ - // always add taxes even if there are not displayed to the customer - $use_taxes = true; - - $initial_product_price_tax_incl = Product::getPriceStatic( - $product->id, - $use_taxes, - isset($combination) ? $combination->id : null, - 2, - null, - false, - true, - 1, - false, - $order->id_customer, - $cart->id, - $order->id_address_tax - ); - - // Creating specific price if needed - if ($product_informations['product_price_tax_incl'] != $initial_product_price_tax_incl) { - $specific_price = new SpecificPrice(); - $specific_price->id_shop = 0; - $specific_price->id_shop_group = 0; - $specific_price->id_currency = 0; - $specific_price->id_country = 0; - $specific_price->id_group = 0; - $specific_price->id_customer = $order->id_customer; - $specific_price->id_product = $product->id; - if (isset($combination)) { - $specific_price->id_product_attribute = $combination->id; - } else { - $specific_price->id_product_attribute = 0; - } - $specific_price->price = $product_informations['product_price_tax_excl']; - $specific_price->from_quantity = 1; - $specific_price->reduction = 0; - $specific_price->reduction_type = 'amount'; - $specific_price->reduction_tax = 0; - $specific_price->from = '0000-00-00 00:00:00'; - $specific_price->to = '0000-00-00 00:00:00'; - $specific_price->add(); - } // Add product to cart $update_quantity = $cart->updateQty( @@ -2079,11 +2073,6 @@ class AdminOrdersControllerCore extends AdminController // Update Tax lines $order_detail->updateTaxAmount($order); - // Delete specific price if exists - if (isset($specific_price)) { - $specific_price->delete(); - } - $products = $this->getProducts($order); // Get the last product @@ -2199,7 +2188,18 @@ class AdminOrdersControllerCore extends AdminController $objHtlBkDtl->date_from = $obj_cart_bk_data->date_from; $objHtlBkDtl->date_to = $obj_cart_bk_data->date_to; - $total_price = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice($idProduct, $obj_cart_bk_data->date_from, $obj_cart_bk_data->date_to); + + $total_price = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice( + $idProduct, + $obj_cart_bk_data->date_from, + $obj_cart_bk_data->date_to, + 0, + Group::getCurrent()->id, + $this->context->cart->id, + $this->context->cookie->id_guest, + $obj_cart_bk_data->id_room + ); + $objHtlBkDtl->total_price_tax_excl = $total_price['total_price_tax_excl']; $objHtlBkDtl->total_price_tax_incl = $total_price['total_price_tax_incl']; $objHtlBkDtl->total_paid_amount = Tools::ps_round($total_price['total_price_tax_incl'], 5); @@ -2232,6 +2232,9 @@ class AdminOrdersControllerCore extends AdminController } } + // delete cart feature prices after room addition success + HotelRoomTypeFeaturePricing::deleteByIdCart($cart->id); + die(json_encode(array( 'result' => true, //'view' => $this->createTemplate('_product_line.tpl')->fetch(), @@ -2294,12 +2297,40 @@ class AdminOrdersControllerCore extends AdminController ))); } + protected function createFeaturePrice($params) + { + $feature_price_name = array(); + foreach (Language::getIDs(true) as $id_lang) { + $feature_price_name[$id_lang] = 'Auto-generated'; + } + + $hrt_feature_price = new HotelRoomTypeFeaturePricing(); + $hrt_feature_price->id_product = (int) $params['id_product']; + $hrt_feature_price->id_cart = (int) $params['id_cart']; + $hrt_feature_price->id_guest = (int) $params['id_guest']; + $hrt_feature_price->id_room = (int) $params['id_room']; + $hrt_feature_price->feature_price_name = $feature_price_name; + $hrt_feature_price->date_selection_type = 1; // date range + $hrt_feature_price->date_from = date('Y-m-d', strtotime($params['date_from'])); + $hrt_feature_price->date_to = date('Y-m-d', strtotime($params['date_to'])); + $hrt_feature_price->is_special_days_exists = 0; + $hrt_feature_price->special_days = json_encode(false); + $hrt_feature_price->impact_way = 3; // fix price + $hrt_feature_price->impact_type = 2; // fixed price + $hrt_feature_price->impact_value = $params['price']; + $hrt_feature_price->active = 1; + $hrt_feature_price->groupBox = array_column(Group::getGroups($this->context->language->id), 'id_group'); + $hrt_feature_price->add(); + } + public function ajaxProcessEditProductOnOrder() { // Return value $res = true; $id_order = (int) Tools::getValue('id_order'); $order = new Order($id_order); + $cart = new Cart($order->id_cart); + $customer = new Cart($order->id_customer); //$order_detail = new OrderDetail((int)Tools::getValue('product_id_order_detail')); $order_detail = new OrderDetail((int) Tools::getValue('order_detail_id'));//by webkul id_order_detail from our table $this->doEditProductValidation($order_detail, $order, isset($order_invoice) ? $order_invoice : null); @@ -2316,11 +2347,12 @@ class AdminOrdersControllerCore extends AdminController $id_hotel = trim(Tools::getValue('id_hotel')); $id_room = trim(Tools::getValue('id_room')); $id_product = trim(Tools::getValue('id_product')); + $room_unit_price = trim(Tools::getValue('room_unit_price')); $obj_booking_detail = new HotelBookingDetail(); $product_quantity = (int) $obj_booking_detail->getNumberOfDays($new_date_from, $new_date_to); $old_product_quantity = (int) $obj_booking_detail->getNumberOfDays($old_date_from, $old_date_to); $qty_diff = $product_quantity - $old_product_quantity; - + /*By webkul to validate fields before deleting the cart and order data form the tables*/ if ($id_hotel == '') { die(json_encode(array( @@ -2362,6 +2394,16 @@ class AdminOrdersControllerCore extends AdminController 'result' => false, 'error' => Tools::displayError('Check out Date Should be after Check In date.'), ))); + } elseif ($room_unit_price == '') { + die(json_encode(array( + 'result' => false, + 'error' => Tools::displayError('Please enter unit price.'), + ))); + } elseif (!Validate::isPrice($room_unit_price)) { + die(json_encode(array( + 'result' => false, + 'error' => Tools::displayError('Please enter a valid unit price.'), + ))); } elseif (!Validate::isUnsignedInt($product_quantity)) { die(json_encode(array( 'result' => false, @@ -2377,28 +2419,58 @@ class AdminOrdersControllerCore extends AdminController ))); } - // By webkul to calculate rates of the product from hotelreservation syatem tables with feature prices.... + // By webkul to calculate rates of the product from hotelreservationsystem tables with feature prices.... + // add feature price for updated price + $hotelCartBookingData = new HotelCartBookingData(); $totalProductPriceBeforeTE = (float) $order_detail->total_price_tax_excl; $totalProductPriceBeforeTI = (float) $order_detail->total_price_tax_incl; $totalProductPriceAfterTE = 0; $totalProductPriceAfterTI = 0; + $totalRoomPriceAfterTE = 0; + $totalRoomPriceAfterTI = 0; $bookedRooms = $obj_booking_detail->getBookedRoomsByIdOrderDetail((int) Tools::getValue('order_detail_id'), $id_product); if ($bookedRooms) { + $params = array( + 'id_cart' => $cart->id, + 'id_guest' => $cart->id_guest, + 'price' => $room_unit_price, + ); + foreach ($bookedRooms as $roomInfo) { + $params['id_product'] = $roomInfo['id_product']; + $params['id_room'] = $roomInfo['id_room']; + if ($roomInfo['id_room'] == $id_room && (strtotime($roomInfo['date_from']) == strtotime($old_date_from))) { - $roomTotalPrice = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice($roomInfo['id_product'], $new_date_from, $new_date_to); + $params = array_merge($params, array('date_from' => $new_date_from, 'date_to' => $new_date_to)); + $this->createFeaturePrice($params); + + $roomTotalPrice = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice( + $roomInfo['id_product'], + $new_date_from, + $new_date_to, + 0, + Group::getCurrent()->id, + $cart->id, + $cart->id_guest, + $roomInfo['id_room'] + ); + $totalProductPriceAfterTE += (float) $roomTotalPrice['total_price_tax_excl']; $totalProductPriceAfterTI += (float) $roomTotalPrice['total_price_tax_incl']; + + $totalRoomPriceAfterTE += (float) $roomTotalPrice['total_price_tax_excl']; + $totalRoomPriceAfterTI += (float) $roomTotalPrice['total_price_tax_incl']; } else { - $roomTotalPrice = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice($roomInfo['id_product'], $roomInfo['date_from'], $roomInfo['date_to']); $totalProductPriceAfterTE += (float) $roomInfo['total_price_tax_excl']; $totalProductPriceAfterTI += (float) $roomInfo['total_price_tax_incl']; } } } - // END + // delete cart feature prices after booking update success + HotelRoomTypeFeaturePricing::deleteByIdCart($cart->id); + // END /*This code is commented by webkul because in our case quantity of the product will be number of days for which room is booked*/ // If multiple product_quantity, the order details concern a product customized @@ -2566,13 +2638,18 @@ class AdminOrdersControllerCore extends AdminController ); /*By webkul to edit the Hotel Cart and Hotel Order tables when editing the room for the order detail page*/ + $new_total_price = array( + 'tax_excl' => $totalRoomPriceAfterTE, + 'tax_incl' => $totalRoomPriceAfterTI, + ); if ($update_htl_tables = $obj_booking_detail->UpdateHotelCartHotelOrderOnOrderEdit( $id_order, $id_room, $old_date_from, $old_date_to, $new_date_from, - $new_date_to + $new_date_to, + $new_total_price )) { // update extra demands total prices if dates are changes (price calc method for each day) if ($extraDemands) { diff --git a/js/admin/orders.js b/js/admin/orders.js index d81f59d4d..5bbdc5b7f 100644 --- a/js/admin/orders.js +++ b/js/admin/orders.js @@ -641,6 +641,8 @@ function init() element_list.find('td .booking_duration_show').hide(); element_list.find('td .booking_duration_edit').show(); } + element_list.find('td .room_unit_price_show').hide(); + element_list.find('td .room_unit_price_edit').show(); //element_list.find('td .product_price_show').hide(); //element_list.find('td .product_price_edit').show(); element_list.find('td.cancelCheck').hide(); @@ -679,6 +681,8 @@ function init() element_list.find('td .booking_duration_show').show(); element_list.find('td .product_price_edit').hide(); element_list.find('td .booking_duration_edit').hide(); + element_list.find('td .room_unit_price_show').show(); + element_list.find('td .room_unit_price_edit').hide(); element_list.find('td.product_invoice').hide(); element_list.find('td.cancelCheck').show(); element_list.find('td.cancelQuantity').show(); diff --git a/modules/hotelreservationsystem/classes/HotelBookingDetail.php b/modules/hotelreservationsystem/classes/HotelBookingDetail.php index 0eb8610cd..edb27ee45 100644 --- a/modules/hotelreservationsystem/classes/HotelBookingDetail.php +++ b/modules/hotelreservationsystem/classes/HotelBookingDetail.php @@ -1212,38 +1212,48 @@ class HotelBookingDetail extends ObjectModel $old_date_from, $old_date_to, $new_date_from, - $new_date_to + $new_date_to, + $new_total_price = null ) { $rowByIdOrderIdRoom = Db::getInstance()->getRow('SELECT * FROM `'._DB_PREFIX_.'htl_booking_detail` WHERE `id_room`='.(int)$id_room.' AND `id_order`='.(int)$id_order); - $numDays = $this->getNumberOfDays($old_date_from, $old_date_to); - $paidUnitRoomPriceTE = $rowByIdOrderIdRoom['total_price_tax_excl']/$numDays; - $paidUnitRoomPriceTI = $rowByIdOrderIdRoom['total_price_tax_incl']/$numDays; - + $newTotalPriceTE = ''; + $newTotalPriceTI = ''; $newNumDays = $this->getNumberOfDays($new_date_from, $new_date_to); - $newTotalPriceTE = $paidUnitRoomPriceTE * $newNumDays; - $newTotalPriceTI = $paidUnitRoomPriceTI * $newNumDays; - //$total_price = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice($rowByIdOrderIdRoom['id_product'], $new_date_from, $new_date_to); - $table = 'htl_cart_booking_data'; - $table1 = 'htl_booking_detail'; - $num_days = $this->getNumberOfDays($new_date_from, $new_date_to); - $data_cart = array( - 'date_from' => $new_date_from, - 'date_to' => $new_date_to, - 'quantity' => $num_days + if ($new_total_price) { + $newTotalPriceTE = $new_total_price['tax_excl']; + $newTotalPriceTI = $new_total_price['tax_incl']; + } else { + $oldNumDays = $this->getNumberOfDays($old_date_from, $old_date_to); + $unitRoomPriceTE = $rowByIdOrderIdRoom['total_price_tax_excl'] / $oldNumDays; + $unitRoomPriceTI = $rowByIdOrderIdRoom['total_price_tax_incl'] / $oldNumDays; + $newTotalPriceTE = $unitRoomPriceTE * $newNumDays; + $newTotalPriceTI = $unitRoomPriceTI * $newNumDays; + } + + $cart_booking = array( + 'table' => 'htl_cart_booking_data', + 'data' => array( + 'date_from' => $new_date_from, + 'date_to' => $new_date_to, + 'quantity' => $newNumDays, + ), ); - $data_order = array( - 'date_from' => $new_date_from, - 'date_to' => $new_date_to, - 'total_price_tax_excl' => $newTotalPriceTE, - 'total_price_tax_incl' => $newTotalPriceTI + + $booking_detail = array( + 'table' => 'htl_booking_detail', + 'data' => array( + 'date_from' => $new_date_from, + 'date_to' => $new_date_to, + 'total_price_tax_excl' => $newTotalPriceTE, + 'total_price_tax_incl' => $newTotalPriceTI, + ), ); $where = 'id_order = '.(int)$id_order.' AND id_room = '.(int)$id_room.' AND date_from= \''.pSQL($old_date_from). '\' AND date_to = \''.pSQL($old_date_to).'\' AND `is_refunded`=0 AND `is_back_order`=0'; - $result = Db::getInstance()->update($table, $data_cart, $where); - - $result1 = Db::getInstance()->update($table1, $data_order, $where); + $result = Db::getInstance()->update($cart_booking['table'], $cart_booking['data'], $where); + $result &= Db::getInstance()->update($booking_detail['table'], $booking_detail['data'], $where); return $result; } diff --git a/modules/hotelreservationsystem/classes/HotelCartBookingData.php b/modules/hotelreservationsystem/classes/HotelCartBookingData.php index ac3db9f25..452b754ee 100644 --- a/modules/hotelreservationsystem/classes/HotelCartBookingData.php +++ b/modules/hotelreservationsystem/classes/HotelCartBookingData.php @@ -145,7 +145,16 @@ class HotelCartBookingData extends ObjectModel if ($cart_book_data) { foreach ($cart_book_data as $key => $value) { // By webkul New way to calculate product prices with feature Prices - $roomTypeDateRangePrice = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice($value['id_product'], $value['date_from'], $value['date_to']); + $roomTypeDateRangePrice = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice( + $value['id_product'], + $value['date_from'], + $value['date_to'], + 0, + (int)Group::getCurrent()->id, + $id_cart, + $id_guest, + $value['id_room'] + ); $cart_book_data[$key]['amt_with_qty'] = $roomTypeDateRangePrice['total_price_tax_excl']; } @@ -620,11 +629,8 @@ class HotelCartBookingData extends ObjectModel $objRoomDemands = new HotelRoomTypeDemand(); foreach ($cart_detail_data as $key => $value) { $product_image_id = Product::getCover($value['id_product']); - $productObj = new Product((int) $value['id_product'], false, (int) Configuration::get('PS_LANG_DEFAULT')); - $link_rewrite = $productObj->link_rewrite; - if ($product_image_id) { $cart_detail_data[$key]['image_link'] = $context->link->getImageLink($link_rewrite, $product_image_id['id_image'], 'small_default'); } else { @@ -640,8 +646,26 @@ class HotelCartBookingData extends ObjectModel $unit_price = Product::getPriceStatic($value['id_product'], true); $unit_price_tax_excl = Product::getPriceStatic($value['id_product'], false); $productPriceWithoutReduction = $productObj->getPriceWithoutReduct(false); - $feature_price = HotelRoomTypeFeaturePricing::getRoomTypeFeaturePricesPerDay($value['id_product'], $value['date_from'], $value['date_to'], true); - $feature_price_tax_excl = HotelRoomTypeFeaturePricing::getRoomTypeFeaturePricesPerDay($value['id_product'], $value['date_from'], $value['date_to'], false); + $feature_price = HotelRoomTypeFeaturePricing::getRoomTypeFeaturePricesPerDay( + $value['id_product'], + $value['date_from'], + $value['date_to'], + true, + 0, + $id_cart, + $value['id_guest'], + $value['id_room'] + ); + $feature_price_tax_excl = HotelRoomTypeFeaturePricing::getRoomTypeFeaturePricesPerDay( + $value['id_product'], + $value['date_from'], + $value['date_to'], + false, + 0, + $id_cart, + $value['id_guest'], + $value['id_room'] + ); $feature_price_diff = (float)($productPriceWithoutReduction - $feature_price); $cart_detail_data[$key]['product_price'] = $unit_price; $cart_detail_data[$key]['product_price_tax_excl'] = $unit_price_tax_excl; @@ -670,7 +694,16 @@ class HotelCartBookingData extends ObjectModel 1 ); // By webkul New way to calculate product prices with feature Prices - $roomTypeDateRangePrice = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice($value['id_product'], $value['date_from'], $value['date_to']); + $roomTypeDateRangePrice = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice( + $value['id_product'], + $value['date_from'], + $value['date_to'], + 0, + 0, + $id_cart, + $value['id_guest'], + $value['id_room'] + ); $cart_detail_data[$key]['amt_with_qty'] = $roomTypeDateRangePrice['total_price_tax_excl']; } @@ -738,8 +771,24 @@ class HotelCartBookingData extends ObjectModel * @param [int] $id_group [id_group for which price is need (if available for the passed group)] * @return [array|false] [returns array containg info of the feature plan if foung otherwise returns false] */ - public function getProductFeaturePricePlanByDateByPriority($id_product, $date, $id_group) - { + public function getProductFeaturePricePlanByDateByPriority( + $id_product, + $date, + $id_group, + $id_cart = 0, + $id_guest = 0, + $id_room = 0 + ) { + if ($id_cart && $id_room) { + if ($featurePrice = Db::getInstance()->getRow( + 'SELECT * FROM `'._DB_PREFIX_.'htl_room_type_feature_pricing` fp + WHERE fp.`id_product` = '.(int) $id_product.' AND fp.`id_cart` = '.(int) $id_cart.' + AND fp.`id_guest` = '.(int) $id_guest.' AND fp.`id_room` = '.(int) $id_room.' AND fp.`active` = 1') + ) { + return $featurePrice; + } + } + //Get priority $featurePricePriority = Configuration::get('HTL_FEATURE_PRICING_PRIORITY'); $featurePricePriority = explode(';', $featurePricePriority); @@ -750,7 +799,7 @@ class HotelCartBookingData extends ObjectModel 'SELECT * FROM `'._DB_PREFIX_.'htl_room_type_feature_pricing` fp INNER JOIN `'._DB_PREFIX_.'htl_room_type_feature_pricing_group` fpg ON (fp.`id_feature_price` = fpg.`id_feature_price` AND fpg.`id_group` = '.(int) $id_group.') - WHERE fp.`id_product`='.(int) $id_product.' AND fp.`active`=1 + WHERE fp.`id_cart` = 0 AND fp.`id_product`='.(int) $id_product.' AND fp.`active`=1 AND fp.`date_selection_type`=2 AND fp.`date_from` = \''.pSQL($date).'\'' )) { return $featurePrice; @@ -760,8 +809,9 @@ class HotelCartBookingData extends ObjectModel 'SELECT * FROM `'._DB_PREFIX_.'htl_room_type_feature_pricing` fp INNER JOIN `'._DB_PREFIX_.'htl_room_type_feature_pricing_group` fpg ON (fp.`id_feature_price` = fpg.`id_feature_price` AND fpg.`id_group` = '.(int) $id_group.') - WHERE fp.`id_product`='.(int) $id_product.' AND fp.`is_special_days_exists`=1 - AND fp.`active`=1 AND fp.`date_from` <= \''.pSQL($date).'\' AND fp.`date_to` >= \''.pSQL($date).'\'' + WHERE fp.`id_cart` = 0 AND fp.`id_product`='.(int) $id_product.' + AND fp.`is_special_days_exists`=1 AND fp.`active`=1 AND fp.`date_from` <= \''.pSQL($date).'\' + AND fp.`date_to` >= \''.pSQL($date).'\'' )) { foreach ($featurePrice as $fRow) { $specialDays = json_decode($fRow['special_days']); @@ -775,7 +825,7 @@ class HotelCartBookingData extends ObjectModel 'SELECT * FROM `'._DB_PREFIX_.'htl_room_type_feature_pricing` fp INNER JOIN `'._DB_PREFIX_.'htl_room_type_feature_pricing_group` fpg ON (fp.`id_feature_price` = fpg.`id_feature_price` AND fpg.`id_group` = '.(int) $id_group.') - WHERE fp.`id_product`='.(int) $id_product.' AND fp.`date_selection_type`=1 + WHERE fp.`id_cart` = 0 AND fp.`id_product`='.(int) $id_product.' AND fp.`date_selection_type`=1 AND `is_special_days_exists`=0 AND `active`=1 AND fp.`date_from` <= \''.pSQL($date).'\' AND fp.`date_to` >= \''.pSQL($date).'\'' )) { diff --git a/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php b/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php index 4ec8282c2..388d9beeb 100644 --- a/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php +++ b/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php @@ -263,6 +263,9 @@ class HotelReservationSystemDb "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_room_type_feature_pricing` ( `id_feature_price` int(11) NOT NULL AUTO_INCREMENT, `id_product` int(11) NOT NULL, + `id_cart` int(11) NOT NULL DEFAULT '0', + `id_guest` int(11) NOT NULL DEFAULT '0', + `id_room` int(11) NOT NULL DEFAULT '0', `date_from` date NOT NULL, `date_to` date NOT NULL, `is_special_days_exists` tinyint(1) NOT NULL, diff --git a/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php b/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php index 2d399ba2b..910675c1d 100644 --- a/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php +++ b/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php @@ -21,6 +21,9 @@ class HotelRoomTypeFeaturePricing extends ObjectModel { public $id_product; + public $id_cart = 0; + public $id_guest = 0; + public $id_room = 0; public $feature_price_name; public $date_selection_type; public $date_from; @@ -42,6 +45,9 @@ class HotelRoomTypeFeaturePricing extends ObjectModel 'multilang' => true, 'fields' => array( 'id_product' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true), + 'id_cart' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), + 'id_guest' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), + 'id_room' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), 'date_from' => array('type' => self::TYPE_DATE, 'validate' => 'isDate', 'required' => true), 'date_to' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'), 'impact_way' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true), @@ -623,8 +629,16 @@ class HotelRoomTypeFeaturePricing extends ObjectModel * * @return [float] [Returns Total price of the room type] */ - public static function getRoomTypeTotalPrice($id_product, $date_from, $date_to, $quantity = 0, $id_group = 0) - { + public static function getRoomTypeTotalPrice( + $id_product, + $date_from, + $date_to, + $quantity = 0, + $id_group = 0, + $id_cart = 0, + $id_guest = 0, + $id_room = 0 + ) { $totalPrice = array(); $totalPrice['total_price_tax_incl'] = 0; $totalPrice['total_price_tax_excl'] = 0; @@ -657,7 +671,10 @@ class HotelRoomTypeFeaturePricing extends ObjectModel if ($featurePrice = $hotelCartBookingData->getProductFeaturePricePlanByDateByPriority( $id_product, $currentDate, - $id_group + $id_group, + $id_cart, + $id_guest, + $id_room )) { if ($featurePrice['impact_type'] == 1) { //percentage @@ -673,10 +690,14 @@ class HotelRoomTypeFeaturePricing extends ObjectModel // Decrease $priceWithFeatureTE = ($productPriceTE - $featureImpactPriceTE); $priceWithFeatureTI = ($productPriceTI - $featureImpactPriceTI); - } else { + } elseif ($featurePrice['impact_way'] == 2) { // Increase $priceWithFeatureTE = ($productPriceTE + $featureImpactPriceTE); $priceWithFeatureTI = ($productPriceTI + $featureImpactPriceTI); + } else { + // Fix + $priceWithFeatureTE = $featureImpactPriceTE; + $priceWithFeatureTI = $featureImpactPriceTI; } if ($priceWithFeatureTI < 0) { $priceWithFeatureTI = 0; @@ -709,8 +730,16 @@ class HotelRoomTypeFeaturePricing extends ObjectModel * @param [date] $date_to [end date] * @return [float] [returns per day feature price of the Room Type] */ - public static function getRoomTypeFeaturePricesPerDay($id_product, $date_from, $date_to, $use_tax = true, $id_group = 0) - { + public static function getRoomTypeFeaturePricesPerDay( + $id_product, + $date_from, + $date_to, + $use_tax = true, + $id_group = 0, + $id_cart = 0, + $id_guest = 0, + $id_room = 0 + ) { $dateFrom = date('Y-m-d', strtotime($date_from)); $dateTo = date('Y-m-d', strtotime($date_to)); $totalDurationPrice = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice( @@ -718,7 +747,10 @@ class HotelRoomTypeFeaturePricing extends ObjectModel $dateFrom, $dateTo, 0, - $id_group + $id_group, + $id_cart, + $id_guest, + $id_room ); $totalDurationPriceTI = $totalDurationPrice['total_price_tax_incl']; @@ -757,6 +789,21 @@ class HotelRoomTypeFeaturePricing extends ObjectModel return Db::getInstance()->delete('htl_room_type_feature_pricing', 'id_product = '.(int)$idProduct); } + public static function deleteByIdCart( + $id_cart, + $id_product = false, + $id_room = false, + $date_from = false, + $date_to = false) + { + return Db::getInstance()->execute( + 'DELETE FROM `'._DB_PREFIX_.'htl_room_type_feature_pricing` + WHERE `id_cart` = '.(int) $id_cart.($id_product ? ' AND `id_product` = '.(int) $id_product. + ' AND `id_room` = '.(int) $id_room.' AND `date_from` = "'.pSQL($date_from). + '" AND `date_to` = "'.pSQL($date_to).'"' : '') + ); + } + /** * Update customer groups associated to the object * @param array $groups groups diff --git a/modules/hotelreservationsystem/controllers/admin/AdminHotelFeaturePricesSettings.php b/modules/hotelreservationsystem/controllers/admin/AdminHotelFeaturePricesSettings.php index 5dc2bfe1b..881949f22 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminHotelFeaturePricesSettings.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminHotelFeaturePricesSettings.php @@ -45,11 +45,16 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController $this->_select .= ' fpl.`feature_price_name` as ftr_price_name, CONCAT(pl.`name`, " (#", a.`id_product`, ")") as product_name, hbl.`hotel_name`, IF(a.impact_type=1 , CONCAT(round(a.impact_value, 2), " ", "%"), a.impact_value) AS impact_value'; $this->_select .= ' ,IF(a.impact_type=1 , \''.$this->l('Percentage').'\', \''.$this->l('Fixed Amount').'\') AS impact_type'; - $this->_select .= ' ,IF(a.impact_way=1 , \''.$this->l('Decrease').'\', \''.$this->l('Increase').'\') - AS impact_way'; + $this->_select .= ', CASE + WHEN a.`impact_way` = 1 THEN \''.$this->l('Decrease').'\' + WHEN a.`impact_way` = 2 THEN \''.$this->l('Increase').'\' + WHEN a.`impact_way` = 3 THEN \''.$this->l('Fix').'\' + END AS `impact_way`'; - $impactWays = array(1 => 'decrease', 2 => 'increase'); - $impactTypes = array(1 => 'Percentage', 2 => 'Fixed Price'); + $this->_where = ' AND a.`id_cart` = 0 AND a.`id_guest` = 0 AND a.`id_room` = 0'; + + $impactWays = array(1 => $this->l('Decrease'), 2 => $this->l('Increase'), 3 => $this->l('Fix')); + $impactTypes = array(1 => $this->l('Percentage'), 2 => $this->l('Fixed Price')); $priorities = Configuration::get('HTL_FEATURE_PRICING_PRIORITY'); $this->context->smarty->assign('featurePricePriority', explode(';', $priorities)); diff --git a/modules/hotelreservationsystem/controllers/admin/AdminHotelRoomsBookingController.php b/modules/hotelreservationsystem/controllers/admin/AdminHotelRoomsBookingController.php index f5dc31d1a..3919943a1 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminHotelRoomsBookingController.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminHotelRoomsBookingController.php @@ -350,7 +350,6 @@ class AdminHotelRoomsBookingController extends ModuleAdminController $this->context->cart->updateQty($num_day, $id_product, null, false, $direction); - $id_cart = $this->context->cart->id; $id_guest = $this->context->cookie->id_guest; @@ -392,27 +391,26 @@ class AdminHotelRoomsBookingController extends ModuleAdminController $bookingParams['search_cart_rms'] = 1; $booking_stats = $obj_booking_dtl->getBookingData($bookingParams); - //$rm_amount = $unit_price * (int)$num_day; - //$rm_amount = Tools::ps_round($rm_amount, 2); - // - //// By webkul New way to calculate product prices with feature Prices + + // By webkul New way to calculate product prices with feature Prices $roomTypeDateRangePrice = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice( $id_product, $date_from, $date_to ); - $rm_amount = $roomTypeDateRangePrice['total_price_tax_incl']; + $rm_amount = $roomTypeDateRangePrice['total_price_tax_excl']; $cart_data = array('room_num' => $obj_rm_info->room_num, - 'room_type' => Product::getProductName((int)$id_product), - 'date_from' => date('Y-M-d', strtotime($date_from)), - 'date_to' => date('Y-M-d', strtotime($date_to)), - 'amount' => $rm_amount, - 'qty' => $num_day, - 'rms_in_cart' => $rms_in_cart, - 'total_amount' => $total_amount, - 'booking_stats' => $booking_stats, - 'id_cart_book_data' => $obj_cart_book_data->id); + 'room_type' => Product::getProductName((int)$id_product), + 'date_from' => date('Y-M-d', strtotime($date_from)), + 'date_to' => date('Y-M-d', strtotime($date_to)), + 'amount' => $rm_amount, + 'qty' => $num_day, + 'rms_in_cart' => $rms_in_cart, + 'total_amount' => $total_amount, + 'booking_stats' => $booking_stats, + 'id_cart_book_data' => $obj_cart_book_data->id + ); if ($obj_cart_book_data->id) { die(json_encode($cart_data)); @@ -483,9 +481,9 @@ class AdminHotelRoomsBookingController extends ModuleAdminController $this->context->smarty->assign( array( 'date_from' => $search_date_from, - 'date_to'=>$search_date_to, - 'booking_data'=>$booking_data, - 'ajax_delete'=>$ajax_delete, + 'date_to' => $search_date_to, + 'booking_data' => $booking_data, + 'ajax_delete' => $ajax_delete, ) ); $tpl_path = 'hotelreservationsystem/views/templates/admin/hotel_rooms_booking/helpers/view/view.tpl'; diff --git a/modules/hotelreservationsystem/views/js/HotelReservationAdmin.js b/modules/hotelreservationsystem/views/js/HotelReservationAdmin.js index df443d995..2197b263c 100644 --- a/modules/hotelreservationsystem/views/js/HotelReservationAdmin.js +++ b/modules/hotelreservationsystem/views/js/HotelReservationAdmin.js @@ -906,26 +906,37 @@ $(document).ready(function() { $('#date_selection_type').on('change', function() { if ($('#date_selection_type').val() == 2) { - $(".specific_date_type").show(); - $(".date_range_type").hide(); - $(".special_days_content").hide(); + $(".specific_date_type").show(200); + $(".date_range_type").hide(200); + $(".special_days_content").hide(200); } else if ($('#date_selection_type').val() == 1) { - $(".specific_date_type").hide(); - $(".date_range_type").show(); - $(".special_days_content").show(); + $(".specific_date_type").hide(200); + $(".date_range_type").show(200); + $(".special_days_content").show(200); } else { - $(".specific_date_type").hide(); - $(".date_range_type").show(); - $(".special_days_content").show(); + $(".specific_date_type").hide(200); + $(".date_range_type").show(200); + $(".special_days_content").show(200); } }); $(".is_special_days_exists").on ('click', function() { if ($(this).is(':checked')) { - $('.week_days').show(); + $('.week_days').show(200); } else { - $('.week_days').hide(); + $('.week_days').hide(200); + } + }); + + $('#price_impact_way').on('change', function() { + if ($('#price_impact_way').val() == 3) { + $('#price_impact_type option[value="2"]').attr('selected', 'selected'); + $('#price_impact_type_input').removeAttr('disabled').val(2); + $('#price_impact_type').trigger('change').attr('disabled', 'disabled'); + } else { + $('#price_impact_type_input').attr('disabled', 'disabled'); + $('#price_impact_type').removeAttr('disabled'); } }); 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 45459358e..2fa68ae8c 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 @@ -206,6 +206,9 @@ + @@ -215,7 +218,7 @@ {l s='Impact Type :' mod='hotelreservationsystem'}
- impact_way) && $objFeaturePrice->impact_way == 3}disabled="disabled"{/if}> @@ -223,6 +226,7 @@ {l s='Fixed Price' mod='hotelreservationsystem'} +