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:
1 parent
2e9a391b37
commit
08b6582fa1
79 files changed
+6213
-76
No files matched your search
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Availability;
|
||||
|
||||
use App\Models\BlockedPeriod;
|
||||
use App\Models\Booking;
|
||||
use App\Models\Property;
|
||||
use Carbon\CarbonImmutable;
|
||||
|
||||
/**
|
||||
* Works on nights: a stay from $from to $until occupies the nights $from … $until - 1 day,
|
||||
* so changeover days (departure and arrival on the same day) are possible.
|
||||
*/
|
||||
class AvailabilityChecker
|
||||
{
|
||||
public function isAvailable(Property $property, CarbonImmutable $from, CarbonImmutable $until, ?Booking $ignore = null): bool
|
||||
{
|
||||
$bookingConflict = $property->bookings()
|
||||
->occupying()
|
||||
->overlapping($from, $until)
|
||||
->when($ignore, fn ($query) => $query->whereKeyNot($ignore->getKey()))
|
||||
->exists();
|
||||
|
||||
return ! $bookingConflict && ! $property->blockedPeriods()->overlapping($from, $until)->exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* Occupied nights within [$from, $until) as a set of 'Y-m-d' strings.
|
||||
*
|
||||
* @return array<string, true>
|
||||
*/
|
||||
public function occupiedNights(Property $property, CarbonImmutable $from, CarbonImmutable $until): array
|
||||
{
|
||||
$periods = $property->bookings()->occupying()->overlapping($from, $until)->get(['arrival', 'departure'])
|
||||
->map(fn (Booking $booking): array => [$booking->arrival, $booking->departure])
|
||||
->concat($property->blockedPeriods()->overlapping($from, $until)->get(['starts_on', 'ends_on'])
|
||||
->map(fn (BlockedPeriod $period): array => [$period->starts_on, $period->ends_on]));
|
||||
|
||||
$nights = [];
|
||||
foreach ($periods as [$start, $end]) {
|
||||
for ($night = $start->max($from); $night->lessThan($end) && $night->lessThan($until); $night = $night->addDay()) {
|
||||
$nights[$night->toDateString()] = true;
|
||||
}
|
||||
}
|
||||
|
||||
return $nights;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user