@extends('layouts.base') @section('content') @section('breadcrumb') @endsection @if(session('success')) @endif
@php $firstInitial = strtoupper(substr($client->firstname ?? '', 0, 1)); $lastInitial = strtoupper(substr($client->lastname ?? '', 0, 1)); $initials = $firstInitial . $lastInitial; @endphp @if($initials) {{ $initials }} @endif

{{ $client->firstname ?? '-' }} {{ $client->lastname ?? '-' }}

{{ $client->email }} {{ format_phone_display($client->phones?->first()?->value ?? null) }} {{ $client->address?->city ?? '-' }}
@php $notesCount = \App\Models\Note::where('noteable_type', \App\Models\Client::class) ->where('noteable_id', $client->id) ->count(); $activeTab = session('open_tab') === 'documents' ? 'documents' : 'informations'; @endphp

{{ $client->civility?->value ?? '-' }} {{ $client->firstname ?? '-' }} {{ $client->lastname ?? '-' }}

{{ $client->birthdate?->format('d/m/Y') ?? '-' }} @php $age = $client->birthdate ? \Carbon\Carbon::parse($client->birthdate)->age : null; @endphp @if($age !== null) {{ $age }} ans @endif

@if($client->profession)

{{ $client->profession ?? '-' }}

@endif

{{ $client->email }}

@if($client->phones && $client->phones->count() > 0) @foreach($client->phones as $phone)

{{ format_phone_display($phone->value) }} {{ $phone->type?->label() ?? '-' }}
@endforeach @endif

@php $address = $client->address?->line_1 ?? '' . ($client->address?->line_2 ? ', ' . $client->address->line_2 : '') . ($client->address?->zip_code || $client->address?->city ? ', ' . $client->address?->zip_code . ' ' . $client->address?->city : ''); @endphp {{ $client->address?->line_1 ?? '' }} @if($client->address?->line_2) {{ $client->address->line_2 ? ', ' . $client->address->line_2 : '' }} @endif @if($client->address?->zip_code || $client->address?->city) , {{ $client->address?->zip_code ?? '-' }} {{ $client->address?->city ?? '-' }} @endif

@if($client->situation_matrimoniale)

Situation matrimoniale

@if($client->date_mariage_pacs)

{{ $client->situation_matrimoniale?->label() ?? '' }} le {{ $client->date_mariage_pacs?->format('d/m/Y') ?? '-' }} {{ $client->lieu_mariage_pacs ? 'à ' . $client->lieu_mariage_pacs : '' }}

@if($client->regime_matrimonial)

Sous le régime matrimonial de la {{ $client->regime_matrimonial?->label() ?? '-' }}

@endif @else

{{ $client->situation_matrimoniale?->label() ?? '' }}

@endif @if($client->date_divorce)

Date de divorce : {{ $client->date_divorce?->format('d/m/Y') ?? '-' }}

@endif @endif

#{{ $client->id }}

Ajouté le {{ $client->created_at->format('d/m/Y H:i') }}

Commercialisateurs

@php // Commercialisateur associé directement au client (champ user_id), // sinon on retombe sur le commercialisateur du premier dossier. // Si le client a un user_id directement associé, on l'affiche toujours // car le client lui-même appartient à l'application. // Sinon, on vérifie que le commercialisateur appartient à l'application // et qu'il a bien le rôle ROLE_COMMERCIALISATEUR. $applicationUserIds = $application->users->pluck('id')->toArray(); if ($client->user) { // Le client a un user_id directement associé, on l'affiche $commercialisateur = $client->user; } else { // Sinon, on cherche dans les options et on vérifie l'appartenance à l'application $commercialisateur = $client->options->first()?->user; } if ($commercialisateur && !in_array($commercialisateur->id, $applicationUserIds)) { $commercialisateur = null; } if ($commercialisateur && !$commercialisateur->isRole(\App\Enums\Role::ROLE_COMMERCIALISATEUR->name)) { $commercialisateur = null; } @endphp @if($commercialisateur)
{{ $commercialisateur->firstname[0] }} {{ $commercialisateur->lastname[0] }} {{ $commercialisateur->firstname }} {{ $commercialisateur->lastname }}
@else Pas de commercialisateur associé @endif

Commercialisateurs rattachés
@if($commercialisateurs->isEmpty())

Aucun commercialisateur rattaché

@else
@foreach($commercialisateurs as $user) @php $options = $client->options()->where('user_id', $user->id)->get(); @endphp @endforeach
Nom du commercialisateur Réseau Lien vers le dossier de vente
{{ $user->firstname }} {{ $user->lastname }} @if($user->companies->first()) {{ $user->companies->first()->name }} @else - @endif @if($options->isNotEmpty()) @foreach($options as $opt) Dossier #{{ $opt->id }} @endforeach @else - @endif
@endif
@csrf
@php // Charger les notes explicitement avec l'utilisateur $notes = \App\Models\Note::where('noteable_type', \App\Models\Client::class) ->where('noteable_id', $client->id) ->with('user') ->orderBy('created_at', 'desc') ->get(); @endphp @if($notes->isEmpty())

Aucune note

@else @foreach($notes->sortByDesc('created_at') as $note)

{{ $note->content }}

@csrf @method('PUT')

{{ $note->created_at->format('d/m/Y') }} @if($note->user) @php $firstInitial = strtoupper(substr($note->user->firstname ?? '', 0, 1)); $lastInitial = strtoupper(substr($note->user->lastname ?? '', 0, 1)); $initials = $firstInitial . $lastInitial; @endphp @if($initials) {{ $initials }} @endif {{ $note->user->firstname }} {{ $note->user->lastname }} @endif
@endforeach @endif
@if($dossiersActifs->isEmpty())

Aucun dossier actif

@else
@foreach($dossiersActifs as $option) @php $product = $option->product; $program = $product?->program; // Fiscalité : d'abord celle du lot, sinon celle du programme $fiscalite = $product?->fiscalites->first(); if (!$fiscalite && $program && $program->fiscalites && $program->fiscalites->count() > 0) { $fiscalite = $program->fiscalites->first(); } $prix = $option->prices->where('type', 'prix_ttc')->first() ?? $product?->prices->where('type', 'prix_ttc')->first(); $currentState = $option->state; $dateReservation = $option->states()->where('type', \App\Enums\OptionState::CONFIRMED->value)->first()?->created_at; @endphp @php $reservation = $option->latestReservation; $currentTaskReservation = $reservation ? $reservation->taskReservations ->where('state', \App\Enums\TaskState::EN_COURS) ->first() : null; @endphp @endforeach
Programme Fiscalité Commercialisateur Option Réservation Prix Statut du dossier
{{ $program?->name ?? '-' }}
{{ $product?->name ?? 'Lot ' . ($product?->number ?? '-') }}
{{ $fiscalite?->type?->label() ?? '-' }} @if($option->user) {{ $option->user->firstname }} {{ $option->user->lastname }} @else Aucun utilisateur @endif {{ $option->created_at->format('d/m/Y') }} {{ $dateReservation?->format('d/m/Y') ?? '-' }} @if($prix) {{ number_format($prix->value, 0, ',', ' ') }} € @else - @endif @if($currentTaskReservation && $currentTaskReservation->task) {{ $currentTaskReservation->task->name }} @elseif($reservation) Aucune tâche en cours @else {{ $currentState?->label() ?? '-' }} @endif @if($reservation) @else @endif
@endif
@if($historiqueVentes->isEmpty())

Aucune vente dans l'historique

@else
@foreach($historiqueVentes as $option) @php $product = $option->product; $program = $product?->program; $prix = $option->prices->where('type', 'prix_ttc')->first() ?? $product?->prices->where('type', 'prix_ttc')->first(); $currentState = $option->state; $dateArchivage = $option->states()->whereIn('type', [ \App\Enums\OptionState::CANCELED->value, \App\Enums\OptionState::CONFIRMED->value, ])->first()?->created_at ?? $option->updated_at; $reservation = $option->latestReservation; // Pour l'historique des ventes, afficher en priorité la tâche CONTRAT_SIGNE si elle existe $currentTaskReservation = null; if ($reservation) { $currentTaskReservation = $reservation->taskReservations ->filter(function ($taskReservation) { return $taskReservation->task && $taskReservation->task->type === \App\Enums\TaskType::CONTRAT_SIGNE; }) ->sortByDesc('created_at') ->first(); } @endphp @endforeach
Programme Archivage Commercialisateur Prix Statut du dossier
{{ $program?->name ?? '-' }}
{{ $product?->name ?? 'Lot ' . ($product?->number ?? '-') }}
{{ $dateArchivage->format('d/m/Y') }} @if($option->user) {{ $option->user->firstname }} {{ $option->user->lastname }} @else Aucun utilisateur @endif @if($prix) {{ number_format($prix->value, 0, ',', ' ') }} € @else - @endif @if($currentTaskReservation && $currentTaskReservation->task) {{ $currentTaskReservation->task->name }} @elseif($reservation) Aucune tâche en cours @else {{ $currentState?->label() ?? '-' }} @endif
@endif
@if($documents->isNotEmpty()) Télécharger le dossier ZIP @endif @if($documents->isEmpty())

Aucun document

@else
@foreach($documents as $document) @endforeach
Titre du document Type de document Ajouté le
{{ $document->name }} {{ $document->type }} {{ $document->created_at->format('d/m/Y H:i') }}
@endif
@push('scripts') @endpush @endsection