FAQ Q389: The rental duration depends on the services selected by the customer on the reservation form. How to implement this?

Section: Reservation form
First of all, you need to make sure your reservation form includes the start time and duration, rather than the default start time and end time fields. This requires that in time-related settings of your resource you specify predefined durations where you should enter all the possible durations that can be used for a reservation. E.g. if based on services selected the duration ranges from half-hour to three hours with 30min increments, you'll need to define durations of 30min, 1h, 1h30min, 2h, 2h30min, 3h.

Once done, in automatic updates of form items it's possible to configure the duration dropdown to work with this use case. Automatic updates normally work by setting a value of one form item whenever another form item is set. In this case, the duration should depend on a number of other fields so we'll need to add a new rule with the trigger item set to Always true. This means that the rule is always active. The dependent item should be set to the Duration field which is a dropdown so we must make sure any value set by this rule is already a possible choice. The checkbox Hide item should be selected because the duration should be set automatically rather than chosen by the customer. The customer should be aware of the duration so this will be added to the your rate box next to the price (see below). In dependent value we set the formula which will calculate the duration based on the services selected.

The service selection should be done using checkboxes or dropdowns. In case of dropdowns it's assumed the customer is choosing the quantity where each unit increases the duration by x minutes. In case of checkboxes the quantity of each service choice is one or zero. Here we'll assume the form includes 4 checkboxes: haircut (adds 60min), shave (adds 30min), hair coloring (adds 30min), scalp massage (adds 60min). As you can see in reservation form layout these services would correspond to planyo tags: $(prop_haircut), $(prop_shave), $(prop_hair_coloring) and $(prop_scalp_massage). You'll see the exact tags to use for each form item on that page. In automatic updates of form items it's possible to use these tags only in specific situations (inside the $(calc:...) tag). Note that you can also use the tags $(prop_res_...) which represent the value of a custom resource property. This is useful if the same reservation form is shared by many resources while the resulting durations are different.

In order to set the dependent item's value (duration) correctly it's important to understand that the duration value in the dropdown is internally expressed as the number of hours, so e.g. 0.5 for 30min, 2 for 2 hours and 1.25 for 1h15min. This means the calculation must be done in hours. In order to tell Planyo to do a math calculation in dependent value you must use the tag $(calc:....). Inside this tag you can use the tags mentioned above plus arithmetic operators: + - * / ( ). In case of the hair styling services explained above, the dependent value would be set as follows:
$(calc:(60 * $(prop_haircut) + 30 * $(prop_shave) + 30 * $(prop_hair_coloring) + 60 * $(prop_scalp_massage)) / 60)
Note that $(prop_...) has the value of 1 if the checkbox is selected and 0 otherwise. So here we have a formula which adds 60 or 30 minutes to the total duration for given service and then the result is divided by 60 because as mentioned the duration must be expressed in hours and not in minutes.

Now the only thing left to do is to inform the customer of the calculated duration. In reservation form info box set the display mode of reservation form page to Price breakdown + Custom and in the custom text include the tag $(duration) which will display the resulting duration.
Questions Fréquemment Posées (FAQ)