- PermissionSeeder: 29 permissions with role mapping (admin/manager/staff) - Policies updated to use hasPermissionTo() instead of hasRole() - ExportBackup command: JSON per-table backup with chunk processing - UserResource: CRUD users with role assignment (admin only) - RoleResource: CRUD roles with permission assignment (admin only) - UserPolicy + RolePolicy: admin-only access control - ImportCskh: detailed skip logging with color in dry-run mode - Widgets: permission-based visibility checks - Tests: 8/8 pass (21 assertions)
71 lines
2.5 KiB
PHP
71 lines
2.5 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') && ! $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;
|
|
}
|
|
}
|