61 lines
1.3 KiB
PHP
61 lines
1.3 KiB
PHP
<?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);
|
|
}
|
|
}
|