Add Saved Values vom DB
This commit is contained in:
parent
8eaf94b022
commit
529183a821
@ -55,6 +55,8 @@ class Engine
|
||||
/** @var \SimpleXMLElement $templates */
|
||||
protected $templates;
|
||||
|
||||
protected $savedCalcValues = [];
|
||||
|
||||
/**
|
||||
* Load XML From String
|
||||
*
|
||||
@ -217,6 +219,8 @@ class Engine
|
||||
// Prefill with defaults
|
||||
/** @var Base $option */
|
||||
foreach($this->article->getOptions() as $option) {
|
||||
$option->setSavedCalcValues($this->savedCalcValues);
|
||||
|
||||
if(!isset($this->variables[$option->getId()]) && $option->getDefault() !== null && !$option instanceof Text) {
|
||||
$this->variables[$option->getId()] = $option->getDefault();
|
||||
}
|
||||
@ -381,4 +385,8 @@ class Engine
|
||||
return $this->templates;
|
||||
}
|
||||
|
||||
public function setSavedCalcReferences($values)
|
||||
{
|
||||
$this->savedCalcValues = $values;
|
||||
}
|
||||
}
|
||||
@ -38,6 +38,7 @@ class Base
|
||||
/** @var bool */
|
||||
protected $isAjaxExport = false;
|
||||
|
||||
protected $savedCalcValues = [];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@ -232,4 +233,20 @@ class Base
|
||||
{
|
||||
return $variables;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getSavedCalcValues()
|
||||
{
|
||||
return $this->savedCalcValues;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $savedCalcValues
|
||||
*/
|
||||
public function setSavedCalcValues($savedCalcValues)
|
||||
{
|
||||
$this->savedCalcValues = $savedCalcValues;
|
||||
}
|
||||
}
|
||||
@ -7,12 +7,42 @@ use PSC\Library\Calc\Tests\Mock\Paper;
|
||||
|
||||
class PaperDbSelect extends Select
|
||||
{
|
||||
public function getSelectedOption()
|
||||
{
|
||||
/** @var Opt $opt */
|
||||
foreach($this->getOptions() as $opt) {
|
||||
if($opt->isSelected()) return $opt;
|
||||
}
|
||||
|
||||
if(isset($this->savedCalcValues[$this->getId()]) && $this->savedCalcValues[$this->getId()]['art_nr'] == $this->getRawValue()) {
|
||||
$opt = new PaperOpt();
|
||||
$opt->setIsSelected(true);
|
||||
$opt->setId($this->savedCalcValues[$this->getId()]['art_nr']);
|
||||
$opt->setLabel($this->savedCalcValues[$this->getId()]['description_1']);
|
||||
|
||||
$paper = new Paper();
|
||||
$paper->setId($this->savedCalcValues[$this->getId()]['id']);
|
||||
$paper->setArtNr($this->savedCalcValues[$this->getId()]['art_nr']);
|
||||
$paper->setDescription1($this->savedCalcValues[$this->getId()]['description_1']);
|
||||
$paper->setDescription2($this->savedCalcValues[$this->getId()]['description_2']);
|
||||
$paper->setPreis($this->savedCalcValues[$this->getId()]['preis']);
|
||||
$paper->setGrammatur($this->savedCalcValues[$this->getId()]['grammatur']);
|
||||
$paper->setOffsetFix($this->savedCalcValues[$this->getId()]['offset_fix']);
|
||||
$paper->setOffsetVar($this->savedCalcValues[$this->getId()]['offset_var']);
|
||||
$paper->setDigitalFix($this->savedCalcValues[$this->getId()]['digital_fix']);
|
||||
$paper->setDigitalVar($this->savedCalcValues[$this->getId()]['digital_var']);
|
||||
$paper->setVolume($this->savedCalcValues[$this->getId()]['volume']);
|
||||
|
||||
$opt->setPaper($paper);
|
||||
|
||||
return $opt;
|
||||
}
|
||||
}
|
||||
|
||||
public function parseAdditionalValues($variables)
|
||||
{
|
||||
/** @var PaperOpt $option */
|
||||
$option = $this->getSelectedOption();
|
||||
|
||||
if($option == null) {
|
||||
|
||||
$variables[$this->getId() . '_grammatur'] = 0;
|
||||
|
||||
56
tests/Complex/PaperSavedTest.php
Normal file
56
tests/Complex/PaperSavedTest.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
namespace PSC\Library\Calc\Tests\Complex;
|
||||
|
||||
|
||||
|
||||
use PSC\Library\Calc\Article;
|
||||
use PSC\Library\Calc\Engine;
|
||||
use PSC\Library\Calc\PaperContainer;
|
||||
use PSC\Library\Calc\Tests\Mock\PaperRepostory;
|
||||
|
||||
class PaperSavedTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/** @var Engine */
|
||||
protected $engine = null;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$repository = new PaperRepostory();
|
||||
|
||||
$paperContainer = new PaperContainer();
|
||||
$paperContainer->parse(simplexml_load_string(file_get_contents(__DIR__ . '/../TestFiles/Complex/papierContainer.xml')));
|
||||
|
||||
$this->engine = new Engine();
|
||||
$this->engine->setPaperContainer($paperContainer);
|
||||
$this->engine->setPaperRepository($repository);
|
||||
$this->engine->setFormulas(file_get_contents(__DIR__.'/../TestFiles/Complex/formels.txt'));
|
||||
$this->engine->setParameters(file_get_contents(__DIR__.'/../TestFiles/Complex/parameters.txt'));
|
||||
|
||||
$this->engine->loadString(file_get_contents(__DIR__ . '/../TestFiles/Complex/1.xml'));
|
||||
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
$this->engine = null;
|
||||
}
|
||||
|
||||
public function testIfArticleCountIsCorrect()
|
||||
{
|
||||
$this->assertEquals(1, $this->engine->getArticles()->Count());
|
||||
}
|
||||
|
||||
public function testIfDefaultPriceIsOk()
|
||||
{
|
||||
$this->engine->setVariable('papier', 'INM137');
|
||||
|
||||
$this->engine->setSavedCalcReferences([ "papier" =>
|
||||
[ "id" => "5039", "install_id" => "1", "uuid" => "0001-00000000-4bfaf9c3-7158-bce189cb",
|
||||
"art_nr" => "INM137", "description_1" => "Bilderdruck matt 250 gr",
|
||||
"description_2" => "Bilderdruck matt 135 gr", "grammatur" => "135", "preis" => "28",
|
||||
"offset_fix" => "0", "offset_var" => "0", "digital_fix" => "0", "digital_var" => "0", "volume" => "0.118" ] ]);
|
||||
|
||||
$this->assertEquals(162.19, $this->engine->getPrice());
|
||||
}
|
||||
}
|
||||
@ -50,6 +50,8 @@ class selectWithGrenzenTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertCount(6, $article->getValidOptions());
|
||||
|
||||
$this->assertCount(6, $article->getOptionsAsArray());
|
||||
|
||||
$this->assertInstanceOf('\PSC\Library\Calc\Option\Type\Select\Opt', $article->getOptionById('umschlag')->getSelectedOption());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@
|
||||
<option id="t30" name="" type="Text" default="Bitte geben Sie den Neuwert Ihres Gebäudes/Ihrer Gebäude ein (in Euro gerundet auf Tsd.)"></option>
|
||||
<option id="gebwert" name="" type="Input" default="0" require="true" hidden="false">
|
||||
<gebyn>
|
||||
<grenze formel="$Vgebwert$V/1000*0.906">1</grenze>
|
||||
<grenze formel="tonumber($Vgebwert$V/1000*0.906)">1</grenze>
|
||||
<grenze formel="">2</grenze>
|
||||
</gebyn>
|
||||
</option>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user