bmc_hub/app/dashboard/backend/views.py
Christian eacbd36e83 feat: Implement Transcription Service for audio files using Whisper API
- Added `transcription_service.py` to handle audio transcription via Whisper API.
- Integrated logging for transcription processes and error handling.
- Supported audio format checks based on configuration settings.

docs: Create Ordre System Implementation Plan

- Drafted comprehensive implementation plan for e-conomic order integration.
- Outlined business requirements, database changes, backend and frontend implementation details.
- Included testing plan and deployment steps for the new order system.

feat: Add AI prompts and regex action capabilities

- Created `ai_prompts` table for storing custom AI prompts.
- Added regex extraction and linking action to email workflow actions.

feat: Introduce conversations module for transcribed audio

- Created `conversations` table to store transcribed conversations with relevant metadata.
- Added indexing for customer, ticket, and user linkage.
- Implemented full-text search capabilities for Danish language.

fix: Add category column to conversations for classification

- Added `category` column to `conversations` table for better conversation classification.
2026-01-11 19:23:21 +01:00

63 lines
2.2 KiB
Python

from fastapi import APIRouter, Request
from fastapi.templating import Jinja2Templates
from fastapi.responses import HTMLResponse
from app.core.database import execute_query_single
router = APIRouter()
templates = Jinja2Templates(directory="app")
@router.get("/", response_class=HTMLResponse)
async def dashboard(request: Request):
"""
Render the dashboard page
"""
# Fetch count of unknown billing worklogs
unknown_query = """
SELECT COUNT(*) as count
FROM tticket_worklog
WHERE billing_method = 'unknown'
AND status NOT IN ('billed', 'rejected')
"""
# Fetch active bankruptcy alerts
# Finds emails classified as 'bankruptcy' that are not processed
bankruptcy_query = """
SELECT e.id, e.subject, e.received_date,
v.name as vendor_name, v.id as vendor_id,
c.name as customer_name, c.id as customer_id
FROM email_messages e
LEFT JOIN vendors v ON e.supplier_id = v.id
LEFT JOIN customers c ON e.customer_id = c.id
WHERE e.classification = 'bankruptcy'
AND e.status NOT IN ('archived')
AND (e.customer_id IS NOT NULL OR e.supplier_id IS NOT NULL)
ORDER BY e.received_date DESC
"""
from app.core.database import execute_query
result = execute_query_single(unknown_query)
unknown_count = result['count'] if result else 0
raw_alerts = execute_query(bankruptcy_query) or []
bankruptcy_alerts = []
for alert in raw_alerts:
item = dict(alert)
# Determine display name
if item.get('customer_name'):
item['display_name'] = f"Kunde: {item['customer_name']}"
elif item.get('vendor_name'):
item['display_name'] = item['vendor_name']
elif 'statstidende' in item.get('subject', '').lower():
item['display_name'] = 'Statstidende'
else:
item['display_name'] = 'Ukendt Afsender'
bankruptcy_alerts.append(item)
return templates.TemplateResponse("dashboard/frontend/index.html", {
"request": request,
"unknown_worklog_count": unknown_count,
"bankruptcy_alerts": bankruptcy_alerts
})