|
|
|
@ -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); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|