authorize('users:manage'); $this->id = $id; if (! User::query()->whereKey($id)->exists()) { session()->flash('error', __('Der angeforderte Benutzer wurde nicht gefunden.')); $this->redirect(route('admin.users.index'), navigate: true); return; } } public function grantCredits(): void { $this->authorize('users:manage'); $this->validate([ 'grantCreditsAmount' => ['required', 'integer', 'min:1', 'max:100000'], 'grantCreditsNote' => ['nullable', 'string', 'max:240'], ]); $user = User::query()->findOrFail($this->id); app(AdminGrantService::class)->grantCredits( $user, $this->grantCreditsAmount, auth()->user(), trim($this->grantCreditsNote) ?: null, ); Flux::toast( text: __(':count Credits gutgeschrieben.', ['count' => $this->grantCreditsAmount]), variant: 'success', ); $this->reset('grantCreditsNote'); } public function grantFreePressReleases(): void { $this->authorize('users:manage'); $this->validate([ 'grantPmCount' => ['required', 'integer', 'min:1', 'max:100'], 'grantPmNote' => ['nullable', 'string', 'max:240'], ]); $user = User::query()->findOrFail($this->id); app(AdminGrantService::class)->grantFreePressReleases( $user, $this->grantPmCount, auth()->user(), trim($this->grantPmNote) ?: null, ); Flux::toast( text: __(':count freie Pressemitteilung(en) gutgeschrieben.', ['count' => $this->grantPmCount]), variant: 'success', ); $this->reset('grantPmNote'); } public function companyUserRoleLabel(?string $role): string { return match ($role ?? 'member') { 'owner' => __('Inhaber'), 'responsible' => __('Verantwortlich'), 'member' => __('Mitglied'), default => (string) ($role ?? 'member'), }; } public function with(): array { $user = User::query() ->with([ 'roles' => fn ($query) => $query->orderBy('name'), 'companies' => fn ($query) => $query ->select(['companies.id', 'companies.name', 'companies.slug', 'companies.email', 'companies.phone', 'companies.portal', 'companies.is_active']) ->withCount('contacts') ->orderBy('name'), 'companies.contacts' => fn ($query) => $query ->select(['contacts.id', 'contacts.company_id', 'contacts.portal', 'contacts.first_name', 'contacts.last_name', 'contacts.responsibility', 'contacts.email', 'contacts.phone']) ->orderBy('last_name') ->orderBy('first_name') ->limit(10), 'billingAddress', ]) ->find($this->id); return [ 'user' => $user, 'creditBalance' => $user ? app(CreditWalletService::class)->balance($user) : 0, 'openPmPurchases' => $user?->openSinglePurchaseCount() ?? 0, 'quotaRemaining' => $user?->pressReleaseQuotaRemaining(), ]; } }; ?>
@if (! $user)
{{ __('Benutzer nicht gefunden') }}
{{ __('Zurück zur Übersicht') }}
@else {{-- ============== PAGE HEADER ============== --}} ID #{{ $user->id }} @if (filled($user->agency_name)) {{ __('Übermittler') }}: {{ $user->agency_name }} @endif @if ($user->is_active) {{ __('Aktiv') }} @else {{ __('Inaktiv') }} @endif {{ __('Zurück') }} {{ __('Bearbeiten') }} {{-- ============== KPI-Reihe ============== --}}
{{ __('Zuordnung') }} {{ __('Registrierung') }} @if ($user->is_active) {{ __('Login möglich') }} @else {{ __('gesperrt') }} @endif {{ $user->last_login_ip ?? __('keine IP') }}
{{ __('Rollen') }}
@forelse ($user->roles as $role) {{ $role->name }} @empty

{{ __('Keine Rollen hinterlegt') }}

@endforelse
{{-- ============== GUTHABEN & KONTINGENT ============== --}}
{{ __('Guthaben & Kontingent') }} {{ __('Gutschriften ohne Zahlung — landen im Verlauf') }}
{{ __('Credit-Saldo') }}
{{ number_format($creditBalance, 0, ',', '.') }}
{{ __('Offene PM-Käufe/Gutschriften') }}
{{ number_format($openPmPurchases, 0, ',', '.') }}
{{ __('PM-Kontingent verbleibend') }}
{{ $quotaRemaining === null ? __('Unbegrenzt') : number_format($quotaRemaining, 0, ',', '.') }}
{{ __('Credits gutschreiben') }}
{{ __('Anzahl Credits') }} {{ __('Grund (optional, erscheint im Ledger & Verlauf)') }} {{ __('Credits gutschreiben') }}
{{ __('Freie Pressemitteilungen gutschreiben') }}
{{ __('Anzahl PMs') }} {{ __('Grund (optional, erscheint im Verlauf)') }} {{ __('Freie PMs gutschreiben') }}

{{ __('Wird als bezahlter 0-€-Einzelkauf verbucht und beim Veröffentlichen regulär eingelöst.') }}

{{ __('Rechnungsadresse') }}
@if ($user->billingAddress)
{{ $user->billingAddress->name }}
{{ $user->billingAddress->address1 }}
@if ($user->billingAddress->address2)
{{ $user->billingAddress->address2 }}
@endif
{{ $user->billingAddress->postal_code }} {{ $user->billingAddress->city }}
{{ $user->billingAddress->country_code }}
@else

{{ __('Keine Rechnungsadresse hinterlegt') }}

@endif
{{ __('Verknüpfte Firmen und Kontakte') }}

{{ __('Kontakte sind die Ansprechpartner der verknüpften Firmen (wie in der Bearbeiten-Ansicht).') }}

@forelse ($user->companies as $company)
@if (\Illuminate\Support\Facades\Route::has('admin.companies.show')) {{ $company->name }} @else
{{ $company->name }}
@endif
{{ $company->slug }}
@if ($company->email) {{ $company->email }} @endif @if ($company->phone) {{ $company->phone }} @endif
{{ $this->companyUserRoleLabel($company->pivot?->role ?? 'member') }} {{ $company->portal?->label() ?? '—' }} @if (! $company->is_active) {{ __('Inaktiv') }} @endif
@if ($company->contacts->isNotEmpty())
@foreach ($company->contacts as $contact)
{{ $contact->displayName() }}
{{ $contact->responsibility ?? __('Keine Rolle hinterlegt') }}
@if ($contact->email) {{ $contact->email }} @endif @if ($contact->phone) {{ $contact->phone }} @endif
{{ $contact->portal?->label() ?? '—' }} @if (\Illuminate\Support\Facades\Route::has('admin.contacts.edit')) {{ __('Bearbeiten') }} @endif
@endforeach @if ($company->contacts_count > $company->contacts->count())

{{ __(':count weitere Kontakte werden hier nicht geladen. Öffne die Firma, um alle Kontakte zu sehen.', ['count' => $company->contacts_count - $company->contacts->count()]) }}

@endif
@else

{{ __('Keine Kontakte bei dieser Firma') }}

@endif
@empty

{{ __('Keine Firmen verknüpft') }}

@endforelse
@endif