318 lines
10 KiB
PHP
318 lines
10 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use Illuminate\Console\Command;
|
|
use App\Models\Stabile;
|
|
use App\Models\Soggetto;
|
|
use App\Models\Ticket;
|
|
use App\Models\UnitaImmobiliare;
|
|
use App\Models\Rata;
|
|
use App\Models\Assemblea;
|
|
use App\Models\User;
|
|
use Carbon\Carbon;
|
|
|
|
class PopulateTestData extends Command
|
|
{
|
|
protected $signature = 'netgescon:populate-test-data';
|
|
protected $description = 'Popola il database con dati di test per NetGesCon';
|
|
|
|
public function handle()
|
|
{
|
|
$this->info('🏢 Popolamento dati di test NetGesCon...');
|
|
|
|
// Crea stabili di test
|
|
$this->createTestStabili();
|
|
|
|
// Crea condomini di test
|
|
$this->createTestCondomini();
|
|
|
|
// Crea tickets di test
|
|
$this->createTestTickets();
|
|
|
|
// Crea rate di test
|
|
$this->createTestRate();
|
|
|
|
// Crea assemblee di test
|
|
$this->createTestAssemblee();
|
|
|
|
$this->info('✅ Dati di test creati con successo!');
|
|
$this->info('📊 Usa /test-sidebar-data per vedere il risultato');
|
|
}
|
|
|
|
private function createTestStabili()
|
|
{
|
|
if (Stabile::count() > 0) {
|
|
$this->info('⏭️ Stabili già presenti, skip...');
|
|
return;
|
|
}
|
|
|
|
$stabili = [
|
|
[
|
|
'nome' => 'Condominio Roma Centro',
|
|
'indirizzo' => 'Via Roma 123, Roma',
|
|
'codice_fiscale' => 'STABROM123',
|
|
'stato' => 'attivo',
|
|
'created_at' => now(),
|
|
'updated_at' => now(),
|
|
],
|
|
[
|
|
'nome' => 'Residenza Milano Nord',
|
|
'indirizzo' => 'Via Milano 456, Milano',
|
|
'codice_fiscale' => 'STABMIL456',
|
|
'stato' => 'attivo',
|
|
'created_at' => now(),
|
|
'updated_at' => now(),
|
|
],
|
|
[
|
|
'nome' => 'Condominio Firenze Sud',
|
|
'indirizzo' => 'Via Firenze 789, Firenze',
|
|
'codice_fiscale' => 'STABFIR789',
|
|
'stato' => 'inattivo',
|
|
'created_at' => now(),
|
|
'updated_at' => now(),
|
|
]
|
|
];
|
|
|
|
foreach ($stabili as $stabile) {
|
|
Stabile::create($stabile);
|
|
}
|
|
|
|
$this->info('🏢 Creati 3 stabili di test');
|
|
}
|
|
|
|
private function createTestCondomini()
|
|
{
|
|
if (Soggetto::count() > 0) {
|
|
$this->info('⏭️ Condomini già presenti, skip...');
|
|
return;
|
|
}
|
|
|
|
$condomini = [
|
|
[
|
|
'nome' => 'Mario',
|
|
'cognome' => 'Rossi',
|
|
'codice_fiscale' => 'RSSMRA80A01H501Z',
|
|
'tipo' => 'proprietario',
|
|
'email' => 'mario.rossi@example.com',
|
|
'telefono' => '333-1234567',
|
|
'created_at' => now(),
|
|
'updated_at' => now(),
|
|
],
|
|
[
|
|
'nome' => 'Giulia',
|
|
'cognome' => 'Bianchi',
|
|
'codice_fiscale' => 'BNCGLI85B15H501Y',
|
|
'tipo' => 'proprietario',
|
|
'email' => 'giulia.bianchi@example.com',
|
|
'telefono' => '333-2345678',
|
|
'created_at' => now(),
|
|
'updated_at' => now(),
|
|
],
|
|
[
|
|
'nome' => 'Luca',
|
|
'cognome' => 'Verdi',
|
|
'codice_fiscale' => 'VRDLCU90C20H501X',
|
|
'tipo' => 'inquilino',
|
|
'email' => 'luca.verdi@example.com',
|
|
'telefono' => '333-3456789',
|
|
'created_at' => now(),
|
|
'updated_at' => now(),
|
|
],
|
|
[
|
|
'nome' => 'Anna',
|
|
'cognome' => 'Neri',
|
|
'codice_fiscale' => 'NRANNA75D25H501W',
|
|
'tipo' => 'inquilino',
|
|
'email' => 'anna.neri@example.com',
|
|
'telefono' => '333-4567890',
|
|
'created_at' => now(),
|
|
'updated_at' => now(),
|
|
]
|
|
];
|
|
|
|
foreach ($condomini as $condomino) {
|
|
Soggetto::create($condomino);
|
|
}
|
|
|
|
$this->info('👥 Creati 4 condomini di test');
|
|
}
|
|
|
|
private function createTestTickets()
|
|
{
|
|
if (Ticket::count() > 0) {
|
|
$this->info('⏭️ Tickets già presenti, skip...');
|
|
return;
|
|
}
|
|
|
|
// Prendi il primo stabile disponibile
|
|
$stabile = Stabile::first();
|
|
if (!$stabile) {
|
|
$this->error('❌ Nessuno stabile trovato. Crea prima uno stabile.');
|
|
return;
|
|
}
|
|
|
|
// Prendi il primo utente disponibile
|
|
$user = User::first();
|
|
if (!$user) {
|
|
$this->error('❌ Nessun utente trovato. Crea prima un utente.');
|
|
return;
|
|
}
|
|
|
|
$tickets = [
|
|
[
|
|
'stabile_id' => $stabile->id,
|
|
'aperto_da_user_id' => $user->id,
|
|
'titolo' => 'Perdita d\'acqua nel bagno',
|
|
'descrizione' => 'C\'è una perdita d\'acqua nel bagno del primo piano',
|
|
'priorita' => 'Alta',
|
|
'stato' => 'Aperto',
|
|
'data_apertura' => now(),
|
|
'created_at' => now(),
|
|
'updated_at' => now(),
|
|
],
|
|
[
|
|
'stabile_id' => $stabile->id,
|
|
'aperto_da_user_id' => $user->id,
|
|
'titolo' => 'Problema ascensore',
|
|
'descrizione' => 'L\'ascensore si ferma tra il secondo e il terzo piano',
|
|
'priorita' => 'Alta',
|
|
'stato' => 'In Lavorazione',
|
|
'data_apertura' => now(),
|
|
'created_at' => now(),
|
|
'updated_at' => now(),
|
|
],
|
|
[
|
|
'stabile_id' => $stabile->id,
|
|
'aperto_da_user_id' => $user->id,
|
|
'titolo' => 'Richiesta sostituzione lampadina',
|
|
'descrizione' => 'La lampadina nell\'androne è bruciata',
|
|
'priorita' => 'Bassa',
|
|
'stato' => 'Aperto',
|
|
'data_apertura' => now(),
|
|
'created_at' => now(),
|
|
'updated_at' => now(),
|
|
],
|
|
[
|
|
'stabile_id' => $stabile->id,
|
|
'aperto_da_user_id' => $user->id,
|
|
'titolo' => 'Rumore eccessivo',
|
|
'descrizione' => 'Il vicino del piano di sopra fa troppo rumore',
|
|
'priorita' => 'Media',
|
|
'stato' => 'Chiuso',
|
|
'data_apertura' => now()->subDays(5),
|
|
'data_chiusura_effettiva' => now(),
|
|
'created_at' => now()->subDays(2),
|
|
'updated_at' => now(),
|
|
]
|
|
];
|
|
|
|
foreach ($tickets as $ticket) {
|
|
Ticket::create($ticket);
|
|
}
|
|
|
|
$this->info('🎫 Creati 4 tickets di test');
|
|
}
|
|
|
|
private function createTestRate()
|
|
{
|
|
// TODO: Implementare rate con la nuova struttura
|
|
$this->info('⏭️ Creazione rate temporaneamente disabilitata');
|
|
return;
|
|
|
|
// Prendi il primo stabile disponibile
|
|
$stabile = Stabile::first();
|
|
if (!$stabile) {
|
|
$this->error('❌ Nessuno stabile trovato. Crea prima uno stabile.');
|
|
return;
|
|
}
|
|
|
|
$rate = [
|
|
[
|
|
'stabile_id' => $stabile->id,
|
|
'importo' => 250.00,
|
|
'data_scadenza' => Carbon::now()->subDays(10), // Scaduta
|
|
'stato' => 'non_pagata',
|
|
'descrizione' => 'Rata mensile gennaio 2025',
|
|
'created_at' => now(),
|
|
'updated_at' => now(),
|
|
],
|
|
[
|
|
'stabile_id' => $stabile->id,
|
|
'importo' => 250.00,
|
|
'data_scadenza' => Carbon::now()->subDays(5), // Scaduta
|
|
'stato' => 'non_pagata',
|
|
'descrizione' => 'Rata mensile febbraio 2025',
|
|
'created_at' => now(),
|
|
'updated_at' => now(),
|
|
],
|
|
[
|
|
'stabile_id' => $stabile->id,
|
|
'importo' => 250.00,
|
|
'data_scadenza' => Carbon::now()->addDays(20),
|
|
'stato' => 'non_pagata',
|
|
'descrizione' => 'Rata mensile marzo 2025',
|
|
'created_at' => now(),
|
|
'updated_at' => now(),
|
|
],
|
|
[
|
|
'stabile_id' => $stabile->id,
|
|
'importo' => 250.00,
|
|
'data_scadenza' => Carbon::now()->subDays(30),
|
|
'data_pagamento' => Carbon::now()->subDays(25),
|
|
'stato' => 'pagata',
|
|
'descrizione' => 'Rata mensile dicembre 2024',
|
|
'created_at' => now(),
|
|
'updated_at' => now(),
|
|
]
|
|
];
|
|
|
|
foreach ($rate as $rata) {
|
|
Rata::create($rata);
|
|
}
|
|
|
|
$this->info('💰 Create 4 rate di test');
|
|
}
|
|
|
|
private function createTestAssemblee()
|
|
{
|
|
// TODO: Implementare assemblee quando la tabella sarà disponibile
|
|
$this->info('⏭️ Creazione assemblee temporaneamente disabilitata');
|
|
return;
|
|
|
|
// Prendi il primo stabile disponibile
|
|
$stabile = Stabile::first();
|
|
if (!$stabile) {
|
|
$this->error('❌ Nessuno stabile trovato. Crea prima uno stabile.');
|
|
return;
|
|
}
|
|
|
|
$assemblee = [
|
|
[
|
|
'stabile_id' => $stabile->id,
|
|
'titolo' => 'Assemblea Ordinaria Gennaio 2025',
|
|
'data_assemblea' => Carbon::now()->addDays(15),
|
|
'luogo' => 'Sala condominiale',
|
|
'stato' => 'programmata',
|
|
'created_at' => now(),
|
|
'updated_at' => now(),
|
|
],
|
|
[
|
|
'stabile_id' => $stabile->id,
|
|
'titolo' => 'Assemblea Straordinaria - Rifacimento tetto',
|
|
'data_assemblea' => Carbon::now()->addDays(30),
|
|
'luogo' => 'Sala condominiale',
|
|
'stato' => 'bozza',
|
|
'created_at' => now(),
|
|
'updated_at' => now(),
|
|
]
|
|
];
|
|
|
|
foreach ($assemblee as $assemblea) {
|
|
Assemblea::create($assemblea);
|
|
}
|
|
|
|
$this->info('🏛️ Create 2 assemblee di test');
|
|
}
|
|
}
|