'decimal:2', 'importo_consuntivo' => 'decimal:2', 'attiva' => 'boolean' ]; /** * Relazione con la tabella millesimale */ public function tabellaMillesimale(): BelongsTo { return $this->belongsTo(TabellaMillesimaleConti::class, 'tabella_millesimale_id'); } /** * Codice completo voce (TABELLA + VOCE) */ public function getCodiceCompletoAttribute(): string { return $this->tabellaMillesimale->codice . ' ' . $this->codice_voce; } /** * Importo effettivo (consuntivo se presente, altrimenti preventivo) */ public function getImportoEffettivoAttribute(): ?float { return $this->importo_consuntivo ?? $this->importo_preventivo; } /** * Scope attive */ public function scopeAttive($query) { return $query->where('attiva', true); } /** * Scope per tabella */ public function scopeByTabella($query, $tabellaId) { return $query->where('tabella_millesimale_id', $tabellaId); } }