@extends('layouts.admin') @section('head') @endsection @section('page-title') Détails de l'intervention @endsection @section('page-subtitle') Informations complètes sur l'intervention @endsection @section('styles') @endsection @section('scripts') @endsection @section('content')

Historique d'activité

@include('admin.interventions.partials.activity_history')

Informations du client

@php // Default values in case $client is null $clientDisplayName = 'Client inconnu'; $clientTypeIcon = 'fa-user'; $clientTypeText = 'Particulier'; $logoUrl = null; if ($client) { // Use accessors from $client passed by the controller $clientDisplayName = $client->client_display_name ?? ($client->client_name ?? 'Client inconnu'); $clientTypeIcon = $client->type_icon ?? 'fa-user'; $clientTypeText = $client->display_type ?? 'Particulier'; $logoUrl = $client->logo_url; // Accessor handles path logic and asset() } $fullAddress = 'Adresse inconnue'; // Default $floorInfo = null; $sideInfo = null; // PRIORITÉ : Utiliser l'adresse spécifique stockée dans l'intervention if (!empty($intervention->address)) { $fullAddress = $intervention->address; // Afficher l'étage et le côté depuis l'adresse client si disponible, // même si l'address_id ne correspond pas (ex: adresse saisie manuellement) if ($clientAddressObj) { $floorInfo = $clientAddressObj->floor ?? null; $sideInfo = $clientAddressObj->side ?? null; } } else { // FALLBACK : Construire l'adresse à partir des composants du client seulement si pas d'adresse dans l'intervention if ($clientAddressObj) { $_addressParts = []; if (!empty($clientAddressObj->street)) { $_addressParts[] = trim($clientAddressObj->street); } $_cityPostalParts = []; if (!empty($clientAddressObj->postal_code)) { $_cityPostalParts[] = trim($clientAddressObj->postal_code); } if (!empty($clientAddressObj->city)) { $_cityPostalParts[] = trim($clientAddressObj->city); } if (!empty($_cityPostalParts)) { $_addressParts[] = implode(' ', $_cityPostalParts); } if (!empty($_addressParts)) { $fullAddress = implode(', ', $_addressParts); } else { // If constructed address is empty, try client's full_address field as a fallback for client if (!empty($clientAddressObj->full_address)) { $fullAddress = $clientAddressObj->full_address; } } $floorInfo = $clientAddressObj->floor ?? null; $sideInfo = $clientAddressObj->side ?? null; } } // Final check if address is effectively empty if (empty(trim(str_replace(',', '', $fullAddress ?? '')))) { $fullAddress = 'Adresse inconnue'; } @endphp
@if($logoUrl) @else @endif
{{ $clientTypeText }}
{{ $fullAddress }}
@if(!empty($floorInfo))
Étage : {{ $floorInfo }}
@endif @if(!empty($sideInfo))
Côté : {{ $sideInfo }}
@endif

Informations de l'intervention

Intervention n° @if(isset($intervention)) {{ !empty($intervention['task_id']) ? $intervention['task_id'] : $intervention['id'] }} @else 123 @endif @php // Utiliser directement le statut réel de l'intervention depuis la base de données $currentStatus = $intervention['status'] ?? 'new'; // Par défaut 'new' si non défini // Textes des statuts $statusTexts = [ 'new' => 'Non attribuée', 'in_progress' => 'En cours', 'late' => 'En retard', 'planned' => 'Planifiée', 'completed' => 'Terminée' ]; $currentStatusText = $statusTexts[$currentStatus] ?? 'Non attribuée'; @endphp {{ $currentStatusText }}
PRIORITÉ
@php // Determine priority and ID from intervention data (assuming $intervention is an array) $intervention_priority = 'normal'; // Default if (isset($intervention['content']['priority']) && !empty($intervention['content']['priority'])) { $intervention_priority = $intervention['content']['priority']; } elseif (isset($intervention['priority']) && !empty($intervention['priority'])) { $intervention_priority = $intervention['priority']; } // Set display class and icon based on priority $priority_badge_class = ($intervention_priority === 'urgent') ? 'priority-badge--urgent' : 'priority-badge--normal'; $priority_font_icon = ($intervention_priority === 'urgent') ? 'fa-exclamation-triangle' : 'fa-check-circle'; // Get intervention ID (assuming $intervention is an array) $intervention_id = $intervention['id'] ?? null; @endphp
{{-- Badge de priorité --}} {{ ucfirst($intervention_priority) }} {{-- Bouton de modification de priorité avec popover --}}
DEADLINE
{{-- Structure HTML standardisée pour l'affichage de la deadline --}} @if(isset($intervention['formatted_deadline']) && $intervention['formatted_deadline'] != 'Non définie') @php $deadlineDisplay = $intervention['formatted_deadline']; // Ajouter le jour de la semaine si deadline_raw est disponible if (isset($intervention['deadline_raw']) && $intervention['deadline_raw']) { try { $deadlineObj = new \DateTime($intervention['deadline_raw']); $dayNames = ['dim.', 'lun.', 'mar.', 'mer.', 'jeu.', 'ven.', 'sam.']; $dayOfWeek = $dayNames[$deadlineObj->format('w')]; $deadlineDisplay = $dayOfWeek . ' ' . $intervention['formatted_deadline']; } catch (\Exception $e) { $deadlineDisplay = $intervention['formatted_deadline']; // Fallback } } @endphp
{{ $deadlineDisplay }} @if($intervention->days_remaining_text && !in_array(strtolower($intervention->status ?? ''), ['completed', 'terminées', 'terminée'])) {{ $intervention->days_remaining_text }} @endif
@else
Non définie
@endif
DATE D'INTERVENTION
@php $interventionDateFromController = $intervention['intervention_date'] ?? null; // A date is considered set if it's not null, not an empty string, // and not the specific placeholder string 'Non programmée'. $hasInterventionDate = ($interventionDateFromController !== null && $interventionDateFromController !== '' && $interventionDateFromController !== 'Non programmée'); @endphp @if($hasInterventionDate) @php $formattedDateDisplay = $interventionDateFromController; $formattedDateWithDay = $interventionDateFromController; try { if (strtotime($interventionDateFromController)) { $dateObj = new DateTime($interventionDateFromController); $formattedDateDisplay = $dateObj->format('d/m/Y'); // Ajouter le jour de la semaine $dayNames = ['dim.', 'lun.', 'mar.', 'mer.', 'jeu.', 'ven.', 'sam.']; $dayOfWeek = $dayNames[$dateObj->format('w')]; $formattedDateWithDay = $dayOfWeek . ' ' . $formattedDateDisplay; } } catch (\Exception $e) { // Log::error('Date formatting error: ' . $e->getMessage()); $formattedDateWithDay = $formattedDateDisplay; // Fallback } @endphp
{{ $formattedDateWithDay }}
@else Non définie @endif
DATE DE FIN D'INTERVENTION
@if(isset($intervention['is_finished']) && $intervention['is_finished'])
Terminée par :
@if(isset($intervention['finished_by'])) @php $finishedByUser = \App\Models\User::find($intervention['finished_by']); @endphp {{ $finishedByUser ? $finishedByUser->prenom . ' ' . $finishedByUser->nom : 'Utilisateur inconnu' }} @else Utilisateur inconnu @endif
@php $finishedAtDisplay = 'Date inconnue'; if (isset($intervention['finished_at'])) { try { $finishedAtObj = \Carbon\Carbon::parse($intervention['finished_at']); $dayNames = ['dim.', 'lun.', 'mar.', 'mer.', 'jeu.', 'ven.', 'sam.']; $dayOfWeek = $dayNames[$finishedAtObj->format('w')]; $finishedAtDisplay = $dayOfWeek . ' ' . $finishedAtObj->format('d/m/Y H:i'); } catch (\Exception $e) { $finishedAtDisplay = \Carbon\Carbon::parse($intervention['finished_at'])->format('d/m/Y H:i'); } } @endphp {{ $finishedAtDisplay }}
@else Non terminée @endif
{{-- Bouton Terminer l'intervention --}} @if(!isset($intervention['is_finished']) || !$intervention['is_finished'])
@endif

Objet

{{ $intervention['title'] ?? 'Réparation plomberie' }}

Description

{{ $intervention['description'] ?: 'Aucune description disponible' }}

Intervenant(s) assigné(s)

@include('admin.interventions.partials._assigned_workers_list', ['intervention' => $intervention])

Médias(s) de l'intervention

Média(s) de fin d'intervention

Commentaires

@php // Décoder les commentaires JSON $comments = []; if (isset($intervention->comments) && !empty($intervention->comments)) { try { if (is_string($intervention->comments)) { $comments = json_decode($intervention->comments, true) ?? []; } elseif (is_array($intervention->comments)) { $comments = $intervention->comments; } } catch (\Exception $e) { // En cas d'erreur de décodage, laisser $comments comme un tableau vide } } // Trier les commentaires par date (plus anciens d'abord) usort($comments, function($a, $b) { $dateA = isset($a['date']) ? strtotime($a['date']) : 0; $dateB = isset($b['date']) ? strtotime($b['date']) : 0; return $dateA - $dateB; // Ordre croissant }); // Fonction pour formater les dates de manière conviviale function formatFriendlyDate($dateString) { $date = new DateTime($dateString); $now = new DateTime(); $yesterday = new DateTime('yesterday'); if ($date->format('Y-m-d') === $now->format('Y-m-d')) { return 'Aujourd\'hui à ' . $date->format('H:i'); } elseif ($date->format('Y-m-d') === $yesterday->format('Y-m-d')) { return 'Hier à ' . $date->format('H:i'); } else { return $date->format('d/m/Y H:i'); } } @endphp
{{ count($comments) }} commentaire(s)
@if(count($comments) > 0) @foreach($comments as $index => $comment) @php $isWorkerComment = isset($comment['author_type']) && $comment['author_type'] === 'worker'; $commentClass = $isWorkerComment ? 'worker-comment' : 'admin-comment'; $avatarColor = $isWorkerComment ? '#1976d2' : '#f57c00'; // Extraire les initiales du nom $authorName = $comment['author'] ?? 'Utilisateur'; $initials = ''; $nameParts = explode(' ', trim($authorName)); foreach($nameParts as $part) { if (!empty($part)) { $initials .= strtoupper(substr($part, 0, 1)); } } if (empty($initials)) { $initials = 'U'; } @endphp
{{ $initials }}
{{ $authorName }} {{ $isWorkerComment ? 'Intervenant' : 'Admin' }} {{ isset($comment['date']) ? formatFriendlyDate($comment['date']) : date('d/m/Y H:i') }}
{{ $comment['text'] ?? '' }}
@endforeach @else

Aucun commentaire pour cette intervention

@endif
@csrf
{{-- Modal Terminer l'intervention --}} @endsection