From 047db97928fc44c31debcb985b696ae086e13d25 Mon Sep 17 00:00:00 2001 From: Marko <52066939+HeX87@users.noreply.github.com> Date: Wed, 13 Dec 2023 14:23:45 +0100 Subject: [PATCH] add fixed export --- src/Command/HiltesImportCommand.php | 6 +++--- src/Helper/HiltesImport.php | 13 ++++++++----- src/Helper/Jtl.php | 8 ++++---- src/Repository/ProductRepository.php | 25 +++++++++++-------------- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/Command/HiltesImportCommand.php b/src/Command/HiltesImportCommand.php index 643fb59..7789baf 100644 --- a/src/Command/HiltesImportCommand.php +++ b/src/Command/HiltesImportCommand.php @@ -60,7 +60,7 @@ class HiltesImportCommand extends Command $hiltesImport = new HiltesImport($this->productRepository, $this->warehouseRepository, $this->stockRepository, $this->logger, $rootPath); - $hiltesImport->startImport($delta); + $prodIds = $hiltesImport->startImport($delta); if (isset($r['error'])) { $io->error($r['text']); @@ -72,10 +72,10 @@ class HiltesImportCommand extends Command $jtl = new Jtl($this->productRepository, $this->warehouseRepository, $this->stockRepository, $this->logger, $rootPath); //Export für Standartlager - $jtl->createExportFile($jtl->getProducts(['1', '3', '5', '10']), 'standard' . ($delta ? '_delta' : '')); + $jtl->createExportFile($jtl->getProducts($prodIds, ['1', '3', '5', '10']), 'standard' . ($delta ? '_delta' : '')); //Export für WMS Lager - $jtl->createExportFile($jtl->getProducts(['8']), 'wms' . ($delta ? '_delta' : '')); + $jtl->createExportFile($jtl->getProducts($prodIds, ['8']), 'wms' . ($delta ? '_delta' : '')); $io->success('Done.'); return Command::SUCCESS; diff --git a/src/Helper/HiltesImport.php b/src/Helper/HiltesImport.php index 7f0c0da..81cbfaf 100644 --- a/src/Helper/HiltesImport.php +++ b/src/Helper/HiltesImport.php @@ -44,9 +44,10 @@ class HiltesImport /** - * @return void + * @param bool $delta + * @return array */ - public function startImport($delta = false) + public function startImport(bool $delta = false): array { #*** Holt alle Dateien if ($this->getFiles($delta)) { @@ -63,18 +64,20 @@ class HiltesImport } } $this->logger->info("Imported $count stocks"); + return $this->cachedProdIds; } else { $this->logger->info('No Files'); } } else { throw new RuntimeException('No Files to Import'); } + return []; } /** * @return bool */ - protected function getFiles($delta = false): bool + protected function getFiles(bool $delta = false): bool { $finder = Finder::create(); $finder @@ -230,9 +233,9 @@ class HiltesImport if (empty($product)) { $product = new Product(); $product->setGtin($gtin); - $this->cachedProdIds[$gtin] = $this->productRepository->save($product, true); + $this->cachedProdIds["$gtin"] = $this->productRepository->save($product, true); } else { - $this->cachedProdIds[$gtin] = $product->getId(); + $this->cachedProdIds["$gtin"] = $product->getId(); } } diff --git a/src/Helper/Jtl.php b/src/Helper/Jtl.php index fcb5398..8aa0620 100644 --- a/src/Helper/Jtl.php +++ b/src/Helper/Jtl.php @@ -59,10 +59,10 @@ class Jtl * @param array $warehousesName * @return array */ - public function getProducts(array $warehousesName): array + public function getProducts(array $prodIds, array $warehousesName): array { $data = array(); - $products = $this->productRepository->findAll(); + $products = $this->productRepository->findById($prodIds); foreach ($warehousesName as $wn) { $warehouse = $this->warehouseRepository->findByWarehouseByName($wn); @@ -82,7 +82,7 @@ class Jtl $data[$s->getProductId() . $warehouseName] = [ 'gtin' => $products[$s->getProductId()]->getGtin(), 'stock' => $s->getInstock(), - 'warehouse' => $this->arrLager[$warehouseName] ?? 'Lager ' . $warehouseName, + 'warehouse' => $this->arrLager[$warehouseName] ?? 'Lager_' . $warehouseName, 'lager' => '01' ]; @@ -97,7 +97,7 @@ class Jtl // 'stock' => 0, // 'warehouse' => 0 // ]; -// $this->logger->info('No stock for product ' . s->getProductId()->getId()); + $this->logger->info('No stock for product ' . s->getProductId()->getId()); } } } diff --git a/src/Repository/ProductRepository.php b/src/Repository/ProductRepository.php index 0fa91d0..0ca5636 100644 --- a/src/Repository/ProductRepository.php +++ b/src/Repository/ProductRepository.php @@ -45,20 +45,17 @@ class ProductRepository extends ServiceEntityRepository } } -// /** -// * @return Product[] Returns an array of Product objects -// */ -// public function findByExampleField($value): array -// { -// return $this->createQueryBuilder('p') -// ->andWhere('p.exampleField = :val') -// ->setParameter('val', $value) -// ->orderBy('p.id', 'ASC') -// ->setMaxResults(10) -// ->getQuery() -// ->getResult() -// ; -// } + /** + * @return Product[] Returns an array of Product objects + */ + public function findById($value): array + { + return $this->createQueryBuilder('p') + ->andWhere('p.id IN (:val)') + ->setParameter('val', $value) + ->getQuery() + ->getResult(); + } // public function findOneBySomeField($value): ?Product // {