Commit Graph

10 Commits

Author SHA1 Message Date
Dries Peeters b4486a627f fix: CI tests, code quality, and duplicate DB indexes
- Webhook models: remove duplicate index definitions so db.create_all()
  no longer raises 'index already exists' (columns already have index=True)
- ImportService: fix circular import by late-importing ClientService,
  ProjectService, TimeTrackingService in __init__
- reports: fix F823 by renaming unpack variable _ to _entry_count to avoid
  shadowing gettext _ in export_task_excel()
- Code quality: add .flake8 with extend-ignore so flake8 CI passes;
  simplify pyproject.toml isort config (drop unsupported options)
- Format: run black and isort on app/
- tests: restore minimal app fixture in test_import_export_models
2026-03-15 10:51:52 +01:00
Dries Peeters c1a1592d2f fix(pdf): show decorative images in export when they overflow the page
- In _on_page(), only skip IMAGE elements when their rect does not
  intersect the page (was skipping when top-left was outside, which
  hid overflowing images).
- Coerce element x, y, width, height to float to avoid type issues.
- In _draw_image_on_canvas(), clip all image drawing to the page
  rectangle (beginPath + rect + clipPath) so the visible portion
  is shown and overflow is clipped like in the preview.
- Try template image file path before get_image_base64 for more
  reliable loading across deployments.
- Add INFO log when drawing template images for debugging.

Fixes #537 (export not showing decorative image when over border).
2026-03-09 20:49:06 +01:00
Dries Peeters 55f2ef29fd feat(overtime): allow overtime calculation by weekly hours (Issue #551) 2026-03-09 20:33:48 +01:00
Dries Peeters d39c5a2f37 fix(pdf-layout): decorative image persistence and PDF preview (Issue #432)
Decorative images now survive save/load and no longer cause a black PDF preview:

- Sync imageUrl onto groups before generateCode() so template_json has
  correct source (invoice and quote layout editors).
- Inject name/imageUrl into design_json with position-based matching so
  reordering does not swap or drop URLs.
- Restore name and imageUrl from saved JSON onto canvas on load
  (synchronous) so Konva custom attrs are not required.
- Omit decorative image elements with empty source from template_json;
  placeholders stay visible in the editor but are not sent to ReportLab.
- ReportLab: explicitly skip decorative images with empty source; validate
  base64 data URI payload and decode in try/except to avoid bad PDF output.

Documentation: PDF_LAYOUT_CUSTOMIZATION.md and PDF_EDITOR_ENHANCED_FEATURES.md
updated with decorative image description, state persistence details, and
troubleshooting. CHANGELOG.md updated under [Unreleased] Fixed.
2026-02-16 07:37:59 +01:00
Dries Peeters 743b7b9d4d Fix PDF invoice missing items (extra goods and expenses)
- Admin PDF preview: build all_line_items on invoice wrapper and resolve
  table data from element data source (invoice.all_line_items or
  invoice.items) so preview matches exported PDF.
- ReportLab: when template uses invoice.items, append both extra_goods
  and expenses to table data so all line types appear in PDF.
- Export PDF: explicitly load items, extra_goods, and expenses before
  generation so data is in session.
- Docs: recommend invoice.all_line_items for custom templates; document
  backward compatibility and preview behavior.

Refs #503

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-09 21:27:05 +01:00
Dries Peeters 5bc637cc6b fix(invoices): include extra goods and expenses in PDF invoice exports
PDF invoices were missing extra goods (and expenses) because the ReportLab
template renderer only used invoice.items as the table data source.

- Add invoice.all_line_items to template context: merged list of items,
  extra_goods, and expenses with normalized description/quantity/price fields
- Update default template schema to use invoice.all_line_items instead of
  invoice.items for the items table
- Add migration to update existing saved templates with the new data source
- Update PDF layout designer: add all_line_items and extra_goods loop options,
  default items table to all_line_items
- Add expenses to fallback ReportLab generator for consistency with
  pdf_default.html

Fixes #503

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-07 22:24:45 +01:00
Dries Peeters 64eee1acd9 Fix decorative image disappearing after save and PDF black screen issue
Fixes issue #432 where decorative images would disappear after saving
the layout and PDF preview would show mostly black.

Root causes:
- Konva's toJSON() doesn't serialize custom attributes like imageUrl
- Warning system adds 'element-overlap' suffix to names, breaking exact matches
- PDF generation tried to render images with empty/invalid sources

Fixes applied:

1. Serialization fixes (quote_pdf_layout.html, pdf_layout.html):
   - Manually inject imageUrl into JSON after Konva serialization
   - Store imageUrl in a map before serialization and match by position/index
   - Ensure primary name is 'decorative-image' before serialization
   - Fix name matching to handle 'decorative-image element-overlap' names

2. Restoration fixes (quote_pdf_layout.html, pdf_layout.html):
   - Search for decorative images using .includes() instead of exact match
   - Match by position when searching saved JSON for imageUrl
   - Create placeholder elements when imageUrl is missing
   - Ensure decorative image groups remain visible even without imageUrl

3. PDF generation fixes (pdf_generator_reportlab.py):
   - Skip decorative images with empty/invalid sources gracefully
   - Log warnings instead of attempting to render invalid images
   - Prevents black screen in PDF preview

4. Enhanced logging:
   - Added [INVOICE] and [SAVE]/[LOAD] prefixes for better debugging
   - Verify imageUrl presence in JSON before saving and after loading

The fixes ensure decorative images are properly saved with their imageUrl
attribute, correctly restored on load, and don't break PDF generation when
the image source is missing or invalid.
2026-01-14 21:15:08 +01:00
Dries Peeters ba9b789c51 feat: Add decorative images to PDF templates with full sync between invoice and quote editors
- Add decorative image element to PDF Layout Designer for both invoice and quote templates
- Implement template-level decorative image upload and management
- Add backend routes for template image upload and serving
- Update PDF generation (HTML preview and ReportLab) to handle template images with transparency preservation
- Sync all decorative image functionality between invoice and quote PDF layout editors

Fixes:
- Fix upload button not opening file picker in invoice template (use fresh DOM references)
- Fix element name matching to handle 'decorative-image element-overlap' format (use .includes() instead of strict equality)
- Fix image restoration after page reload with enhanced JSON searching and position matching
- Fix image persistence in Konva.js serialization/deserialization

Improvements:
- Enhanced image restoration logic with fallback mechanisms
- Improved error handling and console logging for debugging
- Better handling of transparent backgrounds in PDF export
- Consistent behavior between invoice and quote template editors
2026-01-13 13:33:55 +01:00
Dries Peeters 7332928958 fix: add boundary checking for PDF elements and page numbers
- Add page dimension validation in PDF generators to prevent content
  from being drawn outside page boundaries
- Fix page number positioning in fallback PDF generator to ensure
  they stay within page margins
- Add boundary constraints for absolutely positioned elements in
  ReportLab template renderer
- Prevent rendering errors when elements exceed page dimensions
2026-01-11 12:15:34 +01:00
Dries Peeters 4eeaa2a842 feat: Migrate PDF templates to ReportLab JSON format
- Add ReportLab template renderer with JSON-based template system
- Implement template schema validation and helper functions
- Add database migration for template_json columns
- Update visual editor to generate ReportLab JSON alongside HTML/CSS
- Maintain backward compatibility with legacy templates
- Add comprehensive migration documentation

BREAKING CHANGE: Existing PDF templates need to be saved again through
the visual editor to generate the new template_json format. Templates
will continue to work using the legacy fallback generator until saved.
2026-01-09 11:43:42 +01:00