add fixed export
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Marko
2023-12-13 12:53:31 +01:00
parent bbc944273a
commit c6bc1776bd
9 changed files with 47104 additions and 61 deletions

View File

@@ -52,13 +52,15 @@ class HiltesImportCommand extends Command
$io->success('Start Hiltes Import');
$rootPath = $this->GetProjectRootDir();
$delta = $input->getOption('delta');
/**
* @var HiltesImport
*/
$hiltesImport = new HiltesImport($this->productRepository, $this->warehouseRepository, $this->stockRepository, $this->logger, $rootPath);
$hiltesImport->startImport($input->getOption('delta'));
$hiltesImport->startImport($delta);
if (isset($r['error'])) {
$io->error($r['text']);
@@ -70,11 +72,10 @@ class HiltesImportCommand extends Command
$jtl = new Jtl($this->productRepository, $this->warehouseRepository, $this->stockRepository, $this->logger, $rootPath);
//Export für Standartlager
dump("Standard");
$jtl->createExportFile($jtl->getProducts(['1', '3', '5', '10']), 'standard');
dump("WMS");
$jtl->createExportFile($jtl->getProducts(['1', '3', '5', '10']), 'standard' . ($delta ? '_delta' : ''));
//Export für WMS Lager
$jtl->createExportFile($jtl->getProducts(['8']), 'wms');
$jtl->createExportFile($jtl->getProducts(['8']), 'wms' . ($delta ? '_delta' : ''));
$io->success('Done.');
return Command::SUCCESS;

View File

@@ -43,27 +43,45 @@ class JtlExportCommand extends Command
protected function configure(): void
{
$this
->addArgument('arg1', InputArgument::OPTIONAL, 'Argument description')
->addOption('option1', null, InputOption::VALUE_NONE, 'Option description');
$this->addOption('delta', 'd', InputOption::VALUE_NONE, 'Delta Import');
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$io->success('Start JTL Export');
$rootPath = $this->GetProjectRootDir();
$delta = $input->getOption('delta');
/**
* @var HiltesImport
*/
$jtl = new Jtl($this->productRepository, $this->warehouseRepository, $this->stockRepository, $this->logger);
$jtl = new Jtl($this->productRepository, $this->warehouseRepository, $this->stockRepository, $this->logger, $rootPath);
$data = $jtl->getProducts();
$jtl->createExportFile($data);
//Export für Standartlager
$jtl->createExportFile($jtl->getProducts(['1', '3', '5', '10']), 'standard' . ($delta ? '_delta' : ''));
//Export für WMS Lager
$jtl->createExportFile($jtl->getProducts(['8']), 'wms' . ($delta ? '_delta' : ''));
$io->success('Ende JTL Export');
return Command::SUCCESS;
}
public static function GetProjectRootDir()
{
$dirFullPath = __DIR__;
//PRE: $dirs = /app/public/src/Helpers
$dirs = explode('/', $dirFullPath);
array_pop($dirs); //remove last element in array ('Helpers')
array_pop($dirs); //remove the next last element from array ('src')
//POST: $dirs = /app/public
return implode('/', $dirs);
}
}

View File

@@ -56,7 +56,7 @@ class Ftp
throw new Exception("Local file does not exist: $localFile");
}
$r = ftp_nb_put($ftp, $this->getRemoteDir() . $remoteFile, $localFile, FTP_BINARY);
$r = @ftp_nb_put($ftp, $this->getRemoteDir() . $remoteFile, $localFile, FTP_BINARY);
while ($r == FTP_MOREDATA) {
// Continue uploading...

View File

@@ -243,6 +243,14 @@ class Hiltes
}
}
/**
* Sends a request to the specified URL using CURL.
*
* @param string $url The URL to send the request to.
* @param mixed $param The data to send with the request. It should be an associative array.
* @param bool $auth (Optional) Indicates whether to include authorization in the request headers. Default is false.
* @return mixed The response from the server.
*/
public function sendToHiltes($url, $param, $auth = false)
{
$ch = curl_init($url);
@@ -265,6 +273,12 @@ class Hiltes
return $result;
}
/**
* Creates a JSON object based on the given data.
*
* @param mixed $data The data to be converted to JSON.
* @return array The JSON object.
*/
public function createJson($data)
{
$arr = array(

View File

@@ -19,7 +19,7 @@ use Symfony\Component\Finder\Finder;
class HiltesImport
{
protected $currentDirPath;
protected $cachedWarehouseIds;
protected $cachedWarehouse;
protected $arrData = array();
private $productRepository;
private $stockRepository;
@@ -29,6 +29,8 @@ class HiltesImport
private $cachedStockIds;
private $rootPath;
private $deleteFiles = false;
public function __construct(ProductRepository $productRepository, WarehouseRepository $warehouseRepository, StockRepository $stockRepository, LoggerInterface $logger, string $rootPath)
{
$this->productRepository = $productRepository;
@@ -129,8 +131,10 @@ class HiltesImport
$this->logger->error($e->getMessage());
}
unlink($srcFile);
unlink($srcFile . '.Ende');
if ($this->deleteFiles) {
unlink($srcFile);
unlink($srcFile . '.Ende');
}
$this->logger->info($count . ' Datensätze importiert');
@@ -151,7 +155,7 @@ class HiltesImport
* @param array $arr
* @return void
*/
protected function trimArray(array &$arr): void
private function trimArray(array &$arr): void
{
foreach ($arr as $k => $v) {
$arr[$k] = trim($v);
@@ -160,11 +164,16 @@ class HiltesImport
/**
* @param array $data
* @return void
* @return false
*/
protected function saveData(array $data): void
protected function saveData(array $data): bool
{
$warehouse = $this->checkWarehouseName($data[3]);
if (!isset($data[3])) {
$this->logger->error('No Warehouse' . $data[3]);
return false;
}
$warehouse = $this->checkWarehouseName(trim($data[3]));
$gtin = $this->checkProduct(substr($data[0], 1));
if (!empty($warehouse) && !empty($this->cachedStockIds[$gtin][$warehouse->getId()])) {
@@ -177,33 +186,35 @@ class HiltesImport
$stock->setInstock((int)$data[1] / 100);
$this->stockRepository->save($stock, true);
return true;
}
/**
* @param string $warehouseName
* @return Warehouse|false|mixed|null
* @return int
*/
private function checkWarehouseName(string $warehouseName)
{
$warehouseName = ltrim($warehouseName, 0);
if (empty($this->cachedWarehouseIds[$warehouseName])) {
$warehouse = $this->warehouseRepository->findOneBy(['id' => (int)$warehouseName]);
if (empty($this->cachedWarehouse[$warehouseName])) {
$warehouse = $this->warehouseRepository->findOneBy(['name' => $warehouseName]);
//Wenn kein Lager gefunden wurde, dann lege es an
if (empty($warehouse)) {
$warehouse = new Warehouse();
$warehouse->setId((int)$warehouseName);
//$warehouse->setId((int)$warehouseName);
$warehouse->setName($warehouseName);
$this->warehouseRepository->save($warehouse, true);
$warehouseId = $this->warehouseRepository->save($warehouse, true);
$newWarehouse = $this->warehouseRepository->findOneBy(['id' => $warehouseId]);
$this->cachedWarehouse[$warehouseName] = $newWarehouse;
} else {
$this->cachedWarehouse[$warehouseName] = $warehouse;
}
$this->cachedWarehouseIds[$warehouseName] = $warehouse;
}
if (!empty($this->cachedWarehouseIds[$warehouseName])) {
return $this->cachedWarehouseIds[$warehouseName];
}
return false;
return $this->cachedWarehouse[$warehouseName];
}
/**

View File

@@ -102,34 +102,6 @@ class Jtl
}
}
// foreach ($r as $product) {
//
// $stock = $this->stockRepository->findBy(['product_id' => $product->getId()]);
//
// if ($stock) {
// foreach ($stock as $s) {
// $warehouse = $s->getWarehouse();
// $warehouseName = $warehouse->getName();
//
// $data[$product->getId() . $warehouseName] = [
// 'gtin' => $product->getGtin(),
// 'stock' => $s->getInstock(),
// 'warehouse' => $this->arrLager[$warehouseName] ?? 'Lager ' . $warehouseName
// ];
//
// }
// } else {
// $data[$product->getId()] = [
// 'gtin' => $product->getGtin(),
// 'stock' => 0,
// 'warehouse' => 0
// ];
//
// $this->logger->info('No stock for product ' . $product->getId());
// }
// }
return $data;
}
@@ -145,8 +117,6 @@ class Jtl
$file = $this->rootPath . '/jtl/' . $warehouse . '.csv';
dump($file);
$writer = Writer::createFromPath($file, 'w+');
$bytes = $writer->insertAll(new ArrayIterator($data));