Give a position a cost centre

There was none anywhere in the model, so no personnel-cost figure could
be produced at all, and an open position could not say whose budget it
would charge — which is the first question asked about a vacancy.

It hangs on the position, not on the person: the seat costs money even
when nobody sits on it. That is exactly the vacancy case. And not on the
org unit either, although it usually follows from one — a single seat
can be charged elsewhere (project, shared function) without the unit
moving.

As its own dated assignment table rather than a column, because
reassigning is an event with a date. Last year's costs have to stay
where they were incurred; as a column, every change would silently
rewrite every past report. Half-open [valid_from, valid_to), like
position_assignments and om_positions — in SAP OM this is A011.

25 cost centres seeded from the org tree: one per company, division and
department, with teams charging to their department, because a team is a
span of control and not a budget. All 823 positions were assigned from
their own start date, none left over. The number is the first five digits
of the org number, so it can be traced rather than looked up.

Reassignment refuses three things, each checked: the same cost centre
again, a switch on the day the current one started (that period would
never have been in force, and the range constraint says so), and a date
before the position exists.

Verified against the real data, which turned up a defect worth keeping:
a position that starts in the future is charged only from its start, so
asked about today it had no cost centre — and future positions are
exactly what the vacancy list is for. It is now read at the position's
own start date.

Two audit entries from the probe could not be deleted through the
application (the log has no delete policy — correctly), so I removed
them with the admin connection.

Still open, and the reason this is only the first of the three fields I
proposed: location and planned FTE.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-16 19:57:09 +02:00
parent 3a4f44318c
commit e30923e781
13 changed files with 582 additions and 25 deletions

View File

@@ -1,3 +1,4 @@
import { kontierungAm, kontierungenAbfrage, type KontierungsZeile } from "./cost-centers";
import type { Tx } from "./db";
import { jsonArrayFrom } from "./db/json";
import { fmtName, todayIso } from "./format";
@@ -31,6 +32,14 @@ export type OpenPositionResolved = {
orgLabel: string;
/** Seit wann die Stelle unbesetzt ist: Ende der letzten Besetzung, sonst ihr Beginn. */
vacantSince: string;
/**
* Wessen Budget die Stelle belastet.
*
* Der Grund, warum die Kostenstelle an der Planstelle hängt und nicht an der
* Person: hier gibt es keine Person, und trotzdem — gerade deshalb — ist die
* Frage offen, was diese Stelle kostet und wer sie bezahlt.
*/
kostenstelle: { code: string; name: string } | null;
};
/**
@@ -120,7 +129,7 @@ export async function resolveOpenPositions(
)
);
const { ended, chiefs } = await tx
const { ended, chiefs, costRows } = await tx
.selectNoFrom((eb) => [
jsonArrayFrom(
eb
@@ -129,6 +138,7 @@ export async function resolveOpenPositions(
.where("position_id", "in", positionIds)
.where("valid_to", "is not", null)
).as("ended"),
jsonArrayFrom(kontierungenAbfrage(eb, positionIds)).as("costRows"),
jsonArrayFrom(
eb
.selectFrom("om_positions as p")
@@ -168,6 +178,10 @@ export async function resolveOpenPositions(
managerName: managerUnit ? (chiefNameByUnit.get(managerUnit) ?? null) : null,
orgLabel: breadcrumbLabel(orgMaps, p.org_unit_id),
vacantSince: lastEndByPosition.get(p.id) ?? p.valid_from,
// Nicht zum heutigen Tag, sondern zu dem, an dem die Stelle besteht:
// eine künftige Planstelle wird erst mit ihrem Beginn kontiert, hätte
// heute also keine Kostenstelle — obwohl gerade sie geplant wird.
kostenstelle: kontierungAm(costRows as KontierungsZeile[], p.id, p.valid_from > asOf ? p.valid_from : asOf),
};
});
}