[Fixed]: Order invoice does not get updated

This commit is contained in:
Aman deep sharma
2025-01-16 20:31:43 +05:30
parent 950b37ed1c
commit 3a291feb13
2 changed files with 115 additions and 101 deletions

View File

@@ -127,6 +127,15 @@
</div>
</div>
</div>
<div class="product_invoice" style="display: none;">
<select name="product_invoice" class="edit_product_invoice">
{foreach from=$invoices_collection item=invoice}
<option value="{$invoice->id}" {if $invoice->id == $data.id_order_invoice}selected="selected"{/if}>
#{Configuration::get('PS_INVOICE_PREFIX', $current_id_lang, null, $order->id_shop)}{'%06d'|sprintf:$invoice->number}
</option>
{/foreach}
</select>
</div>
</div>
<div class="modal-footer">
<button type="button" id="submitRoomChange" class="btn btn-primary"><i class="icon icon-bed"></i> &nbsp;{l s="Update Rooms"}</button>

View File

@@ -894,89 +894,92 @@ class AdminOrdersControllerCore extends AdminController
&& ($productLineData = Tools::getValue('product_line_data'))
) {
$productLineData = json_decode($productLineData, true);
$smartyVars = array(
'order' => $objOrder,
'data' => $productLineData,
'currency' => new Currency($objOrder->id_currency),
'max_child_age' => Configuration::get('WK_GLOBAL_CHILD_MAX_AGE'),
'orderEdit' => 1,
);
$objCurrency = new Currency($objOrder->id_currency);
$smartyVars['orderCurrency'] = $objOrder->id_currency;
$smartyVars['currencySign'] = $objCurrency->sign;
$smartyVars['link'] = $this->context->link;
$smartyVars['id_booking_detail'] = $productLineData['id'];
$objBookingDemand = new HotelBookingDemands();
// set context currency So that we can get prices in the order currency
$this->context->currency = $objCurrency;
if ($extraDemands = $objBookingDemand->getRoomTypeBookingExtraDemands(
$idOrder,
0,
0,
0,
0,
1,
0,
1,
$productLineData['id']
)) {
$smartyVars['extraDemands'] = $extraDemands;
}
// get room type additional demands
$objRoomDemands = new HotelRoomTypeDemand();
if ($roomTypeDemands = $objRoomDemands->getRoomTypeDemands($idProduct)) {
foreach ($roomTypeDemands as &$demand) {
// if demand has advance options then set demand price as first advance option price.
if (isset($demand['adv_option']) && $demand['adv_option']) {
$demand['price'] = current($demand['adv_option'])['price'];
}
if (Validate::isLoadedObject($objOrderDetail = new OrderDetail($productLineData['id_order_detail']))) {
$productLineData['id_order_invoice'] = $objOrderDetail->id_order_invoice;
$smartyVars = array(
'order' => $objOrder,
'data' => $productLineData,
'currency' => new Currency($objOrder->id_currency),
'max_child_age' => Configuration::get('WK_GLOBAL_CHILD_MAX_AGE'),
'orderEdit' => 1,
);
$objCurrency = new Currency($objOrder->id_currency);
$smartyVars['orderCurrency'] = $objOrder->id_currency;
$smartyVars['currencySign'] = $objCurrency->sign;
$smartyVars['link'] = $this->context->link;
$smartyVars['id_booking_detail'] = $productLineData['id'];
$objBookingDemand = new HotelBookingDemands();
// set context currency So that we can get prices in the order currency
$this->context->currency = $objCurrency;
if ($extraDemands = $objBookingDemand->getRoomTypeBookingExtraDemands(
$idOrder,
0,
0,
0,
0,
1,
0,
1,
$productLineData['id']
)) {
$smartyVars['extraDemands'] = $extraDemands;
}
$smartyVars['roomTypeDemands'] = $roomTypeDemands;
}
$objRoomTypeServiceProductOrderDetail = new RoomTypeServiceProductOrderDetail();
if ($additionalServices = $objRoomTypeServiceProductOrderDetail->getSelectedServicesForRoom(
$productLineData['id']
)) {
$smartyVars['additionalServices'] = $additionalServices;
}
// get room type additional demands
$objRoomTypeServiceProduct = new RoomTypeServiceProduct();
if ($roomTypeServiceProducts = $objRoomTypeServiceProduct->getServiceProductsData($idProduct, 1, 0, false, 2, null)) {
if ($additionalServices) {
foreach ($roomTypeServiceProducts as $key => $product) {
if (in_array($product['id_product'], array_column($additionalServices['additional_services'], 'id_product'))) {
unset($roomTypeServiceProducts[$key]);
// get room type additional demands
$objRoomDemands = new HotelRoomTypeDemand();
if ($roomTypeDemands = $objRoomDemands->getRoomTypeDemands($idProduct)) {
foreach ($roomTypeDemands as &$demand) {
// if demand has advance options then set demand price as first advance option price.
if (isset($demand['adv_option']) && $demand['adv_option']) {
$demand['price'] = current($demand['adv_option'])['price'];
}
}
$smartyVars['roomTypeDemands'] = $roomTypeDemands;
}
$smartyVars['roomTypeServiceProducts'] = $roomTypeServiceProducts;
$objRoomTypeServiceProductOrderDetail = new RoomTypeServiceProductOrderDetail();
if ($additionalServices = $objRoomTypeServiceProductOrderDetail->getSelectedServicesForRoom(
$productLineData['id']
)) {
$smartyVars['additionalServices'] = $additionalServices;
}
// get room type additional demands
$objRoomTypeServiceProduct = new RoomTypeServiceProduct();
if ($roomTypeServiceProducts = $objRoomTypeServiceProduct->getServiceProductsData($idProduct, 1, 0, false, 2, null)) {
if ($additionalServices) {
foreach ($roomTypeServiceProducts as $key => $product) {
if (in_array($product['id_product'], array_column($additionalServices['additional_services'], 'id_product'))) {
unset($roomTypeServiceProducts[$key]);
}
}
}
$smartyVars['roomTypeServiceProducts'] = $roomTypeServiceProducts;
}
$objOrderReturn = new OrderReturn();
$refundReqBookings = $objOrderReturn->getOrderRefundRequestedBookings($objOrder->id, 0, 1);
$smartyVars['refundReqBookings'] = $refundReqBookings;
$smartyVars['invoices_collection'] = $objOrder->getInvoicesCollection();
$this->context->smarty->assign($smartyVars);
$modal = array(
'modal_id' => 'edit-room-booking-modal',
'modal_class' => 'modal-lg order_detail_modal',
'modal_title' => '<i class="icon icon-bed"></i> &nbsp'.$this->l('Edit Room'),
'modal_content' => $this->context->smarty->fetch('controllers/orders/modals/_edit_room_booking.tpl'),
);
$this->context->smarty->assign($modal);
$response['hasError'] = 0;
$response['modalHtml'] = $this->context->smarty->fetch('modal.tpl');
}
$objOrderReturn = new OrderReturn();
$refundReqBookings = $objOrderReturn->getOrderRefundRequestedBookings($objOrder->id, 0, 1);
$smartyVars['refundReqBookings'] = $refundReqBookings;
$this->context->smarty->assign($smartyVars);
$modal = array(
'modal_id' => 'edit-room-booking-modal',
'modal_class' => 'modal-lg order_detail_modal',
'modal_title' => '<i class="icon icon-bed"></i> &nbsp'.$this->l('Edit Room'),
'modal_content' => $this->context->smarty->fetch('controllers/orders/modals/_edit_room_booking.tpl'),
);
$this->context->smarty->assign($modal);
$response['hasError'] = 0;
$response['modalHtml'] = $this->context->smarty->fetch('modal.tpl');
}
die(Tools::jsonEncode($response));
@@ -4873,8 +4876,6 @@ class AdminOrdersControllerCore extends AdminController
if (isset($order_invoice)) {
// Apply changes on OrderInvoice
$order_invoice->total_products += (float)$diff_price_tax_excl;
$order_invoice->total_products_wt += (float)$diff_price_tax_incl;
$order_invoice->total_paid_tax_excl += (float)$diff_price_tax_excl;
$order_invoice->total_paid_tax_incl += (float)$diff_price_tax_incl;
}
@@ -4886,10 +4887,6 @@ class AdminOrdersControllerCore extends AdminController
$order->total_products_wt += (float)$diff_price_tax_incl;
$order->total_products_wt = $order->total_products_wt > 0 ? $order->total_products_wt : 0;
$order->total_paid = Tools::ps_round($order->getOrderTotal(), _PS_PRICE_COMPUTE_PRECISION_);
$order->total_paid_tax_incl = Tools::ps_round($order->getOrderTotal(), _PS_PRICE_COMPUTE_PRECISION_);
$order->total_paid_tax_excl = Tools::ps_round($order->getOrderTotal(false), _PS_PRICE_COMPUTE_PRECISION_);
$res &= $order->update();
}
@@ -4914,10 +4911,6 @@ class AdminOrdersControllerCore extends AdminController
}
}
// Save order invoice
if (isset($order_invoice)) {
$res &= $order_invoice->update();
}
if ($qty_diff != 0) {
$cartQty = $qty_diff;
@@ -5043,7 +5036,6 @@ class AdminOrdersControllerCore extends AdminController
)) {
// update extra demands total prices if dates are changes (price calc method for each day)
if ($extraDemands) {
$order = new Order($id_order);
foreach ($extraDemands as $demand) {
if (isset($demand['extra_demands']) && $demand['extra_demands']) {
foreach ($demand['extra_demands'] as $rDemand) {
@@ -5068,23 +5060,23 @@ class AdminOrdersControllerCore extends AdminController
$objBookingDemand->total_price_tax_incl = $demandPriceTI;
$objBookingDemand->save();
$order_invoice->total_paid_tax_excl -= $rDemand['total_price_tax_excl'];
$order_invoice->total_paid_tax_incl -= $rDemand['total_price_tax_incl'];
$order_invoice->total_paid_tax_excl += (float)$objBookingDemand->total_price_tax_excl;
$order_invoice->total_paid_tax_incl += (float)$objBookingDemand->total_price_tax_incl;
}
}
}
}
// change order total save
$order->total_paid = Tools::ps_round($order->getOrderTotal(), _PS_PRICE_COMPUTE_PRECISION_);
$order->total_paid_tax_incl = Tools::ps_round($order->getOrderTotal(), _PS_PRICE_COMPUTE_PRECISION_);
$order->total_paid_tax_excl = Tools::ps_round($order->getOrderTotal(false), _PS_PRICE_COMPUTE_PRECISION_);
$order->save();
}
if (isset($orderServiceProducts)
&& is_array($orderServiceProducts)
&& count($orderServiceProducts)
) {
$order = new Order((int) $id_order);
foreach ($orderServiceProducts as $orderServiceProduct) {
if (isset($orderServiceProduct['additional_services'])
&& is_array($orderServiceProduct['additional_services'])
@@ -5130,6 +5122,12 @@ class AdminOrdersControllerCore extends AdminController
$objOrderDetail->product_quantity += ($newProductQuantity - $oldProductQuantity);
$objOrderDetail->save();
$order_invoice->total_paid_tax_excl -= $objRoomTypeServiceProductOrderDetail->total_price_tax_excl;
$order_invoice->total_paid_tax_incl -= $objRoomTypeServiceProductOrderDetail->total_price_tax_incl;
$order_invoice->total_paid_tax_excl += (float)$newTotalPriceTaxExcl;
$order_invoice->total_paid_tax_incl += (float)$newTotalPriceTaxIncl;
$objRoomTypeServiceProductOrderDetail->unit_price_tax_excl = $unitPriceTaxExcl;
$objRoomTypeServiceProductOrderDetail->unit_price_tax_incl = $unitPriceTaxIncl;
$objRoomTypeServiceProductOrderDetail->total_price_tax_excl = $newTotalPriceTaxExcl;
@@ -5139,14 +5137,21 @@ class AdminOrdersControllerCore extends AdminController
}
}
}
$order->total_paid = Tools::ps_round($order->getOrderTotal(), _PS_PRICE_COMPUTE_PRECISION_);
$order->total_paid_tax_incl = Tools::ps_round($order->getOrderTotal(), _PS_PRICE_COMPUTE_PRECISION_);
$order->total_paid_tax_excl = Tools::ps_round($order->getOrderTotal(false), _PS_PRICE_COMPUTE_PRECISION_);
$order->save();
}
}
$order->total_paid = Tools::ps_round($order->getOrderTotal(), _PS_PRICE_COMPUTE_PRECISION_);
$order->total_paid_tax_incl = Tools::ps_round($order->getOrderTotal(), _PS_PRICE_COMPUTE_PRECISION_);
$order->total_paid_tax_excl = Tools::ps_round($order->getOrderTotal(false), _PS_PRICE_COMPUTE_PRECISION_);
$order->save();
// Save order invoice
if (isset($order_invoice)) {
$order_invoice->total_products = $order_invoice->total_paid_tax_excl;
$order_invoice->total_products_wt = $order_invoice->total_paid_tax_incl;
$res &= $order_invoice->update();
}
if (is_array(Tools::getValue('product_quantity'))) {
$view = $this->createTemplate('_customized_data.tpl')->fetch();
} else {
@@ -7264,4 +7269,4 @@ class AdminOrdersControllerCore extends AdminController
$this->ajaxDie(json_encode($result));
}
}
}