| @@ -1,6 +1,8 @@ | |||||
| <?php | <?php | ||||
| namespace App\Command; | namespace App\Command; | ||||
| use App\Entity\DinAsset; | |||||
| use App\Entity\DinAssetBenchmark; | |||||
| use Doctrine\ORM\EntityManagerInterface; | use Doctrine\ORM\EntityManagerInterface; | ||||
| use PhpOffice\PhpSpreadsheet\IOFactory; | use PhpOffice\PhpSpreadsheet\IOFactory; | ||||
| use Psr\Container\ContainerInterface; | use Psr\Container\ContainerInterface; | ||||
| @@ -54,24 +56,60 @@ class CmdImportBenchmark extends Command | |||||
| return Command::FAILURE; | return Command::FAILURE; | ||||
| } | } | ||||
| $worksheetData = []; | |||||
| $this->em->getConnection()->beginTransaction(); | |||||
| $highestRow = $worksheet->getHighestRow(); | |||||
| $highestColumn = $worksheet->getHighestColumn(); | |||||
| try { | |||||
| $this->em->createQuery('DELETE FROM App\Entity\DinAssetBenchmark')->execute(); | |||||
| $dinAssetsByDinAndName = []; | |||||
| $dinAssets = $this->em->getRepository(DinAsset::class)->findAll(); | |||||
| /** @var DinAsset $dinAsset */ | |||||
| foreach ($dinAssets as $dinAsset) { | |||||
| $dinAssetsByDinAndName[$dinAsset->getDinNumber().$dinAsset->getName()] = $dinAsset; | |||||
| } | |||||
| $highestRow = $worksheet->getHighestRow(); | |||||
| $highestColumn = $worksheet->getHighestColumn(); | |||||
| $startRow = 2; | |||||
| $startCol = 'A'; | |||||
| for ($row = $startRow; $row <= $highestRow; $row++) { | |||||
| $rowData = []; | |||||
| for ($col = $startCol; $col <= $highestColumn; $col++) { | |||||
| $cell = $worksheet->getCell($col . $row); | |||||
| $rowData[] = $cell->getValue(); | |||||
| } | |||||
| $dinNumber = $rowData[0]; | |||||
| $name = $rowData[5]; | |||||
| $key = $dinNumber.$name; | |||||
| if (!array_key_exists($key, $dinAssetsByDinAndName)) { | |||||
| $output->writeln("No din asset found: ". $key); | |||||
| } else { | |||||
| /** @var DinAsset $dinAsset */ | |||||
| $dinAsset = $dinAssetsByDinAndName[$key]; | |||||
| $dinBenchmark = new DinAssetBenchmark(); | |||||
| $dinBenchmark->setDinAsset($dinAsset); | |||||
| $dinBenchmark->setComponent($rowData[7]); | |||||
| $dinBenchmark->setType($rowData[9]); | |||||
| $dinBenchmark->setBandwidth($rowData[11]); | |||||
| $dinBenchmark->setDeviation($rowData[16]); | |||||
| $dinBenchmark->setAverageCosts($rowData[17]); | |||||
| $dinBenchmark->setMinAverageCosts($rowData[18]); | |||||
| $dinBenchmark->setMaxAverageCosts($rowData[19]); | |||||
| $startRow = 2; | |||||
| $startCol = 'A'; | |||||
| for ($row = $startRow; $row <= $highestRow; $row++) { | |||||
| $rowData = []; | |||||
| for ($col = $startCol; $col <= $highestColumn; $col++) { | |||||
| $cell = $worksheet->getCell($col . $row); | |||||
| $rowData[] = $cell->getValue(); | |||||
| $this->em->persist($dinBenchmark); | |||||
| } | |||||
| } | } | ||||
| $worksheetData[] = $rowData; | |||||
| $this->em->flush(); | |||||
| $this->em->getConnection()->commit(); | |||||
| } catch (\Exception $e) { | |||||
| $this->em->getConnection()->rollBack(); | |||||
| } | } | ||||
| $a = 0; | |||||
| return Command::SUCCESS; | return Command::SUCCESS; | ||||
| } | } | ||||
| @@ -50,7 +50,6 @@ class CmdImportDinAssets extends Command | |||||
| $reader->setReadDataOnly(true); | $reader->setReadDataOnly(true); | ||||
| $spreadsheet = $reader->load($excelFile); | $spreadsheet = $reader->load($excelFile); | ||||
| /** @var Connection $con */ | |||||
| $this->em->getConnection()->beginTransaction(); | $this->em->getConnection()->beginTransaction(); | ||||
| try { | try { | ||||
| @@ -66,7 +65,6 @@ class CmdImportDinAssets extends Command | |||||
| $isDinWorksheet = $dinNumber >= 100 && $dinNumber < 1000; | $isDinWorksheet = $dinNumber >= 100 && $dinNumber < 1000; | ||||
| if ($isDinWorksheet) { | if ($isDinWorksheet) { | ||||
| $worksheetData = []; | |||||
| $highestRow = $worksheet->getHighestRow(); | $highestRow = $worksheet->getHighestRow(); | ||||
| $highestColumn = $worksheet->getHighestColumn(); | $highestColumn = $worksheet->getHighestColumn(); | ||||
| @@ -92,6 +90,9 @@ class CmdImportDinAssets extends Command | |||||
| $dinAsset = new DinAsset(); | $dinAsset = new DinAsset(); | ||||
| $dinAsset->setDinNumber($rowData[0]); | $dinAsset->setDinNumber($rowData[0]); | ||||
| $dinAsset->setName($rowData[1]); | $dinAsset->setName($rowData[1]); | ||||
| $dinAsset->setCycleMonthsMin($rowData[11]); | |||||
| $dinAsset->setCycleMonthsMax($rowData[12]); | |||||
| $dinAsset->setCycleMonthsRecommended($rowData[13]); | |||||
| $this->em->persist($dinAsset); | $this->em->persist($dinAsset); | ||||
| $this->em->flush(); | $this->em->flush(); | ||||
| $dinAssetsByDinAndName[$key] = $dinAsset; | $dinAssetsByDinAndName[$key] = $dinAsset; | ||||
| @@ -108,12 +109,7 @@ class CmdImportDinAssets extends Command | |||||
| $dinAssetTask->setSpecialist($rowData[8] !== null); | $dinAssetTask->setSpecialist($rowData[8] !== null); | ||||
| $dinAssetTask->setSkilledPersonnel($rowData[9] !== null); | $dinAssetTask->setSkilledPersonnel($rowData[9] !== null); | ||||
| $dinAssetTask->setNorm($rowData[10]); | $dinAssetTask->setNorm($rowData[10]); | ||||
| $dinAssetTask->setMinMonths($rowData[11]); | |||||
| $dinAssetTask->setMaxMonths($rowData[12]); | |||||
| $dinAssetTask->setMonthRecommendedInspection($rowData[13]); | |||||
| $dinAssetTask->setMonthRecommendedMaintenance($rowData[14]); | |||||
| $this->em->persist($dinAssetTask); | $this->em->persist($dinAssetTask); | ||||
| $this->em->flush(); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -10,6 +10,7 @@ namespace App\Controller; | |||||
| use App\Entity\Catalogue; | use App\Entity\Catalogue; | ||||
| use App\Entity\CatalogueDetail; | use App\Entity\CatalogueDetail; | ||||
| use App\Entity\DinAsset; | use App\Entity\DinAsset; | ||||
| use App\Entity\DinAssetBenchmark; | |||||
| use App\Entity\User; | use App\Entity\User; | ||||
| use App\Repository\UserRepository; | use App\Repository\UserRepository; | ||||
| use App\Utils\Utils; | use App\Utils\Utils; | ||||
| @@ -67,9 +68,28 @@ class UserController extends AbstractController | |||||
| $user = $this->getUser(); | $user = $this->getUser(); | ||||
| $dinAssets = $em->getRepository(DinAsset::class)->findAll(); | $dinAssets = $em->getRepository(DinAsset::class)->findAll(); | ||||
| /** @var DinAsset $initialDinAsset */ | |||||
| $initialDinAsset = null; | |||||
| $benchmarkValues = []; | |||||
| if (count($dinAssets) > 0) { | |||||
| $initialDinAsset = $dinAssets[0]; | |||||
| $benchmarks = $initialDinAsset->getBenchmarks(); | |||||
| /** @var DinAssetBenchmark $benchmark */ | |||||
| foreach ($benchmarks as $benchmark) { | |||||
| $value = $benchmark->getComponent() ? $benchmark->getComponent() . " | " : ""; | |||||
| $value.= $benchmark->getType() ? $benchmark->getType() . " | " : ""; | |||||
| $value.= $benchmark->getBandwidth() ? $benchmark->getBandwidth() . " | " : ""; | |||||
| if (substr($value, -3) === " | ") { | |||||
| $value = rtrim($value, " | "); | |||||
| } | |||||
| $benchmarkValues[$benchmark->getId()] = $value; | |||||
| } | |||||
| } | |||||
| return $this->render('pages/risk_analysis.html.twig', | return $this->render('pages/risk_analysis.html.twig', | ||||
| [ | [ | ||||
| 'initialDinAsset' => $initialDinAsset, | |||||
| 'benchmarkValues' => $benchmarkValues, | |||||
| 'dinAssets' => $dinAssets, | 'dinAssets' => $dinAssets, | ||||
| 'riskFailure' => Utils::$riskFailure, | 'riskFailure' => Utils::$riskFailure, | ||||
| 'riskCosts' => Utils::$riskCosts, | 'riskCosts' => Utils::$riskCosts, | ||||
| @@ -27,11 +27,31 @@ class DinAsset | |||||
| */ | */ | ||||
| protected $name; | protected $name; | ||||
| /** | |||||
| * @ORM\Column(type="smallint", nullable=false, options={"unsigned" = true}) | |||||
| */ | |||||
| protected $cycleMonthsMin; | |||||
| /** | |||||
| * @ORM\Column(type="smallint", nullable=false, options={"unsigned" = true}) | |||||
| */ | |||||
| protected $cycleMonthsMax; | |||||
| /** | |||||
| * @ORM\Column(type="smallint", nullable=false, options={"unsigned" = true}) | |||||
| */ | |||||
| protected $cycleMonthsRecommended; | |||||
| /** | /** | ||||
| * @ORM\OneToMany(targetEntity="DinAssetTask", mappedBy="dinAsset", cascade={"persist", "remove"}) | * @ORM\OneToMany(targetEntity="DinAssetTask", mappedBy="dinAsset", cascade={"persist", "remove"}) | ||||
| */ | */ | ||||
| private $tasks; | private $tasks; | ||||
| /** | |||||
| * @ORM\OneToMany(targetEntity="DinAssetBenchmark", mappedBy="dinAsset", cascade={"persist", "remove"}) | |||||
| */ | |||||
| private $benchmarks; | |||||
| /** | /** | ||||
| * @return mixed | * @return mixed | ||||
| */ | */ | ||||
| @@ -80,6 +100,54 @@ class DinAsset | |||||
| $this->name = $name; | $this->name = $name; | ||||
| } | } | ||||
| /** | |||||
| * @return mixed | |||||
| */ | |||||
| public function getCycleMonthsMin() | |||||
| { | |||||
| return $this->cycleMonthsMin; | |||||
| } | |||||
| /** | |||||
| * @param mixed $cycleMonthsMin | |||||
| */ | |||||
| public function setCycleMonthsMin($cycleMonthsMin): void | |||||
| { | |||||
| $this->cycleMonthsMin = $cycleMonthsMin; | |||||
| } | |||||
| /** | |||||
| * @return mixed | |||||
| */ | |||||
| public function getCycleMonthsMax() | |||||
| { | |||||
| return $this->cycleMonthsMax; | |||||
| } | |||||
| /** | |||||
| * @param mixed $cycleMonthsMax | |||||
| */ | |||||
| public function setCycleMonthsMax($cycleMonthsMax): void | |||||
| { | |||||
| $this->cycleMonthsMax = $cycleMonthsMax; | |||||
| } | |||||
| /** | |||||
| * @return mixed | |||||
| */ | |||||
| public function getCycleMonthsRecommended() | |||||
| { | |||||
| return $this->cycleMonthsRecommended; | |||||
| } | |||||
| /** | |||||
| * @param mixed $cycleMonthsRecommended | |||||
| */ | |||||
| public function setCycleMonthsRecommended($cycleMonthsRecommended): void | |||||
| { | |||||
| $this->cycleMonthsRecommended = $cycleMonthsRecommended; | |||||
| } | |||||
| /** | /** | ||||
| * @return mixed | * @return mixed | ||||
| */ | */ | ||||
| @@ -97,10 +165,19 @@ class DinAsset | |||||
| } | } | ||||
| /** | /** | ||||
| * @param mixed $task | |||||
| * @return mixed | |||||
| */ | */ | ||||
| public function addTask($task): void | |||||
| public function getBenchmarks() | |||||
| { | { | ||||
| $this->tasks[] = $task; | |||||
| return $this->benchmarks; | |||||
| } | } | ||||
| /** | |||||
| * @param mixed $benchmarks | |||||
| */ | |||||
| public function setBenchmarks($benchmarks): void | |||||
| { | |||||
| $this->benchmarks = $benchmarks; | |||||
| } | |||||
| } | } | ||||
| @@ -0,0 +1,198 @@ | |||||
| <?php | |||||
| namespace App\Entity; | |||||
| use Doctrine\ORM\Mapping as ORM; | |||||
| /** | |||||
| * @ORM\Entity | |||||
| * @ORM\Table(name="din_asset_benchmark") | |||||
| */ | |||||
| class DinAssetBenchmark | |||||
| { | |||||
| /** | |||||
| * @ORM\Id() | |||||
| * @ORM\GeneratedValue() | |||||
| * @ORM\Column(type="integer") | |||||
| */ | |||||
| protected $id; | |||||
| /** | |||||
| * @ORM\ManyToOne(targetEntity="DinAsset", inversedBy="tasks") | |||||
| * @ORM\JoinColumn(name="din_asset_id", referencedColumnName="id", onDelete="SET NULL") | |||||
| */ | |||||
| protected $dinAsset; | |||||
| /** | |||||
| * @ORM\Column(type="string", nullable=true) | |||||
| */ | |||||
| protected $component; | |||||
| /** | |||||
| * @ORM\Column(type="string", nullable=true) | |||||
| */ | |||||
| protected $type; | |||||
| /** | |||||
| * @ORM\Column(type="string", nullable=true) | |||||
| */ | |||||
| protected $bandwidth; | |||||
| /** | |||||
| * @ORM\Column(type="decimal", precision=10, scale=2)) | |||||
| */ | |||||
| protected $deviation; | |||||
| /** | |||||
| * @ORM\Column(type="decimal", precision=10, scale=2)) | |||||
| */ | |||||
| protected $average_costs; | |||||
| /** | |||||
| * @ORM\Column(type="decimal", precision=10, scale=2)) | |||||
| */ | |||||
| protected $min_average_costs; | |||||
| /** | |||||
| * @ORM\Column(type="decimal", precision=10, scale=2)) | |||||
| */ | |||||
| protected $max_average_costs; | |||||
| /** | |||||
| * @return mixed | |||||
| */ | |||||
| public function getId() | |||||
| { | |||||
| return $this->id; | |||||
| } | |||||
| /** | |||||
| * @return mixed | |||||
| */ | |||||
| public function getDinAsset() | |||||
| { | |||||
| return $this->dinAsset; | |||||
| } | |||||
| /** | |||||
| * @param mixed $dinAsset | |||||
| */ | |||||
| public function setDinAsset($dinAsset): void | |||||
| { | |||||
| $this->dinAsset = $dinAsset; | |||||
| } | |||||
| /** | |||||
| * @return mixed | |||||
| */ | |||||
| public function getComponent() | |||||
| { | |||||
| return $this->component; | |||||
| } | |||||
| /** | |||||
| * @param mixed $component | |||||
| */ | |||||
| public function setComponent($component): void | |||||
| { | |||||
| $this->component = $component; | |||||
| } | |||||
| /** | |||||
| * @return mixed | |||||
| */ | |||||
| public function getType() | |||||
| { | |||||
| return $this->type; | |||||
| } | |||||
| /** | |||||
| * @param mixed $type | |||||
| */ | |||||
| public function setType($type): void | |||||
| { | |||||
| $this->type = $type; | |||||
| } | |||||
| /** | |||||
| * @return mixed | |||||
| */ | |||||
| public function getBandwidth() | |||||
| { | |||||
| return $this->bandwidth; | |||||
| } | |||||
| /** | |||||
| * @param mixed $bandwidth | |||||
| */ | |||||
| public function setBandwidth($bandwidth): void | |||||
| { | |||||
| $this->bandwidth = $bandwidth; | |||||
| } | |||||
| /** | |||||
| * @return mixed | |||||
| */ | |||||
| public function getDeviation() | |||||
| { | |||||
| return $this->deviation; | |||||
| } | |||||
| /** | |||||
| * @param mixed $deviation | |||||
| */ | |||||
| public function setDeviation($deviation): void | |||||
| { | |||||
| $this->deviation = $deviation; | |||||
| } | |||||
| /** | |||||
| * @return mixed | |||||
| */ | |||||
| public function getAverageCosts() | |||||
| { | |||||
| return $this->average_costs; | |||||
| } | |||||
| /** | |||||
| * @param mixed $average_costs | |||||
| */ | |||||
| public function setAverageCosts($average_costs): void | |||||
| { | |||||
| $this->average_costs = $average_costs; | |||||
| } | |||||
| /** | |||||
| * @return mixed | |||||
| */ | |||||
| public function getMinAverageCosts() | |||||
| { | |||||
| return $this->min_average_costs; | |||||
| } | |||||
| /** | |||||
| * @param mixed $min_average_costs | |||||
| */ | |||||
| public function setMinAverageCosts($min_average_costs): void | |||||
| { | |||||
| $this->min_average_costs = $min_average_costs; | |||||
| } | |||||
| /** | |||||
| * @return mixed | |||||
| */ | |||||
| public function getMaxAverageCosts() | |||||
| { | |||||
| return $this->max_average_costs; | |||||
| } | |||||
| /** | |||||
| * @param mixed $max_average_costs | |||||
| */ | |||||
| public function setMaxAverageCosts($max_average_costs): void | |||||
| { | |||||
| $this->max_average_costs = $max_average_costs; | |||||
| } | |||||
| } | |||||
| @@ -72,26 +72,6 @@ class DinAssetTask | |||||
| */ | */ | ||||
| protected $norm; | protected $norm; | ||||
| /** | |||||
| * @ORM\Column(type="smallint", nullable=false, options={"unsigned" = true}) | |||||
| */ | |||||
| protected $minMonths; | |||||
| /** | |||||
| * @ORM\Column(type="smallint", nullable=false, options={"unsigned" = true}) | |||||
| */ | |||||
| protected $maxMonths; | |||||
| /** | |||||
| * @ORM\Column(type="smallint", nullable=false, options={"unsigned" = true}) | |||||
| */ | |||||
| protected $monthRecommendedInspection; | |||||
| /** | |||||
| * @ORM\Column(type="smallint", nullable=false, options={"unsigned" = true}) | |||||
| */ | |||||
| protected $monthRecommendedMaintenance; | |||||
| /** | /** | ||||
| * @return mixed | * @return mixed | ||||
| */ | */ | ||||
| @@ -260,69 +240,4 @@ class DinAssetTask | |||||
| $this->norm = $norm; | $this->norm = $norm; | ||||
| } | } | ||||
| /** | |||||
| * @return mixed | |||||
| */ | |||||
| public function getMinMonths() | |||||
| { | |||||
| return $this->minMonths; | |||||
| } | |||||
| /** | |||||
| * @param mixed $minMonths | |||||
| */ | |||||
| public function setMinMonths($minMonths): void | |||||
| { | |||||
| $this->minMonths = $minMonths; | |||||
| } | |||||
| /** | |||||
| * @return mixed | |||||
| */ | |||||
| public function getMaxMonths() | |||||
| { | |||||
| return $this->maxMonths; | |||||
| } | |||||
| /** | |||||
| * @param mixed $maxMonths | |||||
| */ | |||||
| public function setMaxMonths($maxMonths): void | |||||
| { | |||||
| $this->maxMonths = $maxMonths; | |||||
| } | |||||
| /** | |||||
| * @return mixed | |||||
| */ | |||||
| public function getMonthRecommendedInspection() | |||||
| { | |||||
| return $this->monthRecommendedInspection; | |||||
| } | |||||
| /** | |||||
| * @param mixed $monthRecommendedInspection | |||||
| */ | |||||
| public function setMonthRecommendedInspection($monthRecommendedInspection): void | |||||
| { | |||||
| $this->monthRecommendedInspection = $monthRecommendedInspection; | |||||
| } | |||||
| /** | |||||
| * @return mixed | |||||
| */ | |||||
| public function getMonthRecommendedMaintenance() | |||||
| { | |||||
| return $this->monthRecommendedMaintenance; | |||||
| } | |||||
| /** | |||||
| * @param mixed $monthRecommendedMaintenance | |||||
| */ | |||||
| public function setMonthRecommendedMaintenance($monthRecommendedMaintenance): void | |||||
| { | |||||
| $this->monthRecommendedMaintenance = $monthRecommendedMaintenance; | |||||
| } | |||||
| } | } | ||||
| @@ -44,10 +44,19 @@ | |||||
| <option value="0">Nein</option> | <option value="0">Nein</option> | ||||
| <option value="1">Ja</option> | <option value="1">Ja</option> | ||||
| </select> | </select> | ||||
| <label for="cycle">Genügt eine einfache Sichtkontrolle im Rahmen des regelmäßigen Rundgangs?</label> | |||||
| <input name="cycle" type="number" disabled> | |||||
| <label for="bandwidth">Genügt eine einfache Sichtkontrolle im Rahmen des regelmäßigen Rundgangs?</label> | |||||
| <select name="bandwidth" id="bandwidth" disabled> | |||||
| </select> | |||||
| <label for="cycle">Aktueller Zyklus (in Monaten)</label> | |||||
| {% if initialDinAsset is not null %} | |||||
| <input name="cycle" type="number" value="{{ initialDinAsset.cycleMonthsRecommended }}" min="{{ initialDinAsset.cycleMonthsMin }}" max ="{{ initialDinAsset.cycleMonthsMax }}"> | |||||
| {% else %} | |||||
| <input name="cycle" type="number" disabled> | |||||
| {% endif %} | |||||
| <label for="bandwidth">Bandbreite Anlage</label> | |||||
| <select name="bandwidth" id="bandwidth"> | |||||
| {% for key, benchmarkValue in benchmarkValues %} | |||||
| <option value="{{ key }}">{{ benchmarkValue }}</option> | |||||
| {% endfor %} | |||||
| </select> | |||||
| </form> | </form> | ||||
| {% endblock %} | {% endblock %} | ||||