Delivery Calc
This commit is contained in:
parent
f7018214a3
commit
cc5695b1a1
@ -14,7 +14,8 @@
|
|||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=7.0",
|
"php": ">=7.0",
|
||||||
"doctrine/orm": "^2.5"
|
"doctrine/orm": "^2.5",
|
||||||
|
"azuyalabs/yasumi": "^2.5"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "^9",
|
"phpunit/phpunit": "^9",
|
||||||
|
|||||||
1004
composer.lock
generated
1004
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@ -4,6 +4,7 @@ namespace PSC\Library\Calc\Option\Parser;
|
|||||||
use Doctrine\Persistence\ObjectRepository;
|
use Doctrine\Persistence\ObjectRepository;
|
||||||
use PSC\Library\Calc\General\Parser\EdgeCollectionContainer;
|
use PSC\Library\Calc\General\Parser\EdgeCollectionContainer;
|
||||||
use PSC\Library\Calc\Option\Parser\Select\Opt;
|
use PSC\Library\Calc\Option\Parser\Select\Opt;
|
||||||
|
use PSC\Library\Calc\Option\Parser\Select\DeliveryOpt;
|
||||||
use PSC\Library\Calc\PaperContainer;
|
use PSC\Library\Calc\PaperContainer;
|
||||||
use PSC\Library\Calc\Tests\Mock\Paper;
|
use PSC\Library\Calc\Tests\Mock\Paper;
|
||||||
|
|
||||||
@ -25,6 +26,8 @@ class Select extends Base
|
|||||||
{
|
{
|
||||||
if(isset($node['mode']) && (string)$node['mode'] == \PSC\Library\Calc\Option\Type\Select::$modePaperDb) {
|
if(isset($node['mode']) && (string)$node['mode'] == \PSC\Library\Calc\Option\Type\Select::$modePaperDb) {
|
||||||
$this->element = new \PSC\Library\Calc\Option\Type\PaperDbSelect();
|
$this->element = new \PSC\Library\Calc\Option\Type\PaperDbSelect();
|
||||||
|
}elseif(isset($node['mode']) && (string)$node['mode'] == \PSC\Library\Calc\Option\Type\Select::$modeDelivery) {
|
||||||
|
$this->element = new \PSC\Library\Calc\Option\Type\DeliverySelect();
|
||||||
}else{
|
}else{
|
||||||
$this->element = new \PSC\Library\Calc\Option\Type\Select();
|
$this->element = new \PSC\Library\Calc\Option\Type\Select();
|
||||||
}
|
}
|
||||||
@ -43,6 +46,8 @@ class Select extends Base
|
|||||||
|
|
||||||
if(isset($this->node['mode']) && (string)$this->node['mode'] == \PSC\Library\Calc\Option\Type\Select::$modePaperDb) {
|
if(isset($this->node['mode']) && (string)$this->node['mode'] == \PSC\Library\Calc\Option\Type\Select::$modePaperDb) {
|
||||||
$this->parseModePapierDb();
|
$this->parseModePapierDb();
|
||||||
|
}elseif(isset($this->node['mode']) && (string)$this->node['mode'] == \PSC\Library\Calc\Option\Type\Select::$modeDelivery) {
|
||||||
|
$this->parseModeDelivery();
|
||||||
}else{
|
}else{
|
||||||
$this->parseModeNormal();
|
$this->parseModeNormal();
|
||||||
}
|
}
|
||||||
@ -50,6 +55,15 @@ class Select extends Base
|
|||||||
return $this->element;
|
return $this->element;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function parseModeDelivery()
|
||||||
|
{
|
||||||
|
foreach ($this->node->opt as $opt) {
|
||||||
|
$optParser = new DeliveryOpt($opt);
|
||||||
|
$this->element->addOption($optParser->parse());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private function parseModePapierDb()
|
private function parseModePapierDb()
|
||||||
{
|
{
|
||||||
$this->element->setNewPaperObject($this->getPaperRepository()->getNewObject());
|
$this->element->setNewPaperObject($this->getPaperRepository()->getNewObject());
|
||||||
|
|||||||
42
src/Option/Parser/Select/DeliveryOpt.php
Normal file
42
src/Option/Parser/Select/DeliveryOpt.php
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
namespace PSC\Library\Calc\Option\Parser\Select;
|
||||||
|
|
||||||
|
use PSC\Library\Calc\General\Parser\EdgeCollectionContainer;
|
||||||
|
use PSC\Library\Calc\Option\Parser\Base;
|
||||||
|
|
||||||
|
class DeliveryOpt extends Opt
|
||||||
|
{
|
||||||
|
protected $element;
|
||||||
|
|
||||||
|
public function __construct(\SimpleXMLElement $node)
|
||||||
|
{
|
||||||
|
$this->element = new \PSC\Library\Calc\Option\Type\Select\DeliveryOpt();
|
||||||
|
$this->node = $node;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function parse()
|
||||||
|
{
|
||||||
|
parent::parse();
|
||||||
|
|
||||||
|
if(isset($this->node['info'])) {
|
||||||
|
$this->element->setInfo((string)$this->node['info']);
|
||||||
|
}
|
||||||
|
if(isset($this->node['country'])) {
|
||||||
|
$this->element->setCountry((string)$this->node['country']);
|
||||||
|
}
|
||||||
|
if(isset($this->node['dateFormat'])) {
|
||||||
|
$this->element->setDateFormat((string)$this->node['dateFormat']);
|
||||||
|
}
|
||||||
|
if(isset($this->node['maxTime'])) {
|
||||||
|
$this->element->setMaxTime((int)$this->node['maxTime']);
|
||||||
|
}
|
||||||
|
if(isset($this->node['workDays'])) {
|
||||||
|
$this->element->setWorkDays((int)$this->node['workDays']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->element->setLabel((string)$this->node['name']);
|
||||||
|
|
||||||
|
return $this->element;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
18
src/Option/Type/DeliverySelect.php
Normal file
18
src/Option/Type/DeliverySelect.php
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
namespace PSC\Library\Calc\Option\Type;
|
||||||
|
|
||||||
|
use PSC\Library\Calc\Option\Type\Select\Opt;
|
||||||
|
use PSC\Library\Calc\Option\Type\Select\PaperOpt;
|
||||||
|
use PSC\Library\Calc\Tests\Mock\Paper;
|
||||||
|
|
||||||
|
class DeliverySelect extends Select
|
||||||
|
{
|
||||||
|
public function getSelectedOption()
|
||||||
|
{
|
||||||
|
/** @var Opt $opt */
|
||||||
|
foreach($this->getOptions() as $opt) {
|
||||||
|
if($opt->isSelected()) return $opt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -7,6 +7,7 @@ class Select extends Base
|
|||||||
{
|
{
|
||||||
|
|
||||||
static public $modePaperDb = 'papierdb';
|
static public $modePaperDb = 'papierdb';
|
||||||
|
static public $modeDelivery = 'delivery';
|
||||||
|
|
||||||
static public $modeNone = '';
|
static public $modeNone = '';
|
||||||
|
|
||||||
|
|||||||
103
src/Option/Type/Select/DeliveryOpt.php
Normal file
103
src/Option/Type/Select/DeliveryOpt.php
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
<?php
|
||||||
|
namespace PSC\Library\Calc\Option\Type\Select;
|
||||||
|
|
||||||
|
use PSC\Library\Calc\General\Type\EdgeCollectionContainer;
|
||||||
|
use PSC\Library\Calc\Option\Type\Base;
|
||||||
|
use Yasumi\Yasumi;
|
||||||
|
|
||||||
|
class DeliveryOpt extends Opt
|
||||||
|
{
|
||||||
|
protected ?\DateTime $curDate = null;
|
||||||
|
protected string $info = "";
|
||||||
|
|
||||||
|
protected string $country = "Germany";
|
||||||
|
|
||||||
|
protected string $dateFormat = "d.m.Y";
|
||||||
|
|
||||||
|
protected int $workDays = 5;
|
||||||
|
|
||||||
|
protected int $maxTime = 12;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->curDate = new \DateTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getInfo(): string
|
||||||
|
{
|
||||||
|
return $this->info;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCountry(): string
|
||||||
|
{
|
||||||
|
return $this->country;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDateFormat(): string
|
||||||
|
{
|
||||||
|
return $this->dateFormat;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDateFormat(string $dateFormat)
|
||||||
|
{
|
||||||
|
$this->dateFormat = $dateFormat;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCountry(string $country)
|
||||||
|
{
|
||||||
|
$this->country = $country;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setInfo(string $info)
|
||||||
|
{
|
||||||
|
$this->info = $info;
|
||||||
|
}
|
||||||
|
public function getWorkDays(): int
|
||||||
|
{
|
||||||
|
return $this->workDays;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setWorkDays(int $workDays)
|
||||||
|
{
|
||||||
|
$this->workDays = $workDays;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMaxTime(): int
|
||||||
|
{
|
||||||
|
return $this->maxTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setMaxTime(int $maxTime)
|
||||||
|
{
|
||||||
|
$this->maxTime = $maxTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDeliveryDate(): \DateTime
|
||||||
|
{
|
||||||
|
$holidays = Yasumi::create($this->country, (int) date('Y'));
|
||||||
|
|
||||||
|
$currentHour = (int)$this->curDate->format('H');
|
||||||
|
if($currentHour >= $this->maxTime) {
|
||||||
|
$this->workDays++;
|
||||||
|
}
|
||||||
|
|
||||||
|
while($this->workDays >= 1) {
|
||||||
|
$this->curDate->modify("+1 day");
|
||||||
|
if($holidays->isWorkingDay($this->curDate)) {
|
||||||
|
$this->workDays--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->curDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDeliveryDateAsString(): string
|
||||||
|
{
|
||||||
|
return $this->getDeliveryDate()->format($this->dateFormat);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCurDate(\DateTime $curDate)
|
||||||
|
{
|
||||||
|
$this->curDate = $curDate;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -39,6 +39,5 @@ class CalcTest extends TestCase
|
|||||||
public function testIfDefaultPriceIsOk(): void
|
public function testIfDefaultPriceIsOk(): void
|
||||||
{
|
{
|
||||||
$this->assertEquals(130.97 , $this->engine->getPrice());
|
$this->assertEquals(130.97 , $this->engine->getPrice());
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
65
tests/Customer/W/CalcTest.php
Normal file
65
tests/Customer/W/CalcTest.php
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
<?php
|
||||||
|
namespace PSC\Library\Calc\Tests\Customer\W;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use PSC\Library\Calc\Article;
|
||||||
|
use PSC\Library\Calc\Engine;
|
||||||
|
use PSC\Library\Calc\PaperContainer;
|
||||||
|
use PSC\Library\Calc\Tests\Mock\PaperRepostory;
|
||||||
|
|
||||||
|
class CalcTest extends TestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
/** @var Engine */
|
||||||
|
protected $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.xml'));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function tearDown(): void
|
||||||
|
{
|
||||||
|
$this->engine = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testIfDefaultPriceIsOk(): void
|
||||||
|
{
|
||||||
|
$dateTime = new \DateTime('13:12:12 03.02.2023');
|
||||||
|
$this->engine->getArticle()->getOptionById('versand')->getSelectedOption()->setCurDate($dateTime);
|
||||||
|
self::assertSame('', $this->engine->getArticle()->getOptionById('versand')->getSelectedOption()->getInfo());
|
||||||
|
|
||||||
|
self::assertSame('Germany', $this->engine->getArticle()->getOptionById('versand')->getSelectedOption()->getCountry());
|
||||||
|
|
||||||
|
self::assertSame("08.02.2023", $this->engine->getArticle()->getOptionById('versand')->getSelectedOption()->getDeliveryDateAsString(),
|
||||||
|
'Act: ' . $this->engine->getArticle()->getOptionById('versand')->getSelectedOption()->getDeliveryDateAsString() . ' Exp: '.date('d.m.Y'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testMvWestpomPriceIsOk(): void
|
||||||
|
{
|
||||||
|
$dateTime = new \DateTime('13:12:12 03.02.2023');
|
||||||
|
$this->engine->setVariable('versand', 1);
|
||||||
|
$this->engine->calc();
|
||||||
|
$this->engine->getArticle()->getOptionById('versand')->getSelectedOption()->setCurDate($dateTime);
|
||||||
|
|
||||||
|
self::assertSame('Sofortiger Produktionsbeginn bei Dateneingang und Zahlung bis 18 Uhr.', $this->engine->getArticle()->getOptionById('versand')->getSelectedOption()->getInfo());
|
||||||
|
|
||||||
|
self::assertSame('Germany/MecklenburgWesternPomerania', $this->engine->getArticle()->getOptionById('versand')->getSelectedOption()->getCountry());
|
||||||
|
|
||||||
|
self::assertSame("17.02.2023", $this->engine->getArticle()->getOptionById('versand')->getSelectedOption()->getDeliveryDateAsString(),
|
||||||
|
'Act: ' . $this->engine->getArticle()->getOptionById('versand')->getSelectedOption()->getDeliveryDateAsString() . ' Exp: '.date('d.m.Y'));
|
||||||
|
}
|
||||||
|
}
|
||||||
43
tests/Customer/W/calc.xml
Normal file
43
tests/Customer/W/calc.xml
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<kalkulation>
|
||||||
|
<artikel>
|
||||||
|
<name>SD-Durchschreibesätze A4-Blocks</name>
|
||||||
|
<kommentar>210 mm x 297 mm</kommentar>
|
||||||
|
<uploads>
|
||||||
|
<upload id="neutral" name="Druckdaten" description="Bitte laden sie eine PDF für den Druck hoch"/>
|
||||||
|
</uploads>
|
||||||
|
<!-- Grundinformationen fixe Parameter -->
|
||||||
|
<option id="breite" name="Breite" type="Hidden" default="210"/>
|
||||||
|
<option id="hoehe" name="Höhe" type="Hidden" default="297"/>
|
||||||
|
<!-- Ende Grundinformationen -->
|
||||||
|
<!-- Auflage -->
|
||||||
|
<option id="auflage" name="Auflage" type="Select" default="1000">
|
||||||
|
<opt id="1000" name="1000"/>
|
||||||
|
<opt id="2000" name="2000"/>
|
||||||
|
<opt id="3000" name="3000"/>
|
||||||
|
<opt id="4000" name="4000"/>
|
||||||
|
<opt id="5000" name="5000"/>
|
||||||
|
<opt id="7500" name="7500"/>
|
||||||
|
<opt id="10000" name="10000"/>
|
||||||
|
<opt id="15000" name="15000"/>
|
||||||
|
<opt id="20000" name="20000"/>
|
||||||
|
<opt id="25000" name="25000"/>
|
||||||
|
<opt id="30000" name="30000"/>
|
||||||
|
<opt id="40000" name="40000"/>
|
||||||
|
<opt id="50000" name="50000"/>
|
||||||
|
<opt id="75000" name="75000"/>
|
||||||
|
<opt id="100000" name="100000"/>
|
||||||
|
</option>
|
||||||
|
|
||||||
|
<option id="versand" name="Versand" type="Select" mode="delivery" default="3" help="Wählen Sie die Versandart">
|
||||||
|
<opt id="1" name="Standard zzgl. € 0,00" workDays="10" country="Germany/MecklenburgWesternPomerania" maxTime="18" info="Sofortiger Produktionsbeginn bei Dateneingang und Zahlung bis 18 Uhr." dateFormat="d.m.Y">
|
||||||
|
</opt>
|
||||||
|
<opt id="2" name="Express zzgl. 20%" workDays="5" country="Germany" maxTime="12" info="Sofortiger Produktionsbeginn bei Dateneingang und Zahlung bis 12 Uhr." dateFormat="Y-m-d">
|
||||||
|
</opt>
|
||||||
|
<opt id="3" name="default" workDays="2" maxTime="12">
|
||||||
|
</opt>
|
||||||
|
</option>
|
||||||
|
<!-- BLOCK ENDE-->
|
||||||
|
|
||||||
|
</artikel>
|
||||||
|
</kalkulation>
|
||||||
2
tests/Customer/W/calcTemplates.xml
Normal file
2
tests/Customer/W/calcTemplates.xml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
<root>
|
||||||
|
</root>
|
||||||
0
tests/Customer/W/formels.txt
Normal file
0
tests/Customer/W/formels.txt
Normal file
6
tests/Customer/W/papierContainer.xml
Normal file
6
tests/Customer/W/papierContainer.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<container>
|
||||||
|
<papiercontainer id="karten_reduziert">
|
||||||
|
<papier id="sm300g"/>
|
||||||
|
</papiercontainer>
|
||||||
|
</container>
|
||||||
0
tests/Customer/W/parameters.txt
Normal file
0
tests/Customer/W/parameters.txt
Normal file
Loading…
Reference in New Issue
Block a user