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;
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ class Commande extends Model
|
||||
use SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
'numero_commande', 'service_id', 'fournisseur_id', 'user_id',
|
||||
'numero_commande', 'service_id', 'fournisseur_id', 'user_id', 'commune_id',
|
||||
'validateur_id', 'acheteur_id', 'objet', 'description', 'justification',
|
||||
'statut', 'priorite', 'reference_fournisseur', 'imputation_budgetaire',
|
||||
'montant_ht', 'montant_ttc',
|
||||
@@ -98,11 +98,21 @@ class Commande extends Model
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
|
||||
public function commune(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Commune::class);
|
||||
}
|
||||
|
||||
public function validateur(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'validateur_id');
|
||||
}
|
||||
|
||||
public function assets(): HasMany
|
||||
{
|
||||
return $this->hasMany(Asset::class);
|
||||
}
|
||||
|
||||
public function acheteur(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'acheteur_id');
|
||||
|
||||
21
app/Models/Commune.php
Normal file
21
app/Models/Commune.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Commune extends Model
|
||||
{
|
||||
protected $fillable = ['nom', 'code_postal'];
|
||||
|
||||
public function commandes(): HasMany
|
||||
{
|
||||
return $this->hasMany(Commande::class);
|
||||
}
|
||||
|
||||
public function contrats(): HasMany
|
||||
{
|
||||
return $this->hasMany(Contrat::class);
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ class Contrat extends Model
|
||||
'description',
|
||||
'fournisseur_id',
|
||||
'service_id',
|
||||
'commune_id',
|
||||
'date_debut',
|
||||
'date_echeance',
|
||||
'statut',
|
||||
@@ -47,11 +48,21 @@ class Contrat extends Model
|
||||
return $this->belongsTo(Service::class);
|
||||
}
|
||||
|
||||
public function commune(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Commune::class);
|
||||
}
|
||||
|
||||
public function piecesJointes(): HasMany
|
||||
{
|
||||
return $this->hasMany(PieceJointe::class)->orderByDesc('created_at');
|
||||
}
|
||||
|
||||
public function licences(): HasMany
|
||||
{
|
||||
return $this->hasMany(Licence::class);
|
||||
}
|
||||
|
||||
// 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
|
||||
{
|
||||
|
||||
60
app/Models/Licence.php
Normal file
60
app/Models/Licence.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class Licence extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'contrat_id',
|
||||
'fournisseur_id',
|
||||
'commune_id',
|
||||
'nom',
|
||||
'cle_licence',
|
||||
'nombre_sieges_total',
|
||||
'nombre_sieges_utilises',
|
||||
'date_acquisition',
|
||||
'date_expiration',
|
||||
'type_licence',
|
||||
'statut',
|
||||
'notes',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'date_acquisition' => 'date',
|
||||
'date_expiration' => 'date',
|
||||
'cle_licence' => 'encrypted', // Encrypted storage for license keys
|
||||
];
|
||||
|
||||
public function contrat(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Contrat::class);
|
||||
}
|
||||
|
||||
public function fournisseur(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Fournisseur::class);
|
||||
}
|
||||
|
||||
public function commune(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Commune::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the usage rate as a percentage.
|
||||
*/
|
||||
public function getTauxUtilisationAttribute(): float
|
||||
{
|
||||
if ($this->nombre_sieges_total <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return round(($this->nombre_sieges_utilises / $this->nombre_sieges_total) * 100, 2);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user