From bdc9e6541c2a734a7c936f239327d27c2019241f Mon Sep 17 00:00:00 2001 From: DanielS Date: Tue, 30 Jun 2026 15:23:28 +0200 Subject: [PATCH] feat(admin): filter dashboard revenue KPI by current month and completed status --- shop/app/admin/page.tsx | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/shop/app/admin/page.tsx b/shop/app/admin/page.tsx index baa91d7..634da05 100644 --- a/shop/app/admin/page.tsx +++ b/shop/app/admin/page.tsx @@ -14,12 +14,22 @@ async function getKpis() { { count: userCount }, { count: productCount }, ] = await Promise.all([ - adminDb.from('orders').select('total_price, status'), + adminDb.from('orders').select('total_price, status, created_at'), adminDb.from('profiles').select('*', { count: 'exact', head: true }), supabase.from('products').select('*', { count: 'exact', head: true }), ]) - const totalRevenue = (orders ?? []).reduce((sum, o) => sum + Number(o.total_price), 0) + const now = new Date() + const currentYear = now.getFullYear() + const currentMonth = now.getMonth() + + const completedOrdersThisMonth = (orders ?? []).filter(o => { + if (o.status !== 'completed') return false + const orderDate = new Date(o.created_at) + return orderDate.getFullYear() === currentYear && orderDate.getMonth() === currentMonth + }) + + const totalRevenue = completedOrdersThisMonth.reduce((sum, o) => sum + Number(o.total_price), 0) const orderCount = (orders ?? []).length return { totalRevenue, orderCount, userCount: userCount ?? 0, productCount: productCount ?? 0 } @@ -36,14 +46,14 @@ export default async function AdminDashboard() {
- Umsatz gesamt + Umsatz aktueller Monat
{new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(totalRevenue)}
-

Aus allen Bestellungen

+

Nur fertige Bestellungen