feat: infrastructure assets management with warranty tracking and EAN lookup integration
This commit is contained in:
118
app/Http/Controllers/LicenceController.php
Normal file
118
app/Http/Controllers/LicenceController.php
Normal file
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Commune;
|
||||
use App\Models\Contrat;
|
||||
use App\Models\Fournisseur;
|
||||
use App\Models\Licence;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
|
||||
class LicenceController extends Controller
|
||||
{
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$this->authorize('viewAny', Licence::class);
|
||||
|
||||
$query = Licence::with(['fournisseur', 'contrat', 'commune']);
|
||||
|
||||
if (!$request->user()->hasRole('admin')) {
|
||||
$query->where('commune_id', $request->user()->commune_id);
|
||||
}
|
||||
|
||||
$licences = $query->orderBy('date_expiration', 'asc')->paginate(20)->withQueryString();
|
||||
|
||||
return Inertia::render('Licences/Index', [
|
||||
'licences' => $licences,
|
||||
'filters' => $request->only(['search', 'commune_id', 'fournisseur_id']),
|
||||
'communes' => Commune::orderBy('nom')->get(),
|
||||
'fournisseurs' => Fournisseur::active()->orderBy('nom')->get(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function create(): Response
|
||||
{
|
||||
$this->authorize('create', Licence::class);
|
||||
|
||||
return Inertia::render('Licences/Form', [
|
||||
'contrats' => Contrat::orderBy('titre')->get(),
|
||||
'fournisseurs' => Fournisseur::active()->orderBy('nom')->get(),
|
||||
'communes' => Commune::orderBy('nom')->get(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$this->authorize('create', Licence::class);
|
||||
|
||||
$validated = $request->validate([
|
||||
'nom' => 'required|string|max:255',
|
||||
'contrat_id' => 'nullable|exists:contrats,id',
|
||||
'fournisseur_id' => 'required|exists:fournisseurs,id',
|
||||
'commune_id' => 'nullable|exists:communes,id',
|
||||
'cle_licence' => 'nullable|string',
|
||||
'nombre_sieges_total' => 'required|integer|min:1',
|
||||
'nombre_sieges_utilises' => 'required|integer|min:0',
|
||||
'date_acquisition' => 'nullable|date',
|
||||
'date_expiration' => 'nullable|date',
|
||||
'type_licence' => 'required|in:perpétuelle,abonnement',
|
||||
'statut' => 'required|in:active,expirée,résiliée',
|
||||
'notes' => 'nullable|string',
|
||||
]);
|
||||
|
||||
Licence::create($validated);
|
||||
|
||||
return redirect()->route('licences.index')
|
||||
->with('success', 'Licence créée avec succès.');
|
||||
}
|
||||
|
||||
public function edit(Licence $licence): Response
|
||||
{
|
||||
$this->authorize('update', $licence);
|
||||
|
||||
return Inertia::render('Licences/Form', [
|
||||
'licence' => $licence,
|
||||
'contrats' => Contrat::orderBy('titre')->get(),
|
||||
'fournisseurs' => Fournisseur::active()->orderBy('nom')->get(),
|
||||
'communes' => Commune::orderBy('nom')->get(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(Request $request, Licence $licence): RedirectResponse
|
||||
{
|
||||
$this->authorize('update', $licence);
|
||||
|
||||
$validated = $request->validate([
|
||||
'nom' => 'required|string|max:255',
|
||||
'contrat_id' => 'nullable|exists:contrats,id',
|
||||
'fournisseur_id' => 'required|exists:fournisseurs,id',
|
||||
'commune_id' => 'nullable|exists:communes,id',
|
||||
'cle_licence' => 'nullable|string',
|
||||
'nombre_sieges_total' => 'required|integer|min:1',
|
||||
'nombre_sieges_utilises' => 'required|integer|min:0',
|
||||
'date_acquisition' => 'nullable|date',
|
||||
'date_expiration' => 'nullable|date',
|
||||
'type_licence' => 'required|in:perpétuelle,abonnement',
|
||||
'statut' => 'required|in:active,expirée,résiliée',
|
||||
'notes' => 'nullable|string',
|
||||
]);
|
||||
|
||||
$licence->update($validated);
|
||||
|
||||
return redirect()->route('licences.index')
|
||||
->with('success', 'Licence mise à jour.');
|
||||
}
|
||||
|
||||
public function destroy(Licence $licence): RedirectResponse
|
||||
{
|
||||
$this->authorize('delete', $licence);
|
||||
|
||||
$licence->delete();
|
||||
|
||||
return redirect()->route('licences.index')
|
||||
->with('success', 'Licence supprimée.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user