Extend document title levels

This commit is contained in:
2026-07-15 13:11:57 +02:00
parent d8273e794d
commit 6a14b0c1ca
2 changed files with 92 additions and 46 deletions

View File

@@ -399,6 +399,12 @@ export const createInvoicePDF = async (server:FastifyInstance, returnMode, invoi
let pageIndex = 0
const getTitleKey = (row) => `${row.pos} - ${row.text}`
const getTransferSumText = (row) => {
const transferSum = invoiceData.total.titleSumsTransfer[getTitleKey(row)]
return transferSum ? `Übertrag: ${transferSum}` : null
}
invoiceData.rows.forEach((row, index) => {
@@ -579,18 +585,20 @@ export const createInvoicePDF = async (server:FastifyInstance, returnMode, invoi
console.log(invoiceData.rows[index + 1])
if (invoiceData.rows[index + 1].mode === 'title') {
let transferSumText = `Übertrag: ${invoiceData.total.titleSumsTransfer[Object.keys(invoiceData.total.titleSums)[invoiceData.rows[index + 1].pos - 2]]}`
pages[pageCounter - 1].drawText(transferSumText, {
y: getCoordinatesForPDFLib(21, rowHeight - 2, page1).y,
x: getCoordinatesForPDFLib(21, rowHeight - 2, page1).x + 500 - fontBold.widthOfTextAtSize(transferSumText, 10),
size: 10,
color: rgb(0, 0, 0),
lineHeight: 10,
opacity: 1,
maxWidth: 240,
font: fontBold
})
if (invoiceData.rows[index + 1]?.mode === 'title') {
const transferSumText = getTransferSumText(invoiceData.rows[index + 1])
if (transferSumText) {
pages[pageCounter - 1].drawText(transferSumText, {
y: getCoordinatesForPDFLib(21, rowHeight - 2, page1).y,
x: getCoordinatesForPDFLib(21, rowHeight - 2, page1).x + 500 - fontBold.widthOfTextAtSize(transferSumText, 10),
size: 10,
color: rgb(0, 0, 0),
lineHeight: 10,
opacity: 1,
maxWidth: 240,
font: fontBold
})
}
}
@@ -713,17 +721,19 @@ export const createInvoicePDF = async (server:FastifyInstance, returnMode, invoi
if (index === 0 || pageIndex === 0) {
rowHeight += 3
} else {
let transferSumText = `Übertrag: ${invoiceData.total.titleSumsTransfer[Object.keys(invoiceData.total.titleSums)[row.pos - 2]]}`
pages[pageCounter - 1].drawText(transferSumText, {
y: getCoordinatesForPDFLib(21, rowHeight - 2, page1).y,
x: getCoordinatesForPDFLib(21, rowHeight - 2, page1).x + 500 - fontBold.widthOfTextAtSize(transferSumText, 10),
size: 10,
color: rgb(0, 0, 0),
lineHeight: 10,
opacity: 1,
maxWidth: 240,
font: fontBold
})
const transferSumText = getTransferSumText(row)
if (transferSumText) {
pages[pageCounter - 1].drawText(transferSumText, {
y: getCoordinatesForPDFLib(21, rowHeight - 2, page1).y,
x: getCoordinatesForPDFLib(21, rowHeight - 2, page1).x + 500 - fontBold.widthOfTextAtSize(transferSumText, 10),
size: 10,
color: rgb(0, 0, 0),
lineHeight: 10,
opacity: 1,
maxWidth: 240,
font: fontBold
})
}
pages[pageCounter - 1].drawLine({
start: getCoordinatesForPDFLib(20, rowHeight, page1),
@@ -735,6 +745,10 @@ export const createInvoicePDF = async (server:FastifyInstance, returnMode, invoi
rowHeight += 5
}
const titleLevel = Math.min(Math.max(Number(row.titleLevel) || 1, 1), 3)
const titleTextSize = titleLevel === 1 ? 12 : titleLevel === 2 ? 11 : 10
const titleTextX = 35 + ((titleLevel - 1) * 7)
pages[pageCounter - 1].drawText(String(row.pos), {
...getCoordinatesForPDFLib(21, rowHeight, page1),
size: 10,
@@ -746,16 +760,16 @@ export const createInvoicePDF = async (server:FastifyInstance, returnMode, invoi
})
pages[pageCounter - 1].drawText(splitStringBySpace(row.text, 60).join("\n"), {
...getCoordinatesForPDFLib(35, rowHeight, page1),
size: 12,
...getCoordinatesForPDFLib(titleTextX, rowHeight, page1),
size: titleTextSize,
color: rgb(0, 0, 0),
lineHeight: 12,
lineHeight: titleTextSize,
opacity: 1,
maxWidth: 500,
font: fontBold
})
rowHeight += splitStringBySpace(row.text, 60).length * 4.5
rowHeight += splitStringBySpace(row.text, 60).length * (titleLevel === 1 ? 4.5 : 4)
} else if (row.mode === 'text') {
if (index === 0 || pageIndex === 0) {
rowHeight += 3