Primo commit
This commit is contained in:
16
database/seeders/DatabaseSeeder.php
Normal file
16
database/seeders/DatabaseSeeder.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class DatabaseSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
$this->call([
|
||||
RolesAndPermissionsSeeder::class,
|
||||
DevSeeder::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
160
database/seeders/DevSeeder.php
Normal file
160
database/seeders/DevSeeder.php
Normal file
@@ -0,0 +1,160 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use App\Models\User;
|
||||
use App\Models\Setting;
|
||||
use App\Models\Zona;
|
||||
use App\Models\Tipologia;
|
||||
use App\Models\Territorio;
|
||||
use App\Models\Proclamatore;
|
||||
use App\Models\AnnoTeocratico;
|
||||
use App\Models\Assegnazione;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class DevSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
// ─── Admin User ─────────────────────────────
|
||||
$admin = User::firstOrCreate(
|
||||
['email' => 'admin@termanager2.local'],
|
||||
[
|
||||
'name' => 'Amministratore',
|
||||
'password' => bcrypt('password'),
|
||||
]
|
||||
);
|
||||
$admin->assignRole('amministratore');
|
||||
|
||||
$assistente = User::firstOrCreate(
|
||||
['email' => 'assistente@termanager2.local'],
|
||||
[
|
||||
'name' => 'Assistente',
|
||||
'password' => bcrypt('password'),
|
||||
]
|
||||
);
|
||||
$assistente->assignRole('assistente');
|
||||
|
||||
$operatore = User::firstOrCreate(
|
||||
['email' => 'operatore@termanager2.local'],
|
||||
[
|
||||
'name' => 'Operatore',
|
||||
'password' => bcrypt('password'),
|
||||
]
|
||||
);
|
||||
$operatore->assignRole('operatore');
|
||||
|
||||
// ─── Settings ───────────────────────────────
|
||||
Setting::firstOrCreate([], [
|
||||
'congregazione_nome' => 'Congregazione Demo',
|
||||
'giorni_giacenza_da_assegnare' => 120,
|
||||
'giorni_giacenza_prioritari' => 180,
|
||||
'giorni_per_smarrito' => 120,
|
||||
'home_limit_list' => 10,
|
||||
'audit_retention_days' => 730,
|
||||
'setup_completed' => true,
|
||||
]);
|
||||
|
||||
// ─── Zone ───────────────────────────────────
|
||||
$zone = [];
|
||||
foreach (['Centro', 'Nord', 'Sud', 'Est', 'Ovest'] as $nome) {
|
||||
$zone[$nome] = Zona::firstOrCreate(['nome' => $nome]);
|
||||
}
|
||||
|
||||
// ─── Tipologie ─────────────────────────────
|
||||
$tipologie = [];
|
||||
foreach (['Residenziale', 'Commerciale', 'Rurale', 'Telefono'] as $nome) {
|
||||
$tipologie[$nome] = Tipologia::firstOrCreate(['nome' => $nome]);
|
||||
}
|
||||
|
||||
// ─── Proclamatori ───────────────────────────
|
||||
$nomi = [
|
||||
['Mario', 'Rossi'], ['Luisa', 'Bianchi'], ['Giovanni', 'Verdi'],
|
||||
['Anna', 'Neri'], ['Paolo', 'Esposito'], ['Francesca', 'Romano'],
|
||||
['Marco', 'Colombo'], ['Sara', 'Ricci'], ['Luca', 'Marino'],
|
||||
['Elena', 'Greco'], ['Roberto', 'Bruno'], ['Chiara', 'Gallo'],
|
||||
];
|
||||
|
||||
$proclamatori = [];
|
||||
foreach ($nomi as [$nome, $cognome]) {
|
||||
$proclamatori[] = Proclamatore::firstOrCreate(
|
||||
// Can't search encrypted fields, use a simple check
|
||||
['id' => count($proclamatori) + 1],
|
||||
['nome' => $nome, 'cognome' => $cognome, 'attivo' => true]
|
||||
);
|
||||
}
|
||||
// Re-fetch to get proper IDs
|
||||
$proclamatori = Proclamatore::all();
|
||||
|
||||
// ─── Territori ──────────────────────────────
|
||||
$zoneKeys = array_values($zone);
|
||||
$tipoKeys = array_values($tipologie);
|
||||
|
||||
for ($i = 1; $i <= 30; $i++) {
|
||||
Territorio::firstOrCreate(
|
||||
['numero' => (string) $i],
|
||||
[
|
||||
'zona_id' => $zoneKeys[($i - 1) % count($zoneKeys)]->id,
|
||||
'tipologia_id' => $tipoKeys[($i - 1) % count($tipoKeys)]->id,
|
||||
'note' => $i <= 5 ? "Note territorio $i" : null,
|
||||
'confini' => "Confini del territorio $i",
|
||||
'attivo' => $i <= 28, // 2 territories inactive
|
||||
'prioritario' => $i <= 3, // 3 manual priority
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
// ─── Anno teocratico ────────────────────────
|
||||
$anno = AnnoTeocratico::corrente();
|
||||
|
||||
// ─── Assegnazioni di esempio ────────────────
|
||||
$territori = Territorio::where('attivo', true)->get();
|
||||
|
||||
// 10 closed assignments (various dates)
|
||||
for ($i = 0; $i < 10; $i++) {
|
||||
$territorio = $territori[$i];
|
||||
$proclamatore = $proclamatori[$i % $proclamatori->count()];
|
||||
$assignedAt = Carbon::now()->subDays(rand(30, 200));
|
||||
$returnedAt = $assignedAt->copy()->addDays(rand(14, 90));
|
||||
|
||||
if ($returnedAt->isFuture()) {
|
||||
$returnedAt = now()->subDays(rand(1, 10));
|
||||
}
|
||||
|
||||
Assegnazione::firstOrCreate(
|
||||
[
|
||||
'territorio_id' => $territorio->id,
|
||||
'anno_teocratico_id' => $anno->id,
|
||||
'assigned_at' => $assignedAt->toDateString(),
|
||||
],
|
||||
[
|
||||
'proclamatore_id' => $proclamatore->id,
|
||||
'returned_at' => $returnedAt->toDateString(),
|
||||
'created_by' => $admin->id,
|
||||
'returned_by' => $admin->id,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
// 5 open assignments (currently assigned)
|
||||
for ($i = 15; $i < 20; $i++) {
|
||||
$territorio = $territori[$i];
|
||||
$proclamatore = $proclamatori[$i % $proclamatori->count()];
|
||||
$assignedAt = Carbon::now()->subDays(rand(5, 150));
|
||||
|
||||
Assegnazione::firstOrCreate(
|
||||
[
|
||||
'territorio_id' => $territorio->id,
|
||||
'anno_teocratico_id' => $anno->id,
|
||||
'assigned_at' => $assignedAt->toDateString(),
|
||||
],
|
||||
[
|
||||
'proclamatore_id' => $proclamatore->id,
|
||||
'returned_at' => null,
|
||||
'created_by' => $admin->id,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
55
database/seeders/RolesAndPermissionsSeeder.php
Normal file
55
database/seeders/RolesAndPermissionsSeeder.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Spatie\Permission\Models\Role;
|
||||
use Spatie\Permission\Models\Permission;
|
||||
|
||||
class RolesAndPermissionsSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
// Reset cached roles and permissions
|
||||
app()[\Spatie\Permission\PermissionRegistrar::class]->forgetCachedPermissions();
|
||||
|
||||
// Create permissions
|
||||
$permissions = [
|
||||
'settings.manage',
|
||||
'proclamatori.manage',
|
||||
'territori.manage',
|
||||
'campagne.manage',
|
||||
'registro.view',
|
||||
'registro.export',
|
||||
'territori.assign',
|
||||
'territori.return',
|
||||
'audit.view',
|
||||
'audit.export',
|
||||
];
|
||||
|
||||
foreach ($permissions as $permission) {
|
||||
Permission::firstOrCreate(['name' => $permission]);
|
||||
}
|
||||
|
||||
// Amministratore: all permissions
|
||||
$admin = Role::firstOrCreate(['name' => 'amministratore']);
|
||||
$admin->syncPermissions($permissions);
|
||||
|
||||
// Assistente: proclamatori, campagne, assign, return
|
||||
$assistente = Role::firstOrCreate(['name' => 'assistente']);
|
||||
$assistente->syncPermissions([
|
||||
'proclamatori.manage',
|
||||
'campagne.manage',
|
||||
'territori.assign',
|
||||
'territori.return',
|
||||
'registro.view',
|
||||
]);
|
||||
|
||||
// Operatore: assign and return only
|
||||
$operatore = Role::firstOrCreate(['name' => 'operatore']);
|
||||
$operatore->syncPermissions([
|
||||
'territori.assign',
|
||||
'territori.return',
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user