Reservation System

Reservation System

Here is my basic code to start with.

// Step 1: Capture user input for Check-In and Check-Out dates
check_in_date = toDate(check_in,"MM-dd-yyyy");
check_out_date = toDate(check_in,"MM-dd-yyyy");
//info "Check in date " + check_in_date + " - Check out date " + check_out_date;
// Step 2: Get a list of all nightly rentals I only have 68 rentals
all_rentals = Sites[Campsites == true];
//info "All Rentals " + Sites[Campsites == true].count();
// Step 3: Filter rentals that are not booked for the requested date range
available_rentals = Collection();
// Create an empty collection to store available rentals
for each  rental in all_rentals
{
// Check for existing reservations in the "Reservations" table
reservations = CG_Reservation[Sites == rental && Active_Reservation == true && Check_In != null && Last_Night != null && Check_In <= check_out_date && Last_Night >= check_in_date];
// If no reservations conflict with the requested dates, add the rental to available_rentals
if(reservations.ID == null)
{
available_rentals.insert(rental.ID);
}
}

When I execute the code with these dates, 09-25-2024 Check-in and 10-01-2024 Check-out. It's returning 37 available. The correct answer would be 14
How do I remove the 23 that's incorrect
It's returning Rental 2B  Which is already rented 09-27-2024 to 09-29-2024 

Any suggestions

    Access your files securely from anywhere

        Zoho Developer Community




                                  Zoho Desk Resources

                                  • Desk Community Learning Series


                                  • Digest


                                  • Functions


                                  • Meetups


                                  • Kbase


                                  • Resources


                                  • Glossary


                                  • Desk Marketplace


                                  • MVP Corner


                                  • Word of the Day



                                      Zoho Marketing Automation


                                              Manage your brands on social media



                                                    Zoho TeamInbox Resources

                                                      Zoho DataPrep Resources



                                                        Zoho CRM Plus Resources

                                                          Zoho Books Resources


                                                            Zoho Subscriptions Resources

                                                              Zoho Projects Resources


                                                                Zoho Sprints Resources


                                                                  Qntrl Resources


                                                                    Zoho Creator Resources



                                                                        Zoho Campaigns Resources


                                                                          Zoho CRM Resources

                                                                          • CRM Community Learning Series

                                                                            CRM Community Learning Series


                                                                          • Kaizen

                                                                            Kaizen

                                                                          • Functions

                                                                            Functions

                                                                          • Meetups

                                                                            Meetups

                                                                          • Kbase

                                                                            Kbase

                                                                          • Resources

                                                                            Resources

                                                                          • Digest

                                                                            Digest

                                                                          • CRM Marketplace

                                                                            CRM Marketplace

                                                                          • MVP Corner

                                                                            MVP Corner





                                                                              Design. Discuss. Deliver.

                                                                              Create visually engaging stories with Zoho Show.

                                                                              Get Started Now