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:
@@ -24,13 +24,26 @@ import {
|
|||||||
|
|
||||||
// Helper : télécharge un PDF annoté BAP depuis son URL de stockage
|
// 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'
|
// pdfUrl peut être : '/storage/2026-04/BAP_xxx.pdf' ou '/storage/BAP_xxx.pdf'
|
||||||
function downloadBapPdf(pdfUrl: string, supplierName?: string | null) {
|
// Nommage : AAAA-MM-JJ - Fournisseur - N°Facture.pdf
|
||||||
const filename = pdfUrl.split('/').pop() || 'BAP.pdf';
|
function downloadBapPdf(
|
||||||
// Utiliser le query param pdfPath pour passer le chemin complet au serveur
|
pdfUrl: string,
|
||||||
|
supplierName?: string | null,
|
||||||
|
invoiceNumber?: string | null,
|
||||||
|
validatedAt?: Date | string | null
|
||||||
|
) {
|
||||||
|
const fallback = pdfUrl.split('/').pop() || 'BAP.pdf';
|
||||||
const downloadUrl = `/api/download-bap?pdfPath=${encodeURIComponent(pdfUrl)}`;
|
const downloadUrl = `/api/download-bap?pdfPath=${encodeURIComponent(pdfUrl)}`;
|
||||||
|
// Construire le nom de fichier : date - fournisseur - numero.pdf
|
||||||
|
const datePart = validatedAt
|
||||||
|
? new Date(validatedAt).toLocaleDateString('fr-CA') // format AAAA-MM-JJ
|
||||||
|
: '';
|
||||||
|
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');
|
const a = document.createElement('a');
|
||||||
a.href = downloadUrl;
|
a.href = downloadUrl;
|
||||||
a.download = supplierName ? `BAP_${supplierName.replace(/[^a-zA-Z0-9]/g, '_')}.pdf` : filename;
|
a.download = filename;
|
||||||
document.body.appendChild(a);
|
document.body.appendChild(a);
|
||||||
a.click();
|
a.click();
|
||||||
document.body.removeChild(a);
|
document.body.removeChild(a);
|
||||||
@@ -266,7 +279,7 @@ export default function BapHistory() {
|
|||||||
variant="ghost"
|
variant="ghost"
|
||||||
size="sm"
|
size="sm"
|
||||||
className="h-7 px-2 text-emerald-600 hover:text-emerald-700 hover:bg-emerald-50"
|
className="h-7 px-2 text-emerald-600 hover:text-emerald-700 hover:bg-emerald-50"
|
||||||
onClick={() => downloadBapPdf(entry.pdfUrl!, entry.supplierName)}
|
onClick={() => downloadBapPdf(entry.pdfUrl!, entry.supplierName, entry.invoiceNumber, entry.validatedAt)}
|
||||||
title="Télécharger le PDF annoté"
|
title="Télécharger le PDF annoté"
|
||||||
>
|
>
|
||||||
<Download className="h-3.5 w-3.5" />
|
<Download className="h-3.5 w-3.5" />
|
||||||
|
|||||||
@@ -35,14 +35,25 @@ import { trpc } from "@/lib/trpc";
|
|||||||
import { Search, FileText, Download, FileSpreadsheet, Trash2, Edit, Trash, CheckCircle, CheckCircle2, ShieldCheck } from "lucide-react";
|
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
|
// 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'
|
// Nommage : AAAA-MM-JJ - Fournisseur - N°Facture.pdf
|
||||||
function downloadBapPdf(pdfUrl: string, supplierName?: string) {
|
function downloadBapPdf(
|
||||||
const filename = pdfUrl.split('/').pop() || 'BAP.pdf';
|
pdfUrl: string,
|
||||||
// Utiliser le query param pdfPath pour passer le chemin complet au serveur
|
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 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');
|
const a = document.createElement('a');
|
||||||
a.href = downloadUrl;
|
a.href = downloadUrl;
|
||||||
a.download = supplierName ? `BAP_${supplierName.replace(/[^a-zA-Z0-9]/g, '_')}.pdf` : filename;
|
a.download = filename;
|
||||||
document.body.appendChild(a);
|
document.body.appendChild(a);
|
||||||
a.click();
|
a.click();
|
||||||
document.body.removeChild(a);
|
document.body.removeChild(a);
|
||||||
@@ -713,7 +724,7 @@ export default function InvoicesBAP() {
|
|||||||
variant="outline"
|
variant="outline"
|
||||||
className="h-8 px-2 text-blue-600 border-blue-300 hover:bg-blue-50"
|
className="h-8 px-2 text-blue-600 border-blue-300 hover:bg-blue-50"
|
||||||
title="Télécharger le PDF annoté BAP"
|
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" />
|
<Download className="h-4 w-4" />
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
Reference in New Issue
Block a user