Add refund action to booking list/detail with full-refund toggle

- New RefundBookingTableAction on the booking list row and detail page,
  refunding a Confirmed booking directly via RefundBookingAction — no need
  to hunt up its Payment on the Refunds resource first.
- Payment::refundableBalance() extracted from RefundBookingAction's private
  balance check so both refund forms can display and cap against it.
- RefundBookingAction::resolveRefundablePayment() made public for the same
  reason (round-trip leg resolution reused by the UI).
- Both refund forms (ProcessRefundAction and the new booking action) gain a
  "Full refund" toggle, on by default, which refunds the payment's whole
  remaining balance without requiring a manually typed amount. Turning it
  off reveals an amount field capped at the refundable balance.
This commit is contained in:
Nyan Lin Paing
2026-08-30 14:46:26 +07:00
parent a905320d50
commit 231f5679ef
9 changed files with 368 additions and 15 deletions
@@ -10,6 +10,7 @@ use Modules\Booking\Models\Booking;
use Modules\Payment\Database\Factories\PaymentFactory;
use Modules\Payment\Enums\PaymentMethod;
use Modules\Payment\Enums\PaymentStatus;
use Modules\Payment\Enums\RefundStatus;
use Spatie\Activitylog\Models\Concerns\LogsActivity;
use Spatie\Activitylog\Support\LogOptions;
@@ -74,4 +75,17 @@ class Payment extends Model
{
return $this->hasMany(Refund::class);
}
/**
* What's left to refund on this Payment its total minus whatever has
* already been completed-refunded (partial refunds supported, domain.md
* §6). Shared by RefundBookingAction's own guard and the Filament refund
* forms, which surface it to staff before they submit.
*/
public function refundableBalance(): string
{
$alreadyRefunded = (string) $this->refunds()->where('status', RefundStatus::Completed->value)->sum('amount');
return bcsub((string) $this->amount, $alreadyRefunded, 2);
}
}