---
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 no one master does them one right after another on that day but different masters can, the
  finder offers visits one after another (see “Two visits one after another” below).
- **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 gray 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)).

## The price of a variant

When a service has its own price for a level of masters (see
[Levels of masters](master-levels.md)), the price depends on who does it, so the finder
names it per variant: the price of the whole visit and the price of each service, for the master of
that variant. Two variants of the same time with different masters can differ. With no master named,
a variant carries the price of the master the rule of the branch picked. A search can also be
limited to the masters of one level. Without prices for levels nothing is added: every master
takes the usual price.

## 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.

## Two visits one after another at different masters

A client asks, say, for a manicure and a haircut one right after the other, and on that day no master does both: the finder with `in_turn` then offers visits one after another. A leg is a visit of its own at its own master (the place and the device are chosen as for an ordinary visit); the next visit starts exactly where the one before it ends, and the order is the order the services were named in: the finder does not reorder it. The legs are as few as there can be for time to exist that day, and four at most. When one master does everything in a row, one visit is offered, not legs. A master the client named takes at least one leg, and the finder picks the others.

A variant with legs carries `legs` — for every leg its start, its `service_ids` and `resource_ids`, and the prices of its services. It is booked in one action: all the visits are booked or none, and when one leg does not fit, the refusal names its number (`params.leg`, from 1) and nothing is booked. For the notices these are visits back to back: Talemo writes one message about them when it fits (see [Visit notices](visit-notices.md)), and the answer of the booking says in `client_hears` whether the client gets it. The **Calendar** of the web app does not offer legs: there, two visits one after another at different masters are booked as two bookings; in the app the When they can come card offers “Book both”.

## 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** — some service of the visit has no
  place or no device marked for it at all. 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)); `fits` of
  `talemo_list_services` shows who does which.
- **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 variants of the master of the client's last visit come first (they have `last_time` true); 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`, 1 to 10 (10 when left out); and `visit_id` of a visit being moved, whose own time does not stand in the way, with `keep_master` to look for the move only at the master of the visit (below). The tool asks for visits one after another at different masters itself, instead of “nobody together”, except for a move: a move is one visit, so a search with `visit_id` has no legs. The answer is the short form of the finder; it has `outcome`:
  - `found` — `variants` lists the starts. Each one has `resources` — the master, the place and the device it needs, with `resource_id`, `name` and `role` — and `services` (`service_id` and, when there is one, `price`);
  - `none_together` — nobody does these services together; `fits` of `talemo_list_services` shows who does which. Take a service out or mark a master, a place or a device (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. A member of the business who still wants exactly that time books it with `extend_schedule` once the person has said yes to opening it (see [Visits](visits.md));
  - `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.
- At most ten variants come, spread over the whole window rather than the first ten: the earliest and the latest start are among them. Those with `last_time` true always come, and come first. `more` is `true` when the finder found more than came, other starts or other masters at the same starts: do not tell the client that these are all the times. If none suits, find out when or with whom they would rather come, and call the finder again with a narrower window (`from`, `to`, `after`, `before`) or with a master in `resource_ids`.
- `days` lists the dates of the window (the day by the clock of the branch) that have time free for the whole visit; `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`.
- 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`, its `service_ids` (the `service_id` of each entry of `services`) and the `resource_id` of each entry of its `resources`. Do not build a start of your own. A variant with `legs` goes as its `start` and its `legs` (each leg with its `service_ids`, `resource_ids` and `price`, as the finder gave them), without `service_ids` and `resource_ids` at the top; tell the client every leg: who does it (the `name` of the entry of `resources` with the `resource_id` of the leg) and when (the `start` of the leg).
- When a service of the visit has a price for a level, a variant has `price`, the price of the visit, and each entry of `services` has its `price`, both for the master of that variant (no `price` when no service has a price for a level, and for a role that may not see prices); each leg has `price` too, the prices of its services in order. Name the price of the variant you offer, and book it with the same prices in `price` of `talemo_book_visit` (of its leg, for a variant with `legs`). `level_id` (the `level_id` of a master in `fits` of `talemo_list_services`, or `none` for the masters with no level) looks at the masters of one level; a master named in `resource_ids` beats it.
- A move of a visit keeps to the specialist of the visit. With `visit_id` the answer has `visit_master`: the `resource_id` and `name` of the specialist of that visit, and `free`, whether the specialist has time in the window (why not — a day off, busy, switched off — the answer does not say). With `keep_master` set to `true` the finder looks only at the specialist of the visit while `free`: `variants` and `days` are the specialist's. The tool sets `keep_master` itself when there is a `visit_id` and no `resource_ids` or `level_id`. When the specialist of the visit has no time in those days, `free` is `false` and `variants` hold the time of the other specialists: tell the client that the specialist of the visit has no time, and name the specialist of every time you offer (the `resource_id` of the specialist is in `resources` of the variant, the `name` of the specialist in `fits` of `talemo_list_services`). `keep_master` set to `false` is for a client who asked for any specialist or for another one; a specialist named in `resource_ids` and `level_id` beat `keep_master`. Without `visit_id`, `keep_master` is refused: `request.body_invalid`, `params.field` `keep_master`.
- With `visit_id` the answer also has `visit_time`: for each day of the window its `start`, the time of day the visit stands on laid on that day by the clock of the branch, and `free`, whether the visit goes on that `start`. It is what `talemo_move_visit` would answer for that start, not a second guess: the specialist is the one named in `resource_ids`, otherwise the specialist of the visit, the visit has its services as booked, and the place and device of the visit are kept while they are free. When the person asks to move a visit to the same time, take the `start` of the asked day from `visit_time` and pass it to `talemo_move_visit`; never the earliest start of the day in `variants`, which is another time. When `free` is `false` on that day, say so and offer `variants`. A member of the business also gets `reason` for a day that is not free: `taken` (busy), `closed` (outside the open time: say what would open and ask, as for a booking outside it), `past`, `off_step` (not on the step of the branch) or `unfit` (the specialist or place of the visit cannot take it). The online admin gets no `reason`. `visit_time` does not change with `keep_master`, `level_id`, `after`, `before`, `every` or `limit`, and a visit that took place or was canceled has none.
- `talemo_get_calendar` shows the grid of a branch for one to seven days with the schedules, the visits, canceled 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.
