@ekwo-ai/fec 0.4.1 → 0.6.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/LICENSE +1 -1
- package/README.md +37 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/read/decimal.d.ts +25 -0
- package/dist/read/decimal.d.ts.map +1 -0
- package/dist/read/decimal.js +55 -0
- package/dist/read/decimal.js.map +1 -0
- package/dist/read/errors.d.ts +25 -0
- package/dist/read/errors.d.ts.map +1 -0
- package/dist/read/errors.js +12 -0
- package/dist/read/errors.js.map +1 -0
- package/dist/read/index.d.ts +27 -0
- package/dist/read/index.d.ts.map +1 -0
- package/dist/read/index.js +217 -0
- package/dist/read/index.js.map +1 -0
- package/dist/read/text.d.ts +10 -0
- package/dist/read/text.d.ts.map +1 -0
- package/dist/read/text.js +37 -0
- package/dist/read/text.js.map +1 -0
- package/dist/read/types.d.ts +97 -0
- package/dist/read/types.d.ts.map +1 -0
- package/dist/read/types.js +16 -0
- package/dist/read/types.js.map +1 -0
- package/package.json +2 -2
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -49,6 +49,43 @@ knowing when you read a file:
|
|
|
49
49
|
An extract that is not a whole financial year gets no opening lines: it is an
|
|
50
50
|
extract of movements, and `fecFileName` is built from a year end.
|
|
51
51
|
|
|
52
|
+
## Reading one back
|
|
53
|
+
|
|
54
|
+
`readFec()` goes the other way: the file this package writes, and the one any
|
|
55
|
+
package that keeps books in France hands over when asked for a year, into the
|
|
56
|
+
plain shape every reader of an accounting export in this repository declares
|
|
57
|
+
— accounts, parties, entries, violations.
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
import { readFec } from '@ekwo-ai/fec';
|
|
61
|
+
|
|
62
|
+
const books = readFec(bytesOrString); // UTF-8, fatally
|
|
63
|
+
const latin = readFec(bytes, { encoding: 'iso-8859-15' }); // said, never guessed
|
|
64
|
+
|
|
65
|
+
books.entries; // [{ journal: 'VE', number: '1', date: '2025-01-15', reference: 'F-001', lines: […] }, …]
|
|
66
|
+
books.contacts; // one per CompAuxNum, named by CompAuxLib
|
|
67
|
+
books.violations; // an entry that does not balance, a line with two sides, an entry on two dates
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
- The columns are found **by their names in the header**, which the arrêté
|
|
71
|
+
makes mandatory: the variants of the text add columns (a cash-basis
|
|
72
|
+
taxpayer's four) or write `Montant` and `Sens` instead of `Debit` and
|
|
73
|
+
`Credit`, and all of them read.
|
|
74
|
+
- The separator is the one the header uses, a tab or a vertical bar. Dates are
|
|
75
|
+
`AAAAMMJJ`, refused otherwise; an amount has a comma or a point as its
|
|
76
|
+
decimal mark and nothing else.
|
|
77
|
+
- An entry is the lines that share a `JournalCode` and an `EcritureNum`. Each
|
|
78
|
+
line keeps its party (`CompAuxNum`), its currency amount (`Montantdevise`,
|
|
79
|
+
`Idevise`) and its reconciliation mark (`EcritureLet`).
|
|
80
|
+
- A FEC is kept in the currency of the books and never says which, so
|
|
81
|
+
`currency` is null. The *à-nouveaux* arrive as the entries of their journal,
|
|
82
|
+
like any other: saying that journal is the opening is the importer's
|
|
83
|
+
business.
|
|
84
|
+
|
|
85
|
+
What does not add up comes back in `violations`, the entry as written beside
|
|
86
|
+
it; what is not a FEC is thrown as a `BooksFileError` with a `code`. In
|
|
87
|
+
[Ekwo OS](https://github.com/Ekwo-ai/ekwo-os) this is `ekwo import fec <file>`.
|
|
88
|
+
|
|
52
89
|
The separators are options: `decimalSeparator`, `fieldSeparator`, `newline`,
|
|
53
90
|
`header`. The defaults are what the French tooling expects.
|
|
54
91
|
|
package/dist/index.d.ts
CHANGED
|
@@ -105,4 +105,6 @@ export interface FecQueryRow {
|
|
|
105
105
|
}
|
|
106
106
|
/** Maps a `fec_lines()` row onto a {@link FecLine}. */
|
|
107
107
|
export declare function fromQueryRow(row: FecQueryRow): FecLine;
|
|
108
|
+
export { readFec, BooksFileError } from './read/index.js';
|
|
109
|
+
export type { BooksFileErrorCode, Encoding, ImportedAccount, ImportedBooks, ImportedContact, ImportedEntry, ImportedLine, ReadOptions, Violation, } from './read/index.js';
|
|
108
110
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,4CAA4C;AAC5C,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC;AAE7B;;;GAGG;AACH,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC;AAE7B,yEAAyE;AACzE,eAAO,MAAM,WAAW,2PAmBd,CAAC;AAEX,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AAErD;;;;GAIG;AACH,MAAM,WAAW,OAAO;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,OAAO,GAAG,IAAI,CAAC;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,OAAO,GAAG,IAAI,CAAC;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;IACxB,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,OAAO,CAAC,EAAE,OAAO,GAAG,IAAI,GAAG,IAAI,CAAC;IAChC,SAAS,EAAE,OAAO,GAAG,IAAI,CAAC;I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W,GAAG,OAAO,CAqBtD;AAID,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAC1D,YAAY,EACV,kBAAkB,EAClB,QAAQ,EACR,eAAe,EACf,aAAa,EACb,eAAe,EACf,aAAa,EACb,YAAY,EACZ,WAAW,EACX,SAAS,GACV,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -189,4 +189,7 @@ export function fromQueryRow(row) {
|
|
|
189
189
|
idevise: row.idevise,
|
|
190
190
|
};
|
|
191
191
|
}
|
|
192
|
+
// Reading goes the other way, and lives beside: `readFec()` returns what a set
|
|
193
|
+
// of books is once read, in the shape every reader of an export declares.
|
|
194
|
+
export { readFec, BooksFileError } from './read/index.js';
|
|
192
195
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAWH,yEAAyE;AACzE,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,aAAa;IACb,YAAY;IACZ,aAAa;IACb,cAAc;IACd,WAAW;IACX,WAAW;IACX,YAAY;IACZ,YAAY;IACZ,UAAU;IACV,WAAW;IACX,aAAa;IACb,OAAO;IACP,QAAQ;IACR,aAAa;IACb,SAAS;IACT,WAAW;IACX,eAAe;IACf,SAAS;CACD,CAAC;AA4CX,MAAM,QAAQ,GAAyB;IACrC,gBAAgB,EAAE,GAAG;IACrB,cAAc,EAAE,GAAG;IACnB,OAAO,EAAE,MAAM;IACf,MAAM,EAAE,IAAI;CACb,CAAC;AAEF,yEAAyE;AACzE,MAAM,UAAU,aAAa,CAAC,KAAwC;IACpE,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,EAAE;QAAE,OAAO,EAAE,CAAC;IACrE,IAAI,KAAK,YAAY,IAAI,EAAE,CAAC;QAC1B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AAG,CAAC,YAAY;QAC7B,OAAO,EAAE,GAAG,CAAC,QAA0B;QACvC,SAAS,EAAE,GAAG,CAAC,UAAqB;QACpC,aAAa,EAAE,GAAG,CAAC,cAAc;QACjC,OAAO,EAAE,GAAG,CAAC,OAAO;KACrB,CAAC;AACJ,CAAC;AAED,+EAA+E;AAC/E,0EAA0E;AAC1E,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Amounts as the file wrote them, added without a float.
|
|
3
|
+
*
|
|
4
|
+
* An amount is held as a `bigint` of millionths: enough for any currency and
|
|
5
|
+
* any rate a spreadsheet prints, and exact. What leaves is a string with two
|
|
6
|
+
* decimals, and more when the file wrote more that are not zero — dropping a
|
|
7
|
+
* written zero is not rounding, dropping anything else would be, and is never
|
|
8
|
+
* done here.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* The decimal marks a number may be written with. The comma is accepted only
|
|
12
|
+
* where it cannot be a separator of thousands — in a file whose fields are
|
|
13
|
+
* separated by something else — and a number never carries both marks.
|
|
14
|
+
*/
|
|
15
|
+
export type DecimalMark = '.' | ',';
|
|
16
|
+
/**
|
|
17
|
+
* A written amount as millionths, or null when it is not a number this reader
|
|
18
|
+
* accepts: digits, one decimal mark, an optional leading minus or a pair of
|
|
19
|
+
* brackets for a negative. No thousands separator, no currency symbol, no
|
|
20
|
+
* exponent — each of those is refused rather than read one way or another.
|
|
21
|
+
*/
|
|
22
|
+
export declare function parseDecimal(text: string, marks: readonly DecimalMark[]): bigint | null;
|
|
23
|
+
/** Millionths as a decimal string: signed, two decimals, more when they are written. */
|
|
24
|
+
export declare function formatDecimal(value: bigint): string;
|
|
25
|
+
//# sourceMappingURL=decimal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decimal.d.ts","sourceRoot":"","sources":["../../src/read/decimal.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH;;;;GAIG;AACH,MAAM,MAAM,WAAW,GAAG,GAAG,GAAG,GAAG,CAAC;AAEpC;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,WAAW,EAAE,GAAG,MAAM,GAAG,IAAI,CAuBvF;AAED,wFAAwF;AACxF,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAMnD"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Amounts as the file wrote them, added without a float.
|
|
3
|
+
*
|
|
4
|
+
* An amount is held as a `bigint` of millionths: enough for any currency and
|
|
5
|
+
* any rate a spreadsheet prints, and exact. What leaves is a string with two
|
|
6
|
+
* decimals, and more when the file wrote more that are not zero — dropping a
|
|
7
|
+
* written zero is not rounding, dropping anything else would be, and is never
|
|
8
|
+
* done here.
|
|
9
|
+
*/
|
|
10
|
+
const SCALE = 6;
|
|
11
|
+
const UNIT = 10n ** BigInt(SCALE);
|
|
12
|
+
/**
|
|
13
|
+
* A written amount as millionths, or null when it is not a number this reader
|
|
14
|
+
* accepts: digits, one decimal mark, an optional leading minus or a pair of
|
|
15
|
+
* brackets for a negative. No thousands separator, no currency symbol, no
|
|
16
|
+
* exponent — each of those is refused rather than read one way or another.
|
|
17
|
+
*/
|
|
18
|
+
export function parseDecimal(text, marks) {
|
|
19
|
+
let value = text.trim();
|
|
20
|
+
if (value === '')
|
|
21
|
+
return null;
|
|
22
|
+
let negative = false;
|
|
23
|
+
if (value.startsWith('(') && value.endsWith(')')) {
|
|
24
|
+
negative = true;
|
|
25
|
+
value = value.slice(1, -1).trim();
|
|
26
|
+
}
|
|
27
|
+
if (value.startsWith('-')) {
|
|
28
|
+
if (negative)
|
|
29
|
+
return null;
|
|
30
|
+
negative = true;
|
|
31
|
+
value = value.slice(1);
|
|
32
|
+
}
|
|
33
|
+
else if (value.startsWith('+')) {
|
|
34
|
+
value = value.slice(1);
|
|
35
|
+
}
|
|
36
|
+
const pattern = marks.includes(',') ? /^([0-9]+)(?:[.,]([0-9]*))?$|^[.,]([0-9]+)$/ : /^([0-9]+)(?:\.([0-9]*))?$|^\.([0-9]+)$/;
|
|
37
|
+
const match = pattern.exec(value);
|
|
38
|
+
if (match === null)
|
|
39
|
+
return null;
|
|
40
|
+
const whole = match[1] ?? '0';
|
|
41
|
+
const fraction = match[2] ?? match[3] ?? '';
|
|
42
|
+
if (fraction.length > SCALE)
|
|
43
|
+
return null;
|
|
44
|
+
const units = BigInt(whole) * UNIT + BigInt(fraction.padEnd(SCALE, '0') || '0');
|
|
45
|
+
return negative ? -units : units;
|
|
46
|
+
}
|
|
47
|
+
/** Millionths as a decimal string: signed, two decimals, more when they are written. */
|
|
48
|
+
export function formatDecimal(value) {
|
|
49
|
+
const negative = value < 0n;
|
|
50
|
+
const digits = (negative ? -value : value).toString().padStart(SCALE + 1, '0');
|
|
51
|
+
const whole = digits.slice(0, -SCALE);
|
|
52
|
+
const fraction = digits.slice(-SCALE).replace(/0+$/, '').padEnd(2, '0');
|
|
53
|
+
return `${negative ? '-' : ''}${whole}.${fraction}`;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=decimal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decimal.js","sourceRoot":"","sources":["../../src/read/decimal.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,MAAM,KAAK,GAAG,CAAC,CAAC;AAChB,MAAM,IAAI,GAAG,GAAG,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC;AASlC;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,IAAY,EAAE,KAA6B;IACtE,IAAI,KAAK,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;IACxB,IAAI,KAAK,KAAK,EAAE;QAAE,OAAO,IAAI,CAAC;IAC9B,IAAI,QAAQ,GAAG,KAAK,CAAC;IACrB,IAAI,KA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CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;AACnC,CAAC;AAED,wFAAwF;AACxF,MAAM,UAAU,aAAa,CAAC,KAAa;IACzC,MAAM,QAAQ,GAAG,KAAK,GAAG,EAAE,CAAC;IAC5B,MAAM,MAAM,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,KAAK,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;IAC/E,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;IACtC,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IACxE,OAAO,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,KAAK,IAAI,QAAQ,EAAE,CAAC;AACtD,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What makes a file unreadable, as opposed to books that read and do not add
|
|
3
|
+
* up. The second comes back in `violations`; the first is thrown, because a
|
|
4
|
+
* file with no header the reader recognises has no row to hang a violation on.
|
|
5
|
+
*/
|
|
6
|
+
export type BooksFileErrorCode =
|
|
7
|
+
/** Larger than `maxBytes`. Refused before a single character is read. */
|
|
8
|
+
'too_large'
|
|
9
|
+
/** Bytes that are not the encoding announced. */
|
|
10
|
+
| 'unsupported_encoding'
|
|
11
|
+
/** Nothing in the file, or a header and nothing under it. */
|
|
12
|
+
| 'empty_file'
|
|
13
|
+
/** A header that lacks a column the format needs, or names one twice. */
|
|
14
|
+
| 'missing_column'
|
|
15
|
+
/** A quote that is never closed. */
|
|
16
|
+
| 'malformed_csv'
|
|
17
|
+
/** A value the format does not allow where it is: a date, an amount. */
|
|
18
|
+
| 'invalid_value';
|
|
19
|
+
export declare class BooksFileError extends Error {
|
|
20
|
+
readonly code: BooksFileErrorCode;
|
|
21
|
+
/** The row the reader stopped on, from 1, when there is one. */
|
|
22
|
+
readonly row: number | null;
|
|
23
|
+
constructor(code: BooksFileErrorCode, message: string, row?: number | null);
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/read/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,MAAM,kBAAkB;AAC5B,yEAAyE;AACvE,WAAW;AACb,iDAAiD;GAC/C,sBAAsB;AACxB,6DAA6D;GAC3D,YAAY;AACd,yEAAyE;GACvE,gBAAgB;AAClB,oCAAoC;GAClC,eAAe;AACjB,wEAAwE;GACtE,eAAe,CAAC;AAEpB,qBAAa,cAAe,SAAQ,KAAK;IACvC,QAAQ,CAAC,IAAI,EAAE,kBAAkB,CAAC;IAClC,gEAAgE;IAChE,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;gBAEhB,IAAI,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,GAAE,MAAM,GAAG,IAAW;CAMjF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export class BooksFileError extends Error {
|
|
2
|
+
code;
|
|
3
|
+
/** The row the reader stopped on, from 1, when there is one. */
|
|
4
|
+
row;
|
|
5
|
+
constructor(code, message, row = null) {
|
|
6
|
+
super(row === null ? message : `row ${row}: ${message}`);
|
|
7
|
+
this.name = 'BooksFileError';
|
|
8
|
+
this.code = code;
|
|
9
|
+
this.row = row;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/read/errors.ts"],"names":[],"mappings":"AAmBA,MAAM,OAAO,cAAe,SAAQ,KAAK;IAC9B,IAAI,CAAqB;IAClC,gEAAgE;IACvD,GAAG,CAAgB;IAE5B,YAAY,IAAwB,EAAE,OAAe,EAAE,MAAqB,IAAI;QAC9E,KAAK,CAAC,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,GAAG,KAAK,OAAO,EAAE,CAAC,CAAC;QACzD,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,CAAC;CACF"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The FEC read back: the file this package writes, and the one any French
|
|
3
|
+
* accounting package hands over when it is asked for the books of a year.
|
|
4
|
+
*
|
|
5
|
+
* The columns are found **by their names in the header**, which the arrêté
|
|
6
|
+
* makes mandatory, and not by position: the variants of the text — the one of
|
|
7
|
+
* a cash-basis taxpayer adds four columns, one variant carries a `Montant` and
|
|
8
|
+
* a `Sens` instead of `Debit` and `Credit` — differ in what they add, never in
|
|
9
|
+
* the names of what they share. The separator is the one the header uses, a
|
|
10
|
+
* tab or a vertical bar, the two the text allows. The dates are `AAAAMMJJ`;
|
|
11
|
+
* an amount has a comma or a point as its decimal mark, and nothing else.
|
|
12
|
+
*/
|
|
13
|
+
import type { ImportedBooks, ReadOptions } from './types.js';
|
|
14
|
+
export type { Encoding, ImportedAccount, ImportedBooks, ImportedContact, ImportedEntry, ImportedLine, ReadOptions, Violation, } from './types.js';
|
|
15
|
+
export { BooksFileError, type BooksFileErrorCode } from './errors.js';
|
|
16
|
+
/**
|
|
17
|
+
* Reads a FEC. Entries are the lines that share a `JournalCode` and an
|
|
18
|
+
* `EcritureNum`, in the order the file first names them; each line keeps its
|
|
19
|
+
* sub-ledger party (`CompAuxNum`, `CompAuxLib`), its currency amount
|
|
20
|
+
* (`Montantdevise`, `Idevise`) and its reconciliation mark (`EcritureLet`).
|
|
21
|
+
*
|
|
22
|
+
* What does not add up comes back in `violations`, and the entry comes back
|
|
23
|
+
* as the file wrote it: an entry that does not balance, a line with both a
|
|
24
|
+
* debit and a credit, an entry spread over two dates. Nothing is corrected.
|
|
25
|
+
*/
|
|
26
|
+
export declare function readFec(input: string | Uint8Array, options?: ReadOptions): ImportedBooks;
|
|
27
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/read/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAKH,OAAO,KAAK,EAEV,aAAa,EAIb,WAAW,EAEZ,MAAM,YAAY,CAAC;AAEpB,YAAY,EACV,QAAQ,EACR,eAAe,EACf,aAAa,EACb,eAAe,EACf,aAAa,EACb,YAAY,EACZ,WAAW,EACX,SAAS,GACV,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,cAAc,EAAE,KAAK,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAOtE;;;;;;;;;GASG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,EAAE,OAAO,GAAE,WAAgB,GAAG,aAAa,CA+K5F"}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The FEC read back: the file this package writes, and the one any French
|
|
3
|
+
* accounting package hands over when it is asked for the books of a year.
|
|
4
|
+
*
|
|
5
|
+
* The columns are found **by their names in the header**, which the arrêté
|
|
6
|
+
* makes mandatory, and not by position: the variants of the text — the one of
|
|
7
|
+
* a cash-basis taxpayer adds four columns, one variant carries a `Montant` and
|
|
8
|
+
* a `Sens` instead of `Debit` and `Credit` — differ in what they add, never in
|
|
9
|
+
* the names of what they share. The separator is the one the header uses, a
|
|
10
|
+
* tab or a vertical bar, the two the text allows. The dates are `AAAAMMJJ`;
|
|
11
|
+
* an amount has a comma or a point as its decimal mark, and nothing else.
|
|
12
|
+
*/
|
|
13
|
+
import { formatDecimal, parseDecimal } from './decimal.js';
|
|
14
|
+
import { BooksFileError } from './errors.js';
|
|
15
|
+
import { decode } from './text.js';
|
|
16
|
+
export { BooksFileError } from './errors.js';
|
|
17
|
+
const DEFAULTS = { encoding: 'utf-8', maxBytes: 256 * 1024 * 1024 };
|
|
18
|
+
/** The columns an entry cannot be read without. `Debit`/`Credit` or `Montant`/`Sens` come on top. */
|
|
19
|
+
const REQUIRED = ['JournalCode', 'EcritureNum', 'EcritureDate', 'CompteNum'];
|
|
20
|
+
/**
|
|
21
|
+
* Reads a FEC. Entries are the lines that share a `JournalCode` and an
|
|
22
|
+
* `EcritureNum`, in the order the file first names them; each line keeps its
|
|
23
|
+
* sub-ledger party (`CompAuxNum`, `CompAuxLib`), its currency amount
|
|
24
|
+
* (`Montantdevise`, `Idevise`) and its reconciliation mark (`EcritureLet`).
|
|
25
|
+
*
|
|
26
|
+
* What does not add up comes back in `violations`, and the entry comes back
|
|
27
|
+
* as the file wrote it: an entry that does not balance, a line with both a
|
|
28
|
+
* debit and a credit, an entry spread over two dates. Nothing is corrected.
|
|
29
|
+
*/
|
|
30
|
+
export function readFec(input, options = {}) {
|
|
31
|
+
const text = decode(input, options.encoding ?? DEFAULTS.encoding, options.maxBytes ?? DEFAULTS.maxBytes);
|
|
32
|
+
const lines = text.split(/\r\n|\n|\r/);
|
|
33
|
+
while (lines.length > 0 && lines[lines.length - 1] === '')
|
|
34
|
+
lines.pop();
|
|
35
|
+
const headerLine = lines[0];
|
|
36
|
+
if (headerLine === undefined || headerLine.trim() === '')
|
|
37
|
+
throw new BooksFileError('empty_file', 'the file is empty');
|
|
38
|
+
const separator = headerLine.includes('\t') ? '\t' : headerLine.includes('|') ? '|' : null;
|
|
39
|
+
if (separator === null) {
|
|
40
|
+
throw new BooksFileError('missing_column', 'the header is separated by neither a tab nor a vertical bar, the two separators the FEC allows', 1);
|
|
41
|
+
}
|
|
42
|
+
const header = headerLine.split(separator).map((cell) => cell.trim());
|
|
43
|
+
const at = (name) => {
|
|
44
|
+
const index = header.findIndex((cell) => cell.toLowerCase() === name.toLowerCase());
|
|
45
|
+
return index === -1 ? undefined : index;
|
|
46
|
+
};
|
|
47
|
+
for (const name of REQUIRED) {
|
|
48
|
+
if (at(name) === undefined)
|
|
49
|
+
throw new BooksFileError('missing_column', `the header has no ${name} column`, 1);
|
|
50
|
+
}
|
|
51
|
+
const bySides = at('Debit') !== undefined && at('Credit') !== undefined;
|
|
52
|
+
const bySense = at('Montant') !== undefined && at('Sens') !== undefined;
|
|
53
|
+
if (!bySides && !bySense) {
|
|
54
|
+
throw new BooksFileError('missing_column', 'the header has neither Debit and Credit nor Montant and Sens', 1);
|
|
55
|
+
}
|
|
56
|
+
if (lines.length < 2)
|
|
57
|
+
throw new BooksFileError('empty_file', 'the file has a header and no line under it', 1);
|
|
58
|
+
const accounts = new Map();
|
|
59
|
+
const contacts = new Map();
|
|
60
|
+
const entries = new Map();
|
|
61
|
+
const violations = [];
|
|
62
|
+
for (let index = 1; index < lines.length; index += 1) {
|
|
63
|
+
const row = index + 1;
|
|
64
|
+
const raw = lines[index];
|
|
65
|
+
if (raw.trim() === '')
|
|
66
|
+
continue;
|
|
67
|
+
const fields = raw.split(separator);
|
|
68
|
+
const cell = (name) => {
|
|
69
|
+
const position = at(name);
|
|
70
|
+
return position === undefined ? '' : (fields[position] ?? '').trim();
|
|
71
|
+
};
|
|
72
|
+
const amount = (name) => {
|
|
73
|
+
const value = cell(name);
|
|
74
|
+
if (value === '')
|
|
75
|
+
return 0n;
|
|
76
|
+
const parsed = parseDecimal(value, ['.', ',']);
|
|
77
|
+
if (parsed === null)
|
|
78
|
+
throw new BooksFileError('invalid_value', `"${value}" in ${name} is not an amount`, row);
|
|
79
|
+
return parsed;
|
|
80
|
+
};
|
|
81
|
+
const journal = cell('JournalCode');
|
|
82
|
+
const number = cell('EcritureNum');
|
|
83
|
+
const date = fecDate(cell('EcritureDate'), 'EcritureDate', row);
|
|
84
|
+
const account = cell('CompteNum');
|
|
85
|
+
if (journal === '' || number === '' || account === '') {
|
|
86
|
+
violations.push({ rule: 'required', message: 'a line lacks its JournalCode, EcritureNum or CompteNum and was left out', row });
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
let debit;
|
|
90
|
+
let credit;
|
|
91
|
+
if (bySides) {
|
|
92
|
+
debit = amount('Debit');
|
|
93
|
+
credit = amount('Credit');
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
const value = amount('Montant');
|
|
97
|
+
const sense = cell('Sens').toUpperCase();
|
|
98
|
+
if (sense !== 'D' && sense !== 'C' && sense !== '+1' && sense !== '-1') {
|
|
99
|
+
throw new BooksFileError('invalid_value', `"${cell('Sens')}" in Sens is none of D, C, +1, -1`, row);
|
|
100
|
+
}
|
|
101
|
+
const isDebit = sense === 'D' || sense === '+1';
|
|
102
|
+
debit = isDebit ? value : 0n;
|
|
103
|
+
credit = isDebit ? 0n : value;
|
|
104
|
+
}
|
|
105
|
+
if (debit !== 0n && credit !== 0n) {
|
|
106
|
+
violations.push({ rule: 'one_side', message: 'a line carries both a debit and a credit', row });
|
|
107
|
+
}
|
|
108
|
+
// A negative amount is the other side, which is how a reversal is written
|
|
109
|
+
// where the software does not flip it.
|
|
110
|
+
if (debit < 0n) {
|
|
111
|
+
credit -= debit;
|
|
112
|
+
debit = 0n;
|
|
113
|
+
}
|
|
114
|
+
if (credit < 0n) {
|
|
115
|
+
debit -= credit;
|
|
116
|
+
credit = 0n;
|
|
117
|
+
}
|
|
118
|
+
if (!accounts.has(account)) {
|
|
119
|
+
const name = cell('CompteLib');
|
|
120
|
+
accounts.set(account, { code: account, name: name === '' ? null : name, type: null });
|
|
121
|
+
}
|
|
122
|
+
const party = cell('CompAuxNum');
|
|
123
|
+
if (party !== '' && !contacts.has(party)) {
|
|
124
|
+
const name = cell('CompAuxLib');
|
|
125
|
+
contacts.set(party, {
|
|
126
|
+
code: party,
|
|
127
|
+
name: name === '' ? party : name,
|
|
128
|
+
vatNumber: null,
|
|
129
|
+
registrationNumber: null,
|
|
130
|
+
email: null,
|
|
131
|
+
country: null,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
const foreign = cell('Idevise');
|
|
135
|
+
const foreignAmount = cell('Montantdevise');
|
|
136
|
+
let amountCurrency = null;
|
|
137
|
+
if (foreign !== '' && foreignAmount !== '') {
|
|
138
|
+
const parsed = amount('Montantdevise');
|
|
139
|
+
amountCurrency = formatDecimal(parsed < 0n ? -parsed : parsed);
|
|
140
|
+
}
|
|
141
|
+
const label = cell('EcritureLib');
|
|
142
|
+
const line = {
|
|
143
|
+
account,
|
|
144
|
+
contact: party === '' ? null : party,
|
|
145
|
+
label: label === '' ? null : label,
|
|
146
|
+
debit: formatDecimal(debit),
|
|
147
|
+
credit: formatDecimal(credit),
|
|
148
|
+
currency: foreign === '' ? null : foreign.toUpperCase(),
|
|
149
|
+
amountCurrency,
|
|
150
|
+
dueDate: null,
|
|
151
|
+
matching: cell('EcritureLet') === '' ? null : cell('EcritureLet'),
|
|
152
|
+
};
|
|
153
|
+
const key = `${journal}\u0000${number}`;
|
|
154
|
+
let entry = entries.get(key);
|
|
155
|
+
if (entry === undefined) {
|
|
156
|
+
const reference = cell('PieceRef');
|
|
157
|
+
const journalName = cell('JournalLib');
|
|
158
|
+
entry = {
|
|
159
|
+
journal,
|
|
160
|
+
journalName: journalName === '' ? null : journalName,
|
|
161
|
+
number,
|
|
162
|
+
date,
|
|
163
|
+
reference: reference === '' ? null : reference,
|
|
164
|
+
description: line.label,
|
|
165
|
+
lines: [],
|
|
166
|
+
row,
|
|
167
|
+
debits: 0n,
|
|
168
|
+
credits: 0n,
|
|
169
|
+
};
|
|
170
|
+
entries.set(key, entry);
|
|
171
|
+
}
|
|
172
|
+
else if (entry.date !== date) {
|
|
173
|
+
violations.push({
|
|
174
|
+
rule: 'one_date',
|
|
175
|
+
message: `entry ${journal} ${number} is dated ${entry.date} on its first line and ${date} here; it is booked on the first`,
|
|
176
|
+
row,
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
entry.lines.push(line);
|
|
180
|
+
entry.debits += debit;
|
|
181
|
+
entry.credits += credit;
|
|
182
|
+
}
|
|
183
|
+
const read = [];
|
|
184
|
+
for (const { debits, credits, ...entry } of entries.values()) {
|
|
185
|
+
if (debits !== credits) {
|
|
186
|
+
violations.push({
|
|
187
|
+
rule: 'balance',
|
|
188
|
+
message: `entry ${entry.journal} ${entry.number} has debit ${formatDecimal(debits)} and credit ${formatDecimal(credits)}`,
|
|
189
|
+
row: entry.row,
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
read.push(entry);
|
|
193
|
+
}
|
|
194
|
+
return {
|
|
195
|
+
format: 'fec',
|
|
196
|
+
// The FEC is kept in the currency of the books and never says which one.
|
|
197
|
+
currency: null,
|
|
198
|
+
accounts: [...accounts.values()],
|
|
199
|
+
contacts: [...contacts.values()],
|
|
200
|
+
entries: read,
|
|
201
|
+
opening: [],
|
|
202
|
+
violations,
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
/** `AAAAMMJJ` to `YYYY-MM-DD`, refusing a date that does not exist. */
|
|
206
|
+
function fecDate(value, column, row) {
|
|
207
|
+
const match = /^(\d{4})(\d{2})(\d{2})$/.exec(value);
|
|
208
|
+
if (match === null)
|
|
209
|
+
throw new BooksFileError('invalid_value', `"${value}" in ${column} is not a date written AAAAMMJJ`, row);
|
|
210
|
+
const iso = `${match[1]}-${match[2]}-${match[3]}`;
|
|
211
|
+
const parsed = new Date(`${iso}T00:00:00Z`);
|
|
212
|
+
if (Number.isNaN(parsed.getTime()) || parsed.toISOString().slice(0, 10) !== iso) {
|
|
213
|
+
throw new BooksFileError('invalid_value', `${value} in ${column} is not a date of the calendar`, row);
|
|
214
|
+
}
|
|
215
|
+
return iso;
|
|
216
|
+
}
|
|
217
|
+
//# sourceMappingURL=index.js.map
|
|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AC,EAAE,EAAE,CAAC,KAAK,GAAG,EAAE,CAAC;QAChF,MAAM,IAAI,cAAc,CAAC,eAAe,EAAE,GAAG,KAAK,OAAO,MAAM,gCAAgC,EAAE,GAAG,CAAC,CAAC;IACxG,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The bytes of a file as text, in the encoding the caller said. A FEC may be
|
|
3
|
+
* written in UTF-8 or in ISO 8859-15, and nothing in the file says which:
|
|
4
|
+
* the caller does, and bytes that are not UTF-8 are refused rather than read
|
|
5
|
+
* as Latin, where every sequence of bytes would pass.
|
|
6
|
+
*/
|
|
7
|
+
import type { Encoding } from './types.js';
|
|
8
|
+
/** Bytes to text, in the encoding the caller said, refusing what is not that. */
|
|
9
|
+
export declare function decode(input: string | Uint8Array, encoding: Encoding, maxBytes: number): string;
|
|
10
|
+
//# sourceMappingURL=text.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../src/read/text.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAI3C,iFAAiF;AACjF,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAwB/F"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The bytes of a file as text, in the encoding the caller said. A FEC may be
|
|
3
|
+
* written in UTF-8 or in ISO 8859-15, and nothing in the file says which:
|
|
4
|
+
* the caller does, and bytes that are not UTF-8 are refused rather than read
|
|
5
|
+
* as Latin, where every sequence of bytes would pass.
|
|
6
|
+
*/
|
|
7
|
+
import { BooksFileError } from './errors.js';
|
|
8
|
+
const BYTE_ORDER_MARK = 0xfeff;
|
|
9
|
+
/** Bytes to text, in the encoding the caller said, refusing what is not that. */
|
|
10
|
+
export function decode(input, encoding, maxBytes) {
|
|
11
|
+
let text;
|
|
12
|
+
if (typeof input === 'string') {
|
|
13
|
+
if (input.length > maxBytes)
|
|
14
|
+
throw new BooksFileError('too_large', `the file is longer than ${maxBytes} bytes`);
|
|
15
|
+
text = input;
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
if (input.byteLength > maxBytes) {
|
|
19
|
+
throw new BooksFileError('too_large', `the file is ${input.byteLength} bytes, over the limit of ${maxBytes}`);
|
|
20
|
+
}
|
|
21
|
+
if (encoding === 'iso-8859-15') {
|
|
22
|
+
text = new TextDecoder('iso-8859-15').decode(input);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
try {
|
|
26
|
+
text = new TextDecoder('utf-8', { fatal: true }).decode(input);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
throw new BooksFileError('unsupported_encoding', "the bytes are not UTF-8; if the file is written in ISO 8859-15, say so with { encoding: 'iso-8859-15' } — it is not guessed, because every sequence of bytes is valid ISO 8859-15");
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (text.charCodeAt(0) === BYTE_ORDER_MARK)
|
|
34
|
+
text = text.slice(1);
|
|
35
|
+
return text;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=text.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text.js","sourceRoot":"","sources":["../../src/read/text.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAG7C,MAAM,eAAe,GAAG,MAAM,CAAC;AAE/B,iFAAiF;AACjF,MAAM,UAAU,MAAM,CAAC,KAA0B,EAAE,QAAkB,EAAE,QAAgB;IACrF,IAAI,IAAY,CAAC;IACjB,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,IAAI,KAAK,CAAC,MAAM,GAAG,QAAQ;YAAE,MAAM,IAAI,cAAc,CAAC,WAAW,EAAE,2BAA2B,QAAQ,QAAQ,CAAC,CAAC;QAChH,IAAI,GAAG,KAAK,CAAC;IACf,CAAC;SAAM,CAAC;QACN,IAAI,KAAK,CAAC,UAAU,GAAG,QAAQ,EAAE,CAAC;YAChC,MAAM,IAAI,cAAc,CAAC,WAAW,EAAE,eAAe,KAAK,CAAC,UAAU,6BAA6B,QAAQ,EAAE,CAAC,CAAC;QAChH,CAAC;QACD,IAAI,QAAQ,KAAK,aAAa,EAAE,CAAC;YAC/B,IAAI,GAAG,IAAI,WAAW,CAAC,aAAa,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACtD,CAAC;aAAM,CAAC;YACN,IAAI,CAAC;gBACH,IAAI,GAAG,IAAI,WAAW,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACjE,CAAC;YAAC,MAAM,CAAC;gBACP,MAAM,IAAI,cAAc,CACtB,sBAAsB,EACtB,mLAAmL,CACpL,CAAC;YACJ,CAAC;QACH,CAAC;IACH,CAAC;IACD,IAAI,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,eAAe;QAAE,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACjE,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a set of books is once it has been read out of the software that kept
|
|
3
|
+
* them: accounts, parties, entries and an opening balance. The shape is
|
|
4
|
+
* declared here and imported from nowhere — it names no table and no ledger.
|
|
5
|
+
*
|
|
6
|
+
* It is, field for field, the shape every reader of an accounting export in
|
|
7
|
+
* this repository declares for itself (`@ekwo-ai/fec`, and the readers beside
|
|
8
|
+
* this one), so whatever takes one takes the others. It is not a shared
|
|
9
|
+
* abstraction: none imports another, and a reader that has nothing to say for
|
|
10
|
+
* a part of it returns that part empty.
|
|
11
|
+
*
|
|
12
|
+
* Every amount is a **decimal string**, never negative: a line carries a debit
|
|
13
|
+
* or a credit, and the side is the sign. No figure passes through a `number`.
|
|
14
|
+
*/
|
|
15
|
+
/** ISO 8601 calendar date, `YYYY-MM-DD`. */
|
|
16
|
+
export type IsoDate = string;
|
|
17
|
+
/** A fixed-point number, `1234.50`, never negative. */
|
|
18
|
+
export type Decimal = string;
|
|
19
|
+
/** One account of the chart the books were kept on, in the words of that software. */
|
|
20
|
+
export interface ImportedAccount {
|
|
21
|
+
code: string;
|
|
22
|
+
name: string | null;
|
|
23
|
+
/** What the source calls its kind, verbatim. Null when it says nothing. */
|
|
24
|
+
type: string | null;
|
|
25
|
+
}
|
|
26
|
+
/** A customer, a supplier or anybody else a line names. */
|
|
27
|
+
export interface ImportedContact {
|
|
28
|
+
/** How the source identifies the party on a line: its code, or its name where it has no code. */
|
|
29
|
+
code: string;
|
|
30
|
+
name: string;
|
|
31
|
+
vatNumber: string | null;
|
|
32
|
+
registrationNumber: string | null;
|
|
33
|
+
email: string | null;
|
|
34
|
+
/** ISO 3166-1 alpha-2, when the source writes one. Never inferred. */
|
|
35
|
+
country: string | null;
|
|
36
|
+
}
|
|
37
|
+
export interface ImportedLine {
|
|
38
|
+
/** The account code in the source's chart. */
|
|
39
|
+
account: string;
|
|
40
|
+
/** The `code` of an {@link ImportedContact}, or null. */
|
|
41
|
+
contact: string | null;
|
|
42
|
+
label: string | null;
|
|
43
|
+
debit: Decimal;
|
|
44
|
+
credit: Decimal;
|
|
45
|
+
/** A foreign currency the line was in, when the source says so. */
|
|
46
|
+
currency: string | null;
|
|
47
|
+
/** The amount in that currency, never negative. */
|
|
48
|
+
amountCurrency: Decimal | null;
|
|
49
|
+
dueDate: IsoDate | null;
|
|
50
|
+
/** The reconciliation mark the source put on the line, as written. */
|
|
51
|
+
matching: string | null;
|
|
52
|
+
}
|
|
53
|
+
export interface ImportedEntry {
|
|
54
|
+
/** The journal code in the source, or null when it has none. */
|
|
55
|
+
journal: string | null;
|
|
56
|
+
journalName: string | null;
|
|
57
|
+
/** The entry's number in the source. */
|
|
58
|
+
number: string | null;
|
|
59
|
+
date: IsoDate;
|
|
60
|
+
reference: string | null;
|
|
61
|
+
description: string | null;
|
|
62
|
+
lines: ImportedLine[];
|
|
63
|
+
/** The row of the file the entry starts on, from 1, for a message. */
|
|
64
|
+
row: number | null;
|
|
65
|
+
}
|
|
66
|
+
export interface Violation {
|
|
67
|
+
rule: string;
|
|
68
|
+
message: string;
|
|
69
|
+
/** The row of the file, from 1, or null for a rule about the whole file. */
|
|
70
|
+
row: number | null;
|
|
71
|
+
}
|
|
72
|
+
export interface ImportedBooks {
|
|
73
|
+
/** Which reader: `fec` here. */
|
|
74
|
+
format: string;
|
|
75
|
+
/** The currency the file says its amounts are in. Null when it says none: never guessed. */
|
|
76
|
+
currency: string | null;
|
|
77
|
+
accounts: ImportedAccount[];
|
|
78
|
+
contacts: ImportedContact[];
|
|
79
|
+
entries: ImportedEntry[];
|
|
80
|
+
/** A trial balance: one line per account, to become the opening entry of a year. */
|
|
81
|
+
opening: ImportedLine[];
|
|
82
|
+
violations: Violation[];
|
|
83
|
+
}
|
|
84
|
+
/** The two encodings the FEC may be written in, and nothing else. */
|
|
85
|
+
export type Encoding = 'utf-8' | 'iso-8859-15';
|
|
86
|
+
export interface ReadOptions {
|
|
87
|
+
/**
|
|
88
|
+
* How bytes are decoded. Default `utf-8`, fatally: bytes that are not UTF-8
|
|
89
|
+
* are refused by name, never read as something else. A file written in
|
|
90
|
+
* ISO 8859-15 is said to be so, because every sequence of bytes is valid
|
|
91
|
+
* ISO 8859-15 and a guess would always succeed.
|
|
92
|
+
*/
|
|
93
|
+
encoding?: Encoding;
|
|
94
|
+
/** Refused beyond this many bytes, before anything is read. Default 64 MiB. */
|
|
95
|
+
maxBytes?: number;
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@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AAI,CAAC;IACvB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,wCAAwC;IACxC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,IAAI,EAAE,OAAO,CAAC;IACd,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,KAAK,EAAE,YAAY,EAAE,CAAC;IACtB,sEAAsE;IACtE,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;CACpB;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,4EAA4E;IAC5E,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;CACpB;AAED,MAAM,WAAW,aAAa;IAC5B,gCAAgC;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,4FAA4F;IAC5F,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,QAAQ,EAAE,eAAe,EAAE,CAAC;IAC5B,QAAQ,EAAE,eAAe,EAAE,CAAC;IAC5B,OAAO,EAAE,aAAa,EAAE,CAAC;IACzB,oFAAoF;IACpF,OAAO,EAAE,YAAY,EAAE,CAAC;IACxB,UAAU,EAAE,SAAS,EAAE,CAAC;CACzB;AAED,qEAAqE;AACrE,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,aAAa,CAAC;AAE/C,MAAM,WAAW,WAAW;IAC1B;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,+EAA+E;IAC/E,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a set of books is once it has been read out of the software that kept
|
|
3
|
+
* them: accounts, parties, entries and an opening balance. The shape is
|
|
4
|
+
* declared here and imported from nowhere — it names no table and no ledger.
|
|
5
|
+
*
|
|
6
|
+
* It is, field for field, the shape every reader of an accounting export in
|
|
7
|
+
* this repository declares for itself (`@ekwo-ai/fec`, and the readers beside
|
|
8
|
+
* this one), so whatever takes one takes the others. It is not a shared
|
|
9
|
+
* abstraction: none imports another, and a reader that has nothing to say for
|
|
10
|
+
* a part of it returns that part empty.
|
|
11
|
+
*
|
|
12
|
+
* Every amount is a **decimal string**, never negative: a line carries a debit
|
|
13
|
+
* or a credit, and the side is the sign. No figure passes through a `number`.
|
|
14
|
+
*/
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/read/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ekwo-ai/fec",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "The French FEC — fichier des ecritures comptables — in TypeScript: the eighteen columns of the arrete du 29 juillet 2013, from plain ledger rows. Zero dependencies.",
|
|
3
|
+
"version": "0.6.0",
|
|
4
|
+
"description": "The French FEC — fichier des ecritures comptables — in TypeScript: the eighteen columns of the arrete du 29 juillet 2013, from plain ledger rows, and read back into accounts, parties and entries. Zero dependencies.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fec",
|
|
7
7
|
"fichier-des-ecritures-comptables",
|