Subject: RE: Date/Time calculation
Hi Guys,
Thanks for the responses. I got some more information from client and the requirements has been changed now.
I want to make it generic so that i can be used for any combination. let me explain the process.
The Job is being created and it have 48 hrs ( 2 working days) lead time to be completed. The cut off time is 09:00. There are two days a week for Pick up ( Tuesday, Thursday : 09:00) and the item will be delivered next day (24 hrs).
All the Paramenter should be configurable. e.g leadTime, cut-off time, Pick-up days, Delivery Time.
For Example, Job created on Monday 10:00AM. It should be completed within 48 hrs ( leadtime) which means it should be ready by Wed 10:00AM. The next Pick-up day is Thursday 09:00PM and therefore it should be delivered on Friday.
Weekends should be excluded from the working days.
e.g Job created on Friday 10:00AM should be ready by Tuesday 10:00. Because the Pick-up on Tuesday is 09:00 so it will be missed and it will also be delivered next friday.
I’m trying with the following logic which is working fine for all days except Friday. The time part is being ignored at the moment to work out the basic logic but need to be included later.
Please comment on to this code and any response would be appreciated.
weekday := @Weekday(OrderDate);
leadTime := 2;
Collday1 := 3;
Collday2 := 5;
CollDate1 := @Adjust(OrderDate;0;0; Collday1 - weekday ;0;0;0);
CollDate2 := @Adjust(OrderDate;0;0; Collday2 - weekday ;0;0;0);
n := 1;
PDate := @Adjust(OrderDate;0;0; leadTime;0;0;0);
x := @BusinessDays(OrderDate; PDate;1:7) - 1;
@While(x <= leadTime;
PDate := @Adjust(OrderDate;0;0; n + leadTime;0;0;0);
x := @BusinessDays(OrderDate;PDate;1:7) - 1;
n := n + 1);
Pickeddate1 := @Adjust(PDate;0;0; -1;0;0;0);
Pday := @Weekday(Pickeddate1);
Pickeddate := @If(Pday = 1; @Adjust(Pickeddate1;0;0; - 2;0;0;0);
Pday = 7; @Adjust(Pickeddate1;0;0; - 1;0;0;0);
Pickeddate1);
DistDate := @If(( Pickeddate < CollDate1);CollDate1 ;
(Pickeddate >= CollDate1) & (Pickeddate < CollDate2) ; CollDate2 ;
(Pickeddate >= CollDate2); @Adjust(CollDate1;0;0; 7 ;0;0;0);
@Adjust(CollDate2;0;0; 7 ;0;0;0));
delDate := @Text(@Date(@Adjust(DistDate;0;0; 1 ;0;0;0)));
delDate