From 8ca72e3e2eded294fdf52bd3031bc908c098d62e Mon Sep 17 00:00:00 2001
From: Henning Leutz <leutz@pcsg.de>
Date: Mon, 11 May 2020 14:14:41 +0200
Subject: [PATCH] fix: consider eu vat at price factors

---
 src/QUI/ERP/Accounting/Calc.php               |  4 +++
 .../ERP/Accounting/PriceFactors/Factor.php    | 34 +++++++++++++++++++
 2 files changed, 38 insertions(+)

diff --git a/src/QUI/ERP/Accounting/Calc.php b/src/QUI/ERP/Accounting/Calc.php
index 078f836..2aa95cd 100644
--- a/src/QUI/ERP/Accounting/Calc.php
+++ b/src/QUI/ERP/Accounting/Calc.php
@@ -221,6 +221,10 @@ public function calcArticleList(ArticleList $List, $callback = false)
             $nettoSum       = $nettoSum + $PriceFactor->getNettoSum();
             $priceFactorSum = $priceFactorSum + $PriceFactor->getNettoSum();
 
+            if ($isEuVatUser) {
+                $PriceFactor->setEuVatStatus(true);
+            }
+
             $vat    = $PriceFactor->getVat();
             $vatSum = $PriceFactor->getVatSum();
 
diff --git a/src/QUI/ERP/Accounting/PriceFactors/Factor.php b/src/QUI/ERP/Accounting/PriceFactors/Factor.php
index be8d0b1..0bef0e3 100644
--- a/src/QUI/ERP/Accounting/PriceFactors/Factor.php
+++ b/src/QUI/ERP/Accounting/PriceFactors/Factor.php
@@ -58,6 +58,11 @@ class Factor
      */
     protected $valueText = false;
 
+    /**
+     * @var
+     */
+    protected $euVat = false;
+
     /**
      * FactorList constructor.
      *
@@ -133,6 +138,10 @@ public function getDescription()
      */
     public function getSum()
     {
+        if ($this->euVat) {
+            return $this->getNettoSum();
+        }
+
         return $this->sum;
     }
 
@@ -163,6 +172,10 @@ public function getNettoSum()
      */
     public function getVatSum()
     {
+        if ($this->euVat) {
+            return 0;
+        }
+
         if ($this->vat) {
             return $this->nettoSum * ($this->vat / 100);
         }
@@ -177,6 +190,10 @@ public function getVatSum()
      */
     public function getVat()
     {
+        if ($this->euVat) {
+            return 0;
+        }
+
         if ($this->vat) {
             return $this->vat;
         }
@@ -234,4 +251,21 @@ public function toJSON()
     {
         return \json_encode($this->toArray());
     }
+
+    //region eu vat
+
+    public function isEuVat()
+    {
+        return $this->euVat;
+    }
+
+    /**
+     * @param bool $status
+     */
+    public function setEuVatStatus(bool $status)
+    {
+        $this->euVat = $status;
+    }
+
+    //endregion
 }
-- 
GitLab