Newer
Older
<?php
/**
* This file contains QUI\ERP\Accounting\ArticleList
*/
namespace QUI\ERP\Accounting;
use QUI\ERP\Accounting\PriceFactors\FactorList as ErpFactorList;
/**
* Class ArticleListUnique
*
* @package QUI\ERP\Accounting
*/

Henning Leutz
committed
class ArticleListUnique implements \IteratorAggregate
{
/**
/**
* @var bool|mixed
*/
protected $showHeader;
* @var QUI\ERP\Accounting\PriceFactors\FactorList
*/
protected $PriceFactors = false;
/**
* ArticleList constructor.
*
* @param array $attributes
public function __construct($attributes = [])
$needles = ['articles', 'calculations'];
foreach ($needles as $needle) {
if (!isset($attributes[$needle])) {
throw new QUI\ERP\Exception(
'Missing needle for ArticleListUnique',
400,
'class' => 'ArticleListUnique',
'missing' => $needle
$articles = $attributes['articles'];
foreach ($articles as $article) {
if (!isset($article['class'])) {
$this->articles[] = new Article($article);
continue;
}
$class = $article['class'];
$this->articles[] = new Article($article);
continue;
}
if (isset($interfaces[ArticleInterface::class])) {
$this->articles[] = new $class($article);
continue;
}
$this->articles[] = new Article($article);
}
$this->calculations = $attributes['calculations'];
$this->showHeader = isset($attributes['showHeader']) ? $attributes['showHeader'] : true;
$this->PriceFactors = new ErpFactorList();
if (isset($attributes['priceFactors'])) {
$this->PriceFactors = new ErpFactorList($attributes['priceFactors']);
} catch (QUI\ERP\Exception $Exception) {
QUI\System\Log::writeRecursive(
$attributes['priceFactors'],
QUI\System\Log::LEVEL_DEBUG
);
QUI\System\Log::writeDebugException($Exception);
}
}
/**
* Creates a list from a stored representation
*
* @param string $data
* @return ArticleListUnique
*/
public static function unserialize($data)
{
if (\is_string($data)) {
$data = \json_decode($data, true);
}
return new self($data);
}
/**
* Generates a storable representation of the list
*
* @return string
*/
public function serialize()
{
/**
* Return the calculation array
*
* @return array
*/
public function getCalculations()
{
return $this->calculations;
}
/**
* Return the list articles
*
*/
public function getArticles()
{
return $this->articles;
}
/**
* Return the number of articles
*
* @return int
*/
public function count()
{
/**
* Generates a storable json representation of the list
* Alias for serialize()
*
* @return string
*/
public function toJSON()
{
return $this->serialize();
}
/**
* Return the list as an array
*
* @return array
*/
public function toArray()
{
/* @var $Article Article */
return $Article->toArray();
}, $this->articles);
$this->PriceFactors->toArray();
'calculations' => $this->calculations,
'priceFactors' => $this->PriceFactors->toArray()
];
/**
* Display of the header = true
*/
public function displayHeader()
{
$this->showHeader = true;
}
/**
* Display of the header = false
*/
public function hideHeader()
{
$this->showHeader = false;
}
* Return the Article List as HTML, without CSS
* @return string
$Engine = QUI::getTemplateManager()->getEngine();

Henning Leutz
committed
if (!$this->count()) {
return '';
}
$Currency = QUI\ERP\Currency\Handler::getCurrency(
$this->calculations['currencyData']['code']
);
if ($this->calculations['vatArray']) {
$vatArray = $this->calculations['vatArray'];
}
// price display
foreach ($vatArray as $key => $vat) {
$vatArray[$key]['sum'] = $Currency->format($vatArray[$key]['sum']);
}
$this->calculations['sum'] = $Currency->format($this->calculations['sum']);
$this->calculations['subSum'] = $Currency->format($this->calculations['subSum']);
$this->calculations['nettoSum'] = $Currency->format($this->calculations['nettoSum']);
$this->calculations['nettoSubSum'] = $Currency->format($this->calculations['nettoSubSum']);
$articles = \array_map(function ($Article) use ($Currency, &$pos) {
$View = $Article->getView();
$View->setCurrency($Currency);
$View->setPosition($pos);
}, $this->articles);
// output
'priceFactors' => $this->PriceFactors->toArray(),
'this' => $this,
'articles' => $articles,
'calculations' => $this->calculations,
'vatArray' => $vatArray
return $Engine->fetch(\dirname(__FILE__).'/ArticleList.html');
}
/**
* Return the Article List as HTML, with CSS
*
* @return string
*/
public function toHTMLWithCSS()
{
$style = '<style>';
$style .= \file_get_contents(\dirname(__FILE__).'/ArticleList.css');
/**
* Alias for toHTMLWithCSS
*
* @return string
*/
public function render()
{
return $this->toHTMLWithCSS();
}
//region Price Factors
/**
* Return the price factors list (list of price indicators)
*
* @return QUI\ERP\Accounting\PriceFactors\FactorList
*/
public function getPriceFactors()
{
return $this->PriceFactors;
}
//endregion

Henning Leutz
committed
//region iterator
/**
* Iterator helper
*
* @return \ArrayIterator|\Traversable
*/
public function getIterator()
{
return new \ArrayIterator($this->articles);
}
//endregion