Akte auch fuer Portal-Reservierungen aus dem Kalender, Ablauf mit Aktivitaeten, Verlauf, Standardprozess je Portal
Deploy FeWo mit PipelineManager / deploy (push) Successful in 3m34s
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>
This commit is contained in:
1 parent
5ba9ae08ab
commit
81c025f1ee
10 files changed
+450
-75
No files matched your search
@@ -0,0 +1,91 @@
|
||||
<?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();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -2,14 +2,12 @@
|
||||
|
||||
namespace App\Actions;
|
||||
|
||||
use App\Enums\QuoteLineType;
|
||||
use App\Exceptions\ReservationException;
|
||||
use App\Models\Booking;
|
||||
use App\Models\Channel;
|
||||
use App\Models\Property;
|
||||
use App\Pricing\PriceCalculator;
|
||||
use App\Pricing\PortalPrice;
|
||||
use App\Pricing\QuoteException;
|
||||
use App\Pricing\QuoteLine;
|
||||
use App\Pricing\StayRequest;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
@@ -34,7 +32,7 @@ class RecordPortalBooking
|
||||
public function __construct(
|
||||
private CreateReservation $create,
|
||||
private ConfirmBooking $confirm,
|
||||
private PriceCalculator $calculator,
|
||||
private PortalPrice $price,
|
||||
) {}
|
||||
|
||||
/**
|
||||
@@ -60,7 +58,7 @@ public function handle(Property $property, Channel $channel, StayRequest $stay,
|
||||
$changes['guest_confirmed_at'] = now();
|
||||
}
|
||||
if ($portalTotal !== null) {
|
||||
$changes += $this->priceOf($property, $stay, $portalTotal);
|
||||
$changes += $this->price->columns($property, $stay, $portalTotal);
|
||||
}
|
||||
$booking->update($changes);
|
||||
|
||||
@@ -76,32 +74,4 @@ public function handle(Property $property, Channel $channel, StayRequest $stay,
|
||||
|
||||
return $booking->refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Price columns for a booking whose portal price differs from our own calculation: the difference becomes an
|
||||
* adjustment line, so the quote still adds up to what the portal charged.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*
|
||||
* @throws QuoteException
|
||||
*/
|
||||
private function priceOf(Property $property, StayRequest $stay, int $portalTotal): array
|
||||
{
|
||||
$quote = $this->calculator->calculate($property, $stay);
|
||||
$difference = $portalTotal - $quote->total();
|
||||
if ($difference === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$difference = max($difference, -$quote->rent());
|
||||
$quote = $quote->withLine(new QuoteLine(QuoteLineType::Adjustment, 'Abweichung Portalpreis', 1, $difference, $difference));
|
||||
|
||||
return [
|
||||
'price_adjustment' => $difference,
|
||||
'price_adjustment_label' => 'Abweichung Portalpreis',
|
||||
'quote' => $quote->toArray(),
|
||||
'total' => $quote->total(),
|
||||
'deposit' => $quote->deposit(),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user