Deploy FeWo mit PipelineManager / deploy (push) Successful in 3m34s
- Akte anlegen aus einer importierten Portal-Reservierung (Belegung bleibt durchgehend belegt, Kalendereintrag wird Spiegelung) - Akte: Standardprozess (Portal/Vorlage/Storno/Anlagen), Meilensteine mit Aktivitaeten und Aktionshinweis, chronologischer Verlauf - Kanalformular: Abschnitt Standardprozess je Buchungstyp mit Anzeige, was die Vorlage mitbringt - Portalpreis als gemeinsame Logik (PortalPrice) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
78 lines
3.0 KiB
PHP
78 lines
3.0 KiB
PHP
<?php
|
||
|
||
namespace App\Actions;
|
||
|
||
use App\Exceptions\ReservationException;
|
||
use App\Models\Booking;
|
||
use App\Models\Channel;
|
||
use App\Models\Property;
|
||
use App\Pricing\PortalPrice;
|
||
use App\Pricing\QuoteException;
|
||
use App\Pricing\StayRequest;
|
||
use Illuminate\Support\Facades\DB;
|
||
|
||
/**
|
||
* Records a booking that a portal already made binding (e.g. a direct booking on FeWo-direkt) – usually without
|
||
* the guest's contact data. The booking keeps the portal as its origin channel and may carry the portal's price and
|
||
* reference. The landlord decides how the contract process continues:
|
||
*
|
||
* - {@see self::CONFIRM}: the booking becomes binding right away (the dates are occupied), the contract follows
|
||
* once the contact data is known ({@see ProvideGuestContact}) – no contract is generated before that;
|
||
* - {@see self::CONTRACT}: binding and contract mail at once (needs the guest's e-mail address);
|
||
* - {@see self::RECORD}: only recorded as a request, everything else is done by hand.
|
||
*/
|
||
class RecordPortalBooking
|
||
{
|
||
public const CONFIRM = 'confirm';
|
||
|
||
public const CONTRACT = 'contract';
|
||
|
||
public const RECORD = 'record';
|
||
|
||
public function __construct(
|
||
private CreateReservation $create,
|
||
private ConfirmBooking $confirm,
|
||
private PortalPrice $price,
|
||
) {}
|
||
|
||
/**
|
||
* @param array<string, ?string> $guestData first_name and last_name are required, everything else optional
|
||
*
|
||
* @throws QuoteException
|
||
* @throws ReservationException
|
||
*/
|
||
public function handle(Property $property, Channel $channel, StayRequest $stay, array $guestData, string $process = self::CONFIRM, ?string $portalReference = null, ?int $portalTotal = null, ?string $notes = null, bool $guestConfirmed = false): Booking
|
||
{
|
||
if ($channel->property_id !== $property->id) {
|
||
throw new ReservationException('Der Kanal gehört nicht zu dieser Wohnung.');
|
||
}
|
||
|
||
if ($process === self::CONTRACT && blank($guestData['email'] ?? null)) {
|
||
throw new ReservationException('Für den sofortigen Vertragsversand wird die E-Mail-Adresse des Gastes benötigt.');
|
||
}
|
||
|
||
$booking = $this->create->handle($property, $stay, $guestData, source: 'portal', sendMails: false);
|
||
|
||
$changes = ['origin_channel_id' => $channel->id, 'portal_reference' => filled($portalReference) ? trim($portalReference) : null, 'internal_notes' => filled($notes) ? trim($notes) : $booking->internal_notes];
|
||
if ($guestConfirmed) {
|
||
$changes['guest_confirmed_at'] = now();
|
||
}
|
||
if ($portalTotal !== null) {
|
||
$changes += $this->price->columns($property, $stay, $portalTotal);
|
||
}
|
||
$booking->update($changes);
|
||
|
||
if ($process === self::RECORD) {
|
||
return $booking->refresh();
|
||
}
|
||
|
||
if ($process === self::CONTRACT) {
|
||
$this->confirm->handle($booking, notifyGuest: true);
|
||
} else {
|
||
DB::transaction(fn () => $this->confirm->bind($booking));
|
||
}
|
||
|
||
return $booking->refresh();
|
||
}
|
||
}
|