📌 Explanation of the Database Schema
This entity-relationship diagram (ERD) represents a sales management system where products are sold to clients, and
transactions are recorded. The database consists of four main tables:
1️⃣ Produit (Product)
2️⃣ Client (Customer)
3️⃣ Vente (Sale/Transaction)
4️⃣ LigneVente (Sale Line/Order Line)
Each table is linked to others through primary keys (ID) and foreign keys, ensuring data integrity.
📌 Table Descriptions
1️⃣ Table: Produit (Product)
🔹 Stores information about products available for sale.
Field Type Description
IDProduit Primary Key (Id)Unique identifier for each product.
Reference String Product reference or code.
NomProduit String Name of the product.
PrixRevient Numeric Purchase cost of the product.
PrixVente Numeric Selling price of the product.
Quantité Integer Available stock quantity.
ImageProduit String (Blob) Product image (optional).
DateCreation Date Date when the product was added.
Relationships:
One-to-Many (1,1 → 0,n) relationship with LigneVente
🔗 One product can appear in multiple sales, but each sale line is linked to only one product.
2️⃣ Table: Client (Customer)
🔹 Stores customer details.
Field Type Description
IDClientPrimary Key (Id)Unique identifier for each customer.
NomClient String Name of the client.
Email String Client’s email address.
Genre String Gender (Male/Female/Other).
Telephone String Contact number.
AdresseString Physical address.
Relationships:
One-to-Many (1,1 → 0,n) relationship with Vente
🔗 A client can have multiple sales (purchases), but each sale is linked to only one client.
Table: Vente (Sale/Transaction)
🔹 Stores sales transactions, linking clients to purchases.
Field Type Description
IDVente Primary Key (Id)Unique identifier for each sale.
DateVente Date Date when the sale was made.
IDClientForeign Key Links the sale to a specific client.
MontantTotal Numeric Total amount of the sale.
Bénéfice Numeric Profit earned from the sale.
Relationships:
One-to-Many (1,1 → 0,n) relationship with Client
🔗 One client can make multiple purchases.
One-to-Many (1,1 → 1,n) relationship with LigneVente
🔗 Each sale consists of one or more products.
4️⃣ Table: LigneVente (Sale Line/Order Line)
🔹 Stores details of products sold in each sale.
Field Type Description
IDLigneVente Primary Key (Id) Unique identifier for each sale line.
IDVente Foreign Key Links to the Vente table.
IDProduit Foreign Key Links to the Produit table.
PrixRevient Numeric Cost price of the sold product.
Quantité Integer Number of units sold.
Relationships:
Many-to-One (n,1 → 1,1) relationship with Produit
🔗 A product can appear in multiple sales, but each sale line references one product.
Many-to-One (n,1 → 1,1) relationship with Vente
🔗 A sale can contain multiple products, but each sale line belongs to one sale.
📌 Summary of Relationships
1️⃣ Produit → LigneVente (1,n)
A product can be sold multiple times, but each sale line is linked to one product.
2️⃣ Client → Vente (1,n)
A client can have multiple sales, but each sale belongs to one client.
3️⃣ Vente → LigneVente (1,n)
A sale can contain multiple products, but each sale line belongs to one sale.
📌 How Data Flows in the System
Adding a Product
New products are stored in the Produit table.
Registering a Client
Customers are added to the Client table.
Making a Sale
A new entry is created in the Vente table with the IDClient.
Adding Products to the Sale
Products are selected and added to LigneVente with IDProduit, Quantité, and PrixRevient.
Calculating Total & Profit
MontantTotal = SUM(PrixVente * Quantité)
Bénéfice = SUM((PrixVente - PrixRevient) * Quantité)
Stock Updates
When a product is sold, its Quantité in Produit is reduced.
📌 Example Data
Produit Table
IDProduit NomProduit PrixRevient PrixVente Quantité
1 Tomato Box 10 15 100
2 Wooden Crate 20 30 50
Client Table
IDClient NomClient Email Telephone
1 John Doe john@[Link] 1234567890
2 Jane Doe jane@[Link] 0987654321
Vente Table
IDVente DateVente IDClient MontantTotal Bénéfice
1 2025-03-10 1 45 10
LigneVente Table
IDLigneVente IDVente IDProduit PrixRevient Quantité
1 1 1 10 2
2 1 2 20 1
📌 Conclusion
This database structure ensures: ✅ Data consistency (products, clients, sales are properly linked).
✅ Efficient queries (sales tracking, stock management).
✅ Scalability (new features like discounts or invoices can be added).
Let me know if you need further clarifications! 🚀