From 26dac29acbfc69cc7c0e0994f7f371e4e9b1095a Mon Sep 17 00:00:00 2001 From: Henning Leutz <leutz@pcsg.de> Date: Fri, 4 Jun 2021 12:09:46 +0200 Subject: [PATCH] refactor: consider exchange rates --- src/QUI/ERP/Accounting/ArticleList.php | 8 ++++- src/QUI/ERP/Accounting/ArticleListUnique.php | 34 ++++++++++++++++++-- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/src/QUI/ERP/Accounting/ArticleList.php b/src/QUI/ERP/Accounting/ArticleList.php index d21c96c..2f7b1e6 100644 --- a/src/QUI/ERP/Accounting/ArticleList.php +++ b/src/QUI/ERP/Accounting/ArticleList.php @@ -276,7 +276,13 @@ public function toUniqueList(): ArticleListUnique { $this->calc(); - return new ArticleListUnique($this->toArray(), $this->getUser()); + $List = new ArticleListUnique($this->toArray(), $this->getUser()); + + if ($this->ExchangeCurrency) { + $List->setExchangeCurrency($this->ExchangeCurrency); + } + + return $List; } /** diff --git a/src/QUI/ERP/Accounting/ArticleListUnique.php b/src/QUI/ERP/Accounting/ArticleListUnique.php index 9ead39d..3f203a5 100644 --- a/src/QUI/ERP/Accounting/ArticleListUnique.php +++ b/src/QUI/ERP/Accounting/ArticleListUnique.php @@ -54,6 +54,16 @@ class ArticleListUnique implements \IteratorAggregate */ protected $showExchangeRate = true; + /** + * @var null + */ + protected $ExchangeCurrency = null; + + /** + * @var float + */ + protected $exchangeRate = null; + /** * ArticleList constructor. * @@ -273,6 +283,22 @@ public function hideHeader() $this->showHeader = false; } + /** + * @param QUI\ERP\Currency\Currency $Currency + */ + public function setExchangeCurrency(QUI\ERP\Currency\Currency $Currency) + { + $this->ExchangeCurrency = $Currency; + } + + /** + * @param float $rate + */ + public function setExchangeRate(float $rate) + { + $this->exchangeRate = $rate; + } + /** * Return the Article List as HTML, without CSS * @@ -320,14 +346,18 @@ public function toHTML($template = false): string return $View; }, $this->articles); - $ExchangeCurrency = QUI\ERP\Currency\Conf::getAccountingCurrency(); + $ExchangeCurrency = $this->ExchangeCurrency; $showExchangeRate = $this->showExchangeRate; $exchangeRateText = ''; - if ($ExchangeCurrency->getCode() === $Currency->getCode()) { + if (!$ExchangeCurrency || $ExchangeCurrency->getCode() === $Currency->getCode()) { $showExchangeRate = false; $exchangeRate = false; } else { + if ($this->exchangeRate) { + $Currency->setExchangeRate($this->exchangeRate); + } + $exchangeRate = $Currency->getExchangeRate($ExchangeCurrency); $exchangeRate = $ExchangeCurrency->format($exchangeRate); -- GitLab