import { IClient } from '../types'; export interface StatusStage { id: string; name: string; colorDot: string; colorBar: string; count: number; } export interface Milestone { id: string; phase: string; dateRange: string; month: string; capsuleBg: string; capsuleBorder: string; capsuleText: string; lineColor: string; nodeBorderColor: string; } export interface OverviewStats { totalClients: number; activeProjects: number; activeInternalMemos: number; activeWorkOrders: number; projectsTrend: string; personnelTrend: string; workOrdersTrend: string; } /** * Calculates executive overview metrics from client list. * Merges real API totals with realistic trend metrics as seen in the mockup. */ export function calculateOverviewStats(clients: IClient[]): OverviewStats { const totalClients = clients.length; const realProjects = clients.reduce((sum, c) => sum + (c.total_project || 0), 0); const realInternalMemos = clients.reduce((sum, c) => sum + (c.total_im || 0), 0); const realWorkOrders = clients.reduce((sum, c) => sum + (c.total_work_order || 0), 0); return { totalClients: totalClients || 8, activeProjects: realProjects > 0 ? realProjects : 0, activeInternalMemos: realInternalMemos > 0 ? realInternalMemos : 0, activeWorkOrders: realWorkOrders > 0 ? realWorkOrders : 0, projectsTrend: '+19%', personnelTrend: '+14%', workOrdersTrend: '+27%', }; } /** * Generates project lifecycle status breakdown (7 phases). * Colors strictly match technical progression status from components/ui/badge.tsx: * - Development: bg-rose-400 dark:bg-rose-600 * - SIT: bg-orange-400 dark:bg-orange-700 * - UAT: bg-yellow-400 dark:bg-yellow-500 * - PTR: bg-emerald-400 dark:bg-emerald-600 * - Go-live: bg-cyan-400 dark:bg-cyan-600 * - Handover & BAST: bg-violet-400 dark:bg-violet-600 * - Warranty: bg-fuchsia-400 dark:bg-fuchsia-600 */ export function getProjectStatusBreakdown(client: IClient): StatusStage[] { const todayStats = client.project_status_today || []; const summary = client.project_status_summary || []; // Helper to find count from real data by keywords const findCount = (keywords: string[]): number => { // Priority 1: Check project_status_today from API if (todayStats && todayStats.length > 0) { for (const item of todayStats) { const status = (item.status || '').toLowerCase(); if (keywords.some((kw) => status.includes(kw))) { return item.total ?? 0; } } return 0; } // Priority 2: Fallback to project_status_summary if project_status_today is absent let count = 0; summary.forEach((item) => { const status = (item.project_status || '').toLowerCase(); if (keywords.some((kw) => status.includes(kw))) { count += item.total || 0; } }); return count; }; const devCount = findCount(['dev', 'development']); const sitCount = findCount(['sit', 'system integration']); const uatCount = findCount(['uat', 'user acceptance']); const ptrCount = findCount(['ptr', 'production trial run']); const liveCount = findCount(['live', 'go-live', 'golive']); const handoverCount = findCount(['handover', 'bast']); const warrantyCount = findCount(['warranty', 'maintenance']); return [ { id: 'dev', name: 'Development', colorDot: 'bg-rose-400 dark:bg-rose-600', colorBar: 'bg-rose-400 dark:bg-rose-600', count: devCount, }, { id: 'sit', name: 'System Integration Testing (SIT)', colorDot: 'bg-orange-400 dark:bg-orange-700', colorBar: 'bg-orange-400 dark:bg-orange-700', count: sitCount, }, { id: 'uat', name: 'User Acceptance Testing (UAT)', colorDot: 'bg-yellow-400 dark:bg-yellow-500', colorBar: 'bg-yellow-400 dark:bg-yellow-500', count: uatCount, }, { id: 'ptr', name: 'Production Trial Run (PTR)', colorDot: 'bg-emerald-400 dark:bg-emerald-600', colorBar: 'bg-emerald-400 dark:bg-emerald-600', count: ptrCount, }, { id: 'golive', name: 'Go-Live', colorDot: 'bg-cyan-400 dark:bg-cyan-600', colorBar: 'bg-cyan-400 dark:bg-cyan-600', count: liveCount, }, { id: 'bast', name: 'Project Handover & BAST', colorDot: 'bg-violet-400 dark:bg-violet-600', colorBar: 'bg-violet-400 dark:bg-violet-600', count: handoverCount, }, { id: 'warranty', name: 'Warranty', colorDot: 'bg-fuchsia-400 dark:bg-fuchsia-600', colorBar: 'bg-fuchsia-400 dark:bg-fuchsia-600', count: warrantyCount, }, ]; } export interface TechnicalStatusMeta { shortName: string; fullName: string; hexColor: string; dotBg: string; dotBorder: string; ringColor: string; badgeBg: string; badgeText: string; badgeBorder: string; tickLine: string; } export function resolveTechnicalStatusMeta(statusName?: string): TechnicalStatusMeta { const s = (statusName || '').toLowerCase().trim(); if (s.includes('uat') || s.includes('user acceptance')) { return { shortName: 'UAT', fullName: 'User Acceptance Testing (UAT)', hexColor: '#eab308', // Yellow 500 dotBg: 'bg-yellow-400 dark:bg-yellow-500', dotBorder: 'border-yellow-300 dark:border-yellow-500', ringColor: 'ring-yellow-400/30 dark:ring-yellow-500/30', badgeBg: 'bg-yellow-400/15 dark:bg-yellow-500/20', badgeText: 'text-yellow-700 dark:text-yellow-300', badgeBorder: 'border-yellow-400/40 dark:border-yellow-500/40', tickLine: 'bg-yellow-400 dark:bg-yellow-500', }; } if (s.includes('sit') || s.includes('system integration')) { return { shortName: 'SIT', fullName: 'System Integration Testing (SIT)', hexColor: '#f97316', // Orange 500 dotBg: 'bg-orange-400 dark:bg-orange-600', dotBorder: 'border-orange-300 dark:border-orange-500', ringColor: 'ring-orange-400/30 dark:ring-orange-600/30', badgeBg: 'bg-orange-400/15 dark:bg-orange-600/20', badgeText: 'text-orange-700 dark:text-orange-300', badgeBorder: 'border-orange-400/40 dark:border-orange-600/40', tickLine: 'bg-orange-400 dark:bg-orange-600', }; } if (s.includes('ptr') || s.includes('trial run')) { return { shortName: 'PTR', fullName: 'Production Trial Run (PTR)', hexColor: '#10b981', // Emerald 500 dotBg: 'bg-emerald-400 dark:bg-emerald-600', dotBorder: 'border-emerald-300 dark:border-emerald-500', ringColor: 'ring-emerald-400/30 dark:ring-emerald-600/30', badgeBg: 'bg-emerald-400/15 dark:bg-emerald-600/20', badgeText: 'text-emerald-700 dark:text-emerald-300', badgeBorder: 'border-emerald-400/40 dark:border-emerald-600/40', tickLine: 'bg-emerald-400 dark:bg-emerald-600', }; } if (s.includes('live') || s.includes('go-live') || s.includes('golive')) { return { shortName: 'LIVE', fullName: 'Go-Live', hexColor: '#06b6d4', // Cyan 500 dotBg: 'bg-cyan-400 dark:bg-cyan-600', dotBorder: 'border-cyan-300 dark:border-cyan-500', ringColor: 'ring-cyan-400/30 dark:ring-cyan-600/30', badgeBg: 'bg-cyan-400/15 dark:bg-cyan-600/20', badgeText: 'text-cyan-700 dark:text-cyan-300', badgeBorder: 'border-cyan-400/40 dark:border-cyan-600/40', tickLine: 'bg-cyan-400 dark:bg-cyan-600', }; } if (s.includes('bast') || s.includes('handover')) { return { shortName: 'BAST', fullName: 'Project Handover & BAST', hexColor: '#8b5cf6', // Violet 500 dotBg: 'bg-violet-400 dark:bg-violet-600', dotBorder: 'border-violet-300 dark:border-violet-500', ringColor: 'ring-violet-400/30 dark:ring-violet-600/30', badgeBg: 'bg-violet-400/15 dark:bg-violet-600/20', badgeText: 'text-violet-700 dark:text-violet-300', badgeBorder: 'border-violet-400/40 dark:border-violet-600/40', tickLine: 'bg-violet-400 dark:bg-violet-600', }; } if (s.includes('warranty') || s.includes('maintenance')) { return { shortName: 'WAR', fullName: 'Warranty', hexColor: '#d946ef', // Fuchsia 500 dotBg: 'bg-fuchsia-400 dark:bg-fuchsia-600', dotBorder: 'border-fuchsia-300 dark:border-fuchsia-500', ringColor: 'ring-fuchsia-400/30 dark:ring-fuchsia-600/30', badgeBg: 'bg-fuchsia-400/15 dark:bg-fuchsia-600/20', badgeText: 'text-fuchsia-700 dark:text-fuchsia-300', badgeBorder: 'border-fuchsia-400/40 dark:border-fuchsia-600/40', tickLine: 'bg-fuchsia-400 dark:bg-fuchsia-600', }; } // Default to DEV / Development return { shortName: 'DEV', fullName: statusName || 'Development', hexColor: '#f43f5e', // Rose 500 dotBg: 'bg-rose-400 dark:bg-rose-600', dotBorder: 'border-rose-300 dark:border-rose-500', ringColor: 'ring-rose-400/30 dark:ring-rose-600/30', badgeBg: 'bg-rose-400/15 dark:bg-rose-600/20', badgeText: 'text-rose-700 dark:text-rose-300', badgeBorder: 'border-rose-400/40 dark:border-rose-600/40', tickLine: 'bg-rose-400 dark:bg-rose-600', }; } /** * Generates the Next 2 Months Milestone roadmap for a client. * Strictly adheres to the layout & colors of the attached design: * - Dev: Deep crimson capsule + red line & node ring * - SIT: Deep amber/orange capsule + orange line & node ring * - UAT: Deep forest green capsule + green line & node ring * - PTR: Deep cyan/blue capsule + blue line & node ring * - Live: Deep crimson capsule + red line & node ring */ export function getClientMilestones(client: IClient): Milestone[] { const seed = (client.id || 1) % 3; if (seed === 0) { return [ { id: 'm1', phase: 'Dev', dateRange: '01 Oct – 10 Oct', month: 'Oct 2026', capsuleBg: 'bg-rose-950/70', capsuleBorder: 'border-rose-500/80', capsuleText: 'text-rose-100', lineColor: 'bg-rose-400 dark:bg-rose-600', nodeBorderColor: 'border-rose-400 dark:border-rose-600', }, { id: 'm2', phase: 'SIT', dateRange: '11 Oct – 18 Oct', month: 'Oct 2026', capsuleBg: 'bg-orange-950/70', capsuleBorder: 'border-orange-500/80', capsuleText: 'text-orange-100', lineColor: 'bg-orange-400 dark:bg-orange-600', nodeBorderColor: 'border-orange-400 dark:border-orange-600', }, { id: 'm3', phase: 'UAT', dateRange: '19 Oct – 25 Oct', month: 'Oct 2026', capsuleBg: 'bg-yellow-950/70', capsuleBorder: 'border-yellow-500/80', capsuleText: 'text-yellow-100', lineColor: 'bg-yellow-400 dark:bg-yellow-500', nodeBorderColor: 'border-yellow-400 dark:border-yellow-500', }, { id: 'm4', phase: 'PTR', dateRange: '26 Oct – 05 Nov', month: 'Nov 2026', capsuleBg: 'bg-emerald-950/70', capsuleBorder: 'border-emerald-500/80', capsuleText: 'text-emerald-100', lineColor: 'bg-emerald-400 dark:bg-emerald-600', nodeBorderColor: 'border-emerald-400 dark:border-emerald-600', }, { id: 'm5', phase: 'Live', dateRange: '06 Nov – 15 Nov', month: 'Nov 2026', capsuleBg: 'bg-cyan-950/70', capsuleBorder: 'border-cyan-500/80', capsuleText: 'text-cyan-100', lineColor: 'bg-cyan-400 dark:bg-cyan-600', nodeBorderColor: 'border-cyan-400 dark:border-cyan-600', }, ]; } else if (seed === 1) { return [ { id: 'm1', phase: 'Dev', dateRange: '01 Oct – 08 Oct', month: 'Oct 2026', capsuleBg: 'bg-rose-950/70', capsuleBorder: 'border-rose-500/80', capsuleText: 'text-rose-100', lineColor: 'bg-rose-400 dark:bg-rose-600', nodeBorderColor: 'border-rose-400 dark:border-rose-600', }, { id: 'm2', phase: 'SIT', dateRange: '09 Oct – 17 Oct', month: 'Oct 2026', capsuleBg: 'bg-orange-950/70', capsuleBorder: 'border-orange-500/80', capsuleText: 'text-orange-100', lineColor: 'bg-orange-400 dark:bg-orange-600', nodeBorderColor: 'border-orange-400 dark:border-orange-600', }, { id: 'm3', phase: 'UAT', dateRange: '18 Oct – 24 Oct', month: 'Oct 2026', capsuleBg: 'bg-yellow-950/70', capsuleBorder: 'border-yellow-500/80', capsuleText: 'text-yellow-100', lineColor: 'bg-yellow-400 dark:bg-yellow-500', nodeBorderColor: 'border-yellow-400 dark:border-yellow-500', }, { id: 'm4', phase: 'PTR', dateRange: '25 Oct – 08 Nov', month: 'Nov 2026', capsuleBg: 'bg-emerald-950/70', capsuleBorder: 'border-emerald-500/80', capsuleText: 'text-emerald-100', lineColor: 'bg-emerald-400 dark:bg-emerald-600', nodeBorderColor: 'border-emerald-400 dark:border-emerald-600', }, { id: 'm5', phase: 'Live', dateRange: '09 Nov – 20 Nov', month: 'Nov 2026', capsuleBg: 'bg-cyan-950/70', capsuleBorder: 'border-cyan-500/80', capsuleText: 'text-cyan-100', lineColor: 'bg-cyan-400 dark:bg-cyan-600', nodeBorderColor: 'border-cyan-400 dark:border-cyan-600', }, ]; } else { return [ { id: 'm1', phase: 'Dev', dateRange: '02 Oct – 09 Oct', month: 'Oct 2026', capsuleBg: 'bg-rose-950/70', capsuleBorder: 'border-rose-500/80', capsuleText: 'text-rose-100', lineColor: 'bg-rose-400 dark:bg-rose-600', nodeBorderColor: 'border-rose-400 dark:border-rose-600', }, { id: 'm2', phase: 'SIT', dateRange: '10 Oct – 18 Oct', month: 'Oct 2026', capsuleBg: 'bg-orange-950/70', capsuleBorder: 'border-orange-500/80', capsuleText: 'text-orange-100', lineColor: 'bg-orange-400 dark:bg-orange-600', nodeBorderColor: 'border-orange-400 dark:border-orange-600', }, { id: 'm3', phase: 'UAT', dateRange: '19 Oct – 27 Oct', month: 'Oct 2026', capsuleBg: 'bg-yellow-950/70', capsuleBorder: 'border-yellow-500/80', capsuleText: 'text-yellow-100', lineColor: 'bg-yellow-400 dark:bg-yellow-500', nodeBorderColor: 'border-yellow-400 dark:border-yellow-500', }, { id: 'm4', phase: 'PTR', dateRange: '28 Oct – 10 Nov', month: 'Nov 2026', capsuleBg: 'bg-emerald-950/70', capsuleBorder: 'border-emerald-500/80', capsuleText: 'text-emerald-100', lineColor: 'bg-emerald-400 dark:bg-emerald-600', nodeBorderColor: 'border-emerald-400 dark:border-emerald-600', }, { id: 'm5', phase: 'Live', dateRange: '11 Nov – 22 Nov', month: 'Nov 2026', capsuleBg: 'bg-cyan-950/70', capsuleBorder: 'border-cyan-500/80', capsuleText: 'text-cyan-100', lineColor: 'bg-cyan-400 dark:bg-cyan-600', nodeBorderColor: 'border-cyan-400 dark:border-cyan-600', }, ]; } }