Zahlungsaufgaben, Freigabe-/Storno-Link, Vertragsvorlagen, Anreise-Mail
Deploy FeWo mit PipelineManager / deploy (push) Successful in 3m36s
Deploy FeWo mit PipelineManager / deploy (push) Successful in 3m36s
- Zahlungen werden nicht mehr automatisch angemahnt: faellige Anzahlung/Restzahlung werden Aufgaben (Zahlungen & Wuensche, Tages-/Wochenuebersicht); Mail nur per Klick; je Portal und Buchungstyp abschaltbar - Freigabe-Link in der Eingangsbestaetigung, Storno-Link in der Buchungsbestaetigung; je Wohnung Wunsch / sofort / sofort bis Frist; Stornowuensche und Kosten bleiben Aufgabe des Gastgebers - Vertragsvorlagen mit Versionen (je Angebot, Portal oder Wohnung waehlbar), benutzte Versionen gesperrt; Angebot und finaler Vertrag als unveraenderliche PDF mit SHA-256, Vertrag wird nie neu geschrieben - Anreise-Mail je Wohnung einstellbar (Standard 3 Tage), neue Textfelder Schluessel/Parken/Ankunftstag Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
eafab8a2cb
commit
a73b164ea1
51 files changed
+1807
-52
No files matched your search
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions;
|
||||
|
||||
use App\Enums\BookingStatus;
|
||||
use App\Enums\BookingTaskKind;
|
||||
use App\Enums\BookingTaskStatus;
|
||||
use App\Enums\CancellationMode;
|
||||
use App\Exceptions\ReservationException;
|
||||
use App\Mail\BookingCancelled;
|
||||
use App\Mail\CancellationRequested;
|
||||
use App\Models\Booking;
|
||||
use App\Models\BookingTask;
|
||||
use App\Support\Settings;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* The guest uses the cancellation link of the booking confirmation. Depending on the property's setting the
|
||||
* booking is cancelled at once (dates released) or only a request task is created for the landlord – costs
|
||||
* are never settled automatically. Repeating the click changes nothing.
|
||||
*/
|
||||
class CancelBookingByGuest
|
||||
{
|
||||
/**
|
||||
* What a click on the link does for this booking today.
|
||||
*/
|
||||
public function modeFor(Booking $booking): CancellationMode
|
||||
{
|
||||
$property = $booking->property;
|
||||
$freeUntil = $booking->arrival->subDays($property->free_cancellation_days);
|
||||
|
||||
return match ($property->cancellation_mode) {
|
||||
CancellationMode::Instant => CancellationMode::Instant,
|
||||
CancellationMode::InstantWhenFree => today()->lessThanOrEqualTo($freeUntil) ? CancellationMode::Instant : CancellationMode::Request,
|
||||
default => CancellationMode::Request,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @return CancellationMode|null what happened (Instant = cancelled, Request = request recorded); null when it had happened before
|
||||
*
|
||||
* @throws ReservationException
|
||||
*/
|
||||
public function handle(Booking $booking, ?string $message = null): ?CancellationMode
|
||||
{
|
||||
$outcome = DB::transaction(function () use ($booking, $message): ?CancellationMode {
|
||||
$booking->lockForTransition();
|
||||
|
||||
$alreadyAsked = BookingTask::query()->where('booking_id', $booking->id)->where('kind', BookingTaskKind::CancellationRequest)->exists();
|
||||
if ($booking->status === BookingStatus::Cancelled || $alreadyAsked) {
|
||||
return null;
|
||||
}
|
||||
if (! in_array($booking->status, BookingStatus::occupying(), true) || $booking->arrival->isPast()) {
|
||||
throw ReservationException::invalidTransition($booking->status->getLabel(), 'storniert');
|
||||
}
|
||||
|
||||
$mode = $this->modeFor($booking);
|
||||
if ($mode === CancellationMode::Instant) {
|
||||
$booking->update(['status' => BookingStatus::Cancelled, 'cancelled_at' => now()]);
|
||||
}
|
||||
BookingTask::query()->create([
|
||||
'booking_id' => $booking->id,
|
||||
'kind' => BookingTaskKind::CancellationRequest,
|
||||
'status' => BookingTaskStatus::Open,
|
||||
'note' => trim(($mode === CancellationMode::Instant ? 'Vom Gast storniert – bitte Stornokosten und Rückzahlung prüfen. ' : '').($message ?? '')) ?: null,
|
||||
]);
|
||||
|
||||
return $mode;
|
||||
});
|
||||
|
||||
if ($outcome !== null) {
|
||||
$this->notify($booking, $outcome);
|
||||
}
|
||||
|
||||
return $outcome;
|
||||
}
|
||||
|
||||
private function notify(Booking $booking, CancellationMode $mode): void
|
||||
{
|
||||
$booking->loadMissing(['guest', 'property']);
|
||||
$cancelled = $mode === CancellationMode::Instant;
|
||||
|
||||
$sends = [
|
||||
fn () => Mail::to(Settings::notificationRecipients())->send(new CancellationRequested($booking, $cancelled)),
|
||||
fn () => $booking->guest?->email ? Mail::to($booking->guest->email, $booking->guest->full_name)->send(new BookingCancelled($booking, $cancelled)) : null,
|
||||
];
|
||||
foreach ($sends as $send) {
|
||||
try {
|
||||
$send();
|
||||
} catch (Throwable $exception) {
|
||||
Log::warning('Stornomitteilung nicht zugestellt', ['booking' => $booking->id, 'exception' => $exception::class]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions;
|
||||
|
||||
use App\Enums\BookingStatus;
|
||||
use App\Exceptions\ReservationException;
|
||||
use App\Mail\OfferAnswered;
|
||||
use App\Models\Booking;
|
||||
use App\Support\Settings;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* The guest releases a held request or offer through the link in the mail – the dates are free again at once.
|
||||
* Repeating it is harmless. The link only reaches requests that are still held; a binding booking is never touched.
|
||||
*/
|
||||
class ReleaseReservation
|
||||
{
|
||||
/**
|
||||
* @return bool true when this call released the dates, false when they had been released before
|
||||
*
|
||||
* @throws ReservationException
|
||||
*/
|
||||
public function handle(Booking $booking): bool
|
||||
{
|
||||
$released = DB::transaction(function () use ($booking): bool {
|
||||
$booking->lockForTransition();
|
||||
|
||||
if ($booking->status === BookingStatus::Declined && $booking->declined_by === 'guest') {
|
||||
return false;
|
||||
}
|
||||
if (! in_array($booking->status, BookingStatus::holding(), true)) {
|
||||
throw ReservationException::invalidTransition($booking->status->getLabel(), 'freigegeben');
|
||||
}
|
||||
|
||||
$booking->update(['status' => BookingStatus::Declined, 'declined_by' => 'guest', 'hold_expires_at' => null]);
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
if ($released) {
|
||||
try {
|
||||
Mail::to(Settings::notificationRecipients())->send(new OfferAnswered($booking, accepted: false));
|
||||
} catch (Throwable $exception) {
|
||||
Log::warning('Meldung über Freigabe nicht zugestellt', ['booking' => $booking->id, 'exception' => $exception::class]);
|
||||
}
|
||||
}
|
||||
|
||||
return $released;
|
||||
}
|
||||
}
|
||||
@@ -3,22 +3,27 @@
|
||||
namespace App\Actions;
|
||||
|
||||
use App\Enums\BookingStatus;
|
||||
use App\Enums\BookingTaskKind;
|
||||
use App\Enums\BookingTaskStatus;
|
||||
use App\Mail\ArrivalInformation;
|
||||
use App\Mail\PaymentReminder;
|
||||
use App\Models\Booking;
|
||||
use App\Models\BookingTask;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
/**
|
||||
* Daily booking workflow: payment requests and reminders, arrival information, completion after departure.
|
||||
* Every message is sent at most once per booking.
|
||||
* Daily booking workflow. Payments are never chased automatically: due payments become tasks for the landlord
|
||||
* (BookingTask, once per booking and kind) who checks the payment and sends the reminder on a click
|
||||
* ({@see SendPaymentReminder}). Only the arrival information goes out by itself, once per booking, the configured
|
||||
* number of days before arrival. Completion after departure.
|
||||
*/
|
||||
class SendBookingReminders
|
||||
{
|
||||
private const BALANCE_REQUEST_DAYS_BEFORE = 7;
|
||||
|
||||
private const ARRIVAL_INFO_DAYS_BEFORE = 7;
|
||||
/** Upper bound of the per-property setting; the property decides the actual day. */
|
||||
private const ARRIVAL_INFO_MAX_DAYS_BEFORE = 14;
|
||||
|
||||
/**
|
||||
* @return array{deposit_overdue: int, balance_request: int, balance_overdue: int, arrival_info: int, completed: int}
|
||||
@@ -33,7 +38,7 @@ public function handle(): array
|
||||
->whereNull('deposit_reminded_at')
|
||||
->whereDate('deposit_due_on', '<', $today))
|
||||
->filter(fn (Booking $booking): bool => $booking->openDeposit() > 0);
|
||||
$this->remind($depositOverdue, PaymentReminder::DEPOSIT_OVERDUE, 'deposit_reminded_at');
|
||||
$depositTasks = $this->createTasks($depositOverdue, BookingTaskKind::DepositReminder, fn (Booking $booking) => $booking->deposit_due_on);
|
||||
|
||||
$balanceRequest = $this->bookings(fn (Builder $query) => $query
|
||||
->whereIn('status', $unpaid)
|
||||
@@ -41,20 +46,21 @@ public function handle(): array
|
||||
->whereDate('balance_due_on', '>=', $today)
|
||||
->whereDate('balance_due_on', '<=', $today->copy()->addDays(self::BALANCE_REQUEST_DAYS_BEFORE)))
|
||||
->filter(fn (Booking $booking): bool => ! $booking->requiresFullPayment() && $booking->openAmount() > 0 && $booking->status === BookingStatus::DepositPaid);
|
||||
$this->remind($balanceRequest, PaymentReminder::BALANCE_REQUEST, 'balance_requested_at');
|
||||
$requestTasks = $this->createTasks($balanceRequest, BookingTaskKind::BalanceRequest, fn (Booking $booking) => $booking->balance_due_on);
|
||||
|
||||
$balanceOverdue = $this->bookings(fn (Builder $query) => $query
|
||||
->whereIn('status', $unpaid)
|
||||
->whereNull('balance_reminded_at')
|
||||
->whereDate('balance_due_on', '<', $today))
|
||||
->filter(fn (Booking $booking): bool => $booking->openAmount() > 0 && ($booking->status === BookingStatus::DepositPaid || $booking->requiresFullPayment()));
|
||||
$this->remind($balanceOverdue, PaymentReminder::BALANCE_OVERDUE, 'balance_reminded_at');
|
||||
$overdueTasks = $this->createTasks($balanceOverdue, BookingTaskKind::BalanceReminder, fn (Booking $booking) => $booking->balance_due_on);
|
||||
|
||||
$arrivals = $this->bookings(fn (Builder $query) => $query
|
||||
->whereIn('status', BookingStatus::occupying())
|
||||
->whereNull('arrival_info_sent_at')
|
||||
->whereDate('arrival', '>=', $today)
|
||||
->whereDate('arrival', '<=', $today->copy()->addDays(self::ARRIVAL_INFO_DAYS_BEFORE)));
|
||||
->whereDate('arrival', '<=', $today->copy()->addDays(self::ARRIVAL_INFO_MAX_DAYS_BEFORE)))
|
||||
->filter(fn (Booking $booking): bool => $booking->arrival->lessThanOrEqualTo($today->copy()->addDays($booking->property->arrival_info_days_before)));
|
||||
foreach ($arrivals as $booking) {
|
||||
Mail::to($booking->guest->email, $booking->guest->full_name)->send(new ArrivalInformation($booking));
|
||||
$booking->update(['arrival_info_sent_at' => now()]);
|
||||
@@ -67,9 +73,9 @@ public function handle(): array
|
||||
$completed->each->update(['status' => BookingStatus::Completed]);
|
||||
|
||||
return [
|
||||
'deposit_overdue' => $depositOverdue->count(),
|
||||
'balance_request' => $balanceRequest->count(),
|
||||
'balance_overdue' => $balanceOverdue->count(),
|
||||
'deposit_overdue' => $depositTasks,
|
||||
'balance_request' => $requestTasks,
|
||||
'balance_overdue' => $overdueTasks,
|
||||
'arrival_info' => $arrivals->count(),
|
||||
'completed' => $completed->count(),
|
||||
];
|
||||
@@ -81,7 +87,7 @@ public function handle(): array
|
||||
*/
|
||||
private function bookings(callable $constraints): Collection
|
||||
{
|
||||
return $constraints(Booking::query()->with(['guest', 'property', 'payments']))
|
||||
return $constraints(Booking::query()->with(['guest', 'property', 'payments', 'importChannel', 'originChannel']))
|
||||
->whereHas('guest', fn (Builder $query) => $query->whereNull('anonymized_at')->whereNotNull('email')->where('email', '!=', ''))
|
||||
->get()
|
||||
->toBase();
|
||||
@@ -89,12 +95,20 @@ private function bookings(callable $constraints): Collection
|
||||
|
||||
/**
|
||||
* @param Collection<int, Booking> $bookings
|
||||
* @param callable(Booking): mixed $dueOn
|
||||
* @return int the number of tasks created now
|
||||
*/
|
||||
private function remind(Collection $bookings, string $kind, string $sentAtColumn): void
|
||||
private function createTasks(Collection $bookings, BookingTaskKind $kind, callable $dueOn): int
|
||||
{
|
||||
foreach ($bookings as $booking) {
|
||||
Mail::to($booking->guest->email, $booking->guest->full_name)->send(new PaymentReminder($booking, $kind));
|
||||
$booking->update([$sentAtColumn => now()]);
|
||||
$created = 0;
|
||||
foreach ($bookings->filter(fn (Booking $booking): bool => $booking->wantsPaymentTasks()) as $booking) {
|
||||
$task = BookingTask::query()->firstOrCreate(
|
||||
['booking_id' => $booking->id, 'kind' => $kind],
|
||||
['status' => BookingTaskStatus::Open, 'due_on' => $dueOn($booking)],
|
||||
);
|
||||
$created += $task->wasRecentlyCreated ? 1 : 0;
|
||||
}
|
||||
|
||||
return $created;
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@
|
||||
use App\Filament\Resources\Bookings\BookingResource;
|
||||
use App\Mail\OfferMade;
|
||||
use App\Models\Booking;
|
||||
use App\Models\ContractTemplate;
|
||||
use App\Pricing\PriceCalculator;
|
||||
use App\Pricing\PriceQuote;
|
||||
use App\Pricing\QuoteException;
|
||||
@@ -42,7 +43,7 @@ public function __construct(
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @param array{arrival?: string, departure?: string, guests?: int, promo_code?: ?string, price_adjustment?: ?int, price_adjustment_label?: ?string, valid_until?: ?string, offer_message?: ?string, guest?: array<string, ?string>} $changes
|
||||
* @param array{arrival?: string, departure?: string, guests?: int, promo_code?: ?string, price_adjustment?: ?int, price_adjustment_label?: ?string, valid_until?: ?string, offer_message?: ?string, contract_template_id?: int|string|null, guest?: array<string, ?string>} $changes
|
||||
*
|
||||
* @throws QuoteException
|
||||
* @throws ReservationException
|
||||
@@ -97,7 +98,7 @@ public function handle(Booking $booking, array $changes = [], bool $sendMail = t
|
||||
'offer_version' => $booking->offer_version + 1,
|
||||
'offer_sent_at' => now(),
|
||||
'offer_message' => $changes['offer_message'] ?? null,
|
||||
'offer_terms' => OfferTerms::capture(),
|
||||
'offer_terms' => OfferTerms::capture($this->templateFor($booking, $changes)),
|
||||
]);
|
||||
$booking->refresh();
|
||||
$booking->update(['offer_hash' => OfferTerms::hash($booking)]);
|
||||
@@ -113,6 +114,20 @@ public function handle(Booking $booking, array $changes = [], bool $sendMail = t
|
||||
return $booking;
|
||||
}
|
||||
|
||||
/**
|
||||
* The contract template of this offer: chosen explicitly, else the portal's default, else the property's.
|
||||
*
|
||||
* @param array<string, mixed> $changes
|
||||
*/
|
||||
private function templateFor(Booking $booking, array $changes): ?ContractTemplate
|
||||
{
|
||||
$id = filled($changes['contract_template_id'] ?? null)
|
||||
? (int) $changes['contract_template_id']
|
||||
: ($booking->importChannel ?? $booking->originChannel)?->contract_template_id ?? $booking->property->contract_template_id;
|
||||
|
||||
return $id ? ContractTemplate::query()->find($id) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the offer mail. The offer is already saved (and its validity runs), so a failing mail server is
|
||||
* recorded in the admin inbox and reported to the caller instead of being lost.
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions;
|
||||
|
||||
use App\Exceptions\ReservationException;
|
||||
use App\Mail\PaymentReminder;
|
||||
use App\Models\BookingTask;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
/**
|
||||
* Sends the payment mail belonging to a task – only when the landlord decides to, after checking the payment.
|
||||
* The task is completed and the dispatch is recorded on the booking; a failing mail server leaves the task open.
|
||||
*/
|
||||
class SendPaymentReminder
|
||||
{
|
||||
/**
|
||||
* @throws ReservationException
|
||||
*/
|
||||
public function handle(BookingTask $task, string $by): void
|
||||
{
|
||||
$reminder = $task->kind->reminder();
|
||||
$booking = $task->booking->loadMissing(['guest', 'property', 'payments']);
|
||||
|
||||
if ($reminder === null) {
|
||||
throw new ReservationException('Zu dieser Aufgabe gibt es keine Zahlungs-E-Mail.');
|
||||
}
|
||||
if (blank($booking->guest?->email)) {
|
||||
throw new ReservationException('Der Gast hat keine E-Mail-Adresse.');
|
||||
}
|
||||
if ($booking->openAmount() <= 0) {
|
||||
throw new ReservationException('Die Buchung ist bereits vollständig bezahlt.');
|
||||
}
|
||||
|
||||
[$kind, $column] = $reminder;
|
||||
Mail::to($booking->guest->email, $booking->guest->full_name)->send(new PaymentReminder($booking, $kind));
|
||||
$booking->update([$column => now()]);
|
||||
$task->complete($by);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user