92 lines
3.3 KiB
PHP
92 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Models\PricelistFile;
|
|
use App\Enums\PricelistFileStatusEnum;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class PricelistFileProcessService
|
|
{
|
|
public function __construct(
|
|
protected PriceListService $priceListService
|
|
) {}
|
|
|
|
/**
|
|
* Előfeldolgozás (Pre-processing) - Adatok ellenőrzése és validálása
|
|
*
|
|
* @param PricelistFile $pricelistFile
|
|
* @param array $data Az XLS-ből beolvasott adatok
|
|
* @return bool
|
|
*/
|
|
public function preProcess(PricelistFile $pricelistFile, array $data): bool
|
|
{
|
|
$pricelistFile->update([
|
|
'status' => PricelistFileStatusEnum::inprogress,
|
|
'processing_current_step' => 'Előfeldolgozás: Adatok ellenőrzése...',
|
|
'processing_current_step_percentage' => 10,
|
|
]);
|
|
|
|
try {
|
|
// Itt hívjuk majd meg a PriceListService ellenőrző metódusait
|
|
// $results = $this->priceListService->importPriceListCheck($pricelistFile->supplier_id, $data);
|
|
|
|
// TODO: Eredmények mentése (pl. preview_data JSON mezőbe vagy fájlba)
|
|
|
|
$pricelistFile->update([
|
|
'status' => PricelistFileStatusEnum::todo, // Visszaállítjuk, vagy egy új 'waiting_for_approval' státuszra, ha létezik
|
|
'processing_current_step' => 'Előfeldolgozás kész, jóváhagyásra vár.',
|
|
'processing_current_step_percentage' => 100,
|
|
]);
|
|
|
|
return true;
|
|
} catch (\Exception $e) {
|
|
Log::error('Pricelist pre-process error: ' . $e->getMessage());
|
|
$pricelistFile->update([
|
|
'status' => PricelistFileStatusEnum::fail,
|
|
'processing_current_step' => 'Hiba az előfeldolgozás során: ' . $e->getMessage(),
|
|
]);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Végrehajtás (Execution) - Módosítások tényleges alkalmazása tranzakcióban
|
|
*
|
|
* @param PricelistFile $pricelistFile
|
|
* @param array $dataToImport A véglegesítendő adatok
|
|
* @return bool
|
|
*/
|
|
public function execute(PricelistFile $pricelistFile, array $dataToImport): bool
|
|
{
|
|
$pricelistFile->update([
|
|
'status' => PricelistFileStatusEnum::inprogress,
|
|
'processing_current_step' => 'Végrehajtás: Árlista frissítése...',
|
|
'processing_current_step_percentage' => 0,
|
|
]);
|
|
|
|
DB::beginTransaction();
|
|
try {
|
|
// Tényleges importálás végrehajtása a PriceListService segítségével
|
|
// $this->priceListService->importPriceList(...);
|
|
|
|
DB::commit();
|
|
$pricelistFile->update([
|
|
'status' => PricelistFileStatusEnum::done,
|
|
'processing_current_step' => 'Sikeresen befejezve.',
|
|
'processing_current_step_percentage' => 100,
|
|
]);
|
|
return true;
|
|
} catch (\Exception $e) {
|
|
DB::rollBack();
|
|
Log::error('Pricelist execution error: ' . $e->getMessage());
|
|
$pricelistFile->update([
|
|
'status' => PricelistFileStatusEnum::fail,
|
|
'processing_current_step' => 'Hiba a végrehajtás során: ' . $e->getMessage(),
|
|
]);
|
|
return false;
|
|
}
|
|
}
|
|
}
|