@ -37,6 +37,94 @@ class ActivityController extends Controller
return response()->json(['status' => 'success', 'data' => $dataGantt, 'code' => 200], 200);
}
public function activitySCurve($proyek_id, $gantt_id){
// "data": [
// {
// "id": 1,
// "text": "Office itinerancy",
// "type": "project",
// "order": "10",
// "progress": 0.4,
// "open": true,
// "user":"0",
// "start_date": "02-04-2024 00:00",
// "duration": 17,
// "end_date": "19-04-2024 00:00",
// "parent": 0
// }
// ],
// "links": [
// {
// "id": "1",
// "source": "1",
// "target": "2",
// "type": "1"
// }
// ]
// }
$checkHeader = Activity::where('version_gantt_id', $gantt_id)->where('type_activity', 'header')->count();
$finalData = [];
if ($checkHeader > 0) {
$dataHeader = Activity::select('id', 'name as text', 'type_activity as type', 'persentase_progress as progress', 'start_date', 'end_date', 'duration', 'parent_id', 'sortorder as order')->where('version_gantt_id', $gantt_id)->where('type_activity', 'header')->first();
// $dataHeader->start_date1 = isset($dataHeader->start) ? date_format(date_create($dataHeader->start), "d-m-Y H:i") : NULL;
// $dataHeader->end_date1 = isset($dataHeader->end) ? date_format(date_create($dataHeader->end), "d-m-Y H:i") : NULL;
$dataHeader->progress = $dataHeader->progress / 100;
$dataHeader->type = "project";
$dataHeader->text = $dataHeader->name;
$finalData[] = $dataHeader;
$data = Activity::select('id', 'name as text', 'type_activity as type', 'persentase_progress as progress', 'start_date', 'end_date', 'duration', 'parent_id', 'sortorder as order')->where('version_gantt_id', $gantt_id)->where('parent_id', $dataHeader->id)->orderBy('sortorder', 'asc')->get();
} else {
$data = Activity::select('id', 'name as text', 'type_activity as type', 'persentase_progress as progress', 'start_date', 'end_date', 'duration', 'parent_id', 'sortorder as order')->where('version_gantt_id', $gantt_id)->whereNull('parent_id')->orderBy('sortorder', 'asc')->get();
}
foreach ($data as $objRow) {
$type = "project";
$dataChildren = $this->getChildrenSCurve($gantt_id, $objRow->id);
if ($objRow->type_activity == "milestone")
$type = $objRow->type_activity;
if (empty($dataChildren))
$type = "task";
$objRow->parent = $objRow->parent_id ? $objRow->parent_id : null;
// $objRow->start_date = isset($objRow->start) ? date_format(date_create($objRow->start), "d-m-Y H:i") : NULL;
// $objRow->end_date1 = isset($objRow->end) ? date_format(date_create($objRow->end), "d-m-Y H:i") : NULL;
$objRow->progress = $objRow->persentase_progress / 100;
$objRow->type = $type;
$finalData[] = $objRow;
$finalData = array_merge($finalData, $dataChildren);
}
$dataLink = Link::where('version_gantt_id', $gantt_id)->get();
$finalLink = [];
foreach ($dataLink as $objRow) {
$dataRow = array(
'id' => $objRow->id,
'source' => $objRow->s_activity_id,
'target' => $objRow->t_activity_id,
'type' => $objRow->type_link,
'code' => $objRow->code_link
);
if ($objRow->lag)
$dataRow['lag'] = $objRow->lag;
$finalLink[] = $dataRow;
}
$resultData = array(
"data" => $finalData,
"links" => $finalLink
);
return response()->json(['status' => 'success', 'data' => $resultData, 'code' => 200], 200);
}
private function getDataActivity($id)
{
$checkHeader = Activity::where('version_gantt_id', $id)->where('type_activity', 'header')->count();
@ -116,6 +204,43 @@ class ActivityController extends Controller
return $resultData;
}
private function getChildrenSCurve($gantt_id, $parent_id)
{
$finalData = [];
$data = Activity::select('id', 'name as text', 'type_activity as type', 'bobot_planning', 'persentase_progress as progress', 'start_date', 'end_date', 'duration', 'parent_id', 'sortorder as order')
->where('version_gantt_id', $gantt_id)->where('parent_id', $parent_id)->orderBy('sortorder', 'asc')->get();
foreach ($data as $objRow) {
$objRow->parent = $parent_id;
$objRow->progress = (float) $objRow->bobot_planning /100;
// $objRow->start_date1 = isset($objRow->start) ? date_format(date_create($objRow->start), "d-m-Y H:i") : NULL;
// $objRow->end_date1 = isset($objRow->end) ? date_format(date_create($objRow->end), "d-m-Y H:i") : NULL;
$dataChildren = $this->getChildrenSCurve($gantt_id, $objRow->id);
if ($objRow->type_activity == "milestone") {
$objRow->type = $objRow->type_activity;
// $objRow->actual_start = isset($objRow->actual_start) ? date_format(date_create($objRow->actual_start), "d-m-Y") : NULL;
} elseif (empty($dataChildren)) {
$objRow->type = "task";
// $objRow->actual_start = isset($objRow->actual_start) ? date_format(date_create($objRow->actual_start), "d-m-Y") : NULL;
// $objRow->actual_end = isset($objRow->actual_end) ? date_format(date_create($objRow->actual_end), "d-m-Y") : NULL;
// if(isset($objRow->actual_start)){
// $objRow->auto_scheduling = false;
// }
} else {
$objRow->type = "project";
// $actualStart = $this->getFirstLastDateActivity($objRow->id, "start");
// $objRow->actual_start = isset($actualStart) ? date_format(date_create($actualStart), "d-m-Y") : NULL;
// $actualEnd = $this->getFirstLastDateActivity($objRow->id, "end");
// $objRow->actual_end = isset($actualEnd) ? date_format(date_create($actualEnd), "d-m-Y") : NULL;
}
$finalData[] = $objRow;
$finalData = array_merge($finalData, $dataChildren);
}
return $finalData;
}
private function getChildren($gantt_id, $parent_id)
{
$finalData = [];