- 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>
113 lines
2.6 KiB
PHP
113 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Carbon\CarbonImmutable;
|
|
use Database\Factories\PropertyFactory;
|
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
/**
|
|
* A rentable holiday apartment. All money amounts are stored in euro cents.
|
|
*/
|
|
#[Fillable([
|
|
'name',
|
|
'slug',
|
|
'address',
|
|
'size_sqm',
|
|
'max_guests',
|
|
'included_guests',
|
|
'extra_guest_fee_per_night',
|
|
'cleaning_fee',
|
|
'deposit_percent',
|
|
'balance_due_days_before_arrival',
|
|
'hold_hours',
|
|
'check_in_time',
|
|
'check_out_time',
|
|
'is_active',
|
|
])]
|
|
class Property extends Model
|
|
{
|
|
/** @use HasFactory<PropertyFactory> */
|
|
use HasFactory;
|
|
|
|
/**
|
|
* Get the attributes that should be cast.
|
|
*
|
|
* @return array<string, string>
|
|
*/
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'is_active' => 'boolean',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return HasMany<Season, $this>
|
|
*/
|
|
public function seasons(): HasMany
|
|
{
|
|
return $this->hasMany(Season::class)->orderBy('starts_on');
|
|
}
|
|
|
|
/**
|
|
* @return HasMany<Booking, $this>
|
|
*/
|
|
public function bookings(): HasMany
|
|
{
|
|
return $this->hasMany(Booking::class);
|
|
}
|
|
|
|
/**
|
|
* @return HasMany<BlockedPeriod, $this>
|
|
*/
|
|
public function blockedPeriods(): HasMany
|
|
{
|
|
return $this->hasMany(BlockedPeriod::class)->orderBy('starts_on');
|
|
}
|
|
|
|
/**
|
|
* @return HasMany<SpecialOffer, $this>
|
|
*/
|
|
public function specialOffers(): HasMany
|
|
{
|
|
return $this->hasMany(SpecialOffer::class);
|
|
}
|
|
|
|
/**
|
|
* Periods within [$from, $until) for which no season defines a price.
|
|
*
|
|
* @return list<array{from: CarbonImmutable, until: CarbonImmutable}>
|
|
*/
|
|
public function uncoveredPeriods(CarbonImmutable $from, CarbonImmutable $until): array
|
|
{
|
|
$gaps = [];
|
|
$cursor = $from;
|
|
|
|
foreach ($this->seasons()->overlapping($from, $until)->get() as $season) {
|
|
if ($season->starts_on->greaterThan($cursor)) {
|
|
$gaps[] = ['from' => $cursor, 'until' => $season->starts_on];
|
|
}
|
|
|
|
$cursor = $cursor->max($season->ends_on);
|
|
}
|
|
|
|
if ($cursor->lessThan($until)) {
|
|
$gaps[] = ['from' => $cursor, 'until' => $until];
|
|
}
|
|
|
|
return $gaps;
|
|
}
|
|
|
|
/**
|
|
* @return HasMany<Extra, $this>
|
|
*/
|
|
public function extras(): HasMany
|
|
{
|
|
return $this->hasMany(Extra::class)->orderBy('sort_order');
|
|
}
|
|
}
|