From b44644f13abca7dbd80ab722098f4442c832badc Mon Sep 17 00:00:00 2001 From: farhantock Date: Wed, 27 Dec 2023 10:57:53 +0700 Subject: [PATCH] update type condition --- app/Http/Controllers/ActivityController.php | 255 ++++++++++---------- 1 file changed, 128 insertions(+), 127 deletions(-) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index cbb425e..a9a56e4 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -1,4 +1,5 @@ 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" - // } - // ] - // } + 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; @@ -84,17 +86,17 @@ class ActivityController extends Controller foreach ($data as $objRow) { $type = "project"; - $dataChildren = $this->getChildrenSCurve($gantt_id, $objRow->id); + $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->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; @@ -120,9 +122,8 @@ class ActivityController extends Controller "data" => $finalData, "links" => $finalLink ); - - return response()->json(['status' => 'success', 'data' => $resultData, 'code' => 200], 200); + return response()->json(['status' => 'success', 'data' => $resultData, 'code' => 200], 200); } private function getDataActivity($id) @@ -207,15 +208,15 @@ class ActivityController extends Controller 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(); + ->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->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; @@ -234,7 +235,7 @@ class ActivityController extends Controller // $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); } @@ -264,7 +265,7 @@ class ActivityController extends Controller $objRow->type = "task"; $objRow->actual_start = isset($objRow->actual_start) ? date_format(date_create($objRow->actual_start), "Y-m-d") : NULL; $objRow->actual_end = isset($objRow->actual_end) ? date_format(date_create($objRow->actual_end), "Y-m-d") : NULL; - if(isset($objRow->actual_start)){ + if (isset($objRow->actual_start)) { $objRow->auto_scheduling = false; } } else { @@ -281,66 +282,67 @@ class ActivityController extends Controller return $finalData; } - public function getActivityFirst($parentId){ + public function getActivityFirst($parentId) + { $activity = Activity::where('parent_id', $parentId)->orderByRaw('actual_start ASC')->first(); if (!isset($activity)) { return null; } - if($activity->type_activity == "task"){ + if ($activity->type_activity == "task") { // Log::info("activity ", [$activity]); return $activity->actual_start; - }else{ + } else { return $this->getActivityFirst($activity->id); } - } - public function getFirstLastDateActivity($id, $params){ - if($params == "start"){ + public function getFirstLastDateActivity($id, $params) + { + if ($params == "start") { $data = Activity::select('id', 'parent_id', 'name', 'actual_start')->where('parent_id', $id)->get(); - }else{ + } else { $data = Activity::select('id', 'parent_id', 'name', 'actual_end')->where('parent_id', $id)->get(); } - $parent = Activity::findOrFail($id); - $dataFinal=[]; + $parent = Activity::findOrFail($id); + $dataFinal = []; foreach ($data as $val) { $activity = $this->getchildActivityForActual($val->id, $params); $dataFinal[] = $val; $dataFinal = array_merge($dataFinal, $activity); - } - if($params == "start"){ - $actualStartValues = array_column(array_filter($dataFinal, function($item) { + if ($params == "start") { + $actualStartValues = array_column(array_filter($dataFinal, function ($item) { return isset($item['actual_start']); }), 'actual_start'); $returnActualStartOrEnd = count($actualStartValues) > 0 ? min($actualStartValues) : null; - if (isset($parent)) { - $parent->actual_start = $returnActualStartOrEnd; - $parent->save(); - } - }else{ - $actualEndValues = array_column(array_filter($dataFinal, function($item) { + if (isset($parent)) { + $parent->actual_start = $returnActualStartOrEnd; + $parent->save(); + } + } else { + $actualEndValues = array_column(array_filter($dataFinal, function ($item) { return isset($item['actual_end']); }), 'actual_end'); $returnActualStartOrEnd = count($actualEndValues) == count($dataFinal) && count($actualEndValues) > 0 ? max($actualEndValues) : null; - if (isset($parent)) { - $parent->actual_end = $returnActualStartOrEnd; - $parent->save(); - } + if (isset($parent)) { + $parent->actual_end = $returnActualStartOrEnd; + $parent->save(); + } } // return json_encode(["min"=>$minActualStart, "max"=>$maxActualStart]); return $returnActualStartOrEnd; } - public function getchildActivityForActual($parent, $params){ - if($params == "start"){ + public function getchildActivityForActual($parent, $params) + { + if ($params == "start") { $activity = Activity::select('id', 'actual_start')->where('parent_id', $parent)->get(); - }else{ + } else { $activity = Activity::select('id', 'actual_end')->where('parent_id', $parent)->get(); } $temp = []; - foreach($activity as $val1){ + foreach ($activity as $val1) { $getChild = $this->getchildActivityForActual($val1->id, $params); $temp[] = $val1; $temp = array_merge($temp, $getChild); @@ -348,18 +350,18 @@ class ActivityController extends Controller return $temp; } - public function getActivityLast($parentId){ + public function getActivityLast($parentId) + { $activity = Activity::where('parent_id', $parentId)->orderByRaw('actual_end DESC')->first(); if (!isset($activity)) { return null; } - if($activity->type_activity == "task"){ + if ($activity->type_activity == "task") { // Log::info("activity ", [$activity]); return $activity->actual_end; - }else{ + } else { return $this->getActivityLast($activity->id); } - } private function cloneTemplate($id, $proyek_id, $hierarchy_ftth_id = null) @@ -547,53 +549,54 @@ class ActivityController extends Controller return response()->json(['status' => 'success', 'message' => 'Activity Updated!', 'code' => 200], 200); } - public function updateSchedule($ganttId){ - if (empty($ganttId) || !is_int((int) $ganttId)) + public function updateSchedule($ganttId) + { + if (empty($ganttId) || !is_int((int) $ganttId)) return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); - $activities = Activity::where('version_gantt_id', $ganttId)->get(); + $activities = Activity::where('version_gantt_id', $ganttId)->get(); if (!$activities) return response()->json(['status' => 'failed', 'message' => 'Activities not found!', 'code' => 404], 404); $duration = 0; - foreach ($activities as $key => $activity) { - $assignMaterial = AssignMaterial::where('activity_id', $activity->id)->first(); + foreach ($activities as $key => $activity) { + $assignMaterial = AssignMaterial::where('activity_id', $activity->id)->first(); if (isset($assignMaterial)) { $statusActivity = $assignMaterial->status_activity; } else { $statusActivity = ''; } - if (isset($activity->planned_start) && isset($activity->planned_end) && $statusActivity != "done") { - // todo check report for no report / progress == 0 - $today = new DateTime(); - $endDate = new DateTime($activity->end_date); - $startDate = new DateTime($activity->start_date); - $plannedStart = new DateTime($activity->planned_start); - $plannedEnd = new DateTime($activity->planned_end); - $duration = MasterFunctionsHelper::countDays($ganttId, $plannedStart, $plannedEnd); - if ($today >= $endDate) { - $endDate = $today; - $bobotPlanning = (int) $activity->bobot_planning; - $rerataBobot = $duration > 0 ? $bobotPlanning / $duration : 0; - $bobotActual = (int) $activity->persentase_progress/100 * $bobotPlanning; - $sisaBobot = $bobotPlanning - $bobotActual; - $sisaHari = $rerataBobot > 0 ? $sisaBobot / $rerataBobot : 0; - $endDate->modify("+".ceil($sisaHari)." Days"); - $actualDuration = MasterFunctionsHelper::countDays($ganttId, $startDate, $endDate); - $activity->duration = $actualDuration; - $activity->end_date = $endDate; - $activity->save(); - } - } - } + if (isset($activity->planned_start) && isset($activity->planned_end) && $statusActivity != "done") { + // todo check report for no report / progress == 0 + $today = new DateTime(); + $endDate = new DateTime($activity->end_date); + $startDate = new DateTime($activity->start_date); + $plannedStart = new DateTime($activity->planned_start); + $plannedEnd = new DateTime($activity->planned_end); + $duration = MasterFunctionsHelper::countDays($ganttId, $plannedStart, $plannedEnd); + if ($today >= $endDate) { + $endDate = $today; + $bobotPlanning = (int) $activity->bobot_planning; + $rerataBobot = $duration > 0 ? $bobotPlanning / $duration : 0; + $bobotActual = (int) $activity->persentase_progress / 100 * $bobotPlanning; + $sisaBobot = $bobotPlanning - $bobotActual; + $sisaHari = $rerataBobot > 0 ? $sisaBobot / $rerataBobot : 0; + $endDate->modify("+" . ceil($sisaHari) . " Days"); + $actualDuration = MasterFunctionsHelper::countDays($ganttId, $startDate, $endDate); + $activity->duration = $actualDuration; + $activity->end_date = $endDate; + $activity->save(); + } + } + } return response()->json(['status' => 'success', 'message' => 'Activities Updated!', 'code' => 200], 200); - } + } public function batchUpdate(Request $request, $ganttId) { $entities = $request->all(); if (empty($ganttId) || !is_int((int) $ganttId)) return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); - $activity = Activity::where('version_gantt_id',$ganttId)->get(); + $activity = Activity::where('version_gantt_id', $ganttId)->get(); $link = Link::where('version_gantt_id', $ganttId)->get(); if (!$activity) return response()->json(['status' => 'failed', 'message' => 'Activity not found!', 'code' => 404], 404); @@ -604,7 +607,7 @@ class ActivityController extends Controller $activityToUpdate = $activity->firstWhere('id', $entity['data']['id']); $entity['data']['name'] = $entity['data']['text']; $entity['data']['persentase_progress'] = $entity['data']['progress'] * 100; - $entity['data']['type_activity'] = $entity['data']['type']; + $entity['data']['type_activity'] = $entity['data']['type'] ?? 'task'; if (isset($entity['data']['rencana_biaya'])) { $entity['data']['rencana_biaya'] = str_replace(",", ".", $entity['data']['rencana_biaya']); } @@ -627,25 +630,25 @@ class ActivityController extends Controller { if (!$data = Activity::find($id)) return response()->json(['status' => 'failed', 'action' => 'error', 'message' => 'Data not found!', 'code' => 404], 404); - $this->deleteRelative($id); + $this->deleteRelative($id); if (!$data->delete()) return response()->json(['status' => 'failed', 'action' => 'error', 'message' => 'data activity failed deleted!', 'code' => 500], 500); return response()->json(['status' => 'success', "action" => "deleted", 'message' => 'data activity successfully deleted!', 'code' => 200], 200); } - private function deleteRelative($activity_id) + private function deleteRelative($activity_id) { - UserToActivity::where('activity_id', $activity_id)->delete(); - AssignMaterial::where('activity_id', $activity_id)->delete(); - $dataAd = ActivityDokumen::where("activity_id", $activity_id)->get(); + UserToActivity::where('activity_id', $activity_id)->delete(); + AssignMaterial::where('activity_id', $activity_id)->delete(); + $dataAd = ActivityDokumen::where("activity_id", $activity_id)->get(); foreach ($dataAd as $ad) { - if(file_exists($this->pathActivityDocument.$ad->file)){ - unlink($this->pathActivityDocument.$ad->file); + if (file_exists($this->pathActivityDocument . $ad->file)) { + unlink($this->pathActivityDocument . $ad->file); } } - ActivityDokumen::where("activity_id", $activity_id)->delete(); - } + ActivityDokumen::where("activity_id", $activity_id)->delete(); + } public function getUpdate($id) { @@ -667,24 +670,24 @@ class ActivityController extends Controller return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => $totalRecord], 200); } - public function searchAnalysisPrep(Request $request) + public function searchAnalysisPrep(Request $request) { $data = $request->all(); - $dataGet = DB::table('m_activity') - ->select('m_activity.name') - ->where('m_activity.proyek_id', $data['columns'][0]['value']) - ->where('m_activity.type_activity', 'task') - // ->where('m_activity.persentase_progress', '>', 0) - ->groupByRaw('m_activity.name') - ->get(); - return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet ], 200); + $dataGet = DB::table('m_activity') + ->select('m_activity.name') + ->where('m_activity.proyek_id', $data['columns'][0]['value']) + ->where('m_activity.type_activity', 'task') + // ->where('m_activity.persentase_progress', '>', 0) + ->groupByRaw('m_activity.name') + ->get(); + return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet], 200); } - public function searchAnalysis(Request $request) + public function searchAnalysis(Request $request) { $dataBuilder = $this->setUpPayload($request->all(), 'm_activity'); $builder = $dataBuilder['builder']; - $dataGet = $builder->select( + $dataGet = $builder->select( 'selfTable.name', 'persentase_progress', 'selfTable.start_date', @@ -718,7 +721,7 @@ class ActivityController extends Controller ->groupBy('assign_material_to_activity.id') ->groupBy('user_names.user_name') ->get(); - return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet ], 200); + return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet], 200); } // before upload file public function importOld(Request $request) @@ -777,8 +780,7 @@ class ActivityController extends Controller $data['activities'][$key]['weight'] = $parentWeight / $siblingsCount; } - } - ; + }; } $projectStart = Project::select('mulai_proyek')->where('id', $projectId)->first(); foreach ($data['activities'] as $i => $activity_row) { @@ -1137,7 +1139,6 @@ class ActivityController extends Controller return response()->json(['status' => 'failed', 'message' => 'Upload failed!', 'code' => 500], 500); } return response()->json(['status' => 'success', 'message' => 'Upload successful!', 'code' => 200], 200); - } return response()->json(['status' => 'failed', 'message' => 'Upload failed!', 'code' => 500], 500); }