Vorgangskern und geführte Vorgangsbearbeitung (Pakete 1 und 2, Prozessarchitektur v0.10)
- Buchung ist der einheitliche Vorgang: Eingangsart, Vorgangsart A1–A6, eingefrorenes Abwicklungsprofil, gespeicherter Verlauf (booking_events); Gast, Personen und Beträge dürfen unbekannt sein, Platzhalter-Gäste werden migriert und nicht mehr angelegt - Einstellungen in Ebenen: Vermieterstandard (So arbeite ich), Abweichung der Wohnung (Experte), Abweichung je Portal und Eingangsart; ersetzt booking_model als Steuergröße - Ein Weg für extern verbindliche Buchungen (TakeOverExternalBooking) statt RecordPortalBooking und "Akte anlegen"; Portalpreis als belegte Gesamtposition - Startseite "Zu erledigen", neue Vorgangsseite mit nächstem Schritt, Automatik-Schalter, "Beenden" mit Storno statt Statusumschaltung; Status von Hand nur im Expertenmodus - Migration übernimmt bisheriges Verhalten unverändert (abweichende Wohnungswerte bleiben als Abweichung), Bericht: php artisan process:settings-report Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9005c12164
commit
3a728c3255
78 files changed
+4296
-1180
No files matched your search
@@ -32,9 +32,9 @@ class BookingResource extends Resource
|
||||
|
||||
protected static string|UnitEnum|null $navigationGroup = 'Verwaltung';
|
||||
|
||||
protected static ?string $modelLabel = 'Buchung';
|
||||
protected static ?string $modelLabel = 'Vorgang';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'Anfragen & Buchungen';
|
||||
protected static ?string $pluralModelLabel = 'Vorgänge';
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'reference';
|
||||
|
||||
|
||||
@@ -4,9 +4,12 @@
|
||||
|
||||
use App\Actions\ConfirmBooking;
|
||||
use App\Actions\CreateReservation;
|
||||
use App\Actions\RecordPortalBooking;
|
||||
use App\Actions\TakeOverExternalBooking;
|
||||
use App\Exceptions\ReservationException;
|
||||
use App\Filament\Resources\BlockedPeriods\BlockedPeriodResource;
|
||||
use App\Filament\Resources\Bookings\BookingResource;
|
||||
use App\Filament\Resources\Bookings\Schemas\BookingForm;
|
||||
use App\Models\Booking;
|
||||
use App\Models\Channel;
|
||||
use App\Models\Property;
|
||||
use App\Pricing\QuoteException;
|
||||
@@ -17,61 +20,68 @@
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
/**
|
||||
* Entry of a new case that did not come through the website: a request (A1/A2) goes the same way as a website request,
|
||||
* a booking already binding on a portal (A3–A5) is taken over as it is.
|
||||
*/
|
||||
class CreateBooking extends CreateRecord
|
||||
{
|
||||
protected static string $resource = BookingResource::class;
|
||||
|
||||
protected static ?string $title = 'Buchung erfassen';
|
||||
protected static ?string $title = 'Neu eintragen';
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
*/
|
||||
protected function handleRecordCreation(array $data): Model
|
||||
{
|
||||
try {
|
||||
$property = Property::findOrFail($data['property_id']);
|
||||
$stay = new StayRequest(
|
||||
CarbonImmutable::parse($data['arrival']),
|
||||
CarbonImmutable::parse($data['departure']),
|
||||
(int) $data['guests'],
|
||||
promoCode: $data['promo_code'] ?: null,
|
||||
);
|
||||
$guest = Arr::only($data, ['first_name', 'last_name', 'email', 'phone', 'street', 'postal_code', 'city']);
|
||||
|
||||
if (filled($data['channel_id'] ?? null)) {
|
||||
$booking = app(RecordPortalBooking::class)->handle(
|
||||
$property,
|
||||
Channel::query()->findOrFail($data['channel_id']),
|
||||
$stay,
|
||||
$guest,
|
||||
$data['portal_process'] ?? RecordPortalBooking::CONFIRM,
|
||||
$data['portal_reference'] ?? null,
|
||||
filled($data['portal_total'] ?? null) ? (int) $data['portal_total'] : null,
|
||||
$data['internal_notes'] ?: null,
|
||||
(bool) ($data['guest_confirmed'] ?? false),
|
||||
);
|
||||
|
||||
return $booking;
|
||||
}
|
||||
|
||||
$booking = app(CreateReservation::class)->handle($property, $stay, $guest, source: 'manual', sendMails: $data['send_mails']);
|
||||
|
||||
if ($data['confirm_immediately']) {
|
||||
app(ConfirmBooking::class)->handle($booking, notifyGuest: $data['send_mails']);
|
||||
}
|
||||
} catch (QuoteException|ReservationException $exception) {
|
||||
Notification::make()->title('Buchung nicht möglich')->body($exception->getMessage())->danger()->send();
|
||||
|
||||
if (($data['kind'] ?? null) === BookingForm::OWN_USE) {
|
||||
$this->redirect(BlockedPeriodResource::getUrl());
|
||||
$this->halt();
|
||||
}
|
||||
|
||||
$booking->update(['internal_notes' => $data['internal_notes'] ?: null]);
|
||||
try {
|
||||
$property = Property::query()->findOrFail($data['property_id']);
|
||||
$channel = filled($data['channel_id'] ?? null) ? Channel::query()->findOrFail($data['channel_id']) : null;
|
||||
$arrival = CarbonImmutable::parse($data['arrival']);
|
||||
$departure = CarbonImmutable::parse($data['departure']);
|
||||
$guest = Arr::only($data, ['first_name', 'last_name', 'email', 'phone', 'street', 'postal_code', 'city']);
|
||||
|
||||
if ($data['kind'] === BookingForm::EXTERNAL) {
|
||||
return app(TakeOverExternalBooking::class)->handle($property, $channel, $arrival, $departure, [
|
||||
'guest' => $guest,
|
||||
'guests' => filled($data['guests'] ?? null) ? (int) $data['guests'] : null,
|
||||
'portal_reference' => $data['portal_reference'] ?? null,
|
||||
'portal_total' => filled($data['portal_total'] ?? null) ? (int) $data['portal_total'] : null,
|
||||
'notes' => $data['internal_notes'] ?? null,
|
||||
'guest_confirmed' => (bool) ($data['guest_confirmed'] ?? false),
|
||||
]);
|
||||
}
|
||||
|
||||
$stay = new StayRequest($arrival, $departure, (int) $data['guests'], promoCode: filled($data['promo_code'] ?? null) ? $data['promo_code'] : null);
|
||||
$sendMails = (bool) ($data['send_mails'] ?? false);
|
||||
$booking = app(CreateReservation::class)->handle($property, $stay, $guest, source: 'manual', sendMails: $sendMails && ! ($data['confirm_immediately'] ?? false), originChannel: $channel);
|
||||
|
||||
if ($data['confirm_immediately'] ?? false) {
|
||||
app(ConfirmBooking::class)->handle($booking, notifyGuest: $sendMails && filled($booking->guest?->email));
|
||||
}
|
||||
} catch (QuoteException|ReservationException $exception) {
|
||||
Notification::make()->title('Nicht möglich')->body($exception->getMessage())->danger()->send();
|
||||
$this->halt();
|
||||
}
|
||||
|
||||
if (filled($data['internal_notes'] ?? null)) {
|
||||
$booking->update(['internal_notes' => trim(($booking->internal_notes ? $booking->internal_notes."\n\n" : '').$data['internal_notes'])]);
|
||||
}
|
||||
|
||||
return $booking;
|
||||
}
|
||||
|
||||
protected function getRedirectUrl(): string
|
||||
{
|
||||
return BookingResource::getUrl('view', ['record' => $this->getRecord()]);
|
||||
/** @var Booking $record */
|
||||
$record = $this->getRecord();
|
||||
|
||||
return BookingResource::getUrl('view', ['record' => $record]);
|
||||
}
|
||||
}
|
||||
@@ -10,18 +10,26 @@
|
||||
use App\Actions\SetBookingStatus;
|
||||
use App\Documents\OfferTerms;
|
||||
use App\Documents\RentalContract;
|
||||
use App\Enums\AdminMode;
|
||||
use App\Enums\BookingStatus;
|
||||
use App\Enums\IntakeKind;
|
||||
use App\Enums\ProcessingMode;
|
||||
use App\Exceptions\ReservationException;
|
||||
use App\Filament\Actions\AssignGuestAction;
|
||||
use App\Filament\Forms\Components\EuroInput;
|
||||
use App\Filament\Resources\Bookings\BookingResource;
|
||||
use App\Models\Booking;
|
||||
use App\Models\ContractAnnex;
|
||||
use App\Models\ContractTemplate;
|
||||
use App\Models\Extra;
|
||||
use App\Models\User;
|
||||
use App\Pricing\PortalPrice;
|
||||
use App\Pricing\PriceCalculator;
|
||||
use App\Pricing\QuoteException;
|
||||
use App\Pricing\StayRequest;
|
||||
use App\Support\BookingProgress;
|
||||
use App\Process\CaseActivities;
|
||||
use App\Process\CaseAutomation;
|
||||
use App\Process\CaseLog;
|
||||
use App\Support\Money;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Filament\Actions\Action;
|
||||
@@ -40,85 +48,133 @@
|
||||
use Filament\Schemas\Components\Text;
|
||||
use Filament\Schemas\Components\Utilities\Get;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* The case page. At the top only what matters now: the next step as one large button, "Beenden" and the switch between
|
||||
* automatic and manual handling. Everything else that is possible right now sits under "Weitere Möglichkeiten";
|
||||
* technical functions only in the expert view. Ending a case always takes the proper way – a binding booking is
|
||||
* cancelled with its consequences, it cannot be "set back" by a status change.
|
||||
*
|
||||
* @property Booking $record
|
||||
*/
|
||||
class ViewBooking extends ViewRecord
|
||||
{
|
||||
protected static string $resource = BookingResource::class;
|
||||
|
||||
/** Actions for the expert view only. */
|
||||
private const EXPERT = ['offerLink', 'contractText', 'setStatus'];
|
||||
|
||||
public function getTitle(): string
|
||||
{
|
||||
return "{$this->record->reference} · {$this->record->guest->full_name}";
|
||||
return "{$this->record->reference} · {$this->record->guestName()}";
|
||||
}
|
||||
|
||||
public function getSubheading(): string|Htmlable|null
|
||||
{
|
||||
return CaseActivities::situation($this->record);
|
||||
}
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
$actions = collect([
|
||||
$this->sendOfferAction(),
|
||||
$this->provideContactAction(),
|
||||
$this->requestContactAction(),
|
||||
AssignGuestAction::make(),
|
||||
Action::make('sendOffer')
|
||||
->label(fn (): string => $this->record->status === BookingStatus::OfferSent ? 'Angebot ändern & neu senden' : 'Angebot senden')
|
||||
->icon(Heroicon::OutlinedPaperAirplane)
|
||||
->color('success')
|
||||
->visible(fn (): bool => in_array($this->record->status, [BookingStatus::Reserved, BookingStatus::OfferSent, BookingStatus::Expired], true))
|
||||
->modalHeading('Angebot an den Gast senden')
|
||||
->modalDescription('Der Gast erhält das Angebot mit Vertragsentwurf per E-Mail und kann es über einen Link annehmen oder ablehnen. Erst mit seiner Annahme ist die Buchung verbindlich.')
|
||||
->modalSubmitActionLabel('Angebot senden')
|
||||
->modalWidth('3xl')
|
||||
->fillForm(fn (): array => [
|
||||
'arrival' => $this->record->arrival->toDateString(),
|
||||
'departure' => $this->record->departure->toDateString(),
|
||||
'guests' => $this->record->guests,
|
||||
'promo_code' => $this->record->promo_code,
|
||||
'price_adjustment' => $this->record->price_adjustment !== null ? number_format($this->record->price_adjustment / 100, 2, '.', '') : null,
|
||||
'price_adjustment_label' => $this->record->price_adjustment_label,
|
||||
'valid_until' => now()->addHours($this->record->property->hold_hours)->format('Y-m-d H:i'),
|
||||
'offer_message' => $this->record->offer_message,
|
||||
'guest' => $this->record->guest->only(['first_name', 'last_name', 'street', 'postal_code', 'city', 'phone']),
|
||||
])
|
||||
->schema([
|
||||
$this->confirmAction(),
|
||||
$this->resendConfirmationAction(),
|
||||
$this->portalPriceAction(),
|
||||
$this->extendHoldAction(),
|
||||
$this->servicesAction(),
|
||||
$this->offerPdfAction(),
|
||||
$this->contractAction(),
|
||||
$this->offerLinkAction(),
|
||||
$this->contractTextAction(),
|
||||
$this->notesAction(),
|
||||
$this->archiveAction(),
|
||||
$this->setStatusAction(),
|
||||
])->keyBy(fn (Action $action): string => $action->getName());
|
||||
|
||||
$next = CaseActivities::next($this->record)?->action;
|
||||
$primary = $next !== null && $actions->has($next) ? $actions->pull($next)->color('primary')->size('lg')->icon(Heroicon::OutlinedArrowRightCircle) : null;
|
||||
$expert = $actions->only(self::EXPERT)->values()->all();
|
||||
$more = $actions->except(self::EXPERT)->values()->all();
|
||||
|
||||
return array_values(array_filter([
|
||||
$primary,
|
||||
$this->automationAction(),
|
||||
$this->endAction(),
|
||||
ActionGroup::make($more)->label('Weitere Möglichkeiten')->icon(Heroicon::OutlinedEllipsisHorizontal)->button()->color('gray'),
|
||||
$this->isExpert() ? ActionGroup::make($expert)->label('Experte')->icon(Heroicon::OutlinedWrenchScrewdriver)->button()->color('gray') : null,
|
||||
]));
|
||||
}
|
||||
|
||||
private function isExpert(): bool
|
||||
{
|
||||
$user = auth()->user();
|
||||
|
||||
return $user instanceof User && $user->adminMode() === AdminMode::Expert;
|
||||
}
|
||||
|
||||
private function sendOfferAction(): Action
|
||||
{
|
||||
return Action::make('sendOffer')
|
||||
->label(fn (): string => $this->record->status === BookingStatus::OfferSent ? 'Angebot ändern & neu senden' : 'Angebot prüfen und senden')
|
||||
->icon(Heroicon::OutlinedPaperAirplane)
|
||||
->visible(fn (): bool => in_array($this->record->status, [BookingStatus::Reserved, BookingStatus::OfferSent, BookingStatus::Expired], true) && $this->record->intake !== IntakeKind::Booking)
|
||||
->modalHeading('Angebot an den Gast')
|
||||
->modalDescription('Alles ist vorbereitet: Preis, Vertragsvorlage, Anlagen und Gültigkeit kommen aus Ihren Einstellungen. Prüfen Sie die Angaben; „Anpassen“ nur bei Bedarf. Mit „Senden“ erhält der Gast das Angebot mit einem Link zum Annehmen.')
|
||||
->modalSubmitActionLabel('Senden')
|
||||
->modalWidth('3xl')
|
||||
->fillForm(fn (): array => [
|
||||
'arrival' => $this->record->arrival->toDateString(),
|
||||
'departure' => $this->record->departure->toDateString(),
|
||||
'guests' => $this->record->guests,
|
||||
'promo_code' => $this->record->promo_code,
|
||||
'price_adjustment' => $this->record->price_adjustment !== null ? number_format($this->record->price_adjustment / 100, 2, '.', '') : null,
|
||||
'price_adjustment_label' => $this->record->price_adjustment_label,
|
||||
'valid_until' => now()->addHours($this->record->process()->holdHours())->format('Y-m-d H:i'),
|
||||
'offer_message' => $this->record->offer_message,
|
||||
'guest' => $this->record->guest?->only(['first_name', 'last_name', 'street', 'postal_code', 'city', 'phone']) ?? [],
|
||||
])
|
||||
->schema([
|
||||
Section::make('So geht das Angebot hinaus')->schema([
|
||||
Text::make(fn (Get $get): string => $this->offerPricePreview($get)),
|
||||
Text::make(fn (): string => 'Gast: '.$this->record->guestName().' · '.($this->record->guest?->email ?: 'keine E-Mail-Adresse')),
|
||||
Text::make(fn (): string => 'Vertragsvorlage: '.(OfferTerms::templateFor($this->record)?->label() ?? 'Texte der Webseite')),
|
||||
Textarea::make('offer_message')->label('Persönliche Nachricht an den Gast (optional)')->rows(3),
|
||||
]),
|
||||
Section::make('Anpassen')->description('Zeitraum, Preis, Vorlage, Gültigkeit, Angaben zum Gast')->collapsed()->schema([
|
||||
Section::make('Termin')->columns(3)->schema([
|
||||
DatePicker::make('arrival')->label('Anreise')->required()->live(onBlur: true),
|
||||
DatePicker::make('departure')->label('Abreise')->after('arrival')->required()->live(onBlur: true),
|
||||
TextInput::make('guests')->label('Personen')->integer()->minValue(1)->maxValue(fn (): int => $this->record->property->max_guests)->required()->live(onBlur: true),
|
||||
]),
|
||||
Section::make('Preis')->columns(3)->schema([
|
||||
TextInput::make('promo_code')->label('Rabattcode')->helperText('Sonderkondition aus den Angeboten')->maxLength(50)->live(onBlur: true),
|
||||
TextInput::make('price_adjustment')
|
||||
->label('Preisanpassung')
|
||||
->helperText('Minus = Nachlass, z. B. -50')
|
||||
->numeric()
|
||||
->step(0.01)
|
||||
->suffix('€')
|
||||
->live(onBlur: true),
|
||||
TextInput::make('promo_code')->label('Rabattcode')->maxLength(50)->live(onBlur: true),
|
||||
TextInput::make('price_adjustment')->label('Preisanpassung')->helperText('Minus = Nachlass, z. B. -50')->numeric()->step(0.01)->suffix('€')->live(onBlur: true),
|
||||
TextInput::make('price_adjustment_label')->label('Bezeichnung')->placeholder('Nachlass / Zuschlag')->maxLength(80),
|
||||
Text::make(fn (Get $get): string => $this->offerPricePreview($get))->columnSpanFull(),
|
||||
]),
|
||||
Section::make('Vertragsvorlage und Anlagen')->schema([
|
||||
Section::make('Vorlage und Anlagen')->schema([
|
||||
Select::make('contract_template_id')
|
||||
->label('Andere Vorlage für dieses Angebot')
|
||||
->options(fn (): array => ContractTemplate::query()->orderBy('name')->orderBy('version')->get()->mapWithKeys(fn (ContractTemplate $template): array => [$template->id => $template->label()])->all())
|
||||
->placeholder('wie eingestellt'),
|
||||
Select::make('annex_ids')
|
||||
->label('Anlagen')
|
||||
->multiple()
|
||||
->options(fn (): array => ContractAnnex::query()->orderBy('name')->orderBy('version')->get()->mapWithKeys(fn (ContractAnnex $annex): array => [$annex->id => $annex->label()])->all())
|
||||
->default(fn (): array => OfferTerms::templateFor($this->record)?->annexesFor($this->record)->pluck('id')->all() ?? [])
|
||||
->helperText('Vorausgewählt: Anlagen der Vorlage, deren Bedingung zu dieser Buchung passt (z. B. gebuchtes Wäschepaket). Sie können Anlagen hinzufügen oder entfernen.'),
|
||||
Select::make('contract_template_id')
|
||||
->label('Vorlage für dieses Angebot')
|
||||
->options(fn (): array => ContractTemplate::query()->orderBy('name')->orderBy('version')->get()->mapWithKeys(fn (ContractTemplate $template): array => [$template->id => $template->label()])->all())
|
||||
->placeholder('Standard (Portal / Wohnung / Webseite)')
|
||||
->helperText('Die Texte werden beim Versand fest im Angebot abgelegt.'),
|
||||
->default(fn (): array => OfferTerms::templateFor($this->record)?->annexesFor($this->record)->pluck('id')->all() ?? []),
|
||||
]),
|
||||
Section::make('Gültigkeit & Nachricht')->columns(2)->schema([
|
||||
DateTimePicker::make('valid_until')
|
||||
->label('Angebot gültig bis')
|
||||
->helperText(fn (): string => 'Standard: '.$this->record->property->hold_hours.' Stunden (Einstellung der Wohnung). Bis dahin bleibt der Zeitraum reserviert.')
|
||||
->seconds(false)
|
||||
->after('now')
|
||||
->required(),
|
||||
Textarea::make('offer_message')->label('Persönliche Nachricht an den Gast (optional)')->rows(3),
|
||||
]),
|
||||
Section::make('Gast – so erscheint er im Mietvertrag')->columns(2)->collapsed()->schema([
|
||||
DateTimePicker::make('valid_until')
|
||||
->label('Angebot gültig bis')
|
||||
->helperText(fn (): string => 'Eingestellt: '.$this->record->process()->holdHours().' Stunden. Bis dahin bleibt der Zeitraum reserviert.')
|
||||
->seconds(false)
|
||||
->after('now')
|
||||
->required(),
|
||||
Section::make('Gast – so erscheint er im Vertrag')->columns(2)->schema([
|
||||
TextInput::make('guest.first_name')->label('Vorname')->required()->maxLength(100),
|
||||
TextInput::make('guest.last_name')->label('Nachname')->required()->maxLength(100),
|
||||
TextInput::make('guest.street')->label('Straße und Hausnummer')->maxLength(150),
|
||||
@@ -126,246 +182,346 @@ protected function getHeaderActions(): array
|
||||
TextInput::make('guest.city')->label('Ort')->maxLength(100),
|
||||
TextInput::make('guest.phone')->label('Telefon')->maxLength(50),
|
||||
]),
|
||||
])
|
||||
->action(fn (array $data, SendOffer $send) => $this->runWorkflow(
|
||||
fn () => $send->handle($this->record, $this->offerChanges($data)),
|
||||
'Angebot gesendet',
|
||||
)),
|
||||
Action::make('provideContact')
|
||||
->label('Kontaktdaten eintragen')
|
||||
->icon(Heroicon::OutlinedUserPlus)
|
||||
->color(fn (): string => blank($this->record->guest?->email) ? 'warning' : 'gray')
|
||||
->visible(fn (): bool => ! in_array($this->record->status, [BookingStatus::Cancelled, BookingStatus::Declined, BookingStatus::Expired], true))
|
||||
->modalHeading('Kontaktdaten des Gastes')
|
||||
->modalDescription('Kontaktdaten aus Portalnachricht, E-Mail oder Telefonat. Danach kann der Vertragsprozess automatisch weiterlaufen oder von Hand fortgeführt werden.')
|
||||
->modalWidth('3xl')
|
||||
->fillForm(fn (): array => ['guest' => $this->record->guest->only(['first_name', 'last_name', 'email', 'phone', 'street', 'postal_code', 'city']), 'process' => ProvideGuestContact::MANUAL, 'guest_confirmed' => $this->record->guest_confirmed_at !== null])
|
||||
->schema([
|
||||
Section::make('Gast')->columns(2)->schema([
|
||||
TextInput::make('guest.first_name')->label('Vorname')->required()->maxLength(100),
|
||||
TextInput::make('guest.last_name')->label('Nachname')->required()->maxLength(100),
|
||||
TextInput::make('guest.email')->label('E-Mail')->email()->maxLength(255),
|
||||
TextInput::make('guest.phone')->label('Telefon')->tel()->maxLength(50),
|
||||
TextInput::make('guest.street')->label('Straße und Hausnummer')->maxLength(150),
|
||||
TextInput::make('guest.postal_code')->label('PLZ')->maxLength(20),
|
||||
TextInput::make('guest.city')->label('Ort')->maxLength(100),
|
||||
]),
|
||||
Section::make('Wie geht es weiter?')->schema([
|
||||
Radio::make('process')->hiddenLabel()->options([
|
||||
ProvideGuestContact::MANUAL => 'Nur speichern – den Vertragsprozess führe ich von Hand weiter',
|
||||
ProvideGuestContact::AUTOMATIC => 'Automatisch weiter: Portal-Buchung → Bestätigung und Vertrag per E-Mail, Anfrage → Angebot per E-Mail',
|
||||
])->required(),
|
||||
Toggle::make('guest_confirmed')->label('Der Gast hat die Buchung per E-Mail bestätigt'),
|
||||
]),
|
||||
])
|
||||
->action(function (array $data, ProvideGuestContact $provide): void {
|
||||
try {
|
||||
$message = $provide->handle($this->record, $data['guest'], $data['process'], (bool) $data['guest_confirmed']);
|
||||
} catch (ReservationException|QuoteException $exception) {
|
||||
Notification::make()->title('Nicht möglich')->body($exception->getMessage())->danger()->send();
|
||||
|
||||
return;
|
||||
}
|
||||
]),
|
||||
])
|
||||
->action(fn (array $data, SendOffer $send) => $this->runWorkflow(fn () => $send->handle($this->record, $this->offerChanges($data)), 'Angebot gesendet'));
|
||||
}
|
||||
|
||||
private function provideContactAction(): Action
|
||||
{
|
||||
return Action::make('provideContact')
|
||||
->label(fn (): string => $this->record->guest === null ? 'Gast eintragen' : 'Kontaktdaten eintragen')
|
||||
->icon(Heroicon::OutlinedUserPlus)
|
||||
->visible(fn (): bool => ! in_array($this->record->status, [BookingStatus::Cancelled, BookingStatus::Declined, BookingStatus::Expired], true))
|
||||
->modalHeading('Kontaktdaten des Gastes')
|
||||
->modalDescription('Aus Portalnachricht, E-Mail oder Telefonat. Nur eintragen, was bekannt ist.')
|
||||
->modalWidth('3xl')
|
||||
->fillForm(fn (): array => [
|
||||
'guest' => $this->record->guest?->only(['first_name', 'last_name', 'email', 'phone', 'street', 'postal_code', 'city']) ?? [],
|
||||
'process' => $this->record->processingMode() === ProcessingMode::Automatic ? ProvideGuestContact::AUTOMATIC : ProvideGuestContact::MANUAL,
|
||||
'guest_confirmed' => $this->record->guest_confirmed_at !== null,
|
||||
])
|
||||
->schema([
|
||||
Section::make('Gast')->columns(2)->schema([
|
||||
TextInput::make('guest.first_name')->label('Vorname')->required()->maxLength(100),
|
||||
TextInput::make('guest.last_name')->label('Nachname')->required()->maxLength(100),
|
||||
TextInput::make('guest.email')->label('E-Mail')->email()->maxLength(255),
|
||||
TextInput::make('guest.phone')->label('Telefon')->tel()->maxLength(50),
|
||||
TextInput::make('guest.street')->label('Straße und Hausnummer')->maxLength(150),
|
||||
TextInput::make('guest.postal_code')->label('PLZ')->maxLength(20),
|
||||
TextInput::make('guest.city')->label('Ort')->maxLength(100),
|
||||
]),
|
||||
Section::make('Wie geht es danach weiter?')->schema([
|
||||
Radio::make('process')->hiddenLabel()->options([
|
||||
ProvideGuestContact::AUTOMATIC => 'Automatisch weitermachen – das System sendet als Nächstes Angebot bzw. Unterlagen',
|
||||
ProvideGuestContact::MANUAL => 'Nur speichern – den nächsten Schritt gebe ich selbst frei',
|
||||
])->required(),
|
||||
Toggle::make('guest_confirmed')->label('Der Gast hat die Buchung per E-Mail bestätigt'),
|
||||
]),
|
||||
])
|
||||
->action(function (array $data, ProvideGuestContact $provide): void {
|
||||
try {
|
||||
$message = $provide->handle($this->record, $data['guest'], $data['process'], (bool) $data['guest_confirmed']);
|
||||
} catch (ReservationException|QuoteException $exception) {
|
||||
$this->record->refresh();
|
||||
Notification::make()->title($message)->success()->send();
|
||||
}),
|
||||
Action::make('requestContact')
|
||||
->label('Gast um Kontaktdaten bitten')
|
||||
->icon(Heroicon::OutlinedChatBubbleLeftEllipsis)
|
||||
->color('gray')
|
||||
->visible(fn (): bool => blank($this->record->guest?->email) && ! in_array($this->record->status, [BookingStatus::Cancelled, BookingStatus::Declined, BookingStatus::Expired], true))
|
||||
->modalHeading('Gast um Kontaktdaten bitten')
|
||||
->modalDescription('Der Text lässt sich im Nachrichtenfenster des Portals einfügen (Sie senden ihn selbst). Mit „Als angefragt vermerken“ merkt sich die Buchungsakte, dass die Kontaktdaten erfragt wurden.')
|
||||
->modalSubmitActionLabel('Als angefragt vermerken')
|
||||
->fillForm(fn (): array => ['text' => $this->contactRequestText()])
|
||||
->schema([
|
||||
Textarea::make('text')->label('Nachricht an den Gast')->rows(10)->extraInputAttributes(['readonly' => true, 'onclick' => 'this.select()']),
|
||||
])
|
||||
->action(function (): void {
|
||||
$this->record->forceFill(['contact_requested_at' => now()])->saveQuietly();
|
||||
Notification::make()->title('Als angefragt vermerkt')->success()->send();
|
||||
}),
|
||||
Action::make('offerLink')
|
||||
->label('Angebotslink')
|
||||
->icon(Heroicon::OutlinedLink)
|
||||
->color('gray')
|
||||
->visible(fn (): bool => $this->record->status === BookingStatus::OfferSent && $this->record->hold_expires_at?->isFuture())
|
||||
->modalHeading('Link zum Angebot')
|
||||
->modalDescription('Derselbe Link wie in der Angebots-E-Mail – z. B. zum Weitergeben per Messenger. Gültig bis zum Ende der Angebotsfrist.')
|
||||
->schema([
|
||||
TextInput::make('url')->label('Link')->default(fn (SendOffer $send): string => $send->offerUrl($this->record))->readOnly()->copyable(),
|
||||
])
|
||||
->modalSubmitAction(false)
|
||||
->modalCancelActionLabel('Schließen'),
|
||||
Action::make('offerPdf')
|
||||
->label('Angebot (PDF)')
|
||||
->icon(Heroicon::OutlinedDocumentText)
|
||||
->color('gray')
|
||||
->visible(fn (): bool => $this->record->status === BookingStatus::OfferSent && $this->record->offer_path !== null)
|
||||
->action(fn (RentalContract $contract) => response()->download($contract->absolutePath($this->record, draft: true) ?? abort(404), "Angebot-{$this->record->reference}.pdf")),
|
||||
Action::make('confirm')
|
||||
->label('Direkt bestätigen')
|
||||
->icon(Heroicon::OutlinedCheckCircle)
|
||||
->color('gray')
|
||||
->visible(fn (): bool => in_array($this->record->status, [BookingStatus::Reserved, BookingStatus::OfferSent, BookingStatus::Expired], true))
|
||||
->requiresConfirmation()
|
||||
->modalHeading('Buchung direkt bestätigen')
|
||||
->modalDescription('Ohne Angebot und Annahme durch den Gast – nur wenn die Buchung bereits anders verbindlich vereinbart wurde (z. B. telefonisch). Die Buchung wird verbindlich und der Zeitraum dauerhaft belegt.')
|
||||
->schema([
|
||||
Toggle::make('notify')->label('Buchungsbestätigung an den Gast senden')->default(true),
|
||||
])
|
||||
->action(fn (array $data, ConfirmBooking $confirm) => $this->runWorkflow(
|
||||
fn () => $confirm->handle($this->record, $data['notify']),
|
||||
'Buchung bestätigt',
|
||||
)),
|
||||
Action::make('decline')
|
||||
->label('Ablehnen')
|
||||
->icon(Heroicon::OutlinedXCircle)
|
||||
->color('danger')
|
||||
->visible(fn (): bool => in_array($this->record->status, [BookingStatus::Reserved, BookingStatus::OfferSent, BookingStatus::Expired], true))
|
||||
->requiresConfirmation()
|
||||
->modalHeading('Anfrage ablehnen')
|
||||
->schema([
|
||||
Toggle::make('notify')->label('Absage an den Gast senden')->default(true),
|
||||
])
|
||||
->action(fn (array $data, DeclineBooking $decline) => $this->runWorkflow(
|
||||
fn () => $decline->handle($this->record, $data['notify']),
|
||||
'Anfrage abgelehnt',
|
||||
)),
|
||||
Action::make('extendHold')
|
||||
->label('Vormerkung verlängern')
|
||||
->icon(Heroicon::OutlinedClock)
|
||||
->color('gray')
|
||||
->visible(fn (): bool => in_array($this->record->status, BookingStatus::holding(), true))
|
||||
->schema([
|
||||
TextInput::make('hours')->label('Um')->integer()->minValue(1)->default(24)->suffix('Stunden')->required(),
|
||||
])
|
||||
->action(function (array $data): void {
|
||||
$from = $this->record->hold_expires_at?->isFuture() ? $this->record->hold_expires_at : now()->toImmutable();
|
||||
$this->record->update(['hold_expires_at' => $from->addHours((int) $data['hours'])]);
|
||||
Notification::make()->title('Nicht möglich')->body($exception->getMessage())->danger()->send();
|
||||
|
||||
Notification::make()->title('Vorgemerkt bis '.$this->record->hold_expires_at->format('d.m.Y, H:i'))->success()->send();
|
||||
}),
|
||||
Action::make('resendConfirmation')
|
||||
->label(fn (): string => $this->record->confirmation_failed_at !== null ? 'Bestätigung erneut senden (Versand fehlgeschlagen)' : 'Bestätigung erneut senden')
|
||||
->icon(Heroicon::OutlinedEnvelope)
|
||||
->color(fn (): string => $this->record->confirmation_failed_at !== null ? 'danger' : 'gray')
|
||||
->visible(fn (): bool => in_array($this->record->status, BookingStatus::occupying(), true))
|
||||
->requiresConfirmation()
|
||||
->modalDescription('Die Buchungsbestätigung mit dem Mietvertrag wird noch einmal an den Gast gesendet.')
|
||||
->action(function (ConfirmBooking $confirm): void {
|
||||
$sent = $confirm->resend($this->record->fresh());
|
||||
$notification = Notification::make()->title($sent ? 'Bestätigung gesendet' : 'Versand fehlgeschlagen');
|
||||
($sent ? $notification->success() : $notification->danger()->body('Details im Postfach.'))->send();
|
||||
}),
|
||||
Action::make('services')
|
||||
->label('Zusatzleistungen erfassen')
|
||||
->icon(Heroicon::OutlinedPlusCircle)
|
||||
->color('gray')
|
||||
->visible(fn (): bool => ! in_array($this->record->status, [BookingStatus::Cancelled, BookingStatus::Declined, BookingStatus::Expired, BookingStatus::Completed], true))
|
||||
->modalDescription('Gebuchte Zusatzleistungen (kostenpflichtig oder kostenlos), z. B. aus einer Portalbuchung oder per E-Mail erfragt. Sie bestimmen, welche Vertragsanlagen angehängt werden. Der Preis der Buchung wird dadurch nicht verändert.')
|
||||
->fillForm(fn (): array => ['items' => collect((array) $this->record->extras)->map(fn ($quantity, $id): array => ['extra_id' => (int) $id, 'quantity' => (int) $quantity])->values()->all()])
|
||||
->schema([
|
||||
Repeater::make('items')
|
||||
->label('Leistungen')
|
||||
->schema([
|
||||
Select::make('extra_id')->label('Leistung')->options(fn (): array => Extra::query()->orderBy('name')->get()->mapWithKeys(fn (Extra $extra): array => [$extra->id => $extra->name.($extra->price > 0 ? ' ('.Money::format($extra->price).')' : ' (kostenlos)')])->all())->required(),
|
||||
TextInput::make('quantity')->label('Menge')->integer()->minValue(1)->default(1)->required(),
|
||||
])
|
||||
->columns(2)
|
||||
->addActionLabel('Leistung hinzufügen'),
|
||||
])
|
||||
->action(function (array $data): void {
|
||||
$extras = [];
|
||||
foreach ((array) ($data['items'] ?? []) as $item) {
|
||||
$extras[(int) $item['extra_id']] = ((int) ($extras[(int) $item['extra_id']] ?? 0)) + max(1, (int) $item['quantity']);
|
||||
}
|
||||
$this->record->update(['extras' => $extras]);
|
||||
Notification::make()->title('Zusatzleistungen gespeichert')->success()->send();
|
||||
}),
|
||||
Action::make('contractText')
|
||||
->label('Vertragstext ansehen')
|
||||
->icon(Heroicon::OutlinedDocumentMagnifyingGlass)
|
||||
->color('gray')
|
||||
->visible(fn (): bool => $this->record->offer_terms !== null)
|
||||
->modalHeading(fn (): string => 'Vertrag '.$this->record->reference)
|
||||
->modalContent(fn () => view('filament.booking-contract', ['booking' => $this->record]))
|
||||
->modalSubmitAction(false)
|
||||
->modalCancelActionLabel('Schließen')
|
||||
->modalWidth('4xl'),
|
||||
Action::make('contract')
|
||||
->label('Mietvertrag')
|
||||
->icon(Heroicon::OutlinedDocumentText)
|
||||
->color('gray')
|
||||
->visible(fn (): bool => $this->record->contract_path !== null)
|
||||
->action(fn (RentalContract $contract) => response()->download($contract->absolutePath($this->record) ?? abort(404), "Mietvertrag-{$this->record->reference}.pdf")),
|
||||
ActionGroup::make([
|
||||
Action::make('notes')
|
||||
->label('Interne Notiz bearbeiten')
|
||||
->icon(Heroicon::OutlinedPencilSquare)
|
||||
->fillForm(fn (): array => ['internal_notes' => $this->record->internal_notes])
|
||||
return;
|
||||
}
|
||||
|
||||
$this->record->refresh();
|
||||
Notification::make()->title($message)->success()->send();
|
||||
});
|
||||
}
|
||||
|
||||
private function requestContactAction(): Action
|
||||
{
|
||||
return Action::make('requestContact')
|
||||
->label('Gast um Kontaktdaten bitten')
|
||||
->icon(Heroicon::OutlinedChatBubbleLeftEllipsis)
|
||||
->visible(fn (): bool => blank($this->record->guest?->email) && ! in_array($this->record->status, [BookingStatus::Cancelled, BookingStatus::Declined, BookingStatus::Expired], true))
|
||||
->modalHeading('Gast um Kontaktdaten bitten')
|
||||
->modalDescription('Den Text im Nachrichtenfenster des Portals einfügen (Sie senden ihn selbst). „Als angefragt vermerken“ hält fest, dass die Daten erfragt sind.')
|
||||
->modalSubmitActionLabel('Als angefragt vermerken')
|
||||
->fillForm(fn (): array => ['text' => $this->contactRequestText()])
|
||||
->schema([Textarea::make('text')->label('Nachricht an den Gast')->rows(10)->extraInputAttributes(['readonly' => true, 'onclick' => 'this.select()'])])
|
||||
->action(function (): void {
|
||||
$this->record->forceFill(['contact_requested_at' => now()])->save();
|
||||
Notification::make()->title('Als angefragt vermerkt')->success()->send();
|
||||
});
|
||||
}
|
||||
|
||||
private function confirmAction(): Action
|
||||
{
|
||||
return Action::make('confirm')
|
||||
->label('Direkt verbindlich bestätigen')
|
||||
->icon(Heroicon::OutlinedCheckCircle)
|
||||
->visible(fn (): bool => in_array($this->record->status, [BookingStatus::Reserved, BookingStatus::OfferSent, BookingStatus::Expired], true))
|
||||
->requiresConfirmation()
|
||||
->modalHeading('Buchung direkt bestätigen')
|
||||
->modalDescription('Ohne Angebot und Annahme durch den Gast – nur wenn die Buchung schon anders verbindlich vereinbart wurde (z. B. am Telefon). Der Zeitraum wird fest belegt.')
|
||||
->schema([Toggle::make('notify')->label('Buchungsbestätigung an den Gast senden')->default(fn (): bool => filled($this->record->guest?->email))])
|
||||
->action(fn (array $data, ConfirmBooking $confirm) => $this->runWorkflow(fn () => $confirm->handle($this->record, $data['notify']), 'Buchung bestätigt'));
|
||||
}
|
||||
|
||||
private function resendConfirmationAction(): Action
|
||||
{
|
||||
return Action::make('resendConfirmation')
|
||||
->label(fn (): string => match (true) {
|
||||
$this->record->confirmation_failed_at !== null && $this->record->confirmation_sent_at === null => 'Unterlagen erneut senden (Versand fehlgeschlagen)',
|
||||
$this->record->confirmation_sent_at === null => 'Unterlagen an den Gast senden',
|
||||
default => 'Bestätigung erneut senden',
|
||||
})
|
||||
->icon(Heroicon::OutlinedEnvelope)
|
||||
->visible(fn (): bool => $this->record->isBinding() && filled($this->record->guest?->email))
|
||||
->requiresConfirmation()
|
||||
->modalDescription(fn (): string => 'Der Gast erhält die Buchungsbestätigung mit dem Vertrag (Vorlage: '.(OfferTerms::templateFor($this->record)?->label() ?? 'Texte der Webseite').').')
|
||||
->action(function (ConfirmBooking $confirm): void {
|
||||
$missing = app(CaseAutomation::class)->documentBlockers($this->record);
|
||||
if ($missing !== []) {
|
||||
Notification::make()->title('Noch nicht möglich')->body(implode(' ', $missing))->warning()->send();
|
||||
|
||||
return;
|
||||
}
|
||||
$sent = $confirm->resend($this->record->fresh());
|
||||
$this->record->refresh();
|
||||
$notification = Notification::make()->title($sent ? 'Unterlagen gesendet' : 'Versand fehlgeschlagen');
|
||||
($sent ? $notification->success() : $notification->danger()->body('Details im Postfach.'))->send();
|
||||
});
|
||||
}
|
||||
|
||||
private function portalPriceAction(): Action
|
||||
{
|
||||
return Action::make('portalPrice')
|
||||
->label('Gesamtpreis laut Portal eintragen')
|
||||
->icon(Heroicon::OutlinedCurrencyEuro)
|
||||
->visible(fn (): bool => $this->record->intake === IntakeKind::Booking && ! in_array($this->record->status, [BookingStatus::Cancelled, BookingStatus::Declined], true))
|
||||
->modalDescription('Der Betrag, den der Gast beim Portal gebucht hat (Gesamtpreis). Er wird so übernommen und nicht in eigene Positionen zerlegt.')
|
||||
->fillForm(fn (): array => ['portal_total' => $this->record->total, 'guests' => $this->record->guests])
|
||||
->schema([
|
||||
EuroInput::make('portal_total')->label('Gesamtpreis laut Portal')->required(),
|
||||
TextInput::make('guests')->label('Personen (falls bekannt)')->integer()->minValue(1),
|
||||
])
|
||||
->action(function (array $data, PortalPrice $price): void {
|
||||
$guests = filled($data['guests'] ?? null) ? (int) $data['guests'] : $this->record->guests;
|
||||
$this->record->update(['guests' => $guests, ...$price->columns($this->record->property, $this->record->arrival, $this->record->departure, $guests, (int) $data['portal_total'], $this->record->processChannel()?->name)]);
|
||||
CaseLog::record($this->record, 'price', 'Gesamtpreis laut Portal eingetragen: '.Money::format((int) $data['portal_total']));
|
||||
$blockers = app(CaseAutomation::class)->advance($this->record->fresh());
|
||||
$this->record->refresh();
|
||||
Notification::make()->title('Preis gespeichert')->body($blockers === [] ? null : implode(' ', $blockers))->success()->send();
|
||||
});
|
||||
}
|
||||
|
||||
private function extendHoldAction(): Action
|
||||
{
|
||||
return Action::make('extendHold')
|
||||
->label('Reservierung verlängern')
|
||||
->icon(Heroicon::OutlinedClock)
|
||||
->visible(fn (): bool => in_array($this->record->status, BookingStatus::holding(), true))
|
||||
->schema([TextInput::make('hours')->label('Um')->integer()->minValue(1)->default(24)->suffix('Stunden')->required()])
|
||||
->action(function (array $data): void {
|
||||
$from = $this->record->hold_expires_at?->isFuture() ? $this->record->hold_expires_at : now()->toImmutable();
|
||||
$this->record->update(['hold_expires_at' => $from->addHours((int) $data['hours'])]);
|
||||
Notification::make()->title('Reserviert bis '.$this->record->hold_expires_at->format('d.m.Y, H:i'))->success()->send();
|
||||
});
|
||||
}
|
||||
|
||||
private function servicesAction(): Action
|
||||
{
|
||||
return Action::make('services')
|
||||
->label('Zusatzleistungen erfassen')
|
||||
->icon(Heroicon::OutlinedPlusCircle)
|
||||
->visible(fn (): bool => ! in_array($this->record->status, [BookingStatus::Cancelled, BookingStatus::Declined, BookingStatus::Expired, BookingStatus::Completed], true))
|
||||
->modalDescription('Gebuchte Zusatzleistungen (z. B. aus einer Portalbuchung). Sie bestimmen, welche Vertragsanlagen angehängt werden. Der Preis ändert sich dadurch nicht.')
|
||||
->fillForm(fn (): array => ['items' => collect((array) $this->record->extras)->map(fn ($quantity, $id): array => ['extra_id' => (int) $id, 'quantity' => (int) $quantity])->values()->all()])
|
||||
->schema([
|
||||
Repeater::make('items')
|
||||
->label('Leistungen')
|
||||
->schema([
|
||||
Textarea::make('internal_notes')->label('Interne Notizen')->rows(6),
|
||||
Select::make('extra_id')->label('Leistung')->options(fn (): array => Extra::query()->orderBy('name')->get()->mapWithKeys(fn (Extra $extra): array => [$extra->id => $extra->name.($extra->price > 0 ? ' ('.Money::format($extra->price).')' : ' (kostenlos)')])->all())->required(),
|
||||
TextInput::make('quantity')->label('Menge')->integer()->minValue(1)->default(1)->required(),
|
||||
])
|
||||
->action(fn (array $data) => $this->record->update($data)),
|
||||
Action::make('setStatus')
|
||||
->label('Status von Hand ändern')
|
||||
->icon(Heroicon::OutlinedAdjustmentsHorizontal)
|
||||
->visible(fn (): bool => BookingProgress::kind($this->record) !== BookingProgress::OWN && $this->record->status !== BookingStatus::Declined)
|
||||
->modalHeading('Status von Hand ändern')
|
||||
->modalDescription('Für Buchungen, die das System nicht selbst weiterführt. Es werden keine E-Mails versendet. Wird die Buchung wieder verbindlich, prüft das System den Kalender. Stornieren und Ablehnen haben eigene Aktionen.')
|
||||
->schema([
|
||||
Select::make('status')->label('Neuer Status')->options(collect(SetBookingStatus::TARGETS)->mapWithKeys(fn (BookingStatus $status): array => [$status->value => $status->getLabel()])->all())->required(),
|
||||
Textarea::make('reason')->label('Grund / Anlass')->helperText('Wird in den internen Notizen festgehalten.')->required()->rows(2),
|
||||
])
|
||||
->action(function (array $data, SetBookingStatus $setStatus): void {
|
||||
try {
|
||||
$setStatus->handle($this->record, BookingStatus::from($data['status']), $data['reason'], auth()->user()->name);
|
||||
} catch (ReservationException $exception) {
|
||||
Notification::make()->title('Nicht möglich')->body($exception->getMessage())->danger()->send();
|
||||
->columns(2)
|
||||
->addActionLabel('Leistung hinzufügen'),
|
||||
])
|
||||
->action(function (array $data): void {
|
||||
$extras = [];
|
||||
foreach ((array) ($data['items'] ?? []) as $item) {
|
||||
$extras[(int) $item['extra_id']] = ((int) ($extras[(int) $item['extra_id']] ?? 0)) + max(1, (int) $item['quantity']);
|
||||
}
|
||||
$this->record->update(['extras' => $extras]);
|
||||
CaseLog::record($this->record, 'services', 'Zusatzleistungen erfasst');
|
||||
Notification::make()->title('Zusatzleistungen gespeichert')->success()->send();
|
||||
});
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
private function offerPdfAction(): Action
|
||||
{
|
||||
return Action::make('offerPdf')
|
||||
->label('Angebot (PDF)')
|
||||
->icon(Heroicon::OutlinedDocumentText)
|
||||
->visible(fn (): bool => $this->record->status === BookingStatus::OfferSent && $this->record->offer_path !== null)
|
||||
->action(fn (RentalContract $contract) => response()->download($contract->absolutePath($this->record, draft: true) ?? abort(404), "Angebot-{$this->record->reference}.pdf"));
|
||||
}
|
||||
|
||||
$this->record->refresh();
|
||||
Notification::make()->title('Status geändert')->success()->send();
|
||||
}),
|
||||
Action::make('archive')
|
||||
->label(fn (): string => $this->record->archived_at ? 'Aus dem Archiv holen' : 'Archivieren')
|
||||
->icon(Heroicon::OutlinedArchiveBox)
|
||||
->visible(fn (): bool => $this->record->archived_at !== null || $this->record->canBeArchived())
|
||||
->modalDescription(fn (): string => $this->record->archived_at ? 'Die Buchung erscheint wieder in der Liste.' : 'Die Buchung verschwindet aus der Standardliste. Verlauf, E-Mails, Zahlungen und Dokumente bleiben vollständig erhalten.')
|
||||
->requiresConfirmation()
|
||||
->action(function (): void {
|
||||
$this->record->update(['archived_at' => $this->record->archived_at ? null : now()]);
|
||||
Notification::make()->title($this->record->archived_at ? 'Archiviert' : 'Wieder aktiv')->success()->send();
|
||||
}),
|
||||
Action::make('cancel')
|
||||
->label('Stornieren')
|
||||
->icon(Heroicon::OutlinedNoSymbol)
|
||||
->color('danger')
|
||||
->visible(fn (): bool => in_array($this->record->status, BookingStatus::occupying(), true))
|
||||
->modalHeading('Buchung stornieren')
|
||||
->modalDescription('Der Zeitraum wird wieder freigegeben. Gast und Vermieter erhalten eine Stornierungs-E-Mail; die Stornokosten bleiben als Aufgabe offen.')
|
||||
->schema([
|
||||
Toggle::make('notify_guest')->label('Gast per E-Mail informieren')->default(true),
|
||||
Toggle::make('costs_task')->label('Aufgabe „Stornokosten prüfen“ anlegen')->default(true),
|
||||
])
|
||||
->action(function (array $data, CancelBooking $cancel): void {
|
||||
try {
|
||||
$informed = $cancel->handle($this->record, (bool) $data['notify_guest'], (bool) $data['costs_task'], auth()->user()->name);
|
||||
} catch (ReservationException $exception) {
|
||||
Notification::make()->title('Nicht möglich')->body($exception->getMessage())->danger()->send();
|
||||
private function contractAction(): Action
|
||||
{
|
||||
return Action::make('contract')
|
||||
->label('Mietvertrag (PDF)')
|
||||
->icon(Heroicon::OutlinedDocumentText)
|
||||
->visible(fn (): bool => $this->record->contract_path !== null)
|
||||
->action(fn (RentalContract $contract) => response()->download($contract->absolutePath($this->record) ?? abort(404), "Mietvertrag-{$this->record->reference}.pdf"));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
private function offerLinkAction(): Action
|
||||
{
|
||||
return Action::make('offerLink')
|
||||
->label('Angebotslink')
|
||||
->icon(Heroicon::OutlinedLink)
|
||||
->visible(fn (): bool => $this->record->status === BookingStatus::OfferSent && $this->record->hold_expires_at?->isFuture())
|
||||
->modalHeading('Link zum Angebot')
|
||||
->modalDescription('Derselbe Link wie in der Angebots-E-Mail. Gültig bis zum Ende der Angebotsfrist.')
|
||||
->schema([TextInput::make('url')->label('Link')->default(fn (SendOffer $send): string => $send->offerUrl($this->record))->readOnly()->copyable()])
|
||||
->modalSubmitAction(false)
|
||||
->modalCancelActionLabel('Schließen');
|
||||
}
|
||||
|
||||
$notification = Notification::make()->title('Buchung storniert');
|
||||
($informed ? $notification->success() : $notification->warning()->body('Die Mail an den Gast konnte nicht gesendet werden – bitte den Gast selbst informieren.'))->send();
|
||||
}),
|
||||
]),
|
||||
];
|
||||
private function contractTextAction(): Action
|
||||
{
|
||||
return Action::make('contractText')
|
||||
->label('Vertragstext ansehen')
|
||||
->icon(Heroicon::OutlinedDocumentMagnifyingGlass)
|
||||
->visible(fn (): bool => $this->record->offer_terms !== null)
|
||||
->modalHeading(fn (): string => 'Vertrag '.$this->record->reference)
|
||||
->modalContent(fn () => view('filament.booking-contract', ['booking' => $this->record]))
|
||||
->modalSubmitAction(false)
|
||||
->modalCancelActionLabel('Schließen')
|
||||
->modalWidth('4xl');
|
||||
}
|
||||
|
||||
private function notesAction(): Action
|
||||
{
|
||||
return Action::make('notes')
|
||||
->label('Interne Notiz bearbeiten')
|
||||
->icon(Heroicon::OutlinedPencilSquare)
|
||||
->fillForm(fn (): array => ['internal_notes' => $this->record->internal_notes])
|
||||
->schema([Textarea::make('internal_notes')->label('Interne Notizen')->rows(6)])
|
||||
->action(fn (array $data) => $this->record->update($data));
|
||||
}
|
||||
|
||||
private function archiveAction(): Action
|
||||
{
|
||||
return Action::make('archive')
|
||||
->label(fn (): string => $this->record->archived_at ? 'Aus dem Archiv holen' : 'Archivieren')
|
||||
->icon(Heroicon::OutlinedArchiveBox)
|
||||
->visible(fn (): bool => $this->record->archived_at !== null || $this->record->canBeArchived())
|
||||
->modalDescription(fn (): string => $this->record->archived_at ? 'Der Vorgang erscheint wieder in der Liste.' : 'Der Vorgang verschwindet aus der Standardliste. Verlauf, E-Mails, Zahlungen und Dokumente bleiben erhalten.')
|
||||
->requiresConfirmation()
|
||||
->action(function (): void {
|
||||
$this->record->update(['archived_at' => $this->record->archived_at ? null : now()]);
|
||||
Notification::make()->title($this->record->archived_at ? 'Archiviert' : 'Wieder aktiv')->success()->send();
|
||||
});
|
||||
}
|
||||
|
||||
private function setStatusAction(): Action
|
||||
{
|
||||
return Action::make('setStatus')
|
||||
->label('Status von Hand ändern')
|
||||
->icon(Heroicon::OutlinedAdjustmentsHorizontal)
|
||||
->visible(fn (): bool => $this->record->source !== 'website' && $this->record->status !== BookingStatus::Declined)
|
||||
->modalHeading('Status von Hand ändern (Experte)')
|
||||
->modalDescription('Nur für Korrekturen. Es werden keine E-Mails versendet; der Grund steht im Verlauf. Eine verbindliche Buchung kann so nicht beendet oder zur Anfrage gemacht werden – dafür gibt es „Beenden“.')
|
||||
->schema([
|
||||
Select::make('status')->label('Neuer Status')->options(collect(SetBookingStatus::TARGETS)->mapWithKeys(fn (BookingStatus $status): array => [$status->value => $status->getLabel()])->all())->required(),
|
||||
Textarea::make('reason')->label('Grund')->required()->rows(2),
|
||||
])
|
||||
->action(function (array $data, SetBookingStatus $setStatus): void {
|
||||
try {
|
||||
$setStatus->handle($this->record, BookingStatus::from($data['status']), $data['reason'], auth()->user()->name);
|
||||
} catch (ReservationException $exception) {
|
||||
Notification::make()->title('Nicht möglich')->body($exception->getMessage())->danger()->send();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->record->refresh();
|
||||
Notification::make()->title('Status geändert')->success()->send();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Automatic or manual handling of this case.
|
||||
*/
|
||||
private function automationAction(): ?Action
|
||||
{
|
||||
if (in_array($this->record->status, [BookingStatus::Cancelled, BookingStatus::Declined, BookingStatus::Expired, BookingStatus::Completed], true)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$automatic = $this->record->processingMode() === ProcessingMode::Automatic;
|
||||
|
||||
return Action::make('automation')
|
||||
->label($automatic ? 'Läuft automatisch' : 'Sie geben frei')
|
||||
->icon($automatic ? Heroicon::OutlinedBolt : Heroicon::OutlinedHandRaised)
|
||||
->color('gray')
|
||||
->tooltip($automatic ? 'Das System macht selbst weiter, sobald alle Angaben da sind.' : 'Das System bereitet alles vor; Sie geben jeden Schritt frei.')
|
||||
->modalHeading('Wie soll dieser Vorgang weiterlaufen?')
|
||||
->modalDescription('Gilt nur für diesen Vorgang. Ihre allgemeine Einstellung finden Sie unter „So arbeite ich“.')
|
||||
->fillForm(fn (): array => ['mode' => $this->record->processingMode()->value])
|
||||
->schema([Radio::make('mode')->hiddenLabel()->options(ProcessingMode::class)->required()])
|
||||
->action(function (array $data): void {
|
||||
$this->record->update(['processing_mode' => $data['mode'] instanceof ProcessingMode ? $data['mode'] : ProcessingMode::from($data['mode'])]);
|
||||
$blockers = app(CaseAutomation::class)->advance($this->record->fresh());
|
||||
$this->record->refresh();
|
||||
Notification::make()->title($this->record->processingMode()->getLabel())->body($blockers === [] ? null : 'Wartet auf: '.implode(' ', $blockers))->success()->send();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Ending a case: a request ends without booking; a binding booking is cancelled with its consequences (and on the
|
||||
* portal as well when the contract was made there). There is no way around it by changing the status.
|
||||
*/
|
||||
private function endAction(): ?Action
|
||||
{
|
||||
if (in_array($this->record->status, [BookingStatus::Cancelled, BookingStatus::Declined, BookingStatus::Expired, BookingStatus::Completed], true)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$binding = $this->record->isBinding();
|
||||
$hasEmail = filled($this->record->guest?->email);
|
||||
|
||||
return Action::make('end')
|
||||
->label($binding ? 'Stornieren …' : 'Beenden …')
|
||||
->icon(Heroicon::OutlinedStopCircle)
|
||||
->color('danger')
|
||||
->outlined()
|
||||
->modalHeading($binding ? 'Gebuchten Vorgang stornieren' : 'Vorgang ohne Buchung beenden')
|
||||
->modalDescription($binding
|
||||
? 'Die Buchung ist verbindlich. Sie wird storniert, der Zeitraum frei. Stornokosten nach der vereinbarten Regel bleiben als Aufgabe offen.'.($this->record->caseType()->isExternallyBinding() ? ' Gebucht wurde beim Portal – dafür entsteht zusätzlich die Aufgabe, die Stornierung dort zu veranlassen bzw. zu prüfen.' : '')
|
||||
: 'Es ist noch keine verbindliche Buchung zustande gekommen. Der reservierte Zeitraum wird wieder frei.')
|
||||
->modalSubmitActionLabel($binding ? 'Stornieren' : 'Beenden')
|
||||
->schema(array_values(array_filter([
|
||||
$binding ? Radio::make('initiated_by')->label('Wer storniert?')->options(['guest' => 'Der Gast', 'landlord' => 'Wir (Vermieter)'])->required() : null,
|
||||
Textarea::make('reason')->label('Grund')->required()->rows(2),
|
||||
Toggle::make('notify')->label('Den Gast per E-Mail informieren')->default($hasEmail)->disabled(! $hasEmail),
|
||||
$binding ? Toggle::make('costs_task')->label('Aufgabe „Stornokosten prüfen“ anlegen')->default(true) : null,
|
||||
])))
|
||||
->action(function (array $data, CancelBooking $cancel, DeclineBooking $decline) use ($binding, $hasEmail): void {
|
||||
$notify = $hasEmail && (bool) ($data['notify'] ?? false);
|
||||
try {
|
||||
$informed = CaseLog::context(fn () => $binding
|
||||
? $cancel->handle($this->record, $notify, (bool) ($data['costs_task'] ?? true), auth()->user()->name, $data['initiated_by'])
|
||||
: $decline->handle($this->record, $notify), reason: trim((string) $data['reason']));
|
||||
} catch (ReservationException $exception) {
|
||||
Notification::make()->title('Nicht möglich')->body($exception->getMessage())->danger()->send();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->record->refresh();
|
||||
$notification = Notification::make()->title($binding ? 'Buchung storniert' : 'Vorgang beendet');
|
||||
($informed === false ? $notification->warning()->body('Die Mail an den Gast konnte nicht gesendet werden – bitte selbst informieren.') : $notification->success())->send();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -375,8 +531,9 @@ private function contactRequestText(): string
|
||||
{
|
||||
$booking = $this->record;
|
||||
$landlord = config('fewo.owner.name') ?: config('app.name');
|
||||
$greeting = $booking->guest ? "Guten Tag {$booking->guest->first_name} {$booking->guest->last_name}," : 'Guten Tag,';
|
||||
|
||||
return "Guten Tag {$booking->guest->first_name} {$booking->guest->last_name},\n\n"
|
||||
return "{$greeting}\n\n"
|
||||
."vielen Dank für Ihre Buchung der {$booking->property->name} vom {$booking->arrival->format('d.m.Y')} bis {$booking->departure->format('d.m.Y')}. "
|
||||
."Für den Mietvertrag benötigen wir noch Ihre Kontaktdaten: vollständige Anschrift (Straße, PLZ, Ort), eine E-Mail-Adresse und eine Telefonnummer.\n\n"
|
||||
."Sobald wir die Angaben haben, senden wir Ihnen den Vertrag mit allen Informationen zu.\n\n"
|
||||
@@ -414,7 +571,7 @@ private function offerPricePreview(Get $get): string
|
||||
$adjustment = filled($get('price_adjustment')) ? max((int) round((float) $get('price_adjustment') * 100), -$quote->rent()) : 0;
|
||||
$promo = filled($get('promo_code')) ? ($quote->promoCodeApplied ? ' · Rabattcode angewendet' : ' · Rabattcode gilt hier nicht') : '';
|
||||
|
||||
return 'Gesamtpreis im Angebot: '.Money::format($quote->total() + $adjustment).' (bisher '.Money::format($this->record->total).')'.$promo;
|
||||
return 'Preis im Angebot: '.Money::format($quote->total() + $adjustment).' für '.$stay->arrival->format('d.m.').'–'.$stay->departure->format('d.m.Y').', '.$stay->guests.' Personen'.$promo;
|
||||
}
|
||||
|
||||
private function runWorkflow(callable $workflow, string $successTitle): void
|
||||
@@ -427,6 +584,7 @@ private function runWorkflow(callable $workflow, string $successTitle): void
|
||||
return;
|
||||
}
|
||||
|
||||
$this->record->refresh();
|
||||
Notification::make()->title($successTitle)->success()->send();
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
namespace App\Filament\Resources\Bookings\Schemas;
|
||||
|
||||
use App\Actions\RecordPortalBooking;
|
||||
use App\Filament\Forms\Components\EuroInput;
|
||||
use App\Filament\Resources\BlockedPeriods\BlockedPeriodResource;
|
||||
use App\Models\Channel;
|
||||
use App\Models\Property;
|
||||
use App\Support\CurrentProperty;
|
||||
@@ -14,21 +14,49 @@
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Components\Text;
|
||||
use Filament\Schemas\Components\Utilities\Get;
|
||||
use Filament\Schemas\Schema;
|
||||
use Illuminate\Support\HtmlString;
|
||||
|
||||
/**
|
||||
* Manual entry of a booking received by phone or e-mail, or made binding by a portal (e.g. FeWo-direkt, usually
|
||||
* without the guest's contact data). The price is calculated automatically; a portal price can be entered.
|
||||
* "Neu": one entry for everything that arrives outside the website. The first question is what it is – a request,
|
||||
* a booking already binding on a portal, or own use / a block – and only the fields that matter for that answer follow.
|
||||
* Nothing has to be invented: unknown guest data, number of guests or portal price stay empty.
|
||||
*/
|
||||
class BookingForm
|
||||
{
|
||||
public const INQUIRY = 'inquiry';
|
||||
|
||||
public const EXTERNAL = 'external';
|
||||
|
||||
public const OWN_USE = 'own_use';
|
||||
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
$is = fn (string $kind): \Closure => fn (Get $get): bool => $get('kind') === $kind;
|
||||
$isCase = fn (Get $get): bool => in_array($get('kind'), [self::INQUIRY, self::EXTERNAL], true);
|
||||
|
||||
return $schema
|
||||
->components([
|
||||
Section::make('Aufenthalt')
|
||||
Section::make('Was möchten Sie eintragen?')
|
||||
->schema([
|
||||
Radio::make('kind')
|
||||
->hiddenLabel()
|
||||
->options([
|
||||
self::INQUIRY => 'Eine Anfrage – per Telefon, E-Mail oder Nachricht über ein Portal',
|
||||
self::EXTERNAL => 'Eine Buchung, die bei einem Portal schon fest gebucht ist',
|
||||
self::OWN_USE => 'Eigene Nutzung oder eine Sperre (z. B. Wartung)',
|
||||
])
|
||||
->default(self::INQUIRY)
|
||||
->required()
|
||||
->live(),
|
||||
Text::make(new HtmlString('Eigene Nutzung und Sperren tragen Sie bis auf Weiteres unter <a class="underline" href="'.e(BlockedPeriodResource::getUrl()).'">Sperrzeiten</a> ein.'))
|
||||
->visible($is(self::OWN_USE)),
|
||||
]),
|
||||
Section::make('Zeitraum')
|
||||
->columns(2)
|
||||
->visible($isCase)
|
||||
->schema([
|
||||
Select::make('property_id')
|
||||
->label('Wohnung')
|
||||
@@ -40,58 +68,55 @@ public static function configure(Schema $schema): Schema
|
||||
->label('Personen')
|
||||
->integer()
|
||||
->minValue(1)
|
||||
->default(2)
|
||||
->required(),
|
||||
DatePicker::make('arrival')
|
||||
->label('Anreise')
|
||||
->required(),
|
||||
DatePicker::make('departure')
|
||||
->label('Abreise')
|
||||
->after('arrival')
|
||||
->required(),
|
||||
TextInput::make('promo_code')
|
||||
->label('Aktionscode'),
|
||||
->helperText(fn (Get $get): ?string => $get('kind') === self::EXTERNAL ? 'Leer lassen, wenn nicht bekannt.' : null)
|
||||
->required($is(self::INQUIRY)),
|
||||
DatePicker::make('arrival')->label('Anreise')->required(),
|
||||
DatePicker::make('departure')->label('Abreise')->after('arrival')->required(),
|
||||
]),
|
||||
Section::make('Buchungsweg')
|
||||
->description('Telefon oder E-Mail: nichts auswählen. Hat ein Portal die Buchung bereits verbindlich gemacht (z. B. FeWo-direkt), das Portal wählen – dann genügen Name und Zeitraum, die Kontaktdaten können später nachgetragen werden.')
|
||||
Section::make('Portal')
|
||||
->columns(2)
|
||||
->visible($isCase)
|
||||
->schema([
|
||||
Select::make('channel_id')
|
||||
->label('Über Portal')
|
||||
->placeholder('Direkt / telefonisch / per E-Mail')
|
||||
->label(fn (Get $get): string => $get('kind') === self::EXTERNAL ? 'Gebucht über' : 'Über ein Portal (optional)')
|
||||
->placeholder('Direkt – kein Portal')
|
||||
->options(fn (Get $get): array => Channel::query()->where('property_id', $get('property_id'))->orderBy('name')->pluck('name', 'id')->all())
|
||||
->live(),
|
||||
TextInput::make('portal_reference')->label('Referenz im Portal (Buchungsnummer)')->maxLength(100)->visible(fn (Get $get): bool => filled($get('channel_id'))),
|
||||
EuroInput::make('portal_total')->label('Preis laut Portal (Gesamtpreis, optional)')->helperText('Weicht er von unserer Berechnung ab, wird die Differenz als Zeile „Abweichung Portalpreis“ geführt.')->visible(fn (Get $get): bool => filled($get('channel_id'))),
|
||||
->required($is(self::EXTERNAL)),
|
||||
TextInput::make('portal_reference')->label('Buchungsnummer im Portal')->maxLength(100)->visible($is(self::EXTERNAL)),
|
||||
EuroInput::make('portal_total')
|
||||
->label('Gesamtpreis laut Portal')
|
||||
->helperText('Der Betrag, den der Gast beim Portal gebucht hat. Leer lassen, wenn noch nicht bekannt – er wird nicht geschätzt.')
|
||||
->visible($is(self::EXTERNAL)),
|
||||
]),
|
||||
Section::make('Gast')
|
||||
->description(fn (Get $get): ?string => filled($get('channel_id')) ? 'Bei Portalbuchungen ohne Kontaktdaten genügt der Name – E-Mail und Adresse können später ergänzt werden.' : null)
|
||||
->description('Nur eintragen, was bekannt ist. Fehlendes wird später ergänzt; das System erinnert daran.')
|
||||
->columns(2)
|
||||
->visible($isCase)
|
||||
->schema([
|
||||
TextInput::make('first_name')->label('Vorname')->required()->maxLength(255),
|
||||
TextInput::make('last_name')->label('Nachname')->required()->maxLength(255),
|
||||
TextInput::make('email')->label('E-Mail')->email()->required(fn (Get $get): bool => blank($get('channel_id')))->maxLength(255),
|
||||
TextInput::make('first_name')->label('Vorname')->required($is(self::INQUIRY))->maxLength(255),
|
||||
TextInput::make('last_name')->label('Nachname')->required($is(self::INQUIRY))->maxLength(255),
|
||||
TextInput::make('email')->label('E-Mail')->email()->maxLength(255),
|
||||
TextInput::make('phone')->label('Telefon')->tel()->maxLength(50),
|
||||
TextInput::make('street')->label('Straße')->maxLength(255),
|
||||
TextInput::make('postal_code')->label('PLZ')->maxLength(20),
|
||||
TextInput::make('city')->label('Ort')->maxLength(255),
|
||||
Toggle::make('guest_confirmed')->label('Der Gast hat die Buchung bereits per E-Mail bestätigt')->visible($is(self::EXTERNAL)),
|
||||
]),
|
||||
Section::make('Abschluss')
|
||||
Section::make('Wie geht es weiter?')
|
||||
->visible($is(self::INQUIRY))
|
||||
->schema([
|
||||
Textarea::make('internal_notes')->label('Interne Notiz'),
|
||||
Toggle::make('confirm_immediately')->label('Sofort verbindlich bestätigen')->default(true)->visible(fn (Get $get): bool => blank($get('channel_id'))),
|
||||
Toggle::make('send_mails')->label('E-Mails an den Gast senden')->default(false)->visible(fn (Get $get): bool => blank($get('channel_id'))),
|
||||
Radio::make('portal_process')
|
||||
->label('Wie geht der Vertragsprozess weiter?')
|
||||
->options([
|
||||
RecordPortalBooking::CONFIRM => 'Buchung bestätigen (Zeitraum belegen), Vertrag später – sobald die Kontaktdaten da sind',
|
||||
RecordPortalBooking::CONTRACT => 'Buchung bestätigen und Vertrag jetzt per E-Mail senden (E-Mail-Adresse nötig)',
|
||||
RecordPortalBooking::RECORD => 'Nur als Anfrage erfassen – alles Weitere von Hand',
|
||||
])
|
||||
->default(RecordPortalBooking::CONFIRM)
|
||||
->required(fn (Get $get): bool => filled($get('channel_id')))
|
||||
->visible(fn (Get $get): bool => filled($get('channel_id'))),
|
||||
Toggle::make('guest_confirmed')->label('Der Gast hat die Buchung bereits per E-Mail bestätigt')->visible(fn (Get $get): bool => filled($get('channel_id'))),
|
||||
Toggle::make('confirm_immediately')
|
||||
->label('Die Buchung ist mit dem Gast schon fest vereinbart – gleich verbindlich eintragen')
|
||||
->helperText('Aus: Das System bereitet das Angebot vor; je nach Einstellung geht es automatisch hinaus oder wartet auf Ihre Freigabe.')
|
||||
->default(false),
|
||||
Toggle::make('send_mails')->label('Dem Gast E-Mails senden (Eingangsbestätigung bzw. Buchungsbestätigung)')->default(true),
|
||||
TextInput::make('promo_code')->label('Aktionscode')->maxLength(50),
|
||||
]),
|
||||
Section::make('Notiz')
|
||||
->visible($isCase)
|
||||
->collapsed()
|
||||
->schema([
|
||||
Textarea::make('internal_notes')->hiddenLabel()->placeholder('Interne Notiz (nur für Sie sichtbar)'),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -3,8 +3,16 @@
|
||||
namespace App\Filament\Resources\Bookings\Schemas;
|
||||
|
||||
use App\Documents\OfferTerms;
|
||||
use App\Enums\ActivityState;
|
||||
use App\Enums\AdminMode;
|
||||
use App\Enums\ProcessingMode;
|
||||
use App\Enums\ProcessSetting;
|
||||
use App\Enums\Responsibility;
|
||||
use App\Models\Booking;
|
||||
use App\Support\BookingProgress;
|
||||
use App\Models\User;
|
||||
use App\Process\CaseActivities;
|
||||
use App\Process\CaseAutomation;
|
||||
use App\Process\ProcessProfile;
|
||||
use App\Support\Money;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Filament\Infolists\Components\RepeatableEntry;
|
||||
@@ -15,189 +23,194 @@
|
||||
use Filament\Schemas\Schema;
|
||||
use Illuminate\Support\HtmlString;
|
||||
|
||||
/**
|
||||
* The case page: first where it stands and what is next, then the activities and the history, then the facts (guest,
|
||||
* stay, price and payments, documents). Technical details are shown in the expert view only.
|
||||
*/
|
||||
class BookingInfolist
|
||||
{
|
||||
/**
|
||||
* The process as a checklist: every milestone with its state and the activities that belong to it. Open
|
||||
* activities name the action on this page that does them.
|
||||
*/
|
||||
private static function timeline(Booking $booking): HtmlString
|
||||
{
|
||||
$badge = [
|
||||
'done' => ['✓', '#16a34a', 'erledigt'],
|
||||
'current' => ['●', '#d97706', 'jetzt'],
|
||||
'todo' => ['○', '#9ca3af', 'später'],
|
||||
'skipped' => ['–', '#9ca3af', 'entfällt'],
|
||||
];
|
||||
|
||||
$rows = collect(BookingProgress::steps($booking))->map(function (array $step) use ($badge): string {
|
||||
[$icon, $color, $word] = $badge[$step['state']];
|
||||
$activities = collect($step['activities'])->map(fn (array $activity): string => '<li style="margin:.15rem 0;'.($activity['done'] ? 'color:#15803d' : '').'">'.($activity['done'] ? '✓ ' : '○ ').e($activity['label']).($activity['action'] && $step['state'] !== 'skipped' ? ' <span style="color:#b45309">→ Aktion „'.e($activity['action']).'“</span>' : '').'</li>')->implode('');
|
||||
|
||||
return '<div style="display:flex;gap:.75rem;padding:.55rem 0;border-bottom:1px solid rgba(128,128,128,.25)">'
|
||||
.'<div style="width:1.6rem;text-align:center;font-weight:700;color:'.$color.'" title="'.$word.'">'.$icon.'</div>'
|
||||
.'<div style="flex:1"><div style="'.($step['state'] === 'current' ? 'font-weight:700' : '').($step['state'] === 'skipped' ? ';color:#9ca3af' : '').'">'.e($step['label']).($step['detail'] ? ' <span style="font-weight:400;color:#6b7280">· '.e($step['detail']).'</span>' : '').'</div>'
|
||||
.($activities !== '' ? '<ul style="list-style:none;padding:0;margin:.2rem 0 0;font-size:.85rem">'.$activities.'</ul>' : '').'</div></div>';
|
||||
})->implode('');
|
||||
|
||||
return new HtmlString('<div>'.$rows.'</div>');
|
||||
}
|
||||
|
||||
/**
|
||||
* What has happened so far, oldest first.
|
||||
*/
|
||||
private static function chronicle(Booking $booking): HtmlString
|
||||
{
|
||||
$rows = collect(BookingProgress::history($booking))->map(fn (array $event): string => '<li style="margin:.2rem 0"><span style="color:#6b7280">'.$event['at']->format('d.m.Y H:i').'</span> · '.e($event['label']).'</li>')->implode('');
|
||||
|
||||
return new HtmlString('<ul style="list-style:none;padding:0;margin:0;font-size:.9rem">'.$rows.'</ul>');
|
||||
}
|
||||
|
||||
/**
|
||||
* The standard process that applies to this booking: which template (with cancellation rule and annexes) comes from
|
||||
* the portal and booking type, and whether payments become tasks.
|
||||
*/
|
||||
private static function setup(Booking $booking): string
|
||||
{
|
||||
$channel = $booking->importChannel ?? $booking->originChannel;
|
||||
$template = OfferTerms::templateFor($booking);
|
||||
$policy = $template?->cancellationPolicy;
|
||||
$annexes = $template?->annexesFor($booking)->map(fn ($annex) => $annex->name)->implode(', ');
|
||||
|
||||
return collect([
|
||||
$channel ? 'Portal: '.$channel->name : 'Eigene Buchung (Webseite / manuell)',
|
||||
'Vertragsvorlage: '.($template ? $template->label() : 'Texte der Webseite'),
|
||||
'Stornoregel: '.($policy ? $policy->name : 'keine hinterlegt'),
|
||||
'Anlagen: '.($annexes ?: 'keine'),
|
||||
'Zahlungsaufgaben: '.($booking->wantsPaymentTasks() ? 'ja' : 'nein (läuft über das Portal)'),
|
||||
])->implode(' · ');
|
||||
}
|
||||
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->columns(3)
|
||||
->components([
|
||||
Section::make('Vorgang')
|
||||
Section::make('Als Nächstes')
|
||||
->columnSpanFull()
|
||||
->schema([
|
||||
TextEntry::make('process')->label('Art des Vorgangs')->state(fn (Booking $record): string => BookingProgress::kindLabel($record)),
|
||||
TextEntry::make('next')
|
||||
->label(fn (Booking $record): string => 'Nächster Schritt: '.BookingProgress::next($record)['title'])
|
||||
->state(fn (Booking $record): string => BookingProgress::next($record)['text'])
|
||||
->color(fn (Booking $record): string => BookingProgress::next($record)['color'])
|
||||
->weight('bold'),
|
||||
TextEntry::make('setup')
|
||||
->label('Standardprozess (aus Portal und Buchungstyp)')
|
||||
->state(fn (Booking $record): string => self::setup($record))
|
||||
->columnSpanFull(),
|
||||
TextEntry::make('steps')
|
||||
->label('Ablauf: Meilensteine und Aktivitäten')
|
||||
->state(fn (Booking $record): HtmlString => self::timeline($record))
|
||||
->html()
|
||||
->columnSpanFull(),
|
||||
TextEntry::make('chronicle')
|
||||
->label('Bisheriger Verlauf')
|
||||
->state(fn (Booking $record): HtmlString => self::chronicle($record))
|
||||
->html()
|
||||
->columnSpanFull(),
|
||||
->hiddenLabel()
|
||||
->state(fn (Booking $record): HtmlString => self::nextStep($record))
|
||||
->html(),
|
||||
]),
|
||||
Grid::make(1)
|
||||
->columnSpan(2)
|
||||
->schema([
|
||||
Section::make('Vertrag')
|
||||
->columns(2)
|
||||
->schema([
|
||||
TextEntry::make('contract_template')->label('Vorlage')->state(fn (Booking $record): string => isset($record->offer_terms['template']) ? $record->offer_terms['template']['name'].' (Version '.$record->offer_terms['template']['version'].')' : ($record->offer_terms ? 'Texte der Webseite (Stand '.CarbonImmutable::parse($record->offer_terms['captured_at'])->format('d.m.Y').')' : 'Noch kein Angebot / Vertrag')),
|
||||
TextEntry::make('contract_state')->label('Dokumente')->state(fn (Booking $record): string => collect([
|
||||
$record->offer_path ? 'Angebot (PDF) Version '.$record->offer_version : null,
|
||||
$record->contract_path ? 'Mietvertrag (PDF, unveränderlich, Prüfsumme '.substr((string) $record->contract_pdf_sha256, 0, 10).')' : null,
|
||||
])->filter()->implode(' · ') ?: 'Noch kein Dokument – der Vertrag entsteht mit dem Angebot bzw. der Bestätigung'),
|
||||
TextEntry::make('contract_mail')->label('Zustellung')->state(fn (Booking $record): string => $record->confirmation_sent_at ? 'Bestätigung mit Vertrag gesendet am '.$record->confirmation_sent_at->format('d.m.Y, H:i') : ($record->confirmation_failed_at ? 'Versand fehlgeschlagen' : 'Noch nicht gesendet'))->columnSpanFull(),
|
||||
]),
|
||||
Section::make('Aufenthalt')
|
||||
->columns(3)
|
||||
->schema([
|
||||
TextEntry::make('property.name')->label('Wohnung'),
|
||||
TextEntry::make('arrival')->label('Anreise')->date('l, d.m.Y'),
|
||||
TextEntry::make('departure')->label('Abreise')->date('l, d.m.Y'),
|
||||
TextEntry::make('nights')->label('Nächte')->state(fn (Booking $record): int => $record->nights()),
|
||||
TextEntry::make('guests')->label('Personen'),
|
||||
TextEntry::make('promo_code')->label('Aktionscode')->placeholder('–'),
|
||||
]),
|
||||
Section::make('Preis')
|
||||
Section::make('Ablauf')
|
||||
->description('Was erledigt ist, was wartet und was noch kommt.')
|
||||
->schema([TextEntry::make('activities')->hiddenLabel()->state(fn (Booking $record): HtmlString => self::activities($record))->html()]),
|
||||
Section::make('Preis und Zahlungen')
|
||||
->schema([
|
||||
TextEntry::make('price_unknown')
|
||||
->hiddenLabel()
|
||||
->state('Der Gesamtpreis ist noch nicht bekannt.')
|
||||
->color('warning')
|
||||
->visible(fn (Booking $record): bool => $record->total === null),
|
||||
RepeatableEntry::make('quote.lines')
|
||||
->hiddenLabel()
|
||||
->table([
|
||||
TableColumn::make('Leistung'),
|
||||
TableColumn::make('Betrag')->alignEnd(),
|
||||
])
|
||||
->visible(fn (Booking $record): bool => filled($record->quote['lines'] ?? null))
|
||||
->table([TableColumn::make('Leistung'), TableColumn::make('Betrag')->alignEnd()])
|
||||
->schema([
|
||||
TextEntry::make('label'),
|
||||
TextEntry::make('amount')->formatStateUsing(fn (int $state): string => Money::format($state))->alignEnd(),
|
||||
]),
|
||||
Grid::make(4)->schema([
|
||||
Grid::make(4)->visible(fn (Booking $record): bool => $record->total !== null)->schema([
|
||||
TextEntry::make('total')->label('Gesamtpreis')->money('EUR', divideBy: 100, locale: 'de')->weight('bold'),
|
||||
TextEntry::make('deposit')->label('Anzahlung')->money('EUR', divideBy: 100, locale: 'de'),
|
||||
TextEntry::make('balance')->label('Restzahlung')->state(fn (Booking $record): string => Money::format($record->total - $record->deposit)),
|
||||
TextEntry::make('balance_due_on')->label('Rest fällig am')->date('d.m.Y'),
|
||||
TextEntry::make('paid')->label('Bezahlt')->state(fn (Booking $record): string => Money::format($record->paidAmount())),
|
||||
TextEntry::make('open')->label('Offen')->state(fn (Booking $record): string => Money::format($record->openAmount()))->color(fn (Booking $record): string => $record->openAmount() > 0 ? 'danger' : 'success'),
|
||||
TextEntry::make('deposit_due_on')->label('Anzahlung fällig am')->date('d.m.Y')->placeholder('–'),
|
||||
TextEntry::make('open')->label('Offen')
|
||||
->state(fn (Booking $record): string => $record->process()->payments() === Responsibility::Portal ? 'über das Portal' : Money::format($record->openAmount()))
|
||||
->color(fn (Booking $record): string => $record->process()->payments() === Responsibility::Landlord && $record->openAmount() > 0 ? 'danger' : 'success'),
|
||||
TextEntry::make('balance_due_on')->label('Rest fällig am')->date('d.m.Y')->placeholder('–'),
|
||||
]),
|
||||
]),
|
||||
Section::make('Verlauf')
|
||||
->collapsible()
|
||||
->schema([TextEntry::make('history')->hiddenLabel()->state(fn (Booking $record): HtmlString => self::history($record))->html()]),
|
||||
Section::make('Nachricht des Gastes')
|
||||
->visible(fn (Booking $record): bool => filled($record->message))
|
||||
->schema([
|
||||
TextEntry::make('message')->hiddenLabel(),
|
||||
]),
|
||||
->schema([TextEntry::make('message')->hiddenLabel()]),
|
||||
]),
|
||||
Grid::make(1)
|
||||
->columnSpan(1)
|
||||
->schema([
|
||||
Section::make('Status')
|
||||
->schema([
|
||||
TextEntry::make('status')->label('Status')->badge(),
|
||||
TextEntry::make('hold_expires_at')->label('Vorgemerkt bis')->dateTime('d.m.Y, H:i')->visible(fn (Booking $record): bool => $record->hold_expires_at !== null),
|
||||
TextEntry::make('confirmed_at')->label('Bestätigt am')->dateTime('d.m.Y, H:i')->visible(fn (Booking $record): bool => $record->confirmed_at !== null),
|
||||
TextEntry::make('created_at')->label('Eingegangen')->dateTime('d.m.Y, H:i'),
|
||||
TextEntry::make('processing')
|
||||
->label('Bearbeitung / Vorreservierung')
|
||||
->state(fn (Booking $record): string => $record->property->offer_mode->value === 'automatic' ? 'Automatisch' : 'Manuell')
|
||||
->visible(fn (Booking $record): bool => $record->isDirect()),
|
||||
TextEntry::make('offer')
|
||||
->label('Angebot')
|
||||
->state(fn (Booking $record): string => 'Version '.$record->offer_version.', gesendet '.$record->offer_sent_at?->format('d.m.Y, H:i').' · Prüfsumme '.substr((string) $record->offer_hash, 0, 12).(isset($record->offer_terms['template']) ? ' · Vorlage '.$record->offer_terms['template']['name'].' v'.$record->offer_terms['template']['version'] : ''))
|
||||
->visible(fn (Booking $record): bool => $record->offer_version > 0),
|
||||
TextEntry::make('accepted_at')->label('Angenommen am')->dateTime('d.m.Y, H:i:s')->visible(fn (Booking $record): bool => $record->accepted_at !== null),
|
||||
TextEntry::make('confirmation')
|
||||
->label('Bestätigungs-E-Mail')
|
||||
->state(fn (Booking $record): string => $record->confirmation_sent_at !== null ? 'Gesendet '.$record->confirmation_sent_at->format('d.m.Y, H:i') : 'Nicht zugestellt – bitte „Bestätigung erneut senden“')
|
||||
->color(fn (Booking $record): string => $record->confirmation_sent_at !== null ? 'success' : 'danger')
|
||||
->visible(fn (Booking $record): bool => $record->confirmation_sent_at !== null || $record->confirmation_failed_at !== null),
|
||||
TextEntry::make('source')->label('Buchungskanal / Quelle')->state(fn (Booking $record): string => $record->bookingChannelLabel()),
|
||||
TextEntry::make('referral_source')->label('Aufmerksam geworden durch')->placeholder('–'),
|
||||
TextEntry::make('utm')
|
||||
->label('Kampagne (UTM)')
|
||||
->state(fn (Booking $record): ?string => collect([$record->utm_source, $record->utm_medium, $record->utm_campaign])->filter()->implode(' / ') ?: null)
|
||||
->visible(fn (Booking $record): bool => filled($record->utm_source)),
|
||||
]),
|
||||
Section::make('Gast')
|
||||
->schema([
|
||||
TextEntry::make('guest.full_name')->label('Name'),
|
||||
TextEntry::make('guest.email')->label('E-Mail')->placeholder('Unbekannt')->copyable(),
|
||||
TextEntry::make('guest_name')->label('Name')->state(fn (Booking $record): string => $record->guestName())
|
||||
->color(fn (Booking $record): ?string => $record->guest === null ? 'warning' : null),
|
||||
TextEntry::make('guest.email')->label('E-Mail')->placeholder('noch nicht bekannt')->copyable(),
|
||||
TextEntry::make('guest.phone')->label('Telefon')->placeholder('–'),
|
||||
TextEntry::make('guest_address')
|
||||
->label('Adresse')
|
||||
->state(fn (Booking $record): ?string => collect([$record->guest->street, trim("{$record->guest->postal_code} {$record->guest->city}")])->filter()->implode(', ') ?: null)
|
||||
->state(fn (Booking $record): ?string => $record->guest === null ? null : (collect([$record->guest->street, trim("{$record->guest->postal_code} {$record->guest->city}")])->filter()->implode(', ') ?: null))
|
||||
->placeholder('–'),
|
||||
]),
|
||||
Section::make('Interne Notizen')
|
||||
Section::make('Aufenthalt')
|
||||
->schema([
|
||||
TextEntry::make('internal_notes')->hiddenLabel()->placeholder('Keine Notizen'),
|
||||
TextEntry::make('property.name')->label('Wohnung'),
|
||||
TextEntry::make('period')->label('Zeitraum')->state(fn (Booking $record): string => $record->arrival->translatedFormat('D, d.m.Y').' – '.$record->departure->translatedFormat('D, d.m.Y').' ('.$record->nights().' Nächte)'),
|
||||
TextEntry::make('guests')->label('Personen')->placeholder('noch nicht bekannt'),
|
||||
TextEntry::make('channel')->label('Über')->state(fn (Booking $record): string => $record->bookingChannelLabel().($record->portal_reference ? ' · Nr. '.$record->portal_reference : '')),
|
||||
]),
|
||||
Section::make('Dokumente')
|
||||
->schema([
|
||||
TextEntry::make('documents')->hiddenLabel()->state(fn (Booking $record): string => collect([
|
||||
$record->offer_path ? 'Angebot Version '.$record->offer_version : null,
|
||||
$record->contract_path ? 'Mietvertrag' : null,
|
||||
$record->confirmation_sent_at ? 'Bestätigung gesendet am '.$record->confirmation_sent_at->format('d.m.Y') : null,
|
||||
])->filter()->implode(' · ') ?: 'Noch keine'),
|
||||
TextEntry::make('template')->label('Vorlage')->state(fn (Booking $record): string => isset($record->offer_terms['template'])
|
||||
? $record->offer_terms['template']['name'].' (Version '.$record->offer_terms['template']['version'].', festgeschrieben)'
|
||||
: (OfferTerms::templateFor($record)?->label() ?? 'Texte der Webseite').' (vorgesehen)'),
|
||||
]),
|
||||
Section::make('Interne Notizen')
|
||||
->collapsible()
|
||||
->schema([TextEntry::make('internal_notes')->hiddenLabel()->placeholder('Keine Notizen')]),
|
||||
]),
|
||||
Section::make('Technische Angaben')
|
||||
->description('Expertenansicht')
|
||||
->columnSpanFull()
|
||||
->collapsed()
|
||||
->visible(fn (): bool => auth()->user() instanceof User && auth()->user()->adminMode() === AdminMode::Expert)
|
||||
->columns(3)
|
||||
->schema([
|
||||
TextEntry::make('status')->label('Status')->badge(),
|
||||
TextEntry::make('case_type')->label('Vorgangsart')->state(fn (Booking $record): string => strtoupper($record->caseType()->value).' – '.$record->caseType()->getLabel()),
|
||||
TextEntry::make('intake')->label('Eingangsart')->state(fn (Booking $record): string => $record->intake?->getLabel() ?? '–'),
|
||||
TextEntry::make('profile')->label('Abwicklungsprofil (eingefroren)')->state(fn (Booking $record): HtmlString => self::profile($record))->html()->columnSpanFull(),
|
||||
TextEntry::make('hold_expires_at')->label('Reserviert bis')->dateTime('d.m.Y, H:i')->placeholder('–'),
|
||||
TextEntry::make('offer_hash')->label('Angebot (Prüfsumme)')->state(fn (Booking $record): ?string => $record->offer_version > 0 ? 'Version '.$record->offer_version.' · '.substr((string) $record->offer_hash, 0, 16) : null)->placeholder('–'),
|
||||
TextEntry::make('contract_pdf_sha256')->label('Vertrag (Prüfsumme)')->formatStateUsing(fn (?string $state): string => substr((string) $state, 0, 16))->placeholder('–'),
|
||||
TextEntry::make('accepted_at')->label('Angenommen am')->dateTime('d.m.Y, H:i:s')->placeholder('–'),
|
||||
TextEntry::make('source')->label('Quelle'),
|
||||
TextEntry::make('referral_source')->label('Aufmerksam geworden durch')->placeholder('–'),
|
||||
TextEntry::make('utm')->label('Kampagne (UTM)')->state(fn (Booking $record): ?string => collect([$record->utm_source, $record->utm_medium, $record->utm_campaign])->filter()->implode(' / ') ?: null)->placeholder('–'),
|
||||
TextEntry::make('created_at')->label('Eingegangen')->dateTime('d.m.Y, H:i'),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* The next step in large type, with what keeps an automatic case waiting.
|
||||
*/
|
||||
private static function nextStep(Booking $booking): HtmlString
|
||||
{
|
||||
$next = CaseActivities::next($booking);
|
||||
$automatic = $booking->processingMode() === ProcessingMode::Automatic;
|
||||
$waiting = collect(CaseActivities::for($booking))->first(fn ($activity): bool => $activity->state === ActivityState::Waiting);
|
||||
|
||||
$title = match (true) {
|
||||
$next !== null => e($next->label),
|
||||
$waiting !== null => 'Nichts zu tun – es wartet: '.e($waiting->label),
|
||||
default => 'Nichts zu tun.',
|
||||
};
|
||||
$color = $next?->state === ActivityState::Problem ? '#dc2626' : ($next !== null ? '#b45309' : '#15803d');
|
||||
$detail = $next?->detail ?? $waiting?->detail;
|
||||
$mode = $automatic
|
||||
? 'Dieser Vorgang läuft automatisch weiter, sobald alle Angaben da sind.'.(($blockers = self::blockers($booking)) !== [] ? ' Es fehlt: '.e(implode(' ', $blockers)) : '')
|
||||
: 'Sie geben jeden Schritt selbst frei. Der Knopf oben rechts führt zum nächsten Schritt.';
|
||||
|
||||
return new HtmlString('<div style="font-size:1.35rem;font-weight:700;color:'.$color.'">'.$title.'</div>'
|
||||
.($detail ? '<div style="margin-top:.2rem">'.e($detail).'</div>' : '')
|
||||
.'<div style="margin-top:.5rem;color:#6b7280;font-size:.9rem">'.$mode.'</div>');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<string>
|
||||
*/
|
||||
private static function blockers(Booking $booking): array
|
||||
{
|
||||
return $booking->isBinding() && $booking->confirmation_sent_at === null && $booking->process()->documents() === Responsibility::Landlord
|
||||
? app(CaseAutomation::class)->documentBlockers($booking)
|
||||
: [];
|
||||
}
|
||||
|
||||
private static function activities(Booking $booking): HtmlString
|
||||
{
|
||||
$colors = ['success' => '#15803d', 'warning' => '#b45309', 'danger' => '#dc2626', 'info' => '#2563eb', 'gray' => '#9ca3af'];
|
||||
|
||||
$rows = collect(CaseActivities::for($booking))
|
||||
->reject(fn ($activity): bool => $activity->state === ActivityState::NotApplicable)
|
||||
->map(function ($activity) use ($colors): string {
|
||||
$color = $colors[$activity->state->getColor()];
|
||||
$strong = $activity->state->needsAction() ? 'font-weight:700' : '';
|
||||
|
||||
return '<li style="display:flex;gap:.75rem;padding:.45rem 0;border-bottom:1px solid rgba(128,128,128,.2)">'
|
||||
.'<span style="width:1.4rem;text-align:center;font-weight:700;color:'.$color.'">'.$activity->state->icon().'</span>'
|
||||
.'<span style="flex:1;'.$strong.'">'.e($activity->label)
|
||||
.($activity->detail ? ' <span style="font-weight:400;color:#6b7280">· '.e($activity->detail).'</span>' : '')
|
||||
.($activity->url && $activity->state->needsAction() ? ' <a href="'.e($activity->url).'" style="color:#2563eb;text-decoration:underline">erledigen</a>' : '')
|
||||
.'</span><span style="color:'.$color.';font-size:.85rem">'.e($activity->state->getLabel()).'</span></li>';
|
||||
})->implode('');
|
||||
|
||||
return new HtmlString('<ul style="list-style:none;margin:0;padding:0">'.$rows.'</ul>');
|
||||
}
|
||||
|
||||
private static function history(Booking $booking): HtmlString
|
||||
{
|
||||
$rows = $booking->events()->get()->map(fn ($event): string => '<li style="margin:.25rem 0"><span style="color:#6b7280">'.$event->occurred_at->format('d.m.Y H:i').'</span> · '.e($event->summary)
|
||||
.($event->actor ? ' <span style="color:#6b7280">('.e($event->actor).')</span>' : '')
|
||||
.($event->reason ? '<div style="color:#6b7280;margin-left:1rem">Grund: '.e($event->reason).'</div>' : '').'</li>')->implode('');
|
||||
|
||||
return new HtmlString($rows === '' ? 'Noch keine Einträge.' : '<ul style="list-style:none;padding:0;margin:0;font-size:.9rem">'.$rows.'</ul>');
|
||||
}
|
||||
|
||||
private static function profile(Booking $booking): HtmlString
|
||||
{
|
||||
$profile = $booking->process();
|
||||
$rows = collect(ProcessSetting::cases())
|
||||
->reject(fn (ProcessSetting $setting): bool => in_array($setting, ProcessProfile::LIVE, true))
|
||||
->map(fn (ProcessSetting $setting): string => '<li>'.e($setting->question()).' <strong>'.e($setting->describe($profile->value($setting))).'</strong> <span style="color:#6b7280">('.e(ProcessProfile::sourceLabel($profile->source($setting))).')</span></li>')
|
||||
->implode('');
|
||||
|
||||
return new HtmlString('<ul style="list-style:disc;padding-left:1.2rem">'.$rows.'</ul><div style="color:#6b7280;font-size:.85rem">Festgelegt '.e(($profile->origin === 'migration' ? 'bei der Übernahme der bisherigen Daten' : 'beim Eingang').($profile->frozenAt ? ' am '.CarbonImmutable::parse($profile->frozenAt)->format('d.m.Y H:i') : '')).($booking->processing_mode ? ' · Bearbeitung für diesen Vorgang: '.e($booking->processing_mode->getLabel()) : '').'</div>');
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,7 @@ class BookingsTable
|
||||
public static function configure(Table $table, ?int $guestId = null): Table
|
||||
{
|
||||
return $table
|
||||
->description('Eigene Anfragen und Buchungen sowie erkannte Portalreservierungen in einer Liste. „Akte öffnen“ zeigt alles zu einem Vorgang: nächster Schritt, Vertrag, Zahlungen, Aufgaben und E-Mails. Fehlende Gastzuordnungen lassen sich in den Details ergänzen; unbekannte Belegungen haben einen eigenen Klärungsbereich.')
|
||||
->description('Eigene Anfragen und Buchungen sowie erkannte Portalreservierungen in einer Liste. „Öffnen“ zeigt alles zu einem Vorgang: nächster Schritt, Vertrag, Zahlungen, Aufgaben und E-Mails. Fehlende Gastzuordnungen lassen sich in den Details ergänzen; unbekannte Belegungen haben einen eigenen Klärungsbereich.')
|
||||
->records(function (?string $search, ?string $sortColumn, ?string $sortDirection, array $filters, int $page, int|string $recordsPerPage) use ($guestId, $table): LengthAwarePaginator {
|
||||
$propertyId = filled($filters['property']['value'] ?? null) ? (int) $filters['property']['value'] : null;
|
||||
$records = app(OccupancyOverview::class)->records($propertyId, $guestId);
|
||||
@@ -102,6 +102,6 @@ public static function configure(Table $table, ?int $guestId = null): Table
|
||||
Filter::make('without_guest')->label('Gastzuordnung offen'),
|
||||
])
|
||||
->recordUrl(fn (array $record): string => $record['url'])
|
||||
->recordActions([Action::make('view')->label(fn (array $record): string => $record['record_type'] === 'booking' ? 'Akte öffnen' : ($record['kind'] === 'block' ? 'Details' : 'Akte anlegen'))->icon('heroicon-o-folder-open')->button()->color('primary')->url(fn (array $record): string => $record['url'])]);
|
||||
->recordActions([Action::make('view')->label(fn (array $record): string => $record['record_type'] === 'booking' ? 'Öffnen' : ($record['kind'] === 'block' ? 'Details' : 'Als Buchung übernehmen'))->icon('heroicon-o-folder-open')->button()->color('primary')->url(fn (array $record): string => $record['url'])]);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user