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

This commit is contained in:
Marko
2023-11-23 16:54:04 +01:00
parent 231e9390b8
commit 6e98fca7ad
13 changed files with 101 additions and 158 deletions

View File

@@ -42,15 +42,19 @@ class Jtl
* Holt alle Produkte und deren Lagerbestände
* @return array
*/
public function getProducts(): array
public function getProducts(int $warehouseId): array
{
$r = $this->productRepository->findAll();
$data = array();
foreach ($r as $product) {
$stock = $this->stockRepository->findBy(['product_id' => $product->getId()]);
if ($warehouseId != 0) {
$stock = $this->stockRepository->findBy(['product_id' => $product->getId(), 'warehouse_id' => $warehouseId]);
} else {
$stock = $this->stockRepository->findBy(['product_id' => $product->getId()]);
}
if ($stock) {
foreach ($stock as $s) {
@@ -83,17 +87,17 @@ class Jtl
* @param $data
* @return void
*/
public function createExportFile($data): void
public function createExportFile($data, $warehouse): void
{
try {
$writer = Writer::createFromPath(getcwd() . '/www/jtl/cds-export.csv', 'w+');
$writer = Writer::createFromPath(getcwd() . '/www/jtl/' . $warehouse . '.csv', 'w+');
$bytes = $writer->insertAll(new ArrayIterator($data));
if ($bytes) {
$this->logger->info('Exported ' . $bytes . ' bytes');
$FTP = new Ftp();
$FTP->uploadFile(getcwd() . '/www/jtl/cds-export.csv');
$FTP->uploadFile(getcwd() . '/www/jtl/' . $warehouse . '.csv');
}
} catch (Exception $e) {