From d9d12ef58f1f0b376208a319636f5da0b3881b19 Mon Sep 17 00:00:00 2001 From: nico Date: Thu, 5 Nov 2026 10:28:15 +0000 Subject: [PATCH] feat(accounting): make outgoing e-invoices opt-in per tenant --- .../src/modules/einvoice/outgoingZugferd.service.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/backend/src/modules/einvoice/outgoingZugferd.service.ts b/backend/src/modules/einvoice/outgoingZugferd.service.ts index bfa21c1b..e6f9df48 100644 --- a/backend/src/modules/einvoice/outgoingZugferd.service.ts +++ b/backend/src/modules/einvoice/outgoingZugferd.service.ts @@ -30,9 +30,18 @@ export class EInvoiceRequirementsError extends Error { export const breakingIssues = (issues: ZugferdIssue[]) => issues.filter((issue) => issue.type === "breaking") +/** Ausgangs-E-Rechnungen sind pro Mandant ausdrücklich zu aktivieren. */ +async function outgoingEInvoiceEnabled(server: FastifyInstance, tenantId: number) { + const [tenant] = await server.db.select({ businessInfo: tenants.businessInfo }).from(tenants) + .where(eq(tenants.id, tenantId)).limit(1) + if (!tenant) throw new Error("Mandant nicht gefunden") + return (tenant.businessInfo as any)?.outgoingEInvoiceEnabled === true +} + /** Prüft die Pflichtangaben eines (auch ungespeicherten) Belegs. Andere Belegarten liefern keine Hinweise. */ export async function checkOutgoingEInvoice(server: FastifyInstance, tenantId: number, document: any, options: { requireNumber?: boolean } = {}) { if (!document || !isZugferdDocumentType(document.type)) return [] as ZugferdIssue[] + if (!await outgoingEInvoiceEnabled(server, tenantId)) return [] as ZugferdIssue[] const context = await loadZugferdContext(server, tenantId, document) return checkZugferdRequirements(document, context, options) } @@ -92,11 +101,12 @@ export async function loadZugferdContext(server: FastifyInstance, tenantId: numb } /** - * Macht aus der gerenderten Rechnungs-PDF eine ZUGFeRD-Rechnung. Fehlende Pflichtangaben führen zu + * Bei aktivierter Ausgangs-E-Rechnung wird die PDF zur ZUGFeRD-Rechnung. Fehlende Pflichtangaben führen zu * EInvoiceRequirementsError, damit keine Rechnung ohne gültige E-Rechnung abgelegt wird. */ export async function attachZugferdToPdf(server: FastifyInstance, tenantId: number, document: any, pdf: Buffer) { if (!isZugferdDocument(document)) return { pdf, issues: [] as ZugferdIssue[], einvoice: false } + if (!await outgoingEInvoiceEnabled(server, tenantId)) return { pdf, issues: [] as ZugferdIssue[], einvoice: false } const context = await loadZugferdContext(server, tenantId, document) const { xml, issues } = buildZugferdInvoiceXml(document, context) const blocking = breakingIssues(issues)