Compare commits

..

No commits in common. "e6cfad0446a0bc7b29edde2bd7aea0cb99013a1a" and "dd037b8f73b477e4fdfdc87e4458eaa36b589100" have entirely different histories.

12 changed files with 5660 additions and 5965 deletions

File diff suppressed because it is too large Load Diff

View File

@ -65,14 +65,6 @@ class Calc
}
}
if ($option instanceof Select || $option instanceof Checkbox || $option instanceof Radio) {
if ($option instanceof PaperDbSelect) {
if ($option->getStaffelCalc() !== null) {
$formel = $this->formelCalc->parse($option->getStaffelCalc());
eval('$staffelCalcResult = ' . $formel . ';');
$option->setStaffelCalcResult($staffelCalcResult);
$this->engine->setVariables($option->parseAdditionalValues($this->engine->getVariables()));
}
}
foreach ($option->getSelectedOptions() as $opt) {
if ($opt->isValid()) {
$gesamt = $this->parseEdgeCollection(
@ -175,16 +167,12 @@ class Calc
$edge->getCalcValue(),
$orgCv . ' = ' . $cv,
);
$this->engine
->getCalcGraph()
->addPart(new Part(
$this->engine->getCalcGraph()->addPart(new Part(
type: PartType::CalcValue,
name: $option->getId() . '_' . $collection->getName(),
unParsed: $edge->getCalcValue(),
));
$this->engine
->getCalcGraph()
->addPart(new Part(
$this->engine->getCalcGraph()->addPart(new Part(
type: PartType::CalcValue,
name: $calcValueId,
unParsed: $edge->getCalcValue(),
@ -199,11 +187,11 @@ class Calc
if ($edge->getFormel() != '') {
$formel = $this->formelCalc->parse($edge->getFormel());
if (
$formel != ''
&& !in_array($option->getId(), ['weight', 'weight_single'])
&& !$option->isAjaxExport()
&& !$option->isDisplayOnly()
&& $option->isAmount()
$formel != '' &&
!in_array($option->getId(), ['weight', 'weight_single']) &&
!$option->isAjaxExport() &&
!$option->isDisplayOnly() &&
$option->isAmount()
) {
$p = 0;
$formel = str_replace('tonumber', '$this->toNumber', $formel);
@ -211,9 +199,7 @@ class Calc
try {
eval('@$p = ' . $this->eval_func($gesamt, $formel) . ';');
$this->engine->addDebugCalcFormel($edge->getFormel(), $formel . ' = ' . $p);
$this->engine
->getCalcGraph()
->addCalcFormel(new Part(
$this->engine->getCalcGraph()->addCalcFormel(new Part(
type: PartType::Formel,
name: sprintf('%s-%s', $option->getId(), $collection->getName()),
unParsed: $edge->getFormel(),
@ -229,11 +215,11 @@ class Calc
$this->engine->setVariable('price', $gesamt);
}
if (
$formel != ''
&& !in_array($option->getId(), ['weight', 'weight_single'])
&& $option->isAjaxExport()
&& !$option->isDisplayOnly()
&& $option->isAmount()
$formel != '' &&
!in_array($option->getId(), ['weight', 'weight_single']) &&
$option->isAjaxExport() &&
!$option->isDisplayOnly() &&
$option->isAmount()
) {
$p = 0;
$formel = str_replace('tonumber', '$this->toNumber', $formel);
@ -247,11 +233,11 @@ class Calc
}
}
if (
$formel != ''
&& !in_array($option->getId(), ['weight', 'weight_single'])
&& !$option->isAjaxExport()
&& $option->isDisplayOnly()
&& $option->isAmount()
$formel != '' &&
!in_array($option->getId(), ['weight', 'weight_single']) &&
!$option->isAjaxExport() &&
$option->isDisplayOnly() &&
$option->isAmount()
) {
$p = 0;
$formel = str_replace('tonumber', '$this->toNumber', $formel);

View File

@ -23,7 +23,7 @@ class Select extends Base
/** @var ObjectRepository */
protected $paperRepository;
public function __construct(?string $mode = null)
public function __construct(null|string $mode = null)
{
parent::__construct();
@ -49,18 +49,18 @@ class Select extends Base
}
if (
isset($this->json['mode'])
&& (string) $this->json['mode'] == \PSC\Library\Calc\Option\Type\Select::$modePaperDb
isset($this->json['mode']) &&
((string) $this->json['mode']) == \PSC\Library\Calc\Option\Type\Select::$modePaperDb
) {
$this->parseModePapierDbJson();
} elseif (
isset($this->json['mode'])
&& (string) $this->json['mode'] == \PSC\Library\Calc\Option\Type\Select::$modeDelivery
isset($this->json['mode']) &&
((string) $this->json['mode']) == \PSC\Library\Calc\Option\Type\Select::$modeDelivery
) {
$this->parseModeDeliveryJson();
} elseif (
isset($this->json['mode'])
&& (string) $this->json['mode'] == \PSC\Library\Calc\Option\Type\Select::$modeColorDb
isset($this->json['mode']) &&
((string) $this->json['mode']) == \PSC\Library\Calc\Option\Type\Select::$modeColorDb
) {
$this->parseModeColorDbJson();
} else {
@ -81,18 +81,18 @@ class Select extends Base
}
if (
isset($this->node['mode'])
&& (string) $this->node['mode'] == \PSC\Library\Calc\Option\Type\Select::$modePaperDb
isset($this->node['mode']) &&
((string) $this->node['mode']) == \PSC\Library\Calc\Option\Type\Select::$modePaperDb
) {
$this->parseModePapierDbXML();
} elseif (
isset($this->node['mode'])
&& (string) $this->node['mode'] == \PSC\Library\Calc\Option\Type\Select::$modeDelivery
isset($this->node['mode']) &&
((string) $this->node['mode']) == \PSC\Library\Calc\Option\Type\Select::$modeDelivery
) {
$this->parseModeDeliveryXML();
} elseif (
isset($this->node['mode'])
&& (string) $this->node['mode'] == \PSC\Library\Calc\Option\Type\Select::$modeColorDb
isset($this->node['mode']) &&
((string) $this->node['mode']) == \PSC\Library\Calc\Option\Type\Select::$modeColorDb
) {
$this->parseModeColorDbXML();
} else {
@ -123,9 +123,6 @@ class Select extends Base
private function parseModePapierDbXML()
{
$this->element->setContainer((string) $this->node['container']);
if (isset($this->node['staffelCalc'])) {
$this->element->setStaffelCalc((string) $this->node['staffelCalc']);
}
if ($this->getPaperRepository()) {
$this->element->setNewPaperObject($this->getPaperRepository()->getNewObject());
/** @var PaperContainer\Container $container */
@ -157,9 +154,6 @@ class Select extends Base
private function parseModePapierDbJson()
{
$this->element->setContainer((string) $this->json['container']);
if (isset($this->json['staffelCalc'])) {
$this->element->setStaffelCalc((string) $this->json['staffelCalc']);
}
if ($this->getPaperRepository()) {
$this->element->setNewPaperObject($this->getPaperRepository()->getNewObject());
/** @var PaperContainer\Container $container */

View File

@ -10,18 +10,15 @@ class PaperDbSelect extends Select
{
protected $newPaperObject = null;
private ?string $staffelCalc = null;
private ?float $staffelCalcResult = null;
public function getSelectedOption(): ?Opt
public function getSelectedOption(): null|Opt
{
if (count($this->selectedOptions) > 0) {
return $this->selectedOptions[0];
}
if (
isset($this->savedCalcValues[$this->getId()])
&& $this->savedCalcValues[$this->getId()]['art_nr'] == $this->getRawValue()
isset($this->savedCalcValues[$this->getId()]) &&
$this->savedCalcValues[$this->getId()]['art_nr'] == $this->getRawValue()
) {
$opt = new PaperOpt();
$opt->setId($this->savedCalcValues[$this->getId()]['art_nr']);
@ -107,7 +104,6 @@ class PaperDbSelect extends Select
$variables[$this->getId() . '_glam'] = 0;
$variables[$this->getId() . '_post'] = 0;
$variables[$this->getId() . '_sammelform'] = 0;
$variables[$this->getId() . '_staffel_value'] = 0;
} else {
/** @var Paper $paper */
$paper = $option->getPaper();
@ -164,7 +160,6 @@ class PaperDbSelect extends Select
$variables[$this->getId() . '_glam'] = $paper->getGlam();
$variables[$this->getId() . '_post'] = $paper->getPost();
$variables[$this->getId() . '_sammelform'] = $paper->getSammelform();
$variables[$this->getId() . '_staffel_value'] = $this->getStaffelValue($paper);
}
return $variables;
@ -182,7 +177,6 @@ class PaperDbSelect extends Select
{
return array_merge_recursive(parent::generateXML(), ['_attributes' => [
'mode' => 'papierdb',
'staffelCalc' => $this->staffelCalc,
'container' => $this->container,
]]);
}
@ -192,49 +186,8 @@ class PaperDbSelect extends Select
$obj = parent::generateJson();
$obj->mode = 'papierdb';
$obj->container = $this->container;
$obj->staffelCalc = $this->staffelCalc;
$obj->options = [];
$obj->options[] = $this->getSelectedOption()->generateJson();
return $obj;
}
public function setStaffelCalc(?string $staffelCalc): void
{
$this->staffelCalc = $staffelCalc;
}
public function getStaffelCalc(): ?string
{
return $this->staffelCalc;
}
public function setStaffelCalcResult(?float $staffelCalcResult): void
{
$this->staffelCalcResult = $staffelCalcResult;
}
public function getStaffelCalcResult(): ?float
{
return $this->staffelCalcResult;
}
private function getStaffelValue($paper): ?float
{
if ($this->getStaffelCalcResult() >= $paper->getStaffelMenge5()) {
return (float) $paper->getStaffelPreis5();
}
if ($this->getStaffelCalcResult() >= $paper->getStaffelMenge4()) {
return (float) $paper->getStaffelPreis4();
}
if ($this->getStaffelCalcResult() >= $paper->getStaffelMenge3()) {
return (float) $paper->getStaffelPreis3();
}
if ($this->getStaffelCalcResult() >= $paper->getStaffelMenge2()) {
return (float) $paper->getStaffelPreis2();
}
if ($this->getStaffelCalcResult() >= $paper->getStaffelMenge1()) {
return (float) $paper->getStaffelPreis1();
}
return 0;
}
}

View File

@ -1,5 +1,4 @@
<?php
namespace PSC\Library\Calc\Tests\Article;
use PHPUnit\Framework\TestCase;
@ -11,7 +10,7 @@ class SimpleXmlTest extends TestCase
public function testIfArticleCountInXmlCorrect()
{
$parser = new Engine(new Container());
$this->assertTrue($parser->loadString(file_get_contents(__DIR__ . '/../TestFiles/General/simple.xml')));
$this->assertTrue($parser->loadString(file_get_contents(__DIR__ .'/../TestFiles/General/simple.xml')));
$this->assertEquals(1, $parser->getArticles()->Count());
}
@ -19,8 +18,7 @@ class SimpleXmlTest extends TestCase
public function testIfArticleCountInXmlCorrectWith2Article()
{
$parser = new Engine(new Container());
$this->assertTrue($parser->loadString(file_get_contents(__DIR__
. '/../TestFiles/General/simple2articles.xml')));
$this->assertTrue($parser->loadString(file_get_contents(__DIR__ .'/../TestFiles/General/simple2articles.xml')));
$this->assertEquals(2, $parser->getArticles()->Count());
}
@ -28,11 +26,12 @@ class SimpleXmlTest extends TestCase
public function testGetArticleByName()
{
$parser = new Engine(new Container());
$parser->loadString(file_get_contents(__DIR__ . '/../TestFiles/General/simple2articles.xml'));
$parser->loadString(file_get_contents(__DIR__ .'/../TestFiles/General/simple2articles.xml'));
$parser->setActiveArticle('Blocks A5 25blatt geleimt');
$parser->setActiveArticle("Blocks A5 25blatt geleimt");
$article = $parser->getArticle();
$this->assertInstanceOf('PSC\Library\Calc\Article', $article);
$this->assertEquals('Blocks A5 25blatt geleimt', $article->getName());
}
}

View File

@ -1,61 +0,0 @@
<?php
namespace PSC\Library\Calc\Tests\Customer\PP;
use PHPUnit\Framework\TestCase;
use PSC\Library\Calc\Article;
use PSC\Library\Calc\Engine;
use PSC\Library\Calc\Option\Type\Select;
use PSC\Library\Calc\PaperContainer;
use PSC\Library\Calc\Tests\Mock\PaperRepostory;
class CalcTest extends TestCase
{
protected ?Engine $engine = null;
public function setUp(): void
{
$repository = new PaperRepostory();
$paperContainer = new PaperContainer();
$paperContainer->parse(simplexml_load_string(file_get_contents(__DIR__ . '/papierContainer.xml')));
$this->engine = new Engine();
$this->engine->setPaperContainer($paperContainer);
$this->engine->setPaperRepository($repository);
$this->engine->setFormulas(file_get_contents(__DIR__ . '/formels.txt'));
$this->engine->setParameters(file_get_contents(__DIR__ . '/parameters.txt'));
$this->engine->setTemplates(file_get_contents(__DIR__ . '/calcTemplates.xml'));
$this->engine->loadString(file_get_contents(__DIR__ . '/calc.txt'));
}
public function tearDown(): void
{
$this->engine = null;
}
public function testNormalPrice(): void
{
$this->engine->calc();
$this->assertSame(25.00, $this->engine->getPrice());
$this->engine->getCalcGraph()->generateJsonGraph();
}
public function testStaffel2Price(): void
{
$this->engine->setVariable('papier', 'staffel2');
$this->engine->calc();
$this->assertSame(207.00, $this->engine->getPrice());
$this->engine->getCalcGraph()->generateJsonGraph();
}
public function testStaffel2_1Price(): void
{
$this->engine->setVariable('papier', 'staffel2');
$this->engine->setVariable('auflage', '45');
$this->engine->calc();
$this->assertSame(407.00, $this->engine->getPrice());
$this->engine->getCalcGraph()->generateJsonGraph();
}
}

View File

@ -1,39 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Prototyp für wmw, Übergabe prüfen!
ToDo:
-Online-Rabatt wird per exportAjax nur ausgewiesen, wenn Default="ja" ausgewählt ist!
-Buchrücken > 4,5 cm für HDCOVER, HDLEINEN
-Buchrücken > 0,5 cm für PUR
-->
<kalkulation>
<artikel>
<name>Broschüren Offsetdruck</name>
<kommentar></kommentar>
<!-- Grundlagen -->
<name>BRO Prototyp</name>
<kommentar></kommentar>
<option id="auflage" name="Auflage" type="Input" default="21" min="50" max="5000000"/>
<option id="papier" name="PapierDB" type="Select" mode="papierdb" staffelCalc="$Vauflage$V" container="staffel" default="staffel1">
</option>
<option id="calc" type="Hidden">
<auflage>
<grenze formel="$Vpapier_value$V">1-</grenze>
</auflage>
</option>
<option id="calc_staffel" type="Hidden">
<auflage>
<grenze formel="$Vpapier_staffel_value$V">1-</grenze>
</auflage>
</option>
</artikel>
</kalkulation>

View File

@ -1,2 +0,0 @@
<root>
</root>

View File

@ -1 +0,0 @@

View File

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<container>
<papiercontainer id="staffel">
<papier id="staffel1"/>
<papier id="staffel2"/>
</papiercontainer>
</container>

View File

@ -1 +0,0 @@

View File

@ -447,40 +447,6 @@ class PaperRepostory implements ObjectRepository
$papier['ct200']->setUmschlagen(true);
$papier['ct200']->setStaerke(0.191);
$papier['staffel1'] = new Paper();
$papier['staffel1']->setArtNr('staffel1');
$papier['staffel1']->setGrammatur('1');
$papier['staffel1']->setPreis(5);
$papier['staffel1']->setUmschlagen(true);
$papier['staffel1']->setStaerke(0.191);
$papier['staffel1']->setStaffelmenge1(10);
$papier['staffel1']->setStaffelmenge2(20);
$papier['staffel1']->setStaffelmenge3(30);
$papier['staffel1']->setStaffelmenge4(40);
$papier['staffel1']->setStaffelmenge5(50);
$papier['staffel1']->setStaffelpreis1(10);
$papier['staffel1']->setStaffelpreis2(20);
$papier['staffel1']->setStaffelpreis3(30);
$papier['staffel1']->setStaffelpreis4(40);
$papier['staffel1']->setStaffelpreis5(50);
$papier['staffel2'] = new Paper();
$papier['staffel2']->setArtNr('staffel2');
$papier['staffel2']->setGrammatur('1');
$papier['staffel2']->setPreis(6);
$papier['staffel2']->setUmschlagen(true);
$papier['staffel2']->setStaerke(0.191);
$papier['staffel2']->setStaffelmenge1(10);
$papier['staffel2']->setStaffelmenge2(20);
$papier['staffel2']->setStaffelmenge3(30);
$papier['staffel2']->setStaffelmenge4(40);
$papier['staffel2']->setStaffelmenge5(50);
$papier['staffel2']->setStaffelpreis1(101);
$papier['staffel2']->setStaffelpreis2(201);
$papier['staffel2']->setStaffelpreis3(301);
$papier['staffel2']->setStaffelpreis4(401);
$papier['staffel2']->setStaffelpreis5(501);
return $papier[$criteria['artNr']];
}