PROGRAM facturation;
uses crt;
VAR n, nbrart, i, numart, qteart, compteur, comptart: integer;
    nomcl, adrcl, cp, vilcl: string;
    pua, pvhtva, tothtva, tothtvb, tothtvc, tottvaca, tottvacb,
    tottvacc, totalht, totaltva, facture: real;
    codtva: char;


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 ('Veuillez introduire le nombre de clients de la journ‚e: ');
READLN (n);
FOR compteur :=1 to n 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);

    entete;

    (* 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);
        WRITE ('Prix unitaire: '); READLN (pua);
        WRITE ('Quantit‚ command‚e: '); READLN (qteart);
        WRITE ('Code TVA (a b ou c)'); READLN (codtva);
        pvhtva := pua * qteart;

        (* Test pour appliquer le taux de TVA correct *)

        IF codtva = 'a' then tothtva := tothtva + pvhtva;
        IF codtva = 'b' then tothtvb := tothtvb + pvhtva;
        IF codtva = 'c' then tothtvc := tothtvc + pvhtva;

        (* Affichage des r‚sultats *)

        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;
        WRITELN (numart:6, pua:10:1, qteart:13, codtva:8, pvhtva:12:1)

        END;

    (* Calcul et affichage des totaux *)

    tottvaca := tothtva + (tothtva * 6 / 100);
    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);
    tottvacb := tothtvb + (tothtvb * 16 / 100);
    WRITELN (tothtvb:6:1, 'B':12, '16':13, (tothtvb * 16 / 100):8:1, tottvacb:12:1);
    tottvacc := tothtvc + (tothtvc * 25 / 100);
    WRITELN (tothtvc:6:1, 'C':12, '25':13, (tothtvc * 25 / 100):8:1, tottvacc:12:1);
    totalht := tothtva  + tothtvb + tothtvc;
    totaltva := (tothtva * 6 / 100) + (tothtvb  * 16 / 100) + (tothtvc * 25 / 100);
    facture := totalht  + totaltva;
    WRITELN;
    WRITELN ('HTVA':30, 'TVA':8, 'TOTAL':11);
    WRITELN ('------------------------------':49);
    WRITELN (totalht:30:1, totaltva:8:1, facture:11:1)

    END;

WRITELN;
WRITELN ('Fin des factures')

END.
