mirror of
https://github.com/DRYTRIX/TimeTracker.git
synced 2026-01-10 05:30:08 -06:00
Add the ability to create and manage PDF invoice templates for different page sizes (A4, Letter, Legal, A3, A5, Tabloid) with independent templates for each size. Features: - Database migration to create invoice_pdf_templates table with page_size column and default templates for all supported sizes - New InvoicePDFTemplate model with helper methods for template management - Page size selector dropdown in canvas editor with dynamic canvas resizing - Size selection in invoice export view - Each page size maintains its own template (HTML, CSS, design JSON) - Preview functionality converted to full-screen modal popup PDF Generation: - Updated InvoicePDFGenerator to accept page_size parameter - Dynamic @page rule updates in CSS based on selected size - Removed conflicting @page rules from HTML inline styles when separate CSS exists - Template content preserved exactly as saved (no whitespace stripping) - Fallback logic: size-specific template → legacy Settings template → default UI/UX Improvements: - Styled page size selector to match app theme with dark mode support - Fixed canvas editor header styling and readability - Canvas correctly resizes when switching between page sizes - Unsaved changes confirmation uses app's standard modal - All editor controls properly styled for dark/light mode - Preview opens in modal instead of small side window Bug Fixes: - Fixed migration KeyError by correcting down_revision reference - Fixed DatatypeMismatch error by using boolean TRUE instead of integer - Fixed template content mismatch (logo positions) by preserving HTML - Fixed page size not being applied by ensuring @page rules are updated - Fixed f-string syntax error in _generate_css by using .format() instead - Fixed debug_print scope issue in _render_from_custom_template Debugging: - Added comprehensive debug logging to PDF generation flow - Debug output visible in Docker console for troubleshooting - Logs template retrieval, @page size updates, and final CSS content Files Changed: - migrations/versions/041_add_invoice_pdf_templates_table.py (new) - app/models/invoice_pdf_template.py (new) - app/models/__init__.py (register new model) - app/routes/admin.py (template management by size) - app/routes/invoices.py (page size parameter, debug logging) - app/utils/pdf_generator.py (page size support, debug logging) - templates/admin/pdf_layout.html (size selector, canvas resizing, modal) - app/templates/invoices/view.html (size selector for export)