@fin.cx/compatibility 1.1.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/dist_ts/00_commitinfo_data.d.ts +8 -0
- package/dist_ts/00_commitinfo_data.js +9 -0
- package/dist_ts/belegbilder/index.d.ts +19 -0
- package/dist_ts/belegbilder/index.js +31 -0
- package/dist_ts/belegbilder/plugins.d.ts +2 -0
- package/dist_ts/belegbilder/plugins.js +3 -0
- package/dist_ts/encoding/index.d.ts +20 -0
- package/dist_ts/encoding/index.js +46 -0
- package/dist_ts/error.d.ts +10 -0
- package/dist_ts/error.js +8 -0
- package/dist_ts/extf/index.d.ts +62 -0
- package/dist_ts/extf/index.js +78 -0
- package/dist_ts/extf/plugins.d.ts +2 -0
- package/dist_ts/extf/plugins.js +3 -0
- package/dist_ts/index.d.ts +4 -0
- package/dist_ts/index.js +5 -0
- package/license.md +20 -0
- package/package.json +65 -0
- package/readme.md +92 -0
- package/ts/00_commitinfo_data.ts +8 -0
- package/ts/belegbilder/index.ts +54 -0
- package/ts/belegbilder/plugins.ts +3 -0
- package/ts/encoding/index.ts +59 -0
- package/ts/error.ts +16 -0
- package/ts/extf/index.ts +126 -0
- package/ts/extf/plugins.ts +3 -0
- package/ts/index.ts +4 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* autocreated commitinfo by @push.rocks/commitinfo
|
|
3
|
+
*/
|
|
4
|
+
export const commitinfo = {
|
|
5
|
+
name: '@fin.cx/compatibility',
|
|
6
|
+
version: '1.1.0',
|
|
7
|
+
description: 'Exchange formats of third-party accounting systems: the EXTF Buchungsstapel in Windows-1252 on the rows of @fin.cx/skr, and the document-image archive (document.xml and ZIP)'
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiMDBfY29tbWl0aW5mb19kYXRhLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvMDBfY29tbWl0aW5mb19kYXRhLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOztHQUVHO0FBQ0gsTUFBTSxDQUFDLE1BQU0sVUFBVSxHQUFHO0lBQ3hCLElBQUksRUFBRSx1QkFBdUI7SUFDN0IsT0FBTyxFQUFFLE9BQU87SUFDaEIsV0FBVyxFQUFFLCtLQUErSztDQUM3TCxDQUFBIn0=
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** A document image of the archive, linked to its bookings through the GUID in their Beleglink (field 20). */
|
|
2
|
+
export interface IBelegbilderDocument {
|
|
3
|
+
guid: string;
|
|
4
|
+
description: string;
|
|
5
|
+
}
|
|
6
|
+
export interface IBelegbilderEntry extends IBelegbilderDocument {
|
|
7
|
+
/** the document as PDF */
|
|
8
|
+
bytes: Uint8Array;
|
|
9
|
+
}
|
|
10
|
+
export declare const BELEGBILDER_CONTENT_TYPE = "application/zip";
|
|
11
|
+
/** `DATEV_Belege_<label>.zip`, for example `DATEV_Belege_2026-03.zip`. */
|
|
12
|
+
export declare const belegbilderFilename: (labelArg: string) => string;
|
|
13
|
+
/**
|
|
14
|
+
* The manifest of the archive, `document.xml`: one `<document>` per PDF,
|
|
15
|
+
* named by its GUID. UTF-8, unlike the Buchungsstapel.
|
|
16
|
+
*/
|
|
17
|
+
export declare const buildDocumentXml: (documentsArg: readonly IBelegbilderDocument[]) => string;
|
|
18
|
+
/** `document.xml` and one `<GUID>.pdf` per document, as one ZIP. */
|
|
19
|
+
export declare const createBelegbilderZip: (entriesArg: readonly IBelegbilderEntry[]) => Promise<Uint8Array>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as plugins from './plugins.js';
|
|
2
|
+
export const BELEGBILDER_CONTENT_TYPE = 'application/zip';
|
|
3
|
+
/** `DATEV_Belege_<label>.zip`, for example `DATEV_Belege_2026-03.zip`. */
|
|
4
|
+
export const belegbilderFilename = (labelArg) => `DATEV_Belege_${labelArg}.zip`;
|
|
5
|
+
const escapeXml = (valueArg) => valueArg
|
|
6
|
+
.replace(/&/gu, '&')
|
|
7
|
+
.replace(/</gu, '<')
|
|
8
|
+
.replace(/>/gu, '>')
|
|
9
|
+
.replace(/"/gu, '"')
|
|
10
|
+
.replace(/'/gu, ''');
|
|
11
|
+
/**
|
|
12
|
+
* The manifest of the archive, `document.xml`: one `<document>` per PDF,
|
|
13
|
+
* named by its GUID. UTF-8, unlike the Buchungsstapel.
|
|
14
|
+
*/
|
|
15
|
+
export const buildDocumentXml = (documentsArg) => {
|
|
16
|
+
const lines = ['<?xml version="1.0" encoding="UTF-8"?>', '<archive>', ' <content>'];
|
|
17
|
+
for (const document of documentsArg) {
|
|
18
|
+
lines.push(` <document guid="${escapeXml(document.guid)}">`, ' <extension>PDF</extension>', ` <filename>${escapeXml(document.guid)}.pdf</filename>`, ' <beleg_type>1</beleg_type>', ...(document.description ? [` <description>${escapeXml(document.description)}</description>`] : []), ' </document>');
|
|
19
|
+
}
|
|
20
|
+
lines.push(' </content>', '</archive>', '');
|
|
21
|
+
return lines.join('\n');
|
|
22
|
+
};
|
|
23
|
+
/** `document.xml` and one `<GUID>.pdf` per document, as one ZIP. */
|
|
24
|
+
export const createBelegbilderZip = async (entriesArg) => {
|
|
25
|
+
const zipTools = new plugins.smartarchiveZip.ZipTools();
|
|
26
|
+
return zipTools.createZip([
|
|
27
|
+
{ archivePath: 'document.xml', content: buildDocumentXml(entriesArg) },
|
|
28
|
+
...entriesArg.map((entryArg) => ({ archivePath: `${entryArg.guid}.pdf`, content: entryArg.bytes })),
|
|
29
|
+
]);
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi90cy9iZWxlZ2JpbGRlci9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSx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JjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3RzL2JlbGVnYmlsZGVyL3BsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLGVBQWUsTUFBTSxrQ0FBa0MsQ0FBQztBQUVwRSxPQUFPLEVBQUUsZUFBZSxFQUFFLENBQUMifQ==
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** What stands for a character Windows-1252 cannot write. */
|
|
2
|
+
export declare const WINDOWS_1252_REPLACEMENT = "?";
|
|
3
|
+
/** A character that was written as `?`, with its position in the text (UTF-16 offset). */
|
|
4
|
+
export interface IReplacedCharacter {
|
|
5
|
+
offset: number;
|
|
6
|
+
character: string;
|
|
7
|
+
}
|
|
8
|
+
export interface IWindows1252Result {
|
|
9
|
+
bytes: Uint8Array;
|
|
10
|
+
/** in text order; empty when every character could be written */
|
|
11
|
+
replaced: IReplacedCharacter[];
|
|
12
|
+
}
|
|
13
|
+
/** The byte of a code point in Windows-1252, or undefined. */
|
|
14
|
+
export declare const windows1252ByteOf: (codePointArg: number) => number | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Encodes text in Windows-1252. A character the encoding cannot write
|
|
17
|
+
* becomes one `?` and is listed in `replaced`, so the caller can say which
|
|
18
|
+
* text lost which character; nothing is replaced unreported.
|
|
19
|
+
*/
|
|
20
|
+
export declare const encodeWindows1252: (textArg: string) => IWindows1252Result;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Windows-1252 as the WHATWG Encoding Standard defines it: bytes 0x00–0x7F
|
|
3
|
+
* and 0xA0–0xFF are the code points of the same number, and 0x80–0x9F carry
|
|
4
|
+
* the 27 characters below. The five bytes the standard leaves to C1 controls
|
|
5
|
+
* (0x81, 0x8D, 0x8F, 0x90, 0x9D) and every other C1 control are not written:
|
|
6
|
+
* no accounting text holds them.
|
|
7
|
+
*/
|
|
8
|
+
const HIGH_BYTES = [
|
|
9
|
+
[0x20ac, 0x80], [0x201a, 0x82], [0x0192, 0x83], [0x201e, 0x84], [0x2026, 0x85], [0x2020, 0x86], [0x2021, 0x87],
|
|
10
|
+
[0x02c6, 0x88], [0x2030, 0x89], [0x0160, 0x8a], [0x2039, 0x8b], [0x0152, 0x8c], [0x017d, 0x8e], [0x2018, 0x91],
|
|
11
|
+
[0x2019, 0x92], [0x201c, 0x93], [0x201d, 0x94], [0x2022, 0x95], [0x2013, 0x96], [0x2014, 0x97], [0x02dc, 0x98],
|
|
12
|
+
[0x2122, 0x99], [0x0161, 0x9a], [0x203a, 0x9b], [0x0153, 0x9c], [0x017e, 0x9e], [0x0178, 0x9f],
|
|
13
|
+
];
|
|
14
|
+
const HIGH_BYTE_OF = new Map(HIGH_BYTES);
|
|
15
|
+
/** What stands for a character Windows-1252 cannot write. */
|
|
16
|
+
export const WINDOWS_1252_REPLACEMENT = '?';
|
|
17
|
+
/** The byte of a code point in Windows-1252, or undefined. */
|
|
18
|
+
export const windows1252ByteOf = (codePointArg) => {
|
|
19
|
+
if (codePointArg <= 0x7f || (codePointArg >= 0xa0 && codePointArg <= 0xff)) {
|
|
20
|
+
return codePointArg;
|
|
21
|
+
}
|
|
22
|
+
return HIGH_BYTE_OF.get(codePointArg);
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Encodes text in Windows-1252. A character the encoding cannot write
|
|
26
|
+
* becomes one `?` and is listed in `replaced`, so the caller can say which
|
|
27
|
+
* text lost which character; nothing is replaced unreported.
|
|
28
|
+
*/
|
|
29
|
+
export const encodeWindows1252 = (textArg) => {
|
|
30
|
+
const bytes = [];
|
|
31
|
+
const replaced = [];
|
|
32
|
+
let offset = 0;
|
|
33
|
+
for (const character of textArg) {
|
|
34
|
+
const byte = windows1252ByteOf(character.codePointAt(0) ?? 0);
|
|
35
|
+
if (byte === undefined) {
|
|
36
|
+
bytes.push(WINDOWS_1252_REPLACEMENT.charCodeAt(0));
|
|
37
|
+
replaced.push({ offset, character });
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
bytes.push(byte);
|
|
41
|
+
}
|
|
42
|
+
offset += character.length;
|
|
43
|
+
}
|
|
44
|
+
return { bytes: Uint8Array.from(bytes), replaced };
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi90cy9lbmNvZGluZy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7Ozs7O0dBTUc7QUFDSCxNQUFNLFVBQVUsR0FBNkM7SUFDM0QsQ0FBQyxNQUFNLEVBQUUsSUFBSSxDQUFDLEVBQUUsQ0FBQyxNQUFNLEVBQUUsSUFBSSxDQUFDLEVBQUUsQ0FBQyxNQUFNLEVBQUUsSUFBSSxDQUFDLEVBQUUsQ0FBQyxNQUFNLEVBQUUsSUFBSSxDQUFDLEVBQUUsQ0FBQyxNQUFNLEVBQUUsSUFBSSxDQUFDLEVBQUUsQ0FBQyxNQUFNLEVBQUUsSUFBSSxDQUFDLEVBQUUsQ0FBQyxNQUFNLEVBQUUsSUFBSSxDQUFDO0lBQzlHLENBQUMsTUFBTSxFQUFFLElBQUksQ0FBQyxFQUFFLENBQUMsTUFBTSxFQUFFLElBQUksQ0FBQyxFQUFFLENBQUMsTUFBTSxFQUFFLElBQUksQ0FBQyxFQUFFLENBQUMsTUFBTSxFQUFFLElBQUksQ0FBQyxFQUFFLENBQUMsTUFBTSxFQUFFLElBQUksQ0FBQyxFQUFFLENBQUMsTUFBTSxFQUFFLElBQUksQ0FBQyxFQUFFLENBQUMsTUFBTSxFQUFFLElBQUksQ0FBQztJQUM5RyxDQUFDLE1BQU0sRUFBRSxJQUFJLENBQUMsRUFBRSxDQUFDLE1BQU0sRUFBRSxJQUFJLENBQUMsRUFBRSxDQUFDLE1BQU0sRUFBRSxJQUFJLENBQUM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HQUF5QixFQUFFLENBQUM7SUFDMUMsSUFBSSxNQUFNLEdBQUcsQ0FBQyxDQUFDO0lBQ2YsS0FBSyxNQUFNLFNBQVMsSUFBSSxPQUFPLEVBQUUsQ0FBQztRQUNoQyxNQUFNLElBQUksR0FBRyxpQkFBaUIsQ0FBQyxTQUFTLENBQUMsV0FBVyxDQUFDLENBQUMsQ0FBQyxJQUFJLENBQUMsQ0FBQyxDQUFDO1FBQzlELElBQUksSUFBSSxLQUFLLFNBQVMsRUFBRSxDQUFDO1lBQ3ZCLEtBQUssQ0FBQyxJQUFJLENBQUMsd0JBQXdCLENBQUMsVUFBVSxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUM7WUFDbkQsUUFBUSxDQUFDLElBQUksQ0FBQyxFQUFFLE1BQU0sRUFBRSxTQUFTLEVBQUUsQ0FBQyxDQUFDO1FBQ3ZDLENBQUM7YUFBTSxDQUFDO1lBQ04sS0FBSyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsQ0FBQztRQUNuQixDQUFDO1FBQ0QsTUFBTSxJQUFJLFNBQVMsQ0FBQyxNQUFNLENBQUM7SUFDN0IsQ0FBQztJQUNELE9BQU8sRUFBRSxLQUFLLEVBQUUsVUFBVSxDQUFDLElBQUksQ0FBQyxLQUFLLENBQUMsRUFBRSxRQUFRLEVBQUUsQ0FBQztBQUNyRCxDQUFDLENBQUMifQ==
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Why an exchange file could not be written:
|
|
3
|
+
* - `invalid_bookings`: a draft the account policy refuses; the message names it;
|
|
4
|
+
* - `export_failed`: the conversion into rows failed.
|
|
5
|
+
*/
|
|
6
|
+
export type TCompatibilityErrorCode = 'invalid_bookings' | 'export_failed';
|
|
7
|
+
export declare class CompatibilityError extends Error {
|
|
8
|
+
readonly code: TCompatibilityErrorCode;
|
|
9
|
+
constructor(codeArg: TCompatibilityErrorCode, messageArg: string);
|
|
10
|
+
}
|
package/dist_ts/error.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export class CompatibilityError extends Error {
|
|
2
|
+
constructor(codeArg, messageArg) {
|
|
3
|
+
super(messageArg);
|
|
4
|
+
this.name = 'CompatibilityError';
|
|
5
|
+
this.code = codeArg;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXJyb3IuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9lcnJvci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFPQSxNQUFNLE9BQU8sa0JBQW1CLFNBQVEsS0FBSztJQUczQyxZQUFZLE9BQWdDLEVBQUUsVUFBa0I7UUFDOUQsS0FBSyxDQUFDLFVBQVUsQ0FBQyxDQUFDO1FBQ2xCLElBQUksQ0FBQyxJQUFJLEdBQUcsb0JBQW9CLENBQUM7UUFDakMsSUFBSSxDQUFDLElBQUksR0FBRyxPQUFPLENBQUM7SUFDdEIsQ0FBQztDQUNGIn0=
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import * as plugins from './plugins.js';
|
|
2
|
+
import { type IReplacedCharacter } from '../encoding/index.js';
|
|
3
|
+
export { CompatibilityError, type TCompatibilityErrorCode } from '../error.js';
|
|
4
|
+
export type IDatevBuchungsstapelRow = plugins.skrCore.IDatevBuchungsstapelRow;
|
|
5
|
+
export type IDatevExtfHeaderOptions = plugins.skrCore.IDatevExtfHeaderOptions;
|
|
6
|
+
/** The media type of a Buchungsstapel file: the reading side expects Windows-1252. */
|
|
7
|
+
export declare const EXTF_CONTENT_TYPE = "text/csv; charset=windows-1252";
|
|
8
|
+
/** `EXTF_Buchungsstapel_<label>.csv`, for example `EXTF_Buchungsstapel_2026-03.csv`. */
|
|
9
|
+
export declare const extfFilename: (labelArg: string) => string;
|
|
10
|
+
/** One booking of a Buchungsstapel as it can be compared and kept: what a row says, without its layout. */
|
|
11
|
+
export interface IExportBooking {
|
|
12
|
+
umsatzCents: number;
|
|
13
|
+
sollHaben: 'S' | 'H';
|
|
14
|
+
konto: string;
|
|
15
|
+
gegenkonto: string;
|
|
16
|
+
buKey: string;
|
|
17
|
+
/** the Belegdatum, `YYYY-MM-DD` */
|
|
18
|
+
date: string;
|
|
19
|
+
belegfeld1?: string;
|
|
20
|
+
belegfeld2?: string;
|
|
21
|
+
text: string;
|
|
22
|
+
/** the document GUID the row links to (field 20, `BEDI "GUID"`) */
|
|
23
|
+
documentGuid?: string;
|
|
24
|
+
}
|
|
25
|
+
/** The bookings of rows, in their order. */
|
|
26
|
+
export declare const bookingsOfRows: (rowsArg: readonly IDatevBuchungsstapelRow[]) => IExportBooking[];
|
|
27
|
+
/**
|
|
28
|
+
* How many rows two Buchungsstapel of one period do not share, compared on
|
|
29
|
+
* what a booking says (its day, amount, side, accounts, BU key and Belegfeld
|
|
30
|
+
* 1) and not on its wording or its document link. The rows are compared as a
|
|
31
|
+
* multiset: a row that stands twice in one and once in the other differs once.
|
|
32
|
+
*/
|
|
33
|
+
export declare const differingBookingCount: (leftArg: readonly IExportBooking[], rightArg: readonly IExportBooking[]) => number;
|
|
34
|
+
/**
|
|
35
|
+
* Checks every draft against the account policy and turns the drafts into
|
|
36
|
+
* Buchungsstapel rows (`@fin.cx/skr` `journalDraftsToDatevRows`, not fixed).
|
|
37
|
+
* A draft the policy refuses throws `invalid_bookings`, naming the draft; a
|
|
38
|
+
* failure of the conversion throws `export_failed`.
|
|
39
|
+
*/
|
|
40
|
+
export declare const datevRowsOf: (draftsArg: readonly plugins.skrCore.IJournalDraft[], policyArg: plugins.skrCore.IAccountPolicy) => IDatevBuchungsstapelRow[];
|
|
41
|
+
export interface IBuchungsstapelOptions {
|
|
42
|
+
drafts: readonly plugins.skrCore.IJournalDraft[];
|
|
43
|
+
/** the policy the drafts are checked against */
|
|
44
|
+
policy: plugins.skrCore.IAccountPolicy;
|
|
45
|
+
/** the header of the file; its `festschreibung` is written as given */
|
|
46
|
+
header: IDatevExtfHeaderOptions;
|
|
47
|
+
/** the file's name, for example `extfFilename('2026-03')` */
|
|
48
|
+
filename: string;
|
|
49
|
+
}
|
|
50
|
+
export interface IBuchungsstapelFile {
|
|
51
|
+
filename: string;
|
|
52
|
+
/** the file as text, lines ending in CRLF */
|
|
53
|
+
csv: string;
|
|
54
|
+
/** the file in Windows-1252, as it is handed over */
|
|
55
|
+
bytes: Uint8Array;
|
|
56
|
+
rows: IDatevBuchungsstapelRow[];
|
|
57
|
+
bookings: IExportBooking[];
|
|
58
|
+
/** the characters Windows-1252 cannot write, each written as `?` */
|
|
59
|
+
replacedCharacters: IReplacedCharacter[];
|
|
60
|
+
}
|
|
61
|
+
/** Writes a Buchungsstapel: the rows of the drafts, the header and the caption row, encoded in Windows-1252. */
|
|
62
|
+
export declare const writeBuchungsstapel: (optionsArg: IBuchungsstapelOptions) => IBuchungsstapelFile;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import * as plugins from './plugins.js';
|
|
2
|
+
import { CompatibilityError } from '../error.js';
|
|
3
|
+
import { encodeWindows1252 } from '../encoding/index.js';
|
|
4
|
+
export { CompatibilityError } from '../error.js';
|
|
5
|
+
/** The media type of a Buchungsstapel file: the reading side expects Windows-1252. */
|
|
6
|
+
export const EXTF_CONTENT_TYPE = 'text/csv; charset=windows-1252';
|
|
7
|
+
/** `EXTF_Buchungsstapel_<label>.csv`, for example `EXTF_Buchungsstapel_2026-03.csv`. */
|
|
8
|
+
export const extfFilename = (labelArg) => `EXTF_Buchungsstapel_${labelArg}.csv`;
|
|
9
|
+
/** The GUID inside a Beleglink value (`BEDI "GUID"` or the bare GUID). */
|
|
10
|
+
const guidOfLink = (linkArg) => linkArg.replace(/^BEDI\s*/iu, '').replace(/^"+|"+$/gu, '').trim();
|
|
11
|
+
/** The bookings of rows, in their order. */
|
|
12
|
+
export const bookingsOfRows = (rowsArg) => rowsArg.map((rowArg) => ({
|
|
13
|
+
umsatzCents: rowArg.umsatzCents,
|
|
14
|
+
sollHaben: rowArg.sollHaben,
|
|
15
|
+
konto: rowArg.konto,
|
|
16
|
+
gegenkonto: rowArg.gegenKonto,
|
|
17
|
+
buKey: rowArg.buSchluessel,
|
|
18
|
+
date: rowArg.belegDatum.toISOString().slice(0, 10),
|
|
19
|
+
...(rowArg.belegfeld1 ? { belegfeld1: rowArg.belegfeld1 } : {}),
|
|
20
|
+
...(rowArg.belegfeld2 ? { belegfeld2: rowArg.belegfeld2 } : {}),
|
|
21
|
+
text: rowArg.buchungstext,
|
|
22
|
+
...(rowArg.belegLink ? { documentGuid: guidOfLink(rowArg.belegLink) } : {}),
|
|
23
|
+
}));
|
|
24
|
+
/**
|
|
25
|
+
* How many rows two Buchungsstapel of one period do not share, compared on
|
|
26
|
+
* what a booking says (its day, amount, side, accounts, BU key and Belegfeld
|
|
27
|
+
* 1) and not on its wording or its document link. The rows are compared as a
|
|
28
|
+
* multiset: a row that stands twice in one and once in the other differs once.
|
|
29
|
+
*/
|
|
30
|
+
export const differingBookingCount = (leftArg, rightArg) => {
|
|
31
|
+
const keyOf = (bookingArg) => [bookingArg.date, bookingArg.umsatzCents, bookingArg.sollHaben, bookingArg.konto, bookingArg.gegenkonto, bookingArg.buKey, bookingArg.belegfeld1 ?? ''].join('|');
|
|
32
|
+
const unmatched = new Map();
|
|
33
|
+
for (const booking of leftArg) {
|
|
34
|
+
unmatched.set(keyOf(booking), (unmatched.get(keyOf(booking)) ?? 0) + 1);
|
|
35
|
+
}
|
|
36
|
+
let differing = 0;
|
|
37
|
+
for (const booking of rightArg) {
|
|
38
|
+
const left = unmatched.get(keyOf(booking)) ?? 0;
|
|
39
|
+
if (left > 0) {
|
|
40
|
+
unmatched.set(keyOf(booking), left - 1);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
differing += 1;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
for (const left of unmatched.values()) {
|
|
47
|
+
differing += left;
|
|
48
|
+
}
|
|
49
|
+
return differing;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Checks every draft against the account policy and turns the drafts into
|
|
53
|
+
* Buchungsstapel rows (`@fin.cx/skr` `journalDraftsToDatevRows`, not fixed).
|
|
54
|
+
* A draft the policy refuses throws `invalid_bookings`, naming the draft; a
|
|
55
|
+
* failure of the conversion throws `export_failed`.
|
|
56
|
+
*/
|
|
57
|
+
export const datevRowsOf = (draftsArg, policyArg) => {
|
|
58
|
+
for (const draft of draftsArg) {
|
|
59
|
+
const validation = plugins.skrCore.validateJournalDraft(draft, policyArg);
|
|
60
|
+
if (!validation.valid) {
|
|
61
|
+
throw new CompatibilityError('invalid_bookings', `draft "${draft.description}": ${validation.errors.join('; ')}`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
try {
|
|
65
|
+
return plugins.skrCore.journalDraftsToDatevRows([...draftsArg], { festschreibung: false });
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
throw new CompatibilityError('export_failed', error instanceof Error ? error.message : String(error));
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
/** Writes a Buchungsstapel: the rows of the drafts, the header and the caption row, encoded in Windows-1252. */
|
|
72
|
+
export const writeBuchungsstapel = (optionsArg) => {
|
|
73
|
+
const rows = datevRowsOf(optionsArg.drafts, optionsArg.policy);
|
|
74
|
+
const { csv } = plugins.skrCore.writeExtfBuchungsstapel(rows, optionsArg.header);
|
|
75
|
+
const { bytes, replaced } = encodeWindows1252(csv);
|
|
76
|
+
return { filename: optionsArg.filename, csv, bytes, rows, bookings: bookingsOfRows(rows), replacedCharacters: replaced };
|
|
77
|
+
};
|
|
78
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi90cy9leHRmL2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU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QUFNLENBQUMsQ0FBQztJQUNqRixNQUFNLEVBQUUsS0FBSyxFQUFFLFFBQVEsRUFBRSxHQUFHLGlCQUFpQixDQUFDLEdBQUcsQ0FBQyxDQUFDO0lBQ25ELE9BQU8sRUFBRSxRQUFRLEVBQUUsVUFBVSxDQUFDLFFBQVEsRUFBRSxHQUFHLEVBQUUsS0FBSyxFQUFFLElBQUksRUFBRSxRQUFRLEVBQUUsY0FBYyxDQUFDLElBQUksQ0FBQyxFQUFFLGtCQUFrQixFQUFFLFFBQVEsRUFBRSxDQUFDO0FBQzNILENBQUMsQ0FBQyJ9
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import * as skrCore from '@fin.cx/skr/core';
|
|
2
|
+
export { skrCore };
|
|
3
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3RzL2V4dGYvcGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssT0FBTyxNQUFNLGtCQUFrQixDQUFDO0FBRTVDLE9BQU8sRUFBRSxPQUFPLEVBQUUsQ0FBQyJ9
|
package/dist_ts/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export * from './error.js';
|
|
2
|
+
export * from './encoding/index.js';
|
|
3
|
+
export * as extf from './extf/index.js';
|
|
4
|
+
export * as belegbilder from './belegbilder/index.js';
|
|
5
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxjQUFjLFlBQVksQ0FBQztBQUMzQixjQUFjLHFCQUFxQixDQUFDO0FBQ3BDLE9BQU8sS0FBSyxJQUFJLE1BQU0saUJBQWlCLENBQUM7QUFDeEMsT0FBTyxLQUFLLFdBQVcsTUFBTSx3QkFBd0IsQ0FBQyJ9
|
package/license.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Task Venture Capital GmbH
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
SOFTWARE.
|
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fin.cx/compatibility",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "Exchange formats of third-party accounting systems: the EXTF Buchungsstapel in Windows-1252 on the rows of @fin.cx/skr, and the document-image archive (document.xml and ZIP)",
|
|
6
|
+
"main": "dist_ts/index.js",
|
|
7
|
+
"typings": "dist_ts/index.d.ts",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist_ts/index.d.ts",
|
|
12
|
+
"default": "./dist_ts/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./extf": {
|
|
15
|
+
"types": "./dist_ts/extf/index.d.ts",
|
|
16
|
+
"default": "./dist_ts/extf/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./belegbilder": {
|
|
19
|
+
"types": "./dist_ts/belegbilder/index.d.ts",
|
|
20
|
+
"default": "./dist_ts/belegbilder/index.js"
|
|
21
|
+
},
|
|
22
|
+
"./package.json": "./package.json"
|
|
23
|
+
},
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "https://code.foss.global/fin.cx/compatibility.git"
|
|
27
|
+
},
|
|
28
|
+
"keywords": [
|
|
29
|
+
"extf",
|
|
30
|
+
"buchungsstapel",
|
|
31
|
+
"belegbilder",
|
|
32
|
+
"windows-1252",
|
|
33
|
+
"accounting",
|
|
34
|
+
"export",
|
|
35
|
+
"german",
|
|
36
|
+
"typescript"
|
|
37
|
+
],
|
|
38
|
+
"author": "fin.cx",
|
|
39
|
+
"license": "MIT",
|
|
40
|
+
"bugs": {
|
|
41
|
+
"url": "https://code.foss.global/fin.cx/compatibility/issues"
|
|
42
|
+
},
|
|
43
|
+
"homepage": "https://code.foss.global/fin.cx/compatibility#readme",
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@fin.cx/skr": "^4.0.0",
|
|
46
|
+
"@push.rocks/smartarchive": "^5.4.1"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@git.zone/tsbuild": "^5.0.0",
|
|
50
|
+
"@git.zone/tsrun": "^3.0.1",
|
|
51
|
+
"@git.zone/tstest": "^6.3.2",
|
|
52
|
+
"@types/node": "^26.6.2"
|
|
53
|
+
},
|
|
54
|
+
"files": [
|
|
55
|
+
"ts/**/*",
|
|
56
|
+
"dist_ts/**/*",
|
|
57
|
+
"readme.md",
|
|
58
|
+
"license.md"
|
|
59
|
+
],
|
|
60
|
+
"scripts": {
|
|
61
|
+
"test": "(tstest test/ --verbose)",
|
|
62
|
+
"build": "(tsbuild)",
|
|
63
|
+
"buildDocs": "tsdoc"
|
|
64
|
+
}
|
|
65
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# @fin.cx/compatibility
|
|
2
|
+
|
|
3
|
+
Exchange formats of third-party accounting systems: the files a German tax advisor's system imports. The package's name carries no vendor's name; the formats and files keep the names the importing system expects (EXTF, `DATEV_Belege_<label>.zip`, the Datev field names in `@fin.cx/skr`'s rows). Two formats, each on its own entry point:
|
|
4
|
+
|
|
5
|
+
- `@fin.cx/compatibility/extf`: the **EXTF Buchungsstapel**. The rows and the text come from `@fin.cx/skr` (`journalDraftsToDatevRows`, `writeExtfBuchungsstapel`); this module checks the drafts, writes the file in Windows-1252 and says which characters the encoding could not hold.
|
|
6
|
+
- `@fin.cx/compatibility/belegbilder`: the **document-image archive**, a `document.xml` manifest plus one `<GUID>.pdf` per document, as one ZIP, linked to the bookings through the GUID in their Beleglink (field 20).
|
|
7
|
+
|
|
8
|
+
It reads no clock, keeps no state and writes nothing anywhere: files go back to the caller as bytes.
|
|
9
|
+
|
|
10
|
+
## Issue Reporting and Security
|
|
11
|
+
|
|
12
|
+
For reporting bugs, issues, or security vulnerabilities, please visit [community.foss.global/](https://community.foss.global/). This is the central community hub for all issue reporting. Developers who sign and comply with our contribution agreement and go through identification can also get a [code.foss.global/](https://code.foss.global/) account to submit Pull Requests directly.
|
|
13
|
+
|
|
14
|
+
## Install
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pnpm install @fin.cx/compatibility
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
import * as skrCore from '@fin.cx/skr/core';
|
|
24
|
+
import { extf } from '@fin.cx/compatibility';
|
|
25
|
+
// or: import * as extf from '@fin.cx/compatibility/extf';
|
|
26
|
+
|
|
27
|
+
const file = extf.writeBuchungsstapel({
|
|
28
|
+
drafts, // skrCore.IJournalDraft[] of the period
|
|
29
|
+
policy: skrCore.SKR03_DEFAULT_POLICY,
|
|
30
|
+
header: {
|
|
31
|
+
createdAt: new Date(),
|
|
32
|
+
consultantNumber: 1001,
|
|
33
|
+
clientNumber: 1,
|
|
34
|
+
fiscalYearStart: new Date('2026-01-01T00:00:00Z'),
|
|
35
|
+
dateFrom: new Date('2026-03-01T00:00:00Z'),
|
|
36
|
+
dateTo: new Date('2026-03-31T00:00:00Z'),
|
|
37
|
+
label: 'Buchungsstapel 2026-03',
|
|
38
|
+
festschreibung: false,
|
|
39
|
+
},
|
|
40
|
+
filename: extf.extfFilename('2026-03'), // EXTF_Buchungsstapel_2026-03.csv
|
|
41
|
+
});
|
|
42
|
+
file.bytes; // Uint8Array in Windows-1252, served as extf.EXTF_CONTENT_TYPE
|
|
43
|
+
file.bookings; // what each row says, for keeping and comparing
|
|
44
|
+
file.replacedCharacters; // [{ offset, character: 'ő' }, …]: written as "?"
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
- **A draft the account policy refuses** throws `CompatibilityError` with code `invalid_bookings` and a message naming the draft.
|
|
48
|
+
- **A failed conversion** throws code `export_failed`.
|
|
49
|
+
- **`differingBookingCount(left, right)`** counts the rows two Stapel of one period do not share. It compares each booking's day, amount, side, accounts, BU key and Belegfeld 1, as a multiset, and ignores wording and document links.
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
import { belegbilder } from '@fin.cx/compatibility';
|
|
53
|
+
|
|
54
|
+
const zip = await belegbilder.createBelegbilderZip([{ guid, description: 'Rechnung 7', bytes: pdfBytes }]);
|
|
55
|
+
// served as belegbilder.BELEGBILDER_CONTENT_TYPE under belegbilder.belegbilderFilename('2026-03')
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Windows-1252
|
|
59
|
+
|
|
60
|
+
`encodeWindows1252(text)` follows the WHATWG Encoding Standard. Bytes 0x00–0x7F and 0xA0–0xFF are the code points of the same number, and 0x80–0x9F carry the 27 characters € ‚ ƒ „ … † ‡ ˆ ‰ Š ‹ Œ Ž ‘ ’ “ ” • – — ˜ ™ š › œ ž Ÿ.
|
|
61
|
+
|
|
62
|
+
A character outside the encoding becomes one `?` and is listed in `replaced`, so nothing is lost unreported. This includes C1 controls, U+FFFD, and anything outside the Basic Latin and Latin-1 ranges other than those 27.
|
|
63
|
+
|
|
64
|
+
Compared with `iconv-lite` 0.7.3 over every code point of the Basic Multilingual Plane, the output is the same except in two cases:
|
|
65
|
+
|
|
66
|
+
- U+FFFD: iconv-lite writes byte 0x9D, a C1 control; this module writes `?`.
|
|
67
|
+
- A character outside the BMP: iconv-lite writes `??`, one per UTF-16 unit; this module writes one `?`.
|
|
68
|
+
|
|
69
|
+
## Open
|
|
70
|
+
|
|
71
|
+
- **The `document.xml` layout** (`<archive><content><document guid>…`, no namespace) is the one this module took over from its first user. No primary description of the importing system's schema was available when it was written. The layout should be confirmed by one import at a tax advisor before it is relied on.
|
|
72
|
+
|
|
73
|
+
## License and Legal Information
|
|
74
|
+
|
|
75
|
+
This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the [license.md](./license.md) file.
|
|
76
|
+
|
|
77
|
+
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
|
|
78
|
+
|
|
79
|
+
### Trademarks
|
|
80
|
+
|
|
81
|
+
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH or third parties, and are not included within the scope of the MIT license granted herein.
|
|
82
|
+
|
|
83
|
+
Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines or the guidelines of the respective third-party owners, and any usage must be approved in writing. Third-party trademarks used herein are the property of their respective owners and used only in a descriptive manner, e.g. for an implementation of an API or similar.
|
|
84
|
+
|
|
85
|
+
### Company Information
|
|
86
|
+
|
|
87
|
+
Task Venture Capital GmbH
|
|
88
|
+
Registered at District Court Bremen HRB 35230 HB, Germany
|
|
89
|
+
|
|
90
|
+
For any legal inquiries or further information, please contact us via email at hello@task.vc.
|
|
91
|
+
|
|
92
|
+
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* autocreated commitinfo by @push.rocks/commitinfo
|
|
3
|
+
*/
|
|
4
|
+
export const commitinfo = {
|
|
5
|
+
name: '@fin.cx/compatibility',
|
|
6
|
+
version: '1.1.0',
|
|
7
|
+
description: 'Exchange formats of third-party accounting systems: the EXTF Buchungsstapel in Windows-1252 on the rows of @fin.cx/skr, and the document-image archive (document.xml and ZIP)'
|
|
8
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import * as plugins from './plugins.js';
|
|
2
|
+
|
|
3
|
+
/** A document image of the archive, linked to its bookings through the GUID in their Beleglink (field 20). */
|
|
4
|
+
export interface IBelegbilderDocument {
|
|
5
|
+
guid: string;
|
|
6
|
+
description: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface IBelegbilderEntry extends IBelegbilderDocument {
|
|
10
|
+
/** the document as PDF */
|
|
11
|
+
bytes: Uint8Array;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const BELEGBILDER_CONTENT_TYPE = 'application/zip';
|
|
15
|
+
|
|
16
|
+
/** `DATEV_Belege_<label>.zip`, for example `DATEV_Belege_2026-03.zip`. */
|
|
17
|
+
export const belegbilderFilename = (labelArg: string): string => `DATEV_Belege_${labelArg}.zip`;
|
|
18
|
+
|
|
19
|
+
const escapeXml = (valueArg: string): string =>
|
|
20
|
+
valueArg
|
|
21
|
+
.replace(/&/gu, '&')
|
|
22
|
+
.replace(/</gu, '<')
|
|
23
|
+
.replace(/>/gu, '>')
|
|
24
|
+
.replace(/"/gu, '"')
|
|
25
|
+
.replace(/'/gu, ''');
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The manifest of the archive, `document.xml`: one `<document>` per PDF,
|
|
29
|
+
* named by its GUID. UTF-8, unlike the Buchungsstapel.
|
|
30
|
+
*/
|
|
31
|
+
export const buildDocumentXml = (documentsArg: readonly IBelegbilderDocument[]): string => {
|
|
32
|
+
const lines = ['<?xml version="1.0" encoding="UTF-8"?>', '<archive>', ' <content>'];
|
|
33
|
+
for (const document of documentsArg) {
|
|
34
|
+
lines.push(
|
|
35
|
+
` <document guid="${escapeXml(document.guid)}">`,
|
|
36
|
+
' <extension>PDF</extension>',
|
|
37
|
+
` <filename>${escapeXml(document.guid)}.pdf</filename>`,
|
|
38
|
+
' <beleg_type>1</beleg_type>',
|
|
39
|
+
...(document.description ? [` <description>${escapeXml(document.description)}</description>`] : []),
|
|
40
|
+
' </document>',
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
lines.push(' </content>', '</archive>', '');
|
|
44
|
+
return lines.join('\n');
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/** `document.xml` and one `<GUID>.pdf` per document, as one ZIP. */
|
|
48
|
+
export const createBelegbilderZip = async (entriesArg: readonly IBelegbilderEntry[]): Promise<Uint8Array> => {
|
|
49
|
+
const zipTools = new plugins.smartarchiveZip.ZipTools();
|
|
50
|
+
return zipTools.createZip([
|
|
51
|
+
{ archivePath: 'document.xml', content: buildDocumentXml(entriesArg) },
|
|
52
|
+
...entriesArg.map((entryArg) => ({ archivePath: `${entryArg.guid}.pdf`, content: entryArg.bytes })),
|
|
53
|
+
]);
|
|
54
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Windows-1252 as the WHATWG Encoding Standard defines it: bytes 0x00–0x7F
|
|
3
|
+
* and 0xA0–0xFF are the code points of the same number, and 0x80–0x9F carry
|
|
4
|
+
* the 27 characters below. The five bytes the standard leaves to C1 controls
|
|
5
|
+
* (0x81, 0x8D, 0x8F, 0x90, 0x9D) and every other C1 control are not written:
|
|
6
|
+
* no accounting text holds them.
|
|
7
|
+
*/
|
|
8
|
+
const HIGH_BYTES: ReadonlyArray<readonly [number, number]> = [
|
|
9
|
+
[0x20ac, 0x80], [0x201a, 0x82], [0x0192, 0x83], [0x201e, 0x84], [0x2026, 0x85], [0x2020, 0x86], [0x2021, 0x87],
|
|
10
|
+
[0x02c6, 0x88], [0x2030, 0x89], [0x0160, 0x8a], [0x2039, 0x8b], [0x0152, 0x8c], [0x017d, 0x8e], [0x2018, 0x91],
|
|
11
|
+
[0x2019, 0x92], [0x201c, 0x93], [0x201d, 0x94], [0x2022, 0x95], [0x2013, 0x96], [0x2014, 0x97], [0x02dc, 0x98],
|
|
12
|
+
[0x2122, 0x99], [0x0161, 0x9a], [0x203a, 0x9b], [0x0153, 0x9c], [0x017e, 0x9e], [0x0178, 0x9f],
|
|
13
|
+
];
|
|
14
|
+
const HIGH_BYTE_OF = new Map<number, number>(HIGH_BYTES);
|
|
15
|
+
|
|
16
|
+
/** What stands for a character Windows-1252 cannot write. */
|
|
17
|
+
export const WINDOWS_1252_REPLACEMENT = '?';
|
|
18
|
+
|
|
19
|
+
/** A character that was written as `?`, with its position in the text (UTF-16 offset). */
|
|
20
|
+
export interface IReplacedCharacter {
|
|
21
|
+
offset: number;
|
|
22
|
+
character: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface IWindows1252Result {
|
|
26
|
+
bytes: Uint8Array;
|
|
27
|
+
/** in text order; empty when every character could be written */
|
|
28
|
+
replaced: IReplacedCharacter[];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** The byte of a code point in Windows-1252, or undefined. */
|
|
32
|
+
export const windows1252ByteOf = (codePointArg: number): number | undefined => {
|
|
33
|
+
if (codePointArg <= 0x7f || (codePointArg >= 0xa0 && codePointArg <= 0xff)) {
|
|
34
|
+
return codePointArg;
|
|
35
|
+
}
|
|
36
|
+
return HIGH_BYTE_OF.get(codePointArg);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Encodes text in Windows-1252. A character the encoding cannot write
|
|
41
|
+
* becomes one `?` and is listed in `replaced`, so the caller can say which
|
|
42
|
+
* text lost which character; nothing is replaced unreported.
|
|
43
|
+
*/
|
|
44
|
+
export const encodeWindows1252 = (textArg: string): IWindows1252Result => {
|
|
45
|
+
const bytes: number[] = [];
|
|
46
|
+
const replaced: IReplacedCharacter[] = [];
|
|
47
|
+
let offset = 0;
|
|
48
|
+
for (const character of textArg) {
|
|
49
|
+
const byte = windows1252ByteOf(character.codePointAt(0) ?? 0);
|
|
50
|
+
if (byte === undefined) {
|
|
51
|
+
bytes.push(WINDOWS_1252_REPLACEMENT.charCodeAt(0));
|
|
52
|
+
replaced.push({ offset, character });
|
|
53
|
+
} else {
|
|
54
|
+
bytes.push(byte);
|
|
55
|
+
}
|
|
56
|
+
offset += character.length;
|
|
57
|
+
}
|
|
58
|
+
return { bytes: Uint8Array.from(bytes), replaced };
|
|
59
|
+
};
|
package/ts/error.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Why an exchange file could not be written:
|
|
3
|
+
* - `invalid_bookings`: a draft the account policy refuses; the message names it;
|
|
4
|
+
* - `export_failed`: the conversion into rows failed.
|
|
5
|
+
*/
|
|
6
|
+
export type TCompatibilityErrorCode = 'invalid_bookings' | 'export_failed';
|
|
7
|
+
|
|
8
|
+
export class CompatibilityError extends Error {
|
|
9
|
+
public readonly code: TCompatibilityErrorCode;
|
|
10
|
+
|
|
11
|
+
constructor(codeArg: TCompatibilityErrorCode, messageArg: string) {
|
|
12
|
+
super(messageArg);
|
|
13
|
+
this.name = 'CompatibilityError';
|
|
14
|
+
this.code = codeArg;
|
|
15
|
+
}
|
|
16
|
+
}
|
package/ts/extf/index.ts
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import * as plugins from './plugins.js';
|
|
2
|
+
import { CompatibilityError } from '../error.js';
|
|
3
|
+
import { encodeWindows1252, type IReplacedCharacter } from '../encoding/index.js';
|
|
4
|
+
|
|
5
|
+
export { CompatibilityError, type TCompatibilityErrorCode } from '../error.js';
|
|
6
|
+
|
|
7
|
+
export type IDatevBuchungsstapelRow = plugins.skrCore.IDatevBuchungsstapelRow;
|
|
8
|
+
export type IDatevExtfHeaderOptions = plugins.skrCore.IDatevExtfHeaderOptions;
|
|
9
|
+
|
|
10
|
+
/** The media type of a Buchungsstapel file: the reading side expects Windows-1252. */
|
|
11
|
+
export const EXTF_CONTENT_TYPE = 'text/csv; charset=windows-1252';
|
|
12
|
+
|
|
13
|
+
/** `EXTF_Buchungsstapel_<label>.csv`, for example `EXTF_Buchungsstapel_2026-03.csv`. */
|
|
14
|
+
export const extfFilename = (labelArg: string): string => `EXTF_Buchungsstapel_${labelArg}.csv`;
|
|
15
|
+
|
|
16
|
+
/** One booking of a Buchungsstapel as it can be compared and kept: what a row says, without its layout. */
|
|
17
|
+
export interface IExportBooking {
|
|
18
|
+
umsatzCents: number;
|
|
19
|
+
sollHaben: 'S' | 'H';
|
|
20
|
+
konto: string;
|
|
21
|
+
gegenkonto: string;
|
|
22
|
+
buKey: string;
|
|
23
|
+
/** the Belegdatum, `YYYY-MM-DD` */
|
|
24
|
+
date: string;
|
|
25
|
+
belegfeld1?: string;
|
|
26
|
+
belegfeld2?: string;
|
|
27
|
+
text: string;
|
|
28
|
+
/** the document GUID the row links to (field 20, `BEDI "GUID"`) */
|
|
29
|
+
documentGuid?: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** The GUID inside a Beleglink value (`BEDI "GUID"` or the bare GUID). */
|
|
33
|
+
const guidOfLink = (linkArg: string): string => linkArg.replace(/^BEDI\s*/iu, '').replace(/^"+|"+$/gu, '').trim();
|
|
34
|
+
|
|
35
|
+
/** The bookings of rows, in their order. */
|
|
36
|
+
export const bookingsOfRows = (rowsArg: readonly IDatevBuchungsstapelRow[]): IExportBooking[] =>
|
|
37
|
+
rowsArg.map((rowArg) => ({
|
|
38
|
+
umsatzCents: rowArg.umsatzCents,
|
|
39
|
+
sollHaben: rowArg.sollHaben,
|
|
40
|
+
konto: rowArg.konto,
|
|
41
|
+
gegenkonto: rowArg.gegenKonto,
|
|
42
|
+
buKey: rowArg.buSchluessel,
|
|
43
|
+
date: rowArg.belegDatum.toISOString().slice(0, 10),
|
|
44
|
+
...(rowArg.belegfeld1 ? { belegfeld1: rowArg.belegfeld1 } : {}),
|
|
45
|
+
...(rowArg.belegfeld2 ? { belegfeld2: rowArg.belegfeld2 } : {}),
|
|
46
|
+
text: rowArg.buchungstext,
|
|
47
|
+
...(rowArg.belegLink ? { documentGuid: guidOfLink(rowArg.belegLink) } : {}),
|
|
48
|
+
}));
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* How many rows two Buchungsstapel of one period do not share, compared on
|
|
52
|
+
* what a booking says (its day, amount, side, accounts, BU key and Belegfeld
|
|
53
|
+
* 1) and not on its wording or its document link. The rows are compared as a
|
|
54
|
+
* multiset: a row that stands twice in one and once in the other differs once.
|
|
55
|
+
*/
|
|
56
|
+
export const differingBookingCount = (leftArg: readonly IExportBooking[], rightArg: readonly IExportBooking[]): number => {
|
|
57
|
+
const keyOf = (bookingArg: IExportBooking): string =>
|
|
58
|
+
[bookingArg.date, bookingArg.umsatzCents, bookingArg.sollHaben, bookingArg.konto, bookingArg.gegenkonto, bookingArg.buKey, bookingArg.belegfeld1 ?? ''].join('|');
|
|
59
|
+
const unmatched = new Map<string, number>();
|
|
60
|
+
for (const booking of leftArg) {
|
|
61
|
+
unmatched.set(keyOf(booking), (unmatched.get(keyOf(booking)) ?? 0) + 1);
|
|
62
|
+
}
|
|
63
|
+
let differing = 0;
|
|
64
|
+
for (const booking of rightArg) {
|
|
65
|
+
const left = unmatched.get(keyOf(booking)) ?? 0;
|
|
66
|
+
if (left > 0) {
|
|
67
|
+
unmatched.set(keyOf(booking), left - 1);
|
|
68
|
+
} else {
|
|
69
|
+
differing += 1;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
for (const left of unmatched.values()) {
|
|
73
|
+
differing += left;
|
|
74
|
+
}
|
|
75
|
+
return differing;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Checks every draft against the account policy and turns the drafts into
|
|
80
|
+
* Buchungsstapel rows (`@fin.cx/skr` `journalDraftsToDatevRows`, not fixed).
|
|
81
|
+
* A draft the policy refuses throws `invalid_bookings`, naming the draft; a
|
|
82
|
+
* failure of the conversion throws `export_failed`.
|
|
83
|
+
*/
|
|
84
|
+
export const datevRowsOf = (draftsArg: readonly plugins.skrCore.IJournalDraft[], policyArg: plugins.skrCore.IAccountPolicy): IDatevBuchungsstapelRow[] => {
|
|
85
|
+
for (const draft of draftsArg) {
|
|
86
|
+
const validation = plugins.skrCore.validateJournalDraft(draft, policyArg);
|
|
87
|
+
if (!validation.valid) {
|
|
88
|
+
throw new CompatibilityError('invalid_bookings', `draft "${draft.description}": ${validation.errors.join('; ')}`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
try {
|
|
92
|
+
return plugins.skrCore.journalDraftsToDatevRows([...draftsArg], { festschreibung: false });
|
|
93
|
+
} catch (error) {
|
|
94
|
+
throw new CompatibilityError('export_failed', error instanceof Error ? error.message : String(error));
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
export interface IBuchungsstapelOptions {
|
|
99
|
+
drafts: readonly plugins.skrCore.IJournalDraft[];
|
|
100
|
+
/** the policy the drafts are checked against */
|
|
101
|
+
policy: plugins.skrCore.IAccountPolicy;
|
|
102
|
+
/** the header of the file; its `festschreibung` is written as given */
|
|
103
|
+
header: IDatevExtfHeaderOptions;
|
|
104
|
+
/** the file's name, for example `extfFilename('2026-03')` */
|
|
105
|
+
filename: string;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export interface IBuchungsstapelFile {
|
|
109
|
+
filename: string;
|
|
110
|
+
/** the file as text, lines ending in CRLF */
|
|
111
|
+
csv: string;
|
|
112
|
+
/** the file in Windows-1252, as it is handed over */
|
|
113
|
+
bytes: Uint8Array;
|
|
114
|
+
rows: IDatevBuchungsstapelRow[];
|
|
115
|
+
bookings: IExportBooking[];
|
|
116
|
+
/** the characters Windows-1252 cannot write, each written as `?` */
|
|
117
|
+
replacedCharacters: IReplacedCharacter[];
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** Writes a Buchungsstapel: the rows of the drafts, the header and the caption row, encoded in Windows-1252. */
|
|
121
|
+
export const writeBuchungsstapel = (optionsArg: IBuchungsstapelOptions): IBuchungsstapelFile => {
|
|
122
|
+
const rows = datevRowsOf(optionsArg.drafts, optionsArg.policy);
|
|
123
|
+
const { csv } = plugins.skrCore.writeExtfBuchungsstapel(rows, optionsArg.header);
|
|
124
|
+
const { bytes, replaced } = encodeWindows1252(csv);
|
|
125
|
+
return { filename: optionsArg.filename, csv, bytes, rows, bookings: bookingsOfRows(rows), replacedCharacters: replaced };
|
|
126
|
+
};
|
package/ts/index.ts
ADDED