{{-- Appointments section --}} @php $visit_date_free_hours = \App\Models\FreeHour::where('free_hour_date', $appointment_date) ->whereIn('user_id', $drivers) ->get(); @endphp
@foreach($time_blocks as $time_block)
{{ agendaDisplayDate($appointment_date) }} - {{ $time_block->start_time }} - {{ $time_block->end_time }}
@if($appointments->has($appointment_date)) @if($appointments->get($appointment_date)->has($time_block->id)) @foreach($appointments->get($appointment_date)->get($time_block->id) as $driver_id => $driver_appointments) @php $driver = \App\Models\User::where('id', $driver_id) ->with('freeHours', function($q) use ($appointment_date){ $q->where('free_hour_date', $appointment_date); }) ->first(); $driver_appointments = $driver_appointments->sortBy('visit_time'); // Removin duplicate appointments which has same supplir and visit time, just need to one with counts $filtered_appointments = []; foreach($driver_appointments as $key => $driver_appointment){ if($driver_appointment->article){ $key = $driver_appointment->article->supplier_id.'-'.$driver_appointment->article->task_time; if(array_key_exists($key, $filtered_appointments)){ $filtered_appointments[$key]->total_count++; }else{ $driver_appointment->total_count = 1; $filtered_appointments[$key] = $driver_appointment; } }else{ $filtered_appointments[] = $driver_appointment; } } // end combining @endphp
@foreach($filtered_appointments as $driver_appointment) @php switch (count($filtered_appointments)){ case 1: $col_parts = 12; break; case 2: $col_parts = 6; break; default: $col_parts = 4; break; } @endphp
@endforeach
@endforeach {{-- @include('agendas.agenda.free-hour', [ 'visit_date_free_hours' => $visit_date_free_hours, 'visit_time_block' => $time_block, 'appointments_available' => true ]) --}} @else @include('agendas.agenda.free-hour', [ 'visit_date_free_hours' => $visit_date_free_hours, 'visit_time_block' => $time_block, 'appointments_available' => false ]) @endif @else @include('agendas.agenda.free-hour', [ 'visit_date_free_hours' => $visit_date_free_hours, 'visit_time_block' => $time_block, 'appointments_available' => false ]) @endif
@endforeach