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>
This commit is contained in:
parent
1ff1cc3626
commit
1aa43914da
6 changed files with 115 additions and 134 deletions
|
|
@ -34,13 +34,27 @@ class BillingAddress extends Model
|
|||
/**
|
||||
* 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 filled($this->name)
|
||||
&& filled($this->address1)
|
||||
&& filled($this->postal_code)
|
||||
&& filled($this->city)
|
||||
&& filled($this->country_code);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ namespace App\Models;
|
|||
use App\Enums\Portal;
|
||||
use App\Scopes\PortalScope;
|
||||
use Database\Factories\ContactFactory;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
|
@ -21,6 +22,19 @@ class Contact extends Model
|
|||
static::addGlobalScope(new PortalScope);
|
||||
}
|
||||
|
||||
/**
|
||||
* Kontakte einer Firma, portal-unabhängig (ohne GlobalScope) und in der
|
||||
* fürs Kunden-Panel üblichen Sortierung. Single Source of Truth für die
|
||||
* Kontaktauswahl in Erstellen/Bearbeiten und für Kontakt-Zählungen.
|
||||
*/
|
||||
public function scopeForCompany(Builder $query, int $companyId): Builder
|
||||
{
|
||||
return $query->withoutGlobalScopes()
|
||||
->where('company_id', $companyId)
|
||||
->orderBy('last_name')
|
||||
->orderBy('first_name');
|
||||
}
|
||||
|
||||
protected $fillable = [
|
||||
'company_id',
|
||||
'portal',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue