1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
| procedure TFPrincipal.JvXPButton1Click(Sender: TObject);
Var
i: Integer;
DatePiece, DateEcheance: String;
FTxt: TextFile;
begin
with TStringList.Create do
Begin
Try
LoadFromFile(DossierDefaut+'\'+FichierAtraiter);
i := 0;
While (Strings[i] <> FinDeFichier) do
Begin
if (Strings[i] = RuptureLigne) then
Begin
With ADOTable2 Do
Begin
Open;
Insert;
FieldByName('Rupture').AsString := Strings[i];
FieldByName('Journal').AsString := Strings[i+1];
DatePiece := LeftStr(Strings[i+2],2) + '/'+ MidStr(Strings[i+2],3,2) + '/' + RightStr(Strings[i+2],2);
if length(DatePiece) = 8 then FieldByName('DatePiece').AsDateTime := StrToDate(DatePiece);
FieldByName('NumPiece').AsString := Strings[i+5];
FieldByName('Compte').AsString := Strings[i+7];
FieldByName('CodeTiers').AsString := Strings[i+9];
FieldByName('LibellePiece').AsString := Strings[i+11];
DateEcheance := LeftStr(Strings[i+13],2) + '/'+ MidStr(Strings[i+13],3,2) + '/' + RightStr(Strings[i+13],2);
if length(DateEcheance) = 8 then FieldByName('DateEcheance').AsDateTime := StrToDate(DateEcheance);
FieldByName('Sens').AsString := Strings[i+17];
FieldByName('Montant').AsFloat := StrToFloat(StringReplace(Strings[i+18],'.',',',[]));
Post;
end;
i := i + 26;
end;
inc(i);
end;
Finally
Free;
ADOTable2.Close;
end;
end;
AssignFile(FTxt,DossierDefaut+'\'+FichierAtraiter); //FichierAtraiter);
ReWrite(FTxt);
i := 0;
With ADOQuery1 do
Begin
SQL.Clear;
SQL.Add('Select Schema.Journal, Schema.NumPiece, Schema.Compte, Schema.Sens, Sum(Schema.Montant) AS SommeDeMontant, Schema.DatePiece, Schema.CodeTiers, Schema.DateEcheance, Schema.LibellePiece ');
SQL.Add('FROM [Schema] ');
SQL.Add('GROUP BY Schema.Journal, Schema.NumPiece, Schema.Compte, Schema.Sens, Schema.DatePiece, Schema.CodeTiers, Schema.DateEcheance, Schema.LibellePiece ');
SQL.Add('Order By Schema.Journal, Schema.NumPiece ');
Open;
WriteLN(FTxt, '#FLG ');
WriteLN(FTxt, '#VER 5');
WriteLN(FTxt, '#DEV EUR');
While not Eof do
Begin
WriteLN(FTxt, '#MECG');
WriteLN(FTxt, Fields.FieldByName('Journal').AsString);
DatePiece := Leftstr(Fields.FieldByName('DatePiece').AsString,2)+ MidStr(Fields.FieldByName('DatePiece').AsString,4,2) + RightStr(Fields.FieldByName('DatePiece').AsString,2);
if Length(DatePiece) = 6 Then
WriteLN(FTxt, DatePiece)
else
WriteLN(FTxt, '');
WriteLN(FTxt, '');
WriteLN(FTxt, '');
WriteLN(FTxt, Fields.FieldByName('NumPiece').AsString);
WriteLN(FTxt, '');
WriteLN(FTxt, Fields.FieldByName('Compte').AsString);
WriteLN(FTxt, '');
WriteLN(FTxt, Fields.FieldByName('CodeTiers').AsString);
WriteLN(FTxt, '');
WriteLN(FTxt, Fields.FieldByName('LibellePiece').AsString);
WriteLN(FTxt, '');
if (Fields.FieldByName('Compte').AsString = RacineClient)
or (Fields.FieldByName('Compte').AsString = RacineFrs) then
Begin
DateEcheance := Leftstr(Fields.FieldByName('DateEcheance').AsString,2)+ MidStr(Fields.FieldByName('DateEcheance').AsString,4,2) + RightStr(Fields.FieldByName('DateEcheance').AsString,2);
if Length(DateEcheance) = 6 Then
WriteLN(FTxt, DateEcheance)
else
WriteLN(FTxt, '');
end
else
WriteLN(FTxt, '');
WriteLN(FTxt, '');
WriteLN(FTxt, '');
WriteLN(FTxt, '');
WriteLN(FTxt, Fields.FieldByName('Sens').AsString);
WriteLN(FTxt, StringReplace(Fields.FieldByName('SommeDeMontant').AsString,',','.',[]));
WriteLN(FTxt, '');
WriteLN(FTxt, '');
WriteLN(FTxt, '');
WriteLN(FTxt, '');
WriteLN(FTxt, '');
WriteLN(FTxt, '');
WriteLN(FTxt, '');
WriteLN(FTxt, '');
next;
end;
WriteLN(FTxt, '#Fin');
end;
ADOQuery1.Close;
CloseFile(FTxt);
end; |
Partager