From 987a2cd5a9021e39f54025356363a93eafe0469c Mon Sep 17 00:00:00 2001 From: Thomas Peterson Date: Thu, 19 May 2022 20:27:01 +0200 Subject: [PATCH] Add Debug Vars --- src/Calc/Calc.php | 4 ++++ src/Calc/CalcValues.php | 5 +++-- src/Engine.php | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/Calc/Calc.php b/src/Calc/Calc.php index 426a7bb..a2d6ad2 100644 --- a/src/Calc/Calc.php +++ b/src/Calc/Calc.php @@ -106,16 +106,20 @@ class Calc if($edge->getPauschale() != 0) { eval('$gesamt += ' . $edge->getPauschale() . ';'); + $this->engine->addDebugFlatPrice($collection->getName(), $edge->getPauschale()); } if($edge->getPreis() != 0) { eval('$gesamt += ' . ($edge->getPreis()*$var) . ';'); + $this->engine->addDebugPrice($collection->getName(), $edge->getPreis(), $var, $edge->getPreis()*$var); } if($edge->getCalcValue() != "") { $cv = $this->formelCalc->parse($edge->getCalcValue()); + $orgCv = $cv; try { eval('@$cv = ' . $cv . ';'); + $this->engine->addDebugCalcVariables($option->getId() . '_' . $collection->getName(), $edge->getCalcValue(), $orgCv . ' = ' . $cv); }catch (\Throwable $e) { $cv = 0; } diff --git a/src/Calc/CalcValues.php b/src/Calc/CalcValues.php index 6ebff57..22d3dd7 100644 --- a/src/Calc/CalcValues.php +++ b/src/Calc/CalcValues.php @@ -115,11 +115,12 @@ class CalcValues if ($edge->getCalcValue() != "") { $cv = $this->formelCalc->parse($edge->getCalcValue()); + $orgCv = $cv; try { eval('@$cv = ' . $cv . ';'); - $this->engine->addDebugCalcVariables($id, $edge->getCalcValue(), $cv . ' = ' . $cv); + $this->engine->addDebugCalcVariables($id, $edge->getCalcValue(), $orgCv . ' = ' . $cv); }catch (\Throwable $e) { - $this->engine->addDebugCalcVariables($id, $edge->getCalcValue(), $cv . ' = ERROR'); + $this->engine->addDebugCalcVariables($id, $edge->getCalcValue(), $orgCv . ' = ERROR'); $cv = 0; } diff --git a/src/Engine.php b/src/Engine.php index 94b079e..20238b5 100644 --- a/src/Engine.php +++ b/src/Engine.php @@ -50,6 +50,9 @@ class Engine /** @var array */ protected $debugCalcVariables = array(); + protected $debugFlatPrice = array(); + + protected $debugPrice = array(); /** @var float */ protected $price = 0; @@ -351,6 +354,36 @@ class Engine { return $this->debugCalcFormel; } + + public function addDebugFlatPrice($key, $flatPrice) + { + if(!isset($this->debugFlatPrice[$key])) { + $this->debugFlatPrice[$key] = array(); + } + $this->debugFlatPrice[$key][] = $flatPrice; + } + + public function getDebugFlatPrice() + { + return $this->debugFlatPrice; + } + + public function addDebugPrice($key, $price, $multiplicator, $result) + { + if(!isset($this->debugPrice[$key])) { + $this->debugPrice[$key] = array(); + } + $this->debugPrice[$key][] = [ + 'price' => $price, + 'multiplicator' => $multiplicator, + 'result' => $result + ]; + } + + public function getDebugPrice() + { + return $this->debugPrice; + } /** * @return array */