diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index 2c7025f..a04c6e0 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -68,9 +68,6 @@ class ActivityController extends Controller $objRow->planned_start = isset($objRow->planned_start) ? date_format(date_create($objRow->planned_start),"Y-m-d H:i:s") : NULL; $objRow->planned_end = isset($objRow->planned_end) ? date_format(date_create($objRow->planned_end),"Y-m-d H:i:s") : NULL; $objRow->progress = $objRow->persentase_progress / 100; - if ($objRow->sortorder == 0 || $objRow->sortorder == null) { - $objRow->sortorder = $objRow->id; - } $objRow->type = $type; $finalData[] = $objRow; $finalData = array_merge($finalData, $dataChildren); @@ -114,9 +111,6 @@ class ActivityController extends Controller $objRow->end_date = date_format($endDate,"Y-m-d H:i:s"); $objRow->planned_start = isset($objRow->planned_start) ? date_format(date_create($objRow->planned_start),"Y-m-d H:i:s") : NULL; $objRow->planned_end = isset($objRow->planned_end) ? date_format(date_create($objRow->planned_end),"Y-m-d H:i:s") : NULL; - if ($objRow->sortorder == 0 || $objRow->sortorder == null) { - $objRow->sortorder = $objRow->id; - } $dataChildren = $this->getChildren($gantt_id, $objRow->id); if($objRow->type_activity=="milestone"){ $objRow->type = $objRow->type_activity; @@ -144,6 +138,7 @@ class ActivityController extends Controller 'rencana_biaya'=> $project->rencana_biaya, 'type_activity'=> 'project', 'created_by'=>$this->currentName, + 'sortorder'=>1 ]); } else { $rootActivity = Activity::create([ @@ -156,6 +151,7 @@ class ActivityController extends Controller 'rencana_biaya'=> $project->rencana_biaya, 'type_activity'=> 'project', 'created_by'=>$this->currentName, + 'sortorder'=>1 ]); } @@ -166,6 +162,7 @@ class ActivityController extends Controller foreach($resultTypeProject as $objRow){ $childActivities = TemplateGantt::where("parent_id", $objRow->id)->count(); + $max = Activity::where('version_gantt_id', $id)->max('sortorder'); $resultNew = Activity::create([ 'type_activity'=> $childActivities > 0 ? "project" : "task", 'version_gantt_id'=>$id, @@ -174,7 +171,8 @@ class ActivityController extends Controller 'name'=> $objRow->name_activity, 'start_date'=>date("Y-m-d H:i:s"), 'end_date'=>date("Y-m-d H:i:s"), - 'created_by'=>$this->currentName + 'created_by'=>$this->currentName, + 'sortorder'=>$max+1 ]); $this->getChildrenTemplate($id, $objRow->id, $project->type_project_id, $proyek_id, $resultNew->id, $project->mulai_proyek); } @@ -185,6 +183,7 @@ class ActivityController extends Controller $data = TemplateGantt::where('parent_id', $parent_id)->orderByRaw('id ASC')->get(); foreach($data as $objRow){ $childActivities = TemplateGantt::where("parent_id", $objRow->id)->count(); + $max = Activity::where('version_gantt_id', $id)->max('sortorder'); $resultNew = Activity::create([ 'type_activity'=> $childActivities > 0 ? "project" : "task", 'version_gantt_id'=>$id, @@ -193,7 +192,8 @@ class ActivityController extends Controller 'name'=> $objRow->name_activity, 'start_date'=>$firstDay, 'end_date'=>$firstDay, - 'created_by'=>$this->currentName + 'created_by'=>$this->currentName, + 'sortorder'=>$max+1 ]); $this->getChildrenTemplate($id, $objRow->id, $type_proyek_id, $proyek_id, $resultNew->id, $firstDay); } @@ -209,7 +209,8 @@ class ActivityController extends Controller $data['name'] = $request->text; $data['persentase_progress'] = $request->progress; $data['created_by'] = $this->currentName; - $data['sortorder'] = Activity::max("sortorder") + 1; + $max = Activity::where('version_gantt_id', $request->version_gantt_id)->max('sortorder'); + $data['sortorder'] = $max + 1; $data['type_activity'] = "task"; $parent = $data['parent_id'] ?? null; @@ -251,6 +252,7 @@ class ActivityController extends Controller $dataUpdate['name'] = $request->text; $dataUpdate['persentase_progress'] = $request->progress*100; $dataUpdate['updated_by'] = $this->currentName; + unset($dataUpdate['sortorder']); if($data->type_activity!='header') $dataUpdate['type_activity'] = $request->type;