Datenmodell Kern: Projekt, PFA, Vertrag, LV, Nachtrag, Dokument
- Mandant, Auftragnehmer, Projekt mit Suchreihenfolge, Abschnitt (PFA), Vertrag, Leistungsverzeichnis, Nachtrag (MKA nur als Bezug), Nachtragsposition, Dokument - Projektmitglieder mit Projektrolle, Freigaben für vertrauliche Dokumente - Mandant, Land und Projekt werden vom übergeordneten Datensatz übernommen; Fehlzuordnungen über Mandanten oder Projekte hinweg werden abgewiesen - Feste Morph-Map, Factories, Demodaten (Musterbahn, PFA 1–4, N14/N16/N21), Tests Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
ca09d23a78
commit
6aac8b0a16
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\Land;
|
||||
use App\Models\Concerns\ErbtZuordnung;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Database\Factories\VertragFactory;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Attributes\Table;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
|
||||
/**
|
||||
* Auftrag an einen Auftragnehmer innerhalb eines Abschnitts, z. B. „Gleisbau“.
|
||||
* Sein Bau-Soll steht in den zugehörigen Leistungsverzeichnissen.
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $mandant_id
|
||||
* @property Land $land
|
||||
* @property int $projekt_id
|
||||
* @property int $abschnitt_id
|
||||
* @property int $auftragnehmer_id
|
||||
* @property string $bezeichnung
|
||||
* @property string|null $vertragsnummer
|
||||
* @property CarbonImmutable|null $vertrag_vom
|
||||
* @property CarbonImmutable|null $created_at
|
||||
* @property CarbonImmutable|null $updated_at
|
||||
*/
|
||||
#[Table('vertraege')]
|
||||
#[Fillable(['abschnitt_id', 'auftragnehmer_id', 'bezeichnung', 'vertragsnummer', 'vertrag_vom'])]
|
||||
class Vertrag extends Model
|
||||
{
|
||||
/** @use HasFactory<VertragFactory> */
|
||||
use ErbtZuordnung, HasFactory;
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'land' => Land::class,
|
||||
'vertrag_vom' => 'date',
|
||||
];
|
||||
}
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::saving(function (Vertrag $vertrag): void {
|
||||
$auftragnehmer = $vertrag->auftragnehmer()->first();
|
||||
|
||||
if ($auftragnehmer !== null) {
|
||||
$vertrag->gleicheZuordnungAn($auftragnehmer, [
|
||||
'mandant_id' => $auftragnehmer->mandant_id,
|
||||
'land' => $auftragnehmer->land,
|
||||
]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected function zuordnungsEltern(): ?Model
|
||||
{
|
||||
return $this->abschnitt()->first();
|
||||
}
|
||||
|
||||
/** @return BelongsTo<Projekt, $this> */
|
||||
public function projekt(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Projekt::class);
|
||||
}
|
||||
|
||||
/** @return BelongsTo<Abschnitt, $this> */
|
||||
public function abschnitt(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Abschnitt::class);
|
||||
}
|
||||
|
||||
/** @return BelongsTo<Auftragnehmer, $this> */
|
||||
public function auftragnehmer(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Auftragnehmer::class);
|
||||
}
|
||||
|
||||
/** @return HasMany<Leistungsverzeichnis, $this> */
|
||||
public function leistungsverzeichnisse(): HasMany
|
||||
{
|
||||
return $this->hasMany(Leistungsverzeichnis::class);
|
||||
}
|
||||
|
||||
/** @return HasMany<Nachtrag, $this> */
|
||||
public function nachtraege(): HasMany
|
||||
{
|
||||
return $this->hasMany(Nachtrag::class);
|
||||
}
|
||||
|
||||
/** @return MorphMany<Dokument, $this> */
|
||||
public function dokumente(): MorphMany
|
||||
{
|
||||
return $this->morphMany(Dokument::class, 'dokumentable');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user