Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f5f18cd984 | ||
|
|
1c757f7429 | ||
|
|
70a39315e2 | ||
|
|
b9225f5fb8 | ||
|
|
876a0a20f3 |
No files matched your search
@@ -17,7 +17,7 @@ # Ferienwohnung Stommer
|
|||||||
- Website = theme system (`docs/THEMES.md`): themes live in `resources/themes/<key>` (theme.json, theme.css, theme.js, views); views resolve via the `theme::` namespace (theme → parent → base `ostsee-licht`). Pages are lists of sections (`app/Themes/Sections`, catalogue in `config/themes.php`); seasonal `Appearance`s override tokens/texts/hero photo/photos per section (stable `data.id` per placed section) and sections can be limited to appearances. Theme views use only token colour classes (`bg-accent`, `text-muted`, …). New designs are **additional** themes: `php artisan themes:make <key>`, `themes:check`, `themes:preview` – never edit `ostsee-licht` for a new design; authoring rules in `docs/THEME-ERSTELLUNG.md`. Resolve `Theme` lazily (`app(Theme::class)`), never in constructors – middleware `ResolveTheme` replaces it per request.
|
- Website = theme system (`docs/THEMES.md`): themes live in `resources/themes/<key>` (theme.json, theme.css, theme.js, views); views resolve via the `theme::` namespace (theme → parent → base `ostsee-licht`). Pages are lists of sections (`app/Themes/Sections`, catalogue in `config/themes.php`); seasonal `Appearance`s override tokens/texts/hero photo/photos per section (stable `data.id` per placed section) and sections can be limited to appearances. Theme views use only token colour classes (`bg-accent`, `text-muted`, …). New designs are **additional** themes: `php artisan themes:make <key>`, `themes:check`, `themes:preview` – never edit `ostsee-licht` for a new design; authoring rules in `docs/THEME-ERSTELLUNG.md`. Resolve `Theme` lazily (`app(Theme::class)`), never in constructors – middleware `ResolveTheme` replaces it per request.
|
||||||
- Operations (environments, Strato access, server .env, admin accounts, 2FA, known pitfalls): `docs/BETRIEB.md` – read it before touching a server. Admin accounts: `php artisan users:create`; 2FA (Filament app authentication) is mandatory for every account. Admin modes (`App\Enums\AdminMode`: simple/expert per user, user menu switch) only shape the menu via the `FollowsAdminMode` trait on every resource/page (simple menu = `AdminMode::SIMPLE_NAVIGATION`); permissions stay with roles/policies. New admin resources must use `FollowsAdminMode`.
|
- Operations (environments, Strato access, server .env, admin accounts, 2FA, known pitfalls): `docs/BETRIEB.md` – read it before touching a server. Admin accounts: `php artisan users:create`; 2FA (Filament app authentication) is mandatory for every account. Admin modes (`App\Enums\AdminMode`: simple/expert per user, user menu switch) only shape the menu via the `FollowsAdminMode` trait on every resource/page (simple menu = `AdminMode::SIMPLE_NAVIGATION`); permissions stay with roles/policies. New admin resources must use `FollowsAdminMode`.
|
||||||
- Deployment: `scripts/deploy.sh <env> setup|deploy [ref]|rollback|releases|artisan` (atomic releases on Strato, docs/DEPLOYMENT.md; the server keeps only the active release because of Strato's file quota – history = Git tags `deploy/<env>/<timestamp>`); CI `.gitea/workflows/deploy.yml`. Production has no dev packages (no factories/Faker) – production seeding via `ProductionSeeder`.
|
- Deployment: `scripts/deploy.sh <env> setup|deploy [ref]|rollback|releases|artisan` (atomic releases on Strato, docs/DEPLOYMENT.md; the server keeps only the active release because of Strato's file quota – history = Git tags `deploy/<env>/<timestamp>`); CI `.gitea/workflows/deploy.yml`. Production has no dev packages (no factories/Faker) – production seeding via `ProductionSeeder`.
|
||||||
- Strato specifics: `public/index.php` strips the internal `/releases/<v>/public` prefix from `REQUEST_URI` (signed URLs); `URL::forceRootUrl(APP_URL)` outside local/testing; mail routing: `App\Support\Settings` (admin page System › Betrieb, stored on the tenant) – test mode (default) sends every mail to the test recipient only, live delivers normally; `FEWO_MAIL_REDIRECT_TO` is a hard override. Landlord data, bank, addresses and periods are columns of `tenants`: `App\Tenancy\TenantConfig` lays them over `config('fewo.*')` and `mail.from` whenever the tenant context changes, so views and mails keep reading the config keys. Send notifications to `Settings::notificationRecipients()` (never `config('fewo.notification_email')` directly). Retention periods and bot-protection counters can only be tightened against the `.env` baseline. The booking form is protected against bots (`config('fewo.spam')`: honeypot, time trap, rate limits, max open holds per e-mail) – tests that submit it instantly set `fewo.spam.min_seconds` to 0.
|
- Strato specifics: `public/index.php` strips the internal `/releases/<v>/public` prefix from `REQUEST_URI` (signed URLs); `URL::forceRootUrl(APP_URL)` outside local/testing; mail routing: `App\Support\Settings` (admin page System › Betrieb, stored on the tenant) – test mode (default) sends every mail to the test recipient only, live delivers normally; `FEWO_MAIL_REDIRECT_TO` is a hard override. Landlord data, bank, addresses and periods are columns of `tenants`: `App\Tenancy\TenantConfig` lays them over `config('fewo.*')` and `mail.from` whenever the tenant context changes, so views and mails keep reading the config keys. Send notifications to `Settings::notificationRecipients()` (never `config('fewo.notification_email')` directly). Findings detected repeatedly (e.g. by the 5-minute sync) go through `AppSupportInbox` (admin Postfach, fingerprint per tenant, repeated only per the tenant's `reminder_interval_days`), never straight to mail; daily/weekly summaries: `SendDigests` + `DigestReport` (sections `DigestSection`). Retention periods and bot-protection counters can only be tightened against the `.env` baseline. The booking form is protected against bots (`config('fewo.spam')`: honeypot, time trap, rate limits, max open holds per e-mail) – tests that submit it instantly set `fewo.spam.min_seconds` to 0.
|
||||||
- Vite fonts plugin is removed on purpose (corporate proxy breaks remote font downloads, and fonts must be self-hosted for GDPR).
|
- Vite fonts plugin is removed on purpose (corporate proxy breaks remote font downloads, and fonts must be self-hosted for GDPR).
|
||||||
- PHP/Composer on this machine: winget package dir `%LOCALAPPDATA%\Microsoft\WinGet\Packages\PHP.PHP.8.4_*` (Composer as `composer\composer.phar` there).
|
- PHP/Composer on this machine: winget package dir `%LOCALAPPDATA%\Microsoft\WinGet\Packages\PHP.PHP.8.4_*` (Composer as `composer\composer.phar` there).
|
||||||
- Git remote: Gitea `https://gitea.stommer.de/Lars/fewo-stommer.git`, branch `main`.
|
- Git remote: Gitea `https://gitea.stommer.de/Lars/fewo-stommer.git`, branch `main`.
|
||||||
|
|||||||
@@ -9,13 +9,13 @@
|
|||||||
use App\Enums\PortalEmailStatus;
|
use App\Enums\PortalEmailStatus;
|
||||||
use App\Enums\PortalEmailType;
|
use App\Enums\PortalEmailType;
|
||||||
use App\Enums\TenantServiceKey;
|
use App\Enums\TenantServiceKey;
|
||||||
use App\Mail\ChannelConflict;
|
|
||||||
use App\Mail\PortalMailNotification;
|
use App\Mail\PortalMailNotification;
|
||||||
use App\Models\BlockedPeriod;
|
use App\Models\BlockedPeriod;
|
||||||
use App\Models\Channel;
|
use App\Models\Channel;
|
||||||
use App\Models\PortalEmail;
|
use App\Models\PortalEmail;
|
||||||
use App\Support\Settings;
|
use App\Support\Settings;
|
||||||
use App\Tenancy\TenantFeatures;
|
use App\Tenancy\TenantFeatures;
|
||||||
|
use Carbon\CarbonInterface;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Facades\Mail;
|
use Illuminate\Support\Facades\Mail;
|
||||||
|
|
||||||
@@ -80,7 +80,7 @@ public function handle(PortalMail $mail): ?PortalEmail
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($conflicts !== []) {
|
if ($conflicts !== []) {
|
||||||
rescue(fn () => Mail::to(Settings::notificationRecipients())->send(new ChannelConflict($channel, $conflicts)));
|
app(ReportChannelConflicts::class)->handle($channel, $conflicts);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $record;
|
return $record;
|
||||||
@@ -126,7 +126,7 @@ public function senders(Channel $channel): array
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param list<string> $conflicts
|
* @param array<string, CarbonInterface> $conflicts description => first night
|
||||||
* @return array{PortalEmailStatus, ?BlockedPeriod, ?string}
|
* @return array{PortalEmailStatus, ?BlockedPeriod, ?string}
|
||||||
*/
|
*/
|
||||||
private function block(Channel $channel, ParsedPortalMail $parsed, array &$conflicts): array
|
private function block(Channel $channel, ParsedPortalMail $parsed, array &$conflicts): array
|
||||||
@@ -158,7 +158,7 @@ private function block(Channel $channel, ParsedPortalMail $parsed, array &$confl
|
|||||||
$block->forceFill(['needs_review' => true, 'review_note' => 'Überlappende Portalrepräsentationen ohne gemeinsame Kennung persönlich prüfen.'])->saveQuietly();
|
$block->forceFill(['needs_review' => true, 'review_note' => 'Überlappende Portalrepräsentationen ohne gemeinsame Kennung persönlich prüfen.'])->saveQuietly();
|
||||||
}
|
}
|
||||||
|
|
||||||
$conflicts = $this->conflictDetector->conflictsFor($block);
|
$conflicts = array_fill_keys($this->conflictDetector->conflictsFor($block), $block->starts_on);
|
||||||
|
|
||||||
return [PortalEmailStatus::Blocked, $block, null];
|
return [PortalEmailStatus::Blocked, $block, null];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,18 +5,24 @@
|
|||||||
use App\Mail\ChannelTasksNotification;
|
use App\Mail\ChannelTasksNotification;
|
||||||
use App\Models\ChannelTask;
|
use App\Models\ChannelTask;
|
||||||
use App\Support\Settings;
|
use App\Support\Settings;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Support\Facades\Mail;
|
use Illuminate\Support\Facades\Mail;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reminds the landlord once about blocking tasks that are still open after the reminder time.
|
* 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
|
class RemindChannelTasks
|
||||||
{
|
{
|
||||||
public function handle(): int
|
public function handle(): int
|
||||||
{
|
{
|
||||||
|
$interval = Settings::reminderIntervalDays();
|
||||||
|
|
||||||
$tasks = ChannelTask::query()
|
$tasks = ChannelTask::query()
|
||||||
->open()
|
->open()
|
||||||
->whereNull('reminded_at')
|
->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')))
|
->where('created_at', '<=', now()->subMinutes(config('fewo.channels.task_reminder_after_minutes')))
|
||||||
->with('channel')
|
->with('channel')
|
||||||
->get();
|
->get();
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
<?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];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions;
|
||||||
|
|
||||||
|
use App\Enums\DigestSection;
|
||||||
|
use App\Mail\Digest;
|
||||||
|
use App\Models\Tenant;
|
||||||
|
use App\Support\DigestReport;
|
||||||
|
use App\Support\Settings;
|
||||||
|
use Carbon\CarbonImmutable;
|
||||||
|
use Illuminate\Support\Facades\Mail;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends the landlord's daily and/or weekly summary once the chosen hour has come (System › Betrieb ›
|
||||||
|
* Benachrichtigungen). On the weekly day only the weekly summary goes out, never both. Runs per landlord
|
||||||
|
* from the scheduler; the sent dates on the landlord make every summary go out at most once a day.
|
||||||
|
*/
|
||||||
|
class SendDigests
|
||||||
|
{
|
||||||
|
public function __construct(private DigestReport $report) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return 'daily'|'weekly'|null which summary was due (also when it was skipped for being empty)
|
||||||
|
*/
|
||||||
|
public function handle(Tenant $tenant): ?string
|
||||||
|
{
|
||||||
|
$now = CarbonImmutable::now();
|
||||||
|
$today = $now->startOfDay();
|
||||||
|
if ($now->hour < $tenant->digest_hour) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$weekly = $tenant->digest_weekly && $today->isoWeekday() === $tenant->digest_weekday && ! $tenant->digest_weekly_sent_on?->isSameDay($today);
|
||||||
|
$daily = $tenant->digest_daily && ! $tenant->digest_daily_sent_on?->isSameDay($today);
|
||||||
|
if (! $weekly && ! $daily) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->send($tenant, $weekly);
|
||||||
|
$tenant->forceFill([
|
||||||
|
'digest_daily_sent_on' => $today->toDateString(),
|
||||||
|
...($weekly ? ['digest_weekly_sent_on' => $today->toDateString()] : []),
|
||||||
|
])->save();
|
||||||
|
|
||||||
|
return $weekly ? 'weekly' : 'daily';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds and mails one summary. Without anything to report it is skipped unless the landlord wants it
|
||||||
|
* anyway or $force is set (button „Zusammenfassung jetzt senden“).
|
||||||
|
*
|
||||||
|
* @return bool whether a mail was sent
|
||||||
|
*/
|
||||||
|
public function send(Tenant $tenant, bool $weekly, bool $force = false): bool
|
||||||
|
{
|
||||||
|
$since = CarbonImmutable::now()->sub($weekly ? '7 days' : '1 day');
|
||||||
|
$sections = $this->report->build(DigestSection::chosen($tenant->digest_sections), $weekly, $since);
|
||||||
|
|
||||||
|
if ($sections === [] && ! $tenant->digest_when_empty && ! $force) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Mail::to(Settings::notificationRecipients())->send(new Digest($weekly, $sections));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,17 +6,14 @@
|
|||||||
use App\Channels\ConflictDetector;
|
use App\Channels\ConflictDetector;
|
||||||
use App\Channels\ExternalPeriod;
|
use App\Channels\ExternalPeriod;
|
||||||
use App\Enums\ChannelEchoBehavior;
|
use App\Enums\ChannelEchoBehavior;
|
||||||
use App\Mail\ChannelConflict;
|
|
||||||
use App\Models\BlockedPeriod;
|
use App\Models\BlockedPeriod;
|
||||||
use App\Models\Booking;
|
use App\Models\Booking;
|
||||||
use App\Models\Channel;
|
use App\Models\Channel;
|
||||||
use App\Models\ChannelSyncLog;
|
use App\Models\ChannelSyncLog;
|
||||||
use App\Models\Property;
|
use App\Models\Property;
|
||||||
use App\Support\Settings;
|
|
||||||
use Carbon\CarbonImmutable;
|
use Carbon\CarbonImmutable;
|
||||||
use Illuminate\Support\Facades\Cache;
|
use Illuminate\Support\Facades\Cache;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Facades\Mail;
|
|
||||||
|
|
||||||
/** Imports one complete channel snapshot without guessing that overlapping events are identical. */
|
/** Imports one complete channel snapshot without guessing that overlapping events are identical. */
|
||||||
class SyncChannel
|
class SyncChannel
|
||||||
@@ -129,18 +126,18 @@ public function handle(Channel $channel): ChannelSyncLog
|
|||||||
}
|
}
|
||||||
$warnings[] = $note;
|
$warnings[] = $note;
|
||||||
}
|
}
|
||||||
array_push($conflicts, ...$foundConflicts);
|
foreach ($foundConflicts as $conflict) {
|
||||||
|
$conflicts[$conflict] ??= $block->starts_on;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$warnings = array_values(array_unique($warnings));
|
$warnings = array_values(array_unique($warnings));
|
||||||
$locked->forceFill(['last_synced_at' => now(), 'last_success_at' => now(), 'last_error' => null,
|
$locked->forceFill(['last_synced_at' => now(), 'last_success_at' => now(), 'last_error' => null,
|
||||||
'alerted_at' => null, 'last_import_events' => count($periods), 'sync_warnings' => $warnings])->save();
|
'alerted_at' => null, 'last_import_events' => count($periods), 'sync_warnings' => $warnings])->save();
|
||||||
});
|
});
|
||||||
if ($conflicts !== []) {
|
app(ReportChannelConflicts::class)->handle($channel, $conflicts);
|
||||||
rescue(fn () => Mail::to(Settings::notificationRecipients())->send(new ChannelConflict($channel, array_values(array_unique($conflicts)))));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $channel->syncLogs()->create(['successful' => true, 'events' => count($periods), ...$counts,
|
return $channel->syncLogs()->create(['successful' => true, 'events' => count($periods), ...$counts,
|
||||||
'conflicts' => count(array_unique($conflicts)), 'warnings' => $warnings,
|
'conflicts' => count($conflicts), 'warnings' => $warnings,
|
||||||
'duration_ms' => (int) round((microtime(true) - $startedAt) * 1000)]);
|
'duration_ms' => (int) round((microtime(true) - $startedAt) * 1000)]);
|
||||||
} catch (ChannelSyncException $exception) {
|
} catch (ChannelSyncException $exception) {
|
||||||
$channel->forceFill(['last_synced_at' => now(), 'last_error_at' => now(), 'last_error' => $exception->getMessage()])->save();
|
$channel->forceFill(['last_synced_at' => now(), 'last_error_at' => now(), 'last_error' => $exception->getMessage()])->save();
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ enum AdminMode: string implements HasDescription, HasLabel
|
|||||||
*/
|
*/
|
||||||
public const SIMPLE_NAVIGATION = [
|
public const SIMPLE_NAVIGATION = [
|
||||||
OccupancyCalendar::class,
|
OccupancyCalendar::class,
|
||||||
|
InboxMessageResource::class,
|
||||||
BookingResource::class,
|
BookingResource::class,
|
||||||
PortalOccupationResource::class,
|
PortalOccupationResource::class,
|
||||||
BlockedPeriodResource::class,
|
BlockedPeriodResource::class,
|
||||||
@@ -52,7 +53,7 @@ public function getLabel(): string
|
|||||||
public function getDescription(): string
|
public function getDescription(): string
|
||||||
{
|
{
|
||||||
return match ($this) {
|
return match ($this) {
|
||||||
self::Simple => 'Das Tägliche: Anfragen, Buchungen und Verträge, Sperrzeiten, Preise & Angebote, Gäste, Kalenderabgleich (iCal), Portal-Aufgaben, Bewertungen, Fotos',
|
self::Simple => 'Das Tägliche: Postfach, Anfragen, Buchungen und Verträge, Sperrzeiten, Preise & Angebote, Gäste, Kalenderabgleich (iCal), Portal-Aufgaben, Bewertungen, Fotos',
|
||||||
self::Expert => 'Alle Einstellungen: Preise, Angebote, Kalenderabgleich (iCal), Webseite, System',
|
self::Expert => 'Alle Einstellungen: Preise, Angebote, Kalenderabgleich (iCal), Webseite, System',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Enums;
|
||||||
|
|
||||||
|
use Filament\Support\Contracts\HasDescription;
|
||||||
|
use Filament\Support\Contracts\HasLabel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The parts of the daily/weekly summary a landlord can choose (System › Betrieb › Benachrichtigungen).
|
||||||
|
*/
|
||||||
|
enum DigestSection: string implements HasDescription, HasLabel
|
||||||
|
{
|
||||||
|
case Inbox = 'inbox';
|
||||||
|
case Requests = 'requests';
|
||||||
|
case News = 'news';
|
||||||
|
case Stays = 'stays';
|
||||||
|
case Payments = 'payments';
|
||||||
|
case Portals = 'portals';
|
||||||
|
case Reviews = 'reviews';
|
||||||
|
|
||||||
|
public function getLabel(): string
|
||||||
|
{
|
||||||
|
return match ($this) {
|
||||||
|
self::Inbox => 'Postfach',
|
||||||
|
self::Requests => 'Offene Anfragen und Angebote',
|
||||||
|
self::News => 'Neu seit der letzten Übersicht',
|
||||||
|
self::Stays => 'An- und Abreisen',
|
||||||
|
self::Payments => 'Überfällige Zahlungen',
|
||||||
|
self::Portals => 'Portale: Aufgaben und Klärungsfälle',
|
||||||
|
self::Reviews => 'Bewertungen zur Freigabe',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDescription(): string
|
||||||
|
{
|
||||||
|
return match ($this) {
|
||||||
|
self::Inbox => 'Ungelesene Meldungen, z. B. mögliche Doppelbuchungen',
|
||||||
|
self::Requests => 'Anfragen und Angebote, die auf Sie oder den Gast warten, mit Frist',
|
||||||
|
self::News => 'Neue Anfragen, Buchungen, Stornierungen und Portalbuchungen',
|
||||||
|
self::Stays => 'Heute und morgen, in der Wochenübersicht die nächsten 7 Tage',
|
||||||
|
self::Payments => 'Anzahlungen und Restzahlungen nach Fälligkeit',
|
||||||
|
self::Portals => 'Offene Portal-Aufgaben, zu prüfende Portal-Mails und Kalendereinträge, Abgleichsfehler',
|
||||||
|
self::Reviews => 'Neue Bewertungen, die noch nicht freigegeben sind',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param list<string>|null $values stored choice; null = everything
|
||||||
|
* @return list<self>
|
||||||
|
*/
|
||||||
|
public static function chosen(?array $values): array
|
||||||
|
{
|
||||||
|
return $values === null ? self::cases() : array_values(array_filter(self::cases(), fn (self $section): bool => in_array($section->value, $values, true)));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Enums;
|
||||||
|
|
||||||
|
use Filament\Support\Contracts\HasColor;
|
||||||
|
use Filament\Support\Contracts\HasLabel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* What an inbox message is about.
|
||||||
|
*/
|
||||||
|
enum InboxMessageKind: string implements HasColor, HasLabel
|
||||||
|
{
|
||||||
|
case ChannelConflict = 'channel_conflict';
|
||||||
|
|
||||||
|
public function getLabel(): string
|
||||||
|
{
|
||||||
|
return match ($this) {
|
||||||
|
self::ChannelConflict => 'Mögliche Doppelbuchung',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getColor(): string
|
||||||
|
{
|
||||||
|
return match ($this) {
|
||||||
|
self::ChannelConflict => 'danger',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace App\Filament\Pages;
|
namespace App\Filament\Pages;
|
||||||
|
|
||||||
|
use App\Actions\SendDigests;
|
||||||
|
use App\Enums\DigestSection;
|
||||||
use App\Enums\TenantServiceKey;
|
use App\Enums\TenantServiceKey;
|
||||||
use App\Enums\UserRole;
|
use App\Enums\UserRole;
|
||||||
use App\Filament\Concerns\FollowsAdminMode;
|
use App\Filament\Concerns\FollowsAdminMode;
|
||||||
@@ -11,10 +13,12 @@
|
|||||||
use App\Tenancy\TenantFeatures;
|
use App\Tenancy\TenantFeatures;
|
||||||
use BackedEnum;
|
use BackedEnum;
|
||||||
use Filament\Actions\Action;
|
use Filament\Actions\Action;
|
||||||
|
use Filament\Forms\Components\CheckboxList;
|
||||||
use Filament\Forms\Components\Radio;
|
use Filament\Forms\Components\Radio;
|
||||||
use Filament\Forms\Components\Select;
|
use Filament\Forms\Components\Select;
|
||||||
use Filament\Forms\Components\TagsInput;
|
use Filament\Forms\Components\TagsInput;
|
||||||
use Filament\Forms\Components\TextInput;
|
use Filament\Forms\Components\TextInput;
|
||||||
|
use Filament\Forms\Components\Toggle;
|
||||||
use Filament\Notifications\Notification;
|
use Filament\Notifications\Notification;
|
||||||
use Filament\Pages\Page;
|
use Filament\Pages\Page;
|
||||||
use Filament\Schemas\Components\Actions;
|
use Filament\Schemas\Components\Actions;
|
||||||
@@ -30,7 +34,7 @@
|
|||||||
/**
|
/**
|
||||||
* Operating data of the landlord: operating mode (test mode sends every e-mail to one test recipient only;
|
* Operating data of the landlord: operating mode (test mode sends every e-mail to one test recipient only;
|
||||||
* live delivers to the real recipients), the addresses of the internal communication, the landlord's own
|
* live delivers to the real recipients), the addresses of the internal communication, the landlord's own
|
||||||
* address and bank details, and the periods. Administrators only.
|
* address and bank details, reminders and summaries, and the periods. Administrators only.
|
||||||
*/
|
*/
|
||||||
class Operations extends Page
|
class Operations extends Page
|
||||||
{
|
{
|
||||||
@@ -53,6 +57,11 @@ class Operations extends Page
|
|||||||
'channel_task_reminder_after_minutes' => 'Erinnerung an Portal-Aufgaben nach (Minuten)',
|
'channel_task_reminder_after_minutes' => 'Erinnerung an Portal-Aufgaben nach (Minuten)',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/** Choices for repeating open findings (days => label). */
|
||||||
|
public const REMINDER_INTERVALS = [0 => 'Nur einmal', 1 => 'Täglich', 2 => 'Alle 2 Tage', 3 => 'Alle 3 Tage', 7 => 'Wöchentlich'];
|
||||||
|
|
||||||
|
public const WEEKDAYS = [1 => 'Montag', 2 => 'Dienstag', 3 => 'Mittwoch', 4 => 'Donnerstag', 5 => 'Freitag', 6 => 'Samstag', 7 => 'Sonntag'];
|
||||||
|
|
||||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedPower;
|
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedPower;
|
||||||
|
|
||||||
protected static string|UnitEnum|null $navigationGroup = 'System';
|
protected static string|UnitEnum|null $navigationGroup = 'System';
|
||||||
@@ -99,6 +108,13 @@ public function mount(): void
|
|||||||
'mailbox_password' => $tenant->mailbox_password,
|
'mailbox_password' => $tenant->mailbox_password,
|
||||||
'mailbox_encryption' => $tenant->mailbox_encryption,
|
'mailbox_encryption' => $tenant->mailbox_encryption,
|
||||||
'mailbox_folder' => $tenant->mailbox_folder,
|
'mailbox_folder' => $tenant->mailbox_folder,
|
||||||
|
'reminder_interval_days' => $tenant->reminder_interval_days,
|
||||||
|
'digest_daily' => $tenant->digest_daily,
|
||||||
|
'digest_weekly' => $tenant->digest_weekly,
|
||||||
|
'digest_weekday' => $tenant->digest_weekday,
|
||||||
|
'digest_hour' => $tenant->digest_hour,
|
||||||
|
'digest_sections' => array_map(fn (DigestSection $section): string => $section->value, DigestSection::chosen($tenant->digest_sections)),
|
||||||
|
'digest_when_empty' => $tenant->digest_when_empty,
|
||||||
...$this->periodValues($tenant),
|
...$this->periodValues($tenant),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
@@ -181,6 +197,43 @@ public function form(Schema $schema): Schema
|
|||||||
->maxLength(255)
|
->maxLength(255)
|
||||||
->columnSpanFull(),
|
->columnSpanFull(),
|
||||||
]),
|
]),
|
||||||
|
Section::make('Benachrichtigungen')
|
||||||
|
->description('Wie oft offene Meldungen wiederholt werden und welche Zusammenfassungen Sie per E-Mail erhalten. Empfänger sind die Adressen unter „Benachrichtigungen an“.')
|
||||||
|
->columns(2)
|
||||||
|
->schema([
|
||||||
|
Select::make('reminder_interval_days')
|
||||||
|
->label('Offene Meldungen erneut senden')
|
||||||
|
->helperText('Gilt für mögliche Doppelbuchungen (solange sie im Postfach ungelesen sind und weiter bestehen) und offene Portal-Aufgaben.')
|
||||||
|
->options(self::REMINDER_INTERVALS)
|
||||||
|
->selectablePlaceholder(false)
|
||||||
|
->required()
|
||||||
|
->columnSpanFull(),
|
||||||
|
Toggle::make('digest_daily')->label('Tägliche Zusammenfassung'),
|
||||||
|
Toggle::make('digest_weekly')->label('Wöchentliche Zusammenfassung')->live(),
|
||||||
|
Select::make('digest_hour')
|
||||||
|
->label('Versand ab')
|
||||||
|
->options(collect(range(5, 21))->mapWithKeys(fn (int $hour): array => [$hour => sprintf('%02d:00 Uhr', $hour)])->all())
|
||||||
|
->selectablePlaceholder(false)
|
||||||
|
->required(),
|
||||||
|
Select::make('digest_weekday')
|
||||||
|
->label('Wochentag der Wochenübersicht')
|
||||||
|
->helperText('An diesem Tag kommt nur die Wochenübersicht, nicht zusätzlich die tägliche.')
|
||||||
|
->options(self::WEEKDAYS)
|
||||||
|
->selectablePlaceholder(false)
|
||||||
|
->visible(fn (Get $get): bool => (bool) $get('digest_weekly'))
|
||||||
|
->required(),
|
||||||
|
CheckboxList::make('digest_sections')
|
||||||
|
->label('Inhalt der Zusammenfassung')
|
||||||
|
->options(DigestSection::class)
|
||||||
|
->descriptions(collect(DigestSection::cases())->mapWithKeys(fn (DigestSection $section): array => [$section->value => $section->getDescription()])->all())
|
||||||
|
->columns(2)
|
||||||
|
->required()
|
||||||
|
->columnSpanFull(),
|
||||||
|
Toggle::make('digest_when_empty')
|
||||||
|
->label('Auch senden, wenn nichts ansteht')
|
||||||
|
->helperText('Sonst entfällt die Zusammenfassung an Tagen ohne offene Punkte.')
|
||||||
|
->columnSpanFull(),
|
||||||
|
]),
|
||||||
Section::make('Portal-Postfach')
|
Section::make('Portal-Postfach')
|
||||||
->description('Aus diesem Postfach werden die Buchungsmails der Portale gelesen, damit ein Termin sofort gesperrt wird. Leerer Server = ausgeschaltet. Das Passwort liegt verschlüsselt in der Datenbank.')
|
->description('Aus diesem Postfach werden die Buchungsmails der Portale gelesen, damit ein Termin sofort gesperrt wird. Leerer Server = ausgeschaltet. Das Passwort liegt verschlüsselt in der Datenbank.')
|
||||||
->columns(2)
|
->columns(2)
|
||||||
@@ -215,6 +268,29 @@ public function content(Schema $schema): Schema
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getHeaderActions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
Action::make('sendDigest')
|
||||||
|
->label('Zusammenfassung jetzt senden')
|
||||||
|
->icon(Heroicon::OutlinedPaperAirplane)
|
||||||
|
->color('gray')
|
||||||
|
->modalDescription('Schickt die Zusammenfassung mit den gespeicherten Einstellungen sofort an die Benachrichtigungsadressen – auch wenn nichts ansteht. Der reguläre Versand bleibt unverändert.')
|
||||||
|
->schema([
|
||||||
|
Radio::make('weekly')
|
||||||
|
->label('Welche?')
|
||||||
|
->options([0 => 'Tagesübersicht', 1 => 'Wochenübersicht'])
|
||||||
|
->default(0)
|
||||||
|
->required(),
|
||||||
|
])
|
||||||
|
->action(function (array $data): void {
|
||||||
|
app(SendDigests::class)->send($this->tenant(), (bool) $data['weekly'], force: true);
|
||||||
|
|
||||||
|
Notification::make()->title('Zusammenfassung gesendet')->body(Settings::isLive() ? null : 'Testbetrieb: Sie geht an die Testadresse.')->success()->send();
|
||||||
|
}),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
public function save(): void
|
public function save(): void
|
||||||
{
|
{
|
||||||
$data = $this->form->getState();
|
$data = $this->form->getState();
|
||||||
@@ -243,6 +319,13 @@ public function save(): void
|
|||||||
'mailbox_password' => $data['mailbox_password'] ?? null,
|
'mailbox_password' => $data['mailbox_password'] ?? null,
|
||||||
'mailbox_encryption' => $data['mailbox_encryption'] ?? null,
|
'mailbox_encryption' => $data['mailbox_encryption'] ?? null,
|
||||||
'mailbox_folder' => $data['mailbox_folder'] ?? null,
|
'mailbox_folder' => $data['mailbox_folder'] ?? null,
|
||||||
|
'reminder_interval_days' => (int) $data['reminder_interval_days'],
|
||||||
|
'digest_daily' => (bool) $data['digest_daily'],
|
||||||
|
'digest_weekly' => (bool) $data['digest_weekly'],
|
||||||
|
'digest_weekday' => (int) ($data['digest_weekday'] ?? $tenant->digest_weekday),
|
||||||
|
'digest_hour' => (int) $data['digest_hour'],
|
||||||
|
'digest_sections' => count($data['digest_sections']) === count(DigestSection::cases()) ? null : array_values($data['digest_sections']),
|
||||||
|
'digest_when_empty' => (bool) $data['digest_when_empty'],
|
||||||
...array_map(fn (mixed $value): ?int => filled($value) ? (int) $value : null, $this->periodInput($data)),
|
...array_map(fn (mixed $value): ?int => filled($value) ? (int) $value : null, $this->periodInput($data)),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,69 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\InboxMessages;
|
||||||
|
|
||||||
|
use App\Filament\Concerns\FollowsAdminMode;
|
||||||
|
use App\Filament\Resources\InboxMessages\Pages\ListInboxMessages;
|
||||||
|
use App\Filament\Resources\InboxMessages\Tables\InboxMessagesTable;
|
||||||
|
use App\Models\InboxMessage;
|
||||||
|
use BackedEnum;
|
||||||
|
use Filament\Resources\Resource;
|
||||||
|
use Filament\Support\Icons\Heroicon;
|
||||||
|
use Filament\Tables\Table;
|
||||||
|
use UnitEnum;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The admin inbox ("Postfach"): findings the landlord has to look at, each posted once (App\Support\Inbox).
|
||||||
|
*/
|
||||||
|
class InboxMessageResource extends Resource
|
||||||
|
{
|
||||||
|
use FollowsAdminMode;
|
||||||
|
|
||||||
|
protected static ?string $model = InboxMessage::class;
|
||||||
|
|
||||||
|
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedInbox;
|
||||||
|
|
||||||
|
protected static string|UnitEnum|null $navigationGroup = 'Vermietung';
|
||||||
|
|
||||||
|
protected static ?string $navigationLabel = 'Postfach';
|
||||||
|
|
||||||
|
protected static ?string $modelLabel = 'Meldung';
|
||||||
|
|
||||||
|
protected static ?string $pluralModelLabel = 'Postfach';
|
||||||
|
|
||||||
|
protected static ?int $navigationSort = 0;
|
||||||
|
|
||||||
|
public static function table(Table $table): Table
|
||||||
|
{
|
||||||
|
return InboxMessagesTable::configure($table);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function canCreate(): bool
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getNavigationBadge(): ?string
|
||||||
|
{
|
||||||
|
$unread = InboxMessage::query()->unread()->count();
|
||||||
|
|
||||||
|
return $unread > 0 ? (string) $unread : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getNavigationBadgeColor(): string
|
||||||
|
{
|
||||||
|
return 'danger';
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getNavigationBadgeTooltip(): ?string
|
||||||
|
{
|
||||||
|
return 'Ungelesen';
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getPages(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'index' => ListInboxMessages::route('/'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\InboxMessages\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Concerns\ListsCurrentProperty;
|
||||||
|
use App\Filament\Resources\InboxMessages\InboxMessageResource;
|
||||||
|
use App\Models\Property;
|
||||||
|
use Filament\Actions\Action;
|
||||||
|
use Filament\Resources\Pages\ListRecords;
|
||||||
|
use Filament\Support\Icons\Heroicon;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
|
||||||
|
class ListInboxMessages extends ListRecords
|
||||||
|
{
|
||||||
|
use ListsCurrentProperty;
|
||||||
|
|
||||||
|
protected static string $resource = InboxMessageResource::class;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Messages of the chosen apartment and those that concern no apartment in particular.
|
||||||
|
*/
|
||||||
|
protected function scopeToProperty(Builder $query, Property $property): Builder
|
||||||
|
{
|
||||||
|
return $query->where(fn (Builder $query) => $query->where('property_id', $property->id)->orWhereNull('property_id'));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getHeaderActions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
Action::make('readAll')
|
||||||
|
->label('Alle als gelesen markieren')
|
||||||
|
->icon(Heroicon::OutlinedCheck)
|
||||||
|
->color('gray')
|
||||||
|
->visible(fn (): bool => $this->getTableQuery()->unread()->exists())
|
||||||
|
->action(fn () => $this->getTableQuery()->unread()->update(['read_at' => now()])),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\InboxMessages\Tables;
|
||||||
|
|
||||||
|
use App\Enums\InboxMessageKind;
|
||||||
|
use App\Models\InboxMessage;
|
||||||
|
use Filament\Actions\Action;
|
||||||
|
use Filament\Actions\BulkAction;
|
||||||
|
use Filament\Actions\BulkActionGroup;
|
||||||
|
use Filament\Actions\DeleteBulkAction;
|
||||||
|
use Filament\Support\Enums\FontWeight;
|
||||||
|
use Filament\Support\Icons\Heroicon;
|
||||||
|
use Filament\Tables\Columns\IconColumn;
|
||||||
|
use Filament\Tables\Columns\TextColumn;
|
||||||
|
use Filament\Tables\Filters\SelectFilter;
|
||||||
|
use Filament\Tables\Filters\TernaryFilter;
|
||||||
|
use Filament\Tables\Table;
|
||||||
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
|
|
||||||
|
class InboxMessagesTable
|
||||||
|
{
|
||||||
|
public static function configure(Table $table): Table
|
||||||
|
{
|
||||||
|
return $table
|
||||||
|
->defaultSort('created_at', 'desc')
|
||||||
|
->description('Hinweise, um die Sie sich kümmern sollten. Jede Meldung kommt nur einmal – auch wenn sie bei jedem Kalenderabgleich wieder auffällt.')
|
||||||
|
->emptyStateHeading('Keine Meldungen')
|
||||||
|
->columns([
|
||||||
|
IconColumn::make('read_at')
|
||||||
|
->label('')
|
||||||
|
->state(fn (InboxMessage $record): bool => ! $record->isRead())
|
||||||
|
->boolean()
|
||||||
|
->trueIcon(Heroicon::Envelope)
|
||||||
|
->falseIcon(Heroicon::OutlinedEnvelopeOpen)
|
||||||
|
->trueColor('danger')
|
||||||
|
->falseColor('gray')
|
||||||
|
->tooltip(fn (InboxMessage $record): string => $record->isRead() ? 'Gelesen' : 'Ungelesen'),
|
||||||
|
TextColumn::make('created_at')->label('Eingang')->dateTime('d.m. H:i')->sortable(),
|
||||||
|
TextColumn::make('kind')->label('Art')->badge(),
|
||||||
|
TextColumn::make('subject')
|
||||||
|
->label('Meldung')
|
||||||
|
->weight(fn (InboxMessage $record): ?FontWeight => $record->isRead() ? null : FontWeight::Bold)
|
||||||
|
->description(fn (InboxMessage $record): string => $record->body)
|
||||||
|
->wrap(),
|
||||||
|
])
|
||||||
|
->filters([
|
||||||
|
TernaryFilter::make('read_at')
|
||||||
|
->label('Gelesen')
|
||||||
|
->nullable()
|
||||||
|
->trueLabel('Nur gelesene')
|
||||||
|
->falseLabel('Nur ungelesene'),
|
||||||
|
SelectFilter::make('kind')->label('Art')->options(InboxMessageKind::class),
|
||||||
|
])
|
||||||
|
->recordUrl(null)
|
||||||
|
->recordActions([
|
||||||
|
Action::make('open')
|
||||||
|
->label('Ansehen')
|
||||||
|
->icon(Heroicon::OutlinedArrowTopRightOnSquare)
|
||||||
|
->visible(fn (InboxMessage $record): bool => filled($record->action_url))
|
||||||
|
->action(function (InboxMessage $record) {
|
||||||
|
$record->update(['read_at' => $record->read_at ?? now()]);
|
||||||
|
|
||||||
|
return redirect($record->action_url);
|
||||||
|
}),
|
||||||
|
Action::make('toggleRead')
|
||||||
|
->label(fn (InboxMessage $record): string => $record->isRead() ? 'Als ungelesen markieren' : 'Als gelesen markieren')
|
||||||
|
->icon(fn (InboxMessage $record): Heroicon => $record->isRead() ? Heroicon::OutlinedEnvelope : Heroicon::OutlinedCheck)
|
||||||
|
->color('gray')
|
||||||
|
->action(fn (InboxMessage $record) => $record->update(['read_at' => $record->isRead() ? null : now()])),
|
||||||
|
])
|
||||||
|
->toolbarActions([
|
||||||
|
BulkActionGroup::make([
|
||||||
|
BulkAction::make('markRead')
|
||||||
|
->label('Als gelesen markieren')
|
||||||
|
->icon(Heroicon::OutlinedCheck)
|
||||||
|
->action(fn (Collection $records) => InboxMessage::query()->whereKey($records->modelKeys())->update(['read_at' => now()]))
|
||||||
|
->deselectRecordsAfterCompletion(),
|
||||||
|
DeleteBulkAction::make(),
|
||||||
|
]),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,19 +10,23 @@
|
|||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reports overlaps between a newly imported portal occupation and occupations from elsewhere.
|
* Reports overlaps between an imported portal occupation and occupations from elsewhere: new ones and
|
||||||
|
* reminders about ones that are still open.
|
||||||
*/
|
*/
|
||||||
class ChannelConflict extends Mailable
|
class ChannelConflict extends Mailable
|
||||||
{
|
{
|
||||||
use Queueable, SerializesModels;
|
use Queueable, SerializesModels;
|
||||||
|
|
||||||
/** @param list<string> $conflicts */
|
/**
|
||||||
public function __construct(public Channel $channel, public array $conflicts) {}
|
* @param list<string> $conflicts reported for the first time
|
||||||
|
* @param list<string> $reminders reported before, still unread and still detected
|
||||||
|
*/
|
||||||
|
public function __construct(public Channel $channel, public array $conflicts, public array $reminders = []) {}
|
||||||
|
|
||||||
public function envelope(): Envelope
|
public function envelope(): Envelope
|
||||||
{
|
{
|
||||||
return new Envelope(
|
return new Envelope(
|
||||||
subject: 'Achtung: mögliche Doppelbuchung über '.$this->channel->name,
|
subject: ($this->conflicts === [] ? 'Erinnerung' : 'Achtung').': mögliche Doppelbuchung über '.$this->channel->name,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Mail;
|
||||||
|
|
||||||
|
use App\Enums\DigestSection;
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Mail\Mailable;
|
||||||
|
use Illuminate\Mail\Mailables\Content;
|
||||||
|
use Illuminate\Mail\Mailables\Envelope;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The landlord's daily or weekly summary of open points and news (SendDigests, DigestReport).
|
||||||
|
*/
|
||||||
|
class Digest extends Mailable
|
||||||
|
{
|
||||||
|
use Queueable, SerializesModels;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param list<array{section: DigestSection, title: string, items: list<string>, more: int, url: string, link: string}> $sections
|
||||||
|
*/
|
||||||
|
public function __construct(public bool $weekly, public array $sections) {}
|
||||||
|
|
||||||
|
public function envelope(): Envelope
|
||||||
|
{
|
||||||
|
$title = $this->weekly ? 'Wochenübersicht KW '.now()->isoWeek() : 'Tagesübersicht '.now()->format('d.m.Y');
|
||||||
|
$count = array_sum(array_map(fn (array $section): int => count($section['items']) + $section['more'], $this->sections));
|
||||||
|
|
||||||
|
return new Envelope(
|
||||||
|
subject: $title.($count === 0 ? ': nichts Neues' : ": {$count} ".($count === 1 ? 'Punkt' : 'Punkte')),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function content(): Content
|
||||||
|
{
|
||||||
|
return new Content(
|
||||||
|
markdown: 'mail.digest',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Enums\InboxMessageKind;
|
||||||
|
use App\Models\Concerns\BelongsToTenant;
|
||||||
|
use Database\Factories\InboxMessageFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||||
|
use Illuminate\Database\Eloquent\Attributes\Scope;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A message in the admin inbox ("Postfach"). The fingerprint identifies the finding, so the same
|
||||||
|
* finding is posted – and e-mailed – only once per landlord (App\Support\Inbox).
|
||||||
|
*/
|
||||||
|
#[Fillable(['property_id', 'channel_id', 'kind', 'fingerprint', 'subject', 'body', 'action_url', 'notified_at', 'last_seen_at', 'read_at'])]
|
||||||
|
class InboxMessage extends Model
|
||||||
|
{
|
||||||
|
/** @use HasFactory<InboxMessageFactory> */
|
||||||
|
use BelongsToTenant, HasFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the attributes that should be cast.
|
||||||
|
*
|
||||||
|
* @return array<string, string>
|
||||||
|
*/
|
||||||
|
protected function casts(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'kind' => InboxMessageKind::class,
|
||||||
|
'notified_at' => 'immutable_datetime',
|
||||||
|
'last_seen_at' => 'immutable_datetime',
|
||||||
|
'read_at' => 'immutable_datetime',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return BelongsTo<Property, $this>
|
||||||
|
*/
|
||||||
|
public function property(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Property::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return BelongsTo<Channel, $this>
|
||||||
|
*/
|
||||||
|
public function channel(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Channel::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isRead(): bool
|
||||||
|
{
|
||||||
|
return $this->read_at !== null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Builder<InboxMessage> $query
|
||||||
|
* @return Builder<InboxMessage>
|
||||||
|
*/
|
||||||
|
#[Scope]
|
||||||
|
protected function unread(Builder $query): Builder
|
||||||
|
{
|
||||||
|
return $query->whereNull('read_at');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -26,12 +26,24 @@
|
|||||||
'retention_portal_email_excerpt_days', 'retention_attribution_months',
|
'retention_portal_email_excerpt_days', 'retention_attribution_months',
|
||||||
'spam_min_seconds', 'spam_per_ip_per_hour', 'spam_per_email_per_day', 'spam_open_requests_per_email', 'spam_max_links',
|
'spam_min_seconds', 'spam_per_ip_per_hour', 'spam_per_email_per_day', 'spam_open_requests_per_email', 'spam_max_links',
|
||||||
'channel_stale_after_minutes', 'channel_task_reminder_after_minutes',
|
'channel_stale_after_minutes', 'channel_task_reminder_after_minutes',
|
||||||
|
'reminder_interval_days', 'digest_daily', 'digest_weekly', 'digest_weekday', 'digest_hour', 'digest_sections',
|
||||||
|
'digest_when_empty', 'digest_daily_sent_on', 'digest_weekly_sent_on',
|
||||||
])]
|
])]
|
||||||
class Tenant extends Model
|
class Tenant extends Model
|
||||||
{
|
{
|
||||||
/** @use HasFactory<TenantFactory> */
|
/** @use HasFactory<TenantFactory> */
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
|
|
||||||
|
/** Reminder and summary defaults: repeat nothing, a daily summary from 7 a.m., the weekly one on Mondays. */
|
||||||
|
protected $attributes = [
|
||||||
|
'reminder_interval_days' => 0,
|
||||||
|
'digest_daily' => true,
|
||||||
|
'digest_weekly' => false,
|
||||||
|
'digest_weekday' => 1,
|
||||||
|
'digest_hour' => 7,
|
||||||
|
'digest_when_empty' => false,
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The landlord the existing single-website data belongs to.
|
* The landlord the existing single-website data belongs to.
|
||||||
*/
|
*/
|
||||||
@@ -56,6 +68,15 @@ protected function casts(): array
|
|||||||
'bank_name' => 'encrypted',
|
'bank_name' => 'encrypted',
|
||||||
'tax_note' => 'encrypted',
|
'tax_note' => 'encrypted',
|
||||||
'mailbox_password' => 'encrypted',
|
'mailbox_password' => 'encrypted',
|
||||||
|
'reminder_interval_days' => 'integer',
|
||||||
|
'digest_daily' => 'boolean',
|
||||||
|
'digest_weekly' => 'boolean',
|
||||||
|
'digest_weekday' => 'integer',
|
||||||
|
'digest_hour' => 'integer',
|
||||||
|
'digest_sections' => 'array',
|
||||||
|
'digest_when_empty' => 'boolean',
|
||||||
|
'digest_daily_sent_on' => 'immutable_date',
|
||||||
|
'digest_weekly_sent_on' => 'immutable_date',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Policies;
|
||||||
|
|
||||||
|
use App\Enums\Permission;
|
||||||
|
|
||||||
|
class InboxMessagePolicy extends RolePolicy
|
||||||
|
{
|
||||||
|
protected function permission(): Permission
|
||||||
|
{
|
||||||
|
return Permission::Bookings;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,218 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Support;
|
||||||
|
|
||||||
|
use App\Enums\BookingStatus;
|
||||||
|
use App\Enums\DigestSection;
|
||||||
|
use App\Enums\PortalEmailStatus;
|
||||||
|
use App\Enums\ReviewStatus;
|
||||||
|
use App\Filament\Pages\OccupancyCalendar;
|
||||||
|
use App\Filament\Resources\Bookings\BookingResource;
|
||||||
|
use App\Filament\Resources\ChannelTasks\ChannelTaskResource;
|
||||||
|
use App\Filament\Resources\InboxMessages\InboxMessageResource;
|
||||||
|
use App\Filament\Resources\PortalOccupations\PortalOccupationResource;
|
||||||
|
use App\Filament\Resources\Reviews\ReviewResource;
|
||||||
|
use App\Models\BlockedPeriod;
|
||||||
|
use App\Models\Booking;
|
||||||
|
use App\Models\Channel;
|
||||||
|
use App\Models\ChannelTask;
|
||||||
|
use App\Models\InboxMessage;
|
||||||
|
use App\Models\PortalEmail;
|
||||||
|
use App\Models\Property;
|
||||||
|
use App\Models\Review;
|
||||||
|
use Carbon\CarbonImmutable;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Collects what the landlord should know for the daily or weekly summary (SendDigests). Each section lists
|
||||||
|
* at most MAX_ITEMS lines and says how many more there are; empty sections are left out. Lines are Markdown
|
||||||
|
* with HTML-escaped data, so the mail renders them unescaped.
|
||||||
|
*/
|
||||||
|
class DigestReport
|
||||||
|
{
|
||||||
|
public const MAX_ITEMS = 10;
|
||||||
|
|
||||||
|
private bool $namesProperty = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param list<DigestSection> $sections
|
||||||
|
* @return list<array{section: DigestSection, title: string, items: list<string>, more: int, url: string, link: string}>
|
||||||
|
*/
|
||||||
|
public function build(array $sections, bool $weekly, CarbonImmutable $since): array
|
||||||
|
{
|
||||||
|
$this->namesProperty = Property::query()->count() > 1;
|
||||||
|
$report = [];
|
||||||
|
|
||||||
|
foreach ($sections as $section) {
|
||||||
|
[$title, $lines, $url, $link] = match ($section) {
|
||||||
|
DigestSection::Inbox => ['Postfach: ungelesene Meldungen', $this->inbox(), InboxMessageResource::getUrl('index'), 'Postfach öffnen'],
|
||||||
|
DigestSection::Requests => ['Offene Anfragen und Angebote', $this->requests(), BookingResource::getUrl('index'), 'Buchungen öffnen'],
|
||||||
|
DigestSection::News => ['Neu seit '.$since->format('d.m. H:i').' Uhr', $this->news($since), BookingResource::getUrl('index'), 'Buchungen öffnen'],
|
||||||
|
DigestSection::Stays => [$weekly ? 'An- und Abreisen der nächsten 7 Tage' : 'An- und Abreisen heute und morgen', $this->stays($weekly ? 7 : 2), OccupancyCalendar::getUrl(), 'Belegungsplan öffnen'],
|
||||||
|
DigestSection::Payments => ['Überfällige Zahlungen', $this->payments(), BookingResource::getUrl('index'), 'Buchungen öffnen'],
|
||||||
|
DigestSection::Portals => ['Portale: Aufgaben und Klärungsfälle', $this->portals(), ChannelTaskResource::getUrl('index'), 'Portal-Aufgaben öffnen'],
|
||||||
|
DigestSection::Reviews => ['Bewertungen zur Freigabe', $this->reviews(), ReviewResource::getUrl('index'), 'Bewertungen öffnen'],
|
||||||
|
};
|
||||||
|
|
||||||
|
if ($lines->isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$report[] = [
|
||||||
|
'section' => $section,
|
||||||
|
'title' => $title,
|
||||||
|
'items' => $lines->take(self::MAX_ITEMS)->values()->all(),
|
||||||
|
'more' => max(0, $lines->count() - self::MAX_ITEMS),
|
||||||
|
'url' => $url,
|
||||||
|
'link' => $link,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $report;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Collection<int, string>
|
||||||
|
*/
|
||||||
|
private function inbox(): Collection
|
||||||
|
{
|
||||||
|
return InboxMessage::query()->unread()->latest()->get()
|
||||||
|
->map(fn (InboxMessage $message): string => $message->created_at->format('d.m.').' · '.e($message->subject).': '.e($message->body));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Collection<int, string>
|
||||||
|
*/
|
||||||
|
private function requests(): Collection
|
||||||
|
{
|
||||||
|
return Booking::query()->whereIn('status', BookingStatus::holding())->with(['guest', 'property'])->orderBy('hold_expires_at')->get()
|
||||||
|
->map(fn (Booking $booking): string => $this->booking($booking).' – '.$booking->status->getLabel().$this->deadline($booking));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Collection<int, string>
|
||||||
|
*/
|
||||||
|
private function news(CarbonImmutable $since): Collection
|
||||||
|
{
|
||||||
|
$created = Booking::query()->where('created_at', '>=', $since)->with(['guest', 'property'])->oldest()->get()
|
||||||
|
->map(fn (Booking $booking): string => 'Neu: '.$this->booking($booking).' – '.$booking->status->getLabel());
|
||||||
|
$cancelled = Booking::query()->where('status', BookingStatus::Cancelled)->where('created_at', '<', $since)->where('updated_at', '>=', $since)->with(['guest', 'property'])->get()
|
||||||
|
->map(fn (Booking $booking): string => 'Storniert: '.$this->booking($booking));
|
||||||
|
$portal = BlockedPeriod::query()->reservations()->occupying()->where('created_at', '>=', $since)->with(['channel', 'originChannel', 'guest'])->oldest()->get()
|
||||||
|
->map(fn (BlockedPeriod $block): string => 'Portalbuchung '.e($block->bookingChannelLabel()).': '.$this->period($block->starts_on, $block->ends_on).($block->guestName() ? ', '.e($block->guestName()) : ''));
|
||||||
|
|
||||||
|
return $created->concat($cancelled)->concat($portal)->values();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Arrivals and departures from today on, $days days long, sorted by day (departures first).
|
||||||
|
*
|
||||||
|
* @return Collection<int, string>
|
||||||
|
*/
|
||||||
|
private function stays(int $days): Collection
|
||||||
|
{
|
||||||
|
$from = CarbonImmutable::today();
|
||||||
|
$last = $from->addDays($days - 1);
|
||||||
|
$within = fn (string $start, string $end) => fn (Builder $query) => $query
|
||||||
|
->where(fn (Builder $query) => $query->whereDate($start, '>=', $from)->whereDate($start, '<=', $last))
|
||||||
|
->orWhere(fn (Builder $query) => $query->whereDate($end, '>=', $from)->whereDate($end, '<=', $last));
|
||||||
|
$events = [];
|
||||||
|
|
||||||
|
foreach (Booking::query()->whereIn('status', BookingStatus::occupying())->where($within('arrival', 'departure'))->with(['guest', 'property'])->get() as $booking) {
|
||||||
|
$this->stayEvents($events, $from, $last, $booking->arrival, $booking->departure, $this->booking($booking));
|
||||||
|
}
|
||||||
|
foreach (BlockedPeriod::query()->reservations()->occupying()->where($within('starts_on', 'ends_on'))->with(['channel', 'originChannel', 'guest'])->get() as $block) {
|
||||||
|
$this->stayEvents($events, $from, $last, $block->starts_on, $block->ends_on, e(trim($block->bookingChannelLabel().' '.($block->guestName() ?? ''))));
|
||||||
|
}
|
||||||
|
|
||||||
|
ksort($events);
|
||||||
|
|
||||||
|
return collect(array_values($events));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, string> $events
|
||||||
|
*/
|
||||||
|
private function stayEvents(array &$events, CarbonImmutable $from, CarbonImmutable $last, CarbonImmutable $arrival, CarbonImmutable $departure, string $label): void
|
||||||
|
{
|
||||||
|
if ($departure->betweenIncluded($from, $last)) {
|
||||||
|
$events[$departure->toDateString().'-0-'.count($events)] = $this->day($departure).': Abreise '.$label;
|
||||||
|
}
|
||||||
|
if ($arrival->betweenIncluded($from, $last)) {
|
||||||
|
$events[$arrival->toDateString().'-1-'.count($events)] = $this->day($arrival).': Anreise '.$label.' (bis '.$departure->format('d.m.').')';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Collection<int, string>
|
||||||
|
*/
|
||||||
|
private function payments(): Collection
|
||||||
|
{
|
||||||
|
return Booking::query()->whereIn('status', [BookingStatus::Confirmed, BookingStatus::DepositPaid])->with(['guest', 'property', 'payments'])->orderBy('arrival')->get()
|
||||||
|
->map(fn (Booking $booking): ?string => match (true) {
|
||||||
|
$booking->status === BookingStatus::Confirmed && $booking->deposit_due_on?->isPast() && $booking->openDeposit() > 0 => $this->booking($booking).' – Anzahlung '.Money::format($booking->openDeposit()).' seit '.$booking->deposit_due_on->format('d.m.').' fällig',
|
||||||
|
$booking->balance_due_on?->isPast() && $booking->openAmount() > 0 => $this->booking($booking).' – offen '.Money::format($booking->openAmount()).' seit '.$booking->balance_due_on->format('d.m.').' fällig',
|
||||||
|
default => null,
|
||||||
|
})
|
||||||
|
->filter()
|
||||||
|
->values();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Collection<int, string>
|
||||||
|
*/
|
||||||
|
private function portals(): Collection
|
||||||
|
{
|
||||||
|
$tasks = ChannelTask::query()->open()->with('channel')->oldest()->get()
|
||||||
|
->map(fn (ChannelTask $task): string => 'Aufgabe '.e($task->channel->name).': '.$task->action->getLabel().' '.$task->period());
|
||||||
|
$mails = PortalEmail::query()->where('status', PortalEmailStatus::NeedsReview)->with('channel')->latest('received_at')->get()
|
||||||
|
->map(fn (PortalEmail $mail): string => 'Portal-Mail prüfen ('.e($mail->channel->name).'): '.e($mail->subject));
|
||||||
|
$unclear = BlockedPeriod::query()->unclear()->whereDate('ends_on', '>', today())->with('channel')->orderBy('starts_on')->get()
|
||||||
|
->map(fn (BlockedPeriod $block): string => 'Kalendereintrag klären ('.e($block->channel->name ?? 'Portal').'): '.$this->period($block->starts_on, $block->ends_on)
|
||||||
|
.' · [ansehen]('.PortalOccupationResource::getUrl('view', ['record' => $block->id]).')');
|
||||||
|
$channels = Channel::query()->active()->get()->filter(fn (Channel $channel): bool => $channel->isStale() || filled($channel->last_error))
|
||||||
|
->map(fn (Channel $channel): string => 'Kalenderabgleich '.e($channel->name).': '.e($channel->last_error ?: 'seit längerem kein erfolgreicher Abruf'));
|
||||||
|
|
||||||
|
return $tasks->concat($mails)->concat($unclear)->concat($channels)->values();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Collection<int, string>
|
||||||
|
*/
|
||||||
|
private function reviews(): Collection
|
||||||
|
{
|
||||||
|
return Review::query()->where('status', ReviewStatus::Pending)->oldest()->get()
|
||||||
|
->map(fn (Review $review): string => $review->rating.'/5'.($review->title ? ' „'.e($review->title).'“' : '').($review->display_name ? ' von '.e($review->display_name) : ''));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function booking(Booking $booking): string
|
||||||
|
{
|
||||||
|
return '['.$booking->reference.']('.BookingResource::getUrl('view', ['record' => $booking]).') '
|
||||||
|
.e($booking->guest?->full_name ?? 'Gast').', '.$this->period($booking->arrival, $booking->departure)
|
||||||
|
.($this->namesProperty ? ' ('.e($booking->property->name).')' : '');
|
||||||
|
}
|
||||||
|
|
||||||
|
private function deadline(Booking $booking): string
|
||||||
|
{
|
||||||
|
if ($booking->hold_expires_at === null) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return ', Frist bis '.$booking->hold_expires_at->format('d.m. H:i').' Uhr'.($booking->hold_expires_at->isPast() ? ' (abgelaufen)' : '');
|
||||||
|
}
|
||||||
|
|
||||||
|
private function period(CarbonImmutable $from, CarbonImmutable $until): string
|
||||||
|
{
|
||||||
|
return $from->format('d.m.').'–'.$until->format('d.m.Y');
|
||||||
|
}
|
||||||
|
|
||||||
|
private function day(CarbonImmutable $date): string
|
||||||
|
{
|
||||||
|
return match (true) {
|
||||||
|
$date->isToday() => 'Heute',
|
||||||
|
$date->isTomorrow() => 'Morgen',
|
||||||
|
default => $date->locale('de')->isoFormat('dd DD.MM.'),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Support;
|
||||||
|
|
||||||
|
use App\Enums\InboxMessageKind;
|
||||||
|
use App\Models\Channel;
|
||||||
|
use App\Models\InboxMessage;
|
||||||
|
use Illuminate\Database\UniqueConstraintViolationException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Posts findings to the admin inbox ("Postfach"). Each finding has a fingerprint and arrives only once
|
||||||
|
* per landlord, so a check that runs every few minutes does not report a lasting problem again and again.
|
||||||
|
* While the finding is still detected and the message is unread, it is repeated after the landlord's
|
||||||
|
* reminder interval (Settings::reminderIntervalDays(), 0 = never).
|
||||||
|
*/
|
||||||
|
class Inbox
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return InboxMessage|null the message to e-mail now – new (wasRecentlyCreated) or due for a reminder – else null
|
||||||
|
*/
|
||||||
|
public function post(InboxMessageKind $kind, string $fingerprint, string $subject, string $body, ?Channel $channel = null, ?string $actionUrl = null): ?InboxMessage
|
||||||
|
{
|
||||||
|
$fingerprint = $kind->value.':'.$fingerprint;
|
||||||
|
|
||||||
|
$existing = InboxMessage::query()->where('fingerprint', $fingerprint)->first();
|
||||||
|
if ($existing) {
|
||||||
|
$due = $this->reminderDue($existing);
|
||||||
|
$existing->forceFill(['last_seen_at' => now(), ...($due ? ['notified_at' => now()] : [])])->save();
|
||||||
|
|
||||||
|
return $due ? $existing : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return InboxMessage::create([
|
||||||
|
'kind' => $kind,
|
||||||
|
'fingerprint' => $fingerprint,
|
||||||
|
'subject' => mb_substr($subject, 0, 255),
|
||||||
|
'body' => $body,
|
||||||
|
'channel_id' => $channel?->id,
|
||||||
|
'property_id' => $channel?->property_id,
|
||||||
|
'action_url' => $actionUrl,
|
||||||
|
'notified_at' => now(),
|
||||||
|
'last_seen_at' => now(),
|
||||||
|
]);
|
||||||
|
} catch (UniqueConstraintViolationException) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unread messages are repeated once the reminder interval has passed; reading one ends its reminders.
|
||||||
|
*/
|
||||||
|
public function reminderDue(InboxMessage $message): bool
|
||||||
|
{
|
||||||
|
$days = Settings::reminderIntervalDays($message->tenant);
|
||||||
|
|
||||||
|
return $days > 0
|
||||||
|
&& ! $message->isRead()
|
||||||
|
&& ($message->notified_at === null || $message->notified_at->lessThanOrEqualTo(now()->subDays($days)));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -80,6 +80,14 @@ public static function mailRedirectFor(?Tenant $tenant): ?string
|
|||||||
return $tenant?->test_recipient ?: ($recipients[0] ?? null);
|
return $tenant?->test_recipient ?: ($recipients[0] ?? null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* After how many days an unread, still detected finding is e-mailed again; 0 = only once.
|
||||||
|
*/
|
||||||
|
public static function reminderIntervalDays(?Tenant $tenant = null): int
|
||||||
|
{
|
||||||
|
return (int) (($tenant ?? self::tenant())?->reminder_interval_days ?? 0);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Applies the redirect of the current landlord to the mailer; called after saving.
|
* Applies the redirect of the current landlord to the mailer; called after saving.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Factories;
|
||||||
|
|
||||||
|
use App\Enums\InboxMessageKind;
|
||||||
|
use App\Models\InboxMessage;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends Factory<InboxMessage>
|
||||||
|
*/
|
||||||
|
class InboxMessageFactory extends Factory
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Define the model's default state.
|
||||||
|
*
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function definition(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'kind' => InboxMessageKind::ChannelConflict,
|
||||||
|
'fingerprint' => fake()->unique()->uuid(),
|
||||||
|
'subject' => fake()->sentence(4),
|
||||||
|
'body' => fake()->sentence(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function read(): static
|
||||||
|
{
|
||||||
|
return $this->state(fn (): array => ['read_at' => now()]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The admin inbox: things the landlord has to look at. A fingerprint per landlord makes every
|
||||||
|
* finding (e.g. one possible double booking) arrive only once, however often it is detected.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('inbox_messages', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->foreignId('tenant_id')->constrained()->cascadeOnDelete();
|
||||||
|
$table->foreignId('property_id')->nullable()->constrained()->cascadeOnDelete();
|
||||||
|
$table->foreignId('channel_id')->nullable()->constrained()->nullOnDelete();
|
||||||
|
$table->string('kind');
|
||||||
|
$table->string('fingerprint', 100);
|
||||||
|
$table->string('subject');
|
||||||
|
$table->text('body');
|
||||||
|
$table->string('action_url')->nullable();
|
||||||
|
$table->timestamp('read_at')->nullable();
|
||||||
|
$table->timestamps();
|
||||||
|
$table->unique(['tenant_id', 'fingerprint']);
|
||||||
|
$table->index(['tenant_id', 'read_at']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('inbox_messages');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Landlords choose how often an open finding is repeated by e-mail and whether they get a daily and/or
|
||||||
|
* weekly summary. Inbox messages remember when they were last mailed and last detected.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('tenants', function (Blueprint $table) {
|
||||||
|
$table->unsignedSmallInteger('reminder_interval_days')->default(0);
|
||||||
|
$table->boolean('digest_daily')->default(true);
|
||||||
|
$table->boolean('digest_weekly')->default(false);
|
||||||
|
$table->unsignedTinyInteger('digest_weekday')->default(1);
|
||||||
|
$table->unsignedTinyInteger('digest_hour')->default(7);
|
||||||
|
$table->json('digest_sections')->nullable();
|
||||||
|
$table->boolean('digest_when_empty')->default(false);
|
||||||
|
$table->date('digest_daily_sent_on')->nullable();
|
||||||
|
$table->date('digest_weekly_sent_on')->nullable();
|
||||||
|
});
|
||||||
|
|
||||||
|
Schema::table('inbox_messages', function (Blueprint $table) {
|
||||||
|
$table->timestamp('notified_at')->nullable()->after('action_url');
|
||||||
|
$table->timestamp('last_seen_at')->nullable()->after('notified_at');
|
||||||
|
});
|
||||||
|
|
||||||
|
DB::table('inbox_messages')->update(['notified_at' => DB::raw('created_at'), 'last_seen_at' => DB::raw('created_at')]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('inbox_messages', function (Blueprint $table) {
|
||||||
|
$table->dropColumn(['notified_at', 'last_seen_at']);
|
||||||
|
});
|
||||||
|
|
||||||
|
Schema::table('tenants', function (Blueprint $table) {
|
||||||
|
$table->dropColumn(['reminder_interval_days', 'digest_daily', 'digest_weekly', 'digest_weekday', 'digest_hour',
|
||||||
|
'digest_sections', 'digest_when_empty', 'digest_daily_sent_on', 'digest_weekly_sent_on']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -1,5 +1,9 @@
|
|||||||
# Projektstand
|
# Projektstand
|
||||||
|
|
||||||
|
**Erinnerungen und Zusammenfassungen einstellbar (30.10.2026, Branch `feature/erinnerungen-zusammenfassung`):** Neuer Abschnitt System › Betrieb › **Benachrichtigungen** (Spalten auf `tenants`). „Offene Meldungen erneut senden“: nur einmal (Vorgabe), täglich, alle 2/3 Tage, wöchentlich – gilt für mögliche Doppelbuchungen (solange im Postfach ungelesen und weiter festgestellt; Lesen beendet die Erinnerung, `Inbox::reminderDue`) und offene Portal-Aufgaben (`RemindChannelTasks`). **Tägliche und/oder wöchentliche Zusammenfassung** (`SendDigests`, Scheduler alle 15 Minuten, ab wählbarer Uhrzeit, Wochentag wählbar; am Wochentag nur die Wochenübersicht) mit wählbaren Teilen (`DigestSection`, `DigestReport`): Postfach, offene Anfragen/Angebote mit Frist, Neues seit der letzten Übersicht (Anfragen, Buchungen, Stornierungen, Portalbuchungen), An-/Abreisen (heute+morgen bzw. 7 Tage), überfällige Zahlungen, Portal-Aufgaben/zu prüfende Portal-Mails/Kalender-Klärungsfälle/Abgleichsfehler, Bewertungen zur Freigabe. Leere Übersichten entfallen (abschaltbar), Knopf „Zusammenfassung jetzt senden“. Vorgabe: täglich 7 Uhr an, wöchentlich aus. Tests: **520 Feature-Tests / 2725 Assertions grün**, Pint. Seite nicht im Browser angesehen.
|
||||||
|
|
||||||
|
**Doppelbuchungs-Mails nur noch einmal, neues Postfach in der Verwaltung (30.10.2026, Branch `feature/postfach`):** Ursache der Mailflut: `SyncChannel` prüfte bei jedem Abgleich (alle 5 Minuten) alle importierten Belegungen erneut und schickte jede fortbestehende Überschneidung wieder per Mail. Jetzt meldet `ReportChannelConflicts` (Kalenderabgleich und Portal-Mail) jede Überschneidung einmal: Sie landet im neuen **Postfach** (Vermietung › Postfach, `InboxMessage`, Zähler der ungelesenen im Menü, gelesen/ungelesen, „Ansehen“ öffnet den Belegungsplan im betroffenen Monat) und nur neue Meldungen gehen per Mail. Doppelte Meldungen verhindert ein Fingerabdruck je Mandant (`App\Support\Inbox`, eindeutiger Index). Ändern sich Termine, ist es eine neue Meldung. Das Synchronisationsprotokoll zählt offene Konflikte weiter. Nach dem Deployment kommt jede noch bestehende Überschneidung einmal neu (Postfach war leer). Tests: **513 Feature-Tests grün**, Pint.
|
||||||
|
|
||||||
**Wohnungen, Bilder und Banner neu geordnet (29.10.2026, Branch `feature/wohnungs-kontext`):**
|
**Wohnungen, Bilder und Banner neu geordnet (29.10.2026, Branch `feature/wohnungs-kontext`):**
|
||||||
- **Wohnungsumschalter** oben im Verwaltungsmenü (`App\Support\CurrentProperty`, je Mandant in der Sitzung). Listen (Fotos, Ausstattung, Bewertungen, Grundrisse, Sperrzeiten, Kanäle, Portal-Aufgaben/-Mails, Importereignisse), neue Einträge, Belegungsplan und Preise & Angebote folgen ihm; die Buchungsliste startet mit dem Filter auf die Wohnung. Ein geöffneter Eintrag einer anderen Wohnung (z. B. aus einer Mail) schaltet um. Website: Galerie und Ersatz-Titelbild zeigen nur Fotos der Wohnung des Bausteins und Fotos ohne Wohnung.
|
- **Wohnungsumschalter** oben im Verwaltungsmenü (`App\Support\CurrentProperty`, je Mandant in der Sitzung). Listen (Fotos, Ausstattung, Bewertungen, Grundrisse, Sperrzeiten, Kanäle, Portal-Aufgaben/-Mails, Importereignisse), neue Einträge, Belegungsplan und Preise & Angebote folgen ihm; die Buchungsliste startet mit dem Filter auf die Wohnung. Ein geöffneter Eintrag einer anderen Wohnung (z. B. aus einer Mail) schaltet um. Website: Galerie und Ersatz-Titelbild zeigen nur Fotos der Wohnung des Bausteins und Fotos ohne Wohnung.
|
||||||
- **Grundriss & Pläne:** eigene Fotokategorie, die keine Galerie zeigt; vorhandene Grundriss-Bilder wurden umgestellt. Ausgeblendete Planbilder funktionieren im Grundriss weiterhin.
|
- **Grundriss & Pläne:** eigene Fotokategorie, die keine Galerie zeigt; vorhandene Grundriss-Bilder wurden umgestellt. Ausgeblendete Planbilder funktionieren im Grundriss weiterhin.
|
||||||
|
|||||||
@@ -1,15 +1,31 @@
|
|||||||
<x-mail::message :site="$channel->property?->site" :message="$message ?? null">
|
<x-mail::message :site="$channel->property?->site" :message="$message ?? null">
|
||||||
# Mögliche Doppelbuchung
|
# {{ $conflicts === [] ? 'Noch offen: mögliche Doppelbuchung' : 'Mögliche Doppelbuchung' }}
|
||||||
|
|
||||||
Beim Kalender-Abgleich mit **{{ $channel->name }}** wurde eine neue Belegung gefunden, die sich mit einer bestehenden Belegung überschneidet:
|
@if ($conflicts !== [])
|
||||||
|
Beim Kalender-Abgleich mit **{{ $channel->name }}** wurde eine Belegung gefunden, die sich mit einer bestehenden Belegung überschneidet:
|
||||||
|
|
||||||
@foreach ($conflicts as $conflict)
|
@foreach ($conflicts as $conflict)
|
||||||
- {{ $conflict }}
|
- {{ $conflict }}
|
||||||
@endforeach
|
@endforeach
|
||||||
|
|
||||||
|
@endif
|
||||||
|
@if ($reminders !== [])
|
||||||
|
@if ($conflicts === [])
|
||||||
|
Diese Überschneidung mit **{{ $channel->name }}** besteht weiterhin und ist im Postfach noch ungelesen:
|
||||||
|
@else
|
||||||
|
Weiterhin offen und im Postfach noch ungelesen:
|
||||||
|
@endif
|
||||||
|
|
||||||
|
@foreach ($reminders as $reminder)
|
||||||
|
- {{ $reminder }}
|
||||||
|
@endforeach
|
||||||
|
|
||||||
|
@endif
|
||||||
Bitte prüfen Sie das umgehend im Portal und in der Verwaltung. Falls es sich um eine echte Doppelbuchung handelt, sollte einer der Gäste so früh wie möglich informiert werden.
|
Bitte prüfen Sie das umgehend im Portal und in der Verwaltung. Falls es sich um eine echte Doppelbuchung handelt, sollte einer der Gäste so früh wie möglich informiert werden.
|
||||||
|
|
||||||
<x-mail::button :url="\App\Filament\Resources\Bookings\BookingResource::getUrl('index')">
|
Die Meldung steht auch im Postfach der Verwaltung. Solange sie dort ungelesen ist und die Überschneidung besteht, erinnern wir im eingestellten Abstand daran (System › Betrieb › Benachrichtigungen).
|
||||||
Buchungen öffnen
|
|
||||||
|
<x-mail::button :url="\App\Filament\Resources\InboxMessages\InboxMessageResource::getUrl('index')">
|
||||||
|
Postfach öffnen
|
||||||
</x-mail::button>
|
</x-mail::button>
|
||||||
</x-mail::message>
|
</x-mail::message>
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<x-mail::message :message="$message ?? null">
|
||||||
|
# {{ $weekly ? 'Ihre Wochenübersicht' : 'Ihre Tagesübersicht' }}
|
||||||
|
|
||||||
|
@if ($sections === [])
|
||||||
|
Es steht nichts an: keine offenen Anfragen, Meldungen oder Aufgaben.
|
||||||
|
@endif
|
||||||
|
@foreach ($sections as $section)
|
||||||
|
## {{ $section['title'] }}
|
||||||
|
|
||||||
|
@foreach ($section['items'] as $item)
|
||||||
|
- {!! $item !!}
|
||||||
|
@endforeach
|
||||||
|
@if ($section['more'] > 0)
|
||||||
|
- … und {{ $section['more'] }} weitere
|
||||||
|
@endif
|
||||||
|
|
||||||
|
[{{ $section['link'] }}]({{ $section['url'] }})
|
||||||
|
|
||||||
|
@endforeach
|
||||||
|
---
|
||||||
|
|
||||||
|
Was in dieser Übersicht steht und wann sie kommt, stellen Sie in der Verwaltung unter System › Betrieb › Benachrichtigungen ein.
|
||||||
|
</x-mail::message>
|
||||||
@@ -5,6 +5,8 @@
|
|||||||
use App\Actions\RemindChannelTasks;
|
use App\Actions\RemindChannelTasks;
|
||||||
use App\Actions\RequestReviews;
|
use App\Actions\RequestReviews;
|
||||||
use App\Actions\SendBookingReminders;
|
use App\Actions\SendBookingReminders;
|
||||||
|
use App\Actions\SendDigests;
|
||||||
|
use App\Models\Tenant;
|
||||||
use App\Tenancy\TenantRunner;
|
use App\Tenancy\TenantRunner;
|
||||||
use Illuminate\Support\Facades\Schedule;
|
use Illuminate\Support\Facades\Schedule;
|
||||||
|
|
||||||
@@ -28,6 +30,11 @@
|
|||||||
->everyFifteenMinutes()
|
->everyFifteenMinutes()
|
||||||
->withoutOverlapping();
|
->withoutOverlapping();
|
||||||
|
|
||||||
|
Schedule::call(fn (TenantRunner $runner, SendDigests $sendDigests) => $runner->each(fn (Tenant $tenant) => $sendDigests->handle($tenant)))
|
||||||
|
->name('digests:send')
|
||||||
|
->everyFifteenMinutes()
|
||||||
|
->withoutOverlapping();
|
||||||
|
|
||||||
Schedule::call(fn (TenantRunner $runner, SendBookingReminders $sendBookingReminders) => $runner->each(fn () => $sendBookingReminders->handle()))
|
Schedule::call(fn (TenantRunner $runner, SendBookingReminders $sendBookingReminders) => $runner->each(fn () => $sendBookingReminders->handle()))
|
||||||
->name('bookings:reminders')
|
->name('bookings:reminders')
|
||||||
->dailyAt('09:00')
|
->dailyAt('09:00')
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
use App\Enums\BookingStatus;
|
use App\Enums\BookingStatus;
|
||||||
use App\Enums\ChannelTaskAction;
|
use App\Enums\ChannelTaskAction;
|
||||||
use App\Enums\ChannelTaskStatus;
|
use App\Enums\ChannelTaskStatus;
|
||||||
|
use App\Enums\InboxMessageKind;
|
||||||
use App\Filament\Resources\ChannelTasks\Pages\ListChannelTasks;
|
use App\Filament\Resources\ChannelTasks\Pages\ListChannelTasks;
|
||||||
use App\Filament\Resources\Properties\Pages\EditProperty;
|
use App\Filament\Resources\Properties\Pages\EditProperty;
|
||||||
use App\Filament\Resources\Properties\RelationManagers\ChannelsRelationManager;
|
use App\Filament\Resources\Properties\RelationManagers\ChannelsRelationManager;
|
||||||
@@ -21,8 +22,10 @@
|
|||||||
use App\Models\Booking;
|
use App\Models\Booking;
|
||||||
use App\Models\Channel;
|
use App\Models\Channel;
|
||||||
use App\Models\ChannelTask;
|
use App\Models\ChannelTask;
|
||||||
|
use App\Models\InboxMessage;
|
||||||
use App\Models\Property;
|
use App\Models\Property;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
|
use App\Tenancy\TenantContext;
|
||||||
use Carbon\CarbonImmutable;
|
use Carbon\CarbonImmutable;
|
||||||
use Database\Seeders\PropertySeeder;
|
use Database\Seeders\PropertySeeder;
|
||||||
use Filament\Actions\CreateAction;
|
use Filament\Actions\CreateAction;
|
||||||
@@ -118,6 +121,75 @@ public function test_overlap_with_an_existing_booking_is_reported_as_possible_do
|
|||||||
|
|
||||||
$this->assertSame(1, $log->conflicts);
|
$this->assertSame(1, $log->conflicts);
|
||||||
Mail::assertSent(ChannelConflict::class);
|
Mail::assertSent(ChannelConflict::class);
|
||||||
|
$message = InboxMessage::sole();
|
||||||
|
$this->assertSame(InboxMessageKind::ChannelConflict, $message->kind);
|
||||||
|
$this->assertSame($this->property->id, $message->property_id);
|
||||||
|
$this->assertStringContainsString('überschneidet sich mit Buchung', $message->body);
|
||||||
|
$this->assertStringContainsString('monat=2026-11', $message->action_url);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_a_lasting_double_booking_is_reported_once_however_often_the_calendar_is_synced(): void
|
||||||
|
{
|
||||||
|
$booking = Booking::factory()->for($this->property)->create(['arrival' => '2026-11-08', 'departure' => '2026-11-12', 'status' => BookingStatus::Confirmed]);
|
||||||
|
$channel = $this->channel('FeWo-direkt');
|
||||||
|
$this->fakeFeed([['x1', '20261107', '20261110']]);
|
||||||
|
|
||||||
|
foreach (range(1, 3) as $run) {
|
||||||
|
$this->travel(5)->minutes();
|
||||||
|
$log = (new SyncChannel)->handle($channel);
|
||||||
|
$this->assertSame(1, $log->conflicts, 'the sync log keeps counting the open conflict');
|
||||||
|
}
|
||||||
|
|
||||||
|
Mail::assertSentCount(1);
|
||||||
|
$this->assertSame(1, InboxMessage::count());
|
||||||
|
|
||||||
|
$booking->update(['departure' => '2026-11-13']);
|
||||||
|
(new SyncChannel)->handle($channel);
|
||||||
|
|
||||||
|
Mail::assertSent(ChannelConflict::class, 2);
|
||||||
|
$this->assertSame(2, InboxMessage::count());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_an_unread_double_booking_is_repeated_after_the_chosen_interval_until_it_is_read(): void
|
||||||
|
{
|
||||||
|
$this->property->tenant->update(['reminder_interval_days' => 3]);
|
||||||
|
Booking::factory()->for($this->property)->create(['arrival' => '2026-11-08', 'departure' => '2026-11-12', 'status' => BookingStatus::Confirmed]);
|
||||||
|
$channel = $this->channel('FeWo-direkt');
|
||||||
|
$this->fakeFeed([['x1', '20261107', '20261110']]);
|
||||||
|
(new SyncChannel)->handle($channel);
|
||||||
|
|
||||||
|
$this->travel(2)->days();
|
||||||
|
(new SyncChannel)->handle($channel);
|
||||||
|
Mail::assertSentCount(1);
|
||||||
|
|
||||||
|
$this->travel(1)->days();
|
||||||
|
(new SyncChannel)->handle($channel);
|
||||||
|
(new SyncChannel)->handle($channel);
|
||||||
|
Mail::assertSentCount(2);
|
||||||
|
Mail::assertSent(ChannelConflict::class, fn (ChannelConflict $mail): bool => $mail->conflicts === [] && count($mail->reminders) === 1
|
||||||
|
&& str_starts_with($mail->envelope()->subject, 'Erinnerung'));
|
||||||
|
|
||||||
|
InboxMessage::sole()->update(['read_at' => now()]);
|
||||||
|
$this->travel(4)->days();
|
||||||
|
(new SyncChannel)->handle($channel);
|
||||||
|
Mail::assertSentCount(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_open_portal_tasks_are_repeated_after_the_chosen_interval(): void
|
||||||
|
{
|
||||||
|
config(['fewo.channels.task_reminder_after_minutes' => 30]);
|
||||||
|
$this->property->tenant->update(['reminder_interval_days' => 1]);
|
||||||
|
app(TenantContext::class)->set($this->property->tenant);
|
||||||
|
ChannelTask::factory()->for($this->channel('Ostseeklar', manual: true))->create(['created_at' => now()->subHour()]);
|
||||||
|
|
||||||
|
$this->assertSame(1, app(RemindChannelTasks::class)->handle());
|
||||||
|
$this->assertSame(0, app(RemindChannelTasks::class)->handle());
|
||||||
|
$this->travel(1)->days();
|
||||||
|
$this->assertSame(1, app(RemindChannelTasks::class)->handle());
|
||||||
|
|
||||||
|
$this->property->tenant->update(['reminder_interval_days' => 0]);
|
||||||
|
$this->travel(5)->days();
|
||||||
|
$this->assertSame(0, app(RemindChannelTasks::class)->handle());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_failed_import_is_logged_and_alerted_once_until_it_works_again(): void
|
public function test_failed_import_is_logged_and_alerted_once_until_it_works_again(): void
|
||||||
|
|||||||
@@ -0,0 +1,156 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature;
|
||||||
|
|
||||||
|
use App\Actions\SendDigests;
|
||||||
|
use App\Enums\BookingStatus;
|
||||||
|
use App\Enums\DigestSection;
|
||||||
|
use App\Filament\Pages\Operations;
|
||||||
|
use App\Mail\Digest;
|
||||||
|
use App\Models\Booking;
|
||||||
|
use App\Models\Guest;
|
||||||
|
use App\Models\InboxMessage;
|
||||||
|
use App\Models\Property;
|
||||||
|
use App\Models\Tenant;
|
||||||
|
use App\Models\User;
|
||||||
|
use App\Tenancy\TenantConfig;
|
||||||
|
use App\Tenancy\TenantContext;
|
||||||
|
use Carbon\CarbonImmutable;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Illuminate\Support\Facades\Mail;
|
||||||
|
use Livewire\Livewire;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class DigestTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
|
||||||
|
private Tenant $tenant;
|
||||||
|
|
||||||
|
private Property $property;
|
||||||
|
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
config(['fewo.mail_redirect_to' => null]);
|
||||||
|
$this->travelTo(CarbonImmutable::parse('2026-11-02 06:30'));
|
||||||
|
$this->tenant = Tenant::factory()->create(['notification_emails' => 'vermieterin@example.com']);
|
||||||
|
app(TenantContext::class)->set($this->tenant);
|
||||||
|
app(TenantConfig::class)->refresh();
|
||||||
|
$this->property = Property::factory()->create();
|
||||||
|
Mail::fake();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_daily_summary_goes_out_once_from_the_chosen_hour(): void
|
||||||
|
{
|
||||||
|
$this->openRequest();
|
||||||
|
$digests = app(SendDigests::class);
|
||||||
|
|
||||||
|
$this->assertNull($digests->handle($this->tenant));
|
||||||
|
$this->travelTo(CarbonImmutable::parse('2026-11-02 07:00'));
|
||||||
|
$this->assertSame('daily', $digests->handle($this->tenant->fresh()));
|
||||||
|
$this->assertNull($digests->handle($this->tenant->fresh()));
|
||||||
|
|
||||||
|
Mail::assertSent(Digest::class, 1);
|
||||||
|
Mail::assertSent(Digest::class, fn (Digest $mail): bool => $mail->hasTo('vermieterin@example.com') && ! $mail->weekly
|
||||||
|
&& str_starts_with($mail->envelope()->subject, 'Tagesübersicht 02.11.2026: 2 Punkte'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_on_the_weekly_day_only_the_weekly_summary_goes_out(): void
|
||||||
|
{
|
||||||
|
$this->openRequest();
|
||||||
|
$this->tenant->update(['digest_weekly' => true, 'digest_weekday' => 1, 'digest_hour' => 6]);
|
||||||
|
|
||||||
|
$this->assertSame('weekly', app(SendDigests::class)->handle($this->tenant));
|
||||||
|
$this->assertNull(app(SendDigests::class)->handle($this->tenant->fresh()));
|
||||||
|
Mail::assertSent(Digest::class, fn (Digest $mail): bool => $mail->weekly && str_starts_with($mail->envelope()->subject, 'Wochenübersicht KW 45'));
|
||||||
|
Mail::assertSent(Digest::class, 1);
|
||||||
|
|
||||||
|
$this->travel(1)->days();
|
||||||
|
$this->assertSame('daily', app(SendDigests::class)->handle($this->tenant->fresh()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_nothing_to_report_sends_nothing_unless_wanted(): void
|
||||||
|
{
|
||||||
|
$this->tenant->update(['digest_hour' => 6]);
|
||||||
|
|
||||||
|
$this->assertSame('daily', app(SendDigests::class)->handle($this->tenant));
|
||||||
|
Mail::assertNothingSent();
|
||||||
|
|
||||||
|
$this->tenant->update(['digest_when_empty' => true, 'digest_daily_sent_on' => null]);
|
||||||
|
app(SendDigests::class)->handle($this->tenant->fresh());
|
||||||
|
Mail::assertSent(Digest::class, fn (Digest $mail): bool => $mail->sections === [] && str_ends_with($mail->envelope()->subject, 'nichts Neues'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_summary_lists_requests_stays_payments_and_inbox_and_only_the_chosen_sections(): void
|
||||||
|
{
|
||||||
|
$this->openRequest();
|
||||||
|
$this->booking(['arrival' => '2026-11-03', 'departure' => '2026-11-07'], 'Erika Mustermann');
|
||||||
|
$this->booking(['arrival' => '2026-12-01', 'departure' => '2026-12-05', 'balance_due_on' => '2026-10-20', 'created_at' => now()->subWeek()], 'Hans Säumig');
|
||||||
|
InboxMessage::factory()->create(['subject' => 'Mögliche Doppelbuchung über FeWo-direkt', 'body' => '<b>Ostsee</b>']);
|
||||||
|
|
||||||
|
app(SendDigests::class)->send($this->tenant, weekly: false);
|
||||||
|
|
||||||
|
Mail::assertSent(Digest::class, function (Digest $mail): bool {
|
||||||
|
$html = $mail->render();
|
||||||
|
$titles = array_column($mail->sections, 'title');
|
||||||
|
|
||||||
|
return in_array('Offene Anfragen und Angebote', $titles, true)
|
||||||
|
&& in_array('An- und Abreisen heute und morgen', $titles, true)
|
||||||
|
&& in_array('Überfällige Zahlungen', $titles, true)
|
||||||
|
&& str_contains($html, 'Morgen: Anreise')
|
||||||
|
&& str_contains($html, 'Erika Mustermann')
|
||||||
|
&& str_contains($html, 'Hans Säumig')
|
||||||
|
&& str_contains($html, 'Frist bis')
|
||||||
|
&& str_contains($html, '<b>Ostsee</b>')
|
||||||
|
&& ! str_contains($html, '<b>Ostsee</b>');
|
||||||
|
});
|
||||||
|
|
||||||
|
Mail::fake();
|
||||||
|
$this->tenant->update(['digest_sections' => [DigestSection::Inbox->value]]);
|
||||||
|
app(SendDigests::class)->send($this->tenant->fresh(), weekly: false);
|
||||||
|
Mail::assertSent(Digest::class, fn (Digest $mail): bool => array_column($mail->sections, 'section') === [DigestSection::Inbox]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_settings_are_saved_on_the_operations_page_and_a_summary_can_be_sent_right_away(): void
|
||||||
|
{
|
||||||
|
$this->actingAs(User::factory()->create());
|
||||||
|
|
||||||
|
Livewire::test(Operations::class)
|
||||||
|
->assertSet('data.reminder_interval_days', 0)
|
||||||
|
->assertSet('data.digest_daily', true)
|
||||||
|
->set('data.reminder_interval_days', 3)
|
||||||
|
->set('data.digest_weekly', true)
|
||||||
|
->set('data.digest_weekday', 5)
|
||||||
|
->set('data.digest_hour', 18)
|
||||||
|
->set('data.digest_sections', [DigestSection::Inbox->value, DigestSection::Portals->value])
|
||||||
|
->call('save')
|
||||||
|
->assertHasNoErrors()
|
||||||
|
->callAction('sendDigest', ['weekly' => 1]);
|
||||||
|
|
||||||
|
$tenant = $this->tenant->fresh();
|
||||||
|
$this->assertSame([3, true, 5, 18], [$tenant->reminder_interval_days, $tenant->digest_weekly, $tenant->digest_weekday, $tenant->digest_hour]);
|
||||||
|
$this->assertSame(['inbox', 'portals'], $tenant->digest_sections);
|
||||||
|
Mail::assertSent(Digest::class, fn (Digest $mail): bool => $mail->weekly);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function openRequest(): Booking
|
||||||
|
{
|
||||||
|
return Booking::factory()->for($this->property)->reserved()->create(['guest_id' => Guest::factory()->create(['first_name' => 'Anna', 'last_name' => 'Anfrage'])->id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $attributes
|
||||||
|
*/
|
||||||
|
private function booking(array $attributes, string $name): Booking
|
||||||
|
{
|
||||||
|
[$first, $last] = explode(' ', $name);
|
||||||
|
|
||||||
|
return Booking::factory()->for($this->property)->create([
|
||||||
|
'status' => BookingStatus::Confirmed,
|
||||||
|
'guest_id' => Guest::factory()->create(['first_name' => $first, 'last_name' => $last])->id,
|
||||||
|
...$attributes,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,89 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature;
|
||||||
|
|
||||||
|
use App\Enums\InboxMessageKind;
|
||||||
|
use App\Filament\Resources\InboxMessages\InboxMessageResource;
|
||||||
|
use App\Filament\Resources\InboxMessages\Pages\ListInboxMessages;
|
||||||
|
use App\Models\Channel;
|
||||||
|
use App\Models\InboxMessage;
|
||||||
|
use App\Models\Property;
|
||||||
|
use App\Models\User;
|
||||||
|
use App\Support\CurrentProperty;
|
||||||
|
use App\Support\Inbox;
|
||||||
|
use Filament\Actions\Testing\TestAction;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Livewire\Livewire;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class InboxTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
|
||||||
|
private Channel $channel;
|
||||||
|
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->actingAs(User::factory()->create());
|
||||||
|
$this->channel = Channel::factory()->for(Property::factory())->create(['name' => 'FeWo-direkt']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_a_finding_is_posted_only_once(): void
|
||||||
|
{
|
||||||
|
$inbox = app(Inbox::class);
|
||||||
|
|
||||||
|
$first = $inbox->post(InboxMessageKind::ChannelConflict, 'x', 'Mögliche Doppelbuchung', 'Text', $this->channel);
|
||||||
|
$again = $inbox->post(InboxMessageKind::ChannelConflict, 'x', 'Mögliche Doppelbuchung', 'Text', $this->channel);
|
||||||
|
|
||||||
|
$this->assertNotNull($first);
|
||||||
|
$this->assertNull($again);
|
||||||
|
$this->assertSame($this->channel->property_id, $first->property_id);
|
||||||
|
$this->assertSame(1, InboxMessage::count());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_menu_shows_the_number_of_unread_messages(): void
|
||||||
|
{
|
||||||
|
InboxMessage::factory()->for($this->channel)->count(2)->create();
|
||||||
|
InboxMessage::factory()->for($this->channel)->read()->create();
|
||||||
|
|
||||||
|
$this->assertSame('2', InboxMessageResource::getNavigationBadge());
|
||||||
|
$this->get(InboxMessageResource::getUrl('index'))->assertOk()->assertSee('Postfach');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_messages_can_be_marked_as_read_and_opened(): void
|
||||||
|
{
|
||||||
|
$message = InboxMessage::factory()->for($this->channel)->create(['subject' => 'Mögliche Doppelbuchung über FeWo-direkt', 'action_url' => 'http://localhost/admin/belegung']);
|
||||||
|
$other = InboxMessage::factory()->for($this->channel)->create();
|
||||||
|
|
||||||
|
Livewire::test(ListInboxMessages::class)
|
||||||
|
->assertCanSeeTableRecords([$message, $other])
|
||||||
|
->assertSee('Mögliche Doppelbuchung über FeWo-direkt')
|
||||||
|
->callAction(TestAction::make('toggleRead')->table($other))
|
||||||
|
->callAction(TestAction::make('open')->table($message))
|
||||||
|
->assertRedirect('http://localhost/admin/belegung');
|
||||||
|
|
||||||
|
$this->assertTrue($message->fresh()->isRead());
|
||||||
|
$this->assertTrue($other->fresh()->isRead());
|
||||||
|
$this->assertNull(InboxMessageResource::getNavigationBadge());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_read_all_marks_only_the_chosen_apartments_messages(): void
|
||||||
|
{
|
||||||
|
$otherChannel = Channel::factory()->for(Property::factory())->create();
|
||||||
|
$own = InboxMessage::factory()->for($this->channel)->create(['property_id' => $this->channel->property_id]);
|
||||||
|
$general = InboxMessage::factory()->create(['tenant_id' => $this->channel->tenant_id]);
|
||||||
|
$foreign = InboxMessage::factory()->for($otherChannel)->create(['property_id' => $otherChannel->property_id]);
|
||||||
|
app(CurrentProperty::class)->select($this->channel->property);
|
||||||
|
|
||||||
|
Livewire::test(ListInboxMessages::class)
|
||||||
|
->assertCanSeeTableRecords([$own, $general])
|
||||||
|
->assertCanNotSeeTableRecords([$foreign])
|
||||||
|
->callAction('readAll');
|
||||||
|
|
||||||
|
$this->assertTrue($own->fresh()->isRead());
|
||||||
|
$this->assertTrue($general->fresh()->isRead());
|
||||||
|
$this->assertFalse($foreign->fresh()->isRead());
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user