Import angepasst
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
dotworker
2023-02-24 09:17:56 +01:00
parent f0aa2ac5d5
commit 101f3652c5
10 changed files with 238 additions and 119 deletions

View File

@@ -7,20 +7,28 @@ use App\Entity\Product;
use App\Entity\Stock;
use App\Entity\Warehouse;
use App\Repository\ProductRepository;
use App\Repository\StockRepository;
use App\Repository\WarehouseRepository;
use Psr\Log\LoggerInterface;
use Symfony\Component\Finder\Finder;
class HiltesImport
{
private $productRepository;
private $stockRepository;
private $warehouseRepository;
private $logger;
protected $currentDirPath;
protected $cachedWarehouseIds;
private $cachedProdIds;
private $cachedStockIds;
protected $arrData = array();
public function __construct(ProductRepository $productRepository, LoggerInterface $logger)
public function __construct(ProductRepository $productRepository,WarehouseRepository $warehouseRepository,StockRepository $stockRepository, LoggerInterface $logger)
{
$this->productRepository = $productRepository;
$this->warehouseRepository = $warehouseRepository;
$this->stockRepository = $stockRepository;
$this->logger = $logger;
$this->currentDirPath = getcwd();
@@ -34,6 +42,8 @@ class HiltesImport
{
#*** Holt alle Dateien
if($this->getFiles()){
#*** Holt Alle Stocks und setzt ein Array **************
$this->getStocks();
if(!empty($this->arrData['orgFiles']['data']) && count($this->arrData['orgFiles']['data'])){
foreach ($this->arrData['orgFiles']['data'] as $file) {
if(is_file($file['realPath'])){
@@ -46,7 +56,7 @@ class HiltesImport
}else
return array('success'=>1,'text'=>'No Files');
}else
return array('error'=>1,'text'=>'Error in getFiles');
return array('error'=>1,'text'=>'Error in getFiles or no file WS.FERTIG');
}
/**
@@ -61,10 +71,14 @@ class HiltesImport
#->filter(static function (SplFileInfo $file) {
# return $file->isDir() || \preg_match('/\.(php|json)$/', $file->getPathname());
#});
$hasFoundFertigFile = false;
if ($finder->hasResults()) {
dump($finder);
#dump($finder);
foreach ($finder as $file) {
if($file->getRelativePathname()=='WS.FERTIG'){
$hasFoundFertigFile = true;
continue;
}
$this->arrData['orgFiles']['data'][] = array(
'realPath' => $file->getRealPath(),
'fileSize' => $file->getFileInfo()->getSize(),
@@ -75,16 +89,25 @@ class HiltesImport
return false;
}
return true;
return $hasFoundFertigFile;
}
protected function getStocks()
{
$r = $this->stockRepository->findAll();
foreach ($r as $v) {
$this->cachedStockIds[$v->getProductId()][$v->getWarehouse()->getId()] = $v;
}
#dd($this->cachedStockIds);
}
protected function loadFiles($srcFile,$size)
{
#*** Check File ****
#dd($srcFile);
$file = new \SplFileObject($srcFile);
dump($file->getRealPath());
#dump($file->getRealPath());
$this->logger->info('Starte Import von ' . $file->getRealPath());
dump('Starte Import von ' . $file->getRealPath());
$c = 0;
while (!$file->eof()) {
// Header überspringen
@@ -119,52 +142,6 @@ class HiltesImport
#*** Leerzeichen löschen bei den einzelnen Einträgen **********
$this->trimArray($arr);
#***
// $arr[0] = strtolower($arr[0]);
// switch ($arr[0]){
// case 'datei': # Datei
// $this->saveInfoDatei($arr);
// break;
// case 'filiale': # Filiale
// #$this->saveInfoFiliale($arr);
// break;
// case 'land': # Länder
// $this->saveInfoLand($arr);
// break;
// case 'hwg': # Hauptwarengruppe
// #$this->saveInfoHauptWarenGruppe($arr);
// break;
// case 'wg': # Warengruppe
// #$this->saveInfoWarenGruppe($arr);
// break;
// case 'anrede': # Anrede
// #$this->saveInfoAnrede($arr);
// break;
// case 'lieferant': # Lieferant
// #$this->saveInfoLieferant($arr);
// break;
// case 'farb': # Farbcodierung
// #$this->saveInfoFarbCodierung($arr);
// break;
// case 'nlart': # NachlassArt
// #$this->saveInfoNachlassArt($arr);
// break;
// case 'kollektion': # Kollektion
// #$this->saveInfoKollektion($arr);
// break;
// case 'bestand': # Bestand
// #$this->saveInfoBestand($arr);
// break;
// case 'merkmale': # Made In XXXX = Land
// #$this->saveInfoMerkmale($arr);
// break;
// case 'material': # MAterial
// #$this->saveInfoMaterial($arr);
// break;
// default: #
// dump('!!!!! KEIN DEFINIERTER ANFANG "'.$arr[0].'" !!!!!!!!!');
// break;
// }
$this->saveData($arr);
}
@@ -182,28 +159,27 @@ class HiltesImport
*/
protected function saveData(Array $arr){
#dump($arr);
$prod = new Product();
$stock = new Stock();
#*** Speichert und/oder Holt WareHouse ab
$wareHouse = $this->checkWareHouseName($arr[0]);
#*** PRodukt wird angelegt oder geholt ****
#filiale;etikettnr;menge;modellnr;modellbez
$prodId = $this->checkProduct($arr[1],$arr[3],$arr[4]);
#*** Ermitteln ob schon ein ID vorhadnen für ProdId und WareHouseId
if(!empty($wareHouse) && !empty($this->cachedStockIds[$prodId][$wareHouse->getId()])){
$stock = $this->cachedStockIds[$prodId][$wareHouse->getId()];
#dd('JAAAAA');
}else{
$stock = new Stock();
$stock->setProductId($prodId);
$stock->setWarehouse($wareHouse);
}
#dd('CHCEK');
$stock->setInstock((int)$arr[2]);
#$stock->setWarehouseId($wareHouseId);
#dump($stock);
$this->stockRepository->save($stock,true);
$warehouse = new Warehouse();
$warehouse->setName($arr[0]);
// $stock->setWarehouse($warehouse);
#menge;
$prod->setStock($stock);
#eanzuIdent;
$prod->setGtin($arr[13]);
$prod->setShopwareId("");
// dump($prod);
$this->productRepository->save($prod,true);
#dd($stock);
//$stock->setStock((int)$arr[2]);
#filiale;
@@ -236,28 +212,53 @@ class HiltesImport
}
/**
* @param $id
* @return mixed
*/
private function getWarehouseId($id){
$warehouse = $this->warehouseRepository->findOneBy(array('id'=>$id));
if($warehouse instanceof Warehouse){
return $warehouse->getId();
}else{
$warehouse = new Warehouse();
$warehouse->setPriority(0);
$warehouse->setId($this->warehouseRepository->add($warehouse, true));
dump($warehouse);
return $warehouse;
}
}
private function checkWareHouseName(string $wareHouseName){
#*** WEnn keine geCached Id Vorhanden
$warehouse2 = false;
if(empty($this->cachedWarehouseIds[$wareHouseName])){
#*** Check
$warehouse2 = $this->warehouseRepository->findOneBy(['id'=> (int)$wareHouseName]);
#dump($warehouse2);
if(empty($warehouse2)){
$warehouse = new Warehouse();
$warehouse->setId((int)$wareHouseName);
$warehouse->setName($wareHouseName);
#
$this->warehouseRepository->save($warehouse,true);
#*****************
$warehouse2 = $this->warehouseRepository->findOneBy(['id'=> (int)$wareHouseName]);
#dump($warehouse2);
}
$this->cachedWarehouseIds[$wareHouseName] = $warehouse2;
}
if(!empty($this->cachedWarehouseIds[$wareHouseName]))
return $this->cachedWarehouseIds[$wareHouseName];
return false;
}
private function checkProduct(string $gtin,string $modellNr,string $modellBez){
#*** WEnn keine geCached Id Vorhanden
if(empty($this->cachedProdIds[$gtin])){
#*** Check
$prod2 = $this->productRepository->findOneBy(['gtin'=> $gtin]);
#dump($warehouse2);
if(empty($prod2)){
$prod = new Product();
$prod->setGtin($gtin);
$prod->setModellNr($modellNr);
$prod->setModellBez($modellBez);
$prod->setShopwareId("");
#
$this->productRepository->save($prod,true);
#*****************
$prod2 = $this->productRepository->findOneBy(['gtin'=> $gtin]);
#dump($warehouse2);
}
$this->cachedProdIds[$gtin] = $prod2->getId();
}
if(!empty($this->cachedProdIds[$gtin]))
return $this->cachedProdIds[$gtin];
return false;
}
}