Added: Admin can add custom price for facilities and service while editing order
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user