From fbea66b7542de51df762fcd4fb245c7b35c9a510 Mon Sep 17 00:00:00 2001 From: flfeders Date: Wed, 22 Jul 2026 19:40:01 +0200 Subject: [PATCH] Use tenant business payment info for invoice QR codes --- backend/db/schema/tenants.ts | 9 +++ .../src/modules/serialexecution.service.ts | 10 ++- frontend/pages/createDocument/edit/[[id]].vue | 12 ++-- frontend/pages/settings/tenant.vue | 65 ++++++++++++++++++- 4 files changed, 88 insertions(+), 8 deletions(-) diff --git a/backend/db/schema/tenants.ts b/backend/db/schema/tenants.ts index c481452..8e7a8bb 100644 --- a/backend/db/schema/tenants.ts +++ b/backend/db/schema/tenants.ts @@ -60,6 +60,15 @@ export const tenants = pgTable( city: "", name: "", street: "", + email: "", + phone: "", + website: "", + taxNumber: "", + vatId: "", + bankName: "", + bankAccountOwner: "", + iban: "", + bic: "", }), features: jsonb("features").default({ diff --git a/backend/src/modules/serialexecution.service.ts b/backend/src/modules/serialexecution.service.ts index a40edde..bf8bb72 100644 --- a/backend/src/modules/serialexecution.service.ts +++ b/backend/src/modules/serialexecution.service.ts @@ -537,6 +537,9 @@ export function getDocumentDataBackend( ) { const businessInfo = tenant.businessInfo || {}; // Fallback falls leer const paymentQrBankAccount = bankAccounts.find((account: any) => !account.archived && !account.expired && account.iban) || null + const paymentQrIban = businessInfo.iban || paymentQrBankAccount?.iban + const paymentQrBic = businessInfo.bic || paymentQrBankAccount?.bic + const paymentQrRecipient = businessInfo.bankAccountOwner || paymentQrBankAccount?.ownerName || businessInfo.name || tenant.name // --- 1. Agriculture Logic --- // Prüfen ob 'extraModules' existiert, sonst leeres Array annehmen @@ -731,9 +734,10 @@ export function getDocumentDataBackend( agriculture: itemInfo.agriculture, // Falls du AdvanceInvoices brauchst, musst du die Objekte hier übergeben oder leer lassen usedAdvanceInvoices: [], - paymentQr: paymentQrBankAccount && itemInfo.payment_type === "transfer" ? { - iban: paymentQrBankAccount.iban, - recipientName: paymentQrBankAccount.ownerName || businessInfo.name || tenant.name, + paymentQr: paymentQrIban && itemInfo.payment_type === "transfer" ? { + iban: paymentQrIban, + bic: paymentQrBic, + recipientName: paymentQrRecipient, amount: totals.totalGross, remittance: itemInfo.documentNumber || itemInfo.title, } : null diff --git a/frontend/pages/createDocument/edit/[[id]].vue b/frontend/pages/createDocument/edit/[[id]].vue index 95e1d49..bec580e 100644 --- a/frontend/pages/createDocument/edit/[[id]].vue +++ b/frontend/pages/createDocument/edit/[[id]].vue @@ -1411,8 +1411,11 @@ const getDocumentData = async () => { let customerData = customers.value.find(i => i.id === itemInfo.value.customer) let contactData = contacts.value.find(i => i.id === itemInfo.value.contact) - let businessInfo = auth.activeTenantData.businessInfo + let businessInfo = auth.activeTenantData.businessInfo || {} const paymentQrBankAccount = bankaccounts.value.find(account => !account.archived && !account.expired && account.iban) + const paymentQrIban = businessInfo.iban || paymentQrBankAccount?.iban + const paymentQrBic = businessInfo.bic || paymentQrBankAccount?.bic + const paymentQrRecipient = businessInfo.bankAccountOwner || paymentQrBankAccount?.ownerName || businessInfo.name || auth.activeTenantData.name if (auth.activeTenantData.extraModules.includes("agriculture")) { itemInfo.value.rows.forEach(row => { @@ -1629,9 +1632,10 @@ const getDocumentData = async () => { usedAdvanceInvoices: itemInfo.value.usedAdvanceInvoices.map(i => { return createddocuments.value.find(x => x.id === i) }), - paymentQr: paymentQrBankAccount && itemInfo.value.payment_type === "transfer" ? { - iban: paymentQrBankAccount.iban, - recipientName: paymentQrBankAccount.ownerName || businessInfo.name || auth.activeTenantData.name, + paymentQr: paymentQrIban && itemInfo.value.payment_type === "transfer" ? { + iban: paymentQrIban, + bic: paymentQrBic, + recipientName: paymentQrRecipient, amount: documentTotal.value.totalSumToPay, remittance: itemInfo.value.documentNumber || itemInfo.value.title, } : null diff --git a/frontend/pages/settings/tenant.vue b/frontend/pages/settings/tenant.vue index 1db196d..9167cf5 100644 --- a/frontend/pages/settings/tenant.vue +++ b/frontend/pages/settings/tenant.vue @@ -214,17 +214,34 @@ const activeTelephonyTargetOptions = computed(() => { if (telephonyExtensionForm.targetType === "branch") return telephonyExtensionOptions.value.branches || [] return telephonyExtensionOptions.value.users || [] }) +const defaultBusinessInfo = { + name: "", + street: "", + zip: "", + city: "", + email: "", + phone: "", + website: "", + taxNumber: "", + vatId: "", + bankName: "", + bankAccountOwner: "", + iban: "", + bic: "", +} +const normalizeBusinessInfo = (value) => ({ ...defaultBusinessInfo, ...(value || {}) }) const setupPage = async () => { itemInfo.value = auth.activeTenantData console.log(itemInfo.value) + businessInfo.value = normalizeBusinessInfo(auth.activeTenantData?.businessInfo) planningBoardConfig.startTime = auth.activeTenantData?.calendarConfig?.planningBoard?.startTime || "06:00" planningBoardConfig.endTime = auth.activeTenantData?.calendarConfig?.planningBoard?.endTime || "21:00" planningBoardConfig.slotMinutes = auth.activeTenantData?.calendarConfig?.planningBoard?.slotMinutes || 180 } const features = ref({ ...defaultFeatures, ...(auth.activeTenantData?.features || {}) }) -const businessInfo = ref(auth.activeTenantData.businessInfo) +const businessInfo = ref(normalizeBusinessInfo(auth.activeTenantData?.businessInfo)) const accountChart = ref(auth.activeTenantData.accountChart || "skr03") const taxEvaluationPeriod = ref(normalizeTaxEvaluationPeriod(auth.activeTenantData.taxEvaluationPeriod)) const accountChartOptions = [ @@ -245,6 +262,7 @@ const updateTenant = async (newData) => { itemInfo.value = res auth.activeTenantData = res features.value = { ...defaultFeatures, ...(res?.features || {}) } + businessInfo.value = normalizeBusinessInfo(res?.businessInfo) taxEvaluationPeriod.value = normalizeTaxEvaluationPeriod(res?.taxEvaluationPeriod) } } @@ -628,6 +646,51 @@ onMounted(() => { + + + + + + + + + + + + + + + + + + + + + + + + + + +