93 lines
2.1 KiB
PHP
Executable File
93 lines
2.1 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
class FornitoreGescon extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $table = 'fornitori_gescon';
|
|
|
|
protected $fillable = [
|
|
'amministratore_id',
|
|
'codice_fornitore',
|
|
'denominazione',
|
|
'cognome',
|
|
'nome',
|
|
'indirizzo',
|
|
'cap',
|
|
'comune_id',
|
|
'provincia',
|
|
'nazione',
|
|
'codice_fiscale',
|
|
'partita_iva',
|
|
'telefono',
|
|
'cellulare',
|
|
'fax',
|
|
'email',
|
|
'pec',
|
|
'codice_univoco_sdi',
|
|
'tipo_fornitore',
|
|
'categoria_servizio',
|
|
'note',
|
|
'attivo'
|
|
];
|
|
|
|
protected $casts = [
|
|
'attivo' => 'boolean'
|
|
];
|
|
|
|
public function amministratore(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Administrator::class);
|
|
}
|
|
|
|
public function comune(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Comune::class);
|
|
}
|
|
|
|
public function fatture()
|
|
{
|
|
return $this->hasMany(FatturaFornitore::class, 'fornitore_id');
|
|
}
|
|
|
|
public function scopeAttivi($query)
|
|
{
|
|
return $query->where('attivo', true);
|
|
}
|
|
|
|
public function scopeByTipo($query, $tipo)
|
|
{
|
|
return $query->where('tipo_fornitore', $tipo);
|
|
}
|
|
|
|
public function scopeByCategoria($query, $categoria)
|
|
{
|
|
return $query->where('categoria_servizio', 'like', "%{$categoria}%");
|
|
}
|
|
|
|
public function scopeSearch($query, $search)
|
|
{
|
|
return $query->where(function ($q) use ($search) {
|
|
$q->where('denominazione', 'like', "%{$search}%")
|
|
->orWhere('cognome', 'like', "%{$search}%")
|
|
->orWhere('nome', 'like', "%{$search}%")
|
|
->orWhere('codice_fiscale', 'like', "%{$search}%")
|
|
->orWhere('partita_iva', 'like', "%{$search}%");
|
|
});
|
|
}
|
|
|
|
public function getNomeCompletoAttribute()
|
|
{
|
|
if ($this->denominazione) {
|
|
return $this->denominazione;
|
|
}
|
|
return trim($this->cognome . ' ' . $this->nome);
|
|
}
|
|
}
|