record // may not yet be hydrated when getHeaderActions() runs. Fall back to URL // segment which is always present because we're on /app/work-orders/{id}/edit. $woId = $this->record?->id ?? (int) (request()->route('record') ?? request()->segment(3)); \Log::info('EditWorkOrder.getHeaderActions', [ 'record_id_from_prop' => $this->record?->id, 'record_id_resolved' => $woId, 'route_record' => request()->route('record'), 'segment3' => request()->segment(3), ]); $dashboardUrl = url('/app/work-orders/' . $woId . '/dashboard'); return [ Actions\Action::make('dashboard') ->label(__('Vizualizare dashboard')) ->icon('heroicon-m-squares-2x2') ->color('info') ->url($dashboardUrl), Actions\Action::make('apply_template') ->label(__('Aplică șablon')) ->icon('heroicon-m-clipboard-document-list') ->color('gray') ->schema([ \Filament\Forms\Components\Select::make('template_id') ->label(__('Șablon serviciu')) ->options(fn () => \App\Models\Tenant\ServiceTemplate::where('is_active', true)->pluck('name', 'id')) ->searchable() ->required(), ]) ->action(function (array $data) { $template = \App\Models\Tenant\ServiceTemplate::with('items')->find($data['template_id']); if (! $template) return; $r = app(\App\Services\ServiceComposer::class)->applyTemplate($this->record, $template); $this->fillForm(); \Filament\Notifications\Notification::make() ->title(__('Șablon aplicat') . ": {$r['labor']} " . __('manopere') . ", {$r['parts']} " . __('piese')) ->success()->send(); }), Actions\Action::make('ai_diagnose') ->label(__('AI: sugerează diagnostic')) ->icon('heroicon-m-sparkles') ->color('primary') ->visible(fn () => ! empty($this->record->complaint)) ->modalHeading(__('Diagnostic AI bazat pe plângerea clientului')) ->modalSubmitAction(false) ->modalCancelActionLabel(__('Închide')) ->modalContent(function () { [$reply, $meta] = app(\App\Services\Ai\AiAssistantService::class) ->suggestDiagnosis($this->record); return view('filament.tenant.ai-reply', ['reply' => $reply, 'meta' => $meta]); }), Actions\Action::make('tracking') ->label(__('Link client (QR)')) ->icon('heroicon-m-qr-code') ->color('primary') ->modalHeading(fn () => __('Tracking client') . ' — WO #' . $this->record->number) ->modalSubmitAction(false) ->modalCancelActionLabel(__('Închide')) ->modalWidth('lg') ->modalContent(fn () => view('filament.tenant.tracking-qr', [ 'wo' => $this->record, ])), Actions\Action::make('pdf') ->label(__('Descarcă PDF')) ->icon('heroicon-m-document-arrow-down') ->color('gray') ->action(function () { /** @var WorkOrder $wo */ $wo = $this->record; $svc = app(WorkOrderPdfService::class); $pdf = $svc->generate($wo); return response()->streamDownload( fn () => print($pdf->output()), $svc->filename($wo) ); }), Actions\DeleteAction::make(), ]; } }