Compare commits

..

2 Commits

Author SHA1 Message Date
e6cfad0446 Staffelpreise 2026-04-24 10:53:39 +02:00
755cd972e1 Backup 2026-04-23 17:15:08 +02:00
12 changed files with 5917 additions and 5612 deletions

File diff suppressed because it is too large Load Diff

View File

@ -65,6 +65,14 @@ 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(
@ -167,12 +175,16 @@ 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(),
@ -187,11 +199,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);
@ -199,7 +211,9 @@ 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(),
@ -215,11 +229,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);
@ -233,11 +247,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(null|string $mode = null)
public function __construct(?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,6 +123,9 @@ 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 */
@ -154,6 +157,9 @@ 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,15 +10,18 @@ class PaperDbSelect extends Select
{
protected $newPaperObject = null;
public function getSelectedOption(): null|Opt
private ?string $staffelCalc = null;
private ?float $staffelCalcResult = null;
public function getSelectedOption(): ?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']);
@ -104,6 +107,7 @@ 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();
@ -160,6 +164,7 @@ 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;
@ -177,6 +182,7 @@ class PaperDbSelect extends Select
{
return array_merge_recursive(parent::generateXML(), ['_attributes' => [
'mode' => 'papierdb',
'staffelCalc' => $this->staffelCalc,
'container' => $this->container,
]]);
}
@ -186,8 +192,49 @@ 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,4 +1,5 @@
<?php
namespace PSC\Library\Calc\Tests\Article;
use PHPUnit\Framework\TestCase;
@ -10,7 +11,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());
}
@ -18,7 +19,8 @@ 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());
}
@ -26,12 +28,11 @@ 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

@ -0,0 +1,61 @@
<?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

@ -0,0 +1,39 @@
<?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

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

View File

@ -0,0 +1 @@

View File

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

View File

@ -0,0 +1 @@

View File

@ -447,6 +447,40 @@ 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']];
}