---
title: Finding free time for a booking
summary: Booking a visit goes through the finder. It looks for a start at which everyone and everything the visit needs is working and free at once, and says why when there is none.
tools: [talemo_find_times, talemo_get_calendar]
related: [visits, who-does-what, resource-schedule, booking-rules, services-and-prices]
search: [availability, free slots, open time]
---

# Finding times

A visit is booked only through the finder (**Calendar → Book**, or
`talemo_find_times` and then `talemo_book_visit`). Booking checks the chosen
start by the same rules again, so a booked visit is always one the finder would
offer.

## What it asks

- **For whom** — the client's card. It is optional for a search, and with it the
  variants with whoever did the client's last visit come first, marked "last time".
  For booking there is also **New client**: a name and a number instead of a card (see
  [Visits](visits.md)); the finder works for it without "last time": there is no card yet.
- **In one visit** — one or several services. The finder looks for time for all
  of them together.
- **When** — a month where a dot marks the days on which the people, places and
  devices that fit have free time for the whole visit. A day without a dot is all
  taken, a grey one has nobody working, a hatched one has no schedule. Pick a day
  to see the start times on the step of the branch, in the time of the branch:
  Morning (before 12:00), Afternoon (from 12:00), Evening (from 17:00). **Nearest**
  picks both the day and the time at once.
- Optionally the resources it must use. **Who fits** lists the masters, places and
  devices that can do the visit. If a resource picked from the grid menu does not fit
  the services of the visit, the finder refuses, and under the refusal **Who fits**
  stays for that role: the picked one has a cross — press it and the finder starts
  over without it, or pick another one from the list. The refusal names the picked one and
  the services that are not marked for it, and tells that if they need to be marked, this is
  done on its card, in Services.

## What a variant is

A variant is a start, the resources that take it and two durations: **Work** and
**with cleanup**. A start falls on the booking step ("Starts every N minutes — set
in the booking rules"). Work must lie in the open time of every resource and be free
of other visits; the cleanup of the last resource may go past the edge of the working
day, and other visits wait for it. Past time is not offered.

For each of a master, a place and a device the visit needs, a resource is offered only if it is working, free and
marked as doing every service of the visit that needs it (see
[Who does what](who-does-what.md)).

## Who gets a start

When no master is named and several are free at that start, the master of the client's
last visit goes first ("last time"), and then the rule of the branch for Any master picks:
Evenly, No gaps in the schedule or In order (see [Booking rules](booking-rules.md)). A
named master does not follow the rule. A place and a device do not follow it either: the less
busy one that day is taken, then by order of adding. Booking at the chosen start goes by the
same choice, so the visit lands with the master the finder showed. The outcome of each day
(`days`) does not depend on the rule.

## When there is nothing

The answer has one of these reasons, and each is an ordinary answer of the finder:

- **No master has all these services marked together** — no single master is marked for all
  the services that need a master. Free time is not searched; take a service out or
  mark a master.
- **No place (or no device) has the services marked** — for a place or a device `without_fit`
  names the services that are marked for none of them. Free time is not searched; mark the
  service on the card of a place or a device (see [Who does what](who-does-what.md)).
- **No schedule for these days** — no day is laid out for the resources that fit.
  Nobody can be booked until the schedule is laid out (see
  [Schedule of a resource](resource-schedule.md)).
- **Not working in this window** — everyone who fits has a day off or other hours.
  The time is not taken, it is not in the schedules.
- **No free time in this window** — everyone who fits is busy or not working.

With the last two the finder also offers the nearest free time after the window, if
there is one in the next 90 days; the same visit can be booked there.

## The calendar

`talemo_get_calendar` shows the grid of a branch for one to seven days, and the
Calendar grid a week: the resources, their open and busy time by day, the visits, and how many visits are not closed.

## Who can use it

Finding times is its own right; the Administrator role has it. A role limited to own
sees only the masters the person works as. The online admin uses the same finder for
the client it is talking to, and it does not see which resources do not fit or why.

## Tools and refusals

- `talemo_find_times` takes `branch_id` and `service_ids` (the IDs from `talemo_list_services`, in the order they are done) and optionally: `party_id`, so that the resources of the client's last visit come first (`last_time` names them); a window `from` and `to` (a week when left out, 31 days at most) and a time of day `after` and `before`; `resource_ids` when the person asked for particular ones; `every` for every start on the step instead of the earliest of each day for each master; `limit`; and `visit_id` of a visit being moved, whose own time does not stand in the way. The answer has `outcome`:
  - `found` — `variants` lists the starts with the resources for each one needed — master, place, device; `service_ids` of a resource names the services it takes (the master leads all of them, a place and a device are picked for each service: first the one the neighbouring service has); `step_minutes` is the step of the starts;
  - `none_together` — nobody does these services together; `roles` tells who fits as a master, a place and a device, and `without_fit` of a place or a device names the services that no place or device can take. Take a service out or mark a master (see [Who does what](who-does-what.md));
  - `none_free` — everything is taken;
  - `day_off` — nobody who fits works in the window: a day off, other hours than the asked time of day, or the time has passed. It is not busy time, so do not offer it: booking it is refused with `visit.outside_schedule`, or with `visit.past` when the start has passed;
  - `no_schedule` — the fitting resources have no schedule; lay it out first (see [Schedule of a resource](resource-schedule.md)).
- When the window is empty, `next` is the nearest time beyond it within 90 days.
- `days` is the outcome of every day of the window: `date` (the day by the clock of the branch) and `outcome` in the same words as above; `limit` does not change it. To see which days of a month have room, ask the whole month (31 days at most) with `limit` 1 and read `days`: a `found` day has free time for the whole visit.
- Without `every` the answer is incomplete: it has only the earliest start of each day for each master, and a later time may be free. To check a time the person named, search with `every` and with `after` and `before` around it.
- A resource named in `resource_ids` that cannot take its role is refused with `visit.resource_unfit`, `params.role` and `params.resource_id`, as a booking would be: a master who does not do all the services, a place or a device that does none of the services of its role. It is not `none_together`; name another resource or take the services apart.
- A master not named in `resource_ids` is chosen by the finder: first the master of the last visit of `party_id`, then the rule of the branch, `any_master` (see `talemo_get_booking_rules`).
- A variant goes as it is to `talemo_book_visit`: its `start` and the `resource_ids` of its resources. Do not build a start of your own.
- `talemo_get_calendar` shows the grid of a branch for one to seven days with the schedules, the visits, cancelled ones too, and `unclosed_count`. When the person sees just the visits of the resources linked to them, it also gives `own_resource_ids` (see [Visits and their statuses](visits.md)).
- Every outcome is an ordinary answer of the finder, not a failure. Tell the person which one it is and what would change it.
