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>
69 lines
1.9 KiB
PHP
69 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Models\Concerns\BelongsToTenant;
|
|
use App\Observers\BlockedPeriodObserver;
|
|
use Carbon\CarbonInterface;
|
|
use Database\Factories\BlockedPeriodFactory;
|
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
|
use Illuminate\Database\Eloquent\Attributes\ObservedBy;
|
|
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;
|
|
|
|
/**
|
|
* Dates that are not bookable (own use, maintenance, bookings from portals).
|
|
* Like bookings, ends_on is the first free day again.
|
|
*/
|
|
#[ObservedBy(BlockedPeriodObserver::class)]
|
|
#[Fillable(['property_id', 'channel_id', 'starts_on', 'ends_on', 'reason', 'source', 'external_uid'])]
|
|
class BlockedPeriod extends Model
|
|
{
|
|
/** @use HasFactory<BlockedPeriodFactory> */
|
|
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);
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo<Channel, $this>
|
|
*/
|
|
public function channel(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Channel::class);
|
|
}
|
|
|
|
/**
|
|
* @param Builder<BlockedPeriod> $query
|
|
* @return Builder<BlockedPeriod>
|
|
*/
|
|
#[Scope]
|
|
protected function overlapping(Builder $query, CarbonInterface $from, CarbonInterface $until): Builder
|
|
{
|
|
return $query
|
|
->whereDate('starts_on', '<', $until)
|
|
->whereDate('ends_on', '>', $from);
|
|
}
|
|
}
|