Requirement
Calculate the cost of a taxi or hired car based on distance.
Use Case
A cab booking application calculates and displays the approximate cost of a trip based on pickup and drop-off addresses, after which the user can choose to book the ride in the
Rent Requisition
form
by clicking a button.
Steps to follow
Form
| Form Link Name | Field Type | Field Name | Field Link Name |
Rent Requisition | Rent_Requisition | Name | Name | Name |
Phone | Phone | Phone_Number |
Date-Time | Travel Date & Time | Travel_Date_Time |
Single Line | Starting Point | Starting_Point |
Single Line | Drop | Drop |
Booking | Booking | Single Line | Starting Point | Starting_Point |
Single Line | Drop | Drop |
Decimal | Distance | Distance |
Currency | Price | Price |
2. Duplicate the
Booking
form to create a
stateless form. Rename it
Booking Estimate. We are using a stateless form because we are just using it to display the estimate. Some customers may just browse or check for the price.
3. Click on the
Form Properties
icon in the form builder header of the
Booking Estimate
form.
4. In the slider, remove the default buttons:
Submit
and
Reset.
5. Create a button by clicking
Add Button.
6. A new button named
Button
is created. Rename it to
Book Now!
as shown below, by clicking the three dots to the right of the button name.
7. In the same way, create a button named
Calculate Price.
8. Create a workflow
on the
Booking Estimate
form, to be executed upon loading the form, to disable the
Price
and
Distance
fields.
9. Click
Add New Action. Add the below code to disable the
Price
field:
disable Price;
disable Distance;
10. To calculate an estimate for the trip based on the distance traveled, create another workflow to execute when the
Calculate Price
button is clicked.
11. Click
Add New Action
and add the below code to calculate
Distance
and
Price. We are using the Zoho Maps Deluge method to find the
distance between
two locations.
//Calculate the distance between Start and Drop in km. We are using trim() to remove any spaces in the Starting Point and Drop
dist = round(zoho.map.distanceBetween(input.Starting_Point.trim(),input.Drop.trim(),"KILOMETRE"), 2);
//Assuming driver cost to be Rs.350
driverCost = 350;
//Assuming the driving cost to be Rs.17/km
ratePKm = 17;
//Calculating the prime estimate
price = round(driverCost + (dist * ratePKm) , 2);
//Since clicking the button refreshes the form, we are reopening the form after calculation¯with the values.
openUrl("#Form:Booking_Estimate?Starting_Point=" + input.Starting_Point + "&Drop=" + input.Drop + "&Distance=" + dist + "&Price=" + price , "same window");
This will display the estimate of the cost of the journey.
12. Create a workflow for booking the cab when the
Book Now!
button is clicked after the estimate is shown.
13. Click
Add New Action
and click
Deluge Script. Add the below script to open the
Rent Requisition
form with the
Starting_Point
and
Drop
fields already populated.
openUrl("#Form:Rent_Requisition?Starting_Point=" + Starting_Point + "&Drop=" + Drop, "same window");
The customer will enter the
Travel Date & Time
and rider details.
See how it works
Points to Note
zoho.map.distanceBetween(Starting_Point, Drop, "KILOMETRE");