netgescon-master/app/Models/Gestione.php
Pikappa2 f45845ba3c feat: Complete NetGesCon modernization - all core systems implemented
MAJOR IMPLEMENTATION COMPLETED:
 Modern database structure with Laravel best practices
 Complete Eloquent relationships (Amministratore→Stabili→Movements)
 8-character alphanumeric codes system (ADM, ANA, MOV, ALL prefixes)
 Multi-database architecture for administrators
 Complete property management (anagrafica_condominiale, diritti_reali, contratti)
 Distribution system for multi-server deployment
 Universal responsive UI with permission-based sidebar

NEW MODELS & MIGRATIONS:
- AnagraficaCondominiale: Complete person/entity management
- ContattoAnagrafica: Multi-contact system with usage flags
- DirittoReale: Property rights with quotas and percentages
- ContrattoLocazione: Rental contracts with landlord/tenant
- TipoUtilizzo: Property usage types (residential, commercial, etc.)
- Enhanced Stabile: Cadastral data, SDI, rate configuration
- Enhanced UnitaImmobiliare: Modern structure with backward compatibility

SERVICES & CONTROLLERS:
- DistributionService: Multi-server deployment and migration
- FileManagerController: Administrator folder management
- DistributionController: API for server-to-server communication
- MultiDatabaseService: Dynamic database connections

READY FOR PRODUCTION:
 Database schema: Complete and tested
 Models relationships: All working and verified
 Code generation: Automatic 8-char codes implemented
 Testing: Successful data creation confirmed
 Documentation: Complete internal technical docs

NEXT PHASE: Millésimal tables, expense categories, cost distribution engine
2025-07-08 16:24:03 +02:00

95 lines
2.1 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Gestione extends Model
{
use HasFactory, SoftDeletes;
protected $table = 'gestioni';
protected $primaryKey = 'id_gestione';
protected $fillable = [
'stabile_id',
'anno_gestione',
'tipo_gestione',
'data_inizio',
'data_fine',
'descrizione',
'stato',
'preventivo_approvato',
'data_approvazione',
'note',
];
protected $casts = [
'data_inizio' => 'date',
'data_fine' => 'date',
'data_approvazione' => 'date',
'preventivo_approvato' => 'boolean',
'created_at' => 'datetime',
'updated_at' => 'datetime',
'deleted_at' => 'datetime',
];
/**
* Relazione con Stabile
*/
public function stabile()
{
return $this->belongsTo(Stabile::class, 'stabile_id', 'id');
}
/**
* Relazione con Preventivi
*/
public function preventivi()
{
return $this->hasMany(Preventivo::class, 'gestione_id', 'id_gestione');
}
/**
* Relazione con Movimenti Contabili
*/
public function movimentiContabili()
{
return $this->hasMany(MovimentoContabile::class, 'gestione_id', 'id_gestione');
}
/**
* Relazione con Rate
*/
public function rate()
{
return $this->hasMany(Rata::class, 'gestione_id', 'id_gestione');
}
/**
* Scope per gestioni attive
*/
public function scopeAttive($query)
{
return $query->where('stato', 'attiva');
}
/**
* Scope per tipo gestione
*/
public function scopeTipo($query, $tipo)
{
return $query->where('tipo_gestione', $tipo);
}
/**
* Accessor per il nome completo della gestione
*/
public function getNomeCompletoAttribute()
{
return $this->anno_gestione . ' - ' . ucfirst($this->tipo_gestione) .
($this->descrizione ? ' (' . $this->descrizione . ')' : '');
}
}