Files
fewo-stommer/app/Actions/RemindChannelTasks.php
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

40 lines
1.3 KiB
PHP

<?php
namespace App\Actions;
use App\Mail\ChannelTasksNotification;
use App\Models\ChannelTask;
use App\Support\Settings;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Facades\Mail;
/**
* Reminds the landlord about blocking tasks that are still open after the reminder time, and again after
* the landlord's reminder interval while they stay open (Settings::reminderIntervalDays(), 0 = only once).
*/
class RemindChannelTasks
{
public function handle(): int
{
$interval = Settings::reminderIntervalDays();
$tasks = ChannelTask::query()
->open()
->where(fn (Builder $query) => $query
->whereNull('reminded_at')
->when($interval > 0, fn (Builder $query) => $query->orWhere('reminded_at', '<=', now()->subDays($interval))))
->where('created_at', '<=', now()->subMinutes(config('fewo.channels.task_reminder_after_minutes')))
->with('channel')
->get();
if ($tasks->isEmpty()) {
return 0;
}
Mail::to(Settings::notificationRecipients())->send(new ChannelTasksNotification($tasks->all(), reminder: true));
ChannelTask::whereKey($tasks->modelKeys())->update(['reminded_at' => now()]);
return $tasks->count();
}
}