{ Utilisation de tableaux et nombre de clients inconnu pour cette
version du 16 janvier 2000 }

PROGRAM facturation;
uses crt;
VAR aff, nbrart, i, compteur, comptart: integer;
    nomcl, adrcl, cp, vilcl: string;
    tothtva, tothtvb, tothtvc, tottvaca, tottvacb,
    tottvacc, totalht, totaltva, facture: real;
    n: char;
    numart:array [1..50] of real;
    pua:array [1..50] of real;
    qteart:array [1..50] of real;
    pvhtva:array [1..50] of real;
    codtva:array [1..50] of char;


PROCEDURE affichage;
BEGIN
   FOR i:=1 to 50 do WRITE ('-');
   WRITELN;
   WRITELN ('Num‚ro','Prix Unit.':12,'Quantit‚':13,'Code':8,'Prix':10);
   FOR i:=1 to 50 do WRITE ('-');
   WRITELN;
   for aff := 1 to nbrart do
   WRITELN (numart[aff]:6:0, pua[aff]:10:1, qteart[aff]:13:0, codtva[aff]:8, pvhtva[aff]:12:1)
END;


PROCEDURE entete;
BEGIN
    WRITELN ('Firme le bon petit marchand':50);
    WRITELN ('220 route d''Arlon':45);
    WRITELN ('STRASSEN':39);
    WRITELN; WRITELN;
    WRITELN ('Monsieur ',nomcl);
    WRITELN (' ':9, adrcl);
    WRITELN (' ':9, cp,' ',vilcl)
END;

(* Commencement de la boucle principale du programme *)

BEGIN
CLRSCR;
WRITE ('Commencer a encoder les factures ? (o/n): ');
READLN (n);
WHILE ((n = 'o') or (n = 'O')) DO

    BEGIN

    (* Remise a 0 des variables *)

    tothtva := 0; tothtvb := 0; tothtvc := 0;
    tottvaca := 0; tottvacb := 0; tottvacc := 0;

    (* Saisie des donn‚es clients *)

    WRITE ('Nom du client: '); READLN (nomcl);
    WRITE ('Rue + num‚ro: '); READLN (adrcl);
    WRITE ('Code postal: '); READLN (cp);
    WRITE ('Ville: '); READLN (vilcl);

    (* Saisie des articles command‚s *)

    WRITE ('Nombre d''articles de la commande: '); READLN (nbrart);
    FOR comptart := 1 to nbrart do

        BEGIN

        (* Saisie de chaque article *)

        WRITE ('Num‚ro de l''article: '); READLN (numart[comptart]);
        WRITE ('Prix unitaire: '); READLN (pua[comptart]);
        WRITE ('Quantit‚ command‚e: '); READLN (qteart[comptart]);
        WRITE ('Code TVA (a b ou c): '); READLN (codtva[comptart]);
        pvhtva[comptart] := pua[comptart] * qteart[comptart];

        (* Test pour appliquer le taux de TVA correct *)

        IF codtva[comptart] = 'a' then tothtva := tothtva + pvhtva[comptart];
        IF codtva[comptart] = 'b' then tothtvb := tothtvb + pvhtva[comptart];
        IF codtva[comptart] = 'c' then tothtvc := tothtvc + pvhtva[comptart];

        END;

    (* Calculs des totaux *)

    tottvaca := tothtva + (tothtva * 6 / 100);
    tottvacb := tothtvb + (tothtvb * 16 / 100);
    tottvacc := tothtvc + (tothtvc * 25 / 100);
    totalht := tothtva  + tothtvb + tothtvc;
    totaltva := (tothtva * 6 / 100) + (tothtvb  * 16 / 100) + (tothtvc * 25 / 100);
    facture := totalht  + totaltva;

    (* Affichage de la facture *)

    clrscr;
    entete;
    writeln;
    affichage;
    WRITELN;
    WRITELN ('HTVA','CODE':12,'TAUX':13,'TVA':8,'TVAC':13);
    FOR i:=1 to 50 do write ('-');
    WRITELN;
    WRITELN (tothtva:6:1, 'A':12, '6':13, (tothtva * 6 / 100):8:1, tottvaca:12:1);
    WRITELN (tothtvb:6:1, 'B':12, '16':13, (tothtvb * 16 / 100):8:1, tottvacb:12:1);
    WRITELN (tothtvc:6:1, 'C':12, '25':13, (tothtvc * 25 / 100):8:1, tottvacc:12:1);
    WRITELN;
    WRITELN ('HTVA':30, 'TVA':8, 'TOTAL':11);
    WRITELN ('------------------------------':49);
    WRITELN (totalht:30:1, totaltva:8:1, facture:11:1);
    READLN;
    clrscr;
    WRITE ('Continuer avec un autre client ? (o/n) ');
    READLN (n)
    END;  (* n != o *)

WRITELN;
WRITELN ('Fin des factures')

END.
