forked from fahrPool/fahrPool
37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
import { csvFeld } from "@/lib/audit/csv";
|
||
import { rollenBezeichnung } from "@/lib/auth/roles";
|
||
import type { Report } from "./report";
|
||
|
||
const KOPF = ["Name", "Rolle", "Aufträge abgeschlossen", "km", "Fahrzeit (h)", "Arbeitszeit (h)", "Auslastung %"];
|
||
|
||
function stunden(minuten: number): string {
|
||
return (minuten / 60).toFixed(2).replace(".", ",");
|
||
}
|
||
|
||
// Semikolon + BOM fuer deutsches Excel, Formel-Schutz ueber csvFeld.
|
||
export function reportCsv(report: Report): string {
|
||
const zeilen = [KOPF.join(";")];
|
||
for (const z of report.zeilen) {
|
||
zeilen.push(
|
||
[
|
||
z.person.name,
|
||
rollenBezeichnung(z.person.role),
|
||
String(z.abgeschlossen),
|
||
String(z.km),
|
||
stunden(z.fahrtMin),
|
||
stunden(z.arbeitMin),
|
||
z.auslastung === null ? "" : String(z.auslastung),
|
||
]
|
||
.map(csvFeld)
|
||
.join(";")
|
||
);
|
||
}
|
||
const k = report.kacheln;
|
||
zeilen.push(
|
||
["Summe", "", String(k.abgeschlossen), String(k.kmGesamt), stunden(k.fahrtMin), stunden(k.arbeitMin), k.auslastung === null ? "" : String(k.auslastung)]
|
||
.map(csvFeld)
|
||
.join(";")
|
||
);
|
||
return `${zeilen.join("\r\n")}`;
|
||
}
|