Refactor documentation: Update README.md with Laravel branding and restructure content; add new DOCUMENTAZIONE.md for comprehensive project details.

This commit is contained in:
2026-01-19 08:24:22 +01:00
parent 9b3d4b61fc
commit ec8955f9b7
5 changed files with 819 additions and 683 deletions

View File

@@ -8,6 +8,7 @@ use Barryvdh\DomPDF\Facade\Pdf;
use Database\Seeders\ArticoloSeeder;
use Illuminate\Http\Request;
use SimpleSoftwareIO\QrCode\Facades\QrCode;
use \PhpOffice\PhpSpreadsheet\IOFactory;
class ArticoloController extends Controller
{
@@ -172,7 +173,7 @@ class ArticoloController extends Controller
try {
$seeder = new ArticoloSeeder();
$result = $seeder->importFromExcel($file->getPathname(), $cleanImport);
$result = $this->importFromExcel($file->getPathname(), $cleanImport);
$message = "Import completato! ";
$message .= "Articoli importati: {$result['imported']}, ";
@@ -194,5 +195,78 @@ class ArticoloController extends Controller
'message' => 'Errore durante l\'importazione: ' . $e->getMessage(),
], 500);
}
}
/**
* 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(),
];
}
}