feat: Enhance InterestDuplicateNotificationBanner to always check for duplicates on mount and improve PDF generation to return base64 content

This commit is contained in:
2025-07-09 16:28:04 -04:00
parent bf24dc9103
commit 8f625c0df4
3 changed files with 201 additions and 39 deletions

View File

@@ -487,7 +487,15 @@ const generatePDF = async (options: any) => {
try {
console.log('[expenses] Generating PDF with options:', options);
const response = await $fetch('/api/expenses/generate-pdf', {
const response = await $fetch<{
success: boolean;
data: {
filename: string;
content: string;
mimeType: string;
size: number;
};
}>('/api/expenses/generate-pdf', {
method: 'POST',
body: {
expenseIds: selectedExpenses.value,
@@ -495,20 +503,31 @@ const generatePDF = async (options: any) => {
}
});
// Handle PDF download
const blob = new Blob([response as any], { type: 'application/pdf' });
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `${options.documentName || 'expenses'}.pdf`;
a.click();
window.URL.revokeObjectURL(url);
if (response.success && response.data) {
// For now, create HTML file instead of PDF since we're generating HTML content
const htmlContent = atob(response.data.content); // Decode base64
const blob = new Blob([htmlContent], { type: 'text/html' });
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `${options.documentName || 'expenses'}.html`;
a.click();
window.URL.revokeObjectURL(url);
// Also open in new tab for immediate viewing
const newTab = window.open();
if (newTab) {
newTab.document.open();
newTab.document.write(htmlContent);
newTab.document.close();
}
}
showPDFModal.value = false;
} catch (err: any) {
console.error('[expenses] Error generating PDF:', err);
error.value = 'Failed to generate PDF';
error.value = err.message || 'Failed to generate PDF';
}
};