Add-on-Name, 'required' => int, 'available' => int]. * * @var array{label: string, required: int, available: int}|null */ public ?array $creditShortfall = null; /** * Kontext fürs Kauf-Bestätigungs-Modal (Entscheidung 10.07.): Add-ons * buchen erst nach explizitem „Kostenpflichtig buchen", damit ein Klick * auf eine Laufzeit nicht sofort Credits abbucht. Läuft bereits ein * Boost, tragen extendsUntil/newEndsAt den Verlängerungs-Hinweis. * * @var array{type: 'boost'|'proof', label: string, credits: int, days: int|null, extendsUntil: string|null, newEndsAt: string|null}|null */ public ?array $pendingPurchase = null; /** * Pflicht-Schalter im Kauf-Modal: ohne aktive Bestätigung führt * buyPendingAddOn keine Abbuchung aus. */ public bool $purchaseConfirmed = false; public function mount(int $id): void { $this->id = $id; $pr = $this->getMyPR(); $this->authorize('view', $pr); // KI-Grad vorbelegen (bereits deklariert), gemappt auf die zwei // Formular-Optionen; die verbindliche Bestätigung muss bei jedem // Submit erneut gesetzt werden. $this->aiTextDeclaration = $pr->ai_text_declaration?->formOption()->value; } public function submitForReview(): void { $pr = $this->getMyPR(); $this->authorize('submitForReview', $pr); // KI-Kennzeichnung (Art. 50 KI-VO): Pflicht-Deklaration aus dem // Submit-Modal validieren und vor dem Einreichen persistieren. $this->validateAiDeclaration(); $pr->update($this->aiDeclarationAttributes()); try { app(PressReleaseService::class)->submitForReview($pr); } catch (BlacklistViolationException $e) { Flux::modal('confirm-submit-review')->close(); Flux::toast( heading: __('Automatisch abgelehnt'), text: __('Unzulässiges Wort gefunden: ":word". Bitte überarbeiten.', ['word' => $e->word]), variant: 'danger', duration: 8000, ); return; } catch (AiDeclarationRequiredException|BookingRequiredException|QuotaExceededException $e) { Flux::modal('confirm-submit-review')->close(); Flux::toast( heading: __('Nicht eingereicht'), text: $e->getMessage(), variant: 'warning', duration: 8000, ); return; } Flux::modal('confirm-submit-review')->close(); Flux::toast( heading: __('Eingereicht'), text: __('Die automatische Inhaltsprüfung ist in der Regel innerhalb weniger Minuten abgeschlossen.'), variant: 'success', ); } public function generateShareLink(MagicLinkGenerator $generator): void { $pr = $this->getMyPR(); $this->authorize('view', $pr); $share = $generator->createPressReleaseShareLink($pr, auth()->user()); $this->shareUrl = $share['url']; $this->shareExpiresAt = $share['expires_at']->format('d.m.Y H:i'); Flux::toast(text: __('Vorschau-Link wurde erzeugt.'), variant: 'success'); } /** * Kauf-Bestätigung für einen Boost öffnen (Abbuchung erst in * buyPendingAddOn). */ public function confirmBoost(int $days): void { $options = app(CreditPricingService::class)->boostOptions(); if (! isset($options[$days])) { return; } // Läuft bereits ein Boost, verlängert die Buchung dessen Laufzeit — // das Modal weist ausdrücklich darauf hin (Entscheidung 10.07.). $activeUntil = app(BoostService::class)->activeUntil($this->getMyPR()); $this->purchaseConfirmed = false; $this->pendingPurchase = [ 'type' => 'boost', 'label' => __('Boost — :days Tage Platzierung', ['days' => $days]), 'credits' => $options[$days], 'days' => $days, 'extendsUntil' => $activeUntil?->format('d.m.Y H:i'), 'newEndsAt' => $activeUntil?->copy()->addDays($days)->format('d.m.Y H:i'), ]; Flux::modal('confirm-addon-purchase')->show(); } /** * Kauf-Bestätigung für den Veröffentlichungsnachweis öffnen. */ public function confirmProof(): void { $this->purchaseConfirmed = false; $this->pendingPurchase = [ 'type' => 'proof', 'label' => __('Veröffentlichungsnachweis (PDF)'), 'credits' => app(ProofPdfService::class)->priceCredits(), 'days' => null, 'extendsUntil' => null, 'newEndsAt' => null, ]; Flux::modal('confirm-addon-purchase')->show(); } /** * Bestätigten Add-on-Kauf ausführen — der einzige Weg, auf dem die * Buttons der Add-on-Sektion tatsächlich Credits abbuchen. */ public function buyPendingAddOn(): void { // Serverseitige Absicherung des Pflicht-Schalters (der Button ist // clientseitig zusätzlich deaktiviert). if ($this->pendingPurchase !== null && ! $this->purchaseConfirmed) { Flux::toast( text: __('Bitte bestätigen Sie die kostenpflichtige Buchung über den Schalter.'), variant: 'warning', ); return; } $pending = $this->pendingPurchase; $this->pendingPurchase = null; $this->purchaseConfirmed = false; Flux::modal('confirm-addon-purchase')->close(); if ($pending === null) { return; } if ($pending['type'] === 'boost') { $this->buyBoost($pending['days']); return; } $this->buyProof(); } /** * Boost (Platzierung) aus der Wallet buchen — nur veröffentlichte, grüne * PMs sind boostbar (Gate im BoostService). */ public function buyBoost(int $days): void { $pr = $this->getMyPR(); $this->authorize('view', $pr); try { app(BoostService::class)->boost(auth()->user(), $pr, $days); Flux::toast( heading: __('Boost gebucht'), text: __('Ihre Pressemitteilung wird jetzt auf Start- und Branchenseite hervorgehoben.'), variant: 'success', ); } catch (InsufficientCreditsException $e) { $this->showCreditShortfallModal(__('Der Boost'), $e); } catch (BoostNotAllowedException $e) { Flux::toast(text: $e->getMessage(), variant: 'warning', duration: 8000); } } /** * Veröffentlichungsnachweis-PDF kaufen (3 Credits, einmalig je PM). Danach * steht der Download über die Nachweis-Route bereit. */ public function buyProof(): void { $pr = $this->getMyPR(); $this->authorize('downloadProof', $pr); try { app(ProofPdfService::class)->purchase(auth()->user(), $pr); Flux::toast( heading: __('Nachweis gekauft'), text: __('Der Veröffentlichungsnachweis steht jetzt zum Download bereit.'), variant: 'success', ); } catch (InsufficientCreditsException $e) { $this->showCreditShortfallModal(__('Der Veröffentlichungsnachweis'), $e); } } /** * Statt eines flüchtigen Toasts ein Modal mit Aufladen-Link öffnen * (QA-Befund 07.07.): der Kunde soll direkt zur Wallet finden. */ private function showCreditShortfallModal(string $label, InsufficientCreditsException $e): void { $this->creditShortfall = [ 'label' => $label, 'required' => $e->required, 'available' => $e->available, ]; Flux::modal('insufficient-credits')->show(); } /** * Unternehmer-Pflicht-Checkbox vor dem Depublikations-Checkout (T1neu): * protokolliert wie im Buchungs-Modal — der Checkout-Controller verlangt * eine zeitnahe Bestätigung zusätzlich serverseitig. */ public function updatedDepublicationConfirmed(bool $value): void { if (! $value) { return; } $agb = LegalDocument::current(LegalDocument::TYPE_AGB); BookingConfirmation::query()->create([ 'user_id' => auth()->id(), 'booking_type' => 'depublication', 'booking_ref' => (string) $this->id, 'legal_document_id' => $agb?->id, 'agb_version' => $agb?->version ?? (string) config('legal.agb_version'), 'ip' => request()->ip(), 'confirmed_at' => now(), ]); } public function with(): array { $pr = $this->getMyPR(); $this->authorize('view', $pr); $categoryName = $pr->category?->translations->firstWhere('locale', 'de')?->name ?? '–'; $latestRejection = null; if ($pr->status->value === 'rejected') { $latestRejection = $pr->statusLogs ->firstWhere(fn ($log) => $log->to_status?->value === 'rejected'); } $cover = app(PressReleaseCoverImage::class); $user = auth()->user(); $company = $pr->company; $boostService = app(BoostService::class); $proofService = app(ProofPdfService::class); // Share-Klicks der öffentlichen Detailseite, je Kanal aggregiert. $shareCounts = $pr->events() ->where('type', PressReleaseEventType::Share) ->selectRaw('channel, count(*) as clicks') ->groupBy('channel') ->pluck('clicks', 'channel'); return [ 'pr' => $pr, 'publicLinks' => $pr->status === PressReleaseStatus::Published ? $pr->publicPortalLinks() : [], 'creditBalance' => $user->creditBalance(), 'canBoost' => $boostService->canBoost($pr), 'isBoosted' => $boostService->isBoosted($pr), 'boostedUntil' => $boostService->activeUntil($pr), 'boostOptions' => app(CreditPricingService::class)->boostOptions(), 'proofPrice' => $proofService->priceCredits(), 'proofPurchased' => $proofService->hasPurchased($user, $pr), 'companyLogoUrl' => $company?->logoUrl(), 'companyInitials' => $this->companyInitials($company?->name), 'companyMetaLine' => $this->companyMetaLine($company), 'categoryName' => $categoryName, 'coverUrl' => $cover->coverUrl($pr, 'cover'), 'coverIsPlaceholder' => $cover->coverIsPlaceholder($pr), 'titleImage' => $pr->images()->orderByDesc('is_preview')->orderBy('sort_order')->orderBy('id')->first(), 'quotaTotal' => $user->pressReleaseQuotaTotal(), 'quotaRemaining' => $user->pressReleaseQuotaRemaining(), 'canEdit' => auth()->user()->can('update', $pr) && in_array($pr->status->value, ['draft', 'rejected']), // Einreichen zur Prüfung ist hinter eine bezahlte Buchung gegated // (Decision-Update §5.1, Schalter billing.enforce_booking). 'hasActiveBooking' => $user->hasActiveBooking(), 'latestRejection' => $latestRejection, 'shareTotal' => (int) $shareCounts->sum(), 'shareBreakdown' => $shareCounts ->sortDesc() ->map(fn (int $clicks, string $channel) => PressReleaseShareChannel::from($channel)->label().' '.number_format($clicks, 0, ',', '.')) ->implode(' · '), 'contacts' => $pr->contacts, 'statusLogs' => $pr->statusLogs, // T12: Depublikation ist config-gated (ohne Preis kein Angebot). 'depublicationPriceCents' => (int) config('billing.depublication_price_cents'), // Nur ein BEZAHLTER Vorgang blendet das Angebot aus — ein // abgebrochener Checkout (Pending) wird beim nächsten Klick // wiederverwendet (CheckoutController::depublication). 'depublicationRequested' => SinglePurchase::query() ->where('press_release_id', $pr->id) ->where('type', SinglePurchaseType::Depublication->value) ->where('status', SinglePurchaseStatus::Paid->value) ->exists(), ]; } /** * Initialen für die Logo-Kachel (analog zur Firmenübersicht). */ private function companyInitials(?string $name): string { $name = trim((string) $name); if ($name === '') { return '–'; } $letters = collect(preg_split('/\s+/u', $name) ?: []) ->map(fn (string $word): string => mb_substr($word, 0, 1)) ->filter() ->take(2) ->implode(''); return mb_strtoupper($letters ?: mb_substr($name, 0, 2)); } /** * Kompakte Meta-Zeile: Ort (letzte Adresszeile) · Firmentyp. */ private function companyMetaLine(?\App\Models\Company $company): string { if (! $company) { return ''; } $parts = []; $lastAddressLine = collect(preg_split('/\r?\n/', trim((string) $company->address)) ?: []) ->map(fn ($line) => trim((string) $line)) ->filter() ->last(); if (is_string($lastAddressLine) && $lastAddressLine !== '') { $parts[] = $lastAddressLine; } if ($company->type?->label()) { $parts[] = $company->type->label(); } return implode(' · ', $parts); } private ?PressRelease $cachedPressRelease = null; private function getMyPR(): PressRelease { // Pro Livewire-Request memoisiert: mount(), with() und die Add-on- // Aktionen rufen getMyPR() sonst jeweils mit der vollen Eager-Load- // Query erneut auf. Firmen-Kennzahlen direkt mit eager laden, statt // sie nachträglich per loadCount() nachzuziehen. return $this->cachedPressRelease ??= PressRelease::accessibleBy(auth()->user()) ->with([ 'company' => fn ($query) => $query ->select(['id', 'name', 'email', 'phone', 'address', 'portal', 'logo_path', 'legacy_portal', 'is_active', 'type']) ->withCount(['pressReleases', 'contacts']), 'category.translations', 'contacts' => fn ($query) => $query ->withoutGlobalScopes() ->orderBy('last_name') ->orderBy('first_name') ->select(['contacts.id', 'contacts.company_id', 'contacts.first_name', 'contacts.last_name', 'contacts.responsibility', 'contacts.email', 'contacts.phone']), 'statusLogs.changedBy:id,name,email', ]) ->findOrFail($this->id); } }; ?>
{{ $pr->subtitle }}
@endif{{ $pr->company?->name ?? '–' }} · {{ $categoryName }} · {{ $pr->created_at->format('d.m.Y') }}
{{ $pr->status === PressReleaseStatus::Rejected ? __('Sie können den Text bearbeiten und erneut zur Prüfung einreichen.') : __('Reichen Sie den Entwurf ein, sobald er vollständig ist.') }}
{{ __('Diese Pressemitteilung ist veröffentlicht (seit :date).', ['date' => $pr->published_at?->format('d.m.Y H:i') ?? '–']) }}
{{ __('Hervorhebung auf Start- und Branchenseite.') }}
{{ __('Ein weiterer Kauf verlängert die Laufzeit.') }}
@endif @else{{ __('Nur grün geprüfte Pressemitteilungen sind boostbar.') }}
@endif{{ __('PDF mit Datum, Portal und URL — :credits Credits.', ['credits' => $proofPrice]) }}
{{ __('Ihre Pressemitteilung wird gerade geprüft. Sie werden benachrichtigt, sobald eine Entscheidung vorliegt.') }}
{{ $log->reason }}
@endif{{ __('Noch keine Statusänderungen protokolliert.') }}
@endif{{ __('Dieser Text wird für diese Pressemitteilung anstelle des Standard-Abbinders der Firma verwendet.') }}
{{ __('Freiwillige Entfernung dieser veröffentlichten Mitteilung — die öffentliche URL zeigt danach dauerhaft einen Entfernt-Hinweis. Kopien in Suchmaschinen oder Drittarchiven können zeitweise weiter verfügbar sein. Preis: :net € zzgl. USt. (:gross € inkl. 19 % USt.)', ['net' => $depubNet, 'gross' => $depubGross]) }}
{{ __('AGB (Version :version)', ['version' => \App\Models\LegalDocument::currentAgbVersion()]) }} · {{ __('Gesetzliche Ansprüche (z. B. DSGVO) bleiben davon unberührt und sind immer kostenlos.') }}
{{ __('Diese Buchung verlängert den laufenden Boost.') }}
{{ __('Aktuell aktiv bis :until — die neue Laufzeit schließt daran an und endet am :end.', [ 'until' => $pendingPurchase['extendsUntil'], 'end' => $pendingPurchase['newEndsAt'], ]) }}
@if ($creditBalance >= $pendingPurchase['credits']) {{ __('Der Betrag wird sofort von Ihrem Guthaben abgebucht: :available Credits → :rest Credits.', [ 'available' => $creditBalance, 'rest' => $creditBalance - $pendingPurchase['credits'], ]) }} @else {{ __('Ihr Guthaben (:available Credits) reicht dafür nicht aus — es fehlen :missing Credits.', [ 'available' => $creditBalance, 'missing' => $pendingPurchase['credits'] - $creditBalance, ]) }} @endif
{{ __(':label kostet :required Credits — Ihr Guthaben beträgt :available Credits. Es fehlen :missing Credits.', [ 'label' => $creditShortfall['label'], 'required' => $creditShortfall['required'], 'available' => $creditShortfall['available'], 'missing' => max(0, $creditShortfall['required'] - $creditShortfall['available']), ]) }}
{{ __('Guthaben laden Sie unter „Buchungen & Add-ons" auf — es steht sofort zur Verfügung (1 Credit = 1 €, größere Pakete enthalten Bonus-Credits).') }}