Added: Admin can add custom price for facilities and service while editing order
This commit is contained in:
@@ -40,13 +40,16 @@
|
||||
{if isset($extraDemands) && $extraDemands}
|
||||
{foreach $extraDemands as $roomDemand}
|
||||
{foreach $roomDemand['extra_demands'] as $demand}
|
||||
<tr>
|
||||
<tr data-id_booking_demand="{$demand['id_booking_demand']}">
|
||||
<td>{$demand['name']}</td>
|
||||
<td>
|
||||
{displayPrice price=$demand['unit_price_tax_excl'] currency=$orderCurrency}
|
||||
{if $demand['price_calc_method'] == HotelRoomTypeGlobalDemand::WK_PRICE_CALC_METHOD_EACH_DAY}
|
||||
{l s='/ night'}
|
||||
{/if}
|
||||
<div class="input-group">
|
||||
<span class="input-group-addon">{$currencySign}</span>
|
||||
<input type="text" class="form-control unit_price" value="{Tools::ps_round($demand['unit_price_tax_excl'], 2)}">
|
||||
{if $demand['price_calc_method'] == HotelRoomTypeGlobalDemand::WK_PRICE_CALC_METHOD_EACH_DAY}
|
||||
<span class="input-group-addon">{l s='/ night'}</span>
|
||||
{/if}
|
||||
</div>
|
||||
</td>
|
||||
<td>{displayPrice price=$demand['total_price_tax_excl'] currency=$orderCurrency}</td>
|
||||
<td><a class="btn btn-danger pull-right del-order-room-demand" href="#" id_booking_demand="{$demand['id_booking_demand']}"><i class="icon-trash"></i></a></td>
|
||||
@@ -74,7 +77,7 @@
|
||||
<th></th>
|
||||
<th>{l s='Name'}</th>
|
||||
<th>{l s='Option'}</th>
|
||||
<th class="text-right">{l s='Price'}</th>
|
||||
<th class="text-right">{l s='Unit Price'}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -103,12 +106,21 @@
|
||||
{/if}
|
||||
</td>
|
||||
<td class="text-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}
|
||||
|
||||
<div class="input-group">
|
||||
<span class="input-group-addon">{$currencySign}</span>
|
||||
{if isset($selected_adv_option) && isset($demand['adv_option'][$selected_adv_option]['price_tax_excl'])}
|
||||
{assign var=demand_price value=$demand['adv_option'][$selected_adv_option]['price_tax_excl']}
|
||||
{else if isset($demand['adv_option']) && $demand['adv_option']}
|
||||
{assign var=demand_price value=$demand['adv_option'][$demand['adv_option']|@key]['price_tax_excl']}
|
||||
{else}
|
||||
{assign var=demand_price value=$demand['price_tax_excl']}
|
||||
{/if}
|
||||
<input type="text" class="form-control unit_price" value="{Tools::ps_round($demand_price, 2)}" data-id-product="{$product['id_product']}">
|
||||
{if $demand['price_calc_method'] == HotelRoomTypeGlobalDemand::WK_PRICE_CALC_METHOD_EACH_DAY}
|
||||
<span class="input-group-addon">{l s='/ night'}</span>
|
||||
{/if}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
{/foreach}
|
||||
|
||||
@@ -31,8 +31,8 @@
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{l s='Name'}</th>
|
||||
<th></th>
|
||||
<th class="fixed-width-md">{l s='Quantity'}</th>
|
||||
<th class="fixed-width-sm"></th>
|
||||
<th class="fixed-width-sm">{l s='Quantity'}</th>
|
||||
<th>{l s='Unit Price'}</th>
|
||||
<th>{l s='Total Price'}</th>
|
||||
<th class="text-right">{l s='Action'}</th>
|
||||
@@ -41,7 +41,7 @@
|
||||
<tbody>
|
||||
{if isset($additionalServices) && $additionalServices}
|
||||
{foreach $additionalServices['additional_services'] as $service}
|
||||
<tr class="room_demand_block">
|
||||
<tr class="room_demand_block" data-id_room_type_service_product_order_detail="{$service['id_room_type_service_product_order_detail']}">
|
||||
<td>
|
||||
<div>{$service['name']|escape:'html':'UTF-8'}</div>
|
||||
</td>
|
||||
@@ -56,17 +56,23 @@
|
||||
<td>
|
||||
{if $service['allow_multiple_quantity']}
|
||||
<div class="qty_container">
|
||||
<input type="number" class="form-control qty" min="1" data-id_room_type_service_product_order_detail="{$service['id_room_type_service_product_order_detail']}" data-id_product="{$service['id_product']|escape:'html':'UTF-8'}" value="{$service['quantity']|escape:'html':'UTF-8'}">
|
||||
<input type="number" class="form-control qty" min="1" data-id_product="{$service['id_product']|escape:'html':'UTF-8'}" value="{$service['quantity']|escape:'html':'UTF-8'}">
|
||||
</div>
|
||||
{else}
|
||||
--
|
||||
{/if}
|
||||
</td>
|
||||
<td>
|
||||
{displayPrice price=$service['unit_price_tax_excl'] currency=$orderCurrency}
|
||||
{if $service['product_price_calculation_method'] == Product::PRICE_CALCULATION_METHOD_PER_DAY}
|
||||
<div class="input-group">
|
||||
<span class="input-group-addon">{$currencySign}</span>
|
||||
<input type="text" class="form-control unit_price" value="{Tools::ps_round($service['unit_price_tax_excl'], 2)}" data-id-product="{$product['id_product']}">
|
||||
{if Product::PRICE_CALCULATION_METHOD_PER_DAY == $service.product_price_calculation_method}
|
||||
<span class="input-group-addon">{l s='/ night'}</span>
|
||||
{/if}
|
||||
</div>
|
||||
{* {if $service['product_price_calculation_method'] == Product::PRICE_CALCULATION_METHOD_PER_DAY}
|
||||
{l s='/ night'}
|
||||
{/if}
|
||||
{/if} *}
|
||||
</td>
|
||||
<td>{displayPrice price=$service['total_price_tax_excl']|escape:'html':'UTF-8' currency=$orderCurrency}</td>
|
||||
<td><a class="btn btn-danger pull-right del_room_additional_service" data-id_room_type_service_product_order_detail="{$service['id_room_type_service_product_order_detail']}" href="#"><i class="icon-trash"></i></a></td>
|
||||
@@ -90,9 +96,9 @@
|
||||
<tr>
|
||||
<th></th>
|
||||
<th>{l s='Name'}</th>
|
||||
<th></th>
|
||||
<th class="fixed-width-md">{l s='Quantity'}</th>
|
||||
<th class="text-right">{l s='Price'}</th>
|
||||
<th class="fixed-width-sm"> </th>
|
||||
<th class="fixed-width-sm">{l s='Quantity'}</th>
|
||||
<th>{l s='Unit Price'}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -122,10 +128,13 @@
|
||||
{/if}
|
||||
</td>
|
||||
<td class="text-right">
|
||||
{convertPrice price=$product['price_tax_exc']}
|
||||
{if $product['price_calculation_method'] == Product::PRICE_CALCULATION_METHOD_PER_DAY}
|
||||
{l s='/ night'}
|
||||
{/if}
|
||||
<div class="input-group">
|
||||
<span class="input-group-addon">{$currencySign}</span>
|
||||
<input type="text" class="form-control unit_price" name="service_price[{$product['id_product']|escape:'html':'UTF-8'}]" value="{$product['price_tax_exc']}" data-id-product="{$product.id_product}">
|
||||
{if Product::PRICE_CALCULATION_METHOD_PER_DAY == $product['price_calculation_method']}
|
||||
<span class="input-group-addon">{l s='/ night'}</span>
|
||||
{/if}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
{/foreach}
|
||||
|
||||
@@ -1754,11 +1754,11 @@
|
||||
});
|
||||
|
||||
$(document).on('focusout', '#rooms_type_extra_demands .room_ordered_services .qty', function(e) {
|
||||
var qty_wntd = $(this).val();
|
||||
if (qty_wntd == '' || !$.isNumeric(qty_wntd) || qty_wntd < 1) {
|
||||
$(this).val(1);
|
||||
}
|
||||
updateAdditionalServices($(this));
|
||||
updateAdditionalServices($(this).closest('tr'));
|
||||
});
|
||||
|
||||
$(document).on('focusout', '#rooms_type_extra_demands .room_ordered_services .unit_price', function(e) {
|
||||
updateAdditionalServices($(this).closest('tr'));
|
||||
});
|
||||
|
||||
$(document).on('focusout', '#rooms_type_extra_demands #add_room_services_form .qty', function(e) {
|
||||
@@ -1771,7 +1771,17 @@
|
||||
function updateAdditionalServices(element)
|
||||
{
|
||||
var id_room_type_service_product_order_detail = $(element).data('id_room_type_service_product_order_detail');
|
||||
var qty = $(element).val();
|
||||
if ($(element).find('.qty').length) {
|
||||
var qty = $(element).find('.qty').val();
|
||||
if (qty == '' || !$.isNumeric(qty) || qty < 1) {
|
||||
$(element).find('.qty').val(1);
|
||||
qty = 1;
|
||||
}
|
||||
} else {
|
||||
var qty = 1;
|
||||
}
|
||||
|
||||
var unit_price = $(element).find('.unit_price').val();
|
||||
if ($.isNumeric(qty)) {
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
@@ -1784,6 +1794,7 @@
|
||||
data: {
|
||||
id_room_type_service_product_order_detail: id_room_type_service_product_order_detail,
|
||||
qty: qty,
|
||||
unit_price: unit_price,
|
||||
action: 'updateRoomAdditionalServices',
|
||||
ajax: true
|
||||
},
|
||||
@@ -1844,7 +1855,8 @@
|
||||
$(this).closest('#room_extra_demand_content').find('input:checkbox.id_room_type_demand:checked').each(function () {
|
||||
roomDemands.push({
|
||||
'id_global_demand':$(this).val(),
|
||||
'id_option': $(this).closest('.room_demand_block').find('.id_option').val()
|
||||
'id_option': $(this).closest('.room_demand_block').find('.id_option').val(),
|
||||
'unit_price': $(this).closest('.room_demand_block').find('.unit_price').val()
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1860,15 +1872,17 @@
|
||||
data: {
|
||||
id_htl_booking: idHtlBooking,
|
||||
room_demands: JSON.stringify(roomDemands),
|
||||
action: 'EditRoomExtraDemands',
|
||||
action: 'addRoomExtraDemands',
|
||||
ajax: true
|
||||
},
|
||||
success: function(jsonData) {
|
||||
if (jsonData.success) {
|
||||
if (!jsonData.hasError) {
|
||||
showSuccessMessage(txtExtraDemandSucc);
|
||||
if (jsonData.facilities_panel) {
|
||||
$('#room_type_demands_desc').replaceWith(jsonData.facilities_panel);
|
||||
}
|
||||
} else if (jsonData.errors) {
|
||||
showErrorMessage(jsonData.errors);
|
||||
} else {
|
||||
showErrorMessage(txtSomeErr);
|
||||
}
|
||||
@@ -1880,6 +1894,44 @@
|
||||
}
|
||||
});
|
||||
|
||||
{* edit room extra demand*}
|
||||
$(document).on('focusout', '#rooms_type_extra_demands .room_ordered_demands .unit_price', function(e) {
|
||||
updateRoomDemand($(this).closest('tr'));
|
||||
});
|
||||
|
||||
function updateRoomDemand(element)
|
||||
{
|
||||
var id_booking_demand = $(element).data('id_booking_demand');
|
||||
var unit_price = $(element).find('.unit_price').val();
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
headers: {
|
||||
"cache-control": "no-cache"
|
||||
},
|
||||
url: "{$link->getAdminLink('AdminOrders')|addslashes}",
|
||||
dataType: 'JSON',
|
||||
cache: false,
|
||||
data: {
|
||||
id_booking_demand: id_booking_demand,
|
||||
unit_price: unit_price,
|
||||
action: 'updateRoomExtraDemands',
|
||||
ajax: true
|
||||
},
|
||||
success: function(jsonData) {
|
||||
if (!jsonData.hasError) {
|
||||
if (jsonData.facilities_panel) {
|
||||
$('#room_type_demands_desc').replaceWith(jsonData.facilities_panel);
|
||||
}
|
||||
showSuccessMessage(txtExtraDemandSucc);
|
||||
} else {
|
||||
showErrorMessage(jsonData.errors);
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
{* Delete ordered room booking demand *}
|
||||
$(document).on('click', '.del-order-room-demand', function(e) {
|
||||
e.preventDefault();
|
||||
@@ -1960,8 +2012,8 @@
|
||||
var option_selected = $(this).find('option:selected');
|
||||
var extra_demand_price = option_selected.attr("optionPrice")
|
||||
extra_demand_price = parseFloat(extra_demand_price);
|
||||
extra_demand_price = formatCurrency(extra_demand_price, currency_format, currency_sign, currency_blank);
|
||||
$(this).closest('.room_demand_block').find('.extra_demand_option_price').text(extra_demand_price);
|
||||
// extra_demand_price = formatCurrency(extra_demand_price, currency_format, currency_sign, currency_blank);
|
||||
$(this).closest('.room_demand_block').find('.unit_price').val(extra_demand_price);
|
||||
});
|
||||
|
||||
$('#mySwappigModal').on('hidden.bs.modal', function (e)
|
||||
|
||||
@@ -4838,7 +4838,9 @@ class AdminOrdersControllerCore extends AdminController
|
||||
) {
|
||||
$smartyVars = array();
|
||||
$objOrder = new Order($idOrder);
|
||||
$objCurrency = new Currency($objOrder->id_currency);
|
||||
$smartyVars['orderCurrency'] = $objOrder->id_currency;
|
||||
$smartyVars['currencySign'] = $objCurrency->sign;
|
||||
$smartyVars['link'] = $this->context->link;
|
||||
|
||||
$objBookingDemand = new HotelBookingDetail();
|
||||
@@ -4855,7 +4857,7 @@ class AdminOrdersControllerCore extends AdminController
|
||||
$objBookingDemand = new HotelBookingDemands();
|
||||
|
||||
// set context currency So that we can get prices in the order currency
|
||||
$this->context->currency = new Currency($objOrder->id_currency);
|
||||
$this->context->currency = $objCurrency;
|
||||
|
||||
if ($extraDemands = $objBookingDemand->getRoomTypeBookingExtraDemands(
|
||||
$idOrder,
|
||||
@@ -4919,6 +4921,12 @@ class AdminOrdersControllerCore extends AdminController
|
||||
public function processRenderServicesPanel($idOrder, $idProduct, $dateFrom, $dateTo, $idRoom, $orderEdit)
|
||||
{
|
||||
$smartyVars = array();
|
||||
$objOrder = new Order($idOrder);
|
||||
$objCurrency = new Currency($objOrder->id_currency);
|
||||
$smartyVars['orderCurrency'] = $objOrder->id_currency;
|
||||
$smartyVars['currencySign'] = $objCurrency->sign;
|
||||
$smartyVars['link'] = $this->context->link;
|
||||
|
||||
$objBookingDemand = new HotelBookingDetail();
|
||||
$htlBookingDetail = $objBookingDemand->getRowByIdOrderIdProductInDateRange(
|
||||
$idOrder,
|
||||
@@ -4937,9 +4945,8 @@ class AdminOrdersControllerCore extends AdminController
|
||||
}
|
||||
|
||||
if ($orderEdit) {
|
||||
$objOrder = new Order($idOrder);
|
||||
// set context currency So that we can get prices in the order currency
|
||||
$this->context->currency = new Currency($objOrder->id_currency);
|
||||
$this->context->currency = $objCurrency;
|
||||
|
||||
$smartyVars['orderEdit'] = $orderEdit;
|
||||
|
||||
@@ -4967,7 +4974,10 @@ class AdminOrdersControllerCore extends AdminController
|
||||
{
|
||||
$smartyVars = array();
|
||||
$objOrder = new Order($idOrder);
|
||||
$objCurrency = new Currency($objOrder->id_currency);
|
||||
$smartyVars['orderCurrency'] = $objOrder->id_currency;
|
||||
$smartyVars['currencySign'] = $objCurrency->sign;
|
||||
$smartyVars['link'] = $this->context->link;
|
||||
|
||||
$objBookingDemand = new HotelBookingDetail();
|
||||
$htlBookingDetail = $objBookingDemand->getRowByIdOrderIdProductInDateRange(
|
||||
@@ -5024,49 +5034,82 @@ class AdminOrdersControllerCore extends AdminController
|
||||
$response = array('hasError' => false);
|
||||
$id_room_type_service_product_order_detail = Tools::getValue('id_room_type_service_product_order_detail');
|
||||
$quantity = Tools::getValue('qty');
|
||||
$unitPrice = Tools::getValue('unit_price');
|
||||
|
||||
if (Validate::isLoadedObject($objRoomTypeServiceProductOrderDetail = new RoomTypeServiceProductOrderDetail($id_room_type_service_product_order_detail))) {
|
||||
$objOrderDetail = new OrderDetail($objRoomTypeServiceProductOrderDetail->id_order_detail);
|
||||
if ($objOrderDetail->product_allow_multiple_quantity) {
|
||||
if (!Validate::isUnsignedInt($quantity)) {
|
||||
$response['hasError'] = true;
|
||||
$response['errors'] = $this->l('Invalid quantity provided');
|
||||
} else {
|
||||
$objRoomTypeServiceProductOrderDetail->quantity = $quantity;
|
||||
$oldPriceTaxExcl = $objRoomTypeServiceProductOrderDetail->total_price_tax_excl;
|
||||
$oldPriceTaxIncl = $objRoomTypeServiceProductOrderDetail->total_price_tax_incl;
|
||||
$objRoomTypeServiceProductOrderDetail->total_price_tax_excl = $objRoomTypeServiceProductOrderDetail->unit_price_tax_excl * $quantity;
|
||||
$objRoomTypeServiceProductOrderDetail->total_price_tax_incl = $objRoomTypeServiceProductOrderDetail->unit_price_tax_incl * $quantity;
|
||||
$res = true;
|
||||
if ($res &= $objRoomTypeServiceProductOrderDetail->save()) {
|
||||
$order = new Order($objRoomTypeServiceProductOrderDetail->id_order);
|
||||
$priceDiffTaxExcl = $objRoomTypeServiceProductOrderDetail->total_price_tax_excl - $oldPriceTaxExcl;
|
||||
$priceDiffTaxIncl = $objRoomTypeServiceProductOrderDetail->total_price_tax_incl - $oldPriceTaxIncl;
|
||||
|
||||
$objOrderDetail->product_quantity = $quantity;
|
||||
$objOrderDetail->total_price_tax_excl += $priceDiffTaxExcl;
|
||||
$objOrderDetail->total_price_tax_incl += $priceDiffTaxIncl;
|
||||
|
||||
$res &= $objOrderDetail->updateTaxAmount($order);
|
||||
|
||||
$res &= $objOrderDetail->update();
|
||||
|
||||
$order->total_paid_tax_excl += $priceDiffTaxExcl;
|
||||
$order->total_paid_tax_incl += $priceDiffTaxIncl;
|
||||
$order->total_paid += $priceDiffTaxIncl;
|
||||
|
||||
$res &= $order->update();
|
||||
}
|
||||
}
|
||||
if (!$res) {
|
||||
$response['hasError'] = true;
|
||||
$response['errors'] = $this->l('Error while updating service, please try refresing the page');
|
||||
}
|
||||
} else {
|
||||
if (!$objOrderDetail->product_allow_multiple_quantity && $quantity > 1) {
|
||||
$response['hasError'] = true;
|
||||
$response['errors'] = $this->l('cannot order multiple quanitity for this service');
|
||||
} else if (!Validate::isUnsignedInt($quantity)) {
|
||||
$response['hasError'] = true;
|
||||
$response['errors'] = $this->l('Invalid quantity provided');
|
||||
}
|
||||
|
||||
if (!$unitPrice || !ValidateCore::isPrice($unitPrice)) {
|
||||
$response['hasError'] = true;
|
||||
$response['errors'] = $this->l('Invalid unit price');
|
||||
}
|
||||
$objHotelBookingDetail = new HotelBookingDetail($objRoomTypeServiceProductOrderDetail->id_htl_booking_detail);
|
||||
if (!$response['hasError']) {
|
||||
$oldPriceTaxExcl = $objRoomTypeServiceProductOrderDetail->unit_price_tax_excl;
|
||||
$oldPriceTaxIncl = $objRoomTypeServiceProductOrderDetail->unit_price_tax_incl;
|
||||
$oldQuantity = $objRoomTypeServiceProductOrderDetail->quantity;
|
||||
if ($oldPriceTaxExcl) {
|
||||
$oldTaxMultiplier = $oldPriceTaxIncl / $oldPriceTaxExcl;
|
||||
} else {
|
||||
$oldTaxMultiplier = 1;
|
||||
}
|
||||
if ($quantity <= 0) {
|
||||
$quantity = 1;
|
||||
}
|
||||
$objRoomTypeServiceProductOrderDetail->quantity = $quantity;
|
||||
$objRoomTypeServiceProductOrderDetail->unit_price_tax_excl = $unitPrice;
|
||||
$objRoomTypeServiceProductOrderDetail->unit_price_tax_incl = $unitPrice * $oldTaxMultiplier;
|
||||
if ($objOrderDetail->product_price_calculation_method == Product::PRICE_CALCULATION_METHOD_PER_DAY) {
|
||||
$quantity = $quantity * HotelHelper::getNumberOfDays(
|
||||
$objHotelBookingDetail->date_from,
|
||||
$objHotelBookingDetail->date_to
|
||||
);
|
||||
}
|
||||
$objRoomTypeServiceProductOrderDetail->total_price_tax_excl = $objRoomTypeServiceProductOrderDetail->unit_price_tax_excl * $quantity;
|
||||
$objRoomTypeServiceProductOrderDetail->total_price_tax_incl = $objRoomTypeServiceProductOrderDetail->unit_price_tax_incl * $quantity;
|
||||
$res = true;
|
||||
if ($res &= $objRoomTypeServiceProductOrderDetail->save()) {
|
||||
$order = new Order($objRoomTypeServiceProductOrderDetail->id_order);
|
||||
$priceDiffTaxExcl = $objRoomTypeServiceProductOrderDetail->total_price_tax_excl - $oldPriceTaxExcl;
|
||||
$priceDiffTaxIncl = $objRoomTypeServiceProductOrderDetail->total_price_tax_incl - $oldPriceTaxIncl;
|
||||
$quantityDiff = $objRoomTypeServiceProductOrderDetail->quantity - $oldQuantity;
|
||||
|
||||
$objOrderDetail->product_quantity += $quantityDiff;
|
||||
$objOrderDetail->total_price_tax_excl += $priceDiffTaxExcl;
|
||||
$objOrderDetail->total_price_tax_incl += $priceDiffTaxIncl;
|
||||
$objOrderDetail->unit_price_tax_excl = ($objOrderDetail->total_price_tax_excl / $objOrderDetail->product_quantity);
|
||||
$objOrderDetail->unit_price_tax_incl = ($objOrderDetail->total_price_tax_incl / $objOrderDetail->product_quantity);
|
||||
$res &= $objOrderDetail->updateTaxAmount($order);
|
||||
|
||||
$res &= $objOrderDetail->update();
|
||||
|
||||
if ($objOrderDetail->id_order_invoice != 0) {
|
||||
// values changes as values are calculated accoding to the quantity of the product by webkul
|
||||
$order_invoice = new OrderInvoice($objOrderDetail->id_order_invoice);
|
||||
$order_invoice->total_paid_tax_excl += $priceDiffTaxExcl;
|
||||
$order_invoice->total_paid_tax_incl += $priceDiffTaxIncl;
|
||||
$res &= $order_invoice->update();
|
||||
}
|
||||
|
||||
$order->total_paid_tax_excl += $priceDiffTaxExcl;
|
||||
$order->total_paid_tax_incl += $priceDiffTaxIncl;
|
||||
$order->total_paid += $priceDiffTaxIncl;
|
||||
|
||||
$res &= $order->update();
|
||||
}
|
||||
}
|
||||
if (!$res) {
|
||||
$response['hasError'] = true;
|
||||
$response['errors'] = $this->l('Error while updating service, please try refresing the page');
|
||||
}
|
||||
|
||||
$response['service_panel']= $servicesBlock = $this->processRenderServicesPanel(
|
||||
$objOrderDetail->id_order,
|
||||
$objHotelBookingDetail->id_product,
|
||||
@@ -5148,6 +5191,7 @@ class AdminOrdersControllerCore extends AdminController
|
||||
|
||||
$objRoomTypeServiceProduct = new RoomTypeServiceProduct();
|
||||
$qty = Tools::getValue('service_qty');
|
||||
$price = Tools::getValue('service_price');
|
||||
foreach ($selectedServices as $key => $service) {
|
||||
if ($objRoomTypeServiceProduct->isRoomTypeLinkedWithProduct($objHotelBookingDetail->id_product, $service)) {
|
||||
$objProduct = new Product($service, false, $this->context->language->id);
|
||||
@@ -5159,9 +5203,14 @@ class AdminOrdersControllerCore extends AdminController
|
||||
} else {
|
||||
$qty[$service] = 1;
|
||||
}
|
||||
if (!$price[$service] || !ValidateCore::isPrice($price[$service])) {
|
||||
$response['hasError'] = true;
|
||||
$response['errors'][] = sprintf($this->l('Invalid unit price for %s.'), $objProduct->name);
|
||||
}
|
||||
$selectedServices[$key] = array(
|
||||
'id' => $service,
|
||||
'qty' => $qty[$service],
|
||||
'price' => $price[$service],
|
||||
'name' => $objProduct->name,
|
||||
);
|
||||
} else {
|
||||
@@ -5202,6 +5251,37 @@ class AdminOrdersControllerCore extends AdminController
|
||||
$this->context->cart = $cart;
|
||||
$this->context->customer = new Customer($order->id_customer);
|
||||
|
||||
$objRoomTypeServiceProductPrice = new RoomTypeServiceProductPrice();
|
||||
$initialServicePrice = $objRoomTypeServiceProductPrice->getServicePrice(
|
||||
(int)$service['id'],
|
||||
$roomHtlCartInfo['id_product'],
|
||||
1,
|
||||
null,
|
||||
null,
|
||||
false
|
||||
);
|
||||
|
||||
if ($initialServicePrice != $service['price']) {
|
||||
$specific_price = new SpecificPrice();
|
||||
$specific_price->id_shop = 0;
|
||||
$specific_price->id_shop_group = 0;
|
||||
$specific_price->id_cart = $cart->id;
|
||||
$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 = $service['id'];
|
||||
$specific_price->id_product_attribute = 0;
|
||||
$specific_price->price = $service['price'];
|
||||
$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();
|
||||
}
|
||||
|
||||
$objRoomTypeServiceProductCartDetail = new RoomTypeServiceProductCartDetail();
|
||||
$objRoomTypeServiceProductCartDetail->addServiceProductInCart(
|
||||
$service['id'],
|
||||
@@ -5210,7 +5290,6 @@ class AdminOrdersControllerCore extends AdminController
|
||||
$roomHtlCartInfo['id']
|
||||
);
|
||||
$productList = $cart->getProducts();
|
||||
$objRoomTypeServiceProductPrice = new RoomTypeServiceProductPrice();
|
||||
$objHotelRoomType = new HotelRoomType();
|
||||
$roomInfo = $objHotelRoomType->getRoomTypeInfoByIdProduct($objHotelBookingDetail->id_product);
|
||||
$totalPriceChangeTaxExcl = 0;
|
||||
@@ -5222,7 +5301,8 @@ class AdminOrdersControllerCore extends AdminController
|
||||
$product['cart_quantity'],
|
||||
$objHotelBookingDetail->date_from,
|
||||
$objHotelBookingDetail->date_to,
|
||||
false
|
||||
false,
|
||||
$cart->id
|
||||
);
|
||||
$totalPriceChangeTaxIncl += $totalPriceTaxIncl = $objRoomTypeServiceProductPrice->getServicePrice(
|
||||
(int)$product['id_product'],
|
||||
@@ -5230,7 +5310,8 @@ class AdminOrdersControllerCore extends AdminController
|
||||
$product['cart_quantity'],
|
||||
$objHotelBookingDetail->date_from,
|
||||
$objHotelBookingDetail->date_to,
|
||||
true
|
||||
true,
|
||||
$cart->id
|
||||
);
|
||||
$unitPriceTaxExcl = $objRoomTypeServiceProductPrice->getServicePrice(
|
||||
(int)$product['id_product'],
|
||||
@@ -5238,7 +5319,8 @@ class AdminOrdersControllerCore extends AdminController
|
||||
1,
|
||||
$objHotelBookingDetail->date_from,
|
||||
$objHotelBookingDetail->date_to,
|
||||
false
|
||||
false,
|
||||
$cart->id
|
||||
);
|
||||
$unitPriceTaxIncl = $objRoomTypeServiceProductPrice->getServicePrice(
|
||||
(int)$product['id_product'],
|
||||
@@ -5246,7 +5328,8 @@ class AdminOrdersControllerCore extends AdminController
|
||||
1,
|
||||
$objHotelBookingDetail->date_from,
|
||||
$objHotelBookingDetail->date_to,
|
||||
true
|
||||
true,
|
||||
$cart->id
|
||||
);
|
||||
switch (Configuration::get('PS_ROUND_TYPE')) {
|
||||
case Order::ROUND_TOTAL:
|
||||
@@ -5264,8 +5347,6 @@ class AdminOrdersControllerCore extends AdminController
|
||||
$product['total_wt'] = Tools::ps_round($totalPriceTaxIncl, _PS_PRICE_COMPUTE_PRECISION_) * (int)$product['cart_quantity'];
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
$order_detail = new OrderDetail();
|
||||
@@ -5305,9 +5386,13 @@ class AdminOrdersControllerCore extends AdminController
|
||||
$order->total_discounts_tax_incl += (float)abs($cart->getOrderTotal(true, Cart::ONLY_DISCOUNTS));
|
||||
// Save changes of order
|
||||
$order->update();
|
||||
if (Validate::isLoadedObject($specific_price)) {
|
||||
$specific_price->delete();
|
||||
unset($specific_price);
|
||||
}
|
||||
}
|
||||
}
|
||||
$response['service_panel'] = $servicesBlock = $this->processRenderServicesPanel(
|
||||
$response['service_panel'] = $this->processRenderServicesPanel(
|
||||
$order->id,
|
||||
$objHotelBookingDetail->id_product,
|
||||
$objHotelBookingDetail->date_from,
|
||||
@@ -5342,9 +5427,9 @@ class AdminOrdersControllerCore extends AdminController
|
||||
}
|
||||
|
||||
// Process when admin edit rooms and edit rooms additional facilities
|
||||
public function ajaxProcessEditRoomExtraDemands()
|
||||
public function ajaxProcessAddRoomExtraDemands()
|
||||
{
|
||||
$response = array('success' => false);
|
||||
$response = array('success' => false, 'hasError' => false);
|
||||
if ($idHtlBooking = Tools::getValue('id_htl_booking')) {
|
||||
if (Validate::isLoadedObject($objBookingDetail = new HotelBookingDetail($idHtlBooking))) {
|
||||
$roomDemands = Tools::getValue('room_demands');
|
||||
@@ -5359,72 +5444,150 @@ class AdminOrdersControllerCore extends AdminController
|
||||
$objHtlBkDtl = new HotelBookingDetail();
|
||||
$objRoomDemandPrice = new HotelRoomTypeDemandPrice();
|
||||
foreach ($roomDemands as $demand) {
|
||||
$idGlobalDemand = $demand['id_global_demand'];
|
||||
$idOption = $demand['id_option'];
|
||||
$objBookingDemand = new HotelBookingDemands();
|
||||
$objBookingDemand->id_htl_booking = $idHtlBooking;
|
||||
$objGlobalDemand = new HotelRoomTypeGlobalDemand($idGlobalDemand, $idLang);
|
||||
if ($idOption) {
|
||||
$objOption = new HotelRoomTypeGlobalDemandAdvanceOption($idOption, $idLang);
|
||||
$objBookingDemand->name = $objOption->name;
|
||||
} else {
|
||||
$idOption = 0;
|
||||
$objBookingDemand->name = $objGlobalDemand->name;
|
||||
}
|
||||
$objBookingDemand->unit_price_tax_excl = HotelRoomTypeDemand::getPriceStatic(
|
||||
$idProduct,
|
||||
$idGlobalDemand,
|
||||
$idOption,
|
||||
0
|
||||
);
|
||||
$objBookingDemand->unit_price_tax_incl = HotelRoomTypeDemand::getPriceStatic(
|
||||
$idProduct,
|
||||
$idGlobalDemand,
|
||||
$idOption,
|
||||
1
|
||||
);
|
||||
$qty = 1;
|
||||
if ($objGlobalDemand->price_calc_method == HotelRoomTypeGlobalDemand::WK_PRICE_CALC_METHOD_EACH_DAY) {
|
||||
$numDays = $objHtlBkDtl->getNumberOfDays(
|
||||
$objBookingDetail->date_from,
|
||||
$objBookingDetail->date_to
|
||||
);
|
||||
if ($numDays > 1) {
|
||||
$qty *= $numDays;
|
||||
}
|
||||
}
|
||||
$objBookingDemand->total_price_tax_excl = $objBookingDemand->unit_price_tax_excl * $qty;
|
||||
$objBookingDemand->total_price_tax_incl = $objBookingDemand->unit_price_tax_incl * $qty;
|
||||
|
||||
$order_detail = new OrderDetail($objBookingDetail->id_order_detail);
|
||||
// Update OrderInvoice of this OrderDetail
|
||||
if ($order_detail->id_order_invoice != 0) {
|
||||
// values changes as values are calculated accoding to the quantity of the product by webkul
|
||||
$order_invoice = new OrderInvoice($order_detail->id_order_invoice);
|
||||
$order_invoice->total_paid_tax_excl += $objBookingDemand->total_price_tax_excl;
|
||||
$order_invoice->total_paid_tax_incl += $objBookingDemand->total_price_tax_incl;
|
||||
$res &= $order_invoice->update();
|
||||
}
|
||||
|
||||
// change order total
|
||||
$order->total_paid_tax_excl += $objBookingDemand->total_price_tax_excl;
|
||||
$order->total_paid_tax_incl += $objBookingDemand->total_price_tax_incl;
|
||||
$order->total_paid += $objBookingDemand->total_price_tax_incl;
|
||||
|
||||
$objBookingDemand->price_calc_method = $objGlobalDemand->price_calc_method;
|
||||
$objBookingDemand->id_tax_rules_group = $objGlobalDemand->id_tax_rules_group;
|
||||
$taxManager = TaxManagerFactory::getManager(
|
||||
$vatAddress,
|
||||
$objGlobalDemand->id_tax_rules_group
|
||||
);
|
||||
$taxCalc = $taxManager->getTaxCalculator();
|
||||
$objBookingDemand->tax_computation_method = (int)$taxCalc->computation_method;
|
||||
if ($objBookingDemand->save()) {
|
||||
$objBookingDemand->tax_calculator = $taxCalc;
|
||||
// Now save tax details of the extra demand
|
||||
$objBookingDemand->setBookingDemandTaxDetails();
|
||||
if (!$demand['unit_price'] || !ValidateCore::isPrice($demand['unit_price'])) {
|
||||
$objGlobalDemand = new HotelRoomTypeGlobalDemand($demand['id_global_demand'], $idLang);
|
||||
$response['hasError'] = true;
|
||||
$response['errors'][] = sprintf($this->l('Invalid unit price for %s.'), $objGlobalDemand->name);
|
||||
}
|
||||
}
|
||||
if (!$response['hasError']) {
|
||||
foreach ($roomDemands as $demand) {
|
||||
$idGlobalDemand = $demand['id_global_demand'];
|
||||
$idOption = $demand['id_option'];
|
||||
$objBookingDemand = new HotelBookingDemands();
|
||||
$objBookingDemand->id_htl_booking = $idHtlBooking;
|
||||
$objGlobalDemand = new HotelRoomTypeGlobalDemand($idGlobalDemand, $idLang);
|
||||
if ($idOption) {
|
||||
$objOption = new HotelRoomTypeGlobalDemandAdvanceOption($idOption, $idLang);
|
||||
$objBookingDemand->name = $objOption->name;
|
||||
} else {
|
||||
$idOption = 0;
|
||||
$objBookingDemand->name = $objGlobalDemand->name;
|
||||
}
|
||||
$objBookingDemand->unit_price_tax_excl = $demand['unit_price'];
|
||||
$objBookingDemand->unit_price_tax_incl = HotelRoomTypeDemand::getPriceStatic(
|
||||
$idProduct,
|
||||
$idGlobalDemand,
|
||||
$idOption,
|
||||
1,
|
||||
6,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
$demand['unit_price']
|
||||
);
|
||||
$qty = 1;
|
||||
if ($objGlobalDemand->price_calc_method == HotelRoomTypeGlobalDemand::WK_PRICE_CALC_METHOD_EACH_DAY) {
|
||||
$numDays = $objHtlBkDtl->getNumberOfDays(
|
||||
$objBookingDetail->date_from,
|
||||
$objBookingDetail->date_to
|
||||
);
|
||||
if ($numDays > 1) {
|
||||
$qty *= $numDays;
|
||||
}
|
||||
}
|
||||
$objBookingDemand->total_price_tax_excl = $objBookingDemand->unit_price_tax_excl * $qty;
|
||||
$objBookingDemand->total_price_tax_incl = $objBookingDemand->unit_price_tax_incl * $qty;
|
||||
|
||||
$order_detail = new OrderDetail($objBookingDetail->id_order_detail);
|
||||
// Update OrderInvoice of this OrderDetail
|
||||
if ($order_detail->id_order_invoice != 0) {
|
||||
// values changes as values are calculated accoding to the quantity of the product by webkul
|
||||
$order_invoice = new OrderInvoice($order_detail->id_order_invoice);
|
||||
$order_invoice->total_paid_tax_excl += $objBookingDemand->total_price_tax_excl;
|
||||
$order_invoice->total_paid_tax_incl += $objBookingDemand->total_price_tax_incl;
|
||||
$res &= $order_invoice->update();
|
||||
}
|
||||
|
||||
// change order total
|
||||
$order->total_paid_tax_excl += $objBookingDemand->total_price_tax_excl;
|
||||
$order->total_paid_tax_incl += $objBookingDemand->total_price_tax_incl;
|
||||
$order->total_paid += $objBookingDemand->total_price_tax_incl;
|
||||
|
||||
$objBookingDemand->price_calc_method = $objGlobalDemand->price_calc_method;
|
||||
$objBookingDemand->id_tax_rules_group = $objGlobalDemand->id_tax_rules_group;
|
||||
$taxManager = TaxManagerFactory::getManager(
|
||||
$vatAddress,
|
||||
$objGlobalDemand->id_tax_rules_group
|
||||
);
|
||||
$taxCalc = $taxManager->getTaxCalculator();
|
||||
$objBookingDemand->tax_computation_method = (int)$taxCalc->computation_method;
|
||||
if ($objBookingDemand->save()) {
|
||||
$objBookingDemand->tax_calculator = $taxCalc;
|
||||
// Now save tax details of the extra demand
|
||||
$objBookingDemand->setBookingDemandTaxDetails();
|
||||
}
|
||||
}
|
||||
if ($order->save()) {
|
||||
$response['facilities_panel'] = $this->processRenderFacilitiesBlock(
|
||||
$order->id,
|
||||
$objBookingDetail->id_product,
|
||||
$objBookingDetail->date_from,
|
||||
$objBookingDetail->date_to,
|
||||
$objBookingDetail->id_room,
|
||||
true
|
||||
);
|
||||
$response['success'] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
die(json_encode($response));
|
||||
}
|
||||
|
||||
public function ajaxProcessUpdateRoomExtraDemands()
|
||||
{
|
||||
$response = array('success' => false);
|
||||
if ($idBookingDemand = Tools::getValue('id_booking_demand')) {
|
||||
if (Validate::isLoadedObject($objBookingDemand = new HotelBookingDemands($idBookingDemand))) {
|
||||
$unitPrice = Tools::getValue('unit_price');
|
||||
if (!$unitPrice || !ValidateCore::isPrice($unitPrice)) {
|
||||
$response['hasError'] = true;
|
||||
$response['errors'] = $this->l('Invalid unit price');
|
||||
}
|
||||
$oldPriceTaxExcl = $objBookingDemand->unit_price_tax_excl;
|
||||
$oldPriceTaxIncl = $objBookingDemand->unit_price_tax_incl;
|
||||
if ($oldPriceTaxExcl) {
|
||||
$oldTaxMultiplier = $oldPriceTaxIncl / $oldPriceTaxExcl;
|
||||
} else {
|
||||
$oldTaxMultiplier = 1;
|
||||
}
|
||||
$objBookingDemand->unit_price_tax_excl = $unitPrice;
|
||||
$objBookingDemand->unit_price_tax_incl = $unitPrice * $oldTaxMultiplier;
|
||||
$objBookingDetail = new HotelBookingDetail($objBookingDemand->id_htl_booking);
|
||||
if ($objBookingDemand->price_calc_method == HotelRoomTypeGlobalDemand::WK_PRICE_CALC_METHOD_EACH_DAY) {
|
||||
$numDays = $objBookingDetail->getNumberOfDays(
|
||||
$objBookingDetail->date_from,
|
||||
$objBookingDetail->date_to
|
||||
);
|
||||
$objBookingDemand->total_price_tax_excl = $objBookingDemand->unit_price_tax_excl * $numDays;
|
||||
$objBookingDemand->total_price_tax_incl = $objBookingDemand->unit_price_tax_incl * $numDays;
|
||||
} else {
|
||||
$objBookingDemand->total_price_tax_excl = $objBookingDemand->unit_price_tax_excl;
|
||||
$objBookingDemand->total_price_tax_incl = $objBookingDemand->unit_price_tax_incl;
|
||||
}
|
||||
if ($objBookingDemand->save()) {
|
||||
$objBookingDemand->setBookingDemandTaxDetails(1);
|
||||
|
||||
$priceDiffTaxExcl = $objBookingDemand->total_price_tax_excl - $oldPriceTaxExcl;
|
||||
$priceDiffTaxIncl = $objBookingDemand->total_price_tax_incl - $oldPriceTaxIncl;
|
||||
|
||||
|
||||
$order_detail = new OrderDetail($objBookingDetail->id_order_detail);
|
||||
// Update OrderInvoice of this OrderDetail
|
||||
if ($order_detail->id_order_invoice != 0) {
|
||||
// values changes as values are calculated accoding to the quantity of the product by webkul
|
||||
$order_invoice = new OrderInvoice($order_detail->id_order_invoice);
|
||||
$order_invoice->total_paid_tax_excl += $priceDiffTaxExcl;
|
||||
$order_invoice->total_paid_tax_incl += $priceDiffTaxIncl;
|
||||
$res &= $order_invoice->update();
|
||||
}
|
||||
$order = new Order($objBookingDetail->id_order);
|
||||
$order->total_paid_tax_excl += $priceDiffTaxExcl;
|
||||
$order->total_paid_tax_incl += $priceDiffTaxIncl;
|
||||
$order->total_paid += $priceDiffTaxIncl;
|
||||
if ($order->save()) {
|
||||
$response['facilities_panel'] = $this->processRenderFacilitiesBlock(
|
||||
$order->id,
|
||||
|
||||
@@ -205,7 +205,8 @@ class HotelRoomTypeDemand extends ObjectModel
|
||||
$idCustomer = null,
|
||||
$idCart = null,
|
||||
$id_address = null,
|
||||
Context $context = null
|
||||
Context $context = null,
|
||||
$customPrice = null
|
||||
) {
|
||||
if (!$context) {
|
||||
$context = Context::getContext();
|
||||
@@ -266,7 +267,8 @@ class HotelRoomTypeDemand extends ObjectModel
|
||||
$useTax,
|
||||
$decimals,
|
||||
$idCustomer,
|
||||
$idCart
|
||||
$idCart,
|
||||
$customPrice
|
||||
);
|
||||
}
|
||||
|
||||
@@ -282,7 +284,8 @@ class HotelRoomTypeDemand extends ObjectModel
|
||||
$useTax,
|
||||
$decimals,
|
||||
$idCustomer = 0,
|
||||
$idCart = 0
|
||||
$idCart = 0,
|
||||
$customPrice = null
|
||||
) {
|
||||
static $address = null;
|
||||
static $context = null;
|
||||
@@ -310,24 +313,28 @@ class HotelRoomTypeDemand extends ObjectModel
|
||||
|
||||
// here get the price of global demand
|
||||
$objRoomDmdPrice = new HotelRoomTypeDemandPrice();
|
||||
if ($idOption) {
|
||||
$objOption = new HotelRoomTypeGlobalDemandAdvanceOption($idOption);
|
||||
$price = $objRoomDmdPrice->getRoomTypeDemandPrice(
|
||||
$idProduct,
|
||||
$idGlobalDemand,
|
||||
$idOption
|
||||
);
|
||||
if (!Validate::isPrice($price)) {
|
||||
$price = $objOption->price;
|
||||
}
|
||||
if (!is_null($customPrice)) {
|
||||
$price = $customPrice;
|
||||
} else {
|
||||
$objGlobalDemand = new HotelRoomTypeGlobalDemand($idGlobalDemand);
|
||||
$price = $objRoomDmdPrice->getRoomTypeDemandPrice(
|
||||
$idProduct,
|
||||
$idGlobalDemand
|
||||
);
|
||||
if (!Validate::isPrice($price)) {
|
||||
$price = $objGlobalDemand->price;
|
||||
if ($idOption) {
|
||||
$objOption = new HotelRoomTypeGlobalDemandAdvanceOption($idOption);
|
||||
$price = $objRoomDmdPrice->getRoomTypeDemandPrice(
|
||||
$idProduct,
|
||||
$idGlobalDemand,
|
||||
$idOption
|
||||
);
|
||||
if (!Validate::isPrice($price)) {
|
||||
$price = $objOption->price;
|
||||
}
|
||||
} else {
|
||||
$objGlobalDemand = new HotelRoomTypeGlobalDemand($idGlobalDemand);
|
||||
$price = $objRoomDmdPrice->getRoomTypeDemandPrice(
|
||||
$idProduct,
|
||||
$idGlobalDemand
|
||||
);
|
||||
if (!Validate::isPrice($price)) {
|
||||
$price = $objGlobalDemand->price;
|
||||
}
|
||||
}
|
||||
}
|
||||
$price = Tools::convertPrice($price, $idCurrency);
|
||||
|
||||
Reference in New Issue
Block a user