From 6a5c24adcb632b7b4549413e7d0802368bdd71b8 Mon Sep 17 00:00:00 2001 From: wahyu Date: Thu, 21 Sep 2023 14:22:51 +0700 Subject: [PATCH] fix schedule dashboard project --- app/Http/Controllers/ProjectController.php | 57 +++++++++++++--------- routes/web.php | 2 +- 2 files changed, 34 insertions(+), 25 deletions(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index e9c7099..fb73310 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -480,7 +480,7 @@ class ProjectController extends Controller return response()->json(['status' => 'success', 'code' => 200, 'data' => $userProyek, 'totalRecord' => $totalRecord], 200); } - public function detail(Request $request, $id, $gantt_id = null){ + public function detail(Request $request, $id, $gantt_id = null, $s_curve = null){ if(empty($id) || !is_int((int)$id)) return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); @@ -495,33 +495,42 @@ class ProjectController extends Controller $ganttId = $gantt_id; } $result->projectManager = User::where('id', $result->pm_id)->value('name'); - $result->header = Activity::whereNull('parent_id')->where("proyek_id", $id)->where("version_gantt_id", $ganttId)->first(); - // dd($result->header->start_date); - $actualStartExist = Activity::where('version_gantt_id', $ganttId)->whereNotNull('actual_start')->exists(); - $actualEndExist = Activity::where('version_gantt_id', $ganttId)->whereNotNull('actual_end')->exists(); + if (isset($s_curve)) { + $result->header = Activity::whereNull('parent_id')->where("proyek_id", $id)->first(); + $actualStartExist = Activity::where('proyek_id', $id)->whereNotNull('actual_start')->exists(); + $actualEndExist = Activity::where('proyek_id', $id)->whereNotNull('actual_end')->exists(); + $query = Activity::where('proyek_id', $id); + } else { + $result->header = Activity::whereNull('parent_id')->where("proyek_id", $id)->where("version_gantt_id", $ganttId)->first(); + $actualStartExist = Activity::where('version_gantt_id', $ganttId)->whereNotNull('actual_start')->exists(); + $actualEndExist = Activity::where('version_gantt_id', $ganttId)->whereNotNull('actual_end')->exists(); + $query = Activity::where('version_gantt_id', $ganttId); + } - 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'); - } + if ($actualStartExist) { + $startDate = $query->orderBy('actual_start')->value('start_date'); + } else { + $startDate = $query->orderBy('start_date')->value('start_date'); + } + + if ($actualEndExist) { + $endDate = $query->orderByDesc('actual_end')->value('end_date'); + } else { + $endDate = $query->orderByDesc('end_date')->value('end_date'); + } + + $plannedStart = Activity::where('version_gantt_id', $ganttId) + ->orderBy('planned_start') + ->value('planned_start'); + $plannedEnd = Activity::where('version_gantt_id', $ganttId) + ->orderByDesc('planned_end') + ->value('planned_end'); $result->header->start_date = $startDate; $result->header->end_date = $endDate; - return response()->json(['status'=>'success','code'=> 200,'data'=>$result], 200); + $result->header->planned_start = $plannedStart; + $result->header->planned_end = $plannedEnd; + return response()->json(['status'=>'success','code'=> 200,'data'=>$result, 'gantt'=>$ganttId], 200); } public function getOverdueActivities(Request $request){ diff --git a/routes/web.php b/routes/web.php index 8e669a2..448986d 100644 --- a/routes/web.php +++ b/routes/web.php @@ -58,7 +58,7 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout $router->post('/project/add', 'ProjectController@add'); $router->put('/project/update/{id}', 'ProjectController@update'); $router->get('/project/edit/{id}', 'ProjectController@edit'); - $router->get('/project/detail/{id}[/{gantt_id}]', 'ProjectController@detail'); + $router->get('/project/detail/{id}[/{gantt_id}[/{s_curve}]]', 'ProjectController@detail'); $router->delete('/project/delete/{id}', 'ProjectController@delete'); $router->get('/project/list', 'ProjectController@list'); $router->get('/project/set-baseline/{gantt_id}', 'ProjectController@setBaseline');