Developer notes
Technical reference for developers who work with DATEV Export for Accounting. The add-on creates an export file for your tax adviser; it is not DATEV-certified. DATEV is a trademark of DATEV eG.
Add-on identity
Section titled “Add-on identity”| Item | Value |
|---|---|
| Add-on id | kv_datev_export |
| Function prefix | fn_kv_datev_export_ |
| Language variables | kv_datev_export.* |
| CSS scope | .kv-datev |
| PHP namespace | Tygh\Addons\KvDatevExport |
DATEV format conformance
Section titled “DATEV format conformance”Source: the DATEV developer portal, “DATEV Format” (https://developer.datev.de/en/file-formats/details/datev-format/getting-started, /character-set, /format-description, /sample-data). The layout below is checked in tests/unit.php against the official sample data (EXTF_Buchungsstapel.csv, EXTF_DebKred_Stamm.csv; header line, column line and first data line are kept in tests/fixtures/).
| Rule (source) | Implementation | Verified |
|---|---|---|
CSV, fixed prefix EXTF_, line 1 header, line 2 column header line, line 3+ data (Getting started) |
Format::headerLine(), columnLine(), dataLine(); file name EXTF_Buchungsstapel_<from>-<to>.csv |
unit + e2e |
Fields separated by ;, every line ends with CR/LF (Getting started) |
Format::file() joins with \r\n |
unit + e2e |
| Text fields in quotation marks, quotes doubled, no control characters in text (Getting started) | Format::text() |
unit |
| Decimal separator comma, no thousands separator (Getting started) | Format::number() |
unit + e2e |
| Default character set ISO-8859-1 / code page 1252 (Character set) | Format::toCp1252(), no BOM |
unit + e2e (bytes) |
Header: "EXTF";700;21;"Buchungsstapel";13;<created YYYYMMDDHHMMSSfff>;;"RE";"";"";<consultant>;<client>;<fiscal year start YYYYMMDD>;<account length>;<date from>;<date to>;"<label>";"<dictation>";1;0;0;"EUR";;"";;;"03";;;"";"" (31 fields, sample file) |
Format::headerLine() |
unit: byte-identical to the sample header with the sample’s values |
Booking batch column header line, 125 columns from Umsatz (ohne Soll/Haben-Kz) to Abw. Skontokonto (sample file) |
Columns::$booking, generated from the sample |
unit: identical; every data line has 125 fields |
Data line: amount, S/H, currency, … Konto, Gegenkonto (ohne BU-Schlüssel), BU-Schlüssel, Belegdatum (DDMM), Belegfeld 1, Belegfeld 2, Buchungstext (sample file) |
Exporter::bookingLine(); text columns quoted (empty ""), number columns unquoted |
unit: sample data line round trip; e2e field positions |
Debtors/creditors: category 16, format name Debitoren/Kreditoren, format version 5, 254 columns from Konto (sample file) |
Format::headerLine(16), Columns::$debkred, Exporter::debitorFile() |
unit: header identical, 254 fields; e2e |
EU country and VAT ID of a debtor in two columns (DE, 133546770) (sample file) |
Exporter::debitorLine() splits the VAT ID |
e2e |
Not independent of the sample: the field-by-field descriptions of the individual formats are published by DATEV as separate documents that are not freely retrievable; the column order and the header layout above therefore follow the official sample data. Limits of Belegfeld 1 (36 characters; letters, digits and $ & % * + - /) and of the booking text (60 characters) are the documented ones; text beyond them is cut.
Not covered in 1.0: BU keys (the revenue accounts of the standard charts carry the VAT automatically), foreign currencies (the header currency is the store currency and must be EUR), cost centres, document images, recurring bookings, Festschreibung (files are written unlocked: 0).
Booking model
Section titled “Booking model”Mapper::map() (pure PHP, unit tested) turns a normalized document into booking lines:
- Gross amount per VAT rate: tax amount and rate of the order’s tax lines give the gross of the rate; what no tax line explains is the untaxed rest. Rounding differences up to two cents per rate go to the largest rate, so the lines always add up to the order total.
- Revenue account by delivery country and rate: domestic 19/7/0, EU zero VAT = intra-community, EU with VAT = OSS account of the country (error when missing), non-EU = export.
- Optional split of shipping and payment fee onto their own accounts.
- Soll for invoices, Haben for credit notes; optional payment line (clearing account against the debtor).
Data sources
Section titled “Data sources”- Orders:
fn_get_order_info(); parent orders of Multi-Vendor are skipped. kv_invoice_builder(optional):?:kv_ib_documentsfor invoice numbers, issue dates and credit notes (doc_typeI/C), used only when the add-on is active and its table exists.kv_eu_vat_validation(optional):\Tygh\Addons\KvEuVatValidation\Invoice::forOrder()for the buyer VAT ID, guarded like in Invoices & Credit Notes.
Hooks used
Section titled “Hooks used”| Hook | Use |
|---|---|
delete_order |
forgets the export flags of a deleted order |
init_templater_post |
upgrade synchronizer (only while an upgrade is pending) |
Hooks provided
Section titled “Hooks provided”None.
Database tables
Section titled “Database tables”| Table | Content |
|---|---|
?:kv_datev_config |
one JSON settings row per company scope (0 = all vendors / all storefronts) |
?:kv_datev_debitors |
debtor number per customer (registered customers by user id, guests by e-mail hash) with an address snapshot for the master data file |
?:kv_datev_documents |
documents already exported (order, kind, reference, run) |
?:kv_datev_runs |
export history |
Console command
Section titled “Console command”php admin.php --dispatch=kv_datev_export_cron.run writes the scheduled exports (previous day, week or month) of every company scope that has them switched on. Output: one line per scope.
Templates
Section titled “Templates”The add-on has no storefront output. Admin templates live in design/backend/templates/addons/kv_datev_export/.