@php $familyRows = collect(); foreach ($activeEmployers as $employer) { $children = $employer->children->whereNull('archived_at'); $contracts = $employer->children->flatMap->contracts; $familyRows->push([ 'employer' => $employer, 'parentName' => $employer->display_name, 'addedAt' => $employer->created_at?->format('d/m/Y') ?? '—', 'childrenNames' => $children->pluck('first_name')->filter()->join(', '), 'children' => $children->filter(fn ($child) => $child->avatar || filled($child->first_name)), 'contractsCount' => $contracts->count(), 'activeContractsCount' => $contracts->where('status', 'active')->count(), 'draftContractsCount' => $contracts->whereIn('status', ['draft', 'to_sign'])->count(), 'canDelete' => ! $contracts->contains(fn ($contract) => $contract->status === 'active'), ]); } $sortUrl = function (string $column) use ($sort, $direction): string { $query = request()->except(['sort', 'direction', 'page']); if ($sort !== $column) { $query['sort'] = $column; $query['direction'] = 'asc'; } elseif ($direction === 'asc') { $query['sort'] = $column; $query['direction'] = 'desc'; } return request()->url().($query ? '?'.http_build_query($query) : ''); }; $sortIndicator = fn (string $column): string => $sort === $column ? ($direction === 'asc' ? '↑' : '↓') : ''; @endphp

Enfants et parents employeurs

@if ($familyRows->isNotEmpty())
@foreach ($familyRows as $row) @php $employer = $row['employer']; @endphp @endforeach
Famille{{ $sortIndicator('family') }} Enfant(s){{ $sortIndicator('children') }} Parent employeur{{ $sortIndicator('parent') }} Contrats Ajoutée le{{ $sortIndicator('added_at') }} Actions
Total{{ $sortIndicator('contracts_total') }} Actif(s){{ $sortIndicator('contracts_active') }} Projet(s){{ $sortIndicator('contracts_draft') }}
{{ $employer->family_label }} @if ($row['children']->isEmpty()) Aucun enfant renseigné @else
@foreach ($row['children']->filter(fn ($child) => $child->avatar) as $child) first_name)) data-name="{{ $child->first_name }}" @endif> @if (filled($child->first_name)) {{ $child->first_name }} @endif @endforeach @if (($withoutAvatar = $row['children']->reject(fn ($child) => $child->avatar)->pluck('first_name')->filter()->join(', ')) !== '') {{ $withoutAvatar }} @endif
@endif
{{ $row['parentName'] }} {{ $row['contractsCount'] }} {{ $row['activeContractsCount'] }} {{ $row['draftContractsCount'] }} {{ $row['addedAt'] }}
@if ($row['canDelete'])
@csrf @method('patch')
@endif
@foreach ($familyRows as $row) @php $employer = $row['employer']; @endphp
Contrats {{ $row['contractsCount'] }}
Actif(s) {{ $row['activeContractsCount'] }}
Projet(s) {{ $row['draftContractsCount'] }}
@forelse ($row['children'] as $child) @if ($child->avatar) @if (filled($child->first_name)) {{ $child->first_name }} @endif @else {{ $child->first_name }} @endif @empty Aucun enfant renseigné @endforelse
@if ($row['canDelete'])
@endif
@endforeach
{{ $activeEmployers->links() }}
@else
Aucun parent employeur pour le moment.
@endif @if ($archivedEmployers->isNotEmpty())

Historique archivé

{{ $archivedEmployers->count() }} parent(s) employeur(s)
@endif