- Departments + cross-department transfer workflow - Role-based closing (staff→resolved, manager→closed) with proof_of_resolution - Private file storage with collection system + temporary signed URLs - Dashboard: resolved tickets table, stats, handler performance bar chart - Spatie RBAC (admin/manager/staff) - Notifications: TicketTransferred, TicketClosed (database + mail) - Pest tests: 8 tests, 21 assertions - Docker production-ready (Dockerfile + compose + entrypoint)
60 lines
2.0 KiB
PHP
60 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Widgets;
|
|
|
|
use App\Models\Department;
|
|
use App\Models\Feedback;
|
|
use Filament\Widgets\StatsOverviewWidget as BaseWidget;
|
|
use Filament\Widgets\StatsOverviewWidget\Stat;
|
|
|
|
class AvgProcessingTimeWidget extends BaseWidget
|
|
{
|
|
protected function getStats(): array
|
|
{
|
|
$user = auth()->user();
|
|
|
|
$query = Feedback::query()
|
|
->whereNotNull('assigned_to')
|
|
->whereNotNull('updated_at');
|
|
|
|
if ($user->hasRole('manager')) {
|
|
$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();
|
|
|
|
return [
|
|
Stat::make('Resolved Tickets', (string) $totalResolved)
|
|
->description('Total resolved/closed tickets')
|
|
->color('success'),
|
|
|
|
Stat::make('Avg Processing Time', $avgMinutes ? round($avgMinutes) . ' min' : 'N/A')
|
|
->description('Average time from creation to resolution')
|
|
->color('warning'),
|
|
|
|
Stat::make('Pending Tickets', (string) $totalPending)
|
|
->description('Still in progress')
|
|
->color('danger'),
|
|
|
|
Stat::make('Escalated', (string) $escalatedCount)
|
|
->description('Tickets marked as escalated')
|
|
->color('gray'),
|
|
];
|
|
}
|
|
|
|
public static function canView(): bool
|
|
{
|
|
return auth()->user()?->hasRole(['admin', 'manager']) ?? false;
|
|
}
|
|
}
|