133 lines
3.6 KiB
PHP
133 lines
3.6 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Casts\AmountCast;
|
|
use App\Enumerations\RefundReason;
|
|
use App\Scopes\InstancedModel;
|
|
use App\ValueObjects\Amount;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
/**
|
|
* Ein Erstattungsvorgang zu einer Anmeldung.
|
|
*
|
|
* @property int $id
|
|
* @property string $tenant
|
|
* @property int $event_id
|
|
* @property int $event_participant_id
|
|
* @property string $token
|
|
* @property string $status
|
|
* @property Amount|null $amount
|
|
* @property string|null $reason
|
|
* @property string|null $reason_note
|
|
* @property string|null $account_owner
|
|
* @property string|null $account_iban
|
|
* @property int|null $captured_by
|
|
* @property int|null $invoice_id
|
|
* @property int|null $released_by
|
|
* @property \Illuminate\Support\Carbon|null $released_at
|
|
* @property \Illuminate\Support\Carbon|null $accepted_at
|
|
* @property \Illuminate\Support\Carbon|null $cancelled_at
|
|
*/
|
|
class ParticipantRefund extends InstancedModel
|
|
{
|
|
/** Freigegeben, wartet auf die Bankverbindung des Teilis. */
|
|
public const string STATUS_PENDING = 'pending';
|
|
|
|
/** Der Teili hat bestätigt, der Beleg ist erstellt. Ab hier unveränderlich. */
|
|
public const string STATUS_ACCEPTED = 'accepted';
|
|
|
|
/** Von der Aktionsleitung abgebrochen, bevor der Teili bestätigt hat. */
|
|
public const string STATUS_CANCELLED = 'cancelled';
|
|
|
|
protected $table = 'participant_refunds';
|
|
|
|
protected $fillable = [
|
|
'tenant',
|
|
'event_id',
|
|
'event_participant_id',
|
|
'token',
|
|
'status',
|
|
'amount',
|
|
'reason',
|
|
'reason_note',
|
|
'account_owner',
|
|
'account_iban',
|
|
'captured_by',
|
|
'invoice_id',
|
|
'released_by',
|
|
'released_at',
|
|
'accepted_at',
|
|
'cancelled_at',
|
|
];
|
|
|
|
protected $casts = [
|
|
'amount' => AmountCast::class,
|
|
'released_at' => 'datetime',
|
|
'accepted_at' => 'datetime',
|
|
'cancelled_at' => 'datetime',
|
|
];
|
|
|
|
public function participant(): BelongsTo
|
|
{
|
|
return $this->belongsTo(EventParticipant::class, 'event_participant_id');
|
|
}
|
|
|
|
public function event(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Event::class);
|
|
}
|
|
|
|
/**
|
|
* Der Grund als Stammdatensatz. Nicht `reason()`, weil das die Spalte `reason` verdecken würde.
|
|
*/
|
|
public function reasonRelation(): BelongsTo
|
|
{
|
|
return $this->belongsTo(RefundReason::class, 'reason', 'slug');
|
|
}
|
|
|
|
/**
|
|
* Die Abrechnung, die aus diesem Vorgang entstanden ist. Der Auszahlungsstand steht dort und wird
|
|
* hier nicht gedoppelt.
|
|
*/
|
|
public function invoice(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Invoice::class);
|
|
}
|
|
|
|
/**
|
|
* Wer die Bankverbindung aufgenommen hat -- leer, wenn der Teili sie selbst eingetragen hat.
|
|
*/
|
|
public function capturedBy(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'captured_by');
|
|
}
|
|
|
|
/** Ob die Angaben von der Aktionsleitung stammen und nicht vom Teili selbst. */
|
|
public function wasCapturedByManagement(): bool
|
|
{
|
|
return $this->captured_by !== null;
|
|
}
|
|
|
|
public function isPending(): bool
|
|
{
|
|
return $this->status === self::STATUS_PENDING;
|
|
}
|
|
|
|
public function isAccepted(): bool
|
|
{
|
|
return $this->status === self::STATUS_ACCEPTED;
|
|
}
|
|
|
|
/** Der auf dem Beleg auszuweisende Grundtext -- bei Freitext-Gründen der Text der Aktionsleitung. */
|
|
public function reasonText(): string
|
|
{
|
|
return $this->reasonRelation()->first()?->documentText($this->reason_note) ?? '';
|
|
}
|
|
|
|
public function reasonLabel(): string
|
|
{
|
|
return (string) ($this->reasonRelation()->first()?->name ?? '');
|
|
}
|
|
}
|