import { createClient } from "@/lib/supabase/server" import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" import { CalendarDays, CreditCard, Users, DollarSign, TrendingUp, ArrowUpRight, Calendar as CalendarIcon } from "lucide-react" import { format } from "date-fns" import { tr } from "date-fns/locale" import Link from "next/link" import { Badge } from "@/components/ui/badge" export default async function DashboardPage() { const supabase = await createClient() // 1. Total Reservations (Count) const { count: totalReservations } = await supabase .from('reservations') .select('*', { count: 'exact', head: true }) .neq('status', 'cancelled') // 2. Active Customers (Count) const { count: totalCustomers } = await supabase .from('customers') .select('*', { count: 'exact', head: true }) // 3. Pending Payments (Sum of remaining balances) // This is complex to calculate in one query without a view or function, // so we'll approximate or fetch pending payments directly if possible. // For now, let's just count pending reservations as a proxy or fetch recent payments. // Better: Sum of 'amount' from 'payments' where status = 'pending' (if we tracked pending payments that way) // Or: Calculate total potential revenue vs paid revenue. // Let's stick to "Total Revenue" (Paid) for now. const { data: payments } = await supabase .from('payments') .select('amount') .eq('status', 'paid') const totalRevenue = payments?.reduce((sum, p) => sum + Number(p.amount), 0) || 0 // 4. Upcoming Events (Next 5) const { data: upcomingEvents } = await supabase .from('reservations') .select(` id, start_time, status, halls (name), customers (full_name) `) .gte('start_time', new Date().toISOString()) .neq('status', 'cancelled') .order('start_time', { ascending: true }) .limit(5) // 5. Recent Activities (Last 5 created reservations) const { data: recentReservations } = await supabase .from('reservations') .select(` id, created_at, customers (full_name) `) .order('created_at', { ascending: false }) .limit(5) return (
İşletmenizin durumu hakkında genel bakış.
Aktif rezervasyonlar
Kayıtlı müşteri sayısı
Tahsil edilen ödemeler
Yaklaşan etkinlik bulunmuyor.
{event.customers?.full_name}
{event.halls?.name}
{format(new Date(event.start_time), 'd MMM yyyy', { locale: tr })}
{format(new Date(event.start_time), 'HH:mm')}
{res.customers?.full_name} rezervasyon oluşturdu
{format(new Date(res.created_at), 'd MMM HH:mm', { locale: tr })}
Henüz işlem yok.
)}