Files

383 lines
11 KiB
Plaintext

// R-P9a (P9 Auftrag view + project sub-areas).
//
// AD-20: order work is a view on the existing `Projekt` core, not a second
// project/order object and not a won-handoff copy. These rows are sub-areas
// addressed by `projektId` bare scalar.
//
// AD-21: this module owns its schema file. Cross-module references to Projekt,
// User, Group, File and Form are intentionally bare String scalars so this slice
// does not modify projekt/accounts/files/forms schemas.
enum ProjektMitgliedRolle {
monteur
projektleiter
zustaendig
beobachter
}
enum ProjektTerminStatus {
geplant
bestaetigt
erledigt
abgesagt
}
enum RechnungStatus {
entwurf
gestellt
bezahlt
storniert
}
enum RechnungQuelle {
manuell
kwp
}
enum ProjektChecklistTyp {
generisch
maengel
abnahme_doku
}
enum ProjektChecklistItemStatus {
offen
erledigt
entfaellt
}
enum ScheduleEntryStatus {
planned
confirmed
in_progress
done
cancelled
}
enum ScheduleConflictType {
double_booking
absence
availability
}
enum ScheduleConflictSeverity {
warning
blocking
}
enum ScheduleSyncStatus {
pending
synced
failed
}
enum AcceptanceKind {
full
with_defects
rejected
}
enum AcceptanceSignerRole {
kunde
monteur
}
enum OfflineSyncOperation {
schedule_upsert
schedule_status
acceptance_submit
}
enum OfflineSyncStatus {
pending
applied
failed
}
model ProjektMitglied {
id String @id @default(cuid())
tenantId String
projektId String
userId String?
groupId String?
rolle ProjektMitgliedRolle
createdByUserId String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
archivedAt DateTime?
projekt Projekt @relation(fields: [projektId], references: [id], onDelete: Cascade)
@@index([tenantId, projektId, archivedAt])
@@index([tenantId, userId, archivedAt, projektId])
@@index([tenantId, groupId, archivedAt, projektId])
}
/// WF-P8 S02-T: appointment kind offered by the "Termin erstellen" modal.
enum ProjektTerminTyp {
vor_ort
telefon
online
}
model ProjektTermin {
id String @id @default(cuid())
tenantId String
projektId String
createdByUserId String?
assignedToUserId String?
assignedToGroupId String?
titel String
beschreibung String?
startAt DateTime
endAt DateTime?
status ProjektTerminStatus @default(geplant)
/// WF-P8 S02-T. Defaults to the on-site case, which is the SHK norm.
typ ProjektTerminTyp @default(vor_ort)
isDemoData Boolean @default(false)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
archivedAt DateTime?
@@index([tenantId, projektId, archivedAt, startAt])
@@index([tenantId, assignedToUserId])
@@index([tenantId, assignedToGroupId])
}
model Rechnung {
id String @id @default(cuid())
tenantId String
projektId String
createdByUserId String?
rechnungsnummer String
betrag Decimal
status RechnungStatus @default(entwurf)
datum DateTime @default(now())
faelligAm DateTime?
/// Set when the invoice moves to `bezahlt`, cleared when it moves away again.
/// `updatedAt` cannot stand in for this: any later edit overwrites it, which
/// makes revenue by payment date and days-to-payment unmeasurable. Invoices
/// already marked paid before this field existed stay null and are excluded
/// from payment-date reporting rather than counted at a wrong date.
bezahltAm DateTime?
dateiId String?
quelle RechnungQuelle @default(manuell)
isDemoData Boolean @default(false)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
archivedAt DateTime?
@@unique([tenantId, rechnungsnummer])
@@index([tenantId, projektId, archivedAt])
@@index([tenantId, status])
@@index([tenantId, bezahltAm])
@@index([tenantId, dateiId])
}
model ProjektChecklist {
id String @id @default(cuid())
tenantId String
projektId String
createdByUserId String?
titel String
typ ProjektChecklistTyp @default(generisch)
isDemoData Boolean @default(false)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
archivedAt DateTime?
projekt Projekt @relation(fields: [projektId], references: [id], onDelete: Cascade)
items ProjektChecklistItem[]
@@index([tenantId, projektId, typ, archivedAt])
}
model ProjektChecklistItem {
id String @id @default(cuid())
tenantId String
checklistId String
titel String
status ProjektChecklistItemStatus @default(offen)
maengelKlasse String?
fotoFileId String?
assignedToUserId String?
dueAt DateTime?
position Int @default(0)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
checklist ProjektChecklist @relation(fields: [checklistId], references: [id], onDelete: Cascade)
@@index([tenantId, checklistId, status])
@@index([tenantId, status])
@@index([tenantId, fotoFileId])
}
model AuftragPipelineStageConfig {
id String @id @default(cuid())
tenantId String
pipelineId String
stageId String
requiresAcceptanceProtocol Boolean @default(false)
acceptanceFormTemplateId String?
autoArchiveAfterDays Int?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@unique([tenantId, stageId])
@@index([tenantId, pipelineId])
@@index([tenantId, acceptanceFormTemplateId])
}
model AcceptanceFormTemplate {
id String @id @default(cuid())
tenantId String
name String
formId String?
definition Json @default("{}")
isDefault Boolean @default(false)
isDemoData Boolean @default(false)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
archivedAt DateTime?
@@unique([tenantId, name])
@@index([tenantId, archivedAt])
@@index([tenantId, formId])
}
model ProjectTemplate {
id String @id @default(cuid())
tenantId String
name String
defaultPipelineId String?
defaultStageId String?
defaultMembers Json @default("[]")
defaultTasks Json @default("[]")
customFields Json @default("{}")
isDemoData Boolean @default(false)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
archivedAt DateTime?
@@unique([tenantId, name])
@@index([tenantId, archivedAt])
@@index([tenantId, defaultPipelineId])
}
model ScheduleEntry {
id String @id @default(cuid())
tenantId String
projektId String
assignedUserId String
createdByUserId String?
title String
startAt DateTime
endAt DateTime
status ScheduleEntryStatus @default(planned)
calendarEventId String?
syncStatus ScheduleSyncStatus @default(pending)
conflictOverrideReason String?
clientMutationId String?
isDemoData Boolean @default(false)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
archivedAt DateTime?
conflicts ScheduleConflict[]
@@unique([tenantId, clientMutationId])
@@index([tenantId, projektId, archivedAt])
@@index([tenantId, assignedUserId, startAt, endAt])
@@index([tenantId, status])
@@index([tenantId, calendarEventId])
}
model ScheduleConflict {
id String @id @default(cuid())
tenantId String
entryId String
type ScheduleConflictType
severity ScheduleConflictSeverity @default(warning)
messageKey String
sourceKind String?
sourceId String?
createdAt DateTime @default(now())
resolvedAt DateTime?
overriddenAt DateTime?
entry ScheduleEntry @relation(fields: [entryId], references: [id], onDelete: Cascade)
@@index([tenantId, entryId])
@@index([tenantId, type, resolvedAt])
}
model AbnahmeProtokoll {
id String @id @default(cuid())
tenantId String
projektId String
maengelChecklistId String?
createdByUserId String?
datum DateTime @default(now())
acceptanceKind AcceptanceKind
anwesende Json @default("[]")
druckprobe Json @default("{}")
funktionspruefung Json @default("{}")
zaehlerstaende Json @default("{}")
dokumente Json @default("[]")
bemerkungen String?
pdfFileId String?
customerEmail String?
customerEmailQueuedAt DateTime?
clientMutationId String?
gesperrtAt DateTime?
isDemoData Boolean @default(false)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
archivedAt DateTime?
signatures AbnahmeSignatur[]
@@unique([tenantId, clientMutationId])
@@index([tenantId, projektId, archivedAt])
@@index([tenantId, maengelChecklistId])
@@index([tenantId, pdfFileId])
@@index([tenantId, acceptanceKind])
}
model AbnahmeSignatur {
id String @id @default(cuid())
tenantId String
protokollId String
signerName String
signerRole AcceptanceSignerRole
signatureFileId String?
signerIpHash String?
signedAt DateTime @default(now())
createdAt DateTime @default(now())
protokoll AbnahmeProtokoll @relation(fields: [protokollId], references: [id], onDelete: Restrict)
@@index([tenantId, protokollId])
@@index([tenantId, signatureFileId])
}
model OfflineSyncMutation {
id String @id @default(cuid())
tenantId String
clientMutationId String
createdByUserId String?
operation OfflineSyncOperation
payload Json
status OfflineSyncStatus @default(pending)
resultEntityType String?
resultEntityId String?
errorMessageKey String?
createdAt DateTime @default(now())
appliedAt DateTime?
@@unique([tenantId, clientMutationId])
@@index([tenantId, createdByUserId, createdAt])
@@index([tenantId, status])
}