#!/usr/bin/env python3 """ Test script to verify PDF generation works correctly """ import sys import os sys.path.append('/mnt/HC_Volume_103713257/tilbudgivern/backend') from pdf_generator import TilbudgivernPDFGenerator from datetime import datetime import json # Create test data that matches the expected structure in pdf_generator.py test_data = { 'quote_number': f'TG-{datetime.now().strftime("%Y%m%d")}-TEST', 'project': { 'customer_name': 'Test Kunde A/S', 'customer_address': 'Testvej 123, 4000 Roskilde', 'project_description': 'udskiftning af tag pΓ₯ enfamiliehus' }, 'geometry': { 'total_area': 105.0, 'roof_type': 'Komplet tagudskiftning med B7 eternit', 'roof_pitch': 35 }, 'labor': { 'total_work_hours': 85.5, 'carpenter_count': 2, 'hourly_rate': 580.0 }, 'materials': [ { 'material_category': 'Eternit B7 tagplader 920x1320mm', 'quantity': 223, 'total_price': 54635.00 }, { 'material_category': 'Lindab Rainline tagrende 125mm', 'quantity': 14, 'total_price': 3430.00 }, { 'material_category': 'TrykimprΓ¦gnerede lΓ¦gter 30x50mm', 'quantity': 228, 'total_price': 4218.00 }, { 'material_category': 'Eternit rygning inkl. elementer', 'quantity': 12, 'total_price': 2040.00 }, { 'material_category': 'Lindab nedlΓΈb komplet system', 'quantity': 4, 'total_price': 2180.00 } ], 'calculation': { 'total_labor_cost': 49590.00, # 85.5 * 580 'total_material_cost': 66503.00, 'overhead_percentage': 15.0, 'profit_percentage': 20.0, 'vat_percentage': 25.0 } } # Output paths output_pdf = '/mnt/HC_Volume_103713257/tilbudgivern/Test_Tilbud.pdf' output_json = '/mnt/HC_Volume_103713257/tilbudgivern/test_data.json' # Save test data to JSON print("πŸ’Ύ Gemmer test data til JSON...") with open(output_json, 'w', encoding='utf-8') as f: json.dump(test_data, f, indent=2, ensure_ascii=False) print(f"βœ… JSON gemt: {output_json}") # Generate PDF print("\nπŸ”¨ GENERERER TEST PDF...") print(f"πŸ“‹ Kunde: {test_data['project']['customer_name']}") print(f"πŸ“ Adresse: {test_data['project']['customer_address']}") print(f"πŸ“ Tagareal: {test_data['geometry']['total_area']} mΒ²") print(f"⏱️ Arbejdstimer: {test_data['labor']['total_work_hours']} timer") try: generator = TilbudgivernPDFGenerator() success = generator.generate_pdf(test_data, output_pdf) if success: # Check if file exists and has content if os.path.exists(output_pdf): file_size = os.path.getsize(output_pdf) print(f"\nβœ… PDF GENERERET SUCCESFULDT!") print(f"πŸ“„ Fil: {output_pdf}") print(f"πŸ“Š StΓΈrrelse: {file_size:,} bytes") if file_size > 1000: print(f"βœ“ PDF indeholder data (ikke tom)") # Calculate expected values labor = test_data['calculation']['total_labor_cost'] materials = test_data['calculation']['total_material_cost'] subtotal = labor + materials overhead = subtotal * 0.15 profit = subtotal * 0.20 before_vat = subtotal + overhead + profit vat = before_vat * 0.25 total_with_vat = before_vat + vat print(f"\nπŸ’° PRISBEREGNING:") print(f" ArbejdslΓΈn: {labor:>12,.2f} kr") print(f" Materialer: {materials:>12,.2f} kr") print(f" ─────────────────────────────") print(f" Subtotal: {subtotal:>12,.2f} kr") print(f" Overhead (15%): {overhead:>12,.2f} kr") print(f" Profit (20%): {profit:>12,.2f} kr") print(f" Moms (25%): {vat:>12,.2f} kr") print(f" ═════════════════════════════") print(f" TOTAL: {total_with_vat:>12,.2f} kr") print(f"\nβœ“ PDF kan nu Γ₯bnes og verificeres") else: print(f"⚠️ ADVARSEL: PDF er meget lille ({file_size} bytes) - muligvis tom!") else: print(f"❌ FEJL: PDF fil blev ikke oprettet!") else: print(f"❌ FEJL: PDF generering returnerede False") except Exception as e: print(f"❌ FEJL ved generering: {e}") import traceback traceback.print_exc()