feat: infrastructure assets management with warranty tracking and EAN lookup integration
This commit is contained in:
71
app/Models/Asset.php
Normal file
71
app/Models/Asset.php
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user