*/ use BelongsToTenant, HasFactory; /** * Get the attributes that should be cast. * * @return array */ /** * Defaults of the minimum stay rules (as in the migration), also before the model is reloaded. * * @var array */ protected $attributes = [ 'min_stay_fill_gaps' => true, 'min_stay_until_changeover' => false, 'min_stay_absolute' => 2, 'offer_mode' => 'manual', 'pre_reservation_enabled' => true, 'arrival_info_days_before' => 3, 'cancellation_mode' => 'request', 'free_cancellation_days' => 14, ]; protected function casts(): array { return [ 'is_active' => 'boolean', 'offer_mode' => OfferMode::class, 'pre_reservation_enabled' => 'boolean', 'arrival_info_days_before' => 'integer', 'cancellation_mode' => CancellationMode::class, 'free_cancellation_days' => 'integer', 'contract_data' => 'array', 'process_overrides' => 'array', 'stay_tasks' => 'array', 'asks_arrival_time' => 'boolean', 'min_stay_fill_gaps' => 'boolean', 'min_stay_until_changeover' => 'boolean', 'changeover_weekday' => 'integer', 'min_stay_absolute' => 'integer', ]; } /** * @return HasMany */ /** * @return BelongsTo */ public function site(): BelongsTo { return $this->belongsTo(Site::class); } public function seasons(): HasMany { return $this->hasMany(Season::class)->orderBy('starts_on'); } /** * @return HasMany */ public function bookings(): HasMany { return $this->hasMany(Booking::class); } /** * @return HasMany */ public function blockedPeriods(): HasMany { return $this->hasMany(BlockedPeriod::class)->orderBy('starts_on'); } /** * @return HasMany */ /** * The portals of the property (the own website's settings entry is not a portal). */ public function channels(): HasMany { return $this->hasMany(Channel::class)->where('kind', Channel::KIND_PORTAL); } /** * @return HasMany */ public function amenities(): HasMany { return $this->hasMany(Amenity::class)->orderBy('sort_order'); } /** * @return HasOne */ public function floorPlan(): HasOne { return $this->hasOne(FloorPlan::class); } /** * @return HasMany */ public function specialOffers(): HasMany { return $this->hasMany(SpecialOffer::class); } /** * Periods within [$from, $until) for which no season defines a price. * * @return list */ 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 */ public function extras(): HasMany { return $this->hasMany(Extra::class)->orderBy('sort_order'); } /** * The stay tasks of this property (package 9): local services and provider jobs such as cleaning, linen or the key * handover, each with when it is due and for which kinds of stays it applies. No staff planning – a task per case. * * @return list}> */ public function stayTaskDefinitions(): array { $definitions = []; foreach ((array) ($this->stay_tasks ?? []) as $task) { $title = trim((string) ($task['title'] ?? '')); if ($title === '') { continue; } $definitions[] = [ 'key' => 'stay:'.mb_substr(Str::slug($title), 0, 70), 'title' => $title, 'when' => in_array($task['when'] ?? null, ['before_arrival', 'on_arrival', 'after_departure'], true) ? $task['when'] : 'before_arrival', 'days' => max(0, (int) ($task['days'] ?? 1)), 'responsible' => filled($task['responsible'] ?? null) ? trim((string) $task['responsible']) : null, 'applies_to' => array_values(array_filter((array) ($task['applies_to'] ?? ['rental']))) ?: ['rental'], ]; } return $definitions; } }