115 lines
2.5 KiB
PHP
115 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class DatiBancari extends Model
|
|
{
|
|
use SoftDeletes;
|
|
|
|
protected $table = 'dati_bancari';
|
|
|
|
protected $fillable = [
|
|
'stabile_id',
|
|
'contatto_id', // Riferimento alla rubrica universale
|
|
'tipo_conto', // 'corrente', 'deposito', 'risparmio'
|
|
'denominazione_banca',
|
|
'numero_conto',
|
|
'iban',
|
|
'abi',
|
|
'cab',
|
|
'cin',
|
|
'bic_swift',
|
|
'intestazione_conto',
|
|
'data_saldo_iniziale',
|
|
'saldo_iniziale',
|
|
'valuta',
|
|
'stato_conto', // 'attivo', 'chiuso', 'sospeso'
|
|
'note',
|
|
'creato_da',
|
|
'modificato_da'
|
|
];
|
|
|
|
protected $casts = [
|
|
'data_saldo_iniziale' => '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);
|
|
}
|
|
}
|