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:
@@ -34,6 +34,8 @@ type EmployeeDetailProps = {
|
||||
employee: EmployeeRow;
|
||||
placement: PlacementInfo | null;
|
||||
breadcrumb: string;
|
||||
/** Die Kostenstelle der laufenden Planstellenbesetzung. */
|
||||
kostenstelle: { code: string; name: string } | null;
|
||||
manager: MiniEmployee | null;
|
||||
/** Nur gesetzt, wenn die zuständige Leitung abwesend ist und vertreten wird. */
|
||||
formalManager: MiniEmployee | null;
|
||||
@@ -49,7 +51,7 @@ type PanelType = "transfer" | "promote" | "karenz" | "daten" | "terminate" | "re
|
||||
const TABS = ["Stammdaten", "Vertrag", "Organisation", "Historie", "HR-Notizen"] as const;
|
||||
|
||||
export function EmployeeDetail(props: EmployeeDetailProps) {
|
||||
const { employee, placement, breadcrumb, manager, formalManager, directReports, history, dependents, notes, locations, openPositions } = props;
|
||||
const { employee, placement, breadcrumb, kostenstelle, manager, formalManager, directReports, history, dependents, notes, locations, openPositions } = props;
|
||||
const [tab, setTab] = useState<(typeof TABS)[number]>("Stammdaten");
|
||||
const [panel, setPanel] = useState<PanelType>(null);
|
||||
|
||||
@@ -159,6 +161,7 @@ export function EmployeeDetail(props: EmployeeDetailProps) {
|
||||
formalManager={formalManager}
|
||||
directReports={directReports}
|
||||
breadcrumb={breadcrumb}
|
||||
kostenstelle={kostenstelle}
|
||||
/>
|
||||
)}
|
||||
{tab === "Historie" && <HistorieTab history={history} employeeId={employee.id} />}
|
||||
|
||||
@@ -13,15 +13,39 @@ type OrganisationTabProps = {
|
||||
formalManager: MiniEmployee | null;
|
||||
directReports: MiniEmployee[];
|
||||
breadcrumb: string;
|
||||
/**
|
||||
* Die Kostenstelle der Planstelle, auf der die Person heute sitzt — nicht
|
||||
* ihre eigene: sie kontiert dorthin, wo ihr Sitz kontiert ist. Fehlt sie,
|
||||
* hat die Person keine laufende Besetzung (geplanter Eintritt, Austritt).
|
||||
*/
|
||||
kostenstelle: { code: string; name: string } | null;
|
||||
};
|
||||
|
||||
export function OrganisationTab({ employeeId, manager, formalManager, directReports, breadcrumb }: OrganisationTabProps) {
|
||||
export function OrganisationTab({
|
||||
employeeId,
|
||||
manager,
|
||||
formalManager,
|
||||
directReports,
|
||||
breadcrumb,
|
||||
kostenstelle,
|
||||
}: OrganisationTabProps) {
|
||||
return (
|
||||
<div className="flex flex-col gap-6">
|
||||
<div className="flex flex-wrap items-start justify-between gap-3">
|
||||
<div>
|
||||
<h3 className="text-xs font-semibold uppercase tracking-wide text-ink-muted">Organisationseinheit</h3>
|
||||
<p className="mt-1 text-sm text-ink">{breadcrumb}</p>
|
||||
<h3 className="mt-4 text-xs font-semibold uppercase tracking-wide text-ink-muted">Kostenstelle</h3>
|
||||
<p className="mt-1 text-sm text-ink">
|
||||
{kostenstelle ? (
|
||||
<>
|
||||
<span className="font-semibold tabular-nums">{kostenstelle.code}</span>
|
||||
<span className="text-ink-body"> · {kostenstelle.name}</span>
|
||||
</>
|
||||
) : (
|
||||
<span className="text-ink-muted">Keine laufende Planstellenbesetzung</span>
|
||||
)}
|
||||
</p>
|
||||
</div>
|
||||
{/* ?focus= drives the same highlight/auto-expand path the org chart
|
||||
search already uses, so the person is unfolded and centred on
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { updatePosition } from "@/actions/positions";
|
||||
import { setPositionCostCenter, updatePosition } from "@/actions/positions";
|
||||
import { Button } from "@/components/ui/Button";
|
||||
import { SelectField, TextField } from "@/components/ui/Field";
|
||||
import { Modal } from "@/components/ui/Modal";
|
||||
@@ -29,10 +29,15 @@ import type { UnitOption } from "./CreatePositionModal";
|
||||
export function EditPositionModal({
|
||||
position,
|
||||
units,
|
||||
kostenstellen,
|
||||
heute,
|
||||
onClose,
|
||||
}: {
|
||||
position: OpenPositionResolved;
|
||||
units: UnitOption[];
|
||||
kostenstellen: { id: string; code: string; name: string }[];
|
||||
/** Vom Server, nicht aus new Date(): sonst rechnet der Browser mit seiner Zone. */
|
||||
heute: string;
|
||||
onClose: () => void;
|
||||
}) {
|
||||
const { showToast } = useToast();
|
||||
@@ -42,8 +47,18 @@ export function EditPositionModal({
|
||||
const [isChief, setIsChief] = useState(position.is_chief);
|
||||
const [validFrom, setValidFrom] = useState(position.valid_from);
|
||||
const [validTo, setValidTo] = useState(position.valid_to ?? "");
|
||||
// Die Kontierung ist ein eigener Vorgang mit eigenem Stichtag, kein Feld
|
||||
// unter anderen: die laufende wird beendet, die neue beginnt. Deshalb steht
|
||||
// hier ein Datum daneben und kein stilles Überschreiben.
|
||||
const [kostenstelleId, setKostenstelleId] = useState(
|
||||
kostenstellen.find((k) => k.code === position.kostenstelle?.code)?.id ?? ""
|
||||
);
|
||||
const [kostenstelleAb, setKostenstelleAb] = useState(heute);
|
||||
const [pending, setPending] = useState(false);
|
||||
|
||||
const kostenstelleGeaendert =
|
||||
kostenstelleId !== "" && kostenstellen.find((k) => k.id === kostenstelleId)?.code !== position.kostenstelle?.code;
|
||||
|
||||
const unit = units.find((u) => u.id === orgUnitId);
|
||||
// Die eigene Leitung zählt nicht als Hindernis für sich selbst.
|
||||
const chiefTaken = Boolean(unit?.hasChief) && !(position.is_chief && orgUnitId === position.org_unit_id);
|
||||
@@ -62,9 +77,26 @@ export function EditPositionModal({
|
||||
valid_from: validFrom,
|
||||
valid_to: validTo || null,
|
||||
});
|
||||
if (result.success && kostenstelleGeaendert) {
|
||||
// Nacheinander, nicht gemeinsam: die Umkontierung ist ein eigener
|
||||
// Vorgang mit eigenem Stichtag und eigenem Protokolleintrag. Schlägt sie
|
||||
// fehl, steht die übrige Änderung trotzdem — und die Meldung sagt, was
|
||||
// offen blieb, statt beides stillschweigend zu verwerfen.
|
||||
const kosten = await setPositionCostCenter({
|
||||
position_id: position.id,
|
||||
cost_center_id: kostenstelleId,
|
||||
valid_from: kostenstelleAb,
|
||||
});
|
||||
if (!kosten.success) {
|
||||
setPending(false);
|
||||
showToast(kosten.error ?? "Die Kostenstelle konnte nicht geändert werden.", "error");
|
||||
router.refresh();
|
||||
return;
|
||||
}
|
||||
}
|
||||
setPending(false);
|
||||
if (result.success) {
|
||||
showToast("Planstelle geändert.");
|
||||
showToast(kostenstelleGeaendert ? "Planstelle geändert und umkontiert." : "Planstelle geändert.");
|
||||
router.refresh();
|
||||
onClose();
|
||||
} else {
|
||||
@@ -110,6 +142,30 @@ export function EditPositionModal({
|
||||
<TextField label="Gültig bis" type="date" value={validTo} onChange={setValidTo} />
|
||||
</div>
|
||||
|
||||
<SelectField
|
||||
label="Kostenstelle"
|
||||
value={kostenstelleId}
|
||||
onChange={setKostenstelleId}
|
||||
placeholder="Keine"
|
||||
options={kostenstellen.map((k) => ({ value: k.id, label: `${k.code} · ${k.name}` }))}
|
||||
/>
|
||||
{kostenstelleGeaendert && (
|
||||
<div className="rounded border border-border bg-surface px-3 py-2">
|
||||
<TextField
|
||||
label="Umkontieren ab"
|
||||
required
|
||||
type="date"
|
||||
value={kostenstelleAb}
|
||||
onChange={setKostenstelleAb}
|
||||
min={position.valid_from}
|
||||
/>
|
||||
<p className="mt-1.5 text-xs text-ink-muted">
|
||||
Die bisherige Kontierung endet an diesem Tag, die neue beginnt. Was vorher gebucht wurde, bleibt, wo es
|
||||
gebucht wurde.
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<label className="flex items-start gap-2 text-sm text-ink-body">
|
||||
<input
|
||||
type="checkbox"
|
||||
|
||||
@@ -6,7 +6,7 @@ import { useState } from "react";
|
||||
import { deletePosition } from "@/actions/positions";
|
||||
import { Button } from "@/components/ui/Button";
|
||||
import { useToast } from "@/components/ui/Toast";
|
||||
import { fmtDate } from "@/lib/format";
|
||||
import { fmtDate, todayIso } from "@/lib/format";
|
||||
import type { OpenPositionResolved } from "@/lib/positions";
|
||||
import { CreatePositionModal, type UnitOption } from "./CreatePositionModal";
|
||||
import { EditPositionModal } from "./EditPositionModal";
|
||||
@@ -16,9 +16,10 @@ type OpenPositionWithDays = OpenPositionResolved & { daysOpen: number };
|
||||
type PositionsPageClientProps = {
|
||||
openPositions: OpenPositionWithDays[];
|
||||
units: UnitOption[];
|
||||
kostenstellen: { id: string; code: string; name: string }[];
|
||||
};
|
||||
|
||||
export function PositionsPageClient({ openPositions, units }: PositionsPageClientProps) {
|
||||
export function PositionsPageClient({ openPositions, units, kostenstellen }: PositionsPageClientProps) {
|
||||
const { showToast } = useToast();
|
||||
const router = useRouter();
|
||||
const [createOpen, setCreateOpen] = useState(false);
|
||||
@@ -66,6 +67,14 @@ export function PositionsPageClient({ openPositions, units }: PositionsPageClien
|
||||
</span>
|
||||
{p.valid_to && <span className="text-xs font-semibold text-warning-text">endet am {fmtDate(p.valid_to)}</span>}
|
||||
{p.managerName && <span className="text-xs text-ink-muted">berichtet an {p.managerName}</span>}
|
||||
{/* Was die Stelle kostet und wen es trifft — die Frage, die bei einer
|
||||
Vakanz zuerst kommt. */}
|
||||
{p.kostenstelle && (
|
||||
<span className="text-xs text-ink-muted">
|
||||
Kostenstelle <span className="font-semibold tabular-nums text-ink-body">{p.kostenstelle.code}</span> ·{" "}
|
||||
{p.kostenstelle.name}
|
||||
</span>
|
||||
)}
|
||||
</button>
|
||||
|
||||
<Button
|
||||
@@ -121,7 +130,14 @@ export function PositionsPageClient({ openPositions, units }: PositionsPageClien
|
||||
baut — sonst blieben beim zweiten Öffnen die Werte des ersten
|
||||
stehen. */}
|
||||
{editing && (
|
||||
<EditPositionModal key={editing.id} position={editing} units={units} onClose={() => setEditing(null)} />
|
||||
<EditPositionModal
|
||||
key={editing.id}
|
||||
position={editing}
|
||||
units={units}
|
||||
kostenstellen={kostenstellen}
|
||||
heute={todayIso()}
|
||||
onClose={() => setEditing(null)}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user