How to Check date (advanced)

bRahmsbRahms Member Posts: 44
Hello,

i'm back with a more complicated issue. I'm making a planning in Navision which plans Tasks for Employees. But one employee can work on just one Task at the time

Example:
We've got two Employees (EMP0001 & EMP0002) and two maintasks:
TA0001: StartDate: 19/05/07 EndDate: 19/06/07
TA0008: StartDate: 22/05/07 EndDate: 01/08/07

A Employee wants to work on TA0001, so he adds himself to the task and he gives in the period (within the taskperiod, but that works already fine):
EMP0001 TA0001 StartDate: 19/05/07 EndDate: 25/05/07.

Now the issue is, when EMP001 wants to work on another task, it has to filter the table (EmployeePerTask) as so that the Startdate or Enddate can't be between 19/05/07 & 25/05/07. For example:
EMP0001 TA0008 StartDate: 24/07/07 EndDate: 31/07/07 will work
EMP0001 TA0008 StartDate: 22/05/07 EndDate: 30/05/07 MAY NOT work because 22,23,24 & 25/05 is already planned for another task.

How can I fix this? Any help would be appreciated!
I've got this so far:
IF StartDateSub > EndDateSub THEN BEGIN
    EndDateSub := StartDateSub +1;
    MESSAGE('StartDate cant be later as EndDate \EndDate is set to %1', EndDateSub);
END;

Task.SETRANGE(ID, TaskID);
IF Task.FINDFIRST THEN BEGIN
 IF Task.EndDate < EndDateSub THEN
  MESSAGE('EndDate of this Task (%2) cant be later as the general Enddate (%1)',FORMAT(Task.EndDate), FORMAT(EndDateSub));
END;

SubTask.SETRANGE(EmployeeID);
IF SubTask.FINDSET THEN BEGIN
 REPEAT
  IF (SubTask.StartDateSub >= StartDateSub) AND (SubTask.EndDateSub <= EndDateSub) THEN BEGIN
  REPEAT
   IF (EndDateSub = SubTask.EndDateSub) OR (EndDateSub = SubTask.StartDateSub) OR (StartDateSub = SubTask.EndDateSub) 
   OR (StartDateSub = SubTask.StartDateSub) THEN BEGIN
     CheckEndDate := EndDateSub;
     FOR idx := EndDateSub - StartDateSub DOWNTO 0 DO BEGIN
      ERROR('This task overrules another task and cant be planned');
      // ???
     END;
   END;
  UNTIL SubTask.NEXT = 0;
  END;
 UNTIL SubTask.NEXT = 0;
END;

Answers

  • matttraxmatttrax Member Posts: 2,309
    I've actually done somthing a lot like this before.

    Example:

    Tasks
    T1 01/01/07 01/31/07
    T2 02/01/07 02/28/07
    T3 03/01/07 03/31/01

    New task: T4 03/15/07 04/15/07

    TempDate := NewTask."Start Date";
    WHILE TempDate <> NewTask."End Date" DO BEGIN
    CLEAR(Tasks);
    Tasks.SETFILTER("Start Date", '<=%1', TempDate);
    Tasks.SETFILTER("End Date", '>=%1', TempDate);
    IF Tasks.FIND('-') THEN
    ERROR
    ELSE
    TempDate := CALCDATE(TempDate, '+1D');
    END;

    Or something close to it, probably not exactly, I can't remember the exact code.
  • bRahmsbRahms Member Posts: 44
    matttrax wrote:
    I've actually done somthing a lot like this before.

    Example:

    Tasks
    T1 01/01/07 01/31/07
    T2 02/01/07 02/28/07
    T3 03/01/07 03/31/01

    New task: T4 03/15/07 04/15/07

    TempDate := NewTask."Start Date";
    WHILE TempDate <> NewTask."End Date" DO BEGIN
    CLEAR(Tasks);
    Tasks.SETFILTER("Start Date", '<=%1', TempDate);
    Tasks.SETFILTER("End Date", '>=%1', TempDate);
    IF Tasks.FIND('-') THEN
    ERROR
    ELSE
    TempDate := CALCDATE(TempDate, '+1D');
    END;

    Or something close to it, probably not exactly, I can't remember the exact code.

    Thank you very much for this clear answer. It was almost perfect, but there was that one thing i still needed to filter on Empoyee + you switched the calcdate parameters :D. This is the working code:

    SubTask.SETRANGE(EmployeeID);
    IF SubTask.FINDSET THEN BEGIN
     REPEAT
      TempDate := StartDateSub;
      WHILE TempDate <> EndDateSub DO BEGIN
      CLEAR(SubTask);
      SubTask.SETFILTER(StartDateSub, '<=%1', TempDate);
      SubTask.SETFILTER(EndDateSub, '>=%1', TempDate);
      IF SubTask.FINDFIRST THEN
       ERROR('This task overrules another task and cant be planned')
      ELSE
       TempDate := CALCDATE('+1D', TempDate);
      END;
     UNTIL SubTask.NEXT = 0;
    END;
    
  • bRahmsbRahms Member Posts: 44
    Except that I have to repeat the range inside the filter

    SubTask.SETFILTER(StartDateSub, '<=%1', TempDate);
    SubTask.SETFILTER(EndDateSub, '>=%1', TempDate);
    SubTask.SETFILTER(EmployeeID,EmployeeID);

    Is this because a filter overrules a range?
Sign In or Register to comment.