Add photo data to Excel exports and correct database column mappings

Adds a "Photos" sheet to Excel exports with links to images and fixes DB column mappings for sales photos.

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/z4eyzzt
This commit is contained in:
michaelschal committed 2025-07-19 11:28:02 +00:00
1 parent 58a06455f6
commit 91f5c13f33
4 files changed
+73 -42

No files matched your search

-1
View File
@@ -50,7 +50,6 @@ export default function SalesHistory({ canDelete = false }: SalesHistoryProps) {
});
const sales = Array.isArray(salesData) ? salesData : [];
console.log('DEBUG: Sample sale with photos:', sales.find(s => s.photoRecto || s.photoVerso || s.photoTicket));
// Filtrer les ventes selon la recherche
const filteredSales = useMemo(() => {
+70 -1
View File
@@ -4,7 +4,7 @@ export async function exportToExcel(sales: Sale[]): Promise<void> {
if (sales.length === 0) return;
try {
const XLSX = await import('xlsx');
const XLSX = await import('xlsx-js-style');
const { utils, writeFile } = XLSX;
// Créer un nouveau classeur
@@ -113,6 +113,75 @@ export async function exportToExcel(sales: Sale[]): Promise<void> {
summaryWorksheet['!cols'] = [{ wch: 30 }, { wch: 20 }];
utils.book_append_sheet(workbook, summaryWorksheet, 'Résumé');
// Créer une feuille de photos si il y a des ventes avec photos
const salesWithPhotos = sales.filter(sale => sale.photoRecto || sale.photoVerso || sale.photoTicket);
if (salesWithPhotos.length > 0) {
const photosData: any[] = [];
salesWithPhotos.forEach(sale => {
// Ajouter une ligne pour chaque vente avec photos
const photoRow: any = {
'ID Vente': sale.id,
'Date': new Date(sale.timestamp).toLocaleDateString('fr-FR'),
'Client': `${sale.nom} ${sale.prenom}`,
'Vendeur': sale.vendeur
};
// Ajouter les informations sur les photos disponibles
if (sale.photoRecto) {
photoRow['Photo Recto'] = 'DISPONIBLE';
photoRow['Lien Recto'] = `data:image/jpeg;base64,${sale.photoRecto.split(',')[1] || sale.photoRecto}`;
} else {
photoRow['Photo Recto'] = 'NON DISPONIBLE';
photoRow['Lien Recto'] = '';
}
if (sale.photoVerso) {
photoRow['Photo Verso'] = 'DISPONIBLE';
photoRow['Lien Verso'] = `data:image/jpeg;base64,${sale.photoVerso.split(',')[1] || sale.photoVerso}`;
} else {
photoRow['Photo Verso'] = 'NON DISPONIBLE';
photoRow['Lien Verso'] = '';
}
if (sale.photoTicket) {
photoRow['Photo Ticket'] = 'DISPONIBLE';
photoRow['Lien Ticket'] = `data:image/jpeg;base64,${sale.photoTicket.split(',')[1] || sale.photoTicket}`;
} else {
photoRow['Photo Ticket'] = 'NON DISPONIBLE';
photoRow['Lien Ticket'] = '';
}
photosData.push(photoRow);
});
const photosWorksheet = utils.json_to_sheet(photosData);
// Ajuster la largeur des colonnes pour les photos
photosWorksheet['!cols'] = [
{ wch: 10 }, // ID Vente
{ wch: 12 }, // Date
{ wch: 20 }, // Client
{ wch: 15 }, // Vendeur
{ wch: 15 }, // Photo Recto
{ wch: 50 }, // Lien Recto
{ wch: 15 }, // Photo Verso
{ wch: 50 }, // Lien Verso
{ wch: 15 }, // Photo Ticket
{ wch: 50 } // Lien Ticket
];
// Ajuster la hauteur des lignes pour mieux voir les liens
const rowHeights: any[] = [];
for (let i = 0; i <= photosData.length; i++) {
rowHeights.push({ hpt: 20 });
}
photosWorksheet['!rows'] = rowHeights;
utils.book_append_sheet(workbook, photosWorksheet, 'Photos');
}
// Exporter le fichier
const fileName = `registre-feux-artifice-${new Date().toISOString().split('T')[0]}.xlsx`;
writeFile(workbook, fileName);