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.....
0
Comments
Ithink you have your Begin and End in the wrong places.
Hope this helps
Albert
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.
Maybe You want something like this:
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".
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?
(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.
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 read
Even if they are the same, this code should run once for evry month in NoMonth..NoEndMonth.
Example:
StartDate 10\25\2006
EndDate 1\20\2008
The project is running for few months, but this code is:
IF NoEndMonth < NoMonth THEN
NoEndMonth += 12;
, 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):