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>
92 lines
4.4 KiB
PHP
92 lines
4.4 KiB
PHP
<?php
|
||
|
||
namespace App\Actions;
|
||
|
||
use App\Enums\BookingStatus;
|
||
use App\Enums\OccupationKind;
|
||
use App\Exceptions\ReservationException;
|
||
use App\Models\BlockedPeriod;
|
||
use App\Models\Booking;
|
||
use App\Models\Guest;
|
||
use App\Models\Property;
|
||
use App\Pricing\PortalPrice;
|
||
use App\Pricing\StayRequest;
|
||
use App\Tenancy\TenantContext;
|
||
use Carbon\CarbonImmutable;
|
||
use Illuminate\Support\Facades\DB;
|
||
|
||
/**
|
||
* Opens the booking file for a reservation that arrived through a portal calendar. The calendar only says "these
|
||
* nights are taken"; the file gives the reservation its workflow (contact data, contract, payments, arrival,
|
||
* cancellation) like every other booking. The imported calendar entry stays as the portal's mirror of the booking
|
||
* (it keeps its calendar source and UID, but the booking now leads the calendar), the dates stay occupied throughout.
|
||
*
|
||
* Unknown facts stay unknown: the guest is a placeholder without contact data, the price is our own calculation (or
|
||
* empty) until the portal price is entered.
|
||
*/
|
||
class OpenPortalFile
|
||
{
|
||
public function __construct(private PortalPrice $price) {}
|
||
|
||
/**
|
||
* @throws ReservationException
|
||
*/
|
||
public function handle(BlockedPeriod $block): Booking
|
||
{
|
||
return DB::transaction(function () use ($block): Booking {
|
||
Property::query()->whereKey($block->property_id)->lockForUpdate()->firstOrFail();
|
||
$block = BlockedPeriod::query()->whereKey($block->id)->lockForUpdate()->firstOrFail();
|
||
|
||
if (! in_array($block->source, ['channel', 'email'], true) || $block->channel_id === null) {
|
||
throw new ReservationException('Eine Akte gibt es nur für Reservierungen aus einem Portalkalender.');
|
||
}
|
||
if ($block->occupationKind() === OccupationKind::Block) {
|
||
throw new ReservationException('Eine Sperrzeit ist keine Reservierung. Bitte zuerst „Einordnen“ und als Portalreservierung kennzeichnen.');
|
||
}
|
||
if ($block->is_representation && $block->linked_booking_id !== null) {
|
||
return Booking::query()->findOrFail($block->linked_booking_id);
|
||
}
|
||
if ($block->is_representation) {
|
||
throw new ReservationException('Dieser Eintrag ist die Spiegelung einer anderen Belegung. Die Akte gehört an die führende Belegung.');
|
||
}
|
||
|
||
$property = $block->property;
|
||
$channel = $block->channel;
|
||
$fields = (array) ($block->ical_interpretation['fields'] ?? []);
|
||
$guest = $block->guest ?? Guest::query()->create([
|
||
'first_name' => filled($fields['guest_first_name'] ?? null) ? (string) $fields['guest_first_name'] : 'Gast',
|
||
'last_name' => '('.$channel->name.')',
|
||
'email' => '',
|
||
'tenant_id' => app(TenantContext::class)->id(),
|
||
]);
|
||
|
||
$stay = new StayRequest(CarbonImmutable::parse($block->starts_on), CarbonImmutable::parse($block->ends_on), min(2, $property->max_guests));
|
||
$booking = $property->bookings()->create([
|
||
'guest_id' => $guest->id,
|
||
'status' => BookingStatus::Reserved,
|
||
'source' => 'portal',
|
||
'origin_channel_id' => $block->origin_channel_id ?? $channel->id,
|
||
'portal_reference' => $fields['booking_reference'] ?? null,
|
||
'arrival' => $stay->arrival->toDateString(),
|
||
'departure' => $stay->departure->toDateString(),
|
||
'guests' => $stay->guests,
|
||
'hold_expires_at' => null,
|
||
'internal_notes' => 'Akte aus dem Portalkalender „'.$channel->name.'“ angelegt. Personenzahl und Preis sind nicht bekannt – bitte den Portalpreis erfassen.',
|
||
...$this->price->unknownColumns($property, $stay),
|
||
]);
|
||
|
||
$block->forceFill([
|
||
'is_representation' => true, 'representation_automatic' => false, 'canonical_block_id' => null,
|
||
'linked_booking_id' => $booking->id, 'export_approved' => false, 'needs_review' => false, 'reviewed_at' => now(),
|
||
'occupation_kind' => OccupationKind::Reservation, 'guest_id' => $guest->id,
|
||
'review_note' => 'Akte angelegt; die Buchung führt diese Belegung.',
|
||
])->save();
|
||
|
||
app(ConfirmBooking::class)->bind($booking);
|
||
app(ReconcileChannelRepresentations::class)->handle($property);
|
||
|
||
return $booking->refresh();
|
||
});
|
||
}
|
||
}
|