From 28ff274107a27c2fcf49a24db29804ff23b46667 Mon Sep 17 00:00:00 2001 From: flfeders Date: Mon, 13 May 2024 10:43:23 +0200 Subject: [PATCH] Many Changes --- composables/useWorkingTimePDFGenerator.js | 191 +++++++++++++ pages/customers/[mode]/[[id]].vue | 1 - pages/workingtimes/evaluate/[id].vue | 311 ++++++++++++++++++++++ pages/workingtimes/index.vue | 5 + 4 files changed, 507 insertions(+), 1 deletion(-) create mode 100644 composables/useWorkingTimePDFGenerator.js create mode 100644 pages/workingtimes/evaluate/[id].vue diff --git a/composables/useWorkingTimePDFGenerator.js b/composables/useWorkingTimePDFGenerator.js new file mode 100644 index 0000000..e91f417 --- /dev/null +++ b/composables/useWorkingTimePDFGenerator.js @@ -0,0 +1,191 @@ +import {PDFDocument, StandardFonts, rgb} from "pdf-lib" +import dayjs from "dayjs" + + +const getCoordinatesForPDFLib = (x ,y, page) => { + /* + * @param x the wanted X Parameter in Millimeters from Top Left + * @param y the wanted Y Parameter in Millimeters from Top Left + * @param page the page Object + * + * @returns x,y object + * */ + + + let retX = x * 2.83 + let retY = page.getHeight()-(y*2.83) + + return { + x: retX, + y: retY + } + +} + +const getDuration = (time) => { + const minutes = Math.floor(dayjs(time.endDate).diff(dayjs(time.startDate),'minutes',true)) + const hours = Math.floor(minutes/60) + return { + //dezimal: dez, + hours: hours, + minutes: minutes, + composed: `${hours}:${String(minutes % 60).padStart(2,"0")} Std` + } +} + + + + +export const useCreateWorkingTimesPdf = async (input,backgroundSourceBuffer) => { + + const uri = ref("test") + const genPDF = async () => { + const pdfDoc = await PDFDocument.create() + + const font = await pdfDoc.embedFont(StandardFonts.Helvetica) + const fontBold = await pdfDoc.embedFont(StandardFonts.HelveticaBold) + + let pages = [] + let pageCounter = 1 + + + + const backgroudPdf = await PDFDocument.load(backgroundSourceBuffer) + + const firstPageBackground = await pdfDoc.embedPage(backgroudPdf.getPages()[0]) + const secondPageBackground = await pdfDoc.embedPage(backgroudPdf.getPages()[backgroudPdf.getPages().length > 1 ? 1 : 0]) + + const page1 = pdfDoc.addPage() + + page1.drawPage(firstPageBackground, { + x: 0, + y: 0, + }) + + pages.push(page1) + + + //Falzmarke 1 + /*pages[pageCounter - 1].drawLine({ + start: getCoordinatesForPDFLib(0,105,page1), + end: getCoordinatesForPDFLib(7,105,page1), + thickness: 0.25, + color: rgb(0,0,0), + opacity: 1 + })*/ + + //Lochmarke + /*pages[pageCounter - 1].drawLine({ + start: getCoordinatesForPDFLib(0,148.5,page1), + end: getCoordinatesForPDFLib(7,148.5,page1), + thickness: 0.25, + color: rgb(0,0,0), + opacity: 1 + })*/ + + //Falzmarke 2 + /*pages[pageCounter - 1].drawLine({ + start: getCoordinatesForPDFLib(0,210,page1), + end: getCoordinatesForPDFLib(7,210,page1), + thickness: 0.25, + color: rgb(0,0,0), + opacity: 1 + })*/ + console.log(input) + pages[pageCounter - 1].drawText(`Mitarbeiter: ${input.profile}`,{ + x: getCoordinatesForPDFLib(20,65,pages[pageCounter -1]).x, + y: getCoordinatesForPDFLib(20,65,pages[pageCounter -1]).y, + size: 10, + }) + pages[pageCounter - 1].drawText(`Eingereicht: ${Math.floor(input.sumWorkingMinutesEingereicht/60)}:${String(input.sumWorkingMinutesEingereicht % 60).padStart(2,"0")} Std`,{ + x: getCoordinatesForPDFLib(20,70,pages[pageCounter -1]).x, + y: getCoordinatesForPDFLib(20,70,pages[pageCounter -1]).y, + size: 10, + }) + pages[pageCounter - 1].drawText(`Bestätigt: ${Math.floor(input.sumWorkingMinutesApproved/60)}:${String(input.sumWorkingMinutesApproved % 60).padStart(2,"0")} Std`,{ + x: getCoordinatesForPDFLib(20,75,pages[pageCounter -1]).x, + y: getCoordinatesForPDFLib(20,75,pages[pageCounter -1]).y, + size: 10, + }) + pages[pageCounter - 1].drawText(`Soll Stunden: ${input.monthlyWorkingHours} Std`,{ + x: getCoordinatesForPDFLib(20,80,pages[pageCounter -1]).x, + y: getCoordinatesForPDFLib(20,80,pages[pageCounter -1]).y, + size: 10, + }) + pages[pageCounter - 1].drawText(`Abwesend: Std`,{ + x: getCoordinatesForPDFLib(20,85,pages[pageCounter -1]).x, + y: getCoordinatesForPDFLib(20,85,pages[pageCounter -1]).y, + size: 10, + }) + pages[pageCounter - 1].drawText(`Ausgleich: Std`,{ + x: getCoordinatesForPDFLib(20,90,pages[pageCounter -1]).x, + y: getCoordinatesForPDFLib(20,90,pages[pageCounter -1]).y, + size: 10, + }) + pages[pageCounter - 1].drawText(`Inoffizielles Saldo: ${input.saldoInOfficial} Std`,{ + x: getCoordinatesForPDFLib(20,95,pages[pageCounter -1]).x, + y: getCoordinatesForPDFLib(20,95,pages[pageCounter -1]).y, + size: 10, + }) + pages[pageCounter - 1].drawText(`Saldo: ${input.saldo} Std`,{ + x: getCoordinatesForPDFLib(20,100,pages[pageCounter -1]).x, + y: getCoordinatesForPDFLib(20,100,pages[pageCounter -1]).y, + size: 10, + }) + + pages[pageCounter - 1].drawText(`Start:`,{ + x: getCoordinatesForPDFLib(20,110,pages[pageCounter -1]).x, + y: getCoordinatesForPDFLib(20,110,pages[pageCounter -1]).y, + size: 10, + }) + + pages[pageCounter - 1].drawText(`Ende:`,{ + x: getCoordinatesForPDFLib(60,110,pages[pageCounter -1]).x, + y: getCoordinatesForPDFLib(60,110,pages[pageCounter -1]).y, + size: 10, + }) + + pages[pageCounter - 1].drawText(`Dauer:`,{ + x: getCoordinatesForPDFLib(100,110,pages[pageCounter -1]).x, + y: getCoordinatesForPDFLib(100,110,pages[pageCounter -1]).y, + size: 10, + }) + + + let rowHeight = 115 + + input.times.forEach(time => { + pages[pageCounter - 1].drawText(`${dayjs(time.startDate).format("HH:mm DD.MM.YY")}`,{ + x: getCoordinatesForPDFLib(20,rowHeight,pages[pageCounter -1]).x, + y: getCoordinatesForPDFLib(20,rowHeight,pages[pageCounter -1]).y, + size: 10, + }) + + pages[pageCounter - 1].drawText(`${dayjs(time.startDate).format("HH:mm DD.MM.YY")}`,{ + x: getCoordinatesForPDFLib(60,rowHeight,pages[pageCounter -1]).x, + y: getCoordinatesForPDFLib(60,rowHeight,pages[pageCounter -1]).y, + size: 10, + }) + + pages[pageCounter - 1].drawText(`${getDuration(time).composed}`,{ + x: getCoordinatesForPDFLib(100,rowHeight,pages[pageCounter -1]).x, + y: getCoordinatesForPDFLib(100,rowHeight,pages[pageCounter -1]).y, + size: 10, + }) + + rowHeight += 6 + + }) + + + + uri.value = await pdfDoc.saveAsBase64({dataUri: true}) + + } + + await genPDF() + + return uri.value + + +} \ No newline at end of file diff --git a/pages/customers/[mode]/[[id]].vue b/pages/customers/[mode]/[[id]].vue index 3faa595..dfd14c2 100644 --- a/pages/customers/[mode]/[[id]].vue +++ b/pages/customers/[mode]/[[id]].vue @@ -73,7 +73,6 @@ setupPage() + + Auswertung +