program Facturation_commande;

 const   codeA=6;
         codeB=16;
         codeC=25;

    var   nom,                                     {Nom du client}
          adresse,                                 {Adresse du client}
          cp,                                      {Code postal du client}
          ville,                                   {Ville ou r‚side le client}
          reference,                               {R‚f‚rence de l'article}
          codetva :string;                         {Code A ou B ou C selon l'article}
          quantite,                                {Quantit‚ command‚e}
          k,                                       {Constante pour lr FOR}
          l,                                       {Constante pour lr FOR}
          nbrclients,                              {Nombre de clients … facturer}
          nbrart,                         {Nombre de types d'articles}
          prixunit:integer;                        {Prix par unit‚}
          tvaA, tvaB, tvaC:real;                   {TVA sur l'article selon son type}
          prixdevente:longint;                     {Prix de vente de tous les articles du mˆme type}
          pttcA,pttcB,pttcC,                       {Prix total toutes taxes comprises}
          taux,                                    {Taux TVA}
          tothtA,tothtB,tothtC,                    {Total hors TVA (A,B,C)}
          SOMHTVA,TOTTVA,TOTTTC : real;            {Somme hors taxes;Somme tva;Somme tva+somme hors taxes}
          A,B,C :char;                             {Variables d‚finissant le type de TVA … appliquer … l'article}
          temp : text;

     Procedure entete_1;
     begin
      Write('Introduisez le nombre de clients de la journee:');readln(nbrclients);
      for l:=1 to nbrclients do
       begin
         write('Introduisez le nom du client:');readln(nom);
         write('Introduisez l''adresse du client:');readln(adresse);
         write('Introduisez le code postal du client:');readln(cp);
         write('Introduisez la ville :');readln(ville);
         tothtA:=0;
         tothtB:=0;
         tothtC:=0;
       end;
     end;


    Procedure entete_2;
      begin
        writeln(temp,'          FIRME BON PETIT MARCHAND');
        writeln(temp,'              220 route d''Arlon   ');
        writeln(temp,'                   STRASSEN       ')
      end;

     Procedure entete_3;
       begin
        writeln(temp,'                   ',nom  );
        writeln(temp,'                ',adresse);
        writeln(temp,'               ',cp,ville)
       end;

     Procedure prix_de_vente;

       begin
        write('Introduisez le nombre d''articles commandes');readln(nbrart);
        for k:=1 to nbrart do
         begin
           write('Introduisez le num‚ro de l''article');readln(reference);
           write('Introduisez le prix unitaire de l''article');readln(prixunit);
           write('Introduisez la quantite commande');readln(quantite);
           write('introduisez le code tva de l''article');readln(codetva);
           prixdevente:= quantite *  prixunit;
           if codetva='A' then tothtA:= tothtA+prixdevente
            else if codetva='B' then tothtB:=tothtB + prixdevente
            else if codetva='C' then tothtC:=tothtC + prixdevente;
           writeln('Le prix de vente est de ',prixdevente,'francs');
           writeln(temp,'--------------------------------------------------------');
           writeln(temp,'num‚ro    prix unit   quantit‚    Code art    Prix htva');
           writeln(temp,'--------------------------------------------------------');
           writeln(temp,reference,'         ', prixunit,'           ',quantite,'           ',
           codetva,'           ',prixdevente);

         end;
       end;

    Procedure tabl_ttc;

     begin
           tvaA:=(tothtA /100)* codeA ;
           tvaB:=(tothtB /100) * codeB ;
           tvaC:=(tothtC /100) * codeC ;

           pttcA:=tothtA + tvaA;
           pttcB:=tothtB + tvaB;
           pttcC:=tothtC + tvaC;

            writeln(temp,'--------------------------------------------------------');
            writeln(temp,'   HTVA   code        tx          TVA         TVAC      ');
            writeln(temp,'--------------------------------------------------------');
            writeln(temp,tothtA:7:0,'     ','A','         ',codeA,'        ',tvaA:5:0,'    ',pttcA:7:0);
            writeln(temp,tothtB:7:0,'     ','B','         ',codeB,'        ',tvaB:5:0,'    ',pttcB:7:0);
            writeln(temp,tothtC:7:0,'     ','C','         ',codeC,'        ',tvaC:5:0,'    ',pttcC:7:0);
     end;

    Procedure tabltotal;
     begin
      SOMHTVA:=tothtA + tothtB + tothtC;
      TOTTVA:=tvaA + tvaB + tvaC;
      TOTTTC:=SOMHTVA + TOTTVA;

       writeln(temp,'                            HTVA         TVA      TOTAL');
       writeln(temp,'                            ---------------------------');
       writeln(temp,'                          ',SOMHTVA:7:0,'    ',TOTTVA:7:0,'    ',TOTTTC:7:0);
       writeln(temp,'                            ---------------------------');
     end;

BEGIN
    assign(temp,'c:\result.txt');rewrite(temp);
    entete_1;
    writeln(temp,'');
    entete_2;
    entete_3;
    prix_de_vente;
    tabl_ttc;
    tabltotal;
    close(temp)
END.
