fix(dkv): extract invoice number/date from PDF, rename export files to RG-DKV format
Tessera CI/CD / Lint & Type Check (push) Successful in 41s
Tessera CI/CD / Tests (push) Successful in 38s
Tessera CI/CD / Build & Publish Images (push) Successful in 23s

- Parser now extracts Rechnungsnummer (DD/DDDDDDDDD/DDD) and Rechnungsdatum
  from PDF text, so filename doesn't rely on email subject
- Export filename changed from DKV_YYYY-MM_... to RG-DKV-{nr}-{YYMMDD}.xlsx
  e.g. RG-DKV-26-650869002-002-260331.xlsx
- Subject fallback now also matches slash-separated invoice numbers (26/NNN/NNN)
- writeAndPrune simplified to accept baseName instead of separate fields
- Validation regex and prune prefix updated to match new RG-DKV- pattern

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-30 09:39:51 +02:00
parent 5c1aa03270
commit 66ffad149e
3 changed files with 64 additions and 24 deletions
+3 -3
View File
@@ -13,7 +13,7 @@ const MAX_EXPORT_FILES = 10;
/**
* Glob pattern for DKV export files — used for prune selection.
*/
const DKV_FILE_PREFIX = 'DKV_';
const DKV_FILE_PREFIX = 'RG-DKV-';
const DKV_FILE_SUFFIX = '.xlsx';
/**
@@ -128,7 +128,7 @@ export class DkvExportService {
* @param invoiceMonth - Month string "YYYY-MM", e.g. "2026-04"
* @returns The filename that was written (relative to user-files/)
*/
writeAndPrune(buffer: Buffer, rechnungsnummer: string, invoiceMonth: string): string {
writeAndPrune(buffer: Buffer, baseName: string): string {
// Ensure the directory exists
if (!fs.existsSync(this.userFilesDir)) {
fs.mkdirSync(this.userFilesDir, { recursive: true });
@@ -136,7 +136,7 @@ export class DkvExportService {
}
// Build filename server-side — NEVER from request input (T-07-09 path-traversal mitigation)
const filename = `DKV_${invoiceMonth}_${rechnungsnummer}.xlsx`;
const filename = `${baseName}.xlsx`;
const filePath = path.join(this.userFilesDir, filename);
// Write the file