Phase 3: Zahlungen, Mietvertrag, Erinnerungen, Anreiseinformationen
- Zahlungen erfassen (inkl. Erstattungen), Status automatisch: Bestätigt → Anzahlung erhalten → Bezahlt → Abgeschlossen - Anzahlungsfrist bei Bestätigung; kurzfristige Buchungen: Gesamtbetrag sofort - Mietvertrag als PDF (dompdf, Font-Subsetting), bei Bestätigung gespeichert und angehängt; Texte im Admin (Muster) - Täglich: Zahlungserinnerungen (Anzahlung/Rest überfällig, Kopie an Vermieter), Zahlungsaufforderung Rest 7 Tage vorher, Anreiseinfos 7 Tage vorher, Abschluss nach Abreise - Admin: Zahlungen je Buchung, offene Beträge, Vertrag herunterladen/neu erzeugen Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e5f9e0762f
commit
0bf302fcf9
29 files changed
+1248
-18
No files matched your search
@@ -3,6 +3,7 @@
|
||||
namespace App\Actions;
|
||||
|
||||
use App\Availability\AvailabilityChecker;
|
||||
use App\Documents\RentalContract;
|
||||
use App\Enums\BookingStatus;
|
||||
use App\Exceptions\ReservationException;
|
||||
use App\Mail\BookingConfirmed;
|
||||
@@ -11,11 +12,16 @@
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
/**
|
||||
* The landlord accepts a reservation. Expired reservations can still be confirmed while the dates are free.
|
||||
* The landlord accepts a reservation: the booking becomes binding, payment due dates are fixed,
|
||||
* the rental contract is generated and sent with the confirmation.
|
||||
* Expired reservations can still be confirmed while the dates are free.
|
||||
*/
|
||||
class ConfirmBooking
|
||||
{
|
||||
public function __construct(private AvailabilityChecker $availability) {}
|
||||
public function __construct(
|
||||
private AvailabilityChecker $availability,
|
||||
private RentalContract $contract,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @throws ReservationException
|
||||
@@ -35,9 +41,12 @@ public function handle(Booking $booking, bool $notifyGuest = true): void
|
||||
'status' => BookingStatus::Confirmed,
|
||||
'hold_expires_at' => null,
|
||||
'confirmed_at' => now(),
|
||||
'deposit_due_on' => today()->addDays(config('fewo.deposit_due_days'))->toDateString(),
|
||||
]);
|
||||
});
|
||||
|
||||
$this->contract->generate($booking);
|
||||
|
||||
if ($notifyGuest) {
|
||||
Mail::to($booking->guest->email, $booking->guest->full_name)->send(new BookingConfirmed($booking));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions;
|
||||
|
||||
use App\Enums\BookingStatus;
|
||||
use App\Enums\PaymentMethod;
|
||||
use App\Models\Booking;
|
||||
use App\Models\Payment;
|
||||
use Carbon\CarbonInterface;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
/**
|
||||
* Records a received payment (or a refund with a negative amount) and moves the booking along:
|
||||
* Bestätigt → Anzahlung erhalten → Bezahlt.
|
||||
*/
|
||||
class RecordPayment
|
||||
{
|
||||
public function handle(Booking $booking, int $amount, CarbonInterface $paidOn, PaymentMethod $method = PaymentMethod::Transfer, ?string $note = null, ?string $recordedBy = null): Payment
|
||||
{
|
||||
return DB::transaction(function () use ($booking, $amount, $paidOn, $method, $note, $recordedBy): Payment {
|
||||
$payment = $booking->payments()->create([
|
||||
'amount' => $amount,
|
||||
'paid_on' => $paidOn->toDateString(),
|
||||
'method' => $method,
|
||||
'note' => $note,
|
||||
'recorded_by' => $recordedBy,
|
||||
]);
|
||||
|
||||
$booking->unsetRelation('payments');
|
||||
$this->updateStatus($booking);
|
||||
|
||||
return $payment;
|
||||
});
|
||||
}
|
||||
|
||||
public function updateStatus(Booking $booking): void
|
||||
{
|
||||
$paymentStatuses = [BookingStatus::Confirmed, BookingStatus::DepositPaid, BookingStatus::Paid];
|
||||
if (! in_array($booking->status, $paymentStatuses, true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$paid = $booking->paidAmount();
|
||||
$status = match (true) {
|
||||
$paid >= $booking->total => BookingStatus::Paid,
|
||||
$paid >= $booking->deposit && $paid > 0 => BookingStatus::DepositPaid,
|
||||
default => BookingStatus::Confirmed,
|
||||
};
|
||||
|
||||
if ($status !== $booking->status) {
|
||||
$booking->update(['status' => $status]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions;
|
||||
|
||||
use App\Enums\BookingStatus;
|
||||
use App\Mail\ArrivalInformation;
|
||||
use App\Mail\PaymentReminder;
|
||||
use App\Models\Booking;
|
||||
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.
|
||||
*/
|
||||
class SendBookingReminders
|
||||
{
|
||||
private const BALANCE_REQUEST_DAYS_BEFORE = 7;
|
||||
|
||||
private const ARRIVAL_INFO_DAYS_BEFORE = 7;
|
||||
|
||||
/**
|
||||
* @return array{deposit_overdue: int, balance_request: int, balance_overdue: int, arrival_info: int, completed: int}
|
||||
*/
|
||||
public function handle(): array
|
||||
{
|
||||
$today = today();
|
||||
$unpaid = [BookingStatus::Confirmed, BookingStatus::DepositPaid];
|
||||
|
||||
$depositOverdue = $this->bookings(fn (Builder $query) => $query
|
||||
->where('status', BookingStatus::Confirmed)
|
||||
->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');
|
||||
|
||||
$balanceRequest = $this->bookings(fn (Builder $query) => $query
|
||||
->whereIn('status', $unpaid)
|
||||
->whereNull('balance_requested_at')
|
||||
->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');
|
||||
|
||||
$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');
|
||||
|
||||
$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)));
|
||||
foreach ($arrivals as $booking) {
|
||||
Mail::to($booking->guest->email, $booking->guest->full_name)->send(new ArrivalInformation($booking));
|
||||
$booking->update(['arrival_info_sent_at' => now()]);
|
||||
}
|
||||
|
||||
$completed = Booking::query()
|
||||
->where('status', BookingStatus::Paid)
|
||||
->whereDate('departure', '<', $today)
|
||||
->get();
|
||||
$completed->each->update(['status' => BookingStatus::Completed]);
|
||||
|
||||
return [
|
||||
'deposit_overdue' => $depositOverdue->count(),
|
||||
'balance_request' => $balanceRequest->count(),
|
||||
'balance_overdue' => $balanceOverdue->count(),
|
||||
'arrival_info' => $arrivals->count(),
|
||||
'completed' => $completed->count(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable(Builder<Booking>): Builder<Booking> $constraints
|
||||
* @return Collection<int, Booking>
|
||||
*/
|
||||
private function bookings(callable $constraints): Collection
|
||||
{
|
||||
return $constraints(Booking::query()->with(['guest', 'property', 'payments']))
|
||||
->whereHas('guest', fn (Builder $query) => $query->whereNull('anonymized_at'))
|
||||
->get()
|
||||
->toBase();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection<int, Booking> $bookings
|
||||
*/
|
||||
private function remind(Collection $bookings, string $kind, string $sentAtColumn): void
|
||||
{
|
||||
foreach ($bookings as $booking) {
|
||||
Mail::to($booking->guest->email, $booking->guest->full_name)->send(new PaymentReminder($booking, $kind));
|
||||
$booking->update([$sentAtColumn => now()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user