Refactor expense form and add PDF generation functionality

- Update expense form fields (merchant->establishmentName, amount->price)
- Add PDF generation with Puppeteer integration
- Create PDFOptionsModal component for export options
- Update expense form validation and UI layout
- Add server API endpoint for PDF generation
This commit is contained in:
2025-07-09 22:23:50 -04:00
parent b6d71faf5f
commit 893927d4b1
6 changed files with 901 additions and 189 deletions

View File

@@ -504,23 +504,26 @@ const generatePDF = async (options: any) => {
});
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' });
// Decode base64 PDF content
const pdfContent = atob(response.data.content);
// Convert to byte array
const byteNumbers = new Array(pdfContent.length);
for (let i = 0; i < pdfContent.length; i++) {
byteNumbers[i] = pdfContent.charCodeAt(i);
}
const byteArray = new Uint8Array(byteNumbers);
// Create PDF blob and download
const blob = new Blob([byteArray], { type: 'application/pdf' });
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `${options.documentName || 'expenses'}.html`;
a.download = response.data.filename;
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();
}
console.log('[expenses] PDF downloaded successfully:', response.data.filename);
}
showPDFModal.value = false;