feat: infrastructure assets management with warranty tracking and EAN lookup integration
This commit is contained in:
104
app/Http/Controllers/CalendarController.php
Normal file
104
app/Http/Controllers/CalendarController.php
Normal file
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Contrat;
|
||||
use App\Models\Licence;
|
||||
use App\Models\Domaine;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
|
||||
class CalendarController extends Controller
|
||||
{
|
||||
public function index(): Response
|
||||
{
|
||||
return Inertia::render('Calendar/Index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch events for FullCalendar.
|
||||
*/
|
||||
public function events(Request $request)
|
||||
{
|
||||
$events = [];
|
||||
|
||||
// 1. Contracts expirations
|
||||
$contrats = Contrat::with(['fournisseur', 'service'])
|
||||
->whereNotNull('date_echeance')
|
||||
->get();
|
||||
|
||||
foreach ($contrats as $contrat) {
|
||||
$events[] = [
|
||||
'id' => 'contrat-' . $contrat->id,
|
||||
'title' => '📑 ' . $contrat->titre . ' (' . ($contrat->fournisseur->nom ?? 'N/A') . ')',
|
||||
'start' => $contrat->date_echeance->toDateString(),
|
||||
'url' => route('contrats.show', $contrat->id),
|
||||
'backgroundColor' => $this->getContratColor($contrat),
|
||||
'extendedProps' => [
|
||||
'type' => 'Contrat',
|
||||
'service' => $contrat->service->nom ?? 'N/A',
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
// 2. Licenses expirations
|
||||
$licences = Licence::with(['fournisseur'])
|
||||
->whereNotNull('date_expiration')
|
||||
->get();
|
||||
|
||||
foreach ($licences as $licence) {
|
||||
$events[] = [
|
||||
'id' => 'licence-' . $licence->id,
|
||||
'title' => '🔑 ' . $licence->nom . ' (' . ($licence->fournisseur->nom ?? 'N/A') . ')',
|
||||
'start' => $licence->date_expiration->toDateString(),
|
||||
'url' => route('licences.index'), // Link to index or show if implemented
|
||||
'backgroundColor' => '#3498db',
|
||||
'extendedProps' => [
|
||||
'type' => 'Licence',
|
||||
'usage' => $licence->nombre_sieges_utilises . '/' . $licence->nombre_sieges_total,
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
// 3. Domain expirations
|
||||
$domaines = Domaine::whereNotNull('date_echeance')->get();
|
||||
foreach ($domaines as $domaine) {
|
||||
$events[] = [
|
||||
'id' => 'domaine-' . $domaine->id,
|
||||
'title' => '🌐 ' . $domaine->nom,
|
||||
'start' => $domaine->date_echeance->toDateString(),
|
||||
'url' => route('domaines.index'),
|
||||
'backgroundColor' => '#9b59b6',
|
||||
'extendedProps' => [
|
||||
'type' => 'Domaine',
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
// 4. Asset warranties
|
||||
$assets = \App\Models\Asset::whereNotNull('date_fin_garantie')->get();
|
||||
foreach ($assets as $asset) {
|
||||
$events[] = [
|
||||
'id' => 'asset-' . $asset->id,
|
||||
'title' => '🛠️ Garantie : ' . $asset->nom . ' (' . $asset->type . ')',
|
||||
'start' => $asset->date_fin_garantie->toDateString(),
|
||||
'url' => route('assets.show', $asset->id),
|
||||
'backgroundColor' => $asset->garantie_expiree ? '#e74c3c' : '#f1c40f',
|
||||
'extendedProps' => [
|
||||
'type' => 'Asset (Garantie)',
|
||||
'statut' => $asset->statut,
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
return response()->json($events);
|
||||
}
|
||||
|
||||
private function getContratColor($contrat): string
|
||||
{
|
||||
if ($contrat->statut === 'expire') return '#e74c3c';
|
||||
if ($contrat->est_proche_echeance) return '#f39c12';
|
||||
return '#27ae60';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user