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

View File

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

View File

@ -10,18 +10,15 @@ class PaperDbSelect extends Select
{ {
protected $newPaperObject = null; protected $newPaperObject = null;
private ?string $staffelCalc = null; public function getSelectedOption(): null|Opt
private ?float $staffelCalcResult = null;
public function getSelectedOption(): ?Opt
{ {
if (count($this->selectedOptions) > 0) { if (count($this->selectedOptions) > 0) {
return $this->selectedOptions[0]; return $this->selectedOptions[0];
} }
if ( if (
isset($this->savedCalcValues[$this->getId()]) isset($this->savedCalcValues[$this->getId()]) &&
&& $this->savedCalcValues[$this->getId()]['art_nr'] == $this->getRawValue() $this->savedCalcValues[$this->getId()]['art_nr'] == $this->getRawValue()
) { ) {
$opt = new PaperOpt(); $opt = new PaperOpt();
$opt->setId($this->savedCalcValues[$this->getId()]['art_nr']); $opt->setId($this->savedCalcValues[$this->getId()]['art_nr']);
@ -107,7 +104,6 @@ class PaperDbSelect extends Select
$variables[$this->getId() . '_glam'] = 0; $variables[$this->getId() . '_glam'] = 0;
$variables[$this->getId() . '_post'] = 0; $variables[$this->getId() . '_post'] = 0;
$variables[$this->getId() . '_sammelform'] = 0; $variables[$this->getId() . '_sammelform'] = 0;
$variables[$this->getId() . '_staffel_value'] = 0;
} else { } else {
/** @var Paper $paper */ /** @var Paper $paper */
$paper = $option->getPaper(); $paper = $option->getPaper();
@ -164,7 +160,6 @@ class PaperDbSelect extends Select
$variables[$this->getId() . '_glam'] = $paper->getGlam(); $variables[$this->getId() . '_glam'] = $paper->getGlam();
$variables[$this->getId() . '_post'] = $paper->getPost(); $variables[$this->getId() . '_post'] = $paper->getPost();
$variables[$this->getId() . '_sammelform'] = $paper->getSammelform(); $variables[$this->getId() . '_sammelform'] = $paper->getSammelform();
$variables[$this->getId() . '_staffel_value'] = $this->getStaffelValue($paper);
} }
return $variables; return $variables;
@ -182,7 +177,6 @@ class PaperDbSelect extends Select
{ {
return array_merge_recursive(parent::generateXML(), ['_attributes' => [ return array_merge_recursive(parent::generateXML(), ['_attributes' => [
'mode' => 'papierdb', 'mode' => 'papierdb',
'staffelCalc' => $this->staffelCalc,
'container' => $this->container, 'container' => $this->container,
]]); ]]);
} }
@ -192,49 +186,8 @@ class PaperDbSelect extends Select
$obj = parent::generateJson(); $obj = parent::generateJson();
$obj->mode = 'papierdb'; $obj->mode = 'papierdb';
$obj->container = $this->container; $obj->container = $this->container;
$obj->staffelCalc = $this->staffelCalc;
$obj->options = []; $obj->options = [];
$obj->options[] = $this->getSelectedOption()->generateJson(); $obj->options[] = $this->getSelectedOption()->generateJson();
return $obj; 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 <?php
namespace PSC\Library\Calc\Tests\Article; namespace PSC\Library\Calc\Tests\Article;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
@ -19,8 +18,7 @@ class SimpleXmlTest extends TestCase
public function testIfArticleCountInXmlCorrectWith2Article() public function testIfArticleCountInXmlCorrectWith2Article()
{ {
$parser = new Engine(new Container()); $parser = new Engine(new Container());
$this->assertTrue($parser->loadString(file_get_contents(__DIR__ $this->assertTrue($parser->loadString(file_get_contents(__DIR__ .'/../TestFiles/General/simple2articles.xml')));
. '/../TestFiles/General/simple2articles.xml')));
$this->assertEquals(2, $parser->getArticles()->Count()); $this->assertEquals(2, $parser->getArticles()->Count());
} }
@ -30,9 +28,10 @@ class SimpleXmlTest extends TestCase
$parser = new Engine(new Container()); $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(); $article = $parser->getArticle();
$this->assertInstanceOf('PSC\Library\Calc\Article', $article); $this->assertInstanceOf('PSC\Library\Calc\Article', $article);
$this->assertEquals('Blocks A5 25blatt geleimt', $article->getName()); $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']->setUmschlagen(true);
$papier['ct200']->setStaerke(0.191); $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']]; return $papier[$criteria['artNr']];
} }