## Context

### What the two listings report today

```
 ADMIN    index()  →  with(['created_by','company'])->withCount('accounts')
                      ├─ accounts_count  ✓
                      └─ accounts        ✗

 MANAGER  index()  →  with(['created_by','company'])
                      ├─ accounts_count  ✗
                      └─ accounts        ✗
```

The manager's list is the poorer of the two: it reports neither who a request covers nor how many.

### How a manager reaches a request

```php
// OvertimeRequest.php:147
public function scopeFilterByManager($query, $manager) {
    return $query->filterByAccounts($manager->getAllMyEmployeeIds());
}
// → whereHas('accounts', fn ($q) => $q->whereIn('accounts.id', $ids))
```

`whereHas` narrows the **requests**, not the employees inside one. A manager therefore sees any request that holds at least one of their own employees, and such a request may hold others — created by a different manager over an overlapping group, or by `getApplicableAccountsByRequest()` when no department, position or employee was named, which attaches every employee of the company.

`getAllMyEmployeeIds()` is a recursive CTE walking the leader tree three levels deep (`Account.php:1145`), so "the manager's own employees" is itself a non-trivial query, not a column.

### What the avatar needs

`Account::$relationData` already holds a variant sized for exactly this, used by the per-request employees endpoint:

```php
'simple_employee' => [
    'profile:id,account_id,firstname,lastname,avatar',
    'employee:id,account_id,code,working_email',
]
```

The `accounts()` relation uses a heavier one — `simple_employee_detail`, which adds phone, join date, bank account, and the whole position → department → company chain.

### Filters the endpoint already honours

`filterByRequest()` serves this listing and already accepts `q`, `from`, `to`, `created_from`, `created_to`, `status`, `input_mode` and `company_id`. The client currently sends only `status`, `input_mode` and `page`.

## Goals / Non-Goals

**Goals:**
- Let a manager see, without opening anything, who a request covers.
- Keep the cost of the listing independent of how many employees a request holds.
- Keep the figures on the screen consistent with each other.

**Non-Goals:**
- The administrator's screens. Its count is already reported; only the preview is missing there, and that is its own task.
- New filter parameters. Both filters asked for already exist.
- Any change to who counts as covered by a request. Employees who have left are covered, as they are everywhere today. See Decision 6.

## Decisions

### 1. The preview covers the manager's own employees, not the whole roster

A row reports the employees of the request that the manager leads, and `accounts_count` counts those same employees.

*History:* a whole-roster reading was tried first, on the argument that a request is one object with one roster. It was reversed by `fix-overtime-manager-scope`: a manager's list is a view of their own team, so faces, count and monthly figures describe that team and not whoever else shares the request. Do not propose the whole-roster reading again without reading that change.

*What it costs:* two managers sharing a request see different counts for it, and the detail (`GET /{id}/accounts`) still lists everyone, so a row of two faces may open onto five.

*Where the system lands:*

| | Whose employees |
|---|---|
| Preview on the list | the manager's own |
| `accounts_count` | the manager's own |
| `total_employee_on_month` | the manager's own |
| `total_time_on_month` | the manager's own |
| `GET /{id}/accounts` | every employee of the request |

### 2. Ten employees previewed, and the real total beside it

The preview carries at most ten employees, held as `OvertimeRequest::EMPLOYEE_PREVIEW_LIMIT`. `accounts_count` carries the true number, so the client renders the faces it has room for and a remainder.

*Why cap at all:* a request can hold every employee of a company — that is what `getApplicableAccountsByRequest()` does when a manager names no group, and it is the case the workday mode was built for. Thirty rows of that would be a payload measured in megabytes for a list that shows a handful of circles.

*Why ten:* most requests hold one employee, because the administrator's form takes a single `account_id`; the cap only bites on requests made through the manager's form, where a team-sized roster is the common case. Ten lets a team-sized request render without a remainder, and bounds a page at thirty rows times ten — three hundred light records, still small beside the position and department chain the heavier variant would have carried for even one. It was five at first; ten was asked for once the layout was seen.

*Why a fixed number rather than a parameter:* one client renders this, with one layout. A parameter would be a second thing to validate and document so that a number could be changed in two places instead of one.

### 3. A light payload, not the existing relation

The preview loads `simple_employee` — name, avatar, employee code — not the `simple_employee_detail` the `accounts()` relation carries.

*Why:* `simple_employee_detail` pulls phone, join date, bank account number and the position → department → company chain. None of it reaches an avatar or its hover label, and the chain costs joins per employee. The per-request employees endpoint already overrides the relation this way for the same reason.

### 4. Cost does not grow with a request's size

The preview must not be loaded by taking a request's whole roster and slicing it in memory: that reads everything the cap exists to avoid. It should read the pivot for the page's requests, keep the first few ids per request, and load only those employees.

*Why it matters here specifically:* this is a paginated listing, so the work is already multiplied by the page size. The same reasoning drove the batching in `add-overtime-workday-input` Decision 8b, and the worst case is the same one: a single request holding hundreds of employees.

*A detail that is easy to get wrong:* "the first few" has to be a stable few, or the faces shuffle between page loads. Order the pivot by account id, or by the pivot's own key, rather than leaving it to the database.

### 5. The filters asked for are the ones already there

No parameter is added. `q` matches an employee's name or code; `from` and `to` select requests by the date the overtime falls on.

*Worth telling the client:* `q` also matches the request title, so a field labelled only "employee" would surprise someone who typed a title and got a hit. The administrator's screen labels its box "title, code, employee name", which is accurate.

*And:* `from`/`to` select by the overtime date, while `created_from`/`created_to` select by when the request was raised. Both exist and they are different questions.

### 6. A roster is read through the accounts table, never from the pivot alone

Both the preview and the count reach `accounts`, rather than counting or slicing pivot rows directly.

*Why, concretely:* the pivot declares `onDelete('cascade')` on `account_id`, but the only path that deletes an account disables the constraint before doing so:

```php
// EmployeeController.php:1113
DB::statement('SET FOREIGN_KEY_CHECKS=0;');
$item->forceDelete();
DB::statement('SET FOREIGN_KEY_CHECKS=1;');
```

The cascade therefore never fires, and `account_overtime_request` keeps rows pointing at accounts that no longer exist. A count taken off the pivot would include them; a preview taking "the first N account ids" could spend slots on them and render fewer faces than it claims.

*What this is not.* An earlier draft of this decision had the roster excluding "employees who have left", on the reading that `accounts()` carrying `withTrashed()` put them in while the monthly tile's count left them out. That was wrong on both halves. Nothing soft-deletes an account — the one delete path is a hard `forceDelete()`, allowed only within 24 hours of creation — so `withTrashed()` selects nobody extra and the two paths never disagreed. And an employee who leaves is not deleted at all: they are marked `quit_job` on `employees.status`, and no overtime code looks at that column. Departed employees are counted everywhere today, deliberately: the request is a historical record of overtime they worked and were paid for, and a month's figures have to explain a payroll that included them.

*A leftover worth tidying.* `sumOvertimeDuration()` joins `accounts` and adds `whereNull('accounts.deleted_at')`. The join is right, for the orphan reason above. The `whereNull` filters a set that is always empty and its comment claims a purpose it does not serve; it is recorded for correction in the change that added it.

## Risks / Trade-offs

**A manager sees employees outside their team** → Decision 1, accepted deliberately. Bounded by the fact that only requests already touching their team reach the list at all.

**The tile disagrees with the faces** → Only until `add-overtime-workday-input` task 7.11 lands. The two changes have to ship together, or the screen shows a row of avatars over a count of two. This is the one hard ordering constraint.

**The preview silently misleads if the count is wrong** → Ten faces and "+3" is read as thirteen employees. If `accounts_count` were scoped differently from the preview, the remainder would be wrong in a way nobody can see. Both must come from the same set.

**Payload or query growth on a page of large requests** → Decision 4. A test should load a page where one request holds several hundred employees and assert the query count, not the elapsed time.

**Orphan pivot rows inflate a count or blank a face** → Decision 6. Deleting an account leaves its pivot rows behind, because the delete path turns foreign key checks off. A count taken off the pivot, or a preview that picks ids from it without confirming the accounts exist, is wrong in a way that only shows on data where someone was deleted within their first day.

## Open Questions

None outstanding. The treatment of employees who have left was the last one and is settled by Decision 6.
