Let the export select on everything the data model holds
The export offered four criteria — unit, location, status, employment type — while the employee record carries around twenty selectable attributes. Anything else had to be filtered by hand in Excel afterwards, which is how a payroll hand-off stops matching the application it came from. All of them are now filters: contract type, blue/white collar, collective agreement, paygrade, internal/external, gender, company car and its drivetrain, works council, lateral leadership, C-level, type of long-term absence, weekday worked, dependents on file, and open ranges for entry, exit, birth date and weekly hours. The unit filter covers every level rather than only divisions, so a single department can be selected without going the long way round. They live in one table in lib/report-criteria.ts, which the filter panel builds itself from, the parser validates against, and the query turns into conditions. A new criterion is one entry there and nothing else — and it cannot end up working in the report while being silently ignored by the export. The two export links and the saved-report config now carry the query string through as it stands instead of listing the parameters they know about. That enumeration was the actual defect: adding a filter meant remembering three separate places, and forgetting one produced an export that quietly disagreed with the figure on screen. Validation is not housekeeping here. These values reach SQL comparisons and the download filename, i.e. a Content-Disposition header; what is not in the list does not get through. The company car dropdown leaves the employee list. It is one of twenty equals under Berichte now, where the selection can also be exported — which was the point of asking in the first place. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -20,8 +20,6 @@ type SearchParams = {
|
||||
division?: string;
|
||||
status?: string;
|
||||
location?: string;
|
||||
/** "ja" | "nein" | "elektro" | "verbrenner" — alles andere wird übergangen. */
|
||||
dienstwagen?: string;
|
||||
page?: string;
|
||||
};
|
||||
|
||||
@@ -35,7 +33,6 @@ function pageHref(params: SearchParams, page: number): string {
|
||||
if (params.division) sp.set("division", params.division);
|
||||
if (params.status) sp.set("status", params.status);
|
||||
if (params.location) sp.set("location", params.location);
|
||||
if (params.dienstwagen) sp.set("dienstwagen", params.dienstwagen);
|
||||
sp.set("page", String(page));
|
||||
return `/employees?${sp.toString()}`;
|
||||
}
|
||||
@@ -135,13 +132,6 @@ export default async function EmployeesPage({ searchParams }: EmployeesPageProps
|
||||
}
|
||||
|
||||
if (params.location) q = q.where("location_id", "=", params.location);
|
||||
|
||||
// Auf die vier bekannten Werte eingeschränkt: der Parameter kommt aus
|
||||
// der Adresszeile und ist damit fremdbestimmt.
|
||||
if (params.dienstwagen === "ja") q = q.where("has_dienstwagen", "=", true);
|
||||
else if (params.dienstwagen === "nein") q = q.where("has_dienstwagen", "=", false);
|
||||
else if (params.dienstwagen === "elektro") q = q.where("dienstwagen_art", "=", "Elektro");
|
||||
else if (params.dienstwagen === "verbrenner") q = q.where("dienstwagen_art", "=", "Verbrenner");
|
||||
return q;
|
||||
};
|
||||
|
||||
|
||||
@@ -15,11 +15,15 @@ import {
|
||||
sumValues,
|
||||
totalForRows,
|
||||
} from "@/lib/reports";
|
||||
import { parseCriteria } from "@/lib/report-criteria";
|
||||
import { loadEventHistory, loadOrgLookups, loadSnapshotEmployees } from "@/lib/reports-data";
|
||||
import { currentUserId } from "@/lib/auth/session";
|
||||
import { withUser } from "@/lib/db";
|
||||
|
||||
type SearchParams = {
|
||||
// Nur die Parameter, die diese Seite selbst auswertet. Die Auswahlkriterien
|
||||
// stehen ebenfalls in der Adresszeile, werden aber geschlossen von
|
||||
// parseCriteria gelesen — siehe lib/report-criteria.ts.
|
||||
type SearchParams = Record<string, string | string[] | undefined> & {
|
||||
mode?: string;
|
||||
measure?: string;
|
||||
group?: string;
|
||||
@@ -27,7 +31,6 @@ type SearchParams = {
|
||||
division?: string;
|
||||
location?: string;
|
||||
status?: string;
|
||||
employment?: string;
|
||||
asOf?: string;
|
||||
eventType?: string;
|
||||
from?: string;
|
||||
@@ -50,6 +53,7 @@ export default async function ReportsPage({ searchParams }: { searchParams: Prom
|
||||
const measure = parseMeasure(params.measure);
|
||||
const group = parseGroupDimension(params.group);
|
||||
const split = parseSplitDimension(params.split);
|
||||
const criteria = parseCriteria((k) => (typeof params[k] === "string" ? (params[k] as string) : undefined));
|
||||
|
||||
// The report data depends on neither the org lookups nor on who is signed
|
||||
// in, so all three go out together. Against a hosted database a round trip
|
||||
@@ -61,8 +65,8 @@ export default async function ReportsPage({ searchParams }: { searchParams: Prom
|
||||
// Lesestand ist über alle Abfragen hinweg derselbe. Vorher waren es drei
|
||||
// Wellen nacheinander, was gegen eine entfernte Datenbank der teuerste
|
||||
// Teil dieser Seite war.
|
||||
const { lookups, divisions, locations, events, employees, savedReports } = await withUser(userId, async (tx) => {
|
||||
const [{ lookups, divisions, locations }, events, employees, savedReports] = await Promise.all([
|
||||
const { lookups, units, locations, events, employees, savedReports } = await withUser(userId, async (tx) => {
|
||||
const [{ lookups, units, locations }, events, employees, savedReports] = await Promise.all([
|
||||
loadOrgLookups(tx),
|
||||
mode === "events"
|
||||
? loadEventHistory(tx, {
|
||||
@@ -78,7 +82,7 @@ export default async function ReportsPage({ searchParams }: { searchParams: Prom
|
||||
division: params.division,
|
||||
location: params.location,
|
||||
status: params.status,
|
||||
employment: params.employment,
|
||||
criteria,
|
||||
asOf,
|
||||
})
|
||||
: Promise.resolve([]),
|
||||
@@ -91,7 +95,7 @@ export default async function ReportsPage({ searchParams }: { searchParams: Prom
|
||||
.execute()
|
||||
: Promise.resolve([]),
|
||||
]);
|
||||
return { lookups, divisions, locations, events, employees, savedReports };
|
||||
return { lookups, units, locations, events, employees, savedReports };
|
||||
});
|
||||
|
||||
if (mode === "events") {
|
||||
@@ -108,7 +112,7 @@ export default async function ReportsPage({ searchParams }: { searchParams: Prom
|
||||
rows={rows}
|
||||
total={sumValues(rows)}
|
||||
recordCount={events.length}
|
||||
divisions={divisions}
|
||||
units={units}
|
||||
locations={locations}
|
||||
savedReports={savedReports}
|
||||
/>
|
||||
@@ -130,12 +134,12 @@ export default async function ReportsPage({ searchParams }: { searchParams: Prom
|
||||
division: params.division ?? "",
|
||||
location: params.location ?? "",
|
||||
status: params.status ?? "",
|
||||
employment: params.employment ?? "",
|
||||
}}
|
||||
criteria={criteria}
|
||||
rows={rows}
|
||||
total={totalForRows(rows, measure)}
|
||||
recordCount={employees.length}
|
||||
divisions={divisions}
|
||||
units={units}
|
||||
locations={locations}
|
||||
savedReports={savedReports}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user