Files
minicrm/app/Filament/Widgets/ResolvedTicketsWidget.php
2026-05-12 09:23:05 +00:00

77 lines
2.6 KiB
PHP

<?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') && ! auth()->user()->hasRole('admin'),
function ($q) {
$deptIds = Department::where('manager_id', auth()->id())->pluck('id');
return $q->whereIn('current_department_id', $deptIds);
}
)
)
->columns([
TextColumn::make('id')
->label('#')
->sortable()
->weight('bold')
->color('primary'),
TextColumn::make('title')
->label(__('app.widget_ticket'))
->searchable()
->weight('semibold')
->url(fn (Feedback $record): string => FeedbackResource::getUrl('edit', ['record' => $record]))
->color('primary'),
TextColumn::make('customer.name')
->label(__('app.widget_customer'))
->searchable(),
TextColumn::make('contract.product.name')
->label(__('app.product'))
->placeholder(__('app.general')),
TextColumn::make('assignedTo.name')
->label(__('app.widget_handler')),
TextColumn::make('currentDepartment.name')
->label(__('app.department'))
->badge()
->color('info'),
TextColumn::make('updated_at')
->label(__('app.widget_resolved'))
->since()
->sortable()
->color('secondary'),
])
->defaultSort('updated_at', 'desc')
->heading(__('app.widget_tickets_awaiting_closure'))
->description(__('app.widget_tickets_awaiting_desc'))
->paginated([5]);
}
public static function canView(): bool
{
return auth()->user()?->hasPermissionTo('view-dashboard-widgets') ?? false;
}
}