<?php
 namespace App\ImportedOrder; class Supplier extends EntityAbstract { public $idTina; public $idSystem; public $name; public ?array $codes = null; public $fiscalCode; protected function getMergingFields() :array { return [ 'idTina', 'idSystem', 'name', 'codes', 'fiscalCode' ]; } public function addCode($code, $value) { $this->codes[$code] = $value; } protected function validateEntityFields(\App\MessagesCollector $messagesCollector): void { if ( $this->idTina and (!is_numeric($this->idTina) or $this->idTina<0) ) { $messagesCollector->addInfo('The TINA id is invalid - it should be a positive integer.'); } if ($this->codes) { $CFG = \Engine\Loader_Cfg::getInstance()->getGlobal(); foreach ($this->codes as $code=>$val) { if (!$CFG['travel']['standardCodes'][$code]) { $messagesCollector->addInfo("The code type `{$code}` is invalid / not configured."); } } } } public function getPopulatedMatchObject($idExternalSystem) { $CFG = \Engine\Loader_Cfg::getInstance()->getGlobal(); $matchObj = new \App\ImportedOrder\EntityMatch\Supplier('intersect'); if ($this->idTina) { $matchObj->setId($this->idTina); } if ($idExternalSystem and $this->idSystem) { $matchObj->setIdInExtSys(htmlClean($this->idSystem), $idExternalSystem); } if ($this->fiscalCode) { $matchObj->setFiscalCode(htmlClean($this->fiscalCode)); } if ($this->name) { $matchObj->setAlias(htmlClean($this->name), true); } if ($this->codes) { foreach($this->codes as $codeName=>$codeValue) { if ($CFG['travel']['standardCodes'][$codeName] and $codeValue) { $matchObj->setCode($codeValue, $codeName); } } } return $matchObj; } public function getMatchedId($idExternalSystem) { $matchObj = $this->getPopulatedMatchObject($idExternalSystem); $matchObj->search(); if ($matchObj->getResultsCount()==1) { return $matchObj->getFirstMatchId(); } return 0; } }