Rechnungsbeträge deutsch formatieren

This commit is contained in:
2026-07-20 10:17:00 +02:00
parent ae379b0f22
commit 720c70845e
4 changed files with 27 additions and 10 deletions

View File

@@ -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)

View File

@@ -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,

View File

@@ -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) => {

View File

@@ -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 {