Creating Participation refunds
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
<?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 $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',
|
||||
'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');
|
||||
}
|
||||
|
||||
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 ?? '');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user