'date', 'saldo_iniziale' => 'decimal:2', 'created_at' => 'datetime', 'updated_at' => 'datetime', 'deleted_at' => 'datetime', ]; /** * Relazione con Stabile */ public function stabile() { return $this->belongsTo(Stabile::class, 'stabile_id'); } /** * Relazione con RubricaUniversale */ public function contatto() { return $this->belongsTo(RubricaUniversale::class, 'contatto_id'); } /** * Relazione con utente che ha creato */ public function createBy() { return $this->belongsTo(User::class, 'creato_da'); } /** * Relazione con utente che ha modificato */ public function updatedBy() { return $this->belongsTo(User::class, 'modificato_da'); } /** * Relazione con movimenti contabili */ public function movimentiContabili() { return $this->hasMany(MovimentoContabile::class, 'conto_bancario_id'); } /** * Accessor per identificativo conto */ public function getIdentificativoContoAttribute() { return $this->iban ?: $this->numero_conto; } /** * Accessor per descrizione completa */ public function getDescrizioneCompletaAttribute() { return "{$this->denominazione_banca} - {$this->identificativo_conto}"; } /** * Scope per conti attivi */ public function scopeAttivi($query) { return $query->where('stato_conto', 'attivo'); } /** * Scope per stabile */ public function scopePerStabile($query, $stabileId) { return $query->where('stabile_id', $stabileId); } }