diff --git a/src/QUI/ERP/Accounting/ArticleList.php b/src/QUI/ERP/Accounting/ArticleList.php index 28d8e6d870d152de63bdeeec4d1595a1ed1b66cc..2ede96263e6bfb7732a7cc231e09a5af2eeb0798 100644 --- a/src/QUI/ERP/Accounting/ArticleList.php +++ b/src/QUI/ERP/Accounting/ArticleList.php @@ -11,6 +11,8 @@ use function count; use function is_null; +use function key; +use function round; /** * Class ArticleList @@ -477,6 +479,42 @@ public function importPriceFactors(QUI\ERP\Accounting\PriceFactors\FactorList $P $this->PriceFactors = $PriceFactors; } + /** + * @param \QUI\ERP\Accounting\PriceFactors\Factor|QUI\ERP\Products\Utils\PriceFactor $PriceFactor + * @return void + * + * @throws \QUI\ERP\Exception + */ + public function addPriceFactor($PriceFactor) + { + if ($PriceFactor instanceof QUI\ERP\Products\Utils\PriceFactor) { + $isNetto = $this->isNetto; + $vat = 0; + $netto = $PriceFactor->getNettoSum(); + $precision = $this->getCurrency()->getPrecision(); + + if (count($this->vatArray)) { + $vat = key($this->vatArray); + } + + $PriceFactor->setVat($vat); + + $brutto = $netto * ((100 + $vat) / 100); + $brutto = round($brutto, $precision); + + if ($isNetto) { + $PriceFactor->setSum($netto); + } else { + $PriceFactor->setSum($brutto); + } + + $PriceFactor = new QUI\ERP\Accounting\PriceFactors\Factor($PriceFactor->toArray()); + } + + $this->PriceFactors->addFactor($PriceFactor); + $this->recalculate(); + } + //endregion //region order diff --git a/src/QUI/ERP/Accounting/PriceFactors/FactorList.php b/src/QUI/ERP/Accounting/PriceFactors/FactorList.php index ac53aea8c5cff7e850f54fa0df0e4d2f185f351c..221cdd674b538b830171b31923da24b41d1f9781 100644 --- a/src/QUI/ERP/Accounting/PriceFactors/FactorList.php +++ b/src/QUI/ERP/Accounting/PriceFactors/FactorList.php @@ -90,6 +90,15 @@ public function toJSON(): string return json_encode($this->toArray()); } + /** + * @param \QUI\ERP\Accounting\PriceFactors\Factor $Factor + * @return void + */ + public function addFactor(Factor $Factor) + { + $this->list[] = $Factor; + } + //region iterator /**