import { FiltersWidget } from "@/components/dashboard/filters-widget" import { IncomeExpenseGraph } from "@/components/dashboard/income-expense-graph" import { ProjectsWidget } from "@/components/dashboard/projects-widget" import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" import { getCurrentUser } from "@/lib/auth" import { formatCurrency } from "@/lib/utils" import { getProjects } from "@/models/projects" import { getSettings } from "@/models/settings" import { getDashboardStats, getDetailedTimeSeriesStats, getProjectStats } from "@/models/stats" import { TransactionFilters } from "@/models/transactions" import { ArrowDown, ArrowUp, BicepsFlexed } from "lucide-react" import Link from "next/link" export async function StatsWidget({ filters }: { filters: TransactionFilters }) { const user = await getCurrentUser() const projects = await getProjects(user.id) const settings = await getSettings(user.id) const defaultCurrency = settings.default_currency || "EUR" const stats = await getDashboardStats(user.id, filters) const statsTimeSeries = await getDetailedTimeSeriesStats(user.id, filters, defaultCurrency) const statsPerProject = Object.fromEntries( await Promise.all( projects.map((project) => getProjectStats(user.id, project.code, filters).then((stats) => [project.code, stats])) ) ) return (

Overview

{statsTimeSeries.length > 0 && }
Total Income {Object.entries(stats.totalIncomePerCurrency).map(([currency, total]) => (
{formatCurrency(total, currency)}
))} {!Object.entries(stats.totalIncomePerCurrency).length &&
0.00
}
Total Expenses {Object.entries(stats.totalExpensesPerCurrency).map(([currency, total]) => (
{formatCurrency(total, currency)}
))} {!Object.entries(stats.totalExpensesPerCurrency).length &&
0.00
}
Net Profit {Object.entries(stats.profitPerCurrency).map(([currency, total]) => (
= 0 ? "text-green-500" : "text-red-500" }`} > {formatCurrency(total, currency)}
))} {!Object.entries(stats.profitPerCurrency).length &&
0.00
}
Processed Transactions
{stats.invoicesProcessed}

Projects

) }