@extends('layouts.base') @section('content') @section('breadcrumb') @endsection

Clients @if(!isset($allApplications) || $allApplications->count() === 1) - {{ $application->name }} @endif

@if(isset($allApplications) && $allApplications->count() > 1) Gérez les clients de vos applications @else Gérez les clients de votre application @endif

@if(!isset($allApplications) || $allApplications->count() === 1)
Créer un client
@endif
Filtres
@if(isset($allApplications) && $allApplications->count() > 1)
@endif
@php $hasMultipleApplications = isset($allApplications) && $allApplications->count() > 1; @endphp @if($hasMultipleApplications && isset($clientsByApplication)) {{-- Affichage avec plusieurs tableaux (une par application) --}} @foreach($allApplications as $app) @php $appClients = $clientsByApplication[$app->id] ?? collect(); $appPrograms = $app->programs()->get(); $appUsers = $app->users()->get(); @endphp @if($appClients->isNotEmpty() || $app->id == $application->id)
{{ $app->name }} ({{ $appClients->count() }} client{{ $appClients->count() > 1 ? 's' : '' }})
@if($appClients->isEmpty())

Aucun client pour cette application

@else
@foreach($appClients as $client) @endforeach
Nom Prénom Email Nombre de dossiers actifs Nombre de ventes signées Commercialisateur associé Date de création Actions
{{ $client->lastname ?? '-' }} {{ $client->firstname ?? '-' }} {{ $client->email }} {{ $client->active_dossiers_count ?? 0 }} {{ $client->ventes_count ?? 0 }} @php $applicationUserIds = $app->users->pluck('id')->toArray(); $commercialisateur = $client->user ?: $client->options->first()?->user; if ($commercialisateur && !in_array($commercialisateur->id, $applicationUserIds)) { $commercialisateur = null; } @endphp @if($commercialisateur) {{ $commercialisateur->firstname }} {{ $commercialisateur->lastname }} @else - @endif {{ $client->created_at->format('d/m/Y') }}
@endif
@endif @endforeach @else {{-- Affichage classique avec pagination (une seule application) --}} @if($clients->isEmpty())
Aucun client disponible

Vos clients apparaîtront ici une fois qu'ils seront associés à vos applications.

@else
Liste des clients ({{ $clients->total() }})
@foreach($clients as $client) @endforeach
Nom @if(request('sort_by') == 'lastname') @endif Prénom @if(request('sort_by') == 'firstname') @endif Email @if(request('sort_by') == 'email') @endif Nombre de dossiers actifs Nombre de ventes signées Commercialisateur associé @if(request('sort_by') == 'commercialisateur') @endif Date de création @if(request('sort_by') == 'created_at' || !request('sort_by')) @endif Actions
{{ $client->lastname ?? '-' }} {{ $client->firstname ?? '-' }} {{ $client->email }} {{ $client->active_dossiers_count ?? 0 }} {{ $client->ventes_count ?? 0 }} @php // Commercialisateur associé directement au client (champ user_id), // sinon on retombe sur le commercialisateur du premier dossier. // On vérifie que le commercialisateur appartient à l'application $applicationUserIds = $application->users->pluck('id')->toArray(); $commercialisateur = $client->user ?: $client->options->first()?->user; // Filtrer pour ne garder que les users de l'application if ($commercialisateur && !in_array($commercialisateur->id, $applicationUserIds)) { $commercialisateur = null; } @endphp @if($commercialisateur) {{ $commercialisateur->firstname }} {{ $commercialisateur->lastname }} @else - @endif {{ $client->created_at->format('d/m/Y') }}
{{ $clients->links() }}
@endif @endif
@push('scripts') @endpush @endsection