@section('title', 'مسار الزيارات اليومية')
@if(session('success'))
{{ session('success') }}
@endif @if(session('error'))
{{ session('error') }}
@endif @php $activeVisit = $visits->first(fn($v) => $v->status === 'checked_in'); @endphp @if($showVisitPanel && $activeVisit) {{-- ========== Active Visit Panel ========== --}}
● زيارة نشطة
{{ $activeVisit->sequence_no }}

{{ $activeVisit->customer->name_ar ?: $activeVisit->customer->name }}

{{ $activeVisit->customer->city }} · {{ $activeVisit->customer->phone }}

وقت دخول الزيارة: {{ \Carbon\Carbon::parse($activeVisit->check_in_at_utc)->setTimezone('Asia/Riyadh')->format('H:i') }}
إنشاء طلب لهذا العميل @php $todayOrders = $this->getOrdersForCustomer($activeVisit->customer_id); @endphp @if($todayOrders->count() > 0)
@endif
@else {{-- ========== Route slider + visits list ========== --}}
@foreach($weekDays as $d) @php $active = $visitDate === $d['date']; @endphp @endforeach
الزيارات المكتملة: {{ $visits->where('status', 'completed')->count() }} من أصل {{ $visits->count() }} @if($visits->count() > 0) {{ min(100, round(($visits->where('status', 'completed')->count() / $visits->count()) * 100)) }}% منجز @else لا يوجد زيارات @endif
@forelse($visits as $v) @php $statusColor = match($v->status) { 'checked_in' => 'bg-amber-50 border-amber-100 text-amber-600', 'completed' => 'bg-emerald-50 border-emerald-100 text-emerald-600', 'skipped' => 'bg-slate-100 border-slate-200 text-slate-500', default => 'bg-blue-50 border-blue-100 text-[#00316D]', }; $statusLabel = match($v->status) { 'checked_in' => 'تم تسجيل الدخول', 'completed' => 'زيارة مكتملة', 'skipped' => 'تم التخطي', default => 'مخطط لها', }; @endphp
{{ $v->sequence_no }}

{{ $v->customer->name_ar ?: $v->customer->name }}

{{ $v->customer->city }} · {{ $v->customer->phone }}

{{ $statusLabel }}
@if($v->status == 'pending') @php $isToday = $visitDate === today()->toDateString(); @endphp @if($isToday)
@else
@if($visitDate < today()->toDateString()) لم تُنفَّذ — انتهى يومها @else مخطط لها — تتاح في يومها فقط @endif
@endif @elseif($v->status == 'checked_in') @elseif($v->status == 'completed')
دخول: {{ \Carbon\Carbon::parse($v->check_in_at_utc)->setTimezone('Asia/Riyadh')->format('H:i') }} خروج: {{ \Carbon\Carbon::parse($v->check_out_at_utc)->setTimezone('Asia/Riyadh')->format('H:i') }}
@if($v->notes)
التقرير:

"{{ $v->notes }}"

@endif @if($v->sales_order_id)
تم ربط الطلب: {{ \App\Models\SalesOrder::find($v->sales_order_id)?->order_number }}
@endif
@endif
@empty

لا توجد زيارات مجدولة لهذا التاريخ

تأكد من تحديد تاريخ آخر أو تواصل مع مشرف المبيعات الخاص بك.

@endforelse
@endif