Compare commits
5 Commits
main
...
feat/optio
| Author | SHA1 | Date | |
|---|---|---|---|
| 809adbfa8a | |||
| 15d58d5c15 | |||
| 08f529fc0d | |||
| ad7e8b77f1 | |||
| d9d12ef58f |
@@ -2,18 +2,37 @@
|
||||
name: 🐛 Bug Report
|
||||
about: Erstelle einen Bericht, um uns zu helfen, das Projekt zu verbessern.
|
||||
title: '[BUG] '
|
||||
labels: Problem
|
||||
labels: bug
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Beschreibung**
|
||||
|
||||
Eine klare und prägnante Beschreibung des Fehlers.
|
||||
|
||||
**Reproduktion**
|
||||
Schritte, um den Fehler zu reproduzieren:
|
||||
|
||||
Entweder:
|
||||
1. Gehe zu '...'
|
||||
2. Klicke auf '...'
|
||||
3. Scrolle runter zu '...'
|
||||
4. Siehe Fehler
|
||||
|
||||
Oder Link zur Seite
|
||||
|
||||
**Erwartetes Verhalten**
|
||||
Eine klare Beschreibung dessen, was du erwartet hast.
|
||||
|
||||
**Screenshots**
|
||||
|
||||
Falls zutreffend, füge hier Screenshots oder Gifs hinzu, um das Problem zu verdeutlichen.
|
||||
|
||||
**Achtung: Achte bitte auf Datenschutz deiner Daten sowie der Daten deiner Kunden. Sollten ein Screenshot nur mit Daten möglich sein, schwärze diese bitte vor dem Upload.**
|
||||
|
||||
**Umgebung:**
|
||||
- Betriebssystem: [z.B. Windows, macOS, Linux]
|
||||
- Browser / Version (falls relevant): [z.B. Chrome 120]
|
||||
- Projekt-Version: [z.B. v1.0.2]
|
||||
|
||||
**Zusätzlicher Kontext**
|
||||
Füge hier alle anderen Informationen zum Problem hinzu.
|
||||
@@ -2,16 +2,19 @@
|
||||
name: ✨ Feature Request
|
||||
about: Schlage eine Idee für dieses Projekt vor.
|
||||
title: '[FEATURE] '
|
||||
labels: Funktionswunsch
|
||||
labels: enhancement
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Ist dein Feature-Wunsch mit einem Problem verbunden?**
|
||||
|
||||
Eine klare Beschreibung des Problems (z.B. "Ich bin immer genervt, wenn...").
|
||||
|
||||
**Lösungsvorschlag**
|
||||
|
||||
Eine klare Beschreibung dessen, was du dir wünschst und wie es funktionieren soll.
|
||||
|
||||
**Alternativen**
|
||||
Hast du über alternative Lösungen oder Workarounds nachgedacht?
|
||||
|
||||
**Zusätzlicher Kontext**
|
||||
Hier ist Platz für weitere Informationen, Skizzen oder Beispiele von anderen Tools.
|
||||
@@ -9,7 +9,7 @@
|
||||
"fill": "ts-node src/webdav/fill-file-sizes.ts",
|
||||
"dev:dav": "tsx watch src/webdav/server.ts",
|
||||
"build": "tsc",
|
||||
"test:einvoice": "tsx --test tests/einvoice.test.ts tests/zugferdInvoice.test.ts",
|
||||
"test:einvoice": "tsx --test tests/einvoice.test.ts tests/zugferdInvoice.test.ts tests/outgoingEInvoiceSettings.test.ts",
|
||||
"start": "node dist/src/index.js",
|
||||
"schema:index": "ts-node scripts/generate-schema-index.ts",
|
||||
"bankcodes:update": "tsx scripts/generate-de-bank-codes.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)
|
||||
|
||||
@@ -278,6 +278,11 @@ export default async function tenantRoutes(server: FastifyInstance) {
|
||||
|
||||
if (!data) return reply.code(400).send({ error: "data required" })
|
||||
|
||||
if (data.businessInfo && Object.prototype.hasOwnProperty.call(data.businessInfo, "outgoingEInvoiceEnabled")
|
||||
&& typeof data.businessInfo.outgoingEInvoiceEnabled !== "boolean") {
|
||||
return reply.code(400).send({ error: "Die Einstellung für Ausgangs-E-Rechnungen muss ein Wahrheitswert sein." })
|
||||
}
|
||||
|
||||
if (Object.prototype.hasOwnProperty.call(data, "portalConfig")) {
|
||||
const config = data.portalConfig
|
||||
if (!config || typeof config !== "object" || Array.isArray(config)
|
||||
|
||||
56
backend/tests/outgoingEInvoiceSettings.test.ts
Normal file
56
backend/tests/outgoingEInvoiceSettings.test.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import assert from "node:assert/strict"
|
||||
import test from "node:test"
|
||||
import { tenants } from "../db/schema"
|
||||
import { PgDialect } from "drizzle-orm/pg-core"
|
||||
import { assertOutgoingEInvoiceRequirements, attachZugferdToPdf, checkOutgoingEInvoice, EInvoiceRequirementsError } from "../src/modules/einvoice/outgoingZugferd.service"
|
||||
|
||||
const invoice = { type: "invoices", documentNumber: "RE-1", payment_type: "sepa", rows: [] }
|
||||
function serverFor(businessInfo: any) {
|
||||
const tenantIds: number[] = []
|
||||
let otherReads = 0
|
||||
const server = { db: { select: () => ({ from: (table: any) => {
|
||||
const rows = table === tenants ? [{ businessInfo }] : []
|
||||
if (table !== tenants) otherReads++
|
||||
const query: any = {
|
||||
where: (condition: any) => {
|
||||
if (table === tenants) tenantIds.push(new PgDialect().sqlToQuery(condition).params[0] as number)
|
||||
return query
|
||||
},
|
||||
limit: async () => rows,
|
||||
then: (resolve: any, reject: any) => Promise.resolve(rows).then(resolve, reject),
|
||||
}
|
||||
return query
|
||||
} }) } } as any
|
||||
return { server, tenantIds, otherReads: () => otherReads }
|
||||
}
|
||||
|
||||
for (const businessInfo of [undefined, {}, { outgoingEInvoiceEnabled: false }, { outgoingEInvoiceEnabled: "true" }]) {
|
||||
test(`disabled/legacy tenant skips e-invoice requirements: ${JSON.stringify(businessInfo)}`, async () => {
|
||||
const { server, tenantIds, otherReads } = serverFor(businessInfo)
|
||||
assert.deepEqual(await checkOutgoingEInvoice(server, 8, invoice), [])
|
||||
await assertOutgoingEInvoiceRequirements(server, 8, invoice)
|
||||
const pdf = Buffer.from("original PDF bytes")
|
||||
const result = await attachZugferdToPdf(server, 8, invoice, pdf)
|
||||
assert.equal(result.pdf, pdf)
|
||||
assert.equal(result.einvoice, false)
|
||||
assert.deepEqual(result.issues, [])
|
||||
assert.deepEqual(tenantIds, [8, 8, 8])
|
||||
assert.equal(otherReads(), 0)
|
||||
})
|
||||
}
|
||||
|
||||
test("enabled tenant still blocks incomplete invoices before finalization and embedding", async () => {
|
||||
const { server, tenantIds } = serverFor({ outgoingEInvoiceEnabled: true })
|
||||
const issues = await checkOutgoingEInvoice(server, 9, invoice)
|
||||
assert.ok(issues.some(issue => issue.type === "breaking"))
|
||||
await assert.rejects(assertOutgoingEInvoiceRequirements(server, 9, invoice), EInvoiceRequirementsError)
|
||||
await assert.rejects(attachZugferdToPdf(server, 9, invoice, Buffer.from("pdf")), EInvoiceRequirementsError)
|
||||
assert.ok(tenantIds.every(id => id === 9))
|
||||
})
|
||||
|
||||
test("document payload cannot disable the tenant setting", async () => {
|
||||
const { server } = serverFor({ outgoingEInvoiceEnabled: true })
|
||||
await assert.rejects(assertOutgoingEInvoiceRequirements(server, 8, {
|
||||
...invoice, businessInfo: { outgoingEInvoiceEnabled: false }, outgoingEInvoiceEnabled: false,
|
||||
}), EInvoiceRequirementsError)
|
||||
})
|
||||
@@ -233,6 +233,7 @@ const activeTelephonyTargetOptions = computed(() => {
|
||||
return telephonyExtensionOptions.value.users || []
|
||||
})
|
||||
const defaultBusinessInfo = {
|
||||
outgoingEInvoiceEnabled: false,
|
||||
name: "",
|
||||
street: "",
|
||||
zip: "",
|
||||
@@ -752,6 +753,13 @@ onMounted(() => {
|
||||
>
|
||||
<UInput v-model="businessInfo.bic"/>
|
||||
</UFormField>
|
||||
<UFormField
|
||||
label="Ausgangs-E-Rechnungen"
|
||||
description="Optional für diesen Mandanten: Bei Aktivierung werden Rechnungs-PDFs mit ZUGFeRD-Daten erstellt und die erforderlichen Angaben geprüft. Deaktiviert werden normale PDFs ohne E-Rechnungsprüfung erstellt. Gilt auch für Serienrechnungen. Bereits gespeicherte Belege und der Empfang von E-Rechnungen bleiben unverändert."
|
||||
class="mt-6"
|
||||
>
|
||||
<USwitch v-model="businessInfo.outgoingEInvoiceEnabled" label="E-Rechnungen erstellen" />
|
||||
</UFormField>
|
||||
<UButton
|
||||
class="mt-3"
|
||||
@click="updateTenant({businessInfo: businessInfo})"
|
||||
|
||||
Reference in New Issue
Block a user