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
11 changes: 7 additions & 4 deletions SPECIFICATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -1325,11 +1325,14 @@ The HR area (visible only to HR-group members) provides:
1. **Employees list** (`#/hr/employees`, `GET /api/employees?year`, HR-only):
everyone the directory counts as an employee (§2.2), one row each, with their
region code (§7.2), working days and contract percentage of the period in force
today (§6.4), start date (the year, or the day when it falls in the selected
year) and end date, manager (§2.1), and for the selected year the annual days
today (§6.4), start date and end date (both as the locale's date, the same
format on every row), manager (§2.1), and for the selected year the annual days
(§6.4), taken and available, and sick days. Missing data is flagged rather than left
blank: *No region code*, *No manager* (their requests go straight to HR) and *No
contract data*. Filters: all, missing data (any of the three), part-time (fewer
blank: *No region code*, *No contract data* (no working pattern) and *No start
date*. Having no manager is not missing data: the person at the top and often HR
have none, and their requests go straight to HR, so the cell reads *No manager* in
muted text. The subtitle names the employees group by its display name. Filters:
all, missing data (any of the three), part-time (fewer
than five weekdays or under 100 %), and starting or leaving in the year; a search
by name or user id; rows shown 50 at a time. Each row opens the person's profile,
and its menu edits each counting entitlement with its history (§6.1). *Edit as
Expand Down
17 changes: 11 additions & 6 deletions lib/Service/EmployeeListService.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,22 @@
namespace OCA\Absence\Service;

use OCP\App\IAppManager;
use OCP\IGroupManager;
use OCP\IUserManager;

/**
* The HR employees list (§13): everyone with their region code, contract,
* manager, annual days and sick days for a year, and what is missing. Loaded
* manager, annual days and sick days for a year, and what HR still has to
* fill in: the region code, the working pattern and the start date. Loaded
* in a fixed number of queries, however many people there are.
*
* @psalm-import-type Contract from EmployeeService
* @psalm-import-type Period from EmployeeService
*/
class EmployeeListService {
public const MISSING_REGION = 'region';
public const MISSING_MANAGER = 'manager';
public const MISSING_CONTRACT = 'contract';
public const MISSING_START = 'start';

private const ANNUAL = 'annual';
private const FULL_WEEK = 5;
Expand All @@ -37,20 +39,23 @@ public function __construct(
private ConfigService $config,
private ReportService $reports,
private IUserManager $userManager,
private IGroupManager $groupManager,
private IAppManager $appManager,
private ClockService $clock,
private HolidayService $holidays,
) {
}

/**
* @return array{year: int, employeesGroup: string, contacts: bool, rows: list<array<string, mixed>>}
* @return array{year: int, employeesGroup: string, employeesGroupName: string, contacts: bool, rows: list<array<string, mixed>>}
*/
public function list(?int $year): array {
$year ??= $this->clock->userYear();
$group = $this->config->getEmployeesGroup();
return [
'year' => $year,
'employeesGroup' => $this->config->getEmployeesGroup(),
'employeesGroup' => $group,
'employeesGroupName' => $group === '' ? '' : ($this->groupManager->get($group)?->getDisplayName() ?? $group),
'contacts' => $this->appManager->isEnabledForUser('contacts'),
'rows' => $this->rows($this->directory->listAll(), $year),
];
Expand Down Expand Up @@ -86,8 +91,8 @@ public function rows(array $uids, int $year): array {
$current = self::currentPeriod($contract, $today);
$missing = array_keys(array_filter([
self::MISSING_REGION => $this->holidays->needsRegion($region),
self::MISSING_MANAGER => $managerUid === null,
self::MISSING_CONTRACT => $contract['start'] === null && $contract['end'] === null && $contract['periods'] === [],
self::MISSING_CONTRACT => $contract['periods'] === [],
self::MISSING_START => $contract['start'] === null,
]));
$rows[] = [
'uid' => $uid,
Expand Down
6 changes: 4 additions & 2 deletions src/types/employees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ export interface Profile {
history: ProfileChange[] | null
}

/** What HR still has to complete for an employee. */
export type EmployeeMissing = 'region' | 'manager' | 'contract'
/** What HR still has to complete for an employee: a person without a manager lacks nothing, their requests go to HR. */
export type EmployeeMissing = 'region' | 'contract' | 'start'

/** One row of HR's employees list, from EmployeeListService::rows(). */
export interface EmployeeRow {
Expand Down Expand Up @@ -159,6 +159,8 @@ export interface EmployeeList {
year: number
/** Gid of the employees group, '' when none is configured. */
employeesGroup: string
/** Display name of the employees group, '' when none is configured. */
employeesGroupName: string
/** Whether the Contacts app is enabled for the viewer. */
contacts: boolean
rows: EmployeeRow[]
Expand Down
42 changes: 21 additions & 21 deletions src/views/hr/HrEmployees.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
{{ t('absence', 'Employees') }}
</h2>
<p class="employees__sub">
{{ employeesGroup
? t('absence', 'Members of the group {group}, {year}', { group: employeesGroup, year }, undefined, { escape: false, sanitize: false })
{{ employeesGroupName
? t('absence', 'Members of the group {group}, {year}', { group: employeesGroupName, year }, undefined, { escape: false, sanitize: false })
: t('absence', 'Everyone except guest accounts, {year}', { year }) }}
</p>
</div>
Expand Down Expand Up @@ -150,7 +150,14 @@
</template>
</td>
<td>
{{ since(row.contract.start) }}
<template v-if="row.contract.start">
{{ formatDate(row.contract.start) }}
</template>
<NcChip
v-else
variant="warning"
noClose
:text="t('absence', 'No start date')" />
<span v-if="row.contract.end" class="employees__muted">
{{ t('absence', 'until {date}', { date: formatDate(row.contract.end) }) }}
</span>
Expand All @@ -159,11 +166,12 @@
<template v-if="row.manager">
{{ row.manager.displayName }}
</template>
<NcChip
<span
v-else
variant="warning"
noClose
:text="t('absence', 'No manager')" />
class="employees__none"
:title="t('absence', 'No manager, requests go to HR')">
{{ t('absence', 'No manager') }}
</span>
</td>
<td class="num">
{{ fmt(row.annual?.entitlement) }}
Expand Down Expand Up @@ -291,7 +299,7 @@ const currentYear = new Date().getFullYear()

const loading = ref(true)
const rows = shallowRef<EmployeeRow[]>([])
const employeesGroup = ref('')
const employeesGroupName = ref('')
const contacts = ref(false)
const search = ref('')
const filter = ref<FilterId>('all')
Expand Down Expand Up @@ -354,18 +362,6 @@ function fmt(v: number | null | undefined): string {
return v === null || v === undefined ? '' : formatNumber(v)
}

/**
* The year someone started, or the day when it is in the selected year.
*
* @param start YYYY-MM-DD
*/
function since(start: string | null): string {
if (!start) {
return ''
}
return Number(start.slice(0, 4)) === year.value ? formatDate(start) : start.slice(0, 4)
}

/**
* Loads the employees of the selected year.
*/
Expand All @@ -378,7 +374,7 @@ async function reload(): Promise<void> {
return
}
rows.value = list.rows
employeesGroup.value = list.employeesGroup
employeesGroupName.value = list.employeesGroupName
contacts.value = list.contacts
} catch (e) {
if (isLatest()) {
Expand Down Expand Up @@ -439,6 +435,10 @@ async function onSaved(): Promise<void> {
gap: 10px;
}

&__none {
color: var(--color-text-maxcontrast);
}

&__muted,
&__note {
color: var(--color-text-maxcontrast);
Expand Down
31 changes: 28 additions & 3 deletions tests/Integration/EmployeeListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,22 @@ public function testRowsSayWhatIsMissingAndWhoWorksPartTime(): void {
self::assertFalse($this->row(self::PART_TIME, self::YEAR + 1)['startsOrLeaves']);

$bare = $this->row(self::BARE);
self::assertSame([EmployeeListService::MISSING_REGION, EmployeeListService::MISSING_MANAGER, EmployeeListService::MISSING_CONTRACT], $bare['missing']);
self::assertSame([EmployeeListService::MISSING_REGION, EmployeeListService::MISSING_CONTRACT, EmployeeListService::MISSING_START], $bare['missing']);
self::assertFalse($bare['partTime']);
self::assertNull($bare['manager']);
self::assertNull($bare['manager'], 'no manager is not missing data');

// A start date without working days still lacks the contract, and the other way round
$this->fresh(EmployeeService::class)->saveContract(self::BARE, '2020-01-01', null, [], self::HR);
self::assertSame([EmployeeListService::MISSING_REGION, EmployeeListService::MISSING_CONTRACT], $this->row(self::BARE)['missing']);
$this->fresh(EmployeeService::class)->saveContract(self::BARE, null, null, [
['from' => '2020-01-01', 'weekdays' => [1, 2, 3, 4, 5], 'percent' => 100],
], self::HR);
self::assertSame([EmployeeListService::MISSING_REGION, EmployeeListService::MISSING_START], $this->row(self::BARE)['missing']);

// Five days at full time from the start, ending next year
$this->contract(self::BARE, [1, 2, 3, 4, 5], 100);
$bare = $this->row(self::BARE);
self::assertNotContains(EmployeeListService::MISSING_CONTRACT, $bare['missing']);
self::assertSame([EmployeeListService::MISSING_REGION], $bare['missing']);
self::assertFalse($bare['partTime']);
self::assertFalse($bare['startsOrLeaves']);
self::assertTrue($this->row(self::BARE, self::YEAR + 1)['startsOrLeaves']);
Expand All @@ -131,6 +139,23 @@ public function testRowsSayWhatIsMissingAndWhoWorksPartTime(): void {
self::assertFalse($this->row(self::BARE)['partTime'], 'five days, no percentage');
}

public function testTheListNamesTheEmployeesGroupByItsDisplayName(): void {
$groups = Server::get(IGroupManager::class);
$group = $groups->createGroup('itest-emplist-staff');
$group->setDisplayName('Itest Staff');
$group->addUser(Server::get(IUserManager::class)->get(self::PART_TIME));
$appConfig = Server::get(IAppConfig::class);
$appConfig->setValueString(ConfigService::APP_ID, ConfigLexicon::KEY_EMPLOYEES_GROUP, 'itest-emplist-staff');
try {
$list = $this->fresh(EmployeeListService::class)->list(self::YEAR);
self::assertSame('itest-emplist-staff', $list['employeesGroup']);
self::assertSame('Itest Staff', $list['employeesGroupName']);
} finally {
$appConfig->deleteKey(ConfigService::APP_ID, ConfigLexicon::KEY_EMPLOYEES_GROUP);
$group->delete();
}
}

public function testACountryWithRegionalHolidaysNeedsItsRegion(): void {
$holidays = Server::get(HolidayService::class);
$holiday = $holidays->create('2027-01-06', 'ZZ-T1', 'itest Region day');
Expand Down
Loading