Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions SPECIFICATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -1367,10 +1367,13 @@ The HR area (visible only to HR-group members) provides:
decision, and a per-manager table (decisions, median, escalations). Only leave
that went to a manager is counted, so HR-recorded absences (booked without a
decision) never flatter the figure. Escalation rate = escalated ÷ requests that
needed a decision.
needed a decision. Durations under one hour read *under an hour*, not *0 hours*.
- **Bradford Factor** — recorded sick leave scored per employee as
*spells² × days*, ranked, coloured amber/red at the conventional 500/900 review
thresholds. A well-being prompt, deliberately not shown to line managers.
*spells² × days*, ranked, against the conventional review thresholds: 500
(amber, *Review due*) and 900 (red, *Serious*). Each bar is scaled to 900, so
it fills at the serious threshold whatever the other scores are, and the level
is written next to the score, not shown by colour alone. A well-being prompt,
deliberately not shown to line managers.
- **Leave utilisation** — annual `used ÷ entitlement`, company-wide and per team,
plus a watchlist of employees with no non-sick leave in the last ~90 days
(computed from a rolling one-year window), longest-neglected first.
Expand All @@ -1380,7 +1383,7 @@ The HR area (visible only to HR-group members) provides:
the figure each person reads on their own balance. Nothing is at risk once
the date has passed, or in a year other than the current one. Teams are
grouped by the manager each employee reports to; those without a manager form
one group. All of it is HR-only — it names people and includes health-adjacent
one group, *People without a manager*. All of it is HR-only: it names people and includes health-adjacent
figures.
5. **Export:** CSV and Excel (`.xlsx`) export of raw requests and of the balances
report, with date-range and group filters (the group filter narrows to the
Expand Down Expand Up @@ -1504,9 +1507,10 @@ the SPA). All list endpoints paginate and accept filters.
**HR reporting**
- `GET /api/reports/balances` — balances report (filters).
- `GET /api/reports/trends` — aggregated stats for charts.
- `GET /api/reports/sick-leave` — sick-leave overview, every employee ranked by days
lost. Counts the leave type keyed `sick` by default; `typeId` counts another type
instead, which the *Sick leave* view exposes as a type picker. The response carries
- `GET /api/reports/sick-leave`: sick-leave overview, every employee sorted by days
lost (the view shows no rank numbers). Counts the leave type keyed `sick` by
default; `typeId` counts another type instead, which the *Sick leave* view exposes
as a type picker labelled *Leave type counted*, starting on the type keyed `sick`. The response carries
the types it aggregated, so the page can name what it is counting rather than
implying "sickness" is a fixed concept — and can say so plainly when an instance has
no matching type instead of showing a table of zeroes.
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/InsightsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ private function buildTeams(array $uids): array {
$teams[] = [
'managerUid' => $manager === '' ? null : $manager,
'name' => $manager === ''
? $this->l->t('No manager')
? $this->l->t('People without a manager')
: $this->l->t("%s's team", [$this->displayName($manager)]),
'uids' => $members,
];
Expand Down
24 changes: 24 additions & 0 deletions src/utils/bradford.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { describe, expect, it } from 'vitest'
import { bradfordLevel } from './bradford.ts'

describe('bradfordLevel', () => {
it('stays low under the review threshold', () => {
expect(bradfordLevel(0)).toBe('low')
expect(bradfordLevel(2)).toBe('low')
expect(bradfordLevel(499)).toBe('low')
})

it('asks for a review from 500', () => {
expect(bradfordLevel(500)).toBe('review')
expect(bradfordLevel(899)).toBe('review')
})

it('is serious from 900', () => {
expect(bradfordLevel(900)).toBe('serious')
expect(bradfordLevel(5000)).toBe('serious')
})
})
24 changes: 24 additions & 0 deletions src/utils/bradford.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

/** The conventional Bradford Factor score from which a review is due. */
export const BRADFORD_REVIEW = 500

/** The conventional Bradford Factor score from which the case is serious. */
export const BRADFORD_SERIOUS = 900

export type BradfordLevel = 'low' | 'review' | 'serious'

/**
* Where a Bradford Factor score stands against the review thresholds.
*
* @param score spells² × days
*/
export function bradfordLevel(score: number): BradfordLevel {
if (score >= BRADFORD_SERIOUS) {
return 'serious'
}
return score >= BRADFORD_REVIEW ? 'review' : 'low'
}
28 changes: 28 additions & 0 deletions src/utils/duration.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { describe, expect, it } from 'vitest'
import { formatHours } from './duration.ts'

describe('formatHours', () => {
it('says under an hour below one hour', () => {
expect(formatHours(0)).toBe('under an hour')
expect(formatHours(0.9)).toBe('under an hour')
})

it('counts whole hours below two days', () => {
expect(formatHours(1)).toBe('1 hour')
expect(formatHours(5.4)).toBe('5 hours')
expect(formatHours(47.9)).toBe('48 hours')
})

it('counts days from two days on', () => {
expect(formatHours(48)).toBe('2 days')
expect(formatHours(60)).toBe('2.5 days')
})

it('shows a dash when there is nothing to measure', () => {
expect(formatHours(null)).toBe('–')
})
})
26 changes: 26 additions & 0 deletions src/utils/duration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { n, t } from '@nextcloud/l10n'
import { formatNumber } from './locale.ts'

/**
* A duration: "under an hour" below one hour, in hours below two days, in days
* from there.
*
* @param h the hours, null when there is nothing to measure
*/
export function formatHours(h: number | null): string {
if (h === null || h === undefined) {
return '–'
}
if (h < 1) {
return t('absence', 'under an hour')
}
if (h < 48) {
return n('absence', '%n hour', '%n hours', Math.round(h))
}
const days = Math.round(h / 24 * 10) / 10
return n('absence', '{days} day', '{days} days', days, { days: formatNumber(days) })
}
74 changes: 41 additions & 33 deletions src/views/hr/HrInsights.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
<template v-else-if="data">
<div class="tiles">
<StatTile
:value="fmtHours(data.approval.medianHours)"
:value="formatHours(data.approval.medianHours)"
:label="t('absence', 'median time to a decision')"
:caption="t('absence', '95th percentile {p}', { p: fmtHours(data.approval.p95Hours) })">
:caption="t('absence', '95th percentile {p}', { p: formatHours(data.approval.p95Hours) })">
<template #icon>
<TimerOutline :size="20" />
</template>
Expand Down Expand Up @@ -89,7 +89,7 @@
{{ m.decided }}
</td>
<td class="num">
{{ fmtHours(m.medianHours) }}
{{ formatHours(m.medianHours) }}
</td>
<td class="num">
<span v-if="m.escalated > 0" class="pill pill--warn">{{ m.escalated }}</span>
Expand All @@ -111,6 +111,7 @@
</h3>
<p class="surface__lead">
{{ t('absence', 'Recorded sick leave scored as spells² × days, so frequent short absences weigh more heavily than one long illness. A prompt for a supportive conversation, not a verdict.') }}
{{ t('absence', 'A bar fills at {serious}: from {review} a review is due, from {serious} the case is serious.', { review: BRADFORD_REVIEW, serious: BRADFORD_SERIOUS }) }}
</p>
<table v-if="data.bradford.length" class="grid">
<thead>
Expand Down Expand Up @@ -138,10 +139,26 @@
{{ fmtDays(r.days) }}
</td>
<td class="num">
<strong>{{ r.score }}</strong>
<span class="score">
<NcChip
v-if="bradfordLevel(r.score) === 'serious'"
variant="error"
noClose
:text="t('absence', 'Serious')" />
<NcChip
v-else-if="bradfordLevel(r.score) === 'review'"
variant="warning"
noClose
:text="t('absence', 'Review due')" />
<strong>{{ r.score }}</strong>
</span>
</td>
<td class="bar">
<MeterBar :value="r.score" :max="bradfordMax" :color="scoreColor(r.score)" />
<MeterBar
:value="r.score"
:max="BRADFORD_SERIOUS"
:color="scoreColor(r.score)"
:ariaLabel="t('absence', 'Score {score} of {serious}', { score: r.score, serious: BRADFORD_SERIOUS })" />
</td>
</tr>
</tbody>
Expand Down Expand Up @@ -213,7 +230,7 @@
{{ fmtDays(team.outstanding) }}
</td>
<td class="bar">
<MeterBar :value="team.outstanding" :max="liabilityMax" color="var(--color-warning)" />
<MeterBar :value="team.outstanding" :max="liabilityMax" color="var(--color-element-warning)" />
</td>
</tr>
</tbody>
Expand All @@ -229,6 +246,7 @@ import type { Insights, NeglectedRow } from '../../types/index.ts'
import { showError } from '@nextcloud/dialogs'
import { n, t } from '@nextcloud/l10n'
import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
import NcChip from '@nextcloud/vue/components/NcChip'
import ArrowUpBoldCircleOutline from 'vue-material-design-icons/ArrowUpBoldCircleOutline.vue'
import CashMultiple from 'vue-material-design-icons/CashMultiple.vue'
import Leaf from 'vue-material-design-icons/Leaf.vue'
Expand All @@ -238,6 +256,8 @@ import MeterBar from '../../components/MeterBar.vue'
import SkeletonList from '../../components/SkeletonList.vue'
import StatTile from '../../components/StatTile.vue'
import api from '../../services/api.ts'
import { BRADFORD_REVIEW, BRADFORD_SERIOUS, bradfordLevel } from '../../utils/bradford.ts'
import { formatHours } from '../../utils/duration.ts'
import { formatNumber, locale } from '../../utils/locale.ts'

const now = new Date().getFullYear()
Expand All @@ -248,8 +268,6 @@ const year = ref(now)
const yearOptions = [now + 1, now, now - 1, now - 2, now - 3]
const data = ref<Insights | null>(null)

const bradfordMax = computed<number>(() => Math.max(1, ...(data.value?.bradford ?? []).map((r) => r.score)))

const liabilityMax = computed<number>(() => Math.max(1, ...(data.value?.liability.perTeam ?? []).map((r) => r.outstanding)))

const expiryCaption = computed<string>(() => {
Expand Down Expand Up @@ -295,22 +313,6 @@ async function reload(): Promise<void> {
}
}

/**
* A duration in hours below two days, in days from there.
*
* @param h the hours, null when there is nothing to measure
*/
function fmtHours(h: number | null): string {
if (h === null || h === undefined) {
return '–'
}
if (h < 48) {
return n('absence', '%n hour', '%n hours', Math.round(h))
}
const days = Math.round(h / 24 * 10) / 10
return n('absence', '{days} day', '{days} days', days, { days: formatNumber(days) })
}

/**
* A share as a whole percentage.
*
Expand Down Expand Up @@ -347,14 +349,14 @@ function neglectedLabel(p: NeglectedRow): string {
* @param score the score
*/
function scoreColor(score: number): string {
// The recognised Bradford thresholds: 500 = review, 900 = serious.
if (score >= 900) {
return 'var(--color-error, #d65a5a)'
}
if (score >= 500) {
return 'var(--color-warning, #c98a1e)'
switch (bradfordLevel(score)) {
case 'serious':
return 'var(--color-element-error)'
case 'review':
return 'var(--color-element-warning)'
default:
return 'var(--color-primary-element)'
}
return 'var(--color-primary-element)'
}

/**
Expand All @@ -365,9 +367,9 @@ function scoreColor(score: number): string {
function rateColor(rate: number): string {
// Low utilisation is the thing to notice, so it reads warm.
if (rate < 0.4) {
return 'var(--color-warning, #c98a1e)'
return 'var(--color-element-warning)'
}
return 'var(--color-success, #4caf50)'
return 'var(--color-element-success)'
}
</script>

Expand Down Expand Up @@ -466,6 +468,12 @@ function rateColor(rate: number): string {
color: var(--color-text-maxcontrast);
}

.score {
display: inline-flex;
align-items: center;
gap: calc(var(--default-grid-baseline) * 2);
}

.watchlist {
margin-top: 18px;

Expand Down
22 changes: 6 additions & 16 deletions src/views/hr/HrSickLeave.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
v-model="type"
:options="typeOptions"
label="label"
:placeholder="t('absence', 'Sick leave (default)')"
:aria-label-combobox="t('absence', 'Leave type counted')">
:inputLabel="t('absence', 'Leave type counted')"
:clearable="false">
<template #option="{ icon, label }">
<span class="opt"><span class="opt__icon">{{ icon }}</span>{{ label }}</span>
</template>
Expand Down Expand Up @@ -98,9 +98,6 @@
<table class="tbl">
<thead>
<tr>
<th class="num rank">
#
</th>
<th>{{ t('absence', 'Employee') }}</th>
<th class="num">
{{ t('absence', 'Days') }}
Expand All @@ -119,14 +116,11 @@
</thead>
<tbody>
<tr
v-for="(row, index) in filtered"
v-for="row in filtered"
:key="row.employeeUid"
class="row"
:class="{ 'row--drillable': row.days > 0 }"
@click="openRecords(row)">
<td class="num rank">
{{ index + 1 }}
</td>
<td>
<div class="emp">
<NcAvatar
Expand Down Expand Up @@ -230,8 +224,9 @@ const totals = ref<SickLeaveTotals>({ employees: 0, affected: 0, days: 0, episod
// NcTextField types what it emits as string or number
const search = ref<string | number>('')
const onlyAffected = ref(true)
// null means "let the server pick" — it counts the type keyed "sick".
const type = ref<LeaveType | null>(null)
// The type keyed "sick" is what the server counts without a type. null when
// there is none, and the server then finds nothing to count either.
const type = ref<LeaveType | null>(leaveTypesStore.leaveTypes.find((leaveType) => leaveType.key === 'sick') ?? null)
const year = ref(y)
const years = [y - 2, y - 1, y, y + 1]

Expand Down Expand Up @@ -370,11 +365,6 @@ async function reload(): Promise<void> {
gap: calc(var(--default-grid-baseline, 4px) * 4);
}

.rank {
width: 3em;
color: var(--color-text-maxcontrast);
}

.strong {
font-weight: 600;
}
Expand Down
3 changes: 2 additions & 1 deletion tests/Unit/Service/InsightsServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,9 @@ public function testUtilizationAggregatesAndFlagsTheNeglected(): void {
self::assertSame(25.0, $util['company']['used']);
self::assertSame(81.0, $util['company']['entitlement']);
self::assertSame(0.309, $util['company']['rate']);
// Two teams, lowest utilisation first (carol's "no manager" team at 0%).
// Two teams, lowest utilisation first (carol, who has no manager, at 0%).
self::assertSame(0.0, $util['perTeam'][0]['rate']);
self::assertSame('People without a manager', $util['perTeam'][0]['name']);
// carol never took non-sick leave in the window → top of the watchlist.
self::assertSame('carol', $util['neglected'][0]['employeeUid']);
self::assertNull($util['neglected'][0]['daysSince']);
Expand Down
Loading