Deploy FeWo mit PipelineManager / deploy (push) Successful in 3m38s
- Buchung erfassen: Buchungsweg Portal (Referenz, Portalpreis, ohne Kontaktdaten), Prozess bestaetigen/Vertrag sofort/nur erfassen - Buchungsakte: Kontaktdaten eintragen (automatisch oder manuell weiter), Gast um Kontaktdaten bitten, Status von Hand aendern, Archivieren - Liste: Filter Kanal, Anreisezeitraum, Kontaktdaten fehlen; Spalten ausblendbar; Archiv - Klaerung: verstaendlichere Texte, eigenstaendige Belegung mit Kanal gilt als geklaert (Gitea #4) - Akte per Button aus Liste und Belegungsplan erreichbar - Menue: Gruppen Verwaltung (Tagesgeschaeft) und Einrichtung (Konfiguration), einfache Ansicht auf 8 Punkte Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
59 lines
3.9 KiB
PHP
59 lines
3.9 KiB
PHP
<?php
|
|
|
|
namespace App\Actions;
|
|
|
|
use App\Enums\OccupationKind;
|
|
use App\Models\BlockedPeriod;
|
|
use App\Models\Booking;
|
|
use App\Models\Channel;
|
|
use App\Models\Property;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Validation\ValidationException;
|
|
|
|
class ResolveChannelOccupation
|
|
{
|
|
public function handle(BlockedPeriod $block, string $resolution, ?int $targetId = null, ?int $originId = null): BlockedPeriod
|
|
{
|
|
return DB::transaction(function () use ($block, $resolution, $targetId, $originId): BlockedPeriod {
|
|
Property::query()->whereKey($block->property_id)->lockForUpdate()->firstOrFail();
|
|
$block = BlockedPeriod::query()->whereKey($block->id)->lockForUpdate()->firstOrFail();
|
|
if (! in_array($block->source, ['channel', 'email'], true)) {
|
|
throw ValidationException::withMessages(['resolution' => 'Nur importierte Portalereignisse benötigen diese Zuordnung.']);
|
|
}
|
|
if (! in_array($resolution, ['independent', 'block', 'booking'], true)) {
|
|
throw ValidationException::withMessages(['resolution' => 'Bitte eine gültige Klärung wählen.']);
|
|
}
|
|
if ($originId !== null && ! Channel::query()->whereKey($originId)->where('property_id', $block->property_id)->exists()) {
|
|
throw ValidationException::withMessages(['origin_channel_id' => 'Der Ursprungskanal muss zur selben Wohnung gehören.']);
|
|
}
|
|
$attributes = ['is_representation' => false, 'canonical_block_id' => null, 'linked_booking_id' => null,
|
|
'origin_channel_id' => $originId, 'is_private' => $originId === null && $block->is_private, 'export_approved' => true, 'needs_review' => false,
|
|
'reviewed_at' => now(), 'review_note' => 'Als eigenständige Belegung persönlich bestätigt.'];
|
|
if ($resolution !== 'independent') {
|
|
$query = $resolution === 'booking' ? Booking::query()->occupying() : BlockedPeriod::query()->occupying()->whereKeyNot($block->id);
|
|
$target = $query->where('property_id', $block->property_id)->whereKey($targetId)->lockForUpdate()->first();
|
|
$start = $resolution === 'booking' ? $target?->arrival : $target?->starts_on;
|
|
$end = $resolution === 'booking' ? $target?->departure : $target?->ends_on;
|
|
if ($target === null || ! $block->starts_on->equalTo($start) || ! $block->ends_on->equalTo($end)) {
|
|
throw ValidationException::withMessages(['target_id' => 'Eine belegende Buchung oder führende Sperre derselben Wohnung mit genau diesem Zeitraum wählen.']);
|
|
}
|
|
if (BlockedPeriod::query()->where('canonical_block_id', $block->id)->exists()) {
|
|
throw ValidationException::withMessages(['target_id' => 'Diese Sperre führt bereits andere Kalenderdarstellungen. Die Zuordnung an der untergeordneten Darstellung ändern.']);
|
|
}
|
|
$attributes = [...$attributes, 'is_representation' => true, 'export_approved' => false,
|
|
'canonical_block_id' => $resolution === 'block' ? $target->id : null,
|
|
'linked_booking_id' => $resolution === 'booking' ? $target->id : null,
|
|
'review_note' => 'Persönlich zugeordnet; nur die führende Belegung steuert Verfügbarkeit und Export.'];
|
|
}
|
|
// A stay confirmed as independent with a known booking channel (or privately) is no longer "unclear".
|
|
if ($resolution === 'independent' && ($originId !== null || $attributes['is_private']) && in_array($block->occupationKind(), [OccupationKind::Unknown], true)) {
|
|
$attributes['occupation_kind'] = OccupationKind::Reservation;
|
|
}
|
|
$block->forceFill(['representation_automatic' => false])->fill($attributes)->save();
|
|
app(ReconcileChannelRepresentations::class)->handle($block->property);
|
|
|
|
return $block->refresh();
|
|
});
|
|
}
|
|
}
|