feat: infrastructure assets management with warranty tracking and EAN lookup integration

This commit is contained in:
jeremy bayse
2026-04-09 21:51:43 +02:00
parent 3544c77bd1
commit b28c56c94c
46 changed files with 2961 additions and 414 deletions

71
app/Models/Asset.php Normal file
View File

@@ -0,0 +1,71 @@
<?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;
}
}