Files
fewo-stommer/app/Models/Season.php
LarsandCursor 8ebc1a3878 Assign the existing site to one landlord so stommer.info can run tenancy.
Seebad 0.3 stays in this release. With a single landlord every host still reaches the default website.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-23 12:00:11 +02:00

65 lines
1.8 KiB
PHP
Raw Permalink 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\Models;
use App\Models\Concerns\BelongsToTenant;
use Carbon\CarbonInterface;
use Database\Factories\SeasonFactory;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Attributes\Scope;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* A pricing period. A night belongs to the season when starts_on <= night < ends_on,
* so consecutive seasons share their boundary date (e.g. 03.01.–07.03. and 07.03.–03.04.).
*/
#[Fillable(['property_id', 'name', 'starts_on', 'ends_on', 'nightly_rate', 'min_nights'])]
class Season extends Model
{
/** @use HasFactory<SeasonFactory> */
use BelongsToTenant, HasFactory;
/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
'starts_on' => 'immutable_date',
'ends_on' => 'immutable_date',
];
}
/**
* @return BelongsTo<Property, $this>
*/
public function property(): BelongsTo
{
return $this->belongsTo(Property::class);
}
/**
* Seasons that share at least one night with the half-open period [$from, $until).
*
* @param Builder<Season> $query
* @return Builder<Season>
*/
#[Scope]
protected function overlapping(Builder $query, CarbonInterface $from, CarbonInterface $until): Builder
{
return $query
->whereDate('starts_on', '<', $until)
->whereDate('ends_on', '>', $from);
}
public function containsNight(CarbonInterface $night): bool
{
return $this->starts_on->lessThanOrEqualTo($night) && $this->ends_on->greaterThan($night);
}
}