Portalbuchungen und -anfragen aus Kalender und Mail werden ueber PortalIntake zum Vorgang (nur bei sicherer Erkennung), Dubletten ueber Buchungsnummer, gleiches Portal mit gleichen Naechten und Spiegelung; Unsicheres wird geklaert. Portalstorno und -aenderung als Aufgabe am Vorgang ohne stille Stornierung. Schalter je Kanal (Aus als Standard, Beobachten, Anlegen, Anlegen + weiter), Eingangsprotokoll, Bestandsuebernahme mit Vorschau/Bericht/Ruecknahme, Sperrnachweis in drei Stufen. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
64 lines
2.5 KiB
PHP
64 lines
2.5 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 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);
|
|
|
|
return $property->bookings()->create([
|
|
'status' => BookingStatus::Reserved,
|
|
'source' => 'portal',
|
|
'intake' => IntakeKind::Inquiry,
|
|
'origin_channel_id' => $channel->id,
|
|
'portal_reference' => $reference,
|
|
'arrival' => $arrival->toDateString(),
|
|
'departure' => $departure->toDateString(),
|
|
'hold_expires_at' => $profile->preReservation() ? now()->addHours($profile->holdHours()) : null,
|
|
'processing_mode' => $processingMode,
|
|
'internal_notes' => $notes,
|
|
]);
|
|
});
|
|
|
|
app(CaseAutomation::class)->advance($booking);
|
|
|
|
return $booking->refresh();
|
|
}
|
|
}
|