- 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>
103 lines
4.2 KiB
PHP
103 lines
4.2 KiB
PHP
<?php
|
||
|
||
namespace App\Http\Controllers;
|
||
|
||
use App\Actions\AcceptOffer;
|
||
use App\Actions\RejectOffer;
|
||
use App\Enums\BookingStatus;
|
||
use App\Exceptions\ReservationException;
|
||
use App\Models\Booking;
|
||
use App\Process\CaseLog;
|
||
use DateTimeInterface;
|
||
use Illuminate\Contracts\View\View;
|
||
use Illuminate\Http\RedirectResponse;
|
||
use Illuminate\Http\Request;
|
||
use Illuminate\Support\Facades\URL;
|
||
|
||
/**
|
||
* The guest's offer page (no account): reached by the signed link in the offer e-mail. Shows the complete
|
||
* offer and lets the guest accept or decline it; the form actions are signed the same way.
|
||
*/
|
||
class OfferController extends Controller
|
||
{
|
||
public function show(Request $request, Booking $booking, AcceptOffer $accept): View
|
||
{
|
||
$booking->loadMissing(['guest', 'property']);
|
||
$version = (int) $request->query('v');
|
||
|
||
$problem = null;
|
||
if ($booking->status === BookingStatus::OfferSent) {
|
||
try {
|
||
$accept->ensureAcceptable($booking, $version);
|
||
} catch (ReservationException $exception) {
|
||
$problem = $exception->getMessage();
|
||
}
|
||
}
|
||
|
||
$expires = $booking->hold_expires_at?->isFuture() ? $booking->hold_expires_at : now()->addHour();
|
||
|
||
return view('offer', [
|
||
'booking' => $booking,
|
||
'problem' => $problem,
|
||
'canAnswer' => $booking->status === BookingStatus::OfferSent && $problem === null,
|
||
'acceptUrl' => $this->signed($booking, 'offers.accept', $expires, $version),
|
||
'rejectUrl' => $this->signed($booking, 'offers.reject', $expires, $version),
|
||
'title' => 'Ihr Angebot',
|
||
]);
|
||
}
|
||
|
||
public function accept(Request $request, Booking $booking, AcceptOffer $accept): RedirectResponse
|
||
{
|
||
$request->validate(['terms' => ['accepted']], ['terms.accepted' => 'Bitte bestätigen Sie, dass Sie die Bedingungen gelesen haben.']);
|
||
|
||
return $this->answer($request, $booking, function (int $version) use ($accept, $booking): string {
|
||
$concluded = CaseLog::context(fn (): bool => $accept->handle($booking, $version), actor: CaseLog::GUEST);
|
||
$booking->refresh();
|
||
|
||
if (! $concluded) {
|
||
return 'Ihre Buchung ist bereits verbindlich bestätigt – Sie müssen nichts weiter tun.';
|
||
}
|
||
|
||
return $booking->confirmation_sent_at !== null
|
||
? 'Vielen Dank! Ihre Buchung ist verbindlich. Die Bestätigung mit dem Mietvertrag haben wir Ihnen per E-Mail gesendet.'
|
||
: 'Vielen Dank! Ihre Buchung ist verbindlich. Die Bestätigung mit dem Mietvertrag erhalten Sie in Kürze per E-Mail; kommt sie nicht an, melden wir uns bei Ihnen.';
|
||
});
|
||
}
|
||
|
||
public function reject(Request $request, Booking $booking, RejectOffer $reject): RedirectResponse
|
||
{
|
||
return $this->answer($request, $booking, function (int $version) use ($reject, $booking): string {
|
||
CaseLog::context(fn () => $reject->handle($booking, $version), actor: CaseLog::GUEST);
|
||
|
||
return 'Schade – wir haben Ihre Absage erhalten und den Zeitraum wieder freigegeben. Vielleicht ein anderes Mal!';
|
||
});
|
||
}
|
||
|
||
/**
|
||
* Runs the answer (it returns the success message) and returns to a freshly signed offer page with the result.
|
||
*
|
||
* @param callable(int): string $action
|
||
*/
|
||
private function answer(Request $request, Booking $booking, callable $action): RedirectResponse
|
||
{
|
||
$version = (int) $request->query('v');
|
||
$back = $this->signed($booking, 'offers.show', now()->addDays(30), $version);
|
||
|
||
try {
|
||
$success = $action($version);
|
||
} catch (ReservationException $exception) {
|
||
return redirect()->to($back)->with('offer.error', $exception->getMessage());
|
||
}
|
||
|
||
return redirect()->to($back)->with('offer.success', $success);
|
||
}
|
||
|
||
private function signed(Booking $booking, string $name, DateTimeInterface $expiration, int $version): string
|
||
{
|
||
$parameters = ['booking' => $booking, 'v' => $version];
|
||
|
||
return $booking->website()?->temporarySignedRoute($name, $expiration, $parameters)
|
||
?? URL::temporarySignedRoute($name, $expiration, $parameters);
|
||
}
|
||
}
|