add FTP Upload

This commit is contained in:
Marko
2023-09-27 15:07:34 +02:00
parent a1a2eb84b3
commit a97fec167c
29 changed files with 175 additions and 25090 deletions

View File

@@ -12,7 +12,6 @@ use App\Repository\WarehouseRepository;
use Psr\Log\LoggerInterface;
use Symfony\Component\Finder\Finder;
use App\Helper\App\Helper\SplFileInfo;
class HiltesImport
{
@@ -51,18 +50,19 @@ class HiltesImport
foreach ($this->arrData['orgFiles']['data'] as $file) {
if(is_file($file['realPath'])){
$count += $this->loadFiles($file['realPath'],$file['fileSize']);
$count += $this->loadFiles($file['realPath']);
}else{
throw new \RuntimeException("Error: File not found - " . $file['realPath']);
}
}
return array('error'=>1,'text'=>'Error is_file('.$file['realPath'].')');
$this->logger->info("Imported $count stocks");
} else {
$this->logger->info('No Files');
}
}
dump("Imported $count stocks");
}else
return array('success'=>1,'text'=>'No Files');
}else
return array('error'=>1,'text'=>'Error in getFiles or no file WS.FERTIG');
} else {
throw new \RuntimeException('Error in getFiles or no file WS.FERTIG');
}
}
/**
@@ -82,7 +82,6 @@ class HiltesImport
}
if ($finder->hasResults()) {
#dump($finder);
foreach ($finder as $file) {
if($file->getExtension() != 'Ende') {
//prüfen ob Ende Datei vorhanden ist
@@ -103,132 +102,92 @@ class HiltesImport
}
protected function getStocks()
{
$r = $this->stockRepository->findAll();
foreach ($r as $v) {
$this->cachedStockIds[$v->getProductId()][$v->getWarehouse()->getId()] = $v;
$stocks = $this->stockRepository->findAll();
foreach ($stocks as $stock) {
$this->cachedStockIds[$stock->getProductId()][$stock->getWarehouse()->getId()] = $stock;
}
#dd($this->cachedStockIds);
}
/**
* @param $srcFile
* @param $size
* @return int
*/
protected function loadFiles($srcFile,$size)
protected function loadFiles($srcFile)
{
#*** Check File ****
#dd($srcFile);
$file = new \SplFileObject($srcFile);
#dump($file->getRealPath());
try {
$file = new \SplFileObject($srcFile);
$this->logger->info('Starte Import von ' . $file->getRealPath());
$count = 0;
$this->logger->info('Starte Import von ' . $file->getRealPath());
dump('Starte Import von ' . $file->getRealPath());
$c = 0;
while (!$file->eof()) {
while (!$file->eof()) {
$this->processLine($file->fgets());
$count++;
}
}catch (\Exception $e) {
$this->logger->error($e->getMessage());
}
// #*** Convertiert die Zeile in UTF8
// $data = iconv('ISO-8859-1','UTF-8',$file->fgets());
//
// #*** Überspringt die erste Zeile
// if($c == 0){
// $c++;
// continue;
// }
unlink($srcFile);
unlink($srcFile . '.Ende');
#*** Speichert die Zeile
$this->switchSaveData($this->splitLine($file->fgets()));
$c++;
$this->logger->info($count . ' Datensätze importiert');
}
//unlink($file->getRealPath());
dump($c . ' Datensätze importiert');
return $c;
}
protected function splitLine($str){
return str_getcsv($str,';','"');
return $count;
}
/**
* Hier wird festgelegt wo und wie die Zeile gespeichert wird
*
* @param array $arr
* @return void
*/
protected function switchSaveData(array $arr){
if(!empty($arr[0])){
#*** Leerzeichen löschen bei den einzelnen Einträgen **********
$this->trimArray($arr);
#***
$this->saveData($arr);
protected function processLine($line)
{
$data = str_getcsv($line, ';', '"');
if (!empty($data[0])) {
$this->trimArray($data);
$this->saveData($data);
}
}
protected function trimArray(Array &$arr){
protected function trimArray(array &$arr)
{
foreach ($arr as $k=>$v) {
$arr[$k] = trim($v);
}
}
protected function saveData(array $data)
{
$warehouse = $this->checkWarehouseName($data[3]);
$gtin = $this->checkProduct(substr($data[0], 1));
/**
* @param array $arr
* @return void
*/
protected function saveData(Array $arr){
//dump($arr);
#*** Speichert und/oder Holt WareHouse ab
$wareHouse = $this->checkWareHouseName($arr[3]);
#*** PRodukt wird angelegt oder geholt ****
#filiale;etikettnr;menge;
$gtin = $this->checkProduct(substr($arr[0],1));
#*** Ermitteln ob schon ein ID vorhanden für ProdId und WareHouseId
if(!empty($wareHouse) && !empty($this->cachedStockIds[$gtin][$wareHouse->getId()])){
$stock = $this->cachedStockIds[$gtin][$wareHouse->getId()];
if (!empty($warehouse) && !empty($this->cachedStockIds[$gtin][$warehouse->getId()])) {
$stock = $this->cachedStockIds[$gtin][$warehouse->getId()];
}else{
$stock = new Stock();
$stock->setProductId($gtin);
$stock->setWarehouse($wareHouse);
$stock->setWarehouse($warehouse);
}
//dd('CHCEK');
$stock->setInstock((int)$arr[1]/100);
#$stock->setWarehouseId($wareHouseId);
//dump($stock);
$stock->setInstock((int) $data[1] / 100);
$this->stockRepository->save($stock,true);
}
/**
* @param string $wareHouseName
* @return Warehouse|false|int|mixed|null
*/
private function checkWareHouseName(string $wareHouseName){
private function checkWarehouseName(string $warehouseName)
{
$warehouseName = ltrim($warehouseName, 0);
$wareHouseName = ltrim($wareHouseName,0);
#*** WEnn keine geCached Id Vorhanden
if(empty($this->cachedWarehouseIds[$wareHouseName])){
#*** Check
$warehouse2 = $this->warehouseRepository->findOneBy(['id'=> (int)$wareHouseName]);
if(empty($warehouse2)){
if (empty($this->cachedWarehouseIds[$warehouseName])) {
$warehouse = $this->warehouseRepository->findOneBy(['id' => (int) $warehouseName]);
if (empty($warehouse)) {
$warehouse = new Warehouse();
$warehouse->setId((int)$wareHouseName);
$warehouse->setName($wareHouseName);
#
$warehouse->setId((int) $warehouseName);
$warehouse->setName($warehouseName);
$this->warehouseRepository->save($warehouse,true);
$this->cachedWarehouseIds[$wareHouseName] = $warehouse;
#*****************
#$warehouse2 = $this->warehouseRepository->findOneBy(['id'=> (int)$wareHouseName]);
#dump($warehouse2);
$this->cachedWarehouseIds[$warehouseName] = $warehouse;
}else{
$this->cachedWarehouseIds[$wareHouseName] = $warehouse2;
$this->cachedWarehouseIds[$warehouseName] = $warehouse;
}
}
if (!empty($this->cachedWarehouseIds[$warehouseName])) {
return $this->cachedWarehouseIds[$warehouseName];
}
if(!empty($this->cachedWarehouseIds[$wareHouseName]))
return $this->cachedWarehouseIds[$wareHouseName];
return false;
}
@@ -239,28 +198,21 @@ class HiltesImport
private function checkProduct(string $gtin){
#*** WEnn keine geCached Id Vorhanden
if(empty($this->cachedProdIds[$gtin])){
#*** Check
//dump($gtin);
$prod2 = $this->productRepository->findOneBy(['gtin'=> $gtin]);
//dump($prod2);
if(empty($prod2)){
$prod = new Product();
$prod->setGtin($gtin);
// $prod->setModellNr($modellNr);
// $prod->setModellBez($modellBez);
// $prod->setShopwareId("");
#
$this->cachedProdIds[$gtin] = $this->productRepository->save($prod,true);
#*****************
//$prod2 = $this->productRepository->findOneBy(['gtin'=> $gtin]);
#dump($warehouse2);
$product = $this->productRepository->findOneBy(['gtin' => $gtin]);
if (empty($product)) {
$product = new Product();
$product->setGtin($gtin);
$this->cachedProdIds[$gtin] = $this->productRepository->save($product, true);
}else{
$this->cachedProdIds[$gtin] = $prod2->getId();
$this->cachedProdIds[$gtin] = $product->getId();
}
}
}
if(!empty($this->cachedProdIds[$gtin]))
if (!empty($this->cachedProdIds[$gtin])) {
return $this->cachedProdIds[$gtin];
}
return false;
}
}