unit leeruniversal;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons;
type
TForm1 = class(TForm)
ButtonAgrupar: TBitBtn;
OpenDialog1: TOpenDialog;
Label1: TLabel;
Label2: TLabel;
BitBtn1: TBitBtn;
procedure ButtonAgruparClick(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
private
detener : string;
public
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.ButtonAgruparClick(Sender: TObject);
var
s1, s2 : TStringList;
archivo: string;
monto, nombre, autoriz, fecha : string;
anombre, aautoriz, afecha : string;
i : Integer;
cant : Integer;
conv : Double;
ruta : string;
dia : Word;
mes : Word;
ano : Word;
hor : Word;
min : Word;
sec : Word;
mil : Word;
romp : string;
total: Real;
erro : Integer;
errl : string;
linea: string;
taman: Integer;
orig : string;
begin
detener := 'N';
autoriz :='';
nombre := '';
fecha :='';
aautoriz :='';
anombre := '';
afecha :='';
errl := '';
linea:='';
total := 0;
cant := 0;
erro := 0;
orig := '0402364972811201203003798 118 12424409 A010010010100013402000000000014450PEÑA PAULA 903856 ';
taman:= Length(orig);
s1 := TStringList.Create;
s2 := TStringList.Create;
try
OpenDialog1.Execute;
archivo := OpenDialog1.FileName;
s1.LoadFromFile(archivo);
DecodeDate(Now,ano,mes,Dia);
DecodeTime(Now,hor,min,sec,mil);
ruta := OpenDialog1.InitialDir +'Universal_'+inttostr(Dia)+inttostr(mes)+inttostr(ano)+'_'+inttostr(hor)+inttostr(min)+inttostr(sec )+'.txt';
romp := Trim(Copy(s1[0], 36, 8)); anombre := Trim(Copy(s1[i], 85, 60)); aautoriz := Trim(Copy(s1[i], 36, 8)); afecha := Trim(Copy(s1[i], 10, 8));
for i := 0 to (s1.Count-1) do
begin
if Length(s1.Strings[i]) = taman then
begin
monto := Trim(Copy(s1[i], 70, 15)); nombre := Trim(Copy(s1[i], 85, 60)); autoriz := Trim(Copy(s1[i], 36, 8)); fecha := Trim(Copy(s1[i], 10, 8));
If (monto <> '') and (nombre <> '') and (autoriz <> '') then
begin
try
conv := (StrToFloat(monto)*0.01);
monto := FloatToStr(conv);
except
monto := '0.00';
erro := erro + 1;
Label1.Caption := 'Cantidad de errores encontrados = ' + IntToStr(erro);
end;
end;
If Trim(autoriz) <> '' then
begin
If Trim(autoriz) <> Trim(romp) then
begin
linea := '';
linea := afecha + #9 + anombre + #9 + '0000000' + #9 + '0000000' + #9 + '0000000' + #9 + aautoriz + #9 + FloatToStr(total) + #9 + FloatToStr(total);
s2.Add(linea);
total := 0;
romp := Trim(autoriz);
anombre := nombre;
afecha := fecha;
aautoriz:= autoriz;
end;
end;
total := total + StrToFloat(monto);
cant := cant + 1;
Label2.Caption := IntToStr(cant);
Application.ProcessMessages;
If Detener = 'S' then
Break;
end
else
begin
errl := errl + 'Error en Linea '+IntToStr(i)+' - '+ s1.Strings[i]+ ' (TAMAÑO DE LINEA NO COINCIDEN) '+#13;
end;
end;
If (total > 0) then
begin
linea := '';
linea := afecha + #9 + anombre + #9 + '0000000' + #9 + '0000000' + #9 + '0000000' + #9 + aautoriz + #9 + FloatToStr(total) + #9 + FloatToStr(total);
s2.Add(linea);
end;
s2.SaveToFile(ruta);
ShowMessage(errl);
finally
s1.Free;
s2.Free;
end;
Application.Terminate;
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
detener := 'S';
end;
end.