Files
mareike/app/Enumerations/TaxExemptionReason.php
T
2026-08-12 17:18:45 +02:00

71 lines
2.2 KiB
PHP

<?php
namespace App\Enumerations;
use App\Scopes\CommonModel;
/**
* Gründe für eine Umsatzsteuerbefreiung -- DB-gestützt (analog {@see PaymentStatus}), damit Label und
* der auf der Rechnung verpflichtende Hinweis nach § 14 Abs. 4 Nr. 8 UStG zentral pflegbar sind.
* Gemeinnützigkeit allein befreit nicht; die Befreiung braucht immer einen konkreten Rechtsgrund
* (Vereins-Fälle über § 4 Nr. 22a / Nr. 25).
*
* @property string $slug
* @property string $name
* @property string $invoice_text
* @property bool $requires_note
* @property int $sort_order
*/
class TaxExemptionReason extends CommonModel
{
public const string USTG_19 = 'ustg_19';
public const string USTG_4_24 = 'ustg_4_24';
public const string USTG_4_25A = 'ustg_4_25a';
public const string USTG_4_22A = 'ustg_4_22a';
public const string CUSTOM = 'custom';
protected $table = 'tax_exemption_reasons';
protected $primaryKey = 'slug';
public $incrementing = false;
protected $keyType = 'string';
protected $fillable = [
'slug',
'name',
'invoice_text',
'requires_note',
'sort_order',
];
protected $casts = [
'requires_note' => 'boolean',
'sort_order' => 'integer',
];
/**
* Pflichthinweis für die Rechnung. Bei einem individuellen Grund (requires_note) wird der hinterlegte
* Freitext des Tenants verwendet.
*/
public function invoiceText(?string $customNote = null): string
{
return $this->requires_note ? trim((string) $customNote) : $this->invoice_text;
}
/**
* Optionen für das Frontend inkl. Vorschau-Text. Bei einem Freitext-Grund ist `text` leer, da der Text
* erst aus dem Freitext des Tenants entsteht.
*
* @return array<int, array{value: string, label: string, text: string}>
*/
public static function options(): array
{
return self::orderBy('sort_order')->get()
->map(static fn (self $reason): array => [
'value' => $reason->slug,
'label' => $reason->name,
'text' => $reason->requires_note ? '' : $reason->invoice_text,
])
->all();
}
}