Add payment QR code to invoice PDFs

This commit is contained in:
2026-07-22 18:51:13 +02:00
parent 769185cd82
commit dd2a9926dc
3 changed files with 114 additions and 7 deletions

View File

@@ -405,12 +405,15 @@ async function getCloseData(server:FastifyInstance,item: any, tenant: any, units
console.log(item);
const [contact, customer, project, contract] = await Promise.all([
const [contact, customer, project, contract, bankAccounts] = await Promise.all([
fetchById(server, schema.contacts, item.contact),
fetchById(server, schema.customers, item.customer),
fetchById(server, schema.projects, item.project),
fetchById(server, schema.contracts, item.contract),
item.letterhead ? fetchById(server, schema.letterheads, item.letterhead) : null
server.db
.select()
.from(schema.bankaccounts)
.where(and(eq(schema.bankaccounts.tenant, tenant.id), eq(schema.bankaccounts.archived, false), eq(schema.bankaccounts.expired, false)))
]);
@@ -433,7 +436,8 @@ async function getCloseData(server:FastifyInstance,item: any, tenant: any, units
contract, // Contract Object
units, // Units Array
products, // Products Array
services // Services Array
services, // Services Array
bankAccounts // Tenant Bank Accounts
);
@@ -528,9 +532,11 @@ export function getDocumentDataBackend(
contractData: any, // Vertrag
units: any[], // Array aller Einheiten
products: any[], // Array aller Produkte
services: any[] // Array aller Services
services: any[], // Array aller Services
bankAccounts: any[] = [] // Array aller Bankkonten
) {
const businessInfo = tenant.businessInfo || {}; // Fallback falls leer
const paymentQrBankAccount = bankAccounts.find((account: any) => !account.archived && !account.expired && account.iban) || null
// --- 1. Agriculture Logic ---
// Prüfen ob 'extraModules' existiert, sonst leeres Array annehmen
@@ -724,6 +730,12 @@ export function getDocumentDataBackend(
},
agriculture: itemInfo.agriculture,
// Falls du AdvanceInvoices brauchst, musst du die Objekte hier übergeben oder leer lassen
usedAdvanceInvoices: []
usedAdvanceInvoices: [],
paymentQr: paymentQrBankAccount && itemInfo.payment_type === "transfer" ? {
iban: paymentQrBankAccount.iban,
recipientName: paymentQrBankAccount.ownerName || businessInfo.name || tenant.name,
amount: totals.totalGross,
remittance: itemInfo.documentNumber || itemInfo.title,
} : null
};
}