import DashboardLayout from "@/components/DashboardLayout"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; import { trpc } from "@/lib/trpc"; import { FileText, DollarSign, TrendingUp, Clock } from "lucide-react"; import { BarChart, Bar, PieChart, Pie, Cell, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer } from "recharts"; import { Button } from "@/components/ui/button"; import { useState } from "react"; const COLORS = [ '#3b82f6', // blue '#8b5cf6', // purple '#ec4899', // pink '#f59e0b', // amber '#10b981', // emerald '#06b6d4', // cyan '#f97316', // orange '#6366f1', // indigo '#14b8a6', // teal '#a855f7', // violet ]; export default function Dashboard() { const { data: stats, isLoading } = trpc.invoices.getStats.useQuery(); const [showDetailedStats, setShowDetailedStats] = useState(false); if (isLoading) { return (
Chargement des statistiques...
); } const formatCurrency = (amount: number) => { return new Intl.NumberFormat('fr-FR', { style: 'currency', currency: 'EUR', }).format(amount); }; const formatDate = (date: Date | string | null) => { if (!date) return 'N/A'; return new Date(date).toLocaleDateString('fr-FR', { day: '2-digit', month: '2-digit', year: 'numeric', hour: '2-digit', minute: '2-digit', }); }; const getScoreLabel = (score: number) => { if (score >= 90) return 'Excellent'; if (score >= 75) return 'Bon'; if (score >= 60) return 'Moyen'; return 'Faible'; }; const getScoreColor = (score: number) => { if (score >= 90) return 'text-green-600'; if (score >= 75) return 'text-blue-600'; if (score >= 60) return 'text-yellow-600'; return 'text-red-600'; }; return (
{/* Header */}

Tableau de bord

Activité des 30 derniers jours

{/* Stats Cards */}
Factures traitées
{stats?.completed || 0}

{stats?.completed || 0} complétées, {stats?.error || 0} en erreur

Montant total
{formatCurrency(stats?.totalAmount || 0)}

Moyenne : {stats?.completed ? formatCurrency((stats.totalAmount || 0) / stats.completed) : '0 €'} / facture

Score moyen
{stats?.averageScore || 0}
{getScoreLabel(stats?.averageScore || 0)}

Qualité d'extraction

Dernière activité
{stats?.lastActivity ? new Date(stats.lastActivity).toLocaleDateString('fr-FR', { day: '2-digit', month: '2-digit' }) : 'N/A'}

{stats?.lastActivity ? new Date(stats.lastActivity).toLocaleTimeString('fr-FR', { hour: '2-digit', minute: '2-digit' }) : ''}

{/* Detailed Stats */} {showDetailedStats && ( <> {/* Charts Row */}
{/* Weekly Chart */} Factures par semaine Nombre de factures traitées chaque semaine (30 derniers jours) {stats?.weeklyData && stats.weeklyData.length > 0 ? ( ) : (
Aucune donnée disponible
)}
{/* Top Suppliers Pie Chart */} Top 10 fournisseurs Répartition des factures par fournisseur (30 derniers jours) {stats?.topSuppliers && stats.topSuppliers.length > 0 ? ( `${entry.name}: ${entry.percentage.toFixed(0)}%`} outerRadius={80} fill="#8884d8" dataKey="count" > {stats.topSuppliers.map((entry, index) => ( ))} ) : (
Aucune donnée disponible
)}
{/* Suppliers List */} Détail par fournisseur Liste des fournisseurs (30 derniers jours) {stats?.suppliersList && stats.suppliersList.length > 0 ? (
{stats.suppliersList.map((supplier, index) => (
{supplier.name}
{supplier.count} factures
{formatCurrency(supplier.amount)}
))}
) : (
Aucun fournisseur trouvé
)} )}
); }