Zahlungszwecke
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enumerations;
|
||||
|
||||
use App\Scopes\CommonModel;
|
||||
|
||||
/**
|
||||
* Gründe für eine Reisekostenabrechnung -- DB-gestützt (analog {@see RetentionReason}), damit die
|
||||
* Auswahl ohne Deployment pflegbar bleibt.
|
||||
*
|
||||
* Gespeichert wird an der Abrechnung der Slug, bei `other` stattdessen der Freitext: Der Slug sagt für
|
||||
* sich nichts aus, der Text alles. {@see \App\Models\Invoice::travelReasonText()} löst beides auf.
|
||||
*
|
||||
* @property string $slug
|
||||
* @property string $name
|
||||
* @property bool $requires_note
|
||||
* @property int $sort_order
|
||||
*/
|
||||
class TravelReason extends CommonModel
|
||||
{
|
||||
public const string EVENT_TRAVEL = 'event_travel';
|
||||
|
||||
public const string MATERIAL_TRANSPORT = 'material_transport';
|
||||
|
||||
public const string PURCHASE = 'purchase';
|
||||
|
||||
public const string OTHER = 'other';
|
||||
|
||||
protected $table = 'travel_reasons';
|
||||
protected $primaryKey = 'slug';
|
||||
public $incrementing = false;
|
||||
protected $keyType = 'string';
|
||||
|
||||
protected $fillable = [
|
||||
'slug',
|
||||
'name',
|
||||
'requires_note',
|
||||
'sort_order',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'requires_note' => 'boolean',
|
||||
'sort_order' => 'integer',
|
||||
];
|
||||
|
||||
/**
|
||||
* Ein gespeicherter Wert als lesbarer Text: der Name des Grundes, sonst der Wert selbst.
|
||||
*
|
||||
* Der ist dann der Freitext von "Anderer Grund" oder stammt aus der Zeit vor der Auswahl -- beides
|
||||
* ist bereits die Antwort auf die Frage und braucht keine Übersetzung.
|
||||
*/
|
||||
public static function text(?string $value): string
|
||||
{
|
||||
return self::find($value)?->name ?? (string) $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Optionen für das Frontend. `requiresNote` steuert dort das Freitextfeld.
|
||||
*
|
||||
* @return array<int, array{value: string, label: string, requiresNote: bool}>
|
||||
*/
|
||||
public static function options(): array
|
||||
{
|
||||
return self::orderBy('sort_order')->get()
|
||||
->map(static fn (self $reason): array => [
|
||||
'value' => $reason->slug,
|
||||
'label' => $reason->name,
|
||||
'requiresNote' => $reason->requires_note,
|
||||
])
|
||||
->all();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user