feat: AfterSales CRM - SOP compliant real-estate customer care system
- 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)
This commit is contained in:
59
app/Filament/Widgets/HandlerPerformanceWidget.php
Normal file
59
app/Filament/Widgets/HandlerPerformanceWidget.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use App\Models\Department;
|
||||
use App\Models\Feedback;
|
||||
use Filament\Widgets\ChartWidget;
|
||||
|
||||
class HandlerPerformanceWidget extends ChartWidget
|
||||
{
|
||||
protected ?string $heading = 'Avg Processing Time by Handler';
|
||||
|
||||
protected int|string|array $columnSpan = 'full';
|
||||
|
||||
protected function getType(): string
|
||||
{
|
||||
return 'bar';
|
||||
}
|
||||
|
||||
protected function getData(): array
|
||||
{
|
||||
$user = auth()->user();
|
||||
|
||||
$query = Feedback::query()
|
||||
->whereIn('status', ['resolved', 'closed'])
|
||||
->whereNotNull('assigned_to');
|
||||
|
||||
if ($user->hasRole('manager')) {
|
||||
$deptIds = Department::where('manager_id', $user->id)->pluck('id');
|
||||
$query->whereIn('current_department_id', $deptIds);
|
||||
}
|
||||
|
||||
$handlers = (clone $query)
|
||||
->select('assigned_to')
|
||||
->selectRaw('AVG(strftime("%s", updated_at) - strftime("%s", created_at)) / 60 as avg_minutes')
|
||||
->groupBy('assigned_to')
|
||||
->with('assignedTo')
|
||||
->get();
|
||||
|
||||
$labels = $handlers->map(fn ($h) => $h->assignedTo?->name ?? 'Unknown')->toArray();
|
||||
$data = $handlers->map(fn ($h) => round($h->avg_minutes, 1))->toArray();
|
||||
|
||||
return [
|
||||
'datasets' => [
|
||||
[
|
||||
'label' => 'Avg Time (minutes)',
|
||||
'data' => $data,
|
||||
'backgroundColor' => '#3b82f6',
|
||||
],
|
||||
],
|
||||
'labels' => $labels,
|
||||
];
|
||||
}
|
||||
|
||||
public static function canView(): bool
|
||||
{
|
||||
return auth()->user()?->hasRole(['admin', 'manager']) ?? false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user