Berichte: Kostenstelle als Filter und als Gruppierung
All checks were successful
CI / Lint, Typen, Tests, Build (push) Successful in 12m3s
CI / Ausrollen (push) Successful in 11s
CI / Migrationen auf leerer Datenbank (push) Successful in 10m40s

Im Bestand laesst sich nach Kostenstelle filtern ("Alle Kostenstellen")
und gruppieren ("Kostenstelle", Planstellen ohne Kontierung als eigene
Gruppe). Gemeint ist die Kontierung der Planstelle, auf der jemand am
Stichtag sitzt. Der Filter gilt auch fuer die Exporte dieser Seite.

Geprueft: lint, tsc, 950 Tests, Uebergabe-Waechter
This commit is contained in:
2026-10-20 16:08:02 +02:00
parent 0294c792a4
commit ae4918fc6d
7 changed files with 70 additions and 6 deletions

View File

@@ -2,6 +2,7 @@ import type { SelectQueryBuilder } from "kysely";
import type { Schema } from "./db/schema";
import type { Tx } from "./db";
import { ancestorsOf, loadOrgMaps, subtreeOf, type OrgMaps } from "./org";
import { loadKontierungen } from "./cost-centers";
import { loadPlacements } from "./placement";
import type { Austrittsart } from "./types";
import { LEERE_CRITERIA, passtImSpeicher, type Criteria } from "./report-criteria";
@@ -40,6 +41,8 @@ export type ReportFilters = {
/** Id einer Organisationseinheit; wirkt auf die Einheit *und alles darunter*. */
division?: string;
location?: string;
/** Id einer Kostenstelle; gemeint ist die Kontierung der Planstelle zum Stichtag. */
kostenstelle?: string;
status?: string;
/** Alles Weitere — siehe lib/report-criteria.ts. */
criteria?: Criteria;
@@ -235,12 +238,15 @@ export async function loadSnapshotEmployees(tx: Tx, filters: SnapshotFilters): P
return applyCriteria(q, filters.criteria ?? LEERE_CRITERIA);
}
const [data, dependentsCounts, placements, orgMaps, hrNamen] = await Promise.all([
const [data, dependentsCounts, placements, orgMaps, hrNamen, kontierung] = await Promise.all([
snapshotQuery().execute(),
loadDependentsCounts(tx),
loadPlacements(tx, { asOf }),
filters.division ? loadOrgMaps(tx) : Promise.resolve(null),
loadHrNamen(tx),
// Die Kostenstelle hängt an der Planstelle, nicht an der Person: gelesen
// wird die Kontierung der Planstelle, auf der jemand am Stichtag sitzt.
loadKontierungen(tx, { asOf }),
]);
// Der Bereichsfilter meint den ganzen Teilbaum: „Produktion" schliesst
@@ -257,8 +263,11 @@ export async function loadSnapshotEmployees(tx: Tx, filters: SnapshotFilters): P
const orgUnitId = placement?.current ? placement.orgUnitId : null;
if (allowedUnits && (!orgUnitId || !allowedUnits.has(orgUnitId))) continue;
if (!passtImSpeicher({ work_days: e.work_days, dependentsCount: dependentsCounts.get(e.id) ?? 0 }, criteria)) continue;
const kst = placement?.current ? (kontierung.get(placement.positionId) ?? null) : null;
if (filters.kostenstelle && kst?.id !== filters.kostenstelle) continue;
withDerivedStatus.push({
kostenstelle: kst ? `${kst.code} · ${kst.name}` : null,
id: e.id,
first_name: e.first_name,
last_name: e.last_name,