## ADDED Requirements

### Requirement: Overtime Request Input Modes

An overtime request SHALL be recorded in one of two input modes.

In `time_range` mode the request carries a start and an end, and its overtime duration is the interval between them. This is the existing mode and the default: a request that does not state its mode SHALL be a `time_range` request, and every overtime request that exists when this capability is introduced SHALL be a `time_range` request.

In `workday` mode the request carries a date and an amount of overtime workday, and no start or end. The amount is stated in the same `HH:MM` form as every other duration field in the system and means hours of overtime workday, not hours worked.

Both modes SHALL record the date the overtime belongs to, and a request SHALL be attributed to the timesheet of that date.

A request's mode SHALL be reported wherever requests are read, so a reader can tell what was entered, and listings SHALL accept it as a filter so one mode can be shown at a time. A listing given no mode filter SHALL return both.

#### Scenario: Request created without stating a mode
- **WHEN** an overtime request is created without stating an input mode
- **THEN** the request is a `time_range` request

#### Scenario: Existing requests on introduction
- **WHEN** input modes are introduced
- **THEN** every overtime request that already existed is a `time_range` request
- **AND** its overtime duration is unchanged

#### Scenario: Creating a workday request
- **WHEN** an admin creates an overtime request in `workday` mode for a given date with an amount of `05:00`
- **THEN** the request records five hours of overtime workday for that date
- **AND** the request carries no start or end time

#### Scenario: Several workday entries in one submission
- **WHEN** an admin submits three `workday` entries for one employee in a single request
- **THEN** three overtime requests are created
- **AND** each records its own date and amount

#### Scenario: Mode is visible when reading a request
- **WHEN** an overtime request is retrieved or listed
- **THEN** the response states its input mode

#### Scenario: Listing filtered to one mode
- **WHEN** requests are listed filtered to `workday`
- **THEN** the response contains only `workday` requests

#### Scenario: Listing with no mode filter
- **WHEN** requests are listed without a mode filter
- **THEN** the response contains requests of both modes

#### Scenario: Mode filter combines with the other filters
- **WHEN** requests are listed filtered to a date range and to one mode
- **THEN** the response contains only requests meeting both conditions

### Requirement: A Workday Request Fixes the Overtime Workday Credited

The amount of overtime workday stated by a `workday` request SHALL be credited to that date's timesheet exactly as entered. The overtime ratio that governs `time_range` requests SHALL NOT be applied to it, whether the date is an ordinary working day, a day off or a public holiday.

The credited amount SHALL NOT change in response to any later change to the overtime ratio settings, to the holiday calendar, or to the date's classification. Only editing or cancelling the request itself SHALL change it.

#### Scenario: Ordinary working day
- **WHEN** a `workday` request of `05:00` is approved for an ordinary working day
- **THEN** that date's timesheet is credited five hours of overtime workday

#### Scenario: Public holiday
- **WHEN** a `workday` request of `05:00` is approved for a date that is a public holiday whose ratio is 3
- **THEN** that date's timesheet is credited five hours of overtime workday, not fifteen

#### Scenario: Day off
- **WHEN** a `workday` request of `05:00` is approved for a date that is a day off for that employee
- **THEN** that date's timesheet is credited five hours of overtime workday

#### Scenario: Ratio changed after the request was created
- **WHEN** a `workday` request of `05:00` has been approved for a date, and the overtime ratio for that kind of date is subsequently changed
- **AND** that date's timesheet is recalculated
- **THEN** the timesheet is still credited five hours of overtime workday

#### Scenario: Date reclassified as a holiday after the request was created
- **WHEN** a `workday` request of `05:00` has been approved for an ordinary working day, and that date is subsequently declared a public holiday
- **AND** that date's timesheet is recalculated
- **THEN** the timesheet is still credited five hours of overtime workday

#### Scenario: Time range request is unaffected
- **WHEN** a `time_range` request covering four hours is approved for a date whose overtime ratio is 1.5 and whose shift work ratio is 1
- **THEN** that date's timesheet is credited six hours of overtime workday
- **AND** the request behaves exactly as it did before input modes existed

### Requirement: Both Modes Combine on One Day

A date's overtime workday SHALL be the sum of the contribution of every approved overtime request attributed to it, in either mode. The contribution of a `time_range` request SHALL be its duration converted by the overtime ratio and the shift work ratio; the contribution of a `workday` request SHALL be the amount entered.

A date SHALL be marked as carrying recognised overtime when it has any contribution from either mode. A date carrying only `workday` contributions SHALL be marked the same way as one carrying only `time_range` contributions, so that payroll includes it.

The system SHALL NOT reject, warn about or cap a combination of separately submitted requests on one day. The total is whatever was entered. A single submission is constrained separately — see the Entries of One Submission Carry Distinct Dates requirement.

#### Scenario: Two workday requests on one day
- **WHEN** two `workday` requests of `03:00` and `02:00` are approved for the same employee on the same date
- **THEN** that date's timesheet is credited five hours of overtime workday

#### Scenario: Both modes on one day
- **WHEN** a `time_range` request contributing six hours of overtime workday and a `workday` request of `05:00` are both approved for the same employee on the same date
- **THEN** that date's timesheet is credited eleven hours of overtime workday

#### Scenario: A day with only workday requests reaches payroll
- **WHEN** a date has no `time_range` request and one approved `workday` request
- **THEN** that date's timesheet is marked as carrying recognised overtime
- **AND** the entered amount is included in the payroll overtime workday total

#### Scenario: Cancelling one request leaves the others
- **WHEN** one of two approved `workday` requests on a date is cancelled
- **THEN** that date's timesheet is credited only the remaining request's amount

#### Scenario: No combination is refused
- **WHEN** an admin creates several `workday` requests on one date totalling more overtime workday than the employee could plausibly have worked
- **THEN** every request is created
- **AND** the total is credited as entered

### Requirement: Overtime Duration Reported for a Workday Request

A date's overtime duration SHALL continue to be reported for display, filtering and reporting. For the `workday` portion of a date, that duration SHALL be derived from the amount entered by reversing the overtime ratio and the shift work ratio in force at the time the timesheet is calculated, so that the reported duration always reflects the current configuration.

The derived duration SHALL NOT be stored on the overtime request. A `workday` request SHALL report no overtime duration of its own.

When the overtime ratio and the shift work ratio do not permit the reversal, the derived duration SHALL be treated as zero, and the overtime workday credited SHALL be unaffected.

#### Scenario: Duration derived for a workday request
- **WHEN** a `workday` request of `05:00` is approved for a date whose overtime ratio is 1.5 and whose shift work ratio is 1
- **THEN** that date's timesheet reports an overtime duration of three hours twenty minutes
- **AND** it is credited five hours of overtime workday

#### Scenario: Derived duration follows a ratio change
- **WHEN** the date in the preceding scenario is subsequently declared a public holiday whose ratio is 3, and the timesheet is recalculated
- **THEN** that date's timesheet reports an overtime duration of one hour forty minutes
- **AND** it is still credited five hours of overtime workday

#### Scenario: Durations from both modes are added
- **WHEN** a date carries a `time_range` request of four hours and a `workday` request whose derived duration is three hours twenty minutes
- **THEN** that date's timesheet reports an overtime duration of seven hours twenty minutes

#### Scenario: The request itself reports no duration
- **WHEN** a `workday` request is retrieved
- **THEN** it reports the amount of overtime workday entered
- **AND** it reports no overtime duration

#### Scenario: Reversal is not possible
- **WHEN** a `workday` request of `05:00` is approved for a date whose shift work ratio is zero
- **THEN** that date's timesheet is credited five hours of overtime workday
- **AND** it reports an overtime duration of zero
- **AND** no error occurs during calculation

### Requirement: Overlap Checking Applies Only Between Time Range Requests

The system SHALL refuse a new `time_range` request whose interval overlaps an existing approved `time_range` request for the same employee, exactly as it does today.

A `workday` request SHALL be subject to no overlap check, and SHALL NOT be considered when checking a `time_range` request. A `time_range` request SHALL therefore never be refused because of a `workday` request, and a `workday` request SHALL never be refused because of anything.

Filtering or listing overtime requests by a date range SHALL continue to return requests of both modes.

#### Scenario: Two overlapping time range requests
- **WHEN** an admin creates a `time_range` request whose interval overlaps an existing approved `time_range` request for the same employee
- **THEN** the request is refused
- **AND** the response reports the conflicting time range

#### Scenario: Workday request on a date that already has a time range request
- **WHEN** an admin creates a `workday` request for a date on which the employee already has an approved `time_range` request
- **THEN** the request is created

#### Scenario: Time range request on a date that already has a workday request
- **WHEN** an admin creates a `time_range` request for a date on which the employee already has an approved `workday` request
- **THEN** the request is created
- **AND** it is not refused for overlapping

#### Scenario: Time range starting at midnight is not blocked by a workday request
- **WHEN** an admin creates a `time_range` request starting at midnight on a date on which the employee already has an approved `workday` request
- **THEN** the request is created

#### Scenario: Several workday requests on one date
- **WHEN** an admin creates a second `workday` request for a date on which the employee already has one
- **THEN** the request is created

#### Scenario: Listing by date range includes both modes
- **WHEN** overtime requests are listed filtered to a date range containing both a `time_range` and a `workday` request
- **THEN** both requests appear in the result

### Requirement: Minimum Recognised Overtime Applies to Both Modes

The configured minimum recognised overtime is a floor on overtime duration. The system SHALL refuse a `time_range` request whose duration falls below it, as it does today.

The system SHALL also refuse a `workday` request whose entered amount corresponds to an overtime duration below that floor. The correspondence SHALL be established from the overtime ratio and the shift work ratio applicable to the request's date and employee at the moment of submission, and the value so established SHALL be used only for this comparison and SHALL NOT be stored.

The system SHALL refuse a `workday` request whose date and employee give an overtime ratio or shift work ratio that makes the comparison impossible, rather than accepting it unchecked.

#### Scenario: Time range request below the floor
- **WHEN** an admin creates a `time_range` request shorter than the configured minimum
- **THEN** the request is refused
- **AND** the response reports that the time selected is below the minimum

#### Scenario: Workday request below the floor
- **WHEN** the minimum is 45 minutes and an admin creates a `workday` request whose entered amount corresponds to 30 minutes of overtime duration on that date
- **THEN** the request is refused
- **AND** the response reports that the amount is below the minimum

#### Scenario: Workday request above the floor
- **WHEN** the minimum is 45 minutes and an admin creates a `workday` request whose entered amount corresponds to 3 hours 20 minutes of overtime duration on that date
- **THEN** the request is created

#### Scenario: The same amount is judged against the date's own ratio
- **WHEN** the minimum is 45 minutes and an admin submits the same amount for an ordinary working day and for a public holiday whose ratio is higher
- **THEN** each entry is judged against the duration that amount corresponds to on its own date

#### Scenario: Comparison impossible
- **WHEN** an admin creates a `workday` request for a date and employee whose shift work ratio is zero
- **THEN** the request is refused
- **AND** the response reports that the request cannot be evaluated

#### Scenario: Nothing is stored from the comparison
- **WHEN** a `workday` request passes the minimum check and is created
- **THEN** the request records only the amount of overtime workday entered
- **AND** it records no overtime duration

### Requirement: Monthly Summary Reports One Overtime Duration, Counted Per Employee

The monthly summary on the overtime request screens SHALL report a single overtime duration covering both modes.

It SHALL be counted per employee: a request covering several employees contributes once for each of them. A `time_range` request SHALL contribute its own duration for each. A `workday` request SHALL contribute, for each, the duration its entered amount corresponds to under that employee's own ratios, taken as they stand when the summary is read, so the figure never goes stale.

The summary SHALL be derived from the overtime requests themselves and SHALL NOT read timesheets, so a request counts from the moment it is approved, whether or not a timesheet exists for its date.

On the manager's screen only the manager's own employees SHALL be counted, in the duration and in the count of employees; on the administrator's screen every employee a counted request covers SHALL be counted. A manager's screen reaches a request when it holds at least one of their own employees, and such a request may cover others besides; those others are not counted, so that the figures agree with the list's preview and total.

Employees who have been deleted SHALL NOT be counted, in the duration or in the count of employees.

A `workday` request whose ratios do not permit the reversal SHALL contribute nothing to the duration, and SHALL still be counted among the month's requests and employees.

The count of requests and the count of employees SHALL include requests of both modes.

#### Scenario: A request covering several employees counts for each
- **WHEN** the month contains one approved `time_range` request of four hours covering three employees
- **THEN** the summary reports twelve hours of overtime duration
- **AND** counts one request
- **AND** counts three employees

#### Scenario: Summary with both modes
- **WHEN** the month contains approved `time_range` requests totalling 320 minutes across their employees, and one approved `workday` request of `05:00` for one employee whose overtime ratio is 1.5 and shift work ratio is 1
- **THEN** the summary reports 520 minutes of overtime duration

#### Scenario: Summary with only time range requests
- **WHEN** the month contains no `workday` requests
- **THEN** the reported duration is the duration of each request counted once per employee it covers

#### Scenario: A workday request counts before its timesheet exists
- **WHEN** a `workday` request is approved for a date later in the current month for which no timesheet has been created
- **THEN** the reported duration already includes it

#### Scenario: Derived contribution follows a ratio change
- **WHEN** a `workday` request has been counted in the summary, and the overtime ratio for its date is subsequently changed
- **THEN** the next reading of the summary reflects the new ratio

#### Scenario: One request covering employees whose ratios differ
- **WHEN** one `workday` request of `05:00` is approved for three employees whose ratios differ
- **THEN** the reported duration includes a separately derived contribution for each of the three

#### Scenario: A manager's figure covers only their own employees
- **WHEN** a request covering five employees includes two who report to a given manager
- **THEN** that manager's summary counts the duration for those two only
- **AND** counts two employees

#### Scenario: The administrator's figure covers every employee
- **WHEN** the same request is viewed in the administrator's summary within its company scope
- **THEN** the duration is counted for all five
- **AND** the count of employees is five

#### Scenario: A deleted employee is not counted
- **WHEN** a request covers three employees and one of them has since been deleted
- **THEN** the duration is counted for the remaining two
- **AND** the count of employees is two

#### Scenario: A request whose ratios do not permit the reversal
- **WHEN** the month contains an approved `workday` request for an employee whose shift work ratio is zero
- **THEN** that request contributes nothing to the reported duration
- **AND** it is still counted among the month's requests and employees

#### Scenario: Counts include both modes
- **WHEN** the month contains two `time_range` requests and three `workday` requests across four employees
- **THEN** the summary counts five requests
- **AND** counts four employees

#### Scenario: Cost does not grow with the number of employees
- **WHEN** the month contains one `workday` request covering several hundred employees
- **THEN** the summary is produced in a number of database queries that does not grow with that number

### Requirement: Notifying an Employee About a Workday Request

When an overtime request is approved or cancelled, the employee SHALL be notified. The notification for a `time_range` request SHALL state its time range and date, as it does today. The notification for a `workday` request SHALL state its date and the amount of overtime workday, and SHALL NOT present a time range.

#### Scenario: Approval of a workday request
- **WHEN** a `workday` request of `05:00` is approved for an employee
- **THEN** the employee is notified of the date and of five hours of overtime workday
- **AND** the notification contains no time range

#### Scenario: Cancellation of a workday request
- **WHEN** an approved `workday` request is cancelled
- **THEN** the employee is notified of the date and of the amount cancelled
- **AND** the notification contains no time range

#### Scenario: Approval of a time range request
- **WHEN** a `time_range` request is approved
- **THEN** the employee is notified exactly as before input modes existed

### Requirement: Entries of One Submission Carry Distinct Dates

A `workday` submission SHALL be refused when two of its entries carry the same date. Nothing is gained by splitting one date across two entries of one submission — they share a title and are summed — so a repeated date is a mistake rather than an intention.

This SHALL NOT restrict separate submissions. An employee MAY accumulate any number of `workday` requests on one date, each submitted on its own.

#### Scenario: Two entries of one submission carry the same date
- **WHEN** an admin submits three `workday` entries of which two carry the same date
- **THEN** the submission is refused
- **AND** the response reports that date as repeated
- **AND** none of the three entries is created

#### Scenario: Entries of one submission carry distinct dates
- **WHEN** an admin submits three `workday` entries each carrying a different date
- **THEN** three overtime requests are created

#### Scenario: The same date across separate submissions is allowed
- **WHEN** an admin submits a `workday` entry for a date, and then submits another for the same date
- **THEN** both requests exist
- **AND** that date is credited the sum of the two amounts

### Requirement: A Refused Workday Submission Names Every Entry That Failed

When a `workday` submission is refused, the response SHALL list every entry that failed, not only the first. The whole submission is refused, so an admin shown one failure at a time would need one round trip per mistake.

Each listed entry SHALL carry the reason it failed. The response SHALL also carry a status code and a message describing the first failure, exactly as a single-entry refusal does today, so a client reading only those two fields is unaffected.

A submission of several entries for one employee SHALL name an entry by its date, which is sufficient because a submission may not repeat a date.

An entry refused for falling below the minimum recognised duration SHALL also carry the amount of overtime workday it would have to reach, expressed in minutes. That amount depends on the ratios of that employee on that date, which a client does not hold, so without it the person correcting the entry is not told what to change it to.

It SHALL be reported in minutes rather than as a formatted duration, because the client lets the person choose the unit the amount is typed in and only the client knows which one a given entry is using. Presenting the figure in that unit is the client's to do, rounding so that the value it shows is itself accepted.

A submission of one date for several employees SHALL name an entry by its employee. The date belongs to the submission and SHALL be reported once rather than on every entry.

The whole submission SHALL be refused, so no entry of a refused submission is created.

#### Scenario: Several entries of one submission fail
- **WHEN** an admin submits four `workday` entries of which the second is below the minimum recognised duration and the fourth cannot be evaluated
- **THEN** the submission is refused
- **AND** the response lists both entries by date, each with its own reason
- **AND** none of the four entries is created

#### Scenario: One entry of one submission fails
- **WHEN** an admin submits three `workday` entries of which one is below the minimum recognised duration
- **THEN** the response lists that one entry by date
- **AND** reports the amount of overtime workday that entry must reach

#### Scenario: The required amount differs by date
- **WHEN** a submission is refused for two entries below the minimum, one on an ordinary day and one on a public holiday whose ratio is higher
- **THEN** each entry reports its own required amount

#### Scenario: Each refused employee is told their own required amount
- **WHEN** a manager's submission is refused for two employees whose ratios differ
- **THEN** each reports the amount required for that employee

#### Scenario: An entry refused for another reason carries no required amount
- **WHEN** an entry is refused because its date is repeated, or because its ratios make it impossible to evaluate
- **THEN** no required amount is reported for it

#### Scenario: Several employees fail on one date
- **WHEN** a manager submits one `workday` amount for four employees and it is refused for two of them
- **THEN** the response lists both employees, each with its own reason
- **AND** reports the submission's date once
- **AND** no overtime request is created for any of the four

#### Scenario: Status code and message are unchanged
- **WHEN** a `workday` submission is refused for any reason
- **THEN** the response carries the status code and message of the first failure
- **AND** a client that reads only those two fields behaves exactly as it did before failures were listed
