package handler import ( "net/http" "dealroom/templates" ) func (h *Handler) handleAnalytics(w http.ResponseWriter, r *http.Request) { profile := getProfile(r.Context()) var dealCount, fileCount, requestCount, fulfilledCount int h.db.QueryRow("SELECT COUNT(*) FROM deals WHERE organization_id = ? AND is_archived = 0", profile.OrganizationID).Scan(&dealCount) h.db.QueryRow("SELECT COUNT(*) FROM files f JOIN deals d ON f.deal_id = d.id WHERE d.organization_id = ?", profile.OrganizationID).Scan(&fileCount) h.db.QueryRow("SELECT COUNT(*) FROM diligence_requests r JOIN deals d ON r.deal_id = d.id WHERE d.organization_id = ?", profile.OrganizationID).Scan(&requestCount) h.db.QueryRow("SELECT COUNT(*) FROM diligence_requests r JOIN deals d ON r.deal_id = d.id WHERE d.organization_id = ? AND r.atlas_status = 'fulfilled'", profile.OrganizationID).Scan(&fulfilledCount) completionPct := 0 if requestCount > 0 { completionPct = (fulfilledCount * 100) / requestCount } stats := &templates.AnalyticsStats{ DealCount: dealCount, FileCount: fileCount, RequestCount: requestCount, CompletionPct: completionPct, } templates.AnalyticsPage(profile, stats).Render(r.Context(), w) }