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,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\Land;
|
||||
use App\Models\Concerns\ErbtZuordnung;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Database\Factories\AbschnittFactory;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Abschnitt eines Projekts, im Bahnbau meist ein PFA (Planfeststellungsabschnitt).
|
||||
* Wie er in der Oberfläche heißt, steht am Projekt (abschnitt_bezeichnung).
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $mandant_id
|
||||
* @property Land $land
|
||||
* @property int $projekt_id
|
||||
* @property string $bezeichnung
|
||||
* @property int $sortierung
|
||||
* @property CarbonImmutable|null $created_at
|
||||
* @property CarbonImmutable|null $updated_at
|
||||
*/
|
||||
#[Table('abschnitte')]
|
||||
#[Fillable(['projekt_id', 'bezeichnung', 'sortierung'])]
|
||||
class Abschnitt extends Model
|
||||
{
|
||||
/** @use HasFactory<AbschnittFactory> */
|
||||
use ErbtZuordnung, HasFactory;
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'land' => Land::class,
|
||||
];
|
||||
}
|
||||
|
||||
protected function zuordnungsEltern(): ?Model
|
||||
{
|
||||
return $this->projekt()->first();
|
||||
}
|
||||
|
||||
/** @return BelongsTo<Projekt, $this> */
|
||||
public function projekt(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Projekt::class);
|
||||
}
|
||||
|
||||
/** @return HasMany<Vertrag, $this> */
|
||||
public function vertraege(): HasMany
|
||||
{
|
||||
return $this->hasMany(Vertrag::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\Land;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Database\Factories\AuftragnehmerFactory;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Baufirma oder ARGE. Kann in mehreren Abschnitten eines Projekts Verträge haben.
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $mandant_id
|
||||
* @property Land $land
|
||||
* @property string $name
|
||||
* @property CarbonImmutable|null $created_at
|
||||
* @property CarbonImmutable|null $updated_at
|
||||
*/
|
||||
#[Table('auftragnehmer')]
|
||||
#[Fillable(['mandant_id', 'land', 'name'])]
|
||||
class Auftragnehmer extends Model
|
||||
{
|
||||
/** @use HasFactory<AuftragnehmerFactory> */
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'land' => Land::class,
|
||||
];
|
||||
}
|
||||
|
||||
/** @return BelongsTo<Mandant, $this> */
|
||||
public function mandant(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Mandant::class);
|
||||
}
|
||||
|
||||
/** @return HasMany<Vertrag, $this> */
|
||||
public function vertraege(): HasMany
|
||||
{
|
||||
return $this->hasMany(Vertrag::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Concerns;
|
||||
|
||||
use App\Models\Projekt;
|
||||
use BackedEnum;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use LogicException;
|
||||
|
||||
/**
|
||||
* Übernimmt mandant_id, land und projekt_id beim Speichern vom übergeordneten Datensatz.
|
||||
*
|
||||
* Zeigt ein Datensatz auf einen übergeordneten Datensatz eines anderen Mandanten, Landes oder
|
||||
* Projekts, wird das Speichern abgewiesen. So kann kein Vertrag in Projekt A an einem Abschnitt
|
||||
* aus Projekt B hängen.
|
||||
*/
|
||||
trait ErbtZuordnung
|
||||
{
|
||||
/**
|
||||
* Der übergeordnete Datensatz, von dem die Zuordnung übernommen wird.
|
||||
*/
|
||||
abstract protected function zuordnungsEltern(): ?Model;
|
||||
|
||||
protected static function bootErbtZuordnung(): void
|
||||
{
|
||||
static::saving(function (self $model): void {
|
||||
$model->uebernimmZuordnung();
|
||||
});
|
||||
}
|
||||
|
||||
protected function uebernimmZuordnung(): void
|
||||
{
|
||||
$eltern = $this->zuordnungsEltern();
|
||||
|
||||
if ($eltern === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->gleicheZuordnungAn($eltern, [
|
||||
'mandant_id' => $eltern->getAttribute('mandant_id'),
|
||||
'land' => $eltern->getAttribute('land'),
|
||||
'projekt_id' => $eltern instanceof Projekt ? $eltern->getKey() : $eltern->getAttribute('projekt_id'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setzt fehlende Werte und weist abweichende ab.
|
||||
*
|
||||
* @param array<string, mixed> $werte
|
||||
*/
|
||||
protected function gleicheZuordnungAn(Model $anderes, array $werte): void
|
||||
{
|
||||
foreach ($werte as $spalte => $wert) {
|
||||
$eigen = $this->getAttribute($spalte);
|
||||
|
||||
if ($eigen === null) {
|
||||
$this->setAttribute($spalte, $wert);
|
||||
} elseif (self::vergleichswert($eigen) !== self::vergleichswert($wert)) {
|
||||
throw new LogicException(sprintf(
|
||||
'%s: %s passt nicht zu %s.',
|
||||
class_basename($this),
|
||||
$spalte,
|
||||
class_basename($anderes),
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static function vergleichswert(mixed $wert): ?string
|
||||
{
|
||||
if ($wert instanceof BackedEnum) {
|
||||
return (string) $wert->value;
|
||||
}
|
||||
|
||||
return $wert === null ? null : (string) $wert;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\DokumentKategorie;
|
||||
use App\Enums\Land;
|
||||
use App\Models\Concerns\ErbtZuordnung;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Database\Factories\DokumentFactory;
|
||||
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\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
||||
|
||||
/**
|
||||
* Hochgeladene Datei im privaten Speicher. Gehört zu einem Projekt und optional zu einem LV,
|
||||
* Nachtrag oder Vertrag. Ohne Projekt ist es ein allgemeines Dokument (Einstellungen).
|
||||
* Vertrauliche Dokumente sehen nur die freigegebenen Personen.
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $mandant_id
|
||||
* @property Land $land
|
||||
* @property int|null $projekt_id
|
||||
* @property string|null $dokumentable_type
|
||||
* @property int|null $dokumentable_id
|
||||
* @property DokumentKategorie $kategorie
|
||||
* @property string $dateiname
|
||||
* @property string $pfad
|
||||
* @property string $mime_type
|
||||
* @property int $groesse
|
||||
* @property string $sha256
|
||||
* @property bool $vertraulich
|
||||
* @property int|null $hochgeladen_von
|
||||
* @property CarbonImmutable|null $created_at
|
||||
* @property CarbonImmutable|null $updated_at
|
||||
*/
|
||||
#[Table('dokumente')]
|
||||
#[Fillable([
|
||||
'mandant_id', 'land', 'projekt_id', 'kategorie', 'dateiname', 'pfad', 'mime_type',
|
||||
'groesse', 'sha256', 'vertraulich', 'hochgeladen_von',
|
||||
])]
|
||||
class Dokument extends Model
|
||||
{
|
||||
/** @use HasFactory<DokumentFactory> */
|
||||
use ErbtZuordnung, HasFactory;
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'land' => Land::class,
|
||||
'kategorie' => DokumentKategorie::class,
|
||||
'vertraulich' => 'boolean',
|
||||
'groesse' => 'integer',
|
||||
];
|
||||
}
|
||||
|
||||
protected function zuordnungsEltern(): ?Model
|
||||
{
|
||||
if ($this->dokumentable_type !== null) {
|
||||
return $this->dokumentable()->getResults();
|
||||
}
|
||||
|
||||
return $this->projekt()->first();
|
||||
}
|
||||
|
||||
/** @return BelongsTo<Projekt, $this> */
|
||||
public function projekt(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Projekt::class);
|
||||
}
|
||||
|
||||
/** @return MorphTo<Model, $this> */
|
||||
public function dokumentable(): MorphTo
|
||||
{
|
||||
return $this->morphTo();
|
||||
}
|
||||
|
||||
/** @return BelongsTo<User, $this> */
|
||||
public function hochgeladenVon(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'hochgeladen_von');
|
||||
}
|
||||
|
||||
/** @return BelongsToMany<User, $this> */
|
||||
public function freigaben(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(User::class, 'dokument_freigaben')->withTimestamps();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\Land;
|
||||
use App\Enums\VerarbeitungStatus;
|
||||
use App\Models\Concerns\ErbtZuordnung;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Database\Factories\LeistungsverzeichnisFactory;
|
||||
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\MorphMany;
|
||||
|
||||
/**
|
||||
* Ein LV des Vertrags. Die Dateien (X86, D86, PDF) hängen als Dokumente daran,
|
||||
* Positionen und Vorbemerkungen kommen mit dem GAEB-Import dazu.
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $mandant_id
|
||||
* @property Land $land
|
||||
* @property int $projekt_id
|
||||
* @property int $vertrag_id
|
||||
* @property string $bezeichnung
|
||||
* @property VerarbeitungStatus $import_status
|
||||
* @property string|null $import_fehler
|
||||
* @property CarbonImmutable|null $created_at
|
||||
* @property CarbonImmutable|null $updated_at
|
||||
*/
|
||||
#[Table('leistungsverzeichnisse')]
|
||||
#[Fillable(['vertrag_id', 'bezeichnung', 'import_status', 'import_fehler'])]
|
||||
class Leistungsverzeichnis extends Model
|
||||
{
|
||||
/** @use HasFactory<LeistungsverzeichnisFactory> */
|
||||
use ErbtZuordnung, HasFactory;
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'land' => Land::class,
|
||||
'import_status' => VerarbeitungStatus::class,
|
||||
];
|
||||
}
|
||||
|
||||
protected function zuordnungsEltern(): ?Model
|
||||
{
|
||||
return $this->vertrag()->first();
|
||||
}
|
||||
|
||||
/** @return BelongsTo<Projekt, $this> */
|
||||
public function projekt(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Projekt::class);
|
||||
}
|
||||
|
||||
/** @return BelongsTo<Vertrag, $this> */
|
||||
public function vertrag(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Vertrag::class);
|
||||
}
|
||||
|
||||
/** @return MorphMany<Dokument, $this> */
|
||||
public function dokumente(): MorphMany
|
||||
{
|
||||
return $this->morphMany(Dokument::class, 'dokumentable');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\CarbonImmutable;
|
||||
use Database\Factories\MandantFactory;
|
||||
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\HasMany;
|
||||
|
||||
/**
|
||||
* Kunde der Anwendung. Alle Fachdaten gehören genau einem Mandanten.
|
||||
*
|
||||
* @property int $id
|
||||
* @property string $name
|
||||
* @property CarbonImmutable|null $created_at
|
||||
* @property CarbonImmutable|null $updated_at
|
||||
*/
|
||||
#[Table('mandanten')]
|
||||
#[Fillable(['name'])]
|
||||
class Mandant extends Model
|
||||
{
|
||||
/** @use HasFactory<MandantFactory> */
|
||||
use HasFactory;
|
||||
|
||||
/** @return HasMany<Projekt, $this> */
|
||||
public function projekte(): HasMany
|
||||
{
|
||||
return $this->hasMany(Projekt::class);
|
||||
}
|
||||
|
||||
/** @return HasMany<Auftragnehmer, $this> */
|
||||
public function auftragnehmer(): HasMany
|
||||
{
|
||||
return $this->hasMany(Auftragnehmer::class);
|
||||
}
|
||||
|
||||
/** @return HasMany<User, $this> */
|
||||
public function benutzer(): HasMany
|
||||
{
|
||||
return $this->hasMany(User::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\Land;
|
||||
use App\Enums\NachtragStatus;
|
||||
use App\Models\Concerns\ErbtZuordnung;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Database\Factories\NachtragFactory;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Nachtrag eines Auftragnehmers zu einem Vertrag. Geprüft wird je Nachtragsposition, ob die
|
||||
* Leistung schon im Vertrag enthalten ist. Die MKA ist nur eine Bezugsnummer (mka_bezug).
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $mandant_id
|
||||
* @property Land $land
|
||||
* @property int $projekt_id
|
||||
* @property int $vertrag_id
|
||||
* @property string $nummer
|
||||
* @property CarbonImmutable $eingang_am
|
||||
* @property string $betreff
|
||||
* @property list<string>|null $mka_bezug
|
||||
* @property NachtragStatus $status
|
||||
* @property int|null $zugewiesen_an
|
||||
* @property CarbonImmutable|null $created_at
|
||||
* @property CarbonImmutable|null $updated_at
|
||||
*/
|
||||
#[Table('nachtraege')]
|
||||
#[Fillable(['vertrag_id', 'nummer', 'eingang_am', 'betreff', 'mka_bezug', 'status', 'zugewiesen_an'])]
|
||||
class Nachtrag extends Model
|
||||
{
|
||||
/** @use HasFactory<NachtragFactory> */
|
||||
use ErbtZuordnung, HasFactory;
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'land' => Land::class,
|
||||
'eingang_am' => 'date',
|
||||
'mka_bezug' => 'array',
|
||||
'status' => NachtragStatus::class,
|
||||
];
|
||||
}
|
||||
|
||||
protected function zuordnungsEltern(): ?Model
|
||||
{
|
||||
return $this->vertrag()->first();
|
||||
}
|
||||
|
||||
/** @return BelongsTo<Projekt, $this> */
|
||||
public function projekt(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Projekt::class);
|
||||
}
|
||||
|
||||
/** @return BelongsTo<Vertrag, $this> */
|
||||
public function vertrag(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Vertrag::class);
|
||||
}
|
||||
|
||||
/** @return BelongsTo<User, $this> */
|
||||
public function zugewiesenAn(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'zugewiesen_an');
|
||||
}
|
||||
|
||||
/** @return HasMany<Nachtragsposition, $this> */
|
||||
public function positionen(): HasMany
|
||||
{
|
||||
return $this->hasMany(Nachtragsposition::class)->orderBy('sortierung')->orderBy('id');
|
||||
}
|
||||
|
||||
/** @return MorphMany<Dokument, $this> */
|
||||
public function dokumente(): MorphMany
|
||||
{
|
||||
return $this->morphMany(Dokument::class, 'dokumentable');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\Land;
|
||||
use App\Models\Concerns\ErbtZuordnung;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Database\Factories\NachtragspositionFactory;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Position eines Nachtrags-LV. Der Einheitspreis ist in Phase 1 nur Information.
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $mandant_id
|
||||
* @property Land $land
|
||||
* @property int $projekt_id
|
||||
* @property int $nachtrag_id
|
||||
* @property string $oz
|
||||
* @property string $kurztext
|
||||
* @property string|null $langtext
|
||||
* @property string|null $menge
|
||||
* @property string|null $einheit
|
||||
* @property string|null $einheitspreis
|
||||
* @property int $sortierung
|
||||
* @property CarbonImmutable|null $created_at
|
||||
* @property CarbonImmutable|null $updated_at
|
||||
*/
|
||||
#[Table('nachtragspositionen')]
|
||||
#[Fillable(['nachtrag_id', 'oz', 'kurztext', 'langtext', 'menge', 'einheit', 'einheitspreis', 'sortierung'])]
|
||||
class Nachtragsposition extends Model
|
||||
{
|
||||
/** @use HasFactory<NachtragspositionFactory> */
|
||||
use ErbtZuordnung, HasFactory;
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'land' => Land::class,
|
||||
'menge' => 'decimal:3',
|
||||
'einheitspreis' => 'decimal:2',
|
||||
];
|
||||
}
|
||||
|
||||
protected function zuordnungsEltern(): ?Model
|
||||
{
|
||||
return $this->nachtrag()->first();
|
||||
}
|
||||
|
||||
/** @return BelongsTo<Nachtrag, $this> */
|
||||
public function nachtrag(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Nachtrag::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\Land;
|
||||
use App\Enums\Projektrolle;
|
||||
use App\Enums\ProjektStatus;
|
||||
use App\Enums\Vertragsgrundlage;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Database\Factories\ProjektFactory;
|
||||
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\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
/**
|
||||
* Bauprojekt, z. B. „Elektrifizierung Musterbahn“. Gliedert sich in Abschnitte (PFA).
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $mandant_id
|
||||
* @property Land $land
|
||||
* @property string $name
|
||||
* @property string|null $nummer
|
||||
* @property string $auftraggeber
|
||||
* @property Vertragsgrundlage $vertragsgrundlage
|
||||
* @property string $abschnitt_bezeichnung
|
||||
* @property ProjektStatus $status
|
||||
* @property bool $suche_andere_vertraege_im_abschnitt
|
||||
* @property bool $suche_andere_abschnitte
|
||||
* @property bool $suche_nur_gleicher_auftragnehmer
|
||||
* @property CarbonImmutable|null $created_at
|
||||
* @property CarbonImmutable|null $updated_at
|
||||
*/
|
||||
#[Table('projekte')]
|
||||
#[Fillable([
|
||||
'mandant_id', 'land', 'name', 'nummer', 'auftraggeber', 'vertragsgrundlage',
|
||||
'abschnitt_bezeichnung', 'status', 'suche_andere_vertraege_im_abschnitt',
|
||||
'suche_andere_abschnitte', 'suche_nur_gleicher_auftragnehmer',
|
||||
])]
|
||||
class Projekt extends Model
|
||||
{
|
||||
/** @use HasFactory<ProjektFactory> */
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'land' => Land::class,
|
||||
'vertragsgrundlage' => Vertragsgrundlage::class,
|
||||
'status' => ProjektStatus::class,
|
||||
'suche_andere_vertraege_im_abschnitt' => 'boolean',
|
||||
'suche_andere_abschnitte' => 'boolean',
|
||||
'suche_nur_gleicher_auftragnehmer' => 'boolean',
|
||||
];
|
||||
}
|
||||
|
||||
/** @return BelongsTo<Mandant, $this> */
|
||||
public function mandant(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Mandant::class);
|
||||
}
|
||||
|
||||
/** @return HasMany<Abschnitt, $this> */
|
||||
public function abschnitte(): HasMany
|
||||
{
|
||||
return $this->hasMany(Abschnitt::class)->orderBy('sortierung')->orderBy('id');
|
||||
}
|
||||
|
||||
/** @return HasMany<Vertrag, $this> */
|
||||
public function vertraege(): HasMany
|
||||
{
|
||||
return $this->hasMany(Vertrag::class);
|
||||
}
|
||||
|
||||
/** @return HasMany<Nachtrag, $this> */
|
||||
public function nachtraege(): HasMany
|
||||
{
|
||||
return $this->hasMany(Nachtrag::class);
|
||||
}
|
||||
|
||||
/** @return HasMany<Dokument, $this> */
|
||||
public function dokumente(): HasMany
|
||||
{
|
||||
return $this->hasMany(Dokument::class);
|
||||
}
|
||||
|
||||
/** @return BelongsToMany<User, $this> */
|
||||
public function mitglieder(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(User::class, 'projekt_mitglieder')
|
||||
->withPivot('rolle')
|
||||
->withTimestamps();
|
||||
}
|
||||
|
||||
/**
|
||||
* Rolle des Benutzers in diesem Projekt oder null, wenn er kein Mitglied ist.
|
||||
*/
|
||||
public function rolleVon(User $user): ?Projektrolle
|
||||
{
|
||||
/** @var string|null $rolle */
|
||||
$rolle = $this->mitglieder()->whereKey($user->getKey())->value('projekt_mitglieder.rolle');
|
||||
|
||||
return $rolle === null ? null : Projektrolle::from($rolle);
|
||||
}
|
||||
|
||||
public function istArchiviert(): bool
|
||||
{
|
||||
return $this->status === ProjektStatus::Archiviert;
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,8 @@ use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Attributes\Hidden;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Support\Carbon;
|
||||
@@ -18,6 +20,7 @@ use Spatie\Permission\Traits\HasRoles;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int|null $mandant_id
|
||||
* @property string $name
|
||||
* @property string $email
|
||||
* @property string|null $locale
|
||||
@@ -50,6 +53,24 @@ class User extends Authenticatable implements MustVerifyEmail, PasskeyUser
|
||||
];
|
||||
}
|
||||
|
||||
/** @return BelongsTo<Mandant, $this> */
|
||||
public function mandant(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Mandant::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Projekte, in denen der Benutzer Mitglied ist; die Projektrolle steht im Pivot (rolle).
|
||||
*
|
||||
* @return BelongsToMany<Projekt, $this>
|
||||
*/
|
||||
public function projekte(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Projekt::class, 'projekt_mitglieder')
|
||||
->withPivot('rolle')
|
||||
->withTimestamps();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user's initials
|
||||
*/
|
||||
|
||||
@@ -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