I need to bring in a customised date field (something like porel.date01)…which is the easy bit.
I need this date though to be a calculation that cannot be modified.
So,
porel.date01 = PORel.PromiseDt less 1 working day.
Just excluding weekends will be fine. (our production calendar excludes weekends).
Not changed as in…the date01 field cannot be modified by a user (i guess this is to basically make it read only?)…but if the promisedt field is changed the date01 field can move with it.
Calculating date differences used to be a pain, but C# has some functions (VB may as well) for doing the date diff. Just check
In totally pseudo code:
If(DayOfWeek(PromiseDt)= {value of Monday}) Then
Date01 - DateDiff(PromiseDt,-3)
Else If(DayOfWeek(PromiseDt)= {value of Sunday}) Then
Date01 - DateDiff(PromiseDt,-2)
Else
Date01 - DateDiff(PromiseDt,-1)
end if
Do this in a Data Directive on change of PromiseDt
As for making it “read only”, do that at the form level, where ever it is displayed.
def var newDate as Date init Today no-undo.
def var totalDays as Integer init 0 no-undo.
def var validDateFound AS LOGICAL init false no-undo.
def var calName as Character init "MAIN" no-undo.
for each ttQuoteHed no-lock, first QuoteHed where QuoteHed.QuoteNum = ttQuoteHed.QuoteNum.
if (QuoteHed.Quoted eq false) THEN DO:
// Initialize
assign newDate = QuoteHed.DueDate.
for first ProdCal fields (BeginWeekday WorkWeek) where ProdCal.Company = CUR-COMP and ProdCal.CalendarID = calName no-lock.
// Search for a Valid WorkDay
do while validDateFound = false:
// Make sure the WeekDay is not a Saturday or a Sunday
if weekday(newDate) <> 1 and weekday(newDate) <> 7 then do:
// If its not the Weekend make sure it is a WorkingDay
find first ProdCalDay no-lock where ProdCalDay.CalendarID = calName and ProdCalDay.ModifiedDay = newDate and ProdCalDay.WorkingDay = false no-error.
// If its not a WorkingDay try going a date back
if not available(ProdCalDay) then do:
if ProdCal.WorkWeek[ weekday(newDate) ] = true then do:
assign validDateFound = true.
end.
end.
end.
// We dont have a valid date lets try next day
if (validDateFound eq false) THEN DO:
assign newDate = newDate + 1.
END.
end.
end.
// Assign New Due Date
assign QuoteHed.Date02 = newDate.
assign QuoteHed.DueDate = newDate.
END.
end.
def var newDate as Date init Today no-undo.
def var totalDays as Integer init 0 no-undo.
def var validDateFound AS LOGICAL init false no-undo.
def var calName as Character init “MAIN” no-undo.
for each ttPORel no-lock, first PORel where PORel.PONum = ttPORel.PONum.
if (PORel.Date01 > 01/01/2015) THEN DO:
/* Initialize*/
assign newDate = PORel.Date02.
for first ProdCal fields (BeginWeekday WorkWeek) where ProdCal.Company = CUR-COMP and ProdCal.CalendarID = calName no-lock.
/* Search for a Valid WorkDay*/
do while validDateFound = false:
/* Make sure the WeekDay is not a Saturday or a Sunday*/
if weekday(newDate) <> 1 and weekday(newDate) <> 7 then do:
/* If its not the Weekend make sure it is a WorkingDay*/
find first ProdCalDay no-lock where ProdCalDay.CalendarID = calName and ProdCalDay.ModifiedDay = newDate and ProdCalDay.WorkingDay = false no-error.
/* If its not a WorkingDay try going a date back*/
if not available(ProdCalDay) then do:
if ProdCal.WorkWeek[ weekday(newDate) ] = true then do:
assign validDateFound = true.
end.
end.
end.
/* We dont have a valid date lets try next day*/
if (validDateFound eq false) THEN DO:
assign newDate = newDate + 1.
END.
end.
end.
/* Assign New Due Date*/
assign PORel.Date02 = newDate.
END.
You won’t see Date02 change until the record is saved. If you need to see Date02 change on the screen (when Date01 changes), use a customization triggering off an event tied to Date01’s control. Do the math, and then update Date02’s GUI control.
EDIT: This was done in E10, so the expression might vary. WeekDay==1 for Sunday, ==2 for Monday,
EDIT #2 VERY IMPORTANT !!!
Changed the values in the comparisons. On screen help says Sun=1. When in fact, Sun = 0.