"use client"; import { useState } from "react"; import { Card, CardContent } from "poyraz-ui/atoms"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "poyraz-ui/molecules"; import { Bar, BarChart, CartesianGrid, ResponsiveContainer, Tooltip, XAxis, YAxis, PieChart, Pie, Cell, Legend } from "recharts"; import { BarChart3, Filter } from "lucide-react"; export type AnalyticsData = { tasks: { id: string; status: string; created_at: string; due_at?: string }[]; projects: { id: string; name: string }[]; finances: { id: string; type: string; amount: number; transaction_date: string; project_id?: string }[]; }; type AnalyticsClientProps = { data: AnalyticsData; }; const COLORS = ["hsl(var(--primary))", "hsl(var(--destructive))", "#eab308", "#3b82f6", "#8b5cf6"]; export function AnalyticsClient({ data }: AnalyticsClientProps) { const [dateRange, setDateRange] = useState("this_month"); const now = new Date(); const filterByDate = (dateStr: string | null) => { if (!dateStr) return false; const date = new Date(dateStr); if (dateRange === "this_week") { const firstDay = new Date(now.setDate(now.getDate() - now.getDay() + (now.getDay() === 0 ? -6 : 1))); return date >= firstDay; } if (dateRange === "this_month") { return date.getMonth() === now.getMonth() && date.getFullYear() === now.getFullYear(); } if (dateRange === "this_year") { return date.getFullYear() === now.getFullYear(); } return true; }; const filteredFinances = data.finances.filter(f => filterByDate(f.transaction_date)); const filteredTasks = data.tasks.filter(t => filterByDate(t.created_at || t.due_at)); // Project-based income const projectIncomeMap = new Map(); filteredFinances.filter(f => f.type === "income" && f.project_id).forEach(f => { const project = data.projects.find(p => p.id === f.project_id); const name = project ? project.name : "Bilinmeyen"; if (!projectIncomeMap.has(name)) { projectIncomeMap.set(name, { name, value: 0 }); } projectIncomeMap.get(name).value += Number(f.amount); }); const projectIncomeData = Array.from(projectIncomeMap.values()); // Task completion stats const completedTasks = filteredTasks.filter(t => t.status === "completed").length; const activeTasks = filteredTasks.filter(t => t.status !== "completed" && t.status !== "cancelled").length; const taskStatusData = [ { name: "Tamamlanan", value: completedTasks }, { name: "Devam Eden", value: activeTasks } ]; return (
Analizler

Performans ve Finans Analizi

Müşteri bazlı gelirler, görev tamamlama oranları ve proje ilerleme grafikleri.

Proje Bazlı Gelir Dağılımı

{projectIncomeData.length > 0 ? ( {projectIncomeData.map((entry, index) => ( ))} `₺${value}`} contentStyle={{ backgroundColor: 'hsl(var(--background))', borderColor: 'hsl(var(--border))', borderRadius: '0.375rem', }} /> ) : (
Veri bulunamadı.
)}

Görev Durumu Analizi

); }