// *************************
// * VARIABLE DECLARATIONS *
// *************************
// We require an empty date variable to hold a date calculated within the formula
dateVar dteHolder;
// Next, we need to define the due period. As this may change with
// the business rules, it makes sense to put it in a variable at the top of the
// formula to make it easy to change.
numberVar DuePeriod := 4;
// ****************
// * CALCULATIONS *
// ****************
// We add the due period to the current date and store it in the date variable
dteHolder := CurrentDate + DuePeriod;
// Next, we need to determine upon which day the due date falls. Each day has a number
// assigned to it in Crystal. These are:
// 1: Sunday
// 2: Monday
// 3: Tuesday
// 4: Wednesday
// 5: Thursday
// 6: Friday
// 7: Saturday
// So, if the Due Date is 1 or 7 then we need to correct this.
// We examine the due date with a Select...Case structure. These are the rules:
// If the due date falls on a Sunday, we add one further day to it.
// If the due date falls on a Saturday, we add two further days to it.
// Otherwise, there's no need to add any extra days and we return the default.
Select WeekDay(dteHolder)
Case 1: dteHolder + 1 // DueDate falls on Sunday. Add 1 day.
Case 7: dteHolder + 2 // DueDate falls on Saturday. Add 2 days.
default: dteHolder // DueDate falls on Week day. Use DueDate.
; // End Select
// End Formula