Files
fewo-stommer/app/Http/Controllers/SelfServiceController.php
T
LarsandClaude Sonnet 5.5 0c4187edaf
Deploy FeWo mit PipelineManager / deploy (push) Successful in 3m34s
Stornoregeln mit automatischer Kostenberechnung, Storno-Verwaltung, Vertragsanlagen
- Stornoregel (Stufen nach Tagen vor Anreise, Mietpreis oder Gesamtpreis, Ersatzmieter-Gebuehr), je Vertragsvorlage,
  beim Angebot eingefroren, als Platzhalter im Vertrag
- Stornierung (Gast-Link oder Verwaltung) berechnet die Kosten, legt einen Stornofall an; Verwaltung Stornierungen
  mit Vorschlag, Festlegung, Saldo, Abrechnung und Erlass; Gast sieht die Kosten vorab auf der Storno-Seite
- Vertragsanlagen als eigene versionierte Dokumente mit Bedingung (immer, Zusatzleistung, Portal, von Hand),
  je Angebot ausgewaehlt und eingefroren; Zusatzleistungen in der Buchung erfassbar
- FeWo-direkt-Installation legt die Stornoregel aus Paragraf 13 an

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 16:32:48 +01:00

92 lines
4.0 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 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 {
$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,
'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 = $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);
}
}