132 lines
3.8 KiB
PHP
132 lines
3.8 KiB
PHP
<?php
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: thomas
|
|
* Date: 16.04.18
|
|
* Time: 14:00
|
|
*/
|
|
|
|
namespace PSC\Library\Calc\Calc;
|
|
|
|
use PSC\Library\Calc\Article;
|
|
use PSC\Library\Calc\Engine;
|
|
use PSC\Library\Calc\General\Type\Edge;
|
|
use PSC\Library\Calc\General\Type\EdgeCollection;
|
|
use PSC\Library\Calc\General\Type\EdgeCollectionContainer;
|
|
use PSC\Library\Calc\Option\Type\Base;
|
|
use PSC\Library\Calc\Option\Type\PaperDbSelect;
|
|
use PSC\Library\Calc\Option\Type\Select;
|
|
use PSC\Library\Calc\Tests\Mock\Paper;
|
|
|
|
class Calc
|
|
{
|
|
/** @var Engine */
|
|
protected $engine = null;
|
|
|
|
/** @var Article */
|
|
protected $article = null;
|
|
|
|
protected $storageFormulas = [];
|
|
|
|
protected $storageCalcValues = [];
|
|
|
|
protected $formelCalc = null;
|
|
|
|
/**
|
|
* Calc constructor.
|
|
* @param Engine $engine
|
|
* @param Article $article
|
|
*/
|
|
public function __construct($engine, $article)
|
|
{
|
|
$this->engine = $engine;
|
|
$this->article = $article;
|
|
$this->formelCalc = new Formel($engine, $article);
|
|
}
|
|
|
|
public function calc()
|
|
{
|
|
$price = 0;
|
|
|
|
/** @var Base $option */
|
|
foreach($this->article->getOptions() as $option) {
|
|
|
|
if($option instanceof Select) {
|
|
/** @var Select\Opt $opt */
|
|
foreach($option->getOptions() as $opt) {
|
|
if($opt->isValid() && $opt->isSelected()) {
|
|
$price = $this->parseEdgeCollection($price, $option, $opt->getEdgesCollectionContainer());
|
|
}
|
|
}
|
|
}
|
|
|
|
$price = $this->parseEdgeCollection($price, $option, $option->getEdgesCollectionContainer());
|
|
}
|
|
|
|
return $price;
|
|
}
|
|
|
|
/**
|
|
* @param $price
|
|
* @param Base $option
|
|
* @param EdgeCollectionContainer $container
|
|
* @return int
|
|
*/
|
|
private function parseEdgeCollection($price, $option, EdgeCollectionContainer $container)
|
|
{
|
|
|
|
$calcValue1 = 0;
|
|
$calcValue2 = 0;
|
|
$calcValueAccount1 = 0;
|
|
$calcValueAccount2 = 0;
|
|
|
|
/** @var EdgeCollection $collection */
|
|
foreach($container as $collection) {
|
|
if($collection->getName() == "opt") continue;
|
|
if($collection->getFormel() != "") {
|
|
$formel = $this->formelCalc->parse($collection->getFormel());
|
|
eval('$var = ' . $formel . ';');
|
|
}else{
|
|
$var = $this->engine->getVariables()[$collection->getName()];
|
|
}
|
|
|
|
/** @var Edge $edge */
|
|
foreach($collection as $edge) {
|
|
|
|
if($edge->isValid($var)) {
|
|
|
|
if($edge->getPauschale() != 0) {
|
|
eval('$price += ' . $edge->getPauschale() . ';');
|
|
}
|
|
|
|
if($edge->getPreis() != 0) {
|
|
eval('$price += ' . ($edge->getPreis()*$var) . ';');
|
|
}
|
|
|
|
if($edge->getCalcValue() != "") {
|
|
$cv = $this->formelCalc->parse($edge->getCalcValue());
|
|
eval('$cv = ' . $cv . ';');
|
|
$this->engine->addCalcVariable($option->getId() . '_' . $collection->getName(), $cv);
|
|
}
|
|
|
|
if($edge->getFormel() != "") {
|
|
$formel = $this->formelCalc->parse($edge->getFormel());
|
|
if ($formel != "" && $option->getId() != 'weight' && !$option->isAjaxExport()) {
|
|
$p = 0;
|
|
|
|
eval('@$p = ' . $formel . ';');
|
|
if($p > 0) {
|
|
$price += $p;
|
|
}
|
|
|
|
$this->engine->setVariable('price', $price);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return $price;
|
|
}
|
|
|
|
} |