Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b9225f5fb8 | ||
|
|
876a0a20f3 |
No files matched your search
@@ -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];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions;
|
||||||
|
|
||||||
|
use App\Enums\InboxMessageKind;
|
||||||
|
use App\Filament\Pages\OccupancyCalendar;
|
||||||
|
use App\Mail\ChannelConflict;
|
||||||
|
use App\Models\Channel;
|
||||||
|
use App\Support\Inbox;
|
||||||
|
use App\Support\Settings;
|
||||||
|
use Carbon\CarbonInterface;
|
||||||
|
use Illuminate\Support\Facades\Mail;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reports possible double bookings found while importing portal occupations (calendar sync or portal
|
||||||
|
* e-mail). Every conflict lands in the admin inbox once; only conflicts not reported before are e-mailed,
|
||||||
|
* so a lasting overlap does not trigger a mail on every sync.
|
||||||
|
*/
|
||||||
|
class ReportChannelConflicts
|
||||||
|
{
|
||||||
|
public function __construct(private Inbox $inbox) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, CarbonInterface> $conflicts description => first night of the portal occupation
|
||||||
|
* @return list<string> the conflicts reported for the first time
|
||||||
|
*/
|
||||||
|
public function handle(Channel $channel, array $conflicts): array
|
||||||
|
{
|
||||||
|
$new = [];
|
||||||
|
foreach ($conflicts as $description => $startsOn) {
|
||||||
|
$message = $this->inbox->post(
|
||||||
|
InboxMessageKind::ChannelConflict,
|
||||||
|
$channel->id.':'.sha1($description),
|
||||||
|
'Mögliche Doppelbuchung über '.$channel->name,
|
||||||
|
$description,
|
||||||
|
$channel,
|
||||||
|
OccupancyCalendar::getUrl(['monat' => $startsOn->format('Y-m'), 'wohnung' => $channel->property_id]),
|
||||||
|
);
|
||||||
|
if ($message) {
|
||||||
|
$new[] = $description;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($new !== []) {
|
||||||
|
rescue(fn () => Mail::to(Settings::notificationRecipients())->send(new ChannelConflict($channel, $new)));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $new;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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,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',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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(),
|
||||||
|
]),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
<?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', '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,
|
||||||
|
'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');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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,41 @@
|
|||||||
|
<?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 reports a lasting problem a single time.
|
||||||
|
*/
|
||||||
|
class Inbox
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return InboxMessage|null the new message, or null when this finding was posted before
|
||||||
|
*/
|
||||||
|
public function post(InboxMessageKind $kind, string $fingerprint, string $subject, string $body, ?Channel $channel = null, ?string $actionUrl = null): ?InboxMessage
|
||||||
|
{
|
||||||
|
$fingerprint = $kind->value.':'.$fingerprint;
|
||||||
|
|
||||||
|
if (InboxMessage::query()->where('fingerprint', $fingerprint)->exists()) {
|
||||||
|
return 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,
|
||||||
|
]);
|
||||||
|
} catch (UniqueConstraintViolationException) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
# Projektstand
|
# Projektstand
|
||||||
|
|
||||||
|
**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.
|
||||||
|
|||||||
@@ -9,7 +9,9 @@
|
|||||||
|
|
||||||
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')">
|
Diese Meldung steht auch im Postfach der Verwaltung. Sie kommt nur einmal, auch wenn die Überschneidung bei weiteren Abgleichen bestehen bleibt.
|
||||||
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>
|
||||||
@@ -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,6 +22,7 @@
|
|||||||
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 Carbon\CarbonImmutable;
|
use Carbon\CarbonImmutable;
|
||||||
@@ -118,6 +120,33 @@ 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_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,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