72 lines
1.5 KiB
PHP
72 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Carbon\Carbon;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
class Asset extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $fillable = [
|
|
'nom',
|
|
'type',
|
|
'code_ean',
|
|
'marque',
|
|
'modele',
|
|
'numero_serie',
|
|
'emplacement',
|
|
'commune_id',
|
|
'commande_id',
|
|
'date_achat',
|
|
'date_fin_garantie',
|
|
'statut',
|
|
'notes',
|
|
];
|
|
|
|
protected $casts = [
|
|
'date_achat' => 'date',
|
|
'date_fin_garantie' => 'date',
|
|
];
|
|
|
|
public function commune(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Commune::class);
|
|
}
|
|
|
|
public function commande(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Commande::class);
|
|
}
|
|
|
|
public function getEstSousGarantieAttribute(): bool
|
|
{
|
|
if (!$this->date_fin_garantie) {
|
|
return false;
|
|
}
|
|
|
|
return Carbon::now()->isBefore($this->date_fin_garantie);
|
|
}
|
|
|
|
public function getGarantieExpireeAttribute(): bool
|
|
{
|
|
if (!$this->date_fin_garantie) {
|
|
return false;
|
|
}
|
|
|
|
return Carbon::now()->isAfter($this->date_fin_garantie);
|
|
}
|
|
|
|
public function getEstProcheExpirationGarantieAttribute(): bool
|
|
{
|
|
if (!$this->date_fin_garantie || $this->garantie_expiree) {
|
|
return false;
|
|
}
|
|
|
|
return Carbon::now()->diffInDays($this->date_fin_garantie, false) <= 30;
|
|
}
|
|
}
|