add Delta

This commit is contained in:
Marko
2023-09-25 17:36:06 +02:00
parent 2395c1a638
commit 30b675e999
3 changed files with 30 additions and 32 deletions

View File

@@ -12,6 +12,8 @@ use App\Repository\WarehouseRepository;
use Psr\Log\LoggerInterface;
use Symfony\Component\Finder\Finder;
use App\Helper\App\Helper\SplFileInfo;
class HiltesImport
{
private $productRepository;
@@ -38,17 +40,16 @@ class HiltesImport
/**
* @return array|void
*/
public function startImport()
public function startImport($delta = false)
{
#*** Holt alle Dateien
if($this->getFiles()){
if($this->getFiles($delta)){
#*** Holt alle Stocks und setzt ein Array **************
$this->getStocks();
$count = 0;
if(!empty($this->arrData['orgFiles']['data']) && count($this->arrData['orgFiles']['data'])){
foreach ($this->arrData['orgFiles']['data'] as $file) {
if(is_file($file['realPath'])){
$count += $this->loadFiles($file['realPath'],$file['fileSize']);
}else{
@@ -57,8 +58,6 @@ class HiltesImport
}
}
dump("Imported $count stocks");
//remove fertig file
//unlink($this->currentDirPath.'/hiltes/h2c/WS.FERTIG');
}else
return array('success'=>1,'text'=>'No Files');
@@ -69,34 +68,38 @@ class HiltesImport
/**
* @return bool
*/
protected function getFiles()
protected function getFiles($delta = false)
{
$finder = Finder::create();
$finder
->in($this->currentDirPath.'/hiltes/h2c/')
->depth(0);
#->filter(static function (SplFileInfo $file) {
# return $file->isDir() || \preg_match('/\.(php|json)$/', $file->getPathname());
#});
$hasFoundFertigFile = false;
if($delta) {
$finder->name('/_D/');
}else{
$finder->notName('/_D/');
}
if ($finder->hasResults()) {
#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(),
'onlyFileName' => $file->getRelativePathname(),
);
if($file->getExtension() != 'Ende') {
//prüfen ob Ende Datei vorhanden ist
if(file_exists($this->currentDirPath.'/hiltes/h2c/'.$file->getRelativePathname().'.Ende')) {
$this->arrData['orgFiles']['data'][] = array(
'realPath' => $file->getRealPath(),
'fileSize' => $file->getFileInfo()->getSize(),
'onlyFileName' => $file->getRelativePathname(),
);
}
}
}
}else{
return false;
}
return $hasFoundFertigFile;
return true;
}
protected function getStocks()
{
@@ -139,7 +142,7 @@ class HiltesImport
}
unlink($file->getRealPath());
//unlink($file->getRealPath());
dump($c . ' Datensätze importiert');
return $c;
@@ -185,7 +188,6 @@ class HiltesImport
#*** 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()];
//dd('JAAAAA');
}else{
$stock = new Stock();
$stock->setProductId($gtin);
@@ -196,9 +198,6 @@ class HiltesImport
#$stock->setWarehouseId($wareHouseId);
//dump($stock);
$this->stockRepository->save($stock,true);
}
/**
@@ -235,8 +234,6 @@ class HiltesImport
/**
* @param string $gtin
* @param string $modellNr
* @param string $modellBez
* @return false|int|mixed|null
*/
private function checkProduct(string $gtin){