CluPilotCloud/app/Livewire/Admin/CloseDunningCase.php

50 lines
1.3 KiB
PHP

<?php
namespace App\Livewire\Admin;
use App\Models\DunningCase;
use LivewireUI\Modal\ModalComponent;
/**
* Ein Eingriff von Hand in einen laufenden Mahnfall (R20: Eingabefeld, also
* Modal).
*
* Mutiert nichts selbst (R23) — der Bestätigen-Knopf löst ein Ereignis aus,
* das Admin\PaymentProblems auffängt. Die Berechtigungsprüfung bleibt damit an
* der einen Stelle, an der sie schon stand; hier wird sie zusätzlich gestellt,
* weil ein Modal ohne die Route-Middleware der Seite erreichbar ist.
*/
class CloseDunningCase extends ModalComponent
{
public int $id;
public string $note = '';
public int|string $days = 7;
public string $label = '';
public function mount(int $id): void
{
$this->authorize('billing.manage');
$case = DunningCase::query()->with('subscription.customer')->findOr($id, fn () => abort(404));
$this->id = $case->id;
$this->label = $case->subscription?->customer?->name ?? '—';
}
public function confirm(): void
{
$this->authorize('billing.manage');
$this->dispatch('dunning-case-closed', id: $this->id, days: (int) $this->days, note: $this->note);
$this->closeModal();
}
public function render()
{
return view('livewire.admin.close-dunning-case');
}
}