From f0889b23e756bc0c7824100a65e35240980b1ee5 Mon Sep 17 00:00:00 2001 From: Darius Aleksiunas Date: Thu, 17 Nov 2022 10:49:02 +0200 Subject: [PATCH] fix vat rounding precission --- src/Service/CartLinesService.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Service/CartLinesService.php b/src/Service/CartLinesService.php index 5c605b6ef..0bb16399b 100644 --- a/src/Service/CartLinesService.php +++ b/src/Service/CartLinesService.php @@ -102,7 +102,7 @@ public function getCartLines( $orderLines = $this->fillProductLinesWithRemainingData($orderLines, $apiRoundingPrecision, $vatRatePrecision); // Add shipping - $orderLines = $this->addShippingLine($roundedShippingCost, $cartSummary, $apiRoundingPrecision, $orderLines); + $orderLines = $this->addShippingLine($roundedShippingCost, $cartSummary, $apiRoundingPrecision, $vatRatePrecision, $orderLines); // Add wrapping $orderLines = $this->addWrappingLine($wrappingPrice, $cartSummary, $vatRatePrecision, $apiRoundingPrecision, $orderLines); @@ -332,7 +332,7 @@ private function fillProductLinesWithRemainingData(array $orderLines, $apiRoundi 'quantity' => (int) $quantity, 'unitPrice' => round($unitPrice, $apiRoundingPrecision), 'totalAmount' => round($totalAmount, $apiRoundingPrecision), - 'vatRate' => round($actualVatRate, $apiRoundingPrecision), + 'vatRate' => round($actualVatRate, $vatRatePrecision), 'vatAmount' => round($vatAmount, $apiRoundingPrecision), ]; if (isset($line['sku'])) { @@ -354,10 +354,10 @@ private function fillProductLinesWithRemainingData(array $orderLines, $apiRoundi * * @return array */ - private function addShippingLine($roundedShippingCost, $cartSummary, $apiRoundingPrecision, array $orderLines) + private function addShippingLine($roundedShippingCost, $cartSummary, $apiRoundingPrecision, $vatRatePrecision, array $orderLines) { if (round($roundedShippingCost, 2) > 0) { - $shippingVatRate = round(($cartSummary['total_shipping'] - $cartSummary['total_shipping_tax_exc']) / $cartSummary['total_shipping_tax_exc'] * 100, $apiRoundingPrecision); + $shippingVatRate = round(($cartSummary['total_shipping'] - $cartSummary['total_shipping_tax_exc']) / $cartSummary['total_shipping_tax_exc'] * 100, $vatRatePrecision); $orderLines['shipping'] = [ [ @@ -400,7 +400,7 @@ private function addWrappingLine($wrappingPrice, array $cartSummary, $vatRatePre 'quantity' => 1, 'unitPrice' => round($wrappingPrice, $apiRoundingPrecision), 'totalAmount' => round($wrappingPrice, $apiRoundingPrecision), - 'vatAmount' => round($wrappingPrice * $wrappingVatRate / ($wrappingVatRate + 100), $apiRoundingPrecision), + 'vatAmount' => round($wrappingPrice * $wrappingVatRate / ($wrappingVatRate + 100), $vatRatePrecision), 'vatRate' => $wrappingVatRate, ], ];