Vorgangskern und geführte Vorgangsbearbeitung (Pakete 1 und 2, Prozessarchitektur v0.10)
- 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>
This commit is contained in:
1 parent
9005c12164
commit
3a728c3255
78 files changed
+4296
-1180
No files matched your search
@@ -2,90 +2,39 @@
|
||||
|
||||
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.
|
||||
* Takes over a reservation found in a portal calendar as a case ({@see TakeOverExternalBooking}). The calendar only
|
||||
* says "these nights are taken"; the case gives the reservation its handling. The calendar entry stays as the portal's
|
||||
* mirror of the case. A first name from the calendar is no guest identity – it is kept as a note, not as a guest.
|
||||
*/
|
||||
class OpenPortalFile
|
||||
{
|
||||
public function __construct(private PortalPrice $price) {}
|
||||
public function __construct(private TakeOverExternalBooking $takeOver) {}
|
||||
|
||||
/**
|
||||
* @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 ($block->channel === null) {
|
||||
throw new ReservationException('Übernehmen lassen sich nur Reservierungen aus einem Portalkalender.');
|
||||
}
|
||||
|
||||
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.');
|
||||
}
|
||||
$fields = (array) ($block->ical_interpretation['fields'] ?? []);
|
||||
$name = trim((string) ($fields['guest_first_name'] ?? ''));
|
||||
|
||||
$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();
|
||||
});
|
||||
return $this->takeOver->handle(
|
||||
$block->property,
|
||||
$block->channel,
|
||||
CarbonImmutable::parse($block->starts_on),
|
||||
CarbonImmutable::parse($block->ends_on),
|
||||
['notes' => 'Aus dem Portalkalender „'.$block->channel->name.'“ übernommen.'.($name !== '' ? ' Name laut Kalender: '.$name.'.' : '')],
|
||||
$block,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user