first commit
This commit is contained in:
1
database/.gitignore
vendored
Normal file
1
database/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
*.sqlite*
|
||||
44
database/factories/UserFactory.php
Normal file
44
database/factories/UserFactory.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User>
|
||||
*/
|
||||
class UserFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The current password being used by the factory.
|
||||
*/
|
||||
protected static ?string $password;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'name' => fake()->name(),
|
||||
'email' => fake()->unique()->safeEmail(),
|
||||
'email_verified_at' => now(),
|
||||
'password' => static::$password ??= Hash::make('password'),
|
||||
'remember_token' => Str::random(10),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the model's email address should be unverified.
|
||||
*/
|
||||
public function unverified(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'email_verified_at' => null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
49
database/migrations/0001_01_01_000000_create_users_table.php
Normal file
49
database/migrations/0001_01_01_000000_create_users_table.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('users', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
$table->string('email')->unique();
|
||||
$table->timestamp('email_verified_at')->nullable();
|
||||
$table->string('password');
|
||||
$table->rememberToken();
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
Schema::create('password_reset_tokens', function (Blueprint $table) {
|
||||
$table->string('email')->primary();
|
||||
$table->string('token');
|
||||
$table->timestamp('created_at')->nullable();
|
||||
});
|
||||
|
||||
Schema::create('sessions', function (Blueprint $table) {
|
||||
$table->string('id')->primary();
|
||||
$table->foreignId('user_id')->nullable()->index();
|
||||
$table->string('ip_address', 45)->nullable();
|
||||
$table->text('user_agent')->nullable();
|
||||
$table->longText('payload');
|
||||
$table->integer('last_activity')->index();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('users');
|
||||
Schema::dropIfExists('password_reset_tokens');
|
||||
Schema::dropIfExists('sessions');
|
||||
}
|
||||
};
|
||||
35
database/migrations/0001_01_01_000001_create_cache_table.php
Normal file
35
database/migrations/0001_01_01_000001_create_cache_table.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('cache', function (Blueprint $table) {
|
||||
$table->string('key')->primary();
|
||||
$table->mediumText('value');
|
||||
$table->integer('expiration');
|
||||
});
|
||||
|
||||
Schema::create('cache_locks', function (Blueprint $table) {
|
||||
$table->string('key')->primary();
|
||||
$table->string('owner');
|
||||
$table->integer('expiration');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('cache');
|
||||
Schema::dropIfExists('cache_locks');
|
||||
}
|
||||
};
|
||||
57
database/migrations/0001_01_01_000002_create_jobs_table.php
Normal file
57
database/migrations/0001_01_01_000002_create_jobs_table.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('jobs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('queue')->index();
|
||||
$table->longText('payload');
|
||||
$table->unsignedTinyInteger('attempts');
|
||||
$table->unsignedInteger('reserved_at')->nullable();
|
||||
$table->unsignedInteger('available_at');
|
||||
$table->unsignedInteger('created_at');
|
||||
});
|
||||
|
||||
Schema::create('job_batches', function (Blueprint $table) {
|
||||
$table->string('id')->primary();
|
||||
$table->string('name');
|
||||
$table->integer('total_jobs');
|
||||
$table->integer('pending_jobs');
|
||||
$table->integer('failed_jobs');
|
||||
$table->longText('failed_job_ids');
|
||||
$table->mediumText('options')->nullable();
|
||||
$table->integer('cancelled_at')->nullable();
|
||||
$table->integer('created_at');
|
||||
$table->integer('finished_at')->nullable();
|
||||
});
|
||||
|
||||
Schema::create('failed_jobs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('uuid')->unique();
|
||||
$table->text('connection');
|
||||
$table->text('queue');
|
||||
$table->longText('payload');
|
||||
$table->longText('exception');
|
||||
$table->timestamp('failed_at')->useCurrent();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('jobs');
|
||||
Schema::dropIfExists('job_batches');
|
||||
Schema::dropIfExists('failed_jobs');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('articoli', function (Blueprint $table) {
|
||||
$table->id();
|
||||
|
||||
// Campi Ubicazione
|
||||
$table->string('codice_articolo')->unique();
|
||||
$table->string('ciclo')->nullable();
|
||||
$table->string('diametro')->nullable();
|
||||
$table->text('descrizione')->nullable();
|
||||
$table->string('posizione')->nullable();
|
||||
$table->integer('quantita')->default(0);
|
||||
|
||||
// Campi Parametri Tecnologici
|
||||
$table->string('tipo_lavorazione')->nullable();
|
||||
$table->string('materiale_lavorare')->nullable();
|
||||
$table->string('maximum_thickness')->nullable();
|
||||
$table->integer('speed_rpm')->nullable();
|
||||
$table->decimal('feed', 8, 2)->nullable();
|
||||
$table->string('max_thrust_a')->nullable();
|
||||
$table->string('min_torque_a')->nullable();
|
||||
$table->integer('quantita_fori')->nullable();
|
||||
|
||||
// Campo QR Code (formato: id-timestamp, es: 42-1737235200)
|
||||
$table->string('qr_code')->nullable()->unique();
|
||||
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('articoli');
|
||||
}
|
||||
};
|
||||
27
database/seeders/AdminUserSeeder.php
Normal file
27
database/seeders/AdminUserSeeder.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class AdminUserSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
User::updateOrCreate(
|
||||
['email' => 'admin@htt.local'],
|
||||
[
|
||||
'name' => 'Admin',
|
||||
'password' => Hash::make('password'),
|
||||
'email_verified_at' => now(),
|
||||
]
|
||||
);
|
||||
|
||||
$this->command->info('Utente admin creato: admin@htt.local / password');
|
||||
}
|
||||
}
|
||||
98
database/seeders/ArticoloSeeder.php
Normal file
98
database/seeders/ArticoloSeeder.php
Normal file
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Articolo;
|
||||
use Illuminate\Database\Seeder;
|
||||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||
|
||||
class ArticoloSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$filePath = base_path('STRUTTURA DATABASE.xlsx');
|
||||
|
||||
if (!file_exists($filePath)) {
|
||||
$this->command->error('File Excel non trovato: ' . $filePath);
|
||||
return;
|
||||
}
|
||||
|
||||
$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(),
|
||||
];
|
||||
}
|
||||
}
|
||||
24
database/seeders/DatabaseSeeder.php
Normal file
24
database/seeders/DatabaseSeeder.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class DatabaseSeeder extends Seeder
|
||||
{
|
||||
use WithoutModelEvents;
|
||||
|
||||
/**
|
||||
* Seed the application's database.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
// User::factory(10)->create();
|
||||
$this->call([
|
||||
AdminUserSeeder::class,
|
||||
ArticoloSeeder::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user