Project Gantt Chart

Project: {{ $project->title }}
Project No: {{ $project->project_no }}
Timeline: {{ $project->start_date->format('M d, Y') }} - {{ $project->end_date->format('M d, Y') }}
@php $startDate = $project->start_date; $endDate = $project->end_date; $totalDays = $startDate->diffInDays($endDate) + 1; // Generate timeline headers $months = []; $currentDate = clone $startDate; while ($currentDate <= $endDate) { $monthKey = $currentDate->format('Y-m'); if (!isset($months[$monthKey])) { $months[$monthKey] = [ 'name' => $currentDate->format('F Y'), 'weeks' => [] ]; } $weekKey = $currentDate->format('Y-W'); if (!isset($months[$monthKey]['weeks'][$weekKey])) { $weekNumber = $currentDate->format('W'); $months[$monthKey]['weeks'][$weekKey] = [ 'number' => $weekNumber, 'start' => clone $currentDate ]; } $currentDate->addDay(); } // Calculate total columns for colspan $totalColumns = 0; foreach($months as $month) { $totalColumns += count($month['weeks']); } // Calculate percentages for bar positioning function calculateBarStyle($taskStart, $taskEnd, $projectStart, $totalDays) { $startOffset = $taskStart->diffInDays($projectStart); $duration = $taskStart->diffInDays($taskEnd) + 1; $leftPercent = ($startOffset / $totalDays) * 100; $widthPercent = ($duration / $totalDays) * 100; return [ 'left' => $leftPercent . '%', 'width' => $widthPercent . '%', 'duration' => $duration ]; } // Predefined color palette for tasks $colorPalette = [ '#E74C3C', // Red '#3498DB', // Blue '#2ECC71', // Green '#F39C12', // Orange '#9B59B6', // Purple '#1ABC9C', // Teal '#E67E22', // Dark Orange '#27AE60', // Dark Green '#2980B9', // Dark Blue '#8E44AD', // Dark Purple '#D35400', // Burnt Orange '#16A085', // Dark Teal '#C0392B', // Dark Red '#7F8C8D', // Gray '#2C3E50', // Dark Blue-Gray ]; // Function to get lighter version of a color function lightenColor($hex, $percent) { $hex = str_replace('#', '', $hex); if (strlen($hex) == 3) { $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2]; } $rgb = array_map('hexdec', str_split($hex, 2)); foreach ($rgb as $key => $value) { $rgb[$key] = min(255, $value + (255 - $value) * $percent); } return '#' . implode('', array_map('dechex', $rgb)); } // Helper function for darkening colors (PHP) function darkenColor($hex, $percent) { $hex = str_replace('#', '', $hex); if (strlen($hex) == 3) { $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2]; } $rgb = array_map('hexdec', str_split($hex, 2)); foreach ($rgb as $key => $value) { $rgb[$key] = max(0, min(255, $value - ($value * $percent))); } return '#' . implode('', array_map('dechex', $rgb)); } // Assign colors to activities $activityColors = []; $colorIndex = 0; foreach ($activities as $activity) { if (!isset($activityColors[$activity->id])) { $activityColors[$activity->id] = $colorPalette[$colorIndex % count($colorPalette)]; $colorIndex++; } } @endphp @foreach($months as $month) @endforeach @foreach($months as $month) @foreach($month['weeks'] as $week) @endforeach @endforeach @php $totalColumns = 0; foreach($months as $month) { $totalColumns += count($month['weeks']); } @endphp @foreach($activities as $activity) @php $mainColor = $activityColors[$activity->id] ?? '#3498db'; $lighterColor = lightenColor($mainColor, 0.4); @endphp @foreach($activity->LongTermProjectSubActivities as $subActivity) @php $subColor = $activityColors[$activity->id] ?? '#2ecc71'; $lighterSubColor = lightenColor($subColor, 0.5); @endphp @endforeach @endforeach
Task {{ $month['name'] }}
W{{ $week['number'] }}
{{ $activity->activity_name }}
@if($activity->start_date && $activity->end_date) @php $barStyle = calculateBarStyle( $activity->start_date, $activity->end_date, $startDate, $totalDays ); @endphp
{{ $barStyle['duration'] }} days
@endif
{{ $subActivity->sub_activity_name }}
@if($subActivity->start_date && $subActivity->end_date) @php $barStyle = calculateBarStyle( $subActivity->start_date, $subActivity->end_date, $startDate, $totalDays ); $assignee = '-'; $member = DB::table('users')->where('id', $subActivity->assignee_id)->first(); if($member) { $assignee = trim($member->name . ' ' . ($member->last_name ?? '')); } @endphp
@if(!empty($assignee)) Assignee: {{ $assignee }} @else {{ $barStyle['duration'] }} days @endif
@endif
Main Tasks
Sub Tasks
Total Duration: {{ $totalDays }} days
Tasks: {{ $activities->count() }}
Sub Tasks: {{ $activities->sum(function($a) { return $a->LongTermProjectSubActivities->count(); }) }}