- IMAP-Abruf jede Minute (webklex/php-imap, ohne PHP-imap-Erweiterung) oder signierter Push von n8n - Parser für Buchungs-, Storno- und Anfrage-Mails (de/en), Buchungsnummer, An-/Abreise - Erkannte Buchungen werden sofort gesperrt und an handgepflegte Portale weitergegeben; Kalender-Abgleich übernimmt bzw. ersetzt Mail-Sperren - Unklare Mails: Prüf-Mail + Admin-Liste Portal-E-Mails mit Aktion Sperre anlegen - Überwachung des Postfachs in Monitor und /health/sync Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
37 lines
1.7 KiB
PHP
37 lines
1.7 KiB
PHP
<?php
|
||
|
||
namespace App\Channels;
|
||
|
||
use App\Models\BlockedPeriod;
|
||
use App\Models\Booking;
|
||
|
||
/**
|
||
* Finds occupations from other sources that overlap a block reported by a portal
|
||
* (a possible double booking). Blocks of the same portal never conflict with each other.
|
||
*/
|
||
class ConflictDetector
|
||
{
|
||
/**
|
||
* @return list<string> human readable descriptions
|
||
*/
|
||
public function conflictsFor(BlockedPeriod $block): array
|
||
{
|
||
$property = $block->property;
|
||
$channelName = $block->channel->name ?? 'Sperre';
|
||
$period = $block->starts_on->format('d.m.Y').' – '.$block->ends_on->format('d.m.Y');
|
||
|
||
$bookings = $property->bookings()->occupying()->overlapping($block->starts_on, $block->ends_on)->with('guest')->get()
|
||
->map(fn (Booking $booking): string => "{$channelName} meldet {$period}, überschneidet sich mit Buchung {$booking->reference} ({$booking->guest->full_name}, {$booking->arrival->format('d.m.Y')} – {$booking->departure->format('d.m.Y')})");
|
||
|
||
$blocks = $property->blockedPeriods()
|
||
->overlapping($block->starts_on, $block->ends_on)
|
||
->whereKeyNot($block->getKey())
|
||
->when($block->channel_id, fn ($query) => $query->where(fn ($query) => $query->whereNull('channel_id')->orWhere('channel_id', '!=', $block->channel_id)))
|
||
->with('channel')
|
||
->get()
|
||
->map(fn (BlockedPeriod $other): string => "{$channelName} meldet {$period}, überschneidet sich mit Sperre „".($other->channel->name ?? $other->reason ?? 'manuell')."“ ({$other->starts_on->format('d.m.Y')} – {$other->ends_on->format('d.m.Y')})");
|
||
|
||
return [...$bookings->all(), ...$blocks->all()];
|
||
}
|
||
}
|