@invoicekit/datev-export
v0.1.0
Published
Generate DATEV-compatible CSV export files (EXTF) from TypeScript
Downloads
127
Maintainers
Readme
@invoicekit/datev-export
Generate DATEV EXTF export files for German accounting software. Supports Buchungsstapel (posting batches) and Debitoren/Kreditoren (master data) exports.
Installation
npm install @invoicekit/datev-exportQuick Start
Buchungsstapel (Posting Batch)
import { generateBuchungsstapel } from "@invoicekit/datev-export";
const result = generateBuchungsstapel(
[
{
umsatz: 119.0,
sollHaben: "S",
konto: 1200,
gegenKonto: 8400,
belegDatum: new Date(2024, 0, 15),
buchungstext: "Rechnung 2024-001",
belegfeld1: "RE-2024-001",
},
],
{
beraternummer: 1234567,
mandantennummer: 1,
wirtschaftsjahrBeginn: new Date(2024, 0, 1),
sachkontenlaenge: 4,
datumVon: new Date(2024, 0, 1),
datumBis: new Date(2024, 11, 31),
kontenrahmen: "SKR03",
},
);Debitoren (Debtor Master Data)
import { generateDebitoren } from "@invoicekit/datev-export";
const result = generateDebitoren(
[
{
konto: 10000,
name1: "Musterfirma GmbH",
strasse: "Musterstraße 1",
plz: "12345",
ort: "Berlin",
land: "DE",
ustIdNr: "DE123456789",
},
],
{
beraternummer: 1234567,
mandantennummer: 1,
wirtschaftsjahrBeginn: new Date(2024, 0, 1),
sachkontenlaenge: 4,
datumVon: new Date(2024, 0, 1),
datumBis: new Date(2024, 11, 31),
},
);Kreditoren (Creditor Master Data)
import { generateKreditoren } from "@invoicekit/datev-export";
const result = generateKreditoren(
[
{
konto: 70000,
name1: "Lieferant AG",
strasse: "Lieferweg 42",
plz: "54321",
ort: "Hamburg",
land: "DE",
zahlungsbedingung: 30,
},
],
{
beraternummer: 1234567,
mandantennummer: 1,
wirtschaftsjahrBeginn: new Date(2024, 0, 1),
sachkontenlaenge: 4,
datumVon: new Date(2024, 0, 1),
datumBis: new Date(2024, 11, 31),
},
);API Reference
generateBuchungsstapel(buchungen, options)
Generates a DATEV EXTF Buchungsstapel file (data category 21).
Parameters:
buchungen: Buchung[]- Array of posting recordsumsatz(number, required) - Amount (positive)sollHaben("S" | "H", required) - Debit/credit indicatorkonto(number, required) - Account numbergegenKonto(number, required) - Contra account numberbelegDatum(Date, required) - Document datebelegfeld1(string, optional) - Document reference field 1belegfeld2(string, optional) - Document reference field 2buchungstext(string, optional, max 60 chars) - Posting textskonto(number, optional) - Cash discount amountkostenstelle1(string, optional) - Cost center 1kostenstelle2(string, optional) - Cost center 2beleglink(string, optional) - Document link
options: BuchungsstapelOptionsberaternummer(number, 1001-9999999) - Tax advisor numbermandantennummer(number, 1-99999) - Client numberwirtschaftsjahrBeginn(Date) - Fiscal year startsachkontenlaenge(number, 4-8) - G/L account lengthdatumVon(Date) - Period startdatumBis(Date) - Period endbezeichnung(string, optional, max 30 chars) - Descriptionkontenrahmen("SKR03" | "SKR04", optional) - Chart of accountsfestschreibung(boolean, optional) - Lock flag
Returns: string - Complete EXTF file content with \r\n line endings.
generateDebitoren(stammdaten, options)
Generates a DATEV EXTF Debitoren/Kreditoren file (data category 16) for debtor accounts.
generateKreditoren(stammdaten, options)
Generates a DATEV EXTF Debitoren/Kreditoren file (data category 16) for creditor accounts.
Parameters (both functions):
stammdaten: DebitKreditStammdaten[]- Array of master data recordskonto(number, required) - Account number (debtors typically 10000-69999, creditors 70000-99999)name1(string, required) - Company name or last namename2(string, optional) - Additional name / first namekurzbezeichnung(string, optional) - Short namestrasse(string, optional) - Street addressplz(string, optional) - Postal codeort(string, optional) - Cityland(string, optional) - Country code (e.g., "DE")telefon(string, optional) - Phone numberemail(string, optional) - Email addressustIdNr(string, optional) - VAT IDsteuernummer(string, optional) - Tax numberzahlungsbedingung(number, optional) - Payment terms
options: StammdatenOptions- Same fields asBuchungsstapelOptionsexcept nofestschreibung.
Returns: string - Complete EXTF file content with \r\n line endings.
generateHeader(options)
Low-level function to generate EXTF header lines (metadata + column headers).
validateBuchungsstapelOptions(options)
Validates BuchungsstapelOptions. Throws on invalid input.
validateBuchung(buchung)
Validates a Buchung record. Throws on invalid input.
encodeWindows1252(input)
Encodes a JavaScript string to a Uint8Array in Windows-1252 encoding.
decodeWindows1252(input)
Decodes a Uint8Array from Windows-1252 encoding to a JavaScript string.
Kontenrahmen (Chart of Accounts)
DATEV supports two standard charts of accounts:
- SKR03 - Process-oriented chart of accounts (Prozessgliederungsprinzip)
- SKR04 - Function-oriented chart of accounts (Abschlussgliederungsprinzip)
The sachkontenlaenge parameter (4-8) determines the length of G/L account numbers:
// SKR03 with 4-digit accounts
{ sachkontenlaenge: 4, kontenrahmen: "SKR03" }
// SKR04 with 5-digit accounts
{ sachkontenlaenge: 5, kontenrahmen: "SKR04" }Encoding Notes
DATEV expects Windows-1252 encoded files. This package generates UTF-8 strings by default. Use encodeWindows1252() when writing files for DATEV import:
import { generateBuchungsstapel, encodeWindows1252 } from "@invoicekit/datev-export";
import { writeFileSync } from "fs";
const csv = generateBuchungsstapel(buchungen, options);
writeFileSync("EXTF_Buchungsstapel.csv", encodeWindows1252(csv));German umlauts (ae, oe, ue, ss) and special characters are fully supported through the Windows-1252 encoding lookup table.
References
- DATEV Format Documentation (German)
- DATEV EXTF Format Specification v7.0
