Files
fewo-stommer/app/Actions/TakeOverPortalInquiry.php
T
LarsandClaude Opus 5.5 37f48defcc v0.11 U3: Klärungsreservierung für unvollständige Anfragen
- bookings.hold_purpose (offer wie bisher / clarification).
- RequestHold: vollständige Anfrage → Angebots-Hold unverändert;
  unvollständig, aber Wohnung, Zeitraum, verwendbare E-Mail und freier
  Zeitraum → nur Klärungsreservierung (15 min automatisch / 180 min
  Freigabe oder manuell, 0 = keine); sonst nichts (B1). Auch für
  Portalanfragen ohne Gastdaten.
- ExpireReservations beendet nur Angebots-Holds; ein abgelaufener
  Klärungsblock gibt nur den Kalender frei, der Vorgang bleibt offen.
- Vervollständigen erzeugt keinen Hold; erst SendOffer setzt den
  unveränderten Angebots-Hold. AutoOffer prüft danach nur die Verfügbarkeit.
- Booking::clarificationState() liefert den tatsächlichen Sperrstatus.
- Architekturtest: nur die bestehenden Reservierungsschritte schreiben Holds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 13:13:24 +01:00

69 lines
2.9 KiB
PHP

<?php
namespace App\Actions;
use App\Availability\AvailabilityChecker;
use App\Enums\BookingStatus;
use App\Enums\IntakeKind;
use App\Enums\ProcessingMode;
use App\Exceptions\ReservationException;
use App\Models\Booking;
use App\Models\Channel;
use App\Process\CaseAutomation;
use App\Process\ProcessSettings;
use App\Process\RequestHold;
use Carbon\CarbonImmutable;
use Illuminate\Support\Facades\DB;
/**
* A non-binding request through a portal (case type A2) as it arrives: dates and the portal's reference, nothing
* invented. Guest, number of guests and price stay unknown until the landlord enters them; the case then asks for
* exactly that and continues like a request of the own website. Whether the dates are reserved follows the channel's
* settings for requests.
*/
class TakeOverPortalInquiry
{
public function __construct(private AvailabilityChecker $availability, private ProcessSettings $settings) {}
/**
* @throws ReservationException
*/
public function handle(Channel $channel, CarbonImmutable $arrival, CarbonImmutable $departure, ?string $reference = null, ?string $notes = null, ?ProcessingMode $processingMode = null): Booking
{
$property = $channel->property;
if ($departure->lessThanOrEqualTo($arrival)) {
throw new ReservationException('Die Abreise muss nach der Anreise liegen.');
}
$booking = DB::transaction(function () use ($property, $channel, $arrival, $departure, $reference, $notes, $processingMode): Booking {
$property->newQuery()->whereKey($property->id)->lockForUpdate()->firstOrFail();
if (! $this->availability->isAvailable($property, $arrival, $departure)) {
throw ReservationException::notAvailable();
}
$profile = $this->settings->resolve($property, $channel, IntakeKind::Inquiry);
// v0.11 (B1): a portal request without the guest's details holds nothing until the details are there; the
// offer hold comes with the offer.
$draft = new Booking(['property_id' => $property->id, 'arrival' => $arrival->toDateString(), 'departure' => $departure->toDateString()]);
$draft->setRelation('guest', null);
return $property->bookings()->create([
...RequestHold::for($draft, $profile),
'status' => BookingStatus::Reserved,
'source' => 'portal',
'intake' => IntakeKind::Inquiry,
'origin_channel_id' => $channel->id,
'portal_reference' => $reference,
'arrival' => $arrival->toDateString(),
'departure' => $departure->toDateString(),
'processing_mode' => $processingMode,
'internal_notes' => $notes,
]);
});
app(CaseAutomation::class)->advance($booking);
return $booking->refresh();
}
}