253 lines
6.4 KiB
Plaintext
253 lines
6.4 KiB
Plaintext
generator client {
|
|
provider = "prisma-client-js"
|
|
}
|
|
|
|
datasource db {
|
|
provider = "postgresql"
|
|
url = env("DATABASE_URL")
|
|
}
|
|
|
|
model User {
|
|
id String @id @default(cuid())
|
|
email String @unique
|
|
name String?
|
|
passwordHash String?
|
|
role String @default("admin")
|
|
infomaniakId String? @unique
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
sessions Session[]
|
|
quotes Quote[]
|
|
contracts Contract[]
|
|
clients Client[]
|
|
sales Sale[]
|
|
todos TodoItem[]
|
|
}
|
|
|
|
model Session {
|
|
id String @id @default(cuid())
|
|
userId String
|
|
token String @unique
|
|
expiresAt DateTime
|
|
createdAt DateTime @default(now())
|
|
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
|
|
@@index([userId])
|
|
@@index([token])
|
|
}
|
|
|
|
model Client {
|
|
id String @id @default(cuid())
|
|
name String
|
|
email String?
|
|
phone String?
|
|
address String?
|
|
siret String?
|
|
type ClientType @default(PROSPECT)
|
|
isProfessional Boolean? @default(true)
|
|
notes String?
|
|
userId String
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
quotes Quote[]
|
|
contracts Contract[]
|
|
sales Sale[]
|
|
|
|
@@index([userId])
|
|
@@index([type])
|
|
}
|
|
|
|
enum ClientType {
|
|
PROSPECT
|
|
CLIENT
|
|
}
|
|
|
|
model Quote {
|
|
id String @id @default(cuid())
|
|
clientId String
|
|
userId String
|
|
name String
|
|
quoteNumber String?
|
|
status QuoteStatus @default(DRAFT)
|
|
setupTotal Float @default(0)
|
|
monthlyTotal Float @default(0)
|
|
costTotal Float @default(0)
|
|
marginTotal Float @default(0)
|
|
discount Float @default(0)
|
|
travelKm Int @default(0)
|
|
travelCost Float @default(0)
|
|
notes String?
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
client Client @relation(fields: [clientId], references: [id], onDelete: Cascade)
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
items QuoteItem[]
|
|
contract Contract?
|
|
|
|
@@index([clientId])
|
|
@@index([userId])
|
|
@@index([status])
|
|
}
|
|
|
|
enum QuoteStatus {
|
|
DRAFT
|
|
PROPOSAL
|
|
SENT
|
|
ACCEPTED
|
|
REJECTED
|
|
EXPIRED
|
|
}
|
|
|
|
model QuoteItem {
|
|
id String @id @default(cuid())
|
|
quoteId String
|
|
type QuoteItemType
|
|
label String
|
|
description String?
|
|
unitPrice Float
|
|
costPrice Float
|
|
quantity Int @default(1)
|
|
isRecurring Boolean @default(false)
|
|
setupPrice Float @default(0)
|
|
setupCost Float @default(0)
|
|
monthlyPrice Float @default(0)
|
|
monthlyCost Float @default(0)
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
quote Quote @relation(fields: [quoteId], references: [id], onDelete: Cascade)
|
|
|
|
@@index([quoteId])
|
|
}
|
|
|
|
enum QuoteItemType {
|
|
MAINTENANCE_POSTE
|
|
MAINTENANCE_SERVER
|
|
KS_SUITE_STANDARD
|
|
KS_SUITE_BUSINESS
|
|
KS_SUITE_ENTREPRISE
|
|
HOURLY_INTERVENTION
|
|
TRAVEL
|
|
CUSTOM
|
|
}
|
|
|
|
model Contract {
|
|
id String @id @default(cuid())
|
|
clientId String
|
|
userId String
|
|
quoteId String? @unique
|
|
name String
|
|
startDate DateTime
|
|
endDate DateTime?
|
|
setupPrice Float @default(0)
|
|
setupCost Float @default(0)
|
|
monthlyPrice Float @default(0)
|
|
monthlyCost Float @default(0)
|
|
status ContractStatus @default(ACTIVE)
|
|
billingDay Int @default(1)
|
|
notes String?
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
client Client @relation(fields: [clientId], references: [id], onDelete: Cascade)
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
quote Quote? @relation(fields: [quoteId], references: [id], onDelete: SetNull)
|
|
invoices Invoice[]
|
|
|
|
@@index([clientId])
|
|
@@index([userId])
|
|
@@index([status])
|
|
}
|
|
|
|
enum ContractStatus {
|
|
PROPOSAL
|
|
ACTIVE
|
|
PAUSED
|
|
CANCELLED
|
|
EXPIRED
|
|
}
|
|
|
|
model Invoice {
|
|
id String @id @default(cuid())
|
|
contractId String
|
|
month DateTime
|
|
amount Float
|
|
invoiceNumber String?
|
|
emitted Boolean @default(false)
|
|
emittedAt DateTime?
|
|
paidAt DateTime?
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
contract Contract @relation(fields: [contractId], references: [id], onDelete: Cascade)
|
|
|
|
@@index([contractId])
|
|
@@unique([contractId, month])
|
|
}
|
|
|
|
model TodoItem {
|
|
id String @id @default(cuid())
|
|
userId String
|
|
text String
|
|
position Int
|
|
done Boolean @default(false)
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
|
|
@@index([userId])
|
|
}
|
|
|
|
model Sale {
|
|
id String @id @default(cuid())
|
|
clientId String
|
|
userId String
|
|
date DateTime @default(now())
|
|
totalAmount Float @default(0)
|
|
totalCost Float @default(0)
|
|
paid Boolean @default(false)
|
|
notes String?
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
client Client @relation(fields: [clientId], references: [id], onDelete: Cascade)
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
items SaleItem[]
|
|
|
|
@@index([clientId])
|
|
@@index([userId])
|
|
}
|
|
|
|
model SaleItem {
|
|
id String @id @default(cuid())
|
|
saleId String
|
|
label String
|
|
description String?
|
|
quantity Int @default(1)
|
|
unitPrice Float @default(0)
|
|
costPrice Float @default(0)
|
|
createdAt DateTime @default(now())
|
|
|
|
sale Sale @relation(fields: [saleId], references: [id], onDelete: Cascade)
|
|
|
|
@@index([saleId])
|
|
}
|
|
|
|
model ProductCost {
|
|
id String @id @default(cuid())
|
|
key String @unique
|
|
label String
|
|
costPrice Float
|
|
sellPrice Float
|
|
unit String
|
|
category String
|
|
isActive Boolean @default(true)
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
} |