feat: enhance TeamLeadsDashboard with detailed realised vs unrealised values by project type and improved chart visualization
This commit is contained in:
@@ -21,20 +21,39 @@ export async function GET(request) {
|
||||
// Get all projects
|
||||
const projects = getAllProjects();
|
||||
|
||||
// Calculate realised and unrealised values
|
||||
let realisedValue = 0;
|
||||
let unrealisedValue = 0;
|
||||
// Calculate realised and unrealised values by project type
|
||||
const projectTypes = ['design', 'design+construction', 'construction'];
|
||||
const typeSummary = {};
|
||||
|
||||
projectTypes.forEach(type => {
|
||||
typeSummary[type] = {
|
||||
realisedValue: 0,
|
||||
unrealisedValue: 0
|
||||
};
|
||||
});
|
||||
|
||||
projects.forEach(project => {
|
||||
const value = parseFloat(project.wartosc_zlecenia) || 0;
|
||||
const type = project.project_type;
|
||||
|
||||
if (!type || !projectTypes.includes(type)) return;
|
||||
|
||||
if (project.project_status === 'fulfilled' && project.completion_date && project.wartosc_zlecenia) {
|
||||
realisedValue += value;
|
||||
typeSummary[type].realisedValue += value;
|
||||
} else if (project.wartosc_zlecenia && project.project_status !== 'cancelled') {
|
||||
// Count all non-cancelled projects with values as unrealised
|
||||
unrealisedValue += value;
|
||||
typeSummary[type].unrealisedValue += value;
|
||||
}
|
||||
});
|
||||
|
||||
// Calculate overall totals
|
||||
let realisedValue = 0;
|
||||
let unrealisedValue = 0;
|
||||
|
||||
Object.values(typeSummary).forEach(summary => {
|
||||
realisedValue += summary.realisedValue;
|
||||
unrealisedValue += summary.unrealisedValue;
|
||||
});
|
||||
|
||||
// Filter completed projects (those with completion_date and fulfilled status)
|
||||
const completedProjects = projects.filter(project =>
|
||||
project.completion_date &&
|
||||
@@ -61,8 +80,24 @@ export async function GET(request) {
|
||||
{ month: 'Dec 2024', value: 95000, cumulative: 958000 }
|
||||
];
|
||||
summary = {
|
||||
realisedValue: 958000,
|
||||
unrealisedValue: 1242000
|
||||
total: {
|
||||
realisedValue: 958000,
|
||||
unrealisedValue: 1242000
|
||||
},
|
||||
byType: {
|
||||
design: {
|
||||
realisedValue: 320000,
|
||||
unrealisedValue: 480000
|
||||
},
|
||||
'design+construction': {
|
||||
realisedValue: 480000,
|
||||
unrealisedValue: 520000
|
||||
},
|
||||
construction: {
|
||||
realisedValue: 158000,
|
||||
unrealisedValue: 242000
|
||||
}
|
||||
}
|
||||
};
|
||||
} else {
|
||||
// Group by month and calculate monthly totals first
|
||||
@@ -112,8 +147,19 @@ export async function GET(request) {
|
||||
return NextResponse.json({
|
||||
chartData,
|
||||
summary: {
|
||||
realisedValue: Math.round(realisedValue),
|
||||
unrealisedValue: Math.round(unrealisedValue)
|
||||
total: {
|
||||
realisedValue: Math.round(realisedValue),
|
||||
unrealisedValue: Math.round(unrealisedValue)
|
||||
},
|
||||
byType: Object.fromEntries(
|
||||
Object.entries(typeSummary).map(([type, data]) => [
|
||||
type,
|
||||
{
|
||||
realisedValue: Math.round(data.realisedValue),
|
||||
unrealisedValue: Math.round(data.unrealisedValue)
|
||||
}
|
||||
])
|
||||
)
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user