I have been playing around with a few things in the availabilty template and messed something up... Do you think you could explain to me the logic the script uses to see if there is availablty within the hotel?
the core function that checks availability is liberasettimane in the file liberasettimane.php. "Libera settimane" means "to free weeks", as originally php-residence was only for weekly periods, so each time you see "settimane" you can consider that as referring to "days". Liberasettimane works recursively (it calls itself) until it frees an apartment, but I think you are more interested in how it is used in the availability template.
If you open the file modello_disponibilita.php, in the includes/templates directory, after some checking of the passed variables the fuction tab_a_var is called, its role is to transer the reservatins data from the database table to some variables, these variables are passed later to liberasettimane. The requested apartments (you can have multiple requests) are stored in $app_richiesti. If there are some assignment rules 1 ($num_app_agenzia != 0) before the first attempt of liberasettimane some fake reservations are inserted in the periods corresponding to those rules.
Then if there were no rules 1 or it was not possible to free the requested apartments, liberasettimane is called (again or for the first time). If the requested apartments have been freed $fatto_libera will be set to "SI".
That's more or less how it works, hope it was sufficiently clear.