Files
fewo-stommer/app/Http/Controllers/SelfServiceController.php
T
LarsandClaude Sonnet 5.5 a73b164ea1
Deploy FeWo mit PipelineManager / deploy (push) Successful in 3m36s
Zahlungsaufgaben, Freigabe-/Storno-Link, Vertragsvorlagen, Anreise-Mail
- Zahlungen werden nicht mehr automatisch angemahnt: faellige Anzahlung/Restzahlung werden Aufgaben
  (Zahlungen & Wuensche, Tages-/Wochenuebersicht); Mail nur per Klick; je Portal und Buchungstyp abschaltbar
- Freigabe-Link in der Eingangsbestaetigung, Storno-Link in der Buchungsbestaetigung; je Wohnung
  Wunsch / sofort / sofort bis Frist; Stornowuensche und Kosten bleiben Aufgabe des Gastgebers
- Vertragsvorlagen mit Versionen (je Angebot, Portal oder Wohnung waehlbar), benutzte Versionen gesperrt;
  Angebot und finaler Vertrag als unveraenderliche PDF mit SHA-256, Vertrag wird nie neu geschrieben
- Anreise-Mail je Wohnung einstellbar (Standard 3 Tage), neue Textfelder Schluessel/Parken/Ankunftstag

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 12:46:29 +01:00

90 lines
3.9 KiB
PHP
Raw 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 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 {
$release->handle($booking);
} 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,
'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 = $cancel->handle($booking, $data['message'] ?? null);
} 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);
}
}