Skip to content

Commit

Permalink
Merge pull request Qloapps#1172 from vishal-singh-webkul/gli-2232
Browse files Browse the repository at this point in the history
Fixed: Errors occurring while updating the order from back office.
  • Loading branch information
rohit053 authored Aug 22, 2024
2 parents a00b4af + a72fea5 commit 65c06ea
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 49 deletions.
2 changes: 2 additions & 0 deletions classes/order/OrderHistory.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@ public function changeIdOrderState($new_order_state, $id_order, $use_existing_pa
// if order is created by API then create a direct object instead of creating an object from module
if ($order->module == 'wsorder') {
$payment_method = new WebserviceOrder();
} else if ($order->module == 'bo_order') {
$payment_method = new BoOrder();
} else {
$payment_method = Module::getInstanceByName($order->module);
}
Expand Down
2 changes: 2 additions & 0 deletions classes/pdf/HTMLTemplateInvoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ public function getContent()
0,
1,
0,
0,
$type_value['id_order_detail']
);
$cart_htl_data[$type_key]['date_diff'][$date_join]['extra_demands_price_ti'] = $objBookingDemand->getRoomTypeBookingExtraDemands(
Expand All @@ -408,6 +409,7 @@ public function getContent()
0,
1,
1,
0,
$type_value['id_order_detail']
);
$cart_htl_data[$type_key]['date_diff'][$date_join]['additional_services'] = $objRoomTypeServiceProductOrderDetail->getroomTypeServiceProducts(
Expand Down
83 changes: 45 additions & 38 deletions controllers/admin/AdminOrdersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4656,8 +4656,6 @@ public function ajaxProcessEditRoomOnOrder()
$res = true;
$id_order = (int) Tools::getValue('id_order');
$order = new Order($id_order);
$cart = new Cart($order->id_cart);
$customer = new Cart($order->id_customer);
//$order_detail = new OrderDetail((int)Tools::getValue('product_id_order_detail'));
$order_detail = new OrderDetail((int) Tools::getValue('id_order_detail'));//by webkul id_order_detail from our table
$this->doEditRoomValidation($order_detail, $order, isset($order_invoice) ? $order_invoice : null);
Expand All @@ -4666,6 +4664,9 @@ public function ajaxProcessEditRoomOnOrder()
$order_invoice = new OrderInvoice((int) Tools::getValue('product_invoice'));
}
/*By webkul To edit Order and cart entries when edit rooms from the orderLine when editing the order*/
$obj_booking_detail = new HotelBookingDetail((int) Tools::getValue('id_booking_detail'));
$cart = new Cart($obj_booking_detail->id_cart);

$product_informations = $_POST['edit_product'];
$new_date_from = trim(date('Y-m-d', strtotime($product_informations['date_from'])));
$new_date_to = trim(date('Y-m-d', strtotime($product_informations['date_to'])));
Expand All @@ -4675,7 +4676,6 @@ public function ajaxProcessEditRoomOnOrder()
$id_room = trim(Tools::getValue('id_room'));
$id_product = trim(Tools::getValue('id_product'));
$room_unit_price = trim(Tools::getValue('room_unit_price'));
$obj_booking_detail = new HotelBookingDetail();
$product_quantity = (int) $obj_booking_detail->getNumberOfDays($new_date_from, $new_date_to);
$old_product_quantity = (int) $obj_booking_detail->getNumberOfDays($old_date_from, $old_date_to);
$qty_diff = $product_quantity - $old_product_quantity;
Expand Down Expand Up @@ -4857,6 +4857,17 @@ public function ajaxProcessEditRoomOnOrder()
$res &= $order_invoice->update();
}

if ($qty_diff != 0) {
$cartQty = $qty_diff;
$op = 'up';
if ($qty_diff < 0) {
$op = 'down';
$cartQty = -$cartQty;
}

$cart->updateQty($cartQty, $obj_booking_detail->id_product, null, false, $op, 0, null, true);
}

// Update product available quantity
StockAvailable::updateQuantity($order_detail->product_id, $order_detail->product_attribute_id, ($old_quantity - $order_detail->product_quantity), $order->id_shop);

Expand Down Expand Up @@ -4926,15 +4937,22 @@ public function ajaxProcessEditRoomOnOrder()
$id_room,
0,
null,
null
null,
null,
0,
$obj_booking_detail->id
);

$extraDemands = $objBookingDemand->getRoomTypeBookingExtraDemands(
$id_order,
0,
$id_room,
$old_date_from,
$old_date_to
$old_date_to,
1,
0,
1,
$obj_booking_detail->id
);

// set occupancy details
Expand All @@ -4950,15 +4968,16 @@ public function ajaxProcessEditRoomOnOrder()
'tax_incl' => $totalRoomPriceAfterTI,
);

if ($update_htl_tables = $obj_booking_detail->UpdateHotelCartHotelOrderOnOrderEdit(
if ($obj_booking_detail->updateHotelCartHotelOrderOnOrderEdit(
$id_order,
$id_room,
$old_date_from,
$old_date_to,
$new_date_from,
$new_date_to,
$occupancy,
$new_total_price
$new_total_price,
$obj_booking_detail->id
)) {
// update extra demands total prices if dates are changes (price calc method for each day)
if ($extraDemands) {
Expand Down Expand Up @@ -5495,6 +5514,10 @@ public function ajaxProcessDeleteRoomLine()
// delete refund request of the room if exists.
OrderReturnDetail::deleteReturnDetailByIdBookingDetail($id_order, $idHotelBooking);

// Reducing the quantity from the cart after removing the room from the order
$objCart = new Cart($objBookingDetail->id_cart);
$objCart->updateQty($product_quantity, $objBookingDetail->id_product, null, false, 'down', 0, null, true);

// Assign to smarty informations in order to show the new product line
$this->context->smarty->assign(array(
'order' => $order,
Expand Down Expand Up @@ -6238,7 +6261,7 @@ public function ajaxProcessUpdateRoomAdditionalServices()
$oldTotalPriceTaxExcl = $objRoomTypeServiceProductOrderDetail->total_price_tax_excl;
$oldTotalPriceTaxIncl = $objRoomTypeServiceProductOrderDetail->total_price_tax_incl;
$oldQuantity = $objRoomTypeServiceProductOrderDetail->quantity;
if ($oldPriceTaxExcl > 0) {
if ($oldUnitPriceTaxExcl > 0) {
$oldTaxMultiplier = $oldUnitPriceTaxIncl / $oldUnitPriceTaxExcl;
} else {
$oldTaxMultiplier = 1;
Expand Down Expand Up @@ -6424,10 +6447,10 @@ public function ajaxProcessAddRoomAdditionalServices()
);

// add services in room
$order = new Order($objHotelBookingDetail->id_order);
if (!$response['hasError']) {
$this->context->currency = new Currency($order->id_currency);
foreach ($selectedServices as $service) {
$order = new Order($objHotelBookingDetail->id_order);

// Create new cart
$cart = new Cart();
$cart->id_shop_group = $order->id_shop_group;
Expand Down Expand Up @@ -6499,49 +6522,33 @@ public function ajaxProcessAddRoomAdditionalServices()
$roomHtlCartInfo['id'])
) {
$objRoomTypeServiceProductCartDetail = new RoomTypeServiceProductCartDetail((int) $id_room_type_service_product_cart_detail);
$totalPriceChangeTaxExcl += $totalPriceTaxExcl = $objRoomTypeServiceProductPrice->getServicePrice(
(int)$product['id_product'],
0,
$objRoomTypeServiceProductCartDetail->quantity,
$objHotelBookingDetail->date_from,
$objHotelBookingDetail->date_to,
false,
$cart->id
);
$totalPriceChangeTaxIncl += $totalPriceTaxIncl = $objRoomTypeServiceProductPrice->getServicePrice(
(int)$product['id_product'],
0,
$objRoomTypeServiceProductCartDetail->quantity,
$objHotelBookingDetail->date_from,
$objHotelBookingDetail->date_to,
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);
}
$product['cart_quantity'] = $objRoomTypeServiceProductCartDetail->quantity * $numDays;

$product['cart_quantity'] = $objRoomTypeServiceProductCartDetail->quantity * $numDays;
$unitPriceTaxExcl = $objRoomTypeServiceProductPrice->getServicePrice(
(int)$product['id_product'],
0,
$roomHtlCartInfo['id_product'],
1,
$objHotelBookingDetail->date_from,
$objHotelBookingDetail->date_to,
null,
null,
false,
$cart->id
)/ $numDays;
);
$unitPriceTaxIncl = $objRoomTypeServiceProductPrice->getServicePrice(
(int)$product['id_product'],
0,
$roomHtlCartInfo['id_product'],
1,
$objHotelBookingDetail->date_from,
$objHotelBookingDetail->date_to,
null,
null,
true,
$cart->id
)/ $numDays;
);

$totalPriceChangeTaxExcl += $totalPriceTaxExcl = ($unitPriceTaxExcl * $product['cart_quantity']);
$totalPriceChangeTaxIncl += $totalPriceTaxIncl = ($unitPriceTaxIncl * $product['cart_quantity']);
switch (Configuration::get('PS_ROUND_TYPE')) {
case Order::ROUND_TOTAL:
$product['total'] = $totalPriceTaxExcl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ public function getRoomTypeBookingExtraDemands(
$groupByRoom = 1,
$getTotalPrice = 0,
$useTax = 1,
$idOrderDetail = 0,
$idHtlBookingDetail = 0
$idHtlBookingDetail = 0,
$idOrderDetail = 0
) {
$moduleObj = Module::getInstanceByName('hotelreservationsystem');
$context = Context::getContext();
Expand Down
9 changes: 4 additions & 5 deletions modules/hotelreservationsystem/classes/HotelBookingDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -2369,19 +2369,18 @@ public function getRoomBookinInformationForDateRangeByOrder(
return Db::getInstance()->executeS($sql);
}

public function UpdateHotelCartHotelOrderOnOrderEdit(
public function updateHotelCartHotelOrderOnOrderEdit(
$idOrder,
$idRoom,
$oldDateFrom,
$oldDateTo,
$newDateFrom,
$newDateTo,
$occupancy,
$newTotalPrice = null
$newTotalPrice = null,
$idHotelBookingDetail
) {
// retrieve HotelBookingDetail row
$roomBookingData = $this->getRoomBookingData($idRoom, $idOrder, $oldDateFrom, $oldDateTo);
$objHotelBookingDetail = new self($roomBookingData['id']);
$objHotelBookingDetail = new self((int) $idHotelBookingDetail);
if (Validate::isLoadedObject($objHotelBookingDetail)) {
// retrieve HotelCartBookingData row
$idHotelCartBookingData = Db::getInstance()->getValue(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,10 @@ public static function priceCalculation(
$price = $objGlobalDemand->price;
}
}

$price = Tools::convertPrice($price, $idCurrency);
}
$price = Tools::convertPrice($price, $idCurrency);

// Tax calculation section
$address->id_country = $idCountry;
$address->id_state = $idState;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ public function getroomTypeServiceProducts(
$useTax = null,
$autoAddToCart = 0,
$priceAdditionType = null,
$idOrderDetail = 0
$idOrderDetail = 0,
$idHtlBookingDetail = 0
) {

if ($useTax === null) {
$useTax = Product::$_taxCalculationMethod == PS_TAX_EXC ? false : true;
}
Expand Down Expand Up @@ -111,6 +111,9 @@ public function getroomTypeServiceProducts(
if ($idRoom) {
$sql .= ' AND hbd.`id_room`='.(int) $idRoom;
}
if ($idHtlBookingDetail) {
$sql .= ' AND hbd.`id` = '.(int)$idHtlBookingDetail;
}
$sql .= ' ORDER BY hbd.`id`';

if ($getTotalPrice) {
Expand Down
2 changes: 1 addition & 1 deletion pdf/invoice.extra-demands-tab.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
{$service['name']}
</td>
<td class="center">
{if $service['product_tax_label']}{$service['product_tax_label']}{else}{l s='No tax' pdf='true'}{/if}
{if isset($service['product_tax_label']) && $service['product_tax_label']}{$service['product_tax_label']}{else}{l s='No tax' pdf='true'}{/if}
</td>
<td class="center">
{if $service['allow_multiple_quantity']}
Expand Down

0 comments on commit 65c06ea

Please sign in to comment.