# src/report_generator.py import os from datetime import datetime def generate_bulk_html_report(results: list, output_path: str = "bulk_report.html"): """ Creates a single HTML report summarizing multiple invoices. """ # Calculate summary stats total_invoices = len(results) total_value = sum(float(r.get('total_amount') or 0) for r in results) passed_count = sum(1 for r in results if r.get('validation_status') == 'passed') rows_html = "" for idx, res in enumerate(results, 1): # Create a mini-table for the items in this invoice items_list = "" for item in res.get("items", []): total_val = item.get('total', 0) try: total_val = float(total_val) items_list += f"
  • {item.get('description', 'Item')} ${total_val:.2f}
  • " except: items_list += f"
  • {item.get('description', 'Item')}
  • " if not items_list: items_list = "
  • No items detected
  • " # Format total amount total_amt = res.get('total_amount') try: total_display = f"${float(total_amt):,.2f}" if total_amt else "N/A" except: total_display = str(total_amt) if total_amt else "N/A" status = res.get('validation_status') or 'unknown' rows_html += f""" {idx} {res.get('vendor') or 'Unknown Vendor'} {res.get('date') or 'N/A'} {res.get('receipt_number') or 'N/A'} {total_display} {status.title()} """ html_content = f""" Bulk Invoice Report - {datetime.now().strftime('%Y-%m-%d')}

    🧾 Bulk Invoice Extraction Report

    Generated on {datetime.now().strftime('%B %d, %Y at %I:%M %p')}

    {total_invoices}
    Total Invoices
    ${total_value:,.2f}
    Total Value
    {passed_count}/{total_invoices}
    Validation Passed
    {rows_html}
    # Vendor Date Invoice # Total Line Items Status
    """ return html_content