Zentralen Belegungsplan und plattformuebergreifende Buchungs- und Gaesteverwaltung integrieren
Deploy FeWo mit PipelineManager / deploy (push) Successful in 2m41s
Deploy FeWo mit PipelineManager / deploy (push) Successful in 2m41s
This commit is contained in:
1 parent
c74199e978
commit
f369018a68
41 files changed
+1343
-157
No files matched your search
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\OccupationKind;
|
||||
use App\Models\Concerns\BelongsToTenant;
|
||||
use App\Models\Concerns\HasChannelProvenance;
|
||||
use App\Observers\BlockedPeriodObserver;
|
||||
@@ -15,6 +16,7 @@
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
/**
|
||||
@@ -23,7 +25,7 @@
|
||||
*/
|
||||
#[ObservedBy(BlockedPeriodObserver::class)]
|
||||
#[Hidden(['ical_properties', 'ical_raw', 'ical_interpretation'])]
|
||||
#[Fillable(['property_id', 'channel_id', 'origin_channel_id', 'starts_on', 'ends_on', 'reason', 'source', 'external_uid', 'needs_review', 'review_note', 'missing_imports', 'is_representation', 'canonical_block_id', 'linked_booking_id', 'export_approved', 'reviewed_at'])]
|
||||
#[Fillable(['property_id', 'channel_id', 'origin_channel_id', 'guest_id', 'occupation_kind', 'starts_on', 'ends_on', 'reason', 'source', 'external_uid', 'needs_review', 'review_note', 'missing_imports', 'is_representation', 'canonical_block_id', 'linked_booking_id', 'export_approved', 'reviewed_at'])]
|
||||
class BlockedPeriod extends Model
|
||||
{
|
||||
/** @use HasFactory<BlockedPeriodFactory> */
|
||||
@@ -39,6 +41,7 @@ class BlockedPeriod extends Model
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'occupation_kind' => OccupationKind::class,
|
||||
'starts_on' => 'immutable_date',
|
||||
'ends_on' => 'immutable_date',
|
||||
'needs_review' => 'boolean',
|
||||
@@ -87,6 +90,73 @@ public function linkedBooking(): BelongsTo
|
||||
return $this->belongsTo(Booking::class, 'linked_booking_id');
|
||||
}
|
||||
|
||||
/** @return BelongsTo<Guest, $this> */
|
||||
public function guest(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Guest::class);
|
||||
}
|
||||
|
||||
public function occupationKind(): OccupationKind
|
||||
{
|
||||
if ($this->source === 'manual') {
|
||||
return OccupationKind::Block;
|
||||
}
|
||||
|
||||
return $this->occupation_kind ?? ($this->ical_event_type === 'portal_reservation' ? OccupationKind::Reservation : OccupationKind::Unknown);
|
||||
}
|
||||
|
||||
public function guestName(): ?string
|
||||
{
|
||||
if ($this->is_representation) {
|
||||
return $this->linkedBooking?->guest?->full_name ?? $this->canonicalBlock?->guestName();
|
||||
}
|
||||
|
||||
return $this->guest?->full_name ?? ($this->ical_interpretation['fields']['guest_full_name'] ?? $this->ical_interpretation['fields']['guest_first_name'] ?? null);
|
||||
}
|
||||
|
||||
public function assignedGuest(): ?Guest
|
||||
{
|
||||
return $this->is_representation ? ($this->linkedBooking?->guest ?? $this->canonicalBlock?->assignedGuest()) : $this->guest;
|
||||
}
|
||||
|
||||
/** @return HasMany<BlockedPeriod, $this> */
|
||||
public function channelRepresentations(): HasMany
|
||||
{
|
||||
return $this->hasMany(self::class, 'canonical_block_id');
|
||||
}
|
||||
|
||||
/** @param Builder<BlockedPeriod> $query
|
||||
* @return Builder<BlockedPeriod>
|
||||
*/
|
||||
#[Scope]
|
||||
protected function reservations(Builder $query): Builder
|
||||
{
|
||||
return $query->whereIn('source', ['channel', 'email'])->where(fn (Builder $query) => $query
|
||||
->where('occupation_kind', OccupationKind::Reservation)
|
||||
->orWhere(fn (Builder $query) => $query->whereNull('occupation_kind')->where('ical_event_type', 'portal_reservation')));
|
||||
}
|
||||
|
||||
/** @param Builder<BlockedPeriod> $query
|
||||
* @return Builder<BlockedPeriod>
|
||||
*/
|
||||
#[Scope]
|
||||
protected function explicitBlocks(Builder $query): Builder
|
||||
{
|
||||
return $query->where(fn (Builder $query) => $query->where('source', 'manual')->orWhere('occupation_kind', OccupationKind::Block));
|
||||
}
|
||||
|
||||
/** @param Builder<BlockedPeriod> $query
|
||||
* @return Builder<BlockedPeriod>
|
||||
*/
|
||||
#[Scope]
|
||||
protected function unclear(Builder $query): Builder
|
||||
{
|
||||
return $query->whereIn('source', ['channel', 'email'])->where(fn (Builder $query) => $query
|
||||
->where('needs_review', true)
|
||||
->orWhere('occupation_kind', OccupationKind::Unknown)
|
||||
->orWhere(fn (Builder $query) => $query->whereNull('occupation_kind')->where(fn (Builder $query) => $query->whereNull('ical_event_type')->orWhere('ical_event_type', '!=', 'portal_reservation'))));
|
||||
}
|
||||
|
||||
/** @param Builder<BlockedPeriod> $query
|
||||
* @return Builder<BlockedPeriod>
|
||||
*/
|
||||
|
||||
@@ -157,6 +157,36 @@ public function guest(): BelongsTo
|
||||
return $this->belongsTo(Guest::class);
|
||||
}
|
||||
|
||||
/** @return BelongsTo<Channel, $this> */
|
||||
public function originChannel(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Channel::class, 'origin_channel_id');
|
||||
}
|
||||
|
||||
/** @return BelongsTo<Channel, $this> */
|
||||
public function importChannel(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Channel::class, 'import_channel_id');
|
||||
}
|
||||
|
||||
/** @return HasMany<BlockedPeriod, $this> */
|
||||
public function channelRepresentations(): HasMany
|
||||
{
|
||||
return $this->hasMany(BlockedPeriod::class, 'linked_booking_id');
|
||||
}
|
||||
|
||||
public function bookingChannelLabel(): string
|
||||
{
|
||||
return $this->originChannel?->name ?? $this->importChannel?->name ?? match ($this->source) {
|
||||
'website' => 'Eigene Webseite',
|
||||
'manual' => 'Manuell / direkt',
|
||||
'phone' => 'Telefon',
|
||||
'email' => 'E-Mail',
|
||||
'direct' => 'Direkt',
|
||||
default => $this->source,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Bookings that currently occupy their dates: confirmed ones and requests/offers whose hold has not expired.
|
||||
*
|
||||
|
||||
@@ -42,12 +42,18 @@ public function bookings(): HasMany
|
||||
return $this->hasMany(Booking::class)->latest('arrival');
|
||||
}
|
||||
|
||||
/** @return HasMany<BlockedPeriod, $this> */
|
||||
public function portalStays(): HasMany
|
||||
{
|
||||
return $this->hasMany(BlockedPeriod::class)->reservations()->occupying()->latest('starts_on');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Attribute<string, never>
|
||||
*/
|
||||
protected function fullName(): Attribute
|
||||
{
|
||||
return Attribute::get(fn (): string => "{$this->first_name} {$this->last_name}");
|
||||
return Attribute::get(fn (): string => trim("{$this->first_name} {$this->last_name}"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user