|
|
@ -3,7 +3,6 @@
|
|
|
|
* @brief Fonctions liées à la gestion des clients et de leur panier.
|
|
|
|
* @brief Fonctions liées à la gestion des clients et de leur panier.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "client.h"
|
|
|
|
#include "client.h"
|
|
|
|
|
|
|
|
|
|
|
|
#define MAX_ARTICLES 100
|
|
|
|
#define MAX_ARTICLES 100
|
|
|
@ -43,6 +42,69 @@ int charger_clients(int numeros[], float cagnottes[], int suspendues[], int tPhy
|
|
|
|
return i;
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @brief Sauvegarde les données clients dans un fichier.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* Cette fonction permet de sauvegarder les données clients, y compris les numéros de clients, les cagnottes,
|
|
|
|
|
|
|
|
* et les états de suspension, dans un fichier texte.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param numeros - Tableau des numéros de clients.
|
|
|
|
|
|
|
|
* @param cagnottes - Tableau des cagnottes des clients.
|
|
|
|
|
|
|
|
* @param suspendus - Tableau des états de suspension des clients.
|
|
|
|
|
|
|
|
* @param nombreClients - Nombre de clients.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
void sauvegarde_clients(int numeros[], float cagnottes[], int suspendus[], int nombreClients) {
|
|
|
|
|
|
|
|
FILE *fe;
|
|
|
|
|
|
|
|
fe = fopen("donnee/client.txt", "w");
|
|
|
|
|
|
|
|
if (fe == NULL) {
|
|
|
|
|
|
|
|
perror("fopen");
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < nombreClients; i++) {
|
|
|
|
|
|
|
|
fprintf(fe, "%d %.2f %d\n", numeros[i], cagnottes[i], suspendus[i]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(fe);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @brief Recherche l'index de l'article dans le tableau des références.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* Cette fonction recherche l'index de l'article avec la référence donnée dans le tableau des références.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param reference - Référence de l'article à rechercher.
|
|
|
|
|
|
|
|
* @param references - Tableau des références des articles.
|
|
|
|
|
|
|
|
* @param nombreArticles - Nombre d'articles disponibles.
|
|
|
|
|
|
|
|
* @return L'index de l'article s'il est trouvé, sinon -1.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
int trouver_index_article(int reference, int references[], int nombreArticles) {
|
|
|
|
|
|
|
|
for (int i = 0; i < nombreArticles; i++) {
|
|
|
|
|
|
|
|
if (references[i] == reference) {
|
|
|
|
|
|
|
|
return i;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @brief Trouve l'index d'un client dans le tableau des numéros de clients.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* Cette fonction recherche le numéro du client dans le tableau des numéros de clients
|
|
|
|
|
|
|
|
* et retourne l'index du client s'il est trouvé.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param numeroClient - Numéro du client à rechercher.
|
|
|
|
|
|
|
|
* @param numeros - Tableau des numéros de clients.
|
|
|
|
|
|
|
|
* @param nombreClients - Nombre de clients dans le tableau.
|
|
|
|
|
|
|
|
* @return L'index du client s'il est trouvé, -1 sinon.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
int trouver_index_client(int numeroClient, int numeros[], int nombreClients) {
|
|
|
|
|
|
|
|
for (int i = 0; i < nombreClients; i++) {
|
|
|
|
|
|
|
|
if (numeros[i] == numeroClient) {
|
|
|
|
|
|
|
|
return i; // Retourne l'index du client si trouvé
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1; // Retourne -1 si le client n'est pas trouvé
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @brief Ajoute un article au panier du client.
|
|
|
|
* @brief Ajoute un article au panier du client.
|
|
|
@ -84,24 +146,10 @@ void ajouter_article_au_panier(int numeroClient, int references[], float poids[]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (getchar() != '\n');
|
|
|
|
while (getchar() != '\n');
|
|
|
|
|
|
|
|
|
|
|
|
int articleIndex = -1;
|
|
|
|
int articleIndex = trouver_index_article(reference, references, nombreArticles);
|
|
|
|
for (int i = 0; i < nombreArticles; i++) {
|
|
|
|
|
|
|
|
if (references[i] == reference) {
|
|
|
|
|
|
|
|
articleIndex = i;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (articleIndex == -1) {
|
|
|
|
if (articleIndex == -1) {
|
|
|
|
printf("Article non trouvé. Veuillez entrer une référence valide.\n");
|
|
|
|
printf("Article non trouvé. Veuillez entrer une référence valide.\n");
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < *taillePanier; i++) {
|
|
|
|
|
|
|
|
if (panier[i] == reference) {
|
|
|
|
|
|
|
|
printf("Cet article est déjà dans le panier.\n");
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
float poidsTotal = poids[articleIndex] * quantite;
|
|
|
|
float poidsTotal = poids[articleIndex] * quantite;
|
|
|
@ -114,13 +162,7 @@ void ajouter_article_au_panier(int numeroClient, int references[], float poids[]
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
float montantTotal = prixUnitaire[articleIndex] * quantite;
|
|
|
|
float montantTotal = prixUnitaire[articleIndex] * quantite;
|
|
|
|
|
|
|
|
|
|
|
|
int clientIndex = -1;
|
|
|
|
int clientIndex = trouver_index_client(numeroClient, numeros, nombreClients);
|
|
|
|
for (int i = 0; i < nombreClients; i++) {
|
|
|
|
|
|
|
|
if (numeros[i] == numeroClient) {
|
|
|
|
|
|
|
|
clientIndex = i;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (clientIndex != -1) {
|
|
|
|
if (clientIndex != -1) {
|
|
|
|
cagnottes[clientIndex] += 0.1 * montantTotal;
|
|
|
|
cagnottes[clientIndex] += 0.1 * montantTotal;
|
|
|
@ -171,13 +213,7 @@ void supprimer_article_du_panier(int panier[], int quantites[], int *taillePanie
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (getchar() != '\n');
|
|
|
|
while (getchar() != '\n');
|
|
|
|
|
|
|
|
|
|
|
|
int articleIndex = -1;
|
|
|
|
int articleIndex = trouver_index_article(reference, panier, *taillePanier);
|
|
|
|
for (int i = 0; i < *taillePanier; i++) {
|
|
|
|
|
|
|
|
if (panier[i] == reference) {
|
|
|
|
|
|
|
|
articleIndex = i;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (articleIndex == -1) {
|
|
|
|
if (articleIndex == -1) {
|
|
|
|
printf("Article non trouvé dans le panier. Veuillez entrer une référence valide.\n");
|
|
|
|
printf("Article non trouvé dans le panier. Veuillez entrer une référence valide.\n");
|
|
|
@ -194,11 +230,11 @@ void supprimer_article_du_panier(int panier[], int quantites[], int *taillePanie
|
|
|
|
printf("Article supprimé du panier avec succès.\n");
|
|
|
|
printf("Article supprimé du panier avec succès.\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @brief Affiche un récapitulatif du contenu du panier.
|
|
|
|
* @brief Affiche un récapitulatif du contenu du panier.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Cette fonction permet d'afficher un récapitulatif du contenu du panier.
|
|
|
|
* Cette fonction permet d'afficher un récapitulatif détaillé du contenu du panier du client, y compris les références des articles,
|
|
|
|
|
|
|
|
* les quantités, les poids, les volumes, les prix unitaires, les totaux de poids, de volume, de prix, et la cagnotte du client.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param panier - Tableau des références des articles dans le panier.
|
|
|
|
* @param panier - Tableau des références des articles dans le panier.
|
|
|
|
* @param taillePanier - Taille du panier.
|
|
|
|
* @param taillePanier - Taille du panier.
|
|
|
@ -207,25 +243,30 @@ void supprimer_article_du_panier(int panier[], int quantites[], int *taillePanie
|
|
|
|
* @param volume - Tableau des volumes des articles.
|
|
|
|
* @param volume - Tableau des volumes des articles.
|
|
|
|
* @param prixUnitaire - Tableau des prix unitaires des articles.
|
|
|
|
* @param prixUnitaire - Tableau des prix unitaires des articles.
|
|
|
|
* @param quantites - Tableau des quantités de chaque article dans le panier.
|
|
|
|
* @param quantites - Tableau des quantités de chaque article dans le panier.
|
|
|
|
|
|
|
|
* @param cagnottes - Tableau des cagnottes des clients.
|
|
|
|
|
|
|
|
* @param numeroClient - Numéro du client.
|
|
|
|
|
|
|
|
* @param numeros - Tableau des numéros de clients.
|
|
|
|
|
|
|
|
* @param nombreClients - Nombre de clients.
|
|
|
|
|
|
|
|
* @param volumeCoffre - Volume total du coffre.
|
|
|
|
|
|
|
|
* @param chargeMaximale - Charge maximale du coffre.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
void affiche_recap_panier(int panier[], int taillePanier, int references[], float poids[], float volume[],
|
|
|
|
void affiche_recap_panier(int panier[], int taillePanier, int references[], float poids[], float volume[],
|
|
|
|
float prixUnitaire[], int quantites[]) {
|
|
|
|
float prixUnitaire[], int quantites[], float cagnottes[], int numeroClient,
|
|
|
|
|
|
|
|
int numeros[], int nombreClients, float volumeCoffre, float chargeMaximale) {
|
|
|
|
|
|
|
|
printf("Contenu du panier : ");
|
|
|
|
|
|
|
|
for (int i = 0; i < taillePanier; i++) {
|
|
|
|
|
|
|
|
printf("%d ", panier[i]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
printf("Récap :\n");
|
|
|
|
printf("Réf Qté Poids Vol PrixU PoidsTot VolTot PrixTot\n");
|
|
|
|
printf("Réf Qté Poids Vol PrixU PoidsTot VolTot PrixTot\n");
|
|
|
|
|
|
|
|
|
|
|
|
float poidsTotal = 0, volumeTotal = 0, montantTotal = 0;
|
|
|
|
float poidsTotal = 0, volumeTotal = 0, montantTotal = 0;
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < taillePanier; i++) {
|
|
|
|
for (int i = 0; i < taillePanier; i++) {
|
|
|
|
int reference = panier[i];
|
|
|
|
int reference = panier[i];
|
|
|
|
int articleIndex = -1;
|
|
|
|
int articleIndex = trouver_index_article(reference, references, MAX_ARTICLES);
|
|
|
|
for (int j = 0; j < MAX_ARTICLES; j++) {
|
|
|
|
|
|
|
|
if (references[j] == reference) {
|
|
|
|
|
|
|
|
articleIndex = j;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (articleIndex == -1) {
|
|
|
|
|
|
|
|
printf("Article non trouvé. Veuillez entrer une référence valide.\n");
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float poidsArticle = poids[articleIndex];
|
|
|
|
float poidsArticle = poids[articleIndex];
|
|
|
|
float volumeArticle = volume[articleIndex];
|
|
|
|
float volumeArticle = volume[articleIndex];
|
|
|
@ -241,9 +282,14 @@ void affiche_recap_panier(int panier[], int taillePanier, int references[], floa
|
|
|
|
montantTotal += prixArticle * quantite;
|
|
|
|
montantTotal += prixArticle * quantite;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int clientIndex = trouver_index_client(numeroClient, numeros, nombreClients);
|
|
|
|
|
|
|
|
|
|
|
|
printf("Prix total à payer: %.2f euros\n", montantTotal);
|
|
|
|
printf("Prix total à payer: %.2f euros\n", montantTotal);
|
|
|
|
|
|
|
|
printf("Cagnotte totale : %.2f euros\n", cagnottes[clientIndex]);
|
|
|
|
printf("Volume utilise : %.2f litres\n", volumeTotal);
|
|
|
|
printf("Volume utilise : %.2f litres\n", volumeTotal);
|
|
|
|
|
|
|
|
printf("Volume restant : %.2f litres\n", volumeCoffre - volumeTotal);
|
|
|
|
printf("Charge Actuelle: %.2f kg\n", poidsTotal);
|
|
|
|
printf("Charge Actuelle: %.2f kg\n", poidsTotal);
|
|
|
|
|
|
|
|
printf("Charge restante: %.2f kg\n", chargeMaximale - poidsTotal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -336,15 +382,4 @@ void deduire_cagnotte(int numeroClient, float montant, int numeros[], float cagn
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
cagnottes[clientIndex] -= montant;
|
|
|
|
cagnottes[clientIndex] -= montant;
|
|
|
|
|
|
|
|
|
|
|
|
FILE *fe;
|
|
|
|
|
|
|
|
fe = fopen("donnee/client.txt", "w");
|
|
|
|
|
|
|
|
if (fe == NULL) {
|
|
|
|
|
|
|
|
perror("fopen");
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < nombreClients; i++) {
|
|
|
|
|
|
|
|
fprintf(fe, "%d %.2f %d\n", numeros[i], cagnottes[i], suspendus[i]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(fe);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|