Files
fewo-stommer/app/Actions/ReportChannelConflicts.php
T
LarsandClaude Opus 5.5 1c757f7429 Erinnerungsabstand und taegliche/woechentliche Zusammenfassung einstellbar
System > Betrieb > Benachrichtigungen: offene Meldungen (Doppelbuchungen im
Postfach, Portal-Aufgaben) nur einmal oder alle 1/2/3/7 Tage erneut senden;
Tages- und/oder Wochenuebersicht mit waehlbarer Uhrzeit, Wochentag und Inhalt
(Postfach, Anfragen, Neues, An-/Abreisen, Zahlungen, Portale, Bewertungen).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 10:11:15 +01:00

55 lines
1.9 KiB
PHP

<?php
namespace App\Actions;
use App\Enums\InboxMessageKind;
use App\Filament\Pages\OccupancyCalendar;
use App\Mail\ChannelConflict;
use App\Models\Channel;
use App\Support\Inbox;
use App\Support\Settings;
use Carbon\CarbonInterface;
use Illuminate\Support\Facades\Mail;
/**
* Reports possible double bookings found while importing portal occupations (calendar sync or portal
* e-mail). Every conflict lands in the admin inbox once; only conflicts not reported before are e-mailed,
* so a lasting overlap does not trigger a mail on every sync. Unread ones are repeated after the landlord's
* reminder interval while the overlap persists (App\Support\Inbox).
*/
class ReportChannelConflicts
{
public function __construct(private Inbox $inbox) {}
/**
* @param array<string, CarbonInterface> $conflicts description => first night of the portal occupation
* @return list<string> the conflicts e-mailed now (new ones and due reminders)
*/
public function handle(Channel $channel, array $conflicts): array
{
$new = [];
$reminders = [];
foreach ($conflicts as $description => $startsOn) {
$message = $this->inbox->post(
InboxMessageKind::ChannelConflict,
$channel->id.':'.sha1($description),
'Mögliche Doppelbuchung über '.$channel->name,
$description,
$channel,
OccupancyCalendar::getUrl(['monat' => $startsOn->format('Y-m'), 'wohnung' => $channel->property_id]),
);
if ($message?->wasRecentlyCreated) {
$new[] = $description;
} elseif ($message) {
$reminders[] = $description;
}
}
if ($new !== [] || $reminders !== []) {
rescue(fn () => Mail::to(Settings::notificationRecipients())->send(new ChannelConflict($channel, $new, $reminders)));
}
return [...$new, ...$reminders];
}
}