Doppelbuchungen nur einmal melden und im Postfach der Verwaltung zeigen
Der Kalenderabgleich alle 5 Minuten hat jede fortbestehende Ueberschneidung erneut gemailt. ReportChannelConflicts legt jede Ueberschneidung einmal im neuen Postfach (InboxMessage, Fingerabdruck je Mandant) ab und mailt nur neue. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
876a0a20f3
commit
b9225f5fb8
17 files changed
+593
-15
No files matched your search
@@ -0,0 +1,50 @@
|
||||
<?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.
|
||||
*/
|
||||
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 reported for the first time
|
||||
*/
|
||||
public function handle(Channel $channel, array $conflicts): array
|
||||
{
|
||||
$new = [];
|
||||
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) {
|
||||
$new[] = $description;
|
||||
}
|
||||
}
|
||||
|
||||
if ($new !== []) {
|
||||
rescue(fn () => Mail::to(Settings::notificationRecipients())->send(new ChannelConflict($channel, $new)));
|
||||
}
|
||||
|
||||
return $new;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user