Merge pull request #1767 from shazar-webkul/gli-2242
Fixed: Decimal precision mismatch causing pricing inconsistencies
This commit is contained in:
@@ -754,9 +754,8 @@ class CartCore extends ObjectModel
|
||||
$totalPriceByProductTaxExcl += $roomTotalPrice['total_price_tax_excl'];
|
||||
}
|
||||
|
||||
// Rounding as per configurations
|
||||
$row['total'] = Tools::processPriceRounding($totalPriceByProductTaxExcl);
|
||||
$row['total_wt'] = Tools::processPriceRounding($totalPriceByProductTaxIncl);
|
||||
$row['total'] = $totalPriceByProductTaxExcl;
|
||||
$row['total_wt'] = $totalPriceByProductTaxIncl;
|
||||
}
|
||||
} else {
|
||||
$row['total'] = 0;
|
||||
@@ -1768,10 +1767,11 @@ class CartCore extends ObjectModel
|
||||
} else {
|
||||
$priceAdd = $servicePorduct['unit_price_tax_excl'];
|
||||
}
|
||||
$lineTotal = Tools::processPriceRounding($priceAdd, (int)$servicePorduct['quantity']);
|
||||
if ($ps_round_type == Order::ROUND_TOTAL) {
|
||||
$products_total[$id_tax_rules_group.'_'.$id_address] += $priceAdd * (int)$servicePorduct['quantity'];
|
||||
$products_total[$id_tax_rules_group.'_'.$id_address] += $lineTotal;
|
||||
} else {
|
||||
$products_total[$id_tax_rules_group] += $priceAdd * (int)$servicePorduct['quantity'];
|
||||
$products_total[$id_tax_rules_group] += $lineTotal;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -229,12 +229,12 @@ abstract class PaymentModuleCore extends Module
|
||||
$this->currentOrderReference = $reference;
|
||||
|
||||
$order_creation_failed = false;
|
||||
$cart_total_paid = (float)Tools::ps_round((float)$this->context->cart->getOrderTotal(true, Cart::BOTH), 2);
|
||||
$cart_total_paid = (float)Tools::ps_round((float)$this->context->cart->getOrderTotal(true, Cart::BOTH), _PS_PRICE_COMPUTE_PRECISION_);
|
||||
|
||||
if ($this->context->cart->is_advance_payment) {
|
||||
$cart_total_paid = (float)Tools::ps_round(
|
||||
(float)$this->context->cart->getOrderTotal(true, CART::ADVANCE_PAYMENT),
|
||||
2
|
||||
_PS_PRICE_COMPUTE_PRECISION_
|
||||
);
|
||||
}
|
||||
|
||||
@@ -314,7 +314,7 @@ abstract class PaymentModuleCore extends Module
|
||||
$order->gift_message = $this->context->cart->gift_message;
|
||||
$order->mobile_theme = $this->context->cart->mobile_theme;
|
||||
$order->conversion_rate = $this->context->currency->conversion_rate;
|
||||
$amount_paid = !$dont_touch_amount ? Tools::ps_round((float)$amount_paid, 2) : $amount_paid;
|
||||
$amount_paid = !$dont_touch_amount ? Tools::ps_round((float)$amount_paid, _PS_PRICE_COMPUTE_PRECISION_) : $amount_paid;
|
||||
$order->total_paid_real = 0;
|
||||
|
||||
$order->total_products = (float)$this->context->cart->getOrderTotal(false, Cart::ONLY_PRODUCTS, $order->product_list, $id_carrier);
|
||||
@@ -389,7 +389,7 @@ abstract class PaymentModuleCore extends Module
|
||||
(float)$this->context->cart->getOrderTotal(true, Cart::BOTH, $order->product_list, $id_carrier),
|
||||
_PS_PRICE_COMPUTE_PRECISION_
|
||||
);
|
||||
if ($orderTotal = $this->context->cart->getOrderTotal(true, Cart::BOTH, null, $id_carrier)) {
|
||||
if ($orderTotal = Tools::ps_round((float)$this->context->cart->getOrderTotal(true, Cart::BOTH, null, $id_carrier), _PS_PRICE_COMPUTE_PRECISION_)) {
|
||||
$order->amount_paid = (float)Tools::ps_round(
|
||||
(($order->advance_paid_amount * $amount_paid) / $orderTotal),
|
||||
_PS_PRICE_COMPUTE_PRECISION_
|
||||
@@ -850,7 +850,8 @@ abstract class PaymentModuleCore extends Module
|
||||
$objCartBookingData->id_cart,
|
||||
$objCartBookingData->id_guest,
|
||||
$objCartBookingData->id_room,
|
||||
0
|
||||
0,
|
||||
1
|
||||
);
|
||||
|
||||
$objBookingDetail->date_from = $objCartBookingData->date_from;
|
||||
@@ -941,8 +942,8 @@ abstract class PaymentModuleCore extends Module
|
||||
);
|
||||
}
|
||||
|
||||
$objBookingDemand->total_price_tax_excl = Tools::processPriceRounding(($objBookingDemand->unit_price_tax_excl * $numDays));
|
||||
$objBookingDemand->total_price_tax_incl = Tools::processPriceRounding(($objBookingDemand->unit_price_tax_incl * $numDays));
|
||||
$objBookingDemand->total_price_tax_excl = $objBookingDemand->unit_price_tax_excl * $numDays;
|
||||
$objBookingDemand->total_price_tax_incl = $objBookingDemand->unit_price_tax_incl * $numDays;
|
||||
|
||||
$objBookingDemand->price_calc_method = $objGlobalDemand->price_calc_method;
|
||||
$objBookingDemand->id_tax_rules_group = $objGlobalDemand->id_tax_rules_group;
|
||||
|
||||
@@ -2677,7 +2677,7 @@ class OrderCore extends ObjectModel
|
||||
'unit_tax_base' => $autoAddedPriceExcl / $totalAutoAddedQty,
|
||||
'total_tax_base' => $autoAddedPriceExcl,
|
||||
'unit_amount' => $amount,
|
||||
'total_amount' => Tools::processPriceRounding($amount, $totalAutoAddedQty),
|
||||
'total_amount' => Tools::processPriceRounding($amount, $totalAutoAddedQty, $this->round_type, $this->round_mode),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
@@ -2724,7 +2724,7 @@ class OrderCore extends ObjectModel
|
||||
|
||||
foreach ($tax_calculator->getTaxesAmount($unit_price_tax_excl) as $id_tax => $unit_amount) {
|
||||
$total_tax_base = 0;
|
||||
$total_amount = Tools::processPriceRounding($unit_amount, $quantity);
|
||||
$total_amount = Tools::processPriceRounding($unit_amount, $quantity, $this->round_type, $this->round_mode);
|
||||
|
||||
if (!isset($groupedTaxDetails[$id_tax])) {
|
||||
$groupedTaxDetails[$id_tax] = array(
|
||||
|
||||
@@ -5172,8 +5172,8 @@ class AdminOrdersControllerCore extends AdminController
|
||||
$carrier = new Carrier((int)$order->id_carrier);
|
||||
$tax_calculator = $carrier->getTaxCalculator($invoice_address);
|
||||
|
||||
$order_invoice->total_paid_tax_excl = Tools::ps_round((float)$cart->getOrderTotal(false, $total_method), 2);
|
||||
$order_invoice->total_paid_tax_incl = Tools::ps_round((float)$cart->getOrderTotal($use_taxes, $total_method), 2);
|
||||
$order_invoice->total_paid_tax_excl = Tools::ps_round((float)$cart->getOrderTotal(false, $total_method), _PS_PRICE_COMPUTE_PRECISION_);
|
||||
$order_invoice->total_paid_tax_incl = Tools::ps_round((float)$cart->getOrderTotal($use_taxes, $total_method), _PS_PRICE_COMPUTE_PRECISION_);
|
||||
$order_invoice->total_products = (float)$cart->getOrderTotal(false, Cart::ONLY_PRODUCTS);
|
||||
$order_invoice->total_products_wt = (float)$cart->getOrderTotal($use_taxes, Cart::ONLY_PRODUCTS);
|
||||
$order_invoice->total_shipping_tax_excl = (float)$cart->getTotalShippingCost(null, false);
|
||||
@@ -5410,7 +5410,8 @@ class AdminOrdersControllerCore extends AdminController
|
||||
$this->context->cart->id,
|
||||
$this->context->cookie->id_guest,
|
||||
$objCartBookingData->id_room,
|
||||
0
|
||||
0,
|
||||
1
|
||||
);
|
||||
$objBookingDetail->total_price_tax_excl = $total_price['total_price_tax_excl'];
|
||||
$objBookingDetail->total_price_tax_incl = $total_price['total_price_tax_incl'];
|
||||
@@ -5730,8 +5731,8 @@ class AdminOrdersControllerCore extends AdminController
|
||||
$invoice_address = new Address((int) $objOrder->{Configuration::get('PS_TAX_ADDRESS_TYPE', null, null, $objOrder->id_shop)});
|
||||
$carrier = new Carrier((int)$objOrder->id_carrier);
|
||||
$tax_calculator = $carrier->getTaxCalculator($invoice_address);
|
||||
$objOrderInvoice->total_paid_tax_excl = Tools::ps_round((float)$objCart->getOrderTotal(false, $totalMethod), 2);
|
||||
$objOrderInvoice->total_paid_tax_incl = Tools::ps_round((float)$objCart->getOrderTotal($useTaxes, $totalMethod), 2);
|
||||
$objOrderInvoice->total_paid_tax_excl = Tools::ps_round((float)$objCart->getOrderTotal(false, $totalMethod), _PS_PRICE_COMPUTE_PRECISION_);
|
||||
$objOrderInvoice->total_paid_tax_incl = Tools::ps_round((float)$objCart->getOrderTotal($useTaxes, $totalMethod), _PS_PRICE_COMPUTE_PRECISION_);
|
||||
$objOrderInvoice->total_products = (float)$objCart->getOrderTotal(false, Cart::ONLY_PRODUCTS);
|
||||
$objOrderInvoice->total_products_wt = (float)$objCart->getOrderTotal($useTaxes, Cart::ONLY_PRODUCTS);
|
||||
$objOrderInvoice->total_shipping_tax_excl = (float)$objCart->getTotalShippingCost(null, false);
|
||||
@@ -5988,7 +5989,8 @@ class AdminOrdersControllerCore extends AdminController
|
||||
$cart->id,
|
||||
$cart->id_guest,
|
||||
$id_room,
|
||||
0
|
||||
0,
|
||||
1
|
||||
);
|
||||
|
||||
$totalRoomPriceAfterTE = (float) $roomTotalPrice['total_price_tax_excl'];
|
||||
@@ -8530,7 +8532,7 @@ class AdminOrdersControllerCore extends AdminController
|
||||
$objBookingDetail->date_to
|
||||
);
|
||||
}
|
||||
$objBookingDemand->total_price_tax_excl = $totalPriceTaxIncl = Tools::processPriceRounding(
|
||||
$objBookingDemand->total_price_tax_excl = $totalPriceTaxExcl = Tools::processPriceRounding(
|
||||
($objBookingDemand->unit_price_tax_excl * $numDays),
|
||||
1,
|
||||
$order->round_type,
|
||||
@@ -8630,7 +8632,7 @@ class AdminOrdersControllerCore extends AdminController
|
||||
$order->round_type,
|
||||
$order->round_mode
|
||||
);
|
||||
$objBookingDemand->total_price_tax_excl = Tools::processPriceRounding(
|
||||
$objBookingDemand->total_price_tax_incl = Tools::processPriceRounding(
|
||||
($objBookingDemand->unit_price_tax_incl * $numDays),
|
||||
1,
|
||||
$order->round_type,
|
||||
@@ -8936,7 +8938,8 @@ class AdminOrdersControllerCore extends AdminController
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
0,
|
||||
1
|
||||
);
|
||||
if ($objHotelBooking->total_price_tax_excl != $newRoomTotalPrice['total_price_tax_excl']) {
|
||||
$result['has_price_changes'] = 1;
|
||||
|
||||
@@ -1496,7 +1496,7 @@ CREATE TABLE `PREFIX_order_payment` (
|
||||
`id_order_payment` INT NOT NULL auto_increment,
|
||||
`order_reference` VARCHAR(9),
|
||||
`id_currency` INT UNSIGNED NOT NULL,
|
||||
`amount` DECIMAL(10,2) NOT NULL,
|
||||
`amount` DECIMAL(20,6) NOT NULL,
|
||||
`payment_method` varchar(255) NOT NULL,
|
||||
`payment_type` INT UNSIGNED NOT NULL,
|
||||
`conversion_rate` decimal(13,6) NOT NULL DEFAULT 1,
|
||||
@@ -1514,7 +1514,7 @@ CREATE TABLE `PREFIX_order_payment_detail` (
|
||||
`id_order_payment_detail` INT(10) unsigned NOT NULL auto_increment,
|
||||
`id_order_payment` INT(10) unsigned NOT NULL,
|
||||
`id_order` INT(10) unsigned NOT NULL,
|
||||
`amount` DECIMAL(10,2) NOT NULL,
|
||||
`amount` DECIMAL(20,6) NOT NULL,
|
||||
`receipt_number` INT(10) NOT NULL,
|
||||
`date_add` DATETIME NOT NULL,
|
||||
PRIMARY KEY (`id_order_payment_detail`)
|
||||
|
||||
@@ -126,9 +126,9 @@ class HotelBookingDemands extends ObjectModel
|
||||
if ($getTotalPrice) {
|
||||
foreach ($roomTypeDemands as $demand) {
|
||||
if ($useTax) {
|
||||
$totalDemandsPrice += Tools::processPriceRounding($demand['total_price_tax_incl']);
|
||||
$totalDemandsPrice += (float)$demand['total_price_tax_incl'];
|
||||
} else {
|
||||
$totalDemandsPrice += Tools::processPriceRounding($demand['total_price_tax_excl']);
|
||||
$totalDemandsPrice += (float)$demand['total_price_tax_excl'];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -203,15 +203,16 @@ class HotelBookingDemands extends ObjectModel
|
||||
}
|
||||
$values = '';
|
||||
$priceTaxExcl = $this->unit_price_tax_excl;
|
||||
$objBkDetail = new HotelBookingDetail($this->id_htl_booking);
|
||||
$objOrder = new Order($objBkDetail->id_order);
|
||||
foreach ($taxCalculator->getTaxesAmount($priceTaxExcl) as $idTax => $amount) {
|
||||
$quantity = 1;
|
||||
if ($this->price_calc_method == HotelRoomTypeGlobalDemand::WK_PRICE_CALC_METHOD_EACH_DAY) {
|
||||
$objBkDetail = new HotelBookingDetail($this->id_htl_booking);
|
||||
$quantity = HotelHelper::getNumberOfDays($objBkDetail->date_from, $objBkDetail->date_to);
|
||||
}
|
||||
|
||||
// Rounding as per configurations
|
||||
$totalAmount = Tools::processPriceRounding($amount, $quantity);
|
||||
// Rounding as per configurations — use order's stored round settings
|
||||
$totalAmount = Tools::processPriceRounding($amount, $quantity, $objOrder->round_type, $objOrder->round_mode);
|
||||
|
||||
$values .= '('.(int)$this->id.','.(int)$idTax.','.(float)$amount.','.
|
||||
(float)$totalAmount.'),';
|
||||
|
||||
@@ -2096,7 +2096,8 @@ class HotelBookingDetail extends ObjectModel
|
||||
$context->cart->id,
|
||||
$context->cookie->id_guest,
|
||||
$objCartBookingData->id_room,
|
||||
0
|
||||
0,
|
||||
1
|
||||
);
|
||||
$objBookingDetail->total_price_tax_excl = $totalRoomTypePrice['total_price_tax_excl'];
|
||||
$objBookingDetail->total_price_tax_incl = $totalRoomTypePrice['total_price_tax_incl'];
|
||||
|
||||
@@ -90,17 +90,14 @@ class HotelRoomTypeDemandPrice extends ObjectModel
|
||||
$useTax
|
||||
);
|
||||
}
|
||||
$numDays = 1;
|
||||
if ($objGlobalDemand->price_calc_method == HotelRoomTypeGlobalDemand::WK_PRICE_CALC_METHOD_EACH_DAY) {
|
||||
if ($dateFrom && $dateTo) {
|
||||
$numDays = HotelHelper::getNumberOfDays($dateFrom, $dateTo);
|
||||
if ($numDays > 1) {
|
||||
$price *= $numDays;
|
||||
}
|
||||
$numDays = max(1, HotelHelper::getNumberOfDays($dateFrom, $dateTo));
|
||||
}
|
||||
}
|
||||
|
||||
// Rounding as per configurations
|
||||
$totalDemandsPrice += Tools::processPriceRounding($price);
|
||||
$totalDemandsPrice += $price * $numDays;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -409,7 +409,7 @@ class HotelRoomTypeFeaturePricing extends ObjectModel
|
||||
$use_reduc
|
||||
)) {
|
||||
foreach($servicesWithTax as $service) {
|
||||
$totalPrice['total_price_tax_incl'] += Tools::processPriceRounding($service['price']);
|
||||
$totalPrice['total_price_tax_incl'] += $service['price'];
|
||||
}
|
||||
}
|
||||
if ($servicesWithoutTax = RoomTypeServiceProduct::getAutoAddServices(
|
||||
@@ -421,7 +421,7 @@ class HotelRoomTypeFeaturePricing extends ObjectModel
|
||||
$use_reduc
|
||||
)) {
|
||||
foreach($servicesWithoutTax as $service) {
|
||||
$totalPrice['total_price_tax_excl'] += Tools::processPriceRounding($service['price']);
|
||||
$totalPrice['total_price_tax_excl'] += $service['price'];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -430,8 +430,8 @@ class HotelRoomTypeFeaturePricing extends ObjectModel
|
||||
if (!$quantity) {
|
||||
$quantity = 1;
|
||||
}
|
||||
$totalPrice['total_price_tax_incl'] = Tools::processPriceRounding($totalPrice['total_price_tax_incl'], $quantity);
|
||||
$totalPrice['total_price_tax_excl'] = Tools::processPriceRounding($totalPrice['total_price_tax_excl'], $quantity);
|
||||
$totalPrice['total_price_tax_incl'] = $totalPrice['total_price_tax_incl'] * $quantity;
|
||||
$totalPrice['total_price_tax_excl'] = $totalPrice['total_price_tax_excl'] * $quantity;
|
||||
|
||||
return $totalPrice;
|
||||
}
|
||||
|
||||
@@ -324,13 +324,13 @@ class ServiceProductCartDetail extends ObjectModel
|
||||
'unit_price_tax_incl' => $priceTaxIncl,
|
||||
'unit_price_tax_excl' => $priceTaxExcl,
|
||||
'quantity' => $product['quantity'],
|
||||
'total_price_tax_incl' => $priceTaxIncl * (int)$product['quantity'] * $numDays,
|
||||
'total_price_tax_excl' => $priceTaxExcl * (int)$product['quantity'] * $numDays,
|
||||
'total_price_tax_incl' => $priceTaxIncl * $numDays * (int)$product['quantity'],
|
||||
'total_price_tax_excl' => $priceTaxExcl * $numDays * (int)$product['quantity'],
|
||||
'cover_img' => $coverImg,
|
||||
'price_calculation_method' => $product['price_calculation_method'],
|
||||
'auto_add_to_cart' => $product['auto_add_to_cart'],
|
||||
'price_addition_type' => $product['price_addition_type'],
|
||||
'total_price' => ($useTax ? $priceTaxIncl * (int)$product['quantity'] * $numDays : $priceTaxExcl * (int)$product['quantity'] * $numDays),
|
||||
'total_price' => ($useTax ? $priceTaxIncl : $priceTaxExcl) * $numDays * (int)$product['quantity'],
|
||||
);
|
||||
|
||||
if ($product['htl_cart_booking_id']) {
|
||||
|
||||
@@ -892,6 +892,7 @@ class AdminHotelRoomsBookingController extends ModuleAdminController
|
||||
// if room is changing in the reallocation
|
||||
if ($objHotelBooking->id_product != $idNewRoomType) {
|
||||
$result['has_room_type_change'] = 1;
|
||||
$objOrder = new Order($objHotelBooking->id_order);
|
||||
$occupancy = array(
|
||||
array(
|
||||
'adults' => $objHotelBooking->adults,
|
||||
@@ -908,7 +909,8 @@ class AdminHotelRoomsBookingController extends ModuleAdminController
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
0,
|
||||
1
|
||||
);
|
||||
|
||||
if ($objHotelBooking->total_price_tax_excl != $newRoomTotalPrice['total_price_tax_excl']) {
|
||||
|
||||
Reference in New Issue
Block a user