move getAvailableUnitNumber out of sql, fix case when user request the unit number that is already assigned