From d6dcff417710f6f13b2c20098213dfbeac52ff2d Mon Sep 17 00:00:00 2001 From: satori Date: Wed, 27 Jul 2022 06:31:06 +0700 Subject: [PATCH] endpoint for Dashboard PMO --- app/Http/Controllers/ProjectController.php | 48 +++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 5402bc8..250ccf6 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -206,12 +206,58 @@ class ProjectController extends Controller public function list() { - $data = Project::all(); + $data = Project::orderBy('id', 'desc')->get(); $countData = $data->count(); if(!$data) return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); + $costWarningThreshold = 50000000; + $costDangerThreshold = 25000000; + $scheduleWarningThreshold = 10; + $scheduleDangerThreshold = 5; + foreach($data as $d){ + $progress = $costVariance = $actualCost = 0; + $lastActivity = null; + $scheduleHealth = "on-track"; + $costHealth = "on-budget"; + $rootActivity = Activity::whereNull('parent_id')->where('proyek_id', $d->id)->orderBy('version_gantt_id', 'desc')->first(); + if($rootActivity){ + $costVariance = $d->rencana_biaya - $rootActivity->biaya_actual; + $actualCost = $rootActivity->biaya_actual ?? 0; + $progress = $rootActivity->persentase_progress ?? 0; + /* + $timeleft = strtotime($d->mulai_proyek) - strtotime($rootActivity->end_date); + $date1 = new \DateTime(date("Y-m-d", strtotime($d->mulai_proyek))); + $date2 = new \DateTime(date("Y-m-d", strtotime($rootActivity->end_date))); + $daysRemaining = $date2->diff($date1); + $daysRemaining = $daysRemaining->d; + + if($daysRemaining <= $scheduleDangerThreshold) { + $scheduleHealth = "danger"; + } elseif ($daysRemaining <= $scheduleWarningThreshold) { + $scheduleHealth = "warning"; + } + + $lastActivity = date("d/m/Y", strtotime($rootActivity->end_date)); + */ + if($costVariance <= $costDangerThreshold) { + $costHealth = "danger"; + } elseif ($costVariance <= $costWarningThreshold) { + $costHealth = "warning"; + } + } + $d->plannedInterval = date("d/m/Y", strtotime($d->mulai_proyek)) . " - " . date("d/m/Y", strtotime($d->akhir_proyek)); + $d->plannedCost = $d->rencana_biaya; + $d->actualCost = $actualCost; + //$d->lastActivity = $lastActivity ?? "-"; + //$d->lastActivity = $daysRemaining . " -- " . $lastActivity . "\n" . $date1 . "\n" . $date2; + $d->costVariance = $costVariance; + $d->costHealth = $costHealth; + //$d->scheduleHealth = $scheduleHealth; + $d->progress = $progress . "%"; + } + return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); }