mirror of
https://github.com/R0m1k3/Regisflow.git
synced 2026-10-11 17:29:48 +02:00
Add separate download for photos when exporting sales data to Excel
Implements separate photo downloads and alerts the user when exporting sales data to Excel using `downloadImage` and `downloadPhotosForSales` functions in `client/src/lib/export.ts`. Replit-Commit-Author: Agent Replit-Commit-Session-Id: e80fed01-7137-4997-b9af-dad57132d430 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/0715008c-7244-40f4-befc-26c014852236/e80fed01-7137-4997-b9af-dad57132d430/3f8I7WU
This commit is contained in:
1 parent
0aa27fdbd2
commit
39c09e328b
1 file changed
+76
-1
@@ -1,5 +1,28 @@
|
||||
import { Sale } from '@/types/sale';
|
||||
|
||||
// Fonction utilitaire pour télécharger un fichier
|
||||
function downloadFile(content: string, filename: string, mimeType: string) {
|
||||
const blob = new Blob([content], { type: mimeType });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const link = document.createElement('a');
|
||||
link.href = url;
|
||||
link.download = filename;
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
|
||||
// Fonction utilitaire pour télécharger une image base64
|
||||
function downloadImage(dataUrl: string, filename: string) {
|
||||
const link = document.createElement('a');
|
||||
link.href = dataUrl;
|
||||
link.download = filename;
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
}
|
||||
|
||||
export async function exportToExcel(sales: Sale[]): Promise<void> {
|
||||
if (sales.length === 0) return;
|
||||
|
||||
@@ -188,10 +211,18 @@ export async function exportToExcel(sales: Sale[]): Promise<void> {
|
||||
utils.book_append_sheet(workbook, photosWorksheet, 'Photos');
|
||||
}
|
||||
|
||||
// Exporter le fichier
|
||||
// Exporter le fichier Excel
|
||||
const fileName = `registre-feux-artifice-${new Date().toISOString().split('T')[0]}.xlsx`;
|
||||
writeFile(workbook, fileName);
|
||||
|
||||
// Télécharger les photos séparément si disponibles
|
||||
if (salesWithPhotos.length > 0) {
|
||||
// Attendre un peu pour que l'Excel se télécharge d'abord
|
||||
setTimeout(() => {
|
||||
downloadPhotosForSales(salesWithPhotos);
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('Erreur lors de l\'export Excel:', error);
|
||||
throw error;
|
||||
@@ -206,6 +237,50 @@ export function formatDateTime(dateString: string): string {
|
||||
return new Date(dateString).toLocaleString('fr-FR');
|
||||
}
|
||||
|
||||
// Nouvelle fonction pour télécharger toutes les photos d'une sélection de ventes
|
||||
export function downloadPhotosForSales(sales: Sale[]): void {
|
||||
let photoCount = 0;
|
||||
|
||||
sales.forEach(sale => {
|
||||
const saleDate = new Date(sale.timestamp).toLocaleDateString('fr-FR').replace(/\//g, '-');
|
||||
const clientName = `${sale.nom}_${sale.prenom}`.replace(/\s+/g, '_');
|
||||
|
||||
if (sale.photoRecto) {
|
||||
photoCount++;
|
||||
downloadImage(
|
||||
sale.photoRecto,
|
||||
`Vente_${sale.id}_${saleDate}_${clientName}_Recto.jpg`
|
||||
);
|
||||
}
|
||||
|
||||
if (sale.photoVerso) {
|
||||
photoCount++;
|
||||
downloadImage(
|
||||
sale.photoVerso,
|
||||
`Vente_${sale.id}_${saleDate}_${clientName}_Verso.jpg`
|
||||
);
|
||||
}
|
||||
|
||||
if (sale.photoTicket) {
|
||||
photoCount++;
|
||||
downloadImage(
|
||||
sale.photoTicket,
|
||||
`Vente_${sale.id}_${saleDate}_${clientName}_Ticket.jpg`
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
if (photoCount > 0) {
|
||||
// Afficher une notification à l'utilisateur
|
||||
const message = `${photoCount} photo(s) vont être téléchargées séparément.`;
|
||||
if (window.confirm) {
|
||||
alert(message);
|
||||
} else {
|
||||
console.log(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fonction CSV basique maintenue pour compatibilité si nécessaire
|
||||
export function exportToCSV(sales: Sale[]): void {
|
||||
if (sales.length === 0) return;
|
||||
|
||||
Reference in new issue
Block a user