Berichte: Kostenstelle als Filter und als Gruppierung
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:
@@ -1,3 +1,4 @@
|
||||
import { loadKontierungen } from "./cost-centers";
|
||||
import type { Tx } from "./db";
|
||||
import { derivedStatusFilter } from "./employee-status-filter";
|
||||
import { fmtName, todayIso } from "./format";
|
||||
@@ -38,6 +39,7 @@ export function exportParameter(params: URLSearchParams): ExportParameter {
|
||||
filters: {
|
||||
division: params.get("division") ?? undefined,
|
||||
location: params.get("location") ?? undefined,
|
||||
kostenstelle: params.get("kostenstelle") ?? undefined,
|
||||
status: params.get("status") ?? undefined,
|
||||
criteria: parseCriteria((k) => params.get(k)),
|
||||
},
|
||||
@@ -86,7 +88,7 @@ export async function ladeExportMitarbeiter(
|
||||
return applyCriteria(q, criteria);
|
||||
}
|
||||
|
||||
const [employees, lookupResult, allEmployees, dependentsCounts, placements, lines, hrKonten, kontakte] = await Promise.all([
|
||||
const [employees, lookupResult, allEmployees, dependentsCounts, placements, lines, hrKonten, kontakte, kontierung] = await Promise.all([
|
||||
employeeQuery().execute(),
|
||||
loadOrgLookups(tx),
|
||||
// Absichtlich schmal: die Liste umfasst **alle** Personen, nicht nur die
|
||||
@@ -103,6 +105,9 @@ export async function ladeExportMitarbeiter(
|
||||
.orderBy("employee_id")
|
||||
.orderBy("created_at")
|
||||
.execute(),
|
||||
// Nur für den Filter nach Kostenstelle — wie im Bericht die Kontierung
|
||||
// der Planstelle zum Stichtag.
|
||||
filters.kostenstelle ? loadKontierungen(tx, { asOf: stichtag }) : Promise.resolve(null),
|
||||
]);
|
||||
const notfallkontakte = new Map<string, { name: string; phone: string; relation: string | null }[]>();
|
||||
for (const k of kontakte) {
|
||||
@@ -121,6 +126,7 @@ export async function ladeExportMitarbeiter(
|
||||
const orgUnitId = placement?.current ? placement.orgUnitId : null;
|
||||
if (allowedUnits && (!orgUnitId || !allowedUnits.has(orgUnitId))) return [];
|
||||
if (!passtImSpeicher({ work_days: e.work_days, dependentsCount: dependentsCounts.get(e.id) ?? 0 }, criteria)) return [];
|
||||
if (kontierung && (!placement?.current || kontierung.get(placement.positionId)?.id !== filters.kostenstelle)) return [];
|
||||
return [
|
||||
{
|
||||
...e,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -32,6 +32,7 @@ export type GroupDimension =
|
||||
| "c_level"
|
||||
| "has_dependents"
|
||||
| "teilzeit_art"
|
||||
| "kostenstelle"
|
||||
| "weekday";
|
||||
|
||||
/**
|
||||
@@ -90,6 +91,7 @@ export const GROUP_LABELS: Record<GroupDimension, string> = {
|
||||
c_level: "C-Level",
|
||||
has_dependents: "Hat Angehörige",
|
||||
teilzeit_art: "Teilzeitvariante",
|
||||
kostenstelle: "Kostenstelle",
|
||||
weekday: "Wochentag",
|
||||
};
|
||||
|
||||
@@ -137,6 +139,12 @@ export type ReportEmployee = {
|
||||
is_laterale_fuehrung: boolean;
|
||||
is_c_level: boolean;
|
||||
teilzeit_art: string | null;
|
||||
/**
|
||||
* Die Kostenstelle der Planstelle zum Stichtag, als „Nummer · Bezeichnung";
|
||||
* null ohne Planstelle oder ohne Kontierung. Optional, damit Testbestände
|
||||
* ohne die Angabe gültig bleiben.
|
||||
*/
|
||||
kostenstelle?: string | null;
|
||||
dependents_count: number;
|
||||
/**
|
||||
* Der Name der zuständigen HR — beim Laden aufgelöst, weil der Bericht
|
||||
@@ -262,6 +270,10 @@ export function groupKeyFor(e: ReportEmployee, dim: GroupDimension, lookups: Org
|
||||
case "teilzeit_art":
|
||||
// „Keine" statt „–": die Antwort ist hier eine Aussage, kein Fehlen.
|
||||
return e.teilzeit_art ?? "Keine";
|
||||
case "kostenstelle":
|
||||
// Eine eigene Gruppe: Planstellen ohne Kontierung sind genau die, nach
|
||||
// denen man hier sucht.
|
||||
return e.kostenstelle ?? "Ohne Kostenstelle";
|
||||
case "weekday":
|
||||
// Not a strict partition — see groupKeysFor, which aggregateReport
|
||||
// actually uses. This single-key fallback only covers a direct
|
||||
|
||||
Reference in New Issue
Block a user