Skip to content

Instantly share code, notes, and snippets.

@hasokeric
Created August 31, 2016 15:24
Show Gist options
  • Save hasokeric/3307cfbb67db85a69263ee13be0b1f40 to your computer and use it in GitHub Desktop.
Save hasokeric/3307cfbb67db85a69263ee13be0b1f40 to your computer and use it in GitHub Desktop.
Epicor's System sets an Automatic Due Date from your Company Config table... But if you say +3 days... it doesnt care if its a weekend or a holiday... Lets check the Production Calendar and assign a proper DueDate.
/* Specify the DueDate */
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 where ttQuoteHed.RowMod = "A".
if (ttQuoteHed.Quoted eq false) THEN DO:
/* Initialize */
assign newDate = ttQuoteHed.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:
/*{lib\PublishInfoMsg.i &InfoMsg=string(newDate)}.*/
/* 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. /* if */
/* We dont have a valid date lets try next day */
if (validDateFound eq false) THEN DO:
assign newDate = newDate + 1.
END.
end. /* while */
end.
/* Assign New Due Date */
assign ttQuoteHed.Date02 = newDate.
assign ttQuoteHed.DueDate = newDate.
END.
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment