diff --git a/src/QUI/ERP/Shipping/EventHandler.php b/src/QUI/ERP/Shipping/EventHandler.php index 9143647470c95beea814be3b4e75aef940307986..269f17ae9c80490f3cdcd12ec8b9e677885b7709 100644 --- a/src/QUI/ERP/Shipping/EventHandler.php +++ b/src/QUI/ERP/Shipping/EventHandler.php @@ -101,7 +101,7 @@ public static function onQuiqqerOrderBasketToOrderEnd( } $PriceFactors = $Products->getPriceFactors(); - $PriceFactors->addToEnd($Shipping->toPriceFactor()); + $PriceFactors->addToEnd($Shipping->toPriceFactor(null, $Order)); try { $Products->recalculation(); @@ -217,6 +217,7 @@ public static function onQuiqqerOrderCustomerDataSave( } catch (QUI\Exception $Exception) { $Order->clearAddressDelivery(); $Order->save(); + return; } diff --git a/src/QUI/ERP/Shipping/Types/ShippingEntry.php b/src/QUI/ERP/Shipping/Types/ShippingEntry.php index dd1b60d9b1305e1635a8200942843f7fed2a6f73..a74b121a03967109cdfe7287a0402d1f6b9a9372 100644 --- a/src/QUI/ERP/Shipping/Types/ShippingEntry.php +++ b/src/QUI/ERP/Shipping/Types/ShippingEntry.php @@ -690,11 +690,14 @@ public function setOrder(QUI\ERP\Order\OrderInterface $Order) /** * @param null $Locale + * @param QUI\ERP\Order\AbstractOrder|null $Order * * @return QUI\ERP\Products\Utils\PriceFactor */ - public function toPriceFactor($Locale = null) - { + public function toPriceFactor( + $Locale = null, + QUI\ERP\Order\AbstractOrder $Order = null + ) { $PriceFactor = new QUI\ERP\Products\Utils\PriceFactor([ 'title' => QUI::getLocale()->get('quiqqer/shipping', 'shipping.order.title', [ 'shipping' => $this->getTitle($Locale) @@ -707,6 +710,30 @@ public function toPriceFactor($Locale = null) 'visible' => true ]); + /* @var $Article QUI\ERP\Accounting\Article */ + $Articles = $Order->getArticles(); + $vats = []; + + foreach ($Articles as $Article) { + $vat = $Article->getVat(); + $price = $Article->getPrice()->getValue(); + + if (!isset($vats[$vat])) { + $vats[$vat] = 0; + } + + $vats[$vat] = $vats[$vat] + $price; + } + + // look at vat, which vat should be used + if (\count($vats) === 1) { + $PriceFactor->setVat(\key($vats)); + } else { + // get max + $maxVat = \array_keys($vats, \max($vats))[0]; + $PriceFactor->setVat($maxVat); + } + return $PriceFactor; }