Enforce 3-day holiday weekend reservations |
Top Previous Next |
We plan to eventually have some "simple" way to set up special restrictions like 3-day weekends, but until we do there is a way you can do it with a customization.
Standard disclaimer: This involves Advanced Customizations, which are beyond the scope of normal tech support -- aside from this example, you're on your own with the implementation of this function and any side effects it may cause if not done correctly.
Please note that this is only going to work well with single reservations or synchronized reservations -- if you use the New Reservation dialog to make multiple reservations covering different dates, this will not check them all.
1. The first step is to add a Dialog definition that's an Add-on to the New Reservation dialog. Go to Maintenance / Advanced Customizations / Dialogs, and click "Add dialog definition".
Note: Only one Add-on definition can be active for a given dialog, so if you already had such a definition, for instance to force How-Heard to be filled in (described a previous newsletter article), then you would just add elements on to the existing one instead of creating a new one here (in which case, skip to step 3).
2. Give it a name, such as "New Reservation add-on". Then check the "Add-on" box and select "New Reservation" from the list. We're not adding any new controls to it, so the Width and Height values can remain 0.
3. Now we need to add an action to the dialog that checks the dates, showing an error message and preventing the reservation from being saved if they are note appropriate. Click "Add Element", and for the element type select "Action on data saved".
4. We don't really need a Condition for this element (assuming we always want it to enforce the rule), though you might want to add a condition so that only non-administrators are restricted, for instance. In that case you could put the following expression in the Condition box:
CurrentOpLevel() < 5
5. Now for the Action expression, which will be executed when the reservation is saved (e.g. "Done", "Continue", or any other button clicked that would normally save the reservation). We won't go into the design details, but it should be fairly self-explanatory if you look up the components in the Function Reference of the Advanced Customizations documentation. Also note that we need the Control ID of the How Heard field, which can be looked up in the Dialog Control ID reference. This can be found online here: http://campgroundmaster.com/help/basedialogs.html.
Basically what we're doing here is checking to see if the First Night is after July 4th or the Last Night is before July 2nd. If so then it's OK, the reservation doesn't include the holiday weekend, and we can return True (OK to continue). We're also checking the number of nights, and if it's 3 or more then we're also OK to continue and we return True. Otherwise, the dates include the holiday weekend and it's too short, so we need to tell them it's not a valid reservation and return False to not let them save the reservation.
Enter this for the Action expression:
IIFQ(DlgGetCtrlDate(1052) > {7/4/10} OR DlgGetCtrlDate(1068) < {7/2/10} OR
Val(DlgGetCtrlText(1069)) >= 3,'.T.',
'B(Eval(MessageBox("Error -- Holiday weekend reservations must be at least 3 nights."), .F.))')
A few notes about the expression:
- It's broken into multiple lines for readability here, but it must be continuous (no line breaks) when you enter it. If copied from this text, you need to "delete" the line breaks after pasting it into the expression.
- IIFQ is used instead of IIF, because we don't want both of the result expressions to be evaluated (which would result in the error showing up no matter what).
- Every single punctuation mark and space is important. Study it very carefully if not using copy/paste. The braces around the dates are different than the parenthesis used in other places. Single-quotes are not the same as double-quotes.
6. We also need to check both of the boxes -- "Execute the action before..." and "Abort the operation...". Obviously we want to make sure this condition is met before actually saving the reservation, and if the How Heard is not filled in then we don't want to save the reservation yet.
7. Now just Save the element, and we're done with the customization for checking the How Heard field. Once you're all finished, just Save everything and try it out. Remember that if you entered the condition shown in step 4, it will still allow short holiday reservations unless you log in as a lower level operator.
If you need to check multiple dates, then it's best to add a separate element for each one (otherwise the logic gets complicated) Just use the Copy Element function to make copies of this one and change the dates in each one accordingly.