'date', 'date_echeance' => 'date', 'montant' => 'decimal:2', ]; const STATUTS_LABELS = [ 'actif' => 'Actif', 'a_renouveler' => 'À renouveler', 'expire' => 'Expiré', 'resilie' => 'Résilié', ]; public function fournisseur(): BelongsTo { return $this->belongsTo(Fournisseur::class); } public function service(): BelongsTo { return $this->belongsTo(Service::class); } public function piecesJointes(): HasMany { return $this->hasMany(PieceJointe::class)->orderByDesc('created_at'); } // Un contrat est considéré "proche d'expiration" si l'échéance est dans moins de 30 jours (ou selon son préavis) public function getEstProcheEcheanceAttribute(): bool { if (!$this->date_echeance || in_array($this->statut, ['resilie', 'expire'])) { return false; } $joursAvantAlerte = $this->preavis_jours > 0 ? $this->preavis_jours + 15 : 30; return Carbon::now()->diffInDays($this->date_echeance, false) <= $joursAvantAlerte; } public function getEstEnRetardAttribute(): bool { if (!$this->date_echeance || $this->statut === 'resilie') { return false; } return Carbon::now()->isAfter($this->date_echeance); } }