Adding Balance Brought Forward to Contributions.

Hi Exerts,
I have a report that i created. There are balances that are imported into a table Called Balances. This balances were the total contributions for each employee before computerization that in 1990. Now i want this balance brought forward to be added to the total contributions for a particulars years say 1991. This result should now show as the balance brought forward for the year 1992. This balance brought for should also be added to the total contributions of 1992 and the answer show as balance brought forward for in the 1993 statement. Also if a user runs the report from say 1990 to 2007, the balance brought forward which is imported into the balances table should be added to the total contributions of an employee from 1990 to 2007 and the sum be taken as balance brought forward for the 2008 statement.

Any ideas on how to go about this. Have a look at the report and please help me solve this.

Code:

OBJECT Report 75023 EmployeeStatementByEmployer
{
OBJECT-PROPERTIES
{
Date=12/02/08;
Time=17:12:37;
Modified=Yes;
Version List=SSMS1.5.6;
}
PROPERTIES
{
Orientation=Portrait;
}
DATAITEMS
{
{ PROPERTIES
{
DataItemTable=Table18;
ReqFilterFields=No.;
}
SECTIONS
{
}
}
{ PROPERTIES
{
DataItemIndent=1;
DataItemTable=Table5200;
DataItemTableView=SORTING(No.)
ORDER(Ascending);
OnAfterGetRecord=BEGIN
//Employee.GET(Empid);
//EmployeeName := Employee.“First Name” + Space + Employee.“Middle Name” + Space + Employee.“Last Name”;
END;

ReqFilterFields=No.;
DataItemLink=Employer No.=FIELD(No.);
}
SECTIONS
{
}
}
{ PROPERTIES
{
DataItemIndent=2;
DataItemTable=Table5207;
DataItemTableView=SORTING(Employee No.,From Date)
ORDER(Ascending);
PrintOnlyIfDetail=No;
OnAfterGetRecord=BEGIN

CompanyInfo.GET;
CompanyInfo.CALCFIELDS(Picture);

// Initialize variables
FromDate := 010190D;
ToDate := 311205D;
Amount := 0; TotalAmount := 0; CurrAccTotal := 0;
ContMonth := ‘’;
MonthContAmount := 0;
// Variable initialization ends above.

// Setting Range and Filters.
{ Contributions.SETCURRENTKEY(“Employee No.”,“From Date”);
Contributions.SETRANGE(“Employee No.”,Employee.“No.”);
Contributions.SETRANGE(“From Date”,FromDate,ToDate);
Contributions.SETFILTER(“From Date”,’>=%1’,FromDate);
Contributions.SETFILTER(“To Date”,’<=%1’,ToDate); }
// Range and filter settings end.

// Getting RetireDate
IF EVALUATE(NewBirthDate, Employee.“Birth Date”) THEN BEGIN
RetireDate1 := CALCDATE(’<+60Y>’,NewBirthDate);
RetireDate := FORMAT(RetireDate1,0,’//’);
END ELSE
RetireDate := ‘’;
// RetireDate Ends above.

// Getting Bal. Br/FWD from Balances table.
IF Balances.GET(“Employee No.”) =TRUE
THEN BEGIN
BalBrFwd := Balances.BalBrFwd;
END ELSE
BalBrFwd := 0.00;
// Getting Bal. Br/FWD ends above.













// Getting User’s Full Name begins.
User.GET(USERID);
UserName := User.Name;
// Getting User’s Full Name ends.


// Code to get Rate from Benefits
BenefitsKey.SETCURRENTKEY(“Period Start”);
BenefitsKey.SETRANGE(“Period Start”,FromDate,ToDate);
BenefitsKey.SETFILTER(“Period Start”,’<=%1’,FromDate);
BenefitsKey.SETFILTER(“Period End”,’>=%1’,ToDate);
// Code Ends above.


IF BenefitsKey.FIND(’-’) THEN
Rate := BenefitsKey.Rate;


//Code to Count Months
IF (FromDate <> 0D) AND (ToDate > FromDate) THEN BEGIN
Calendar.RESET;
Calendar.SETRANGE(“Period Type”,Calendar.“Period Type”::Month);
Calendar.SETRANGE(“Period Start”,FromDate,ToDate);
Months := Calendar.COUNT;
END ELSE
Months := 0;
// Code Ends above.

//First Code brought down here
Cont.SETCURRENTKEY(“Employee No.”,“From Date”);
Cont.SETRANGE(“Employee No.”,Employee.“No.”);
Cont.SETRANGE(“From Date”,FromDate,ToDate);
Cont.SETFILTER(“From Date”,’>=%1’,FromDate);
Cont.SETFILTER(“To Date”,’<=%1’,ToDate);

IF Cont.FIND(’-’) THEN BEGIN
TotalAmount := Cont.Quantity;
IF Cont.NEXT <> 0 THEN
REPEAT
TotalAmount := TotalAmount + Cont.Quantity;
UNTIL Cont.NEXT = 0;
END;

Cont.SETRANGE(“Employee No.”,Empid);

IF Cont.FIND(’-’) THEN BEGIN
TBalBrFwd := Balances.BalBrFwd + Cont.Quantity;
IF Cont.NEXT <> 0 THEN
REPEAT
TBalBrFwd := TBalBrFwd + Cont.Quantity;
UNTIL Cont.NEXT = 0;
END;



Amount := (TotalAmount * Rate * Months)/24;
CurrAccTotal := Amount + TotalAmount;

BalInt := BalBrFwd * Rate * Months/12;
GrandTotal := BalBrFwd + CurrAccTotal + BalInt;


//Formatting Months Below
ContMonth := FORMAT(Contributions.“To Date”,0,’, ‘);
CurrContYear := FORMAT(Contributions.“To Date”,0,’’);
MonthContAmount := Contributions.Quantity;
EndDate := FORMAT(ToDate,0,’ , ‘);
BeginDate := FORMAT(FromDate,0,’ , ‘);
// Formatting Ends above line.

//Employee Contribution
ContMonth := FORMAT(Contributions.“To Date”,0,’, ‘);
MonthContAmountEmployee := Contributions.Quantity/3;
EndDate := FORMAT(ToDate,0,’ , ‘);
BeginDate := FORMAT(FromDate,0,’ , ‘);

//Employer Contribution
ContMonth := FORMAT(Contributions.“To Date”,0,’, ‘);
MonthContAmountEmployer := Contributions.Quantity*2/3;
EndDate := FORMAT(ToDate,0,’ , ‘);
BeginDate := FORMAT(FromDate,0,’ , ‘);


IF (ContMonth = ‘’ ) OR (MonthContAmount = 0.00)
OR (CurrContYear <> FORMAT(ToDate,0,’’))
THEN CurrReport.SKIP;

RateDisplay := Rate * 100;
END;

DataItemLinkReference=Employee;
DataItemLink=Employee No.=FIELD(No.);
}
SECTIONS
{
{ PROPERTIES
{
SectionType=Header;
SectionWidth=21150;
SectionHeight=10575;
}
CONTROLS
{
{ 1000000000;TextBox;0 ;0 ;2250 ;1692 ;FontSize=8;
FontBold=Yes;
SourceExpr=TODAY }
{ 1000000001;Label ;3900 ;3807 ;8250 ;423 ;HorzAlign=Center;
VertAlign=Center;
FontSize=8;
FontBold=Yes;
MultiLine=Yes;
CaptionML=ENU=SOCIAL SECURITY AND HOUSING FINANCE CORPORATION }
{ 1000000002;Label ;4500 ;4230 ;5850 ;423 ;HorzAlign=Center;
VertAlign=Center;
FontSize=8;
FontBold=Yes;
MultiLine=Yes;
CaptionML=ENU=NATIONAL PROVIDENT FUND SCHEME }
{ 1000000003;Label ;3900 ;4653 ;6450 ;423 ;FontSize=8;
FontBold=Yes;
CaptionML=ENU="EMPLOYEE STATEMENT OF ACCOUNT AS AT " }
{ 1000000004;TextBox;10350;4653 ;4650 ;423 ;FontSize=8;
FontBold=Yes;
SourceExpr=EndDate }
{ 1000000005;PictureBox;3900;0 ;8550 ;3384 ;Border=Yes;
SourceExpr=CompanyInfo.Picture }
{ 1000000006;Label ;0 ;6345 ;4200 ;423 ;FontSize=8;
FontBold=Yes;
CaptionML=ENU=SOCIAL SECURITY NUMBER: }
{ 1000000007;Label ;0 ;6768 ;2550 ;423 ;FontSize=8;
&nb