80 lines
4.0 KiB
JavaScript
80 lines
4.0 KiB
JavaScript
const CaseAnalyticsService = require('./case-analytics-service');
|
|
|
|
async function testAnalyticsService() {
|
|
console.log('🔄 Testing Case Analytics Service...\n');
|
|
|
|
const service = new CaseAnalyticsService();
|
|
|
|
try {
|
|
// Test 1: Overall KPIs
|
|
console.log('📊 Testing Overall KPIs...');
|
|
const kpis = await service.getOverallKPIs();
|
|
console.log(`✅ Total Projects: ${kpis.total_projects}`);
|
|
console.log(`✅ Unique Customers: ${kpis.unique_customers}`);
|
|
console.log(`✅ Total Project Value: ${kpis.total_project_value?.toLocaleString()} kr`);
|
|
console.log(`✅ Overall Profit Margin: ${kpis.overall_profit_margin}%`);
|
|
console.log(`✅ Active Employees: ${kpis.active_employees}`);
|
|
|
|
// Test 2: Employee Performance
|
|
console.log('\n👥 Testing Employee Performance...');
|
|
const employees = await service.getEmployeePerformanceMetrics();
|
|
console.log(`✅ Found ${employees.length} employees with performance data`);
|
|
|
|
if (employees.length > 0) {
|
|
const topEmployee = employees[0];
|
|
console.log(`✅ Top Employee: ${topEmployee.full_name}`);
|
|
console.log(` - Total Hours: ${topEmployee.total_hours}t`);
|
|
console.log(` - Projects Worked: ${topEmployee.projects_worked}`);
|
|
console.log(` - Labor Value: ${topEmployee.total_labor_value?.toLocaleString()} kr`);
|
|
}
|
|
|
|
// Test 3: Customer Analytics
|
|
console.log('\n🏢 Testing Customer Analytics...');
|
|
const customers = await service.getCustomerAnalytics();
|
|
console.log(`✅ Found ${customers.length} customers with analytics data`);
|
|
|
|
if (customers.length > 0) {
|
|
const topCustomer = customers[0];
|
|
console.log(`✅ Top Customer: ${topCustomer.customer_number}`);
|
|
console.log(` - Total Projects: ${topCustomer.total_projects}`);
|
|
console.log(` - Customer Value: ${topCustomer.total_customer_value?.toLocaleString()} kr`);
|
|
console.log(` - Avg Project Value: ${topCustomer.avg_project_total_value?.toLocaleString()} kr`);
|
|
}
|
|
|
|
// Test 4: Material Insights
|
|
console.log('\n🔨 Testing Material Insights...');
|
|
const materials = await service.getMaterialInsights();
|
|
console.log(`✅ Found ${materials.length} suppliers with material data`);
|
|
|
|
if (materials.length > 0) {
|
|
const topSupplier = materials[0];
|
|
console.log(`✅ Top Supplier: ${topSupplier.supplier}`);
|
|
console.log(` - Total Purchases: ${Number(topSupplier.total_purchases).toLocaleString()} kr`);
|
|
console.log(` - Projects Used: ${topSupplier.projects_used}`);
|
|
console.log(` - Profit Margin: ${topSupplier.profit_margin_percent}%`);
|
|
}
|
|
|
|
// Test 5: Project Analytics (limited)
|
|
console.log('\n📋 Testing Project Analytics...');
|
|
const projects = await service.generateProjectAnalytics();
|
|
const validProjects = projects.filter(p => p.actual_hours > 0);
|
|
console.log(`✅ Found ${validProjects.length} projects with complete data`);
|
|
|
|
if (validProjects.length > 0) {
|
|
const sampleProject = validProjects[0];
|
|
console.log(`✅ Sample Project: ${sampleProject.case_number} - ${sampleProject.description}`);
|
|
console.log(` - Hours: ${sampleProject.actual_hours}t`);
|
|
console.log(` - Project Value: ${sampleProject.total_project_value?.toLocaleString()} kr`);
|
|
console.log(` - Employees: ${sampleProject.employees_count}`);
|
|
}
|
|
|
|
console.log('\n🎉 All analytics tests completed successfully!');
|
|
console.log('\n📈 READY FOR DASHBOARD INTEGRATION');
|
|
|
|
} catch (error) {
|
|
console.error('❌ Analytics test error:', error.message);
|
|
console.error('Stack:', error.stack);
|
|
}
|
|
}
|
|
|
|
testAnalyticsService().catch(console.error); |