Looping Issue

vipinkuruvilla
Member Posts: 143
Hai All,
Iam creating a payroll system for my company using Navision 4.0
For calculating Bonus Iam using 2 For Loops , for getting the start month and start year.
But the looping is not properly working. I have written my code in OnPush of a button
The following is my code :
StructureDetails.SETRANGE(StructureDetails.Code,Code);
IF StructureDetails.FIND('-') THEN
REPEAT
IF StructureDetails."Tax/Charge Code" ='BONUS' THEN
BEGIN
getMonth:=0;
recBonus.FIND('-');
recBonus.RESET;
RecEmployee.SETRANGE(RecEmployee."No.","Employee No");
IF RecEmployee.FIND('-') THEN
DateOfJoining:=RecEmployee."Data of Joining";
MonthDOJ := DATE2DMY(DateOfJoining, 2);
DOJYear := DATE2DMY(DateOfJoining, 3);
IF recBonus.FIND('-') THEN
strMonth:= recBonus."Start Date";
NoMonth:= DATE2DMY(strMonth, 2);
noYear:= DATE2DMY(strMonth, 3);
strEndMonth:= recBonus."End Date";
NoEndMonth:= DATE2DMY(strEndMonth, 2);
NoEndYear:= DATE2DMY(strEndMonth, 3);
IF (MonthDOJ <= NoMonth) OR (DOJYear <= noYear) THEN
recBonus.SETRANGE(recBonus.Active,TRUE);
IF recBonus.FIND('-') THEN
recBonuspayhead.SETRANGE(recBonuspayhead."Bonus Code",recBonus."Bonus Code");
IF recBonuspayhead.FIND('-') THEN
REPEAT
StrOrderLineDetails.SETRANGE(StrOrderLineDetails."Structure Code",Code);
StrOrderLineDetails.SETRANGE("Tax/Charge Code",recBonuspayhead.PayHead);
IF StrOrderLineDetails.FIND('-') THEN BEGIN
REPEAT
FOR j:= NoMonth TO NoEndMonth DO BEGIN
FOR y:= noYear TO NoEndYear DO BEGIN
BonusAmount:=BonusAmount+StrOrderLineDetails."Actual Amount";
END;
UNTIL StrOrderLineDetails.NEXT=0;
END;
UNTIL recBonuspayhead.NEXT=0;
END;
UNTIL StructureDetails.NEXT=0;
Actualamount:= (BonusAmount*8.33)/100;
IF (Actualamount > 3500) THEN
BEGIN
BonusResult:= 3500 * (StrOrderLineDetails."Actual Amount"/StrOrderLineDetails."Actual Calculation Value");
END ELSE BEGIN
BonusResult:= 3500;
END;
MESSAGE('%1',BonusResult);
Can anyone go through my above code and let me know my mistake??
Any help is appreciated.....
Iam creating a payroll system for my company using Navision 4.0
For calculating Bonus Iam using 2 For Loops , for getting the start month and start year.
But the looping is not properly working. I have written my code in OnPush of a button
The following is my code :
StructureDetails.SETRANGE(StructureDetails.Code,Code);
IF StructureDetails.FIND('-') THEN
REPEAT
IF StructureDetails."Tax/Charge Code" ='BONUS' THEN
BEGIN
getMonth:=0;
recBonus.FIND('-');
recBonus.RESET;
RecEmployee.SETRANGE(RecEmployee."No.","Employee No");
IF RecEmployee.FIND('-') THEN
DateOfJoining:=RecEmployee."Data of Joining";
MonthDOJ := DATE2DMY(DateOfJoining, 2);
DOJYear := DATE2DMY(DateOfJoining, 3);
IF recBonus.FIND('-') THEN
strMonth:= recBonus."Start Date";
NoMonth:= DATE2DMY(strMonth, 2);
noYear:= DATE2DMY(strMonth, 3);
strEndMonth:= recBonus."End Date";
NoEndMonth:= DATE2DMY(strEndMonth, 2);
NoEndYear:= DATE2DMY(strEndMonth, 3);
IF (MonthDOJ <= NoMonth) OR (DOJYear <= noYear) THEN
recBonus.SETRANGE(recBonus.Active,TRUE);
IF recBonus.FIND('-') THEN
recBonuspayhead.SETRANGE(recBonuspayhead."Bonus Code",recBonus."Bonus Code");
IF recBonuspayhead.FIND('-') THEN
REPEAT
StrOrderLineDetails.SETRANGE(StrOrderLineDetails."Structure Code",Code);
StrOrderLineDetails.SETRANGE("Tax/Charge Code",recBonuspayhead.PayHead);
IF StrOrderLineDetails.FIND('-') THEN BEGIN
REPEAT
FOR j:= NoMonth TO NoEndMonth DO BEGIN
FOR y:= noYear TO NoEndYear DO BEGIN
BonusAmount:=BonusAmount+StrOrderLineDetails."Actual Amount";
END;
UNTIL StrOrderLineDetails.NEXT=0;
END;
UNTIL recBonuspayhead.NEXT=0;
END;
UNTIL StructureDetails.NEXT=0;
Actualamount:= (BonusAmount*8.33)/100;
IF (Actualamount > 3500) THEN
BEGIN
BonusResult:= 3500 * (StrOrderLineDetails."Actual Amount"/StrOrderLineDetails."Actual Calculation Value");
END ELSE BEGIN
BonusResult:= 3500;
END;
MESSAGE('%1',BonusResult);
Can anyone go through my above code and let me know my mistake??
Any help is appreciated.....
0
Comments
-
Hi
Ithink you have your Begin and End in the wrong places.StructureDetails.SETRANGE(StructureDetails.Code,Code); IF StructureDetails.FIND('-') THEN REPEAT IF StructureDetails."Tax/Charge Code" ='BONUS' THEN BEGIN getMonth:=0; recBonus.FIND('-'); recBonus.RESET; RecEmployee.SETRANGE(RecEmployee."No.","Employee No"); IF RecEmployee.FIND('-') THEN DateOfJoining:=RecEmployee."Data of Joining"; MonthDOJ := DATE2DMY(DateOfJoining, 2); DOJYear := DATE2DMY(DateOfJoining, 3); IF recBonus.FIND('-') THEN strMonth:= recBonus."Start Date"; NoMonth:= DATE2DMY(strMonth, 2); noYear:= DATE2DMY(strMonth, 3); strEndMonth:= recBonus."End Date"; NoEndMonth:= DATE2DMY(strEndMonth, 2); NoEndYear:= DATE2DMY(strEndMonth, 3); IF (MonthDOJ <= NoMonth) OR (DOJYear <= noYear) THEN recBonus.SETRANGE(recBonus.Active,TRUE); IF recBonus.FIND('-') THEN recBonuspayhead.SETRANGE(recBonuspayhead."Bonus Code",recBonus."Bonus Code"); IF recBonuspayhead.FIND('-') THEN REPEAT StrOrderLineDetails.SETRANGE(StrOrderLineDetails."Structure Code",Code); StrOrderLineDetails.SETRANGE("Tax/Charge Code",recBonuspayhead.PayHead); IF StrOrderLineDetails.FIND('-') THEN BEGIN REPEAT FOR j:= NoMonth TO NoEndMonth DO BEGIN FOR y:= noYear TO NoEndYear DO BEGIN BonusAmount:=BonusAmount+StrOrderLineDetails."Actual Amount"; END; END; UNTIL StrOrderLineDetails.NEXT=0; UNTIL recBonuspayhead.NEXT=0; END; Actualamount:= (BonusAmount*8.33)/100; IF (Actualamount > 3500) THEN BEGIN BonusResult:= 3500 * (StrOrderLineDetails."Actual Amount"/StrOrderLineDetails."Actual Calculation Value"); END ELSE BEGIN BonusResult:= 3500; END; UNTIL StructureDetails.NEXT=0; MESSAGE('%1',BonusResult);
Hope this helps
Albert0 -
You want to count Bonus for
2005 JAN, FEB, MAR
2006 JAN, FEB, MAR
2007 JAN, FEB, MAR
This code does it... 9 months only, even if project goes from 01.2005 to 03.2007.FOR j:= NoMonth TO NoEndMonth DO BEGIN FOR y:= noYear TO NoEndYear DO BEGIN BonusAmount:=BonusAmount+StrOrderLineDetails."Actual Amount"; END; END;
Maybe You want something like this:IF noYear = NoEndYear THEN BEGIN FOR j:= NoMonth TO NoEndMonth DO BonusAmount:=BonusAmount+StrOrderLineDetails."Actual Amount"; END ELSE BEGIN FOR y:= noYear TO NoEndYear DO BEGIN IF y=noYear THEN FOR j:= NoMonth TO 12 DO BonusAmount:=BonusAmount+StrOrderLineDetails."Actual Amount" ELSE IF y=NoEndYear THEN FOR j:= 1 TO NoEndMonth DO BonusAmount:=BonusAmount+StrOrderLineDetails."Actual Amount" ELSE FOR j:= 1 TO 12 DO BonusAmount:=BonusAmount+StrOrderLineDetails."Actual Amount"; END; END;
I made it on break at work, so there can be some mistakes... I just wanted to show You what in my opinion is "strange".0 -
FOR j:= NoMonth TO NoEndMonth DO BEGIN FOR y:= noYear TO NoEndYear DO BEGIN BonusAmount:=BonusAmount+StrOrderLineDetails."Actual Amount"; END; END;
Iam not getting any values in Y. Iam not sure why this is happening. Iam getting value in j but no value in y. Can anyone tell me why this is so?0 -
1. Set a trap befor that line
(FOR j:= NoMonth TO NoEndMonth DO BEGIN)
and tell me what values do You have in:
- NoMonth
- NoEndMonth
- noYear
- NoEndYear
2. What is the point of using strEndMonth? In this code I don't see a reason why it should be declare.0 -
Hi
It could also be that noyear and noendyear as the same value
Just a question
You are always finding the first bonus record regardless if it is for the right employee or not.
BTW my code should readIF recBonuspayhead.FIND('-') THEN REPEAT StrOrderLineDetails.SETRANGE(StrOrderLineDetails."Structure Code",Code); StrOrderLineDetails.SETRANGE("Tax/Charge Code",recBonuspayhead.PayHead); IF StrOrderLineDetails.FIND('-') THEN BEGIN REPEAT FOR j:= NoMonth TO NoEndMonth DO BEGIN FOR y:= noYear TO NoEndYear DO BEGIN BonusAmount:=BonusAmount+StrOrderLineDetails."Actual Amount"; END; END; UNTIL StrOrderLineDetails.NEXT=0; END; UNTIL recBonuspayhead.NEXT=0; Actualamount:= (BonusAmount*8.33)/100;
0 -
It could also be that noyear and noendyear as the same value
Even if they are the same, this code should run once for evry month in NoMonth..NoEndMonth.0 -
This Code is wrong:
FOR j:= NoMonth TO NoEndMonth DO BEGIN FOR y:= noYear TO NoEndYear DO BEGIN BonusAmount:=BonusAmount+StrOrderLineDetails."Actual Amount"; END; END;
Example:
StartDate 10\25\2006
EndDate 1\20\2008
The project is running for few months, but this code is:FOR j:=10 TO 1 DO BEGIN // Is not going to loop FOR y:=2006 TO 2008 DO BEGIN
0 -
In that case, before the For loop he would need this:
IF NoEndMonth < NoMonth THEN
NoEndMonth += 12;FOR j:=10 TO 1 DO BEGIN // Is not going to loop FOR y:=2006 TO 2008 DO BEGIN
0 -
yes knight
, but still he is loosing some months from "middle" year. I just don't belive tha he wants to do it. In my example it is 8 months from 2007 year.
PS: You code should be in my first example code
(Posted: Wed Jun 25, 2008 12:29 pm):IF noYear = NoEndYear THEN BEGIN IF NoEndMonth < NoMonth THEN NoEndMonth += 12; FOR j:= NoMonth TO NoEndMonth DO BonusAmount:=BonusAmount+StrOrderLineDetails."Actual Amount"; END
0 -
well talk about teamwork.. the combination of our code creates the solution? :P0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K 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
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions