1
0
Fork 0
fahrPool/web/lib/reports/csv.ts

37 lines
1.1 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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")}`;
}