Deploy FeWo mit PipelineManager / deploy (push) Successful in 4m44s
- Paket 8: Zahlungsarten (Gast an uns, laut Portal, Auszahlung, Erstattung), Portalbeträge als Angaben mit Quelle, Übersicht nach Zuständigkeit (R09). - Paket 5: Ändern mit Folgenvorschau, vereinbart oder dem Gast vorgeschlagen (signierter Link), ein Stornoweg mit Grund und Erstattung, Portalstorno erst nach Bestätigung. - Paket 6: eigene Nutzung, Besuch und Sperre als Vorgang mit Kurabgabe und Aufenthaltsbestätigung; Bestandsübernahme der Sperren mit identischem Export. - Wirksame Einstellungen (Expertenansicht), Abnahmekatalog T01–T14, Ergebnis-, Abnahme- und Konfigurationsdokument. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
61 lines
2.1 KiB
PHP
61 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Actions;
|
|
|
|
use App\Enums\BookingStatus;
|
|
use App\Enums\PaymentKind;
|
|
use App\Enums\PaymentMethod;
|
|
use App\Models\Booking;
|
|
use App\Models\Payment;
|
|
use Carbon\CarbonInterface;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
/**
|
|
* Records a payment of a case with its kind (package 8): the guest paid us, the portal reports the guest paid it, the
|
|
* portal paid out to us, or we refunded the guest. Only the guest's payments move the booking along
|
|
* (Bestätigt → Anzahlung erhalten → Bezahlt); a refund is stored as a negative amount.
|
|
*/
|
|
class RecordPayment
|
|
{
|
|
public function handle(Booking $booking, int $amount, CarbonInterface $paidOn, PaymentMethod $method = PaymentMethod::Transfer, ?string $note = null, ?string $recordedBy = null, PaymentKind $kind = PaymentKind::Guest, ?string $source = null): Payment
|
|
{
|
|
$amount = $kind === PaymentKind::Refund ? -abs($amount) : $amount;
|
|
|
|
return DB::transaction(function () use ($booking, $amount, $paidOn, $method, $note, $recordedBy, $kind, $source): Payment {
|
|
$payment = $booking->payments()->create([
|
|
'amount' => $amount,
|
|
'paid_on' => $paidOn->toDateString(),
|
|
'method' => $method,
|
|
'note' => $note,
|
|
'recorded_by' => $recordedBy,
|
|
'kind' => $kind,
|
|
'source' => $source,
|
|
]);
|
|
|
|
$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]);
|
|
}
|
|
}
|
|
}
|