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/AvgProcessingTimeWidget.php
Normal file
59
app/Filament/Widgets/AvgProcessingTimeWidget.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
59
app/Filament/Widgets/ResolvedTicketsWidget.php
Normal file
59
app/Filament/Widgets/ResolvedTicketsWidget.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use App\Filament\Resources\Feedback\FeedbackResource;
|
||||
use App\Models\Department;
|
||||
use App\Models\Feedback;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
use Filament\Widgets\TableWidget as BaseWidget;
|
||||
|
||||
class ResolvedTicketsWidget extends BaseWidget
|
||||
{
|
||||
protected int|string|array $columnSpan = 'full';
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->query(
|
||||
Feedback::query()
|
||||
->where('status', 'resolved')
|
||||
->when(
|
||||
auth()->user()->hasRole('manager'),
|
||||
function ($q) {
|
||||
$deptIds = Department::where('manager_id', auth()->id())->pluck('id');
|
||||
return $q->whereIn('current_department_id', $deptIds);
|
||||
}
|
||||
)
|
||||
)
|
||||
->columns([
|
||||
TextColumn::make('id')
|
||||
->label('#')
|
||||
->sortable(),
|
||||
TextColumn::make('title')
|
||||
->label('Ticket')
|
||||
->searchable()
|
||||
->url(fn (Feedback $record): string => FeedbackResource::getUrl('edit', ['record' => $record])),
|
||||
TextColumn::make('customer.name')
|
||||
->label('Customer')
|
||||
->searchable(),
|
||||
TextColumn::make('assignedTo.name')
|
||||
->label('Handler'),
|
||||
TextColumn::make('currentDepartment.name')
|
||||
->label('Department'),
|
||||
TextColumn::make('updated_at')
|
||||
->label('Resolved Date')
|
||||
->dateTime('d/m/Y')
|
||||
->sortable(),
|
||||
])
|
||||
->defaultSort('updated_at', 'desc')
|
||||
->heading('Tickets Awaiting Closure (Resolved)')
|
||||
->description('Tickets that have been resolved and are pending manager review for closure.');
|
||||
}
|
||||
|
||||
public static function canView(): bool
|
||||
{
|
||||
return auth()->user()?->hasRole(['admin', 'manager']) ?? false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user