uses GKVars, DateUnit,Crt;
type
PagoFileType = File of PagoRecType;
RescRecType = Record
RescCosto : CostoRecType;
Importe : Real;
end;
var
FileName : String12;
Index : Text;
CostoFile : File of CostoRecType;
CostoRec : CostoRecType;
TasaFile : PagoFileType;
PagoFile : PagoFileType;
RvaFile : File of RvaRecType;
RvaRec : RvaRecType;
Pago : Real;
FecVal : String8;
RvaAnt,
DivAcumAnt : Real;
FileExist : Boolean;
Stop : Boolean;
ValuePos,
TasaPos : Word;
Rescate : Boolean;
RescFile : File of RescRecType;
RescRec : RescRecType;
MontoResc : Real;
function NomArcPago(FileName: String12) :String12;
begin
Delete(FileName,Length(FileName)-3,4);
Delete(FileName,1,2);
NomArcPago := 'PK' + FileName + '.DAT';
end;
function GetFirstValue(var PagoFile : PagoFileType;
Key : String5 ;
var Valor : Real ) : Word ;
var
Reg : PagoRecType;
Low, Mid, High : LongInt;
begin
GetFirstValue := 0;
Valor := 0;
{$I-}
Reset(PagoFile);
{$I+}
if IOResult=0 then begin
low := 0;
high := FileSize(PagoFile) - 1;
While high >= low do begin
mid := (low + high) div 2;
Seek(PagoFile,Mid);
Read(PagoFile,Reg);
With Reg do begin
If Key > KeyRec then
low := mid + 1
Else begin
If Key < KeyRec then
high := mid - 1
Else begin
high := -1;
Valor := Reg.Value
end
end;
end { with }
end; { while }
GetFirstValue := FilePos(PagoFile);
end; { if IOResult = 0 }
end; { function GetFirstValue }
function GetNextValue(var PagoFile : PagoFileType ;
var ValuePos : Word ;
var Valor : Real ) : Boolean;
var
Reg : PagoRecType;
begin
GetNextValue := False;
Seek(PagoFile,ValuePos);
If not eof(PagoFile) then begin
Read(PagoFile,Reg);
ValuePos := FilePos(PagoFile);
Valor := Reg.Value;
GetNextValue := True;
end;
end;
function GetPagoAcum(var PagoFile : PagoFileType;
Key : String5 ;
var Valor : Real ) : Word;
var
Pago : Real;
PagoIni : Real;
Anio, AnioI : Word;
Mes, MesI,
MesF : Word;
ValuePos : Word;
Code : Integer;
begin
FileExist := True;
PagoIni := 0;
ConvWord(Key,AnioI,MesI);
for Anio := 87 to AnioI do begin
If Anio = AnioI then MesF:=MesI Else MesF:=12;
for Mes := 1 to MesF do begin
If (Mes=1) and (Anio=87) then begin
ValuePos := GetFirstValue(PagoFile,'87-01',Pago);
If ValuePos = 0 then begin
FileExist := False;
Writeln(' File "',NomArcPago(FileName),'" does not exist or ',
'it is empty');
Writeln
end
end
Else begin
If FileExist then
If not GetNextValue(PagoFile,ValuePos,Pago) then Pago := 0
end;
PagoIni := PagoIni + Pago;
end;
end;
Valor := PagoIni;
If FileExist then GetPagoAcum := FilePos(PagoFile)
Else GetPagoAcum := 0;
end;
procedure CalcRva(var Rva, DivAcum, Divid, ContAut : Real ;
Fx,
Costo,
Pago,
ir : Real );
const
it = 0.004867551 ; { 6% mensualizado }
var
RvaAnt,
DivAcumAnt,
RvaIni,
PagoNeto : Real;
function ContAutomat(var Rva,DivAcum : Real): Real;
begin
ContAutomat := 0;
If -Rva > DivAcum then begin
Rva := Rva + DivAcum;
ContAutomat := DivAcum;
DivAcum := 0
end
Else begin
DivAcum := DivAcum + Rva;
ContAutomat := -Rva;
Rva := 0
end;
end;
begin { procedure CalcRva }
RvaAnt := Rva;
DivAcumAnt := DivAcum;
RvaIni := RvaAnt - Fx;
PagoNeto := Pago * 0.75;
Rva := RvaIni * (1+it) - Costo + PagoNeto * (1 + it/2) ;
If RvaIni < 0 then Divid := PagoNeto * (ir - it)/2
Else Divid := RvaIni * (ir - it) + PagoNeto * (ir - it)/2 ;
If Divid < 0 then Divid := 0;
DivAcum := DivAcumAnt * (1+ir) + Divid;
If Rva < 0 then ContAut := ContAutomat(Rva,DivAcum)
Else ContAut := 0;
end; { procedure CalcRva }
function ComisionRenov(var Rva, DivAcum, PrimaRen : Real ) : Real;
var
Comision : Real;
Saldo : Real;
Reg : PagoRecType;
KeyRec : String5;
begin
Read(PagoFile,Reg);
with Reg do begin
If ( KeyRec > '91-08') or ( KeyRec < '07-01') then
begin
Clrscr;gotoxy(1,2);write('Key ',KeyRec);
Comision := 0;
end
Else begin
Comision := 0.25 * PrimaRen;
If DivAcum >= Comision then DivAcum := DivAcum - Comision
Else begin
Saldo := Comision - DivAcum;
DivAcum := 0;
If Rva > Saldo then Rva := Rva - Saldo
Else begin
If Rva <= 0 then Comision := Comision - Saldo
Else begin
Comision := Comision - (Saldo - Rva);
Rva := 0
end
end
end
end;
ComisionRenov := Comision;
end; {with}
end;
function RescExist( FileName : String12 ): Boolean;
begin
ChangeExt(FileName,'RSC');
Assign(RescFile,RescPath + FileName);
{$I-} Reset(RescFile); {$I+}
RescExist := (IOResult=0);
end;
begin { main program }
Repeat
Write(' Fecha de Valuacion (DD/MM/AA) :');
Readln(FecVal);
Until Valid(FecVal);
Assign(TasaFile,PagoPath + 'GKTasas.DAT');
Assign(Index,DataPath + 'IndGK.IDX');
Reset(Index);
While not eof(Index) do begin
Readln(Index,FileName);
ChangeExt(FileName,'TOT');
Writeln(' Archivo de Entrada : ',CostoPath + FileName);
Assign(CostoFile,CostoPath + FileName);
Reset(CostoFile);
ChangeExt(FileName,'RVA');
Writeln(' Archivo de Salida : ',RvaPath + FileName);
Writeln;
Assign(RvaFile,RvaPath + FileName);
Rewrite(RvaFile);
RvaAnt := 0;
DivAcumAnt := 0;
FileExist := True;
Assign(PagoFile,PagoPath + NomArcPago(FileName));
Stop := False;
Rescate := RescExist(FileName);
While not Stop do begin
read(CostoFile,CostoRec);
Stop := eof(CostoFile) or (CostoRec.AnioMes = Anio_Mes(FecVal));
If Rescate then begin
Read(RescFile,RescRec);
If RescRec.RescCosto.AnioMes = CostoRec.AnioMes then begin
With RescRec, CostoRec do begin
NumAseg := NumAseg - RescCosto.NumAseg;
Prima := Prima - RescCosto.Prima;
SumAseg := SumAseg - RescCosto.SumAseg;
Gasto := Gasto - RescCosto.Gasto;
CostoM := CostoM - RescCosto.CostoM;
CostoT := CostoT - RescCosto.CostoT;
PrimaRen := PrimaRen - RescCosto.PrimaRen;
MontoResc := Importe;
end;
end
Else begin
Reset(RescFile);
MontoResc := 0;
end;
end;
With CostoRec do begin
If FilePos(CostoFile)=1 then begin
ValuePos := GetPagoAcum(PagoFile,AnioMes,Pago)
end
Else begin
If FileExist then begin
If not GetNextValue(PagoFile,ValuePos,Pago) then Pago := 0;
end
end;
With RvaRec do begin
SecName := Seccion;
AnioM := AnioMes;
NAseg := NumAseg;
SAseg := SumAseg;
PrimaR := Pago;
PrimaT := Prima;
Fx := Gasto;
Costo := CostoT;
If FilePos(CostoFile)=1 then
TasaPos := GetFirstValue(TasaFile,AnioMes,Tasa)
Else begin
If not GetNextValue(TasaFile,TasaPos,Tasa) then begin
Writeln(' No existe la Tasa correspondiente a : ',AnioMes);
Tasa := 0
end
end;
Reserva := RvaAnt ;
DivAcum := DivAcumAnt ;
CalcRva(Reserva,DivAcum,Dividendo,ContAut,Fx,Costo,Pago,Tasa);
If Rescate then begin
If DivAcum >= MontoResc then DivAcum := DivAcum - MontoResc
Else begin
Reserva := Reserva + (DivAcum - MontoResc);
DivAcum := 0;
end;
end;
Comision := ComisionRenov(Reserva,DivAcum,PrimaRen);
RvaAnt := Reserva ;
DivAcumAnt := DivAcum ;
Write(RvaFile,RvaRec);
end; { with RvaRec }
end; { with CostoRec }
end; { while not eof(CostoFile) }
Close(CostoFile);
If Rescate then Close(RescFile);
If FileExist then Close(PagoFile);
Close(TasaFile);
Close(RvaFile);
end; { while not eof(Index) }
Close(Index);
end. { main program }
este todo el codigo de mi programa
muchas gracias......