fix: nom fichier export conforme date-fournisseur-numero.pdf

This commit is contained in:
Manus
2026-05-06 12:18:03 -04:00
parent 4086227df7
commit 7c73d701ac

View File

@@ -1191,8 +1191,13 @@ export const appRouter = router({
// Build source path from fileKey // Build source path from fileKey
const sourcePath = path.join(STORAGE_BASE_PATH, invoice.fileKey); const sourcePath = path.join(STORAGE_BASE_PATH, invoice.fileKey);
// Extract filename from fileKey // Build export filename: date-fournisseur-numero.pdf
const filename = path.basename(invoice.fileKey); const invoiceDateStr = invoice.invoiceDate
? new Date(invoice.invoiceDate).toISOString().slice(0, 10)
: new Date().toISOString().slice(0, 10);
const supplierSafe = (invoice.supplierName || 'INCONNU').replace(/[^a-zA-Z0-9\u00C0-\u017F\s-]/g, '').trim().replace(/\s+/g, '_');
const invoiceNumSafe = (invoice.invoiceNumber || `id${invoice.id}`).replace(/[^a-zA-Z0-9\u00C0-\u017F\s-]/g, '').trim().replace(/\s+/g, '_');
const filename = `${invoiceDateStr}-${supplierSafe}-${invoiceNumSafe}.pdf`;
const destPath = path.join(exportFolder, filename); const destPath = path.join(exportFolder, filename);
// Find signature associated with invoice service // Find signature associated with invoice service