local procedure CalculateMonthstoFYEnd1(): Integer
var
frommonth: Date;
tomonth: Date;
Diff: Integer;
FYSTART1: Date;
FYEND1: Date;
StartDate: Date;
EndDate: Date;
begin
FYSTART1 := CalculateFYStart1();
FYEND1 := CalculateFYEND1();
if Rec."Expected Starting Date" = 0D then
StartDate := DMY2DATE(01, 01, 1973)
else
StartDate := rec."Expected Starting Date";
if Rec."Expected End Date" = 0D then
EndDate := DMY2DATE(01, 01, 1973)
else
EndDate := rec."Expected End Date";
//Rule#1
If (StartDate <= FYSTART1) and (EndDate >= FYSTART1) and (EndDate <= FYEND1) then begin
fromMonth := FYSTART1;
toMonth := EndDate;
Diff := 1 + DATE2DMY(toMonth, 2) - DATE2DMY(fromMonth, 2) + 12 * (DATE2DMY(toMonth, 3) - DATE2DMY(fromMonth, 3));
end;
//Rule#2
If (StartDate <= FYSTART1) and (EndDate >= FYEND1) then begin
fromMonth := FYSTART1;
toMonth := FYEND1;
Diff := 1 + DATE2DMY(toMonth, 2) - DATE2DMY(fromMonth, 2) + 12 * (DATE2DMY(toMonth, 3) - DATE2DMY(fromMonth, 3));
end;
//Rule#3
If (StartDate >= FYSTART1) and (StartDate <= FYEND1) and (EndDate <= FYSTART1) and (EndDate <= FYEND1) then begin
fromMonth := StartDate;
toMonth := EndDate;
Diff := 1 + DATE2DMY(toMonth, 2) - DATE2DMY(fromMonth, 2) + 12 * (DATE2DMY(toMonth, 3) - DATE2DMY(fromMonth, 3));
end;
//Rule#4
If (StartDate >= FYSTART1) and (EndDate >= FYEND1) then begin
fromMonth := StartDate;
toMonth := FYEND1;
Diff := 1 + DATE2DMY(toMonth, 2) - DATE2DMY(fromMonth, 2) + 12 * (DATE2DMY(toMonth, 3) - DATE2DMY(fromMonth, 3));
end;
//Rule#5
If (StartDate >= FYSTART1) and (StartDate >= FYEND1) then
Diff := 0;
exit(Diff);
end;