Checkpoint: Modification du nommage des PDFs BAP téléchargés : format "AAAA-MM-JJ - Fournisseur - N°Facture.pdf" dans BapHistory.tsx et InvoicesBAP.tsx. Les paramètres invoiceNumber et validatedAt sont passés à la fonction downloadBapPdf.
This commit is contained in:
@@ -35,14 +35,25 @@ import { trpc } from "@/lib/trpc";
|
||||
import { Search, FileText, Download, FileSpreadsheet, Trash2, Edit, Trash, CheckCircle, CheckCircle2, ShieldCheck } from "lucide-react";
|
||||
|
||||
// Helper : télécharge un PDF annoté BAP depuis son URL de stockage
|
||||
// pdfUrl peut être : '/storage/2026-04/BAP_xxx.pdf' ou '/storage/BAP_xxx.pdf'
|
||||
function downloadBapPdf(pdfUrl: string, supplierName?: string) {
|
||||
const filename = pdfUrl.split('/').pop() || 'BAP.pdf';
|
||||
// Utiliser le query param pdfPath pour passer le chemin complet au serveur
|
||||
// Nommage : AAAA-MM-JJ - Fournisseur - N°Facture.pdf
|
||||
function downloadBapPdf(
|
||||
pdfUrl: string,
|
||||
supplierName?: string,
|
||||
invoiceNumber?: string | null,
|
||||
validatedAt?: Date | string | null
|
||||
) {
|
||||
const fallback = pdfUrl.split('/').pop() || 'BAP.pdf';
|
||||
const downloadUrl = `/api/download-bap?pdfPath=${encodeURIComponent(pdfUrl)}`;
|
||||
const datePart = validatedAt
|
||||
? new Date(validatedAt).toLocaleDateString('fr-CA') // AAAA-MM-JJ
|
||||
: new Date().toLocaleDateString('fr-CA');
|
||||
const supplierPart = (supplierName || '').replace(/[^a-zA-Z0-9à-ÿ \-]/g, '').trim();
|
||||
const numberPart = (invoiceNumber || '').replace(/[^a-zA-Z0-9\-]/g, '').trim();
|
||||
const parts = [datePart, supplierPart, numberPart].filter(Boolean);
|
||||
const filename = parts.length > 0 ? `${parts.join(' - ')}.pdf` : fallback;
|
||||
const a = document.createElement('a');
|
||||
a.href = downloadUrl;
|
||||
a.download = supplierName ? `BAP_${supplierName.replace(/[^a-zA-Z0-9]/g, '_')}.pdf` : filename;
|
||||
a.download = filename;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
@@ -713,7 +724,7 @@ export default function InvoicesBAP() {
|
||||
variant="outline"
|
||||
className="h-8 px-2 text-blue-600 border-blue-300 hover:bg-blue-50"
|
||||
title="Télécharger le PDF annoté BAP"
|
||||
onClick={() => downloadBapPdf(bapPdfUrls[invoice.id], invoice.supplierName || undefined)}
|
||||
onClick={() => downloadBapPdf(bapPdfUrls[invoice.id], invoice.supplierName || undefined, invoice.invoiceNumber, invoice.bapValidatedAt)}
|
||||
>
|
||||
<Download className="h-4 w-4" />
|
||||
</Button>
|
||||
|
||||
Reference in New Issue
Block a user