datev-extf-parser 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -2
- package/cli.js +13 -0
- package/index.d.ts +19 -0
- package/index.js +75 -0
- package/package.json +37 -4
package/README.md
CHANGED
|
@@ -1,3 +1,33 @@
|
|
|
1
|
-
#
|
|
1
|
+
# datev-extf-parser
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Zero-dependency JavaScript / TypeScript parser for **DATEV EXTF Buchungsstapel CSV** files (Germany & Austria, SKR03/SKR04, Format v700).
|
|
4
|
+
|
|
5
|
+
> **Need multi-tab Excel (.xlsx) with Konten-Summen & DATEV validation in your browser?**
|
|
6
|
+
> Use **[radarbg.com/instant/datev-to-excel](https://radarbg.com/instant/datev-to-excel?ref=npm-datev)** · [Download free DATEV EXTF sample CSV](https://radarbg.com/samples/datev-extf-sample-csv?ref=npm-datev) · [Free DATEV Excel template](https://radarbg.com/templates/datev-buchungsstapel-excel-template?ref=npm-datev)
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install datev-extf-parser
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
```js
|
|
17
|
+
const fs = require('fs');
|
|
18
|
+
const { parseDatevExtf, toCsv } = require('datev-extf-parser');
|
|
19
|
+
|
|
20
|
+
const res = parseDatevExtf(fs.readFileSync('EXTF_Buchungsstapel.csv', 'latin1'));
|
|
21
|
+
console.log(res.meta, res.totals, res.bookings);
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## CLI
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npx datev-extf-parser EXTF_Buchungsstapel.csv --json
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Related Online Tools
|
|
31
|
+
- [DATEV EXTF to Excel & Validator](https://radarbg.com/instant/datev-to-excel?ref=npm-datev)
|
|
32
|
+
- [XRechnung 3.0 Viewer](https://radarbg.com/de/xrechnung-auslesen?ref=npm-datev)
|
|
33
|
+
- [Free Accounting Excel Templates](https://radarbg.com/templates?ref=npm-datev)
|
package/cli.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const { parseDatevExtf, toCsv } = require('./index');
|
|
5
|
+
const file = process.argv[2];
|
|
6
|
+
if (!file || file === '-h' || file === '--help') {
|
|
7
|
+
console.log('Usage: datev-extf-parser <EXTF_Buchungsstapel.csv> [--json]');
|
|
8
|
+
console.log('Online DATEV EXTF validator & Excel converter: https://radarbg.com/instant/datev-to-excel?ref=npm-datev');
|
|
9
|
+
process.exit(0);
|
|
10
|
+
}
|
|
11
|
+
const parsed = parseDatevExtf(fs.readFileSync(file, 'latin1'));
|
|
12
|
+
if (process.argv.includes('--json')) console.log(JSON.stringify(parsed, null, 2));
|
|
13
|
+
else process.stdout.write(toCsv(parsed));
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface DatevBooking {
|
|
2
|
+
amount: number;
|
|
3
|
+
sh: string;
|
|
4
|
+
currency: string;
|
|
5
|
+
konto: string;
|
|
6
|
+
gegenkonto: string;
|
|
7
|
+
buSchluessel: string;
|
|
8
|
+
belegdatum: string;
|
|
9
|
+
belegfeld1: string;
|
|
10
|
+
buchungstext: string;
|
|
11
|
+
kost1: string;
|
|
12
|
+
}
|
|
13
|
+
export interface DatevResult {
|
|
14
|
+
meta: Record<string, string>;
|
|
15
|
+
bookings: DatevBooking[];
|
|
16
|
+
totals: { soll: number; haben: number; count: number };
|
|
17
|
+
}
|
|
18
|
+
export declare function parseDatevExtf(text: string): DatevResult;
|
|
19
|
+
export declare function toCsv(parsed: DatevResult): string;
|
package/index.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function splitSemicolon(line) {
|
|
4
|
+
const out = [];
|
|
5
|
+
let cur = '';
|
|
6
|
+
let inQ = false;
|
|
7
|
+
for (let i = 0; i < line.length; i++) {
|
|
8
|
+
const ch = line[i];
|
|
9
|
+
if (ch === '"') {
|
|
10
|
+
if (inQ && line[i + 1] === '"') { cur += '"'; i++; }
|
|
11
|
+
else inQ = !inQ;
|
|
12
|
+
} else if (ch === ';' && !inQ) {
|
|
13
|
+
out.push(cur);
|
|
14
|
+
cur = '';
|
|
15
|
+
} else {
|
|
16
|
+
cur += ch;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
out.push(cur);
|
|
20
|
+
return out;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function parseDatevExtf(text) {
|
|
24
|
+
const lines = String(text || '').replace(/\r\n/g, '\n').split('\n').filter(l => l.trim().length > 0);
|
|
25
|
+
if (lines.length < 3) return { meta: {}, bookings: [], totals: { soll: 0, haben: 0, count: 0 } };
|
|
26
|
+
const h = splitSemicolon(lines[0]);
|
|
27
|
+
const meta = {
|
|
28
|
+
format: h[0] || '',
|
|
29
|
+
version: h[1] || '',
|
|
30
|
+
category: h[3] || '',
|
|
31
|
+
beraterNr: h[10] || '',
|
|
32
|
+
mandantenNr: h[11] || '',
|
|
33
|
+
wjBeginn: h[12] || '',
|
|
34
|
+
currency: h[21] || 'EUR',
|
|
35
|
+
};
|
|
36
|
+
const bookings = [];
|
|
37
|
+
let soll = 0;
|
|
38
|
+
let haben = 0;
|
|
39
|
+
for (let i = 2; i < lines.length; i++) {
|
|
40
|
+
const p = splitSemicolon(lines[i]);
|
|
41
|
+
const amount = parseFloat((p[0] || '0').replace(/\./g, '').replace(',', '.')) || 0;
|
|
42
|
+
const sh = (p[1] || '').toUpperCase();
|
|
43
|
+
if (sh === 'S') soll += amount;
|
|
44
|
+
else if (sh === 'H') haben += amount;
|
|
45
|
+
bookings.push({
|
|
46
|
+
amount: Number(amount.toFixed(2)),
|
|
47
|
+
sh,
|
|
48
|
+
currency: p[2] || meta.currency,
|
|
49
|
+
konto: p[6] || '',
|
|
50
|
+
gegenkonto: p[7] || '',
|
|
51
|
+
buSchluessel: p[8] || '',
|
|
52
|
+
belegdatum: p[9] || '',
|
|
53
|
+
belegfeld1: p[10] || '',
|
|
54
|
+
buchungstext: p[13] || '',
|
|
55
|
+
kost1: p[36] || p[24] || '',
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
meta,
|
|
60
|
+
bookings,
|
|
61
|
+
totals: { soll: Number(soll.toFixed(2)), haben: Number(haben.toFixed(2)), count: bookings.length },
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function toCsv(parsed) {
|
|
66
|
+
const header = ['Amount', 'S/H', 'Currency', 'Konto', 'Gegenkonto', 'BU', 'Belegdatum', 'Belegfeld1', 'Buchungstext'];
|
|
67
|
+
const esc = v => '"' + String(v == null ? '' : v).replace(/"/g, '""') + '"';
|
|
68
|
+
const rows = [header.join(',')];
|
|
69
|
+
for (const b of parsed.bookings || []) {
|
|
70
|
+
rows.push([b.amount.toFixed(2), b.sh, b.currency, b.konto, b.gegenkonto, b.buSchluessel, b.belegdatum, b.belegfeld1, b.buchungstext].map(esc).join(','));
|
|
71
|
+
}
|
|
72
|
+
return rows.join('\n') + '\n';
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
module.exports = { parseDatevExtf, toCsv };
|
package/package.json
CHANGED
|
@@ -1,6 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "datev-extf-parser",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Zero-dependency DATEV EXTF Buchungsstapel CSV parser for German & Austrian accounting (SKR03/SKR04)",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"bin": {
|
|
8
|
+
"datev-extf-parser": "cli.js"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"test": "node test.js"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"datev",
|
|
15
|
+
"extf",
|
|
16
|
+
"buchungsstapel",
|
|
17
|
+
"accounting",
|
|
18
|
+
"germany",
|
|
19
|
+
"skr03",
|
|
20
|
+
"skr04",
|
|
21
|
+
"csv",
|
|
22
|
+
"excel"
|
|
23
|
+
],
|
|
24
|
+
"author": "RadarBG (https://radarbg.com)",
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"homepage": "https://radarbg.com/instant/datev-to-excel?ref=npm-datev",
|
|
27
|
+
"bugs": {
|
|
28
|
+
"url": "https://radarbg.com/support?ref=npm-datev"
|
|
29
|
+
},
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=14.0.0"
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"index.js",
|
|
35
|
+
"index.d.ts",
|
|
36
|
+
"cli.js",
|
|
37
|
+
"README.md"
|
|
38
|
+
]
|
|
39
|
+
}
|