Changes for mersing add and edit pages commits and add service functionality in add order page

This commit is contained in:
Sumit Panwar
2025-02-22 14:31:07 +05:30
parent dcefbb4afa
commit 279366f80f
11 changed files with 1043 additions and 587 deletions

View File

@@ -18,82 +18,77 @@
*}
<div class="modal" tabindex="-1" role="dialog" id="rooms_type_extra_demands">
<div class="modal-dialog" role="document">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
<ul class="nav nav-tabs" role="tablist">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><i class="icon-remove-sign"></i></button>
<h4 class="modal-title"><i class="icon icon-bed"></i> &nbsp;{l s='Room Services'}</h4>
</div>
<div class="modal-body" id="rooms_extra_demands">
<ul class="nav nav-tabs" role="tablist">
{if isset($selectedRoomDemands) && $selectedRoomDemands}
<li role="presentation" class="active"><a href="#room_type_demands_desc" aria-controls="facilities" role="tab" data-toggle="tab">{l s='Facilities'}</a></li>
{/if}
{if isset($roomTypeServiceProducts) && $roomTypeServiceProducts}
{if isset($serviceProducts) && $serviceProducts}
<li role="presentation" {if !isset($selectedRoomDemands) || !$selectedRoomDemands}class="active"{/if}><a href="#room_type_service_product_desc" aria-controls="services" role="tab" data-toggle="tab">{l s='Services'}</a></li>
{/if}
</ul>
</div>
<div class="modal-body" id="rooms_extra_demands">
<div class="tab-content">
{if isset($selectedRoomDemands) && $selectedRoomDemands}
<div id="room_type_demands_desc" class="tab-pane active">
<div class="rooms_extra_demands_head">
<p class="rooms_extra_demands_text">{l s='Add below facilities to the room for better hotel experience'}</p>
</div>
<div id="room_type_demands_desc">
{if isset($selectedRoomDemands) && $selectedRoomDemands}
{assign var=roomCount value=1}
{foreach $selectedRoomDemands as $key => $roomDemand}
<div class="row room_demands_container">
<div class="col-sm-12 demand_header">
<span>
<i class="icon-bed"></i>
{if isset($roomDemand['room_num']) && $roomDemand['room_num']}
{l s='Room'} {$roomDemand['room_num']|escape:'html':'UTF-8'}
{else}
{l s='Room'} {$roomCount|escape:'html':'UTF-8'}
{/if}
</span>
</div>
<div class="col-sm-12 room_demand_detail">
{if isset($roomTypeDemands) && $roomTypeDemands}
{foreach $roomTypeDemands as $idGlobalDemand => $demand}
<div class="row room_demand_block">
<div class="col-xs-6">
<div class="row">
<div class="col-xs-2">
<input id_cart_booking="{$roomDemand['id']}" value="{$idGlobalDemand|escape:'html':'UTF-8'}" type="checkbox" class="id_room_type_demand" {if isset($roomDemand['selected_global_demands']) && $roomDemand['selected_global_demands'] && ($idGlobalDemand|in_array:$roomDemand['selected_global_demands'])}checked{/if} />
</div>
<div class="col-xs-10 demand_adv_option_block">
<p>{$demand['name']|escape:'html':'UTF-8'}</p>
{if isset($demand['adv_option']) && $demand['adv_option']}
<select class="id_option">
{foreach $demand['adv_option'] as $idOption => $option}
{assign var=demand_key value="`$idGlobalDemand`-`$idOption`"}
<option optionPrice="{$option['price_tax_excl']|escape:'html':'UTF-8'}" value="{$idOption|escape:'html':'UTF-8'}" {if isset($roomDemand['extra_demands'][$demand_key])}selected{/if} key="{$demand_key}">{$option['name']}</option>
{if isset($roomDemand['extra_demands'][$demand_key])}
{assign var=selected_adv_option value="$idOption"}
{/if}
{/foreach}
</select>
{else}
<input type="hidden" class="id_option" value="0" />
{/if}
</div>
</div>
</div>
<div class="col-xs-6">
<p class="pull-right">
<span class="extra_demand_option_price">
{if isset($selected_adv_option) && isset($demand['adv_option'][$selected_adv_option]['price_tax_excl'])}{convertPrice price = $demand['adv_option'][$selected_adv_option]['price_tax_excl']|escape:'html':'UTF-8'}{else if isset($demand['adv_option']) && $demand['adv_option']}{convertPrice price = $demand['adv_option'][$demand['adv_option']|@key]['price_tax_excl']}{else}{convertPrice price = $demand['price_tax_excl']|escape:'html':'UTF-8'}{/if}
</span>
{if $demand['price_calc_method'] == HotelRoomTypeGlobalDemand::WK_PRICE_CALC_METHOD_EACH_DAY}
{l s='/ night'}
{/if}
</p>
</div>
</div>
{/foreach}
<table class="table table-striped">
<thead>
<tr>
<th></th>
<th>{l s='Name'}</th>
<th>{l s='Options'}</th>
<th>{l s='Unit Price (tax excl.)'}</th>
</tr>
</thead>
<tbody>
{foreach $roomTypeDemands as $idGlobalDemand => $demand}
<tr class="room_demand_block">
<td>
<input id_cart_booking="{$roomDemand['id']}" value="{$idGlobalDemand|escape:'html':'UTF-8'}" type="checkbox" class="id_room_type_demand" {if isset($roomDemand['selected_global_demands']) && $roomDemand['selected_global_demands'] && ($idGlobalDemand|in_array:$roomDemand['selected_global_demands'])}checked{/if} />
</td>
<td class="demand_adv_option_block">
<p>{$demand['name']|escape:'html':'UTF-8'}</p>
</td>
<td class="demand_adv_option_block">
{if isset($demand['adv_option']) && $demand['adv_option']}
<select class="id_option">
{foreach $demand['adv_option'] as $idOption => $option}
{assign var=demand_key value="`$idGlobalDemand`-`$idOption`"}
<option optionPrice="{$option['price_tax_excl']|escape:'html':'UTF-8'}" value="{$idOption|escape:'html':'UTF-8'}" {if isset($roomDemand['extra_demands'][$demand_key])}selected{/if} key="{$demand_key}">{$option['name']}</option>
{if isset($roomDemand['extra_demands'][$demand_key])}
{assign var=selected_adv_option value="$idOption"}
{/if}
{/foreach}
</select>
{else}
--
<input type="hidden" class="id_option" value="0" />
{/if}
</td>
<td>
<span class="extra_demand_option_price">
{if isset($selected_adv_option) && isset($demand['adv_option'][$selected_adv_option]['price_tax_excl'])}{convertPrice price = $demand['adv_option'][$selected_adv_option]['price_tax_excl']|escape:'html':'UTF-8'}{else if isset($demand['adv_option']) && $demand['adv_option']}{convertPrice price = $demand['adv_option'][$demand['adv_option']|@key]['price_tax_excl']}{else}{convertPrice price = $demand['price_tax_excl']|escape:'html':'UTF-8'}{/if}
</span>
{if $demand['price_calc_method'] == HotelRoomTypeGlobalDemand::WK_PRICE_CALC_METHOD_EACH_DAY}
{l s='/ night'}
{/if}
</td>
</tr>
{/foreach}
</tbody>
</table>
{/if}
</div>
</div>
@@ -103,78 +98,16 @@
</div>
</div>
{/if}
{if isset($roomTypeServiceProducts) && $roomTypeServiceProducts}
<div id="room_type_service_product_desc" class="tab-pane{if !isset($selectedRoomDemands) || !$selectedRoomDemands} active{/if}">
<div class="rooms_extra_demands_head">
<p class="rooms_extra_demands_text">{l s='Add below services to the rooms for better hotel experience'}</p>
</div>
<div id="room_type_services_desc">
{assign var=roomCount value=1}
<div class="row room_demands_container">
<div class="col-sm-12 demand_header">
<span>
<i class="icon-bed"></i>
{if isset($selectedRoomServiceProduct['room_num']) && $selectedRoomServiceProduct['room_num']}
{l s='Room'} {$selectedRoomServiceProduct['room_num']|escape:'html':'UTF-8'}
{else}
{l s='Room'} {$roomCount|escape:'html':'UTF-8'}
{/if}
</span>
</div>
<div class="col-sm-12 room_demand_detail">
{if isset($roomTypeServiceProducts) && $roomTypeServiceProducts}
{foreach $roomTypeServiceProducts as $product}
<div class="row room_demand_block">
<div class="col-xs-5">
<div class="row">
<div class="col-xs-2">
<input data-id_cart_booking="{$selectedRoomServiceProduct['id']}" value="{$product['id_product']|escape:'html':'UTF-8'}" type="checkbox" class="change_room_type_service_product" {if isset($selectedRoomServiceProduct['selected_service']) && $selectedRoomServiceProduct['selected_service'] && ($product['id_product']|array_key_exists:$selectedRoomServiceProduct['selected_service'])}checked{/if}/>
</div>
<div class="col-xs-10">
<p>{$product['name']|escape:'html':'UTF-8'}</p>
{if $product.allow_multiple_quantity}
<div class="qty_container">
<input type="number" class="form-control room_type_service_product_qty qty" id="qty_{$product.id_product}" name="service_product_qty_{$product.id_product}" data-id-product="{$product.id_product}" min="1" data-max-quantity="{$product.max_quantity}" value="{if isset($selectedRoomServiceProduct['selected_service']) && $selectedRoomServiceProduct['selected_service'] && ($product['id_product']|array_key_exists:$selectedRoomServiceProduct['selected_service'])}{$selectedRoomServiceProduct['selected_service'][$product['id_product']]['quantity']}{else}1{/if}">
<p style="display:{if isset($selectedRoomServiceProduct['selected_service']) && $selectedRoomServiceProduct['selected_service'] && ($product['id_product']|array_key_exists:$selectedRoomServiceProduct['selected_service']) && $selectedRoomServiceProduct['selected_service'][$product['id_product']]['quantity'] > $product.max_quantity}block{else}none{/if}; margin-top: 4px;">
<span class="label label-warning">{l s='Maximum allowed quantity: %s' sprintf=$product.max_quantity}</span>
</p>
</div>
{/if}
</div>
</div>
</div>
<div class="col-xs-3">
{if $product['auto_add_to_cart'] && $product['price_addition_type'] == Product::PRICE_ADDITION_TYPE_INDEPENDENT}
<span class="badge badge-info label">{l s='Convenience fee'}</span>
{/if}
{if $product['auto_add_to_cart'] && $product['price_addition_type'] == Product::PRICE_ADDITION_TYPE_WITH_ROOM}
<span class="badge badge-info label">{l s='Auto added'}</span>
{/if}
</div>
<div class="col-xs-4">
{if ($product.show_price && !isset($restricted_country_mode)) || isset($groups)}
<div id="service_cart_price_{$selectedRoomServiceProduct['id']}_{$product['id_product']}_input" class="input-group" {if !isset($selectedRoomServiceProduct['selected_service']) || !$selectedRoomServiceProduct['selected_service'] || !($product['id_product']|array_key_exists:$selectedRoomServiceProduct['selected_service'])}style="display:none;"{/if}>
<span class="input-group-addon">
{$cartCurrency->sign}
</span>
<input class="service_cart_price_input" id="service_cart_price_{$selectedRoomServiceProduct['id']}_{$product['id_product']}" type="text" value="{$product.price_tax_exc}"/>
</div>
<span id="service_cart_price_{$selectedRoomServiceProduct['id']}_{$product['id_product']}_txt" class="pull-right" {if isset($selectedRoomServiceProduct['selected_service']) && $selectedRoomServiceProduct['selected_service'] && ($product['id_product']|array_key_exists:$selectedRoomServiceProduct['selected_service'])}style="display:none;"{/if}>{convertPrice price=$product.price_tax_exc}</span>
{/if}
</div>
</div>
{/foreach}
{/if}
</div>
</div>
</div>
</div>
{/if}
{include file='controllers/orders/modals/_add_order_extra_services_tab_content.tpl'}
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">{l s='Close'}</button>
</div>
</div>
</div>
{if isset($loaderImg) && $loaderImg}
<div class="loading_overlay">
<img src='{$loaderImg}' class="loading-img"/>
</div>
{/if}
</div>

View File

@@ -145,7 +145,7 @@
</button>
{if (isset($data.extra_demands) && $data.extra_demands) || isset($data.additional_service) && $data.additional_service}
<br />
<a href="#" id_room="{$data.id_room|escape:'html':'UTF-8'}" date_from="{$data.date_from|escape:'html':'UTF-8'}" date_to="{$data.date_to|escape:'html':'UTF-8'}" id_product="{$data.id_product|escape:'html':'UTF-8'}" id_cart="{$data.id_cart|escape:'html':'UTF-8'}" class="open_rooms_extra_demands btn btn-success" title="{l s='Click here to add or remove the extra services of this room type.'}">
<a href="#" id_hotel_cart_booking="{$data.id|escape:'html':'UTF-8'}" id_room="{$data.id_room|escape:'html':'UTF-8'}" date_from="{$data.date_from|escape:'html':'UTF-8'}" date_to="{$data.date_to|escape:'html':'UTF-8'}" id_product="{$data.id_product|escape:'html':'UTF-8'}" id_cart="{$data.id_cart|escape:'html':'UTF-8'}" class="open_rooms_extra_demands btn btn-success" title="{l s='Click here to add or remove the extra services of this room type.'}">
<i class="icon-pencil"></i>&nbsp;{l s='Services'}
</a>
{/if}
@@ -210,22 +210,13 @@
color:#979797;
font-size:12px;}
/*Extra demands CSS*/
#rooms_type_extra_demands .modal-header {
padding-bottom: 0px}
#rooms_extra_demands {
font-size: 16px;}
#rooms_extra_demands .room_demands_container {
border: 1px solid #ddd;}
#rooms_extra_demands .demand_header {
padding: 10px;
color: #333;
border-bottom: 1px solid #ddd;}
#rooms_extra_demands .rooms_extra_demands_head {
margin-bottom: 18px;}
#rooms_extra_demands .room_demand_block {
margin-bottom: 15px;
color: #333;
font-size: 14px;}
#rooms_extra_demands .room_demand_detail {
padding: 15px 15px 0px 15px;}
color: #333;}
#room_type_service_product_desc #back_to_service_btn {
display: none;}
#add_new_room_services_block {
display: none;}
</style>

View File

@@ -177,7 +177,7 @@
$('body').on('click', '.delete_service_product', function(){
if (confirm("{l s='Are you sure?'}"))
{
$(".loading_overlay").show();
$.ajax({
type:"POST",
url: "{$link->getAdminLink('AdminOrders')|addslashes}",
@@ -204,7 +204,10 @@
{
alert("l s='Some error occured.please try again.'}");
}
}
},
complete: function(){
$(".loading_overlay").hide();
}
});
$(this).closest("tr").remove();
}
@@ -1499,6 +1502,9 @@
var idRoom = $(this).attr('id_room');
var dateFrom = $(this).attr('date_from');
var dateTo = $(this).attr('date_to');
var idHotelCartBooking = $(this).attr('id_hotel_cart_booking');
$(".loading_overlay").show();
$.ajax({
type: 'POST',
dataType: 'JSON',
@@ -1513,17 +1519,29 @@
id_room: idRoom,
id_cart: idCart,
id_product: idProduct,
id_hotel_cart_booking: idHotelCartBooking,
action: 'getRoomTypeCartDemands',
ajax: true
},
success: function(response) {
if (response.status) {
$('#customer_cart_details').after(response.html_exta_demands);
if (response.hasError) {
var errorHtml = error_found_txt + ':<br>';
errorHtml += '<ol>';
$.each(response.errors, function(key, errorMsg) {
errorHtml += '<li>' + errorMsg + '</li>';
});
errorHtml += '</ol>';
showErrorMessage(errorHtml);
} else {
$('#customer_cart_details').after(response.html_exta_demands);
// $('#rooms_type_extra_demands').find('#room_type_demands_desc').html('');
// $('#rooms_type_extra_demands').find('#room_type_demands_desc').append(response.html_exta_demands);
$('#rooms_type_extra_demands').modal('show');
}
}
},
complete: function() {
$(".loading_overlay").hide();
}
});
});
$(document).on('hidden.bs.modal', '#rooms_type_extra_demands', function (e) {
@@ -1542,6 +1560,7 @@
});
});
var idBookingCart = $(this).attr('id_cart_booking');
$(".loading_overlay").show();
$.ajax({
type: 'POST',
dataType: 'JSON',
@@ -1563,7 +1582,10 @@
} else {
showErrorMessage(txtExtraDemandErr);
}
}
},
complete: function() {
$(".loading_overlay").hide();
}
});
});
@@ -1584,6 +1606,7 @@
});
});
var idBookingCart = $(this).closest('.room_demand_block').find('.id_room_type_demand').attr('id_cart_booking');
$(".loading_overlay").show();
$.ajax({
type: 'POST',
dataType: 'JSON',
@@ -1605,7 +1628,10 @@
} else {
showErrorMessage(txtExtraDemandErr);
}
}
},
complete: function() {
$(".loading_overlay").hide();
}
});
}
});
@@ -1687,6 +1713,75 @@
}
});
// click on back button on created facilities while additional facilities edit
$(document).on('click', '#back_to_service_btn', function() {
$('#room_type_services_desc').show();
$('#add_new_room_services_block').hide();
$('#back_to_service_btn').hide();
});
// Add new custom service: Show hide new custom service form
$(document).on('click', '#btn_new_room_service', function() {
$('#add_new_room_services_block').show();
$('#back_to_service_btn').show();
$('#room_type_services_desc').hide();
});
// Add new custom service: change auto added option
$(document).on('change', '#add_new_room_services_form input[name="new_service_auto_added"]', function() {
var room_type_tax_rule_group_exist = $("#room_type_tax_rule_group_exist").val();
if ($(this).val() == 1) {
$("#new_service_price_tax_rule_container").hide();
$("#new_service_price_addition_type_container").show();
$("#new_service_qty_container").hide();
} else {
$("#new_service_price_addition_type_container").hide();
$("#new_service_qty_container").show();
$("#new_service_price_tax_rule_container").show();
}
});
// Add new custom service to the room
$(document).on('submit', '#add_new_room_services_form', function(e) {
e.preventDefault();
var form_data = new FormData(this);
form_data.append('ajax', true);
form_data.append('action', 'addNewRoomServices');
$(".loading_overlay").show();
$.ajax({
type: 'POST',
headers: {
"cache-control": "no-cache"
},
url: "{$link->getAdminLink('AdminCarts')|addslashes}",
dataType: 'JSON',
cache: false,
data: form_data,
processData: false,
contentType: false,
success: function(jsonData) {
if (!jsonData.hasError) {
if (jsonData.service_panel) {
$('#room_type_service_product_desc').replaceWith(jsonData.service_panel);
}
showSuccessMessage(txtExtraDemandSucc);
} else {
var errorHtml = error_found_txt + ':<br>';
errorHtml += '<ol>';
$.each(jsonData.errors, function(key, errorMsg) {
errorHtml += '<li>' + errorMsg + '</li>';
});
errorHtml += '</ol>';
showErrorMessage(errorHtml);
}
},
complete: function() {
$(".loading_overlay").hide();
}
});
});
function updateServiceProducts(element)
{
var qty = $(element).closest('.room_demand_block').find('input.qty').val();
@@ -1695,17 +1790,12 @@
var id_product = $(dataElement).val();
var id_cart_booking = $(dataElement).data('id_cart_booking');
var service_price = $("#service_cart_price_"+id_cart_booking+"_"+id_product).val();
if (operator == 'up') {
$("#service_cart_price_"+id_cart_booking+"_"+id_product+"_input").show();
$("#service_cart_price_"+id_cart_booking+"_"+id_product+"_txt").hide();
} else {
$("#service_cart_price_"+id_cart_booking+"_"+id_product+"_input").hide();
$("#service_cart_price_"+id_cart_booking+"_"+id_product+"_txt").show();
}
if (typeof(qty) == 'undefined') {
qty = 1;
}
$(".loading_overlay").show();
$.ajax({
type: 'POST',
headers: {
@@ -1730,7 +1820,10 @@
showErrorMessage(jsonData.errors);
}
}
},
complete: function() {
$(".loading_overlay").hide();
}
});
}
@@ -2293,8 +2386,7 @@
{addJsDefL name='max_children_txt'}{l s='Maximum children occupancy reached' js=1}{/addJsDefL}
{addJsDefL name='no_children_allowed_txt'}{l s='Only adults can be accommodated' js=1}{/addJsDefL}
{addJsDefL name='invalid_occupancy_txt'}{l s='Invalid occupancy(adults/children) found.' js=1}{/addJsDefL}
{addJsDefL name='error_found_txt'}{l s='Errors found' js=1}{/addJsDefL}
{/strip}
<div id="loader_container">

View File

@@ -0,0 +1,170 @@
{*
* Since 2010 Webkul.
*
* NOTICE OF LICENSE
*
* All right is reserved,
* Please go through this link for complete license : https://store.webkul.com/license.html
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future. If you wish to customize this module for your
* needs please refer to https://store.webkul.com/customisation-guidelines/ for more information.
*
* @author Webkul IN <support@webkul.com>
* @copyright Since 2010 Webkul IN
* @license https://store.webkul.com/license.html
*}
<div id="room_type_service_product_desc" class="tab-pane{if !isset($selectedRoomDemands) || !$selectedRoomDemands} active{/if}">
{if $customServiceAllowed}
<div class="row">
<button id="btn_new_room_service" class="btn btn-success pull-right"><i class="icon-plus-circle"></i> {l s='Add a new service'}</button>
<button id="back_to_service_btn" class="btn btn-default"><i class="icon-arrow-left"></i> {l s='Back'}</button>
</div>
<hr>
{/if}
{if isset($serviceProducts) && $serviceProducts}
<div id="room_type_services_desc">
{assign var=roomCount value=1}
<div class="row room_demands_container">
<div class="col-sm-12 room_demand_detail">
{if isset($serviceProducts) && $serviceProducts}
<table class="table table-striped">
<thead>
<tr>
<th></th>
<th>{l s='Name'}</th>
<th class="fixed-width-sm"></th>
<th class="fixed-width-sm">{l s='Quantity'}</th>
<th>{l s='Unit Price (tax excl.)'}</th>
</tr>
</thead>
<tbody>
{foreach $serviceProducts as $product}
<tr class="room_demand_block">
<td>
<input data-id_cart_booking="{$selectedRoomServiceProduct['id']}" value="{$product['id_product']|escape:'html':'UTF-8'}" type="checkbox" class="change_room_type_service_product" {if isset($selectedRoomServiceProduct['selected_service']) && $selectedRoomServiceProduct['selected_service'] && ($product['id_product']|array_key_exists:$selectedRoomServiceProduct['selected_service'])}checked{/if}/>
</td>
<td>
<p>{$product['name']|escape:'html':'UTF-8'}</p>
</td>
<td>
{if $product['auto_add_to_cart'] && $product['price_addition_type'] == Product::PRICE_ADDITION_TYPE_INDEPENDENT}
<span class="badge badge-info label">{l s='Convenience fee'}</span>
{/if}
{if $product['auto_add_to_cart'] && $product['price_addition_type'] == Product::PRICE_ADDITION_TYPE_WITH_ROOM}
<span class="badge badge-info label">{l s='Auto added'}</span>
{/if}
</td>
<td>
{if $product.allow_multiple_quantity}
<div class="qty_container">
<input type="number" class="form-control room_type_service_product_qty qty" id="qty_{$product.id_product}" name="service_product_qty_{$product.id_product}" data-id-product="{$product.id_product}" min="1" data-max-quantity="{$product.max_quantity}" value="{if isset($selectedRoomServiceProduct['selected_service']) && $selectedRoomServiceProduct['selected_service'] && ($product['id_product']|array_key_exists:$selectedRoomServiceProduct['selected_service'])}{$selectedRoomServiceProduct['selected_service'][$product['id_product']]['quantity']}{else}1{/if}">
<p style="display:{if isset($selectedRoomServiceProduct['selected_service']) && $selectedRoomServiceProduct['selected_service'] && ($product['id_product']|array_key_exists:$selectedRoomServiceProduct['selected_service']) && $selectedRoomServiceProduct['selected_service'][$product['id_product']]['quantity'] > $product.max_quantity}block{else}none{/if}; margin-top: 4px;">
<span class="label label-warning">{l s='Maximum allowed quantity: %s' sprintf=$product.max_quantity}</span>
</p>
</div>
{else}
--
{/if}
</td>
<td>
{if ($product.show_price && !isset($restricted_country_mode)) || isset($groups)}
<div id="service_cart_price_{$selectedRoomServiceProduct['id']}_{$product['id_product']}_input" class="input-group">
<span class="input-group-addon">
{$cartCurrency->sign}
</span>
<input class="service_cart_price_input" id="service_cart_price_{$selectedRoomServiceProduct['id']}_{$product['id_product']}" type="text" value="{$product.price_tax_exc}"/>
{if Product::PRICE_CALCULATION_METHOD_PER_DAY == $product['price_calculation_method']}
<span class="input-group-addon">{l s='/ night'}</span>
{/if}
</div>
{/if}
</td>
</tr>
{/foreach}
</tbody>
</table>
{/if}
</div>
</div>
</div>
{/if}
{if $customServiceAllowed}
<div id="add_new_room_services_block" class="row">
<form id="add_new_room_services_form" class="col-sm-12 room_services_container">
<div class="row form-group">
<div class="col-sm-6">
<label class="control-label required">{l s='Name'}</label>
<input type="text" class="form-control" name="new_service_name"/>
</div>
<div class="col-sm-6">
<label class="control-label required">{l s='Price(tax excl.)'}</label>
<div class="input-group">
<span class="input-group-addon">{$cartCurrency->sign}</span>
<input type="text" class="form-control" name="new_service_price"/>
</div>
</div>
</div>
<div class="row form-group">
<div class="col-sm-6">
<label class="control-label">{l s='Price calculation method'}</label>
<select class="form-control" name="new_service_price_calc_method">
<option value="{Product::PRICE_CALCULATION_METHOD_PER_BOOKING}">{l s='Add price once for the booking range'}</option>
<option value="{Product::PRICE_CALCULATION_METHOD_PER_DAY}">{l s='Add price for each day of booking'}</option>
</select>
</div>
<div class="col-sm-6">
<label class="control-label">{l s='Auto added service'}</label>
<div>
<span class="switch prestashop-switch fixed-width-lg">
<input type="radio" name="new_service_auto_added" id="new_service_auto_added_on" value="1"/>
<label for="new_service_auto_added_on" class="radioCheck">
{l s='Yes'}
</label>
<input type="radio" name="new_service_auto_added" id="new_service_auto_added_off" value="0" checked="checked"/>
<label for="new_service_auto_added_off" class="radioCheck">
{l s='No'}
</label>
<a class="slide-button btn"></a>
</span>
</div>
</div>
</div>
<div class="row form-group">
<div id="new_service_price_tax_rule_container" class="col-sm-6">
<label class="control-label">{l s='Tax rule'}</label>
<select name="new_service_price_tax_rule_group">
{foreach from=$taxRulesGroups item=taxRuleGroup}
<option value="{$taxRuleGroup.id_tax_rules_group}">{$taxRuleGroup.name}</option>
{/foreach}
</select>
</div>
<div id="new_service_price_addition_type_container" class="col-sm-6" style="display:none;">
<label class="control-label">{l s='Price display preference'}</label>
<select name="new_service_price_addition_type" id="new_service_price_addition_type">
<option value="{Product::PRICE_ADDITION_TYPE_WITH_ROOM}">{l s='Add price in room price'}</option>
<option value="{Product::PRICE_ADDITION_TYPE_INDEPENDENT}">{l s='Add price as convenience Fee'}</option>
</select>
</div>
<div id="new_service_qty_container" class="col-sm-6">
<label class="control-label required">{l s='Quantity'}</label>
<input type="number" class="form-control qty" min="1" name="new_service_qty" value="1">
</div>
</div>
<input type="hidden" name="id_hotel_cart_booking" value="{$id_hotel_cart_booking}">
<div class="row form-group">
<div class="col-sm-12 help-block">
{l s='Note: If auto added service is enabled, then tax of the booking\'s room type will be applicable.'}
</div>
</div>
<div class="modal-footer">
<button type="submit" id="save_new_service" class="btn btn-primary"><i class="icon icon-save"></i> &nbsp;{l s="Update Service"}</button>
</div>
</form>
</div>
{/if}
</div>

View File

@@ -21,7 +21,9 @@
{if isset($orderEdit) && $orderEdit}
<div class="col-sm-12 facility_nav_btn">
<button id="btn_new_room_service" class="btn btn-success pull-right"><i class="icon-plus-circle"></i> {l s='Add a new service'}</button>
{if $customServiceAllowed}
<button id="btn_new_room_service" class="btn btn-success pull-right"><i class="icon-plus-circle"></i> {l s='Add a new service'}</button>
{/if}
<button id="btn_new_existing_room_service" class="btn btn-success"><i class="icon-plus-circle"></i> {l s='Add existing service'}</button>
<button id="back_to_service_btn" class="btn btn-default"><i class="icon-arrow-left"></i> {l s='Back'}</button>
<hr>
@@ -159,79 +161,81 @@
<input type="hidden" name="id_booking_detail" value="{$id_booking_detail}">
</form>
<form id="add_new_room_services_form" class="col-sm-12 room_services_container">
<div class="row form-group">
<div class="col-sm-6">
<label class="control-label required">{l s='Name'}</label>
<input type="text" class="form-control" name="new_service_name"/>
</div>
<div class="col-sm-6">
<label class="control-label required">{l s='Price(tax excl.)'}</label>
<div class="input-group">
<span class="input-group-addon">{$currencySign}</span>
<input type="text" class="form-control" name="new_service_price"/>
</div>
</div>
</div>
<div class="row form-group">
<div class="col-sm-6">
<label class="control-label">{l s='Price calculation method'}</label>
<select class="form-control" name="new_service_price_calc_method">
<option value="{Product::PRICE_CALCULATION_METHOD_PER_BOOKING}">{l s='Add price once for the booking range'}</option>
<option value="{Product::PRICE_CALCULATION_METHOD_PER_DAY}">{l s='Add price for each day of booking'}</option>
</select>
</div>
<div class="col-sm-6">
<label class="control-label">{l s='Auto added service'}</label>
<div>
<span class="switch prestashop-switch fixed-width-lg">
<input type="radio" name="new_service_auto_added" id="new_service_auto_added_on" value="1"/>
<label for="new_service_auto_added_on" class="radioCheck">
{l s='Yes'}
</label>
<input type="radio" name="new_service_auto_added" id="new_service_auto_added_off" value="0" checked="checked"/>
<label for="new_service_auto_added_off" class="radioCheck">
{l s='No'}
</label>
<a class="slide-button btn"></a>
</span>
</div>
</div>
</div>
<div class="row form-group">
<div id="new_service_price_tax_rule_container" class="col-sm-6">
<label class="control-label">{l s='Tax rule'}</label>
<select name="new_service_price_tax_rule_group">
{foreach from=$taxRulesGroups item=taxRuleGroup}
<option value="{$taxRuleGroup.id_tax_rules_group}">{$taxRuleGroup.name}</option>
{/foreach}
</select>
</div>
<div id="new_service_price_addition_type_container" class="col-sm-6" style="display:none;">
<label class="control-label">{l s='Price display preference'}</label>
<select name="new_service_price_addition_type" id="new_service_price_addition_type">
<option value="{Product::PRICE_ADDITION_TYPE_WITH_ROOM}">{l s='Add price in room price'}</option>
<option value="{Product::PRICE_ADDITION_TYPE_INDEPENDENT}">{l s='Add price as convenience Fee'}</option>
</select>
</div>
<div id="new_service_qty_container" class="col-sm-6">
<label class="control-label required">{l s='Quantity'}</label>
<input type="number" class="form-control qty" min="1" name="new_service_qty" value="1">
</div>
</div>
{if $roomTypeTaxRuleGroupExist}
{if $customServiceAllowed}
<form id="add_new_room_services_form" class="col-sm-12 room_services_container">
<div class="row form-group">
<div class="col-sm-12 help-block">
{l s='Note: If auto added service is enabled, then tax of the booking\'s room type will be applicable.'}
<div class="col-sm-6">
<label class="control-label required">{l s='Name'}</label>
<input type="text" class="form-control" name="new_service_name"/>
</div>
<div class="col-sm-6">
<label class="control-label required">{l s='Price(tax excl.)'}</label>
<div class="input-group">
<span class="input-group-addon">{$currencySign}</span>
<input type="text" class="form-control" name="new_service_price"/>
</div>
</div>
</div>
{/if}
<div class="modal-footer">
<button type="submit" id="save_new_service" class="btn btn-primary"><i class="icon icon-save"></i> &nbsp;{l s="Update Service"}</button>
</div>
<input type="hidden" name="id_booking_detail" value="{$id_booking_detail}">
<input type="hidden" id="room_type_tax_rule_group_exist" name="room_type_tax_rule_group_exist" value="{$roomTypeTaxRuleGroupExist}">
</form>
<div class="row form-group">
<div class="col-sm-6">
<label class="control-label">{l s='Price calculation method'}</label>
<select class="form-control" name="new_service_price_calc_method">
<option value="{Product::PRICE_CALCULATION_METHOD_PER_BOOKING}">{l s='Add price once for the booking range'}</option>
<option value="{Product::PRICE_CALCULATION_METHOD_PER_DAY}">{l s='Add price for each day of booking'}</option>
</select>
</div>
<div class="col-sm-6">
<label class="control-label">{l s='Auto added service'}</label>
<div>
<span class="switch prestashop-switch fixed-width-lg">
<input type="radio" name="new_service_auto_added" id="new_service_auto_added_on" value="1"/>
<label for="new_service_auto_added_on" class="radioCheck">
{l s='Yes'}
</label>
<input type="radio" name="new_service_auto_added" id="new_service_auto_added_off" value="0" checked="checked"/>
<label for="new_service_auto_added_off" class="radioCheck">
{l s='No'}
</label>
<a class="slide-button btn"></a>
</span>
</div>
</div>
</div>
<div class="row form-group">
<div id="new_service_price_tax_rule_container" class="col-sm-6">
<label class="control-label">{l s='Tax rule'}</label>
<select name="new_service_price_tax_rule_group">
{foreach from=$taxRulesGroups item=taxRuleGroup}
<option value="{$taxRuleGroup.id_tax_rules_group}">{$taxRuleGroup.name}</option>
{/foreach}
</select>
</div>
<div id="new_service_price_addition_type_container" class="col-sm-6" style="display:none;">
<label class="control-label">{l s='Price display preference'}</label>
<select name="new_service_price_addition_type" id="new_service_price_addition_type">
<option value="{Product::PRICE_ADDITION_TYPE_WITH_ROOM}">{l s='Add price in room price'}</option>
<option value="{Product::PRICE_ADDITION_TYPE_INDEPENDENT}">{l s='Add price as convenience Fee'}</option>
</select>
</div>
<div id="new_service_qty_container" class="col-sm-6">
<label class="control-label required">{l s='Quantity'}</label>
<input type="number" class="form-control qty" min="1" name="new_service_qty" value="1">
</div>
</div>
{if $roomTypeTaxRuleGroupExist}
<div class="row form-group">
<div class="col-sm-12 help-block">
{l s='Note: If auto added service is enabled, then tax of the booking\'s room type will be applicable.'}
</div>
</div>
{/if}
<div class="modal-footer">
<button type="submit" id="save_new_service" class="btn btn-primary"><i class="icon icon-save"></i> &nbsp;{l s="Update Service"}</button>
</div>
<input type="hidden" name="id_booking_detail" value="{$id_booking_detail}">
<input type="hidden" id="room_type_tax_rule_group_exist" name="room_type_tax_rule_group_exist" value="{$roomTypeTaxRuleGroupExist}">
</form>
{/if}
{elseif isset($additionalServices) && $additionalServices}
<table class="table room_demand_detail">

View File

@@ -26,7 +26,7 @@
/* Debug only */
if (!defined('_PS_MODE_DEV_')) {
define('_PS_MODE_DEV_', false);
define('_PS_MODE_DEV_', true);
}
/* Compatibility warning */
define('_PS_DISPLAY_COMPATIBILITY_WARNING_', false);

View File

@@ -1064,84 +1064,107 @@ class AdminCartsControllerCore extends AdminController
// Process to get extra demands of any room while order creation process form.tpl
public function ajaxProcessGetRoomTypeCartDemands()
{
$response = array('status' => false);
if ($idProduct = Tools::getValue('id_product')) {
if (($dateFrom = Tools::getValue('date_from'))
&& ($dateTo = Tools::getValue('date_to'))
&& ($idRoom = Tools::getValue('id_room'))
&& ($idCart = Tools::getValue('id_cart'))
) {
$objCartBookingData = new HotelCartBookingData();
if ($selectedRoomDemands = $objCartBookingData->getCartExtraDemands(
$idCart,
$idProduct,
$idRoom,
$dateFrom,
$dateTo
)) {
// get room type additional demands
$objRoomDemands = new HotelRoomTypeDemand();
if ($roomTypeDemands = $objRoomDemands->getRoomTypeDemands($idProduct)) {
foreach ($roomTypeDemands as &$demand) {
// if demand has advance options then set demand price as first advance option price.
if (isset($demand['adv_option']) && $demand['adv_option']) {
$demand['price'] = current($demand['adv_option'])['price'];
}
$response['hasError'] = false;
$response['errors'] = [];
if (($idProduct = Tools::getValue('id_product'))
&& ($dateFrom = Tools::getValue('date_from'))
&& ($dateTo = Tools::getValue('date_to'))
&& ($idRoom = Tools::getValue('id_room'))
&& ($idCart = Tools::getValue('id_cart'))
&& ($idHotelCartBooking = Tools::getValue('id_hotel_cart_booking'))
) {
$objCartBookingData = new HotelCartBookingData();
if ($selectedRoomDemands = $objCartBookingData->getCartExtraDemands(
$idCart,
$idProduct,
$idRoom,
$dateFrom,
$dateTo
)) {
// get room type additional demands
$objRoomDemands = new HotelRoomTypeDemand();
if ($roomTypeDemands = $objRoomDemands->getRoomTypeDemands($idProduct)) {
foreach ($roomTypeDemands as &$demand) {
// if demand has advance options then set demand price as first advance option price.
if (isset($demand['adv_option']) && $demand['adv_option']) {
$demand['price'] = current($demand['adv_option'])['price'];
}
foreach ($selectedRoomDemands as &$selectedDemand) {
$objRoom = new HotelRoomInformation($selectedDemand['id_room']);
$selectedDemand['room_num'] = $objRoom->room_num;
if (isset($selectedDemand['extra_demands']) && $selectedDemand['extra_demands']) {
$extraDmd = array();
foreach ($selectedDemand['extra_demands'] as $sDemand) {
$selectedDemand['selected_global_demands'][] = $sDemand['id_global_demand'];
$extraDmd[$sDemand['id_global_demand'].'-'.$sDemand['id_option']] = $sDemand;
}
$selectedDemand['extra_demands'] = $extraDmd;
}
foreach ($selectedRoomDemands as &$selectedDemand) {
$objRoom = new HotelRoomInformation($selectedDemand['id_room']);
$selectedDemand['room_num'] = $objRoom->room_num;
if (isset($selectedDemand['extra_demands']) && $selectedDemand['extra_demands']) {
$extraDmd = array();
foreach ($selectedDemand['extra_demands'] as $sDemand) {
$selectedDemand['selected_global_demands'][] = $sDemand['id_global_demand'];
$extraDmd[$sDemand['id_global_demand'].'-'.$sDemand['id_option']] = $sDemand;
}
$selectedDemand['extra_demands'] = $extraDmd;
}
$this->context->smarty->assign('roomTypeDemands', $roomTypeDemands);
$this->context->smarty->assign('selectedRoomDemands', $selectedRoomDemands);
}
$this->context->smarty->assign('roomTypeDemands', $roomTypeDemands);
$this->context->smarty->assign('selectedRoomDemands', $selectedRoomDemands);
}
}
if (Configuration::get('PS_ALLOW_ADD_ALL_SERVICES_IN_BOOKING')) {
// get all services
$objProduct = new Product();
$serviceProducts = $objProduct->getServiceProducts();
} else {
$objRoomTypeServiceProduct = new RoomTypeServiceProduct();
$serviceProducts = $objRoomTypeServiceProduct->getServiceProductsData($idProduct, 1, 0, false, 2, null);
}
if ($serviceProducts) {
$objRoomTypeServPrice = new RoomTypeServiceProductPrice();
foreach ($serviceProducts as $key => $servProduct) {
$serviceProducts[$key]['price_tax_exc'] = $objRoomTypeServPrice->getServicePrice($servProduct['id_product'], 0, 1, null, null, false, $idCart);
if ($additionalServices
&& (in_array($servProduct['id_product'], array_column($additionalServices['additional_services'], 'id_product')))
) {
unset($serviceProducts[$key]);
}
}
$objRoomTypeServiceProduct = new RoomTypeServiceProduct();
$objRoomTypeServiceProductCartDetail = new RoomTypeServiceProductCartDetail();
$roomTypeServiceProducts = $objRoomTypeServiceProduct->getServiceProductsData($idProduct, 1, 0, false, 2, null);
if ($selectedRoomServiceProduct = $objCartBookingData->getRoomRowByIdProductIdRoomInDateRange(
$idCart,
$idProduct,
$dateFrom,
$dateTo,
$idRoom
)) {
$selectedRoomServiceProduct['selected_service'] = $objRoomTypeServiceProductCartDetail->getRoomServiceProducts(
$selectedRoomServiceProduct['id'],
0,
null,
null
);
}
}
$objCart = new Cart($idCart);
$cartCurrency = new Currency($objCart->id_currency);
$this->context->smarty->assign(array(
'cartCurrency' => $cartCurrency,
'roomTypeServiceProducts' => $roomTypeServiceProducts,
'selectedRoomServiceProduct' => $selectedRoomServiceProduct
));
$htlCartBoookingata = $objCartBookingData->getRoomRowByIdProductIdRoomInDateRange(
$idCart,
$idProduct,
$dateFrom,
$dateTo,
$idRoom
if ($selectedRoomServiceProduct = $objCartBookingData->getRoomRowByIdProductIdRoomInDateRange(
$idCart,
$idProduct,
$dateFrom,
$dateTo,
$idRoom
)) {
$objRoomTypeServiceProductCartDetail = new RoomTypeServiceProductCartDetail();
$selectedRoomServiceProduct['selected_service'] = $objRoomTypeServiceProductCartDetail->getRoomServiceProducts(
$selectedRoomServiceProduct['id'],
0,
null,
null
);
}
$objCart = new Cart($idCart);
$cartCurrency = new Currency($objCart->id_currency);
$taxRulesGroups = TaxRulesGroup::getTaxRulesGroups(true);
$this->context->smarty->assign(array(
'taxRulesGroups' => $taxRulesGroups,
'id_hotel_cart_booking' => $idHotelCartBooking,
'cartCurrency' => $cartCurrency,
'serviceProducts' => $serviceProducts,
'selectedRoomServiceProduct' => $selectedRoomServiceProduct,
'customServiceAllowed' => Configuration::get('PS_ALLOW_CREATE_CUSTOM_SERVICES_IN_BOOKING'),
'loaderImg' => $this->context->link->getMediaLink(_PS_IMG_.'admin/ajax-loader.gif')
));
$response['html_exta_demands'] = $this->context->smarty->fetch(
_PS_ADMIN_DIR_.'/themes/default/template/controllers/orders/_cart_booking_demands.tpl'
);
} else {
$response['hasError'] = true;
$response['errors'][] = $this->l('Some error occurred. please try again.');
}
$response['status'] = true;
$response['html_exta_demands'] = $this->context->smarty->fetch(
_PS_ADMIN_DIR_.'/themes/default/template/controllers/orders/_cart_booking_demands.tpl'
);
$this->ajaxDie(json_encode($response));
}
@@ -1227,4 +1250,208 @@ class AdminCartsControllerCore extends AdminController
$list = $helper->generateList($this->_list, $this->fields_list);
return $list;
}
// Add new custom services to room
public function ajaxProcessAddNewRoomServices()
{
$response = array('hasError' => false);
// Check tab access is allowed to edit
if ($this->tabAccess['edit'] == 1) {
if (Configuration::get('PS_ALLOW_CREATE_CUSTOM_SERVICES_IN_BOOKING')) {
$idHotelCartBooking = Tools::getValue('id_hotel_cart_booking');
// valiadate services being added
if (Validate::isLoadedObject($objHtlCartBooking = new HotelCartBookingData($idHotelCartBooking))) {
$name = Tools::getValue('new_service_name');
$price = Tools::getValue('new_service_price');
$priceCalcMethod = Tools::getValue('new_service_price_calc_method');
$priceAdditionType = Tools::getValue('new_service_price_addition_type');
$productQty = Tools::getValue('new_service_qty');
$idTaxRuleGroup = Tools::getValue('new_service_price_tax_rule_group');
$autoAdded = Tools::getValue('new_service_auto_added');
// adjust values for auto added services
if ($autoAdded) {
$productQty = 1;
$objRoomType = new Product($objHtlCartBooking->id_product);
if (Validate::isLoadedObject($objTaxRuleGroup = new TaxRulesGroup($objRoomType->id_tax_rules_group))) {
$idTaxRuleGroup = $objRoomType->id_tax_rules_group;
}
} else {
$priceAdditionType = 0;
if (empty($productQty)) {
$response['hasError'] = true;
$response['errors'][] = $this->l('Service quantity is required');
} elseif (!Validate::isUnsignedInt($productQty)) {
$response['hasError'] = true;
$response['errors'][] = $this->l('Invalid service quantity');
}
}
// Validate service data provided
if (empty($name)) {
$response['hasError'] = true;
$response['errors'][] = $this->l('Service name is required');
} elseif (!Validate::isCatalogName($name)) {
$response['hasError'] = true;
$response['errors'][] = $this->l('Invalid service name');
}
if (empty($price)) {
$response['hasError'] = true;
$response['errors'][] = $this->l('Service price is required');
} elseif (!Validate::isPrice($price)) {
$response['hasError'] = true;
$response['errors'][] = $this->l('Invalid service price');
}
// if no validation errors then add service
if (!$response['hasError']) {
// ======= START: Create Service product =========
$objServiceProduct = new Product();
$objServiceProduct->price_calculation_method = $priceCalcMethod;
$objServiceProduct->service_product_type = Product::SERVICE_PRODUCT_WITH_ROOMTYPE;
$objServiceProduct->id_category_default = Configuration::get('PS_SERVICE_CATEGORY');
$objServiceProduct->name[Configuration::get('PS_LANG_DEFAULT')] = $name;
$objServiceProduct->id_shop_default = Configuration::get('PS_SHOP_DEFAULT');
$objServiceProduct->allow_multiple_quantity = !$autoAdded;
$objServiceProduct->id_tax_rules_group = $idTaxRuleGroup;
$objServiceProduct->price = $price;
$objServiceProduct->wholesale_price = 0;
$languages = Language::getLanguages(false);
foreach ($languages as $lang) {
$objServiceProduct->link_rewrite[$lang['id_lang']] = Tools::link_rewrite($name);
}
$objServiceProduct->available_for_order = true;
$objServiceProduct->show_price = true;
$objServiceProduct->is_virtual = true;
$objServiceProduct->auto_add_to_cart = $autoAdded;
$objServiceProduct->price_addition_type = $priceAdditionType;
$objServiceProduct->booking_product = false;
$objServiceProduct->show_at_front = false;
$objServiceProduct->indexed = false;
$objServiceProduct->minimal_quantity = 1;
$objServiceProduct->active = true;
$objServiceProduct->max_quantity = 99999;
// ======= Create Service product END =========
if ($objServiceProduct->save()) {
// If service product is create successfully the start adding the product in cart and order
$objCart = new Cart($objHtlCartBooking->id_cart);
$objServiceProduct = new Product($objServiceProduct->id, false, $objCart->id_lang);
$objRoomTypeServiceProductCartDetail = new RoomTypeServiceProductCartDetail();
if ($objRoomTypeServiceProductCartDetail->addServiceProductInCart(
$objServiceProduct->id,
$productQty,
$objCart->id,
$objHtlCartBooking->id
)) {
// Lets create a specific price for the service to match the price provided by the user
$objSpecificPrice = new SpecificPrice();
$objSpecificPrice->id_shop = 0;
$objSpecificPrice->id_shop_group = 0;
$objSpecificPrice->id_cart = $objCart->id;
$objSpecificPrice->id_currency = $objCart->id_currency;
$objSpecificPrice->id_country = 0;
$objSpecificPrice->id_group = 0;
$objSpecificPrice->id_customer = $objCart->id_customer;
$objSpecificPrice->id_product = $objServiceProduct->id;
$objSpecificPrice->id_product_attribute = 0;
$objSpecificPrice->price = $price;
$objSpecificPrice->from_quantity = 1;
$objSpecificPrice->reduction = 0;
$objSpecificPrice->reduction_type = 'amount';
$objSpecificPrice->reduction_tax = 0;
$objSpecificPrice->from = '0000-00-00 00:00:00';
$objSpecificPrice->to = '0000-00-00 00:00:00';
if ($objSpecificPrice->add()) {
$response['service_panel'] = $this->getBookingServicesTabContent($objHtlCartBooking->id);
} else {
$response['hasError'] = true;
$response['errors'][] = $this->l('Some error occurred while adding service to the room');
}
} else {
$response['hasError'] = true;
$response['errors'][] = $this->l('Unable to add service to the room');
}
} else {
$response['hasError'] = true;
$response['errors'][] = $this->l('Unable to add service to the room');
}
}
} else {
$response['hasError'] = true;
$response['errors'][] = $this->l('Room not found');
}
} else {
$response['hasError'] = true;
$response['errors'][] = $this->l('Adding a new custom service is not allowed.');
}
} else {
$response['hasError'] = true;
$response['errors'][] = $this->l('You do not have permission to edit this order.');
}
die(json_encode($response));
}
public function getBookingServicesTabContent($idHotelCartBooking)
{
$servicesTpl = '';
if (Validate::isLoadedObject($objCartBookingData = new HotelCartBookingData($idHotelCartBooking))) {
if (Configuration::get('PS_ALLOW_ADD_ALL_SERVICES_IN_BOOKING')) {
// get all services
$objProduct = new Product();
$serviceProducts = $objProduct->getServiceProducts();
} else {
$objRoomTypeServiceProduct = new RoomTypeServiceProduct();
$serviceProducts = $objRoomTypeServiceProduct->getServiceProductsData($objCartBookingData->id_product, 1, 0, false, 2, null);
}
if ($serviceProducts) {
foreach ($serviceProducts as $key => $servProduct) {
$serviceProducts[$key]['price_tax_exc'] = $servProduct['price'];
if ($additionalServices
&& (in_array($servProduct['id_product'], array_column($additionalServices['additional_services'], 'id_product')))
) {
unset($serviceProducts[$key]);
}
}
}
if ($selectedRoomServiceProduct = $objCartBookingData->getRoomRowByIdProductIdRoomInDateRange(
$objCartBookingData->id_cart,
$objCartBookingData->id_product,
$objCartBookingData->date_from,
$objCartBookingData->date_to,
$objCartBookingData->id_room
)) {
$objRoomTypeServiceProductCartDetail = new RoomTypeServiceProductCartDetail();
$selectedRoomServiceProduct['selected_service'] = $objRoomTypeServiceProductCartDetail->getRoomServiceProducts(
$selectedRoomServiceProduct['id'],
0,
null,
null
);
}
$objCart = new Cart($objCartBookingData->id_cart);
$cartCurrency = new Currency($objCart->id_currency);
$taxRulesGroups = TaxRulesGroup::getTaxRulesGroups(true);
$this->context->smarty->assign(array(
'id_hotel_cart_booking' => $idHotelCartBooking,
'taxRulesGroups' => $taxRulesGroups,
'cartCurrency' => $cartCurrency,
'serviceProducts' => $serviceProducts,
'selectedRoomServiceProduct' => $selectedRoomServiceProduct,
'customServiceAllowed' => Configuration::get('PS_ALLOW_CREATE_CUSTOM_SERVICES_IN_BOOKING'),
));
$servicesTpl = $this->context->smarty->fetch(
_PS_ADMIN_DIR_.'/themes/default/template/controllers/orders/modals/_add_order_extra_services_tab_content.tpl'
);
}
return $servicesTpl;
}
}

View File

@@ -197,7 +197,7 @@ class AdminOrderPreferencesControllerCore extends AdminController
'type' => 'bool'
),
'PS_ORDER_LIST_PRICE_DISPLAY_CURRENCY' => array(
'title' => $this->l('Display order list prices in'),
'title' => $this->l('Display order list prices in Back Office'),
'hint' => $this->l('Choose the currency in which you want the prices in the order list to be displayed.'),
'desc' => $this->l('\'Order currency\' is the currency in which customer created the order and \'Default currency\' is the currency configured in localization.'),
'validation' => 'isInt',
@@ -222,6 +222,20 @@ class AdminOrderPreferencesControllerCore extends AdminController
'class' => 'fixed-width-xl',
'suffix' => $this->l('day(s)'),
),
'PS_ALLOW_ADD_ALL_SERVICES_IN_BOOKING' => array(
'title' => $this->l('Allow to add all services in a booking'),
'hint' => $this->l('Enable to allow all services created to be added in a booking while adding or editing a booking. Disable to allow only attached services with room type.'),
'desc' => $this->l('If enabled, only attached services with room type will be available to be added to a booking.'),
'cast' => 'intval',
'type' => 'bool'
),
'PS_ALLOW_CREATE_CUSTOM_SERVICES_IN_BOOKING' => array(
'title' => $this->l('Allow to create custom service for a booking'),
'hint' => $this->l('Enable to allow to create custom service while adding or editing a booking.'),
'desc' => $this->l('If disabled, a custom service can not be created while adding or editing a booking.'),
'cast' => 'intval',
'type' => 'bool'
),
),
'submit' => array('title' => $this->l('Save'))
),

View File

@@ -387,7 +387,8 @@ class AdminOrdersControllerCore extends AdminController
$this->context->currency = new Currency((int)$cart->id_currency);
// validate cart for removing invalid data from cart before new order creation
$this->errors = array_merge($this->errors, HotelCartBookingData::validateCartBookings());
// remove not linked services with room types from cart if not allowed to book them
$this->errors = array_merge($this->errors, HotelCartBookingData::validateCartBookings(!Configuration::get('PS_ALLOW_ADD_ALL_SERVICES_IN_BOOKING')));
$cart_detail_data = array();
$cart_detail_data_obj = new HotelCartBookingData();
@@ -948,9 +949,16 @@ class AdminOrdersControllerCore extends AdminController
$smartyVars['additionalServices'] = $additionalServices;
}
// get all services
$objProduct = new Product();
if ($serviceProducts = $objProduct->getServiceProducts()) {
if (Configuration::get('PS_ALLOW_ADD_ALL_SERVICES_IN_BOOKING')) {
// get all services
$objProduct = new Product();
$serviceProducts = $objProduct->getServiceProducts();
} else {
$objRoomTypeServiceProduct = new RoomTypeServiceProduct();
$serviceProducts = $objRoomTypeServiceProduct->getServiceProductsData($idProduct, 1, 0, false, 2, null);
}
if ($serviceProducts) {
foreach ($serviceProducts as $key => $servProduct) {
$serviceProducts[$key]['price_tax_exc'] = $servProduct['price'];
if ($additionalServices
@@ -959,10 +967,10 @@ class AdminOrdersControllerCore extends AdminController
unset($serviceProducts[$key]);
}
}
$smartyVars['serviceProducts'] = $serviceProducts;
}
$smartyVars['serviceProducts'] = $serviceProducts;
$objOrderReturn = new OrderReturn();
$refundReqBookings = $objOrderReturn->getOrderRefundRequestedBookings($objOrder->id, 0, 1);
$smartyVars['refundReqBookings'] = $refundReqBookings;
@@ -978,6 +986,9 @@ class AdminOrdersControllerCore extends AdminController
$taxRulesGroups = TaxRulesGroup::getTaxRulesGroups(true);
$smartyVars['taxRulesGroups'] = $taxRulesGroups;
$smartyVars['customServiceAllowed'] = Configuration::get('PS_ALLOW_CREATE_CUSTOM_SERVICES_IN_BOOKING');
$this->context->smarty->assign($smartyVars);
$modal = array(
@@ -2781,9 +2792,9 @@ class AdminOrdersControllerCore extends AdminController
$product['amount_refund'] = Tools::displayPrice($resume['amount_tax_incl'], $currency);
// if the current stock requires a warning
if ($product['current_stock'] <= 0 && $display_out_of_stock_warning) {
$this->displayWarning($this->l('This booked room type is not found: ').' '.$product['product_name']);
}
// if ($product['current_stock'] <= 0 && $display_out_of_stock_warning) {
// $this->displayWarning($this->l('This booked room type is not found: ').' '.$product['product_name']);
// }
if ($product['id_warehouse'] != 0) {
$warehouse = new Warehouse((int)$product['id_warehouse']);
$product['warehouse_name'] = $warehouse->name;
@@ -6282,9 +6293,16 @@ class AdminOrdersControllerCore extends AdminController
$smartyVars['orderEdit'] = $orderEdit;
// get room type additional demands
$objProduct = new Product();
if ($serviceProducts = $objProduct->getServiceProducts()) {
if (Configuration::get('PS_ALLOW_ADD_ALL_SERVICES_IN_BOOKING')) {
// get all services
$objProduct = new Product();
$serviceProducts = $objProduct->getServiceProducts();
} else {
$objRoomTypeServiceProduct = new RoomTypeServiceProduct();
$serviceProducts = $objRoomTypeServiceProduct->getServiceProductsData($idProduct, 1, 0, false, 2, null);
}
if ($serviceProducts) {
foreach ($serviceProducts as $key => $servProduct) {
$serviceProducts[$key]['price_tax_exc'] = $servProduct['price'];
if ($additionalServices
@@ -6293,9 +6311,11 @@ class AdminOrdersControllerCore extends AdminController
unset($serviceProducts[$key]);
}
}
$smartyVars['serviceProducts'] = $serviceProducts;
}
$smartyVars['serviceProducts'] = $serviceProducts;
$smartyVars['customServiceAllowed'] = Configuration::get('PS_ALLOW_CREATE_CUSTOM_SERVICES_IN_BOOKING');
// check if booking room type tax rule is still exist
$objHotelBookingDetail = new HotelBookingDetail($idHtlBookingDetail);
$objOrderDetail = new OrderDetail($objHotelBookingDetail->id_order_detail);
@@ -6833,195 +6853,200 @@ class AdminOrdersControllerCore extends AdminController
$response = array('hasError' => false);
// Check tab access is allowed to edit
if ($this->tabAccess['edit'] == 1) {
$idBookingDetail = Tools::getValue('id_booking_detail');
// valiadate services being added
if (Validate::isLoadedObject($objHotelBookingDetail = new HotelBookingDetail($idBookingDetail))) {
$objHotelCartBookingData = new HotelCartBookingData();
if ($roomHtlCartInfo = $objHotelCartBookingData->getRoomRowByIdProductIdRoomInDateRange(
$objHotelBookingDetail->id_cart,
$objHotelBookingDetail->id_product,
$objHotelBookingDetail->date_from,
$objHotelBookingDetail->date_to,
$objHotelBookingDetail->id_room
)) {
$name = Tools::getValue('new_service_name');
$price = Tools::getValue('new_service_price');
$priceCalcMethod = Tools::getValue('new_service_price_calc_method');
$priceAdditionType = Tools::getValue('new_service_price_addition_type');
$productQty = Tools::getValue('new_service_qty');
$idTaxRuleGroup = Tools::getValue('new_service_price_tax_rule_group');
$autoAdded = Tools::getValue('new_service_auto_added');
if (Configuration::get('PS_ALLOW_CREATE_CUSTOM_SERVICES_IN_BOOKING')) {
$idBookingDetail = Tools::getValue('id_booking_detail');
// valiadate services being added
if (Validate::isLoadedObject($objHotelBookingDetail = new HotelBookingDetail($idBookingDetail))) {
$objHotelCartBookingData = new HotelCartBookingData();
if ($roomHtlCartInfo = $objHotelCartBookingData->getRoomRowByIdProductIdRoomInDateRange(
$objHotelBookingDetail->id_cart,
$objHotelBookingDetail->id_product,
$objHotelBookingDetail->date_from,
$objHotelBookingDetail->date_to,
$objHotelBookingDetail->id_room
)) {
$name = Tools::getValue('new_service_name');
$price = Tools::getValue('new_service_price');
$priceCalcMethod = Tools::getValue('new_service_price_calc_method');
$priceAdditionType = Tools::getValue('new_service_price_addition_type');
$productQty = Tools::getValue('new_service_qty');
$idTaxRuleGroup = Tools::getValue('new_service_price_tax_rule_group');
$autoAdded = Tools::getValue('new_service_auto_added');
// adjust values for auto added services
if ($autoAdded) {
$productQty = 1;
// check if booking room type tax rule is still exist
$objOrderDetail = new OrderDetail($objHotelBookingDetail->id_order_detail);
if (Validate::isLoadedObject($objTaxRuleGroup = new TaxRulesGroup($objOrderDetail->id_tax_rules_group))) {
$idTaxRuleGroup = $objOrderDetail->id_tax_rules_group;
// adjust values for auto added services
if ($autoAdded) {
$productQty = 1;
// check if booking room type tax rule is still exist
$objOrderDetail = new OrderDetail($objHotelBookingDetail->id_order_detail);
if (Validate::isLoadedObject($objTaxRuleGroup = new TaxRulesGroup($objOrderDetail->id_tax_rules_group))) {
$idTaxRuleGroup = $objOrderDetail->id_tax_rules_group;
}
} else {
$priceAdditionType = 0;
if (empty($productQty)) {
$response['hasError'] = true;
$response['errors'][] = $this->l('Service quantity is required');
} elseif (!Validate::isUnsignedInt($productQty)) {
$response['hasError'] = true;
$response['errors'][] = $this->l('Invalid service quantity');
}
}
} else {
$priceAdditionType = 0;
if (empty($productQty)) {
// Validate service data provided
if (empty($name)) {
$response['hasError'] = true;
$response['errors'][] = $this->l('Service quantity is required');
} elseif (!Validate::isUnsignedInt($productQty)) {
$response['errors'][] = $this->l('Service name is required');
} elseif (!Validate::isCatalogName($name)) {
$response['hasError'] = true;
$response['errors'][] = $this->l('Invalid service quantity');
$response['errors'][] = $this->l('Invalid service name');
}
}
// Validate service data provided
if (empty($name)) {
$response['hasError'] = true;
$response['errors'][] = $this->l('Service name is required');
} elseif (!Validate::isCatalogName($name)) {
$response['hasError'] = true;
$response['errors'][] = $this->l('Invalid service name');
}
if (empty($price)) {
$response['hasError'] = true;
$response['errors'][] = $this->l('Service price is required');
} elseif (!Validate::isPrice($price)) {
$response['hasError'] = true;
$response['errors'][] = $this->l('Invalid service price');
}
// if no validation errors then add service
if (!$response['hasError']) {
// ======= START: Create Service product =========
$objServiceProduct = new Product();
$objServiceProduct->price_calculation_method = $priceCalcMethod;
$objServiceProduct->service_product_type = Product::SERVICE_PRODUCT_WITH_ROOMTYPE;
$objServiceProduct->id_category_default = Configuration::get('PS_SERVICE_CATEGORY');
$objServiceProduct->name[Configuration::get('PS_LANG_DEFAULT')] = $name;
$objServiceProduct->id_shop_default = Configuration::get('PS_SHOP_DEFAULT');
$objServiceProduct->allow_multiple_quantity = !$autoAdded;
$objServiceProduct->id_tax_rules_group = $idTaxRuleGroup;
$objServiceProduct->price = $price;
$objServiceProduct->wholesale_price = 0;
$languages = Language::getLanguages(false);
foreach ($languages as $lang) {
$objServiceProduct->link_rewrite[$lang['id_lang']] = Tools::link_rewrite($name);
if (empty($price)) {
$response['hasError'] = true;
$response['errors'][] = $this->l('Service price is required');
} elseif (!Validate::isPrice($price)) {
$response['hasError'] = true;
$response['errors'][] = $this->l('Invalid service price');
}
$objServiceProduct->available_for_order = true;
$objServiceProduct->show_price = true;
$objServiceProduct->is_virtual = true;
$objServiceProduct->auto_add_to_cart = $autoAdded;
$objServiceProduct->price_addition_type = $priceAdditionType;
$objServiceProduct->booking_product = false;
$objServiceProduct->show_at_front = false;
$objServiceProduct->indexed = false;
$objServiceProduct->minimal_quantity = 1;
$objServiceProduct->active = true;
// ======= Create Service product END =========
if ($objServiceProduct->save()) {
// If service product is create successfully the start adding the product in cart and order
$objServiceProduct = new Product($objServiceProduct->id, false, $objOrder->id_lang);
$objOrder = new Order($objHotelBookingDetail->id_order);
// if no validation errors then add service
if (!$response['hasError']) {
// ======= START: Create Service product =========
$objServiceProduct = new Product();
$objServiceProduct->price_calculation_method = $priceCalcMethod;
$objServiceProduct->service_product_type = Product::SERVICE_PRODUCT_WITH_ROOMTYPE;
$objServiceProduct->id_category_default = Configuration::get('PS_SERVICE_CATEGORY');
$objServiceProduct->name[Configuration::get('PS_LANG_DEFAULT')] = $name;
$objServiceProduct->id_shop_default = Configuration::get('PS_SHOP_DEFAULT');
$objServiceProduct->allow_multiple_quantity = !$autoAdded;
$objServiceProduct->id_tax_rules_group = $idTaxRuleGroup;
$objServiceProduct->price = $price;
$objServiceProduct->wholesale_price = 0;
$languages = Language::getLanguages(false);
foreach ($languages as $lang) {
$objServiceProduct->link_rewrite[$lang['id_lang']] = Tools::link_rewrite($name);
}
$objServiceProduct->available_for_order = true;
$objServiceProduct->show_price = true;
$objServiceProduct->is_virtual = true;
$objServiceProduct->auto_add_to_cart = $autoAdded;
$objServiceProduct->price_addition_type = $priceAdditionType;
$objServiceProduct->booking_product = false;
$objServiceProduct->show_at_front = false;
$objServiceProduct->indexed = false;
$objServiceProduct->minimal_quantity = 1;
$objServiceProduct->active = true;
// Create new cart
$objCart = new Cart();
$objCart->id_shop_group = $objOrder->id_shop_group;
$objCart->id_shop = $objOrder->id_shop;
$objCart->id_customer = $objOrder->id_customer;
$objCart->id_carrier = $objOrder->id_carrier;
$objCart->id_address_delivery = $objOrder->id_address_delivery;
$objCart->id_address_invoice = $objOrder->id_address_invoice;
$objCart->id_currency = $objOrder->id_currency;
$objCart->id_lang = $objOrder->id_lang;
$objCart->secure_key = $objOrder->secure_key;
if ($objCart->add()) {
$this->context->cart = $objCart;
$this->context->customer = new Customer($objOrder->id_customer);
// set context currency So that we can get prices in the order currency
$this->context->currency = new Currency($objOrder->id_currency);
// ======= Create Service product END =========
if ($objServiceProduct->save()) {
// If service product is create successfully the start adding the product in cart and order
$objOrder = new Order($objHotelBookingDetail->id_order);
$objServiceProduct = new Product($objServiceProduct->id, false, $objOrder->id_lang);
$objRoomTypeServiceProductCartDetail = new RoomTypeServiceProductCartDetail();
if ($objRoomTypeServiceProductCartDetail->addServiceProductInCart(
$objServiceProduct->id,
$productQty,
$objCart->id,
$roomHtlCartInfo['id']
)) {
if ($productList = $objCart->getProducts()) {
$totalPriceChangeTaxExcl = 0;
$totalPriceChangeTaxIncl = 0;
$unitPriceTaxIncl = 0;
$unitPriceTaxExcl = 0;
// Create new cart
$objCart = new Cart();
$objCart->id_shop_group = $objOrder->id_shop_group;
$objCart->id_shop = $objOrder->id_shop;
$objCart->id_customer = $objOrder->id_customer;
$objCart->id_carrier = $objOrder->id_carrier;
$objCart->id_address_delivery = $objOrder->id_address_delivery;
$objCart->id_address_invoice = $objOrder->id_address_invoice;
$objCart->id_currency = $objOrder->id_currency;
$objCart->id_lang = $objOrder->id_lang;
$objCart->secure_key = $objOrder->secure_key;
if ($objCart->add()) {
$this->context->cart = $objCart;
$this->context->customer = new Customer($objOrder->id_customer);
// set context currency So that we can get prices in the order currency
$this->context->currency = new Currency($objOrder->id_currency);
$objRoomTypeServiceProductPrice = new RoomTypeServiceProductPrice();
$cartProductProcessed = 1;
$numDays = 1;
if (Product::getProductPriceCalculation($objServiceProduct->id) == Product::PRICE_CALCULATION_METHOD_PER_DAY) {
$numDays = HotelHelper::getNumberOfDays($objHotelBookingDetail->date_from, $objHotelBookingDetail->date_to);
}
foreach ($productList as &$product) {
// This is used to get the actual quanity of the service as it is calculated incorrectly if the service is per night
if ($idRoomTypeServProductCart = $objRoomTypeServiceProductCartDetail->alreadyExists(
$product['id_product'],
$objCart->id,
$roomHtlCartInfo['id'])
) {
// Lets create a specific price for the service to match the price provided by the user
$objSpecificPrice = new SpecificPrice();
$objSpecificPrice->id_shop = 0;
$objSpecificPrice->id_shop_group = 0;
$objSpecificPrice->id_cart = $objCart->id;
$objSpecificPrice->id_currency = $objOrder->id_currency;
$objSpecificPrice->id_country = 0;
$objSpecificPrice->id_group = 0;
$objSpecificPrice->id_customer = $objOrder->id_customer;
$objSpecificPrice->id_product = $objServiceProduct->id;
$objSpecificPrice->id_product_attribute = 0;
$objSpecificPrice->price = $price;
$objSpecificPrice->from_quantity = 1;
$objSpecificPrice->reduction = 0;
$objSpecificPrice->reduction_type = 'amount';
$objSpecificPrice->reduction_tax = 0;
$objSpecificPrice->from = '0000-00-00 00:00:00';
$objSpecificPrice->to = '0000-00-00 00:00:00';
if ($objSpecificPrice->add()) {
if (Validate::isLoadedObject($objRoomTypeServiceProductCartDetail = new RoomTypeServiceProductCartDetail((int) $idRoomTypeServProductCart))) {
$unitPriceTaxExcl = $objRoomTypeServiceProductPrice->getServicePrice(
(int)$product['id_product'],
0,
1,
$objHotelBookingDetail->date_from,
$objHotelBookingDetail->date_to,
false,
$objCart->id
) / $numDays;
$objRoomTypeServiceProductCartDetail = new RoomTypeServiceProductCartDetail();
if ($objRoomTypeServiceProductCartDetail->addServiceProductInCart(
$objServiceProduct->id,
$productQty,
$objCart->id,
$roomHtlCartInfo['id']
)) {
if ($productList = $objCart->getProducts()) {
$totalPriceChangeTaxExcl = 0;
$totalPriceChangeTaxIncl = 0;
$unitPriceTaxIncl = 0;
$unitPriceTaxExcl = 0;
$unitPriceTaxIncl = $objRoomTypeServiceProductPrice->getServicePrice(
(int)$product['id_product'],
0,
1,
$objHotelBookingDetail->date_from,
$objHotelBookingDetail->date_to,
true,
$objCart->id
) / $numDays;
$objRoomTypeServiceProductPrice = new RoomTypeServiceProductPrice();
$cartProductProcessed = 1;
$numDays = 1;
if (Product::getProductPriceCalculation($objServiceProduct->id) == Product::PRICE_CALCULATION_METHOD_PER_DAY) {
$numDays = HotelHelper::getNumberOfDays($objHotelBookingDetail->date_from, $objHotelBookingDetail->date_to);
}
foreach ($productList as &$product) {
// This is used to get the actual quanity of the service as it is calculated incorrectly if the service is per night
if ($idRoomTypeServProductCart = $objRoomTypeServiceProductCartDetail->alreadyExists(
$product['id_product'],
$objCart->id,
$roomHtlCartInfo['id'])
) {
// Lets create a specific price for the service to match the price provided by the user
$objSpecificPrice = new SpecificPrice();
$objSpecificPrice->id_shop = 0;
$objSpecificPrice->id_shop_group = 0;
$objSpecificPrice->id_cart = $objCart->id;
$objSpecificPrice->id_currency = $objOrder->id_currency;
$objSpecificPrice->id_country = 0;
$objSpecificPrice->id_group = 0;
$objSpecificPrice->id_customer = $objOrder->id_customer;
$objSpecificPrice->id_product = $objServiceProduct->id;
$objSpecificPrice->id_product_attribute = 0;
$objSpecificPrice->price = $price;
$objSpecificPrice->from_quantity = 1;
$objSpecificPrice->reduction = 0;
$objSpecificPrice->reduction_type = 'amount';
$objSpecificPrice->reduction_tax = 0;
$objSpecificPrice->from = '0000-00-00 00:00:00';
$objSpecificPrice->to = '0000-00-00 00:00:00';
if ($objSpecificPrice->add()) {
if (Validate::isLoadedObject($objRoomTypeServiceProductCartDetail = new RoomTypeServiceProductCartDetail((int) $idRoomTypeServProductCart))) {
$unitPriceTaxExcl = $objRoomTypeServiceProductPrice->getServicePrice(
(int)$product['id_product'],
0,
1,
$objHotelBookingDetail->date_from,
$objHotelBookingDetail->date_to,
false,
$objCart->id
) / $numDays;
$totalPriceChangeTaxExcl += $totalPriceTaxExcl = Tools::processPriceRounding(
($unitPriceTaxExcl * $numDays),
$objRoomTypeServiceProductCartDetail->quantity,
$objOrder->round_type,
$objOrder->round_mode
);
$totalPriceChangeTaxIncl += $totalPriceTaxIncl = Tools::processPriceRounding(
($unitPriceTaxIncl * $numDays),
$objRoomTypeServiceProductCartDetail->quantity,
$objOrder->round_type,
$objOrder->round_mode
);
$unitPriceTaxIncl = $objRoomTypeServiceProductPrice->getServicePrice(
(int)$product['id_product'],
0,
1,
$objHotelBookingDetail->date_from,
$objHotelBookingDetail->date_to,
true,
$objCart->id
) / $numDays;
$product['total'] = $totalPriceTaxExcl;
$product['total_wt'] = $totalPriceTaxIncl;
$totalPriceChangeTaxExcl += $totalPriceTaxExcl = Tools::processPriceRounding(
($unitPriceTaxExcl * $numDays),
$objRoomTypeServiceProductCartDetail->quantity,
$objOrder->round_type,
$objOrder->round_mode
);
$totalPriceChangeTaxIncl += $totalPriceTaxIncl = Tools::processPriceRounding(
($unitPriceTaxIncl * $numDays),
$objRoomTypeServiceProductCartDetail->quantity,
$objOrder->round_type,
$objOrder->round_mode
);
$cartProductProcessed = 1;
$product['total'] = $totalPriceTaxExcl;
$product['total_wt'] = $totalPriceTaxIncl;
$cartProductProcessed = 1;
} else {
$cartProductProcessed = 0;
break;
}
} else {
$cartProductProcessed = 0;
break;
@@ -7030,108 +7055,107 @@ class AdminOrdersControllerCore extends AdminController
$cartProductProcessed = 0;
break;
}
} else {
$cartProductProcessed = 0;
break;
}
}
// If all cart products processed then only we will proceed further
if ($cartProductProcessed) {
$objOrderInvoice = new OrderInvoice($objOrderDetail->id_order_invoice);
// add in order detail table
$orderDetail = new OrderDetail();
$orderDetail->createList($objOrder, $objCart, $objOrder->getCurrentOrderState(), $productList, (isset($objOrderInvoice) ? $objOrderInvoice->id : 0), true);
// Add in room type service product order detail
$objRoomTypeServiceProductOrderDetail = new RoomTypeServiceProductOrderDetail();
$objRoomTypeServiceProductOrderDetail->id_product = $objServiceProduct->id;
$objRoomTypeServiceProductOrderDetail->id_order = $objHotelBookingDetail->id_order;
$objRoomTypeServiceProductOrderDetail->id_order_detail = $orderDetail->id;
$objRoomTypeServiceProductOrderDetail->id_cart = $objCart->id;
$objRoomTypeServiceProductOrderDetail->id_htl_booking_detail = $objHotelBookingDetail->id;
$objRoomTypeServiceProductOrderDetail->unit_price_tax_excl = $unitPriceTaxExcl;
$objRoomTypeServiceProductOrderDetail->unit_price_tax_incl = $unitPriceTaxIncl;
$objRoomTypeServiceProductOrderDetail->total_price_tax_excl = $totalPriceTaxExcl;
$objRoomTypeServiceProductOrderDetail->total_price_tax_incl = $totalPriceTaxIncl;
$objRoomTypeServiceProductOrderDetail->name = $name;
$objRoomTypeServiceProductOrderDetail->quantity = $productQty;
$objRoomTypeServiceProductOrderDetail->auto_added = $autoAdded;
$objRoomTypeServiceProductOrderDetail->save();
// update totals amount of order
$objOrder->total_products = Tools::ps_round((float)($objOrder->total_products + $totalPriceChangeTaxExcl), _PS_PRICE_COMPUTE_PRECISION_);
$objOrder->total_products_wt = Tools::ps_round((float)($objOrder->total_products_wt + $totalPriceChangeTaxIncl), _PS_PRICE_COMPUTE_PRECISION_);
$objOrder->total_paid = Tools::ps_round($objOrder->getOrderTotal(), _PS_PRICE_COMPUTE_PRECISION_);
$objOrder->total_paid_tax_incl = Tools::ps_round($objOrder->getOrderTotal(), _PS_PRICE_COMPUTE_PRECISION_);
$objOrder->total_paid_tax_excl = Tools::ps_round($objOrder->getOrderTotal(false), _PS_PRICE_COMPUTE_PRECISION_);
// update invoice total
if (isset($objOrderInvoice) && Validate::isLoadedObject($objOrderInvoice)) {
$objOrderInvoice->total_paid_tax_excl += Tools::ps_round((float)$totalPriceChangeTaxExcl, _PS_PRICE_COMPUTE_PRECISION_);
$objOrderInvoice->total_paid_tax_incl += Tools::ps_round((float)$totalPriceChangeTaxIncl, _PS_PRICE_COMPUTE_PRECISION_);
$objOrderInvoice->save();
}
// discounts calculation for order
$objOrder->total_discounts += (float)abs($objCart->getOrderTotal(true, Cart::ONLY_DISCOUNTS));
$objOrder->total_discounts_tax_excl += (float)abs($objCart->getOrderTotal(false, Cart::ONLY_DISCOUNTS));
$objOrder->total_discounts_tax_incl += (float)abs($objCart->getOrderTotal(true, Cart::ONLY_DISCOUNTS));
// If all cart products processed then only we will proceed further
if ($cartProductProcessed) {
$objOrderInvoice = new OrderInvoice($objOrderDetail->id_order_invoice);
// Save changes of order
if ($objOrder->update()) {
$response['service_panel'] = $this->processRenderServicesPanel(
$objOrder->id,
$objHotelBookingDetail->id_product,
$objHotelBookingDetail->date_from,
$objHotelBookingDetail->date_to,
$objHotelBookingDetail->id_room,
$objHotelBookingDetail->id,
true
);
// add in order detail table
$orderDetail = new OrderDetail();
$orderDetail->createList($objOrder, $objCart, $objOrder->getCurrentOrderState(), $productList, (isset($objOrderInvoice) ? $objOrderInvoice->id : 0), true);
// Add in room type service product order detail
$objRoomTypeServiceProductOrderDetail = new RoomTypeServiceProductOrderDetail();
$objRoomTypeServiceProductOrderDetail->id_product = $objServiceProduct->id;
$objRoomTypeServiceProductOrderDetail->id_order = $objHotelBookingDetail->id_order;
$objRoomTypeServiceProductOrderDetail->id_order_detail = $orderDetail->id;
$objRoomTypeServiceProductOrderDetail->id_cart = $objCart->id;
$objRoomTypeServiceProductOrderDetail->id_htl_booking_detail = $objHotelBookingDetail->id;
$objRoomTypeServiceProductOrderDetail->unit_price_tax_excl = $unitPriceTaxExcl;
$objRoomTypeServiceProductOrderDetail->unit_price_tax_incl = $unitPriceTaxIncl;
$objRoomTypeServiceProductOrderDetail->total_price_tax_excl = $totalPriceTaxExcl;
$objRoomTypeServiceProductOrderDetail->total_price_tax_incl = $totalPriceTaxIncl;
$objRoomTypeServiceProductOrderDetail->name = $name;
$objRoomTypeServiceProductOrderDetail->quantity = $productQty;
$objRoomTypeServiceProductOrderDetail->auto_added = $autoAdded;
$objRoomTypeServiceProductOrderDetail->save();
// update totals amount of order
$objOrder->total_products = Tools::ps_round((float)($objOrder->total_products + $totalPriceChangeTaxExcl), _PS_PRICE_COMPUTE_PRECISION_);
$objOrder->total_products_wt = Tools::ps_round((float)($objOrder->total_products_wt + $totalPriceChangeTaxIncl), _PS_PRICE_COMPUTE_PRECISION_);
$objOrder->total_paid = Tools::ps_round($objOrder->getOrderTotal(), _PS_PRICE_COMPUTE_PRECISION_);
$objOrder->total_paid_tax_incl = Tools::ps_round($objOrder->getOrderTotal(), _PS_PRICE_COMPUTE_PRECISION_);
$objOrder->total_paid_tax_excl = Tools::ps_round($objOrder->getOrderTotal(false), _PS_PRICE_COMPUTE_PRECISION_);
// update invoice total
if (isset($objOrderInvoice) && Validate::isLoadedObject($objOrderInvoice)) {
$objOrderInvoice->total_paid_tax_excl += Tools::ps_round((float)$totalPriceChangeTaxExcl, _PS_PRICE_COMPUTE_PRECISION_);
$objOrderInvoice->total_paid_tax_incl += Tools::ps_round((float)$totalPriceChangeTaxIncl, _PS_PRICE_COMPUTE_PRECISION_);
$objOrderInvoice->save();
}
// discounts calculation for order
$objOrder->total_discounts += (float)abs($objCart->getOrderTotal(true, Cart::ONLY_DISCOUNTS));
$objOrder->total_discounts_tax_excl += (float)abs($objCart->getOrderTotal(false, Cart::ONLY_DISCOUNTS));
$objOrder->total_discounts_tax_incl += (float)abs($objCart->getOrderTotal(true, Cart::ONLY_DISCOUNTS));
// Save changes of order
if ($objOrder->update()) {
$response['service_panel'] = $this->processRenderServicesPanel(
$objOrder->id,
$objHotelBookingDetail->id_product,
$objHotelBookingDetail->date_from,
$objHotelBookingDetail->date_to,
$objHotelBookingDetail->id_room,
$objHotelBookingDetail->id,
true
);
} else {
$response['hasError'] = true;
$response['errors'][] = $this->l('Some error occurred while updating the order');
}
// at last delete the specific price created for the service
if (Validate::isLoadedObject($objSpecificPrice)) {
$objSpecificPrice->delete();
unset($objSpecificPrice);
}
} else {
$response['hasError'] = true;
$response['errors'][] = $this->l('Some error occurred while updating the order1');
$response['errors'][] = $this->l('Some error occurred while updating the order');
}
// at last delete the specific price created for the service
if (Validate::isLoadedObject($objSpecificPrice)) {
$objSpecificPrice->delete();
unset($objSpecificPrice);
}
// at last delete the created service
$objServiceProduct->delete();
} else {
$response['hasError'] = true;
$response['errors'][] = $this->l('Some error occurred while updating the order11');
$response['errors'][] = $this->l('Unable to add service to the room');
}
} else {
$response['hasError'] = true;
$response['errors'][] = $this->l('Unable to add service to the room1');
$response['errors'][] = $this->l('Unable to add service to the room');
}
} else {
$response['hasError'] = true;
$response['errors'][] = $this->l('Unable to add service to the room11');
$response['errors'][] = $this->l('Unable to add service to the room');
}
} else {
$response['hasError'] = true;
$response['errors'][] = $this->l('Unable to add service to the room111');
$response['errors'][] = $this->l('Unable to add service to the room');
}
} else {
$response['hasError'] = true;
$response['errors'][] = $this->l('Unable to add service to the room1111');
// at last delete the created service
$objServiceProduct->delete();
}
} else {
$response['hasError'] = true;
$response['errors'][] = $this->l('Unable to add service to the room');
}
} else {
$response['hasError'] = true;
$response['errors'][] = $this->l('Unable to add service to the room11111');
$response['errors'][] = $this->l('Room not found');
}
} else {
$response['hasError'] = true;
$response['errors'][] = $this->l('Room not found');
$response['errors'][] = $this->l('Adding a new custom service is not allowed.');
}
} else {
$response['hasError'] = true;
@@ -7442,28 +7466,23 @@ class AdminOrdersControllerCore extends AdminController
$objRoomTypeServiceProductCartDetail = new RoomTypeServiceProductCartDetail();
if ($operator == 'up') {
$objRoomTypeServiceProduct = new RoomTypeServiceProduct();
if ($objRoomTypeServiceProduct->isRoomTypeLinkedWithProduct($objHotelCartBookingData->id_product, $idServiceProduct)) {
// validate quanitity
if (Validate::isLoadedObject($objProduct = new Product($idServiceProduct))) {
if ($objProduct->allow_multiple_quantity) {
if (!Validate::isUnsignedInt($qty)) {
$this->errors[] = Tools::displayError('The quantity you\'ve entered is invalid.');
// } elseif ($objProduct->max_quantity && $qty > $objProduct->max_quantity) {
// $this->errors[] = Tools::displayError(sprintf('cannot add more than %d quantity.', $objProduct->max_quantity));
}
} else {
$qty = 1;
}
// validate price
if ($price && !ValidateCore::isPrice($price)) {
$this->errors[] = Tools::displayError('Invalid service unit price.');
// validate quanitity
if (Validate::isLoadedObject($objProduct = new Product($idServiceProduct))) {
if ($objProduct->allow_multiple_quantity) {
if (!Validate::isUnsignedInt($qty)) {
$this->errors[] = Tools::displayError('The quantity you\'ve entered is invalid.');
// } elseif ($objProduct->max_quantity && $qty > $objProduct->max_quantity) {
// $this->errors[] = Tools::displayError(sprintf('cannot add more than %d quantity.', $objProduct->max_quantity));
}
} else {
$this->errors[] = Tools::displayError('This Service is not available.');
$qty = 1;
}
// validate price
if ($price && !ValidateCore::isPrice($price)) {
$this->errors[] = Tools::displayError('Invalid service unit price.');
}
} else {
$this->errors[] = Tools::displayError('This Service is not available with selected room.');
$this->errors[] = Tools::displayError('This Service is not available.');
}
}

View File

@@ -230,6 +230,12 @@
<configuration id="PS_ORDER_LIST_PRICE_DISPLAY_CURRENCY" name="PS_ORDER_LIST_PRICE_DISPLAY_CURRENCY">
<value>1</value>
</configuration>
<configuration id="PS_ALLOW_ADD_ALL_SERVICES_IN_BOOKING" name="PS_ALLOW_ADD_ALL_SERVICES_IN_BOOKING">
<value>1</value>
</configuration>
<configuration id="PS_ALLOW_CREATE_CUSTOM_SERVICES_IN_BOOKING" name="PS_ALLOW_CREATE_CUSTOM_SERVICES_IN_BOOKING">
<value>1</value>
</configuration>
<configuration id="TRACKING_DIRECT_TRAFFIC" name="TRACKING_DIRECT_TRAFFIC">
<value>0</value>
</configuration>

View File

@@ -929,7 +929,7 @@ class HotelCartBookingData extends ObjectModel
}
// validate cart data if not available then remove from cart
public static function validateCartBookings()
public static function validateCartBookings($checkServiceRoomLink = true)
{
$context = Context::getContext();
$errors = array();
@@ -965,7 +965,7 @@ class HotelCartBookingData extends ObjectModel
} else {
if (!$product->active) {
$objRoomTypeServiceProductCartDetail->removeServiceProductByIdHtlCartBooking($service['htl_cart_booking_id'], $service['id_product']);
} else {
} elseif ($checkServiceRoomLink) {
if (!$objRoomTypeServiceProduct->isRoomTypeLinkedWithProduct($service['id_product_room_type'], $service['id_product'])) {
$objRoomTypeServiceProductCartDetail->removeServiceProductByIdHtlCartBooking($service['htl_cart_booking_id'], $service['id_product']);
}