Umstellung auf anzeige x h y min

This commit is contained in:
2026-02-13 12:21:43 +01:00
parent 23c255438b
commit af1f6efb40
8 changed files with 117 additions and 94 deletions

View File

@@ -3,7 +3,7 @@
const PDFDocument = require('pdfkit');
const QRCode = require('qrcode');
const { db } = require('../database');
const { formatDate, formatDateTime } = require('../helpers/utils');
const { formatDate, formatDateTime, formatHoursMin } = require('../helpers/utils');
const { getHolidaysWithNamesForDateRange } = require('./feiertage-service');
// Kalenderwoche berechnen
@@ -190,7 +190,7 @@ function generatePDF(timesheetId, req, res) {
// Feiertag am Wochenende: keine Tagesarbeitsstunden anzeigen
const holidayDay = new Date(row.date + 'T12:00:00').getDay();
const isWeekendHoliday = (holidayDay === 0 || holidayDay === 6);
const holidayHoursStr = isWeekendHoliday ? '0 h (Feiertag)' : fullDayHours.toFixed(2) + ' h (Feiertag)';
const holidayHoursStr = isWeekendHoliday ? '0 h 0 min (Feiertag)' : formatHoursMin(fullDayHours) + ' (Feiertag)';
const rowData = [formatDate(row.date), '-', '-', '-', holidayHoursStr];
rowData.forEach((data, i) => {
doc.text(data, x, y, { width: colWidths[i], align: 'left' });
@@ -215,7 +215,7 @@ function generatePDF(timesheetId, req, res) {
entry.start_time || '-',
entry.end_time || '-',
entry.break_minutes ? `${entry.break_minutes} min` : '-',
entry.total_hours ? entry.total_hours.toFixed(2) + ' h' : '-'
entry.total_hours ? formatHoursMin(entry.total_hours) : '-'
];
rowData.forEach((data, i) => {
@@ -250,7 +250,7 @@ function generatePDF(timesheetId, req, res) {
if (activity.projectNumber) {
activityText += ` (Projekt: ${activity.projectNumber})`;
}
activityText += ` - ${activity.hours.toFixed(2)} h`;
activityText += ` - ${formatHoursMin(activity.hours)}`;
doc.fontSize(9).font('Helvetica');
doc.text(activityText, 70, doc.y, { width: 360 });
doc.moveDown(0.2);
@@ -264,7 +264,7 @@ function generatePDF(timesheetId, req, res) {
overtimeInfo.push('Feiertag: ' + (holidayNames.get(entry.date) || 'Feiertag'));
}
if (entry.overtime_taken_hours && parseFloat(entry.overtime_taken_hours) > 0) {
overtimeInfo.push(`Überstunden genommen: ${parseFloat(entry.overtime_taken_hours).toFixed(2)} h`);
overtimeInfo.push(`Überstunden genommen: ${formatHoursMin(parseFloat(entry.overtime_taken_hours))}`);
}
if (entry.vacation_type) {
const vacationText = entry.vacation_type === 'full' ? 'Ganzer Tag' : 'Halber Tag';
@@ -308,7 +308,7 @@ function generatePDF(timesheetId, req, res) {
doc.font('Helvetica-Bold');
// Gesamtstunden = Arbeitsstunden + Urlaubsstunden + Feiertagsstunden (8h pro Feiertag)
const totalHoursWithVacation = totalHours + vacationHours + holidayHours;
doc.text(`Gesamtstunden: ${totalHoursWithVacation.toFixed(2)} h`, 50, doc.y);
doc.text(`Gesamtstunden: ${formatHoursMin(totalHoursWithVacation)}`, 50, doc.y);
// Überstunden berechnen und anzeigen
const wochenstunden = timesheet.wochenstunden || 0;
@@ -318,11 +318,11 @@ function generatePDF(timesheetId, req, res) {
doc.moveDown(0.3);
doc.font('Helvetica-Bold');
if (overtimeHours > 0) {
doc.text(`Überstunden: +${overtimeHours.toFixed(2)} h`, 50, doc.y);
doc.text(`Überstunden: +${formatHoursMin(overtimeHours)}`, 50, doc.y);
} else if (overtimeHours < 0) {
doc.text(`Überstunden: ${overtimeHours.toFixed(2)} h`, 50, doc.y);
doc.text(`Überstunden: ${formatHoursMin(overtimeHours)}`, 50, doc.y);
} else {
doc.text(`Überstunden: 0.00 h`, 50, doc.y);
doc.text(`Überstunden: ${formatHoursMin(0)}`, 50, doc.y);
}
doc.end();
@@ -462,7 +462,7 @@ function generatePDFToBuffer(timesheetId, req) {
// Feiertag am Wochenende: keine Tagesarbeitsstunden anzeigen
const holidayDay = new Date(row.date + 'T12:00:00').getDay();
const isWeekendHoliday = (holidayDay === 0 || holidayDay === 6);
const holidayHoursStr = isWeekendHoliday ? '0 h (Feiertag)' : fullDayHoursBuf.toFixed(2) + ' h (Feiertag)';
const holidayHoursStr = isWeekendHoliday ? '0 h 0 min (Feiertag)' : formatHoursMin(fullDayHoursBuf) + ' (Feiertag)';
const rowDataBuf = [formatDate(row.date), '-', '-', '-', holidayHoursStr];
rowDataBuf.forEach((data, i) => {
doc.text(data, x, y, { width: colWidths[i], align: 'left' });
@@ -487,7 +487,7 @@ function generatePDFToBuffer(timesheetId, req) {
entry.start_time || '-',
entry.end_time || '-',
entry.break_minutes ? `${entry.break_minutes} min` : '-',
entry.total_hours ? entry.total_hours.toFixed(2) + ' h' : '-'
entry.total_hours ? formatHoursMin(entry.total_hours) : '-'
];
rowData.forEach((data, i) => {
@@ -519,7 +519,7 @@ function generatePDFToBuffer(timesheetId, req) {
if (activity.projectNumber) {
activityText += ` (Projekt: ${activity.projectNumber})`;
}
activityText += ` - ${activity.hours.toFixed(2)} h`;
activityText += ` - ${formatHoursMin(activity.hours)}`;
doc.fontSize(9).font('Helvetica');
doc.text(activityText, 70, doc.y, { width: 360 });
doc.moveDown(0.2);
@@ -532,7 +532,7 @@ function generatePDFToBuffer(timesheetId, req) {
overtimeInfo.push('Feiertag: ' + (holidayNames.get(entry.date) || 'Feiertag'));
}
if (entry.overtime_taken_hours && parseFloat(entry.overtime_taken_hours) > 0) {
overtimeInfo.push(`Überstunden genommen: ${parseFloat(entry.overtime_taken_hours).toFixed(2)} h`);
overtimeInfo.push(`Überstunden genommen: ${formatHoursMin(parseFloat(entry.overtime_taken_hours))}`);
}
if (entry.vacation_type) {
const vacationText = entry.vacation_type === 'full' ? 'Ganzer Tag' : 'Halber Tag';
@@ -573,7 +573,7 @@ function generatePDFToBuffer(timesheetId, req) {
doc.moveDown(0.5);
doc.font('Helvetica-Bold');
const totalHoursWithVacation = totalHours + vacationHours + holidayHours;
doc.text(`Gesamtstunden: ${totalHoursWithVacation.toFixed(2)} h`, 50, doc.y);
doc.text(`Gesamtstunden: ${formatHoursMin(totalHoursWithVacation)}`, 50, doc.y);
const wochenstunden = timesheet.wochenstunden || 0;
const overtimeHours = totalHoursWithVacation - wochenstunden;
@@ -581,11 +581,11 @@ function generatePDFToBuffer(timesheetId, req) {
doc.moveDown(0.3);
doc.font('Helvetica-Bold');
if (overtimeHours > 0) {
doc.text(`Überstunden: +${overtimeHours.toFixed(2)} h`, 50, doc.y);
doc.text(`Überstunden: +${formatHoursMin(overtimeHours)}`, 50, doc.y);
} else if (overtimeHours < 0) {
doc.text(`Überstunden: ${overtimeHours.toFixed(2)} h`, 50, doc.y);
doc.text(`Überstunden: ${formatHoursMin(overtimeHours)}`, 50, doc.y);
} else {
doc.text(`Überstunden: 0.00 h`, 50, doc.y);
doc.text(`Überstunden: ${formatHoursMin(0)}`, 50, doc.y);
}
doc.end();