A variable never gets to display
asembereng
Member Posts: 220
I am going through an ex-employee code to find out why the variable called BenefitAmount never gets to display on section. What the variable does is, if there a payment for the chosen year, it should display the amount. Below is the codes for the report. Can someone help me figure out what is going on? I have tried but i cant find a clue. thanks
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.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;
<BenefitsRate2> - OnAfterGetRecord()
BalBrFwd := ClBal;
I+=1;
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;
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;
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];
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] ;
// handle initial payment there is only one period
IF (PaidInFull = 0) AND (PercentPayedArr[BenefitIndex] = 100) THEN
BEGIN
PaidInFull := 1;
END;
benefitAmount := 0;
BenefitsRate.NEXT(-1);
BenefitIndex := 1;
END;
END;
Cont.RESET;
Cont.SETCURRENTKEY("Employee No.","From Date");
Cont.SETRANGE("Employee No.", Empid);
Cont.SETRANGE("From Date",StartPeriodDate, EndPeriodDate);
Cont.CALCSUMS(Quantity);
ContForYear := Cont.Quantity;
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;
Cont.RESET;
Cont.SETCURRENTKEY("Employee No.","From Date");
Cont.SETRANGE("Employee No.", Empid);
Cont.SETRANGE("From Date",StartPeriodDate, EndPeriodDate);
Cont.CALCSUMS(Quantity);
ContForYear := Cont.Quantity;
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 := FirstYearContPeriodDate - 1;
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.SETRANGE("Employee No.", Empid);
Cont.SETRANGE("From Date",StartPeriodDate,EndPeriodDate);
Cont.CALCSUMS(Quantity);
ContForYear := Cont.Quantity;
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;
MonthCorrectedIntRate := Rat * NofMonths/12.00000000000000 ;
// Calculate interests and total balances
CurrYearEmployerTotal := ContForYear * 2/3;
CurrYearEmployeeTotal := ContForYear/3;
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;
0
Comments
-
Hi !
First of all - I assume, that benefitAmount is not being displayed when it is zero. This is properly done by properties on the specific field on the sections.
Therefore let's concentrated on why it is zero (null).
It alls happens on the <BenefitsRate2> - OnAfterGetRecord() section.
Take a look here - I have removed all unnecessary code, which makes it easy to read:01: <BenefitsRate2> - OnAfterGetRecord() 02: 03: IF (benefitPay.COUNT > 0) THEN BEGIN 04: 05: IF ( BenefitIndex = 0 ) THEN BEGIN 06: 07: IF FirstYearContNotBeginJanuary AND (FirstYearContPeriodNumber = 1) AND 08: (("Period Start" < FirstYearContPeriodDate) AND ("Period End" > FirstYearContPeriodDate)) 09: THEN BEGIN 10: END ELSE IF FirstYearContNotBeginJanuary AND (FirstYearContPeriodNumber = 2) AND 11: (("Period Start" < FirstYearContPeriodDate) AND ("Period End" > FirstYearContPeriodDate)) 12: THEN BEGIN 13: END ELSE BEGIN 14: IF ( StartPeriodDate = EndPeriodDate ) THEN BEGIN 15: benefitAmount := BenefitPayAmountArr[BenefitIndex]; 16: IF ( benefitPay.COUNT > BenefitIndex) THEN BEGIN 17: END ELSE BEGIN 18: benefitAmount := BenefitPayAmountArr[BenefitIndex]; 19: END; 20: END ELSE BEGIN 21: benefitAmount := 0; 22: END; 23: END; 24: END ELSE IF (BenefitIndex >= 1 ) THEN BEGIN 25: benefitAmount := BenefitPayAmountArr[BenefitIndex]; 26: END; 27: END ELSE BEGIN 28: benefitAmount := 0; 29: END;
As you can see, benefitAmount is zero, when:
1) benefitPay.COUNT <= 0, due to first if statement (03)
2) (benefitPay.COUNT > 0) AND
(BenefitIndex = 0) AND
(NOT (FirstYearContNotBeginJanuary AND
((FirstYearContPeriodNumber = 1 ) OR (FirstYearContPeriodNumber = 2)) AND
(("Period Start" < FirstYearContPeriodDate) AND ("Period End" > FirstYearContPeriodDate)))) AND
(StartPeriodDate <> EndPeriodDate )
due to the following if statements (03), (05), (07), (10), (14)
3) the last possibility could also be that BenefitPayAmountArr[BenefitIndex] is zero.
So have you tried using the debugger? ;-)0
Categories
- All Categories
- 75 General
- 75 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 610 NAV Courses, Exams & Certification
- 1.9K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 250 Dynamics CRM
- 102 Dynamics GP
- 6 Dynamics SL
- 1.5K Other
- 991 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 28 Design Patterns (General & Best Practices)
- Architectural Patterns
- 9 Design Patterns
- 4 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1K General Chat
- 1.6K Website
- 77 Testing
- 1.2K Download section
- 23 How Tos section
- 249 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions