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() {
Aus allen Bestellungen
+Nur fertige Bestellungen