Files
fewo-stommer/app/Http/Controllers/SelfServiceController.php
LarsandClaude Opus 5.5 3a728c3255 Vorgangskern und geführte Vorgangsbearbeitung (Pakete 1 und 2, Prozessarchitektur v0.10)
- Buchung ist der einheitliche Vorgang: Eingangsart, Vorgangsart A1–A6, eingefrorenes
  Abwicklungsprofil, gespeicherter Verlauf (booking_events); Gast, Personen und Beträge
  dürfen unbekannt sein, Platzhalter-Gäste werden migriert und nicht mehr angelegt
- Einstellungen in Ebenen: Vermieterstandard (So arbeite ich), Abweichung der Wohnung
  (Experte), Abweichung je Portal und Eingangsart; ersetzt booking_model als Steuergröße
- Ein Weg für extern verbindliche Buchungen (TakeOverExternalBooking) statt
  RecordPortalBooking und "Akte anlegen"; Portalpreis als belegte Gesamtposition
- Startseite "Zu erledigen", neue Vorgangsseite mit nächstem Schritt, Automatik-Schalter,
  "Beenden" mit Storno statt Statusumschaltung; Status von Hand nur im Expertenmodus
- Migration übernimmt bisheriges Verhalten unverändert (abweichende Wohnungswerte bleiben
  als Abweichung), Bericht: php artisan process:settings-report

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 16:25:46 +01:00

93 lines
4.1 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Http\Controllers;
use App\Actions\CancelBookingByGuest;
use App\Actions\ReleaseReservation;
use App\Enums\BookingStatus;
use App\Enums\CancellationMode;
use App\Exceptions\ReservationException;
use App\Models\Booking;
use App\Process\CaseLog;
use App\Support\CancellationCost;
use DateTimeInterface;
use Illuminate\Contracts\View\View;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\URL;
/**
* Pages behind the signed links in the guest's mails: release a held request, cancel a booking. Opening a page
* changes nothing; only the button on it does (POST, signed, rate limited).
*/
class SelfServiceController extends Controller
{
public function showRelease(Booking $booking): View
{
$booking->loadMissing(['guest', 'property']);
return view('self-service.release', [
'booking' => $booking,
'canRelease' => in_array($booking->status, BookingStatus::holding(), true) && $booking->isHoldActive(),
'released' => $booking->status === BookingStatus::Declined && $booking->declined_by === 'guest',
'action' => $this->signed('reservations.release.confirm', $booking, now()->addHour()),
'title' => 'Zeitraum freigeben',
]);
}
public function release(Booking $booking, ReleaseReservation $release): RedirectResponse
{
try {
CaseLog::context(fn () => $release->handle($booking), actor: CaseLog::GUEST);
} catch (ReservationException $exception) {
return redirect()->to($this->signed('reservations.release', $booking, now()->addDays(2)))->with('self-service.error', $exception->getMessage());
}
return redirect()->to($this->signed('reservations.release', $booking, now()->addDays(30)))->with('self-service.success', 'Vielen Dank – der Zeitraum ist wieder freigegeben.');
}
public function showCancel(Booking $booking, CancelBookingByGuest $cancel): View
{
$booking->loadMissing(['guest', 'property']);
$open = in_array($booking->status, BookingStatus::occupying(), true) && ! $booking->arrival->isPast();
return view('self-service.cancel', [
'booking' => $booking,
'canCancel' => $open && ! $booking->cancellationRequested(),
'alreadyAsked' => $booking->status === BookingStatus::Cancelled || $booking->cancellationRequested(),
'instant' => $cancel->modeFor($booking) === CancellationMode::Instant,
'cost' => CancellationCost::calculate($booking),
'action' => $this->signed('bookings.cancel.confirm', $booking, now()->addHour()),
'title' => 'Buchung stornieren',
]);
}
public function cancel(Request $request, Booking $booking, CancelBookingByGuest $cancel): RedirectResponse
{
$data = $request->validate(['message' => ['nullable', 'string', 'max:1000']]);
$back = fn (int $days): string => $this->signed('bookings.cancel', $booking, now()->addDays($days));
try {
$outcome = CaseLog::context(fn () => $cancel->handle($booking, $data['message'] ?? null), actor: CaseLog::GUEST);
} catch (ReservationException $exception) {
return redirect()->to($back(2))->with('self-service.error', $exception->getMessage());
}
$success = match ($outcome) {
CancellationMode::Instant => 'Ihre Buchung ist storniert. Eine Bestätigung haben wir Ihnen per E-Mail gesendet.',
CancellationMode::Request => 'Wir haben Ihren Stornierungswunsch erhalten. Ihre Buchung bleibt bestehen, bis wir uns bei Ihnen gemeldet haben.',
default => 'Ihr Stornierungswunsch liegt uns bereits vor.',
};
return redirect()->to($back(30))->with('self-service.success', $success);
}
private function signed(string $name, Booking $booking, DateTimeInterface $expiration): string
{
$parameters = ['booking' => $booking];
return $booking->website()?->temporarySignedRoute($name, $expiration, $parameters)
?? URL::temporarySignedRoute($name, $expiration, $parameters);
}
}