diff --git a/ajax/calcNettoPrice.php b/ajax/calcNettoPrice.php index 137111ae3d9b9f470a271251dbe2dc065fc5fcfe..ba61fe6be86769728f534e5a23076a3af1857e7d 100644 --- a/ajax/calcNettoPrice.php +++ b/ajax/calcNettoPrice.php @@ -53,15 +53,43 @@ function ($price, $formatted, $vat) { } $vat = ($vat / 100) + 1; - $price = $price / $vat; + $netto = $price / $vat; + $netto = round($netto, QUI\ERP\Defaults::getPrecision()); + + // gegenrechnung + $precision = QUI\ERP\Defaults::getPrecision(); + $bruttoInput = round($price, $precision); + + $decimalParts = explode('.', $bruttoInput); + $inputPrecision = isset($decimalParts[1]) ? strlen($decimalParts[1]) : 0; + + $brutto = round($netto, $precision) * $vat; + $brutto = round($brutto, $inputPrecision); + + if ($brutto != $bruttoInput) { + $netto = round($netto, $precision); + $brutto = round($netto * $vat, $inputPrecision); + + if ($brutto != $bruttoInput) { + for ($i = 0; $i < 10; $i++) { + $nettoCheck = substr($netto, 0, -$precision); + $bruttoCheck = round($nettoCheck * $vat, $inputPrecision); + + if ($bruttoCheck == $bruttoInput) { + $netto = $nettoCheck; + break; + } + } + } + } if (isset($formatted) && $formatted) { - return QUI\ERP\Defaults::getCurrency()->format($price); + return QUI\ERP\Defaults::getCurrency()->format($netto); } - $price = \round($price, QUI\ERP\Defaults::getPrecision()); + //$netto = round($netto, QUI\ERP\Defaults::getPrecision()); - return $price; + return $netto; }, ['price', 'formatted', 'vat'] ); diff --git a/src/QUI/ERP/Accounting/Calc.php b/src/QUI/ERP/Accounting/Calc.php index d85e4b6b93d56fdb65af7219a257835ba171dc3a..0c92dec8cf39588f09c7369b149dc7df476eb503 100644 --- a/src/QUI/ERP/Accounting/Calc.php +++ b/src/QUI/ERP/Accounting/Calc.php @@ -600,6 +600,7 @@ public function calcArticlePrice(Article $Article, $callback = false) $price = $isNetto ? $nettoPrice : $bruttoPrice; $sum = $isNetto ? $nettoSum : $bruttoSum; $basisPrice = $isNetto ? $basisNettoPrice : $basisNettoPrice + ($basisNettoPrice * $vat / 100); + $basisPrice = round($basisPrice, QUI\ERP\Defaults::getPrecision()); $vatArray = [ 'vat' => $vat,