Hi Jutta,
Thank you for contacting us and I'll be happy to assist.
Based on what you've shared, I'm afraid filtering that your project requires cannot be impletement, only using Toolset plugin's built-in features and you'll need to include some custom programming as well.
Although, 1-1 assistance around custom developement of this extent is beyond the scope of support that we provide, but we do our best to guide in the right direction, whenever possible.
Following are some points which should help you in getting started in the right direction:
1. Is there any specific reason that in your "occupancy", you're storing records of "free_from" and "free_to", instead of "occupied_from" and "occupied_to"?
My understanding is that a fair deal of processing can be avoided, if the occupancy records are saved conversly, which can be crucial for performance in the longer run.
2. To achieve availability filtering, you can save each date on which a certain a apartment is not available/booked, as a seperate custom field entry with that apartment, with a same key, at the time of booking entry.
For example, if "Apartment A" is booked from Nov 6th - Nov 10th, it's custom field key set for booked status (e.g. booked_date) will have 5 record entries for these dates.
Note: save these date values in "Unix timestamp" format, so that performing numrical comparison becomes easier.
3. In your view's search filters, you can ask visitors to enter two dates to check the availablity (To & From).
4. Using a function hooked to "wpv_filter_query" filter ( https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query ), you can get IDs of all the aparments, which are booked between the user's selected dates in an array.
( ref: https://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters )
5. After that, inside that same function, you'll be able to set "post__not_in" query parameter to the main query, to make sure that apartment whose IDs are available in that array are excluded from the results.
( ref: https://codex.wordpress.org/Class_Reference/WP_Query#Post_.26_Page_Parameters )
For a more personalized and detailed assistance around the custom development, you can also consider consulting a professional from our list of recommended contractors:
https://toolset.com/contractors/
I hope this helps and please let me know if you have any further information or questions.
regards,
Waqar