Phase 2: Kalender, Anfrage, Vorreservierung & Sonderangebote

- Gäste, Buchungen (Status-Workflow), Sperrzeiten, Sonderangebote
- Vorreservierung mit Haltezeit je Wohnung; abgelaufene Holds geben den Kalender sofort frei, Cron setzt Status und benachrichtigt
- Sonderangebote/Sonderkonditionen: %, € pro Aufenthalt, Sonderpreis/Nacht, Gratis-Nächte; Bedingungen u. a. Saison, Vorlauf, Wochentag, Nächte, Aktionscode; bestes Einzel- vs. kombinierte Angebote
- Öffentliche Seite /buchen: Belegungskalender, Live-Preis, Anfrageformular (Honeypot, Rate-Limit)
- E-Mails: Angebot an Gast, Benachrichtigung Vermieter, Bestätigung, Absage, Ablauf
- Filament: Anfragen & Buchungen (bestätigen, ablehnen, verlängern, stornieren, Telefonbuchung), Gäste, Sperrzeiten, Sonderangebote
- Deutsche Validierungstexte

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Lars StommerandClaude Opus 5.5 committed 2026-10-22 09:43:12 +02:00
1 parent 2e9a391b37
commit 08b6582fa1
79 files changed
+6213 -76

No files matched your search

+45
View File
@@ -0,0 +1,45 @@
<?php
namespace App\Actions;
use App\Availability\AvailabilityChecker;
use App\Enums\BookingStatus;
use App\Exceptions\ReservationException;
use App\Mail\BookingConfirmed;
use App\Models\Booking;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Mail;
/**
* The landlord accepts a reservation. Expired reservations can still be confirmed while the dates are free.
*/
class ConfirmBooking
{
public function __construct(private AvailabilityChecker $availability) {}
/**
* @throws ReservationException
*/
public function handle(Booking $booking, bool $notifyGuest = true): void
{
if (! in_array($booking->status, [BookingStatus::Reserved, BookingStatus::Expired], true)) {
throw ReservationException::invalidTransition($booking->status->getLabel(), 'bestätigt');
}
DB::transaction(function () use ($booking): void {
if (! $this->availability->isAvailable($booking->property, $booking->arrival, $booking->departure, ignore: $booking)) {
throw ReservationException::notAvailable();
}
$booking->update([
'status' => BookingStatus::Confirmed,
'hold_expires_at' => null,
'confirmed_at' => now(),
]);
});
if ($notifyGuest) {
Mail::to($booking->guest->email, $booking->guest->full_name)->send(new BookingConfirmed($booking));
}
}
}
+88
View File
@@ -0,0 +1,88 @@
<?php
namespace App\Actions;
use App\Availability\AvailabilityChecker;
use App\Enums\BookingStatus;
use App\Exceptions\ReservationException;
use App\Mail\NewReservation;
use App\Mail\ReservationReceived;
use App\Models\Booking;
use App\Models\Guest;
use App\Models\Property;
use App\Pricing\PriceCalculator;
use App\Pricing\QuoteException;
use App\Pricing\StayRequest;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Mail;
use Throwable;
/**
* Turns a guest request into a reservation that holds the dates for the property's hold time,
* and sends the quote to the guest and a notification to the landlord.
*/
class CreateReservation
{
public function __construct(
private PriceCalculator $calculator,
private AvailabilityChecker $availability,
) {}
/**
* @param array{first_name: string, last_name: string, email: string, phone?: ?string, street?: ?string, postal_code?: ?string, city?: ?string, country?: ?string} $guestData
*
* @throws QuoteException
* @throws ReservationException
*/
public function handle(Property $property, StayRequest $stay, array $guestData, ?string $message = null, string $source = 'website', bool $sendMails = true): Booking
{
$booking = DB::transaction(function () use ($property, $stay, $guestData, $message, $source): Booking {
Property::whereKey($property->getKey())->lockForUpdate()->first();
if (! $this->availability->isAvailable($property, $stay->arrival, $stay->departure)) {
throw ReservationException::notAvailable();
}
$quote = $this->calculator->calculate($property, $stay);
$guest = Guest::firstOrNew(['email' => mb_strtolower($guestData['email'])]);
$guest->fill($guestData)->fill(['email' => mb_strtolower($guestData['email'])])->save();
return $property->bookings()->create([
'guest_id' => $guest->id,
'status' => BookingStatus::Reserved,
'source' => $source,
'arrival' => $stay->arrival->toDateString(),
'departure' => $stay->departure->toDateString(),
'guests' => $stay->guests,
'extras' => array_filter($stay->extras),
'promo_code' => $quote->promoCodeApplied ? $stay->promoCode : null,
'quote' => $quote->toArray(),
'total' => $quote->total(),
'deposit' => $quote->deposit(),
'balance_due_on' => $quote->balanceDueOn->toDateString(),
'hold_expires_at' => now()->addHours($property->hold_hours),
'message' => $message,
]);
});
if ($sendMails) {
$this->sendMails($booking);
}
return $booking;
}
/**
* A failing mail server must not lose the reservation; failures are reported and visible in the log.
*/
private function sendMails(Booking $booking): void
{
try {
Mail::to($booking->guest->email, $booking->guest->full_name)->send(new ReservationReceived($booking));
Mail::to(config('fewo.notification_email'))->send(new NewReservation($booking));
} catch (Throwable $exception) {
report($exception);
}
}
}
+31
View File
@@ -0,0 +1,31 @@
<?php
namespace App\Actions;
use App\Enums\BookingStatus;
use App\Exceptions\ReservationException;
use App\Mail\BookingDeclined;
use App\Models\Booking;
use Illuminate\Support\Facades\Mail;
class DeclineBooking
{
/**
* @throws ReservationException
*/
public function handle(Booking $booking, bool $notifyGuest = true): void
{
if (! in_array($booking->status, [BookingStatus::Reserved, BookingStatus::Expired], true)) {
throw ReservationException::invalidTransition($booking->status->getLabel(), 'abgelehnt');
}
$booking->update([
'status' => BookingStatus::Declined,
'hold_expires_at' => null,
]);
if ($notifyGuest) {
Mail::to($booking->guest->email, $booking->guest->full_name)->send(new BookingDeclined($booking));
}
}
}
+32
View File
@@ -0,0 +1,32 @@
<?php
namespace App\Actions;
use App\Enums\BookingStatus;
use App\Mail\ReservationExpired;
use App\Models\Booking;
use Illuminate\Support\Facades\Mail;
/**
* Marks reservations whose hold time is over as expired and tells the landlord.
* The calendar already treats them as free once the hold time is over; this only updates the status.
*/
class ExpireReservations
{
public function handle(): int
{
$expired = Booking::query()
->where('status', BookingStatus::Reserved)
->where('hold_expires_at', '<=', now())
->with(['guest', 'property'])
->get();
foreach ($expired as $booking) {
$booking->update(['status' => BookingStatus::Expired]);
Mail::to(config('fewo.notification_email'))->send(new ReservationExpired($booking));
}
return $expired->count();
}
}