diff --git a/donnee/client.txt b/donnee/client.txt index 2460022..a3f9e56 100644 --- a/donnee/client.txt +++ b/donnee/client.txt @@ -1,3 +1,3 @@ 32 69.00 1 -5079 75.50 0 +5079 600.70 0 53 0.00 0 diff --git a/src/app/interface/interface_client.c b/src/app/interface/interface_client.c index 03d1f8a..8e3fcca 100644 --- a/src/app/interface/interface_client.c +++ b/src/app/interface/interface_client.c @@ -16,6 +16,7 @@ void affiche_client(void) { printf("||\t4 : Supprimer un article du panier. \t\t\t||\n"); printf("||\t5 : Modifier la quantité d'un article du panier. \t||\n"); printf("||\t6 : Réinitialiser le panier.\t\t\t\t||\n"); + printf("||\t7 : Passer au payement.\t\t\t\t\t||\n"); printf("||\t9 : Quitter.\t\t\t\t\t\t||\n"); printf("+----------------------------------------------------------------+\n"); } @@ -276,7 +277,7 @@ void deduire_cagnotte(int numClient, float montant, int tNumClient[], float tCag printf("Il vous reste %.2f euros dans votre cagnotte.\n", tCagnotte[clientIndex]); } -void quitter_application(int tPanier[], int tLogPanier, int tRef[], float tPoid[], float tVol[], +void payer(int tPanier[], int tLogPanier, int tRef[], float tPoid[], float tVol[], float tPrixUnitaire[], int tQuantite[], float tCagnotte[], int numClient, int tNumClient[], int tLogClient, float budget, int tSus[], float volumeCoffre, float chargeMaximale) { @@ -328,18 +329,21 @@ void quitter_application(int tPanier[], int tLogPanier, int tRef[], float tPoid[ printf("Volume utilise : %.2f litres\n", volumeTotal); printf("Charge Actuelle: %.2f kg\n", poidsTotal); - if(volumeTotal > volumeCoffre) { + if(poidsTotal > chargeMaximale || volumeTotal > volumeCoffre) { printf("Attention : %s", attentionDepassement); printf("Vous ne pourrez pas payer. De plus vous ne pourrez pas utiliser votre cagnotte car votre coffre est plein.\n"); - printf("Payement non effectué.\n"); - return; - } + printf("Voulez vous revenir en arrière pour modifier votre panier ? (1 pour Oui, 0 pour Non) : "); + while (scanf("%d", &choixCagnotte) != 1 || (choixCagnotte != 0 && choixCagnotte != 1)) { + while (getchar() != '\n'); + fprintf(stderr, "\x1B[31mERREUR : Veuillez entrer 1 pour Oui ou 0 pour Non :\x1B[0m "); + } - if(poidsTotal > chargeMaximale) { - printf("Attention : %s", attentionDepassement); - printf("Vous ne pourrez pas payer. De plus vous ne pourrez pas utiliser votre cagnotte car votre coffre est plein.\n"); - printf("Payement non effectué.\n"); - return; + if (choixCagnotte == 1) { + return; + } else { + printf("Payement non effectué.\n"); + return; + } } if(tSus[clientIndex] == 1 && budget > 0 && montantTotal > budget) { @@ -417,7 +421,7 @@ void quitter_application(int tPanier[], int tLogPanier, int tRef[], float tPoid[ void menu_client(int *choix) { affiche_client(); printf("Vous choisissez: "); - while (scanf("%d", choix) != 1 || *choix < 0 || *choix > 9 || (*choix > 6 && *choix < 9)) { + while (scanf("%d", choix) != 1 || *choix < 0 || *choix > 9 || (*choix > 7 && *choix < 9)) { while (getchar() != '\n'); fprintf(stderr, "\x1B[31mERREUR : Veuillez entrer un choix valide :\x1B[0m "); } @@ -462,8 +466,10 @@ void global_client(void) { case 6: reinitialiser_panier(tPanier, tQuantite, &tLogPanier, tCagnotte, numClient, tNumClient, tLogClient, tRef, tPrixUnitaire); break; + case 7: + payer(tPanier, tLogPanier, tRef, tPoids, tVol, tPrixUnitaire, tQuantite, tCagnotte, numClient, tNumClient, tLogClient, budget, tSus, volumeCoffre, chargeMaximale); + break; case 9: - quitter_application(tPanier, tLogPanier, tRef, tPoids, tVol, tPrixUnitaire, tQuantite, tCagnotte, numClient, tNumClient, tLogClient, budget, tSus, volumeCoffre, chargeMaximale); sauvegarde_clients(tNumClient, tCagnotte, tSus, tLogClient); printf("Au revoir !\n"); return; diff --git a/src/app/interface/interface_client.h b/src/app/interface/interface_client.h index 94207a6..e85608b 100644 --- a/src/app/interface/interface_client.h +++ b/src/app/interface/interface_client.h @@ -137,7 +137,9 @@ void reinitialiser_panier(int tPanier[], int tQuantite[], int *tLogPanier, float void deduire_cagnotte(int numClient, float montant, int tNumClient[], float tCagnotte[], int tLogClient); /** - * @brief Quitter l'application client. + * @brief Passe a la phase de paiement. + * + * Cette fonction vérifie les dépassement de volume, de poids et de budget avant de quitter l'application. * * @param tPanier - Le panier d'achat du client. * @param tLogPanier - La taille du panier. @@ -155,7 +157,7 @@ void deduire_cagnotte(int numClient, float montant, int tNumClient[], float tCag * @param volumeCoffre - La limite de volume pour le véhicul du client. * @param chargeMaximale - La limite de poids pour le véhicul du client. */ -void quitter_application(int tPanier[], int tLogPanier, int tRef[], float tPoid[], float tVol[], +void payer(int tPanier[], int tLogPanier, int tRef[], float tPoid[], float tVol[], float tPrixUnitaire[], int tQuantite[], float tCagnotte[], int numClient, int tNumClient[], int tLogClient, float budget, int tSus[], float volumeCoffre, float chargeMaximale);