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,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
/** Art eines hochgeladenen Dokuments. */
|
||||
enum DokumentKategorie: string
|
||||
{
|
||||
case LvX86 = 'lv_x86';
|
||||
case LvD86 = 'lv_d86';
|
||||
case LvPdf = 'lv_pdf';
|
||||
case NachtragsLvX86 = 'nachtrags_lv_x86';
|
||||
case NachtragsLvD86 = 'nachtrags_lv_d86';
|
||||
case NachtragsLvPdf = 'nachtrags_lv_pdf';
|
||||
case Anschreiben = 'anschreiben';
|
||||
case Anlage = 'anlage';
|
||||
case Vorlage = 'vorlage';
|
||||
case Sonstiges = 'sonstiges';
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
/** Land mit eigenen Regeln (Normen, Begriffe, Anspruchsgrundlagen). */
|
||||
enum Land: string
|
||||
{
|
||||
case DE = 'DE';
|
||||
case AT = 'AT';
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
/** Bearbeitungsstand eines Nachtrags. */
|
||||
enum NachtragStatus: string
|
||||
{
|
||||
case Eingegangen = 'eingegangen';
|
||||
case Vorgeprueft = 'vorgeprueft';
|
||||
case InPruefung = 'in_pruefung';
|
||||
case Geprueft = 'geprueft';
|
||||
case Exportiert = 'exportiert';
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
/** Lebenszyklus eines Projekts; archivierte Projekte sind schreibgeschützt. */
|
||||
enum ProjektStatus: string
|
||||
{
|
||||
case Aktiv = 'aktiv';
|
||||
case Abgeschlossen = 'abgeschlossen';
|
||||
case Archiviert = 'archiviert';
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
/** Rolle eines Benutzers innerhalb eines Projekts. */
|
||||
enum Projektrolle: string
|
||||
{
|
||||
case Projektleiter = 'projektleiter';
|
||||
case Bearbeiter = 'bearbeiter';
|
||||
case Leser = 'leser';
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
/** Stand der Verarbeitung im Hintergrund (Import, Texterkennung, Indexierung). */
|
||||
enum VerarbeitungStatus: string
|
||||
{
|
||||
case Wartet = 'wartet';
|
||||
case Laeuft = 'laeuft';
|
||||
case Fertig = 'fertig';
|
||||
case Fehler = 'fehler';
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
/** Vertragsgrundlage eines Projekts. */
|
||||
enum Vertragsgrundlage: string
|
||||
{
|
||||
case VobB = 'vob_b';
|
||||
case Bgb = 'bgb';
|
||||
}
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,13 @@
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Models\Leistungsverzeichnis;
|
||||
use App\Models\Nachtrag;
|
||||
use App\Models\Projekt;
|
||||
use App\Models\User;
|
||||
use App\Models\Vertrag;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||
use Illuminate\Support\Facades\Date;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
@@ -33,6 +39,15 @@ class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
Date::use(CarbonImmutable::class);
|
||||
|
||||
// Feste Namen für polymorphe Beziehungen statt Klassennamen in der Datenbank.
|
||||
Relation::enforceMorphMap([
|
||||
'user' => User::class,
|
||||
'projekt' => Projekt::class,
|
||||
'vertrag' => Vertrag::class,
|
||||
'leistungsverzeichnis' => Leistungsverzeichnis::class,
|
||||
'nachtrag' => Nachtrag::class,
|
||||
]);
|
||||
|
||||
DB::prohibitDestructiveCommands(
|
||||
app()->isProduction(),
|
||||
);
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Abschnitt;
|
||||
use App\Models\Projekt;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<Abschnitt>
|
||||
*/
|
||||
class AbschnittFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'projekt_id' => Projekt::factory(),
|
||||
'bezeichnung' => 'PFA '.fake()->unique()->numberBetween(1, 999999),
|
||||
'sortierung' => 0,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Enums\Land;
|
||||
use App\Models\Auftragnehmer;
|
||||
use App\Models\Mandant;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<Auftragnehmer>
|
||||
*/
|
||||
class AuftragnehmerFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'mandant_id' => Mandant::factory(),
|
||||
'land' => Land::DE,
|
||||
'name' => fake()->unique()->company(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Enums\DokumentKategorie;
|
||||
use App\Models\Dokument;
|
||||
use App\Models\Projekt;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* @extends Factory<Dokument>
|
||||
*/
|
||||
class DokumentFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
$uuid = (string) Str::uuid();
|
||||
|
||||
return [
|
||||
'projekt_id' => Projekt::factory(),
|
||||
'kategorie' => DokumentKategorie::Sonstiges,
|
||||
'dateiname' => 'beispiel.pdf',
|
||||
'pfad' => 'dokumente/'.$uuid.'.pdf',
|
||||
'mime_type' => 'application/pdf',
|
||||
'groesse' => fake()->numberBetween(10_000, 5_000_000),
|
||||
'sha256' => hash('sha256', $uuid),
|
||||
'vertraulich' => false,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Dokument zu einem LV, Nachtrag oder Vertrag; Projekt, Mandant und Land kommen von dort.
|
||||
*/
|
||||
public function zu(Model $dokumentable, DokumentKategorie $kategorie): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'projekt_id' => null,
|
||||
'dokumentable_type' => $dokumentable->getMorphClass(),
|
||||
'dokumentable_id' => $dokumentable->getKey(),
|
||||
'kategorie' => $kategorie,
|
||||
]);
|
||||
}
|
||||
|
||||
public function vertraulich(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => ['vertraulich' => true]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Enums\VerarbeitungStatus;
|
||||
use App\Models\Leistungsverzeichnis;
|
||||
use App\Models\Vertrag;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<Leistungsverzeichnis>
|
||||
*/
|
||||
class LeistungsverzeichnisFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'vertrag_id' => Vertrag::factory(),
|
||||
'bezeichnung' => sprintf('LV %02d %s', fake()->numberBetween(1, 35), fake()->randomElement([
|
||||
'Baustelleneinrichtung', 'Oberbau', 'Entwässerung', 'Kabeltiefbau', 'Erdbau',
|
||||
])),
|
||||
'import_status' => VerarbeitungStatus::Wartet,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Mandant;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<Mandant>
|
||||
*/
|
||||
class MandantFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'name' => fake()->unique()->company(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Enums\NachtragStatus;
|
||||
use App\Models\Nachtrag;
|
||||
use App\Models\Vertrag;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<Nachtrag>
|
||||
*/
|
||||
class NachtragFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'vertrag_id' => Vertrag::factory(),
|
||||
'nummer' => 'N'.fake()->unique()->numberBetween(1, 999999),
|
||||
'eingang_am' => fake()->dateTimeBetween('-3 months'),
|
||||
'betreff' => fake()->sentence(4),
|
||||
'mka_bezug' => ['MKA '.fake()->numberBetween(1, 200)],
|
||||
'status' => NachtragStatus::Eingegangen,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Nachtrag;
|
||||
use App\Models\Nachtragsposition;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<Nachtragsposition>
|
||||
*/
|
||||
class NachtragspositionFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'nachtrag_id' => Nachtrag::factory(),
|
||||
'oz' => sprintf('01.%07d', fake()->unique()->numberBetween(1, 9999999)),
|
||||
'kurztext' => fake()->sentence(5),
|
||||
'langtext' => fake()->paragraph(),
|
||||
'menge' => fake()->randomFloat(3, 1, 2000),
|
||||
'einheit' => fake()->randomElement(['m', 'm²', 'm³', 'St', 'psch']),
|
||||
'einheitspreis' => fake()->randomFloat(2, 1, 500),
|
||||
'sortierung' => 0,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Enums\Land;
|
||||
use App\Enums\ProjektStatus;
|
||||
use App\Enums\Vertragsgrundlage;
|
||||
use App\Models\Mandant;
|
||||
use App\Models\Projekt;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<Projekt>
|
||||
*/
|
||||
class ProjektFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'mandant_id' => Mandant::factory(),
|
||||
'land' => Land::DE,
|
||||
'name' => 'Elektrifizierung '.fake()->city(),
|
||||
'nummer' => fake()->numerify('P-####'),
|
||||
'auftraggeber' => 'DB InfraGO AG',
|
||||
'vertragsgrundlage' => Vertragsgrundlage::VobB,
|
||||
'abschnitt_bezeichnung' => 'PFA',
|
||||
'status' => ProjektStatus::Aktiv,
|
||||
];
|
||||
}
|
||||
|
||||
public function archiviert(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => ['status' => ProjektStatus::Archiviert]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Abschnitt;
|
||||
use App\Models\Auftragnehmer;
|
||||
use App\Models\Vertrag;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<Vertrag>
|
||||
*/
|
||||
class VertragFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'abschnitt_id' => Abschnitt::factory(),
|
||||
// Auftragnehmer im selben Mandanten und Land wie der Abschnitt
|
||||
'auftragnehmer_id' => function (array $attributes) {
|
||||
$abschnitt = Abschnitt::query()->whereKey($attributes['abschnitt_id'])->firstOrFail();
|
||||
|
||||
return Auftragnehmer::factory()->state([
|
||||
'mandant_id' => $abschnitt->mandant_id,
|
||||
'land' => $abschnitt->land,
|
||||
]);
|
||||
},
|
||||
'bezeichnung' => fake()->randomElement(['Gleisbau', 'Tunnelbau', 'Oberleitung', 'Kabeltiefbau']),
|
||||
'vertragsnummer' => fake()->numerify('V-#####'),
|
||||
'vertrag_vom' => fake()->dateTimeBetween('-2 years', '-1 month'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,183 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Kern des Datenmodells: Mandant → Projekt → Abschnitt (PFA) → Vertrag → LVs und Nachträge.
|
||||
* Beschreibung in docs/datenmodell.md.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('mandanten', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name')->unique();
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->foreignId('mandant_id')->nullable()->after('id')->constrained('mandanten')->restrictOnDelete();
|
||||
});
|
||||
|
||||
Schema::create('auftragnehmer', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('mandant_id')->constrained('mandanten')->restrictOnDelete();
|
||||
$table->char('land', 2);
|
||||
$table->string('name');
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['mandant_id', 'land', 'name']);
|
||||
});
|
||||
|
||||
Schema::create('projekte', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('mandant_id')->constrained('mandanten')->restrictOnDelete();
|
||||
$table->char('land', 2);
|
||||
$table->string('name');
|
||||
$table->string('nummer', 100)->nullable();
|
||||
$table->string('auftraggeber');
|
||||
$table->string('vertragsgrundlage', 20)->default('vob_b');
|
||||
$table->string('abschnitt_bezeichnung', 50)->default('PFA');
|
||||
$table->string('status', 20)->default('aktiv');
|
||||
$table->boolean('suche_andere_vertraege_im_abschnitt')->default(false);
|
||||
$table->boolean('suche_andere_abschnitte')->default(true);
|
||||
$table->boolean('suche_nur_gleicher_auftragnehmer')->default(false);
|
||||
$table->timestamps();
|
||||
|
||||
$table->index(['mandant_id', 'land', 'status']);
|
||||
});
|
||||
|
||||
Schema::create('projekt_mitglieder', function (Blueprint $table) {
|
||||
$table->foreignId('projekt_id')->constrained('projekte')->cascadeOnDelete();
|
||||
$table->foreignId('user_id')->constrained('users')->cascadeOnDelete();
|
||||
$table->string('rolle', 20);
|
||||
$table->timestamps();
|
||||
|
||||
$table->primary(['projekt_id', 'user_id']);
|
||||
});
|
||||
|
||||
Schema::create('abschnitte', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('mandant_id')->constrained('mandanten')->restrictOnDelete();
|
||||
$table->char('land', 2);
|
||||
$table->foreignId('projekt_id')->constrained('projekte')->restrictOnDelete();
|
||||
$table->string('bezeichnung', 100);
|
||||
$table->unsignedSmallInteger('sortierung')->default(0);
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['projekt_id', 'bezeichnung']);
|
||||
});
|
||||
|
||||
Schema::create('vertraege', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('mandant_id')->constrained('mandanten')->restrictOnDelete();
|
||||
$table->char('land', 2);
|
||||
$table->foreignId('projekt_id')->constrained('projekte')->restrictOnDelete();
|
||||
$table->foreignId('abschnitt_id')->constrained('abschnitte')->restrictOnDelete();
|
||||
$table->foreignId('auftragnehmer_id')->constrained('auftragnehmer')->restrictOnDelete();
|
||||
$table->string('bezeichnung', 150);
|
||||
$table->string('vertragsnummer', 100)->nullable();
|
||||
$table->date('vertrag_vom')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
Schema::create('leistungsverzeichnisse', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('mandant_id')->constrained('mandanten')->restrictOnDelete();
|
||||
$table->char('land', 2);
|
||||
$table->foreignId('projekt_id')->constrained('projekte')->restrictOnDelete();
|
||||
$table->foreignId('vertrag_id')->constrained('vertraege')->restrictOnDelete();
|
||||
$table->string('bezeichnung');
|
||||
$table->string('import_status', 20)->default('wartet');
|
||||
$table->text('import_fehler')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
Schema::create('nachtraege', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('mandant_id')->constrained('mandanten')->restrictOnDelete();
|
||||
$table->char('land', 2);
|
||||
$table->foreignId('projekt_id')->constrained('projekte')->restrictOnDelete();
|
||||
$table->foreignId('vertrag_id')->constrained('vertraege')->restrictOnDelete();
|
||||
$table->string('nummer', 50);
|
||||
$table->date('eingang_am');
|
||||
$table->string('betreff');
|
||||
$table->json('mka_bezug')->nullable();
|
||||
$table->string('status', 20)->default('eingegangen');
|
||||
$table->foreignId('zugewiesen_an')->nullable()->constrained('users')->nullOnDelete();
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['vertrag_id', 'nummer']);
|
||||
$table->index(['projekt_id', 'status']);
|
||||
});
|
||||
|
||||
Schema::create('nachtragspositionen', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('mandant_id')->constrained('mandanten')->restrictOnDelete();
|
||||
$table->char('land', 2);
|
||||
$table->foreignId('projekt_id')->constrained('projekte')->restrictOnDelete();
|
||||
$table->foreignId('nachtrag_id')->constrained('nachtraege')->cascadeOnDelete();
|
||||
$table->string('oz', 50);
|
||||
$table->string('kurztext', 500);
|
||||
$table->text('langtext')->nullable();
|
||||
$table->decimal('menge', 15, 3)->nullable();
|
||||
$table->string('einheit', 20)->nullable();
|
||||
$table->decimal('einheitspreis', 15, 2)->nullable();
|
||||
$table->unsignedInteger('sortierung')->default(0);
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['nachtrag_id', 'oz']);
|
||||
});
|
||||
|
||||
Schema::create('dokumente', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('mandant_id')->constrained('mandanten')->restrictOnDelete();
|
||||
$table->char('land', 2);
|
||||
$table->foreignId('projekt_id')->nullable()->constrained('projekte')->restrictOnDelete();
|
||||
$table->nullableMorphs('dokumentable');
|
||||
$table->string('kategorie', 40);
|
||||
$table->string('dateiname');
|
||||
$table->string('pfad', 500);
|
||||
$table->string('mime_type', 150);
|
||||
$table->unsignedBigInteger('groesse');
|
||||
$table->char('sha256', 64);
|
||||
$table->boolean('vertraulich')->default(false);
|
||||
$table->foreignId('hochgeladen_von')->nullable()->constrained('users')->nullOnDelete();
|
||||
$table->timestamps();
|
||||
|
||||
$table->index(['projekt_id', 'kategorie']);
|
||||
$table->index('sha256');
|
||||
});
|
||||
|
||||
Schema::create('dokument_freigaben', function (Blueprint $table) {
|
||||
$table->foreignId('dokument_id')->constrained('dokumente')->cascadeOnDelete();
|
||||
$table->foreignId('user_id')->constrained('users')->cascadeOnDelete();
|
||||
$table->timestamps();
|
||||
|
||||
$table->primary(['dokument_id', 'user_id']);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('dokument_freigaben');
|
||||
Schema::dropIfExists('dokumente');
|
||||
Schema::dropIfExists('nachtragspositionen');
|
||||
Schema::dropIfExists('nachtraege');
|
||||
Schema::dropIfExists('leistungsverzeichnisse');
|
||||
Schema::dropIfExists('vertraege');
|
||||
Schema::dropIfExists('abschnitte');
|
||||
Schema::dropIfExists('projekt_mitglieder');
|
||||
Schema::dropIfExists('projekte');
|
||||
Schema::dropIfExists('auftragnehmer');
|
||||
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->dropConstrainedForeignId('mandant_id');
|
||||
});
|
||||
|
||||
Schema::dropIfExists('mandanten');
|
||||
}
|
||||
};
|
||||
@@ -21,5 +21,9 @@ class DatabaseSeeder extends Seeder
|
||||
'name' => 'Test User',
|
||||
'email' => 'test@example.com',
|
||||
]);
|
||||
|
||||
if (app()->isLocal()) {
|
||||
$this->call(DemoSeeder::class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Enums\Land;
|
||||
use App\Enums\NachtragStatus;
|
||||
use App\Enums\Projektrolle;
|
||||
use App\Enums\VerarbeitungStatus;
|
||||
use App\Models\Abschnitt;
|
||||
use App\Models\Auftragnehmer;
|
||||
use App\Models\Mandant;
|
||||
use App\Models\Nachtrag;
|
||||
use App\Models\Projekt;
|
||||
use App\Models\User;
|
||||
use App\Models\Vertrag;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
/**
|
||||
* Erfundene Beispieldaten für Entwicklung und Vorführung (dieselben wie in der
|
||||
* Rückmeldung an Claude Design). Keine echten Kundendaten.
|
||||
*/
|
||||
class DemoSeeder extends Seeder
|
||||
{
|
||||
public const PROJEKT = 'Elektrifizierung Musterbahn';
|
||||
|
||||
public function run(): void
|
||||
{
|
||||
if (Projekt::query()->where('name', self::PROJEKT)->exists()) {
|
||||
$this->command->info('Demodaten sind schon vorhanden.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$mandant = Mandant::query()->firstOrCreate(['name' => 'Demo-Mandant']);
|
||||
|
||||
$projekt = Projekt::query()->create([
|
||||
'mandant_id' => $mandant->id,
|
||||
'land' => Land::DE,
|
||||
'name' => self::PROJEKT,
|
||||
'nummer' => 'P-2025-01',
|
||||
'auftraggeber' => 'DB InfraGO AG',
|
||||
]);
|
||||
|
||||
$an = fn (string $name) => Auftragnehmer::query()->firstOrCreate(
|
||||
['mandant_id' => $mandant->id, 'land' => Land::DE, 'name' => $name],
|
||||
);
|
||||
$arge = $an('ARGE Musterbau');
|
||||
$tunnel = $an('Tunnelbau Beispiel GmbH');
|
||||
$oberleitung = $an('Oberleitung Nord GmbH');
|
||||
|
||||
$abschnitte = [];
|
||||
foreach ([1, 2, 3, 4] as $nr) {
|
||||
$abschnitte[$nr] = Abschnitt::query()->create([
|
||||
'projekt_id' => $projekt->id,
|
||||
'bezeichnung' => 'PFA '.$nr,
|
||||
'sortierung' => $nr,
|
||||
]);
|
||||
}
|
||||
|
||||
$vertrag = fn (Abschnitt $abschnitt, Auftragnehmer $auftragnehmer, string $bezeichnung) => Vertrag::query()->create([
|
||||
'abschnitt_id' => $abschnitt->id,
|
||||
'auftragnehmer_id' => $auftragnehmer->id,
|
||||
'bezeichnung' => $bezeichnung,
|
||||
'vertrag_vom' => '2025-03-01',
|
||||
]);
|
||||
|
||||
$vertrag($abschnitte[1], $oberleitung, 'Oberleitung');
|
||||
$vertrag($abschnitte[2], $oberleitung, 'Oberleitung');
|
||||
$gleisbauPfa3 = $vertrag($abschnitte[3], $arge, 'Gleisbau');
|
||||
$vertrag($abschnitte[3], $tunnel, 'Tunnelbau');
|
||||
$vertrag($abschnitte[3], $oberleitung, 'Oberleitung');
|
||||
$gleisbauPfa4 = $vertrag($abschnitte[4], $arge, 'Gleisbau');
|
||||
$vertrag($abschnitte[4], $tunnel, 'Tunnelbau');
|
||||
$vertrag($abschnitte[4], $oberleitung, 'Oberleitung');
|
||||
|
||||
foreach (['LV 01 Baustelleneinrichtung', 'LV 03 Oberbau', 'LV 05 Entwässerung', 'LV 07 Kabeltiefbau'] as $bezeichnung) {
|
||||
$gleisbauPfa4->leistungsverzeichnisse()->create(['bezeichnung' => $bezeichnung, 'import_status' => VerarbeitungStatus::Wartet]);
|
||||
$gleisbauPfa3->leistungsverzeichnisse()->create(['bezeichnung' => $bezeichnung, 'import_status' => VerarbeitungStatus::Wartet]);
|
||||
}
|
||||
|
||||
$this->nachtrag($gleisbauPfa4, 'N14', 'Lieferung besohlter Schwellen', '2026-09-29', ['MKA 112'], [
|
||||
['N14.0010', 'Schwelle B70 mit Besohlung liefern', 420, 'St', 137.50],
|
||||
['N14.0020', 'Zulage Verlegen besohlter Schwellen', 420, 'St', 12.40],
|
||||
]);
|
||||
$this->nachtrag($gleisbauPfa4, 'N16', 'Kamerabefahrung und Spülen der Entwässerungsleitungen', '2026-09-15', ['MKA 98'], [
|
||||
['N16.0010', 'Kamerabefahrung Leitungen DN 160', 850, 'm', 3.20],
|
||||
['N16.0020', 'Leitungen DN 160 spülen', 850, 'm', 2.10],
|
||||
]);
|
||||
$this->nachtrag($gleisbauPfa4, 'N21', 'Kabelschutzrohr DN 110 verlegen', '2026-10-01', ['MKA 131', 'MKA 133'], [
|
||||
['N21.0010', 'Kabelschutzrohr DN 110 verlegen', 1200, 'm', 36.80],
|
||||
]);
|
||||
|
||||
$testbenutzer = User::query()->where('email', 'test@example.com')->first();
|
||||
if ($testbenutzer !== null) {
|
||||
$testbenutzer->mandant()->associate($mandant)->save();
|
||||
$projekt->mitglieder()->attach($testbenutzer, ['rolle' => Projektrolle::Projektleiter->value]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<string> $mka
|
||||
* @param list<array{0: string, 1: string, 2: int|float, 3: string, 4: float}> $positionen
|
||||
*/
|
||||
private function nachtrag(Vertrag $vertrag, string $nummer, string $betreff, string $eingang, array $mka, array $positionen): Nachtrag
|
||||
{
|
||||
$nachtrag = $vertrag->nachtraege()->create([
|
||||
'nummer' => $nummer,
|
||||
'betreff' => $betreff,
|
||||
'eingang_am' => $eingang,
|
||||
'mka_bezug' => $mka,
|
||||
'status' => NachtragStatus::Eingegangen,
|
||||
]);
|
||||
|
||||
foreach ($positionen as $i => [$oz, $kurztext, $menge, $einheit, $ep]) {
|
||||
$nachtrag->positionen()->create([
|
||||
'oz' => $oz,
|
||||
'kurztext' => $kurztext,
|
||||
'menge' => $menge,
|
||||
'einheit' => $einheit,
|
||||
'einheitspreis' => $ep,
|
||||
'sortierung' => $i,
|
||||
]);
|
||||
}
|
||||
|
||||
return $nachtrag;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
# KI-BauIN – Datenmodell (Kern)
|
||||
|
||||
Stand: 5. Oktober 2026. Grundlage für Phase 1. Später ergänzt werden LV-Positionen und
|
||||
Vorbemerkungen (GAEB-Import, AP5), Prüfung, Feedback und Regeln (AP6–AP8) sowie die Einstellungen
|
||||
der KI-Schnittstelle (AP3).
|
||||
|
||||
## Übersicht
|
||||
|
||||
```mermaid
|
||||
erDiagram
|
||||
MANDANT ||--o{ PROJEKT : hat
|
||||
MANDANT ||--o{ AUFTRAGNEHMER : hat
|
||||
MANDANT ||--o{ USER : hat
|
||||
PROJEKT ||--o{ ABSCHNITT : "gliedert sich in (PFA)"
|
||||
ABSCHNITT ||--o{ VERTRAG : enthält
|
||||
AUFTRAGNEHMER ||--o{ VERTRAG : "ist Partner von"
|
||||
VERTRAG ||--o{ LEISTUNGSVERZEICHNIS : "hat (oft 20–35)"
|
||||
VERTRAG ||--o{ NACHTRAG : "erhält"
|
||||
NACHTRAG ||--o{ NACHTRAGSPOSITION : hat
|
||||
PROJEKT ||--o{ DOKUMENT : "enthält"
|
||||
LEISTUNGSVERZEICHNIS ||--o{ DOKUMENT : "X86, D86, PDF"
|
||||
NACHTRAG ||--o{ DOKUMENT : "Nachtrags-LV, Anschreiben, Anlagen"
|
||||
PROJEKT }o--o{ USER : "Mitglieder mit Projektrolle"
|
||||
DOKUMENT }o--o{ USER : "Freigaben (vertraulich)"
|
||||
```
|
||||
|
||||
| Modell | Tabelle | Inhalt |
|
||||
|---|---|---|
|
||||
| `Mandant` | `mandanten` | Kunde der Anwendung (im Pilot nur BauIn) |
|
||||
| `Projekt` | `projekte` | z. B. „Elektrifizierung Musterbahn“; Auftraggeber, Vertragsgrundlage, Status, Suchreihenfolge |
|
||||
| `Abschnitt` | `abschnitte` | PFA bzw. Abschnitt; die Bezeichnung „PFA“ steht am Projekt (`abschnitt_bezeichnung`) |
|
||||
| `Auftragnehmer` | `auftragnehmer` | Firma oder ARGE; kann in mehreren PFAs Verträge haben |
|
||||
| `Vertrag` | `vertraege` | Auftrag an einen Auftragnehmer in einem Abschnitt, z. B. „Gleisbau“ |
|
||||
| `Leistungsverzeichnis` | `leistungsverzeichnisse` | ein LV des Vertrags; Dateien als Dokumente, Importstatus |
|
||||
| `Nachtrag` | `nachtraege` | Nr., Eingang, Betreff, MKA-Bezug (Liste), Status, zugewiesen an |
|
||||
| `Nachtragsposition` | `nachtragspositionen` | OZ, Kurztext, Langtext, Menge, Einheit, EP (nur Information) |
|
||||
| `Dokument` | `dokumente` | hochgeladene Datei; gehört zu Projekt und optional zu LV, Nachtrag usw.; vertraulich ja/nein |
|
||||
|
||||
Pivot-Tabellen: `projekt_mitglieder` (Benutzer, Projekt, Projektrolle) und `dokument_freigaben`
|
||||
(vertrauliche Dokumente für benannte Personen).
|
||||
|
||||
## Festlegungen
|
||||
|
||||
- **Mandant, Land und Projekt an jedem Fachdatensatz.** `mandant_id` und `land` stehen an allen
|
||||
Fachtabellen; `projekt_id` an allem unterhalb des Projekts. Die Werte werden beim Speichern vom
|
||||
übergeordneten Datensatz übernommen (`App\Models\Concerns\ErbtZuordnung`). Ein Datensatz, der
|
||||
auf einen Datensatz eines anderen Mandanten, Landes oder Projekts zeigt, wird abgewiesen. Das
|
||||
gilt auch für Vertrag und Auftragnehmer.
|
||||
- **Rollen:** Globale Rollen (Administrator, Regelverantwortlicher) über Spatie
|
||||
laravel-permission. Projektrollen (Projektleiter, Bearbeiter, Leser) in `projekt_mitglieder`,
|
||||
weil sie je Projekt verschieden sind. Der Teams-Modus von Spatie bleibt aus.
|
||||
- **MKA nur als Bezug:** `nachtraege.mka_bezug` ist eine Liste von Nummern (Fragenkatalog A8).
|
||||
- **Dokumente polymorph:** `dokumentable` zeigt auf LV, Nachtrag oder Vertrag; `projekt_id`
|
||||
bleibt für die Rechteprüfung immer gesetzt. Ohne Projekt ist es ein allgemeines Dokument
|
||||
(Einstellungen). Die Morph-Namen sind fest (`projekt`, `vertrag`, `leistungsverzeichnis`,
|
||||
`nachtrag`, `user`), damit Klassennamen nicht in der Datenbank stehen.
|
||||
- **Löschen:** Fachdaten werden nicht kaskadierend gelöscht; ein Projekt mit Abschnitten lässt
|
||||
sich nicht löschen, sondern wird archiviert. Ausnahmen: Nachtragspositionen hängen am Nachtrag,
|
||||
Pivot-Einträge an ihren beiden Seiten.
|
||||
- **Suchreihenfolge je Projekt (vorläufig, Fragenkatalog A10):** andere Verträge im selben
|
||||
Abschnitt einbeziehen = nein, andere Abschnitte = ja, nur gleicher Auftragnehmer = nein.
|
||||
- **Beträge** als Dezimalzahlen (Menge 15,3, EP 15,2); Preise sind in Phase 1 nur Information.
|
||||
+2
-2
@@ -209,8 +209,8 @@ PDF-Anzeige mit Sprung zur Position, Massen-Upload, Suchreihenfolge über PFAs u
|
||||
- [ ] API-Schlüssel für die Entwicklung bei ITM anfordern
|
||||
- [ ] **Meilisearch-Test Teil 1** (erzeugte 4.096-dim. Vektoren, z. B. 50.000 Stück):
|
||||
Indexierungszeit, Antwortzeit mit Filtern, RAM und Platte; jeweils ohne und mit binärer Quantisierung
|
||||
- [ ] Datenmodell Kern: Mandant, Land, Projekt, PFA, Vertrag, LV, Dokument (Kategorie,
|
||||
Vertraulichkeit), Nachtrag, Nachtragsposition, Mitgliedschaften
|
||||
- [x] Datenmodell Kern: Mandant, Land, Projekt, PFA, Vertrag, LV, Dokument (Kategorie,
|
||||
Vertraulichkeit), Nachtrag, Nachtragsposition, Mitgliedschaften (`docs/datenmodell.md`, Demodaten)
|
||||
- [ ] Benutzerverwaltung, Rollen und Rechte (Spatie, ggf. Teams je Projekt)
|
||||
- [ ] GAEB-X86-Test mit öffentlichen Beispieldateien, Bibliothek auswählen
|
||||
- [ ] CI in Gitea Actions: Tests, Pint, PHPStan
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Datenmodell;
|
||||
|
||||
use App\Enums\DokumentKategorie;
|
||||
use App\Enums\NachtragStatus;
|
||||
use App\Enums\Projektrolle;
|
||||
use App\Models\Abschnitt;
|
||||
use App\Models\Auftragnehmer;
|
||||
use App\Models\Dokument;
|
||||
use App\Models\Nachtrag;
|
||||
use App\Models\Nachtragsposition;
|
||||
use App\Models\Projekt;
|
||||
use App\Models\User;
|
||||
use App\Models\Vertrag;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class BeziehungenTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_auftragnehmer_kann_in_mehreren_abschnitten_vertraege_haben(): void
|
||||
{
|
||||
$projekt = Projekt::factory()->create();
|
||||
$auftragnehmer = Auftragnehmer::factory()->create(['mandant_id' => $projekt->mandant_id]);
|
||||
[$pfa3, $pfa4] = Abschnitt::factory()->count(2)->create(['projekt_id' => $projekt->id]);
|
||||
|
||||
Vertrag::factory()->create(['abschnitt_id' => $pfa3->id, 'auftragnehmer_id' => $auftragnehmer->id]);
|
||||
Vertrag::factory()->create(['abschnitt_id' => $pfa4->id, 'auftragnehmer_id' => $auftragnehmer->id]);
|
||||
|
||||
$this->assertEqualsCanonicalizing(
|
||||
[$pfa3->id, $pfa4->id],
|
||||
$auftragnehmer->vertraege()->pluck('abschnitt_id')->all(),
|
||||
);
|
||||
$this->assertSame(2, $projekt->vertraege()->count());
|
||||
}
|
||||
|
||||
public function test_nachtrag_hat_mka_bezug_status_und_positionen_in_reihenfolge(): void
|
||||
{
|
||||
$nachtrag = Nachtrag::factory()->create(['mka_bezug' => ['MKA 131', 'MKA 133']]);
|
||||
Nachtragsposition::factory()->create(['nachtrag_id' => $nachtrag->id, 'oz' => 'N1.0020', 'sortierung' => 2]);
|
||||
Nachtragsposition::factory()->create(['nachtrag_id' => $nachtrag->id, 'oz' => 'N1.0010', 'sortierung' => 1]);
|
||||
|
||||
$nachtrag = $nachtrag->fresh();
|
||||
|
||||
$this->assertNotNull($nachtrag);
|
||||
$this->assertSame(['MKA 131', 'MKA 133'], $nachtrag->mka_bezug);
|
||||
$this->assertSame(NachtragStatus::Eingegangen, $nachtrag->status);
|
||||
$this->assertSame(['N1.0010', 'N1.0020'], $nachtrag->positionen->pluck('oz')->all());
|
||||
}
|
||||
|
||||
public function test_nachtragsnummer_ist_je_vertrag_eindeutig(): void
|
||||
{
|
||||
$vertrag = Vertrag::factory()->create();
|
||||
Nachtrag::factory()->create(['vertrag_id' => $vertrag->id, 'nummer' => 'N14']);
|
||||
|
||||
$this->expectException(QueryException::class);
|
||||
|
||||
Nachtrag::factory()->create(['vertrag_id' => $vertrag->id, 'nummer' => 'N14']);
|
||||
}
|
||||
|
||||
public function test_projektmitglieder_haben_eine_rolle(): void
|
||||
{
|
||||
$projekt = Projekt::factory()->create();
|
||||
$leiterin = User::factory()->create();
|
||||
$leser = User::factory()->create();
|
||||
$aussenstehend = User::factory()->create();
|
||||
|
||||
$projekt->mitglieder()->attach($leiterin, ['rolle' => Projektrolle::Projektleiter->value]);
|
||||
$projekt->mitglieder()->attach($leser, ['rolle' => Projektrolle::Leser->value]);
|
||||
|
||||
$this->assertSame(Projektrolle::Projektleiter, $projekt->rolleVon($leiterin));
|
||||
$this->assertSame(Projektrolle::Leser, $projekt->rolleVon($leser));
|
||||
$this->assertNull($projekt->rolleVon($aussenstehend));
|
||||
$this->assertTrue($leiterin->projekte()->whereKey($projekt->id)->exists());
|
||||
}
|
||||
|
||||
public function test_vertrauliches_dokument_hat_benannte_freigaben(): void
|
||||
{
|
||||
$nachtrag = Nachtrag::factory()->create();
|
||||
$dokument = Dokument::factory()->zu($nachtrag, DokumentKategorie::Anlage)->vertraulich()->create();
|
||||
$berechtigt = User::factory()->create();
|
||||
|
||||
$dokument->freigaben()->attach($berechtigt);
|
||||
|
||||
$this->assertTrue($dokument->vertraulich);
|
||||
$this->assertSame([$berechtigt->id], $dokument->freigaben()->pluck('users.id')->all());
|
||||
$this->assertSame(1, $nachtrag->dokumente()->count());
|
||||
}
|
||||
|
||||
public function test_archiviertes_projekt_wird_erkannt(): void
|
||||
{
|
||||
$this->assertTrue(Projekt::factory()->archiviert()->create()->istArchiviert());
|
||||
$this->assertFalse(Projekt::factory()->create()->istArchiviert());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Datenmodell;
|
||||
|
||||
use App\Enums\Projektrolle;
|
||||
use App\Models\Nachtrag;
|
||||
use App\Models\Projekt;
|
||||
use App\Models\User;
|
||||
use Database\Seeders\DemoSeeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class DemoSeederTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_demodaten_entsprechen_den_beispielen_und_lassen_sich_wiederholt_einspielen(): void
|
||||
{
|
||||
$testbenutzer = User::factory()->create(['email' => 'test@example.com']);
|
||||
|
||||
$this->seed(DemoSeeder::class);
|
||||
$this->seed(DemoSeeder::class);
|
||||
|
||||
$projekt = Projekt::query()->where('name', DemoSeeder::PROJEKT)->sole();
|
||||
$this->assertSame(['PFA 1', 'PFA 2', 'PFA 3', 'PFA 4'], $projekt->abschnitte->pluck('bezeichnung')->all());
|
||||
$this->assertSame(8, $projekt->vertraege()->count());
|
||||
$this->assertSame(['N14', 'N16', 'N21'], $projekt->nachtraege()->orderBy('nummer')->pluck('nummer')->all());
|
||||
$this->assertSame(['MKA 131', 'MKA 133'], Nachtrag::query()->where('nummer', 'N21')->sole()->mka_bezug);
|
||||
$this->assertSame(Projektrolle::Projektleiter, $projekt->rolleVon($testbenutzer));
|
||||
$this->assertSame($projekt->mandant_id, $testbenutzer->fresh()?->mandant_id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Datenmodell;
|
||||
|
||||
use App\Models\Abschnitt;
|
||||
use App\Models\Nachtrag;
|
||||
use App\Models\Nachtragsposition;
|
||||
use App\Models\Projekt;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class LoeschenTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_projekt_mit_abschnitten_laesst_sich_nicht_loeschen(): void
|
||||
{
|
||||
$abschnitt = Abschnitt::factory()->create();
|
||||
|
||||
$this->expectException(QueryException::class);
|
||||
|
||||
$abschnitt->projekt->delete();
|
||||
}
|
||||
|
||||
public function test_nachtragspositionen_werden_mit_dem_nachtrag_geloescht(): void
|
||||
{
|
||||
$nachtrag = Nachtrag::factory()->create();
|
||||
Nachtragsposition::factory()->count(3)->create(['nachtrag_id' => $nachtrag->id]);
|
||||
|
||||
$nachtrag->delete();
|
||||
|
||||
$this->assertSame(0, Nachtragsposition::query()->count());
|
||||
}
|
||||
|
||||
public function test_geloeschter_benutzer_verschwindet_aus_projekt_und_zuweisung(): void
|
||||
{
|
||||
$projekt = Projekt::factory()->create();
|
||||
$benutzer = User::factory()->create();
|
||||
$projekt->mitglieder()->attach($benutzer, ['rolle' => 'bearbeiter']);
|
||||
$nachtrag = Nachtrag::factory()->create(['zugewiesen_an' => $benutzer->id]);
|
||||
|
||||
$benutzer->delete();
|
||||
|
||||
$this->assertSame(0, $projekt->mitglieder()->count());
|
||||
$this->assertNull($nachtrag->fresh()?->zugewiesen_an);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Datenmodell;
|
||||
|
||||
use App\Enums\DokumentKategorie;
|
||||
use App\Enums\Land;
|
||||
use App\Models\Abschnitt;
|
||||
use App\Models\Auftragnehmer;
|
||||
use App\Models\Dokument;
|
||||
use App\Models\Leistungsverzeichnis;
|
||||
use App\Models\Mandant;
|
||||
use App\Models\Nachtrag;
|
||||
use App\Models\Nachtragsposition;
|
||||
use App\Models\Projekt;
|
||||
use App\Models\Vertrag;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use LogicException;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ZuordnungTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_mandant_land_und_projekt_werden_die_kette_hinunter_uebernommen(): void
|
||||
{
|
||||
$projekt = Projekt::factory()->create(['land' => Land::AT]);
|
||||
$abschnitt = Abschnitt::factory()->create(['projekt_id' => $projekt->id]);
|
||||
$vertrag = Vertrag::factory()->create(['abschnitt_id' => $abschnitt->id]);
|
||||
$lv = Leistungsverzeichnis::factory()->create(['vertrag_id' => $vertrag->id]);
|
||||
$nachtrag = Nachtrag::factory()->create(['vertrag_id' => $vertrag->id]);
|
||||
$position = Nachtragsposition::factory()->create(['nachtrag_id' => $nachtrag->id]);
|
||||
|
||||
foreach ([$abschnitt, $vertrag, $lv, $nachtrag, $position] as $datensatz) {
|
||||
$this->assertSame($projekt->mandant_id, $datensatz->mandant_id, $datensatz::class);
|
||||
$this->assertSame(Land::AT, $datensatz->land, $datensatz::class);
|
||||
$this->assertSame($projekt->id, $datensatz->projekt_id, $datensatz::class);
|
||||
}
|
||||
}
|
||||
|
||||
public function test_dokument_uebernimmt_die_zuordnung_vom_lv(): void
|
||||
{
|
||||
$lv = Leistungsverzeichnis::factory()->create();
|
||||
|
||||
$dokument = Dokument::factory()->zu($lv, DokumentKategorie::LvX86)->create();
|
||||
|
||||
$this->assertSame($lv->projekt_id, $dokument->projekt_id);
|
||||
$this->assertSame($lv->mandant_id, $dokument->mandant_id);
|
||||
$this->assertTrue($dokument->dokumentable?->is($lv));
|
||||
$this->assertSame('leistungsverzeichnis', $dokument->dokumentable_type);
|
||||
}
|
||||
|
||||
public function test_allgemeines_dokument_ohne_projekt_braucht_mandant_und_land(): void
|
||||
{
|
||||
$mandant = Mandant::factory()->create();
|
||||
|
||||
$dokument = Dokument::factory()->create([
|
||||
'projekt_id' => null,
|
||||
'mandant_id' => $mandant->id,
|
||||
'land' => Land::DE,
|
||||
'kategorie' => DokumentKategorie::Vorlage,
|
||||
]);
|
||||
|
||||
$this->assertNull($dokument->projekt_id);
|
||||
$this->assertSame($mandant->id, $dokument->mandant_id);
|
||||
}
|
||||
|
||||
public function test_vertrag_mit_auftragnehmer_eines_anderen_mandanten_wird_abgewiesen(): void
|
||||
{
|
||||
$abschnitt = Abschnitt::factory()->create();
|
||||
$fremderAuftragnehmer = Auftragnehmer::factory()->create();
|
||||
|
||||
$this->expectException(LogicException::class);
|
||||
|
||||
Vertrag::factory()->create([
|
||||
'abschnitt_id' => $abschnitt->id,
|
||||
'auftragnehmer_id' => $fremderAuftragnehmer->id,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_abweichender_mandant_beim_anlegen_wird_abgewiesen(): void
|
||||
{
|
||||
$projekt = Projekt::factory()->create();
|
||||
$andererMandant = Mandant::factory()->create();
|
||||
|
||||
$this->expectException(LogicException::class);
|
||||
|
||||
Abschnitt::factory()->create([
|
||||
'projekt_id' => $projekt->id,
|
||||
'mandant_id' => $andererMandant->id,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_nachtrag_laesst_sich_nicht_in_ein_anderes_projekt_verschieben(): void
|
||||
{
|
||||
$nachtrag = Nachtrag::factory()->create();
|
||||
$vertragInAnderemProjekt = Vertrag::factory()->create();
|
||||
|
||||
$this->expectException(LogicException::class);
|
||||
|
||||
$nachtrag->update(['vertrag_id' => $vertragInAnderemProjekt->id]);
|
||||
}
|
||||
|
||||
public function test_nachtrag_darf_innerhalb_des_projekts_den_vertrag_wechseln(): void
|
||||
{
|
||||
$nachtrag = Nachtrag::factory()->create();
|
||||
$abschnitt = $nachtrag->vertrag->abschnitt;
|
||||
$andererVertrag = Vertrag::factory()->create(['abschnitt_id' => $abschnitt->id]);
|
||||
|
||||
$nachtrag->update(['vertrag_id' => $andererVertrag->id]);
|
||||
|
||||
$this->assertSame($andererVertrag->id, $nachtrag->fresh()?->vertrag_id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user