Deploy FeWo mit PipelineManager / deploy (push) Successful in 3m59s
Eine Zusammenstellung vor jedem Dokument (Angebot, Bestaetigung, Buchungsunterlagen extern), Dokumentart je Vorgangsart, Freigaben fuer Vorlagen und Dokumentarten, Schutz vor unvereinbarten Bedingungen bei Portalbuchungen (E-004), kein doppelter Versand, Absicherung Hold 0 bis Paket 7, A6-Aufenthaltsbestaetigung vorbereitet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
99 lines
4.4 KiB
PHP
99 lines
4.4 KiB
PHP
<?php
|
||
|
||
namespace App\Filament\Resources\Bookings\Pages;
|
||
|
||
use App\Actions\ConfirmBooking;
|
||
use App\Actions\CreateReservation;
|
||
use App\Actions\SendBookingDocuments;
|
||
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;
|
||
use App\Pricing\StayRequest;
|
||
use Carbon\CarbonImmutable;
|
||
use Filament\Notifications\Notification;
|
||
use Filament\Resources\Pages\CreateRecord;
|
||
use Illuminate\Database\Eloquent\Model;
|
||
use Illuminate\Support\Arr;
|
||
use Illuminate\Support\Facades\DB;
|
||
|
||
/**
|
||
* 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 = 'Neu eintragen';
|
||
|
||
/**
|
||
* @param array<string, mixed> $data
|
||
*/
|
||
protected function handleRecordCreation(array $data): Model
|
||
{
|
||
if (($data['kind'] ?? null) === BookingForm::OWN_USE) {
|
||
$this->redirect(BlockedPeriodResource::getUrl());
|
||
$this->halt();
|
||
}
|
||
|
||
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) {
|
||
DB::transaction(fn () => app(ConfirmBooking::class)->bind($booking));
|
||
if ($sendMails && filled($booking->guest?->email)) {
|
||
// The documents go out only when their composition needs no check; otherwise they wait on the case page.
|
||
$waiting = app(SendBookingDocuments::class)->automatically($booking->fresh());
|
||
if ($waiting !== []) {
|
||
Notification::make()->title('Gebucht – Unterlagen noch nicht gesendet')->body(implode(' ', $waiting))->warning()->send();
|
||
}
|
||
} else {
|
||
app(ConfirmBooking::class)->deliver($booking->fresh(), notifyGuest: false);
|
||
}
|
||
}
|
||
} 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
|
||
{
|
||
/** @var Booking $record */
|
||
$record = $this->getRecord();
|
||
|
||
return BookingResource::getUrl('view', ['record' => $record]);
|
||
}
|
||
}
|