feat: infrastructure assets management with warranty tracking and EAN lookup integration
This commit is contained in:
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