user(); $query = Feedback::query() ->whereNotNull('assigned_to') ->whereNotNull('updated_at'); if ($user->hasRole('manager') && ! $user->hasRole('admin')) { $deptIds = Department::where('manager_id', $user->id)->pluck('id'); $query->whereIn('current_department_id', $deptIds); } $totalResolved = (clone $query)->whereIn('status', ['resolved', 'closed'])->count(); $avgMinutes = (clone $query) ->whereIn('status', ['resolved', 'closed']) ->selectRaw('AVG(strftime("%s", updated_at) - strftime("%s", created_at)) / 60 as avg_minutes') ->value('avg_minutes'); $totalPending = (clone $query)->whereNotIn('status', ['resolved', 'closed'])->count(); $escalatedCount = (clone $query)->where('is_escalated', true)->count(); $avgDisplay = $avgMinutes ? round($avgMinutes) . ' min' : 'N/A'; $avgDescription = $avgMinutes ? 'Avg time from creation to resolution' : 'No resolved tickets yet'; return [ Stat::make('Resolved Tickets', (string) $totalResolved) ->description('Total resolved/closed tickets') ->descriptionIcon('heroicon-m-check-circle') ->color('success') ->chart([7, 3, 4, 5, 6, 8, $totalResolved]), Stat::make('Avg Processing Time', $avgDisplay) ->description($avgDescription) ->descriptionIcon('heroicon-m-clock') ->color('info'), Stat::make('Pending Tickets', (string) $totalPending) ->description('Still in progress') ->descriptionIcon('heroicon-m-arrow-path') ->color('warning') ->chart([3, 5, 4, 6, 5, 4, $totalPending]), Stat::make('Escalated', (string) $escalatedCount) ->description('Tickets marked as escalated') ->descriptionIcon('heroicon-m-exclamation-triangle') ->color('danger'), ]; } public static function canView(): bool { return auth()->user()?->hasPermissionTo('view-dashboard-widgets') ?? false; } }