349 lines
8.8 KiB
Plaintext
349 lines
8.8 KiB
Plaintext
// Schéma de base de données pour la Gestion de Magasin d'Optique
|
|
|
|
generator client {
|
|
provider = "prisma-client-js"
|
|
}
|
|
|
|
datasource db {
|
|
provider = "sqlite"
|
|
url = env("DATABASE_URL")
|
|
}
|
|
|
|
// ============================================
|
|
// ÉNUMÉRATIONS
|
|
// ============================================
|
|
|
|
enum StatutVente {
|
|
INITIEE
|
|
PAYEE
|
|
ANNULEE
|
|
REMBOURSEE
|
|
}
|
|
|
|
enum StatutAchat {
|
|
BROUILLON
|
|
VALIDE
|
|
}
|
|
|
|
enum ModePaiement {
|
|
ESPECES
|
|
CARTE
|
|
CHEQUE
|
|
VIREMENT
|
|
BON_CAISSE
|
|
}
|
|
|
|
enum TypeFichier {
|
|
ORDONNANCE
|
|
FACTURE_ACHAT
|
|
FACTURE_VENTE
|
|
IMAGE_PRODUIT
|
|
}
|
|
|
|
enum RoleEmploye {
|
|
VENDEUR
|
|
RESPONSABLE
|
|
ADMIN
|
|
}
|
|
|
|
enum TypeMonture {
|
|
COMPLET
|
|
NATUREL
|
|
CERCLAGE
|
|
}
|
|
|
|
enum TypeVerre {
|
|
SIMPLE
|
|
BIFOCAL
|
|
PROGRESSIF
|
|
}
|
|
|
|
enum StatutAtelier {
|
|
EN_ATTENTE
|
|
EN_COURS
|
|
TERMINE
|
|
PRET
|
|
RETIRE
|
|
}
|
|
|
|
// ============================================
|
|
// MODÈLES PRINCIPAUX
|
|
// ============================================
|
|
|
|
// Employé du magasin
|
|
model Employe {
|
|
id String @id @default(cuid())
|
|
email String @unique
|
|
nom String
|
|
prenom String
|
|
role RoleEmploye @default(VENDEUR)
|
|
actif Boolean @default(true)
|
|
motDePasse String
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
// Relations
|
|
ventes Vente[]
|
|
facturesAchat FactureAchat[]
|
|
retours Retour[]
|
|
paiements Paiement[]
|
|
patients Patient[]
|
|
}
|
|
|
|
// Client / Patient
|
|
model Client {
|
|
id String @id @default(cuid())
|
|
nom String
|
|
prenom String
|
|
email String?
|
|
telephone String @unique
|
|
adresse String?
|
|
ville String?
|
|
codePostal String?
|
|
dateNaissance DateTime?
|
|
notes String?
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
// Relations
|
|
patients Patient[]
|
|
ventes Vente[]
|
|
}
|
|
|
|
// Patient avec données de vision
|
|
model Patient {
|
|
id String @id @default(cuid())
|
|
clientId String
|
|
dateCreation DateTime @default(now())
|
|
odSphere Float? // Œil droit - Sphère
|
|
odCylindre Float? // Œil droit - Cylindre
|
|
odAxe Int? // Œil droit - Axe
|
|
ogSphere Float? // Œil gauche - Sphère
|
|
ogCylindre Float? // Œil gauche - Cylindre
|
|
ogAxe Int? // Œil gauche - Axe
|
|
addition Float? // Addition
|
|
pd Float? // Distance pupillaire
|
|
hauteur Float? // Hauteur
|
|
notes String?
|
|
employeId String?
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
// Relations
|
|
client Client @relation(fields: [clientId], references: [id], onDelete: Cascade)
|
|
employe Employe? @relation(fields: [employeId], references: [id])
|
|
ordonnances Ordonnance[]
|
|
}
|
|
|
|
// Ordonnance (prescription médicale)
|
|
model Ordonnance {
|
|
id String @id @default(cuid())
|
|
patientId String
|
|
numero String @unique
|
|
dateEmission DateTime
|
|
medecin String?
|
|
notes String?
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
// Relations
|
|
patient Patient @relation(fields: [patientId], references: [id], onDelete: Cascade)
|
|
fichiers Fichier[]
|
|
}
|
|
|
|
// Fournisseur
|
|
model Fournisseur {
|
|
id String @id @default(cuid())
|
|
nom String
|
|
contact String?
|
|
email String?
|
|
telephone String?
|
|
adresse String?
|
|
ville String?
|
|
codePostal String?
|
|
notes String?
|
|
actif Boolean @default(true)
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
// Relations
|
|
facturesAchat FactureAchat[]
|
|
produits Produit[]
|
|
}
|
|
|
|
// Produit (lunettes, lentilles, accessoires, verres)
|
|
model Produit {
|
|
id String @id @default(cuid())
|
|
reference String @unique
|
|
designation String
|
|
categorie String // MONTURE, VERRE, LENTILLE, ACCESSOIRE
|
|
fournisseurId String?
|
|
prixAchatHT Float
|
|
prixVenteTTC Float
|
|
tva Float @default(20.0)
|
|
stock Int @default(0)
|
|
stockMin Int @default(5)
|
|
emplacement String? // Rayon, étagère
|
|
marque String?
|
|
typeMonture TypeMonture?
|
|
typeVerre TypeVerre?
|
|
indice Float? // Indice de réfraction (1.5, 1.6, etc.)
|
|
materiau String? // Acétate, métal, titane, etc.
|
|
couleur String?
|
|
dimensions String? // Largeur, pont, branches (ex: 54-18-140)
|
|
description String?
|
|
codeBarre String? @unique
|
|
actif Boolean @default(true)
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
// Relations
|
|
fournisseur Fournisseur? @relation(fields: [fournisseurId], references: [id])
|
|
ligneVente LigneVente[]
|
|
ligneFacture LigneFacture[]
|
|
fichiers Fichier[]
|
|
}
|
|
|
|
// Vente
|
|
model Vente {
|
|
id String @id @default(cuid())
|
|
clientId String?
|
|
numero String @unique
|
|
date DateTime @default(now())
|
|
statut StatutVente @default(INITIEE)
|
|
statutAtelier StatutAtelier @default(EN_ATTENTE)
|
|
montantHT Float
|
|
montantTVA Float
|
|
montantTTC Float
|
|
remise Float @default(0)
|
|
notes String?
|
|
employeId String?
|
|
dateAtelier DateTime?
|
|
dateRetrait DateTime?
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
// Relations
|
|
client Client? @relation(fields: [clientId], references: [id])
|
|
employe Employe? @relation(fields: [employeId], references: [id])
|
|
lignes LigneVente[]
|
|
paiements Paiement[]
|
|
retours Retour[]
|
|
fichiers Fichier[]
|
|
}
|
|
|
|
// Ligne de vente
|
|
model LigneVente {
|
|
id String @id @default(cuid())
|
|
venteId String
|
|
produitId String
|
|
quantite Int @default(1)
|
|
prixUnitaireHT Float
|
|
prixUnitaireTTC Float
|
|
remise Float @default(0)
|
|
montantHT Float
|
|
montantTTC Float
|
|
createdAt DateTime @default(now())
|
|
|
|
// Relations
|
|
vente Vente @relation(fields: [venteId], references: [id], onDelete: Cascade)
|
|
produit Produit @relation(fields: [produitId], references: [id])
|
|
}
|
|
|
|
// Paiement
|
|
model Paiement {
|
|
id String @id @default(cuid())
|
|
venteId String
|
|
mode ModePaiement
|
|
montant Float
|
|
date DateTime @default(now())
|
|
reference String?
|
|
notes String?
|
|
employeId String?
|
|
createdAt DateTime @default(now())
|
|
|
|
// Relations
|
|
vente Vente @relation(fields: [venteId], references: [id], onDelete: Cascade)
|
|
employe Employe? @relation(fields: [employeId], references: [id])
|
|
}
|
|
|
|
// Facture d'achat
|
|
model FactureAchat {
|
|
id String @id @default(cuid())
|
|
fournisseurId String
|
|
numero String @unique
|
|
date DateTime @default(now())
|
|
dateReception DateTime?
|
|
statut StatutAchat @default(BROUILLON)
|
|
montantHT Float
|
|
montantTVA Float
|
|
montantTTC Float
|
|
notes String?
|
|
employeId String?
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
// Relations
|
|
fournisseur Fournisseur @relation(fields: [fournisseurId], references: [id])
|
|
employe Employe? @relation(fields: [employeId], references: [id])
|
|
lignes LigneFacture[]
|
|
fichiers Fichier[]
|
|
}
|
|
|
|
// Ligne de facture d'achat
|
|
model LigneFacture {
|
|
id String @id @default(cuid())
|
|
factureId String
|
|
produitId String
|
|
quantite Int @default(1)
|
|
prixUnitaireHT Float
|
|
tauxTVA Float @default(20.0)
|
|
montantHT Float
|
|
montantTVA Float
|
|
montantTTC Float
|
|
createdAt DateTime @default(now())
|
|
|
|
// Relations
|
|
facture FactureAchat @relation(fields: [factureId], references: [id], onDelete: Cascade)
|
|
produit Produit @relation(fields: [produitId], references: [id])
|
|
}
|
|
|
|
// Retour / SAV
|
|
model Retour {
|
|
id String @id @default(cuid())
|
|
venteId String?
|
|
numero String @unique
|
|
date DateTime @default(now())
|
|
motif String
|
|
montant Float
|
|
notes String?
|
|
employeId String?
|
|
createdAt DateTime @default(now())
|
|
|
|
// Relations
|
|
vente Vente? @relation(fields: [venteId], references: [id])
|
|
employe Employe? @relation(fields: [employeId], references: [id])
|
|
}
|
|
|
|
// Fichier / Document
|
|
model Fichier {
|
|
id String @id @default(cuid())
|
|
nom String
|
|
type TypeFichier
|
|
url String
|
|
taille Int
|
|
mimeType String
|
|
createdAt DateTime @default(now())
|
|
|
|
// Relations - Optionnelles selon le type
|
|
ordonnanceId String?
|
|
venteId String?
|
|
factureAchatId String?
|
|
produitId String?
|
|
|
|
ordonnance Ordonnance? @relation(fields: [ordonnanceId], references: [id])
|
|
vente Vente? @relation(fields: [venteId], references: [id])
|
|
factureAchat FactureAchat? @relation(fields: [factureAchatId], references: [id])
|
|
produit Produit? @relation(fields: [produitId], references: [id])
|
|
}
|