diff --git a/STRUTTURA DATABASE.xlsx b/STRUTTURA DATABASE.xlsx index e3243b1..4e174c4 100644 Binary files a/STRUTTURA DATABASE.xlsx and b/STRUTTURA DATABASE.xlsx differ diff --git a/database/seeders/ArticoloSeeder.php b/database/seeders/ArticoloSeeder.php index 6c8575e..00eafe8 100644 --- a/database/seeders/ArticoloSeeder.php +++ b/database/seeders/ArticoloSeeder.php @@ -23,76 +23,5 @@ class ArticoloSeeder extends Seeder $this->importFromExcel($filePath); } - /** - * Import articoli from Excel file. - */ - public function importFromExcel(string $filePath, bool $cleanImport = false): array - { - $spreadsheet = IOFactory::load($filePath); - $worksheet = $spreadsheet->getActiveSheet(); - $rows = $worksheet->toArray(); - $imported = 0; - $updated = 0; - $errors = []; - - // If clean import, delete all existing records - if ($cleanImport) { - Articolo::truncate(); - } - - // Skip header rows (first 2 rows) - foreach (array_slice($rows, 2) as $index => $row) { - // Skip empty rows - if (empty($row[0])) { - continue; - } - - try { - $exists = Articolo::where('codice_articolo', $row[0])->exists(); - - Articolo::updateOrCreate( - ['codice_articolo' => $row[0]], - [ - 'ciclo' => $row[1] ?? null, - 'diametro' => $row[2] ?? null, - 'descrizione' => $row[3] ?? null, - 'posizione' => $row[4] ?? null, - 'quantita' => is_numeric($row[5]) ? (int) $row[5] : 0, - 'tipo_lavorazione' => $row[6] ?? null, - 'materiale_lavorare' => $row[7] ?? null, - 'maximum_thickness' => $row[8] ?? null, - 'speed_rpm' => is_numeric($row[9]) ? (int) $row[9] : null, - 'feed' => is_numeric($row[10]) ? (float) $row[10] : null, - 'max_thrust_a' => $row[11] ?? null, - 'min_torque_a' => $row[12] ?? null, - 'quantita_fori' => is_numeric($row[13]) ? (int) $row[13] : null, - ] - ); - - if ($exists && !$cleanImport) { - $updated++; - } else { - $imported++; - } - - if (isset($this->command)) { - $this->command->info('Importato articolo: ' . $row[0]); - } - } catch (\Exception $e) { - $errors[] = "Riga " . ($index + 3) . ": " . $e->getMessage(); - } - } - - if (isset($this->command)) { - $this->command->info('Import completato! Totale articoli: ' . Articolo::count()); - } - - return [ - 'imported' => $imported, - 'updated' => $updated, - 'errors' => $errors, - 'total' => Articolo::count(), - ]; - } } diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index eece49a..e174e4c 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -17,8 +17,7 @@ class DatabaseSeeder extends Seeder { // User::factory(10)->create(); $this->call([ - AdminUserSeeder::class, - ArticoloSeeder::class, + AdminUserSeeder::class ]); } }