From 720c70845e78787d541a7ef4786c653d1a78d9b6 Mon Sep 17 00:00:00 2001 From: flfeders Date: Mon, 20 Jul 2026 10:17:00 +0200 Subject: [PATCH] =?UTF-8?q?Rechnungsbetr=C3=A4ge=20deutsch=20formatieren?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/modules/serialexecution.service.ts | 5 ++++- backend/src/utils/pdf.ts | 19 ++++++++++++++----- backend/src/utils/stringRendering.ts | 9 +++++++-- frontend/pages/createDocument/edit/[[id]].vue | 4 ++-- 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/backend/src/modules/serialexecution.service.ts b/backend/src/modules/serialexecution.service.ts index 14e5287..e05e51e 100644 --- a/backend/src/modules/serialexecution.service.ts +++ b/backend/src/modules/serialexecution.service.ts @@ -447,7 +447,10 @@ async function getCloseData(server:FastifyInstance,item: any, tenant: any, units // Formatiert Zahlen zu deutscher Währung function renderCurrency(value: any, currency = "€") { if (value === undefined || value === null) return "0,00 " + currency; - return Number(value).toFixed(2).replace(".", ",") + " " + currency; + return Number(value).toLocaleString("de-DE", { + minimumFractionDigits: 2, + maximumFractionDigits: 2 + }) + " " + currency; } // Berechnet den Zeilenpreis (Menge * Preis * Rabatt) diff --git a/backend/src/utils/pdf.ts b/backend/src/utils/pdf.ts index 76ef318..067bf27 100644 --- a/backend/src/utils/pdf.ts +++ b/backend/src/utils/pdf.ts @@ -25,6 +25,10 @@ const getCoordinatesForPDFLib = (x:number ,y:number, page:any) => { } } +const getRightAlignedX = (rightEdgeMm: number, text: string, size: number, font: any, page: any) => { + return getCoordinatesForPDFLib(rightEdgeMm, 0, page).x - font.widthOfTextAtSize(text, size) +} + const getBackgroundSourceBuffer = async (server:FastifyInstance, path:string) => { @@ -372,8 +376,10 @@ export const createInvoicePDF = async (server:FastifyInstance, returnMode, invoi font: fontBold }) - pages[pageCounter - 1].drawText("Einheitspreis", { - ...getCoordinatesForPDFLib(150, 137, page1), + const unitPriceHeader = "Einheitspreis" + pages[pageCounter - 1].drawText(unitPriceHeader, { + y: getCoordinatesForPDFLib(150, 137, page1).y, + x: getRightAlignedX(177, unitPriceHeader, 12, fontBold, page1), size: 12, color: rgb(0, 0, 0), lineHeight: 12, @@ -508,7 +514,8 @@ export const createInvoicePDF = async (server:FastifyInstance, returnMode, invoi maxWidth: 240 }) pages[pageCounter - 1].drawText(row.price, { - ...getCoordinatesForPDFLib(150, rowHeight, page1), + y: getCoordinatesForPDFLib(150, rowHeight, page1).y, + x: getRightAlignedX(177, row.price, 10, font, page1), size: 10, color: rgb(0, 0, 0), lineHeight: 10, @@ -689,8 +696,10 @@ export const createInvoicePDF = async (server:FastifyInstance, returnMode, invoi font: fontBold }) - page.drawText("Einheitspreis", { - ...getCoordinatesForPDFLib(150, 22, page1), + const unitPriceHeader = "Einheitspreis" + page.drawText(unitPriceHeader, { + y: getCoordinatesForPDFLib(150, 22, page1).y, + x: getRightAlignedX(177, unitPriceHeader, 12, fontBold, page1), size: 12, color: rgb(0, 0, 0), lineHeight: 12, diff --git a/backend/src/utils/stringRendering.ts b/backend/src/utils/stringRendering.ts index 72dbad1..68100c4 100644 --- a/backend/src/utils/stringRendering.ts +++ b/backend/src/utils/stringRendering.ts @@ -1,6 +1,11 @@ export const renderAsCurrency = (value: string | number,currencyString = "€") => { - return `${Number(value).toFixed(2).replace(".",",")} ${currencyString}` + const formattedValue = Number(value).toLocaleString("de-DE", { + minimumFractionDigits: 2, + maximumFractionDigits: 2 + }) + + return `${formattedValue} ${currencyString}` } export const splitStringBySpace = (input:string,maxSplitLength:number,removeLinebreaks = false) => { @@ -48,4 +53,4 @@ export const splitStringBySpace = (input:string,maxSplitLength:number,removeLine }) return returnSplitStrings -} \ No newline at end of file +} diff --git a/frontend/pages/createDocument/edit/[[id]].vue b/frontend/pages/createDocument/edit/[[id]].vue index 769dd69..54aface 100644 --- a/frontend/pages/createDocument/edit/[[id]].vue +++ b/frontend/pages/createDocument/edit/[[id]].vue @@ -1409,11 +1409,11 @@ const getDocumentData = async () => { return { ...row, - rowAmount: `${getRowAmount(row)} €`, + rowAmount: renderCurrency(Number(row.quantity) * Number(row.price) * (1 - Number(row.discountPercent) / 100)), quantity: String(row.quantity).replace(".", ","), unit: unit.short, pos: String(row.pos), - price: `${String(row.price.toFixed(2)).replace(".", ",")} €`, + price: renderCurrency(row.price), discountText: `(Rabatt: ${row.discountPercent} %)` } } else {