diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index ab5c490..61902e9 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -16,8 +16,13 @@ class ActivityController extends Controller { public function getByGanttId($id, $proyek_id) { - if(Activity::where('proyek_id', $proyek_id)->where("version_gantt_id", $id)->count() == 0) { - $this->cloneTemplate($id, $proyek_id); + $gantt = VersionGantt::find($id); + if(Activity::where('proyek_id', $proyek_id)->where("version_gantt_id", $id)->count() == 0) { + if(!$gantt->hierarchy_ftth_id) { + $this->cloneTemplate($id, $proyek_id); + } else { + $this->cloneTemplate($id, $proyek_id, $gantt->hierarchy_ftth_id); + } } $dataGantt = $this->getDataActivity($id); @@ -120,21 +125,33 @@ class ActivityController extends Controller return $finalData; } - private function cloneTemplate($id, $proyek_id) - { - $project = Project::find($proyek_id); - - $rootActivity = Activity::create([ - 'version_gantt_id'=>$id, - 'proyek_id'=>$proyek_id, - 'name'=> $project->nama, - 'kode_sortname'=>$project->kode_sortname, - 'start_date'=> $project->mulai_proyek, - 'end_date'=> $project->akhir_proyek, - 'rencana_biaya'=> $project->rencana_biaya, - 'type_activity'=> 'project', - 'created_by'=>$this->currentName, - ]); + private function cloneTemplate($id, $proyek_id, $hierarchy_ftth_id = null) { + $project = Project::find($proyek_id); + if($hierarchy_ftth_id){ + $gantt = VersionGantt::find($id); + $rootActivity = Activity::create([ + 'version_gantt_id'=>$id, + 'proyek_id'=>$proyek_id, + 'name'=> $gantt->name_version, + 'start_date'=> $project->mulai_proyek, + 'end_date'=> $project->akhir_proyek, + 'rencana_biaya'=> $project->rencana_biaya, + 'type_activity'=> 'project', + 'created_by'=>$this->currentName, + ]); + } else { + $rootActivity = Activity::create([ + 'version_gantt_id'=>$id, + 'proyek_id'=>$proyek_id, + 'name'=> $project->nama, + 'kode_sortname'=>$project->kode_sortname, + 'start_date'=> $project->mulai_proyek, + 'end_date'=> $project->akhir_proyek, + 'rencana_biaya'=> $project->rencana_biaya, + 'type_activity'=> 'project', + 'created_by'=>$this->currentName, + ]); + } $resultTypeProject = TemplateGantt::where('proyek_type_id', $project->type_proyek_id) ->whereNull('parent_id')