From 0b13e01b4928233bbdaf87609356de3af1bf5374 Mon Sep 17 00:00:00 2001 From: wahyu Date: Mon, 28 Aug 2023 14:59:51 +0700 Subject: [PATCH] fix schedule dashboard project --- app/Http/Controllers/ProjectController.php | 26 +++++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 944b7ad..0a37a92 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -448,13 +448,27 @@ class ProjectController extends Controller // dd($result->header->start_date); $ganttId = $gantt['last_gantt_id']; - $startDate = Activity::where('version_gantt_id', $ganttId) - ->orderBy('start_date') - ->value('start_date'); + $actualStartExist = Activity::where('version_gantt_id', $ganttId)->whereNotNull('actual_start')->exists(); + $actualEndExist = Activity::where('version_gantt_id', $ganttId)->whereNotNull('actual_end')->exists(); - $endDate = Activity::where('version_gantt_id', $ganttId) - ->orderByDesc('end_date') - ->value('end_date'); + if ($actualStartExist) { + $startDate = Activity::where('version_gantt_id', $ganttId) + ->orderBy('actual_start') + ->value('start_date'); + } else { + $startDate = Activity::where('version_gantt_id', $ganttId) + ->orderBy('start_date') + ->value('start_date'); + } + if ($actualEndExist) { + $endDate = Activity::where('version_gantt_id', $ganttId) + ->orderByDesc('actual_end') + ->value('end_date'); + } else { + $endDate = Activity::where('version_gantt_id', $ganttId) + ->orderByDesc('end_date') + ->value('end_date'); + } $result->header->start_date = $startDate; $result->header->end_date = $endDate; return response()->json(['status'=>'success','code'=> 200,'data'=>$result, 'gantt'=>$gantt], 200);