@fin.cx/skr 1.1.0 → 1.2.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.
Files changed (46) hide show
  1. package/dist_ts/index.d.ts +6 -0
  2. package/dist_ts/index.js +7 -1
  3. package/dist_ts/plugins.d.ts +8 -1
  4. package/dist_ts/plugins.js +10 -2
  5. package/dist_ts/skr.api.d.ts +70 -0
  6. package/dist_ts/skr.api.js +348 -1
  7. package/dist_ts/skr.export.accounts.d.ts +53 -0
  8. package/dist_ts/skr.export.accounts.js +111 -0
  9. package/dist_ts/skr.export.balances.d.ts +59 -0
  10. package/dist_ts/skr.export.balances.js +205 -0
  11. package/dist_ts/skr.export.d.ts +110 -0
  12. package/dist_ts/skr.export.js +315 -0
  13. package/dist_ts/skr.export.ledger.d.ts +95 -0
  14. package/dist_ts/skr.export.ledger.js +164 -0
  15. package/dist_ts/skr.export.pdf.d.ts +82 -0
  16. package/dist_ts/skr.export.pdf.js +548 -0
  17. package/dist_ts/skr.invoice.adapter.d.ts +98 -0
  18. package/dist_ts/skr.invoice.adapter.js +476 -0
  19. package/dist_ts/skr.invoice.booking.d.ts +102 -0
  20. package/dist_ts/skr.invoice.booking.js +556 -0
  21. package/dist_ts/skr.invoice.entity.d.ts +287 -0
  22. package/dist_ts/skr.invoice.entity.js +2 -0
  23. package/dist_ts/skr.invoice.mapper.d.ts +69 -0
  24. package/dist_ts/skr.invoice.mapper.js +401 -0
  25. package/dist_ts/skr.invoice.storage.d.ts +140 -0
  26. package/dist_ts/skr.invoice.storage.js +529 -0
  27. package/dist_ts/skr.security.d.ts +65 -0
  28. package/dist_ts/skr.security.js +319 -0
  29. package/dist_ts/skr.types.d.ts +1 -0
  30. package/package.json +17 -12
  31. package/readme.md +207 -16
  32. package/ts/index.ts +6 -0
  33. package/ts/plugins.ts +22 -1
  34. package/ts/skr.api.ts +485 -0
  35. package/ts/skr.export.accounts.ts +154 -0
  36. package/ts/skr.export.balances.ts +270 -0
  37. package/ts/skr.export.ledger.ts +249 -0
  38. package/ts/skr.export.pdf.ts +601 -0
  39. package/ts/skr.export.ts +443 -0
  40. package/ts/skr.invoice.adapter.ts +581 -0
  41. package/ts/skr.invoice.booking.ts +738 -0
  42. package/ts/skr.invoice.entity.ts +351 -0
  43. package/ts/skr.invoice.mapper.ts +486 -0
  44. package/ts/skr.invoice.storage.ts +710 -0
  45. package/ts/skr.security.ts +405 -0
  46. package/ts/skr.types.ts +1 -0
@@ -0,0 +1,351 @@
1
+ import type { TSKRType } from './skr.types.js';
2
+
3
+ /**
4
+ * Invoice direction
5
+ */
6
+ export type TInvoiceDirection = 'inbound' | 'outbound';
7
+
8
+ /**
9
+ * Supported e-invoice formats
10
+ */
11
+ export type TInvoiceFormat = 'xrechnung' | 'zugferd' | 'facturx' | 'peppol' | 'ubl';
12
+
13
+ /**
14
+ * Invoice status in the system
15
+ */
16
+ export type TInvoiceStatus = 'draft' | 'validated' | 'posted' | 'partially_paid' | 'paid' | 'cancelled' | 'error';
17
+
18
+ /**
19
+ * Tax scenario classification
20
+ */
21
+ export type TTaxScenario =
22
+ | 'domestic_taxed' // Standard domestic with VAT
23
+ | 'domestic_exempt' // Domestic tax-exempt
24
+ | 'reverse_charge' // §13b UStG
25
+ | 'intra_eu_supply' // Intra-EU supply
26
+ | 'intra_eu_acquisition' // Intra-EU acquisition
27
+ | 'export' // Export outside EU
28
+ | 'small_business'; // §19 UStG small business
29
+
30
+ /**
31
+ * VAT rate categories
32
+ */
33
+ export interface IVATCategory {
34
+ code: string; // S (Standard), Z (Zero), E (Exempt), AE (Reverse charge), etc.
35
+ rate: number; // Tax rate percentage
36
+ exemptionReason?: string;
37
+ }
38
+
39
+ /**
40
+ * Party information (supplier/customer)
41
+ */
42
+ export interface IInvoiceParty {
43
+ id: string;
44
+ name: string;
45
+ address: {
46
+ street?: string;
47
+ city?: string;
48
+ postalCode?: string;
49
+ countryCode: string;
50
+ };
51
+ vatId?: string;
52
+ taxId?: string;
53
+ email?: string;
54
+ phone?: string;
55
+ bankAccount?: {
56
+ iban: string;
57
+ bic?: string;
58
+ accountHolder?: string;
59
+ };
60
+ }
61
+
62
+ /**
63
+ * Invoice line item
64
+ */
65
+ export interface IInvoiceLine {
66
+ lineNumber: number;
67
+ description: string;
68
+ quantity: number;
69
+ unitPrice: number;
70
+ netAmount: number;
71
+ vatCategory: IVATCategory;
72
+ vatAmount: number;
73
+ grossAmount: number;
74
+ accountNumber?: string; // SKR account for booking
75
+ costCenter?: string;
76
+ productCode?: string;
77
+ allowances?: IAllowanceCharge[];
78
+ charges?: IAllowanceCharge[];
79
+ }
80
+
81
+ /**
82
+ * Allowance or charge
83
+ */
84
+ export interface IAllowanceCharge {
85
+ reason: string;
86
+ amount: number;
87
+ percentage?: number;
88
+ vatCategory?: IVATCategory;
89
+ vatAmount?: number;
90
+ }
91
+
92
+ /**
93
+ * Payment terms
94
+ */
95
+ export interface IPaymentTerms {
96
+ dueDate: Date;
97
+ paymentTermsNote?: string;
98
+ skonto?: {
99
+ percentage: number;
100
+ days: number;
101
+ baseAmount: number;
102
+ }[];
103
+ }
104
+
105
+ /**
106
+ * Validation result
107
+ */
108
+ export interface IValidationResult {
109
+ isValid: boolean;
110
+ syntax: {
111
+ valid: boolean;
112
+ errors: string[];
113
+ warnings: string[];
114
+ };
115
+ semantic: {
116
+ valid: boolean;
117
+ errors: string[];
118
+ warnings: string[];
119
+ };
120
+ businessRules: {
121
+ valid: boolean;
122
+ errors: string[];
123
+ warnings: string[];
124
+ };
125
+ countrySpecific?: {
126
+ valid: boolean;
127
+ errors: string[];
128
+ warnings: string[];
129
+ };
130
+ validatedAt: Date;
131
+ validatorVersion: string;
132
+ }
133
+
134
+ /**
135
+ * Booking information
136
+ */
137
+ export interface IBookingInfo {
138
+ journalEntryId: string;
139
+ transactionIds: string[];
140
+ bookedAt: Date;
141
+ bookedBy: string;
142
+ bookingRules: {
143
+ vendorAccount?: string;
144
+ customerAccount?: string;
145
+ expenseAccounts?: string[];
146
+ revenueAccounts?: string[];
147
+ vatAccounts?: string[];
148
+ };
149
+ confidence: number; // 0-100
150
+ autoBooked: boolean;
151
+ }
152
+
153
+ /**
154
+ * Payment information
155
+ */
156
+ export interface IPaymentInfo {
157
+ paymentId: string;
158
+ paymentDate: Date;
159
+ amount: number;
160
+ currency: string;
161
+ bankTransactionId?: string;
162
+ endToEndId?: string;
163
+ remittanceInfo?: string;
164
+ skontoTaken?: number;
165
+ }
166
+
167
+ /**
168
+ * Main invoice entity
169
+ */
170
+ export interface IInvoice {
171
+ // Identity
172
+ id: string;
173
+ direction: TInvoiceDirection;
174
+ format: TInvoiceFormat;
175
+
176
+ // EN16931 Business Terms
177
+ invoiceNumber: string; // BT-1
178
+ issueDate: Date; // BT-2
179
+ invoiceTypeCode?: string; // BT-3 (380=Invoice, 381=Credit note)
180
+ currencyCode: string; // BT-5
181
+ taxCurrencyCode?: string; // BT-6
182
+ taxPointDate?: Date; // BT-7 (Leistungsdatum)
183
+ paymentDueDate?: Date; // BT-9
184
+ buyerReference?: string; // BT-10
185
+ projectReference?: string; // BT-11
186
+ contractReference?: string; // BT-12
187
+ orderReference?: string; // BT-13
188
+ sellerOrderReference?: string; // BT-14
189
+
190
+ // Parties
191
+ supplier: IInvoiceParty;
192
+ customer: IInvoiceParty;
193
+ payee?: IInvoiceParty; // If different from supplier
194
+
195
+ // Line items
196
+ lines: IInvoiceLine[];
197
+
198
+ // Document level allowances/charges
199
+ allowances?: IAllowanceCharge[];
200
+ charges?: IAllowanceCharge[];
201
+
202
+ // Amounts
203
+ lineNetAmount: number; // Sum of line net amounts
204
+ allowanceTotalAmount?: number;
205
+ chargeTotalAmount?: number;
206
+ taxExclusiveAmount: number; // BT-109
207
+ taxInclusiveAmount: number; // BT-112
208
+ prepaidAmount?: number; // BT-113
209
+ payableAmount: number; // BT-115
210
+
211
+ // VAT breakdown
212
+ vatBreakdown: {
213
+ vatCategory: IVATCategory;
214
+ taxableAmount: number; // BT-116
215
+ taxAmount: number; // BT-117
216
+ }[];
217
+ totalVATAmount: number; // BT-110
218
+
219
+ // Payment
220
+ paymentTerms?: IPaymentTerms;
221
+ paymentMeans?: {
222
+ code: string; // 30=Bank transfer, 48=Card, etc.
223
+ account?: IInvoiceParty['bankAccount'];
224
+ };
225
+ payments?: IPaymentInfo[];
226
+
227
+ // Notes
228
+ invoiceNote?: string; // BT-22
229
+
230
+ // Processing metadata
231
+ status: TInvoiceStatus;
232
+ taxScenario?: TTaxScenario;
233
+ skrType?: TSKRType;
234
+
235
+ // Storage
236
+ contentHash: string; // SHA-256 of normalized XML
237
+ xmlContent?: string;
238
+ pdfHash?: string;
239
+ pdfContent?: Buffer;
240
+
241
+ // Validation
242
+ validationResult?: IValidationResult;
243
+
244
+ // Booking
245
+ bookingInfo?: IBookingInfo;
246
+
247
+ // Audit trail
248
+ createdAt: Date;
249
+ createdBy: string;
250
+ modifiedAt?: Date;
251
+ modifiedBy?: string;
252
+
253
+ // Additional metadata
254
+ metadata?: {
255
+ importSource?: string;
256
+ importedAt?: Date;
257
+ parserVersion?: string;
258
+ originalFilename?: string;
259
+ originalFormat?: string;
260
+ [key: string]: any;
261
+ };
262
+ }
263
+
264
+ /**
265
+ * Invoice import options
266
+ */
267
+ export interface IInvoiceImportOptions {
268
+ autoBook?: boolean;
269
+ confidenceThreshold?: number;
270
+ validateOnly?: boolean;
271
+ skipDuplicateCheck?: boolean;
272
+ bookingRules?: {
273
+ vendorDefaults?: Record<string, string>;
274
+ customerDefaults?: Record<string, string>;
275
+ productCategoryMapping?: Record<string, string>;
276
+ };
277
+ }
278
+
279
+ /**
280
+ * Invoice export options
281
+ */
282
+ export interface IInvoiceExportOptions {
283
+ format: TInvoiceFormat;
284
+ embedInPdf?: boolean;
285
+ sign?: boolean;
286
+ validate?: boolean;
287
+ }
288
+
289
+ /**
290
+ * Invoice search filter
291
+ */
292
+ export interface IInvoiceFilter {
293
+ direction?: TInvoiceDirection;
294
+ status?: TInvoiceStatus;
295
+ format?: TInvoiceFormat;
296
+ dateFrom?: Date;
297
+ dateTo?: Date;
298
+ supplierId?: string;
299
+ customerId?: string;
300
+ minAmount?: number;
301
+ maxAmount?: number;
302
+ invoiceNumber?: string;
303
+ reference?: string;
304
+ isPaid?: boolean;
305
+ isOverdue?: boolean;
306
+ }
307
+
308
+ /**
309
+ * Duplicate check result
310
+ */
311
+ export interface IDuplicateCheckResult {
312
+ isDuplicate: boolean;
313
+ matchedInvoiceId?: string;
314
+ matchedContentHash?: string;
315
+ matchedFields?: string[];
316
+ confidence: number;
317
+ }
318
+
319
+ /**
320
+ * Booking rules configuration
321
+ */
322
+ export interface IBookingRules {
323
+ skrType: TSKRType;
324
+
325
+ // Control accounts
326
+ vendorControlAccount: string;
327
+ customerControlAccount: string;
328
+
329
+ // VAT accounts
330
+ vatAccounts: {
331
+ inputVAT19: string;
332
+ inputVAT7: string;
333
+ outputVAT19: string;
334
+ outputVAT7: string;
335
+ reverseChargeVAT: string;
336
+ };
337
+
338
+ // Default accounts
339
+ defaultExpenseAccount: string;
340
+ defaultRevenueAccount: string;
341
+
342
+ // Mappings
343
+ productCategoryMapping?: Record<string, string>;
344
+ vendorMapping?: Record<string, string>;
345
+ customerMapping?: Record<string, string>;
346
+
347
+ // Skonto
348
+ skontoMethod?: 'net' | 'gross';
349
+ skontoExpenseAccount?: string;
350
+ skontoRevenueAccount?: string;
351
+ }