233 lines
6.4 KiB
C
233 lines
6.4 KiB
C
#include <stdio.h>
|
||
#include <stdlib.h>
|
||
#include <string.h>
|
||
#include <stdio.h>
|
||
#include <conio.h>
|
||
#define __TVA__ 1.21
|
||
#define __REDUC__ 0.9
|
||
#define __MAXNBRART__ 3
|
||
|
||
#define __STRLEN__ 34
|
||
|
||
typedef struct {
|
||
char deisgnation[__STRLEN__];
|
||
float prixHTVA;
|
||
int quant;
|
||
} Article;
|
||
typedef struct {
|
||
Article * article;
|
||
unsigned int nbrArt;
|
||
} Panier;
|
||
|
||
|
||
|
||
|
||
void EncoderDate(int*, int*, int*);
|
||
int DateValide (int, int, int);
|
||
void afficherArticle(Article * article, unsigned int nbrArt, FILE * file);
|
||
void encoderArticle(Article * article);
|
||
|
||
int main()
|
||
{
|
||
int j,m,a;
|
||
char continuer = 'y';
|
||
FILE * file;
|
||
file = fopen("fact.txt","w");
|
||
if(file == NULL)
|
||
{
|
||
printf("Erreur lors de l'ouvertur !\n");
|
||
return -1;
|
||
}
|
||
|
||
Panier panier;
|
||
panier.article = (Article *)malloc(sizeof(Article));
|
||
panier.nbrArt = 1;
|
||
if(panier.article == NULL)
|
||
{
|
||
printf("ERREUR ALLOCATION !");
|
||
free(panier.article);
|
||
return -1;
|
||
}
|
||
|
||
do
|
||
{
|
||
EncoderDate(&j,&m,&a);
|
||
}
|
||
while (!DateValide(j, m, a));
|
||
|
||
do
|
||
{
|
||
if(panier.nbrArt <= __MAXNBRART__)
|
||
{
|
||
encoderArticle(&(panier.article[panier.nbrArt-1]));
|
||
printf("Y-a-t-il encore un article ?(Y|n)");
|
||
fflush(stdin);
|
||
scanf("%c", &continuer);
|
||
if(panier.nbrArt < 3 && (continuer|0b00100000) == 'y')
|
||
{
|
||
panier.nbrArt++;
|
||
Article * tempArticle;
|
||
tempArticle = (Article*)realloc(panier.article, sizeof(Article)*(panier.nbrArt));
|
||
if(panier.article == NULL)
|
||
{
|
||
printf("ERREUR ALLOCATION !");
|
||
free(tempArticle);
|
||
free(panier.article);
|
||
return -1;
|
||
}
|
||
else
|
||
{
|
||
panier.article = tempArticle;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
system("cls");
|
||
printf("Vous avez ateint le nombre d'article maximum !\n\n");
|
||
break;
|
||
}
|
||
}
|
||
}while((continuer|0b00100000) == 'y');
|
||
//En t<>te de la facture
|
||
printf("La Bulle Informatique\nRoute du Condroz 78, 4123 Neupre\n");
|
||
printf("\nFacture a payer\n");
|
||
printf("Date de facturation :");
|
||
|
||
fprintf(file,"La Bulle Informatique\nRoute du Condroz 78, 4123 Neupre\n");
|
||
fprintf(file,"\nFacture a payer\n");
|
||
fprintf(file,"Date de facturation :");
|
||
if (j<10)
|
||
{
|
||
if (m<10)
|
||
{
|
||
printf("0%d/0%d/%d", j, m, a);
|
||
fprintf(file,"0%d/0%d/%d", j, m, a);
|
||
}
|
||
else
|
||
{
|
||
printf("0%d/%d/%d", j, m, a);
|
||
fprintf(file,"0%d/%d/%d", j, m, a);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (m<10)
|
||
{
|
||
printf("%d/0%d/%d", j, m, a);
|
||
fprintf(file,"%d/0%d/%d", j, m, a);
|
||
}
|
||
else
|
||
{
|
||
printf("%d/%d/%d", j, m, a);
|
||
fprintf(file,"%d/%d/%d", j, m, a);
|
||
}
|
||
}
|
||
printf("%u\n", panier.nbrArt);
|
||
afficherArticle(panier.article,panier.nbrArt, file);
|
||
getch();
|
||
fclose(file);
|
||
free(panier.article);
|
||
return 0;
|
||
}
|
||
void EncoderDate(int *j, int *m, int *a)
|
||
{
|
||
printf("Entrez la date sous cette forme : jj/mm/aaaa\n");
|
||
fflush(stdin); scanf("%d/%d/%d",j,m,a);
|
||
}
|
||
|
||
int DateValide(int j, int m, int a)
|
||
{
|
||
int bis;
|
||
if(m != 2)
|
||
{
|
||
if(m >= 1 && m <= 7)
|
||
{
|
||
if(m %2 == 0)
|
||
{
|
||
if(j >= 1 && j <= 30) return 1;
|
||
else return 0;
|
||
}
|
||
else
|
||
{
|
||
if(j >= 1 && j <= 31) return 1;
|
||
else return 0;
|
||
}
|
||
}
|
||
else if(m > 7 && m <= 12)
|
||
{
|
||
if(m %2 == 0)
|
||
{
|
||
if(j >= 1 && j <= 31) return 1;
|
||
else return 0;
|
||
}
|
||
else
|
||
{
|
||
if(j >= 1 && j <= 30) return 1;
|
||
else return 0;
|
||
}
|
||
}
|
||
else return 0;
|
||
}
|
||
else
|
||
{
|
||
if(a %100 == 0)
|
||
{
|
||
if(a %400 == 0) bis = 1;
|
||
else bis = 0;
|
||
}
|
||
else
|
||
{
|
||
if(a %4 == 0)bis = 1;
|
||
else bis = 0;
|
||
}
|
||
if(bis == 1)
|
||
{
|
||
if(j >= 1 && j <= 29) return 1;
|
||
else return 0;
|
||
}
|
||
else
|
||
{
|
||
if(j >= 1 && j <= 28) return 1;
|
||
else return 0;
|
||
}
|
||
}
|
||
}
|
||
|
||
void afficherArticle(Article * article, unsigned int nbrArt,FILE * file)
|
||
{
|
||
unsigned int i;
|
||
float prixTot=0;
|
||
fprintf(file,"\n|---------------------------------------------------------------------------------------------|\
|
||
\n| Designation | prixHTVA | Quantite | 10%% | prixTVAC |");
|
||
printf("\n|---------------------------------------------------------------------------------------------|\
|
||
\n| Designation | prixHTVA | Quantite | 10%% | prixTVAC |");
|
||
for(i=0;i<nbrArt;i++)
|
||
{
|
||
printf("\n|%34s|%12.2f Eur |%14d| %c |%12.2f |",\
|
||
article[i].deisgnation,article[i].prixHTVA,article[i].quant\
|
||
,(article[i].quant>=20)?'x':' ',\
|
||
(article[i].quant>=20)?article[i].prixHTVA*__TVA__*__REDUC__*article[i].quant:article[i].prixHTVA*__TVA__*article[i].quant);
|
||
fprintf(file,"\n|%34s|%12.2f Eur |%14d| %c |%12.2f |",\
|
||
article[i].deisgnation,article[i].prixHTVA,article[i].quant\
|
||
,(article[i].quant>=20)?'x':' ',\
|
||
(article[i].quant>=20)?article[i].prixHTVA*__TVA__*__REDUC__*article[i].quant:article[i].prixHTVA*__TVA__*article[i].quant);
|
||
|
||
prixTot += (article[i].quant>=20)?article[i].prixHTVA*__TVA__*__REDUC__*article[i].quant:article[i].prixHTVA*__TVA__*article[i].quant;
|
||
}
|
||
printf("\n|---------------------------------------------------------------------------------------------|");
|
||
printf("\nPrix totale :%f", prixTot);
|
||
|
||
fprintf(file,"\n|---------------------------------------------------------------------------------------------|");
|
||
fprintf(file,"\nPrix totale :%f", prixTot);
|
||
}
|
||
void encoderArticle(Article * article)
|
||
{
|
||
printf("\nVeuillez entrer le nom : ");
|
||
scanf("%34s", article->deisgnation);
|
||
printf("\nVeuillez entrer le prix a l'unite hors TVA : ");
|
||
scanf("%f", &article->prixHTVA);
|
||
printf("\nVeuillez entrer la quantite desiree : ");
|
||
fflush(stdin);
|
||
scanf("%d", &article->quant);
|
||
}
|