diff --git a/ajax/calcNettoPrice.php b/ajax/calcNettoPrice.php index ba61fe6be86769728f534e5a23076a3af1857e7d..bd21e216ab1b7624f77a5d3dc256d9bcada70f20 100644 --- a/ajax/calcNettoPrice.php +++ b/ajax/calcNettoPrice.php @@ -22,6 +22,14 @@ function ($price, $formatted, $vat) { $price = QUI\ERP\Money\Price::validatePrice($price); + if (empty($price)) { + if (isset($formatted) && $formatted) { + return QUI\ERP\Defaults::getCurrency()->format(0); + } + + return 0; + } + if (empty($vat) && !is_numeric($vat)) { $Area = QUI\ERP\Defaults::getArea(); diff --git a/src/QUI/ERP/Accounting/Calc.php b/src/QUI/ERP/Accounting/Calc.php index 142c45a220b3eb631b2dae532a8a18efc71dc40d..7e813a9a42a3d8f7e8ffb6267ed2fa11cc0e36e7 100644 --- a/src/QUI/ERP/Accounting/Calc.php +++ b/src/QUI/ERP/Accounting/Calc.php @@ -459,7 +459,7 @@ public function calcArticleList(ArticleList $List, $callback = false): ArticleLi // counterbalance - gegenrechnung // works only for one vat entry - if (count($vatArray) === 1) { + if (count($vatArray) === 1 && $isNetto) { $vat = key($vatArray); $netto = $bruttoSum / ((float)$vat / 100 + 1); @@ -585,6 +585,15 @@ public function calcArticlePrice(Article $Article, $callback = false) $checkVat = $checkBrutto - $nettoPriceNotRounded; $checkVat = round($checkVat * $Article->getQuantity(), $Currency->getPrecision()); + if ($nettoPrice + $checkVat !== $checkBrutto) { + $diff = round( + $nettoPrice + $checkVat - $checkBrutto, + $Currency->getPrecision() + ); + + $checkVat = $checkVat - $diff; + } + // sum $nettoSum = $this->round($nettoPrice * $Article->getQuantity()); $vatSum = $nettoSum * ($vat / 100);