Merge pull request #941 from shreesh-webkul/gli-1753
Added: Admin can add custom price for facilities and services while editing order
This commit is contained in:
@@ -5357,7 +5357,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();
|
||||
@@ -5374,7 +5376,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,
|
||||
@@ -5438,6 +5440,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,
|
||||
@@ -5456,9 +5464,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;
|
||||
|
||||
@@ -5486,7 +5493,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(
|
||||
@@ -5543,61 +5553,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))) {
|
||||
if (Validate::isLoadedObject($objHotelBookingDetail = new HotelBookingDetail((int) $objRoomTypeServiceProductOrderDetail->id_htl_booking_detail))) {
|
||||
$numDays = 1;
|
||||
if (Product::getProductPriceCalculation($objRoomTypeServiceProductOrderDetail->id_product) == Product::PRICE_CALCULATION_METHOD_PER_DAY) {
|
||||
$numDays = HotelHelper::getNumberOfDays($objHotelBookingDetail->date_from, $objHotelBookingDetail->date_to);
|
||||
}
|
||||
|
||||
$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 {
|
||||
$oldQuantity = $objRoomTypeServiceProductOrderDetail->quantity;
|
||||
$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 * $numDays;
|
||||
$objRoomTypeServiceProductOrderDetail->total_price_tax_incl = $objRoomTypeServiceProductOrderDetail->unit_price_tax_incl * $quantity * $numDays;
|
||||
$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 - $oldQuantity) * $numDays);
|
||||
$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 {
|
||||
$response['hasError'] = true;
|
||||
$response['errors'] = $this->l('cannot order multiple quanitity for this service');
|
||||
}
|
||||
} else {
|
||||
$objOrderDetail = new OrderDetail($objRoomTypeServiceProductOrderDetail->id_order_detail);
|
||||
if (!$objOrderDetail->product_allow_multiple_quantity && $quantity > 1) {
|
||||
$response['hasError'] = true;
|
||||
$response['errors'] = $this->l('Additional service not found');
|
||||
$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 (!ValidateCore::isPrice($unitPrice)) {
|
||||
$response['hasError'] = true;
|
||||
$response['errors'] = $this->l('Invalid unit price');
|
||||
}
|
||||
$objHotelBookingDetail = new HotelBookingDetail($objRoomTypeServiceProductOrderDetail->id_htl_booking_detail);
|
||||
$res = true;
|
||||
if (!$response['hasError']) {
|
||||
$oldPriceTaxExcl = $objRoomTypeServiceProductOrderDetail->unit_price_tax_excl;
|
||||
$oldPriceTaxIncl = $objRoomTypeServiceProductOrderDetail->unit_price_tax_incl;
|
||||
$oldQuantity = $objRoomTypeServiceProductOrderDetail->quantity;
|
||||
if ($oldPriceTaxExcl > 0) {
|
||||
$oldTaxMultiplier = $oldPriceTaxIncl / $oldPriceTaxExcl;
|
||||
} else {
|
||||
$oldTaxMultiplier = 1;
|
||||
}
|
||||
if ($quantity <= 0) {
|
||||
$quantity = 1;
|
||||
}
|
||||
$objRoomTypeServiceProductOrderDetail->quantity = $quantity;
|
||||
$objRoomTypeServiceProductOrderDetail->unit_price_tax_excl = Tools::ps_round($unitPrice, 6);
|
||||
$objRoomTypeServiceProductOrderDetail->unit_price_tax_incl = Tools::ps_round($unitPrice * $oldTaxMultiplier, 6);
|
||||
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 = Tools::ps_round($objRoomTypeServiceProductOrderDetail->unit_price_tax_excl * $quantity, 6);
|
||||
$objRoomTypeServiceProductOrderDetail->total_price_tax_incl = Tools::ps_round($objRoomTypeServiceProductOrderDetail->unit_price_tax_incl * $quantity, 6);
|
||||
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,
|
||||
@@ -5679,6 +5710,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);
|
||||
@@ -5690,9 +5722,14 @@ class AdminOrdersControllerCore extends AdminController
|
||||
} else {
|
||||
$qty[$service] = 1;
|
||||
}
|
||||
if (!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 {
|
||||
@@ -5733,6 +5770,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 = $order->id_currency;
|
||||
$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'],
|
||||
@@ -5741,7 +5809,6 @@ class AdminOrdersControllerCore extends AdminController
|
||||
$roomHtlCartInfo['id']
|
||||
);
|
||||
$productList = $cart->getProducts();
|
||||
$objRoomTypeServiceProductPrice = new RoomTypeServiceProductPrice();
|
||||
$objHotelRoomType = new HotelRoomType();
|
||||
$roomInfo = $objHotelRoomType->getRoomTypeInfoByIdProduct($objHotelBookingDetail->id_product);
|
||||
$totalPriceChangeTaxExcl = 0;
|
||||
@@ -5758,20 +5825,23 @@ class AdminOrdersControllerCore extends AdminController
|
||||
$objRoomTypeServiceProductCartDetail = new RoomTypeServiceProductCartDetail((int) $id_room_type_service_product_cart_detail);
|
||||
$totalPriceChangeTaxExcl += $totalPriceTaxExcl = $objRoomTypeServiceProductPrice->getServicePrice(
|
||||
(int)$product['id_product'],
|
||||
$roomInfo['id'],
|
||||
0,
|
||||
$objRoomTypeServiceProductCartDetail->quantity,
|
||||
$objHotelBookingDetail->date_from,
|
||||
$objHotelBookingDetail->date_to,
|
||||
false
|
||||
false,
|
||||
$cart->id
|
||||
);
|
||||
$totalPriceChangeTaxIncl += $totalPriceTaxIncl = $objRoomTypeServiceProductPrice->getServicePrice(
|
||||
(int)$product['id_product'],
|
||||
$roomInfo['id'],
|
||||
0,
|
||||
$objRoomTypeServiceProductCartDetail->quantity,
|
||||
$objHotelBookingDetail->date_from,
|
||||
$objHotelBookingDetail->date_to,
|
||||
true
|
||||
true,
|
||||
$cart->id
|
||||
);
|
||||
|
||||
$numDays = 1;
|
||||
if (Product::getProductPriceCalculation($product['id_product']) == Product::PRICE_CALCULATION_METHOD_PER_DAY) {
|
||||
$numDays = HotelHelper::getNumberOfDays($objHotelBookingDetail->date_from, $objHotelBookingDetail->date_to);
|
||||
@@ -5780,19 +5850,21 @@ class AdminOrdersControllerCore extends AdminController
|
||||
|
||||
$unitPriceTaxExcl = $objRoomTypeServiceProductPrice->getServicePrice(
|
||||
(int)$product['id_product'],
|
||||
$roomInfo['id'],
|
||||
0,
|
||||
1,
|
||||
$objHotelBookingDetail->date_from,
|
||||
$objHotelBookingDetail->date_to,
|
||||
false
|
||||
false,
|
||||
$cart->id
|
||||
)/ $numDays;
|
||||
$unitPriceTaxIncl = $objRoomTypeServiceProductPrice->getServicePrice(
|
||||
(int)$product['id_product'],
|
||||
$roomInfo['id'],
|
||||
0,
|
||||
1,
|
||||
$objHotelBookingDetail->date_from,
|
||||
$objHotelBookingDetail->date_to,
|
||||
true
|
||||
true,
|
||||
$cart->id
|
||||
)/ $numDays;
|
||||
switch (Configuration::get('PS_ROUND_TYPE')) {
|
||||
case Order::ROUND_TOTAL:
|
||||
@@ -5850,9 +5922,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,
|
||||
@@ -5887,9 +5963,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');
|
||||
@@ -5904,72 +5980,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 (!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 > 0) {
|
||||
$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,
|
||||
|
||||
Reference in New Issue
Block a user