How can I restrict travel bookings based on place and trip date?

How can I restrict travel bookings based on place and trip date?

In the following code, added to the on add -> validate block of the Script tab, the Booking_Form restricts entries based on the following conditions:

  • Only four bookings allowed for a specific place on a day. If the number of bookings (with Place & TripDate same as the input Place & TripDate) is equal to 4, the alert message will be displayed and the record will not be submitted. 
  • The same person cannot book on consecutive weekends. The consecutive weekend days (Saturday and Sunday) are calculated based on the current Trip date. If the same person has booked on those dates, the alert message will be displayed and the record will not be submitted.  

            if (count(Booking_form[(Place == input.Place && TripDate == input.TripDate)])  ==  4)
{
alert "Booking full on this date. Please try some other date";
cancel submit;
}
else if (input.Date_1.getDayOfWeek() >= 6)
{
previous_weekend1 = (input.TripDate - '1W:0D:0H:0M:0S');
previous_weekend2 = (input.TripDate - '0W:6D:0H:0M:0S');
if ((count(Booking_form[(Name == input.Name && TripDate == previous_weekend1)]) != 0) ||
(count(Booking_form[(Name == input.Name && TripDate == previous_weekend2)]) != 0))
{
alert "You cannot book consecutive weekends";
cancel submit;
}
}