Portal-Direktbuchung erfassen, Kontaktdaten-Prozess, manueller Statuswechsel, Archiv, Filter, Menue Verwaltung/Einrichtung
Deploy FeWo mit PipelineManager / deploy (push) Successful in 3m38s
Deploy FeWo mit PipelineManager / deploy (push) Successful in 3m38s
- Buchung erfassen: Buchungsweg Portal (Referenz, Portalpreis, ohne Kontaktdaten), Prozess bestaetigen/Vertrag sofort/nur erfassen - Buchungsakte: Kontaktdaten eintragen (automatisch oder manuell weiter), Gast um Kontaktdaten bitten, Status von Hand aendern, Archivieren - Liste: Filter Kanal, Anreisezeitraum, Kontaktdaten fehlen; Spalten ausblendbar; Archiv - Klaerung: verstaendlichere Texte, eigenstaendige Belegung mit Kanal gilt als geklaert (Gitea #4) - Akte per Button aus Liste und Belegungsplan erreichbar - Menue: Gruppen Verwaltung (Tagesgeschaeft) und Einrichtung (Konfiguration), einfache Ansicht auf 8 Punkte Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0c4187edaf
commit
5ba9ae08ab
37 files changed
+786
-82
No files matched your search
@@ -108,8 +108,8 @@ private function create(Property $property, StayRequest $stay, array $guestData,
|
||||
*/
|
||||
private function guestFor(array $guestData): array
|
||||
{
|
||||
$email = mb_strtolower($guestData['email']);
|
||||
$guest = Guest::query()->where('email', $email)->first();
|
||||
$email = mb_strtolower(trim((string) ($guestData['email'] ?? '')));
|
||||
$guest = $email === '' ? null : Guest::query()->where('email', $email)->first();
|
||||
|
||||
if ($guest === null) {
|
||||
return [Guest::create([
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions;
|
||||
|
||||
use App\Enums\BookingStatus;
|
||||
use App\Exceptions\ReservationException;
|
||||
use App\Models\Booking;
|
||||
use App\Support\BookingProgress;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
/**
|
||||
* The guest's contact data arrived (portal message, e-mail, phone) and is entered on the booking. The landlord chooses
|
||||
* whether the process continues automatically – a binding portal booking gets its contract, a request gets the
|
||||
* offer – or by hand (data only). An already existing e-mail confirmation of the guest can be recorded as well.
|
||||
*/
|
||||
class ProvideGuestContact
|
||||
{
|
||||
public const AUTOMATIC = 'automatic';
|
||||
|
||||
public const MANUAL = 'manual';
|
||||
|
||||
public function __construct(private ConfirmBooking $confirm, private SendOffer $offer) {}
|
||||
|
||||
/**
|
||||
* @param array<string, ?string> $contact first_name, last_name, email, phone, street, postal_code, city, country
|
||||
* @return string what was done, for the notification
|
||||
*
|
||||
* @throws ReservationException
|
||||
*/
|
||||
public function handle(Booking $booking, array $contact, string $process = self::MANUAL, bool $guestConfirmed = false): string
|
||||
{
|
||||
$contact = array_map(fn ($value) => filled($value) ? trim((string) $value) : null, Arr::only($contact, ['first_name', 'last_name', 'email', 'phone', 'street', 'postal_code', 'city', 'country']));
|
||||
if (isset($contact['email'])) {
|
||||
$contact['email'] = mb_strtolower($contact['email']);
|
||||
}
|
||||
|
||||
if ($process === self::AUTOMATIC && blank($contact['email'] ?? $booking->guest?->email)) {
|
||||
throw new ReservationException('Für den automatischen Ablauf wird die E-Mail-Adresse des Gastes benötigt.');
|
||||
}
|
||||
|
||||
$booking->guest->update(array_filter($contact, fn ($value) => $value !== null));
|
||||
if ($guestConfirmed) {
|
||||
$booking->forceFill(['guest_confirmed_at' => $booking->guest_confirmed_at ?? now()])->saveQuietly();
|
||||
}
|
||||
$booking->refresh()->load('guest');
|
||||
|
||||
if ($process !== self::AUTOMATIC) {
|
||||
return 'Kontaktdaten gespeichert';
|
||||
}
|
||||
|
||||
if (in_array($booking->status, BookingStatus::occupying(), true)) {
|
||||
$this->confirm->deliver($booking);
|
||||
|
||||
return 'Kontaktdaten gespeichert, Vertrag gesendet';
|
||||
}
|
||||
|
||||
if (BookingProgress::kind($booking) === BookingProgress::PORTAL_BOOKING) {
|
||||
$this->confirm->handle($booking);
|
||||
|
||||
return 'Kontaktdaten gespeichert, Buchung bestätigt und Vertrag gesendet';
|
||||
}
|
||||
|
||||
$this->offer->handle($booking);
|
||||
|
||||
return 'Kontaktdaten gespeichert, Angebot gesendet';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
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\QuoteException;
|
||||
use App\Pricing\QuoteLine;
|
||||
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 PriceCalculator $calculator,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @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->priceOf($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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Actions;
|
||||
|
||||
use App\Enums\OccupationKind;
|
||||
use App\Models\BlockedPeriod;
|
||||
use App\Models\Booking;
|
||||
use App\Models\Channel;
|
||||
@@ -44,6 +45,10 @@ public function handle(BlockedPeriod $block, string $resolution, ?int $targetId
|
||||
'linked_booking_id' => $resolution === 'booking' ? $target->id : null,
|
||||
'review_note' => 'Persönlich zugeordnet; nur die führende Belegung steuert Verfügbarkeit und Export.'];
|
||||
}
|
||||
// A stay confirmed as independent with a known booking channel (or privately) is no longer "unclear".
|
||||
if ($resolution === 'independent' && ($originId !== null || $attributes['is_private']) && in_array($block->occupationKind(), [OccupationKind::Unknown], true)) {
|
||||
$attributes['occupation_kind'] = OccupationKind::Reservation;
|
||||
}
|
||||
$block->forceFill(['representation_automatic' => false])->fill($attributes)->save();
|
||||
app(ReconcileChannelRepresentations::class)->handle($block->property);
|
||||
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions;
|
||||
|
||||
use App\Availability\AvailabilityChecker;
|
||||
use App\Enums\BookingStatus;
|
||||
use App\Enums\BookingTaskKind;
|
||||
use App\Enums\BookingTaskStatus;
|
||||
use App\Exceptions\ReservationException;
|
||||
use App\Models\Booking;
|
||||
use App\Models\BookingTask;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
/**
|
||||
* Manual status change for processes the system does not drive itself (bookings entered by hand, portal bookings):
|
||||
* the landlord moves the booking along the stages and gives a reason, which is added to the internal notes.
|
||||
* Cancelling and declining are separate actions (they inform people and record costs). Making a booking binding
|
||||
* again checks the calendar like every other writer; no mail is sent and no contract is generated here.
|
||||
*/
|
||||
class SetBookingStatus
|
||||
{
|
||||
/** @var list<BookingStatus> */
|
||||
public const TARGETS = [BookingStatus::Reserved, BookingStatus::Confirmed, BookingStatus::DepositPaid, BookingStatus::Paid, BookingStatus::Completed];
|
||||
|
||||
public function __construct(private AvailabilityChecker $availability) {}
|
||||
|
||||
/**
|
||||
* @throws ReservationException
|
||||
*/
|
||||
public function handle(Booking $booking, BookingStatus $status, string $reason, string $by = 'Verwaltung'): Booking
|
||||
{
|
||||
if (! in_array($status, self::TARGETS, true)) {
|
||||
throw new ReservationException('Auf diesen Status kann nicht von Hand gewechselt werden. Stornieren und Ablehnen haben eigene Aktionen.');
|
||||
}
|
||||
|
||||
if (blank(trim($reason))) {
|
||||
throw new ReservationException('Bitte einen Grund für die Statusänderung angeben.');
|
||||
}
|
||||
|
||||
DB::transaction(function () use ($booking, $status, $reason, $by): void {
|
||||
$booking->lockForTransition();
|
||||
$from = $booking->status;
|
||||
|
||||
if ($from === $status) {
|
||||
throw new ReservationException('Die Buchung hat diesen Status bereits.');
|
||||
}
|
||||
|
||||
$becomesBinding = in_array($status, BookingStatus::occupying(), true) && ! in_array($from, BookingStatus::occupying(), true);
|
||||
if ($becomesBinding && ! $this->availability->isAvailable($booking->property, $booking->arrival, $booking->departure, ignore: $booking)) {
|
||||
throw ReservationException::notAvailable();
|
||||
}
|
||||
|
||||
$changes = ['status' => $status];
|
||||
if ($becomesBinding) {
|
||||
$changes += ['hold_expires_at' => null, 'confirmed_at' => $booking->confirmed_at ?? now(), 'cancelled_at' => null];
|
||||
}
|
||||
if ($status === BookingStatus::Reserved) {
|
||||
$changes['hold_expires_at'] = null;
|
||||
}
|
||||
|
||||
$line = now()->format('d.m.Y H:i').' '.$by.': Status von „'.$from->getLabel().'“ auf „'.$status->getLabel().'“ gesetzt – '.trim($reason);
|
||||
$booking->update($changes + ['internal_notes' => trim(($booking->internal_notes ? $booking->internal_notes."\n" : '').$line)]);
|
||||
|
||||
// A booking taken back into the process no longer needs the cancellation follow-up.
|
||||
if ($becomesBinding) {
|
||||
BookingTask::query()->where('booking_id', $booking->id)->where('status', BookingTaskStatus::Open)
|
||||
->whereIn('kind', [BookingTaskKind::CancellationFee, BookingTaskKind::CancellationRequest])
|
||||
->update(['status' => BookingTaskStatus::Done, 'completed_by' => $by, 'completed_at' => now()]);
|
||||
}
|
||||
});
|
||||
|
||||
return $booking->refresh();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user