Report skipping records it should not be skipping

asemberengasembereng Member Posts: 220
can someone help me out please??? I have developed a kind of a complex report which calculates benefit computation but I Skips some records for specific employees. Below is the code i have. Please advise me on where i am doing wrong.


RESET;

I := 0;


StartCurrYear := DMY2DATE(1,1,year);
ApprovalDate := DMY2DATE(31,12,year);

SETRANGE("Period Start",StartCurrYear,ApprovalDate);


endYearDateDayMonth := FORMAT(ApprovalDate,0,'<Day> <Month Text>');

totalBenefits := -1;
BenefitIndex := 0;


User.GET(USERID);
UserName := User.Name;


IF (BalBrFwd = 0.00) THEN
BEGIN

Cont.RESET;
Cont.SETCURRENTKEY("Employee No.","From Date");
Cont.SETFILTER ("Fund Type",'<>IICF');
Cont.SETRANGE("Employee No.", Empid);
Cont.SETRANGE("From Date",StartCurrYear,ApprovalDate);


IF Cont.FIND('-') THEN
BEGIN
FirstYearContPeriodDate := Cont."From Date";

FirstYearContNotBeginJanuary := FALSE;
FirstYearContPeriodNumber := 0;


BenefitsTable.SETCURRENTKEY("Period Start");
BenefitsTable.SETFILTER("Period Start",'<=%1',FirstYearContPeriodDate);
BenefitsTable.FIND('+');


IF (BalBrFwd = 0.00) AND (DATE2DMY(BenefitsTable."Period Start",2) <> DATE2DMY(FirstYearContPeriodDate,2) ) THEN
BEGIN
//MESSAGE('TRUE');
FirstYearContNotBeginJanuary := TRUE;
FirstYearContPeriodNumber := 1;
END;
END;
END;




BalBrFwd := ClBal;
ContForYear := 0;
CountCont := 0;

I+=1;

CountCont += 1;
//message('%1',countCont);
FOR J := 1 TO 50 DO
BEGIN
BenefitPayDateArr[J] := 0D;
BenefitPayAmountArr[J] := 0.0;
PercentPayedArr[J] := 0.0;
END;

Rat := Rate;
displayRate := Rat * 100;

benefitPay.RESET;
benefitPay.SETCURRENTKEY("Employee No.","Payment Date");
benefitPay.SETRANGE("Employee No.", Empid);
benefitPay.SETRANGE("Payment Date","Period Start","Period End");



J := 1;
IF benefitPay.FIND('-') THEN
REPEAT

BenefitPayDateArr[J] := benefitPay."Payment Date";
BenefitPayAmountArr[J] := benefitPay.Amounts;
PercentPayedArr[J] := benefitPay."Percentage Paid";
J := J + 1;

UNTIL benefitPay.NEXT <= 0;




IF (benefitPay.COUNT > 0) THEN
BEGIN




IF ( BenefitIndex = 0 ) THEN
BEGIN

IF FirstYearContNotBeginJanuary AND (FirstYearContPeriodNumber = 1) AND
(("Period Start" < FirstYearContPeriodDate) AND ("Period End" > FirstYearContPeriodDate)) THEN
BEGIN
//MESSAGE( 'x%1' , DATE2DMY(FirstYearContPeriodDate,2));
StartPeriodDate := "Period Start";
EndPeriodDate := FirstYearContPeriodDate - 1;
// EndPeriodDate := "Period End";
FirstYearContPeriodNumber := 2;
BenefitsRate.NEXT(-1);
END
ELSE IF FirstYearContNotBeginJanuary AND (FirstYearContPeriodNumber = 2) AND
(("Period Start" < FirstYearContPeriodDate) AND ("Period End" > FirstYearContPeriodDate)) THEN
BEGIN
//MESSAGE( 'y%1' , DATE2DMY(FirstYearContPeriodDate,2));
StartPeriodDate := FirstYearContPeriodDate;
EndPeriodDate := BenefitPayDateArr[1] - 1;
//EndPeriodDate := "Period End";
FirstYearContNotBeginJanuary := FALSE;
FirstYearContPeriodNumber := 3;
// TODO handle the case where the benefit payment is the same as the first contribution
// this may possibly occur when refunding

BenefitsRate.NEXT(-1);
END
ELSE
BEGIN



//MESSAGE( 'z' );

// initialize benefit index
BenefitIndex := 1;

// benefitPay.FIND('-');
// calculate the intitial period prior to the payment date
// TODO::::::handle case where end period is the samne as the end payment period::::TODO

IF FirstYearContPeriodNumber = 3 THEN
BEGIN
StartPeriodDate := BenefitPayDateArr[BenefitIndex];
EndPeriodDate := BenefitPayDateArr[BenefitIndex];
FirstYearContPeriodNumber := 4;
END
ELSE
BEGIN
StartPeriodDate := "Period Start";
EndPeriodDate := BenefitPayDateArr[BenefitIndex];
//EndPeriodDate := "Period End";
END;

// if the start and end periods are the same then we have a complex case
// We subtract the benefit smount and use the endperiod of either the next
// payment period of the end period of the benefit rate if the former does not exist



IF ( StartPeriodDate = EndPeriodDate ) THEN
BEGIN

benefitAmount := BenefitPayAmountArr[BenefitIndex];
PercentPayed := PercentPayedArr[BenefitIndex];

IF ( benefitPay.COUNT > BenefitIndex) THEN
BEGIN

// MESSAGE('b- BI = %1'+'BDAte %2 ' + 'B-Count %3', BenefitIndex, BenefitPayDateArr[BenefitIndex], benefitPay.COUNT);

IF (PaidInFull = 0) AND (PercentPayedArr[BenefitIndex] = 100) THEN
BEGIN
PaidInFull := 1;
END;


// There is no period calculated without a subtracted payment so we move to next benefit next time
//BenefitIndex += 1;
EndPeriodDate := BenefitPayDateArr[BenefitIndex + 1] ;
benefitPay.NEXT(-1);

END
ELSE
BEGIN
// MESSAGE('a- BI = %1'+'BA %2 ' + 'B-Count %3', BenefitIndex, BenefitPayDateArr[BenefitIndex], BenefitPayAmountArr[BenefitIndex]);
benefitAmount := BenefitPayAmountArr[BenefitIndex];
PercentPayed := PercentPayedArr[BenefitIndex];

IF (PaidInFull = 0) AND (PercentPayedArr[BenefitIndex] = 100) THEN
BEGIN
PaidInFull := 2;
END;


EndPeriodDate := "Period End";
BenefitIndex := 0;
END;

END
ELSE
BEGIN
// EndPeriodDate := BenefitPayDateArr[BenefitIndex] ;
EndPeriodDate := "Period End";
// handle initial payment there is only one period

IF (PaidInFull = 0) AND (PercentPayedArr[BenefitIndex] = 100) THEN
BEGIN
PaidInFull := 1;
END;

// ===============================================================================
// benefitAmount := 0;
benefitPay.CALCSUMS(Amounts);
benefitAmount := benefitPay.Amounts;
BenefitsRate.NEXT(-1);
BenefitIndex := 1;

END;

END;

Cont.RESET;
Cont.SETCURRENTKEY("Employee No.","From Date");
Cont.SETFILTER ("Fund Type",'<>IICF');
Cont.SETRANGE("Employee No.", Empid);
Cont.SETRANGE("From Date",StartPeriodDate, EndPeriodDate);
Cont.CALCSUMS(Quantity);
ContForYear := Cont.Quantity;
CountCont += 1;
TotCont := BalBrFwd + ContForYear;



END
ELSE IF (BenefitIndex >= 1 ) THEN
BEGIN

//MESSAGE( 'z1' );
// TODO::::::handle case where end period is the samne as the end payment period::::TODO

//MESSAGE('a- BI = %1'+'BA %2 ' + 'B-Count %3', BenefitIndex, BenefitPayDateArr[BenefitIndex],BenefitPayAmountArr[BenefitIndex]);

IF (BenefitPayDateArr[BenefitIndex] + 1) > "Period End" THEN
StartPeriodDate := BenefitPayDateArr[BenefitIndex]
ELSE
StartPeriodDate := BenefitPayDateArr[BenefitIndex] + 1;

benefitAmount := BenefitPayAmountArr[BenefitIndex];
PercentPayed := PercentPayedArr[BenefitIndex];

// MESSAGE('AAA BI = %1' + 'B Amount = %2' , BenefitIndex, benefitPay.Amounts );

IF ( benefitPay.COUNT > BenefitIndex ) THEN
BEGIN
BenefitIndex += 1;
EndPeriodDate := BenefitPayDateArr[BenefitIndex] ;
BenefitsRate.NEXT(-1);
//MESSAGE('a-rate = %1'+'rat %2 ' + 'B-Count %3', Rate, Rat ,BenefitPayAmountArr[BenefitIndex]);

END
ELSE
BEGIN
//MESSAGE('b-rate = %1'+'rat %2 ' + 'B-Count %3', Rate, Rat ,BenefitPayAmountArr[BenefitIndex]);

IF (PaidInFull = 0) AND (PercentPayedArr[BenefitIndex] = 100) THEN
BEGIN
IF StartPeriodDate = "Period Start" THEN
PaidInFull := 2
ELSE
PaidInFull := 1;
END;

EndPeriodDate := "Period End" ;
BenefitIndex := 0;
END;

IF benefitPay.FIND('-') THEN BEGIN
benefitAmount := benefitPay.Amounts;
END;

Cont.RESET;
Cont.SETCURRENTKEY("Employee No.","From Date");
Cont.SETFILTER ("Fund Type",'<>IICF');
Cont.SETRANGE("Employee No.", Empid);
Cont.SETRANGE("From Date",StartPeriodDate, EndPeriodDate);
Cont.CALCSUMS(Quantity);
ContForYear := Cont.Quantity;
CountCont += 1;
TotCont := BalBrFwd + ContForYear;
END;


END
ELSE
BEGIN

// Do the calculation without benefit subttractions as none exist
// CALCSUM quantity for the period of similar interest in the benefits table

IF FirstYearContNotBeginJanuary AND (FirstYearContPeriodNumber = 1) AND
(("Period Start" < FirstYearContPeriodDate) AND ("Period End" > FirstYearContPeriodDate)) THEN
BEGIN
// MESSAGE( 'a%1' , DATE2DMY(FirstYearContPeriodDate,2));
StartPeriodDate := "Period Start";
EndPeriodDate := "Period End";
FirstYearContPeriodNumber := 2;
BenefitsRate.NEXT(-1);
END
ELSE IF FirstYearContNotBeginJanuary AND (FirstYearContPeriodNumber = 2) AND
(("Period Start" < FirstYearContPeriodDate) AND ("Period End" > FirstYearContPeriodDate)) THEN
BEGIN
// MESSAGE( 'b%1' , DATE2DMY(FirstYearContPeriodDate,2));
StartPeriodDate := FirstYearContPeriodDate;
EndPeriodDate := "Period End";
FirstYearContNotBeginJanuary := FALSE;
END
ELSE
BEGIN
// MESSAGE( 'c%1' , DATE2DMY(FirstYearContPeriodDate,2));
StartPeriodDate := "Period Start";
EndPeriodDate := "Period End";
END;


Cont.RESET;
Cont.SETCURRENTKEY("Employee No.","From Date");
Cont.SETFILTER ("Fund Type",'<>IICF');
Cont.SETRANGE("Employee No.", Empid);
Cont.SETRANGE("From Date",StartPeriodDate,EndPeriodDate);
Cont.CALCSUMS(Quantity);
ContForYear := Cont.Quantity;
CountCont += 1;
PercentPayed := 0;
benefitAmount := 0;
TotCont := BalBrFwd + ContForYear;

END;

IF (EndPeriodDate > ApprovalDate ) THEN
BEGIN
EndPeriodDate := ApprovalDate;

END;


StartPeriodMonth := DATE2DMY(StartPeriodDate, 2);
EndPeriodMonth := DATE2DMY(EndPeriodDate, 2);

StartPeriodYear := DATE2DMY(StartPeriodDate, 3);
EndPeriodYear := DATE2DMY(EndPeriodDate, 3);


//MESSAGE('B - Start:%1 -- end:%2 ',
// FORMAT(StartPeriodDate,0,'<Day>/<Month>/<Year4>'),
// FORMAT(EndPeriodDate,0,'<Day>/<Month>/<Year4>'));


//MESSAGE('S %1 ' + ' E %2', StartPeriodMonth, EndPeriodMonth);

//PeriodDateText := FORMAT(StartPeriodDate,0,'<Day>/<Month>/<Year2>');


IF (StartPeriodDate = EndPeriodDate) THEN
BEGIN
NofMonths := 0;

END
ELSE IF (EndPeriodYear = StartPeriodYear) THEN
BEGIN
NofMonths := (EndPeriodMonth - StartPeriodMonth + 1 )
END
ELSE
BEGIN
NofMonths := (EndPeriodMonth - StartPeriodMonth + 1 );
NofMonths := NofMonths + ((EndPeriodYear - StartPeriodYear ) * 12);
// MESSAGE('D%1', NofMonths);
END;

// changed from from + 1 ) MOD 12 to MOD 12) + 1

NofMonths := NofMonths - 2;
NofMonths += (DATE2DMY(DMY2DATE(1, (StartPeriodMonth MOD 12) + 1, StartPeriodYear)-1,1) - DATE2DMY(StartPeriodDate, 1) + 1)/
DATE2DMY(DMY2DATE(1, (StartPeriodMonth MOD 12) + 1, StartPeriodYear)-1,1);

NofMonths += DATE2DMY(EndPeriodDate, 1)/ DATE2DMY(DMY2DATE(1, (EndPeriodMonth MOD 12) + 1, EndPeriodYear)-1,1);

IF (StartPeriodDate = EndPeriodDate) THEN
NofMonths := 0;

NofMonths := (EndPeriodDate - StartPeriodDate) div 30;

MonthCorrectedIntRate := Rat * NofMonths/12.00000000000000 ;
message('%1', NofMonths);

// Calculate interests and total balances

CurrYearEmployerTotal := ContForYear * 2/3;
CurrYearEmployeeTotal := ContForYear/3;

message ('%1',CountCont);

IF (PaidInFull <= 1) THEN
BEGIN

CurrYearInt := ((ContForYear - benefitAmount) * MonthCorrectedIntRate)/2;
InterestLessCont := BalBrFwd * MonthCorrectedIntRate;
IntTotCont := ((ContForYear - benefitAmount) * MonthCorrectedIntRate)/2 + BalBrFwd * MonthCorrectedIntRate;
ClBal := BalBrFwd + ContForYear + IntTotCont - benefitAmount;

//MESSAGE('PaidInFull %1 ', PaidInFull);

IF (PaidInFull = 1) THEN
BEGIN
PaidInFull := 2;
END;
END
ELSE
BEGIN
// It is possible to pay in full and continue to post contributions in rare cases
// No interest is paid in this case
CurrYearInt := 0;
IntTotCont := 0;
InterestLessCont := 0;
//MESSAGE('ContForYear %1 ' + ' benefitAmount %2 ', ContForYear, benefitAmount);
ClBal := BalBrFwd + ContForYear - benefitAmount;
END;

TotalBenefitPayable := TotalBenefitPayablePercent/100 * ClBal;

Comments

Sign In or Register to comment.