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
@@ -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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user