{{-- resources/views/dashboard/index.blade.php --}} @extends('layouts.app') @section('content')

{{ __('app.dashboard') }}

@if(!empty($searchQuery ?? null))
{{ __('dashboard.search_results_for') }} "{{ $searchQuery }}"
@php $any = false; @endphp @if(!empty($searchResults['employees'] ?? null) && $searchResults['employees']->count()) @php $any = true; @endphp
{{ __('dashboard.search_employees') }}
@endif @if(!empty($searchResults['activities'] ?? null) && $searchResults['activities']->count()) @php $any = true; @endphp
{{ __('dashboard.search_activities') }}
    @foreach($searchResults['activities'] as $act)
  • {{ $act->created_at->format('Y-m-d H:i') }} — {{ __('activity.' . $act->description) ?? $act->description }} — {{ $act->user?->name ?? '—' }}
  • @endforeach
@endif @if(!empty($searchResults['notifications'] ?? null) && $searchResults['notifications']->count()) @php $any = true; @endphp
{{ __('dashboard.search_notifications') }}
    @foreach($searchResults['notifications'] as $n) @php $data = json_decode($n->data, true); @endphp
  • {{ $n->created_at }} — {{ $data['title'] ?? Str::limit($data['message'] ?? '', 60) }}
  • @endforeach
@endif @if(!empty($searchResults['attendances'] ?? null) && $searchResults['attendances']->count()) @php $any = true; @endphp
{{ __('dashboard.search_attendances') }}
    @foreach($searchResults['attendances'] as $a)
  • {{ $a->date->format('Y-m-d') }} — {{ $a->employee?->name ?? '—' }} — {{ $a->status }}
  • @endforeach
@endif @if(!empty($searchResults['departments'] ?? null) && $searchResults['departments']->count()) @php $any = true; @endphp
{{ __('dashboard.search_departments') }}
    @foreach($searchResults['departments'] as $d)
  • {{ $d->name }}
  • @endforeach
@endif @if(!empty($searchResults['positions'] ?? null) && $searchResults['positions']->count()) @php $any = true; @endphp
{{ __('dashboard.search_positions') }}
    @foreach($searchResults['positions'] as $p)
  • {{ $p->name }}
  • @endforeach
@endif @if(!empty($searchResults['payrolls'] ?? null) && $searchResults['payrolls']->count()) @php $any = true; @endphp
{{ __('dashboard.search_payrolls') }}
@endif @if(!empty($searchResults['leaves'] ?? null) && $searchResults['leaves']->count()) @php $any = true; @endphp
{{ __('app.leaves') }}
@endif @if(!empty($searchResults['deductions'] ?? null) && $searchResults['deductions']->count()) @php $any = true; @endphp
{{ __('app.deductions') }}
@endif @if(!empty($searchResults['loans'] ?? null) && $searchResults['loans']->count()) @php $any = true; @endphp
{{ __('app.loans') }}
@endif @unless($any)

{{ __('app.no_data_found') }}

@endunless
@endif

{{ __('app.total') }} {{ __('app.employees') }}

{{ $stats['total_employees'] ?? 0 }}

{{ __('app.attendance') }} - {{ __('app.today') }}

{{ $presentToday ?? 0 }}

{{ $attendanceRate ?? 0 }}%

{{ __('app.attendance_status.late') }} - {{ __('app.today') }}

{{ $lateToday ?? 0 }}

{{ $lateRate ?? 0 }}%

{{ __('app.attendance_status.absent') }} - {{ __('app.today') }}

{{ $absentToday ?? 0 }}

{{ $absentRate ?? 0 }}%
{{ __('app.attendance_stats') }}
{{ __('app.average_checkin_time') }}: {{ $averageCheckInTime ?? '00:00' }}
{{ __('app.recent_activities') }}
@forelse($recentActivities ?? [] as $activity)
@php $activityProps = $activity->properties ?? []; if (is_string($activityProps)) { $decoded = json_decode($activityProps, true); $activityProps = is_array($decoded) ? $decoded : []; } elseif (!is_array($activityProps)) { $activityProps = (array) $activityProps; } @endphp {{ __('activity.' . $activity->description, $activityProps) }}

{{ __('dashboard.by') }}: {{ $activity->user?->name ?? __('dashboard.system_fallback_name') }}

{{ $activity->created_at->translatedFormat('d F Y H:i') }}
@empty

{{ __('app.no_recent_activities') }}

@endforelse
{{ __('app.recent_payrolls') }}
{{ __('app.view_all') }}
@if($recentPayrolls && $recentPayrolls->count() > 0)
@foreach($recentPayrolls as $payroll) @endforeach
{{ __('dashboard.th_employee') }} {{ __('dashboard.th_net_salary') }} {{ __('dashboard.th_month') }} {{ __('dashboard.th_status') }} {{ __('dashboard.th_actions') }}
{{ $payroll->employee->name }} {{ number_format($payroll->net_salary, 2) }} {{ $currency_name ?? 'د.ك' }} {{ \Carbon\Carbon::create()->month($payroll->month)->translatedFormat('F') }} {{ $payroll->year }} @switch($payroll->status) @case('paid') {{ __('dashboard.paid') }} @break @case('pending') {{ __('dashboard.pending_payment') }} @break @default {{ $payroll->status }} @endswitch
@else

{{ __('app.no_recent_payrolls') }}

@endif
{{ __('app.recent_leaves') }}
{{ __('app.view_all') }}
@if($recentLeaves && $recentLeaves->count() > 0)
@foreach($recentLeaves as $leave) @endforeach
{{ __('dashboard.th_employee') }} {{ __('dashboard.th_leave_type') }} {{ __('dashboard.th_period') }} {{ __('dashboard.th_status') }} {{ __('dashboard.th_actions') }}
{{ $leave->employee->name }} @php $leaveTypes = [ 'annual' => __('dashboard.leave_type_annual'), 'sick' => __('dashboard.leave_type_sick'), 'emergency' => __('dashboard.leave_type_emergency'), 'maternity' => __('dashboard.leave_type_maternity'), 'paternity' => __('dashboard.leave_type_paternity'), 'unpaid' => __('dashboard.leave_type_unpaid'), ]; @endphp {{ $leaveTypes[$leave->leave_type] ?? $leave->leave_type }} {{ $leave->start_date->format('Y-m-d') }} {{ __('app.to') }} {{ $leave->end_date->format('Y-m-d') }} @switch($leave->status) @case('approved') {{ __('dashboard.leave_status_approved') }} @break @case('pending') {{ __('dashboard.leave_status_pending') }} @break @case('rejected') {{ __('dashboard.leave_status_rejected') }} @break @default {{ $leave->status }} @endswitch
@else

{{ __('app.no_recent_leaves') }}

@endif
{{ __('app.recent_deductions') }}
{{ __('app.view_all') }}
@if($recentDeductions && $recentDeductions->count() > 0)
@foreach($recentDeductions as $deduction) @php // Robust extraction of deduction type for translation lookup $rawType = $deduction->type ?? null; $rawString = ''; if (is_array($rawType)) { $rawString = $rawType['slug'] ?? $rawType['code'] ?? $rawType['name'] ?? ($rawType['type'] ?? json_encode($rawType)); } elseif (is_object($rawType)) { $rawArr = (array) $rawType; $rawString = $rawArr['slug'] ?? $rawArr['code'] ?? $rawArr['name'] ?? ($rawArr['type'] ?? json_encode($rawArr)); } else { $rawString = is_string($rawType) ? $rawType : ''; } // normalize to slug: lowercase, replace non-alnum with underscore $slug = trim(strtolower((string) $rawString)); $slug = preg_replace('/[^a-z0-9]+/i', '_', $slug); $slug = trim($slug, '_'); // try multiple candidate slugs (handle variants like 'in_kind_deduction', 'deduction_cash') $candidates = [$slug]; if ($slug) { $candidates[] = preg_replace('/_?deduction$/', '', $slug); $candidates[] = preg_replace('/^deduction_?/', '', $slug); $candidates[] = preg_replace('/_?type$/', '', $slug); } $candidates = array_values(array_filter(array_unique($candidates))); $deductionTypeLabel = null; foreach ($candidates as $candidate) { $key = 'dashboard.deduction_type_' . ($candidate ?: 'other'); $val = __($key); if ($val !== $key) { $deductionTypeLabel = $val; break; } } if (!$deductionTypeLabel) { // Try to match the raw string against translation VALUES (covers cases where DB stores Arabic text like 'خصومات') try { $all = trans('dashboard'); foreach($all as $tkey => $tval) { if (is_string($tval) && mb_strtolower(trim($tval)) == mb_strtolower(trim($rawString))) { if (str_starts_with($tkey, 'deduction_type_')) { $deductionTypeLabel = $tval; break; } } } } catch (\Throwable $e) { // ignore and fallback } if (!$deductionTypeLabel) { // fallback to provided Arabic label or raw string, else generic 'Other' $deductionTypeLabel = $deduction->type_arabic ?? ($rawString ?: __('dashboard.deduction_type_other')); } } @endphp @endforeach
{{ __('dashboard.th_employee') }} {{ __('dashboard.th_type') }} {{ __('dashboard.th_amount') }} {{ __('dashboard.th_date') }} {{ __('dashboard.th_status') }} {{ __('dashboard.th_actions') }}
{{ $deduction->employee->name }}{{ $deductionTypeLabel }} {{ number_format($deduction->amount, 2) }} {{ get_currency_code() }} {{ $deduction->deduction_date->format('Y-m-d') }} @switch($deduction->status) @case('applied') {{ __('dashboard.deduction_status_applied') }} @break @case('pending') {{ __('dashboard.deduction_status_pending') }} @break @case('cancelled') {{ __('dashboard.deduction_status_cancelled') }} @break @default {{ __('dashboard.status_unknown') }} @endswitch
@else

{{ __('app.no_recent_deductions') }}

@endif
{{ __('app.recent_loans') }}
{{ __('app.view_all') }}
@if($recentLoans && $recentLoans->count() > 0)
@foreach($recentLoans as $loan) @php $loanTypeKey = 'dashboard.loan_type_' . ($loan->loan_type ?? ''); $loanTypeLabel = __($loanTypeKey); if ($loanTypeLabel === $loanTypeKey) { $loanTypeLabel = $loan->loan_type_arabic ?? $loan->loan_type; } @endphp @endforeach
{{ __('dashboard.th_employee') }} {{ __('dashboard.th_type') }} {{ __('dashboard.th_amount') }} {{ __('dashboard.th_date') }} {{ __('dashboard.th_status') }} {{ __('dashboard.th_actions') }}
{{ $loan->employee->name }}{{ $loanTypeLabel }} {{ number_format($loan->amount, 2) }} {{ get_currency_code() }} {{ $loan->created_at->format('Y-m-d') }} @switch($loan->status) @case('pending') {{ __('dashboard.loan_status_pending') }} @break @case('approved') {{ __('dashboard.loan_status_approved') }} @break @case('active') {{ __('dashboard.loan_status_active') }} @break @case('completed') {{ __('dashboard.loan_status_completed') }} @break @case('cancelled') {{ __('dashboard.loan_status_cancelled') }} @break @default {{ __('dashboard.status_unknown') }} @endswitch
@else

{{ __('app.no_recent_loans') }}

@endif
{{ __('app.notifications') }}
@forelse($notifications ?? [] as $notification) @empty @endforelse
# {{ __('dashboard.th_title') }} {{ __('dashboard.th_description') }} {{ __('dashboard.th_sender') }} {{ __('dashboard.th_date') }} {{ __('dashboard.th_status') }} {{ __('dashboard.th_actions') }}
{{ $loop->iteration }} {{ $notification->data['title'] ?? __('app.notification_new_default_title') }} {{ Str::limit($notification->data['message'] ?? __('app.notification_details_default'), 80) }} @if(isset($notification->data['sender']) && $notification->data['sender'] == 'system') {{ __('dashboard.system_name') }} @else {{ $notification->notifiable?->name ?? __('dashboard.system_fallback_name') }} @endif {{ $notification->created_at->diffForHumans() }} @if($notification->read_at) {{ __('app.notification_read') }} @else {{ __('app.notification_unread') }} @endif
@if(!$notification->read_at) @endif

{{ __('app.no_notifications') }}
@if(isset($notifications) && $notifications->hasPages())
{{ $notifications->links() }}
@endif
@endsection