presseportale/app/Models/BillingAddress.php
Kevin Adametz 1aa43914da WS-8: doppelte Logik konsolidieren (Tags, Kontakt-Query, Billing)
- Themen-Tag-Verwaltung (addTag/removeTag/tagsArray) war in create- und
  edit-Editor byte-identisch dupliziert -> Trait
  App\Livewire\Concerns\InteractsWithPressReleaseTags.
- Kontaktauswahl je Firma (withoutGlobalScopes + where + Sortierung) aus
  create/edit/dashboard in Contact::scopeForCompany() zentralisiert.
- Rechnungsadress-Pflichtfelder als BillingAddress::REQUIRED_FIELDS; isComplete()
  und neues completenessPercent() teilen die Liste, Dashboard nutzt es statt
  eigener Feldliste.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-18 13:33:59 +00:00

60 lines
1.5 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class BillingAddress extends Model
{
use HasFactory;
protected $fillable = [
'user_id',
'salutation_key',
'title',
'company',
'first_name',
'last_name',
'name',
'address1',
'address2',
'postal_code',
'city',
'country_code',
'vat_id',
];
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
/**
* Ist die Adresse vollständig genug für eine Rechnung bzw. Buchung?
* Maßgeblich: Empfänger (Name), Straße, PLZ, Ort und Land.
*
* @var list<string>
*/
public const REQUIRED_FIELDS = ['name', 'address1', 'postal_code', 'city', 'country_code'];
public function isComplete(): bool
{
return collect(self::REQUIRED_FIELDS)
->every(fn (string $field): bool => filled($this->{$field}));
}
/**
* Anteil der ausgefüllten Pflichtfelder in Prozent (0–100) — für die
* Fortschritts-Anzeige im Dashboard.
*/
public function completenessPercent(): int
{
$filled = collect(self::REQUIRED_FIELDS)
->filter(fn (string $field): bool => filled($this->{$field}))
->count();
return (int) round(($filled / count(self::REQUIRED_FIELDS)) * 100);
}
}