feat: add realised vs unrealised value summary to TeamLeadsDashboard with pie chart visualization

This commit is contained in:
2025-11-14 12:08:46 +01:00
parent ac77a9d259
commit 7f63dc1df6
2 changed files with 92 additions and 5 deletions

View File

@@ -21,6 +21,20 @@ export async function GET(request) {
// Get all projects
const projects = getAllProjects();
// Calculate realised and unrealised values
let realisedValue = 0;
let unrealisedValue = 0;
projects.forEach(project => {
const value = parseFloat(project.wartosc_zlecenia) || 0;
if (project.project_status === 'fulfilled' && project.completion_date && project.wartosc_zlecenia) {
realisedValue += value;
} else if (project.wartosc_zlecenia && project.project_status !== 'cancelled') {
// Count all non-cancelled projects with values as unrealised
unrealisedValue += value;
}
});
// Filter completed projects (those with completion_date and fulfilled status)
const completedProjects = projects.filter(project =>
project.completion_date &&
@@ -30,6 +44,7 @@ export async function GET(request) {
// If no data, return sample data for demonstration
let chartData;
let summary;
if (completedProjects.length === 0) {
chartData = [
{ month: 'Jan 2024', value: 50000, cumulative: 50000 },
@@ -45,6 +60,10 @@ export async function GET(request) {
{ month: 'Nov 2024', value: 88000, cumulative: 863000 },
{ month: 'Dec 2024', value: 95000, cumulative: 958000 }
];
summary = {
realisedValue: 958000,
unrealisedValue: 1242000
};
} else {
// Group by month and calculate monthly totals first
const monthlyData = {};
@@ -84,9 +103,19 @@ export async function GET(request) {
value: Math.round(monthlyData[monthKey].value),
cumulative: Math.round(monthlyData[monthKey].cumulative)
}));
summary = {
realisedValue: Math.round(realisedValue),
unrealisedValue: Math.round(unrealisedValue)
};
}
return NextResponse.json(chartData);
return NextResponse.json({
chartData,
summary: {
realisedValue: Math.round(realisedValue),
unrealisedValue: Math.round(unrealisedValue)
}
});
} catch (error) {
console.error('Dashboard API error:', error);