161 lines
6.0 KiB
PHP
161 lines
6.0 KiB
PHP
<?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,
|
|
]
|
|
);
|
|
}
|
|
}
|
|
}
|