From a71ea577b25d1fb5f2fd5a906075470a511f4794 Mon Sep 17 00:00:00 2001 From: flfeders Date: Tue, 11 Aug 2026 13:41:01 +0200 Subject: [PATCH] =?UTF-8?q?DATEV-Automatikkonten=20mit=20Bruttobetr=C3=A4g?= =?UTF-8?q?en=20exportieren?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/utils/export/datev.ts | 6 +++--- backend/tests/datevExport.test.ts | 29 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 backend/tests/datevExport.test.ts diff --git a/backend/src/utils/export/datev.ts b/backend/src/utils/export/datev.ts index 7b8ab81..1182d24 100644 --- a/backend/src/utils/export/datev.ts +++ b/backend/src/utils/export/datev.ts @@ -93,7 +93,7 @@ const getIncomingInvoiceTaxOverride = (invoice: any) => { }; }; -const getCreatedDocumentRevenueLines = (document: any) => { +export const getCreatedDocumentRevenueLines = (document: any) => { const totals = getCreatedDocumentTotal(document); if (document.taxType === "13b UStG") { @@ -105,8 +105,8 @@ const getCreatedDocumentRevenueLines = (document: any) => { } return [ - { account: "8400", amount: Number(totals.net19.toFixed(2)) }, - { account: "8334", amount: Number(totals.net7.toFixed(2)) }, + { account: "8400", amount: Number((totals.net19 + totals.total19).toFixed(2)) }, + { account: "8334", amount: Number((totals.net7 + totals.total7).toFixed(2)) }, { account: "8290", amount: Number(totals.net0.toFixed(2)) }, ].filter((line) => line.amount !== 0); }; diff --git a/backend/tests/datevExport.test.ts b/backend/tests/datevExport.test.ts new file mode 100644 index 0000000..6ee7644 --- /dev/null +++ b/backend/tests/datevExport.test.ts @@ -0,0 +1,29 @@ +import assert from "node:assert/strict"; +import test from "node:test"; +import { getCreatedDocumentRevenueLines } from "../src/utils/export/datev"; + +test("exports gross amounts for DATEV automatic revenue accounts", () => { + const revenueLines = getCreatedDocumentRevenueLines({ + rows: [ + { mode: "position", quantity: 1, price: 100, discountPercent: 0, taxPercent: 19 }, + { mode: "position", quantity: 2, price: 50, discountPercent: 0, taxPercent: 7 }, + { mode: "position", quantity: 1, price: 50, discountPercent: 0, taxPercent: 0 }, + ], + }); + + assert.deepEqual(revenueLines, [ + { account: "8400", amount: 119 }, + { account: "8334", amount: 107 }, + { account: "8290", amount: 50 }, + ]); +}); + +test("preserves negative gross amounts for cancellations", () => { + const revenueLines = getCreatedDocumentRevenueLines({ + rows: [ + { mode: "position", quantity: -1, price: 100, discountPercent: 0, taxPercent: 19 }, + ], + }); + + assert.deepEqual(revenueLines, [{ account: "8400", amount: -119 }]); +});